Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove trailing commas from keystore json #2200

Merged
merged 9 commits into from
Dec 1, 2023
42 changes: 29 additions & 13 deletions waku/waku_keystore/keyfile.nim
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,22 @@ proc compareMac(m1: openArray[byte], m2: openArray[byte]): bool =
else:
return false

type CypherParams = object
iv: string

type CryptoNew = object
cipher: string
cipherparams: CypherParams
ciphertext: string
kdf: string
kdfparams: JsonNode
mac: string

type KeystoreEntry = object
crypto: CryptoNew
id: string
version: string

weboko marked this conversation as resolved.
Show resolved Hide resolved
# Creates a keyfile for secret encrypted with password according to the other parameters
# Returns keyfile in JSON according to Web3 Secure storage format (here, differently than standard, version and id are optional)
proc createKeyFileJson*(secret: openArray[byte],
Expand Down Expand Up @@ -373,20 +389,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
Loading