@arkade-os/swap 0.1.0-rc.2 → 0.1.0-rc.20

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 (54) hide show
  1. package/README.md +52 -2
  2. package/dist/advanced.cjs +8376 -0
  3. package/dist/advanced.d.cts +550 -0
  4. package/dist/advanced.d.ts +550 -0
  5. package/dist/advanced.js +451 -0
  6. package/dist/chunk-A3SHHRX4.js +104 -0
  7. package/dist/chunk-HUQQVBC4.js +4262 -0
  8. package/dist/{chunk-EOYGUCDM.js → chunk-ITFCQWPG.js} +755 -1382
  9. package/dist/chunk-PVB7EBAM.js +2517 -0
  10. package/dist/errors-C3h8ANmE.d.ts +1560 -0
  11. package/dist/errors-hm7aqnRM.d.cts +1560 -0
  12. package/dist/index.cjs +4861 -3988
  13. package/dist/index.d.cts +69 -2812
  14. package/dist/index.d.ts +69 -2812
  15. package/dist/index.js +179 -3719
  16. package/dist/lockupContract-5r5RlgOJ.d.cts +137 -0
  17. package/dist/lockupContract-5r5RlgOJ.d.ts +137 -0
  18. package/dist/node/index.cjs +61 -10
  19. package/dist/node/index.d.cts +249 -591
  20. package/dist/node/index.d.ts +249 -591
  21. package/dist/node/index.js +65 -10
  22. package/dist/nostr.cjs +191 -11
  23. package/dist/nostr.d.cts +23 -68
  24. package/dist/nostr.d.ts +23 -68
  25. package/dist/nostr.js +3 -4
  26. package/dist/offer-Bd9Yvd8Z.d.ts +261 -0
  27. package/dist/offer-F88rtL_I.d.cts +261 -0
  28. package/dist/protocol.cjs +4086 -3706
  29. package/dist/protocol.d.cts +163 -768
  30. package/dist/protocol.d.ts +163 -768
  31. package/dist/protocol.js +190 -173
  32. package/dist/repositories/realm/index.cjs +55 -11
  33. package/dist/repositories/realm/index.d.cts +18 -30
  34. package/dist/repositories/realm/index.d.ts +18 -30
  35. package/dist/repositories/realm/index.js +49 -12
  36. package/dist/repositories/sqlite/index.cjs +61 -10
  37. package/dist/repositories/sqlite/index.d.cts +7 -6
  38. package/dist/repositories/sqlite/index.d.ts +7 -6
  39. package/dist/repositories/sqlite/index.js +57 -11
  40. package/dist/repository-BuYWGAKz.d.cts +2261 -0
  41. package/dist/repository-DYnRLPt-.d.ts +2261 -0
  42. package/dist/rfq-60PGpQ_x.d.cts +950 -0
  43. package/dist/rfq-60PGpQ_x.d.ts +950 -0
  44. package/dist/watch-BTyiBLSd.d.ts +74 -0
  45. package/dist/watch-M_KY-5ho.d.cts +74 -0
  46. package/package.json +20 -10
  47. package/dist/chunk-LYCMM3VB.js +0 -1357
  48. package/dist/chunk-U7VWWTL6.js +0 -66
  49. package/dist/repository-_zU9_pM3.d.cts +0 -3426
  50. package/dist/repository-kO95noyv.d.ts +0 -3426
  51. package/dist/rfq-DdBV4JO5.d.cts +0 -1097
  52. package/dist/rfq-DdBV4JO5.d.ts +0 -1097
  53. package/dist/watch-CQqvwgwY.d.cts +0 -96
  54. package/dist/watch-wMbmfN4p.d.ts +0 -96
