@vultisig/cli 0.2.0-alpha.6 → 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
@@ -727,6 +1866,7 @@ Use --add <contractAddress> to add or --remove <tokenId> to remove`));
727
1866
  }
728
1867
 
729
1868
  // src/commands/transaction.ts
1869
+ var import_qrcode_terminal = __toESM(require_main(), 1);
730
1870
  import { Chain, Vultisig as Vultisig2 } from "@vultisig/sdk";
731
1871
  async function executeSend(ctx2, params) {
732
1872
  const vault = await ctx2.ensureActiveVault();
@@ -782,17 +1922,48 @@ async function sendTransaction(vault, params) {
782
1922
  }
783
1923
  }
784
1924
  await ensureVaultUnlocked(vault, params.password);
785
- const signSpinner = createSpinner("Signing transaction...");
1925
+ const isSecureVault = vault.type === "secure";
1926
+ const signSpinner = createSpinner(isSecureVault ? "Preparing secure signing session..." : "Signing transaction...");
786
1927
  vault.on("signingProgress", ({ step }) => {
787
1928
  signSpinner.text = `${step.message} (${step.progress}%)`;
788
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
+ }
789
1957
  try {
790
1958
  const messageHashes = await vault.extractMessageHashes(payload);
791
- const signature = await vault.sign({
792
- transaction: payload,
793
- chain: payload.coin.chain,
794
- messageHashes
795
- });
1959
+ const signature = await vault.sign(
1960
+ {
1961
+ transaction: payload,
1962
+ chain: payload.coin.chain,
1963
+ messageHashes
1964
+ },
1965
+ { signal: params.signal }
1966
+ );
796
1967
  signSpinner.succeed("Transaction signed");
797
1968
  const broadcastSpinner = createSpinner("Broadcasting transaction...");
798
1969
  const txHash = await vault.broadcastTx({
@@ -814,198 +1985,179 @@ async function sendTransaction(vault, params) {
814
1985
  return result;
815
1986
  } finally {
816
1987
  vault.removeAllListeners("signingProgress");
1988
+ if (isSecureVault) {
1989
+ vault.removeAllListeners("qrCodeReady");
1990
+ vault.removeAllListeners("deviceJoined");
1991
+ }
817
1992
  }
818
1993
  }
819
1994
 
820
1995
  // src/commands/vault-management.ts
1996
+ var import_qrcode_terminal2 = __toESM(require_main(), 1);
821
1997
  import chalk5 from "chalk";
822
1998
  import { promises as fs } from "fs";
823
1999
  import inquirer4 from "inquirer";
824
- async function executeCreate(ctx2, options = { type: "fast" }) {
825
- const vaultType = options.type.toLowerCase();
826
- if (vaultType !== "fast" && vaultType !== "secure") {
827
- throw new Error('Invalid vault type. Must be "fast" or "secure"');
828
- }
829
- let name = options.name;
830
- let password = options.password;
831
- const prompts = [];
832
- if (!name) {
833
- prompts.push({
834
- type: "input",
835
- name: "name",
836
- message: "Enter vault name:",
837
- validate: (input) => input.trim() !== "" || "Name is required"
838
- });
839
- }
840
- if (!password) {
841
- prompts.push({
842
- type: "password",
843
- name: "password",
844
- message: "Enter password:",
845
- mask: "*",
846
- validate: (input) => input.length >= 8 || "Password must be at least 8 characters"
847
- });
848
- prompts.push({
849
- type: "password",
850
- name: "confirmPassword",
851
- message: "Confirm password:",
852
- mask: "*",
853
- validate: (input, ans) => input === ans.password || "Passwords do not match"
854
- });
855
- }
856
- if (prompts.length > 0) {
857
- const answers = await inquirer4.prompt(prompts);
858
- name = name || answers.name;
859
- password = password || answers.password;
860
- }
861
- if (vaultType === "fast") {
862
- let email = options.email;
863
- if (!email) {
864
- const emailAnswer = await inquirer4.prompt([
865
- {
866
- type: "input",
867
- name: "email",
868
- message: "Enter email for verification:",
869
- validate: (input) => /\S+@\S+\.\S+/.test(input) || "Invalid email format"
870
- }
871
- ]);
872
- email = emailAnswer.email;
873
- }
874
- const spinner = createSpinner("Creating vault...");
875
- 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({
876
2015
  name,
877
2016
  password,
878
2017
  email,
879
2018
  onProgress: (step) => {
880
2019
  spinner.text = `${step.message} (${step.progress}%)`;
881
2020
  }
882
- });
883
- spinner.succeed(`Vault keys generated: ${name}`);
884
- warn("\nA verification code has been sent to your email.");
885
- info("Please check your inbox and enter the code.");
886
- const MAX_VERIFY_ATTEMPTS = 5;
887
- let attempts = 0;
888
- while (attempts < MAX_VERIFY_ATTEMPTS) {
889
- attempts++;
890
- 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([
891
2063
  {
892
- type: "input",
893
- name: "code",
894
- message: `Verification code sent to ${email}. Enter code:`,
895
- 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
+ ]
896
2072
  }
897
2073
  ]);
898
- const verifySpinner = createSpinner("Verifying email code...");
899
- try {
900
- const vault = await ctx2.sdk.verifyVault(vaultId, codeAnswer.code);
901
- verifySpinner.succeed("Email verified successfully!");
902
- setupVaultEvents(vault);
903
- await ctx2.setActiveVault(vault);
904
- success("\n+ Vault created!");
905
- info("\nYour vault is ready. Run the following commands:");
906
- printResult(chalk5.cyan(" vultisig balance ") + "- View balances");
907
- printResult(chalk5.cyan(" vultisig addresses ") + "- View addresses");
908
- printResult(chalk5.cyan(" vultisig portfolio ") + "- View portfolio value");
909
- return vault;
910
- } catch (err) {
911
- verifySpinner.fail("Verification failed");
912
- error(`
913
- \u2717 ${err.message || "Invalid verification code"}`);
914
- if (attempts >= MAX_VERIFY_ATTEMPTS) {
915
- warn("\nMaximum attempts reached.");
916
- warn("\nTo retry verification later, use:");
917
- info(` vultisig verify ${vaultId}`);
918
- err.exitCode = 1;
919
- throw err;
920
- }
921
- const { action } = await inquirer4.prompt([
922
- {
923
- type: "list",
924
- name: "action",
925
- message: `What would you like to do? (${MAX_VERIFY_ATTEMPTS - attempts} attempts remaining)`,
926
- choices: [
927
- { name: "Enter a different code", value: "retry" },
928
- { name: "Resend verification email (rate limited)", value: "resend" },
929
- { name: "Abort and verify later", value: "abort" }
930
- ]
931
- }
932
- ]);
933
- if (action === "abort") {
934
- warn("\nVault creation paused. To complete verification, use:");
935
- info(` vultisig verify ${vaultId}`);
936
- warn("\nNote: The pending vault is stored in memory only and will be lost if you exit.");
937
- return void 0;
938
- }
939
- if (action === "resend") {
940
- const resendSpinner = createSpinner("Resending verification email...");
941
- try {
942
- await ctx2.sdk.resendVaultVerification(vaultId);
943
- resendSpinner.succeed("Verification email sent!");
944
- info("Check your inbox for the new code. Note: There may be a ~3 minute cooldown between resends.");
945
- } catch (resendErr) {
946
- resendSpinner.fail("Failed to resend");
947
- warn(resendErr.message || "Could not resend email. You may need to wait a few minutes.");
948
- }
949
- }
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;
950
2079
  }
951
- }
952
- throw new Error("Verification loop exited unexpectedly");
953
- } else {
954
- let threshold = options.threshold;
955
- let totalShares = options.shares;
956
- const securePrompts = [];
957
- if (threshold === void 0) {
958
- securePrompts.push({
959
- type: "number",
960
- name: "threshold",
961
- message: "Signing threshold (m):",
962
- default: 2,
963
- validate: (input) => input > 0 || "Threshold must be greater than 0"
964
- });
965
- }
966
- if (totalShares === void 0) {
967
- securePrompts.push({
968
- type: "number",
969
- name: "totalShares",
970
- message: "Total shares (n):",
971
- default: 3,
972
- validate: (input, ans) => {
973
- const t = threshold ?? ans.threshold;
974
- 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.");
975
2089
  }
976
- });
977
- }
978
- if (securePrompts.length > 0) {
979
- const secureAnswers = await inquirer4.prompt(securePrompts);
980
- threshold = threshold ?? secureAnswers.threshold;
981
- totalShares = totalShares ?? secureAnswers.totalShares;
2090
+ }
982
2091
  }
983
- const spinner = createSpinner("Creating secure vault...");
984
- try {
985
- 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({
986
2101
  name,
987
2102
  password,
988
2103
  devices: totalShares,
989
2104
  threshold,
990
2105
  onProgress: (step) => {
991
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
+ }
992
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
993
2147
  });
994
- setupVaultEvents(result.vault);
995
- await ctx2.setActiveVault(result.vault);
996
- spinner.succeed(`Secure vault created: ${name} (${threshold}-of-${totalShares})`);
997
- warn(`
998
- Important: Save your vault backup file (.vult) in a secure location.`);
999
- warn(`This is a ${threshold}-of-${totalShares} vault. You'll need ${threshold} devices to sign transactions.`);
1000
- success("\n+ Vault created!");
1001
2148
  return result.vault;
