aboutsummaryrefslogtreecommitdiff
path: root/src/js/node
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/node')
-rw-r--r--src/js/node/assert.js29
-rw-r--r--src/js/node/assert.strict.ts49
-rw-r--r--src/js/node/async_hooks.ts21
-rw-r--r--src/js/node/child_process.js58
-rw-r--r--src/js/node/cluster.ts52
-rw-r--r--src/js/node/console.ts1
-rw-r--r--src/js/node/crypto.js12183
-rw-r--r--src/js/node/dgram.ts7
-rw-r--r--src/js/node/diagnostics_channel.ts (renamed from src/js/node/diagnostics_channel.js)7
-rw-r--r--src/js/node/dns.js42
-rw-r--r--src/js/node/dns.promises.js47
-rw-r--r--src/js/node/dns.promises.ts2
-rw-r--r--src/js/node/domain.ts60
-rw-r--r--src/js/node/events.js127
-rw-r--r--src/js/node/fs.js77
-rw-r--r--src/js/node/fs.promises.ts132
-rw-r--r--src/js/node/http.ts80
-rw-r--r--src/js/node/http2.ts19
-rw-r--r--src/js/node/https.ts47
-rw-r--r--src/js/node/inspector.ts8
-rw-r--r--src/js/node/net.js10
-rw-r--r--src/js/node/os.ts (renamed from src/js/node/os.js)34
-rw-r--r--src/js/node/path.posix.ts37
-rw-r--r--src/js/node/path.ts54
-rw-r--r--src/js/node/path.win32.ts36
-rw-r--r--src/js/node/perf_hooks.js43
-rw-r--r--src/js/node/perf_hooks.ts59
-rw-r--r--src/js/node/punycode.js431
-rw-r--r--src/js/node/querystring.js396
-rw-r--r--src/js/node/readline.js34
-rw-r--r--src/js/node/readline.promises.js11
-rw-r--r--src/js/node/readline.promises.ts2
-rw-r--r--src/js/node/repl.ts7
-rw-r--r--src/js/node/stream.consumers.js13
-rw-r--r--src/js/node/stream.js309
-rw-r--r--src/js/node/stream.promises.js10
-rw-r--r--src/js/node/stream.promises.ts2
-rw-r--r--src/js/node/stream.web.js28
-rw-r--r--src/js/node/timers.js9
-rw-r--r--src/js/node/timers.promises.js11
-rw-r--r--src/js/node/tls.js40
-rw-r--r--src/js/node/trace_events.ts5
-rw-r--r--src/js/node/url.js24
-rw-r--r--src/js/node/util.js82
-rw-r--r--src/js/node/v8.ts34
-rw-r--r--src/js/node/vm.ts40
-rw-r--r--src/js/node/wasi.js12
-rw-r--r--src/js/node/worker_threads.ts1
-rw-r--r--src/js/node/zlib.js104
49 files changed, 1508 insertions, 13418 deletions
diff --git a/src/js/node/assert.js b/src/js/node/assert.js
index a00a84509..475f72006 100644
--- a/src/js/node/assert.js
+++ b/src/js/node/assert.js
@@ -1,6 +1,5 @@
// Hardcoded module "node:assert"
-var { Bun } = $lazy("primordials");
-import util from "node:util";
+const util = require("node:util");
var isDeepEqual = Bun.deepEquals;
var __commonJS = (cb, mod) =>
@@ -653,7 +652,6 @@ var require_assertion_error = __commonJS({
.concat(indicator);
}
var AssertionError = /* @__PURE__ */ (function (_Error) {
- _inherits(AssertionError2, _Error);
function AssertionError2(options) {
var _this;
if ((_classCallCheck(this, AssertionError2), _typeof(options) !== "object" || options === null))
@@ -781,6 +779,8 @@ should equal
_possibleConstructorReturn(_this)
);
}
+ AssertionError2.prototype = {};
+ _inherits(AssertionError2, _Error);
return (
_createClass(AssertionError2, [
{
@@ -830,6 +830,7 @@ var require_assert = __commonJS({
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
}
+
var _require = require_errors(),
_require$codes = _require.codes,
ERR_AMBIGUOUS_ARGUMENT = _require$codes.ERR_AMBIGUOUS_ARGUMENT,
@@ -1256,26 +1257,6 @@ function CallTracker() {
throw new Error("CallTracker is not supported yet");
}
-assert_module[Symbol.for("CommonJS")] = 0;
assert_module["CallTracker"] = CallTracker;
-export var {
- AssertionError,
- assert,
- deepEqual,
- deepStrictEqual,
- doesNotReject,
- doesNotThrow,
- equal,
- fail,
- ifError,
- notDeepEqual,
- notDeepStrictEqual,
- notEqual,
- notStrictEqual,
- ok,
- rejects,
- strict,
- strictEqual,
- throws,
-} = assert_module;
+
export default assert_module;
diff --git a/src/js/node/assert.strict.ts b/src/js/node/assert.strict.ts
index f512c3c91..f12edbff1 100644
--- a/src/js/node/assert.strict.ts
+++ b/src/js/node/assert.strict.ts
@@ -1,49 +1,2 @@
// Hardcoded module "node:assert/strict"
-import { strict as strictBase } from "node:assert";
-
-export var {
- fail,
- AssertionError,
- ok,
- equal,
- notEqual,
- deepEqual,
- notDeepEqual,
- deepStrictEqual,
- notDeepStrictEqual,
- strictEqual,
- notStrictEqual,
- throws,
- rejects,
- doesNotThrow,
- doesNotReject,
- ifError,
- match,
- doesNotMatch,
- CallTracker,
-} = strictBase;
-
-const defaultObject = {
- fail,
- AssertionError,
- ok,
- equal,
- notEqual,
- deepEqual,
- notDeepEqual,
- deepStrictEqual,
- notDeepStrictEqual,
- strictEqual,
- notStrictEqual,
- throws,
- rejects,
- doesNotThrow,
- doesNotReject,
- ifError,
- match,
- doesNotMatch,
- CallTracker,
- [Symbol.for("CommonJS")]: 0,
-};
-
-export { defaultObject as default, strictBase as strict };
+export default require("node:assert").strict;
diff --git a/src/js/node/async_hooks.ts b/src/js/node/async_hooks.ts
index da9f6c136..2a671b6a2 100644
--- a/src/js/node/async_hooks.ts
+++ b/src/js/node/async_hooks.ts
@@ -21,7 +21,15 @@
// AsyncContextData is an immutable array managed in here, formatted [key, value, key, value] where
// each key is an AsyncLocalStorage object and the value is the associated value.
//
-const { get, set, cleanupLater } = $lazy("async_hooks");
+const { cleanupLater } = $lazy("async_hooks");
+
+function get(): ReadonlyArray<any> | undefined {
+ return $getInternalField($asyncContext, 0);
+}
+
+function set(contextValue: ReadonlyArray<any> | undefined) {
+ return $putInternalField($asyncContext, 0, contextValue);
+}
class AsyncLocalStorage {
#disableCalled = false;
@@ -298,16 +306,6 @@ const asyncWrapProviders = {
INSPECTORJSBINDING: 57,
};
-export {
- AsyncLocalStorage,
- createHook,
- executionAsyncId,
- triggerAsyncId,
- executionAsyncResource,
- asyncWrapProviders,
- AsyncResource,
-};
-
export default {
AsyncLocalStorage,
createHook,
@@ -316,5 +314,4 @@ export default {
executionAsyncResource,
asyncWrapProviders,
AsyncResource,
- [Symbol.for("CommonJS")]: 0,
};
diff --git a/src/js/node/child_process.js b/src/js/node/child_process.js
index edcb51cef..ef96dbce5 100644
--- a/src/js/node/child_process.js
+++ b/src/js/node/child_process.js
@@ -1,13 +1,11 @@
// Hardcoded module "node:child_process"
-import { EventEmitter } from "node:events";
-import * as StreamModule from "node:stream";
-import { constants } from "node:os";
-import { promisify } from "node:util";
-const signals = constants.signals;
+const EventEmitter = require("node:events");
+const StreamModule = require("node:stream");
+const {
+ constants: { signals },
+} = require("node:os");
+const { promisify } = require("node:util");
-const { ArrayBuffer, Uint8Array, String, Object, Buffer, Promise } = $lazy("primordials");
-
-var ObjectPrototypeHasOwnProperty = Object.prototype.hasOwnProperty;
var ObjectCreate = Object.create;
var ObjectAssign = Object.assign;
var ObjectDefineProperty = Object.defineProperty;
@@ -39,17 +37,9 @@ var Uint8ArrayPrototypeIncludes = Uint8Array.prototype.includes;
const MAX_BUFFER = 1024 * 1024;
-// General debug vs tracking stdio streams. Useful for stream debugging in particular
-const __DEBUG__ = process.env.DEBUG || false;
-
-// You can use this env var along with `process.env.DEBUG_TRACK_EE` to debug stdio streams
-// Just set `DEBUG_TRACK_EE=PARENT_STDOUT-0, PARENT_STDOUT-1`, etc. and `DEBUG_STDIO=1` and you will be able to track particular stdio streams
-// TODO: Add ability to track a range of IDs rather than just enumerated ones
-const __TRACK_STDIO__ = process.env.DEBUG_STDIO;
-const debug = __DEBUG__ ? console.log : () => {};
-
-if (__TRACK_STDIO__) {
- debug("child_process: debug mode on");
+// Pass DEBUG_CHILD_PROCESS=1 to enable debug output
+if ($debug) {
+ $debug("child_process: debug mode on");
globalThis.__lastId = null;
globalThis.__getId = () => {
return globalThis.__lastId !== null ? globalThis.__lastId++ : 0;
@@ -156,14 +146,14 @@ function spawnTimeoutFunction(child, timeoutHolder) {
* }} [options]
* @returns {ChildProcess}
*/
-export function spawn(file, args, options) {
+function spawn(file, args, options) {
options = normalizeSpawnArguments(file, args, options);
validateTimeout(options.timeout);
validateAbortSignal(options.signal, "options.signal");
const killSignal = sanitizeKillSignal(options.killSignal);
const child = new ChildProcess();
- debug("spawn", options);
+ $debug("spawn", options);
child.spawn(options);
if (options.timeout > 0) {
@@ -227,7 +217,7 @@ export function spawn(file, args, options) {
* ) => any} [callback]
* @returns {ChildProcess}
*/
-export function execFile(file, args, options, callback) {
+function execFile(file, args, options, callback) {
({ file, args, options, callback } = normalizeExecFileArgs(file, args, options, callback));
options = {
@@ -481,7 +471,7 @@ export function execFile(file, args, options, callback) {
* ) => any} [callback]
* @returns {ChildProcess}
*/
-export function exec(command, options, callback) {
+function exec(command, options, callback) {
const opts = normalizeExecArgs(command, options, callback);
return execFile(opts.file, opts.options, opts.callback);
}
@@ -543,7 +533,7 @@ ObjectDefineProperty(exec, promisify.custom, {
* error: Error;
* }}
*/
-export function spawnSync(file, args, options) {
+function spawnSync(file, args, options) {
options = {
maxBuffer: MAX_BUFFER,
...normalizeSpawnArguments(file, args, options),
@@ -552,7 +542,7 @@ export function spawnSync(file, args, options) {
const maxBuffer = options.maxBuffer;
const encoding = options.encoding;
- debug("spawnSync", options);
+ $debug("spawnSync", options);
// Validate the timeout, if present.
validateTimeout(options.timeout);
@@ -631,7 +621,7 @@ export function spawnSync(file, args, options) {
* }} [options]
* @returns {Buffer | string}
*/
-export function execFileSync(file, args, options) {
+function execFileSync(file, args, options) {
({ file, args, options } = normalizeExecFileArgs(file, args, options));
// const inheritStderr = !options.stdio;
@@ -667,7 +657,7 @@ export function execFileSync(file, args, options) {
* }} [options]
* @returns {Buffer | string}
*/
-export function execSync(command, options) {
+function execSync(command, options) {
const opts = normalizeExecArgs(command, options, null);
// const inheritStderr = !opts.options.stdio;
@@ -725,7 +715,7 @@ function stdioStringToArray(stdio, channel) {
* }} [options]
* @returns {ChildProcess}
*/
-export function fork(modulePath, args = [], options) {
+function fork(modulePath, args = [], options) {
modulePath = getValidatedPath(modulePath, "modulePath");
// Get options and args arguments.
@@ -975,7 +965,7 @@ function checkExecSyncError(ret, args, cmd) {
//------------------------------------------------------------------------------
// Section 3. ChildProcess class
//------------------------------------------------------------------------------
-export class ChildProcess extends EventEmitter {
+class ChildProcess extends EventEmitter {
#handle;
#exited = false;
#closesNeeded = 1;
@@ -1045,11 +1035,11 @@ export class ChildProcess extends EventEmitter {
}
#getBunSpawnIo(i, encoding) {
- if (__DEBUG__ && !this.#handle) {
+ if ($debug && !this.#handle) {
if (this.#handle === null) {
- debug("ChildProcess: getBunSpawnIo: this.#handle is null. This means the subprocess already exited");
+ $debug("ChildProcess: getBunSpawnIo: this.#handle is null. This means the subprocess already exited");
} else {
- debug("ChildProcess: getBunSpawnIo: this.#handle is undefined");
+ $debug("ChildProcess: getBunSpawnIo: this.#handle is undefined");
}
}
@@ -1253,7 +1243,7 @@ export class ChildProcess extends EventEmitter {
}
#maybeClose() {
- debug("Attempting to maybe close...");
+ $debug("Attempting to maybe close...");
this.#closesGot++;
if (this.#closesGot === this.#closesNeeded) {
this.emit("close", this.exitCode, this.signalCode);
@@ -1836,6 +1826,4 @@ export default {
spawnSync,
execFileSync,
execSync,
-
- [Symbol.for("CommonJS")]: 0,
};
diff --git a/src/js/node/cluster.ts b/src/js/node/cluster.ts
index 1be94eeb2..8c1ebdd09 100644
--- a/src/js/node/cluster.ts
+++ b/src/js/node/cluster.ts
@@ -2,51 +2,39 @@
// This is a stub
// We leave it in here to provide a better error message
// TODO: implement node cluster
-import EventEmitter from "node:events";
-import { throwNotImplemented } from "../shared";
-
-export var SCHED_NONE = 0,
- SCHED_RR = 1,
- Worker,
- schedulingPolicy = 2,
- isWorker = false,
- isPrimary = true,
- isMaster = true,
- cluster;
-
-Worker = function Worker() {
- throwNotImplemented("node:cluster Worker", 2428);
-};
+const EventEmitter = require("node:events");
+const { throwNotImplemented } = require("$shared");
// TODO: is it okay for this to be a class?
class Cluster extends EventEmitter {
- static isWorker = false;
- static isPrimary = true;
- static isMaster = true;
+ isWorker = false;
+ isPrimary = true;
+ isMaster = true;
+ workers = {};
+ settings = {};
+ SCHED_NONE = 1;
+ SCHED_RR = 2;
+ schedulingPolicy = 2;
- static Worker = Worker;
+ Worker = function Worker() {
+ throwNotImplemented("node:cluster Worker", 2428);
+ };
- fork() {
+ setupPrimary() {
throwNotImplemented("node:cluster", 2428);
}
- disconnect() {
+ setupMaster() {
throwNotImplemented("node:cluster", 2428);
}
- setupMaster() {
+ fork() {
throwNotImplemented("node:cluster", 2428);
}
- settings = {};
- workers = {};
- SCHED_NONE = 0;
- SCHED_RR = 1;
- schedulingPolicy = 2;
- // @ts-expect-error
- [Symbol.for("CommonJS")] = 0;
+ disconnect() {
+ throwNotImplemented("node:cluster", 2428);
+ }
}
-cluster = new Cluster();
-
-export { cluster as default };
+export default new Cluster();
diff --git a/src/js/node/console.ts b/src/js/node/console.ts
new file mode 100644
index 000000000..34cc54b56
--- /dev/null
+++ b/src/js/node/console.ts
@@ -0,0 +1 @@
+export default console;
diff --git a/src/js/node/crypto.js b/src/js/node/crypto.js
index 0e4840d38..351f6adff 100644
--- a/src/js/node/crypto.js
+++ b/src/js/node/crypto.js
@@ -1,18 +1,14 @@
// Hardcoded module "node:crypto"
-var __create = Object.create;
var __defProp = Object.defineProperty;
-var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-var __getProtoOf = Object.getPrototypeOf,
- __hasOwnProp = Object.prototype.hasOwnProperty;
-import { StringDecoder } from "node:string_decoder";
-import * as BufferModule from "node:buffer";
-import * as StreamModule from "node:stream";
+const StreamModule = require("node:stream");
+const BufferModule = require("node:buffer");
+const StringDecoder = require("node:string_decoder").StringDecoder;
const MAX_STRING_LENGTH = 536870888;
var Buffer = globalThis.Buffer;
const EMPTY_BUFFER = Buffer.alloc(0);
-const { isAnyArrayBuffer, isArrayBufferView } = require("util/types");
+const { isAnyArrayBuffer, isArrayBufferView } = require("node:util/types");
function getArrayBufferOrView(buffer, name, encoding) {
if (isAnyArrayBuffer(buffer)) return buffer;
@@ -34,38 +30,13 @@ function getArrayBufferOrView(buffer, name, encoding) {
const crypto = globalThis.crypto;
const globalCrypto = crypto;
-var __esm = (fn, res) =>
- function () {
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])((fn = 0))), res;
- };
var __commonJS = (cb, mod) =>
function () {
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: !0 });
- },
- __copyProps = (to, from, except, desc) => {
- if ((from && typeof from == "object") || typeof from == "function")
- for (let key of __getOwnPropNames(from))
- !__hasOwnProp.call(to, key) &&
- key !== except &&
- __defProp(to, key, {
- get: () => from[key],
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
- });
- return to;
- },
- __reExport = (target, mod, secondTarget) => (
- __copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")
- ),
- __toESM = (mod, isNodeMode, target) => (
- (target = mod != null ? __create(__getProtoOf(mod)) : {}),
- __copyProps(
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
- mod,
- )
- );
+ for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0 });
+};
// node_modules/safe-buffer/index.js
var require_safe_buffer = __commonJS({
@@ -138,28 +109,18 @@ Use Chrome, Firefox or Internet Explorer 11`);
// node_modules/inherits/inherits_browser.js
var require_inherits_browser = __commonJS({
"node_modules/inherits/inherits_browser.js"(exports, module) {
- typeof Object.create == "function"
- ? (module.exports = function (ctor, superCtor) {
- superCtor &&
- ((ctor.super_ = superCtor),
- (ctor.prototype = Object.create(superCtor.prototype, {
- constructor: {
- value: ctor,
- enumerable: !1,
- writable: !0,
- configurable: !0,
- },
- })));
- })
- : (module.exports = function (ctor, superCtor) {
- if (superCtor) {
- ctor.super_ = superCtor;
- var TempCtor = function () {};
- (TempCtor.prototype = superCtor.prototype),
- (ctor.prototype = new TempCtor()),
- (ctor.prototype.constructor = ctor);
- }
- });
+ module.exports = function (ctor, superCtor) {
+ superCtor &&
+ ((ctor.super_ = superCtor),
+ (ctor.prototype = Object.create(superCtor.prototype, {
+ constructor: {
+ value: ctor,
+ enumerable: !1,
+ writable: !0,
+ configurable: !0,
+ },
+ })));
+ };
},
});
@@ -496,6 +457,7 @@ var require_hash = __commonJS({
(this._blockSize = blockSize),
(this._len = 0);
}
+ Hash.prototype = {};
Hash.prototype.update = function (data, enc) {
typeof data == "string" && ((enc = enc || "utf8"), (data = Buffer2.from(data, enc)));
for (
@@ -1149,7 +1111,7 @@ var require_cipher_base = __commonJS({
// node_modules/create-hash/browser.js
var require_browser2 = __commonJS({
"node_modules/create-hash/browser.js"(exports, module) {
- ("use strict");
+ "use strict";
// does not become a node stream unless you create it into one
const LazyHash = function Hash(algorithm, options) {
this._options = options;
@@ -1329,6 +1291,7 @@ var require_legacy = __commonJS({
(ipad[i] = key[i] ^ 54), (opad[i] = key[i] ^ 92);
this._hash = [ipad];
}
+ Hmac.prototype = {};
inherits(Hmac, Base);
Hmac.prototype._update = function (data) {
this._hash.push(data);
@@ -1355,14 +1318,14 @@ var require_md52 = __commonJS({
var require_browser3 = __commonJS({
"node_modules/create-hmac/browser.js"(exports, module) {
"use strict";
- var inherits = require_inherits_browser(),
- Legacy = require_legacy(),
- Base = require_cipher_base(),
- Buffer2 = require_safe_buffer().Buffer,
- md5 = require_md52(),
- RIPEMD160 = require_ripemd160(),
- sha = require_sha2(),
- ZEROS = Buffer2.alloc(128);
+ var inherits = require_inherits_browser();
+ var Legacy = require_legacy();
+ var Base = require_cipher_base();
+ var Buffer2 = require_safe_buffer().Buffer;
+ var md5 = require_md52();
+ var RIPEMD160 = require_ripemd160();
+ var sha = require_sha2();
+ var ZEROS = Buffer2.alloc(128);
function Hmac(alg, key) {
Base.call(this, "digest"), typeof key == "string" && (key = Buffer2.from(key));
var blocksize = alg === "sha512" || alg === "sha384" ? 128 : 64;
@@ -1653,6 +1616,7 @@ var require_sync_browser = __commonJS({
(this.hash = hash),
(this.size = sizes[alg]);
}
+ Hmac.prototype = {};
Hmac.prototype.run = function (data, ipad) {
data.copy(ipad, this.blocksize);
var h = this.hash(ipad);
@@ -1958,6 +1922,7 @@ var require_cipher = __commonJS({
(this.buffer = new Array(this.blockSize)),
(this.bufferOff = 0);
}
+ Cipher.prototype = {};
module.exports = Cipher;
Cipher.prototype._init = function () {};
Cipher.prototype.update = function (data) {
@@ -2778,6 +2743,7 @@ var require_aes = __commonJS({
function AES(key) {
(this._key = asUInt32Array(key)), this._reset();
}
+ AES.prototype = {};
AES.blockSize = 4 * 4;
AES.keySize = 256 / 8;
AES.prototype.blockSize = AES.blockSize;
@@ -2882,6 +2848,7 @@ var require_ghash = __commonJS({
function GHASH(key) {
(this.h = key), (this.state = Buffer2.alloc(16, 0)), (this.cache = Buffer2.allocUnsafe(0));
}
+ GHASH.prototype = {};
GHASH.prototype.ghash = function (block) {
for (var i = -1; ++i < block.length; ) this.state[i] ^= block[i];
this._multiply();
@@ -3102,6 +3069,7 @@ var require_encrypter = __commonJS({
function Splitter() {
this.cache = Buffer2.allocUnsafe(0);
}
+ Splitter.prototype = {};
Splitter.prototype.add = function (data) {
this.cache = Buffer2.concat([this.cache, data]);
};
@@ -3191,6 +3159,7 @@ var require_decrypter = __commonJS({
function Splitter() {
this.cache = Buffer2.allocUnsafe(0);
}
+ Splitter.prototype = {};
Splitter.prototype.add = function (data) {
this.cache = Buffer2.concat([this.cache, data]);
};
@@ -3367,6 +3336,7 @@ var require_bn = __commonJS({
((base === "le" || base === "be") && ((endian = base), (base = 10)),
this._init(number || 0, base || 10, endian || "be"));
}
+ BN.prototype = {};
typeof module2 == "object" ? (module2.exports = BN) : (exports2.BN = BN), (BN.BN = BN), (BN.wordSize = 26);
var Buffer2 = Buffer;
(BN.isBN = function (num) {
@@ -4432,6 +4402,7 @@ var require_bn = __commonJS({
function FFTM(x, y) {
(this.x = x), (this.y = y);
}
+ FFTM.prototype = {};
(FFTM.prototype.makeRBT = function (N) {
for (var t = new Array(N), l = BN.prototype._countBits(N) - 1, i = 0; i < N; i++) t[i] = this.revBin(i, l, N);
return t;
@@ -5072,6 +5043,7 @@ var require_bn = __commonJS({
(this.k = new BN(1).iushln(this.n).isub(this.p)),
(this.tmp = this._tmp());
}
+ MPrime.prototype = {};
(MPrime.prototype._tmp = function () {
var tmp = new BN(null);
return (tmp.words = new Array(Math.ceil(this.n / 13))), tmp;
@@ -5165,6 +5137,7 @@ var require_bn = __commonJS({
(this.m = prime.p), (this.prime = prime);
} else assert(m.gtn(1), "modulus must be greater than 1"), (this.m = m), (this.prime = null);
}
+ Red.prototype = {};
(Red.prototype._verify1 = function (a) {
assert(a.negative === 0, "red works only with positives"), assert(a.red, "red works only with red numbers");
}),
@@ -5328,1998 +5301,7 @@ var require_bn = __commonJS({
})(typeof module > "u" || module, exports);
},
});
-
-// node_modules/miller-rabin/node_modules/bn.js/lib/bn.js
-var require_bn2 = __commonJS({
- "node_modules/miller-rabin/node_modules/bn.js/lib/bn.js"(exports, module) {
- (function (module2, exports2) {
- "use strict";
- function assert(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 BN(number, base, endian) {
- if (BN.isBN(number)) return number;
- (this.negative = 0),
- (this.words = null),
- (this.length = 0),
- (this.red = null),
- number !== null &&
- ((base === "le" || base === "be") && ((endian = base), (base = 10)),
- this._init(number || 0, base || 10, endian || "be"));
- }
- typeof module2 == "object" ? (module2.exports = BN) : (exports2.BN = BN), (BN.BN = BN), (BN.wordSize = 26);
- var Buffer2 = Buffer;
- (BN.isBN = function (num) {
- return num instanceof BN
- ? !0
- : num !== null &&
- typeof num == "object" &&
- num.constructor.wordSize === BN.wordSize &&
- Array.isArray(num.words);
- }),
- (BN.max = function (left, right) {
- return left.cmp(right) > 0 ? left : right;
- }),
- (BN.min = function (left, right) {
- return left.cmp(right) < 0 ? left : right;
- }),
- (BN.prototype._init = function (number, base, endian) {
- if (typeof number == "number") return this._initNumber(number, base, endian);
- if (typeof number == "object") return this._initArray(number, base, endian);
- base === "hex" && (base = 16),
- assert(base === (base | 0) && base >= 2 && base <= 36),
- (number = number.toString().replace(/\s+/g, ""));
- var start = 0;
- number[0] === "-" && (start++, (this.negative = 1)),
- start < number.length &&
- (base === 16
- ? this._parseHex(number, start, endian)
- : (this._parseBase(number, base, start),
- endian === "le" && this._initArray(this.toArray(), base, endian)));
- }),
- (BN.prototype._initNumber = function (number, base, endian) {
- number < 0 && ((this.negative = 1), (number = -number)),
- number < 67108864
- ? ((this.words = [number & 67108863]), (this.length = 1))
- : number < 4503599627370496
- ? ((this.words = [number & 67108863, (number / 67108864) & 67108863]), (this.length = 2))
- : (assert(number < 9007199254740992),
- (this.words = [number & 67108863, (number / 67108864) & 67108863, 1]),
- (this.length = 3)),
- endian === "le" && this._initArray(this.toArray(), base, endian);
- }),
- (BN.prototype._initArray = function (number, base, endian) {
- if ((assert(typeof number.length == "number"), number.length <= 0))
- return (this.words = [0]), (this.length = 1), 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,
- 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),
- 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),
- off >= 26 && ((off -= 26), j++);
- return this.strip();
- });
- function parseHex4Bits(string, index) {
- var c = string.charCodeAt(index);
- return c >= 65 && c <= 70 ? c - 55 : c >= 97 && c <= 102 ? c - 87 : (c - 48) & 15;
- }
- function parseHexByte(string, lowerBound, index) {
- var r = parseHex4Bits(string, index);
- return index - 1 >= lowerBound && (r |= parseHex4Bits(string, index - 1) << 4), r;
- }
- BN.prototype._parseHex = function (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,
- j = 0,
- w;
- if (endian === "be")
- for (i = number.length - 1; i >= start; i -= 2)
- (w = parseHexByte(number, start, i) << off),
- (this.words[j] |= w & 67108863),
- off >= 18 ? ((off -= 18), (j += 1), (this.words[j] |= w >>> 26)) : (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),
- off >= 18 ? ((off -= 18), (j += 1), (this.words[j] |= w >>> 26)) : (off += 8);
- }
- this.strip();
- };
- function parseBase(str, start, end, mul) {
- for (var r = 0, len = Math.min(str.length, end), i = start; i < len; i++) {
- var c = str.charCodeAt(i) - 48;
- (r *= mul), c >= 49 ? (r += c - 49 + 10) : c >= 17 ? (r += c - 17 + 10) : (r += c);
- }
- return r;
- }
- (BN.prototype._parseBase = function (number, base, start) {
- (this.words = [0]), (this.length = 1);
- for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) limbLen++;
- limbLen--, (limbPow = (limbPow / base) | 0);
- for (
- var total = number.length - start,
- mod = total % limbLen,
- end = Math.min(total, total - mod) + start,
- word = 0,
- i = start;
- i < end;
- i += limbLen
- )
- (word = parseBase(number, i, i + limbLen, base)),
- this.imuln(limbPow),
- this.words[0] + word < 67108864 ? (this.words[0] += word) : this._iaddn(word);
- if (mod !== 0) {
- var pow = 1;
- for (word = parseBase(number, i, number.length, base), i = 0; i < mod; i++) pow *= base;
- this.imuln(pow), this.words[0] + word < 67108864 ? (this.words[0] += word) : this._iaddn(word);
- }
- this.strip();
- }),
- (BN.prototype.copy = function (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);
- }),
- (BN.prototype.clone = function () {
- var r = new BN(null);
- return this.copy(r), r;
- }),
- (BN.prototype._expand = function (size) {
- for (; this.length < size; ) this.words[this.length++] = 0;
- return this;
- }),
- (BN.prototype.strip = function () {
- for (; this.length > 1 && this.words[this.length - 1] === 0; ) this.length--;
- return this._normSign();
- }),
- (BN.prototype._normSign = function () {
- return this.length === 1 && this.words[0] === 0 && (this.negative = 0), this;
- }),
- (BN.prototype.inspect = function () {
- return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
- });
- var zeros = [
- "",
- "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",
- ],
- 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,
- ],
- 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,
- ];
- (BN.prototype.toString = function (base, padding) {
- (base = base || 10), (padding = padding | 0 || 1);
- var out;
- if (base === 16 || base === "hex") {
- out = "";
- for (var off = 0, carry = 0, i = 0; i < this.length; i++) {
- var w = this.words[i],
- word = (((w << off) | carry) & 16777215).toString(16);
- (carry = (w >>> (24 - off)) & 16777215),
- carry !== 0 || i !== this.length - 1 ? (out = zeros[6 - word.length] + word + out) : (out = word + out),
- (off += 2),
- off >= 26 && ((off -= 26), i--);
- }
- for (carry !== 0 && (out = carry.toString(16) + out); out.length % padding !== 0; ) out = "0" + out;
- return this.negative !== 0 && (out = "-" + out), out;
- }
- if (base === (base | 0) && base >= 2 && base <= 36) {
- var groupSize = groupSizes[base],
- groupBase = groupBases[base];
- out = "";
- var c = this.clone();
- for (c.negative = 0; !c.isZero(); ) {
- var r = c.modn(groupBase).toString(base);
- (c = c.idivn(groupBase)), c.isZero() ? (out = r + out) : (out = zeros[groupSize - r.length] + r + out);
- }
- for (this.isZero() && (out = "0" + out); out.length % padding !== 0; ) out = "0" + out;
- return this.negative !== 0 && (out = "-" + out), out;
- }
- assert(!1, "Base should be between 2 and 36");
- }),
- (BN.prototype.toNumber = function () {
- var ret = this.words[0];
- return (
- this.length === 2
- ? (ret += this.words[1] * 67108864)
- : this.length === 3 && this.words[2] === 1
- ? (ret += 4503599627370496 + this.words[1] * 67108864)
- : this.length > 2 && assert(!1, "Number can only safely store up to 53 bits"),
- this.negative !== 0 ? -ret : ret
- );
- }),
- (BN.prototype.toJSON = function () {
- return this.toString(16);
- }),
- (BN.prototype.toBuffer = function (endian, length) {
- return assert(typeof Buffer2 < "u"), this.toArrayLike(Buffer2, endian, length);
- }),
- (BN.prototype.toArray = function (endian, length) {
- return this.toArrayLike(Array, endian, length);
- }),
- (BN.prototype.toArrayLike = function (ArrayType, endian, length) {
- var byteLength = this.byteLength(),
- reqLength = length || Math.max(1, byteLength);
- assert(byteLength <= reqLength, "byte array longer than desired length"),
- assert(reqLength > 0, "Requested array length <= 0"),
- this.strip();
- var littleEndian = endian === "le",
- res = new ArrayType(reqLength),
- b,
- i,
- q = this.clone();
- if (littleEndian) {
- for (i = 0; !q.isZero(); i++) (b = q.andln(255)), q.iushrn(8), (res[i] = b);
- for (; i < reqLength; i++) res[i] = 0;
- } else {
- for (i = 0; i < reqLength - byteLength; i++) res[i] = 0;
- for (i = 0; !q.isZero(); i++) (b = q.andln(255)), q.iushrn(8), (res[reqLength - i - 1] = b);
- }
- return res;
- }),
- Math.clz32
- ? (BN.prototype._countBits = function (w) {
- return 32 - Math.clz32(w);
- })
- : (BN.prototype._countBits = function (w) {
- var t = w,
- r = 0;
- return (
- t >= 4096 && ((r += 13), (t >>>= 13)),
- t >= 64 && ((r += 7), (t >>>= 7)),
- t >= 8 && ((r += 4), (t >>>= 4)),
- t >= 2 && ((r += 2), (t >>>= 2)),
- r + t
- );
- }),
- (BN.prototype._zeroBits = function (w) {
- if (w === 0) return 26;
- var t = w,
- r = 0;
- return (
- (t & 8191) === 0 && ((r += 13), (t >>>= 13)),
- (t & 127) === 0 && ((r += 7), (t >>>= 7)),
- (t & 15) === 0 && ((r += 4), (t >>>= 4)),
- (t & 3) === 0 && ((r += 2), (t >>>= 2)),
- (t & 1) === 0 && r++,
- r
- );
- }),
- (BN.prototype.bitLength = function () {
- var w = this.words[this.length - 1],
- hi = this._countBits(w);
- return (this.length - 1) * 26 + hi;
- });
- function toBitArray(num) {
- for (var w = new Array(num.bitLength()), bit = 0; bit < w.length; bit++) {
- var off = (bit / 26) | 0,
- wbit = bit % 26;
- w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
- }
- return w;
- }
- (BN.prototype.zeroBits = function () {
- if (this.isZero()) return 0;
- for (var r = 0, i = 0; i < this.length; i++) {
- var b = this._zeroBits(this.words[i]);
- if (((r += b), b !== 26)) break;
- }
- return r;
- }),
- (BN.prototype.byteLength = function () {
- return Math.ceil(this.bitLength() / 8);
- }),
- (BN.prototype.toTwos = function (width) {
- return this.negative !== 0 ? this.abs().inotn(width).iaddn(1) : this.clone();
- }),
- (BN.prototype.fromTwos = function (width) {
- return this.testn(width - 1) ? this.notn(width).iaddn(1).ineg() : this.clone();
- }),
- (BN.prototype.isNeg = function () {
- return this.negative !== 0;
- }),
- (BN.prototype.neg = function () {
- return this.clone().ineg();
- }),
- (BN.prototype.ineg = function () {
- return this.isZero() || (this.negative ^= 1), this;
- }),
- (BN.prototype.iuor = function (num) {
- for (; 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();
- }),
- (BN.prototype.ior = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuor(num);
- }),
- (BN.prototype.or = function (num) {
- return this.length > num.length ? this.clone().ior(num) : num.clone().ior(this);
- }),
- (BN.prototype.uor = function (num) {
- return this.length > num.length ? this.clone().iuor(num) : num.clone().iuor(this);
- }),
- (BN.prototype.iuand = function (num) {
- var b;
- this.length > num.length ? (b = num) : (b = this);
- for (var i = 0; i < b.length; i++) this.words[i] = this.words[i] & num.words[i];
- return (this.length = b.length), this.strip();
- }),
- (BN.prototype.iand = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuand(num);
- }),
- (BN.prototype.and = function (num) {
- return this.length > num.length ? this.clone().iand(num) : num.clone().iand(this);
- }),
- (BN.prototype.uand = function (num) {
- return this.length > num.length ? this.clone().iuand(num) : num.clone().iuand(this);
- }),
- (BN.prototype.iuxor = function (num) {
- var a, b;
- this.length > num.length ? ((a = this), (b = num)) : ((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];
- return (this.length = a.length), this.strip();
- }),
- (BN.prototype.ixor = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuxor(num);
- }),
- (BN.prototype.xor = function (num) {
- return this.length > num.length ? this.clone().ixor(num) : num.clone().ixor(this);
- }),
- (BN.prototype.uxor = function (num) {
- return this.length > num.length ? this.clone().iuxor(num) : num.clone().iuxor(this);
- }),
- (BN.prototype.inotn = function (width) {
- assert(typeof width == "number" && width >= 0);
- var bytesNeeded = Math.ceil(width / 26) | 0,
- bitsLeft = width % 26;
- this._expand(bytesNeeded), bitsLeft > 0 && bytesNeeded--;
- for (var i = 0; i < bytesNeeded; i++) this.words[i] = ~this.words[i] & 67108863;
- return bitsLeft > 0 && (this.words[i] = ~this.words[i] & (67108863 >> (26 - bitsLeft))), this.strip();
- }),
- (BN.prototype.notn = function (width) {
- return this.clone().inotn(width);
- }),
- (BN.prototype.setn = function (bit, val) {
- assert(typeof bit == "number" && bit >= 0);
- var off = (bit / 26) | 0,
- wbit = bit % 26;
- return (
- this._expand(off + 1),
- val
- ? (this.words[off] = this.words[off] | (1 << wbit))
- : (this.words[off] = this.words[off] & ~(1 << wbit)),
- this.strip()
- );
- }),
- (BN.prototype.iadd = function (num) {
- var r;
- if (this.negative !== 0 && num.negative === 0)
- return (this.negative = 0), (r = this.isub(num)), (this.negative ^= 1), this._normSign();
- if (this.negative === 0 && num.negative !== 0)
- return (num.negative = 0), (r = this.isub(num)), (num.negative = 1), r._normSign();
- var a, b;
- this.length > num.length ? ((a = this), (b = num)) : ((a = num), (b = this));
- for (var carry = 0, i = 0; i < b.length; i++)
- (r = (a.words[i] | 0) + (b.words[i] | 0) + carry), (this.words[i] = r & 67108863), (carry = r >>> 26);
- for (; carry !== 0 && i < a.length; i++)
- (r = (a.words[i] | 0) + carry), (this.words[i] = r & 67108863), (carry = r >>> 26);
- if (((this.length = a.length), carry !== 0)) (this.words[this.length] = carry), this.length++;
- else if (a !== this) for (; i < a.length; i++) this.words[i] = a.words[i];
- return this;
- }),
- (BN.prototype.add = function (num) {
- var res;
- return num.negative !== 0 && this.negative === 0
- ? ((num.negative = 0), (res = this.sub(num)), (num.negative ^= 1), res)
- : num.negative === 0 && this.negative !== 0
- ? ((this.negative = 0), (res = num.sub(this)), (this.negative = 1), res)
- : this.length > num.length
- ? this.clone().iadd(num)
- : num.clone().iadd(this);
- }),
- (BN.prototype.isub = function (num) {
- if (num.negative !== 0) {
- num.negative = 0;
- var r = this.iadd(num);
- return (num.negative = 1), r._normSign();
- } else if (this.negative !== 0)
- return (this.negative = 0), this.iadd(num), (this.negative = 1), this._normSign();
- var cmp = this.cmp(num);
- if (cmp === 0) return (this.negative = 0), (this.length = 1), (this.words[0] = 0), this;
- var a, b;
- cmp > 0 ? ((a = this), (b = num)) : ((a = num), (b = this));
- for (var carry = 0, i = 0; i < b.length; i++)
- (r = (a.words[i] | 0) - (b.words[i] | 0) + carry), (carry = r >> 26), (this.words[i] = r & 67108863);
- for (; carry !== 0 && i < a.length; i++)
- (r = (a.words[i] | 0) + carry), (carry = r >> 26), (this.words[i] = r & 67108863);
- if (carry === 0 && i < a.length && a !== this) for (; i < a.length; i++) this.words[i] = a.words[i];
- return (this.length = Math.max(this.length, i)), a !== this && (this.negative = 1), this.strip();
- }),
- (BN.prototype.sub = function (num) {
- return this.clone().isub(num);
- });
- function smallMulTo(self2, num, out) {
- out.negative = num.negative ^ self2.negative;
- var len = (self2.length + num.length) | 0;
- (out.length = len), (len = (len - 1) | 0);
- var a = self2.words[0] | 0,
- b = num.words[0] | 0,
- r = a * b,
- lo = r & 67108863,
- carry = (r / 67108864) | 0;
- out.words[0] = lo;
- for (var k = 1; k < len; k++) {
- for (
- var ncarry = carry >>> 26,
- rword = carry & 67108863,
- maxJ = Math.min(k, num.length - 1),
- j = Math.max(0, k - self2.length + 1);
- j <= maxJ;
- j++
- ) {
- var i = (k - j) | 0;
- (a = self2.words[i] | 0),
- (b = num.words[j] | 0),
- (r = a * b + rword),
- (ncarry += (r / 67108864) | 0),
- (rword = r & 67108863);
- }
- (out.words[k] = rword | 0), (carry = ncarry | 0);
- }
- return carry !== 0 ? (out.words[k] = carry | 0) : out.length--, out.strip();
- }
- var comb10MulTo = function (self2, num, out) {
- var a = self2.words,
- b = num.words,
- o = out.words,
- c = 0,
- lo,
- mid,
- hi,
- a0 = a[0] | 0,
- al0 = a0 & 8191,
- ah0 = a0 >>> 13,
- a1 = a[1] | 0,
- al1 = a1 & 8191,
- ah1 = a1 >>> 13,
- a2 = a[2] | 0,
- al2 = a2 & 8191,
- ah2 = a2 >>> 13,
- a3 = a[3] | 0,
- al3 = a3 & 8191,
- ah3 = a3 >>> 13,
- a4 = a[4] | 0,
- al4 = a4 & 8191,
- ah4 = a4 >>> 13,
- a5 = a[5] | 0,
- al5 = a5 & 8191,
- ah5 = a5 >>> 13,
- a6 = a[6] | 0,
- al6 = a6 & 8191,
- ah6 = a6 >>> 13,
- a7 = a[7] | 0,
- al7 = a7 & 8191,
- ah7 = a7 >>> 13,
- a8 = a[8] | 0,
- al8 = a8 & 8191,
- ah8 = a8 >>> 13,
- a9 = a[9] | 0,
- al9 = a9 & 8191,
- ah9 = a9 >>> 13,
- b0 = b[0] | 0,
- bl0 = b0 & 8191,
- bh0 = b0 >>> 13,
- b1 = b[1] | 0,
- bl1 = b1 & 8191,
- bh1 = b1 >>> 13,
- b2 = b[2] | 0,
- bl2 = b2 & 8191,
- bh2 = b2 >>> 13,
- b3 = b[3] | 0,
- bl3 = b3 & 8191,
- bh3 = b3 >>> 13,
- b4 = b[4] | 0,
- bl4 = b4 & 8191,
- bh4 = b4 >>> 13,
- b5 = b[5] | 0,
- bl5 = b5 & 8191,
- bh5 = b5 >>> 13,
- b6 = b[6] | 0,
- bl6 = b6 & 8191,
- bh6 = b6 >>> 13,
- b7 = b[7] | 0,
- bl7 = b7 & 8191,
- bh7 = b7 >>> 13,
- b8 = b[8] | 0,
- bl8 = b8 & 8191,
- bh8 = b8 >>> 13,
- b9 = b[9] | 0,
- bl9 = b9 & 8191,
- bh9 = b9 >>> 13;
- (out.negative = self2.negative ^ num.negative),
- (out.length = 19),
- (lo = Math.imul(al0, bl0)),
- (mid = Math.imul(al0, bh0)),
- (mid = (mid + Math.imul(ah0, bl0)) | 0),
- (hi = Math.imul(ah0, bh0));
- var w0 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0),
- (w0 &= 67108863),
- (lo = Math.imul(al1, bl0)),
- (mid = Math.imul(al1, bh0)),
- (mid = (mid + Math.imul(ah1, bl0)) | 0),
- (hi = Math.imul(ah1, bh0)),
- (lo = (lo + Math.imul(al0, bl1)) | 0),
- (mid = (mid + Math.imul(al0, bh1)) | 0),
- (mid = (mid + Math.imul(ah0, bl1)) | 0),
- (hi = (hi + Math.imul(ah0, bh1)) | 0);
- var w1 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0),
- (w1 &= 67108863),
- (lo = Math.imul(al2, bl0)),
- (mid = Math.imul(al2, bh0)),
- (mid = (mid + Math.imul(ah2, bl0)) | 0),
- (hi = Math.imul(ah2, bh0)),
- (lo = (lo + Math.imul(al1, bl1)) | 0),
- (mid = (mid + Math.imul(al1, bh1)) | 0),
- (mid = (mid + Math.imul(ah1, bl1)) | 0),
- (hi = (hi + Math.imul(ah1, bh1)) | 0),
- (lo = (lo + Math.imul(al0, bl2)) | 0),
- (mid = (mid + Math.imul(al0, bh2)) | 0),
- (mid = (mid + Math.imul(ah0, bl2)) | 0),
- (hi = (hi + Math.imul(ah0, bh2)) | 0);
- var w2 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0),
- (w2 &= 67108863),
- (lo = Math.imul(al3, bl0)),
- (mid = Math.imul(al3, bh0)),
- (mid = (mid + Math.imul(ah3, bl0)) | 0),
- (hi = Math.imul(ah3, bh0)),
- (lo = (lo + Math.imul(al2, bl1)) | 0),
- (mid = (mid + Math.imul(al2, bh1)) | 0),
- (mid = (mid + Math.imul(ah2, bl1)) | 0),
- (hi = (hi + Math.imul(ah2, bh1)) | 0),
- (lo = (lo + Math.imul(al1, bl2)) | 0),
- (mid = (mid + Math.imul(al1, bh2)) | 0),
- (mid = (mid + Math.imul(ah1, bl2)) | 0),
- (hi = (hi + Math.imul(ah1, bh2)) | 0),
- (lo = (lo + Math.imul(al0, bl3)) | 0),
- (mid = (mid + Math.imul(al0, bh3)) | 0),
- (mid = (mid + Math.imul(ah0, bl3)) | 0),
- (hi = (hi + Math.imul(ah0, bh3)) | 0);
- var w3 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0),
- (w3 &= 67108863),
- (lo = Math.imul(al4, bl0)),
- (mid = Math.imul(al4, bh0)),
- (mid = (mid + Math.imul(ah4, bl0)) | 0),
- (hi = Math.imul(ah4, bh0)),
- (lo = (lo + Math.imul(al3, bl1)) | 0),
- (mid = (mid + Math.imul(al3, bh1)) | 0),
- (mid = (mid + Math.imul(ah3, bl1)) | 0),
- (hi = (hi + Math.imul(ah3, bh1)) | 0),
- (lo = (lo + Math.imul(al2, bl2)) | 0),
- (mid = (mid + Math.imul(al2, bh2)) | 0),
- (mid = (mid + Math.imul(ah2, bl2)) | 0),
- (hi = (hi + Math.imul(ah2, bh2)) | 0),
- (lo = (lo + Math.imul(al1, bl3)) | 0),
- (mid = (mid + Math.imul(al1, bh3)) | 0),
- (mid = (mid + Math.imul(ah1, bl3)) | 0),
- (hi = (hi + Math.imul(ah1, bh3)) | 0),
- (lo = (lo + Math.imul(al0, bl4)) | 0),
- (mid = (mid + Math.imul(al0, bh4)) | 0),
- (mid = (mid + Math.imul(ah0, bl4)) | 0),
- (hi = (hi + Math.imul(ah0, bh4)) | 0);
- var w4 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0),
- (w4 &= 67108863),
- (lo = Math.imul(al5, bl0)),
- (mid = Math.imul(al5, bh0)),
- (mid = (mid + Math.imul(ah5, bl0)) | 0),
- (hi = Math.imul(ah5, bh0)),
- (lo = (lo + Math.imul(al4, bl1)) | 0),
- (mid = (mid + Math.imul(al4, bh1)) | 0),
- (mid = (mid + Math.imul(ah4, bl1)) | 0),
- (hi = (hi + Math.imul(ah4, bh1)) | 0),
- (lo = (lo + Math.imul(al3, bl2)) | 0),
- (mid = (mid + Math.imul(al3, bh2)) | 0),
- (mid = (mid + Math.imul(ah3, bl2)) | 0),
- (hi = (hi + Math.imul(ah3, bh2)) | 0),
- (lo = (lo + Math.imul(al2, bl3)) | 0),
- (mid = (mid + Math.imul(al2, bh3)) | 0),
- (mid = (mid + Math.imul(ah2, bl3)) | 0),
- (hi = (hi + Math.imul(ah2, bh3)) | 0),
- (lo = (lo + Math.imul(al1, bl4)) | 0),
- (mid = (mid + Math.imul(al1, bh4)) | 0),
- (mid = (mid + Math.imul(ah1, bl4)) | 0),
- (hi = (hi + Math.imul(ah1, bh4)) | 0),
- (lo = (lo + Math.imul(al0, bl5)) | 0),
- (mid = (mid + Math.imul(al0, bh5)) | 0),
- (mid = (mid + Math.imul(ah0, bl5)) | 0),
- (hi = (hi + Math.imul(ah0, bh5)) | 0);
- var w5 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0),
- (w5 &= 67108863),
- (lo = Math.imul(al6, bl0)),
- (mid = Math.imul(al6, bh0)),
- (mid = (mid + Math.imul(ah6, bl0)) | 0),
- (hi = Math.imul(ah6, bh0)),
- (lo = (lo + Math.imul(al5, bl1)) | 0),
- (mid = (mid + Math.imul(al5, bh1)) | 0),
- (mid = (mid + Math.imul(ah5, bl1)) | 0),
- (hi = (hi + Math.imul(ah5, bh1)) | 0),
- (lo = (lo + Math.imul(al4, bl2)) | 0),
- (mid = (mid + Math.imul(al4, bh2)) | 0),
- (mid = (mid + Math.imul(ah4, bl2)) | 0),
- (hi = (hi + Math.imul(ah4, bh2)) | 0),
- (lo = (lo + Math.imul(al3, bl3)) | 0),
- (mid = (mid + Math.imul(al3, bh3)) | 0),
- (mid = (mid + Math.imul(ah3, bl3)) | 0),
- (hi = (hi + Math.imul(ah3, bh3)) | 0),
- (lo = (lo + Math.imul(al2, bl4)) | 0),
- (mid = (mid + Math.imul(al2, bh4)) | 0),
- (mid = (mid + Math.imul(ah2, bl4)) | 0),
- (hi = (hi + Math.imul(ah2, bh4)) | 0),
- (lo = (lo + Math.imul(al1, bl5)) | 0),
- (mid = (mid + Math.imul(al1, bh5)) | 0),
- (mid = (mid + Math.imul(ah1, bl5)) | 0),
- (hi = (hi + Math.imul(ah1, bh5)) | 0),
- (lo = (lo + Math.imul(al0, bl6)) | 0),
- (mid = (mid + Math.imul(al0, bh6)) | 0),
- (mid = (mid + Math.imul(ah0, bl6)) | 0),
- (hi = (hi + Math.imul(ah0, bh6)) | 0);
- var w6 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0),
- (w6 &= 67108863),
- (lo = Math.imul(al7, bl0)),
- (mid = Math.imul(al7, bh0)),
- (mid = (mid + Math.imul(ah7, bl0)) | 0),
- (hi = Math.imul(ah7, bh0)),
- (lo = (lo + Math.imul(al6, bl1)) | 0),
- (mid = (mid + Math.imul(al6, bh1)) | 0),
- (mid = (mid + Math.imul(ah6, bl1)) | 0),
- (hi = (hi + Math.imul(ah6, bh1)) | 0),
- (lo = (lo + Math.imul(al5, bl2)) | 0),
- (mid = (mid + Math.imul(al5, bh2)) | 0),
- (mid = (mid + Math.imul(ah5, bl2)) | 0),
- (hi = (hi + Math.imul(ah5, bh2)) | 0),
- (lo = (lo + Math.imul(al4, bl3)) | 0),
- (mid = (mid + Math.imul(al4, bh3)) | 0),
- (mid = (mid + Math.imul(ah4, bl3)) | 0),
- (hi = (hi + Math.imul(ah4, bh3)) | 0),
- (lo = (lo + Math.imul(al3, bl4)) | 0),
- (mid = (mid + Math.imul(al3, bh4)) | 0),
- (mid = (mid + Math.imul(ah3, bl4)) | 0),
- (hi = (hi + Math.imul(ah3, bh4)) | 0),
- (lo = (lo + Math.imul(al2, bl5)) | 0),
- (mid = (mid + Math.imul(al2, bh5)) | 0),
- (mid = (mid + Math.imul(ah2, bl5)) | 0),
- (hi = (hi + Math.imul(ah2, bh5)) | 0),
- (lo = (lo + Math.imul(al1, bl6)) | 0),
- (mid = (mid + Math.imul(al1, bh6)) | 0),
- (mid = (mid + Math.imul(ah1, bl6)) | 0),
- (hi = (hi + Math.imul(ah1, bh6)) | 0),
- (lo = (lo + Math.imul(al0, bl7)) | 0),
- (mid = (mid + Math.imul(al0, bh7)) | 0),
- (mid = (mid + Math.imul(ah0, bl7)) | 0),
- (hi = (hi + Math.imul(ah0, bh7)) | 0);
- var w7 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0),
- (w7 &= 67108863),
- (lo = Math.imul(al8, bl0)),
- (mid = Math.imul(al8, bh0)),
- (mid = (mid + Math.imul(ah8, bl0)) | 0),
- (hi = Math.imul(ah8, bh0)),
- (lo = (lo + Math.imul(al7, bl1)) | 0),
- (mid = (mid + Math.imul(al7, bh1)) | 0),
- (mid = (mid + Math.imul(ah7, bl1)) | 0),
- (hi = (hi + Math.imul(ah7, bh1)) | 0),
- (lo = (lo + Math.imul(al6, bl2)) | 0),
- (mid = (mid + Math.imul(al6, bh2)) | 0),
- (mid = (mid + Math.imul(ah6, bl2)) | 0),
- (hi = (hi + Math.imul(ah6, bh2)) | 0),
- (lo = (lo + Math.imul(al5, bl3)) | 0),
- (mid = (mid + Math.imul(al5, bh3)) | 0),
- (mid = (mid + Math.imul(ah5, bl3)) | 0),
- (hi = (hi + Math.imul(ah5, bh3)) | 0),
- (lo = (lo + Math.imul(al4, bl4)) | 0),
- (mid = (mid + Math.imul(al4, bh4)) | 0),
- (mid = (mid + Math.imul(ah4, bl4)) | 0),
- (hi = (hi + Math.imul(ah4, bh4)) | 0),
- (lo = (lo + Math.imul(al3, bl5)) | 0),
- (mid = (mid + Math.imul(al3, bh5)) | 0),
- (mid = (mid + Math.imul(ah3, bl5)) | 0),
- (hi = (hi + Math.imul(ah3, bh5)) | 0),
- (lo = (lo + Math.imul(al2, bl6)) | 0),
- (mid = (mid + Math.imul(al2, bh6)) | 0),
- (mid = (mid + Math.imul(ah2, bl6)) | 0),
- (hi = (hi + Math.imul(ah2, bh6)) | 0),
- (lo = (lo + Math.imul(al1, bl7)) | 0),
- (mid = (mid + Math.imul(al1, bh7)) | 0),
- (mid = (mid + Math.imul(ah1, bl7)) | 0),
- (hi = (hi + Math.imul(ah1, bh7)) | 0),
- (lo = (lo + Math.imul(al0, bl8)) | 0),
- (mid = (mid + Math.imul(al0, bh8)) | 0),
- (mid = (mid + Math.imul(ah0, bl8)) | 0),
- (hi = (hi + Math.imul(ah0, bh8)) | 0);
- var w8 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0),
- (w8 &= 67108863),
- (lo = Math.imul(al9, bl0)),
- (mid = Math.imul(al9, bh0)),
- (mid = (mid + Math.imul(ah9, bl0)) | 0),
- (hi = Math.imul(ah9, bh0)),
- (lo = (lo + Math.imul(al8, bl1)) | 0),
- (mid = (mid + Math.imul(al8, bh1)) | 0),
- (mid = (mid + Math.imul(ah8, bl1)) | 0),
- (hi = (hi + Math.imul(ah8, bh1)) | 0),
- (lo = (lo + Math.imul(al7, bl2)) | 0),
- (mid = (mid + Math.imul(al7, bh2)) | 0),
- (mid = (mid + Math.imul(ah7, bl2)) | 0),
- (hi = (hi + Math.imul(ah7, bh2)) | 0),
- (lo = (lo + Math.imul(al6, bl3)) | 0),
- (mid = (mid + Math.imul(al6, bh3)) | 0),
- (mid = (mid + Math.imul(ah6, bl3)) | 0),
- (hi = (hi + Math.imul(ah6, bh3)) | 0),
- (lo = (lo + Math.imul(al5, bl4)) | 0),
- (mid = (mid + Math.imul(al5, bh4)) | 0),
- (mid = (mid + Math.imul(ah5, bl4)) | 0),
- (hi = (hi + Math.imul(ah5, bh4)) | 0),
- (lo = (lo + Math.imul(al4, bl5)) | 0),
- (mid = (mid + Math.imul(al4, bh5)) | 0),
- (mid = (mid + Math.imul(ah4, bl5)) | 0),
- (hi = (hi + Math.imul(ah4, bh5)) | 0),
- (lo = (lo + Math.imul(al3, bl6)) | 0),
- (mid = (mid + Math.imul(al3, bh6)) | 0),
- (mid = (mid + Math.imul(ah3, bl6)) | 0),
- (hi = (hi + Math.imul(ah3, bh6)) | 0),
- (lo = (lo + Math.imul(al2, bl7)) | 0),
- (mid = (mid + Math.imul(al2, bh7)) | 0),
- (mid = (mid + Math.imul(ah2, bl7)) | 0),
- (hi = (hi + Math.imul(ah2, bh7)) | 0),
- (lo = (lo + Math.imul(al1, bl8)) | 0),
- (mid = (mid + Math.imul(al1, bh8)) | 0),
- (mid = (mid + Math.imul(ah1, bl8)) | 0),
- (hi = (hi + Math.imul(ah1, bh8)) | 0),
- (lo = (lo + Math.imul(al0, bl9)) | 0),
- (mid = (mid + Math.imul(al0, bh9)) | 0),
- (mid = (mid + Math.imul(ah0, bl9)) | 0),
- (hi = (hi + Math.imul(ah0, bh9)) | 0);
- var w9 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0),
- (w9 &= 67108863),
- (lo = Math.imul(al9, bl1)),
- (mid = Math.imul(al9, bh1)),
- (mid = (mid + Math.imul(ah9, bl1)) | 0),
- (hi = Math.imul(ah9, bh1)),
- (lo = (lo + Math.imul(al8, bl2)) | 0),
- (mid = (mid + Math.imul(al8, bh2)) | 0),
- (mid = (mid + Math.imul(ah8, bl2)) | 0),
- (hi = (hi + Math.imul(ah8, bh2)) | 0),
- (lo = (lo + Math.imul(al7, bl3)) | 0),
- (mid = (mid + Math.imul(al7, bh3)) | 0),
- (mid = (mid + Math.imul(ah7, bl3)) | 0),
- (hi = (hi + Math.imul(ah7, bh3)) | 0),
- (lo = (lo + Math.imul(al6, bl4)) | 0),
- (mid = (mid + Math.imul(al6, bh4)) | 0),
- (mid = (mid + Math.imul(ah6, bl4)) | 0),
- (hi = (hi + Math.imul(ah6, bh4)) | 0),
- (lo = (lo + Math.imul(al5, bl5)) | 0),
- (mid = (mid + Math.imul(al5, bh5)) | 0),
- (mid = (mid + Math.imul(ah5, bl5)) | 0),
- (hi = (hi + Math.imul(ah5, bh5)) | 0),
- (lo = (lo + Math.imul(al4, bl6)) | 0),
- (mid = (mid + Math.imul(al4, bh6)) | 0),
- (mid = (mid + Math.imul(ah4, bl6)) | 0),
- (hi = (hi + Math.imul(ah4, bh6)) | 0),
- (lo = (lo + Math.imul(al3, bl7)) | 0),
- (mid = (mid + Math.imul(al3, bh7)) | 0),
- (mid = (mid + Math.imul(ah3, bl7)) | 0),
- (hi = (hi + Math.imul(ah3, bh7)) | 0),
- (lo = (lo + Math.imul(al2, bl8)) | 0),
- (mid = (mid + Math.imul(al2, bh8)) | 0),
- (mid = (mid + Math.imul(ah2, bl8)) | 0),
- (hi = (hi + Math.imul(ah2, bh8)) | 0),
- (lo = (lo + Math.imul(al1, bl9)) | 0),
- (mid = (mid + Math.imul(al1, bh9)) | 0),
- (mid = (mid + Math.imul(ah1, bl9)) | 0),
- (hi = (hi + Math.imul(ah1, bh9)) | 0);
- var w10 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0),
- (w10 &= 67108863),
- (lo = Math.imul(al9, bl2)),
- (mid = Math.imul(al9, bh2)),
- (mid = (mid + Math.imul(ah9, bl2)) | 0),
- (hi = Math.imul(ah9, bh2)),
- (lo = (lo + Math.imul(al8, bl3)) | 0),
- (mid = (mid + Math.imul(al8, bh3)) | 0),
- (mid = (mid + Math.imul(ah8, bl3)) | 0),
- (hi = (hi + Math.imul(ah8, bh3)) | 0),
- (lo = (lo + Math.imul(al7, bl4)) | 0),
- (mid = (mid + Math.imul(al7, bh4)) | 0),
- (mid = (mid + Math.imul(ah7, bl4)) | 0),
- (hi = (hi + Math.imul(ah7, bh4)) | 0),
- (lo = (lo + Math.imul(al6, bl5)) | 0),
- (mid = (mid + Math.imul(al6, bh5)) | 0),
- (mid = (mid + Math.imul(ah6, bl5)) | 0),
- (hi = (hi + Math.imul(ah6, bh5)) | 0),
- (lo = (lo + Math.imul(al5, bl6)) | 0),
- (mid = (mid + Math.imul(al5, bh6)) | 0),
- (mid = (mid + Math.imul(ah5, bl6)) | 0),
- (hi = (hi + Math.imul(ah5, bh6)) | 0),
- (lo = (lo + Math.imul(al4, bl7)) | 0),
- (mid = (mid + Math.imul(al4, bh7)) | 0),
- (mid = (mid + Math.imul(ah4, bl7)) | 0),
- (hi = (hi + Math.imul(ah4, bh7)) | 0),
- (lo = (lo + Math.imul(al3, bl8)) | 0),
- (mid = (mid + Math.imul(al3, bh8)) | 0),
- (mid = (mid + Math.imul(ah3, bl8)) | 0),
- (hi = (hi + Math.imul(ah3, bh8)) | 0),
- (lo = (lo + Math.imul(al2, bl9)) | 0),
- (mid = (mid + Math.imul(al2, bh9)) | 0),
- (mid = (mid + Math.imul(ah2, bl9)) | 0),
- (hi = (hi + Math.imul(ah2, bh9)) | 0);
- var w11 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0),
- (w11 &= 67108863),
- (lo = Math.imul(al9, bl3)),
- (mid = Math.imul(al9, bh3)),
- (mid = (mid + Math.imul(ah9, bl3)) | 0),
- (hi = Math.imul(ah9, bh3)),
- (lo = (lo + Math.imul(al8, bl4)) | 0),
- (mid = (mid + Math.imul(al8, bh4)) | 0),
- (mid = (mid + Math.imul(ah8, bl4)) | 0),
- (hi = (hi + Math.imul(ah8, bh4)) | 0),
- (lo = (lo + Math.imul(al7, bl5)) | 0),
- (mid = (mid + Math.imul(al7, bh5)) | 0),
- (mid = (mid + Math.imul(ah7, bl5)) | 0),
- (hi = (hi + Math.imul(ah7, bh5)) | 0),
- (lo = (lo + Math.imul(al6, bl6)) | 0),
- (mid = (mid + Math.imul(al6, bh6)) | 0),
- (mid = (mid + Math.imul(ah6, bl6)) | 0),
- (hi = (hi + Math.imul(ah6, bh6)) | 0),
- (lo = (lo + Math.imul(al5, bl7)) | 0),
- (mid = (mid + Math.imul(al5, bh7)) | 0),
- (mid = (mid + Math.imul(ah5, bl7)) | 0),
- (hi = (hi + Math.imul(ah5, bh7)) | 0),
- (lo = (lo + Math.imul(al4, bl8)) | 0),
- (mid = (mid + Math.imul(al4, bh8)) | 0),
- (mid = (mid + Math.imul(ah4, bl8)) | 0),
- (hi = (hi + Math.imul(ah4, bh8)) | 0),
- (lo = (lo + Math.imul(al3, bl9)) | 0),
- (mid = (mid + Math.imul(al3, bh9)) | 0),
- (mid = (mid + Math.imul(ah3, bl9)) | 0),
- (hi = (hi + Math.imul(ah3, bh9)) | 0);
- var w12 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0),
- (w12 &= 67108863),
- (lo = Math.imul(al9, bl4)),
- (mid = Math.imul(al9, bh4)),
- (mid = (mid + Math.imul(ah9, bl4)) | 0),
- (hi = Math.imul(ah9, bh4)),
- (lo = (lo + Math.imul(al8, bl5)) | 0),
- (mid = (mid + Math.imul(al8, bh5)) | 0),
- (mid = (mid + Math.imul(ah8, bl5)) | 0),
- (hi = (hi + Math.imul(ah8, bh5)) | 0),
- (lo = (lo + Math.imul(al7, bl6)) | 0),
- (mid = (mid + Math.imul(al7, bh6)) | 0),
- (mid = (mid + Math.imul(ah7, bl6)) | 0),
- (hi = (hi + Math.imul(ah7, bh6)) | 0),
- (lo = (lo + Math.imul(al6, bl7)) | 0),
- (mid = (mid + Math.imul(al6, bh7)) | 0),
- (mid = (mid + Math.imul(ah6, bl7)) | 0),
- (hi = (hi + Math.imul(ah6, bh7)) | 0),
- (lo = (lo + Math.imul(al5, bl8)) | 0),
- (mid = (mid + Math.imul(al5, bh8)) | 0),
- (mid = (mid + Math.imul(ah5, bl8)) | 0),
- (hi = (hi + Math.imul(ah5, bh8)) | 0),
- (lo = (lo + Math.imul(al4, bl9)) | 0),
- (mid = (mid + Math.imul(al4, bh9)) | 0),
- (mid = (mid + Math.imul(ah4, bl9)) | 0),
- (hi = (hi + Math.imul(ah4, bh9)) | 0);
- var w13 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0),
- (w13 &= 67108863),
- (lo = Math.imul(al9, bl5)),
- (mid = Math.imul(al9, bh5)),
- (mid = (mid + Math.imul(ah9, bl5)) | 0),
- (hi = Math.imul(ah9, bh5)),
- (lo = (lo + Math.imul(al8, bl6)) | 0),
- (mid = (mid + Math.imul(al8, bh6)) | 0),
- (mid = (mid + Math.imul(ah8, bl6)) | 0),
- (hi = (hi + Math.imul(ah8, bh6)) | 0),
- (lo = (lo + Math.imul(al7, bl7)) | 0),
- (mid = (mid + Math.imul(al7, bh7)) | 0),
- (mid = (mid + Math.imul(ah7, bl7)) | 0),
- (hi = (hi + Math.imul(ah7, bh7)) | 0),
- (lo = (lo + Math.imul(al6, bl8)) | 0),
- (mid = (mid + Math.imul(al6, bh8)) | 0),
- (mid = (mid + Math.imul(ah6, bl8)) | 0),
- (hi = (hi + Math.imul(ah6, bh8)) | 0),
- (lo = (lo + Math.imul(al5, bl9)) | 0),
- (mid = (mid + Math.imul(al5, bh9)) | 0),
- (mid = (mid + Math.imul(ah5, bl9)) | 0),
- (hi = (hi + Math.imul(ah5, bh9)) | 0);
- var w14 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0),
- (w14 &= 67108863),
- (lo = Math.imul(al9, bl6)),
- (mid = Math.imul(al9, bh6)),
- (mid = (mid + Math.imul(ah9, bl6)) | 0),
- (hi = Math.imul(ah9, bh6)),
- (lo = (lo + Math.imul(al8, bl7)) | 0),
- (mid = (mid + Math.imul(al8, bh7)) | 0),
- (mid = (mid + Math.imul(ah8, bl7)) | 0),
- (hi = (hi + Math.imul(ah8, bh7)) | 0),
- (lo = (lo + Math.imul(al7, bl8)) | 0),
- (mid = (mid + Math.imul(al7, bh8)) | 0),
- (mid = (mid + Math.imul(ah7, bl8)) | 0),
- (hi = (hi + Math.imul(ah7, bh8)) | 0),
- (lo = (lo + Math.imul(al6, bl9)) | 0),
- (mid = (mid + Math.imul(al6, bh9)) | 0),
- (mid = (mid + Math.imul(ah6, bl9)) | 0),
- (hi = (hi + Math.imul(ah6, bh9)) | 0);
- var w15 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0),
- (w15 &= 67108863),
- (lo = Math.imul(al9, bl7)),
- (mid = Math.imul(al9, bh7)),
- (mid = (mid + Math.imul(ah9, bl7)) | 0),
- (hi = Math.imul(ah9, bh7)),
- (lo = (lo + Math.imul(al8, bl8)) | 0),
- (mid = (mid + Math.imul(al8, bh8)) | 0),
- (mid = (mid + Math.imul(ah8, bl8)) | 0),
- (hi = (hi + Math.imul(ah8, bh8)) | 0),
- (lo = (lo + Math.imul(al7, bl9)) | 0),
- (mid = (mid + Math.imul(al7, bh9)) | 0),
- (mid = (mid + Math.imul(ah7, bl9)) | 0),
- (hi = (hi + Math.imul(ah7, bh9)) | 0);
- var w16 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0),
- (w16 &= 67108863),
- (lo = Math.imul(al9, bl8)),
- (mid = Math.imul(al9, bh8)),
- (mid = (mid + Math.imul(ah9, bl8)) | 0),
- (hi = Math.imul(ah9, bh8)),
- (lo = (lo + Math.imul(al8, bl9)) | 0),
- (mid = (mid + Math.imul(al8, bh9)) | 0),
- (mid = (mid + Math.imul(ah8, bl9)) | 0),
- (hi = (hi + Math.imul(ah8, bh9)) | 0);
- var w17 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0),
- (w17 &= 67108863),
- (lo = Math.imul(al9, bl9)),
- (mid = Math.imul(al9, bh9)),
- (mid = (mid + Math.imul(ah9, bl9)) | 0),
- (hi = Math.imul(ah9, bh9));
- var w18 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- return (
- (c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0),
- (w18 &= 67108863),
- (o[0] = w0),
- (o[1] = w1),
- (o[2] = w2),
- (o[3] = w3),
- (o[4] = w4),
- (o[5] = w5),
- (o[6] = w6),
- (o[7] = w7),
- (o[8] = w8),
- (o[9] = w9),
- (o[10] = w10),
- (o[11] = w11),
- (o[12] = w12),
- (o[13] = w13),
- (o[14] = w14),
- (o[15] = w15),
- (o[16] = w16),
- (o[17] = w17),
- (o[18] = w18),
- c !== 0 && ((o[19] = c), out.length++),
- out
- );
- };
- Math.imul || (comb10MulTo = smallMulTo);
- function bigMulTo(self2, num, out) {
- (out.negative = num.negative ^ self2.negative), (out.length = self2.length + num.length);
- for (var carry = 0, hncarry = 0, k = 0; k < out.length - 1; k++) {
- var ncarry = hncarry;
- hncarry = 0;
- for (
- var rword = carry & 67108863, maxJ = Math.min(k, num.length - 1), j = Math.max(0, k - self2.length + 1);
- j <= maxJ;
- j++
- ) {
- var i = k - j,
- a = self2.words[i] | 0,
- b = num.words[j] | 0,
- r = a * b,
- lo = r & 67108863;
- (ncarry = (ncarry + ((r / 67108864) | 0)) | 0),
- (lo = (lo + rword) | 0),
- (rword = lo & 67108863),
- (ncarry = (ncarry + (lo >>> 26)) | 0),
- (hncarry += ncarry >>> 26),
- (ncarry &= 67108863);
- }
- (out.words[k] = rword), (carry = ncarry), (ncarry = hncarry);
- }
- return carry !== 0 ? (out.words[k] = carry) : out.length--, out.strip();
- }
- function jumboMulTo(self2, num, out) {
- var fftm = new FFTM();
- return fftm.mulp(self2, num, out);
- }
- BN.prototype.mulTo = function (num, out) {
- var res,
- len = this.length + num.length;
- return (
- this.length === 10 && num.length === 10
- ? (res = comb10MulTo(this, num, out))
- : len < 63
- ? (res = smallMulTo(this, num, out))
- : len < 1024
- ? (res = bigMulTo(this, num, out))
- : (res = jumboMulTo(this, num, out)),
- res
- );
- };
- function FFTM(x, y) {
- (this.x = x), (this.y = y);
- }
- (FFTM.prototype.makeRBT = function (N) {
- for (var t = new Array(N), l = BN.prototype._countBits(N) - 1, i = 0; i < N; i++) t[i] = this.revBin(i, l, N);
- return t;
- }),
- (FFTM.prototype.revBin = function (x, l, N) {
- if (x === 0 || x === N - 1) return x;
- for (var rb = 0, i = 0; i < l; i++) (rb |= (x & 1) << (l - i - 1)), (x >>= 1);
- return rb;
- }),
- (FFTM.prototype.permute = function (rbt, rws, iws, rtws, itws, N) {
- for (var i = 0; i < N; i++) (rtws[i] = rws[rbt[i]]), (itws[i] = iws[rbt[i]]);
- }),
- (FFTM.prototype.transform = function (rws, iws, rtws, itws, N, rbt) {
- this.permute(rbt, rws, iws, rtws, itws, N);
- for (var s = 1; s < N; s <<= 1)
- for (
- var l = s << 1, rtwdf = Math.cos((2 * Math.PI) / l), itwdf = Math.sin((2 * Math.PI) / l), p = 0;
- p < N;
- p += l
- )
- for (var rtwdf_ = rtwdf, itwdf_ = itwdf, j = 0; j < s; j++) {
- var re = rtws[p + j],
- ie = itws[p + j],
- ro = rtws[p + j + s],
- io = itws[p + j + s],
- rx = rtwdf_ * ro - itwdf_ * io;
- (io = rtwdf_ * io + itwdf_ * ro),
- (ro = rx),
- (rtws[p + j] = re + ro),
- (itws[p + j] = ie + io),
- (rtws[p + j + s] = re - ro),
- (itws[p + j + s] = ie - io),
- j !== l &&
- ((rx = rtwdf * rtwdf_ - itwdf * itwdf_), (itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_), (rtwdf_ = rx));
- }
- }),
- (FFTM.prototype.guessLen13b = function (n, m) {
- var N = Math.max(m, n) | 1,
- odd = N & 1,
- i = 0;
- for (N = (N / 2) | 0; N; N = N >>> 1) i++;
- return 1 << (i + 1 + odd);
- }),
- (FFTM.prototype.conjugate = function (rws, iws, N) {
- if (!(N <= 1))
- for (var i = 0; i < N / 2; i++) {
- var t = rws[i];
- (rws[i] = rws[N - i - 1]),
- (rws[N - i - 1] = t),
- (t = iws[i]),
- (iws[i] = -iws[N - i - 1]),
- (iws[N - i - 1] = -t);
- }
- }),
- (FFTM.prototype.normalize13b = function (ws, N) {
- for (var carry = 0, i = 0; i < N / 2; i++) {
- var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry;
- (ws[i] = w & 67108863), w < 67108864 ? (carry = 0) : (carry = (w / 67108864) | 0);
- }
- return ws;
- }),
- (FFTM.prototype.convert13b = function (ws, len, rws, N) {
- for (var carry = 0, i = 0; i < len; i++)
- (carry = carry + (ws[i] | 0)),
- (rws[2 * i] = carry & 8191),
- (carry = carry >>> 13),
- (rws[2 * i + 1] = carry & 8191),
- (carry = carry >>> 13);
- for (i = 2 * len; i < N; ++i) rws[i] = 0;
- assert(carry === 0), assert((carry & -8192) === 0);
- }),
- (FFTM.prototype.stub = function (N) {
- for (var ph = new Array(N), i = 0; i < N; i++) ph[i] = 0;
- return ph;
- }),
- (FFTM.prototype.mulp = function (x, y, out) {
- var N = 2 * this.guessLen13b(x.length, y.length),
- rbt = this.makeRBT(N),
- _ = this.stub(N),
- rws = new Array(N),
- rwst = new Array(N),
- iwst = new Array(N),
- nrws = new Array(N),
- nrwst = new Array(N),
- niwst = new Array(N),
- rmws = out.words;
- (rmws.length = N),
- this.convert13b(x.words, x.length, rws, N),
- this.convert13b(y.words, y.length, nrws, N),
- this.transform(rws, _, rwst, iwst, N, rbt),
- this.transform(nrws, _, nrwst, niwst, N, rbt);
- for (var i = 0; i < N; i++) {
- var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
- (iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]), (rwst[i] = rx);
- }
- return (
- this.conjugate(rwst, iwst, N),
- this.transform(rwst, iwst, rmws, _, N, rbt),
- this.conjugate(rmws, _, N),
- this.normalize13b(rmws, N),
- (out.negative = x.negative ^ y.negative),
- (out.length = x.length + y.length),
- out.strip()
- );
- }),
- (BN.prototype.mul = function (num) {
- var out = new BN(null);
- return (out.words = new Array(this.length + num.length)), this.mulTo(num, out);
- }),
- (BN.prototype.mulf = function (num) {
- var out = new BN(null);
- return (out.words = new Array(this.length + num.length)), jumboMulTo(this, num, out);
- }),
- (BN.prototype.imul = function (num) {
- return this.clone().mulTo(num, this);
- }),
- (BN.prototype.imuln = function (num) {
- assert(typeof num == "number"), assert(num < 67108864);
- for (var carry = 0, i = 0; i < this.length; i++) {
- var w = (this.words[i] | 0) * num,
- lo = (w & 67108863) + (carry & 67108863);
- (carry >>= 26), (carry += (w / 67108864) | 0), (carry += lo >>> 26), (this.words[i] = lo & 67108863);
- }
- return carry !== 0 && ((this.words[i] = carry), this.length++), this;
- }),
- (BN.prototype.muln = function (num) {
- return this.clone().imuln(num);
- }),
- (BN.prototype.sqr = function () {
- return this.mul(this);
- }),
- (BN.prototype.isqr = function () {
- return this.imul(this.clone());
- }),
- (BN.prototype.pow = function (num) {
- var w = toBitArray(num);
- if (w.length === 0) return new BN(1);
- for (var res = this, i = 0; i < w.length && w[i] === 0; i++, res = res.sqr());
- if (++i < w.length) for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) w[i] !== 0 && (res = res.mul(q));
- return res;
- }),
- (BN.prototype.iushln = function (bits) {
- assert(typeof bits == "number" && bits >= 0);
- var r = bits % 26,
- s = (bits - r) / 26,
- carryMask = (67108863 >>> (26 - r)) << (26 - r),
- i;
- if (r !== 0) {
- var carry = 0;
- for (i = 0; i < this.length; i++) {
- var newCarry = this.words[i] & carryMask,
- c = ((this.words[i] | 0) - newCarry) << r;
- (this.words[i] = c | carry), (carry = newCarry >>> (26 - r));
- }
- carry && ((this.words[i] = carry), this.length++);
- }
- if (s !== 0) {
- for (i = this.length - 1; i >= 0; i--) this.words[i + s] = this.words[i];
- for (i = 0; i < s; i++) this.words[i] = 0;
- this.length += s;
- }
- return this.strip();
- }),
- (BN.prototype.ishln = function (bits) {
- return assert(this.negative === 0), this.iushln(bits);
- }),
- (BN.prototype.iushrn = function (bits, hint, extended) {
- assert(typeof bits == "number" && bits >= 0);
- var h;
- hint ? (h = (hint - (hint % 26)) / 26) : (h = 0);
- var r = bits % 26,
- s = Math.min((bits - r) / 26, this.length),
- mask = 67108863 ^ ((67108863 >>> r) << r),
- maskedWords = extended;
- if (((h -= s), (h = Math.max(0, h)), maskedWords)) {
- for (var i = 0; i < s; i++) maskedWords.words[i] = this.words[i];
- maskedWords.length = s;
- }
- if (s !== 0)
- if (this.length > s) for (this.length -= s, i = 0; i < this.length; i++) this.words[i] = this.words[i + s];
- else (this.words[0] = 0), (this.length = 1);
- var carry = 0;
- for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
- var word = this.words[i] | 0;
- (this.words[i] = (carry << (26 - r)) | (word >>> r)), (carry = word & mask);
- }
- return (
- maskedWords && carry !== 0 && (maskedWords.words[maskedWords.length++] = carry),
- this.length === 0 && ((this.words[0] = 0), (this.length = 1)),
- this.strip()
- );
- }),
- (BN.prototype.ishrn = function (bits, hint, extended) {
- return assert(this.negative === 0), this.iushrn(bits, hint, extended);
- }),
- (BN.prototype.shln = function (bits) {
- return this.clone().ishln(bits);
- }),
- (BN.prototype.ushln = function (bits) {
- return this.clone().iushln(bits);
- }),
- (BN.prototype.shrn = function (bits) {
- return this.clone().ishrn(bits);
- }),
- (BN.prototype.ushrn = function (bits) {
- return this.clone().iushrn(bits);
- }),
- (BN.prototype.testn = function (bit) {
- assert(typeof bit == "number" && bit >= 0);
- var r = bit % 26,
- s = (bit - r) / 26,
- q = 1 << r;
- if (this.length <= s) return !1;
- var w = this.words[s];
- return !!(w & q);
- }),
- (BN.prototype.imaskn = function (bits) {
- assert(typeof bits == "number" && bits >= 0);
- var r = bits % 26,
- s = (bits - r) / 26;
- if ((assert(this.negative === 0, "imaskn works only with positive numbers"), this.length <= s)) return this;
- if ((r !== 0 && s++, (this.length = Math.min(s, this.length)), r !== 0)) {
- var mask = 67108863 ^ ((67108863 >>> r) << r);
- this.words[this.length - 1] &= mask;
- }
- return this.strip();
- }),
- (BN.prototype.maskn = function (bits) {
- return this.clone().imaskn(bits);
- }),
- (BN.prototype.iaddn = function (num) {
- return (
- assert(typeof num == "number"),
- assert(num < 67108864),
- num < 0
- ? this.isubn(-num)
- : this.negative !== 0
- ? this.length === 1 && (this.words[0] | 0) < num
- ? ((this.words[0] = num - (this.words[0] | 0)), (this.negative = 0), this)
- : ((this.negative = 0), this.isubn(num), (this.negative = 1), this)
- : this._iaddn(num)
- );
- }),
- (BN.prototype._iaddn = function (num) {
- this.words[0] += num;
- for (var i = 0; i < this.length && this.words[i] >= 67108864; i++)
- (this.words[i] -= 67108864), i === this.length - 1 ? (this.words[i + 1] = 1) : this.words[i + 1]++;
- return (this.length = Math.max(this.length, i + 1)), this;
- }),
- (BN.prototype.isubn = function (num) {
- if ((assert(typeof num == "number"), assert(num < 67108864), num < 0)) return this.iaddn(-num);
- if (this.negative !== 0) return (this.negative = 0), this.iaddn(num), (this.negative = 1), this;
- if (((this.words[0] -= num), this.length === 1 && this.words[0] < 0))
- (this.words[0] = -this.words[0]), (this.negative = 1);
- else
- for (var i = 0; i < this.length && this.words[i] < 0; i++)
- (this.words[i] += 67108864), (this.words[i + 1] -= 1);
- return this.strip();
- }),
- (BN.prototype.addn = function (num) {
- return this.clone().iaddn(num);
- }),
- (BN.prototype.subn = function (num) {
- return this.clone().isubn(num);
- }),
- (BN.prototype.iabs = function () {
- return (this.negative = 0), this;
- }),
- (BN.prototype.abs = function () {
- return this.clone().iabs();
- }),
- (BN.prototype._ishlnsubmul = function (num, mul, shift) {
- var len = num.length + shift,
- i;
- this._expand(len);
- var w,
- carry = 0;
- for (i = 0; i < num.length; i++) {
- w = (this.words[i + shift] | 0) + carry;
- var right = (num.words[i] | 0) * mul;
- (w -= right & 67108863),
- (carry = (w >> 26) - ((right / 67108864) | 0)),
- (this.words[i + shift] = w & 67108863);
- }
- for (; i < this.length - shift; i++)
- (w = (this.words[i + shift] | 0) + carry), (carry = w >> 26), (this.words[i + shift] = w & 67108863);
- if (carry === 0) return this.strip();
- for (assert(carry === -1), carry = 0, i = 0; i < this.length; i++)
- (w = -(this.words[i] | 0) + carry), (carry = w >> 26), (this.words[i] = w & 67108863);
- return (this.negative = 1), this.strip();
- }),
- (BN.prototype._wordDiv = function (num, mode) {
- var shift = this.length - num.length,
- a = this.clone(),
- b = num,
- bhi = b.words[b.length - 1] | 0,
- bhiBits = this._countBits(bhi);
- (shift = 26 - bhiBits),
- shift !== 0 && ((b = b.ushln(shift)), a.iushln(shift), (bhi = b.words[b.length - 1] | 0));
- var m = a.length - b.length,
- q;
- if (mode !== "mod") {
- (q = new BN(null)), (q.length = m + 1), (q.words = new Array(q.length));
- for (var i = 0; i < q.length; i++) q.words[i] = 0;
- }
- var diff = a.clone()._ishlnsubmul(b, 1, m);
- diff.negative === 0 && ((a = diff), q && (q.words[m] = 1));
- for (var j = m - 1; j >= 0; j--) {
- var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0);
- for (qj = Math.min((qj / bhi) | 0, 67108863), a._ishlnsubmul(b, qj, j); a.negative !== 0; )
- qj--, (a.negative = 0), a._ishlnsubmul(b, 1, j), a.isZero() || (a.negative ^= 1);
- q && (q.words[j] = qj);
- }
- return (
- q && q.strip(),
- a.strip(),
- mode !== "div" && shift !== 0 && a.iushrn(shift),
- {
- div: q || null,
- mod: a,
- }
- );
- }),
- (BN.prototype.divmod = function (num, mode, positive) {
- if ((assert(!num.isZero()), this.isZero()))
- return {
- div: new BN(0),
- mod: new BN(0),
- };
- var div, mod, res;
- return this.negative !== 0 && num.negative === 0
- ? ((res = this.neg().divmod(num, mode)),
- mode !== "mod" && (div = res.div.neg()),
- mode !== "div" && ((mod = res.mod.neg()), positive && mod.negative !== 0 && mod.iadd(num)),
- {
- div,
- mod,
- })
- : this.negative === 0 && num.negative !== 0
- ? ((res = this.divmod(num.neg(), mode)),
- mode !== "mod" && (div = res.div.neg()),
- {
- div,
- mod: res.mod,
- })
- : (this.negative & num.negative) !== 0
- ? ((res = this.neg().divmod(num.neg(), mode)),
- mode !== "div" && ((mod = res.mod.neg()), positive && mod.negative !== 0 && mod.isub(num)),
- {
- div: res.div,
- mod,
- })
- : num.length > this.length || this.cmp(num) < 0
- ? {
- div: new BN(0),
- mod: this,
- }
- : num.length === 1
- ? mode === "div"
- ? {
- div: this.divn(num.words[0]),
- mod: null,
- }
- : mode === "mod"
- ? {
- div: null,
- mod: new BN(this.modn(num.words[0])),
- }
- : {
- div: this.divn(num.words[0]),
- mod: new BN(this.modn(num.words[0])),
- }
- : this._wordDiv(num, mode);
- }),
- (BN.prototype.div = function (num) {
- return this.divmod(num, "div", !1).div;
- }),
- (BN.prototype.mod = function (num) {
- return this.divmod(num, "mod", !1).mod;
- }),
- (BN.prototype.umod = function (num) {
- return this.divmod(num, "mod", !0).mod;
- }),
- (BN.prototype.divRound = function (num) {
- var dm = this.divmod(num);
- if (dm.mod.isZero()) return dm.div;
- var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod,
- half = num.ushrn(1),
- r2 = num.andln(1),
- cmp = mod.cmp(half);
- return cmp < 0 || (r2 === 1 && cmp === 0)
- ? dm.div
- : dm.div.negative !== 0
- ? dm.div.isubn(1)
- : dm.div.iaddn(1);
- }),
- (BN.prototype.modn = function (num) {
- assert(num <= 67108863);
- for (var p = (1 << 26) % num, acc = 0, i = this.length - 1; i >= 0; i--)
- acc = (p * acc + (this.words[i] | 0)) % num;
- return acc;
- }),
- (BN.prototype.idivn = function (num) {
- assert(num <= 67108863);
- for (var carry = 0, i = this.length - 1; i >= 0; i--) {
- var w = (this.words[i] | 0) + carry * 67108864;
- (this.words[i] = (w / num) | 0), (carry = w % num);
- }
- return this.strip();
- }),
- (BN.prototype.divn = function (num) {
- return this.clone().idivn(num);
- }),
- (BN.prototype.egcd = function (p) {
- assert(p.negative === 0), assert(!p.isZero());
- var x = this,
- y = p.clone();
- x.negative !== 0 ? (x = x.umod(p)) : (x = x.clone());
- for (var A = new BN(1), B = new BN(0), C = new BN(0), D = new BN(1), g = 0; x.isEven() && y.isEven(); )
- x.iushrn(1), y.iushrn(1), ++g;
- for (var yp = y.clone(), xp = x.clone(); !x.isZero(); ) {
- for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
- if (i > 0)
- for (x.iushrn(i); i-- > 0; )
- (A.isOdd() || B.isOdd()) && (A.iadd(yp), B.isub(xp)), A.iushrn(1), B.iushrn(1);
- for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
- if (j > 0)
- for (y.iushrn(j); j-- > 0; )
- (C.isOdd() || D.isOdd()) && (C.iadd(yp), D.isub(xp)), C.iushrn(1), D.iushrn(1);
- x.cmp(y) >= 0 ? (x.isub(y), A.isub(C), B.isub(D)) : (y.isub(x), C.isub(A), D.isub(B));
- }
- return {
- a: C,
- b: D,
- gcd: y.iushln(g),
- };
- }),
- (BN.prototype._invmp = function (p) {
- assert(p.negative === 0), assert(!p.isZero());
- var a = this,
- b = p.clone();
- a.negative !== 0 ? (a = a.umod(p)) : (a = a.clone());
- for (var x1 = new BN(1), x2 = new BN(0), delta = b.clone(); a.cmpn(1) > 0 && b.cmpn(1) > 0; ) {
- for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
- if (i > 0) for (a.iushrn(i); i-- > 0; ) x1.isOdd() && x1.iadd(delta), x1.iushrn(1);
- for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
- if (j > 0) for (b.iushrn(j); j-- > 0; ) x2.isOdd() && x2.iadd(delta), x2.iushrn(1);
- a.cmp(b) >= 0 ? (a.isub(b), x1.isub(x2)) : (b.isub(a), x2.isub(x1));
- }
- var res;
- return a.cmpn(1) === 0 ? (res = x1) : (res = x2), res.cmpn(0) < 0 && res.iadd(p), res;
- }),
- (BN.prototype.gcd = function (num) {
- if (this.isZero()) return num.abs();
- if (num.isZero()) return this.abs();
- var a = this.clone(),
- b = num.clone();
- (a.negative = 0), (b.negative = 0);
- for (var shift = 0; a.isEven() && b.isEven(); shift++) a.iushrn(1), b.iushrn(1);
- do {
- for (; a.isEven(); ) a.iushrn(1);
- for (; b.isEven(); ) b.iushrn(1);
- var r = a.cmp(b);
- if (r < 0) {
- var t = a;
- (a = b), (b = t);
- } else if (r === 0 || b.cmpn(1) === 0) break;
- a.isub(b);
- } while (!0);
- return b.iushln(shift);
- }),
- (BN.prototype.invm = function (num) {
- return this.egcd(num).a.umod(num);
- }),
- (BN.prototype.isEven = function () {
- return (this.words[0] & 1) === 0;
- }),
- (BN.prototype.isOdd = function () {
- return (this.words[0] & 1) === 1;
- }),
- (BN.prototype.andln = function (num) {
- return this.words[0] & num;
- }),
- (BN.prototype.bincn = function (bit) {
- assert(typeof bit == "number");
- var r = bit % 26,
- s = (bit - r) / 26,
- q = 1 << r;
- if (this.length <= s) return this._expand(s + 1), (this.words[s] |= q), this;
- for (var carry = q, i = s; carry !== 0 && i < this.length; i++) {
- var w = this.words[i] | 0;
- (w += carry), (carry = w >>> 26), (w &= 67108863), (this.words[i] = w);
- }
- return carry !== 0 && ((this.words[i] = carry), this.length++), this;
- }),
- (BN.prototype.isZero = function () {
- return this.length === 1 && this.words[0] === 0;
- }),
- (BN.prototype.cmpn = function (num) {
- var negative = num < 0;
- if (this.negative !== 0 && !negative) return -1;
- if (this.negative === 0 && negative) return 1;
- this.strip();
- var res;
- if (this.length > 1) res = 1;
- else {
- negative && (num = -num), assert(num <= 67108863, "Number is too big");
- var w = this.words[0] | 0;
- res = w === num ? 0 : w < num ? -1 : 1;
- }
- return this.negative !== 0 ? -res | 0 : res;
- }),
- (BN.prototype.cmp = function (num) {
- if (this.negative !== 0 && num.negative === 0) return -1;
- if (this.negative === 0 && num.negative !== 0) return 1;
- var res = this.ucmp(num);
- return this.negative !== 0 ? -res | 0 : res;
- }),
- (BN.prototype.ucmp = function (num) {
- if (this.length > num.length) return 1;
- if (this.length < num.length) return -1;
- for (var res = 0, i = this.length - 1; i >= 0; i--) {
- var a = this.words[i] | 0,
- b = num.words[i] | 0;
- if (a !== b) {
- a < b ? (res = -1) : a > b && (res = 1);
- break;
- }
- }
- return res;
- }),
- (BN.prototype.gtn = function (num) {
- return this.cmpn(num) === 1;
- }),
- (BN.prototype.gt = function (num) {
- return this.cmp(num) === 1;
- }),
- (BN.prototype.gten = function (num) {
- return this.cmpn(num) >= 0;
- }),
- (BN.prototype.gte = function (num) {
- return this.cmp(num) >= 0;
- }),
- (BN.prototype.ltn = function (num) {
- return this.cmpn(num) === -1;
- }),
- (BN.prototype.lt = function (num) {
- return this.cmp(num) === -1;
- }),
- (BN.prototype.lten = function (num) {
- return this.cmpn(num) <= 0;
- }),
- (BN.prototype.lte = function (num) {
- return this.cmp(num) <= 0;
- }),
- (BN.prototype.eqn = function (num) {
- return this.cmpn(num) === 0;
- }),
- (BN.prototype.eq = function (num) {
- return this.cmp(num) === 0;
- }),
- (BN.red = function (num) {
- return new Red(num);
- }),
- (BN.prototype.toRed = function (ctx) {
- return (
- assert(!this.red, "Already a number in reduction context"),
- assert(this.negative === 0, "red works only with positives"),
- ctx.convertTo(this)._forceRed(ctx)
- );
- }),
- (BN.prototype.fromRed = function () {
- return assert(this.red, "fromRed works only with numbers in reduction context"), this.red.convertFrom(this);
- }),
- (BN.prototype._forceRed = function (ctx) {
- return (this.red = ctx), this;
- }),
- (BN.prototype.forceRed = function (ctx) {
- return assert(!this.red, "Already a number in reduction context"), this._forceRed(ctx);
- }),
- (BN.prototype.redAdd = function (num) {
- return assert(this.red, "redAdd works only with red numbers"), this.red.add(this, num);
- }),
- (BN.prototype.redIAdd = function (num) {
- return assert(this.red, "redIAdd works only with red numbers"), this.red.iadd(this, num);
- }),
- (BN.prototype.redSub = function (num) {
- return assert(this.red, "redSub works only with red numbers"), this.red.sub(this, num);
- }),
- (BN.prototype.redISub = function (num) {
- return assert(this.red, "redISub works only with red numbers"), this.red.isub(this, num);
- }),
- (BN.prototype.redShl = function (num) {
- return assert(this.red, "redShl works only with red numbers"), this.red.shl(this, num);
- }),
- (BN.prototype.redMul = function (num) {
- return (
- assert(this.red, "redMul works only with red numbers"),
- this.red._verify2(this, num),
- this.red.mul(this, num)
- );
- }),
- (BN.prototype.redIMul = function (num) {
- return (
- assert(this.red, "redMul works only with red numbers"),
- this.red._verify2(this, num),
- this.red.imul(this, num)
- );
- }),
- (BN.prototype.redSqr = function () {
- return assert(this.red, "redSqr works only with red numbers"), this.red._verify1(this), this.red.sqr(this);
- }),
- (BN.prototype.redISqr = function () {
- return assert(this.red, "redISqr works only with red numbers"), this.red._verify1(this), this.red.isqr(this);
- }),
- (BN.prototype.redSqrt = function () {
- return assert(this.red, "redSqrt works only with red numbers"), this.red._verify1(this), this.red.sqrt(this);
- }),
- (BN.prototype.redInvm = function () {
- return assert(this.red, "redInvm works only with red numbers"), this.red._verify1(this), this.red.invm(this);
- }),
- (BN.prototype.redNeg = function () {
- return assert(this.red, "redNeg works only with red numbers"), this.red._verify1(this), this.red.neg(this);
- }),
- (BN.prototype.redPow = function (num) {
- return assert(this.red && !num.red, "redPow(normalNum)"), this.red._verify1(this), this.red.pow(this, num);
- });
- var primes = {
- k256: null,
- p224: null,
- p192: null,
- p25519: null,
- };
- function MPrime(name, p) {
- (this.name = name),
- (this.p = new BN(p, 16)),
- (this.n = this.p.bitLength()),
- (this.k = new BN(1).iushln(this.n).isub(this.p)),
- (this.tmp = this._tmp());
- }
- (MPrime.prototype._tmp = function () {
- var tmp = new BN(null);
- return (tmp.words = new Array(Math.ceil(this.n / 13))), tmp;
- }),
- (MPrime.prototype.ireduce = function (num) {
- var r = num,
- rlen;
- do this.split(r, this.tmp), (r = this.imulK(r)), (r = r.iadd(this.tmp)), (rlen = r.bitLength());
- while (rlen > this.n);
- var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
- return (
- cmp === 0
- ? ((r.words[0] = 0), (r.length = 1))
- : cmp > 0
- ? r.isub(this.p)
- : r.strip !== void 0
- ? r.strip()
- : r._strip(),
- r
- );
- }),
- (MPrime.prototype.split = function (input, out) {
- input.iushrn(this.n, 0, out);
- }),
- (MPrime.prototype.imulK = function (num) {
- return num.imul(this.k);
- });
- function K256() {
- MPrime.call(this, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f");
- }
- inherits(K256, MPrime),
- (K256.prototype.split = function (input, output) {
- for (var mask = 4194303, outLen = Math.min(input.length, 9), i = 0; i < outLen; i++)
- output.words[i] = input.words[i];
- if (((output.length = outLen), input.length <= 9)) {
- (input.words[0] = 0), (input.length = 1);
- return;
- }
- var prev = input.words[9];
- for (output.words[output.length++] = prev & mask, i = 10; i < input.length; i++) {
- var next = input.words[i] | 0;
- (input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22)), (prev = next);
- }
- (prev >>>= 22),
- (input.words[i - 10] = prev),
- prev === 0 && input.length > 10 ? (input.length -= 10) : (input.length -= 9);
- }),
- (K256.prototype.imulK = function (num) {
- (num.words[num.length] = 0), (num.words[num.length + 1] = 0), (num.length += 2);
- for (var lo = 0, i = 0; i < num.length; i++) {
- var w = num.words[i] | 0;
- (lo += w * 977), (num.words[i] = lo & 67108863), (lo = w * 64 + ((lo / 67108864) | 0));
- }
- return (
- num.words[num.length - 1] === 0 && (num.length--, num.words[num.length - 1] === 0 && num.length--), num
- );
- });
- function P224() {
- MPrime.call(this, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001");
- }
- inherits(P224, MPrime);
- function P192() {
- MPrime.call(this, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff");
- }
- inherits(P192, MPrime);
- function P25519() {
- MPrime.call(this, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed");
- }
- inherits(P25519, MPrime),
- (P25519.prototype.imulK = function (num) {
- for (var carry = 0, i = 0; i < num.length; i++) {
- var hi = (num.words[i] | 0) * 19 + carry,
- lo = hi & 67108863;
- (hi >>>= 26), (num.words[i] = lo), (carry = hi);
- }
- return carry !== 0 && (num.words[num.length++] = carry), num;
- }),
- (BN._prime = function (name) {
- if (primes[name]) return primes[name];
- var prime2;
- if (name === "k256") prime2 = new K256();
- else if (name === "p224") prime2 = new P224();
- else if (name === "p192") prime2 = new P192();
- else if (name === "p25519") prime2 = new P25519();
- else throw new Error("Unknown prime " + name);
- return (primes[name] = prime2), prime2;
- });
- function Red(m) {
- if (typeof m == "string") {
- var prime = BN._prime(m);
- (this.m = prime.p), (this.prime = prime);
- } else assert(m.gtn(1), "modulus must be greater than 1"), (this.m = m), (this.prime = null);
- }
- (Red.prototype._verify1 = function (a) {
- assert(a.negative === 0, "red works only with positives"), assert(a.red, "red works only with red numbers");
- }),
- (Red.prototype._verify2 = function (a, b) {
- assert((a.negative | b.negative) === 0, "red works only with positives"),
- assert(a.red && a.red === b.red, "red works only with red numbers");
- }),
- (Red.prototype.imod = function (a) {
- return this.prime ? this.prime.ireduce(a)._forceRed(this) : a.umod(this.m)._forceRed(this);
- }),
- (Red.prototype.neg = function (a) {
- return a.isZero() ? a.clone() : this.m.sub(a)._forceRed(this);
- }),
- (Red.prototype.add = function (a, b) {
- this._verify2(a, b);
- var res = a.add(b);
- return res.cmp(this.m) >= 0 && res.isub(this.m), res._forceRed(this);
- }),
- (Red.prototype.iadd = function (a, b) {
- this._verify2(a, b);
- var res = a.iadd(b);
- return res.cmp(this.m) >= 0 && res.isub(this.m), res;
- }),
- (Red.prototype.sub = function (a, b) {
- this._verify2(a, b);
- var res = a.sub(b);
- return res.cmpn(0) < 0 && res.iadd(this.m), res._forceRed(this);
- }),
- (Red.prototype.isub = function (a, b) {
- this._verify2(a, b);
- var res = a.isub(b);
- return res.cmpn(0) < 0 && res.iadd(this.m), res;
- }),
- (Red.prototype.shl = function (a, num) {
- return this._verify1(a), this.imod(a.ushln(num));
- }),
- (Red.prototype.imul = function (a, b) {
- return this._verify2(a, b), this.imod(a.imul(b));
- }),
- (Red.prototype.mul = function (a, b) {
- return this._verify2(a, b), this.imod(a.mul(b));
- }),
- (Red.prototype.isqr = function (a) {
- return this.imul(a, a.clone());
- }),
- (Red.prototype.sqr = function (a) {
- return this.mul(a, a);
- }),
- (Red.prototype.sqrt = function (a) {
- if (a.isZero()) return a.clone();
- var mod3 = this.m.andln(3);
- if ((assert(mod3 % 2 === 1), mod3 === 3)) {
- var pow = this.m.add(new BN(1)).iushrn(2);
- return this.pow(a, pow);
- }
- for (var q = this.m.subn(1), s = 0; !q.isZero() && q.andln(1) === 0; ) s++, q.iushrn(1);
- assert(!q.isZero());
- var one = new BN(1).toRed(this),
- nOne = one.redNeg(),
- lpow = this.m.subn(1).iushrn(1),
- z = this.m.bitLength();
- for (z = new BN(2 * z * z).toRed(this); this.pow(z, lpow).cmp(nOne) !== 0; ) z.redIAdd(nOne);
- for (
- var c = this.pow(z, q), r = this.pow(a, q.addn(1).iushrn(1)), t = this.pow(a, q), m = s;
- t.cmp(one) !== 0;
-
- ) {
- for (var tmp = t, i = 0; tmp.cmp(one) !== 0; i++) tmp = tmp.redSqr();
- assert(i < m);
- var b = this.pow(c, new BN(1).iushln(m - i - 1));
- (r = r.redMul(b)), (c = b.redSqr()), (t = t.redMul(c)), (m = i);
- }
- return r;
- }),
- (Red.prototype.invm = function (a) {
- var inv = a._invmp(this.m);
- return inv.negative !== 0 ? ((inv.negative = 0), this.imod(inv).redNeg()) : this.imod(inv);
- }),
- (Red.prototype.pow = function (a, num) {
- if (num.isZero()) return new BN(1).toRed(this);
- if (num.cmpn(1) === 0) return a.clone();
- var windowSize = 4,
- wnd = new Array(1 << windowSize);
- (wnd[0] = new BN(1).toRed(this)), (wnd[1] = a);
- for (var i = 2; i < wnd.length; i++) wnd[i] = this.mul(wnd[i - 1], a);
- var res = wnd[0],
- current = 0,
- currentLen = 0,
- start = num.bitLength() % 26;
- for (start === 0 && (start = 26), i = num.length - 1; i >= 0; i--) {
- for (var word = num.words[i], j = start - 1; j >= 0; j--) {
- var bit = (word >> j) & 1;
- if ((res !== wnd[0] && (res = this.sqr(res)), bit === 0 && current === 0)) {
- currentLen = 0;
- continue;
- }
- (current <<= 1),
- (current |= bit),
- currentLen++,
- !(currentLen !== windowSize && (i !== 0 || j !== 0)) &&
- ((res = this.mul(res, wnd[current])), (currentLen = 0), (current = 0));
- }
- start = 26;
- }
- return res;
- }),
- (Red.prototype.convertTo = function (num) {
- var r = num.umod(this.m);
- return r === num ? r.clone() : r;
- }),
- (Red.prototype.convertFrom = function (num) {
- var res = num.clone();
- return (res.red = null), res;
- }),
- (BN.mont = function (num) {
- return new Mont(num);
- });
- function Mont(m) {
- Red.call(this, m),
- (this.shift = this.m.bitLength()),
- this.shift % 26 !== 0 && (this.shift += 26 - (this.shift % 26)),
- (this.r = new BN(1).iushln(this.shift)),
- (this.r2 = this.imod(this.r.sqr())),
- (this.rinv = this.r._invmp(this.m)),
- (this.minv = this.rinv.mul(this.r).isubn(1).div(this.m)),
- (this.minv = this.minv.umod(this.r)),
- (this.minv = this.r.sub(this.minv));
- }
- inherits(Mont, Red),
- (Mont.prototype.convertTo = function (num) {
- return this.imod(num.ushln(this.shift));
- }),
- (Mont.prototype.convertFrom = function (num) {
- var r = this.imod(num.mul(this.rinv));
- return (r.red = null), r;
- }),
- (Mont.prototype.imul = function (a, b) {
- if (a.isZero() || b.isZero()) return (a.words[0] = 0), (a.length = 1), a;
- var t = a.imul(b),
- c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),
- u = t.isub(c).iushrn(this.shift),
- res = u;
- return (
- u.cmp(this.m) >= 0 ? (res = u.isub(this.m)) : u.cmpn(0) < 0 && (res = u.iadd(this.m)), res._forceRed(this)
- );
- }),
- (Mont.prototype.mul = function (a, b) {
- if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
- var t = a.mul(b),
- c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),
- u = t.isub(c).iushrn(this.shift),
- res = u;
- return (
- u.cmp(this.m) >= 0 ? (res = u.isub(this.m)) : u.cmpn(0) < 0 && (res = u.iadd(this.m)), res._forceRed(this)
- );
- }),
- (Mont.prototype.invm = function (a) {
- var res = this.imod(a._invmp(this.m).mul(this.r2));
- return res._forceRed(this);
- });
- })(typeof module > "u" || module, exports);
- },
-});
-
-// (disabled):node_modules/crypto-browserify/index.js
-var require_crypto_browserify = __commonJS({
- "(disabled):node_modules/crypto-browserify/index.js"() {},
-});
+var require_bn2 = require_bn;
// node_modules/brorand/index.js
var require_brorand = __commonJS({
@@ -7331,6 +5313,7 @@ var require_brorand = __commonJS({
function Rand(rand) {
this.rand = rand;
}
+ Rand.prototype = {};
module.exports.Rand = Rand;
Rand.prototype.generate = function (len) {
return this._rand(len);
@@ -7355,6 +5338,7 @@ var require_mr = __commonJS({
MillerRabin.create = function (rand) {
return new MillerRabin(rand);
};
+ MillerRabin.prototype = {};
MillerRabin.prototype._randbelow = function (n) {
var len = n.bitLength(),
min_bytes = Math.ceil(len / 8);
@@ -7585,6 +5569,7 @@ var require_dh = __commonJS({
(this._primeCode = void 0),
malleable ? ((this.setPublicKey = setPublicKey), (this.setPrivateKey = setPrivateKey)) : (this._primeCode = 8);
}
+ DH.prototype = {};
Object.defineProperty(DH.prototype, "verifyError", {
enumerable: !0,
get: function () {
@@ -7673,2035 +5658,7 @@ var require_browser7 = __commonJS({
});
// node_modules/bn.js/lib/bn.js
-var require_bn3 = __commonJS({
- "node_modules/bn.js/lib/bn.js"(exports, module) {
- (function (module2, exports2) {
- "use strict";
- function assert(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 BN(number, base, endian) {
- if (BN.isBN(number)) return number;
- (this.negative = 0),
- (this.words = null),
- (this.length = 0),
- (this.red = null),
- number !== null &&
- ((base === "le" || base === "be") && ((endian = base), (base = 10)),
- this._init(number || 0, base || 10, endian || "be"));
- }
- typeof module2 == "object" ? (module2.exports = BN) : (exports2.BN = BN), (BN.BN = BN), (BN.wordSize = 26);
- var Buffer2 = Buffer;
- (BN.isBN = function (num) {
- return num instanceof BN
- ? !0
- : num !== null &&
- typeof num == "object" &&
- num.constructor.wordSize === BN.wordSize &&
- Array.isArray(num.words);
- }),
- (BN.max = function (left, right) {
- return left.cmp(right) > 0 ? left : right;
- }),
- (BN.min = function (left, right) {
- return left.cmp(right) < 0 ? left : right;
- }),
- (BN.prototype._init = function (number, base, endian) {
- if (typeof number == "number") return this._initNumber(number, base, endian);
- if (typeof number == "object") return this._initArray(number, base, endian);
- base === "hex" && (base = 16),
- assert(base === (base | 0) && base >= 2 && base <= 36),
- (number = number.toString().replace(/\s+/g, ""));
- var start = 0;
- number[0] === "-" && (start++, (this.negative = 1)),
- start < number.length &&
- (base === 16
- ? this._parseHex(number, start, endian)
- : (this._parseBase(number, base, start),
- endian === "le" && this._initArray(this.toArray(), base, endian)));
- }),
- (BN.prototype._initNumber = function (number, base, endian) {
- number < 0 && ((this.negative = 1), (number = -number)),
- number < 67108864
- ? ((this.words = [number & 67108863]), (this.length = 1))
- : number < 4503599627370496
- ? ((this.words = [number & 67108863, (number / 67108864) & 67108863]), (this.length = 2))
- : (assert(number < 9007199254740992),
- (this.words = [number & 67108863, (number / 67108864) & 67108863, 1]),
- (this.length = 3)),
- endian === "le" && this._initArray(this.toArray(), base, endian);
- }),
- (BN.prototype._initArray = function (number, base, endian) {
- if ((assert(typeof number.length == "number"), number.length <= 0))
- return (this.words = [0]), (this.length = 1), 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,
- 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),
- 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),
- 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;
- if (c >= 65 && c <= 70) return c - 55;
- if (c >= 97 && c <= 102) return c - 87;
- assert(!1, "Invalid character in " + string);
- }
- function parseHexByte(string, lowerBound, index) {
- var r = parseHex4Bits(string, index);
- return index - 1 >= lowerBound && (r |= parseHex4Bits(string, index - 1) << 4), r;
- }
- BN.prototype._parseHex = function (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,
- j = 0,
- w;
- if (endian === "be")
- for (i = number.length - 1; i >= start; i -= 2)
- (w = parseHexByte(number, start, i) << off),
- (this.words[j] |= w & 67108863),
- off >= 18 ? ((off -= 18), (j += 1), (this.words[j] |= w >>> 26)) : (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),
- off >= 18 ? ((off -= 18), (j += 1), (this.words[j] |= w >>> 26)) : (off += 8);
- }
- this._strip();
- };
- function parseBase(str, start, end, mul) {
- for (var r = 0, b = 0, len = Math.min(str.length, end), i = start; i < len; i++) {
- var c = str.charCodeAt(i) - 48;
- (r *= mul),
- c >= 49 ? (b = c - 49 + 10) : c >= 17 ? (b = c - 17 + 10) : (b = c),
- assert(c >= 0 && b < mul, "Invalid character"),
- (r += b);
- }
- return r;
- }
- (BN.prototype._parseBase = function (number, base, start) {
- (this.words = [0]), (this.length = 1);
- for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) limbLen++;
- limbLen--, (limbPow = (limbPow / base) | 0);
- for (
- var total = number.length - start,
- mod = total % limbLen,
- end = Math.min(total, total - mod) + start,
- word = 0,
- i = start;
- i < end;
- i += limbLen
- )
- (word = parseBase(number, i, i + limbLen, base)),
- this.imuln(limbPow),
- this.words[0] + word < 67108864 ? (this.words[0] += word) : this._iaddn(word);
- if (mod !== 0) {
- var pow = 1;
- for (word = parseBase(number, i, number.length, base), i = 0; i < mod; i++) pow *= base;
- this.imuln(pow), this.words[0] + word < 67108864 ? (this.words[0] += word) : this._iaddn(word);
- }
- this._strip();
- }),
- (BN.prototype.copy = function (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);
- }
- if (
- ((BN.prototype._move = function (dest) {
- move(dest, this);
- }),
- (BN.prototype.clone = function () {
- var r = new BN(null);
- return this.copy(r), r;
- }),
- (BN.prototype._expand = function (size) {
- for (; this.length < size; ) this.words[this.length++] = 0;
- return this;
- }),
- (BN.prototype._strip = function () {
- for (; this.length > 1 && this.words[this.length - 1] === 0; ) this.length--;
- return this._normSign();
- }),
- (BN.prototype._normSign = function () {
- return this.length === 1 && this.words[0] === 0 && (this.negative = 0), this;
- }),
- typeof Symbol < "u" && typeof Symbol.for == "function")
- )
- try {
- BN.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
- } catch {
- BN.prototype.inspect = inspect;
- }
- else BN.prototype.inspect = inspect;
- function inspect() {
- return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
- }
- var zeros = [
- "",
- "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",
- ],
- 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,
- ],
- 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,
- ];
- (BN.prototype.toString = function (base, padding) {
- (base = base || 10), (padding = padding | 0 || 1);
- var out;
- if (base === 16 || base === "hex") {
- out = "";
- for (var off = 0, carry = 0, i = 0; i < this.length; i++) {
- var w = this.words[i],
- word = (((w << off) | carry) & 16777215).toString(16);
- (carry = (w >>> (24 - off)) & 16777215),
- (off += 2),
- off >= 26 && ((off -= 26), i--),
- carry !== 0 || i !== this.length - 1 ? (out = zeros[6 - word.length] + word + out) : (out = word + out);
- }
- for (carry !== 0 && (out = carry.toString(16) + out); out.length % padding !== 0; ) out = "0" + out;
- return this.negative !== 0 && (out = "-" + out), out;
- }
- if (base === (base | 0) && base >= 2 && base <= 36) {
- var groupSize = groupSizes[base],
- groupBase = groupBases[base];
- out = "";
- var c = this.clone();
- for (c.negative = 0; !c.isZero(); ) {
- var r = c.modrn(groupBase).toString(base);
- (c = c.idivn(groupBase)), c.isZero() ? (out = r + out) : (out = zeros[groupSize - r.length] + r + out);
- }
- for (this.isZero() && (out = "0" + out); out.length % padding !== 0; ) out = "0" + out;
- return this.negative !== 0 && (out = "-" + out), out;
- }
- assert(!1, "Base should be between 2 and 36");
- }),
- (BN.prototype.toNumber = function () {
- var ret = this.words[0];
- return (
- this.length === 2
- ? (ret += this.words[1] * 67108864)
- : this.length === 3 && this.words[2] === 1
- ? (ret += 4503599627370496 + this.words[1] * 67108864)
- : this.length > 2 && assert(!1, "Number can only safely store up to 53 bits"),
- this.negative !== 0 ? -ret : ret
- );
- }),
- (BN.prototype.toJSON = function () {
- return this.toString(16, 2);
- }),
- Buffer2 &&
- (BN.prototype.toBuffer = function (endian, length) {
- return this.toArrayLike(Buffer2, endian, length);
- }),
- (BN.prototype.toArray = function (endian, length) {
- return this.toArrayLike(Array, endian, length);
- });
- var allocate = function (ArrayType, size) {
- return ArrayType.allocUnsafe ? ArrayType.allocUnsafe(size) : new ArrayType(size);
- };
- (BN.prototype.toArrayLike = function (ArrayType, endian, length) {
- this._strip();
- var byteLength = this.byteLength(),
- reqLength = length || Math.max(1, byteLength);
- assert(byteLength <= reqLength, "byte array longer than desired length"),
- assert(reqLength > 0, "Requested array length <= 0");
- var res = allocate(ArrayType, reqLength),
- postfix = endian === "le" ? "LE" : "BE";
- return this["_toArrayLike" + postfix](res, byteLength), res;
- }),
- (BN.prototype._toArrayLikeLE = function (res, byteLength) {
- for (var position = 0, carry = 0, i = 0, shift = 0; i < this.length; i++) {
- var word = (this.words[i] << shift) | carry;
- (res[position++] = word & 255),
- position < res.length && (res[position++] = (word >> 8) & 255),
- position < res.length && (res[position++] = (word >> 16) & 255),
- shift === 6
- ? (position < res.length && (res[position++] = (word >> 24) & 255), (carry = 0), (shift = 0))
- : ((carry = word >>> 24), (shift += 2));
- }
- if (position < res.length) for (res[position++] = carry; position < res.length; ) res[position++] = 0;
- }),
- (BN.prototype._toArrayLikeBE = function (res, byteLength) {
- for (var position = res.length - 1, carry = 0, i = 0, shift = 0; i < this.length; i++) {
- var word = (this.words[i] << shift) | carry;
- (res[position--] = word & 255),
- position >= 0 && (res[position--] = (word >> 8) & 255),
- position >= 0 && (res[position--] = (word >> 16) & 255),
- shift === 6
- ? (position >= 0 && (res[position--] = (word >> 24) & 255), (carry = 0), (shift = 0))
- : ((carry = word >>> 24), (shift += 2));
- }
- if (position >= 0) for (res[position--] = carry; position >= 0; ) res[position--] = 0;
- }),
- Math.clz32
- ? (BN.prototype._countBits = function (w) {
- return 32 - Math.clz32(w);
- })
- : (BN.prototype._countBits = function (w) {
- var t = w,
- r = 0;
- return (
- t >= 4096 && ((r += 13), (t >>>= 13)),
- t >= 64 && ((r += 7), (t >>>= 7)),
- t >= 8 && ((r += 4), (t >>>= 4)),
- t >= 2 && ((r += 2), (t >>>= 2)),
- r + t
- );
- }),
- (BN.prototype._zeroBits = function (w) {
- if (w === 0) return 26;
- var t = w,
- r = 0;
- return (
- (t & 8191) === 0 && ((r += 13), (t >>>= 13)),
- (t & 127) === 0 && ((r += 7), (t >>>= 7)),
- (t & 15) === 0 && ((r += 4), (t >>>= 4)),
- (t & 3) === 0 && ((r += 2), (t >>>= 2)),
- (t & 1) === 0 && r++,
- r
- );
- }),
- (BN.prototype.bitLength = function () {
- var w = this.words[this.length - 1],
- hi = this._countBits(w);
- return (this.length - 1) * 26 + hi;
- });
- function toBitArray(num) {
- for (var w = new Array(num.bitLength()), bit = 0; bit < w.length; bit++) {
- var off = (bit / 26) | 0,
- wbit = bit % 26;
- w[bit] = (num.words[off] >>> wbit) & 1;
- }
- return w;
- }
- (BN.prototype.zeroBits = function () {
- if (this.isZero()) return 0;
- for (var r = 0, i = 0; i < this.length; i++) {
- var b = this._zeroBits(this.words[i]);
- if (((r += b), b !== 26)) break;
- }
- return r;
- }),
- (BN.prototype.byteLength = function () {
- return Math.ceil(this.bitLength() / 8);
- }),
- (BN.prototype.toTwos = function (width) {
- return this.negative !== 0 ? this.abs().inotn(width).iaddn(1) : this.clone();
- }),
- (BN.prototype.fromTwos = function (width) {
- return this.testn(width - 1) ? this.notn(width).iaddn(1).ineg() : this.clone();
- }),
- (BN.prototype.isNeg = function () {
- return this.negative !== 0;
- }),
- (BN.prototype.neg = function () {
- return this.clone().ineg();
- }),
- (BN.prototype.ineg = function () {
- return this.isZero() || (this.negative ^= 1), this;
- }),
- (BN.prototype.iuor = function (num) {
- for (; 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();
- }),
- (BN.prototype.ior = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuor(num);
- }),
- (BN.prototype.or = function (num) {
- return this.length > num.length ? this.clone().ior(num) : num.clone().ior(this);
- }),
- (BN.prototype.uor = function (num) {
- return this.length > num.length ? this.clone().iuor(num) : num.clone().iuor(this);
- }),
- (BN.prototype.iuand = function (num) {
- var b;
- this.length > num.length ? (b = num) : (b = this);
- for (var i = 0; i < b.length; i++) this.words[i] = this.words[i] & num.words[i];
- return (this.length = b.length), this._strip();
- }),
- (BN.prototype.iand = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuand(num);
- }),
- (BN.prototype.and = function (num) {
- return this.length > num.length ? this.clone().iand(num) : num.clone().iand(this);
- }),
- (BN.prototype.uand = function (num) {
- return this.length > num.length ? this.clone().iuand(num) : num.clone().iuand(this);
- }),
- (BN.prototype.iuxor = function (num) {
- var a, b;
- this.length > num.length ? ((a = this), (b = num)) : ((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];
- return (this.length = a.length), this._strip();
- }),
- (BN.prototype.ixor = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuxor(num);
- }),
- (BN.prototype.xor = function (num) {
- return this.length > num.length ? this.clone().ixor(num) : num.clone().ixor(this);
- }),
- (BN.prototype.uxor = function (num) {
- return this.length > num.length ? this.clone().iuxor(num) : num.clone().iuxor(this);
- }),
- (BN.prototype.inotn = function (width) {
- assert(typeof width == "number" && width >= 0);
- var bytesNeeded = Math.ceil(width / 26) | 0,
- bitsLeft = width % 26;
- this._expand(bytesNeeded), bitsLeft > 0 && bytesNeeded--;
- for (var i = 0; i < bytesNeeded; i++) this.words[i] = ~this.words[i] & 67108863;
- return bitsLeft > 0 && (this.words[i] = ~this.words[i] & (67108863 >> (26 - bitsLeft))), this._strip();
- }),
- (BN.prototype.notn = function (width) {
- return this.clone().inotn(width);
- }),
- (BN.prototype.setn = function (bit, val) {
- assert(typeof bit == "number" && bit >= 0);
- var off = (bit / 26) | 0,
- wbit = bit % 26;
- return (
- this._expand(off + 1),
- val
- ? (this.words[off] = this.words[off] | (1 << wbit))
- : (this.words[off] = this.words[off] & ~(1 << wbit)),
- this._strip()
- );
- }),
- (BN.prototype.iadd = function (num) {
- var r;
- if (this.negative !== 0 && num.negative === 0)
- return (this.negative = 0), (r = this.isub(num)), (this.negative ^= 1), this._normSign();
- if (this.negative === 0 && num.negative !== 0)
- return (num.negative = 0), (r = this.isub(num)), (num.negative = 1), r._normSign();
- var a, b;
- this.length > num.length ? ((a = this), (b = num)) : ((a = num), (b = this));
- for (var carry = 0, i = 0; i < b.length; i++)
- (r = (a.words[i] | 0) + (b.words[i] | 0) + carry), (this.words[i] = r & 67108863), (carry = r >>> 26);
- for (; carry !== 0 && i < a.length; i++)
- (r = (a.words[i] | 0) + carry), (this.words[i] = r & 67108863), (carry = r >>> 26);
- if (((this.length = a.length), carry !== 0)) (this.words[this.length] = carry), this.length++;
- else if (a !== this) for (; i < a.length; i++) this.words[i] = a.words[i];
- return this;
- }),
- (BN.prototype.add = function (num) {
- var res;
- return num.negative !== 0 && this.negative === 0
- ? ((num.negative = 0), (res = this.sub(num)), (num.negative ^= 1), res)
- : num.negative === 0 && this.negative !== 0
- ? ((this.negative = 0), (res = num.sub(this)), (this.negative = 1), res)
- : this.length > num.length
- ? this.clone().iadd(num)
- : num.clone().iadd(this);
- }),
- (BN.prototype.isub = function (num) {
- if (num.negative !== 0) {
- num.negative = 0;
- var r = this.iadd(num);
- return (num.negative = 1), r._normSign();
- } else if (this.negative !== 0)
- return (this.negative = 0), this.iadd(num), (this.negative = 1), this._normSign();
- var cmp = this.cmp(num);
- if (cmp === 0) return (this.negative = 0), (this.length = 1), (this.words[0] = 0), this;
- var a, b;
- cmp > 0 ? ((a = this), (b = num)) : ((a = num), (b = this));
- for (var carry = 0, i = 0; i < b.length; i++)
- (r = (a.words[i] | 0) - (b.words[i] | 0) + carry), (carry = r >> 26), (this.words[i] = r & 67108863);
- for (; carry !== 0 && i < a.length; i++)
- (r = (a.words[i] | 0) + carry), (carry = r >> 26), (this.words[i] = r & 67108863);
- if (carry === 0 && i < a.length && a !== this) for (; i < a.length; i++) this.words[i] = a.words[i];
- return (this.length = Math.max(this.length, i)), a !== this && (this.negative = 1), this._strip();
- }),
- (BN.prototype.sub = function (num) {
- return this.clone().isub(num);
- });
- function smallMulTo(self2, num, out) {
- out.negative = num.negative ^ self2.negative;
- var len = (self2.length + num.length) | 0;
- (out.length = len), (len = (len - 1) | 0);
- var a = self2.words[0] | 0,
- b = num.words[0] | 0,
- r = a * b,
- lo = r & 67108863,
- carry = (r / 67108864) | 0;
- out.words[0] = lo;
- for (var k = 1; k < len; k++) {
- for (
- var ncarry = carry >>> 26,
- rword = carry & 67108863,
- maxJ = Math.min(k, num.length - 1),
- j = Math.max(0, k - self2.length + 1);
- j <= maxJ;
- j++
- ) {
- var i = (k - j) | 0;
- (a = self2.words[i] | 0),
- (b = num.words[j] | 0),
- (r = a * b + rword),
- (ncarry += (r / 67108864) | 0),
- (rword = r & 67108863);
- }
- (out.words[k] = rword | 0), (carry = ncarry | 0);
- }
- return carry !== 0 ? (out.words[k] = carry | 0) : out.length--, out._strip();
- }
- var comb10MulTo = function (self2, num, out) {
- var a = self2.words,
- b = num.words,
- o = out.words,
- c = 0,
- lo,
- mid,
- hi,
- a0 = a[0] | 0,
- al0 = a0 & 8191,
- ah0 = a0 >>> 13,
- a1 = a[1] | 0,
- al1 = a1 & 8191,
- ah1 = a1 >>> 13,
- a2 = a[2] | 0,
- al2 = a2 & 8191,
- ah2 = a2 >>> 13,
- a3 = a[3] | 0,
- al3 = a3 & 8191,
- ah3 = a3 >>> 13,
- a4 = a[4] | 0,
- al4 = a4 & 8191,
- ah4 = a4 >>> 13,
- a5 = a[5] | 0,
- al5 = a5 & 8191,
- ah5 = a5 >>> 13,
- a6 = a[6] | 0,
- al6 = a6 & 8191,
- ah6 = a6 >>> 13,
- a7 = a[7] | 0,
- al7 = a7 & 8191,
- ah7 = a7 >>> 13,
- a8 = a[8] | 0,
- al8 = a8 & 8191,
- ah8 = a8 >>> 13,
- a9 = a[9] | 0,
- al9 = a9 & 8191,
- ah9 = a9 >>> 13,
- b0 = b[0] | 0,
- bl0 = b0 & 8191,
- bh0 = b0 >>> 13,
- b1 = b[1] | 0,
- bl1 = b1 & 8191,
- bh1 = b1 >>> 13,
- b2 = b[2] | 0,
- bl2 = b2 & 8191,
- bh2 = b2 >>> 13,
- b3 = b[3] | 0,
- bl3 = b3 & 8191,
- bh3 = b3 >>> 13,
- b4 = b[4] | 0,
- bl4 = b4 & 8191,
- bh4 = b4 >>> 13,
- b5 = b[5] | 0,
- bl5 = b5 & 8191,
- bh5 = b5 >>> 13,
- b6 = b[6] | 0,
- bl6 = b6 & 8191,
- bh6 = b6 >>> 13,
- b7 = b[7] | 0,
- bl7 = b7 & 8191,
- bh7 = b7 >>> 13,
- b8 = b[8] | 0,
- bl8 = b8 & 8191,
- bh8 = b8 >>> 13,
- b9 = b[9] | 0,
- bl9 = b9 & 8191,
- bh9 = b9 >>> 13;
- (out.negative = self2.negative ^ num.negative),
- (out.length = 19),
- (lo = Math.imul(al0, bl0)),
- (mid = Math.imul(al0, bh0)),
- (mid = (mid + Math.imul(ah0, bl0)) | 0),
- (hi = Math.imul(ah0, bh0));
- var w0 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0),
- (w0 &= 67108863),
- (lo = Math.imul(al1, bl0)),
- (mid = Math.imul(al1, bh0)),
- (mid = (mid + Math.imul(ah1, bl0)) | 0),
- (hi = Math.imul(ah1, bh0)),
- (lo = (lo + Math.imul(al0, bl1)) | 0),
- (mid = (mid + Math.imul(al0, bh1)) | 0),
- (mid = (mid + Math.imul(ah0, bl1)) | 0),
- (hi = (hi + Math.imul(ah0, bh1)) | 0);
- var w1 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0),
- (w1 &= 67108863),
- (lo = Math.imul(al2, bl0)),
- (mid = Math.imul(al2, bh0)),
- (mid = (mid + Math.imul(ah2, bl0)) | 0),
- (hi = Math.imul(ah2, bh0)),
- (lo = (lo + Math.imul(al1, bl1)) | 0),
- (mid = (mid + Math.imul(al1, bh1)) | 0),
- (mid = (mid + Math.imul(ah1, bl1)) | 0),
- (hi = (hi + Math.imul(ah1, bh1)) | 0),
- (lo = (lo + Math.imul(al0, bl2)) | 0),
- (mid = (mid + Math.imul(al0, bh2)) | 0),
- (mid = (mid + Math.imul(ah0, bl2)) | 0),
- (hi = (hi + Math.imul(ah0, bh2)) | 0);
- var w2 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0),
- (w2 &= 67108863),
- (lo = Math.imul(al3, bl0)),
- (mid = Math.imul(al3, bh0)),
- (mid = (mid + Math.imul(ah3, bl0)) | 0),
- (hi = Math.imul(ah3, bh0)),
- (lo = (lo + Math.imul(al2, bl1)) | 0),
- (mid = (mid + Math.imul(al2, bh1)) | 0),
- (mid = (mid + Math.imul(ah2, bl1)) | 0),
- (hi = (hi + Math.imul(ah2, bh1)) | 0),
- (lo = (lo + Math.imul(al1, bl2)) | 0),
- (mid = (mid + Math.imul(al1, bh2)) | 0),
- (mid = (mid + Math.imul(ah1, bl2)) | 0),
- (hi = (hi + Math.imul(ah1, bh2)) | 0),
- (lo = (lo + Math.imul(al0, bl3)) | 0),
- (mid = (mid + Math.imul(al0, bh3)) | 0),
- (mid = (mid + Math.imul(ah0, bl3)) | 0),
- (hi = (hi + Math.imul(ah0, bh3)) | 0);
- var w3 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0),
- (w3 &= 67108863),
- (lo = Math.imul(al4, bl0)),
- (mid = Math.imul(al4, bh0)),
- (mid = (mid + Math.imul(ah4, bl0)) | 0),
- (hi = Math.imul(ah4, bh0)),
- (lo = (lo + Math.imul(al3, bl1)) | 0),
- (mid = (mid + Math.imul(al3, bh1)) | 0),
- (mid = (mid + Math.imul(ah3, bl1)) | 0),
- (hi = (hi + Math.imul(ah3, bh1)) | 0),
- (lo = (lo + Math.imul(al2, bl2)) | 0),
- (mid = (mid + Math.imul(al2, bh2)) | 0),
- (mid = (mid + Math.imul(ah2, bl2)) | 0),
- (hi = (hi + Math.imul(ah2, bh2)) | 0),
- (lo = (lo + Math.imul(al1, bl3)) | 0),
- (mid = (mid + Math.imul(al1, bh3)) | 0),
- (mid = (mid + Math.imul(ah1, bl3)) | 0),
- (hi = (hi + Math.imul(ah1, bh3)) | 0),
- (lo = (lo + Math.imul(al0, bl4)) | 0),
- (mid = (mid + Math.imul(al0, bh4)) | 0),
- (mid = (mid + Math.imul(ah0, bl4)) | 0),
- (hi = (hi + Math.imul(ah0, bh4)) | 0);
- var w4 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0),
- (w4 &= 67108863),
- (lo = Math.imul(al5, bl0)),
- (mid = Math.imul(al5, bh0)),
- (mid = (mid + Math.imul(ah5, bl0)) | 0),
- (hi = Math.imul(ah5, bh0)),
- (lo = (lo + Math.imul(al4, bl1)) | 0),
- (mid = (mid + Math.imul(al4, bh1)) | 0),
- (mid = (mid + Math.imul(ah4, bl1)) | 0),
- (hi = (hi + Math.imul(ah4, bh1)) | 0),
- (lo = (lo + Math.imul(al3, bl2)) | 0),
- (mid = (mid + Math.imul(al3, bh2)) | 0),
- (mid = (mid + Math.imul(ah3, bl2)) | 0),
- (hi = (hi + Math.imul(ah3, bh2)) | 0),
- (lo = (lo + Math.imul(al2, bl3)) | 0),
- (mid = (mid + Math.imul(al2, bh3)) | 0),
- (mid = (mid + Math.imul(ah2, bl3)) | 0),
- (hi = (hi + Math.imul(ah2, bh3)) | 0),
- (lo = (lo + Math.imul(al1, bl4)) | 0),
- (mid = (mid + Math.imul(al1, bh4)) | 0),
- (mid = (mid + Math.imul(ah1, bl4)) | 0),
- (hi = (hi + Math.imul(ah1, bh4)) | 0),
- (lo = (lo + Math.imul(al0, bl5)) | 0),
- (mid = (mid + Math.imul(al0, bh5)) | 0),
- (mid = (mid + Math.imul(ah0, bl5)) | 0),
- (hi = (hi + Math.imul(ah0, bh5)) | 0);
- var w5 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0),
- (w5 &= 67108863),
- (lo = Math.imul(al6, bl0)),
- (mid = Math.imul(al6, bh0)),
- (mid = (mid + Math.imul(ah6, bl0)) | 0),
- (hi = Math.imul(ah6, bh0)),
- (lo = (lo + Math.imul(al5, bl1)) | 0),
- (mid = (mid + Math.imul(al5, bh1)) | 0),
- (mid = (mid + Math.imul(ah5, bl1)) | 0),
- (hi = (hi + Math.imul(ah5, bh1)) | 0),
- (lo = (lo + Math.imul(al4, bl2)) | 0),
- (mid = (mid + Math.imul(al4, bh2)) | 0),
- (mid = (mid + Math.imul(ah4, bl2)) | 0),
- (hi = (hi + Math.imul(ah4, bh2)) | 0),
- (lo = (lo + Math.imul(al3, bl3)) | 0),
- (mid = (mid + Math.imul(al3, bh3)) | 0),
- (mid = (mid + Math.imul(ah3, bl3)) | 0),
- (hi = (hi + Math.imul(ah3, bh3)) | 0),
- (lo = (lo + Math.imul(al2, bl4)) | 0),
- (mid = (mid + Math.imul(al2, bh4)) | 0),
- (mid = (mid + Math.imul(ah2, bl4)) | 0),
- (hi = (hi + Math.imul(ah2, bh4)) | 0),
- (lo = (lo + Math.imul(al1, bl5)) | 0),
- (mid = (mid + Math.imul(al1, bh5)) | 0),
- (mid = (mid + Math.imul(ah1, bl5)) | 0),
- (hi = (hi + Math.imul(ah1, bh5)) | 0),
- (lo = (lo + Math.imul(al0, bl6)) | 0),
- (mid = (mid + Math.imul(al0, bh6)) | 0),
- (mid = (mid + Math.imul(ah0, bl6)) | 0),
- (hi = (hi + Math.imul(ah0, bh6)) | 0);
- var w6 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0),
- (w6 &= 67108863),
- (lo = Math.imul(al7, bl0)),
- (mid = Math.imul(al7, bh0)),
- (mid = (mid + Math.imul(ah7, bl0)) | 0),
- (hi = Math.imul(ah7, bh0)),
- (lo = (lo + Math.imul(al6, bl1)) | 0),
- (mid = (mid + Math.imul(al6, bh1)) | 0),
- (mid = (mid + Math.imul(ah6, bl1)) | 0),
- (hi = (hi + Math.imul(ah6, bh1)) | 0),
- (lo = (lo + Math.imul(al5, bl2)) | 0),
- (mid = (mid + Math.imul(al5, bh2)) | 0),
- (mid = (mid + Math.imul(ah5, bl2)) | 0),
- (hi = (hi + Math.imul(ah5, bh2)) | 0),
- (lo = (lo + Math.imul(al4, bl3)) | 0),
- (mid = (mid + Math.imul(al4, bh3)) | 0),
- (mid = (mid + Math.imul(ah4, bl3)) | 0),
- (hi = (hi + Math.imul(ah4, bh3)) | 0),
- (lo = (lo + Math.imul(al3, bl4)) | 0),
- (mid = (mid + Math.imul(al3, bh4)) | 0),
- (mid = (mid + Math.imul(ah3, bl4)) | 0),
- (hi = (hi + Math.imul(ah3, bh4)) | 0),
- (lo = (lo + Math.imul(al2, bl5)) | 0),
- (mid = (mid + Math.imul(al2, bh5)) | 0),
- (mid = (mid + Math.imul(ah2, bl5)) | 0),
- (hi = (hi + Math.imul(ah2, bh5)) | 0),
- (lo = (lo + Math.imul(al1, bl6)) | 0),
- (mid = (mid + Math.imul(al1, bh6)) | 0),
- (mid = (mid + Math.imul(ah1, bl6)) | 0),
- (hi = (hi + Math.imul(ah1, bh6)) | 0),
- (lo = (lo + Math.imul(al0, bl7)) | 0),
- (mid = (mid + Math.imul(al0, bh7)) | 0),
- (mid = (mid + Math.imul(ah0, bl7)) | 0),
- (hi = (hi + Math.imul(ah0, bh7)) | 0);
- var w7 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0),
- (w7 &= 67108863),
- (lo = Math.imul(al8, bl0)),
- (mid = Math.imul(al8, bh0)),
- (mid = (mid + Math.imul(ah8, bl0)) | 0),
- (hi = Math.imul(ah8, bh0)),
- (lo = (lo + Math.imul(al7, bl1)) | 0),
- (mid = (mid + Math.imul(al7, bh1)) | 0),
- (mid = (mid + Math.imul(ah7, bl1)) | 0),
- (hi = (hi + Math.imul(ah7, bh1)) | 0),
- (lo = (lo + Math.imul(al6, bl2)) | 0),
- (mid = (mid + Math.imul(al6, bh2)) | 0),
- (mid = (mid + Math.imul(ah6, bl2)) | 0),
- (hi = (hi + Math.imul(ah6, bh2)) | 0),
- (lo = (lo + Math.imul(al5, bl3)) | 0),
- (mid = (mid + Math.imul(al5, bh3)) | 0),
- (mid = (mid + Math.imul(ah5, bl3)) | 0),
- (hi = (hi + Math.imul(ah5, bh3)) | 0),
- (lo = (lo + Math.imul(al4, bl4)) | 0),
- (mid = (mid + Math.imul(al4, bh4)) | 0),
- (mid = (mid + Math.imul(ah4, bl4)) | 0),
- (hi = (hi + Math.imul(ah4, bh4)) | 0),
- (lo = (lo + Math.imul(al3, bl5)) | 0),
- (mid = (mid + Math.imul(al3, bh5)) | 0),
- (mid = (mid + Math.imul(ah3, bl5)) | 0),
- (hi = (hi + Math.imul(ah3, bh5)) | 0),
- (lo = (lo + Math.imul(al2, bl6)) | 0),
- (mid = (mid + Math.imul(al2, bh6)) | 0),
- (mid = (mid + Math.imul(ah2, bl6)) | 0),
- (hi = (hi + Math.imul(ah2, bh6)) | 0),
- (lo = (lo + Math.imul(al1, bl7)) | 0),
- (mid = (mid + Math.imul(al1, bh7)) | 0),
- (mid = (mid + Math.imul(ah1, bl7)) | 0),
- (hi = (hi + Math.imul(ah1, bh7)) | 0),
- (lo = (lo + Math.imul(al0, bl8)) | 0),
- (mid = (mid + Math.imul(al0, bh8)) | 0),
- (mid = (mid + Math.imul(ah0, bl8)) | 0),
- (hi = (hi + Math.imul(ah0, bh8)) | 0);
- var w8 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0),
- (w8 &= 67108863),
- (lo = Math.imul(al9, bl0)),
- (mid = Math.imul(al9, bh0)),
- (mid = (mid + Math.imul(ah9, bl0)) | 0),
- (hi = Math.imul(ah9, bh0)),
- (lo = (lo + Math.imul(al8, bl1)) | 0),
- (mid = (mid + Math.imul(al8, bh1)) | 0),
- (mid = (mid + Math.imul(ah8, bl1)) | 0),
- (hi = (hi + Math.imul(ah8, bh1)) | 0),
- (lo = (lo + Math.imul(al7, bl2)) | 0),
- (mid = (mid + Math.imul(al7, bh2)) | 0),
- (mid = (mid + Math.imul(ah7, bl2)) | 0),
- (hi = (hi + Math.imul(ah7, bh2)) | 0),
- (lo = (lo + Math.imul(al6, bl3)) | 0),
- (mid = (mid + Math.imul(al6, bh3)) | 0),
- (mid = (mid + Math.imul(ah6, bl3)) | 0),
- (hi = (hi + Math.imul(ah6, bh3)) | 0),
- (lo = (lo + Math.imul(al5, bl4)) | 0),
- (mid = (mid + Math.imul(al5, bh4)) | 0),
- (mid = (mid + Math.imul(ah5, bl4)) | 0),
- (hi = (hi + Math.imul(ah5, bh4)) | 0),
- (lo = (lo + Math.imul(al4, bl5)) | 0),
- (mid = (mid + Math.imul(al4, bh5)) | 0),
- (mid = (mid + Math.imul(ah4, bl5)) | 0),
- (hi = (hi + Math.imul(ah4, bh5)) | 0),
- (lo = (lo + Math.imul(al3, bl6)) | 0),
- (mid = (mid + Math.imul(al3, bh6)) | 0),
- (mid = (mid + Math.imul(ah3, bl6)) | 0),
- (hi = (hi + Math.imul(ah3, bh6)) | 0),
- (lo = (lo + Math.imul(al2, bl7)) | 0),
- (mid = (mid + Math.imul(al2, bh7)) | 0),
- (mid = (mid + Math.imul(ah2, bl7)) | 0),
- (hi = (hi + Math.imul(ah2, bh7)) | 0),
- (lo = (lo + Math.imul(al1, bl8)) | 0),
- (mid = (mid + Math.imul(al1, bh8)) | 0),
- (mid = (mid + Math.imul(ah1, bl8)) | 0),
- (hi = (hi + Math.imul(ah1, bh8)) | 0),
- (lo = (lo + Math.imul(al0, bl9)) | 0),
- (mid = (mid + Math.imul(al0, bh9)) | 0),
- (mid = (mid + Math.imul(ah0, bl9)) | 0),
- (hi = (hi + Math.imul(ah0, bh9)) | 0);
- var w9 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0),
- (w9 &= 67108863),
- (lo = Math.imul(al9, bl1)),
- (mid = Math.imul(al9, bh1)),
- (mid = (mid + Math.imul(ah9, bl1)) | 0),
- (hi = Math.imul(ah9, bh1)),
- (lo = (lo + Math.imul(al8, bl2)) | 0),
- (mid = (mid + Math.imul(al8, bh2)) | 0),
- (mid = (mid + Math.imul(ah8, bl2)) | 0),
- (hi = (hi + Math.imul(ah8, bh2)) | 0),
- (lo = (lo + Math.imul(al7, bl3)) | 0),
- (mid = (mid + Math.imul(al7, bh3)) | 0),
- (mid = (mid + Math.imul(ah7, bl3)) | 0),
- (hi = (hi + Math.imul(ah7, bh3)) | 0),
- (lo = (lo + Math.imul(al6, bl4)) | 0),
- (mid = (mid + Math.imul(al6, bh4)) | 0),
- (mid = (mid + Math.imul(ah6, bl4)) | 0),
- (hi = (hi + Math.imul(ah6, bh4)) | 0),
- (lo = (lo + Math.imul(al5, bl5)) | 0),
- (mid = (mid + Math.imul(al5, bh5)) | 0),
- (mid = (mid + Math.imul(ah5, bl5)) | 0),
- (hi = (hi + Math.imul(ah5, bh5)) | 0),
- (lo = (lo + Math.imul(al4, bl6)) | 0),
- (mid = (mid + Math.imul(al4, bh6)) | 0),
- (mid = (mid + Math.imul(ah4, bl6)) | 0),
- (hi = (hi + Math.imul(ah4, bh6)) | 0),
- (lo = (lo + Math.imul(al3, bl7)) | 0),
- (mid = (mid + Math.imul(al3, bh7)) | 0),
- (mid = (mid + Math.imul(ah3, bl7)) | 0),
- (hi = (hi + Math.imul(ah3, bh7)) | 0),
- (lo = (lo + Math.imul(al2, bl8)) | 0),
- (mid = (mid + Math.imul(al2, bh8)) | 0),
- (mid = (mid + Math.imul(ah2, bl8)) | 0),
- (hi = (hi + Math.imul(ah2, bh8)) | 0),
- (lo = (lo + Math.imul(al1, bl9)) | 0),
- (mid = (mid + Math.imul(al1, bh9)) | 0),
- (mid = (mid + Math.imul(ah1, bl9)) | 0),
- (hi = (hi + Math.imul(ah1, bh9)) | 0);
- var w10 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0),
- (w10 &= 67108863),
- (lo = Math.imul(al9, bl2)),
- (mid = Math.imul(al9, bh2)),
- (mid = (mid + Math.imul(ah9, bl2)) | 0),
- (hi = Math.imul(ah9, bh2)),
- (lo = (lo + Math.imul(al8, bl3)) | 0),
- (mid = (mid + Math.imul(al8, bh3)) | 0),
- (mid = (mid + Math.imul(ah8, bl3)) | 0),
- (hi = (hi + Math.imul(ah8, bh3)) | 0),
- (lo = (lo + Math.imul(al7, bl4)) | 0),
- (mid = (mid + Math.imul(al7, bh4)) | 0),
- (mid = (mid + Math.imul(ah7, bl4)) | 0),
- (hi = (hi + Math.imul(ah7, bh4)) | 0),
- (lo = (lo + Math.imul(al6, bl5)) | 0),
- (mid = (mid + Math.imul(al6, bh5)) | 0),
- (mid = (mid + Math.imul(ah6, bl5)) | 0),
- (hi = (hi + Math.imul(ah6, bh5)) | 0),
- (lo = (lo + Math.imul(al5, bl6)) | 0),
- (mid = (mid + Math.imul(al5, bh6)) | 0),
- (mid = (mid + Math.imul(ah5, bl6)) | 0),
- (hi = (hi + Math.imul(ah5, bh6)) | 0),
- (lo = (lo + Math.imul(al4, bl7)) | 0),
- (mid = (mid + Math.imul(al4, bh7)) | 0),
- (mid = (mid + Math.imul(ah4, bl7)) | 0),
- (hi = (hi + Math.imul(ah4, bh7)) | 0),
- (lo = (lo + Math.imul(al3, bl8)) | 0),
- (mid = (mid + Math.imul(al3, bh8)) | 0),
- (mid = (mid + Math.imul(ah3, bl8)) | 0),
- (hi = (hi + Math.imul(ah3, bh8)) | 0),
- (lo = (lo + Math.imul(al2, bl9)) | 0),
- (mid = (mid + Math.imul(al2, bh9)) | 0),
- (mid = (mid + Math.imul(ah2, bl9)) | 0),
- (hi = (hi + Math.imul(ah2, bh9)) | 0);
- var w11 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0),
- (w11 &= 67108863),
- (lo = Math.imul(al9, bl3)),
- (mid = Math.imul(al9, bh3)),
- (mid = (mid + Math.imul(ah9, bl3)) | 0),
- (hi = Math.imul(ah9, bh3)),
- (lo = (lo + Math.imul(al8, bl4)) | 0),
- (mid = (mid + Math.imul(al8, bh4)) | 0),
- (mid = (mid + Math.imul(ah8, bl4)) | 0),
- (hi = (hi + Math.imul(ah8, bh4)) | 0),
- (lo = (lo + Math.imul(al7, bl5)) | 0),
- (mid = (mid + Math.imul(al7, bh5)) | 0),
- (mid = (mid + Math.imul(ah7, bl5)) | 0),
- (hi = (hi + Math.imul(ah7, bh5)) | 0),
- (lo = (lo + Math.imul(al6, bl6)) | 0),
- (mid = (mid + Math.imul(al6, bh6)) | 0),
- (mid = (mid + Math.imul(ah6, bl6)) | 0),
- (hi = (hi + Math.imul(ah6, bh6)) | 0),
- (lo = (lo + Math.imul(al5, bl7)) | 0),
- (mid = (mid + Math.imul(al5, bh7)) | 0),
- (mid = (mid + Math.imul(ah5, bl7)) | 0),
- (hi = (hi + Math.imul(ah5, bh7)) | 0),
- (lo = (lo + Math.imul(al4, bl8)) | 0),
- (mid = (mid + Math.imul(al4, bh8)) | 0),
- (mid = (mid + Math.imul(ah4, bl8)) | 0),
- (hi = (hi + Math.imul(ah4, bh8)) | 0),
- (lo = (lo + Math.imul(al3, bl9)) | 0),
- (mid = (mid + Math.imul(al3, bh9)) | 0),
- (mid = (mid + Math.imul(ah3, bl9)) | 0),
- (hi = (hi + Math.imul(ah3, bh9)) | 0);
- var w12 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0),
- (w12 &= 67108863),
- (lo = Math.imul(al9, bl4)),
- (mid = Math.imul(al9, bh4)),
- (mid = (mid + Math.imul(ah9, bl4)) | 0),
- (hi = Math.imul(ah9, bh4)),
- (lo = (lo + Math.imul(al8, bl5)) | 0),
- (mid = (mid + Math.imul(al8, bh5)) | 0),
- (mid = (mid + Math.imul(ah8, bl5)) | 0),
- (hi = (hi + Math.imul(ah8, bh5)) | 0),
- (lo = (lo + Math.imul(al7, bl6)) | 0),
- (mid = (mid + Math.imul(al7, bh6)) | 0),
- (mid = (mid + Math.imul(ah7, bl6)) | 0),
- (hi = (hi + Math.imul(ah7, bh6)) | 0),
- (lo = (lo + Math.imul(al6, bl7)) | 0),
- (mid = (mid + Math.imul(al6, bh7)) | 0),
- (mid = (mid + Math.imul(ah6, bl7)) | 0),
- (hi = (hi + Math.imul(ah6, bh7)) | 0),
- (lo = (lo + Math.imul(al5, bl8)) | 0),
- (mid = (mid + Math.imul(al5, bh8)) | 0),
- (mid = (mid + Math.imul(ah5, bl8)) | 0),
- (hi = (hi + Math.imul(ah5, bh8)) | 0),
- (lo = (lo + Math.imul(al4, bl9)) | 0),
- (mid = (mid + Math.imul(al4, bh9)) | 0),
- (mid = (mid + Math.imul(ah4, bl9)) | 0),
- (hi = (hi + Math.imul(ah4, bh9)) | 0);
- var w13 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0),
- (w13 &= 67108863),
- (lo = Math.imul(al9, bl5)),
- (mid = Math.imul(al9, bh5)),
- (mid = (mid + Math.imul(ah9, bl5)) | 0),
- (hi = Math.imul(ah9, bh5)),
- (lo = (lo + Math.imul(al8, bl6)) | 0),
- (mid = (mid + Math.imul(al8, bh6)) | 0),
- (mid = (mid + Math.imul(ah8, bl6)) | 0),
- (hi = (hi + Math.imul(ah8, bh6)) | 0),
- (lo = (lo + Math.imul(al7, bl7)) | 0),
- (mid = (mid + Math.imul(al7, bh7)) | 0),
- (mid = (mid + Math.imul(ah7, bl7)) | 0),
- (hi = (hi + Math.imul(ah7, bh7)) | 0),
- (lo = (lo + Math.imul(al6, bl8)) | 0),
- (mid = (mid + Math.imul(al6, bh8)) | 0),
- (mid = (mid + Math.imul(ah6, bl8)) | 0),
- (hi = (hi + Math.imul(ah6, bh8)) | 0),
- (lo = (lo + Math.imul(al5, bl9)) | 0),
- (mid = (mid + Math.imul(al5, bh9)) | 0),
- (mid = (mid + Math.imul(ah5, bl9)) | 0),
- (hi = (hi + Math.imul(ah5, bh9)) | 0);
- var w14 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0),
- (w14 &= 67108863),
- (lo = Math.imul(al9, bl6)),
- (mid = Math.imul(al9, bh6)),
- (mid = (mid + Math.imul(ah9, bl6)) | 0),
- (hi = Math.imul(ah9, bh6)),
- (lo = (lo + Math.imul(al8, bl7)) | 0),
- (mid = (mid + Math.imul(al8, bh7)) | 0),
- (mid = (mid + Math.imul(ah8, bl7)) | 0),
- (hi = (hi + Math.imul(ah8, bh7)) | 0),
- (lo = (lo + Math.imul(al7, bl8)) | 0),
- (mid = (mid + Math.imul(al7, bh8)) | 0),
- (mid = (mid + Math.imul(ah7, bl8)) | 0),
- (hi = (hi + Math.imul(ah7, bh8)) | 0),
- (lo = (lo + Math.imul(al6, bl9)) | 0),
- (mid = (mid + Math.imul(al6, bh9)) | 0),
- (mid = (mid + Math.imul(ah6, bl9)) | 0),
- (hi = (hi + Math.imul(ah6, bh9)) | 0);
- var w15 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0),
- (w15 &= 67108863),
- (lo = Math.imul(al9, bl7)),
- (mid = Math.imul(al9, bh7)),
- (mid = (mid + Math.imul(ah9, bl7)) | 0),
- (hi = Math.imul(ah9, bh7)),
- (lo = (lo + Math.imul(al8, bl8)) | 0),
- (mid = (mid + Math.imul(al8, bh8)) | 0),
- (mid = (mid + Math.imul(ah8, bl8)) | 0),
- (hi = (hi + Math.imul(ah8, bh8)) | 0),
- (lo = (lo + Math.imul(al7, bl9)) | 0),
- (mid = (mid + Math.imul(al7, bh9)) | 0),
- (mid = (mid + Math.imul(ah7, bl9)) | 0),
- (hi = (hi + Math.imul(ah7, bh9)) | 0);
- var w16 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0),
- (w16 &= 67108863),
- (lo = Math.imul(al9, bl8)),
- (mid = Math.imul(al9, bh8)),
- (mid = (mid + Math.imul(ah9, bl8)) | 0),
- (hi = Math.imul(ah9, bh8)),
- (lo = (lo + Math.imul(al8, bl9)) | 0),
- (mid = (mid + Math.imul(al8, bh9)) | 0),
- (mid = (mid + Math.imul(ah8, bl9)) | 0),
- (hi = (hi + Math.imul(ah8, bh9)) | 0);
- var w17 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0),
- (w17 &= 67108863),
- (lo = Math.imul(al9, bl9)),
- (mid = Math.imul(al9, bh9)),
- (mid = (mid + Math.imul(ah9, bl9)) | 0),
- (hi = Math.imul(ah9, bh9));
- var w18 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- return (
- (c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0),
- (w18 &= 67108863),
- (o[0] = w0),
- (o[1] = w1),
- (o[2] = w2),
- (o[3] = w3),
- (o[4] = w4),
- (o[5] = w5),
- (o[6] = w6),
- (o[7] = w7),
- (o[8] = w8),
- (o[9] = w9),
- (o[10] = w10),
- (o[11] = w11),
- (o[12] = w12),
- (o[13] = w13),
- (o[14] = w14),
- (o[15] = w15),
- (o[16] = w16),
- (o[17] = w17),
- (o[18] = w18),
- c !== 0 && ((o[19] = c), out.length++),
- out
- );
- };
- Math.imul || (comb10MulTo = smallMulTo);
- function bigMulTo(self2, num, out) {
- (out.negative = num.negative ^ self2.negative), (out.length = self2.length + num.length);
- for (var carry = 0, hncarry = 0, k = 0; k < out.length - 1; k++) {
- var ncarry = hncarry;
- hncarry = 0;
- for (
- var rword = carry & 67108863, maxJ = Math.min(k, num.length - 1), j = Math.max(0, k - self2.length + 1);
- j <= maxJ;
- j++
- ) {
- var i = k - j,
- a = self2.words[i] | 0,
- b = num.words[j] | 0,
- r = a * b,
- lo = r & 67108863;
- (ncarry = (ncarry + ((r / 67108864) | 0)) | 0),
- (lo = (lo + rword) | 0),
- (rword = lo & 67108863),
- (ncarry = (ncarry + (lo >>> 26)) | 0),
- (hncarry += ncarry >>> 26),
- (ncarry &= 67108863);
- }
- (out.words[k] = rword), (carry = ncarry), (ncarry = hncarry);
- }
- return carry !== 0 ? (out.words[k] = carry) : out.length--, out._strip();
- }
- function jumboMulTo(self2, num, out) {
- return bigMulTo(self2, num, out);
- }
- BN.prototype.mulTo = function (num, out) {
- var res,
- len = this.length + num.length;
- return (
- this.length === 10 && num.length === 10
- ? (res = comb10MulTo(this, num, out))
- : len < 63
- ? (res = smallMulTo(this, num, out))
- : len < 1024
- ? (res = bigMulTo(this, num, out))
- : (res = jumboMulTo(this, num, out)),
- res
- );
- };
- function FFTM(x, y) {
- (this.x = x), (this.y = y);
- }
- (FFTM.prototype.makeRBT = function (N) {
- for (var t = new Array(N), l = BN.prototype._countBits(N) - 1, i = 0; i < N; i++) t[i] = this.revBin(i, l, N);
- return t;
- }),
- (FFTM.prototype.revBin = function (x, l, N) {
- if (x === 0 || x === N - 1) return x;
- for (var rb = 0, i = 0; i < l; i++) (rb |= (x & 1) << (l - i - 1)), (x >>= 1);
- return rb;
- }),
- (FFTM.prototype.permute = function (rbt, rws, iws, rtws, itws, N) {
- for (var i = 0; i < N; i++) (rtws[i] = rws[rbt[i]]), (itws[i] = iws[rbt[i]]);
- }),
- (FFTM.prototype.transform = function (rws, iws, rtws, itws, N, rbt) {
- this.permute(rbt, rws, iws, rtws, itws, N);
- for (var s = 1; s < N; s <<= 1)
- for (
- var l = s << 1, rtwdf = Math.cos((2 * Math.PI) / l), itwdf = Math.sin((2 * Math.PI) / l), p = 0;
- p < N;
- p += l
- )
- for (var rtwdf_ = rtwdf, itwdf_ = itwdf, j = 0; j < s; j++) {
- var re = rtws[p + j],
- ie = itws[p + j],
- ro = rtws[p + j + s],
- io = itws[p + j + s],
- rx = rtwdf_ * ro - itwdf_ * io;
- (io = rtwdf_ * io + itwdf_ * ro),
- (ro = rx),
- (rtws[p + j] = re + ro),
- (itws[p + j] = ie + io),
- (rtws[p + j + s] = re - ro),
- (itws[p + j + s] = ie - io),
- j !== l &&
- ((rx = rtwdf * rtwdf_ - itwdf * itwdf_), (itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_), (rtwdf_ = rx));
- }
- }),
- (FFTM.prototype.guessLen13b = function (n, m) {
- var N = Math.max(m, n) | 1,
- odd = N & 1,
- i = 0;
- for (N = (N / 2) | 0; N; N = N >>> 1) i++;
- return 1 << (i + 1 + odd);
- }),
- (FFTM.prototype.conjugate = function (rws, iws, N) {
- if (!(N <= 1))
- for (var i = 0; i < N / 2; i++) {
- var t = rws[i];
- (rws[i] = rws[N - i - 1]),
- (rws[N - i - 1] = t),
- (t = iws[i]),
- (iws[i] = -iws[N - i - 1]),
- (iws[N - i - 1] = -t);
- }
- }),
- (FFTM.prototype.normalize13b = function (ws, N) {
- for (var carry = 0, i = 0; i < N / 2; i++) {
- var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry;
- (ws[i] = w & 67108863), w < 67108864 ? (carry = 0) : (carry = (w / 67108864) | 0);
- }
- return ws;
- }),
- (FFTM.prototype.convert13b = function (ws, len, rws, N) {
- for (var carry = 0, i = 0; i < len; i++)
- (carry = carry + (ws[i] | 0)),
- (rws[2 * i] = carry & 8191),
- (carry = carry >>> 13),
- (rws[2 * i + 1] = carry & 8191),
- (carry = carry >>> 13);
- for (i = 2 * len; i < N; ++i) rws[i] = 0;
- assert(carry === 0), assert((carry & -8192) === 0);
- }),
- (FFTM.prototype.stub = function (N) {
- for (var ph = new Array(N), i = 0; i < N; i++) ph[i] = 0;
- return ph;
- }),
- (FFTM.prototype.mulp = function (x, y, out) {
- var N = 2 * this.guessLen13b(x.length, y.length),
- rbt = this.makeRBT(N),
- _ = this.stub(N),
- rws = new Array(N),
- rwst = new Array(N),
- iwst = new Array(N),
- nrws = new Array(N),
- nrwst = new Array(N),
- niwst = new Array(N),
- rmws = out.words;
- (rmws.length = N),
- this.convert13b(x.words, x.length, rws, N),
- this.convert13b(y.words, y.length, nrws, N),
- this.transform(rws, _, rwst, iwst, N, rbt),
- this.transform(nrws, _, nrwst, niwst, N, rbt);
- for (var i = 0; i < N; i++) {
- var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
- (iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]), (rwst[i] = rx);
- }
- return (
- this.conjugate(rwst, iwst, N),
- this.transform(rwst, iwst, rmws, _, N, rbt),
- this.conjugate(rmws, _, N),
- this.normalize13b(rmws, N),
- (out.negative = x.negative ^ y.negative),
- (out.length = x.length + y.length),
- out._strip()
- );
- }),
- (BN.prototype.mul = function (num) {
- var out = new BN(null);
- return (out.words = new Array(this.length + num.length)), this.mulTo(num, out);
- }),
- (BN.prototype.mulf = function (num) {
- var out = new BN(null);
- return (out.words = new Array(this.length + num.length)), jumboMulTo(this, num, out);
- }),
- (BN.prototype.imul = function (num) {
- return this.clone().mulTo(num, this);
- }),
- (BN.prototype.imuln = function (num) {
- var isNegNum = num < 0;
- isNegNum && (num = -num), assert(typeof num == "number"), assert(num < 67108864);
- for (var carry = 0, i = 0; i < this.length; i++) {
- var w = (this.words[i] | 0) * num,
- lo = (w & 67108863) + (carry & 67108863);
- (carry >>= 26), (carry += (w / 67108864) | 0), (carry += lo >>> 26), (this.words[i] = lo & 67108863);
- }
- return carry !== 0 && ((this.words[i] = carry), this.length++), isNegNum ? this.ineg() : this;
- }),
- (BN.prototype.muln = function (num) {
- return this.clone().imuln(num);
- }),
- (BN.prototype.sqr = function () {
- return this.mul(this);
- }),
- (BN.prototype.isqr = function () {
- return this.imul(this.clone());
- }),
- (BN.prototype.pow = function (num) {
- var w = toBitArray(num);
- if (w.length === 0) return new BN(1);
- for (var res = this, i = 0; i < w.length && w[i] === 0; i++, res = res.sqr());
- if (++i < w.length) for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) w[i] !== 0 && (res = res.mul(q));
- return res;
- }),
- (BN.prototype.iushln = function (bits) {
- assert(typeof bits == "number" && bits >= 0);
- var r = bits % 26,
- s = (bits - r) / 26,
- carryMask = (67108863 >>> (26 - r)) << (26 - r),
- i;
- if (r !== 0) {
- var carry = 0;
- for (i = 0; i < this.length; i++) {
- var newCarry = this.words[i] & carryMask,
- c = ((this.words[i] | 0) - newCarry) << r;
- (this.words[i] = c | carry), (carry = newCarry >>> (26 - r));
- }
- carry && ((this.words[i] = carry), this.length++);
- }
- if (s !== 0) {
- for (i = this.length - 1; i >= 0; i--) this.words[i + s] = this.words[i];
- for (i = 0; i < s; i++) this.words[i] = 0;
- this.length += s;
- }
- return this._strip();
- }),
- (BN.prototype.ishln = function (bits) {
- return assert(this.negative === 0), this.iushln(bits);
- }),
- (BN.prototype.iushrn = function (bits, hint, extended) {
- assert(typeof bits == "number" && bits >= 0);
- var h;
- hint ? (h = (hint - (hint % 26)) / 26) : (h = 0);
- var r = bits % 26,
- s = Math.min((bits - r) / 26, this.length),
- mask = 67108863 ^ ((67108863 >>> r) << r),
- maskedWords = extended;
- if (((h -= s), (h = Math.max(0, h)), maskedWords)) {
- for (var i = 0; i < s; i++) maskedWords.words[i] = this.words[i];
- maskedWords.length = s;
- }
- if (s !== 0)
- if (this.length > s) for (this.length -= s, i = 0; i < this.length; i++) this.words[i] = this.words[i + s];
- else (this.words[0] = 0), (this.length = 1);
- var carry = 0;
- for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
- var word = this.words[i] | 0;
- (this.words[i] = (carry << (26 - r)) | (word >>> r)), (carry = word & mask);
- }
- return (
- maskedWords && carry !== 0 && (maskedWords.words[maskedWords.length++] = carry),
- this.length === 0 && ((this.words[0] = 0), (this.length = 1)),
- this._strip()
- );
- }),
- (BN.prototype.ishrn = function (bits, hint, extended) {
- return assert(this.negative === 0), this.iushrn(bits, hint, extended);
- }),
- (BN.prototype.shln = function (bits) {
- return this.clone().ishln(bits);
- }),
- (BN.prototype.ushln = function (bits) {
- return this.clone().iushln(bits);
- }),
- (BN.prototype.shrn = function (bits) {
- return this.clone().ishrn(bits);
- }),
- (BN.prototype.ushrn = function (bits) {
- return this.clone().iushrn(bits);
- }),
- (BN.prototype.testn = function (bit) {
- assert(typeof bit == "number" && bit >= 0);
- var r = bit % 26,
- s = (bit - r) / 26,
- q = 1 << r;
- if (this.length <= s) return !1;
- var w = this.words[s];
- return !!(w & q);
- }),
- (BN.prototype.imaskn = function (bits) {
- assert(typeof bits == "number" && bits >= 0);
- var r = bits % 26,
- s = (bits - r) / 26;
- if ((assert(this.negative === 0, "imaskn works only with positive numbers"), this.length <= s)) return this;
- if ((r !== 0 && s++, (this.length = Math.min(s, this.length)), r !== 0)) {
- var mask = 67108863 ^ ((67108863 >>> r) << r);
- this.words[this.length - 1] &= mask;
- }
- return this._strip();
- }),
- (BN.prototype.maskn = function (bits) {
- return this.clone().imaskn(bits);
- }),
- (BN.prototype.iaddn = function (num) {
- return (
- assert(typeof num == "number"),
- assert(num < 67108864),
- num < 0
- ? this.isubn(-num)
- : this.negative !== 0
- ? this.length === 1 && (this.words[0] | 0) <= num
- ? ((this.words[0] = num - (this.words[0] | 0)), (this.negative = 0), this)
- : ((this.negative = 0), this.isubn(num), (this.negative = 1), this)
- : this._iaddn(num)
- );
- }),
- (BN.prototype._iaddn = function (num) {
- this.words[0] += num;
- for (var i = 0; i < this.length && this.words[i] >= 67108864; i++)
- (this.words[i] -= 67108864), i === this.length - 1 ? (this.words[i + 1] = 1) : this.words[i + 1]++;
- return (this.length = Math.max(this.length, i + 1)), this;
- }),
- (BN.prototype.isubn = function (num) {
- if ((assert(typeof num == "number"), assert(num < 67108864), num < 0)) return this.iaddn(-num);
- if (this.negative !== 0) return (this.negative = 0), this.iaddn(num), (this.negative = 1), this;
- if (((this.words[0] -= num), this.length === 1 && this.words[0] < 0))
- (this.words[0] = -this.words[0]), (this.negative = 1);
- else
- for (var i = 0; i < this.length && this.words[i] < 0; i++)
- (this.words[i] += 67108864), (this.words[i + 1] -= 1);
- return this._strip();
- }),
- (BN.prototype.addn = function (num) {
- return this.clone().iaddn(num);
- }),
- (BN.prototype.subn = function (num) {
- return this.clone().isubn(num);
- }),
- (BN.prototype.iabs = function () {
- return (this.negative = 0), this;
- }),
- (BN.prototype.abs = function () {
- return this.clone().iabs();
- }),
- (BN.prototype._ishlnsubmul = function (num, mul, shift) {
- var len = num.length + shift,
- i;
- this._expand(len);
- var w,
- carry = 0;
- for (i = 0; i < num.length; i++) {
- w = (this.words[i + shift] | 0) + carry;
- var right = (num.words[i] | 0) * mul;
- (w -= right & 67108863),
- (carry = (w >> 26) - ((right / 67108864) | 0)),
- (this.words[i + shift] = w & 67108863);
- }
- for (; i < this.length - shift; i++)
- (w = (this.words[i + shift] | 0) + carry), (carry = w >> 26), (this.words[i + shift] = w & 67108863);
- if (carry === 0) return this._strip();
- for (assert(carry === -1), carry = 0, i = 0; i < this.length; i++)
- (w = -(this.words[i] | 0) + carry), (carry = w >> 26), (this.words[i] = w & 67108863);
- return (this.negative = 1), this._strip();
- }),
- (BN.prototype._wordDiv = function (num, mode) {
- var shift = this.length - num.length,
- a = this.clone(),
- b = num,
- bhi = b.words[b.length - 1] | 0,
- bhiBits = this._countBits(bhi);
- (shift = 26 - bhiBits),
- shift !== 0 && ((b = b.ushln(shift)), a.iushln(shift), (bhi = b.words[b.length - 1] | 0));
- var m = a.length - b.length,
- q;
- if (mode !== "mod") {
- (q = new BN(null)), (q.length = m + 1), (q.words = new Array(q.length));
- for (var i = 0; i < q.length; i++) q.words[i] = 0;
- }
- var diff = a.clone()._ishlnsubmul(b, 1, m);
- diff.negative === 0 && ((a = diff), q && (q.words[m] = 1));
- for (var j = m - 1; j >= 0; j--) {
- var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0);
- for (qj = Math.min((qj / bhi) | 0, 67108863), a._ishlnsubmul(b, qj, j); a.negative !== 0; )
- qj--, (a.negative = 0), a._ishlnsubmul(b, 1, j), a.isZero() || (a.negative ^= 1);
- q && (q.words[j] = qj);
- }
- return (
- q && q._strip(),
- a._strip(),
- mode !== "div" && shift !== 0 && a.iushrn(shift),
- {
- div: q || null,
- mod: a,
- }
- );
- }),
- (BN.prototype.divmod = function (num, mode, positive) {
- if ((assert(!num.isZero()), this.isZero()))
- return {
- div: new BN(0),
- mod: new BN(0),
- };
- var div, mod, res;
- return this.negative !== 0 && num.negative === 0
- ? ((res = this.neg().divmod(num, mode)),
- mode !== "mod" && (div = res.div.neg()),
- mode !== "div" && ((mod = res.mod.neg()), positive && mod.negative !== 0 && mod.iadd(num)),
- {
- div,
- mod,
- })
- : this.negative === 0 && num.negative !== 0
- ? ((res = this.divmod(num.neg(), mode)),
- mode !== "mod" && (div = res.div.neg()),
- {
- div,
- mod: res.mod,
- })
- : (this.negative & num.negative) !== 0
- ? ((res = this.neg().divmod(num.neg(), mode)),
- mode !== "div" && ((mod = res.mod.neg()), positive && mod.negative !== 0 && mod.isub(num)),
- {
- div: res.div,
- mod,
- })
- : num.length > this.length || this.cmp(num) < 0
- ? {
- div: new BN(0),
- mod: this,
- }
- : num.length === 1
- ? mode === "div"
- ? {
- div: this.divn(num.words[0]),
- mod: null,
- }
- : mode === "mod"
- ? {
- div: null,
- mod: new BN(this.modrn(num.words[0])),
- }
- : {
- div: this.divn(num.words[0]),
- mod: new BN(this.modrn(num.words[0])),
- }
- : this._wordDiv(num, mode);
- }),
- (BN.prototype.div = function (num) {
- return this.divmod(num, "div", !1).div;
- }),
- (BN.prototype.mod = function (num) {
- return this.divmod(num, "mod", !1).mod;
- }),
- (BN.prototype.umod = function (num) {
- return this.divmod(num, "mod", !0).mod;
- }),
- (BN.prototype.divRound = function (num) {
- var dm = this.divmod(num);
- if (dm.mod.isZero()) return dm.div;
- var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod,
- half = num.ushrn(1),
- r2 = num.andln(1),
- cmp = mod.cmp(half);
- return cmp < 0 || (r2 === 1 && cmp === 0)
- ? dm.div
- : dm.div.negative !== 0
- ? dm.div.isubn(1)
- : dm.div.iaddn(1);
- }),
- (BN.prototype.modrn = function (num) {
- var isNegNum = num < 0;
- isNegNum && (num = -num), assert(num <= 67108863);
- for (var p = (1 << 26) % num, acc = 0, i = this.length - 1; i >= 0; i--)
- acc = (p * acc + (this.words[i] | 0)) % num;
- return isNegNum ? -acc : acc;
- }),
- (BN.prototype.modn = function (num) {
- return this.modrn(num);
- }),
- (BN.prototype.idivn = function (num) {
- var isNegNum = num < 0;
- isNegNum && (num = -num), assert(num <= 67108863);
- for (var carry = 0, i = this.length - 1; i >= 0; i--) {
- var w = (this.words[i] | 0) + carry * 67108864;
- (this.words[i] = (w / num) | 0), (carry = w % num);
- }
- return this._strip(), isNegNum ? this.ineg() : this;
- }),
- (BN.prototype.divn = function (num) {
- return this.clone().idivn(num);
- }),
- (BN.prototype.egcd = function (p) {
- assert(p.negative === 0), assert(!p.isZero());
- var x = this,
- y = p.clone();
- x.negative !== 0 ? (x = x.umod(p)) : (x = x.clone());
- for (var A = new BN(1), B = new BN(0), C = new BN(0), D = new BN(1), g = 0; x.isEven() && y.isEven(); )
- x.iushrn(1), y.iushrn(1), ++g;
- for (var yp = y.clone(), xp = x.clone(); !x.isZero(); ) {
- for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
- if (i > 0)
- for (x.iushrn(i); i-- > 0; )
- (A.isOdd() || B.isOdd()) && (A.iadd(yp), B.isub(xp)), A.iushrn(1), B.iushrn(1);
- for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
- if (j > 0)
- for (y.iushrn(j); j-- > 0; )
- (C.isOdd() || D.isOdd()) && (C.iadd(yp), D.isub(xp)), C.iushrn(1), D.iushrn(1);
- x.cmp(y) >= 0 ? (x.isub(y), A.isub(C), B.isub(D)) : (y.isub(x), C.isub(A), D.isub(B));
- }
- return {
- a: C,
- b: D,
- gcd: y.iushln(g),
- };
- }),
- (BN.prototype._invmp = function (p) {
- assert(p.negative === 0), assert(!p.isZero());
- var a = this,
- b = p.clone();
- a.negative !== 0 ? (a = a.umod(p)) : (a = a.clone());
- for (var x1 = new BN(1), x2 = new BN(0), delta = b.clone(); a.cmpn(1) > 0 && b.cmpn(1) > 0; ) {
- for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
- if (i > 0) for (a.iushrn(i); i-- > 0; ) x1.isOdd() && x1.iadd(delta), x1.iushrn(1);
- for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
- if (j > 0) for (b.iushrn(j); j-- > 0; ) x2.isOdd() && x2.iadd(delta), x2.iushrn(1);
- a.cmp(b) >= 0 ? (a.isub(b), x1.isub(x2)) : (b.isub(a), x2.isub(x1));
- }
- var res;
- return a.cmpn(1) === 0 ? (res = x1) : (res = x2), res.cmpn(0) < 0 && res.iadd(p), res;
- }),
- (BN.prototype.gcd = function (num) {
- if (this.isZero()) return num.abs();
- if (num.isZero()) return this.abs();
- var a = this.clone(),
- b = num.clone();
- (a.negative = 0), (b.negative = 0);
- for (var shift = 0; a.isEven() && b.isEven(); shift++) a.iushrn(1), b.iushrn(1);
- do {
- for (; a.isEven(); ) a.iushrn(1);
- for (; b.isEven(); ) b.iushrn(1);
- var r = a.cmp(b);
- if (r < 0) {
- var t = a;
- (a = b), (b = t);
- } else if (r === 0 || b.cmpn(1) === 0) break;
- a.isub(b);
- } while (!0);
- return b.iushln(shift);
- }),
- (BN.prototype.invm = function (num) {
- return this.egcd(num).a.umod(num);
- }),
- (BN.prototype.isEven = function () {
- return (this.words[0] & 1) === 0;
- }),
- (BN.prototype.isOdd = function () {
- return (this.words[0] & 1) === 1;
- }),
- (BN.prototype.andln = function (num) {
- return this.words[0] & num;
- }),
- (BN.prototype.bincn = function (bit) {
- assert(typeof bit == "number");
- var r = bit % 26,
- s = (bit - r) / 26,
- q = 1 << r;
- if (this.length <= s) return this._expand(s + 1), (this.words[s] |= q), this;
- for (var carry = q, i = s; carry !== 0 && i < this.length; i++) {
- var w = this.words[i] | 0;
- (w += carry), (carry = w >>> 26), (w &= 67108863), (this.words[i] = w);
- }
- return carry !== 0 && ((this.words[i] = carry), this.length++), this;
- }),
- (BN.prototype.isZero = function () {
- return this.length === 1 && this.words[0] === 0;
- }),
- (BN.prototype.cmpn = function (num) {
- var negative = num < 0;
- if (this.negative !== 0 && !negative) return -1;
- if (this.negative === 0 && negative) return 1;
- this._strip();
- var res;
- if (this.length > 1) res = 1;
- else {
- negative && (num = -num), assert(num <= 67108863, "Number is too big");
- var w = this.words[0] | 0;
- res = w === num ? 0 : w < num ? -1 : 1;
- }
- return this.negative !== 0 ? -res | 0 : res;
- }),
- (BN.prototype.cmp = function (num) {
- if (this.negative !== 0 && num.negative === 0) return -1;
- if (this.negative === 0 && num.negative !== 0) return 1;
- var res = this.ucmp(num);
- return this.negative !== 0 ? -res | 0 : res;
- }),
- (BN.prototype.ucmp = function (num) {
- if (this.length > num.length) return 1;
- if (this.length < num.length) return -1;
- for (var res = 0, i = this.length - 1; i >= 0; i--) {
- var a = this.words[i] | 0,
- b = num.words[i] | 0;
- if (a !== b) {
- a < b ? (res = -1) : a > b && (res = 1);
- break;
- }
- }
- return res;
- }),
- (BN.prototype.gtn = function (num) {
- return this.cmpn(num) === 1;
- }),
- (BN.prototype.gt = function (num) {
- return this.cmp(num) === 1;
- }),
- (BN.prototype.gten = function (num) {
- return this.cmpn(num) >= 0;
- }),
- (BN.prototype.gte = function (num) {
- return this.cmp(num) >= 0;
- }),
- (BN.prototype.ltn = function (num) {
- return this.cmpn(num) === -1;
- }),
- (BN.prototype.lt = function (num) {
- return this.cmp(num) === -1;
- }),
- (BN.prototype.lten = function (num) {
- return this.cmpn(num) <= 0;
- }),
- (BN.prototype.lte = function (num) {
- return this.cmp(num) <= 0;
- }),
- (BN.prototype.eqn = function (num) {
- return this.cmpn(num) === 0;
- }),
- (BN.prototype.eq = function (num) {
- return this.cmp(num) === 0;
- }),
- (BN.red = function (num) {
- return new Red(num);
- }),
- (BN.prototype.toRed = function (ctx) {
- return (
- assert(!this.red, "Already a number in reduction context"),
- assert(this.negative === 0, "red works only with positives"),
- ctx.convertTo(this)._forceRed(ctx)
- );
- }),
- (BN.prototype.fromRed = function () {
- return assert(this.red, "fromRed works only with numbers in reduction context"), this.red.convertFrom(this);
- }),
- (BN.prototype._forceRed = function (ctx) {
- return (this.red = ctx), this;
- }),
- (BN.prototype.forceRed = function (ctx) {
- return assert(!this.red, "Already a number in reduction context"), this._forceRed(ctx);
- }),
- (BN.prototype.redAdd = function (num) {
- return assert(this.red, "redAdd works only with red numbers"), this.red.add(this, num);
- }),
- (BN.prototype.redIAdd = function (num) {
- return assert(this.red, "redIAdd works only with red numbers"), this.red.iadd(this, num);
- }),
- (BN.prototype.redSub = function (num) {
- return assert(this.red, "redSub works only with red numbers"), this.red.sub(this, num);
- }),
- (BN.prototype.redISub = function (num) {
- return assert(this.red, "redISub works only with red numbers"), this.red.isub(this, num);
- }),
- (BN.prototype.redShl = function (num) {
- return assert(this.red, "redShl works only with red numbers"), this.red.shl(this, num);
- }),
- (BN.prototype.redMul = function (num) {
- return (
- assert(this.red, "redMul works only with red numbers"),
- this.red._verify2(this, num),
- this.red.mul(this, num)
- );
- }),
- (BN.prototype.redIMul = function (num) {
- return (
- assert(this.red, "redMul works only with red numbers"),
- this.red._verify2(this, num),
- this.red.imul(this, num)
- );
- }),
- (BN.prototype.redSqr = function () {
- return assert(this.red, "redSqr works only with red numbers"), this.red._verify1(this), this.red.sqr(this);
- }),
- (BN.prototype.redISqr = function () {
- return assert(this.red, "redISqr works only with red numbers"), this.red._verify1(this), this.red.isqr(this);
- }),
- (BN.prototype.redSqrt = function () {
- return assert(this.red, "redSqrt works only with red numbers"), this.red._verify1(this), this.red.sqrt(this);
- }),
- (BN.prototype.redInvm = function () {
- return assert(this.red, "redInvm works only with red numbers"), this.red._verify1(this), this.red.invm(this);
- }),
- (BN.prototype.redNeg = function () {
- return assert(this.red, "redNeg works only with red numbers"), this.red._verify1(this), this.red.neg(this);
- }),
- (BN.prototype.redPow = function (num) {
- return assert(this.red && !num.red, "redPow(normalNum)"), this.red._verify1(this), this.red.pow(this, num);
- });
- var primes = {
- k256: null,
- p224: null,
- p192: null,
- p25519: null,
- };
- function MPrime(name, p) {
- (this.name = name),
- (this.p = new BN(p, 16)),
- (this.n = this.p.bitLength()),
- (this.k = new BN(1).iushln(this.n).isub(this.p)),
- (this.tmp = this._tmp());
- }
- (MPrime.prototype._tmp = function () {
- var tmp = new BN(null);
- return (tmp.words = new Array(Math.ceil(this.n / 13))), tmp;
- }),
- (MPrime.prototype.ireduce = function (num) {
- var r = num,
- rlen;
- do this.split(r, this.tmp), (r = this.imulK(r)), (r = r.iadd(this.tmp)), (rlen = r.bitLength());
- while (rlen > this.n);
- var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
- return (
- cmp === 0
- ? ((r.words[0] = 0), (r.length = 1))
- : cmp > 0
- ? r.isub(this.p)
- : r.strip !== void 0
- ? r.strip()
- : r._strip(),
- r
- );
- }),
- (MPrime.prototype.split = function (input, out) {
- input.iushrn(this.n, 0, out);
- }),
- (MPrime.prototype.imulK = function (num) {
- return num.imul(this.k);
- });
- function K256() {
- MPrime.call(this, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f");
- }
- inherits(K256, MPrime),
- (K256.prototype.split = function (input, output) {
- for (var mask = 4194303, outLen = Math.min(input.length, 9), i = 0; i < outLen; i++)
- output.words[i] = input.words[i];
- if (((output.length = outLen), input.length <= 9)) {
- (input.words[0] = 0), (input.length = 1);
- return;
- }
- var prev = input.words[9];
- for (output.words[output.length++] = prev & mask, i = 10; i < input.length; i++) {
- var next = input.words[i] | 0;
- (input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22)), (prev = next);
- }
- (prev >>>= 22),
- (input.words[i - 10] = prev),
- prev === 0 && input.length > 10 ? (input.length -= 10) : (input.length -= 9);
- }),
- (K256.prototype.imulK = function (num) {
- (num.words[num.length] = 0), (num.words[num.length + 1] = 0), (num.length += 2);
- for (var lo = 0, i = 0; i < num.length; i++) {
- var w = num.words[i] | 0;
- (lo += w * 977), (num.words[i] = lo & 67108863), (lo = w * 64 + ((lo / 67108864) | 0));
- }
- return (
- num.words[num.length - 1] === 0 && (num.length--, num.words[num.length - 1] === 0 && num.length--), num
- );
- });
- function P224() {
- MPrime.call(this, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001");
- }
- inherits(P224, MPrime);
- function P192() {
- MPrime.call(this, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff");
- }
- inherits(P192, MPrime);
- function P25519() {
- MPrime.call(this, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed");
- }
- inherits(P25519, MPrime),
- (P25519.prototype.imulK = function (num) {
- for (var carry = 0, i = 0; i < num.length; i++) {
- var hi = (num.words[i] | 0) * 19 + carry,
- lo = hi & 67108863;
- (hi >>>= 26), (num.words[i] = lo), (carry = hi);
- }
- return carry !== 0 && (num.words[num.length++] = carry), num;
- }),
- (BN._prime = function (name) {
- if (primes[name]) return primes[name];
- var prime2;
- if (name === "k256") prime2 = new K256();
- else if (name === "p224") prime2 = new P224();
- else if (name === "p192") prime2 = new P192();
- else if (name === "p25519") prime2 = new P25519();
- else throw new Error("Unknown prime " + name);
- return (primes[name] = prime2), prime2;
- });
- function Red(m) {
- if (typeof m == "string") {
- var prime = BN._prime(m);
- (this.m = prime.p), (this.prime = prime);
- } else assert(m.gtn(1), "modulus must be greater than 1"), (this.m = m), (this.prime = null);
- }
- (Red.prototype._verify1 = function (a) {
- assert(a.negative === 0, "red works only with positives"), assert(a.red, "red works only with red numbers");
- }),
- (Red.prototype._verify2 = function (a, b) {
- assert((a.negative | b.negative) === 0, "red works only with positives"),
- assert(a.red && a.red === b.red, "red works only with red numbers");
- }),
- (Red.prototype.imod = function (a) {
- return this.prime ? this.prime.ireduce(a)._forceRed(this) : (move(a, a.umod(this.m)._forceRed(this)), a);
- }),
- (Red.prototype.neg = function (a) {
- return a.isZero() ? a.clone() : this.m.sub(a)._forceRed(this);
- }),
- (Red.prototype.add = function (a, b) {
- this._verify2(a, b);
- var res = a.add(b);
- return res.cmp(this.m) >= 0 && res.isub(this.m), res._forceRed(this);
- }),
- (Red.prototype.iadd = function (a, b) {
- this._verify2(a, b);
- var res = a.iadd(b);
- return res.cmp(this.m) >= 0 && res.isub(this.m), res;
- }),
- (Red.prototype.sub = function (a, b) {
- this._verify2(a, b);
- var res = a.sub(b);
- return res.cmpn(0) < 0 && res.iadd(this.m), res._forceRed(this);
- }),
- (Red.prototype.isub = function (a, b) {
- this._verify2(a, b);
- var res = a.isub(b);
- return res.cmpn(0) < 0 && res.iadd(this.m), res;
- }),
- (Red.prototype.shl = function (a, num) {
- return this._verify1(a), this.imod(a.ushln(num));
- }),
- (Red.prototype.imul = function (a, b) {
- return this._verify2(a, b), this.imod(a.imul(b));
- }),
- (Red.prototype.mul = function (a, b) {
- return this._verify2(a, b), this.imod(a.mul(b));
- }),
- (Red.prototype.isqr = function (a) {
- return this.imul(a, a.clone());
- }),
- (Red.prototype.sqr = function (a) {
- return this.mul(a, a);
- }),
- (Red.prototype.sqrt = function (a) {
- if (a.isZero()) return a.clone();
- var mod3 = this.m.andln(3);
- if ((assert(mod3 % 2 === 1), mod3 === 3)) {
- var pow = this.m.add(new BN(1)).iushrn(2);
- return this.pow(a, pow);
- }
- for (var q = this.m.subn(1), s = 0; !q.isZero() && q.andln(1) === 0; ) s++, q.iushrn(1);
- assert(!q.isZero());
- var one = new BN(1).toRed(this),
- nOne = one.redNeg(),
- lpow = this.m.subn(1).iushrn(1),
- z = this.m.bitLength();
- for (z = new BN(2 * z * z).toRed(this); this.pow(z, lpow).cmp(nOne) !== 0; ) z.redIAdd(nOne);
- for (
- var c = this.pow(z, q), r = this.pow(a, q.addn(1).iushrn(1)), t = this.pow(a, q), m = s;
- t.cmp(one) !== 0;
-
- ) {
- for (var tmp = t, i = 0; tmp.cmp(one) !== 0; i++) tmp = tmp.redSqr();
- assert(i < m);
- var b = this.pow(c, new BN(1).iushln(m - i - 1));
- (r = r.redMul(b)), (c = b.redSqr()), (t = t.redMul(c)), (m = i);
- }
- return r;
- }),
- (Red.prototype.invm = function (a) {
- var inv = a._invmp(this.m);
- return inv.negative !== 0 ? ((inv.negative = 0), this.imod(inv).redNeg()) : this.imod(inv);
- }),
- (Red.prototype.pow = function (a, num) {
- if (num.isZero()) return new BN(1).toRed(this);
- if (num.cmpn(1) === 0) return a.clone();
- var windowSize = 4,
- wnd = new Array(1 << windowSize);
- (wnd[0] = new BN(1).toRed(this)), (wnd[1] = a);
- for (var i = 2; i < wnd.length; i++) wnd[i] = this.mul(wnd[i - 1], a);
- var res = wnd[0],
- current = 0,
- currentLen = 0,
- start = num.bitLength() % 26;
- for (start === 0 && (start = 26), i = num.length - 1; i >= 0; i--) {
- for (var word = num.words[i], j = start - 1; j >= 0; j--) {
- var bit = (word >> j) & 1;
- if ((res !== wnd[0] && (res = this.sqr(res)), bit === 0 && current === 0)) {
- currentLen = 0;
- continue;
- }
- (current <<= 1),
- (current |= bit),
- currentLen++,
- !(currentLen !== windowSize && (i !== 0 || j !== 0)) &&
- ((res = this.mul(res, wnd[current])), (currentLen = 0), (current = 0));
- }
- start = 26;
- }
- return res;
- }),
- (Red.prototype.convertTo = function (num) {
- var r = num.umod(this.m);
- return r === num ? r.clone() : r;
- }),
- (Red.prototype.convertFrom = function (num) {
- var res = num.clone();
- return (res.red = null), res;
- }),
- (BN.mont = function (num) {
- return new Mont(num);
- });
- function Mont(m) {
- Red.call(this, m),
- (this.shift = this.m.bitLength()),
- this.shift % 26 !== 0 && (this.shift += 26 - (this.shift % 26)),
- (this.r = new BN(1).iushln(this.shift)),
- (this.r2 = this.imod(this.r.sqr())),
- (this.rinv = this.r._invmp(this.m)),
- (this.minv = this.rinv.mul(this.r).isubn(1).div(this.m)),
- (this.minv = this.minv.umod(this.r)),
- (this.minv = this.r.sub(this.minv));
- }
- inherits(Mont, Red),
- (Mont.prototype.convertTo = function (num) {
- return this.imod(num.ushln(this.shift));
- }),
- (Mont.prototype.convertFrom = function (num) {
- var r = this.imod(num.mul(this.rinv));
- return (r.red = null), r;
- }),
- (Mont.prototype.imul = function (a, b) {
- if (a.isZero() || b.isZero()) return (a.words[0] = 0), (a.length = 1), a;
- var t = a.imul(b),
- c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),
- u = t.isub(c).iushrn(this.shift),
- res = u;
- return (
- u.cmp(this.m) >= 0 ? (res = u.isub(this.m)) : u.cmpn(0) < 0 && (res = u.iadd(this.m)), res._forceRed(this)
- );
- }),
- (Mont.prototype.mul = function (a, b) {
- if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
- var t = a.mul(b),
- c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),
- u = t.isub(c).iushrn(this.shift),
- res = u;
- return (
- u.cmp(this.m) >= 0 ? (res = u.isub(this.m)) : u.cmpn(0) < 0 && (res = u.iadd(this.m)), res._forceRed(this)
- );
- }),
- (Mont.prototype.invm = function (a) {
- var res = this.imod(a._invmp(this.m).mul(this.r2));
- return res._forceRed(this);
- });
- })(typeof module > "u" || module, exports);
- },
-});
+var require_bn3 = require_bn;
// node_modules/browserify-rsa/index.js
var require_browserify_rsa = __commonJS({
@@ -9795,1991 +5752,7 @@ var require_package = __commonJS({
});
// node_modules/elliptic/node_modules/bn.js/lib/bn.js
-var require_bn4 = __commonJS({
- "node_modules/elliptic/node_modules/bn.js/lib/bn.js"(exports, module) {
- (function (module2, exports2) {
- "use strict";
- function assert(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 BN(number, base, endian) {
- if (BN.isBN(number)) return number;
- (this.negative = 0),
- (this.words = null),
- (this.length = 0),
- (this.red = null),
- number !== null &&
- ((base === "le" || base === "be") && ((endian = base), (base = 10)),
- this._init(number || 0, base || 10, endian || "be"));
- }
- typeof module2 == "object" ? (module2.exports = BN) : (exports2.BN = BN), (BN.BN = BN), (BN.wordSize = 26);
- var Buffer2 = Buffer;
- (BN.isBN = function (num) {
- return num instanceof BN
- ? !0
- : num !== null &&
- typeof num == "object" &&
- num.constructor.wordSize === BN.wordSize &&
- Array.isArray(num.words);
- }),
- (BN.max = function (left, right) {
- return left.cmp(right) > 0 ? left : right;
- }),
- (BN.min = function (left, right) {
- return left.cmp(right) < 0 ? left : right;
- }),
- (BN.prototype._init = function (number, base, endian) {
- if (typeof number == "number") return this._initNumber(number, base, endian);
- if (typeof number == "object") return this._initArray(number, base, endian);
- base === "hex" && (base = 16),
- assert(base === (base | 0) && base >= 2 && base <= 36),
- (number = number.toString().replace(/\s+/g, ""));
- var start = 0;
- number[0] === "-" && (start++, (this.negative = 1)),
- start < number.length &&
- (base === 16
- ? this._parseHex(number, start, endian)
- : (this._parseBase(number, base, start),
- endian === "le" && this._initArray(this.toArray(), base, endian)));
- }),
- (BN.prototype._initNumber = function (number, base, endian) {
- number < 0 && ((this.negative = 1), (number = -number)),
- number < 67108864
- ? ((this.words = [number & 67108863]), (this.length = 1))
- : number < 4503599627370496
- ? ((this.words = [number & 67108863, (number / 67108864) & 67108863]), (this.length = 2))
- : (assert(number < 9007199254740992),
- (this.words = [number & 67108863, (number / 67108864) & 67108863, 1]),
- (this.length = 3)),
- endian === "le" && this._initArray(this.toArray(), base, endian);
- }),
- (BN.prototype._initArray = function (number, base, endian) {
- if ((assert(typeof number.length == "number"), number.length <= 0))
- return (this.words = [0]), (this.length = 1), 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,
- 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),
- 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),
- off >= 26 && ((off -= 26), j++);
- return this.strip();
- });
- function parseHex4Bits(string, index) {
- var c = string.charCodeAt(index);
- return c >= 65 && c <= 70 ? c - 55 : c >= 97 && c <= 102 ? c - 87 : (c - 48) & 15;
- }
- function parseHexByte(string, lowerBound, index) {
- var r = parseHex4Bits(string, index);
- return index - 1 >= lowerBound && (r |= parseHex4Bits(string, index - 1) << 4), r;
- }
- BN.prototype._parseHex = function (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,
- j = 0,
- w;
- if (endian === "be")
- for (i = number.length - 1; i >= start; i -= 2)
- (w = parseHexByte(number, start, i) << off),
- (this.words[j] |= w & 67108863),
- off >= 18 ? ((off -= 18), (j += 1), (this.words[j] |= w >>> 26)) : (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),
- off >= 18 ? ((off -= 18), (j += 1), (this.words[j] |= w >>> 26)) : (off += 8);
- }
- this.strip();
- };
- function parseBase(str, start, end, mul) {
- for (var r = 0, len = Math.min(str.length, end), i = start; i < len; i++) {
- var c = str.charCodeAt(i) - 48;
- (r *= mul), c >= 49 ? (r += c - 49 + 10) : c >= 17 ? (r += c - 17 + 10) : (r += c);
- }
- return r;
- }
- (BN.prototype._parseBase = function (number, base, start) {
- (this.words = [0]), (this.length = 1);
- for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) limbLen++;
- limbLen--, (limbPow = (limbPow / base) | 0);
- for (
- var total = number.length - start,
- mod = total % limbLen,
- end = Math.min(total, total - mod) + start,
- word = 0,
- i = start;
- i < end;
- i += limbLen
- )
- (word = parseBase(number, i, i + limbLen, base)),
- this.imuln(limbPow),
- this.words[0] + word < 67108864 ? (this.words[0] += word) : this._iaddn(word);
- if (mod !== 0) {
- var pow = 1;
- for (word = parseBase(number, i, number.length, base), i = 0; i < mod; i++) pow *= base;
- this.imuln(pow), this.words[0] + word < 67108864 ? (this.words[0] += word) : this._iaddn(word);
- }
- this.strip();
- }),
- (BN.prototype.copy = function (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);
- }),
- (BN.prototype.clone = function () {
- var r = new BN(null);
- return this.copy(r), r;
- }),
- (BN.prototype._expand = function (size) {
- for (; this.length < size; ) this.words[this.length++] = 0;
- return this;
- }),
- (BN.prototype.strip = function () {
- for (; this.length > 1 && this.words[this.length - 1] === 0; ) this.length--;
- return this._normSign();
- }),
- (BN.prototype._normSign = function () {
- return this.length === 1 && this.words[0] === 0 && (this.negative = 0), this;
- }),
- (BN.prototype.inspect = function () {
- return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
- });
- var zeros = [
- "",
- "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",
- ],
- 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,
- ],
- 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,
- ];
- (BN.prototype.toString = function (base, padding) {
- (base = base || 10), (padding = padding | 0 || 1);
- var out;
- if (base === 16 || base === "hex") {
- out = "";
- for (var off = 0, carry = 0, i = 0; i < this.length; i++) {
- var w = this.words[i],
- word = (((w << off) | carry) & 16777215).toString(16);
- (carry = (w >>> (24 - off)) & 16777215),
- carry !== 0 || i !== this.length - 1 ? (out = zeros[6 - word.length] + word + out) : (out = word + out),
- (off += 2),
- off >= 26 && ((off -= 26), i--);
- }
- for (carry !== 0 && (out = carry.toString(16) + out); out.length % padding !== 0; ) out = "0" + out;
- return this.negative !== 0 && (out = "-" + out), out;
- }
- if (base === (base | 0) && base >= 2 && base <= 36) {
- var groupSize = groupSizes[base],
- groupBase = groupBases[base];
- out = "";
- var c = this.clone();
- for (c.negative = 0; !c.isZero(); ) {
- var r = c.modn(groupBase).toString(base);
- (c = c.idivn(groupBase)), c.isZero() ? (out = r + out) : (out = zeros[groupSize - r.length] + r + out);
- }
- for (this.isZero() && (out = "0" + out); out.length % padding !== 0; ) out = "0" + out;
- return this.negative !== 0 && (out = "-" + out), out;
- }
- assert(!1, "Base should be between 2 and 36");
- }),
- (BN.prototype.toNumber = function () {
- var ret = this.words[0];
- return (
- this.length === 2
- ? (ret += this.words[1] * 67108864)
- : this.length === 3 && this.words[2] === 1
- ? (ret += 4503599627370496 + this.words[1] * 67108864)
- : this.length > 2 && assert(!1, "Number can only safely store up to 53 bits"),
- this.negative !== 0 ? -ret : ret
- );
- }),
- (BN.prototype.toJSON = function () {
- return this.toString(16);
- }),
- (BN.prototype.toBuffer = function (endian, length) {
- return assert(typeof Buffer2 < "u"), this.toArrayLike(Buffer2, endian, length);
- }),
- (BN.prototype.toArray = function (endian, length) {
- return this.toArrayLike(Array, endian, length);
- }),
- (BN.prototype.toArrayLike = function (ArrayType, endian, length) {
- var byteLength = this.byteLength(),
- reqLength = length || Math.max(1, byteLength);
- assert(byteLength <= reqLength, "byte array longer than desired length"),
- assert(reqLength > 0, "Requested array length <= 0"),
- this.strip();
- var littleEndian = endian === "le",
- res = new ArrayType(reqLength),
- b,
- i,
- q = this.clone();
- if (littleEndian) {
- for (i = 0; !q.isZero(); i++) (b = q.andln(255)), q.iushrn(8), (res[i] = b);
- for (; i < reqLength; i++) res[i] = 0;
- } else {
- for (i = 0; i < reqLength - byteLength; i++) res[i] = 0;
- for (i = 0; !q.isZero(); i++) (b = q.andln(255)), q.iushrn(8), (res[reqLength - i - 1] = b);
- }
- return res;
- }),
- Math.clz32
- ? (BN.prototype._countBits = function (w) {
- return 32 - Math.clz32(w);
- })
- : (BN.prototype._countBits = function (w) {
- var t = w,
- r = 0;
- return (
- t >= 4096 && ((r += 13), (t >>>= 13)),
- t >= 64 && ((r += 7), (t >>>= 7)),
- t >= 8 && ((r += 4), (t >>>= 4)),
- t >= 2 && ((r += 2), (t >>>= 2)),
- r + t
- );
- }),
- (BN.prototype._zeroBits = function (w) {
- if (w === 0) return 26;
- var t = w,
- r = 0;
- return (
- (t & 8191) === 0 && ((r += 13), (t >>>= 13)),
- (t & 127) === 0 && ((r += 7), (t >>>= 7)),
- (t & 15) === 0 && ((r += 4), (t >>>= 4)),
- (t & 3) === 0 && ((r += 2), (t >>>= 2)),
- (t & 1) === 0 && r++,
- r
- );
- }),
- (BN.prototype.bitLength = function () {
- var w = this.words[this.length - 1],
- hi = this._countBits(w);
- return (this.length - 1) * 26 + hi;
- });
- function toBitArray(num) {
- for (var w = new Array(num.bitLength()), bit = 0; bit < w.length; bit++) {
- var off = (bit / 26) | 0,
- wbit = bit % 26;
- w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
- }
- return w;
- }
- (BN.prototype.zeroBits = function () {
- if (this.isZero()) return 0;
- for (var r = 0, i = 0; i < this.length; i++) {
- var b = this._zeroBits(this.words[i]);
- if (((r += b), b !== 26)) break;
- }
- return r;
- }),
- (BN.prototype.byteLength = function () {
- return Math.ceil(this.bitLength() / 8);
- }),
- (BN.prototype.toTwos = function (width) {
- return this.negative !== 0 ? this.abs().inotn(width).iaddn(1) : this.clone();
- }),
- (BN.prototype.fromTwos = function (width) {
- return this.testn(width - 1) ? this.notn(width).iaddn(1).ineg() : this.clone();
- }),
- (BN.prototype.isNeg = function () {
- return this.negative !== 0;
- }),
- (BN.prototype.neg = function () {
- return this.clone().ineg();
- }),
- (BN.prototype.ineg = function () {
- return this.isZero() || (this.negative ^= 1), this;
- }),
- (BN.prototype.iuor = function (num) {
- for (; 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();
- }),
- (BN.prototype.ior = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuor(num);
- }),
- (BN.prototype.or = function (num) {
- return this.length > num.length ? this.clone().ior(num) : num.clone().ior(this);
- }),
- (BN.prototype.uor = function (num) {
- return this.length > num.length ? this.clone().iuor(num) : num.clone().iuor(this);
- }),
- (BN.prototype.iuand = function (num) {
- var b;
- this.length > num.length ? (b = num) : (b = this);
- for (var i = 0; i < b.length; i++) this.words[i] = this.words[i] & num.words[i];
- return (this.length = b.length), this.strip();
- }),
- (BN.prototype.iand = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuand(num);
- }),
- (BN.prototype.and = function (num) {
- return this.length > num.length ? this.clone().iand(num) : num.clone().iand(this);
- }),
- (BN.prototype.uand = function (num) {
- return this.length > num.length ? this.clone().iuand(num) : num.clone().iuand(this);
- }),
- (BN.prototype.iuxor = function (num) {
- var a, b;
- this.length > num.length ? ((a = this), (b = num)) : ((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];
- return (this.length = a.length), this.strip();
- }),
- (BN.prototype.ixor = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuxor(num);
- }),
- (BN.prototype.xor = function (num) {
- return this.length > num.length ? this.clone().ixor(num) : num.clone().ixor(this);
- }),
- (BN.prototype.uxor = function (num) {
- return this.length > num.length ? this.clone().iuxor(num) : num.clone().iuxor(this);
- }),
- (BN.prototype.inotn = function (width) {
- assert(typeof width == "number" && width >= 0);
- var bytesNeeded = Math.ceil(width / 26) | 0,
- bitsLeft = width % 26;
- this._expand(bytesNeeded), bitsLeft > 0 && bytesNeeded--;
- for (var i = 0; i < bytesNeeded; i++) this.words[i] = ~this.words[i] & 67108863;
- return bitsLeft > 0 && (this.words[i] = ~this.words[i] & (67108863 >> (26 - bitsLeft))), this.strip();
- }),
- (BN.prototype.notn = function (width) {
- return this.clone().inotn(width);
- }),
- (BN.prototype.setn = function (bit, val) {
- assert(typeof bit == "number" && bit >= 0);
- var off = (bit / 26) | 0,
- wbit = bit % 26;
- return (
- this._expand(off + 1),
- val
- ? (this.words[off] = this.words[off] | (1 << wbit))
- : (this.words[off] = this.words[off] & ~(1 << wbit)),
- this.strip()
- );
- }),
- (BN.prototype.iadd = function (num) {
- var r;
- if (this.negative !== 0 && num.negative === 0)
- return (this.negative = 0), (r = this.isub(num)), (this.negative ^= 1), this._normSign();
- if (this.negative === 0 && num.negative !== 0)
- return (num.negative = 0), (r = this.isub(num)), (num.negative = 1), r._normSign();
- var a, b;
- this.length > num.length ? ((a = this), (b = num)) : ((a = num), (b = this));
- for (var carry = 0, i = 0; i < b.length; i++)
- (r = (a.words[i] | 0) + (b.words[i] | 0) + carry), (this.words[i] = r & 67108863), (carry = r >>> 26);
- for (; carry !== 0 && i < a.length; i++)
- (r = (a.words[i] | 0) + carry), (this.words[i] = r & 67108863), (carry = r >>> 26);
- if (((this.length = a.length), carry !== 0)) (this.words[this.length] = carry), this.length++;
- else if (a !== this) for (; i < a.length; i++) this.words[i] = a.words[i];
- return this;
- }),
- (BN.prototype.add = function (num) {
- var res;
- return num.negative !== 0 && this.negative === 0
- ? ((num.negative = 0), (res = this.sub(num)), (num.negative ^= 1), res)
- : num.negative === 0 && this.negative !== 0
- ? ((this.negative = 0), (res = num.sub(this)), (this.negative = 1), res)
- : this.length > num.length
- ? this.clone().iadd(num)
- : num.clone().iadd(this);
- }),
- (BN.prototype.isub = function (num) {
- if (num.negative !== 0) {
- num.negative = 0;
- var r = this.iadd(num);
- return (num.negative = 1), r._normSign();
- } else if (this.negative !== 0)
- return (this.negative = 0), this.iadd(num), (this.negative = 1), this._normSign();
- var cmp = this.cmp(num);
- if (cmp === 0) return (this.negative = 0), (this.length = 1), (this.words[0] = 0), this;
- var a, b;
- cmp > 0 ? ((a = this), (b = num)) : ((a = num), (b = this));
- for (var carry = 0, i = 0; i < b.length; i++)
- (r = (a.words[i] | 0) - (b.words[i] | 0) + carry), (carry = r >> 26), (this.words[i] = r & 67108863);
- for (; carry !== 0 && i < a.length; i++)
- (r = (a.words[i] | 0) + carry), (carry = r >> 26), (this.words[i] = r & 67108863);
- if (carry === 0 && i < a.length && a !== this) for (; i < a.length; i++) this.words[i] = a.words[i];
- return (this.length = Math.max(this.length, i)), a !== this && (this.negative = 1), this.strip();
- }),
- (BN.prototype.sub = function (num) {
- return this.clone().isub(num);
- });
- function smallMulTo(self2, num, out) {
- out.negative = num.negative ^ self2.negative;
- var len = (self2.length + num.length) | 0;
- (out.length = len), (len = (len - 1) | 0);
- var a = self2.words[0] | 0,
- b = num.words[0] | 0,
- r = a * b,
- lo = r & 67108863,
- carry = (r / 67108864) | 0;
- out.words[0] = lo;
- for (var k = 1; k < len; k++) {
- for (
- var ncarry = carry >>> 26,
- rword = carry & 67108863,
- maxJ = Math.min(k, num.length - 1),
- j = Math.max(0, k - self2.length + 1);
- j <= maxJ;
- j++
- ) {
- var i = (k - j) | 0;
- (a = self2.words[i] | 0),
- (b = num.words[j] | 0),
- (r = a * b + rword),
- (ncarry += (r / 67108864) | 0),
- (rword = r & 67108863);
- }
- (out.words[k] = rword | 0), (carry = ncarry | 0);
- }
- return carry !== 0 ? (out.words[k] = carry | 0) : out.length--, out.strip();
- }
- var comb10MulTo = function (self2, num, out) {
- var a = self2.words,
- b = num.words,
- o = out.words,
- c = 0,
- lo,
- mid,
- hi,
- a0 = a[0] | 0,
- al0 = a0 & 8191,
- ah0 = a0 >>> 13,
- a1 = a[1] | 0,
- al1 = a1 & 8191,
- ah1 = a1 >>> 13,
- a2 = a[2] | 0,
- al2 = a2 & 8191,
- ah2 = a2 >>> 13,
- a3 = a[3] | 0,
- al3 = a3 & 8191,
- ah3 = a3 >>> 13,
- a4 = a[4] | 0,
- al4 = a4 & 8191,
- ah4 = a4 >>> 13,
- a5 = a[5] | 0,
- al5 = a5 & 8191,
- ah5 = a5 >>> 13,
- a6 = a[6] | 0,
- al6 = a6 & 8191,
- ah6 = a6 >>> 13,
- a7 = a[7] | 0,
- al7 = a7 & 8191,
- ah7 = a7 >>> 13,
- a8 = a[8] | 0,
- al8 = a8 & 8191,
- ah8 = a8 >>> 13,
- a9 = a[9] | 0,
- al9 = a9 & 8191,
- ah9 = a9 >>> 13,
- b0 = b[0] | 0,
- bl0 = b0 & 8191,
- bh0 = b0 >>> 13,
- b1 = b[1] | 0,
- bl1 = b1 & 8191,
- bh1 = b1 >>> 13,
- b2 = b[2] | 0,
- bl2 = b2 & 8191,
- bh2 = b2 >>> 13,
- b3 = b[3] | 0,
- bl3 = b3 & 8191,
- bh3 = b3 >>> 13,
- b4 = b[4] | 0,
- bl4 = b4 & 8191,
- bh4 = b4 >>> 13,
- b5 = b[5] | 0,
- bl5 = b5 & 8191,
- bh5 = b5 >>> 13,
- b6 = b[6] | 0,
- bl6 = b6 & 8191,
- bh6 = b6 >>> 13,
- b7 = b[7] | 0,
- bl7 = b7 & 8191,
- bh7 = b7 >>> 13,
- b8 = b[8] | 0,
- bl8 = b8 & 8191,
- bh8 = b8 >>> 13,
- b9 = b[9] | 0,
- bl9 = b9 & 8191,
- bh9 = b9 >>> 13;
- (out.negative = self2.negative ^ num.negative),
- (out.length = 19),
- (lo = Math.imul(al0, bl0)),
- (mid = Math.imul(al0, bh0)),
- (mid = (mid + Math.imul(ah0, bl0)) | 0),
- (hi = Math.imul(ah0, bh0));
- var w0 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0),
- (w0 &= 67108863),
- (lo = Math.imul(al1, bl0)),
- (mid = Math.imul(al1, bh0)),
- (mid = (mid + Math.imul(ah1, bl0)) | 0),
- (hi = Math.imul(ah1, bh0)),
- (lo = (lo + Math.imul(al0, bl1)) | 0),
- (mid = (mid + Math.imul(al0, bh1)) | 0),
- (mid = (mid + Math.imul(ah0, bl1)) | 0),
- (hi = (hi + Math.imul(ah0, bh1)) | 0);
- var w1 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0),
- (w1 &= 67108863),
- (lo = Math.imul(al2, bl0)),
- (mid = Math.imul(al2, bh0)),
- (mid = (mid + Math.imul(ah2, bl0)) | 0),
- (hi = Math.imul(ah2, bh0)),
- (lo = (lo + Math.imul(al1, bl1)) | 0),
- (mid = (mid + Math.imul(al1, bh1)) | 0),
- (mid = (mid + Math.imul(ah1, bl1)) | 0),
- (hi = (hi + Math.imul(ah1, bh1)) | 0),
- (lo = (lo + Math.imul(al0, bl2)) | 0),
- (mid = (mid + Math.imul(al0, bh2)) | 0),
- (mid = (mid + Math.imul(ah0, bl2)) | 0),
- (hi = (hi + Math.imul(ah0, bh2)) | 0);
- var w2 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0),
- (w2 &= 67108863),
- (lo = Math.imul(al3, bl0)),
- (mid = Math.imul(al3, bh0)),
- (mid = (mid + Math.imul(ah3, bl0)) | 0),
- (hi = Math.imul(ah3, bh0)),
- (lo = (lo + Math.imul(al2, bl1)) | 0),
- (mid = (mid + Math.imul(al2, bh1)) | 0),
- (mid = (mid + Math.imul(ah2, bl1)) | 0),
- (hi = (hi + Math.imul(ah2, bh1)) | 0),
- (lo = (lo + Math.imul(al1, bl2)) | 0),
- (mid = (mid + Math.imul(al1, bh2)) | 0),
- (mid = (mid + Math.imul(ah1, bl2)) | 0),
- (hi = (hi + Math.imul(ah1, bh2)) | 0),
- (lo = (lo + Math.imul(al0, bl3)) | 0),
- (mid = (mid + Math.imul(al0, bh3)) | 0),
- (mid = (mid + Math.imul(ah0, bl3)) | 0),
- (hi = (hi + Math.imul(ah0, bh3)) | 0);
- var w3 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0),
- (w3 &= 67108863),
- (lo = Math.imul(al4, bl0)),
- (mid = Math.imul(al4, bh0)),
- (mid = (mid + Math.imul(ah4, bl0)) | 0),
- (hi = Math.imul(ah4, bh0)),
- (lo = (lo + Math.imul(al3, bl1)) | 0),
- (mid = (mid + Math.imul(al3, bh1)) | 0),
- (mid = (mid + Math.imul(ah3, bl1)) | 0),
- (hi = (hi + Math.imul(ah3, bh1)) | 0),
- (lo = (lo + Math.imul(al2, bl2)) | 0),
- (mid = (mid + Math.imul(al2, bh2)) | 0),
- (mid = (mid + Math.imul(ah2, bl2)) | 0),
- (hi = (hi + Math.imul(ah2, bh2)) | 0),
- (lo = (lo + Math.imul(al1, bl3)) | 0),
- (mid = (mid + Math.imul(al1, bh3)) | 0),
- (mid = (mid + Math.imul(ah1, bl3)) | 0),
- (hi = (hi + Math.imul(ah1, bh3)) | 0),
- (lo = (lo + Math.imul(al0, bl4)) | 0),
- (mid = (mid + Math.imul(al0, bh4)) | 0),
- (mid = (mid + Math.imul(ah0, bl4)) | 0),
- (hi = (hi + Math.imul(ah0, bh4)) | 0);
- var w4 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0),
- (w4 &= 67108863),
- (lo = Math.imul(al5, bl0)),
- (mid = Math.imul(al5, bh0)),
- (mid = (mid + Math.imul(ah5, bl0)) | 0),
- (hi = Math.imul(ah5, bh0)),
- (lo = (lo + Math.imul(al4, bl1)) | 0),
- (mid = (mid + Math.imul(al4, bh1)) | 0),
- (mid = (mid + Math.imul(ah4, bl1)) | 0),
- (hi = (hi + Math.imul(ah4, bh1)) | 0),
- (lo = (lo + Math.imul(al3, bl2)) | 0),
- (mid = (mid + Math.imul(al3, bh2)) | 0),
- (mid = (mid + Math.imul(ah3, bl2)) | 0),
- (hi = (hi + Math.imul(ah3, bh2)) | 0),
- (lo = (lo + Math.imul(al2, bl3)) | 0),
- (mid = (mid + Math.imul(al2, bh3)) | 0),
- (mid = (mid + Math.imul(ah2, bl3)) | 0),
- (hi = (hi + Math.imul(ah2, bh3)) | 0),
- (lo = (lo + Math.imul(al1, bl4)) | 0),
- (mid = (mid + Math.imul(al1, bh4)) | 0),
- (mid = (mid + Math.imul(ah1, bl4)) | 0),
- (hi = (hi + Math.imul(ah1, bh4)) | 0),
- (lo = (lo + Math.imul(al0, bl5)) | 0),
- (mid = (mid + Math.imul(al0, bh5)) | 0),
- (mid = (mid + Math.imul(ah0, bl5)) | 0),
- (hi = (hi + Math.imul(ah0, bh5)) | 0);
- var w5 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0),
- (w5 &= 67108863),
- (lo = Math.imul(al6, bl0)),
- (mid = Math.imul(al6, bh0)),
- (mid = (mid + Math.imul(ah6, bl0)) | 0),
- (hi = Math.imul(ah6, bh0)),
- (lo = (lo + Math.imul(al5, bl1)) | 0),
- (mid = (mid + Math.imul(al5, bh1)) | 0),
- (mid = (mid + Math.imul(ah5, bl1)) | 0),
- (hi = (hi + Math.imul(ah5, bh1)) | 0),
- (lo = (lo + Math.imul(al4, bl2)) | 0),
- (mid = (mid + Math.imul(al4, bh2)) | 0),
- (mid = (mid + Math.imul(ah4, bl2)) | 0),
- (hi = (hi + Math.imul(ah4, bh2)) | 0),
- (lo = (lo + Math.imul(al3, bl3)) | 0),
- (mid = (mid + Math.imul(al3, bh3)) | 0),
- (mid = (mid + Math.imul(ah3, bl3)) | 0),
- (hi = (hi + Math.imul(ah3, bh3)) | 0),
- (lo = (lo + Math.imul(al2, bl4)) | 0),
- (mid = (mid + Math.imul(al2, bh4)) | 0),
- (mid = (mid + Math.imul(ah2, bl4)) | 0),
- (hi = (hi + Math.imul(ah2, bh4)) | 0),
- (lo = (lo + Math.imul(al1, bl5)) | 0),
- (mid = (mid + Math.imul(al1, bh5)) | 0),
- (mid = (mid + Math.imul(ah1, bl5)) | 0),
- (hi = (hi + Math.imul(ah1, bh5)) | 0),
- (lo = (lo + Math.imul(al0, bl6)) | 0),
- (mid = (mid + Math.imul(al0, bh6)) | 0),
- (mid = (mid + Math.imul(ah0, bl6)) | 0),
- (hi = (hi + Math.imul(ah0, bh6)) | 0);
- var w6 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0),
- (w6 &= 67108863),
- (lo = Math.imul(al7, bl0)),
- (mid = Math.imul(al7, bh0)),
- (mid = (mid + Math.imul(ah7, bl0)) | 0),
- (hi = Math.imul(ah7, bh0)),
- (lo = (lo + Math.imul(al6, bl1)) | 0),
- (mid = (mid + Math.imul(al6, bh1)) | 0),
- (mid = (mid + Math.imul(ah6, bl1)) | 0),
- (hi = (hi + Math.imul(ah6, bh1)) | 0),
- (lo = (lo + Math.imul(al5, bl2)) | 0),
- (mid = (mid + Math.imul(al5, bh2)) | 0),
- (mid = (mid + Math.imul(ah5, bl2)) | 0),
- (hi = (hi + Math.imul(ah5, bh2)) | 0),
- (lo = (lo + Math.imul(al4, bl3)) | 0),
- (mid = (mid + Math.imul(al4, bh3)) | 0),
- (mid = (mid + Math.imul(ah4, bl3)) | 0),
- (hi = (hi + Math.imul(ah4, bh3)) | 0),
- (lo = (lo + Math.imul(al3, bl4)) | 0),
- (mid = (mid + Math.imul(al3, bh4)) | 0),
- (mid = (mid + Math.imul(ah3, bl4)) | 0),
- (hi = (hi + Math.imul(ah3, bh4)) | 0),
- (lo = (lo + Math.imul(al2, bl5)) | 0),
- (mid = (mid + Math.imul(al2, bh5)) | 0),
- (mid = (mid + Math.imul(ah2, bl5)) | 0),
- (hi = (hi + Math.imul(ah2, bh5)) | 0),
- (lo = (lo + Math.imul(al1, bl6)) | 0),
- (mid = (mid + Math.imul(al1, bh6)) | 0),
- (mid = (mid + Math.imul(ah1, bl6)) | 0),
- (hi = (hi + Math.imul(ah1, bh6)) | 0),
- (lo = (lo + Math.imul(al0, bl7)) | 0),
- (mid = (mid + Math.imul(al0, bh7)) | 0),
- (mid = (mid + Math.imul(ah0, bl7)) | 0),
- (hi = (hi + Math.imul(ah0, bh7)) | 0);
- var w7 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0),
- (w7 &= 67108863),
- (lo = Math.imul(al8, bl0)),
- (mid = Math.imul(al8, bh0)),
- (mid = (mid + Math.imul(ah8, bl0)) | 0),
- (hi = Math.imul(ah8, bh0)),
- (lo = (lo + Math.imul(al7, bl1)) | 0),
- (mid = (mid + Math.imul(al7, bh1)) | 0),
- (mid = (mid + Math.imul(ah7, bl1)) | 0),
- (hi = (hi + Math.imul(ah7, bh1)) | 0),
- (lo = (lo + Math.imul(al6, bl2)) | 0),
- (mid = (mid + Math.imul(al6, bh2)) | 0),
- (mid = (mid + Math.imul(ah6, bl2)) | 0),
- (hi = (hi + Math.imul(ah6, bh2)) | 0),
- (lo = (lo + Math.imul(al5, bl3)) | 0),
- (mid = (mid + Math.imul(al5, bh3)) | 0),
- (mid = (mid + Math.imul(ah5, bl3)) | 0),
- (hi = (hi + Math.imul(ah5, bh3)) | 0),
- (lo = (lo + Math.imul(al4, bl4)) | 0),
- (mid = (mid + Math.imul(al4, bh4)) | 0),
- (mid = (mid + Math.imul(ah4, bl4)) | 0),
- (hi = (hi + Math.imul(ah4, bh4)) | 0),
- (lo = (lo + Math.imul(al3, bl5)) | 0),
- (mid = (mid + Math.imul(al3, bh5)) | 0),
- (mid = (mid + Math.imul(ah3, bl5)) | 0),
- (hi = (hi + Math.imul(ah3, bh5)) | 0),
- (lo = (lo + Math.imul(al2, bl6)) | 0),
- (mid = (mid + Math.imul(al2, bh6)) | 0),
- (mid = (mid + Math.imul(ah2, bl6)) | 0),
- (hi = (hi + Math.imul(ah2, bh6)) | 0),
- (lo = (lo + Math.imul(al1, bl7)) | 0),
- (mid = (mid + Math.imul(al1, bh7)) | 0),
- (mid = (mid + Math.imul(ah1, bl7)) | 0),
- (hi = (hi + Math.imul(ah1, bh7)) | 0),
- (lo = (lo + Math.imul(al0, bl8)) | 0),
- (mid = (mid + Math.imul(al0, bh8)) | 0),
- (mid = (mid + Math.imul(ah0, bl8)) | 0),
- (hi = (hi + Math.imul(ah0, bh8)) | 0);
- var w8 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0),
- (w8 &= 67108863),
- (lo = Math.imul(al9, bl0)),
- (mid = Math.imul(al9, bh0)),
- (mid = (mid + Math.imul(ah9, bl0)) | 0),
- (hi = Math.imul(ah9, bh0)),
- (lo = (lo + Math.imul(al8, bl1)) | 0),
- (mid = (mid + Math.imul(al8, bh1)) | 0),
- (mid = (mid + Math.imul(ah8, bl1)) | 0),
- (hi = (hi + Math.imul(ah8, bh1)) | 0),
- (lo = (lo + Math.imul(al7, bl2)) | 0),
- (mid = (mid + Math.imul(al7, bh2)) | 0),
- (mid = (mid + Math.imul(ah7, bl2)) | 0),
- (hi = (hi + Math.imul(ah7, bh2)) | 0),
- (lo = (lo + Math.imul(al6, bl3)) | 0),
- (mid = (mid + Math.imul(al6, bh3)) | 0),
- (mid = (mid + Math.imul(ah6, bl3)) | 0),
- (hi = (hi + Math.imul(ah6, bh3)) | 0),
- (lo = (lo + Math.imul(al5, bl4)) | 0),
- (mid = (mid + Math.imul(al5, bh4)) | 0),
- (mid = (mid + Math.imul(ah5, bl4)) | 0),
- (hi = (hi + Math.imul(ah5, bh4)) | 0),
- (lo = (lo + Math.imul(al4, bl5)) | 0),
- (mid = (mid + Math.imul(al4, bh5)) | 0),
- (mid = (mid + Math.imul(ah4, bl5)) | 0),
- (hi = (hi + Math.imul(ah4, bh5)) | 0),
- (lo = (lo + Math.imul(al3, bl6)) | 0),
- (mid = (mid + Math.imul(al3, bh6)) | 0),
- (mid = (mid + Math.imul(ah3, bl6)) | 0),
- (hi = (hi + Math.imul(ah3, bh6)) | 0),
- (lo = (lo + Math.imul(al2, bl7)) | 0),
- (mid = (mid + Math.imul(al2, bh7)) | 0),
- (mid = (mid + Math.imul(ah2, bl7)) | 0),
- (hi = (hi + Math.imul(ah2, bh7)) | 0),
- (lo = (lo + Math.imul(al1, bl8)) | 0),
- (mid = (mid + Math.imul(al1, bh8)) | 0),
- (mid = (mid + Math.imul(ah1, bl8)) | 0),
- (hi = (hi + Math.imul(ah1, bh8)) | 0),
- (lo = (lo + Math.imul(al0, bl9)) | 0),
- (mid = (mid + Math.imul(al0, bh9)) | 0),
- (mid = (mid + Math.imul(ah0, bl9)) | 0),
- (hi = (hi + Math.imul(ah0, bh9)) | 0);
- var w9 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0),
- (w9 &= 67108863),
- (lo = Math.imul(al9, bl1)),
- (mid = Math.imul(al9, bh1)),
- (mid = (mid + Math.imul(ah9, bl1)) | 0),
- (hi = Math.imul(ah9, bh1)),
- (lo = (lo + Math.imul(al8, bl2)) | 0),
- (mid = (mid + Math.imul(al8, bh2)) | 0),
- (mid = (mid + Math.imul(ah8, bl2)) | 0),
- (hi = (hi + Math.imul(ah8, bh2)) | 0),
- (lo = (lo + Math.imul(al7, bl3)) | 0),
- (mid = (mid + Math.imul(al7, bh3)) | 0),
- (mid = (mid + Math.imul(ah7, bl3)) | 0),
- (hi = (hi + Math.imul(ah7, bh3)) | 0),
- (lo = (lo + Math.imul(al6, bl4)) | 0),
- (mid = (mid + Math.imul(al6, bh4)) | 0),
- (mid = (mid + Math.imul(ah6, bl4)) | 0),
- (hi = (hi + Math.imul(ah6, bh4)) | 0),
- (lo = (lo + Math.imul(al5, bl5)) | 0),
- (mid = (mid + Math.imul(al5, bh5)) | 0),
- (mid = (mid + Math.imul(ah5, bl5)) | 0),
- (hi = (hi + Math.imul(ah5, bh5)) | 0),
- (lo = (lo + Math.imul(al4, bl6)) | 0),
- (mid = (mid + Math.imul(al4, bh6)) | 0),
- (mid = (mid + Math.imul(ah4, bl6)) | 0),
- (hi = (hi + Math.imul(ah4, bh6)) | 0),
- (lo = (lo + Math.imul(al3, bl7)) | 0),
- (mid = (mid + Math.imul(al3, bh7)) | 0),
- (mid = (mid + Math.imul(ah3, bl7)) | 0),
- (hi = (hi + Math.imul(ah3, bh7)) | 0),
- (lo = (lo + Math.imul(al2, bl8)) | 0),
- (mid = (mid + Math.imul(al2, bh8)) | 0),
- (mid = (mid + Math.imul(ah2, bl8)) | 0),
- (hi = (hi + Math.imul(ah2, bh8)) | 0),
- (lo = (lo + Math.imul(al1, bl9)) | 0),
- (mid = (mid + Math.imul(al1, bh9)) | 0),
- (mid = (mid + Math.imul(ah1, bl9)) | 0),
- (hi = (hi + Math.imul(ah1, bh9)) | 0);
- var w10 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0),
- (w10 &= 67108863),
- (lo = Math.imul(al9, bl2)),
- (mid = Math.imul(al9, bh2)),
- (mid = (mid + Math.imul(ah9, bl2)) | 0),
- (hi = Math.imul(ah9, bh2)),
- (lo = (lo + Math.imul(al8, bl3)) | 0),
- (mid = (mid + Math.imul(al8, bh3)) | 0),
- (mid = (mid + Math.imul(ah8, bl3)) | 0),
- (hi = (hi + Math.imul(ah8, bh3)) | 0),
- (lo = (lo + Math.imul(al7, bl4)) | 0),
- (mid = (mid + Math.imul(al7, bh4)) | 0),
- (mid = (mid + Math.imul(ah7, bl4)) | 0),
- (hi = (hi + Math.imul(ah7, bh4)) | 0),
- (lo = (lo + Math.imul(al6, bl5)) | 0),
- (mid = (mid + Math.imul(al6, bh5)) | 0),
- (mid = (mid + Math.imul(ah6, bl5)) | 0),
- (hi = (hi + Math.imul(ah6, bh5)) | 0),
- (lo = (lo + Math.imul(al5, bl6)) | 0),
- (mid = (mid + Math.imul(al5, bh6)) | 0),
- (mid = (mid + Math.imul(ah5, bl6)) | 0),
- (hi = (hi + Math.imul(ah5, bh6)) | 0),
- (lo = (lo + Math.imul(al4, bl7)) | 0),
- (mid = (mid + Math.imul(al4, bh7)) | 0),
- (mid = (mid + Math.imul(ah4, bl7)) | 0),
- (hi = (hi + Math.imul(ah4, bh7)) | 0),
- (lo = (lo + Math.imul(al3, bl8)) | 0),
- (mid = (mid + Math.imul(al3, bh8)) | 0),
- (mid = (mid + Math.imul(ah3, bl8)) | 0),
- (hi = (hi + Math.imul(ah3, bh8)) | 0),
- (lo = (lo + Math.imul(al2, bl9)) | 0),
- (mid = (mid + Math.imul(al2, bh9)) | 0),
- (mid = (mid + Math.imul(ah2, bl9)) | 0),
- (hi = (hi + Math.imul(ah2, bh9)) | 0);
- var w11 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0),
- (w11 &= 67108863),
- (lo = Math.imul(al9, bl3)),
- (mid = Math.imul(al9, bh3)),
- (mid = (mid + Math.imul(ah9, bl3)) | 0),
- (hi = Math.imul(ah9, bh3)),
- (lo = (lo + Math.imul(al8, bl4)) | 0),
- (mid = (mid + Math.imul(al8, bh4)) | 0),
- (mid = (mid + Math.imul(ah8, bl4)) | 0),
- (hi = (hi + Math.imul(ah8, bh4)) | 0),
- (lo = (lo + Math.imul(al7, bl5)) | 0),
- (mid = (mid + Math.imul(al7, bh5)) | 0),
- (mid = (mid + Math.imul(ah7, bl5)) | 0),
- (hi = (hi + Math.imul(ah7, bh5)) | 0),
- (lo = (lo + Math.imul(al6, bl6)) | 0),
- (mid = (mid + Math.imul(al6, bh6)) | 0),
- (mid = (mid + Math.imul(ah6, bl6)) | 0),
- (hi = (hi + Math.imul(ah6, bh6)) | 0),
- (lo = (lo + Math.imul(al5, bl7)) | 0),
- (mid = (mid + Math.imul(al5, bh7)) | 0),
- (mid = (mid + Math.imul(ah5, bl7)) | 0),
- (hi = (hi + Math.imul(ah5, bh7)) | 0),
- (lo = (lo + Math.imul(al4, bl8)) | 0),
- (mid = (mid + Math.imul(al4, bh8)) | 0),
- (mid = (mid + Math.imul(ah4, bl8)) | 0),
- (hi = (hi + Math.imul(ah4, bh8)) | 0),
- (lo = (lo + Math.imul(al3, bl9)) | 0),
- (mid = (mid + Math.imul(al3, bh9)) | 0),
- (mid = (mid + Math.imul(ah3, bl9)) | 0),
- (hi = (hi + Math.imul(ah3, bh9)) | 0);
- var w12 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0),
- (w12 &= 67108863),
- (lo = Math.imul(al9, bl4)),
- (mid = Math.imul(al9, bh4)),
- (mid = (mid + Math.imul(ah9, bl4)) | 0),
- (hi = Math.imul(ah9, bh4)),
- (lo = (lo + Math.imul(al8, bl5)) | 0),
- (mid = (mid + Math.imul(al8, bh5)) | 0),
- (mid = (mid + Math.imul(ah8, bl5)) | 0),
- (hi = (hi + Math.imul(ah8, bh5)) | 0),
- (lo = (lo + Math.imul(al7, bl6)) | 0),
- (mid = (mid + Math.imul(al7, bh6)) | 0),
- (mid = (mid + Math.imul(ah7, bl6)) | 0),
- (hi = (hi + Math.imul(ah7, bh6)) | 0),
- (lo = (lo + Math.imul(al6, bl7)) | 0),
- (mid = (mid + Math.imul(al6, bh7)) | 0),
- (mid = (mid + Math.imul(ah6, bl7)) | 0),
- (hi = (hi + Math.imul(ah6, bh7)) | 0),
- (lo = (lo + Math.imul(al5, bl8)) | 0),
- (mid = (mid + Math.imul(al5, bh8)) | 0),
- (mid = (mid + Math.imul(ah5, bl8)) | 0),
- (hi = (hi + Math.imul(ah5, bh8)) | 0),
- (lo = (lo + Math.imul(al4, bl9)) | 0),
- (mid = (mid + Math.imul(al4, bh9)) | 0),
- (mid = (mid + Math.imul(ah4, bl9)) | 0),
- (hi = (hi + Math.imul(ah4, bh9)) | 0);
- var w13 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0),
- (w13 &= 67108863),
- (lo = Math.imul(al9, bl5)),
- (mid = Math.imul(al9, bh5)),
- (mid = (mid + Math.imul(ah9, bl5)) | 0),
- (hi = Math.imul(ah9, bh5)),
- (lo = (lo + Math.imul(al8, bl6)) | 0),
- (mid = (mid + Math.imul(al8, bh6)) | 0),
- (mid = (mid + Math.imul(ah8, bl6)) | 0),
- (hi = (hi + Math.imul(ah8, bh6)) | 0),
- (lo = (lo + Math.imul(al7, bl7)) | 0),
- (mid = (mid + Math.imul(al7, bh7)) | 0),
- (mid = (mid + Math.imul(ah7, bl7)) | 0),
- (hi = (hi + Math.imul(ah7, bh7)) | 0),
- (lo = (lo + Math.imul(al6, bl8)) | 0),
- (mid = (mid + Math.imul(al6, bh8)) | 0),
- (mid = (mid + Math.imul(ah6, bl8)) | 0),
- (hi = (hi + Math.imul(ah6, bh8)) | 0),
- (lo = (lo + Math.imul(al5, bl9)) | 0),
- (mid = (mid + Math.imul(al5, bh9)) | 0),
- (mid = (mid + Math.imul(ah5, bl9)) | 0),
- (hi = (hi + Math.imul(ah5, bh9)) | 0);
- var w14 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0),
- (w14 &= 67108863),
- (lo = Math.imul(al9, bl6)),
- (mid = Math.imul(al9, bh6)),
- (mid = (mid + Math.imul(ah9, bl6)) | 0),
- (hi = Math.imul(ah9, bh6)),
- (lo = (lo + Math.imul(al8, bl7)) | 0),
- (mid = (mid + Math.imul(al8, bh7)) | 0),
- (mid = (mid + Math.imul(ah8, bl7)) | 0),
- (hi = (hi + Math.imul(ah8, bh7)) | 0),
- (lo = (lo + Math.imul(al7, bl8)) | 0),
- (mid = (mid + Math.imul(al7, bh8)) | 0),
- (mid = (mid + Math.imul(ah7, bl8)) | 0),
- (hi = (hi + Math.imul(ah7, bh8)) | 0),
- (lo = (lo + Math.imul(al6, bl9)) | 0),
- (mid = (mid + Math.imul(al6, bh9)) | 0),
- (mid = (mid + Math.imul(ah6, bl9)) | 0),
- (hi = (hi + Math.imul(ah6, bh9)) | 0);
- var w15 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0),
- (w15 &= 67108863),
- (lo = Math.imul(al9, bl7)),
- (mid = Math.imul(al9, bh7)),
- (mid = (mid + Math.imul(ah9, bl7)) | 0),
- (hi = Math.imul(ah9, bh7)),
- (lo = (lo + Math.imul(al8, bl8)) | 0),
- (mid = (mid + Math.imul(al8, bh8)) | 0),
- (mid = (mid + Math.imul(ah8, bl8)) | 0),
- (hi = (hi + Math.imul(ah8, bh8)) | 0),
- (lo = (lo + Math.imul(al7, bl9)) | 0),
- (mid = (mid + Math.imul(al7, bh9)) | 0),
- (mid = (mid + Math.imul(ah7, bl9)) | 0),
- (hi = (hi + Math.imul(ah7, bh9)) | 0);
- var w16 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0),
- (w16 &= 67108863),
- (lo = Math.imul(al9, bl8)),
- (mid = Math.imul(al9, bh8)),
- (mid = (mid + Math.imul(ah9, bl8)) | 0),
- (hi = Math.imul(ah9, bh8)),
- (lo = (lo + Math.imul(al8, bl9)) | 0),
- (mid = (mid + Math.imul(al8, bh9)) | 0),
- (mid = (mid + Math.imul(ah8, bl9)) | 0),
- (hi = (hi + Math.imul(ah8, bh9)) | 0);
- var w17 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0),
- (w17 &= 67108863),
- (lo = Math.imul(al9, bl9)),
- (mid = Math.imul(al9, bh9)),
- (mid = (mid + Math.imul(ah9, bl9)) | 0),
- (hi = Math.imul(ah9, bh9));
- var w18 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- return (
- (c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0),
- (w18 &= 67108863),
- (o[0] = w0),
- (o[1] = w1),
- (o[2] = w2),
- (o[3] = w3),
- (o[4] = w4),
- (o[5] = w5),
- (o[6] = w6),
- (o[7] = w7),
- (o[8] = w8),
- (o[9] = w9),
- (o[10] = w10),
- (o[11] = w11),
- (o[12] = w12),
- (o[13] = w13),
- (o[14] = w14),
- (o[15] = w15),
- (o[16] = w16),
- (o[17] = w17),
- (o[18] = w18),
- c !== 0 && ((o[19] = c), out.length++),
- out
- );
- };
- Math.imul || (comb10MulTo = smallMulTo);
- function bigMulTo(self2, num, out) {
- (out.negative = num.negative ^ self2.negative), (out.length = self2.length + num.length);
- for (var carry = 0, hncarry = 0, k = 0; k < out.length - 1; k++) {
- var ncarry = hncarry;
- hncarry = 0;
- for (
- var rword = carry & 67108863, maxJ = Math.min(k, num.length - 1), j = Math.max(0, k - self2.length + 1);
- j <= maxJ;
- j++
- ) {
- var i = k - j,
- a = self2.words[i] | 0,
- b = num.words[j] | 0,
- r = a * b,
- lo = r & 67108863;
- (ncarry = (ncarry + ((r / 67108864) | 0)) | 0),
- (lo = (lo + rword) | 0),
- (rword = lo & 67108863),
- (ncarry = (ncarry + (lo >>> 26)) | 0),
- (hncarry += ncarry >>> 26),
- (ncarry &= 67108863);
- }
- (out.words[k] = rword), (carry = ncarry), (ncarry = hncarry);
- }
- return carry !== 0 ? (out.words[k] = carry) : out.length--, out.strip();
- }
- function jumboMulTo(self2, num, out) {
- var fftm = new FFTM();
- return fftm.mulp(self2, num, out);
- }
- BN.prototype.mulTo = function (num, out) {
- var res,
- len = this.length + num.length;
- return (
- this.length === 10 && num.length === 10
- ? (res = comb10MulTo(this, num, out))
- : len < 63
- ? (res = smallMulTo(this, num, out))
- : len < 1024
- ? (res = bigMulTo(this, num, out))
- : (res = jumboMulTo(this, num, out)),
- res
- );
- };
- function FFTM(x, y) {
- (this.x = x), (this.y = y);
- }
- (FFTM.prototype.makeRBT = function (N) {
- for (var t = new Array(N), l = BN.prototype._countBits(N) - 1, i = 0; i < N; i++) t[i] = this.revBin(i, l, N);
- return t;
- }),
- (FFTM.prototype.revBin = function (x, l, N) {
- if (x === 0 || x === N - 1) return x;
- for (var rb = 0, i = 0; i < l; i++) (rb |= (x & 1) << (l - i - 1)), (x >>= 1);
- return rb;
- }),
- (FFTM.prototype.permute = function (rbt, rws, iws, rtws, itws, N) {
- for (var i = 0; i < N; i++) (rtws[i] = rws[rbt[i]]), (itws[i] = iws[rbt[i]]);
- }),
- (FFTM.prototype.transform = function (rws, iws, rtws, itws, N, rbt) {
- this.permute(rbt, rws, iws, rtws, itws, N);
- for (var s = 1; s < N; s <<= 1)
- for (
- var l = s << 1, rtwdf = Math.cos((2 * Math.PI) / l), itwdf = Math.sin((2 * Math.PI) / l), p = 0;
- p < N;
- p += l
- )
- for (var rtwdf_ = rtwdf, itwdf_ = itwdf, j = 0; j < s; j++) {
- var re = rtws[p + j],
- ie = itws[p + j],
- ro = rtws[p + j + s],
- io = itws[p + j + s],
- rx = rtwdf_ * ro - itwdf_ * io;
- (io = rtwdf_ * io + itwdf_ * ro),
- (ro = rx),
- (rtws[p + j] = re + ro),
- (itws[p + j] = ie + io),
- (rtws[p + j + s] = re - ro),
- (itws[p + j + s] = ie - io),
- j !== l &&
- ((rx = rtwdf * rtwdf_ - itwdf * itwdf_), (itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_), (rtwdf_ = rx));
- }
- }),
- (FFTM.prototype.guessLen13b = function (n, m) {
- var N = Math.max(m, n) | 1,
- odd = N & 1,
- i = 0;
- for (N = (N / 2) | 0; N; N = N >>> 1) i++;
- return 1 << (i + 1 + odd);
- }),
- (FFTM.prototype.conjugate = function (rws, iws, N) {
- if (!(N <= 1))
- for (var i = 0; i < N / 2; i++) {
- var t = rws[i];
- (rws[i] = rws[N - i - 1]),
- (rws[N - i - 1] = t),
- (t = iws[i]),
- (iws[i] = -iws[N - i - 1]),
- (iws[N - i - 1] = -t);
- }
- }),
- (FFTM.prototype.normalize13b = function (ws, N) {
- for (var carry = 0, i = 0; i < N / 2; i++) {
- var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry;
- (ws[i] = w & 67108863), w < 67108864 ? (carry = 0) : (carry = (w / 67108864) | 0);
- }
- return ws;
- }),
- (FFTM.prototype.convert13b = function (ws, len, rws, N) {
- for (var carry = 0, i = 0; i < len; i++)
- (carry = carry + (ws[i] | 0)),
- (rws[2 * i] = carry & 8191),
- (carry = carry >>> 13),
- (rws[2 * i + 1] = carry & 8191),
- (carry = carry >>> 13);
- for (i = 2 * len; i < N; ++i) rws[i] = 0;
- assert(carry === 0), assert((carry & -8192) === 0);
- }),
- (FFTM.prototype.stub = function (N) {
- for (var ph = new Array(N), i = 0; i < N; i++) ph[i] = 0;
- return ph;
- }),
- (FFTM.prototype.mulp = function (x, y, out) {
- var N = 2 * this.guessLen13b(x.length, y.length),
- rbt = this.makeRBT(N),
- _ = this.stub(N),
- rws = new Array(N),
- rwst = new Array(N),
- iwst = new Array(N),
- nrws = new Array(N),
- nrwst = new Array(N),
- niwst = new Array(N),
- rmws = out.words;
- (rmws.length = N),
- this.convert13b(x.words, x.length, rws, N),
- this.convert13b(y.words, y.length, nrws, N),
- this.transform(rws, _, rwst, iwst, N, rbt),
- this.transform(nrws, _, nrwst, niwst, N, rbt);
- for (var i = 0; i < N; i++) {
- var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
- (iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]), (rwst[i] = rx);
- }
- return (
- this.conjugate(rwst, iwst, N),
- this.transform(rwst, iwst, rmws, _, N, rbt),
- this.conjugate(rmws, _, N),
- this.normalize13b(rmws, N),
- (out.negative = x.negative ^ y.negative),
- (out.length = x.length + y.length),
- out.strip()
- );
- }),
- (BN.prototype.mul = function (num) {
- var out = new BN(null);
- return (out.words = new Array(this.length + num.length)), this.mulTo(num, out);
- }),
- (BN.prototype.mulf = function (num) {
- var out = new BN(null);
- return (out.words = new Array(this.length + num.length)), jumboMulTo(this, num, out);
- }),
- (BN.prototype.imul = function (num) {
- return this.clone().mulTo(num, this);
- }),
- (BN.prototype.imuln = function (num) {
- assert(typeof num == "number"), assert(num < 67108864);
- for (var carry = 0, i = 0; i < this.length; i++) {
- var w = (this.words[i] | 0) * num,
- lo = (w & 67108863) + (carry & 67108863);
- (carry >>= 26), (carry += (w / 67108864) | 0), (carry += lo >>> 26), (this.words[i] = lo & 67108863);
- }
- return carry !== 0 && ((this.words[i] = carry), this.length++), this;
- }),
- (BN.prototype.muln = function (num) {
- return this.clone().imuln(num);
- }),
- (BN.prototype.sqr = function () {
- return this.mul(this);
- }),
- (BN.prototype.isqr = function () {
- return this.imul(this.clone());
- }),
- (BN.prototype.pow = function (num) {
- var w = toBitArray(num);
- if (w.length === 0) return new BN(1);
- for (var res = this, i = 0; i < w.length && w[i] === 0; i++, res = res.sqr());
- if (++i < w.length) for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) w[i] !== 0 && (res = res.mul(q));
- return res;
- }),
- (BN.prototype.iushln = function (bits) {
- assert(typeof bits == "number" && bits >= 0);
- var r = bits % 26,
- s = (bits - r) / 26,
- carryMask = (67108863 >>> (26 - r)) << (26 - r),
- i;
- if (r !== 0) {
- var carry = 0;
- for (i = 0; i < this.length; i++) {
- var newCarry = this.words[i] & carryMask,
- c = ((this.words[i] | 0) - newCarry) << r;
- (this.words[i] = c | carry), (carry = newCarry >>> (26 - r));
- }
- carry && ((this.words[i] = carry), this.length++);
- }
- if (s !== 0) {
- for (i = this.length - 1; i >= 0; i--) this.words[i + s] = this.words[i];
- for (i = 0; i < s; i++) this.words[i] = 0;
- this.length += s;
- }
- return this.strip();
- }),
- (BN.prototype.ishln = function (bits) {
- return assert(this.negative === 0), this.iushln(bits);
- }),
- (BN.prototype.iushrn = function (bits, hint, extended) {
- assert(typeof bits == "number" && bits >= 0);
- var h;
- hint ? (h = (hint - (hint % 26)) / 26) : (h = 0);
- var r = bits % 26,
- s = Math.min((bits - r) / 26, this.length),
- mask = 67108863 ^ ((67108863 >>> r) << r),
- maskedWords = extended;
- if (((h -= s), (h = Math.max(0, h)), maskedWords)) {
- for (var i = 0; i < s; i++) maskedWords.words[i] = this.words[i];
- maskedWords.length = s;
- }
- if (s !== 0)
- if (this.length > s) for (this.length -= s, i = 0; i < this.length; i++) this.words[i] = this.words[i + s];
- else (this.words[0] = 0), (this.length = 1);
- var carry = 0;
- for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
- var word = this.words[i] | 0;
- (this.words[i] = (carry << (26 - r)) | (word >>> r)), (carry = word & mask);
- }
- return (
- maskedWords && carry !== 0 && (maskedWords.words[maskedWords.length++] = carry),
- this.length === 0 && ((this.words[0] = 0), (this.length = 1)),
- this.strip()
- );
- }),
- (BN.prototype.ishrn = function (bits, hint, extended) {
- return assert(this.negative === 0), this.iushrn(bits, hint, extended);
- }),
- (BN.prototype.shln = function (bits) {
- return this.clone().ishln(bits);
- }),
- (BN.prototype.ushln = function (bits) {
- return this.clone().iushln(bits);
- }),
- (BN.prototype.shrn = function (bits) {
- return this.clone().ishrn(bits);
- }),
- (BN.prototype.ushrn = function (bits) {
- return this.clone().iushrn(bits);
- }),
- (BN.prototype.testn = function (bit) {
- assert(typeof bit == "number" && bit >= 0);
- var r = bit % 26,
- s = (bit - r) / 26,
- q = 1 << r;
- if (this.length <= s) return !1;
- var w = this.words[s];
- return !!(w & q);
- }),
- (BN.prototype.imaskn = function (bits) {
- assert(typeof bits == "number" && bits >= 0);
- var r = bits % 26,
- s = (bits - r) / 26;
- if ((assert(this.negative === 0, "imaskn works only with positive numbers"), this.length <= s)) return this;
- if ((r !== 0 && s++, (this.length = Math.min(s, this.length)), r !== 0)) {
- var mask = 67108863 ^ ((67108863 >>> r) << r);
- this.words[this.length - 1] &= mask;
- }
- return this.strip();
- }),
- (BN.prototype.maskn = function (bits) {
- return this.clone().imaskn(bits);
- }),
- (BN.prototype.iaddn = function (num) {
- return (
- assert(typeof num == "number"),
- assert(num < 67108864),
- num < 0
- ? this.isubn(-num)
- : this.negative !== 0
- ? this.length === 1 && (this.words[0] | 0) < num
- ? ((this.words[0] = num - (this.words[0] | 0)), (this.negative = 0), this)
- : ((this.negative = 0), this.isubn(num), (this.negative = 1), this)
- : this._iaddn(num)
- );
- }),
- (BN.prototype._iaddn = function (num) {
- this.words[0] += num;
- for (var i = 0; i < this.length && this.words[i] >= 67108864; i++)
- (this.words[i] -= 67108864), i === this.length - 1 ? (this.words[i + 1] = 1) : this.words[i + 1]++;
- return (this.length = Math.max(this.length, i + 1)), this;
- }),
- (BN.prototype.isubn = function (num) {
- if ((assert(typeof num == "number"), assert(num < 67108864), num < 0)) return this.iaddn(-num);
- if (this.negative !== 0) return (this.negative = 0), this.iaddn(num), (this.negative = 1), this;
- if (((this.words[0] -= num), this.length === 1 && this.words[0] < 0))
- (this.words[0] = -this.words[0]), (this.negative = 1);
- else
- for (var i = 0; i < this.length && this.words[i] < 0; i++)
- (this.words[i] += 67108864), (this.words[i + 1] -= 1);
- return this.strip();
- }),
- (BN.prototype.addn = function (num) {
- return this.clone().iaddn(num);
- }),
- (BN.prototype.subn = function (num) {
- return this.clone().isubn(num);
- }),
- (BN.prototype.iabs = function () {
- return (this.negative = 0), this;
- }),
- (BN.prototype.abs = function () {
- return this.clone().iabs();
- }),
- (BN.prototype._ishlnsubmul = function (num, mul, shift) {
- var len = num.length + shift,
- i;
- this._expand(len);
- var w,
- carry = 0;
- for (i = 0; i < num.length; i++) {
- w = (this.words[i + shift] | 0) + carry;
- var right = (num.words[i] | 0) * mul;
- (w -= right & 67108863),
- (carry = (w >> 26) - ((right / 67108864) | 0)),
- (this.words[i + shift] = w & 67108863);
- }
- for (; i < this.length - shift; i++)
- (w = (this.words[i + shift] | 0) + carry), (carry = w >> 26), (this.words[i + shift] = w & 67108863);
- if (carry === 0) return this.strip();
- for (assert(carry === -1), carry = 0, i = 0; i < this.length; i++)
- (w = -(this.words[i] | 0) + carry), (carry = w >> 26), (this.words[i] = w & 67108863);
- return (this.negative = 1), this.strip();
- }),
- (BN.prototype._wordDiv = function (num, mode) {
- var shift = this.length - num.length,
- a = this.clone(),
- b = num,
- bhi = b.words[b.length - 1] | 0,
- bhiBits = this._countBits(bhi);
- (shift = 26 - bhiBits),
- shift !== 0 && ((b = b.ushln(shift)), a.iushln(shift), (bhi = b.words[b.length - 1] | 0));
- var m = a.length - b.length,
- q;
- if (mode !== "mod") {
- (q = new BN(null)), (q.length = m + 1), (q.words = new Array(q.length));
- for (var i = 0; i < q.length; i++) q.words[i] = 0;
- }
- var diff = a.clone()._ishlnsubmul(b, 1, m);
- diff.negative === 0 && ((a = diff), q && (q.words[m] = 1));
- for (var j = m - 1; j >= 0; j--) {
- var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0);
- for (qj = Math.min((qj / bhi) | 0, 67108863), a._ishlnsubmul(b, qj, j); a.negative !== 0; )
- qj--, (a.negative = 0), a._ishlnsubmul(b, 1, j), a.isZero() || (a.negative ^= 1);
- q && (q.words[j] = qj);
- }
- return (
- q && q.strip(),
- a.strip(),
- mode !== "div" && shift !== 0 && a.iushrn(shift),
- {
- div: q || null,
- mod: a,
- }
- );
- }),
- (BN.prototype.divmod = function (num, mode, positive) {
- if ((assert(!num.isZero()), this.isZero()))
- return {
- div: new BN(0),
- mod: new BN(0),
- };
- var div, mod, res;
- return this.negative !== 0 && num.negative === 0
- ? ((res = this.neg().divmod(num, mode)),
- mode !== "mod" && (div = res.div.neg()),
- mode !== "div" && ((mod = res.mod.neg()), positive && mod.negative !== 0 && mod.iadd(num)),
- {
- div,
- mod,
- })
- : this.negative === 0 && num.negative !== 0
- ? ((res = this.divmod(num.neg(), mode)),
- mode !== "mod" && (div = res.div.neg()),
- {
- div,
- mod: res.mod,
- })
- : (this.negative & num.negative) !== 0
- ? ((res = this.neg().divmod(num.neg(), mode)),
- mode !== "div" && ((mod = res.mod.neg()), positive && mod.negative !== 0 && mod.isub(num)),
- {
- div: res.div,
- mod,
- })
- : num.length > this.length || this.cmp(num) < 0
- ? {
- div: new BN(0),
- mod: this,
- }
- : num.length === 1
- ? mode === "div"
- ? {
- div: this.divn(num.words[0]),
- mod: null,
- }
- : mode === "mod"
- ? {
- div: null,
- mod: new BN(this.modn(num.words[0])),
- }
- : {
- div: this.divn(num.words[0]),
- mod: new BN(this.modn(num.words[0])),
- }
- : this._wordDiv(num, mode);
- }),
- (BN.prototype.div = function (num) {
- return this.divmod(num, "div", !1).div;
- }),
- (BN.prototype.mod = function (num) {
- return this.divmod(num, "mod", !1).mod;
- }),
- (BN.prototype.umod = function (num) {
- return this.divmod(num, "mod", !0).mod;
- }),
- (BN.prototype.divRound = function (num) {
- var dm = this.divmod(num);
- if (dm.mod.isZero()) return dm.div;
- var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod,
- half = num.ushrn(1),
- r2 = num.andln(1),
- cmp = mod.cmp(half);
- return cmp < 0 || (r2 === 1 && cmp === 0)
- ? dm.div
- : dm.div.negative !== 0
- ? dm.div.isubn(1)
- : dm.div.iaddn(1);
- }),
- (BN.prototype.modn = function (num) {
- assert(num <= 67108863);
- for (var p = (1 << 26) % num, acc = 0, i = this.length - 1; i >= 0; i--)
- acc = (p * acc + (this.words[i] | 0)) % num;
- return acc;
- }),
- (BN.prototype.idivn = function (num) {
- assert(num <= 67108863);
- for (var carry = 0, i = this.length - 1; i >= 0; i--) {
- var w = (this.words[i] | 0) + carry * 67108864;
- (this.words[i] = (w / num) | 0), (carry = w % num);
- }
- return this.strip();
- }),
- (BN.prototype.divn = function (num) {
- return this.clone().idivn(num);
- }),
- (BN.prototype.egcd = function (p) {
- assert(p.negative === 0), assert(!p.isZero());
- var x = this,
- y = p.clone();
- x.negative !== 0 ? (x = x.umod(p)) : (x = x.clone());
- for (var A = new BN(1), B = new BN(0), C = new BN(0), D = new BN(1), g = 0; x.isEven() && y.isEven(); )
- x.iushrn(1), y.iushrn(1), ++g;
- for (var yp = y.clone(), xp = x.clone(); !x.isZero(); ) {
- for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
- if (i > 0)
- for (x.iushrn(i); i-- > 0; )
- (A.isOdd() || B.isOdd()) && (A.iadd(yp), B.isub(xp)), A.iushrn(1), B.iushrn(1);
- for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
- if (j > 0)
- for (y.iushrn(j); j-- > 0; )
- (C.isOdd() || D.isOdd()) && (C.iadd(yp), D.isub(xp)), C.iushrn(1), D.iushrn(1);
- x.cmp(y) >= 0 ? (x.isub(y), A.isub(C), B.isub(D)) : (y.isub(x), C.isub(A), D.isub(B));
- }
- return {
- a: C,
- b: D,
- gcd: y.iushln(g),
- };
- }),
- (BN.prototype._invmp = function (p) {
- assert(p.negative === 0), assert(!p.isZero());
- var a = this,
- b = p.clone();
- a.negative !== 0 ? (a = a.umod(p)) : (a = a.clone());
- for (var x1 = new BN(1), x2 = new BN(0), delta = b.clone(); a.cmpn(1) > 0 && b.cmpn(1) > 0; ) {
- for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
- if (i > 0) for (a.iushrn(i); i-- > 0; ) x1.isOdd() && x1.iadd(delta), x1.iushrn(1);
- for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
- if (j > 0) for (b.iushrn(j); j-- > 0; ) x2.isOdd() && x2.iadd(delta), x2.iushrn(1);
- a.cmp(b) >= 0 ? (a.isub(b), x1.isub(x2)) : (b.isub(a), x2.isub(x1));
- }
- var res;
- return a.cmpn(1) === 0 ? (res = x1) : (res = x2), res.cmpn(0) < 0 && res.iadd(p), res;
- }),
- (BN.prototype.gcd = function (num) {
- if (this.isZero()) return num.abs();
- if (num.isZero()) return this.abs();
- var a = this.clone(),
- b = num.clone();
- (a.negative = 0), (b.negative = 0);
- for (var shift = 0; a.isEven() && b.isEven(); shift++) a.iushrn(1), b.iushrn(1);
- do {
- for (; a.isEven(); ) a.iushrn(1);
- for (; b.isEven(); ) b.iushrn(1);
- var r = a.cmp(b);
- if (r < 0) {
- var t = a;
- (a = b), (b = t);
- } else if (r === 0 || b.cmpn(1) === 0) break;
- a.isub(b);
- } while (!0);
- return b.iushln(shift);
- }),
- (BN.prototype.invm = function (num) {
- return this.egcd(num).a.umod(num);
- }),
- (BN.prototype.isEven = function () {
- return (this.words[0] & 1) === 0;
- }),
- (BN.prototype.isOdd = function () {
- return (this.words[0] & 1) === 1;
- }),
- (BN.prototype.andln = function (num) {
- return this.words[0] & num;
- }),
- (BN.prototype.bincn = function (bit) {
- assert(typeof bit == "number");
- var r = bit % 26,
- s = (bit - r) / 26,
- q = 1 << r;
- if (this.length <= s) return this._expand(s + 1), (this.words[s] |= q), this;
- for (var carry = q, i = s; carry !== 0 && i < this.length; i++) {
- var w = this.words[i] | 0;
- (w += carry), (carry = w >>> 26), (w &= 67108863), (this.words[i] = w);
- }
- return carry !== 0 && ((this.words[i] = carry), this.length++), this;
- }),
- (BN.prototype.isZero = function () {
- return this.length === 1 && this.words[0] === 0;
- }),
- (BN.prototype.cmpn = function (num) {
- var negative = num < 0;
- if (this.negative !== 0 && !negative) return -1;
- if (this.negative === 0 && negative) return 1;
- this.strip();
- var res;
- if (this.length > 1) res = 1;
- else {
- negative && (num = -num), assert(num <= 67108863, "Number is too big");
- var w = this.words[0] | 0;
- res = w === num ? 0 : w < num ? -1 : 1;
- }
- return this.negative !== 0 ? -res | 0 : res;
- }),
- (BN.prototype.cmp = function (num) {
- if (this.negative !== 0 && num.negative === 0) return -1;
- if (this.negative === 0 && num.negative !== 0) return 1;
- var res = this.ucmp(num);
- return this.negative !== 0 ? -res | 0 : res;
- }),
- (BN.prototype.ucmp = function (num) {
- if (this.length > num.length) return 1;
- if (this.length < num.length) return -1;
- for (var res = 0, i = this.length - 1; i >= 0; i--) {
- var a = this.words[i] | 0,
- b = num.words[i] | 0;
- if (a !== b) {
- a < b ? (res = -1) : a > b && (res = 1);
- break;
- }
- }
- return res;
- }),
- (BN.prototype.gtn = function (num) {
- return this.cmpn(num) === 1;
- }),
- (BN.prototype.gt = function (num) {
- return this.cmp(num) === 1;
- }),
- (BN.prototype.gten = function (num) {
- return this.cmpn(num) >= 0;
- }),
- (BN.prototype.gte = function (num) {
- return this.cmp(num) >= 0;
- }),
- (BN.prototype.ltn = function (num) {
- return this.cmpn(num) === -1;
- }),
- (BN.prototype.lt = function (num) {
- return this.cmp(num) === -1;
- }),
- (BN.prototype.lten = function (num) {
- return this.cmpn(num) <= 0;
- }),
- (BN.prototype.lte = function (num) {
- return this.cmp(num) <= 0;
- }),
- (BN.prototype.eqn = function (num) {
- return this.cmpn(num) === 0;
- }),
- (BN.prototype.eq = function (num) {
- return this.cmp(num) === 0;
- }),
- (BN.red = function (num) {
- return new Red(num);
- }),
- (BN.prototype.toRed = function (ctx) {
- return (
- assert(!this.red, "Already a number in reduction context"),
- assert(this.negative === 0, "red works only with positives"),
- ctx.convertTo(this)._forceRed(ctx)
- );
- }),
- (BN.prototype.fromRed = function () {
- return assert(this.red, "fromRed works only with numbers in reduction context"), this.red.convertFrom(this);
- }),
- (BN.prototype._forceRed = function (ctx) {
- return (this.red = ctx), this;
- }),
- (BN.prototype.forceRed = function (ctx) {
- return assert(!this.red, "Already a number in reduction context"), this._forceRed(ctx);
- }),
- (BN.prototype.redAdd = function (num) {
- return assert(this.red, "redAdd works only with red numbers"), this.red.add(this, num);
- }),
- (BN.prototype.redIAdd = function (num) {
- return assert(this.red, "redIAdd works only with red numbers"), this.red.iadd(this, num);
- }),
- (BN.prototype.redSub = function (num) {
- return assert(this.red, "redSub works only with red numbers"), this.red.sub(this, num);
- }),
- (BN.prototype.redISub = function (num) {
- return assert(this.red, "redISub works only with red numbers"), this.red.isub(this, num);
- }),
- (BN.prototype.redShl = function (num) {
- return assert(this.red, "redShl works only with red numbers"), this.red.shl(this, num);
- }),
- (BN.prototype.redMul = function (num) {
- return (
- assert(this.red, "redMul works only with red numbers"),
- this.red._verify2(this, num),
- this.red.mul(this, num)
- );
- }),
- (BN.prototype.redIMul = function (num) {
- return (
- assert(this.red, "redMul works only with red numbers"),
- this.red._verify2(this, num),
- this.red.imul(this, num)
- );
- }),
- (BN.prototype.redSqr = function () {
- return assert(this.red, "redSqr works only with red numbers"), this.red._verify1(this), this.red.sqr(this);
- }),
- (BN.prototype.redISqr = function () {
- return assert(this.red, "redISqr works only with red numbers"), this.red._verify1(this), this.red.isqr(this);
- }),
- (BN.prototype.redSqrt = function () {
- return assert(this.red, "redSqrt works only with red numbers"), this.red._verify1(this), this.red.sqrt(this);
- }),
- (BN.prototype.redInvm = function () {
- return assert(this.red, "redInvm works only with red numbers"), this.red._verify1(this), this.red.invm(this);
- }),
- (BN.prototype.redNeg = function () {
- return assert(this.red, "redNeg works only with red numbers"), this.red._verify1(this), this.red.neg(this);
- }),
- (BN.prototype.redPow = function (num) {
- return assert(this.red && !num.red, "redPow(normalNum)"), this.red._verify1(this), this.red.pow(this, num);
- });
- var primes = {
- k256: null,
- p224: null,
- p192: null,
- p25519: null,
- };
- function MPrime(name, p) {
- (this.name = name),
- (this.p = new BN(p, 16)),
- (this.n = this.p.bitLength()),
- (this.k = new BN(1).iushln(this.n).isub(this.p)),
- (this.tmp = this._tmp());
- }
- (MPrime.prototype._tmp = function () {
- var tmp = new BN(null);
- return (tmp.words = new Array(Math.ceil(this.n / 13))), tmp;
- }),
- (MPrime.prototype.ireduce = function (num) {
- var r = num,
- rlen;
- do this.split(r, this.tmp), (r = this.imulK(r)), (r = r.iadd(this.tmp)), (rlen = r.bitLength());
- while (rlen > this.n);
- var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
- return (
- cmp === 0
- ? ((r.words[0] = 0), (r.length = 1))
- : cmp > 0
- ? r.isub(this.p)
- : r.strip !== void 0
- ? r.strip()
- : r._strip(),
- r
- );
- }),
- (MPrime.prototype.split = function (input, out) {
- input.iushrn(this.n, 0, out);
- }),
- (MPrime.prototype.imulK = function (num) {
- return num.imul(this.k);
- });
- function K256() {
- MPrime.call(this, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f");
- }
- inherits(K256, MPrime),
- (K256.prototype.split = function (input, output) {
- for (var mask = 4194303, outLen = Math.min(input.length, 9), i = 0; i < outLen; i++)
- output.words[i] = input.words[i];
- if (((output.length = outLen), input.length <= 9)) {
- (input.words[0] = 0), (input.length = 1);
- return;
- }
- var prev = input.words[9];
- for (output.words[output.length++] = prev & mask, i = 10; i < input.length; i++) {
- var next = input.words[i] | 0;
- (input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22)), (prev = next);
- }
- (prev >>>= 22),
- (input.words[i - 10] = prev),
- prev === 0 && input.length > 10 ? (input.length -= 10) : (input.length -= 9);
- }),
- (K256.prototype.imulK = function (num) {
- (num.words[num.length] = 0), (num.words[num.length + 1] = 0), (num.length += 2);
- for (var lo = 0, i = 0; i < num.length; i++) {
- var w = num.words[i] | 0;
- (lo += w * 977), (num.words[i] = lo & 67108863), (lo = w * 64 + ((lo / 67108864) | 0));
- }
- return (
- num.words[num.length - 1] === 0 && (num.length--, num.words[num.length - 1] === 0 && num.length--), num
- );
- });
- function P224() {
- MPrime.call(this, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001");
- }
- inherits(P224, MPrime);
- function P192() {
- MPrime.call(this, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff");
- }
- inherits(P192, MPrime);
- function P25519() {
- MPrime.call(this, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed");
- }
- inherits(P25519, MPrime),
- (P25519.prototype.imulK = function (num) {
- for (var carry = 0, i = 0; i < num.length; i++) {
- var hi = (num.words[i] | 0) * 19 + carry,
- lo = hi & 67108863;
- (hi >>>= 26), (num.words[i] = lo), (carry = hi);
- }
- return carry !== 0 && (num.words[num.length++] = carry), num;
- }),
- (BN._prime = function (name) {
- if (primes[name]) return primes[name];
- var prime2;
- if (name === "k256") prime2 = new K256();
- else if (name === "p224") prime2 = new P224();
- else if (name === "p192") prime2 = new P192();
- else if (name === "p25519") prime2 = new P25519();
- else throw new Error("Unknown prime " + name);
- return (primes[name] = prime2), prime2;
- });
- function Red(m) {
- if (typeof m == "string") {
- var prime = BN._prime(m);
- (this.m = prime.p), (this.prime = prime);
- } else assert(m.gtn(1), "modulus must be greater than 1"), (this.m = m), (this.prime = null);
- }
- (Red.prototype._verify1 = function (a) {
- assert(a.negative === 0, "red works only with positives"), assert(a.red, "red works only with red numbers");
- }),
- (Red.prototype._verify2 = function (a, b) {
- assert((a.negative | b.negative) === 0, "red works only with positives"),
- assert(a.red && a.red === b.red, "red works only with red numbers");
- }),
- (Red.prototype.imod = function (a) {
- return this.prime ? this.prime.ireduce(a)._forceRed(this) : a.umod(this.m)._forceRed(this);
- }),
- (Red.prototype.neg = function (a) {
- return a.isZero() ? a.clone() : this.m.sub(a)._forceRed(this);
- }),
- (Red.prototype.add = function (a, b) {
- this._verify2(a, b);
- var res = a.add(b);
- return res.cmp(this.m) >= 0 && res.isub(this.m), res._forceRed(this);
- }),
- (Red.prototype.iadd = function (a, b) {
- this._verify2(a, b);
- var res = a.iadd(b);
- return res.cmp(this.m) >= 0 && res.isub(this.m), res;
- }),
- (Red.prototype.sub = function (a, b) {
- this._verify2(a, b);
- var res = a.sub(b);
- return res.cmpn(0) < 0 && res.iadd(this.m), res._forceRed(this);
- }),
- (Red.prototype.isub = function (a, b) {
- this._verify2(a, b);
- var res = a.isub(b);
- return res.cmpn(0) < 0 && res.iadd(this.m), res;
- }),
- (Red.prototype.shl = function (a, num) {
- return this._verify1(a), this.imod(a.ushln(num));
- }),
- (Red.prototype.imul = function (a, b) {
- return this._verify2(a, b), this.imod(a.imul(b));
- }),
- (Red.prototype.mul = function (a, b) {
- return this._verify2(a, b), this.imod(a.mul(b));
- }),
- (Red.prototype.isqr = function (a) {
- return this.imul(a, a.clone());
- }),
- (Red.prototype.sqr = function (a) {
- return this.mul(a, a);
- }),
- (Red.prototype.sqrt = function (a) {
- if (a.isZero()) return a.clone();
- var mod3 = this.m.andln(3);
- if ((assert(mod3 % 2 === 1), mod3 === 3)) {
- var pow = this.m.add(new BN(1)).iushrn(2);
- return this.pow(a, pow);
- }
- for (var q = this.m.subn(1), s = 0; !q.isZero() && q.andln(1) === 0; ) s++, q.iushrn(1);
- assert(!q.isZero());
- var one = new BN(1).toRed(this),
- nOne = one.redNeg(),
- lpow = this.m.subn(1).iushrn(1),
- z = this.m.bitLength();
- for (z = new BN(2 * z * z).toRed(this); this.pow(z, lpow).cmp(nOne) !== 0; ) z.redIAdd(nOne);
- for (
- var c = this.pow(z, q), r = this.pow(a, q.addn(1).iushrn(1)), t = this.pow(a, q), m = s;
- t.cmp(one) !== 0;
-
- ) {
- for (var tmp = t, i = 0; tmp.cmp(one) !== 0; i++) tmp = tmp.redSqr();
- assert(i < m);
- var b = this.pow(c, new BN(1).iushln(m - i - 1));
- (r = r.redMul(b)), (c = b.redSqr()), (t = t.redMul(c)), (m = i);
- }
- return r;
- }),
- (Red.prototype.invm = function (a) {
- var inv = a._invmp(this.m);
- return inv.negative !== 0 ? ((inv.negative = 0), this.imod(inv).redNeg()) : this.imod(inv);
- }),
- (Red.prototype.pow = function (a, num) {
- if (num.isZero()) return new BN(1).toRed(this);
- if (num.cmpn(1) === 0) return a.clone();
- var windowSize = 4,
- wnd = new Array(1 << windowSize);
- (wnd[0] = new BN(1).toRed(this)), (wnd[1] = a);
- for (var i = 2; i < wnd.length; i++) wnd[i] = this.mul(wnd[i - 1], a);
- var res = wnd[0],
- current = 0,
- currentLen = 0,
- start = num.bitLength() % 26;
- for (start === 0 && (start = 26), i = num.length - 1; i >= 0; i--) {
- for (var word = num.words[i], j = start - 1; j >= 0; j--) {
- var bit = (word >> j) & 1;
- if ((res !== wnd[0] && (res = this.sqr(res)), bit === 0 && current === 0)) {
- currentLen = 0;
- continue;
- }
- (current <<= 1),
- (current |= bit),
- currentLen++,
- !(currentLen !== windowSize && (i !== 0 || j !== 0)) &&
- ((res = this.mul(res, wnd[current])), (currentLen = 0), (current = 0));
- }
- start = 26;
- }
- return res;
- }),
- (Red.prototype.convertTo = function (num) {
- var r = num.umod(this.m);
- return r === num ? r.clone() : r;
- }),
- (Red.prototype.convertFrom = function (num) {
- var res = num.clone();
- return (res.red = null), res;
- }),
- (BN.mont = function (num) {
- return new Mont(num);
- });
- function Mont(m) {
- Red.call(this, m),
- (this.shift = this.m.bitLength()),
- this.shift % 26 !== 0 && (this.shift += 26 - (this.shift % 26)),
- (this.r = new BN(1).iushln(this.shift)),
- (this.r2 = this.imod(this.r.sqr())),
- (this.rinv = this.r._invmp(this.m)),
- (this.minv = this.rinv.mul(this.r).isubn(1).div(this.m)),
- (this.minv = this.minv.umod(this.r)),
- (this.minv = this.r.sub(this.minv));
- }
- inherits(Mont, Red),
- (Mont.prototype.convertTo = function (num) {
- return this.imod(num.ushln(this.shift));
- }),
- (Mont.prototype.convertFrom = function (num) {
- var r = this.imod(num.mul(this.rinv));
- return (r.red = null), r;
- }),
- (Mont.prototype.imul = function (a, b) {
- if (a.isZero() || b.isZero()) return (a.words[0] = 0), (a.length = 1), a;
- var t = a.imul(b),
- c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),
- u = t.isub(c).iushrn(this.shift),
- res = u;
- return (
- u.cmp(this.m) >= 0 ? (res = u.isub(this.m)) : u.cmpn(0) < 0 && (res = u.iadd(this.m)), res._forceRed(this)
- );
- }),
- (Mont.prototype.mul = function (a, b) {
- if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
- var t = a.mul(b),
- c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),
- u = t.isub(c).iushrn(this.shift),
- res = u;
- return (
- u.cmp(this.m) >= 0 ? (res = u.isub(this.m)) : u.cmpn(0) < 0 && (res = u.iadd(this.m)), res._forceRed(this)
- );
- }),
- (Mont.prototype.invm = function (a) {
- var res = this.imod(a._invmp(this.m).mul(this.r2));
- return res._forceRed(this);
- });
- })(typeof module > "u" || module, exports);
- },
-});
+var require_bn4 = require_bn;
// node_modules/minimalistic-crypto-utils/lib/utils.js
var require_utils2 = __commonJS({
@@ -11920,6 +5893,7 @@ var require_base = __commonJS({
: ((this._maxwellTrick = !0), (this.redN = this.n.toRed(this.red)));
}
module.exports = BaseCurve;
+ BaseCurve.prototype = {};
BaseCurve.prototype.point = function () {
throw new Error("Not implemented");
};
@@ -12038,6 +6012,7 @@ var require_base = __commonJS({
function BasePoint(curve, type) {
(this.curve = curve), (this.type = type), (this.precomputed = null);
}
+ BasePoint.prototype = {};
BaseCurve.BasePoint = BasePoint;
BasePoint.prototype.eq = function () {
throw new Error("Not implemented");
@@ -13307,6 +7282,7 @@ var require_common = __commonJS({
(this._delta8 = this.blockSize / 8),
(this._delta32 = this.blockSize / 32);
}
+ BlockHash.prototype = {};
exports.BlockHash = BlockHash;
BlockHash.prototype.update = function (msg, enc) {
if (
@@ -13920,6 +7896,7 @@ var require_hmac = __commonJS({
(this.outer = null),
this._init(utils.toArray(key, enc));
}
+ Hmac.prototype = {};
module.exports = Hmac;
Hmac.prototype._init = function (key) {
key.length > this.blockSize && (key = new this.Hash().update(key).digest()), assert(key.length <= this.blockSize);
@@ -14936,6 +8913,7 @@ var require_hmac_drbg = __commonJS({
assert(entropy.length >= this.minEntropy / 8, "Not enough entropy. Minimum is: " + this.minEntropy + " bits"),
this._init(entropy, nonce, pers);
}
+ HmacDRBG.prototype = {};
module.exports = HmacDRBG;
HmacDRBG.prototype._init = function (entropy, nonce, pers) {
var seed = entropy.concat(nonce).concat(pers);
@@ -14989,6 +8967,7 @@ var require_key = __commonJS({
options.priv && this._importPrivate(options.priv, options.privEnc),
options.pub && this._importPublic(options.pub, options.pubEnc);
}
+ KeyPair.prototype = {};
module.exports = KeyPair;
KeyPair.fromPublic = function (ec, pub, enc) {
return pub instanceof KeyPair
@@ -15072,6 +9051,7 @@ var require_signature = __commonJS({
(this.s = new BN(options.s, 16)),
options.recoveryParam === void 0 ? (this.recoveryParam = null) : (this.recoveryParam = options.recoveryParam));
}
+ Signature.prototype = {};
module.exports = Signature;
function Position() {
this.place = 0;
@@ -15162,6 +9142,7 @@ var require_ec = __commonJS({
this.g.precompute(options.curve.n.bitLength() + 1),
(this.hash = options.hash || options.curve.hash);
}
+ EC.prototype = {};
module.exports = EC;
EC.prototype.keyPair = function (options) {
return new KeyPair(this, options);
@@ -15298,6 +9279,7 @@ var require_key2 = __commonJS({
(this._secret = parseBytes(params.secret)),
eddsa.isPoint(params.pub) ? (this._pub = params.pub) : (this._pubBytes = parseBytes(params.pub));
}
+ KeyPair.prototype = {};
KeyPair.fromPublic = function (eddsa, pub) {
return pub instanceof KeyPair ? pub : new KeyPair(eddsa, { pub });
};
@@ -15368,6 +9350,7 @@ var require_signature2 = __commonJS({
(this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded),
(this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded);
}
+ Signature.prototype = {};
cachedProperty(Signature, "S", function () {
return this.eddsa.decodeInt(this.Sencoded());
});
@@ -15412,6 +9395,7 @@ var require_eddsa = __commonJS({
(this.encodingLength = Math.ceil(curve.n.bitLength() / 8)),
(this.hash = hash.sha512);
}
+ EDDSA.prototype = {};
module.exports = EDDSA;
EDDSA.prototype.sign = function (message, secret) {
message = parseBytes(message);
@@ -15484,1992 +9468,7 @@ var require_elliptic = __commonJS({
});
// node_modules/asn1.js/node_modules/bn.js/lib/bn.js
-var require_bn5 = __commonJS({
- "node_modules/asn1.js/node_modules/bn.js/lib/bn.js"(exports, module) {
- (function (module2, exports2) {
- "use strict";
- function assert(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 BN(number, base, endian) {
- if (BN.isBN(number)) return number;
- (this.negative = 0),
- (this.words = null),
- (this.length = 0),
- (this.red = null),
- number !== null &&
- ((base === "le" || base === "be") && ((endian = base), (base = 10)),
- this._init(number || 0, base || 10, endian || "be"));
- }
- typeof module2 == "object" ? (module2.exports = BN) : (exports2.BN = BN), (BN.BN = BN), (BN.wordSize = 26);
- var Buffer2 = Buffer;
-
- (BN.isBN = function (num) {
- return num instanceof BN
- ? !0
- : num !== null &&
- typeof num == "object" &&
- num.constructor.wordSize === BN.wordSize &&
- Array.isArray(num.words);
- }),
- (BN.max = function (left, right) {
- return left.cmp(right) > 0 ? left : right;
- }),
- (BN.min = function (left, right) {
- return left.cmp(right) < 0 ? left : right;
- }),
- (BN.prototype._init = function (number, base, endian) {
- if (typeof number == "number") return this._initNumber(number, base, endian);
- if (typeof number == "object") return this._initArray(number, base, endian);
- base === "hex" && (base = 16),
- assert(base === (base | 0) && base >= 2 && base <= 36),
- (number = number.toString().replace(/\s+/g, ""));
- var start = 0;
- number[0] === "-" && (start++, (this.negative = 1)),
- start < number.length &&
- (base === 16
- ? this._parseHex(number, start, endian)
- : (this._parseBase(number, base, start),
- endian === "le" && this._initArray(this.toArray(), base, endian)));
- }),
- (BN.prototype._initNumber = function (number, base, endian) {
- number < 0 && ((this.negative = 1), (number = -number)),
- number < 67108864
- ? ((this.words = [number & 67108863]), (this.length = 1))
- : number < 4503599627370496
- ? ((this.words = [number & 67108863, (number / 67108864) & 67108863]), (this.length = 2))
- : (assert(number < 9007199254740992),
- (this.words = [number & 67108863, (number / 67108864) & 67108863, 1]),
- (this.length = 3)),
- endian === "le" && this._initArray(this.toArray(), base, endian);
- }),
- (BN.prototype._initArray = function (number, base, endian) {
- if ((assert(typeof number.length == "number"), number.length <= 0))
- return (this.words = [0]), (this.length = 1), 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,
- 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),
- 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),
- off >= 26 && ((off -= 26), j++);
- return this.strip();
- });
- function parseHex4Bits(string, index) {
- var c = string.charCodeAt(index);
- return c >= 65 && c <= 70 ? c - 55 : c >= 97 && c <= 102 ? c - 87 : (c - 48) & 15;
- }
- function parseHexByte(string, lowerBound, index) {
- var r = parseHex4Bits(string, index);
- return index - 1 >= lowerBound && (r |= parseHex4Bits(string, index - 1) << 4), r;
- }
- BN.prototype._parseHex = function (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,
- j = 0,
- w;
- if (endian === "be")
- for (i = number.length - 1; i >= start; i -= 2)
- (w = parseHexByte(number, start, i) << off),
- (this.words[j] |= w & 67108863),
- off >= 18 ? ((off -= 18), (j += 1), (this.words[j] |= w >>> 26)) : (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),
- off >= 18 ? ((off -= 18), (j += 1), (this.words[j] |= w >>> 26)) : (off += 8);
- }
- this.strip();
- };
- function parseBase(str, start, end, mul) {
- for (var r = 0, len = Math.min(str.length, end), i = start; i < len; i++) {
- var c = str.charCodeAt(i) - 48;
- (r *= mul), c >= 49 ? (r += c - 49 + 10) : c >= 17 ? (r += c - 17 + 10) : (r += c);
- }
- return r;
- }
- (BN.prototype._parseBase = function (number, base, start) {
- (this.words = [0]), (this.length = 1);
- for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) limbLen++;
- limbLen--, (limbPow = (limbPow / base) | 0);
- for (
- var total = number.length - start,
- mod = total % limbLen,
- end = Math.min(total, total - mod) + start,
- word = 0,
- i = start;
- i < end;
- i += limbLen
- )
- (word = parseBase(number, i, i + limbLen, base)),
- this.imuln(limbPow),
- this.words[0] + word < 67108864 ? (this.words[0] += word) : this._iaddn(word);
- if (mod !== 0) {
- var pow = 1;
- for (word = parseBase(number, i, number.length, base), i = 0; i < mod; i++) pow *= base;
- this.imuln(pow), this.words[0] + word < 67108864 ? (this.words[0] += word) : this._iaddn(word);
- }
- this.strip();
- }),
- (BN.prototype.copy = function (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);
- }),
- (BN.prototype.clone = function () {
- var r = new BN(null);
- return this.copy(r), r;
- }),
- (BN.prototype._expand = function (size) {
- for (; this.length < size; ) this.words[this.length++] = 0;
- return this;
- }),
- (BN.prototype.strip = function () {
- for (; this.length > 1 && this.words[this.length - 1] === 0; ) this.length--;
- return this._normSign();
- }),
- (BN.prototype._normSign = function () {
- return this.length === 1 && this.words[0] === 0 && (this.negative = 0), this;
- }),
- (BN.prototype.inspect = function () {
- return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
- });
- var zeros = [
- "",
- "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",
- ],
- 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,
- ],
- 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,
- ];
- (BN.prototype.toString = function (base, padding) {
- (base = base || 10), (padding = padding | 0 || 1);
- var out;
- if (base === 16 || base === "hex") {
- out = "";
- for (var off = 0, carry = 0, i = 0; i < this.length; i++) {
- var w = this.words[i],
- word = (((w << off) | carry) & 16777215).toString(16);
- (carry = (w >>> (24 - off)) & 16777215),
- carry !== 0 || i !== this.length - 1 ? (out = zeros[6 - word.length] + word + out) : (out = word + out),
- (off += 2),
- off >= 26 && ((off -= 26), i--);
- }
- for (carry !== 0 && (out = carry.toString(16) + out); out.length % padding !== 0; ) out = "0" + out;
- return this.negative !== 0 && (out = "-" + out), out;
- }
- if (base === (base | 0) && base >= 2 && base <= 36) {
- var groupSize = groupSizes[base],
- groupBase = groupBases[base];
- out = "";
- var c = this.clone();
- for (c.negative = 0; !c.isZero(); ) {
- var r = c.modn(groupBase).toString(base);
- (c = c.idivn(groupBase)), c.isZero() ? (out = r + out) : (out = zeros[groupSize - r.length] + r + out);
- }
- for (this.isZero() && (out = "0" + out); out.length % padding !== 0; ) out = "0" + out;
- return this.negative !== 0 && (out = "-" + out), out;
- }
- assert(!1, "Base should be between 2 and 36");
- }),
- (BN.prototype.toNumber = function () {
- var ret = this.words[0];
- return (
- this.length === 2
- ? (ret += this.words[1] * 67108864)
- : this.length === 3 && this.words[2] === 1
- ? (ret += 4503599627370496 + this.words[1] * 67108864)
- : this.length > 2 && assert(!1, "Number can only safely store up to 53 bits"),
- this.negative !== 0 ? -ret : ret
- );
- }),
- (BN.prototype.toJSON = function () {
- return this.toString(16);
- }),
- (BN.prototype.toBuffer = function (endian, length) {
- return assert(typeof Buffer2 < "u"), this.toArrayLike(Buffer2, endian, length);
- }),
- (BN.prototype.toArray = function (endian, length) {
- return this.toArrayLike(Array, endian, length);
- }),
- (BN.prototype.toArrayLike = function (ArrayType, endian, length) {
- var byteLength = this.byteLength(),
- reqLength = length || Math.max(1, byteLength);
- assert(byteLength <= reqLength, "byte array longer than desired length"),
- assert(reqLength > 0, "Requested array length <= 0"),
- this.strip();
- var littleEndian = endian === "le",
- res = new ArrayType(reqLength),
- b,
- i,
- q = this.clone();
- if (littleEndian) {
- for (i = 0; !q.isZero(); i++) (b = q.andln(255)), q.iushrn(8), (res[i] = b);
- for (; i < reqLength; i++) res[i] = 0;
- } else {
- for (i = 0; i < reqLength - byteLength; i++) res[i] = 0;
- for (i = 0; !q.isZero(); i++) (b = q.andln(255)), q.iushrn(8), (res[reqLength - i - 1] = b);
- }
- return res;
- }),
- Math.clz32
- ? (BN.prototype._countBits = function (w) {
- return 32 - Math.clz32(w);
- })
- : (BN.prototype._countBits = function (w) {
- var t = w,
- r = 0;
- return (
- t >= 4096 && ((r += 13), (t >>>= 13)),
- t >= 64 && ((r += 7), (t >>>= 7)),
- t >= 8 && ((r += 4), (t >>>= 4)),
- t >= 2 && ((r += 2), (t >>>= 2)),
- r + t
- );
- }),
- (BN.prototype._zeroBits = function (w) {
- if (w === 0) return 26;
- var t = w,
- r = 0;
- return (
- (t & 8191) === 0 && ((r += 13), (t >>>= 13)),
- (t & 127) === 0 && ((r += 7), (t >>>= 7)),
- (t & 15) === 0 && ((r += 4), (t >>>= 4)),
- (t & 3) === 0 && ((r += 2), (t >>>= 2)),
- (t & 1) === 0 && r++,
- r
- );
- }),
- (BN.prototype.bitLength = function () {
- var w = this.words[this.length - 1],
- hi = this._countBits(w);
- return (this.length - 1) * 26 + hi;
- });
- function toBitArray(num) {
- for (var w = new Array(num.bitLength()), bit = 0; bit < w.length; bit++) {
- var off = (bit / 26) | 0,
- wbit = bit % 26;
- w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
- }
- return w;
- }
- (BN.prototype.zeroBits = function () {
- if (this.isZero()) return 0;
- for (var r = 0, i = 0; i < this.length; i++) {
- var b = this._zeroBits(this.words[i]);
- if (((r += b), b !== 26)) break;
- }
- return r;
- }),
- (BN.prototype.byteLength = function () {
- return Math.ceil(this.bitLength() / 8);
- }),
- (BN.prototype.toTwos = function (width) {
- return this.negative !== 0 ? this.abs().inotn(width).iaddn(1) : this.clone();
- }),
- (BN.prototype.fromTwos = function (width) {
- return this.testn(width - 1) ? this.notn(width).iaddn(1).ineg() : this.clone();
- }),
- (BN.prototype.isNeg = function () {
- return this.negative !== 0;
- }),
- (BN.prototype.neg = function () {
- return this.clone().ineg();
- }),
- (BN.prototype.ineg = function () {
- return this.isZero() || (this.negative ^= 1), this;
- }),
- (BN.prototype.iuor = function (num) {
- for (; 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();
- }),
- (BN.prototype.ior = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuor(num);
- }),
- (BN.prototype.or = function (num) {
- return this.length > num.length ? this.clone().ior(num) : num.clone().ior(this);
- }),
- (BN.prototype.uor = function (num) {
- return this.length > num.length ? this.clone().iuor(num) : num.clone().iuor(this);
- }),
- (BN.prototype.iuand = function (num) {
- var b;
- this.length > num.length ? (b = num) : (b = this);
- for (var i = 0; i < b.length; i++) this.words[i] = this.words[i] & num.words[i];
- return (this.length = b.length), this.strip();
- }),
- (BN.prototype.iand = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuand(num);
- }),
- (BN.prototype.and = function (num) {
- return this.length > num.length ? this.clone().iand(num) : num.clone().iand(this);
- }),
- (BN.prototype.uand = function (num) {
- return this.length > num.length ? this.clone().iuand(num) : num.clone().iuand(this);
- }),
- (BN.prototype.iuxor = function (num) {
- var a, b;
- this.length > num.length ? ((a = this), (b = num)) : ((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];
- return (this.length = a.length), this.strip();
- }),
- (BN.prototype.ixor = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuxor(num);
- }),
- (BN.prototype.xor = function (num) {
- return this.length > num.length ? this.clone().ixor(num) : num.clone().ixor(this);
- }),
- (BN.prototype.uxor = function (num) {
- return this.length > num.length ? this.clone().iuxor(num) : num.clone().iuxor(this);
- }),
- (BN.prototype.inotn = function (width) {
- assert(typeof width == "number" && width >= 0);
- var bytesNeeded = Math.ceil(width / 26) | 0,
- bitsLeft = width % 26;
- this._expand(bytesNeeded), bitsLeft > 0 && bytesNeeded--;
- for (var i = 0; i < bytesNeeded; i++) this.words[i] = ~this.words[i] & 67108863;
- return bitsLeft > 0 && (this.words[i] = ~this.words[i] & (67108863 >> (26 - bitsLeft))), this.strip();
- }),
- (BN.prototype.notn = function (width) {
- return this.clone().inotn(width);
- }),
- (BN.prototype.setn = function (bit, val) {
- assert(typeof bit == "number" && bit >= 0);
- var off = (bit / 26) | 0,
- wbit = bit % 26;
- return (
- this._expand(off + 1),
- val
- ? (this.words[off] = this.words[off] | (1 << wbit))
- : (this.words[off] = this.words[off] & ~(1 << wbit)),
- this.strip()
- );
- }),
- (BN.prototype.iadd = function (num) {
- var r;
- if (this.negative !== 0 && num.negative === 0)
- return (this.negative = 0), (r = this.isub(num)), (this.negative ^= 1), this._normSign();
- if (this.negative === 0 && num.negative !== 0)
- return (num.negative = 0), (r = this.isub(num)), (num.negative = 1), r._normSign();
- var a, b;
- this.length > num.length ? ((a = this), (b = num)) : ((a = num), (b = this));
- for (var carry = 0, i = 0; i < b.length; i++)
- (r = (a.words[i] | 0) + (b.words[i] | 0) + carry), (this.words[i] = r & 67108863), (carry = r >>> 26);
- for (; carry !== 0 && i < a.length; i++)
- (r = (a.words[i] | 0) + carry), (this.words[i] = r & 67108863), (carry = r >>> 26);
- if (((this.length = a.length), carry !== 0)) (this.words[this.length] = carry), this.length++;
- else if (a !== this) for (; i < a.length; i++) this.words[i] = a.words[i];
- return this;
- }),
- (BN.prototype.add = function (num) {
- var res;
- return num.negative !== 0 && this.negative === 0
- ? ((num.negative = 0), (res = this.sub(num)), (num.negative ^= 1), res)
- : num.negative === 0 && this.negative !== 0
- ? ((this.negative = 0), (res = num.sub(this)), (this.negative = 1), res)
- : this.length > num.length
- ? this.clone().iadd(num)
- : num.clone().iadd(this);
- }),
- (BN.prototype.isub = function (num) {
- if (num.negative !== 0) {
- num.negative = 0;
- var r = this.iadd(num);
- return (num.negative = 1), r._normSign();
- } else if (this.negative !== 0)
- return (this.negative = 0), this.iadd(num), (this.negative = 1), this._normSign();
- var cmp = this.cmp(num);
- if (cmp === 0) return (this.negative = 0), (this.length = 1), (this.words[0] = 0), this;
- var a, b;
- cmp > 0 ? ((a = this), (b = num)) : ((a = num), (b = this));
- for (var carry = 0, i = 0; i < b.length; i++)
- (r = (a.words[i] | 0) - (b.words[i] | 0) + carry), (carry = r >> 26), (this.words[i] = r & 67108863);
- for (; carry !== 0 && i < a.length; i++)
- (r = (a.words[i] | 0) + carry), (carry = r >> 26), (this.words[i] = r & 67108863);
- if (carry === 0 && i < a.length && a !== this) for (; i < a.length; i++) this.words[i] = a.words[i];
- return (this.length = Math.max(this.length, i)), a !== this && (this.negative = 1), this.strip();
- }),
- (BN.prototype.sub = function (num) {
- return this.clone().isub(num);
- });
- function smallMulTo(self2, num, out) {
- out.negative = num.negative ^ self2.negative;
- var len = (self2.length + num.length) | 0;
- (out.length = len), (len = (len - 1) | 0);
- var a = self2.words[0] | 0,
- b = num.words[0] | 0,
- r = a * b,
- lo = r & 67108863,
- carry = (r / 67108864) | 0;
- out.words[0] = lo;
- for (var k = 1; k < len; k++) {
- for (
- var ncarry = carry >>> 26,
- rword = carry & 67108863,
- maxJ = Math.min(k, num.length - 1),
- j = Math.max(0, k - self2.length + 1);
- j <= maxJ;
- j++
- ) {
- var i = (k - j) | 0;
- (a = self2.words[i] | 0),
- (b = num.words[j] | 0),
- (r = a * b + rword),
- (ncarry += (r / 67108864) | 0),
- (rword = r & 67108863);
- }
- (out.words[k] = rword | 0), (carry = ncarry | 0);
- }
- return carry !== 0 ? (out.words[k] = carry | 0) : out.length--, out.strip();
- }
- var comb10MulTo = function (self2, num, out) {
- var a = self2.words,
- b = num.words,
- o = out.words,
- c = 0,
- lo,
- mid,
- hi,
- a0 = a[0] | 0,
- al0 = a0 & 8191,
- ah0 = a0 >>> 13,
- a1 = a[1] | 0,
- al1 = a1 & 8191,
- ah1 = a1 >>> 13,
- a2 = a[2] | 0,
- al2 = a2 & 8191,
- ah2 = a2 >>> 13,
- a3 = a[3] | 0,
- al3 = a3 & 8191,
- ah3 = a3 >>> 13,
- a4 = a[4] | 0,
- al4 = a4 & 8191,
- ah4 = a4 >>> 13,
- a5 = a[5] | 0,
- al5 = a5 & 8191,
- ah5 = a5 >>> 13,
- a6 = a[6] | 0,
- al6 = a6 & 8191,
- ah6 = a6 >>> 13,
- a7 = a[7] | 0,
- al7 = a7 & 8191,
- ah7 = a7 >>> 13,
- a8 = a[8] | 0,
- al8 = a8 & 8191,
- ah8 = a8 >>> 13,
- a9 = a[9] | 0,
- al9 = a9 & 8191,
- ah9 = a9 >>> 13,
- b0 = b[0] | 0,
- bl0 = b0 & 8191,
- bh0 = b0 >>> 13,
- b1 = b[1] | 0,
- bl1 = b1 & 8191,
- bh1 = b1 >>> 13,
- b2 = b[2] | 0,
- bl2 = b2 & 8191,
- bh2 = b2 >>> 13,
- b3 = b[3] | 0,
- bl3 = b3 & 8191,
- bh3 = b3 >>> 13,
- b4 = b[4] | 0,
- bl4 = b4 & 8191,
- bh4 = b4 >>> 13,
- b5 = b[5] | 0,
- bl5 = b5 & 8191,
- bh5 = b5 >>> 13,
- b6 = b[6] | 0,
- bl6 = b6 & 8191,
- bh6 = b6 >>> 13,
- b7 = b[7] | 0,
- bl7 = b7 & 8191,
- bh7 = b7 >>> 13,
- b8 = b[8] | 0,
- bl8 = b8 & 8191,
- bh8 = b8 >>> 13,
- b9 = b[9] | 0,
- bl9 = b9 & 8191,
- bh9 = b9 >>> 13;
- (out.negative = self2.negative ^ num.negative),
- (out.length = 19),
- (lo = Math.imul(al0, bl0)),
- (mid = Math.imul(al0, bh0)),
- (mid = (mid + Math.imul(ah0, bl0)) | 0),
- (hi = Math.imul(ah0, bh0));
- var w0 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0),
- (w0 &= 67108863),
- (lo = Math.imul(al1, bl0)),
- (mid = Math.imul(al1, bh0)),
- (mid = (mid + Math.imul(ah1, bl0)) | 0),
- (hi = Math.imul(ah1, bh0)),
- (lo = (lo + Math.imul(al0, bl1)) | 0),
- (mid = (mid + Math.imul(al0, bh1)) | 0),
- (mid = (mid + Math.imul(ah0, bl1)) | 0),
- (hi = (hi + Math.imul(ah0, bh1)) | 0);
- var w1 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0),
- (w1 &= 67108863),
- (lo = Math.imul(al2, bl0)),
- (mid = Math.imul(al2, bh0)),
- (mid = (mid + Math.imul(ah2, bl0)) | 0),
- (hi = Math.imul(ah2, bh0)),
- (lo = (lo + Math.imul(al1, bl1)) | 0),
- (mid = (mid + Math.imul(al1, bh1)) | 0),
- (mid = (mid + Math.imul(ah1, bl1)) | 0),
- (hi = (hi + Math.imul(ah1, bh1)) | 0),
- (lo = (lo + Math.imul(al0, bl2)) | 0),
- (mid = (mid + Math.imul(al0, bh2)) | 0),
- (mid = (mid + Math.imul(ah0, bl2)) | 0),
- (hi = (hi + Math.imul(ah0, bh2)) | 0);
- var w2 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0),
- (w2 &= 67108863),
- (lo = Math.imul(al3, bl0)),
- (mid = Math.imul(al3, bh0)),
- (mid = (mid + Math.imul(ah3, bl0)) | 0),
- (hi = Math.imul(ah3, bh0)),
- (lo = (lo + Math.imul(al2, bl1)) | 0),
- (mid = (mid + Math.imul(al2, bh1)) | 0),
- (mid = (mid + Math.imul(ah2, bl1)) | 0),
- (hi = (hi + Math.imul(ah2, bh1)) | 0),
- (lo = (lo + Math.imul(al1, bl2)) | 0),
- (mid = (mid + Math.imul(al1, bh2)) | 0),
- (mid = (mid + Math.imul(ah1, bl2)) | 0),
- (hi = (hi + Math.imul(ah1, bh2)) | 0),
- (lo = (lo + Math.imul(al0, bl3)) | 0),
- (mid = (mid + Math.imul(al0, bh3)) | 0),
- (mid = (mid + Math.imul(ah0, bl3)) | 0),
- (hi = (hi + Math.imul(ah0, bh3)) | 0);
- var w3 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0),
- (w3 &= 67108863),
- (lo = Math.imul(al4, bl0)),
- (mid = Math.imul(al4, bh0)),
- (mid = (mid + Math.imul(ah4, bl0)) | 0),
- (hi = Math.imul(ah4, bh0)),
- (lo = (lo + Math.imul(al3, bl1)) | 0),
- (mid = (mid + Math.imul(al3, bh1)) | 0),
- (mid = (mid + Math.imul(ah3, bl1)) | 0),
- (hi = (hi + Math.imul(ah3, bh1)) | 0),
- (lo = (lo + Math.imul(al2, bl2)) | 0),
- (mid = (mid + Math.imul(al2, bh2)) | 0),
- (mid = (mid + Math.imul(ah2, bl2)) | 0),
- (hi = (hi + Math.imul(ah2, bh2)) | 0),
- (lo = (lo + Math.imul(al1, bl3)) | 0),
- (mid = (mid + Math.imul(al1, bh3)) | 0),
- (mid = (mid + Math.imul(ah1, bl3)) | 0),
- (hi = (hi + Math.imul(ah1, bh3)) | 0),
- (lo = (lo + Math.imul(al0, bl4)) | 0),
- (mid = (mid + Math.imul(al0, bh4)) | 0),
- (mid = (mid + Math.imul(ah0, bl4)) | 0),
- (hi = (hi + Math.imul(ah0, bh4)) | 0);
- var w4 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0),
- (w4 &= 67108863),
- (lo = Math.imul(al5, bl0)),
- (mid = Math.imul(al5, bh0)),
- (mid = (mid + Math.imul(ah5, bl0)) | 0),
- (hi = Math.imul(ah5, bh0)),
- (lo = (lo + Math.imul(al4, bl1)) | 0),
- (mid = (mid + Math.imul(al4, bh1)) | 0),
- (mid = (mid + Math.imul(ah4, bl1)) | 0),
- (hi = (hi + Math.imul(ah4, bh1)) | 0),
- (lo = (lo + Math.imul(al3, bl2)) | 0),
- (mid = (mid + Math.imul(al3, bh2)) | 0),
- (mid = (mid + Math.imul(ah3, bl2)) | 0),
- (hi = (hi + Math.imul(ah3, bh2)) | 0),
- (lo = (lo + Math.imul(al2, bl3)) | 0),
- (mid = (mid + Math.imul(al2, bh3)) | 0),
- (mid = (mid + Math.imul(ah2, bl3)) | 0),
- (hi = (hi + Math.imul(ah2, bh3)) | 0),
- (lo = (lo + Math.imul(al1, bl4)) | 0),
- (mid = (mid + Math.imul(al1, bh4)) | 0),
- (mid = (mid + Math.imul(ah1, bl4)) | 0),
- (hi = (hi + Math.imul(ah1, bh4)) | 0),
- (lo = (lo + Math.imul(al0, bl5)) | 0),
- (mid = (mid + Math.imul(al0, bh5)) | 0),
- (mid = (mid + Math.imul(ah0, bl5)) | 0),
- (hi = (hi + Math.imul(ah0, bh5)) | 0);
- var w5 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0),
- (w5 &= 67108863),
- (lo = Math.imul(al6, bl0)),
- (mid = Math.imul(al6, bh0)),
- (mid = (mid + Math.imul(ah6, bl0)) | 0),
- (hi = Math.imul(ah6, bh0)),
- (lo = (lo + Math.imul(al5, bl1)) | 0),
- (mid = (mid + Math.imul(al5, bh1)) | 0),
- (mid = (mid + Math.imul(ah5, bl1)) | 0),
- (hi = (hi + Math.imul(ah5, bh1)) | 0),
- (lo = (lo + Math.imul(al4, bl2)) | 0),
- (mid = (mid + Math.imul(al4, bh2)) | 0),
- (mid = (mid + Math.imul(ah4, bl2)) | 0),
- (hi = (hi + Math.imul(ah4, bh2)) | 0),
- (lo = (lo + Math.imul(al3, bl3)) | 0),
- (mid = (mid + Math.imul(al3, bh3)) | 0),
- (mid = (mid + Math.imul(ah3, bl3)) | 0),
- (hi = (hi + Math.imul(ah3, bh3)) | 0),
- (lo = (lo + Math.imul(al2, bl4)) | 0),
- (mid = (mid + Math.imul(al2, bh4)) | 0),
- (mid = (mid + Math.imul(ah2, bl4)) | 0),
- (hi = (hi + Math.imul(ah2, bh4)) | 0),
- (lo = (lo + Math.imul(al1, bl5)) | 0),
- (mid = (mid + Math.imul(al1, bh5)) | 0),
- (mid = (mid + Math.imul(ah1, bl5)) | 0),
- (hi = (hi + Math.imul(ah1, bh5)) | 0),
- (lo = (lo + Math.imul(al0, bl6)) | 0),
- (mid = (mid + Math.imul(al0, bh6)) | 0),
- (mid = (mid + Math.imul(ah0, bl6)) | 0),
- (hi = (hi + Math.imul(ah0, bh6)) | 0);
- var w6 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0),
- (w6 &= 67108863),
- (lo = Math.imul(al7, bl0)),
- (mid = Math.imul(al7, bh0)),
- (mid = (mid + Math.imul(ah7, bl0)) | 0),
- (hi = Math.imul(ah7, bh0)),
- (lo = (lo + Math.imul(al6, bl1)) | 0),
- (mid = (mid + Math.imul(al6, bh1)) | 0),
- (mid = (mid + Math.imul(ah6, bl1)) | 0),
- (hi = (hi + Math.imul(ah6, bh1)) | 0),
- (lo = (lo + Math.imul(al5, bl2)) | 0),
- (mid = (mid + Math.imul(al5, bh2)) | 0),
- (mid = (mid + Math.imul(ah5, bl2)) | 0),
- (hi = (hi + Math.imul(ah5, bh2)) | 0),
- (lo = (lo + Math.imul(al4, bl3)) | 0),
- (mid = (mid + Math.imul(al4, bh3)) | 0),
- (mid = (mid + Math.imul(ah4, bl3)) | 0),
- (hi = (hi + Math.imul(ah4, bh3)) | 0),
- (lo = (lo + Math.imul(al3, bl4)) | 0),
- (mid = (mid + Math.imul(al3, bh4)) | 0),
- (mid = (mid + Math.imul(ah3, bl4)) | 0),
- (hi = (hi + Math.imul(ah3, bh4)) | 0),
- (lo = (lo + Math.imul(al2, bl5)) | 0),
- (mid = (mid + Math.imul(al2, bh5)) | 0),
- (mid = (mid + Math.imul(ah2, bl5)) | 0),
- (hi = (hi + Math.imul(ah2, bh5)) | 0),
- (lo = (lo + Math.imul(al1, bl6)) | 0),
- (mid = (mid + Math.imul(al1, bh6)) | 0),
- (mid = (mid + Math.imul(ah1, bl6)) | 0),
- (hi = (hi + Math.imul(ah1, bh6)) | 0),
- (lo = (lo + Math.imul(al0, bl7)) | 0),
- (mid = (mid + Math.imul(al0, bh7)) | 0),
- (mid = (mid + Math.imul(ah0, bl7)) | 0),
- (hi = (hi + Math.imul(ah0, bh7)) | 0);
- var w7 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0),
- (w7 &= 67108863),
- (lo = Math.imul(al8, bl0)),
- (mid = Math.imul(al8, bh0)),
- (mid = (mid + Math.imul(ah8, bl0)) | 0),
- (hi = Math.imul(ah8, bh0)),
- (lo = (lo + Math.imul(al7, bl1)) | 0),
- (mid = (mid + Math.imul(al7, bh1)) | 0),
- (mid = (mid + Math.imul(ah7, bl1)) | 0),
- (hi = (hi + Math.imul(ah7, bh1)) | 0),
- (lo = (lo + Math.imul(al6, bl2)) | 0),
- (mid = (mid + Math.imul(al6, bh2)) | 0),
- (mid = (mid + Math.imul(ah6, bl2)) | 0),
- (hi = (hi + Math.imul(ah6, bh2)) | 0),
- (lo = (lo + Math.imul(al5, bl3)) | 0),
- (mid = (mid + Math.imul(al5, bh3)) | 0),
- (mid = (mid + Math.imul(ah5, bl3)) | 0),
- (hi = (hi + Math.imul(ah5, bh3)) | 0),
- (lo = (lo + Math.imul(al4, bl4)) | 0),
- (mid = (mid + Math.imul(al4, bh4)) | 0),
- (mid = (mid + Math.imul(ah4, bl4)) | 0),
- (hi = (hi + Math.imul(ah4, bh4)) | 0),
- (lo = (lo + Math.imul(al3, bl5)) | 0),
- (mid = (mid + Math.imul(al3, bh5)) | 0),
- (mid = (mid + Math.imul(ah3, bl5)) | 0),
- (hi = (hi + Math.imul(ah3, bh5)) | 0),
- (lo = (lo + Math.imul(al2, bl6)) | 0),
- (mid = (mid + Math.imul(al2, bh6)) | 0),
- (mid = (mid + Math.imul(ah2, bl6)) | 0),
- (hi = (hi + Math.imul(ah2, bh6)) | 0),
- (lo = (lo + Math.imul(al1, bl7)) | 0),
- (mid = (mid + Math.imul(al1, bh7)) | 0),
- (mid = (mid + Math.imul(ah1, bl7)) | 0),
- (hi = (hi + Math.imul(ah1, bh7)) | 0),
- (lo = (lo + Math.imul(al0, bl8)) | 0),
- (mid = (mid + Math.imul(al0, bh8)) | 0),
- (mid = (mid + Math.imul(ah0, bl8)) | 0),
- (hi = (hi + Math.imul(ah0, bh8)) | 0);
- var w8 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0),
- (w8 &= 67108863),
- (lo = Math.imul(al9, bl0)),
- (mid = Math.imul(al9, bh0)),
- (mid = (mid + Math.imul(ah9, bl0)) | 0),
- (hi = Math.imul(ah9, bh0)),
- (lo = (lo + Math.imul(al8, bl1)) | 0),
- (mid = (mid + Math.imul(al8, bh1)) | 0),
- (mid = (mid + Math.imul(ah8, bl1)) | 0),
- (hi = (hi + Math.imul(ah8, bh1)) | 0),
- (lo = (lo + Math.imul(al7, bl2)) | 0),
- (mid = (mid + Math.imul(al7, bh2)) | 0),
- (mid = (mid + Math.imul(ah7, bl2)) | 0),
- (hi = (hi + Math.imul(ah7, bh2)) | 0),
- (lo = (lo + Math.imul(al6, bl3)) | 0),
- (mid = (mid + Math.imul(al6, bh3)) | 0),
- (mid = (mid + Math.imul(ah6, bl3)) | 0),
- (hi = (hi + Math.imul(ah6, bh3)) | 0),
- (lo = (lo + Math.imul(al5, bl4)) | 0),
- (mid = (mid + Math.imul(al5, bh4)) | 0),
- (mid = (mid + Math.imul(ah5, bl4)) | 0),
- (hi = (hi + Math.imul(ah5, bh4)) | 0),
- (lo = (lo + Math.imul(al4, bl5)) | 0),
- (mid = (mid + Math.imul(al4, bh5)) | 0),
- (mid = (mid + Math.imul(ah4, bl5)) | 0),
- (hi = (hi + Math.imul(ah4, bh5)) | 0),
- (lo = (lo + Math.imul(al3, bl6)) | 0),
- (mid = (mid + Math.imul(al3, bh6)) | 0),
- (mid = (mid + Math.imul(ah3, bl6)) | 0),
- (hi = (hi + Math.imul(ah3, bh6)) | 0),
- (lo = (lo + Math.imul(al2, bl7)) | 0),
- (mid = (mid + Math.imul(al2, bh7)) | 0),
- (mid = (mid + Math.imul(ah2, bl7)) | 0),
- (hi = (hi + Math.imul(ah2, bh7)) | 0),
- (lo = (lo + Math.imul(al1, bl8)) | 0),
- (mid = (mid + Math.imul(al1, bh8)) | 0),
- (mid = (mid + Math.imul(ah1, bl8)) | 0),
- (hi = (hi + Math.imul(ah1, bh8)) | 0),
- (lo = (lo + Math.imul(al0, bl9)) | 0),
- (mid = (mid + Math.imul(al0, bh9)) | 0),
- (mid = (mid + Math.imul(ah0, bl9)) | 0),
- (hi = (hi + Math.imul(ah0, bh9)) | 0);
- var w9 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0),
- (w9 &= 67108863),
- (lo = Math.imul(al9, bl1)),
- (mid = Math.imul(al9, bh1)),
- (mid = (mid + Math.imul(ah9, bl1)) | 0),
- (hi = Math.imul(ah9, bh1)),
- (lo = (lo + Math.imul(al8, bl2)) | 0),
- (mid = (mid + Math.imul(al8, bh2)) | 0),
- (mid = (mid + Math.imul(ah8, bl2)) | 0),
- (hi = (hi + Math.imul(ah8, bh2)) | 0),
- (lo = (lo + Math.imul(al7, bl3)) | 0),
- (mid = (mid + Math.imul(al7, bh3)) | 0),
- (mid = (mid + Math.imul(ah7, bl3)) | 0),
- (hi = (hi + Math.imul(ah7, bh3)) | 0),
- (lo = (lo + Math.imul(al6, bl4)) | 0),
- (mid = (mid + Math.imul(al6, bh4)) | 0),
- (mid = (mid + Math.imul(ah6, bl4)) | 0),
- (hi = (hi + Math.imul(ah6, bh4)) | 0),
- (lo = (lo + Math.imul(al5, bl5)) | 0),
- (mid = (mid + Math.imul(al5, bh5)) | 0),
- (mid = (mid + Math.imul(ah5, bl5)) | 0),
- (hi = (hi + Math.imul(ah5, bh5)) | 0),
- (lo = (lo + Math.imul(al4, bl6)) | 0),
- (mid = (mid + Math.imul(al4, bh6)) | 0),
- (mid = (mid + Math.imul(ah4, bl6)) | 0),
- (hi = (hi + Math.imul(ah4, bh6)) | 0),
- (lo = (lo + Math.imul(al3, bl7)) | 0),
- (mid = (mid + Math.imul(al3, bh7)) | 0),
- (mid = (mid + Math.imul(ah3, bl7)) | 0),
- (hi = (hi + Math.imul(ah3, bh7)) | 0),
- (lo = (lo + Math.imul(al2, bl8)) | 0),
- (mid = (mid + Math.imul(al2, bh8)) | 0),
- (mid = (mid + Math.imul(ah2, bl8)) | 0),
- (hi = (hi + Math.imul(ah2, bh8)) | 0),
- (lo = (lo + Math.imul(al1, bl9)) | 0),
- (mid = (mid + Math.imul(al1, bh9)) | 0),
- (mid = (mid + Math.imul(ah1, bl9)) | 0),
- (hi = (hi + Math.imul(ah1, bh9)) | 0);
- var w10 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0),
- (w10 &= 67108863),
- (lo = Math.imul(al9, bl2)),
- (mid = Math.imul(al9, bh2)),
- (mid = (mid + Math.imul(ah9, bl2)) | 0),
- (hi = Math.imul(ah9, bh2)),
- (lo = (lo + Math.imul(al8, bl3)) | 0),
- (mid = (mid + Math.imul(al8, bh3)) | 0),
- (mid = (mid + Math.imul(ah8, bl3)) | 0),
- (hi = (hi + Math.imul(ah8, bh3)) | 0),
- (lo = (lo + Math.imul(al7, bl4)) | 0),
- (mid = (mid + Math.imul(al7, bh4)) | 0),
- (mid = (mid + Math.imul(ah7, bl4)) | 0),
- (hi = (hi + Math.imul(ah7, bh4)) | 0),
- (lo = (lo + Math.imul(al6, bl5)) | 0),
- (mid = (mid + Math.imul(al6, bh5)) | 0),
- (mid = (mid + Math.imul(ah6, bl5)) | 0),
- (hi = (hi + Math.imul(ah6, bh5)) | 0),
- (lo = (lo + Math.imul(al5, bl6)) | 0),
- (mid = (mid + Math.imul(al5, bh6)) | 0),
- (mid = (mid + Math.imul(ah5, bl6)) | 0),
- (hi = (hi + Math.imul(ah5, bh6)) | 0),
- (lo = (lo + Math.imul(al4, bl7)) | 0),
- (mid = (mid + Math.imul(al4, bh7)) | 0),
- (mid = (mid + Math.imul(ah4, bl7)) | 0),
- (hi = (hi + Math.imul(ah4, bh7)) | 0),
- (lo = (lo + Math.imul(al3, bl8)) | 0),
- (mid = (mid + Math.imul(al3, bh8)) | 0),
- (mid = (mid + Math.imul(ah3, bl8)) | 0),
- (hi = (hi + Math.imul(ah3, bh8)) | 0),
- (lo = (lo + Math.imul(al2, bl9)) | 0),
- (mid = (mid + Math.imul(al2, bh9)) | 0),
- (mid = (mid + Math.imul(ah2, bl9)) | 0),
- (hi = (hi + Math.imul(ah2, bh9)) | 0);
- var w11 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0),
- (w11 &= 67108863),
- (lo = Math.imul(al9, bl3)),
- (mid = Math.imul(al9, bh3)),
- (mid = (mid + Math.imul(ah9, bl3)) | 0),
- (hi = Math.imul(ah9, bh3)),
- (lo = (lo + Math.imul(al8, bl4)) | 0),
- (mid = (mid + Math.imul(al8, bh4)) | 0),
- (mid = (mid + Math.imul(ah8, bl4)) | 0),
- (hi = (hi + Math.imul(ah8, bh4)) | 0),
- (lo = (lo + Math.imul(al7, bl5)) | 0),
- (mid = (mid + Math.imul(al7, bh5)) | 0),
- (mid = (mid + Math.imul(ah7, bl5)) | 0),
- (hi = (hi + Math.imul(ah7, bh5)) | 0),
- (lo = (lo + Math.imul(al6, bl6)) | 0),
- (mid = (mid + Math.imul(al6, bh6)) | 0),
- (mid = (mid + Math.imul(ah6, bl6)) | 0),
- (hi = (hi + Math.imul(ah6, bh6)) | 0),
- (lo = (lo + Math.imul(al5, bl7)) | 0),
- (mid = (mid + Math.imul(al5, bh7)) | 0),
- (mid = (mid + Math.imul(ah5, bl7)) | 0),
- (hi = (hi + Math.imul(ah5, bh7)) | 0),
- (lo = (lo + Math.imul(al4, bl8)) | 0),
- (mid = (mid + Math.imul(al4, bh8)) | 0),
- (mid = (mid + Math.imul(ah4, bl8)) | 0),
- (hi = (hi + Math.imul(ah4, bh8)) | 0),
- (lo = (lo + Math.imul(al3, bl9)) | 0),
- (mid = (mid + Math.imul(al3, bh9)) | 0),
- (mid = (mid + Math.imul(ah3, bl9)) | 0),
- (hi = (hi + Math.imul(ah3, bh9)) | 0);
- var w12 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0),
- (w12 &= 67108863),
- (lo = Math.imul(al9, bl4)),
- (mid = Math.imul(al9, bh4)),
- (mid = (mid + Math.imul(ah9, bl4)) | 0),
- (hi = Math.imul(ah9, bh4)),
- (lo = (lo + Math.imul(al8, bl5)) | 0),
- (mid = (mid + Math.imul(al8, bh5)) | 0),
- (mid = (mid + Math.imul(ah8, bl5)) | 0),
- (hi = (hi + Math.imul(ah8, bh5)) | 0),
- (lo = (lo + Math.imul(al7, bl6)) | 0),
- (mid = (mid + Math.imul(al7, bh6)) | 0),
- (mid = (mid + Math.imul(ah7, bl6)) | 0),
- (hi = (hi + Math.imul(ah7, bh6)) | 0),
- (lo = (lo + Math.imul(al6, bl7)) | 0),
- (mid = (mid + Math.imul(al6, bh7)) | 0),
- (mid = (mid + Math.imul(ah6, bl7)) | 0),
- (hi = (hi + Math.imul(ah6, bh7)) | 0),
- (lo = (lo + Math.imul(al5, bl8)) | 0),
- (mid = (mid + Math.imul(al5, bh8)) | 0),
- (mid = (mid + Math.imul(ah5, bl8)) | 0),
- (hi = (hi + Math.imul(ah5, bh8)) | 0),
- (lo = (lo + Math.imul(al4, bl9)) | 0),
- (mid = (mid + Math.imul(al4, bh9)) | 0),
- (mid = (mid + Math.imul(ah4, bl9)) | 0),
- (hi = (hi + Math.imul(ah4, bh9)) | 0);
- var w13 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0),
- (w13 &= 67108863),
- (lo = Math.imul(al9, bl5)),
- (mid = Math.imul(al9, bh5)),
- (mid = (mid + Math.imul(ah9, bl5)) | 0),
- (hi = Math.imul(ah9, bh5)),
- (lo = (lo + Math.imul(al8, bl6)) | 0),
- (mid = (mid + Math.imul(al8, bh6)) | 0),
- (mid = (mid + Math.imul(ah8, bl6)) | 0),
- (hi = (hi + Math.imul(ah8, bh6)) | 0),
- (lo = (lo + Math.imul(al7, bl7)) | 0),
- (mid = (mid + Math.imul(al7, bh7)) | 0),
- (mid = (mid + Math.imul(ah7, bl7)) | 0),
- (hi = (hi + Math.imul(ah7, bh7)) | 0),
- (lo = (lo + Math.imul(al6, bl8)) | 0),
- (mid = (mid + Math.imul(al6, bh8)) | 0),
- (mid = (mid + Math.imul(ah6, bl8)) | 0),
- (hi = (hi + Math.imul(ah6, bh8)) | 0),
- (lo = (lo + Math.imul(al5, bl9)) | 0),
- (mid = (mid + Math.imul(al5, bh9)) | 0),
- (mid = (mid + Math.imul(ah5, bl9)) | 0),
- (hi = (hi + Math.imul(ah5, bh9)) | 0);
- var w14 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0),
- (w14 &= 67108863),
- (lo = Math.imul(al9, bl6)),
- (mid = Math.imul(al9, bh6)),
- (mid = (mid + Math.imul(ah9, bl6)) | 0),
- (hi = Math.imul(ah9, bh6)),
- (lo = (lo + Math.imul(al8, bl7)) | 0),
- (mid = (mid + Math.imul(al8, bh7)) | 0),
- (mid = (mid + Math.imul(ah8, bl7)) | 0),
- (hi = (hi + Math.imul(ah8, bh7)) | 0),
- (lo = (lo + Math.imul(al7, bl8)) | 0),
- (mid = (mid + Math.imul(al7, bh8)) | 0),
- (mid = (mid + Math.imul(ah7, bl8)) | 0),
- (hi = (hi + Math.imul(ah7, bh8)) | 0),
- (lo = (lo + Math.imul(al6, bl9)) | 0),
- (mid = (mid + Math.imul(al6, bh9)) | 0),
- (mid = (mid + Math.imul(ah6, bl9)) | 0),
- (hi = (hi + Math.imul(ah6, bh9)) | 0);
- var w15 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0),
- (w15 &= 67108863),
- (lo = Math.imul(al9, bl7)),
- (mid = Math.imul(al9, bh7)),
- (mid = (mid + Math.imul(ah9, bl7)) | 0),
- (hi = Math.imul(ah9, bh7)),
- (lo = (lo + Math.imul(al8, bl8)) | 0),
- (mid = (mid + Math.imul(al8, bh8)) | 0),
- (mid = (mid + Math.imul(ah8, bl8)) | 0),
- (hi = (hi + Math.imul(ah8, bh8)) | 0),
- (lo = (lo + Math.imul(al7, bl9)) | 0),
- (mid = (mid + Math.imul(al7, bh9)) | 0),
- (mid = (mid + Math.imul(ah7, bl9)) | 0),
- (hi = (hi + Math.imul(ah7, bh9)) | 0);
- var w16 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0),
- (w16 &= 67108863),
- (lo = Math.imul(al9, bl8)),
- (mid = Math.imul(al9, bh8)),
- (mid = (mid + Math.imul(ah9, bl8)) | 0),
- (hi = Math.imul(ah9, bh8)),
- (lo = (lo + Math.imul(al8, bl9)) | 0),
- (mid = (mid + Math.imul(al8, bh9)) | 0),
- (mid = (mid + Math.imul(ah8, bl9)) | 0),
- (hi = (hi + Math.imul(ah8, bh9)) | 0);
- var w17 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0),
- (w17 &= 67108863),
- (lo = Math.imul(al9, bl9)),
- (mid = Math.imul(al9, bh9)),
- (mid = (mid + Math.imul(ah9, bl9)) | 0),
- (hi = Math.imul(ah9, bh9));
- var w18 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- return (
- (c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0),
- (w18 &= 67108863),
- (o[0] = w0),
- (o[1] = w1),
- (o[2] = w2),
- (o[3] = w3),
- (o[4] = w4),
- (o[5] = w5),
- (o[6] = w6),
- (o[7] = w7),
- (o[8] = w8),
- (o[9] = w9),
- (o[10] = w10),
- (o[11] = w11),
- (o[12] = w12),
- (o[13] = w13),
- (o[14] = w14),
- (o[15] = w15),
- (o[16] = w16),
- (o[17] = w17),
- (o[18] = w18),
- c !== 0 && ((o[19] = c), out.length++),
- out
- );
- };
- Math.imul || (comb10MulTo = smallMulTo);
- function bigMulTo(self2, num, out) {
- (out.negative = num.negative ^ self2.negative), (out.length = self2.length + num.length);
- for (var carry = 0, hncarry = 0, k = 0; k < out.length - 1; k++) {
- var ncarry = hncarry;
- hncarry = 0;
- for (
- var rword = carry & 67108863, maxJ = Math.min(k, num.length - 1), j = Math.max(0, k - self2.length + 1);
- j <= maxJ;
- j++
- ) {
- var i = k - j,
- a = self2.words[i] | 0,
- b = num.words[j] | 0,
- r = a * b,
- lo = r & 67108863;
- (ncarry = (ncarry + ((r / 67108864) | 0)) | 0),
- (lo = (lo + rword) | 0),
- (rword = lo & 67108863),
- (ncarry = (ncarry + (lo >>> 26)) | 0),
- (hncarry += ncarry >>> 26),
- (ncarry &= 67108863);
- }
- (out.words[k] = rword), (carry = ncarry), (ncarry = hncarry);
- }
- return carry !== 0 ? (out.words[k] = carry) : out.length--, out.strip();
- }
- function jumboMulTo(self2, num, out) {
- var fftm = new FFTM();
- return fftm.mulp(self2, num, out);
- }
- BN.prototype.mulTo = function (num, out) {
- var res,
- len = this.length + num.length;
- return (
- this.length === 10 && num.length === 10
- ? (res = comb10MulTo(this, num, out))
- : len < 63
- ? (res = smallMulTo(this, num, out))
- : len < 1024
- ? (res = bigMulTo(this, num, out))
- : (res = jumboMulTo(this, num, out)),
- res
- );
- };
- function FFTM(x, y) {
- (this.x = x), (this.y = y);
- }
- (FFTM.prototype.makeRBT = function (N) {
- for (var t = new Array(N), l = BN.prototype._countBits(N) - 1, i = 0; i < N; i++) t[i] = this.revBin(i, l, N);
- return t;
- }),
- (FFTM.prototype.revBin = function (x, l, N) {
- if (x === 0 || x === N - 1) return x;
- for (var rb = 0, i = 0; i < l; i++) (rb |= (x & 1) << (l - i - 1)), (x >>= 1);
- return rb;
- }),
- (FFTM.prototype.permute = function (rbt, rws, iws, rtws, itws, N) {
- for (var i = 0; i < N; i++) (rtws[i] = rws[rbt[i]]), (itws[i] = iws[rbt[i]]);
- }),
- (FFTM.prototype.transform = function (rws, iws, rtws, itws, N, rbt) {
- this.permute(rbt, rws, iws, rtws, itws, N);
- for (var s = 1; s < N; s <<= 1)
- for (
- var l = s << 1, rtwdf = Math.cos((2 * Math.PI) / l), itwdf = Math.sin((2 * Math.PI) / l), p = 0;
- p < N;
- p += l
- )
- for (var rtwdf_ = rtwdf, itwdf_ = itwdf, j = 0; j < s; j++) {
- var re = rtws[p + j],
- ie = itws[p + j],
- ro = rtws[p + j + s],
- io = itws[p + j + s],
- rx = rtwdf_ * ro - itwdf_ * io;
- (io = rtwdf_ * io + itwdf_ * ro),
- (ro = rx),
- (rtws[p + j] = re + ro),
- (itws[p + j] = ie + io),
- (rtws[p + j + s] = re - ro),
- (itws[p + j + s] = ie - io),
- j !== l &&
- ((rx = rtwdf * rtwdf_ - itwdf * itwdf_), (itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_), (rtwdf_ = rx));
- }
- }),
- (FFTM.prototype.guessLen13b = function (n, m) {
- var N = Math.max(m, n) | 1,
- odd = N & 1,
- i = 0;
- for (N = (N / 2) | 0; N; N = N >>> 1) i++;
- return 1 << (i + 1 + odd);
- }),
- (FFTM.prototype.conjugate = function (rws, iws, N) {
- if (!(N <= 1))
- for (var i = 0; i < N / 2; i++) {
- var t = rws[i];
- (rws[i] = rws[N - i - 1]),
- (rws[N - i - 1] = t),
- (t = iws[i]),
- (iws[i] = -iws[N - i - 1]),
- (iws[N - i - 1] = -t);
- }
- }),
- (FFTM.prototype.normalize13b = function (ws, N) {
- for (var carry = 0, i = 0; i < N / 2; i++) {
- var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry;
- (ws[i] = w & 67108863), w < 67108864 ? (carry = 0) : (carry = (w / 67108864) | 0);
- }
- return ws;
- }),
- (FFTM.prototype.convert13b = function (ws, len, rws, N) {
- for (var carry = 0, i = 0; i < len; i++)
- (carry = carry + (ws[i] | 0)),
- (rws[2 * i] = carry & 8191),
- (carry = carry >>> 13),
- (rws[2 * i + 1] = carry & 8191),
- (carry = carry >>> 13);
- for (i = 2 * len; i < N; ++i) rws[i] = 0;
- assert(carry === 0), assert((carry & -8192) === 0);
- }),
- (FFTM.prototype.stub = function (N) {
- for (var ph = new Array(N), i = 0; i < N; i++) ph[i] = 0;
- return ph;
- }),
- (FFTM.prototype.mulp = function (x, y, out) {
- var N = 2 * this.guessLen13b(x.length, y.length),
- rbt = this.makeRBT(N),
- _ = this.stub(N),
- rws = new Array(N),
- rwst = new Array(N),
- iwst = new Array(N),
- nrws = new Array(N),
- nrwst = new Array(N),
- niwst = new Array(N),
- rmws = out.words;
- (rmws.length = N),
- this.convert13b(x.words, x.length, rws, N),
- this.convert13b(y.words, y.length, nrws, N),
- this.transform(rws, _, rwst, iwst, N, rbt),
- this.transform(nrws, _, nrwst, niwst, N, rbt);
- for (var i = 0; i < N; i++) {
- var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
- (iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]), (rwst[i] = rx);
- }
- return (
- this.conjugate(rwst, iwst, N),
- this.transform(rwst, iwst, rmws, _, N, rbt),
- this.conjugate(rmws, _, N),
- this.normalize13b(rmws, N),
- (out.negative = x.negative ^ y.negative),
- (out.length = x.length + y.length),
- out.strip()
- );
- }),
- (BN.prototype.mul = function (num) {
- var out = new BN(null);
- return (out.words = new Array(this.length + num.length)), this.mulTo(num, out);
- }),
- (BN.prototype.mulf = function (num) {
- var out = new BN(null);
- return (out.words = new Array(this.length + num.length)), jumboMulTo(this, num, out);
- }),
- (BN.prototype.imul = function (num) {
- return this.clone().mulTo(num, this);
- }),
- (BN.prototype.imuln = function (num) {
- assert(typeof num == "number"), assert(num < 67108864);
- for (var carry = 0, i = 0; i < this.length; i++) {
- var w = (this.words[i] | 0) * num,
- lo = (w & 67108863) + (carry & 67108863);
- (carry >>= 26), (carry += (w / 67108864) | 0), (carry += lo >>> 26), (this.words[i] = lo & 67108863);
- }
- return carry !== 0 && ((this.words[i] = carry), this.length++), this;
- }),
- (BN.prototype.muln = function (num) {
- return this.clone().imuln(num);
- }),
- (BN.prototype.sqr = function () {
- return this.mul(this);
- }),
- (BN.prototype.isqr = function () {
- return this.imul(this.clone());
- }),
- (BN.prototype.pow = function (num) {
- var w = toBitArray(num);
- if (w.length === 0) return new BN(1);
- for (var res = this, i = 0; i < w.length && w[i] === 0; i++, res = res.sqr());
- if (++i < w.length) for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) w[i] !== 0 && (res = res.mul(q));
- return res;
- }),
- (BN.prototype.iushln = function (bits) {
- assert(typeof bits == "number" && bits >= 0);
- var r = bits % 26,
- s = (bits - r) / 26,
- carryMask = (67108863 >>> (26 - r)) << (26 - r),
- i;
- if (r !== 0) {
- var carry = 0;
- for (i = 0; i < this.length; i++) {
- var newCarry = this.words[i] & carryMask,
- c = ((this.words[i] | 0) - newCarry) << r;
- (this.words[i] = c | carry), (carry = newCarry >>> (26 - r));
- }
- carry && ((this.words[i] = carry), this.length++);
- }
- if (s !== 0) {
- for (i = this.length - 1; i >= 0; i--) this.words[i + s] = this.words[i];
- for (i = 0; i < s; i++) this.words[i] = 0;
- this.length += s;
- }
- return this.strip();
- }),
- (BN.prototype.ishln = function (bits) {
- return assert(this.negative === 0), this.iushln(bits);
- }),
- (BN.prototype.iushrn = function (bits, hint, extended) {
- assert(typeof bits == "number" && bits >= 0);
- var h;
- hint ? (h = (hint - (hint % 26)) / 26) : (h = 0);
- var r = bits % 26,
- s = Math.min((bits - r) / 26, this.length),
- mask = 67108863 ^ ((67108863 >>> r) << r),
- maskedWords = extended;
- if (((h -= s), (h = Math.max(0, h)), maskedWords)) {
- for (var i = 0; i < s; i++) maskedWords.words[i] = this.words[i];
- maskedWords.length = s;
- }
- if (s !== 0)
- if (this.length > s) for (this.length -= s, i = 0; i < this.length; i++) this.words[i] = this.words[i + s];
- else (this.words[0] = 0), (this.length = 1);
- var carry = 0;
- for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
- var word = this.words[i] | 0;
- (this.words[i] = (carry << (26 - r)) | (word >>> r)), (carry = word & mask);
- }
- return (
- maskedWords && carry !== 0 && (maskedWords.words[maskedWords.length++] = carry),
- this.length === 0 && ((this.words[0] = 0), (this.length = 1)),
- this.strip()
- );
- }),
- (BN.prototype.ishrn = function (bits, hint, extended) {
- return assert(this.negative === 0), this.iushrn(bits, hint, extended);
- }),
- (BN.prototype.shln = function (bits) {
- return this.clone().ishln(bits);
- }),
- (BN.prototype.ushln = function (bits) {
- return this.clone().iushln(bits);
- }),
- (BN.prototype.shrn = function (bits) {
- return this.clone().ishrn(bits);
- }),
- (BN.prototype.ushrn = function (bits) {
- return this.clone().iushrn(bits);
- }),
- (BN.prototype.testn = function (bit) {
- assert(typeof bit == "number" && bit >= 0);
- var r = bit % 26,
- s = (bit - r) / 26,
- q = 1 << r;
- if (this.length <= s) return !1;
- var w = this.words[s];
- return !!(w & q);
- }),
- (BN.prototype.imaskn = function (bits) {
- assert(typeof bits == "number" && bits >= 0);
- var r = bits % 26,
- s = (bits - r) / 26;
- if ((assert(this.negative === 0, "imaskn works only with positive numbers"), this.length <= s)) return this;
- if ((r !== 0 && s++, (this.length = Math.min(s, this.length)), r !== 0)) {
- var mask = 67108863 ^ ((67108863 >>> r) << r);
- this.words[this.length - 1] &= mask;
- }
- return this.strip();
- }),
- (BN.prototype.maskn = function (bits) {
- return this.clone().imaskn(bits);
- }),
- (BN.prototype.iaddn = function (num) {
- return (
- assert(typeof num == "number"),
- assert(num < 67108864),
- num < 0
- ? this.isubn(-num)
- : this.negative !== 0
- ? this.length === 1 && (this.words[0] | 0) < num
- ? ((this.words[0] = num - (this.words[0] | 0)), (this.negative = 0), this)
- : ((this.negative = 0), this.isubn(num), (this.negative = 1), this)
- : this._iaddn(num)
- );
- }),
- (BN.prototype._iaddn = function (num) {
- this.words[0] += num;
- for (var i = 0; i < this.length && this.words[i] >= 67108864; i++)
- (this.words[i] -= 67108864), i === this.length - 1 ? (this.words[i + 1] = 1) : this.words[i + 1]++;
- return (this.length = Math.max(this.length, i + 1)), this;
- }),
- (BN.prototype.isubn = function (num) {
- if ((assert(typeof num == "number"), assert(num < 67108864), num < 0)) return this.iaddn(-num);
- if (this.negative !== 0) return (this.negative = 0), this.iaddn(num), (this.negative = 1), this;
- if (((this.words[0] -= num), this.length === 1 && this.words[0] < 0))
- (this.words[0] = -this.words[0]), (this.negative = 1);
- else
- for (var i = 0; i < this.length && this.words[i] < 0; i++)
- (this.words[i] += 67108864), (this.words[i + 1] -= 1);
- return this.strip();
- }),
- (BN.prototype.addn = function (num) {
- return this.clone().iaddn(num);
- }),
- (BN.prototype.subn = function (num) {
- return this.clone().isubn(num);
- }),
- (BN.prototype.iabs = function () {
- return (this.negative = 0), this;
- }),
- (BN.prototype.abs = function () {
- return this.clone().iabs();
- }),
- (BN.prototype._ishlnsubmul = function (num, mul, shift) {
- var len = num.length + shift,
- i;
- this._expand(len);
- var w,
- carry = 0;
- for (i = 0; i < num.length; i++) {
- w = (this.words[i + shift] | 0) + carry;
- var right = (num.words[i] | 0) * mul;
- (w -= right & 67108863),
- (carry = (w >> 26) - ((right / 67108864) | 0)),
- (this.words[i + shift] = w & 67108863);
- }
- for (; i < this.length - shift; i++)
- (w = (this.words[i + shift] | 0) + carry), (carry = w >> 26), (this.words[i + shift] = w & 67108863);
- if (carry === 0) return this.strip();
- for (assert(carry === -1), carry = 0, i = 0; i < this.length; i++)
- (w = -(this.words[i] | 0) + carry), (carry = w >> 26), (this.words[i] = w & 67108863);
- return (this.negative = 1), this.strip();
- }),
- (BN.prototype._wordDiv = function (num, mode) {
- var shift = this.length - num.length,
- a = this.clone(),
- b = num,
- bhi = b.words[b.length - 1] | 0,
- bhiBits = this._countBits(bhi);
- (shift = 26 - bhiBits),
- shift !== 0 && ((b = b.ushln(shift)), a.iushln(shift), (bhi = b.words[b.length - 1] | 0));
- var m = a.length - b.length,
- q;
- if (mode !== "mod") {
- (q = new BN(null)), (q.length = m + 1), (q.words = new Array(q.length));
- for (var i = 0; i < q.length; i++) q.words[i] = 0;
- }
- var diff = a.clone()._ishlnsubmul(b, 1, m);
- diff.negative === 0 && ((a = diff), q && (q.words[m] = 1));
- for (var j = m - 1; j >= 0; j--) {
- var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0);
- for (qj = Math.min((qj / bhi) | 0, 67108863), a._ishlnsubmul(b, qj, j); a.negative !== 0; )
- qj--, (a.negative = 0), a._ishlnsubmul(b, 1, j), a.isZero() || (a.negative ^= 1);
- q && (q.words[j] = qj);
- }
- return (
- q && q.strip(),
- a.strip(),
- mode !== "div" && shift !== 0 && a.iushrn(shift),
- {
- div: q || null,
- mod: a,
- }
- );
- }),
- (BN.prototype.divmod = function (num, mode, positive) {
- if ((assert(!num.isZero()), this.isZero()))
- return {
- div: new BN(0),
- mod: new BN(0),
- };
- var div, mod, res;
- return this.negative !== 0 && num.negative === 0
- ? ((res = this.neg().divmod(num, mode)),
- mode !== "mod" && (div = res.div.neg()),
- mode !== "div" && ((mod = res.mod.neg()), positive && mod.negative !== 0 && mod.iadd(num)),
- {
- div,
- mod,
- })
- : this.negative === 0 && num.negative !== 0
- ? ((res = this.divmod(num.neg(), mode)),
- mode !== "mod" && (div = res.div.neg()),
- {
- div,
- mod: res.mod,
- })
- : (this.negative & num.negative) !== 0
- ? ((res = this.neg().divmod(num.neg(), mode)),
- mode !== "div" && ((mod = res.mod.neg()), positive && mod.negative !== 0 && mod.isub(num)),
- {
- div: res.div,
- mod,
- })
- : num.length > this.length || this.cmp(num) < 0
- ? {
- div: new BN(0),
- mod: this,
- }
- : num.length === 1
- ? mode === "div"
- ? {
- div: this.divn(num.words[0]),
- mod: null,
- }
- : mode === "mod"
- ? {
- div: null,
- mod: new BN(this.modn(num.words[0])),
- }
- : {
- div: this.divn(num.words[0]),
- mod: new BN(this.modn(num.words[0])),
- }
- : this._wordDiv(num, mode);
- }),
- (BN.prototype.div = function (num) {
- return this.divmod(num, "div", !1).div;
- }),
- (BN.prototype.mod = function (num) {
- return this.divmod(num, "mod", !1).mod;
- }),
- (BN.prototype.umod = function (num) {
- return this.divmod(num, "mod", !0).mod;
- }),
- (BN.prototype.divRound = function (num) {
- var dm = this.divmod(num);
- if (dm.mod.isZero()) return dm.div;
- var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod,
- half = num.ushrn(1),
- r2 = num.andln(1),
- cmp = mod.cmp(half);
- return cmp < 0 || (r2 === 1 && cmp === 0)
- ? dm.div
- : dm.div.negative !== 0
- ? dm.div.isubn(1)
- : dm.div.iaddn(1);
- }),
- (BN.prototype.modn = function (num) {
- assert(num <= 67108863);
- for (var p = (1 << 26) % num, acc = 0, i = this.length - 1; i >= 0; i--)
- acc = (p * acc + (this.words[i] | 0)) % num;
- return acc;
- }),
- (BN.prototype.idivn = function (num) {
- assert(num <= 67108863);
- for (var carry = 0, i = this.length - 1; i >= 0; i--) {
- var w = (this.words[i] | 0) + carry * 67108864;
- (this.words[i] = (w / num) | 0), (carry = w % num);
- }
- return this.strip();
- }),
- (BN.prototype.divn = function (num) {
- return this.clone().idivn(num);
- }),
- (BN.prototype.egcd = function (p) {
- assert(p.negative === 0), assert(!p.isZero());
- var x = this,
- y = p.clone();
- x.negative !== 0 ? (x = x.umod(p)) : (x = x.clone());
- for (var A = new BN(1), B = new BN(0), C = new BN(0), D = new BN(1), g = 0; x.isEven() && y.isEven(); )
- x.iushrn(1), y.iushrn(1), ++g;
- for (var yp = y.clone(), xp = x.clone(); !x.isZero(); ) {
- for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
- if (i > 0)
- for (x.iushrn(i); i-- > 0; )
- (A.isOdd() || B.isOdd()) && (A.iadd(yp), B.isub(xp)), A.iushrn(1), B.iushrn(1);
- for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
- if (j > 0)
- for (y.iushrn(j); j-- > 0; )
- (C.isOdd() || D.isOdd()) && (C.iadd(yp), D.isub(xp)), C.iushrn(1), D.iushrn(1);
- x.cmp(y) >= 0 ? (x.isub(y), A.isub(C), B.isub(D)) : (y.isub(x), C.isub(A), D.isub(B));
- }
- return {
- a: C,
- b: D,
- gcd: y.iushln(g),
- };
- }),
- (BN.prototype._invmp = function (p) {
- assert(p.negative === 0), assert(!p.isZero());
- var a = this,
- b = p.clone();
- a.negative !== 0 ? (a = a.umod(p)) : (a = a.clone());
- for (var x1 = new BN(1), x2 = new BN(0), delta = b.clone(); a.cmpn(1) > 0 && b.cmpn(1) > 0; ) {
- for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
- if (i > 0) for (a.iushrn(i); i-- > 0; ) x1.isOdd() && x1.iadd(delta), x1.iushrn(1);
- for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
- if (j > 0) for (b.iushrn(j); j-- > 0; ) x2.isOdd() && x2.iadd(delta), x2.iushrn(1);
- a.cmp(b) >= 0 ? (a.isub(b), x1.isub(x2)) : (b.isub(a), x2.isub(x1));
- }
- var res;
- return a.cmpn(1) === 0 ? (res = x1) : (res = x2), res.cmpn(0) < 0 && res.iadd(p), res;
- }),
- (BN.prototype.gcd = function (num) {
- if (this.isZero()) return num.abs();
- if (num.isZero()) return this.abs();
- var a = this.clone(),
- b = num.clone();
- (a.negative = 0), (b.negative = 0);
- for (var shift = 0; a.isEven() && b.isEven(); shift++) a.iushrn(1), b.iushrn(1);
- do {
- for (; a.isEven(); ) a.iushrn(1);
- for (; b.isEven(); ) b.iushrn(1);
- var r = a.cmp(b);
- if (r < 0) {
- var t = a;
- (a = b), (b = t);
- } else if (r === 0 || b.cmpn(1) === 0) break;
- a.isub(b);
- } while (!0);
- return b.iushln(shift);
- }),
- (BN.prototype.invm = function (num) {
- return this.egcd(num).a.umod(num);
- }),
- (BN.prototype.isEven = function () {
- return (this.words[0] & 1) === 0;
- }),
- (BN.prototype.isOdd = function () {
- return (this.words[0] & 1) === 1;
- }),
- (BN.prototype.andln = function (num) {
- return this.words[0] & num;
- }),
- (BN.prototype.bincn = function (bit) {
- assert(typeof bit == "number");
- var r = bit % 26,
- s = (bit - r) / 26,
- q = 1 << r;
- if (this.length <= s) return this._expand(s + 1), (this.words[s] |= q), this;
- for (var carry = q, i = s; carry !== 0 && i < this.length; i++) {
- var w = this.words[i] | 0;
- (w += carry), (carry = w >>> 26), (w &= 67108863), (this.words[i] = w);
- }
- return carry !== 0 && ((this.words[i] = carry), this.length++), this;
- }),
- (BN.prototype.isZero = function () {
- return this.length === 1 && this.words[0] === 0;
- }),
- (BN.prototype.cmpn = function (num) {
- var negative = num < 0;
- if (this.negative !== 0 && !negative) return -1;
- if (this.negative === 0 && negative) return 1;
- this.strip();
- var res;
- if (this.length > 1) res = 1;
- else {
- negative && (num = -num), assert(num <= 67108863, "Number is too big");
- var w = this.words[0] | 0;
- res = w === num ? 0 : w < num ? -1 : 1;
- }
- return this.negative !== 0 ? -res | 0 : res;
- }),
- (BN.prototype.cmp = function (num) {
- if (this.negative !== 0 && num.negative === 0) return -1;
- if (this.negative === 0 && num.negative !== 0) return 1;
- var res = this.ucmp(num);
- return this.negative !== 0 ? -res | 0 : res;
- }),
- (BN.prototype.ucmp = function (num) {
- if (this.length > num.length) return 1;
- if (this.length < num.length) return -1;
- for (var res = 0, i = this.length - 1; i >= 0; i--) {
- var a = this.words[i] | 0,
- b = num.words[i] | 0;
- if (a !== b) {
- a < b ? (res = -1) : a > b && (res = 1);
- break;
- }
- }
- return res;
- }),
- (BN.prototype.gtn = function (num) {
- return this.cmpn(num) === 1;
- }),
- (BN.prototype.gt = function (num) {
- return this.cmp(num) === 1;
- }),
- (BN.prototype.gten = function (num) {
- return this.cmpn(num) >= 0;
- }),
- (BN.prototype.gte = function (num) {
- return this.cmp(num) >= 0;
- }),
- (BN.prototype.ltn = function (num) {
- return this.cmpn(num) === -1;
- }),
- (BN.prototype.lt = function (num) {
- return this.cmp(num) === -1;
- }),
- (BN.prototype.lten = function (num) {
- return this.cmpn(num) <= 0;
- }),
- (BN.prototype.lte = function (num) {
- return this.cmp(num) <= 0;
- }),
- (BN.prototype.eqn = function (num) {
- return this.cmpn(num) === 0;
- }),
- (BN.prototype.eq = function (num) {
- return this.cmp(num) === 0;
- }),
- (BN.red = function (num) {
- return new Red(num);
- }),
- (BN.prototype.toRed = function (ctx) {
- return (
- assert(!this.red, "Already a number in reduction context"),
- assert(this.negative === 0, "red works only with positives"),
- ctx.convertTo(this)._forceRed(ctx)
- );
- }),
- (BN.prototype.fromRed = function () {
- return assert(this.red, "fromRed works only with numbers in reduction context"), this.red.convertFrom(this);
- }),
- (BN.prototype._forceRed = function (ctx) {
- return (this.red = ctx), this;
- }),
- (BN.prototype.forceRed = function (ctx) {
- return assert(!this.red, "Already a number in reduction context"), this._forceRed(ctx);
- }),
- (BN.prototype.redAdd = function (num) {
- return assert(this.red, "redAdd works only with red numbers"), this.red.add(this, num);
- }),
- (BN.prototype.redIAdd = function (num) {
- return assert(this.red, "redIAdd works only with red numbers"), this.red.iadd(this, num);
- }),
- (BN.prototype.redSub = function (num) {
- return assert(this.red, "redSub works only with red numbers"), this.red.sub(this, num);
- }),
- (BN.prototype.redISub = function (num) {
- return assert(this.red, "redISub works only with red numbers"), this.red.isub(this, num);
- }),
- (BN.prototype.redShl = function (num) {
- return assert(this.red, "redShl works only with red numbers"), this.red.shl(this, num);
- }),
- (BN.prototype.redMul = function (num) {
- return (
- assert(this.red, "redMul works only with red numbers"),
- this.red._verify2(this, num),
- this.red.mul(this, num)
- );
- }),
- (BN.prototype.redIMul = function (num) {
- return (
- assert(this.red, "redMul works only with red numbers"),
- this.red._verify2(this, num),
- this.red.imul(this, num)
- );
- }),
- (BN.prototype.redSqr = function () {
- return assert(this.red, "redSqr works only with red numbers"), this.red._verify1(this), this.red.sqr(this);
- }),
- (BN.prototype.redISqr = function () {
- return assert(this.red, "redISqr works only with red numbers"), this.red._verify1(this), this.red.isqr(this);
- }),
- (BN.prototype.redSqrt = function () {
- return assert(this.red, "redSqrt works only with red numbers"), this.red._verify1(this), this.red.sqrt(this);
- }),
- (BN.prototype.redInvm = function () {
- return assert(this.red, "redInvm works only with red numbers"), this.red._verify1(this), this.red.invm(this);
- }),
- (BN.prototype.redNeg = function () {
- return assert(this.red, "redNeg works only with red numbers"), this.red._verify1(this), this.red.neg(this);
- }),
- (BN.prototype.redPow = function (num) {
- return assert(this.red && !num.red, "redPow(normalNum)"), this.red._verify1(this), this.red.pow(this, num);
- });
- var primes = {
- k256: null,
- p224: null,
- p192: null,
- p25519: null,
- };
- function MPrime(name, p) {
- (this.name = name),
- (this.p = new BN(p, 16)),
- (this.n = this.p.bitLength()),
- (this.k = new BN(1).iushln(this.n).isub(this.p)),
- (this.tmp = this._tmp());
- }
- (MPrime.prototype._tmp = function () {
- var tmp = new BN(null);
- return (tmp.words = new Array(Math.ceil(this.n / 13))), tmp;
- }),
- (MPrime.prototype.ireduce = function (num) {
- var r = num,
- rlen;
- do this.split(r, this.tmp), (r = this.imulK(r)), (r = r.iadd(this.tmp)), (rlen = r.bitLength());
- while (rlen > this.n);
- var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
- return (
- cmp === 0
- ? ((r.words[0] = 0), (r.length = 1))
- : cmp > 0
- ? r.isub(this.p)
- : r.strip !== void 0
- ? r.strip()
- : r._strip(),
- r
- );
- }),
- (MPrime.prototype.split = function (input, out) {
- input.iushrn(this.n, 0, out);
- }),
- (MPrime.prototype.imulK = function (num) {
- return num.imul(this.k);
- });
- function K256() {
- MPrime.call(this, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f");
- }
- inherits(K256, MPrime),
- (K256.prototype.split = function (input, output) {
- for (var mask = 4194303, outLen = Math.min(input.length, 9), i = 0; i < outLen; i++)
- output.words[i] = input.words[i];
- if (((output.length = outLen), input.length <= 9)) {
- (input.words[0] = 0), (input.length = 1);
- return;
- }
- var prev = input.words[9];
- for (output.words[output.length++] = prev & mask, i = 10; i < input.length; i++) {
- var next = input.words[i] | 0;
- (input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22)), (prev = next);
- }
- (prev >>>= 22),
- (input.words[i - 10] = prev),
- prev === 0 && input.length > 10 ? (input.length -= 10) : (input.length -= 9);
- }),
- (K256.prototype.imulK = function (num) {
- (num.words[num.length] = 0), (num.words[num.length + 1] = 0), (num.length += 2);
- for (var lo = 0, i = 0; i < num.length; i++) {
- var w = num.words[i] | 0;
- (lo += w * 977), (num.words[i] = lo & 67108863), (lo = w * 64 + ((lo / 67108864) | 0));
- }
- return (
- num.words[num.length - 1] === 0 && (num.length--, num.words[num.length - 1] === 0 && num.length--), num
- );
- });
- function P224() {
- MPrime.call(this, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001");
- }
- inherits(P224, MPrime);
- function P192() {
- MPrime.call(this, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff");
- }
- inherits(P192, MPrime);
- function P25519() {
- MPrime.call(this, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed");
- }
- inherits(P25519, MPrime),
- (P25519.prototype.imulK = function (num) {
- for (var carry = 0, i = 0; i < num.length; i++) {
- var hi = (num.words[i] | 0) * 19 + carry,
- lo = hi & 67108863;
- (hi >>>= 26), (num.words[i] = lo), (carry = hi);
- }
- return carry !== 0 && (num.words[num.length++] = carry), num;
- }),
- (BN._prime = function (name) {
- if (primes[name]) return primes[name];
- var prime2;
- if (name === "k256") prime2 = new K256();
- else if (name === "p224") prime2 = new P224();
- else if (name === "p192") prime2 = new P192();
- else if (name === "p25519") prime2 = new P25519();
- else throw new Error("Unknown prime " + name);
- return (primes[name] = prime2), prime2;
- });
- function Red(m) {
- if (typeof m == "string") {
- var prime = BN._prime(m);
- (this.m = prime.p), (this.prime = prime);
- } else assert(m.gtn(1), "modulus must be greater than 1"), (this.m = m), (this.prime = null);
- }
- (Red.prototype._verify1 = function (a) {
- assert(a.negative === 0, "red works only with positives"), assert(a.red, "red works only with red numbers");
- }),
- (Red.prototype._verify2 = function (a, b) {
- assert((a.negative | b.negative) === 0, "red works only with positives"),
- assert(a.red && a.red === b.red, "red works only with red numbers");
- }),
- (Red.prototype.imod = function (a) {
- return this.prime ? this.prime.ireduce(a)._forceRed(this) : a.umod(this.m)._forceRed(this);
- }),
- (Red.prototype.neg = function (a) {
- return a.isZero() ? a.clone() : this.m.sub(a)._forceRed(this);
- }),
- (Red.prototype.add = function (a, b) {
- this._verify2(a, b);
- var res = a.add(b);
- return res.cmp(this.m) >= 0 && res.isub(this.m), res._forceRed(this);
- }),
- (Red.prototype.iadd = function (a, b) {
- this._verify2(a, b);
- var res = a.iadd(b);
- return res.cmp(this.m) >= 0 && res.isub(this.m), res;
- }),
- (Red.prototype.sub = function (a, b) {
- this._verify2(a, b);
- var res = a.sub(b);
- return res.cmpn(0) < 0 && res.iadd(this.m), res._forceRed(this);
- }),
- (Red.prototype.isub = function (a, b) {
- this._verify2(a, b);
- var res = a.isub(b);
- return res.cmpn(0) < 0 && res.iadd(this.m), res;
- }),
- (Red.prototype.shl = function (a, num) {
- return this._verify1(a), this.imod(a.ushln(num));
- }),
- (Red.prototype.imul = function (a, b) {
- return this._verify2(a, b), this.imod(a.imul(b));
- }),
- (Red.prototype.mul = function (a, b) {
- return this._verify2(a, b), this.imod(a.mul(b));
- }),
- (Red.prototype.isqr = function (a) {
- return this.imul(a, a.clone());
- }),
- (Red.prototype.sqr = function (a) {
- return this.mul(a, a);
- }),
- (Red.prototype.sqrt = function (a) {
- if (a.isZero()) return a.clone();
- var mod3 = this.m.andln(3);
- if ((assert(mod3 % 2 === 1), mod3 === 3)) {
- var pow = this.m.add(new BN(1)).iushrn(2);
- return this.pow(a, pow);
- }
- for (var q = this.m.subn(1), s = 0; !q.isZero() && q.andln(1) === 0; ) s++, q.iushrn(1);
- assert(!q.isZero());
- var one = new BN(1).toRed(this),
- nOne = one.redNeg(),
- lpow = this.m.subn(1).iushrn(1),
- z = this.m.bitLength();
- for (z = new BN(2 * z * z).toRed(this); this.pow(z, lpow).cmp(nOne) !== 0; ) z.redIAdd(nOne);
- for (
- var c = this.pow(z, q), r = this.pow(a, q.addn(1).iushrn(1)), t = this.pow(a, q), m = s;
- t.cmp(one) !== 0;
-
- ) {
- for (var tmp = t, i = 0; tmp.cmp(one) !== 0; i++) tmp = tmp.redSqr();
- assert(i < m);
- var b = this.pow(c, new BN(1).iushln(m - i - 1));
- (r = r.redMul(b)), (c = b.redSqr()), (t = t.redMul(c)), (m = i);
- }
- return r;
- }),
- (Red.prototype.invm = function (a) {
- var inv = a._invmp(this.m);
- return inv.negative !== 0 ? ((inv.negative = 0), this.imod(inv).redNeg()) : this.imod(inv);
- }),
- (Red.prototype.pow = function (a, num) {
- if (num.isZero()) return new BN(1).toRed(this);
- if (num.cmpn(1) === 0) return a.clone();
- var windowSize = 4,
- wnd = new Array(1 << windowSize);
- (wnd[0] = new BN(1).toRed(this)), (wnd[1] = a);
- for (var i = 2; i < wnd.length; i++) wnd[i] = this.mul(wnd[i - 1], a);
- var res = wnd[0],
- current = 0,
- currentLen = 0,
- start = num.bitLength() % 26;
- for (start === 0 && (start = 26), i = num.length - 1; i >= 0; i--) {
- for (var word = num.words[i], j = start - 1; j >= 0; j--) {
- var bit = (word >> j) & 1;
- if ((res !== wnd[0] && (res = this.sqr(res)), bit === 0 && current === 0)) {
- currentLen = 0;
- continue;
- }
- (current <<= 1),
- (current |= bit),
- currentLen++,
- !(currentLen !== windowSize && (i !== 0 || j !== 0)) &&
- ((res = this.mul(res, wnd[current])), (currentLen = 0), (current = 0));
- }
- start = 26;
- }
- return res;
- }),
- (Red.prototype.convertTo = function (num) {
- var r = num.umod(this.m);
- return r === num ? r.clone() : r;
- }),
- (Red.prototype.convertFrom = function (num) {
- var res = num.clone();
- return (res.red = null), res;
- }),
- (BN.mont = function (num) {
- return new Mont(num);
- });
- function Mont(m) {
- Red.call(this, m),
- (this.shift = this.m.bitLength()),
- this.shift % 26 !== 0 && (this.shift += 26 - (this.shift % 26)),
- (this.r = new BN(1).iushln(this.shift)),
- (this.r2 = this.imod(this.r.sqr())),
- (this.rinv = this.r._invmp(this.m)),
- (this.minv = this.rinv.mul(this.r).isubn(1).div(this.m)),
- (this.minv = this.minv.umod(this.r)),
- (this.minv = this.r.sub(this.minv));
- }
- inherits(Mont, Red),
- (Mont.prototype.convertTo = function (num) {
- return this.imod(num.ushln(this.shift));
- }),
- (Mont.prototype.convertFrom = function (num) {
- var r = this.imod(num.mul(this.rinv));
- return (r.red = null), r;
- }),
- (Mont.prototype.imul = function (a, b) {
- if (a.isZero() || b.isZero()) return (a.words[0] = 0), (a.length = 1), a;
- var t = a.imul(b),
- c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),
- u = t.isub(c).iushrn(this.shift),
- res = u;
- return (
- u.cmp(this.m) >= 0 ? (res = u.isub(this.m)) : u.cmpn(0) < 0 && (res = u.iadd(this.m)), res._forceRed(this)
- );
- }),
- (Mont.prototype.mul = function (a, b) {
- if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
- var t = a.mul(b),
- c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),
- u = t.isub(c).iushrn(this.shift),
- res = u;
- return (
- u.cmp(this.m) >= 0 ? (res = u.isub(this.m)) : u.cmpn(0) < 0 && (res = u.iadd(this.m)), res._forceRed(this)
- );
- }),
- (Mont.prototype.invm = function (a) {
- var res = this.imod(a._invmp(this.m).mul(this.r2));
- return res._forceRed(this);
- });
- })(typeof module > "u" || module, exports);
- },
-});
+var require_bn5 = require_bn;
// node_modules/safer-buffer/safer.js
var require_safer = __commonJS({
@@ -17538,6 +9537,7 @@ var require_reporter = __commonJS({
errors: [],
};
}
+ Reporter.prototype = {};
exports.Reporter = Reporter;
Reporter.prototype.isError = function (obj) {
return obj instanceof ReporterError;
@@ -17710,6 +9710,7 @@ var require_buffer = __commonJS({
else if (Buffer2.isBuffer(value)) (this.value = value), (this.length = value.length);
else return reporter.error("Unsupported type: " + typeof value);
}
+ EncoderBuffer.prototype = {};
exports.EncoderBuffer = EncoderBuffer;
EncoderBuffer.isEncoderBuffer = function (data) {
return data instanceof EncoderBuffer
@@ -17821,6 +9822,7 @@ var require_node = __commonJS({
(state.contains = null),
state.parent || ((state.children = []), this._wrap());
}
+ Node.prototype = {};
module.exports = Node;
var stateProps = [
"enc",
@@ -18255,6 +10257,7 @@ var require_der2 = __commonJS({
(this.tree = new DERNode()),
this.tree._init(entity.body);
}
+ DEREncoder.prototype = {};
module.exports = DEREncoder;
DEREncoder.prototype.encode = function (data, reporter) {
return this.tree._encode(data, reporter).join();
@@ -18470,6 +10473,7 @@ var require_der3 = __commonJS({
(this.tree = new DERNode()),
this.tree._init(entity.body);
}
+ DERDecoder.prototype = {};
module.exports = DERDecoder;
DERDecoder.prototype.decode = function (data, options) {
return (
@@ -18721,6 +10725,7 @@ var require_api = __commonJS({
function Entity(name, body) {
(this.name = name), (this.body = body), (this.decoders = {}), (this.encoders = {});
}
+ Entity.prototype = {};
Entity.prototype._createNamed = function (Base) {
let name = this.name;
function Generated(entity) {
@@ -19346,12 +11351,12 @@ var require_verify = __commonJS({
// node_modules/browserify-sign/browser/index.js
var require_browser8 = __commonJS({
"node_modules/browserify-sign/browser/index.js"(exports, module) {
- var Buffer2 = require_safe_buffer().Buffer,
- createHash = require_browser2(),
- inherits = require_inherits_browser(),
- sign = require_sign(),
- verify = require_verify(),
- algorithms = require_algorithms();
+ var Buffer2 = require_safe_buffer().Buffer;
+ var createHash = require_browser2();
+ var inherits = require_inherits_browser();
+ var sign = require_sign();
+ var verify = require_verify();
+ var algorithms = require_algorithms();
Object.keys(algorithms).forEach(function (key) {
(algorithms[key].id = Buffer2.from(algorithms[key].id, "hex")), (algorithms[key.toLowerCase()] = algorithms[key]);
});
@@ -19411,1991 +11416,7 @@ var require_browser8 = __commonJS({
});
// node_modules/create-ecdh/node_modules/bn.js/lib/bn.js
-var require_bn6 = __commonJS({
- "node_modules/create-ecdh/node_modules/bn.js/lib/bn.js"(exports, module) {
- (function (module2, exports2) {
- "use strict";
- function assert(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 BN(number, base, endian) {
- if (BN.isBN(number)) return number;
- (this.negative = 0),
- (this.words = null),
- (this.length = 0),
- (this.red = null),
- number !== null &&
- ((base === "le" || base === "be") && ((endian = base), (base = 10)),
- this._init(number || 0, base || 10, endian || "be"));
- }
- typeof module2 == "object" ? (module2.exports = BN) : (exports2.BN = BN), (BN.BN = BN), (BN.wordSize = 26);
- var Buffer2 = Buffer;
- (BN.isBN = function (num) {
- return num instanceof BN
- ? !0
- : num !== null &&
- typeof num == "object" &&
- num.constructor.wordSize === BN.wordSize &&
- Array.isArray(num.words);
- }),
- (BN.max = function (left, right) {
- return left.cmp(right) > 0 ? left : right;
- }),
- (BN.min = function (left, right) {
- return left.cmp(right) < 0 ? left : right;
- }),
- (BN.prototype._init = function (number, base, endian) {
- if (typeof number == "number") return this._initNumber(number, base, endian);
- if (typeof number == "object") return this._initArray(number, base, endian);
- base === "hex" && (base = 16),
- assert(base === (base | 0) && base >= 2 && base <= 36),
- (number = number.toString().replace(/\s+/g, ""));
- var start = 0;
- number[0] === "-" && (start++, (this.negative = 1)),
- start < number.length &&
- (base === 16
- ? this._parseHex(number, start, endian)
- : (this._parseBase(number, base, start),
- endian === "le" && this._initArray(this.toArray(), base, endian)));
- }),
- (BN.prototype._initNumber = function (number, base, endian) {
- number < 0 && ((this.negative = 1), (number = -number)),
- number < 67108864
- ? ((this.words = [number & 67108863]), (this.length = 1))
- : number < 4503599627370496
- ? ((this.words = [number & 67108863, (number / 67108864) & 67108863]), (this.length = 2))
- : (assert(number < 9007199254740992),
- (this.words = [number & 67108863, (number / 67108864) & 67108863, 1]),
- (this.length = 3)),
- endian === "le" && this._initArray(this.toArray(), base, endian);
- }),
- (BN.prototype._initArray = function (number, base, endian) {
- if ((assert(typeof number.length == "number"), number.length <= 0))
- return (this.words = [0]), (this.length = 1), 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,
- 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),
- 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),
- off >= 26 && ((off -= 26), j++);
- return this.strip();
- });
- function parseHex4Bits(string, index) {
- var c = string.charCodeAt(index);
- return c >= 65 && c <= 70 ? c - 55 : c >= 97 && c <= 102 ? c - 87 : (c - 48) & 15;
- }
- function parseHexByte(string, lowerBound, index) {
- var r = parseHex4Bits(string, index);
- return index - 1 >= lowerBound && (r |= parseHex4Bits(string, index - 1) << 4), r;
- }
- BN.prototype._parseHex = function (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,
- j = 0,
- w;
- if (endian === "be")
- for (i = number.length - 1; i >= start; i -= 2)
- (w = parseHexByte(number, start, i) << off),
- (this.words[j] |= w & 67108863),
- off >= 18 ? ((off -= 18), (j += 1), (this.words[j] |= w >>> 26)) : (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),
- off >= 18 ? ((off -= 18), (j += 1), (this.words[j] |= w >>> 26)) : (off += 8);
- }
- this.strip();
- };
- function parseBase(str, start, end, mul) {
- for (var r = 0, len = Math.min(str.length, end), i = start; i < len; i++) {
- var c = str.charCodeAt(i) - 48;
- (r *= mul), c >= 49 ? (r += c - 49 + 10) : c >= 17 ? (r += c - 17 + 10) : (r += c);
- }
- return r;
- }
- (BN.prototype._parseBase = function (number, base, start) {
- (this.words = [0]), (this.length = 1);
- for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) limbLen++;
- limbLen--, (limbPow = (limbPow / base) | 0);
- for (
- var total = number.length - start,
- mod = total % limbLen,
- end = Math.min(total, total - mod) + start,
- word = 0,
- i = start;
- i < end;
- i += limbLen
- )
- (word = parseBase(number, i, i + limbLen, base)),
- this.imuln(limbPow),
- this.words[0] + word < 67108864 ? (this.words[0] += word) : this._iaddn(word);
- if (mod !== 0) {
- var pow = 1;
- for (word = parseBase(number, i, number.length, base), i = 0; i < mod; i++) pow *= base;
- this.imuln(pow), this.words[0] + word < 67108864 ? (this.words[0] += word) : this._iaddn(word);
- }
- this.strip();
- }),
- (BN.prototype.copy = function (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);
- }),
- (BN.prototype.clone = function () {
- var r = new BN(null);
- return this.copy(r), r;
- }),
- (BN.prototype._expand = function (size) {
- for (; this.length < size; ) this.words[this.length++] = 0;
- return this;
- }),
- (BN.prototype.strip = function () {
- for (; this.length > 1 && this.words[this.length - 1] === 0; ) this.length--;
- return this._normSign();
- }),
- (BN.prototype._normSign = function () {
- return this.length === 1 && this.words[0] === 0 && (this.negative = 0), this;
- }),
- (BN.prototype.inspect = function () {
- return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
- });
- var zeros = [
- "",
- "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",
- ],
- 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,
- ],
- 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,
- ];
- (BN.prototype.toString = function (base, padding) {
- (base = base || 10), (padding = padding | 0 || 1);
- var out;
- if (base === 16 || base === "hex") {
- out = "";
- for (var off = 0, carry = 0, i = 0; i < this.length; i++) {
- var w = this.words[i],
- word = (((w << off) | carry) & 16777215).toString(16);
- (carry = (w >>> (24 - off)) & 16777215),
- carry !== 0 || i !== this.length - 1 ? (out = zeros[6 - word.length] + word + out) : (out = word + out),
- (off += 2),
- off >= 26 && ((off -= 26), i--);
- }
- for (carry !== 0 && (out = carry.toString(16) + out); out.length % padding !== 0; ) out = "0" + out;
- return this.negative !== 0 && (out = "-" + out), out;
- }
- if (base === (base | 0) && base >= 2 && base <= 36) {
- var groupSize = groupSizes[base],
- groupBase = groupBases[base];
- out = "";
- var c = this.clone();
- for (c.negative = 0; !c.isZero(); ) {
- var r = c.modn(groupBase).toString(base);
- (c = c.idivn(groupBase)), c.isZero() ? (out = r + out) : (out = zeros[groupSize - r.length] + r + out);
- }
- for (this.isZero() && (out = "0" + out); out.length % padding !== 0; ) out = "0" + out;
- return this.negative !== 0 && (out = "-" + out), out;
- }
- assert(!1, "Base should be between 2 and 36");
- }),
- (BN.prototype.toNumber = function () {
- var ret = this.words[0];
- return (
- this.length === 2
- ? (ret += this.words[1] * 67108864)
- : this.length === 3 && this.words[2] === 1
- ? (ret += 4503599627370496 + this.words[1] * 67108864)
- : this.length > 2 && assert(!1, "Number can only safely store up to 53 bits"),
- this.negative !== 0 ? -ret : ret
- );
- }),
- (BN.prototype.toJSON = function () {
- return this.toString(16);
- }),
- (BN.prototype.toBuffer = function (endian, length) {
- return assert(typeof Buffer2 < "u"), this.toArrayLike(Buffer2, endian, length);
- }),
- (BN.prototype.toArray = function (endian, length) {
- return this.toArrayLike(Array, endian, length);
- }),
- (BN.prototype.toArrayLike = function (ArrayType, endian, length) {
- var byteLength = this.byteLength(),
- reqLength = length || Math.max(1, byteLength);
- assert(byteLength <= reqLength, "byte array longer than desired length"),
- assert(reqLength > 0, "Requested array length <= 0"),
- this.strip();
- var littleEndian = endian === "le",
- res = new ArrayType(reqLength),
- b,
- i,
- q = this.clone();
- if (littleEndian) {
- for (i = 0; !q.isZero(); i++) (b = q.andln(255)), q.iushrn(8), (res[i] = b);
- for (; i < reqLength; i++) res[i] = 0;
- } else {
- for (i = 0; i < reqLength - byteLength; i++) res[i] = 0;
- for (i = 0; !q.isZero(); i++) (b = q.andln(255)), q.iushrn(8), (res[reqLength - i - 1] = b);
- }
- return res;
- }),
- Math.clz32
- ? (BN.prototype._countBits = function (w) {
- return 32 - Math.clz32(w);
- })
- : (BN.prototype._countBits = function (w) {
- var t = w,
- r = 0;
- return (
- t >= 4096 && ((r += 13), (t >>>= 13)),
- t >= 64 && ((r += 7), (t >>>= 7)),
- t >= 8 && ((r += 4), (t >>>= 4)),
- t >= 2 && ((r += 2), (t >>>= 2)),
- r + t
- );
- }),
- (BN.prototype._zeroBits = function (w) {
- if (w === 0) return 26;
- var t = w,
- r = 0;
- return (
- (t & 8191) === 0 && ((r += 13), (t >>>= 13)),
- (t & 127) === 0 && ((r += 7), (t >>>= 7)),
- (t & 15) === 0 && ((r += 4), (t >>>= 4)),
- (t & 3) === 0 && ((r += 2), (t >>>= 2)),
- (t & 1) === 0 && r++,
- r
- );
- }),
- (BN.prototype.bitLength = function () {
- var w = this.words[this.length - 1],
- hi = this._countBits(w);
- return (this.length - 1) * 26 + hi;
- });
- function toBitArray(num) {
- for (var w = new Array(num.bitLength()), bit = 0; bit < w.length; bit++) {
- var off = (bit / 26) | 0,
- wbit = bit % 26;
- w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
- }
- return w;
- }
- (BN.prototype.zeroBits = function () {
- if (this.isZero()) return 0;
- for (var r = 0, i = 0; i < this.length; i++) {
- var b = this._zeroBits(this.words[i]);
- if (((r += b), b !== 26)) break;
- }
- return r;
- }),
- (BN.prototype.byteLength = function () {
- return Math.ceil(this.bitLength() / 8);
- }),
- (BN.prototype.toTwos = function (width) {
- return this.negative !== 0 ? this.abs().inotn(width).iaddn(1) : this.clone();
- }),
- (BN.prototype.fromTwos = function (width) {
- return this.testn(width - 1) ? this.notn(width).iaddn(1).ineg() : this.clone();
- }),
- (BN.prototype.isNeg = function () {
- return this.negative !== 0;
- }),
- (BN.prototype.neg = function () {
- return this.clone().ineg();
- }),
- (BN.prototype.ineg = function () {
- return this.isZero() || (this.negative ^= 1), this;
- }),
- (BN.prototype.iuor = function (num) {
- for (; 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();
- }),
- (BN.prototype.ior = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuor(num);
- }),
- (BN.prototype.or = function (num) {
- return this.length > num.length ? this.clone().ior(num) : num.clone().ior(this);
- }),
- (BN.prototype.uor = function (num) {
- return this.length > num.length ? this.clone().iuor(num) : num.clone().iuor(this);
- }),
- (BN.prototype.iuand = function (num) {
- var b;
- this.length > num.length ? (b = num) : (b = this);
- for (var i = 0; i < b.length; i++) this.words[i] = this.words[i] & num.words[i];
- return (this.length = b.length), this.strip();
- }),
- (BN.prototype.iand = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuand(num);
- }),
- (BN.prototype.and = function (num) {
- return this.length > num.length ? this.clone().iand(num) : num.clone().iand(this);
- }),
- (BN.prototype.uand = function (num) {
- return this.length > num.length ? this.clone().iuand(num) : num.clone().iuand(this);
- }),
- (BN.prototype.iuxor = function (num) {
- var a, b;
- this.length > num.length ? ((a = this), (b = num)) : ((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];
- return (this.length = a.length), this.strip();
- }),
- (BN.prototype.ixor = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuxor(num);
- }),
- (BN.prototype.xor = function (num) {
- return this.length > num.length ? this.clone().ixor(num) : num.clone().ixor(this);
- }),
- (BN.prototype.uxor = function (num) {
- return this.length > num.length ? this.clone().iuxor(num) : num.clone().iuxor(this);
- }),
- (BN.prototype.inotn = function (width) {
- assert(typeof width == "number" && width >= 0);
- var bytesNeeded = Math.ceil(width / 26) | 0,
- bitsLeft = width % 26;
- this._expand(bytesNeeded), bitsLeft > 0 && bytesNeeded--;
- for (var i = 0; i < bytesNeeded; i++) this.words[i] = ~this.words[i] & 67108863;
- return bitsLeft > 0 && (this.words[i] = ~this.words[i] & (67108863 >> (26 - bitsLeft))), this.strip();
- }),
- (BN.prototype.notn = function (width) {
- return this.clone().inotn(width);
- }),
- (BN.prototype.setn = function (bit, val) {
- assert(typeof bit == "number" && bit >= 0);
- var off = (bit / 26) | 0,
- wbit = bit % 26;
- return (
- this._expand(off + 1),
- val
- ? (this.words[off] = this.words[off] | (1 << wbit))
- : (this.words[off] = this.words[off] & ~(1 << wbit)),
- this.strip()
- );
- }),
- (BN.prototype.iadd = function (num) {
- var r;
- if (this.negative !== 0 && num.negative === 0)
- return (this.negative = 0), (r = this.isub(num)), (this.negative ^= 1), this._normSign();
- if (this.negative === 0 && num.negative !== 0)
- return (num.negative = 0), (r = this.isub(num)), (num.negative = 1), r._normSign();
- var a, b;
- this.length > num.length ? ((a = this), (b = num)) : ((a = num), (b = this));
- for (var carry = 0, i = 0; i < b.length; i++)
- (r = (a.words[i] | 0) + (b.words[i] | 0) + carry), (this.words[i] = r & 67108863), (carry = r >>> 26);
- for (; carry !== 0 && i < a.length; i++)
- (r = (a.words[i] | 0) + carry), (this.words[i] = r & 67108863), (carry = r >>> 26);
- if (((this.length = a.length), carry !== 0)) (this.words[this.length] = carry), this.length++;
- else if (a !== this) for (; i < a.length; i++) this.words[i] = a.words[i];
- return this;
- }),
- (BN.prototype.add = function (num) {
- var res;
- return num.negative !== 0 && this.negative === 0
- ? ((num.negative = 0), (res = this.sub(num)), (num.negative ^= 1), res)
- : num.negative === 0 && this.negative !== 0
- ? ((this.negative = 0), (res = num.sub(this)), (this.negative = 1), res)
- : this.length > num.length
- ? this.clone().iadd(num)
- : num.clone().iadd(this);
- }),
- (BN.prototype.isub = function (num) {
- if (num.negative !== 0) {
- num.negative = 0;
- var r = this.iadd(num);
- return (num.negative = 1), r._normSign();
- } else if (this.negative !== 0)
- return (this.negative = 0), this.iadd(num), (this.negative = 1), this._normSign();
- var cmp = this.cmp(num);
- if (cmp === 0) return (this.negative = 0), (this.length = 1), (this.words[0] = 0), this;
- var a, b;
- cmp > 0 ? ((a = this), (b = num)) : ((a = num), (b = this));
- for (var carry = 0, i = 0; i < b.length; i++)
- (r = (a.words[i] | 0) - (b.words[i] | 0) + carry), (carry = r >> 26), (this.words[i] = r & 67108863);
- for (; carry !== 0 && i < a.length; i++)
- (r = (a.words[i] | 0) + carry), (carry = r >> 26), (this.words[i] = r & 67108863);
- if (carry === 0 && i < a.length && a !== this) for (; i < a.length; i++) this.words[i] = a.words[i];
- return (this.length = Math.max(this.length, i)), a !== this && (this.negative = 1), this.strip();
- }),
- (BN.prototype.sub = function (num) {
- return this.clone().isub(num);
- });
- function smallMulTo(self2, num, out) {
- out.negative = num.negative ^ self2.negative;
- var len = (self2.length + num.length) | 0;
- (out.length = len), (len = (len - 1) | 0);
- var a = self2.words[0] | 0,
- b = num.words[0] | 0,
- r = a * b,
- lo = r & 67108863,
- carry = (r / 67108864) | 0;
- out.words[0] = lo;
- for (var k = 1; k < len; k++) {
- for (
- var ncarry = carry >>> 26,
- rword = carry & 67108863,
- maxJ = Math.min(k, num.length - 1),
- j = Math.max(0, k - self2.length + 1);
- j <= maxJ;
- j++
- ) {
- var i = (k - j) | 0;
- (a = self2.words[i] | 0),
- (b = num.words[j] | 0),
- (r = a * b + rword),
- (ncarry += (r / 67108864) | 0),
- (rword = r & 67108863);
- }
- (out.words[k] = rword | 0), (carry = ncarry | 0);
- }
- return carry !== 0 ? (out.words[k] = carry | 0) : out.length--, out.strip();
- }
- var comb10MulTo = function (self2, num, out) {
- var a = self2.words,
- b = num.words,
- o = out.words,
- c = 0,
- lo,
- mid,
- hi,
- a0 = a[0] | 0,
- al0 = a0 & 8191,
- ah0 = a0 >>> 13,
- a1 = a[1] | 0,
- al1 = a1 & 8191,
- ah1 = a1 >>> 13,
- a2 = a[2] | 0,
- al2 = a2 & 8191,
- ah2 = a2 >>> 13,
- a3 = a[3] | 0,
- al3 = a3 & 8191,
- ah3 = a3 >>> 13,
- a4 = a[4] | 0,
- al4 = a4 & 8191,
- ah4 = a4 >>> 13,
- a5 = a[5] | 0,
- al5 = a5 & 8191,
- ah5 = a5 >>> 13,
- a6 = a[6] | 0,
- al6 = a6 & 8191,
- ah6 = a6 >>> 13,
- a7 = a[7] | 0,
- al7 = a7 & 8191,
- ah7 = a7 >>> 13,
- a8 = a[8] | 0,
- al8 = a8 & 8191,
- ah8 = a8 >>> 13,
- a9 = a[9] | 0,
- al9 = a9 & 8191,
- ah9 = a9 >>> 13,
- b0 = b[0] | 0,
- bl0 = b0 & 8191,
- bh0 = b0 >>> 13,
- b1 = b[1] | 0,
- bl1 = b1 & 8191,
- bh1 = b1 >>> 13,
- b2 = b[2] | 0,
- bl2 = b2 & 8191,
- bh2 = b2 >>> 13,
- b3 = b[3] | 0,
- bl3 = b3 & 8191,
- bh3 = b3 >>> 13,
- b4 = b[4] | 0,
- bl4 = b4 & 8191,
- bh4 = b4 >>> 13,
- b5 = b[5] | 0,
- bl5 = b5 & 8191,
- bh5 = b5 >>> 13,
- b6 = b[6] | 0,
- bl6 = b6 & 8191,
- bh6 = b6 >>> 13,
- b7 = b[7] | 0,
- bl7 = b7 & 8191,
- bh7 = b7 >>> 13,
- b8 = b[8] | 0,
- bl8 = b8 & 8191,
- bh8 = b8 >>> 13,
- b9 = b[9] | 0,
- bl9 = b9 & 8191,
- bh9 = b9 >>> 13;
- (out.negative = self2.negative ^ num.negative),
- (out.length = 19),
- (lo = Math.imul(al0, bl0)),
- (mid = Math.imul(al0, bh0)),
- (mid = (mid + Math.imul(ah0, bl0)) | 0),
- (hi = Math.imul(ah0, bh0));
- var w0 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0),
- (w0 &= 67108863),
- (lo = Math.imul(al1, bl0)),
- (mid = Math.imul(al1, bh0)),
- (mid = (mid + Math.imul(ah1, bl0)) | 0),
- (hi = Math.imul(ah1, bh0)),
- (lo = (lo + Math.imul(al0, bl1)) | 0),
- (mid = (mid + Math.imul(al0, bh1)) | 0),
- (mid = (mid + Math.imul(ah0, bl1)) | 0),
- (hi = (hi + Math.imul(ah0, bh1)) | 0);
- var w1 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0),
- (w1 &= 67108863),
- (lo = Math.imul(al2, bl0)),
- (mid = Math.imul(al2, bh0)),
- (mid = (mid + Math.imul(ah2, bl0)) | 0),
- (hi = Math.imul(ah2, bh0)),
- (lo = (lo + Math.imul(al1, bl1)) | 0),
- (mid = (mid + Math.imul(al1, bh1)) | 0),
- (mid = (mid + Math.imul(ah1, bl1)) | 0),
- (hi = (hi + Math.imul(ah1, bh1)) | 0),
- (lo = (lo + Math.imul(al0, bl2)) | 0),
- (mid = (mid + Math.imul(al0, bh2)) | 0),
- (mid = (mid + Math.imul(ah0, bl2)) | 0),
- (hi = (hi + Math.imul(ah0, bh2)) | 0);
- var w2 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0),
- (w2 &= 67108863),
- (lo = Math.imul(al3, bl0)),
- (mid = Math.imul(al3, bh0)),
- (mid = (mid + Math.imul(ah3, bl0)) | 0),
- (hi = Math.imul(ah3, bh0)),
- (lo = (lo + Math.imul(al2, bl1)) | 0),
- (mid = (mid + Math.imul(al2, bh1)) | 0),
- (mid = (mid + Math.imul(ah2, bl1)) | 0),
- (hi = (hi + Math.imul(ah2, bh1)) | 0),
- (lo = (lo + Math.imul(al1, bl2)) | 0),
- (mid = (mid + Math.imul(al1, bh2)) | 0),
- (mid = (mid + Math.imul(ah1, bl2)) | 0),
- (hi = (hi + Math.imul(ah1, bh2)) | 0),
- (lo = (lo + Math.imul(al0, bl3)) | 0),
- (mid = (mid + Math.imul(al0, bh3)) | 0),
- (mid = (mid + Math.imul(ah0, bl3)) | 0),
- (hi = (hi + Math.imul(ah0, bh3)) | 0);
- var w3 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0),
- (w3 &= 67108863),
- (lo = Math.imul(al4, bl0)),
- (mid = Math.imul(al4, bh0)),
- (mid = (mid + Math.imul(ah4, bl0)) | 0),
- (hi = Math.imul(ah4, bh0)),
- (lo = (lo + Math.imul(al3, bl1)) | 0),
- (mid = (mid + Math.imul(al3, bh1)) | 0),
- (mid = (mid + Math.imul(ah3, bl1)) | 0),
- (hi = (hi + Math.imul(ah3, bh1)) | 0),
- (lo = (lo + Math.imul(al2, bl2)) | 0),
- (mid = (mid + Math.imul(al2, bh2)) | 0),
- (mid = (mid + Math.imul(ah2, bl2)) | 0),
- (hi = (hi + Math.imul(ah2, bh2)) | 0),
- (lo = (lo + Math.imul(al1, bl3)) | 0),
- (mid = (mid + Math.imul(al1, bh3)) | 0),
- (mid = (mid + Math.imul(ah1, bl3)) | 0),
- (hi = (hi + Math.imul(ah1, bh3)) | 0),
- (lo = (lo + Math.imul(al0, bl4)) | 0),
- (mid = (mid + Math.imul(al0, bh4)) | 0),
- (mid = (mid + Math.imul(ah0, bl4)) | 0),
- (hi = (hi + Math.imul(ah0, bh4)) | 0);
- var w4 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0),
- (w4 &= 67108863),
- (lo = Math.imul(al5, bl0)),
- (mid = Math.imul(al5, bh0)),
- (mid = (mid + Math.imul(ah5, bl0)) | 0),
- (hi = Math.imul(ah5, bh0)),
- (lo = (lo + Math.imul(al4, bl1)) | 0),
- (mid = (mid + Math.imul(al4, bh1)) | 0),
- (mid = (mid + Math.imul(ah4, bl1)) | 0),
- (hi = (hi + Math.imul(ah4, bh1)) | 0),
- (lo = (lo + Math.imul(al3, bl2)) | 0),
- (mid = (mid + Math.imul(al3, bh2)) | 0),
- (mid = (mid + Math.imul(ah3, bl2)) | 0),
- (hi = (hi + Math.imul(ah3, bh2)) | 0),
- (lo = (lo + Math.imul(al2, bl3)) | 0),
- (mid = (mid + Math.imul(al2, bh3)) | 0),
- (mid = (mid + Math.imul(ah2, bl3)) | 0),
- (hi = (hi + Math.imul(ah2, bh3)) | 0),
- (lo = (lo + Math.imul(al1, bl4)) | 0),
- (mid = (mid + Math.imul(al1, bh4)) | 0),
- (mid = (mid + Math.imul(ah1, bl4)) | 0),
- (hi = (hi + Math.imul(ah1, bh4)) | 0),
- (lo = (lo + Math.imul(al0, bl5)) | 0),
- (mid = (mid + Math.imul(al0, bh5)) | 0),
- (mid = (mid + Math.imul(ah0, bl5)) | 0),
- (hi = (hi + Math.imul(ah0, bh5)) | 0);
- var w5 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0),
- (w5 &= 67108863),
- (lo = Math.imul(al6, bl0)),
- (mid = Math.imul(al6, bh0)),
- (mid = (mid + Math.imul(ah6, bl0)) | 0),
- (hi = Math.imul(ah6, bh0)),
- (lo = (lo + Math.imul(al5, bl1)) | 0),
- (mid = (mid + Math.imul(al5, bh1)) | 0),
- (mid = (mid + Math.imul(ah5, bl1)) | 0),
- (hi = (hi + Math.imul(ah5, bh1)) | 0),
- (lo = (lo + Math.imul(al4, bl2)) | 0),
- (mid = (mid + Math.imul(al4, bh2)) | 0),
- (mid = (mid + Math.imul(ah4, bl2)) | 0),
- (hi = (hi + Math.imul(ah4, bh2)) | 0),
- (lo = (lo + Math.imul(al3, bl3)) | 0),
- (mid = (mid + Math.imul(al3, bh3)) | 0),
- (mid = (mid + Math.imul(ah3, bl3)) | 0),
- (hi = (hi + Math.imul(ah3, bh3)) | 0),
- (lo = (lo + Math.imul(al2, bl4)) | 0),
- (mid = (mid + Math.imul(al2, bh4)) | 0),
- (mid = (mid + Math.imul(ah2, bl4)) | 0),
- (hi = (hi + Math.imul(ah2, bh4)) | 0),
- (lo = (lo + Math.imul(al1, bl5)) | 0),
- (mid = (mid + Math.imul(al1, bh5)) | 0),
- (mid = (mid + Math.imul(ah1, bl5)) | 0),
- (hi = (hi + Math.imul(ah1, bh5)) | 0),
- (lo = (lo + Math.imul(al0, bl6)) | 0),
- (mid = (mid + Math.imul(al0, bh6)) | 0),
- (mid = (mid + Math.imul(ah0, bl6)) | 0),
- (hi = (hi + Math.imul(ah0, bh6)) | 0);
- var w6 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0),
- (w6 &= 67108863),
- (lo = Math.imul(al7, bl0)),
- (mid = Math.imul(al7, bh0)),
- (mid = (mid + Math.imul(ah7, bl0)) | 0),
- (hi = Math.imul(ah7, bh0)),
- (lo = (lo + Math.imul(al6, bl1)) | 0),
- (mid = (mid + Math.imul(al6, bh1)) | 0),
- (mid = (mid + Math.imul(ah6, bl1)) | 0),
- (hi = (hi + Math.imul(ah6, bh1)) | 0),
- (lo = (lo + Math.imul(al5, bl2)) | 0),
- (mid = (mid + Math.imul(al5, bh2)) | 0),
- (mid = (mid + Math.imul(ah5, bl2)) | 0),
- (hi = (hi + Math.imul(ah5, bh2)) | 0),
- (lo = (lo + Math.imul(al4, bl3)) | 0),
- (mid = (mid + Math.imul(al4, bh3)) | 0),
- (mid = (mid + Math.imul(ah4, bl3)) | 0),
- (hi = (hi + Math.imul(ah4, bh3)) | 0),
- (lo = (lo + Math.imul(al3, bl4)) | 0),
- (mid = (mid + Math.imul(al3, bh4)) | 0),
- (mid = (mid + Math.imul(ah3, bl4)) | 0),
- (hi = (hi + Math.imul(ah3, bh4)) | 0),
- (lo = (lo + Math.imul(al2, bl5)) | 0),
- (mid = (mid + Math.imul(al2, bh5)) | 0),
- (mid = (mid + Math.imul(ah2, bl5)) | 0),
- (hi = (hi + Math.imul(ah2, bh5)) | 0),
- (lo = (lo + Math.imul(al1, bl6)) | 0),
- (mid = (mid + Math.imul(al1, bh6)) | 0),
- (mid = (mid + Math.imul(ah1, bl6)) | 0),
- (hi = (hi + Math.imul(ah1, bh6)) | 0),
- (lo = (lo + Math.imul(al0, bl7)) | 0),
- (mid = (mid + Math.imul(al0, bh7)) | 0),
- (mid = (mid + Math.imul(ah0, bl7)) | 0),
- (hi = (hi + Math.imul(ah0, bh7)) | 0);
- var w7 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0),
- (w7 &= 67108863),
- (lo = Math.imul(al8, bl0)),
- (mid = Math.imul(al8, bh0)),
- (mid = (mid + Math.imul(ah8, bl0)) | 0),
- (hi = Math.imul(ah8, bh0)),
- (lo = (lo + Math.imul(al7, bl1)) | 0),
- (mid = (mid + Math.imul(al7, bh1)) | 0),
- (mid = (mid + Math.imul(ah7, bl1)) | 0),
- (hi = (hi + Math.imul(ah7, bh1)) | 0),
- (lo = (lo + Math.imul(al6, bl2)) | 0),
- (mid = (mid + Math.imul(al6, bh2)) | 0),
- (mid = (mid + Math.imul(ah6, bl2)) | 0),
- (hi = (hi + Math.imul(ah6, bh2)) | 0),
- (lo = (lo + Math.imul(al5, bl3)) | 0),
- (mid = (mid + Math.imul(al5, bh3)) | 0),
- (mid = (mid + Math.imul(ah5, bl3)) | 0),
- (hi = (hi + Math.imul(ah5, bh3)) | 0),
- (lo = (lo + Math.imul(al4, bl4)) | 0),
- (mid = (mid + Math.imul(al4, bh4)) | 0),
- (mid = (mid + Math.imul(ah4, bl4)) | 0),
- (hi = (hi + Math.imul(ah4, bh4)) | 0),
- (lo = (lo + Math.imul(al3, bl5)) | 0),
- (mid = (mid + Math.imul(al3, bh5)) | 0),
- (mid = (mid + Math.imul(ah3, bl5)) | 0),
- (hi = (hi + Math.imul(ah3, bh5)) | 0),
- (lo = (lo + Math.imul(al2, bl6)) | 0),
- (mid = (mid + Math.imul(al2, bh6)) | 0),
- (mid = (mid + Math.imul(ah2, bl6)) | 0),
- (hi = (hi + Math.imul(ah2, bh6)) | 0),
- (lo = (lo + Math.imul(al1, bl7)) | 0),
- (mid = (mid + Math.imul(al1, bh7)) | 0),
- (mid = (mid + Math.imul(ah1, bl7)) | 0),
- (hi = (hi + Math.imul(ah1, bh7)) | 0),
- (lo = (lo + Math.imul(al0, bl8)) | 0),
- (mid = (mid + Math.imul(al0, bh8)) | 0),
- (mid = (mid + Math.imul(ah0, bl8)) | 0),
- (hi = (hi + Math.imul(ah0, bh8)) | 0);
- var w8 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0),
- (w8 &= 67108863),
- (lo = Math.imul(al9, bl0)),
- (mid = Math.imul(al9, bh0)),
- (mid = (mid + Math.imul(ah9, bl0)) | 0),
- (hi = Math.imul(ah9, bh0)),
- (lo = (lo + Math.imul(al8, bl1)) | 0),
- (mid = (mid + Math.imul(al8, bh1)) | 0),
- (mid = (mid + Math.imul(ah8, bl1)) | 0),
- (hi = (hi + Math.imul(ah8, bh1)) | 0),
- (lo = (lo + Math.imul(al7, bl2)) | 0),
- (mid = (mid + Math.imul(al7, bh2)) | 0),
- (mid = (mid + Math.imul(ah7, bl2)) | 0),
- (hi = (hi + Math.imul(ah7, bh2)) | 0),
- (lo = (lo + Math.imul(al6, bl3)) | 0),
- (mid = (mid + Math.imul(al6, bh3)) | 0),
- (mid = (mid + Math.imul(ah6, bl3)) | 0),
- (hi = (hi + Math.imul(ah6, bh3)) | 0),
- (lo = (lo + Math.imul(al5, bl4)) | 0),
- (mid = (mid + Math.imul(al5, bh4)) | 0),
- (mid = (mid + Math.imul(ah5, bl4)) | 0),
- (hi = (hi + Math.imul(ah5, bh4)) | 0),
- (lo = (lo + Math.imul(al4, bl5)) | 0),
- (mid = (mid + Math.imul(al4, bh5)) | 0),
- (mid = (mid + Math.imul(ah4, bl5)) | 0),
- (hi = (hi + Math.imul(ah4, bh5)) | 0),
- (lo = (lo + Math.imul(al3, bl6)) | 0),
- (mid = (mid + Math.imul(al3, bh6)) | 0),
- (mid = (mid + Math.imul(ah3, bl6)) | 0),
- (hi = (hi + Math.imul(ah3, bh6)) | 0),
- (lo = (lo + Math.imul(al2, bl7)) | 0),
- (mid = (mid + Math.imul(al2, bh7)) | 0),
- (mid = (mid + Math.imul(ah2, bl7)) | 0),
- (hi = (hi + Math.imul(ah2, bh7)) | 0),
- (lo = (lo + Math.imul(al1, bl8)) | 0),
- (mid = (mid + Math.imul(al1, bh8)) | 0),
- (mid = (mid + Math.imul(ah1, bl8)) | 0),
- (hi = (hi + Math.imul(ah1, bh8)) | 0),
- (lo = (lo + Math.imul(al0, bl9)) | 0),
- (mid = (mid + Math.imul(al0, bh9)) | 0),
- (mid = (mid + Math.imul(ah0, bl9)) | 0),
- (hi = (hi + Math.imul(ah0, bh9)) | 0);
- var w9 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0),
- (w9 &= 67108863),
- (lo = Math.imul(al9, bl1)),
- (mid = Math.imul(al9, bh1)),
- (mid = (mid + Math.imul(ah9, bl1)) | 0),
- (hi = Math.imul(ah9, bh1)),
- (lo = (lo + Math.imul(al8, bl2)) | 0),
- (mid = (mid + Math.imul(al8, bh2)) | 0),
- (mid = (mid + Math.imul(ah8, bl2)) | 0),
- (hi = (hi + Math.imul(ah8, bh2)) | 0),
- (lo = (lo + Math.imul(al7, bl3)) | 0),
- (mid = (mid + Math.imul(al7, bh3)) | 0),
- (mid = (mid + Math.imul(ah7, bl3)) | 0),
- (hi = (hi + Math.imul(ah7, bh3)) | 0),
- (lo = (lo + Math.imul(al6, bl4)) | 0),
- (mid = (mid + Math.imul(al6, bh4)) | 0),
- (mid = (mid + Math.imul(ah6, bl4)) | 0),
- (hi = (hi + Math.imul(ah6, bh4)) | 0),
- (lo = (lo + Math.imul(al5, bl5)) | 0),
- (mid = (mid + Math.imul(al5, bh5)) | 0),
- (mid = (mid + Math.imul(ah5, bl5)) | 0),
- (hi = (hi + Math.imul(ah5, bh5)) | 0),
- (lo = (lo + Math.imul(al4, bl6)) | 0),
- (mid = (mid + Math.imul(al4, bh6)) | 0),
- (mid = (mid + Math.imul(ah4, bl6)) | 0),
- (hi = (hi + Math.imul(ah4, bh6)) | 0),
- (lo = (lo + Math.imul(al3, bl7)) | 0),
- (mid = (mid + Math.imul(al3, bh7)) | 0),
- (mid = (mid + Math.imul(ah3, bl7)) | 0),
- (hi = (hi + Math.imul(ah3, bh7)) | 0),
- (lo = (lo + Math.imul(al2, bl8)) | 0),
- (mid = (mid + Math.imul(al2, bh8)) | 0),
- (mid = (mid + Math.imul(ah2, bl8)) | 0),
- (hi = (hi + Math.imul(ah2, bh8)) | 0),
- (lo = (lo + Math.imul(al1, bl9)) | 0),
- (mid = (mid + Math.imul(al1, bh9)) | 0),
- (mid = (mid + Math.imul(ah1, bl9)) | 0),
- (hi = (hi + Math.imul(ah1, bh9)) | 0);
- var w10 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0),
- (w10 &= 67108863),
- (lo = Math.imul(al9, bl2)),
- (mid = Math.imul(al9, bh2)),
- (mid = (mid + Math.imul(ah9, bl2)) | 0),
- (hi = Math.imul(ah9, bh2)),
- (lo = (lo + Math.imul(al8, bl3)) | 0),
- (mid = (mid + Math.imul(al8, bh3)) | 0),
- (mid = (mid + Math.imul(ah8, bl3)) | 0),
- (hi = (hi + Math.imul(ah8, bh3)) | 0),
- (lo = (lo + Math.imul(al7, bl4)) | 0),
- (mid = (mid + Math.imul(al7, bh4)) | 0),
- (mid = (mid + Math.imul(ah7, bl4)) | 0),
- (hi = (hi + Math.imul(ah7, bh4)) | 0),
- (lo = (lo + Math.imul(al6, bl5)) | 0),
- (mid = (mid + Math.imul(al6, bh5)) | 0),
- (mid = (mid + Math.imul(ah6, bl5)) | 0),
- (hi = (hi + Math.imul(ah6, bh5)) | 0),
- (lo = (lo + Math.imul(al5, bl6)) | 0),
- (mid = (mid + Math.imul(al5, bh6)) | 0),
- (mid = (mid + Math.imul(ah5, bl6)) | 0),
- (hi = (hi + Math.imul(ah5, bh6)) | 0),
- (lo = (lo + Math.imul(al4, bl7)) | 0),
- (mid = (mid + Math.imul(al4, bh7)) | 0),
- (mid = (mid + Math.imul(ah4, bl7)) | 0),
- (hi = (hi + Math.imul(ah4, bh7)) | 0),
- (lo = (lo + Math.imul(al3, bl8)) | 0),
- (mid = (mid + Math.imul(al3, bh8)) | 0),
- (mid = (mid + Math.imul(ah3, bl8)) | 0),
- (hi = (hi + Math.imul(ah3, bh8)) | 0),
- (lo = (lo + Math.imul(al2, bl9)) | 0),
- (mid = (mid + Math.imul(al2, bh9)) | 0),
- (mid = (mid + Math.imul(ah2, bl9)) | 0),
- (hi = (hi + Math.imul(ah2, bh9)) | 0);
- var w11 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0),
- (w11 &= 67108863),
- (lo = Math.imul(al9, bl3)),
- (mid = Math.imul(al9, bh3)),
- (mid = (mid + Math.imul(ah9, bl3)) | 0),
- (hi = Math.imul(ah9, bh3)),
- (lo = (lo + Math.imul(al8, bl4)) | 0),
- (mid = (mid + Math.imul(al8, bh4)) | 0),
- (mid = (mid + Math.imul(ah8, bl4)) | 0),
- (hi = (hi + Math.imul(ah8, bh4)) | 0),
- (lo = (lo + Math.imul(al7, bl5)) | 0),
- (mid = (mid + Math.imul(al7, bh5)) | 0),
- (mid = (mid + Math.imul(ah7, bl5)) | 0),
- (hi = (hi + Math.imul(ah7, bh5)) | 0),
- (lo = (lo + Math.imul(al6, bl6)) | 0),
- (mid = (mid + Math.imul(al6, bh6)) | 0),
- (mid = (mid + Math.imul(ah6, bl6)) | 0),
- (hi = (hi + Math.imul(ah6, bh6)) | 0),
- (lo = (lo + Math.imul(al5, bl7)) | 0),
- (mid = (mid + Math.imul(al5, bh7)) | 0),
- (mid = (mid + Math.imul(ah5, bl7)) | 0),
- (hi = (hi + Math.imul(ah5, bh7)) | 0),
- (lo = (lo + Math.imul(al4, bl8)) | 0),
- (mid = (mid + Math.imul(al4, bh8)) | 0),
- (mid = (mid + Math.imul(ah4, bl8)) | 0),
- (hi = (hi + Math.imul(ah4, bh8)) | 0),
- (lo = (lo + Math.imul(al3, bl9)) | 0),
- (mid = (mid + Math.imul(al3, bh9)) | 0),
- (mid = (mid + Math.imul(ah3, bl9)) | 0),
- (hi = (hi + Math.imul(ah3, bh9)) | 0);
- var w12 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0),
- (w12 &= 67108863),
- (lo = Math.imul(al9, bl4)),
- (mid = Math.imul(al9, bh4)),
- (mid = (mid + Math.imul(ah9, bl4)) | 0),
- (hi = Math.imul(ah9, bh4)),
- (lo = (lo + Math.imul(al8, bl5)) | 0),
- (mid = (mid + Math.imul(al8, bh5)) | 0),
- (mid = (mid + Math.imul(ah8, bl5)) | 0),
- (hi = (hi + Math.imul(ah8, bh5)) | 0),
- (lo = (lo + Math.imul(al7, bl6)) | 0),
- (mid = (mid + Math.imul(al7, bh6)) | 0),
- (mid = (mid + Math.imul(ah7, bl6)) | 0),
- (hi = (hi + Math.imul(ah7, bh6)) | 0),
- (lo = (lo + Math.imul(al6, bl7)) | 0),
- (mid = (mid + Math.imul(al6, bh7)) | 0),
- (mid = (mid + Math.imul(ah6, bl7)) | 0),
- (hi = (hi + Math.imul(ah6, bh7)) | 0),
- (lo = (lo + Math.imul(al5, bl8)) | 0),
- (mid = (mid + Math.imul(al5, bh8)) | 0),
- (mid = (mid + Math.imul(ah5, bl8)) | 0),
- (hi = (hi + Math.imul(ah5, bh8)) | 0),
- (lo = (lo + Math.imul(al4, bl9)) | 0),
- (mid = (mid + Math.imul(al4, bh9)) | 0),
- (mid = (mid + Math.imul(ah4, bl9)) | 0),
- (hi = (hi + Math.imul(ah4, bh9)) | 0);
- var w13 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0),
- (w13 &= 67108863),
- (lo = Math.imul(al9, bl5)),
- (mid = Math.imul(al9, bh5)),
- (mid = (mid + Math.imul(ah9, bl5)) | 0),
- (hi = Math.imul(ah9, bh5)),
- (lo = (lo + Math.imul(al8, bl6)) | 0),
- (mid = (mid + Math.imul(al8, bh6)) | 0),
- (mid = (mid + Math.imul(ah8, bl6)) | 0),
- (hi = (hi + Math.imul(ah8, bh6)) | 0),
- (lo = (lo + Math.imul(al7, bl7)) | 0),
- (mid = (mid + Math.imul(al7, bh7)) | 0),
- (mid = (mid + Math.imul(ah7, bl7)) | 0),
- (hi = (hi + Math.imul(ah7, bh7)) | 0),
- (lo = (lo + Math.imul(al6, bl8)) | 0),
- (mid = (mid + Math.imul(al6, bh8)) | 0),
- (mid = (mid + Math.imul(ah6, bl8)) | 0),
- (hi = (hi + Math.imul(ah6, bh8)) | 0),
- (lo = (lo + Math.imul(al5, bl9)) | 0),
- (mid = (mid + Math.imul(al5, bh9)) | 0),
- (mid = (mid + Math.imul(ah5, bl9)) | 0),
- (hi = (hi + Math.imul(ah5, bh9)) | 0);
- var w14 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0),
- (w14 &= 67108863),
- (lo = Math.imul(al9, bl6)),
- (mid = Math.imul(al9, bh6)),
- (mid = (mid + Math.imul(ah9, bl6)) | 0),
- (hi = Math.imul(ah9, bh6)),
- (lo = (lo + Math.imul(al8, bl7)) | 0),
- (mid = (mid + Math.imul(al8, bh7)) | 0),
- (mid = (mid + Math.imul(ah8, bl7)) | 0),
- (hi = (hi + Math.imul(ah8, bh7)) | 0),
- (lo = (lo + Math.imul(al7, bl8)) | 0),
- (mid = (mid + Math.imul(al7, bh8)) | 0),
- (mid = (mid + Math.imul(ah7, bl8)) | 0),
- (hi = (hi + Math.imul(ah7, bh8)) | 0),
- (lo = (lo + Math.imul(al6, bl9)) | 0),
- (mid = (mid + Math.imul(al6, bh9)) | 0),
- (mid = (mid + Math.imul(ah6, bl9)) | 0),
- (hi = (hi + Math.imul(ah6, bh9)) | 0);
- var w15 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0),
- (w15 &= 67108863),
- (lo = Math.imul(al9, bl7)),
- (mid = Math.imul(al9, bh7)),
- (mid = (mid + Math.imul(ah9, bl7)) | 0),
- (hi = Math.imul(ah9, bh7)),
- (lo = (lo + Math.imul(al8, bl8)) | 0),
- (mid = (mid + Math.imul(al8, bh8)) | 0),
- (mid = (mid + Math.imul(ah8, bl8)) | 0),
- (hi = (hi + Math.imul(ah8, bh8)) | 0),
- (lo = (lo + Math.imul(al7, bl9)) | 0),
- (mid = (mid + Math.imul(al7, bh9)) | 0),
- (mid = (mid + Math.imul(ah7, bl9)) | 0),
- (hi = (hi + Math.imul(ah7, bh9)) | 0);
- var w16 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0),
- (w16 &= 67108863),
- (lo = Math.imul(al9, bl8)),
- (mid = Math.imul(al9, bh8)),
- (mid = (mid + Math.imul(ah9, bl8)) | 0),
- (hi = Math.imul(ah9, bh8)),
- (lo = (lo + Math.imul(al8, bl9)) | 0),
- (mid = (mid + Math.imul(al8, bh9)) | 0),
- (mid = (mid + Math.imul(ah8, bl9)) | 0),
- (hi = (hi + Math.imul(ah8, bh9)) | 0);
- var w17 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0),
- (w17 &= 67108863),
- (lo = Math.imul(al9, bl9)),
- (mid = Math.imul(al9, bh9)),
- (mid = (mid + Math.imul(ah9, bl9)) | 0),
- (hi = Math.imul(ah9, bh9));
- var w18 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- return (
- (c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0),
- (w18 &= 67108863),
- (o[0] = w0),
- (o[1] = w1),
- (o[2] = w2),
- (o[3] = w3),
- (o[4] = w4),
- (o[5] = w5),
- (o[6] = w6),
- (o[7] = w7),
- (o[8] = w8),
- (o[9] = w9),
- (o[10] = w10),
- (o[11] = w11),
- (o[12] = w12),
- (o[13] = w13),
- (o[14] = w14),
- (o[15] = w15),
- (o[16] = w16),
- (o[17] = w17),
- (o[18] = w18),
- c !== 0 && ((o[19] = c), out.length++),
- out
- );
- };
- Math.imul || (comb10MulTo = smallMulTo);
- function bigMulTo(self2, num, out) {
- (out.negative = num.negative ^ self2.negative), (out.length = self2.length + num.length);
- for (var carry = 0, hncarry = 0, k = 0; k < out.length - 1; k++) {
- var ncarry = hncarry;
- hncarry = 0;
- for (
- var rword = carry & 67108863, maxJ = Math.min(k, num.length - 1), j = Math.max(0, k - self2.length + 1);
- j <= maxJ;
- j++
- ) {
- var i = k - j,
- a = self2.words[i] | 0,
- b = num.words[j] | 0,
- r = a * b,
- lo = r & 67108863;
- (ncarry = (ncarry + ((r / 67108864) | 0)) | 0),
- (lo = (lo + rword) | 0),
- (rword = lo & 67108863),
- (ncarry = (ncarry + (lo >>> 26)) | 0),
- (hncarry += ncarry >>> 26),
- (ncarry &= 67108863);
- }
- (out.words[k] = rword), (carry = ncarry), (ncarry = hncarry);
- }
- return carry !== 0 ? (out.words[k] = carry) : out.length--, out.strip();
- }
- function jumboMulTo(self2, num, out) {
- var fftm = new FFTM();
- return fftm.mulp(self2, num, out);
- }
- BN.prototype.mulTo = function (num, out) {
- var res,
- len = this.length + num.length;
- return (
- this.length === 10 && num.length === 10
- ? (res = comb10MulTo(this, num, out))
- : len < 63
- ? (res = smallMulTo(this, num, out))
- : len < 1024
- ? (res = bigMulTo(this, num, out))
- : (res = jumboMulTo(this, num, out)),
- res
- );
- };
- function FFTM(x, y) {
- (this.x = x), (this.y = y);
- }
- (FFTM.prototype.makeRBT = function (N) {
- for (var t = new Array(N), l = BN.prototype._countBits(N) - 1, i = 0; i < N; i++) t[i] = this.revBin(i, l, N);
- return t;
- }),
- (FFTM.prototype.revBin = function (x, l, N) {
- if (x === 0 || x === N - 1) return x;
- for (var rb = 0, i = 0; i < l; i++) (rb |= (x & 1) << (l - i - 1)), (x >>= 1);
- return rb;
- }),
- (FFTM.prototype.permute = function (rbt, rws, iws, rtws, itws, N) {
- for (var i = 0; i < N; i++) (rtws[i] = rws[rbt[i]]), (itws[i] = iws[rbt[i]]);
- }),
- (FFTM.prototype.transform = function (rws, iws, rtws, itws, N, rbt) {
- this.permute(rbt, rws, iws, rtws, itws, N);
- for (var s = 1; s < N; s <<= 1)
- for (
- var l = s << 1, rtwdf = Math.cos((2 * Math.PI) / l), itwdf = Math.sin((2 * Math.PI) / l), p = 0;
- p < N;
- p += l
- )
- for (var rtwdf_ = rtwdf, itwdf_ = itwdf, j = 0; j < s; j++) {
- var re = rtws[p + j],
- ie = itws[p + j],
- ro = rtws[p + j + s],
- io = itws[p + j + s],
- rx = rtwdf_ * ro - itwdf_ * io;
- (io = rtwdf_ * io + itwdf_ * ro),
- (ro = rx),
- (rtws[p + j] = re + ro),
- (itws[p + j] = ie + io),
- (rtws[p + j + s] = re - ro),
- (itws[p + j + s] = ie - io),
- j !== l &&
- ((rx = rtwdf * rtwdf_ - itwdf * itwdf_), (itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_), (rtwdf_ = rx));
- }
- }),
- (FFTM.prototype.guessLen13b = function (n, m) {
- var N = Math.max(m, n) | 1,
- odd = N & 1,
- i = 0;
- for (N = (N / 2) | 0; N; N = N >>> 1) i++;
- return 1 << (i + 1 + odd);
- }),
- (FFTM.prototype.conjugate = function (rws, iws, N) {
- if (!(N <= 1))
- for (var i = 0; i < N / 2; i++) {
- var t = rws[i];
- (rws[i] = rws[N - i - 1]),
- (rws[N - i - 1] = t),
- (t = iws[i]),
- (iws[i] = -iws[N - i - 1]),
- (iws[N - i - 1] = -t);
- }
- }),
- (FFTM.prototype.normalize13b = function (ws, N) {
- for (var carry = 0, i = 0; i < N / 2; i++) {
- var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry;
- (ws[i] = w & 67108863), w < 67108864 ? (carry = 0) : (carry = (w / 67108864) | 0);
- }
- return ws;
- }),
- (FFTM.prototype.convert13b = function (ws, len, rws, N) {
- for (var carry = 0, i = 0; i < len; i++)
- (carry = carry + (ws[i] | 0)),
- (rws[2 * i] = carry & 8191),
- (carry = carry >>> 13),
- (rws[2 * i + 1] = carry & 8191),
- (carry = carry >>> 13);
- for (i = 2 * len; i < N; ++i) rws[i] = 0;
- assert(carry === 0), assert((carry & -8192) === 0);
- }),
- (FFTM.prototype.stub = function (N) {
- for (var ph = new Array(N), i = 0; i < N; i++) ph[i] = 0;
- return ph;
- }),
- (FFTM.prototype.mulp = function (x, y, out) {
- var N = 2 * this.guessLen13b(x.length, y.length),
- rbt = this.makeRBT(N),
- _ = this.stub(N),
- rws = new Array(N),
- rwst = new Array(N),
- iwst = new Array(N),
- nrws = new Array(N),
- nrwst = new Array(N),
- niwst = new Array(N),
- rmws = out.words;
- (rmws.length = N),
- this.convert13b(x.words, x.length, rws, N),
- this.convert13b(y.words, y.length, nrws, N),
- this.transform(rws, _, rwst, iwst, N, rbt),
- this.transform(nrws, _, nrwst, niwst, N, rbt);
- for (var i = 0; i < N; i++) {
- var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
- (iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]), (rwst[i] = rx);
- }
- return (
- this.conjugate(rwst, iwst, N),
- this.transform(rwst, iwst, rmws, _, N, rbt),
- this.conjugate(rmws, _, N),
- this.normalize13b(rmws, N),
- (out.negative = x.negative ^ y.negative),
- (out.length = x.length + y.length),
- out.strip()
- );
- }),
- (BN.prototype.mul = function (num) {
- var out = new BN(null);
- return (out.words = new Array(this.length + num.length)), this.mulTo(num, out);
- }),
- (BN.prototype.mulf = function (num) {
- var out = new BN(null);
- return (out.words = new Array(this.length + num.length)), jumboMulTo(this, num, out);
- }),
- (BN.prototype.imul = function (num) {
- return this.clone().mulTo(num, this);
- }),
- (BN.prototype.imuln = function (num) {
- assert(typeof num == "number"), assert(num < 67108864);
- for (var carry = 0, i = 0; i < this.length; i++) {
- var w = (this.words[i] | 0) * num,
- lo = (w & 67108863) + (carry & 67108863);
- (carry >>= 26), (carry += (w / 67108864) | 0), (carry += lo >>> 26), (this.words[i] = lo & 67108863);
- }
- return carry !== 0 && ((this.words[i] = carry), this.length++), this;
- }),
- (BN.prototype.muln = function (num) {
- return this.clone().imuln(num);
- }),
- (BN.prototype.sqr = function () {
- return this.mul(this);
- }),
- (BN.prototype.isqr = function () {
- return this.imul(this.clone());
- }),
- (BN.prototype.pow = function (num) {
- var w = toBitArray(num);
- if (w.length === 0) return new BN(1);
- for (var res = this, i = 0; i < w.length && w[i] === 0; i++, res = res.sqr());
- if (++i < w.length) for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) w[i] !== 0 && (res = res.mul(q));
- return res;
- }),
- (BN.prototype.iushln = function (bits) {
- assert(typeof bits == "number" && bits >= 0);
- var r = bits % 26,
- s = (bits - r) / 26,
- carryMask = (67108863 >>> (26 - r)) << (26 - r),
- i;
- if (r !== 0) {
- var carry = 0;
- for (i = 0; i < this.length; i++) {
- var newCarry = this.words[i] & carryMask,
- c = ((this.words[i] | 0) - newCarry) << r;
- (this.words[i] = c | carry), (carry = newCarry >>> (26 - r));
- }
- carry && ((this.words[i] = carry), this.length++);
- }
- if (s !== 0) {
- for (i = this.length - 1; i >= 0; i--) this.words[i + s] = this.words[i];
- for (i = 0; i < s; i++) this.words[i] = 0;
- this.length += s;
- }
- return this.strip();
- }),
- (BN.prototype.ishln = function (bits) {
- return assert(this.negative === 0), this.iushln(bits);
- }),
- (BN.prototype.iushrn = function (bits, hint, extended) {
- assert(typeof bits == "number" && bits >= 0);
- var h;
- hint ? (h = (hint - (hint % 26)) / 26) : (h = 0);
- var r = bits % 26,
- s = Math.min((bits - r) / 26, this.length),
- mask = 67108863 ^ ((67108863 >>> r) << r),
- maskedWords = extended;
- if (((h -= s), (h = Math.max(0, h)), maskedWords)) {
- for (var i = 0; i < s; i++) maskedWords.words[i] = this.words[i];
- maskedWords.length = s;
- }
- if (s !== 0)
- if (this.length > s) for (this.length -= s, i = 0; i < this.length; i++) this.words[i] = this.words[i + s];
- else (this.words[0] = 0), (this.length = 1);
- var carry = 0;
- for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
- var word = this.words[i] | 0;
- (this.words[i] = (carry << (26 - r)) | (word >>> r)), (carry = word & mask);
- }
- return (
- maskedWords && carry !== 0 && (maskedWords.words[maskedWords.length++] = carry),
- this.length === 0 && ((this.words[0] = 0), (this.length = 1)),
- this.strip()
- );
- }),
- (BN.prototype.ishrn = function (bits, hint, extended) {
- return assert(this.negative === 0), this.iushrn(bits, hint, extended);
- }),
- (BN.prototype.shln = function (bits) {
- return this.clone().ishln(bits);
- }),
- (BN.prototype.ushln = function (bits) {
- return this.clone().iushln(bits);
- }),
- (BN.prototype.shrn = function (bits) {
- return this.clone().ishrn(bits);
- }),
- (BN.prototype.ushrn = function (bits) {
- return this.clone().iushrn(bits);
- }),
- (BN.prototype.testn = function (bit) {
- assert(typeof bit == "number" && bit >= 0);
- var r = bit % 26,
- s = (bit - r) / 26,
- q = 1 << r;
- if (this.length <= s) return !1;
- var w = this.words[s];
- return !!(w & q);
- }),
- (BN.prototype.imaskn = function (bits) {
- assert(typeof bits == "number" && bits >= 0);
- var r = bits % 26,
- s = (bits - r) / 26;
- if ((assert(this.negative === 0, "imaskn works only with positive numbers"), this.length <= s)) return this;
- if ((r !== 0 && s++, (this.length = Math.min(s, this.length)), r !== 0)) {
- var mask = 67108863 ^ ((67108863 >>> r) << r);
- this.words[this.length - 1] &= mask;
- }
- return this.strip();
- }),
- (BN.prototype.maskn = function (bits) {
- return this.clone().imaskn(bits);
- }),
- (BN.prototype.iaddn = function (num) {
- return (
- assert(typeof num == "number"),
- assert(num < 67108864),
- num < 0
- ? this.isubn(-num)
- : this.negative !== 0
- ? this.length === 1 && (this.words[0] | 0) < num
- ? ((this.words[0] = num - (this.words[0] | 0)), (this.negative = 0), this)
- : ((this.negative = 0), this.isubn(num), (this.negative = 1), this)
- : this._iaddn(num)
- );
- }),
- (BN.prototype._iaddn = function (num) {
- this.words[0] += num;
- for (var i = 0; i < this.length && this.words[i] >= 67108864; i++)
- (this.words[i] -= 67108864), i === this.length - 1 ? (this.words[i + 1] = 1) : this.words[i + 1]++;
- return (this.length = Math.max(this.length, i + 1)), this;
- }),
- (BN.prototype.isubn = function (num) {
- if ((assert(typeof num == "number"), assert(num < 67108864), num < 0)) return this.iaddn(-num);
- if (this.negative !== 0) return (this.negative = 0), this.iaddn(num), (this.negative = 1), this;
- if (((this.words[0] -= num), this.length === 1 && this.words[0] < 0))
- (this.words[0] = -this.words[0]), (this.negative = 1);
- else
- for (var i = 0; i < this.length && this.words[i] < 0; i++)
- (this.words[i] += 67108864), (this.words[i + 1] -= 1);
- return this.strip();
- }),
- (BN.prototype.addn = function (num) {
- return this.clone().iaddn(num);
- }),
- (BN.prototype.subn = function (num) {
- return this.clone().isubn(num);
- }),
- (BN.prototype.iabs = function () {
- return (this.negative = 0), this;
- }),
- (BN.prototype.abs = function () {
- return this.clone().iabs();
- }),
- (BN.prototype._ishlnsubmul = function (num, mul, shift) {
- var len = num.length + shift,
- i;
- this._expand(len);
- var w,
- carry = 0;
- for (i = 0; i < num.length; i++) {
- w = (this.words[i + shift] | 0) + carry;
- var right = (num.words[i] | 0) * mul;
- (w -= right & 67108863),
- (carry = (w >> 26) - ((right / 67108864) | 0)),
- (this.words[i + shift] = w & 67108863);
- }
- for (; i < this.length - shift; i++)
- (w = (this.words[i + shift] | 0) + carry), (carry = w >> 26), (this.words[i + shift] = w & 67108863);
- if (carry === 0) return this.strip();
- for (assert(carry === -1), carry = 0, i = 0; i < this.length; i++)
- (w = -(this.words[i] | 0) + carry), (carry = w >> 26), (this.words[i] = w & 67108863);
- return (this.negative = 1), this.strip();
- }),
- (BN.prototype._wordDiv = function (num, mode) {
- var shift = this.length - num.length,
- a = this.clone(),
- b = num,
- bhi = b.words[b.length - 1] | 0,
- bhiBits = this._countBits(bhi);
- (shift = 26 - bhiBits),
- shift !== 0 && ((b = b.ushln(shift)), a.iushln(shift), (bhi = b.words[b.length - 1] | 0));
- var m = a.length - b.length,
- q;
- if (mode !== "mod") {
- (q = new BN(null)), (q.length = m + 1), (q.words = new Array(q.length));
- for (var i = 0; i < q.length; i++) q.words[i] = 0;
- }
- var diff = a.clone()._ishlnsubmul(b, 1, m);
- diff.negative === 0 && ((a = diff), q && (q.words[m] = 1));
- for (var j = m - 1; j >= 0; j--) {
- var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0);
- for (qj = Math.min((qj / bhi) | 0, 67108863), a._ishlnsubmul(b, qj, j); a.negative !== 0; )
- qj--, (a.negative = 0), a._ishlnsubmul(b, 1, j), a.isZero() || (a.negative ^= 1);
- q && (q.words[j] = qj);
- }
- return (
- q && q.strip(),
- a.strip(),
- mode !== "div" && shift !== 0 && a.iushrn(shift),
- {
- div: q || null,
- mod: a,
- }
- );
- }),
- (BN.prototype.divmod = function (num, mode, positive) {
- if ((assert(!num.isZero()), this.isZero()))
- return {
- div: new BN(0),
- mod: new BN(0),
- };
- var div, mod, res;
- return this.negative !== 0 && num.negative === 0
- ? ((res = this.neg().divmod(num, mode)),
- mode !== "mod" && (div = res.div.neg()),
- mode !== "div" && ((mod = res.mod.neg()), positive && mod.negative !== 0 && mod.iadd(num)),
- {
- div,
- mod,
- })
- : this.negative === 0 && num.negative !== 0
- ? ((res = this.divmod(num.neg(), mode)),
- mode !== "mod" && (div = res.div.neg()),
- {
- div,
- mod: res.mod,
- })
- : (this.negative & num.negative) !== 0
- ? ((res = this.neg().divmod(num.neg(), mode)),
- mode !== "div" && ((mod = res.mod.neg()), positive && mod.negative !== 0 && mod.isub(num)),
- {
- div: res.div,
- mod,
- })
- : num.length > this.length || this.cmp(num) < 0
- ? {
- div: new BN(0),
- mod: this,
- }
- : num.length === 1
- ? mode === "div"
- ? {
- div: this.divn(num.words[0]),
- mod: null,
- }
- : mode === "mod"
- ? {
- div: null,
- mod: new BN(this.modn(num.words[0])),
- }
- : {
- div: this.divn(num.words[0]),
- mod: new BN(this.modn(num.words[0])),
- }
- : this._wordDiv(num, mode);
- }),
- (BN.prototype.div = function (num) {
- return this.divmod(num, "div", !1).div;
- }),
- (BN.prototype.mod = function (num) {
- return this.divmod(num, "mod", !1).mod;
- }),
- (BN.prototype.umod = function (num) {
- return this.divmod(num, "mod", !0).mod;
- }),
- (BN.prototype.divRound = function (num) {
- var dm = this.divmod(num);
- if (dm.mod.isZero()) return dm.div;
- var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod,
- half = num.ushrn(1),
- r2 = num.andln(1),
- cmp = mod.cmp(half);
- return cmp < 0 || (r2 === 1 && cmp === 0)
- ? dm.div
- : dm.div.negative !== 0
- ? dm.div.isubn(1)
- : dm.div.iaddn(1);
- }),
- (BN.prototype.modn = function (num) {
- assert(num <= 67108863);
- for (var p = (1 << 26) % num, acc = 0, i = this.length - 1; i >= 0; i--)
- acc = (p * acc + (this.words[i] | 0)) % num;
- return acc;
- }),
- (BN.prototype.idivn = function (num) {
- assert(num <= 67108863);
- for (var carry = 0, i = this.length - 1; i >= 0; i--) {
- var w = (this.words[i] | 0) + carry * 67108864;
- (this.words[i] = (w / num) | 0), (carry = w % num);
- }
- return this.strip();
- }),
- (BN.prototype.divn = function (num) {
- return this.clone().idivn(num);
- }),
- (BN.prototype.egcd = function (p) {
- assert(p.negative === 0), assert(!p.isZero());
- var x = this,
- y = p.clone();
- x.negative !== 0 ? (x = x.umod(p)) : (x = x.clone());
- for (var A = new BN(1), B = new BN(0), C = new BN(0), D = new BN(1), g = 0; x.isEven() && y.isEven(); )
- x.iushrn(1), y.iushrn(1), ++g;
- for (var yp = y.clone(), xp = x.clone(); !x.isZero(); ) {
- for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
- if (i > 0)
- for (x.iushrn(i); i-- > 0; )
- (A.isOdd() || B.isOdd()) && (A.iadd(yp), B.isub(xp)), A.iushrn(1), B.iushrn(1);
- for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
- if (j > 0)
- for (y.iushrn(j); j-- > 0; )
- (C.isOdd() || D.isOdd()) && (C.iadd(yp), D.isub(xp)), C.iushrn(1), D.iushrn(1);
- x.cmp(y) >= 0 ? (x.isub(y), A.isub(C), B.isub(D)) : (y.isub(x), C.isub(A), D.isub(B));
- }
- return {
- a: C,
- b: D,
- gcd: y.iushln(g),
- };
- }),
- (BN.prototype._invmp = function (p) {
- assert(p.negative === 0), assert(!p.isZero());
- var a = this,
- b = p.clone();
- a.negative !== 0 ? (a = a.umod(p)) : (a = a.clone());
- for (var x1 = new BN(1), x2 = new BN(0), delta = b.clone(); a.cmpn(1) > 0 && b.cmpn(1) > 0; ) {
- for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
- if (i > 0) for (a.iushrn(i); i-- > 0; ) x1.isOdd() && x1.iadd(delta), x1.iushrn(1);
- for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
- if (j > 0) for (b.iushrn(j); j-- > 0; ) x2.isOdd() && x2.iadd(delta), x2.iushrn(1);
- a.cmp(b) >= 0 ? (a.isub(b), x1.isub(x2)) : (b.isub(a), x2.isub(x1));
- }
- var res;
- return a.cmpn(1) === 0 ? (res = x1) : (res = x2), res.cmpn(0) < 0 && res.iadd(p), res;
- }),
- (BN.prototype.gcd = function (num) {
- if (this.isZero()) return num.abs();
- if (num.isZero()) return this.abs();
- var a = this.clone(),
- b = num.clone();
- (a.negative = 0), (b.negative = 0);
- for (var shift = 0; a.isEven() && b.isEven(); shift++) a.iushrn(1), b.iushrn(1);
- do {
- for (; a.isEven(); ) a.iushrn(1);
- for (; b.isEven(); ) b.iushrn(1);
- var r = a.cmp(b);
- if (r < 0) {
- var t = a;
- (a = b), (b = t);
- } else if (r === 0 || b.cmpn(1) === 0) break;
- a.isub(b);
- } while (!0);
- return b.iushln(shift);
- }),
- (BN.prototype.invm = function (num) {
- return this.egcd(num).a.umod(num);
- }),
- (BN.prototype.isEven = function () {
- return (this.words[0] & 1) === 0;
- }),
- (BN.prototype.isOdd = function () {
- return (this.words[0] & 1) === 1;
- }),
- (BN.prototype.andln = function (num) {
- return this.words[0] & num;
- }),
- (BN.prototype.bincn = function (bit) {
- assert(typeof bit == "number");
- var r = bit % 26,
- s = (bit - r) / 26,
- q = 1 << r;
- if (this.length <= s) return this._expand(s + 1), (this.words[s] |= q), this;
- for (var carry = q, i = s; carry !== 0 && i < this.length; i++) {
- var w = this.words[i] | 0;
- (w += carry), (carry = w >>> 26), (w &= 67108863), (this.words[i] = w);
- }
- return carry !== 0 && ((this.words[i] = carry), this.length++), this;
- }),
- (BN.prototype.isZero = function () {
- return this.length === 1 && this.words[0] === 0;
- }),
- (BN.prototype.cmpn = function (num) {
- var negative = num < 0;
- if (this.negative !== 0 && !negative) return -1;
- if (this.negative === 0 && negative) return 1;
- this.strip();
- var res;
- if (this.length > 1) res = 1;
- else {
- negative && (num = -num), assert(num <= 67108863, "Number is too big");
- var w = this.words[0] | 0;
- res = w === num ? 0 : w < num ? -1 : 1;
- }
- return this.negative !== 0 ? -res | 0 : res;
- }),
- (BN.prototype.cmp = function (num) {
- if (this.negative !== 0 && num.negative === 0) return -1;
- if (this.negative === 0 && num.negative !== 0) return 1;
- var res = this.ucmp(num);
- return this.negative !== 0 ? -res | 0 : res;
- }),
- (BN.prototype.ucmp = function (num) {
- if (this.length > num.length) return 1;
- if (this.length < num.length) return -1;
- for (var res = 0, i = this.length - 1; i >= 0; i--) {
- var a = this.words[i] | 0,
- b = num.words[i] | 0;
- if (a !== b) {
- a < b ? (res = -1) : a > b && (res = 1);
- break;
- }
- }
- return res;
- }),
- (BN.prototype.gtn = function (num) {
- return this.cmpn(num) === 1;
- }),
- (BN.prototype.gt = function (num) {
- return this.cmp(num) === 1;
- }),
- (BN.prototype.gten = function (num) {
- return this.cmpn(num) >= 0;
- }),
- (BN.prototype.gte = function (num) {
- return this.cmp(num) >= 0;
- }),
- (BN.prototype.ltn = function (num) {
- return this.cmpn(num) === -1;
- }),
- (BN.prototype.lt = function (num) {
- return this.cmp(num) === -1;
- }),
- (BN.prototype.lten = function (num) {
- return this.cmpn(num) <= 0;
- }),
- (BN.prototype.lte = function (num) {
- return this.cmp(num) <= 0;
- }),
- (BN.prototype.eqn = function (num) {
- return this.cmpn(num) === 0;
- }),
- (BN.prototype.eq = function (num) {
- return this.cmp(num) === 0;
- }),
- (BN.red = function (num) {
- return new Red(num);
- }),
- (BN.prototype.toRed = function (ctx) {
- return (
- assert(!this.red, "Already a number in reduction context"),
- assert(this.negative === 0, "red works only with positives"),
- ctx.convertTo(this)._forceRed(ctx)
- );
- }),
- (BN.prototype.fromRed = function () {
- return assert(this.red, "fromRed works only with numbers in reduction context"), this.red.convertFrom(this);
- }),
- (BN.prototype._forceRed = function (ctx) {
- return (this.red = ctx), this;
- }),
- (BN.prototype.forceRed = function (ctx) {
- return assert(!this.red, "Already a number in reduction context"), this._forceRed(ctx);
- }),
- (BN.prototype.redAdd = function (num) {
- return assert(this.red, "redAdd works only with red numbers"), this.red.add(this, num);
- }),
- (BN.prototype.redIAdd = function (num) {
- return assert(this.red, "redIAdd works only with red numbers"), this.red.iadd(this, num);
- }),
- (BN.prototype.redSub = function (num) {
- return assert(this.red, "redSub works only with red numbers"), this.red.sub(this, num);
- }),
- (BN.prototype.redISub = function (num) {
- return assert(this.red, "redISub works only with red numbers"), this.red.isub(this, num);
- }),
- (BN.prototype.redShl = function (num) {
- return assert(this.red, "redShl works only with red numbers"), this.red.shl(this, num);
- }),
- (BN.prototype.redMul = function (num) {
- return (
- assert(this.red, "redMul works only with red numbers"),
- this.red._verify2(this, num),
- this.red.mul(this, num)
- );
- }),
- (BN.prototype.redIMul = function (num) {
- return (
- assert(this.red, "redMul works only with red numbers"),
- this.red._verify2(this, num),
- this.red.imul(this, num)
- );
- }),
- (BN.prototype.redSqr = function () {
- return assert(this.red, "redSqr works only with red numbers"), this.red._verify1(this), this.red.sqr(this);
- }),
- (BN.prototype.redISqr = function () {
- return assert(this.red, "redISqr works only with red numbers"), this.red._verify1(this), this.red.isqr(this);
- }),
- (BN.prototype.redSqrt = function () {
- return assert(this.red, "redSqrt works only with red numbers"), this.red._verify1(this), this.red.sqrt(this);
- }),
- (BN.prototype.redInvm = function () {
- return assert(this.red, "redInvm works only with red numbers"), this.red._verify1(this), this.red.invm(this);
- }),
- (BN.prototype.redNeg = function () {
- return assert(this.red, "redNeg works only with red numbers"), this.red._verify1(this), this.red.neg(this);
- }),
- (BN.prototype.redPow = function (num) {
- return assert(this.red && !num.red, "redPow(normalNum)"), this.red._verify1(this), this.red.pow(this, num);
- });
- var primes = {
- k256: null,
- p224: null,
- p192: null,
- p25519: null,
- };
- function MPrime(name, p) {
- (this.name = name),
- (this.p = new BN(p, 16)),
- (this.n = this.p.bitLength()),
- (this.k = new BN(1).iushln(this.n).isub(this.p)),
- (this.tmp = this._tmp());
- }
- (MPrime.prototype._tmp = function () {
- var tmp = new BN(null);
- return (tmp.words = new Array(Math.ceil(this.n / 13))), tmp;
- }),
- (MPrime.prototype.ireduce = function (num) {
- var r = num,
- rlen;
- do this.split(r, this.tmp), (r = this.imulK(r)), (r = r.iadd(this.tmp)), (rlen = r.bitLength());
- while (rlen > this.n);
- var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
- return (
- cmp === 0
- ? ((r.words[0] = 0), (r.length = 1))
- : cmp > 0
- ? r.isub(this.p)
- : r.strip !== void 0
- ? r.strip()
- : r._strip(),
- r
- );
- }),
- (MPrime.prototype.split = function (input, out) {
- input.iushrn(this.n, 0, out);
- }),
- (MPrime.prototype.imulK = function (num) {
- return num.imul(this.k);
- });
- function K256() {
- MPrime.call(this, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f");
- }
- inherits(K256, MPrime),
- (K256.prototype.split = function (input, output) {
- for (var mask = 4194303, outLen = Math.min(input.length, 9), i = 0; i < outLen; i++)
- output.words[i] = input.words[i];
- if (((output.length = outLen), input.length <= 9)) {
- (input.words[0] = 0), (input.length = 1);
- return;
- }
- var prev = input.words[9];
- for (output.words[output.length++] = prev & mask, i = 10; i < input.length; i++) {
- var next = input.words[i] | 0;
- (input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22)), (prev = next);
- }
- (prev >>>= 22),
- (input.words[i - 10] = prev),
- prev === 0 && input.length > 10 ? (input.length -= 10) : (input.length -= 9);
- }),
- (K256.prototype.imulK = function (num) {
- (num.words[num.length] = 0), (num.words[num.length + 1] = 0), (num.length += 2);
- for (var lo = 0, i = 0; i < num.length; i++) {
- var w = num.words[i] | 0;
- (lo += w * 977), (num.words[i] = lo & 67108863), (lo = w * 64 + ((lo / 67108864) | 0));
- }
- return (
- num.words[num.length - 1] === 0 && (num.length--, num.words[num.length - 1] === 0 && num.length--), num
- );
- });
- function P224() {
- MPrime.call(this, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001");
- }
- inherits(P224, MPrime);
- function P192() {
- MPrime.call(this, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff");
- }
- inherits(P192, MPrime);
- function P25519() {
- MPrime.call(this, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed");
- }
- inherits(P25519, MPrime),
- (P25519.prototype.imulK = function (num) {
- for (var carry = 0, i = 0; i < num.length; i++) {
- var hi = (num.words[i] | 0) * 19 + carry,
- lo = hi & 67108863;
- (hi >>>= 26), (num.words[i] = lo), (carry = hi);
- }
- return carry !== 0 && (num.words[num.length++] = carry), num;
- }),
- (BN._prime = function (name) {
- if (primes[name]) return primes[name];
- var prime2;
- if (name === "k256") prime2 = new K256();
- else if (name === "p224") prime2 = new P224();
- else if (name === "p192") prime2 = new P192();
- else if (name === "p25519") prime2 = new P25519();
- else throw new Error("Unknown prime " + name);
- return (primes[name] = prime2), prime2;
- });
- function Red(m) {
- if (typeof m == "string") {
- var prime = BN._prime(m);
- (this.m = prime.p), (this.prime = prime);
- } else assert(m.gtn(1), "modulus must be greater than 1"), (this.m = m), (this.prime = null);
- }
- (Red.prototype._verify1 = function (a) {
- assert(a.negative === 0, "red works only with positives"), assert(a.red, "red works only with red numbers");
- }),
- (Red.prototype._verify2 = function (a, b) {
- assert((a.negative | b.negative) === 0, "red works only with positives"),
- assert(a.red && a.red === b.red, "red works only with red numbers");
- }),
- (Red.prototype.imod = function (a) {
- return this.prime ? this.prime.ireduce(a)._forceRed(this) : a.umod(this.m)._forceRed(this);
- }),
- (Red.prototype.neg = function (a) {
- return a.isZero() ? a.clone() : this.m.sub(a)._forceRed(this);
- }),
- (Red.prototype.add = function (a, b) {
- this._verify2(a, b);
- var res = a.add(b);
- return res.cmp(this.m) >= 0 && res.isub(this.m), res._forceRed(this);
- }),
- (Red.prototype.iadd = function (a, b) {
- this._verify2(a, b);
- var res = a.iadd(b);
- return res.cmp(this.m) >= 0 && res.isub(this.m), res;
- }),
- (Red.prototype.sub = function (a, b) {
- this._verify2(a, b);
- var res = a.sub(b);
- return res.cmpn(0) < 0 && res.iadd(this.m), res._forceRed(this);
- }),
- (Red.prototype.isub = function (a, b) {
- this._verify2(a, b);
- var res = a.isub(b);
- return res.cmpn(0) < 0 && res.iadd(this.m), res;
- }),
- (Red.prototype.shl = function (a, num) {
- return this._verify1(a), this.imod(a.ushln(num));
- }),
- (Red.prototype.imul = function (a, b) {
- return this._verify2(a, b), this.imod(a.imul(b));
- }),
- (Red.prototype.mul = function (a, b) {
- return this._verify2(a, b), this.imod(a.mul(b));
- }),
- (Red.prototype.isqr = function (a) {
- return this.imul(a, a.clone());
- }),
- (Red.prototype.sqr = function (a) {
- return this.mul(a, a);
- }),
- (Red.prototype.sqrt = function (a) {
- if (a.isZero()) return a.clone();
- var mod3 = this.m.andln(3);
- if ((assert(mod3 % 2 === 1), mod3 === 3)) {
- var pow = this.m.add(new BN(1)).iushrn(2);
- return this.pow(a, pow);
- }
- for (var q = this.m.subn(1), s = 0; !q.isZero() && q.andln(1) === 0; ) s++, q.iushrn(1);
- assert(!q.isZero());
- var one = new BN(1).toRed(this),
- nOne = one.redNeg(),
- lpow = this.m.subn(1).iushrn(1),
- z = this.m.bitLength();
- for (z = new BN(2 * z * z).toRed(this); this.pow(z, lpow).cmp(nOne) !== 0; ) z.redIAdd(nOne);
- for (
- var c = this.pow(z, q), r = this.pow(a, q.addn(1).iushrn(1)), t = this.pow(a, q), m = s;
- t.cmp(one) !== 0;
-
- ) {
- for (var tmp = t, i = 0; tmp.cmp(one) !== 0; i++) tmp = tmp.redSqr();
- assert(i < m);
- var b = this.pow(c, new BN(1).iushln(m - i - 1));
- (r = r.redMul(b)), (c = b.redSqr()), (t = t.redMul(c)), (m = i);
- }
- return r;
- }),
- (Red.prototype.invm = function (a) {
- var inv = a._invmp(this.m);
- return inv.negative !== 0 ? ((inv.negative = 0), this.imod(inv).redNeg()) : this.imod(inv);
- }),
- (Red.prototype.pow = function (a, num) {
- if (num.isZero()) return new BN(1).toRed(this);
- if (num.cmpn(1) === 0) return a.clone();
- var windowSize = 4,
- wnd = new Array(1 << windowSize);
- (wnd[0] = new BN(1).toRed(this)), (wnd[1] = a);
- for (var i = 2; i < wnd.length; i++) wnd[i] = this.mul(wnd[i - 1], a);
- var res = wnd[0],
- current = 0,
- currentLen = 0,
- start = num.bitLength() % 26;
- for (start === 0 && (start = 26), i = num.length - 1; i >= 0; i--) {
- for (var word = num.words[i], j = start - 1; j >= 0; j--) {
- var bit = (word >> j) & 1;
- if ((res !== wnd[0] && (res = this.sqr(res)), bit === 0 && current === 0)) {
- currentLen = 0;
- continue;
- }
- (current <<= 1),
- (current |= bit),
- currentLen++,
- !(currentLen !== windowSize && (i !== 0 || j !== 0)) &&
- ((res = this.mul(res, wnd[current])), (currentLen = 0), (current = 0));
- }
- start = 26;
- }
- return res;
- }),
- (Red.prototype.convertTo = function (num) {
- var r = num.umod(this.m);
- return r === num ? r.clone() : r;
- }),
- (Red.prototype.convertFrom = function (num) {
- var res = num.clone();
- return (res.red = null), res;
- }),
- (BN.mont = function (num) {
- return new Mont(num);
- });
- function Mont(m) {
- Red.call(this, m),
- (this.shift = this.m.bitLength()),
- this.shift % 26 !== 0 && (this.shift += 26 - (this.shift % 26)),
- (this.r = new BN(1).iushln(this.shift)),
- (this.r2 = this.imod(this.r.sqr())),
- (this.rinv = this.r._invmp(this.m)),
- (this.minv = this.rinv.mul(this.r).isubn(1).div(this.m)),
- (this.minv = this.minv.umod(this.r)),
- (this.minv = this.r.sub(this.minv));
- }
- inherits(Mont, Red),
- (Mont.prototype.convertTo = function (num) {
- return this.imod(num.ushln(this.shift));
- }),
- (Mont.prototype.convertFrom = function (num) {
- var r = this.imod(num.mul(this.rinv));
- return (r.red = null), r;
- }),
- (Mont.prototype.imul = function (a, b) {
- if (a.isZero() || b.isZero()) return (a.words[0] = 0), (a.length = 1), a;
- var t = a.imul(b),
- c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),
- u = t.isub(c).iushrn(this.shift),
- res = u;
- return (
- u.cmp(this.m) >= 0 ? (res = u.isub(this.m)) : u.cmpn(0) < 0 && (res = u.iadd(this.m)), res._forceRed(this)
- );
- }),
- (Mont.prototype.mul = function (a, b) {
- if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
- var t = a.mul(b),
- c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),
- u = t.isub(c).iushrn(this.shift),
- res = u;
- return (
- u.cmp(this.m) >= 0 ? (res = u.isub(this.m)) : u.cmpn(0) < 0 && (res = u.iadd(this.m)), res._forceRed(this)
- );
- }),
- (Mont.prototype.invm = function (a) {
- var res = this.imod(a._invmp(this.m).mul(this.r2));
- return res._forceRed(this);
- });
- })(typeof module > "u" || module, exports);
- },
-});
+var require_bn6 = require_bn;
// node_modules/create-ecdh/browser.js
var require_browser9 = __commonJS({
@@ -21449,6 +11470,7 @@ var require_browser9 = __commonJS({
(this.curve = new elliptic.ec(this.curveType.name)),
(this.keys = void 0);
}
+ ECDH.prototype = {};
ECDH.prototype.generateKeys = function (enc, format) {
return (this.keys = this.curve.genKeyPair()), this.getPublicKey(enc, format);
};
@@ -21517,1991 +11539,7 @@ var require_xor = __commonJS({
});
// node_modules/public-encrypt/node_modules/bn.js/lib/bn.js
-var require_bn7 = __commonJS({
- "node_modules/public-encrypt/node_modules/bn.js/lib/bn.js"(exports, module) {
- (function (module2, exports2) {
- "use strict";
- function assert(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 BN(number, base, endian) {
- if (BN.isBN(number)) return number;
- (this.negative = 0),
- (this.words = null),
- (this.length = 0),
- (this.red = null),
- number !== null &&
- ((base === "le" || base === "be") && ((endian = base), (base = 10)),
- this._init(number || 0, base || 10, endian || "be"));
- }
- typeof module2 == "object" ? (module2.exports = BN) : (exports2.BN = BN), (BN.BN = BN), (BN.wordSize = 26);
- var Buffer2 = globalThis.Buffer;
- (BN.isBN = function (num) {
- return num instanceof BN
- ? !0
- : num !== null &&
- typeof num == "object" &&
- num.constructor.wordSize === BN.wordSize &&
- Array.isArray(num.words);
- }),
- (BN.max = function (left, right) {
- return left.cmp(right) > 0 ? left : right;
- }),
- (BN.min = function (left, right) {
- return left.cmp(right) < 0 ? left : right;
- }),
- (BN.prototype._init = function (number, base, endian) {
- if (typeof number == "number") return this._initNumber(number, base, endian);
- if (typeof number == "object") return this._initArray(number, base, endian);
- base === "hex" && (base = 16),
- assert(base === (base | 0) && base >= 2 && base <= 36),
- (number = number.toString().replace(/\s+/g, ""));
- var start = 0;
- number[0] === "-" && (start++, (this.negative = 1)),
- start < number.length &&
- (base === 16
- ? this._parseHex(number, start, endian)
- : (this._parseBase(number, base, start),
- endian === "le" && this._initArray(this.toArray(), base, endian)));
- }),
- (BN.prototype._initNumber = function (number, base, endian) {
- number < 0 && ((this.negative = 1), (number = -number)),
- number < 67108864
- ? ((this.words = [number & 67108863]), (this.length = 1))
- : number < 4503599627370496
- ? ((this.words = [number & 67108863, (number / 67108864) & 67108863]), (this.length = 2))
- : (assert(number < 9007199254740992),
- (this.words = [number & 67108863, (number / 67108864) & 67108863, 1]),
- (this.length = 3)),
- endian === "le" && this._initArray(this.toArray(), base, endian);
- }),
- (BN.prototype._initArray = function (number, base, endian) {
- if ((assert(typeof number.length == "number"), number.length <= 0))
- return (this.words = [0]), (this.length = 1), 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,
- 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),
- 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),
- off >= 26 && ((off -= 26), j++);
- return this.strip();
- });
- function parseHex4Bits(string, index) {
- var c = string.charCodeAt(index);
- return c >= 65 && c <= 70 ? c - 55 : c >= 97 && c <= 102 ? c - 87 : (c - 48) & 15;
- }
- function parseHexByte(string, lowerBound, index) {
- var r = parseHex4Bits(string, index);
- return index - 1 >= lowerBound && (r |= parseHex4Bits(string, index - 1) << 4), r;
- }
- BN.prototype._parseHex = function (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,
- j = 0,
- w;
- if (endian === "be")
- for (i = number.length - 1; i >= start; i -= 2)
- (w = parseHexByte(number, start, i) << off),
- (this.words[j] |= w & 67108863),
- off >= 18 ? ((off -= 18), (j += 1), (this.words[j] |= w >>> 26)) : (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),
- off >= 18 ? ((off -= 18), (j += 1), (this.words[j] |= w >>> 26)) : (off += 8);
- }
- this.strip();
- };
- function parseBase(str, start, end, mul) {
- for (var r = 0, len = Math.min(str.length, end), i = start; i < len; i++) {
- var c = str.charCodeAt(i) - 48;
- (r *= mul), c >= 49 ? (r += c - 49 + 10) : c >= 17 ? (r += c - 17 + 10) : (r += c);
- }
- return r;
- }
- (BN.prototype._parseBase = function (number, base, start) {
- (this.words = [0]), (this.length = 1);
- for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) limbLen++;
- limbLen--, (limbPow = (limbPow / base) | 0);
- for (
- var total = number.length - start,
- mod = total % limbLen,
- end = Math.min(total, total - mod) + start,
- word = 0,
- i = start;
- i < end;
- i += limbLen
- )
- (word = parseBase(number, i, i + limbLen, base)),
- this.imuln(limbPow),
- this.words[0] + word < 67108864 ? (this.words[0] += word) : this._iaddn(word);
- if (mod !== 0) {
- var pow = 1;
- for (word = parseBase(number, i, number.length, base), i = 0; i < mod; i++) pow *= base;
- this.imuln(pow), this.words[0] + word < 67108864 ? (this.words[0] += word) : this._iaddn(word);
- }
- this.strip();
- }),
- (BN.prototype.copy = function (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);
- }),
- (BN.prototype.clone = function () {
- var r = new BN(null);
- return this.copy(r), r;
- }),
- (BN.prototype._expand = function (size) {
- for (; this.length < size; ) this.words[this.length++] = 0;
- return this;
- }),
- (BN.prototype.strip = function () {
- for (; this.length > 1 && this.words[this.length - 1] === 0; ) this.length--;
- return this._normSign();
- }),
- (BN.prototype._normSign = function () {
- return this.length === 1 && this.words[0] === 0 && (this.negative = 0), this;
- }),
- (BN.prototype.inspect = function () {
- return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
- });
- var zeros = [
- "",
- "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",
- ],
- 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,
- ],
- 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,
- ];
- (BN.prototype.toString = function (base, padding) {
- (base = base || 10), (padding = padding | 0 || 1);
- var out;
- if (base === 16 || base === "hex") {
- out = "";
- for (var off = 0, carry = 0, i = 0; i < this.length; i++) {
- var w = this.words[i],
- word = (((w << off) | carry) & 16777215).toString(16);
- (carry = (w >>> (24 - off)) & 16777215),
- carry !== 0 || i !== this.length - 1 ? (out = zeros[6 - word.length] + word + out) : (out = word + out),
- (off += 2),
- off >= 26 && ((off -= 26), i--);
- }
- for (carry !== 0 && (out = carry.toString(16) + out); out.length % padding !== 0; ) out = "0" + out;
- return this.negative !== 0 && (out = "-" + out), out;
- }
- if (base === (base | 0) && base >= 2 && base <= 36) {
- var groupSize = groupSizes[base],
- groupBase = groupBases[base];
- out = "";
- var c = this.clone();
- for (c.negative = 0; !c.isZero(); ) {
- var r = c.modn(groupBase).toString(base);
- (c = c.idivn(groupBase)), c.isZero() ? (out = r + out) : (out = zeros[groupSize - r.length] + r + out);
- }
- for (this.isZero() && (out = "0" + out); out.length % padding !== 0; ) out = "0" + out;
- return this.negative !== 0 && (out = "-" + out), out;
- }
- assert(!1, "Base should be between 2 and 36");
- }),
- (BN.prototype.toNumber = function () {
- var ret = this.words[0];
- return (
- this.length === 2
- ? (ret += this.words[1] * 67108864)
- : this.length === 3 && this.words[2] === 1
- ? (ret += 4503599627370496 + this.words[1] * 67108864)
- : this.length > 2 && assert(!1, "Number can only safely store up to 53 bits"),
- this.negative !== 0 ? -ret : ret
- );
- }),
- (BN.prototype.toJSON = function () {
- return this.toString(16);
- }),
- (BN.prototype.toBuffer = function (endian, length) {
- return assert(typeof Buffer2 < "u"), this.toArrayLike(Buffer2, endian, length);
- }),
- (BN.prototype.toArray = function (endian, length) {
- return this.toArrayLike(Array, endian, length);
- }),
- (BN.prototype.toArrayLike = function (ArrayType, endian, length) {
- var byteLength = this.byteLength(),
- reqLength = length || Math.max(1, byteLength);
- assert(byteLength <= reqLength, "byte array longer than desired length"),
- assert(reqLength > 0, "Requested array length <= 0"),
- this.strip();
- var littleEndian = endian === "le",
- res = new ArrayType(reqLength),
- b,
- i,
- q = this.clone();
- if (littleEndian) {
- for (i = 0; !q.isZero(); i++) (b = q.andln(255)), q.iushrn(8), (res[i] = b);
- for (; i < reqLength; i++) res[i] = 0;
- } else {
- for (i = 0; i < reqLength - byteLength; i++) res[i] = 0;
- for (i = 0; !q.isZero(); i++) (b = q.andln(255)), q.iushrn(8), (res[reqLength - i - 1] = b);
- }
- return res;
- }),
- Math.clz32
- ? (BN.prototype._countBits = function (w) {
- return 32 - Math.clz32(w);
- })
- : (BN.prototype._countBits = function (w) {
- var t = w,
- r = 0;
- return (
- t >= 4096 && ((r += 13), (t >>>= 13)),
- t >= 64 && ((r += 7), (t >>>= 7)),
- t >= 8 && ((r += 4), (t >>>= 4)),
- t >= 2 && ((r += 2), (t >>>= 2)),
- r + t
- );
- }),
- (BN.prototype._zeroBits = function (w) {
- if (w === 0) return 26;
- var t = w,
- r = 0;
- return (
- (t & 8191) === 0 && ((r += 13), (t >>>= 13)),
- (t & 127) === 0 && ((r += 7), (t >>>= 7)),
- (t & 15) === 0 && ((r += 4), (t >>>= 4)),
- (t & 3) === 0 && ((r += 2), (t >>>= 2)),
- (t & 1) === 0 && r++,
- r
- );
- }),
- (BN.prototype.bitLength = function () {
- var w = this.words[this.length - 1],
- hi = this._countBits(w);
- return (this.length - 1) * 26 + hi;
- });
- function toBitArray(num) {
- for (var w = new Array(num.bitLength()), bit = 0; bit < w.length; bit++) {
- var off = (bit / 26) | 0,
- wbit = bit % 26;
- w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
- }
- return w;
- }
- (BN.prototype.zeroBits = function () {
- if (this.isZero()) return 0;
- for (var r = 0, i = 0; i < this.length; i++) {
- var b = this._zeroBits(this.words[i]);
- if (((r += b), b !== 26)) break;
- }
- return r;
- }),
- (BN.prototype.byteLength = function () {
- return Math.ceil(this.bitLength() / 8);
- }),
- (BN.prototype.toTwos = function (width) {
- return this.negative !== 0 ? this.abs().inotn(width).iaddn(1) : this.clone();
- }),
- (BN.prototype.fromTwos = function (width) {
- return this.testn(width - 1) ? this.notn(width).iaddn(1).ineg() : this.clone();
- }),
- (BN.prototype.isNeg = function () {
- return this.negative !== 0;
- }),
- (BN.prototype.neg = function () {
- return this.clone().ineg();
- }),
- (BN.prototype.ineg = function () {
- return this.isZero() || (this.negative ^= 1), this;
- }),
- (BN.prototype.iuor = function (num) {
- for (; 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();
- }),
- (BN.prototype.ior = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuor(num);
- }),
- (BN.prototype.or = function (num) {
- return this.length > num.length ? this.clone().ior(num) : num.clone().ior(this);
- }),
- (BN.prototype.uor = function (num) {
- return this.length > num.length ? this.clone().iuor(num) : num.clone().iuor(this);
- }),
- (BN.prototype.iuand = function (num) {
- var b;
- this.length > num.length ? (b = num) : (b = this);
- for (var i = 0; i < b.length; i++) this.words[i] = this.words[i] & num.words[i];
- return (this.length = b.length), this.strip();
- }),
- (BN.prototype.iand = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuand(num);
- }),
- (BN.prototype.and = function (num) {
- return this.length > num.length ? this.clone().iand(num) : num.clone().iand(this);
- }),
- (BN.prototype.uand = function (num) {
- return this.length > num.length ? this.clone().iuand(num) : num.clone().iuand(this);
- }),
- (BN.prototype.iuxor = function (num) {
- var a, b;
- this.length > num.length ? ((a = this), (b = num)) : ((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];
- return (this.length = a.length), this.strip();
- }),
- (BN.prototype.ixor = function (num) {
- return assert((this.negative | num.negative) === 0), this.iuxor(num);
- }),
- (BN.prototype.xor = function (num) {
- return this.length > num.length ? this.clone().ixor(num) : num.clone().ixor(this);
- }),
- (BN.prototype.uxor = function (num) {
- return this.length > num.length ? this.clone().iuxor(num) : num.clone().iuxor(this);
- }),
- (BN.prototype.inotn = function (width) {
- assert(typeof width == "number" && width >= 0);
- var bytesNeeded = Math.ceil(width / 26) | 0,
- bitsLeft = width % 26;
- this._expand(bytesNeeded), bitsLeft > 0 && bytesNeeded--;
- for (var i = 0; i < bytesNeeded; i++) this.words[i] = ~this.words[i] & 67108863;
- return bitsLeft > 0 && (this.words[i] = ~this.words[i] & (67108863 >> (26 - bitsLeft))), this.strip();
- }),
- (BN.prototype.notn = function (width) {
- return this.clone().inotn(width);
- }),
- (BN.prototype.setn = function (bit, val) {
- assert(typeof bit == "number" && bit >= 0);
- var off = (bit / 26) | 0,
- wbit = bit % 26;
- return (
- this._expand(off + 1),
- val
- ? (this.words[off] = this.words[off] | (1 << wbit))
- : (this.words[off] = this.words[off] & ~(1 << wbit)),
- this.strip()
- );
- }),
- (BN.prototype.iadd = function (num) {
- var r;
- if (this.negative !== 0 && num.negative === 0)
- return (this.negative = 0), (r = this.isub(num)), (this.negative ^= 1), this._normSign();
- if (this.negative === 0 && num.negative !== 0)
- return (num.negative = 0), (r = this.isub(num)), (num.negative = 1), r._normSign();
- var a, b;
- this.length > num.length ? ((a = this), (b = num)) : ((a = num), (b = this));
- for (var carry = 0, i = 0; i < b.length; i++)
- (r = (a.words[i] | 0) + (b.words[i] | 0) + carry), (this.words[i] = r & 67108863), (carry = r >>> 26);
- for (; carry !== 0 && i < a.length; i++)
- (r = (a.words[i] | 0) + carry), (this.words[i] = r & 67108863), (carry = r >>> 26);
- if (((this.length = a.length), carry !== 0)) (this.words[this.length] = carry), this.length++;
- else if (a !== this) for (; i < a.length; i++) this.words[i] = a.words[i];
- return this;
- }),
- (BN.prototype.add = function (num) {
- var res;
- return num.negative !== 0 && this.negative === 0
- ? ((num.negative = 0), (res = this.sub(num)), (num.negative ^= 1), res)
- : num.negative === 0 && this.negative !== 0
- ? ((this.negative = 0), (res = num.sub(this)), (this.negative = 1), res)
- : this.length > num.length
- ? this.clone().iadd(num)
- : num.clone().iadd(this);
- }),
- (BN.prototype.isub = function (num) {
- if (num.negative !== 0) {
- num.negative = 0;
- var r = this.iadd(num);
- return (num.negative = 1), r._normSign();
- } else if (this.negative !== 0)
- return (this.negative = 0), this.iadd(num), (this.negative = 1), this._normSign();
- var cmp = this.cmp(num);
- if (cmp === 0) return (this.negative = 0), (this.length = 1), (this.words[0] = 0), this;
- var a, b;
- cmp > 0 ? ((a = this), (b = num)) : ((a = num), (b = this));
- for (var carry = 0, i = 0; i < b.length; i++)
- (r = (a.words[i] | 0) - (b.words[i] | 0) + carry), (carry = r >> 26), (this.words[i] = r & 67108863);
- for (; carry !== 0 && i < a.length; i++)
- (r = (a.words[i] | 0) + carry), (carry = r >> 26), (this.words[i] = r & 67108863);
- if (carry === 0 && i < a.length && a !== this) for (; i < a.length; i++) this.words[i] = a.words[i];
- return (this.length = Math.max(this.length, i)), a !== this && (this.negative = 1), this.strip();
- }),
- (BN.prototype.sub = function (num) {
- return this.clone().isub(num);
- });
- function smallMulTo(self2, num, out) {
- out.negative = num.negative ^ self2.negative;
- var len = (self2.length + num.length) | 0;
- (out.length = len), (len = (len - 1) | 0);
- var a = self2.words[0] | 0,
- b = num.words[0] | 0,
- r = a * b,
- lo = r & 67108863,
- carry = (r / 67108864) | 0;
- out.words[0] = lo;
- for (var k = 1; k < len; k++) {
- for (
- var ncarry = carry >>> 26,
- rword = carry & 67108863,
- maxJ = Math.min(k, num.length - 1),
- j = Math.max(0, k - self2.length + 1);
- j <= maxJ;
- j++
- ) {
- var i = (k - j) | 0;
- (a = self2.words[i] | 0),
- (b = num.words[j] | 0),
- (r = a * b + rword),
- (ncarry += (r / 67108864) | 0),
- (rword = r & 67108863);
- }
- (out.words[k] = rword | 0), (carry = ncarry | 0);
- }
- return carry !== 0 ? (out.words[k] = carry | 0) : out.length--, out.strip();
- }
- var comb10MulTo = function (self2, num, out) {
- var a = self2.words,
- b = num.words,
- o = out.words,
- c = 0,
- lo,
- mid,
- hi,
- a0 = a[0] | 0,
- al0 = a0 & 8191,
- ah0 = a0 >>> 13,
- a1 = a[1] | 0,
- al1 = a1 & 8191,
- ah1 = a1 >>> 13,
- a2 = a[2] | 0,
- al2 = a2 & 8191,
- ah2 = a2 >>> 13,
- a3 = a[3] | 0,
- al3 = a3 & 8191,
- ah3 = a3 >>> 13,
- a4 = a[4] | 0,
- al4 = a4 & 8191,
- ah4 = a4 >>> 13,
- a5 = a[5] | 0,
- al5 = a5 & 8191,
- ah5 = a5 >>> 13,
- a6 = a[6] | 0,
- al6 = a6 & 8191,
- ah6 = a6 >>> 13,
- a7 = a[7] | 0,
- al7 = a7 & 8191,
- ah7 = a7 >>> 13,
- a8 = a[8] | 0,
- al8 = a8 & 8191,
- ah8 = a8 >>> 13,
- a9 = a[9] | 0,
- al9 = a9 & 8191,
- ah9 = a9 >>> 13,
- b0 = b[0] | 0,
- bl0 = b0 & 8191,
- bh0 = b0 >>> 13,
- b1 = b[1] | 0,
- bl1 = b1 & 8191,
- bh1 = b1 >>> 13,
- b2 = b[2] | 0,
- bl2 = b2 & 8191,
- bh2 = b2 >>> 13,
- b3 = b[3] | 0,
- bl3 = b3 & 8191,
- bh3 = b3 >>> 13,
- b4 = b[4] | 0,
- bl4 = b4 & 8191,
- bh4 = b4 >>> 13,
- b5 = b[5] | 0,
- bl5 = b5 & 8191,
- bh5 = b5 >>> 13,
- b6 = b[6] | 0,
- bl6 = b6 & 8191,
- bh6 = b6 >>> 13,
- b7 = b[7] | 0,
- bl7 = b7 & 8191,
- bh7 = b7 >>> 13,
- b8 = b[8] | 0,
- bl8 = b8 & 8191,
- bh8 = b8 >>> 13,
- b9 = b[9] | 0,
- bl9 = b9 & 8191,
- bh9 = b9 >>> 13;
- (out.negative = self2.negative ^ num.negative),
- (out.length = 19),
- (lo = Math.imul(al0, bl0)),
- (mid = Math.imul(al0, bh0)),
- (mid = (mid + Math.imul(ah0, bl0)) | 0),
- (hi = Math.imul(ah0, bh0));
- var w0 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0),
- (w0 &= 67108863),
- (lo = Math.imul(al1, bl0)),
- (mid = Math.imul(al1, bh0)),
- (mid = (mid + Math.imul(ah1, bl0)) | 0),
- (hi = Math.imul(ah1, bh0)),
- (lo = (lo + Math.imul(al0, bl1)) | 0),
- (mid = (mid + Math.imul(al0, bh1)) | 0),
- (mid = (mid + Math.imul(ah0, bl1)) | 0),
- (hi = (hi + Math.imul(ah0, bh1)) | 0);
- var w1 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0),
- (w1 &= 67108863),
- (lo = Math.imul(al2, bl0)),
- (mid = Math.imul(al2, bh0)),
- (mid = (mid + Math.imul(ah2, bl0)) | 0),
- (hi = Math.imul(ah2, bh0)),
- (lo = (lo + Math.imul(al1, bl1)) | 0),
- (mid = (mid + Math.imul(al1, bh1)) | 0),
- (mid = (mid + Math.imul(ah1, bl1)) | 0),
- (hi = (hi + Math.imul(ah1, bh1)) | 0),
- (lo = (lo + Math.imul(al0, bl2)) | 0),
- (mid = (mid + Math.imul(al0, bh2)) | 0),
- (mid = (mid + Math.imul(ah0, bl2)) | 0),
- (hi = (hi + Math.imul(ah0, bh2)) | 0);
- var w2 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0),
- (w2 &= 67108863),
- (lo = Math.imul(al3, bl0)),
- (mid = Math.imul(al3, bh0)),
- (mid = (mid + Math.imul(ah3, bl0)) | 0),
- (hi = Math.imul(ah3, bh0)),
- (lo = (lo + Math.imul(al2, bl1)) | 0),
- (mid = (mid + Math.imul(al2, bh1)) | 0),
- (mid = (mid + Math.imul(ah2, bl1)) | 0),
- (hi = (hi + Math.imul(ah2, bh1)) | 0),
- (lo = (lo + Math.imul(al1, bl2)) | 0),
- (mid = (mid + Math.imul(al1, bh2)) | 0),
- (mid = (mid + Math.imul(ah1, bl2)) | 0),
- (hi = (hi + Math.imul(ah1, bh2)) | 0),
- (lo = (lo + Math.imul(al0, bl3)) | 0),
- (mid = (mid + Math.imul(al0, bh3)) | 0),
- (mid = (mid + Math.imul(ah0, bl3)) | 0),
- (hi = (hi + Math.imul(ah0, bh3)) | 0);
- var w3 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0),
- (w3 &= 67108863),
- (lo = Math.imul(al4, bl0)),
- (mid = Math.imul(al4, bh0)),
- (mid = (mid + Math.imul(ah4, bl0)) | 0),
- (hi = Math.imul(ah4, bh0)),
- (lo = (lo + Math.imul(al3, bl1)) | 0),
- (mid = (mid + Math.imul(al3, bh1)) | 0),
- (mid = (mid + Math.imul(ah3, bl1)) | 0),
- (hi = (hi + Math.imul(ah3, bh1)) | 0),
- (lo = (lo + Math.imul(al2, bl2)) | 0),
- (mid = (mid + Math.imul(al2, bh2)) | 0),
- (mid = (mid + Math.imul(ah2, bl2)) | 0),
- (hi = (hi + Math.imul(ah2, bh2)) | 0),
- (lo = (lo + Math.imul(al1, bl3)) | 0),
- (mid = (mid + Math.imul(al1, bh3)) | 0),
- (mid = (mid + Math.imul(ah1, bl3)) | 0),
- (hi = (hi + Math.imul(ah1, bh3)) | 0),
- (lo = (lo + Math.imul(al0, bl4)) | 0),
- (mid = (mid + Math.imul(al0, bh4)) | 0),
- (mid = (mid + Math.imul(ah0, bl4)) | 0),
- (hi = (hi + Math.imul(ah0, bh4)) | 0);
- var w4 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0),
- (w4 &= 67108863),
- (lo = Math.imul(al5, bl0)),
- (mid = Math.imul(al5, bh0)),
- (mid = (mid + Math.imul(ah5, bl0)) | 0),
- (hi = Math.imul(ah5, bh0)),
- (lo = (lo + Math.imul(al4, bl1)) | 0),
- (mid = (mid + Math.imul(al4, bh1)) | 0),
- (mid = (mid + Math.imul(ah4, bl1)) | 0),
- (hi = (hi + Math.imul(ah4, bh1)) | 0),
- (lo = (lo + Math.imul(al3, bl2)) | 0),
- (mid = (mid + Math.imul(al3, bh2)) | 0),
- (mid = (mid + Math.imul(ah3, bl2)) | 0),
- (hi = (hi + Math.imul(ah3, bh2)) | 0),
- (lo = (lo + Math.imul(al2, bl3)) | 0),
- (mid = (mid + Math.imul(al2, bh3)) | 0),
- (mid = (mid + Math.imul(ah2, bl3)) | 0),
- (hi = (hi + Math.imul(ah2, bh3)) | 0),
- (lo = (lo + Math.imul(al1, bl4)) | 0),
- (mid = (mid + Math.imul(al1, bh4)) | 0),
- (mid = (mid + Math.imul(ah1, bl4)) | 0),
- (hi = (hi + Math.imul(ah1, bh4)) | 0),
- (lo = (lo + Math.imul(al0, bl5)) | 0),
- (mid = (mid + Math.imul(al0, bh5)) | 0),
- (mid = (mid + Math.imul(ah0, bl5)) | 0),
- (hi = (hi + Math.imul(ah0, bh5)) | 0);
- var w5 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0),
- (w5 &= 67108863),
- (lo = Math.imul(al6, bl0)),
- (mid = Math.imul(al6, bh0)),
- (mid = (mid + Math.imul(ah6, bl0)) | 0),
- (hi = Math.imul(ah6, bh0)),
- (lo = (lo + Math.imul(al5, bl1)) | 0),
- (mid = (mid + Math.imul(al5, bh1)) | 0),
- (mid = (mid + Math.imul(ah5, bl1)) | 0),
- (hi = (hi + Math.imul(ah5, bh1)) | 0),
- (lo = (lo + Math.imul(al4, bl2)) | 0),
- (mid = (mid + Math.imul(al4, bh2)) | 0),
- (mid = (mid + Math.imul(ah4, bl2)) | 0),
- (hi = (hi + Math.imul(ah4, bh2)) | 0),
- (lo = (lo + Math.imul(al3, bl3)) | 0),
- (mid = (mid + Math.imul(al3, bh3)) | 0),
- (mid = (mid + Math.imul(ah3, bl3)) | 0),
- (hi = (hi + Math.imul(ah3, bh3)) | 0),
- (lo = (lo + Math.imul(al2, bl4)) | 0),
- (mid = (mid + Math.imul(al2, bh4)) | 0),
- (mid = (mid + Math.imul(ah2, bl4)) | 0),
- (hi = (hi + Math.imul(ah2, bh4)) | 0),
- (lo = (lo + Math.imul(al1, bl5)) | 0),
- (mid = (mid + Math.imul(al1, bh5)) | 0),
- (mid = (mid + Math.imul(ah1, bl5)) | 0),
- (hi = (hi + Math.imul(ah1, bh5)) | 0),
- (lo = (lo + Math.imul(al0, bl6)) | 0),
- (mid = (mid + Math.imul(al0, bh6)) | 0),
- (mid = (mid + Math.imul(ah0, bl6)) | 0),
- (hi = (hi + Math.imul(ah0, bh6)) | 0);
- var w6 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0),
- (w6 &= 67108863),
- (lo = Math.imul(al7, bl0)),
- (mid = Math.imul(al7, bh0)),
- (mid = (mid + Math.imul(ah7, bl0)) | 0),
- (hi = Math.imul(ah7, bh0)),
- (lo = (lo + Math.imul(al6, bl1)) | 0),
- (mid = (mid + Math.imul(al6, bh1)) | 0),
- (mid = (mid + Math.imul(ah6, bl1)) | 0),
- (hi = (hi + Math.imul(ah6, bh1)) | 0),
- (lo = (lo + Math.imul(al5, bl2)) | 0),
- (mid = (mid + Math.imul(al5, bh2)) | 0),
- (mid = (mid + Math.imul(ah5, bl2)) | 0),
- (hi = (hi + Math.imul(ah5, bh2)) | 0),
- (lo = (lo + Math.imul(al4, bl3)) | 0),
- (mid = (mid + Math.imul(al4, bh3)) | 0),
- (mid = (mid + Math.imul(ah4, bl3)) | 0),
- (hi = (hi + Math.imul(ah4, bh3)) | 0),
- (lo = (lo + Math.imul(al3, bl4)) | 0),
- (mid = (mid + Math.imul(al3, bh4)) | 0),
- (mid = (mid + Math.imul(ah3, bl4)) | 0),
- (hi = (hi + Math.imul(ah3, bh4)) | 0),
- (lo = (lo + Math.imul(al2, bl5)) | 0),
- (mid = (mid + Math.imul(al2, bh5)) | 0),
- (mid = (mid + Math.imul(ah2, bl5)) | 0),
- (hi = (hi + Math.imul(ah2, bh5)) | 0),
- (lo = (lo + Math.imul(al1, bl6)) | 0),
- (mid = (mid + Math.imul(al1, bh6)) | 0),
- (mid = (mid + Math.imul(ah1, bl6)) | 0),
- (hi = (hi + Math.imul(ah1, bh6)) | 0),
- (lo = (lo + Math.imul(al0, bl7)) | 0),
- (mid = (mid + Math.imul(al0, bh7)) | 0),
- (mid = (mid + Math.imul(ah0, bl7)) | 0),
- (hi = (hi + Math.imul(ah0, bh7)) | 0);
- var w7 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0),
- (w7 &= 67108863),
- (lo = Math.imul(al8, bl0)),
- (mid = Math.imul(al8, bh0)),
- (mid = (mid + Math.imul(ah8, bl0)) | 0),
- (hi = Math.imul(ah8, bh0)),
- (lo = (lo + Math.imul(al7, bl1)) | 0),
- (mid = (mid + Math.imul(al7, bh1)) | 0),
- (mid = (mid + Math.imul(ah7, bl1)) | 0),
- (hi = (hi + Math.imul(ah7, bh1)) | 0),
- (lo = (lo + Math.imul(al6, bl2)) | 0),
- (mid = (mid + Math.imul(al6, bh2)) | 0),
- (mid = (mid + Math.imul(ah6, bl2)) | 0),
- (hi = (hi + Math.imul(ah6, bh2)) | 0),
- (lo = (lo + Math.imul(al5, bl3)) | 0),
- (mid = (mid + Math.imul(al5, bh3)) | 0),
- (mid = (mid + Math.imul(ah5, bl3)) | 0),
- (hi = (hi + Math.imul(ah5, bh3)) | 0),
- (lo = (lo + Math.imul(al4, bl4)) | 0),
- (mid = (mid + Math.imul(al4, bh4)) | 0),
- (mid = (mid + Math.imul(ah4, bl4)) | 0),
- (hi = (hi + Math.imul(ah4, bh4)) | 0),
- (lo = (lo + Math.imul(al3, bl5)) | 0),
- (mid = (mid + Math.imul(al3, bh5)) | 0),
- (mid = (mid + Math.imul(ah3, bl5)) | 0),
- (hi = (hi + Math.imul(ah3, bh5)) | 0),
- (lo = (lo + Math.imul(al2, bl6)) | 0),
- (mid = (mid + Math.imul(al2, bh6)) | 0),
- (mid = (mid + Math.imul(ah2, bl6)) | 0),
- (hi = (hi + Math.imul(ah2, bh6)) | 0),
- (lo = (lo + Math.imul(al1, bl7)) | 0),
- (mid = (mid + Math.imul(al1, bh7)) | 0),
- (mid = (mid + Math.imul(ah1, bl7)) | 0),
- (hi = (hi + Math.imul(ah1, bh7)) | 0),
- (lo = (lo + Math.imul(al0, bl8)) | 0),
- (mid = (mid + Math.imul(al0, bh8)) | 0),
- (mid = (mid + Math.imul(ah0, bl8)) | 0),
- (hi = (hi + Math.imul(ah0, bh8)) | 0);
- var w8 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0),
- (w8 &= 67108863),
- (lo = Math.imul(al9, bl0)),
- (mid = Math.imul(al9, bh0)),
- (mid = (mid + Math.imul(ah9, bl0)) | 0),
- (hi = Math.imul(ah9, bh0)),
- (lo = (lo + Math.imul(al8, bl1)) | 0),
- (mid = (mid + Math.imul(al8, bh1)) | 0),
- (mid = (mid + Math.imul(ah8, bl1)) | 0),
- (hi = (hi + Math.imul(ah8, bh1)) | 0),
- (lo = (lo + Math.imul(al7, bl2)) | 0),
- (mid = (mid + Math.imul(al7, bh2)) | 0),
- (mid = (mid + Math.imul(ah7, bl2)) | 0),
- (hi = (hi + Math.imul(ah7, bh2)) | 0),
- (lo = (lo + Math.imul(al6, bl3)) | 0),
- (mid = (mid + Math.imul(al6, bh3)) | 0),
- (mid = (mid + Math.imul(ah6, bl3)) | 0),
- (hi = (hi + Math.imul(ah6, bh3)) | 0),
- (lo = (lo + Math.imul(al5, bl4)) | 0),
- (mid = (mid + Math.imul(al5, bh4)) | 0),
- (mid = (mid + Math.imul(ah5, bl4)) | 0),
- (hi = (hi + Math.imul(ah5, bh4)) | 0),
- (lo = (lo + Math.imul(al4, bl5)) | 0),
- (mid = (mid + Math.imul(al4, bh5)) | 0),
- (mid = (mid + Math.imul(ah4, bl5)) | 0),
- (hi = (hi + Math.imul(ah4, bh5)) | 0),
- (lo = (lo + Math.imul(al3, bl6)) | 0),
- (mid = (mid + Math.imul(al3, bh6)) | 0),
- (mid = (mid + Math.imul(ah3, bl6)) | 0),
- (hi = (hi + Math.imul(ah3, bh6)) | 0),
- (lo = (lo + Math.imul(al2, bl7)) | 0),
- (mid = (mid + Math.imul(al2, bh7)) | 0),
- (mid = (mid + Math.imul(ah2, bl7)) | 0),
- (hi = (hi + Math.imul(ah2, bh7)) | 0),
- (lo = (lo + Math.imul(al1, bl8)) | 0),
- (mid = (mid + Math.imul(al1, bh8)) | 0),
- (mid = (mid + Math.imul(ah1, bl8)) | 0),
- (hi = (hi + Math.imul(ah1, bh8)) | 0),
- (lo = (lo + Math.imul(al0, bl9)) | 0),
- (mid = (mid + Math.imul(al0, bh9)) | 0),
- (mid = (mid + Math.imul(ah0, bl9)) | 0),
- (hi = (hi + Math.imul(ah0, bh9)) | 0);
- var w9 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0),
- (w9 &= 67108863),
- (lo = Math.imul(al9, bl1)),
- (mid = Math.imul(al9, bh1)),
- (mid = (mid + Math.imul(ah9, bl1)) | 0),
- (hi = Math.imul(ah9, bh1)),
- (lo = (lo + Math.imul(al8, bl2)) | 0),
- (mid = (mid + Math.imul(al8, bh2)) | 0),
- (mid = (mid + Math.imul(ah8, bl2)) | 0),
- (hi = (hi + Math.imul(ah8, bh2)) | 0),
- (lo = (lo + Math.imul(al7, bl3)) | 0),
- (mid = (mid + Math.imul(al7, bh3)) | 0),
- (mid = (mid + Math.imul(ah7, bl3)) | 0),
- (hi = (hi + Math.imul(ah7, bh3)) | 0),
- (lo = (lo + Math.imul(al6, bl4)) | 0),
- (mid = (mid + Math.imul(al6, bh4)) | 0),
- (mid = (mid + Math.imul(ah6, bl4)) | 0),
- (hi = (hi + Math.imul(ah6, bh4)) | 0),
- (lo = (lo + Math.imul(al5, bl5)) | 0),
- (mid = (mid + Math.imul(al5, bh5)) | 0),
- (mid = (mid + Math.imul(ah5, bl5)) | 0),
- (hi = (hi + Math.imul(ah5, bh5)) | 0),
- (lo = (lo + Math.imul(al4, bl6)) | 0),
- (mid = (mid + Math.imul(al4, bh6)) | 0),
- (mid = (mid + Math.imul(ah4, bl6)) | 0),
- (hi = (hi + Math.imul(ah4, bh6)) | 0),
- (lo = (lo + Math.imul(al3, bl7)) | 0),
- (mid = (mid + Math.imul(al3, bh7)) | 0),
- (mid = (mid + Math.imul(ah3, bl7)) | 0),
- (hi = (hi + Math.imul(ah3, bh7)) | 0),
- (lo = (lo + Math.imul(al2, bl8)) | 0),
- (mid = (mid + Math.imul(al2, bh8)) | 0),
- (mid = (mid + Math.imul(ah2, bl8)) | 0),
- (hi = (hi + Math.imul(ah2, bh8)) | 0),
- (lo = (lo + Math.imul(al1, bl9)) | 0),
- (mid = (mid + Math.imul(al1, bh9)) | 0),
- (mid = (mid + Math.imul(ah1, bl9)) | 0),
- (hi = (hi + Math.imul(ah1, bh9)) | 0);
- var w10 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0),
- (w10 &= 67108863),
- (lo = Math.imul(al9, bl2)),
- (mid = Math.imul(al9, bh2)),
- (mid = (mid + Math.imul(ah9, bl2)) | 0),
- (hi = Math.imul(ah9, bh2)),
- (lo = (lo + Math.imul(al8, bl3)) | 0),
- (mid = (mid + Math.imul(al8, bh3)) | 0),
- (mid = (mid + Math.imul(ah8, bl3)) | 0),
- (hi = (hi + Math.imul(ah8, bh3)) | 0),
- (lo = (lo + Math.imul(al7, bl4)) | 0),
- (mid = (mid + Math.imul(al7, bh4)) | 0),
- (mid = (mid + Math.imul(ah7, bl4)) | 0),
- (hi = (hi + Math.imul(ah7, bh4)) | 0),
- (lo = (lo + Math.imul(al6, bl5)) | 0),
- (mid = (mid + Math.imul(al6, bh5)) | 0),
- (mid = (mid + Math.imul(ah6, bl5)) | 0),
- (hi = (hi + Math.imul(ah6, bh5)) | 0),
- (lo = (lo + Math.imul(al5, bl6)) | 0),
- (mid = (mid + Math.imul(al5, bh6)) | 0),
- (mid = (mid + Math.imul(ah5, bl6)) | 0),
- (hi = (hi + Math.imul(ah5, bh6)) | 0),
- (lo = (lo + Math.imul(al4, bl7)) | 0),
- (mid = (mid + Math.imul(al4, bh7)) | 0),
- (mid = (mid + Math.imul(ah4, bl7)) | 0),
- (hi = (hi + Math.imul(ah4, bh7)) | 0),
- (lo = (lo + Math.imul(al3, bl8)) | 0),
- (mid = (mid + Math.imul(al3, bh8)) | 0),
- (mid = (mid + Math.imul(ah3, bl8)) | 0),
- (hi = (hi + Math.imul(ah3, bh8)) | 0),
- (lo = (lo + Math.imul(al2, bl9)) | 0),
- (mid = (mid + Math.imul(al2, bh9)) | 0),
- (mid = (mid + Math.imul(ah2, bl9)) | 0),
- (hi = (hi + Math.imul(ah2, bh9)) | 0);
- var w11 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0),
- (w11 &= 67108863),
- (lo = Math.imul(al9, bl3)),
- (mid = Math.imul(al9, bh3)),
- (mid = (mid + Math.imul(ah9, bl3)) | 0),
- (hi = Math.imul(ah9, bh3)),
- (lo = (lo + Math.imul(al8, bl4)) | 0),
- (mid = (mid + Math.imul(al8, bh4)) | 0),
- (mid = (mid + Math.imul(ah8, bl4)) | 0),
- (hi = (hi + Math.imul(ah8, bh4)) | 0),
- (lo = (lo + Math.imul(al7, bl5)) | 0),
- (mid = (mid + Math.imul(al7, bh5)) | 0),
- (mid = (mid + Math.imul(ah7, bl5)) | 0),
- (hi = (hi + Math.imul(ah7, bh5)) | 0),
- (lo = (lo + Math.imul(al6, bl6)) | 0),
- (mid = (mid + Math.imul(al6, bh6)) | 0),
- (mid = (mid + Math.imul(ah6, bl6)) | 0),
- (hi = (hi + Math.imul(ah6, bh6)) | 0),
- (lo = (lo + Math.imul(al5, bl7)) | 0),
- (mid = (mid + Math.imul(al5, bh7)) | 0),
- (mid = (mid + Math.imul(ah5, bl7)) | 0),
- (hi = (hi + Math.imul(ah5, bh7)) | 0),
- (lo = (lo + Math.imul(al4, bl8)) | 0),
- (mid = (mid + Math.imul(al4, bh8)) | 0),
- (mid = (mid + Math.imul(ah4, bl8)) | 0),
- (hi = (hi + Math.imul(ah4, bh8)) | 0),
- (lo = (lo + Math.imul(al3, bl9)) | 0),
- (mid = (mid + Math.imul(al3, bh9)) | 0),
- (mid = (mid + Math.imul(ah3, bl9)) | 0),
- (hi = (hi + Math.imul(ah3, bh9)) | 0);
- var w12 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0),
- (w12 &= 67108863),
- (lo = Math.imul(al9, bl4)),
- (mid = Math.imul(al9, bh4)),
- (mid = (mid + Math.imul(ah9, bl4)) | 0),
- (hi = Math.imul(ah9, bh4)),
- (lo = (lo + Math.imul(al8, bl5)) | 0),
- (mid = (mid + Math.imul(al8, bh5)) | 0),
- (mid = (mid + Math.imul(ah8, bl5)) | 0),
- (hi = (hi + Math.imul(ah8, bh5)) | 0),
- (lo = (lo + Math.imul(al7, bl6)) | 0),
- (mid = (mid + Math.imul(al7, bh6)) | 0),
- (mid = (mid + Math.imul(ah7, bl6)) | 0),
- (hi = (hi + Math.imul(ah7, bh6)) | 0),
- (lo = (lo + Math.imul(al6, bl7)) | 0),
- (mid = (mid + Math.imul(al6, bh7)) | 0),
- (mid = (mid + Math.imul(ah6, bl7)) | 0),
- (hi = (hi + Math.imul(ah6, bh7)) | 0),
- (lo = (lo + Math.imul(al5, bl8)) | 0),
- (mid = (mid + Math.imul(al5, bh8)) | 0),
- (mid = (mid + Math.imul(ah5, bl8)) | 0),
- (hi = (hi + Math.imul(ah5, bh8)) | 0),
- (lo = (lo + Math.imul(al4, bl9)) | 0),
- (mid = (mid + Math.imul(al4, bh9)) | 0),
- (mid = (mid + Math.imul(ah4, bl9)) | 0),
- (hi = (hi + Math.imul(ah4, bh9)) | 0);
- var w13 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0),
- (w13 &= 67108863),
- (lo = Math.imul(al9, bl5)),
- (mid = Math.imul(al9, bh5)),
- (mid = (mid + Math.imul(ah9, bl5)) | 0),
- (hi = Math.imul(ah9, bh5)),
- (lo = (lo + Math.imul(al8, bl6)) | 0),
- (mid = (mid + Math.imul(al8, bh6)) | 0),
- (mid = (mid + Math.imul(ah8, bl6)) | 0),
- (hi = (hi + Math.imul(ah8, bh6)) | 0),
- (lo = (lo + Math.imul(al7, bl7)) | 0),
- (mid = (mid + Math.imul(al7, bh7)) | 0),
- (mid = (mid + Math.imul(ah7, bl7)) | 0),
- (hi = (hi + Math.imul(ah7, bh7)) | 0),
- (lo = (lo + Math.imul(al6, bl8)) | 0),
- (mid = (mid + Math.imul(al6, bh8)) | 0),
- (mid = (mid + Math.imul(ah6, bl8)) | 0),
- (hi = (hi + Math.imul(ah6, bh8)) | 0),
- (lo = (lo + Math.imul(al5, bl9)) | 0),
- (mid = (mid + Math.imul(al5, bh9)) | 0),
- (mid = (mid + Math.imul(ah5, bl9)) | 0),
- (hi = (hi + Math.imul(ah5, bh9)) | 0);
- var w14 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0),
- (w14 &= 67108863),
- (lo = Math.imul(al9, bl6)),
- (mid = Math.imul(al9, bh6)),
- (mid = (mid + Math.imul(ah9, bl6)) | 0),
- (hi = Math.imul(ah9, bh6)),
- (lo = (lo + Math.imul(al8, bl7)) | 0),
- (mid = (mid + Math.imul(al8, bh7)) | 0),
- (mid = (mid + Math.imul(ah8, bl7)) | 0),
- (hi = (hi + Math.imul(ah8, bh7)) | 0),
- (lo = (lo + Math.imul(al7, bl8)) | 0),
- (mid = (mid + Math.imul(al7, bh8)) | 0),
- (mid = (mid + Math.imul(ah7, bl8)) | 0),
- (hi = (hi + Math.imul(ah7, bh8)) | 0),
- (lo = (lo + Math.imul(al6, bl9)) | 0),
- (mid = (mid + Math.imul(al6, bh9)) | 0),
- (mid = (mid + Math.imul(ah6, bl9)) | 0),
- (hi = (hi + Math.imul(ah6, bh9)) | 0);
- var w15 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0),
- (w15 &= 67108863),
- (lo = Math.imul(al9, bl7)),
- (mid = Math.imul(al9, bh7)),
- (mid = (mid + Math.imul(ah9, bl7)) | 0),
- (hi = Math.imul(ah9, bh7)),
- (lo = (lo + Math.imul(al8, bl8)) | 0),
- (mid = (mid + Math.imul(al8, bh8)) | 0),
- (mid = (mid + Math.imul(ah8, bl8)) | 0),
- (hi = (hi + Math.imul(ah8, bh8)) | 0),
- (lo = (lo + Math.imul(al7, bl9)) | 0),
- (mid = (mid + Math.imul(al7, bh9)) | 0),
- (mid = (mid + Math.imul(ah7, bl9)) | 0),
- (hi = (hi + Math.imul(ah7, bh9)) | 0);
- var w16 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0),
- (w16 &= 67108863),
- (lo = Math.imul(al9, bl8)),
- (mid = Math.imul(al9, bh8)),
- (mid = (mid + Math.imul(ah9, bl8)) | 0),
- (hi = Math.imul(ah9, bh8)),
- (lo = (lo + Math.imul(al8, bl9)) | 0),
- (mid = (mid + Math.imul(al8, bh9)) | 0),
- (mid = (mid + Math.imul(ah8, bl9)) | 0),
- (hi = (hi + Math.imul(ah8, bh9)) | 0);
- var w17 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- (c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0),
- (w17 &= 67108863),
- (lo = Math.imul(al9, bl9)),
- (mid = Math.imul(al9, bh9)),
- (mid = (mid + Math.imul(ah9, bl9)) | 0),
- (hi = Math.imul(ah9, bh9));
- var w18 = (((c + lo) | 0) + ((mid & 8191) << 13)) | 0;
- return (
- (c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0),
- (w18 &= 67108863),
- (o[0] = w0),
- (o[1] = w1),
- (o[2] = w2),
- (o[3] = w3),
- (o[4] = w4),
- (o[5] = w5),
- (o[6] = w6),
- (o[7] = w7),
- (o[8] = w8),
- (o[9] = w9),
- (o[10] = w10),
- (o[11] = w11),
- (o[12] = w12),
- (o[13] = w13),
- (o[14] = w14),
- (o[15] = w15),
- (o[16] = w16),
- (o[17] = w17),
- (o[18] = w18),
- c !== 0 && ((o[19] = c), out.length++),
- out
- );
- };
- Math.imul || (comb10MulTo = smallMulTo);
- function bigMulTo(self2, num, out) {
- (out.negative = num.negative ^ self2.negative), (out.length = self2.length + num.length);
- for (var carry = 0, hncarry = 0, k = 0; k < out.length - 1; k++) {
- var ncarry = hncarry;
- hncarry = 0;
- for (
- var rword = carry & 67108863, maxJ = Math.min(k, num.length - 1), j = Math.max(0, k - self2.length + 1);
- j <= maxJ;
- j++
- ) {
- var i = k - j,
- a = self2.words[i] | 0,
- b = num.words[j] | 0,
- r = a * b,
- lo = r & 67108863;
- (ncarry = (ncarry + ((r / 67108864) | 0)) | 0),
- (lo = (lo + rword) | 0),
- (rword = lo & 67108863),
- (ncarry = (ncarry + (lo >>> 26)) | 0),
- (hncarry += ncarry >>> 26),
- (ncarry &= 67108863);
- }
- (out.words[k] = rword), (carry = ncarry), (ncarry = hncarry);
- }
- return carry !== 0 ? (out.words[k] = carry) : out.length--, out.strip();
- }
- function jumboMulTo(self2, num, out) {
- var fftm = new FFTM();
- return fftm.mulp(self2, num, out);
- }
- BN.prototype.mulTo = function (num, out) {
- var res,
- len = this.length + num.length;
- return (
- this.length === 10 && num.length === 10
- ? (res = comb10MulTo(this, num, out))
- : len < 63
- ? (res = smallMulTo(this, num, out))
- : len < 1024
- ? (res = bigMulTo(this, num, out))
- : (res = jumboMulTo(this, num, out)),
- res
- );
- };
- function FFTM(x, y) {
- (this.x = x), (this.y = y);
- }
- (FFTM.prototype.makeRBT = function (N) {
- for (var t = new Array(N), l = BN.prototype._countBits(N) - 1, i = 0; i < N; i++) t[i] = this.revBin(i, l, N);
- return t;
- }),
- (FFTM.prototype.revBin = function (x, l, N) {
- if (x === 0 || x === N - 1) return x;
- for (var rb = 0, i = 0; i < l; i++) (rb |= (x & 1) << (l - i - 1)), (x >>= 1);
- return rb;
- }),
- (FFTM.prototype.permute = function (rbt, rws, iws, rtws, itws, N) {
- for (var i = 0; i < N; i++) (rtws[i] = rws[rbt[i]]), (itws[i] = iws[rbt[i]]);
- }),
- (FFTM.prototype.transform = function (rws, iws, rtws, itws, N, rbt) {
- this.permute(rbt, rws, iws, rtws, itws, N);
- for (var s = 1; s < N; s <<= 1)
- for (
- var l = s << 1, rtwdf = Math.cos((2 * Math.PI) / l), itwdf = Math.sin((2 * Math.PI) / l), p = 0;
- p < N;
- p += l
- )
- for (var rtwdf_ = rtwdf, itwdf_ = itwdf, j = 0; j < s; j++) {
- var re = rtws[p + j],
- ie = itws[p + j],
- ro = rtws[p + j + s],
- io = itws[p + j + s],
- rx = rtwdf_ * ro - itwdf_ * io;
- (io = rtwdf_ * io + itwdf_ * ro),
- (ro = rx),
- (rtws[p + j] = re + ro),
- (itws[p + j] = ie + io),
- (rtws[p + j + s] = re - ro),
- (itws[p + j + s] = ie - io),
- j !== l &&
- ((rx = rtwdf * rtwdf_ - itwdf * itwdf_), (itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_), (rtwdf_ = rx));
- }
- }),
- (FFTM.prototype.guessLen13b = function (n, m) {
- var N = Math.max(m, n) | 1,
- odd = N & 1,
- i = 0;
- for (N = (N / 2) | 0; N; N = N >>> 1) i++;
- return 1 << (i + 1 + odd);
- }),
- (FFTM.prototype.conjugate = function (rws, iws, N) {
- if (!(N <= 1))
- for (var i = 0; i < N / 2; i++) {
- var t = rws[i];
- (rws[i] = rws[N - i - 1]),
- (rws[N - i - 1] = t),
- (t = iws[i]),
- (iws[i] = -iws[N - i - 1]),
- (iws[N - i - 1] = -t);
- }
- }),
- (FFTM.prototype.normalize13b = function (ws, N) {
- for (var carry = 0, i = 0; i < N / 2; i++) {
- var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry;
- (ws[i] = w & 67108863), w < 67108864 ? (carry = 0) : (carry = (w / 67108864) | 0);
- }
- return ws;
- }),
- (FFTM.prototype.convert13b = function (ws, len, rws, N) {
- for (var carry = 0, i = 0; i < len; i++)
- (carry = carry + (ws[i] | 0)),
- (rws[2 * i] = carry & 8191),
- (carry = carry >>> 13),
- (rws[2 * i + 1] = carry & 8191),
- (carry = carry >>> 13);
- for (i = 2 * len; i < N; ++i) rws[i] = 0;
- assert(carry === 0), assert((carry & -8192) === 0);
- }),
- (FFTM.prototype.stub = function (N) {
- for (var ph = new Array(N), i = 0; i < N; i++) ph[i] = 0;
- return ph;
- }),
- (FFTM.prototype.mulp = function (x, y, out) {
- var N = 2 * this.guessLen13b(x.length, y.length),
- rbt = this.makeRBT(N),
- _ = this.stub(N),
- rws = new Array(N),
- rwst = new Array(N),
- iwst = new Array(N),
- nrws = new Array(N),
- nrwst = new Array(N),
- niwst = new Array(N),
- rmws = out.words;
- (rmws.length = N),
- this.convert13b(x.words, x.length, rws, N),
- this.convert13b(y.words, y.length, nrws, N),
- this.transform(rws, _, rwst, iwst, N, rbt),
- this.transform(nrws, _, nrwst, niwst, N, rbt);
- for (var i = 0; i < N; i++) {
- var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
- (iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]), (rwst[i] = rx);
- }
- return (
- this.conjugate(rwst, iwst, N),
- this.transform(rwst, iwst, rmws, _, N, rbt),
- this.conjugate(rmws, _, N),
- this.normalize13b(rmws, N),
- (out.negative = x.negative ^ y.negative),
- (out.length = x.length + y.length),
- out.strip()
- );
- }),
- (BN.prototype.mul = function (num) {
- var out = new BN(null);
- return (out.words = new Array(this.length + num.length)), this.mulTo(num, out);
- }),
- (BN.prototype.mulf = function (num) {
- var out = new BN(null);
- return (out.words = new Array(this.length + num.length)), jumboMulTo(this, num, out);
- }),
- (BN.prototype.imul = function (num) {
- return this.clone().mulTo(num, this);
- }),
- (BN.prototype.imuln = function (num) {
- assert(typeof num == "number"), assert(num < 67108864);
- for (var carry = 0, i = 0; i < this.length; i++) {
- var w = (this.words[i] | 0) * num,
- lo = (w & 67108863) + (carry & 67108863);
- (carry >>= 26), (carry += (w / 67108864) | 0), (carry += lo >>> 26), (this.words[i] = lo & 67108863);
- }
- return carry !== 0 && ((this.words[i] = carry), this.length++), this;
- }),
- (BN.prototype.muln = function (num) {
- return this.clone().imuln(num);
- }),
- (BN.prototype.sqr = function () {
- return this.mul(this);
- }),
- (BN.prototype.isqr = function () {
- return this.imul(this.clone());
- }),
- (BN.prototype.pow = function (num) {
- var w = toBitArray(num);
- if (w.length === 0) return new BN(1);
- for (var res = this, i = 0; i < w.length && w[i] === 0; i++, res = res.sqr());
- if (++i < w.length) for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) w[i] !== 0 && (res = res.mul(q));
- return res;
- }),
- (BN.prototype.iushln = function (bits) {
- assert(typeof bits == "number" && bits >= 0);
- var r = bits % 26,
- s = (bits - r) / 26,
- carryMask = (67108863 >>> (26 - r)) << (26 - r),
- i;
- if (r !== 0) {
- var carry = 0;
- for (i = 0; i < this.length; i++) {
- var newCarry = this.words[i] & carryMask,
- c = ((this.words[i] | 0) - newCarry) << r;
- (this.words[i] = c | carry), (carry = newCarry >>> (26 - r));
- }
- carry && ((this.words[i] = carry), this.length++);
- }
- if (s !== 0) {
- for (i = this.length - 1; i >= 0; i--) this.words[i + s] = this.words[i];
- for (i = 0; i < s; i++) this.words[i] = 0;
- this.length += s;
- }
- return this.strip();
- }),
- (BN.prototype.ishln = function (bits) {
- return assert(this.negative === 0), this.iushln(bits);
- }),
- (BN.prototype.iushrn = function (bits, hint, extended) {
- assert(typeof bits == "number" && bits >= 0);
- var h;
- hint ? (h = (hint - (hint % 26)) / 26) : (h = 0);
- var r = bits % 26,
- s = Math.min((bits - r) / 26, this.length),
- mask = 67108863 ^ ((67108863 >>> r) << r),
- maskedWords = extended;
- if (((h -= s), (h = Math.max(0, h)), maskedWords)) {
- for (var i = 0; i < s; i++) maskedWords.words[i] = this.words[i];
- maskedWords.length = s;
- }
- if (s !== 0)
- if (this.length > s) for (this.length -= s, i = 0; i < this.length; i++) this.words[i] = this.words[i + s];
- else (this.words[0] = 0), (this.length = 1);
- var carry = 0;
- for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
- var word = this.words[i] | 0;
- (this.words[i] = (carry << (26 - r)) | (word >>> r)), (carry = word & mask);
- }
- return (
- maskedWords && carry !== 0 && (maskedWords.words[maskedWords.length++] = carry),
- this.length === 0 && ((this.words[0] = 0), (this.length = 1)),
- this.strip()
- );
- }),
- (BN.prototype.ishrn = function (bits, hint, extended) {
- return assert(this.negative === 0), this.iushrn(bits, hint, extended);
- }),
- (BN.prototype.shln = function (bits) {
- return this.clone().ishln(bits);
- }),
- (BN.prototype.ushln = function (bits) {
- return this.clone().iushln(bits);
- }),
- (BN.prototype.shrn = function (bits) {
- return this.clone().ishrn(bits);
- }),
- (BN.prototype.ushrn = function (bits) {
- return this.clone().iushrn(bits);
- }),
- (BN.prototype.testn = function (bit) {
- assert(typeof bit == "number" && bit >= 0);
- var r = bit % 26,
- s = (bit - r) / 26,
- q = 1 << r;
- if (this.length <= s) return !1;
- var w = this.words[s];
- return !!(w & q);
- }),
- (BN.prototype.imaskn = function (bits) {
- assert(typeof bits == "number" && bits >= 0);
- var r = bits % 26,
- s = (bits - r) / 26;
- if ((assert(this.negative === 0, "imaskn works only with positive numbers"), this.length <= s)) return this;
- if ((r !== 0 && s++, (this.length = Math.min(s, this.length)), r !== 0)) {
- var mask = 67108863 ^ ((67108863 >>> r) << r);
- this.words[this.length - 1] &= mask;
- }
- return this.strip();
- }),
- (BN.prototype.maskn = function (bits) {
- return this.clone().imaskn(bits);
- }),
- (BN.prototype.iaddn = function (num) {
- return (
- assert(typeof num == "number"),
- assert(num < 67108864),
- num < 0
- ? this.isubn(-num)
- : this.negative !== 0
- ? this.length === 1 && (this.words[0] | 0) < num
- ? ((this.words[0] = num - (this.words[0] | 0)), (this.negative = 0), this)
- : ((this.negative = 0), this.isubn(num), (this.negative = 1), this)
- : this._iaddn(num)
- );
- }),
- (BN.prototype._iaddn = function (num) {
- this.words[0] += num;
- for (var i = 0; i < this.length && this.words[i] >= 67108864; i++)
- (this.words[i] -= 67108864), i === this.length - 1 ? (this.words[i + 1] = 1) : this.words[i + 1]++;
- return (this.length = Math.max(this.length, i + 1)), this;
- }),
- (BN.prototype.isubn = function (num) {
- if ((assert(typeof num == "number"), assert(num < 67108864), num < 0)) return this.iaddn(-num);
- if (this.negative !== 0) return (this.negative = 0), this.iaddn(num), (this.negative = 1), this;
- if (((this.words[0] -= num), this.length === 1 && this.words[0] < 0))
- (this.words[0] = -this.words[0]), (this.negative = 1);
- else
- for (var i = 0; i < this.length && this.words[i] < 0; i++)
- (this.words[i] += 67108864), (this.words[i + 1] -= 1);
- return this.strip();
- }),
- (BN.prototype.addn = function (num) {
- return this.clone().iaddn(num);
- }),
- (BN.prototype.subn = function (num) {
- return this.clone().isubn(num);
- }),
- (BN.prototype.iabs = function () {
- return (this.negative = 0), this;
- }),
- (BN.prototype.abs = function () {
- return this.clone().iabs();
- }),
- (BN.prototype._ishlnsubmul = function (num, mul, shift) {
- var len = num.length + shift,
- i;
- this._expand(len);
- var w,
- carry = 0;
- for (i = 0; i < num.length; i++) {
- w = (this.words[i + shift] | 0) + carry;
- var right = (num.words[i] | 0) * mul;
- (w -= right & 67108863),
- (carry = (w >> 26) - ((right / 67108864) | 0)),
- (this.words[i + shift] = w & 67108863);
- }
- for (; i < this.length - shift; i++)
- (w = (this.words[i + shift] | 0) + carry), (carry = w >> 26), (this.words[i + shift] = w & 67108863);
- if (carry === 0) return this.strip();
- for (assert(carry === -1), carry = 0, i = 0; i < this.length; i++)
- (w = -(this.words[i] | 0) + carry), (carry = w >> 26), (this.words[i] = w & 67108863);
- return (this.negative = 1), this.strip();
- }),
- (BN.prototype._wordDiv = function (num, mode) {
- var shift = this.length - num.length,
- a = this.clone(),
- b = num,
- bhi = b.words[b.length - 1] | 0,
- bhiBits = this._countBits(bhi);
- (shift = 26 - bhiBits),
- shift !== 0 && ((b = b.ushln(shift)), a.iushln(shift), (bhi = b.words[b.length - 1] | 0));
- var m = a.length - b.length,
- q;
- if (mode !== "mod") {
- (q = new BN(null)), (q.length = m + 1), (q.words = new Array(q.length));
- for (var i = 0; i < q.length; i++) q.words[i] = 0;
- }
- var diff = a.clone()._ishlnsubmul(b, 1, m);
- diff.negative === 0 && ((a = diff), q && (q.words[m] = 1));
- for (var j = m - 1; j >= 0; j--) {
- var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0);
- for (qj = Math.min((qj / bhi) | 0, 67108863), a._ishlnsubmul(b, qj, j); a.negative !== 0; )
- qj--, (a.negative = 0), a._ishlnsubmul(b, 1, j), a.isZero() || (a.negative ^= 1);
- q && (q.words[j] = qj);
- }
- return (
- q && q.strip(),
- a.strip(),
- mode !== "div" && shift !== 0 && a.iushrn(shift),
- {
- div: q || null,
- mod: a,
- }
- );
- }),
- (BN.prototype.divmod = function (num, mode, positive) {
- if ((assert(!num.isZero()), this.isZero()))
- return {
- div: new BN(0),
- mod: new BN(0),
- };
- var div, mod, res;
- return this.negative !== 0 && num.negative === 0
- ? ((res = this.neg().divmod(num, mode)),
- mode !== "mod" && (div = res.div.neg()),
- mode !== "div" && ((mod = res.mod.neg()), positive && mod.negative !== 0 && mod.iadd(num)),
- {
- div,
- mod,
- })
- : this.negative === 0 && num.negative !== 0
- ? ((res = this.divmod(num.neg(), mode)),
- mode !== "mod" && (div = res.div.neg()),
- {
- div,
- mod: res.mod,
- })
- : (this.negative & num.negative) !== 0
- ? ((res = this.neg().divmod(num.neg(), mode)),
- mode !== "div" && ((mod = res.mod.neg()), positive && mod.negative !== 0 && mod.isub(num)),
- {
- div: res.div,
- mod,
- })
- : num.length > this.length || this.cmp(num) < 0
- ? {
- div: new BN(0),
- mod: this,
- }
- : num.length === 1
- ? mode === "div"
- ? {
- div: this.divn(num.words[0]),
- mod: null,
- }
- : mode === "mod"
- ? {
- div: null,
- mod: new BN(this.modn(num.words[0])),
- }
- : {
- div: this.divn(num.words[0]),
- mod: new BN(this.modn(num.words[0])),
- }
- : this._wordDiv(num, mode);
- }),
- (BN.prototype.div = function (num) {
- return this.divmod(num, "div", !1).div;
- }),
- (BN.prototype.mod = function (num) {
- return this.divmod(num, "mod", !1).mod;
- }),
- (BN.prototype.umod = function (num) {
- return this.divmod(num, "mod", !0).mod;
- }),
- (BN.prototype.divRound = function (num) {
- var dm = this.divmod(num);
- if (dm.mod.isZero()) return dm.div;
- var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod,
- half = num.ushrn(1),
- r2 = num.andln(1),
- cmp = mod.cmp(half);
- return cmp < 0 || (r2 === 1 && cmp === 0)
- ? dm.div
- : dm.div.negative !== 0
- ? dm.div.isubn(1)
- : dm.div.iaddn(1);
- }),
- (BN.prototype.modn = function (num) {
- assert(num <= 67108863);
- for (var p = (1 << 26) % num, acc = 0, i = this.length - 1; i >= 0; i--)
- acc = (p * acc + (this.words[i] | 0)) % num;
- return acc;
- }),
- (BN.prototype.idivn = function (num) {
- assert(num <= 67108863);
- for (var carry = 0, i = this.length - 1; i >= 0; i--) {
- var w = (this.words[i] | 0) + carry * 67108864;
- (this.words[i] = (w / num) | 0), (carry = w % num);
- }
- return this.strip();
- }),
- (BN.prototype.divn = function (num) {
- return this.clone().idivn(num);
- }),
- (BN.prototype.egcd = function (p) {
- assert(p.negative === 0), assert(!p.isZero());
- var x = this,
- y = p.clone();
- x.negative !== 0 ? (x = x.umod(p)) : (x = x.clone());
- for (var A = new BN(1), B = new BN(0), C = new BN(0), D = new BN(1), g = 0; x.isEven() && y.isEven(); )
- x.iushrn(1), y.iushrn(1), ++g;
- for (var yp = y.clone(), xp = x.clone(); !x.isZero(); ) {
- for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
- if (i > 0)
- for (x.iushrn(i); i-- > 0; )
- (A.isOdd() || B.isOdd()) && (A.iadd(yp), B.isub(xp)), A.iushrn(1), B.iushrn(1);
- for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
- if (j > 0)
- for (y.iushrn(j); j-- > 0; )
- (C.isOdd() || D.isOdd()) && (C.iadd(yp), D.isub(xp)), C.iushrn(1), D.iushrn(1);
- x.cmp(y) >= 0 ? (x.isub(y), A.isub(C), B.isub(D)) : (y.isub(x), C.isub(A), D.isub(B));
- }
- return {
- a: C,
- b: D,
- gcd: y.iushln(g),
- };
- }),
- (BN.prototype._invmp = function (p) {
- assert(p.negative === 0), assert(!p.isZero());
- var a = this,
- b = p.clone();
- a.negative !== 0 ? (a = a.umod(p)) : (a = a.clone());
- for (var x1 = new BN(1), x2 = new BN(0), delta = b.clone(); a.cmpn(1) > 0 && b.cmpn(1) > 0; ) {
- for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
- if (i > 0) for (a.iushrn(i); i-- > 0; ) x1.isOdd() && x1.iadd(delta), x1.iushrn(1);
- for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
- if (j > 0) for (b.iushrn(j); j-- > 0; ) x2.isOdd() && x2.iadd(delta), x2.iushrn(1);
- a.cmp(b) >= 0 ? (a.isub(b), x1.isub(x2)) : (b.isub(a), x2.isub(x1));
- }
- var res;
- return a.cmpn(1) === 0 ? (res = x1) : (res = x2), res.cmpn(0) < 0 && res.iadd(p), res;
- }),
- (BN.prototype.gcd = function (num) {
- if (this.isZero()) return num.abs();
- if (num.isZero()) return this.abs();
- var a = this.clone(),
- b = num.clone();
- (a.negative = 0), (b.negative = 0);
- for (var shift = 0; a.isEven() && b.isEven(); shift++) a.iushrn(1), b.iushrn(1);
- do {
- for (; a.isEven(); ) a.iushrn(1);
- for (; b.isEven(); ) b.iushrn(1);
- var r = a.cmp(b);
- if (r < 0) {
- var t = a;
- (a = b), (b = t);
- } else if (r === 0 || b.cmpn(1) === 0) break;
- a.isub(b);
- } while (!0);
- return b.iushln(shift);
- }),
- (BN.prototype.invm = function (num) {
- return this.egcd(num).a.umod(num);
- }),
- (BN.prototype.isEven = function () {
- return (this.words[0] & 1) === 0;
- }),
- (BN.prototype.isOdd = function () {
- return (this.words[0] & 1) === 1;
- }),
- (BN.prototype.andln = function (num) {
- return this.words[0] & num;
- }),
- (BN.prototype.bincn = function (bit) {
- assert(typeof bit == "number");
- var r = bit % 26,
- s = (bit - r) / 26,
- q = 1 << r;
- if (this.length <= s) return this._expand(s + 1), (this.words[s] |= q), this;
- for (var carry = q, i = s; carry !== 0 && i < this.length; i++) {
- var w = this.words[i] | 0;
- (w += carry), (carry = w >>> 26), (w &= 67108863), (this.words[i] = w);
- }
- return carry !== 0 && ((this.words[i] = carry), this.length++), this;
- }),
- (BN.prototype.isZero = function () {
- return this.length === 1 && this.words[0] === 0;
- }),
- (BN.prototype.cmpn = function (num) {
- var negative = num < 0;
- if (this.negative !== 0 && !negative) return -1;
- if (this.negative === 0 && negative) return 1;
- this.strip();
- var res;
- if (this.length > 1) res = 1;
- else {
- negative && (num = -num), assert(num <= 67108863, "Number is too big");
- var w = this.words[0] | 0;
- res = w === num ? 0 : w < num ? -1 : 1;
- }
- return this.negative !== 0 ? -res | 0 : res;
- }),
- (BN.prototype.cmp = function (num) {
- if (this.negative !== 0 && num.negative === 0) return -1;
- if (this.negative === 0 && num.negative !== 0) return 1;
- var res = this.ucmp(num);
- return this.negative !== 0 ? -res | 0 : res;
- }),
- (BN.prototype.ucmp = function (num) {
- if (this.length > num.length) return 1;
- if (this.length < num.length) return -1;
- for (var res = 0, i = this.length - 1; i >= 0; i--) {
- var a = this.words[i] | 0,
- b = num.words[i] | 0;
- if (a !== b) {
- a < b ? (res = -1) : a > b && (res = 1);
- break;
- }
- }
- return res;
- }),
- (BN.prototype.gtn = function (num) {
- return this.cmpn(num) === 1;
- }),
- (BN.prototype.gt = function (num) {
- return this.cmp(num) === 1;
- }),
- (BN.prototype.gten = function (num) {
- return this.cmpn(num) >= 0;
- }),
- (BN.prototype.gte = function (num) {
- return this.cmp(num) >= 0;
- }),
- (BN.prototype.ltn = function (num) {
- return this.cmpn(num) === -1;
- }),
- (BN.prototype.lt = function (num) {
- return this.cmp(num) === -1;
- }),
- (BN.prototype.lten = function (num) {
- return this.cmpn(num) <= 0;
- }),
- (BN.prototype.lte = function (num) {
- return this.cmp(num) <= 0;
- }),
- (BN.prototype.eqn = function (num) {
- return this.cmpn(num) === 0;
- }),
- (BN.prototype.eq = function (num) {
- return this.cmp(num) === 0;
- }),
- (BN.red = function (num) {
- return new Red(num);
- }),
- (BN.prototype.toRed = function (ctx) {
- return (
- assert(!this.red, "Already a number in reduction context"),
- assert(this.negative === 0, "red works only with positives"),
- ctx.convertTo(this)._forceRed(ctx)
- );
- }),
- (BN.prototype.fromRed = function () {
- return assert(this.red, "fromRed works only with numbers in reduction context"), this.red.convertFrom(this);
- }),
- (BN.prototype._forceRed = function (ctx) {
- return (this.red = ctx), this;
- }),
- (BN.prototype.forceRed = function (ctx) {
- return assert(!this.red, "Already a number in reduction context"), this._forceRed(ctx);
- }),
- (BN.prototype.redAdd = function (num) {
- return assert(this.red, "redAdd works only with red numbers"), this.red.add(this, num);
- }),
- (BN.prototype.redIAdd = function (num) {
- return assert(this.red, "redIAdd works only with red numbers"), this.red.iadd(this, num);
- }),
- (BN.prototype.redSub = function (num) {
- return assert(this.red, "redSub works only with red numbers"), this.red.sub(this, num);
- }),
- (BN.prototype.redISub = function (num) {
- return assert(this.red, "redISub works only with red numbers"), this.red.isub(this, num);
- }),
- (BN.prototype.redShl = function (num) {
- return assert(this.red, "redShl works only with red numbers"), this.red.shl(this, num);
- }),
- (BN.prototype.redMul = function (num) {
- return (
- assert(this.red, "redMul works only with red numbers"),
- this.red._verify2(this, num),
- this.red.mul(this, num)
- );
- }),
- (BN.prototype.redIMul = function (num) {
- return (
- assert(this.red, "redMul works only with red numbers"),
- this.red._verify2(this, num),
- this.red.imul(this, num)
- );
- }),
- (BN.prototype.redSqr = function () {
- return assert(this.red, "redSqr works only with red numbers"), this.red._verify1(this), this.red.sqr(this);
- }),
- (BN.prototype.redISqr = function () {
- return assert(this.red, "redISqr works only with red numbers"), this.red._verify1(this), this.red.isqr(this);
- }),
- (BN.prototype.redSqrt = function () {
- return assert(this.red, "redSqrt works only with red numbers"), this.red._verify1(this), this.red.sqrt(this);
- }),
- (BN.prototype.redInvm = function () {
- return assert(this.red, "redInvm works only with red numbers"), this.red._verify1(this), this.red.invm(this);
- }),
- (BN.prototype.redNeg = function () {
- return assert(this.red, "redNeg works only with red numbers"), this.red._verify1(this), this.red.neg(this);
- }),
- (BN.prototype.redPow = function (num) {
- return assert(this.red && !num.red, "redPow(normalNum)"), this.red._verify1(this), this.red.pow(this, num);
- });
- var primes = {
- k256: null,
- p224: null,
- p192: null,
- p25519: null,
- };
- function MPrime(name, p) {
- (this.name = name),
- (this.p = new BN(p, 16)),
- (this.n = this.p.bitLength()),
- (this.k = new BN(1).iushln(this.n).isub(this.p)),
- (this.tmp = this._tmp());
- }
- (MPrime.prototype._tmp = function () {
- var tmp = new BN(null);
- return (tmp.words = new Array(Math.ceil(this.n / 13))), tmp;
- }),
- (MPrime.prototype.ireduce = function (num) {
- var r = num,
- rlen;
- do this.split(r, this.tmp), (r = this.imulK(r)), (r = r.iadd(this.tmp)), (rlen = r.bitLength());
- while (rlen > this.n);
- var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
- return (
- cmp === 0
- ? ((r.words[0] = 0), (r.length = 1))
- : cmp > 0
- ? r.isub(this.p)
- : r.strip !== void 0
- ? r.strip()
- : r._strip(),
- r
- );
- }),
- (MPrime.prototype.split = function (input, out) {
- input.iushrn(this.n, 0, out);
- }),
- (MPrime.prototype.imulK = function (num) {
- return num.imul(this.k);
- });
- function K256() {
- MPrime.call(this, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f");
- }
- inherits(K256, MPrime),
- (K256.prototype.split = function (input, output) {
- for (var mask = 4194303, outLen = Math.min(input.length, 9), i = 0; i < outLen; i++)
- output.words[i] = input.words[i];
- if (((output.length = outLen), input.length <= 9)) {
- (input.words[0] = 0), (input.length = 1);
- return;
- }
- var prev = input.words[9];
- for (output.words[output.length++] = prev & mask, i = 10; i < input.length; i++) {
- var next = input.words[i] | 0;
- (input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22)), (prev = next);
- }
- (prev >>>= 22),
- (input.words[i - 10] = prev),
- prev === 0 && input.length > 10 ? (input.length -= 10) : (input.length -= 9);
- }),
- (K256.prototype.imulK = function (num) {
- (num.words[num.length] = 0), (num.words[num.length + 1] = 0), (num.length += 2);
- for (var lo = 0, i = 0; i < num.length; i++) {
- var w = num.words[i] | 0;
- (lo += w * 977), (num.words[i] = lo & 67108863), (lo = w * 64 + ((lo / 67108864) | 0));
- }
- return (
- num.words[num.length - 1] === 0 && (num.length--, num.words[num.length - 1] === 0 && num.length--), num
- );
- });
- function P224() {
- MPrime.call(this, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001");
- }
- inherits(P224, MPrime);
- function P192() {
- MPrime.call(this, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff");
- }
- inherits(P192, MPrime);
- function P25519() {
- MPrime.call(this, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed");
- }
- inherits(P25519, MPrime),
- (P25519.prototype.imulK = function (num) {
- for (var carry = 0, i = 0; i < num.length; i++) {
- var hi = (num.words[i] | 0) * 19 + carry,
- lo = hi & 67108863;
- (hi >>>= 26), (num.words[i] = lo), (carry = hi);
- }
- return carry !== 0 && (num.words[num.length++] = carry), num;
- }),
- (BN._prime = function (name) {
- if (primes[name]) return primes[name];
- var prime2;
- if (name === "k256") prime2 = new K256();
- else if (name === "p224") prime2 = new P224();
- else if (name === "p192") prime2 = new P192();
- else if (name === "p25519") prime2 = new P25519();
- else throw new Error("Unknown prime " + name);
- return (primes[name] = prime2), prime2;
- });
- function Red(m) {
- if (typeof m == "string") {
- var prime = BN._prime(m);
- (this.m = prime.p), (this.prime = prime);
- } else assert(m.gtn(1), "modulus must be greater than 1"), (this.m = m), (this.prime = null);
- }
- (Red.prototype._verify1 = function (a) {
- assert(a.negative === 0, "red works only with positives"), assert(a.red, "red works only with red numbers");
- }),
- (Red.prototype._verify2 = function (a, b) {
- assert((a.negative | b.negative) === 0, "red works only with positives"),
- assert(a.red && a.red === b.red, "red works only with red numbers");
- }),
- (Red.prototype.imod = function (a) {
- return this.prime ? this.prime.ireduce(a)._forceRed(this) : a.umod(this.m)._forceRed(this);
- }),
- (Red.prototype.neg = function (a) {
- return a.isZero() ? a.clone() : this.m.sub(a)._forceRed(this);
- }),
- (Red.prototype.add = function (a, b) {
- this._verify2(a, b);
- var res = a.add(b);
- return res.cmp(this.m) >= 0 && res.isub(this.m), res._forceRed(this);
- }),
- (Red.prototype.iadd = function (a, b) {
- this._verify2(a, b);
- var res = a.iadd(b);
- return res.cmp(this.m) >= 0 && res.isub(this.m), res;
- }),
- (Red.prototype.sub = function (a, b) {
- this._verify2(a, b);
- var res = a.sub(b);
- return res.cmpn(0) < 0 && res.iadd(this.m), res._forceRed(this);
- }),
- (Red.prototype.isub = function (a, b) {
- this._verify2(a, b);
- var res = a.isub(b);
- return res.cmpn(0) < 0 && res.iadd(this.m), res;
- }),
- (Red.prototype.shl = function (a, num) {
- return this._verify1(a), this.imod(a.ushln(num));
- }),
- (Red.prototype.imul = function (a, b) {
- return this._verify2(a, b), this.imod(a.imul(b));
- }),
- (Red.prototype.mul = function (a, b) {
- return this._verify2(a, b), this.imod(a.mul(b));
- }),
- (Red.prototype.isqr = function (a) {
- return this.imul(a, a.clone());
- }),
- (Red.prototype.sqr = function (a) {
- return this.mul(a, a);
- }),
- (Red.prototype.sqrt = function (a) {
- if (a.isZero()) return a.clone();
- var mod3 = this.m.andln(3);
- if ((assert(mod3 % 2 === 1), mod3 === 3)) {
- var pow = this.m.add(new BN(1)).iushrn(2);
- return this.pow(a, pow);
- }
- for (var q = this.m.subn(1), s = 0; !q.isZero() && q.andln(1) === 0; ) s++, q.iushrn(1);
- assert(!q.isZero());
- var one = new BN(1).toRed(this),
- nOne = one.redNeg(),
- lpow = this.m.subn(1).iushrn(1),
- z = this.m.bitLength();
- for (z = new BN(2 * z * z).toRed(this); this.pow(z, lpow).cmp(nOne) !== 0; ) z.redIAdd(nOne);
- for (
- var c = this.pow(z, q), r = this.pow(a, q.addn(1).iushrn(1)), t = this.pow(a, q), m = s;
- t.cmp(one) !== 0;
-
- ) {
- for (var tmp = t, i = 0; tmp.cmp(one) !== 0; i++) tmp = tmp.redSqr();
- assert(i < m);
- var b = this.pow(c, new BN(1).iushln(m - i - 1));
- (r = r.redMul(b)), (c = b.redSqr()), (t = t.redMul(c)), (m = i);
- }
- return r;
- }),
- (Red.prototype.invm = function (a) {
- var inv = a._invmp(this.m);
- return inv.negative !== 0 ? ((inv.negative = 0), this.imod(inv).redNeg()) : this.imod(inv);
- }),
- (Red.prototype.pow = function (a, num) {
- if (num.isZero()) return new BN(1).toRed(this);
- if (num.cmpn(1) === 0) return a.clone();
- var windowSize = 4,
- wnd = new Array(1 << windowSize);
- (wnd[0] = new BN(1).toRed(this)), (wnd[1] = a);
- for (var i = 2; i < wnd.length; i++) wnd[i] = this.mul(wnd[i - 1], a);
- var res = wnd[0],
- current = 0,
- currentLen = 0,
- start = num.bitLength() % 26;
- for (start === 0 && (start = 26), i = num.length - 1; i >= 0; i--) {
- for (var word = num.words[i], j = start - 1; j >= 0; j--) {
- var bit = (word >> j) & 1;
- if ((res !== wnd[0] && (res = this.sqr(res)), bit === 0 && current === 0)) {
- currentLen = 0;
- continue;
- }
- (current <<= 1),
- (current |= bit),
- currentLen++,
- !(currentLen !== windowSize && (i !== 0 || j !== 0)) &&
- ((res = this.mul(res, wnd[current])), (currentLen = 0), (current = 0));
- }
- start = 26;
- }
- return res;
- }),
- (Red.prototype.convertTo = function (num) {
- var r = num.umod(this.m);
- return r === num ? r.clone() : r;
- }),
- (Red.prototype.convertFrom = function (num) {
- var res = num.clone();
- return (res.red = null), res;
- }),
- (BN.mont = function (num) {
- return new Mont(num);
- });
- function Mont(m) {
- Red.call(this, m),
- (this.shift = this.m.bitLength()),
- this.shift % 26 !== 0 && (this.shift += 26 - (this.shift % 26)),
- (this.r = new BN(1).iushln(this.shift)),
- (this.r2 = this.imod(this.r.sqr())),
- (this.rinv = this.r._invmp(this.m)),
- (this.minv = this.rinv.mul(this.r).isubn(1).div(this.m)),
- (this.minv = this.minv.umod(this.r)),
- (this.minv = this.r.sub(this.minv));
- }
- inherits(Mont, Red),
- (Mont.prototype.convertTo = function (num) {
- return this.imod(num.ushln(this.shift));
- }),
- (Mont.prototype.convertFrom = function (num) {
- var r = this.imod(num.mul(this.rinv));
- return (r.red = null), r;
- }),
- (Mont.prototype.imul = function (a, b) {
- if (a.isZero() || b.isZero()) return (a.words[0] = 0), (a.length = 1), a;
- var t = a.imul(b),
- c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),
- u = t.isub(c).iushrn(this.shift),
- res = u;
- return (
- u.cmp(this.m) >= 0 ? (res = u.isub(this.m)) : u.cmpn(0) < 0 && (res = u.iadd(this.m)), res._forceRed(this)
- );
- }),
- (Mont.prototype.mul = function (a, b) {
- if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
- var t = a.mul(b),
- c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),
- u = t.isub(c).iushrn(this.shift),
- res = u;
- return (
- u.cmp(this.m) >= 0 ? (res = u.isub(this.m)) : u.cmpn(0) < 0 && (res = u.iadd(this.m)), res._forceRed(this)
- );
- }),
- (Mont.prototype.invm = function (a) {
- var res = this.imod(a._invmp(this.m).mul(this.r2));
- return res._forceRed(this);
- });
- })(typeof module > "u" || module, exports);
- },
-});
+var require_bn7 = require_bn;
const { CryptoHasher } = globalThis.Bun;
@@ -23768,31 +11806,13 @@ var require_crypto_browserify2 = __commonJS({
`),
);
};
- exports.constants = {
- DH_CHECK_P_NOT_SAFE_PRIME: 2,
- DH_CHECK_P_NOT_PRIME: 1,
- DH_UNABLE_TO_CHECK_GENERATOR: 4,
- DH_NOT_SUITABLE_GENERATOR: 8,
- NPN_ENABLED: 1,
- ALPN_ENABLED: 1,
- RSA_PKCS1_PADDING: 1,
- RSA_SSLV23_PADDING: 2,
- RSA_NO_PADDING: 3,
- RSA_PKCS1_OAEP_PADDING: 4,
- RSA_X931_PADDING: 5,
- RSA_PKCS1_PSS_PADDING: 6,
- POINT_CONVERSION_COMPRESSED: 2,
- POINT_CONVERSION_UNCOMPRESSED: 4,
- POINT_CONVERSION_HYBRID: 6,
- };
+ exports.constants = $processBindingConstants.crypto;
},
});
// crypto.js
-var crypto_exports = {
- ...require_crypto_browserify2(),
- [Symbol.for("CommonJS")]: 0,
-};
+var crypto_exports = require_crypto_browserify2();
+
var DEFAULT_ENCODING = "buffer",
getRandomValues = array => crypto.getRandomValues(array),
randomUUID = () => crypto.randomUUID(),
@@ -23882,58 +11902,5 @@ __export(crypto_exports, {
subtle: () => webcrypto.subtle,
});
-export const {
- randomBytes,
- rng,
- pseudoRandomBytes,
- prng,
- Hash,
- createHash,
- createHmac,
- Hmac,
- getHashes,
- pbkdf2,
- pbkdf2Sync,
- Cipher,
- createCipher,
- Cipheriv,
- createCipheriv,
- Decipher,
- createDecipher,
- Decipheriv,
- createDecipheriv,
- getCiphers,
- listCiphers,
- DiffieHellmanGroup,
- createDiffieHellmanGroup,
- getDiffieHellman,
- createDiffieHellman,
- DiffieHellman,
- createSign,
- Sign,
- createVerify,
- Verify,
- createECDH,
- publicEncrypt,
- privateEncrypt,
- publicDecrypt,
- privateDecrypt,
- randomFill,
- randomFillSync,
- createCredentials,
- constants,
-} = crypto_exports;
-
-export {
- DEFAULT_ENCODING,
- getRandomValues,
- getCurves,
- randomUUID,
- randomInt,
- scrypt,
- scryptSync,
- timingSafeEqual,
- webcrypto,
-};
export default crypto_exports;
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
diff --git a/src/js/node/dgram.ts b/src/js/node/dgram.ts
index ba5a058a3..dd6f2895d 100644
--- a/src/js/node/dgram.ts
+++ b/src/js/node/dgram.ts
@@ -1,6 +1,6 @@
// Hardcoded module "node:dgram"
// This is a stub! None of this is actually implemented yet.
-import { hideFromStack, throwNotImplemented } from "../shared";
+const { hideFromStack, throwNotImplemented } = require("$shared");
function createSocket() {
throwNotImplemented("node:dgram createSocket", 1630);
@@ -14,13 +14,10 @@ function _createSocketHandle() {
throwNotImplemented("node:dgram _createSocketHandle", 1630);
}
-const defaultObject = {
+export default {
createSocket,
Socket,
_createSocketHandle,
- [Symbol.for("CommonJS")]: 0,
};
-export { defaultObject as default, Socket, createSocket, _createSocketHandle };
-
hideFromStack(createSocket, Socket, _createSocketHandle);
diff --git a/src/js/node/diagnostics_channel.js b/src/js/node/diagnostics_channel.ts
index 72eb47d2e..45816bdc4 100644
--- a/src/js/node/diagnostics_channel.js
+++ b/src/js/node/diagnostics_channel.ts
@@ -1,7 +1,7 @@
// Hardcoded module "node:diagnostics_channel"
// This is a stub! None of this is actually implemented yet.
-import { hideFromStack, throwNotImplemented } from "../shared";
+const { hideFromStack, throwNotImplemented } = require("$shared");
class Channel {
constructor(name) {
@@ -24,15 +24,12 @@ function unsubscribe() {
throwNotImplemented("node:diagnostics_channel", 2688);
}
-const defaultObject = {
+export default {
channel,
hasSubscribers,
subscribe,
unsubscribe,
Channel,
- [Symbol.for("CommonJS")]: 0,
};
-export { defaultObject as default, Channel, channel, hasSubscribers, subscribe, unsubscribe };
-
hideFromStack([channel, hasSubscribers, subscribe, unsubscribe, Channel]);
diff --git a/src/js/node/dns.js b/src/js/node/dns.js
index 17621f1a5..ef28b0e3b 100644
--- a/src/js/node/dns.js
+++ b/src/js/node/dns.js
@@ -1,7 +1,6 @@
// Hardcoded module "node:dns"
// only resolve4, resolve, lookup, resolve6 and resolveSrv are implemented.
-
-const { dns } = globalThis.Bun;
+const dns = Bun.dns;
function lookup(domain, options, callback) {
if (typeof options == "function") {
@@ -432,10 +431,11 @@ function resolve(hostname, rrtype, callback) {
function Resolver(options) {
return new InternalResolver(options);
}
+Resolver.prototype = {};
Object.setPrototypeOf(Resolver.prototype, InternalResolver.prototype);
Object.setPrototypeOf(Resolver, InternalResolver);
-export var {
+var {
resolve,
resolve4,
resolve6,
@@ -478,7 +478,7 @@ const promisifyResolveX = res => {
};
// promisified versions
-export const promises = {
+const promises = {
lookup(domain, options) {
if (options?.all) {
return dns.lookup(domain, options).then(promisifyLookupAll);
@@ -633,7 +633,7 @@ for (const key of ["resolveAny", "reverse"]) {
promises[key] = () => Promise.resolve(undefined);
}
-const exports = {
+export default {
// these are wrong
ADDRCONFIG: 0,
ALL: 1,
@@ -685,36 +685,4 @@ const exports = {
resolveTxt,
resolveNaptr,
promises,
- [Symbol.for("CommonJS")]: 0,
};
-export default exports;
-export const {
- ADDRCONFIG,
- ALL,
- V4MAPPED,
- NODATA,
- FORMERR,
- SERVFAIL,
- NOTFOUND,
- NOTIMP,
- REFUSED,
- BADQUERY,
- BADNAME,
- BADFAMILY,
- BADRESP,
- CONNREFUSED,
- TIMEOUT,
- EOF,
- FILE,
- NOMEM,
- DESTRUCTION,
- BADSTR,
- BADFLAGS,
- NONAME,
- BADHINTS,
- NOTINITIALIZED,
- LOADIPHLPAPI,
- ADDRGETNETWORKPARAMS,
- CANCELLED,
-} = exports;
-export { lookup, lookupService, Resolver, setServers, setDefaultResultOrder };
diff --git a/src/js/node/dns.promises.js b/src/js/node/dns.promises.js
deleted file mode 100644
index bcc47faee..000000000
--- a/src/js/node/dns.promises.js
+++ /dev/null
@@ -1,47 +0,0 @@
-// Hardcoded module "node:dns/promises"
-import { promises } from "node:dns";
-
-export const {
- lookup,
- lookupService,
- resolve,
- resolve4,
- resolve6,
- resolveAny,
- resolveCname,
- resolveCaa,
- resolveMx,
- resolveNaptr,
- resolveNs,
- resolvePtr,
- resolveSoa,
- resolveSrv,
- resolveTxt,
- reverse,
- Resolver,
- setServers,
- setDefaultResultOrder,
-} = promises;
-
-export default {
- lookup,
- lookupService,
- resolve,
- resolve4,
- resolve6,
- resolveAny,
- resolveCname,
- resolveCaa,
- resolveMx,
- resolveNaptr,
- resolveNs,
- resolvePtr,
- resolveSoa,
- resolveSrv,
- resolveTxt,
- reverse,
- Resolver,
- setServers,
- setDefaultResultOrder,
- [Symbol.for("CommonJS")]: 0,
-};
diff --git a/src/js/node/dns.promises.ts b/src/js/node/dns.promises.ts
new file mode 100644
index 000000000..e0bfbc123
--- /dev/null
+++ b/src/js/node/dns.promises.ts
@@ -0,0 +1,2 @@
+// Hardcoded module "node:dns/promises"
+export default require("node:dns").promises;
diff --git a/src/js/node/domain.ts b/src/js/node/domain.ts
new file mode 100644
index 000000000..b03367ff4
--- /dev/null
+++ b/src/js/node/domain.ts
@@ -0,0 +1,60 @@
+// Import Events
+var EventEmitter = require("node:events");
+
+// Export Domain
+var domain: any = {};
+domain.createDomain = domain.create = function () {
+ var d = new EventEmitter();
+
+ function emitError(e) {
+ d.emit("error", e);
+ }
+
+ d.add = function (emitter) {
+ emitter.on("error", emitError);
+ };
+ d.remove = function (emitter) {
+ emitter.removeListener("error", emitError);
+ };
+ d.bind = function (fn) {
+ return function () {
+ var args = Array.prototype.slice.call(arguments);
+ try {
+ fn.apply(null, args);
+ } catch (err) {
+ emitError(err);
+ }
+ };
+ };
+ d.intercept = function (fn) {
+ return function (err) {
+ if (err) {
+ emitError(err);
+ } else {
+ var args = Array.prototype.slice.call(arguments, 1);
+ try {
+ fn.apply(null, args);
+ } catch (err) {
+ emitError(err);
+ }
+ }
+ };
+ };
+ d.run = function (fn) {
+ try {
+ fn();
+ } catch (err) {
+ emitError(err);
+ }
+ return this;
+ };
+ d.dispose = function () {
+ this.removeAllListeners();
+ return this;
+ };
+ d.enter = d.exit = function () {
+ return this;
+ };
+ return d;
+};
+export default domain;
diff --git a/src/js/node/events.js b/src/js/node/events.js
index 09f89084a..da7cfd57c 100644
--- a/src/js/node/events.js
+++ b/src/js/node/events.js
@@ -1,10 +1,8 @@
// Reimplementation of https://nodejs.org/api/events.html
// Reference: https://github.com/nodejs/node/blob/main/lib/events.js
-import { throwNotImplemented } from "../shared";
+const { throwNotImplemented } = require("$shared");
-var { isPromise, Array, Object } = $lazy("primordials");
const SymbolFor = Symbol.for;
-const ObjectDefineProperty = Object.defineProperty;
const kCapture = Symbol("kCapture");
const kErrorMonitor = SymbolFor("events.errorMonitor");
const kMaxEventTargetListeners = Symbol("events.maxEventTargetListeners");
@@ -17,7 +15,7 @@ const ArrayPrototypeSlice = Array.prototype.slice;
var defaultMaxListeners = 10;
// EventEmitter must be a standard function because some old code will do weird tricks like `EventEmitter.apply(this)`.
-function EventEmitter(opts) {
+const EventEmitter = function EventEmitter(opts) {
if (this._events === undefined || this._events === this.__proto__._events) {
this._events = { __proto__: null };
this._eventsCount = 0;
@@ -27,8 +25,9 @@ function EventEmitter(opts) {
if ((this[kCapture] = opts?.captureRejections ? Boolean(opts?.captureRejections) : EventEmitterPrototype[kCapture])) {
this.emit = emitWithRejectionCapture;
}
-}
-const EventEmitterPrototype = EventEmitter.prototype;
+};
+const EventEmitterPrototype = (EventEmitter.prototype = {});
+
EventEmitterPrototype._events = undefined;
EventEmitterPrototype._eventsCount = 0;
EventEmitterPrototype._maxListeners = undefined;
@@ -108,7 +107,7 @@ const emitWithRejectionCapture = function emit(type, ...args) {
if (handlers === undefined) return false;
for (var handler of [...handlers]) {
var result = handler.apply(this, args);
- if (result !== undefined && isPromise(result)) {
+ if (result !== undefined && $isPromise(result)) {
addCatch(this, result, type, args);
}
}
@@ -308,13 +307,11 @@ function once(emitter, type, options) {
}
});
}
-EventEmitter.once = once;
function on(emitter, type, options) {
var { signal, close, highWatermark = Number.MAX_SAFE_INTEGER, lowWatermark = 1 } = options || {};
throwNotImplemented("events.on", 2679);
}
-EventEmitter.on = on;
function getEventListeners(emitter, type) {
if (emitter instanceof EventTarget) {
@@ -322,7 +319,6 @@ function getEventListeners(emitter, type) {
}
return emitter.listeners(type);
}
-EventEmitter.getEventListeners = getEventListeners;
function setMaxListeners(n, ...eventTargets) {
validateNumber(n, "setMaxListeners", 0);
@@ -335,57 +331,10 @@ function setMaxListeners(n, ...eventTargets) {
defaultMaxListeners = n;
}
}
-EventEmitter.setMaxListeners = setMaxListeners;
function listenerCount(emitter, type) {
return emitter.listenerCount(type);
}
-EventEmitter.listenerCount = listenerCount;
-
-EventEmitter.EventEmitter = EventEmitter;
-EventEmitter.usingDomains = false;
-EventEmitter.captureRejectionSymbol = captureRejectionSymbol;
-ObjectDefineProperty(EventEmitter, "captureRejections", {
- __proto__: null,
- get() {
- return EventEmitterPrototype[kCapture];
- },
- set(value) {
- validateBoolean(value, "EventEmitter.captureRejections");
-
- EventEmitterPrototype[kCapture] = value;
- },
- enumerable: true,
-});
-EventEmitter.errorMonitor = kErrorMonitor;
-Object.defineProperties(EventEmitter, {
- defaultMaxListeners: {
- enumerable: true,
- get: () => {
- return defaultMaxListeners;
- },
- set: arg => {
- validateNumber(arg, "defaultMaxListeners", 0);
- defaultMaxListeners = arg;
- },
- },
- kMaxEventTargetListeners: {
- __proto__: null,
- value: kMaxEventTargetListeners,
- enumerable: false,
- configurable: false,
- writable: false,
- },
- kMaxEventTargetListenersWarned: {
- __proto__: null,
- value: kMaxEventTargetListenersWarned,
- enumerable: false,
- configurable: false,
- writable: false,
- },
-});
-EventEmitter.init = EventEmitter;
-EventEmitter[Symbol.for("CommonJS")] = 0;
function eventTargetAgnosticRemoveListener(emitter, name, listener, flags) {
if (typeof emitter.removeListener === "function") {
@@ -460,7 +409,9 @@ class EventEmitterAsyncResource extends EventEmitter {
asyncResource;
constructor(options) {
- if (!AsyncResource) AsyncResource = import.meta.require("async_hooks").AsyncResource;
+ if (!AsyncResource) {
+ AsyncResource = require("node:async_hooks").AsyncResource;
+ }
var { captureRejections = false, triggerAsyncId, name = new.target.name, requireManualDestroy } = options || {};
super({ captureRejections });
this.triggerAsyncId = triggerAsyncId ?? 0;
@@ -476,19 +427,55 @@ class EventEmitterAsyncResource extends EventEmitter {
}
}
-const usingDomains = false;
-// EventEmitter[Symbol.for("CommonJS")] = 0;
-Object.assign(EventEmitter, { once, on, getEventListeners, setMaxListeners, listenerCount, EventEmitterAsyncResource });
-export {
- EventEmitter,
- captureRejectionSymbol,
- kErrorMonitor as errorMonitor,
- getEventListeners,
- listenerCount,
- on,
+Object.defineProperties(EventEmitter, {
+ captureRejections: {
+ get() {
+ return EventEmitterPrototype[kCapture];
+ },
+ set(value) {
+ validateBoolean(value, "EventEmitter.captureRejections");
+
+ EventEmitterPrototype[kCapture] = value;
+ },
+ enumerable: true,
+ },
+ defaultMaxListeners: {
+ enumerable: true,
+ get: () => {
+ return defaultMaxListeners;
+ },
+ set: arg => {
+ validateNumber(arg, "defaultMaxListeners", 0);
+ defaultMaxListeners = arg;
+ },
+ },
+ kMaxEventTargetListeners: {
+ value: kMaxEventTargetListeners,
+ enumerable: false,
+ configurable: false,
+ writable: false,
+ },
+ kMaxEventTargetListenersWarned: {
+ value: kMaxEventTargetListenersWarned,
+ enumerable: false,
+ configurable: false,
+ writable: false,
+ },
+});
+Object.assign(EventEmitter, {
once,
+ on,
+ getEventListeners,
+ // getMaxListeners,
setMaxListeners,
- usingDomains,
+ EventEmitter,
+ usingDomains: false,
+ captureRejectionSymbol,
EventEmitterAsyncResource,
-};
+ errorMonitor: kErrorMonitor,
+ setMaxListeners,
+ init: EventEmitter,
+ listenerCount,
+});
+
export default EventEmitter;
diff --git a/src/js/node/fs.js b/src/js/node/fs.js
index d287809c6..27f1a7b4c 100644
--- a/src/js/node/fs.js
+++ b/src/js/node/fs.js
@@ -1,17 +1,11 @@
-export var ReadStream;
-export var WriteStream;
-
-import { EventEmitter } from "node:events";
-
// Hardcoded module "node:fs"
-var { direct, isPromise, isCallable } = $lazy("primordials");
-import promises from "node:fs/promises";
-export { default as promises } from "node:fs/promises";
-import * as Stream from "node:stream";
+var ReadStream;
+var WriteStream;
+const EventEmitter = require("node:events");
+const promises = require("node:fs/promises");
+const Stream = require("node:stream");
var fs = Bun.fs();
-var debug = process.env.DEBUG ? console.log : () => {};
-
class FSWatcher extends EventEmitter {
#watcher;
#listener;
@@ -68,7 +62,8 @@ class FSWatcher extends EventEmitter {
this.#watcher?.unref();
}
}
-export var access = function access(...args) {
+
+var access = function access(...args) {
callbackify(fs.accessSync, args);
},
appendFile = function appendFile(...args) {
@@ -350,18 +345,15 @@ ReadStream = (function (InternalReadStream) {
value: "ReadStream",
enumerable: false,
});
-
- return Object.defineProperty(
- function ReadStream(path, options) {
- return new InternalReadStream(path, options);
- },
- Symbol.hasInstance,
- {
- value(instance) {
- return instance instanceof InternalReadStream;
- },
+ function ReadStream(path, options) {
+ return new InternalReadStream(path, options);
+ }
+ ReadStream.prototype = InternalReadStream.prototype;
+ return Object.defineProperty(ReadStream, Symbol.hasInstance, {
+ value(instance) {
+ return instance instanceof InternalReadStream;
},
- );
+ });
})(
class ReadStream extends Stream._getNativeReadableStreamPrototype(2, Stream.Readable) {
constructor(pathOrFd, options = defaultReadStreamOptions) {
@@ -419,9 +411,9 @@ ReadStream = (function (InternalReadStream) {
// Get the stream controller
// We need the pointer to the underlying stream controller for the NativeReadable
var stream = fileRef.stream();
- var native = direct(stream);
+ var native = $direct(stream);
if (!native) {
- debug("no native readable stream");
+ $debug("no native readable stream");
throw new Error("no native readable stream");
}
var { stream: ptr } = native;
@@ -573,7 +565,7 @@ ReadStream = (function (InternalReadStream) {
? Math.min(end - pos + 1, n) // takes smaller of length of the rest of the file to read minus the cursor position, or the highwatermark
: Math.min(end - bytesRead + 1, n); // takes the smaller of the length of the rest of the file from the bytes that we have marked read, or the highwatermark
- debug("n @ fs.ReadStream.#internalRead, after clamp", n);
+ $debug("n @ fs.ReadStream.#internalRead, after clamp", n);
// If n is 0 or less, then we read all the file, push null to stream, ending it
if (n <= 0) {
@@ -593,16 +585,16 @@ ReadStream = (function (InternalReadStream) {
if (this.#fileSize > 0 && n > this.#fileSize) {
n = this.#fileSize + 1;
}
- debug("fileSize", this.#fileSize);
+ $debug("fileSize", this.#fileSize);
}
// At this point, we know the file size and how much we want to read of the file
this[kIoDone] = false;
var res = super._read(n);
- debug("res -- undefined? why?", res);
- if (isPromise(res)) {
+ $debug("res -- undefined? why?", res);
+ if ($isPromise(res)) {
var then = res?.then;
- if (then && isCallable(then)) {
+ if (then && $isCallable(then)) {
then(
() => {
this[kIoDone] = true;
@@ -671,7 +663,7 @@ ReadStream = (function (InternalReadStream) {
},
);
-export function createReadStream(path, options) {
+function createReadStream(path, options) {
return new ReadStream(path, options);
}
@@ -698,17 +690,15 @@ WriteStream = (function (InternalWriteStream) {
enumerable: false,
});
- return Object.defineProperty(
- function WriteStream(path, options) {
- return new InternalWriteStream(path, options);
- },
- Symbol.hasInstance,
- {
- value(instance) {
- return instance instanceof InternalWriteStream;
- },
+ function WriteStream(path, options) {
+ return new InternalWriteStream(path, options);
+ }
+ WriteStream.prototype = InternalWriteStream.prototype;
+ return Object.defineProperty(WriteStream, Symbol.hasInstance, {
+ value(instance) {
+ return instance instanceof InternalWriteStream;
},
- );
+ });
})(
class WriteStream extends Stream.NativeWritable {
constructor(path, options = defaultWriteStreamOptions) {
@@ -993,7 +983,7 @@ WriteStream = (function (InternalWriteStream) {
},
);
-export function createWriteStream(path, options) {
+function createWriteStream(path, options) {
// const WriteStream = getLazyWriteStream();
return new WriteStream(path, options);
}
@@ -1043,7 +1033,6 @@ realpath.native = realpath;
realpathSync.native = realpathSync;
export default {
- [Symbol.for("CommonJS")]: 0,
access,
accessSync,
appendFile,
@@ -1141,5 +1130,3 @@ export default {
// return getLazyReadStream();
// },
};
-
-export { constants } from "node:fs/promises";
diff --git a/src/js/node/fs.promises.ts b/src/js/node/fs.promises.ts
index bdbacd27d..6a1c42ecd 100644
--- a/src/js/node/fs.promises.ts
+++ b/src/js/node/fs.promises.ts
@@ -1,8 +1,5 @@
// Hardcoded module "node:fs/promises"
-
-// Note: `constants` is injected into the top of this file
-declare var constants: typeof import("node:fs/promises").constants;
-const { createFIFO } = $lazy("primordials");
+const constants = $processBindingConstants.fs;
var fs = Bun.fs();
@@ -19,7 +16,7 @@ var promisify = {
},
}[notrace];
-export function watch(
+function watch(
filename: string | Buffer | URL,
options: { encoding?: BufferEncoding; persistent?: boolean; recursive?: boolean; signal?: AbortSignal } = {},
) {
@@ -39,7 +36,7 @@ export function watch(
if (typeof options === "string") {
options = { encoding: options };
}
- const queue = createFIFO();
+ const queue = $createFIFO();
const watcher = fs.watch(filename, options || {}, (eventType: string, filename: string | Buffer | undefined) => {
queue.push({ eventType, filename });
@@ -91,43 +88,45 @@ export function watch(
},
};
}
-export var access = promisify(fs.accessSync),
- appendFile = promisify(fs.appendFileSync),
- close = promisify(fs.closeSync),
- copyFile = promisify(fs.copyFileSync),
- exists = promisify(fs.existsSync),
- chown = promisify(fs.chownSync),
- chmod = promisify(fs.chmodSync),
- fchmod = promisify(fs.fchmodSync),
- fchown = promisify(fs.fchownSync),
- fstat = promisify(fs.fstatSync),
- fsync = promisify(fs.fsyncSync),
- ftruncate = promisify(fs.ftruncateSync),
- futimes = promisify(fs.futimesSync),
- lchmod = promisify(fs.lchmodSync),
- lchown = promisify(fs.lchownSync),
- link = promisify(fs.linkSync),
- lstat = fs.lstat.bind(fs),
- mkdir = promisify(fs.mkdirSync),
- mkdtemp = promisify(fs.mkdtempSync),
- open = promisify(fs.openSync),
- read = promisify(fs.readSync),
- write = promisify(fs.writeSync),
- readdir = fs.readdir.bind(fs),
- readFile = fs.readFile.bind(fs),
- writeFile = promisify(fs.writeFileSync),
- readlink = promisify(fs.readlinkSync),
- realpath = promisify(fs.realpathSync),
- rename = promisify(fs.renameSync),
- stat = fs.stat.bind(fs),
- symlink = promisify(fs.symlinkSync),
- truncate = promisify(fs.truncateSync),
- unlink = promisify(fs.unlinkSync),
- utimes = promisify(fs.utimesSync),
- lutimes = promisify(fs.lutimesSync),
- rm = promisify(fs.rmSync),
- rmdir = promisify(fs.rmdirSync),
- writev = (fd, buffers, position) => {
+
+export default {
+ access: promisify(fs.accessSync),
+ appendFile: promisify(fs.appendFileSync),
+ close: promisify(fs.closeSync),
+ copyFile: promisify(fs.copyFileSync),
+ exists: promisify(fs.existsSync),
+ chown: promisify(fs.chownSync),
+ chmod: promisify(fs.chmodSync),
+ fchmod: promisify(fs.fchmodSync),
+ fchown: promisify(fs.fchownSync),
+ fstat: promisify(fs.fstatSync),
+ fsync: promisify(fs.fsyncSync),
+ ftruncate: promisify(fs.ftruncateSync),
+ futimes: promisify(fs.futimesSync),
+ lchmod: promisify(fs.lchmodSync),
+ lchown: promisify(fs.lchownSync),
+ link: promisify(fs.linkSync),
+ lstat: fs.lstat.bind(fs),
+ mkdir: promisify(fs.mkdirSync),
+ mkdtemp: promisify(fs.mkdtempSync),
+ open: promisify(fs.openSync),
+ read: promisify(fs.readSync),
+ write: promisify(fs.writeSync),
+ readdir: fs.readdir.bind(fs),
+ readFile: fs.readFile.bind(fs),
+ writeFile: promisify(fs.writeFileSync),
+ readlink: promisify(fs.readlinkSync),
+ realpath: promisify(fs.realpathSync),
+ rename: promisify(fs.renameSync),
+ stat: fs.stat.bind(fs),
+ symlink: promisify(fs.symlinkSync),
+ truncate: promisify(fs.truncateSync),
+ unlink: promisify(fs.unlinkSync),
+ utimes: promisify(fs.utimesSync),
+ lutimes: promisify(fs.lutimesSync),
+ rm: promisify(fs.rmSync),
+ rmdir: promisify(fs.rmdirSync),
+ writev: (fd, buffers, position) => {
return new Promise((resolve, reject) => {
try {
var bytesWritten = fs.writevSync(fd, buffers, position);
@@ -142,7 +141,7 @@ export var access = promisify(fs.accessSync),
});
});
},
- readv = (fd, buffers, position) => {
+ readv: (fd, buffers, position) => {
return new Promise((resolve, reject) => {
try {
var bytesRead = fs.readvSync(fd, buffers, position);
@@ -156,48 +155,7 @@ export var access = promisify(fs.accessSync),
buffers,
});
});
- };
-
-export default {
- access,
- appendFile,
- close,
- copyFile,
- exists,
- chown,
- chmod,
- fchmod,
- fchown,
- fstat,
- fsync,
- ftruncate,
- futimes,
- lchmod,
- lchown,
- link,
- lstat,
- mkdir,
- mkdtemp,
- open,
- read,
- write,
- readdir,
- readFile,
- writeFile,
- readlink,
- realpath,
- rename,
- stat,
- symlink,
- truncate,
- unlink,
- utimes,
- lutimes,
- rm,
- rmdir,
- watch,
- writev,
- readv,
+ },
constants,
- [Symbol.for("CommonJS")]: 0,
+ watch,
};
diff --git a/src/js/node/http.ts b/src/js/node/http.ts
index 2eb5231d5..4f7549c17 100644
--- a/src/js/node/http.ts
+++ b/src/js/node/http.ts
@@ -1,7 +1,7 @@
// Hardcoded module "node:http"
-import { EventEmitter } from "node:events";
-import { Readable, Writable, Duplex } from "node:stream";
-import { isTypedArray } from "util/types";
+const EventEmitter = require("node:events");
+const { isTypedArray } = require("node:util/types");
+const { Duplex, Readable, Writable } = require("node:stream");
const headerCharRegex = /[^\t\x20-\x7e\x80-\xff]/;
/**
@@ -14,14 +14,14 @@ function checkInvalidHeaderChar(val: string) {
return RegExpPrototypeExec.call(headerCharRegex, val) !== null;
}
-export const validateHeaderName = (name, label) => {
+const validateHeaderName = (name, label) => {
if (typeof name !== "string" || !name || !checkIsHttpToken(name)) {
// throw new ERR_INVALID_HTTP_TOKEN(label || "Header name", name);
throw new Error("ERR_INVALID_HTTP_TOKEN");
}
};
-export const validateHeaderValue = (name, value) => {
+const validateHeaderValue = (name, value) => {
if (value === undefined) {
// throw new ERR_HTTP_INVALID_HEADER_VALUE(value, name);
throw new Error("ERR_HTTP_INVALID_HEADER_VALUE");
@@ -57,16 +57,11 @@ function isIPv6(input) {
// Importing from node:url is unnecessary
const { URL } = globalThis;
-const { newArrayWithSize, String, Object, Array } = $lazy("primordials");
-
const globalReportError = globalThis.reportError;
const setTimeout = globalThis.setTimeout;
const fetch = Bun.fetch;
const nop = () => {};
-const __DEBUG__ = process.env.__DEBUG__;
-const debug = __DEBUG__ ? (...args) => console.log("node:http", ...args) : nop;
-
const kEmptyObject = Object.freeze(Object.create(null));
const kOutHeaders = Symbol.for("kOutHeaders");
const kEndCalled = Symbol.for("kEndCalled");
@@ -218,11 +213,11 @@ var FakeSocket = class Socket extends Duplex {
_write(chunk, encoding, callback) {}
};
-export function createServer(options, callback) {
+function createServer(options, callback) {
return new Server(options, callback);
}
-export class Agent extends EventEmitter {
+class Agent extends EventEmitter {
defaultPort = 80;
protocol = "http:";
options;
@@ -270,7 +265,7 @@ export class Agent extends EventEmitter {
}
createConnection() {
- debug(`${NODE_HTTP_WARNING}\n`, "WARN: Agent.createConnection is a no-op, returns fake socket");
+ $debug(`${NODE_HTTP_WARNING}\n`, "WARN: Agent.createConnection is a no-op, returns fake socket");
return (this.#fakeSocket ??= new FakeSocket());
}
@@ -287,30 +282,30 @@ export class Agent extends EventEmitter {
}
addRequest() {
- debug(`${NODE_HTTP_WARNING}\n`, "WARN: Agent.addRequest is a no-op");
+ $debug(`${NODE_HTTP_WARNING}\n`, "WARN: Agent.addRequest is a no-op");
}
createSocket(req, options, cb) {
- debug(`${NODE_HTTP_WARNING}\n`, "WARN: Agent.createSocket returns fake socket");
+ $debug(`${NODE_HTTP_WARNING}\n`, "WARN: Agent.createSocket returns fake socket");
cb(null, (this.#fakeSocket ??= new FakeSocket()));
}
removeSocket() {
- debug(`${NODE_HTTP_WARNING}\n`, "WARN: Agent.removeSocket is a no-op");
+ $debug(`${NODE_HTTP_WARNING}\n`, "WARN: Agent.removeSocket is a no-op");
}
keepSocketAlive() {
- debug(`${NODE_HTTP_WARNING}\n`, "WARN: Agent.keepSocketAlive is a no-op");
+ $debug(`${NODE_HTTP_WARNING}\n`, "WARN: Agent.keepSocketAlive is a no-op");
return true;
}
reuseSocket() {
- debug(`${NODE_HTTP_WARNING}\n`, "WARN: Agent.reuseSocket is a no-op");
+ $debug(`${NODE_HTTP_WARNING}\n`, "WARN: Agent.reuseSocket is a no-op");
}
destroy() {
- debug(`${NODE_HTTP_WARNING}\n`, "WARN: Agent.destroy is a no-op");
+ $debug(`${NODE_HTTP_WARNING}\n`, "WARN: Agent.destroy is a no-op");
}
}
function emitListeningNextTick(self, onListen, err, hostname, port) {
@@ -331,7 +326,7 @@ function emitListeningNextTick(self, onListen, err, hostname, port) {
}
}
-export class Server extends EventEmitter {
+class Server extends EventEmitter {
#server;
#options;
#tls;
@@ -558,7 +553,7 @@ export class Server extends EventEmitter {
function assignHeaders(object, req) {
var headers = req.headers.toJSON();
- const rawHeaders = newArrayWithSize(req.headers.count * 2);
+ const rawHeaders = $newArrayWithSize(req.headers.count * 2);
var i = 0;
for (const key in headers) {
rawHeaders[i++] = key;
@@ -577,7 +572,7 @@ function getDefaultHTTPSAgent() {
return (_defaultHTTPSAgent ??= new Agent({ defaultPort: 443, protocol: "https:" }));
}
-export class IncomingMessage extends Readable {
+class IncomingMessage extends Readable {
method: string;
complete: boolean;
@@ -796,7 +791,7 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
}
if (!msg._hasBody) {
- debug("This type of response MUST NOT have a body. " + "Ignoring write() calls.");
+ $debug("This type of response MUST NOT have a body. " + "Ignoring write() calls.");
process.nextTick(callback);
return true;
}
@@ -809,7 +804,7 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
return true;
}
-export class OutgoingMessage extends Writable {
+class OutgoingMessage extends Writable {
#headers;
headersSent = false;
sendDate = true;
@@ -958,7 +953,7 @@ export class OutgoingMessage extends Writable {
}
let OriginalWriteHeadFn, OriginalImplicitHeadFn;
-export class ServerResponse extends Writable {
+class ServerResponse extends Writable {
declare _writableState: any;
constructor({ req, reply }) {
@@ -1196,7 +1191,7 @@ export class ServerResponse extends Writable {
OriginalWriteHeadFn = ServerResponse.prototype.writeHead;
OriginalImplicitHeadFn = ServerResponse.prototype._implicitHeader;
-export class ClientRequest extends OutgoingMessage {
+class ClientRequest extends OutgoingMessage {
#timeout;
#res: IncomingMessage | null = null;
#upgradeOrConnect = false;
@@ -1285,7 +1280,7 @@ export class ClientRequest extends OutgoingMessage {
headers: this.getHeaders(),
body: body && method !== "GET" && method !== "HEAD" && method !== "OPTIONS" ? body : undefined,
redirect: "manual",
- verbose: Boolean(__DEBUG__),
+ verbose: !!$debug,
signal: this[kAbortController].signal,
// Timeouts are handled via this.setTimeout.
@@ -1300,7 +1295,7 @@ export class ClientRequest extends OutgoingMessage {
this.emit("response", res);
})
.catch(err => {
- if (__DEBUG__) globalReportError(err);
+ if (!!$debug) globalReportError(err);
this.emit("error", err);
})
.finally(() => {
@@ -1308,7 +1303,7 @@ export class ClientRequest extends OutgoingMessage {
this[kClearTimeout]();
});
} catch (err) {
- if (__DEBUG__) globalReportError(err);
+ if (!!$debug) globalReportError(err);
this.emit("error", err);
} finally {
callback();
@@ -1388,7 +1383,7 @@ export class ClientRequest extends OutgoingMessage {
if (options.path) {
const path = String(options.path);
if (RegExpPrototypeExec.call(INVALID_PATH_REGEX, path) !== null) {
- debug('Path contains unescaped characters: "%s"', path);
+ $debug('Path contains unescaped characters: "%s"', path);
throw new Error("Path contains unescaped characters");
// throw new ERR_UNESCAPED_CHARACTERS("Request path");
}
@@ -1467,8 +1462,7 @@ export class ClientRequest extends OutgoingMessage {
this.once("response", cb);
}
- __DEBUG__ &&
- debug(`new ClientRequest: ${this.#method} ${this.#protocol}//${this.#host}:${this.#port}${this.#path}`);
+ $debug(`new ClientRequest: ${this.#method} ${this.#protocol}//${this.#host}:${this.#port}${this.#path}`);
// if (
// method === "GET" ||
@@ -1556,12 +1550,13 @@ export class ClientRequest extends OutgoingMessage {
}
setSocketKeepAlive(enable = true, initialDelay = 0) {
- __DEBUG__ && debug(`${NODE_HTTP_WARNING}\n`, "WARN: ClientRequest.setSocketKeepAlive is a no-op");
+ $debug(`${NODE_HTTP_WARNING}\n`, "WARN: ClientRequest.setSocketKeepAlive is a no-op");
}
setNoDelay(noDelay = true) {
- __DEBUG__ && debug(`${NODE_HTTP_WARNING}\n`, "WARN: ClientRequest.setNoDelay is a no-op");
+ $debug(`${NODE_HTTP_WARNING}\n`, "WARN: ClientRequest.setNoDelay is a no-op");
}
+
[kClearTimeout]() {
if (this.#timeoutTimer) {
clearTimeout(this.#timeoutTimer);
@@ -1666,7 +1661,7 @@ function checkIsHttpToken(val) {
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-export const METHODS = [
+const METHODS = [
"ACL",
"BIND",
"CHECKOUT",
@@ -1703,7 +1698,7 @@ export const METHODS = [
"UNSUBSCRIBE",
];
-export const STATUS_CODES = {
+const STATUS_CODES = {
100: "Continue",
101: "Switching Protocols",
102: "Processing",
@@ -1863,7 +1858,7 @@ function _writeHead(statusCode, reason, obj, response) {
* @param {Function} [cb]
* @returns {ClientRequest}
*/
-export function request(url, options, cb) {
+function request(url, options, cb) {
return new ClientRequest(url, options, cb);
}
@@ -1874,14 +1869,14 @@ export function request(url, options, cb) {
* @param {Function} [cb]
* @returns {ClientRequest}
*/
-export function get(url, options, cb) {
+function get(url, options, cb) {
const req = request(url, options, cb);
req.end();
return req;
}
-export var globalAgent = new Agent();
-var defaultObject = {
+var globalAgent = new Agent();
+export default {
Agent,
Server,
METHODS,
@@ -1895,12 +1890,9 @@ var defaultObject = {
validateHeaderName,
validateHeaderValue,
setMaxIdleHTTPParsers(max) {
- debug(`${NODE_HTTP_WARNING}\n`, "setMaxIdleHTTPParsers() is a no-op");
+ $debug(`${NODE_HTTP_WARNING}\n`, "setMaxIdleHTTPParsers() is a no-op");
},
globalAgent,
ClientRequest,
OutgoingMessage,
- [Symbol.for("CommonJS")]: 0,
};
-
-export default defaultObject;
diff --git a/src/js/node/http2.ts b/src/js/node/http2.ts
index b19e38a6d..fce1a8c72 100644
--- a/src/js/node/http2.ts
+++ b/src/js/node/http2.ts
@@ -1,6 +1,6 @@
// Hardcoded module "node:http2"
// This is a stub! None of this is actually implemented yet.
-import { hideFromStack, throwNotImplemented } from "../shared";
+const { hideFromStack, throwNotImplemented } = require("$shared");
function connect() {
throwNotImplemented("node:http2 connect", 887);
@@ -280,7 +280,7 @@ function Http2ServerResponse() {
throwNotImplemented("node:http2 Http2ServerResponse", 887);
}
-const defaultObject = {
+export default {
constants,
createServer,
createSecureServer,
@@ -290,21 +290,6 @@ const defaultObject = {
sensitiveHeaders,
Http2ServerRequest,
Http2ServerResponse,
- [Symbol.for("CommonJS")]: 0,
- connect,
-};
-
-export {
- constants,
- createServer,
- createSecureServer,
- getDefaultSettings,
- getPackedSettings,
- getUnpackedSettings,
- sensitiveHeaders,
- Http2ServerRequest,
- Http2ServerResponse,
- defaultObject as default,
connect,
};
diff --git a/src/js/node/https.ts b/src/js/node/https.ts
index 08eb89a01..d75fb3132 100644
--- a/src/js/node/https.ts
+++ b/src/js/node/https.ts
@@ -1,19 +1,5 @@
// Hardcoded module "node:https"
-import * as http from "node:http";
-
-var {
- Agent,
- Server,
- METHODS,
- STATUS_CODES,
- createServer,
- ServerResponse,
- IncomingMessage,
- maxHeaderSize,
- validateHeaderName,
- validateHeaderValue,
- globalAgent,
-} = http;
+const http = require("node:http");
function request(input, options, cb) {
if (input && typeof input === "object" && !(input instanceof URL)) {
@@ -31,35 +17,8 @@ function get(input, options, cb) {
return req;
}
-var defaultExport = {
- Agent,
- Server,
- METHODS,
- STATUS_CODES,
- createServer,
- ServerResponse,
- IncomingMessage,
- request,
+export default {
+ ...http,
get,
- maxHeaderSize,
- validateHeaderName,
- validateHeaderValue,
- globalAgent,
-};
-
-export {
- Agent,
- Server,
- METHODS,
- STATUS_CODES,
- createServer,
- ServerResponse,
- IncomingMessage,
request,
- get,
- maxHeaderSize,
- validateHeaderName,
- validateHeaderValue,
- globalAgent,
};
-export default defaultExport;
diff --git a/src/js/node/inspector.ts b/src/js/node/inspector.ts
index f81084274..1fd7316f7 100644
--- a/src/js/node/inspector.ts
+++ b/src/js/node/inspector.ts
@@ -1,7 +1,7 @@
// Hardcoded module "node:inspector" and "node:inspector/promises"
// This is a stub! None of this is actually implemented yet.
-import { hideFromStack, throwNotImplemented } from "../shared";
-import EventEmitter from "node:events";
+const { hideFromStack, throwNotImplemented } = require("$shared");
+const EventEmitter = require("node:events");
function open() {
throwNotImplemented("node:inspector open", 2445);
@@ -33,15 +33,13 @@ const console = {
},
};
-var defaultObject = {
+export default {
console,
open,
close,
url,
waitForDebugger,
Session,
- [Symbol.for("CommonJS")]: 0,
};
-export { console, open, close, url, waitForDebugger, Session, defaultObject as default };
hideFromStack(open, close, url, waitForDebugger, Session.prototype.constructor);
diff --git a/src/js/node/net.js b/src/js/node/net.js
index 5501d327b..0513f44d3 100644
--- a/src/js/node/net.js
+++ b/src/js/node/net.js
@@ -19,8 +19,8 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-import { Duplex } from "node:stream";
-import { EventEmitter } from "node:events";
+const { Duplex } = require("node:stream");
+const EventEmitter = require("node:events");
// IPv4 Segment
const v4Seg = "(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
@@ -56,7 +56,6 @@ function isIP(s) {
return 0;
}
-const { Bun, createFIFO, Object } = $lazy("primordials");
const { connect: bunConnect } = Bun;
var { setTimeout } = globalThis;
@@ -294,7 +293,7 @@ const Socket = (function (InternalSocket) {
#closed = false;
connecting = false;
localAddress = "127.0.0.1";
- #readQueue = createFIFO();
+ #readQueue = $createFIFO();
remotePort;
[bunSocketInternal] = null;
[bunTLSConnectOptions] = null;
@@ -891,8 +890,5 @@ export default {
isIPv4,
isIPv6,
Socket,
- [Symbol.for("CommonJS")]: 0,
[Symbol.for("::bunternal::")]: SocketClass,
};
-
-export { createServer, Server, createConnection, connect, isIP, isIPv4, isIPv6, Socket };
diff --git a/src/js/node/os.js b/src/js/node/os.ts
index 40250ef9a..c5b202444 100644
--- a/src/js/node/os.js
+++ b/src/js/node/os.ts
@@ -1,7 +1,6 @@
// Hardcoded module "node:os"
-export var tmpdir = function () {
- var { Bun } = $lazy("primordials");
+var tmpdir = function () {
var env = Bun.env;
tmpdir = function () {
@@ -101,35 +100,8 @@ function bound(obj) {
machine: obj.machine.bind(obj),
devNull: obj.devNull,
EOL: obj.EOL,
- constants: obj.constants,
- [Symbol.for("CommonJS")]: 0,
+ constants: $processBindingConstants.os,
};
}
-var os = bound(Bun._Os());
-
-export var {
- arch,
- cpus,
- endianness,
- freemem,
- getPriority,
- homedir,
- hostname,
- loadavg,
- networkInterfaces,
- platform,
- release,
- setPriority,
- totalmem,
- type,
- uptime,
- userInfo,
- version,
- machine,
- devNull,
- EOL,
- constants,
-} = os;
-
-export default os;
+export default bound(Bun._Os());
diff --git a/src/js/node/path.posix.ts b/src/js/node/path.posix.ts
index e94da9cea..d4aeddd85 100644
--- a/src/js/node/path.posix.ts
+++ b/src/js/node/path.posix.ts
@@ -1,37 +1,2 @@
// Hardcoded module "node:path/posix"
-function bound(obj) {
- return {
- basename: obj.basename.bind(obj),
- dirname: obj.dirname.bind(obj),
- extname: obj.extname.bind(obj),
- format: obj.format.bind(obj),
- isAbsolute: obj.isAbsolute.bind(obj),
- join: obj.join.bind(obj),
- normalize: obj.normalize.bind(obj),
- parse: obj.parse.bind(obj),
- relative: obj.relative.bind(obj),
- resolve: obj.resolve.bind(obj),
- toNamespacedPath: obj.toNamespacedPath.bind(obj),
- sep: obj.sep,
- delimiter: obj.delimiter,
- };
-}
-var path = bound(Bun._Path(false));
-path[Symbol.for("CommonJS")] = 0;
-
-export var {
- basename,
- dirname,
- extname,
- format,
- isAbsolute,
- join,
- normalize,
- parse,
- relative,
- resolve,
- toNamespacedPath,
- sep,
- delimiter,
-} = path;
-export default path;
+export default require("node:path").posix;
diff --git a/src/js/node/path.ts b/src/js/node/path.ts
index 7c20d520b..ba7977740 100644
--- a/src/js/node/path.ts
+++ b/src/js/node/path.ts
@@ -1,49 +1,31 @@
// Hardcoded module "node:path"
-export const createModule = obj => Object.assign(Object.create(null), obj);
function bound(obj) {
- var result = createModule({
- basename: obj.basename.bind(obj),
+ const toNamespacedPath = obj.toNamespacedPath.bind(obj);
+ const result = {
+ resolve: obj.resolve.bind(obj),
+ normalize: obj.normalize.bind(obj),
+ isAbsolute: obj.isAbsolute.bind(obj),
+ join: obj.join.bind(obj),
+ relative: obj.relative.bind(obj),
+ toNamespacedPath,
dirname: obj.dirname.bind(obj),
+ basename: obj.basename.bind(obj),
extname: obj.extname.bind(obj),
format: obj.format.bind(obj),
- isAbsolute: obj.isAbsolute.bind(obj),
- join: obj.join.bind(obj),
- normalize: obj.normalize.bind(obj),
parse: obj.parse.bind(obj),
- relative: obj.relative.bind(obj),
- resolve: obj.resolve.bind(obj),
- toNamespacedPath: obj.toNamespacedPath.bind(obj),
sep: obj.sep,
delimiter: obj.delimiter,
- });
- result.default = result;
+ win32: undefined,
+ posix: undefined,
+ _makeLong: toNamespacedPath,
+ };
return result;
}
-var path = bound(Bun._Path());
-
-export var posix = bound(Bun._Path(false));
-export var win32 = bound(Bun._Path(true));
-path.win32 = win32;
-path.posix = posix;
+const posix: any = bound(Bun._Path(false));
+const win32: any = bound(Bun._Path(true));
-export var {
- basename,
- dirname,
- extname,
- format,
- isAbsolute,
- join,
- normalize,
- parse,
- relative,
- resolve,
- toNamespacedPath,
- sep,
- delimiter,
- __esModule,
-} = path;
+posix.win32 = win32.win32 = win32;
+posix.posix = win32.posix = posix;
-path[Symbol.for("CommonJS")] = 0;
-path.__esModule = true;
-export default path;
+export default process.platform === "win32" ? win32 : posix;
diff --git a/src/js/node/path.win32.ts b/src/js/node/path.win32.ts
index 1c8bda4ba..a8a74fbb2 100644
--- a/src/js/node/path.win32.ts
+++ b/src/js/node/path.win32.ts
@@ -1,36 +1,2 @@
// Hardcoded module "node:path/win32"
-function bound(obj) {
- return {
- basename: obj.basename.bind(obj),
- dirname: obj.dirname.bind(obj),
- extname: obj.extname.bind(obj),
- format: obj.format.bind(obj),
- isAbsolute: obj.isAbsolute.bind(obj),
- join: obj.join.bind(obj),
- normalize: obj.normalize.bind(obj),
- parse: obj.parse.bind(obj),
- relative: obj.relative.bind(obj),
- resolve: obj.resolve.bind(obj),
- toNamespacedPath: obj.toNamespacedPath.bind(obj),
- sep: obj.sep,
- delimiter: obj.delimiter,
- };
-}
-var path = bound(Bun._Path(true));
-
-export var {
- basename,
- dirname,
- extname,
- format,
- isAbsolute,
- join,
- normalize,
- parse,
- relative,
- resolve,
- toNamespacedPath,
- sep,
- delimiter,
-} = path;
-export default path;
+export default require("node:path").win32;
diff --git a/src/js/node/perf_hooks.js b/src/js/node/perf_hooks.js
deleted file mode 100644
index 592868ab5..000000000
--- a/src/js/node/perf_hooks.js
+++ /dev/null
@@ -1,43 +0,0 @@
-// Hardcoded module "node:perf_hooks"
-import { throwNotImplemented } from "../shared";
-
-export var constants = {
- NODE_PERFORMANCE_GC_MAJOR: 4,
- NODE_PERFORMANCE_GC_MINOR: 1,
- NODE_PERFORMANCE_GC_INCREMENTAL: 8,
- NODE_PERFORMANCE_GC_WEAKCB: 16,
- NODE_PERFORMANCE_GC_FLAGS_NO: 0,
- NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED: 2,
- NODE_PERFORMANCE_GC_FLAGS_FORCED: 4,
- NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING: 8,
- NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE: 16,
- NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY: 32,
- NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE: 64,
-};
-
-export var performance = globalThis.performance;
-
-export class PerformanceObserver {
- constructor() {
- throwNotImplemented("PerformanceObserver");
- }
-}
-
-export class PerformanceEntry {
- constructor() {
- throwNotImplemented("PerformanceEntry");
- }
-}
-export class PerformanceNodeTiming {
- constructor() {
- throw new Error("PerformanceNodeTiming is not supported in this environment.");
- }
-}
-
-export default {
- performance,
- constants,
- PerformanceEntry,
- PerformanceNodeTiming,
- [Symbol.for("CommonJS")]: 0,
-};
diff --git a/src/js/node/perf_hooks.ts b/src/js/node/perf_hooks.ts
new file mode 100644
index 000000000..c40d335ae
--- /dev/null
+++ b/src/js/node/perf_hooks.ts
@@ -0,0 +1,59 @@
+// Hardcoded module "node:perf_hooks"
+const { throwNotImplemented } = require("$shared");
+
+var constants = {
+ NODE_PERFORMANCE_GC_MAJOR: 4,
+ NODE_PERFORMANCE_GC_MINOR: 1,
+ NODE_PERFORMANCE_GC_INCREMENTAL: 8,
+ NODE_PERFORMANCE_GC_WEAKCB: 16,
+ NODE_PERFORMANCE_GC_FLAGS_NO: 0,
+ NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED: 2,
+ NODE_PERFORMANCE_GC_FLAGS_FORCED: 4,
+ NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING: 8,
+ NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE: 16,
+ NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY: 32,
+ NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE: 64,
+};
+
+var performance = globalThis.performance;
+
+class PerformanceObserver {
+ constructor() {
+ throwNotImplemented("PerformanceObserver");
+ }
+}
+
+class PerformanceEntry {
+ constructor() {
+ throwNotImplemented("PerformanceEntry");
+ }
+}
+
+export default {
+ performance,
+ // performance: {
+ // clearMarks: [Function: clearMarks],
+ // clearMeasures: [Function: clearMeasures],
+ // clearResourceTimings: [Function: clearResourceTimings],
+ // getEntries: [Function: getEntries],
+ // getEntriesByName: [Function: getEntriesByName],
+ // getEntriesByType: [Function: getEntriesByType],
+ // mark: [Function: mark],
+ // measure: [Function: measure],
+ // now: performance.now,
+ // setResourceTimingBufferSize: [Function: setResourceTimingBufferSize],
+ // timeOrigin: performance.timeOrigin,
+ // toJSON: [Function: toJSON],
+ // onresourcetimingbufferfull: [Getter/Setter]
+ // },
+ constants,
+ // Performance: [class Performance extends EventTarget],
+ PerformanceEntry,
+ // PerformanceMark: [class PerformanceMark extends PerformanceEntry],
+ // PerformanceMeasure: [class PerformanceMeasure extends PerformanceEntry],
+ PerformanceObserver,
+ // PerformanceObserverEntryList: [class PerformanceObserverEntryList],
+ // PerformanceResourceTiming: [class PerformanceResourceTiming extends PerformanceEntry],
+ // monitorEventLoopDelay: [Function: monitorEventLoopDelay],
+ // createHistogram: [Function: createHistogram],
+};
diff --git a/src/js/node/punycode.js b/src/js/node/punycode.js
new file mode 100644
index 000000000..6d41161fd
--- /dev/null
+++ b/src/js/node/punycode.js
@@ -0,0 +1,431 @@
+// taken directly from https://www.npmjs.com/package/punycode
+"use strict";
+
+/** Highest positive signed 32-bit float value */
+const maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
+
+/** Bootstring parameters */
+const base = 36;
+const tMin = 1;
+const tMax = 26;
+const skew = 38;
+const damp = 700;
+const initialBias = 72;
+const initialN = 128; // 0x80
+const delimiter = "-"; // '\x2D'
+
+/** Regular expressions */
+const regexPunycode = /^xn--/;
+const regexNonASCII = /[^\0-\x7F]/; // Note: U+007F DEL is excluded too.
+const regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
+
+/** Error messages */
+const errors = {
+ "overflow": "Overflow: input needs wider integers to process",
+ "not-basic": "Illegal input >= 0x80 (not a basic code point)",
+ "invalid-input": "Invalid input",
+};
+
+/** Convenience shortcuts */
+const baseMinusTMin = base - tMin;
+const floor = Math.floor;
+const stringFromCharCode = String.fromCharCode;
+
+/*--------------------------------------------------------------------------*/
+
+/**
+ * A generic error utility function.
+ * @private
+ * @param {String} type The error type.
+ * @returns {Error} Throws a `RangeError` with the applicable error message.
+ */
+function error(type) {
+ throw new RangeError(errors[type]);
+}
+
+/**
+ * A generic `Array#map` utility function.
+ * @private
+ * @param {Array} array The array to iterate over.
+ * @param {Function} callback The function that gets called for every array
+ * item.
+ * @returns {Array} A new array of values returned by the callback function.
+ */
+function map(array, callback) {
+ const result = [];
+ let length = array.length;
+ while (length--) {
+ result[length] = callback(array[length]);
+ }
+ return result;
+}
+
+/**
+ * A simple `Array#map`-like wrapper to work with domain name strings or email
+ * addresses.
+ * @private
+ * @param {String} domain The domain name or email address.
+ * @param {Function} callback The function that gets called for every
+ * character.
+ * @returns {String} A new string of characters returned by the callback
+ * function.
+ */
+function mapDomain(domain, callback) {
+ const parts = domain.split("@");
+ let result = "";
+ if (parts.length > 1) {
+ // In email addresses, only the domain name should be punycoded. Leave
+ // the local part (i.e. everything up to `@`) intact.
+ result = parts[0] + "@";
+ domain = parts[1];
+ }
+ // Avoid `split(regex)` for IE8 compatibility. See #17.
+ domain = domain.replace(regexSeparators, "\x2E");
+ const labels = domain.split(".");
+ const encoded = map(labels, callback).join(".");
+ return result + encoded;
+}
+
+/**
+ * Creates an array containing the numeric code points of each Unicode
+ * character in the string. While JavaScript uses UCS-2 internally,
+ * this function will convert a pair of surrogate halves (each of which
+ * UCS-2 exposes as separate characters) into a single code point,
+ * matching UTF-16.
+ * @see `punycode.ucs2.encode`
+ * @see <https://mathiasbynens.be/notes/javascript-encoding>
+ * @memberOf punycode.ucs2
+ * @name decode
+ * @param {String} string The Unicode input string (UCS-2).
+ * @returns {Array} The new array of code points.
+ */
+function ucs2decode(string) {
+ const output = [];
+ let counter = 0;
+ const length = string.length;
+ while (counter < length) {
+ const value = string.charCodeAt(counter++);
+ if (value >= 0xd800 && value <= 0xdbff && counter < length) {
+ // It's a high surrogate, and there is a next character.
+ const extra = string.charCodeAt(counter++);
+ if ((extra & 0xfc00) == 0xdc00) {
+ // Low surrogate.
+ output.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000);
+ } else {
+ // It's an unmatched surrogate; only append this code unit, in case the
+ // next code unit is the high surrogate of a surrogate pair.
+ output.push(value);
+ counter--;
+ }
+ } else {
+ output.push(value);
+ }
+ }
+ return output;
+}
+
+/**
+ * Creates a string based on an array of numeric code points.
+ * @see `punycode.ucs2.decode`
+ * @memberOf punycode.ucs2
+ * @name encode
+ * @param {Array} codePoints The array of numeric code points.
+ * @returns {String} The new Unicode string (UCS-2).
+ */
+const ucs2encode = codePoints => String.fromCodePoint(...codePoints);
+
+/**
+ * Converts a basic code point into a digit/integer.
+ * @see `digitToBasic()`
+ * @private
+ * @param {Number} codePoint The basic numeric code point value.
+ * @returns {Number} The numeric value of a basic code point (for use in
+ * representing integers) in the range `0` to `base - 1`, or `base` if
+ * the code point does not represent a value.
+ */
+const basicToDigit = function (codePoint) {
+ if (codePoint >= 0x30 && codePoint < 0x3a) {
+ return 26 + (codePoint - 0x30);
+ }
+ if (codePoint >= 0x41 && codePoint < 0x5b) {
+ return codePoint - 0x41;
+ }
+ if (codePoint >= 0x61 && codePoint < 0x7b) {
+ return codePoint - 0x61;
+ }
+ return base;
+};
+
+/**
+ * Converts a digit/integer into a basic code point.
+ * @see `basicToDigit()`
+ * @private
+ * @param {Number} digit The numeric value of a basic code point.
+ * @returns {Number} The basic code point whose value (when used for
+ * representing integers) is `digit`, which needs to be in the range
+ * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
+ * used; else, the lowercase form is used. The behavior is undefined
+ * if `flag` is non-zero and `digit` has no uppercase form.
+ */
+const digitToBasic = function (digit, flag) {
+ // 0..25 map to ASCII a..z or A..Z
+ // 26..35 map to ASCII 0..9
+ return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
+};
+
+/**
+ * Bias adaptation function as per section 3.4 of RFC 3492.
+ * https://tools.ietf.org/html/rfc3492#section-3.4
+ * @private
+ */
+const adapt = function (delta, numPoints, firstTime) {
+ let k = 0;
+ delta = firstTime ? floor(delta / damp) : delta >> 1;
+ delta += floor(delta / numPoints);
+ for (; /* no initialization */ delta > (baseMinusTMin * tMax) >> 1; k += base) {
+ delta = floor(delta / baseMinusTMin);
+ }
+ return floor(k + ((baseMinusTMin + 1) * delta) / (delta + skew));
+};
+
+/**
+ * Converts a Punycode string of ASCII-only symbols to a string of Unicode
+ * symbols.
+ * @memberOf punycode
+ * @param {String} input The Punycode string of ASCII-only symbols.
+ * @returns {String} The resulting string of Unicode symbols.
+ */
+const decode = function (input) {
+ // Don't use UCS-2.
+ const output = [];
+ const inputLength = input.length;
+ let i = 0;
+ let n = initialN;
+ let bias = initialBias;
+
+ // Handle the basic code points: let `basic` be the number of input code
+ // points before the last delimiter, or `0` if there is none, then copy
+ // the first basic code points to the output.
+
+ let basic = input.lastIndexOf(delimiter);
+ if (basic < 0) {
+ basic = 0;
+ }
+
+ for (let j = 0; j < basic; ++j) {
+ // if it's not a basic code point
+ if (input.charCodeAt(j) >= 0x80) {
+ error("not-basic");
+ }
+ output.push(input.charCodeAt(j));
+ }
+
+ // Main decoding loop: start just after the last delimiter if any basic code
+ // points were copied; start at the beginning otherwise.
+
+ for (let index = basic > 0 ? basic + 1 : 0; index < inputLength /* no final expression */; ) {
+ // `index` is the index of the next character to be consumed.
+ // Decode a generalized variable-length integer into `delta`,
+ // which gets added to `i`. The overflow checking is easier
+ // if we increase `i` as we go, then subtract off its starting
+ // value at the end to obtain `delta`.
+ const oldi = i;
+ for (let w = 1, k = base /* no condition */; ; k += base) {
+ if (index >= inputLength) {
+ error("invalid-input");
+ }
+
+ const digit = basicToDigit(input.charCodeAt(index++));
+
+ if (digit >= base) {
+ error("invalid-input");
+ }
+ if (digit > floor((maxInt - i) / w)) {
+ error("overflow");
+ }
+
+ i += digit * w;
+ const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
+
+ if (digit < t) {
+ break;
+ }
+
+ const baseMinusT = base - t;
+ if (w > floor(maxInt / baseMinusT)) {
+ error("overflow");
+ }
+
+ w *= baseMinusT;
+ }
+
+ const out = output.length + 1;
+ bias = adapt(i - oldi, out, oldi == 0);
+
+ // `i` was supposed to wrap around from `out` to `0`,
+ // incrementing `n` each time, so we'll fix that now:
+ if (floor(i / out) > maxInt - n) {
+ error("overflow");
+ }
+
+ n += floor(i / out);
+ i %= out;
+
+ // Insert `n` at position `i` of the output.
+ output.splice(i++, 0, n);
+ }
+
+ return String.fromCodePoint(...output);
+};
+
+/**
+ * Converts a string of Unicode symbols (e.g. a domain name label) to a
+ * Punycode string of ASCII-only symbols.
+ * @memberOf punycode
+ * @param {String} input The string of Unicode symbols.
+ * @returns {String} The resulting Punycode string of ASCII-only symbols.
+ */
+const encode = function (input) {
+ const output = [];
+
+ // Convert the input in UCS-2 to an array of Unicode code points.
+ input = ucs2decode(input);
+
+ // Cache the length.
+ const inputLength = input.length;
+
+ // Initialize the state.
+ let n = initialN;
+ let delta = 0;
+ let bias = initialBias;
+
+ // Handle the basic code points.
+ for (const currentValue of input) {
+ if (currentValue < 0x80) {
+ output.push(stringFromCharCode(currentValue));
+ }
+ }
+
+ const basicLength = output.length;
+ let handledCPCount = basicLength;
+
+ // `handledCPCount` is the number of code points that have been handled;
+ // `basicLength` is the number of basic code points.
+
+ // Finish the basic string with a delimiter unless it's empty.
+ if (basicLength) {
+ output.push(delimiter);
+ }
+
+ // Main encoding loop:
+ while (handledCPCount < inputLength) {
+ // All non-basic code points < n have been handled already. Find the next
+ // larger one:
+ let m = maxInt;
+ for (const currentValue of input) {
+ if (currentValue >= n && currentValue < m) {
+ m = currentValue;
+ }
+ }
+
+ // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
+ // but guard against overflow.
+ const handledCPCountPlusOne = handledCPCount + 1;
+ if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
+ error("overflow");
+ }
+
+ delta += (m - n) * handledCPCountPlusOne;
+ n = m;
+
+ for (const currentValue of input) {
+ if (currentValue < n && ++delta > maxInt) {
+ error("overflow");
+ }
+ if (currentValue === n) {
+ // Represent delta as a generalized variable-length integer.
+ let q = delta;
+ for (let k = base /* no condition */; ; k += base) {
+ const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
+ if (q < t) {
+ break;
+ }
+ const qMinusT = q - t;
+ const baseMinusT = base - t;
+ output.push(stringFromCharCode(digitToBasic(t + (qMinusT % baseMinusT), 0)));
+ q = floor(qMinusT / baseMinusT);
+ }
+
+ output.push(stringFromCharCode(digitToBasic(q, 0)));
+ bias = adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength);
+ delta = 0;
+ ++handledCPCount;
+ }
+ }
+
+ ++delta;
+ ++n;
+ }
+ return output.join("");
+};
+
+/**
+ * Converts a Punycode string representing a domain name or an email address
+ * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
+ * it doesn't matter if you call it on a string that has already been
+ * converted to Unicode.
+ * @memberOf punycode
+ * @param {String} input The Punycoded domain name or email address to
+ * convert to Unicode.
+ * @returns {String} The Unicode representation of the given Punycode
+ * string.
+ */
+const toUnicode = function (input) {
+ return mapDomain(input, function (string) {
+ return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string;
+ });
+};
+
+/**
+ * Converts a Unicode string representing a domain name or an email address to
+ * Punycode. Only the non-ASCII parts of the domain name will be converted,
+ * i.e. it doesn't matter if you call it with a domain that's already in
+ * ASCII.
+ * @memberOf punycode
+ * @param {String} input The domain name or email address to convert, as a
+ * Unicode string.
+ * @returns {String} The Punycode representation of the given domain name or
+ * email address.
+ */
+const toASCII = function (input) {
+ return mapDomain(input, function (string) {
+ return regexNonASCII.test(string) ? "xn--" + encode(string) : string;
+ });
+};
+
+/*--------------------------------------------------------------------------*/
+
+/** Define the public API */
+export default {
+ /**
+ * A string representing the current Punycode.js version number.
+ * @memberOf punycode
+ * @type String
+ */
+ "version": "2.1.0",
+ /**
+ * An object of methods to convert from JavaScript's internal character
+ * representation (UCS-2) to Unicode code points, and back.
+ * @see <https://mathiasbynens.be/notes/javascript-encoding>
+ * @memberOf punycode
+ * @type Object
+ */
+ "ucs2": {
+ "decode": ucs2decode,
+ "encode": ucs2encode,
+ },
+ "decode": decode,
+ "encode": encode,
+ "toASCII": toASCII,
+ "toUnicode": toUnicode,
+};
diff --git a/src/js/node/querystring.js b/src/js/node/querystring.js
new file mode 100644
index 000000000..232bdac75
--- /dev/null
+++ b/src/js/node/querystring.js
@@ -0,0 +1,396 @@
+var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
+
+var Buffer = require("node:buffer").Buffer;
+
+// src/node-fallbacks/node_modules/querystring-es3/src/object-keys.js
+var require_object_keys = __commonJS((exports, module) => {
+ var objectKeys =
+ Object.keys ||
+ (function () {
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
+ var hasDontEnumBug = !{ toString: null }.propertyIsEnumerable("toString");
+ var dontEnums = [
+ "toString",
+ "toLocaleString",
+ "valueOf",
+ "hasOwnProperty",
+ "isPrototypeOf",
+ "propertyIsEnumerable",
+ "constructor",
+ ];
+ var dontEnumsLength = dontEnums.length;
+ return function (obj) {
+ if (typeof obj !== "function" && (typeof obj !== "object" || obj === null)) {
+ throw new TypeError("Object.keys called on non-object");
+ }
+ var result = [];
+ var prop;
+ var i;
+ for (prop in obj) {
+ if (hasOwnProperty.call(obj, prop)) {
+ result.push(prop);
+ }
+ }
+ if (hasDontEnumBug) {
+ for (i = 0; i < dontEnumsLength; i++) {
+ if (hasOwnProperty.call(obj, dontEnums[i])) {
+ result.push(dontEnums[i]);
+ }
+ }
+ }
+ return result;
+ };
+ })();
+ module.exports = objectKeys;
+});
+
+// src/node-fallbacks/node_modules/querystring-es3/src/index.js
+var require_src = __commonJS((exports, module) => {
+ var ParsedQueryString = function () {};
+ var unescapeBuffer = function (s, decodeSpaces) {
+ var out = Buffer.allocUnsafe(s.length);
+ var state = 0;
+ var n, m, hexchar, c;
+ for (var inIndex = 0, outIndex = 0; ; inIndex++) {
+ if (inIndex < s.length) {
+ c = s.charCodeAt(inIndex);
+ } else {
+ if (state > 0) {
+ out[outIndex++] = 37;
+ if (state === 2) out[outIndex++] = hexchar;
+ }
+ break;
+ }
+ switch (state) {
+ case 0:
+ switch (c) {
+ case 37:
+ n = 0;
+ m = 0;
+ state = 1;
+ break;
+ case 43:
+ if (decodeSpaces) c = 32;
+ default:
+ out[outIndex++] = c;
+ break;
+ }
+ break;
+ case 1:
+ hexchar = c;
+ n = unhexTable[c];
+ if (!(n >= 0)) {
+ out[outIndex++] = 37;
+ out[outIndex++] = c;
+ state = 0;
+ break;
+ }
+ state = 2;
+ break;
+ case 2:
+ state = 0;
+ m = unhexTable[c];
+ if (!(m >= 0)) {
+ out[outIndex++] = 37;
+ out[outIndex++] = hexchar;
+ out[outIndex++] = c;
+ break;
+ }
+ out[outIndex++] = 16 * n + m;
+ break;
+ }
+ }
+ return out.slice(0, outIndex);
+ };
+ var qsUnescape = function (s, decodeSpaces) {
+ try {
+ return decodeURIComponent(s);
+ } catch (e) {
+ return QueryString.unescapeBuffer(s, decodeSpaces).toString();
+ }
+ };
+ var qsEscape = function (str) {
+ if (typeof str !== "string") {
+ if (typeof str === "object") str = String(str);
+ else str += "";
+ }
+ var out = "";
+ var lastPos = 0;
+ for (var i2 = 0; i2 < str.length; ++i2) {
+ var c = str.charCodeAt(i2);
+ if (c < 128) {
+ if (noEscape[c] === 1) continue;
+ if (lastPos < i2) out += str.slice(lastPos, i2);
+ lastPos = i2 + 1;
+ out += hexTable[c];
+ continue;
+ }
+ if (lastPos < i2) out += str.slice(lastPos, i2);
+ if (c < 2048) {
+ lastPos = i2 + 1;
+ out += hexTable[192 | (c >> 6)] + hexTable[128 | (c & 63)];
+ continue;
+ }
+ if (c < 55296 || c >= 57344) {
+ lastPos = i2 + 1;
+ out += hexTable[224 | (c >> 12)] + hexTable[128 | ((c >> 6) & 63)] + hexTable[128 | (c & 63)];
+ continue;
+ }
+ ++i2;
+ var c2;
+ if (i2 < str.length) c2 = str.charCodeAt(i2) & 1023;
+ else throw new URIError("URI malformed");
+ lastPos = i2 + 1;
+ c = 65536 + (((c & 1023) << 10) | c2);
+ out +=
+ hexTable[240 | (c >> 18)] +
+ hexTable[128 | ((c >> 12) & 63)] +
+ hexTable[128 | ((c >> 6) & 63)] +
+ hexTable[128 | (c & 63)];
+ }
+ if (lastPos === 0) return str;
+ if (lastPos < str.length) return out + str.slice(lastPos);
+ return out;
+ };
+ var stringifyPrimitive = function (v) {
+ if (typeof v === "string") return v;
+ if (typeof v === "number" && isFinite(v)) return "" + v;
+ if (typeof v === "boolean") return v ? "true" : "false";
+ return "";
+ };
+ var stringify = function (obj, sep, eq, options) {
+ sep = sep || "&";
+ eq = eq || "=";
+ var encode = QueryString.escape;
+ if (options && typeof options.encodeURIComponent === "function") {
+ encode = options.encodeURIComponent;
+ }
+ if (obj !== null && typeof obj === "object") {
+ var keys = objectKeys(obj);
+ var len = keys.length;
+ var flast = len - 1;
+ var fields = "";
+ for (var i2 = 0; i2 < len; ++i2) {
+ var k = keys[i2];
+ var v = obj[k];
+ var ks = encode(stringifyPrimitive(k)) + eq;
+ if (isArray(v)) {
+ var vlen = v.length;
+ var vlast = vlen - 1;
+ for (var j = 0; j < vlen; ++j) {
+ fields += ks + encode(stringifyPrimitive(v[j]));
+ if (j < vlast) fields += sep;
+ }
+ if (vlen && i2 < flast) fields += sep;
+ } else {
+ fields += ks + encode(stringifyPrimitive(v));
+ if (i2 < flast) fields += sep;
+ }
+ }
+ return fields;
+ }
+ return "";
+ };
+ var charCodes = function (str) {
+ if (str.length === 0) return [];
+ if (str.length === 1) return [str.charCodeAt(0)];
+ const ret = [];
+ for (var i2 = 0; i2 < str.length; ++i2) ret[ret.length] = str.charCodeAt(i2);
+ return ret;
+ };
+ var parse = function (qs, sep, eq, options) {
+ const obj = new ParsedQueryString();
+ if (typeof qs !== "string" || qs.length === 0) {
+ return obj;
+ }
+ var sepCodes = !sep ? defSepCodes : charCodes(sep + "");
+ var eqCodes = !eq ? defEqCodes : charCodes(eq + "");
+ const sepLen = sepCodes.length;
+ const eqLen = eqCodes.length;
+ var pairs = 1000;
+ if (options && typeof options.maxKeys === "number") {
+ pairs = options.maxKeys > 0 ? options.maxKeys : -1;
+ }
+ var decode = QueryString.unescape;
+ if (options && typeof options.decodeURIComponent === "function") {
+ decode = options.decodeURIComponent;
+ }
+ const customDecode = decode !== qsUnescape;
+ const keys = [];
+ var posIdx = 0;
+ var lastPos = 0;
+ var sepIdx = 0;
+ var eqIdx = 0;
+ var key = "";
+ var value = "";
+ var keyEncoded = customDecode;
+ var valEncoded = customDecode;
+ var encodeCheck = 0;
+ for (var i2 = 0; i2 < qs.length; ++i2) {
+ const code = qs.charCodeAt(i2);
+ if (code === sepCodes[sepIdx]) {
+ if (++sepIdx === sepLen) {
+ const end = i2 - sepIdx + 1;
+ if (eqIdx < eqLen) {
+ if (lastPos < end) key += qs.slice(lastPos, end);
+ } else if (lastPos < end) value += qs.slice(lastPos, end);
+ if (keyEncoded) key = decodeStr(key, decode);
+ if (valEncoded) value = decodeStr(value, decode);
+ if (key || value || lastPos - posIdx > sepLen || i2 === 0) {
+ if (indexOf(keys, key) === -1) {
+ obj[key] = value;
+ keys[keys.length] = key;
+ } else {
+ const curValue = obj[key] || "";
+ if (curValue.pop) curValue[curValue.length] = value;
+ else if (curValue) obj[key] = [curValue, value];
+ }
+ } else if (i2 === 1) {
+ delete obj[key];
+ }
+ if (--pairs === 0) break;
+ keyEncoded = valEncoded = customDecode;
+ encodeCheck = 0;
+ key = value = "";
+ posIdx = lastPos;
+ lastPos = i2 + 1;
+ sepIdx = eqIdx = 0;
+ }
+ continue;
+ } else {
+ sepIdx = 0;
+ if (!valEncoded) {
+ if (code === 37) {
+ encodeCheck = 1;
+ } else if (
+ encodeCheck > 0 &&
+ ((code >= 48 && code <= 57) || (code >= 65 && code <= 70) || (code >= 97 && code <= 102))
+ ) {
+ if (++encodeCheck === 3) valEncoded = true;
+ } else {
+ encodeCheck = 0;
+ }
+ }
+ }
+ if (eqIdx < eqLen) {
+ if (code === eqCodes[eqIdx]) {
+ if (++eqIdx === eqLen) {
+ const end = i2 - eqIdx + 1;
+ if (lastPos < end) key += qs.slice(lastPos, end);
+ encodeCheck = 0;
+ lastPos = i2 + 1;
+ }
+ continue;
+ } else {
+ eqIdx = 0;
+ if (!keyEncoded) {
+ if (code === 37) {
+ encodeCheck = 1;
+ } else if (
+ encodeCheck > 0 &&
+ ((code >= 48 && code <= 57) || (code >= 65 && code <= 70) || (code >= 97 && code <= 102))
+ ) {
+ if (++encodeCheck === 3) keyEncoded = true;
+ } else {
+ encodeCheck = 0;
+ }
+ }
+ }
+ }
+ if (code === 43) {
+ if (eqIdx < eqLen) {
+ if (lastPos < i2) key += qs.slice(lastPos, i2);
+ key += "%20";
+ keyEncoded = true;
+ } else {
+ if (lastPos < i2) value += qs.slice(lastPos, i2);
+ value += "%20";
+ valEncoded = true;
+ }
+ lastPos = i2 + 1;
+ }
+ }
+ if (pairs !== 0 && (lastPos < qs.length || eqIdx > 0)) {
+ if (lastPos < qs.length) {
+ if (eqIdx < eqLen) key += qs.slice(lastPos);
+ else if (sepIdx < sepLen) value += qs.slice(lastPos);
+ }
+ if (keyEncoded) key = decodeStr(key, decode);
+ if (valEncoded) value = decodeStr(value, decode);
+ if (indexOf(keys, key) === -1) {
+ obj[key] = value;
+ keys[keys.length] = key;
+ } else {
+ const curValue = obj[key];
+ if (curValue.pop) curValue[curValue.length] = value;
+ else obj[key] = [curValue, value];
+ }
+ }
+ return obj;
+ };
+ var decodeStr = function (s, decoder) {
+ try {
+ return decoder(s);
+ } catch (e) {
+ return QueryString.unescape(s, true);
+ }
+ };
+ var QueryString = (module.exports = {
+ unescapeBuffer,
+ unescape: qsUnescape,
+ escape: qsEscape,
+ stringify,
+ encode: stringify,
+ parse,
+ decode: parse,
+ });
+ var objectKeys = require_object_keys();
+ var isArray = arg => Object.prototype.toString.call(arg) === "[object Array]";
+ var indexOf = (arr, searchElement, fromIndex) => {
+ var k;
+ if (arr == null) {
+ throw new TypeError('"arr" is null or not defined');
+ }
+ var o = Object(arr);
+ var len = o.length >>> 0;
+ if (len === 0) {
+ return -1;
+ }
+ var n = fromIndex | 0;
+ if (n >= len) {
+ return -1;
+ }
+ k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
+ while (k < len) {
+ if (k in o && o[k] === searchElement) {
+ return k;
+ }
+ k++;
+ }
+ return -1;
+ };
+ ParsedQueryString.prototype = Object.create ? Object.create(null) : {};
+ var unhexTable = [
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1,
+ -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ ];
+ var hexTable = [];
+ for (i = 0; i < 256; ++i) hexTable[i] = "%" + ((i < 16 ? "0" : "") + i.toString(16)).toUpperCase();
+ var i;
+ var noEscape = [
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0,
+ ];
+ var defSepCodes = [38];
+ var defEqCodes = [61];
+});
+export default require_src();
diff --git a/src/js/node/readline.js b/src/js/node/readline.js
index b1613e34d..0811fb95f 100644
--- a/src/js/node/readline.js
+++ b/src/js/node/readline.js
@@ -25,10 +25,8 @@
// ----------------------------------------------------------------------------
// Section: Imports
// ----------------------------------------------------------------------------
-var { Array, RegExp, String, Bun } = $lazy("primordials");
-import { EventEmitter } from "node:events";
-import { clearTimeout, setTimeout } from "timers";
-import { StringDecoder } from "string_decoder";
+const EventEmitter = require("node:events");
+const { StringDecoder } = require("node:string_decoder");
var isWritable;
var { inspect } = Bun;
@@ -1571,6 +1569,7 @@ function InterfaceConstructor(input, output, completer, terminal) {
input.resume();
}
+InterfaceConstructor.prototype = {};
ObjectSetPrototypeOf(InterfaceConstructor.prototype, EventEmitter.prototype);
// ObjectSetPrototypeOf(InterfaceConstructor, EventEmitter);
@@ -2555,6 +2554,7 @@ function Interface(input, output, completer, terminal) {
this._ttyWrite = _ttyWriteDumb.bind(this);
}
}
+Interface.prototype = {};
ObjectSetPrototypeOf(Interface.prototype, _Interface.prototype);
ObjectSetPrototypeOf(Interface, _Interface);
@@ -2957,7 +2957,7 @@ class Readline {
#todo = [];
constructor(stream, options = undefined) {
- isWritable ??= import.meta.require("node:stream").isWritable;
+ isWritable ??= require("node:stream").isWritable;
if (!isWritable(stream)) throw new ERR_INVALID_ARG_TYPE("stream", "Writable", stream);
this.#stream = stream;
if (options?.autoCommit != null) {
@@ -3101,21 +3101,6 @@ var PromisesInterface = class Interface extends _Interface {
// ----------------------------------------------------------------------------
// Exports
// ----------------------------------------------------------------------------
-export var Interface = Interface;
-export var clearLine = clearLine;
-export var clearScreenDown = clearScreenDown;
-export var createInterface = createInterface;
-export var cursorTo = cursorTo;
-export var emitKeypressEvents = emitKeypressEvents;
-export var moveCursor = moveCursor;
-export var promises = {
- Readline,
- Interface: PromisesInterface,
- createInterface(input, output, completer, terminal) {
- return new PromisesInterface(input, output, completer, terminal);
- },
-};
-
export default {
Interface,
clearLine,
@@ -3124,7 +3109,13 @@ export default {
cursorTo,
emitKeypressEvents,
moveCursor,
- promises,
+ promises: {
+ Readline,
+ Interface: PromisesInterface,
+ createInterface(input, output, completer, terminal) {
+ return new PromisesInterface(input, output, completer, terminal);
+ },
+ },
[SymbolFor("__BUN_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED__")]: {
CSI,
@@ -3133,5 +3124,4 @@ export default {
stripVTControlCharacters,
},
},
- [SymbolFor("CommonJS")]: 0,
};
diff --git a/src/js/node/readline.promises.js b/src/js/node/readline.promises.js
deleted file mode 100644
index 6890235b4..000000000
--- a/src/js/node/readline.promises.js
+++ /dev/null
@@ -1,11 +0,0 @@
-// Hardcoded module "node:readline/promises"
-import { promises } from "node:readline";
-
-export const { Readline, Interface, createInterface } = promises;
-
-export default {
- Readline,
- Interface,
- createInterface,
- [Symbol.for("CommonJS")]: 0,
-};
diff --git a/src/js/node/readline.promises.ts b/src/js/node/readline.promises.ts
new file mode 100644
index 000000000..6ab60f0b2
--- /dev/null
+++ b/src/js/node/readline.promises.ts
@@ -0,0 +1,2 @@
+// Hardcoded module "node:readline/promises"
+export default require("node:readline").promises;
diff --git a/src/js/node/repl.ts b/src/js/node/repl.ts
index 33065e2ed..ff1474a47 100644
--- a/src/js/node/repl.ts
+++ b/src/js/node/repl.ts
@@ -1,7 +1,7 @@
// Hardcoded module "node:repl"
// This is a stub! None of this is actually implemented yet.
// It only exists to make some packages which import this module work.
-import { throwNotImplemented } from "../shared";
+const { throwNotImplemented } = require("$shared");
function REPLServer() {
throwNotImplemented("node:repl REPLServer");
@@ -18,8 +18,7 @@ function start() {
throwNotImplemented("node:repl");
}
-var repl = {
- [Symbol.for("CommonJS")]: 0,
+export default {
lines: [],
context: globalThis,
historyIndex: -1,
@@ -76,5 +75,3 @@ var repl = {
},
),
};
-
-export { repl as default, repl, REPLServer, Recoverable, REPL_MODE_SLOPPY, REPL_MODE_STRICT, start };
diff --git a/src/js/node/stream.consumers.js b/src/js/node/stream.consumers.js
index 8dbe2920a..4df51d1bf 100644
--- a/src/js/node/stream.consumers.js
+++ b/src/js/node/stream.consumers.js
@@ -1,18 +1,15 @@
// Hardcoded module "node:stream/consumers" / "readable-stream/consumer"
-const { Bun } = $lazy("primordials");
+const arrayBuffer = Bun.readableStreamToArrayBuffer;
+const text = Bun.readableStreamToText;
+const json = stream => Bun.readableStreamToText(stream).then(JSON.parse);
-export const arrayBuffer = Bun.readableStreamToArrayBuffer;
-export const text = Bun.readableStreamToText;
-export const json = stream => Bun.readableStreamToText(stream).then(JSON.parse);
-
-export const buffer = async readableStream => {
+const buffer = async readableStream => {
return new Buffer(await arrayBuffer(readableStream));
};
-export const blob = Bun.readableStreamToBlob;
+const blob = Bun.readableStreamToBlob;
export default {
- [Symbol.for("CommonJS")]: 0,
arrayBuffer,
text,
json,
diff --git a/src/js/node/stream.js b/src/js/node/stream.js
index 1ae0f7fb6..9f5d14bf8 100644
--- a/src/js/node/stream.js
+++ b/src/js/node/stream.js
@@ -1,68 +1,16 @@
// Hardcoded module "node:stream" / "readable-stream"
// "readable-stream" npm package
-// just transpiled
-
-// This must go at the top of the file, before any side effects.
-// IS_BUN_DEVELOPMENT is a bundle-only global variable that is set to true when
-// building a development bundle.
-const __TRACK_EE__ = IS_BUN_DEVELOPMENT && !!process.env.DEBUG_TRACK_EE;
-const __DEBUG__ = IS_BUN_DEVELOPMENT && !!(process.env.DEBUG || process.env.DEBUG_STREAMS || __TRACK_EE__);
-
-if (__DEBUG__) {
- globalThis.__IDS_TO_TRACK = process.env.DEBUG_TRACK_EE?.length
- ? process.env.DEBUG_TRACK_EE.split(",")
- : process.env.DEBUG_STREAMS?.length
- ? process.env.DEBUG_STREAMS.split(",")
- : null;
-}
-
-// Separating DEBUG, DEBUG_STREAMS and DEBUG_TRACK_EE env vars makes it easier to focus on the
-// events in this file rather than all debug output across all files
+// just transpiled and debug logs added.
-// You can include comma-delimited IDs as the value to either DEBUG_STREAMS or DEBUG_TRACK_EE and it will track
-// The events and/or all of the outputs for the given stream IDs assigned at stream construction
-// By default, child_process gives
+const EE = $lazy("events");
+const StringDecoder = require("node:string_decoder").StringDecoder;
-var debug = __DEBUG__
- ? globalThis.__IDS_TO_TRACK
- ? // If we are tracking IDs for debug event emitters, we should prefix the debug output with the ID
- (...args) => {
- const lastItem = args[args.length - 1];
- if (!globalThis.__IDS_TO_TRACK.includes(lastItem)) return;
- console.log(`ID: ${lastItem}`, ...args.slice(0, -1));
- }
- : (...args) => console.log(...args.slice(0, -1))
- : () => {};
-
-var { isPromise, isCallable, direct, Object } = $lazy("primordials");
-import { EventEmitter as EE } from "bun:events_native";
-import { StringDecoder } from "node:string_decoder";
-
-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 __ObjectSetPrototypeOf = Object.setPrototypeOf;
var __commonJS = (cb, mod) =>
function __require2() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
-var __copyProps = (to, from, except, desc) => {
- if ((from && typeof from === "object") || typeof from === "function") {
- for (let key of __getOwnPropNames(from))
- if (!__hasOwnProp.call(to, key) && key !== except)
- __defProp(to, key, {
- get: () => from[key],
- set: val => (from[key] = val),
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
- configurable: true,
- });
- }
- return to;
-};
var runOnNextTick = process.nextTick;
@@ -74,6 +22,8 @@ function validateBoolean(value, name) {
if (typeof value !== "boolean") throw new ERR_INVALID_ARG_TYPE(name, "boolean", value);
}
+$debug("node:stream loaded");
+
/**
* @callback validateObject
* @param {*} value
@@ -2053,6 +2003,7 @@ var require_legacy = __commonJS({
if (!(this instanceof Stream)) return new Stream(options);
EE.call(this, options);
}
+ Stream.prototype = {};
ObjectSetPrototypeOf(Stream.prototype, EE.prototype);
ObjectSetPrototypeOf(Stream, EE);
@@ -2331,6 +2282,7 @@ var require_readable = __commonJS({
}
});
}
+ Readable.prototype = {};
ObjectSetPrototypeOf(Readable.prototype, Stream.prototype);
ObjectSetPrototypeOf(Readable, Stream);
@@ -2340,32 +2292,31 @@ var require_readable = __commonJS({
if (ev === "data") {
state.readableListening = this.listenerCount("readable") > 0;
if (state.flowing !== false) {
- __DEBUG__ && debug("in flowing mode!", this.__id);
+ $debug("in flowing mode!", this.__id);
this.resume();
} else {
- __DEBUG__ && debug("in readable mode!", this.__id);
+ $debug("in readable mode!", this.__id);
}
} else if (ev === "readable") {
- __DEBUG__ && debug("readable listener added!", this.__id);
+ $debug("readable listener added!", this.__id);
if (!state.endEmitted && !state.readableListening) {
state.readableListening = state.needReadable = true;
state.flowing = false;
state.emittedReadable = false;
- __DEBUG__ &&
- debug(
- "on readable - state.length, reading, emittedReadable",
- state.length,
- state.reading,
- state.emittedReadable,
- this.__id,
- );
+ $debug(
+ "on readable - state.length, reading, emittedReadable",
+ state.length,
+ state.reading,
+ state.emittedReadable,
+ this.__id,
+ );
if (state.length) {
emitReadable(this, state);
} else if (!state.reading) {
runOnNextTick(nReadingNextTick, this);
}
} else if (state.endEmitted) {
- __DEBUG__ && debug("end already emitted...", this.__id);
+ $debug("end already emitted...", this.__id);
}
}
return res;
@@ -2421,7 +2372,7 @@ var require_readable = __commonJS({
}
async _read() {
- __DEBUG__ && debug("ReadableFromWeb _read()", this.__id);
+ $debug("ReadableFromWeb _read()", this.__id);
var stream = this.#stream,
reader = this.#reader;
if (stream) {
@@ -2438,7 +2389,7 @@ var require_readable = __commonJS({
value;
const firstResult = reader.readMany();
- if (isPromise(firstResult)) {
+ if ($isPromise(firstResult)) {
({ done, value } = await firstResult);
if (this.#closed) {
@@ -2565,7 +2516,7 @@ var require_readable = __commonJS({
}
// REVERT ME
function emitReadable(stream, state) {
- __DEBUG__ && debug("NativeReadable - emitReadable", stream.__id);
+ $debug("NativeReadable - emitReadable", stream.__id);
_emitReadable(stream, state);
}
var destroyImpl = require_destroy();
@@ -2599,7 +2550,7 @@ var require_readable = __commonJS({
return readableAddChunk(this, chunk, encoding, true);
};
function readableAddChunk(stream, chunk, encoding, addToFront) {
- __DEBUG__ && debug("readableAddChunk", chunk, stream.__id);
+ $debug("readableAddChunk", chunk, stream.__id);
const state = stream._readableState;
let err;
if (!state.objectMode) {
@@ -2655,8 +2606,8 @@ var require_readable = __commonJS({
return !state.ended && (state.length < state.highWaterMark || state.length === 0);
}
function addChunk(stream, state, chunk, addToFront) {
- __DEBUG__ && debug("adding chunk", stream.__id);
- __DEBUG__ && debug("chunk", chunk.toString(), stream.__id);
+ $debug("adding chunk", stream.__id);
+ $debug("chunk", chunk.toString(), stream.__id);
if (state.flowing && state.length === 0 && !state.sync && stream.listenerCount("data") > 0) {
if (state.multiAwaitDrain) {
state.awaitDrainWriters.clear();
@@ -2669,9 +2620,10 @@ var require_readable = __commonJS({
state.length += state.objectMode ? 1 : chunk.length;
if (addToFront) state.buffer.unshift(chunk);
else state.buffer.push(chunk);
- __DEBUG__ && debug("needReadable @ addChunk", state.needReadable, stream.__id);
+ $debug("needReadable @ addChunk", state.needReadable, stream.__id);
if (state.needReadable) emitReadable(stream, state);
}
+ $debug("about to maybereadmore");
maybeReadMore(stream, state);
}
Readable.prototype.isPaused = function () {
@@ -2723,7 +2675,7 @@ var require_readable = __commonJS({
}
// You can override either this method, or the async _read(n) below.
Readable.prototype.read = function (n) {
- __DEBUG__ && debug("read - n =", n, this.__id);
+ $debug("read - n =", n, this.__id);
if (!NumberIsInteger(n)) {
n = NumberParseInt(n, 10);
}
@@ -2743,7 +2695,7 @@ var require_readable = __commonJS({
state.needReadable &&
((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)
) {
- __DEBUG__ && debug("read: emitReadable or endReadable", state.length, state.ended, this.__id);
+ $debug("read: emitReadable or endReadable", state.length, state.ended, this.__id);
if (state.length === 0 && state.ended) endReadable(this);
else emitReadable(this, state);
return null;
@@ -2753,8 +2705,7 @@ var require_readable = __commonJS({
// If we've ended, and we're now clear, then finish it up.
if (n === 0 && state.ended) {
- __DEBUG__ &&
- debug("read: calling endReadable if length 0 -- length, state.ended", state.length, state.ended, this.__id);
+ $debug("read: calling endReadable if length 0 -- length, state.ended", state.length, state.ended, this.__id);
if (state.length === 0) endReadable(this);
return null;
}
@@ -2783,23 +2734,23 @@ var require_readable = __commonJS({
// if we need a readable event, then we need to do some reading.
let doRead = state.needReadable;
- __DEBUG__ && debug("need readable", doRead, this.__id);
+ $debug("need readable", doRead, this.__id);
// If we currently have less than the highWaterMark, then also read some.
if (state.length === 0 || state.length - n < state.highWaterMark) {
doRead = true;
- __DEBUG__ && debug("length less than watermark", doRead, this.__id);
+ $debug("length less than watermark", doRead, this.__id);
}
// However, if we've ended, then there's no point, if we're already
// reading, then it's unnecessary, if we're constructing we have to wait,
// and if we're destroyed or errored, then it's not allowed,
if (state.ended || state.reading || state.destroyed || state.errored || !state.constructed) {
- __DEBUG__ && debug("state.constructed?", state.constructed, this.__id);
+ $debug("state.constructed?", state.constructed, this.__id);
doRead = false;
- __DEBUG__ && debug("reading, ended or constructing", doRead, this.__id);
+ $debug("reading, ended or constructing", doRead, this.__id);
} else if (doRead) {
- __DEBUG__ && debug("do read", this.__id);
+ $debug("do read", this.__id);
state.reading = true;
state.sync = true;
// If the length is currently zero, then we *need* a readable event.
@@ -2808,17 +2759,17 @@ var require_readable = __commonJS({
// Call internal read method
try {
var result = this._read(state.highWaterMark);
- if (isPromise(result)) {
- __DEBUG__ && debug("async _read", this.__id);
+ if ($isPromise(result)) {
+ $debug("async _read", this.__id);
const peeked = Bun.peek(result);
- __DEBUG__ && debug("peeked promise", peeked, this.__id);
+ $debug("peeked promise", peeked, this.__id);
if (peeked !== result) {
result = peeked;
}
}
- if (isPromise(result) && result?.then && isCallable(result.then)) {
- __DEBUG__ && debug("async _read result.then setup", this.__id);
+ if ($isPromise(result) && result?.then && $isCallable(result.then)) {
+ $debug("async _read result.then setup", this.__id);
result.then(nop, function (err) {
errorOrDestroy(this, err);
});
@@ -2833,16 +2784,16 @@ var require_readable = __commonJS({
if (!state.reading) n = howMuchToRead(nOrig, state);
}
- __DEBUG__ && debug("n @ fromList", n, this.__id);
+ $debug("n @ fromList", n, this.__id);
let ret;
if (n > 0) ret = fromList(n, state);
else ret = null;
- __DEBUG__ && debug("ret @ read", ret, this.__id);
+ $debug("ret @ read", ret, this.__id);
if (ret === null) {
state.needReadable = state.length <= state.highWaterMark;
- __DEBUG__ && debug("state.length while ret = null", state.length, this.__id);
+ $debug("state.length while ret = null", state.length, this.__id);
n = 0;
} else {
state.length -= n;
@@ -2882,14 +2833,14 @@ var require_readable = __commonJS({
}
}
state.pipes.push(dest);
- __DEBUG__ && debug("pipe count=%d opts=%j", state.pipes.length, pipeOpts, src.__id);
+ $debug("pipe count=%d opts=%j", state.pipes.length, pipeOpts, src.__id);
const doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
const endFn = doEnd ? onend : unpipe;
if (state.endEmitted) runOnNextTick(endFn);
else src.once("end", endFn);
dest.on("unpipe", onunpipe);
function onunpipe(readable, unpipeInfo) {
- __DEBUG__ && debug("onunpipe", src.__id);
+ $debug("onunpipe", src.__id);
if (readable === src) {
if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
unpipeInfo.hasUnpiped = true;
@@ -2898,13 +2849,13 @@ var require_readable = __commonJS({
}
}
function onend() {
- __DEBUG__ && debug("onend", src.__id);
+ $debug("onend", src.__id);
dest.end();
}
let ondrain;
let cleanedUp = false;
function cleanup() {
- __DEBUG__ && debug("cleanup", src.__id);
+ $debug("cleanup", src.__id);
dest.removeListener("close", onclose);
dest.removeListener("finish", onfinish);
if (ondrain) {
@@ -2921,11 +2872,11 @@ var require_readable = __commonJS({
function pause() {
if (!cleanedUp) {
if (state.pipes.length === 1 && state.pipes[0] === dest) {
- __DEBUG__ && debug("false write response, pause", 0, src.__id);
+ $debug("false write response, pause", 0, src.__id);
state.awaitDrainWriters = dest;
state.multiAwaitDrain = false;
} else if (state.pipes.length > 1 && state.pipes.includes(dest)) {
- __DEBUG__ && debug("false write response, pause", state.awaitDrainWriters.size, src.__id);
+ $debug("false write response, pause", state.awaitDrainWriters.size, src.__id);
state.awaitDrainWriters.add(dest);
}
src.pause();
@@ -2937,15 +2888,15 @@ var require_readable = __commonJS({
}
src.on("data", ondata);
function ondata(chunk) {
- __DEBUG__ && debug("ondata", src.__id);
+ $debug("ondata", src.__id);
const ret = dest.write(chunk);
- __DEBUG__ && debug("dest.write", ret, src.__id);
+ $debug("dest.write", ret, src.__id);
if (ret === false) {
pause();
}
}
function onerror(er) {
- debug("onerror", er);
+ $debug("onerror", er);
unpipe();
dest.removeListener("error", onerror);
if (dest.listenerCount("error") === 0) {
@@ -2964,13 +2915,13 @@ var require_readable = __commonJS({
}
dest.once("close", onclose);
function onfinish() {
- debug("onfinish");
+ $debug("onfinish");
dest.removeListener("close", onclose);
unpipe();
}
dest.once("finish", onfinish);
function unpipe() {
- debug("unpipe");
+ $debug("unpipe");
src.unpipe(dest);
}
dest.emit("pipe", src);
@@ -2979,7 +2930,7 @@ var require_readable = __commonJS({
pause();
}
} else if (!state.flowing) {
- debug("pipe resume");
+ $debug("pipe resume");
src.resume();
}
return dest;
@@ -2988,10 +2939,10 @@ var require_readable = __commonJS({
return function pipeOnDrainFunctionResult() {
const state = src._readableState;
if (state.awaitDrainWriters === dest) {
- debug("pipeOnDrain", 1);
+ $debug("pipeOnDrain", 1);
state.awaitDrainWriters = null;
} else if (state.multiAwaitDrain) {
- debug("pipeOnDrain", state.awaitDrainWriters.size);
+ $debug("pipeOnDrain", state.awaitDrainWriters.size);
state.awaitDrainWriters.delete(dest);
}
if ((!state.awaitDrainWriters || state.awaitDrainWriters.size === 0) && src.listenerCount("data")) {
@@ -3050,13 +3001,13 @@ var require_readable = __commonJS({
}
}
function nReadingNextTick(self) {
- __DEBUG__ && debug("on readable nextTick, calling read(0)", self.__id);
+ $debug("on readable nextTick, calling read(0)", self.__id);
self.read(0);
}
Readable.prototype.resume = function () {
const state = this._readableState;
if (!state.flowing) {
- __DEBUG__ && debug("resume", this.__id);
+ $debug("resume", this.__id);
state.flowing = !state.readableListening;
resume(this, state);
}
@@ -3064,9 +3015,9 @@ var require_readable = __commonJS({
return this;
};
Readable.prototype.pause = function () {
- __DEBUG__ && debug("call pause flowing=%j", this._readableState.flowing, this.__id);
+ $debug("call pause flowing=%j", this._readableState.flowing, this.__id);
if (this._readableState.flowing !== false) {
- __DEBUG__ && debug("pause", this.__id);
+ $debug("pause", this.__id);
this._readableState.flowing = false;
this.emit("pause");
}
@@ -3294,18 +3245,18 @@ var require_readable = __commonJS({
}
function endReadable(stream) {
const state = stream._readableState;
- __DEBUG__ && debug("endEmitted @ endReadable", state.endEmitted, stream.__id);
+ $debug("endEmitted @ endReadable", state.endEmitted, stream.__id);
if (!state.endEmitted) {
state.ended = true;
runOnNextTick(endReadableNT, state, stream);
}
}
function endReadableNT(state, stream) {
- __DEBUG__ && debug("endReadableNT -- endEmitted, state.length", state.endEmitted, state.length, stream.__id);
+ $debug("endReadableNT -- endEmitted, state.length", state.endEmitted, state.length, stream.__id);
if (!state.errored && !state.closeEmitted && !state.endEmitted && state.length === 0) {
state.endEmitted = true;
stream.emit("end");
- __DEBUG__ && debug("end emitted @ endReadableNT", stream.__id);
+ $debug("end emitted @ endReadableNT", stream.__id);
if (stream.writable && stream.allowHalfOpen === false) {
runOnNextTick(endWritableNT, stream);
} else if (state.autoDestroy) {
@@ -3492,6 +3443,7 @@ var require_writable = __commonJS({
finishMaybe(this, state);
});
}
+ Writable.prototype = {};
ObjectSetPrototypeOf(Writable.prototype, Stream.prototype);
ObjectSetPrototypeOf(Writable, Stream);
module.exports = Writable;
@@ -3535,6 +3487,7 @@ var require_writable = __commonJS({
this.closeEmitted = false;
this[kOnFinished] = [];
}
+ WritableState.prototype = {};
function resetBuffer(state) {
state.buffered = [];
state.bufferedIndex = 0;
@@ -3814,7 +3767,7 @@ var require_writable = __commonJS({
Writable.prototype._writev = null;
Writable.prototype.end = function (chunk, encoding, cb, native = false) {
const state = this._writableState;
- __DEBUG__ && debug("end", state, this.__id);
+ $debug("end", state, this.__id);
if (typeof chunk === "function") {
cb = chunk;
chunk = null;
@@ -3871,7 +3824,7 @@ var require_writable = __commonJS({
!state.writing &&
!state.errorEmitted &&
!state.closeEmitted;
- debug("needFinish", needFinish, tag);
+ $debug("needFinish", needFinish, tag);
return needFinish;
}
function callFinal(stream, state) {
@@ -3917,7 +3870,7 @@ var require_writable = __commonJS({
}
}
function finishMaybe(stream, state, sync) {
- __DEBUG__ && debug("finishMaybe -- state, sync", state, sync, stream.__id);
+ $debug("finishMaybe -- state, sync", state, sync, stream.__id);
if (!needFinish(state, stream.__id)) return;
@@ -4454,8 +4407,8 @@ var require_duplex = __commonJS({
this.allowHalfOpen = true;
}
}
+ Duplex.prototype = {};
module.exports = Duplex;
-
ObjectSetPrototypeOf(Duplex.prototype, Readable.prototype);
ObjectSetPrototypeOf(Duplex, Readable);
@@ -4532,6 +4485,7 @@ var require_transform = __commonJS({
this.on("prefinish", prefinish.bind(this));
}
+ Transform.prototype = {};
ObjectSetPrototypeOf(Transform.prototype, Duplex.prototype);
ObjectSetPrototypeOf(Transform, Duplex);
@@ -4618,6 +4572,7 @@ var require_passthrough = __commonJS({
if (!(this instanceof PassThrough)) return new PassThrough(options);
Transform.call(this, options);
}
+ PassThrough.prototype = {};
ObjectSetPrototypeOf(PassThrough.prototype, Transform.prototype);
ObjectSetPrototypeOf(PassThrough, Transform);
@@ -5240,47 +5195,6 @@ var require_stream = __commonJS({
},
});
-// node_modules/readable-stream/lib/ours/index.js
-var require_ours = __commonJS({
- "node_modules/readable-stream/lib/ours/index.js"(exports, module) {
- "use strict";
- const CustomStream = require_stream();
- const promises = require_promises();
- const originalDestroy = CustomStream.Readable.destroy;
- module.exports = CustomStream;
- module.exports._uint8ArrayToBuffer = CustomStream._uint8ArrayToBuffer;
- module.exports._isUint8Array = CustomStream._isUint8Array;
- module.exports.isDisturbed = CustomStream.isDisturbed;
- module.exports.isErrored = CustomStream.isErrored;
- module.exports.isWritable = CustomStream.isWritable;
- module.exports.isReadable = CustomStream.isReadable;
- module.exports.Readable = CustomStream.Readable;
- module.exports.Writable = CustomStream.Writable;
- module.exports.Duplex = CustomStream.Duplex;
- module.exports.Transform = CustomStream.Transform;
- module.exports.PassThrough = CustomStream.PassThrough;
- module.exports.addAbortSignal = CustomStream.addAbortSignal;
- module.exports.finished = CustomStream.finished;
- module.exports.destroy = CustomStream.destroy;
- module.exports.destroy = originalDestroy;
- module.exports.pipeline = CustomStream.pipeline;
- module.exports.compose = CustomStream.compose;
-
- module.exports._getNativeReadableStreamPrototype = getNativeReadableStreamPrototype;
- module.exports.NativeWritable = NativeWritable;
-
- Object.defineProperty(CustomStream, "promises", {
- configurable: true,
- enumerable: true,
- get() {
- return promises;
- },
- });
- module.exports.Stream = CustomStream.Stream;
- module.exports.default = module.exports;
- },
-});
-
/**
* Bun native stream wrapper
*
@@ -5357,21 +5271,21 @@ function createNativeStreamReadable(nativeType, Readable) {
// However, in the case of an fs.ReadStream, we can pass the number of bytes we want to read
// which may be significantly less than the actual highWaterMark
_read(maxToRead) {
- __DEBUG__ && debug("NativeReadable._read", this.__id);
+ $debug("NativeReadable._read", this.__id);
if (this.#pendingRead) {
- __DEBUG__ && debug("pendingRead is true", this.__id);
+ $debug("pendingRead is true", this.__id);
return;
}
var ptr = this.#bunNativePtr;
- __DEBUG__ && debug("ptr @ NativeReadable._read", ptr, this.__id);
+ $debug("ptr @ NativeReadable._read", ptr, this.__id);
if (ptr === 0) {
this.push(null);
return;
}
if (!this.#constructed) {
- __DEBUG__ && debug("NativeReadable not constructed yet", this.__id);
+ $debug("NativeReadable not constructed yet", this.__id);
this.#internalConstruct(ptr);
}
@@ -5398,18 +5312,18 @@ function createNativeStreamReadable(nativeType, Readable) {
#internalConstruct(ptr) {
this.#constructed = true;
const result = start(ptr, this.#highWaterMark);
- __DEBUG__ && debug("NativeReadable internal `start` result", result, this.__id);
+ $debug("NativeReadable internal `start` result", result, this.__id);
if (typeof result === "number" && result > 1) {
this.#hasResized = true;
- __DEBUG__ && debug("NativeReadable resized", this.__id);
+ $debug("NativeReadable resized", this.__id);
this.#highWaterMark = Math.min(this.#highWaterMark, result);
}
if (drainFn) {
const drainResult = drainFn(ptr);
- __DEBUG__ && debug("NativeReadable drain result", drainResult, this.__id);
+ $debug("NativeReadable drain result", drainResult, this.__id);
if ((drainResult?.byteLength ?? 0) > 0) {
this.push(drainResult);
}
@@ -5421,7 +5335,7 @@ function createNativeStreamReadable(nativeType, Readable) {
// how many bytes they want to read (ie. when reading only part of a file)
#getRemainingChunk(maxToRead = this.#highWaterMark) {
var chunk = this.#remainingChunk;
- __DEBUG__ && debug("chunk @ #getRemainingChunk", chunk, this.__id);
+ $debug("chunk @ #getRemainingChunk", chunk, this.__id);
if (chunk?.byteLength ?? 0 < MIN_BUFFER_SIZE) {
var size = maxToRead > MIN_BUFFER_SIZE ? maxToRead : MIN_BUFFER_SIZE;
this.#remainingChunk = chunk = new Buffer(size);
@@ -5430,12 +5344,12 @@ function createNativeStreamReadable(nativeType, Readable) {
}
// push(result, encoding) {
- // __DEBUG__ && debug("NativeReadable push -- result, encoding", result, encoding, this.__id);
+ // debug("NativeReadable push -- result, encoding", result, encoding, this.__id);
// return super.push(...arguments);
// }
#handleResult(result, view, isClosed) {
- __DEBUG__ && debug("result, isClosed @ #handleResult", result, isClosed, this.__id);
+ $debug("result, isClosed @ #handleResult", result, isClosed, this.__id);
if (typeof result === "number") {
if (result >= this.#highWaterMark && !this.#hasResized && !isClosed) {
@@ -5453,30 +5367,30 @@ function createNativeStreamReadable(nativeType, Readable) {
if (result.byteLength >= this.#highWaterMark && !this.#hasResized && !isClosed) {
this.#highWaterMark *= 2;
this.#hasResized = true;
- __DEBUG__ && debug("Resized", this.__id);
+ $debug("Resized", this.__id);
}
return handleArrayBufferViewResult(this, result, view, isClosed);
} else {
- __DEBUG__ && debug("Unknown result type", result, this.__id);
+ $debug("Unknown result type", result, this.__id);
throw new Error("Invalid result from pull");
}
}
#internalRead(view, ptr) {
- __DEBUG__ && debug("#internalRead()", this.__id);
+ $debug("#internalRead()", this.__id);
closer[0] = false;
var result = pull(ptr, view, closer);
- if (isPromise(result)) {
+ if ($isPromise(result)) {
this.#pendingRead = true;
return result.then(
result => {
this.#pendingRead = false;
- __DEBUG__ && debug("pending no longerrrrrrrr (result returned from pull)", this.__id);
+ $debug("pending no longerrrrrrrr (result returned from pull)", this.__id);
this.#remainingChunk = this.#handleResult(result, view, closer[0]);
},
reason => {
- __DEBUG__ && debug("error from pull", reason, this.__id);
+ $debug("error from pull", reason, this.__id);
errorOrDestroy(this, reason);
},
);
@@ -5497,7 +5411,7 @@ function createNativeStreamReadable(nativeType, Readable) {
if (updateRef) {
updateRef(ptr, false);
}
- __DEBUG__ && debug("NativeReadable destroyed", this.__id);
+ $debug("NativeReadable destroyed", this.__id);
cancel(ptr, error);
callback(error);
}
@@ -5544,9 +5458,9 @@ function getNativeReadableStream(Readable, stream, options) {
return undefined;
}
- const native = direct(stream);
+ const native = $direct(stream);
if (!native) {
- debug("no native readable stream");
+ $debug("no native readable stream");
return undefined;
}
const { stream: ptr, data: type } = native;
@@ -5611,7 +5525,7 @@ var NativeWritable = class NativeWritable extends Writable {
var fileSink = this.#fileSink;
var result = fileSink.write(chunk);
- if (isPromise(result)) {
+ if ($isPromise(result)) {
// var writePromises = this.#writePromises;
// var i = writePromises.length;
// writePromises[i] = result;
@@ -5658,28 +5572,19 @@ var NativeWritable = class NativeWritable extends Writable {
}
};
-const stream_exports = require_ours();
-stream_exports[Symbol.for("CommonJS")] = 0;
-stream_exports[Symbol.for("::bunternal::")] = { _ReadableFromWeb, _ReadableFromWebForUndici };
-export default stream_exports;
-export var _uint8ArrayToBuffer = stream_exports._uint8ArrayToBuffer;
-export var _isUint8Array = stream_exports._isUint8Array;
-export var isDisturbed = stream_exports.isDisturbed;
-export var isErrored = stream_exports.isErrored;
-export var isWritable = stream_exports.isWritable;
-export var isReadable = stream_exports.isReadable;
-export var Readable = stream_exports.Readable;
-export var Writable = stream_exports.Writable;
-export var Duplex = stream_exports.Duplex;
-export var Transform = stream_exports.Transform;
-export var PassThrough = stream_exports.PassThrough;
-export var addAbortSignal = stream_exports.addAbortSignal;
-export var finished = stream_exports.finished;
-export var destroy = stream_exports.destroy;
-export var pipeline = stream_exports.pipeline;
-export var compose = stream_exports.compose;
-export var Stream = stream_exports.Stream;
-export var eos = (stream_exports["eos"] = require_end_of_stream);
-export var _getNativeReadableStreamPrototype = stream_exports._getNativeReadableStreamPrototype;
-export var NativeWritable = stream_exports.NativeWritable;
-export var promises = Stream.promises;
+const exports = require_stream();
+const promises = require_promises();
+exports._getNativeReadableStreamPrototype = getNativeReadableStreamPrototype;
+exports.NativeWritable = NativeWritable;
+Object.defineProperty(exports, "promises", {
+ configurable: true,
+ enumerable: true,
+ get() {
+ return promises;
+ },
+});
+
+exports[Symbol.for("::bunternal::")] = { _ReadableFromWeb, _ReadableFromWebForUndici };
+exports.eos = require_end_of_stream();
+
+export default exports;
diff --git a/src/js/node/stream.promises.js b/src/js/node/stream.promises.js
deleted file mode 100644
index 323785a4c..000000000
--- a/src/js/node/stream.promises.js
+++ /dev/null
@@ -1,10 +0,0 @@
-// Hardcoded module "node:stream/promises"
-import { promises } from "node:stream";
-
-export var { pipeline, finished } = promises;
-
-export default {
- pipeline,
- finished,
- [Symbol.for("CommonJS")]: 0,
-};
diff --git a/src/js/node/stream.promises.ts b/src/js/node/stream.promises.ts
new file mode 100644
index 000000000..04aaf0b0c
--- /dev/null
+++ b/src/js/node/stream.promises.ts
@@ -0,0 +1,2 @@
+// Hardcoded module "node:stream/promises"
+export default require("node:stream").promises;
diff --git a/src/js/node/stream.web.js b/src/js/node/stream.web.js
index b7b947af9..ab3458d2d 100644
--- a/src/js/node/stream.web.js
+++ b/src/js/node/stream.web.js
@@ -1,23 +1,4 @@
// Hardcoded module "node:stream/web" / "readable-stream/web"
-export const {
- ReadableStream,
- ReadableStreamDefaultReader,
- ReadableStreamBYOBReader,
- ReadableStreamBYOBRequest,
- ReadableByteStreamController,
- ReadableStreamDefaultController,
- TransformStream,
- TransformStreamDefaultController,
- WritableStream,
- WritableStreamDefaultWriter,
- WritableStreamDefaultController,
- ByteLengthQueuingStrategy,
- CountQueuingStrategy,
- TextEncoderStream,
- TextDecoderStream,
- CompressionStream,
- DecompressionStream,
-} = globalThis;
export default {
ReadableStream,
ReadableStreamDefaultReader,
@@ -32,9 +13,8 @@ export default {
WritableStreamDefaultController,
ByteLengthQueuingStrategy,
CountQueuingStrategy,
- TextEncoderStream,
- TextDecoderStream,
- CompressionStream,
- DecompressionStream,
- [Symbol.for("CommonJS")]: 0,
+ // TextEncoderStream,
+ // TextDecoderStream,
+ // CompressionStream,
+ // DecompressionStream,
};
diff --git a/src/js/node/timers.js b/src/js/node/timers.js
index 4e907a7ab..221fa181a 100644
--- a/src/js/node/timers.js
+++ b/src/js/node/timers.js
@@ -1,14 +1,11 @@
// Hardcoded module "node:timers"
// This implementation isn't 100% correct
// Ref/unref does not impact whether the process is kept alive
-
-export var { setTimeout, clearTimeout, setInterval, setImmediate, clearInterval, clearImmediate } = globalThis;
-
export default {
+ setTimeout,
+ clearTimeout,
setInterval,
setImmediate,
- setTimeout,
clearInterval,
- clearTimeout,
- [Symbol.for("CommonJS")]: 0,
+ clearImmediate,
};
diff --git a/src/js/node/timers.promises.js b/src/js/node/timers.promises.js
index 3e2e7bcd5..eb171941a 100644
--- a/src/js/node/timers.promises.js
+++ b/src/js/node/timers.promises.js
@@ -232,5 +232,12 @@ function setIntervalPromise(after = 1, value, options = {}) {
}
}
-export { setTimeoutPromise as setTimeout, setImmediatePromise as setImmediate, setIntervalPromise as setInterval };
-export default { setTimeout: setTimeoutPromise, setImmediate: setImmediatePromise, setInterval: setIntervalPromise };
+export default {
+ setTimeout: setTimeoutPromise,
+ setImmediate: setImmediatePromise,
+ setInterval: setIntervalPromise,
+ scheduler: {
+ wait: (delay, options) => setTimeoutPromise(delay, undefined, options),
+ yield: setImmediatePromise,
+ },
+};
diff --git a/src/js/node/tls.js b/src/js/node/tls.js
index 567baddc1..fc2d9065a 100644
--- a/src/js/node/tls.js
+++ b/src/js/node/tls.js
@@ -1,11 +1,8 @@
// Hardcoded module "node:tls"
-import { isArrayBufferView, isTypedArray } from "util/types";
-import net, { Server as NetServer } from "node:net";
-const InternalTCPSocket = net[Symbol.for("::bunternal::")];
+const { isArrayBufferView, isTypedArray } = require("node:util/types");
+const net = require("node:net");
+const { Server: NetServer, [Symbol.for("::bunternal::")]: InternalTCPSocket } = net;
const bunSocketInternal = Symbol.for("::bunnetsocketinternal::");
-
-const { RegExp, Array, String } = $lazy("primordials");
-
const { rootCertificates, canonicalizeIP } = $lazy("internal/tls");
const SymbolReplace = Symbol.replace;
@@ -628,10 +625,6 @@ function getCiphers() {
return DEFAULT_CIPHERS.split(":");
}
-function getCurves() {
- return;
-}
-
// Convert protocols array into valid OpenSSL protocols list
// ("\x06spdy/2\x08http/1.1\x08http/1.0")
function convertProtocols(protocols) {
@@ -682,8 +675,7 @@ function convertALPNProtocols(protocols, out) {
}
}
-var exports = {
- [Symbol.for("CommonJS")]: 0,
+export default {
CLIENT_RENEG_LIMIT,
CLIENT_RENEG_WINDOW,
connect,
@@ -696,7 +688,6 @@ var exports = {
DEFAULT_MAX_VERSION,
DEFAULT_MIN_VERSION,
getCiphers,
- getCurves,
parseCertString,
SecureContext,
Server,
@@ -704,26 +695,3 @@ var exports = {
checkServerIdentity,
rootCertificates,
};
-
-export {
- CLIENT_RENEG_LIMIT,
- CLIENT_RENEG_WINDOW,
- connect,
- convertALPNProtocols,
- createConnection,
- createSecureContext,
- createServer,
- DEFAULT_CIPHERS,
- DEFAULT_ECDH_CURVE,
- DEFAULT_MAX_VERSION,
- DEFAULT_MIN_VERSION,
- getCiphers,
- getCurves,
- parseCertString,
- SecureContext,
- checkServerIdentity,
- Server,
- TLSSocket,
- rootCertificates,
- exports as default,
-};
diff --git a/src/js/node/trace_events.ts b/src/js/node/trace_events.ts
index 7edcc57d0..e0cb82f34 100644
--- a/src/js/node/trace_events.ts
+++ b/src/js/node/trace_events.ts
@@ -26,10 +26,7 @@ function getEnabledCategories() {
return "";
}
-var defaultObject = {
+export default {
createTracing,
getEnabledCategories,
- [Symbol.for("CommonJS")]: 0,
};
-
-export { defaultObject as default, createTracing, getEnabledCategories };
diff --git a/src/js/node/url.js b/src/js/node/url.js
index 927543405..3b6b57ac2 100644
--- a/src/js/node/url.js
+++ b/src/js/node/url.js
@@ -39,6 +39,7 @@ function Url() {
this.path = null;
this.href = null;
}
+Url.prototype = {};
// Reference: RFC 3986, RFC 1808, RFC 2396
@@ -820,10 +821,10 @@ function urlToHttpOptions(url) {
return options;
}
-const lazy = $lazy;
-const pathToFileURL = lazy("pathToFileURL");
-const fileURLToPath = lazy("fileURLToPath");
-const defaultObject = {
+const pathToFileURL = $lazy("pathToFileURL");
+const fileURLToPath = $lazy("fileURLToPath");
+
+export default {
parse: urlParse,
resolve: urlResolve,
resolveObject: urlResolveObject,
@@ -834,19 +835,4 @@ const defaultObject = {
pathToFileURL,
fileURLToPath,
urlToHttpOptions,
- [Symbol.for("CommonJS")]: 0,
-};
-
-export {
- defaultObject as default,
- urlParse as parse,
- urlResolve as resolve,
- urlResolveObject as resolveObject,
- urlFormat as format,
- Url,
- URLSearchParams,
- URL,
- pathToFileURL,
- fileURLToPath,
- urlToHttpOptions,
};
diff --git a/src/js/node/util.js b/src/js/node/util.js
index 2ec4aadb9..92d77701e 100644
--- a/src/js/node/util.js
+++ b/src/js/node/util.js
@@ -1,22 +1,13 @@
// Hardcoded module "node:util"
-import * as types from "node:util/types";
-export { default as types } from "node:util/types";
+const types = require("node:util/types");
var cjs_exports = {};
-export default cjs_exports;
-
-var __getOwnPropNames = Object.getOwnPropertyNames;
-var __commonJS = (cb, mod) =>
- function __require() {
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
- };
-
function isBufferInterface({ copy, fill, readUint8 }) {
return typeof copy === "function" && typeof fill === "function" && typeof readUint8 === "function";
}
-export function isBuffer(value) {
+function isBuffer(value) {
return (
Buffer.isBuffer(value) ||
// incase it ends up as a browserify buffer
@@ -28,22 +19,6 @@ function isFunction(value) {
return typeof value === "function";
}
-// node_modules/inherits/inherits_browser.js
-var require_inherits_browser = __commonJS({
- "node_modules/inherits/inherits_browser.js"(exports, module2) {
- module2.exports = function inherits(ctor, superCtor) {
- ctor.super_ = superCtor;
- ctor.prototype = Object.create(superCtor.prototype, {
- constructor: {
- value: ctor,
- enumerable: false,
- writable: true,
- configurable: true,
- },
- });
- };
- },
-});
const deepEquals = Bun.deepEquals;
const isDeepStrictEqual = (a, b) => deepEquals(a, b, true);
var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;
@@ -244,7 +219,7 @@ function formatValue(ctx, value, recurseTimes) {
var base = "",
array = false,
braces = ["{", "}"];
- if (isArray(value)) {
+ if ($isArray(value)) {
array = true;
braces = ["[", "]"];
}
@@ -393,10 +368,6 @@ function reduceToSingleString(output, base, braces) {
return braces[0] + base + " " + output.join(", ") + " " + braces[1];
}
-function isArray(ar) {
- return Array.isArray(ar);
-}
-
function isBoolean(arg) {
return typeof arg === "boolean";
}
@@ -416,6 +387,7 @@ function isNumber(arg) {
function isString(arg) {
return typeof arg === "string";
}
+
function isSymbol(arg) {
return typeof arg === "symbol";
}
@@ -450,7 +422,17 @@ function timestamp() {
var log = function log() {
console.log("%s - %s", timestamp(), format.apply(cjs_exports, arguments));
};
-var inherits = (inherits = require_inherits_browser());
+var inherits = function inherits(ctor, superCtor) {
+ ctor.super_ = superCtor;
+ ctor.prototype = Object.create(superCtor.prototype, {
+ constructor: {
+ value: ctor,
+ enumerable: false,
+ writable: true,
+ configurable: true,
+ },
+ });
+};
var _extend = function (origin, add) {
if (!add || !isObject(add)) return origin;
var keys = Object.keys(add);
@@ -550,20 +532,18 @@ function callbackify(original) {
Object.defineProperties(callbackified, getOwnPropertyDescriptors(original));
return callbackified;
}
-export var TextDecoder = globalThis.TextDecoder;
-export var TextEncoder = globalThis.TextEncoder;
var toUSVString = input => {
return (input + "").toWellFormed();
};
-Object.assign(cjs_exports, {
+export default Object.assign(cjs_exports, {
format,
deprecate,
debuglog,
_extend,
inspect,
types,
- isArray,
+ isArray: $isArray,
isBoolean,
isNull,
isNullOrUndefined,
@@ -586,32 +566,4 @@ Object.assign(cjs_exports, {
isDeepStrictEqual,
TextDecoder,
TextEncoder,
- [Symbol.for("CommonJS")]: 0,
});
-
-export {
- format,
- deprecate,
- debuglog,
- inspect,
- isArray,
- isBoolean,
- isNull,
- isNullOrUndefined,
- isNumber,
- isString,
- isSymbol,
- isUndefined,
- isRegExp,
- isObject,
- isDate,
- isError,
- isFunction,
- isPrimitive,
- log,
- inherits,
- promisify,
- callbackify,
- isDeepStrictEqual,
- toUSVString,
-};
diff --git a/src/js/node/v8.ts b/src/js/node/v8.ts
index b043e10fe..f74422de8 100644
--- a/src/js/node/v8.ts
+++ b/src/js/node/v8.ts
@@ -1,7 +1,7 @@
// Hardcoded module "node:v8"
// This is a stub! None of this is actually implemented yet.
-import { hideFromStack, throwNotImplemented } from "../shared";
-import { serialize as jscSerialize, deserialize as jscDeserialize } from "bun:jsc";
+const { hideFromStack, throwNotImplemented } = require("$shared");
+const jsc = require("bun:jsc");
function notimpl(message) {
throwNotImplemented("node:v8 " + message);
@@ -44,7 +44,7 @@ function setFlagsFromString() {
notimpl("setFlagsFromString");
}
function deserialize(value) {
- return jscDeserialize(value);
+ return jsc.deserialize(value);
}
function takeCoverage() {
notimpl("takeCoverage");
@@ -53,7 +53,7 @@ function stopCoverage() {
notimpl("stopCoverage");
}
function serialize(arg1) {
- return jscSerialize(arg1, { binaryType: "nodebuffer" });
+ return jsc.serialize(arg1, { binaryType: "nodebuffer" });
}
function writeHeapSnapshot() {
notimpl("writeHeapSnapshot");
@@ -85,7 +85,7 @@ const promiseHooks = {
isBuildingSnapshot: () => notimpl("isBuildingSnapshot"),
};
-const defaultObject = {
+export default {
cachedDataVersionTag,
getHeapSnapshot,
getHeapStatistics,
@@ -102,30 +102,6 @@ const defaultObject = {
startupSnapshot,
Deserializer,
Serializer,
- [Symbol.for("CommonJS")]: 0,
-};
-
-export {
- cachedDataVersionTag,
- getHeapSnapshot,
- getHeapStatistics,
- getHeapSpaceStatistics,
- getHeapCodeStatistics,
- setFlagsFromString,
- deserialize,
- takeCoverage,
- stopCoverage,
- serialize,
- writeHeapSnapshot,
- setHeapSnapshotNearHeapLimit,
- promiseHooks,
- startupSnapshot,
- Deserializer,
- Serializer,
- DefaultDeserializer,
- DefaultSerializer,
- GCProfiler,
- defaultObject as default,
};
hideFromStack(
diff --git a/src/js/node/vm.ts b/src/js/node/vm.ts
index 331f4fbc6..e3058780a 100644
--- a/src/js/node/vm.ts
+++ b/src/js/node/vm.ts
@@ -1,5 +1,5 @@
// Hardcoded module "node:vm"
-import { throwNotImplemented } from "../shared";
+const { throwNotImplemented } = require("$shared");
const vm = $lazy("vm");
@@ -10,26 +10,31 @@ function runInContext(code, context, options) {
}
function compileFunction() {
- throwNotImplemented("node:vm compileFunction", 401);
+ throwNotImplemented("node:vm compileFunction");
}
function measureMemory() {
- throwNotImplemented("node:vm measureMemory", 401);
+ throwNotImplemented("node:vm measureMemory");
}
-const defaultObject = {
- createContext,
- runInContext,
- runInNewContext,
- runInThisContext,
- isContext,
- compileFunction,
- measureMemory,
- Script,
- [Symbol.for("CommonJS")]: 0,
-};
+class Module {
+ constructor() {
+ throwNotImplemented("node:vm Module");
+ }
+}
+
+class SourceTextModule {
+ constructor() {
+ throwNotImplemented("node:vm Module");
+ }
+}
+
+class SyntheticModule {
+ constructor() {
+ throwNotImplemented("node:vm Module");
+ }
+}
-export {
- defaultObject as default,
+export default {
createContext,
runInContext,
runInNewContext,
@@ -38,4 +43,7 @@ export {
compileFunction,
measureMemory,
Script,
+ Module,
+ SourceTextModule,
+ SyntheticModule,
};
diff --git a/src/js/node/wasi.js b/src/js/node/wasi.js
index ea693585a..c8b051cd3 100644
--- a/src/js/node/wasi.js
+++ b/src/js/node/wasi.js
@@ -8,7 +8,7 @@
/** **/
// constants is injected into the top of this file
-const nodeFsConstants = constants;
+const nodeFsConstants = $processBindingConstants.fs;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -769,9 +769,9 @@ var require_wasi = __commonJS({
process.kill(process.pid, signal);
},
randomFillSync: array => crypto.getRandomValues(array),
- isTTY: fd => import.meta.require("node:tty").isatty(fd),
+ isTTY: fd => require("node:tty").isatty(fd),
fs: Bun.fs(),
- path: import.meta.require("node:path"),
+ path: require("node:path"),
};
return (defaultConfig = {
@@ -1936,8 +1936,4 @@ var require_wasi = __commonJS({
exports.default = WASI;
},
});
-const WASIExport = require_wasi();
-const WASI = WASIExport.default;
-WASIExport[Symbol.for("CommonJS")] = 0;
-export { WASIExport as WASI };
-export default WASIExport;
+export default { WASI: require_wasi().default };
diff --git a/src/js/node/worker_threads.ts b/src/js/node/worker_threads.ts
new file mode 100644
index 000000000..2db3a9446
--- /dev/null
+++ b/src/js/node/worker_threads.ts
@@ -0,0 +1 @@
+export default $lazy("masqueradesAsUndefined");
diff --git a/src/js/node/zlib.js b/src/js/node/zlib.js
index 77a9e8089..9fb9633b9 100644
--- a/src/js/node/zlib.js
+++ b/src/js/node/zlib.js
@@ -3,76 +3,17 @@
// This is a very slow module!
// It should really be fixed. It will show up in benchmarking. It also loads
// slowly. We need to fix it!
-import { default as assert } from "node:assert";
-import * as AssertModule from "node:assert";
-import * as BufferModule from "node:buffer";
-import * as StreamModule from "node:stream";
-import * as Util from "node:util";
+const assert = require("node:assert");
+const BufferModule = require("node:buffer");
+const StreamModule = require("node:stream");
+const Util = require("node:util");
-export var Deflate,
- Inflate,
- Gzip,
- Gunzip,
- DeflateRaw,
- InflateRaw,
- Unzip,
- createDeflate,
- createInflate,
- createDeflateRaw,
- createInflateRaw,
- createGzip,
- createGunzip,
- createUnzip,
- deflate,
- deflateSync,
- gzip,
- gzipSync,
- deflateRaw,
- deflateRawSync,
- unzip,
- unzipSync,
- inflate,
- inflateSync,
- gunzip,
- gunzipSync,
- inflateRaw,
- inflateRawSync,
- constants;
-
-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 __commonJS = (cb, mod) =>
function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
-var __copyProps = (to, from, except, desc) => {
- if ((from && typeof from === "object") || typeof from === "function") {
- for (let key of __getOwnPropNames(from))
- if (!__hasOwnProp.call(to, key) && key !== except)
- __defProp(to, key, {
- get: () => from[key],
- enumerable: !(desc = __getOwnPropDesc(from, key)) || 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/pako/lib/zlib/zstream.js
var require_zstream = __commonJS({
"node_modules/pako/lib/zlib/zstream.js"(exports, module2) {
@@ -3662,6 +3603,7 @@ var require_binding = __commonJS({
this.pending_close = false;
this.gzip_id_bytes_read = 0;
}
+ Zlib.prototype = {};
Zlib.prototype.close = function () {
if (this.write_in_progress) {
this.pending_close = true;
@@ -3974,7 +3916,6 @@ var require_lib = __commonJS({
var Transform = StreamModule.Transform;
var binding = require_binding();
var util = Util;
- var assert = AssertModule.ok;
var kMaxLength = BufferModule.kMaxLength;
var kRangeErrorMessage =
"Cannot create final Buffer. It would be larger than 0x" + kMaxLength.toString(16) + " bytes";
@@ -4468,37 +4409,4 @@ var require_lib = __commonJS({
});
// zlib.js
-var zlib_exports = require_lib();
-zlib_exports[Symbol.for("CommonJS")] = 0;
-
-export default zlib_exports;
-
-Deflate = zlib_exports.Deflate;
-Inflate = zlib_exports.Inflate;
-Gzip = zlib_exports.Gzip;
-Gunzip = zlib_exports.Gunzip;
-DeflateRaw = zlib_exports.DeflateRaw;
-InflateRaw = zlib_exports.InflateRaw;
-Unzip = zlib_exports.Unzip;
-createDeflate = zlib_exports.createDeflate;
-createInflate = zlib_exports.createInflate;
-createDeflateRaw = zlib_exports.createDeflateRaw;
-createInflateRaw = zlib_exports.createInflateRaw;
-createGzip = zlib_exports.createGzip;
-createGunzip = zlib_exports.createGunzip;
-createUnzip = zlib_exports.createUnzip;
-deflate = zlib_exports.deflate;
-deflateSync = zlib_exports.deflateSync;
-gzip = zlib_exports.gzip;
-gzipSync = zlib_exports.gzipSync;
-deflateRaw = zlib_exports.deflateRaw;
-deflateRawSync = zlib_exports.deflateRawSync;
-unzip = zlib_exports.unzip;
-unzipSync = zlib_exports.unzipSync;
-inflate = zlib_exports.inflate;
-inflateSync = zlib_exports.inflateSync;
-gunzip = zlib_exports.gunzip;
-gunzipSync = zlib_exports.gunzipSync;
-inflateRaw = zlib_exports.inflateRaw;
-inflateRawSync = zlib_exports.inflateRawSync;
-constants = zlib_exports.constants;
+export default require_lib();