Update library to work with Libchat

This commit is contained in:
Jazz Turner-Baggs 2026-02-11 09:59:10 -08:00
parent 3fab891d47
commit bcfd98eb2a
No known key found for this signature in database
4 changed files with 12 additions and 19 deletions

View File

@ -71,9 +71,9 @@ proc DefaultConfig*(): WakuConfig =
shardId: @[shardId], pubsubTopic: &"/waku/2/rs/{clusterId}/{shardId}",
staticPeers: @[])
proc sendPayload*(client: WakuClient, contentTopic: string,
env: WapEnvelopeV1) {.async.} =
let bytes = encode(env)
proc sendBytes*(client: WakuClient, contentTopic: string,
bytes: seq[byte]) {.async.} =
let msg = WakuMessage(contentTopic: contentTopic, payload: bytes)
let res = await client.node.publish(some(PubsubTopic(client.cfg.pubsubTopic)), msg)

View File

@ -9,6 +9,7 @@ type
errTypeError
errWrapped
errTopic
errLibChat
proc `$`*(x: ChatError): string =
fmt"ChatError(code={$x.code}, context: {x.context})"

View File

@ -32,6 +32,13 @@ proc getPubkey*(self: Identity): PublicKey =
proc getAddr*(self: Identity): string =
result = get_addr(self.getPubKey())
proc getName*(self: Identity): string =
result = self.name
proc toHex(key: PublicKey): string =
bytesToHex(key.bytes())
proc `$`*(key: PublicKey): string =
let byteStr = toHex(key)
fmt"{byteStr[0..3]}..{byteStr[^4 .. ^1]}"

View File

@ -6,7 +6,6 @@ import strutils
proc getCurrentTimestamp*(): Timestamp =
result = waku_core.getNanosecondTime(getTime().toUnix())
proc hash_func*(s: string | seq[byte]): string =
# This should be Blake2s but it does not exist so substituting with Blake2b
result = getBlake2b(s, 4, "")
@ -17,17 +16,3 @@ proc bytesToHex*[T](bytes: openarray[T], lowercase: bool = false): string =
for b in bytes:
let hex = b.toHex(2)
result.add(if lowercase: hex.toLower() else: hex)
proc toBytes*(s: string): seq[byte] =
result = cast[seq[byte]](s)
proc toUtfString*(b: seq[byte]): string =
result = cast[string](b)
macro panic*(reason: string): untyped =
result = quote do:
let pos = instantiationInfo()
echo `reason` & " ($1:$2)" % [
pos.filename, $pos.line]
echo "traceback:\n", getStackTrace()
quit(1)