Skip to content

Commit 4c039b8

Browse files
committed
Add tests for generated hd priv keys
1 parent 279bb8f commit 4c039b8

File tree

2 files changed

+100
-19
lines changed

2 files changed

+100
-19
lines changed

test/fixtures/keystore.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,70 @@
149149
"ent1" : "c",
150150
"targetHash" : "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
151151
}
152+
],
153+
"mnemonicSeedTests": [
154+
{
155+
"password" : "password",
156+
"salt": "lightwalletSalt",
157+
"pwDerivedKey" : [12, 37, 184, 176, 141, 255, 15, 70, 189, 195, 206, 218, 109, 172, 141, 233, 117, 114, 2, 10, 156, 57, 255, 102, 37, 66, 2, 177, 82, 70, 1, 246],
158+
"mnSeed": "jelly better achieve collect unaware mountain thought cargo oxygen act hood bridge",
159+
"hdRootPriv": "xprv9s21ZrQH143K3vCy7FkijuhZgUbbTSGwrWmvwyLsW7bHDwtE3x5fXLfMTX4N3sHGfCRwRr9n7R5fGg5y6sRhbQN7J58mu1gbMputHnrZYAw"
160+
},
161+
{
162+
"password" : "asdflknwqeroilasdflkjnzvmnwmet",
163+
"salt": "lightwalletSalt",
164+
"pwDerivedKey" : [24,100,147,66,23,117,206,186,27,54,254,137,187,174,103,5,38,18,139,128,139,74,217,188,166,34,0,30,54,133,158,208],
165+
"mnSeed": "afford alter spike radar gate glance object seek swamp infant panel yellow",
166+
"hdRootPriv": "xprv9s21ZrQH143K4F3jaSGsPkj54F6VXF3DZxjb69DH4AVmoYanpgwLA8RqQMXV1nbXyQrsXzwiY15sxt3sgh4rD61S6aXd5DmVSvbonWem6HR"
167+
},
168+
{
169+
"password" : "!@&#*#()",
170+
"salt": "lightwalletSalt",
171+
"pwDerivedKey" : [51,238,218,224,61,216,29,19,249,245,254,125,54,245,160,253,1,73,137,234,137,138,109,226,61,11,128,41,76,115,80,43],
172+
"mnSeed": "turtle front uncle idea crush write shrug there lottery flower risk shell",
173+
"hdRootPriv": "xprv9s21ZrQH143K3ENdSTFWNa61Dpo7TyVwXdNGnr9LX4UGqEJgCxGhnDmAeVZTPTddYgpDPTQqyruHCyuRHx5yAbnLSzce4GhGHWmXLyi3ujA"
174+
},
175+
{
176+
"password" : "PassHello",
177+
"salt": "lightwalletSalt",
178+
"pwDerivedKey" : [113,91,117,133,102,129,128,16,251,116,91,122,215,255,183,202,72,108,222,129,238,46,143,236,132,13,127,227,110,202,254,112],
179+
"mnSeed": "board flee heavy tunnel powder denial science ski answer betray cargo cat",
180+
"hdRootPriv": "xprv9s21ZrQH143K33giBRhHYG2HGme23pHx8zPWqM7H6jVuj5Uz47GefcuhFf4U8AtCRQVpGZRrSfgz8A4v7v9rFUG1eyYvL9Z1GhDEjCRVWdd"
181+
},
182+
{
183+
"password" : "password",
184+
"salt": "strangeSalt",
185+
"pwDerivedKey": [205, 127, 41, 55, 40, 243, 95, 138, 187, 239, 244, 242, 33, 239, 174, 4, 146, 184, 75, 185, 221, 160, 223, 207, 124, 49, 16, 208, 237, 141, 15, 120],
186+
"mnSeed": "そいとげる かぶか しちりん かわく がいらい けしごむ ときおり くさい そっこう さめる たいまつばな うすめる",
187+
"hdRootPriv": "xprv9s21ZrQH143K4ZC7EcgBoLbGp4BRVNNGhQZ1KCtMxYNkKXELKKe97BkPu9xj2M7NhksgyApceqk8wJANuNwhHR4DzsakecLhR28aCwk5XHd"
188+
},
189+
{
190+
"password" : "password",
191+
"salt": "strangeSalt",
192+
"pwDerivedKey": [205, 127, 41, 55, 40, 243, 95, 138, 187, 239, 244, 242, 33, 239, 174, 4, 146, 184, 75, 185, 221, 160, 223, 207, 124, 49, 16, 208, 237, 141, 15, 120],
193+
"mnSeed": "conocer cero abeja falso crónica norma clínica vivaz pañuelo tubería innato género",
194+
"hdRootPriv": "xprv9s21ZrQH143K2ZciTt8VLGEYMuqt9jV6LyHWES2TipbgiRjEGE547Y3SfJZcDphfT2ysr48e7kzScN2xJJ4r8yR2RnFLurvDo7WA2xRqfnu"
195+
},
196+
{
197+
"password" : "password",
198+
"salt": "strangeSalt",
199+
"pwDerivedKey": [205, 127, 41, 55, 40, 243, 95, 138, 187, 239, 244, 242, 33, 239, 174, 4, 146, 184, 75, 185, 221, 160, 223, 207, 124, 49, 16, 208, 237, 141, 15, 120],
200+
"mnSeed": "标 叫 是 控 专 网 约 堵 怪 胺 居 医",
201+
"hdRootPriv": "xprv9s21ZrQH143K2uixweugxzUnaxgxrWyy6oPuf3JAvFNLQTYc5a7PJRxK99bzomR2RPLve6z68zVdHTsbheYYcUBsbFeQiFt5o8Yk3XqnsCu"
202+
},
203+
{
204+
"password" : "password",
205+
"salt": "strangeSalt",
206+
"pwDerivedKey": [205, 127, 41, 55, 40, 243, 95, 138, 187, 239, 244, 242, 33, 239, 174, 4, 146, 184, 75, 185, 221, 160, 223, 207, 124, 49, 16, 208, 237, 141, 15, 120],
207+
"mnSeed": "rouge racine arriver sucre chute phrase moqueur désigner arriver décembre nuancer chien",
208+
"hdRootPriv": "xprv9s21ZrQH143K2Mg2MDBrYxpmZ7MUarcQnF9G1jzKU4MSZoNfjepSwZTZF83JZB42pdwydCtgLp2PrKbPLXSSEQXwaeSitQ7qzSNzVNUPDY8"
209+
},
210+
{
211+
"password" : "password",
212+
"salt": "strangeSalt",
213+
"pwDerivedKey": [205, 127, 41, 55, 40, 243, 95, 138, 187, 239, 244, 242, 33, 239, 174, 4, 146, 184, 75, 185, 221, 160, 223, 207, 124, 49, 16, 208, 237, 141, 15, 120],
214+
"mnSeed": "smeraldo scodella arso tecnico continuo rischio peso eletto arso domato prefisso comodo",
215+
"hdRootPriv": "xprv9s21ZrQH143K4AucDHZwwJKWYXT3X5FNAK4cfWGHR8dMrdvuJk2jv5SoiBD21hPtB4VTNLeWh7sVyaiVHjV5oEvzQuDyyyviZQPxjRxoaUd"
216+
}
152217
]
153218
}

