|
@ -27,6 +27,12 @@ function HDKey(versions) { |
|
|
this.chainCode = null |
|
|
this.chainCode = null |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(HDKey.prototype, 'identifier', { |
|
|
|
|
|
get: function() { |
|
|
|
|
|
return this._identifier |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
Object.defineProperty(HDKey.prototype, 'privateKey', { |
|
|
Object.defineProperty(HDKey.prototype, 'privateKey', { |
|
|
get: function() { |
|
|
get: function() { |
|
|
return this._privateKey |
|
|
return this._privateKey |
|
@ -36,6 +42,7 @@ Object.defineProperty(HDKey.prototype, 'privateKey', { |
|
|
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.params.G.multiply(this._privateKeyInteger).getEncoded(true) //force compressed point
|
|
|
|
|
|
this._identifier = hash160(this.publicKey) |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
@ -64,14 +71,8 @@ Object.defineProperty(HDKey.prototype, 'publicOld', { |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
HDKey.prototype.getIdentifier = function() { |
|
|
|
|
|
//just computing pubKeyHash here
|
|
|
|
|
|
var sha = crypto.createHash('sha256').update(this.publicKey).digest() |
|
|
|
|
|
return crypto.createHash('rmd160').update(sha).digest() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
HDKey.prototype.getFingerprint = function() { |
|
|
HDKey.prototype.getFingerprint = function() { |
|
|
return this.getIdentifier().slice(0, 4) |
|
|
return this.identifier.slice(0, 4) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -214,3 +215,8 @@ function serialize(hdkey, version, key) { |
|
|
return buffer |
|
|
return buffer |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function hash160(buf) { |
|
|
|
|
|
var sha = crypto.createHash('sha256').update(buf).digest() |
|
|
|
|
|
return crypto.createHash('rmd160').update(sha).digest() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|