Fixed bug in Base62 operations when using different alphabets

This commit is contained in:
n1474335 2019-11-13 17:59:16 +00:00
parent d3473a7462
commit cce84c3782
2 changed files with 18 additions and 8 deletions

View file

@ -44,12 +44,15 @@ class ToBase62 extends Operation {
input = new Uint8Array(input);
if (input.length < 1) return "";
const ALPHABET = Utils.expandAlphRange(args[0]).join("");
const BN = BigNumber.clone({ ALPHABET });
const alphabet = Utils.expandAlphRange(args[0]).join("");
const BN62 = BigNumber.clone({ ALPHABET: alphabet });
input = toHexFast(input).toUpperCase();
const number = new BN(input, 16);
// Read number in as hex using normal alphabet
const normalized = new BigNumber(input, 16);
// Copy to BigNumber clone that uses the specified Base62 alphabet
const number = new BN62(normalized);
return number.toString(62);
}