cryptocoinjs / hdkey

JavaScript component for Bitcoin hierarchical deterministic keys (BIP32)
MIT License
201 stars 74 forks source link

Getting same output for any input to "fromMasterSeed" #23

Closed alexander-morris closed 6 years ago

alexander-morris commented 6 years ago

I was excited to find your module but it looks like there might be a minor issue.

When I run the following script, it doesn't seem that the seed is being regenerated on each occurrence:

var HDKey = require('hdkey') for ( var i = 0; i < 10; i++ ) { var str = "str" + i; console.log(str) var master_seed = HDKey.fromMasterSeed(new Buffer.from(str, 'hex')) console.log(master_seed._privateKey)
}

which produces

str0 <Buffer 30 0b 15 5f 75 19 64 27 6c 05 36 23 0b d9 b1 6f e7 a8 65 33 c3 cb aa 75 75 e8 d0 43 1d be df 23> str1 <Buffer 30 0b 15 5f 75 19 64 27 6c 05 36 23 0b d9 b1 6f e7 a8 65 33 c3 cb aa 75 75 e8 d0 43 1d be df 23> str2 <Buffer 30 0b 15 5f 75 19 64 27 6c 05 36 23 0b d9 b1 6f e7 a8 65 33 c3 cb aa 75 75 e8 d0 43 1d be df 23> str3 <Buffer 30 0b 15 5f 75 19 64 27 6c 05 36 23 0b d9 b1 6f e7 a8 65 33 c3 cb aa 75 75 e8 d0 43 1d be df 23> str4 <Buffer 30 0b 15 5f 75 19 64 27 6c 05 36 23 0b d9 b1 6f e7 a8 65 33 c3 cb aa 75 75 e8 d0 43 1d be df 23> str5 <Buffer 30 0b 15 5f 75 19 64 27 6c 05 36 23 0b d9 b1 6f e7 a8 65 33 c3 cb aa 75 75 e8 d0 43 1d be df 23> str6 <Buffer 30 0b 15 5f 75 19 64 27 6c 05 36 23 0b d9 b1 6f e7 a8 65 33 c3 cb aa 75 75 e8 d0 43 1d be df 23> str7 <Buffer 30 0b 15 5f 75 19 64 27 6c 05 36 23 0b d9 b1 6f e7 a8 65 33 c3 cb aa 75 75 e8 d0 43 1d be df 23> str8 <Buffer 30 0b 15 5f 75 19 64 27 6c 05 36 23 0b d9 b1 6f e7 a8 65 33 c3 cb aa 75 75 e8 d0 43 1d be df 23> str9 <Buffer 30 0b 15 5f 75 19 64 27 6c 05 36 23 0b d9 b1 6f e7 a8 65 33 c3 cb aa 75 75 e8 d0 43 1d be df 23>

RyanZim commented 6 years ago

str0 isn't a valid hex string, so you're generating the hdkey from an empty buffer regardless of the string. This works:

var HDKey = require('hdkey')
for ( var i = 0; i < 10; i++ ) {
var str = "str" + i;
console.log(str)
var master_seed = HDKey.fromMasterSeed(Buffer.from(str, 'utf8'))
console.log(master_seed._privateKey)
}
alexander-morris commented 6 years ago

D'oh. Thanks Ryan!