jwallet-web-keystore
Advanced tools
Comparing version
@@ -255,3 +255,3 @@ 'use strict'; | ||
if (type === this.mnemonicType) { | ||
return R.compose(R.assoc('bip32XPublicKey', bip32XPublicKey)(walletData), isReadOnly ? R.identity : R.assoc('mnemonic', this._decryptData(encrypted.mnemonic, password, salt)))(walletData); | ||
return R.compose(R.assoc('bip32XPublicKey', bip32XPublicKey), isReadOnly ? R.identity : R.assoc('mnemonic', this._decryptData(encrypted.mnemonic, password, salt).trim()))(walletData); | ||
} | ||
@@ -277,4 +277,2 @@ | ||
this._restoreBackupData(data); | ||
return data; | ||
} catch (err) { | ||
@@ -281,0 +279,0 @@ throw new Error('Failed to parse backup data'); |
@@ -15,7 +15,17 @@ 'use strict'; | ||
var addSaltForWallets = function addSaltForWallets(wallet) { | ||
return R.assoc('salt', salt)(wallet); | ||
var prepareWallet = function prepareWallet(wallet) { | ||
var accountName = wallet.accountName, | ||
type = wallet.type, | ||
isReadOnly = wallet.isReadOnly; | ||
var mnemonicType = isReadOnly ? 'bip32Xpub' : 'mnemonic'; | ||
var addressType = isReadOnly ? 'address' : 'privateKey'; | ||
var customType = type === 'mnemonic' ? mnemonicType : addressType; | ||
return R.compose(R.assoc('name', accountName), R.assoc('customType', customType), R.assoc('salt', isReadOnly ? null : salt))(wallet); | ||
}; | ||
var newWallets = R.map(addSaltForWallets)(accounts); | ||
var newWallets = R.map(prepareWallet)(accounts); | ||
return R.compose(R.assoc('version', '0.7.0'), R.assoc('wallets', R.concat(wallets || [])(newWallets)))(backupData); | ||
@@ -22,0 +32,0 @@ }; |
{ | ||
"name": "jwallet-web-keystore", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"description": "Library for ethereum blockchain accounts management", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"lint": "./node_modules/.bin/eslint ./src", | ||
"test": "./node_modules/.bin/mocha --compilers babel-register", | ||
"test": "./node_modules/.bin/mocha --compilers babel-register --recursive", | ||
"clean": "rm -rf ./lib", | ||
@@ -11,0 +11,0 @@ "compile": "npm run clean && ./node_modules/.bin/babel ./src --out-dir ./lib", |
@@ -343,6 +343,2 @@ # jwallet-web-keystore | ||
##### Returns | ||
Deserialized keystore data for restoring of backup. | ||
##### Example | ||
@@ -352,3 +348,3 @@ | ||
const backupData = '{"wallets":[{"type":"mnemonic","id":"2e820ddb-a9ce-43e1-b7ec-dbed59eec7e9",...' | ||
const keystoreDeserializedData = keystore.deserialize(backupData) | ||
keystore.deserialize(backupData) | ||
``` | ||
@@ -355,0 +351,0 @@ |
@@ -198,7 +198,11 @@ const should = require('should') | ||
it('getDecryptedWallet() should get current private key', function(done) { | ||
it('getDecryptedWallet() should return wallet data (with decrypted private key)', function(done) { | ||
const decryptedWallet = keystore.getDecryptedWallet(newPassword, walletId) | ||
decryptedWallet.should.be.an.Object() | ||
decryptedWallet.id.should.be.equal(walletId) | ||
decryptedWallet.readOnly.should.be.equal('no') | ||
decryptedWallet.type.should.be.equal('privateKey') | ||
decryptedWallet.name.should.be.equal(updatedWalletName) | ||
decryptedWallet.address.should.be.equal(privateKeyAddressPair.address) | ||
decryptedWallet.privateKey.should.be.equal(privateKeyAddressPair.privateKey) | ||
@@ -205,0 +209,0 @@ |
@@ -21,2 +21,3 @@ const should = require('should') | ||
bip32XPublicKeyCustomPath: 'xpub6EHUjFfkAkfqXkqkcZKNxa4Gx6ybxSfRFFeUYsBsqm2Eg2xrz7KWtAmW1pdJ6DNA852xkLtCPTbCinawRFm29WD4XLF8npKNQNpYa42cCwy', | ||
bip32XPublicKeyCustomPath2: 'xpub6EzL2PV6NukMTntAULEUcdyNTzPvJDPFnog6p5fQek1ANmCm7sP1wJAFhFwBbxGESbzacQbivU97vGpuqzGrc3rVKSV8htoegG5TsrtNGUM', | ||
} | ||
@@ -223,3 +224,3 @@ | ||
it('getPrivateKey() should get private key by index', function(done) { | ||
it('getPrivateKey() should get private key (with current index)', function(done) { | ||
const privateKey = keystore.getPrivateKey(password, walletId) | ||
@@ -232,2 +233,16 @@ | ||
}) | ||
it('getDecryptedWallet() should get wallet data (with decrypted mnemonic)', function(done) { | ||
const decryptedWallet = keystore.getDecryptedWallet(password, walletId) | ||
decryptedWallet.should.be.an.Object() | ||
decryptedWallet.name.should.be.equal(name) | ||
decryptedWallet.id.should.be.equal(walletId) | ||
decryptedWallet.readOnly.should.be.equal('no') | ||
decryptedWallet.type.should.be.equal('mnemonic') | ||
decryptedWallet.mnemonic.should.be.equal(mnemonicXPubPair.mnemonic) | ||
decryptedWallet.bip32XPublicKey.should.be.equal(mnemonicXPubPair.bip32XPublicKeyCustomPath2) | ||
done() | ||
}) | ||
}) |
@@ -191,2 +191,15 @@ const should = require('should') | ||
}) | ||
it('getDecryptedWallet() should return wallet data', function(done) { | ||
const wallet = keystore.getDecryptedWallet(password, walletId) | ||
wallet.should.be.an.Object() | ||
wallet.name.should.be.equal(name) | ||
wallet.id.should.be.equal(walletId) | ||
wallet.readOnly.should.be.equal('yes') | ||
wallet.type.should.be.equal('address') | ||
wallet.address.should.be.equal(privateKeyAddressPair.address) | ||
done() | ||
}) | ||
}) |
@@ -111,2 +111,15 @@ const should = require('should') | ||
it('getDecryptedWallet() should return wallet data', function(done) { | ||
const wallet = keystore.getDecryptedWallet(password, walletId) | ||
wallet.should.be.an.Object() | ||
wallet.name.should.be.equal(name) | ||
wallet.id.should.be.equal(walletId) | ||
wallet.readOnly.should.be.equal('yes') | ||
wallet.type.should.be.equal('bip32Xpub') | ||
wallet.bip32XPublicKey.should.be.equal(bip32XPublicKey) | ||
done() | ||
}) | ||
it('removeWallet() should throw error (incorrect walletId)', function(done) { | ||
@@ -113,0 +126,0 @@ try { |
@@ -45,9 +45,9 @@ const should = require('should') | ||
it('deserialize() should restore and return deserialized keystore data', function(done) { | ||
const deserializedKeystoreData = keystore.deserialize(serializedKeystoreData) | ||
keystore.deserialize(serializedKeystoreData) | ||
deserializedKeystoreData.should.be.an.Object() | ||
deserializedKeystoreData.wallets.should.be.an.Array() | ||
deserializedKeystoreData.wallets[0].should.be.an.Object() | ||
deserializedKeystoreData.wallets[0].id.should.be.equal(walletId) | ||
deserializedKeystoreData.version.should.be.equal(currentKeystoreVersion) | ||
keystore.getWallets().should.be.an.Array() | ||
keystore.getWallets().length.should.be.greaterThanOrEqual(1) | ||
keystore.getWallets()[0].should.be.an.Object() | ||
keystore.getWallet(walletId).id.should.be.equal(walletId) | ||
keystore.version.should.be.equal(currentKeystoreVersion) | ||
@@ -54,0 +54,0 @@ done() |
90363
9.37%23
4.55%1794
6.85%510
-0.78%