|
@ -39,7 +39,7 @@ Object.defineProperty(HDKey.prototype, 'privateKey', { |
|
|
assert.equal(value.length, 32, 'Private key must be 32 bytes.') |
|
|
assert.equal(value.length, 32, 'Private key must be 32 bytes.') |
|
|
this._privateKey = value |
|
|
this._privateKey = value |
|
|
this._privateKeyInteger = BigInteger.fromBuffer(this._privateKey) |
|
|
this._privateKeyInteger = BigInteger.fromBuffer(this._privateKey) |
|
|
this._publicKey = ecparams.params.G.multiply(this._privateKeyInteger).getEncoded(true) //force compressed point
|
|
|
this._publicKey = ecparams.G.multiply(this._privateKeyInteger).getEncoded(true) //force compressed point
|
|
|
this._identifier = hash160(this.publicKey) |
|
|
this._identifier = hash160(this.publicKey) |
|
|
this._fingerprint = this._identifier.slice(0, 4).readUInt32BE(0) |
|
|
this._fingerprint = this._identifier.slice(0, 4).readUInt32BE(0) |
|
|
} |
|
|
} |
|
@ -128,10 +128,10 @@ HDKey.prototype.deriveChild = function(index) { |
|
|
// Private parent key -> private child key
|
|
|
// Private parent key -> private child key
|
|
|
if (this.privateKey) { |
|
|
if (this.privateKey) { |
|
|
// ki = parse256(IL) + kpar (mod n)
|
|
|
// ki = parse256(IL) + kpar (mod n)
|
|
|
var ki = pIL.add(BigInteger.fromBuffer(this.privateKey)).mod(ecparams.params.n) |
|
|
var ki = pIL.add(BigInteger.fromBuffer(this.privateKey)).mod(ecparams.n) |
|
|
|
|
|
|
|
|
// In case parse256(IL) >= n or ki == 0, one should proceed with the next value for i
|
|
|
// In case parse256(IL) >= n or ki == 0, one should proceed with the next value for i
|
|
|
if (pIL.compareTo(ecparams.params.n) >= 0 || ki.signum() === 0) { |
|
|
if (pIL.compareTo(ecparams.n) >= 0 || ki.signum() === 0) { |
|
|
return this.derive(index + 1) |
|
|
return this.derive(index + 1) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|