1002
- } catch (err) {
1003
- spinner.fail("Secure vault creation failed");
1004
- if (err.message?.includes("not implemented")) {
1005
- warn("\nSecure vault creation is not yet implemented in the SDK");
1006
- }
1007
- throw err;
1008
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;
1009
2161
  }
1010
2162
  }
1011
2163
  async function executeImport(ctx2, file) {
@@ -1284,11 +2436,14 @@ async function executeSwap(ctx2, options) {
1284
2436
  });
1285
2437
  try {
1286
2438
  const approvalHashes = await vault.extractMessageHashes(approvalPayload);
1287
- const approvalSig = await vault.sign({
1288
- transaction: approvalPayload,
1289
- chain: options.fromChain,
1290
- messageHashes: approvalHashes
1291
- });
2439
+ const approvalSig = await vault.sign(
2440
+ {
2441
+ transaction: approvalPayload,
2442
+ chain: options.fromChain,
2443
+ messageHashes: approvalHashes
2444
+ },
2445
+ { signal: options.signal }
2446
+ );
1292
2447
  approvalSpinner.succeed("Approval signed");
1293
2448
  const broadcastApprovalSpinner = createSpinner("Broadcasting approval...");
1294
2449
  const approvalTxHash = await vault.broadcastTx({
@@ -1309,11 +2464,14 @@ async function executeSwap(ctx2, options) {
1309
2464
  });
1310
2465
  try {
1311
2466
  const messageHashes = await vault.extractMessageHashes(keysignPayload);
1312
- const signature = await vault.sign({
1313
- transaction: keysignPayload,
1314
- chain: options.fromChain,
1315
- messageHashes
1316
- });
2467
+ const signature = await vault.sign(
2468
+ {
2469
+ transaction: keysignPayload,
2470
+ chain: options.fromChain,
2471
+ messageHashes
2472
+ },
2473
+ { signal: options.signal }
2474
+ );
1317
2475
  signSpinner.succeed("Swap transaction signed");
1318
2476
  const broadcastSpinner = createSpinner("Broadcasting swap transaction...");
1319
2477
  const txHash = await vault.broadcastTx({
@@ -2076,6 +3234,12 @@ function createShellContext(sdk, options) {
2076
3234
  }
2077
3235
 
2078
3236
  // src/interactive/session.ts
3237
+ var PromptCancelledError = class extends Error {
3238
+ name = "PromptCancelledError";
3239
+ constructor() {
3240
+ super("Prompt cancelled");
3241
+ }
3242
+ };
2079
3243
  function createSpinner2(text) {
2080
3244
  return ora3({
2081
3245
  text,
@@ -2088,6 +3252,9 @@ function createSpinner2(text) {
2088
3252
  var ShellSession = class {
2089
3253
  ctx;
2090
3254
  eventBuffer;
3255
+ lastSigintTime = 0;
3256
+ DOUBLE_CTRL_C_TIMEOUT = 2e3;
3257
+ // 2 seconds
2091
3258
  constructor(sdk, options) {
2092
3259
  this.ctx = createShellContext(sdk, options);
2093
3260
  this.eventBuffer = new EventBuffer();
@@ -2133,19 +3300,135 @@ var ShellSession = class {
2133
3300
  resolve(answer);
2134
3301
  });
2135
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)"));
2136
3312
  rl.close();
2137
- console.log(chalk9.yellow("\nGoodbye!"));
2138
- this.ctx.dispose();
2139
- process.exit(0);
3313
+ resolve("");
2140
3314
  });
2141
3315
  });
2142
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());
3369
+ });
3370
+ });
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
+ }
2143
3425
  /**
2144
3426
  * Process a line of input
2145
3427
  */
