Skip to content

Commit

Permalink
Port optional Secret Storage wallet address to v5 (#582).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Aug 22, 2019
1 parent 8745a81 commit a12d60d
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 21 deletions.
21 changes: 12 additions & 9 deletions packages/json-wallets/src.ts/keystore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,18 @@ export function decrypt(json: string, password: Bytes | string, progressCallback
return null;
}

let address = data.address.toLowerCase();
if (address.substring(0, 2) !== "0x") { address = "0x" + address; }

try {
if (getAddress(address) !== computeAddress(privateKey)) {
reject(new Error("address mismatch"));
return null;
}
} catch (e) { }
let address = computeAddress(privateKey);
if (data.address) {
let check = data.address.toLowerCase();
if (check.substring(0, 2) !== "0x") { check = "0x" + check; }

try {
if (getAddress(check) !== address) {
reject(new Error("address mismatch"));
return null;
}
} catch (e) { }
}

let account: any = {
_isKeystoreAccount: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"encseed": "3a7cc89f7d53d44d6e6445a2cf7fa359598f7914e1b4f808a1b55a13ea4cc71a5529782ba169bb0b169b29e4160c2d4d3167ed282267634ae326379cdf400bf82bc9512be11169bc1822fef4a17b9cf4ad685544ddfc793eafee573650f19185", "ethaddr": "0b88d4b324ec24c8c078551e6e5075547157e5b6", "email": "[email protected]", "btcaddr": "13pey9DLvYxeftGaGF1xgTfPYNmhu1fbm3"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"encseed": "e695362f72ab0a364385f35a3435300188300ee5220c03dcbcf461c62432b6679ab163abf476aefa5f8cf366eea73c8b7e28e8c0a79ef819634bb8ee1875253d05b3825076c514063a7ccd8f0f79ba352799571f8ec8b749f8508a638a9a891d", "ethaddr": "2e326fa404fc3661de4f4361776ed9bbabdc26e3", "email": "[email protected]", "btcaddr": "1GW9wXcbtFNV6N6Mxje82Tmjk2iB9fffaj"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"012363d61bdc53d0290a0f25e9c89f8257550fb8","id":"5ba8719b-faf9-49ec-8bca-21522e3d56dc","version":3,"Crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"bc0473d60284d2d6994bb6793e916d06"},"ciphertext":"e73ed0b0c53bcaea4516a15faba3f6d76dbe71b9b46a460ed7e04a68e0867dd7","kdf":"scrypt","kdfparams":{"salt":"97f0b6e17c392f76a726ceea02bac98f17265f1aa5cf8f9ad1c2b56025bc4714","n":131072,"dklen":32,"p":1,"r":8},"mac":"ff4f2db7e7588f8dd41374d7b98dfd7746b554c0099a6c0765be7b1c7913e1f3"},"x-ethers":{"client":"ethers.js","gethFilename":"UTC--2018-01-27T01-52-22.0Z--012363d61bdc53d0290a0f25e9c89f8257550fb8","mnemonicCounter":"70224accc00e35328a010a19fef51121","mnemonicCiphertext":"cf835e13e4f90b190052263dbd24b020","version":"0.1"}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":3,"id":"05D302EE-23DC-48C4-B89C-CAAAC1C780C4","x-ethers":{"gethFilename":"UTC--2018-01-26T20-25-02.0Z--15db397ed5f682acb22b0afc6c8de4cdfbda7cbc","mnemonicCiphertext":"b92c7c3da540ae7beee55365fb330c33","mnemonicCounter":"a65d689a73c096025f2acae3f7068510","client":"ethers/iOS","version":"0.1"},"Crypto":{"ciphertext":"fa6ff2374087a089ec9fcba3bc21389f5e26ec2932c95b608ebe0218efab83c6","cipherparams":{"iv":"5ddca45b254406516ca2c97d18d5dfd9"},"kdf":"scrypt","kdfparams":{"r":8,"p":1,"n":262144,"dklen":32,"salt":"864a474f8586ab0fa97ed9240ae6227b2b22b48bdf298137c355e4a07eb19831"},"mac":"eaa89325acedbf88c0893e53c8c8d426b590655746c66da9cd76e4f72d84084f","cipher":"aes-128-ctr"},"address":"15db397ed5f682acb22b0afc6c8de4cdfbda7cbc"}
Original file line number Diff line number Diff line change
@@ -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}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"17c5185167401ed00cf5f5b2fc97d9bbfdb7d025","id":"01234567-8901-4345-a789-012345678901","version":3,"Crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"deadbeef1deadbeef2deadbeef301234"},"ciphertext":"cea502df4b9405fa2b6d8d19ec4e2953c5ce08e0e01d4c0292512ce62baef8f3","kdf":"scrypt","kdfparams":{"salt":"abcd1abcd2abcd3abcd4abcd5abcd6ef","n":1024,"dklen":32,"p":2,"r":4},"mac":"6e0a8e2409261d464e35a251f4b1fddd6ad0f7045a18d3957c127387f1c0de72"}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":"a9b7570b-fd36-8a32-f4ea-26080a941143","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"1de99c07c6592eaac911ae9cf07db88d"},"ciphertext":"951ca34a268314c0cde0409566bcac4d4907dc87f34764fe8542786415cb5726","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"7d2ebe49878f15e031bcdf9f0be47e7d49542252145850b7862a08a0c209a0e9"},"mac":"dc595787a3d08d98e2d808a981b8e9566d8ed1087c0257481ffc1196e13d8c0a"},"address":"00a329c0648769a73afac7f9381e08fb43dbea72","name":"Blank","meta":"{\"passwordHint\":\"\",\"timestamp\":1495227675346}"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"4a9cf99357f5789251a8d7fad5b86d0f31eeb938","Crypto":{"cipher":"aes-128-ctr","ciphertext":"f93a875c23f5430bb86962da1ff2176d5b9179cfdd31e93027d67b0123e7a059","cipherparams":{"iv":"5fb35020cc5e84447a4b8a3a39543dbe"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"0d6bf5361b8c70745b8d03bb096876b27f00de2627b503b3f7c5ce9e8e70abe6"},"mac":"8f80f79e55cc36c231a00a69c43d603bd0cf8eb70bb9d77532cd7ddb56e4707e"},"id":"372b47d8-aba7-41a5-b3cd-a848b4f5aab1","version":3}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"88a5c2d9919e46f883eb62f7b8dd9d0cc45bc290","Crypto":{"cipher":"aes-128-ctr","ciphertext":"10adcc8bcaf49474c6710460e0dc974331f71ee4c7baa7314b4a23d25fd6c406","cipherparams":{"iv":"1dcdf13e49cea706994ed38804f6d171"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"bbfa53547e3e3bfcc9786a2cbef8504a5031d82734ecef02153e29daeed658fd"},"mac":"1cf53b5ae8d75f8c037b453e7c3c61b010225d916768a6b145adf5cf9cb3a703"},"id":"fb1280c0-d646-4e40-9550-7026b1be504a","version":3}
33 changes: 33 additions & 0 deletions packages/testcases/src.ts/generation-scripts/wallets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

