// 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') // FIXME: ? This is a Base58Check alphabet var alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" var base = BigInteger.valueOf(58) var alphabetMap = {} for (var i=0; i= 0) { var mod = bi.mod(base) 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 0) { bytes.unshift(0) } return new Buffer(bytes) } module.exports = { encode: encode, decode: decode }