Merge pull request #550 from bitcoinjs/testnet
Add network list tests for ECPair/HDNode
This commit is contained in:
commit
7d2b2dee45
6 changed files with 20 additions and 9 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue