Merge remote-tracking branch 'upstream/master'

This commit is contained in:
n1073645 2019-11-14 09:03:06 +00:00
commit 30c6917914
6 changed files with 25 additions and 18 deletions

View file

@ -42,15 +42,22 @@ class FromBase62 extends Operation {
*/
run(input, args) {
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 });
const re = new RegExp("[^" + ALPHABET.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g");
const re = new RegExp("[^" + alphabet.replace(/[[\]\\\-^$]/g, "\\$&") + "]", "g");
input = input.replace(re, "");
const number = new BN(input, 62);
// Read number in using Base62 alphabet
const number = new BN62(input, 62);
// Copy to new BigNumber object that uses the default alphabet
const normalized = new BigNumber(number);
return Utils.convertToByteArray(number.toString(16), "Hex");
// Convert to hex and add leading 0 if required
let hex = normalized.toString(16);
if (hex.length % 2 !== 0) hex = "0" + hex;
return Utils.convertToByteArray(hex, "Hex");
}
}

View file

@ -6,8 +6,8 @@
* @license Apache-2.0
*/
import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
* Lorenz operation

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);
}