@vultisig/cli 0.2.0-alpha.5 → 0.2.0-alpha.7

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.
package/dist/index.js CHANGED
@@ -1,10 +1,1105 @@
1
1
  #!/usr/bin/env node
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
2
8
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
9
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
10
  }) : x)(function(x) {
5
11
  if (typeof require !== "undefined") return require.apply(this, arguments);
6
12
  throw Error('Dynamic require of "' + x + '" is not supported');
7
13
  });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+
34
+ // ../../node_modules/qrcode-terminal/vendor/QRCode/QRMode.js
35
+ var require_QRMode = __commonJS({
36
+ "../../node_modules/qrcode-terminal/vendor/QRCode/QRMode.js"(exports, module) {
37
+ module.exports = {
38
+ MODE_NUMBER: 1 << 0,
39
+ MODE_ALPHA_NUM: 1 << 1,
40
+ MODE_8BIT_BYTE: 1 << 2,
41
+ MODE_KANJI: 1 << 3
42
+ };
43
+ }
44
+ });
45
+
46
+ // ../../node_modules/qrcode-terminal/vendor/QRCode/QR8bitByte.js
47
+ var require_QR8bitByte = __commonJS({
48
+ "../../node_modules/qrcode-terminal/vendor/QRCode/QR8bitByte.js"(exports, module) {
49
+ var QRMode = require_QRMode();
50
+ function QR8bitByte(data) {
51
+ this.mode = QRMode.MODE_8BIT_BYTE;
52
+ this.data = data;
53
+ }
54
+ QR8bitByte.prototype = {
55
+ getLength: function() {
56
+ return this.data.length;
57
+ },
58
+ write: function(buffer) {
59
+ for (var i = 0; i < this.data.length; i++) {
60
+ buffer.put(this.data.charCodeAt(i), 8);
61
+ }
62
+ }
63
+ };
64
+ module.exports = QR8bitByte;
65
+ }
66
+ });
67
+
68
+ // ../../node_modules/qrcode-terminal/vendor/QRCode/QRMath.js
69
+ var require_QRMath = __commonJS({
70
+ "../../node_modules/qrcode-terminal/vendor/QRCode/QRMath.js"(exports, module) {
71
+ var QRMath = {
72
+ glog: function(n) {
73
+ if (n < 1) {
74
+ throw new Error("glog(" + n + ")");
75
+ }
76
+ return QRMath.LOG_TABLE[n];
77
+ },
78
+ gexp: function(n) {
79
+ while (n < 0) {
80
+ n += 255;
81
+ }
82
+ while (n >= 256) {
83
+ n -= 255;
84
+ }
85
+ return QRMath.EXP_TABLE[n];
86
+ },
87
+ EXP_TABLE: new Array(256),
88
+ LOG_TABLE: new Array(256)
89
+ };
90
+ for (i = 0; i < 8; i++) {
91
+ QRMath.EXP_TABLE[i] = 1 << i;
92
+ }
93
+ var i;
94
+ for (i = 8; i < 256; i++) {
95
+ QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] ^ QRMath.EXP_TABLE[i - 5] ^ QRMath.EXP_TABLE[i - 6] ^ QRMath.EXP_TABLE[i - 8];
96
+ }
97
+ var i;
98
+ for (i = 0; i < 255; i++) {
99
+ QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i;
100
+ }
101
+ var i;
102
+ module.exports = QRMath;
103
+ }
104
+ });
105
+
106
+ // ../../node_modules/qrcode-terminal/vendor/QRCode/QRPolynomial.js
107
+ var require_QRPolynomial = __commonJS({
108
+ "../../node_modules/qrcode-terminal/vendor/QRCode/QRPolynomial.js"(exports, module) {
109
+ var QRMath = require_QRMath();
110
+ function QRPolynomial(num, shift) {
111
+ if (num.length === void 0) {
112
+ throw new Error(num.length + "/" + shift);
113
+ }
114
+ var offset = 0;
115
+ while (offset < num.length && num[offset] === 0) {
116
+ offset++;
117
+ }
118
+ this.num = new Array(num.length - offset + shift);
119
+ for (var i = 0; i < num.length - offset; i++) {
120
+ this.num[i] = num[i + offset];
121
+ }
122
+ }
123
+ QRPolynomial.prototype = {
124
+ get: function(index) {
125
+ return this.num[index];
126
+ },
127
+ getLength: function() {
128
+ return this.num.length;
129
+ },
130
+ multiply: function(e) {
131
+ var num = new Array(this.getLength() + e.getLength() - 1);
132
+ for (var i = 0; i < this.getLength(); i++) {
133
+ for (var j = 0; j < e.getLength(); j++) {
134
+ num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i)) + QRMath.glog(e.get(j)));
135
+ }
136
+ }
137
+ return new QRPolynomial(num, 0);
138
+ },
139
+ mod: function(e) {
140
+ if (this.getLength() - e.getLength() < 0) {
141
+ return this;
142
+ }
143
+ var ratio = QRMath.glog(this.get(0)) - QRMath.glog(e.get(0));
144
+ var num = new Array(this.getLength());
145
+ for (var i = 0; i < this.getLength(); i++) {
146
+ num[i] = this.get(i);
147
+ }
148
+ for (var x = 0; x < e.getLength(); x++) {
149
+ num[x] ^= QRMath.gexp(QRMath.glog(e.get(x)) + ratio);
150
+ }
151
+ return new QRPolynomial(num, 0).mod(e);
152
+ }
153
+ };
154
+ module.exports = QRPolynomial;
155
+ }
156
+ });
157
+
158
+ // ../../node_modules/qrcode-terminal/vendor/QRCode/QRMaskPattern.js
159
+ var require_QRMaskPattern = __commonJS({
160
+ "../../node_modules/qrcode-terminal/vendor/QRCode/QRMaskPattern.js"(exports, module) {
161
+ module.exports = {
162
+ PATTERN000: 0,
163
+ PATTERN001: 1,
164
+ PATTERN010: 2,
165
+ PATTERN011: 3,
166
+ PATTERN100: 4,
167
+ PATTERN101: 5,
168
+ PATTERN110: 6,
169
+ PATTERN111: 7
170
+ };
171
+ }
172
+ });
173
+
174
+ // ../../node_modules/qrcode-terminal/vendor/QRCode/QRUtil.js
175
+ var require_QRUtil = __commonJS({
176
+ "../../node_modules/qrcode-terminal/vendor/QRCode/QRUtil.js"(exports, module) {
177
+ var QRMode = require_QRMode();
178
+ var QRPolynomial = require_QRPolynomial();
179
+ var QRMath = require_QRMath();
180
+ var QRMaskPattern = require_QRMaskPattern();
181
+ var QRUtil = {
182
+ PATTERN_POSITION_TABLE: [
183
+ [],
184
+ [6, 18],
185
+ [6, 22],
186
+ [6, 26],
187
+ [6, 30],
188
+ [6, 34],
189
+ [6, 22, 38],
190
+ [6, 24, 42],
191
+ [6, 26, 46],
192
+ [6, 28, 50],
193
+ [6, 30, 54],
194
+ [6, 32, 58],
195
+ [6, 34, 62],
196
+ [6, 26, 46, 66],
197
+ [6, 26, 48, 70],
198
+ [6, 26, 50, 74],
199
+ [6, 30, 54, 78],
200
+ [6, 30, 56, 82],
201
+ [6, 30, 58, 86],
202
+ [6, 34, 62, 90],
203
+ [6, 28, 50, 72, 94],
204
+ [6, 26, 50, 74, 98],
205
+ [6, 30, 54, 78, 102],
206
+ [6, 28, 54, 80, 106],
207
+ [6, 32, 58, 84, 110],
208
+ [6, 30, 58, 86, 114],
209
+ [6, 34, 62, 90, 118],
210
+ [6, 26, 50, 74, 98, 122],
211
+ [6, 30, 54, 78, 102, 126],
212
+ [6, 26, 52, 78, 104, 130],
213
+ [6, 30, 56, 82, 108, 134],
214
+ [6, 34, 60, 86, 112, 138],
215
+ [6, 30, 58, 86, 114, 142],
216
+ [6, 34, 62, 90, 118, 146],
217
+ [6, 30, 54, 78, 102, 126, 150],
218
+ [6, 24, 50, 76, 102, 128, 154],
219
+ [6, 28, 54, 80, 106, 132, 158],
220
+ [6, 32, 58, 84, 110, 136, 162],
221
+ [6, 26, 54, 82, 110, 138, 166],
222
+ [6, 30, 58, 86, 114, 142, 170]
223
+ ],
224
+ G15: 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0,
225
+ G18: 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0,
226
+ G15_MASK: 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1,
227
+ getBCHTypeInfo: function(data) {
228
+ var d = data << 10;
229
+ while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {
230
+ d ^= QRUtil.G15 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15);
231
+ }
232
+ return (data << 10 | d) ^ QRUtil.G15_MASK;
233
+ },
234
+ getBCHTypeNumber: function(data) {
235
+ var d = data << 12;
236
+ while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {
237
+ d ^= QRUtil.G18 << QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18);
238
+ }
239
+ return data << 12 | d;
240
+ },
241
+ getBCHDigit: function(data) {
242
+ var digit = 0;
243
+ while (data !== 0) {
244
+ digit++;
245
+ data >>>= 1;
246
+ }
247
+ return digit;
248
+ },
249
+ getPatternPosition: function(typeNumber) {
250
+ return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1];
251
+ },
252
+ getMask: function(maskPattern, i, j) {
253
+ switch (maskPattern) {
254
+ case QRMaskPattern.PATTERN000:
255
+ return (i + j) % 2 === 0;
256
+ case QRMaskPattern.PATTERN001:
257
+ return i % 2 === 0;
258
+ case QRMaskPattern.PATTERN010:
259
+ return j % 3 === 0;
260
+ case QRMaskPattern.PATTERN011:
261
+ return (i + j) % 3 === 0;
262
+ case QRMaskPattern.PATTERN100:
263
+ return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
264
+ case QRMaskPattern.PATTERN101:
265
+ return i * j % 2 + i * j % 3 === 0;
266
+ case QRMaskPattern.PATTERN110:
267
+ return (i * j % 2 + i * j % 3) % 2 === 0;
268
+ case QRMaskPattern.PATTERN111:
269
+ return (i * j % 3 + (i + j) % 2) % 2 === 0;
270
+ default:
271
+ throw new Error("bad maskPattern:" + maskPattern);
272
+ }
273
+ },
274
+ getErrorCorrectPolynomial: function(errorCorrectLength) {
275
+ var a = new QRPolynomial([1], 0);
276
+ for (var i = 0; i < errorCorrectLength; i++) {
277
+ a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0));
278
+ }
279
+ return a;
280
+ },
281
+ getLengthInBits: function(mode, type) {
282
+ if (1 <= type && type < 10) {
283
+ switch (mode) {
284
+ case QRMode.MODE_NUMBER:
285
+ return 10;
286
+ case QRMode.MODE_ALPHA_NUM:
287
+ return 9;
288
+ case QRMode.MODE_8BIT_BYTE:
289
+ return 8;
290
+ case QRMode.MODE_KANJI:
291
+ return 8;
292
+ default:
293
+ throw new Error("mode:" + mode);
294
+ }
295
+ } else if (type < 27) {
296
+ switch (mode) {
297
+ case QRMode.MODE_NUMBER:
298
+ return 12;
299
+ case QRMode.MODE_ALPHA_NUM:
300
+ return 11;
301
+ case QRMode.MODE_8BIT_BYTE:
302
+ return 16;
303
+ case QRMode.MODE_KANJI:
304
+ return 10;
305
+ default:
306
+ throw new Error("mode:" + mode);
307
+ }
308
+ } else if (type < 41) {
309
+ switch (mode) {
310
+ case QRMode.MODE_NUMBER:
311
+ return 14;
312
+ case QRMode.MODE_ALPHA_NUM:
313
+ return 13;
314
+ case QRMode.MODE_8BIT_BYTE:
315
+ return 16;
316
+ case QRMode.MODE_KANJI:
317
+ return 12;
318
+ default:
319
+ throw new Error("mode:" + mode);
320
+ }
321
+ } else {
322
+ throw new Error("type:" + type);
323
+ }
324
+ },
325
+ getLostPoint: function(qrCode) {
326
+ var moduleCount = qrCode.getModuleCount();
327
+ var lostPoint = 0;
328
+ var row = 0;
329
+ var col = 0;
330
+ for (row = 0; row < moduleCount; row++) {
331
+ for (col = 0; col < moduleCount; col++) {
332
+ var sameCount = 0;
333
+ var dark = qrCode.isDark(row, col);
334
+ for (var r = -1; r <= 1; r++) {
335
+ if (row + r < 0 || moduleCount <= row + r) {
336
+ continue;
337
+ }
338
+ for (var c = -1; c <= 1; c++) {
339
+ if (col + c < 0 || moduleCount <= col + c) {
340
+ continue;
341
+ }
342
+ if (r === 0 && c === 0) {
343
+ continue;
344
+ }
345
+ if (dark === qrCode.isDark(row + r, col + c)) {
346
+ sameCount++;
347
+ }
348
+ }
349
+ }
350
+ if (sameCount > 5) {
351
+ lostPoint += 3 + sameCount - 5;
352
+ }
353
+ }
354
+ }
355
+ for (row = 0; row < moduleCount - 1; row++) {
356
+ for (col = 0; col < moduleCount - 1; col++) {
357
+ var count = 0;
358
+ if (qrCode.isDark(row, col)) count++;
359
+ if (qrCode.isDark(row + 1, col)) count++;
360
+ if (qrCode.isDark(row, col + 1)) count++;
361
+ if (qrCode.isDark(row + 1, col + 1)) count++;
362
+ if (count === 0 || count === 4) {
363
+ lostPoint += 3;
364
+ }
365
+ }
366
+ }
367
+ for (row = 0; row < moduleCount; row++) {
368
+ for (col = 0; col < moduleCount - 6; col++) {
369
+ if (qrCode.isDark(row, col) && !qrCode.isDark(row, col + 1) && qrCode.isDark(row, col + 2) && qrCode.isDark(row, col + 3) && qrCode.isDark(row, col + 4) && !qrCode.isDark(row, col + 5) && qrCode.isDark(row, col + 6)) {
370
+ lostPoint += 40;
371
+ }
372
+ }
373
+ }
374
+ for (col = 0; col < moduleCount; col++) {
375
+ for (row = 0; row < moduleCount - 6; row++) {
376
+ if (qrCode.isDark(row, col) && !qrCode.isDark(row + 1, col) && qrCode.isDark(row + 2, col) && qrCode.isDark(row + 3, col) && qrCode.isDark(row + 4, col) && !qrCode.isDark(row + 5, col) && qrCode.isDark(row + 6, col)) {
377
+ lostPoint += 40;
378
+ }
379
+ }
380
+ }
381
+ var darkCount = 0;
382
+ for (col = 0; col < moduleCount; col++) {
383
+ for (row = 0; row < moduleCount; row++) {
384
+ if (qrCode.isDark(row, col)) {
385
+ darkCount++;
386
+ }
387
+ }
388
+ }
389
+ var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5;
390
+ lostPoint += ratio * 10;
391
+ return lostPoint;
392
+ }
393
+ };
394
+ module.exports = QRUtil;
395
+ }
396
+ });
397
+
398
+ // ../../node_modules/qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js
399
+ var require_QRErrorCorrectLevel = __commonJS({
400
+ "../../node_modules/qrcode-terminal/vendor/QRCode/QRErrorCorrectLevel.js"(exports, module) {
401
+ module.exports = {
402
+ L: 1,
403
+ M: 0,
404
+ Q: 3,
405
+ H: 2
406
+ };
407
+ }
408
+ });
409
+
410
+ // ../../node_modules/qrcode-terminal/vendor/QRCode/QRRSBlock.js
411
+ var require_QRRSBlock = __commonJS({
412
+ "../../node_modules/qrcode-terminal/vendor/QRCode/QRRSBlock.js"(exports, module) {
413
+ var QRErrorCorrectLevel = require_QRErrorCorrectLevel();
414
+ function QRRSBlock(totalCount, dataCount) {
415
+ this.totalCount = totalCount;
416
+ this.dataCount = dataCount;
417
+ }
418
+ QRRSBlock.RS_BLOCK_TABLE = [
419
+ // L
420
+ // M
421
+ // Q
422
+ // H
423
+ // 1
424
+ [1, 26, 19],
425
+ [1, 26, 16],
426
+ [1, 26, 13],
427
+ [1, 26, 9],
428
+ // 2
429
+ [1, 44, 34],
430
+ [1, 44, 28],
431
+ [1, 44, 22],
432
+ [1, 44, 16],
433
+ // 3
434
+ [1, 70, 55],
435
+ [1, 70, 44],
436
+ [2, 35, 17],
437
+ [2, 35, 13],
438
+ // 4
439
+ [1, 100, 80],
440
+ [2, 50, 32],
441
+ [2, 50, 24],
442
+ [4, 25, 9],
443
+ // 5
444
+ [1, 134, 108],
445
+ [2, 67, 43],
446
+ [2, 33, 15, 2, 34, 16],
447
+ [2, 33, 11, 2, 34, 12],
448
+ // 6
449
+ [2, 86, 68],
450
+ [4, 43, 27],
451
+ [4, 43, 19],
452
+ [4, 43, 15],
453
+ // 7
454
+ [2, 98, 78],
455
+ [4, 49, 31],
456
+ [2, 32, 14, 4, 33, 15],
457
+ [4, 39, 13, 1, 40, 14],
458
+ // 8
459
+ [2, 121, 97],
460
+ [2, 60, 38, 2, 61, 39],
461
+ [4, 40, 18, 2, 41, 19],
462
+ [4, 40, 14, 2, 41, 15],
463
+ // 9
464
+ [2, 146, 116],
465
+ [3, 58, 36, 2, 59, 37],
466
+ [4, 36, 16, 4, 37, 17],
467
+ [4, 36, 12, 4, 37, 13],
468
+ // 10
469
+ [2, 86, 68, 2, 87, 69],
470
+ [4, 69, 43, 1, 70, 44],
471
+ [6, 43, 19, 2, 44, 20],
472
+ [6, 43, 15, 2, 44, 16],
473
+ // 11
474
+ [4, 101, 81],
475
+ [1, 80, 50, 4, 81, 51],
476
+ [4, 50, 22, 4, 51, 23],
477
+ [3, 36, 12, 8, 37, 13],
478
+ // 12
479
+ [2, 116, 92, 2, 117, 93],
480
+ [6, 58, 36, 2, 59, 37],
481
+ [4, 46, 20, 6, 47, 21],
482
+ [7, 42, 14, 4, 43, 15],
483
+ // 13
484
+ [4, 133, 107],
485
+ [8, 59, 37, 1, 60, 38],
486
+ [8, 44, 20, 4, 45, 21],
487
+ [12, 33, 11, 4, 34, 12],
488
+ // 14
489
+ [3, 145, 115, 1, 146, 116],
490
+ [4, 64, 40, 5, 65, 41],
491
+ [11, 36, 16, 5, 37, 17],
492
+ [11, 36, 12, 5, 37, 13],
493
+ // 15
494
+ [5, 109, 87, 1, 110, 88],
495
+ [5, 65, 41, 5, 66, 42],
496
+ [5, 54, 24, 7, 55, 25],
497
+ [11, 36, 12],
498
+ // 16
499
+ [5, 122, 98, 1, 123, 99],
500
+ [7, 73, 45, 3, 74, 46],
501
+ [15, 43, 19, 2, 44, 20],
502
+ [3, 45, 15, 13, 46, 16],
503
+ // 17
504
+ [1, 135, 107, 5, 136, 108],
505
+ [10, 74, 46, 1, 75, 47],
506
+ [1, 50, 22, 15, 51, 23],
507
+ [2, 42, 14, 17, 43, 15],
508
+ // 18
509
+ [5, 150, 120, 1, 151, 121],
510
+ [9, 69, 43, 4, 70, 44],
511
+ [17, 50, 22, 1, 51, 23],
512
+ [2, 42, 14, 19, 43, 15],
513
+ // 19
514
+ [3, 141, 113, 4, 142, 114],
515
+ [3, 70, 44, 11, 71, 45],
516
+ [17, 47, 21, 4, 48, 22],
517
+ [9, 39, 13, 16, 40, 14],
518
+ // 20
519
+ [3, 135, 107, 5, 136, 108],
520
+ [3, 67, 41, 13, 68, 42],
521
+ [15, 54, 24, 5, 55, 25],
522
+ [15, 43, 15, 10, 44, 16],
523
+ // 21
524
+ [4, 144, 116, 4, 145, 117],
525
+ [17, 68, 42],
526
+ [17, 50, 22, 6, 51, 23],
527
+ [19, 46, 16, 6, 47, 17],
528
+ // 22
529
+ [2, 139, 111, 7, 140, 112],
530
+ [17, 74, 46],
531
+ [7, 54, 24, 16, 55, 25],
532
+ [34, 37, 13],
533
+ // 23
534
+ [4, 151, 121, 5, 152, 122],
535
+ [4, 75, 47, 14, 76, 48],
536
+ [11, 54, 24, 14, 55, 25],
537
+ [16, 45, 15, 14, 46, 16],
538
+ // 24
539
+ [6, 147, 117, 4, 148, 118],
540
+ [6, 73, 45, 14, 74, 46],
541
+ [11, 54, 24, 16, 55, 25],
542
+ [30, 46, 16, 2, 47, 17],
543
+ // 25
544
+ [8, 132, 106, 4, 133, 107],
545
+ [8, 75, 47, 13, 76, 48],
546
+ [7, 54, 24, 22, 55, 25],
547
+ [22, 45, 15, 13, 46, 16],
548
+ // 26
549
+ [10, 142, 114, 2, 143, 115],
550
+ [19, 74, 46, 4, 75, 47],
551
+ [28, 50, 22, 6, 51, 23],
552
+ [33, 46, 16, 4, 47, 17],
553
+ // 27
554
+ [8, 152, 122, 4, 153, 123],
555
+ [22, 73, 45, 3, 74, 46],
556
+ [8, 53, 23, 26, 54, 24],
557
+ [12, 45, 15, 28, 46, 16],
558
+ // 28
559
+ [3, 147, 117, 10, 148, 118],
560
+ [3, 73, 45, 23, 74, 46],
561
+ [4, 54, 24, 31, 55, 25],
562
+ [11, 45, 15, 31, 46, 16],
563
+ // 29
564
+ [7, 146, 116, 7, 147, 117],
565
+ [21, 73, 45, 7, 74, 46],
566
+ [1, 53, 23, 37, 54, 24],
567
+ [19, 45, 15, 26, 46, 16],
568
+ // 30
569
+ [5, 145, 115, 10, 146, 116],
570
+ [19, 75, 47, 10, 76, 48],
571
+ [15, 54, 24, 25, 55, 25],
572
+ [23, 45, 15, 25, 46, 16],
573
+ // 31
574
+ [13, 145, 115, 3, 146, 116],
575
+ [2, 74, 46, 29, 75, 47],
576
+ [42, 54, 24, 1, 55, 25],
577
+ [23, 45, 15, 28, 46, 16],
578
+ // 32
579
+ [17, 145, 115],
580
+ [10, 74, 46, 23, 75, 47],
581
+ [10, 54, 24, 35, 55, 25],
582
+ [19, 45, 15, 35, 46, 16],
583
+ // 33
584
+ [17, 145, 115, 1, 146, 116],
585
+ [14, 74, 46, 21, 75, 47],
586
+ [29, 54, 24, 19, 55, 25],
587
+ [11, 45, 15, 46, 46, 16],
588
+ // 34
589
+ [13, 145, 115, 6, 146, 116],
590
+ [14, 74, 46, 23, 75, 47],
591
+ [44, 54, 24, 7, 55, 25],
592
+ [59, 46, 16, 1, 47, 17],
593
+ // 35
594
+ [12, 151, 121, 7, 152, 122],
595
+ [12, 75, 47, 26, 76, 48],
596
+ [39, 54, 24, 14, 55, 25],
597
+ [22, 45, 15, 41, 46, 16],
598
+ // 36
599
+ [6, 151, 121, 14, 152, 122],
600
+ [6, 75, 47, 34, 76, 48],
601
+ [46, 54, 24, 10, 55, 25],
602
+ [2, 45, 15, 64, 46, 16],
603
+ // 37
604
+ [17, 152, 122, 4, 153, 123],
605
+ [29, 74, 46, 14, 75, 47],
606
+ [49, 54, 24, 10, 55, 25],
607
+ [24, 45, 15, 46, 46, 16],
608
+ // 38
609
+ [4, 152, 122, 18, 153, 123],
610
+ [13, 74, 46, 32, 75, 47],
611
+ [48, 54, 24, 14, 55, 25],
612
+ [42, 45, 15, 32, 46, 16],
613
+ // 39
614
+ [20, 147, 117, 4, 148, 118],
615
+ [40, 75, 47, 7, 76, 48],
616
+ [43, 54, 24, 22, 55, 25],
617
+ [10, 45, 15, 67, 46, 16],
618
+ // 40
619
+ [19, 148, 118, 6, 149, 119],
620
+ [18, 75, 47, 31, 76, 48],
621
+ [34, 54, 24, 34, 55, 25],
622
+ [20, 45, 15, 61, 46, 16]
623
+ ];
624
+ QRRSBlock.getRSBlocks = function(typeNumber, errorCorrectLevel) {
625
+ var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel);
626
+ if (rsBlock === void 0) {
627
+ throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel);
628
+ }
629
+ var length = rsBlock.length / 3;
630
+ var list = [];
631
+ for (var i = 0; i < length; i++) {
632
+ var count = rsBlock[i * 3 + 0];
633
+ var totalCount = rsBlock[i * 3 + 1];
634
+ var dataCount = rsBlock[i * 3 + 2];
635
+ for (var j = 0; j < count; j++) {
636
+ list.push(new QRRSBlock(totalCount, dataCount));
637
+ }
638
+ }
639
+ return list;
640
+ };
641
+ QRRSBlock.getRsBlockTable = function(typeNumber, errorCorrectLevel) {
642
+ switch (errorCorrectLevel) {
643
+ case QRErrorCorrectLevel.L:
644
+ return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
645
+ case QRErrorCorrectLevel.M:
646
+ return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
647
+ case QRErrorCorrectLevel.Q:
648
+ return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
649
+ case QRErrorCorrectLevel.H:
650
+ return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
651
+ default:
652
+ return void 0;
653
+ }
654
+ };
655
+ module.exports = QRRSBlock;
656
+ }
657
+ });
658
+
659
+ // ../../node_modules/qrcode-terminal/vendor/QRCode/QRBitBuffer.js
660
+ var require_QRBitBuffer = __commonJS({
661
+ "../../node_modules/qrcode-terminal/vendor/QRCode/QRBitBuffer.js"(exports, module) {
662
+ function QRBitBuffer() {
663
+ this.buffer = [];
664
+ this.length = 0;
665
+ }
666
+ QRBitBuffer.prototype = {
667
+ get: function(index) {
668
+ var bufIndex = Math.floor(index / 8);
669
+ return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) == 1;
670
+ },
671
+ put: function(num, length) {
672
+ for (var i = 0; i < length; i++) {
673
+ this.putBit((num >>> length - i - 1 & 1) == 1);
674
+ }
675
+ },
676
+ getLengthInBits: function() {
677
+ return this.length;
678
+ },
679
+ putBit: function(bit) {
680
+ var bufIndex = Math.floor(this.length / 8);
681
+ if (this.buffer.length <= bufIndex) {
682
+ this.buffer.push(0);
683
+ }
684
+ if (bit) {
685
+ this.buffer[bufIndex] |= 128 >>> this.length % 8;
686
+ }
687
+ this.length++;
688
+ }
689
+ };
690
+ module.exports = QRBitBuffer;
691
+ }
692
+ });
693
+
694
+ // ../../node_modules/qrcode-terminal/vendor/QRCode/index.js
695
+ var require_QRCode = __commonJS({
696
+ "../../node_modules/qrcode-terminal/vendor/QRCode/index.js"(exports, module) {
697
+ var QR8bitByte = require_QR8bitByte();
698
+ var QRUtil = require_QRUtil();
699
+ var QRPolynomial = require_QRPolynomial();
700
+ var QRRSBlock = require_QRRSBlock();
701
+ var QRBitBuffer = require_QRBitBuffer();
702
+ function QRCode(typeNumber, errorCorrectLevel) {
703
+ this.typeNumber = typeNumber;
704
+ this.errorCorrectLevel = errorCorrectLevel;
705
+ this.modules = null;
706
+ this.moduleCount = 0;
707
+ this.dataCache = null;
708
+ this.dataList = [];
709
+ }
710
+ QRCode.prototype = {
711
+ addData: function(data) {
712
+ var newData = new QR8bitByte(data);
713
+ this.dataList.push(newData);
714
+ this.dataCache = null;
715
+ },
716
+ isDark: function(row, col) {
717
+ if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) {
718
+ throw new Error(row + "," + col);
719
+ }
720
+ return this.modules[row][col];
721
+ },
722
+ getModuleCount: function() {
723
+ return this.moduleCount;
724
+ },
725
+ make: function() {
726
+ if (this.typeNumber < 1) {
727
+ var typeNumber = 1;
728
+ for (typeNumber = 1; typeNumber < 40; typeNumber++) {
729
+ var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel);
730
+ var buffer = new QRBitBuffer();
731
+ var totalDataCount = 0;
732
+ for (var i = 0; i < rsBlocks.length; i++) {
733
+ totalDataCount += rsBlocks[i].dataCount;
734
+ }
735
+ for (var x = 0; x < this.dataList.length; x++) {
736
+ var data = this.dataList[x];
737
+ buffer.put(data.mode, 4);
738
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber));
739
+ data.write(buffer);
740
+ }
741
+ if (buffer.getLengthInBits() <= totalDataCount * 8)
742
+ break;
743
+ }
744
+ this.typeNumber = typeNumber;
745
+ }
746
+ this.makeImpl(false, this.getBestMaskPattern());
747
+ },
748
+ makeImpl: function(test, maskPattern) {
749
+ this.moduleCount = this.typeNumber * 4 + 17;
750
+ this.modules = new Array(this.moduleCount);
751
+ for (var row = 0; row < this.moduleCount; row++) {
752
+ this.modules[row] = new Array(this.moduleCount);
753
+ for (var col = 0; col < this.moduleCount; col++) {
754
+ this.modules[row][col] = null;
755
+ }
756
+ }
757
+ this.setupPositionProbePattern(0, 0);
758
+ this.setupPositionProbePattern(this.moduleCount - 7, 0);
759
+ this.setupPositionProbePattern(0, this.moduleCount - 7);
760
+ this.setupPositionAdjustPattern();
761
+ this.setupTimingPattern();
762
+ this.setupTypeInfo(test, maskPattern);
763
+ if (this.typeNumber >= 7) {
764
+ this.setupTypeNumber(test);
765
+ }
766
+ if (this.dataCache === null) {
767
+ this.dataCache = QRCode.createData(this.typeNumber, this.errorCorrectLevel, this.dataList);
768
+ }
769
+ this.mapData(this.dataCache, maskPattern);
770
+ },
771
+ setupPositionProbePattern: function(row, col) {
772
+ for (var r = -1; r <= 7; r++) {
773
+ if (row + r <= -1 || this.moduleCount <= row + r) continue;
774
+ for (var c = -1; c <= 7; c++) {
775
+ if (col + c <= -1 || this.moduleCount <= col + c) continue;
776
+ if (0 <= r && r <= 6 && (c === 0 || c === 6) || 0 <= c && c <= 6 && (r === 0 || r === 6) || 2 <= r && r <= 4 && 2 <= c && c <= 4) {
777
+ this.modules[row + r][col + c] = true;
778
+ } else {
779
+ this.modules[row + r][col + c] = false;
780
+ }
781
+ }
782
+ }
783
+ },
784
+ getBestMaskPattern: function() {
785
+ var minLostPoint = 0;
786
+ var pattern = 0;
787
+ for (var i = 0; i < 8; i++) {
788
+ this.makeImpl(true, i);
789
+ var lostPoint = QRUtil.getLostPoint(this);
790
+ if (i === 0 || minLostPoint > lostPoint) {
791
+ minLostPoint = lostPoint;
792
+ pattern = i;
793
+ }
794
+ }
795
+ return pattern;
796
+ },
797
+ createMovieClip: function(target_mc, instance_name, depth) {
798
+ var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth);
799
+ var cs = 1;
800
+ this.make();
801
+ for (var row = 0; row < this.modules.length; row++) {
802
+ var y = row * cs;
803
+ for (var col = 0; col < this.modules[row].length; col++) {
804
+ var x = col * cs;
805
+ var dark = this.modules[row][col];
806
+ if (dark) {
807
+ qr_mc.beginFill(0, 100);
808
+ qr_mc.moveTo(x, y);
809
+ qr_mc.lineTo(x + cs, y);
810
+ qr_mc.lineTo(x + cs, y + cs);
811
+ qr_mc.lineTo(x, y + cs);
812
+ qr_mc.endFill();
813
+ }
814
+ }
815
+ }
816
+ return qr_mc;
817
+ },
818
+ setupTimingPattern: function() {
819
+ for (var r = 8; r < this.moduleCount - 8; r++) {
820
+ if (this.modules[r][6] !== null) {
821
+ continue;
822
+ }
823
+ this.modules[r][6] = r % 2 === 0;
824
+ }
825
+ for (var c = 8; c < this.moduleCount - 8; c++) {
826
+ if (this.modules[6][c] !== null) {
827
+ continue;
828
+ }
829
+ this.modules[6][c] = c % 2 === 0;
830
+ }
831
+ },
832
+ setupPositionAdjustPattern: function() {
833
+ var pos = QRUtil.getPatternPosition(this.typeNumber);
834
+ for (var i = 0; i < pos.length; i++) {
835
+ for (var j = 0; j < pos.length; j++) {
836
+ var row = pos[i];
837
+ var col = pos[j];
838
+ if (this.modules[row][col] !== null) {
839
+ continue;
840
+ }
841
+ for (var r = -2; r <= 2; r++) {
842
+ for (var c = -2; c <= 2; c++) {
843
+ if (Math.abs(r) === 2 || Math.abs(c) === 2 || r === 0 && c === 0) {
844
+ this.modules[row + r][col + c] = true;
845
+ } else {
846
+ this.modules[row + r][col + c] = false;
847
+ }
848
+ }
849
+ }
850
+ }
851
+ }
852
+ },
853
+ setupTypeNumber: function(test) {
854
+ var bits = QRUtil.getBCHTypeNumber(this.typeNumber);
855
+ var mod;
856
+ for (var i = 0; i < 18; i++) {
857
+ mod = !test && (bits >> i & 1) === 1;
858
+ this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod;
859
+ }
860
+ for (var x = 0; x < 18; x++) {
861
+ mod = !test && (bits >> x & 1) === 1;
862
+ this.modules[x % 3 + this.moduleCount - 8 - 3][Math.floor(x / 3)] = mod;
863
+ }
864
+ },
865
+ setupTypeInfo: function(test, maskPattern) {
866
+ var data = this.errorCorrectLevel << 3 | maskPattern;
867
+ var bits = QRUtil.getBCHTypeInfo(data);
868
+ var mod;
869
+ for (var v = 0; v < 15; v++) {
870
+ mod = !test && (bits >> v & 1) === 1;
871
+ if (v < 6) {
872
+ this.modules[v][8] = mod;
873
+ } else if (v < 8) {
874
+ this.modules[v + 1][8] = mod;
875
+ } else {
876
+ this.modules[this.moduleCount - 15 + v][8] = mod;
877
+ }
878
+ }
879
+ for (var h = 0; h < 15; h++) {
880
+ mod = !test && (bits >> h & 1) === 1;
881
+ if (h < 8) {
882
+ this.modules[8][this.moduleCount - h - 1] = mod;
883
+ } else if (h < 9) {
884
+ this.modules[8][15 - h - 1 + 1] = mod;
885
+ } else {
886
+ this.modules[8][15 - h - 1] = mod;
887
+ }
888
+ }
889
+ this.modules[this.moduleCount - 8][8] = !test;
890
+ },
891
+ mapData: function(data, maskPattern) {
892
+ var inc = -1;
893
+ var row = this.moduleCount - 1;
894
+ var bitIndex = 7;
895
+ var byteIndex = 0;
896
+ for (var col = this.moduleCount - 1; col > 0; col -= 2) {
897
+ if (col === 6) col--;
898
+ while (true) {
899
+ for (var c = 0; c < 2; c++) {
900
+ if (this.modules[row][col - c] === null) {
901
+ var dark = false;
902
+ if (byteIndex < data.length) {
903
+ dark = (data[byteIndex] >>> bitIndex & 1) === 1;
904
+ }
905
+ var mask = QRUtil.getMask(maskPattern, row, col - c);
906
+ if (mask) {
907
+ dark = !dark;
908
+ }
909
+ this.modules[row][col - c] = dark;
910
+ bitIndex--;
911
+ if (bitIndex === -1) {
912
+ byteIndex++;
913
+ bitIndex = 7;
914
+ }
915
+ }
916
+ }
917
+ row += inc;
918
+ if (row < 0 || this.moduleCount <= row) {
919
+ row -= inc;
920
+ inc = -inc;
921
+ break;
922
+ }
923
+ }
924
+ }
925
+ }
926
+ };
927
+ QRCode.PAD0 = 236;
928
+ QRCode.PAD1 = 17;
929
+ QRCode.createData = function(typeNumber, errorCorrectLevel, dataList) {
930
+ var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel);
931
+ var buffer = new QRBitBuffer();
932
+ for (var i = 0; i < dataList.length; i++) {
933
+ var data = dataList[i];
934
+ buffer.put(data.mode, 4);
935
+ buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber));
936
+ data.write(buffer);
937
+ }
938
+ var totalDataCount = 0;
939
+ for (var x = 0; x < rsBlocks.length; x++) {
940
+ totalDataCount += rsBlocks[x].dataCount;
941
+ }
942
+ if (buffer.getLengthInBits() > totalDataCount * 8) {
943
+ throw new Error("code length overflow. (" + buffer.getLengthInBits() + ">" + totalDataCount * 8 + ")");
944
+ }
945
+ if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) {
946
+ buffer.put(0, 4);
947
+ }
948
+ while (buffer.getLengthInBits() % 8 !== 0) {
949
+ buffer.putBit(false);
950
+ }
951
+ while (true) {
952
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
953
+ break;
954
+ }
955
+ buffer.put(QRCode.PAD0, 8);
956
+ if (buffer.getLengthInBits() >= totalDataCount * 8) {
957
+ break;
958
+ }
959
+ buffer.put(QRCode.PAD1, 8);
960
+ }
961
+ return QRCode.createBytes(buffer, rsBlocks);
962
+ };
963
+ QRCode.createBytes = function(buffer, rsBlocks) {
964
+ var offset = 0;
965
+ var maxDcCount = 0;
966
+ var maxEcCount = 0;
967
+ var dcdata = new Array(rsBlocks.length);
968
+ var ecdata = new Array(rsBlocks.length);
969
+ for (var r = 0; r < rsBlocks.length; r++) {
970
+ var dcCount = rsBlocks[r].dataCount;
971
+ var ecCount = rsBlocks[r].totalCount - dcCount;
972
+ maxDcCount = Math.max(maxDcCount, dcCount);
973
+ maxEcCount = Math.max(maxEcCount, ecCount);
974
+ dcdata[r] = new Array(dcCount);
975
+ for (var i = 0; i < dcdata[r].length; i++) {
976
+ dcdata[r][i] = 255 & buffer.buffer[i + offset];
977
+ }
978
+ offset += dcCount;
979
+ var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
980
+ var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
981
+ var modPoly = rawPoly.mod(rsPoly);
982
+ ecdata[r] = new Array(rsPoly.getLength() - 1);
983
+ for (var x = 0; x < ecdata[r].length; x++) {
984
+ var modIndex = x + modPoly.getLength() - ecdata[r].length;
985
+ ecdata[r][x] = modIndex >= 0 ? modPoly.get(modIndex) : 0;
986
+ }
987
+ }
988
+ var totalCodeCount = 0;
989
+ for (var y = 0; y < rsBlocks.length; y++) {
990
+ totalCodeCount += rsBlocks[y].totalCount;
991
+ }
992
+ var data = new Array(totalCodeCount);
993
+ var index = 0;
994
+ for (var z = 0; z < maxDcCount; z++) {
995
+ for (var s = 0; s < rsBlocks.length; s++) {
996
+ if (z < dcdata[s].length) {
997
+ data[index++] = dcdata[s][z];
998
+ }
999
+ }
1000
+ }
1001
+ for (var xx = 0; xx < maxEcCount; xx++) {
1002
+ for (var t = 0; t < rsBlocks.length; t++) {
1003
+ if (xx < ecdata[t].length) {
1004
+ data[index++] = ecdata[t][xx];
1005
+ }
1006
+ }
1007
+ }
1008
+ return data;
1009
+ };
1010
+ module.exports = QRCode;
1011
+ }
1012
+ });
1013
+
1014
+ // ../../node_modules/qrcode-terminal/lib/main.js
1015
+ var require_main = __commonJS({
1016
+ "../../node_modules/qrcode-terminal/lib/main.js"(exports, module) {
1017
+ var QRCode = require_QRCode();
1018
+ var QRErrorCorrectLevel = require_QRErrorCorrectLevel();
1019
+ var black = "\x1B[40m \x1B[0m";
1020
+ var white = "\x1B[47m \x1B[0m";
1021
+ var toCell = function(isBlack) {
1022
+ return isBlack ? black : white;
1023
+ };
1024
+ var repeat = function(color) {
1025
+ return {
1026
+ times: function(count) {
1027
+ return new Array(count).join(color);
1028
+ }
1029
+ };
1030
+ };
1031
+ var fill = function(length, value) {
1032
+ var arr = new Array(length);
1033
+ for (var i = 0; i < length; i++) {
1034
+ arr[i] = value;
1035
+ }
1036
+ return arr;
1037
+ };
1038
+ module.exports = {
1039
+ error: QRErrorCorrectLevel.L,
1040
+ generate: function(input, opts, cb) {
1041
+ if (typeof opts === "function") {
1042
+ cb = opts;
1043
+ opts = {};
1044
+ }
1045
+ var qrcode3 = new QRCode(-1, this.error);
1046
+ qrcode3.addData(input);
1047
+ qrcode3.make();
1048
+ var output = "";
1049
+ if (opts && opts.small) {
1050
+ var BLACK = true, WHITE = false;
1051
+ var moduleCount = qrcode3.getModuleCount();
1052
+ var moduleData = qrcode3.modules.slice();
1053
+ var oddRow = moduleCount % 2 === 1;
1054
+ if (oddRow) {
1055
+ moduleData.push(fill(moduleCount, WHITE));
1056
+ }
1057
+ var platte = {
1058
+ WHITE_ALL: "\u2588",
1059
+ WHITE_BLACK: "\u2580",
1060
+ BLACK_WHITE: "\u2584",
1061
+ BLACK_ALL: " "
1062
+ };
1063
+ var borderTop = repeat(platte.BLACK_WHITE).times(moduleCount + 3);
1064
+ var borderBottom = repeat(platte.WHITE_BLACK).times(moduleCount + 3);
1065
+ output += borderTop + "\n";
1066
+ for (var row = 0; row < moduleCount; row += 2) {
1067
+ output += platte.WHITE_ALL;
1068
+ for (var col = 0; col < moduleCount; col++) {
1069
+ if (moduleData[row][col] === WHITE && moduleData[row + 1][col] === WHITE) {
1070
+ output += platte.WHITE_ALL;
1071
+ } else if (moduleData[row][col] === WHITE && moduleData[row + 1][col] === BLACK) {
1072
+ output += platte.WHITE_BLACK;
1073
+ } else if (moduleData[row][col] === BLACK && moduleData[row + 1][col] === WHITE) {
1074
+ output += platte.BLACK_WHITE;
1075
+ } else {
1076
+ output += platte.BLACK_ALL;
1077
+ }
1078
+ }
1079
+ output += platte.WHITE_ALL + "\n";
1080
+ }
1081
+ if (!oddRow) {
1082
+ output += borderBottom;
1083
+ }
1084
+ } else {
1085
+ var border = repeat(white).times(qrcode3.getModuleCount() + 3);
1086
+ output += border + "\n";
1087
+ qrcode3.modules.forEach(function(row2) {
1088
+ output += white;
1089
+ output += row2.map(toCell).join("");
1090
+ output += white + "\n";
1091
+ });
1092
+ output += border;
1093
+ }
1094
+ if (cb) cb(output);
1095
+ else console.log(output);
1096
+ },
1097
+ setErrorLevel: function(error2) {
1098
+ this.error = QRErrorCorrectLevel[error2] || this.error;
1099
+ }
1100
+ };
1101
+ }
1102
+ });
8
1103
 
