Skip to content

Commit

Permalink
Support for BIP49 YPUB/UPUB
Browse files Browse the repository at this point in the history
  • Loading branch information
plasticlobster committed Nov 17, 2017
1 parent 9c8503c commit 8f39b51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/hdnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ HDNode.fromBase58 = function (string, networks) {
if (Array.isArray(networks)) {
network = networks.filter(function (x) {
return version === x.bip32.private ||
version === x.bip32.public
version === x.bip32.public ||
version === x.bip49.private ||
version === x.bip49.public
}).pop()

if (!network) throw new Error('Unknown network version')
Expand All @@ -75,7 +77,9 @@ HDNode.fromBase58 = function (string, networks) {
}

if (version !== network.bip32.private &&
version !== network.bip32.public) throw new Error('Invalid network version')
version !== network.bip32.public &&
version !== network.bip49.private &&
version !== network.bip49.public) throw new Error('Invalid network version')

// 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, ...
var depth = buffer[4]
Expand Down
8 changes: 8 additions & 0 deletions src/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module.exports = {
public: 0x0488b21e,
private: 0x0488ade4
},
bip49: {
public: 0x049D7CB2,
private: 0x049D7878
},
pubKeyHash: 0x00,
scriptHash: 0x05,
wif: 0x80
Expand All @@ -20,6 +24,10 @@ module.exports = {
public: 0x043587cf,
private: 0x04358394
},
bip49: {
public: 0x044A5262,
private: 0x044A4E28
},
pubKeyHash: 0x6f,
scriptHash: 0xc4,
wif: 0xef
Expand Down

1 comment on commit 8f39b51

@mautematico
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not working.

Take this example:

const Bitcoin = require('bitcoinjs-lib');

Bitcoin.HDNode.fromBase58('ypub6XMTwf6NSvfzYYgVgdNWRNfMTiQt4rSjZbEk8qoCnBGhUD2rsgZ2A8pexgzaGLKgySZxqxrctDpAVU8QtfxqfX8QUAhtFmGFUFx9B51TVg8', Bitcoin.networks.bitcoin)
    .derive(0)
    .derive(27)
    .getAddress()

HDNode gets built, but output address is not segwit-p2sh (it's not even p2sh address):

'113QfzmxXN8kMjr1ZkLEww6BpMzSG1eGiQ'

Please sign in to comment.