@vultisig/cli 0.2.0-alpha.6 → 0.2.0-beta.8
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/CHANGELOG.md +39 -0
- package/README.md +95 -2
- package/dist/index.js +1644 -259
- package/package.json +3 -3
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,32 +1251,78 @@ 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
|
-
|
|
1307
|
+
const spinner2 = createNoopSpinner(text);
|
|
1308
|
+
activeSpinners.add(spinner2);
|
|
1309
|
+
return spinner2;
|
|
173
1310
|
}
|
|
174
|
-
|
|
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
|
|
1317
|
+
var passwordCache = /* @__PURE__ */ new Map();
|
|
1318
|
+
function cachePassword(vaultIdOrName, password) {
|
|
1319
|
+
passwordCache.set(vaultIdOrName, password);
|
|
1320
|
+
}
|
|
1321
|
+
function getCachedPassword(vaultId, vaultName) {
|
|
1322
|
+
if (vaultName && passwordCache.has(vaultName)) return passwordCache.get(vaultName);
|
|
1323
|
+
if (passwordCache.has(vaultId)) return passwordCache.get(vaultId);
|
|
1324
|
+
return null;
|
|
1325
|
+
}
|
|
178
1326
|
function parseVaultPasswords() {
|
|
179
1327
|
const passwordMap = /* @__PURE__ */ new Map();
|
|
180
1328
|
const passwordsEnv = process.env.VAULT_PASSWORDS;
|
|
@@ -217,14 +1365,23 @@ async function promptForPassword(vaultName, vaultId) {
|
|
|
217
1365
|
return password;
|
|
218
1366
|
}
|
|
219
1367
|
async function getPassword(vaultId, vaultName) {
|
|
1368
|
+
const cachedPassword = getCachedPassword(vaultId, vaultName);
|
|
1369
|
+
if (cachedPassword) {
|
|
1370
|
+
return cachedPassword;
|
|
1371
|
+
}
|
|
220
1372
|
const envPassword = getPasswordFromEnv(vaultId, vaultName);
|
|
221
1373
|
if (envPassword) {
|
|
1374
|
+
cachePassword(vaultId, envPassword);
|
|
1375
|
+
if (vaultName) cachePassword(vaultName, envPassword);
|
|
222
1376
|
return envPassword;
|
|
223
1377
|
}
|
|
224
1378
|
if (isSilent() || isJsonOutput()) {
|
|
225
1379
|
throw new Error("Password required but not provided. Set VAULT_PASSWORD or VAULT_PASSWORDS environment variable.");
|
|
226
1380
|
}
|
|
227
|
-
|
|
1381
|
+
const password = await promptForPassword(vaultName, vaultId);
|
|
1382
|
+
cachePassword(vaultId, password);
|
|
1383
|
+
if (vaultName) cachePassword(vaultName, password);
|
|
1384
|
+
return password;
|
|
228
1385
|
}
|
|
229
1386
|
function createPasswordCallback() {
|
|
230
1387
|
return async (vaultId, vaultName) => {
|
|
@@ -727,6 +1884,7 @@ Use --add <contractAddress> to add or --remove <tokenId> to remove`));
|
|
|
727
1884
|
}
|
|
728
1885
|
|
|
729
1886
|
// src/commands/transaction.ts
|
|
1887
|
+
var import_qrcode_terminal = __toESM(require_main(), 1);
|
|
730
1888
|
import { Chain, Vultisig as Vultisig2 } from "@vultisig/sdk";
|
|
731
1889
|
async function executeSend(ctx2, params) {
|
|
732
1890
|
const vault = await ctx2.ensureActiveVault();
|
|
@@ -782,17 +1940,48 @@ async function sendTransaction(vault, params) {
|
|
|
782
1940
|
}
|
|
783
1941
|
}
|
|
784
1942
|
await ensureVaultUnlocked(vault, params.password);
|
|
785
|
-
const
|
|
1943
|
+
const isSecureVault = vault.type === "secure";
|
|
1944
|
+
const signSpinner = createSpinner(isSecureVault ? "Preparing secure signing session..." : "Signing transaction...");
|
|
786
1945
|
vault.on("signingProgress", ({ step }) => {
|
|
787
1946
|
signSpinner.text = `${step.message} (${step.progress}%)`;
|
|
788
1947
|
});
|
|
1948
|
+
if (isSecureVault) {
|
|
1949
|
+
vault.on("qrCodeReady", ({ qrPayload }) => {
|
|
1950
|
+
if (isJsonOutput()) {
|
|
1951
|
+
printResult(qrPayload);
|
|
1952
|
+
} else if (isSilent()) {
|
|
1953
|
+
printResult(`QR Payload: ${qrPayload}`);
|
|
1954
|
+
} else {
|
|
1955
|
+
signSpinner.stop();
|
|
1956
|
+
info("\nScan this QR code with your Vultisig mobile app to sign:");
|
|
1957
|
+
import_qrcode_terminal.default.generate(qrPayload, { small: true });
|
|
1958
|
+
info(`
|
|
1959
|
+
Or use this URL: ${qrPayload}
|
|
1960
|
+
`);
|
|
1961
|
+
signSpinner.start("Waiting for devices to join signing session...");
|
|
1962
|
+
}
|
|
1963
|
+
});
|
|
1964
|
+
vault.on(
|
|
1965
|
+
"deviceJoined",
|
|
1966
|
+
({ deviceId, totalJoined, required }) => {
|
|
1967
|
+
if (!isSilent()) {
|
|
1968
|
+
signSpinner.text = `Device joined: ${totalJoined}/${required} (${deviceId})`;
|
|
1969
|
+
} else if (!isJsonOutput()) {
|
|
1970
|
+
printResult(`Device joined: ${totalJoined}/${required}`);
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
);
|
|
1974
|
+
}
|
|
789
1975
|
try {
|
|
790
1976
|
const messageHashes = await vault.extractMessageHashes(payload);
|
|
791
|
-
const signature = await vault.sign(
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
1977
|
+
const signature = await vault.sign(
|
|
1978
|
+
{
|
|
1979
|
+
transaction: payload,
|
|
1980
|
+
chain: payload.coin.chain,
|
|
1981
|
+
messageHashes
|
|
1982
|
+
},
|
|
1983
|
+
{ signal: params.signal }
|
|
1984
|
+
);
|
|
796
1985
|
signSpinner.succeed("Transaction signed");
|
|
797
1986
|
const broadcastSpinner = createSpinner("Broadcasting transaction...");
|
|
798
1987
|
const txHash = await vault.broadcastTx({
|
|
@@ -814,198 +2003,180 @@ async function sendTransaction(vault, params) {
|
|
|
814
2003
|
return result;
|
|
815
2004
|
} finally {
|
|
816
2005
|
vault.removeAllListeners("signingProgress");
|
|
2006
|
+
if (isSecureVault) {
|
|
2007
|
+
vault.removeAllListeners("qrCodeReady");
|
|
2008
|
+
vault.removeAllListeners("deviceJoined");
|
|
2009
|
+
}
|
|
817
2010
|
}
|
|
818
2011
|
}
|
|
819
2012
|
|
|
820
2013
|
// src/commands/vault-management.ts
|
|
2014
|
+
var import_qrcode_terminal2 = __toESM(require_main(), 1);
|
|
821
2015
|
import chalk5 from "chalk";
|
|
822
2016
|
import { promises as fs } from "fs";
|
|
823
2017
|
import inquirer4 from "inquirer";
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
if (
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
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({
|
|
2018
|
+
import path from "path";
|
|
2019
|
+
function withAbortSignal(promise, signal) {
|
|
2020
|
+
if (!signal) return promise;
|
|
2021
|
+
return Promise.race([
|
|
2022
|
+
promise,
|
|
2023
|
+
new Promise((_, reject) => {
|
|
2024
|
+
if (signal.aborted) reject(new Error("Operation cancelled"));
|
|
2025
|
+
signal.addEventListener("abort", () => reject(new Error("Operation cancelled")), { once: true });
|
|
2026
|
+
})
|
|
2027
|
+
]);
|
|
2028
|
+
}
|
|
2029
|
+
async function executeCreateFast(ctx2, options) {
|
|
2030
|
+
const { name, password, email, signal } = options;
|
|
2031
|
+
const spinner = createSpinner("Creating vault...");
|
|
2032
|
+
const vaultId = await withAbortSignal(
|
|
2033
|
+
ctx2.sdk.createFastVault({
|
|
876
2034
|
name,
|
|
877
2035
|
password,
|
|
878
2036
|
email,
|
|
879
2037
|
onProgress: (step) => {
|
|
880
2038
|
spinner.text = `${step.message} (${step.progress}%)`;
|
|
881
2039
|
}
|
|
882
|
-
})
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
2040
|
+
}),
|
|
2041
|
+
signal
|
|
2042
|
+
);
|
|
2043
|
+
spinner.succeed(`Vault keys generated: ${name}`);
|
|
2044
|
+
warn("\nA verification code has been sent to your email.");
|
|
2045
|
+
info("Please check your inbox and enter the code.");
|
|
2046
|
+
const MAX_VERIFY_ATTEMPTS = 5;
|
|
2047
|
+
let attempts = 0;
|
|
2048
|
+
while (attempts < MAX_VERIFY_ATTEMPTS) {
|
|
2049
|
+
attempts++;
|
|
2050
|
+
const codeAnswer = await inquirer4.prompt([
|
|
2051
|
+
{
|
|
2052
|
+
type: "input",
|
|
2053
|
+
name: "code",
|
|
2054
|
+
message: `Verification code sent to ${email}. Enter code:`,
|
|
2055
|
+
validate: (input) => /^\d{4,6}$/.test(input) || "Code must be 4-6 digits"
|
|
2056
|
+
}
|
|
2057
|
+
]);
|
|
2058
|
+
const verifySpinner = createSpinner("Verifying email code...");
|
|
2059
|
+
try {
|
|
2060
|
+
const vault = await ctx2.sdk.verifyVault(vaultId, codeAnswer.code);
|
|
2061
|
+
verifySpinner.succeed("Email verified successfully!");
|
|
2062
|
+
setupVaultEvents(vault);
|
|
2063
|
+
await ctx2.setActiveVault(vault);
|
|
2064
|
+
success("\n+ Vault created!");
|
|
2065
|
+
info("\nYour vault is ready. Run the following commands:");
|
|
2066
|
+
printResult(chalk5.cyan(" vultisig balance ") + "- View balances");
|
|
2067
|
+
printResult(chalk5.cyan(" vultisig addresses ") + "- View addresses");
|
|
2068
|
+
printResult(chalk5.cyan(" vultisig portfolio ") + "- View portfolio value");
|
|
2069
|
+
return vault;
|
|
2070
|
+
} catch (err) {
|
|
2071
|
+
verifySpinner.fail("Verification failed");
|
|
2072
|
+
error(`
|
|
2073
|
+
\u2717 ${err.message || "Invalid verification code"}`);
|
|
2074
|
+
if (attempts >= MAX_VERIFY_ATTEMPTS) {
|
|
2075
|
+
warn("\nMaximum attempts reached.");
|
|
2076
|
+
warn("\nTo retry verification later, use:");
|
|
2077
|
+
info(` vultisig verify ${vaultId}`);
|
|
2078
|
+
err.exitCode = 1;
|
|
2079
|
+
throw err;
|
|
2080
|
+
}
|
|
2081
|
+
const { action } = await inquirer4.prompt([
|
|
891
2082
|
{
|
|
892
|
-
type: "
|
|
893
|
-
name: "
|
|
894
|
-
message: `
|
|
895
|
-
|
|
2083
|
+
type: "list",
|
|
2084
|
+
name: "action",
|
|
2085
|
+
message: `What would you like to do? (${MAX_VERIFY_ATTEMPTS - attempts} attempts remaining)`,
|
|
2086
|
+
choices: [
|
|
2087
|
+
{ name: "Enter a different code", value: "retry" },
|
|
2088
|
+
{ name: "Resend verification email (rate limited)", value: "resend" },
|
|
2089
|
+
{ name: "Abort and verify later", value: "abort" }
|
|
2090
|
+
]
|
|
896
2091
|
}
|
|
897
2092
|
]);
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
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
|
-
}
|
|
2093
|
+
if (action === "abort") {
|
|
2094
|
+
warn("\nVault creation paused. To complete verification, use:");
|
|
2095
|
+
info(` vultisig verify ${vaultId}`);
|
|
2096
|
+
warn("\nNote: The pending vault is stored in memory only and will be lost if you exit.");
|
|
2097
|
+
return void 0;
|
|
950
2098
|
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
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})`;
|
|
2099
|
+
if (action === "resend") {
|
|
2100
|
+
const resendSpinner = createSpinner("Resending verification email...");
|
|
2101
|
+
try {
|
|
2102
|
+
await ctx2.sdk.resendVaultVerification(vaultId);
|
|
2103
|
+
resendSpinner.succeed("Verification email sent!");
|
|
2104
|
+
info("Check your inbox for the new code. Note: There may be a ~3 minute cooldown between resends.");
|
|
2105
|
+
} catch (resendErr) {
|
|
2106
|
+
resendSpinner.fail("Failed to resend");
|
|
2107
|
+
warn(resendErr.message || "Could not resend email. You may need to wait a few minutes.");
|
|
975
2108
|
}
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
if (securePrompts.length > 0) {
|
|
979
|
-
const secureAnswers = await inquirer4.prompt(securePrompts);
|
|
980
|
-
threshold = threshold ?? secureAnswers.threshold;
|
|
981
|
-
totalShares = totalShares ?? secureAnswers.totalShares;
|
|
2109
|
+
}
|
|
982
2110
|
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
2111
|
+
}
|
|
2112
|
+
throw new Error("Verification loop exited unexpectedly");
|
|
2113
|
+
}
|
|
2114
|
+
async function executeCreateSecure(ctx2, options) {
|
|
2115
|
+
const { name, password, threshold, shares: totalShares, signal } = options;
|
|
2116
|
+
const spinner = createSpinner("Creating secure vault...");
|
|
2117
|
+
try {
|
|
2118
|
+
const result = await withAbortSignal(
|
|
2119
|
+
ctx2.sdk.createSecureVault({
|
|
986
2120
|
name,
|
|
987
2121
|
password,
|
|
988
2122
|
devices: totalShares,
|
|
989
2123
|
threshold,
|
|
990
2124
|
onProgress: (step) => {
|
|
991
2125
|
spinner.text = `${step.message} (${step.progress}%)`;
|
|
2126
|
+
},
|
|
2127
|
+
onQRCodeReady: (qrPayload) => {
|
|
2128
|
+
if (isJsonOutput()) {
|
|
2129
|
+
printResult(qrPayload);
|
|
2130
|
+
} else if (isSilent()) {
|
|
2131
|
+
printResult(`QR Payload: ${qrPayload}`);
|
|
2132
|
+
} else {
|
|
2133
|
+
spinner.stop();
|
|
2134
|
+
info("\nScan this QR code with your Vultisig mobile app:");
|
|
2135
|
+
import_qrcode_terminal2.default.generate(qrPayload, { small: true });
|
|
2136
|
+
info(`
|
|
2137
|
+
Or use this URL: ${qrPayload}
|
|
2138
|
+
`);
|
|
2139
|
+
info(chalk5.gray("(Press Ctrl+C to cancel)\n"));
|
|
2140
|
+
spinner.start(`Waiting for ${totalShares} devices to join...`);
|
|
2141
|
+
}
|
|
2142
|
+
},
|
|
2143
|
+
onDeviceJoined: (deviceId, totalJoined, required) => {
|
|
2144
|
+
if (!isSilent()) {
|
|
2145
|
+
spinner.text = `Device joined: ${totalJoined}/${required} (${deviceId})`;
|
|
2146
|
+
} else if (!isJsonOutput()) {
|
|
2147
|
+
printResult(`Device joined: ${totalJoined}/${required}`);
|
|
2148
|
+
}
|
|
992
2149
|
}
|
|
2150
|
+
}),
|
|
2151
|
+
signal
|
|
2152
|
+
);
|
|
2153
|
+
setupVaultEvents(result.vault);
|
|
2154
|
+
await ctx2.setActiveVault(result.vault);
|
|
2155
|
+
spinner.succeed(`Secure vault created: ${name} (${threshold}-of-${totalShares})`);
|
|
2156
|
+
if (isJsonOutput()) {
|
|
2157
|
+
outputJson({
|
|
2158
|
+
vault: {
|
|
2159
|
+
id: result.vaultId,
|
|
2160
|
+
name,
|
|
2161
|
+
type: "secure",
|
|
2162
|
+
threshold,
|
|
2163
|
+
totalSigners: totalShares
|
|
2164
|
+
},
|
|
2165
|
+
sessionId: result.sessionId
|
|
993
2166
|
});
|
|
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
2167
|
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
2168
|
}
|
|
2169
|
+
warn(`
|
|
2170
|
+
Important: Save your vault backup file (.vult) in a secure location.`);
|
|
2171
|
+
warn(`This is a ${threshold}-of-${totalShares} vault. You'll need ${threshold} devices to sign transactions.`);
|
|
2172
|
+
success("\n+ Vault created!");
|
|
2173
|
+
return result.vault;
|
|
2174
|
+
} catch (err) {
|
|
2175
|
+
spinner.fail("Secure vault creation failed");
|
|
2176
|
+
if (err.message?.includes("not implemented")) {
|
|
2177
|
+
warn("\nSecure vault creation is not yet implemented in the SDK");
|
|
2178
|
+
}
|
|
2179
|
+
throw err;
|
|
1009
2180
|
}
|
|
1010
2181
|
}
|
|
1011
2182
|
async function executeImport(ctx2, file) {
|
|
@@ -1066,38 +2237,47 @@ async function executeVerify(ctx2, vaultId, options = {}) {
|
|
|
1066
2237
|
}
|
|
1067
2238
|
async function executeExport(ctx2, options = {}) {
|
|
1068
2239
|
const vault = await ctx2.ensureActiveVault();
|
|
1069
|
-
let
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
2240
|
+
let exportPassword = options.exportPassword;
|
|
2241
|
+
if (exportPassword === void 0) {
|
|
2242
|
+
if (options.password !== void 0) {
|
|
2243
|
+
exportPassword = options.password;
|
|
2244
|
+
} else {
|
|
2245
|
+
const answer = await inquirer4.prompt([
|
|
2246
|
+
{
|
|
2247
|
+
type: "password",
|
|
2248
|
+
name: "exportPassword",
|
|
2249
|
+
message: "Enter password for export encryption (leave empty for no encryption):",
|
|
2250
|
+
mask: "*"
|
|
2251
|
+
}
|
|
2252
|
+
]);
|
|
2253
|
+
exportPassword = answer.exportPassword || void 0;
|
|
2254
|
+
}
|
|
1081
2255
|
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
2256
|
+
const spinner = createSpinner("Exporting vault...");
|
|
2257
|
+
const { data: vultContent, filename: sdkFilename } = await vault.export(exportPassword);
|
|
2258
|
+
let outputPath;
|
|
2259
|
+
if (options.outputPath) {
|
|
2260
|
+
const resolvedPath = path.resolve(options.outputPath);
|
|
2261
|
+
try {
|
|
2262
|
+
const stat = await fs.stat(resolvedPath);
|
|
2263
|
+
if (stat.isDirectory()) {
|
|
2264
|
+
outputPath = path.join(resolvedPath, sdkFilename);
|
|
2265
|
+
} else {
|
|
2266
|
+
outputPath = resolvedPath;
|
|
1089
2267
|
}
|
|
1090
|
-
|
|
1091
|
-
|
|
2268
|
+
} catch {
|
|
2269
|
+
outputPath = resolvedPath;
|
|
2270
|
+
}
|
|
2271
|
+
} else {
|
|
2272
|
+
outputPath = path.resolve(sdkFilename);
|
|
1092
2273
|
}
|
|
1093
|
-
const
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
spinner.succeed(`Vault exported: ${fileName}`);
|
|
2274
|
+
const parentDir = path.dirname(outputPath);
|
|
2275
|
+
await fs.mkdir(parentDir, { recursive: true });
|
|
2276
|
+
await fs.writeFile(outputPath, vultContent, "utf-8");
|
|
2277
|
+
spinner.succeed(`Vault exported: ${outputPath}`);
|
|
1098
2278
|
success("\n+ Vault exported successfully!");
|
|
1099
|
-
info(`File: ${
|
|
1100
|
-
return
|
|
2279
|
+
info(`File: ${outputPath}`);
|
|
2280
|
+
return outputPath;
|
|
1101
2281
|
}
|
|
1102
2282
|
async function executeVaults(ctx2) {
|
|
1103
2283
|
const spinner = createSpinner("Loading vaults...");
|
|
@@ -1284,11 +2464,14 @@ async function executeSwap(ctx2, options) {
|
|
|
1284
2464
|
});
|
|
1285
2465
|
try {
|
|
1286
2466
|
const approvalHashes = await vault.extractMessageHashes(approvalPayload);
|
|
1287
|
-
const approvalSig = await vault.sign(
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
2467
|
+
const approvalSig = await vault.sign(
|
|
2468
|
+
{
|
|
2469
|
+
transaction: approvalPayload,
|
|
2470
|
+
chain: options.fromChain,
|
|
2471
|
+
messageHashes: approvalHashes
|
|
2472
|
+
},
|
|
2473
|
+
{ signal: options.signal }
|
|
2474
|
+
);
|
|
1292
2475
|
approvalSpinner.succeed("Approval signed");
|
|
1293
2476
|
const broadcastApprovalSpinner = createSpinner("Broadcasting approval...");
|
|
1294
2477
|
const approvalTxHash = await vault.broadcastTx({
|
|
@@ -1309,11 +2492,14 @@ async function executeSwap(ctx2, options) {
|
|
|
1309
2492
|
});
|
|
1310
2493
|
try {
|
|
1311
2494
|
const messageHashes = await vault.extractMessageHashes(keysignPayload);
|
|
1312
|
-
const signature = await vault.sign(
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
2495
|
+
const signature = await vault.sign(
|
|
2496
|
+
{
|
|
2497
|
+
transaction: keysignPayload,
|
|
2498
|
+
chain: options.fromChain,
|
|
2499
|
+
messageHashes
|
|
2500
|
+
},
|
|
2501
|
+
{ signal: options.signal }
|
|
2502
|
+
);
|
|
1317
2503
|
signSpinner.succeed("Swap transaction signed");
|
|
1318
2504
|
const broadcastSpinner = createSpinner("Broadcasting swap transaction...");
|
|
1319
2505
|
const txHash = await vault.broadcastTx({
|
|
@@ -1486,7 +2672,7 @@ Address Book${options.chain ? ` (${options.chain})` : ""}:
|
|
|
1486
2672
|
// src/interactive/completer.ts
|
|
1487
2673
|
import { Chain as Chain3 } from "@vultisig/sdk";
|
|
1488
2674
|
import fs2 from "fs";
|
|
1489
|
-
import
|
|
2675
|
+
import path2 from "path";
|
|
1490
2676
|
var COMMANDS = [
|
|
1491
2677
|
// Vault management
|
|
1492
2678
|
"vaults",
|
|
@@ -1560,28 +2746,28 @@ function createCompleter(ctx2) {
|
|
|
1560
2746
|
}
|
|
1561
2747
|
function completeFilePath(partial, filterVult) {
|
|
1562
2748
|
try {
|
|
1563
|
-
const endsWithSeparator = partial.endsWith("/") || partial.endsWith(
|
|
2749
|
+
const endsWithSeparator = partial.endsWith("/") || partial.endsWith(path2.sep);
|
|
1564
2750
|
let dir;
|
|
1565
2751
|
let basename;
|
|
1566
2752
|
if (endsWithSeparator) {
|
|
1567
2753
|
dir = partial;
|
|
1568
2754
|
basename = "";
|
|
1569
2755
|
} else {
|
|
1570
|
-
dir =
|
|
1571
|
-
basename =
|
|
2756
|
+
dir = path2.dirname(partial);
|
|
2757
|
+
basename = path2.basename(partial);
|
|
1572
2758
|
if (fs2.existsSync(partial) && fs2.statSync(partial).isDirectory()) {
|
|
1573
2759
|
dir = partial;
|
|
1574
2760
|
basename = "";
|
|
1575
2761
|
}
|
|
1576
2762
|
}
|
|
1577
|
-
const resolvedDir =
|
|
2763
|
+
const resolvedDir = path2.resolve(dir);
|
|
1578
2764
|
if (!fs2.existsSync(resolvedDir) || !fs2.statSync(resolvedDir).isDirectory()) {
|
|
1579
2765
|
return [[], partial];
|
|
1580
2766
|
}
|
|
1581
2767
|
const files = fs2.readdirSync(resolvedDir);
|
|
1582
2768
|
const matches = files.filter((file) => file.startsWith(basename)).map((file) => {
|
|
1583
|
-
const fullPath =
|
|
1584
|
-
const stats = fs2.statSync(
|
|
2769
|
+
const fullPath = path2.join(dir, file);
|
|
2770
|
+
const stats = fs2.statSync(path2.join(resolvedDir, file));
|
|
1585
2771
|
if (stats.isDirectory()) {
|
|
1586
2772
|
return fullPath + "/";
|
|
1587
2773
|
}
|
|
@@ -2076,6 +3262,12 @@ function createShellContext(sdk, options) {
|
|
|
2076
3262
|
}
|
|
2077
3263
|
|
|
2078
3264
|
// src/interactive/session.ts
|
|
3265
|
+
var PromptCancelledError = class extends Error {
|
|
3266
|
+
name = "PromptCancelledError";
|
|
3267
|
+
constructor() {
|
|
3268
|
+
super("Prompt cancelled");
|
|
3269
|
+
}
|
|
3270
|
+
};
|
|
2079
3271
|
function createSpinner2(text) {
|
|
2080
3272
|
return ora3({
|
|
2081
3273
|
text,
|
|
@@ -2088,6 +3280,9 @@ function createSpinner2(text) {
|
|
|
2088
3280
|
var ShellSession = class {
|
|
2089
3281
|
ctx;
|
|
2090
3282
|
eventBuffer;
|
|
3283
|
+
lastSigintTime = 0;
|
|
3284
|
+
DOUBLE_CTRL_C_TIMEOUT = 2e3;
|
|
3285
|
+
// 2 seconds
|
|
2091
3286
|
constructor(sdk, options) {
|
|
2092
3287
|
this.ctx = createShellContext(sdk, options);
|
|
2093
3288
|
this.eventBuffer = new EventBuffer();
|
|
@@ -2133,19 +3328,135 @@ var ShellSession = class {
|
|
|
2133
3328
|
resolve(answer);
|
|
2134
3329
|
});
|
|
2135
3330
|
rl.on("SIGINT", () => {
|
|
3331
|
+
const now = Date.now();
|
|
3332
|
+
if (now - this.lastSigintTime < this.DOUBLE_CTRL_C_TIMEOUT) {
|
|
3333
|
+
rl.close();
|
|
3334
|
+
console.log(chalk9.yellow("\nGoodbye!"));
|
|
3335
|
+
this.ctx.dispose();
|
|
3336
|
+
process.exit(0);
|
|
3337
|
+
}
|
|
3338
|
+
this.lastSigintTime = now;
|
|
3339
|
+
console.log(chalk9.yellow("\n(Press Ctrl+C again to exit)"));
|
|
2136
3340
|
rl.close();
|
|
2137
|
-
|
|
2138
|
-
this.ctx.dispose();
|
|
2139
|
-
process.exit(0);
|
|
3341
|
+
resolve("");
|
|
2140
3342
|
});
|
|
2141
3343
|
});
|
|
2142
3344
|
}
|
|
3345
|
+
/**
|
|
3346
|
+
* Simple prompt for input (used within commands)
|
|
3347
|
+
*/
|
|
3348
|
+
prompt(message, defaultValue) {
|
|
3349
|
+
return new Promise((resolve, reject) => {
|
|
3350
|
+
const displayPrompt = defaultValue ? `${message} [${defaultValue}]: ` : `${message}: `;
|
|
3351
|
+
const rl = readline.createInterface({
|
|
3352
|
+
input: process.stdin,
|
|
3353
|
+
output: process.stdout,
|
|
3354
|
+
terminal: true
|
|
3355
|
+
});
|
|
3356
|
+
rl.question(displayPrompt, (answer) => {
|
|
3357
|
+
rl.close();
|
|
3358
|
+
resolve(answer.trim() || defaultValue || "");
|
|
3359
|
+
});
|
|
3360
|
+
rl.on("SIGINT", () => {
|
|
3361
|
+
rl.close();
|
|
3362
|
+
reject(new PromptCancelledError());
|
|
3363
|
+
});
|
|
3364
|
+
});
|
|
3365
|
+
}
|
|
3366
|
+
/**
|
|
3367
|
+
* Prompt for password input (masked)
|
|
3368
|
+
*/
|
|
3369
|
+
promptPassword(message) {
|
|
3370
|
+
return new Promise((resolve, reject) => {
|
|
3371
|
+
const rl = readline.createInterface({
|
|
3372
|
+
input: process.stdin,
|
|
3373
|
+
output: process.stdout,
|
|
3374
|
+
terminal: true
|
|
3375
|
+
});
|
|
3376
|
+
const stdin = process.stdin;
|
|
3377
|
+
const onData = (char) => {
|
|
3378
|
+
const c = char.toString();
|
|
3379
|
+
if (c === "\n" || c === "\r") return;
|
|
3380
|
+
if (c === "") return;
|
|
3381
|
+
if (c === "\x7F" || c === "\b") {
|
|
3382
|
+
process.stdout.write("\b \b");
|
|
3383
|
+
} else {
|
|
3384
|
+
process.stdout.write("*");
|
|
3385
|
+
}
|
|
3386
|
+
};
|
|
3387
|
+
stdin.on("data", onData);
|
|
3388
|
+
rl.question(`${message}: `, (answer) => {
|
|
3389
|
+
stdin.removeListener("data", onData);
|
|
3390
|
+
rl.close();
|
|
3391
|
+
resolve(answer);
|
|
3392
|
+
});
|
|
3393
|
+
rl.on("SIGINT", () => {
|
|
3394
|
+
stdin.removeListener("data", onData);
|
|
3395
|
+
rl.close();
|
|
3396
|
+
reject(new PromptCancelledError());
|
|
3397
|
+
});
|
|
3398
|
+
});
|
|
3399
|
+
}
|
|
3400
|
+
/**
|
|
3401
|
+
* Run an async operation with Ctrl+C cancellation support.
|
|
3402
|
+
* Uses Promise.race to avoid wrapping the original promise chain,
|
|
3403
|
+
* which can interfere with MPC protocol timing.
|
|
3404
|
+
*/
|
|
3405
|
+
withCancellation(fn) {
|
|
3406
|
+
const abortController = new AbortController();
|
|
3407
|
+
let rejectCancellation;
|
|
3408
|
+
const cancellationPromise = new Promise((_, reject) => {
|
|
3409
|
+
rejectCancellation = reject;
|
|
3410
|
+
});
|
|
3411
|
+
const onSigint = () => {
|
|
3412
|
+
cleanup();
|
|
3413
|
+
abortController.abort();
|
|
3414
|
+
rejectCancellation(new Error("Operation cancelled"));
|
|
3415
|
+
};
|
|
3416
|
+
const cleanup = () => {
|
|
3417
|
+
process.removeListener("SIGINT", onSigint);
|
|
3418
|
+
};
|
|
3419
|
+
process.on("SIGINT", onSigint);
|
|
3420
|
+
return Promise.race([fn(abortController.signal), cancellationPromise]).finally(cleanup);
|
|
3421
|
+
}
|
|
3422
|
+
/**
|
|
3423
|
+
* Run an async operation with Ctrl+C cancellation support.
|
|
3424
|
+
* Creates an AbortController and passes the signal to the operation.
|
|
3425
|
+
* On SIGINT, aborts the signal which causes the operation to throw.
|
|
3426
|
+
*/
|
|
3427
|
+
async withAbortHandler(fn) {
|
|
3428
|
+
const controller = new AbortController();
|
|
3429
|
+
const onSigint = () => {
|
|
3430
|
+
controller.abort();
|
|
3431
|
+
stopAllSpinners();
|
|
3432
|
+
process.stdout.write("\x1B[?25h");
|
|
3433
|
+
process.stdout.write("\r\x1B[K");
|
|
3434
|
+
console.log(chalk9.yellow("\nCancelling operation..."));
|
|
3435
|
+
};
|
|
3436
|
+
const cleanup = () => {
|
|
3437
|
+
process.removeListener("SIGINT", onSigint);
|
|
3438
|
+
};
|
|
3439
|
+
process.on("SIGINT", onSigint);
|
|
3440
|
+
try {
|
|
3441
|
+
const result = await fn(controller.signal);
|
|
3442
|
+
cleanup();
|
|
3443
|
+
return result;
|
|
3444
|
+
} catch (err) {
|
|
3445
|
+
cleanup();
|
|
3446
|
+
stopAllSpinners();
|
|
3447
|
+
if (controller.signal.aborted) {
|
|
3448
|
+
throw new Error("Operation aborted");
|
|
3449
|
+
}
|
|
3450
|
+
throw err;
|
|
3451
|
+
}
|
|
3452
|
+
}
|
|
2143
3453
|
/**
|
|
2144
3454
|
* Process a line of input
|
|
2145
3455
|
*/
|
|
2146
3456
|
async processLine(line) {
|
|
2147
3457
|
const input = line.trim();
|
|
2148
3458
|
if (!input) return;
|
|
3459
|
+
this.lastSigintTime = 0;
|
|
2149
3460
|
const [command, ...args] = input.split(/\s+/);
|
|
2150
3461
|
try {
|
|
2151
3462
|
this.eventBuffer.startCommand();
|
|
@@ -2153,6 +3464,13 @@ var ShellSession = class {
|
|
|
2153
3464
|
this.eventBuffer.endCommand();
|
|
2154
3465
|
} catch (error2) {
|
|
2155
3466
|
this.eventBuffer.endCommand();
|
|
3467
|
+
if (error2.name === "ExitPromptError" || error2.name === "PromptCancelledError" || error2.message === "Operation cancelled" || error2.message === "Operation aborted") {
|
|
3468
|
+
stopAllSpinners();
|
|
3469
|
+
process.stdout.write("\x1B[?25h");
|
|
3470
|
+
process.stdout.write("\r\x1B[K");
|
|
3471
|
+
console.log(chalk9.yellow("Operation cancelled"));
|
|
3472
|
+
return;
|
|
3473
|
+
}
|
|
2156
3474
|
console.error(chalk9.red(`
|
|
2157
3475
|
Error: ${error2.message}`));
|
|
2158
3476
|
}
|
|
@@ -2173,7 +3491,7 @@ Error: ${error2.message}`));
|
|
|
2173
3491
|
await this.importVault(args);
|
|
2174
3492
|
break;
|
|
2175
3493
|
case "create":
|
|
2176
|
-
await this.createVault();
|
|
3494
|
+
await this.createVault(args);
|
|
2177
3495
|
break;
|
|
2178
3496
|
case "info":
|
|
2179
3497
|
await executeInfo(this.ctx);
|
|
@@ -2295,18 +3613,75 @@ Error: ${error2.message}`));
|
|
|
2295
3613
|
this.ctx.addVault(vault);
|
|
2296
3614
|
this.eventBuffer.setupVaultListeners(vault);
|
|
2297
3615
|
}
|
|
2298
|
-
async createVault() {
|
|
2299
|
-
const
|
|
2300
|
-
|
|
2301
|
-
|
|
3616
|
+
async createVault(args) {
|
|
3617
|
+
const type = args[0]?.toLowerCase();
|
|
3618
|
+
if (!type || type !== "fast" && type !== "secure") {
|
|
3619
|
+
console.log(chalk9.yellow("Usage: create <fast|secure>"));
|
|
3620
|
+
console.log(chalk9.gray(" create fast - Create a fast vault (server-assisted 2-of-2)"));
|
|
3621
|
+
console.log(chalk9.gray(" create secure - Create a secure vault (multi-device MPC)"));
|
|
3622
|
+
return;
|
|
3623
|
+
}
|
|
3624
|
+
let vault;
|
|
3625
|
+
if (type === "fast") {
|
|
3626
|
+
const name = await this.prompt("Vault name");
|
|
3627
|
+
if (!name) {
|
|
3628
|
+
console.log(chalk9.red("Name is required"));
|
|
3629
|
+
return;
|
|
3630
|
+
}
|
|
3631
|
+
const password = await this.promptPassword("Vault password");
|
|
3632
|
+
if (!password) {
|
|
3633
|
+
console.log(chalk9.red("Password is required"));
|
|
3634
|
+
return;
|
|
3635
|
+
}
|
|
3636
|
+
const email = await this.prompt("Email for verification");
|
|
3637
|
+
if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
|
3638
|
+
console.log(chalk9.red("Valid email is required"));
|
|
3639
|
+
return;
|
|
3640
|
+
}
|
|
3641
|
+
vault = await this.withCancellation((signal) => executeCreateFast(this.ctx, { name, password, email, signal }));
|
|
3642
|
+
} else {
|
|
3643
|
+
const name = await this.prompt("Vault name");
|
|
3644
|
+
if (!name) {
|
|
3645
|
+
console.log(chalk9.red("Name is required"));
|
|
3646
|
+
return;
|
|
3647
|
+
}
|
|
3648
|
+
const sharesStr = await this.prompt("Total shares (devices)", "3");
|
|
3649
|
+
const shares = parseInt(sharesStr, 10);
|
|
3650
|
+
if (isNaN(shares) || shares < 2) {
|
|
3651
|
+
console.log(chalk9.red("Must have at least 2 shares"));
|
|
3652
|
+
return;
|
|
3653
|
+
}
|
|
3654
|
+
const thresholdStr = await this.prompt("Signing threshold", "2");
|
|
3655
|
+
const threshold = parseInt(thresholdStr, 10);
|
|
3656
|
+
if (isNaN(threshold) || threshold < 1 || threshold > shares) {
|
|
3657
|
+
console.log(chalk9.red(`Threshold must be between 1 and ${shares}`));
|
|
3658
|
+
return;
|
|
3659
|
+
}
|
|
3660
|
+
const password = await this.promptPassword("Vault password (optional, press Enter to skip)");
|
|
3661
|
+
vault = await this.withCancellation(
|
|
3662
|
+
(signal) => executeCreateSecure(this.ctx, {
|
|
3663
|
+
name,
|
|
3664
|
+
password: password || void 0,
|
|
3665
|
+
threshold,
|
|
3666
|
+
shares,
|
|
3667
|
+
signal
|
|
3668
|
+
})
|
|
3669
|
+
);
|
|
3670
|
+
}
|
|
3671
|
+
if (vault) {
|
|
3672
|
+
this.ctx.addVault(vault);
|
|
3673
|
+
this.eventBuffer.setupVaultListeners(vault);
|
|
3674
|
+
}
|
|
2302
3675
|
}
|
|
2303
3676
|
async runBalance(args) {
|
|
2304
3677
|
const chainStr = args[0];
|
|
2305
3678
|
const includeTokens = args.includes("-t") || args.includes("--tokens");
|
|
2306
|
-
await
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
3679
|
+
await this.withCancellation(
|
|
3680
|
+
() => executeBalance(this.ctx, {
|
|
3681
|
+
chain: chainStr ? findChainByName(chainStr) || chainStr : void 0,
|
|
3682
|
+
includeTokens
|
|
3683
|
+
})
|
|
3684
|
+
);
|
|
2310
3685
|
}
|
|
2311
3686
|
async runPortfolio(args) {
|
|
2312
3687
|
let currency = "usd";
|
|
@@ -2321,7 +3696,7 @@ Error: ${error2.message}`));
|
|
|
2321
3696
|
console.log(chalk9.yellow(`Supported currencies: ${fiatCurrencies3.join(", ")}`));
|
|
2322
3697
|
return;
|
|
2323
3698
|
}
|
|
2324
|
-
await executePortfolio(this.ctx, { currency });
|
|
3699
|
+
await this.withCancellation(() => executePortfolio(this.ctx, { currency }));
|
|
2325
3700
|
}
|
|
2326
3701
|
async runSend(args) {
|
|
2327
3702
|
if (args.length < 3) {
|
|
@@ -2342,9 +3717,9 @@ Error: ${error2.message}`));
|
|
|
2342
3717
|
}
|
|
2343
3718
|
}
|
|
2344
3719
|
try {
|
|
2345
|
-
await executeSend(this.ctx, { chain, to, amount, tokenId, memo });
|
|
3720
|
+
await this.withAbortHandler((signal) => executeSend(this.ctx, { chain, to, amount, tokenId, memo, signal }));
|
|
2346
3721
|
} catch (err) {
|
|
2347
|
-
if (err.message === "Transaction cancelled by user") {
|
|
3722
|
+
if (err.message === "Transaction cancelled by user" || err.message === "Operation cancelled" || err.message === "Operation aborted") {
|
|
2348
3723
|
console.log(chalk9.yellow("\nTransaction cancelled"));
|
|
2349
3724
|
return;
|
|
2350
3725
|
}
|
|
@@ -2419,7 +3794,7 @@ Error: ${error2.message}`));
|
|
|
2419
3794
|
i++;
|
|
2420
3795
|
}
|
|
2421
3796
|
}
|
|
2422
|
-
await executeSwapQuote(this.ctx, { fromChain, toChain, amount, fromToken, toToken });
|
|
3797
|
+
await this.withCancellation(() => executeSwapQuote(this.ctx, { fromChain, toChain, amount, fromToken, toToken }));
|
|
2423
3798
|
}
|
|
2424
3799
|
async runSwap(args) {
|
|
2425
3800
|
if (args.length < 3) {
|
|
@@ -2450,9 +3825,11 @@ Error: ${error2.message}`));
|
|
|
2450
3825
|
}
|
|
2451
3826
|
}
|
|
2452
3827
|
try {
|
|
2453
|
-
await
|
|
3828
|
+
await this.withAbortHandler(
|
|
3829
|
+
(signal) => executeSwap(this.ctx, { fromChain, toChain, amount, fromToken, toToken, slippage, signal })
|
|
3830
|
+
);
|
|
2454
3831
|
} catch (err) {
|
|
2455
|
-
if (err.message === "Swap cancelled by user") {
|
|
3832
|
+
if (err.message === "Swap cancelled by user" || err.message === "Operation cancelled" || err.message === "Operation aborted") {
|
|
2456
3833
|
console.log(chalk9.yellow("\nSwap cancelled"));
|
|
2457
3834
|
return;
|
|
2458
3835
|
}
|
|
@@ -2551,7 +3928,7 @@ var cachedVersion = null;
|
|
|
2551
3928
|
function getVersion() {
|
|
2552
3929
|
if (cachedVersion) return cachedVersion;
|
|
2553
3930
|
if (true) {
|
|
2554
|
-
cachedVersion = "0.2.0-
|
|
3931
|
+
cachedVersion = "0.2.0-beta.8";
|
|
2555
3932
|
return cachedVersion;
|
|
2556
3933
|
}
|
|
2557
3934
|
try {
|
|
@@ -3019,14 +4396,17 @@ async function findVaultByNameOrId(sdk, nameOrId) {
|
|
|
3019
4396
|
if (byPartialId) return byPartialId;
|
|
3020
4397
|
return null;
|
|
3021
4398
|
}
|
|
3022
|
-
async function init(vaultOverride) {
|
|
4399
|
+
async function init(vaultOverride, unlockPassword) {
|
|
3023
4400
|
if (!ctx) {
|
|
4401
|
+
const vaultSelector = vaultOverride || process.env.VULTISIG_VAULT;
|
|
4402
|
+
if (unlockPassword && vaultSelector) {
|
|
4403
|
+
cachePassword(vaultSelector, unlockPassword);
|
|
4404
|
+
}
|
|
3024
4405
|
const sdk = new Vultisig3({
|
|
3025
4406
|
onPasswordRequired: createPasswordCallback()
|
|
3026
4407
|
});
|
|
3027
4408
|
await sdk.initialize();
|
|
3028
4409
|
ctx = new CLIContext(sdk);
|
|
3029
|
-
const vaultSelector = vaultOverride || process.env.VULTISIG_VAULT;
|
|
3030
4410
|
let vault = null;
|
|
3031
4411
|
if (vaultSelector) {
|
|
3032
4412
|
vault = await findVaultByNameOrId(sdk, vaultSelector);
|
|
@@ -3043,20 +4423,23 @@ async function init(vaultOverride) {
|
|
|
3043
4423
|
}
|
|
3044
4424
|
return ctx;
|
|
3045
4425
|
}
|
|
3046
|
-
program.command("create").description("Create a
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
4426
|
+
var createCmd = program.command("create").description("Create a vault");
|
|
4427
|
+
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(
|
|
4428
|
+
withExit(async (options) => {
|
|
4429
|
+
const context = await init(program.opts().vault);
|
|
4430
|
+
await executeCreateFast(context, options);
|
|
4431
|
+
})
|
|
4432
|
+
);
|
|
4433
|
+
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(
|
|
4434
|
+
withExit(async (options) => {
|
|
4435
|
+
const context = await init(program.opts().vault);
|
|
4436
|
+
await executeCreateSecure(context, {
|
|
4437
|
+
name: options.name,
|
|
4438
|
+
password: options.password,
|
|
4439
|
+
threshold: parseInt(options.threshold, 10),
|
|
4440
|
+
shares: parseInt(options.shares, 10)
|
|
4441
|
+
});
|
|
4442
|
+
})
|
|
3060
4443
|
);
|
|
3061
4444
|
program.command("import <file>").description("Import vault from .vult file").action(
|
|
3062
4445
|
withExit(async (file) => {
|
|
@@ -3126,13 +4509,13 @@ program.command("server").description("Check server connectivity and status").ac
|
|
|
3126
4509
|
await executeServer(context);
|
|
3127
4510
|
})
|
|
3128
4511
|
);
|
|
3129
|
-
program.command("export [path]").description("Export vault to file").option("--
|
|
3130
|
-
withExit(async (
|
|
3131
|
-
const context = await init(program.opts().vault);
|
|
4512
|
+
program.command("export [path]").description("Export vault to file").option("--password <password>", "Password to unlock the vault (for encrypted vaults)").option("--exportPassword <password>", "Password to encrypt the exported file (defaults to --password)").action(
|
|
4513
|
+
withExit(async (path3, options) => {
|
|
4514
|
+
const context = await init(program.opts().vault, options.password);
|
|
3132
4515
|
await executeExport(context, {
|
|
3133
|
-
outputPath:
|
|
3134
|
-
|
|
3135
|
-
|
|
4516
|
+
outputPath: path3,
|
|
4517
|
+
password: options.password,
|
|
4518
|
+
exportPassword: options.exportPassword
|
|
3136
4519
|
});
|
|
3137
4520
|
})
|
|
3138
4521
|
);
|
|
@@ -3291,12 +4674,14 @@ async function startInteractiveMode() {
|
|
|
3291
4674
|
const session = new ShellSession(sdk);
|
|
3292
4675
|
await session.start();
|
|
3293
4676
|
}
|
|
4677
|
+
var isInteractiveMode = process.argv.includes("-i") || process.argv.includes("--interactive");
|
|
3294
4678
|
process.on("SIGINT", () => {
|
|
4679
|
+
if (isInteractiveMode) return;
|
|
3295
4680
|
warn("\n\nShutting down...");
|
|
3296
4681
|
ctx?.dispose();
|
|
3297
4682
|
process.exit(0);
|
|
3298
4683
|
});
|
|
3299
|
-
if (
|
|
4684
|
+
if (isInteractiveMode) {
|
|
3300
4685
|
startInteractiveMode().catch((err) => {
|
|
3301
4686
|
error(`Failed to start interactive mode: ${err.message}`);
|
|
3302
4687
|
process.exit(1);
|