Skip to content

Commit 9e32c89

Browse files
committed
ECPair/tests: always use WIF for error throwing
1 parent 54c071c commit 9e32c89

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/ecpair.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ ECPair.fromPublicKeyBuffer = function (buffer, network) {
5858
}
5959

6060
ECPair.fromWIF = function (string, network) {
61-
network = network || NETWORKS.bitcoin
6261
var buffer = bs58check.decode(string)
6362

6463
if (types.Array(network)) {
@@ -67,9 +66,9 @@ ECPair.fromWIF = function (string, network) {
6766
network = network.filter(function (network) {
6867
return version === network.wif
6968
}).pop()
70-
if (!network) throw new Error('Invalid network version')
7169
}
7270

71+
network = network || NETWORKS.bitcoin
7372
var decoded = wif.decodeRaw(buffer, network.wif)
7473
var d = BigInteger.fromBuffer(decoded.privateKey)
7574

test/ecpair.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ describe('ECPair', function () {
107107
fixtures.invalid.fromWIF.forEach(function (f) {
108108
it('throws on ' + f.WIF, function () {
109109
assert.throws(function () {
110-
ECPair.fromWIF(f.WIF)
110+
var networks = f.network ? NETWORKS[f.network] : NETWORKS_LIST
111+
112+
ECPair.fromWIF(f.WIF, networks)
111113
}, new RegExp(f.exception))
112114
})
113115
})

test/fixtures/ecpair.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,13 @@
107107
"fromWIF": [
108108
{
109109
"exception": "Invalid network version",
110+
"network": "bitcoin",
110111
"WIF": "92Qba5hnyWSn5Ffcka56yMQauaWY6ZLd91Vzxbi4a9CCetaHtYj"
111112
},
113+
{
114+
"exception": "Invalid network version",
115+
"WIF": "brQnSed3Fia1w9VcbbS6ZGDgJ6ENkgwuQY2LS7pEC5bKHD1fMF"
116+
},
112117
{
113118
"exception": "Invalid compression flag",
114119
"WIF": "KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sfZr2ym"

0 commit comments

Comments
 (0)