@dvmkit/dvm-cli 0.21.0 → 0.22.1
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-YRLRHJ6O.js → chunk-23FGJKIX.js} +1 -1
- package/dist/{chunk-GWISSHP6.js → chunk-2K4ARVPA.js} +202 -87
- package/dist/{chunk-L3PHIA5L.js → chunk-AFR5KKJX.js} +3 -3
- package/dist/{chunk-QVX7KPLS.js → chunk-AWK22TUP.js} +1 -1
- package/dist/{chunk-CMIEPFKP.js → chunk-AWWLO2WW.js} +4 -0
- package/dist/{chunk-M4Q3DBQO.js → chunk-ITESN5XP.js} +2 -2
- package/dist/{chunk-7UGJALAX.js → chunk-X2CKIG2D.js} +2 -2
- package/dist/{chunk-BU5E7IDF.js → chunk-YSALCR5X.js} +2 -4
- package/dist/{client-MJZL7XTD.js → client-5SB2HSH5.js} +2 -2
- package/dist/dvm.js +565 -205
- package/dist/{internal-TUEXUURQ.js → internal-EVD5WVAK.js} +1 -1
- package/dist/{lifecycle-7PSR5CYB.js → lifecycle-GR7WGYVQ.js} +2 -2
- package/dist/{pocket-refill-OX3WXUZ4.js → pocket-refill-MS6SL7FZ.js} +6 -6
- package/dist/{tempo-lifecycle-BOW6OFSI.js → tempo-lifecycle-7EYW5W5Z.js} +4 -4
- package/dist/{tempo-wallet-D424H37T.js → tempo-wallet-QOC3BHVE.js} +3 -3
- package/dist/{wallet-CZV4TOJ3.js → wallet-RIHHIQRK.js} +3 -3
- package/package.json +1 -1
- package/skills/dvm/calling.md +3 -3
- package/skills/dvm/credit.md +2 -0
- package/skills/dvm/wallets.md +3 -1
|
@@ -3,15 +3,15 @@ import { createRequire as __dvmCreateRequire } from "node:module";
|
|
|
3
3
|
const require = __dvmCreateRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
connectedTempoAccount
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AFR5KKJX.js";
|
|
7
7
|
import {
|
|
8
8
|
loadX402Wallet,
|
|
9
9
|
x402NetworkLabel
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-ITESN5XP.js";
|
|
11
11
|
import {
|
|
12
12
|
isCreditPosture,
|
|
13
13
|
loadConfig
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-YSALCR5X.js";
|
|
15
15
|
import {
|
|
16
16
|
addOutputWarnings,
|
|
17
17
|
costAnchor,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
resolveBtcUsdRate,
|
|
28
28
|
tryResolveBtcUsdRate,
|
|
29
29
|
tryX402Payment
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-23FGJKIX.js";
|
|
31
31
|
import {
|
|
32
32
|
A,
|
|
33
33
|
BUDGET_FILE,
|
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
STABLECOIN_FUND_RAILS,
|
|
43
43
|
TEMPO_CHARGE_PENDING_STALE_MS,
|
|
44
44
|
TEMPO_SESSION_UPDATED_REASON,
|
|
45
|
+
WALLET_FILE,
|
|
45
46
|
acknowledgeReplayedX402Payment,
|
|
46
47
|
acknowledgeX402ChannelOwner,
|
|
47
48
|
amountBoundsVerdict,
|
|
@@ -134,6 +135,7 @@ import {
|
|
|
134
135
|
recordPendingTempoChargeFunding,
|
|
135
136
|
recordPendingX402ExactFunding,
|
|
136
137
|
recordPendingX402Funding,
|
|
138
|
+
rehydrateOutputData,
|
|
137
139
|
require_proper_lockfile,
|
|
138
140
|
restoreProofsFromOutputs,
|
|
139
141
|
retirePendingX402Funding,
|
|
@@ -185,7 +187,7 @@ import {
|
|
|
185
187
|
x402PendingUnsettled,
|
|
186
188
|
x402RequiredFromError,
|
|
187
189
|
x402VoucherPendingState
|
|
188
|
-
} from "./chunk-
|
|
190
|
+
} from "./chunk-AWWLO2WW.js";
|
|
189
191
|
import {
|
|
190
192
|
Challenge_exports,
|
|
191
193
|
Credential_exports
|
|
@@ -3128,6 +3130,21 @@ function updateObservedJob(id, update) {
|
|
|
3128
3130
|
}
|
|
3129
3131
|
}, true);
|
|
3130
3132
|
}
|
|
3133
|
+
function recordStatusMessageHistory(id, next, previous) {
|
|
3134
|
+
if (isDeepStrictEqual(next, previous)) return;
|
|
3135
|
+
mutateJobs((jobs) => {
|
|
3136
|
+
const job = jobs.find((entry) => entry.id === id);
|
|
3137
|
+
if (!job) return;
|
|
3138
|
+
const current = job.statusMessageHistory;
|
|
3139
|
+
if (!current || isDeepStrictEqual(current, previous)) {
|
|
3140
|
+
job.statusMessageHistory = next;
|
|
3141
|
+
} else if (next.through > current.through) {
|
|
3142
|
+
const { promptGapScan, ...coverage } = next;
|
|
3143
|
+
const scan = isDeepStrictEqual(current.promptGapScan, previous?.promptGapScan) ? promptGapScan : current.promptGapScan;
|
|
3144
|
+
job.statusMessageHistory = { ...coverage, ...scan && { promptGapScan: scan } };
|
|
3145
|
+
}
|
|
3146
|
+
}, true);
|
|
3147
|
+
}
|
|
3131
3148
|
function recordCallerMessageHash(jobId, endpoint, hash) {
|
|
3132
3149
|
mutateJobs((jobs) => {
|
|
3133
3150
|
const job = jobs.find((entry) => entry.id === jobId && sameEndpoint(entry.endpoint, endpoint));
|
|
@@ -3262,15 +3279,17 @@ function clearPaymentCreditRefusals(job, requestSeq) {
|
|
|
3262
3279
|
function markPaymentRequestAnswered(jobId, requestSeq) {
|
|
3263
3280
|
mutateJobs((jobs) => {
|
|
3264
3281
|
const job = jobs.find((entry) => entry.id === jobId);
|
|
3265
|
-
if (
|
|
3266
|
-
clearPaymentCreditRefusals(job, requestSeq);
|
|
3267
|
-
if (!job.paidPaymentRequestSeqs?.includes(requestSeq))
|
|
3268
|
-
(job.paidPaymentRequestSeqs ??= []).push(requestSeq);
|
|
3269
|
-
job.inFlightPaymentRequestSeqs = job.inFlightPaymentRequestSeqs?.filter((seq) => seq !== requestSeq);
|
|
3270
|
-
if (!job.inFlightPaymentRequestSeqs?.length) delete job.inFlightPaymentRequestSeqs;
|
|
3271
|
-
clearPaymentRequestStartTime(job, requestSeq);
|
|
3282
|
+
if (job) recordAnsweredPaymentRequest(job, requestSeq);
|
|
3272
3283
|
}, true);
|
|
3273
3284
|
}
|
|
3285
|
+
function recordAnsweredPaymentRequest(job, requestSeq) {
|
|
3286
|
+
clearPaymentCreditRefusals(job, requestSeq);
|
|
3287
|
+
if (!job.paidPaymentRequestSeqs?.includes(requestSeq))
|
|
3288
|
+
(job.paidPaymentRequestSeqs ??= []).push(requestSeq);
|
|
3289
|
+
job.inFlightPaymentRequestSeqs = job.inFlightPaymentRequestSeqs?.filter((seq) => seq !== requestSeq);
|
|
3290
|
+
if (!job.inFlightPaymentRequestSeqs?.length) delete job.inFlightPaymentRequestSeqs;
|
|
3291
|
+
clearPaymentRequestStartTime(job, requestSeq);
|
|
3292
|
+
}
|
|
3274
3293
|
function blockHeldPayment(jobId, requestSeq, blocked) {
|
|
3275
3294
|
mutateJobs((jobs) => {
|
|
3276
3295
|
const job = jobs.find((entry) => entry.id === jobId);
|
|
@@ -4149,7 +4168,10 @@ function mandateDrawTotal(job, history) {
|
|
|
4149
4168
|
}
|
|
4150
4169
|
return total;
|
|
4151
4170
|
}
|
|
4152
|
-
function
|
|
4171
|
+
function confirmedMissingAsk(job, paymentSeq, requestSeq, fullHistoryThrough) {
|
|
4172
|
+
return fullHistoryThrough !== void 0 && paymentSeq <= fullHistoryThrough || job?.mandateMissingAskSeqs?.includes(requestSeq) === true;
|
|
4173
|
+
}
|
|
4174
|
+
function mandatePaymentReports(job, history, fullHistoryThrough) {
|
|
4153
4175
|
const mandate = job?.mandate;
|
|
4154
4176
|
const currency = safeCurrency(mandate?.currency);
|
|
4155
4177
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -4172,6 +4194,7 @@ function mandatePaymentReports(job, history) {
|
|
|
4172
4194
|
}
|
|
4173
4195
|
const total = job ? mandateDrawTotal(job, prefix) : 0;
|
|
4174
4196
|
const ask = asks.get(paid.request_seq);
|
|
4197
|
+
const requestUnverified = !ask && !seen.has(paid.request_seq) && !confirmedMissingAsk(job, message.seq, paid.request_seq, fullHistoryThrough);
|
|
4175
4198
|
const violations = [];
|
|
4176
4199
|
const reasons = [];
|
|
4177
4200
|
const breach = (field, reason) => {
|
|
@@ -4179,8 +4202,9 @@ function mandatePaymentReports(job, history) {
|
|
|
4179
4202
|
reasons.push(reason);
|
|
4180
4203
|
};
|
|
4181
4204
|
if (!validMicro2(paid.amount_micro) || paid.amount_micro === 0) breach("amount_micro", "an invalid payment amount");
|
|
4182
|
-
if (!ask)
|
|
4183
|
-
|
|
4205
|
+
if (!ask) {
|
|
4206
|
+
if (!requestUnverified) breach("request_seq", "a payment for a charge missing from the job's requests");
|
|
4207
|
+
} else if (!ask.content.credit) breach("ask_unpriced", "a payment for a charge with no credit price");
|
|
4184
4208
|
else {
|
|
4185
4209
|
if (paid.amount_micro > ask.content.credit.amount_micro)
|
|
4186
4210
|
breach("ask_amount_micro", `more than the provider requested for this charge (${money(ask.content.credit.amount_micro, currency)})`);
|
|
@@ -4203,7 +4227,7 @@ function mandatePaymentReports(job, history) {
|
|
|
4203
4227
|
const paidCurrency = mandate ? paid.currency === mandate.currency ? currency : null : safeCurrency(paid.currency);
|
|
4204
4228
|
const amount = { amount_micro: paid.amount_micro, currency: paid.currency, display: money(paid.amount_micro, paidCurrency) };
|
|
4205
4229
|
const overchargeDisplay = reasons.length ? `Provider overcharge: ${reasons.join("; ")}.` : void 0;
|
|
4206
|
-
const display = `${amount.display} paid from your credit under your standing limit. ` + (mandate ? `Running credit total ${money(total, currency)} of ${money(mandate.max_total_micro, currency)} budget.` : "The signed standing limit is not available locally, so its limits could not be checked.") + (overchargeDisplay ? ` ${overchargeDisplay}` : "");
|
|
4230
|
+
const display = `${amount.display} paid from your credit under your standing limit. ` + (mandate ? `Running credit total ${money(total, currency)} of ${money(mandate.max_total_micro, currency)} budget.` : "The signed standing limit is not available locally, so its limits could not be checked.") + (requestUnverified ? " The link to the payment request could not be verified from the available messages." : "") + (overchargeDisplay ? ` ${overchargeDisplay}` : "");
|
|
4207
4231
|
reports.push({
|
|
4208
4232
|
amount_msats: ask?.content.amount_msats ?? 0,
|
|
4209
4233
|
seq: message.seq,
|
|
@@ -4211,6 +4235,7 @@ function mandatePaymentReports(job, history) {
|
|
|
4211
4235
|
mandate: true,
|
|
4212
4236
|
amount,
|
|
4213
4237
|
limits_checked: !!mandate,
|
|
4238
|
+
...requestUnverified ? { request_seq_unverified: true } : {},
|
|
4214
4239
|
total_micro: total,
|
|
4215
4240
|
budget_micro: mandate?.max_total_micro,
|
|
4216
4241
|
currency,
|
|
@@ -4222,8 +4247,15 @@ function mandatePaymentReports(job, history) {
|
|
|
4222
4247
|
}
|
|
4223
4248
|
return reports;
|
|
4224
4249
|
}
|
|
4225
|
-
function
|
|
4226
|
-
|
|
4250
|
+
function readMandatePaymentReport(message, jobId) {
|
|
4251
|
+
if (!mandateCredit(message)) return void 0;
|
|
4252
|
+
return mandatePaymentReports(
|
|
4253
|
+
jobId ? loadJob(jobId) : void 0,
|
|
4254
|
+
[message, ...jobId ? loadMessages(jobId) : []]
|
|
4255
|
+
).find((entry) => entry.seq === message.seq);
|
|
4256
|
+
}
|
|
4257
|
+
function mandatePaymentSummary(job, messages, fullHistoryThrough) {
|
|
4258
|
+
const payments = mandatePaymentReports(job, messages, fullHistoryThrough);
|
|
4227
4259
|
if (!payments.length) return {};
|
|
4228
4260
|
const violated = [...new Set(payments.flatMap((payment) => payment.violated_limits))];
|
|
4229
4261
|
return { mandate_payments: payments, ...violated.length ? {
|
|
@@ -4232,17 +4264,30 @@ function mandatePaymentSummary(job, messages) {
|
|
|
4232
4264
|
display: [...new Set(payments.map((payment) => payment.overcharge_display).filter(Boolean))].join(" ")
|
|
4233
4265
|
} : {} };
|
|
4234
4266
|
}
|
|
4235
|
-
function recordMandatePayments(jobId, history) {
|
|
4267
|
+
function recordMandatePayments(jobId, history, fullHistoryThrough) {
|
|
4236
4268
|
if (!loadJob(jobId)?.mandate || !history.some(mandateCredit)) return;
|
|
4237
4269
|
mutateCreditPayment(jobId, (job) => {
|
|
4238
4270
|
for (const message of history) {
|
|
4239
4271
|
const credit = mandateCredit(message);
|
|
4240
4272
|
if (!credit) continue;
|
|
4273
|
+
const requestSeq = credit.request_seq;
|
|
4274
|
+
const request = history.find((entry) => entry.seq === requestSeq);
|
|
4275
|
+
const ask = request?.from === "provider" && request.type === "payment-request" ? request : void 0;
|
|
4276
|
+
if (Number.isSafeInteger(requestSeq) && requestSeq >= 0 && requestSeq < message.seq) {
|
|
4277
|
+
if (!ask && (request || confirmedMissingAsk(job, message.seq, requestSeq, fullHistoryThrough))) {
|
|
4278
|
+
if (!job.mandateMissingAskSeqs?.includes(requestSeq)) (job.mandateMissingAskSeqs ??= []).push(requestSeq);
|
|
4279
|
+
if (job.paidPaymentRequestSeqs?.includes(requestSeq))
|
|
4280
|
+
job.paidPaymentRequestSeqs = job.paidPaymentRequestSeqs.filter((seq) => seq !== requestSeq);
|
|
4281
|
+
} else {
|
|
4282
|
+
if (ask && job.mandateMissingAskSeqs?.includes(requestSeq))
|
|
4283
|
+
job.mandateMissingAskSeqs = job.mandateMissingAskSeqs.filter((seq) => seq !== requestSeq);
|
|
4284
|
+
recordAnsweredPaymentRequest(job, requestSeq);
|
|
4285
|
+
}
|
|
4286
|
+
}
|
|
4241
4287
|
if (job.pendingCreditPayment?.authorization.request_seq === credit.request_seq)
|
|
4242
4288
|
delete job.pendingCreditPayment;
|
|
4243
4289
|
const booked2 = job.mandatePaymentSeqs?.includes(message.seq) === true;
|
|
4244
|
-
const
|
|
4245
|
-
const msats = ask?.type === "payment-request" ? ask.content.amount_msats : 0;
|
|
4290
|
+
const msats = ask?.content.amount_msats ?? 0;
|
|
4246
4291
|
const valuations = job.mandatePaymentMsats ??= {};
|
|
4247
4292
|
const previous = valuations[message.seq] ?? 0;
|
|
4248
4293
|
if (!booked2 || previous === 0 && msats > 0) {
|
|
@@ -5421,12 +5466,13 @@ async function reconcilePaymentRequestHistory(jobId, requestSeq, history, status
|
|
|
5421
5466
|
);
|
|
5422
5467
|
return false;
|
|
5423
5468
|
}
|
|
5424
|
-
async function settleRecordedPayments(jobId) {
|
|
5469
|
+
async function settleRecordedPayments(jobId, fullHistoryThrough) {
|
|
5425
5470
|
await applySubmissionVerdicts().catch(() => void 0);
|
|
5426
5471
|
const job = loadJob(jobId);
|
|
5427
5472
|
const recorded = job?.mandate || job?.pendingCreditPayment ? loadMessages(jobId) : [];
|
|
5428
|
-
if (job?.mandate) recordMandatePayments(jobId, recorded);
|
|
5429
|
-
const
|
|
5473
|
+
if (job?.mandate) recordMandatePayments(jobId, recorded, fullHistoryThrough);
|
|
5474
|
+
const reconciled = loadJob(jobId);
|
|
5475
|
+
const pending = reconciled?.pendingCreditPayment;
|
|
5430
5476
|
if (pending && recorded.some((message) => {
|
|
5431
5477
|
const credit = message.type === "payment" && message.from === "requester" ? message.content.credit : void 0;
|
|
5432
5478
|
const expected = pending.authorization;
|
|
@@ -5440,7 +5486,11 @@ async function settleRecordedPayments(jobId) {
|
|
|
5440
5486
|
if (held.size === 0) return;
|
|
5441
5487
|
const history = loadMessages(jobId);
|
|
5442
5488
|
const answers = paymentAnswers(history);
|
|
5443
|
-
for (const seq of held)
|
|
5489
|
+
for (const seq of held) {
|
|
5490
|
+
const payments = answers.get(seq);
|
|
5491
|
+
if (payments?.some((payment) => !mandateCredit(payment) || !reconciled?.mandateMissingAskSeqs?.includes(seq)))
|
|
5492
|
+
await settleAnsweredAsk(jobId, seq, history);
|
|
5493
|
+
}
|
|
5444
5494
|
}
|
|
5445
5495
|
function settleUntilMs(jobId, requestSeq, now) {
|
|
5446
5496
|
const startedAt = loadJob(jobId)?.inFlightPaymentRequestStartedAtMs?.[requestSeq];
|
|
@@ -5737,12 +5787,12 @@ async function stablecoinRemaining(rail) {
|
|
|
5737
5787
|
const balance = await Promise.race([
|
|
5738
5788
|
(async () => {
|
|
5739
5789
|
if (rail === "x402") {
|
|
5740
|
-
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-
|
|
5790
|
+
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-RIHHIQRK.js");
|
|
5741
5791
|
const wallet = loadX402Wallet2();
|
|
5742
5792
|
if (!wallet) return;
|
|
5743
5793
|
return (await getX402Balance(await ensureAddress(wallet))).usdc;
|
|
5744
5794
|
}
|
|
5745
|
-
const { connectedTempoAccount: connectedTempoAccount2 } = await import("./tempo-wallet-
|
|
5795
|
+
const { connectedTempoAccount: connectedTempoAccount2 } = await import("./tempo-wallet-QOC3BHVE.js");
|
|
5746
5796
|
const account = await connectedTempoAccount2();
|
|
5747
5797
|
if (account) return (await getTempoUsdcBalance(account)).usdc;
|
|
5748
5798
|
})(),
|
|
@@ -9926,6 +9976,9 @@ async function findFundableAlternatives(configured, skip, sats) {
|
|
|
9926
9976
|
}
|
|
9927
9977
|
|
|
9928
9978
|
// src/lib/wallet-agent/recovery.ts
|
|
9979
|
+
import { createHash as createHash4 } from "crypto";
|
|
9980
|
+
import { setTimeout as sleepFor } from "timers/promises";
|
|
9981
|
+
var import_proper_lockfile5 = __toESM(require_proper_lockfile(), 1);
|
|
9929
9982
|
var DEFAULT_SWEEP_QUOTE_RETRY_TIMEOUT_MS = 1e4;
|
|
9930
9983
|
var MINT_QUOTE_EXPIRY_GRACE_MS = 24 * 60 * 60 * 1e3;
|
|
9931
9984
|
async function sweepPendingMints(opts = {}) {
|
|
@@ -9933,27 +9986,17 @@ async function sweepPendingMints(opts = {}) {
|
|
|
9933
9986
|
if (!wallet || wallet.pending_mints.length === 0) {
|
|
9934
9987
|
return { outcomes: [], recovered_proofs: [], still_pending: [], refused: [], errors: [] };
|
|
9935
9988
|
}
|
|
9936
|
-
const now = opts.now ?? (() => Date.now());
|
|
9937
|
-
const expiryGraceMs = opts.expiryGraceMs ?? MINT_QUOTE_EXPIRY_GRACE_MS;
|
|
9938
|
-
const getWalletForMint = opts.getWalletForMint ?? getWallet;
|
|
9939
|
-
const quoteRetryTimeoutMs = opts.quoteRetryTimeoutMs ?? DEFAULT_SWEEP_QUOTE_RETRY_TIMEOUT_MS;
|
|
9940
9989
|
const outcomes = [];
|
|
9941
9990
|
for (const entry of wallet.pending_mints) {
|
|
9942
|
-
const outcome = await
|
|
9943
|
-
|
|
9944
|
-
|
|
9945
|
-
|
|
9946
|
-
})
|
|
9947
|
-
|
|
9948
|
-
|
|
9949
|
-
|
|
9950
|
-
|
|
9951
|
-
)) {
|
|
9952
|
-
await withWalletLock(() => {
|
|
9953
|
-
const fresh = loadAgentWallet() ?? wallet;
|
|
9954
|
-
const updated = outcomes.reduce(applyOutcome, fresh);
|
|
9955
|
-
saveAgentWallet(updated);
|
|
9956
|
-
});
|
|
9991
|
+
const outcome = await reconcilePendingMint(entry, opts);
|
|
9992
|
+
if (outcome.kind === "no_longer_pending") continue;
|
|
9993
|
+
if (outcome.kind === "busy") {
|
|
9994
|
+
outcomes.push({ kind: "error", entry, error: "Another command is checking this mint quote." });
|
|
9995
|
+
} else if (outcome.kind === "error") {
|
|
9996
|
+
outcomes.push({ kind: "error", entry: outcome.entry, error: errorMessage(outcome.cause) });
|
|
9997
|
+
} else {
|
|
9998
|
+
outcomes.push(outcome);
|
|
9999
|
+
}
|
|
9957
10000
|
}
|
|
9958
10001
|
return {
|
|
9959
10002
|
outcomes,
|
|
@@ -9967,7 +10010,69 @@ async function sweepPendingMints(opts = {}) {
|
|
|
9967
10010
|
errors: outcomes.filter((o) => o.kind === "error").map((o) => ({ quote_id: o.entry.quote_id, error: o.error }))
|
|
9968
10011
|
};
|
|
9969
10012
|
}
|
|
9970
|
-
async function
|
|
10013
|
+
async function reconcilePendingMint(entry, opts = {}) {
|
|
10014
|
+
const key = createHash4("sha256").update(JSON.stringify([entry.mint, entry.quote_id])).digest("hex");
|
|
10015
|
+
let release;
|
|
10016
|
+
try {
|
|
10017
|
+
release = await import_proper_lockfile5.default.lock(`${WALLET_FILE}.mint-${key}`, { realpath: false, stale: 3e4, retries: 0 });
|
|
10018
|
+
} catch (err) {
|
|
10019
|
+
if (err.code === "ELOCKED") return { kind: "busy" };
|
|
10020
|
+
return { kind: "error", entry, cause: err };
|
|
10021
|
+
}
|
|
10022
|
+
try {
|
|
10023
|
+
const wallet = loadAgentWallet();
|
|
10024
|
+
const current = wallet?.pending_mints.find((pending) => matchesPendingMint(pending, entry));
|
|
10025
|
+
if (!wallet || !current) return { kind: "no_longer_pending" };
|
|
10026
|
+
const outcome = await processEntry(wallet, current, opts);
|
|
10027
|
+
if (outcome.kind === "minted" || outcome.kind === "restored" || outcome.kind === "already_issued" || outcome.kind === "expired") {
|
|
10028
|
+
const committed = await withMintWriteLock(opts.deadlineMs, () => {
|
|
10029
|
+
const fresh = currentMintWallet(wallet, current);
|
|
10030
|
+
if (!fresh) return false;
|
|
10031
|
+
const proofs = outcome.kind === "minted" || outcome.kind === "restored" ? outcome.proofs : [];
|
|
10032
|
+
saveAgentWallet({
|
|
10033
|
+
...fresh,
|
|
10034
|
+
pending_mints: fresh.pending_mints.filter((pending) => !matchesPendingMint(pending, current)),
|
|
10035
|
+
proofs: [...fresh.proofs, ...proofs]
|
|
10036
|
+
});
|
|
10037
|
+
return true;
|
|
10038
|
+
});
|
|
10039
|
+
if (!committed) return { kind: "no_longer_pending" };
|
|
10040
|
+
}
|
|
10041
|
+
return outcome;
|
|
10042
|
+
} catch (err) {
|
|
10043
|
+
return { kind: "error", entry, cause: err };
|
|
10044
|
+
} finally {
|
|
10045
|
+
await release().catch(() => void 0);
|
|
10046
|
+
}
|
|
10047
|
+
}
|
|
10048
|
+
function matchesPendingMint(left, right) {
|
|
10049
|
+
return left.mint === right.mint && left.quote_id === right.quote_id && left.requested_at === right.requested_at;
|
|
10050
|
+
}
|
|
10051
|
+
function currentMintWallet(wallet, entry) {
|
|
10052
|
+
const fresh = loadAgentWallet();
|
|
10053
|
+
if (fresh?.lock_pubkey === wallet.lock_pubkey && fresh.pending_mints.some((pending) => matchesPendingMint(pending, entry))) {
|
|
10054
|
+
return fresh;
|
|
10055
|
+
}
|
|
10056
|
+
}
|
|
10057
|
+
async function withMintWriteLock(deadlineMs, write) {
|
|
10058
|
+
if (deadlineMs === void 0) return withWalletLock(write);
|
|
10059
|
+
for (; ; ) {
|
|
10060
|
+
try {
|
|
10061
|
+
return await withWalletLock(write, { retries: 0 });
|
|
10062
|
+
} catch (err) {
|
|
10063
|
+
const remaining = deadlineMs - Date.now();
|
|
10064
|
+
if (!(err instanceof DvmError && err.code === "wallet_locked") || remaining <= 0) throw err;
|
|
10065
|
+
await sleepFor(Math.min(remaining, 50));
|
|
10066
|
+
}
|
|
10067
|
+
}
|
|
10068
|
+
}
|
|
10069
|
+
async function processEntry(wallet, entry, opts) {
|
|
10070
|
+
const now = opts.now ?? Date.now;
|
|
10071
|
+
const nowMs = now();
|
|
10072
|
+
if (opts.pollDeadlineMs !== void 0 && nowMs >= opts.pollDeadlineMs) {
|
|
10073
|
+
return { kind: "still_pending", entry };
|
|
10074
|
+
}
|
|
10075
|
+
const getWalletForMint = opts.getWalletForMint ?? getWallet;
|
|
9971
10076
|
let cashuWallet;
|
|
9972
10077
|
let quoteResponse;
|
|
9973
10078
|
try {
|
|
@@ -9978,10 +10083,13 @@ async function processEntry(wallet, entry, nowMs, expiryGraceMs, getWalletForMin
|
|
|
9978
10083
|
return { cashuWallet: candidate, quoteResponse: quote };
|
|
9979
10084
|
},
|
|
9980
10085
|
{
|
|
9981
|
-
deadlineMs:
|
|
10086
|
+
deadlineMs: Math.min(
|
|
10087
|
+
opts.pollDeadlineMs ?? Infinity,
|
|
10088
|
+
nowMs + (opts.quoteRetryTimeoutMs ?? DEFAULT_SWEEP_QUOTE_RETRY_TIMEOUT_MS)
|
|
10089
|
+
),
|
|
9982
10090
|
quoteId: entry.quote_id,
|
|
9983
|
-
now
|
|
9984
|
-
sleep:
|
|
10091
|
+
now,
|
|
10092
|
+
sleep: opts.sleep
|
|
9985
10093
|
}
|
|
9986
10094
|
));
|
|
9987
10095
|
} catch (err) {
|
|
@@ -9994,7 +10102,7 @@ async function processEntry(wallet, entry, nowMs, expiryGraceMs, getWalletForMin
|
|
|
9994
10102
|
() => getWalletForMint(entry.mint)
|
|
9995
10103
|
);
|
|
9996
10104
|
}
|
|
9997
|
-
return { kind: "error", entry,
|
|
10105
|
+
return { kind: "error", entry, cause: err };
|
|
9998
10106
|
}
|
|
9999
10107
|
const state = quoteResponse.state;
|
|
10000
10108
|
if (state === sa.ISSUED) {
|
|
@@ -10013,36 +10121,53 @@ async function processEntry(wallet, entry, nowMs, expiryGraceMs, getWalletForMin
|
|
|
10013
10121
|
}
|
|
10014
10122
|
return { kind: "restored", entry, proofs: restoredProofs };
|
|
10015
10123
|
} catch (err) {
|
|
10016
|
-
return { kind: "error", entry,
|
|
10124
|
+
return { kind: "error", entry, cause: err };
|
|
10017
10125
|
}
|
|
10018
10126
|
}
|
|
10019
10127
|
if (state === sa.PAID) {
|
|
10020
10128
|
try {
|
|
10021
|
-
|
|
10022
|
-
|
|
10023
|
-
|
|
10024
|
-
|
|
10025
|
-
|
|
10129
|
+
let savedMinting = entry.minting;
|
|
10130
|
+
if (savedMinting && cashuWallet.keyChain.getKeysets().some(
|
|
10131
|
+
(keyset) => keyset.id === savedMinting?.keyset_id && keyset.isActive === false
|
|
10132
|
+
)) {
|
|
10133
|
+
await cashuWallet.ensureOperableKeysets([savedMinting.keyset_id]);
|
|
10134
|
+
const proofs2 = await restoreFromMintingState(cashuWallet, savedMinting, wallet.lock_pubkey, entry.mint);
|
|
10135
|
+
if (proofs2.length > 0) return { kind: "restored", entry, proofs: proofs2 };
|
|
10136
|
+
savedMinting = void 0;
|
|
10137
|
+
}
|
|
10138
|
+
const preview = savedMinting ? await cashuWallet.prepareMint(
|
|
10139
|
+
"bolt11",
|
|
10140
|
+
entry.amount_sats,
|
|
10141
|
+
quoteResponse,
|
|
10142
|
+
{ privkey: wallet.lock_privkey, keysetId: savedMinting.keyset_id },
|
|
10143
|
+
{ type: "custom", data: rehydrateOutputData(savedMinting.outputs) }
|
|
10144
|
+
) : await prepareP2PKMint(
|
|
10026
10145
|
cashuWallet,
|
|
10027
10146
|
entry.amount_sats,
|
|
10028
10147
|
quoteResponse,
|
|
10029
10148
|
wallet.lock_privkey,
|
|
10030
10149
|
wallet.lock_pubkey,
|
|
10031
|
-
|
|
10150
|
+
computeSmartDenominations(entry.amount_sats, {
|
|
10151
|
+
maxDenomination: maxKeysetDenomination(cashuWallet),
|
|
10152
|
+
includeTinyTail: false
|
|
10153
|
+
})
|
|
10032
10154
|
);
|
|
10033
|
-
|
|
10034
|
-
|
|
10035
|
-
|
|
10036
|
-
|
|
10037
|
-
|
|
10038
|
-
const
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10042
|
-
|
|
10043
|
-
|
|
10155
|
+
if (!savedMinting) {
|
|
10156
|
+
const minting = {
|
|
10157
|
+
keyset_id: preview.keysetId,
|
|
10158
|
+
outputs: serializeOutputData(preview.outputData)
|
|
10159
|
+
};
|
|
10160
|
+
const saved = await withMintWriteLock(opts.deadlineMs, () => {
|
|
10161
|
+
const fresh = currentMintWallet(wallet, entry);
|
|
10162
|
+
if (!fresh) return false;
|
|
10163
|
+
saveAgentWallet({
|
|
10164
|
+
...fresh,
|
|
10165
|
+
pending_mints: fresh.pending_mints.map((p) => matchesPendingMint(p, entry) ? { ...p, minting } : p)
|
|
10166
|
+
});
|
|
10167
|
+
return true;
|
|
10044
10168
|
});
|
|
10045
|
-
|
|
10169
|
+
if (!saved) return { kind: "no_longer_pending" };
|
|
10170
|
+
}
|
|
10046
10171
|
const proofs = await cashuWallet.completeMint(preview);
|
|
10047
10172
|
const agentProofs = proofs.map((p) => toAgentProof(p, entry.mint, wallet.lock_pubkey));
|
|
10048
10173
|
return { kind: "minted", entry, proofs: agentProofs };
|
|
@@ -10050,7 +10175,7 @@ async function processEntry(wallet, entry, nowMs, expiryGraceMs, getWalletForMin
|
|
|
10050
10175
|
if (mintQuoteRefusal(err) === "expired") {
|
|
10051
10176
|
return { kind: "paid_refused", entry, reason: "quote_expired" };
|
|
10052
10177
|
}
|
|
10053
|
-
return { kind: "error", entry,
|
|
10178
|
+
return { kind: "error", entry, cause: err };
|
|
10054
10179
|
}
|
|
10055
10180
|
}
|
|
10056
10181
|
if (state === "EXPIRED") {
|
|
@@ -10064,7 +10189,7 @@ async function processEntry(wallet, entry, nowMs, expiryGraceMs, getWalletForMin
|
|
|
10064
10189
|
if (nowMs <= expiredAtMs) {
|
|
10065
10190
|
return { kind: "still_pending", entry };
|
|
10066
10191
|
}
|
|
10067
|
-
const dropAfterMs = expiredAtMs + expiryGraceMs;
|
|
10192
|
+
const dropAfterMs = expiredAtMs + (opts.expiryGraceMs ?? MINT_QUOTE_EXPIRY_GRACE_MS);
|
|
10068
10193
|
if (nowMs > dropAfterMs) {
|
|
10069
10194
|
return finalAnswer(wallet, entry, "grace_elapsed", async () => cashuWallet);
|
|
10070
10195
|
}
|
|
@@ -10085,13 +10210,13 @@ async function finalAnswer(wallet, entry, reason, getCashuWallet) {
|
|
|
10085
10210
|
);
|
|
10086
10211
|
if (restored.length > 0) return { kind: "restored", entry, proofs: restored };
|
|
10087
10212
|
} catch (err) {
|
|
10088
|
-
return { kind: "error", entry,
|
|
10213
|
+
return { kind: "error", entry, cause: err };
|
|
10089
10214
|
}
|
|
10090
10215
|
if (reason === "mint_expired") return { kind: "paid_refused", entry, reason: "quote_expired" };
|
|
10091
10216
|
return {
|
|
10092
10217
|
kind: "error",
|
|
10093
10218
|
entry,
|
|
10094
|
-
|
|
10219
|
+
cause: reason === "mint_unknown" ? "The mint reported this quote paid earlier and no longer knows it; nothing could be restored, so the quote is kept." : "The mint reported this quote paid earlier and now reports it unpaid; nothing could be restored, so the quote is kept."
|
|
10095
10220
|
};
|
|
10096
10221
|
}
|
|
10097
10222
|
var MINT_QUOTE_EXPIRED_CODE = 20007;
|
|
@@ -10111,19 +10236,6 @@ async function restoreFromMintingState(cashuWallet, minting, lockPubkey, mintUrl
|
|
|
10111
10236
|
const proofs = await restoreProofsFromOutputs(cashuWallet, minting.keyset_id, minting.outputs);
|
|
10112
10237
|
return proofs.map((proof) => toAgentProof(proof, mintUrl, lockPubkey));
|
|
10113
10238
|
}
|
|
10114
|
-
function applyOutcome(wallet, outcome) {
|
|
10115
|
-
if (outcome.kind === "still_pending" || outcome.kind === "paid_refused" || outcome.kind === "error") {
|
|
10116
|
-
return wallet;
|
|
10117
|
-
}
|
|
10118
|
-
const next = {
|
|
10119
|
-
...wallet,
|
|
10120
|
-
pending_mints: wallet.pending_mints.filter((p) => p.quote_id !== outcome.entry.quote_id)
|
|
10121
|
-
};
|
|
10122
|
-
if (outcome.kind === "minted" || outcome.kind === "restored") {
|
|
10123
|
-
next.proofs = [...wallet.proofs, ...outcome.proofs];
|
|
10124
|
-
}
|
|
10125
|
-
return next;
|
|
10126
|
-
}
|
|
10127
10239
|
function errorMessage(err) {
|
|
10128
10240
|
return err instanceof Error ? err.message : String(err);
|
|
10129
10241
|
}
|
|
@@ -10175,6 +10287,7 @@ export {
|
|
|
10175
10287
|
hasUnknownUpfrontRail,
|
|
10176
10288
|
updateJob,
|
|
10177
10289
|
updateObservedJob,
|
|
10290
|
+
recordStatusMessageHistory,
|
|
10178
10291
|
recordCallerMessageHash,
|
|
10179
10292
|
markJobTerminal,
|
|
10180
10293
|
loadJob,
|
|
@@ -10213,6 +10326,7 @@ export {
|
|
|
10213
10326
|
mandateCredit,
|
|
10214
10327
|
mandateDrawTotal,
|
|
10215
10328
|
mandatePaymentReports,
|
|
10329
|
+
readMandatePaymentReport,
|
|
10216
10330
|
mandatePaymentSummary,
|
|
10217
10331
|
recordMandatePayments,
|
|
10218
10332
|
storedMandateSummary,
|
|
@@ -10355,5 +10469,6 @@ export {
|
|
|
10355
10469
|
describeMintBounds,
|
|
10356
10470
|
MINT_QUOTE_EXPIRY_GRACE_MS,
|
|
10357
10471
|
sweepPendingMints,
|
|
10472
|
+
reconcilePendingMint,
|
|
10358
10473
|
mintQuoteRefusal
|
|
10359
10474
|
};
|
|
@@ -4,11 +4,11 @@ const require = __dvmCreateRequire(import.meta.url);
|
|
|
4
4
|
import {
|
|
5
5
|
loadConfig,
|
|
6
6
|
updateConfig
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-YSALCR5X.js";
|
|
8
8
|
import {
|
|
9
9
|
tempoAccountFromConfig,
|
|
10
10
|
tryResolveTempoAsset
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-AWWLO2WW.js";
|
|
12
12
|
import {
|
|
13
13
|
DvmError
|
|
14
14
|
} from "./chunk-MP63OWTD.js";
|
|
@@ -46,7 +46,7 @@ async function generateTempoKey(opts = {}) {
|
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
48
|
if (existing && opts.force) {
|
|
49
|
-
const { assertTempoWalletIdle } = await import("./tempo-lifecycle-
|
|
49
|
+
const { assertTempoWalletIdle } = await import("./tempo-lifecycle-7EYW5W5Z.js");
|
|
50
50
|
await assertTempoWalletIdle("replace");
|
|
51
51
|
}
|
|
52
52
|
const { privateKeyToAccount, generatePrivateKey } = await import("./accounts-2WZE4N5F.js");
|
|
@@ -17160,6 +17160,9 @@ var _a = {
|
|
|
17160
17160
|
};
|
|
17161
17161
|
var va = {};
|
|
17162
17162
|
var ya = E;
|
|
17163
|
+
function ba(e24) {
|
|
17164
|
+
va = e24;
|
|
17165
|
+
}
|
|
17163
17166
|
function xa(e24) {
|
|
17164
17167
|
ya = e24;
|
|
17165
17168
|
}
|
|
@@ -78398,6 +78401,7 @@ export {
|
|
|
78398
78401
|
ki,
|
|
78399
78402
|
sa,
|
|
78400
78403
|
la,
|
|
78404
|
+
ba,
|
|
78401
78405
|
extract,
|
|
78402
78406
|
expand,
|
|
78403
78407
|
toLockPubkey,
|
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
authorizeProtectedRemoval,
|
|
6
6
|
loadConfig,
|
|
7
7
|
updateConfig
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-YSALCR5X.js";
|
|
9
9
|
import {
|
|
10
10
|
withX402ChannelLock,
|
|
11
11
|
x402WalletFromConfig
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-AWWLO2WW.js";
|
|
13
13
|
import {
|
|
14
14
|
DvmError,
|
|
15
15
|
X402_DEFAULT_NETWORK,
|
|
@@ -3,7 +3,7 @@ import { createRequire as __dvmCreateRequire } from "node:module";
|
|
|
3
3
|
const require = __dvmCreateRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
connectedTempoAccount
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AFR5KKJX.js";
|
|
7
7
|
import {
|
|
8
8
|
deriveIdentityFromPrivkey,
|
|
9
9
|
formatUsdcMicrounits,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
reconcileTempoChannelOnChain,
|
|
14
14
|
shellQuoteArg,
|
|
15
15
|
tempoChannelControlledBy
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-AWWLO2WW.js";
|
|
17
17
|
import {
|
|
18
18
|
DvmError
|
|
19
19
|
} from "./chunk-MP63OWTD.js";
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
CONFIG_PINNED_FILE,
|
|
9
9
|
ensureConfigDir,
|
|
10
10
|
require_proper_lockfile
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-AWWLO2WW.js";
|
|
12
12
|
import {
|
|
13
13
|
DvmError
|
|
14
14
|
} from "./chunk-MP63OWTD.js";
|
|
@@ -197,7 +197,6 @@ function readRawConfig() {
|
|
|
197
197
|
function writeConfigFile(config) {
|
|
198
198
|
writeJsonAtomic(CONFIG_FILE, config);
|
|
199
199
|
}
|
|
200
|
-
var CONFIG_SNAPSHOT_SLOTS = ["backup", "pinned"];
|
|
201
200
|
function configSnapshotPath(slot) {
|
|
202
201
|
return slot === "pinned" ? CONFIG_PINNED_FILE : CONFIG_BACKUP_FILE;
|
|
203
202
|
}
|
|
@@ -536,7 +535,6 @@ async function updateConfig(update) {
|
|
|
536
535
|
const stripped = [
|
|
537
536
|
.../* @__PURE__ */ new Set([...removals, ...superseded, ...update.sanitizeBackup ?? []])
|
|
538
537
|
].filter(isSecretProtectedTarget);
|
|
539
|
-
const sweeping = update.sweepSlots ?? CONFIG_SNAPSHOT_SLOTS;
|
|
540
538
|
const swept = [];
|
|
541
539
|
if (raw !== null) {
|
|
542
540
|
if (stripped.length > 0) {
|
|
@@ -546,7 +544,7 @@ async function updateConfig(update) {
|
|
|
546
544
|
retainConfigBackup();
|
|
547
545
|
}
|
|
548
546
|
}
|
|
549
|
-
if (stripped.length > 0 &&
|
|
547
|
+
if (stripped.length > 0 && update.preservePin !== true) {
|
|
550
548
|
if (sweepPinnedSnapshot(stripped, base ?? {}, update.reason)) swept.push("pinned");
|
|
551
549
|
}
|
|
552
550
|
const backup = describeConfigBackup();
|
|
@@ -3,8 +3,8 @@ import { createRequire as __dvmCreateRequire } from "node:module";
|
|
|
3
3
|
const require = __dvmCreateRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
tryX402Payment
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-23FGJKIX.js";
|
|
7
|
+
import "./chunk-AWWLO2WW.js";
|
|
8
8
|
import "./chunk-JBU7RKQ3.js";
|
|
9
9
|
import "./chunk-KDNFUDOG.js";
|
|
10
10
|
import "./chunk-IUTVV6N5.js";
|