Merge pull request #168 from dcousens/167fix

Fixes #167
This commit is contained in:
Wei Lu 2014-05-04 10:11:19 +08:00
commit a830e2cded
2 changed files with 13 additions and 1 deletions

View file

@ -205,6 +205,7 @@ HDWallet.prototype.derive = function(i) {
I = HmacFromBytesToBytes(SHA512, KPar.concat(iBytes), cPar) I = HmacFromBytesToBytes(SHA512, KPar.concat(iBytes), cPar)
} }
// FIXME: Boo, CSJ.algo.SHA512 uses byte arrays // FIXME: Boo, CSJ.algo.SHA512 uses byte arrays
I = new Buffer(I) I = new Buffer(I)
@ -225,7 +226,7 @@ HDWallet.prototype.derive = function(i) {
hd.pub = hd.priv.pub hd.pub = hd.priv.pub
} else { } else {
// Ki = (IL + kpar)*G = IL*G + Kpar // Ki = (IL + kpar)*G = IL*G + Kpar
var Ki = IL.multiply(ecparams.getG()).add(this.pub.Q) var Ki = ecparams.getG().multiply(IL).add(this.pub.Q)
hd.pub = new ECPubKey(Ki, true) hd.pub = new ECPubKey(Ki, true)
} }

View file

@ -231,6 +231,17 @@ describe('HDWallet', function() {
}) })
}) })
describe('derive', function() {
describe('m/0', function() {
it('works', function() {
var wallet = HDWallet.fromBase58('xpub6CxuB8ifZCMXeS3KbyNkYvrsJEHqxedCSiUhrNwH1nKtb8hcJpxDbDxkdoVCTR2bQ1G8hY4UMv85gef9SEpgFFUftBjt37FUSZxVx4AU9Qh').derive(0)
assert.equal(wallet.depth, 4)
assert.equal(wallet.toBase58(), 'xpub6DyYbqDaPgHkj1Sk5EaqC4HgGN7xRePCGJeei9En2kCK8kZk8HRnnPuKSbNX6vwQVvmYnTPhK8vpUEXTBd5BQ9MUKBewhGJtL49YuUfQwJw')
})
})
})
describe('network types', function() { describe('network types', function() {
it('ensures that a bitcoin Wallet generates bitcoin addresses', function() { it('ensures that a bitcoin Wallet generates bitcoin addresses', function() {
var wallet = new HDWallet(new Buffer('foobar'), 'bitcoin') var wallet = new HDWallet(new Buffer('foobar'), 'bitcoin')