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` - added properties: `privateKey` and `publicKey`
- removed method `getIdentifier()`, added property `identifier` - removed method `getIdentifier()`, added property `identifier`
- removed method `getFingerprint()`, added property `fingerprint` - removed method `getFingerprint()`, added property `fingerprint`
- renamed `private` to `privateExtendedKey`
- renamed `public` to `publicExtendedKey`
0.0.1 / 2014-05-29 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 HARDENED_OFFSET = 0x80000000
var LEN = 78 var LEN = 78
var N = ecparams.params.n
//Bitcoin hardcoded by default, can use package `coininfo` for others //Bitcoin hardcoded by default, can use package `coininfo` for others
var BITCOIN_VERSIONS = {private: 0x0488ADE4, public: 0x0488B21E} 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() { get: function() {
return serialize(this, this.versions.private, Buffer.concat([new Buffer([0]), this.privateKey])) 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() { get: function() {
return serialize(this, this.versions.public, this.publicKey) return serialize(this, this.versions.public, this.publicKey)
} }
@ -74,7 +72,7 @@ HDKey.prototype.derive = function(path) {
return this return this
var entries = path.split('/') var entries = path.split('/')
var hkey = this var hdkey = this
entries.forEach(function(c, i) { entries.forEach(function(c, i) {
if (i == 0) { if (i == 0) {
assert(c, 'm', 'Invalid path') assert(c, 'm', 'Invalid path')
@ -86,10 +84,10 @@ HDKey.prototype.derive = function(path) {
assert(childIndex < HARDENED_OFFSET, 'Invalid index') assert(childIndex < HARDENED_OFFSET, 'Invalid index')
if (hardened) childIndex += HARDENED_OFFSET if (hardened) childIndex += HARDENED_OFFSET
hkey = hkey.deriveChild(childIndex) hdkey = hdkey.deriveChild(childIndex)
}) })
return hkey return hdkey
} }
HDKey.prototype.deriveChild = function(index) { HDKey.prototype.deriveChild = function(index) {
@ -124,10 +122,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(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 // 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) 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 hdkey = HDKey.fromMasterSeed(new Buffer(f.seed, 'hex'))
var childkey = hdkey.derive(f.path) var childkey = hdkey.derive(f.path)
assert.equal(encode(childkey.privateOld), f.private) assert.equal(encode(childkey.privateExtendedKey), f.private)
assert.equal(encode(childkey.publicOld), f.public) assert.equal(encode(childkey.publicExtendedKey), f.public)
}) })
}) })
}) })

Loading…
Cancel
Save