@dvmkit/sdk 0.2.0-rc.9 → 0.3.0-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.
Files changed (58) hide show
  1. package/README.md +2 -0
  2. package/dist/{chunk-V7EVFLAK.js → chunk-2D75MNNG.js} +154 -523
  3. package/dist/{chunk-BIFLRKMO.js → chunk-2KGG5ORW.js} +1 -1
  4. package/dist/{chunk-5URG56JJ.js → chunk-A4CM2BD3.js} +18 -2
  5. package/dist/{chunk-FT6HTUM4.js → chunk-AJNFXR7J.js} +1 -1
  6. package/dist/{chunk-S3XAHZQY.js → chunk-COYKJRMM.js} +24 -3
  7. package/dist/{chunk-UP2F5RRT.js → chunk-D7YQYLLM.js} +1 -4
  8. package/dist/{chunk-OMIQMMME.js → chunk-FPOLJRBF.js} +3 -3
  9. package/dist/{chunk-QP53RWAD.js → chunk-HHTL3ZFT.js} +9 -6
  10. package/dist/{chunk-PCUQZDZA.js → chunk-LTAIBLS2.js} +537 -321
  11. package/dist/{chunk-JDT5LCJC.js → chunk-MD3H3BF7.js} +1 -1
  12. package/dist/{chunk-KSQEFVFJ.js → chunk-MMCE7XSR.js} +1 -1
  13. package/dist/{chunk-MRAGS5VP.js → chunk-N5B66UOS.js} +4 -16
  14. package/dist/{chunk-2ATUAUAO.js → chunk-O6D72KYA.js} +2 -2
  15. package/dist/{chunk-KXCKFIJI.js → chunk-QX52F6IB.js} +1 -1
  16. package/dist/{chunk-PHHAYRQV.js → chunk-U5VNEALI.js} +23 -10
  17. package/dist/{chunk-JLXYOV4Y.js → chunk-V5ZRATJH.js} +1 -1
  18. package/dist/{chunk-6GRIKOFB.js → chunk-VA7GT6C6.js} +5 -16
  19. package/dist/{chunk-O2X2CCKH.js → chunk-VIVXB4CD.js} +1 -1
  20. package/dist/{chunk-L67WTZX2.js → chunk-XMDQOXHO.js} +10 -33
  21. package/dist/{chunk-QT4ONTST.js → chunk-XRLKGCAW.js} +1 -1
  22. package/dist/{chunk-KMZXTBLA.js → chunk-XZ7LW4S5.js} +0 -1
  23. package/dist/{chunk-XQXJKJ3P.js → chunk-YO56VCTQ.js} +0 -4
  24. package/dist/{credit-ledger-5ZEJRI46.js → credit-ledger-MHA652TV.js} +2 -2
  25. package/dist/{credit-menu-D4Gcdgc4.d.ts → credit-menu-BlCL7gZx.d.ts} +175 -533
  26. package/dist/{fx-B0SLBe5x.d.ts → fx-DhyT1Cjh.d.ts} +1 -1
  27. package/dist/index.d.ts +5 -17
  28. package/dist/internal/caller.d.ts +109 -698
  29. package/dist/internal/caller.js +10 -12
  30. package/dist/internal/server.d.ts +17 -42
  31. package/dist/internal/server.js +16 -15
  32. package/dist/{job-store-B2uZvga4.d.ts → job-store-D3CcZp_g.d.ts} +6 -10
  33. package/dist/{lightning-backend-CQBnQgsT.d.ts → lightning-backend-BhsyrBLa.d.ts} +1 -15
  34. package/dist/{memory-credit-ledger-ZOH6C3N4.js → memory-credit-ledger-BYBATRN3.js} +3 -3
  35. package/dist/{mpp-secret-state-WNAQQ6K4.js → mpp-secret-state-B5GCILVH.js} +1 -1
  36. package/dist/{mpp-setup-IOJBF7DB.js → mpp-setup-MPP3ST5X.js} +1 -1
  37. package/dist/{payout-reporter-5PIRYFVQ.js → payout-reporter-KEMUXEUO.js} +2 -2
  38. package/dist/{postgres-consumed-credential-store-ISRHBMOU.js → postgres-consumed-credential-store-6N2V5MJN.js} +1 -1
  39. package/dist/postgres-job-store-VE2JRUEC.js +7 -0
  40. package/dist/postgres-kv-store-DXGTKXLU.js +7 -0
  41. package/dist/{postgres-replay-store-IZFLTTAC.js → postgres-replay-store-ZF4JNZOW.js} +2 -2
  42. package/dist/{processed-payment-store-FIDI3RNH.js → processed-payment-store-GKMAWOM3.js} +2 -2
  43. package/dist/revenue-reporter-O75BGYFK.js +7 -0
  44. package/dist/server/index.d.ts +37 -140
  45. package/dist/server/index.js +64 -127
  46. package/dist/{step-cache-CXg7ziML.d.ts → step-cache-v2yhyhSZ.d.ts} +359 -1112
  47. package/dist/{tempo-charge-store-76TDAF34.js → tempo-charge-store-SDTUNTKA.js} +2 -2
  48. package/dist/{tempo-lifecycle-DXM7QXJQ.js → tempo-lifecycle-G5SB4HFC.js} +4 -4
  49. package/dist/{tempo-session-store-2JNOKJGX.js → tempo-session-store-WF3VZXNF.js} +2 -2
  50. package/dist/{tempo-wallet-O67H5M4N.js → tempo-wallet-ZFNUDFVO.js} +1 -1
  51. package/dist/testing/index.d.ts +2 -2
  52. package/dist/testing/index.js +2 -2
  53. package/dist/{usd-BNDg1715.d.ts → usd-Cu9G6xv2.d.ts} +1 -1
  54. package/dist/{x402-7S2EFINY.js → x402-CI6PSHNO.js} +4 -4
  55. package/package.json +2 -2
  56. package/dist/postgres-job-store-OGQ6IT4U.js +0 -7
  57. package/dist/postgres-kv-store-D5E2EZ24.js +0 -7
  58. package/dist/revenue-reporter-NNCNRY4C.js +0 -7