9
1104
  // src/index.ts
10
1105
  import "dotenv/config";
@@ -142,6 +1237,13 @@ function printTable(data) {
142
1237
  function printError(message) {
143
1238
  console.error(chalk.red(message));
144
1239
  }
1240
+ var activeSpinners = /* @__PURE__ */ new Set();
1241
+ function stopAllSpinners() {
1242
+ for (const spinner of activeSpinners) {
1243
+ spinner.stop();
1244
+ }
1245
+ activeSpinners.clear();
1246
+ }
145
1247
  function createNoopSpinner(text) {
146
1248
  const noopSpinner = {
147
1249
  text,
@@ -149,29 +1251,66 @@ function createNoopSpinner(text) {
149
1251
  return this;
150
1252
  },
151
1253
  stop() {
1254
+ activeSpinners.delete(this);
152
1255
  return this;
153
1256
  },
154
1257
  succeed() {
1258
+ activeSpinners.delete(this);
155
1259
  return this;
156
1260
  },
157
1261
  fail(text2) {
1262
+ activeSpinners.delete(this);
158
1263
  if (text2) printError(text2);
159
1264
  return this;
160
1265
  },
161
1266
  warn() {
1267
+ activeSpinners.delete(this);
162
1268
  return this;
163
1269
  },
164
1270
  info() {
1271
+ activeSpinners.delete(this);
165
1272
  return this;
166
1273
  }
167
1274
  };
168
1275
  return noopSpinner;
169
1276
  }
1277
+ function wrapOraSpinner(spinner) {
1278
+ const originalStop = spinner.stop.bind(spinner);
1279
+ const originalSucceed = spinner.succeed.bind(spinner);
1280
+ const originalFail = spinner.fail.bind(spinner);
1281
+ const originalWarn = spinner.warn.bind(spinner);
1282
+ const originalInfo = spinner.info.bind(spinner);
1283
+ spinner.stop = () => {
1284
+ activeSpinners.delete(spinner);
1285
+ return originalStop();
1286
+ };
1287
+ spinner.succeed = (text) => {
1288
+ activeSpinners.delete(spinner);
1289
+ return originalSucceed(text);
1290
+ };
1291
+ spinner.fail = (text) => {
1292
+ activeSpinners.delete(spinner);
1293
+ return originalFail(text);
1294
+ };
1295
+ spinner.warn = (text) => {
1296
+ activeSpinners.delete(spinner);
1297
+ return originalWarn(text);
1298
+ };
1299
+ spinner.info = (text) => {
1300
+ activeSpinners.delete(spinner);
1301
+ return originalInfo(text);
1302
+ };
1303
+ return spinner;
1304
+ }
170
1305
  function createSpinner(text) {
171
1306
  if (silentMode) {
172
- return createNoopSpinner(text);
1307
+ const spinner2 = createNoopSpinner(text);
1308
+ activeSpinners.add(spinner2);
1309
+ return spinner2;
173
1310
  }
174
- return ora(text).start();
1311
+ const spinner = wrapOraSpinner(ora(text).start());
1312
+ activeSpinners.add(spinner);
1313
+ return spinner;
175
1314
  }
176
1315
 
177
1316
  // src/core/password-manager.ts
@@ -231,6 +1370,17 @@ function createPasswordCallback() {
231
1370
  return getPassword(vaultId, vaultName);
232
1371
  };
233
1372
  }