@@ -0,0 +1,550 @@
1
+ import { A as AssetAliasTable, C as CorridorFactory, a as ArkadeCorridorDeps, L as LightningCorridorDeps, O as OnchainCorridorDeps, b as CorridorSet, D as DiscoveryIndex, S as SwapPolicy, c as DiscoveryLeg, M as MarketCandidate, d as DiscoverySnapshot } from './errors-hm7aqnRM.cjs';
2
+ export { e as AcceptConflict, f as AcceptInput, g as AmbiguousDestination, h as AmountEncodingUnsupported, i as AmountMismatch, j as AssetRfqPreparation, k as AttestingRfqTransport, l as CORRIDOR_FACTORIES, m as CancelInput, n as CancelOutcome, o as ClaimedDestination, p as ClientDisposed, q as CorridorBase, r as CorridorClaim, s as CorridorCovenant, t as CorridorDeadline, u as CorridorDeps, v as CorridorDepsByCorridor, w as CorridorDrive, x as CorridorLockup, y as CorridorModule, z as CorridorOverrides, B as CorridorPass, E as CorridorRfqPreparation, F as DiscoveryConfig, G as DiscoveryIndexInput, H as DiscoverySnapshotUnavailable, I as DriveMode, J as DriveRefusal, K as ExchangeOptions, N as FEED_TTL_MS, P as FeeCeiling, Q as FeedFetch, R as FeedQuoteInput, T as INDEXED_NETWORKS, U as InconsistentRoute, V as InsufficientFunds, W as LockupOwner, X as Market, Y as MaxFeeExceeded, Z as MissingCorridorDep, _ as NotCancellable, $ as ONCHAIN_CLAIM_FEE_RATE_SATVB, a0 as ObservationSeam, a1 as OfferPreparation, a2 as OnchainClaim, a3 as OperatorUnreachable, a4 as ParsedRfqQuote, a5 as PayOptions, a6 as PayResult, a7 as QuoteCheck, a8 as QuoteExpired, a9 as QuotePreparation, aa as QuoteVerificationFailed, ab as REGISTRY_URL, ac as ReceiveArtifact, ad as ReceiveOptions, ae as ReceiveRequest, af as RecoveryResult, ag as RegisteredAsset, ah as RfqAuctionPolicy, ai as RfqPreparation, aj as RfqQuoteInput, ak as RfqRendezvous, al as RfqTransportFactory, am as RouteSide, an as SWAP_ERROR_NAMES, ao as SwapClient, ap as SwapClientConfig, aq as SwapDrive, ar as SwapDriveConfig, as as SwapDriveRefusedError, at as SwapError, au as SwapErrorName, av as SwapFilter, aw as UnsupportedRoute, ax as VerbDeps, ay as acceptQuote, az as attesting, aA as cancelSwap, aB as canonicalAssetId, aC as cardMarketOf, aD as chooseMarket, aE as conflictingFields, aF as corridorSet, aG as createSwapClient, aH as createSwapDrive, aI as discoveryIndex, aJ as eligibleMarkets, aK as enforceFeeCeiling, aL as exchange, aM as feedFetch, aN as feedSpread, aO as isAddressable, aP as isCardMarket, aQ as isIndexedNetwork, aR as isSwapError, aS as isUsableCard, aT as liveArkadeInfo, aU as marketBackendOf, aV as marketKeyOf, aW as marketRefOf, aX as nostrTransportFactory, aY as parseRfqQuote, aZ as pay, a_ as quoteFromFeed, a$ as quoteViaRfq, b0 as readableRecord, b1 as receive, b2 as resolveCorridorBase, b3 as resolveCorridorDeps, b4 as rfqLeg, b5 as rfqPairFor, b6 as swapRecordOf, b7 as toDiscoveryLeg, b8 as usableMarkets, b9 as verifyPlanLegs, ba as withCanonicalAmount } from './errors-hm7aqnRM.cjs';
3
+ import { DiscoveredMarket } from '@arkade-os/solver-discovery';
4
+ import { N as NetworkRef, C as Corridor, A as AssetId, R as Rail, a as RfqSwapRecordStore, b as CorridorSwapRecord, Q as QuoteId, c as AssetSwapStatus, S as SwapRecord, O as OfferSwapRecord, d as AssetSwapRepository, e as RfqSwapRecord, f as RfqSwapPageFilter, g as RfqSwapPageCursor, h as AssetSwap, L as LockupSpendIndexer, i as RouteResolution, j as ResolvedEndpoint, P as PinnedAmount, I as Instrument, k as Route, l as QuoteInput, m as Pubkey } from './repository-BuYWGAKz.cjs';
5
+ export { n as ACTIVITY_TOKEN, o as ARKADE_ASSET_NAMESPACE, p as Amount, q as AmountFormatError, r as AmountOn, s as AmountRefusal, t as Artifact, u as AssetIdError, v as AssetIdRefusal, w as AssetNamespace, x as AssetOn, y as AssetPart, z as AssetRef, B as AssetScale, D as AssetSwapId, E as AtomicDecimal, F as AuctionMarketRef, G as AuctionProvenance, H as BITCOIN_RAILS, J as BTC_ASSET_PART, K as BitcoinRail, M as CORRIDORS, T as CORRIDOR_PASS, U as CardMarketRef, V as CorridorId, W as CorridorKind, X as DepositArtifact, Y as DisplayDecimal, Z as Endpoint, _ as Ep, $ as Hex, a0 as LOCKUP_OWNER, a1 as MarketBackend, a2 as MarketRef, a3 as OFFER_SWAP_ID_PREFIX, a4 as Outcome, a5 as ParsedAssetId, a6 as Quote, a7 as QuoteLeg, a8 as RAILS, a9 as RFQ_SWAP_ID_PREFIX, aa as RailOf, ab as RankedBid, ac as RawState, ad as RecordedArtifact, ae as RecordedEndpoint, af as RecordedInstrument, ag as RecordedLeg, ah as RestoredMarketRef, ai as RfqAmountSide, aj as SnapshotRef, ak as Swap, al as SwapFamily, am as SwapRecordCommon, an as SwapUpdate, ao as Unsubscribe, ap as arkadeAsset, aq as artifactOf, ar as assetPartOf, as as assetSwapIdOf, at as bitcoinNetworkOf, au as btcAssetPart, av as btcOn, aw as corridorOfRail, ax as corridorOutcome, ay as decodeRfqAmount, az as encodeRfqAmount, aA as familyOfSwapId, aB as formatAssetId, aC as fromAtomicDecimal, aD as fromRfqAmountSide, aE as fundsFromWallet, aF as instrumentOf, aG as isAssetId, aH as isAtomicDecimal, aI as isBtcAsset, aJ as isBtcAssetLenient, aK as isNetworkRef, aL as issuanceOf, aM as legOf, aN as offerOutcome, aO as parseAssetId, aP as quoteIdOfSwapId, aQ as railOf, aR as railOfCorridor, aS as readsChain, aT as recordArtifact, aU as recordEndpoint, aV as recordInstrument, aW as recordLeg, aX as recordOutcome, aY as sameAsset, aZ as swapOf, a_ as toAtomicDecimal, a$ as toRfqAmountSide, b0 as toSafeNumber } from './repository-BuYWGAKz.cjs';
6
+ import { I as InvoiceFacts, C as ChainSource, R as RfqQuote } from './rfq-60PGpQ_x.cjs';
7
+ export { S as SwapRefusal } from './rfq-60PGpQ_x.cjs';
8
+ import * as btc from '@scure/btc-signer';
9
+ import { OnchainProvider, NetworkName, PageRequest, PageResult, IWallet, VHTLC } from '@arkade-os/sdk';
10
+ import { O as OfferSpendChanges, a as OfferSwapFacts, b as OfferSwapSource } from './watch-M_KY-5ho.cjs';
11
+ import './offer-F88rtL_I.cjs';
12
+
13
+ /**
14
+ * The alias table, filled from discovery: the inverse of `toDiscoveryLeg`, mapping a card's
15
+ * corridor and `AssetInfo` back to the public id a caller may write, plus its ticker.
16
+ *
17
+ * Tickers are display metadata, never identity, so `canonicalAssetId` refuses a ticker naming two
18
+ * assets. Rows dedupe by id and ticker, so nine solvers listing one asset is one row.
19
+ */
20
+
21
+ /**
22
+ * The public id for one side of a card, or `undefined` when not expressible: an arkade-issued
23
+ * asset on lightning or L1, or an id that is neither BTC nor the identity form.
24
+ */
25
+ declare const publicAssetId: (corridor: Corridor, assetId: string, network: NetworkRef) => AssetId | undefined;
26
+ /** Every asset the snapshot names, as caller-writable ids and their tickers. */
27
+ declare const aliasTableFrom: (markets: readonly DiscoveredMarket[], network: NetworkRef) => AssetAliasTable;
28
+ /**
29
+ * The table narrowed to one rail.
30
+ *
31
+ * BTC has one id per rail (Q12), so a whole-table lookup of `"BTC"` would collide and refuse. The
32
+ * leg's rail is already fixed (by destination, `via`, or being the wallet's side), so resolving on
33
+ * it is a fact, not a preference. Collisions within a rail (two arkade `USDT`s) still refuse.
34
+ */
35
+ declare const scopedToRail: (table: AssetAliasTable, rail: Rail) => AssetAliasTable;
36
+
37
+ /** BOLT11's default expiry when an invoice carries no `x` tag. */
38
+ declare const DEFAULT_INVOICE_EXPIRY_SECONDS = 3600;
39
+ /**
40
+ * Decode a BOLT11 invoice into the facts the corridor needs.
41
+ *
42
+ * Signature-blind, like the library: it does not prove who issued the invoice, only that the
43
+ * payment hash compared downstream is the one the payer would pay to.
44
+ *
45
+ * @throws when the string is not a decodable BOLT11 invoice, or decodes without
46
+ * the timestamp or payment hash BOLT11 requires.
47
+ */
48
+ declare const decodeBolt11: (invoice: string) => InvoiceFacts;
49
+
50
+ /** The chain tip, as the two reads that need it want it. */
51
+ interface L1Tip {
52
+ height: number;
53
+ /** Median-time-past, unix seconds. */
54
+ mtp: number;
55
+ }
56
+ /** What the adapter reads L1 through: core's provider, plus the one fact its
57
+ * interface does not promise. */
58
+ interface ChainSourceBackend {
59
+ provider: OnchainProvider;
60
+ tip(): Promise<L1Tip>;
61
+ }
62
+ /** The address parameters an output script is encoded under. Structural, so
63
+ * core's `Network` and `L1_NETWORKS`' entries both satisfy it directly. */
64
+ type AddressParams = typeof btc.NETWORK;
65
+ /**
66
+ * A {@link ChainSource} over an arbitrary L1 backend, so a caller with its own `OnchainProvider`
67
+ * can reuse the adapter logic, and tests can run it without a server.
68
+ */
69
+ declare const chainSourceOver: (backend: ChainSourceBackend, network: AddressParams) => ChainSource;
70
+ /**
71
+ * Tip height and median-time-past off Esplora's `/blocks`. Not `/blocks/tip`: that is not in the
72
+ * Esplora spec (electrs aliases it, mempool answers an empty array).
73
+ */
74
+ declare const esploraTip: (esploraUrl: string, fetchImpl?: typeof fetch) => Promise<L1Tip>;
75
+ /** The default: core's Esplora provider at `esploraUrl`, with the tip read off
76
+ * `/blocks` beside it. */
77
+ declare const esploraChainSource: (input: {
78
+ /** Esplora REST base — the corridor's override, or `ESPLORA_URL[network]`. */
79
+ esploraUrl: string;
80
+ /** Address parameters for the script-to-address encode. */
81
+ network: AddressParams;
82
+ /** For hosts without a global `fetch`, and for tests. Only the `/blocks`
83
+ * read takes it: core's provider carries its own fetch wrapper. */
84
+ fetchImpl?: typeof fetch;
85
+ }) => ChainSource;
86
+
87
+ declare const arkadeCorridor: CorridorFactory<ArkadeCorridorDeps>;
88
+
89
+ /**
90
+ * The lightning corridor: a BOLT11 invoice, on this wallet's network.
91
+ *
92
+ * Core's `isLightningInvoice` checks shape only (no checksum, no decode), so the network
93
+ * match and decode happen here. `lntbs` is both signet and mutinynet, so a
94
+ * signet-versus-mutinynet mismatch is not detectable; `lnsb` (simnet) passes core's regex
95
+ * but names no `NetworkName`, so it is refused rather than mapped to a neighbour.
96
+ *
97
+ * Gates owned here: HRP, invoice expiry, amountless refusal. Gates that need the quote
98
+ * (e.g. headroom vs `quote.refund_locktime`) belong to the quote path.
99
+ */
100
+
101
+ /**
102
+ * Which networks an invoice HRP can belong to. Ordered, not a record: `lnbcrt` must be
103
+ * tested before `lnbc` and `lntbs` before `lntb`.
104
+ */
105
+ declare const INVOICE_HRPS: readonly [readonly ["lnbcrt", readonly ["regtest"]], readonly ["lntbs", readonly ["signet", "mutinynet"]], readonly ["lnbc", readonly ["bitcoin"]], readonly ["lntb", readonly ["testnet"]]];
106
+ /** The networks `raw`'s HRP names, or `undefined` for one no network claims. */
107
+ declare const networksOfInvoiceHrp: (raw: string) => readonly NetworkName[] | undefined;
108
+ /**
109
+ * Both directions, with ownership inverted. `arkade -> lightning`: the trader funds the
110
+ * lockup, so `refundLocktime` is a moment to refund AFTER (the solver claims with the
111
+ * preimage it learns by paying). `lightning -> arkade`: the solver funds it, the trader
112
+ * has no refund, and the deadline is a moment to have claimed BEFORE.
113
+ */
114
+ declare const LIGHTNING_DRIVE: {
115
+ readonly give: {
116
+ readonly lockups: readonly [{
117
+ readonly covenant: "arkade_lockup";
118
+ readonly owner: "solver";
119
+ readonly deadline: "refund_locktime";
120
+ }];
121
+ readonly actions: readonly ["claimLockup"];
122
+ readonly seams: readonly ["indexer"];
123
+ };
124
+ readonly take: {
125
+ readonly lockups: readonly [{
126
+ readonly covenant: "arkade_lockup";
127
+ readonly owner: "trader";
128
+ readonly deadline: "refund_locktime";
129
+ }];
130
+ readonly actions: readonly ["refundArkade"];
131
+ readonly seams: readonly ["indexer"];
132
+ };
133
+ };
134
+ declare const lightningCorridor: CorridorFactory<LightningCorridorDeps>;
135
+
136
+ /**
137
+ * One direction only. `onchain -> arkade` is deliberately absent: it adds an L1 half the
138
+ * trader funds and must refund itself, and declaring only the lockup half would yield a
139
+ * manager that silently lets the trader's L1 refund window pass.
140
+ *
141
+ * On `arkade -> onchain` the two covenants have different owners: the Arkade lockup is
142
+ * the trader's (`refundLocktime` = money comes back), but the L1 HTLC's refund leaf is
143
+ * the solver's, so reaching `htlc.refundLocktime` means the claim was missed.
144
+ */
145
+ declare const ONCHAIN_DRIVE: {
146
+ readonly take: {
147
+ readonly lockups: readonly [{
148
+ readonly covenant: "arkade_lockup";
149
+ readonly owner: "trader";
150
+ readonly deadline: "refund_locktime";
151
+ }, {
152
+ readonly covenant: "onchain_htlc";
153
+ readonly owner: "solver";
154
+ readonly deadline: "htlc_refund_locktime";
155
+ }];
156
+ readonly actions: readonly ["claimOnchain", "refundArkade"];
157
+ readonly seams: readonly ["indexer", "chain"];
158
+ };
159
+ };
160
+ declare const onchainCorridor: CorridorFactory<OnchainCorridorDeps>;
161
+
162
+ /**
163
+ * The seams between the v2 record store and v1's drive machinery.
164
+ *
165
+ * **The record bridge is the load-bearing one.** `RfqSwapManager` restores from `getRfqSwapsPage()`,
166
+ * while `accept()` writes `saveSwapRecord` into a disjoint keyspace, so without this file the
167
+ * manager's restore returns nothing for every v2-accepted swap. {@link CorridorSwapRecord} carries
168
+ * every {@link RfqSwapRecord} field but the ignored display `amount`, which keeps the bridge cheap.
169
+ *
170
+ * - **The store is wired as the manager's `repository` dep**: `restoreFromRepository` opens with
171
+ * `requireRepository`, so leaving it unwired would mean a hand-rolled restore.
172
+ * - **It carries an `rfqId -> QuoteId` index**: manager callbacks key on `rfqId`. Without it
173
+ * `arkadeRefunder` misses its record and throws `RefundNotLocallyPossibleError` — which the
174
+ * manager reads as PERMANENT — blocking every v2 send leg for its refund window with funds locked.
175
+ * - **`removeRfqSwap` is inert**: `restoreFromRepository` runs `dropRetired` first, which would
176
+ * hard-delete v2 records under v1's thirty-day retention before `client.ready` resolves. v2
177
+ * retention is still undecided. The manager still drops its in-memory copy; the record survives.
178
+ */
179
+
180
+ /** Every stored corridor record, and every offer record, in one read. */
181
+ declare const splitRecords: (records: readonly SwapRecord[]) => {
182
+ corridor: CorridorSwapRecord[];
183
+ offer: OfferSwapRecord[];
184
+ };
185
+ /** A v2 corridor record as the manager's own record type, minus the display `amount`
186
+ * (`rebuildRfqSwap` reads none, and inventing one would record a number no request produced). */
187
+ declare const rfqRecordOf: (record: CorridorSwapRecord) => RfqSwapRecord;
188
+ /**
189
+ * The manager's mutable half, written back onto the v2 record. REPLACED, not merged (as
190
+ * `updateRfqSwapRecord` does): the manager clears `blockedReason`/`claimFailure`, and a spread could
191
+ * never clear them, leaving a stale refusal reading as live. The origin half, `fundingTxid`
192
+ * included, is carried through untouched — the manager never learns it.
193
+ */
194
+ declare const withRfqState: (record: CorridorSwapRecord, state: RfqSwapRecord) => CorridorSwapRecord;
195
+ /** One keyset page over records already in memory, in the repository's `(updatedAt, rfqId)` order. */
196
+ declare const pageRfqRecords: (records: readonly RfqSwapRecord[], filter: RfqSwapPageFilter, page: PageRequest<RfqSwapPageCursor>) => PageResult<RfqSwapRecord, RfqSwapPageCursor>;
197
+ /** What a bridge or source hands back to the drive after a write. */
198
+ type RecordSink = (record: SwapRecord) => void;
199
+ interface CorridorRecordStore extends RfqSwapRecordStore {
200
+ /** Remember which quote id an `rfqId` belongs to, so a callback keyed on
201
+ * the manager's id can find the v2 record. Called at restore and at admit. */
202
+ index(record: CorridorSwapRecord): void;
203
+ /** The quote id for a manager-side `rfqId`, if this store has seen it. */
204
+ quoteIdOf(rfqId: string): QuoteId | undefined;
205
+ }
206
+ /**
207
+ * The v2 record store, as the manager's `repository` dep. Every read goes to the repository (the
208
+ * system of record), so a consumer's edit is never overwritten by a boot-time copy. Only the index
209
+ * is in memory; a miss costs one scan, never a wrong answer.
210
+ */
211
+ declare const corridorRecordStore: (repository: AssetSwapRepository, onRecord?: RecordSink,
212
+ /**
213
+ * Which stored records the restore may hand to the manager. Two cases:
214
+ * - an `arkade -> onchain` record on a client whose chain source was refused — the manager would
215
+ * fail it TERMINALLY on its first pass; excluded, it stays durable, undriven and self-reporting;
216
+ * - a terminal record, which the manager would rebuild only to file as finished (a covenant
217
+ * derivation and row lookup for nothing). It stays readable in the drive's registry.
218
+ */
219
+ admits?: (record: CorridorSwapRecord) => boolean) => CorridorRecordStore;
220
+ /** A v2 offer record as the watcher and coverage read one. */
221
+ declare const offerFactsOf: (record: OfferSwapRecord) => OfferSwapFacts & {
222
+ id: QuoteId;
223
+ };
224
+ /** The v2 offer half of the record store, as the watcher's source. */
225
+ declare const offerRecordSource: (repository: AssetSwapRepository, onRecord?: RecordSink, now?: () => number) => OfferSwapSource<OfferSwapFacts & {
226
+ id: QuoteId;
227
+ }>;
228
+ /** One classified spend, written onto a v2 offer record. */
229
+ declare const applyOfferSpend: (record: OfferSwapRecord, changes: OfferSpendChanges, now: number) => OfferSwapRecord;
230
+ /** What the restore scan learned about one deposit. */
231
+ interface DepositFate {
232
+ readonly status: AssetSwapStatus;
233
+ readonly spentTxid?: string;
234
+ /** Unix milliseconds, as `AssetSwap` carries it. */
235
+ readonly completedAt?: number;
236
+ }
237
+ /** A deposit's fate written onto its record. The spend too: the watcher only
238
+ * writes a spend it saw, and it sees nothing between two clients. */
239
+ declare const withDepositFate: (record: OfferSwapRecord, fate: DepositFate, now: number) => OfferSwapRecord;
240
+ /** Whether the fate says anything the record does not; the write it gates re-emits the swap. */
241
+ declare const fateMoved: (record: OfferSwapRecord, fate: DepositFate) => boolean;
242
+ /**
243
+ * An offer record for a deposit the restore scan found and no record claims. Keyed on the funding
244
+ * txid so a re-scan updates rather than duplicates. The chain lacks the market, solver, spread and
245
+ * deadline, hence `market.kind: "restored"` and a zero fee.
246
+ */
247
+ declare const restoredOfferRecord: (swap: AssetSwap, network: NetworkRef, now: number) => OfferSwapRecord;
248
+ /**
249
+ * A corridor record for a v1 `rfqSwaps` row. v1 kept one display `amount` and no quote, invoice or
250
+ * solver key, so both legs carry that amount, the fee is zero, Lightning legs stand in as
251
+ * `wallet`, and `market.kind` is `"restored"`. Throws when the row has no payment hash or its
252
+ * lockup address does not decode.
253
+ */
254
+ declare const restoredCorridorRecord: (stored: RfqSwapRecord, network: NetworkRef, refundLocktime: number) => CorridorSwapRecord;
255
+ /**
256
+ * The wallet's own reader, as the manager's required observation seam. The reader reads NAMED
257
+ * foreign scripts and has no "own wallet" default, so a call with neither scripts nor outpoints is a
258
+ * caller bug. Built from the wallet (the client takes no server URL or provider); the drive still
259
+ * takes it as an input so unit tests can double it.
260
+ */
261
+ declare const walletLockupIndexer: (wallet: IWallet) => LockupSpendIndexer;
262
+
263
+ /**
264
+ * Route resolution: the single place `to` is parsed, the corridor pair decided, the
265
+ * amount pinned and the market chosen — everything before a solver is told anything.
266
+ *
267
+ * The order (§3.1) is load-bearing: `to` first (needs no market data); the pair selects
268
+ * the `Route` variant, refusing unsupported pairs before any round trip or record; only
269
+ * then the market index, since tickers resolve against the cards themselves. Exactly one
270
+ * amount may be pinned; two is `AmountMismatch`, thrown here so nothing is disclosed.
271
+ */
272
+
273
+ /** The four implemented corridor pairs, spelled as the route union spells them. */
274
+ declare const SUPPORTED_PAIRS: readonly ["arkade->arkade", "arkade->lightning", "lightning->arkade", "arkade->onchain"];
275
+ type SupportedPair = (typeof SUPPORTED_PAIRS)[number];
276
+ interface ResolveDeps {
277
+ readonly corridors: CorridorSet;
278
+ /** The network the wallet reported; every defaulted asset id is on it. */
279
+ readonly network: NetworkName;
280
+ readonly discovery: DiscoveryIndex;
281
+ readonly policy?: SwapPolicy;
282
+ /**
283
+ * `resolve()` reads what is in hand; `quote()` may fetch. A flag, not two functions,
284
+ * so the resolution a caller vetoed is exactly the one they quote.
285
+ */
286
+ readonly mode: "resolve" | "quote";
287
+ }
288
+ /** What the quote path needs from a resolution, over what a caller sees. */
289
+ interface ResolvedRoute {
290
+ readonly resolution: RouteResolution;
291
+ /** Both legs in discovery's vocabulary — what the market lookup matched on. */
292
+ readonly legs: {
293
+ readonly give: DiscoveryLeg;
294
+ readonly take: DiscoveryLeg;
295
+ };
296
+ readonly give: ResolvedEndpoint;
297
+ readonly take: ResolvedEndpoint;
298
+ readonly pair: SupportedPair;
299
+ readonly candidates: readonly MarketCandidate[];
300
+ /** The chosen card, absent when nothing eligible survived. */
301
+ readonly market?: MarketCandidate;
302
+ readonly snapshot: DiscoverySnapshot;
303
+ readonly amount?: PinnedAmount;
304
+ /** The alias table the snapshot produced, so the quote path can reuse it. */
305
+ readonly aliases: AssetAliasTable;
306
+ }
307
+ /**
308
+ * Assemble the closed `Route` from two fully-instrumented legs.
309
+ *
310
+ * The quote path's one cast: the type checker cannot correlate `corridor` and `asset`,
311
+ * so the runtime re-check turns a broken invariant into a throw rather than a covenant
312
+ * built against the wrong rail.
313
+ */
314
+ declare const assembleRoute: (give: ResolvedEndpoint & {
315
+ instrument: Instrument;
316
+ }, take: ResolvedEndpoint & {
317
+ instrument: Instrument;
318
+ }) => Route;
319
+ declare const resolveRoute: (input: QuoteInput, deps: ResolveDeps) => Promise<ResolvedRoute>;
320
+
321
+ /** A `number` of sats from atomic units, or {@link AmountEncodingUnsupported}. */
322
+ declare const satsOf: (value: bigint, field: string) => number;
323
+
324
+ /**
325
+ * Quote verification as one invariant: every check runs once, on both backends, before any quote
326
+ * is returned, and every failure is one error class naming the check.
327
+ *
328
+ * The gates themselves stay `rfq.ts`'s (audited, and carrying the covenant-mirroring timing
329
+ * constants); this only maps a gate's stable `reason` to a {@link QuoteCheck}.
330
+ *
331
+ * Two failures are deliberately NOT verification failures: a solver declining is `SwapRefusal`,
332
+ * and an expired or expiring quote is `QuoteExpired` (the remedy is a fresh quote, not a
333
+ * different solver).
334
+ */
335
+
336
+ /**
337
+ * The fifth check: who answered.
338
+ *
339
+ * Run here, not left to the transport, so swapping in a different transport cannot disable it.
340
+ * Addressed mode only: published RFQ attributes each bid by its own signature.
341
+ *
342
+ * `pinnable` is the trust boundary: a cached card's `discovery_pubkey` is unvalidated (anyone with
343
+ * write access to browser storage could choose it), so a cache-sourced key fails closed.
344
+ */
345
+ declare const verifyResponder: (input: {
346
+ /** The key this transport proves every reply came from, if it proves one. */
347
+ readonly attested?: Pubkey;
348
+ /** The card's `discovery_pubkey`. */
349
+ readonly expected?: Pubkey;
350
+ /** Whether `expected` came from a source that can be trusted to name it. */
351
+ readonly pinnable: boolean;
352
+ }) => void;
353
+ /**
354
+ * The pair check, run here as well as in the transport's `expectQuote`, so a transport that skips
355
+ * it (or one a caller injected) cannot make the quote path skip it too.
356
+ */
357
+ declare const verifyPair: (quoted: unknown, requested: string) => void;
358
+ /**
359
+ * Derive the covenant, and fold every way that can fail into the `lockup_address` check.
360
+ *
361
+ * `AddressMismatch` is that check under its v1 name; a missing binding field or malformed solver
362
+ * hex is the same check reached earlier. All mean "do not fund this".
363
+ */
364
+ declare const verifyingDerivation: <T>(derive: () => T) => T;
365
+ /**
366
+ * The send legs' window gate: the quote's own expiry, the refund headroom, and
367
+ * — on `arkade -> onchain` — the L1 confirmation window and the timelock order
368
+ * between the two contracts.
369
+ */
370
+ declare const verifySendWindow: (input: {
371
+ readonly quote: RfqQuote;
372
+ readonly quoteId: QuoteId;
373
+ readonly now: number;
374
+ readonly invoiceExpiresAt?: number;
375
+ readonly onchain?: {
376
+ htlcLocktime: number;
377
+ minConfirmations: number;
378
+ direction: "send" | "receive";
379
+ };
380
+ }) => void;
381
+ /**
382
+ * The receive legs' window gate, measured from the pay deadline rather than
383
+ * from now.
384
+ *
385
+ * `refund_locktime` is the SOLVER's here, so BIP-113 lag extends the trader's claim window; what
386
+ * can run out is the hold invoice, so the window that matters is after a last-moment payment.
387
+ */
388
+ declare const verifyReceiveWindow: (input: {
389
+ readonly quote: RfqQuote;
390
+ readonly quoteId: QuoteId;
391
+ readonly payDeadline: number;
392
+ readonly now: number;
393
+ }) => void;
394
+ /**
395
+ * The invoice check on a send: `to_amount` must equal the invoice amount (BOLT11 is exact-out),
396
+ * and `from_amount` below it is a negative spread.
397
+ */
398
+ declare const verifySendInvoice: (input: {
399
+ /** The amount the trader's own decode read off the invoice. */
400
+ readonly invoiced: bigint;
401
+ readonly give: bigint;
402
+ readonly take: bigint;
403
+ }) => void;
404
+ /**
405
+ * The invoice check on a receive: bind the SOLVER's hold invoice to this swap's
406
+ * hash and to the quote.
407
+ *
408
+ * The one attack on this corridor with no on-chain trace: an invoice on another payment hash is
409
+ * paid to the solver in full and no lockup on `H` is ever funded. Not delegated to
410
+ * `verifyReceiveInvoice`, which compares against `quote.from_amount` as a JS number; mid amount
411
+ * migration that field may be a string, and `!==` would refuse every migrated solver.
412
+ */
413
+ declare const verifyReceiveInvoiceFacts: (input: {
414
+ readonly invoice: string;
415
+ readonly decode: (bolt11: string) => InvoiceFacts;
416
+ /** `sha256(P)`, hex — the trader's OWN. */
417
+ readonly paymentHash: string;
418
+ /** The quote's `from_amount`: what the payer is asked for. */
419
+ readonly payAmount: bigint;
420
+ readonly validUntil: number;
421
+ }) => {
422
+ payDeadline: number;
423
+ };
424
+ /**
425
+ * The policy floor on a quote's remaining life: refuses terms that will expire before the caller
426
+ * can use them. With no floor set, only expiry itself refuses.
427
+ */
428
+ declare const verifyQuoteTtl: (input: {
429
+ readonly quoteId: QuoteId;
430
+ readonly expiresAt: number;
431
+ readonly now: number;
432
+ readonly floorSeconds?: number;
433
+ }) => void;
434
+ /**
435
+ * The quote answers the request that was made: the pinned side must not be repriced.
436
+ *
437
+ * Reported as the `pair` check, since the trade's identity on the wire is the pair plus the pinned
438
+ * side; {@link QuoteCheck} gains no member for it.
439
+ */
440
+ declare const verifyQuotedAmount: (input: {
441
+ readonly pair: string;
442
+ readonly pinned: {
443
+ on: "give" | "take";
444
+ value: bigint;
445
+ };
446
+ readonly give: bigint;
447
+ readonly take: bigint;
448
+ }) => void;
449
+ /**
450
+ * The quote answers the request, on a pair whose two legs carry **different
451
+ * assets**.
452
+ *
453
+ * Everything {@link verifyQuotedAmount} establishes except the one check that
454
+ * does not survive the change of asset: `take > give` is a mispricing when both
455
+ * legs are BTC and is the normal shape of a trade when they are not — 10_000
456
+ * sats for 1_000 cents reads one way round, and the reverse trade reads the
457
+ * other. Comparing them would refuse a correct quote on one direction of every
458
+ * asset market, which is why this is a separate function rather than a flag.
459
+ *
460
+ * What replaces it is positivity on both legs: a zero payout is not a trade,
461
+ * and it is the only cross-asset statement about the two numbers that means
462
+ * anything without a price.
463
+ */
464
+ declare const verifyCrossAssetAmount: (input: {
465
+ readonly pair: string;
466
+ readonly pinned: {
467
+ on: "give" | "take";
468
+ value: bigint;
469
+ };
470
+ readonly give: bigint;
471
+ readonly take: bigint;
472
+ }) => void;
473
+ /**
474
+ * The solver's carrier for an asset deposit, well-formed. Reported as the `pair` check, like the
475
+ * amounts: it is sats the trader funds on top of the quoted give leg.
476
+ */
477
+ declare const verifiedCarrierSats: (quote: RfqQuote) => bigint;
478
+
479
+ /**
480
+ * `retryable` is the point of the type: a 400 says the packet does not bind to
481
+ * this address at this daemon — wrong key, script or taptree — and retrying
482
+ * changes none of them. Only a full registry (429) and a transport fault (5xx,
483
+ * or `status` 0 for a throwing `fetch`) are worth trying again.
484
+ */
485
+ declare class CovclaimdRevealError extends Error {
486
+ readonly name = "CovclaimdRevealError";
487
+ readonly status: number;
488
+ readonly detail: string;
489
+ readonly retryable: boolean;
490
+ constructor(what: string, status: number, detail: string);
491
+ }
492
+ interface CovclaimdInfo {
493
+ /** 33-byte compressed — feeds {@link sealClaimPacket} unchanged. */
494
+ covclaimdPubkey: Uint8Array;
495
+ /** Compressed hex — feeds `requestLightningReceive`'s `emulatorPubkey`. */
496
+ emulatorPubkey: string;
497
+ }
498
+ /** The four fields `POST /v1/reveal` takes. */
499
+ interface RevealParams {
500
+ /** The funded lockup's Arkade address, bech32m. */
501
+ swapAddress: string;
502
+ /** `sealClaimPacket(...).ciphertext`, base64. */
503
+ ciphertext: string;
504
+ /** The covenant's `enforcePayTo` ArkadeScript, base64. */
505
+ arkadeScript: string;
506
+ /** The lockup's serialized taptree, hex. */
507
+ taptree: string;
508
+ }
509
+ interface CovclaimdClient {
510
+ info(): Promise<CovclaimdInfo>;
511
+ reveal(params: RevealParams): Promise<void>;
512
+ }
513
+ /** `fetchImpl` is injectable, matching `httpTransport` in `rfq.ts`. */
514
+ declare const covclaimdClient: (baseUrl: string, options?: {
515
+ fetchImpl?: typeof fetch;
516
+ timeoutMs?: number;
517
+ /** Opt out of the TLS requirement — a private network you trust. */
518
+ allowInsecureHttp?: boolean;
519
+ }) => CovclaimdClient;
520
+ /**
521
+ * The two wire fields that are functions of the covenant alone.
522
+ *
523
+ * A client-derived `arkadeScript` can differ from the funder's only if the
524
+ * covenants differ: the script is tweaked into the non-interactive claim leaf's
525
+ * co-signer key, so a different one is a different leaf, root, and lockup
526
+ * address — already covered by the address check made before funding.
527
+ */
528
+ declare function revealFieldsFromScript(script: InstanceType<typeof VHTLC.ScriptV2>): {
529
+ arkadeScript: string;
530
+ taptree: string;
531
+ };
532
+ /**
533
+ * Seal `P` to the daemon `client` speaks to and register it there, so covclaimd
534
+ * claims the lockup once the solver funds it and the trader can go offline.
535
+ *
536
+ * Registration EXPIRES — covclaimd drops it 15 minutes after the last reveal —
537
+ * and re-revealing refreshes rather than duplicates it, so a caller waiting on
538
+ * a slow funding should reveal again, not once. The two gates below name a
539
+ * cause covclaimd would otherwise report as an opaque 400.
540
+ */
541
+ declare function revealClaimPacket(client: CovclaimdClient, input: {
542
+ script: InstanceType<typeof VHTLC.ScriptV2>;
543
+ address: string;
544
+ /** `P`, 32 bytes, from the swap's `secrets`. */
545
+ preimage: Uint8Array;
546
+ }): Promise<{
547
+ ciphertext: string;
548
+ }>;
549
+
550
+ export { type AddressParams, ArkadeCorridorDeps, AssetAliasTable, AssetId, type ChainSourceBackend, Corridor, CorridorFactory, type CorridorRecordStore, CorridorSet, CorridorSwapRecord, type CovclaimdClient, type CovclaimdInfo, CovclaimdRevealError, DEFAULT_INVOICE_EXPIRY_SECONDS, type DepositFate, DiscoveryIndex, DiscoveryLeg, DiscoverySnapshot, INVOICE_HRPS, Instrument, type L1Tip, LIGHTNING_DRIVE, LightningCorridorDeps, MarketCandidate, NetworkRef, ONCHAIN_DRIVE, OfferSwapRecord, OnchainCorridorDeps, PinnedAmount, Pubkey, QuoteId, QuoteInput, Rail, type RecordSink, type ResolveDeps, ResolvedEndpoint, type ResolvedRoute, type RevealParams, Route, RouteResolution, SwapPolicy, SwapRecord, aliasTableFrom, applyOfferSpend, arkadeCorridor, assembleRoute, chainSourceOver, corridorRecordStore, covclaimdClient, decodeBolt11, esploraChainSource, esploraTip, fateMoved, lightningCorridor, networksOfInvoiceHrp, offerFactsOf, offerRecordSource, onchainCorridor, pageRfqRecords, publicAssetId, resolveRoute, restoredCorridorRecord, restoredOfferRecord, revealClaimPacket, revealFieldsFromScript, rfqRecordOf, satsOf, scopedToRail, splitRecords, verifiedCarrierSats, verifyCrossAssetAmount, verifyPair, verifyQuoteTtl, verifyQuotedAmount, verifyReceiveInvoiceFacts, verifyReceiveWindow, verifyResponder, verifySendInvoice, verifySendWindow, verifyingDerivation, walletLockupIndexer, withDepositFate, withRfqState };