@jpool/bond-cli 1.5.3 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +380 -112
  2. package/dist/cli.js +3322 -171
  3. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -6,6 +6,12 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __esm = (fn, res) => function __init() {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ };
12
+ var __commonJS = (cb, mod) => function __require() {
13
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
14
+ };
9
15
  var __export = (target, all) => {
10
16
  for (var name in all)
11
17
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,21 +22,2922 @@ var __copyProps = (to, from, except, desc) => {
16
22
  if (!__hasOwnProp.call(to, key) && key !== except)
17
23
  __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
24
  }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
25
+ return to;
26
+ };
27
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
28
+ // If the importer is in node compatibility mode or this is not an ESM
29
+ // file that has been converted to a CommonJS file using a Babel-
30
+ // compatible transform (i.e. "__esModule" has not been set), then set
31
+ // "default" to the CommonJS "module.exports" for node compatibility.
32
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
33
+ mod
34
+ ));
35
+
36
+ // ../../node_modules/.pnpm/tsup@8.5.0_@swc+core@1.13.5_@swc+helpers@0.5.17__jiti@2.5.1_postcss@8.5.6_tsx@4.20.5_typescript@5.9.3_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js
37
+ var init_cjs_shims = __esm({
38
+ "../../node_modules/.pnpm/tsup@8.5.0_@swc+core@1.13.5_@swc+helpers@0.5.17__jiti@2.5.1_postcss@8.5.6_tsx@4.20.5_typescript@5.9.3_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js"() {
39
+ "use strict";
40
+ }
41
+ });
42
+
43
+ // ../../node_modules/.pnpm/bn.js@5.2.2/node_modules/bn.js/lib/bn.js
44
+ var require_bn = __commonJS({
45
+ "../../node_modules/.pnpm/bn.js@5.2.2/node_modules/bn.js/lib/bn.js"(exports2, module2) {
46
+ "use strict";
47
+ init_cjs_shims();
48
+ (function(module3, exports3) {
49
+ "use strict";
50
+ function assert(val, msg) {
51
+ if (!val) throw new Error(msg || "Assertion failed");
52
+ }
53
+ function inherits(ctor, superCtor) {
54
+ ctor.super_ = superCtor;
55
+ var TempCtor = function() {
56
+ };
57
+ TempCtor.prototype = superCtor.prototype;
58
+ ctor.prototype = new TempCtor();
59
+ ctor.prototype.constructor = ctor;
60
+ }
61
+ function BN2(number, base, endian) {
62
+ if (BN2.isBN(number)) {
63
+ return number;
64
+ }
65
+ this.negative = 0;
66
+ this.words = null;
67
+ this.length = 0;
68
+ this.red = null;
69
+ if (number !== null) {
70
+ if (base === "le" || base === "be") {
71
+ endian = base;
72
+ base = 10;
73
+ }
74
+ this._init(number || 0, base || 10, endian || "be");
75
+ }
76
+ }
77
+ if (typeof module3 === "object") {
78
+ module3.exports = BN2;
79
+ } else {
80
+ exports3.BN = BN2;
81
+ }
82
+ BN2.BN = BN2;
83
+ BN2.wordSize = 26;
84
+ var Buffer3;
85
+ try {
86
+ if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") {
87
+ Buffer3 = window.Buffer;
88
+ } else {
89
+ Buffer3 = require("buffer").Buffer;
90
+ }
91
+ } catch (e) {
92
+ }
93
+ BN2.isBN = function isBN(num) {
94
+ if (num instanceof BN2) {
95
+ return true;
96
+ }
97
+ return num !== null && typeof num === "object" && num.constructor.wordSize === BN2.wordSize && Array.isArray(num.words);
98
+ };
99
+ BN2.max = function max(left, right) {
100
+ if (left.cmp(right) > 0) return left;
101
+ return right;
102
+ };
103
+ BN2.min = function min(left, right) {
104
+ if (left.cmp(right) < 0) return left;
105
+ return right;
106
+ };
107
+ BN2.prototype._init = function init(number, base, endian) {
108
+ if (typeof number === "number") {
109
+ return this._initNumber(number, base, endian);
110
+ }
111
+ if (typeof number === "object") {
112
+ return this._initArray(number, base, endian);
113
+ }
114
+ if (base === "hex") {
115
+ base = 16;
116
+ }
117
+ assert(base === (base | 0) && base >= 2 && base <= 36);
118
+ number = number.toString().replace(/\s+/g, "");
119
+ var start = 0;
120
+ if (number[0] === "-") {
121
+ start++;
122
+ this.negative = 1;
123
+ }
124
+ if (start < number.length) {
125
+ if (base === 16) {
126
+ this._parseHex(number, start, endian);
127
+ } else {
128
+ this._parseBase(number, base, start);
129
+ if (endian === "le") {
130
+ this._initArray(this.toArray(), base, endian);
131
+ }
132
+ }
133
+ }
134
+ };
135
+ BN2.prototype._initNumber = function _initNumber(number, base, endian) {
136
+ if (number < 0) {
137
+ this.negative = 1;
138
+ number = -number;
139
+ }
140
+ if (number < 67108864) {
141
+ this.words = [number & 67108863];
142
+ this.length = 1;
143
+ } else if (number < 4503599627370496) {
144
+ this.words = [
145
+ number & 67108863,
146
+ number / 67108864 & 67108863
147
+ ];
148
+ this.length = 2;
149
+ } else {
150
+ assert(number < 9007199254740992);
151
+ this.words = [
152
+ number & 67108863,
153
+ number / 67108864 & 67108863,
154
+ 1
155
+ ];
156
+ this.length = 3;
157
+ }
158
+ if (endian !== "le") return;
159
+ this._initArray(this.toArray(), base, endian);
160
+ };
161
+ BN2.prototype._initArray = function _initArray(number, base, endian) {
162
+ assert(typeof number.length === "number");
163
+ if (number.length <= 0) {
164
+ this.words = [0];
165
+ this.length = 1;
166
+ return this;
167
+ }
168
+ this.length = Math.ceil(number.length / 3);
169
+ this.words = new Array(this.length);
170
+ for (var i = 0; i < this.length; i++) {
171
+ this.words[i] = 0;
172
+ }
173
+ var j, w;
174
+ var off = 0;
175
+ if (endian === "be") {
176
+ for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
177
+ w = number[i] | number[i - 1] << 8 | number[i - 2] << 16;
178
+ this.words[j] |= w << off & 67108863;
179
+ this.words[j + 1] = w >>> 26 - off & 67108863;
180
+ off += 24;
181
+ if (off >= 26) {
182
+ off -= 26;
183
+ j++;
184
+ }
185
+ }
186
+ } else if (endian === "le") {
187
+ for (i = 0, j = 0; i < number.length; i += 3) {
188
+ w = number[i] | number[i + 1] << 8 | number[i + 2] << 16;
189
+ this.words[j] |= w << off & 67108863;
190
+ this.words[j + 1] = w >>> 26 - off & 67108863;
191
+ off += 24;
192
+ if (off >= 26) {
193
+ off -= 26;
194
+ j++;
195
+ }
196
+ }
197
+ }
198
+ return this._strip();
199
+ };
200
+ function parseHex4Bits(string, index) {
201
+ var c = string.charCodeAt(index);
202
+ if (c >= 48 && c <= 57) {
203
+ return c - 48;
204
+ } else if (c >= 65 && c <= 70) {
205
+ return c - 55;
206
+ } else if (c >= 97 && c <= 102) {
207
+ return c - 87;
208
+ } else {
209
+ assert(false, "Invalid character in " + string);
210
+ }
211
+ }
212
+ function parseHexByte(string, lowerBound, index) {
213
+ var r = parseHex4Bits(string, index);
214
+ if (index - 1 >= lowerBound) {
215
+ r |= parseHex4Bits(string, index - 1) << 4;
216
+ }
217
+ return r;
218
+ }
219
+ BN2.prototype._parseHex = function _parseHex(number, start, endian) {
220
+ this.length = Math.ceil((number.length - start) / 6);
221
+ this.words = new Array(this.length);
222
+ for (var i = 0; i < this.length; i++) {
223
+ this.words[i] = 0;
224
+ }
225
+ var off = 0;
226
+ var j = 0;
227
+ var w;
228
+ if (endian === "be") {
229
+ for (i = number.length - 1; i >= start; i -= 2) {
230
+ w = parseHexByte(number, start, i) << off;
231
+ this.words[j] |= w & 67108863;
232
+ if (off >= 18) {
233
+ off -= 18;
234
+ j += 1;
235
+ this.words[j] |= w >>> 26;
236
+ } else {
237
+ off += 8;
238
+ }
239
+ }
240
+ } else {
241
+ var parseLength = number.length - start;
242
+ for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) {
243
+ w = parseHexByte(number, start, i) << off;
244
+ this.words[j] |= w & 67108863;
245
+ if (off >= 18) {
246
+ off -= 18;
247
+ j += 1;
248
+ this.words[j] |= w >>> 26;
249
+ } else {
250
+ off += 8;
251
+ }
252
+ }
253
+ }
254
+ this._strip();
255
+ };
256
+ function parseBase(str, start, end, mul) {
257
+ var r = 0;
258
+ var b = 0;
259
+ var len = Math.min(str.length, end);
260
+ for (var i = start; i < len; i++) {
261
+ var c = str.charCodeAt(i) - 48;
262
+ r *= mul;
263
+ if (c >= 49) {
264
+ b = c - 49 + 10;
265
+ } else if (c >= 17) {
266
+ b = c - 17 + 10;
267
+ } else {
268
+ b = c;
269
+ }
270
+ assert(c >= 0 && b < mul, "Invalid character");
271
+ r += b;
272
+ }
273
+ return r;
274
+ }
275
+ BN2.prototype._parseBase = function _parseBase(number, base, start) {
276
+ this.words = [0];
277
+ this.length = 1;
278
+ for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) {
279
+ limbLen++;
280
+ }
281
+ limbLen--;
282
+ limbPow = limbPow / base | 0;
283
+ var total = number.length - start;
284
+ var mod = total % limbLen;
285
+ var end = Math.min(total, total - mod) + start;
286
+ var word = 0;
287
+ for (var i = start; i < end; i += limbLen) {
288
+ word = parseBase(number, i, i + limbLen, base);
289
+ this.imuln(limbPow);
290
+ if (this.words[0] + word < 67108864) {
291
+ this.words[0] += word;
292
+ } else {
293
+ this._iaddn(word);
294
+ }
295
+ }
296
+ if (mod !== 0) {
297
+ var pow = 1;
298
+ word = parseBase(number, i, number.length, base);
299
+ for (i = 0; i < mod; i++) {
300
+ pow *= base;
301
+ }
302
+ this.imuln(pow);
303
+ if (this.words[0] + word < 67108864) {
304
+ this.words[0] += word;
305
+ } else {
306
+ this._iaddn(word);
307
+ }
308
+ }
309
+ this._strip();
310
+ };
311
+ BN2.prototype.copy = function copy(dest) {
312
+ dest.words = new Array(this.length);
313
+ for (var i = 0; i < this.length; i++) {
314
+ dest.words[i] = this.words[i];
315
+ }
316
+ dest.length = this.length;
317
+ dest.negative = this.negative;
318
+ dest.red = this.red;
319
+ };
320
+ function move(dest, src) {
321
+ dest.words = src.words;
322
+ dest.length = src.length;
323
+ dest.negative = src.negative;
324
+ dest.red = src.red;
325
+ }
326
+ BN2.prototype._move = function _move(dest) {
327
+ move(dest, this);
328
+ };
329
+ BN2.prototype.clone = function clone() {
330
+ var r = new BN2(null);
331
+ this.copy(r);
332
+ return r;
333
+ };
334
+ BN2.prototype._expand = function _expand(size) {
335
+ while (this.length < size) {
336
+ this.words[this.length++] = 0;
337
+ }
338
+ return this;
339
+ };
340
+ BN2.prototype._strip = function strip() {
341
+ while (this.length > 1 && this.words[this.length - 1] === 0) {
342
+ this.length--;
343
+ }
344
+ return this._normSign();
345
+ };
346
+ BN2.prototype._normSign = function _normSign() {
347
+ if (this.length === 1 && this.words[0] === 0) {
348
+ this.negative = 0;
349
+ }
350
+ return this;
351
+ };
352
+ if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") {
353
+ try {
354
+ BN2.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect;
355
+ } catch (e) {
356
+ BN2.prototype.inspect = inspect;
357
+ }
358
+ } else {
359
+ BN2.prototype.inspect = inspect;
360
+ }
361
+ function inspect() {
362
+ return (this.red ? "<BN-R: " : "<BN: ") + this.toString(16) + ">";
363
+ }
364
+ var zeros = [
365
+ "",
366
+ "0",
367
+ "00",
368
+ "000",
369
+ "0000",
370
+ "00000",
371
+ "000000",
372
+ "0000000",
373
+ "00000000",
374
+ "000000000",
375
+ "0000000000",
376
+ "00000000000",
377
+ "000000000000",
378
+ "0000000000000",
379
+ "00000000000000",
380
+ "000000000000000",
381
+ "0000000000000000",
382
+ "00000000000000000",
383
+ "000000000000000000",
384
+ "0000000000000000000",
385
+ "00000000000000000000",
386
+ "000000000000000000000",
387
+ "0000000000000000000000",
388
+ "00000000000000000000000",
389
+ "000000000000000000000000",
390
+ "0000000000000000000000000"
391
+ ];
392
+ var groupSizes = [
393
+ 0,
394
+ 0,
395
+ 25,
396
+ 16,
397
+ 12,
398
+ 11,
399
+ 10,
400
+ 9,
401
+ 8,
402
+ 8,
403
+ 7,
404
+ 7,
405
+ 7,
406
+ 7,
407
+ 6,
408
+ 6,
409
+ 6,
410
+ 6,
411
+ 6,
412
+ 6,
413
+ 6,
414
+ 5,
415
+ 5,
416
+ 5,
417
+ 5,
418
+ 5,
419
+ 5,
420
+ 5,
421
+ 5,
422
+ 5,
423
+ 5,
424
+ 5,
425
+ 5,
426
+ 5,
427
+ 5,
428
+ 5,
429
+ 5
430
+ ];
431
+ var groupBases = [
432
+ 0,
433
+ 0,
434
+ 33554432,
435
+ 43046721,
436
+ 16777216,
437
+ 48828125,
438
+ 60466176,
439
+ 40353607,
440
+ 16777216,
441
+ 43046721,
442
+ 1e7,
443
+ 19487171,
444
+ 35831808,
445
+ 62748517,
446
+ 7529536,
447
+ 11390625,
448
+ 16777216,
449
+ 24137569,
450
+ 34012224,
451
+ 47045881,
452
+ 64e6,
453
+ 4084101,
454
+ 5153632,
455
+ 6436343,
456
+ 7962624,
457
+ 9765625,
458
+ 11881376,
459
+ 14348907,
460
+ 17210368,
461
+ 20511149,
462
+ 243e5,
463
+ 28629151,
464
+ 33554432,
465
+ 39135393,
466
+ 45435424,
467
+ 52521875,
468
+ 60466176
469
+ ];
470
+ BN2.prototype.toString = function toString(base, padding) {
471
+ base = base || 10;
472
+ padding = padding | 0 || 1;
473
+ var out;
474
+ if (base === 16 || base === "hex") {
475
+ out = "";
476
+ var off = 0;
477
+ var carry = 0;
478
+ for (var i = 0; i < this.length; i++) {
479
+ var w = this.words[i];
480
+ var word = ((w << off | carry) & 16777215).toString(16);
481
+ carry = w >>> 24 - off & 16777215;
482
+ off += 2;
483
+ if (off >= 26) {
484
+ off -= 26;
485
+ i--;
486
+ }
487
+ if (carry !== 0 || i !== this.length - 1) {
488
+ out = zeros[6 - word.length] + word + out;
489
+ } else {
490
+ out = word + out;
491
+ }
492
+ }
493
+ if (carry !== 0) {
494
+ out = carry.toString(16) + out;
495
+ }
496
+ while (out.length % padding !== 0) {
497
+ out = "0" + out;
498
+ }
499
+ if (this.negative !== 0) {
500
+ out = "-" + out;
501
+ }
502
+ return out;
503
+ }
504
+ if (base === (base | 0) && base >= 2 && base <= 36) {
505
+ var groupSize = groupSizes[base];
506
+ var groupBase = groupBases[base];
507
+ out = "";
508
+ var c = this.clone();
509
+ c.negative = 0;
510
+ while (!c.isZero()) {
511
+ var r = c.modrn(groupBase).toString(base);
512
+ c = c.idivn(groupBase);
513
+ if (!c.isZero()) {
514
+ out = zeros[groupSize - r.length] + r + out;
515
+ } else {
516
+ out = r + out;
517
+ }
518
+ }
519
+ if (this.isZero()) {
520
+ out = "0" + out;
521
+ }
522
+ while (out.length % padding !== 0) {
523
+ out = "0" + out;
524
+ }
525
+ if (this.negative !== 0) {
526
+ out = "-" + out;
527
+ }
528
+ return out;
529
+ }
530
+ assert(false, "Base should be between 2 and 36");
531
+ };
532
+ BN2.prototype.toNumber = function toNumber() {
533
+ var ret = this.words[0];
534
+ if (this.length === 2) {
535
+ ret += this.words[1] * 67108864;
536
+ } else if (this.length === 3 && this.words[2] === 1) {
537
+ ret += 4503599627370496 + this.words[1] * 67108864;
538
+ } else if (this.length > 2) {
539
+ assert(false, "Number can only safely store up to 53 bits");
540
+ }
541
+ return this.negative !== 0 ? -ret : ret;
542
+ };
543
+ BN2.prototype.toJSON = function toJSON() {
544
+ return this.toString(16, 2);
545
+ };
546
+ if (Buffer3) {
547
+ BN2.prototype.toBuffer = function toBuffer(endian, length) {
548
+ return this.toArrayLike(Buffer3, endian, length);
549
+ };
550
+ }
551
+ BN2.prototype.toArray = function toArray(endian, length) {
552
+ return this.toArrayLike(Array, endian, length);
553
+ };
554
+ var allocate = function allocate2(ArrayType, size) {
555
+ if (ArrayType.allocUnsafe) {
556
+ return ArrayType.allocUnsafe(size);
557
+ }
558
+ return new ArrayType(size);
559
+ };
560
+ BN2.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
561
+ this._strip();
562
+ var byteLength = this.byteLength();
563
+ var reqLength = length || Math.max(1, byteLength);
564
+ assert(byteLength <= reqLength, "byte array longer than desired length");
565
+ assert(reqLength > 0, "Requested array length <= 0");
566
+ var res = allocate(ArrayType, reqLength);
567
+ var postfix = endian === "le" ? "LE" : "BE";
568
+ this["_toArrayLike" + postfix](res, byteLength);
569
+ return res;
570
+ };
571
+ BN2.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
572
+ var position = 0;
573
+ var carry = 0;
574
+ for (var i = 0, shift = 0; i < this.length; i++) {
575
+ var word = this.words[i] << shift | carry;
576
+ res[position++] = word & 255;
577
+ if (position < res.length) {
578
+ res[position++] = word >> 8 & 255;
579
+ }
580
+ if (position < res.length) {
581
+ res[position++] = word >> 16 & 255;
582
+ }
583
+ if (shift === 6) {
584
+ if (position < res.length) {
585
+ res[position++] = word >> 24 & 255;
586
+ }
587
+ carry = 0;
588
+ shift = 0;
589
+ } else {
590
+ carry = word >>> 24;
591
+ shift += 2;
592
+ }
593
+ }
594
+ if (position < res.length) {
595
+ res[position++] = carry;
596
+ while (position < res.length) {
597
+ res[position++] = 0;
598
+ }
599
+ }
600
+ };
601
+ BN2.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
602
+ var position = res.length - 1;
603
+ var carry = 0;
604
+ for (var i = 0, shift = 0; i < this.length; i++) {
605
+ var word = this.words[i] << shift | carry;
606
+ res[position--] = word & 255;
607
+ if (position >= 0) {
608
+ res[position--] = word >> 8 & 255;
609
+ }
610
+ if (position >= 0) {
611
+ res[position--] = word >> 16 & 255;
612
+ }
613
+ if (shift === 6) {
614
+ if (position >= 0) {
615
+ res[position--] = word >> 24 & 255;
616
+ }
617
+ carry = 0;
618
+ shift = 0;
619
+ } else {
620
+ carry = word >>> 24;
621
+ shift += 2;
622
+ }
623
+ }
624
+ if (position >= 0) {
625
+ res[position--] = carry;
626
+ while (position >= 0) {
627
+ res[position--] = 0;
628
+ }
629
+ }
630
+ };
631
+ if (Math.clz32) {
632
+ BN2.prototype._countBits = function _countBits(w) {
633
+ return 32 - Math.clz32(w);
634
+ };
635
+ } else {
636
+ BN2.prototype._countBits = function _countBits(w) {
637
+ var t = w;
638
+ var r = 0;
639
+ if (t >= 4096) {
640
+ r += 13;
641
+ t >>>= 13;
642
+ }
643
+ if (t >= 64) {
644
+ r += 7;
645
+ t >>>= 7;
646
+ }
647
+ if (t >= 8) {
648
+ r += 4;
649
+ t >>>= 4;
650
+ }
651
+ if (t >= 2) {
652
+ r += 2;
653
+ t >>>= 2;
654
+ }
655
+ return r + t;
656
+ };
657
+ }
658
+ BN2.prototype._zeroBits = function _zeroBits(w) {
659
+ if (w === 0) return 26;
660
+ var t = w;
661
+ var r = 0;
662
+ if ((t & 8191) === 0) {
663
+ r += 13;
664
+ t >>>= 13;
665
+ }
666
+ if ((t & 127) === 0) {
667
+ r += 7;
668
+ t >>>= 7;
669
+ }
670
+ if ((t & 15) === 0) {
671
+ r += 4;
672
+ t >>>= 4;
673
+ }
674
+ if ((t & 3) === 0) {
675
+ r += 2;
676
+ t >>>= 2;
677
+ }
678
+ if ((t & 1) === 0) {
679
+ r++;
680
+ }
681
+ return r;
682
+ };
683
+ BN2.prototype.bitLength = function bitLength() {
684
+ var w = this.words[this.length - 1];
685
+ var hi = this._countBits(w);
686
+ return (this.length - 1) * 26 + hi;
687
+ };
688
+ function toBitArray(num) {
689
+ var w = new Array(num.bitLength());
690
+ for (var bit = 0; bit < w.length; bit++) {
691
+ var off = bit / 26 | 0;
692
+ var wbit = bit % 26;
693
+ w[bit] = num.words[off] >>> wbit & 1;
694
+ }
695
+ return w;
696
+ }
697
+ BN2.prototype.zeroBits = function zeroBits() {
698
+ if (this.isZero()) return 0;
699
+ var r = 0;
700
+ for (var i = 0; i < this.length; i++) {
701
+ var b = this._zeroBits(this.words[i]);
702
+ r += b;
703
+ if (b !== 26) break;
704
+ }
705
+ return r;
706
+ };
707
+ BN2.prototype.byteLength = function byteLength() {
708
+ return Math.ceil(this.bitLength() / 8);
709
+ };
710
+ BN2.prototype.toTwos = function toTwos(width) {
711
+ if (this.negative !== 0) {
712
+ return this.abs().inotn(width).iaddn(1);
713
+ }
714
+ return this.clone();
715
+ };
716
+ BN2.prototype.fromTwos = function fromTwos(width) {
717
+ if (this.testn(width - 1)) {
718
+ return this.notn(width).iaddn(1).ineg();
719
+ }
720
+ return this.clone();
721
+ };
722
+ BN2.prototype.isNeg = function isNeg() {
723
+ return this.negative !== 0;
724
+ };
725
+ BN2.prototype.neg = function neg() {
726
+ return this.clone().ineg();
727
+ };
728
+ BN2.prototype.ineg = function ineg() {
729
+ if (!this.isZero()) {
730
+ this.negative ^= 1;
731
+ }
732
+ return this;
733
+ };
734
+ BN2.prototype.iuor = function iuor(num) {
735
+ while (this.length < num.length) {
736
+ this.words[this.length++] = 0;
737
+ }
738
+ for (var i = 0; i < num.length; i++) {
739
+ this.words[i] = this.words[i] | num.words[i];
740
+ }
741
+ return this._strip();
742
+ };
743
+ BN2.prototype.ior = function ior(num) {
744
+ assert((this.negative | num.negative) === 0);
745
+ return this.iuor(num);
746
+ };
747
+ BN2.prototype.or = function or(num) {
748
+ if (this.length > num.length) return this.clone().ior(num);
749
+ return num.clone().ior(this);
750
+ };
751
+ BN2.prototype.uor = function uor(num) {
752
+ if (this.length > num.length) return this.clone().iuor(num);
753
+ return num.clone().iuor(this);
754
+ };
755
+ BN2.prototype.iuand = function iuand(num) {
756
+ var b;
757
+ if (this.length > num.length) {
758
+ b = num;
759
+ } else {
760
+ b = this;
761
+ }
762
+ for (var i = 0; i < b.length; i++) {
763
+ this.words[i] = this.words[i] & num.words[i];
764
+ }
765
+ this.length = b.length;
766
+ return this._strip();
767
+ };
768
+ BN2.prototype.iand = function iand(num) {
769
+ assert((this.negative | num.negative) === 0);
770
+ return this.iuand(num);
771
+ };
772
+ BN2.prototype.and = function and(num) {
773
+ if (this.length > num.length) return this.clone().iand(num);
774
+ return num.clone().iand(this);
775
+ };
776
+ BN2.prototype.uand = function uand(num) {
777
+ if (this.length > num.length) return this.clone().iuand(num);
778
+ return num.clone().iuand(this);
779
+ };
780
+ BN2.prototype.iuxor = function iuxor(num) {
781
+ var a;
782
+ var b;
783
+ if (this.length > num.length) {
784
+ a = this;
785
+ b = num;
786
+ } else {
787
+ a = num;
788
+ b = this;
789
+ }
790
+ for (var i = 0; i < b.length; i++) {
791
+ this.words[i] = a.words[i] ^ b.words[i];
792
+ }
793
+ if (this !== a) {
794
+ for (; i < a.length; i++) {
795
+ this.words[i] = a.words[i];
796
+ }
797
+ }
798
+ this.length = a.length;
799
+ return this._strip();
800
+ };
801
+ BN2.prototype.ixor = function ixor(num) {
802
+ assert((this.negative | num.negative) === 0);
803
+ return this.iuxor(num);
804
+ };
805
+ BN2.prototype.xor = function xor(num) {
806
+ if (this.length > num.length) return this.clone().ixor(num);
807
+ return num.clone().ixor(this);
808
+ };
809
+ BN2.prototype.uxor = function uxor(num) {
810
+ if (this.length > num.length) return this.clone().iuxor(num);
811
+ return num.clone().iuxor(this);
812
+ };
813
+ BN2.prototype.inotn = function inotn(width) {
814
+ assert(typeof width === "number" && width >= 0);
815
+ var bytesNeeded = Math.ceil(width / 26) | 0;
816
+ var bitsLeft = width % 26;
817
+ this._expand(bytesNeeded);
818
+ if (bitsLeft > 0) {
819
+ bytesNeeded--;
820
+ }
821
+ for (var i = 0; i < bytesNeeded; i++) {
822
+ this.words[i] = ~this.words[i] & 67108863;
823
+ }
824
+ if (bitsLeft > 0) {
825
+ this.words[i] = ~this.words[i] & 67108863 >> 26 - bitsLeft;
826
+ }
827
+ return this._strip();
828
+ };
829
+ BN2.prototype.notn = function notn(width) {
830
+ return this.clone().inotn(width);
831
+ };
832
+ BN2.prototype.setn = function setn(bit, val) {
833
+ assert(typeof bit === "number" && bit >= 0);
834
+ var off = bit / 26 | 0;
835
+ var wbit = bit % 26;
836
+ this._expand(off + 1);
837
+ if (val) {
838
+ this.words[off] = this.words[off] | 1 << wbit;
839
+ } else {
840
+ this.words[off] = this.words[off] & ~(1 << wbit);
841
+ }
842
+ return this._strip();
843
+ };
844
+ BN2.prototype.iadd = function iadd(num) {
845
+ var r;
846
+ if (this.negative !== 0 && num.negative === 0) {
847
+ this.negative = 0;
848
+ r = this.isub(num);
849
+ this.negative ^= 1;
850
+ return this._normSign();
851
+ } else if (this.negative === 0 && num.negative !== 0) {
852
+ num.negative = 0;
853
+ r = this.isub(num);
854
+ num.negative = 1;
855
+ return r._normSign();
856
+ }
857
+ var a, b;
858
+ if (this.length > num.length) {
859
+ a = this;
860
+ b = num;
861
+ } else {
862
+ a = num;
863
+ b = this;
864
+ }
865
+ var carry = 0;
866
+ for (var i = 0; i < b.length; i++) {
867
+ r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
868
+ this.words[i] = r & 67108863;
869
+ carry = r >>> 26;
870
+ }
871
+ for (; carry !== 0 && i < a.length; i++) {
872
+ r = (a.words[i] | 0) + carry;
873
+ this.words[i] = r & 67108863;
874
+ carry = r >>> 26;
875
+ }
876
+ this.length = a.length;
877
+ if (carry !== 0) {
878
+ this.words[this.length] = carry;
879
+ this.length++;
880
+ } else if (a !== this) {
881
+ for (; i < a.length; i++) {
882
+ this.words[i] = a.words[i];
883
+ }
884
+ }
885
+ return this;
886
+ };
887
+ BN2.prototype.add = function add(num) {
888
+ var res;
889
+ if (num.negative !== 0 && this.negative === 0) {
890
+ num.negative = 0;
891
+ res = this.sub(num);
892
+ num.negative ^= 1;
893
+ return res;
894
+ } else if (num.negative === 0 && this.negative !== 0) {
895
+ this.negative = 0;
896
+ res = num.sub(this);
897
+ this.negative = 1;
898
+ return res;
899
+ }
900
+ if (this.length > num.length) return this.clone().iadd(num);
901
+ return num.clone().iadd(this);
902
+ };
903
+ BN2.prototype.isub = function isub(num) {
904
+ if (num.negative !== 0) {
905
+ num.negative = 0;
906
+ var r = this.iadd(num);
907
+ num.negative = 1;
908
+ return r._normSign();
909
+ } else if (this.negative !== 0) {
910
+ this.negative = 0;
911
+ this.iadd(num);
912
+ this.negative = 1;
913
+ return this._normSign();
914
+ }
915
+ var cmp = this.cmp(num);
916
+ if (cmp === 0) {
917
+ this.negative = 0;
918
+ this.length = 1;
919
+ this.words[0] = 0;
920
+ return this;
921
+ }
922
+ var a, b;
923
+ if (cmp > 0) {
924
+ a = this;
925
+ b = num;
926
+ } else {
927
+ a = num;
928
+ b = this;
929
+ }
930
+ var carry = 0;
931
+ for (var i = 0; i < b.length; i++) {
932
+ r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
933
+ carry = r >> 26;
934
+ this.words[i] = r & 67108863;
935
+ }
936
+ for (; carry !== 0 && i < a.length; i++) {
937
+ r = (a.words[i] | 0) + carry;
938
+ carry = r >> 26;
939
+ this.words[i] = r & 67108863;
940
+ }
941
+ if (carry === 0 && i < a.length && a !== this) {
942
+ for (; i < a.length; i++) {
943
+ this.words[i] = a.words[i];
944
+ }
945
+ }
946
+ this.length = Math.max(this.length, i);
947
+ if (a !== this) {
948
+ this.negative = 1;
949
+ }
950
+ return this._strip();
951
+ };
952
+ BN2.prototype.sub = function sub(num) {
953
+ return this.clone().isub(num);
954
+ };
955
+ function smallMulTo(self, num, out) {
956
+ out.negative = num.negative ^ self.negative;
957
+ var len = self.length + num.length | 0;
958
+ out.length = len;
959
+ len = len - 1 | 0;
960
+ var a = self.words[0] | 0;
961
+ var b = num.words[0] | 0;
962
+ var r = a * b;
963
+ var lo = r & 67108863;
964
+ var carry = r / 67108864 | 0;
965
+ out.words[0] = lo;
966
+ for (var k = 1; k < len; k++) {
967
+ var ncarry = carry >>> 26;
968
+ var rword = carry & 67108863;
969
+ var maxJ = Math.min(k, num.length - 1);
970
+ for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
971
+ var i = k - j | 0;
972
+ a = self.words[i] | 0;
973
+ b = num.words[j] | 0;
974
+ r = a * b + rword;
975
+ ncarry += r / 67108864 | 0;
976
+ rword = r & 67108863;
977
+ }
978
+ out.words[k] = rword | 0;
979
+ carry = ncarry | 0;
980
+ }
981
+ if (carry !== 0) {
982
+ out.words[k] = carry | 0;
983
+ } else {
984
+ out.length--;
985
+ }
986
+ return out._strip();
987
+ }
988
+ var comb10MulTo = function comb10MulTo2(self, num, out) {
989
+ var a = self.words;
990
+ var b = num.words;
991
+ var o = out.words;
992
+ var c = 0;
993
+ var lo;
994
+ var mid;
995
+ var hi;
996
+ var a0 = a[0] | 0;
997
+ var al0 = a0 & 8191;
998
+ var ah0 = a0 >>> 13;
999
+ var a1 = a[1] | 0;
1000
+ var al1 = a1 & 8191;
1001
+ var ah1 = a1 >>> 13;
1002
+ var a2 = a[2] | 0;
1003
+ var al2 = a2 & 8191;
1004
+ var ah2 = a2 >>> 13;
1005
+ var a3 = a[3] | 0;
1006
+ var al3 = a3 & 8191;
1007
+ var ah3 = a3 >>> 13;
1008
+ var a4 = a[4] | 0;
1009
+ var al4 = a4 & 8191;
1010
+ var ah4 = a4 >>> 13;
1011
+ var a5 = a[5] | 0;
1012
+ var al5 = a5 & 8191;
1013
+ var ah5 = a5 >>> 13;
1014
+ var a6 = a[6] | 0;
1015
+ var al6 = a6 & 8191;
1016
+ var ah6 = a6 >>> 13;
1017
+ var a7 = a[7] | 0;
1018
+ var al7 = a7 & 8191;
1019
+ var ah7 = a7 >>> 13;
1020
+ var a8 = a[8] | 0;
1021
+ var al8 = a8 & 8191;
1022
+ var ah8 = a8 >>> 13;
1023
+ var a9 = a[9] | 0;
1024
+ var al9 = a9 & 8191;
1025
+ var ah9 = a9 >>> 13;
1026
+ var b0 = b[0] | 0;
1027
+ var bl0 = b0 & 8191;
1028
+ var bh0 = b0 >>> 13;
1029
+ var b1 = b[1] | 0;
1030
+ var bl1 = b1 & 8191;
1031
+ var bh1 = b1 >>> 13;
1032
+ var b2 = b[2] | 0;
1033
+ var bl2 = b2 & 8191;
1034
+ var bh2 = b2 >>> 13;
1035
+ var b3 = b[3] | 0;
1036
+ var bl3 = b3 & 8191;
1037
+ var bh3 = b3 >>> 13;
1038
+ var b4 = b[4] | 0;
1039
+ var bl4 = b4 & 8191;
1040
+ var bh4 = b4 >>> 13;
1041
+ var b5 = b[5] | 0;
1042
+ var bl5 = b5 & 8191;
1043
+ var bh5 = b5 >>> 13;
1044
+ var b6 = b[6] | 0;
1045
+ var bl6 = b6 & 8191;
1046
+ var bh6 = b6 >>> 13;
1047
+ var b7 = b[7] | 0;
1048
+ var bl7 = b7 & 8191;
1049
+ var bh7 = b7 >>> 13;
1050
+ var b8 = b[8] | 0;
1051
+ var bl8 = b8 & 8191;
1052
+ var bh8 = b8 >>> 13;
1053
+ var b9 = b[9] | 0;
1054
+ var bl9 = b9 & 8191;
1055
+ var bh9 = b9 >>> 13;
1056
+ out.negative = self.negative ^ num.negative;
1057
+ out.length = 19;
1058
+ lo = Math.imul(al0, bl0);
1059
+ mid = Math.imul(al0, bh0);
1060
+ mid = mid + Math.imul(ah0, bl0) | 0;
1061
+ hi = Math.imul(ah0, bh0);
1062
+ var w0 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1063
+ c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0;
1064
+ w0 &= 67108863;
1065
+ lo = Math.imul(al1, bl0);
1066
+ mid = Math.imul(al1, bh0);
1067
+ mid = mid + Math.imul(ah1, bl0) | 0;
1068
+ hi = Math.imul(ah1, bh0);
1069
+ lo = lo + Math.imul(al0, bl1) | 0;
1070
+ mid = mid + Math.imul(al0, bh1) | 0;
1071
+ mid = mid + Math.imul(ah0, bl1) | 0;
1072
+ hi = hi + Math.imul(ah0, bh1) | 0;
1073
+ var w1 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1074
+ c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0;
1075
+ w1 &= 67108863;
1076
+ lo = Math.imul(al2, bl0);
1077
+ mid = Math.imul(al2, bh0);
1078
+ mid = mid + Math.imul(ah2, bl0) | 0;
1079
+ hi = Math.imul(ah2, bh0);
1080
+ lo = lo + Math.imul(al1, bl1) | 0;
1081
+ mid = mid + Math.imul(al1, bh1) | 0;
1082
+ mid = mid + Math.imul(ah1, bl1) | 0;
1083
+ hi = hi + Math.imul(ah1, bh1) | 0;
1084
+ lo = lo + Math.imul(al0, bl2) | 0;
1085
+ mid = mid + Math.imul(al0, bh2) | 0;
1086
+ mid = mid + Math.imul(ah0, bl2) | 0;
1087
+ hi = hi + Math.imul(ah0, bh2) | 0;
1088
+ var w2 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1089
+ c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0;
1090
+ w2 &= 67108863;
1091
+ lo = Math.imul(al3, bl0);
1092
+ mid = Math.imul(al3, bh0);
1093
+ mid = mid + Math.imul(ah3, bl0) | 0;
1094
+ hi = Math.imul(ah3, bh0);
1095
+ lo = lo + Math.imul(al2, bl1) | 0;
1096
+ mid = mid + Math.imul(al2, bh1) | 0;
1097
+ mid = mid + Math.imul(ah2, bl1) | 0;
1098
+ hi = hi + Math.imul(ah2, bh1) | 0;
1099
+ lo = lo + Math.imul(al1, bl2) | 0;
1100
+ mid = mid + Math.imul(al1, bh2) | 0;
1101
+ mid = mid + Math.imul(ah1, bl2) | 0;
1102
+ hi = hi + Math.imul(ah1, bh2) | 0;
1103
+ lo = lo + Math.imul(al0, bl3) | 0;
1104
+ mid = mid + Math.imul(al0, bh3) | 0;
1105
+ mid = mid + Math.imul(ah0, bl3) | 0;
1106
+ hi = hi + Math.imul(ah0, bh3) | 0;
1107
+ var w3 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1108
+ c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0;
1109
+ w3 &= 67108863;
1110
+ lo = Math.imul(al4, bl0);
1111
+ mid = Math.imul(al4, bh0);
1112
+ mid = mid + Math.imul(ah4, bl0) | 0;
1113
+ hi = Math.imul(ah4, bh0);
1114
+ lo = lo + Math.imul(al3, bl1) | 0;
1115
+ mid = mid + Math.imul(al3, bh1) | 0;
1116
+ mid = mid + Math.imul(ah3, bl1) | 0;
1117
+ hi = hi + Math.imul(ah3, bh1) | 0;
1118
+ lo = lo + Math.imul(al2, bl2) | 0;
1119
+ mid = mid + Math.imul(al2, bh2) | 0;
1120
+ mid = mid + Math.imul(ah2, bl2) | 0;
1121
+ hi = hi + Math.imul(ah2, bh2) | 0;
1122
+ lo = lo + Math.imul(al1, bl3) | 0;
1123
+ mid = mid + Math.imul(al1, bh3) | 0;
1124
+ mid = mid + Math.imul(ah1, bl3) | 0;
1125
+ hi = hi + Math.imul(ah1, bh3) | 0;
1126
+ lo = lo + Math.imul(al0, bl4) | 0;
1127
+ mid = mid + Math.imul(al0, bh4) | 0;
1128
+ mid = mid + Math.imul(ah0, bl4) | 0;
1129
+ hi = hi + Math.imul(ah0, bh4) | 0;
1130
+ var w4 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1131
+ c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0;
1132
+ w4 &= 67108863;
1133
+ lo = Math.imul(al5, bl0);
1134
+ mid = Math.imul(al5, bh0);
1135
+ mid = mid + Math.imul(ah5, bl0) | 0;
1136
+ hi = Math.imul(ah5, bh0);
1137
+ lo = lo + Math.imul(al4, bl1) | 0;
1138
+ mid = mid + Math.imul(al4, bh1) | 0;
1139
+ mid = mid + Math.imul(ah4, bl1) | 0;
1140
+ hi = hi + Math.imul(ah4, bh1) | 0;
1141
+ lo = lo + Math.imul(al3, bl2) | 0;
1142
+ mid = mid + Math.imul(al3, bh2) | 0;
1143
+ mid = mid + Math.imul(ah3, bl2) | 0;
1144
+ hi = hi + Math.imul(ah3, bh2) | 0;
1145
+ lo = lo + Math.imul(al2, bl3) | 0;
1146
+ mid = mid + Math.imul(al2, bh3) | 0;
1147
+ mid = mid + Math.imul(ah2, bl3) | 0;
1148
+ hi = hi + Math.imul(ah2, bh3) | 0;
1149
+ lo = lo + Math.imul(al1, bl4) | 0;
1150
+ mid = mid + Math.imul(al1, bh4) | 0;
1151
+ mid = mid + Math.imul(ah1, bl4) | 0;
1152
+ hi = hi + Math.imul(ah1, bh4) | 0;
1153
+ lo = lo + Math.imul(al0, bl5) | 0;
1154
+ mid = mid + Math.imul(al0, bh5) | 0;
1155
+ mid = mid + Math.imul(ah0, bl5) | 0;
1156
+ hi = hi + Math.imul(ah0, bh5) | 0;
1157
+ var w5 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1158
+ c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0;
1159
+ w5 &= 67108863;
1160
+ lo = Math.imul(al6, bl0);
1161
+ mid = Math.imul(al6, bh0);
1162
+ mid = mid + Math.imul(ah6, bl0) | 0;
1163
+ hi = Math.imul(ah6, bh0);
1164
+ lo = lo + Math.imul(al5, bl1) | 0;
1165
+ mid = mid + Math.imul(al5, bh1) | 0;
1166
+ mid = mid + Math.imul(ah5, bl1) | 0;
1167
+ hi = hi + Math.imul(ah5, bh1) | 0;
1168
+ lo = lo + Math.imul(al4, bl2) | 0;
1169
+ mid = mid + Math.imul(al4, bh2) | 0;
1170
+ mid = mid + Math.imul(ah4, bl2) | 0;
1171
+ hi = hi + Math.imul(ah4, bh2) | 0;
1172
+ lo = lo + Math.imul(al3, bl3) | 0;
1173
+ mid = mid + Math.imul(al3, bh3) | 0;
1174
+ mid = mid + Math.imul(ah3, bl3) | 0;
1175
+ hi = hi + Math.imul(ah3, bh3) | 0;
1176
+ lo = lo + Math.imul(al2, bl4) | 0;
1177
+ mid = mid + Math.imul(al2, bh4) | 0;
1178
+ mid = mid + Math.imul(ah2, bl4) | 0;
1179
+ hi = hi + Math.imul(ah2, bh4) | 0;
1180
+ lo = lo + Math.imul(al1, bl5) | 0;
1181
+ mid = mid + Math.imul(al1, bh5) | 0;
1182
+ mid = mid + Math.imul(ah1, bl5) | 0;
1183
+ hi = hi + Math.imul(ah1, bh5) | 0;
1184
+ lo = lo + Math.imul(al0, bl6) | 0;
1185
+ mid = mid + Math.imul(al0, bh6) | 0;
1186
+ mid = mid + Math.imul(ah0, bl6) | 0;
1187
+ hi = hi + Math.imul(ah0, bh6) | 0;
1188
+ var w6 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1189
+ c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0;
1190
+ w6 &= 67108863;
1191
+ lo = Math.imul(al7, bl0);
1192
+ mid = Math.imul(al7, bh0);
1193
+ mid = mid + Math.imul(ah7, bl0) | 0;
1194
+ hi = Math.imul(ah7, bh0);
1195
+ lo = lo + Math.imul(al6, bl1) | 0;
1196
+ mid = mid + Math.imul(al6, bh1) | 0;
1197
+ mid = mid + Math.imul(ah6, bl1) | 0;
1198
+ hi = hi + Math.imul(ah6, bh1) | 0;
1199
+ lo = lo + Math.imul(al5, bl2) | 0;
1200
+ mid = mid + Math.imul(al5, bh2) | 0;
1201
+ mid = mid + Math.imul(ah5, bl2) | 0;
1202
+ hi = hi + Math.imul(ah5, bh2) | 0;
1203
+ lo = lo + Math.imul(al4, bl3) | 0;
1204
+ mid = mid + Math.imul(al4, bh3) | 0;
1205
+ mid = mid + Math.imul(ah4, bl3) | 0;
1206
+ hi = hi + Math.imul(ah4, bh3) | 0;
1207
+ lo = lo + Math.imul(al3, bl4) | 0;
1208
+ mid = mid + Math.imul(al3, bh4) | 0;
1209
+ mid = mid + Math.imul(ah3, bl4) | 0;
1210
+ hi = hi + Math.imul(ah3, bh4) | 0;
1211
+ lo = lo + Math.imul(al2, bl5) | 0;
1212
+ mid = mid + Math.imul(al2, bh5) | 0;
1213
+ mid = mid + Math.imul(ah2, bl5) | 0;
1214
+ hi = hi + Math.imul(ah2, bh5) | 0;
1215
+ lo = lo + Math.imul(al1, bl6) | 0;
1216
+ mid = mid + Math.imul(al1, bh6) | 0;
1217
+ mid = mid + Math.imul(ah1, bl6) | 0;
1218
+ hi = hi + Math.imul(ah1, bh6) | 0;
1219
+ lo = lo + Math.imul(al0, bl7) | 0;
1220
+ mid = mid + Math.imul(al0, bh7) | 0;
1221
+ mid = mid + Math.imul(ah0, bl7) | 0;
1222
+ hi = hi + Math.imul(ah0, bh7) | 0;
1223
+ var w7 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1224
+ c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0;
1225
+ w7 &= 67108863;
1226
+ lo = Math.imul(al8, bl0);
1227
+ mid = Math.imul(al8, bh0);
1228
+ mid = mid + Math.imul(ah8, bl0) | 0;
1229
+ hi = Math.imul(ah8, bh0);
1230
+ lo = lo + Math.imul(al7, bl1) | 0;
1231
+ mid = mid + Math.imul(al7, bh1) | 0;
1232
+ mid = mid + Math.imul(ah7, bl1) | 0;
1233
+ hi = hi + Math.imul(ah7, bh1) | 0;
1234
+ lo = lo + Math.imul(al6, bl2) | 0;
1235
+ mid = mid + Math.imul(al6, bh2) | 0;
1236
+ mid = mid + Math.imul(ah6, bl2) | 0;
1237
+ hi = hi + Math.imul(ah6, bh2) | 0;
1238
+ lo = lo + Math.imul(al5, bl3) | 0;
1239
+ mid = mid + Math.imul(al5, bh3) | 0;
1240
+ mid = mid + Math.imul(ah5, bl3) | 0;
1241
+ hi = hi + Math.imul(ah5, bh3) | 0;
1242
+ lo = lo + Math.imul(al4, bl4) | 0;
1243
+ mid = mid + Math.imul(al4, bh4) | 0;
1244
+ mid = mid + Math.imul(ah4, bl4) | 0;
1245
+ hi = hi + Math.imul(ah4, bh4) | 0;
1246
+ lo = lo + Math.imul(al3, bl5) | 0;
1247
+ mid = mid + Math.imul(al3, bh5) | 0;
1248
+ mid = mid + Math.imul(ah3, bl5) | 0;
1249
+ hi = hi + Math.imul(ah3, bh5) | 0;
1250
+ lo = lo + Math.imul(al2, bl6) | 0;
1251
+ mid = mid + Math.imul(al2, bh6) | 0;
1252
+ mid = mid + Math.imul(ah2, bl6) | 0;
1253
+ hi = hi + Math.imul(ah2, bh6) | 0;
1254
+ lo = lo + Math.imul(al1, bl7) | 0;
1255
+ mid = mid + Math.imul(al1, bh7) | 0;
1256
+ mid = mid + Math.imul(ah1, bl7) | 0;
1257
+ hi = hi + Math.imul(ah1, bh7) | 0;
1258
+ lo = lo + Math.imul(al0, bl8) | 0;
1259
+ mid = mid + Math.imul(al0, bh8) | 0;
1260
+ mid = mid + Math.imul(ah0, bl8) | 0;
1261
+ hi = hi + Math.imul(ah0, bh8) | 0;
1262
+ var w8 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1263
+ c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0;
1264
+ w8 &= 67108863;
1265
+ lo = Math.imul(al9, bl0);
1266
+ mid = Math.imul(al9, bh0);
1267
+ mid = mid + Math.imul(ah9, bl0) | 0;
1268
+ hi = Math.imul(ah9, bh0);
1269
+ lo = lo + Math.imul(al8, bl1) | 0;
1270
+ mid = mid + Math.imul(al8, bh1) | 0;
1271
+ mid = mid + Math.imul(ah8, bl1) | 0;
1272
+ hi = hi + Math.imul(ah8, bh1) | 0;
1273
+ lo = lo + Math.imul(al7, bl2) | 0;
1274
+ mid = mid + Math.imul(al7, bh2) | 0;
1275
+ mid = mid + Math.imul(ah7, bl2) | 0;
1276
+ hi = hi + Math.imul(ah7, bh2) | 0;
1277
+ lo = lo + Math.imul(al6, bl3) | 0;
1278
+ mid = mid + Math.imul(al6, bh3) | 0;
1279
+ mid = mid + Math.imul(ah6, bl3) | 0;
1280
+ hi = hi + Math.imul(ah6, bh3) | 0;
1281
+ lo = lo + Math.imul(al5, bl4) | 0;
1282
+ mid = mid + Math.imul(al5, bh4) | 0;
1283
+ mid = mid + Math.imul(ah5, bl4) | 0;
1284
+ hi = hi + Math.imul(ah5, bh4) | 0;
1285
+ lo = lo + Math.imul(al4, bl5) | 0;
1286
+ mid = mid + Math.imul(al4, bh5) | 0;
1287
+ mid = mid + Math.imul(ah4, bl5) | 0;
1288
+ hi = hi + Math.imul(ah4, bh5) | 0;
1289
+ lo = lo + Math.imul(al3, bl6) | 0;
1290
+ mid = mid + Math.imul(al3, bh6) | 0;
1291
+ mid = mid + Math.imul(ah3, bl6) | 0;
1292
+ hi = hi + Math.imul(ah3, bh6) | 0;
1293
+ lo = lo + Math.imul(al2, bl7) | 0;
1294
+ mid = mid + Math.imul(al2, bh7) | 0;
1295
+ mid = mid + Math.imul(ah2, bl7) | 0;
1296
+ hi = hi + Math.imul(ah2, bh7) | 0;
1297
+ lo = lo + Math.imul(al1, bl8) | 0;
1298
+ mid = mid + Math.imul(al1, bh8) | 0;
1299
+ mid = mid + Math.imul(ah1, bl8) | 0;
1300
+ hi = hi + Math.imul(ah1, bh8) | 0;
1301
+ lo = lo + Math.imul(al0, bl9) | 0;
1302
+ mid = mid + Math.imul(al0, bh9) | 0;
1303
+ mid = mid + Math.imul(ah0, bl9) | 0;
1304
+ hi = hi + Math.imul(ah0, bh9) | 0;
1305
+ var w9 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1306
+ c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0;
1307
+ w9 &= 67108863;
1308
+ lo = Math.imul(al9, bl1);
1309
+ mid = Math.imul(al9, bh1);
1310
+ mid = mid + Math.imul(ah9, bl1) | 0;
1311
+ hi = Math.imul(ah9, bh1);
1312
+ lo = lo + Math.imul(al8, bl2) | 0;
1313
+ mid = mid + Math.imul(al8, bh2) | 0;
1314
+ mid = mid + Math.imul(ah8, bl2) | 0;
1315
+ hi = hi + Math.imul(ah8, bh2) | 0;
1316
+ lo = lo + Math.imul(al7, bl3) | 0;
1317
+ mid = mid + Math.imul(al7, bh3) | 0;
1318
+ mid = mid + Math.imul(ah7, bl3) | 0;
1319
+ hi = hi + Math.imul(ah7, bh3) | 0;
1320
+ lo = lo + Math.imul(al6, bl4) | 0;
1321
+ mid = mid + Math.imul(al6, bh4) | 0;
1322
+ mid = mid + Math.imul(ah6, bl4) | 0;
1323
+ hi = hi + Math.imul(ah6, bh4) | 0;
1324
+ lo = lo + Math.imul(al5, bl5) | 0;
1325
+ mid = mid + Math.imul(al5, bh5) | 0;
1326
+ mid = mid + Math.imul(ah5, bl5) | 0;
1327
+ hi = hi + Math.imul(ah5, bh5) | 0;
1328
+ lo = lo + Math.imul(al4, bl6) | 0;
1329
+ mid = mid + Math.imul(al4, bh6) | 0;
1330
+ mid = mid + Math.imul(ah4, bl6) | 0;
1331
+ hi = hi + Math.imul(ah4, bh6) | 0;
1332
+ lo = lo + Math.imul(al3, bl7) | 0;
1333
+ mid = mid + Math.imul(al3, bh7) | 0;
1334
+ mid = mid + Math.imul(ah3, bl7) | 0;
1335
+ hi = hi + Math.imul(ah3, bh7) | 0;
1336
+ lo = lo + Math.imul(al2, bl8) | 0;
1337
+ mid = mid + Math.imul(al2, bh8) | 0;
1338
+ mid = mid + Math.imul(ah2, bl8) | 0;
1339
+ hi = hi + Math.imul(ah2, bh8) | 0;
1340
+ lo = lo + Math.imul(al1, bl9) | 0;
1341
+ mid = mid + Math.imul(al1, bh9) | 0;
1342
+ mid = mid + Math.imul(ah1, bl9) | 0;
1343
+ hi = hi + Math.imul(ah1, bh9) | 0;
1344
+ var w10 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1345
+ c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0;
1346
+ w10 &= 67108863;
1347
+ lo = Math.imul(al9, bl2);
1348
+ mid = Math.imul(al9, bh2);
1349
+ mid = mid + Math.imul(ah9, bl2) | 0;
1350
+ hi = Math.imul(ah9, bh2);
1351
+ lo = lo + Math.imul(al8, bl3) | 0;
1352
+ mid = mid + Math.imul(al8, bh3) | 0;
1353
+ mid = mid + Math.imul(ah8, bl3) | 0;
1354
+ hi = hi + Math.imul(ah8, bh3) | 0;
1355
+ lo = lo + Math.imul(al7, bl4) | 0;
1356
+ mid = mid + Math.imul(al7, bh4) | 0;
1357
+ mid = mid + Math.imul(ah7, bl4) | 0;
1358
+ hi = hi + Math.imul(ah7, bh4) | 0;
1359
+ lo = lo + Math.imul(al6, bl5) | 0;
1360
+ mid = mid + Math.imul(al6, bh5) | 0;
1361
+ mid = mid + Math.imul(ah6, bl5) | 0;
1362
+ hi = hi + Math.imul(ah6, bh5) | 0;
1363
+ lo = lo + Math.imul(al5, bl6) | 0;
1364
+ mid = mid + Math.imul(al5, bh6) | 0;
1365
+ mid = mid + Math.imul(ah5, bl6) | 0;
1366
+ hi = hi + Math.imul(ah5, bh6) | 0;
1367
+ lo = lo + Math.imul(al4, bl7) | 0;
1368
+ mid = mid + Math.imul(al4, bh7) | 0;
1369
+ mid = mid + Math.imul(ah4, bl7) | 0;
1370
+ hi = hi + Math.imul(ah4, bh7) | 0;
1371
+ lo = lo + Math.imul(al3, bl8) | 0;
1372
+ mid = mid + Math.imul(al3, bh8) | 0;
1373
+ mid = mid + Math.imul(ah3, bl8) | 0;
1374
+ hi = hi + Math.imul(ah3, bh8) | 0;
1375
+ lo = lo + Math.imul(al2, bl9) | 0;
1376
+ mid = mid + Math.imul(al2, bh9) | 0;
1377
+ mid = mid + Math.imul(ah2, bl9) | 0;
1378
+ hi = hi + Math.imul(ah2, bh9) | 0;
1379
+ var w11 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1380
+ c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0;
1381
+ w11 &= 67108863;
1382
+ lo = Math.imul(al9, bl3);
1383
+ mid = Math.imul(al9, bh3);
1384
+ mid = mid + Math.imul(ah9, bl3) | 0;
1385
+ hi = Math.imul(ah9, bh3);
1386
+ lo = lo + Math.imul(al8, bl4) | 0;
1387
+ mid = mid + Math.imul(al8, bh4) | 0;
1388
+ mid = mid + Math.imul(ah8, bl4) | 0;
1389
+ hi = hi + Math.imul(ah8, bh4) | 0;
1390
+ lo = lo + Math.imul(al7, bl5) | 0;
1391
+ mid = mid + Math.imul(al7, bh5) | 0;
1392
+ mid = mid + Math.imul(ah7, bl5) | 0;
1393
+ hi = hi + Math.imul(ah7, bh5) | 0;
1394
+ lo = lo + Math.imul(al6, bl6) | 0;
1395
+ mid = mid + Math.imul(al6, bh6) | 0;
1396
+ mid = mid + Math.imul(ah6, bl6) | 0;
1397
+ hi = hi + Math.imul(ah6, bh6) | 0;
1398
+ lo = lo + Math.imul(al5, bl7) | 0;
1399
+ mid = mid + Math.imul(al5, bh7) | 0;
1400
+ mid = mid + Math.imul(ah5, bl7) | 0;
1401
+ hi = hi + Math.imul(ah5, bh7) | 0;
1402
+ lo = lo + Math.imul(al4, bl8) | 0;
1403
+ mid = mid + Math.imul(al4, bh8) | 0;
1404
+ mid = mid + Math.imul(ah4, bl8) | 0;
1405
+ hi = hi + Math.imul(ah4, bh8) | 0;
1406
+ lo = lo + Math.imul(al3, bl9) | 0;
1407
+ mid = mid + Math.imul(al3, bh9) | 0;
1408
+ mid = mid + Math.imul(ah3, bl9) | 0;
1409
+ hi = hi + Math.imul(ah3, bh9) | 0;
1410
+ var w12 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1411
+ c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0;
1412
+ w12 &= 67108863;
1413
+ lo = Math.imul(al9, bl4);
1414
+ mid = Math.imul(al9, bh4);
1415
+ mid = mid + Math.imul(ah9, bl4) | 0;
1416
+ hi = Math.imul(ah9, bh4);
1417
+ lo = lo + Math.imul(al8, bl5) | 0;
1418
+ mid = mid + Math.imul(al8, bh5) | 0;
1419
+ mid = mid + Math.imul(ah8, bl5) | 0;
1420
+ hi = hi + Math.imul(ah8, bh5) | 0;
1421
+ lo = lo + Math.imul(al7, bl6) | 0;
1422
+ mid = mid + Math.imul(al7, bh6) | 0;
1423
+ mid = mid + Math.imul(ah7, bl6) | 0;
1424
+ hi = hi + Math.imul(ah7, bh6) | 0;
1425
+ lo = lo + Math.imul(al6, bl7) | 0;
1426
+ mid = mid + Math.imul(al6, bh7) | 0;
1427
+ mid = mid + Math.imul(ah6, bl7) | 0;
1428
+ hi = hi + Math.imul(ah6, bh7) | 0;
1429
+ lo = lo + Math.imul(al5, bl8) | 0;
1430
+ mid = mid + Math.imul(al5, bh8) | 0;
1431
+ mid = mid + Math.imul(ah5, bl8) | 0;
1432
+ hi = hi + Math.imul(ah5, bh8) | 0;
1433
+ lo = lo + Math.imul(al4, bl9) | 0;
1434
+ mid = mid + Math.imul(al4, bh9) | 0;
1435
+ mid = mid + Math.imul(ah4, bl9) | 0;
1436
+ hi = hi + Math.imul(ah4, bh9) | 0;
1437
+ var w13 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1438
+ c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0;
1439
+ w13 &= 67108863;
1440
+ lo = Math.imul(al9, bl5);
1441
+ mid = Math.imul(al9, bh5);
1442
+ mid = mid + Math.imul(ah9, bl5) | 0;
1443
+ hi = Math.imul(ah9, bh5);
1444
+ lo = lo + Math.imul(al8, bl6) | 0;
1445
+ mid = mid + Math.imul(al8, bh6) | 0;
1446
+ mid = mid + Math.imul(ah8, bl6) | 0;
1447
+ hi = hi + Math.imul(ah8, bh6) | 0;
1448
+ lo = lo + Math.imul(al7, bl7) | 0;
1449
+ mid = mid + Math.imul(al7, bh7) | 0;
1450
+ mid = mid + Math.imul(ah7, bl7) | 0;
1451
+ hi = hi + Math.imul(ah7, bh7) | 0;
1452
+ lo = lo + Math.imul(al6, bl8) | 0;
1453
+ mid = mid + Math.imul(al6, bh8) | 0;
1454
+ mid = mid + Math.imul(ah6, bl8) | 0;
1455
+ hi = hi + Math.imul(ah6, bh8) | 0;
1456
+ lo = lo + Math.imul(al5, bl9) | 0;
1457
+ mid = mid + Math.imul(al5, bh9) | 0;
1458
+ mid = mid + Math.imul(ah5, bl9) | 0;
1459
+ hi = hi + Math.imul(ah5, bh9) | 0;
1460
+ var w14 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1461
+ c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0;
1462
+ w14 &= 67108863;
1463
+ lo = Math.imul(al9, bl6);
1464
+ mid = Math.imul(al9, bh6);
1465
+ mid = mid + Math.imul(ah9, bl6) | 0;
1466
+ hi = Math.imul(ah9, bh6);
1467
+ lo = lo + Math.imul(al8, bl7) | 0;
1468
+ mid = mid + Math.imul(al8, bh7) | 0;
1469
+ mid = mid + Math.imul(ah8, bl7) | 0;
1470
+ hi = hi + Math.imul(ah8, bh7) | 0;
1471
+ lo = lo + Math.imul(al7, bl8) | 0;
1472
+ mid = mid + Math.imul(al7, bh8) | 0;
1473
+ mid = mid + Math.imul(ah7, bl8) | 0;
1474
+ hi = hi + Math.imul(ah7, bh8) | 0;
1475
+ lo = lo + Math.imul(al6, bl9) | 0;
1476
+ mid = mid + Math.imul(al6, bh9) | 0;
1477
+ mid = mid + Math.imul(ah6, bl9) | 0;
1478
+ hi = hi + Math.imul(ah6, bh9) | 0;
1479
+ var w15 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1480
+ c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0;
1481
+ w15 &= 67108863;
1482
+ lo = Math.imul(al9, bl7);
1483
+ mid = Math.imul(al9, bh7);
1484
+ mid = mid + Math.imul(ah9, bl7) | 0;
1485
+ hi = Math.imul(ah9, bh7);
1486
+ lo = lo + Math.imul(al8, bl8) | 0;
1487
+ mid = mid + Math.imul(al8, bh8) | 0;
1488
+ mid = mid + Math.imul(ah8, bl8) | 0;
1489
+ hi = hi + Math.imul(ah8, bh8) | 0;
1490
+ lo = lo + Math.imul(al7, bl9) | 0;
1491
+ mid = mid + Math.imul(al7, bh9) | 0;
1492
+ mid = mid + Math.imul(ah7, bl9) | 0;
1493
+ hi = hi + Math.imul(ah7, bh9) | 0;
1494
+ var w16 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1495
+ c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0;
1496
+ w16 &= 67108863;
1497
+ lo = Math.imul(al9, bl8);
1498
+ mid = Math.imul(al9, bh8);
1499
+ mid = mid + Math.imul(ah9, bl8) | 0;
1500
+ hi = Math.imul(ah9, bh8);
1501
+ lo = lo + Math.imul(al8, bl9) | 0;
1502
+ mid = mid + Math.imul(al8, bh9) | 0;
1503
+ mid = mid + Math.imul(ah8, bl9) | 0;
1504
+ hi = hi + Math.imul(ah8, bh9) | 0;
1505
+ var w17 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1506
+ c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0;
1507
+ w17 &= 67108863;
1508
+ lo = Math.imul(al9, bl9);
1509
+ mid = Math.imul(al9, bh9);
1510
+ mid = mid + Math.imul(ah9, bl9) | 0;
1511
+ hi = Math.imul(ah9, bh9);
1512
+ var w18 = (c + lo | 0) + ((mid & 8191) << 13) | 0;
1513
+ c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0;
1514
+ w18 &= 67108863;
1515
+ o[0] = w0;
1516
+ o[1] = w1;
1517
+ o[2] = w2;
1518
+ o[3] = w3;
1519
+ o[4] = w4;
1520
+ o[5] = w5;
1521
+ o[6] = w6;
1522
+ o[7] = w7;
1523
+ o[8] = w8;
1524
+ o[9] = w9;
1525
+ o[10] = w10;
1526
+ o[11] = w11;
1527
+ o[12] = w12;
1528
+ o[13] = w13;
1529
+ o[14] = w14;
1530
+ o[15] = w15;
1531
+ o[16] = w16;
1532
+ o[17] = w17;
1533
+ o[18] = w18;
1534
+ if (c !== 0) {
1535
+ o[19] = c;
1536
+ out.length++;
1537
+ }
1538
+ return out;
1539
+ };
1540
+ if (!Math.imul) {
1541
+ comb10MulTo = smallMulTo;
1542
+ }
1543
+ function bigMulTo(self, num, out) {
1544
+ out.negative = num.negative ^ self.negative;
1545
+ out.length = self.length + num.length;
1546
+ var carry = 0;
1547
+ var hncarry = 0;
1548
+ for (var k = 0; k < out.length - 1; k++) {
1549
+ var ncarry = hncarry;
1550
+ hncarry = 0;
1551
+ var rword = carry & 67108863;
1552
+ var maxJ = Math.min(k, num.length - 1);
1553
+ for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
1554
+ var i = k - j;
1555
+ var a = self.words[i] | 0;
1556
+ var b = num.words[j] | 0;
1557
+ var r = a * b;
1558
+ var lo = r & 67108863;
1559
+ ncarry = ncarry + (r / 67108864 | 0) | 0;
1560
+ lo = lo + rword | 0;
1561
+ rword = lo & 67108863;
1562
+ ncarry = ncarry + (lo >>> 26) | 0;
1563
+ hncarry += ncarry >>> 26;
1564
+ ncarry &= 67108863;
1565
+ }
1566
+ out.words[k] = rword;
1567
+ carry = ncarry;
1568
+ ncarry = hncarry;
1569
+ }
1570
+ if (carry !== 0) {
1571
+ out.words[k] = carry;
1572
+ } else {
1573
+ out.length--;
1574
+ }
1575
+ return out._strip();
1576
+ }
1577
+ function jumboMulTo(self, num, out) {
1578
+ return bigMulTo(self, num, out);
1579
+ }
1580
+ BN2.prototype.mulTo = function mulTo(num, out) {
1581
+ var res;
1582
+ var len = this.length + num.length;
1583
+ if (this.length === 10 && num.length === 10) {
1584
+ res = comb10MulTo(this, num, out);
1585
+ } else if (len < 63) {
1586
+ res = smallMulTo(this, num, out);
1587
+ } else if (len < 1024) {
1588
+ res = bigMulTo(this, num, out);
1589
+ } else {
1590
+ res = jumboMulTo(this, num, out);
1591
+ }
1592
+ return res;
1593
+ };
1594
+ function FFTM(x, y) {
1595
+ this.x = x;
1596
+ this.y = y;
1597
+ }
1598
+ FFTM.prototype.makeRBT = function makeRBT(N) {
1599
+ var t = new Array(N);
1600
+ var l = BN2.prototype._countBits(N) - 1;
1601
+ for (var i = 0; i < N; i++) {
1602
+ t[i] = this.revBin(i, l, N);
1603
+ }
1604
+ return t;
1605
+ };
1606
+ FFTM.prototype.revBin = function revBin(x, l, N) {
1607
+ if (x === 0 || x === N - 1) return x;
1608
+ var rb = 0;
1609
+ for (var i = 0; i < l; i++) {
1610
+ rb |= (x & 1) << l - i - 1;
1611
+ x >>= 1;
1612
+ }
1613
+ return rb;
1614
+ };
1615
+ FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) {
1616
+ for (var i = 0; i < N; i++) {
1617
+ rtws[i] = rws[rbt[i]];
1618
+ itws[i] = iws[rbt[i]];
1619
+ }
1620
+ };
1621
+ FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) {
1622
+ this.permute(rbt, rws, iws, rtws, itws, N);
1623
+ for (var s = 1; s < N; s <<= 1) {
1624
+ var l = s << 1;
1625
+ var rtwdf = Math.cos(2 * Math.PI / l);
1626
+ var itwdf = Math.sin(2 * Math.PI / l);
1627
+ for (var p = 0; p < N; p += l) {
1628
+ var rtwdf_ = rtwdf;
1629
+ var itwdf_ = itwdf;
1630
+ for (var j = 0; j < s; j++) {
1631
+ var re = rtws[p + j];
1632
+ var ie = itws[p + j];
1633
+ var ro = rtws[p + j + s];
1634
+ var io = itws[p + j + s];
1635
+ var rx = rtwdf_ * ro - itwdf_ * io;
1636
+ io = rtwdf_ * io + itwdf_ * ro;
1637
+ ro = rx;
1638
+ rtws[p + j] = re + ro;
1639
+ itws[p + j] = ie + io;
1640
+ rtws[p + j + s] = re - ro;
1641
+ itws[p + j + s] = ie - io;
1642
+ if (j !== l) {
1643
+ rx = rtwdf * rtwdf_ - itwdf * itwdf_;
1644
+ itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
1645
+ rtwdf_ = rx;
1646
+ }
1647
+ }
1648
+ }
1649
+ }
1650
+ };
1651
+ FFTM.prototype.guessLen13b = function guessLen13b(n, m) {
1652
+ var N = Math.max(m, n) | 1;
1653
+ var odd = N & 1;
1654
+ var i = 0;
1655
+ for (N = N / 2 | 0; N; N = N >>> 1) {
1656
+ i++;
1657
+ }
1658
+ return 1 << i + 1 + odd;
1659
+ };
1660
+ FFTM.prototype.conjugate = function conjugate(rws, iws, N) {
1661
+ if (N <= 1) return;
1662
+ for (var i = 0; i < N / 2; i++) {
1663
+ var t = rws[i];
1664
+ rws[i] = rws[N - i - 1];
1665
+ rws[N - i - 1] = t;
1666
+ t = iws[i];
1667
+ iws[i] = -iws[N - i - 1];
1668
+ iws[N - i - 1] = -t;
1669
+ }
1670
+ };
1671
+ FFTM.prototype.normalize13b = function normalize13b(ws, N) {
1672
+ var carry = 0;
1673
+ for (var i = 0; i < N / 2; i++) {
1674
+ var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry;
1675
+ ws[i] = w & 67108863;
1676
+ if (w < 67108864) {
1677
+ carry = 0;
1678
+ } else {
1679
+ carry = w / 67108864 | 0;
1680
+ }
1681
+ }
1682
+ return ws;
1683
+ };
1684
+ FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) {
1685
+ var carry = 0;
1686
+ for (var i = 0; i < len; i++) {
1687
+ carry = carry + (ws[i] | 0);
1688
+ rws[2 * i] = carry & 8191;
1689
+ carry = carry >>> 13;
1690
+ rws[2 * i + 1] = carry & 8191;
1691
+ carry = carry >>> 13;
1692
+ }
1693
+ for (i = 2 * len; i < N; ++i) {
1694
+ rws[i] = 0;
1695
+ }
1696
+ assert(carry === 0);
1697
+ assert((carry & ~8191) === 0);
1698
+ };
1699
+ FFTM.prototype.stub = function stub(N) {
1700
+ var ph = new Array(N);
1701
+ for (var i = 0; i < N; i++) {
1702
+ ph[i] = 0;
1703
+ }
1704
+ return ph;
1705
+ };
1706
+ FFTM.prototype.mulp = function mulp(x, y, out) {
1707
+ var N = 2 * this.guessLen13b(x.length, y.length);
1708
+ var rbt = this.makeRBT(N);
1709
+ var _ = this.stub(N);
1710
+ var rws = new Array(N);
1711
+ var rwst = new Array(N);
1712
+ var iwst = new Array(N);
1713
+ var nrws = new Array(N);
1714
+ var nrwst = new Array(N);
1715
+ var niwst = new Array(N);
1716
+ var rmws = out.words;
1717
+ rmws.length = N;
1718
+ this.convert13b(x.words, x.length, rws, N);
1719
+ this.convert13b(y.words, y.length, nrws, N);
1720
+ this.transform(rws, _, rwst, iwst, N, rbt);
1721
+ this.transform(nrws, _, nrwst, niwst, N, rbt);
1722
+ for (var i = 0; i < N; i++) {
1723
+ var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
1724
+ iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
1725
+ rwst[i] = rx;
1726
+ }
1727
+ this.conjugate(rwst, iwst, N);
1728
+ this.transform(rwst, iwst, rmws, _, N, rbt);
1729
+ this.conjugate(rmws, _, N);
1730
+ this.normalize13b(rmws, N);
1731
+ out.negative = x.negative ^ y.negative;
1732
+ out.length = x.length + y.length;
1733
+ return out._strip();
1734
+ };
1735
+ BN2.prototype.mul = function mul(num) {
1736
+ var out = new BN2(null);
1737
+ out.words = new Array(this.length + num.length);
1738
+ return this.mulTo(num, out);
1739
+ };
1740
+ BN2.prototype.mulf = function mulf(num) {
1741
+ var out = new BN2(null);
1742
+ out.words = new Array(this.length + num.length);
1743
+ return jumboMulTo(this, num, out);
1744
+ };
1745
+ BN2.prototype.imul = function imul(num) {
1746
+ return this.clone().mulTo(num, this);
1747
+ };
1748
+ BN2.prototype.imuln = function imuln(num) {
1749
+ var isNegNum = num < 0;
1750
+ if (isNegNum) num = -num;
1751
+ assert(typeof num === "number");
1752
+ assert(num < 67108864);
1753
+ var carry = 0;
1754
+ for (var i = 0; i < this.length; i++) {
1755
+ var w = (this.words[i] | 0) * num;
1756
+ var lo = (w & 67108863) + (carry & 67108863);
1757
+ carry >>= 26;
1758
+ carry += w / 67108864 | 0;
1759
+ carry += lo >>> 26;
1760
+ this.words[i] = lo & 67108863;
1761
+ }
1762
+ if (carry !== 0) {
1763
+ this.words[i] = carry;
1764
+ this.length++;
1765
+ }
1766
+ this.length = num === 0 ? 1 : this.length;
1767
+ return isNegNum ? this.ineg() : this;
1768
+ };
1769
+ BN2.prototype.muln = function muln(num) {
1770
+ return this.clone().imuln(num);
1771
+ };
1772
+ BN2.prototype.sqr = function sqr() {
1773
+ return this.mul(this);
1774
+ };
1775
+ BN2.prototype.isqr = function isqr() {
1776
+ return this.imul(this.clone());
1777
+ };
1778
+ BN2.prototype.pow = function pow(num) {
1779
+ var w = toBitArray(num);
1780
+ if (w.length === 0) return new BN2(1);
1781
+ var res = this;
1782
+ for (var i = 0; i < w.length; i++, res = res.sqr()) {
1783
+ if (w[i] !== 0) break;
1784
+ }
1785
+ if (++i < w.length) {
1786
+ for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
1787
+ if (w[i] === 0) continue;
1788
+ res = res.mul(q);
1789
+ }
1790
+ }
1791
+ return res;
1792
+ };
1793
+ BN2.prototype.iushln = function iushln(bits) {
1794
+ assert(typeof bits === "number" && bits >= 0);
1795
+ var r = bits % 26;
1796
+ var s = (bits - r) / 26;
1797
+ var carryMask = 67108863 >>> 26 - r << 26 - r;
1798
+ var i;
1799
+ if (r !== 0) {
1800
+ var carry = 0;
1801
+ for (i = 0; i < this.length; i++) {
1802
+ var newCarry = this.words[i] & carryMask;
1803
+ var c = (this.words[i] | 0) - newCarry << r;
1804
+ this.words[i] = c | carry;
1805
+ carry = newCarry >>> 26 - r;
1806
+ }
1807
+ if (carry) {
1808
+ this.words[i] = carry;
1809
+ this.length++;
1810
+ }
1811
+ }
1812
+ if (s !== 0) {
1813
+ for (i = this.length - 1; i >= 0; i--) {
1814
+ this.words[i + s] = this.words[i];
1815
+ }
1816
+ for (i = 0; i < s; i++) {
1817
+ this.words[i] = 0;
1818
+ }
1819
+ this.length += s;
1820
+ }
1821
+ return this._strip();
1822
+ };
1823
+ BN2.prototype.ishln = function ishln(bits) {
1824
+ assert(this.negative === 0);
1825
+ return this.iushln(bits);
1826
+ };
1827
+ BN2.prototype.iushrn = function iushrn(bits, hint, extended) {
1828
+ assert(typeof bits === "number" && bits >= 0);
1829
+ var h;
1830
+ if (hint) {
1831
+ h = (hint - hint % 26) / 26;
1832
+ } else {
1833
+ h = 0;
1834
+ }
1835
+ var r = bits % 26;
1836
+ var s = Math.min((bits - r) / 26, this.length);
1837
+ var mask = 67108863 ^ 67108863 >>> r << r;
1838
+ var maskedWords = extended;
1839
+ h -= s;
1840
+ h = Math.max(0, h);
1841
+ if (maskedWords) {
1842
+ for (var i = 0; i < s; i++) {
1843
+ maskedWords.words[i] = this.words[i];
1844
+ }
1845
+ maskedWords.length = s;
1846
+ }
1847
+ if (s === 0) {
1848
+ } else if (this.length > s) {
1849
+ this.length -= s;
1850
+ for (i = 0; i < this.length; i++) {
1851
+ this.words[i] = this.words[i + s];
1852
+ }
1853
+ } else {
1854
+ this.words[0] = 0;
1855
+ this.length = 1;
1856
+ }
1857
+ var carry = 0;
1858
+ for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
1859
+ var word = this.words[i] | 0;
1860
+ this.words[i] = carry << 26 - r | word >>> r;
1861
+ carry = word & mask;
1862
+ }
1863
+ if (maskedWords && carry !== 0) {
1864
+ maskedWords.words[maskedWords.length++] = carry;
1865
+ }
1866
+ if (this.length === 0) {
1867
+ this.words[0] = 0;
1868
+ this.length = 1;
1869
+ }
1870
+ return this._strip();
1871
+ };
1872
+ BN2.prototype.ishrn = function ishrn(bits, hint, extended) {
1873
+ assert(this.negative === 0);
1874
+ return this.iushrn(bits, hint, extended);
1875
+ };
1876
+ BN2.prototype.shln = function shln(bits) {
1877
+ return this.clone().ishln(bits);
1878
+ };
1879
+ BN2.prototype.ushln = function ushln(bits) {
1880
+ return this.clone().iushln(bits);
1881
+ };
1882
+ BN2.prototype.shrn = function shrn(bits) {
1883
+ return this.clone().ishrn(bits);
1884
+ };
1885
+ BN2.prototype.ushrn = function ushrn(bits) {
1886
+ return this.clone().iushrn(bits);
1887
+ };
1888
+ BN2.prototype.testn = function testn(bit) {
1889
+ assert(typeof bit === "number" && bit >= 0);
1890
+ var r = bit % 26;
1891
+ var s = (bit - r) / 26;
1892
+ var q = 1 << r;
1893
+ if (this.length <= s) return false;
1894
+ var w = this.words[s];
1895
+ return !!(w & q);
1896
+ };
1897
+ BN2.prototype.imaskn = function imaskn(bits) {
1898
+ assert(typeof bits === "number" && bits >= 0);
1899
+ var r = bits % 26;
1900
+ var s = (bits - r) / 26;
1901
+ assert(this.negative === 0, "imaskn works only with positive numbers");
1902
+ if (this.length <= s) {
1903
+ return this;
1904
+ }
1905
+ if (r !== 0) {
1906
+ s++;
1907
+ }
1908
+ this.length = Math.min(s, this.length);
1909
+ if (r !== 0) {
1910
+ var mask = 67108863 ^ 67108863 >>> r << r;
1911
+ this.words[this.length - 1] &= mask;
1912
+ }
1913
+ return this._strip();
1914
+ };
1915
+ BN2.prototype.maskn = function maskn(bits) {
1916
+ return this.clone().imaskn(bits);
1917
+ };
1918
+ BN2.prototype.iaddn = function iaddn(num) {
1919
+ assert(typeof num === "number");
1920
+ assert(num < 67108864);
1921
+ if (num < 0) return this.isubn(-num);
1922
+ if (this.negative !== 0) {
1923
+ if (this.length === 1 && (this.words[0] | 0) <= num) {
1924
+ this.words[0] = num - (this.words[0] | 0);
1925
+ this.negative = 0;
1926
+ return this;
1927
+ }
1928
+ this.negative = 0;
1929
+ this.isubn(num);
1930
+ this.negative = 1;
1931
+ return this;
1932
+ }
1933
+ return this._iaddn(num);
1934
+ };
1935
+ BN2.prototype._iaddn = function _iaddn(num) {
1936
+ this.words[0] += num;
1937
+ for (var i = 0; i < this.length && this.words[i] >= 67108864; i++) {
1938
+ this.words[i] -= 67108864;
1939
+ if (i === this.length - 1) {
1940
+ this.words[i + 1] = 1;
1941
+ } else {
1942
+ this.words[i + 1]++;
1943
+ }
1944
+ }
1945
+ this.length = Math.max(this.length, i + 1);
1946
+ return this;
1947
+ };
1948
+ BN2.prototype.isubn = function isubn(num) {
1949
+ assert(typeof num === "number");
1950
+ assert(num < 67108864);
1951
+ if (num < 0) return this.iaddn(-num);
1952
+ if (this.negative !== 0) {
1953
+ this.negative = 0;
1954
+ this.iaddn(num);
1955
+ this.negative = 1;
1956
+ return this;
1957
+ }
1958
+ this.words[0] -= num;
1959
+ if (this.length === 1 && this.words[0] < 0) {
1960
+ this.words[0] = -this.words[0];
1961
+ this.negative = 1;
1962
+ } else {
1963
+ for (var i = 0; i < this.length && this.words[i] < 0; i++) {
1964
+ this.words[i] += 67108864;
1965
+ this.words[i + 1] -= 1;
1966
+ }
1967
+ }
1968
+ return this._strip();
1969
+ };
1970
+ BN2.prototype.addn = function addn(num) {
1971
+ return this.clone().iaddn(num);
1972
+ };
1973
+ BN2.prototype.subn = function subn(num) {
1974
+ return this.clone().isubn(num);
1975
+ };
1976
+ BN2.prototype.iabs = function iabs() {
1977
+ this.negative = 0;
1978
+ return this;
1979
+ };
1980
+ BN2.prototype.abs = function abs() {
1981
+ return this.clone().iabs();
1982
+ };
1983
+ BN2.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
1984
+ var len = num.length + shift;
1985
+ var i;
1986
+ this._expand(len);
1987
+ var w;
1988
+ var carry = 0;
1989
+ for (i = 0; i < num.length; i++) {
1990
+ w = (this.words[i + shift] | 0) + carry;
1991
+ var right = (num.words[i] | 0) * mul;
1992
+ w -= right & 67108863;
1993
+ carry = (w >> 26) - (right / 67108864 | 0);
1994
+ this.words[i + shift] = w & 67108863;
1995
+ }
1996
+ for (; i < this.length - shift; i++) {
1997
+ w = (this.words[i + shift] | 0) + carry;
1998
+ carry = w >> 26;
1999
+ this.words[i + shift] = w & 67108863;
2000
+ }
2001
+ if (carry === 0) return this._strip();
2002
+ assert(carry === -1);
2003
+ carry = 0;
2004
+ for (i = 0; i < this.length; i++) {
2005
+ w = -(this.words[i] | 0) + carry;
2006
+ carry = w >> 26;
2007
+ this.words[i] = w & 67108863;
2008
+ }
2009
+ this.negative = 1;
2010
+ return this._strip();
2011
+ };
2012
+ BN2.prototype._wordDiv = function _wordDiv(num, mode) {
2013
+ var shift = this.length - num.length;
2014
+ var a = this.clone();
2015
+ var b = num;
2016
+ var bhi = b.words[b.length - 1] | 0;
2017
+ var bhiBits = this._countBits(bhi);
2018
+ shift = 26 - bhiBits;
2019
+ if (shift !== 0) {
2020
+ b = b.ushln(shift);
2021
+ a.iushln(shift);
2022
+ bhi = b.words[b.length - 1] | 0;
2023
+ }
2024
+ var m = a.length - b.length;
2025
+ var q;
2026
+ if (mode !== "mod") {
2027
+ q = new BN2(null);
2028
+ q.length = m + 1;
2029
+ q.words = new Array(q.length);
2030
+ for (var i = 0; i < q.length; i++) {
2031
+ q.words[i] = 0;
2032
+ }
2033
+ }
2034
+ var diff = a.clone()._ishlnsubmul(b, 1, m);
2035
+ if (diff.negative === 0) {
2036
+ a = diff;
2037
+ if (q) {
2038
+ q.words[m] = 1;
2039
+ }
2040
+ }
2041
+ for (var j = m - 1; j >= 0; j--) {
2042
+ var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0);
2043
+ qj = Math.min(qj / bhi | 0, 67108863);
2044
+ a._ishlnsubmul(b, qj, j);
2045
+ while (a.negative !== 0) {
2046
+ qj--;
2047
+ a.negative = 0;
2048
+ a._ishlnsubmul(b, 1, j);
2049
+ if (!a.isZero()) {
2050
+ a.negative ^= 1;
2051
+ }
2052
+ }
2053
+ if (q) {
2054
+ q.words[j] = qj;
2055
+ }
2056
+ }
2057
+ if (q) {
2058
+ q._strip();
2059
+ }
2060
+ a._strip();
2061
+ if (mode !== "div" && shift !== 0) {
2062
+ a.iushrn(shift);
2063
+ }
2064
+ return {
2065
+ div: q || null,
2066
+ mod: a
2067
+ };
2068
+ };
2069
+ BN2.prototype.divmod = function divmod(num, mode, positive) {
2070
+ assert(!num.isZero());
2071
+ if (this.isZero()) {
2072
+ return {
2073
+ div: new BN2(0),
2074
+ mod: new BN2(0)
2075
+ };
2076
+ }
2077
+ var div, mod, res;
2078
+ if (this.negative !== 0 && num.negative === 0) {
2079
+ res = this.neg().divmod(num, mode);
2080
+ if (mode !== "mod") {
2081
+ div = res.div.neg();
2082
+ }
2083
+ if (mode !== "div") {
2084
+ mod = res.mod.neg();
2085
+ if (positive && mod.negative !== 0) {
2086
+ mod.iadd(num);
2087
+ }
2088
+ }
2089
+ return {
2090
+ div,
2091
+ mod
2092
+ };
2093
+ }
2094
+ if (this.negative === 0 && num.negative !== 0) {
2095
+ res = this.divmod(num.neg(), mode);
2096
+ if (mode !== "mod") {
2097
+ div = res.div.neg();
2098
+ }
2099
+ return {
2100
+ div,
2101
+ mod: res.mod
2102
+ };
2103
+ }
2104
+ if ((this.negative & num.negative) !== 0) {
2105
+ res = this.neg().divmod(num.neg(), mode);
2106
+ if (mode !== "div") {
2107
+ mod = res.mod.neg();
2108
+ if (positive && mod.negative !== 0) {
2109
+ mod.isub(num);
2110
+ }
2111
+ }
2112
+ return {
2113
+ div: res.div,
2114
+ mod
2115
+ };
2116
+ }
2117
+ if (num.length > this.length || this.cmp(num) < 0) {
2118
+ return {
2119
+ div: new BN2(0),
2120
+ mod: this
2121
+ };
2122
+ }
2123
+ if (num.length === 1) {
2124
+ if (mode === "div") {
2125
+ return {
2126
+ div: this.divn(num.words[0]),
2127
+ mod: null
2128
+ };
2129
+ }
2130
+ if (mode === "mod") {
2131
+ return {
2132
+ div: null,
2133
+ mod: new BN2(this.modrn(num.words[0]))
2134
+ };
2135
+ }
2136
+ return {
2137
+ div: this.divn(num.words[0]),
2138
+ mod: new BN2(this.modrn(num.words[0]))
2139
+ };
2140
+ }
2141
+ return this._wordDiv(num, mode);
2142
+ };
2143
+ BN2.prototype.div = function div(num) {
2144
+ return this.divmod(num, "div", false).div;
2145
+ };
2146
+ BN2.prototype.mod = function mod(num) {
2147
+ return this.divmod(num, "mod", false).mod;
2148
+ };
2149
+ BN2.prototype.umod = function umod(num) {
2150
+ return this.divmod(num, "mod", true).mod;
2151
+ };
2152
+ BN2.prototype.divRound = function divRound(num) {
2153
+ var dm = this.divmod(num);
2154
+ if (dm.mod.isZero()) return dm.div;
2155
+ var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
2156
+ var half = num.ushrn(1);
2157
+ var r2 = num.andln(1);
2158
+ var cmp = mod.cmp(half);
2159
+ if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
2160
+ return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
2161
+ };
2162
+ BN2.prototype.modrn = function modrn(num) {
2163
+ var isNegNum = num < 0;
2164
+ if (isNegNum) num = -num;
2165
+ assert(num <= 67108863);
2166
+ var p = (1 << 26) % num;
2167
+ var acc = 0;
2168
+ for (var i = this.length - 1; i >= 0; i--) {
2169
+ acc = (p * acc + (this.words[i] | 0)) % num;
2170
+ }
2171
+ return isNegNum ? -acc : acc;
2172
+ };
2173
+ BN2.prototype.modn = function modn(num) {
2174
+ return this.modrn(num);
2175
+ };
2176
+ BN2.prototype.idivn = function idivn(num) {
2177
+ var isNegNum = num < 0;
2178
+ if (isNegNum) num = -num;
2179
+ assert(num <= 67108863);
2180
+ var carry = 0;
2181
+ for (var i = this.length - 1; i >= 0; i--) {
2182
+ var w = (this.words[i] | 0) + carry * 67108864;
2183
+ this.words[i] = w / num | 0;
2184
+ carry = w % num;
2185
+ }
2186
+ this._strip();
2187
+ return isNegNum ? this.ineg() : this;
2188
+ };
2189
+ BN2.prototype.divn = function divn(num) {
2190
+ return this.clone().idivn(num);
2191
+ };
2192
+ BN2.prototype.egcd = function egcd(p) {
2193
+ assert(p.negative === 0);
2194
+ assert(!p.isZero());
2195
+ var x = this;
2196
+ var y = p.clone();
2197
+ if (x.negative !== 0) {
2198
+ x = x.umod(p);
2199
+ } else {
2200
+ x = x.clone();
2201
+ }
2202
+ var A = new BN2(1);
2203
+ var B = new BN2(0);
2204
+ var C = new BN2(0);
2205
+ var D = new BN2(1);
2206
+ var g = 0;
2207
+ while (x.isEven() && y.isEven()) {
2208
+ x.iushrn(1);
2209
+ y.iushrn(1);
2210
+ ++g;
2211
+ }
2212
+ var yp = y.clone();
2213
+ var xp = x.clone();
2214
+ while (!x.isZero()) {
2215
+ for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1) ;
2216
+ if (i > 0) {
2217
+ x.iushrn(i);
2218
+ while (i-- > 0) {
2219
+ if (A.isOdd() || B.isOdd()) {
2220
+ A.iadd(yp);
2221
+ B.isub(xp);
2222
+ }
2223
+ A.iushrn(1);
2224
+ B.iushrn(1);
2225
+ }
2226
+ }
2227
+ for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1) ;
2228
+ if (j > 0) {
2229
+ y.iushrn(j);
2230
+ while (j-- > 0) {
2231
+ if (C.isOdd() || D.isOdd()) {
2232
+ C.iadd(yp);
2233
+ D.isub(xp);
2234
+ }
2235
+ C.iushrn(1);
2236
+ D.iushrn(1);
2237
+ }
2238
+ }
2239
+ if (x.cmp(y) >= 0) {
2240
+ x.isub(y);
2241
+ A.isub(C);
2242
+ B.isub(D);
2243
+ } else {
2244
+ y.isub(x);
2245
+ C.isub(A);
2246
+ D.isub(B);
2247
+ }
2248
+ }
2249
+ return {
2250
+ a: C,
2251
+ b: D,
2252
+ gcd: y.iushln(g)
2253
+ };
2254
+ };
2255
+ BN2.prototype._invmp = function _invmp(p) {
2256
+ assert(p.negative === 0);
2257
+ assert(!p.isZero());
2258
+ var a = this;
2259
+ var b = p.clone();
2260
+ if (a.negative !== 0) {
2261
+ a = a.umod(p);
2262
+ } else {
2263
+ a = a.clone();
2264
+ }
2265
+ var x1 = new BN2(1);
2266
+ var x2 = new BN2(0);
2267
+ var delta = b.clone();
2268
+ while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
2269
+ for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1) ;
2270
+ if (i > 0) {
2271
+ a.iushrn(i);
2272
+ while (i-- > 0) {
2273
+ if (x1.isOdd()) {
2274
+ x1.iadd(delta);
2275
+ }
2276
+ x1.iushrn(1);
2277
+ }
2278
+ }
2279
+ for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1) ;
2280
+ if (j > 0) {
2281
+ b.iushrn(j);
2282
+ while (j-- > 0) {
2283
+ if (x2.isOdd()) {
2284
+ x2.iadd(delta);
2285
+ }
2286
+ x2.iushrn(1);
2287
+ }
2288
+ }
2289
+ if (a.cmp(b) >= 0) {
2290
+ a.isub(b);
2291
+ x1.isub(x2);
2292
+ } else {
2293
+ b.isub(a);
2294
+ x2.isub(x1);
2295
+ }
2296
+ }
2297
+ var res;
2298
+ if (a.cmpn(1) === 0) {
2299
+ res = x1;
2300
+ } else {
2301
+ res = x2;
2302
+ }
2303
+ if (res.cmpn(0) < 0) {
2304
+ res.iadd(p);
2305
+ }
2306
+ return res;
2307
+ };
2308
+ BN2.prototype.gcd = function gcd(num) {
2309
+ if (this.isZero()) return num.abs();
2310
+ if (num.isZero()) return this.abs();
2311
+ var a = this.clone();
2312
+ var b = num.clone();
2313
+ a.negative = 0;
2314
+ b.negative = 0;
2315
+ for (var shift = 0; a.isEven() && b.isEven(); shift++) {
2316
+ a.iushrn(1);
2317
+ b.iushrn(1);
2318
+ }
2319
+ do {
2320
+ while (a.isEven()) {
2321
+ a.iushrn(1);
2322
+ }
2323
+ while (b.isEven()) {
2324
+ b.iushrn(1);
2325
+ }
2326
+ var r = a.cmp(b);
2327
+ if (r < 0) {
2328
+ var t = a;
2329
+ a = b;
2330
+ b = t;
2331
+ } else if (r === 0 || b.cmpn(1) === 0) {
2332
+ break;
2333
+ }
2334
+ a.isub(b);
2335
+ } while (true);
2336
+ return b.iushln(shift);
2337
+ };
2338
+ BN2.prototype.invm = function invm(num) {
2339
+ return this.egcd(num).a.umod(num);
2340
+ };
2341
+ BN2.prototype.isEven = function isEven() {
2342
+ return (this.words[0] & 1) === 0;
2343
+ };
2344
+ BN2.prototype.isOdd = function isOdd() {
2345
+ return (this.words[0] & 1) === 1;
2346
+ };
2347
+ BN2.prototype.andln = function andln(num) {
2348
+ return this.words[0] & num;
2349
+ };
2350
+ BN2.prototype.bincn = function bincn(bit) {
2351
+ assert(typeof bit === "number");
2352
+ var r = bit % 26;
2353
+ var s = (bit - r) / 26;
2354
+ var q = 1 << r;
2355
+ if (this.length <= s) {
2356
+ this._expand(s + 1);
2357
+ this.words[s] |= q;
2358
+ return this;
2359
+ }
2360
+ var carry = q;
2361
+ for (var i = s; carry !== 0 && i < this.length; i++) {
2362
+ var w = this.words[i] | 0;
2363
+ w += carry;
2364
+ carry = w >>> 26;
2365
+ w &= 67108863;
2366
+ this.words[i] = w;
2367
+ }
2368
+ if (carry !== 0) {
2369
+ this.words[i] = carry;
2370
+ this.length++;
2371
+ }
2372
+ return this;
2373
+ };
2374
+ BN2.prototype.isZero = function isZero() {
2375
+ return this.length === 1 && this.words[0] === 0;
2376
+ };
2377
+ BN2.prototype.cmpn = function cmpn(num) {
2378
+ var negative = num < 0;
2379
+ if (this.negative !== 0 && !negative) return -1;
2380
+ if (this.negative === 0 && negative) return 1;
2381
+ this._strip();
2382
+ var res;
2383
+ if (this.length > 1) {
2384
+ res = 1;
2385
+ } else {
2386
+ if (negative) {
2387
+ num = -num;
2388
+ }
2389
+ assert(num <= 67108863, "Number is too big");
2390
+ var w = this.words[0] | 0;
2391
+ res = w === num ? 0 : w < num ? -1 : 1;
2392
+ }
2393
+ if (this.negative !== 0) return -res | 0;
2394
+ return res;
2395
+ };
2396
+ BN2.prototype.cmp = function cmp(num) {
2397
+ if (this.negative !== 0 && num.negative === 0) return -1;
2398
+ if (this.negative === 0 && num.negative !== 0) return 1;
2399
+ var res = this.ucmp(num);
2400
+ if (this.negative !== 0) return -res | 0;
2401
+ return res;
2402
+ };
2403
+ BN2.prototype.ucmp = function ucmp(num) {
2404
+ if (this.length > num.length) return 1;
2405
+ if (this.length < num.length) return -1;
2406
+ var res = 0;
2407
+ for (var i = this.length - 1; i >= 0; i--) {
2408
+ var a = this.words[i] | 0;
2409
+ var b = num.words[i] | 0;
2410
+ if (a === b) continue;
2411
+ if (a < b) {
2412
+ res = -1;
2413
+ } else if (a > b) {
2414
+ res = 1;
2415
+ }
2416
+ break;
2417
+ }
2418
+ return res;
2419
+ };
2420
+ BN2.prototype.gtn = function gtn(num) {
2421
+ return this.cmpn(num) === 1;
2422
+ };
2423
+ BN2.prototype.gt = function gt(num) {
2424
+ return this.cmp(num) === 1;
2425
+ };
2426
+ BN2.prototype.gten = function gten(num) {
2427
+ return this.cmpn(num) >= 0;
2428
+ };
2429
+ BN2.prototype.gte = function gte(num) {
2430
+ return this.cmp(num) >= 0;
2431
+ };
2432
+ BN2.prototype.ltn = function ltn(num) {
2433
+ return this.cmpn(num) === -1;
2434
+ };
2435
+ BN2.prototype.lt = function lt(num) {
2436
+ return this.cmp(num) === -1;
2437
+ };
2438
+ BN2.prototype.lten = function lten(num) {
2439
+ return this.cmpn(num) <= 0;
2440
+ };
2441
+ BN2.prototype.lte = function lte(num) {
2442
+ return this.cmp(num) <= 0;
2443
+ };
2444
+ BN2.prototype.eqn = function eqn(num) {
2445
+ return this.cmpn(num) === 0;
2446
+ };
2447
+ BN2.prototype.eq = function eq(num) {
2448
+ return this.cmp(num) === 0;
2449
+ };
2450
+ BN2.red = function red2(num) {
2451
+ return new Red(num);
2452
+ };
2453
+ BN2.prototype.toRed = function toRed(ctx) {
2454
+ assert(!this.red, "Already a number in reduction context");
2455
+ assert(this.negative === 0, "red works only with positives");
2456
+ return ctx.convertTo(this)._forceRed(ctx);
2457
+ };
2458
+ BN2.prototype.fromRed = function fromRed() {
2459
+ assert(this.red, "fromRed works only with numbers in reduction context");
2460
+ return this.red.convertFrom(this);
2461
+ };
2462
+ BN2.prototype._forceRed = function _forceRed(ctx) {
2463
+ this.red = ctx;
2464
+ return this;
2465
+ };
2466
+ BN2.prototype.forceRed = function forceRed(ctx) {
2467
+ assert(!this.red, "Already a number in reduction context");
2468
+ return this._forceRed(ctx);
2469
+ };
2470
+ BN2.prototype.redAdd = function redAdd(num) {
2471
+ assert(this.red, "redAdd works only with red numbers");
2472
+ return this.red.add(this, num);
2473
+ };
2474
+ BN2.prototype.redIAdd = function redIAdd(num) {
2475
+ assert(this.red, "redIAdd works only with red numbers");
2476
+ return this.red.iadd(this, num);
2477
+ };
2478
+ BN2.prototype.redSub = function redSub(num) {
2479
+ assert(this.red, "redSub works only with red numbers");
2480
+ return this.red.sub(this, num);
2481
+ };
2482
+ BN2.prototype.redISub = function redISub(num) {
2483
+ assert(this.red, "redISub works only with red numbers");
2484
+ return this.red.isub(this, num);
2485
+ };
2486
+ BN2.prototype.redShl = function redShl(num) {
2487
+ assert(this.red, "redShl works only with red numbers");
2488
+ return this.red.shl(this, num);
2489
+ };
2490
+ BN2.prototype.redMul = function redMul(num) {
2491
+ assert(this.red, "redMul works only with red numbers");
2492
+ this.red._verify2(this, num);
2493
+ return this.red.mul(this, num);
2494
+ };
2495
+ BN2.prototype.redIMul = function redIMul(num) {
2496
+ assert(this.red, "redMul works only with red numbers");
2497
+ this.red._verify2(this, num);
2498
+ return this.red.imul(this, num);
2499
+ };
2500
+ BN2.prototype.redSqr = function redSqr() {
2501
+ assert(this.red, "redSqr works only with red numbers");
2502
+ this.red._verify1(this);
2503
+ return this.red.sqr(this);
2504
+ };
2505
+ BN2.prototype.redISqr = function redISqr() {
2506
+ assert(this.red, "redISqr works only with red numbers");
2507
+ this.red._verify1(this);
2508
+ return this.red.isqr(this);
2509
+ };
2510
+ BN2.prototype.redSqrt = function redSqrt() {
2511
+ assert(this.red, "redSqrt works only with red numbers");
2512
+ this.red._verify1(this);
2513
+ return this.red.sqrt(this);
2514
+ };
2515
+ BN2.prototype.redInvm = function redInvm() {
2516
+ assert(this.red, "redInvm works only with red numbers");
2517
+ this.red._verify1(this);
2518
+ return this.red.invm(this);
2519
+ };
2520
+ BN2.prototype.redNeg = function redNeg() {
2521
+ assert(this.red, "redNeg works only with red numbers");
2522
+ this.red._verify1(this);
2523
+ return this.red.neg(this);
2524
+ };
2525
+ BN2.prototype.redPow = function redPow(num) {
2526
+ assert(this.red && !num.red, "redPow(normalNum)");
2527
+ this.red._verify1(this);
2528
+ return this.red.pow(this, num);
2529
+ };
2530
+ var primes = {
2531
+ k256: null,
2532
+ p224: null,
2533
+ p192: null,
2534
+ p25519: null
2535
+ };
2536
+ function MPrime(name, p) {
2537
+ this.name = name;
2538
+ this.p = new BN2(p, 16);
2539
+ this.n = this.p.bitLength();
2540
+ this.k = new BN2(1).iushln(this.n).isub(this.p);
2541
+ this.tmp = this._tmp();
2542
+ }
2543
+ MPrime.prototype._tmp = function _tmp() {
2544
+ var tmp = new BN2(null);
2545
+ tmp.words = new Array(Math.ceil(this.n / 13));
2546
+ return tmp;
2547
+ };
2548
+ MPrime.prototype.ireduce = function ireduce(num) {
2549
+ var r = num;
2550
+ var rlen;
2551
+ do {
2552
+ this.split(r, this.tmp);
2553
+ r = this.imulK(r);
2554
+ r = r.iadd(this.tmp);
2555
+ rlen = r.bitLength();
2556
+ } while (rlen > this.n);
2557
+ var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
2558
+ if (cmp === 0) {
2559
+ r.words[0] = 0;
2560
+ r.length = 1;
2561
+ } else if (cmp > 0) {
2562
+ r.isub(this.p);
2563
+ } else {
2564
+ if (r.strip !== void 0) {
2565
+ r.strip();
2566
+ } else {
2567
+ r._strip();
2568
+ }
2569
+ }
2570
+ return r;
2571
+ };
2572
+ MPrime.prototype.split = function split(input, out) {
2573
+ input.iushrn(this.n, 0, out);
2574
+ };
2575
+ MPrime.prototype.imulK = function imulK(num) {
2576
+ return num.imul(this.k);
2577
+ };
2578
+ function K256() {
2579
+ MPrime.call(
2580
+ this,
2581
+ "k256",
2582
+ "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"
2583
+ );
2584
+ }
2585
+ inherits(K256, MPrime);
2586
+ K256.prototype.split = function split(input, output) {
2587
+ var mask = 4194303;
2588
+ var outLen = Math.min(input.length, 9);
2589
+ for (var i = 0; i < outLen; i++) {
2590
+ output.words[i] = input.words[i];
2591
+ }
2592
+ output.length = outLen;
2593
+ if (input.length <= 9) {
2594
+ input.words[0] = 0;
2595
+ input.length = 1;
2596
+ return;
2597
+ }
2598
+ var prev = input.words[9];
2599
+ output.words[output.length++] = prev & mask;
2600
+ for (i = 10; i < input.length; i++) {
2601
+ var next = input.words[i] | 0;
2602
+ input.words[i - 10] = (next & mask) << 4 | prev >>> 22;
2603
+ prev = next;
2604
+ }
2605
+ prev >>>= 22;
2606
+ input.words[i - 10] = prev;
2607
+ if (prev === 0 && input.length > 10) {
2608
+ input.length -= 10;
2609
+ } else {
2610
+ input.length -= 9;
2611
+ }
2612
+ };
2613
+ K256.prototype.imulK = function imulK(num) {
2614
+ num.words[num.length] = 0;
2615
+ num.words[num.length + 1] = 0;
2616
+ num.length += 2;
2617
+ var lo = 0;
2618
+ for (var i = 0; i < num.length; i++) {
2619
+ var w = num.words[i] | 0;
2620
+ lo += w * 977;
2621
+ num.words[i] = lo & 67108863;
2622
+ lo = w * 64 + (lo / 67108864 | 0);
2623
+ }
2624
+ if (num.words[num.length - 1] === 0) {
2625
+ num.length--;
2626
+ if (num.words[num.length - 1] === 0) {
2627
+ num.length--;
2628
+ }
2629
+ }
2630
+ return num;
2631
+ };
2632
+ function P224() {
2633
+ MPrime.call(
2634
+ this,
2635
+ "p224",
2636
+ "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"
2637
+ );
2638
+ }
2639
+ inherits(P224, MPrime);
2640
+ function P192() {
2641
+ MPrime.call(
2642
+ this,
2643
+ "p192",
2644
+ "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"
2645
+ );
2646
+ }
2647
+ inherits(P192, MPrime);
2648
+ function P25519() {
2649
+ MPrime.call(
2650
+ this,
2651
+ "25519",
2652
+ "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"
2653
+ );
2654
+ }
2655
+ inherits(P25519, MPrime);
2656
+ P25519.prototype.imulK = function imulK(num) {
2657
+ var carry = 0;
2658
+ for (var i = 0; i < num.length; i++) {
2659
+ var hi = (num.words[i] | 0) * 19 + carry;
2660
+ var lo = hi & 67108863;
2661
+ hi >>>= 26;
2662
+ num.words[i] = lo;
2663
+ carry = hi;
2664
+ }
2665
+ if (carry !== 0) {
2666
+ num.words[num.length++] = carry;
2667
+ }
2668
+ return num;
2669
+ };
2670
+ BN2._prime = function prime(name) {
2671
+ if (primes[name]) return primes[name];
2672
+ var prime2;
2673
+ if (name === "k256") {
2674
+ prime2 = new K256();
2675
+ } else if (name === "p224") {
2676
+ prime2 = new P224();
2677
+ } else if (name === "p192") {
2678
+ prime2 = new P192();
2679
+ } else if (name === "p25519") {
2680
+ prime2 = new P25519();
2681
+ } else {
2682
+ throw new Error("Unknown prime " + name);
2683
+ }
2684
+ primes[name] = prime2;
2685
+ return prime2;
2686
+ };
2687
+ function Red(m) {
2688
+ if (typeof m === "string") {
2689
+ var prime = BN2._prime(m);
2690
+ this.m = prime.p;
2691
+ this.prime = prime;
2692
+ } else {
2693
+ assert(m.gtn(1), "modulus must be greater than 1");
2694
+ this.m = m;
2695
+ this.prime = null;
2696
+ }
2697
+ }
2698
+ Red.prototype._verify1 = function _verify1(a) {
2699
+ assert(a.negative === 0, "red works only with positives");
2700
+ assert(a.red, "red works only with red numbers");
2701
+ };
2702
+ Red.prototype._verify2 = function _verify2(a, b) {
2703
+ assert((a.negative | b.negative) === 0, "red works only with positives");
2704
+ assert(
2705
+ a.red && a.red === b.red,
2706
+ "red works only with red numbers"
2707
+ );
2708
+ };
2709
+ Red.prototype.imod = function imod(a) {
2710
+ if (this.prime) return this.prime.ireduce(a)._forceRed(this);
2711
+ move(a, a.umod(this.m)._forceRed(this));
2712
+ return a;
2713
+ };
2714
+ Red.prototype.neg = function neg(a) {
2715
+ if (a.isZero()) {
2716
+ return a.clone();
2717
+ }
2718
+ return this.m.sub(a)._forceRed(this);
2719
+ };
2720
+ Red.prototype.add = function add(a, b) {
2721
+ this._verify2(a, b);
2722
+ var res = a.add(b);
2723
+ if (res.cmp(this.m) >= 0) {
2724
+ res.isub(this.m);
2725
+ }
2726
+ return res._forceRed(this);
2727
+ };
2728
+ Red.prototype.iadd = function iadd(a, b) {
2729
+ this._verify2(a, b);
2730
+ var res = a.iadd(b);
2731
+ if (res.cmp(this.m) >= 0) {
2732
+ res.isub(this.m);
2733
+ }
2734
+ return res;
2735
+ };
2736
+ Red.prototype.sub = function sub(a, b) {
2737
+ this._verify2(a, b);
2738
+ var res = a.sub(b);
2739
+ if (res.cmpn(0) < 0) {
2740
+ res.iadd(this.m);
2741
+ }
2742
+ return res._forceRed(this);
2743
+ };
2744
+ Red.prototype.isub = function isub(a, b) {
2745
+ this._verify2(a, b);
2746
+ var res = a.isub(b);
2747
+ if (res.cmpn(0) < 0) {
2748
+ res.iadd(this.m);
2749
+ }
2750
+ return res;
2751
+ };
2752
+ Red.prototype.shl = function shl(a, num) {
2753
+ this._verify1(a);
2754
+ return this.imod(a.ushln(num));
2755
+ };
2756
+ Red.prototype.imul = function imul(a, b) {
2757
+ this._verify2(a, b);
2758
+ return this.imod(a.imul(b));
2759
+ };
2760
+ Red.prototype.mul = function mul(a, b) {
2761
+ this._verify2(a, b);
2762
+ return this.imod(a.mul(b));
2763
+ };
2764
+ Red.prototype.isqr = function isqr(a) {
2765
+ return this.imul(a, a.clone());
2766
+ };
2767
+ Red.prototype.sqr = function sqr(a) {
2768
+ return this.mul(a, a);
2769
+ };
2770
+ Red.prototype.sqrt = function sqrt(a) {
2771
+ if (a.isZero()) return a.clone();
2772
+ var mod3 = this.m.andln(3);
2773
+ assert(mod3 % 2 === 1);
2774
+ if (mod3 === 3) {
2775
+ var pow = this.m.add(new BN2(1)).iushrn(2);
2776
+ return this.pow(a, pow);
2777
+ }
2778
+ var q = this.m.subn(1);
2779
+ var s = 0;
2780
+ while (!q.isZero() && q.andln(1) === 0) {
2781
+ s++;
2782
+ q.iushrn(1);
2783
+ }
2784
+ assert(!q.isZero());
2785
+ var one = new BN2(1).toRed(this);
2786
+ var nOne = one.redNeg();
2787
+ var lpow = this.m.subn(1).iushrn(1);
2788
+ var z = this.m.bitLength();
2789
+ z = new BN2(2 * z * z).toRed(this);
2790
+ while (this.pow(z, lpow).cmp(nOne) !== 0) {
2791
+ z.redIAdd(nOne);
2792
+ }
2793
+ var c = this.pow(z, q);
2794
+ var r = this.pow(a, q.addn(1).iushrn(1));
2795
+ var t = this.pow(a, q);
2796
+ var m = s;
2797
+ while (t.cmp(one) !== 0) {
2798
+ var tmp = t;
2799
+ for (var i = 0; tmp.cmp(one) !== 0; i++) {
2800
+ tmp = tmp.redSqr();
2801
+ }
2802
+ assert(i < m);
2803
+ var b = this.pow(c, new BN2(1).iushln(m - i - 1));
2804
+ r = r.redMul(b);
2805
+ c = b.redSqr();
2806
+ t = t.redMul(c);
2807
+ m = i;
2808
+ }
2809
+ return r;
2810
+ };
2811
+ Red.prototype.invm = function invm(a) {
2812
+ var inv = a._invmp(this.m);
2813
+ if (inv.negative !== 0) {
2814
+ inv.negative = 0;
2815
+ return this.imod(inv).redNeg();
2816
+ } else {
2817
+ return this.imod(inv);
2818
+ }
2819
+ };
2820
+ Red.prototype.pow = function pow(a, num) {
2821
+ if (num.isZero()) return new BN2(1).toRed(this);
2822
+ if (num.cmpn(1) === 0) return a.clone();
2823
+ var windowSize = 4;
2824
+ var wnd = new Array(1 << windowSize);
2825
+ wnd[0] = new BN2(1).toRed(this);
2826
+ wnd[1] = a;
2827
+ for (var i = 2; i < wnd.length; i++) {
2828
+ wnd[i] = this.mul(wnd[i - 1], a);
2829
+ }
2830
+ var res = wnd[0];
2831
+ var current = 0;
2832
+ var currentLen = 0;
2833
+ var start = num.bitLength() % 26;
2834
+ if (start === 0) {
2835
+ start = 26;
2836
+ }
2837
+ for (i = num.length - 1; i >= 0; i--) {
2838
+ var word = num.words[i];
2839
+ for (var j = start - 1; j >= 0; j--) {
2840
+ var bit = word >> j & 1;
2841
+ if (res !== wnd[0]) {
2842
+ res = this.sqr(res);
2843
+ }
2844
+ if (bit === 0 && current === 0) {
2845
+ currentLen = 0;
2846
+ continue;
2847
+ }
2848
+ current <<= 1;
2849
+ current |= bit;
2850
+ currentLen++;
2851
+ if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
2852
+ res = this.mul(res, wnd[current]);
2853
+ currentLen = 0;
2854
+ current = 0;
2855
+ }
2856
+ start = 26;
2857
+ }
2858
+ return res;
2859
+ };
2860
+ Red.prototype.convertTo = function convertTo(num) {
2861
+ var r = num.umod(this.m);
2862
+ return r === num ? r.clone() : r;
2863
+ };
2864
+ Red.prototype.convertFrom = function convertFrom(num) {
2865
+ var res = num.clone();
2866
+ res.red = null;
2867
+ return res;
2868
+ };
2869
+ BN2.mont = function mont(num) {
2870
+ return new Mont(num);
2871
+ };
2872
+ function Mont(m) {
2873
+ Red.call(this, m);
2874
+ this.shift = this.m.bitLength();
2875
+ if (this.shift % 26 !== 0) {
2876
+ this.shift += 26 - this.shift % 26;
2877
+ }
2878
+ this.r = new BN2(1).iushln(this.shift);
2879
+ this.r2 = this.imod(this.r.sqr());
2880
+ this.rinv = this.r._invmp(this.m);
2881
+ this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
2882
+ this.minv = this.minv.umod(this.r);
2883
+ this.minv = this.r.sub(this.minv);
2884
+ }
2885
+ inherits(Mont, Red);
2886
+ Mont.prototype.convertTo = function convertTo(num) {
2887
+ return this.imod(num.ushln(this.shift));
2888
+ };
2889
+ Mont.prototype.convertFrom = function convertFrom(num) {
2890
+ var r = this.imod(num.mul(this.rinv));
2891
+ r.red = null;
2892
+ return r;
2893
+ };
2894
+ Mont.prototype.imul = function imul(a, b) {
2895
+ if (a.isZero() || b.isZero()) {
2896
+ a.words[0] = 0;
2897
+ a.length = 1;
2898
+ return a;
2899
+ }
2900
+ var t = a.imul(b);
2901
+ var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
2902
+ var u = t.isub(c).iushrn(this.shift);
2903
+ var res = u;
2904
+ if (u.cmp(this.m) >= 0) {
2905
+ res = u.isub(this.m);
2906
+ } else if (u.cmpn(0) < 0) {
2907
+ res = u.iadd(this.m);
2908
+ }
2909
+ return res._forceRed(this);
2910
+ };
2911
+ Mont.prototype.mul = function mul(a, b) {
2912
+ if (a.isZero() || b.isZero()) return new BN2(0)._forceRed(this);
2913
+ var t = a.mul(b);
2914
+ var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
2915
+ var u = t.isub(c).iushrn(this.shift);
2916
+ var res = u;
2917
+ if (u.cmp(this.m) >= 0) {
2918
+ res = u.isub(this.m);
2919
+ } else if (u.cmpn(0) < 0) {
2920
+ res = u.iadd(this.m);
2921
+ }
2922
+ return res._forceRed(this);
2923
+ };
2924
+ Mont.prototype.invm = function invm(a) {
2925
+ var res = this.imod(a._invmp(this.m).mul(this.r2));
2926
+ return res._forceRed(this);
2927
+ };
2928
+ })(typeof module2 === "undefined" || module2, exports2);
2929
+ }
2930
+ });
29
2931
 
