mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-16 18:06:45 +00:00
e7b2b88f5b
* fix(rln-relay): modify keystore credentials logic fix: bump version * Update waku/waku_rln_relay/group_manager/on_chain/group_manager.nim Co-authored-by: Ivan Folgueira Bande <128452529+Ivansete-status@users.noreply.github.com> * Update tests/waku_rln_relay/test_waku_rln_relay.nim Co-authored-by: Ivan Folgueira Bande <128452529+Ivansete-status@users.noreply.github.com> * Update waku/waku_keystore/protocol_types.nim Co-authored-by: Ivan Folgueira Bande <128452529+Ivansete-status@users.noreply.github.com> * fix: greatly improve error handling * fix: display proc and appropriate assert --------- Co-authored-by: Ivan Folgueira Bande <128452529+Ivansete-status@users.noreply.github.com>
32 lines
1.2 KiB
Nim
32 lines
1.2 KiB
Nim
when (NimMajor, NimMinor) < (1, 4):
|
|
{.push raises: [Defect].}
|
|
else:
|
|
{.push raises: [].}
|
|
|
|
import
|
|
json,
|
|
stew/[results, byteutils],
|
|
./protocol_types
|
|
|
|
# Encodes a KeystoreMembership credential to a byte sequence
|
|
proc encode*(credential: KeystoreMembership): seq[byte] =
|
|
# TODO: use custom encoding, avoid wordy json
|
|
var stringCredential: string
|
|
# NOTE: toUgly appends to the string, doesn't replace its contents
|
|
stringCredential.toUgly(%credential)
|
|
return toBytes(stringCredential)
|
|
|
|
# Decodes a byte sequence to a KeystoreMembership credential
|
|
proc decode*(encodedCredential: seq[byte]): KeystoreResult[KeystoreMembership] =
|
|
# TODO: use custom decoding, avoid wordy json
|
|
try:
|
|
# we parse the json decrypted keystoreCredential
|
|
let jsonObject = parseJson(string.fromBytes(encodedCredential))
|
|
return ok(to(jsonObject, KeystoreMembership))
|
|
except JsonParsingError:
|
|
return err(AppKeystoreError(kind: KeystoreJsonError,
|
|
msg: getCurrentExceptionMsg()))
|
|
except Exception: #parseJson raises Exception
|
|
return err(AppKeystoreError(kind: KeystoreOsError,
|
|
msg: getCurrentExceptionMsg()))
|