base58: cleanup variable names

The encode/decode functions are also now similar syntactically.
This commit is contained in:
Daniel Cousens 2014-05-31 11:48:15 +10:00
parent 61c57adbf8
commit 77d4325d4b

View file

@ -12,7 +12,7 @@ var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
var ALPHABET_BUF = new Buffer(ALPHABET, 'ascii')
var ALPHABET_MAP = {}
for(var i = 0; i < ALPHABET.length; i++) {
ALPHABET_MAP[ALPHABET[i]] = BigInteger.valueOf(i)
ALPHABET_MAP[ALPHABET.charAt(i)] = BigInteger.valueOf(i)
}
var BASE = BigInteger.valueOf(58)
@ -43,7 +43,7 @@ function encode(buffer) {
function decode(string) {
if (string.length === 0) return new Buffer(0)
var num = BigInteger.ZERO.clone()
var num = BigInteger.ZERO
for (var i = 0; i < string.length; i++) {
num = num.multiply(BASE)
@ -55,16 +55,16 @@ function decode(string) {
}
// deal with leading zeros
var i = 0
while ((i < string.length) && (string[i] === ALPHABET[0])) {
i++
var j = 0
while ((j < string.length) && (string[j] === ALPHABET[0])) {
j++
}
var buffer = num.toBuffer()
var leadz = new Buffer(i)
leadz.fill(0)
var leadingZeros = new Buffer(j)
leadingZeros.fill(0)
return Buffer.concat([leadz, buffer])
return Buffer.concat([leadingZeros, buffer])
}
module.exports = {