mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-11 14:37:00 +00:00
initial changes
This commit is contained in:
parent
61548d9260
commit
7cdab6756b
@ -18,19 +18,18 @@ Json.setWriter JsonWriter, PreferredOutput = string
|
|||||||
#### Type conversion
|
#### Type conversion
|
||||||
|
|
||||||
proc parseHash*(input: Option[string]): Result[Option[WakuMessageHash], string] =
|
proc parseHash*(input: Option[string]): Result[Option[WakuMessageHash], string] =
|
||||||
let base64UrlEncoded =
|
let hexUrlEncoded =
|
||||||
if input.isSome():
|
if input.isSome():
|
||||||
input.get()
|
input.get()
|
||||||
else:
|
else:
|
||||||
return ok(none(WakuMessageHash))
|
return ok(none(WakuMessageHash))
|
||||||
|
|
||||||
if base64UrlEncoded == "":
|
if hexUrlEncoded == "":
|
||||||
return ok(none(WakuMessageHash))
|
return ok(none(WakuMessageHash))
|
||||||
|
|
||||||
let base64Encoded = decodeUrl(base64UrlEncoded, false)
|
let hexDecoded = decodeUrl(hexUrlEncoded, false)
|
||||||
|
|
||||||
let decodedBytes = base64.decode(Base64String(base64Encoded)).valueOr:
|
let decodedBytes = hexToByteArray(hexDecoded)
|
||||||
return err("waku message hash parsing error: " & error)
|
|
||||||
|
|
||||||
if decodedBytes.len != 32:
|
if decodedBytes.len != 32:
|
||||||
return
|
return
|
||||||
@ -58,12 +57,12 @@ proc parseHashes*(input: Option[string]): Result[seq[WakuMessageHash], string] =
|
|||||||
return ok(hashes)
|
return ok(hashes)
|
||||||
|
|
||||||
# Converts a given MessageDigest object into a suitable
|
# Converts a given MessageDigest object into a suitable
|
||||||
# Base64-URL-encoded string suitable to be transmitted in a Rest
|
# Hex-URL-encoded string suitable to be transmitted in a Rest
|
||||||
# request-response. The MessageDigest is first base64 encoded
|
# request-response. The MessageDigest is first hex encoded
|
||||||
# and this result is URL-encoded.
|
# and this result is URL-encoded.
|
||||||
proc toRestStringWakuMessageHash*(self: WakuMessageHash): string =
|
proc toRestStringWakuMessageHash*(self: WakuMessageHash): string =
|
||||||
let base64Encoded = base64.encode(self)
|
let hexEncoded = self.to0xHex()
|
||||||
encodeUrl($base64Encoded, false)
|
encodeUrl(hexEncoded, false)
|
||||||
|
|
||||||
## WakuMessage serde
|
## WakuMessage serde
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user