@@ -1,13 +1,13 @@
1
- import { ab as CashuMode, bK as CreditDrainEnqueue, R as ResolvedCreditConfig, bL as DVMAuthScheme, z as SignedRequestDomain, bM as CreditLedgerLike, bN as X402RefundSettlementGate, bO as CreditSnapshot, bP as DrawResult, bQ as X402SettlementStatus, bR as X402UnresolvedRefund, bS as GrownDrawResult, bT as DrawResolution, bU as FundingRecord, X as FundingReceipt, bV as CreditInvoiceRecord, bW as InvoiceSettlement, bX as BlockedInvoiceCursor, bY as InvoiceReconciliation, bZ as InvoiceWriteOff, b_ as DrawRecord, b$ as StalePendingDrawCursor, c0 as TempoCreditLossEvidence, c1 as CreditLedgerQuerier, c2 as TempoCreditLoss, c3 as X402CreditLossEvidence, c4 as X402CreditLoss, c5 as DrainMethod, c6 as DrainRequestResult, c7 as BitcoinDepositLiability, bo as FundingLot, c8 as CreditDrainRecord, c9 as ChannelDrainCursor, ca as DrainWriteOff, cb as DrainReleaseResult, cc as DrainFulfilment, cd as DrainTransitionResult, Y as JobReceipt, a1 as Message, K as KVStore, F as SignedRequestReplayStore, Z as ZodLike, a as DVMDescriptor } from '../step-cache-CXg7ziML.js';
2
- export { ce as CLIENT_COMPATIBILITY_HEADERS, d as CanonicalEnvelope, cf as ClientCompatibility, cg as ClientCompatibilityEnv, ch as ClientCompatibilityGate, ci as ClientCompatibilityRequirement, cj as ClientSemVer, e as CreateSignedRequestVerifierOpts, ck as CreditFundingBasis, cl as CreditInvoiceStatus, cm as CreditLedger, cn as CreditLedgerError, co as CreditLedgerErrorCode, cp as CreditLedgerErrorDetails, cq as CreditLedgerPool, cr as CreditStatus, cs as DRAIN_DELIVERY_RESERVE_SATS, ct as DVM_PROTOCOL_VERSION, cu as DrainConflictReason, cv as DrawRailValue, cw as DrawStatus, cx as JobCostReportPayload, cy as JobTerminalReportPayload, cz as PostgresX402ChannelStorage, cA as ReplayStoreBackend, cB as RevenueSkippedNoRailPayload, cC as RevenueSkippedNoRailReason, w as SIGNED_REQUEST_AUTH_ID, x as SIGNED_REQUEST_STATEMENT_VERSION, cD as Secp256k1AuthOpts, y as SignedRequestAudience, B as SignedRequestError, E as SignedRequestFailure, G as SignedRequestSignOpts, H as SignedRequestStatementHeader, M as SignedRequestVerifier, cE as X402ChannelStorageOpts, cF as X402RelayLockHolder, cG as X402RelaySubmissionLock, cH as X402RelaySubmissionLockError, cI as allocateDrawValue, cJ as clientCompatibilityAttributes, cK as clientCompatibilityMiddleware, cL as clientUpgradeRequired, N as createSignedRequestVerifier, cM as parseClientCapabilities, cN as parseClientCompatibility, cO as parseDvmClient, cP as parseProtocolVersion, cQ as requireClientCompatibility, cR as secp256k1Auth, cS as signedRequestInput, T as signedRequestStatementHeader } from '../step-cache-CXg7ziML.js';
1
+ import { ab as CashuMode, bK as CreditDrainEnqueue, R as ResolvedCreditConfig, bL as DVMAuthScheme, z as SignedRequestDomain, bM as CreditLedgerLike, bN as X402RefundSettlementGate, bO as CreditSnapshot, bP as DrawResult, bQ as X402SettlementStatus, bR as X402UnresolvedRefund, bS as GrownDrawResult, bT as DrawResolution, bU as FundingRecord, X as FundingReceipt, bV as CreditInvoiceRecord, bW as InvoiceSettlement, bX as BlockedInvoiceCursor, bY as InvoiceReconciliation, bZ as InvoiceWriteOff, b_ as DrawRecord, b$ as StalePendingDrawCursor, c0 as TempoCreditLossEvidence, c1 as CreditLedgerQuerier, c2 as TempoCreditLoss, c3 as X402CreditLossEvidence, c4 as X402CreditLoss, c5 as DrainMethod, c6 as DrainRequestResult, c7 as BitcoinDepositLiability, bo as FundingLot, c8 as CreditDrainRecord, c9 as ChannelDrainCursor, ca as DrainWriteOff, cb as DrainReleaseResult, cc as DrainFulfilment, cd as DrainTransitionResult, Y as JobReceipt, a1 as Message, K as KVStore, F as SignedRequestReplayStore, Z as ZodLike, a as DVMDescriptor } from '../step-cache-v2yhyhSZ.js';
2
+ export { ce as CLIENT_COMPATIBILITY_HEADERS, d as CanonicalEnvelope, cf as ClientCompatibility, cg as ClientCompatibilityEnv, ch as ClientCompatibilityGate, ci as ClientCompatibilityRequirement, cj as ClientSemVer, e as CreateSignedRequestVerifierOpts, ck as CreditFundingBasis, cl as CreditInvoiceStatus, cm as CreditLedger, cn as CreditLedgerError, co as CreditLedgerErrorCode, cp as CreditLedgerErrorDetails, cq as CreditLedgerPool, cr as CreditStatus, cs as DRAIN_DELIVERY_RESERVE_SATS, ct as DVM_PROTOCOL_VERSION, cu as DrainConflictReason, cv as DrawRailValue, cw as DrawStatus, cx as JobCostReportPayload, cy as JobTerminalReportPayload, cz as PostgresX402ChannelStorage, cA as ReplayStoreBackend, cB as RevenueSkippedNoRailPayload, cC as RevenueSkippedNoRailReason, w as SIGNED_REQUEST_AUTH_ID, x as SIGNED_REQUEST_STATEMENT_VERSION, cD as Secp256k1AuthOpts, y as SignedRequestAudience, B as SignedRequestError, E as SignedRequestFailure, G as SignedRequestSignOpts, H as SignedRequestStatementHeader, M as SignedRequestVerifier, cE as X402ChannelStorageOpts, cF as X402RelayLockHolder, cG as X402RelaySubmissionLock, cH as X402RelaySubmissionLockError, cI as allocateDrawValue, cJ as clientCompatibilityAttributes, cK as clientCompatibilityMiddleware, cL as clientUpgradeRequired, N as createSignedRequestVerifier, cM as parseClientCapabilities, cN as parseClientCompatibility, cO as parseDvmClient, cP as parseProtocolVersion, cQ as requireClientCompatibility, cR as secp256k1Auth, cS as signedRequestInput, T as signedRequestStatementHeader } from '../step-cache-v2yhyhSZ.js';
3
3
  import { Pool } from 'pg';