30
2932
  // src/cli.ts
31
- var import_web32 = require("@solana/web3.js");
2933
+ init_cjs_shims();
2934
+ var import_web33 = require("@solana/web3.js");
2935
+
2936
+ // ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.js
2937
+ init_cjs_shims();
32
2938
 
33
2939
  // ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
2940
+ init_cjs_shims();
34
2941
  var ANSI_BACKGROUND_OFFSET = 10;
35
2942
  var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
36
2943
  var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
@@ -217,6 +3124,7 @@ var ansiStyles = assembleStyles();
217
3124
  var ansi_styles_default = ansiStyles;
218
3125
 
219
3126
  // ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js
3127
+ init_cjs_shims();
220
3128
  var import_node_process = __toESM(require("process"), 1);
221
3129
  var import_node_os = __toESM(require("os"), 1);
222
3130
  var import_node_tty = __toESM(require("tty"), 1);
@@ -349,6 +3257,7 @@ var supportsColor = {
349
3257
  var supports_color_default = supportsColor;
350
3258
 
351
3259
  // ../../node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.js
3260
+ init_cjs_shims();
352
3261
  function stringReplaceAll(string, substring, replacer) {
353
3262
  let index = string.indexOf(substring);
354
3263
  if (index === -1) {
@@ -529,15 +3438,22 @@ var source_default = chalk;
529
3438
  var import_commander = require("commander");
530
3439
 
531
3440
  // ../../node_modules/.pnpm/ora@9.0.0/node_modules/ora/index.js
3441
+ init_cjs_shims();
532
3442
  var import_node_process6 = __toESM(require("process"), 1);
533
3443
 
534
3444
  // ../../node_modules/.pnpm/cli-cursor@5.0.0/node_modules/cli-cursor/index.js
3445
+ init_cjs_shims();
535
3446
  var import_node_process3 = __toESM(require("process"), 1);
536
3447
 
537
3448
  // ../../node_modules/.pnpm/restore-cursor@5.1.0/node_modules/restore-cursor/index.js
3449
+ init_cjs_shims();
538
3450
  var import_node_process2 = __toESM(require("process"), 1);
539
3451
 
3452
+ // ../../node_modules/.pnpm/onetime@7.0.0/node_modules/onetime/index.js
3453
+ init_cjs_shims();
3454
+
540
3455
  // ../../node_modules/.pnpm/mimic-function@5.0.1/node_modules/mimic-function/index.js
3456
+ init_cjs_shims();
541
3457
  var copyProperty = (to, from, property, ignoreNonConfigurable) => {
542
3458
  if (property === "length" || property === "prototype") {
543
3459
  return;
@@ -614,7 +3530,11 @@ onetime.callCount = (function_) => {
614
3530
  };
615
3531
  var onetime_default = onetime;
616
3532
 
3533
+ // ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js
3534
+ init_cjs_shims();
3535
+
617
3536
  // ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
3537
+ init_cjs_shims();
618
3538
  var signals = [];
619
3539
  signals.push("SIGHUP", "SIGINT", "SIGTERM");
620
3540
  if (process.platform !== "win32") {
@@ -905,6 +3825,9 @@ cliCursor.toggle = (force, writableStream) => {
905
3825
  };
906
3826
  var cli_cursor_default = cliCursor;
907
3827
 
3828
+ // ../../node_modules/.pnpm/cli-spinners@3.2.1/node_modules/cli-spinners/index.js
3829
+ init_cjs_shims();
3830
+
908
3831
  // ../../node_modules/.pnpm/cli-spinners@3.2.1/node_modules/cli-spinners/spinners.json
909
3832
  var spinners_default = {
910
3833
  dots: {
@@ -2563,6 +5486,9 @@ var spinners_default = {
2563
5486
  var cli_spinners_default = spinners_default;
2564
5487
  var spinnersList = Object.keys(spinners_default);
2565
5488
 
5489
+ // ../../node_modules/.pnpm/log-symbols@7.0.1/node_modules/log-symbols/index.js
5490
+ init_cjs_shims();
5491
+
2566
5492
  // ../../node_modules/.pnpm/log-symbols@7.0.1/node_modules/log-symbols/symbols.js
2567
5493
  var symbols_exports = {};
2568
5494
  __export(symbols_exports, {
@@ -2571,8 +5497,10 @@ __export(symbols_exports, {
2571
5497
  success: () => success,
2572
5498
  warning: () => warning
2573
5499
  });
5500
+ init_cjs_shims();
2574
5501
 
2575
5502
  // ../../node_modules/.pnpm/yoctocolors@2.1.2/node_modules/yoctocolors/base.js
5503
+ init_cjs_shims();
2576
5504
  var import_node_tty2 = __toESM(require("tty"), 1);
2577
5505
  var hasColors = import_node_tty2.default?.WriteStream?.prototype?.hasColors?.() ?? false;
2578
5506
  var format = (open, close) => {
@@ -2643,6 +5571,7 @@ var bgCyanBright = format(106, 49);
2643
5571
  var bgWhiteBright = format(107, 49);
2644
5572
 
2645
5573
  // ../../node_modules/.pnpm/is-unicode-supported@2.1.0/node_modules/is-unicode-supported/index.js
5574
+ init_cjs_shims();
2646
5575
  var import_node_process4 = __toESM(require("process"), 1);
2647
5576
  function isUnicodeSupported() {
2648
5577
  const { env: env2 } = import_node_process4.default;
@@ -2660,7 +5589,11 @@ var success = green(_isUnicodeSupported ? "\u2714" : "\u221A");
2660
5589
  var warning = yellow(_isUnicodeSupported ? "\u26A0" : "\u203C");
2661
5590
  var error = red(_isUnicodeSupported ? "\u2716" : "\xD7");
2662
5591
 
5592
+ // ../../node_modules/.pnpm/strip-ansi@7.1.2/node_modules/strip-ansi/index.js
5593
+ init_cjs_shims();
5594
+
2663
5595
  // ../../node_modules/.pnpm/ansi-regex@6.2.0/node_modules/ansi-regex/index.js
5596
+ init_cjs_shims();
2664
5597
  function ansiRegex({ onlyFirst = false } = {}) {
2665
5598
  const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
2666
5599
  const osc = `(?:\\u001B\\][\\s\\S]*?${ST})`;
@@ -2678,7 +5611,14 @@ function stripAnsi(string) {
2678
5611
  return string.replace(regex, "");
2679
5612
  }
2680
5613
 
5614
+ // ../../node_modules/.pnpm/string-width@8.1.0/node_modules/string-width/index.js
5615
+ init_cjs_shims();
5616
+
5617
+ // ../../node_modules/.pnpm/get-east-asian-width@1.3.1/node_modules/get-east-asian-width/index.js
5618
+ init_cjs_shims();
5619
+
2681
5620
  // ../../node_modules/.pnpm/get-east-asian-width@1.3.1/node_modules/get-east-asian-width/lookup.js
5621
+ init_cjs_shims();
2682
5622
  function isAmbiguous(x) {
2683
5623
  return x === 161 || x === 164 || x === 167 || x === 168 || x === 170 || x === 173 || x === 174 || x >= 176 && x <= 180 || x >= 182 && x <= 186 || x >= 188 && x <= 191 || x === 198 || x === 208 || x === 215 || x === 216 || x >= 222 && x <= 225 || x === 230 || x >= 232 && x <= 234 || x === 236 || x === 237 || x === 240 || x === 242 || x === 243 || x >= 247 && x <= 250 || x === 252 || x === 254 || x === 257 || x === 273 || x === 275 || x === 283 || x === 294 || x === 295 || x === 299 || x >= 305 && x <= 307 || x === 312 || x >= 319 && x <= 322 || x === 324 || x >= 328 && x <= 331 || x === 333 || x === 338 || x === 339 || x === 358 || x === 359 || x === 363 || x === 462 || x === 464 || x === 466 || x === 468 || x === 470 || x === 472 || x === 474 || x === 476 || x === 593 || x === 609 || x === 708 || x === 711 || x >= 713 && x <= 715 || x === 717 || x === 720 || x >= 728 && x <= 731 || x === 733 || x === 735 || x >= 768 && x <= 879 || x >= 913 && x <= 929 || x >= 931 && x <= 937 || x >= 945 && x <= 961 || x >= 963 && x <= 969 || x === 1025 || x >= 1040 && x <= 1103 || x === 1105 || x === 8208 || x >= 8211 && x <= 8214 || x === 8216 || x === 8217 || x === 8220 || x === 8221 || x >= 8224 && x <= 8226 || x >= 8228 && x <= 8231 || x === 8240 || x === 8242 || x === 8243 || x === 8245 || x === 8251 || x === 8254 || x === 8308 || x === 8319 || x >= 8321 && x <= 8324 || x === 8364 || x === 8451 || x === 8453 || x === 8457 || x === 8467 || x === 8470 || x === 8481 || x === 8482 || x === 8486 || x === 8491 || x === 8531 || x === 8532 || x >= 8539 && x <= 8542 || x >= 8544 && x <= 8555 || x >= 8560 && x <= 8569 || x === 8585 || x >= 8592 && x <= 8601 || x === 8632 || x === 8633 || x === 8658 || x === 8660 || x === 8679 || x === 8704 || x === 8706 || x === 8707 || x === 8711 || x === 8712 || x === 8715 || x === 8719 || x === 8721 || x === 8725 || x === 8730 || x >= 8733 && x <= 8736 || x === 8739 || x === 8741 || x >= 8743 && x <= 8748 || x === 8750 || x >= 8756 && x <= 8759 || x === 8764 || x === 8765 || x === 8776 || x === 8780 || x === 8786 || x === 8800 || x === 8801 || x >= 8804 && x <= 8807 || x === 8810 || x === 8811 || x === 8814 || x === 8815 || x === 8834 || x === 8835 || x === 8838 || x === 8839 || x === 8853 || x === 8857 || x === 8869 || x === 8895 || x === 8978 || x >= 9312 && x <= 9449 || x >= 9451 && x <= 9547 || x >= 9552 && x <= 9587 || x >= 9600 && x <= 9615 || x >= 9618 && x <= 9621 || x === 9632 || x === 9633 || x >= 9635 && x <= 9641 || x === 9650 || x === 9651 || x === 9654 || x === 9655 || x === 9660 || x === 9661 || x === 9664 || x === 9665 || x >= 9670 && x <= 9672 || x === 9675 || x >= 9678 && x <= 9681 || x >= 9698 && x <= 9701 || x === 9711 || x === 9733 || x === 9734 || x === 9737 || x === 9742 || x === 9743 || x === 9756 || x === 9758 || x === 9792 || x === 9794 || x === 9824 || x === 9825 || x >= 9827 && x <= 9829 || x >= 9831 && x <= 9834 || x === 9836 || x === 9837 || x === 9839 || x === 9886 || x === 9887 || x === 9919 || x >= 9926 && x <= 9933 || x >= 9935 && x <= 9939 || x >= 9941 && x <= 9953 || x === 9955 || x === 9960 || x === 9961 || x >= 9963 && x <= 9969 || x === 9972 || x >= 9974 && x <= 9977 || x === 9979 || x === 9980 || x === 9982 || x === 9983 || x === 10045 || x >= 10102 && x <= 10111 || x >= 11094 && x <= 11097 || x >= 12872 && x <= 12879 || x >= 57344 && x <= 63743 || x >= 65024 && x <= 65039 || x === 65533 || x >= 127232 && x <= 127242 || x >= 127248 && x <= 127277 || x >= 127280 && x <= 127337 || x >= 127344 && x <= 127373 || x === 127375 || x === 127376 || x >= 127387 && x <= 127404 || x >= 917760 && x <= 917999 || x >= 983040 && x <= 1048573 || x >= 1048576 && x <= 1114109;
2684
5624
  }
@@ -2758,6 +5698,7 @@ function stringWidth(input, options = {}) {
2758
5698
  }
2759
5699
 
2760
5700
  // ../../node_modules/.pnpm/is-interactive@2.0.0/node_modules/is-interactive/index.js
5701
+ init_cjs_shims();
2761
5702
  function isInteractive({ stream = process.stdout } = {}) {
2762
5703
  return Boolean(
2763
5704
  stream && stream.isTTY && process.env.TERM !== "dumb" && !("CI" in process.env)
@@ -2765,6 +5706,7 @@ function isInteractive({ stream = process.stdout } = {}) {
2765
5706
  }
2766
5707
 
2767
5708
  // ../../node_modules/.pnpm/stdin-discarder@0.2.2/node_modules/stdin-discarder/index.js
5709
+ init_cjs_shims();
2768
5710
  var import_node_process5 = __toESM(require("process"), 1);
2769
5711
  var ASCII_ETX_CODE = 3;
2770
5712
  var StdinDiscarder = class {
@@ -3115,6 +6057,7 @@ function ora(options) {
3115
6057
  }
3116
6058
 
3117
6059
  // src/context.ts
6060
+ init_cjs_shims();
3118
6061
  var import_node_buffer = require("buffer");
3119
6062
  var import_node_fs = require("fs");
3120
6063
  var import_node_os2 = require("os");
@@ -3122,30 +6065,36 @@ var import_node_path = require("path");
3122
6065
  var import_anchor = require("@coral-xyz/anchor");
3123
6066
  var import_bond_sdk = require("@jpool/bond-sdk");
3124
6067
  var import_web3 = require("@solana/web3.js");
3125
- var DEFAULT_CLUSTER = "mainnet-beta";
3126
6068
  var context;
3127
6069
  function useContext() {
3128
6070
  return context;
3129
6071
  }
3130
6072
  function initContext({ cluster, env: env2, keypair }) {
3131
6073
  const opts = import_anchor.AnchorProvider.defaultOptions();
3132
- const connection = new import_web3.Connection(resolveRpcUrl(cluster), opts.commitment);
6074
+ const rpcUrl = resolveRpcUrl(cluster);
6075
+ const connection = new import_web3.Connection(rpcUrl, opts.commitment);
3133
6076
  const wallet = new import_anchor.Wallet(resolveKeypair(keypair));
3134
6077
  const provider = new import_anchor.AnchorProvider(connection, wallet, opts);
3135
6078
  const client = new import_bond_sdk.JBondClient(provider).env(env2);
3136
- return context = { keypair: wallet.payer, provider, client, cluster: cluster ?? DEFAULT_CLUSTER };
6079
+ context = {
6080
+ cluster: cluster || "mainnet-beta",
6081
+ keypair: wallet.payer,
6082
+ provider,
6083
+ client
6084
+ };
6085
+ return context;
3137
6086
  }
3138
6087
  function resolveRpcUrl(cluster) {
6088
+ if (!cluster) {
6089
+ return (0, import_web3.clusterApiUrl)("mainnet-beta");
6090
+ }
6091
+ if (cluster.startsWith("http")) {
6092
+ return cluster;
6093
+ }
3139
6094
  try {
3140
- if (!cluster) {
3141
- throw new Error("No cluster provided");
3142
- }
3143
6095
  return (0, import_web3.clusterApiUrl)(cluster);
3144
6096
  } catch {
3145
- if (cluster && cluster.startsWith("http")) {
3146
- return cluster;
3147
- }
3148
- return (0, import_web3.clusterApiUrl)(DEFAULT_CLUSTER);
6097
+ return (0, import_web3.clusterApiUrl)("mainnet-beta");
3149
6098
  }
3150
6099
  }
3151
6100
  function resolveKeypair(path) {
@@ -3157,246 +6106,448 @@ function resolveKeypair(path) {
3157
6106
  } else if (process.env.CLI_SOLANA_KEYPAIR) {
3158
6107
  buffer = (0, import_node_fs.readFileSync)(process.env.CLI_SOLANA_KEYPAIR);
3159
6108
  } else {
3160
- buffer = (0, import_node_fs.readFileSync)(
3161
- (0, import_node_path.join)((0, import_node_os2.homedir)(), ".config", "solana", "id.json").replace(/\\/g, "/")
3162
- );
6109
+ const defaultPath = (0, import_node_path.join)((0, import_node_os2.homedir)(), ".config", "solana", "id.json").replace(/\\/g, "/");
6110
+ buffer = (0, import_node_fs.readFileSync)(defaultPath);
3163
6111
  }
3164
- return import_web3.Keypair.fromSecretKey(
3165
- import_node_buffer.Buffer.from(JSON.parse(buffer.toString()))
3166
- );
6112
+ return import_web3.Keypair.fromSecretKey(import_node_buffer.Buffer.from(JSON.parse(buffer.toString())));
6113
+ }
6114
+
6115
+ // src/utils.ts
6116
+ init_cjs_shims();
6117
+ var import_web32 = require("@solana/web3.js");
6118
+ var import_bn = __toESM(require_bn());
6119
+ function lamportsToSol(lamports) {
6120
+ if (typeof lamports === "number") {
6121
+ return Math.abs(lamports) / import_web32.LAMPORTS_PER_SOL;
6122
+ }
6123
+ let signMultiplier = 1;
6124
+ if (lamports.isNeg()) {
6125
+ signMultiplier = -1;
6126
+ }
6127
+ const absLamports = lamports.abs();
6128
+ const lamportsString = absLamports.toString(10).padStart(10, "0");
6129
+ const splitIndex = lamportsString.length - 9;
6130
+ const solString = `${lamportsString.slice(0, splitIndex)}.${lamportsString.slice(splitIndex)}`;
6131
+ return signMultiplier * Number.parseFloat(solString);
6132
+ }
6133
+ function parseCollateralType(input) {
6134
+ if (input === "native") {
6135
+ return { native: {} };
6136
+ }
6137
+ if (input.startsWith("token:")) {
6138
+ const parts = input.split(":");
6139
+ if (parts.length !== 2) {
6140
+ throw new Error("Invalid token format. Use token:<mint-address>");
6141
+ }
6142
+ return { token: [new import_web32.PublicKey(parts[1])] };
6143
+ }
6144
+ if (input.startsWith("stakeAccount:")) {
6145
+ return { stakeAccount: {} };
6146
+ }
6147
+ throw new Error("Invalid collateral type. Use: native | token:<mint> | stakeAccount");
6148
+ }
6149
+ function parseBondType(type) {
6150
+ const normalized = (type || "").toLowerCase();
6151
+ if (normalized === "crowdfunding") {
6152
+ return { crowdfunding: {} };
6153
+ }
6154
+ if (normalized === "standard") {
6155
+ return { standard: {} };
6156
+ }
6157
+ console.error(source_default.red(`Invalid bond type: ${type}`));
6158
+ process.exit(1);
3167
6159
  }
3168
6160
 
3169
6161
  // package.json
3170
- var version = "1.5.3";
6162
+ var version = "1.6.0";
3171
6163
 
3172
6164
  // src/cli.ts
3173
- import_commander.program.name("jbond").description("CLI to interact with the JPool Bond program").version(process.env.VERSION ?? version).allowExcessArguments(false).option("-c, --cluster <CLUSTER>", "Solana cluster or RPC URL").option("-k, --keypair <KEYPAIR>", "Filepath to Solana keypair").hook("preAction", async (command) => {
6165
+ var log = {
6166
+ success: (...text) => console.log(source_default.green(...text)),
6167
+ warn: (...text) => console.log(source_default.yellow(...text)),
6168
+ info: (...text) => console.log(source_default.blue(...text)),
6169
+ error: (...text) => console.error(source_default.red(...text)),
6170
+ header: (...text) => console.log(source_default.cyan(`${text}
6171
+ `)),
6172
+ json: (data, color) => console.log(source_default[color ?? "magenta"](JSON.stringify(data, null, 2)))
6173
+ };
6174
+ import_commander.program.name("jbond").description("CLI to interact with the JPool Bond program").version(process.env.VERSION ?? version).option("-c, --cluster <cluster>", "Solana cluster (mainnet-beta, devnet, testnet) or RPC URL", process.env.CLUSTER ?? "mainnet-beta").option("-k, --keypair <path>", "Path to Solana keypair file").option("-b, --bond <name>", "Bond name (or set JBOND_BOND env var)", process.env.JBOND_BOND).option("-t, --bond-type <type>", "Bond type: standard|crowdfunding", "standard").hook("preAction", async (command) => {
3174
6175
  const opts = command.opts();
3175
6176
  const { provider, client } = initContext(opts);
3176
- console.log(source_default.dim(`# Version: ${command.version()}`));
3177
- console.log(source_default.dim(`# Program: ${client.programId}`));
3178
- console.log(source_default.dim(`# Keypair: ${provider.wallet.publicKey}`));
3179
- console.log(source_default.dim(`# Rpc Url: ${provider.connection.rpcEndpoint}`));
3180
- console.log("\n");
3181
- }).hook("postAction", (_c) => {
3182
- process.exit();
3183
- });
3184
- import_commander.program.command("info").description("Get global state information").action(async () => {
6177
+ log.json({
6178
+ version: command.version(),
6179
+ program: client.programId,
6180
+ signer: provider.wallet.publicKey,
6181
+ rpc: provider.connection.rpcEndpoint
6182
+ }, "dim");
6183
+ console.log("");
6184
+ }).hook("postAction", () => process.exit(0));
6185
+ import_commander.program.command("init").description("Initialize global bond program state").option("-a, --authority <pubkey>", "Authority (defaults to signer)").action(async (opts) => {
6186
+ const spinner = ora("Initializing global state").start();
3185
6187
  const { client, provider } = useContext();
3186
6188
  try {
3187
- const state = await client.getGlobalState();
6189
+ const authority = opts.authority ? new import_web33.PublicKey(opts.authority) : provider.wallet.publicKey;
6190
+ const tx = await client.globalInitialize({ authority });
6191
+ spinner.succeed("Global state initialized");
6192
+ log.json({
6193
+ transaction: tx,
6194
+ authority: authority.toString()
6195
+ });
6196
+ } catch (error2) {
6197
+ spinner.fail("Failed to initialize global state");
6198
+ log.error(String(error2));
6199
+ process.exit(1);
6200
+ }
6201
+ });
6202
+ var bond = import_commander.program.command("bond").description("Manage bond projects");
6203
+ bond.command("init <name>").description("Initialize a new bond project").option("-r, --reserve <address>", "Reserve vault address (defaults to signer)").option("-c, --collateral <type>", "Collateral type: native | token:<mint> | stakeAccount", "native").option("-a, --authority <pubkey>", "Withdraw authority (defaults to signer)").action(async (name, opts) => {
6204
+ const spinner = ora("Initializing bond").start();
6205
+ const { client, keypair } = useContext();
6206
+ try {
6207
+ const reserve = opts.reserve ? new import_web33.PublicKey(opts.reserve) : keypair.publicKey;
6208
+ const authority = opts.authority ? new import_web33.PublicKey(opts.authority) : void 0;
6209
+ const bondType = parseBondType(import_commander.program.opts().bondType);
6210
+ const collateralType = parseCollateralType(opts.collateral);
6211
+ await client.bondInitialize({ bondType, name, authority, collateralType, reserve });
6212
+ spinner.succeed("Bond initialized");
6213
+ log.json({
6214
+ name,
6215
+ reserve: reserve.toString(),
6216
+ collateral: opts.collateral
6217
+ });
6218
+ } catch (error2) {
6219
+ spinner.fail("Failed to initialize bond");
6220
+ log.error(String(error2));
6221
+ process.exit(1);
6222
+ }
6223
+ });
6224
+ bond.command("config").description("Update bond configuration").option("-a, --authority <pubkey>", "New authority address").option("-r, --reserve <pubkey>", "New reserve address").action(async (opts) => {
6225
+ const spinner = ora("Updating bond configuration").start();
6226
+ const { client } = useContext();
6227
+ const bondType = parseBondType(import_commander.program.opts().bondType);
6228
+ const bondName = getBondName();
6229
+ try {
6230
+ if (!opts.authority && !opts.reserve) {
6231
+ throw new Error("Must provide --authority or --reserve (or both)");
6232
+ }
6233
+ const newAuthority = opts.authority ? new import_web33.PublicKey(opts.authority) : void 0;
6234
+ const newReserve = opts.reserve ? new import_web33.PublicKey(opts.reserve) : void 0;
6235
+ const tx = await client.bondConfigure({
6236
+ bondType,
6237
+ name: bondName,
6238
+ newAuthority,
6239
+ newReserve
6240
+ });
6241
+ spinner.succeed("Bond configuration updated");
6242
+ const details = {};
6243
+ if (newAuthority) {
6244
+ details.authority = newAuthority.toString();
6245
+ }
6246
+ if (newReserve) {
6247
+ details.reserve = newReserve.toString();
6248
+ }
6249
+ details.transaction = tx;
6250
+ log.json(details);
6251
+ } catch (error2) {
6252
+ spinner.fail("Failed to update bond configuration");
6253
+ log.error(String(error2));
6254
+ process.exit(1);
6255
+ }
6256
+ });
6257
+ bond.command("info").description("Show bond state information").action(async () => {
6258
+ const { client } = useContext();
6259
+ const bondType = parseBondType(import_commander.program.opts().bondType);
6260
+ const bondName = getBondName();
6261
+ try {
6262
+ const state = await client.getBondState(bondType, bondName);
3188
6263
  if (!state) {
3189
- console.log(source_default.yellow("Global state not initialized"));
6264
+ log.warn("Bond state not found");
6265
+ return;
6266
+ }
6267
+ log.header("Bond State Information");
6268
+ log.json(state);
6269
+ } catch (error2) {
6270
+ log.error(`Failed to get bond state: ${error2}`);
6271
+ process.exit(1);
6272
+ }
6273
+ });
6274
+ bond.command("list").description("List all bond states").action(async () => {
6275
+ const { client } = useContext();
6276
+ const bondType = parseBondType(import_commander.program.opts().bondType);
6277
+ try {
6278
+ const states = await client.getAllBondStates(bondType);
6279
+ if (states.length === 0) {
6280
+ log.warn("No bond states found");
3190
6281
  return;
3191
6282
  }
3192
- console.log(source_default.cyan("Global State Information:"));
3193
- console.log(source_default.white(` Authority: ${state.authority}`));
3194
- console.log(source_default.white(` Reserve: ${state.reserve}`));
3195
- console.log(source_default.white(` Total Validators: ${state.totalValidators}`));
3196
- console.log(source_default.white(` Total Compensation Amount: ${state.totalCompensationAmount.toString()}`));
3197
- const epochInfo = await provider.connection.getEpochInfo();
3198
- console.log(source_default.white(` Current Epoch: ${epochInfo.epoch}`));
6283
+ log.header(`Found ${states.length} bond state(s)
6284
+ `);
6285
+ states.forEach((state, index) => {
6286
+ log.info(`Bond ${index + 1}:`);
6287
+ log.json(state);
6288
+ console.log("");
6289
+ });
3199
6290
  } catch (error2) {
3200
- console.error(source_default.red(`Failed to get global state info: ${error2}`));
6291
+ log.error(`Failed to list bond states: ${error2}`);
3201
6292
  process.exit(1);
3202
6293
  }
3203
6294
  });
3204
- import_commander.program.command("initialize").description("Initialize the global state and reserve vault").requiredOption("-r, --reserve <address>", "Reserve vault address").option("-w, --claim-authority <pubkey>", "Claim authority (defaults to signer)").action(async (opts) => {
3205
- const spinner = ora("Initializing global state...").start();
6295
+ bond.command("collateral-type").description("Show bond collateral type").action(async () => {
3206
6296
  const { client } = useContext();
3207
- const reserve = new import_web32.PublicKey(opts.reserve);
3208
- const authority = opts.claimAuthority ? new import_web32.PublicKey(opts.claimAuthority) : void 0;
6297
+ const bondType = parseBondType(import_commander.program.opts().bondType);
6298
+ const bondName = getBondName();
3209
6299
  try {
3210
- const tx = await client.initialize({ reserve, authority });
3211
- spinner.succeed(source_default.green(`Bond program initialized successfully!`));
3212
- console.log(source_default.gray(`Transaction: ${tx}`));
3213
- console.log(source_default.gray(`Reserve address: ${reserve.toString()}`));
6300
+ const collateralType = await client.getBondCollateralType(bondType, bondName);
6301
+ log.header("Collateral Type:");
6302
+ log.json(collateralType);
3214
6303
  } catch (error2) {
3215
- spinner.fail(source_default.red(`Failed to initialize bond program: ${error2}`));
6304
+ log.error(`Failed to get collateral type: ${error2}`);
6305
+ process.exit(1);
3216
6306
  }
3217
6307
  });
3218
- import_commander.program.command("register-validator").description("Register validator and fund initial collateral").argument("<vote-account>", "Vote account public key").argument("<amount>", "Initial collateral amount in SOL").action(async (voteAccountStr, amount) => {
3219
- const spinner = ora("Registering validator...").start();
6308
+ var validator = import_commander.program.command("validator").description("Manage validator bonds");
6309
+ validator.command("register <vote>").description("Register validator and create bond account").action(async (vote) => {
6310
+ const spinner = ora("Registering validator").start();
3220
6311
  const { keypair, client } = useContext();
6312
+ const bondType = parseBondType(import_commander.program.opts().bondType);
6313
+ const bondName = getBondName();
3221
6314
  try {
3222
- const voteAccount = new import_web32.PublicKey(voteAccountStr);
3223
- const initialCollateral = Number.parseFloat(amount);
3224
- if (Number.isNaN(initialCollateral) || initialCollateral <= 0) {
3225
- throw new Error("Invalid collateral amount");
3226
- }
3227
- const tx = await client.registerValidator({
6315
+ const voteAccount = new import_web33.PublicKey(vote);
6316
+ await client.registerValidator({
6317
+ bondType,
6318
+ name: bondName,
3228
6319
  voteAccount,
3229
- initialCollateral,
3230
6320
  identity: keypair.publicKey
3231
6321
  });
3232
- spinner.succeed(source_default.green(`Validator registered successfully!`));
3233
- console.log(source_default.gray(`Transaction: ${tx}`));
3234
- console.log(source_default.gray(`Initial collateral: ${initialCollateral} SOL`));
3235
- console.log(source_default.gray(`Validator: ${keypair.publicKey.toString()}`));
3236
- console.log(source_default.gray(`Vote Account: ${voteAccountStr}`));
6322
+ spinner.succeed("Validator registered");
6323
+ log.json({
6324
+ validator: keypair.publicKey.toString(),
6325
+ voteAccount: vote
6326
+ });
3237
6327
  } catch (error2) {
3238
- spinner.fail(source_default.red(`Failed to register validator: ${error2}`));
6328
+ spinner.fail("Failed to register validator");
6329
+ log.error(String(error2));
6330
+ process.exit(1);
3239
6331
  }
3240
6332
  });
3241
- import_commander.program.command("topup-collateral").description("Top up collateral for existing validator").argument("<vote-account>", "Vote account public key").argument("<amount>", "Amount to top up in SOL").action(async (voteAccountStr, amount) => {
3242
- const spinner = ora("Topping up collateral...").start();
3243
- const { client } = useContext();
6333
+ validator.command("topup <vote> <amount>").description("Add collateral to validator bond account").action(async (vote, amount) => {
6334
+ const spinner = ora("Adding collateral").start();
6335
+ const { client, keypair } = useContext();
6336
+ const bondType = parseBondType(import_commander.program.opts().bondType);
6337
+ const bondName = getBondName();
3244
6338
  try {
3245
- const voteAccount = new import_web32.PublicKey(voteAccountStr);
6339
+ const voteAccount = new import_web33.PublicKey(vote);
3246
6340
  const topUpAmount = Number.parseFloat(amount);
3247
6341
  if (Number.isNaN(topUpAmount) || topUpAmount <= 0) {
3248
- throw new Error("Invalid top-up amount");
6342
+ throw new Error("Invalid amount: must be positive number");
3249
6343
  }
3250
- const signature = await client.topUpCollateral({ voteAccount, amount: topUpAmount });
3251
- spinner.succeed(source_default.green(`Collateral topped up successfully!`));
3252
- console.log(source_default.gray(`Signature: ${signature}`));
3253
- console.log(source_default.gray(`Top-up amount: ${topUpAmount} SOL`));
6344
+ const signature = await client.topUpCollateral({
6345
+ bondType,
6346
+ name: bondName,
6347
+ identity: keypair.publicKey,
6348
+ voteAccount,
6349
+ collateral: { amount: topUpAmount }
6350
+ });
6351
+ spinner.succeed("Collateral added");
6352
+ log.json({
6353
+ amount: `${topUpAmount} SOL`,
6354
+ transaction: signature
6355
+ });
3254
6356
  } catch (error2) {
3255
- spinner.fail(source_default.red(`Failed to top up collateral: ${error2}`));
6357
+ spinner.fail("Failed to add collateral");
6358
+ log.error(String(error2));
3256
6359
  process.exit(1);
3257
6360
  }
3258
6361
  });
3259
- import_commander.program.command("withdraw-collateral").description("Withdraw collateral from validator bond account").argument("<vote-account>", "Vote account public key").argument("<destination>", "Destination address for withdrawn funds").argument("<amount>", "Amount to withdraw in SOL").action(async (voteAccountStr, destinationStr, amount) => {
3260
- const spinner = ora("Withdrawing collateral...").start();
6362
+ validator.command("withdraw <vote-account> <amount> <destination>").description("Withdraw collateral from validator bond account").action(async (voteAccountStr, amount, destinationStr) => {
6363
+ const spinner = ora("Withdrawing collateral").start();
3261
6364
  const { client } = useContext();
6365
+ const bondType = parseBondType(import_commander.program.opts().bondType);
6366
+ const bondName = getBondName();
3262
6367
  try {
3263
- const voteAccount = new import_web32.PublicKey(voteAccountStr);
3264
- const destination = new import_web32.PublicKey(destinationStr);
6368
+ const voteAccount = new import_web33.PublicKey(voteAccountStr);
6369
+ const destination = new import_web33.PublicKey(destinationStr);
3265
6370
  const withdrawAmount = Number.parseFloat(amount);
3266
6371
  if (Number.isNaN(withdrawAmount) || withdrawAmount <= 0) {
3267
- throw new Error("Invalid withdrawal amount");
6372
+ throw new Error("Invalid amount: must be positive number");
3268
6373
  }
3269
- const bondAccount = await client.getValidatorBond(voteAccount);
3270
- if (!bondAccount) {
6374
+ const bond2 = await client.getValidatorBond(bondType, bondName, voteAccount);
6375
+ if (!bond2) {
3271
6376
  throw new Error("Validator bond account not found");
3272
6377
  }
3273
- const tx = await client.withdrawCollateral({ voteAccount, destination, amount: withdrawAmount });
3274
- spinner.succeed(source_default.green(`Collateral withdrawn successfully!`));
3275
- console.log(source_default.gray(`Transaction: ${tx}`));
3276
- console.log(source_default.gray(`Amount withdrawn: ${withdrawAmount} SOL`));
3277
- console.log(source_default.gray(`Destination: ${destinationStr}`));
6378
+ const tx = await client.withdrawCollateral({
6379
+ bondType,
6380
+ name: bondName,
6381
+ voteAccount,
6382
+ destination,
6383
+ withdraw: { amount: withdrawAmount }
6384
+ });
6385
+ spinner.succeed("Collateral withdrawn");
6386
+ log.json({
6387
+ amount: `${withdrawAmount} SOL`,
6388
+ destination: destinationStr,
6389
+ transaction: tx
6390
+ });
3278
6391
  } catch (error2) {
3279
- spinner.fail(source_default.red(`Failed to withdraw collateral: ${error2}`));
6392
+ spinner.fail("Failed to withdraw collateral");
6393
+ log.error(String(error2));
3280
6394
  process.exit(1);
3281
6395
  }
3282
6396
  });
3283
- import_commander.program.command("claim-compensation").description("Claim compensation from validator to reserve").argument("<vote-account>", "Vote account public key").argument("<amount>", "Amount to withdraw in SOL").action(async (voteAccountStr, amount) => {
3284
- const spinner = ora("Claiming compensation...").start();
6397
+ validator.command("claim <vote> <amount>").description("Claim collateral from validator to reserve").action(async (vote, amount) => {
6398
+ const spinner = ora("Claiming collateral").start();
3285
6399
  const { client } = useContext();
6400
+ const bondType = parseBondType(import_commander.program.opts().bondType);
6401
+ const bondName = getBondName();
3286
6402
  try {
3287
- const voteAccount = new import_web32.PublicKey(voteAccountStr);
3288
- const withdrawAmount = Number.parseFloat(amount);
3289
- if (Number.isNaN(withdrawAmount) || withdrawAmount <= 0) {
3290
- throw new Error("Invalid withdrawal amount");
6403
+ const voteAccount = new import_web33.PublicKey(vote);
6404
+ const claimAmount = Number.parseFloat(amount);
6405
+ if (Number.isNaN(claimAmount) || claimAmount <= 0) {
6406
+ throw new Error("Invalid amount: must be positive number");
3291
6407
  }
3292
6408
  const tx = await client.claimCompensation({
6409
+ bondType,
6410
+ name: bondName,
3293
6411
  voteAccount,
3294
- amount: withdrawAmount
6412
+ claim: { amount: claimAmount }
6413
+ });
6414
+ spinner.succeed("Collateral claimed");
6415
+ log.json({
6416
+ amount: `${claimAmount} SOL`,
6417
+ transaction: tx
3295
6418
  });
3296
- spinner.succeed(source_default.green(`Compensation withdrawn successfully!`));
3297
- console.log(source_default.gray(`Transaction: ${tx}`));
3298
- console.log(source_default.gray(`Amount: ${withdrawAmount} SOL`));
3299
6419
  } catch (error2) {
3300
- spinner.fail(source_default.red(`Failed to withdraw compensation: ${error2}`));
6420
+ spinner.fail("Failed to claim collateral");
6421
+ log.error(String(error2));
3301
6422
  process.exit(1);
3302
6423
  }
3303
6424
  });
3304
- import_commander.program.command("validator-info").description("Get validator bond account information").argument("<vote-account>", "Vote account public key").option("-v, --validator <pubkey>", "Validator public key (optional, defaults to current keypair)").action(async (voteAccountStr) => {
6425
+ validator.command("info <vote>").description("Show validator bond account information").action(async (vote) => {
3305
6426
  const { client } = useContext();
6427
+ const bondType = parseBondType(import_commander.program.opts().bondType);
6428
+ const bondName = getBondName();
3306
6429
  try {
3307
- const voteAccount = new import_web32.PublicKey(voteAccountStr);
3308
- const [validatorBondAddress] = client.pda.validatorBond(voteAccount);
3309
- console.log(source_default.gray(`Validator Bond Address: ${validatorBondAddress.toString()}`));
3310
- const state = await client.getValidatorBond(
3311
- voteAccount
3312
- );
3313
- if (!state) {
3314
- console.log(source_default.yellow("Validator bond account not found"));
6430
+ const voteAccount = new import_web33.PublicKey(vote);
6431
+ const [bondAddress] = client.pda.validatorBond(bondType, bondName, voteAccount);
6432
+ const bond2 = await client.getValidatorBond(bondType, bondName, voteAccount);
6433
+ const balance = await client.getValidatorBondBalance(bondType, bondName, voteAccount);
6434
+ if (!bond2) {
6435
+ log.warn("Validator bond account not found");
3315
6436
  return;
3316
6437
  }
3317
- console.log(source_default.cyan("\nValidator Bond Account Information:"));
3318
- console.log(source_default.white(` Validator: ${state.identity}`));
3319
- console.log(source_default.white(` Vote Account: ${state.voteAccount}`));
3320
- if (state.withdrawalAuthority) {
3321
- console.log(source_default.white(` Withdrawal Authority: ${state.withdrawalAuthority}`));
3322
- } else {
3323
- console.log(source_default.white(` Withdrawal Authority: Not set (identity only)`));
3324
- }
3325
- console.log(
3326
- source_default.white(
3327
- ` Active: ${state.isActive ? source_default.green("Yes") : source_default.red("No")}`
3328
- )
3329
- );
3330
- console.log(source_default.white(` Created At: ${state.createdAt}`));
6438
+ log.header("Validator Bond Information");
6439
+ log.json({
6440
+ address: bondAddress.toString(),
6441
+ validator: bond2.identity,
6442
+ voteAccount: bond2.voteAccount,
6443
+ balance: `${lamportsToSol(balance)} SOL`,
6444
+ authority: bond2.withdrawalAuthority || "identity only",
6445
+ createdAt: bond2.createdAt,
6446
+ creator: bond2.creator
6447
+ });
3331
6448
  } catch (error2) {
3332
- console.error(source_default.red(`Failed to get validator info: ${error2}`));
6449
+ log.error(`Failed to get validator info: ${error2}`);
3333
6450
  process.exit(1);
3334
6451
  }
3335
6452
  });
3336
- import_commander.program.command("set-withdraw-authority").description("Set or update withdrawal authority for validator bond").argument("<vote-account>", "Vote account public key").option("-w, --new-authority <pubkey>", "New withdrawal authority (omit to remove authority)").action(async (voteAccountStr, options) => {
3337
- const spinner = ora("Setting withdrawal authority...").start();
6453
+ validator.command("set-authority <vote>").description("Set withdrawal authority for validator bond").option("-a, --authority <pubkey>", "New withdrawal authority (omit to remove)").action(async (vote, opts) => {
6454
+ const spinner = ora("Setting withdrawal authority").start();
3338
6455
  const { client, keypair } = useContext();
6456
+ const bondType = parseBondType(import_commander.program.opts().bondType);
6457
+ const bondName = getBondName();
3339
6458
  try {
3340
- const voteAccount = new import_web32.PublicKey(voteAccountStr);
3341
- const bondAccount = await client.getValidatorBond(voteAccount);
3342
- if (!bondAccount) {
6459
+ const voteAccount = new import_web33.PublicKey(vote);
6460
+ const bond2 = await client.getValidatorBond(bondType, bondName, voteAccount);
6461
+ if (!bond2) {
3343
6462
  throw new Error("Validator bond account not found");
3344
6463
  }
3345
- if (!bondAccount.identity.equals(keypair.publicKey)) {
6464
+ if (!bond2.identity.equals(keypair.publicKey)) {
3346
6465
  throw new Error("Signer must be the validator identity");
3347
6466
  }
3348
- const newWithdrawAuthority = options.newAuthority ? new import_web32.PublicKey(options.newAuthority) : null;
6467
+ const newAuthority = opts.authority ? new import_web33.PublicKey(opts.authority) : null;
3349
6468
  const tx = await client.setWithdrawAuthority({
6469
+ bondType,
6470
+ name: bondName,
3350
6471
  voteAccount,
3351
- newWithdrawAuthority
6472
+ newWithdrawAuthority: newAuthority
3352
6473
  });
3353
- spinner.succeed(source_default.green(`Withdrawal authority updated successfully!`));
3354
- console.log(source_default.gray(`Transaction: ${tx}`));
3355
- if (newWithdrawAuthority) {
3356
- console.log(source_default.gray(`New withdrawal authority: ${newWithdrawAuthority.toString()}`));
3357
- } else {
3358
- console.log(source_default.gray(`Withdrawal authority removed (identity only)`));
3359
- }
6474
+ spinner.succeed("Withdrawal authority updated");
6475
+ log.json({
6476
+ authority: newAuthority?.toString() || "removed (identity only)",
6477
+ transaction: tx
6478
+ });
6479
+ } catch (error2) {
6480
+ spinner.fail("Failed to set withdrawal authority");
6481
+ log.error(String(error2));
6482
+ process.exit(1);
6483
+ }
6484
+ });
6485
+ validator.command("history <vote>").description("Show transaction history for validator").option("-l, --limit <number>", "Number of records", "10").action(async (vote, opts) => {
6486
+ const { client } = useContext();
6487
+ const bondType = parseBondType(import_commander.program.opts().bondType);
6488
+ const bondName = getBondName();
6489
+ const limit = Number.parseInt(opts.limit, 10);
6490
+ const voteAccount = new import_web33.PublicKey(vote);
6491
+ const cluster = import_commander.program.opts().cluster || "mainnet-beta";
6492
+ try {
6493
+ const history = await client.getHistory(bondType, bondName, voteAccount, { limit, cluster });
6494
+ log.header(`Transaction History (limit: ${limit})`);
6495
+ log.json(history);
3360
6496
  } catch (error2) {
3361
- spinner.fail(source_default.red(`Failed to set withdrawal authority: ${error2}`));
6497
+ log.error(`Failed to get transaction history: ${error2}`);
3362
6498
  process.exit(1);
3363
6499
  }
3364
6500
  });
3365
- import_commander.program.command("configure").description("Update program configuration (authority and/or reserve)").option("-a, --new-authority <pubkey>", "New authority address").option("-r, --new-reserve <pubkey>", "New reserve address").action(async (opts) => {
3366
- const spinner = ora("Updating program configuration...").start();
6501
+ var session = import_commander.program.command("session").description("Manage bond sessions");
6502
+ session.command("start <duration>").description("Start a bond session").action(async (duration) => {
6503
+ const spinner = ora("Starting bond session").start();
3367
6504
  const { client } = useContext();
6505
+ const bondType = parseBondType(import_commander.program.opts().bondType);
6506
+ const bondName = getBondName();
3368
6507
  try {
3369
- if (!opts.newAuthority && !opts.newReserve) {
3370
- throw new Error("At least one of --new-authority or --new-reserve must be provided");
6508
+ if (Number.isNaN(duration) || duration <= 0) {
6509
+ throw new Error("Invalid duration: must be positive number");
3371
6510
  }
3372
- const newAuthority = opts.newAuthority ? new import_web32.PublicKey(opts.newAuthority) : void 0;
3373
- const newReserve = opts.newReserve ? new import_web32.PublicKey(opts.newReserve) : void 0;
3374
- const tx = await client.configure({
3375
- newAuthority,
3376
- newReserve
6511
+ const tx = await client.bondStart({ bondType, name: bondName, duration_secs: duration });
6512
+ spinner.succeed("Bond session started");
6513
+ log.json({
6514
+ duration: `${duration} seconds`,
6515
+ transaction: tx
3377
6516
  });
3378
- spinner.succeed(source_default.green(`Program configuration updated successfully!`));
3379
- console.log(source_default.gray(`Transaction: ${tx}`));
3380
- if (newAuthority) {
3381
- console.log(source_default.gray(`New authority: ${newAuthority.toString()}`));
3382
- }
3383
- if (newReserve) {
3384
- console.log(source_default.gray(`New reserve: ${newReserve.toString()}`));
3385
- }
3386
6517
  } catch (error2) {
3387
- spinner.fail(source_default.red(`Failed to update configuration: ${error2}`));
6518
+ spinner.fail("Failed to start bond session");
6519
+ log.error(String(error2));
3388
6520
  process.exit(1);
3389
6521
  }
3390
6522
  });
3391
- import_commander.program.command("*", { isDefault: true, hidden: true }).allowExcessArguments(true).action(() => {
3392
- import_commander.program.help();
6523
+ session.command("finish").description("Finish current bond session").action(async () => {
6524
+ const spinner = ora("Finishing bond session").start();
6525
+ const { client } = useContext();
6526
+ const bondType = parseBondType(import_commander.program.opts().bondType);
6527
+ const bondName = getBondName();
6528
+ try {
6529
+ const transaction = await client.bondFinish({ bondType, name: bondName });
6530
+ spinner.succeed("Bond session finished");
6531
+ log.json({ transaction });
6532
+ } catch (error2) {
6533
+ spinner.fail("Failed to finish bond session");
6534
+ log.error(String(error2));
6535
+ process.exit(1);
6536
+ }
3393
6537
  });
6538
+ import_commander.program.command("*", { isDefault: true, hidden: true }).allowExcessArguments(true).action(() => import_commander.program.help());
3394
6539
  import_commander.program.parseAsync().catch((e) => {
3395
- console.log(source_default.red(e.message));
6540
+ log.error(`
6541
+ ${e.message}`);
3396
6542
  if (e.logs) {
3397
- console.log(
3398
- source_default.red(JSON.stringify(e.logs, null, 2))
3399
- );
6543
+ log.json(e.logs, "red");
3400
6544
  }
3401
- process.exit();
6545
+ process.exit(1);
3402
6546
  });
6547
+ function getBondName() {
6548
+ const bond2 = import_commander.program.opts().bond;
6549
+ if (!bond2) {
6550
+ throw new Error("Bond is required. Use -b <name>");
6551
+ }
6552
+ return bond2;
6553
+ }