Merge pull request from bitcoinjs/testnet

Add network list tests for ECPair/HDNode
This commit is contained in:
Daniel Cousens 2016-02-25 18:20:53 +11:00
commit 7d2b2dee45
6 changed files with 20 additions and 9 deletions

View file

@ -58,7 +58,6 @@ ECPair.fromPublicKeyBuffer = function (buffer, network) {
}
ECPair.fromWIF = function (string, network) {
network = network || NETWORKS.bitcoin
var buffer = bs58check.decode(string)
if (types.Array(network)) {
@ -67,9 +66,11 @@ ECPair.fromWIF = function (string, network) {
network = network.filter(function (network) {
return version === network.wif
}).pop()
if (!network) throw new Error('Invalid network version')
if (!network) throw new Error('Unknown network version')
}
network = network || NETWORKS.bitcoin
var decoded = wif.decodeRaw(buffer, network.wif)
var d = BigInteger.fromBuffer(decoded.privateKey)

View file

@ -64,7 +64,9 @@ HDNode.fromBase58 = function (string, networks) {
network = networks.filter(function (network) {
return version === network.bip32.private ||
version === network.bip32.public
}).pop() || {}
}).pop()
if (!network) throw new Error('Unknown network version')
// otherwise, assume a network object (or default to bitcoin)
} else {
@ -72,7 +74,7 @@ HDNode.fromBase58 = function (string, networks) {
}
if (version !== network.bip32.private &&
version !== network.bip32.public) throw new Error('Invalid network')
version !== network.bip32.public) throw new Error('Invalid network version')
// 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, ...
var depth = buffer[4]