4
- import { ak as CreditMenu, b as AppEnv, U as UpfrontPaymentOpts, h as PaymentInfo, al as ReceiptIssuer, am as LightningReceive, an as TempoSettlementReadiness, ao as DVMHostOpts, ap as DVMServeResult } from '../credit-menu-D4Gcdgc4.js';
5
- export { aq as BuildCreditMenuArgs, ar as BuilderIdentity, as as CREDIT_ENVELOPE_KEYS, C as ConsumedCredentialStore, at as CreateX402BatchSettlementServerOpts, au as CreditEnvelope, av as CreditEnvelopeError, aw as CreditFundCommitment, ax as CreditTerms, ay as DEFAULT_INVOICE_TTL_SECONDS, az as DVMHost, aA as JobManager, aB as JobManagerOpts, aC as LightningReceiveConfig, aD as MIN_INVOICE_TTL_SECONDS, aE as MemoryConsumedCredentialStore, aF as MemoryConsumedCredentialStoreOpts, aG as MemoryProcessedPaymentStore, aH as MemoryX402ExactSettlementStore, aI as MountOpts, aJ as OwnerDisplay, aK as PaidJobCompletion, aL as PaymentMode, aM as PlatformReporterOpts, aN as PostgresProcessedPaymentStore, aO as PostgresX402ExactSettlementStore, aP as PriceFiat, aQ as ProcessedPaymentQuerier, aR as ProcessedPaymentRail, aS as ProcessedPaymentRecord, aT as ProcessedPaymentReplayError, aU as ProcessedPaymentStore, aV as X402BatchAcceptance, aW as X402BatchFunding, aX as X402BatchRefusal, aY as X402BatchSettlementServer, aZ as X402ExactAcceptance, a_ as X402ExactIntentConflictError, a$ as X402ExactSettlementAttempt, b0 as X402ExactSettlementChainEvidence, b1 as X402ExactSettlementEffect, b2 as X402ExactSettlementEvidenceMissingError, b3 as X402ExactSettlementEvidenceReader, b4 as X402ExactSettlementIntent, b5 as X402ExactSettlementNotReadyError, b6 as X402ExactSettlementServer, b7 as X402ExactSettlementServerOpts, b8 as X402ExactSettlementStatus, b9 as X402ExactSettlementStore, ba as X402SettlementChainEvidence, bb as X402SettlementEvidenceReader, bc as X402SettlementSubmissionError, bd as X402_BATCH_AUTO_SETTLEMENT, be as X402_BATCH_MIN_WITHDRAW_DELAY_SECONDS, bf as X402_BATCH_SETTLEMENT_NETWORK, bg as attachCreditMenu, bh as buildCreditMenu, bi as createDVMHost, bj as createX402BatchSettlementServer, bk as creditEnvelopeIgnoreFields, bl as drawSettlementRef, bm as extractCreditEnvelope, bn as fundingCommitment, bo as selectPrimaryCredit, bp as stripCreditEnvelope, bq as toCreditView } from '../credit-menu-D4Gcdgc4.js';
4
+ import { ak as CreditMenu, b as AppEnv, U as UpfrontPaymentOpts, h as PaymentInfo, al as ReceiptIssuer, am as LightningReceive, an as TempoSettlementReadiness, ao as DVMHostOpts, ap as DVMServeResult } from '../credit-menu-BlCL7gZx.js';
5
+ export { aq as BuildCreditMenuArgs, ar as BuilderIdentity, as as CREDIT_ENVELOPE_KEYS, C as ConsumedCredentialStore, at as CreateX402BatchSettlementServerOpts, au as CreditEnvelope, av as CreditEnvelopeError, aw as CreditFundCommitment, ax as CreditTerms, ay as DEFAULT_INVOICE_TTL_SECONDS, az as DVMHost, aA as HostingControlCommand, aB as HostingControlConfig, aC as HostingControlStatus, aD as JobManager, aE as JobManagerOpts, aF as LightningReceiveConfig, aG as MIN_INVOICE_TTL_SECONDS, aH as MemoryConsumedCredentialStore, aI as MemoryConsumedCredentialStoreOpts, aJ as MemoryProcessedPaymentStore, aK as MemoryX402ExactSettlementStore, aL as MountOpts, aM as OwnerDisplay, aN as PaidJobCompletion, aO as PaymentMode, aP as PlatformReporterOpts, aQ as PostgresProcessedPaymentStore, aR as PostgresX402ExactSettlementStore, aS as PriceFiat, aT as ProcessedPaymentQuerier, aU as ProcessedPaymentRail, aV as ProcessedPaymentRecord, aW as ProcessedPaymentReplayError, aX as ProcessedPaymentStore, aY as X402BatchAcceptance, aZ as X402BatchFunding, a_ as X402BatchRefusal, a$ as X402BatchSettlementServer, b0 as X402ExactAcceptance, b1 as X402ExactIntentConflictError, b2 as X402ExactSettlementAttempt, b3 as X402ExactSettlementChainEvidence, b4 as X402ExactSettlementEffect, b5 as X402ExactSettlementEvidenceMissingError, b6 as X402ExactSettlementEvidenceReader, b7 as X402ExactSettlementIntent, b8 as X402ExactSettlementNotReadyError, b9 as X402ExactSettlementServer, ba as X402ExactSettlementServerOpts, bb as X402ExactSettlementStatus, bc as X402ExactSettlementStore, bd as X402SettlementChainEvidence, be as X402SettlementEvidenceReader, bf as X402SettlementSubmissionError, bg as X402_BATCH_AUTO_SETTLEMENT, bh as X402_BATCH_MIN_WITHDRAW_DELAY_SECONDS, bi as X402_BATCH_SETTLEMENT_NETWORK, bj as attachCreditMenu, bk as buildCreditMenu, bl as createDVMHost, bm as createX402BatchSettlementServer, bn as creditEnvelopeIgnoreFields, bo as drawSettlementRef, bp as extractCreditEnvelope, bq as fundingCommitment, br as selectPrimaryCredit, bs as signHostingControl, bt as stripCreditEnvelope, bu as toCreditView } from '../credit-menu-BlCL7gZx.js';
6
6
  import { Context } from 'hono';
7
7
  import { z } from 'zod';
8
- import { F as FxFetcher } from '../fx-B0SLBe5x.js';
9
- import { c as StreamableJobStore, R as ReceiptIssuingStore, J as JobRecord, d as RequestIdClaim, e as RequestIdClaimResult, f as JobRetentionCursor, O as OutgoingMessage, A as AppendOutgoingOptions, P as PaymentCreditDelta, V as VerifyAndCreditResult, g as JobCounters } from '../job-store-B2uZvga4.js';
10
- export { a as JobStatus, b as JobStore, h as isStreamableJobStore } from '../job-store-B2uZvga4.js';
8
+ import { F as FxFetcher } from '../fx-DhyT1Cjh.js';
9
+ import { c as StreamableJobStore, R as ReceiptIssuingStore, J as JobRecord, d as RequestIdClaim, e as RequestIdClaimResult, f as JobRetentionCursor, O as OutgoingMessage, A as AppendOutgoingOptions, P as PaymentCreditDelta, V as VerifyAndCreditResult, g as JobCounters } from '../job-store-D3CcZp_g.js';
10
+ export { a as JobStatus, b as JobStore, h as isStreamableJobStore } from '../job-store-D3CcZp_g.js';
11
11
  export { P as PinnedFetch, S as SSRFError, a as SSRFGuardOpts, b as SSRFReason, c as SSRFResolver, d as assertSafeUrl, e as createPinnedFetch } from '../ssrf-dMooihtY.js';
12
12
  import 'mppx';
13
13
  import '@x402/core/server';
@@ -15,12 +15,11 @@ import '@x402/evm/batch-settlement/server';
15
15
  import 'viem';
16
16
  import '@x402/core/types';
17
17
  import '@cashu/cashu-ts';
18
- import '../lightning-backend-CQBnQgsT.js';
18
+ import '../lightning-backend-BhsyrBLa.js';
19
19
 
20
20
  /** Lifetime of a per-call implicit credit before the ledger refuses new draws. */
21
21
  declare const IMPLICIT_CREDIT_TTL_MS: number;
22
22
 
23
- /** Builder-lock and Cashu accumulator opts resolved from environment variables. */
24
23
  interface ResolvedCashuOpts {
25
24
  cashuMode: CashuMode | undefined;
26
25
  lockPubkey: string | undefined;
@@ -42,10 +41,7 @@ interface ResolvedCashuOpts {
42
41
  declare function resolveCashuOptsFromEnv(env: Record<string, string>, pool?: Pool, cashuModeHint?: CashuMode): Promise<ResolvedCashuOpts>;
43
42
 
44
43
  /**
45
- * What a terminal drain transition needs in order to book its platform drain
46
- * report. Every field is optional because a DVM can legitimately
47
- * run without platform reporting — a `dvmctl dev` server, a self-hosted
48
- * builder, a test host — and a drain must still be fulfillable there.
44
+ * Reporting is optional; an unwired host still runs the money transition.
49
45
  */
50
46
  interface DrainReportWiring {
51
47
  /** The SDK's own Postgres, which holds both the ledger and the reporter's outbox. */
@@ -57,14 +53,8 @@ interface DrainReportWiring {
57
53
  }
58
54
 
59
55
  /**
60
- * Signed body of a `POST /v1/credit` request. The op discriminator
61
- * lives **inside** the signed bytes, so a network attacker can't rewrite a
62
- * `balance` read into a `drain`.
63
- *
64
- * Deliberately independent of `credit-envelope.ts`, which parses the credit
65
- * fields riding a `/v1/job` body: that shape pairs `credit_id` with a
66
- * mandatory `draw_id`, and a fund-only top-up has no draw. Two routes, two
67
- * schemas — sharing one would force a top-up to invent a draw id.
56
+ * Authenticate the raw body, including op. Its schema is independent of job-input credit/draw
57
+ * envelopes; normal job schema projection must not define this wire contract.
68
58
  */
69
59
  declare const CREDIT_REQUEST_SCHEMA: z.ZodObject<{
70
60
  op: z.ZodEnum<{
@@ -99,49 +89,34 @@ declare const CREDIT_REQUEST_SCHEMA: z.ZodObject<{
99
89
  timestamp: z.ZodNumber;
100
90
  nonce: z.ZodString;
101
91
  }, z.core.$strip>;
102
- /** Parsed `/v1/credit` body. */
103
92
  type CreditRequest = z.infer<typeof CREDIT_REQUEST_SCHEMA>;
104
- /** Everything the `/v1/credit` handler needs from the server that mounts it. */
105
93
  interface CreditRouteDeps {
106
- /** Resolved credit sizing, or `undefined` when this DVM didn't opt in. */
107
94
  menu: () => Promise<CreditMenu | undefined>;
108
- /** Resolved builder policy; absent and older config fail closed. */
109
95
  creditConfig: ResolvedCreditConfig | undefined;
110
96
  auth: DVMAuthScheme | undefined;
111
97
  /** Exact `/v1/credit` audience and operation expected by the auth gate. */
112
98
  authDomain?: SignedRequestDomain;
113
99
  ledger: CreditLedgerLike;
114
100
  fxFetcher: FxFetcher;
115
- /** Per-DVM + per-request rail wiring, shared with `/v1/job` (see `railVerifyOpts`). */
116
101
  railOpts: (c: Context<AppEnv>) => Promise<UpfrontPaymentOpts>;
117
102
  /**
118
- * Book a committed top-up as a platform deposit. A fund-only
119
- * top-up moves real money onto a credit whose draws will each book revenue
120
- * later, so skipping this would report the spending without the money that
121
- * backed it — the DVM's outstanding liability would go negative.
103
+ * Report committed fund-only top-ups as deposits. They have no job terminal to book the
104
+ * liability; replay must not report it twice.
122
105
  */
123
106
  onDeposit: (funding: NonNullable<PaymentInfo["funding"]>) => void;
124
107
  /**
125
- * Platform drain-report wiring, used by the cashu pickup — the
126
- * one terminal drain transition that lands on this caller-facing route.
127
- * Empty on a DVM with no platform reporting, which changes nothing about
128
- * the reclaim itself.
108
+ * Optional terminal drain report wiring: Cashu pickup and channel completion commit their
109
+ * ledger transition with its report.
129
110
  */
130
111
  drainReport: DrainReportWiring;
131
112
  /**
132
- * Receipt signer, when this DVM has a receipt key. Drain ops
133
- * countersign every reclaim event with it; absent, drains still
134
- * work — the ledger stays authoritative, the caller just gets no portable
135
- * evidence artifact.
113
+ * Optional signer for reclaim observations. The ledger transition remains authoritative;
114
+ * signature issuance happens after commit and may fail separately.
136
115
  */
137
116
  receiptIssuer: ReceiptIssuer | undefined;
138
117
  /**
139
- * The Lightning receive leg, when this DVM configured one.
140
- * Absent ⇒ `method: "lightning"` is refused with `lightning_unavailable`
141
- * and the funding menu never advertised it in the first place.
142
- *
143
- * Only the *issue* path reaches through this. Settling goes via
144
- * {@link settleLightning}, which is where a settlement books its deposit.
118
+ * Optional receive-only Lightning funding leg. Issuance uses the wallet; polling uses the
119
+ * shared settlement hook. An absent leg refuses method:lightning.
145
120
  */
146
121
  lightning: {
147
122
  receive: LightningReceive;
@@ -154,28 +129,10 @@ interface CreditRouteDeps {
154
129
  * invoice on the same credit is swept with it.
155
130
  */
156
131
  settleLightning: (callerPubkey: string, creditId?: string) => Promise<void>;
157
- /** Hosted operator fee-token gate; absent on self-hosted DVMs. */
132
+ /** Hosting gate around a fresh funding operation, after caller auth and before any rail effect. */
133
+ withFundingAdmission?: (c: Context<AppEnv>, body: CreditRequest, run: () => Promise<Response>) => Promise<Response>;
158
134
  tempoSettlementReadiness?: TempoSettlementReadiness;
159
135
  }
160
- /**
161
- * `POST /v1/credit` — the caller-facing surface of the credits settlement
162
- * layer (the funding-menu and signed-operation contract). Three ops on one signed, replay-protected
163
- * envelope, mirroring `/v1/job`'s auth discipline exactly:
164
- *
165
- * - **fund** — a top-up with no job attached. The rail artifact rides the same
166
- * headers as `/v1/job` (`X-Cashu` + `X-Cashu-Request-Id`, `X-PAYMENT`,
167
- * `Authorization: Payment …`) and a missing or bad one comes back as the
168
- * same 402 envelope, which is what lets a caller's existing resumable-submit
169
- * machinery drive a top-up with no new client code.
170
- * - **balance** — what do I hold here, including expired credits (their value
171
- * is still the caller's), plus the funding menu, so the same read
172
- * also answers what may be added.
173
- * - **drain** — reclaim the unspent balance (the reclaim contract). One
174
- * op is both the request and the poll/pickup: the first call debits the
175
- * available balance into a `pending` liability; re-polling the same
176
- * `drain_id` returns the current state, delivers the parked Cashu token
177
- * when the builder's batch job has parked it, and is idempotent throughout.
178
- */
179
136
  declare function handleCreditRequest(c: Context<AppEnv>, deps: CreditRouteDeps): Promise<Response>;
180
137
 
181
138
  /**
@@ -192,61 +149,24 @@ type InitLockPool = Pick<Pool, "connect"> & {
192
149
  };
193
150
  };
194
151
  /**
195
- * The single session advisory-lock key serializing **all** SDK boot-time
196
- * schema work against concurrent creators — two machines cold-booting one DVM
197
- * against a fresh database, or parallel test files sharing one DB.
198
- *
199
- * Postgres' `IF NOT EXISTS` existence check is not atomic against a concurrent
200
- * creator: two sessions running the same `CREATE TABLE IF NOT EXISTS` at once
201
- * can raise `duplicate key value violates unique constraint
202
- * "pg_type_typname_nsp_index"` (23505) in the loser, which at SDK boot is an
203
- * unhandled throw that kills the machine.
204
- *
205
- * Deliberately distinct from `PLATFORM_INIT_ADVISORY_LOCK` (17320917) — a
206
- * DVM's own database is not the platform database — and from the first-party
207
- * DVMs' own keys (cast 17320918, scrape 17320926, scribe 24700919). **A new
208
- * SDK store reuses this key rather than inventing a second one**: one key means
209
- * there is only ever one lock order, so the per-store lock-order inversion that
210
- * deadlocked can't recur.
152
+ * All SDK boot DDL shares one advisory-lock key. CREATE TABLE IF NOT EXISTS
153
+ * can still race in Postgres system catalogs across machines. Reusing one key
154
+ * also prevents inconsistent lock acquisition order between SDK stores.
211
155
  */
212
156
  declare const SDK_INIT_ADVISORY_LOCK = 17320927;
213
157
  /**
214
- * Run `fn` holding {@link SDK_INIT_ADVISORY_LOCK} on `db`. Every SDK
215
- * boot-path `CREATE TABLE IF NOT EXISTS` goes through here.
216
- *
217
- * Overlapping callers on the same pool share **one** acquisition: the first
218
- * connects and locks, concurrent and nested callers join the held lock, and
219
- * the last one out unlocks and releases the client. That keeps * deliberately-parallel store-init batch parallel — six `init()`s racing each
220
- * other would otherwise queue behind one another — and keeps the uncontended
221
- * cost at one extra round trip per boot phase rather than one per store.
222
- * Sharing is safe for the DDL, which is what this lock is for: it excludes
223
- * *other machines*, and within one process no two inits create the same table.
224
- * It is not by itself a mutex between same-pool callers — two of them
225
- * concurrently running one non-idempotent statement still race, so anything
226
- * riding this lock that isn't `CREATE … IF NOT EXISTS` must carry its own
227
- * conflict handling (`seedLockPubkeyState`'s `ON CONFLICT DO NOTHING`).
228
- *
229
- * Session-level (not `pg_advisory_xact_lock`) because the DDL runs in
230
- * autocommit with no enclosing transaction, so the lock and the unlock ride a
231
- * dedicated pinned client — advisory locks are session-scoped and the unlock
232
- * must land on the backend that holds it. Released in `finally` on every path
233
- * including throws: an SDK boot that died holding this lock would block every
234
- * sibling until its connection closed.
235
- *
236
- * Guarded DDL needs a second connection while the advisory-lock client stays
237
- * pinned. Pools with `max < 2` would starve boot and are rejected.
158
+ * Overlapping callers on one pool share a pinned session lock and run their
159
+ * guarded work in order. A nested call from the active callback is reentrant.
160
+ * The last caller unlocks, preserving protection against other pools/processes.
161
+ * DDL runs on another connection; pools smaller than two are rejected.
162
+ * The pinned client is released in finally, including guarded failures.
238
163
  */
239
164
  declare function withSdkInitLock<T>(db: InitLockPool, fn: () => Promise<T>): Promise<T>;
240
165
 
241
166
  /**
242
- * In-memory {@link CreditLedgerLike} for pool-less setups — devMode, direct
243
- * `createDVMServer` tests, and the in-process x402 money loop — mirroring the
244
- * `MemoryJobStore` precedent. Same semantics as the Postgres `CreditLedger`
245
- * (two-phase draws, replay-before-expiry, `draw_conflict`, gap-free
246
- * `ledger_seq`), minus durability and cross-machine safety: per-process only,
247
- * so production DVMs must use the Postgres ledger (the durable-ledger requirement).
248
- * Every mutating verb is synchronous between awaits, so operations are
249
- * atomic in-process; the `tx` handles are accepted and ignored.
167
+ * Per-process development/test ledger without durability or cross-machine safety. Mutations
168
+ * run synchronously between awaits; accepted tx handles are ignored. Production funding
169
+ * requires a durable ledger.
250
170
  */
251
171
  declare class MemoryCreditLedger implements CreditLedgerLike {
252
172
  /**
@@ -263,13 +183,10 @@ declare class MemoryCreditLedger implements CreditLedgerLike {
263
183
  private x402Settlements?;
264
184
  /** Internal disposable transaction snapshot. The caller must serialize every ledger access. */
265
185
  forkForTransaction(): MemoryCreditLedger;
266
- /** See {@link CreditLedger.useX402SettlementGate} — same contract. */
267
186
  useX402SettlementGate(gate: X402RefundSettlementGate): void;
268
187
  fund(args: Parameters<CreditLedgerLike["fund"]>[0]): Promise<CreditSnapshot>;
269
188
  draw(args: Parameters<CreditLedgerLike["draw"]>[0]): Promise<DrawResult>;
270
- /** See {@link CreditLedger.blockingX402Refund} — same contract. */
271
189
  blockingX402Refund(channelId: string | null | undefined, statuses: X402SettlementStatus[]): Promise<X402UnresolvedRefund | undefined>;
272
- /** The unresolved x402 refund that must stop an effect on `creditId`. */
273
190
  private blockingRefundForCredit;
274
191
  growDraw(args: Parameters<CreditLedgerLike["growDraw"]>[0]): Promise<GrownDrawResult>;
275
192
  settle(args: Parameters<CreditLedgerLike["settle"]>[0]): Promise<DrawResolution>;
@@ -316,7 +233,6 @@ declare class MemoryCreditLedger implements CreditLedgerLike {
316
233
  private findByPaymentHash;
317
234
  private fundSync;
318
235
  private drawSync;
319
- /** Mid-job top-up growth — see `CreditLedger.growDraw` for the semantics. */
320
236
  private growDrawSync;
321
237
  get(creditId: string, opts?: {
322
238
  nowMs?: number;
@@ -336,7 +252,6 @@ declare class MemoryCreditLedger implements CreditLedgerLike {
336
252
  limit: number;
337
253
  after?: StalePendingDrawCursor;
338
254
  }): Promise<DrawRecord[]>;
339
- /** Settled draws' native value for the credit an x402 channel funded. */
340
255
  earnedNativeForX402Channel(channelId: string): Promise<number | undefined>;
341
256
  getCreditByX402Channel(channelId: string): Promise<CreditSnapshot | undefined>;
342
257
  terminalizeTempoCredits(evidence: TempoCreditLossEvidence, _tx?: CreditLedgerQuerier): Promise<TempoCreditLoss[]>;
@@ -488,6 +403,7 @@ declare class PostgresJobStore implements StreamableJobStore, ReceiptIssuingStor
488
403
  heartbeatActiveJobs(jobIds: string[], now: number): Promise<void>;
489
404
  cancelStaleJob(jobId: string, expectedActivityBefore: number, reason: string, terminalStatus: "failed" | "cancelled"): Promise<boolean>;
490
405
  cancelJob(jobId: string, reason: string): Promise<boolean>;
406
+ cancelJobForHosting(jobId: string, reason: string): Promise<boolean>;
491
407
  getCounters(jobId: string): Promise<JobCounters | undefined>;
492
408
  claimForProcessing(jobId: string): Promise<boolean>;
493
409
  tryReactivationLock<T>(jobId: string, fn: () => Promise<T>): Promise<{
@@ -563,16 +479,8 @@ interface PostgresReplayStoreOpts {
563
479
  gcSampleRate?: number;
564
480
  }
565
481
  /**
566
- * Postgres-backed replay store implementing {@link SignedRequestReplayStore}.
567
- *
568
- * Cross-machine safe: relies on the PK on `(pubkey, timestamp, nonce)` with
569
- * `INSERT ... ON CONFLICT DO NOTHING` to detect duplicates atomically across
570
- * concurrent inserts from multiple machines. The consumer hands in a `Pool`
571
- * (matching `PostgresJobStore` / `PostgresKVStore`) and manages its lifecycle.
572
- *
573
- * Multi-machine deploys of secp256k1-auth'd DVMs SHOULD use this store to
574
- * close the per-process replay window — see {@link SignedRequestReplayStore}
575
- * for the threat model.
482
+ * The (pubkey, timestamp, nonce) primary key detects concurrent duplicates
483
+ * atomically across machines. The caller owns the pool lifecycle.
576
484
  */
577
485
  declare class PostgresReplayStore implements SignedRequestReplayStore {
578
486
  private pool;
@@ -598,18 +506,7 @@ declare function stripProtocolEnvelope(schema: unknown, data: unknown): unknown;
598
506
  declare function requestIdFromEnvelope(data: unknown): string | undefined;
599
507
  declare function hasInvalidRequestId(data: unknown): boolean;
600
508
 
601
- /**
602
- * Convenience one-liner over {@link createDVMHost}. For
603
- * single-DVM hosts, `serve(dvm, opts)` is equivalent to
604
- * `createDVMHost(opts).mount(dvm).serve()`. Multi-DVM hosts go through
605
- * `createDVMHost` directly so each mount can carry its own prefix.
606
- *
607
- * This is **shorthand-over-host**, not a parallel code path — every wiring
608
- * step (Cashu/MPP/x402 envelope resolution, platform reporter, db, fx) flows
609
- * through `createDVMHost`. First-party DVMs that use `serve(...)` are NOT
610
- * exposed to the wiring-drift bug class fixed in 485/511, which was
611
- * about bypassing the host entirely. There is no migration to do.
612
- */
509
+ /** Single-DVM host. Use createDVMHost for multiple mounts with distinct prefixes. */
613
510
  declare function serve<State, InputSchema extends ZodLike | undefined = undefined>(descriptor: DVMDescriptor<State, InputSchema>, opts?: DVMHostOpts): Promise<DVMServeResult>;
614
511
 
615
- export { BlockedInvoiceCursor, CREDIT_REQUEST_SCHEMA, CreditInvoiceRecord, CreditLedgerLike, CreditLedgerQuerier, CreditMenu, type CreditRequest, type CreditRouteDeps, CreditSnapshot, DVMAuthScheme, DVMHostOpts, DVMServeResult, DrawRecord, DrawResolution, DrawResult, FundingRecord, GrownDrawResult, IMPLICIT_CREDIT_TTL_MS, type InitLockPool, InvoiceReconciliation, InvoiceSettlement, InvoiceWriteOff, JobRecord, LightningReceive, MemoryCreditLedger, PostgresJobStore, PostgresKVStore, PostgresReplayStore, type PostgresReplayStoreOpts, REQUEST_ID_FIELD, type ResolvedCashuOpts, SDK_INIT_ADVISORY_LOCK, SignedRequestDomain, SignedRequestReplayStore, StalePendingDrawCursor, StreamableJobStore, handleCreditRequest, hasInvalidRequestId, protocolEnvelopeIgnoreFields, requestIdFromEnvelope, resolveCashuOptsFromEnv, serve, stripProtocolEnvelope, withSdkInitLock };
512
+ export { BitcoinDepositLiability, BlockedInvoiceCursor, CREDIT_REQUEST_SCHEMA, CreditInvoiceRecord, CreditLedgerLike, CreditLedgerQuerier, CreditMenu, type CreditRequest, type CreditRouteDeps, CreditSnapshot, DVMAuthScheme, DVMHostOpts, DVMServeResult, DrawRecord, DrawResolution, DrawResult, FundingRecord, GrownDrawResult, IMPLICIT_CREDIT_TTL_MS, type InitLockPool, InvoiceReconciliation, InvoiceSettlement, InvoiceWriteOff, JobRecord, LightningReceive, MemoryCreditLedger, PostgresJobStore, PostgresKVStore, PostgresReplayStore, type PostgresReplayStoreOpts, REQUEST_ID_FIELD, type ResolvedCashuOpts, SDK_INIT_ADVISORY_LOCK, SignedRequestDomain, SignedRequestReplayStore, StalePendingDrawCursor, StreamableJobStore, handleCreditRequest, hasInvalidRequestId, protocolEnvelopeIgnoreFields, requestIdFromEnvelope, resolveCashuOptsFromEnv, serve, stripProtocolEnvelope, withSdkInitLock };