Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: bitcoinjs/wif
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: COINiD/wif
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 2 commits
  • 1 file changed
  • 2 contributors

Commits on Jan 22, 2019

  1. Update index.js

    rikardwissing committed Jan 22, 2019
    Copy the full SHA
    6193f3b View commit details
  2. Update index.js

    rikardwissing committed Jan 22, 2019
    Copy the full SHA
    f35c072 View commit details
Showing with 13 additions and 5 deletions.
  1. +13 −5 index.js
18 changes: 13 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
var bs58check = require('bs58check')
var bs58checkBase = require('bs58check/base')
var Buffer = require('safe-buffer').Buffer

function getBs58check (network) {
if(network && network.hashFunctions && network.hashFunctions.address) {
return bs58checkBase(network.hashFunctions.address);
}
return bs58check;
}

function decodeRaw (buffer, version) {
// check version only if defined
if (version !== undefined && buffer[0] !== version) throw new Error('Invalid network version')
@@ -41,14 +49,14 @@ function encodeRaw (version, privateKey, compressed) {
return result
}

function decode (string, version) {
return decodeRaw(bs58check.decode(string), version)
function decode (string, version, network) {
return decodeRaw(getBs58check(network).decode(string), version)
}

function encode (version, privateKey, compressed) {
if (typeof version === 'number') return bs58check.encode(encodeRaw(version, privateKey, compressed))
function encode (version, privateKey, compressed, network) {
if (typeof version === 'number') return getBs58check(network).encode(encodeRaw(version, privateKey, compressed))

return bs58check.encode(
return getBs58check(network).encode(
encodeRaw(
version.version,
version.privateKey,