diff --git a/CHANGELOG.md b/CHANGELOG.md index b063996..a17a983 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ------------------ - 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` +- changed behavior of `fromExtendedKey()` from accepting a type of `Buffer` bytes to base58 `string` 0.2.0 / 2014-06-25 ------------------ diff --git a/lib/hdkey.js b/lib/hdkey.js index 7c25171..eed1082 100644 --- a/lib/hdkey.js +++ b/lib/hdkey.js @@ -175,11 +175,13 @@ HDKey.fromMasterSeed = function(seedBuffer, versions) { return hdkey } -HDKey.fromExtendedKey = function(keyBuffer, versions) { +HDKey.fromExtendedKey = function(base58key, versions) { // => version(4) || depth(1) || fingerprint(4) || index(4) || chain(32) || key(33) versions = versions || BITCOIN_VERSIONS var hdkey = new HDKey(versions) + var keyBuffer = cs.decode(base58key) + var version = keyBuffer.readUInt32BE(0) assert(version === versions.private || version === versions.public, 'Version mismatch: does not match private or public') diff --git a/test/hdkey.test.js b/test/hdkey.test.js index 34caa3e..05d93c6 100644 --- a/test/hdkey.test.js +++ b/test/hdkey.test.js @@ -62,8 +62,7 @@ describe('hdkey', function() { it('should parse it', function() { //m/0/2147483647'/1/2147483646'/2 var key = "xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j" - var keyBuffer = cs.decode(key) - var hdkey = HDKey.fromExtendedKey(keyBuffer) + var hdkey = HDKey.fromExtendedKey(key) assert.equal(hdkey.versions.private, 0x0488ade4) assert.equal(hdkey.versions.public, 0x0488b21e) assert.equal(hdkey.depth, 5) @@ -80,8 +79,7 @@ describe('hdkey', function() { it('should parse it', function() { //m/0/2147483647'/1/2147483646'/2 var key = "xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt" - var keyBuffer = cs.decode(key) - var hdkey = HDKey.fromExtendedKey(keyBuffer) + var hdkey = HDKey.fromExtendedKey(key) assert.equal(hdkey.versions.private, 0x0488ade4) assert.equal(hdkey.versions.public, 0x0488b21e) assert.equal(hdkey.depth, 5) @@ -98,8 +96,7 @@ describe('hdkey', function() { describe('> when deriving public key', function() { it('should work', function() { var key = "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8" - var keyBuffer = cs.decode(key) - var hdkey = HDKey.fromExtendedKey(keyBuffer) + var hdkey = HDKey.fromExtendedKey(key) var path = "m/3353535/2223/0/99424/4/33" var derivedHDKey = hdkey.derive(path)