1373
+ async function ensureVaultUnlocked(vault, password) {
1374
+ if (!vault.isEncrypted || vault.isUnlocked()) {
1375
+ return;
1376
+ }
1377
+ if (password) {
1378
+ await vault.unlock(password);
1379
+ return;
1380
+ }
1381
+ const inputPassword = await promptForPassword(vault.name, vault.id);
1382
+ await vault.unlock(inputPassword);
1383
+ }
234
1384
 
235
1385
  // src/adapters/cli-context.ts
236
1386
  var CLIContext = class extends BaseCommandContext {
@@ -716,6 +1866,7 @@ Use --add <contractAddress> to add or --remove <tokenId> to remove`));
716
1866
  }
717
1867
 
718
1868
  // src/commands/transaction.ts
1869
+ var import_qrcode_terminal = __toESM(require_main(), 1);
719
1870
  import { Chain, Vultisig as Vultisig2 } from "@vultisig/sdk";
720
1871
  async function executeSend(ctx2, params) {
721
1872
  const vault = await ctx2.ensureActiveVault();
@@ -770,17 +1921,49 @@ async function sendTransaction(vault, params) {
770
1921
  throw new Error("Transaction cancelled by user");
771
1922
  }
772
1923
  }
773
- const signSpinner = createSpinner("Signing transaction...");
1924
+ await ensureVaultUnlocked(vault, params.password);
1925
+ const isSecureVault = vault.type === "secure";
1926
+ const signSpinner = createSpinner(isSecureVault ? "Preparing secure signing session..." : "Signing transaction...");
774
1927
  vault.on("signingProgress", ({ step }) => {
775
1928
  signSpinner.text = `${step.message} (${step.progress}%)`;
776
1929
  });
1930
+ if (isSecureVault) {
1931
+ vault.on("qrCodeReady", ({ qrPayload }) => {
1932
+ if (isJsonOutput()) {
1933
+ printResult(qrPayload);
1934
+ } else if (isSilent()) {
1935
+ printResult(`QR Payload: ${qrPayload}`);
1936
+ } else {
1937
+ signSpinner.stop();
1938
+ info("\nScan this QR code with your Vultisig mobile app to sign:");
1939
+ import_qrcode_terminal.default.generate(qrPayload, { small: true });
1940
+ info(`
1941
+ Or use this URL: ${qrPayload}
1942
+ `);
1943
+ signSpinner.start("Waiting for devices to join signing session...");
1944
+ }
1945
+ });
1946
+ vault.on(
1947
+ "deviceJoined",
1948
+ ({ deviceId, totalJoined, required }) => {
1949
+ if (!isSilent()) {
1950
+ signSpinner.text = `Device joined: ${totalJoined}/${required} (${deviceId})`;
1951
+ } else if (!isJsonOutput()) {
1952
+ printResult(`Device joined: ${totalJoined}/${required}`);
1953
+ }
1954
+ }
1955
+ );
1956
+ }
777
1957
  try {
778
1958
  const messageHashes = await vault.extractMessageHashes(payload);
779
- const signature = await vault.sign({
780
- transaction: payload,
781
- chain: payload.coin.chain,
782
- messageHashes
783
- });
1959
+ const signature = await vault.sign(
1960
+ {
1961
+ transaction: payload,
1962
+ chain: payload.coin.chain,
1963
+ messageHashes
1964
+ },
1965
+ { signal: params.signal }
1966
+ );
784
1967
  signSpinner.succeed("Transaction signed");
785
1968
  const broadcastSpinner = createSpinner("Broadcasting transaction...");
786
1969
  const txHash = await vault.broadcastTx({
@@ -802,198 +1985,179 @@ async function sendTransaction(vault, params) {
802
1985
  return result;
803
1986
  } finally {
804
1987
  vault.removeAllListeners("signingProgress");
1988
+ if (isSecureVault) {
1989
+ vault.removeAllListeners("qrCodeReady");
1990
+ vault.removeAllListeners("deviceJoined");
1991
+ }
805
1992
  }
806
1993
  }
807
1994
 
808
1995
  // src/commands/vault-management.ts
1996
+ var import_qrcode_terminal2 = __toESM(require_main(), 1);
809
1997
  import chalk5 from "chalk";
810
1998
  import { promises as fs } from "fs";
811
1999
  import inquirer4 from "inquirer";
812
- async function executeCreate(ctx2, options = { type: "fast" }) {
813
- const vaultType = options.type.toLowerCase();
814
- if (vaultType !== "fast" && vaultType !== "secure") {
815
- throw new Error('Invalid vault type. Must be "fast" or "secure"');
816
- }
817
- let name = options.name;
818
- let password = options.password;
819
- const prompts = [];
820
- if (!name) {
821
- prompts.push({
822
- type: "input",
823
- name: "name",
824
- message: "Enter vault name:",
825
- validate: (input) => input.trim() !== "" || "Name is required"
826
- });
827
- }
828
- if (!password) {
829
- prompts.push({
830
- type: "password",
831
- name: "password",
832
- message: "Enter password:",
833
- mask: "*",
834
- validate: (input) => input.length >= 8 || "Password must be at least 8 characters"
835
- });
836
- prompts.push({
837
- type: "password",
838
- name: "confirmPassword",
839
- message: "Confirm password:",
840
- mask: "*",
841
- validate: (input, ans) => input === ans.password || "Passwords do not match"
842
- });
843
- }
844
- if (prompts.length > 0) {
845
- const answers = await inquirer4.prompt(prompts);
846
- name = name || answers.name;
847
- password = password || answers.password;
848
- }
849
- if (vaultType === "fast") {
850
- let email = options.email;
851
- if (!email) {
852
- const emailAnswer = await inquirer4.prompt([
853
- {
854
- type: "input",
855
- name: "email",
856
- message: "Enter email for verification:",
857
- validate: (input) => /\S+@\S+\.\S+/.test(input) || "Invalid email format"
858
- }
859
- ]);
860
- email = emailAnswer.email;
861
- }
862
- const spinner = createSpinner("Creating vault...");
863
- const vaultId = await ctx2.sdk.createFastVault({
2000
+ function withAbortSignal(promise, signal) {
2001
+ if (!signal) return promise;
2002
+ return Promise.race([
2003
+ promise,
2004
+ new Promise((_, reject) => {
2005
+ if (signal.aborted) reject(new Error("Operation cancelled"));
2006
+ signal.addEventListener("abort", () => reject(new Error("Operation cancelled")), { once: true });
2007
+ })
2008
+ ]);
2009
+ }
2010
+ async function executeCreateFast(ctx2, options) {
2011
+ const { name, password, email, signal } = options;
2012
+ const spinner = createSpinner("Creating vault...");
2013
+ const vaultId = await withAbortSignal(
2014
+ ctx2.sdk.createFastVault({
864
2015
  name,
865
2016
  password,
866
2017
  email,
867
2018
  onProgress: (step) => {
868
2019
  spinner.text = `${step.message} (${step.progress}%)`;
869
2020
  }
870
- });
871
- spinner.succeed(`Vault keys generated: ${name}`);
872
- warn("\nA verification code has been sent to your email.");
873
- info("Please check your inbox and enter the code.");
874
- const MAX_VERIFY_ATTEMPTS = 5;
875
- let attempts = 0;
876
- while (attempts < MAX_VERIFY_ATTEMPTS) {
877
- attempts++;
878
- const codeAnswer = await inquirer4.prompt([
2021
+ }),
2022
+ signal
2023
+ );
2024
+ spinner.succeed(`Vault keys generated: ${name}`);
2025
+ warn("\nA verification code has been sent to your email.");
2026
+ info("Please check your inbox and enter the code.");
2027
+ const MAX_VERIFY_ATTEMPTS = 5;
2028
+ let attempts = 0;
2029
+ while (attempts < MAX_VERIFY_ATTEMPTS) {
2030
+ attempts++;
2031
+ const codeAnswer = await inquirer4.prompt([
2032
+ {
2033
+ type: "input",
2034
+ name: "code",
2035
+ message: `Verification code sent to ${email}. Enter code:`,
2036
+ validate: (input) => /^\d{4,6}$/.test(input) || "Code must be 4-6 digits"
2037
+ }
2038
+ ]);
2039
+ const verifySpinner = createSpinner("Verifying email code...");
2040
+ try {
2041
+ const vault = await ctx2.sdk.verifyVault(vaultId, codeAnswer.code);
2042
+ verifySpinner.succeed("Email verified successfully!");
2043
+ setupVaultEvents(vault);
2044
+ await ctx2.setActiveVault(vault);
2045
+ success("\n+ Vault created!");
2046
+ info("\nYour vault is ready. Run the following commands:");
2047
+ printResult(chalk5.cyan(" vultisig balance ") + "- View balances");
2048
+ printResult(chalk5.cyan(" vultisig addresses ") + "- View addresses");
2049
+ printResult(chalk5.cyan(" vultisig portfolio ") + "- View portfolio value");
2050
+ return vault;
2051
+ } catch (err) {
2052
+ verifySpinner.fail("Verification failed");
2053
+ error(`
2054
+ \u2717 ${err.message || "Invalid verification code"}`);
2055
+ if (attempts >= MAX_VERIFY_ATTEMPTS) {
2056
+ warn("\nMaximum attempts reached.");
2057
+ warn("\nTo retry verification later, use:");
2058
+ info(` vultisig verify ${vaultId}`);
2059
+ err.exitCode = 1;
2060
+ throw err;
2061
+ }
2062
+ const { action } = await inquirer4.prompt([
879
2063
  {
880
- type: "input",
881
- name: "code",
882
- message: `Verification code sent to ${email}. Enter code:`,
883
- validate: (input) => /^\d{4,6}$/.test(input) || "Code must be 4-6 digits"
2064
+ type: "list",
2065
+ name: "action",
2066
+ message: `What would you like to do? (${MAX_VERIFY_ATTEMPTS - attempts} attempts remaining)`,
2067
+ choices: [
2068
+ { name: "Enter a different code", value: "retry" },
2069
+ { name: "Resend verification email (rate limited)", value: "resend" },
2070
+ { name: "Abort and verify later", value: "abort" }
2071
+ ]
884
2072
  }
885
2073
  ]);
886
- const verifySpinner = createSpinner("Verifying email code...");
887
- try {
888
- const vault = await ctx2.sdk.verifyVault(vaultId, codeAnswer.code);
889
- verifySpinner.succeed("Email verified successfully!");
890
- setupVaultEvents(vault);
891
- await ctx2.setActiveVault(vault);
892
- success("\n+ Vault created!");
893
- info("\nYour vault is ready. Run the following commands:");
894
- printResult(chalk5.cyan(" vultisig balance ") + "- View balances");
895
- printResult(chalk5.cyan(" vultisig addresses ") + "- View addresses");
896
- printResult(chalk5.cyan(" vultisig portfolio ") + "- View portfolio value");
897
- return vault;
898
- } catch (err) {
899
- verifySpinner.fail("Verification failed");
900
- error(`
901
- \u2717 ${err.message || "Invalid verification code"}`);
902
- if (attempts >= MAX_VERIFY_ATTEMPTS) {
903
- warn("\nMaximum attempts reached.");
904
- warn("\nTo retry verification later, use:");
905
- info(` vultisig verify ${vaultId}`);
906
- err.exitCode = 1;
907
- throw err;
908
- }
909
- const { action } = await inquirer4.prompt([
910
- {
911
- type: "list",
912
- name: "action",
913
- message: `What would you like to do? (${MAX_VERIFY_ATTEMPTS - attempts} attempts remaining)`,
914
- choices: [
915
- { name: "Enter a different code", value: "retry" },
916
- { name: "Resend verification email (rate limited)", value: "resend" },
917
- { name: "Abort and verify later", value: "abort" }
918
- ]
919
- }
920
- ]);
921
- if (action === "abort") {
922
- warn("\nVault creation paused. To complete verification, use:");
923
- info(` vultisig verify ${vaultId}`);
924
- warn("\nNote: The pending vault is stored in memory only and will be lost if you exit.");
925
- return void 0;
926
- }
927
- if (action === "resend") {
928
- const resendSpinner = createSpinner("Resending verification email...");
929
- try {
930
- await ctx2.sdk.resendVaultVerification(vaultId);
931
- resendSpinner.succeed("Verification email sent!");
932
- info("Check your inbox for the new code. Note: There may be a ~3 minute cooldown between resends.");
933
- } catch (resendErr) {
934
- resendSpinner.fail("Failed to resend");
935
- warn(resendErr.message || "Could not resend email. You may need to wait a few minutes.");
936
- }
937
- }
2074
+ if (action === "abort") {
2075
+ warn("\nVault creation paused. To complete verification, use:");
2076
+ info(` vultisig verify ${vaultId}`);
2077
+ warn("\nNote: The pending vault is stored in memory only and will be lost if you exit.");
2078
+ return void 0;
938
2079
  }
939
- }
940
- throw new Error("Verification loop exited unexpectedly");
941
- } else {
942
- let threshold = options.threshold;
943
- let totalShares = options.shares;
944
- const securePrompts = [];
945
- if (threshold === void 0) {
946
- securePrompts.push({
947
- type: "number",
948
- name: "threshold",
949
- message: "Signing threshold (m):",
950
- default: 2,
951
- validate: (input) => input > 0 || "Threshold must be greater than 0"
952
- });
953
- }
954
- if (totalShares === void 0) {
955
- securePrompts.push({
956
- type: "number",
957
- name: "totalShares",
958
- message: "Total shares (n):",
959
- default: 3,
960
- validate: (input, ans) => {
961
- const t = threshold ?? ans.threshold;
962
- return input >= t || `Total shares must be >= threshold (${t})`;
2080
+ if (action === "resend") {
2081
+ const resendSpinner = createSpinner("Resending verification email...");
2082
+ try {
2083
+ await ctx2.sdk.resendVaultVerification(vaultId);
2084
+ resendSpinner.succeed("Verification email sent!");
2085
+ info("Check your inbox for the new code. Note: There may be a ~3 minute cooldown between resends.");
2086
+ } catch (resendErr) {
2087
+ resendSpinner.fail("Failed to resend");
2088
+ warn(resendErr.message || "Could not resend email. You may need to wait a few minutes.");
963
2089
  }
964
- });
965
- }
966
- if (securePrompts.length > 0) {
967
- const secureAnswers = await inquirer4.prompt(securePrompts);
968
- threshold = threshold ?? secureAnswers.threshold;
969
- totalShares = totalShares ?? secureAnswers.totalShares;
2090
+ }
970
2091
  }
971
- const spinner = createSpinner("Creating secure vault...");
972
- try {
973
- const result = await ctx2.sdk.createSecureVault({
2092
+ }
2093
+ throw new Error("Verification loop exited unexpectedly");
2094
+ }
2095
+ async function executeCreateSecure(ctx2, options) {
2096
+ const { name, password, threshold, shares: totalShares, signal } = options;
2097
+ const spinner = createSpinner("Creating secure vault...");
2098
+ try {
2099
+ const result = await withAbortSignal(
2100
+ ctx2.sdk.createSecureVault({
974
2101
  name,
975
2102
  password,
976
2103
  devices: totalShares,
977
2104
  threshold,
978
2105
  onProgress: (step) => {
979
2106
  spinner.text = `${step.message} (${step.progress}%)`;
2107
+ },
2108
+ onQRCodeReady: (qrPayload) => {
2109
+ if (isJsonOutput()) {
2110
+ printResult(qrPayload);
2111
+ } else if (isSilent()) {
2112
+ printResult(`QR Payload: ${qrPayload}`);
2113
+ } else {
2114
+ spinner.stop();
2115
+ info("\nScan this QR code with your Vultisig mobile app:");
2116
+ import_qrcode_terminal2.default.generate(qrPayload, { small: true });
2117
+ info(`
2118
+ Or use this URL: ${qrPayload}
2119
+ `);
2120
+ info(chalk5.gray("(Press Ctrl+C to cancel)\n"));
2121
+ spinner.start(`Waiting for ${totalShares} devices to join...`);
2122
+ }
2123
+ },
2124
+ onDeviceJoined: (deviceId, totalJoined, required) => {
2125
+ if (!isSilent()) {
2126
+ spinner.text = `Device joined: ${totalJoined}/${required} (${deviceId})`;
2127
+ } else if (!isJsonOutput()) {
2128
+ printResult(`Device joined: ${totalJoined}/${required}`);
2129
+ }
980
2130
  }
2131
+ }),
2132
+ signal
2133
+ );
2134
+ setupVaultEvents(result.vault);
2135
+ await ctx2.setActiveVault(result.vault);
2136
+ spinner.succeed(`Secure vault created: ${name} (${threshold}-of-${totalShares})`);
2137
+ if (isJsonOutput()) {
2138
+ outputJson({
2139
+ vault: {
2140
+ id: result.vaultId,
2141
+ name,
2142
+ type: "secure",
2143
+ threshold,
2144
+ totalSigners: totalShares
2145
+ },
2146
+ sessionId: result.sessionId
981
2147
  });
982
- setupVaultEvents(result.vault);
983
- await ctx2.setActiveVault(result.vault);
984
- spinner.succeed(`Secure vault created: ${name} (${threshold}-of-${totalShares})`);
985
- warn(`
986
- Important: Save your vault backup file (.vult) in a secure location.`);
987
- warn(`This is a ${threshold}-of-${totalShares} vault. You'll need ${threshold} devices to sign transactions.`);
988
- success("\n+ Vault created!");
989
2148
  return result.vault;
990
- } catch (err) {
991
- spinner.fail("Secure vault creation failed");
992
- if (err.message?.includes("not implemented")) {
993
- warn("\nSecure vault creation is not yet implemented in the SDK");
994
- }
995
- throw err;
996
2149
  }
