@dvmkit/dvm-cli 0.21.0 → 0.22.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-YRLRHJ6O.js → chunk-23FGJKIX.js} +1 -1
- 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-GWISSHP6.js → chunk-WGZ3HBST.js} +186 -87
- 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 +391 -162
- 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-TF7M2XCZ.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 +2 -2
- package/skills/dvm/credit.md +2 -0
- package/skills/dvm/wallets.md +3 -1
|
@@ -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,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
|
|
@@ -3262,15 +3264,17 @@ function clearPaymentCreditRefusals(job, requestSeq) {
|
|
|
3262
3264
|
function markPaymentRequestAnswered(jobId, requestSeq) {
|
|
3263
3265
|
mutateJobs((jobs) => {
|
|
3264
3266
|
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);
|
|
3267
|
+
if (job) recordAnsweredPaymentRequest(job, requestSeq);
|
|
3272
3268
|
}, true);
|
|
3273
3269
|
}
|
|
3270
|
+
function recordAnsweredPaymentRequest(job, requestSeq) {
|
|
3271
|
+
clearPaymentCreditRefusals(job, requestSeq);
|
|
3272
|
+
if (!job.paidPaymentRequestSeqs?.includes(requestSeq))
|
|
3273
|
+
(job.paidPaymentRequestSeqs ??= []).push(requestSeq);
|
|
3274
|
+
job.inFlightPaymentRequestSeqs = job.inFlightPaymentRequestSeqs?.filter((seq) => seq !== requestSeq);
|
|
3275
|
+
if (!job.inFlightPaymentRequestSeqs?.length) delete job.inFlightPaymentRequestSeqs;
|
|
3276
|
+
clearPaymentRequestStartTime(job, requestSeq);
|
|
3277
|
+
}
|
|
3274
3278
|
function blockHeldPayment(jobId, requestSeq, blocked) {
|
|
3275
3279
|
mutateJobs((jobs) => {
|
|
3276
3280
|
const job = jobs.find((entry) => entry.id === jobId);
|
|
@@ -4149,7 +4153,10 @@ function mandateDrawTotal(job, history) {
|
|
|
4149
4153
|
}
|
|
4150
4154
|
return total;
|
|
4151
4155
|
}
|
|
4152
|
-
function
|
|
4156
|
+
function confirmedMissingAsk(job, paymentSeq, requestSeq, fullHistoryThrough) {
|
|
4157
|
+
return fullHistoryThrough !== void 0 && paymentSeq <= fullHistoryThrough || job?.mandateMissingAskSeqs?.includes(requestSeq) === true;
|
|
4158
|
+
}
|
|
4159
|
+
function mandatePaymentReports(job, history, fullHistoryThrough) {
|
|
4153
4160
|
const mandate = job?.mandate;
|
|
4154
4161
|
const currency = safeCurrency(mandate?.currency);
|
|
4155
4162
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -4172,6 +4179,7 @@ function mandatePaymentReports(job, history) {
|
|
|
4172
4179
|
}
|
|
4173
4180
|
const total = job ? mandateDrawTotal(job, prefix) : 0;
|
|
4174
4181
|
const ask = asks.get(paid.request_seq);
|
|
4182
|
+
const requestUnverified = !ask && !seen.has(paid.request_seq) && !confirmedMissingAsk(job, message.seq, paid.request_seq, fullHistoryThrough);
|
|
4175
4183
|
const violations = [];
|
|
4176
4184
|
const reasons = [];
|
|
4177
4185
|
const breach = (field, reason) => {
|
|
@@ -4179,8 +4187,9 @@ function mandatePaymentReports(job, history) {
|
|
|
4179
4187
|
reasons.push(reason);
|
|
4180
4188
|
};
|
|
4181
4189
|
if (!validMicro2(paid.amount_micro) || paid.amount_micro === 0) breach("amount_micro", "an invalid payment amount");
|
|
4182
|
-
if (!ask)
|
|
4183
|
-
|
|
4190
|
+
if (!ask) {
|
|
4191
|
+
if (!requestUnverified) breach("request_seq", "a payment for a charge missing from the job's requests");
|
|
4192
|
+
} else if (!ask.content.credit) breach("ask_unpriced", "a payment for a charge with no credit price");
|
|
4184
4193
|
else {
|
|
4185
4194
|
if (paid.amount_micro > ask.content.credit.amount_micro)
|
|
4186
4195
|
breach("ask_amount_micro", `more than the provider requested for this charge (${money(ask.content.credit.amount_micro, currency)})`);
|
|
@@ -4203,7 +4212,7 @@ function mandatePaymentReports(job, history) {
|
|
|
4203
4212
|
const paidCurrency = mandate ? paid.currency === mandate.currency ? currency : null : safeCurrency(paid.currency);
|
|
4204
4213
|
const amount = { amount_micro: paid.amount_micro, currency: paid.currency, display: money(paid.amount_micro, paidCurrency) };
|
|
4205
4214
|
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}` : "");
|
|
4215
|
+
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
4216
|
reports.push({
|
|
4208
4217
|
amount_msats: ask?.content.amount_msats ?? 0,
|
|
4209
4218
|
seq: message.seq,
|
|
@@ -4211,6 +4220,7 @@ function mandatePaymentReports(job, history) {
|
|
|
4211
4220
|
mandate: true,
|
|
4212
4221
|
amount,
|
|
4213
4222
|
limits_checked: !!mandate,
|
|
4223
|
+
...requestUnverified ? { request_seq_unverified: true } : {},
|
|
4214
4224
|
total_micro: total,
|
|
4215
4225
|
budget_micro: mandate?.max_total_micro,
|
|
4216
4226
|
currency,
|
|
@@ -4222,8 +4232,15 @@ function mandatePaymentReports(job, history) {
|
|
|
4222
4232
|
}
|
|
4223
4233
|
return reports;
|
|
4224
4234
|
}
|
|
4225
|
-
function
|
|
4226
|
-
|
|
4235
|
+
function readMandatePaymentReport(message, jobId) {
|
|
4236
|
+
if (!mandateCredit(message)) return void 0;
|
|
4237
|
+
return mandatePaymentReports(
|
|
4238
|
+
jobId ? loadJob(jobId) : void 0,
|
|
4239
|
+
[message, ...jobId ? loadMessages(jobId) : []]
|
|
4240
|
+
).find((entry) => entry.seq === message.seq);
|
|
4241
|
+
}
|
|
4242
|
+
function mandatePaymentSummary(job, messages, fullHistoryThrough) {
|
|
4243
|
+
const payments = mandatePaymentReports(job, messages, fullHistoryThrough);
|
|
4227
4244
|
if (!payments.length) return {};
|
|
4228
4245
|
const violated = [...new Set(payments.flatMap((payment) => payment.violated_limits))];
|
|
4229
4246
|
return { mandate_payments: payments, ...violated.length ? {
|
|
@@ -4232,17 +4249,30 @@ function mandatePaymentSummary(job, messages) {
|
|
|
4232
4249
|
display: [...new Set(payments.map((payment) => payment.overcharge_display).filter(Boolean))].join(" ")
|
|
4233
4250
|
} : {} };
|
|
4234
4251
|
}
|
|
4235
|
-
function recordMandatePayments(jobId, history) {
|
|
4252
|
+
function recordMandatePayments(jobId, history, fullHistoryThrough) {
|
|
4236
4253
|
if (!loadJob(jobId)?.mandate || !history.some(mandateCredit)) return;
|
|
4237
4254
|
mutateCreditPayment(jobId, (job) => {
|
|
4238
4255
|
for (const message of history) {
|
|
4239
4256
|
const credit = mandateCredit(message);
|
|
4240
4257
|
if (!credit) continue;
|
|
4258
|
+
const requestSeq = credit.request_seq;
|
|
4259
|
+
const request = history.find((entry) => entry.seq === requestSeq);
|
|
4260
|
+
const ask = request?.from === "provider" && request.type === "payment-request" ? request : void 0;
|
|
4261
|
+
if (Number.isSafeInteger(requestSeq) && requestSeq >= 0 && requestSeq < message.seq) {
|
|
4262
|
+
if (!ask && (request || confirmedMissingAsk(job, message.seq, requestSeq, fullHistoryThrough))) {
|
|
4263
|
+
if (!job.mandateMissingAskSeqs?.includes(requestSeq)) (job.mandateMissingAskSeqs ??= []).push(requestSeq);
|
|
4264
|
+
if (job.paidPaymentRequestSeqs?.includes(requestSeq))
|
|
4265
|
+
job.paidPaymentRequestSeqs = job.paidPaymentRequestSeqs.filter((seq) => seq !== requestSeq);
|
|
4266
|
+
} else {
|
|
4267
|
+
if (ask && job.mandateMissingAskSeqs?.includes(requestSeq))
|
|
4268
|
+
job.mandateMissingAskSeqs = job.mandateMissingAskSeqs.filter((seq) => seq !== requestSeq);
|
|
4269
|
+
recordAnsweredPaymentRequest(job, requestSeq);
|
|
4270
|
+
}
|
|
4271
|
+
}
|
|
4241
4272
|
if (job.pendingCreditPayment?.authorization.request_seq === credit.request_seq)
|
|
4242
4273
|
delete job.pendingCreditPayment;
|
|
4243
4274
|
const booked2 = job.mandatePaymentSeqs?.includes(message.seq) === true;
|
|
4244
|
-
const
|
|
4245
|
-
const msats = ask?.type === "payment-request" ? ask.content.amount_msats : 0;
|
|
4275
|
+
const msats = ask?.content.amount_msats ?? 0;
|
|
4246
4276
|
const valuations = job.mandatePaymentMsats ??= {};
|
|
4247
4277
|
const previous = valuations[message.seq] ?? 0;
|
|
4248
4278
|
if (!booked2 || previous === 0 && msats > 0) {
|
|
@@ -5421,12 +5451,13 @@ async function reconcilePaymentRequestHistory(jobId, requestSeq, history, status
|
|
|
5421
5451
|
);
|
|
5422
5452
|
return false;
|
|
5423
5453
|
}
|
|
5424
|
-
async function settleRecordedPayments(jobId) {
|
|
5454
|
+
async function settleRecordedPayments(jobId, fullHistoryThrough) {
|
|
5425
5455
|
await applySubmissionVerdicts().catch(() => void 0);
|
|
5426
5456
|
const job = loadJob(jobId);
|
|
5427
5457
|
const recorded = job?.mandate || job?.pendingCreditPayment ? loadMessages(jobId) : [];
|
|
5428
|
-
if (job?.mandate) recordMandatePayments(jobId, recorded);
|
|
5429
|
-
const
|
|
5458
|
+
if (job?.mandate) recordMandatePayments(jobId, recorded, fullHistoryThrough);
|
|
5459
|
+
const reconciled = loadJob(jobId);
|
|
5460
|
+
const pending = reconciled?.pendingCreditPayment;
|
|
5430
5461
|
if (pending && recorded.some((message) => {
|
|
5431
5462
|
const credit = message.type === "payment" && message.from === "requester" ? message.content.credit : void 0;
|
|
5432
5463
|
const expected = pending.authorization;
|
|
@@ -5440,7 +5471,11 @@ async function settleRecordedPayments(jobId) {
|
|
|
5440
5471
|
if (held.size === 0) return;
|
|
5441
5472
|
const history = loadMessages(jobId);
|
|
5442
5473
|
const answers = paymentAnswers(history);
|
|
5443
|
-
for (const seq of held)
|
|
5474
|
+
for (const seq of held) {
|
|
5475
|
+
const payments = answers.get(seq);
|
|
5476
|
+
if (payments?.some((payment) => !mandateCredit(payment) || !reconciled?.mandateMissingAskSeqs?.includes(seq)))
|
|
5477
|
+
await settleAnsweredAsk(jobId, seq, history);
|
|
5478
|
+
}
|
|
5444
5479
|
}
|
|
5445
5480
|
function settleUntilMs(jobId, requestSeq, now) {
|
|
5446
5481
|
const startedAt = loadJob(jobId)?.inFlightPaymentRequestStartedAtMs?.[requestSeq];
|
|
@@ -5737,12 +5772,12 @@ async function stablecoinRemaining(rail) {
|
|
|
5737
5772
|
const balance = await Promise.race([
|
|
5738
5773
|
(async () => {
|
|
5739
5774
|
if (rail === "x402") {
|
|
5740
|
-
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-
|
|
5775
|
+
const { loadX402Wallet: loadX402Wallet2 } = await import("./wallet-RIHHIQRK.js");
|
|
5741
5776
|
const wallet = loadX402Wallet2();
|
|
5742
5777
|
if (!wallet) return;
|
|
5743
5778
|
return (await getX402Balance(await ensureAddress(wallet))).usdc;
|
|
5744
5779
|
}
|
|
5745
|
-
const { connectedTempoAccount: connectedTempoAccount2 } = await import("./tempo-wallet-
|
|
5780
|
+
const { connectedTempoAccount: connectedTempoAccount2 } = await import("./tempo-wallet-QOC3BHVE.js");
|
|
5746
5781
|
const account = await connectedTempoAccount2();
|
|
5747
5782
|
if (account) return (await getTempoUsdcBalance(account)).usdc;
|
|
5748
5783
|
})(),
|
|
@@ -9926,6 +9961,9 @@ async function findFundableAlternatives(configured, skip, sats) {
|
|
|
9926
9961
|
}
|
|
9927
9962
|
|
|
9928
9963
|
// src/lib/wallet-agent/recovery.ts
|
|
9964
|
+
import { createHash as createHash4 } from "crypto";
|
|
9965
|
+
import { setTimeout as sleepFor } from "timers/promises";
|
|
9966
|
+
var import_proper_lockfile5 = __toESM(require_proper_lockfile(), 1);
|
|
9929
9967
|
var DEFAULT_SWEEP_QUOTE_RETRY_TIMEOUT_MS = 1e4;
|
|
9930
9968
|
var MINT_QUOTE_EXPIRY_GRACE_MS = 24 * 60 * 60 * 1e3;
|
|
9931
9969
|
async function sweepPendingMints(opts = {}) {
|
|
@@ -9933,27 +9971,17 @@ async function sweepPendingMints(opts = {}) {
|
|
|
9933
9971
|
if (!wallet || wallet.pending_mints.length === 0) {
|
|
9934
9972
|
return { outcomes: [], recovered_proofs: [], still_pending: [], refused: [], errors: [] };
|
|
9935
9973
|
}
|
|
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
9974
|
const outcomes = [];
|
|
9941
9975
|
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
|
-
});
|
|
9976
|
+
const outcome = await reconcilePendingMint(entry, opts);
|
|
9977
|
+
if (outcome.kind === "no_longer_pending") continue;
|
|
9978
|
+
if (outcome.kind === "busy") {
|
|
9979
|
+
outcomes.push({ kind: "error", entry, error: "Another command is checking this mint quote." });
|
|
9980
|
+
} else if (outcome.kind === "error") {
|
|
9981
|
+
outcomes.push({ kind: "error", entry: outcome.entry, error: errorMessage(outcome.cause) });
|
|
9982
|
+
} else {
|
|
9983
|
+
outcomes.push(outcome);
|
|
9984
|
+
}
|
|
9957
9985
|
}
|
|
9958
9986
|
return {
|
|
9959
9987
|
outcomes,
|
|
@@ -9967,7 +9995,69 @@ async function sweepPendingMints(opts = {}) {
|
|
|
9967
9995
|
errors: outcomes.filter((o) => o.kind === "error").map((o) => ({ quote_id: o.entry.quote_id, error: o.error }))
|
|
9968
9996
|
};
|
|
9969
9997
|
}
|
|
9970
|
-
async function
|
|
9998
|
+
async function reconcilePendingMint(entry, opts = {}) {
|
|
9999
|
+
const key = createHash4("sha256").update(JSON.stringify([entry.mint, entry.quote_id])).digest("hex");
|
|
10000
|
+
let release;
|
|
10001
|
+
try {
|
|
10002
|
+
release = await import_proper_lockfile5.default.lock(`${WALLET_FILE}.mint-${key}`, { realpath: false, stale: 3e4, retries: 0 });
|
|
10003
|
+
} catch (err) {
|
|
10004
|
+
if (err.code === "ELOCKED") return { kind: "busy" };
|
|
10005
|
+
return { kind: "error", entry, cause: err };
|
|
10006
|
+
}
|
|
10007
|
+
try {
|
|
10008
|
+
const wallet = loadAgentWallet();
|
|
10009
|
+
const current = wallet?.pending_mints.find((pending) => matchesPendingMint(pending, entry));
|
|
10010
|
+
if (!wallet || !current) return { kind: "no_longer_pending" };
|
|
10011
|
+
const outcome = await processEntry(wallet, current, opts);
|
|
10012
|
+
if (outcome.kind === "minted" || outcome.kind === "restored" || outcome.kind === "already_issued" || outcome.kind === "expired") {
|
|
10013
|
+
const committed = await withMintWriteLock(opts.deadlineMs, () => {
|
|
10014
|
+
const fresh = currentMintWallet(wallet, current);
|
|
10015
|
+
if (!fresh) return false;
|
|
10016
|
+
const proofs = outcome.kind === "minted" || outcome.kind === "restored" ? outcome.proofs : [];
|
|
10017
|
+
saveAgentWallet({
|
|
10018
|
+
...fresh,
|
|
10019
|
+
pending_mints: fresh.pending_mints.filter((pending) => !matchesPendingMint(pending, current)),
|
|
10020
|
+
proofs: [...fresh.proofs, ...proofs]
|
|
10021
|
+
});
|
|
10022
|
+
return true;
|
|
10023
|
+
});
|
|
10024
|
+
if (!committed) return { kind: "no_longer_pending" };
|
|
10025
|
+
}
|
|
10026
|
+
return outcome;
|
|
10027
|
+
} catch (err) {
|
|
10028
|
+
return { kind: "error", entry, cause: err };
|
|
10029
|
+
} finally {
|
|
10030
|
+
await release().catch(() => void 0);
|
|
10031
|
+
}
|
|
10032
|
+
}
|
|
10033
|
+
function matchesPendingMint(left, right) {
|
|
10034
|
+
return left.mint === right.mint && left.quote_id === right.quote_id && left.requested_at === right.requested_at;
|
|
10035
|
+
}
|
|
10036
|
+
function currentMintWallet(wallet, entry) {
|
|
10037
|
+
const fresh = loadAgentWallet();
|
|
10038
|
+
if (fresh?.lock_pubkey === wallet.lock_pubkey && fresh.pending_mints.some((pending) => matchesPendingMint(pending, entry))) {
|
|
10039
|
+
return fresh;
|
|
10040
|
+
}
|
|
10041
|
+
}
|
|
10042
|
+
async function withMintWriteLock(deadlineMs, write) {
|
|
10043
|
+
if (deadlineMs === void 0) return withWalletLock(write);
|
|
10044
|
+
for (; ; ) {
|
|
10045
|
+
try {
|
|
10046
|
+
return await withWalletLock(write, { retries: 0 });
|
|
10047
|
+
} catch (err) {
|
|
10048
|
+
const remaining = deadlineMs - Date.now();
|
|
10049
|
+
if (!(err instanceof DvmError && err.code === "wallet_locked") || remaining <= 0) throw err;
|
|
10050
|
+
await sleepFor(Math.min(remaining, 50));
|
|
10051
|
+
}
|
|
10052
|
+
}
|
|
10053
|
+
}
|
|
10054
|
+
async function processEntry(wallet, entry, opts) {
|
|
10055
|
+
const now = opts.now ?? Date.now;
|
|
10056
|
+
const nowMs = now();
|
|
10057
|
+
if (opts.pollDeadlineMs !== void 0 && nowMs >= opts.pollDeadlineMs) {
|
|
10058
|
+
return { kind: "still_pending", entry };
|
|
10059
|
+
}
|
|
10060
|
+
const getWalletForMint = opts.getWalletForMint ?? getWallet;
|
|
9971
10061
|
let cashuWallet;
|
|
9972
10062
|
let quoteResponse;
|
|
9973
10063
|
try {
|
|
@@ -9978,10 +10068,13 @@ async function processEntry(wallet, entry, nowMs, expiryGraceMs, getWalletForMin
|
|
|
9978
10068
|
return { cashuWallet: candidate, quoteResponse: quote };
|
|
9979
10069
|
},
|
|
9980
10070
|
{
|
|
9981
|
-
deadlineMs:
|
|
10071
|
+
deadlineMs: Math.min(
|
|
10072
|
+
opts.pollDeadlineMs ?? Infinity,
|
|
10073
|
+
nowMs + (opts.quoteRetryTimeoutMs ?? DEFAULT_SWEEP_QUOTE_RETRY_TIMEOUT_MS)
|
|
10074
|
+
),
|
|
9982
10075
|
quoteId: entry.quote_id,
|
|
9983
|
-
now
|
|
9984
|
-
sleep:
|
|
10076
|
+
now,
|
|
10077
|
+
sleep: opts.sleep
|
|
9985
10078
|
}
|
|
9986
10079
|
));
|
|
9987
10080
|
} catch (err) {
|
|
@@ -9994,7 +10087,7 @@ async function processEntry(wallet, entry, nowMs, expiryGraceMs, getWalletForMin
|
|
|
9994
10087
|
() => getWalletForMint(entry.mint)
|
|
9995
10088
|
);
|
|
9996
10089
|
}
|
|
9997
|
-
return { kind: "error", entry,
|
|
10090
|
+
return { kind: "error", entry, cause: err };
|
|
9998
10091
|
}
|
|
9999
10092
|
const state = quoteResponse.state;
|
|
10000
10093
|
if (state === sa.ISSUED) {
|
|
@@ -10013,36 +10106,53 @@ async function processEntry(wallet, entry, nowMs, expiryGraceMs, getWalletForMin
|
|
|
10013
10106
|
}
|
|
10014
10107
|
return { kind: "restored", entry, proofs: restoredProofs };
|
|
10015
10108
|
} catch (err) {
|
|
10016
|
-
return { kind: "error", entry,
|
|
10109
|
+
return { kind: "error", entry, cause: err };
|
|
10017
10110
|
}
|
|
10018
10111
|
}
|
|
10019
10112
|
if (state === sa.PAID) {
|
|
10020
10113
|
try {
|
|
10021
|
-
|
|
10022
|
-
|
|
10023
|
-
|
|
10024
|
-
|
|
10025
|
-
|
|
10114
|
+
let savedMinting = entry.minting;
|
|
10115
|
+
if (savedMinting && cashuWallet.keyChain.getKeysets().some(
|
|
10116
|
+
(keyset) => keyset.id === savedMinting?.keyset_id && keyset.isActive === false
|
|
10117
|
+
)) {
|
|
10118
|
+
await cashuWallet.ensureOperableKeysets([savedMinting.keyset_id]);
|
|
10119
|
+
const proofs2 = await restoreFromMintingState(cashuWallet, savedMinting, wallet.lock_pubkey, entry.mint);
|
|
10120
|
+
if (proofs2.length > 0) return { kind: "restored", entry, proofs: proofs2 };
|
|
10121
|
+
savedMinting = void 0;
|
|
10122
|
+
}
|
|
10123
|
+
const preview = savedMinting ? await cashuWallet.prepareMint(
|
|
10124
|
+
"bolt11",
|
|
10125
|
+
entry.amount_sats,
|
|
10126
|
+
quoteResponse,
|
|
10127
|
+
{ privkey: wallet.lock_privkey, keysetId: savedMinting.keyset_id },
|
|
10128
|
+
{ type: "custom", data: rehydrateOutputData(savedMinting.outputs) }
|
|
10129
|
+
) : await prepareP2PKMint(
|
|
10026
10130
|
cashuWallet,
|
|
10027
10131
|
entry.amount_sats,
|
|
10028
10132
|
quoteResponse,
|
|
10029
10133
|
wallet.lock_privkey,
|
|
10030
10134
|
wallet.lock_pubkey,
|
|
10031
|
-
|
|
10135
|
+
computeSmartDenominations(entry.amount_sats, {
|
|
10136
|
+
maxDenomination: maxKeysetDenomination(cashuWallet),
|
|
10137
|
+
includeTinyTail: false
|
|
10138
|
+
})
|
|
10032
10139
|
);
|
|
10033
|
-
|
|
10034
|
-
|
|
10035
|
-
|
|
10036
|
-
|
|
10037
|
-
|
|
10038
|
-
const
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10042
|
-
|
|
10043
|
-
|
|
10140
|
+
if (!savedMinting) {
|
|
10141
|
+
const minting = {
|
|
10142
|
+
keyset_id: preview.keysetId,
|
|
10143
|
+
outputs: serializeOutputData(preview.outputData)
|
|
10144
|
+
};
|
|
10145
|
+
const saved = await withMintWriteLock(opts.deadlineMs, () => {
|
|
10146
|
+
const fresh = currentMintWallet(wallet, entry);
|
|
10147
|
+
if (!fresh) return false;
|
|
10148
|
+
saveAgentWallet({
|
|
10149
|
+
...fresh,
|
|
10150
|
+
pending_mints: fresh.pending_mints.map((p) => matchesPendingMint(p, entry) ? { ...p, minting } : p)
|
|
10151
|
+
});
|
|
10152
|
+
return true;
|
|
10044
10153
|
});
|
|
10045
|
-
|
|
10154
|
+
if (!saved) return { kind: "no_longer_pending" };
|
|
10155
|
+
}
|
|
10046
10156
|
const proofs = await cashuWallet.completeMint(preview);
|
|
10047
10157
|
const agentProofs = proofs.map((p) => toAgentProof(p, entry.mint, wallet.lock_pubkey));
|
|
10048
10158
|
return { kind: "minted", entry, proofs: agentProofs };
|
|
@@ -10050,7 +10160,7 @@ async function processEntry(wallet, entry, nowMs, expiryGraceMs, getWalletForMin
|
|
|
10050
10160
|
if (mintQuoteRefusal(err) === "expired") {
|
|
10051
10161
|
return { kind: "paid_refused", entry, reason: "quote_expired" };
|
|
10052
10162
|
}
|
|
10053
|
-
return { kind: "error", entry,
|
|
10163
|
+
return { kind: "error", entry, cause: err };
|
|
10054
10164
|
}
|
|
10055
10165
|
}
|
|
10056
10166
|
if (state === "EXPIRED") {
|
|
@@ -10064,7 +10174,7 @@ async function processEntry(wallet, entry, nowMs, expiryGraceMs, getWalletForMin
|
|
|
10064
10174
|
if (nowMs <= expiredAtMs) {
|
|
10065
10175
|
return { kind: "still_pending", entry };
|
|
10066
10176
|
}
|
|
10067
|
-
const dropAfterMs = expiredAtMs + expiryGraceMs;
|
|
10177
|
+
const dropAfterMs = expiredAtMs + (opts.expiryGraceMs ?? MINT_QUOTE_EXPIRY_GRACE_MS);
|
|
10068
10178
|
if (nowMs > dropAfterMs) {
|
|
10069
10179
|
return finalAnswer(wallet, entry, "grace_elapsed", async () => cashuWallet);
|
|
10070
10180
|
}
|
|
@@ -10085,13 +10195,13 @@ async function finalAnswer(wallet, entry, reason, getCashuWallet) {
|
|
|
10085
10195
|
);
|
|
10086
10196
|
if (restored.length > 0) return { kind: "restored", entry, proofs: restored };
|
|
10087
10197
|
} catch (err) {
|
|
10088
|
-
return { kind: "error", entry,
|
|
10198
|
+
return { kind: "error", entry, cause: err };
|
|
10089
10199
|
}
|
|
10090
10200
|
if (reason === "mint_expired") return { kind: "paid_refused", entry, reason: "quote_expired" };
|
|
10091
10201
|
return {
|
|
10092
10202
|
kind: "error",
|
|
10093
10203
|
entry,
|
|
10094
|
-
|
|
10204
|
+
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
10205
|
};
|
|
10096
10206
|
}
|
|
10097
10207
|
var MINT_QUOTE_EXPIRED_CODE = 20007;
|
|
@@ -10111,19 +10221,6 @@ async function restoreFromMintingState(cashuWallet, minting, lockPubkey, mintUrl
|
|
|
10111
10221
|
const proofs = await restoreProofsFromOutputs(cashuWallet, minting.keyset_id, minting.outputs);
|
|
10112
10222
|
return proofs.map((proof) => toAgentProof(proof, mintUrl, lockPubkey));
|
|
10113
10223
|
}
|
|
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
10224
|
function errorMessage(err) {
|
|
10128
10225
|
return err instanceof Error ? err.message : String(err);
|
|
10129
10226
|
}
|
|
@@ -10213,6 +10310,7 @@ export {
|
|
|
10213
10310
|
mandateCredit,
|
|
10214
10311
|
mandateDrawTotal,
|
|
10215
10312
|
mandatePaymentReports,
|
|
10313
|
+
readMandatePaymentReport,
|
|
10216
10314
|
mandatePaymentSummary,
|
|
10217
10315
|
recordMandatePayments,
|
|
10218
10316
|
storedMandateSummary,
|
|
@@ -10355,5 +10453,6 @@ export {
|
|
|
10355
10453
|
describeMintBounds,
|
|
10356
10454
|
MINT_QUOTE_EXPIRY_GRACE_MS,
|
|
10357
10455
|
sweepPendingMints,
|
|
10456
|
+
reconcilePendingMint,
|
|
10358
10457
|
mintQuoteRefusal
|
|
10359
10458
|
};
|
|
@@ -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";
|