From 103d3981ad80b83dba48fe88cb5f2dcf715104b2 Mon Sep 17 00:00:00 2001 From: Sasha <118575614+weboko@users.noreply.github.com> Date: Fri, 1 Dec 2023 12:57:19 +0100 Subject: [PATCH] fix: remove trailing commas from keystore json (#2200) * fix: remove trailing commas from keystore json * keyfile.nim: try a different Json formatting approach * build keystore * address comment --------- Co-authored-by: Ivan Folgueira Bande --- waku/waku_keystore/keyfile.nim | 43 ++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/waku/waku_keystore/keyfile.nim b/waku/waku_keystore/keyfile.nim index 7bcd407ab5..70fe6802d6 100644 --- a/waku/waku_keystore/keyfile.nim +++ b/waku/waku_keystore/keyfile.nim @@ -92,6 +92,23 @@ type DKey = array[DKLen, byte] KfResult*[T] = Result[T, KeyFileError] + # basic types for building Keystore JSON + CypherParams = object + iv: string + + CryptoNew = object + cipher: string + cipherparams: CypherParams + ciphertext: string + kdf: string + kdfparams: JsonNode + mac: string + + KeystoreEntry = object + crypto: CryptoNew + id: string + version: string + const SupportedHashes = [ "sha224", "sha256", "sha384", "sha512", @@ -373,20 +390,20 @@ proc createKeyFileJson*(secret: openArray[byte], let params = ? kdfParams(kdfkind, toHex(salt, true), workfactor) - let json = %* - { - "crypto": { - "cipher": $cryptkind, - "cipherparams": { - "iv": toHex(iv, true) - }, - "ciphertext": toHex(ciphertext, true), - "kdf": $kdfkind, - "kdfparams": params, - "mac": toHex(mac.data, true), - }, - } + var obj = KeystoreEntry( + crypto: CryptoNew( + cipher: $cryptkind, + cipherparams: CypherParams( + iv: toHex(iv, true) + ), + ciphertext: toHex(ciphertext, true), + kdf: $kdfkind, + kdfparams: params, + mac: toHex(mac.data, true) + ) + ) + let json = %* obj if IdInKeyfile: json.add("id", %($u)) if VersionInKeyfile: