@dvmkit/sdk 0.2.0-rc.9 → 0.2.1-rc.9
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/README.md +2 -0
- package/dist/{chunk-V7EVFLAK.js → chunk-2D75MNNG.js} +154 -523
- package/dist/{chunk-BIFLRKMO.js → chunk-2KGG5ORW.js} +1 -1
- package/dist/{chunk-5URG56JJ.js → chunk-A4CM2BD3.js} +18 -2
- package/dist/{chunk-FT6HTUM4.js → chunk-AJNFXR7J.js} +1 -1
- package/dist/{chunk-S3XAHZQY.js → chunk-COYKJRMM.js} +24 -3
- package/dist/{chunk-UP2F5RRT.js → chunk-D7YQYLLM.js} +1 -4
- package/dist/{chunk-OMIQMMME.js → chunk-FPOLJRBF.js} +3 -3
- package/dist/{chunk-QP53RWAD.js → chunk-JAHRF5X3.js} +1 -1
- package/dist/{chunk-PCUQZDZA.js → chunk-JNKQZVZX.js} +95 -321
- package/dist/{chunk-JDT5LCJC.js → chunk-MD3H3BF7.js} +1 -1
- package/dist/{chunk-KSQEFVFJ.js → chunk-MMCE7XSR.js} +1 -1
- package/dist/{chunk-MRAGS5VP.js → chunk-N5B66UOS.js} +4 -16
- package/dist/{chunk-2ATUAUAO.js → chunk-O6D72KYA.js} +2 -2
- package/dist/{chunk-KXCKFIJI.js → chunk-QX52F6IB.js} +1 -1
- package/dist/{chunk-PHHAYRQV.js → chunk-U5VNEALI.js} +23 -10
- package/dist/{chunk-JLXYOV4Y.js → chunk-V5ZRATJH.js} +1 -1
- package/dist/{chunk-6GRIKOFB.js → chunk-VA7GT6C6.js} +5 -16
- package/dist/{chunk-O2X2CCKH.js → chunk-VIVXB4CD.js} +1 -1
- package/dist/{chunk-L67WTZX2.js → chunk-XMDQOXHO.js} +10 -33
- package/dist/{chunk-QT4ONTST.js → chunk-XRLKGCAW.js} +1 -1
- package/dist/{chunk-KMZXTBLA.js → chunk-XZ7LW4S5.js} +0 -1
- package/dist/{chunk-XQXJKJ3P.js → chunk-YO56VCTQ.js} +0 -4
- package/dist/{credit-ledger-5ZEJRI46.js → credit-ledger-MHA652TV.js} +2 -2
- package/dist/{credit-menu-D4Gcdgc4.d.ts → credit-menu-kDA9RVzD.d.ts} +135 -532
- package/dist/{fx-B0SLBe5x.d.ts → fx-DhyT1Cjh.d.ts} +1 -1
- package/dist/index.d.ts +5 -17
- package/dist/internal/caller.d.ts +109 -698
- package/dist/internal/caller.js +10 -12
- package/dist/internal/server.d.ts +17 -42
- package/dist/internal/server.js +15 -15
- package/dist/{job-store-B2uZvga4.d.ts → job-store-D3CcZp_g.d.ts} +6 -10
- package/dist/{lightning-backend-CQBnQgsT.d.ts → lightning-backend-BhsyrBLa.d.ts} +1 -15
- package/dist/{memory-credit-ledger-ZOH6C3N4.js → memory-credit-ledger-BYBATRN3.js} +3 -3
- package/dist/{mpp-secret-state-WNAQQ6K4.js → mpp-secret-state-B5GCILVH.js} +1 -1
- package/dist/{mpp-setup-IOJBF7DB.js → mpp-setup-MPP3ST5X.js} +1 -1
- package/dist/{payout-reporter-5PIRYFVQ.js → payout-reporter-KEMUXEUO.js} +2 -2
- package/dist/{postgres-consumed-credential-store-ISRHBMOU.js → postgres-consumed-credential-store-6N2V5MJN.js} +1 -1
- package/dist/postgres-job-store-MZZZMS2B.js +7 -0
- package/dist/postgres-kv-store-DXGTKXLU.js +7 -0
- package/dist/{postgres-replay-store-IZFLTTAC.js → postgres-replay-store-ZF4JNZOW.js} +2 -2
- package/dist/{processed-payment-store-FIDI3RNH.js → processed-payment-store-GKMAWOM3.js} +2 -2
- package/dist/revenue-reporter-O75BGYFK.js +7 -0
- package/dist/server/index.d.ts +34 -140
- package/dist/server/index.js +52 -124
- package/dist/{step-cache-CXg7ziML.d.ts → step-cache-v2yhyhSZ.d.ts} +359 -1112
- package/dist/{tempo-charge-store-76TDAF34.js → tempo-charge-store-SDTUNTKA.js} +2 -2
- package/dist/{tempo-lifecycle-DXM7QXJQ.js → tempo-lifecycle-G5SB4HFC.js} +4 -4
- package/dist/{tempo-session-store-2JNOKJGX.js → tempo-session-store-WF3VZXNF.js} +2 -2
- package/dist/{tempo-wallet-O67H5M4N.js → tempo-wallet-ZFNUDFVO.js} +1 -1
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/dist/{usd-BNDg1715.d.ts → usd-Cu9G6xv2.d.ts} +1 -1
- package/dist/{x402-7S2EFINY.js → x402-CI6PSHNO.js} +4 -4
- package/package.json +2 -2
- package/dist/postgres-job-store-OGQ6IT4U.js +0 -7
- package/dist/postgres-kv-store-D5E2EZ24.js +0 -7
- package/dist/revenue-reporter-NNCNRY4C.js +0 -7
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { ah as FundingMethod, o as PaymentMethod, bM as CreditLedgerLike, a1 as Message, X as FundingReceipt, bO as CreditSnapshot, Y as JobReceipt, S as SDKJobContext, aw as StepCache, u as ResponseContent, P as PaymentContent, a2 as MessageType, bj as X402Receipt, aE as X402Config, bi as X402ExactVersionSupport, cT as X402SettlementIntent, aq as PaymentRequirementsV2, c1 as CreditLedgerQuerier, cU as X402SettlementCursor, bQ as X402SettlementStatus, cV as X402SettlementWriteOff, bN as X402RefundSettlementGate, cW as X402FacilitatorAuth, cX as X402BatchSettlementConfig, cz as PostgresX402ChannelStorage, cY as X402PayoutObserver, br as MppxServer, ab as CashuMode, cZ as CreditDepositEnqueue, c_ as X402SettlementReconciliationReason, ao as PaymentRequirements, a0 as MppxCredential, bm as CreditDepositPayload, bP as DrawResult, cn as CreditLedgerError, a6 as ReceiptCredit, ae as DrainReceiptEvent, ad as DrainReceipt, K as KVStore, y as SignedRequestAudience, c$ as CreditDrawReleaseEnqueue, cx as JobCostReportPayload, cy as JobTerminalReportPayload, cB as RevenueSkippedNoRailPayload, Z as ZodLike, a as DVMDescriptor, bV as CreditInvoiceRecord, bW as InvoiceSettlement, ch as ClientCompatibilityGate, cf as ClientCompatibility, bu as PayoutReporter, R as ResolvedCreditConfig, g as CreditView } from './step-cache-
|
|
1
|
+
import { ah as FundingMethod, o as PaymentMethod, bM as CreditLedgerLike, a1 as Message, X as FundingReceipt, bO as CreditSnapshot, Y as JobReceipt, S as SDKJobContext, aw as StepCache, u as ResponseContent, P as PaymentContent, a2 as MessageType, bj as X402Receipt, aE as X402Config, bi as X402ExactVersionSupport, cT as X402SettlementIntent, aq as PaymentRequirementsV2, c1 as CreditLedgerQuerier, cU as X402SettlementCursor, bQ as X402SettlementStatus, cV as X402SettlementWriteOff, bN as X402RefundSettlementGate, cW as X402FacilitatorAuth, cX as X402BatchSettlementConfig, cz as PostgresX402ChannelStorage, cY as X402PayoutObserver, br as MppxServer, ab as CashuMode, cZ as CreditDepositEnqueue, c_ as X402SettlementReconciliationReason, ao as PaymentRequirements, a0 as MppxCredential, bm as CreditDepositPayload, bP as DrawResult, cn as CreditLedgerError, a6 as ReceiptCredit, ae as DrainReceiptEvent, ad as DrainReceipt, K as KVStore, y as SignedRequestAudience, c$ as CreditDrawReleaseEnqueue, cx as JobCostReportPayload, cy as JobTerminalReportPayload, cB as RevenueSkippedNoRailPayload, Z as ZodLike, a as DVMDescriptor, bV as CreditInvoiceRecord, bW as InvoiceSettlement, ch as ClientCompatibilityGate, cf as ClientCompatibility, bu as PayoutReporter, R as ResolvedCreditConfig, g as CreditView } from './step-cache-v2yhyhSZ.js';
|
|
2
2
|
import { ProofLike, SerializedDLEQ, Proof } from '@cashu/cashu-ts';
|
|
3
3
|
import { Hono, Context } from 'hono';
|
|
4
4
|
import { Pool } from 'pg';
|
|
5
|
-
import { b as FxRateSnapshot, F as FxFetcher } from './fx-
|
|
6
|
-
import { g as LockPubkey, f as CheckMintHealthOptions, b as LightningBackend, A as AttestationPayload } from './lightning-backend-
|
|
7
|
-
import { T as TopUpCapUnenforcedReason, A as AppendOutgoingOptions, J as JobRecord, b as JobStore } from './job-store-
|
|
5
|
+
import { b as FxRateSnapshot, F as FxFetcher } from './fx-DhyT1Cjh.js';
|
|
6
|
+
import { g as LockPubkey, f as CheckMintHealthOptions, b as LightningBackend, A as AttestationPayload } from './lightning-backend-BhsyrBLa.js';
|
|
7
|
+
import { T as TopUpCapUnenforcedReason, A as AppendOutgoingOptions, J as JobRecord, b as JobStore } from './job-store-D3CcZp_g.js';
|
|
8
8
|
import { Challenge } from 'mppx';
|
|
9
9
|
import { SettleResponse, SupportedResponse } from '@x402/core/types';
|
|
10
10
|
import { Channel, AutoSettlementConfig } from '@x402/evm/batch-settlement/server';
|
|
11
11
|
import { FacilitatorClient } from '@x402/core/server';
|
|
12
12
|
|
|
13
|
-
/** A row in the per-DVM `wallet_accumulator` table. */
|
|
14
13
|
interface WalletAccumulatorRow {
|
|
15
14
|
id: string;
|
|
16
15
|
dvmId: string;
|
|
@@ -36,11 +35,8 @@ interface WalletAccumulatorRow {
|
|
|
36
35
|
* rows created before the column existed.
|
|
37
36
|
*/
|
|
38
37
|
meltQuoteId: string | null;
|
|
39
|
-
/**
|
|
40
|
-
*
|
|
41
|
-
* accepted proof has no `locktime` tag. Drives oldest-first
|
|
42
|
-
* ordering and the future `wallet_accumulator_batch_expiring_soon` monitor.
|
|
43
|
-
*/
|
|
38
|
+
/** NUT-11 locktime at acceptance, in epoch ms; null without a tag.
|
|
39
|
+
* Drives oldest-first ordering and expiring-soon monitoring. */
|
|
44
40
|
tExpire: number | null;
|
|
45
41
|
}
|
|
46
42
|
/**
|
|
@@ -174,7 +170,6 @@ interface DisposableCashuCommit {
|
|
|
174
170
|
commit(requestId: string, proofs: Proof[], account: (ledger: CreditLedgerLike) => Promise<void>): Promise<void>;
|
|
175
171
|
}
|
|
176
172
|
|
|
177
|
-
/** How often the sweep runs, and how long after boot its first pass fires. */
|
|
178
173
|
interface CreditExpirySweepOpts {
|
|
179
174
|
/** Sweep period. Defaults to {@link DEFAULT_SWEEP_INTERVAL_MS}; `0` disables the timer. */
|
|
180
175
|
intervalMs?: number;
|
|
@@ -183,21 +178,17 @@ interface CreditExpirySweepOpts {
|
|
|
183
178
|
* disables the boot pass, leaving only the interval.
|
|
184
179
|
*/
|
|
185
180
|
bootDelayMs?: number;
|
|
186
|
-
/** Credits released per pass. Passed straight to the ledger. */
|
|
187
181
|
limit?: number;
|
|
188
182
|
}
|
|
189
183
|
|
|
190
|
-
/** Promise resolver for a pending client prompt response. */
|
|
191
184
|
interface PromptResolver {
|
|
192
185
|
resolve: (value: ResponseContent) => void;
|
|
193
186
|
reject: (reason: Error) => void;
|
|
194
187
|
}
|
|
195
|
-
/** Promise resolver for a pending client payment. */
|
|
196
188
|
interface PaymentResolver {
|
|
197
189
|
resolve: (value: PaymentContent) => void;
|
|
198
190
|
reject: (reason: Error) => void;
|
|
199
191
|
}
|
|
200
|
-
/** In-memory representation of a running job. */
|
|
201
192
|
interface ServerJob {
|
|
202
193
|
id: string;
|
|
203
194
|
tags: string[];
|
|
@@ -262,17 +253,13 @@ interface ServerJob {
|
|
|
262
253
|
/** Chain transaction returned to callers recovering x402 or Tempo acceptance. */
|
|
263
254
|
paymentTransactionHash?: string;
|
|
264
255
|
/**
|
|
265
|
-
* Rail-native
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
* so multi-credit jobs sum the per-credit native amounts.
|
|
269
|
-
* The upfront credit initializes this value; mid-job credits accumulate same-rail
|
|
270
|
-
* and reset on a cross-rail switch (see `processIncomingPayment`).
|
|
256
|
+
* Rail-native atomic units accumulated across same-rail credits: Tempo and
|
|
257
|
+
* x402 use stablecoin micro-units. A rail switch resets this amount; Cashu
|
|
258
|
+
* revenue is derived from paidMsats instead.
|
|
271
259
|
*/
|
|
272
260
|
nativeAmount?: number;
|
|
273
261
|
/** Native asset tag paired with `nativeAmount`. */
|
|
274
262
|
nativeAsset?: "sats" | "usdc" | "usdc.e" | "usd-cents";
|
|
275
|
-
/** Cashu flow discriminator written into `revenue_events.metadata.cashu_flow`. */
|
|
276
263
|
cashuFlow?: "p2pk_accumulator";
|
|
277
264
|
/**
|
|
278
265
|
* What this job cost the **builder** to serve, in 1e-6 of
|
|
@@ -316,8 +303,8 @@ interface ServerJob {
|
|
|
316
303
|
* nonce issued by `requestPayment` and stamped onto the outbound x402
|
|
317
304
|
* envelope; the caller signs `TransferWithAuthorization` against this exact
|
|
318
305
|
* `bytes32`. Verification rejects an incoming `x402_payment` whose decoded
|
|
319
|
-
* authorization nonce differs
|
|
320
|
-
*
|
|
306
|
+
* authorization nonce differs before crediting the job. Cleared on
|
|
307
|
+
* successful credit.
|
|
321
308
|
*/
|
|
322
309
|
pendingX402Nonce?: string;
|
|
323
310
|
/**
|
|
@@ -415,9 +402,8 @@ interface ServerJob {
|
|
|
415
402
|
/** Unix ms timestamp of last activity (message, yield, terminal). */
|
|
416
403
|
lastActivityAt: number;
|
|
417
404
|
}
|
|
418
|
-
/** Extract the persistent fields from a ServerJob into a JobRecord. */
|
|
419
405
|
declare function toJobRecord(job: ServerJob): JobRecord;
|
|
420
|
-
/**
|
|
406
|
+
/** Restored snapshots receive fresh process-local listeners, cancellation and prompt state. */
|
|
421
407
|
declare function fromJobRecord(record: JobRecord): ServerJob;
|
|
422
408
|
/**
|
|
423
409
|
* Signal cancellation to a running handler. Idempotent — aborting an
|
|
@@ -433,40 +419,14 @@ declare function abortJob(job: ServerJob, reason: string): void;
|
|
|
433
419
|
declare class JobCancelledError extends Error {
|
|
434
420
|
constructor(message?: string);
|
|
435
421
|
}
|
|
436
|
-
/** Append a provider-sent message to the job and notify SSE listeners. */
|
|
437
422
|
declare function providerMessage(job: ServerJob, type: MessageType, content: Record<string, unknown> | object): void;
|
|
438
423
|
declare function isTerminal(status: ServerJob["status"]): boolean;
|
|
439
|
-
/** Check if a message is a yield point (ends the provider's turn). */
|
|
440
424
|
declare function isYieldMessage(msg: Message): boolean;
|
|
441
425
|
|
|
442
|
-
/**
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
* mint on a timer, tracks consecutive failures, and flips a mint to `sick`
|
|
446
|
-
* once the threshold is crossed. The SDK uses the resulting view to:
|
|
447
|
-
*
|
|
448
|
-
* 1. Filter `/v1/info`'s advertised `mints` to currently-healthy ones.
|
|
449
|
-
* 2. Reject new accumulator receives at sick mints before they touch the
|
|
450
|
-
* DB (`cashu_mint_sick` 503 from `verifyAccumulatorReceipt`).
|
|
451
|
-
*
|
|
452
|
-
* Since this tracker is the sole owner of mint health: boot no longer
|
|
453
|
-
* runs a fail-fast check before binding the port. To preserve what boot used
|
|
454
|
-
* to guarantee it (a) treats a mint as healthy only when it's reachable AND
|
|
455
|
-
* NUT-compliant (reproducing `assertNutSupport` via `nutCompliant`), and (b)
|
|
456
|
-
* exposes `initialProbeComplete()` so the paid path holds calls at
|
|
457
|
-
* `mint_health_pending` until the first probe validates ≥1 mint.
|
|
458
|
-
*
|
|
459
|
-
* Existing accumulator entries are not touched — they're P2PK-locked to the
|
|
460
|
-
* original mint and stay put until `dvmctl melt-pending` drains them. The
|
|
461
|
-
* accumulator monitor's `wallet_accumulator_batch_expiring_soon` already
|
|
462
|
-
* pages the builder when a stuck batch nears `t_expire`.
|
|
463
|
-
*
|
|
464
|
-
* In-memory only — no DB persistence. The platform cron keeps the durable
|
|
465
|
-
* record + email path; the SDK only needs fresh in-process state
|
|
466
|
-
* to make routing decisions.
|
|
467
|
-
*/
|
|
426
|
+
/** In-process mint health gates advertising and new receives. Paid calls wait for
|
|
427
|
+
* the first probe; NUT incompatibility fails immediately, transient failures
|
|
428
|
+
* use a consecutive threshold. Existing accumulator proofs remain at their mint. */
|
|
468
429
|
|
|
469
|
-
/** Per-mint runtime view exposed by `snapshot()`. */
|
|
470
430
|
interface MintHealthSnapshot {
|
|
471
431
|
/** Last-observed wall-clock latency of the probe in ms. */
|
|
472
432
|
latencyMs?: number;
|
|
@@ -486,9 +446,7 @@ interface MintHealthSnapshot {
|
|
|
486
446
|
* never resolves without a config/mint change.
|
|
487
447
|
*/
|
|
488
448
|
nutIncompatible?: boolean;
|
|
489
|
-
/** Mint version reported by the last successful probe. */
|
|
490
449
|
version?: string;
|
|
491
|
-
/** Error category from the most recent failed probe. */
|
|
492
450
|
errorCode?: string;
|
|
493
451
|
}
|
|
494
452
|
interface MintHealthTrackerOptions {
|
|
@@ -508,22 +466,9 @@ interface MintHealthTrackerOptions {
|
|
|
508
466
|
consecutiveFailuresToSick?: number;
|
|
509
467
|
fetchImpl?: typeof fetch;
|
|
510
468
|
now?: () => number;
|
|
511
|
-
/**
|
|
512
|
-
* Per-probe timeout / retry / backoff, forwarded to {@link checkMintHealth}.
|
|
513
|
-
* Defaults to that function's own defaults — 3 attempts with `[200, 500]`
|
|
514
|
-
* backoff, which is what a real tick should do.
|
|
515
|
-
*
|
|
516
|
-
* Tests that drive several failing ticks set `backoffMs: [0]`: a failing
|
|
517
|
-
* probe otherwise costs 700ms of real `setTimeout`, and four of them put a
|
|
518
|
-
* unit test within a loaded CI runner's reach of the 5s default timeout.
|
|
519
|
-
* `fetchImpl` is set on the tracker, not here.
|
|
520
|
-
*/
|
|
469
|
+
/** Forwarded to checkMintHealth; fetchImpl is supplied on the tracker. */
|
|
521
470
|
probe?: Omit<CheckMintHealthOptions, "fetchImpl">;
|
|
522
471
|
}
|
|
523
|
-
/**
|
|
524
|
-
* Runtime mint-health tracker. Owns its own timer; `start()` runs an initial
|
|
525
|
-
* probe immediately so the first received call doesn't see a stale snapshot.
|
|
526
|
-
*/
|
|
527
472
|
declare class MintHealthTracker {
|
|
528
473
|
private readonly mints;
|
|
529
474
|
private readonly tickIntervalMs;
|
|
@@ -569,60 +514,31 @@ declare class MintHealthTracker {
|
|
|
569
514
|
* where a merely-flapping mint is still published.
|
|
570
515
|
*/
|
|
571
516
|
isNutIncompatible(mintUrl: string): boolean;
|
|
572
|
-
/** Plain-object snapshot keyed by mint URL — for tests + observability. */
|
|
573
517
|
snapshot(): Record<string, MintHealthSnapshot>;
|
|
574
518
|
private applyResult;
|
|
575
|
-
/**
|
|
576
|
-
* One-shot structured summary emitted after the first probe tick. Replaces
|
|
577
|
-
* the boot check's per-mint `cashu_mint_startup_health` lines and surfaces an
|
|
578
|
-
* all-mints-unhealthy warning — the operator alert that the Fly restart-loop
|
|
579
|
-
* used to be before boot stopped refusing to start.
|
|
580
|
-
*/
|
|
519
|
+
/** One boot summary, including an all-unhealthy warning. */
|
|
581
520
|
private logBootHealth;
|
|
582
521
|
}
|
|
583
522
|
|
|
584
523
|
/**
|
|
585
|
-
* Credit fields
|
|
524
|
+
* Credit fields belong to the raw signed body. The funding commitment hashes the header
|
|
525
|
+
* artifact, binding money outside that body to its intended credit.
|
|
586
526
|
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
* - `credit_id` — the credit to draw against.
|
|
592
|
-
* - `draw_id` — client-generated draw id; the ledger's idempotency key.
|
|
593
|
-
* - `fund` — optional `{ amount_micro, commitment }` funding commitment:
|
|
594
|
-
* present iff a funding artifact (X-Cashu / X-PAYMENT / mpp credential)
|
|
595
|
-
* rides the same request. `commitment` is the SHA-256 hex over the raw
|
|
596
|
-
* artifact bytes, binding the header-borne proof — which sits OUTSIDE the
|
|
597
|
-
* signed body — to the credit its sender intended (the funding-commitment rule).
|
|
598
|
-
*
|
|
599
|
-
* These are envelope-level fields, not capability input: **the SDK** removes
|
|
600
|
-
* them before any builder-owned schema parses ({@link stripCreditEnvelope} in
|
|
601
|
-
* `JobManager.parseInput` and on the quote path; {@link
|
|
602
|
-
* creditEnvelopeIgnoreFields} feeding the auth verifier's own schema check), so
|
|
603
|
-
* handlers never see them and a top-level `.strict()` capability schema is
|
|
604
|
-
* fine. Relying on Zod's default strip mode instead was the trap:
|
|
605
|
-
* `.strict()` rejects unknown keys, so an explicit draw 400'd at parse before
|
|
606
|
-
* the envelope was ever extracted.
|
|
607
|
-
*
|
|
608
|
-
* The strip never touches the canonical signing bytes. Every auth call site
|
|
609
|
-
* verifies the raw wire body (`signedRequestInput`), so the credit
|
|
610
|
-
* fields are in the verified bytes because they were never taken out of them —
|
|
611
|
-
* the strip is only ever applied to what a schema is about to parse.
|
|
527
|
+
* Schema projection strips undeclared protocol keys before builder input parsing, without
|
|
528
|
+
* changing canonical signing bytes. Signature verification must use the original wire body; a
|
|
529
|
+
* parsed projection may omit credit fields.
|
|
612
530
|
*/
|
|
613
531
|
interface CreditEnvelope {
|
|
614
532
|
creditId: string;
|
|
615
533
|
drawId: string;
|
|
616
534
|
fund?: CreditFundCommitment;
|
|
617
535
|
}
|
|
618
|
-
/** The signed funding commitment for a fund-and-draw request. */
|
|
619
536
|
interface CreditFundCommitment {
|
|
620
537
|
/** Funding amount in 1e-6 units of the credit's currency. */
|
|
621
538
|
amountMicro: number;
|
|
622
539
|
/** SHA-256 hex over the raw funding artifact bytes. */
|
|
623
540
|
commitment: string;
|
|
624
541
|
}
|
|
625
|
-
/** Wire keys reserved for the credit envelope inside `body.data`. */
|
|
626
542
|
declare const CREDIT_ENVELOPE_KEYS: readonly ["credit_id", "draw_id", "fund"];
|
|
627
543
|
/**
|
|
628
544
|
* Thrown by {@link extractCreditEnvelope} on a structurally invalid credit
|
|
@@ -640,28 +556,16 @@ declare class CreditEnvelopeError extends Error {
|
|
|
640
556
|
*/
|
|
641
557
|
declare function extractCreditEnvelope(data: unknown): CreditEnvelope | undefined;
|
|
642
558
|
/**
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
647
|
-
* one exception this exists for is `/v1/credit`'s own `CREDIT_REQUEST_SCHEMA`,
|
|
648
|
-
* where `credit_id` and `fund` are real fields on a different wire shape and
|
|
649
|
-
* removing them would empty the request. It is not an escape hatch for a
|
|
650
|
-
* capability: the three names stay reserved on `body.data`, and declaring one
|
|
651
|
-
* doesn't win a builder their own value — `app.ts` runs
|
|
652
|
-
* {@link extractCreditEnvelope} over the raw body on every submit, so a
|
|
653
|
-
* capability that declares `fund` answers `invalid_credit_fields` instead.
|
|
559
|
+
* Return protocol keys not declared by the schema. Schema-declared keys remain available,
|
|
560
|
+
* including /v1/credit’s differently shaped credit_id and fund fields. Submit separately
|
|
561
|
+
* extracts and validates the credit envelope from raw body.data; declaring a key does not
|
|
562
|
+
* bypass that validation.
|
|
654
563
|
*/
|
|
655
564
|
declare function creditEnvelopeIgnoreFields(schema: unknown): readonly string[];
|
|
656
565
|
/**
|
|
657
|
-
* Remove
|
|
658
|
-
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
661
|
-
* Returns `data` unchanged when it isn't a plain object or carries none of the
|
|
662
|
-
* removable keys, so the ordinary no-credit request allocates nothing. Never
|
|
663
|
-
* use the result to derive canonical signing bytes: those cover the wire form,
|
|
664
|
-
* credit fields included (`signedRequestInput`).
|
|
566
|
+
* Remove undeclared credit keys before schema parsing. Preserve nonobject/array inputs and
|
|
567
|
+
* objects with no removable keys. Never derive signing bytes from this projection; signatures
|
|
568
|
+
* cover the raw wire body.
|
|
665
569
|
*/
|
|
666
570
|
declare function stripCreditEnvelope(schema: unknown, data: unknown): unknown;
|
|
667
571
|
|
|
@@ -904,18 +808,8 @@ declare function derivedFundCreditId(callerPubkey: string, fundId: string): stri
|
|
|
904
808
|
declare function drawSettlementRef(dvmId: string, creditId: string, drawId: string): string;
|
|
905
809
|
|
|
906
810
|
/**
|
|
907
|
-
*
|
|
908
|
-
*
|
|
909
|
-
* commit point of their own — the money moves at the facilitator / the payer's
|
|
910
|
-
* mpp server — so the marker row, inserted in the SAME transaction as
|
|
911
|
-
* `CreditLedger.fund` + `draw`, is what makes a crash-replayed credential
|
|
912
|
-
* unable to fund twice: the second attempt collides on the primary key and
|
|
913
|
-
* surfaces as {@link ProcessedPaymentReplayError}, which the verifier routes
|
|
914
|
-
* into the recovery gates instead of a second fund.
|
|
915
|
-
*
|
|
916
|
-
* The Cashu rail does not use this store — its accumulator insert is already
|
|
917
|
-
* the durable commit point, and its replay key (the `X-Cashu-Request-Id`
|
|
918
|
-
* regime) must stay exactly as-is (dual-idempotency rule, the signed credit contract).
|
|
811
|
+
* x402/Tempo marker, funding and draw commit in one transaction so a retry
|
|
812
|
+
* cannot fund twice. Cashu retains its separate accumulator replay regime.
|
|
919
813
|
*/
|
|
920
814
|
interface ProcessedPaymentStore {
|
|
921
815
|
/**
|
|
@@ -941,11 +835,8 @@ interface ProcessedPaymentStore {
|
|
|
941
835
|
paymentId: string;
|
|
942
836
|
}): Promise<ProcessedPaymentRecord | undefined>;
|
|
943
837
|
/**
|
|
944
|
-
*
|
|
945
|
-
*
|
|
946
|
-
* the handle through to `record` / `CreditLedger.fund` / `draw` so all
|
|
947
|
-
* three commit atomically. The memory implementation invokes `fn` with no
|
|
948
|
-
* handle — its operations are synchronous-atomic in-process.
|
|
838
|
+
* Postgres supplies a transaction for marker, fund and draw; failure rolls it
|
|
839
|
+
* back. Memory invokes fn without a transactional handle or rollback.
|
|
949
840
|
*/
|
|
950
841
|
withTx<T>(fn: (tx?: ProcessedPaymentQuerier) => Promise<T>): Promise<T>;
|
|
951
842
|
}
|
|
@@ -1024,7 +915,6 @@ declare class MemoryProcessedPaymentStore implements ProcessedPaymentStore {
|
|
|
1024
915
|
*/
|
|
1025
916
|
type AccumulatorRejectionCode = "missing_request_id" | "missing_lock_pubkey" | "not_p2pk_locked" | "wrong_lock_pubkey" | "proof_not_unspent" | "proof_pending" | "replay_rejected" | "mint_unreachable" | "invalid_token";
|
|
1026
917
|
|
|
1027
|
-
/** Durable state of one exact x402 authorization. */
|
|
1028
918
|
type X402ExactSettlementStatus = "prepared" | "submitting" | "settled" | "local_committed" | "ambiguous" | "rejected" | "complete";
|
|
1029
919
|
/** Serializable local economic effect that follows an exact settlement. */
|
|
1030
920
|
interface X402ExactSettlementEffect {
|
|
@@ -1073,7 +963,6 @@ interface X402ExactAuthorizationFacts {
|
|
|
1073
963
|
nonce: string;
|
|
1074
964
|
fingerprint: string;
|
|
1075
965
|
}
|
|
1076
|
-
/** One durable exact-x402 settlement intent. */
|
|
1077
966
|
interface X402ExactSettlementIntent extends X402ExactAuthorizationFacts {
|
|
1078
967
|
id: string;
|
|
1079
968
|
dvmId: string;
|
|
@@ -1128,11 +1017,9 @@ interface X402ExactSettlementStore {
|
|
|
1128
1017
|
}): Promise<X402ExactSettlementIntent[]>;
|
|
1129
1018
|
attempts(dvmId: string, intentId: string): Promise<X402ExactSettlementAttempt[]>;
|
|
1130
1019
|
}
|
|
1131
|
-
/** Postgres-backed exact settlement intent store. */
|
|
1132
1020
|
declare class PostgresX402ExactSettlementStore implements X402ExactSettlementStore {
|
|
1133
1021
|
private readonly pool;
|
|
1134
1022
|
constructor(pool: Pick<Pool, "query" | "connect">);
|
|
1135
|
-
/** Create the exact settlement tables. */
|
|
1136
1023
|
init(): Promise<void>;
|
|
1137
1024
|
prepare(intent: Omit<X402ExactSettlementIntent, "status" | "createdAt" | "updatedAt" | "resolvedAt">): Promise<X402ExactSettlementIntent>;
|
|
1138
1025
|
get(dvmId: string, intentId: string): Promise<X402ExactSettlementIntent | undefined>;
|
|
@@ -1241,7 +1128,6 @@ type X402ExactAcceptance<T> = {
|
|
|
1241
1128
|
intentId: string;
|
|
1242
1129
|
reason: string;
|
|
1243
1130
|
};
|
|
1244
|
-
/** Dependencies for the durable exact x402 settlement coordinator. */
|
|
1245
1131
|
interface X402ExactSettlementServerOpts {
|
|
1246
1132
|
store: X402ExactSettlementStore;
|
|
1247
1133
|
evidence?: X402ExactSettlementEvidenceReader;
|
|
@@ -1264,13 +1150,11 @@ declare class X402ExactSettlementServer {
|
|
|
1264
1150
|
effect?: X402ExactSettlementEffect;
|
|
1265
1151
|
commit: (receipt: X402Receipt, tx?: ProcessedPaymentQuerier, effect?: X402ExactSettlementEffect) => Promise<T>;
|
|
1266
1152
|
}): Promise<X402ExactAcceptance<T>>;
|
|
1267
|
-
/** Read the operator queue. */
|
|
1268
1153
|
list(args: {
|
|
1269
1154
|
dvmId: string;
|
|
1270
1155
|
limit: number;
|
|
1271
1156
|
includeResolved?: boolean;
|
|
1272
1157
|
}): Promise<X402ExactSettlementIntent[]>;
|
|
1273
|
-
/** Read durable attempt evidence for one intent. */
|
|
1274
1158
|
attempts(dvmId: string, intentId: string): Promise<X402ExactSettlementAttempt[]>;
|
|
1275
1159
|
/** Reconcile and finish one intent from chain evidence. */
|
|
1276
1160
|
reconcile(dvmId: string, intentId: string): Promise<{
|
|
@@ -1614,7 +1498,6 @@ interface CreateX402BatchSettlementServerOpts {
|
|
|
1614
1498
|
*/
|
|
1615
1499
|
declare function createX402BatchSettlementServer(opts: CreateX402BatchSettlementServerOpts): Promise<X402BatchSettlementServer>;
|
|
1616
1500
|
|
|
1617
|
-
/** Payment state from upfront token verification. */
|
|
1618
1501
|
interface PaymentInfo {
|
|
1619
1502
|
/**
|
|
1620
1503
|
* Rail value this payment contributes to the job, in millisatoshis.
|
|
@@ -1647,12 +1530,10 @@ interface PaymentInfo {
|
|
|
1647
1530
|
/** Chain transaction returned to a caller recovering this accepted request. */
|
|
1648
1531
|
paymentTransactionHash?: string;
|
|
1649
1532
|
/**
|
|
1650
|
-
*
|
|
1651
|
-
*
|
|
1652
|
-
* `paidMsats / 1000` derivation in the platform callback covers it.
|
|
1533
|
+
* Stablecoin micro-units for Tempo and x402. Cashu leaves this unset; its revenue is derived
|
|
1534
|
+
* from paidMsats.
|
|
1653
1535
|
*/
|
|
1654
1536
|
nativeAmount?: number;
|
|
1655
|
-
/** Native asset tag matching `revenue_events.native_asset`. */
|
|
1656
1537
|
nativeAsset?: "sats" | "usdc" | "usdc.e" | "usd-cents";
|
|
1657
1538
|
/**
|
|
1658
1539
|
* Discriminator written into `revenue_events.metadata.cashu_flow` so ops
|
|
@@ -1801,7 +1682,6 @@ interface UpfrontPaymentOpts {
|
|
|
1801
1682
|
* no per-process replay protection beyond mppx's own expiry check.
|
|
1802
1683
|
*/
|
|
1803
1684
|
consumedCredentialStore?: ConsumedCredentialStore;
|
|
1804
|
-
/** Cashu receive mode. Routes the receive path. */
|
|
1805
1685
|
cashuMode?: CashuMode;
|
|
1806
1686
|
/** Per-DVM Postgres pool — required for the `p2pk-accumulator` path. */
|
|
1807
1687
|
accumulatorDb?: AccumulatorPool;
|
|
@@ -1834,12 +1714,9 @@ interface UpfrontPaymentOpts {
|
|
|
1834
1714
|
*/
|
|
1835
1715
|
fxFetcher?: FxFetcher;
|
|
1836
1716
|
/**
|
|
1837
|
-
*
|
|
1838
|
-
*
|
|
1839
|
-
*
|
|
1840
|
-
* when the price can't be fiat-denominated), the payment is accepted with
|
|
1841
|
-
* legacy semantics and a structured warning — money is never refused
|
|
1842
|
-
* because the ledger is unavailable.
|
|
1717
|
+
* Attached payments fund and draw an implicit per-job credit atomically with
|
|
1718
|
+
* rail accounting. Omitting the ledger uses the legacy ledgerless path;
|
|
1719
|
+
* a configured ledger requires a fiat-denominated price before acceptance.
|
|
1843
1720
|
*/
|
|
1844
1721
|
creditLedger?: CreditLedgerLike;
|
|
1845
1722
|
/**
|
|
@@ -1917,7 +1794,6 @@ interface FundOnlyRequest {
|
|
|
1917
1794
|
*/
|
|
1918
1795
|
commitment: string;
|
|
1919
1796
|
}
|
|
1920
|
-
/** Structured payment validation error detail carried through `PaymentValidationError`. */
|
|
1921
1797
|
interface PaymentErrorDetail {
|
|
1922
1798
|
body: Record<string, unknown>;
|
|
1923
1799
|
status: number;
|
|
@@ -2065,7 +1941,6 @@ declare function hasPaymentProof(content: Record<string, unknown>): boolean;
|
|
|
2065
1941
|
* surfaces always keep charge.
|
|
2066
1942
|
*/
|
|
2067
1943
|
declare function issueUpfrontChallenges(mpp: MppxServer, requiredMsats: number, resourcePath: string, btcUsdRate: number, sessionIssuable?: boolean, allowOneShotStablecoin?: unknown, priceFiat?: PriceFiat): Promise<Challenge.Challenge[]>;
|
|
2068
|
-
/** Verify an upfront payment on job submission (Cashu, x402, or MPP). */
|
|
2069
1944
|
declare function verifyUpfrontPayment(opts: UpfrontPaymentOpts): Promise<PaymentResult>;
|
|
2070
1945
|
/**
|
|
2071
1946
|
* A management credential signed for a channel other than the one required
|
|
@@ -2117,25 +1992,9 @@ declare function verifyTempoSessionManagementCredential(args: {
|
|
|
2117
1992
|
*/
|
|
2118
1993
|
type PaymentErrorCode = "payment_invalid" | "x402_not_offered" | "x402_settlement_ambiguous" | "cashu_unavailable" | "cashu_not_p2pk_locked" | "mint_health_pending" | "cashu_mint_sick" | "payment_insufficient" | "payment_unapplied" | "insufficient_credit" | "credit_expired" | "credit_unbacked" | "credit_not_found" | "tempo_channel_closing" | "settlement_pending" | "draw_conflict" | "funding_commitment_mismatch" | "credit_not_supported" | "one_shot_credit_not_supported" | "credit_below_min" | "below_rail_minimum" | "credit_over_max" | "credit_id_unavailable" | "nothing_to_drain" | "drain_below_dust" | "drain_not_found" | "drain_conflict" | "drain_method_unsupported" | "tempo_channel_exit_required" | "x402_settlement_submission_failed" | X402SettlementReconciliationReason | "lightning_settlement_pending" | "lightning_invoice_expired" | "lightning_unavailable" | AccumulatorRejectionCode;
|
|
2119
1994
|
/**
|
|
2120
|
-
*
|
|
2121
|
-
*
|
|
2122
|
-
*
|
|
2123
|
-
* human and branches retries on. `display`, `hint`, and `retryable` default from
|
|
2124
|
-
* {@link PAYMENT_ERROR_COPY} keyed on `code`; `message` is the per-site operator
|
|
2125
|
-
* log line. The prose fields can be overridden for dynamic cases (e.g.
|
|
2126
|
-
* `cashu_mint_sick` naming the currently-healthy mints, or a retained deposit
|
|
2127
|
-
* distinguishing "not spent" from "not paid"). `extra` carries a code's ad-hoc
|
|
2128
|
-
* fields (`mints`, `required_msats`, `received_msats`) and is merged last so
|
|
2129
|
-
* those are preserved.
|
|
2130
|
-
*
|
|
2131
|
-
* `retryable` overrides on the same terms, and for the same reason: a code that
|
|
2132
|
-
* covers more than one refusal can be terminal for one of them and clear on its
|
|
2133
|
-
* own for another — `drain_conflict` is both. Override it only
|
|
2134
|
-
* alongside the `hint`, since the two are one answer: a hint that says retry
|
|
2135
|
-
* under `retryable: false` is the disagreement this exists to prevent.
|
|
2136
|
-
*
|
|
2137
|
-
* Upstream of {@link buildPaymentErrorResponse}, which serializes the body onto
|
|
2138
|
-
* a `Response` — this shapes it.
|
|
1995
|
+
* Per-code display, hint and retryability may be overridden for a particular
|
|
1996
|
+
* refusal. Keep the hint and retry decision consistent. Extra fields merge
|
|
1997
|
+
* last, so callers can supply code-specific amounts and alternatives.
|
|
2139
1998
|
*/
|
|
2140
1999
|
declare function paymentErrorBody(code: PaymentErrorCode, opts: {
|
|
2141
2000
|
message: string;
|
|
@@ -2216,14 +2075,9 @@ interface IncomingPaymentOpts {
|
|
|
2216
2075
|
creditTtlMs?: number;
|
|
2217
2076
|
}
|
|
2218
2077
|
/**
|
|
2219
|
-
*
|
|
2220
|
-
*
|
|
2221
|
-
*
|
|
2222
|
-
* inside Tx C so verify+credit land atomically.
|
|
2223
|
-
*
|
|
2224
|
-
* `snapshot` carries the read-only job state the verification path needs
|
|
2225
|
-
* (`pendingPaymentMsats` for amount checks, the MPP/x402 per-job bindings,
|
|
2226
|
-
* `paymentRail` for the same-rail accumulator check).
|
|
2078
|
+
* Job state read by incoming-payment verification; the job itself is not mutated. Rail
|
|
2079
|
+
* acceptance and ledger funding can still occur before the caller applies the returned credit in
|
|
2080
|
+
* Tx C.
|
|
2227
2081
|
*/
|
|
2228
2082
|
interface VerifyIncomingSnapshot {
|
|
2229
2083
|
pendingPaymentMsats?: number;
|
|
@@ -2326,16 +2180,8 @@ declare function verifyIncomingPayment(body: {
|
|
|
2326
2180
|
*/
|
|
2327
2181
|
declare function applyPaymentInfoToJob(job: ServerJob, info: VerifiedIncomingPayment): void;
|
|
2328
2182
|
/**
|
|
2329
|
-
*
|
|
2330
|
-
*
|
|
2331
|
-
* **The isolate-runtime path, and deliberately ledger-less** (the isolate-runtime rule). Its
|
|
2332
|
-
* only caller is `platform/isolate-job-manager.ts`; isolate DVMs have no
|
|
2333
|
-
* Postgres of their own, so they run implicit N=1 with today's semantics
|
|
2334
|
-
* preserved and never advertise credit. The credits-carrying mid-job path is
|
|
2335
|
-
* {@link verifyIncomingPayment} + `JobManager.processPayment` (Tx C), where
|
|
2336
|
-
* wired `fund` + `growDraw`. Wiring a ledger here would need a
|
|
2337
|
-
* platform-side ledger leg with its own funding-atomicity and receipt-key
|
|
2338
|
-
* story — the trust-surface expansion exists to decide.
|
|
2183
|
+
* Legacy ledgerless payment path. Mutates the job on acceptance; durable credit hosts use
|
|
2184
|
+
* verifyIncomingPayment and apply its result in Tx C.
|
|
2339
2185
|
*/
|
|
2340
2186
|
declare function processIncomingPayment(job: ServerJob, body: {
|
|
2341
2187
|
type: MessageType;
|
|
@@ -2414,14 +2260,8 @@ interface ReceiptIssuerOpts {
|
|
|
2414
2260
|
dvmId: string;
|
|
2415
2261
|
}
|
|
2416
2262
|
/**
|
|
2417
|
-
*
|
|
2418
|
-
*
|
|
2419
|
-
* Constructed only when a receipt key is wired, so the presence of an issuer
|
|
2420
|
-
* *is* the "this DVM emits receipts" signal that `/v1/info` advertises. Pure:
|
|
2421
|
-
* it holds the key and the slug and turns a terminal `JobRecord` plus an
|
|
2422
|
-
* allocated sequence number into signed bytes — sequence allocation and
|
|
2423
|
-
* persistence belong to the store, which is what makes issuance idempotent
|
|
2424
|
-
* across machines.
|
|
2263
|
+
* An issuer indicates receipt support. Sequence allocation and write-once
|
|
2264
|
+
* persistence belong to the store; signing alone does not provide idempotency.
|
|
2425
2265
|
*/
|
|
2426
2266
|
declare class ReceiptIssuer {
|
|
2427
2267
|
/** x-only pubkey this issuer signs under; the attested `receipt_pubkey`. */
|
|
@@ -2431,20 +2271,10 @@ declare class ReceiptIssuer {
|
|
|
2431
2271
|
private readonly dvmId;
|
|
2432
2272
|
constructor(opts: ReceiptIssuerOpts);
|
|
2433
2273
|
/**
|
|
2434
|
-
*
|
|
2435
|
-
*
|
|
2436
|
-
*
|
|
2437
|
-
*
|
|
2438
|
-
* sequence number and still attest an outcome. Whether feedback is
|
|
2439
|
-
* paid-only is the feedback layer's call, not this one's.
|
|
2440
|
-
*
|
|
2441
|
-
* Timing and attribution come from the committed terminal row, not signing
|
|
2442
|
-
* time or handler input. Legacy rows without those durable inputs omit the
|
|
2443
|
-
* optional blocks rather than inventing historical evidence.
|
|
2444
|
-
*
|
|
2445
|
-
* `credit` is the resolved draw block — present on every job
|
|
2446
|
-
* whose payment funded/drew the ledger, absent otherwise. Signature-
|
|
2447
|
-
* compatible either way: `canonicalize` omits absent keys.
|
|
2274
|
+
* seq is store-allocated; issuedAt is epoch seconds. Free jobs also consume a
|
|
2275
|
+
* sequence and attest their outcome. Timing/attribution comes from the committed
|
|
2276
|
+
* terminal row; legacy rows omit unknown historical fields. credit is present
|
|
2277
|
+
* only for a resolved ledger draw.
|
|
2448
2278
|
*/
|
|
2449
2279
|
issue(record: JobRecord, seq: number, issuedAt?: number, credit?: ReceiptCredit): JobReceipt;
|
|
2450
2280
|
/**
|
|
@@ -2544,9 +2374,9 @@ interface JobManagerOpts {
|
|
|
2544
2374
|
env: Record<string, string>;
|
|
2545
2375
|
store: KVStore;
|
|
2546
2376
|
mints?: string[];
|
|
2547
|
-
/**
|
|
2377
|
+
/** Durable in production; defaults to memory only in development/test mode. */
|
|
2548
2378
|
jobStore?: JobStore;
|
|
2549
|
-
/**
|
|
2379
|
+
/** Skips payment only when no payment rail is configured. Wired rails still verify. */
|
|
2550
2380
|
devMode?: boolean;
|
|
2551
2381
|
/** Payment methods this DVM accepts. Default: derived by the server from configured rails. */
|
|
2552
2382
|
paymentMethods?: PaymentMethod[];
|
|
@@ -2555,9 +2385,7 @@ interface JobManagerOpts {
|
|
|
2555
2385
|
x402ExactSettlement?: X402ExactSettlementServer;
|
|
2556
2386
|
/** Live facilitator capabilities for version-specific mid-job payment handling. */
|
|
2557
2387
|
x402FacilitatorHealth?: X402FacilitatorHealthLike;
|
|
2558
|
-
/** MPP multi-rail payment handle (built via `createMppFromOpts`). */
|
|
2559
2388
|
mpp?: MppxServer;
|
|
2560
|
-
/** Cashu receive mode. */
|
|
2561
2389
|
cashuMode?: CashuMode;
|
|
2562
2390
|
/** Builder's NUT-11 P2PK lock pubkey. Required for accumulator mode. */
|
|
2563
2391
|
lockPubkey?: string;
|
|
@@ -2693,16 +2521,10 @@ interface JobManagerOpts {
|
|
|
2693
2521
|
*/
|
|
2694
2522
|
onRevenueSkippedNoRail?: (info: RevenueSkippedNoRailPayload) => void | Promise<void>;
|
|
2695
2523
|
/**
|
|
2696
|
-
*
|
|
2697
|
-
*
|
|
2698
|
-
*
|
|
2699
|
-
*
|
|
2700
|
-
* a worker crash, OOM, or silent `messageAppender` failure. Default:
|
|
2701
|
-
* `2 × descriptor.idleTimeout + STALE_JOB_WATCHDOG_HEADROOM_MS`, which keeps
|
|
2702
|
-
* the default beyond scrape's `JOB_TIMEOUT_MS`.
|
|
2703
|
-
* Builders whose per-handler wall-clock bound exceeds 90s must override
|
|
2704
|
-
* this — otherwise the watchdog fires on a legitimate in-flight handler.
|
|
2705
|
-
* Set to `0` to disable (test seam).
|
|
2524
|
+
* Awaiting-input age in milliseconds before cancellation. Defaults to
|
|
2525
|
+
* twice descriptor.idleTimeout (seconds), converted to milliseconds, plus
|
|
2526
|
+
* STALE_JOB_WATCHDOG_HEADROOM_MS. Set to 0 to disable this arm; processing
|
|
2527
|
+
* jobs use processingWatchdogMs.
|
|
2706
2528
|
*/
|
|
2707
2529
|
staleJobTimeoutMs?: number;
|
|
2708
2530
|
/**
|
|
@@ -2907,9 +2729,7 @@ declare class JobManager<State, InputSchema extends ZodLike | undefined> {
|
|
|
2907
2729
|
* never promise something `issueReceipt` silently declines to do.
|
|
2908
2730
|
*/
|
|
2909
2731
|
get receiptsEnabled(): boolean;
|
|
2910
|
-
/** True when the named capability exists on this descriptor. */
|
|
2911
2732
|
hasCapability(name: string): boolean;
|
|
2912
|
-
/** Names of every capability this descriptor exposes — used for error envelopes. */
|
|
2913
2733
|
capabilityNames(): string[];
|
|
2914
2734
|
/**
|
|
2915
2735
|
* Resolve a capability's static `price` to msats.
|
|
@@ -3101,9 +2921,7 @@ declare class JobManager<State, InputSchema extends ZodLike | undefined> {
|
|
|
3101
2921
|
* `artifact`'s NOTIFY silently drops the artifact.
|
|
3102
2922
|
*/
|
|
3103
2923
|
private wireMessageAppender;
|
|
3104
|
-
/** Start (or restart) the idle timer for a job. */
|
|
3105
2924
|
startIdleTimer(job: ServerJob): void;
|
|
3106
|
-
/** Clear the idle timer for a job. */
|
|
3107
2925
|
clearIdleTimer(id: string): void;
|
|
3108
2926
|
/** Cancel a job due to idle timeout. Exposed for the reactivation path's idle-expiry guard. */
|
|
3109
2927
|
cancelJobIdle(job: ServerJob): Promise<void>;
|
|
@@ -3609,7 +3427,6 @@ declare class JobManager<State, InputSchema extends ZodLike | undefined> {
|
|
|
3609
3427
|
private reportTerminalJob;
|
|
3610
3428
|
private terminalReportRecoveryCursor?;
|
|
3611
3429
|
private recoverTerminalReports;
|
|
3612
|
-
/** Handle job reaching terminal state (completed, failed, cancelled). */
|
|
3613
3430
|
private handleJobTerminal;
|
|
3614
3431
|
/**
|
|
3615
3432
|
* Re-enqueue terminal cost-only rows left between the job commit and outbox
|
|
@@ -3671,19 +3488,16 @@ declare class JobManager<State, InputSchema extends ZodLike | undefined> {
|
|
|
3671
3488
|
private bookRevenue;
|
|
3672
3489
|
/** Schedule job removal from activeJobs after a delay so clients can still poll final status. */
|
|
3673
3490
|
scheduleCleanup(job: ServerJob): void;
|
|
3674
|
-
/** Clear all timers. Called on server shutdown to allow clean exit. */
|
|
3675
3491
|
shutdown(): void;
|
|
3676
3492
|
}
|
|
3677
3493
|
|
|
3678
3494
|
/** Cached liveness signal for a platform-hosted DVM's Lightning receive rail. */
|
|
3679
3495
|
interface LightningRailHealth {
|
|
3680
|
-
/** Whether the receive rail may be advertised at this instant. */
|
|
3681
3496
|
available(): boolean;
|
|
3682
3497
|
/** Prime the cached signal at boot when the source supports it. */
|
|
3683
3498
|
refresh?(): Promise<void>;
|
|
3684
3499
|
}
|
|
3685
3500
|
|
|
3686
|
-
/** Builder-facing wiring for the Lightning receive leg. */
|
|
3687
3501
|
interface LightningReceiveConfig {
|
|
3688
3502
|
/**
|
|
3689
3503
|
* Receive-only NWC connection URI (`DVMKIT_NWC_RECEIVE_URI`). Validated at
|
|
@@ -3722,25 +3536,14 @@ declare const DEFAULT_INVOICE_TTL_SECONDS = 900;
|
|
|
3722
3536
|
*/
|
|
3723
3537
|
declare const MIN_INVOICE_TTL_SECONDS = 600;
|
|
3724
3538
|
/**
|
|
3725
|
-
*
|
|
3726
|
-
*
|
|
3727
|
-
*
|
|
3728
|
-
*
|
|
3729
|
-
* settlement. Two properties are load-bearing:
|
|
3539
|
+
* Prepaid Lightning funding over a receive-safe NWC connection. URI construction validates
|
|
3540
|
+
* the advertised method allowlist, refusing spending or unknown authority; the injected
|
|
3541
|
+
* backend seam bypasses that probe. Receive-safe methods include invoice, read and
|
|
3542
|
+
* hold-invoice operations.
|
|
3730
3543
|
*
|
|
3731
|
-
*
|
|
3732
|
-
*
|
|
3733
|
-
*
|
|
3734
|
-
* connection by rule.
|
|
3735
|
-
* - **Crediting is pull-based — there is no settlement watcher.** The caller's
|
|
3736
|
-
* next request drives `lookup_invoice`, which is what makes this work on a
|
|
3737
|
-
* suspend-to-zero fleet: a machine that is asleep has nothing to miss.
|
|
3738
|
-
* Wallet downtime at that moment delays crediting; it never loses money,
|
|
3739
|
-
* because the invoice→credit binding is a durable row.
|
|
3740
|
-
*
|
|
3741
|
-
* Reachability is **cached**, never probed per request: the funding menu is
|
|
3742
|
-
* assembled on every quote and every 402, so a live NIP-47 round trip there
|
|
3743
|
-
* would put a nostr relay in the latency path of every priced call.
|
|
3544
|
+
* Crediting is pull-based: later requests observe settlement against the durable invoice
|
|
3545
|
+
* binding, so sleeping hosts need no watcher. Reachability is cached and refreshed in the
|
|
3546
|
+
* background for funding menus.
|
|
3744
3547
|
*/
|
|
3745
3548
|
declare class LightningReceive {
|
|
3746
3549
|
private readonly source;
|
|
@@ -3753,36 +3556,21 @@ declare class LightningReceive {
|
|
|
3753
3556
|
private constructor();
|
|
3754
3557
|
private readonly railHealth;
|
|
3755
3558
|
/**
|
|
3756
|
-
*
|
|
3757
|
-
*
|
|
3758
|
-
*
|
|
3759
|
-
*
|
|
3760
|
-
* unreachable.** A wallet outage at boot must not stop a DVM whose other
|
|
3761
|
-
* rails are fine — the menu simply omits `lightning` until a later probe
|
|
3762
|
-
* succeeds. A connection that can spend, or one that can't state what it can
|
|
3763
|
-
* do, is a different thing entirely: it is a standing money risk that no
|
|
3764
|
-
* amount of retrying fixes, so it fails the boot loudly with the fix in the
|
|
3765
|
-
* message.
|
|
3559
|
+
* Return undefined when unconfigured. Permission/URI failures refuse construction with a
|
|
3560
|
+
* corrective message; wallet transport failure constructs an unavailable receive leg so
|
|
3561
|
+
* other rails can still boot. Recovery must validate method scope before advertising
|
|
3562
|
+
* Lightning.
|
|
3766
3563
|
*/
|
|
3767
3564
|
static create(config: LightningReceiveConfig): Promise<LightningReceive | undefined>;
|
|
3768
3565
|
/**
|
|
3769
|
-
*
|
|
3770
|
-
*
|
|
3771
|
-
* Reads the cached observation and never blocks; a stale one kicks off a
|
|
3772
|
-
* background refresh and answers with what we last knew. Advertising a rail
|
|
3773
|
-
* whose wallet is down would hand the caller an option that 402s on use —
|
|
3774
|
-
* the §4 posture is to drop it and let the sale survive on the others.
|
|
3566
|
+
* Answer from cached wallet and optional rail-health observations without blocking. A stale
|
|
3567
|
+
* wallet observation starts a background refresh.
|
|
3775
3568
|
*/
|
|
3776
3569
|
available(): boolean;
|
|
3777
3570
|
/**
|
|
3778
|
-
*
|
|
3779
|
-
*
|
|
3780
|
-
*
|
|
3781
|
-
* signed body — that binding is the condition-3 commitment on this
|
|
3782
|
-
* rail, and it is why no artifact hash rides the request: there is no
|
|
3783
|
-
* caller-supplied artifact to hash. A re-poll returns the stored row rather
|
|
3784
|
-
* than minting again; a second bolt11 for one `fund_id` would leave two
|
|
3785
|
-
* payable invoices against a funding that can only be credited once.
|
|
3571
|
+
* Return the stored invoice on retry: two payable bolt11s for one fund ID could charge
|
|
3572
|
+
* twice while only one credits. Caller and amount are bound to the recorded credit/funding
|
|
3573
|
+
* pair, without a caller-supplied artifact hash.
|
|
3786
3574
|
*/
|
|
3787
3575
|
issue(ledger: CreditLedgerLike, args: {
|
|
3788
3576
|
creditId: string;
|
|
@@ -3794,24 +3582,9 @@ declare class LightningReceive {
|
|
|
3794
3582
|
description?: string;
|
|
3795
3583
|
}): Promise<CreditInvoiceRecord>;
|
|
3796
3584
|
/**
|
|
3797
|
-
*
|
|
3798
|
-
*
|
|
3799
|
-
*
|
|
3800
|
-
* `blocked` row implies payment — {@link applyOne} returns above the block
|
|
3801
|
-
* classification when the lookup says unpaid — but that is *this fleet's
|
|
3802
|
-
* belief, recorded possibly weeks ago*, and the verb it gates mints balance
|
|
3803
|
-
* against it. One round trip turns the belief into a fact and recovers the
|
|
3804
|
-
* true settlement instant for `settled_at`, which a blocked row never got to
|
|
3805
|
-
* write.
|
|
3806
|
-
*
|
|
3807
|
-
* Unlike {@link settlePending} this **throws**: there is no request whose
|
|
3808
|
-
* latency it protects, and crediting on an unverifiable wallet is exactly
|
|
3809
|
-
* what it exists to prevent. `NOT_FOUND` is the one exception, and it is not
|
|
3810
|
-
* an outage — it is the wallet saying it has never seen this hash, the same
|
|
3811
|
-
* reading {@link applyOne} and the caller-side reconcile in `src/lib/nwc.ts`
|
|
3812
|
-
* take. It comes back as `known: false` because the operator's repair for it
|
|
3813
|
-
* ("you are pointed at a different wallet than the one that minted this")
|
|
3814
|
-
* is not the repair for an unpaid invoice, and certainly not for a retry.
|
|
3585
|
+
* Re-observe the wallet payment before an operator credits a blocked invoice and recover
|
|
3586
|
+
* its settlement instant. Unlike settlePending, lookup failures throw. NOT_FOUND returns
|
|
3587
|
+
* known:false, distinguishing the wrong wallet/unknown hash from an unpaid known invoice.
|
|
3815
3588
|
*/
|
|
3816
3589
|
lookupSettlement(paymentHash: string): Promise<{
|
|
3817
3590
|
settled: boolean;
|
|
@@ -3819,23 +3592,12 @@ declare class LightningReceive {
|
|
|
3819
3592
|
known: boolean;
|
|
3820
3593
|
}>;
|
|
3821
3594
|
/**
|
|
3822
|
-
*
|
|
3823
|
-
*
|
|
3824
|
-
*
|
|
3825
|
-
* The pending rows are read locally first, so the common case (nothing
|
|
3826
|
-
* outstanding) costs one indexed SELECT and no network at all. Bounded to
|
|
3827
|
-
* {@link MAX_SETTLE_CHECKS} invoices on a short deadline, and **never throws
|
|
3828
|
-
* into the request**: a wallet failure here means the caller's balance is
|
|
3829
|
-
* merely not updated yet, which the ordinary `insufficient_credit` path
|
|
3830
|
-
* already states honestly.
|
|
3595
|
+
* Read pending invoices locally, then check at most MAX_SETTLE_CHECKS on bounded wallet
|
|
3596
|
+
* deadlines. Log failures without throwing into the request.
|
|
3831
3597
|
*
|
|
3832
|
-
*
|
|
3833
|
-
*
|
|
3834
|
-
*
|
|
3835
|
-
* the rest of the pass down with it: the next invoice in the window may be
|
|
3836
|
-
* the paid one, and it would never be looked up. Only a transport failure
|
|
3837
|
-
* ends the pass early, because there the wallet itself is gone and the
|
|
3838
|
-
* remaining lookups would just spend the caller's latency confirming it.
|
|
3598
|
+
* An invoice-specific failure must not suppress payable siblings; wallet transport failure
|
|
3599
|
+
* ends the pass. Deterministic refusals retire that row as blocked for operator repair,
|
|
3600
|
+
* while transient failures remain pending.
|
|
3839
3601
|
*/
|
|
3840
3602
|
settlePending(ledger: CreditLedgerLike, args: {
|
|
3841
3603
|
callerPubkey: string;
|
|
@@ -3845,49 +3607,21 @@ declare class LightningReceive {
|
|
|
3845
3607
|
enqueueCreditDeposit?: CreditDepositEnqueue;
|
|
3846
3608
|
nowMs?: number;
|
|
3847
3609
|
}): Promise<InvoiceSettlement[]>;
|
|
3848
|
-
/**
|
|
3849
|
-
* One invoice's settlement check. Returns the applied settlement, or
|
|
3850
|
-
* `undefined` when nothing changed (still unpaid, or retired unpaid).
|
|
3851
|
-
*
|
|
3852
|
-
* Throws whatever the wallet or the ledger threw — classifying that is
|
|
3853
|
-
* {@link retireOrLog}'s job, so this stays one invoice's happy path.
|
|
3854
|
-
*/
|
|
3855
3610
|
private applyOne;
|
|
3856
3611
|
/**
|
|
3857
|
-
*
|
|
3858
|
-
*
|
|
3859
|
-
*
|
|
3860
|
-
* The split that matters is permanent-versus-transient, because it decides
|
|
3861
|
-
* whether the row keeps a slot in the sweep window. A transient failure — the
|
|
3862
|
-
* database blinked, the wallet answered oddly — leaves it `pending` and the
|
|
3863
|
-
* caller's next request retries it. A **permanent** one means the ledger will
|
|
3864
|
-
* refuse this invoice identically forever, so leaving it pending costs a
|
|
3865
|
-
* `lookup_invoice` on every subsequent request and, at
|
|
3866
|
-
* {@link MAX_SETTLE_CHECKS} of them, fills the window so a genuinely payable
|
|
3867
|
-
* invoice behind them is never even looked up. Those get `blocked`, which
|
|
3868
|
-
* drops them out of the sweep and hands the operator the payment hash.
|
|
3612
|
+
* Retire a deterministic uncreditable payment as blocked so it no longer occupies the
|
|
3613
|
+
* bounded sweep window. Transient failures stay pending for a later request; report the
|
|
3614
|
+
* payment hash for operator repair.
|
|
3869
3615
|
*/
|
|
3870
3616
|
private retireOrLog;
|
|
3871
3617
|
/**
|
|
3872
|
-
*
|
|
3873
|
-
*
|
|
3874
|
-
*
|
|
3875
|
-
*
|
|
3876
|
-
* has already committed (a `credit_fundings` entry at this
|
|
3877
|
-
* `(credit_id, fund_id)`, or a `credits` row whose owner, denomination or
|
|
3878
|
-
* rail disagrees with the invoice), or the basis this module rebuilds
|
|
3879
|
-
* identically from the invoice row on every pass. None of them is a race.
|
|
3880
|
-
*
|
|
3881
|
-
* `funding_replayed` is the one that needs a second read to classify.
|
|
3882
|
-
* Usually it *is* benign — a concurrent check won the race and the money is
|
|
3883
|
-
* credited either way — but the key is `(credit_id, fund_id)` and `fund_id`
|
|
3884
|
-
* is **caller-chosen**: reuse it on cashu or x402 after this bolt11 was
|
|
3885
|
-
* minted and the row that collided is a different payment entirely, so the
|
|
3886
|
-
* sats this invoice received have nowhere to land.
|
|
3618
|
+
* Classify funding_replayed by reading the existing funding’s rail. A Lightning row can
|
|
3619
|
+
* represent a concurrent applied check; another rail at this caller-chosen key is a
|
|
3620
|
+
* different payment, leaving the invoice’s sats uncredited. A failed diagnostic read
|
|
3621
|
+
* remains transient, never a guessed permanent refusal.
|
|
3887
3622
|
*/
|
|
3888
3623
|
private blockingReason;
|
|
3889
3624
|
private withBackend;
|
|
3890
|
-
/** Record activity without letting it promote an unvalidated connection. */
|
|
3891
3625
|
private noteOperationOk;
|
|
3892
3626
|
private notePermissionsOk;
|
|
3893
3627
|
private notePermissionRefused;
|
|
@@ -3910,7 +3644,7 @@ interface OwnerDisplay {
|
|
|
3910
3644
|
avatarUrl?: string | null;
|
|
3911
3645
|
type: "builder" | "org";
|
|
3912
3646
|
}
|
|
3913
|
-
/**
|
|
3647
|
+
/** Builder identity advertised on /v1/info. */
|
|
3914
3648
|
interface BuilderIdentity {
|
|
3915
3649
|
id?: string;
|
|
3916
3650
|
name?: string;
|
|
@@ -3935,7 +3669,6 @@ interface PlatformReporterOpts {
|
|
|
3935
3669
|
/** Platform internal URL. Defaults to `DVMKIT_PLATFORM_URL` env. */
|
|
3936
3670
|
url?: string;
|
|
3937
3671
|
}
|
|
3938
|
-
/** Running host handle returned by serve(). */
|
|
3939
3672
|
interface DVMServeResult {
|
|
3940
3673
|
url: string;
|
|
3941
3674
|
close: () => Promise<void>;
|
|
@@ -3957,7 +3690,6 @@ interface DVMHostOpts {
|
|
|
3957
3690
|
* to ambient process variables.
|
|
3958
3691
|
*/
|
|
3959
3692
|
env?: Record<string, string>;
|
|
3960
|
-
/** Builder identity for `/v1/info` (forward-compatible). */
|
|
3961
3693
|
builder?: BuilderIdentity;
|
|
3962
3694
|
/** Owner display identity for `/v1/info#owner`. Falls back to env vars. */
|
|
3963
3695
|
owner?: OwnerDisplay;
|
|
@@ -3985,7 +3717,6 @@ interface DVMHostOpts {
|
|
|
3985
3717
|
pool?: Pool;
|
|
3986
3718
|
/** Cashu mints accepted. Defaults to env `DVMKIT_CASHU_MINTS`. */
|
|
3987
3719
|
mints?: string[];
|
|
3988
|
-
/** Cashu receive mode override. */
|
|
3989
3720
|
cashuMode?: CashuMode;
|
|
3990
3721
|
/** MPP handle override. Defaults to env-resolved via `createMppFromOpts`. */
|
|
3991
3722
|
mpp?: MppxServer;
|
|
@@ -4008,9 +3739,7 @@ interface DVMHostOpts {
|
|
|
4008
3739
|
onPaidJobCompleted?: (event: PaidJobCompletion) => void | Promise<void>;
|
|
4009
3740
|
/** When true, payment is skipped only when no payment rail is configured. */
|
|
4010
3741
|
devMode?: boolean;
|
|
4011
|
-
/** Consumed-credential store override (test seam). */
|
|
4012
3742
|
consumedCredentialStore?: ConsumedCredentialStore;
|
|
4013
|
-
/** Mint-health tracker override (test seam). */
|
|
4014
3743
|
mintHealthTracker?: MintHealthTracker;
|
|
4015
3744
|
/** Operator-alert boundary for failed terminal-job retention passes. */
|
|
4016
3745
|
onJobRetentionSweepFailed?: JobManagerOpts["onJobRetentionSweepFailed"];
|
|
@@ -4023,12 +3752,10 @@ interface DVMHostOpts {
|
|
|
4023
3752
|
*/
|
|
4024
3753
|
wrapRouteClientCompatibility?: (sdkGate: ClientCompatibilityGate) => ClientCompatibilityGate;
|
|
4025
3754
|
}
|
|
4026
|
-
/** Per-mount options. Currently only `prefix` is supported. */
|
|
4027
3755
|
interface MountOpts {
|
|
4028
3756
|
/** Path prefix for this DVM's protocol routes (e.g. `/delete-feed`). */
|
|
4029
3757
|
prefix?: string;
|
|
4030
3758
|
}
|
|
4031
|
-
/** Live DVM host. Single wiring locus for the SDK. */
|
|
4032
3759
|
interface DVMHost {
|
|
4033
3760
|
/**
|
|
4034
3761
|
* Underlying Hono app for custom non-protocol routes that belong to the
|
|
@@ -4057,7 +3784,6 @@ interface DVMHost {
|
|
|
4057
3784
|
* a single mount with no prefix attaches at root.
|
|
4058
3785
|
*/
|
|
4059
3786
|
mount<S, I extends ZodLike | undefined>(descriptor: DVMDescriptor<S, I>, opts?: MountOpts): void;
|
|
4060
|
-
/** Start listening. Returns the live server handle. */
|
|
4061
3787
|
serve(opts?: {
|
|
4062
3788
|
port?: number;
|
|
4063
3789
|
}): Promise<DVMServeResult>;
|
|
@@ -4101,22 +3827,10 @@ interface TempoObserverHealth {
|
|
|
4101
3827
|
/** Prime the cached signal at boot. */
|
|
4102
3828
|
refresh?(): Promise<void>;
|
|
4103
3829
|
/**
|
|
4104
|
-
*
|
|
4105
|
-
*
|
|
4106
|
-
*
|
|
4107
|
-
* The
|
|
4108
|
-
* close observer's payee-fallback rung 2 — was written once per container
|
|
4109
|
-
* deploy and never refreshed, so a builder flipping sessions on with
|
|
4110
|
-
* `dvmctl env --set` stayed invisible to the fallback indefinitely. That is a
|
|
4111
|
-
* `no_route` on the first close of that DVM's first channel, which is exactly
|
|
4112
|
-
* the race the rung exists to cover.
|
|
4113
|
-
*
|
|
4114
|
-
* The reader must answer from **configuration**, never from
|
|
4115
|
-
* {@link TempoObserverHealth.available} — a fail-closed gate blip must not
|
|
4116
|
-
* de-stamp the DVM, which is the failure through a new door.
|
|
4117
|
-
*
|
|
4118
|
-
* Returns a disposer the mount calls on shutdown, so a torn-down capability
|
|
4119
|
-
* stops voting in the OR below.
|
|
3830
|
+
* Report the OR of mounted session capabilities to keep the platform's
|
|
3831
|
+
* observer watch signal current. Readers must use configuration, not current
|
|
3832
|
+
* availability: an observer outage must not erase the capability it watches.
|
|
3833
|
+
* The returned disposer removes a mount's contribution on shutdown.
|
|
4120
3834
|
*/
|
|
4121
3835
|
declareSessionCapability?(read: () => boolean): () => void;
|
|
4122
3836
|
}
|
|
@@ -4164,7 +3878,6 @@ interface TempoSettlementReadinessStateStore {
|
|
|
4164
3878
|
clearFailureIfRefilled(version: string, balanceMicro: bigint, lowBalanceMicro: bigint): Promise<boolean>;
|
|
4165
3879
|
clearFailureAfterSuccessfulTransaction(version: string): Promise<boolean>;
|
|
4166
3880
|
}
|
|
4167
|
-
/** Construction inputs for {@link TempoSettlementReadiness}. */
|
|
4168
3881
|
interface TempoSettlementReadinessOptions {
|
|
4169
3882
|
address: `0x${string}`;
|
|
4170
3883
|
network: string;
|
|
@@ -4211,7 +3924,6 @@ declare class TempoSettlementReadiness {
|
|
|
4211
3924
|
start(): void;
|
|
4212
3925
|
/** Stop the cadence without affecting any in-flight reading. */
|
|
4213
3926
|
stop(): void;
|
|
4214
|
-
/** Read and report the configured fee-token balance now. */
|
|
4215
3927
|
checkBalance(opts?: {
|
|
4216
3928
|
successfulTransaction?: boolean;
|
|
4217
3929
|
recoveryVersion?: string;
|
|
@@ -4234,24 +3946,11 @@ declare class TempoSettlementReadiness {
|
|
|
4234
3946
|
private notify;
|
|
4235
3947
|
}
|
|
4236
3948
|
|
|
4237
|
-
/**
|
|
4238
|
-
* Options for the revenue reporter readiness assertion.
|
|
4239
|
-
*
|
|
4240
|
-
* The check branches on `platformUrl` presence — that's the unambiguous
|
|
4241
|
-
* "platform-hosted" signal. `failFast` stays on the opts as a general SDK
|
|
4242
|
-
* strict-mode flag but is not consulted by this assertion.
|
|
4243
|
-
*/
|
|
4244
3949
|
interface RevenueBootCheckOpts {
|
|
4245
3950
|
/**
|
|
4246
|
-
*
|
|
4247
|
-
* boundary. Reserved for future warning-vs-fatal SDK checks; the
|
|
4248
|
-
* reporter check itself ignores it, hence optional.
|
|
3951
|
+
* Reporter readiness ignores this host strict-mode flag.
|
|
4249
3952
|
*/
|
|
4250
3953
|
failFast?: boolean;
|
|
4251
|
-
/**
|
|
4252
|
-
* The SDK's canonical "this is a dev/test run" signal. Exempts the boot from
|
|
4253
|
-
* the platform-hosted wiring requirement — see below.
|
|
4254
|
-
*/
|
|
4255
3954
|
devMode?: boolean;
|
|
4256
3955
|
platformToken: string | undefined;
|
|
4257
3956
|
platformUrl: string | undefined;
|
|
@@ -4356,10 +4055,8 @@ interface SDKServerOpts {
|
|
|
4356
4055
|
/** Postgres pool for builder admin state and wallet accumulator persistence. */
|
|
4357
4056
|
db?: Pool;
|
|
4358
4057
|
/**
|
|
4359
|
-
*
|
|
4360
|
-
*
|
|
4361
|
-
* revenue-reporter boot check is gated on platform context, not on this
|
|
4362
|
-
* flag.
|
|
4058
|
+
* Host strict-mode flag. Reporter readiness follows hosted context regardless
|
|
4059
|
+
* of this value.
|
|
4363
4060
|
*/
|
|
4364
4061
|
failFast?: boolean;
|
|
4365
4062
|
/** Agent-wallet: per-DVM identifier — drives the monitor advisory lock + replay key. */
|
|
@@ -4486,12 +4183,6 @@ interface SDKServerOpts {
|
|
|
4486
4183
|
*/
|
|
4487
4184
|
creditExpirySweep?: CreditExpirySweepOpts;
|
|
4488
4185
|
}
|
|
4489
|
-
/**
|
|
4490
|
-
* Builds a Hono sub-app for one DVM descriptor, wires payment verification,
|
|
4491
|
-
* auto-wires `RevenueReporter` when platform env + db + dvmId are present, and
|
|
4492
|
-
* runs the platform-hosted partial-wiring assertion — gated on
|
|
4493
|
-
* `DVMKIT_PLATFORM_URL` presence, independent of `DVMKIT_FAIL_FAST`.
|
|
4494
|
-
*/
|
|
4495
4186
|
declare function createDVMServer<State, InputSchema extends ZodLike | undefined>(descriptor: DVMDescriptor<State, InputSchema>, opts: SDKServerOpts): Promise<{
|
|
4496
4187
|
app: Hono<AppEnv>;
|
|
4497
4188
|
authAudience?: SignedRequestAudience;
|
|
@@ -4533,13 +4224,8 @@ interface AppEnv {
|
|
|
4533
4224
|
declare function unknownRouteNotFound(c: Context): Response;
|
|
4534
4225
|
|
|
4535
4226
|
/**
|
|
4536
|
-
*
|
|
4537
|
-
*
|
|
4538
|
-
*
|
|
4539
|
-
* This type deliberately excludes the per-caller echo. `/v1/info` is public
|
|
4540
|
-
* and cacheable, so its type must make a caller credit ID or balance
|
|
4541
|
-
* unrepresentable rather than relying on the current handler not to ask for
|
|
4542
|
-
* one.
|
|
4227
|
+
* Public, cacheable prepaid terms exclude caller IDs and balances. toCreditTerms explicitly
|
|
4228
|
+
* whitelists this shape so later caller-specific menu fields cannot leak into /v1/info.
|
|
4543
4229
|
*/
|
|
4544
4230
|
interface CreditTerms {
|
|
4545
4231
|
/** Smallest funding accepted, in 1e-6 units of `currency`. */
|
|
@@ -4552,7 +4238,10 @@ interface CreditTerms {
|
|
|
4552
4238
|
currency: string;
|
|
4553
4239
|
/** Rails a top-up may be funded over. */
|
|
4554
4240
|
funding: FundingMethod[];
|
|
4555
|
-
/**
|
|
4241
|
+
/**
|
|
4242
|
+
* Tempo methods are actionable. withheld names configured but temporarily unavailable
|
|
4243
|
+
* instruments, preserving capability discovery without advertising them for funding.
|
|
4244
|
+
*/
|
|
4556
4245
|
tempo?: {
|
|
4557
4246
|
methods: {
|
|
4558
4247
|
method: string;
|
|
@@ -4564,63 +4253,32 @@ interface CreditTerms {
|
|
|
4564
4253
|
reason: string;
|
|
4565
4254
|
}[];
|
|
4566
4255
|
};
|
|
4567
|
-
/**
|
|
4256
|
+
/**
|
|
4257
|
+
* Present with offered x402 funding. Reusable batch settlement is enabled by default; exact
|
|
4258
|
+
* requires explicit acceptance of its manual refund obligation.
|
|
4259
|
+
*/
|
|
4568
4260
|
x402?: {
|
|
4569
4261
|
schemes: {
|
|
4570
4262
|
scheme: string;
|
|
4571
4263
|
network: string;
|
|
4572
4264
|
}[];
|
|
4573
4265
|
};
|
|
4574
|
-
/**
|
|
4266
|
+
/**
|
|
4267
|
+
* Configured Lightning receive floor in micro-units of currency, including the advertised
|
|
4268
|
+
* FX margin. Issuance checks the raw sats floor at current rates; arbitrary drift can still
|
|
4269
|
+
* make the advertised amount insufficient.
|
|
4270
|
+
*/
|
|
4575
4271
|
lightning_min_micro?: number;
|
|
4576
4272
|
}
|
|
4577
4273
|
/**
|
|
4578
|
-
*
|
|
4579
|
-
*
|
|
4274
|
+
* Funding options and sizing in the wire denomination. max_micro limits residual balance,
|
|
4275
|
+
* not a job’s price; fund-and-draw can spend a larger payment immediately. Lightning funds
|
|
4276
|
+
* credit but is not an attached-proof payment method.
|
|
4580
4277
|
*
|
|
4581
|
-
*
|
|
4582
|
-
*
|
|
4583
|
-
* it still clears as fund-and-immediately-draw. `funding` is the rail list a
|
|
4584
|
-
* top-up may arrive on — a {@link FundingMethod}, not a `PaymentMethod`, since
|
|
4585
|
-
* `lightning` funds a credit without ever being an attached-proof wire method.
|
|
4586
|
-
* A rail whose backing wallet is unreachable drops out and the sale survives
|
|
4587
|
-
* on the others.
|
|
4588
|
-
*
|
|
4589
|
-
* The `credit_id` / `balance_micro` / `remaining_micro` / `expiry_ms` echo
|
|
4590
|
-
* appears only for an authenticated caller who already holds a live credit —
|
|
4591
|
-
* so one round trip answers "what does this cost, and what do I have left?"
|
|
4592
|
-
* through the signed credit endpoint.
|
|
4278
|
+
* An authenticated caller’s live credit may add an echo with funded and spendable balance;
|
|
4279
|
+
* pending holds are included only in the funded figure.
|
|
4593
4280
|
*/
|
|
4594
4281
|
interface CreditMenu extends CreditTerms {
|
|
4595
|
-
/**
|
|
4596
|
-
* MPP instruments accepted for this credit, reusable sessions first when
|
|
4597
|
-
* available.
|
|
4598
|
-
*
|
|
4599
|
-
* `withheld` names an instrument this DVM is configured for and is not
|
|
4600
|
-
* offering at this instant, with the reason. Two audiences read
|
|
4601
|
-
* it. An agent gets to relay *why* `tempo/session` vanished instead of
|
|
4602
|
-
* inferring the DVM never had it. And the platform's deploy probe reads
|
|
4603
|
-
* capability from `methods ∪ withheld`, so a deploy landing during an
|
|
4604
|
-
* observer blip no longer stamps `tempo_session_advertised_at` NULL and
|
|
4605
|
-
* drops the DVM out of the close observer's payee fallback permanently.
|
|
4606
|
-
* `methods` stays the list a caller acts on — never widen it to include a
|
|
4607
|
-
* withheld instrument.
|
|
4608
|
-
*/
|
|
4609
|
-
/**
|
|
4610
|
-
* Which x402 flavours a top-up may arrive on, and the chain each rides
|
|
4611
|
-
* Present exactly when `funding` lists `x402`. Reusable
|
|
4612
|
-
* `batch-settlement` is admitted by default; one-payment `exact` appears
|
|
4613
|
-
* only when the builder explicitly accepts its manual refund obligation.
|
|
4614
|
-
*/
|
|
4615
|
-
/**
|
|
4616
|
-
* Smallest funding the `lightning` rail accepts, in 1e-6 units of
|
|
4617
|
-
* `currency`. Present only when `funding` lists `lightning`. This is the
|
|
4618
|
-
* deployment's sats-physical receive floor rendered into fiat
|
|
4619
|
-
* with a ×{@link LIGHTNING_FLOOR_FX_MARGIN} margin absorbing rate drift
|
|
4620
|
-
* between menu fetch and funding — issuance enforces the *raw* floor at
|
|
4621
|
-
* request-time rates, so funding exactly this figure always clears. Rails
|
|
4622
|
-
* without an entry (cashu) have no floor beyond `min_micro`.
|
|
4623
|
-
*/
|
|
4624
4282
|
/** The caller's credit this echo describes. Present only with the echo. */
|
|
4625
4283
|
credit_id?: string;
|
|
4626
4284
|
/** Funded balance, pending holds NOT subtracted. */
|
|
@@ -4630,7 +4288,6 @@ interface CreditMenu extends CreditTerms {
|
|
|
4630
4288
|
/** Absolute expiry of the echoed credit, ms since epoch. */
|
|
4631
4289
|
expiry_ms?: number;
|
|
4632
4290
|
}
|
|
4633
|
-
/** Everything {@link buildCreditMenu} needs, assembled per request. */
|
|
4634
4291
|
interface BuildCreditMenuArgs {
|
|
4635
4292
|
/**
|
|
4636
4293
|
* Which runtime is answering. `"isolate"` is refused unconditionally — see
|
|
@@ -4640,13 +4297,8 @@ interface BuildCreditMenuArgs {
|
|
|
4640
4297
|
/** The DVM's resolved `credit` block; `undefined` means it didn't opt in. */
|
|
4641
4298
|
config: ResolvedCreditConfig | undefined;
|
|
4642
4299
|
/**
|
|
4643
|
-
*
|
|
4644
|
-
*
|
|
4645
|
-
* `DVMServer.creditCurrency()`. Deliberately *not* the currency of
|
|
4646
|
-
* the response this menu rides on: a quote priced elsewhere is refused before
|
|
4647
|
-
* it reaches here, so the two agree, and sourcing it from the response is
|
|
4648
|
-
* what left `POST /v1/credit` — which has no response to read — funding in
|
|
4649
|
-
* hardwired USD at a DVM whose jobs draw in something else.
|
|
4300
|
+
* Use the DVM’s declared denomination, including /v1/credit where no quote response supplies
|
|
4301
|
+
* it. Quote validation refuses a different denomination before menu construction.
|
|
4650
4302
|
*/
|
|
4651
4303
|
currency: string;
|
|
4652
4304
|
/** Rails this DVM settles over — the menu's funding options. */
|
|
@@ -4662,31 +4314,19 @@ interface BuildCreditMenuArgs {
|
|
|
4662
4314
|
intent: "charge" | "session";
|
|
4663
4315
|
reason: string;
|
|
4664
4316
|
}[];
|
|
4665
|
-
/**
|
|
4666
|
-
* x402 flavours this DVM can actually accept a top-up on — one
|
|
4667
|
-
* server read, so what the sub-block advertises is what `/v1/credit` will
|
|
4668
|
-
* answer a 402 with.
|
|
4669
|
-
*/
|
|
4670
4317
|
x402Schemes?: {
|
|
4671
4318
|
scheme: string;
|
|
4672
4319
|
network: string;
|
|
4673
4320
|
}[];
|
|
4674
4321
|
/**
|
|
4675
|
-
*
|
|
4676
|
-
* the
|
|
4677
|
-
*
|
|
4678
|
-
* menu: a rail whose minimum we can't state honestly is a rail we must not
|
|
4679
|
-
* advertise, but the other rails' sale survives.
|
|
4322
|
+
* Configured raw receive floor in sats, rendered with an FX margin for the menu. Failure
|
|
4323
|
+
* omits Lightning while allowing the rest of the menu; issuance checks the raw floor at
|
|
4324
|
+
* current request-time rates.
|
|
4680
4325
|
*/
|
|
4681
4326
|
lightningFundingMinSats?: number;
|
|
4682
4327
|
/**
|
|
4683
|
-
*
|
|
4684
|
-
*
|
|
4685
|
-
* the filter in {@link buildCreditMenu}.
|
|
4686
|
-
*
|
|
4687
|
-
* Read off the **configured** mint list, never the health-filtered
|
|
4688
|
-
* advertised one: a mint blip must not make a funding rail appear and
|
|
4689
|
-
* disappear between quotes.
|
|
4328
|
+
* Read the configured accepted mint list, not its health-filtered advertisement. Non-channel
|
|
4329
|
+
* Bitcoin refunds need a mint, but configuration alone does not establish refund solvency.
|
|
4690
4330
|
*/
|
|
4691
4331
|
hasAcceptedMint?: boolean;
|
|
4692
4332
|
fxFetcher: FxFetcher;
|
|
@@ -4699,50 +4339,18 @@ interface BuildCreditMenuArgs {
|
|
|
4699
4339
|
callerPubkey?: string;
|
|
4700
4340
|
}
|
|
4701
4341
|
/**
|
|
4702
|
-
*
|
|
4703
|
-
*
|
|
4704
|
-
* because advertising anyway would misadvertise:
|
|
4342
|
+
* Return no menu for static ineligibility or unresolvable denomination bounds. Isolates
|
|
4343
|
+
* currently lack durable credit storage; anonymous balances must not be advertised.
|
|
4705
4344
|
*
|
|
4706
|
-
*
|
|
4707
|
-
* before config is even read. Isolate DVMs have no Postgres of their own;
|
|
4708
|
-
* their only DVM-side persistence is the last-write-wins callback KV, which
|
|
4709
|
-
* the durable-ledger requirement prohibits for credit state. Until isolate
|
|
4710
|
-
* runtimes have durable credit storage, they run implicit N=1 only and their quote never offers
|
|
4711
|
-
* credit so nothing is misadvertised.
|
|
4712
|
-
* 2. **Not opted in** — no `credit` block on `configureDVM`.
|
|
4713
|
-
* 3. **No descriptor auth** — a credit belongs to a verified secp256k1 pubkey.
|
|
4714
|
-
* Without auth the ledger's funder identity degrades to the requester id or
|
|
4715
|
-
* `"anonymous"` (see `resolveLedgerContext`), which would pool every
|
|
4716
|
-
* anonymous caller's money into one balance. Advertising a per-caller
|
|
4717
|
-
* balance on such a DVM would be a lie at best and a disclosure at worst.
|
|
4718
|
-
* 4. **Non-durable ledger outside devMode** — a `MemoryCreditLedger` is
|
|
4719
|
-
* per-process, so a caller funding on machine A and drawing on machine B
|
|
4720
|
-
* gets `credit_not_found`. Advertise only what survives the fleet.
|
|
4721
|
-
* 5. **Bounds not expressible in `currency`** — an fx outage, or a currency the
|
|
4722
|
-
* snapshot doesn't carry. Omit rather than quote a number we can't state.
|
|
4723
|
-
*
|
|
4724
|
-
* The balance echo is added only when a verified `callerPubkey` holds a live,
|
|
4725
|
-
* same-currency credit.
|
|
4726
|
-
*
|
|
4727
|
-
* Rungs 1–4 live in {@link creditMenuConfigured}, which the capability refresh
|
|
4728
|
-
* reads too.
|
|
4345
|
+
* Select the caller echo only from live, same-currency credits with spendable value.
|
|
4729
4346
|
*/
|
|
4730
4347
|
declare function buildCreditMenu(args: BuildCreditMenuArgs): Promise<CreditMenu | undefined>;
|
|
4731
4348
|
/**
|
|
4732
|
-
*
|
|
4733
|
-
*
|
|
4734
|
-
* this list grows with each paid job.
|
|
4349
|
+
* Choose the largest live, active, same-currency spendable balance; newest creation breaks
|
|
4350
|
+
* a tie. Released implicit payments can hold reclaimable value and are eligible too.
|
|
4735
4351
|
*
|
|
4736
|
-
*
|
|
4737
|
-
*
|
|
4738
|
-
* draw against next. A failed job's released hold leaves a positive implicit
|
|
4739
|
-
* balance, which is real caller money (the credit lifecycle contract, no debit on failure) and is
|
|
4740
|
-
* echoed like any other.
|
|
4741
|
-
*
|
|
4742
|
-
* **Requires a verified pubkey.** Never call this with a requester id or
|
|
4743
|
-
* `"anonymous"`: on an auth-less DVM the ledger pools every anonymous caller
|
|
4744
|
-
* under one `caller_pubkey`, so echoing it would show one caller another's
|
|
4745
|
-
* balance.
|
|
4352
|
+
* The caller supplies a verified pubkey. Anonymous/missing identity returns no credit; the
|
|
4353
|
+
* ledger’s anonymous pool must not be exposed to an individual caller.
|
|
4746
4354
|
*/
|
|
4747
4355
|
declare function selectPrimaryCredit(args: {
|
|
4748
4356
|
ledger: CreditLedgerLike;
|
|
@@ -4750,20 +4358,15 @@ declare function selectPrimaryCredit(args: {
|
|
|
4750
4358
|
currency: string;
|
|
4751
4359
|
nowMs?: number;
|
|
4752
4360
|
}): Promise<CreditSnapshot | undefined>;
|
|
4753
|
-
/** Narrow a ledger snapshot to the read-only shape a quote handler receives. */
|
|
4754
4361
|
declare function toCreditView(snapshot: CreditSnapshot): CreditView;
|
|
4755
4362
|
/**
|
|
4756
|
-
*
|
|
4757
|
-
*
|
|
4758
|
-
* checks presence, and the isolate tier depends on the key never appearing.
|
|
4363
|
+
* Omit the credit key entirely when there is no menu; consumers use presence to determine
|
|
4364
|
+
* whether credit is offered.
|
|
4759
4365
|
*/
|
|
4760
4366
|
declare function attachCreditMenu(body: Record<string, unknown>, menu: CreditMenu | undefined): Record<string, unknown>;
|
|
4761
4367
|
/**
|
|
4762
|
-
*
|
|
4763
|
-
*
|
|
4764
|
-
* This is an explicit whitelist rather than object rest syntax: a later
|
|
4765
|
-
* caller-specific field added to {@link CreditMenu} cannot cross this boundary
|
|
4766
|
-
* until someone deliberately adds it to {@link CreditTerms} and this copy.
|
|
4368
|
+
* Explicitly whitelist public /v1/info terms. A future caller-specific menu field cannot
|
|
4369
|
+
* cross this cacheable boundary merely by being added to CreditMenu.
|
|
4767
4370
|
*/
|
|
4768
4371
|
declare function toCreditTerms(menu: CreditMenu): CreditTerms;
|
|
4769
4372
|
|