From f53b821cc909176ad576d63f6cb3f2b5b38cfdb6 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 3 Apr 2014 19:45:05 +1100 Subject: [PATCH] Isolates Base58Check encoding from Base58 code/tests --- src/base58.js | 94 +++++++++++++++------------------------------ src/base58check.js | 53 +++++++++++++++++++++++++ src/index.js | 1 + test/base58.js | 66 ++++++++++++++++--------------- test/base58check.js | 76 ++++++++++++++++++++++++++++++++++++ 5 files changed, 195 insertions(+), 95 deletions(-) create mode 100644 src/base58check.js create mode 100644 test/base58check.js diff --git a/src/base58.js b/src/base58.js index 0b38586..3715c3b 100644 --- a/src/base58.js +++ b/src/base58.js @@ -1,66 +1,65 @@ -// https://en.bitcoin.it/wiki/Base58Check_encoding +// Base58 encoding/decoding +// Originally written by Mike Hearn for BitcoinJ +// Copyright (c) 2011 Google Inc +// Ported to JavaScript by Stefan Thomas var BigInteger = require('./jsbn/jsbn') -var Crypto = require('crypto-js') -var convert = require('./convert') -var SHA256 = Crypto.SHA256 +// FIXME: ? This is a Base58Check alphabet var alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" var base = BigInteger.valueOf(58) -var positions = {} +var alphabetMap = {} for (var i=0; i= 0) { var mod = bi.mod(base) - chars.push(alphabet[mod.intValue()]) bi = bi.subtract(mod).divide(base) + + chars.push(alphabet[mod.intValue()]) } chars.push(alphabet[bi.intValue()]) // Convert leading zeros too. - for (var i=0; i