Skip to content
This repository was archived by the owner on Nov 14, 2023. It is now read-only.

Commit 63c292a

Browse files
authored
Merge pull request #109 from zhiqiang-bianjie/develop
R4R: Adjust keystore file to generate difficulty factor
2 parents d1f78f5 + e07a034 commit 63c292a

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"keystore": {
5454
"kdf": "pbkdf2",
5555
"cipherAlg": "aes-128-ctr",
56-
"c": 262144
56+
"c": 10000
5757
}
5858
},
5959
"cosmos": {

src/chains/iris/crypto.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class IrisCrypto extends Crypto {
6969
}
7070

7171
// @see:https://github.com/binance-chain/javascript-sdk/blob/master/src/crypto/index.js
72-
exportKeystore(privateKeyHex,password){
72+
exportKeystore(privateKeyHex,password,opts = {}){
7373
if (Utils.isEmpty(password) || password.length < 8){
7474
throw new Error("password's length must be greater than 8")
7575
}
@@ -78,14 +78,15 @@ class IrisCrypto extends Crypto {
7878
}
7979
const salt = Cryp.randomBytes(32);
8080
const iv = Cryp.randomBytes(16);
81-
const cipherAlg = Config.iris.keystore.cipherAlg;
82-
const kdf = Config.iris.keystore.kdf;
81+
const cipherAlg = opts.cipherAlg ? opts.cipherAlg : Config.iris.keystore.cipherAlg;
82+
const kdf = opts.kdf ? opts.kdf : Config.iris.keystore.kdf;
83+
const c = opts.c ? opts.c : Config.iris.keystore.c;
8384
const address = this.import(privateKeyHex).address;
8485

8586
const kdfparams = {
8687
dklen: 32,
8788
salt: salt.toString("hex"),
88-
c: Config.iris.keystore.c,
89+
c: c,
8990
prf: "hmac-sha256"
9091
};
9192
const derivedKey = Cryp.pbkdf2Sync(Buffer.from(password), salt, kdfparams.c, kdfparams.dklen, "sha256");

test/keystore.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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"}}
1+
{"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"}}

0 commit comments

Comments
 (0)