Browse Source

renamed private to privateExtendedKey, renamed public to publicExtendedKey

master
JP Richardson 11 years ago
parent
commit
e0846232c2
  1. 2
      CHANGELOG.md
  2. 16
      lib/hdkey.js
  3. 4
      test/hdkey.test.js

2
CHANGELOG.md

@ -9,6 +9,8 @@ x.y.z / 2014-06-dd
- added properties: `privateKey` and `publicKey`
- removed method `getIdentifier()`, added property `identifier`
- removed method `getFingerprint()`, added property `fingerprint`
- renamed `private` to `privateExtendedKey`
- renamed `public` to `publicExtendedKey`
0.0.1 / 2014-05-29
------------------

16
lib/hdkey.js

@ -12,8 +12,6 @@ var MASTER_SECRET = new Buffer('Bitcoin seed')
var HARDENED_OFFSET = 0x80000000
var LEN = 78
var N = ecparams.params.n
//Bitcoin hardcoded by default, can use package `coininfo` for others
var BITCOIN_VERSIONS = {private: 0x0488ADE4, public: 0x0488B21E}
@ -56,13 +54,13 @@ Object.defineProperty(HDKey.prototype, 'publicKey', {
}
})
Object.defineProperty(HDKey.prototype, 'privateOld', {
Object.defineProperty(HDKey.prototype, 'privateExtendedKey', {
get: function() {
return serialize(this, this.versions.private, Buffer.concat([new Buffer([0]), this.privateKey]))
}
})
Object.defineProperty(HDKey.prototype, 'publicOld', {
Object.defineProperty(HDKey.prototype, 'publicExtendedKey', {
get: function() {
return serialize(this, this.versions.public, this.publicKey)
}
@ -74,7 +72,7 @@ HDKey.prototype.derive = function(path) {
return this
var entries = path.split('/')
var hkey = this
var hdkey = this
entries.forEach(function(c, i) {
if (i == 0) {
assert(c, 'm', 'Invalid path')
@ -86,10 +84,10 @@ HDKey.prototype.derive = function(path) {
assert(childIndex < HARDENED_OFFSET, 'Invalid index')
if (hardened) childIndex += HARDENED_OFFSET
hkey = hkey.deriveChild(childIndex)
hdkey = hdkey.deriveChild(childIndex)
})
return hkey
return hdkey
}
HDKey.prototype.deriveChild = function(index) {
@ -124,10 +122,10 @@ HDKey.prototype.deriveChild = function(index) {
// Private parent key -> private child key
if (this.privateKey) {
// ki = parse256(IL) + kpar (mod n)
var ki = pIL.add(BigInteger.fromBuffer(this.privateKey)).mod(N)
var ki = pIL.add(BigInteger.fromBuffer(this.privateKey)).mod(ecparams.params.n)
// In case parse256(IL) >= n or ki == 0, one should proceed with the next value for i
if (pIL.compareTo(N) >= 0 || ki.signum() === 0) {
if (pIL.compareTo(ecparams.params.n) >= 0 || ki.signum() === 0) {
return this.derive(index + 1)
}

4
test/hdkey.test.js

@ -23,8 +23,8 @@ describe('hdkey', function() {
var hdkey = HDKey.fromMasterSeed(new Buffer(f.seed, 'hex'))
var childkey = hdkey.derive(f.path)
assert.equal(encode(childkey.privateOld), f.private)
assert.equal(encode(childkey.publicOld), f.public)
assert.equal(encode(childkey.privateExtendedKey), f.private)
assert.equal(encode(childkey.publicExtendedKey), f.public)
})
})
})

Loading…
Cancel
Save