Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for BIP49 YPUB/UPUB #927

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ||
Copy link
Contributor

@afk11 afk11 Dec 15, 2017

Choose a reason for hiding this comment

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

I think these semantics should be opt-in. Imagine someone supported Bitcoin Cash, and imported keys. There's not currently a bitcoin-cash network in the library, so they're using the bitcoin network for that. Imagine they didn't read the release notes, and allowed users to import a P2SH(P2WPKH) address, and funded that on Bitcoin Cash.. They're unspendable without talking to a miner.

I think this feature should be opt in, so a new function bip44TypefromBase58 or something that forces developers to think about what they are doing.

Copy link
Contributor

Choose a reason for hiding this comment

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

@afk11 I don't understand, what about these new BIP49 constants would trap users into creating unspendable addresses?

Copy link
Contributor

@dcousens dcousens Jan 17, 2018

Choose a reason for hiding this comment

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

Isn't the risk that any P2SH(P2WPKH) scripts are unspendable by BCash nodes?
Nothing to do with the BIP49 constants?

Copy link
Contributor

Choose a reason for hiding this comment

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

Applications might accept stuff they shouldn't when forks like bitcoin cash happen, and developers start using bitcoin.networks.bitcoin as a bitcoin cash network. It's mostly that the feature should only be used via specialized encoding/decoding/factory functions. That way, developers have to consider the difference between xpub only, and the format that uses different scripts.

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