diff --git a/packages/caver-klay/caver-klay-accounts/src/index.js b/packages/caver-klay/caver-klay-accounts/src/index.js index 219acd23..493b400e 100644 --- a/packages/caver-klay/caver-klay-accounts/src/index.js +++ b/packages/caver-klay/caver-klay-accounts/src/index.js @@ -1393,7 +1393,8 @@ Accounts.prototype.decrypt = function(v3Keystore, password, nonStrict) { throw new Error('No password given.') } - const json = _.isObject(v3Keystore) ? v3Keystore : JSON.parse(nonStrict ? v3Keystore.toLowerCase() : v3Keystore) + // To deep copy an object, using JSON.parse and JSON.stringify (object -> string -> object) + const json = _.isObject(v3Keystore) ? _.cloneDeep(v3Keystore) : JSON.parse(nonStrict ? v3Keystore.toLowerCase() : v3Keystore) if (json.version !== 3 && json.version !== 4) { console.warn('This is not a V3 or V4 wallet.') diff --git a/packages/caver-wallet/src/keyring/keyringFactory.js b/packages/caver-wallet/src/keyring/keyringFactory.js index d3a62875..c80a14cc 100644 --- a/packages/caver-wallet/src/keyring/keyringFactory.js +++ b/packages/caver-wallet/src/keyring/keyringFactory.js @@ -209,7 +209,8 @@ class KeyringFactory { * @return {AbstractKeyring} */ static decrypt(keystore, password) { - const json = _.isObject(keystore) ? keystore : JSON.parse(keystore) + // To deep copy an object, using JSON.parse and JSON.stringify (object -> string -> object) + const json = _.isObject(keystore) ? _.cloneDeep(keystore) : JSON.parse(keystore) if (json.version !== 3 && json.version !== 4) console.warn('This is not a V3 or V4 wallet.') diff --git a/test/packages/caver.klay.accounts.js b/test/packages/caver.klay.accounts.js index 46f72762..81087075 100644 --- a/test/packages/caver.klay.accounts.js +++ b/test/packages/caver.klay.accounts.js @@ -3531,6 +3531,7 @@ describe('caver.klay.accounts.decrypt', () => { const result = caver.klay.accounts.decrypt(keystoreJsonV3, password) isAccount(result, { keys: expectedAccount.keys, address: expectedAccount.address }) + expect(keystoreJsonV3.crypto).not.to.be.undefined }).timeout(50000) }) diff --git a/test/packages/caver.wallet.keyring.js b/test/packages/caver.wallet.keyring.js index 90ac261b..dabe2b81 100644 --- a/test/packages/caver.wallet.keyring.js +++ b/test/packages/caver.wallet.keyring.js @@ -789,6 +789,7 @@ describe('caver.wallet.keyring.decrypt', () => { const result = caver.wallet.keyring.decrypt(keystoreJsonV3, password) validateKeyring(result, { keys: expectedAccount.keys, address: expectedAccount.address }) + expect(keystoreJsonV3.crypto).not.to.be.undefined }) }) })