diff --git a/CHANGELOG.md b/CHANGELOG.md index 9438651..e36903b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ x.y.z / 2014-06-dd - added method `fromMasterSeed(seedBuffer, [versions])` - changed constructor from `new HDKey(masterSeed, [versions])` to `new HDKey([versions])` - added properties: `privateKey` and `publicKey` +- removed method `getIdentifier()`, added property `identifier` 0.0.1 / 2014-05-29 ------------------ diff --git a/lib/hdkey.js b/lib/hdkey.js index cc3e5ca..ea22c63 100644 --- a/lib/hdkey.js +++ b/lib/hdkey.js @@ -27,6 +27,12 @@ function HDKey(versions) { this.chainCode = null } +Object.defineProperty(HDKey.prototype, 'identifier', { + get: function() { + return this._identifier + } +}) + Object.defineProperty(HDKey.prototype, 'privateKey', { get: function() { return this._privateKey @@ -36,6 +42,7 @@ Object.defineProperty(HDKey.prototype, 'privateKey', { this._privateKey = value this._privateKeyInteger = BigInteger.fromBuffer(this._privateKey) 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() { - return this.getIdentifier().slice(0, 4) + return this.identifier.slice(0, 4) } @@ -214,3 +215,8 @@ function serialize(hdkey, version, key) { return buffer } +function hash160(buf) { + var sha = crypto.createHash('sha256').update(buf).digest() + return crypto.createHash('rmd160').update(sha).digest() +} +