@iandjx/wallet
Version:
Implmentation of web3react-v8 for RT widgets
1,525 lines (1,520 loc) • 3.09 MB
JavaScript
"use strict";
(() => {
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined")
return require.apply(this, arguments);
throw new Error('Dynamic require of "' + x + '" is not supported');
});
var __esm = (fn, res) => function __init() {
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
};
var __commonJS = (cb, mod) => function __require2() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from2, except, desc) => {
if (from2 && typeof from2 === "object" || typeof from2 === "function") {
for (let key2 of __getOwnPropNames(from2))
if (!__hasOwnProp.call(to, key2) && key2 !== except)
__defProp(to, key2, { get: () => from2[key2], enumerable: !(desc = __getOwnPropDesc(from2, key2)) || desc.enumerable });
}
return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// node_modules/.pnpm/@ethersproject+logger@5.7.0/node_modules/@ethersproject/logger/lib.esm/_version.js
var version;
var init_version = __esm({
"node_modules/.pnpm/@ethersproject+logger@5.7.0/node_modules/@ethersproject/logger/lib.esm/_version.js"() {
version = "logger/5.7.0";
}
});
// node_modules/.pnpm/@ethersproject+logger@5.7.0/node_modules/@ethersproject/logger/lib.esm/index.js
function _checkNormalize() {
try {
const missing = [];
["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => {
try {
if ("test".normalize(form) !== "test") {
throw new Error("bad normalize");
}
;
} catch (error) {
missing.push(form);
}
});
if (missing.length) {
throw new Error("missing " + missing.join(", "));
}
if (String.fromCharCode(233).normalize("NFD") !== String.fromCharCode(101, 769)) {
throw new Error("broken implementation");
}
} catch (error) {
return error.message;
}
return null;
}
var _permanentCensorErrors, _censorErrors, LogLevels, _logLevel, _globalLogger, _normalizeError, LogLevel, ErrorCode, HEX, Logger;
var init_lib = __esm({
"node_modules/.pnpm/@ethersproject+logger@5.7.0/node_modules/@ethersproject/logger/lib.esm/index.js"() {
"use strict";
init_version();
_permanentCensorErrors = false;
_censorErrors = false;
LogLevels = { debug: 1, "default": 2, info: 2, warning: 3, error: 4, off: 5 };
_logLevel = LogLevels["default"];
_globalLogger = null;
_normalizeError = _checkNormalize();
(function(LogLevel2) {
LogLevel2["DEBUG"] = "DEBUG";
LogLevel2["INFO"] = "INFO";
LogLevel2["WARNING"] = "WARNING";
LogLevel2["ERROR"] = "ERROR";
LogLevel2["OFF"] = "OFF";
})(LogLevel || (LogLevel = {}));
(function(ErrorCode2) {
ErrorCode2["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
ErrorCode2["NOT_IMPLEMENTED"] = "NOT_IMPLEMENTED";
ErrorCode2["UNSUPPORTED_OPERATION"] = "UNSUPPORTED_OPERATION";
ErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
ErrorCode2["SERVER_ERROR"] = "SERVER_ERROR";
ErrorCode2["TIMEOUT"] = "TIMEOUT";
ErrorCode2["BUFFER_OVERRUN"] = "BUFFER_OVERRUN";
ErrorCode2["NUMERIC_FAULT"] = "NUMERIC_FAULT";
ErrorCode2["MISSING_NEW"] = "MISSING_NEW";
ErrorCode2["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
ErrorCode2["MISSING_ARGUMENT"] = "MISSING_ARGUMENT";
ErrorCode2["UNEXPECTED_ARGUMENT"] = "UNEXPECTED_ARGUMENT";
ErrorCode2["CALL_EXCEPTION"] = "CALL_EXCEPTION";
ErrorCode2["INSUFFICIENT_FUNDS"] = "INSUFFICIENT_FUNDS";
ErrorCode2["NONCE_EXPIRED"] = "NONCE_EXPIRED";
ErrorCode2["REPLACEMENT_UNDERPRICED"] = "REPLACEMENT_UNDERPRICED";
ErrorCode2["UNPREDICTABLE_GAS_LIMIT"] = "UNPREDICTABLE_GAS_LIMIT";
ErrorCode2["TRANSACTION_REPLACED"] = "TRANSACTION_REPLACED";
ErrorCode2["ACTION_REJECTED"] = "ACTION_REJECTED";
})(ErrorCode || (ErrorCode = {}));
HEX = "0123456789abcdef";
Logger = class {
constructor(version27) {
Object.defineProperty(this, "version", {
enumerable: true,
value: version27,
writable: false
});
}
_log(logLevel, args) {
const level = logLevel.toLowerCase();
if (LogLevels[level] == null) {
this.throwArgumentError("invalid log level name", "logLevel", logLevel);
}
if (_logLevel > LogLevels[level]) {
return;
}
console.log.apply(console, args);
}
debug(...args) {
this._log(Logger.levels.DEBUG, args);
}
info(...args) {
this._log(Logger.levels.INFO, args);
}
warn(...args) {
this._log(Logger.levels.WARNING, args);
}
makeError(message, code, params) {
if (_censorErrors) {
return this.makeError("censored error", code, {});
}
if (!code) {
code = Logger.errors.UNKNOWN_ERROR;
}
if (!params) {
params = {};
}
const messageDetails = [];
Object.keys(params).forEach((key2) => {
const value = params[key2];
try {
if (value instanceof Uint8Array) {
let hex = "";
for (let i = 0; i < value.length; i++) {
hex += HEX[value[i] >> 4];
hex += HEX[value[i] & 15];
}
messageDetails.push(key2 + "=Uint8Array(0x" + hex + ")");
} else {
messageDetails.push(key2 + "=" + JSON.stringify(value));
}
} catch (error2) {
messageDetails.push(key2 + "=" + JSON.stringify(params[key2].toString()));
}
});
messageDetails.push(`code=${code}`);
messageDetails.push(`version=${this.version}`);
const reason = message;
let url = "";
switch (code) {
case ErrorCode.NUMERIC_FAULT: {
url = "NUMERIC_FAULT";
const fault = message;
switch (fault) {
case "overflow":
case "underflow":
case "division-by-zero":
url += "-" + fault;
break;
case "negative-power":
case "negative-width":
url += "-unsupported";
break;
case "unbound-bitwise-result":
url += "-unbound-result";
break;
}
break;
}
case ErrorCode.CALL_EXCEPTION:
case ErrorCode.INSUFFICIENT_FUNDS:
case ErrorCode.MISSING_NEW:
case ErrorCode.NONCE_EXPIRED:
case ErrorCode.REPLACEMENT_UNDERPRICED:
case ErrorCode.TRANSACTION_REPLACED:
case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
url = code;
break;
}
if (url) {
message += " [ See: https://links.ethers.org/v5-errors-" + url + " ]";
}
if (messageDetails.length) {
message += " (" + messageDetails.join(", ") + ")";
}
const error = new Error(message);
error.reason = reason;
error.code = code;
Object.keys(params).forEach(function(key2) {
error[key2] = params[key2];
});
return error;
}
throwError(message, code, params) {
throw this.makeError(message, code, params);
}
throwArgumentError(message, name, value) {
return this.throwError(message, Logger.errors.INVALID_ARGUMENT, {
argument: name,
value
});
}
assert(condition, message, code, params) {
if (!!condition) {
return;
}
this.throwError(message, code, params);
}
assertArgument(condition, message, name, value) {
if (!!condition) {
return;
}
this.throwArgumentError(message, name, value);
}
checkNormalize(message) {
if (message == null) {
message = "platform missing String.prototype.normalize";
}
if (_normalizeError) {
this.throwError("platform missing String.prototype.normalize", Logger.errors.UNSUPPORTED_OPERATION, {
operation: "String.prototype.normalize",
form: _normalizeError
});
}
}
checkSafeUint53(value, message) {
if (typeof value !== "number") {
return;
}
if (message == null) {
message = "value not safe";
}
if (value < 0 || value >= 9007199254740991) {
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
operation: "checkSafeInteger",
fault: "out-of-safe-range",
value
});
}
if (value % 1) {
this.throwError(message, Logger.errors.NUMERIC_FAULT, {
operation: "checkSafeInteger",
fault: "non-integer",
value
});
}
}
checkArgumentCount(count2, expectedCount, message) {
if (message) {
message = ": " + message;
} else {
message = "";
}
if (count2 < expectedCount) {
this.throwError("missing argument" + message, Logger.errors.MISSING_ARGUMENT, {
count: count2,
expectedCount
});
}
if (count2 > expectedCount) {
this.throwError("too many arguments" + message, Logger.errors.UNEXPECTED_ARGUMENT, {
count: count2,
expectedCount
});
}
}
checkNew(target, kind) {
if (target === Object || target == null) {
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
}
}
checkAbstract(target, kind) {
if (target === kind) {
this.throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", Logger.errors.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" });
} else if (target === Object || target == null) {
this.throwError("missing new", Logger.errors.MISSING_NEW, { name: kind.name });
}
}
static globalLogger() {
if (!_globalLogger) {
_globalLogger = new Logger(version);
}
return _globalLogger;
}
static setCensorship(censorship, permanent) {
if (!censorship && permanent) {
this.globalLogger().throwError("cannot permanently disable censorship", Logger.errors.UNSUPPORTED_OPERATION, {
operation: "setCensorship"
});
}
if (_permanentCensorErrors) {
if (!censorship) {
return;
}
this.globalLogger().throwError("error censorship permanent", Logger.errors.UNSUPPORTED_OPERATION, {
operation: "setCensorship"
});
}
_censorErrors = !!censorship;
_permanentCensorErrors = !!permanent;
}
static setLogLevel(logLevel) {
const level = LogLevels[logLevel.toLowerCase()];
if (level == null) {
Logger.globalLogger().warn("invalid log level - " + logLevel);
return;
}
_logLevel = level;
}
static from(version27) {
return new Logger(version27);
}
};
Logger.errors = ErrorCode;
Logger.levels = LogLevel;
}
});
// node_modules/.pnpm/@ethersproject+bytes@5.7.0/node_modules/@ethersproject/bytes/lib.esm/_version.js
var version2;
var init_version2 = __esm({
"node_modules/.pnpm/@ethersproject+bytes@5.7.0/node_modules/@ethersproject/bytes/lib.esm/_version.js"() {
version2 = "bytes/5.7.0";
}
});
// node_modules/.pnpm/@ethersproject+bytes@5.7.0/node_modules/@ethersproject/bytes/lib.esm/index.js
function isHexable(value) {
return !!value.toHexString;
}
function addSlice(array) {
if (array.slice) {
return array;
}
array.slice = function() {
const args = Array.prototype.slice.call(arguments);
return addSlice(new Uint8Array(Array.prototype.slice.apply(array, args)));
};
return array;
}
function isBytesLike(value) {
return isHexString(value) && !(value.length % 2) || isBytes(value);
}
function isInteger(value) {
return typeof value === "number" && value == value && value % 1 === 0;
}
function isBytes(value) {
if (value == null) {
return false;
}
if (value.constructor === Uint8Array) {
return true;
}
if (typeof value === "string") {
return false;
}
if (!isInteger(value.length) || value.length < 0) {
return false;
}
for (let i = 0; i < value.length; i++) {
const v = value[i];
if (!isInteger(v) || v < 0 || v >= 256) {
return false;
}
}
return true;
}
function arrayify(value, options) {
if (!options) {
options = {};
}
if (typeof value === "number") {
logger.checkSafeUint53(value, "invalid arrayify value");
const result = [];
while (value) {
result.unshift(value & 255);
value = parseInt(String(value / 256));
}
if (result.length === 0) {
result.push(0);
}
return addSlice(new Uint8Array(result));
}
if (options.allowMissingPrefix && typeof value === "string" && value.substring(0, 2) !== "0x") {
value = "0x" + value;
}
if (isHexable(value)) {
value = value.toHexString();
}
if (isHexString(value)) {
let hex = value.substring(2);
if (hex.length % 2) {
if (options.hexPad === "left") {
hex = "0" + hex;
} else if (options.hexPad === "right") {
hex += "0";
} else {
logger.throwArgumentError("hex data is odd-length", "value", value);
}
}
const result = [];
for (let i = 0; i < hex.length; i += 2) {
result.push(parseInt(hex.substring(i, i + 2), 16));
}
return addSlice(new Uint8Array(result));
}
if (isBytes(value)) {
return addSlice(new Uint8Array(value));
}
return logger.throwArgumentError("invalid arrayify value", "value", value);
}
function concat(items) {
const objects = items.map((item) => arrayify(item));
const length = objects.reduce((accum, item) => accum + item.length, 0);
const result = new Uint8Array(length);
objects.reduce((offset, object) => {
result.set(object, offset);
return offset + object.length;
}, 0);
return addSlice(result);
}
function stripZeros(value) {
let result = arrayify(value);
if (result.length === 0) {
return result;
}
let start = 0;
while (start < result.length && result[start] === 0) {
start++;
}
if (start) {
result = result.slice(start);
}
return result;
}
function zeroPad(value, length) {
value = arrayify(value);
if (value.length > length) {
logger.throwArgumentError("value out of range", "value", arguments[0]);
}
const result = new Uint8Array(length);
result.set(value, length - value.length);
return addSlice(result);
}
function isHexString(value, length) {
if (typeof value !== "string" || !value.match(/^0x[0-9A-Fa-f]*$/)) {
return false;
}
if (length && value.length !== 2 + 2 * length) {
return false;
}
return true;
}
function hexlify(value, options) {
if (!options) {
options = {};
}
if (typeof value === "number") {
logger.checkSafeUint53(value, "invalid hexlify value");
let hex = "";
while (value) {
hex = HexCharacters[value & 15] + hex;
value = Math.floor(value / 16);
}
if (hex.length) {
if (hex.length % 2) {
hex = "0" + hex;
}
return "0x" + hex;
}
return "0x00";
}
if (typeof value === "bigint") {
value = value.toString(16);
if (value.length % 2) {
return "0x0" + value;
}
return "0x" + value;
}
if (options.allowMissingPrefix && typeof value === "string" && value.substring(0, 2) !== "0x") {
value = "0x" + value;
}
if (isHexable(value)) {
return value.toHexString();
}
if (isHexString(value)) {
if (value.length % 2) {
if (options.hexPad === "left") {
value = "0x0" + value.substring(2);
} else if (options.hexPad === "right") {
value += "0";
} else {
logger.throwArgumentError("hex data is odd-length", "value", value);
}
}
return value.toLowerCase();
}
if (isBytes(value)) {
let result = "0x";
for (let i = 0; i < value.length; i++) {
let v = value[i];
result += HexCharacters[(v & 240) >> 4] + HexCharacters[v & 15];
}
return result;
}
return logger.throwArgumentError("invalid hexlify value", "value", value);
}
function hexDataLength(data) {
if (typeof data !== "string") {
data = hexlify(data);
} else if (!isHexString(data) || data.length % 2) {
return null;
}
return (data.length - 2) / 2;
}
function hexDataSlice(data, offset, endOffset) {
if (typeof data !== "string") {
data = hexlify(data);
} else if (!isHexString(data) || data.length % 2) {
logger.throwArgumentError("invalid hexData", "value", data);
}
offset = 2 + 2 * offset;
if (endOffset != null) {
return "0x" + data.substring(offset, 2 + 2 * endOffset);
}
return "0x" + data.substring(offset);
}
function hexConcat(items) {
let result = "0x";
items.forEach((item) => {
result += hexlify(item).substring(2);
});
return result;
}
function hexValue(value) {
const trimmed = hexStripZeros(hexlify(value, { hexPad: "left" }));
if (trimmed === "0x") {
return "0x0";
}
return trimmed;
}
function hexStripZeros(value) {
if (typeof value !== "string") {
value = hexlify(value);
}
if (!isHexString(value)) {
logger.throwArgumentError("invalid hex string", "value", value);
}
value = value.substring(2);
let offset = 0;
while (offset < value.length && value[offset] === "0") {
offset++;
}
return "0x" + value.substring(offset);
}
function hexZeroPad(value, length) {
if (typeof value !== "string") {
value = hexlify(value);
} else if (!isHexString(value)) {
logger.throwArgumentError("invalid hex string", "value", value);
}
if (value.length > 2 * length + 2) {
logger.throwArgumentError("value out of range", "value", arguments[1]);
}
while (value.length < 2 * length + 2) {
value = "0x0" + value.substring(2);
}
return value;
}
function splitSignature(signature2) {
const result = {
r: "0x",
s: "0x",
_vs: "0x",
recoveryParam: 0,
v: 0,
yParityAndS: "0x",
compact: "0x"
};
if (isBytesLike(signature2)) {
let bytes = arrayify(signature2);
if (bytes.length === 64) {
result.v = 27 + (bytes[32] >> 7);
bytes[32] &= 127;
result.r = hexlify(bytes.slice(0, 32));
result.s = hexlify(bytes.slice(32, 64));
} else if (bytes.length === 65) {
result.r = hexlify(bytes.slice(0, 32));
result.s = hexlify(bytes.slice(32, 64));
result.v = bytes[64];
} else {
logger.throwArgumentError("invalid signature string", "signature", signature2);
}
if (result.v < 27) {
if (result.v === 0 || result.v === 1) {
result.v += 27;
} else {
logger.throwArgumentError("signature invalid v byte", "signature", signature2);
}
}
result.recoveryParam = 1 - result.v % 2;
if (result.recoveryParam) {
bytes[32] |= 128;
}
result._vs = hexlify(bytes.slice(32, 64));
} else {
result.r = signature2.r;
result.s = signature2.s;
result.v = signature2.v;
result.recoveryParam = signature2.recoveryParam;
result._vs = signature2._vs;
if (result._vs != null) {
const vs2 = zeroPad(arrayify(result._vs), 32);
result._vs = hexlify(vs2);
const recoveryParam = vs2[0] >= 128 ? 1 : 0;
if (result.recoveryParam == null) {
result.recoveryParam = recoveryParam;
} else if (result.recoveryParam !== recoveryParam) {
logger.throwArgumentError("signature recoveryParam mismatch _vs", "signature", signature2);
}
vs2[0] &= 127;
const s = hexlify(vs2);
if (result.s == null) {
result.s = s;
} else if (result.s !== s) {
logger.throwArgumentError("signature v mismatch _vs", "signature", signature2);
}
}
if (result.recoveryParam == null) {
if (result.v == null) {
logger.throwArgumentError("signature missing v and recoveryParam", "signature", signature2);
} else if (result.v === 0 || result.v === 1) {
result.recoveryParam = result.v;
} else {
result.recoveryParam = 1 - result.v % 2;
}
} else {
if (result.v == null) {
result.v = 27 + result.recoveryParam;
} else {
const recId = result.v === 0 || result.v === 1 ? result.v : 1 - result.v % 2;
if (result.recoveryParam !== recId) {
logger.throwArgumentError("signature recoveryParam mismatch v", "signature", signature2);
}
}
}
if (result.r == null || !isHexString(result.r)) {
logger.throwArgumentError("signature missing or invalid r", "signature", signature2);
} else {
result.r = hexZeroPad(result.r, 32);
}
if (result.s == null || !isHexString(result.s)) {
logger.throwArgumentError("signature missing or invalid s", "signature", signature2);
} else {
result.s = hexZeroPad(result.s, 32);
}
const vs = arrayify(result.s);
if (vs[0] >= 128) {
logger.throwArgumentError("signature s out of range", "signature", signature2);
}
if (result.recoveryParam) {
vs[0] |= 128;
}
const _vs = hexlify(vs);
if (result._vs) {
if (!isHexString(result._vs)) {
logger.throwArgumentError("signature invalid _vs", "signature", signature2);
}
result._vs = hexZeroPad(result._vs, 32);
}
if (result._vs == null) {
result._vs = _vs;
} else if (result._vs !== _vs) {
logger.throwArgumentError("signature _vs mismatch v and s", "signature", signature2);
}
}
result.yParityAndS = result._vs;
result.compact = result.r + result.yParityAndS.substring(2);
return result;
}
function joinSignature(signature2) {
signature2 = splitSignature(signature2);
return hexlify(concat([
signature2.r,
signature2.s,
signature2.recoveryParam ? "0x1c" : "0x1b"
]));
}
var logger, HexCharacters;
var init_lib2 = __esm({
"node_modules/.pnpm/@ethersproject+bytes@5.7.0/node_modules/@ethersproject/bytes/lib.esm/index.js"() {
"use strict";
init_lib();
init_version2();
logger = new Logger(version2);
HexCharacters = "0123456789abcdef";
}
});
// node_modules/.pnpm/bn.js@5.2.1/node_modules/bn.js/lib/bn.js
var require_bn = __commonJS({
"node_modules/.pnpm/bn.js@5.2.1/node_modules/bn.js/lib/bn.js"(exports, module) {
(function(module2, exports2) {
"use strict";
function assert3(val, msg) {
if (!val)
throw new Error(msg || "Assertion failed");
}
function inherits(ctor, superCtor) {
ctor.super_ = superCtor;
var TempCtor = function() {
};
TempCtor.prototype = superCtor.prototype;
ctor.prototype = new TempCtor();
ctor.prototype.constructor = ctor;
}
function BN3(number, base2, endian) {
if (BN3.isBN(number)) {
return number;
}
this.negative = 0;
this.words = null;
this.length = 0;
this.red = null;
if (number !== null) {
if (base2 === "le" || base2 === "be") {
endian = base2;
base2 = 10;
}
this._init(number || 0, base2 || 10, endian || "be");
}
}
if (typeof module2 === "object") {
module2.exports = BN3;
} else {
exports2.BN = BN3;
}
BN3.BN = BN3;
BN3.wordSize = 26;
var Buffer2;
try {
if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") {
Buffer2 = window.Buffer;
} else {
Buffer2 = __require("buffer").Buffer;
}
} catch (e) {
}
BN3.isBN = function isBN(num) {
if (num instanceof BN3) {
return true;
}
return num !== null && typeof num === "object" && num.constructor.wordSize === BN3.wordSize && Array.isArray(num.words);
};
BN3.max = function max2(left, right) {
if (left.cmp(right) > 0)
return left;
return right;
};
BN3.min = function min2(left, right) {
if (left.cmp(right) < 0)
return left;
return right;
};
BN3.prototype._init = function init2(number, base2, endian) {
if (typeof number === "number") {
return this._initNumber(number, base2, endian);
}
if (typeof number === "object") {
return this._initArray(number, base2, endian);
}
if (base2 === "hex") {
base2 = 16;
}
assert3(base2 === (base2 | 0) && base2 >= 2 && base2 <= 36);
number = number.toString().replace(/\s+/g, "");
var start = 0;
if (number[0] === "-") {
start++;
this.negative = 1;
}
if (start < number.length) {
if (base2 === 16) {
this._parseHex(number, start, endian);
} else {
this._parseBase(number, base2, start);
if (endian === "le") {
this._initArray(this.toArray(), base2, endian);
}
}
}
};
BN3.prototype._initNumber = function _initNumber(number, base2, endian) {
if (number < 0) {
this.negative = 1;
number = -number;
}
if (number < 67108864) {
this.words = [number & 67108863];
this.length = 1;
} else if (number < 4503599627370496) {
this.words = [
number & 67108863,
number / 67108864 & 67108863
];
this.length = 2;
} else {
assert3(number < 9007199254740992);
this.words = [
number & 67108863,
number / 67108864 & 67108863,
1
];
this.length = 3;
}
if (endian !== "le")
return;
this._initArray(this.toArray(), base2, endian);
};
BN3.prototype._initArray = function _initArray(number, base2, endian) {
assert3(typeof number.length === "number");
if (number.length <= 0) {
this.words = [0];
this.length = 1;
return this;
}
this.length = Math.ceil(number.length / 3);
this.words = new Array(this.length);
for (var i = 0; i < this.length; i++) {
this.words[i] = 0;
}
var j, w;
var off = 0;
if (endian === "be") {
for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
w = number[i] | number[i - 1] << 8 | number[i - 2] << 16;
this.words[j] |= w << off & 67108863;
this.words[j + 1] = w >>> 26 - off & 67108863;
off += 24;
if (off >= 26) {
off -= 26;
j++;
}
}
} else if (endian === "le") {
for (i = 0, j = 0; i < number.length; i += 3) {
w = number[i] | number[i + 1] << 8 | number[i + 2] << 16;
this.words[j] |= w << off & 67108863;
this.words[j + 1] = w >>> 26 - off & 67108863;
off += 24;
if (off >= 26) {
off -= 26;
j++;
}
}
}
return this._strip();
};
function parseHex4Bits(string, index) {
var c = string.charCodeAt(index);
if (c >= 48 && c <= 57) {
return c - 48;
} else if (c >= 65 && c <= 70) {
return c - 55;
} else if (c >= 97 && c <= 102) {
return c - 87;
} else {
assert3(false, "Invalid character in " + string);
}
}
function parseHexByte(string, lowerBound, index) {
var r3 = parseHex4Bits(string, index);
if (index - 1 >= lowerBound) {
r3 |= parseHex4Bits(string, index - 1) << 4;
}
return r3;
}
BN3.prototype._parseHex = function _parseHex(number, start, endian) {
this.length = Math.ceil((number.length - start) / 6);
this.words = new Array(this.length);
for (var i = 0; i < this.length; i++) {
this.words[i] = 0;
}
var off = 0;
var j = 0;
var w;
if (endian === "be") {
for (i = number.length - 1; i >= start; i -= 2) {
w = parseHexByte(number, start, i) << off;
this.words[j] |= w & 67108863;
if (off >= 18) {
off -= 18;
j += 1;
this.words[j] |= w >>> 26;
} else {
off += 8;
}
}
} else {
var parseLength = number.length - start;
for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) {
w = parseHexByte(number, start, i) << off;
this.words[j] |= w & 67108863;
if (off >= 18) {
off -= 18;
j += 1;
this.words[j] |= w >>> 26;
} else {
off += 8;
}
}
}
this._strip();
};
function parseBase(str, start, end, mul3) {
var r3 = 0;
var b = 0;
var len = Math.min(str.length, end);
for (var i = start; i < len; i++) {
var c = str.charCodeAt(i) - 48;
r3 *= mul3;
if (c >= 49) {
b = c - 49 + 10;
} else if (c >= 17) {
b = c - 17 + 10;
} else {
b = c;
}
assert3(c >= 0 && b < mul3, "Invalid character");
r3 += b;
}
return r3;
}
BN3.prototype._parseBase = function _parseBase(number, base2, start) {
this.words = [0];
this.length = 1;
for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base2) {
limbLen++;
}
limbLen--;
limbPow = limbPow / base2 | 0;
var total = number.length - start;
var mod = total % limbLen;
var end = Math.min(total, total - mod) + start;
var word = 0;
for (var i = start; i < end; i += limbLen) {
word = parseBase(number, i, i + limbLen, base2);
this.imuln(limbPow);
if (this.words[0] + word < 67108864) {
this.words[0] += word;
} else {
this._iaddn(word);
}
}
if (mod !== 0) {
var pow = 1;
word = parseBase(number, i, number.length, base2);
for (i = 0; i < mod; i++) {
pow *= base2;
}
this.imuln(pow);
if (this.words[0] + word < 67108864) {
this.words[0] += word;
} else {
this._iaddn(word);
}
}
this._strip();
};
BN3.prototype.copy = function copy(dest) {
dest.words = new Array(this.length);
for (var i = 0; i < this.length; i++) {
dest.words[i] = this.words[i];
}
dest.length = this.length;
dest.negative = this.negative;
dest.red = this.red;
};
function move(dest, src) {
dest.words = src.words;
dest.length = src.length;
dest.negative = src.negative;
dest.red = src.red;
}
BN3.prototype._move = function _move(dest) {
move(dest, this);
};
BN3.prototype.clone = function clone2() {
var r3 = new BN3(null);
this.copy(r3);
return r3;
};
BN3.prototype._expand = function _expand(size) {
while (this.length < size) {
this.words[this.length++] = 0;
}
return this;
};
BN3.prototype._strip = function strip() {
while (this.length > 1 && this.words[this.length - 1] === 0) {
this.length--;
}
return this._normSign();
};
BN3.prototype._normSign = function _normSign() {
if (this.length === 1 && this.words[0] === 0) {
this.negative = 0;
}
return this;
};
if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") {
try {
BN3.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect4;
} catch (e) {
BN3.prototype.inspect = inspect4;
}
} else {
BN3.prototype.inspect = inspect4;
}
function inspect4() {
return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
}
var zeros2 = [
"",
"0",
"00",
"000",
"0000",
"00000",
"000000",
"0000000",
"00000000",
"000000000",
"0000000000",
"00000000000",
"000000000000",
"0000000000000",
"00000000000000",
"000000000000000",
"0000000000000000",
"00000000000000000",
"000000000000000000",
"0000000000000000000",
"00000000000000000000",
"000000000000000000000",
"0000000000000000000000",
"00000000000000000000000",
"000000000000000000000000",
"0000000000000000000000000"
];
var groupSizes = [
0,
0,
25,
16,
12,
11,
10,
9,
8,
8,
7,
7,
7,
7,
6,
6,
6,
6,
6,
6,
6,
5,
5,
5,
5,
5,
5,
5,
5,
5,
5,
5,
5,
5,
5,
5,
5
];
var groupBases = [
0,
0,
33554432,
43046721,
16777216,
48828125,
60466176,
40353607,
16777216,
43046721,
1e7,
19487171,
35831808,
62748517,
7529536,
11390625,
16777216,
24137569,
34012224,
47045881,
64e6,
4084101,
5153632,
6436343,
7962624,
9765625,
11881376,
14348907,
17210368,
20511149,
243e5,
28629151,
33554432,
39135393,
45435424,
52521875,
60466176
];
BN3.prototype.toString = function toString(base2, padding2) {
base2 = base2 || 10;
padding2 = padding2 | 0 || 1;
var out;
if (base2 === 16 || base2 === "hex") {
out = "";
var off = 0;
var carry = 0;
for (var i = 0; i < this.length; i++) {
var w = this.words[i];
var word = ((w << off | carry) & 16777215).toString(16);
carry = w >>> 24 - off & 16777215;
off += 2;
if (off >= 26) {
off -= 26;
i--;
}
if (carry !== 0 || i !== this.length - 1) {
out = zeros2[6 - word.length] + word + out;
} else {
out = word + out;
}
}
if (carry !== 0) {
out = carry.toString(16) + out;
}
while (out.length % padding2 !== 0) {
out = "0" + out;
}
if (this.negative !== 0) {
out = "-" + out;
}
return out;
}
if (base2 === (base2 | 0) && base2 >= 2 && base2 <= 36) {
var groupSize = groupSizes[base2];
var groupBase = groupBases[base2];
out = "";
var c = this.clone();
c.negative = 0;
while (!c.isZero()) {
var r3 = c.modrn(groupBase).toString(base2);
c = c.idivn(groupBase);
if (!c.isZero()) {
out = zeros2[groupSize - r3.length] + r3 + out;
} else {
out = r3 + out;
}
}
if (this.isZero()) {
out = "0" + out;
}
while (out.length % padding2 !== 0) {
out = "0" + out;
}
if (this.negative !== 0) {
out = "-" + out;
}
return out;
}
assert3(false, "Base should be between 2 and 36");
};
BN3.prototype.toNumber = function toNumber() {
var ret = this.words[0];
if (this.length === 2) {
ret += this.words[1] * 67108864;
} else if (this.length === 3 && this.words[2] === 1) {
ret += 4503599627370496 + this.words[1] * 67108864;
} else if (this.length > 2) {
assert3(false, "Number can only safely store up to 53 bits");
}
return this.negative !== 0 ? -ret : ret;
};
BN3.prototype.toJSON = function toJSON2() {
return this.toString(16, 2);
};
if (Buffer2) {
BN3.prototype.toBuffer = function toBuffer(endian, length) {
return this.toArrayLike(Buffer2, endian, length);
};
}
BN3.prototype.toArray = function toArray2(endian, length) {
return this.toArrayLike(Array, endian, length);
};
var allocate = function allocate2(ArrayType, size) {
if (ArrayType.allocUnsafe) {
return ArrayType.allocUnsafe(size);
}
return new ArrayType(size);
};
BN3.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
this._strip();
var byteLength = this.byteLength();
var reqLength = length || Math.max(1, byteLength);
assert3(byteLength <= reqLength, "byte array longer than desired length");
assert3(reqLength > 0, "Requested array length <= 0");
var res = allocate(ArrayType, reqLength);
var postfix = endian === "le" ? "LE" : "BE";
this["_toArrayLike" + postfix](res, byteLength);
return res;
};
BN3.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
var position = 0;
var carry = 0;
for (var i = 0, shift = 0; i < this.length; i++) {
var word = this.words[i] << shift | carry;
res[position++] = word & 255;
if (position < res.length) {
res[position++] = word >> 8 & 255;
}
if (position < res.length) {
res[position++] = word >> 16 & 255;
}
if (shift === 6) {
if (position < res.length) {
res[position++] = word >> 24 & 255;
}
carry = 0;
shift = 0;
} else {
carry = word >>> 24;
shift += 2;
}
}
if (position < res.length) {
res[position++] = carry;
while (position < res.length) {
res[position++] = 0;
}
}
};
BN3.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
var position = res.length - 1;
var carry = 0;
for (var i = 0, shift = 0; i < this.length; i++) {
var word = this.words[i] << shift | carry;
res[position--] = word & 255;
if (position >= 0) {
res[position--] = word >> 8 & 255;
}
if (position >= 0) {
res[position--] = word >> 16 & 255;
}
if (shift === 6) {
if (position >= 0) {
res[position--] = word >> 24 & 255;
}
carry = 0;
shift = 0;
} else {
carry = word >>> 24;
shift += 2;
}
}
if (position >= 0) {
res[position--] = carry;
while (position >= 0) {
res[position--] = 0;
}
}
};
if (Math.clz32) {
BN3.prototype._countBits = function _countBits(w) {
return 32 - Math.clz32(w);
};
} else {
BN3.prototype._countBits = function _countBits(w) {
var t = w;
var r3 = 0;
if (t >= 4096) {
r3 += 13;
t >>>= 13;
}
if (t >= 64) {
r3 += 7;
t >>>= 7;
}
if (t >= 8) {
r3 += 4;
t >>>= 4;
}
if (t >= 2) {
r3 += 2;
t >>>= 2;
}
return r3 + t;
};
}
BN3.prototype._zeroBits = function _zeroBits(w) {
if (w === 0)
return 26;
var t = w;
var r3 = 0;
if ((t & 8191) === 0) {
r3 += 13;
t >>>= 13;
}
if ((t & 127) === 0) {
r3 += 7;
t >>>= 7;
}
if ((t & 15) === 0) {
r3 += 4;
t >>>= 4;
}
if ((t & 3) === 0) {
r3 += 2;
t >>>= 2;
}
if ((t & 1) === 0) {
r3++;
}
return r3;
};
BN3.prototype.bitLength = function bitLength() {
var w = this.words[this.length - 1];
var hi = this._countBits(w);
return (this.length - 1) * 26 + hi;
};
function toBitArray(num) {
var w = new Array(num.bitLength());
for (var bit = 0; bit < w.length; bit++) {
var off = bit / 26 | 0;
var wbit = bit % 26;
w[bit] = num.words[off] >>> wbit & 1;
}
return w;
}
BN3.prototype.zeroBits = function zeroBits() {
if (this.isZero())
return 0;
var r3 = 0;
for (var i = 0; i < this.length; i++) {
var b = this._zeroBits(this.words[i]);
r3 += b;
if (b !== 26)
break;
}
return r3;
};
BN3.prototype.byteLength = function byteLength() {
return Math.ceil(this.bitLength() / 8);
};
BN3.prototype.toTwos = function toTwos(width) {
if (this.negative !== 0) {
return this.abs().inotn(width).iaddn(1);
}
return this.clone();
};
BN3.prototype.fromTwos = function fromTwos(width) {
if (this.testn(width - 1)) {
return this.notn(width).iaddn(1).ineg();
}
return this.clone();
};
BN3.prototype.isNeg = function isNeg() {
return this.negative !== 0;
};
BN3.prototype.neg = function neg3() {
return this.clone().ineg();
};
BN3.prototype.ineg = function ineg() {
if (!this.isZero()) {
this.negative ^= 1;
}
return this;
};
BN3.prototype.iuor = function iuor(num) {
while (this.length < num.length) {
this.words[this.length++] = 0;
}
for (var i = 0; i < num.length; i++) {
this.words[i] = this.words[i] | num.words[i];
}
return this._strip();
};
BN3.prototype.ior = function ior(num) {
assert3((this.negative | num.negative) === 0);
return this.iuor(num);
};
BN3.prototype.or = function or(num) {
if (this.length > num.length)
return this.clone().ior(num);
return num.clone().ior(this);
};
BN3.prototype.uor = function uor(num) {
if (this.length > num.length)
return this.clone().iuor(num);
return num.clone().iuor(this);
};
BN3.prototype.iuand = function iuand(num) {
var b;
if (this.length > num.length) {
b = num;
} else {
b = this;
}
for (var i = 0; i < b.length; i++) {
this.words[i] = this.words[i] & num.words[i];
}
this.length = b.length;
return this._strip();
};
BN3.prototype.iand = function iand(num) {
assert3((this.negative | num.negative) === 0);
return this.iuand(num);
};
BN3.prototype.and = function and(num) {
if (this.length > num.length)
return this.clone().iand(num);
return num.clone().iand(this);
};
BN3.prototype.uand = function uand(num) {
if (this.length > num.length)
return this.clone().iuand(num);
return num.clone().iuand(this);
};
BN3.prototype.iuxor = function iuxor(num) {
var a;
var b;
if (this.length > num.length) {
a = this;
b = num;
} else {
a = num;
b = this;
}
for (var i = 0; i < b.length; i++) {
this.words[i] = a.words[i] ^ b.words[i];
}
if (this !== a) {
for (; i < a.length; i++) {
this.words[i] = a.words[i];
}
}
this.length = a.length;
return this._strip();
};
BN3.prototype.ixor = function ixor(num) {
assert3((this.negative | num.negative) === 0);
return this.iuxor(num);
};
BN3.prototype.xor = function xor(num) {
if (this.length > num.length)
return this.clone().ixor(num);
return num.clone().ixor(this);
};
BN3.prototype.uxor = function uxor(num) {
if (this.length > num.length)
return this.clone().iuxor(num);
return num.clone().iuxor(this);
};
BN3.prototype.inotn = function inotn(width) {
assert3(typeof width === "number" && width >= 0);
var bytesNeeded = Math.ceil(width / 26) | 0;
var bitsLeft = width % 26;
this._expand(bytesNeeded);
if (bitsLeft > 0) {
bytesNeeded--;
}
for (var i = 0; i < bytesNeeded; i++) {
this.words[i] = ~this.words[i] & 67108863;
}
if (bitsLeft > 0) {
this.words[i] = ~this.words[i] & 67108863 >> 26 - bitsLeft;
}
return this._strip();
};
BN3.prototype.notn = function notn(width) {
return this.clone().inotn(width);
};
BN3.prototype.setn = function setn(bit, val) {
assert3(typeof bit === "number" && bit >= 0);
var off = bit / 26 | 0