Browse Source

changed privateExtendedKey() and publicExtendedKey() to return base 58 encoded string

master
JP Richardson 11 years ago
parent
commit
7bda496700
  1. 2
      CHANGELOG.md
  2. 6
      lib/hdkey.js
  3. 3
      package.json
  4. 12
      test/hdkey.test.js

2
CHANGELOG.md

@ -1,7 +1,7 @@
0.3.0 / 2014-06-29
------------------
- bugfix: if private key was less than 32 bytes, pad out to 32 bytes with leading zeros (this happens in derive)
- changed behavior of `privateExtendedKey()` and `publicExtendedKey()` to return base 58 encoded `string` instead of `Buffer`
0.2.0 / 2014-06-25
------------------

6
lib/hdkey.js

@ -1,11 +1,13 @@
var assert = require('assert')
var crypto = require('crypto')
var BigInteger = require('bigi')
var cs = require('coinstring')
var ecurve = require('ecurve')
var curve = ecurve.getCurveByName('secp256k1')
var Point = ecurve.Point
var sha512 = require('sha512')
module.exports = HDKey
var MASTER_SECRET = new Buffer('Bitcoin seed')
@ -63,13 +65,13 @@ Object.defineProperty(HDKey.prototype, 'publicKey', {
Object.defineProperty(HDKey.prototype, 'privateExtendedKey', {
get: function() {
return serialize(this, this.versions.private, Buffer.concat([new Buffer([0]), this.privateKey]))
return cs.encode(serialize(this, this.versions.private, Buffer.concat([new Buffer([0]), this.privateKey])))
}
})
Object.defineProperty(HDKey.prototype, 'publicExtendedKey', {
get: function() {
return serialize(this, this.versions.public, this.publicKey)
return cs.encode(serialize(this, this.versions.public, this.publicKey))
}
})

3
package.json

@ -27,8 +27,7 @@
"istanbul": "^0.2.10",
"secure-random": "^1.0.0",
"mochify": "^0.9.3",
"crypto-browserify": "^2.1.8",
"coinstring": "^2.0.0"
"crypto-browserify": "^2.1.8"
},
"dependencies": {
"sha512": "0.0.1",

12
test/hdkey.test.js

@ -9,10 +9,6 @@ var curve = ecurve.getCurveByName('secp256k1')
var HDKey = require('../')
var fixtures = require('./fixtures/hdkey')
function encode(buf) {
return cs.encode(buf)
}
describe('hdkey', function() {
describe('+ fromMasterSeed', function() {
var f = fixtures.valid.forEach(function(f) {
@ -21,8 +17,8 @@ describe('hdkey', function() {
var hdkey = HDKey.fromMasterSeed(new Buffer(f.seed, 'hex'))
var childkey = hdkey.derive(f.path)
assert.equal(encode(childkey.privateExtendedKey), f.private)
assert.equal(encode(childkey.publicExtendedKey), f.public)
assert.equal(childkey.privateExtendedKey, f.private)
assert.equal(childkey.publicExtendedKey, f.public)
})
})
})
@ -109,7 +105,7 @@ describe('hdkey', function() {
var derivedHDKey = hdkey.derive(path)
var expected = "xpub6JdKdVJtdx6sC3nh87pDvnGhotXuU5Kz6Qy7Piy84vUAwWSYShsUGULE8u6gCivTHgz7cCKJHiXaaMeieB4YnoFVAsNgHHKXJ2mN6jCMbH1"
assert.equal(cs.encode(derivedHDKey.publicExtendedKey), expected)
assert.equal(derivedHDKey.publicExtendedKey, expected)
})
})
@ -121,7 +117,7 @@ describe('hdkey', function() {
var newKey = masterKey.derive("m/44'/6'/4'")
var expected = 'xprv9ymoag6W7cR6KBcJzhCM6qqTrb3rRVVwXKzwNqp1tDWcwierEv3BA9if3ARHMhMPh9u2jNoutcgpUBLMfq3kADDo7LzfoCnhhXMRGX3PXDx'
assert.equal(cs.encode(newKey.privateExtendedKey), expected)
assert.equal(newKey.privateExtendedKey, expected)
})
})
})

Loading…
Cancel
Save