@dvmkit/dvm-cli 0.19.2 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-MM646MFM.js → chunk-2B2MCZ2I.js} +3 -3
- package/dist/{chunk-NKD4NEUF.js → chunk-2YPUKPJN.js} +2 -2
- package/dist/{chunk-X6BETQ7V.js → chunk-4RINUKY4.js} +1 -0
- package/dist/{chunk-5ZY5IKS2.js → chunk-4S6TNP4N.js} +471 -154
- package/dist/{chunk-B5KW2TPR.js → chunk-DOAMK5C6.js} +1 -1
- package/dist/{chunk-3NXAIRFF.js → chunk-EEQPFGPM.js} +1 -1
- package/dist/{chunk-OCVRCWBL.js → chunk-MSQJWCPT.js} +2 -2
- package/dist/{chunk-7HJ5ZR3D.js → chunk-QXXPXQLM.js} +1 -1
- package/dist/{client-PY4T2DOA.js → client-FKYQXFBN.js} +2 -2
- package/dist/dvm.js +803 -325
- package/dist/{internal-WAQ3LZN4.js → internal-EQJXMIR2.js} +1 -1
- package/dist/{lifecycle-NOK3MKL4.js → lifecycle-3IBVUCTB.js} +2 -2
- package/dist/{pocket-refill-ETV6QWO6.js → pocket-refill-M65PPCN3.js} +6 -6
- package/dist/{tempo-lifecycle-QGJ4JEHN.js → tempo-lifecycle-Q3N5GGIQ.js} +4 -4
- package/dist/{tempo-wallet-GDDZZP5S.js → tempo-wallet-AY6R3E4Z.js} +3 -3
- package/dist/{wallet-2M3H75UP.js → wallet-J7JCMFZ2.js} +3 -3
- package/package.json +1 -1
- package/skills/dvm/calling.md +5 -1
- package/skills/dvm/credit.md +10 -2
- package/skills/dvm/recovery.md +6 -0
- package/skills/dvm/wallets.md +4 -0
package/dist/dvm.js
CHANGED
|
@@ -5,17 +5,18 @@ import {
|
|
|
5
5
|
assertTempoWalletIdle,
|
|
6
6
|
findSigningIdentityByPubkey,
|
|
7
7
|
resolveSigningIdentity
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-MSQJWCPT.js";
|
|
9
9
|
import {
|
|
10
|
-
CARD_MIN_MICRO,
|
|
11
10
|
DEFAULT_CREDIT_POSTURE,
|
|
12
11
|
DEFAULT_RESERVE_LOCKTIME_SECONDS,
|
|
13
12
|
JOB_READ_TIMEOUT_MS,
|
|
13
|
+
MINT_FEE_EXPLAINER,
|
|
14
14
|
MINT_QUOTE_EXPIRY_GRACE_MS,
|
|
15
15
|
NWC_FUNDING_FLOAT_ROLE,
|
|
16
16
|
SUBMISSION_EVIDENCE_DIR,
|
|
17
17
|
abandonPendingSubmission,
|
|
18
18
|
abandonSubmissionInWallet,
|
|
19
|
+
addCashuSwapFee,
|
|
19
20
|
addPayment,
|
|
20
21
|
answeredYieldSeqs,
|
|
21
22
|
appendMessages,
|
|
@@ -33,6 +34,8 @@ import {
|
|
|
33
34
|
captureDrawFundingReceipts,
|
|
34
35
|
captureFundingReceipt,
|
|
35
36
|
captureTransportReceipt,
|
|
37
|
+
cardMinimumMicro,
|
|
38
|
+
cashuPaymentFeeFields,
|
|
36
39
|
clearAskPaymentBlocks,
|
|
37
40
|
clearPaymentRequestInFlight,
|
|
38
41
|
clearReclaimIntent,
|
|
@@ -50,6 +53,7 @@ import {
|
|
|
50
53
|
declinedAskSeqs,
|
|
51
54
|
deriveAlias,
|
|
52
55
|
describeBudgetOverrun,
|
|
56
|
+
describeCashuPayment,
|
|
53
57
|
describeMintBounds,
|
|
54
58
|
dollarBoundUsdMicro,
|
|
55
59
|
drainReceiptsDisplay,
|
|
@@ -192,6 +196,7 @@ import {
|
|
|
192
196
|
settleRecordedPayments,
|
|
193
197
|
settlementCurrencyHint,
|
|
194
198
|
statusSnapshot,
|
|
199
|
+
submissionSwapFeeSats,
|
|
195
200
|
sweepPendingMints,
|
|
196
201
|
sweepStaleInFlight,
|
|
197
202
|
terminalSettlementFields,
|
|
@@ -218,13 +223,13 @@ import {
|
|
|
218
223
|
withJobTokenRedaction,
|
|
219
224
|
withRequestResultRecovery,
|
|
220
225
|
withoutPendingMint
|
|
221
|
-
} from "./chunk-
|
|
226
|
+
} from "./chunk-4S6TNP4N.js";
|
|
222
227
|
import {
|
|
223
228
|
connectedTempoAccount,
|
|
224
229
|
generateTempoKey,
|
|
225
230
|
tempoBalanceCheckHint,
|
|
226
231
|
tempoWrongAssetHint
|
|
227
|
-
} from "./chunk-
|
|
232
|
+
} from "./chunk-2B2MCZ2I.js";
|
|
228
233
|
import {
|
|
229
234
|
assertSupportedX402Network,
|
|
230
235
|
connectedX402Payer,
|
|
@@ -233,7 +238,7 @@ import {
|
|
|
233
238
|
repinX402WalletNetwork,
|
|
234
239
|
saveX402Wallet,
|
|
235
240
|
x402NetworkLabel
|
|
236
|
-
} from "./chunk-
|
|
241
|
+
} from "./chunk-2YPUKPJN.js";
|
|
237
242
|
import {
|
|
238
243
|
CREDIT_POSTURES,
|
|
239
244
|
FEEDBACK_POSTURES,
|
|
@@ -250,7 +255,7 @@ import {
|
|
|
250
255
|
retireConfigBackup,
|
|
251
256
|
rollbackConfig,
|
|
252
257
|
updateConfig
|
|
253
|
-
} from "./chunk-
|
|
258
|
+
} from "./chunk-EEQPFGPM.js";
|
|
254
259
|
import {
|
|
255
260
|
addOutputWarnings,
|
|
256
261
|
assertValidBudget,
|
|
@@ -273,10 +278,10 @@ import {
|
|
|
273
278
|
tryX402Payment,
|
|
274
279
|
withOutputWarningContext,
|
|
275
280
|
withOutputWarnings
|
|
276
|
-
} from "./chunk-
|
|
281
|
+
} from "./chunk-QXXPXQLM.js";
|
|
277
282
|
import {
|
|
278
283
|
assertX402WalletIdle
|
|
279
|
-
} from "./chunk-
|
|
284
|
+
} from "./chunk-DOAMK5C6.js";
|
|
280
285
|
import {
|
|
281
286
|
A,
|
|
282
287
|
AGENT_MNEMONIC_FILE,
|
|
@@ -346,6 +351,7 @@ import {
|
|
|
346
351
|
clean,
|
|
347
352
|
clearCreditSelection,
|
|
348
353
|
clearPendingDrain,
|
|
354
|
+
clearPendingFunding,
|
|
349
355
|
clearPendingX402Funding,
|
|
350
356
|
clearRefillRailUnavailable,
|
|
351
357
|
computeSmartDenominations,
|
|
@@ -503,6 +509,7 @@ import {
|
|
|
503
509
|
withinAdvertisedTolerance,
|
|
504
510
|
wrapCipher,
|
|
505
511
|
writeAgentMnemonic,
|
|
512
|
+
x,
|
|
506
513
|
x402ChannelControlledBy,
|
|
507
514
|
x402ChannelReservation,
|
|
508
515
|
x402CreditChannelNetworks,
|
|
@@ -516,7 +523,7 @@ import {
|
|
|
516
523
|
x402PendingUnsettled,
|
|
517
524
|
x402RequiredFromError,
|
|
518
525
|
x402ReservationRelease
|
|
519
|
-
} from "./chunk-
|
|
526
|
+
} from "./chunk-4RINUKY4.js";
|
|
520
527
|
import "./chunk-JBU7RKQ3.js";
|
|
521
528
|
import "./chunk-KDNFUDOG.js";
|
|
522
529
|
import "./chunk-IUTVV6N5.js";
|
|
@@ -5043,13 +5050,13 @@ var require_galois_field = __commonJS({
|
|
|
5043
5050
|
var EXP_TABLE = new Uint8Array(512);
|
|
5044
5051
|
var LOG_TABLE = new Uint8Array(256);
|
|
5045
5052
|
(function initTables() {
|
|
5046
|
-
let
|
|
5053
|
+
let x2 = 1;
|
|
5047
5054
|
for (let i2 = 0; i2 < 255; i2++) {
|
|
5048
|
-
EXP_TABLE[i2] =
|
|
5049
|
-
LOG_TABLE[
|
|
5050
|
-
|
|
5051
|
-
if (
|
|
5052
|
-
|
|
5055
|
+
EXP_TABLE[i2] = x2;
|
|
5056
|
+
LOG_TABLE[x2] = i2;
|
|
5057
|
+
x2 <<= 1;
|
|
5058
|
+
if (x2 & 256) {
|
|
5059
|
+
x2 ^= 285;
|
|
5053
5060
|
}
|
|
5054
5061
|
}
|
|
5055
5062
|
for (let i2 = 255; i2 < 512; i2++) {
|
|
@@ -5063,9 +5070,9 @@ var require_galois_field = __commonJS({
|
|
|
5063
5070
|
exports.exp = function exp(n) {
|
|
5064
5071
|
return EXP_TABLE[n];
|
|
5065
5072
|
};
|
|
5066
|
-
exports.mul = function mul(
|
|
5067
|
-
if (
|
|
5068
|
-
return EXP_TABLE[LOG_TABLE[
|
|
5073
|
+
exports.mul = function mul(x2, y) {
|
|
5074
|
+
if (x2 === 0 || y === 0) return 0;
|
|
5075
|
+
return EXP_TABLE[LOG_TABLE[x2] + LOG_TABLE[y]];
|
|
5069
5076
|
};
|
|
5070
5077
|
}
|
|
5071
5078
|
});
|
|
@@ -6323,9 +6330,9 @@ var require_interlace = __commonJS({
|
|
|
6323
6330
|
return images;
|
|
6324
6331
|
};
|
|
6325
6332
|
exports.getInterlaceIterator = function(width) {
|
|
6326
|
-
return function(
|
|
6327
|
-
let outerXLeftOver =
|
|
6328
|
-
let outerX = (
|
|
6333
|
+
return function(x2, y, pass) {
|
|
6334
|
+
let outerXLeftOver = x2 % imagePasses[pass].x.length;
|
|
6335
|
+
let outerX = (x2 - outerXLeftOver) / imagePasses[pass].x.length * 8 + imagePasses[pass].x[outerXLeftOver];
|
|
6329
6336
|
let outerYLeftOver = y % imagePasses[pass].y.length;
|
|
6330
6337
|
let outerY = (y - outerYLeftOver) / imagePasses[pass].y.length * 8 + imagePasses[pass].y[outerYLeftOver];
|
|
6331
6338
|
return outerX * 4 + outerY * width * 4;
|
|
@@ -6411,43 +6418,43 @@ var require_filter_parse = __commonJS({
|
|
|
6411
6418
|
Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
|
|
6412
6419
|
let xComparison = this._xComparison;
|
|
6413
6420
|
let xBiggerThan = xComparison - 1;
|
|
6414
|
-
for (let
|
|
6415
|
-
let rawByte = rawData[1 +
|
|
6416
|
-
let f1Left =
|
|
6417
|
-
unfilteredLine[
|
|
6421
|
+
for (let x2 = 0; x2 < byteWidth; x2++) {
|
|
6422
|
+
let rawByte = rawData[1 + x2];
|
|
6423
|
+
let f1Left = x2 > xBiggerThan ? unfilteredLine[x2 - xComparison] : 0;
|
|
6424
|
+
unfilteredLine[x2] = rawByte + f1Left;
|
|
6418
6425
|
}
|
|
6419
6426
|
};
|
|
6420
6427
|
Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
|
|
6421
6428
|
let lastLine = this._lastLine;
|
|
6422
|
-
for (let
|
|
6423
|
-
let rawByte = rawData[1 +
|
|
6424
|
-
let f2Up = lastLine ? lastLine[
|
|
6425
|
-
unfilteredLine[
|
|
6429
|
+
for (let x2 = 0; x2 < byteWidth; x2++) {
|
|
6430
|
+
let rawByte = rawData[1 + x2];
|
|
6431
|
+
let f2Up = lastLine ? lastLine[x2] : 0;
|
|
6432
|
+
unfilteredLine[x2] = rawByte + f2Up;
|
|
6426
6433
|
}
|
|
6427
6434
|
};
|
|
6428
6435
|
Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
|
|
6429
6436
|
let xComparison = this._xComparison;
|
|
6430
6437
|
let xBiggerThan = xComparison - 1;
|
|
6431
6438
|
let lastLine = this._lastLine;
|
|
6432
|
-
for (let
|
|
6433
|
-
let rawByte = rawData[1 +
|
|
6434
|
-
let f3Up = lastLine ? lastLine[
|
|
6435
|
-
let f3Left =
|
|
6439
|
+
for (let x2 = 0; x2 < byteWidth; x2++) {
|
|
6440
|
+
let rawByte = rawData[1 + x2];
|
|
6441
|
+
let f3Up = lastLine ? lastLine[x2] : 0;
|
|
6442
|
+
let f3Left = x2 > xBiggerThan ? unfilteredLine[x2 - xComparison] : 0;
|
|
6436
6443
|
let f3Add = Math.floor((f3Left + f3Up) / 2);
|
|
6437
|
-
unfilteredLine[
|
|
6444
|
+
unfilteredLine[x2] = rawByte + f3Add;
|
|
6438
6445
|
}
|
|
6439
6446
|
};
|
|
6440
6447
|
Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
|
|
6441
6448
|
let xComparison = this._xComparison;
|
|
6442
6449
|
let xBiggerThan = xComparison - 1;
|
|
6443
6450
|
let lastLine = this._lastLine;
|
|
6444
|
-
for (let
|
|
6445
|
-
let rawByte = rawData[1 +
|
|
6446
|
-
let f4Up = lastLine ? lastLine[
|
|
6447
|
-
let f4Left =
|
|
6448
|
-
let f4UpLeft =
|
|
6451
|
+
for (let x2 = 0; x2 < byteWidth; x2++) {
|
|
6452
|
+
let rawByte = rawData[1 + x2];
|
|
6453
|
+
let f4Up = lastLine ? lastLine[x2] : 0;
|
|
6454
|
+
let f4Left = x2 > xBiggerThan ? unfilteredLine[x2 - xComparison] : 0;
|
|
6455
|
+
let f4UpLeft = x2 > xBiggerThan && lastLine ? lastLine[x2 - xComparison] : 0;
|
|
6449
6456
|
let f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
|
|
6450
|
-
unfilteredLine[
|
|
6457
|
+
unfilteredLine[x2] = rawByte + f4Add;
|
|
6451
6458
|
}
|
|
6452
6459
|
};
|
|
6453
6460
|
Filter.prototype._reverseFilterLine = function(rawData) {
|
|
@@ -6600,7 +6607,7 @@ var require_crc = __commonJS({
|
|
|
6600
6607
|
var require_parser = __commonJS({
|
|
6601
6608
|
"node_modules/pngjs/lib/parser.js"(exports, module) {
|
|
6602
6609
|
"use strict";
|
|
6603
|
-
var
|
|
6610
|
+
var constants2 = require_constants();
|
|
6604
6611
|
var CrcCalculator = require_crc();
|
|
6605
6612
|
var Parser = module.exports = function(options, dependencies) {
|
|
6606
6613
|
this._options = options;
|
|
@@ -6611,12 +6618,12 @@ var require_parser = __commonJS({
|
|
|
6611
6618
|
this._palette = [];
|
|
6612
6619
|
this._colorType = 0;
|
|
6613
6620
|
this._chunks = {};
|
|
6614
|
-
this._chunks[
|
|
6615
|
-
this._chunks[
|
|
6616
|
-
this._chunks[
|
|
6617
|
-
this._chunks[
|
|
6618
|
-
this._chunks[
|
|
6619
|
-
this._chunks[
|
|
6621
|
+
this._chunks[constants2.TYPE_IHDR] = this._handleIHDR.bind(this);
|
|
6622
|
+
this._chunks[constants2.TYPE_IEND] = this._handleIEND.bind(this);
|
|
6623
|
+
this._chunks[constants2.TYPE_IDAT] = this._handleIDAT.bind(this);
|
|
6624
|
+
this._chunks[constants2.TYPE_PLTE] = this._handlePLTE.bind(this);
|
|
6625
|
+
this._chunks[constants2.TYPE_tRNS] = this._handleTRNS.bind(this);
|
|
6626
|
+
this._chunks[constants2.TYPE_gAMA] = this._handleGAMA.bind(this);
|
|
6620
6627
|
this.read = dependencies.read;
|
|
6621
6628
|
this.error = dependencies.error;
|
|
6622
6629
|
this.metadata = dependencies.metadata;
|
|
@@ -6631,10 +6638,10 @@ var require_parser = __commonJS({
|
|
|
6631
6638
|
};
|
|
6632
6639
|
};
|
|
6633
6640
|
Parser.prototype.start = function() {
|
|
6634
|
-
this.read(
|
|
6641
|
+
this.read(constants2.PNG_SIGNATURE.length, this._parseSignature.bind(this));
|
|
6635
6642
|
};
|
|
6636
6643
|
Parser.prototype._parseSignature = function(data) {
|
|
6637
|
-
let signature =
|
|
6644
|
+
let signature = constants2.PNG_SIGNATURE;
|
|
6638
6645
|
for (let i2 = 0; i2 < signature.length; i2++) {
|
|
6639
6646
|
if (data[i2] !== signature[i2]) {
|
|
6640
6647
|
this.error(new Error("Invalid file signature"));
|
|
@@ -6651,7 +6658,7 @@ var require_parser = __commonJS({
|
|
|
6651
6658
|
name += String.fromCharCode(data[i2]);
|
|
6652
6659
|
}
|
|
6653
6660
|
let ancillary = Boolean(data[4] & 32);
|
|
6654
|
-
if (!this._hasIHDR && type !==
|
|
6661
|
+
if (!this._hasIHDR && type !== constants2.TYPE_IHDR) {
|
|
6655
6662
|
this.error(new Error("Expected IHDR on beggining"));
|
|
6656
6663
|
return;
|
|
6657
6664
|
}
|
|
@@ -6699,7 +6706,7 @@ var require_parser = __commonJS({
|
|
|
6699
6706
|
this.error(new Error("Unsupported bit depth " + depth));
|
|
6700
6707
|
return;
|
|
6701
6708
|
}
|
|
6702
|
-
if (!(colorType in
|
|
6709
|
+
if (!(colorType in constants2.COLORTYPE_TO_BPP_MAP)) {
|
|
6703
6710
|
this.error(new Error("Unsupported color type"));
|
|
6704
6711
|
return;
|
|
6705
6712
|
}
|
|
@@ -6716,16 +6723,16 @@ var require_parser = __commonJS({
|
|
|
6716
6723
|
return;
|
|
6717
6724
|
}
|
|
6718
6725
|
this._colorType = colorType;
|
|
6719
|
-
let bpp =
|
|
6726
|
+
let bpp = constants2.COLORTYPE_TO_BPP_MAP[this._colorType];
|
|
6720
6727
|
this._hasIHDR = true;
|
|
6721
6728
|
this.metadata({
|
|
6722
6729
|
width,
|
|
6723
6730
|
height,
|
|
6724
6731
|
depth,
|
|
6725
6732
|
interlace: Boolean(interlace),
|
|
6726
|
-
palette: Boolean(colorType &
|
|
6727
|
-
color: Boolean(colorType &
|
|
6728
|
-
alpha: Boolean(colorType &
|
|
6733
|
+
palette: Boolean(colorType & constants2.COLORTYPE_PALETTE),
|
|
6734
|
+
color: Boolean(colorType & constants2.COLORTYPE_COLOR),
|
|
6735
|
+
alpha: Boolean(colorType & constants2.COLORTYPE_ALPHA),
|
|
6729
6736
|
bpp,
|
|
6730
6737
|
colorType
|
|
6731
6738
|
});
|
|
@@ -6749,7 +6756,7 @@ var require_parser = __commonJS({
|
|
|
6749
6756
|
};
|
|
6750
6757
|
Parser.prototype._parseTRNS = function(data) {
|
|
6751
6758
|
this._crc.write(data);
|
|
6752
|
-
if (this._colorType ===
|
|
6759
|
+
if (this._colorType === constants2.COLORTYPE_PALETTE_COLOR) {
|
|
6753
6760
|
if (this._palette.length === 0) {
|
|
6754
6761
|
this.error(new Error("Transparency chunk must be after palette"));
|
|
6755
6762
|
return;
|
|
@@ -6763,10 +6770,10 @@ var require_parser = __commonJS({
|
|
|
6763
6770
|
}
|
|
6764
6771
|
this.palette(this._palette);
|
|
6765
6772
|
}
|
|
6766
|
-
if (this._colorType ===
|
|
6773
|
+
if (this._colorType === constants2.COLORTYPE_GRAYSCALE) {
|
|
6767
6774
|
this.transColor([data.readUInt16BE(0)]);
|
|
6768
6775
|
}
|
|
6769
|
-
if (this._colorType ===
|
|
6776
|
+
if (this._colorType === constants2.COLORTYPE_COLOR) {
|
|
6770
6777
|
this.transColor([
|
|
6771
6778
|
data.readUInt16BE(0),
|
|
6772
6779
|
data.readUInt16BE(2),
|
|
@@ -6780,7 +6787,7 @@ var require_parser = __commonJS({
|
|
|
6780
6787
|
};
|
|
6781
6788
|
Parser.prototype._parseGAMA = function(data) {
|
|
6782
6789
|
this._crc.write(data);
|
|
6783
|
-
this.gamma(data.readUInt32BE(0) /
|
|
6790
|
+
this.gamma(data.readUInt32BE(0) / constants2.GAMMA_DIVISION);
|
|
6784
6791
|
this._handleChunkEnd();
|
|
6785
6792
|
};
|
|
6786
6793
|
Parser.prototype._handleIDAT = function(length) {
|
|
@@ -6792,7 +6799,7 @@ var require_parser = __commonJS({
|
|
|
6792
6799
|
};
|
|
6793
6800
|
Parser.prototype._parseIDAT = function(length, data) {
|
|
6794
6801
|
this._crc.write(data);
|
|
6795
|
-
if (this._colorType ===
|
|
6802
|
+
if (this._colorType === constants2.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
|
|
6796
6803
|
throw new Error("Expected palette not found");
|
|
6797
6804
|
}
|
|
6798
6805
|
this.inflateData(data);
|
|
@@ -6979,8 +6986,8 @@ var require_bitmapper = __commonJS({
|
|
|
6979
6986
|
let imageHeight = image.height;
|
|
6980
6987
|
let imagePass = image.index;
|
|
6981
6988
|
for (let y = 0; y < imageHeight; y++) {
|
|
6982
|
-
for (let
|
|
6983
|
-
let pxPos = getPxPos(
|
|
6989
|
+
for (let x2 = 0; x2 < imageWidth; x2++) {
|
|
6990
|
+
let pxPos = getPxPos(x2, y, imagePass);
|
|
6984
6991
|
pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
|
|
6985
6992
|
rawPos += bpp;
|
|
6986
6993
|
}
|
|
@@ -6992,9 +6999,9 @@ var require_bitmapper = __commonJS({
|
|
|
6992
6999
|
let imageHeight = image.height;
|
|
6993
7000
|
let imagePass = image.index;
|
|
6994
7001
|
for (let y = 0; y < imageHeight; y++) {
|
|
6995
|
-
for (let
|
|
7002
|
+
for (let x2 = 0; x2 < imageWidth; x2++) {
|
|
6996
7003
|
let pixelData = bits.get(bpp);
|
|
6997
|
-
let pxPos = getPxPos(
|
|
7004
|
+
let pxPos = getPxPos(x2, y, imagePass);
|
|
6998
7005
|
pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
|
|
6999
7006
|
}
|
|
7000
7007
|
bits.resetAfterLine();
|
|
@@ -7072,7 +7079,7 @@ var require_format_normaliser = __commonJS({
|
|
|
7072
7079
|
function dePalette(indata, outdata, width, height, palette) {
|
|
7073
7080
|
let pxPos = 0;
|
|
7074
7081
|
for (let y = 0; y < height; y++) {
|
|
7075
|
-
for (let
|
|
7082
|
+
for (let x2 = 0; x2 < width; x2++) {
|
|
7076
7083
|
let color = palette[indata[pxPos]];
|
|
7077
7084
|
if (!color) {
|
|
7078
7085
|
throw new Error("index " + indata[pxPos] + " not in palette");
|
|
@@ -7087,7 +7094,7 @@ var require_format_normaliser = __commonJS({
|
|
|
7087
7094
|
function replaceTransparentColor(indata, outdata, width, height, transColor) {
|
|
7088
7095
|
let pxPos = 0;
|
|
7089
7096
|
for (let y = 0; y < height; y++) {
|
|
7090
|
-
for (let
|
|
7097
|
+
for (let x2 = 0; x2 < width; x2++) {
|
|
7091
7098
|
let makeTrans = false;
|
|
7092
7099
|
if (transColor.length === 1) {
|
|
7093
7100
|
if (transColor[0] === indata[pxPos]) {
|
|
@@ -7110,7 +7117,7 @@ var require_format_normaliser = __commonJS({
|
|
|
7110
7117
|
let maxInSample = Math.pow(2, depth) - 1;
|
|
7111
7118
|
let pxPos = 0;
|
|
7112
7119
|
for (let y = 0; y < height; y++) {
|
|
7113
|
-
for (let
|
|
7120
|
+
for (let x2 = 0; x2 < width; x2++) {
|
|
7114
7121
|
for (let i2 = 0; i2 < 4; i2++) {
|
|
7115
7122
|
outdata[pxPos + i2] = Math.floor(
|
|
7116
7123
|
indata[pxPos + i2] * maxOutSample / maxInSample + 0.5
|
|
@@ -7276,9 +7283,9 @@ var require_parser_async = __commonJS({
|
|
|
7276
7283
|
var require_bitpacker = __commonJS({
|
|
7277
7284
|
"node_modules/pngjs/lib/bitpacker.js"(exports, module) {
|
|
7278
7285
|
"use strict";
|
|
7279
|
-
var
|
|
7286
|
+
var constants2 = require_constants();
|
|
7280
7287
|
module.exports = function(dataIn, width, height, options) {
|
|
7281
|
-
let outHasAlpha = [
|
|
7288
|
+
let outHasAlpha = [constants2.COLORTYPE_COLOR_ALPHA, constants2.COLORTYPE_ALPHA].indexOf(
|
|
7282
7289
|
options.colorType
|
|
7283
7290
|
) !== -1;
|
|
7284
7291
|
if (options.colorType === options.inputColorType) {
|
|
@@ -7298,11 +7305,11 @@ var require_bitpacker = __commonJS({
|
|
|
7298
7305
|
}
|
|
7299
7306
|
let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
|
|
7300
7307
|
let maxValue = 255;
|
|
7301
|
-
let inBpp =
|
|
7308
|
+
let inBpp = constants2.COLORTYPE_TO_BPP_MAP[options.inputColorType];
|
|
7302
7309
|
if (inBpp === 4 && !options.inputHasAlpha) {
|
|
7303
7310
|
inBpp = 3;
|
|
7304
7311
|
}
|
|
7305
|
-
let outBpp =
|
|
7312
|
+
let outBpp = constants2.COLORTYPE_TO_BPP_MAP[options.colorType];
|
|
7306
7313
|
if (options.bitDepth === 16) {
|
|
7307
7314
|
maxValue = 65535;
|
|
7308
7315
|
outBpp *= 2;
|
|
@@ -7326,24 +7333,24 @@ var require_bitpacker = __commonJS({
|
|
|
7326
7333
|
let blue;
|
|
7327
7334
|
let alpha = maxValue;
|
|
7328
7335
|
switch (options.inputColorType) {
|
|
7329
|
-
case
|
|
7336
|
+
case constants2.COLORTYPE_COLOR_ALPHA:
|
|
7330
7337
|
alpha = data[inIndex + 3];
|
|
7331
7338
|
red = data[inIndex];
|
|
7332
7339
|
green = data[inIndex + 1];
|
|
7333
7340
|
blue = data[inIndex + 2];
|
|
7334
7341
|
break;
|
|
7335
|
-
case
|
|
7342
|
+
case constants2.COLORTYPE_COLOR:
|
|
7336
7343
|
red = data[inIndex];
|
|
7337
7344
|
green = data[inIndex + 1];
|
|
7338
7345
|
blue = data[inIndex + 2];
|
|
7339
7346
|
break;
|
|
7340
|
-
case
|
|
7347
|
+
case constants2.COLORTYPE_ALPHA:
|
|
7341
7348
|
alpha = data[inIndex + 1];
|
|
7342
7349
|
red = data[inIndex];
|
|
7343
7350
|
green = red;
|
|
7344
7351
|
blue = red;
|
|
7345
7352
|
break;
|
|
7346
|
-
case
|
|
7353
|
+
case constants2.COLORTYPE_GRAYSCALE:
|
|
7347
7354
|
red = data[inIndex];
|
|
7348
7355
|
green = red;
|
|
7349
7356
|
blue = red;
|
|
@@ -7373,11 +7380,11 @@ var require_bitpacker = __commonJS({
|
|
|
7373
7380
|
return { red, green, blue, alpha };
|
|
7374
7381
|
}
|
|
7375
7382
|
for (let y = 0; y < height; y++) {
|
|
7376
|
-
for (let
|
|
7383
|
+
for (let x2 = 0; x2 < width; x2++) {
|
|
7377
7384
|
let rgba = getRGBA(data, inIndex);
|
|
7378
7385
|
switch (options.colorType) {
|
|
7379
|
-
case
|
|
7380
|
-
case
|
|
7386
|
+
case constants2.COLORTYPE_COLOR_ALPHA:
|
|
7387
|
+
case constants2.COLORTYPE_COLOR:
|
|
7381
7388
|
if (options.bitDepth === 8) {
|
|
7382
7389
|
outData[outIndex] = rgba.red;
|
|
7383
7390
|
outData[outIndex + 1] = rgba.green;
|
|
@@ -7394,8 +7401,8 @@ var require_bitpacker = __commonJS({
|
|
|
7394
7401
|
}
|
|
7395
7402
|
}
|
|
7396
7403
|
break;
|
|
7397
|
-
case
|
|
7398
|
-
case
|
|
7404
|
+
case constants2.COLORTYPE_ALPHA:
|
|
7405
|
+
case constants2.COLORTYPE_GRAYSCALE: {
|
|
7399
7406
|
let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
|
|
7400
7407
|
if (options.bitDepth === 8) {
|
|
7401
7408
|
outData[outIndex] = grayscale;
|
|
@@ -7428,8 +7435,8 @@ var require_filter_pack = __commonJS({
|
|
|
7428
7435
|
"use strict";
|
|
7429
7436
|
var paethPredictor = require_paeth_predictor();
|
|
7430
7437
|
function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
|
|
7431
|
-
for (let
|
|
7432
|
-
rawData[rawPos +
|
|
7438
|
+
for (let x2 = 0; x2 < byteWidth; x2++) {
|
|
7439
|
+
rawData[rawPos + x2] = pxData[pxPos + x2];
|
|
7433
7440
|
}
|
|
7434
7441
|
}
|
|
7435
7442
|
function filterSumNone(pxData, pxPos, byteWidth) {
|
|
@@ -7441,72 +7448,72 @@ var require_filter_pack = __commonJS({
|
|
|
7441
7448
|
return sum;
|
|
7442
7449
|
}
|
|
7443
7450
|
function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
7444
|
-
for (let
|
|
7445
|
-
let left =
|
|
7446
|
-
let val = pxData[pxPos +
|
|
7447
|
-
rawData[rawPos +
|
|
7451
|
+
for (let x2 = 0; x2 < byteWidth; x2++) {
|
|
7452
|
+
let left = x2 >= bpp ? pxData[pxPos + x2 - bpp] : 0;
|
|
7453
|
+
let val = pxData[pxPos + x2] - left;
|
|
7454
|
+
rawData[rawPos + x2] = val;
|
|
7448
7455
|
}
|
|
7449
7456
|
}
|
|
7450
7457
|
function filterSumSub(pxData, pxPos, byteWidth, bpp) {
|
|
7451
7458
|
let sum = 0;
|
|
7452
|
-
for (let
|
|
7453
|
-
let left =
|
|
7454
|
-
let val = pxData[pxPos +
|
|
7459
|
+
for (let x2 = 0; x2 < byteWidth; x2++) {
|
|
7460
|
+
let left = x2 >= bpp ? pxData[pxPos + x2 - bpp] : 0;
|
|
7461
|
+
let val = pxData[pxPos + x2] - left;
|
|
7455
7462
|
sum += Math.abs(val);
|
|
7456
7463
|
}
|
|
7457
7464
|
return sum;
|
|
7458
7465
|
}
|
|
7459
7466
|
function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
|
|
7460
|
-
for (let
|
|
7461
|
-
let up = pxPos > 0 ? pxData[pxPos +
|
|
7462
|
-
let val = pxData[pxPos +
|
|
7463
|
-
rawData[rawPos +
|
|
7467
|
+
for (let x2 = 0; x2 < byteWidth; x2++) {
|
|
7468
|
+
let up = pxPos > 0 ? pxData[pxPos + x2 - byteWidth] : 0;
|
|
7469
|
+
let val = pxData[pxPos + x2] - up;
|
|
7470
|
+
rawData[rawPos + x2] = val;
|
|
7464
7471
|
}
|
|
7465
7472
|
}
|
|
7466
7473
|
function filterSumUp(pxData, pxPos, byteWidth) {
|
|
7467
7474
|
let sum = 0;
|
|
7468
7475
|
let length = pxPos + byteWidth;
|
|
7469
|
-
for (let
|
|
7470
|
-
let up = pxPos > 0 ? pxData[
|
|
7471
|
-
let val = pxData[
|
|
7476
|
+
for (let x2 = pxPos; x2 < length; x2++) {
|
|
7477
|
+
let up = pxPos > 0 ? pxData[x2 - byteWidth] : 0;
|
|
7478
|
+
let val = pxData[x2] - up;
|
|
7472
7479
|
sum += Math.abs(val);
|
|
7473
7480
|
}
|
|
7474
7481
|
return sum;
|
|
7475
7482
|
}
|
|
7476
7483
|
function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
7477
|
-
for (let
|
|
7478
|
-
let left =
|
|
7479
|
-
let up = pxPos > 0 ? pxData[pxPos +
|
|
7480
|
-
let val = pxData[pxPos +
|
|
7481
|
-
rawData[rawPos +
|
|
7484
|
+
for (let x2 = 0; x2 < byteWidth; x2++) {
|
|
7485
|
+
let left = x2 >= bpp ? pxData[pxPos + x2 - bpp] : 0;
|
|
7486
|
+
let up = pxPos > 0 ? pxData[pxPos + x2 - byteWidth] : 0;
|
|
7487
|
+
let val = pxData[pxPos + x2] - (left + up >> 1);
|
|
7488
|
+
rawData[rawPos + x2] = val;
|
|
7482
7489
|
}
|
|
7483
7490
|
}
|
|
7484
7491
|
function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
|
|
7485
7492
|
let sum = 0;
|
|
7486
|
-
for (let
|
|
7487
|
-
let left =
|
|
7488
|
-
let up = pxPos > 0 ? pxData[pxPos +
|
|
7489
|
-
let val = pxData[pxPos +
|
|
7493
|
+
for (let x2 = 0; x2 < byteWidth; x2++) {
|
|
7494
|
+
let left = x2 >= bpp ? pxData[pxPos + x2 - bpp] : 0;
|
|
7495
|
+
let up = pxPos > 0 ? pxData[pxPos + x2 - byteWidth] : 0;
|
|
7496
|
+
let val = pxData[pxPos + x2] - (left + up >> 1);
|
|
7490
7497
|
sum += Math.abs(val);
|
|
7491
7498
|
}
|
|
7492
7499
|
return sum;
|
|
7493
7500
|
}
|
|
7494
7501
|
function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
7495
|
-
for (let
|
|
7496
|
-
let left =
|
|
7497
|
-
let up = pxPos > 0 ? pxData[pxPos +
|
|
7498
|
-
let upleft = pxPos > 0 &&
|
|
7499
|
-
let val = pxData[pxPos +
|
|
7500
|
-
rawData[rawPos +
|
|
7502
|
+
for (let x2 = 0; x2 < byteWidth; x2++) {
|
|
7503
|
+
let left = x2 >= bpp ? pxData[pxPos + x2 - bpp] : 0;
|
|
7504
|
+
let up = pxPos > 0 ? pxData[pxPos + x2 - byteWidth] : 0;
|
|
7505
|
+
let upleft = pxPos > 0 && x2 >= bpp ? pxData[pxPos + x2 - (byteWidth + bpp)] : 0;
|
|
7506
|
+
let val = pxData[pxPos + x2] - paethPredictor(left, up, upleft);
|
|
7507
|
+
rawData[rawPos + x2] = val;
|
|
7501
7508
|
}
|
|
7502
7509
|
}
|
|
7503
7510
|
function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
|
|
7504
7511
|
let sum = 0;
|
|
7505
|
-
for (let
|
|
7506
|
-
let left =
|
|
7507
|
-
let up = pxPos > 0 ? pxData[pxPos +
|
|
7508
|
-
let upleft = pxPos > 0 &&
|
|
7509
|
-
let val = pxData[pxPos +
|
|
7512
|
+
for (let x2 = 0; x2 < byteWidth; x2++) {
|
|
7513
|
+
let left = x2 >= bpp ? pxData[pxPos + x2 - bpp] : 0;
|
|
7514
|
+
let up = pxPos > 0 ? pxData[pxPos + x2 - byteWidth] : 0;
|
|
7515
|
+
let upleft = pxPos > 0 && x2 >= bpp ? pxData[pxPos + x2 - (byteWidth + bpp)] : 0;
|
|
7516
|
+
let val = pxData[pxPos + x2] - paethPredictor(left, up, upleft);
|
|
7510
7517
|
sum += Math.abs(val);
|
|
7511
7518
|
}
|
|
7512
7519
|
return sum;
|
|
@@ -7568,7 +7575,7 @@ var require_filter_pack = __commonJS({
|
|
|
7568
7575
|
var require_packer = __commonJS({
|
|
7569
7576
|
"node_modules/pngjs/lib/packer.js"(exports, module) {
|
|
7570
7577
|
"use strict";
|
|
7571
|
-
var
|
|
7578
|
+
var constants2 = require_constants();
|
|
7572
7579
|
var CrcStream = require_crc();
|
|
7573
7580
|
var bitPacker = require_bitpacker();
|
|
7574
7581
|
var filter = require_filter_pack();
|
|
@@ -7581,23 +7588,23 @@ var require_packer = __commonJS({
|
|
|
7581
7588
|
options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
|
|
7582
7589
|
options.deflateFactory = options.deflateFactory || zlib.createDeflate;
|
|
7583
7590
|
options.bitDepth = options.bitDepth || 8;
|
|
7584
|
-
options.colorType = typeof options.colorType === "number" ? options.colorType :
|
|
7585
|
-
options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType :
|
|
7591
|
+
options.colorType = typeof options.colorType === "number" ? options.colorType : constants2.COLORTYPE_COLOR_ALPHA;
|
|
7592
|
+
options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType : constants2.COLORTYPE_COLOR_ALPHA;
|
|
7586
7593
|
if ([
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7594
|
+
constants2.COLORTYPE_GRAYSCALE,
|
|
7595
|
+
constants2.COLORTYPE_COLOR,
|
|
7596
|
+
constants2.COLORTYPE_COLOR_ALPHA,
|
|
7597
|
+
constants2.COLORTYPE_ALPHA
|
|
7591
7598
|
].indexOf(options.colorType) === -1) {
|
|
7592
7599
|
throw new Error(
|
|
7593
7600
|
"option color type:" + options.colorType + " is not supported at present"
|
|
7594
7601
|
);
|
|
7595
7602
|
}
|
|
7596
7603
|
if ([
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
|
|
7604
|
+
constants2.COLORTYPE_GRAYSCALE,
|
|
7605
|
+
constants2.COLORTYPE_COLOR,
|
|
7606
|
+
constants2.COLORTYPE_COLOR_ALPHA,
|
|
7607
|
+
constants2.COLORTYPE_ALPHA
|
|
7601
7608
|
].indexOf(options.inputColorType) === -1) {
|
|
7602
7609
|
throw new Error(
|
|
7603
7610
|
"option input color type:" + options.inputColorType + " is not supported at present"
|
|
@@ -7621,7 +7628,7 @@ var require_packer = __commonJS({
|
|
|
7621
7628
|
};
|
|
7622
7629
|
Packer.prototype.filterData = function(data, width, height) {
|
|
7623
7630
|
let packedData = bitPacker(data, width, height, this._options);
|
|
7624
|
-
let bpp =
|
|
7631
|
+
let bpp = constants2.COLORTYPE_TO_BPP_MAP[this._options.colorType];
|
|
7625
7632
|
let filteredData = filter(packedData, width, height, this._options, bpp);
|
|
7626
7633
|
return filteredData;
|
|
7627
7634
|
};
|
|
@@ -7641,8 +7648,8 @@ var require_packer = __commonJS({
|
|
|
7641
7648
|
};
|
|
7642
7649
|
Packer.prototype.packGAMA = function(gamma) {
|
|
7643
7650
|
let buf = Buffer.alloc(4);
|
|
7644
|
-
buf.writeUInt32BE(Math.floor(gamma *
|
|
7645
|
-
return this._packChunk(
|
|
7651
|
+
buf.writeUInt32BE(Math.floor(gamma * constants2.GAMMA_DIVISION), 0);
|
|
7652
|
+
return this._packChunk(constants2.TYPE_gAMA, buf);
|
|
7646
7653
|
};
|
|
7647
7654
|
Packer.prototype.packIHDR = function(width, height) {
|
|
7648
7655
|
let buf = Buffer.alloc(13);
|
|
@@ -7653,13 +7660,13 @@ var require_packer = __commonJS({
|
|
|
7653
7660
|
buf[10] = 0;
|
|
7654
7661
|
buf[11] = 0;
|
|
7655
7662
|
buf[12] = 0;
|
|
7656
|
-
return this._packChunk(
|
|
7663
|
+
return this._packChunk(constants2.TYPE_IHDR, buf);
|
|
7657
7664
|
};
|
|
7658
7665
|
Packer.prototype.packIDAT = function(data) {
|
|
7659
|
-
return this._packChunk(
|
|
7666
|
+
return this._packChunk(constants2.TYPE_IDAT, data);
|
|
7660
7667
|
};
|
|
7661
7668
|
Packer.prototype.packIEND = function() {
|
|
7662
|
-
return this._packChunk(
|
|
7669
|
+
return this._packChunk(constants2.TYPE_IEND, null);
|
|
7663
7670
|
};
|
|
7664
7671
|
}
|
|
7665
7672
|
});
|
|
@@ -7670,7 +7677,7 @@ var require_packer_async = __commonJS({
|
|
|
7670
7677
|
"use strict";
|
|
7671
7678
|
var util = __require("util");
|
|
7672
7679
|
var Stream = __require("stream");
|
|
7673
|
-
var
|
|
7680
|
+
var constants2 = require_constants();
|
|
7674
7681
|
var Packer = require_packer();
|
|
7675
7682
|
var PackerAsync = module.exports = function(opt) {
|
|
7676
7683
|
Stream.call(this);
|
|
@@ -7681,7 +7688,7 @@ var require_packer_async = __commonJS({
|
|
|
7681
7688
|
};
|
|
7682
7689
|
util.inherits(PackerAsync, Stream);
|
|
7683
7690
|
PackerAsync.prototype.pack = function(data, width, height, gamma) {
|
|
7684
|
-
this.emit("data", Buffer.from(
|
|
7691
|
+
this.emit("data", Buffer.from(constants2.PNG_SIGNATURE));
|
|
7685
7692
|
this.emit("data", this._packer.packIHDR(width, height));
|
|
7686
7693
|
if (gamma) {
|
|
7687
7694
|
this.emit("data", this._packer.packGAMA(gamma));
|
|
@@ -8005,7 +8012,7 @@ var require_packer_sync = __commonJS({
|
|
|
8005
8012
|
if (!zlib.deflateSync) {
|
|
8006
8013
|
hasSyncZlib = false;
|
|
8007
8014
|
}
|
|
8008
|
-
var
|
|
8015
|
+
var constants2 = require_constants();
|
|
8009
8016
|
var Packer = require_packer();
|
|
8010
8017
|
module.exports = function(metaData, opt) {
|
|
8011
8018
|
if (!hasSyncZlib) {
|
|
@@ -8016,7 +8023,7 @@ var require_packer_sync = __commonJS({
|
|
|
8016
8023
|
let options = opt || {};
|
|
8017
8024
|
let packer = new Packer(options);
|
|
8018
8025
|
let chunks = [];
|
|
8019
|
-
chunks.push(Buffer.from(
|
|
8026
|
+
chunks.push(Buffer.from(constants2.PNG_SIGNATURE));
|
|
8020
8027
|
chunks.push(packer.packIHDR(metaData.width, metaData.height));
|
|
8021
8028
|
if (metaData.gamma) {
|
|
8022
8029
|
chunks.push(packer.packGAMA(metaData.gamma));
|
|
@@ -8175,8 +8182,8 @@ var require_png = __commonJS({
|
|
|
8175
8182
|
PNG.adjustGamma = function(src) {
|
|
8176
8183
|
if (src.gamma) {
|
|
8177
8184
|
for (let y = 0; y < src.height; y++) {
|
|
8178
|
-
for (let
|
|
8179
|
-
let idx = src.width * y +
|
|
8185
|
+
for (let x2 = 0; x2 < src.width; x2++) {
|
|
8186
|
+
let idx = src.width * y + x2 << 2;
|
|
8180
8187
|
for (let i2 = 0; i2 < 3; i2++) {
|
|
8181
8188
|
let sample = src.data[idx + i2] / 255;
|
|
8182
8189
|
sample = Math.pow(sample, 1 / 2.2 / src.gamma);
|
|
@@ -8459,15 +8466,15 @@ var require_terminal_small = __commonJS({
|
|
|
8459
8466
|
22: "\u2588"
|
|
8460
8467
|
};
|
|
8461
8468
|
};
|
|
8462
|
-
var mkCodePixel = function(modules, size,
|
|
8469
|
+
var mkCodePixel = function(modules, size, x2, y) {
|
|
8463
8470
|
const sizePlus = size + 1;
|
|
8464
|
-
if (
|
|
8465
|
-
if (
|
|
8466
|
-
const idx = y * size +
|
|
8471
|
+
if (x2 >= sizePlus || y >= sizePlus || y < -1 || x2 < -1) return "0";
|
|
8472
|
+
if (x2 >= size || y >= size || y < 0 || x2 < 0) return "1";
|
|
8473
|
+
const idx = y * size + x2;
|
|
8467
8474
|
return modules[idx] ? "2" : "1";
|
|
8468
8475
|
};
|
|
8469
|
-
var mkCode = function(modules, size,
|
|
8470
|
-
return mkCodePixel(modules, size,
|
|
8476
|
+
var mkCode = function(modules, size, x2, y) {
|
|
8477
|
+
return mkCodePixel(modules, size, x2, y) + mkCodePixel(modules, size, x2, y + 1);
|
|
8471
8478
|
};
|
|
8472
8479
|
exports.render = function(qrData, options, cb) {
|
|
8473
8480
|
const size = qrData.modules.size;
|
|
@@ -8480,8 +8487,8 @@ var require_terminal_small = __commonJS({
|
|
|
8480
8487
|
const newLine = reset + "\n" + lineSetup;
|
|
8481
8488
|
let output = lineSetup;
|
|
8482
8489
|
for (let y = -1; y < size + 1; y += 2) {
|
|
8483
|
-
for (let
|
|
8484
|
-
output += palette[mkCode(data, size,
|
|
8490
|
+
for (let x2 = -1; x2 < size; x2++) {
|
|
8491
|
+
output += palette[mkCode(data, size, x2, y)];
|
|
8485
8492
|
}
|
|
8486
8493
|
output += palette[mkCode(data, size, size, y)] + newLine;
|
|
8487
8494
|
}
|
|
@@ -8519,8 +8526,8 @@ var require_svg_tag = __commonJS({
|
|
|
8519
8526
|
const str = attrib + '="' + color.hex + '"';
|
|
8520
8527
|
return alpha < 1 ? str + " " + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"' : str;
|
|
8521
8528
|
}
|
|
8522
|
-
function svgCmd(cmd,
|
|
8523
|
-
let str = cmd +
|
|
8529
|
+
function svgCmd(cmd, x2, y) {
|
|
8530
|
+
let str = cmd + x2;
|
|
8524
8531
|
if (typeof y !== "undefined") str += " " + y;
|
|
8525
8532
|
return str;
|
|
8526
8533
|
}
|
|
@@ -8843,7 +8850,7 @@ var require_lib = __commonJS({
|
|
|
8843
8850
|
|
|
8844
8851
|
// src/cli/dvm.ts
|
|
8845
8852
|
import { realpathSync as realpathSync2 } from "fs";
|
|
8846
|
-
import { fileURLToPath as
|
|
8853
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
8847
8854
|
|
|
8848
8855
|
// node_modules/commander/esm.mjs
|
|
8849
8856
|
var import_index = __toESM(require_commander(), 1);
|
|
@@ -8925,6 +8932,11 @@ function renderDiscoveryDisplay(row, indent) {
|
|
|
8925
8932
|
}
|
|
8926
8933
|
}
|
|
8927
8934
|
|
|
8935
|
+
// src/lib/job-read-error.ts
|
|
8936
|
+
function isTransientJobReadError(error) {
|
|
8937
|
+
return isAbortError(error) || error instanceof DvmError && ["timeout", "provider_unreachable"].includes(error.code);
|
|
8938
|
+
}
|
|
8939
|
+
|
|
8928
8940
|
// src/lib/payment-lock.ts
|
|
8929
8941
|
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
8930
8942
|
import { createHash } from "crypto";
|
|
@@ -9422,6 +9434,29 @@ function saveState(state) {
|
|
|
9422
9434
|
}
|
|
9423
9435
|
|
|
9424
9436
|
// src/lib/credit-notice.ts
|
|
9437
|
+
function refusedFundingReport(endpoint, outcome) {
|
|
9438
|
+
return {
|
|
9439
|
+
endpoint,
|
|
9440
|
+
status: outcome.status,
|
|
9441
|
+
credit_id: outcome.creditId,
|
|
9442
|
+
fund_id: outcome.fundId,
|
|
9443
|
+
rail: outcome.rail,
|
|
9444
|
+
...outcome.spentSats !== void 0 ? { spent_sats: outcome.spentSats } : {},
|
|
9445
|
+
...outcome.principalSats !== void 0 ? { principal_sats: outcome.principalSats } : {},
|
|
9446
|
+
...outcome.routingFeeSats !== void 0 ? { routing_fee_sats: outcome.routingFeeSats } : {},
|
|
9447
|
+
...outcome.totalWalletFeeSats !== void 0 ? { total_wallet_fee_sats: outcome.totalWalletFeeSats } : {},
|
|
9448
|
+
...outcome.unitemizedWalletFeeSats !== void 0 ? { unitemized_wallet_fee_sats: outcome.unitemizedWalletFeeSats } : {},
|
|
9449
|
+
...outcome.walletDebitSats !== void 0 ? { wallet_debit_sats: outcome.walletDebitSats } : {},
|
|
9450
|
+
...outcome.paymentOutcome ? { payment_outcome: outcome.paymentOutcome } : {},
|
|
9451
|
+
...outcome.error ? { error_code: outcome.error.code } : {},
|
|
9452
|
+
display: outcome.display,
|
|
9453
|
+
hint: outcome.hint
|
|
9454
|
+
};
|
|
9455
|
+
}
|
|
9456
|
+
function noteRefusedCreditFunding(endpoint, outcome, human) {
|
|
9457
|
+
if (human) info([outcome.display, outcome.hint].filter(Boolean).join(" "));
|
|
9458
|
+
else (pending.refused_fundings ??= []).push(refusedFundingReport(endpoint, outcome));
|
|
9459
|
+
}
|
|
9425
9460
|
function buildCreditFundingSkipped(args) {
|
|
9426
9461
|
return {
|
|
9427
9462
|
code: "credit_funding_skipped",
|
|
@@ -11902,8 +11937,8 @@ async function handleLockedPaymentRequest(jobId, request2, policy, transport, pr
|
|
|
11902
11937
|
}
|
|
11903
11938
|
}
|
|
11904
11939
|
if ((opts?.rail === void 0 || opts.rail === "x402") && request2.x402) {
|
|
11905
|
-
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-
|
|
11906
|
-
const { tryX402Payment: tryX402Payment2 } = await import("./client-
|
|
11940
|
+
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-J7JCMFZ2.js");
|
|
11941
|
+
const { tryX402Payment: tryX402Payment2 } = await import("./client-FKYQXFBN.js");
|
|
11907
11942
|
const wallet = loadX402Wallet2();
|
|
11908
11943
|
if (wallet) {
|
|
11909
11944
|
let proof;
|
|
@@ -12046,6 +12081,7 @@ async function redeliverUnconfirmedPayment(args) {
|
|
|
12046
12081
|
requestId: held.request_id,
|
|
12047
12082
|
mint: held.mint,
|
|
12048
12083
|
totalSats: held.amount_sats,
|
|
12084
|
+
swapFeeSats: submissionSwapFeeSats(held),
|
|
12049
12085
|
endpoint: held.endpoint,
|
|
12050
12086
|
intendedLockPubkey: held.intended_lock_pubkey
|
|
12051
12087
|
}
|
|
@@ -12198,10 +12234,12 @@ async function deliverAgentWalletPayment(args) {
|
|
|
12198
12234
|
dvm_endpoint: provider.endpoint,
|
|
12199
12235
|
mint: prepared.mint,
|
|
12200
12236
|
amount_sats: prepared.totalSats,
|
|
12237
|
+
...prepared.swapFeeSats > 0 ? { fee_sats: prepared.swapFeeSats } : {},
|
|
12201
12238
|
signed_at_ms: Date.now()
|
|
12202
12239
|
}
|
|
12203
12240
|
});
|
|
12204
12241
|
addPayment(jobId, request2.amount_msats, approval, submission.usdMicro);
|
|
12242
|
+
addCashuSwapFee(jobId, prepared.swapFeeSats);
|
|
12205
12243
|
recordSpend({
|
|
12206
12244
|
msats: request2.amount_msats,
|
|
12207
12245
|
btcRate: submission.btcRate,
|
|
@@ -12461,6 +12499,7 @@ function withRefundNextAction(jobId, action, claims) {
|
|
|
12461
12499
|
// src/lib/stream-loop.ts
|
|
12462
12500
|
async function streamLoop(opts) {
|
|
12463
12501
|
const { jobId, transport, provider } = opts;
|
|
12502
|
+
const recoverableRead = (error) => opts.retryUnreachableReads ? isTransientJobReadError(error) : isMessagePollTimeout(error);
|
|
12464
12503
|
if (hasUnsavedJobState()) return {
|
|
12465
12504
|
messages: [],
|
|
12466
12505
|
autoPayments: [],
|
|
@@ -12556,7 +12595,7 @@ async function streamLoop(opts) {
|
|
|
12556
12595
|
try {
|
|
12557
12596
|
result = await streamFn(jobId, cursor, provider, streamOpts);
|
|
12558
12597
|
} catch (err) {
|
|
12559
|
-
if (isAbortError(err) || deadline !== void 0 &&
|
|
12598
|
+
if (isAbortError(err) || deadline !== void 0 && recoverableRead(err)) break;
|
|
12560
12599
|
throw err;
|
|
12561
12600
|
}
|
|
12562
12601
|
batchMessages = result.messages.filter((message2) => message2.seq > cursor);
|
|
@@ -12566,7 +12605,7 @@ async function streamLoop(opts) {
|
|
|
12566
12605
|
try {
|
|
12567
12606
|
batchMessages = (await transport.getMessages(jobId, cursor, provider, pollOptions)).filter((message2) => message2.seq > cursor);
|
|
12568
12607
|
} catch (err) {
|
|
12569
|
-
if (deadline !== void 0 &&
|
|
12608
|
+
if (deadline !== void 0 && recoverableRead(err)) break;
|
|
12570
12609
|
throw err;
|
|
12571
12610
|
}
|
|
12572
12611
|
for (const msg of batchMessages) {
|
|
@@ -12605,7 +12644,7 @@ async function streamLoop(opts) {
|
|
|
12605
12644
|
break;
|
|
12606
12645
|
}
|
|
12607
12646
|
} catch (error) {
|
|
12608
|
-
if (!
|
|
12647
|
+
if (!recoverableRead(error) && !(error instanceof DvmError && ["payment_settling", "payment_request_not_pending"].includes(error.code))) throw error;
|
|
12609
12648
|
paymentUnresolved = true;
|
|
12610
12649
|
}
|
|
12611
12650
|
if (paymentUnresolved) {
|
|
@@ -12671,7 +12710,7 @@ async function streamLoop(opts) {
|
|
|
12671
12710
|
recheck = (await transport.getMessages(jobId, cursor, provider, pollOptions)).filter((message2) => message2.seq > cursor);
|
|
12672
12711
|
}
|
|
12673
12712
|
} catch (err) {
|
|
12674
|
-
if (deadline === void 0 || !
|
|
12713
|
+
if (deadline === void 0 || !recoverableRead(err)) throw err;
|
|
12675
12714
|
}
|
|
12676
12715
|
if (recheck.length > 0) {
|
|
12677
12716
|
for (const msg of recheck) opts.onMessage?.(msg);
|
|
@@ -13021,18 +13060,18 @@ function paramsToData(params) {
|
|
|
13021
13060
|
function jobTokenHeader(jobToken) {
|
|
13022
13061
|
return jobToken ? { "X-Job-Token": jobToken } : {};
|
|
13023
13062
|
}
|
|
13024
|
-
function messagePollUnreachable(jobId) {
|
|
13063
|
+
function messagePollUnreachable(jobId, operation = "fetch messages") {
|
|
13025
13064
|
return new DvmError(
|
|
13026
13065
|
"provider_unreachable",
|
|
13027
|
-
`Could not reach the provider to
|
|
13028
|
-
|
|
13066
|
+
`Could not reach the provider to ${operation} for job ${jobId}.`,
|
|
13067
|
+
`The provider may be down or unreachable from this network. Continue watching this job with \`dvm messages ${shellQuoteArg(jobId)} --wait\` once it is back.`
|
|
13029
13068
|
);
|
|
13030
13069
|
}
|
|
13031
|
-
async function readMessagePollBody(read, jobId) {
|
|
13070
|
+
async function readMessagePollBody(read, jobId, operation) {
|
|
13032
13071
|
try {
|
|
13033
13072
|
return await read();
|
|
13034
13073
|
} catch (err) {
|
|
13035
|
-
if (err instanceof TypeError && !isAbortError(err)) throw messagePollUnreachable(jobId);
|
|
13074
|
+
if (err instanceof TypeError && !isAbortError(err)) throw messagePollUnreachable(jobId, operation);
|
|
13036
13075
|
throw err;
|
|
13037
13076
|
}
|
|
13038
13077
|
}
|
|
@@ -13471,7 +13510,7 @@ var HttpsTransport = class {
|
|
|
13471
13510
|
const url2 = `${endpoint}/v1/job/${jobId}`;
|
|
13472
13511
|
const signal = options?.timeoutMs && options.timeoutMs > 0 ? AbortSignal.timeout(options.timeoutMs) : void 0;
|
|
13473
13512
|
try {
|
|
13474
|
-
const res = await dvmFetch(url2, { headers: jobTokenHeader(options?.jobToken), signal });
|
|
13513
|
+
const res = await readMessagePollBody(() => dvmFetch(url2, { headers: jobTokenHeader(options?.jobToken), signal }), jobId, "read status");
|
|
13475
13514
|
captureTraceId(res);
|
|
13476
13515
|
if (res.status === 404) {
|
|
13477
13516
|
const storedEndpoint = loadJob(jobId)?.endpoint;
|
|
@@ -13481,11 +13520,11 @@ var HttpsTransport = class {
|
|
|
13481
13520
|
));
|
|
13482
13521
|
}
|
|
13483
13522
|
if (!res.ok) {
|
|
13484
|
-
const credentialErr = jobCredentialError(res.status, await res.text());
|
|
13523
|
+
const credentialErr = jobCredentialError(res.status, await readMessagePollBody(() => res.text(), jobId, "read status"));
|
|
13485
13524
|
if (credentialErr) throw credentialErr;
|
|
13486
13525
|
throw new DvmError("provider_error", `Status check failed (${res.status})`);
|
|
13487
13526
|
}
|
|
13488
|
-
const data = await res.json();
|
|
13527
|
+
const data = await readMessagePollBody(() => res.json(), jobId, "read status");
|
|
13489
13528
|
return {
|
|
13490
13529
|
jobId,
|
|
13491
13530
|
status: data.status,
|
|
@@ -13638,12 +13677,12 @@ var HttpsTransport = class {
|
|
|
13638
13677
|
throw new DvmError("not_supported", "HTTPS stream requires a provider with an endpoint.");
|
|
13639
13678
|
}
|
|
13640
13679
|
const url2 = `${endpoint}/v1/job/${jobId}/messages?after=${afterSeq}`;
|
|
13641
|
-
const res = await dvmFetch(url2, {
|
|
13680
|
+
const res = await readMessagePollBody(() => dvmFetch(url2, {
|
|
13642
13681
|
headers: { Accept: "text/event-stream", ...jobTokenHeader(options?.jobToken) },
|
|
13643
13682
|
signal: options?.signal
|
|
13644
|
-
});
|
|
13683
|
+
}), jobId);
|
|
13645
13684
|
if (!res.ok) {
|
|
13646
|
-
const text = await res.text();
|
|
13685
|
+
const text = await readMessagePollBody(() => res.text(), jobId);
|
|
13647
13686
|
const credentialErr = jobCredentialError(res.status, text);
|
|
13648
13687
|
if (credentialErr) throw credentialErr;
|
|
13649
13688
|
throw providerResponseError("provider_error", `stream failed (${res.status}): ${text}`);
|
|
@@ -13651,7 +13690,7 @@ var HttpsTransport = class {
|
|
|
13651
13690
|
const contentType = res.headers.get("content-type") ?? "";
|
|
13652
13691
|
const recognize = callerMessageRecognizer(jobId, endpoint);
|
|
13653
13692
|
if (contentType.includes("application/json")) {
|
|
13654
|
-
const body = await res.json();
|
|
13693
|
+
const body = await readMessagePollBody(() => res.json(), jobId);
|
|
13655
13694
|
const messages2 = (body.messages ?? []).map(recognize);
|
|
13656
13695
|
const last = messages2.at(-1);
|
|
13657
13696
|
const reason = last?.type === "complete" ? "complete" : last?.type === "cancel" ? "cancel" : "yield";
|
|
@@ -14732,7 +14771,7 @@ async function settleCreditAfterJob(args) {
|
|
|
14732
14771
|
}
|
|
14733
14772
|
}
|
|
14734
14773
|
if (args.allowTopup !== false) {
|
|
14735
|
-
const refill = args.refillPocket ?? (await import("./pocket-refill-
|
|
14774
|
+
const refill = args.refillPocket ?? (await import("./pocket-refill-M65PPCN3.js")).refillPocketIfLow;
|
|
14736
14775
|
await refill({ human: args.human }).catch(() => void 0);
|
|
14737
14776
|
}
|
|
14738
14777
|
}
|
|
@@ -15033,6 +15072,10 @@ function reportFunding(args, outcome, ctx) {
|
|
|
15033
15072
|
);
|
|
15034
15073
|
return;
|
|
15035
15074
|
}
|
|
15075
|
+
case "invoice_pending":
|
|
15076
|
+
info(`${what} at ${args.ref.endpoint} deferred \u2014 ${outcome.display}${hint}`);
|
|
15077
|
+
incomplete("credit_funding_deferred");
|
|
15078
|
+
return;
|
|
15036
15079
|
case "settlement_pending":
|
|
15037
15080
|
info(`${what} at ${args.ref.endpoint} \u2014 ${outcome.display}${hint}`);
|
|
15038
15081
|
incomplete("credit_funding_settlement_pending");
|
|
@@ -15513,14 +15556,14 @@ async function confirmRollback(stored, preview, opts) {
|
|
|
15513
15556
|
async function withStrandingChecked(removing, commit) {
|
|
15514
15557
|
const leaving = new Set(removing.map((target) => target.split(".")[0]));
|
|
15515
15558
|
if (leaving.has("tempo")) {
|
|
15516
|
-
const { assertTempoWalletIdle: assertTempoWalletIdle2 } = await import("./tempo-lifecycle-
|
|
15559
|
+
const { assertTempoWalletIdle: assertTempoWalletIdle2 } = await import("./tempo-lifecycle-Q3N5GGIQ.js");
|
|
15517
15560
|
await assertTempoWalletIdle2("disconnect");
|
|
15518
15561
|
}
|
|
15519
15562
|
if (!leaving.has("x402")) return commit();
|
|
15520
|
-
const { withX402ChannelLock: withX402ChannelLock2, listPendingX402Fundings: listPendingX402Fundings2, x402PendingUnsettled: x402PendingUnsettled2 } = await import("./internal-
|
|
15521
|
-
const { assertX402WalletIdle: assertX402WalletIdle2 } = await import("./lifecycle-
|
|
15522
|
-
const { ensureAddress: ensureAddress2 } = await import("./internal-
|
|
15523
|
-
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-
|
|
15563
|
+
const { withX402ChannelLock: withX402ChannelLock2, listPendingX402Fundings: listPendingX402Fundings2, x402PendingUnsettled: x402PendingUnsettled2 } = await import("./internal-EQJXMIR2.js");
|
|
15564
|
+
const { assertX402WalletIdle: assertX402WalletIdle2 } = await import("./lifecycle-3IBVUCTB.js");
|
|
15565
|
+
const { ensureAddress: ensureAddress2 } = await import("./internal-EQJXMIR2.js");
|
|
15566
|
+
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-J7JCMFZ2.js");
|
|
15524
15567
|
return withX402ChannelLock2(async () => {
|
|
15525
15568
|
const unsettled = listPendingX402Fundings2().filter((entry) => x402PendingUnsettled2(entry));
|
|
15526
15569
|
if (unsettled.length > 0) {
|
|
@@ -15812,7 +15855,7 @@ function railMinimums(menu) {
|
|
|
15812
15855
|
minimums.push({ rail: "lightning", minMicro: menu.lightning_min_micro });
|
|
15813
15856
|
}
|
|
15814
15857
|
if (menu?.funding.includes("stripe")) {
|
|
15815
|
-
minimums.push({ rail: "stripe", minMicro:
|
|
15858
|
+
minimums.push({ rail: "stripe", minMicro: cardMinimumMicro(menu) });
|
|
15816
15859
|
}
|
|
15817
15860
|
return minimums;
|
|
15818
15861
|
}
|
|
@@ -16250,6 +16293,17 @@ async function runCreditBalance(dvm, opts) {
|
|
|
16250
16293
|
try {
|
|
16251
16294
|
for (const endpoint of endpoints) {
|
|
16252
16295
|
try {
|
|
16296
|
+
if (!opts.observeOnly && !opts.selectionOnly) {
|
|
16297
|
+
const refused = await pollPendingCreditFundings({
|
|
16298
|
+
transport,
|
|
16299
|
+
ref: { endpoint },
|
|
16300
|
+
signing: signer
|
|
16301
|
+
}).catch(() => []);
|
|
16302
|
+
for (const outcome of refused) {
|
|
16303
|
+
noteRefusedCreditFunding(endpoint, outcome, opts.human);
|
|
16304
|
+
clearPendingFunding(endpoint, signer.pubkey, outcome.creditId, outcome.fundId);
|
|
16305
|
+
}
|
|
16306
|
+
}
|
|
16253
16307
|
reads.push(
|
|
16254
16308
|
await balanceAt(
|
|
16255
16309
|
transport,
|
|
@@ -16258,8 +16312,7 @@ async function runCreditBalance(dvm, opts) {
|
|
|
16258
16312
|
headroomOf,
|
|
16259
16313
|
advisoryRate,
|
|
16260
16314
|
opts.creditId,
|
|
16261
|
-
opts.observeOnly
|
|
16262
|
-
opts.selectionOnly
|
|
16315
|
+
opts.observeOnly
|
|
16263
16316
|
)
|
|
16264
16317
|
);
|
|
16265
16318
|
} catch (err) {
|
|
@@ -16307,18 +16360,12 @@ async function runCreditBalance(dvm, opts) {
|
|
|
16307
16360
|
dvms: machines,
|
|
16308
16361
|
display,
|
|
16309
16362
|
hint: "Balances come from signed server reads or countersigned job receipts. `drawable: true` identifies value job draws can use; every untracked prepaid sibling carries the exact `drain_command` that reclaims it, while `kind: implicit` rows have no drain path. Each entry in `dvms` says what may be funded at that machine now. Expired prepaid credit remains reclaimable; a lost implicit balance does not.",
|
|
16310
|
-
...creditHint ? { credit_hint: creditHint } : {}
|
|
16363
|
+
...creditHint ? { credit_hint: creditHint } : {},
|
|
16364
|
+
...takeCreditNoticeFields()
|
|
16311
16365
|
}
|
|
16312
16366
|
});
|
|
16313
16367
|
}
|
|
16314
|
-
async function balanceAt(transport, endpoint, signer, headroomOf, advisoryRate, creditId, observeOnly = false
|
|
16315
|
-
if (!observeOnly && !selectionOnly) {
|
|
16316
|
-
await pollPendingCreditFundings({
|
|
16317
|
-
transport,
|
|
16318
|
-
ref: { endpoint },
|
|
16319
|
-
signing: signer
|
|
16320
|
-
}).catch(() => void 0);
|
|
16321
|
-
}
|
|
16368
|
+
async function balanceAt(transport, endpoint, signer, headroomOf, advisoryRate, creditId, observeOnly = false) {
|
|
16322
16369
|
const providerInfo = await transport.describe({ endpoint }).catch(() => void 0);
|
|
16323
16370
|
const identity = providerDvmIdentity(providerInfo);
|
|
16324
16371
|
const postureOff = effectiveCreditPosture(loadConfig()?.credit, endpoint, identity).posture === "off";
|
|
@@ -20232,6 +20279,26 @@ function capitalise(s) {
|
|
|
20232
20279
|
return s.length === 0 ? s : s[0].toUpperCase() + s.slice(1);
|
|
20233
20280
|
}
|
|
20234
20281
|
|
|
20282
|
+
// src/lib/qr.ts
|
|
20283
|
+
var import_qrcode = __toESM(require_lib(), 1);
|
|
20284
|
+
import { randomBytes as randomBytes2 } from "crypto";
|
|
20285
|
+
import { tmpdir } from "os";
|
|
20286
|
+
import { join as join4 } from "path";
|
|
20287
|
+
async function renderQrTerminal(payload) {
|
|
20288
|
+
return (0, import_qrcode.toString)(payload, { type: "terminal", small: true });
|
|
20289
|
+
}
|
|
20290
|
+
async function renderQrPng(payload, outPath) {
|
|
20291
|
+
await (0, import_qrcode.toFile)(outPath, payload, {
|
|
20292
|
+
type: "png",
|
|
20293
|
+
errorCorrectionLevel: "M",
|
|
20294
|
+
margin: 2,
|
|
20295
|
+
scale: 8
|
|
20296
|
+
});
|
|
20297
|
+
}
|
|
20298
|
+
function defaultQrImagePath(prefix = "dvm-wallet-fund") {
|
|
20299
|
+
return join4(tmpdir(), `${prefix}-${randomBytes2(8).toString("hex")}.png`);
|
|
20300
|
+
}
|
|
20301
|
+
|
|
20235
20302
|
// src/lib/credit/funding.ts
|
|
20236
20303
|
async function runCreditFund(dvm, opts) {
|
|
20237
20304
|
const invocationStartedAt = Date.now();
|
|
@@ -20249,8 +20316,15 @@ async function runCreditFund(dvm, opts) {
|
|
|
20249
20316
|
);
|
|
20250
20317
|
}
|
|
20251
20318
|
const fundingMode = parseFundingMode(opts.fundingMode);
|
|
20252
|
-
const cardSpt = await resolveCardSpt(opts.spt);
|
|
20253
20319
|
const namedRail = parseFundRail(opts.rail);
|
|
20320
|
+
if (opts.invoice && (namedRail && namedRail !== "lightning" || opts.spt !== void 0 || fundingMode || opts.cashuMint !== void 0 || opts.maxCashuPrincipalSats !== void 0 || opts.maxCashuFeeSats !== void 0)) {
|
|
20321
|
+
throw new DvmError(
|
|
20322
|
+
"invalid_argument",
|
|
20323
|
+
"--invoice only applies to Lightning credit funding.",
|
|
20324
|
+
"Use --rail lightning --invoice without card, stablecoin, or Cashu funding options."
|
|
20325
|
+
);
|
|
20326
|
+
}
|
|
20327
|
+
const cardSpt = await resolveCardSpt(opts.spt);
|
|
20254
20328
|
if (cardSpt !== void 0 && namedRail && namedRail !== "stripe") {
|
|
20255
20329
|
throw new DvmError(
|
|
20256
20330
|
"invalid_argument",
|
|
@@ -20261,7 +20335,7 @@ async function runCreditFund(dvm, opts) {
|
|
|
20261
20335
|
}
|
|
20262
20336
|
);
|
|
20263
20337
|
}
|
|
20264
|
-
const flagRail = cardSpt !== void 0 ? "stripe" : namedRail;
|
|
20338
|
+
const flagRail = opts.invoice ? "lightning" : cardSpt !== void 0 ? "stripe" : namedRail;
|
|
20265
20339
|
if (fundingMode && flagRail && !isStablecoinFundRail(flagRail)) {
|
|
20266
20340
|
throw new DvmError(
|
|
20267
20341
|
"invalid_argument",
|
|
@@ -20308,6 +20382,13 @@ async function runCreditFund(dvm, opts) {
|
|
|
20308
20382
|
stored,
|
|
20309
20383
|
journalled: pending4
|
|
20310
20384
|
});
|
|
20385
|
+
if (opts.invoice && (pending4 && pending4.rail !== "lightning" || signedPending)) {
|
|
20386
|
+
throw new DvmError(
|
|
20387
|
+
"invalid_argument",
|
|
20388
|
+
"Another funding for this credit is unresolved on a different rail.",
|
|
20389
|
+
"Resume that funding without --invoice before starting a Lightning funding."
|
|
20390
|
+
);
|
|
20391
|
+
}
|
|
20311
20392
|
const configPin = effectiveFundingRail(config2?.credit, endpoint, attestedIdentity);
|
|
20312
20393
|
const boundRail = pinnedRail(stored, opts.creditId);
|
|
20313
20394
|
if (!pending4 && !signedPending && flagRail && boundRail && flagRail !== boundRail) {
|
|
@@ -20360,6 +20441,17 @@ async function runCreditFund(dvm, opts) {
|
|
|
20360
20441
|
creditId: pending4?.creditId ?? opts.creditId ?? signedPending?.creditId ?? (canRefillStoredCredit(stored) ? stored.creditId : randomUUID3()),
|
|
20361
20442
|
amountMicro: fundMicro,
|
|
20362
20443
|
human: opts.human,
|
|
20444
|
+
invoice: opts.invoice,
|
|
20445
|
+
invoiceWait: opts.wait !== false,
|
|
20446
|
+
...signer.source.kind !== "env" ? { invoiceIdentity: signer.source.name } : {},
|
|
20447
|
+
invoiceProgress: async (handoff) => {
|
|
20448
|
+
if (opts.human) {
|
|
20449
|
+
info(String(handoff.display));
|
|
20450
|
+
info(String(handoff.bolt11));
|
|
20451
|
+
info(await renderQrTerminal(String(handoff.bolt11).toUpperCase()));
|
|
20452
|
+
info(`Resume with: ${String(handoff.next_step)}`);
|
|
20453
|
+
} else json({ op: "fund", endpoint, ...handoff });
|
|
20454
|
+
},
|
|
20363
20455
|
providerInfo,
|
|
20364
20456
|
...menu ? { menu } : {},
|
|
20365
20457
|
...stored ? { targetMicro: Math.max(stored.targetMicro, fundMicro) } : {},
|
|
@@ -20430,7 +20522,12 @@ async function runCreditFund(dvm, opts) {
|
|
|
20430
20522
|
outcome.display,
|
|
20431
20523
|
providerDisplay || providerHint ? `The DVM says: ${[providerDisplay?.text, providerHint?.text].filter(Boolean).join(" ")}` : void 0,
|
|
20432
20524
|
modeSentence,
|
|
20433
|
-
outcome.hint
|
|
20525
|
+
outcome.hint,
|
|
20526
|
+
...outcome.invoiceHandoff && opts.human ? [
|
|
20527
|
+
String(outcome.invoiceHandoff.bolt11),
|
|
20528
|
+
await renderQrTerminal(String(outcome.invoiceHandoff.bolt11).toUpperCase()),
|
|
20529
|
+
`Resume with: ${String(outcome.invoiceHandoff.next_step)}`
|
|
20530
|
+
] : []
|
|
20434
20531
|
].filter((line) => line !== void 0);
|
|
20435
20532
|
renderCreditFunding({
|
|
20436
20533
|
human: opts.human === true,
|
|
@@ -20440,6 +20537,7 @@ async function runCreditFund(dvm, opts) {
|
|
|
20440
20537
|
endpoint,
|
|
20441
20538
|
status: outcome.status,
|
|
20442
20539
|
...outcome.checkoutHandoff ?? {},
|
|
20540
|
+
...outcome.invoiceHandoff ?? {},
|
|
20443
20541
|
credit_id: outcome.creditId,
|
|
20444
20542
|
fund_id: outcome.fundId,
|
|
20445
20543
|
...resumedNote ? { resumed: resumedNote } : {},
|
|
@@ -22241,8 +22339,8 @@ async function probeX402(x402, timeoutMs) {
|
|
|
22241
22339
|
let network;
|
|
22242
22340
|
let address;
|
|
22243
22341
|
try {
|
|
22244
|
-
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-
|
|
22245
|
-
const { getX402Balance, ensureAddress: ensureAddress2, usdcContractByCaip2 } = await import("./internal-
|
|
22342
|
+
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-J7JCMFZ2.js");
|
|
22343
|
+
const { getX402Balance, ensureAddress: ensureAddress2, usdcContractByCaip2 } = await import("./internal-EQJXMIR2.js");
|
|
22246
22344
|
const wallet = loadX402Wallet2();
|
|
22247
22345
|
if (!wallet) {
|
|
22248
22346
|
const storedKey = x402.privateKey;
|
|
@@ -22294,8 +22392,8 @@ async function probeMpp(mpp, timeoutMs) {
|
|
|
22294
22392
|
if (!mpp) return null;
|
|
22295
22393
|
if (mpp.method === "tempo") {
|
|
22296
22394
|
try {
|
|
22297
|
-
const { connectedTempoAccount: connectedTempoAccount2 } = await import("./tempo-wallet-
|
|
22298
|
-
const { getTempoUsdcBalance: getTempoUsdcBalance3, resolveTempoNetwork: resolveTempoNetwork2 } = await import("./internal-
|
|
22395
|
+
const { connectedTempoAccount: connectedTempoAccount2 } = await import("./tempo-wallet-AY6R3E4Z.js");
|
|
22396
|
+
const { getTempoUsdcBalance: getTempoUsdcBalance3, resolveTempoNetwork: resolveTempoNetwork2 } = await import("./internal-EQJXMIR2.js");
|
|
22299
22397
|
const account = await connectedTempoAccount2();
|
|
22300
22398
|
if (!account) {
|
|
22301
22399
|
return {
|
|
@@ -22390,7 +22488,7 @@ function x402WrongAssetHint(asset) {
|
|
|
22390
22488
|
|
|
22391
22489
|
// src/lib/build-freshness.ts
|
|
22392
22490
|
import { existsSync as existsSync4, readdirSync, statSync } from "fs";
|
|
22393
|
-
import { dirname as dirname2, join as
|
|
22491
|
+
import { dirname as dirname2, join as join5 } from "path";
|
|
22394
22492
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
22395
22493
|
var EXTRA_SOURCES = ["package.json", "tsup.config.ts"];
|
|
22396
22494
|
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", "__snapshots__"]);
|
|
@@ -22409,11 +22507,11 @@ function checkBuildFreshness(opts) {
|
|
|
22409
22507
|
skipReason
|
|
22410
22508
|
});
|
|
22411
22509
|
if (root === null) return skipped("running_from_source");
|
|
22412
|
-
const bundlePath =
|
|
22510
|
+
const bundlePath = join5(root, "dist", "dvm.js");
|
|
22413
22511
|
if (dirname2(moduleDir) !== root || !existsSync4(bundlePath)) {
|
|
22414
22512
|
return skipped("running_from_source");
|
|
22415
22513
|
}
|
|
22416
|
-
const srcDir =
|
|
22514
|
+
const srcDir = join5(root, "src");
|
|
22417
22515
|
if (!existsSync4(srcDir)) return skipped("no_source_tree");
|
|
22418
22516
|
const builtAtMs = statSync(bundlePath).mtimeMs;
|
|
22419
22517
|
const newer = [];
|
|
@@ -22423,7 +22521,7 @@ function checkBuildFreshness(opts) {
|
|
|
22423
22521
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
22424
22522
|
if (budget2.left-- <= 0) return;
|
|
22425
22523
|
if (entry.name.startsWith(".") || SKIP_DIRS.has(entry.name)) continue;
|
|
22426
|
-
const abs =
|
|
22524
|
+
const abs = join5(dir, entry.name);
|
|
22427
22525
|
const relPath = rel ? `${rel}/${entry.name}` : entry.name;
|
|
22428
22526
|
if (entry.isDirectory()) {
|
|
22429
22527
|
visit(abs, relPath, budget2);
|
|
@@ -22438,7 +22536,7 @@ function checkBuildFreshness(opts) {
|
|
|
22438
22536
|
const budget = { left: MAX_ENTRIES };
|
|
22439
22537
|
visit(srcDir, "src", budget);
|
|
22440
22538
|
for (const name of EXTRA_SOURCES) {
|
|
22441
|
-
const abs =
|
|
22539
|
+
const abs = join5(root, name);
|
|
22442
22540
|
if (!existsSync4(abs)) continue;
|
|
22443
22541
|
const mtimeMs = statSync(abs).mtimeMs;
|
|
22444
22542
|
if (mtimeMs > newestMs) newestMs = mtimeMs;
|
|
@@ -22457,7 +22555,7 @@ function checkBuildFreshness(opts) {
|
|
|
22457
22555
|
function findPackageRoot(start) {
|
|
22458
22556
|
let dir = start;
|
|
22459
22557
|
for (; ; ) {
|
|
22460
|
-
if (existsSync4(
|
|
22558
|
+
if (existsSync4(join5(dir, "package.json"))) return dir;
|
|
22461
22559
|
const parent = dirname2(dir);
|
|
22462
22560
|
if (parent === dir) return null;
|
|
22463
22561
|
dir = parent;
|
|
@@ -22466,7 +22564,7 @@ function findPackageRoot(start) {
|
|
|
22466
22564
|
|
|
22467
22565
|
// src/lib/caller-state.ts
|
|
22468
22566
|
import { existsSync as existsSync6, readdirSync as readdirSync2, readFileSync as readFileSync6, statSync as statSync2 } from "fs";
|
|
22469
|
-
import { basename, join as
|
|
22567
|
+
import { basename, join as join7 } from "path";
|
|
22470
22568
|
|
|
22471
22569
|
// src/lib/request-refusal-store.ts
|
|
22472
22570
|
import {
|
|
@@ -22479,11 +22577,11 @@ import {
|
|
|
22479
22577
|
rmSync,
|
|
22480
22578
|
writeFileSync as writeFileSync3
|
|
22481
22579
|
} from "fs";
|
|
22482
|
-
import { join as
|
|
22483
|
-
var REQUEST_REFUSALS_DIR =
|
|
22580
|
+
import { join as join6 } from "path";
|
|
22581
|
+
var REQUEST_REFUSALS_DIR = join6(CONFIG_DIR, "request-refusals");
|
|
22484
22582
|
var SAFE_TOKEN = /^[a-z0-9_.:-]{1,64}$/;
|
|
22485
22583
|
function requestIntentMayExist(requestId) {
|
|
22486
|
-
return existsSync5(
|
|
22584
|
+
return existsSync5(join6(REQUEST_INTENTS_DIR, requestId));
|
|
22487
22585
|
}
|
|
22488
22586
|
function recordRequestRefusal(requestId, refusal) {
|
|
22489
22587
|
if (!isPublicRequestId(requestId) || requestIntentMayExist(requestId)) return false;
|
|
@@ -22530,7 +22628,7 @@ function loadRequestRefusal(requestId) {
|
|
|
22530
22628
|
}
|
|
22531
22629
|
}
|
|
22532
22630
|
function refusalPath(requestId) {
|
|
22533
|
-
return
|
|
22631
|
+
return join6(REQUEST_REFUSALS_DIR, `${requestId}.json`);
|
|
22534
22632
|
}
|
|
22535
22633
|
|
|
22536
22634
|
// src/lib/caller-state.ts
|
|
@@ -22549,9 +22647,15 @@ function detectSetupState() {
|
|
|
22549
22647
|
}
|
|
22550
22648
|
function isPartialSetup(state) {
|
|
22551
22649
|
const hasExisting = state.existingState.jobs || state.existingState.messages;
|
|
22552
|
-
const hasMissing = state.missing.config || state.missing.identity
|
|
22650
|
+
const hasMissing = state.missing.config || state.missing.identity;
|
|
22553
22651
|
return hasExisting && hasMissing;
|
|
22554
22652
|
}
|
|
22653
|
+
function describeMissingSetup(state) {
|
|
22654
|
+
const files = [];
|
|
22655
|
+
if (state.missing.config) files.push("config.json");
|
|
22656
|
+
if (state.missing.identity) files.push("identities.json");
|
|
22657
|
+
return files.join(" and ");
|
|
22658
|
+
}
|
|
22555
22659
|
function describeExisting(state) {
|
|
22556
22660
|
const { jobs, messages: messages2 } = state.existingState;
|
|
22557
22661
|
if (jobs && messages2) return "job and message history";
|
|
@@ -22683,7 +22787,7 @@ function findQuarantinedCreditStores() {
|
|
|
22683
22787
|
} catch {
|
|
22684
22788
|
return [];
|
|
22685
22789
|
}
|
|
22686
|
-
return entries.filter((name) => name.startsWith(prefix)).sort((a, b) => a < b ? 1 : a > b ? -1 : 0).map((name) => ({ path:
|
|
22790
|
+
return entries.filter((name) => name.startsWith(prefix)).sort((a, b) => a < b ? 1 : a > b ? -1 : 0).map((name) => ({ path: join7(CONFIG_DIR, name), name }));
|
|
22687
22791
|
}
|
|
22688
22792
|
function checkOne(spec) {
|
|
22689
22793
|
const exists = existsSync6(spec.path);
|
|
@@ -22722,7 +22826,7 @@ function checkSecretDirectory(dir, row) {
|
|
|
22722
22826
|
try {
|
|
22723
22827
|
const offenders = [];
|
|
22724
22828
|
for (const name of readdirSync2(dir)) {
|
|
22725
|
-
const path =
|
|
22829
|
+
const path = join7(dir, name);
|
|
22726
22830
|
const stat2 = statSync2(path);
|
|
22727
22831
|
if (!stat2.isFile()) continue;
|
|
22728
22832
|
const mode = stat2.mode & 511;
|
|
@@ -22755,7 +22859,7 @@ function readBtcRateCacheAge(now = Date.now()) {
|
|
|
22755
22859
|
|
|
22756
22860
|
// src/lib/mnemonic-backups.ts
|
|
22757
22861
|
import { readdirSync as readdirSync3, statSync as statSync3 } from "fs";
|
|
22758
|
-
import { basename as basename2, dirname as dirname3, join as
|
|
22862
|
+
import { basename as basename2, dirname as dirname3, join as join8 } from "path";
|
|
22759
22863
|
function findMnemonicBackups(mnemonicFile, nowMs = Date.now()) {
|
|
22760
22864
|
const dir = dirname3(mnemonicFile);
|
|
22761
22865
|
const prefix = `${basename2(mnemonicFile)}.`;
|
|
@@ -22767,7 +22871,7 @@ function findMnemonicBackups(mnemonicFile, nowMs = Date.now()) {
|
|
|
22767
22871
|
throw err;
|
|
22768
22872
|
}
|
|
22769
22873
|
return names.filter((name) => name.startsWith(prefix) && name.endsWith(".bak")).map((name) => {
|
|
22770
|
-
const path =
|
|
22874
|
+
const path = join8(dir, name);
|
|
22771
22875
|
const stat2 = statSync3(path);
|
|
22772
22876
|
if (!stat2.isFile()) return null;
|
|
22773
22877
|
const ageMs2 = Math.max(0, nowMs - stat2.mtimeMs);
|
|
@@ -23249,12 +23353,13 @@ function buildFileChecks() {
|
|
|
23249
23353
|
try {
|
|
23250
23354
|
const state = detectSetupState();
|
|
23251
23355
|
if (isPartialSetup(state)) {
|
|
23356
|
+
const missing = describeMissingSetup(state);
|
|
23252
23357
|
checks.push({
|
|
23253
23358
|
name: "partial_setup_state",
|
|
23254
23359
|
group: "files",
|
|
23255
23360
|
status: "warn",
|
|
23256
|
-
display:
|
|
23257
|
-
hint:
|
|
23361
|
+
display: `Caller history (jobs / messages) is present. Missing setup: ${missing}.`,
|
|
23362
|
+
hint: `Run 'dvm init' to recreate ${missing} without touching existing history.`,
|
|
23258
23363
|
details: { existingState: state.existingState, missing: state.missing }
|
|
23259
23364
|
});
|
|
23260
23365
|
}
|
|
@@ -24991,7 +25096,7 @@ var nudgedThisInvocation = false;
|
|
|
24991
25096
|
// src/lib/platform.ts
|
|
24992
25097
|
import { existsSync as existsSync8, mkdirSync as mkdirSync2, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "fs";
|
|
24993
25098
|
import { homedir as homedir2 } from "os";
|
|
24994
|
-
import { join as
|
|
25099
|
+
import { join as join9 } from "path";
|
|
24995
25100
|
function getPlatformUrl() {
|
|
24996
25101
|
return process.env.DVMKIT_PLATFORM_URL ?? "https://api.dvmkit.dev";
|
|
24997
25102
|
}
|
|
@@ -25468,11 +25573,11 @@ async function init(opts) {
|
|
|
25468
25573
|
const creditPosture2 = existing.credit?.posture ?? posture ?? DEFAULT_CREDIT_POSTURE;
|
|
25469
25574
|
const feedbackPosture2 = existing.feedback?.posture ?? DEFAULT_FEEDBACK_POSTURE;
|
|
25470
25575
|
if (opts.human) {
|
|
25471
|
-
if (
|
|
25576
|
+
if (isPartialSetup(setupState)) {
|
|
25472
25577
|
info(
|
|
25473
|
-
`Found existing ${describeExisting(setupState)} in ${CONFIG_DIR}
|
|
25578
|
+
`Found existing ${describeExisting(setupState)} in ${CONFIG_DIR}. Missing setup: ${describeMissingSetup(setupState)}.`
|
|
25474
25579
|
);
|
|
25475
|
-
info("
|
|
25580
|
+
info("Preserved existing history.");
|
|
25476
25581
|
}
|
|
25477
25582
|
info(created ? `Config written to ${CONFIG_FILE}` : `Config already exists at ${CONFIG_FILE}`);
|
|
25478
25583
|
if (!created) info("Nothing already configured was changed.");
|
|
@@ -25557,7 +25662,7 @@ function finalizeProgressLine() {
|
|
|
25557
25662
|
}
|
|
25558
25663
|
|
|
25559
25664
|
// src/lib/save-artifact.ts
|
|
25560
|
-
import { randomBytes as
|
|
25665
|
+
import { randomBytes as randomBytes3 } from "crypto";
|
|
25561
25666
|
import {
|
|
25562
25667
|
chmodSync,
|
|
25563
25668
|
closeSync as closeSync3,
|
|
@@ -25568,8 +25673,8 @@ import {
|
|
|
25568
25673
|
unlinkSync as unlinkSync3,
|
|
25569
25674
|
writeFileSync as writeFileSync6
|
|
25570
25675
|
} from "fs";
|
|
25571
|
-
import { tmpdir } from "os";
|
|
25572
|
-
import { join as
|
|
25676
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
25677
|
+
import { join as join10 } from "path";
|
|
25573
25678
|
|
|
25574
25679
|
// src/lib/mime-ext.ts
|
|
25575
25680
|
var MIME_TO_EXT = {
|
|
@@ -25625,7 +25730,7 @@ var ArtifactSaveSession = class {
|
|
|
25625
25730
|
let created = false;
|
|
25626
25731
|
try {
|
|
25627
25732
|
const directory = this.ensureDirectory();
|
|
25628
|
-
path =
|
|
25733
|
+
path = join10(directory, `artifact-${randomBytes3(16).toString("hex")}.${ext}`);
|
|
25629
25734
|
fd = openSync3(path, "wx", FILE_MODE);
|
|
25630
25735
|
created = true;
|
|
25631
25736
|
writeFileSync6(fd, buf);
|
|
@@ -25654,7 +25759,7 @@ var ArtifactSaveSession = class {
|
|
|
25654
25759
|
}
|
|
25655
25760
|
ensureDirectory() {
|
|
25656
25761
|
if (this.directory) return this.directory;
|
|
25657
|
-
const directory = mkdtempSync(
|
|
25762
|
+
const directory = mkdtempSync(join10(tmpdir2(), "dvm-artifacts-"));
|
|
25658
25763
|
try {
|
|
25659
25764
|
chmodSync(directory, DIRECTORY_MODE);
|
|
25660
25765
|
} catch (err) {
|
|
@@ -25979,7 +26084,7 @@ async function waitAttached(opts, durationMs, now) {
|
|
|
25979
26084
|
try {
|
|
25980
26085
|
return await read();
|
|
25981
26086
|
} catch (error) {
|
|
25982
|
-
if (!
|
|
26087
|
+
if (!isTransientJobReadError(error)) throw error;
|
|
25983
26088
|
await new Promise((resolve3) => setTimeout(resolve3, Math.min(backoffMs, Math.max(0, deadline - now()))));
|
|
25984
26089
|
backoffMs = Math.min(backoffMs * 2, 3e4);
|
|
25985
26090
|
}
|
|
@@ -26074,6 +26179,7 @@ async function waitAttached(opts, durationMs, now) {
|
|
|
26074
26179
|
onMessage,
|
|
26075
26180
|
messageAppendSession,
|
|
26076
26181
|
afterSeq: streamAfter,
|
|
26182
|
+
retryUnreachableReads: true,
|
|
26077
26183
|
timeoutMs: readOptions().timeoutMs
|
|
26078
26184
|
});
|
|
26079
26185
|
collectMessages(next.messages);
|
|
@@ -26121,11 +26227,11 @@ async function messages(jobId, opts) {
|
|
|
26121
26227
|
if (opts.until !== void 0 && !opts.wait || opts.wait && opts.stream === false) {
|
|
26122
26228
|
throw new DvmError("invalid_arguments", "Use --until with --wait, and --wait with streaming enabled.");
|
|
26123
26229
|
}
|
|
26230
|
+
const waitDuration = opts.wait ? parseDurationMs(opts.until ?? "12h") : void 0;
|
|
26124
26231
|
const access = resolveJobAccess(jobId, opts);
|
|
26125
|
-
return withJobTokenRedaction(access.jobToken, () => withOutputWarnings(() => messagesWithAccess(jobId, opts, access), opts.human));
|
|
26232
|
+
return withJobTokenRedaction(access.jobToken, () => withOutputWarnings(() => messagesWithAccess(jobId, opts, access, waitDuration), opts.human));
|
|
26126
26233
|
}
|
|
26127
|
-
async function messagesWithAccess(jobId, opts, access) {
|
|
26128
|
-
const waitDuration = opts.wait ? parseDurationMs(opts.until ?? "12h") : void 0;
|
|
26234
|
+
async function messagesWithAccess(jobId, opts, access, waitDuration) {
|
|
26129
26235
|
const artifactSession = opts.human ? createArtifactSaveSession() : void 0;
|
|
26130
26236
|
const { stored, ref, jobToken } = access;
|
|
26131
26237
|
const json3 = (data) => providerJobJson(data, !!stored);
|
|
@@ -26798,15 +26904,15 @@ function parsePositiveCashuSats(raw2) {
|
|
|
26798
26904
|
function positive(value) {
|
|
26799
26905
|
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
26800
26906
|
}
|
|
26801
|
-
function autoPayWarnings(
|
|
26907
|
+
function autoPayWarnings(quotes2, limits, ceiling, btcRate = getLastKnownBtcRate()?.rate ?? 0, { upfrontCoveredByCredit = false } = {}) {
|
|
26802
26908
|
if (!limits.budget && !limits.autoPayBelow) return [];
|
|
26803
26909
|
if (!positive(btcRate)) {
|
|
26804
|
-
const quoted =
|
|
26910
|
+
const quoted = quotes2.find((quote2) => quote2.upfront?.currency === "usd" && positive(quote2.upfront.amount) && positive(quote2.priceMsats));
|
|
26805
26911
|
btcRate = getLastKnownBtcRate()?.rate ?? (quoted ? quoted.upfront.amount * 1e11 / quoted.priceMsats : 0);
|
|
26806
26912
|
}
|
|
26807
26913
|
const amounts = [];
|
|
26808
26914
|
let excludedUpfront = false;
|
|
26809
|
-
for (const quote2 of
|
|
26915
|
+
for (const quote2 of quotes2) {
|
|
26810
26916
|
if (quote2.upfront?.currency === "usd" && positive(quote2.upfront.amount)) {
|
|
26811
26917
|
if (upfrontCoveredByCredit) excludedUpfront = true;
|
|
26812
26918
|
else amounts.push(quote2.upfront.amount);
|
|
@@ -26952,7 +27058,7 @@ function jsonParseErrorLine(jsonText, err) {
|
|
|
26952
27058
|
function expectedFieldsFromSchema(schema) {
|
|
26953
27059
|
const props = schema.properties;
|
|
26954
27060
|
if (!isPlainObject(props)) return [];
|
|
26955
|
-
const requiredList = Array.isArray(schema.required) ? schema.required.filter((
|
|
27061
|
+
const requiredList = Array.isArray(schema.required) ? schema.required.filter((x2) => typeof x2 === "string") : [];
|
|
26956
27062
|
const required = new Set(requiredList);
|
|
26957
27063
|
const out = [];
|
|
26958
27064
|
for (const [name, raw2] of Object.entries(props)) {
|
|
@@ -26999,7 +27105,7 @@ function jsonSchemaType(node) {
|
|
|
26999
27105
|
if (!isPlainObject(node)) return "unknown";
|
|
27000
27106
|
const t = node.type;
|
|
27001
27107
|
if (typeof t === "string") return t;
|
|
27002
|
-
if (Array.isArray(t)) return t.filter((
|
|
27108
|
+
if (Array.isArray(t)) return t.filter((x2) => typeof x2 === "string").join("|") || "unknown";
|
|
27003
27109
|
if (Array.isArray(node.anyOf) || Array.isArray(node.oneOf)) return "union";
|
|
27004
27110
|
if (Array.isArray(node.enum)) return "enum";
|
|
27005
27111
|
return "unknown";
|
|
@@ -27197,7 +27303,7 @@ async function quoteWithWarnings(opts) {
|
|
|
27197
27303
|
});
|
|
27198
27304
|
progressNotice("Requesting quote...", opts.human);
|
|
27199
27305
|
const usedPrimitiveInput = !!opts.input && !opts.data && !(opts.param && opts.param.length > 0);
|
|
27200
|
-
const
|
|
27306
|
+
const quotes2 = await withInputSchemaHint(
|
|
27201
27307
|
transport,
|
|
27202
27308
|
ref,
|
|
27203
27309
|
{
|
|
@@ -27211,10 +27317,10 @@ async function quoteWithWarnings(opts) {
|
|
|
27211
27317
|
},
|
|
27212
27318
|
() => transport.quote(ref, envelope)
|
|
27213
27319
|
);
|
|
27214
|
-
if (
|
|
27320
|
+
if (quotes2.length === 0) {
|
|
27215
27321
|
throw new DvmError("no_quotes", "No quotes received from provider.");
|
|
27216
27322
|
}
|
|
27217
|
-
const q =
|
|
27323
|
+
const q = quotes2[0];
|
|
27218
27324
|
const pricing = providerInfo.capabilities?.[capability]?.pricing;
|
|
27219
27325
|
addOutputWarnings(autoPayWarnings([q], {
|
|
27220
27326
|
budget: opts.budget ?? config2?.defaultBudget,
|
|
@@ -27849,13 +27955,13 @@ function buildRow(url2, list, fee, source) {
|
|
|
27849
27955
|
}
|
|
27850
27956
|
|
|
27851
27957
|
// src/commands/request-output.ts
|
|
27852
|
-
function outputCollectedQuotes(jobId,
|
|
27958
|
+
function outputCollectedQuotes(jobId, quotes2, opts, identity, hint, nextAction) {
|
|
27853
27959
|
const defaultHint = jobId ? "Use --auto-pay or --budget to pay automatically." : "Upfront payment required. Re-submit with --auto-pay to pay automatically.";
|
|
27854
27960
|
const effectiveHint = nextAction?.hint ?? hint ?? defaultHint;
|
|
27855
27961
|
if (opts.human) {
|
|
27856
|
-
info(`${
|
|
27857
|
-
for (let i2 = 0; i2 <
|
|
27858
|
-
const q =
|
|
27962
|
+
info(`${quotes2.length} quote(s) received:`);
|
|
27963
|
+
for (let i2 = 0; i2 < quotes2.length; i2++) {
|
|
27964
|
+
const q = quotes2[i2];
|
|
27859
27965
|
info(` ${i2 + 1}. ${quoteAmountLabel(q)}`);
|
|
27860
27966
|
}
|
|
27861
27967
|
info(`
|
|
@@ -27869,14 +27975,14 @@ ${effectiveHint}`);
|
|
|
27869
27975
|
...requestIdFields(opts),
|
|
27870
27976
|
...dvmIdentity(identity?.dvmId, identity?.capability),
|
|
27871
27977
|
status: "quotes-collected",
|
|
27872
|
-
quotes: formatQuotes(
|
|
27978
|
+
quotes: formatQuotes(quotes2),
|
|
27873
27979
|
hint: effectiveHint,
|
|
27874
27980
|
...takeCreditNoticeFields(),
|
|
27875
27981
|
next_action: nextAction ?? null
|
|
27876
27982
|
});
|
|
27877
27983
|
}
|
|
27878
27984
|
}
|
|
27879
|
-
function outputQuotesNoWallet(jobId,
|
|
27985
|
+
function outputQuotesNoWallet(jobId, quotes2, opts, identity) {
|
|
27880
27986
|
const nextAction = {
|
|
27881
27987
|
type: "setup_wallet",
|
|
27882
27988
|
command: "dvm wallet setup",
|
|
@@ -27885,7 +27991,7 @@ function outputQuotesNoWallet(jobId, quotes, opts, identity) {
|
|
|
27885
27991
|
};
|
|
27886
27992
|
if (opts.human) {
|
|
27887
27993
|
info("No wallet connected. Quotes received:");
|
|
27888
|
-
for (const q of
|
|
27994
|
+
for (const q of quotes2) {
|
|
27889
27995
|
info(` ${quoteAmountLabel(q)}`);
|
|
27890
27996
|
}
|
|
27891
27997
|
info(`
|
|
@@ -27897,7 +28003,7 @@ ${nextAction.hint}`);
|
|
|
27897
28003
|
...requestIdFields(opts),
|
|
27898
28004
|
...dvmIdentity(identity?.dvmId, identity?.capability),
|
|
27899
28005
|
status: "quotes-collected",
|
|
27900
|
-
quotes: formatQuotes(
|
|
28006
|
+
quotes: formatQuotes(quotes2),
|
|
27901
28007
|
message: "No wallet connected.",
|
|
27902
28008
|
hint: nextAction.hint,
|
|
27903
28009
|
...takeCreditNoticeFields(),
|
|
@@ -27905,7 +28011,7 @@ ${nextAction.hint}`);
|
|
|
27905
28011
|
});
|
|
27906
28012
|
}
|
|
27907
28013
|
}
|
|
27908
|
-
function outputQuotesNoEligibleMint(jobId,
|
|
28014
|
+
function outputQuotesNoEligibleMint(jobId, quotes2, opts, identity, detail) {
|
|
27909
28015
|
const acceptedList = detail.acceptedMints.join(", ") || "(none advertised)";
|
|
27910
28016
|
const heldList = detail.heldMints.map((m) => `${m.mint}: ${m.sats} sats`).join(", ");
|
|
27911
28017
|
const message2 = detail.code === "no_eligible_mint" ? "Wallet connected, but it holds no balance at any Cashu mint this service accepts." : "Wallet connected, but its balance at this service's accepted mint is too low to cover the quote.";
|
|
@@ -27918,7 +28024,7 @@ function outputQuotesNoEligibleMint(jobId, quotes, opts, identity, detail) {
|
|
|
27918
28024
|
};
|
|
27919
28025
|
if (opts.human) {
|
|
27920
28026
|
info(message2);
|
|
27921
|
-
for (const q of
|
|
28027
|
+
for (const q of quotes2) {
|
|
27922
28028
|
info(` ${quoteAmountLabel(q)}`);
|
|
27923
28029
|
}
|
|
27924
28030
|
info(`
|
|
@@ -27930,7 +28036,7 @@ ${hint}`);
|
|
|
27930
28036
|
...requestIdFields(opts),
|
|
27931
28037
|
...dvmIdentity(identity?.dvmId, identity?.capability),
|
|
27932
28038
|
status: "quotes-collected",
|
|
27933
|
-
quotes: formatQuotes(
|
|
28039
|
+
quotes: formatQuotes(quotes2),
|
|
27934
28040
|
message: message2,
|
|
27935
28041
|
hint,
|
|
27936
28042
|
...takeCreditNoticeFields(),
|
|
@@ -27941,11 +28047,11 @@ ${hint}`);
|
|
|
27941
28047
|
});
|
|
27942
28048
|
}
|
|
27943
28049
|
}
|
|
27944
|
-
function outputOverBudget(jobId,
|
|
27945
|
-
const effectiveHint = nextAction?.hint ?? `Every quote is above your budget${
|
|
28050
|
+
function outputOverBudget(jobId, quotes2, opts, identity, nextAction) {
|
|
28051
|
+
const effectiveHint = nextAction?.hint ?? `Every quote is above your budget${quotes2.length > 0 ? ` \u2014 the cheapest is ${quoteAmountLabel(cheapestQuote(quotes2))}` : ""}. Re-run with --budget at or above the quote price to approve it.`;
|
|
27946
28052
|
if (opts.human) {
|
|
27947
28053
|
info("No quotes within budget.");
|
|
27948
|
-
for (const q of
|
|
28054
|
+
for (const q of quotes2) {
|
|
27949
28055
|
info(` ${quoteAmountLabel(q)}`);
|
|
27950
28056
|
}
|
|
27951
28057
|
info(`
|
|
@@ -27959,18 +28065,18 @@ ${effectiveHint}`);
|
|
|
27959
28065
|
...requestIdFields(opts),
|
|
27960
28066
|
...dvmIdentity(identity?.dvmId, identity?.capability),
|
|
27961
28067
|
status: "over-budget",
|
|
27962
|
-
quotes: formatQuotes(
|
|
28068
|
+
quotes: formatQuotes(quotes2),
|
|
27963
28069
|
hint: effectiveHint,
|
|
27964
28070
|
...takeCreditNoticeFields(),
|
|
27965
28071
|
next_action: nextAction ?? null
|
|
27966
28072
|
});
|
|
27967
28073
|
}
|
|
27968
28074
|
}
|
|
27969
|
-
function cheapestQuote(
|
|
27970
|
-
return
|
|
28075
|
+
function cheapestQuote(quotes2) {
|
|
28076
|
+
return quotes2.reduce((min, q) => q.priceMsats < min.priceMsats ? q : min);
|
|
27971
28077
|
}
|
|
27972
|
-
function formatQuotes(
|
|
27973
|
-
return
|
|
28078
|
+
function formatQuotes(quotes2) {
|
|
28079
|
+
return quotes2.map((q) => ({
|
|
27974
28080
|
upfront: q.upfront,
|
|
27975
28081
|
msats: q.priceMsats,
|
|
27976
28082
|
...q.description ? { description: asProviderText(q.description) } : {},
|
|
@@ -28483,22 +28589,22 @@ async function requestWithWarnings(opts, stage) {
|
|
|
28483
28589
|
jobRequestId = recovered.requestId;
|
|
28484
28590
|
}
|
|
28485
28591
|
if (receipt.status === "payment-required") {
|
|
28486
|
-
const
|
|
28592
|
+
const quotes2 = receipt.quotes ?? [];
|
|
28487
28593
|
if (opts.creditOnly) {
|
|
28488
28594
|
transport.close();
|
|
28489
28595
|
throw new DvmError("credit_only_unavailable", "The selected prepaid credit did not cover this submission; no fresh payment was attempted.");
|
|
28490
28596
|
}
|
|
28491
28597
|
if (!previewWarnings.length || previewUpfrontCoveredByCredit) {
|
|
28492
|
-
addOutputWarnings(autoPayWarnings(
|
|
28598
|
+
addOutputWarnings(autoPayWarnings(quotes2, warningLimits, void 0, btcRate), opts.human);
|
|
28493
28599
|
}
|
|
28494
|
-
if (autoPayConsent &&
|
|
28600
|
+
if (autoPayConsent && quotes2.length > 0) {
|
|
28495
28601
|
const pay2 = () => handleAutoPayQuotes(
|
|
28496
28602
|
transport,
|
|
28497
28603
|
ref,
|
|
28498
28604
|
envelope,
|
|
28499
28605
|
receipt.jobId,
|
|
28500
28606
|
deadlineMs,
|
|
28501
|
-
|
|
28607
|
+
quotes2,
|
|
28502
28608
|
budgetMsats,
|
|
28503
28609
|
opts,
|
|
28504
28610
|
identity,
|
|
@@ -28525,8 +28631,8 @@ async function requestWithWarnings(opts, stage) {
|
|
|
28525
28631
|
transport.close();
|
|
28526
28632
|
const minMaxPayments = opts.maxPayments === "0" ? 1 : void 0;
|
|
28527
28633
|
let action;
|
|
28528
|
-
if (
|
|
28529
|
-
const cheapest = cheapestQuote(
|
|
28634
|
+
if (quotes2.length > 0) {
|
|
28635
|
+
const cheapest = cheapestQuote(quotes2);
|
|
28530
28636
|
const adjustmentNote = minMaxPayments ? " Bumps --max-payments from 0 to 1." : "";
|
|
28531
28637
|
action = buildResubmitAction(
|
|
28532
28638
|
opts,
|
|
@@ -28534,7 +28640,7 @@ async function requestWithWarnings(opts, stage) {
|
|
|
28534
28640
|
`Upfront payment required: ${quoteAmountLabel(cheapest)}. Re-run with --auto-pay to approve.${adjustmentNote}`
|
|
28535
28641
|
);
|
|
28536
28642
|
}
|
|
28537
|
-
outputCollectedQuotes(receipt.jobId || null,
|
|
28643
|
+
outputCollectedQuotes(receipt.jobId || null, quotes2, opts, identity, void 0, action);
|
|
28538
28644
|
return;
|
|
28539
28645
|
}
|
|
28540
28646
|
saveSubmittedJob({
|
|
@@ -28807,8 +28913,8 @@ function sha256Hex(value) {
|
|
|
28807
28913
|
}
|
|
28808
28914
|
async function fetchServerPriceMicro(transport, ref, envelope) {
|
|
28809
28915
|
try {
|
|
28810
|
-
const
|
|
28811
|
-
return quotePriceMicro(
|
|
28916
|
+
const quotes2 = await transport.quote(ref, envelope);
|
|
28917
|
+
return quotePriceMicro(quotes2[0]);
|
|
28812
28918
|
} catch {
|
|
28813
28919
|
return void 0;
|
|
28814
28920
|
}
|
|
@@ -29051,22 +29157,22 @@ async function recoverDrawProbe(err, args) {
|
|
|
29051
29157
|
}
|
|
29052
29158
|
throw err;
|
|
29053
29159
|
}
|
|
29054
|
-
async function handleAutoPayQuotes(transport, ref, envelope, jobId, deadlineMs,
|
|
29160
|
+
async function handleAutoPayQuotes(transport, ref, envelope, jobId, deadlineMs, quotes2, budgetMsats, opts, identity, policy, providerInfo, creditCtx) {
|
|
29055
29161
|
const configuredLimits = loadConfig();
|
|
29056
29162
|
const declaredBudget = opts.budget ?? configuredLimits?.defaultBudget;
|
|
29057
29163
|
const declaredAutoPayBelow = opts.autoPayBelow ?? configuredLimits?.autoPayThreshold;
|
|
29058
|
-
const chosen = budgetMsats ?
|
|
29164
|
+
const chosen = budgetMsats ? quotes2.find(
|
|
29059
29165
|
(quote2) => quoteWithinDeclaredLimit(quote2, budgetMsats, declaredBudget, opts.rail)
|
|
29060
|
-
) :
|
|
29166
|
+
) : quotes2[0];
|
|
29061
29167
|
if (!chosen) {
|
|
29062
29168
|
transport.close?.();
|
|
29063
|
-
const cheapest = cheapestQuote(
|
|
29169
|
+
const cheapest = cheapestQuote(quotes2);
|
|
29064
29170
|
const action = buildResubmitAction(
|
|
29065
29171
|
opts,
|
|
29066
29172
|
{ minBudgetMsats: cheapest.priceMsats, minAutoPayBelowMsats: cheapest.priceMsats },
|
|
29067
29173
|
`Cheapest quote (${quoteAmountLabel(cheapest)}) exceeds your --budget. Re-run with --budget at or above the quote price.`
|
|
29068
29174
|
);
|
|
29069
|
-
outputOverBudget(jobId || null,
|
|
29175
|
+
outputOverBudget(jobId || null, quotes2, opts, identity, action);
|
|
29070
29176
|
return;
|
|
29071
29177
|
}
|
|
29072
29178
|
if (!quoteWithinDeclaredLimit(chosen, policy.autoPayBelowMsats, declaredAutoPayBelow, opts.rail)) {
|
|
@@ -29078,7 +29184,7 @@ async function handleAutoPayQuotes(transport, ref, envelope, jobId, deadlineMs,
|
|
|
29078
29184
|
);
|
|
29079
29185
|
outputCollectedQuotes(
|
|
29080
29186
|
jobId || null,
|
|
29081
|
-
|
|
29187
|
+
quotes2,
|
|
29082
29188
|
opts,
|
|
29083
29189
|
identity,
|
|
29084
29190
|
"Price exceeds your --auto-pay-below threshold. Increase it or pass a higher --budget.",
|
|
@@ -29095,7 +29201,7 @@ async function handleAutoPayQuotes(transport, ref, envelope, jobId, deadlineMs,
|
|
|
29095
29201
|
);
|
|
29096
29202
|
outputCollectedQuotes(
|
|
29097
29203
|
jobId || null,
|
|
29098
|
-
|
|
29204
|
+
quotes2,
|
|
29099
29205
|
opts,
|
|
29100
29206
|
identity,
|
|
29101
29207
|
"--max-payments is 0 but a payment is required to proceed. Resubmit with --max-payments 1 (or higher) and --auto-pay if you wish to authorise it.",
|
|
@@ -29246,7 +29352,7 @@ async function handleAutoPayQuotes(transport, ref, envelope, jobId, deadlineMs,
|
|
|
29246
29352
|
}
|
|
29247
29353
|
if (selection.rails.length === 0) {
|
|
29248
29354
|
transport.close?.();
|
|
29249
|
-
outputQuotesNoWallet(jobId,
|
|
29355
|
+
outputQuotesNoWallet(jobId, quotes2, opts, identity);
|
|
29250
29356
|
return;
|
|
29251
29357
|
}
|
|
29252
29358
|
if (opts.mint && !selection.rails.some((r) => r === "cashu_p2pk")) {
|
|
@@ -29323,7 +29429,7 @@ async function handleAutoPayQuotes(transport, ref, envelope, jobId, deadlineMs,
|
|
|
29323
29429
|
jobId,
|
|
29324
29430
|
deadlineMs,
|
|
29325
29431
|
chosen,
|
|
29326
|
-
quotes,
|
|
29432
|
+
quotes: quotes2,
|
|
29327
29433
|
opts: railOpts,
|
|
29328
29434
|
identity,
|
|
29329
29435
|
policy,
|
|
@@ -29362,14 +29468,14 @@ async function handleAutoPayQuotes(transport, ref, envelope, jobId, deadlineMs,
|
|
|
29362
29468
|
if (cashuFellThroughCode && agentWallet) {
|
|
29363
29469
|
outputQuotesNoEligibleMint(
|
|
29364
29470
|
jobId,
|
|
29365
|
-
|
|
29471
|
+
quotes2,
|
|
29366
29472
|
opts,
|
|
29367
29473
|
identity,
|
|
29368
29474
|
buildNoEligibleMintDetail(cashuFellThroughCode, providerInfo, agentWallet, chosen)
|
|
29369
29475
|
);
|
|
29370
29476
|
return;
|
|
29371
29477
|
}
|
|
29372
|
-
outputQuotesNoWallet(jobId,
|
|
29478
|
+
outputQuotesNoWallet(jobId, quotes2, opts, identity);
|
|
29373
29479
|
}
|
|
29374
29480
|
function buildNoEligibleMintDetail(code, providerInfo, agentWallet, chosen) {
|
|
29375
29481
|
const acceptedMints = providerInfo.cashu?.mints ?? [];
|
|
@@ -30268,6 +30374,7 @@ async function payWithAgentWallet(transport, ref, envelope, jobId, deadlineMs, c
|
|
|
30268
30374
|
}
|
|
30269
30375
|
await collectCashuChange(effectiveJobId, receipt.cashuChange);
|
|
30270
30376
|
recordUpfrontRailPayment(effectiveJobId, cashuUpfrontPayment(chosen, btcRate), true);
|
|
30377
|
+
addCashuSwapFee(effectiveJobId, prepared.swapFeeSats);
|
|
30271
30378
|
if (!hasUnsavedJobState()) await commitAgentSpend({
|
|
30272
30379
|
requestId: prepared.requestId,
|
|
30273
30380
|
recentSpend: {
|
|
@@ -30275,6 +30382,7 @@ async function payWithAgentWallet(transport, ref, envelope, jobId, deadlineMs, c
|
|
|
30275
30382
|
dvm_endpoint: ref.endpoint,
|
|
30276
30383
|
mint: prepared.mint,
|
|
30277
30384
|
amount_sats: prepared.totalSats,
|
|
30385
|
+
...prepared.swapFeeSats > 0 ? { fee_sats: prepared.swapFeeSats } : {},
|
|
30278
30386
|
signed_at_ms: Date.now()
|
|
30279
30387
|
}
|
|
30280
30388
|
});
|
|
@@ -30323,6 +30431,8 @@ async function payWithAgentWallet(transport, ref, envelope, jobId, deadlineMs, c
|
|
|
30323
30431
|
transport.close?.();
|
|
30324
30432
|
if (opts.human) {
|
|
30325
30433
|
console.log(receipt.summary);
|
|
30434
|
+
const feeLine = describeCashuPayment(prepared.totalSats, prepared.swapFeeSats);
|
|
30435
|
+
if (feeLine) info(feeLine);
|
|
30326
30436
|
const hint = nextStepHint(effectiveJobId, receipt.payloadIn, receipt.artifactCount, true);
|
|
30327
30437
|
if (hint) info(`\u{1F4CE} ${hint}`);
|
|
30328
30438
|
await renderReceiptHuman(captured, effectiveJobId);
|
|
@@ -30337,6 +30447,7 @@ async function payWithAgentWallet(transport, ref, envelope, jobId, deadlineMs, c
|
|
|
30337
30447
|
paidWith: "cashu_p2pk",
|
|
30338
30448
|
mint: prepared.mint,
|
|
30339
30449
|
amountSats: prepared.totalSats,
|
|
30450
|
+
...cashuPaymentFeeFields(prepared.totalSats, prepared.swapFeeSats),
|
|
30340
30451
|
requestId: prepared.requestId,
|
|
30341
30452
|
...prepared.attempts?.length ? { mint_attempts: prepared.attempts } : {},
|
|
30342
30453
|
...prepared.submissionBindingFingerprint ? { submissionBindingFingerprint: prepared.submissionBindingFingerprint } : {},
|
|
@@ -30363,6 +30474,7 @@ async function payWithAgentWallet(transport, ref, envelope, jobId, deadlineMs, c
|
|
|
30363
30474
|
paidWith: "cashu_p2pk",
|
|
30364
30475
|
mint: prepared.mint,
|
|
30365
30476
|
amountSats: prepared.totalSats,
|
|
30477
|
+
...cashuPaymentFeeFields(prepared.totalSats, prepared.swapFeeSats),
|
|
30366
30478
|
requestId: prepared.requestId,
|
|
30367
30479
|
...prepared.attempts?.length ? { mint_attempts: prepared.attempts } : {},
|
|
30368
30480
|
...prepared.submissionBindingFingerprint ? { submissionBindingFingerprint: prepared.submissionBindingFingerprint } : {}
|
|
@@ -31430,6 +31542,9 @@ function jobSpend(job, receipt) {
|
|
|
31430
31542
|
if (receipt && job.paymentMethod === "credit" && !knownCredit) display += " The receipt total includes the unrecorded credit draw.";
|
|
31431
31543
|
if (receipt && converted) display += " Receipt comparison is unknown: local records lack comparable native settlement amounts for Tempo/x402 payments. Converted BTC totals can differ with exchange rates and do not establish a difference in token principal or fees.";
|
|
31432
31544
|
const [receiptLabel, localLabel] = receiptTotalDisplay === totalDisplay ? [`${receipt.paid.msats} msats`, `${total} msats`] : [receiptTotalDisplay, totalDisplay];
|
|
31545
|
+
const swapFeeSats = job.cashuSwapFeeSats ?? 0;
|
|
31546
|
+
const swapFeeDisplay = swapFeeSats > 0 ? `Mint fee: ${formatPaymentAmount(swapFeeSats * 1e3, void 0, { anchor: false })} left your wallet on top of the payments above. ${MINT_FEE_EXPLAINER}` : void 0;
|
|
31547
|
+
if (swapFeeDisplay) display += ` ${swapFeeDisplay}`;
|
|
31433
31548
|
if (receiptMismatch) display += ` Receipt total ${receiptLabel} differs from local total ${localLabel}; mint fees, returned change, or a payment not recorded locally can explain the difference.`;
|
|
31434
31549
|
return {
|
|
31435
31550
|
charges,
|
|
@@ -31445,6 +31560,7 @@ function jobSpend(job, receipt) {
|
|
|
31445
31560
|
)
|
|
31446
31561
|
} : {},
|
|
31447
31562
|
...budgetDisplay ? { budget_display: budgetDisplay } : {},
|
|
31563
|
+
...swapFeeDisplay ? { swap_fee_sats: swapFeeSats, swap_fee_display: swapFeeDisplay } : {},
|
|
31448
31564
|
payments,
|
|
31449
31565
|
max_payments: job.policy?.maxPayments ?? null,
|
|
31450
31566
|
log_mismatch: logMismatch,
|
|
@@ -33768,26 +33884,6 @@ function mnemonicValidationError(result) {
|
|
|
33768
33884
|
);
|
|
33769
33885
|
}
|
|
33770
33886
|
|
|
33771
|
-
// src/lib/qr.ts
|
|
33772
|
-
var import_qrcode = __toESM(require_lib(), 1);
|
|
33773
|
-
import { randomBytes as randomBytes3 } from "crypto";
|
|
33774
|
-
import { tmpdir as tmpdir2 } from "os";
|
|
33775
|
-
import { join as join10 } from "path";
|
|
33776
|
-
async function renderQrTerminal(payload) {
|
|
33777
|
-
return (0, import_qrcode.toString)(payload, { type: "terminal", small: true });
|
|
33778
|
-
}
|
|
33779
|
-
async function renderQrPng(payload, outPath) {
|
|
33780
|
-
await (0, import_qrcode.toFile)(outPath, payload, {
|
|
33781
|
-
type: "png",
|
|
33782
|
-
errorCorrectionLevel: "M",
|
|
33783
|
-
margin: 2,
|
|
33784
|
-
scale: 8
|
|
33785
|
-
});
|
|
33786
|
-
}
|
|
33787
|
-
function defaultQrImagePath(prefix = "dvm-wallet-fund") {
|
|
33788
|
-
return join10(tmpdir2(), `${prefix}-${randomBytes3(8).toString("hex")}.png`);
|
|
33789
|
-
}
|
|
33790
|
-
|
|
33791
33887
|
// src/lib/funding-handoff.ts
|
|
33792
33888
|
var EVM_ADDRESS = /^0x[0-9a-fA-F]{40}$/;
|
|
33793
33889
|
async function prepareStablecoinFundingHandoff(opts) {
|
|
@@ -34229,6 +34325,105 @@ function examples(fetcher) {
|
|
|
34229
34325
|
return parts.join(", ");
|
|
34230
34326
|
}
|
|
34231
34327
|
|
|
34328
|
+
// src/lib/error-handler.ts
|
|
34329
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
34330
|
+
import { dirname as dirname4, isAbsolute as isAbsolute2, join as join12, relative as relative2, sep as sep3 } from "path";
|
|
34331
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
34332
|
+
|
|
34333
|
+
// src/lib/internal-error-log.ts
|
|
34334
|
+
import { closeSync as closeSync4, constants, fchmodSync, fstatSync as fstatSync2, openSync as openSync4, renameSync as renameSync5, rmSync as rmSync2, writeSync, chmodSync as chmodSync2, readFileSync as readFileSync10, lstatSync } from "fs";
|
|
34335
|
+
import { homedir as homedir3 } from "os";
|
|
34336
|
+
import { isAbsolute, join as join11, relative, sep as sep2 } from "path";
|
|
34337
|
+
var MAX_LOG_BYTES = 256 * 1024;
|
|
34338
|
+
function appendInternalErrorLog(err, diagnostic) {
|
|
34339
|
+
let fd;
|
|
34340
|
+
try {
|
|
34341
|
+
const record2 = JSON.stringify({
|
|
34342
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34343
|
+
version: localVersion(),
|
|
34344
|
+
command: process.argv[2],
|
|
34345
|
+
code: "internal",
|
|
34346
|
+
error_name: diagnostic.name,
|
|
34347
|
+
...diagnostic.code ? { error_code: diagnostic.code } : {},
|
|
34348
|
+
...errorDetail(err, 0)
|
|
34349
|
+
}) + "\n";
|
|
34350
|
+
if (Buffer.byteLength(record2) > MAX_LOG_BYTES) return void 0;
|
|
34351
|
+
const dir = join11(CONFIG_DIR, "logs");
|
|
34352
|
+
const file2 = join11(dir, "internal-errors.jsonl");
|
|
34353
|
+
try {
|
|
34354
|
+
if (!lstatSync(dir).isDirectory()) return void 0;
|
|
34355
|
+
} catch (err2) {
|
|
34356
|
+
if (err2.code !== "ENOENT") throw err2;
|
|
34357
|
+
ensureConfigSubdir(dir);
|
|
34358
|
+
}
|
|
34359
|
+
if (!lstatSync(dir).isDirectory()) return void 0;
|
|
34360
|
+
chmodSync2(dir, 448);
|
|
34361
|
+
const open2 = () => {
|
|
34362
|
+
const descriptor = openSync4(file2, constants.O_WRONLY | constants.O_CREAT | constants.O_APPEND | constants.O_NOFOLLOW, 384);
|
|
34363
|
+
try {
|
|
34364
|
+
fchmodSync(descriptor, 384);
|
|
34365
|
+
return descriptor;
|
|
34366
|
+
} catch (err2) {
|
|
34367
|
+
closeSync4(descriptor);
|
|
34368
|
+
throw err2;
|
|
34369
|
+
}
|
|
34370
|
+
};
|
|
34371
|
+
fd = open2();
|
|
34372
|
+
const size = fstatSync2(fd).size;
|
|
34373
|
+
if (size + Buffer.byteLength(record2) > MAX_LOG_BYTES) {
|
|
34374
|
+
closeSync4(fd);
|
|
34375
|
+
fd = void 0;
|
|
34376
|
+
rmSync2(file2 + ".1", { force: true });
|
|
34377
|
+
if (size <= MAX_LOG_BYTES) renameSync5(file2, file2 + ".1");
|
|
34378
|
+
else rmSync2(file2);
|
|
34379
|
+
fd = open2();
|
|
34380
|
+
}
|
|
34381
|
+
const bytes = Buffer.from(record2);
|
|
34382
|
+
let offset = 0;
|
|
34383
|
+
while (offset < bytes.length) offset += writeSync(fd, bytes, offset, bytes.length - offset);
|
|
34384
|
+
closeSync4(fd);
|
|
34385
|
+
fd = void 0;
|
|
34386
|
+
const fromHome = relative(homedir3(), file2);
|
|
34387
|
+
return fromHome !== ".." && !fromHome.startsWith(".." + sep2) && !isAbsolute(fromHome) ? join11("~", fromHome) : file2;
|
|
34388
|
+
} catch {
|
|
34389
|
+
return void 0;
|
|
34390
|
+
} finally {
|
|
34391
|
+
if (fd !== void 0) {
|
|
34392
|
+
try {
|
|
34393
|
+
closeSync4(fd);
|
|
34394
|
+
} catch {
|
|
34395
|
+
}
|
|
34396
|
+
}
|
|
34397
|
+
}
|
|
34398
|
+
}
|
|
34399
|
+
function errorDetail(err, depth) {
|
|
34400
|
+
const message2 = readProperty(err, "message");
|
|
34401
|
+
const stack = readProperty(err, "stack");
|
|
34402
|
+
const cause = readProperty(err, "cause");
|
|
34403
|
+
return {
|
|
34404
|
+
...typeof message2 === "string" ? { message: message2 } : typeof err === "string" ? { message: err } : {},
|
|
34405
|
+
...typeof stack === "string" ? { stack } : {},
|
|
34406
|
+
...cause !== void 0 && depth < 5 ? { cause: errorDetail(cause, depth + 1) } : {}
|
|
34407
|
+
};
|
|
34408
|
+
}
|
|
34409
|
+
function readProperty(value, key) {
|
|
34410
|
+
try {
|
|
34411
|
+
return value !== null && (typeof value === "object" || typeof value === "function") ? value[key] : void 0;
|
|
34412
|
+
} catch {
|
|
34413
|
+
return void 0;
|
|
34414
|
+
}
|
|
34415
|
+
}
|
|
34416
|
+
function localVersion() {
|
|
34417
|
+
for (const parent of ["..", "../.."]) {
|
|
34418
|
+
try {
|
|
34419
|
+
const manifest = JSON.parse(readFileSync10(join11(import.meta.dirname, parent, "package.json"), "utf8"));
|
|
34420
|
+
if (manifest.name === "@dvmkit/dvm-cli") return manifest.version;
|
|
34421
|
+
} catch {
|
|
34422
|
+
}
|
|
34423
|
+
}
|
|
34424
|
+
return void 0;
|
|
34425
|
+
}
|
|
34426
|
+
|
|
34232
34427
|
// src/lib/error-handler.ts
|
|
34233
34428
|
async function catchErrors(fn, human, jsonFields) {
|
|
34234
34429
|
const lifetimeHold = setInterval(() => void 0, 60 * 60 * 1e3);
|
|
@@ -34282,9 +34477,13 @@ function handleError(err, human, jsonFields) {
|
|
|
34282
34477
|
process.exit(1);
|
|
34283
34478
|
}
|
|
34284
34479
|
const diagnostic = unknownErrorDiagnostic(err);
|
|
34285
|
-
const
|
|
34480
|
+
const site = unknownErrorSite(err);
|
|
34481
|
+
const log = appendInternalErrorLog(err, diagnostic);
|
|
34482
|
+
const label = site.length ? `${diagnostic.label} at ${site.join(" < ")}` : diagnostic.label;
|
|
34483
|
+
const message2 = `An unexpected internal error occurred (${label}).`;
|
|
34286
34484
|
if (human) {
|
|
34287
34485
|
info(`Error: ${message2}`);
|
|
34486
|
+
if (log) info(`Details saved to ${log}`);
|
|
34288
34487
|
} else {
|
|
34289
34488
|
json({
|
|
34290
34489
|
...jsonFields,
|
|
@@ -34292,6 +34491,8 @@ function handleError(err, human, jsonFields) {
|
|
|
34292
34491
|
code: "internal",
|
|
34293
34492
|
message: message2,
|
|
34294
34493
|
error_name: diagnostic.name,
|
|
34494
|
+
...site.length ? { error_site: site } : {},
|
|
34495
|
+
...log ? { error_log: log } : {},
|
|
34295
34496
|
...diagnostic.code ? { error_code: diagnostic.code } : {}
|
|
34296
34497
|
},
|
|
34297
34498
|
...takeCreditNoticeFields(),
|
|
@@ -34305,6 +34506,7 @@ function unknownErrorDiagnostic(err) {
|
|
|
34305
34506
|
const code = unknownErrorCode(err);
|
|
34306
34507
|
return { name, ...code ? { code } : {}, label: code ? `${name}:${code}` : name };
|
|
34307
34508
|
}
|
|
34509
|
+
var CLI_PACKAGE_ROOT = findCliPackageRoot();
|
|
34308
34510
|
var ERROR_NAME_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]{0,63}$/;
|
|
34309
34511
|
function unknownErrorName(err) {
|
|
34310
34512
|
if (!(err instanceof Error)) return `thrown_${typeof err}`;
|
|
@@ -34328,6 +34530,46 @@ function unknownErrorCode(err) {
|
|
|
34328
34530
|
return void 0;
|
|
34329
34531
|
}
|
|
34330
34532
|
}
|
|
34533
|
+
function unknownErrorSite(err) {
|
|
34534
|
+
try {
|
|
34535
|
+
if (!CLI_PACKAGE_ROOT || !(err instanceof Error) || typeof err.stack !== "string" || typeof err.message !== "string") return [];
|
|
34536
|
+
const lines = err.stack.split("\n");
|
|
34537
|
+
const headerLines = err.message.split("\n").length;
|
|
34538
|
+
if (!lines.slice(0, headerLines).join("\n").endsWith(err.message)) return [];
|
|
34539
|
+
const names = [];
|
|
34540
|
+
for (const frame of lines.slice(headerLines)) {
|
|
34541
|
+
if (frame.includes("node:")) continue;
|
|
34542
|
+
const match = /^\s+at (?:async )?([^()]+) \((.*):\d+:\d+\)$/.exec(frame);
|
|
34543
|
+
if (!match) continue;
|
|
34544
|
+
const name = match[1].replace(/^new /, "").replace(/ \[as [^\]]+\]$/, "");
|
|
34545
|
+
const segments = name.split(".");
|
|
34546
|
+
if (name.length > 128 || !segments.every((segment) => ERROR_NAME_PATTERN.test(segment) && !/^(?:[a-f0-9]{64}|nsec1[a-z0-9]{58})$/i.test(segment))) continue;
|
|
34547
|
+
let location = match[2];
|
|
34548
|
+
if (location.startsWith("file:")) location = fileURLToPath3(location);
|
|
34549
|
+
if (!isAbsolute2(location)) continue;
|
|
34550
|
+
const fromPackage = relative2(CLI_PACKAGE_ROOT, location);
|
|
34551
|
+
if (isAbsolute2(fromPackage) || fromPackage === ".." || fromPackage.startsWith(".." + sep3)) continue;
|
|
34552
|
+
names.push(name);
|
|
34553
|
+
if (names.length === 5) break;
|
|
34554
|
+
}
|
|
34555
|
+
return names;
|
|
34556
|
+
} catch {
|
|
34557
|
+
return [];
|
|
34558
|
+
}
|
|
34559
|
+
}
|
|
34560
|
+
function findCliPackageRoot() {
|
|
34561
|
+
let dir = import.meta.dirname;
|
|
34562
|
+
for (; ; ) {
|
|
34563
|
+
try {
|
|
34564
|
+
const manifest = JSON.parse(readFileSync11(join12(dir, "package.json"), "utf8"));
|
|
34565
|
+
if (manifest.name === "@dvmkit/dvm-cli") return dir;
|
|
34566
|
+
} catch {
|
|
34567
|
+
}
|
|
34568
|
+
const parent = dirname4(dir);
|
|
34569
|
+
if (parent === dir) return void 0;
|
|
34570
|
+
dir = parent;
|
|
34571
|
+
}
|
|
34572
|
+
}
|
|
34331
34573
|
|
|
34332
34574
|
// src/lib/wallet-agent/mint-failure-observer.ts
|
|
34333
34575
|
var MintFailureLog = class {
|
|
@@ -35296,6 +35538,7 @@ async function walletShow(opts) {
|
|
|
35296
35538
|
for (const spend of recentSpends) {
|
|
35297
35539
|
info(` ${formatRecentSpend(spend)}`);
|
|
35298
35540
|
}
|
|
35541
|
+
if (recentSpends.some((spend) => spend.fee_sats)) info(MINT_FEE_EXPLAINER);
|
|
35299
35542
|
}
|
|
35300
35543
|
} else {
|
|
35301
35544
|
const totalUsd = railsSnapshot.reduce((sum, r) => sum + (r.json.balance_usd ?? 0), 0);
|
|
@@ -35681,7 +35924,8 @@ function reportUncheckedMints(unchecked) {
|
|
|
35681
35924
|
function formatRecentSpend(spend) {
|
|
35682
35925
|
const when = new Date(spend.signed_at_ms).toISOString();
|
|
35683
35926
|
const reqShort = `${spend.request_id.slice(0, 8)}\u2026${spend.request_id.slice(-4)}`;
|
|
35684
|
-
|
|
35927
|
+
const fee = spend.fee_sats !== void 0 && spend.fee_sats > 0 ? ` + ${spend.fee_sats} sats mint fee` : "";
|
|
35928
|
+
return `${when} ${spend.amount_sats} sats${fee} ${spend.dvm_endpoint} (req ${reqShort})`;
|
|
35685
35929
|
}
|
|
35686
35930
|
function formatMintSourceTag(source) {
|
|
35687
35931
|
switch (source) {
|
|
@@ -35803,14 +36047,14 @@ import { randomUUID as randomUUID5 } from "crypto";
|
|
|
35803
36047
|
// src/lib/wallet-agent/release-intents.ts
|
|
35804
36048
|
var import_proper_lockfile3 = __toESM(require_proper_lockfile(), 1);
|
|
35805
36049
|
import { createHash as createHash6 } from "crypto";
|
|
35806
|
-
import { dirname as
|
|
36050
|
+
import { dirname as dirname5, join as join13 } from "path";
|
|
35807
36051
|
var intents = journalFile("release-intents.json");
|
|
35808
36052
|
async function withReleaseLock(walletPubkey, builderHandle, mint, operation) {
|
|
35809
36053
|
ensureConfigDir();
|
|
35810
36054
|
const key = createHash6("sha256").update(JSON.stringify([walletPubkey, builderHandle, mint])).digest("hex");
|
|
35811
36055
|
let unlock;
|
|
35812
36056
|
try {
|
|
35813
|
-
unlock = await import_proper_lockfile3.default.lock(
|
|
36057
|
+
unlock = await import_proper_lockfile3.default.lock(join13(dirname5(JOBS_FILE), `release-${key}`), {
|
|
35814
36058
|
realpath: false,
|
|
35815
36059
|
stale: 2 * 6e4,
|
|
35816
36060
|
retries: 0
|
|
@@ -36786,8 +37030,129 @@ function assertInvoiceNotPending(wallet, invoice) {
|
|
|
36786
37030
|
}
|
|
36787
37031
|
}
|
|
36788
37032
|
|
|
37033
|
+
// src/lib/wallet-agent/melt-quotes.ts
|
|
37034
|
+
var quotes = journalFile("melt-quotes.json");
|
|
37035
|
+
var UNDATED_QUOTE_TTL_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
37036
|
+
function normalise(bolt11) {
|
|
37037
|
+
return invoiceDestination(bolt11) ?? bolt11.toLowerCase();
|
|
37038
|
+
}
|
|
37039
|
+
function isStale(entry, nowMs) {
|
|
37040
|
+
if (typeof entry.expires_at === "number") return entry.expires_at * 1e3 <= nowMs;
|
|
37041
|
+
const created = Date.parse(entry.created_at);
|
|
37042
|
+
return !Number.isFinite(created) || created + UNDATED_QUOTE_TTL_MS <= nowMs;
|
|
37043
|
+
}
|
|
37044
|
+
function isEntry(value) {
|
|
37045
|
+
if (typeof value !== "object" || value === null) return false;
|
|
37046
|
+
const entry = value;
|
|
37047
|
+
return typeof entry.mint === "string" && typeof entry.quote_id === "string" && entry.quote_id.length > 0 && typeof entry.bolt11 === "string" && typeof entry.created_at === "string";
|
|
37048
|
+
}
|
|
37049
|
+
function storedMeltQuote(mint, bolt11, nowMs) {
|
|
37050
|
+
const invoice = normalise(bolt11);
|
|
37051
|
+
return quotes.read().filter(isEntry).find((entry) => entry.mint === mint && entry.bolt11 === invoice && !isStale(entry, nowMs));
|
|
37052
|
+
}
|
|
37053
|
+
function rememberMeltQuote(entry, nowMs) {
|
|
37054
|
+
const invoice = normalise(entry.bolt11);
|
|
37055
|
+
quotes.withLock(() => {
|
|
37056
|
+
const kept = quotes.read().filter(isEntry).filter((held) => !isStale(held, nowMs) && !(held.mint === entry.mint && held.bolt11 === invoice));
|
|
37057
|
+
quotes.write([...kept, { ...entry, bolt11: invoice, created_at: new Date(nowMs).toISOString() }]);
|
|
37058
|
+
});
|
|
37059
|
+
}
|
|
37060
|
+
function forgetMeltQuote(mint, bolt11, quoteId) {
|
|
37061
|
+
const invoice = normalise(bolt11);
|
|
37062
|
+
const matches = (held) => held.mint === mint && held.bolt11 === invoice && (quoteId === void 0 || held.quote_id === quoteId);
|
|
37063
|
+
if (!quotes.read().filter(isEntry).some(matches)) return;
|
|
37064
|
+
quotes.withLock(() => quotes.write(quotes.read().filter(isEntry).filter((held) => !matches(held))));
|
|
37065
|
+
}
|
|
37066
|
+
|
|
36789
37067
|
// src/lib/wallet-agent/cash-out-invoice.ts
|
|
36790
|
-
|
|
37068
|
+
function isDuplicateQuoteRefusal(err) {
|
|
37069
|
+
return /already has a (melt )?quote/i.test(err instanceof Error ? err.message : String(err));
|
|
37070
|
+
}
|
|
37071
|
+
function isMintRejection(err) {
|
|
37072
|
+
if (err instanceof te) return true;
|
|
37073
|
+
return err instanceof x && err.status >= 400 && err.status < 500 && err.status !== 408 && err.status !== 429;
|
|
37074
|
+
}
|
|
37075
|
+
async function resolveInvoiceQuote(mint, invoice, nowMs, cashuWallet) {
|
|
37076
|
+
const held = storedMeltQuote(mint, invoice, nowMs);
|
|
37077
|
+
if (held) {
|
|
37078
|
+
let current;
|
|
37079
|
+
try {
|
|
37080
|
+
current = await cashuWallet.checkMeltQuoteBolt11(held.quote_id);
|
|
37081
|
+
} catch (err) {
|
|
37082
|
+
if (!isMintRejection(err)) {
|
|
37083
|
+
return {
|
|
37084
|
+
kind: "failed",
|
|
37085
|
+
mint,
|
|
37086
|
+
settlement: "reverted",
|
|
37087
|
+
reason: "quote_state_unknown",
|
|
37088
|
+
message: `Could not check this wallet's saved melt quote for the invoice at ${mint}: ${err instanceof Error ? err.message : String(err)}. No money moved and the quote is still saved. Run \`dvm wallet mint-health\`, then retry \`dvm wallet cash-out <invoice>\`; do not pay this invoice from another mint until the quote's state is known.`
|
|
37089
|
+
};
|
|
37090
|
+
}
|
|
37091
|
+
forgetStored(mint, invoice, held.quote_id);
|
|
37092
|
+
current = void 0;
|
|
37093
|
+
}
|
|
37094
|
+
if (current && current.state === "PAID") {
|
|
37095
|
+
return {
|
|
37096
|
+
kind: "failed",
|
|
37097
|
+
mint,
|
|
37098
|
+
settlement: "reverted",
|
|
37099
|
+
reason: "quote_already_in_progress",
|
|
37100
|
+
message: `${mint} reports this invoice as already paid with this wallet's saved quote. No money moved in this run and nothing is left to pay; do not pay this invoice again. \`dvm wallet show\` shows the current balance.`
|
|
37101
|
+
};
|
|
37102
|
+
}
|
|
37103
|
+
if (current && current.state === "PENDING") {
|
|
37104
|
+
return {
|
|
37105
|
+
kind: "failed",
|
|
37106
|
+
mint,
|
|
37107
|
+
settlement: "reverted",
|
|
37108
|
+
reason: "quote_already_in_progress",
|
|
37109
|
+
message: `${mint} reports this invoice's melt quote as being paid. No money moved in this run. Run \`dvm wallet show\` to reconcile it; do not pay this invoice again.`
|
|
37110
|
+
};
|
|
37111
|
+
}
|
|
37112
|
+
const sameInvoice = current !== void 0 && (typeof current.request !== "string" || invoiceDestination(current.request) === invoiceDestination(invoice));
|
|
37113
|
+
const live = current !== void 0 && current.state === "UNPAID" && sameInvoice && !(typeof current.expiry === "number" && current.expiry * 1e3 <= nowMs);
|
|
37114
|
+
if (current && live) {
|
|
37115
|
+
return {
|
|
37116
|
+
amountSats: A.from(current.amount).toNumber(),
|
|
37117
|
+
feeReserveSats: A.from(current.fee_reserve).toNumber(),
|
|
37118
|
+
rawQuote: current
|
|
37119
|
+
};
|
|
37120
|
+
}
|
|
37121
|
+
if (current) forgetStored(mint, invoice, held.quote_id);
|
|
37122
|
+
}
|
|
37123
|
+
let quote2;
|
|
37124
|
+
try {
|
|
37125
|
+
quote2 = await fetchMeltQuote(mint, invoice);
|
|
37126
|
+
} catch (err) {
|
|
37127
|
+
if (!isDuplicateQuoteRefusal(err)) throw err;
|
|
37128
|
+
return {
|
|
37129
|
+
kind: "failed",
|
|
37130
|
+
mint,
|
|
37131
|
+
settlement: "reverted",
|
|
37132
|
+
reason: "quote_already_exists",
|
|
37133
|
+
message: `${mint} already holds a melt quote for this invoice and will not issue another, and this wallet has no usable record of that quote. No money moved. Ask for a new invoice, or run \`dvm wallet cash-out <invoice> --mint <url>\` to pay this one from a different mint.`
|
|
37134
|
+
};
|
|
37135
|
+
}
|
|
37136
|
+
try {
|
|
37137
|
+
rememberMeltQuote({
|
|
37138
|
+
mint,
|
|
37139
|
+
bolt11: invoice,
|
|
37140
|
+
quote_id: quote2.rawQuote.quote,
|
|
37141
|
+
amount_sats: quote2.amountSats,
|
|
37142
|
+
fee_reserve_sats: quote2.feeReserveSats,
|
|
37143
|
+
expires_at: typeof quote2.rawQuote.expiry === "number" ? quote2.rawQuote.expiry : null
|
|
37144
|
+
}, nowMs);
|
|
37145
|
+
} catch {
|
|
37146
|
+
}
|
|
37147
|
+
return quote2;
|
|
37148
|
+
}
|
|
37149
|
+
function forgetStored(mint, invoice, quoteId) {
|
|
37150
|
+
try {
|
|
37151
|
+
forgetMeltQuote(mint, invoice, quoteId);
|
|
37152
|
+
} catch {
|
|
37153
|
+
}
|
|
37154
|
+
}
|
|
37155
|
+
async function prepareInvoice(opts, candidates, bounds, cashuWallet) {
|
|
36791
37156
|
const mint = opts.mintUrl;
|
|
36792
37157
|
const refuse = (reason, message2) => ({
|
|
36793
37158
|
kind: "skipped",
|
|
@@ -36798,7 +37163,8 @@ async function prepareInvoice(opts, candidates, bounds) {
|
|
|
36798
37163
|
const invoice = opts.bolt11;
|
|
36799
37164
|
const amount = invoiceAmountSats(invoice, (opts.now ?? Date.now)());
|
|
36800
37165
|
try {
|
|
36801
|
-
const quote2 = await
|
|
37166
|
+
const quote2 = await resolveInvoiceQuote(mint, invoice, (opts.now ?? Date.now)(), cashuWallet);
|
|
37167
|
+
if ("kind" in quote2) return quote2;
|
|
36802
37168
|
if (quote2.amountSats !== amount) {
|
|
36803
37169
|
return refuse("quote_amount_mismatch", `The mint quoted ${quote2.amountSats} sats for a ${amount} sat invoice.`);
|
|
36804
37170
|
}
|
|
@@ -36849,7 +37215,7 @@ async function prepareInvoice(opts, candidates, bounds) {
|
|
|
36849
37215
|
async function prepareCashOut(opts, candidates, cashuWallet) {
|
|
36850
37216
|
const mintUrl = opts.mintUrl;
|
|
36851
37217
|
const fetchInvoice = opts.fetchInvoice ?? fetchLnurlPayInvoice;
|
|
36852
|
-
if (opts.bolt11 !== void 0) return prepareInvoice(opts, candidates, meltBoundsOf(cashuWallet));
|
|
37218
|
+
if (opts.bolt11 !== void 0) return prepareInvoice(opts, candidates, meltBoundsOf(cashuWallet), cashuWallet);
|
|
36853
37219
|
const meltBounds = meltBoundsOf(cashuWallet);
|
|
36854
37220
|
let target = opts.target;
|
|
36855
37221
|
let cappedByMintMax;
|
|
@@ -37066,7 +37432,7 @@ async function cashOutFromMint(opts) {
|
|
|
37066
37432
|
kind: "skipped",
|
|
37067
37433
|
mint: mintUrl,
|
|
37068
37434
|
reason: "fee_cap_exceeded",
|
|
37069
|
-
message: `Fees at ${mintUrl} would be up to ${totalFees} sats, over the ${opts.maxFeeSats} sat cap.${opts.bolt11 ? " No money moved.
|
|
37435
|
+
message: `Fees at ${mintUrl} would be up to ${totalFees} sats, over the ${opts.maxFeeSats} sat cap.${opts.bolt11 ? " No money moved. The quote is saved: run `dvm wallet cash-out <invoice> --max-fee <sats>` with a sufficient cap to pay with it if you accept these fees." : ""}`,
|
|
37070
37436
|
quote: quoteView
|
|
37071
37437
|
};
|
|
37072
37438
|
}
|
|
@@ -37154,6 +37520,12 @@ async function cashOutFromMint(opts) {
|
|
|
37154
37520
|
pending_melts: fresh.pending_melts.filter((m) => m.quote_id !== entry.quote_id)
|
|
37155
37521
|
});
|
|
37156
37522
|
});
|
|
37523
|
+
if (opts.bolt11) {
|
|
37524
|
+
try {
|
|
37525
|
+
forgetMeltQuote(mintUrl, opts.bolt11, entry.quote_id);
|
|
37526
|
+
} catch {
|
|
37527
|
+
}
|
|
37528
|
+
}
|
|
37157
37529
|
return {
|
|
37158
37530
|
kind: "sent",
|
|
37159
37531
|
mint: mintUrl,
|
|
@@ -37207,6 +37579,27 @@ function errorMessage3(err) {
|
|
|
37207
37579
|
return err instanceof Error ? err.message : String(err);
|
|
37208
37580
|
}
|
|
37209
37581
|
|
|
37582
|
+
// src/lib/wallet-agent/cash-out-fees.ts
|
|
37583
|
+
var LARGE_FEE_SHARE_PERCENT = 2;
|
|
37584
|
+
function feeSharePercent(feeSats, payoutSats) {
|
|
37585
|
+
if (payoutSats <= 0) return null;
|
|
37586
|
+
return Math.round(feeSats / payoutSats * 1e3) / 10;
|
|
37587
|
+
}
|
|
37588
|
+
function isLargeFeeShare(feeSats, payoutSats) {
|
|
37589
|
+
return payoutSats > 0 && feeSats * 100 > payoutSats * LARGE_FEE_SHARE_PERCENT;
|
|
37590
|
+
}
|
|
37591
|
+
function settledFeeBreakdown(quote2, changeSats) {
|
|
37592
|
+
const feeSats = quote2.debit_sats - quote2.amount_sats - changeSats;
|
|
37593
|
+
const routingFeeSats = Math.max(0, feeSats - quote2.input_fee_sats);
|
|
37594
|
+
return {
|
|
37595
|
+
feeSats,
|
|
37596
|
+
inputFeeSats: quote2.input_fee_sats,
|
|
37597
|
+
routingFeeSats,
|
|
37598
|
+
routingReserveReturnedSats: Math.max(0, quote2.fee_reserve_sats - routingFeeSats)
|
|
37599
|
+
};
|
|
37600
|
+
}
|
|
37601
|
+
var LARGE_FEE_ADVICE = "That is a large share of the payout. Run with --dry-run to see the fee before anything is paid, and pass --max-fee <sats> to refuse a mint whose fees exceed your limit.";
|
|
37602
|
+
|
|
37210
37603
|
// src/commands/wallet-cash-out.ts
|
|
37211
37604
|
async function walletCashOut(destination, opts) {
|
|
37212
37605
|
const human = opts.human ?? false;
|
|
@@ -37272,7 +37665,8 @@ async function walletCashOut(destination, opts) {
|
|
|
37272
37665
|
}
|
|
37273
37666
|
});
|
|
37274
37667
|
outcomes.push(outcome);
|
|
37275
|
-
|
|
37668
|
+
const routable = outcome.kind === "skipped" || outcome.kind === "failed" && !outcome.quote && !outcome.reason;
|
|
37669
|
+
if (bolt11 && !routable) break;
|
|
37276
37670
|
if (requested && (outcome.kind === "sent" || outcome.kind === "quoted")) {
|
|
37277
37671
|
remaining -= outcome.quote.amount_sats;
|
|
37278
37672
|
}
|
|
@@ -37282,6 +37676,19 @@ async function walletCashOut(destination, opts) {
|
|
|
37282
37676
|
0
|
|
37283
37677
|
);
|
|
37284
37678
|
const feeSats = outcomes.reduce((sum, o) => sum + (o.kind === "sent" ? netFeeSats(o) : 0), 0);
|
|
37679
|
+
const sentBreakdowns = outcomes.flatMap(
|
|
37680
|
+
(o) => o.kind === "sent" ? [settledFeeBreakdown(o.quote, o.change_sats)] : []
|
|
37681
|
+
);
|
|
37682
|
+
const inputFeeSats = sentBreakdowns.reduce((sum, b) => sum + b.inputFeeSats, 0);
|
|
37683
|
+
const routingFeeSats = sentBreakdowns.reduce((sum, b) => sum + b.routingFeeSats, 0);
|
|
37684
|
+
const routingReserveReturnedSats = sentBreakdowns.reduce(
|
|
37685
|
+
(sum, b) => sum + b.routingReserveReturnedSats,
|
|
37686
|
+
0
|
|
37687
|
+
);
|
|
37688
|
+
const quotedFeeSats = outcomes.reduce(
|
|
37689
|
+
(sum, o) => sum + (o.kind === "quoted" ? quotedFeeCeiling(o.quote) : 0),
|
|
37690
|
+
0
|
|
37691
|
+
);
|
|
37285
37692
|
const changeSats = outcomes.reduce((sum, o) => sum + (o.kind === "sent" ? o.change_sats : 0), 0);
|
|
37286
37693
|
const quotedSats = outcomes.reduce(
|
|
37287
37694
|
(sum, o) => sum + (o.kind === "quoted" ? o.quote.amount_sats : 0),
|
|
@@ -37292,13 +37699,21 @@ async function walletCashOut(destination, opts) {
|
|
|
37292
37699
|
const moreToSend = opts.all === true || shortfall > 0;
|
|
37293
37700
|
const rows = outcomes.map((o) => toRow(o, moreToSend));
|
|
37294
37701
|
const status2 = opts.dryRun ? "quoted" : sentSats > 0 ? "cashed_out" : "nothing_sent";
|
|
37295
|
-
const
|
|
37702
|
+
const headlineFeeSats = opts.dryRun ? quotedFeeSats : feeSats;
|
|
37703
|
+
const headlinePayoutSats = opts.dryRun ? quotedSats : sentSats;
|
|
37704
|
+
const feeSharePct = feeSharePercent(headlineFeeSats, headlinePayoutSats);
|
|
37705
|
+
const feeWarning = rows.some((r) => r.fee_warning) || isLargeFeeShare(headlineFeeSats, headlinePayoutSats);
|
|
37706
|
+
const anyInputFee = rows.some((r) => (r.input_fee_sats ?? 0) > 0);
|
|
37707
|
+
const display = opts.dryRun ? `Quoted ${quotedSats} sats to ${destination}${bolt11 ? " from one mint" : ` across ${rows.length} mint(s)`}${quotedFeeSats > 0 ? `, with fees of up to ${feeAmount(quotedFeeSats)}${shareClause(feeSharePct)}` : ""}. Nothing was paid.${feeWarning ? ` ${LARGE_FEE_ADVICE}` : ""}${anyInputFee ? ` ${MINT_FEE_EXPLAINER}` : ""}` : sentSats > 0 ? `Sent ${sentSats} sats to ${destination}${feeSats > 0 ? `, plus ${feeAmount(feeSats)} in fees (${inputFeeSats} mint input fee + ${routingFeeSats} routing${shareClause(feeSharePct, true)}${routingReserveReturnedSats > 0 ? `; ${routingReserveReturnedSats} sats of unused routing reserve came back` : ""})` : ""}${shortfall > 0 ? ` \u2014 ${shortfall} sats short of what you asked for` : ""}.${feeSats > 0 && inputFeeSats > 0 ? ` ${MINT_FEE_EXPLAINER}` : ""}` : `Nothing was sent to ${destination}.`;
|
|
37296
37708
|
const cappedCount = moreToSend ? rows.filter((r) => r.mint_max_sats !== void 0).length : 0;
|
|
37709
|
+
const savedQuote = bolt11 ? outcomes.find((o) => o.kind === "quoted")?.quote : void 0;
|
|
37297
37710
|
const hint = buildHint({
|
|
37298
37711
|
unresolvedCount: unresolved.length,
|
|
37299
37712
|
shortfall,
|
|
37300
37713
|
cappedCount,
|
|
37301
|
-
dryRun: opts.dryRun
|
|
37714
|
+
dryRun: opts.dryRun,
|
|
37715
|
+
savedQuote,
|
|
37716
|
+
invoiceOutcomes: bolt11 ? outcomes : void 0
|
|
37302
37717
|
});
|
|
37303
37718
|
if (human) {
|
|
37304
37719
|
info("");
|
|
@@ -37316,6 +37731,12 @@ async function walletCashOut(destination, opts) {
|
|
|
37316
37731
|
requested_sats: requested?.sats ?? invoiceSats ?? null,
|
|
37317
37732
|
sats_sent: sentSats,
|
|
37318
37733
|
fee_sats: feeSats,
|
|
37734
|
+
input_fee_sats: inputFeeSats,
|
|
37735
|
+
routing_fee_sats: routingFeeSats,
|
|
37736
|
+
routing_reserve_returned_sats: routingReserveReturnedSats,
|
|
37737
|
+
quoted_fee_sats: quotedFeeSats,
|
|
37738
|
+
fee_share_pct: feeSharePct,
|
|
37739
|
+
fee_warning: feeWarning,
|
|
37319
37740
|
change_sats: changeSats,
|
|
37320
37741
|
shortfall_sats: shortfall,
|
|
37321
37742
|
mints: rows,
|
|
@@ -37331,6 +37752,16 @@ async function walletCashOut(destination, opts) {
|
|
|
37331
37752
|
);
|
|
37332
37753
|
}
|
|
37333
37754
|
}
|
|
37755
|
+
function quotedFeeCeiling(quote2) {
|
|
37756
|
+
return quote2.fee_reserve_sats + quote2.input_fee_sats;
|
|
37757
|
+
}
|
|
37758
|
+
function shareClause(share, inline = false) {
|
|
37759
|
+
if (share === null) return "";
|
|
37760
|
+
return inline ? `, about ${share}% of the payout` : ` (about ${share}% of the payout)`;
|
|
37761
|
+
}
|
|
37762
|
+
function feeAmount(sats) {
|
|
37763
|
+
return formatAmountBestEffort(sats * 1e3, { anchor: false });
|
|
37764
|
+
}
|
|
37334
37765
|
function netFeeSats(outcome) {
|
|
37335
37766
|
return outcome.quote.debit_sats - outcome.quote.amount_sats - outcome.change_sats;
|
|
37336
37767
|
}
|
|
@@ -37348,13 +37779,25 @@ function toRow(outcome, moreToSend) {
|
|
|
37348
37779
|
input_fee_sats: null,
|
|
37349
37780
|
debit_sats: null,
|
|
37350
37781
|
change_sats: null,
|
|
37782
|
+
fee_sats: null,
|
|
37783
|
+
routing_fee_sats: null,
|
|
37784
|
+
routing_reserve_returned_sats: null,
|
|
37785
|
+
fee_share_pct: null,
|
|
37786
|
+
fee_warning: false,
|
|
37351
37787
|
preimage: null,
|
|
37352
37788
|
error: null
|
|
37353
37789
|
};
|
|
37354
37790
|
switch (outcome.kind) {
|
|
37355
|
-
case "sent":
|
|
37791
|
+
case "sent": {
|
|
37792
|
+
const breakdown = settledFeeBreakdown(outcome.quote, outcome.change_sats);
|
|
37793
|
+
const share = feeSharePercent(breakdown.feeSats, outcome.quote.amount_sats);
|
|
37356
37794
|
return {
|
|
37357
37795
|
...base,
|
|
37796
|
+
fee_sats: breakdown.feeSats,
|
|
37797
|
+
routing_fee_sats: breakdown.routingFeeSats,
|
|
37798
|
+
routing_reserve_returned_sats: breakdown.routingReserveReturnedSats,
|
|
37799
|
+
fee_share_pct: share,
|
|
37800
|
+
fee_warning: isLargeFeeShare(breakdown.feeSats, outcome.quote.amount_sats),
|
|
37358
37801
|
sats_sent: outcome.quote.amount_sats,
|
|
37359
37802
|
fee_reserve_sats: outcome.quote.fee_reserve_sats,
|
|
37360
37803
|
input_fee_sats: outcome.quote.input_fee_sats,
|
|
@@ -37362,11 +37805,18 @@ function toRow(outcome, moreToSend) {
|
|
|
37362
37805
|
change_sats: outcome.change_sats,
|
|
37363
37806
|
preimage: outcome.preimage,
|
|
37364
37807
|
...outcome.mint_max_sats !== void 0 ? { mint_max_sats: outcome.mint_max_sats } : {},
|
|
37365
|
-
display: `${outcome.mint}: sent ${outcome.quote.amount_sats} sats
|
|
37808
|
+
display: `${outcome.mint}: sent ${outcome.quote.amount_sats} sats. Fees ${breakdown.feeSats} sats${shareClause(share, true)}: ${breakdown.inputFeeSats} mint input fee + ${breakdown.routingFeeSats} routing${breakdown.routingReserveReturnedSats > 0 ? `; ${breakdown.routingReserveReturnedSats} sats of unused routing reserve came back` : ""}.${capNote(outcome.mint_max_sats, moreToSend)}`
|
|
37366
37809
|
};
|
|
37367
|
-
|
|
37810
|
+
}
|
|
37811
|
+
case "quoted": {
|
|
37812
|
+
const ceiling = quotedFeeCeiling(outcome.quote);
|
|
37813
|
+
const share = feeSharePercent(ceiling, outcome.quote.amount_sats);
|
|
37814
|
+
const large = isLargeFeeShare(ceiling, outcome.quote.amount_sats);
|
|
37368
37815
|
return {
|
|
37369
37816
|
...base,
|
|
37817
|
+
fee_sats: ceiling,
|
|
37818
|
+
fee_share_pct: share,
|
|
37819
|
+
fee_warning: large,
|
|
37370
37820
|
fee_reserve_sats: outcome.quote.fee_reserve_sats,
|
|
37371
37821
|
input_fee_sats: outcome.quote.input_fee_sats,
|
|
37372
37822
|
debit_sats: outcome.quote.debit_sats,
|
|
@@ -37374,8 +37824,9 @@ function toRow(outcome, moreToSend) {
|
|
|
37374
37824
|
// A dry run sent nothing, so "run it again" would be the wrong advice
|
|
37375
37825
|
// whatever the mode — the cap is reported as fact and the summary hint
|
|
37376
37826
|
// already says to re-run without --dry-run.
|
|
37377
|
-
display: `${outcome.mint}: would send ${outcome.quote.amount_sats} sats for up to ${outcome.quote.fee_reserve_sats + outcome.quote.input_fee_sats}
|
|
37827
|
+
display: `${outcome.mint}: would send ${outcome.quote.amount_sats} sats for up to ${ceiling} sats in fees (${outcome.quote.fee_reserve_sats} routing reserve + ${outcome.quote.input_fee_sats} mint input fee${shareClause(share, true)}).${large ? ` ${LARGE_FEE_ADVICE}` : ""}${capNote(outcome.mint_max_sats, false)}`
|
|
37378
37828
|
};
|
|
37829
|
+
}
|
|
37379
37830
|
case "skipped":
|
|
37380
37831
|
return {
|
|
37381
37832
|
...base,
|
|
@@ -37388,14 +37839,17 @@ function toRow(outcome, moreToSend) {
|
|
|
37388
37839
|
return {
|
|
37389
37840
|
...base,
|
|
37390
37841
|
settlement: outcome.settlement,
|
|
37842
|
+
...outcome.reason !== void 0 ? { reason: outcome.reason } : {},
|
|
37391
37843
|
error: outcome.message,
|
|
37392
37844
|
display: `${outcome.mint}: failed \u2014 ${outcome.message}`
|
|
37393
37845
|
};
|
|
37394
37846
|
}
|
|
37395
37847
|
}
|
|
37396
37848
|
function emitQuote(quote2, destination, human) {
|
|
37397
|
-
const fees = quote2
|
|
37398
|
-
const
|
|
37849
|
+
const fees = quotedFeeCeiling(quote2);
|
|
37850
|
+
const share = feeSharePercent(fees, quote2.amount_sats);
|
|
37851
|
+
const large = isLargeFeeShare(fees, quote2.amount_sats);
|
|
37852
|
+
const display = `${quote2.mint}: sending ${quote2.amount_sats} sats to ${destination} costs up to ${fees} sats in fees (${quote2.fee_reserve_sats} routing reserve + ${quote2.input_fee_sats} mint input fee${shareClause(share, true)}), debiting up to ${quote2.debit_sats} sats. Unused routing reserve comes back.${large ? ` ${LARGE_FEE_ADVICE}` : ""}`;
|
|
37399
37853
|
if (human) {
|
|
37400
37854
|
info(display);
|
|
37401
37855
|
} else {
|
|
@@ -37407,6 +37861,9 @@ function emitQuote(quote2, destination, human) {
|
|
|
37407
37861
|
amount_sats: quote2.amount_sats,
|
|
37408
37862
|
fee_reserve_sats: quote2.fee_reserve_sats,
|
|
37409
37863
|
input_fee_sats: quote2.input_fee_sats,
|
|
37864
|
+
fee_sats: fees,
|
|
37865
|
+
fee_share_pct: share,
|
|
37866
|
+
fee_warning: large,
|
|
37410
37867
|
debit_sats: quote2.debit_sats,
|
|
37411
37868
|
expires_at: quote2.expires_at,
|
|
37412
37869
|
display
|
|
@@ -37425,6 +37882,11 @@ function buildHint(args) {
|
|
|
37425
37882
|
return "At least one melt's outcome is unknown \u2014 those sats stay committed until `dvm wallet show` reconciles them against the mint. Don't retry that mint until it does.";
|
|
37426
37883
|
}
|
|
37427
37884
|
if (args.dryRun) {
|
|
37885
|
+
if (args.savedQuote) {
|
|
37886
|
+
const until = args.savedQuote.expires_at !== null ? ` until it expires at ${new Date(args.savedQuote.expires_at * 1e3).toISOString()}` : " while the mint still holds it unpaid";
|
|
37887
|
+
return `Re-run without --dry-run to send. This quote is saved and the real run pays with it${until}, at the fees shown.`;
|
|
37888
|
+
}
|
|
37889
|
+
if (args.invoiceOutcomes) return unquotedInvoiceHint(args.invoiceOutcomes);
|
|
37428
37890
|
return "Re-run without --dry-run to send. Quotes expire, so the fee is re-quoted at that point.";
|
|
37429
37891
|
}
|
|
37430
37892
|
if (args.cappedCount > 0) {
|
|
@@ -37435,6 +37897,22 @@ function buildHint(args) {
|
|
|
37435
37897
|
}
|
|
37436
37898
|
return "Confirm the remaining balance with `dvm wallet show`.";
|
|
37437
37899
|
}
|
|
37900
|
+
function unquotedInvoiceHint(outcomes) {
|
|
37901
|
+
const reason = outcomes.find((o) => o.kind === "failed" && o.reason !== void 0);
|
|
37902
|
+
if (reason?.kind === "failed" && reason.reason === "quote_already_in_progress") {
|
|
37903
|
+
return "Do not re-run to send: the mint reports this invoice's quote as paid or being paid. `dvm wallet show` reconciles any payment still in flight.";
|
|
37904
|
+
}
|
|
37905
|
+
if (reason?.kind === "failed" && reason.reason === "quote_already_exists") {
|
|
37906
|
+
return "Re-running will not send this invoice from that mint: it will not issue another quote. Ask for a new invoice, or pass --mint to pay from a different mint.";
|
|
37907
|
+
}
|
|
37908
|
+
if (reason?.kind === "failed" && reason.reason === "quote_state_unknown") {
|
|
37909
|
+
return "Nothing was quoted because the saved quote could not be checked. It is still saved: retry once `dvm wallet mint-health` shows the mint reachable.";
|
|
37910
|
+
}
|
|
37911
|
+
if (outcomes.some((o) => o.kind === "skipped" && o.reason === "fee_cap_exceeded")) {
|
|
37912
|
+
return "Nothing would be sent at this fee cap. The quote is saved, so a re-run meets the same fees: raise --max-fee to accept them.";
|
|
37913
|
+
}
|
|
37914
|
+
return "Nothing would be sent: see the per-mint reasons above.";
|
|
37915
|
+
}
|
|
37438
37916
|
function parseMaxFee(raw2) {
|
|
37439
37917
|
if (raw2 === void 0) return void 0;
|
|
37440
37918
|
const n = Number(raw2);
|
|
@@ -38699,15 +39177,15 @@ function hexToBytes2(hex2) {
|
|
|
38699
39177
|
// src/lib/wallet-pairing-store.ts
|
|
38700
39178
|
var import_proper_lockfile4 = __toESM(require_proper_lockfile(), 1);
|
|
38701
39179
|
import {
|
|
38702
|
-
chmodSync as
|
|
39180
|
+
chmodSync as chmodSync3,
|
|
38703
39181
|
existsSync as existsSync9,
|
|
38704
39182
|
readdirSync as readdirSync5,
|
|
38705
|
-
readFileSync as
|
|
38706
|
-
renameSync as
|
|
39183
|
+
readFileSync as readFileSync12,
|
|
39184
|
+
renameSync as renameSync6,
|
|
38707
39185
|
unlinkSync as unlinkSync4,
|
|
38708
39186
|
writeFileSync as writeFileSync7
|
|
38709
39187
|
} from "fs";
|
|
38710
|
-
import { join as
|
|
39188
|
+
import { join as join14 } from "path";
|
|
38711
39189
|
var pairingIdPattern = /^[0-9a-f]{64}$/;
|
|
38712
39190
|
var stateSchema = external_exports.object({
|
|
38713
39191
|
version: external_exports.literal(1),
|
|
@@ -38730,7 +39208,7 @@ function createWalletPairingState(state) {
|
|
|
38730
39208
|
ensurePairingsDirectory();
|
|
38731
39209
|
const path = pairingPath(state.pairing_id);
|
|
38732
39210
|
writeFileSync7(path, JSON.stringify(state, null, 2) + "\n", { mode: 384, flag: "wx" });
|
|
38733
|
-
|
|
39211
|
+
chmodSync3(path, 384);
|
|
38734
39212
|
}
|
|
38735
39213
|
function loadWalletPairingState(pairingId) {
|
|
38736
39214
|
const path = pairingPath(pairingId);
|
|
@@ -38742,7 +39220,7 @@ function loadWalletPairingState(pairingId) {
|
|
|
38742
39220
|
);
|
|
38743
39221
|
}
|
|
38744
39222
|
try {
|
|
38745
|
-
return stateSchema.parse(JSON.parse(
|
|
39223
|
+
return stateSchema.parse(JSON.parse(readFileSync12(path, "utf8")));
|
|
38746
39224
|
} catch {
|
|
38747
39225
|
throw new DvmError(
|
|
38748
39226
|
"wallet_pairing_state_invalid",
|
|
@@ -38758,8 +39236,8 @@ function saveWalletPairingState(state) {
|
|
|
38758
39236
|
const tmp = `${path}.tmp`;
|
|
38759
39237
|
writeFileSync7(tmp, JSON.stringify(state, null, 2) + "\n", { mode: 384 });
|
|
38760
39238
|
try {
|
|
38761
|
-
|
|
38762
|
-
|
|
39239
|
+
renameSync6(tmp, path);
|
|
39240
|
+
chmodSync3(path, 384);
|
|
38763
39241
|
} catch (err) {
|
|
38764
39242
|
try {
|
|
38765
39243
|
unlinkSync4(tmp);
|
|
@@ -38781,9 +39259,9 @@ function cleanupExpiredWalletPairingStates(nowSeconds = Math.floor(Date.now() /
|
|
|
38781
39259
|
let removed = 0;
|
|
38782
39260
|
for (const name of readdirSync5(PAIRINGS_DIR)) {
|
|
38783
39261
|
if (!/^[0-9a-f]{64}\.json$/.test(name)) continue;
|
|
38784
|
-
const path =
|
|
39262
|
+
const path = join14(PAIRINGS_DIR, name);
|
|
38785
39263
|
try {
|
|
38786
|
-
const state = stateSchema.parse(JSON.parse(
|
|
39264
|
+
const state = stateSchema.parse(JSON.parse(readFileSync12(path, "utf8")));
|
|
38787
39265
|
if (state.manifest.expires_at <= nowSeconds) {
|
|
38788
39266
|
unlinkSync4(path);
|
|
38789
39267
|
removed += 1;
|
|
@@ -38825,11 +39303,11 @@ function pairingPath(pairingId) {
|
|
|
38825
39303
|
"Wallet pairing id must be 64 lowercase hexadecimal characters."
|
|
38826
39304
|
);
|
|
38827
39305
|
}
|
|
38828
|
-
return
|
|
39306
|
+
return join14(PAIRINGS_DIR, `${pairingId}.json`);
|
|
38829
39307
|
}
|
|
38830
39308
|
function ensurePairingsDirectory() {
|
|
38831
39309
|
ensureConfigSubdir(PAIRINGS_DIR);
|
|
38832
|
-
|
|
39310
|
+
chmodSync3(PAIRINGS_DIR, 448);
|
|
38833
39311
|
}
|
|
38834
39312
|
|
|
38835
39313
|
// src/commands/wallet-pair.ts
|
|
@@ -40743,7 +41221,7 @@ function buildProgram() {
|
|
|
40743
41221
|
).option(
|
|
40744
41222
|
"--over-trust",
|
|
40745
41223
|
"Fund past the trust-tier cap deliberately \u2014 required for an amount above what receipts here have earned, on every rail except card (stripe), which the cap never applies to"
|
|
40746
|
-
).option("--rail <rail>", `Force a funding rail: ${creditFundRails}`).option("--cashu-mint <mint>", "Pin Cashu funding to one DVM-accepted mint").option(
|
|
41224
|
+
).option("--rail <rail>", `Force a funding rail: ${creditFundRails}`).option("--invoice", "Print a Lightning funding invoice for payment from any wallet; implies --rail lightning").option("--cashu-mint <mint>", "Pin Cashu funding to one DVM-accepted mint").option(
|
|
40747
41225
|
"--max-cashu-principal-sats <sats>",
|
|
40748
41226
|
"Refuse Cashu funding above this token-principal ceiling"
|
|
40749
41227
|
).option("--max-cashu-fee-sats <sats>", "Refuse Cashu funding above this swap-fee ceiling").option(
|
|
@@ -40752,7 +41230,7 @@ function buildProgram() {
|
|
|
40752
41230
|
).option(
|
|
40753
41231
|
"--spt <token>",
|
|
40754
41232
|
"Pay by card: the shared payment token (spt_\u2026) your human approved in Stripe Link, or '-' to read it from stdin. Implies --rail stripe; without it, --rail stripe offers a card checkout link when supported, otherwise the link-cli approval steps"
|
|
40755
|
-
).option("--no-wait", "Print the card checkout link and exit; re-run to resume and confirm payment").option("--credit-id <id>", "Fund a specific credit id instead of the tracked one").option("--as <name>", "Caller signing identity to sign the funding as").option("--human", "Human-readable output instead of JSON").action((dvm, opts) => {
|
|
41233
|
+
).option("--no-wait", "Print the card checkout link or Lightning --invoice and exit; re-run to resume and confirm payment").option("--credit-id <id>", "Fund a specific credit id instead of the tracked one").option("--as <name>", "Caller signing identity to sign the funding as").option("--human", "Human-readable output instead of JSON").action((dvm, opts) => {
|
|
40756
41234
|
return catchErrors(() => creditFund(dvm, opts), opts.human);
|
|
40757
41235
|
});
|
|
40758
41236
|
credit.command("drain <dvm>").description(
|
|
@@ -40786,7 +41264,7 @@ function buildProgram() {
|
|
|
40786
41264
|
} }).exitOverride((error) => {
|
|
40787
41265
|
if (error.exitCode === 0 || !jsonWait()) process.exit(error.exitCode);
|
|
40788
41266
|
handleError(new DvmError("invalid_arguments", error.message.replace(/^error: /, "")), false, { event: "error" });
|
|
40789
|
-
}).description("Fetch messages from a job conversation").option("--endpoint <url>", "Provider URL override (env: DVM_JOB_ENDPOINT)").option("--job-token <hex>", "Job bearer token override (env: DVM_JOB_TOKEN)").option("--after <seq>", "Only show messages with seq > N").option("--no-stream", "Non-blocking snapshot instead of streaming until yield").option("--human", "Human-readable output instead of JSON").option("--wait", "Stay attached until the job needs input or ends; JSON output is one line per event").option("--until <duration>", "Wait limit with --wait (default: 12h; e.g. 30s, 5m, 12h)").option("--timeout <sec>", "Read timeout (default: 5s, or 60s with --wait)").action((jobId, opts) => {
|
|
41267
|
+
}).description("Fetch messages from a job conversation").option("--endpoint <url>", "Provider URL override (env: DVM_JOB_ENDPOINT)").option("--job-token <hex>", "Job bearer token override (env: DVM_JOB_TOKEN)").option("--after <seq>", "Only show messages with seq > N").option("--no-stream", "Non-blocking snapshot instead of streaming until yield").option("--human", "Human-readable output instead of JSON").option("--wait", "Stay attached until the job needs input or ends; JSON output is one line per event").option("--until <duration>", "Wait limit with --wait (default: 12h; e.g. 30s, 5m, 12h, 1h30m)").option("--timeout <sec>", "Read timeout (default: 5s, or 60s with --wait)").action((jobId, opts) => {
|
|
40790
41268
|
return catchErrors(() => messages(jobId, opts), opts.human, opts.wait && !opts.human ? { event: "error" } : void 0);
|
|
40791
41269
|
});
|
|
40792
41270
|
program2.command("message <job-id> [text]").description("Send a message in a job conversation").option("--endpoint <url>", "Provider URL override (env: DVM_JOB_ENDPOINT)").option("--job-token <hex>", "Job bearer token override (env: DVM_JOB_TOKEN)").option(
|
|
@@ -40908,7 +41386,7 @@ Docs:
|
|
|
40908
41386
|
"Local budget charges, credit draws, completed refunds/losses, and active recovery, newest first. Confirmed spend history has no automatic expiry; budget limits still use rolling windows."
|
|
40909
41387
|
).option("--today", "Only spends since UTC start of today").option(
|
|
40910
41388
|
"--since <iso-or-duration>",
|
|
40911
|
-
"Only spends since an ISO date (2026-07-01) or a duration (7d, 24h, 30m)"
|
|
41389
|
+
"Only spends since an ISO date (2026-07-01) or a duration (7d, 24h, 30m, 1h30m)"
|
|
40912
41390
|
).option("--limit <n>", "Max rows to show, newest first (default 50)").option("--offset <n>", "Skip rows in unchanged newest-first history (default 0)").option("--cursor <token>", "Continue history with the same filters; refuses changed local records").option("--endpoint <url>", "Only history at this endpoint origin").option("--kind <kind>", "Only job, float_fund, credit_fund, credit_draw, completed_refund, expired_credit_loss, or active_recovery rows").option("--human", "Human-readable table instead of JSON").action((opts) => {
|
|
40913
41391
|
return catchErrors(() => {
|
|
40914
41392
|
walletHistory(opts);
|
|
@@ -41152,7 +41630,7 @@ function collectOption(val, acc) {
|
|
|
41152
41630
|
acc.push(val);
|
|
41153
41631
|
return acc;
|
|
41154
41632
|
}
|
|
41155
|
-
if (process.argv[1] && realpathSync2(process.argv[1]) ===
|
|
41633
|
+
if (process.argv[1] && realpathSync2(process.argv[1]) === fileURLToPath4(import.meta.url)) {
|
|
41156
41634
|
installGlobalAcceptEncoding();
|
|
41157
41635
|
await buildProgram().parseAsync();
|
|
41158
41636
|
}
|