Skip to content

Commit

Permalink
fix: remove trailing commas from keystore json (#2200)
Browse files Browse the repository at this point in the history
* 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 <ivansete@status.im>
  • Loading branch information
weboko and Ivansete-status committed Dec 1, 2023
1 parent c86dc44 commit 103d398
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions waku/waku_keystore/keyfile.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 103d398

Please sign in to comment.