2146
3428
  async processLine(line) {
2147
3429
  const input = line.trim();
2148
3430
  if (!input) return;
3431
+ this.lastSigintTime = 0;
2149
3432
  const [command, ...args] = input.split(/\s+/);
2150
3433
  try {
2151
3434
  this.eventBuffer.startCommand();
@@ -2153,6 +3436,13 @@ var ShellSession = class {
2153
3436
  this.eventBuffer.endCommand();
2154
3437
  } catch (error2) {
2155
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
+ }
2156
3446
  console.error(chalk9.red(`
2157
3447
  Error: ${error2.message}`));
2158
3448
  }
@@ -2173,7 +3463,7 @@ Error: ${error2.message}`));
2173
3463
  await this.importVault(args);
2174
3464
  break;
2175
3465
  case "create":
2176
- await this.createVault();
3466
+ await this.createVault(args);
2177
3467
  break;
2178
3468
  case "info":
2179
3469
  await executeInfo(this.ctx);
@@ -2295,18 +3585,75 @@ Error: ${error2.message}`));
2295
3585
  this.ctx.addVault(vault);
2296
3586
  this.eventBuffer.setupVaultListeners(vault);
2297
3587
  }
2298
- async createVault() {
2299
- const vault = await executeCreate(this.ctx, { type: "fast" });
2300
- this.ctx.addVault(vault);
2301
- 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
+ }
2302
3647
  }