2150
+ warn(`
2151
+ Important: Save your vault backup file (.vult) in a secure location.`);
2152
+ warn(`This is a ${threshold}-of-${totalShares} vault. You'll need ${threshold} devices to sign transactions.`);
2153
+ success("\n+ Vault created!");
2154
+ return result.vault;
2155
+ } catch (err) {
2156
+ spinner.fail("Secure vault creation failed");
2157
+ if (err.message?.includes("not implemented")) {
2158
+ warn("\nSecure vault creation is not yet implemented in the SDK");
2159
+ }
2160
+ throw err;
997
2161
  }
998
2162
  }
999
2163
  async function executeImport(ctx2, file) {
@@ -1263,6 +2427,7 @@ async function executeSwap(ctx2, options) {
1263
2427
  autoApprove: false
1264
2428
  });
1265
2429
  prepSpinner.succeed("Swap prepared");
2430
+ await ensureVaultUnlocked(vault, options.password);
1266
2431
  if (approvalPayload) {
1267
2432
  info("\nToken approval required before swap...");
1268
2433
  const approvalSpinner = createSpinner("Signing approval transaction...");
@@ -1271,11 +2436,14 @@ async function executeSwap(ctx2, options) {
1271
2436
  });
1272
2437
  try {
1273
2438
  const approvalHashes = await vault.extractMessageHashes(approvalPayload);
1274
- const approvalSig = await vault.sign({
1275
- transaction: approvalPayload,
1276
- chain: options.fromChain,
1277
- messageHashes: approvalHashes
1278
- });
2439
+ const approvalSig = await vault.sign(
2440
+ {
2441
+ transaction: approvalPayload,
2442
+ chain: options.fromChain,
2443
+ messageHashes: approvalHashes
2444
+ },
2445
+ { signal: options.signal }
2446
+ );
1279
2447
  approvalSpinner.succeed("Approval signed");
1280
2448
  const broadcastApprovalSpinner = createSpinner("Broadcasting approval...");
1281
2449
  const approvalTxHash = await vault.broadcastTx({
@@ -1296,11 +2464,14 @@ async function executeSwap(ctx2, options) {
1296
2464
  });
1297
2465
  try {
1298
2466
  const messageHashes = await vault.extractMessageHashes(keysignPayload);
1299
- const signature = await vault.sign({
1300
- transaction: keysignPayload,
1301
- chain: options.fromChain,
1302
- messageHashes
1303
- });
2467
+ const signature = await vault.sign(
2468
+ {
2469
+ transaction: keysignPayload,
2470
+ chain: options.fromChain,
2471
+ messageHashes
2472
+ },
2473
+ { signal: options.signal }
2474
+ );
1304
2475
  signSpinner.succeed("Swap transaction signed");
1305
2476
  const broadcastSpinner = createSpinner("Broadcasting swap transaction...");
1306
2477
  const txHash = await vault.broadcastTx({
@@ -2063,6 +3234,12 @@ function createShellContext(sdk, options) {
2063
3234
  }
2064
3235
 
2065
3236
  // src/interactive/session.ts
3237
+ var PromptCancelledError = class extends Error {
3238
+ name = "PromptCancelledError";
3239
+ constructor() {
3240
+ super("Prompt cancelled");
3241
+ }
3242
+ };
2066
3243
  function createSpinner2(text) {
2067
3244
  return ora3({
2068
3245
  text,
@@ -2075,6 +3252,9 @@ function createSpinner2(text) {
2075
3252
  var ShellSession = class {
2076
3253
  ctx;
2077
3254
  eventBuffer;
3255
+ lastSigintTime = 0;
3256
+ DOUBLE_CTRL_C_TIMEOUT = 2e3;
3257
+ // 2 seconds
2078
3258
  constructor(sdk, options) {
2079
3259
  this.ctx = createShellContext(sdk, options);
2080
3260
  this.eventBuffer = new EventBuffer();
@@ -2120,19 +3300,135 @@ var ShellSession = class {
2120
3300
  resolve(answer);
2121
3301
  });
2122
3302
  rl.on("SIGINT", () => {
3303
+ const now = Date.now();
3304
+ if (now - this.lastSigintTime < this.DOUBLE_CTRL_C_TIMEOUT) {
3305
+ rl.close();
3306
+ console.log(chalk9.yellow("\nGoodbye!"));
3307
+ this.ctx.dispose();
3308
+ process.exit(0);
3309
+ }
3310
+ this.lastSigintTime = now;
3311
+ console.log(chalk9.yellow("\n(Press Ctrl+C again to exit)"));
2123
3312
  rl.close();
2124
- console.log(chalk9.yellow("\nGoodbye!"));
2125
- this.ctx.dispose();
2126
- process.exit(0);
3313
+ resolve("");
3314
+ });
3315
+ });
3316
+ }
3317
+ /**
3318
+ * Simple prompt for input (used within commands)
3319
+ */
3320
+ prompt(message, defaultValue) {
3321
+ return new Promise((resolve, reject) => {
3322
+ const displayPrompt = defaultValue ? `${message} [${defaultValue}]: ` : `${message}: `;
3323
+ const rl = readline.createInterface({
3324
+ input: process.stdin,
3325
+ output: process.stdout,
3326
+ terminal: true
3327
+ });
3328
+ rl.question(displayPrompt, (answer) => {
3329
+ rl.close();
3330
+ resolve(answer.trim() || defaultValue || "");
3331
+ });
3332
+ rl.on("SIGINT", () => {
3333
+ rl.close();
3334
+ reject(new PromptCancelledError());
3335
+ });
3336
+ });
3337
+ }
3338
+ /**
3339
+ * Prompt for password input (masked)
3340
+ */
3341
+ promptPassword(message) {
3342
+ return new Promise((resolve, reject) => {
3343
+ const rl = readline.createInterface({
3344
+ input: process.stdin,
3345
+ output: process.stdout,
3346
+ terminal: true
3347
+ });
3348
+ const stdin = process.stdin;
3349
+ const onData = (char) => {
3350
+ const c = char.toString();
3351
+ if (c === "\n" || c === "\r") return;
3352
+ if (c === "") return;
3353
+ if (c === "\x7F" || c === "\b") {
3354
+ process.stdout.write("\b \b");
3355
+ } else {
3356
+ process.stdout.write("*");
3357
+ }
3358
+ };
3359
+ stdin.on("data", onData);
3360
+ rl.question(`${message}: `, (answer) => {
3361
+ stdin.removeListener("data", onData);
3362
+ rl.close();
3363
+ resolve(answer);
3364
+ });
3365
+ rl.on("SIGINT", () => {
3366
+ stdin.removeListener("data", onData);
3367
+ rl.close();
3368
+ reject(new PromptCancelledError());
2127
3369
  });
2128
3370
  });
2129
3371
  }
3372
+ /**
3373
+ * Run an async operation with Ctrl+C cancellation support.
3374
+ * Uses Promise.race to avoid wrapping the original promise chain,
3375
+ * which can interfere with MPC protocol timing.
3376
+ */
3377
+ withCancellation(fn) {
3378
+ const abortController = new AbortController();
3379
+ let rejectCancellation;
3380
+ const cancellationPromise = new Promise((_, reject) => {
3381
+ rejectCancellation = reject;
3382
+ });
3383
+ const onSigint = () => {
3384
+ cleanup();
3385
+ abortController.abort();
3386
+ rejectCancellation(new Error("Operation cancelled"));
3387
+ };
3388
+ const cleanup = () => {
3389
+ process.removeListener("SIGINT", onSigint);
3390
+ };
3391
+ process.on("SIGINT", onSigint);
3392
+ return Promise.race([fn(abortController.signal), cancellationPromise]).finally(cleanup);
3393
+ }
3394
+ /**
3395
+ * Run an async operation with Ctrl+C cancellation support.
3396
+ * Creates an AbortController and passes the signal to the operation.
3397
+ * On SIGINT, aborts the signal which causes the operation to throw.
3398
+ */
3399
+ async withAbortHandler(fn) {
3400
+ const controller = new AbortController();
3401
+ const onSigint = () => {
3402
+ controller.abort();
3403
+ stopAllSpinners();
3404
+ process.stdout.write("\x1B[?25h");
3405
+ process.stdout.write("\r\x1B[K");
3406
+ console.log(chalk9.yellow("\nCancelling operation..."));
3407
+ };
3408
+ const cleanup = () => {
3409
+ process.removeListener("SIGINT", onSigint);
3410
+ };
3411
+ process.on("SIGINT", onSigint);
3412
+ try {
3413
+ const result = await fn(controller.signal);
3414
+ cleanup();
3415
+ return result;
3416
+ } catch (err) {
3417
+ cleanup();
3418
+ stopAllSpinners();
3419
+ if (controller.signal.aborted) {
3420
+ throw new Error("Operation aborted");
3421
+ }
3422
+ throw err;
3423
+ }
3424
+ }
2130
3425
  /**
2131
3426
  * Process a line of input
2132
3427
  */
2133
3428
  async processLine(line) {
2134
3429
  const input = line.trim();
2135
3430
  if (!input) return;
3431
+ this.lastSigintTime = 0;
2136
3432
  const [command, ...args] = input.split(/\s+/);
2137
3433
  try {
2138
3434
  this.eventBuffer.startCommand();
@@ -2140,6 +3436,13 @@ var ShellSession = class {
2140
3436
  this.eventBuffer.endCommand();
2141
3437
  } catch (error2) {
2142
3438
  this.eventBuffer.endCommand();
3439
+ if (error2.name === "ExitPromptError" || error2.name === "PromptCancelledError" || error2.message === "Operation cancelled" || error2.message === "Operation aborted") {
3440
+ stopAllSpinners();
3441
+ process.stdout.write("\x1B[?25h");
3442
+ process.stdout.write("\r\x1B[K");
3443
+ console.log(chalk9.yellow("Operation cancelled"));
3444
+ return;
3445
+ }
2143
3446
  console.error(chalk9.red(`
2144
3447
  Error: ${error2.message}`));
2145
3448
  }
@@ -2160,7 +3463,7 @@ Error: ${error2.message}`));
2160
3463
  await this.importVault(args);
2161
3464
  break;
2162
3465
  case "create":
2163
- await this.createVault();
3466
+ await this.createVault(args);
2164
3467
  break;
2165
3468
  case "info":
2166
3469
  await executeInfo(this.ctx);
@@ -2282,18 +3585,75 @@ Error: ${error2.message}`));
2282
3585
  this.ctx.addVault(vault);
2283
3586
  this.eventBuffer.setupVaultListeners(vault);
2284
3587
  }
2285
- async createVault() {
2286
- const vault = await executeCreate(this.ctx, { type: "fast" });
2287
- this.ctx.addVault(vault);
2288
- this.eventBuffer.setupVaultListeners(vault);
3588
+ async createVault(args) {
3589
+ const type = args[0]?.toLowerCase();
3590
+ if (!type || type !== "fast" && type !== "secure") {
3591
+ console.log(chalk9.yellow("Usage: create <fast|secure>"));
3592
+ console.log(chalk9.gray(" create fast - Create a fast vault (server-assisted 2-of-2)"));
3593
+ console.log(chalk9.gray(" create secure - Create a secure vault (multi-device MPC)"));
3594
+ return;
3595
+ }
3596
+ let vault;
3597
+ if (type === "fast") {
3598
+ const name = await this.prompt("Vault name");
3599
+ if (!name) {
3600
+ console.log(chalk9.red("Name is required"));
3601
+ return;
3602
+ }
3603
+ const password = await this.promptPassword("Vault password");
3604
+ if (!password) {
3605
+ console.log(chalk9.red("Password is required"));
3606
+ return;
3607
+ }
3608
+ const email = await this.prompt("Email for verification");
3609
+ if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
3610
+ console.log(chalk9.red("Valid email is required"));
3611
+ return;
3612
+ }
3613
+ vault = await this.withCancellation((signal) => executeCreateFast(this.ctx, { name, password, email, signal }));
3614
+ } else {
3615
+ const name = await this.prompt("Vault name");
3616
+ if (!name) {
3617
+ console.log(chalk9.red("Name is required"));
3618
+ return;
3619
+ }
3620
+ const sharesStr = await this.prompt("Total shares (devices)", "3");
3621
+ const shares = parseInt(sharesStr, 10);
3622
+ if (isNaN(shares) || shares < 2) {
3623
+ console.log(chalk9.red("Must have at least 2 shares"));
3624
+ return;
3625
+ }
3626
+ const thresholdStr = await this.prompt("Signing threshold", "2");
3627
+ const threshold = parseInt(thresholdStr, 10);
3628
+ if (isNaN(threshold) || threshold < 1 || threshold > shares) {
3629
+ console.log(chalk9.red(`Threshold must be between 1 and ${shares}`));
3630
+ return;
3631
+ }
3632
+ const password = await this.promptPassword("Vault password (optional, press Enter to skip)");
3633
+ vault = await this.withCancellation(
3634
+ (signal) => executeCreateSecure(this.ctx, {
3635
+ name,
3636
+ password: password || void 0,
3637
+ threshold,
3638
+ shares,
3639
+ signal
3640
+ })
3641
+ );
3642
+ }
3643
+ if (vault) {
3644
+ this.ctx.addVault(vault);
3645
+ this.eventBuffer.setupVaultListeners(vault);
3646
+ }
2289
3647
  }
2290
3648
  async runBalance(args) {
2291
3649
  const chainStr = args[0];
2292
3650
  const includeTokens = args.includes("-t") || args.includes("--tokens");
2293
- await executeBalance(this.ctx, {
2294
- chain: chainStr ? findChainByName(chainStr) || chainStr : void 0,
2295
- includeTokens
2296
- });
3651
+ await this.withCancellation(
3652
+ () => executeBalance(this.ctx, {
3653
+ chain: chainStr ? findChainByName(chainStr) || chainStr : void 0,
3654
+ includeTokens
3655
+ })
3656
+ );
2297
3657
  }
2298
3658
  async runPortfolio(args) {
2299
3659
  let currency = "usd";
@@ -2308,7 +3668,7 @@ Error: ${error2.message}`));
2308
3668
  console.log(chalk9.yellow(`Supported currencies: ${fiatCurrencies3.join(", ")}`));
2309
3669
  return;
2310
3670
  }
2311
- await executePortfolio(this.ctx, { currency });
3671
+ await this.withCancellation(() => executePortfolio(this.ctx, { currency }));
2312
3672
  }
2313
3673
  async runSend(args) {
2314
3674
  if (args.length < 3) {
@@ -2329,9 +3689,9 @@ Error: ${error2.message}`));
2329
3689
  }
2330
3690
  }
2331
3691
  try {
2332
- await executeSend(this.ctx, { chain, to, amount, tokenId, memo });
3692
+ await this.withAbortHandler((signal) => executeSend(this.ctx, { chain, to, amount, tokenId, memo, signal }));
2333
3693
  } catch (err) {
2334
- if (err.message === "Transaction cancelled by user") {
3694
+ if (err.message === "Transaction cancelled by user" || err.message === "Operation cancelled" || err.message === "Operation aborted") {
2335
3695
  console.log(chalk9.yellow("\nTransaction cancelled"));
2336
3696
  return;
2337
3697
  }
@@ -2406,7 +3766,7 @@ Error: ${error2.message}`));
2406
3766
  i++;
2407
3767
  }
2408
3768
  }
2409
- await executeSwapQuote(this.ctx, { fromChain, toChain, amount, fromToken, toToken });
3769
+ await this.withCancellation(() => executeSwapQuote(this.ctx, { fromChain, toChain, amount, fromToken, toToken }));
2410
3770
  }
2411
3771
  async runSwap(args) {
2412
3772
  if (args.length < 3) {
@@ -2437,9 +3797,11 @@ Error: ${error2.message}`));
2437
3797
  }
2438
3798
  }
2439
3799
  try {
2440
- await executeSwap(this.ctx, { fromChain, toChain, amount, fromToken, toToken, slippage });
3800
+ await this.withAbortHandler(
3801
+ (signal) => executeSwap(this.ctx, { fromChain, toChain, amount, fromToken, toToken, slippage, signal })
3802
+ );
2441
3803
  } catch (err) {
2442
- if (err.message === "Swap cancelled by user") {
3804
+ if (err.message === "Swap cancelled by user" || err.message === "Operation cancelled" || err.message === "Operation aborted") {
2443
3805
  console.log(chalk9.yellow("\nSwap cancelled"));
2444
3806
  return;
2445
3807
  }
@@ -2537,13 +3899,17 @@ import { join } from "path";
2537
3899
  var cachedVersion = null;
2538
3900
  function getVersion() {
2539
3901
  if (cachedVersion) return cachedVersion;
3902
+ if (true) {
3903
+ cachedVersion = "0.2.0-alpha.7";
3904
+ return cachedVersion;
3905
+ }
2540
3906
  try {
2541
3907
  const packagePath = new URL("../../package.json", import.meta.url);
2542
3908
  const pkg = JSON.parse(readFileSync(packagePath, "utf-8"));
2543
3909
  cachedVersion = pkg.version;
2544
3910
  return cachedVersion;
2545
3911
  } catch {
2546
- cachedVersion = "0.1.0-beta.1";
3912
+ cachedVersion = "0.0.0-unknown";
2547
3913
  return cachedVersion;
2548
3914
  }
2549
3915
  }
@@ -3026,20 +4392,23 @@ async function init(vaultOverride) {
3026
4392
  }
3027
4393
  return ctx;
3028
4394
  }
3029
- program.command("create").description("Create a new vault").option("--type <type>", "Vault type: fast or secure", "fast").option("--name <name>", "Vault name").option("--password <password>", "Vault password").option("--email <email>", "Email for verification (fast vault)").option("--threshold <m>", "Signing threshold (secure vault)").option("--shares <n>", "Total shares (secure vault)").action(
3030
- withExit(
3031
- async (options) => {
3032
- const context = await init(program.opts().vault);
3033
- await executeCreate(context, {
3034
- type: options.type,
3035
- name: options.name,
3036
- password: options.password,
3037
- email: options.email,
3038
- threshold: options.threshold ? parseInt(options.threshold, 10) : void 0,
3039
- shares: options.shares ? parseInt(options.shares, 10) : void 0
3040
- });
3041
- }
3042
- )
4395
+ var createCmd = program.command("create").description("Create a vault");
4396
+ createCmd.command("fast").description("Create a fast vault (server-assisted 2-of-2)").requiredOption("--name <name>", "Vault name").requiredOption("--password <password>", "Vault password").requiredOption("--email <email>", "Email for verification").action(
4397
+ withExit(async (options) => {
4398
+ const context = await init(program.opts().vault);
4399
+ await executeCreateFast(context, options);
4400
+ })
4401
+ );
4402
+ createCmd.command("secure").description("Create a secure vault (multi-device MPC)").requiredOption("--name <name>", "Vault name").option("--password <password>", "Vault password (optional)").option("--threshold <m>", "Signing threshold", "2").option("--shares <n>", "Total shares", "3").action(
4403
+ withExit(async (options) => {
4404
+ const context = await init(program.opts().vault);
4405
+ await executeCreateSecure(context, {
4406
+ name: options.name,
4407
+ password: options.password,
4408
+ threshold: parseInt(options.threshold, 10),
4409
+ shares: parseInt(options.shares, 10)
4410
+ });
4411
+ })
3043
4412
  );
3044
4413
  program.command("import <file>").description("Import vault from .vult file").action(
3045
4414
  withExit(async (file) => {
@@ -3067,7 +4436,7 @@ program.command("balance [chain]").description("Show balance for a chain or all
3067
4436
  });
3068
4437
  })
3069
4438
  );
3070
- program.command("send <chain> <to> <amount>").description("Send tokens to an address").option("--token <tokenId>", "Token to send (default: native)").option("--memo <memo>", "Transaction memo").option("-y, --yes", "Skip confirmation prompt").action(
4439
+ program.command("send <chain> <to> <amount>").description("Send tokens to an address").option("--token <tokenId>", "Token to send (default: native)").option("--memo <memo>", "Transaction memo").option("-y, --yes", "Skip confirmation prompt").option("--password <password>", "Vault password for signing").action(
3071
4440
  withExit(
3072
4441
  async (chainStr, to, amount, options) => {
3073
4442
  const context = await init(program.opts().vault);
@@ -3078,7 +4447,8 @@ program.command("send <chain> <to> <amount>").description("Send tokens to an add
3078
4447
  amount,
3079
4448
  tokenId: options.token,
3080
4449
  memo: options.memo,
3081
- yes: options.yes
4450
+ yes: options.yes,
4451
+ password: options.password
3082
4452
  });
3083
4453
  } catch (err) {
3084
4454
  if (err.message === "Transaction cancelled by user") {
@@ -3204,7 +4574,7 @@ program.command("swap-quote <fromChain> <toChain> <amount>").description("Get a
3204
4574
  }
3205
4575
  )
3206
4576
  );
3207
- program.command("swap <fromChain> <toChain> <amount>").description("Swap tokens between chains").option("--from-token <address>", "Token address to swap from (default: native)").option("--to-token <address>", "Token address to swap to (default: native)").option("--slippage <percent>", "Slippage tolerance in percent", "1").option("-y, --yes", "Skip confirmation prompt").action(
4577
+ program.command("swap <fromChain> <toChain> <amount>").description("Swap tokens between chains").option("--from-token <address>", "Token address to swap from (default: native)").option("--to-token <address>", "Token address to swap to (default: native)").option("--slippage <percent>", "Slippage tolerance in percent", "1").option("-y, --yes", "Skip confirmation prompt").option("--password <password>", "Vault password for signing").action(
3208
4578
  withExit(
3209
4579
  async (fromChainStr, toChainStr, amountStr, options) => {
3210
4580
  const context = await init(program.opts().vault);
@@ -3216,7 +4586,8 @@ program.command("swap <fromChain> <toChain> <amount>").description("Swap tokens
3216
4586
  fromToken: options.fromToken,
3217
4587
  toToken: options.toToken,
3218
4588
  slippage: options.slippage ? parseFloat(options.slippage) : void 0,
3219
- yes: options.yes
4589
+ yes: options.yes,
4590
+ password: options.password
3220
4591
  });
3221
4592
  } catch (err) {
3222
4593
  if (err.message === "Swap cancelled by user") {
@@ -3272,12 +4643,14 @@ async function startInteractiveMode() {
3272
4643
  const session = new ShellSession(sdk);
3273
4644
  await session.start();
3274
4645
  }
4646
+ var isInteractiveMode = process.argv.includes("-i") || process.argv.includes("--interactive");
3275
4647
  process.on("SIGINT", () => {
4648
+ if (isInteractiveMode) return;
3276
4649
  warn("\n\nShutting down...");
3277
4650
  ctx?.dispose();
3278
4651
  process.exit(0);
3279
4652
  });
3280
- if (process.argv.includes("-i") || process.argv.includes("--interactive")) {
4653
+ if (isInteractiveMode) {
3281
4654
  startInteractiveMode().catch((err) => {
3282
4655
  error(`Failed to start interactive mode: ${err.message}`);
3283
4656
  process.exit(1);