ECPair.fromWIF = function (string, network) { var decoded = wif.decode(string) var version = decoded.version // list of networks? if (types.Array(network)) { network = network.filter(function (x) { return version === x.wif }).pop() // We should not use pop since it depends on the order of the networks for the same wif if (!network) throw new Error('Unknown network version') // otherwise, assume a network object (or default to bitcoin) } else { network = network || NETWORKS.bitcoin if (version !== network.wif) throw new Error('Invalid network version') } var d = BigInteger.fromBuffer(decoded.privateKey) return new ECPair(d, null, { compressed: decoded.compressed, network: network }) }
ECPair.fromWIF = function (string, network) { var decoded = wif.decode(string) var version = decoded.version // [network, ...] if (types.Array(network)) { network = network.filter(function (network) { return version === network.wif }).pop() if (!network) throw new Error('Unknown network version') // network } else { network = network || NETWORKS.bitcoin if (version !== network.wif) throw new Error('Invalid network version') } var d = BigInteger.fromBuffer(decoded.privateKey) return new ECPair(d, null, { compressed: decoded.compressed, network: network }) }
function fromWIF(wifString, network) { const decoded = wif.decode(wifString); const version = decoded.version; // list of networks? if (types.Array(network)) { network = network .filter((x) => { return version === x.wif; }) .pop(); if (!network) throw new Error('Unknown network version'); // otherwise, assume a network object (or default to bitcoin) } else { network = network || NETWORKS.bitcoin; if (version !== network.wif) throw new Error('Invalid network version'); } return fromPrivateKey(decoded.privateKey, { compressed: decoded.compressed, network: network, }); }