import fs from "fs";
import { resolve } from "path";

import { saveTests, TestCase } from "..";

const testcases: Array<TestCase.Wallet> = [];

const mnemonics: { [ address: string ]: string } = {
'15db397ed5f682acb22b0afc6c8de4cdfbda7cbc': 'debris glass rich exotic window other film slow expose flight either wealth',
'012363d61bdc53d0290a0f25e9c89f8257550fb8': 'service basket parent alcohol fault similar survey twelve hockey cloud walk panel'
};

const inputDir = resolve(__dirname, "../input/wallets");
fs.readdirSync(inputDir).forEach((filename) => {
let content = fs.readFileSync(resolve(inputDir, filename)).toString();
let data = JSON.parse(content);
const comps = filename.split(".")[0].split("-");
testcases.push({
name: comps[1],
type: (data.ethaddr ? "crowdsale": "secret-storage"),
hasAddress: !!data.address,
address: ("0x" + comps[2]),
privateKey: ("0x" + comps[3]),
mnemonic: (mnemonics[comps[2]] || null),
password: comps[4],
json: content
});
});

saveTests("wallets", testcases);

11 changes: 11 additions & 0 deletions packages/testcases/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ export module TestCase {
flags?: string;
};

export type Wallet = {
name: string;
type: "crowdsale" | "secret-storage";
hasAddress: boolean;
address: string;
privateKey: string;
mnemonic?: string;
password?: string;
json: string;
};

export type Wordlist = {
locale: string;
content: string;
Expand Down
Binary file modified packages/testcases/testcases/wallets.json.gz
Binary file not shown.
18 changes: 6 additions & 12 deletions packages/tests/src.ts/test-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,22 @@
import assert from "assert";

import { ethers } from "ethers";
import { loadTests } from "@ethersproject/testcases";
import { loadTests, TestCase } from "@ethersproject/testcases";

import * as utils from "./utils";


describe('Test JSON Wallets', function() {
type TestCase = {
name: string;
json: string;
password: string;
address: string;
privateKey: string;
mnemonic: string;
};

let tests: Array<TestCase> = loadTests('wallets');
let tests: Array<TestCase.Wallet> = loadTests('wallets');
tests.forEach(function(test) {
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 ethers.Wallet.fromEncryptedJson(test.json, test.password).then((wallet) => {
assert.equal(wallet.privateKey, test.privateKey,
Expand Down

0 comments on commit a12d60d

Please sign in to comment.