diff --git a/config.json b/config.json index 7845c37..d0c3e61 100644 --- a/config.json +++ b/config.json @@ -53,7 +53,7 @@ "keystore": { "kdf": "pbkdf2", "cipherAlg": "aes-128-ctr", - "c": 262144 + "c": 10000 } }, "cosmos": { diff --git a/src/chains/iris/crypto.js b/src/chains/iris/crypto.js index 8e75d77..69396e9 100644 --- a/src/chains/iris/crypto.js +++ b/src/chains/iris/crypto.js @@ -69,7 +69,7 @@ class IrisCrypto extends Crypto { } // @see:https://github.com/binance-chain/javascript-sdk/blob/master/src/crypto/index.js - exportKeystore(privateKeyHex,password){ + exportKeystore(privateKeyHex,password,opts = {}){ if (Utils.isEmpty(password) || password.length < 8){ throw new Error("password's length must be greater than 8") } @@ -78,14 +78,15 @@ class IrisCrypto extends Crypto { } const salt = Cryp.randomBytes(32); const iv = Cryp.randomBytes(16); - const cipherAlg = Config.iris.keystore.cipherAlg; - const kdf = Config.iris.keystore.kdf; + const cipherAlg = opts.cipherAlg ? opts.cipherAlg : Config.iris.keystore.cipherAlg; + const kdf = opts.kdf ? opts.kdf : Config.iris.keystore.kdf; + const c = opts.c ? opts.c : Config.iris.keystore.c; const address = this.import(privateKeyHex).address; const kdfparams = { dklen: 32, salt: salt.toString("hex"), - c: Config.iris.keystore.c, + c: c, prf: "hmac-sha256" }; const derivedKey = Cryp.pbkdf2Sync(Buffer.from(password), salt, kdfparams.c, kdfparams.dklen, "sha256"); diff --git a/test/keystore.json b/test/keystore.json index 2fee29e..1a58314 100644 --- a/test/keystore.json +++ b/test/keystore.json @@ -1 +1 @@ -{"version":"1","id":"65177bc2-8240-4024-8180-dd0b2d888903","address":"faa1ljemm0yznz58qxxs8xyak7fashcfxf5lssn6jm","crypto":{"ciphertext":"793acc81ed7d3f8aead7872f81cc7297e0527ab9ee87a24f8aa7de6a6b4072e9","cipherparams":{"iv":"7ebe22befa6b278f0f348fe9e3f7c524"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"0fa96f07f73d3dfe2bff410b708de347080a326c898e2d5631af4d598e851401","c":262144,"prf":"hmac-sha256"},"mac":"15467c52ade57fd59200544612cccd2310825f8378d3f52228b52d07b56fbdba"}} \ No newline at end of file +{"version":"1","id":"cdda101b-cb44-4daf-8ed6-2a28b1289f6c","address":"faa1ljemm0yznz58qxxs8xyak7fashcfxf5lssn6jm","crypto":{"ciphertext":"03878b0196704fcfe13f56f9e12ff003c9c33b249e87b981ca0c8763ebe085f1","cipherparams":{"iv":"4848b511d0647dd572c4d1dfa9f65289"},"cipher":"aes-128-ctr","kdf":"pbkdf2","kdfparams":{"dklen":32,"salt":"06f0a45bd8f512d17349723da67d1eddbfac1cc497b6cbd2ad8a2852376d76db","c":10000,"prf":"hmac-sha256"},"mac":"f6c13e10eb8496847710bcedde95b5bf9aed85a834ce05c7b7eb01db05f26568"}} \ No newline at end of file