2303
3648
  async runBalance(args) {
2304
3649
  const chainStr = args[0];
2305
3650
  const includeTokens = args.includes("-t") || args.includes("--tokens");
2306
- await executeBalance(this.ctx, {
2307
- chain: chainStr ? findChainByName(chainStr) || chainStr : void 0,
2308
- includeTokens
2309
- });
3651
+ await this.withCancellation(
3652
+ () => executeBalance(this.ctx, {
3653
+ chain: chainStr ? findChainByName(chainStr) || chainStr : void 0,
3654
+ includeTokens
3655
+ })
3656
+ );
2310
3657
  }
2311
3658
  async runPortfolio(args) {
2312
3659
  let currency = "usd";
@@ -2321,7 +3668,7 @@ Error: ${error2.message}`));
2321
3668
  console.log(chalk9.yellow(`Supported currencies: ${fiatCurrencies3.join(", ")}`));
2322
3669
  return;
2323
3670
  }
2324
- await executePortfolio(this.ctx, { currency });
3671
+ await this.withCancellation(() => executePortfolio(this.ctx, { currency }));
2325
3672
  }
2326
3673
  async runSend(args) {
2327
3674
  if (args.length < 3) {
@@ -2342,9 +3689,9 @@ Error: ${error2.message}`));
2342
3689
  }
