Allow Secret Storage wallet address to be optional (#582).

This commit is contained in:
Richard Moore 2019-08-22 15:22:20 -04:00
parent d719064628
commit 24f243e689
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
5 changed files with 18 additions and 7 deletions

@ -171,7 +171,7 @@ export function decrypt(json: string, password: Arrayish, progressCallback?: Pro
}
var signingKey = new SigningKey(privateKey);
if (signingKey.address !== getAddress(data.address)) {
if (data.address && signingKey.address !== getAddress(data.address)) {
reject(new Error('address mismatch'));
return null;
}

@ -6,6 +6,7 @@ var path = require('path');
var utils = require('../utils.js');
function prefixAddress(address) {
if (!address) { return null; }
if (address.substring(0, 2) !== '0x') {
address = '0x' + address;
}
@ -25,6 +26,10 @@ Output.push({
});
*/
var addresses = {
"582": "0x008aeeda4d805471df9b2a5b0f38a0c3bcba786b"
};
var privateKeys = {
'0x0b88d4b324ec24c8c078551e6e5075547157e5b6': '0xd4375d2a931db84ea8825b69a3128913597744d9236cacec675cc18e1bda4446',
'0x2e326fa404fc3661de4f4361776ed9bbabdc26e3': '0xcf367fc32bf789b3339c6664af4a12263e9db0e0eb70f247da1d1165e150c487',
@ -33,7 +38,8 @@ var privateKeys = {
'0x88a5c2d9919e46f883eb62f7b8dd9d0cc45bc290': '0xf03e581353c794928373fb0893bc731aefc4c4e234e643f3a46998b03cd4d7c5',
'0x17c5185167401ed00cf5f5b2fc97d9bbfdb7d025': '0x4242424242424242424242424242424242424242424242424242424242424242',
'0x012363d61bdc53d0290a0f25e9c89f8257550fb8': '0x4c94faa2c558a998d10ee8b2b9b8eb1fbcb8a6ac5fd085c6f95535604fc1bffb',
'0x15db397ed5f682acb22b0afc6c8de4cdfbda7cbc': '0xcdf3c34a2ea0ff181f462856168f5851e68c37b583eb158403e43aeab4964fee'
'0x15db397ed5f682acb22b0afc6c8de4cdfbda7cbc': '0xcdf3c34a2ea0ff181f462856168f5851e68c37b583eb158403e43aeab4964fee',
'0x008aeeda4d805471df9b2a5b0f38a0c3bcba786b': '0x7a28b5ba57c53603b0b07b56bba752f7784bf506fa95edc395f5cf6c7514fe9d'
}
var mnemonics = {
@ -62,14 +68,16 @@ fs.readdirSync(walletPath).forEach(function(filename) {
});
} else {
let address = (addresses[name] || prefixAddress(data.address));
Output.push({
type: 'secret-storage',
address: prefixAddress(data.address),
hasAddress: !addresses[name],
address: address,
json: JSON.stringify(data),
mnemonic: mnemonics[prefixAddress(data.address)] || '',
mnemonic: mnemonics[address] || '',
name: name,
password: password,
privateKey: privateKeys[prefixAddress(data.address)],
privateKey: privateKeys[address],
});
}
});

@ -0,0 +1 @@
{"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"6087dab2f9fdbbfaddc31a909735c1e6"},"ciphertext":"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46","kdf":"pbkdf2","kdfparams":{"c":262144,"dklen":32,"prf":"hmac-sha256","salt":"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"},"mac":"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"},"id":"3198bc9c-6672-5ab3-d995-4942343ae5b6","version":3}

@ -12,8 +12,10 @@ describe('Test JSON Wallets', function() {
it(('decrypts wallet - ' + test.name), function() {
this.timeout(1200000);
assert.ok((ethers.utils.getJsonWalletAddress(test.json) !== null),
'detect encrypted JSON wallet');
if (test.hasAddress) {
assert.ok((ethers.utils.getJsonWalletAddress(test.json) !== null),
'detect encrypted JSON wallet');
}
return Wallet.fromEncryptedJson(test.json, test.password).then(function(wallet) {
assert.equal(wallet.privateKey, test.privateKey,

Binary file not shown.