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

Commit

Permalink
Merge pull request #109 from zhiqiang-bianjie/develop
Browse files Browse the repository at this point in the history
R4R: Adjust keystore file to generate difficulty factor
  • Loading branch information
zhangyelong authored Aug 28, 2019
2 parents d1f78f5 + e07a034 commit 63c292a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"keystore": {
"kdf": "pbkdf2",
"cipherAlg": "aes-128-ctr",
"c": 262144
"c": 10000
}
},
"cosmos": {
Expand Down
9 changes: 5 additions & 4 deletions src/chains/iris/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion test/keystore.json
Original file line number Diff line number Diff line change
@@ -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"}}
{"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 comments on commit 63c292a

Please sign in to comment.