UNPKG

151 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3 typeof define === 'function' && define.amd ? define(['exports'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.polkadotUtil = {}));
5})(this, (function (exports) { 'use strict';
6
7 const global = window;
8
9 const packageInfo$5 = {
10 name: '@polkadot/util',
11 path: (({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('bundle-polkadot-util.js', document.baseURI).href)) }) && (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('bundle-polkadot-util.js', document.baseURI).href))) ? new URL((typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('bundle-polkadot-util.js', document.baseURI).href))).pathname.substring(0, new URL((typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('bundle-polkadot-util.js', document.baseURI).href))).pathname.lastIndexOf('/') + 1) : 'auto',
12 type: 'esm',
13 version: '9.6.2'
14 };
15
16 function arrayChunk(array, chunkSize) {
17 const outputSize = Math.ceil(array.length / chunkSize);
18 if (outputSize === 1) {
19 return [array];
20 }
21 const output = Array(outputSize);
22 for (let i = 0; i < outputSize; i++) {
23 const offset = i * chunkSize;
24 output[i] = array.slice(offset, offset + chunkSize);
25 }
26 return output;
27 }
28
29 function arrayFilter(array, allowNulls = true) {
30 return array.filter(v => v !== undefined && (allowNulls || v !== null));
31 }
32
33 function arrayFlatten(arrays) {
34 if (arrays.length === 1) {
35 return arrays[0];
36 }
37 let size = 0;
38 for (let i = 0; i < arrays.length; i++) {
39 size += arrays[i].length;
40 }
41 const output = new Array(size);
42 let i = -1;
43 for (let j = 0; j < arrays.length; j++) {
44 const a = arrays[j];
45 for (let e = 0; e < a.length; e++) {
46 output[++i] = a[e];
47 }
48 }
49 return output;
50 }
51
52 function arrayRange(size, startAt = 0) {
53 if (size <= 0) {
54 throw new Error('Expected non-zero, positive number as a range size');
55 }
56 const result = new Array(size);
57 for (let i = 0; i < size; i++) {
58 result[i] = i + startAt;
59 }
60 return result;
61 }
62
63 function arrayShuffle(input) {
64 const result = input.slice();
65 let curr = result.length;
66 if (curr === 1) {
67 return result;
68 }
69 while (curr !== 0) {
70 const rand = ~~(Math.random() * curr);
71 curr--;
72 [result[curr], result[rand]] = [result[rand], result[curr]];
73 }
74 return result;
75 }
76
77 function arrayZip(keys, values) {
78 const result = new Array(keys.length);
79 for (let i = 0; i < keys.length; i++) {
80 result[i] = [keys[i], values[i]];
81 }
82 return result;
83 }
84
85 function isFunction(value) {
86 return typeof value === 'function';
87 }
88
89 function assert(condition, message) {
90 if (!condition) {
91 throw new Error(isFunction(message) ? message() : message);
92 }
93 }
94 function assertReturn(value, message) {
95 assert(value !== undefined && value !== null, message);
96 return value;
97 }
98 function assertUnreachable(x) {
99 throw new Error(`This codepath should be unreachable. Unhandled input: ${x}`);
100 }
101
102 const packageInfo$4 = {
103 name: '@polkadot/x-global',
104 path: (({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('bundle-polkadot-util.js', document.baseURI).href)) }) && (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('bundle-polkadot-util.js', document.baseURI).href))) ? new URL((typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('bundle-polkadot-util.js', document.baseURI).href))).pathname.substring(0, new URL((typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('bundle-polkadot-util.js', document.baseURI).href))).pathname.lastIndexOf('/') + 1) : 'auto',
105 type: 'esm',
106 version: '9.6.2'
107 };
108
109 function evaluateThis(fn) {
110 return fn('return this');
111 }
112 const xglobal = typeof globalThis !== 'undefined' ? globalThis : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : evaluateThis(Function);
113 function extractGlobal(name, fallback) {
114 return typeof xglobal[name] === 'undefined' ? fallback : xglobal[name];
115 }
116 function exposeGlobal(name, fallback) {
117 if (typeof xglobal[name] === 'undefined') {
118 xglobal[name] = fallback;
119 }
120 }
121
122 const build = /*#__PURE__*/Object.freeze({
123 __proto__: null,
124 xglobal: xglobal,
125 extractGlobal: extractGlobal,
126 exposeGlobal: exposeGlobal,
127 packageInfo: packageInfo$4
128 });
129
130 ({
131 name: '@polkadot/x-bigint',
132 path: (({ url: (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('bundle-polkadot-util.js', document.baseURI).href)) }) && (typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('bundle-polkadot-util.js', document.baseURI).href))) ? new URL((typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('bundle-polkadot-util.js', document.baseURI).href))).pathname.substring(0, new URL((typeof document === 'undefined' && typeof location === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : typeof document === 'undefined' ? location.href : (document.currentScript && document.currentScript.src || new URL('bundle-polkadot-util.js', document.baseURI).href))).pathname.lastIndexOf('/') + 1) : 'auto',
133 type: 'esm',
134 version: '9.6.2'
135 });
136
137 const BigInt = typeof xglobal.BigInt === 'function' && typeof xglobal.BigInt.asIntN === 'function' ? xglobal.BigInt : () => Number.NaN;
138
139 const _0n = BigInt(0);
140 const _1n = BigInt(1);
141 const _1Mn = BigInt(1000000);
142 const _1Bn = BigInt(1000000000);
143 const _1Qn = _1Bn * _1Bn;
144 const _2pow53n = BigInt(Number.MAX_SAFE_INTEGER);
145
146 function objectSpread(dest, ...sources) {
147 for (let i = 0; i < sources.length; i++) {
148 const src = sources[i];
149 if (src) {
150 Object.assign(dest, src);
151 }
152 }
153 return dest;
154 }
155
156 const U8_MAX = BigInt(256);
157 const U16_MAX = BigInt(256 * 256);
158 function u8aToBigInt(value, {
159 isLe = true,
160 isNegative = false
161 } = {}) {
162 if (!value || !value.length) {
163 return BigInt(0);
164 }
165 const u8a = isLe ? value : value.reverse();
166 const dvI = new DataView(u8a.buffer, u8a.byteOffset);
167 const mod = u8a.length % 2;
168 let result = BigInt(0);
169 if (isNegative) {
170 for (let i = u8a.length - 2; i >= mod; i -= 2) {
171 result = result * U16_MAX + BigInt(dvI.getUint16(i, true) ^ 0xffff);
172 }
173 if (mod) {
174 result = result * U8_MAX + BigInt(dvI.getUint8(0) ^ 0xff);
175 }
176 } else {
177 for (let i = u8a.length - 2; i >= mod; i -= 2) {
178 result = result * U16_MAX + BigInt(dvI.getUint16(i, true));
179 }
180 if (mod) {
181 result = result * U8_MAX + BigInt(dvI.getUint8(0));
182 }
183 }
184 return isNegative ? result * -_1n - _1n : result;
185 }
186
187 const REGEX_HEX_PREFIXED = /^0x[\da-fA-F]+$/;
188 const REGEX_HEX_NOPREFIX = /^[\da-fA-F]+$/;
189 function isHex(value, bitLength = -1, ignoreLength) {
190 return typeof value === 'string' && (value === '0x' || REGEX_HEX_PREFIXED.test(value)) && (bitLength === -1 ? ignoreLength || value.length % 2 === 0 : value.length === 2 + Math.ceil(bitLength / 4));
191 }
192
193 const CHARS = '0123456789abcdef';
194 const UNHEX = new Array(256);
195 for (let i = 0; i < CHARS.length; i++) {
196 UNHEX[CHARS[i].charCodeAt(0)] = i;
197 if (i > 9) {
198 UNHEX[CHARS[i].toUpperCase().charCodeAt(0)] = i;
199 }
200 }
201 function hexToU8a(value, bitLength = -1) {
202 if (!value || value === '0x') {
203 return new Uint8Array();
204 }
205 let s = 0;
206 if (REGEX_HEX_PREFIXED.test(value)) {
207 s = 2;
208 } else if (!REGEX_HEX_NOPREFIX.test(value)) {
209 throw new Error(`Expected hex value to convert, found '${value}'`);
210 }
211 const strLength = (value.length - s) / 2;
212 const endLength = Math.ceil(bitLength === -1 ? strLength : bitLength / 8);
213 const result = new Uint8Array(endLength);
214 const offset = endLength > strLength ? endLength - strLength : 0;
215 for (let i = offset; i < endLength; i++, s += 2) {
216 result[i] = (UNHEX[value.charCodeAt(s)] << 4) + UNHEX[value.charCodeAt(s + 1)];
217 }
218 return result;
219 }
220
221 function hexToBigInt(value, options = {}) {
222 return !value || value === '0x' ? BigInt(0) : u8aToBigInt(hexToU8a(value), objectSpread({
223 isLe: false,
224 isNegative: false
225 }, options));
226 }
227
228 var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
229
230 function getDefaultExportFromCjs (x) {
231 return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
232 }
233
234 function getAugmentedNamespace(n) {
235 var f = n.default;
236 if (typeof f == "function") {
237 var a = function () {
238 return f.apply(this, arguments);
239 };
240 a.prototype = f.prototype;
241 } else a = {};
242 Object.defineProperty(a, '__esModule', {value: true});
243 Object.keys(n).forEach(function (k) {
244 var d = Object.getOwnPropertyDescriptor(n, k);
245 Object.defineProperty(a, k, d.get ? d : {
246 enumerable: true,
247 get: function () {
248 return n[k];
249 }
250 });
251 });
252 return a;
253 }
254
255 var bn = {exports: {}};
256
257 const _nodeResolve_empty = {};
258
259 const _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({
260 __proto__: null,
261 'default': _nodeResolve_empty
262 });
263
264 const require$$0$1 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1);
265
266 (function (module) {
267 (function (module, exports) {
268 function assert (val, msg) {
269 if (!val) throw new Error(msg || 'Assertion failed');
270 }
271 function inherits (ctor, superCtor) {
272 ctor.super_ = superCtor;
273 var TempCtor = function () {};
274 TempCtor.prototype = superCtor.prototype;
275 ctor.prototype = new TempCtor();
276 ctor.prototype.constructor = ctor;
277 }
278 function BN (number, base, endian) {
279 if (BN.isBN(number)) {
280 return number;
281 }
282 this.negative = 0;
283 this.words = null;
284 this.length = 0;
285 this.red = null;
286 if (number !== null) {
287 if (base === 'le' || base === 'be') {
288 endian = base;
289 base = 10;
290 }
291 this._init(number || 0, base || 10, endian || 'be');
292 }
293 }
294 if (typeof module === 'object') {
295 module.exports = BN;
296 } else {
297 exports.BN = BN;
298 }
299 BN.BN = BN;
300 BN.wordSize = 26;
301 var Buffer;
302 try {
303 if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
304 Buffer = window.Buffer;
305 } else {
306 Buffer = require$$0$1.Buffer;
307 }
308 } catch (e) {
309 }
310 BN.isBN = function isBN (num) {
311 if (num instanceof BN) {
312 return true;
313 }
314 return num !== null && typeof num === 'object' &&
315 num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
316 };
317 BN.max = function max (left, right) {
318 if (left.cmp(right) > 0) return left;
319 return right;
320 };
321 BN.min = function min (left, right) {
322 if (left.cmp(right) < 0) return left;
323 return right;
324 };
325 BN.prototype._init = function init (number, base, endian) {
326 if (typeof number === 'number') {
327 return this._initNumber(number, base, endian);
328 }
329 if (typeof number === 'object') {
330 return this._initArray(number, base, endian);
331 }
332 if (base === 'hex') {
333 base = 16;
334 }
335 assert(base === (base | 0) && base >= 2 && base <= 36);
336 number = number.toString().replace(/\s+/g, '');
337 var start = 0;
338 if (number[0] === '-') {
339 start++;
340 this.negative = 1;
341 }
342 if (start < number.length) {
343 if (base === 16) {
344 this._parseHex(number, start, endian);
345 } else {
346 this._parseBase(number, base, start);
347 if (endian === 'le') {
348 this._initArray(this.toArray(), base, endian);
349 }
350 }
351 }
352 };
353 BN.prototype._initNumber = function _initNumber (number, base, endian) {
354 if (number < 0) {
355 this.negative = 1;
356 number = -number;
357 }
358 if (number < 0x4000000) {
359 this.words = [number & 0x3ffffff];
360 this.length = 1;
361 } else if (number < 0x10000000000000) {
362 this.words = [
363 number & 0x3ffffff,
364 (number / 0x4000000) & 0x3ffffff
365 ];
366 this.length = 2;
367 } else {
368 assert(number < 0x20000000000000);
369 this.words = [
370 number & 0x3ffffff,
371 (number / 0x4000000) & 0x3ffffff,
372 1
373 ];
374 this.length = 3;
375 }
376 if (endian !== 'le') return;
377 this._initArray(this.toArray(), base, endian);
378 };
379 BN.prototype._initArray = function _initArray (number, base, endian) {
380 assert(typeof number.length === 'number');
381 if (number.length <= 0) {
382 this.words = [0];
383 this.length = 1;
384 return this;
385 }
386 this.length = Math.ceil(number.length / 3);
387 this.words = new Array(this.length);
388 for (var i = 0; i < this.length; i++) {
389 this.words[i] = 0;
390 }
391 var j, w;
392 var off = 0;
393 if (endian === 'be') {
394 for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
395 w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);
396 this.words[j] |= (w << off) & 0x3ffffff;
397 this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
398 off += 24;
399 if (off >= 26) {
400 off -= 26;
401 j++;
402 }
403 }
404 } else if (endian === 'le') {
405 for (i = 0, j = 0; i < number.length; i += 3) {
406 w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);
407 this.words[j] |= (w << off) & 0x3ffffff;
408 this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
409 off += 24;
410 if (off >= 26) {
411 off -= 26;
412 j++;
413 }
414 }
415 }
416 return this._strip();
417 };
418 function parseHex4Bits (string, index) {
419 var c = string.charCodeAt(index);
420 if (c >= 48 && c <= 57) {
421 return c - 48;
422 } else if (c >= 65 && c <= 70) {
423 return c - 55;
424 } else if (c >= 97 && c <= 102) {
425 return c - 87;
426 } else {
427 assert(false, 'Invalid character in ' + string);
428 }
429 }
430 function parseHexByte (string, lowerBound, index) {
431 var r = parseHex4Bits(string, index);
432 if (index - 1 >= lowerBound) {
433 r |= parseHex4Bits(string, index - 1) << 4;
434 }
435 return r;
436 }
437 BN.prototype._parseHex = function _parseHex (number, start, endian) {
438 this.length = Math.ceil((number.length - start) / 6);
439 this.words = new Array(this.length);
440 for (var i = 0; i < this.length; i++) {
441 this.words[i] = 0;
442 }
443 var off = 0;
444 var j = 0;
445 var w;
446 if (endian === 'be') {
447 for (i = number.length - 1; i >= start; i -= 2) {
448 w = parseHexByte(number, start, i) << off;
449 this.words[j] |= w & 0x3ffffff;
450 if (off >= 18) {
451 off -= 18;
452 j += 1;
453 this.words[j] |= w >>> 26;
454 } else {
455 off += 8;
456 }
457 }
458 } else {
459 var parseLength = number.length - start;
460 for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) {
461 w = parseHexByte(number, start, i) << off;
462 this.words[j] |= w & 0x3ffffff;
463 if (off >= 18) {
464 off -= 18;
465 j += 1;
466 this.words[j] |= w >>> 26;
467 } else {
468 off += 8;
469 }
470 }
471 }
472 this._strip();
473 };
474 function parseBase (str, start, end, mul) {
475 var r = 0;
476 var b = 0;
477 var len = Math.min(str.length, end);
478 for (var i = start; i < len; i++) {
479 var c = str.charCodeAt(i) - 48;
480 r *= mul;
481 if (c >= 49) {
482 b = c - 49 + 0xa;
483 } else if (c >= 17) {
484 b = c - 17 + 0xa;
485 } else {
486 b = c;
487 }
488 assert(c >= 0 && b < mul, 'Invalid character');
489 r += b;
490 }
491 return r;
492 }
493 BN.prototype._parseBase = function _parseBase (number, base, start) {
494 this.words = [0];
495 this.length = 1;
496 for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
497 limbLen++;
498 }
499 limbLen--;
500 limbPow = (limbPow / base) | 0;
501 var total = number.length - start;
502 var mod = total % limbLen;
503 var end = Math.min(total, total - mod) + start;
504 var word = 0;
505 for (var i = start; i < end; i += limbLen) {
506 word = parseBase(number, i, i + limbLen, base);
507 this.imuln(limbPow);
508 if (this.words[0] + word < 0x4000000) {
509 this.words[0] += word;
510 } else {
511 this._iaddn(word);
512 }
513 }
514 if (mod !== 0) {
515 var pow = 1;
516 word = parseBase(number, i, number.length, base);
517 for (i = 0; i < mod; i++) {
518 pow *= base;
519 }
520 this.imuln(pow);
521 if (this.words[0] + word < 0x4000000) {
522 this.words[0] += word;
523 } else {
524 this._iaddn(word);
525 }
526 }
527 this._strip();
528 };
529 BN.prototype.copy = function copy (dest) {
530 dest.words = new Array(this.length);
531 for (var i = 0; i < this.length; i++) {
532 dest.words[i] = this.words[i];
533 }
534 dest.length = this.length;
535 dest.negative = this.negative;
536 dest.red = this.red;
537 };
538 function move (dest, src) {
539 dest.words = src.words;
540 dest.length = src.length;
541 dest.negative = src.negative;
542 dest.red = src.red;
543 }
544 BN.prototype._move = function _move (dest) {
545 move(dest, this);
546 };
547 BN.prototype.clone = function clone () {
548 var r = new BN(null);
549 this.copy(r);
550 return r;
551 };
552 BN.prototype._expand = function _expand (size) {
553 while (this.length < size) {
554 this.words[this.length++] = 0;
555 }
556 return this;
557 };
558 BN.prototype._strip = function strip () {
559 while (this.length > 1 && this.words[this.length - 1] === 0) {
560 this.length--;
561 }
562 return this._normSign();
563 };
564 BN.prototype._normSign = function _normSign () {
565 if (this.length === 1 && this.words[0] === 0) {
566 this.negative = 0;
567 }
568 return this;
569 };
570 if (typeof Symbol !== 'undefined' && typeof Symbol.for === 'function') {
571 try {
572 BN.prototype[Symbol.for('nodejs.util.inspect.custom')] = inspect;
573 } catch (e) {
574 BN.prototype.inspect = inspect;
575 }
576 } else {
577 BN.prototype.inspect = inspect;
578 }
579 function inspect () {
580 return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
581 }
582 var zeros = [
583 '',
584 '0',
585 '00',
586 '000',
587 '0000',
588 '00000',
589 '000000',
590 '0000000',
591 '00000000',
592 '000000000',
593 '0000000000',
594 '00000000000',
595 '000000000000',
596 '0000000000000',
597 '00000000000000',
598 '000000000000000',
599 '0000000000000000',
600 '00000000000000000',
601 '000000000000000000',
602 '0000000000000000000',
603 '00000000000000000000',
604 '000000000000000000000',
605 '0000000000000000000000',
606 '00000000000000000000000',
607 '000000000000000000000000',
608 '0000000000000000000000000'
609 ];
610 var groupSizes = [
611 0, 0,
612 25, 16, 12, 11, 10, 9, 8,
613 8, 7, 7, 7, 7, 6, 6,
614 6, 6, 6, 6, 6, 5, 5,
615 5, 5, 5, 5, 5, 5, 5,
616 5, 5, 5, 5, 5, 5, 5
617 ];
618 var groupBases = [
619 0, 0,
620 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
621 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
622 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
623 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
624 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
625 ];
626 BN.prototype.toString = function toString (base, padding) {
627 base = base || 10;
628 padding = padding | 0 || 1;
629 var out;
630 if (base === 16 || base === 'hex') {
631 out = '';
632 var off = 0;
633 var carry = 0;
634 for (var i = 0; i < this.length; i++) {
635 var w = this.words[i];
636 var word = (((w << off) | carry) & 0xffffff).toString(16);
637 carry = (w >>> (24 - off)) & 0xffffff;
638 off += 2;
639 if (off >= 26) {
640 off -= 26;
641 i--;
642 }
643 if (carry !== 0 || i !== this.length - 1) {
644 out = zeros[6 - word.length] + word + out;
645 } else {
646 out = word + out;
647 }
648 }
649 if (carry !== 0) {
650 out = carry.toString(16) + out;
651 }
652 while (out.length % padding !== 0) {
653 out = '0' + out;
654 }
655 if (this.negative !== 0) {
656 out = '-' + out;
657 }
658 return out;
659 }
660 if (base === (base | 0) && base >= 2 && base <= 36) {
661 var groupSize = groupSizes[base];
662 var groupBase = groupBases[base];
663 out = '';
664 var c = this.clone();
665 c.negative = 0;
666 while (!c.isZero()) {
667 var r = c.modrn(groupBase).toString(base);
668 c = c.idivn(groupBase);
669 if (!c.isZero()) {
670 out = zeros[groupSize - r.length] + r + out;
671 } else {
672 out = r + out;
673 }
674 }
675 if (this.isZero()) {
676 out = '0' + out;
677 }
678 while (out.length % padding !== 0) {
679 out = '0' + out;
680 }
681 if (this.negative !== 0) {
682 out = '-' + out;
683 }
684 return out;
685 }
686 assert(false, 'Base should be between 2 and 36');
687 };
688 BN.prototype.toNumber = function toNumber () {
689 var ret = this.words[0];
690 if (this.length === 2) {
691 ret += this.words[1] * 0x4000000;
692 } else if (this.length === 3 && this.words[2] === 0x01) {
693 ret += 0x10000000000000 + (this.words[1] * 0x4000000);
694 } else if (this.length > 2) {
695 assert(false, 'Number can only safely store up to 53 bits');
696 }
697 return (this.negative !== 0) ? -ret : ret;
698 };
699 BN.prototype.toJSON = function toJSON () {
700 return this.toString(16, 2);
701 };
702 if (Buffer) {
703 BN.prototype.toBuffer = function toBuffer (endian, length) {
704 return this.toArrayLike(Buffer, endian, length);
705 };
706 }
707 BN.prototype.toArray = function toArray (endian, length) {
708 return this.toArrayLike(Array, endian, length);
709 };
710 var allocate = function allocate (ArrayType, size) {
711 if (ArrayType.allocUnsafe) {
712 return ArrayType.allocUnsafe(size);
713 }
714 return new ArrayType(size);
715 };
716 BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) {
717 this._strip();
718 var byteLength = this.byteLength();
719 var reqLength = length || Math.max(1, byteLength);
720 assert(byteLength <= reqLength, 'byte array longer than desired length');
721 assert(reqLength > 0, 'Requested array length <= 0');
722 var res = allocate(ArrayType, reqLength);
723 var postfix = endian === 'le' ? 'LE' : 'BE';
724 this['_toArrayLike' + postfix](res, byteLength);
725 return res;
726 };
727 BN.prototype._toArrayLikeLE = function _toArrayLikeLE (res, byteLength) {
728 var position = 0;
729 var carry = 0;
730 for (var i = 0, shift = 0; i < this.length; i++) {
731 var word = (this.words[i] << shift) | carry;
732 res[position++] = word & 0xff;
733 if (position < res.length) {
734 res[position++] = (word >> 8) & 0xff;
735 }
736 if (position < res.length) {
737 res[position++] = (word >> 16) & 0xff;
738 }
739 if (shift === 6) {
740 if (position < res.length) {
741 res[position++] = (word >> 24) & 0xff;
742 }
743 carry = 0;
744 shift = 0;
745 } else {
746 carry = word >>> 24;
747 shift += 2;
748 }
749 }
750 if (position < res.length) {
751 res[position++] = carry;
752 while (position < res.length) {
753 res[position++] = 0;
754 }
755 }
756 };
757 BN.prototype._toArrayLikeBE = function _toArrayLikeBE (res, byteLength) {
758 var position = res.length - 1;
759 var carry = 0;
760 for (var i = 0, shift = 0; i < this.length; i++) {
761 var word = (this.words[i] << shift) | carry;
762 res[position--] = word & 0xff;
763 if (position >= 0) {
764 res[position--] = (word >> 8) & 0xff;
765 }
766 if (position >= 0) {
767 res[position--] = (word >> 16) & 0xff;
768 }
769 if (shift === 6) {
770 if (position >= 0) {
771 res[position--] = (word >> 24) & 0xff;
772 }
773 carry = 0;
774 shift = 0;
775 } else {
776 carry = word >>> 24;
777 shift += 2;
778 }
779 }
780 if (position >= 0) {
781 res[position--] = carry;
782 while (position >= 0) {
783 res[position--] = 0;
784 }
785 }
786 };
787 if (Math.clz32) {
788 BN.prototype._countBits = function _countBits (w) {
789 return 32 - Math.clz32(w);
790 };
791 } else {
792 BN.prototype._countBits = function _countBits (w) {
793 var t = w;
794 var r = 0;
795 if (t >= 0x1000) {
796 r += 13;
797 t >>>= 13;
798 }
799 if (t >= 0x40) {
800 r += 7;
801 t >>>= 7;
802 }
803 if (t >= 0x8) {
804 r += 4;
805 t >>>= 4;
806 }
807 if (t >= 0x02) {
808 r += 2;
809 t >>>= 2;
810 }
811 return r + t;
812 };
813 }
814 BN.prototype._zeroBits = function _zeroBits (w) {
815 if (w === 0) return 26;
816 var t = w;
817 var r = 0;
818 if ((t & 0x1fff) === 0) {
819 r += 13;
820 t >>>= 13;
821 }
822 if ((t & 0x7f) === 0) {
823 r += 7;
824 t >>>= 7;
825 }
826 if ((t & 0xf) === 0) {
827 r += 4;
828 t >>>= 4;
829 }
830 if ((t & 0x3) === 0) {
831 r += 2;
832 t >>>= 2;
833 }
834 if ((t & 0x1) === 0) {
835 r++;
836 }
837 return r;
838 };
839 BN.prototype.bitLength = function bitLength () {
840 var w = this.words[this.length - 1];
841 var hi = this._countBits(w);
842 return (this.length - 1) * 26 + hi;
843 };
844 function toBitArray (num) {
845 var w = new Array(num.bitLength());
846 for (var bit = 0; bit < w.length; bit++) {
847 var off = (bit / 26) | 0;
848 var wbit = bit % 26;
849 w[bit] = (num.words[off] >>> wbit) & 0x01;
850 }
851 return w;
852 }
853 BN.prototype.zeroBits = function zeroBits () {
854 if (this.isZero()) return 0;
855 var r = 0;
856 for (var i = 0; i < this.length; i++) {
857 var b = this._zeroBits(this.words[i]);
858 r += b;
859 if (b !== 26) break;
860 }
861 return r;
862 };
863 BN.prototype.byteLength = function byteLength () {
864 return Math.ceil(this.bitLength() / 8);
865 };
866 BN.prototype.toTwos = function toTwos (width) {
867 if (this.negative !== 0) {
868 return this.abs().inotn(width).iaddn(1);
869 }
870 return this.clone();
871 };
872 BN.prototype.fromTwos = function fromTwos (width) {
873 if (this.testn(width - 1)) {
874 return this.notn(width).iaddn(1).ineg();
875 }
876 return this.clone();
877 };
878 BN.prototype.isNeg = function isNeg () {
879 return this.negative !== 0;
880 };
881 BN.prototype.neg = function neg () {
882 return this.clone().ineg();
883 };
884 BN.prototype.ineg = function ineg () {
885 if (!this.isZero()) {
886 this.negative ^= 1;
887 }
888 return this;
889 };
890 BN.prototype.iuor = function iuor (num) {
891 while (this.length < num.length) {
892 this.words[this.length++] = 0;
893 }
894 for (var i = 0; i < num.length; i++) {
895 this.words[i] = this.words[i] | num.words[i];
896 }
897 return this._strip();
898 };
899 BN.prototype.ior = function ior (num) {
900 assert((this.negative | num.negative) === 0);
901 return this.iuor(num);
902 };
903 BN.prototype.or = function or (num) {
904 if (this.length > num.length) return this.clone().ior(num);
905 return num.clone().ior(this);
906 };
907 BN.prototype.uor = function uor (num) {
908 if (this.length > num.length) return this.clone().iuor(num);
909 return num.clone().iuor(this);
910 };
911 BN.prototype.iuand = function iuand (num) {
912 var b;
913 if (this.length > num.length) {
914 b = num;
915 } else {
916 b = this;
917 }
918 for (var i = 0; i < b.length; i++) {
919 this.words[i] = this.words[i] & num.words[i];
920 }
921 this.length = b.length;
922 return this._strip();
923 };
924 BN.prototype.iand = function iand (num) {
925 assert((this.negative | num.negative) === 0);
926 return this.iuand(num);
927 };
928 BN.prototype.and = function and (num) {
929 if (this.length > num.length) return this.clone().iand(num);
930 return num.clone().iand(this);
931 };
932 BN.prototype.uand = function uand (num) {
933 if (this.length > num.length) return this.clone().iuand(num);
934 return num.clone().iuand(this);
935 };
936 BN.prototype.iuxor = function iuxor (num) {
937 var a;
938 var b;
939 if (this.length > num.length) {
940 a = this;
941 b = num;
942 } else {
943 a = num;
944 b = this;
945 }
946 for (var i = 0; i < b.length; i++) {
947 this.words[i] = a.words[i] ^ b.words[i];
948 }
949 if (this !== a) {
950 for (; i < a.length; i++) {
951 this.words[i] = a.words[i];
952 }
953 }
954 this.length = a.length;
955 return this._strip();
956 };
957 BN.prototype.ixor = function ixor (num) {
958 assert((this.negative | num.negative) === 0);
959 return this.iuxor(num);
960 };
961 BN.prototype.xor = function xor (num) {
962 if (this.length > num.length) return this.clone().ixor(num);
963 return num.clone().ixor(this);
964 };
965 BN.prototype.uxor = function uxor (num) {
966 if (this.length > num.length) return this.clone().iuxor(num);
967 return num.clone().iuxor(this);
968 };
969 BN.prototype.inotn = function inotn (width) {
970 assert(typeof width === 'number' && width >= 0);
971 var bytesNeeded = Math.ceil(width / 26) | 0;
972 var bitsLeft = width % 26;
973 this._expand(bytesNeeded);
974 if (bitsLeft > 0) {
975 bytesNeeded--;
976 }
977 for (var i = 0; i < bytesNeeded; i++) {
978 this.words[i] = ~this.words[i] & 0x3ffffff;
979 }
980 if (bitsLeft > 0) {
981 this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft));
982 }
983 return this._strip();
984 };
985 BN.prototype.notn = function notn (width) {
986 return this.clone().inotn(width);
987 };
988 BN.prototype.setn = function setn (bit, val) {
989 assert(typeof bit === 'number' && bit >= 0);
990 var off = (bit / 26) | 0;
991 var wbit = bit % 26;
992 this._expand(off + 1);
993 if (val) {
994 this.words[off] = this.words[off] | (1 << wbit);
995 } else {
996 this.words[off] = this.words[off] & ~(1 << wbit);
997 }
998 return this._strip();
999 };
1000 BN.prototype.iadd = function iadd (num) {
1001 var r;
1002 if (this.negative !== 0 && num.negative === 0) {
1003 this.negative = 0;
1004 r = this.isub(num);
1005 this.negative ^= 1;
1006 return this._normSign();
1007 } else if (this.negative === 0 && num.negative !== 0) {
1008 num.negative = 0;
1009 r = this.isub(num);
1010 num.negative = 1;
1011 return r._normSign();
1012 }
1013 var a, b;
1014 if (this.length > num.length) {
1015 a = this;
1016 b = num;
1017 } else {
1018 a = num;
1019 b = this;
1020 }
1021 var carry = 0;
1022 for (var i = 0; i < b.length; i++) {
1023 r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
1024 this.words[i] = r & 0x3ffffff;
1025 carry = r >>> 26;
1026 }
1027 for (; carry !== 0 && i < a.length; i++) {
1028 r = (a.words[i] | 0) + carry;
1029 this.words[i] = r & 0x3ffffff;
1030 carry = r >>> 26;
1031 }
1032 this.length = a.length;
1033 if (carry !== 0) {
1034 this.words[this.length] = carry;
1035 this.length++;
1036 } else if (a !== this) {
1037 for (; i < a.length; i++) {
1038 this.words[i] = a.words[i];
1039 }
1040 }
1041 return this;
1042 };
1043 BN.prototype.add = function add (num) {
1044 var res;
1045 if (num.negative !== 0 && this.negative === 0) {
1046 num.negative = 0;
1047 res = this.sub(num);
1048 num.negative ^= 1;
1049 return res;
1050 } else if (num.negative === 0 && this.negative !== 0) {
1051 this.negative = 0;
1052 res = num.sub(this);
1053 this.negative = 1;
1054 return res;
1055 }
1056 if (this.length > num.length) return this.clone().iadd(num);
1057 return num.clone().iadd(this);
1058 };
1059 BN.prototype.isub = function isub (num) {
1060 if (num.negative !== 0) {
1061 num.negative = 0;
1062 var r = this.iadd(num);
1063 num.negative = 1;
1064 return r._normSign();
1065 } else if (this.negative !== 0) {
1066 this.negative = 0;
1067 this.iadd(num);
1068 this.negative = 1;
1069 return this._normSign();
1070 }
1071 var cmp = this.cmp(num);
1072 if (cmp === 0) {
1073 this.negative = 0;
1074 this.length = 1;
1075 this.words[0] = 0;
1076 return this;
1077 }
1078 var a, b;
1079 if (cmp > 0) {
1080 a = this;
1081 b = num;
1082 } else {
1083 a = num;
1084 b = this;
1085 }
1086 var carry = 0;
1087 for (var i = 0; i < b.length; i++) {
1088 r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
1089 carry = r >> 26;
1090 this.words[i] = r & 0x3ffffff;
1091 }
1092 for (; carry !== 0 && i < a.length; i++) {
1093 r = (a.words[i] | 0) + carry;
1094 carry = r >> 26;
1095 this.words[i] = r & 0x3ffffff;
1096 }
1097 if (carry === 0 && i < a.length && a !== this) {
1098 for (; i < a.length; i++) {
1099 this.words[i] = a.words[i];
1100 }
1101 }
1102 this.length = Math.max(this.length, i);
1103 if (a !== this) {
1104 this.negative = 1;
1105 }
1106 return this._strip();
1107 };
1108 BN.prototype.sub = function sub (num) {
1109 return this.clone().isub(num);
1110 };
1111 function smallMulTo (self, num, out) {
1112 out.negative = num.negative ^ self.negative;
1113 var len = (self.length + num.length) | 0;
1114 out.length = len;
1115 len = (len - 1) | 0;
1116 var a = self.words[0] | 0;
1117 var b = num.words[0] | 0;
1118 var r = a * b;
1119 var lo = r & 0x3ffffff;
1120 var carry = (r / 0x4000000) | 0;
1121 out.words[0] = lo;
1122 for (var k = 1; k < len; k++) {
1123 var ncarry = carry >>> 26;
1124 var rword = carry & 0x3ffffff;
1125 var maxJ = Math.min(k, num.length - 1);
1126 for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
1127 var i = (k - j) | 0;
1128 a = self.words[i] | 0;
1129 b = num.words[j] | 0;
1130 r = a * b + rword;
1131 ncarry += (r / 0x4000000) | 0;
1132 rword = r & 0x3ffffff;
1133 }
1134 out.words[k] = rword | 0;
1135 carry = ncarry | 0;
1136 }
1137 if (carry !== 0) {
1138 out.words[k] = carry | 0;
1139 } else {
1140 out.length--;
1141 }
1142 return out._strip();
1143 }
1144 var comb10MulTo = function comb10MulTo (self, num, out) {
1145 var a = self.words;
1146 var b = num.words;
1147 var o = out.words;
1148 var c = 0;
1149 var lo;
1150 var mid;
1151 var hi;
1152 var a0 = a[0] | 0;
1153 var al0 = a0 & 0x1fff;
1154 var ah0 = a0 >>> 13;
1155 var a1 = a[1] | 0;
1156 var al1 = a1 & 0x1fff;
1157 var ah1 = a1 >>> 13;
1158 var a2 = a[2] | 0;
1159 var al2 = a2 & 0x1fff;
1160 var ah2 = a2 >>> 13;
1161 var a3 = a[3] | 0;
1162 var al3 = a3 & 0x1fff;
1163 var ah3 = a3 >>> 13;
1164 var a4 = a[4] | 0;
1165 var al4 = a4 & 0x1fff;
1166 var ah4 = a4 >>> 13;
1167 var a5 = a[5] | 0;
1168 var al5 = a5 & 0x1fff;
1169 var ah5 = a5 >>> 13;
1170 var a6 = a[6] | 0;
1171 var al6 = a6 & 0x1fff;
1172 var ah6 = a6 >>> 13;
1173 var a7 = a[7] | 0;
1174 var al7 = a7 & 0x1fff;
1175 var ah7 = a7 >>> 13;
1176 var a8 = a[8] | 0;
1177 var al8 = a8 & 0x1fff;
1178 var ah8 = a8 >>> 13;
1179 var a9 = a[9] | 0;
1180 var al9 = a9 & 0x1fff;
1181 var ah9 = a9 >>> 13;
1182 var b0 = b[0] | 0;
1183 var bl0 = b0 & 0x1fff;
1184 var bh0 = b0 >>> 13;
1185 var b1 = b[1] | 0;
1186 var bl1 = b1 & 0x1fff;
1187 var bh1 = b1 >>> 13;
1188 var b2 = b[2] | 0;
1189 var bl2 = b2 & 0x1fff;
1190 var bh2 = b2 >>> 13;
1191 var b3 = b[3] | 0;
1192 var bl3 = b3 & 0x1fff;
1193 var bh3 = b3 >>> 13;
1194 var b4 = b[4] | 0;
1195 var bl4 = b4 & 0x1fff;
1196 var bh4 = b4 >>> 13;
1197 var b5 = b[5] | 0;
1198 var bl5 = b5 & 0x1fff;
1199 var bh5 = b5 >>> 13;
1200 var b6 = b[6] | 0;
1201 var bl6 = b6 & 0x1fff;
1202 var bh6 = b6 >>> 13;
1203 var b7 = b[7] | 0;
1204 var bl7 = b7 & 0x1fff;
1205 var bh7 = b7 >>> 13;
1206 var b8 = b[8] | 0;
1207 var bl8 = b8 & 0x1fff;
1208 var bh8 = b8 >>> 13;
1209 var b9 = b[9] | 0;
1210 var bl9 = b9 & 0x1fff;
1211 var bh9 = b9 >>> 13;
1212 out.negative = self.negative ^ num.negative;
1213 out.length = 19;
1214 lo = Math.imul(al0, bl0);
1215 mid = Math.imul(al0, bh0);
1216 mid = (mid + Math.imul(ah0, bl0)) | 0;
1217 hi = Math.imul(ah0, bh0);
1218 var w0 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1219 c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0;
1220 w0 &= 0x3ffffff;
1221 lo = Math.imul(al1, bl0);
1222 mid = Math.imul(al1, bh0);
1223 mid = (mid + Math.imul(ah1, bl0)) | 0;
1224 hi = Math.imul(ah1, bh0);
1225 lo = (lo + Math.imul(al0, bl1)) | 0;
1226 mid = (mid + Math.imul(al0, bh1)) | 0;
1227 mid = (mid + Math.imul(ah0, bl1)) | 0;
1228 hi = (hi + Math.imul(ah0, bh1)) | 0;
1229 var w1 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1230 c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0;
1231 w1 &= 0x3ffffff;
1232 lo = Math.imul(al2, bl0);
1233 mid = Math.imul(al2, bh0);
1234 mid = (mid + Math.imul(ah2, bl0)) | 0;
1235 hi = Math.imul(ah2, bh0);
1236 lo = (lo + Math.imul(al1, bl1)) | 0;
1237 mid = (mid + Math.imul(al1, bh1)) | 0;
1238 mid = (mid + Math.imul(ah1, bl1)) | 0;
1239 hi = (hi + Math.imul(ah1, bh1)) | 0;
1240 lo = (lo + Math.imul(al0, bl2)) | 0;
1241 mid = (mid + Math.imul(al0, bh2)) | 0;
1242 mid = (mid + Math.imul(ah0, bl2)) | 0;
1243 hi = (hi + Math.imul(ah0, bh2)) | 0;
1244 var w2 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1245 c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0;
1246 w2 &= 0x3ffffff;
1247 lo = Math.imul(al3, bl0);
1248 mid = Math.imul(al3, bh0);
1249 mid = (mid + Math.imul(ah3, bl0)) | 0;
1250 hi = Math.imul(ah3, bh0);
1251 lo = (lo + Math.imul(al2, bl1)) | 0;
1252 mid = (mid + Math.imul(al2, bh1)) | 0;
1253 mid = (mid + Math.imul(ah2, bl1)) | 0;
1254 hi = (hi + Math.imul(ah2, bh1)) | 0;
1255 lo = (lo + Math.imul(al1, bl2)) | 0;
1256 mid = (mid + Math.imul(al1, bh2)) | 0;
1257 mid = (mid + Math.imul(ah1, bl2)) | 0;
1258 hi = (hi + Math.imul(ah1, bh2)) | 0;
1259 lo = (lo + Math.imul(al0, bl3)) | 0;
1260 mid = (mid + Math.imul(al0, bh3)) | 0;
1261 mid = (mid + Math.imul(ah0, bl3)) | 0;
1262 hi = (hi + Math.imul(ah0, bh3)) | 0;
1263 var w3 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1264 c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0;
1265 w3 &= 0x3ffffff;
1266 lo = Math.imul(al4, bl0);
1267 mid = Math.imul(al4, bh0);
1268 mid = (mid + Math.imul(ah4, bl0)) | 0;
1269 hi = Math.imul(ah4, bh0);
1270 lo = (lo + Math.imul(al3, bl1)) | 0;
1271 mid = (mid + Math.imul(al3, bh1)) | 0;
1272 mid = (mid + Math.imul(ah3, bl1)) | 0;
1273 hi = (hi + Math.imul(ah3, bh1)) | 0;
1274 lo = (lo + Math.imul(al2, bl2)) | 0;
1275 mid = (mid + Math.imul(al2, bh2)) | 0;
1276 mid = (mid + Math.imul(ah2, bl2)) | 0;
1277 hi = (hi + Math.imul(ah2, bh2)) | 0;
1278 lo = (lo + Math.imul(al1, bl3)) | 0;
1279 mid = (mid + Math.imul(al1, bh3)) | 0;
1280 mid = (mid + Math.imul(ah1, bl3)) | 0;
1281 hi = (hi + Math.imul(ah1, bh3)) | 0;
1282 lo = (lo + Math.imul(al0, bl4)) | 0;
1283 mid = (mid + Math.imul(al0, bh4)) | 0;
1284 mid = (mid + Math.imul(ah0, bl4)) | 0;
1285 hi = (hi + Math.imul(ah0, bh4)) | 0;
1286 var w4 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1287 c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0;
1288 w4 &= 0x3ffffff;
1289 lo = Math.imul(al5, bl0);
1290 mid = Math.imul(al5, bh0);
1291 mid = (mid + Math.imul(ah5, bl0)) | 0;
1292 hi = Math.imul(ah5, bh0);
1293 lo = (lo + Math.imul(al4, bl1)) | 0;
1294 mid = (mid + Math.imul(al4, bh1)) | 0;
1295 mid = (mid + Math.imul(ah4, bl1)) | 0;
1296 hi = (hi + Math.imul(ah4, bh1)) | 0;
1297 lo = (lo + Math.imul(al3, bl2)) | 0;
1298 mid = (mid + Math.imul(al3, bh2)) | 0;
1299 mid = (mid + Math.imul(ah3, bl2)) | 0;
1300 hi = (hi + Math.imul(ah3, bh2)) | 0;
1301 lo = (lo + Math.imul(al2, bl3)) | 0;
1302 mid = (mid + Math.imul(al2, bh3)) | 0;
1303 mid = (mid + Math.imul(ah2, bl3)) | 0;
1304 hi = (hi + Math.imul(ah2, bh3)) | 0;
1305 lo = (lo + Math.imul(al1, bl4)) | 0;
1306 mid = (mid + Math.imul(al1, bh4)) | 0;
1307 mid = (mid + Math.imul(ah1, bl4)) | 0;
1308 hi = (hi + Math.imul(ah1, bh4)) | 0;
1309 lo = (lo + Math.imul(al0, bl5)) | 0;
1310 mid = (mid + Math.imul(al0, bh5)) | 0;
1311 mid = (mid + Math.imul(ah0, bl5)) | 0;
1312 hi = (hi + Math.imul(ah0, bh5)) | 0;
1313 var w5 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1314 c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0;
1315 w5 &= 0x3ffffff;
1316 lo = Math.imul(al6, bl0);
1317 mid = Math.imul(al6, bh0);
1318 mid = (mid + Math.imul(ah6, bl0)) | 0;
1319 hi = Math.imul(ah6, bh0);
1320 lo = (lo + Math.imul(al5, bl1)) | 0;
1321 mid = (mid + Math.imul(al5, bh1)) | 0;
1322 mid = (mid + Math.imul(ah5, bl1)) | 0;
1323 hi = (hi + Math.imul(ah5, bh1)) | 0;
1324 lo = (lo + Math.imul(al4, bl2)) | 0;
1325 mid = (mid + Math.imul(al4, bh2)) | 0;
1326 mid = (mid + Math.imul(ah4, bl2)) | 0;
1327 hi = (hi + Math.imul(ah4, bh2)) | 0;
1328 lo = (lo + Math.imul(al3, bl3)) | 0;
1329 mid = (mid + Math.imul(al3, bh3)) | 0;
1330 mid = (mid + Math.imul(ah3, bl3)) | 0;
1331 hi = (hi + Math.imul(ah3, bh3)) | 0;
1332 lo = (lo + Math.imul(al2, bl4)) | 0;
1333 mid = (mid + Math.imul(al2, bh4)) | 0;
1334 mid = (mid + Math.imul(ah2, bl4)) | 0;
1335 hi = (hi + Math.imul(ah2, bh4)) | 0;
1336 lo = (lo + Math.imul(al1, bl5)) | 0;
1337 mid = (mid + Math.imul(al1, bh5)) | 0;
1338 mid = (mid + Math.imul(ah1, bl5)) | 0;
1339 hi = (hi + Math.imul(ah1, bh5)) | 0;
1340 lo = (lo + Math.imul(al0, bl6)) | 0;
1341 mid = (mid + Math.imul(al0, bh6)) | 0;
1342 mid = (mid + Math.imul(ah0, bl6)) | 0;
1343 hi = (hi + Math.imul(ah0, bh6)) | 0;
1344 var w6 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1345 c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0;
1346 w6 &= 0x3ffffff;
1347 lo = Math.imul(al7, bl0);
1348 mid = Math.imul(al7, bh0);
1349 mid = (mid + Math.imul(ah7, bl0)) | 0;
1350 hi = Math.imul(ah7, bh0);
1351 lo = (lo + Math.imul(al6, bl1)) | 0;
1352 mid = (mid + Math.imul(al6, bh1)) | 0;
1353 mid = (mid + Math.imul(ah6, bl1)) | 0;
1354 hi = (hi + Math.imul(ah6, bh1)) | 0;
1355 lo = (lo + Math.imul(al5, bl2)) | 0;
1356 mid = (mid + Math.imul(al5, bh2)) | 0;
1357 mid = (mid + Math.imul(ah5, bl2)) | 0;
1358 hi = (hi + Math.imul(ah5, bh2)) | 0;
1359 lo = (lo + Math.imul(al4, bl3)) | 0;
1360 mid = (mid + Math.imul(al4, bh3)) | 0;
1361 mid = (mid + Math.imul(ah4, bl3)) | 0;
1362 hi = (hi + Math.imul(ah4, bh3)) | 0;
1363 lo = (lo + Math.imul(al3, bl4)) | 0;
1364 mid = (mid + Math.imul(al3, bh4)) | 0;
1365 mid = (mid + Math.imul(ah3, bl4)) | 0;
1366 hi = (hi + Math.imul(ah3, bh4)) | 0;
1367 lo = (lo + Math.imul(al2, bl5)) | 0;
1368 mid = (mid + Math.imul(al2, bh5)) | 0;
1369 mid = (mid + Math.imul(ah2, bl5)) | 0;
1370 hi = (hi + Math.imul(ah2, bh5)) | 0;
1371 lo = (lo + Math.imul(al1, bl6)) | 0;
1372 mid = (mid + Math.imul(al1, bh6)) | 0;
1373 mid = (mid + Math.imul(ah1, bl6)) | 0;
1374 hi = (hi + Math.imul(ah1, bh6)) | 0;
1375 lo = (lo + Math.imul(al0, bl7)) | 0;
1376 mid = (mid + Math.imul(al0, bh7)) | 0;
1377 mid = (mid + Math.imul(ah0, bl7)) | 0;
1378 hi = (hi + Math.imul(ah0, bh7)) | 0;
1379 var w7 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1380 c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0;
1381 w7 &= 0x3ffffff;
1382 lo = Math.imul(al8, bl0);
1383 mid = Math.imul(al8, bh0);
1384 mid = (mid + Math.imul(ah8, bl0)) | 0;
1385 hi = Math.imul(ah8, bh0);
1386 lo = (lo + Math.imul(al7, bl1)) | 0;
1387 mid = (mid + Math.imul(al7, bh1)) | 0;
1388 mid = (mid + Math.imul(ah7, bl1)) | 0;
1389 hi = (hi + Math.imul(ah7, bh1)) | 0;
1390 lo = (lo + Math.imul(al6, bl2)) | 0;
1391 mid = (mid + Math.imul(al6, bh2)) | 0;
1392 mid = (mid + Math.imul(ah6, bl2)) | 0;
1393 hi = (hi + Math.imul(ah6, bh2)) | 0;
1394 lo = (lo + Math.imul(al5, bl3)) | 0;
1395 mid = (mid + Math.imul(al5, bh3)) | 0;
1396 mid = (mid + Math.imul(ah5, bl3)) | 0;
1397 hi = (hi + Math.imul(ah5, bh3)) | 0;
1398 lo = (lo + Math.imul(al4, bl4)) | 0;
1399 mid = (mid + Math.imul(al4, bh4)) | 0;
1400 mid = (mid + Math.imul(ah4, bl4)) | 0;
1401 hi = (hi + Math.imul(ah4, bh4)) | 0;
1402 lo = (lo + Math.imul(al3, bl5)) | 0;
1403 mid = (mid + Math.imul(al3, bh5)) | 0;
1404 mid = (mid + Math.imul(ah3, bl5)) | 0;
1405 hi = (hi + Math.imul(ah3, bh5)) | 0;
1406 lo = (lo + Math.imul(al2, bl6)) | 0;
1407 mid = (mid + Math.imul(al2, bh6)) | 0;
1408 mid = (mid + Math.imul(ah2, bl6)) | 0;
1409 hi = (hi + Math.imul(ah2, bh6)) | 0;
1410 lo = (lo + Math.imul(al1, bl7)) | 0;
1411 mid = (mid + Math.imul(al1, bh7)) | 0;
1412 mid = (mid + Math.imul(ah1, bl7)) | 0;
1413 hi = (hi + Math.imul(ah1, bh7)) | 0;
1414 lo = (lo + Math.imul(al0, bl8)) | 0;
1415 mid = (mid + Math.imul(al0, bh8)) | 0;
1416 mid = (mid + Math.imul(ah0, bl8)) | 0;
1417 hi = (hi + Math.imul(ah0, bh8)) | 0;
1418 var w8 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1419 c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0;
1420 w8 &= 0x3ffffff;
1421 lo = Math.imul(al9, bl0);
1422 mid = Math.imul(al9, bh0);
1423 mid = (mid + Math.imul(ah9, bl0)) | 0;
1424 hi = Math.imul(ah9, bh0);
1425 lo = (lo + Math.imul(al8, bl1)) | 0;
1426 mid = (mid + Math.imul(al8, bh1)) | 0;
1427 mid = (mid + Math.imul(ah8, bl1)) | 0;
1428 hi = (hi + Math.imul(ah8, bh1)) | 0;
1429 lo = (lo + Math.imul(al7, bl2)) | 0;
1430 mid = (mid + Math.imul(al7, bh2)) | 0;
1431 mid = (mid + Math.imul(ah7, bl2)) | 0;
1432 hi = (hi + Math.imul(ah7, bh2)) | 0;
1433 lo = (lo + Math.imul(al6, bl3)) | 0;
1434 mid = (mid + Math.imul(al6, bh3)) | 0;
1435 mid = (mid + Math.imul(ah6, bl3)) | 0;
1436 hi = (hi + Math.imul(ah6, bh3)) | 0;
1437 lo = (lo + Math.imul(al5, bl4)) | 0;
1438 mid = (mid + Math.imul(al5, bh4)) | 0;
1439 mid = (mid + Math.imul(ah5, bl4)) | 0;
1440 hi = (hi + Math.imul(ah5, bh4)) | 0;
1441 lo = (lo + Math.imul(al4, bl5)) | 0;
1442 mid = (mid + Math.imul(al4, bh5)) | 0;
1443 mid = (mid + Math.imul(ah4, bl5)) | 0;
1444 hi = (hi + Math.imul(ah4, bh5)) | 0;
1445 lo = (lo + Math.imul(al3, bl6)) | 0;
1446 mid = (mid + Math.imul(al3, bh6)) | 0;
1447 mid = (mid + Math.imul(ah3, bl6)) | 0;
1448 hi = (hi + Math.imul(ah3, bh6)) | 0;
1449 lo = (lo + Math.imul(al2, bl7)) | 0;
1450 mid = (mid + Math.imul(al2, bh7)) | 0;
1451 mid = (mid + Math.imul(ah2, bl7)) | 0;
1452 hi = (hi + Math.imul(ah2, bh7)) | 0;
1453 lo = (lo + Math.imul(al1, bl8)) | 0;
1454 mid = (mid + Math.imul(al1, bh8)) | 0;
1455 mid = (mid + Math.imul(ah1, bl8)) | 0;
1456 hi = (hi + Math.imul(ah1, bh8)) | 0;
1457 lo = (lo + Math.imul(al0, bl9)) | 0;
1458 mid = (mid + Math.imul(al0, bh9)) | 0;
1459 mid = (mid + Math.imul(ah0, bl9)) | 0;
1460 hi = (hi + Math.imul(ah0, bh9)) | 0;
1461 var w9 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1462 c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0;
1463 w9 &= 0x3ffffff;
1464 lo = Math.imul(al9, bl1);
1465 mid = Math.imul(al9, bh1);
1466 mid = (mid + Math.imul(ah9, bl1)) | 0;
1467 hi = Math.imul(ah9, bh1);
1468 lo = (lo + Math.imul(al8, bl2)) | 0;
1469 mid = (mid + Math.imul(al8, bh2)) | 0;
1470 mid = (mid + Math.imul(ah8, bl2)) | 0;
1471 hi = (hi + Math.imul(ah8, bh2)) | 0;
1472 lo = (lo + Math.imul(al7, bl3)) | 0;
1473 mid = (mid + Math.imul(al7, bh3)) | 0;
1474 mid = (mid + Math.imul(ah7, bl3)) | 0;
1475 hi = (hi + Math.imul(ah7, bh3)) | 0;
1476 lo = (lo + Math.imul(al6, bl4)) | 0;
1477 mid = (mid + Math.imul(al6, bh4)) | 0;
1478 mid = (mid + Math.imul(ah6, bl4)) | 0;
1479 hi = (hi + Math.imul(ah6, bh4)) | 0;
1480 lo = (lo + Math.imul(al5, bl5)) | 0;
1481 mid = (mid + Math.imul(al5, bh5)) | 0;
1482 mid = (mid + Math.imul(ah5, bl5)) | 0;
1483 hi = (hi + Math.imul(ah5, bh5)) | 0;
1484 lo = (lo + Math.imul(al4, bl6)) | 0;
1485 mid = (mid + Math.imul(al4, bh6)) | 0;
1486 mid = (mid + Math.imul(ah4, bl6)) | 0;
1487 hi = (hi + Math.imul(ah4, bh6)) | 0;
1488 lo = (lo + Math.imul(al3, bl7)) | 0;
1489 mid = (mid + Math.imul(al3, bh7)) | 0;
1490 mid = (mid + Math.imul(ah3, bl7)) | 0;
1491 hi = (hi + Math.imul(ah3, bh7)) | 0;
1492 lo = (lo + Math.imul(al2, bl8)) | 0;
1493 mid = (mid + Math.imul(al2, bh8)) | 0;
1494 mid = (mid + Math.imul(ah2, bl8)) | 0;
1495 hi = (hi + Math.imul(ah2, bh8)) | 0;
1496 lo = (lo + Math.imul(al1, bl9)) | 0;
1497 mid = (mid + Math.imul(al1, bh9)) | 0;
1498 mid = (mid + Math.imul(ah1, bl9)) | 0;
1499 hi = (hi + Math.imul(ah1, bh9)) | 0;
1500 var w10 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1501 c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0;
1502 w10 &= 0x3ffffff;
1503 lo = Math.imul(al9, bl2);
1504 mid = Math.imul(al9, bh2);
1505 mid = (mid + Math.imul(ah9, bl2)) | 0;
1506 hi = Math.imul(ah9, bh2);
1507 lo = (lo + Math.imul(al8, bl3)) | 0;
1508 mid = (mid + Math.imul(al8, bh3)) | 0;
1509 mid = (mid + Math.imul(ah8, bl3)) | 0;
1510 hi = (hi + Math.imul(ah8, bh3)) | 0;
1511 lo = (lo + Math.imul(al7, bl4)) | 0;
1512 mid = (mid + Math.imul(al7, bh4)) | 0;
1513 mid = (mid + Math.imul(ah7, bl4)) | 0;
1514 hi = (hi + Math.imul(ah7, bh4)) | 0;
1515 lo = (lo + Math.imul(al6, bl5)) | 0;
1516 mid = (mid + Math.imul(al6, bh5)) | 0;
1517 mid = (mid + Math.imul(ah6, bl5)) | 0;
1518 hi = (hi + Math.imul(ah6, bh5)) | 0;
1519 lo = (lo + Math.imul(al5, bl6)) | 0;
1520 mid = (mid + Math.imul(al5, bh6)) | 0;
1521 mid = (mid + Math.imul(ah5, bl6)) | 0;
1522 hi = (hi + Math.imul(ah5, bh6)) | 0;
1523 lo = (lo + Math.imul(al4, bl7)) | 0;
1524 mid = (mid + Math.imul(al4, bh7)) | 0;
1525 mid = (mid + Math.imul(ah4, bl7)) | 0;
1526 hi = (hi + Math.imul(ah4, bh7)) | 0;
1527 lo = (lo + Math.imul(al3, bl8)) | 0;
1528 mid = (mid + Math.imul(al3, bh8)) | 0;
1529 mid = (mid + Math.imul(ah3, bl8)) | 0;
1530 hi = (hi + Math.imul(ah3, bh8)) | 0;
1531 lo = (lo + Math.imul(al2, bl9)) | 0;
1532 mid = (mid + Math.imul(al2, bh9)) | 0;
1533 mid = (mid + Math.imul(ah2, bl9)) | 0;
1534 hi = (hi + Math.imul(ah2, bh9)) | 0;
1535 var w11 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1536 c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0;
1537 w11 &= 0x3ffffff;
1538 lo = Math.imul(al9, bl3);
1539 mid = Math.imul(al9, bh3);
1540 mid = (mid + Math.imul(ah9, bl3)) | 0;
1541 hi = Math.imul(ah9, bh3);
1542 lo = (lo + Math.imul(al8, bl4)) | 0;
1543 mid = (mid + Math.imul(al8, bh4)) | 0;
1544 mid = (mid + Math.imul(ah8, bl4)) | 0;
1545 hi = (hi + Math.imul(ah8, bh4)) | 0;
1546 lo = (lo + Math.imul(al7, bl5)) | 0;
1547 mid = (mid + Math.imul(al7, bh5)) | 0;
1548 mid = (mid + Math.imul(ah7, bl5)) | 0;
1549 hi = (hi + Math.imul(ah7, bh5)) | 0;
1550 lo = (lo + Math.imul(al6, bl6)) | 0;
1551 mid = (mid + Math.imul(al6, bh6)) | 0;
1552 mid = (mid + Math.imul(ah6, bl6)) | 0;
1553 hi = (hi + Math.imul(ah6, bh6)) | 0;
1554 lo = (lo + Math.imul(al5, bl7)) | 0;
1555 mid = (mid + Math.imul(al5, bh7)) | 0;
1556 mid = (mid + Math.imul(ah5, bl7)) | 0;
1557 hi = (hi + Math.imul(ah5, bh7)) | 0;
1558 lo = (lo + Math.imul(al4, bl8)) | 0;
1559 mid = (mid + Math.imul(al4, bh8)) | 0;
1560 mid = (mid + Math.imul(ah4, bl8)) | 0;
1561 hi = (hi + Math.imul(ah4, bh8)) | 0;
1562 lo = (lo + Math.imul(al3, bl9)) | 0;
1563 mid = (mid + Math.imul(al3, bh9)) | 0;
1564 mid = (mid + Math.imul(ah3, bl9)) | 0;
1565 hi = (hi + Math.imul(ah3, bh9)) | 0;
1566 var w12 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1567 c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0;
1568 w12 &= 0x3ffffff;
1569 lo = Math.imul(al9, bl4);
1570 mid = Math.imul(al9, bh4);
1571 mid = (mid + Math.imul(ah9, bl4)) | 0;
1572 hi = Math.imul(ah9, bh4);
1573 lo = (lo + Math.imul(al8, bl5)) | 0;
1574 mid = (mid + Math.imul(al8, bh5)) | 0;
1575 mid = (mid + Math.imul(ah8, bl5)) | 0;
1576 hi = (hi + Math.imul(ah8, bh5)) | 0;
1577 lo = (lo + Math.imul(al7, bl6)) | 0;
1578 mid = (mid + Math.imul(al7, bh6)) | 0;
1579 mid = (mid + Math.imul(ah7, bl6)) | 0;
1580 hi = (hi + Math.imul(ah7, bh6)) | 0;
1581 lo = (lo + Math.imul(al6, bl7)) | 0;
1582 mid = (mid + Math.imul(al6, bh7)) | 0;
1583 mid = (mid + Math.imul(ah6, bl7)) | 0;
1584 hi = (hi + Math.imul(ah6, bh7)) | 0;
1585 lo = (lo + Math.imul(al5, bl8)) | 0;
1586 mid = (mid + Math.imul(al5, bh8)) | 0;
1587 mid = (mid + Math.imul(ah5, bl8)) | 0;
1588 hi = (hi + Math.imul(ah5, bh8)) | 0;
1589 lo = (lo + Math.imul(al4, bl9)) | 0;
1590 mid = (mid + Math.imul(al4, bh9)) | 0;
1591 mid = (mid + Math.imul(ah4, bl9)) | 0;
1592 hi = (hi + Math.imul(ah4, bh9)) | 0;
1593 var w13 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1594 c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0;
1595 w13 &= 0x3ffffff;
1596 lo = Math.imul(al9, bl5);
1597 mid = Math.imul(al9, bh5);
1598 mid = (mid + Math.imul(ah9, bl5)) | 0;
1599 hi = Math.imul(ah9, bh5);
1600 lo = (lo + Math.imul(al8, bl6)) | 0;
1601 mid = (mid + Math.imul(al8, bh6)) | 0;
1602 mid = (mid + Math.imul(ah8, bl6)) | 0;
1603 hi = (hi + Math.imul(ah8, bh6)) | 0;
1604 lo = (lo + Math.imul(al7, bl7)) | 0;
1605 mid = (mid + Math.imul(al7, bh7)) | 0;
1606 mid = (mid + Math.imul(ah7, bl7)) | 0;
1607 hi = (hi + Math.imul(ah7, bh7)) | 0;
1608 lo = (lo + Math.imul(al6, bl8)) | 0;
1609 mid = (mid + Math.imul(al6, bh8)) | 0;
1610 mid = (mid + Math.imul(ah6, bl8)) | 0;
1611 hi = (hi + Math.imul(ah6, bh8)) | 0;
1612 lo = (lo + Math.imul(al5, bl9)) | 0;
1613 mid = (mid + Math.imul(al5, bh9)) | 0;
1614 mid = (mid + Math.imul(ah5, bl9)) | 0;
1615 hi = (hi + Math.imul(ah5, bh9)) | 0;
1616 var w14 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1617 c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0;
1618 w14 &= 0x3ffffff;
1619 lo = Math.imul(al9, bl6);
1620 mid = Math.imul(al9, bh6);
1621 mid = (mid + Math.imul(ah9, bl6)) | 0;
1622 hi = Math.imul(ah9, bh6);
1623 lo = (lo + Math.imul(al8, bl7)) | 0;
1624 mid = (mid + Math.imul(al8, bh7)) | 0;
1625 mid = (mid + Math.imul(ah8, bl7)) | 0;
1626 hi = (hi + Math.imul(ah8, bh7)) | 0;
1627 lo = (lo + Math.imul(al7, bl8)) | 0;
1628 mid = (mid + Math.imul(al7, bh8)) | 0;
1629 mid = (mid + Math.imul(ah7, bl8)) | 0;
1630 hi = (hi + Math.imul(ah7, bh8)) | 0;
1631 lo = (lo + Math.imul(al6, bl9)) | 0;
1632 mid = (mid + Math.imul(al6, bh9)) | 0;
1633 mid = (mid + Math.imul(ah6, bl9)) | 0;
1634 hi = (hi + Math.imul(ah6, bh9)) | 0;
1635 var w15 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1636 c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0;
1637 w15 &= 0x3ffffff;
1638 lo = Math.imul(al9, bl7);
1639 mid = Math.imul(al9, bh7);
1640 mid = (mid + Math.imul(ah9, bl7)) | 0;
1641 hi = Math.imul(ah9, bh7);
1642 lo = (lo + Math.imul(al8, bl8)) | 0;
1643 mid = (mid + Math.imul(al8, bh8)) | 0;
1644 mid = (mid + Math.imul(ah8, bl8)) | 0;
1645 hi = (hi + Math.imul(ah8, bh8)) | 0;
1646 lo = (lo + Math.imul(al7, bl9)) | 0;
1647 mid = (mid + Math.imul(al7, bh9)) | 0;
1648 mid = (mid + Math.imul(ah7, bl9)) | 0;
1649 hi = (hi + Math.imul(ah7, bh9)) | 0;
1650 var w16 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1651 c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0;
1652 w16 &= 0x3ffffff;
1653 lo = Math.imul(al9, bl8);
1654 mid = Math.imul(al9, bh8);
1655 mid = (mid + Math.imul(ah9, bl8)) | 0;
1656 hi = Math.imul(ah9, bh8);
1657 lo = (lo + Math.imul(al8, bl9)) | 0;
1658 mid = (mid + Math.imul(al8, bh9)) | 0;
1659 mid = (mid + Math.imul(ah8, bl9)) | 0;
1660 hi = (hi + Math.imul(ah8, bh9)) | 0;
1661 var w17 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1662 c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0;
1663 w17 &= 0x3ffffff;
1664 lo = Math.imul(al9, bl9);
1665 mid = Math.imul(al9, bh9);
1666 mid = (mid + Math.imul(ah9, bl9)) | 0;
1667 hi = Math.imul(ah9, bh9);
1668 var w18 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
1669 c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0;
1670 w18 &= 0x3ffffff;
1671 o[0] = w0;
1672 o[1] = w1;
1673 o[2] = w2;
1674 o[3] = w3;
1675 o[4] = w4;
1676 o[5] = w5;
1677 o[6] = w6;
1678 o[7] = w7;
1679 o[8] = w8;
1680 o[9] = w9;
1681 o[10] = w10;
1682 o[11] = w11;
1683 o[12] = w12;
1684 o[13] = w13;
1685 o[14] = w14;
1686 o[15] = w15;
1687 o[16] = w16;
1688 o[17] = w17;
1689 o[18] = w18;
1690 if (c !== 0) {
1691 o[19] = c;
1692 out.length++;
1693 }
1694 return out;
1695 };
1696 if (!Math.imul) {
1697 comb10MulTo = smallMulTo;
1698 }
1699 function bigMulTo (self, num, out) {
1700 out.negative = num.negative ^ self.negative;
1701 out.length = self.length + num.length;
1702 var carry = 0;
1703 var hncarry = 0;
1704 for (var k = 0; k < out.length - 1; k++) {
1705 var ncarry = hncarry;
1706 hncarry = 0;
1707 var rword = carry & 0x3ffffff;
1708 var maxJ = Math.min(k, num.length - 1);
1709 for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
1710 var i = k - j;
1711 var a = self.words[i] | 0;
1712 var b = num.words[j] | 0;
1713 var r = a * b;
1714 var lo = r & 0x3ffffff;
1715 ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0;
1716 lo = (lo + rword) | 0;
1717 rword = lo & 0x3ffffff;
1718 ncarry = (ncarry + (lo >>> 26)) | 0;
1719 hncarry += ncarry >>> 26;
1720 ncarry &= 0x3ffffff;
1721 }
1722 out.words[k] = rword;
1723 carry = ncarry;
1724 ncarry = hncarry;
1725 }
1726 if (carry !== 0) {
1727 out.words[k] = carry;
1728 } else {
1729 out.length--;
1730 }
1731 return out._strip();
1732 }
1733 function jumboMulTo (self, num, out) {
1734 return bigMulTo(self, num, out);
1735 }
1736 BN.prototype.mulTo = function mulTo (num, out) {
1737 var res;
1738 var len = this.length + num.length;
1739 if (this.length === 10 && num.length === 10) {
1740 res = comb10MulTo(this, num, out);
1741 } else if (len < 63) {
1742 res = smallMulTo(this, num, out);
1743 } else if (len < 1024) {
1744 res = bigMulTo(this, num, out);
1745 } else {
1746 res = jumboMulTo(this, num, out);
1747 }
1748 return res;
1749 };
1750 BN.prototype.mul = function mul (num) {
1751 var out = new BN(null);
1752 out.words = new Array(this.length + num.length);
1753 return this.mulTo(num, out);
1754 };
1755 BN.prototype.mulf = function mulf (num) {
1756 var out = new BN(null);
1757 out.words = new Array(this.length + num.length);
1758 return jumboMulTo(this, num, out);
1759 };
1760 BN.prototype.imul = function imul (num) {
1761 return this.clone().mulTo(num, this);
1762 };
1763 BN.prototype.imuln = function imuln (num) {
1764 var isNegNum = num < 0;
1765 if (isNegNum) num = -num;
1766 assert(typeof num === 'number');
1767 assert(num < 0x4000000);
1768 var carry = 0;
1769 for (var i = 0; i < this.length; i++) {
1770 var w = (this.words[i] | 0) * num;
1771 var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
1772 carry >>= 26;
1773 carry += (w / 0x4000000) | 0;
1774 carry += lo >>> 26;
1775 this.words[i] = lo & 0x3ffffff;
1776 }
1777 if (carry !== 0) {
1778 this.words[i] = carry;
1779 this.length++;
1780 }
1781 return isNegNum ? this.ineg() : this;
1782 };
1783 BN.prototype.muln = function muln (num) {
1784 return this.clone().imuln(num);
1785 };
1786 BN.prototype.sqr = function sqr () {
1787 return this.mul(this);
1788 };
1789 BN.prototype.isqr = function isqr () {
1790 return this.imul(this.clone());
1791 };
1792 BN.prototype.pow = function pow (num) {
1793 var w = toBitArray(num);
1794 if (w.length === 0) return new BN(1);
1795 var res = this;
1796 for (var i = 0; i < w.length; i++, res = res.sqr()) {
1797 if (w[i] !== 0) break;
1798 }
1799 if (++i < w.length) {
1800 for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
1801 if (w[i] === 0) continue;
1802 res = res.mul(q);
1803 }
1804 }
1805 return res;
1806 };
1807 BN.prototype.iushln = function iushln (bits) {
1808 assert(typeof bits === 'number' && bits >= 0);
1809 var r = bits % 26;
1810 var s = (bits - r) / 26;
1811 var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r);
1812 var i;
1813 if (r !== 0) {
1814 var carry = 0;
1815 for (i = 0; i < this.length; i++) {
1816 var newCarry = this.words[i] & carryMask;
1817 var c = ((this.words[i] | 0) - newCarry) << r;
1818 this.words[i] = c | carry;
1819 carry = newCarry >>> (26 - r);
1820 }
1821 if (carry) {
1822 this.words[i] = carry;
1823 this.length++;
1824 }
1825 }
1826 if (s !== 0) {
1827 for (i = this.length - 1; i >= 0; i--) {
1828 this.words[i + s] = this.words[i];
1829 }
1830 for (i = 0; i < s; i++) {
1831 this.words[i] = 0;
1832 }
1833 this.length += s;
1834 }
1835 return this._strip();
1836 };
1837 BN.prototype.ishln = function ishln (bits) {
1838 assert(this.negative === 0);
1839 return this.iushln(bits);
1840 };
1841 BN.prototype.iushrn = function iushrn (bits, hint, extended) {
1842 assert(typeof bits === 'number' && bits >= 0);
1843 var h;
1844 if (hint) {
1845 h = (hint - (hint % 26)) / 26;
1846 } else {
1847 h = 0;
1848 }
1849 var r = bits % 26;
1850 var s = Math.min((bits - r) / 26, this.length);
1851 var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
1852 var maskedWords = extended;
1853 h -= s;
1854 h = Math.max(0, h);
1855 if (maskedWords) {
1856 for (var i = 0; i < s; i++) {
1857 maskedWords.words[i] = this.words[i];
1858 }
1859 maskedWords.length = s;
1860 }
1861 if (s === 0) ; else if (this.length > s) {
1862 this.length -= s;
1863 for (i = 0; i < this.length; i++) {
1864 this.words[i] = this.words[i + s];
1865 }
1866 } else {
1867 this.words[0] = 0;
1868 this.length = 1;
1869 }
1870 var carry = 0;
1871 for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
1872 var word = this.words[i] | 0;
1873 this.words[i] = (carry << (26 - r)) | (word >>> r);
1874 carry = word & mask;
1875 }
1876 if (maskedWords && carry !== 0) {
1877 maskedWords.words[maskedWords.length++] = carry;
1878 }
1879 if (this.length === 0) {
1880 this.words[0] = 0;
1881 this.length = 1;
1882 }
1883 return this._strip();
1884 };
1885 BN.prototype.ishrn = function ishrn (bits, hint, extended) {
1886 assert(this.negative === 0);
1887 return this.iushrn(bits, hint, extended);
1888 };
1889 BN.prototype.shln = function shln (bits) {
1890 return this.clone().ishln(bits);
1891 };
1892 BN.prototype.ushln = function ushln (bits) {
1893 return this.clone().iushln(bits);
1894 };
1895 BN.prototype.shrn = function shrn (bits) {
1896 return this.clone().ishrn(bits);
1897 };
1898 BN.prototype.ushrn = function ushrn (bits) {
1899 return this.clone().iushrn(bits);
1900 };
1901 BN.prototype.testn = function testn (bit) {
1902 assert(typeof bit === 'number' && bit >= 0);
1903 var r = bit % 26;
1904 var s = (bit - r) / 26;
1905 var q = 1 << r;
1906 if (this.length <= s) return false;
1907 var w = this.words[s];
1908 return !!(w & q);
1909 };
1910 BN.prototype.imaskn = function imaskn (bits) {
1911 assert(typeof bits === 'number' && bits >= 0);
1912 var r = bits % 26;
1913 var s = (bits - r) / 26;
1914 assert(this.negative === 0, 'imaskn works only with positive numbers');
1915 if (this.length <= s) {
1916 return this;
1917 }
1918 if (r !== 0) {
1919 s++;
1920 }
1921 this.length = Math.min(s, this.length);
1922 if (r !== 0) {
1923 var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
1924 this.words[this.length - 1] &= mask;
1925 }
1926 return this._strip();
1927 };
1928 BN.prototype.maskn = function maskn (bits) {
1929 return this.clone().imaskn(bits);
1930 };
1931 BN.prototype.iaddn = function iaddn (num) {
1932 assert(typeof num === 'number');
1933 assert(num < 0x4000000);
1934 if (num < 0) return this.isubn(-num);
1935 if (this.negative !== 0) {
1936 if (this.length === 1 && (this.words[0] | 0) <= num) {
1937 this.words[0] = num - (this.words[0] | 0);
1938 this.negative = 0;
1939 return this;
1940 }
1941 this.negative = 0;
1942 this.isubn(num);
1943 this.negative = 1;
1944 return this;
1945 }
1946 return this._iaddn(num);
1947 };
1948 BN.prototype._iaddn = function _iaddn (num) {
1949 this.words[0] += num;
1950 for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
1951 this.words[i] -= 0x4000000;
1952 if (i === this.length - 1) {
1953 this.words[i + 1] = 1;
1954 } else {
1955 this.words[i + 1]++;
1956 }
1957 }
1958 this.length = Math.max(this.length, i + 1);
1959 return this;
1960 };
1961 BN.prototype.isubn = function isubn (num) {
1962 assert(typeof num === 'number');
1963 assert(num < 0x4000000);
1964 if (num < 0) return this.iaddn(-num);
1965 if (this.negative !== 0) {
1966 this.negative = 0;
1967 this.iaddn(num);
1968 this.negative = 1;
1969 return this;
1970 }
1971 this.words[0] -= num;
1972 if (this.length === 1 && this.words[0] < 0) {
1973 this.words[0] = -this.words[0];
1974 this.negative = 1;
1975 } else {
1976 for (var i = 0; i < this.length && this.words[i] < 0; i++) {
1977 this.words[i] += 0x4000000;
1978 this.words[i + 1] -= 1;
1979 }
1980 }
1981 return this._strip();
1982 };
1983 BN.prototype.addn = function addn (num) {
1984 return this.clone().iaddn(num);
1985 };
1986 BN.prototype.subn = function subn (num) {
1987 return this.clone().isubn(num);
1988 };
1989 BN.prototype.iabs = function iabs () {
1990 this.negative = 0;
1991 return this;
1992 };
1993 BN.prototype.abs = function abs () {
1994 return this.clone().iabs();
1995 };
1996 BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) {
1997 var len = num.length + shift;
1998 var i;
1999 this._expand(len);
2000 var w;
2001 var carry = 0;
2002 for (i = 0; i < num.length; i++) {
2003 w = (this.words[i + shift] | 0) + carry;
2004 var right = (num.words[i] | 0) * mul;
2005 w -= right & 0x3ffffff;
2006 carry = (w >> 26) - ((right / 0x4000000) | 0);
2007 this.words[i + shift] = w & 0x3ffffff;
2008 }
2009 for (; i < this.length - shift; i++) {
2010 w = (this.words[i + shift] | 0) + carry;
2011 carry = w >> 26;
2012 this.words[i + shift] = w & 0x3ffffff;
2013 }
2014 if (carry === 0) return this._strip();
2015 assert(carry === -1);
2016 carry = 0;
2017 for (i = 0; i < this.length; i++) {
2018 w = -(this.words[i] | 0) + carry;
2019 carry = w >> 26;
2020 this.words[i] = w & 0x3ffffff;
2021 }
2022 this.negative = 1;
2023 return this._strip();
2024 };
2025 BN.prototype._wordDiv = function _wordDiv (num, mode) {
2026 var shift = this.length - num.length;
2027 var a = this.clone();
2028 var b = num;
2029 var bhi = b.words[b.length - 1] | 0;
2030 var bhiBits = this._countBits(bhi);
2031 shift = 26 - bhiBits;
2032 if (shift !== 0) {
2033 b = b.ushln(shift);
2034 a.iushln(shift);
2035 bhi = b.words[b.length - 1] | 0;
2036 }
2037 var m = a.length - b.length;
2038 var q;
2039 if (mode !== 'mod') {
2040 q = new BN(null);
2041 q.length = m + 1;
2042 q.words = new Array(q.length);
2043 for (var i = 0; i < q.length; i++) {
2044 q.words[i] = 0;
2045 }
2046 }
2047 var diff = a.clone()._ishlnsubmul(b, 1, m);
2048 if (diff.negative === 0) {
2049 a = diff;
2050 if (q) {
2051 q.words[m] = 1;
2052 }
2053 }
2054 for (var j = m - 1; j >= 0; j--) {
2055 var qj = (a.words[b.length + j] | 0) * 0x4000000 +
2056 (a.words[b.length + j - 1] | 0);
2057 qj = Math.min((qj / bhi) | 0, 0x3ffffff);
2058 a._ishlnsubmul(b, qj, j);
2059 while (a.negative !== 0) {
2060 qj--;
2061 a.negative = 0;
2062 a._ishlnsubmul(b, 1, j);
2063 if (!a.isZero()) {
2064 a.negative ^= 1;
2065 }
2066 }
2067 if (q) {
2068 q.words[j] = qj;
2069 }
2070 }
2071 if (q) {
2072 q._strip();
2073 }
2074 a._strip();
2075 if (mode !== 'div' && shift !== 0) {
2076 a.iushrn(shift);
2077 }
2078 return {
2079 div: q || null,
2080 mod: a
2081 };
2082 };
2083 BN.prototype.divmod = function divmod (num, mode, positive) {
2084 assert(!num.isZero());
2085 if (this.isZero()) {
2086 return {
2087 div: new BN(0),
2088 mod: new BN(0)
2089 };
2090 }
2091 var div, mod, res;
2092 if (this.negative !== 0 && num.negative === 0) {
2093 res = this.neg().divmod(num, mode);
2094 if (mode !== 'mod') {
2095 div = res.div.neg();
2096 }
2097 if (mode !== 'div') {
2098 mod = res.mod.neg();
2099 if (positive && mod.negative !== 0) {
2100 mod.iadd(num);
2101 }
2102 }
2103 return {
2104 div: div,
2105 mod: mod
2106 };
2107 }
2108 if (this.negative === 0 && num.negative !== 0) {
2109 res = this.divmod(num.neg(), mode);
2110 if (mode !== 'mod') {
2111 div = res.div.neg();
2112 }
2113 return {
2114 div: div,
2115 mod: res.mod
2116 };
2117 }
2118 if ((this.negative & num.negative) !== 0) {
2119 res = this.neg().divmod(num.neg(), mode);
2120 if (mode !== 'div') {
2121 mod = res.mod.neg();
2122 if (positive && mod.negative !== 0) {
2123 mod.isub(num);
2124 }
2125 }
2126 return {
2127 div: res.div,
2128 mod: mod
2129 };
2130 }
2131 if (num.length > this.length || this.cmp(num) < 0) {
2132 return {
2133 div: new BN(0),
2134 mod: this
2135 };
2136 }
2137 if (num.length === 1) {
2138 if (mode === 'div') {
2139 return {
2140 div: this.divn(num.words[0]),
2141 mod: null
2142 };
2143 }
2144 if (mode === 'mod') {
2145 return {
2146 div: null,
2147 mod: new BN(this.modrn(num.words[0]))
2148 };
2149 }
2150 return {
2151 div: this.divn(num.words[0]),
2152 mod: new BN(this.modrn(num.words[0]))
2153 };
2154 }
2155 return this._wordDiv(num, mode);
2156 };
2157 BN.prototype.div = function div (num) {
2158 return this.divmod(num, 'div', false).div;
2159 };
2160 BN.prototype.mod = function mod (num) {
2161 return this.divmod(num, 'mod', false).mod;
2162 };
2163 BN.prototype.umod = function umod (num) {
2164 return this.divmod(num, 'mod', true).mod;
2165 };
2166 BN.prototype.divRound = function divRound (num) {
2167 var dm = this.divmod(num);
2168 if (dm.mod.isZero()) return dm.div;
2169 var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
2170 var half = num.ushrn(1);
2171 var r2 = num.andln(1);
2172 var cmp = mod.cmp(half);
2173 if (cmp < 0 || (r2 === 1 && cmp === 0)) return dm.div;
2174 return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
2175 };
2176 BN.prototype.modrn = function modrn (num) {
2177 var isNegNum = num < 0;
2178 if (isNegNum) num = -num;
2179 assert(num <= 0x3ffffff);
2180 var p = (1 << 26) % num;
2181 var acc = 0;
2182 for (var i = this.length - 1; i >= 0; i--) {
2183 acc = (p * acc + (this.words[i] | 0)) % num;
2184 }
2185 return isNegNum ? -acc : acc;
2186 };
2187 BN.prototype.modn = function modn (num) {
2188 return this.modrn(num);
2189 };
2190 BN.prototype.idivn = function idivn (num) {
2191 var isNegNum = num < 0;
2192 if (isNegNum) num = -num;
2193 assert(num <= 0x3ffffff);
2194 var carry = 0;
2195 for (var i = this.length - 1; i >= 0; i--) {
2196 var w = (this.words[i] | 0) + carry * 0x4000000;
2197 this.words[i] = (w / num) | 0;
2198 carry = w % num;
2199 }
2200 this._strip();
2201 return isNegNum ? this.ineg() : this;
2202 };
2203 BN.prototype.divn = function divn (num) {
2204 return this.clone().idivn(num);
2205 };
2206 BN.prototype.egcd = function egcd (p) {
2207 assert(p.negative === 0);
2208 assert(!p.isZero());
2209 var x = this;
2210 var y = p.clone();
2211 if (x.negative !== 0) {
2212 x = x.umod(p);
2213 } else {
2214 x = x.clone();
2215 }
2216 var A = new BN(1);
2217 var B = new BN(0);
2218 var C = new BN(0);
2219 var D = new BN(1);
2220 var g = 0;
2221 while (x.isEven() && y.isEven()) {
2222 x.iushrn(1);
2223 y.iushrn(1);
2224 ++g;
2225 }
2226 var yp = y.clone();
2227 var xp = x.clone();
2228 while (!x.isZero()) {
2229 for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
2230 if (i > 0) {
2231 x.iushrn(i);
2232 while (i-- > 0) {
2233 if (A.isOdd() || B.isOdd()) {
2234 A.iadd(yp);
2235 B.isub(xp);
2236 }
2237 A.iushrn(1);
2238 B.iushrn(1);
2239 }
2240 }
2241 for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
2242 if (j > 0) {
2243 y.iushrn(j);
2244 while (j-- > 0) {
2245 if (C.isOdd() || D.isOdd()) {
2246 C.iadd(yp);
2247 D.isub(xp);
2248 }
2249 C.iushrn(1);
2250 D.iushrn(1);
2251 }
2252 }
2253 if (x.cmp(y) >= 0) {
2254 x.isub(y);
2255 A.isub(C);
2256 B.isub(D);
2257 } else {
2258 y.isub(x);
2259 C.isub(A);
2260 D.isub(B);
2261 }
2262 }
2263 return {
2264 a: C,
2265 b: D,
2266 gcd: y.iushln(g)
2267 };
2268 };
2269 BN.prototype._invmp = function _invmp (p) {
2270 assert(p.negative === 0);
2271 assert(!p.isZero());
2272 var a = this;
2273 var b = p.clone();
2274 if (a.negative !== 0) {
2275 a = a.umod(p);
2276 } else {
2277 a = a.clone();
2278 }
2279 var x1 = new BN(1);
2280 var x2 = new BN(0);
2281 var delta = b.clone();
2282 while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
2283 for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
2284 if (i > 0) {
2285 a.iushrn(i);
2286 while (i-- > 0) {
2287 if (x1.isOdd()) {
2288 x1.iadd(delta);
2289 }
2290 x1.iushrn(1);
2291 }
2292 }
2293 for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
2294 if (j > 0) {
2295 b.iushrn(j);
2296 while (j-- > 0) {
2297 if (x2.isOdd()) {
2298 x2.iadd(delta);
2299 }
2300 x2.iushrn(1);
2301 }
2302 }
2303 if (a.cmp(b) >= 0) {
2304 a.isub(b);
2305 x1.isub(x2);
2306 } else {
2307 b.isub(a);
2308 x2.isub(x1);
2309 }
2310 }
2311 var res;
2312 if (a.cmpn(1) === 0) {
2313 res = x1;
2314 } else {
2315 res = x2;
2316 }
2317 if (res.cmpn(0) < 0) {
2318 res.iadd(p);
2319 }
2320 return res;
2321 };
2322 BN.prototype.gcd = function gcd (num) {
2323 if (this.isZero()) return num.abs();
2324 if (num.isZero()) return this.abs();
2325 var a = this.clone();
2326 var b = num.clone();
2327 a.negative = 0;
2328 b.negative = 0;
2329 for (var shift = 0; a.isEven() && b.isEven(); shift++) {
2330 a.iushrn(1);
2331 b.iushrn(1);
2332 }
2333 do {
2334 while (a.isEven()) {
2335 a.iushrn(1);
2336 }
2337 while (b.isEven()) {
2338 b.iushrn(1);
2339 }
2340 var r = a.cmp(b);
2341 if (r < 0) {
2342 var t = a;
2343 a = b;
2344 b = t;
2345 } else if (r === 0 || b.cmpn(1) === 0) {
2346 break;
2347 }
2348 a.isub(b);
2349 } while (true);
2350 return b.iushln(shift);
2351 };
2352 BN.prototype.invm = function invm (num) {
2353 return this.egcd(num).a.umod(num);
2354 };
2355 BN.prototype.isEven = function isEven () {
2356 return (this.words[0] & 1) === 0;
2357 };
2358 BN.prototype.isOdd = function isOdd () {
2359 return (this.words[0] & 1) === 1;
2360 };
2361 BN.prototype.andln = function andln (num) {
2362 return this.words[0] & num;
2363 };
2364 BN.prototype.bincn = function bincn (bit) {
2365 assert(typeof bit === 'number');
2366 var r = bit % 26;
2367 var s = (bit - r) / 26;
2368 var q = 1 << r;
2369 if (this.length <= s) {
2370 this._expand(s + 1);
2371 this.words[s] |= q;
2372 return this;
2373 }
2374 var carry = q;
2375 for (var i = s; carry !== 0 && i < this.length; i++) {
2376 var w = this.words[i] | 0;
2377 w += carry;
2378 carry = w >>> 26;
2379 w &= 0x3ffffff;
2380 this.words[i] = w;
2381 }
2382 if (carry !== 0) {
2383 this.words[i] = carry;
2384 this.length++;
2385 }
2386 return this;
2387 };
2388 BN.prototype.isZero = function isZero () {
2389 return this.length === 1 && this.words[0] === 0;
2390 };
2391 BN.prototype.cmpn = function cmpn (num) {
2392 var negative = num < 0;
2393 if (this.negative !== 0 && !negative) return -1;
2394 if (this.negative === 0 && negative) return 1;
2395 this._strip();
2396 var res;
2397 if (this.length > 1) {
2398 res = 1;
2399 } else {
2400 if (negative) {
2401 num = -num;
2402 }
2403 assert(num <= 0x3ffffff, 'Number is too big');
2404 var w = this.words[0] | 0;
2405 res = w === num ? 0 : w < num ? -1 : 1;
2406 }
2407 if (this.negative !== 0) return -res | 0;
2408 return res;
2409 };
2410 BN.prototype.cmp = function cmp (num) {
2411 if (this.negative !== 0 && num.negative === 0) return -1;
2412 if (this.negative === 0 && num.negative !== 0) return 1;
2413 var res = this.ucmp(num);
2414 if (this.negative !== 0) return -res | 0;
2415 return res;
2416 };
2417 BN.prototype.ucmp = function ucmp (num) {
2418 if (this.length > num.length) return 1;
2419 if (this.length < num.length) return -1;
2420 var res = 0;
2421 for (var i = this.length - 1; i >= 0; i--) {
2422 var a = this.words[i] | 0;
2423 var b = num.words[i] | 0;
2424 if (a === b) continue;
2425 if (a < b) {
2426 res = -1;
2427 } else if (a > b) {
2428 res = 1;
2429 }
2430 break;
2431 }
2432 return res;
2433 };
2434 BN.prototype.gtn = function gtn (num) {
2435 return this.cmpn(num) === 1;
2436 };
2437 BN.prototype.gt = function gt (num) {
2438 return this.cmp(num) === 1;
2439 };
2440 BN.prototype.gten = function gten (num) {
2441 return this.cmpn(num) >= 0;
2442 };
2443 BN.prototype.gte = function gte (num) {
2444 return this.cmp(num) >= 0;
2445 };
2446 BN.prototype.ltn = function ltn (num) {
2447 return this.cmpn(num) === -1;
2448 };
2449 BN.prototype.lt = function lt (num) {
2450 return this.cmp(num) === -1;
2451 };
2452 BN.prototype.lten = function lten (num) {
2453 return this.cmpn(num) <= 0;
2454 };
2455 BN.prototype.lte = function lte (num) {
2456 return this.cmp(num) <= 0;
2457 };
2458 BN.prototype.eqn = function eqn (num) {
2459 return this.cmpn(num) === 0;
2460 };
2461 BN.prototype.eq = function eq (num) {
2462 return this.cmp(num) === 0;
2463 };
2464 BN.red = function red (num) {
2465 return new Red(num);
2466 };
2467 BN.prototype.toRed = function toRed (ctx) {
2468 assert(!this.red, 'Already a number in reduction context');
2469 assert(this.negative === 0, 'red works only with positives');
2470 return ctx.convertTo(this)._forceRed(ctx);
2471 };
2472 BN.prototype.fromRed = function fromRed () {
2473 assert(this.red, 'fromRed works only with numbers in reduction context');
2474 return this.red.convertFrom(this);
2475 };
2476 BN.prototype._forceRed = function _forceRed (ctx) {
2477 this.red = ctx;
2478 return this;
2479 };
2480 BN.prototype.forceRed = function forceRed (ctx) {
2481 assert(!this.red, 'Already a number in reduction context');
2482 return this._forceRed(ctx);
2483 };
2484 BN.prototype.redAdd = function redAdd (num) {
2485 assert(this.red, 'redAdd works only with red numbers');
2486 return this.red.add(this, num);
2487 };
2488 BN.prototype.redIAdd = function redIAdd (num) {
2489 assert(this.red, 'redIAdd works only with red numbers');
2490 return this.red.iadd(this, num);
2491 };
2492 BN.prototype.redSub = function redSub (num) {
2493 assert(this.red, 'redSub works only with red numbers');
2494 return this.red.sub(this, num);
2495 };
2496 BN.prototype.redISub = function redISub (num) {
2497 assert(this.red, 'redISub works only with red numbers');
2498 return this.red.isub(this, num);
2499 };
2500 BN.prototype.redShl = function redShl (num) {
2501 assert(this.red, 'redShl works only with red numbers');
2502 return this.red.shl(this, num);
2503 };
2504 BN.prototype.redMul = function redMul (num) {
2505 assert(this.red, 'redMul works only with red numbers');
2506 this.red._verify2(this, num);
2507 return this.red.mul(this, num);
2508 };
2509 BN.prototype.redIMul = function redIMul (num) {
2510 assert(this.red, 'redMul works only with red numbers');
2511 this.red._verify2(this, num);
2512 return this.red.imul(this, num);
2513 };
2514 BN.prototype.redSqr = function redSqr () {
2515 assert(this.red, 'redSqr works only with red numbers');
2516 this.red._verify1(this);
2517 return this.red.sqr(this);
2518 };
2519 BN.prototype.redISqr = function redISqr () {
2520 assert(this.red, 'redISqr works only with red numbers');
2521 this.red._verify1(this);
2522 return this.red.isqr(this);
2523 };
2524 BN.prototype.redSqrt = function redSqrt () {
2525 assert(this.red, 'redSqrt works only with red numbers');
2526 this.red._verify1(this);
2527 return this.red.sqrt(this);
2528 };
2529 BN.prototype.redInvm = function redInvm () {
2530 assert(this.red, 'redInvm works only with red numbers');
2531 this.red._verify1(this);
2532 return this.red.invm(this);
2533 };
2534 BN.prototype.redNeg = function redNeg () {
2535 assert(this.red, 'redNeg works only with red numbers');
2536 this.red._verify1(this);
2537 return this.red.neg(this);
2538 };
2539 BN.prototype.redPow = function redPow (num) {
2540 assert(this.red && !num.red, 'redPow(normalNum)');
2541 this.red._verify1(this);
2542 return this.red.pow(this, num);
2543 };
2544 var primes = {
2545 k256: null,
2546 p224: null,
2547 p192: null,
2548 p25519: null
2549 };
2550 function MPrime (name, p) {
2551 this.name = name;
2552 this.p = new BN(p, 16);
2553 this.n = this.p.bitLength();
2554 this.k = new BN(1).iushln(this.n).isub(this.p);
2555 this.tmp = this._tmp();
2556 }
2557 MPrime.prototype._tmp = function _tmp () {
2558 var tmp = new BN(null);
2559 tmp.words = new Array(Math.ceil(this.n / 13));
2560 return tmp;
2561 };
2562 MPrime.prototype.ireduce = function ireduce (num) {
2563 var r = num;
2564 var rlen;
2565 do {
2566 this.split(r, this.tmp);
2567 r = this.imulK(r);
2568 r = r.iadd(this.tmp);
2569 rlen = r.bitLength();
2570 } while (rlen > this.n);
2571 var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
2572 if (cmp === 0) {
2573 r.words[0] = 0;
2574 r.length = 1;
2575 } else if (cmp > 0) {
2576 r.isub(this.p);
2577 } else {
2578 if (r.strip !== undefined) {
2579 r.strip();
2580 } else {
2581 r._strip();
2582 }
2583 }
2584 return r;
2585 };
2586 MPrime.prototype.split = function split (input, out) {
2587 input.iushrn(this.n, 0, out);
2588 };
2589 MPrime.prototype.imulK = function imulK (num) {
2590 return num.imul(this.k);
2591 };
2592 function K256 () {
2593 MPrime.call(
2594 this,
2595 'k256',
2596 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
2597 }
2598 inherits(K256, MPrime);
2599 K256.prototype.split = function split (input, output) {
2600 var mask = 0x3fffff;
2601 var outLen = Math.min(input.length, 9);
2602 for (var i = 0; i < outLen; i++) {
2603 output.words[i] = input.words[i];
2604 }
2605 output.length = outLen;
2606 if (input.length <= 9) {
2607 input.words[0] = 0;
2608 input.length = 1;
2609 return;
2610 }
2611 var prev = input.words[9];
2612 output.words[output.length++] = prev & mask;
2613 for (i = 10; i < input.length; i++) {
2614 var next = input.words[i] | 0;
2615 input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22);
2616 prev = next;
2617 }
2618 prev >>>= 22;
2619 input.words[i - 10] = prev;
2620 if (prev === 0 && input.length > 10) {
2621 input.length -= 10;
2622 } else {
2623 input.length -= 9;
2624 }
2625 };
2626 K256.prototype.imulK = function imulK (num) {
2627 num.words[num.length] = 0;
2628 num.words[num.length + 1] = 0;
2629 num.length += 2;
2630 var lo = 0;
2631 for (var i = 0; i < num.length; i++) {
2632 var w = num.words[i] | 0;
2633 lo += w * 0x3d1;
2634 num.words[i] = lo & 0x3ffffff;
2635 lo = w * 0x40 + ((lo / 0x4000000) | 0);
2636 }
2637 if (num.words[num.length - 1] === 0) {
2638 num.length--;
2639 if (num.words[num.length - 1] === 0) {
2640 num.length--;
2641 }
2642 }
2643 return num;
2644 };
2645 function P224 () {
2646 MPrime.call(
2647 this,
2648 'p224',
2649 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
2650 }
2651 inherits(P224, MPrime);
2652 function P192 () {
2653 MPrime.call(
2654 this,
2655 'p192',
2656 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
2657 }
2658 inherits(P192, MPrime);
2659 function P25519 () {
2660 MPrime.call(
2661 this,
2662 '25519',
2663 '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
2664 }
2665 inherits(P25519, MPrime);
2666 P25519.prototype.imulK = function imulK (num) {
2667 var carry = 0;
2668 for (var i = 0; i < num.length; i++) {
2669 var hi = (num.words[i] | 0) * 0x13 + carry;
2670 var lo = hi & 0x3ffffff;
2671 hi >>>= 26;
2672 num.words[i] = lo;
2673 carry = hi;
2674 }
2675 if (carry !== 0) {
2676 num.words[num.length++] = carry;
2677 }
2678 return num;
2679 };
2680 BN._prime = function prime (name) {
2681 if (primes[name]) return primes[name];
2682 var prime;
2683 if (name === 'k256') {
2684 prime = new K256();
2685 } else if (name === 'p224') {
2686 prime = new P224();
2687 } else if (name === 'p192') {
2688 prime = new P192();
2689 } else if (name === 'p25519') {
2690 prime = new P25519();
2691 } else {
2692 throw new Error('Unknown prime ' + name);
2693 }
2694 primes[name] = prime;
2695 return prime;
2696 };
2697 function Red (m) {
2698 if (typeof m === 'string') {
2699 var prime = BN._prime(m);
2700 this.m = prime.p;
2701 this.prime = prime;
2702 } else {
2703 assert(m.gtn(1), 'modulus must be greater than 1');
2704 this.m = m;
2705 this.prime = null;
2706 }
2707 }
2708 Red.prototype._verify1 = function _verify1 (a) {
2709 assert(a.negative === 0, 'red works only with positives');
2710 assert(a.red, 'red works only with red numbers');
2711 };
2712 Red.prototype._verify2 = function _verify2 (a, b) {
2713 assert((a.negative | b.negative) === 0, 'red works only with positives');
2714 assert(a.red && a.red === b.red,
2715 'red works only with red numbers');
2716 };
2717 Red.prototype.imod = function imod (a) {
2718 if (this.prime) return this.prime.ireduce(a)._forceRed(this);
2719 move(a, a.umod(this.m)._forceRed(this));
2720 return a;
2721 };
2722 Red.prototype.neg = function neg (a) {
2723 if (a.isZero()) {
2724 return a.clone();
2725 }
2726 return this.m.sub(a)._forceRed(this);
2727 };
2728 Red.prototype.add = function add (a, b) {
2729 this._verify2(a, b);
2730 var res = a.add(b);
2731 if (res.cmp(this.m) >= 0) {
2732 res.isub(this.m);
2733 }
2734 return res._forceRed(this);
2735 };
2736 Red.prototype.iadd = function iadd (a, b) {
2737 this._verify2(a, b);
2738 var res = a.iadd(b);
2739 if (res.cmp(this.m) >= 0) {
2740 res.isub(this.m);
2741 }
2742 return res;
2743 };
2744 Red.prototype.sub = function sub (a, b) {
2745 this._verify2(a, b);
2746 var res = a.sub(b);
2747 if (res.cmpn(0) < 0) {
2748 res.iadd(this.m);
2749 }
2750 return res._forceRed(this);
2751 };
2752 Red.prototype.isub = function isub (a, b) {
2753 this._verify2(a, b);
2754 var res = a.isub(b);
2755 if (res.cmpn(0) < 0) {
2756 res.iadd(this.m);
2757 }
2758 return res;
2759 };
2760 Red.prototype.shl = function shl (a, num) {
2761 this._verify1(a);
2762 return this.imod(a.ushln(num));
2763 };
2764 Red.prototype.imul = function imul (a, b) {
2765 this._verify2(a, b);
2766 return this.imod(a.imul(b));
2767 };
2768 Red.prototype.mul = function mul (a, b) {
2769 this._verify2(a, b);
2770 return this.imod(a.mul(b));
2771 };
2772 Red.prototype.isqr = function isqr (a) {
2773 return this.imul(a, a.clone());
2774 };
2775 Red.prototype.sqr = function sqr (a) {
2776 return this.mul(a, a);
2777 };
2778 Red.prototype.sqrt = function sqrt (a) {
2779 if (a.isZero()) return a.clone();
2780 var mod3 = this.m.andln(3);
2781 assert(mod3 % 2 === 1);
2782 if (mod3 === 3) {
2783 var pow = this.m.add(new BN(1)).iushrn(2);
2784 return this.pow(a, pow);
2785 }
2786 var q = this.m.subn(1);
2787 var s = 0;
2788 while (!q.isZero() && q.andln(1) === 0) {
2789 s++;
2790 q.iushrn(1);
2791 }
2792 assert(!q.isZero());
2793 var one = new BN(1).toRed(this);
2794 var nOne = one.redNeg();
2795 var lpow = this.m.subn(1).iushrn(1);
2796 var z = this.m.bitLength();
2797 z = new BN(2 * z * z).toRed(this);
2798 while (this.pow(z, lpow).cmp(nOne) !== 0) {
2799 z.redIAdd(nOne);
2800 }
2801 var c = this.pow(z, q);
2802 var r = this.pow(a, q.addn(1).iushrn(1));
2803 var t = this.pow(a, q);
2804 var m = s;
2805 while (t.cmp(one) !== 0) {
2806 var tmp = t;
2807 for (var i = 0; tmp.cmp(one) !== 0; i++) {
2808 tmp = tmp.redSqr();
2809 }
2810 assert(i < m);
2811 var b = this.pow(c, new BN(1).iushln(m - i - 1));
2812 r = r.redMul(b);
2813 c = b.redSqr();
2814 t = t.redMul(c);
2815 m = i;
2816 }
2817 return r;
2818 };
2819 Red.prototype.invm = function invm (a) {
2820 var inv = a._invmp(this.m);
2821 if (inv.negative !== 0) {
2822 inv.negative = 0;
2823 return this.imod(inv).redNeg();
2824 } else {
2825 return this.imod(inv);
2826 }
2827 };
2828 Red.prototype.pow = function pow (a, num) {
2829 if (num.isZero()) return new BN(1).toRed(this);
2830 if (num.cmpn(1) === 0) return a.clone();
2831 var windowSize = 4;
2832 var wnd = new Array(1 << windowSize);
2833 wnd[0] = new BN(1).toRed(this);
2834 wnd[1] = a;
2835 for (var i = 2; i < wnd.length; i++) {
2836 wnd[i] = this.mul(wnd[i - 1], a);
2837 }
2838 var res = wnd[0];
2839 var current = 0;
2840 var currentLen = 0;
2841 var start = num.bitLength() % 26;
2842 if (start === 0) {
2843 start = 26;
2844 }
2845 for (i = num.length - 1; i >= 0; i--) {
2846 var word = num.words[i];
2847 for (var j = start - 1; j >= 0; j--) {
2848 var bit = (word >> j) & 1;
2849 if (res !== wnd[0]) {
2850 res = this.sqr(res);
2851 }
2852 if (bit === 0 && current === 0) {
2853 currentLen = 0;
2854 continue;
2855 }
2856 current <<= 1;
2857 current |= bit;
2858 currentLen++;
2859 if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
2860 res = this.mul(res, wnd[current]);
2861 currentLen = 0;
2862 current = 0;
2863 }
2864 start = 26;
2865 }
2866 return res;
2867 };
2868 Red.prototype.convertTo = function convertTo (num) {
2869 var r = num.umod(this.m);
2870 return r === num ? r.clone() : r;
2871 };
2872 Red.prototype.convertFrom = function convertFrom (num) {
2873 var res = num.clone();
2874 res.red = null;
2875 return res;
2876 };
2877 BN.mont = function mont (num) {
2878 return new Mont(num);
2879 };
2880 function Mont (m) {
2881 Red.call(this, m);
2882 this.shift = this.m.bitLength();
2883 if (this.shift % 26 !== 0) {
2884 this.shift += 26 - (this.shift % 26);
2885 }
2886 this.r = new BN(1).iushln(this.shift);
2887 this.r2 = this.imod(this.r.sqr());
2888 this.rinv = this.r._invmp(this.m);
2889 this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
2890 this.minv = this.minv.umod(this.r);
2891 this.minv = this.r.sub(this.minv);
2892 }
2893 inherits(Mont, Red);
2894 Mont.prototype.convertTo = function convertTo (num) {
2895 return this.imod(num.ushln(this.shift));
2896 };
2897 Mont.prototype.convertFrom = function convertFrom (num) {
2898 var r = this.imod(num.mul(this.rinv));
2899 r.red = null;
2900 return r;
2901 };
2902 Mont.prototype.imul = function imul (a, b) {
2903 if (a.isZero() || b.isZero()) {
2904 a.words[0] = 0;
2905 a.length = 1;
2906 return a;
2907 }
2908 var t = a.imul(b);
2909 var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
2910 var u = t.isub(c).iushrn(this.shift);
2911 var res = u;
2912 if (u.cmp(this.m) >= 0) {
2913 res = u.isub(this.m);
2914 } else if (u.cmpn(0) < 0) {
2915 res = u.iadd(this.m);
2916 }
2917 return res._forceRed(this);
2918 };
2919 Mont.prototype.mul = function mul (a, b) {
2920 if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
2921 var t = a.mul(b);
2922 var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
2923 var u = t.isub(c).iushrn(this.shift);
2924 var res = u;
2925 if (u.cmp(this.m) >= 0) {
2926 res = u.isub(this.m);
2927 } else if (u.cmpn(0) < 0) {
2928 res = u.iadd(this.m);
2929 }
2930 return res._forceRed(this);
2931 };
2932 Mont.prototype.invm = function invm (a) {
2933 var res = this.imod(a._invmp(this.m).mul(this.r2));
2934 return res._forceRed(this);
2935 };
2936 })(module, commonjsGlobal);
2937 } (bn));
2938 const BN = bn.exports;
2939
2940 function isBn(value) {
2941 return BN.isBN(value);
2942 }
2943
2944 function isObject(value) {
2945 return !!value && typeof value === 'object';
2946 }
2947
2948 function isOn(...fns) {
2949 return value => (isObject(value) || isFunction(value)) && fns.every(f => isFunction(value[f]));
2950 }
2951 function isOnObject(...fns) {
2952 return value => isObject(value) && fns.every(f => isFunction(value[f]));
2953 }
2954
2955 const isToBigInt = isOn('toBigInt');
2956
2957 const isToBn = isOn('toBn');
2958
2959 function nToBigInt(value) {
2960 return typeof value === 'bigint' ? value : !value ? BigInt(0) : isHex(value) ? hexToBigInt(value.toString()) : isBn(value) ? BigInt(value.toString()) : isToBigInt(value) ? value.toBigInt() : isToBn(value) ? BigInt(value.toBn().toString()) : BigInt(value);
2961 }
2962
2963 const SQRT_MAX_SAFE_INTEGER$1 = BigInt(94906265);
2964 function nSqrt(value) {
2965 const n = nToBigInt(value);
2966 if (n < _0n) {
2967 throw new Error('square root of negative numbers is not supported');
2968 }
2969 if (n <= _2pow53n) {
2970 return BigInt(~~Math.sqrt(Number(n)));
2971 }
2972 let x0 = SQRT_MAX_SAFE_INTEGER$1;
2973 while (true) {
2974 const x1 = n / x0 + x0 >> _1n;
2975 if (x0 === x1 || x0 === x1 - _1n) {
2976 return x0;
2977 }
2978 x0 = x1;
2979 }
2980 }
2981
2982 function createCmp(cmp) {
2983 return (...items) => {
2984 if (items.length === 0) {
2985 throw new Error('Must provide one or more arguments');
2986 }
2987 let result = items[0];
2988 for (let i = 1; i < items.length; i++) {
2989 if (cmp(items[i], result)) {
2990 result = items[i];
2991 }
2992 }
2993 return result;
2994 };
2995 }
2996
2997 const nMax = createCmp((a, b) => a > b);
2998 const nMin = createCmp((a, b) => a < b);
2999
3000 const hasBigInt = typeof BigInt === 'function' && typeof BigInt.asIntN === 'function';
3001 const hasBuffer = typeof Buffer !== 'undefined';
3002 const hasCjs = typeof require === 'function' && typeof module !== 'undefined';
3003 const hasDirname = typeof __dirname !== 'undefined';
3004 const hasEsm = !hasCjs;
3005 const hasProcess = typeof process === 'object';
3006 const hasWasm = typeof WebAssembly !== 'undefined';
3007
3008 function isBuffer(value) {
3009 return hasBuffer && isFunction(value && value.readDoubleLE) && Buffer.isBuffer(value);
3010 }
3011
3012 function isU8a(value) {
3013 return (value && value.constructor) === Uint8Array || value instanceof Uint8Array;
3014 }
3015
3016 var browser$1 = {};
3017
3018 const require$$0 = /*@__PURE__*/getAugmentedNamespace(build);
3019
3020 var fallback$1 = {};
3021
3022 Object.defineProperty(fallback$1, "__esModule", {
3023 value: true
3024 });
3025 fallback$1.TextEncoder = void 0;
3026 class TextEncoder {
3027 encode(value) {
3028 const u8a = new Uint8Array(value.length);
3029 for (let i = 0; i < value.length; i++) {
3030 u8a[i] = value.charCodeAt(i);
3031 }
3032 return u8a;
3033 }
3034 }
3035 fallback$1.TextEncoder = TextEncoder;
3036
3037 var packageInfo$3 = {};
3038
3039 Object.defineProperty(packageInfo$3, "__esModule", {
3040 value: true
3041 });
3042 packageInfo$3.packageInfo = void 0;
3043 const packageInfo$2 = {
3044 name: '@polkadot/x-textencoder',
3045 path: typeof __dirname === 'string' ? __dirname : 'auto',
3046 type: 'cjs',
3047 version: '9.6.2'
3048 };
3049 packageInfo$3.packageInfo = packageInfo$2;
3050
3051 (function (exports) {
3052 Object.defineProperty(exports, "__esModule", {
3053 value: true
3054 });
3055 exports.TextEncoder = void 0;
3056 Object.defineProperty(exports, "packageInfo", {
3057 enumerable: true,
3058 get: function () {
3059 return _packageInfo.packageInfo;
3060 }
3061 });
3062 var _xGlobal = require$$0;
3063 var _fallback = fallback$1;
3064 var _packageInfo = packageInfo$3;
3065 const TextEncoder = (0, _xGlobal.extractGlobal)('TextEncoder', _fallback.TextEncoder);
3066 exports.TextEncoder = TextEncoder;
3067 } (browser$1));
3068 getDefaultExportFromCjs(browser$1);
3069
3070 const encoder = new browser$1.TextEncoder();
3071 function stringToU8a(value) {
3072 return value ? encoder.encode(value.toString()) : new Uint8Array();
3073 }
3074
3075 function u8aToU8a(value) {
3076 return isU8a(value) ? value : isHex(value) ? hexToU8a(value) : isBuffer(value) || Array.isArray(value) ? new Uint8Array(value) : stringToU8a(value);
3077 }
3078
3079 function u8aCmp(a, b) {
3080 const u8aa = u8aToU8a(a);
3081 const u8ab = u8aToU8a(b);
3082 let i = 0;
3083 while (true) {
3084 const overA = i >= u8aa.length;
3085 const overB = i >= u8ab.length;
3086 if (overA && overB) {
3087 return 0;
3088 } else if (overA) {
3089 return -1;
3090 } else if (overB) {
3091 return 1;
3092 } else if (u8aa[i] !== u8ab[i]) {
3093 return u8aa[i] > u8ab[i] ? 1 : -1;
3094 }
3095 i++;
3096 }
3097 }
3098
3099 function u8aConcat(...list) {
3100 const u8as = new Array(list.length);
3101 let length = 0;
3102 for (let i = 0; i < list.length; i++) {
3103 u8as[i] = u8aToU8a(list[i]);
3104 length += u8as[i].length;
3105 }
3106 return u8aConcatStrict(u8as, length);
3107 }
3108 function u8aConcatStrict(u8as, length = 0) {
3109 let offset = 0;
3110 if (!length) {
3111 for (let i = 0; i < u8as.length; i++) {
3112 length += u8as[i].length;
3113 }
3114 }
3115 const result = new Uint8Array(length);
3116 for (let i = 0; i < u8as.length; i++) {
3117 result.set(u8as[i], offset);
3118 offset += u8as[i].length;
3119 }
3120 return result;
3121 }
3122
3123 function u8aEmpty(value) {
3124 for (let i = 0; i < value.length; i++) {
3125 if (value[i]) {
3126 return false;
3127 }
3128 }
3129 return true;
3130 }
3131
3132 function u8aEq(a, b) {
3133 const u8aa = u8aToU8a(a);
3134 const u8ab = u8aToU8a(b);
3135 if (u8aa.length === u8ab.length) {
3136 const dvA = new DataView(u8aa.buffer, u8aa.byteOffset);
3137 const dvB = new DataView(u8ab.buffer, u8ab.byteOffset);
3138 const mod = u8aa.length % 4;
3139 const length = u8aa.length - mod;
3140 for (let i = 0; i < length; i += 4) {
3141 if (dvA.getUint32(i) !== dvB.getUint32(i)) {
3142 return false;
3143 }
3144 }
3145 for (let i = length; i < u8aa.length; i++) {
3146 if (u8aa[i] !== u8ab[i]) {
3147 return false;
3148 }
3149 }
3150 return true;
3151 }
3152 return false;
3153 }
3154
3155 function u8aFixLength(value, bitLength = -1, atStart = false) {
3156 const byteLength = Math.ceil(bitLength / 8);
3157 if (bitLength === -1 || value.length === byteLength) {
3158 return value;
3159 } else if (value.length > byteLength) {
3160 return value.subarray(0, byteLength);
3161 }
3162 const result = new Uint8Array(byteLength);
3163 result.set(value, atStart ? 0 : byteLength - value.length);
3164 return result;
3165 }
3166
3167 function u8aToFloat(value, {
3168 bitLength = 32,
3169 isLe = true
3170 } = {}) {
3171 if (bitLength !== 32 && bitLength !== 64) {
3172 throw new Error('Invalid bitLength provided, expected 32 or 64');
3173 } else if (value.length < bitLength / 8) {
3174 throw new Error(`Invalid input buffer provided, expected at least ${bitLength / 8} bytes, found ${value.length}`);
3175 }
3176 const dv = new DataView(value.buffer, value.byteOffset);
3177 return bitLength === 32 ? dv.getFloat32(0, isLe) : dv.getFloat64(0, isLe);
3178 }
3179
3180 function u8aSorted(u8as) {
3181 return u8as.sort(u8aCmp);
3182 }
3183
3184 function isBoolean(value) {
3185 return typeof value === 'boolean';
3186 }
3187
3188 function u8aToBn(value, options = {}) {
3189 const {
3190 isLe = true,
3191 isNegative = false
3192 } = isBoolean(options) ? {
3193 isLe: options
3194 } : options;
3195 const count = value.length;
3196 if (count <= 6) {
3197 if (isNegative) {
3198 let result = 0;
3199 if (isLe) {
3200 switch (count) {
3201 case 0:
3202 return new BN(0);
3203 case 1:
3204 result = value[0] ^ 0x000000ff;
3205 break;
3206 case 2:
3207 result = value[0] + (value[1] << 8) ^ 0x0000ffff;
3208 break;
3209 case 3:
3210 result = value[0] + (value[1] << 8) + (value[2] << 16) ^ 0x00ffffff;
3211 break;
3212 case 4:
3213 result = value[0] + (value[1] << 8) + (value[2] << 16) + value[3] * 0x1000000 ^ 0xffffffff;
3214 break;
3215 case 5:
3216 result = (value[0] + (value[1] << 8) + (value[2] << 16) + value[3] * 0x1000000 ^ 0xffffffff) + (value[4] ^ 0xff) * 0x100000000;
3217 break;
3218 default:
3219 result = (value[0] + (value[1] << 8) + (value[2] << 16) + value[3] * 0x1000000 ^ 0xffffffff) + (value[4] + (value[5] << 8) ^ 0x0000ffff) * 0x100000000;
3220 break;
3221 }
3222 } else {
3223 for (let i = 0; i < count; i++) {
3224 result = result * 0x100 + (value[i] ^ 0xff);
3225 }
3226 }
3227 return count ? new BN(result * -1 - 1) : new BN(0);
3228 } else if (isLe) {
3229 switch (count) {
3230 case 0:
3231 return new BN(0);
3232 case 1:
3233 return new BN(value[0]);
3234 case 2:
3235 return new BN(value[0] + (value[1] << 8));
3236 case 3:
3237 return new BN(value[0] + (value[1] << 8) + (value[2] << 16));
3238 case 4:
3239 return new BN(value[0] + (value[1] << 8) + (value[2] << 16) + value[3] * 0x1000000);
3240 case 5:
3241 return new BN(value[0] + (value[1] << 8) + (value[2] << 16) + (value[3] + (value[4] << 8)) * 0x1000000);
3242 default:
3243 return new BN(value[0] + (value[1] << 8) + (value[2] << 16) + (value[3] + (value[4] << 8) + (value[5] << 16)) * 0x1000000);
3244 }
3245 } else {
3246 let result = 0;
3247 for (let i = 0; i < count; i++) {
3248 result = result * 0x100 + value[i];
3249 }
3250 return new BN(result);
3251 }
3252 }
3253 return isNegative ? new BN(value, isLe ? 'le' : 'be').fromTwos(value.length * 8) : new BN(value, isLe ? 'le' : 'be');
3254 }
3255
3256 function u8aToBuffer(value) {
3257 return Buffer.from(value || []);
3258 }
3259
3260 const U8 = new Array(256);
3261 const U16 = new Array(256 * 256);
3262 for (let n = 0; n < 256; n++) {
3263 U8[n] = n.toString(16).padStart(2, '0');
3264 }
3265 for (let i = 0; i < 256; i++) {
3266 const s = i << 8;
3267 for (let j = 0; j < 256; j++) {
3268 U16[s | j] = U8[i] + U8[j];
3269 }
3270 }
3271 function hex(value) {
3272 const mod = value.length % 2;
3273 const length = value.length - mod;
3274 const dv = new DataView(value.buffer, value.byteOffset);
3275 let result = '';
3276 for (let i = 0; i < length; i += 2) {
3277 result += U16[dv.getUint16(i)];
3278 }
3279 if (mod) {
3280 result += U8[dv.getUint8(length)];
3281 }
3282 return result;
3283 }
3284 function u8aToHex(value, bitLength = -1, isPrefixed = true) {
3285 const length = Math.ceil(bitLength / 8);
3286 return `${isPrefixed ? '0x' : ''}${!value || !value.length ? '' : bitLength > 0 && value.length > length ? `${hex(value.subarray(0, length / 2))}…${hex(value.subarray(value.length - length / 2))}` : hex(value)}`;
3287 }
3288
3289 function u8aToNumber(value, {
3290 isNegative = false
3291 } = {}) {
3292 const count = value.length;
3293 if (isNegative) {
3294 let result = 0;
3295 switch (count) {
3296 case 0:
3297 return 0;
3298 case 1:
3299 result = value[0] ^ 0x000000ff;
3300 break;
3301 case 2:
3302 result = value[0] + (value[1] << 8) ^ 0x0000ffff;
3303 break;
3304 case 3:
3305 result = value[0] + (value[1] << 8) + (value[2] << 16) ^ 0x00ffffff;
3306 break;
3307 case 4:
3308 result = value[0] + (value[1] << 8) + (value[2] << 16) + value[3] * 0x1000000 ^ 0xffffffff;
3309 break;
3310 case 5:
3311 result = (value[0] + (value[1] << 8) + (value[2] << 16) + value[3] * 0x1000000 ^ 0xffffffff) + (value[4] ^ 0xff) * 0x100000000;
3312 break;
3313 case 6:
3314 result = (value[0] + (value[1] << 8) + (value[2] << 16) + value[3] * 0x1000000 ^ 0xffffffff) + (value[4] + (value[5] << 8) ^ 0x0000ffff) * 0x100000000;
3315 break;
3316 default:
3317 throw new Error('Value more than 48-bits cannot be reliably converted');
3318 }
3319 return result * -1 - 1;
3320 }
3321 switch (count) {
3322 case 0:
3323 return 0;
3324 case 1:
3325 return value[0];
3326 case 2:
3327 return value[0] + (value[1] << 8);
3328 case 3:
3329 return value[0] + (value[1] << 8) + (value[2] << 16);
3330 case 4:
3331 return value[0] + (value[1] << 8) + (value[2] << 16) + value[3] * 0x1000000;
3332 case 5:
3333 return value[0] + (value[1] << 8) + (value[2] << 16) + (value[3] + (value[4] << 8)) * 0x1000000;
3334 case 6:
3335 return value[0] + (value[1] << 8) + (value[2] << 16) + (value[3] + (value[4] << 8) + (value[5] << 16)) * 0x1000000;
3336 default:
3337 throw new Error('Value more than 48-bits cannot be reliably converted');
3338 }
3339 }
3340
3341 var browser = {};
3342
3343 var fallback = {};
3344
3345 Object.defineProperty(fallback, "__esModule", {
3346 value: true
3347 });
3348 fallback.TextDecoder = void 0;
3349 class TextDecoder {
3350 constructor(_) {
3351 }
3352 decode(value) {
3353 let result = '';
3354 for (let i = 0; i < value.length; i++) {
3355 result += String.fromCharCode(value[i]);
3356 }
3357 return result;
3358 }
3359 }
3360 fallback.TextDecoder = TextDecoder;
3361
3362 var packageInfo$1 = {};
3363
3364 Object.defineProperty(packageInfo$1, "__esModule", {
3365 value: true
3366 });
3367 packageInfo$1.packageInfo = void 0;
3368 const packageInfo = {
3369 name: '@polkadot/x-textdecoder',
3370 path: typeof __dirname === 'string' ? __dirname : 'auto',
3371 type: 'cjs',
3372 version: '9.6.2'
3373 };
3374 packageInfo$1.packageInfo = packageInfo;
3375
3376 (function (exports) {
3377 Object.defineProperty(exports, "__esModule", {
3378 value: true
3379 });
3380 exports.TextDecoder = void 0;
3381 Object.defineProperty(exports, "packageInfo", {
3382 enumerable: true,
3383 get: function () {
3384 return _packageInfo.packageInfo;
3385 }
3386 });
3387 var _xGlobal = require$$0;
3388 var _fallback = fallback;
3389 var _packageInfo = packageInfo$1;
3390 const TextDecoder = (0, _xGlobal.extractGlobal)('TextDecoder', _fallback.TextDecoder);
3391 exports.TextDecoder = TextDecoder;
3392 } (browser));
3393 getDefaultExportFromCjs(browser);
3394
3395 const decoder = new browser.TextDecoder('utf-8');
3396 function u8aToString(value) {
3397 return value ? decoder.decode(value) : '';
3398 }
3399
3400 const U8A_WRAP_ETHEREUM = u8aToU8a('\x19Ethereum Signed Message:\n');
3401 const U8A_WRAP_PREFIX = u8aToU8a('<Bytes>');
3402 const U8A_WRAP_POSTFIX = u8aToU8a('</Bytes>');
3403 const WRAP_LEN = U8A_WRAP_PREFIX.length + U8A_WRAP_POSTFIX.length;
3404 function u8aIsWrapped(u8a, withEthereum) {
3405 return u8a.length >= WRAP_LEN && u8aEq(u8a.subarray(0, U8A_WRAP_PREFIX.length), U8A_WRAP_PREFIX) && u8aEq(u8a.slice(-U8A_WRAP_POSTFIX.length), U8A_WRAP_POSTFIX) || withEthereum && u8a.length >= U8A_WRAP_ETHEREUM.length && u8aEq(u8a.subarray(0, U8A_WRAP_ETHEREUM.length), U8A_WRAP_ETHEREUM);
3406 }
3407 function u8aUnwrapBytes(bytes) {
3408 const u8a = u8aToU8a(bytes);
3409 return u8aIsWrapped(u8a, false) ? u8a.subarray(U8A_WRAP_PREFIX.length, u8a.length - U8A_WRAP_POSTFIX.length) : u8a;
3410 }
3411 function u8aWrapBytes(bytes) {
3412 const u8a = u8aToU8a(bytes);
3413 return u8aIsWrapped(u8a, true) ? u8a : u8aConcatStrict([U8A_WRAP_PREFIX, u8a, U8A_WRAP_POSTFIX]);
3414 }
3415
3416 const DIV = BigInt(256);
3417 const NEG_MASK = BigInt(0xff);
3418 function toU8a(value, {
3419 isLe,
3420 isNegative
3421 }) {
3422 const arr = [];
3423 if (isNegative) {
3424 value = (value + _1n) * -_1n;
3425 }
3426 while (value !== _0n) {
3427 const mod = value % DIV;
3428 const val = Number(isNegative ? mod ^ NEG_MASK : mod);
3429 if (isLe) {
3430 arr.push(val);
3431 } else {
3432 arr.unshift(val);
3433 }
3434 value = (value - mod) / DIV;
3435 }
3436 return Uint8Array.from(arr);
3437 }
3438 function nToU8a(value, options) {
3439 const opts = objectSpread({
3440 bitLength: -1,
3441 isLe: true,
3442 isNegative: false
3443 }, options);
3444 const valueBi = nToBigInt(value);
3445 if (valueBi === _0n) {
3446 return opts.bitLength === -1 ? new Uint8Array() : new Uint8Array(Math.ceil((opts.bitLength || 0) / 8));
3447 }
3448 const u8a = toU8a(valueBi, opts);
3449 if (opts.bitLength === -1) {
3450 return u8a;
3451 }
3452 const byteLength = Math.ceil((opts.bitLength || 0) / 8);
3453 const output = new Uint8Array(byteLength);
3454 if (opts.isNegative) {
3455 output.fill(0xff);
3456 }
3457 output.set(u8a, opts.isLe ? 0 : byteLength - u8a.length);
3458 return output;
3459 }
3460
3461 const ZERO_STR$1 = '0x00';
3462 function nToHex(value, options) {
3463 return !value ? ZERO_STR$1 : u8aToHex(nToU8a(value, objectSpread(
3464 {
3465 isLe: false,
3466 isNegative: false
3467 }, options)));
3468 }
3469
3470 const BN_ZERO = new BN(0);
3471 const BN_ONE = new BN(1);
3472 const BN_TWO = new BN(2);
3473 const BN_THREE = new BN(3);
3474 const BN_FOUR = new BN(4);
3475 const BN_FIVE = new BN(5);
3476 const BN_SIX = new BN(6);
3477 const BN_SEVEN = new BN(7);
3478 const BN_EIGHT = new BN(8);
3479 const BN_NINE = new BN(9);
3480 const BN_TEN = new BN(10);
3481 const BN_HUNDRED = new BN(100);
3482 const BN_THOUSAND = new BN(1000);
3483 const BN_MILLION = new BN(1000000);
3484 const BN_BILLION = new BN(1000000000);
3485 const BN_QUINTILL = BN_BILLION.mul(BN_BILLION);
3486 const BN_MAX_INTEGER = new BN(Number.MAX_SAFE_INTEGER);
3487
3488 function hexStripPrefix(value) {
3489 if (!value || value === '0x') {
3490 return '';
3491 } else if (REGEX_HEX_PREFIXED.test(value)) {
3492 return value.substring(2);
3493 } else if (REGEX_HEX_NOPREFIX.test(value)) {
3494 return value;
3495 }
3496 throw new Error(`Expected hex value to convert, found '${value}'`);
3497 }
3498
3499 function hexToBn(value, options = {}) {
3500 if (!value || value === '0x') {
3501 return new BN(0);
3502 }
3503 const {
3504 isLe = false,
3505 isNegative = false
3506 } = isBoolean(options) ? {
3507 isLe: options
3508 } : options;
3509 const stripped = hexStripPrefix(value);
3510 const bn = new BN(stripped, 16, isLe ? 'le' : 'be');
3511 return isNegative ? bn.fromTwos(stripped.length * 4) : bn;
3512 }
3513
3514 const bnMax = createCmp((a, b) => a.gt(b));
3515 const bnMin = createCmp((a, b) => a.lt(b));
3516
3517 function isBigInt(value) {
3518 return typeof value === 'bigint';
3519 }
3520
3521 function bnToBn(value) {
3522 return value ? BN.isBN(value) ? value : isHex(value) ? hexToBn(value.toString()) : isBigInt(value) ? new BN(value.toString()) : isToBn(value) ? value.toBn() : isToBigInt(value) ? new BN(value.toBigInt().toString()) : new BN(value) : new BN(0);
3523 }
3524
3525 const SQRT_MAX_SAFE_INTEGER = new BN(94906265);
3526 function bnSqrt(value) {
3527 const n = bnToBn(value);
3528 if (n.isNeg()) {
3529 throw new Error('square root of negative numbers is not supported');
3530 }
3531 if (n.lte(BN_MAX_INTEGER)) {
3532 return new BN(~~Math.sqrt(n.toNumber()));
3533 }
3534 let x0 = SQRT_MAX_SAFE_INTEGER.clone();
3535 while (true) {
3536 const x1 = n.div(x0).iadd(x0).ishrn(1);
3537 if (x0.eq(x1) || x0.eq(x1.sub(BN_ONE))) {
3538 return x0;
3539 }
3540 x0 = x1;
3541 }
3542 }
3543
3544 function isNumber(value) {
3545 return typeof value === 'number';
3546 }
3547
3548 const DEFAULT_OPTS$1 = {
3549 bitLength: -1,
3550 isLe: true,
3551 isNegative: false
3552 };
3553 function bnToU8a(value, arg1 = DEFAULT_OPTS$1, arg2 = true) {
3554 const {
3555 bitLength = -1,
3556 isLe = true,
3557 isNegative = false
3558 } = isNumber(arg1) ? {
3559 bitLength: arg1,
3560 isLe: arg2
3561 } : arg1;
3562 const valueBn = bnToBn(value);
3563 const byteLength = bitLength === -1 ? Math.ceil(valueBn.bitLength() / 8) : Math.ceil((bitLength || 0) / 8);
3564 if (!value) {
3565 return bitLength === -1 ? new Uint8Array() : new Uint8Array(byteLength);
3566 }
3567 const output = new Uint8Array(byteLength);
3568 const bn = isNegative ? valueBn.toTwos(byteLength * 8) : valueBn;
3569 output.set(bn.toArray(isLe ? 'le' : 'be', byteLength), 0);
3570 return output;
3571 }
3572
3573 const ZERO_STR = '0x00';
3574 const DEFAULT_OPTS = {
3575 bitLength: -1,
3576 isLe: false,
3577 isNegative: false
3578 };
3579 function bnToHex(value, arg1 = DEFAULT_OPTS, arg2 = false) {
3580 return !value ? ZERO_STR : u8aToHex(bnToU8a(value, objectSpread(
3581 {
3582 isLe: false,
3583 isNegative: false
3584 }, isNumber(arg1) ? {
3585 bitLength: arg1,
3586 isLe: arg2
3587 } : arg1)));
3588 }
3589
3590 function bufferToU8a(buffer) {
3591 return new Uint8Array(buffer || []);
3592 }
3593
3594 const MAX_U8 = BN_TWO.pow(new BN(8 - 2)).isub(BN_ONE);
3595 const MAX_U16 = BN_TWO.pow(new BN(16 - 2)).isub(BN_ONE);
3596 const MAX_U32 = BN_TWO.pow(new BN(32 - 2)).isub(BN_ONE);
3597 const BL_16 = {
3598 bitLength: 16
3599 };
3600 const BL_32 = {
3601 bitLength: 32
3602 };
3603 function compactToU8a(value) {
3604 const bn = bnToBn(value);
3605 if (bn.lte(MAX_U8)) {
3606 return new Uint8Array([bn.toNumber() << 2]);
3607 } else if (bn.lte(MAX_U16)) {
3608 return bnToU8a(bn.shln(2).iadd(BN_ONE), BL_16);
3609 } else if (bn.lte(MAX_U32)) {
3610 return bnToU8a(bn.shln(2).iadd(BN_TWO), BL_32);
3611 }
3612 const u8a = bnToU8a(bn);
3613 let length = u8a.length;
3614 while (u8a[length - 1] === 0) {
3615 length--;
3616 }
3617 if (length < 4) {
3618 throw new Error('Invalid length, previous checks match anything less than 2^30');
3619 }
3620 return u8aConcatStrict([
3621 new Uint8Array([(length - 4 << 2) + 0b11]), u8a.subarray(0, length)]);
3622 }
3623
3624 function compactAddLength(input) {
3625 return u8aConcatStrict([compactToU8a(input.length), input]);
3626 }
3627
3628 function compactFromU8a(input) {
3629 const u8a = u8aToU8a(input);
3630 switch (u8a[0] & 0b11) {
3631 case 0b00:
3632 return [1, new BN(u8a[0] >>> 2)];
3633 case 0b01:
3634 return [2, new BN(u8a[0] + (u8a[1] << 8) >>> 2)];
3635 case 0b10:
3636 return [4, new BN(u8a[0] + (u8a[1] << 8) + (u8a[2] << 16) + u8a[3] * 0x1000000 >>> 2)];
3637 default:
3638 {
3639 const offset = (u8a[0] >>> 2) + 5;
3640 switch (offset) {
3641 case 5:
3642 return [5, new BN(u8a[1] + (u8a[2] << 8) + (u8a[3] << 16) + u8a[4] * 0x1000000)];
3643 case 6:
3644 return [6, new BN(u8a[1] + (u8a[2] << 8) + (u8a[3] << 16) + (u8a[4] + (u8a[5] << 8)) * 0x1000000)];
3645 case 7:
3646 return [7, new BN(u8a[1] + (u8a[2] << 8) + (u8a[3] << 16) + (u8a[4] + (u8a[5] << 8) + (u8a[6] << 16)) * 0x1000000)];
3647 default:
3648 return [offset, u8aToBn(u8a.subarray(1, offset))];
3649 }
3650 }
3651 }
3652 }
3653 function compactFromU8aLim(u8a) {
3654 switch (u8a[0] & 0b11) {
3655 case 0b00:
3656 return [1, u8a[0] >>> 2];
3657 case 0b01:
3658 return [2, u8a[0] + (u8a[1] << 8) >>> 2];
3659 case 0b10:
3660 return [4, u8a[0] + (u8a[1] << 8) + (u8a[2] << 16) + u8a[3] * 0x1000000 >>> 2];
3661 default:
3662 {
3663 switch ((u8a[0] >>> 2) + 5) {
3664 case 5:
3665 return [5, u8a[1] + (u8a[2] << 8) + (u8a[3] << 16) + u8a[4] * 0x1000000];
3666 case 6:
3667 return [6, u8a[1] + (u8a[2] << 8) + (u8a[3] << 16) + (u8a[4] + (u8a[5] << 8)) * 0x1000000];
3668 case 7:
3669 return [7, u8a[1] + (u8a[2] << 8) + (u8a[3] << 16) + (u8a[4] + (u8a[5] << 8) + (u8a[6] << 16)) * 0x1000000];
3670 default:
3671 throw new Error('Compact input is > Number.MAX_SAFE_INTEGER');
3672 }
3673 }
3674 }
3675 }
3676
3677 function compactStripLength(input) {
3678 const [offset, length] = compactFromU8a(input);
3679 const total = offset + length.toNumber();
3680 return [total, input.subarray(offset, total)];
3681 }
3682
3683 const MIN_MS = 60 * 1000;
3684 const HR_MS = MIN_MS * 60;
3685 const DAY_MS = HR_MS * 24;
3686 const ZERO = {
3687 days: 0,
3688 hours: 0,
3689 milliseconds: 0,
3690 minutes: 0,
3691 seconds: 0
3692 };
3693 function add(a, b) {
3694 return {
3695 days: (a.days || 0) + b.days,
3696 hours: (a.hours || 0) + b.hours,
3697 milliseconds: (a.milliseconds || 0) + b.milliseconds,
3698 minutes: (a.minutes || 0) + b.minutes,
3699 seconds: (a.seconds || 0) + b.seconds
3700 };
3701 }
3702 function extractSecs(ms) {
3703 const s = ms / 1000;
3704 if (s < 60) {
3705 const seconds = ~~s;
3706 return add({
3707 seconds
3708 }, extractTime(ms - seconds * 1000));
3709 }
3710 const m = s / 60;
3711 if (m < 60) {
3712 const minutes = ~~m;
3713 return add({
3714 minutes
3715 }, extractTime(ms - minutes * MIN_MS));
3716 }
3717 const h = m / 60;
3718 if (h < 24) {
3719 const hours = ~~h;
3720 return add({
3721 hours
3722 }, extractTime(ms - hours * HR_MS));
3723 }
3724 const days = ~~(h / 24);
3725 return add({
3726 days
3727 }, extractTime(ms - days * DAY_MS));
3728 }
3729 function extractTime(milliseconds) {
3730 return !milliseconds ? ZERO : milliseconds < 1000 ? add({
3731 milliseconds
3732 }, ZERO) : extractSecs(milliseconds);
3733 }
3734
3735 function floatToU8a(value = 0.0, {
3736 bitLength = 32,
3737 isLe = true
3738 } = {}) {
3739 if (bitLength !== 32 && bitLength !== 64) {
3740 throw new Error('Invalid bitLength provided, expected 32 or 64');
3741 }
3742 const result = new Uint8Array(bitLength / 8);
3743 const dv = new DataView(result.buffer, result.byteOffset);
3744 if (bitLength === 32) {
3745 dv.setFloat32(0, Number(value), isLe);
3746 } else {
3747 dv.setFloat64(0, Number(value), isLe);
3748 }
3749 return result;
3750 }
3751
3752 const NUMBER_REGEX = new RegExp('(\\d+?)(?=(\\d{3})+(?!\\d)|$)', 'g');
3753 function formatDecimal(value) {
3754 const isNegative = value[0].startsWith('-');
3755 const matched = isNegative ? value.substring(1).match(NUMBER_REGEX) : value.match(NUMBER_REGEX);
3756 return matched ? `${isNegative ? '-' : ''}${matched.join(',')}` : value;
3757 }
3758
3759 const SI_MID = 8;
3760 const SI = [{
3761 power: -24,
3762 text: 'yocto',
3763 value: 'y'
3764 }, {
3765 power: -21,
3766 text: 'zepto',
3767 value: 'z'
3768 }, {
3769 power: -18,
3770 text: 'atto',
3771 value: 'a'
3772 }, {
3773 power: -15,
3774 text: 'femto',
3775 value: 'f'
3776 }, {
3777 power: -12,
3778 text: 'pico',
3779 value: 'p'
3780 }, {
3781 power: -9,
3782 text: 'nano',
3783 value: 'n'
3784 }, {
3785 power: -6,
3786 text: 'micro',
3787 value: 'µ'
3788 }, {
3789 power: -3,
3790 text: 'milli',
3791 value: 'm'
3792 }, {
3793 power: 0,
3794 text: 'Unit',
3795 value: '-'
3796 },
3797 {
3798 power: 3,
3799 text: 'Kilo',
3800 value: 'k'
3801 }, {
3802 power: 6,
3803 text: 'Mill',
3804 value: 'M'
3805 },
3806 {
3807 power: 9,
3808 text: 'Bill',
3809 value: 'B'
3810 },
3811 {
3812 power: 12,
3813 text: 'Tril',
3814 value: 'T'
3815 },
3816 {
3817 power: 15,
3818 text: 'Peta',
3819 value: 'P'
3820 }, {
3821 power: 18,
3822 text: 'Exa',
3823 value: 'E'
3824 }, {
3825 power: 21,
3826 text: 'Zeta',
3827 value: 'Z'
3828 }, {
3829 power: 24,
3830 text: 'Yotta',
3831 value: 'Y'
3832 }];
3833 function findSi(type) {
3834 for (let i = 0; i < SI.length; i++) {
3835 if (SI[i].value === type) {
3836 return SI[i];
3837 }
3838 }
3839 return SI[SI_MID];
3840 }
3841 function calcSi(text, decimals, forceUnit) {
3842 if (forceUnit) {
3843 return findSi(forceUnit);
3844 }
3845 const siDefIndex = SI_MID - 1 + Math.ceil((text.length - decimals) / 3);
3846 return SI[siDefIndex] || SI[siDefIndex < 0 ? 0 : SI.length - 1];
3847 }
3848
3849 const DEFAULT_DECIMALS = 0;
3850 const DEFAULT_UNIT = SI[SI_MID].text;
3851 let defaultDecimals = DEFAULT_DECIMALS;
3852 let defaultUnit = DEFAULT_UNIT;
3853 function getUnits(si, withSi, withSiFull, withUnit) {
3854 const unit = isBoolean(withUnit) ? SI[SI_MID].text : withUnit;
3855 return withSi || withSiFull ? si.value === '-' ? withUnit ? ` ${unit}` : '' : ` ${withSiFull ? `${si.text}${withUnit ? ' ' : ''}` : si.value}${withUnit ? unit : ''}` : '';
3856 }
3857 function getPrePost(text, decimals, forceUnit) {
3858 const si = calcSi(text, decimals, forceUnit);
3859 const mid = text.length - (decimals + si.power);
3860 const prefix = text.substring(0, mid);
3861 const padding = mid < 0 ? 0 - mid : 0;
3862 const postfix = `${`${new Array(padding + 1).join('0')}${text}`.substring(mid < 0 ? 0 : mid)}0000`.substring(0, 4);
3863 return [si, prefix || '0', postfix];
3864 }
3865 function _formatBalance(input, options = true, optDecimals = defaultDecimals) {
3866 let text = bnToBn(input).toString();
3867 if (text.length === 0 || text === '0') {
3868 return '0';
3869 }
3870 const {
3871 decimals = optDecimals,
3872 forceUnit = undefined,
3873 withSi = true,
3874 withSiFull = false,
3875 withUnit = true
3876 } = isBoolean(options) ? {
3877 withSi: options
3878 } : options;
3879 let sign = '';
3880 if (text[0].startsWith('-')) {
3881 sign = '-';
3882 text = text.substring(1);
3883 }
3884 const [si, prefix, postfix] = getPrePost(text, decimals, forceUnit);
3885 const units = getUnits(si, withSi, withSiFull, withUnit);
3886 return `${sign}${formatDecimal(prefix)}.${postfix}${units}`;
3887 }
3888 const formatBalance = _formatBalance;
3889 formatBalance.calcSi = (text, decimals = defaultDecimals) => calcSi(text, decimals);
3890 formatBalance.findSi = findSi;
3891 formatBalance.getDefaults = () => {
3892 return {
3893 decimals: defaultDecimals,
3894 unit: defaultUnit
3895 };
3896 };
3897 formatBalance.getOptions = (decimals = defaultDecimals) => {
3898 return SI.filter(({
3899 power
3900 }) => power < 0 ? decimals + power >= 0 : true);
3901 };
3902 formatBalance.setDefaults = ({
3903 decimals,
3904 unit
3905 }) => {
3906 defaultDecimals = decimals === undefined ? defaultDecimals : Array.isArray(decimals) ? decimals[0] : decimals;
3907 defaultUnit = unit === undefined ? defaultUnit : Array.isArray(unit) ? unit[0] : unit;
3908 SI[SI_MID].text = defaultUnit;
3909 };
3910
3911 function zeroPad(value) {
3912 return value.toString().padStart(2, '0');
3913 }
3914 function formatDate(date) {
3915 const year = date.getFullYear().toString();
3916 const month = zeroPad(date.getMonth() + 1);
3917 const day = zeroPad(date.getDate());
3918 const hour = zeroPad(date.getHours());
3919 const minute = zeroPad(date.getMinutes());
3920 const second = zeroPad(date.getSeconds());
3921 return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
3922 }
3923
3924 function formatValue(elapsed) {
3925 if (elapsed < 15) {
3926 return `${elapsed.toFixed(1)}s`;
3927 } else if (elapsed < 60) {
3928 return `${elapsed | 0}s`;
3929 } else if (elapsed < 3600) {
3930 return `${elapsed / 60 | 0}m`;
3931 }
3932 return `${elapsed / 3600 | 0}h`;
3933 }
3934 function formatElapsed(now, value) {
3935 const tsNow = now && now.getTime() || 0;
3936 const tsValue = value instanceof Date ? value.getTime() : bnToBn(value).toNumber();
3937 return tsNow && tsValue ? formatValue(Math.max(Math.abs(tsNow - tsValue), 0) / 1000) : '0.0s';
3938 }
3939
3940 function formatNumber(value) {
3941 return formatDecimal(bnToBn(value).toString());
3942 }
3943
3944 function hexHasPrefix(value) {
3945 return !!value && isHex(value, -1);
3946 }
3947
3948 function hexAddPrefix(value) {
3949 return value && hexHasPrefix(value) ? value : `0x${value && value.length % 2 === 1 ? '0' : ''}${value || ''}`;
3950 }
3951
3952 function hexFixLength(value, bitLength = -1, withPadding = false) {
3953 const strLength = Math.ceil(bitLength / 4);
3954 const hexLength = strLength + 2;
3955 return hexAddPrefix(bitLength === -1 || value.length === hexLength || !withPadding && value.length < hexLength ? hexStripPrefix(value) : value.length > hexLength ? hexStripPrefix(value).slice(-1 * strLength) : `${'0'.repeat(strLength)}${hexStripPrefix(value)}`.slice(-1 * strLength));
3956 }
3957
3958 function hexToNumber(value) {
3959 return value ? hexToBn(value).toNumber() : NaN;
3960 }
3961
3962 function hexToString(_value) {
3963 return u8aToString(hexToU8a(_value));
3964 }
3965
3966 function isArray(value) {
3967 return Array.isArray(value);
3968 }
3969
3970 function isString(value) {
3971 return typeof value === 'string' || value instanceof String;
3972 }
3973
3974 function isAsciiStr(str) {
3975 const count = str.length;
3976 for (let i = 0; i < count; i++) {
3977 const b = str.charCodeAt(i);
3978 if (!(b < 127 && (b >= 32 || b === 10 || b === 9 || b === 13))) {
3979 return false;
3980 }
3981 }
3982 return true;
3983 }
3984 function isAsciiBytes(u8a) {
3985 const count = u8a.length;
3986 for (let i = 0; i < count; i++) {
3987 const b = u8a[i];
3988 if (!(b < 127 && (b >= 32 || b === 10 || b === 9 || b === 13))) {
3989 return false;
3990 }
3991 }
3992 return true;
3993 }
3994 function isAscii(value) {
3995 return isString(value) ? isHex(value) ? isAsciiBytes(u8aToU8a(value)) : isAsciiStr(value) : value ? isAsciiBytes(value) : false;
3996 }
3997
3998 function isChildClass(Parent, Child) {
3999 return Child
4000 ? Parent === Child || Parent.isPrototypeOf(Child) : false;
4001 }
4002
4003 const checkCodec = isOnObject('toHex', 'toU8a');
4004 const checkRegistry = isOnObject('get');
4005 function isCodec(value) {
4006 return checkCodec(value) && checkRegistry(value.registry);
4007 }
4008
4009 const isCompact = isOnObject('toBigInt', 'toBn', 'toNumber', 'unwrap');
4010
4011 function isError(value) {
4012 return (value && value.constructor) === Error || value instanceof Error;
4013 }
4014
4015 function isInstanceOf(value, Clazz) {
4016 return (value && value.constructor) === Clazz || value instanceof Clazz;
4017 }
4018
4019 const word = '[a-fA-F\\d:]';
4020 const b = options => options && options.includeBoundaries ?
4021 `(?:(?<=\\s|^)(?=${word})|(?<=${word})(?=\\s|$))` :
4022 '';
4023 const v4 = '(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}';
4024 const v6seg = '[a-fA-F\\d]{1,4}';
4025 const v6 = `
4026(?:
4027(?:${v6seg}:){7}(?:${v6seg}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
4028(?:${v6seg}:){6}(?:${v4}|:${v6seg}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
4029(?:${v6seg}:){5}(?::${v4}|(?::${v6seg}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
4030(?:${v6seg}:){4}(?:(?::${v6seg}){0,1}:${v4}|(?::${v6seg}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
4031(?:${v6seg}:){3}(?:(?::${v6seg}){0,2}:${v4}|(?::${v6seg}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
4032(?:${v6seg}:){2}(?:(?::${v6seg}){0,3}:${v4}|(?::${v6seg}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
4033(?:${v6seg}:){1}(?:(?::${v6seg}){0,4}:${v4}|(?::${v6seg}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
4034(?::(?:(?::${v6seg}){0,5}:${v4}|(?::${v6seg}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
4035)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
4036`.replace(/\s*\/\/.*$/gm, '').replace(/\n/g, '').trim();
4037 const v46Exact = new RegExp(`(?:^${v4}$)|(?:^${v6}$)`);
4038 const v4exact = new RegExp(`^${v4}$`);
4039 const v6exact = new RegExp(`^${v6}$`);
4040 const ip = options => options && options.exact ?
4041 v46Exact :
4042 new RegExp(`(?:${b(options)}${v4}${b(options)})|(?:${b(options)}${v6}${b(options)})`, 'g');
4043 ip.v4 = options => options && options.exact ? v4exact : new RegExp(`${b(options)}${v4}${b(options)}`, 'g');
4044 ip.v6 = options => options && options.exact ? v6exact : new RegExp(`${b(options)}${v6}${b(options)}`, 'g');
4045 var ipRegex = ip;
4046
4047 function isIp(value, type) {
4048 if (type === 'v4') {
4049 return ipRegex.v4({
4050 exact: true
4051 }).test(value);
4052 } else if (type === 'v6') {
4053 return ipRegex.v6({
4054 exact: true
4055 }).test(value);
4056 }
4057 return ipRegex({
4058 exact: true
4059 }).test(value);
4060 }
4061
4062 function replacer(_, v) {
4063 return isBigInt(v) ? v.toString() : v;
4064 }
4065 function stringify(value, space) {
4066 return JSON.stringify(value, replacer, space);
4067 }
4068
4069 function isJsonObject(value) {
4070 const str = typeof value !== 'string' ? stringify(value) : value;
4071 try {
4072 const obj = JSON.parse(str);
4073 return typeof obj === 'object' && obj !== null;
4074 } catch (e) {
4075 return false;
4076 }
4077 }
4078
4079 function isNull(value) {
4080 return value === null;
4081 }
4082
4083 const isObservable = isOn('next');
4084
4085 const isPromise = isOnObject('catch', 'then');
4086
4087 const REGEX_DEV = /(Development|Local Testnet)$/;
4088 function isTestChain(chain) {
4089 if (!chain) {
4090 return false;
4091 }
4092 return !!REGEX_DEV.test(chain.toString());
4093 }
4094
4095 function isUndefined(value) {
4096 return value === undefined;
4097 }
4098
4099 function isUtf8(value) {
4100 if (!value) {
4101 return isString(value);
4102 }
4103 const u8a = u8aToU8a(value);
4104 const len = u8a.length;
4105 let i = 0;
4106 while (i < len) {
4107 if (u8a[i] <= 0x7F)
4108 {
4109 i += 1;
4110 } else if (u8a[i] >= 0xC2 && u8a[i] <= 0xDF)
4111 {
4112 if (i + 1 < len)
4113 {
4114 if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0xBF) {
4115 return false;
4116 }
4117 } else {
4118 return false;
4119 }
4120 i += 2;
4121 } else if (u8a[i] === 0xE0)
4122 {
4123 if (i + 2 < len)
4124 {
4125 if (u8a[i + 1] < 0xA0 || u8a[i + 1] > 0xBF) {
4126 return false;
4127 }
4128 if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
4129 return false;
4130 }
4131 } else {
4132 return false;
4133 }
4134 i += 3;
4135 } else if (u8a[i] >= 0xE1 && u8a[i] <= 0xEC)
4136 {
4137 if (i + 2 < len)
4138 {
4139 if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0xBF) {
4140 return false;
4141 }
4142 if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
4143 return false;
4144 }
4145 } else {
4146 return false;
4147 }
4148 i += 3;
4149 } else if (u8a[i] === 0xED)
4150 {
4151 if (i + 2 < len)
4152 {
4153 if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0x9F) {
4154 return false;
4155 }
4156 if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
4157 return false;
4158 }
4159 } else {
4160 return false;
4161 }
4162 i += 3;
4163 } else if (u8a[i] >= 0xEE && u8a[i] <= 0xEF)
4164 {
4165 if (i + 2 < len)
4166 {
4167 if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0xBF) {
4168 return false;
4169 }
4170 if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
4171 return false;
4172 }
4173 } else {
4174 return false;
4175 }
4176 i += 3;
4177 } else if (u8a[i] === 0xF0)
4178 {
4179 if (i + 3 < len)
4180 {
4181 if (u8a[i + 1] < 0x90 || u8a[i + 1] > 0xBF) {
4182 return false;
4183 }
4184 if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
4185 return false;
4186 }
4187 if (u8a[i + 3] < 0x80 || u8a[i + 3] > 0xBF) {
4188 return false;
4189 }
4190 } else {
4191 return false;
4192 }
4193 i += 4;
4194 } else if (u8a[i] >= 0xF1 && u8a[i] <= 0xF3)
4195 {
4196 if (i + 3 < len)
4197 {
4198 if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0xBF) {
4199 return false;
4200 }
4201 if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
4202 return false;
4203 }
4204 if (u8a[i + 3] < 0x80 || u8a[i + 3] > 0xBF) {
4205 return false;
4206 }
4207 } else {
4208 return false;
4209 }
4210 i += 4;
4211 } else if (u8a[i] === 0xF4)
4212 {
4213 if (i + 3 < len)
4214 {
4215 if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0x8F) {
4216 return false;
4217 }
4218 if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
4219 return false;
4220 }
4221 if (u8a[i + 3] < 0x80 || u8a[i + 3] > 0xBF) {
4222 return false;
4223 }
4224 } else {
4225 return false;
4226 }
4227 i += 4;
4228 } else {
4229 return false;
4230 }
4231 }
4232 return true;
4233 }
4234
4235 const WASM_MAGIC = new Uint8Array([0, 97, 115, 109]);
4236 function isWasm(value) {
4237 return isU8a(value) && u8aEq(value.subarray(0, 4), WASM_MAGIC);
4238 }
4239
4240 function lazyMethod(result, item, creator, getName) {
4241 const name = getName ? getName(item) : item.toString();
4242 let value;
4243 Object.defineProperty(result, name, {
4244 configurable: true,
4245 enumerable: true,
4246 get: function () {
4247 if (value === undefined) {
4248 value = creator(item);
4249 try {
4250 Object.defineProperty(this, name, {
4251 value
4252 });
4253 } catch {
4254 }
4255 }
4256 return value;
4257 }
4258 });
4259 }
4260 function lazyMethods(result, items, creator, getName) {
4261 for (let i = 0; i < items.length; i++) {
4262 lazyMethod(result, items[i], creator, getName);
4263 }
4264 return result;
4265 }
4266
4267 const logTo = {
4268 debug: 'log',
4269 error: 'error',
4270 log: 'log',
4271 warn: 'warn'
4272 };
4273 function formatOther(value) {
4274 if (value && isObject(value) && value.constructor === Object) {
4275 const result = {};
4276 for (const k of Object.keys(value)) {
4277 result[k] = loggerFormat(value[k]);
4278 }
4279 return result;
4280 }
4281 return value;
4282 }
4283 function loggerFormat(value) {
4284 if (Array.isArray(value)) {
4285 return value.map(loggerFormat);
4286 } else if (isBn(value)) {
4287 return value.toString();
4288 } else if (isU8a(value) || isBuffer(value)) {
4289 return u8aToHex(u8aToU8a(value));
4290 }
4291 return formatOther(value);
4292 }
4293 function formatWithLength(maxLength) {
4294 return v => {
4295 if (maxLength <= 0) {
4296 return v;
4297 }
4298 const r = `${v}`;
4299 return r.length < maxLength ? v : `${r.substring(0, maxLength)} ...`;
4300 };
4301 }
4302 function apply(log, type, values, maxSize = -1) {
4303 if (values.length === 1 && isFunction(values[0])) {
4304 const fnResult = values[0]();
4305 return apply(log, type, Array.isArray(fnResult) ? fnResult : [fnResult], maxSize);
4306 }
4307 console[logTo[log]](formatDate(new Date()), type, ...values.map(loggerFormat).map(formatWithLength(maxSize)));
4308 }
4309 function noop() {
4310 }
4311 function isDebugOn(e, type) {
4312 return !!e && (e === '*' || type === e || e.endsWith('*') && type.startsWith(e.slice(0, -1)));
4313 }
4314 function isDebugOff(e, type) {
4315 return !!e && e.startsWith('-') && (type === e.slice(1) || e.endsWith('*') && type.startsWith(e.slice(1, -1)));
4316 }
4317 function getDebugFlag(env, type) {
4318 let flag = false;
4319 for (const e of env) {
4320 if (isDebugOn(e, type)) {
4321 flag = true;
4322 } else if (isDebugOff(e, type)) {
4323 flag = false;
4324 }
4325 }
4326 return flag;
4327 }
4328 function parseEnv(type) {
4329 const env = (hasProcess ? process : {}).env || {};
4330 const maxSize = parseInt(env.DEBUG_MAX || '-1', 10);
4331 return [getDebugFlag((env.DEBUG || '').toLowerCase().split(','), type), isNaN(maxSize) ? -1 : maxSize];
4332 }
4333 function logger(_type) {
4334 const type = `${_type.toUpperCase()}:`.padStart(16);
4335 const [isDebug, maxSize] = parseEnv(_type.toLowerCase());
4336 return {
4337 debug: isDebug ? (...values) => apply('debug', type, values, maxSize) : noop,
4338 error: (...values) => apply('error', type, values),
4339 log: (...values) => apply('log', type, values),
4340 noop,
4341 warn: (...values) => apply('warn', type, values)
4342 };
4343 }
4344
4345 function defaultGetId() {
4346 return 'none';
4347 }
4348 function memoize(fn, {
4349 getInstanceId = defaultGetId
4350 } = {}) {
4351 const cache = {};
4352 const memoized = (...args) => {
4353 const stringParams = stringify(args);
4354 const instanceId = getInstanceId();
4355 if (!cache[instanceId]) {
4356 cache[instanceId] = {};
4357 }
4358 if (cache[instanceId][stringParams] === undefined) {
4359 cache[instanceId][stringParams] = fn(...args);
4360 }
4361 return cache[instanceId][stringParams];
4362 };
4363 memoized.unmemoize = (...args) => {
4364 const stringParams = stringify(args);
4365 const instanceId = getInstanceId();
4366 if (cache[instanceId] && cache[instanceId][stringParams] !== undefined) {
4367 delete cache[instanceId][stringParams];
4368 }
4369 };
4370 return memoized;
4371 }
4372
4373 function nextTick(onExec, onError) {
4374 Promise.resolve().then(() => {
4375 onExec();
4376 }).catch(error => {
4377 if (onError) {
4378 onError(error);
4379 } else {
4380 console.error(error);
4381 }
4382 });
4383 }
4384
4385 function numberToHex(value, bitLength = -1) {
4386 if (value === undefined || value === null || isNaN(value)) {
4387 return '0x';
4388 }
4389 const hex = value.toString(16);
4390 return hexFixLength(hex.length % 2 ? `0${hex}` : hex, bitLength, true);
4391 }
4392
4393 function numberToU8a(value, bitLength = -1) {
4394 return value === undefined || value === null || isNaN(value) ? new Uint8Array() : hexToU8a(numberToHex(value, bitLength));
4395 }
4396
4397 function objectClear(value) {
4398 const keys = Object.keys(value);
4399 for (let i = 0; i < keys.length; i++) {
4400 delete value[keys[i]];
4401 }
4402 return value;
4403 }
4404
4405 function objectCopy(source) {
4406 return objectSpread({}, source);
4407 }
4408
4409 function objectEntries(obj) {
4410 return Object.entries(obj);
4411 }
4412
4413 function objectKeys(value) {
4414 return Object.keys(value);
4415 }
4416
4417 function objectProperty(that, key, getter) {
4418 if (!(key in that)) {
4419 Object.defineProperty(that, key, {
4420 enumerable: true,
4421 get: () => getter(key)
4422 });
4423 }
4424 }
4425 function objectProperties(that, keys, getter) {
4426 for (let i = 0; i < keys.length; i++) {
4427 objectProperty(that, keys[i], k => getter(k, i));
4428 }
4429 }
4430
4431 function objectValues(obj) {
4432 return Object.values(obj);
4433 }
4434
4435 function promisify(self, fn, ...params) {
4436 return new Promise((resolve, reject) => {
4437 fn.apply(self, params.concat((error, result) => {
4438 if (error) {
4439 reject(error);
4440 } else {
4441 resolve(result);
4442 }
4443 }));
4444 });
4445 }
4446
4447 const CC_TO_UP = new Array(256);
4448 const CC_TO_LO = new Array(256);
4449 for (let i = 0; i < CC_TO_UP.length; i++) {
4450 CC_TO_LO[i] = String.fromCharCode(i).toLowerCase();
4451 CC_TO_UP[i] = String.fromCharCode(i).toUpperCase();
4452 }
4453 function formatAllCaps(w) {
4454 return w.slice(0, w.length - 1).toLowerCase() + CC_TO_UP[w.charCodeAt(w.length - 1)];
4455 }
4456 function converter$1(format) {
4457 return value => {
4458 const parts = value
4459 .replace(/[-_., ]+/g, ' ')
4460 .trim()
4461 .split(' ');
4462 const count = parts.length;
4463 let result = '';
4464 for (let i = 0; i < count; i++) {
4465 const w = parts[i];
4466 result += format(/^[\dA-Z]+$/.test(w)
4467 ? w.toLowerCase()
4468 : w.replace(/^[\dA-Z]{2,}[^a-z]/, formatAllCaps), i);
4469 }
4470 return result;
4471 };
4472 }
4473 const stringCamelCase = converter$1((w, i) =>
4474 (i ? CC_TO_UP[w.charCodeAt(0)] : CC_TO_LO[w.charCodeAt(0)]) + w.slice(1));
4475 const stringPascalCase = converter$1(w =>
4476 CC_TO_UP[w.charCodeAt(0)] + w.slice(1));
4477
4478 function converter(map) {
4479 return value => value ? map[value.charCodeAt(0)] + value.slice(1) : '';
4480 }
4481 const stringLowerFirst = converter(CC_TO_LO);
4482 const stringUpperFirst = converter(CC_TO_UP);
4483
4484 function stringShorten(value, prefixLength = 6) {
4485 return value.length <= 2 + 2 * prefixLength ? value.toString() : `${value.substring(0, prefixLength)}${value.slice(-prefixLength)}`;
4486 }
4487
4488 function stringToHex(value) {
4489 return u8aToHex(stringToU8a(value));
4490 }
4491
4492 const DEDUPE = 'Either remove and explicitly install matching versions or dedupe using your package manager.\nThe following conflicting packages were found:';
4493 function getEntry(name) {
4494 const _global = xglobal;
4495 if (!_global.__polkadotjs) {
4496 _global.__polkadotjs = {};
4497 }
4498 if (!_global.__polkadotjs[name]) {
4499 _global.__polkadotjs[name] = [];
4500 }
4501 return _global.__polkadotjs[name];
4502 }
4503 function formatDisplay(all, fmt) {
4504 let max = 0;
4505 for (let i = 0; i < all.length; i++) {
4506 max = Math.max(max, all[i].version.length);
4507 }
4508 return all.map(d => `\t${fmt(d.version.padEnd(max), d).join('\t')}`).join('\n');
4509 }
4510 function formatInfo(version, {
4511 name
4512 }) {
4513 return [version, name];
4514 }
4515 function formatVersion(version, {
4516 path,
4517 type
4518 }) {
4519 let extracted;
4520 if (path && path.length >= 5) {
4521 const nmIndex = path.indexOf('node_modules');
4522 extracted = nmIndex === -1 ? path : path.substring(nmIndex);
4523 } else {
4524 extracted = '<unknown>';
4525 }
4526 return [`${`${type || ''}`.padStart(3)} ${version}`, extracted];
4527 }
4528 function getPath(infoPath, pathOrFn) {
4529 if (infoPath) {
4530 return infoPath;
4531 } else if (isFunction(pathOrFn)) {
4532 try {
4533 return pathOrFn() || '';
4534 } catch (error) {
4535 return '';
4536 }
4537 }
4538 return pathOrFn || '';
4539 }
4540 function warn(pre, all, fmt) {
4541 console.warn(`${pre}\n${DEDUPE}\n${formatDisplay(all, fmt)}`);
4542 }
4543 function detectPackage({
4544 name,
4545 path,
4546 type,
4547 version
4548 }, pathOrFn, deps = []) {
4549 if (!name.startsWith('@polkadot')) {
4550 throw new Error(`Invalid package descriptor ${name}`);
4551 }
4552 const entry = getEntry(name);
4553 entry.push({
4554 path: getPath(path, pathOrFn),
4555 type,
4556 version
4557 });
4558 if (entry.length !== 1) {
4559 warn(`${name} has multiple versions, ensure that there is only one installed.`, entry, formatVersion);
4560 } else {
4561 const mismatches = deps.filter(d => d && d.version !== version);
4562 if (mismatches.length) {
4563 warn(`${name} requires direct dependencies exactly matching version ${version}.`, mismatches, formatInfo);
4564 }
4565 }
4566 }
4567
4568 exports.BN = BN;
4569 exports.BN_BILLION = BN_BILLION;
4570 exports.BN_EIGHT = BN_EIGHT;
4571 exports.BN_FIVE = BN_FIVE;
4572 exports.BN_FOUR = BN_FOUR;
4573 exports.BN_HUNDRED = BN_HUNDRED;
4574 exports.BN_MAX_INTEGER = BN_MAX_INTEGER;
4575 exports.BN_MILLION = BN_MILLION;
4576 exports.BN_NINE = BN_NINE;
4577 exports.BN_ONE = BN_ONE;
4578 exports.BN_QUINTILL = BN_QUINTILL;
4579 exports.BN_SEVEN = BN_SEVEN;
4580 exports.BN_SIX = BN_SIX;
4581 exports.BN_TEN = BN_TEN;
4582 exports.BN_THOUSAND = BN_THOUSAND;
4583 exports.BN_THREE = BN_THREE;
4584 exports.BN_TWO = BN_TWO;
4585 exports.BN_ZERO = BN_ZERO;
4586 exports.U8A_WRAP_ETHEREUM = U8A_WRAP_ETHEREUM;
4587 exports.U8A_WRAP_POSTFIX = U8A_WRAP_POSTFIX;
4588 exports.U8A_WRAP_PREFIX = U8A_WRAP_PREFIX;
4589 exports._0n = _0n;
4590 exports._1Bn = _1Bn;
4591 exports._1Mn = _1Mn;
4592 exports._1Qn = _1Qn;
4593 exports._1n = _1n;
4594 exports._2pow53n = _2pow53n;
4595 exports.arrayChunk = arrayChunk;
4596 exports.arrayFilter = arrayFilter;
4597 exports.arrayFlatten = arrayFlatten;
4598 exports.arrayRange = arrayRange;
4599 exports.arrayShuffle = arrayShuffle;
4600 exports.arrayZip = arrayZip;
4601 exports.assert = assert;
4602 exports.assertReturn = assertReturn;
4603 exports.assertUnreachable = assertUnreachable;
4604 exports.bnFromHex = hexToBn;
4605 exports.bnMax = bnMax;
4606 exports.bnMin = bnMin;
4607 exports.bnSqrt = bnSqrt;
4608 exports.bnToBn = bnToBn;
4609 exports.bnToHex = bnToHex;
4610 exports.bnToU8a = bnToU8a;
4611 exports.bufferToU8a = bufferToU8a;
4612 exports.calcSi = calcSi;
4613 exports.compactAddLength = compactAddLength;
4614 exports.compactFromU8a = compactFromU8a;
4615 exports.compactFromU8aLim = compactFromU8aLim;
4616 exports.compactStripLength = compactStripLength;
4617 exports.compactToU8a = compactToU8a;
4618 exports.detectPackage = detectPackage;
4619 exports.extractTime = extractTime;
4620 exports.findSi = findSi;
4621 exports.floatToU8a = floatToU8a;
4622 exports.formatBalance = formatBalance;
4623 exports.formatDate = formatDate;
4624 exports.formatDecimal = formatDecimal;
4625 exports.formatElapsed = formatElapsed;
4626 exports.formatNumber = formatNumber;
4627 exports.hasBigInt = hasBigInt;
4628 exports.hasBuffer = hasBuffer;
4629 exports.hasCjs = hasCjs;
4630 exports.hasDirname = hasDirname;
4631 exports.hasEsm = hasEsm;
4632 exports.hasProcess = hasProcess;
4633 exports.hasWasm = hasWasm;
4634 exports.hexAddPrefix = hexAddPrefix;
4635 exports.hexFixLength = hexFixLength;
4636 exports.hexHasPrefix = hexHasPrefix;
4637 exports.hexStripPrefix = hexStripPrefix;
4638 exports.hexToBigInt = hexToBigInt;
4639 exports.hexToBn = hexToBn;
4640 exports.hexToNumber = hexToNumber;
4641 exports.hexToString = hexToString;
4642 exports.hexToU8a = hexToU8a;
4643 exports.isArray = isArray;
4644 exports.isAscii = isAscii;
4645 exports.isBigInt = isBigInt;
4646 exports.isBn = isBn;
4647 exports.isBoolean = isBoolean;
4648 exports.isBuffer = isBuffer;
4649 exports.isChildClass = isChildClass;
4650 exports.isCodec = isCodec;
4651 exports.isCompact = isCompact;
4652 exports.isError = isError;
4653 exports.isFunction = isFunction;
4654 exports.isHex = isHex;
4655 exports.isInstanceOf = isInstanceOf;
4656 exports.isIp = isIp;
4657 exports.isJsonObject = isJsonObject;
4658 exports.isNull = isNull;
4659 exports.isNumber = isNumber;
4660 exports.isObject = isObject;
4661 exports.isObservable = isObservable;
4662 exports.isPromise = isPromise;
4663 exports.isString = isString;
4664 exports.isTestChain = isTestChain;
4665 exports.isToBigInt = isToBigInt;
4666 exports.isToBn = isToBn;
4667 exports.isU8a = isU8a;
4668 exports.isUndefined = isUndefined;
4669 exports.isUtf8 = isUtf8;
4670 exports.isWasm = isWasm;
4671 exports.lazyMethod = lazyMethod;
4672 exports.lazyMethods = lazyMethods;
4673 exports.logger = logger;
4674 exports.loggerFormat = loggerFormat;
4675 exports.memoize = memoize;
4676 exports.nMax = nMax;
4677 exports.nMin = nMin;
4678 exports.nSqrt = nSqrt;
4679 exports.nToBigInt = nToBigInt;
4680 exports.nToHex = nToHex;
4681 exports.nToU8a = nToU8a;
4682 exports.nextTick = nextTick;
4683 exports.numberToHex = numberToHex;
4684 exports.numberToU8a = numberToU8a;
4685 exports.objectClear = objectClear;
4686 exports.objectCopy = objectCopy;
4687 exports.objectEntries = objectEntries;
4688 exports.objectKeys = objectKeys;
4689 exports.objectProperties = objectProperties;
4690 exports.objectProperty = objectProperty;
4691 exports.objectSpread = objectSpread;
4692 exports.objectValues = objectValues;
4693 exports.packageInfo = packageInfo$5;
4694 exports.promisify = promisify;
4695 exports.stringCamelCase = stringCamelCase;
4696 exports.stringLowerFirst = stringLowerFirst;
4697 exports.stringPascalCase = stringPascalCase;
4698 exports.stringShorten = stringShorten;
4699 exports.stringToHex = stringToHex;
4700 exports.stringToU8a = stringToU8a;
4701 exports.stringUpperFirst = stringUpperFirst;
4702 exports.stringify = stringify;
4703 exports.u8aCmp = u8aCmp;
4704 exports.u8aConcat = u8aConcat;
4705 exports.u8aConcatStrict = u8aConcatStrict;
4706 exports.u8aEmpty = u8aEmpty;
4707 exports.u8aEq = u8aEq;
4708 exports.u8aFixLength = u8aFixLength;
4709 exports.u8aIsWrapped = u8aIsWrapped;
4710 exports.u8aSorted = u8aSorted;
4711 exports.u8aToBigInt = u8aToBigInt;
4712 exports.u8aToBn = u8aToBn;
4713 exports.u8aToBuffer = u8aToBuffer;
4714 exports.u8aToFloat = u8aToFloat;
4715 exports.u8aToHex = u8aToHex;
4716 exports.u8aToNumber = u8aToNumber;
4717 exports.u8aToString = u8aToString;
4718 exports.u8aToU8a = u8aToU8a;
4719 exports.u8aUnwrapBytes = u8aUnwrapBytes;
4720 exports.u8aWrapBytes = u8aWrapBytes;
4721
4722 Object.defineProperty(exports, '__esModule', { value: true });
4723
4724}));