2343
3690
  }
2344
3691
  try {
2345
- await executeSend(this.ctx, { chain, to, amount, tokenId, memo });
3692
+ await this.withAbortHandler((signal) => executeSend(this.ctx, { chain, to, amount, tokenId, memo, signal }));
2346
3693
  } catch (err) {
2347
- if (err.message === "Transaction cancelled by user") {
3694
+ if (err.message === "Transaction cancelled by user" || err.message === "Operation cancelled" || err.message === "Operation aborted") {
2348
3695
  console.log(chalk9.yellow("\nTransaction cancelled"));
2349
3696
  return;
2350
3697
  }
@@ -2419,7 +3766,7 @@ Error: ${error2.message}`));
2419
3766
  i++;
2420
3767
  }
2421
3768
  }
2422
- await executeSwapQuote(this.ctx, { fromChain, toChain, amount, fromToken, toToken });
3769
+ await this.withCancellation(() => executeSwapQuote(this.ctx, { fromChain, toChain, amount, fromToken, toToken }));
2423
3770
  }
2424
3771
  async runSwap(args) {
2425
3772
  if (args.length < 3) {
@@ -2450,9 +3797,11 @@ Error: ${error2.message}`));
2450
3797
  }
2451
3798
  }
2452
3799
  try {
2453
- 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
+ );
2454
3803
  } catch (err) {
2455
- if (err.message === "Swap cancelled by user") {
3804
+ if (err.message === "Swap cancelled by user" || err.message === "Operation cancelled" || err.message === "Operation aborted") {
2456
3805
  console.log(chalk9.yellow("\nSwap cancelled"));
2457
3806
  return;
2458
3807
  }
@@ -2551,7 +3900,7 @@ var cachedVersion = null;
2551
3900
  function getVersion() {
2552
3901
  if (cachedVersion) return cachedVersion;
2553
3902
  if (true) {
2554
- cachedVersion = "0.2.0-alpha.6";
3903
+ cachedVersion = "0.2.0-alpha.7";
2555
3904
  return cachedVersion;
2556
3905
  }
2557
3906
  try {
@@ -3043,20 +4392,23 @@ async function init(vaultOverride) {
3043
4392
  }
3044
4393
  return ctx;
3045
4394
  }
3046
- 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(
3047
- withExit(
3048
- async (options) => {
3049
- const context = await init(program.opts().vault);
3050
- await executeCreate(context, {
3051
- type: options.type,
3052
- name: options.name,
3053
- password: options.password,
3054
- email: options.email,
3055
- threshold: options.threshold ? parseInt(options.threshold, 10) : void 0,
3056
- shares: options.shares ? parseInt(options.shares, 10) : void 0
3057
- });
3058
- }
3059
- )
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
+ })
3060
4412
  );
3061
4413
  program.command("import <file>").description("Import vault from .vult file").action(
3062
4414
  withExit(async (file) => {
@@ -3291,12 +4643,14 @@ async function startInteractiveMode() {
3291
4643
  const session = new ShellSession(sdk);
3292
4644
  await session.start();
3293
4645
  }
4646
+ var isInteractiveMode = process.argv.includes("-i") || process.argv.includes("--interactive");
3294
4647
  process.on("SIGINT", () => {
4648
+ if (isInteractiveMode) return;
3295
4649
  warn("\n\nShutting down...");
3296
4650
  ctx?.dispose();
3297
4651
  process.exit(0);
3298
4652
  });
3299
- if (process.argv.includes("-i") || process.argv.includes("--interactive")) {
4653
+ if (isInteractiveMode) {
3300
4654
  startInteractiveMode().catch((err) => {
3301
4655
  error(`Failed to start interactive mode: ${err.message}`);
3302
4656
  process.exit(1);