test/keystore.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@ var Transaction = require('ethereumjs-tx');
1717
describe("Keystore", function() {
1818

1919
describe("createVault constructor", function() {
20-
it('accepts a variety of options', function(done) {
21-
var fixture = fixtures.valid[0];
22-
23-
keyStore.createVault({
24-
password: fixture.password,
25-
seedPhrase: fixture.mnSeed,
26-
salt: fixture.salt,
27-
}, function(err, ks) {
28-
expect(ks.encSeed).to.not.equal(undefined);
29-
var decryptedPaddedSeed = keyStore._decryptString(ks.encSeed, Uint8Array.from(fixtures.valid[0].pwDerivedKey));
30-
// Check padding
31-
expect(decryptedPaddedSeed.length).to.equal(120);
32-
expect(decryptedPaddedSeed.trim()).to.equal(fixtures.valid[0].mnSeed);
33-
done();
34-
});
35-
});
36-
3720
Object.keys(Mnemonic.Words).forEach(function (lang) {
3821
it('should generete random seed of language ' + lang, function (done) {
3922
var fixture = fixtures.valid[0];
@@ -45,8 +28,7 @@ describe("Keystore", function() {
4528
}, function (err, ks) {
4629
if (err) return done(err)
4730
expect(ks.encSeed).to.not.equal(undefined);
48-
var decryptedPaddedSeed = keyStore._decryptString(ks.encSeed, Uint8Array.from(fixtures.valid[0].pwDerivedKey));
49-
// Check padding
31+
var decryptedPaddedSeed = keyStore._decryptString(ks.encSeed, Uint8Array.from(fixture.pwDerivedKey));
5032
var words = decryptedPaddedSeed.trim().split(/\s/);
5133
words.forEach(function (w) {
5234
expect(Mnemonic.Words[lang].indexOf(w)).to.not.equal(-1, 'word ' + w + ' is not in dictionary');
@@ -56,6 +38,40 @@ describe("Keystore", function() {
5638
});
5739
})
5840

41+
fixtures.mnemonicSeedTests.forEach(function (fixture) {
42+
it('should store mnemonic seed "' + fixture.mnSeed + '"', function (done) {
43+
keyStore.createVault({
44+
password: fixture.password,
45+
seedPhrase: fixture.mnSeed,
46+
salt: fixture.salt,
47+
}, function(err, ks) {
48+
if (err) return done(err)
49+
expect(ks.encSeed).to.not.equal(undefined);
50+
var decryptedPaddedSeed = keyStore._decryptString(ks.encSeed, Uint8Array.from(fixture.pwDerivedKey));
51+
// Check padding
52+
expect(decryptedPaddedSeed.length).to.equal(120);
53+
expect(decryptedPaddedSeed.trim()).to.equal(fixture.mnSeed);
54+
done();
55+
});
56+
})
57+
});
58+
59+
fixtures.mnemonicSeedTests.forEach(function (fixture) {
60+
it('should generate HD root key for seed "' + fixture.mnSeed + '"', function (done) {
61+
keyStore.createVault({
62+
password: fixture.password,
63+
seedPhrase: fixture.mnSeed,
64+
salt: fixture.salt,
65+
}, function (err, ks) {
66+
if (err) return done(err)
67+
expect(ks.encSeed).to.not.equal(undefined);
68+
var decryptedHdRootPriv = keyStore._decryptString(ks.encHdRootPriv, Uint8Array.from(fixture.pwDerivedKey));
69+
expect(decryptedHdRootPriv.trim()).to.equal(fixture.hdRootPriv);
70+
done();
71+
});
72+
});
73+
});
74+
5975
it('generates a random salt for key generation', function(done) {
6076
this.timeout(10000);
6177
var fixture = fixtures.valid[0];

0 commit comments

Comments
 (0)