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

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,950 @@
1
+ import { VHTLC, IWallet, ProvisionedKey, ProvisionedClaimSecret, asset } from '@arkade-os/sdk';
2
+
3
+ /** L1 confirmation-depth and reorg margin between dependent timelocks. */
4
+ declare const ONCHAIN_ORDER_MARGIN_SECONDS: number;
5
+ /** Don't broadcast a claim with less than this before the refund leaf opens:
6
+ * MTP lag plus confirmation time. Past this point the safe move is to let the
7
+ * swap die and take the covenant refund — claiming into the counterparty's
8
+ * live refund window risks losing the race AND publishing P. */
9
+ declare const ONCHAIN_CLAIM_MARGIN_SECONDS: number;
10
+ /** Bounds on the confirmation depth a quote may demand. */
11
+ declare const MAX_MIN_CONFIRMATIONS = 6;
12
+ /**
13
+ * BIP65's boundary between the two things an absolute locktime can mean: below it a block height,
14
+ * at or above it a unix timestamp (so the comparison is strict).
15
+ */
16
+ declare const LOCKTIME_THRESHOLD = 500000000;
17
+ /** Conservative block interval for converting depths into wall-clock time. */
18
+ declare const ONCHAIN_SECONDS_PER_BLOCK = 600;
19
+ /**
20
+ * Outputs below this are unspendable in practice; builders refuse them.
21
+ *
22
+ * 330, not 546: dust depends on output type, and both payouts here are taproot (546 is P2PKH).
23
+ * The higher figure would refuse relayable refunds. A legacy `payoutPkScript` would need a
24
+ * script-derived threshold. `BigInt(330)`, not `330n`: consumers read this source directly and
25
+ * may target below ES2020.
26
+ */
27
+ declare const ONCHAIN_DUST_SATS: bigint;
28
+ /** 32 random bytes. The user generates P for BOTH onchain directions. */
29
+ declare const newPreimage: () => Uint8Array;
30
+ /** `sha256(P)`, hex — the wire `payment_hash`, same convention as BOLT11. */
31
+ declare const paymentHashOf: (preimage: Uint8Array) => string;
32
+ type OnchainNetwork = "bitcoin" | "testnet" | "regtest";
33
+ /**
34
+ * The `payoutPkScript` {@link buildHtlcClaim} pays the fill to. Resolve it EARLY: nothing else
35
+ * names the spender's destination, and one that cannot be encoded must be refused before the swap
36
+ * is negotiated, not at claim time.
37
+ */
38
+ declare const l1ScriptForAddress: (address: string, network: OnchainNetwork) => Uint8Array;
39
+ interface OnchainHtlcParams {
40
+ /** `sha256(P)`, hex; the HASH160 commitment is derived internally. */
41
+ paymentHash: string;
42
+ /** x-only key that claims with the preimage. */
43
+ claimKey: Uint8Array;
44
+ /** x-only key that refunds after the locktime. */
45
+ refundKey: Uint8Array;
46
+ /** Absolute unix seconds (consensus matures it against median-time-past). */
47
+ refundLocktime: number;
48
+ }
49
+ interface OnchainHtlc {
50
+ address: string;
51
+ /** `0x5120…` — the P2TR output script. */
52
+ pkScript: Uint8Array;
53
+ leaves: {
54
+ claim: Uint8Array;
55
+ refund: Uint8Array;
56
+ };
57
+ /** Serialized control blocks per leaf, ready for a script-path witness. */
58
+ controlBlocks: {
59
+ claim: Uint8Array;
60
+ refund: Uint8Array;
61
+ };
62
+ paymentHash: string;
63
+ refundLocktime: number;
64
+ }
65
+ /**
66
+ * Derive the two-leaf taproot HTLC. Internal key is the BIP-341 NUMS point, so
67
+ * there is no key-path spend, ever:
68
+ *
69
+ * claim: `OP_SIZE 32 OP_EQUALVERIFY OP_HASH160 <h160> OP_EQUALVERIFY <claimKey> OP_CHECKSIG`
70
+ * refund: `<locktime> OP_CHECKLOCKTIMEVERIFY OP_DROP <refundKey> OP_CHECKSIG`
71
+ *
72
+ * `OP_SIZE 32` pins the preimage to 32 bytes before hashing, as BOLT3 HTLCs do. Pinned
73
+ * byte-for-byte by the golden test; any drift changes addresses on BOTH sides of a swap.
74
+ */
75
+ declare function onchainHtlcScript(params: OnchainHtlcParams, network: OnchainNetwork): OnchainHtlc;
76
+ interface HtlcUtxo {
77
+ txid: string;
78
+ vout: number;
79
+ amount: bigint;
80
+ }
81
+ interface SpendResult {
82
+ txHex: string;
83
+ txid: string;
84
+ /** `utxo.amount − fee` — what actually lands at the payout script. */
85
+ payoutAmount: bigint;
86
+ }
87
+ /** Script-path spend of the claim leaf; the witness reveals P — that is how
88
+ * the counterparty learns it, so never build this unless the claim will win
89
+ * (see {@link claimOnchainFill}). `sign` is BIP340 over the claim key. */
90
+ declare const buildHtlcClaim: (input: {
91
+ htlc: OnchainHtlc;
92
+ utxo: HtlcUtxo;
93
+ preimage: Uint8Array;
94
+ payoutPkScript: Uint8Array;
95
+ feeRateSatVb: number;
96
+ sign: (sighash: Uint8Array) => Promise<Uint8Array>;
97
+ }) => Promise<SpendResult>;
98
+ /** Script-path spend of the refund leaf; consensus-valid only once nLockTime
99
+ * has matured against median-time-past — gate on {@link ChainSource.getMtp},
100
+ * not wall clock. `sign` is BIP340 over the refund key. */
101
+ declare const buildHtlcRefund: (input: {
102
+ htlc: OnchainHtlc;
103
+ utxo: HtlcUtxo;
104
+ payoutPkScript: Uint8Array;
105
+ feeRateSatVb: number;
106
+ sign: (sighash: Uint8Array) => Promise<Uint8Array>;
107
+ }) => Promise<SpendResult>;
108
+ interface ChainUtxo extends HtlcUtxo {
109
+ confirmations: number;
110
+ }
111
+ /** The package's whole view of Bitcoin L1, injected so the package stays backend-free
112
+ * (`CorridorOverrides.onchain.chain` takes it). */
113
+ interface ChainSource {
114
+ /** Confirmed+mempool outputs paying a script; used to detect the fill. */
115
+ getScriptUtxos(pkScript: Uint8Array): Promise<ChainUtxo[]>;
116
+ /** The spend of an outpoint, if any — where P is extracted from. A
117
+ * provider omitting the spender txid still lists it in `pkScript`'s history. */
118
+ getSpendingTx(txid: string, vout: number, pkScript: Uint8Array): Promise<{
119
+ txHex: string;
120
+ } | null>;
121
+ broadcast(txHex: string): Promise<string>;
122
+ /** Current median-time-past, unix seconds — gates refund broadcasting. */
123
+ getMtp(): Promise<number>;
124
+ }
125
+ /** Read P out of a claim spend's witness: the 32-byte item whose sha256 is the
126
+ * payment hash. Null when the tx reveals no matching preimage (e.g. a refund
127
+ * spend, or an unrelated tx). */
128
+ declare function extractPreimage(txHex: string, paymentHash: string): Uint8Array | null;
129
+ /** Poll {@link ChainSource} until the HTLC is funded to the required depth.
130
+ * Picks the largest qualifying output when several exist. Throws (reason
131
+ * `fill_timeout`) once `deadline` (unix seconds) passes without one. */
132
+ declare function awaitOnchainFill(chain: ChainSource, htlc: OnchainHtlc, minConfirmations: number, options?: {
133
+ pollMs?: number;
134
+ deadline?: number;
135
+ }): Promise<ChainUtxo>;
136
+ /**
137
+ * Claim the fill: build the claim spend and broadcast it, publishing P (that is how the solver
138
+ * gets paid). Refuses (`claim_window_closed`) with less than {@link ONCHAIN_CLAIM_MARGIN_SECONDS}
139
+ * before the refund leaf opens.
140
+ */
141
+ declare function claimOnchainFill(chain: ChainSource, input: {
142
+ htlc: OnchainHtlc;
143
+ utxo: HtlcUtxo;
144
+ preimage: Uint8Array;
145
+ payoutPkScript: Uint8Array;
146
+ feeRateSatVb: number;
147
+ sign: (sighash: Uint8Array) => Promise<Uint8Array>;
148
+ /** Injected for tests; defaults to wall clock. */
149
+ now?: number;
150
+ }): Promise<{
151
+ txid: string;
152
+ payoutAmount: bigint;
153
+ }>;
154
+ /** Where an onchain HTLC stands, for crash recovery. Persisting the record BEFORE funding is what
155
+ * makes this classification (and the claim) possible after a restart. */
156
+ type OnchainHtlcPhase = {
157
+ phase: "unfunded";
158
+ } | {
159
+ phase: "awaiting_confirmations";
160
+ utxo: ChainUtxo;
161
+ } | {
162
+ phase: "claimable";
163
+ utxo: ChainUtxo;
164
+ }
165
+ /**
166
+ * The refund leaf has matured, so the CLAIM WINDOW IS CLOSED and `claimOnchainFill` throws.
167
+ * Do not claim: let the counterparty's L1 refund settle and take the Arkade-side covenant
168
+ * refund. On a swap you expected to claim, this means the claim was missed.
169
+ */
170
+ | {
171
+ phase: "refundable";
172
+ utxo: ChainUtxo;
173
+ } | {
174
+ phase: "claimed";
175
+ txid: string;
176
+ preimage: Uint8Array;
177
+ } | {
178
+ phase: "swept";
179
+ txid: string;
180
+ };
181
+ /**
182
+ * Classify an HTLC from chain state alone. `funding` (the known outpoint from
183
+ * the stored record) is what distinguishes "never funded" from "funded and
184
+ * already spent": without it a spent HTLC looks unfunded.
185
+ *
186
+ * `claimed` carries the preimage read from the spend's witness — the receipt;
187
+ * `swept` is a spend that reveals no preimage (the counterparty's refund).
188
+ */
189
+ declare function classifyOnchainHtlc(chain: ChainSource, input: {
190
+ htlc: OnchainHtlc;
191
+ minConfirmations: number;
192
+ funding?: {
193
+ txid: string;
194
+ vout: number;
195
+ };
196
+ }): Promise<OnchainHtlcPhase>;
197
+
198
+ /** Legs are `<corridor>:<asset>`; a pair is directional, `from->to`. */
199
+ declare const ARKADE_BTC = "arkade:BTC";
200
+ declare const LIGHTNING_BTC = "lightning:BTC";
201
+ declare const ONCHAIN_BTC = "onchain:BTC";
202
+ /** The arkade leg for an asset: the asset id itself, 68 lowercase hex, in the pair because the
203
+ * pair is what both sides route and subscribe on.
204
+ *
205
+ * Takes an `AssetId`, not a string, to enforce lowercase (`hex.decode` accepts uppercase,
206
+ * `toString()` emits lowercase): solvers compare pair strings byte for byte, so `A1B2…` would be
207
+ * skipped as an unserved pair. */
208
+ declare const arkadeAssetLeg: (id: asset.AssetId) => string;
209
+ /** The implemented pair: pay a BOLT11 invoice out of an Arkade balance. */
210
+ declare const LIGHTNING_SEND_PAIR: string;
211
+ /** On-board via Lightning: pay the solver's hold invoice, land on Arkade. */
212
+ declare const LIGHTNING_RECEIVE_PAIR: string;
213
+ declare const ONCHAIN_SEND_PAIR: string;
214
+ /** On-board: a Bitcoin-L1 HTLC in, Arkade sats out. */
215
+ declare const ONCHAIN_RECEIVE_PAIR: string;
216
+ /** The closed refusal set. Treat any unknown reason as a generic decline. */
217
+ type RfqRefusalReason = "unsupported_pair" | "unsupported_payload" | "amount_out_of_range" | "exposure_cap" | "invoice_expired" | "quote_conflict" | "pricing_unavailable" | "rate_limited";
218
+ declare const RFQ_REFUSAL_ERROR_CODES: readonly ["amount_side_unsupported", "exact_out_unsupported", "invalid_amount", "invalid_payout_address", "invalid_refund_address", "invoice_amount_mismatch", "invoice_cltv_too_large", "invoice_malformed", "invoice_missing_amount", "invoice_missing_network", "invoice_missing_payment_hash", "invoice_missing_timestamp", "invoice_mixed_case", "invoice_sub_satoshi_amount", "invoice_too_long", "invoice_wrong_network"];
219
+ type RfqRefusalErrorCode = (typeof RFQ_REFUSAL_ERROR_CODES)[number];
220
+ type RfqRefusalUnit = "blocks" | "characters" | "sats";
221
+ interface RfqRefusalDetail {
222
+ errorCode?: RfqRefusalErrorCode;
223
+ field?: string;
224
+ actual?: number;
225
+ expected?: number;
226
+ limit?: number;
227
+ unit?: RfqRefusalUnit;
228
+ }
229
+ declare const isRfqRefusalErrorCode: (value: unknown) => value is RfqRefusalErrorCode;
230
+ /** A refusal from the solver, carrying its closed-set reason. */
231
+ declare class SwapRefusal extends Error {
232
+ /** Literal-typed so the v2 error taxonomy's union discriminates on `name`
233
+ * — a `string` here collapses the discriminant for every member. */
234
+ readonly name = "SwapRefusal";
235
+ readonly reason: string;
236
+ readonly rfqId: string | undefined;
237
+ readonly errorCode: RfqRefusalErrorCode | undefined;
238
+ readonly field: string | undefined;
239
+ readonly actual: number | undefined;
240
+ readonly expected: number | undefined;
241
+ readonly limit: number | undefined;
242
+ readonly unit: RfqRefusalUnit | undefined;
243
+ constructor(reason: string, rfqId?: string, detail?: RfqRefusalDetail);
244
+ }
245
+ /**
246
+ * The solver's address does not match the local derivation. NEVER fund past
247
+ * this. `derived` is every candidate address tried — more than one when the
248
+ * derivation itself is ambiguous, see {@link verifyLockupAddress}.
249
+ */
250
+ declare class AddressMismatch extends Error {
251
+ readonly derived: string | string[];
252
+ readonly quoted: string | undefined;
253
+ constructor(derived: string | string[], quoted?: string);
254
+ }
255
+ interface RfqQuote {
256
+ v: 1;
257
+ type: "rfq_quote";
258
+ rfq_id: string;
259
+ pair: string;
260
+ /** Sats on HTLC-class corridors (number); canonical decimal string on
261
+ * arkade↔arkade asset legs (bigint range, see WIRE_ASSET_AMOUNT on the
262
+ * solver). */
263
+ from_amount: number | string;
264
+ to_amount: number | string;
265
+ /** Dust an asset deposit rides on, kept by the filler. Expected back in `to_amount`; the
266
+ * client counts any shortfall as fee. */
267
+ carrier_sats?: number | string;
268
+ solver_pubkey: string;
269
+ valid_until: number;
270
+ /** HTLC-class quotes only; absent for arkade↔arkade. */
271
+ refund_locktime?: number;
272
+ profile: {
273
+ [key: string]: unknown;
274
+ payment_hash?: string;
275
+ lockup_address?: string;
276
+ refund_without_receiver_delay?: number;
277
+ offer_address?: string;
278
+ offer_pk_script?: string;
279
+ };
280
+ [key: string]: unknown;
281
+ }
282
+ interface RfqStatus {
283
+ v: 1;
284
+ type: "rfq_status";
285
+ rfq_id: string;
286
+ state: string;
287
+ updated_at: number;
288
+ profile: Record<string, unknown>;
289
+ [key: string]: unknown;
290
+ }
291
+ /** The rfq_request for the lightning send profile. BOLT11 is exact-out: the invoice fixes the
292
+ * amount. `senderPubkey` is the trader's key for the VHTLC's sender-side leaves (see
293
+ * {@link lightningSendContract}), sent as `client_refund_pubkey`; the solver's schema
294
+ * (https://docs.arkadeos.com/intents/reference/rfq) is `.strict()`, so a wrong or missing name
295
+ * refuses every request.
296
+ */
297
+ declare const lightningSendRequest: (input: {
298
+ rfqId: string;
299
+ invoice: string;
300
+ refundAddress: string;
301
+ senderPubkey: Uint8Array;
302
+ }) => Record<string, unknown>;
303
+ /** The rfq_request for an arkade↔arkade swap. At least one side names an asset
304
+ * id (BTC has none), and the id is the leg itself — see
305
+ * {@link arkadeAssetLeg}.
306
+ *
307
+ * Matches the reference solver's strict `AssetRfqRequest`: `amount` is a canonical decimal string
308
+ * of atomic units (never a JSON number: an asset's precision is unknowable client-side), and
309
+ * `amount_side` is `"from"` or `"to"`, and `profile` carries the trader's covenant position — the fill pays `maker_pk_script`, and `cancel`
310
+ * is signed by `maker_public_key`. */
311
+ declare const arkadeSwapRequest: (input: {
312
+ rfqId: string;
313
+ /** Asset the trader deposits; omit when depositing BTC. */
314
+ offerAsset?: asset.AssetId;
315
+ /** Asset the trader wants; omit when wanting BTC. */
316
+ wantAsset?: asset.AssetId;
317
+ amountSide?: "from" | "to";
318
+ /** Atomic units of the deposit (`from`) leg. bigint-safe: encoded as a
319
+ * canonical decimal string on the wire. */
320
+ amount: bigint | number | string;
321
+ /** Trader's own taproot scriptPubKey (34 bytes, `OP_1 <32-byte program>`),
322
+ * as bytes or lowercase hex. The covenant's `makerWP` minus its prefix. */
323
+ makerPkScript: Uint8Array | string;
324
+ /** Trader's own x-only key (32 bytes), as bytes or lowercase hex. The
325
+ * `cancel` path's `user` signer. */
326
+ makerPublicKey: Uint8Array | string;
327
+ }) => Record<string, unknown>;
328
+ /** Canonical decimal string of atomic units: ASCII digits, no sign, point,
329
+ * exponent, or leading zero (unless the value is exactly "0"). bigint passes
330
+ * through; number must be a safe integer; string must already be canonical.
331
+ *
332
+ * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`. */
333
+ declare const canonicalAssetAmount: (amount: bigint | number | string) => string;
334
+ /** 34-byte taproot scriptPubKey (`OP_1 <32-byte program>`), lowercase hex.
335
+ *
336
+ * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`. */
337
+ declare const normalizeMakerPkScript: (value: Uint8Array | string) => string;
338
+ /** 32-byte x-only key, lowercase hex. Never a 33-byte compressed key.
339
+ *
340
+ * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`. */
341
+ declare const normalizeMakerPublicKey: (value: Uint8Array | string) => string;
342
+ /**
343
+ * Compare-only check of the solver's address against YOUR OWN derivation(s)
344
+ * — never extends trust, only narrows it.
345
+ *
346
+ * Pass an array when your derivation is ambiguous, as for covenant lockups while solvers roll out
347
+ * the timelocked non-interactive refund leaf (nothing on the wire says which shape a quote uses).
348
+ * No security is lost: every candidate pins the refund to the trader's own destination.
349
+ *
350
+ * @returns the address that matched.
351
+ * @throws {AddressMismatch} only when NONE of the candidates match.
352
+ */
353
+ declare const verifyLockupAddress: (quote: RfqQuote, derivedAddress: string | string[]) => string;
354
+ interface RfqTransport {
355
+ requestQuote(payload: Record<string, unknown>): Promise<RfqQuote>;
356
+ status(rfqId: string): Promise<RfqStatus | null>;
357
+ close(): Promise<void>;
358
+ }
359
+ /** HTTP: POST /v1/swap for quotes, GET /v1/rfq/<rfq_id> for status.
360
+ * `fetchImpl` is injectable for tests and non-global-fetch runtimes. */
361
+ declare const httpTransport: (baseUrl: string, options?: {
362
+ fetchImpl?: typeof fetch;
363
+ }) => RfqTransport;
364
+ /** Minimal WebSocket surface the relay transport needs — satisfied by the DOM
365
+ * WebSocket and by `ws` alike, so neither becomes a dependency. */
366
+ interface RelaySocket {
367
+ send(data: string): void;
368
+ close(): void;
369
+ addEventListener(type: "open" | "message" | "error", listener: (event: any) => void): void;
370
+ }
371
+ /** Relay: both parties outbound, addressed by x-only pubkey, speaking the dev
372
+ * broker framing. Nostr (directed kind + NIP-44) replaces only this function.
373
+ * One socket; replies correlated by rfq_id. */
374
+ declare const relayTransport: (relayUrl: string, options: {
375
+ solverPubkey: string;
376
+ clientPubkey: string;
377
+ WebSocketCtor?: new (url: string) => RelaySocket;
378
+ timeoutMs?: number;
379
+ }) => RfqTransport;
380
+ /** The solver's unilateral-claim delay, derived from the Arkade operator's reported
381
+ * exit delay exactly as the reference solver derives it — both sides read the
382
+ * SAME server, so the derivation (not a quote field) is what keeps the two
383
+ * scripts identical. */
384
+ declare const unilateralClaimDelay: (operatorExitDelaySeconds: number) => number;
385
+ /** VHTLC's `unilateralRefund` tier: sender + receiver, no server — LEVEL with
386
+ * `claimDelay`, not above it. Neither party can spend a two-signature leaf
387
+ * alone, so separating it buys no safety and would only eat into the headroom that matters. */
388
+ declare const unilateralRefundDelay: (claimDelay: number) => number;
389
+ /** VHTLC's `unilateralRefundWithoutReceiver` tier: sender alone, needing
390
+ * nobody. The only leaf whose timing can steal — a funder able to refund
391
+ * before the claimant can claim takes money from someone holding the preimage
392
+ * — so it opens last, by {@link SOLO_REFUND_HEADROOM_SECONDS}. */
393
+ declare const unilateralRefundWithoutReceiverDelay: (claimDelay: number) => number;
394
+ /** Compile the lightning-send VHTLC from the quote's binding fields plus the
395
+ * trader's own data. `paymentHash` is the BOLT11 payment hash (`sha256(P)`,
396
+ * hex); the script's HASH160 commitment is derived from it here, which is why
397
+ * the trader never needs to see `P`.
398
+ *
399
+ * Nine leaves unless `legacy`: VHTLC's six plus the emulator-covenant suite —
400
+ * `nonInteractiveClaim` (server + emulator, pays the solver's `receiverPkScript`),
401
+ * `nonInteractiveRefund` (server + solver + emulator, pays the trader's `refundPkScript`, no
402
+ * timelock or trader signature; see {@link VHTLC.Options.nonInteractiveParameters}), and
403
+ * `nonInteractiveRefundWithoutReceiver` (server + emulator after `refundLocktime`).
404
+ */
405
+ declare function lightningSendContract(params: {
406
+ /** Binding field #1: the solver's x-only key, from the quote. */
407
+ solverPubkey: Uint8Array;
408
+ /** Binding field #2: when the trader's refund path opens, from the quote. */
409
+ refundLocktime: number;
410
+ /** The Arkade operator's x-only key — the trader's OWN connection. */
411
+ operatorPubkey: Uint8Array;
412
+ /** BOLT11 payment hash, hex — from the trader's OWN invoice decode. */
413
+ paymentHash: string;
414
+ /** From {@link unilateralClaimDelay} over the trader's OWN server info; all three unilateral
415
+ * tiers derive from it. */
416
+ claimDelay: number;
417
+ /** Binding quote field. Optional only for rebuilding pre-upgrade scripts. */
418
+ refundWithoutReceiverDelay?: number;
419
+ /** Emulator x-only key (32 bytes). */
420
+ emulatorPubkey: Uint8Array;
421
+ /** Where a refund must pay: the trader's P2TR pkScript (34 bytes). Also
422
+ * the refund covenants' destination. */
423
+ refundPkScript: Uint8Array;
424
+ /** The trader's own key — VHTLC's `sender` role, on every interactive refund-side leaf. */
425
+ senderPubkey: Uint8Array;
426
+ /** The solver's claim destination (`profile.receiver_pk_script`, P2TR), used only to derive
427
+ * `nonInteractiveClaim`'s covenant key; not otherwise trusted. */
428
+ receiverPkScript: Uint8Array;
429
+ /** LEGACY REBUILD ONLY: re-derive a lockup funded before the timelocked refund leaf shipped
430
+ * (see {@link VHTLC.Options.nonInteractiveParameters}); set by {@link matchQuotedLockup}. */
431
+ legacy?: "preTimelockedRefund";
432
+ }): InstanceType<typeof VHTLC.ScriptV2>;
433
+ /** Every input {@link lightningSendContract} builds from. */
434
+ type LightningSendContractParams = Parameters<typeof lightningSendContract>[0];
435
+ /** The BOLT11 facts the trader read from its OWN decode — this module takes
436
+ * the facts, not the decoder, so any wallet's existing decoder serves
437
+ * (`CorridorOverrides.lightning.decode` returns it). */
438
+ interface InvoiceFacts {
439
+ /** The raw BOLT11 — what travels in the request profile. */
440
+ raw: string;
441
+ /** `sha256(P)`, LOWERCASE hex (64 chars) — {@link verifyReceiveInvoice}
442
+ * compares it byte-for-byte against `paymentHashOf`, which emits lowercase. */
443
+ paymentHash: string;
444
+ amountSats: number;
445
+ /** Absolute expiry, unix seconds. */
446
+ expiresAt: number;
447
+ }
448
+ /**
449
+ * The lightning-send user flow: quote → derive locally → verify → gate. Funds nothing: the caller
450
+ * funds `address` with `fundAmount` before `quote.valid_until`, then may go OFFLINE. Success
451
+ * reveals the preimage in the solver's claim witness; failure refunds to `refundAddress`.
452
+ *
453
+ * @throws {SwapRefusal} (closed reason), {@link AddressMismatch} (never fund), a gate error with a
454
+ * stable `reason`, or {@link LockupRegistrationFailed} — only the last leaves the quote good for a
455
+ * retry once local storage is.
456
+ *
457
+ * @remarks Registers the lockup with the contract manager before returning the address, so it is
458
+ * watched (and out of coin selection) from the moment it lands, and a persistence failure throws
459
+ * while nothing is funded. Persist `secrets` (a public descriptor) with the record: it is how the
460
+ * refund signer is found again; without it `nonInteractiveRefund` still works but needs the
461
+ * SOLVER's active cooperation.
462
+ */
463
+ declare function requestLightningSend(wallet: IWallet, transport: RfqTransport, params: {
464
+ invoice: InvoiceFacts;
465
+ rfqId?: string;
466
+ /** Co-signer key override (33-byte compressed hex); see
467
+ * {@link resolveEmulatorPubkey}. */
468
+ emulatorPubkey?: string;
469
+ }): Promise<{
470
+ rfqId: string;
471
+ quote: RfqQuote;
472
+ /** The trader's OWN derivation — the only address to fund. */
473
+ address: string;
474
+ /** What the lockup must carry: the quote's `from_amount` (the invoice
475
+ * amount plus the corridor's fee), in sats. */
476
+ fundAmount: number;
477
+ /** The covenant's scriptPubKey, for watching the lockup and its spend. */
478
+ swapPkScript: Uint8Array;
479
+ /** The covenant itself. Hand it to `RfqSwapManager` as the record's `lockup` (with
480
+ * `address`); without it the manager can only poll and cannot retire the row. */
481
+ script: InstanceType<typeof VHTLC.ScriptV2>;
482
+ /** Where a failed swap refunds; the address `secrets.pkScript` was decoded from. */
483
+ refundAddress: string;
484
+ /** The VHTLC `sender` x-only key, bound into the covenant. Public. */
485
+ senderPubkey: Uint8Array;
486
+ /** How the `sender` key is recovered later. Persist it with the record;
487
+ * it holds nothing secret. */
488
+ secrets: ProvisionedKey;
489
+ /**
490
+ * Every input the covenant was built from, as it was AT REQUEST TIME (half are not on the
491
+ * quote). All public, and optional to persist: `rebuildRfqSwap` reads the registered contract
492
+ * row. To rebuild without that store, keep
493
+ * `VHTLCV2ContractHandler.serializeParams(script.options)` instead.
494
+ */
495
+ contractParams: LightningSendContractParams;
496
+ }>;
497
+ /** Compare-only check of the solver's offer address AND script against YOUR OWN derivation.
498
+ * Throws {@link AddressMismatch} unless both match exactly.
499
+ *
500
+ * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`. */
501
+ declare const verifyOfferAddress: (quote: RfqQuote, derived: {
502
+ address: string;
503
+ swapPkScript: Uint8Array;
504
+ }) => {
505
+ address: string;
506
+ swapPkScript: Uint8Array;
507
+ };
508
+ /** Gate an arkade↔arkade quote immediately before funding. The only clock is `valid_until`:
509
+ * funding after it leaves a deposit the solver won't fill, reclaimable only via `cancelOffer`.
510
+ *
511
+ * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`. */
512
+ declare const assertArkadeFundable: (input: {
513
+ quote: RfqQuote;
514
+ now?: number;
515
+ }) => void;
516
+ /**
517
+ * The arkade↔arkade user flow: quote → derive locally → verify → gate. Funds nothing; the caller
518
+ * funds before `quote.valid_until`, then may go offline. No timelock refund: an unfilled offer is
519
+ * cancelled cooperatively (`cancelOffer`).
520
+ *
521
+ * With `amountSide: "to"` the deposit is the solver's to name: set `maxFromAmount`, or fund
522
+ * whatever it quotes.
523
+ *
524
+ * Maker keys are read once here so the request profile and the local `createOffer` derivation
525
+ * cannot diverge. Throws {@link SwapRefusal}, {@link AddressMismatch} (never fund), or a gate error
526
+ * with a stable `reason`.
527
+ *
528
+ * `client.exchange()` now covers this route end to end — it opens the card's
529
+ * Nostr rendezvous, sends this same request, runs the full verification set,
530
+ * and registers, persists and funds in one step — so there is nothing left here
531
+ * that it does not do. What it additionally refuses is a transport that cannot
532
+ * say who answered, which this function, taking one from its caller, cannot.
533
+ *
534
+ * Funding (caller's job, immediately after, before `valid_until`):
535
+ * - BTC->asset (`wantAsset`): `wallet.send({ address, amount: Number(fundAmount), extensions: [extension] })`
536
+ * - asset->BTC or asset->asset (`offerAsset`): `wallet.send({ address, amount: Number(carrierSats), assets: [{ assetId: offerAsset, amount: fundAmount }], extensions: [extension] })`
537
+ *
538
+ * @deprecated Use `client.exchange()`. Moved off the package root to `@arkade-os/swap/protocol`.
539
+ */
540
+ declare function requestArkadeSwap(wallet: IWallet, transport: RfqTransport, params: {
541
+ /** Asset the trader deposits; omit when depositing BTC. */
542
+ offerAsset?: asset.AssetId;
543
+ /** Asset the trader wants; omit when wanting BTC. */
544
+ wantAsset?: asset.AssetId;
545
+ /** Atomic units of whichever leg `amountSide` names. */
546
+ amount: bigint | number | string;
547
+ amountSide?: "from" | "to";
548
+ /** Bounds the side the SOLVER chose — the named side is echoed back verbatim,
549
+ * so asserting it proves nothing and an unbounded caller funds what it is asked. */
550
+ maxFromAmount?: bigint | number | string;
551
+ minToAmount?: bigint | number | string;
552
+ rfqId?: string;
553
+ /** Co-signer key override (33-byte compressed hex); see `createOffer`. */
554
+ emulatorPubkey?: string;
555
+ now?: number;
556
+ }): Promise<{
557
+ rfqId: string;
558
+ quote: RfqQuote;
559
+ pair: string;
560
+ /** The trader's OWN derivation — the only address to fund. */
561
+ address: string;
562
+ /** What the deposit must carry: the quote's `from_amount`. Sats for a BTC
563
+ * deposit, asset units for an asset deposit (plus a dust carrier). */
564
+ fundAmount: bigint;
565
+ /** Dust sats to attach to an asset deposit; 0n for a BTC deposit. */
566
+ carrierSats: bigint;
567
+ /** The covenant's scriptPubKey, for watching the deposit and its spend. */
568
+ swapPkScript: Uint8Array;
569
+ /** The encoded offer. Persist this — it is the only input `cancelOffer`
570
+ * needs, and the restore scan reads it back off the funding tx. */
571
+ offerHex: string;
572
+ /** Ready for `wallet.send`'s `extensions`. */
573
+ extension: {
574
+ type: number;
575
+ payload: Uint8Array;
576
+ };
577
+ }>;
578
+ /** The rfq_request for `arkade:BTC->onchain:BTC`. Exact-out means "this much
579
+ * lands in the L1 HTLC". `senderPubkey` is the user's own key for the
580
+ * VHTLC's sender-side leaves — same role as in {@link lightningSendRequest}.
581
+ * On the wire it's `client_refund_pubkey`, same as there. */
582
+ declare const onchainSendRequest: (input: {
583
+ rfqId: string;
584
+ /** `sha256(P)`, hex — user-chosen; see {@link paymentHashOf}. */
585
+ paymentHash: string;
586
+ /** User's x-only L1 key for the HTLC's claim leaf. */
587
+ payoutPubkey: Uint8Array;
588
+ /** User's arkade address — where the covenant refund must pay. */
589
+ refundAddress: string;
590
+ senderPubkey: Uint8Array;
591
+ amount: number;
592
+ amountSide: "from" | "to";
593
+ }) => Record<string, unknown>;
594
+ /** The rfq_request for `lightning:BTC->arkade:BTC`. The trader sends only `H` plus `P` sealed to
595
+ * covclaimd, so the solver never sees `P` before a claim witness. `payoutPubkey` is the covenant's
596
+ * `receiver`, so the trader can claim without covclaimd. */
597
+ declare const lightningReceiveRequest: (input: {
598
+ rfqId: string;
599
+ /** `H = sha256(P)`, hex — trader-chosen; see {@link paymentHashOf}. */
600
+ paymentHash: string;
601
+ /** Trader's arkade address — where the swapped sats land. */
602
+ payoutAddress: string;
603
+ /** Trader's x-only arkade key — the covenant's `receiver` role. */
604
+ payoutPubkey: Uint8Array;
605
+ /** `P` sealed to covclaimd, base64 — `sealClaimPacket(...).ciphertext`. Omitted from the wire
606
+ * when there is no covclaimd: the solver refuses an empty packet. */
607
+ claimPacket?: string;
608
+ amount: number;
609
+ amountSide: "from" | "to";
610
+ }) => Record<string, unknown>;
611
+ /** The rfq_request for `onchain:BTC->arkade:BTC`. The user funds the L1 HTLC (holding its refund
612
+ * role); P travels sealed to covclaimd so the user can go offline after funding. */
613
+ declare const onchainReceiveRequest: (input: {
614
+ rfqId: string;
615
+ paymentHash: string;
616
+ /** Trader's arkade address — where the swapped sats land. */
617
+ payoutAddress: string;
618
+ /** Trader's x-only arkade key — the covenant's `receiver` role. */
619
+ payoutPubkey: Uint8Array;
620
+ /** Trader's x-only L1 key for the HTLC's refund leaf. */
621
+ refundPubkey: Uint8Array;
622
+ /** `P` sealed to covclaimd, base64. Omitted when there is none to seal to —
623
+ * see {@link lightningReceiveRequest}. */
624
+ claimPacket?: string;
625
+ amount: number;
626
+ amountSide: "from" | "to";
627
+ }) => Record<string, unknown>;
628
+ /**
629
+ * The pure core of {@link requestOnchainSend}: derive BOTH contracts locally
630
+ * from the quote's binding fields plus the user's own data, and refuse on any
631
+ * mismatch. Binding: `solver_pubkey`, `refund_locktime`, `htlc_pubkey`,
632
+ * `htlc_locktime`, `min_confirmations`; `lockup_address` and `htlc_address`
633
+ * are compare-only.
634
+ */
635
+ declare function deriveOnchainSend(input: {
636
+ quote: RfqQuote;
637
+ paymentHash: string;
638
+ payoutPubkey: Uint8Array;
639
+ operatorPubkey: Uint8Array;
640
+ emulatorPubkey: Uint8Array;
641
+ claimDelay: number;
642
+ hrp: string;
643
+ l1Network: OnchainNetwork;
644
+ refundAddress: string;
645
+ /** The user's own key for the VHTLC's sender-side leaves — same role as
646
+ * in {@link requestLightningSend}. */
647
+ senderPubkey: Uint8Array;
648
+ }): {
649
+ address: string;
650
+ swapPkScript: Uint8Array;
651
+ /** The lockup covenant itself — what the contract row is registered from,
652
+ * so the row can never key on a script other than the derived one. */
653
+ script: InstanceType<typeof VHTLC.ScriptV2>;
654
+ htlc: OnchainHtlc;
655
+ /** The inputs {@link htlc} was built from; nothing else gives them back (L1 has no contract
656
+ * row, and `OnchainHtlc` exposes only derived values). */
657
+ htlcParams: OnchainHtlcParams;
658
+ /** Echoed from the input so the result fully describes the L1 half
659
+ * ({@link onchainSendProfile} reads it). */
660
+ l1Network: OnchainNetwork;
661
+ refundLocktime: number;
662
+ htlcLocktime: number;
663
+ minConfirmations: number;
664
+ expectedAmount: number;
665
+ };
666
+ /**
667
+ * The `arkade:BTC->onchain:BTC` user flow, mirroring `requestLightningSend`:
668
+ * quote → derive BOTH contracts locally → verify → gate. Pure of funding —
669
+ * the caller funds `address` with its own wallet before `quote.valid_until`.
670
+ *
671
+ * Registers the arkade lockup before returning, as {@link requestLightningSend} does (the L1 HTLC
672
+ * has no contract row).
673
+ *
674
+ * Two obligations, both LOUD:
675
+ * - **Persist `secrets` (with the record) BEFORE funding.** On a non-HD wallet it carries raw
676
+ * secrets; losing them forfeits the L1 claim and every interactive refund path.
677
+ * - **Stay claim-capable.** The user must claim the L1 HTLC (`awaitOnchainFill` →
678
+ * `claimOnchainFill`) before `htlc.refundLocktime`, or the fill is forfeit and the swap falls
679
+ * back to the Arkade covenant refund.
680
+ */
681
+ declare function requestOnchainSend(wallet: IWallet, transport: RfqTransport, params: {
682
+ amount: number;
683
+ amountSide: "from" | "to";
684
+ /** User's x-only L1 key that will claim the HTLC. */
685
+ payoutPubkey: Uint8Array;
686
+ /** Optional caller-owned P. Persist it with the returned secrets before funding. */
687
+ preimage?: Uint8Array;
688
+ rfqId?: string;
689
+ /** Co-signer key override (33-byte compressed hex); see
690
+ * {@link resolveEmulatorPubkey}. */
691
+ emulatorPubkey?: string;
692
+ }): Promise<{
693
+ rfqId: string;
694
+ quote: RfqQuote;
695
+ /** The user's OWN arkade lockup derivation — the only address to fund. */
696
+ address: string;
697
+ fundAmount: number;
698
+ /** What the solver's L1 fill must carry — persist it with the record. */
699
+ expectedAmount: number;
700
+ swapPkScript: Uint8Array;
701
+ /** The arkade covenant itself — the record's `lockup` for
702
+ * `RfqSwapManager`, same role as {@link requestLightningSend}'s. */
703
+ script: InstanceType<typeof VHTLC.ScriptV2>;
704
+ refundAddress: string;
705
+ /** The EXPECTED L1 fill, derived locally — watch and claim against this. */
706
+ htlc: OnchainHtlc;
707
+ /** The inputs {@link htlc} was built from — persist these (with `htlc.address`) to rebuild it
708
+ * after a restart; nothing else gives them back. Prefer `onchainSendProfile(result)` to
709
+ * mapping them by hand. */
710
+ htlcParams: OnchainHtlcParams;
711
+ /** Which bitcoin network the L1 HTLC was derived for. NOT the ark network name: signet,
712
+ * mutinynet and testnet4 all become `"testnet"`. */
713
+ l1Network: OnchainNetwork;
714
+ /** `profile.min_confirmations`; gates when the L1 fill becomes claimable,
715
+ * and part of what a restored swap needs to drive its own claim. */
716
+ minConfirmations: number;
717
+ /** The arkade lockup's refund deadline, as the covenant was built with it. Read this, not
718
+ * `quote.refund_locktime`: a solver may carry the value in `profile` instead. */
719
+ refundLocktime: number;
720
+ /** The VHTLC `sender` x-only key, bound into the covenant. Public. */
721
+ senderPubkey: Uint8Array;
722
+ /** How the preimage and the `sender` key are recovered later — map it
723
+ * through `swapSecretsToRecord` and persist BEFORE funding. Public unless
724
+ * `mustPersistPreimage` says the wallet could not derive P. */
725
+ secrets: ProvisionedClaimSecret;
726
+ }>;
727
+ /**
728
+ * Bind the SOLVER's hold invoice to the quote and to the trader's own `H`.
729
+ *
730
+ * The only attack on this corridor with no on-chain trace: an invoice on another payment hash is
731
+ * paid to the solver in full and no lockup on `H` is ever funded. NEVER publish an invoice that
732
+ * has not passed this.
733
+ *
734
+ * The decoder is injected (no BOLT11 dependency), but the comparison lives here: a caller-supplied
735
+ * summary of an adversary's invoice checks nothing. A hold invoice is indistinguishable on the
736
+ * wire, so that is not checked.
737
+ *
738
+ * Reasons: `invoice_undecodable` | `invoice_hash_mismatch` |
739
+ * `invoice_amount_mismatch` | `quote_malformed`.
740
+ *
741
+ * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
742
+ */
743
+ declare const verifyReceiveInvoice: (input: {
744
+ invoice: string;
745
+ decode: (bolt11: string) => InvoiceFacts;
746
+ /** `sha256(P)`, hex — the trader's OWN. */
747
+ paymentHash: string;
748
+ quote: RfqQuote;
749
+ }) => {
750
+ payDeadline: number;
751
+ };
752
+ /** Compile the RECEIVE-direction VHTLC: the same suite-carrying tree as {@link
753
+ * lightningSendContract} with the roles inverted — the trader is the
754
+ * `receiver` (it generated `P` and claims the lockup with it), the solver is
755
+ * the `sender` (it funds the lockup and holds the refund recourse). Shared by both receive
756
+ * corridors.
757
+ *
758
+ * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
759
+ */
760
+ declare function lightningReceiveContract(params: {
761
+ /** Binding field #1: the solver's x-only key, from the quote — VHTLC's
762
+ * `sender` role on the receive corridors. */
763
+ solverPubkey: Uint8Array;
764
+ /** Binding field #2: the SOLVER's own refund deadline on these legs, from
765
+ * the quote — after it the solver may reclaim an unclaimed lockup. */
766
+ refundLocktime: number;
767
+ /** The Arkade operator's x-only key — the trader's OWN connection. */
768
+ operatorPubkey: Uint8Array;
769
+ /** `sha256(P)`, hex — the trader's OWN preimage hash. */
770
+ paymentHash: string;
771
+ /** From {@link unilateralClaimDelay} over the trader's OWN server info. */
772
+ claimDelay: number;
773
+ /** Emulator x-only key — see {@link requestLightningSend}'s parameter. */
774
+ emulatorPubkey: Uint8Array;
775
+ /** The solver's covenant refund destination, from the quote
776
+ * (`profile.solver_refund_pk_script`) — the one tree parameter nothing
777
+ * else on the wire determines. */
778
+ solverRefundPkScript: Uint8Array;
779
+ /** The trader's own x-only Arkade key — VHTLC's `receiver` role on these
780
+ * legs, so the trader can claim without covclaimd. */
781
+ payoutPubkey: Uint8Array;
782
+ /** The trader's own Arkade payout pkScript (decoded from its payout
783
+ * address) — `nonInteractiveClaim`'s pinned destination. */
784
+ payoutPkScript: Uint8Array;
785
+ /** LEGACY REBUILD ONLY — see {@link lightningSendVtxoScript}'s `legacy`. */
786
+ legacy?: "preTimelockedRefund";
787
+ }): InstanceType<typeof VHTLC.ScriptV2>;
788
+ /** Every input {@link lightningReceiveContract} builds from; see
789
+ * {@link LightningSendContractParams}.
790
+ *
791
+ * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
792
+ */
793
+ type LightningReceiveContractParams = Parameters<typeof lightningReceiveContract>[0];
794
+ /**
795
+ * The pure core of {@link requestLightningReceive}: derive the solver-funded
796
+ * covenant locally from the quote's binding fields plus the trader's own data
797
+ * and refuse on any address mismatch. The trader funds nothing on Arkade here, but this is what
798
+ * makes paying the hold invoice safe: the lockup must be a tree whose claim paths pay the trader.
799
+ */
800
+ declare function deriveLightningReceive(input: {
801
+ quote: RfqQuote;
802
+ paymentHash: string;
803
+ payoutPubkey: Uint8Array;
804
+ payoutAddress: string;
805
+ operatorPubkey: Uint8Array;
806
+ emulatorPubkey: Uint8Array;
807
+ claimDelay: number;
808
+ hrp: string;
809
+ }): {
810
+ address: string;
811
+ swapPkScript: Uint8Array;
812
+ script: InstanceType<typeof VHTLC.ScriptV2>;
813
+ /** The solver's hold invoice on `H` — what the trader pays to arm the swap. */
814
+ invoice: string;
815
+ refundLocktime: number;
816
+ /** Every input the covenant was built from; see `requestLightningSend`'s result. */
817
+ contractParams: LightningReceiveContractParams;
818
+ };
819
+ /**
820
+ * The `lightning:BTC->arkade:BTC` user flow: quote → derive the covenant locally → verify → gate.
821
+ * Returns the solver's hold invoice (already checked by {@link verifyReceiveInvoice}) for the
822
+ * trader's own Lightning wallet to PAY before `invoiceExpiresAt`. Once the HTLC is held the solver
823
+ * funds the lockup and the trader claims it with its own `P` ({@link claimReceiveLockup}).
824
+ *
825
+ * Three obligations, all before the invoice is handed to a payer:
826
+ *
827
+ * 1. Persist `secrets` and `expectedAmount`; without the latter the claim cannot check the funded
828
+ * value.
829
+ * 2. Stay online. covclaimd cannot claim this covenant today, so an unclaimed lockup is reclaimed
830
+ * by the solver at `refund_locktime` and the payer refunded.
831
+ * 3. On {@link LockupRegistrationFailed}, call this again once the store works. The failed attempt
832
+ * is inert (no invoice was returned); re-registering `error.script` does NOT resume it.
833
+ */
834
+ declare function requestLightningReceive(wallet: IWallet, transport: RfqTransport, params: {
835
+ amount: number;
836
+ amountSide: "from" | "to";
837
+ /** Co-signer key override (33-byte compressed hex); see
838
+ * {@link resolveEmulatorPubkey}. */
839
+ emulatorPubkey?: string;
840
+ /** covclaimd's 33-byte compressed pubkey; the claim packet seals `P` to it. Unset where
841
+ * none is deployed: nothing is sent, and claiming before `refund_locktime` is the caller's
842
+ * job. Never substitute a throwaway key — nobody could open it. */
843
+ covclaimdPubkey?: Uint8Array;
844
+ /** The caller's own BOLT11 decoder, applied to the SOLVER's invoice. Required: skipping
845
+ * this check can lose the whole payment. */
846
+ decodeInvoice: (bolt11: string) => InvoiceFacts;
847
+ /** Opt-in ceiling, in sats, on what the payer will be asked for. */
848
+ maxPayAmount?: number;
849
+ rfqId?: string;
850
+ }): Promise<{
851
+ rfqId: string;
852
+ quote: RfqQuote;
853
+ /** The solver's hold invoice — what the trader pays, for `payAmount`.
854
+ * Verified against this swap's `H` and the quote's `from_amount`. */
855
+ invoice: string;
856
+ /** What the trader pays: the quote's `from_amount`. */
857
+ payAmount: number;
858
+ /** What the solver's lockup must carry: the quote's `to_amount`. Persist it with the record:
859
+ * `pushClaim` refuses to publish `P` for less. */
860
+ expectedAmount: number;
861
+ /** Last moment the invoice can be paid, unix seconds: `min(invoice
862
+ * expiry, valid_until)`. */
863
+ invoiceExpiresAt: number;
864
+ /** The trader's OWN derivation of the lockup the solver must fund. */
865
+ address: string;
866
+ swapPkScript: Uint8Array;
867
+ script: InstanceType<typeof VHTLC.ScriptV2>;
868
+ payoutAddress: string;
869
+ /** The trader's covenant `receiver` key, bound into the tree. Public. */
870
+ payoutPubkey: Uint8Array;
871
+ /** How the preimage and the payout key are recovered later — map it
872
+ * through `swapSecretsToRecord` and persist BEFORE paying the invoice.
873
+ * Public unless `mustPersistPreimage` says the wallet could not derive P. */
874
+ secrets: ProvisionedClaimSecret;
875
+ /** Every input the covenant was built from; see the same field on
876
+ * `requestLightningSend`'s result. */
877
+ contractParams: LightningReceiveContractParams;
878
+ }>;
879
+ /**
880
+ * The pure core of {@link requestOnchainReceive}: derive BOTH contracts
881
+ * locally — the solver-funded Arkade covenant and the L1 HTLC the trader
882
+ * funds — and refuse on any mismatch. Binding: `solver_pubkey`,
883
+ * `refund_locktime`, `claim_pubkey`, `htlc_locktime`, `min_confirmations`;
884
+ * `lockup_address` and `htlc_address` are compare-only.
885
+ */
886
+ declare function deriveOnchainReceive(input: {
887
+ quote: RfqQuote;
888
+ paymentHash: string;
889
+ payoutPubkey: Uint8Array;
890
+ payoutAddress: string;
891
+ /** The trader's own x-only L1 key — the HTLC's refund role. */
892
+ refundPubkey: Uint8Array;
893
+ operatorPubkey: Uint8Array;
894
+ emulatorPubkey: Uint8Array;
895
+ claimDelay: number;
896
+ hrp: string;
897
+ l1Network: OnchainNetwork;
898
+ }): {
899
+ address: string;
900
+ swapPkScript: Uint8Array;
901
+ script: InstanceType<typeof VHTLC.ScriptV2>;
902
+ /** The L1 HTLC the trader funds, derived locally — fund only this. */
903
+ htlc: OnchainHtlc;
904
+ refundLocktime: number;
905
+ htlcLocktime: number;
906
+ minConfirmations: number;
907
+ };
908
+ /**
909
+ * The `onchain:BTC->arkade:BTC` user flow: quote → derive BOTH contracts
910
+ * locally → verify → gate. Returns the L1 HTLC for the trader's own L1 wallet to fund with
911
+ * `fundAmount`. After `min_confirmations` the solver funds the Arkade lockup; the trader claims it
912
+ * with `P`.
913
+ *
914
+ * Persist `secrets` BEFORE funding. If the swap never settles, the L1 refund leaf opens at
915
+ * `htlc.refundLocktime` (see `buildHtlcRefund`).
916
+ */
917
+ declare function requestOnchainReceive(wallet: IWallet, transport: RfqTransport, params: {
918
+ amount: number;
919
+ amountSide: "from" | "to";
920
+ /** Co-signer key override (33-byte compressed hex); see
921
+ * {@link resolveEmulatorPubkey}. */
922
+ emulatorPubkey?: string;
923
+ /** Trader's x-only L1 key for the HTLC's refund leaf. */
924
+ refundPubkey: Uint8Array;
925
+ /** covclaimd's 33-byte compressed pubkey; see {@link requestLightningReceive}. */
926
+ covclaimdPubkey?: Uint8Array;
927
+ rfqId?: string;
928
+ }): Promise<{
929
+ rfqId: string;
930
+ quote: RfqQuote;
931
+ /** The trader's OWN derivation of the lockup the solver must fund. */
932
+ address: string;
933
+ /** What the trader's L1 funding must carry: the quote's `from_amount`. */
934
+ fundAmount: number;
935
+ /** What the solver's lockup must carry: the quote's `to_amount`. Persist
936
+ * it with the record — see {@link requestLightningReceive}. */
937
+ expectedAmount: number;
938
+ swapPkScript: Uint8Array;
939
+ script: InstanceType<typeof VHTLC.ScriptV2>;
940
+ /** The EXPECTED L1 contract, derived locally — fund only this address. */
941
+ htlc: OnchainHtlc;
942
+ payoutAddress: string;
943
+ payoutPubkey: Uint8Array;
944
+ /** How the preimage and the payout key are recovered later — map it
945
+ * through `swapSecretsToRecord` and persist BEFORE funding. Public unless
946
+ * `mustPersistPreimage` says the wallet could not derive P. */
947
+ secrets: ProvisionedClaimSecret;
948
+ }>;
949
+
950
+ export { lightningReceiveRequest as $, ARKADE_BTC as A, type RfqRefusalReason as B, type ChainSource as C, type RfqStatus as D, arkadeAssetLeg as E, arkadeSwapRequest as F, assertArkadeFundable as G, type HtlcUtxo as H, type InvoiceFacts as I, awaitOnchainFill as J, buildHtlcClaim as K, type LightningSendContractParams as L, MAX_MIN_CONFIRMATIONS as M, buildHtlcRefund as N, type OnchainHtlc as O, canonicalAssetAmount as P, claimOnchainFill as Q, type RfqQuote as R, SwapRefusal as S, classifyOnchainHtlc as T, deriveLightningReceive as U, deriveOnchainReceive as V, deriveOnchainSend as W, extractPreimage as X, httpTransport as Y, l1ScriptForAddress as Z, lightningReceiveContract as _, RFQ_REFUSAL_ERROR_CODES as a, lightningSendContract as a0, lightningSendRequest as a1, newPreimage as a2, normalizeMakerPkScript as a3, normalizeMakerPublicKey as a4, onchainHtlcScript as a5, onchainReceiveRequest as a6, onchainSendRequest as a7, paymentHashOf as a8, relayTransport as a9, requestArkadeSwap as aa, requestLightningReceive as ab, requestOnchainReceive as ac, unilateralClaimDelay as ad, unilateralRefundDelay as ae, unilateralRefundWithoutReceiverDelay as af, verifyLockupAddress as ag, verifyOfferAddress as ah, verifyReceiveInvoice as ai, type RfqRefusalDetail as b, type RfqRefusalErrorCode as c, type RfqRefusalUnit as d, type RfqTransport as e, type LightningReceiveContractParams as f, type OnchainHtlcParams as g, type OnchainNetwork as h, isRfqRefusalErrorCode as i, requestOnchainSend as j, AddressMismatch as k, type ChainUtxo as l, LIGHTNING_BTC as m, LIGHTNING_RECEIVE_PAIR as n, LIGHTNING_SEND_PAIR as o, LOCKTIME_THRESHOLD as p, ONCHAIN_BTC as q, requestLightningSend as r, ONCHAIN_CLAIM_MARGIN_SECONDS as s, ONCHAIN_DUST_SATS as t, ONCHAIN_ORDER_MARGIN_SECONDS as u, ONCHAIN_RECEIVE_PAIR as v, ONCHAIN_SECONDS_PER_BLOCK as w, ONCHAIN_SEND_PAIR as x, type OnchainHtlcPhase as y, type RelaySocket as z };