Browse Source

lib/hdkey: removed method getIdentifier() added property identifier

master
JP Richardson 11 years ago
parent
commit
6e6264636f
  1. 1
      CHANGELOG.md
  2. 20
      lib/hdkey.js

1
CHANGELOG.md

@ -7,6 +7,7 @@ x.y.z / 2014-06-dd
- added method `fromMasterSeed(seedBuffer, [versions])` - added method `fromMasterSeed(seedBuffer, [versions])`
- changed constructor from `new HDKey(masterSeed, [versions])` to `new HDKey([versions])` - changed constructor from `new HDKey(masterSeed, [versions])` to `new HDKey([versions])`
- added properties: `privateKey` and `publicKey` - added properties: `privateKey` and `publicKey`
- removed method `getIdentifier()`, added property `identifier`
0.0.1 / 2014-05-29 0.0.1 / 2014-05-29
------------------ ------------------

20
lib/hdkey.js

@ -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()
}

Loading…
Cancel
Save