@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
@@ -1,1097 +0,0 @@
1
- import { VHTLC, IWallet, ProvisionedKey, ProvisionedClaimSecret, asset } from '@arkade-os/sdk';
2
-
3
- /** L1 confirmation-depth and reorg margin between dependent timelocks.
4
- *
5
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
6
- */
7
- declare const ONCHAIN_ORDER_MARGIN_SECONDS: number;
8
- /** Don't broadcast a claim with less than this before the refund leaf opens:
9
- * MTP lag plus confirmation time. Past this point the safe move is to let the
10
- * swap die and take the covenant refund — claiming into the counterparty's
11
- * live refund window risks losing the race AND publishing P.
12
- *
13
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
14
- */
15
- declare const ONCHAIN_CLAIM_MARGIN_SECONDS: number;
16
- /** Bounds on the confirmation depth a quote may demand.
17
- *
18
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
19
- */
20
- declare const MAX_MIN_CONFIRMATIONS = 6;
21
- /**
22
- * BIP65's boundary between the two things an absolute locktime can mean.
23
- * Below it consensus reads the value as a block height; at or above it, as a
24
- * unix timestamp. 500,000,000 itself is 1985-07-05 and is a timestamp, so the
25
- * comparison against it is strict.
26
- *
27
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
28
- */
29
- declare const LOCKTIME_THRESHOLD = 500000000;
30
- /** Conservative block interval for converting depths into wall-clock time.
31
- *
32
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
33
- */
34
- declare const ONCHAIN_SECONDS_PER_BLOCK = 600;
35
- /**
36
- * Outputs below this are unspendable in practice; builders refuse them.
37
- *
38
- * 330, not 546: Bitcoin Core's dust threshold is a function of the OUTPUT
39
- * type, and 546 is the P2PKH figure. Both payout scripts on this corridor are
40
- * taproot — the claim pays the user's Arkade-side L1 address and the refund
41
- * pays the trader's — for which the threshold is 330 (the same number
42
- * `FALLBACK_WALLET_DUST_AMOUNT` already uses in the core SDK). Holding the
43
- * P2PKH number here rejects payouts between 330 and 546 that the network
44
- * would relay perfectly well, which on a refund path means refusing to return
45
- * funds that could have been returned.
46
- *
47
- * Should a caller ever pass a legacy `payoutPkScript`, this floor is too low
48
- * for that output and the spend would be non-standard; the threshold would
49
- * then have to be derived from the script rather than fixed.
50
- *
51
- * `BigInt(330)` rather than a `330n` literal, matching the rest of the
52
- * package: a bigint literal needs an ES2020 target, and this source is read
53
- * directly by consumers that target lower — forcing every one of them to
54
- * raise their own target for a single constant. The compiled output is
55
- * identical.
56
- *
57
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
58
- */
59
- declare const ONCHAIN_DUST_SATS: bigint;
60
- /** 32 random bytes. The user generates P for BOTH onchain directions.
61
- *
62
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
63
- */
64
- declare const newPreimage: () => Uint8Array;
65
- /** `sha256(P)`, hex — the wire `payment_hash`, same convention as BOLT11.
66
- *
67
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
68
- */
69
- declare const paymentHashOf: (preimage: Uint8Array) => string;
70
- /** @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
71
- type OnchainNetwork = "bitcoin" | "testnet" | "regtest";
72
- /**
73
- * The `payoutPkScript` {@link buildHtlcClaim} pays the fill to. Resolved EARLY:
74
- * the claim's output is the spender's own choice, so nothing that survives a
75
- * send screen names it, and a destination that cannot be encoded must be
76
- * refused before the swap is negotiated rather than at claim time.
77
- *
78
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
79
- */
80
- declare const l1ScriptForAddress: (address: string, network: OnchainNetwork) => Uint8Array;
81
- /** @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
82
- interface OnchainHtlcParams {
83
- /** `sha256(P)`, hex; the HASH160 commitment is derived internally. */
84
- paymentHash: string;
85
- /** x-only key that claims with the preimage. */
86
- claimKey: Uint8Array;
87
- /** x-only key that refunds after the locktime. */
88
- refundKey: Uint8Array;
89
- /** Absolute unix seconds (consensus matures it against median-time-past). */
90
- refundLocktime: number;
91
- }
92
- /** @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
93
- interface OnchainHtlc {
94
- address: string;
95
- /** `0x5120…` — the P2TR output script. */
96
- pkScript: Uint8Array;
97
- leaves: {
98
- claim: Uint8Array;
99
- refund: Uint8Array;
100
- };
101
- /** Serialized control blocks per leaf, ready for a script-path witness. */
102
- controlBlocks: {
103
- claim: Uint8Array;
104
- refund: Uint8Array;
105
- };
106
- paymentHash: string;
107
- refundLocktime: number;
108
- }
109
- /**
110
- * Derive the two-leaf taproot HTLC. Internal key is the BIP-341 NUMS point, so
111
- * there is no key-path spend, ever:
112
- *
113
- * claim: `OP_SIZE 32 OP_EQUALVERIFY OP_HASH160 <h160> OP_EQUALVERIFY <claimKey> OP_CHECKSIG`
114
- * refund: `<locktime> OP_CHECKLOCKTIMEVERIFY OP_DROP <refundKey> OP_CHECKSIG`
115
- *
116
- * The claim leaf's `OP_SIZE 32 OP_EQUALVERIFY` prefix pins the witness
117
- * preimage to exactly 32 bytes before it's hashed — the same shape real HTLC
118
- * scripts (e.g. BOLT3's) carry, and this contract's preimage is always
119
- * exactly 32 bytes by construction.
120
- *
121
- * Pure derivation — pinned byte-for-byte by the golden test; any drift here
122
- * changes addresses on BOTH sides of a swap.
123
- *
124
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
125
- */
126
- declare function onchainHtlcScript(params: OnchainHtlcParams, network: OnchainNetwork): OnchainHtlc;
127
- /** @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
128
- interface HtlcUtxo {
129
- txid: string;
130
- vout: number;
131
- amount: bigint;
132
- }
133
- interface SpendResult {
134
- txHex: string;
135
- txid: string;
136
- /** `utxo.amount − fee` — what actually lands at the payout script. */
137
- payoutAmount: bigint;
138
- }
139
- /** Script-path spend of the claim leaf; the witness reveals P — that is how
140
- * the counterparty learns it, so never build this unless the claim will win
141
- * (see {@link claimOnchainFill}). `sign` is BIP340 over the claim key.
142
- *
143
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
144
- */
145
- declare const buildHtlcClaim: (input: {
146
- htlc: OnchainHtlc;
147
- utxo: HtlcUtxo;
148
- preimage: Uint8Array;
149
- payoutPkScript: Uint8Array;
150
- feeRateSatVb: number;
151
- sign: (sighash: Uint8Array) => Promise<Uint8Array>;
152
- }) => Promise<SpendResult>;
153
- /** Script-path spend of the refund leaf; consensus-valid only once nLockTime
154
- * has matured against median-time-past — gate on {@link ChainSource.getMtp},
155
- * not wall clock. `sign` is BIP340 over the refund key.
156
- *
157
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
158
- */
159
- declare const buildHtlcRefund: (input: {
160
- htlc: OnchainHtlc;
161
- utxo: HtlcUtxo;
162
- payoutPkScript: Uint8Array;
163
- feeRateSatVb: number;
164
- sign: (sighash: Uint8Array) => Promise<Uint8Array>;
165
- }) => Promise<SpendResult>;
166
- /** @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
167
- interface ChainUtxo extends HtlcUtxo {
168
- confirmations: number;
169
- }
170
- /** The package's whole view of Bitcoin L1. An esplora-backed implementation
171
- * belongs to the caller (a reference one lives in the test suite); the package
172
- * itself stays backend-free.
173
- *
174
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
175
- */
176
- interface ChainSource {
177
- /** Confirmed+mempool outputs paying a script; used to detect the fill. */
178
- getScriptUtxos(pkScript: Uint8Array): Promise<ChainUtxo[]>;
179
- /** The spend of an outpoint, if any — where P is extracted from. A
180
- * provider omitting the spender txid still lists it in `pkScript`'s history. */
181
- getSpendingTx(txid: string, vout: number, pkScript: Uint8Array): Promise<{
182
- txHex: string;
183
- } | null>;
184
- broadcast(txHex: string): Promise<string>;
185
- /** Current median-time-past, unix seconds — gates refund broadcasting. */
186
- getMtp(): Promise<number>;
187
- }
188
- /** Read P out of a claim spend's witness: the 32-byte item whose sha256 is the
189
- * payment hash. Null when the tx reveals no matching preimage (e.g. a refund
190
- * spend, or an unrelated tx).
191
- *
192
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
193
- */
194
- declare function extractPreimage(txHex: string, paymentHash: string): Uint8Array | null;
195
- /** Poll {@link ChainSource} until the HTLC is funded to the required depth.
196
- * Picks the largest qualifying output when several exist. Throws (reason
197
- * `fill_timeout`) once `deadline` (unix seconds) passes without one.
198
- *
199
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
200
- */
201
- declare function awaitOnchainFill(chain: ChainSource, htlc: OnchainHtlc, minConfirmations: number, options?: {
202
- pollMs?: number;
203
- deadline?: number;
204
- }): Promise<ChainUtxo>;
205
- /**
206
- * Claim the fill: build the claim spend and broadcast it. Broadcasting
207
- * publishes P (mempool) — by design, it is how the solver gets paid — so this
208
- * refuses (reason `claim_window_closed`) when less than
209
- * {@link ONCHAIN_CLAIM_MARGIN_SECONDS} remains before the refund leaf opens:
210
- * past that point, let the swap die and take the covenant refund instead of
211
- * racing the counterparty's refund with P exposed.
212
- *
213
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
214
- */
215
- declare function claimOnchainFill(chain: ChainSource, input: {
216
- htlc: OnchainHtlc;
217
- utxo: HtlcUtxo;
218
- preimage: Uint8Array;
219
- payoutPkScript: Uint8Array;
220
- feeRateSatVb: number;
221
- sign: (sighash: Uint8Array) => Promise<Uint8Array>;
222
- /** Injected for tests; defaults to wall clock. */
223
- now?: number;
224
- }): Promise<{
225
- txid: string;
226
- payoutAmount: bigint;
227
- }>;
228
- /** Where an onchain HTLC stands, for crash recovery (see the store docs:
229
- * persisting the record BEFORE funding is what makes this classification —
230
- * and the claim — possible after a restart).
231
- *
232
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
233
- */
234
- type OnchainHtlcPhase = {
235
- phase: "unfunded";
236
- } | {
237
- phase: "awaiting_confirmations";
238
- utxo: ChainUtxo;
239
- } | {
240
- phase: "claimable";
241
- utxo: ChainUtxo;
242
- }
243
- /**
244
- * The refund leaf has matured, which means the CLAIM WINDOW IS CLOSED —
245
- * `claimOnchainFill` throws `claim_window_closed` from here, by design.
246
- * A recovery caller reading this phase must not try to claim: the correct
247
- * action is to let the counterparty's L1 refund settle and take the
248
- * Arkade-side covenant refund. Reaching this phase on a swap you expected
249
- * to claim means the claim was missed, not that it is still available.
250
- */
251
- | {
252
- phase: "refundable";
253
- utxo: ChainUtxo;
254
- } | {
255
- phase: "claimed";
256
- txid: string;
257
- preimage: Uint8Array;
258
- } | {
259
- phase: "swept";
260
- txid: string;
261
- };
262
- /**
263
- * Classify an HTLC from chain state alone. `funding` (the known outpoint from
264
- * the stored record) is what distinguishes "never funded" from "funded and
265
- * already spent": without it a spent HTLC looks unfunded.
266
- *
267
- * `claimed` carries the preimage read from the spend's witness — the receipt;
268
- * `swept` is a spend that reveals no preimage (the counterparty's refund).
269
- *
270
- * @deprecated Internal to the onchain corridor; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
271
- */
272
- declare function classifyOnchainHtlc(chain: ChainSource, input: {
273
- htlc: OnchainHtlc;
274
- minConfirmations: number;
275
- funding?: {
276
- txid: string;
277
- vout: number;
278
- };
279
- }): Promise<OnchainHtlcPhase>;
280
-
281
- /** Legs are `<corridor>:<asset>`; a pair is directional, `from->to`.
282
- *
283
- * @deprecated An RFQ pair leg, not an asset id — the client builds the pair from the route. The v2 asset id is `btcOn("arkade", network)`. Moved off the package root to `@arkade-os/swap/protocol`.
284
- */
285
- declare const ARKADE_BTC = "arkade:BTC";
286
- /** @deprecated An RFQ pair leg, not an asset id — the client builds the pair from the route. The v2 asset id is `btcOn("bolt11", network)`. Moved off the package root to `@arkade-os/swap/protocol`. */
287
- declare const LIGHTNING_BTC = "lightning:BTC";
288
- /** @deprecated An RFQ pair leg, not an asset id — the client builds the pair from the route. The v2 asset id is `btcOn("bitcoin", network)`. Moved off the package root to `@arkade-os/swap/protocol`. */
289
- declare const ONCHAIN_BTC = "onchain:BTC";
290
- /** The arkade leg for an asset: the asset id itself, 68 lowercase hex. The id
291
- * lives in the pair rather than the profile because the pair is the field both
292
- * sides route and subscribe on, and a coarse leg cannot say which asset a
293
- * market key is for.
294
- *
295
- * Taking an `AssetId` rather than a string is what enforces the case rule:
296
- * `hex.decode` accepts uppercase while `hex.encode` only emits lowercase, so a
297
- * value that reached us as `A1B2…` leaves here as `a1b2…`. Solvers compare pair
298
- * strings byte for byte — a sender that normalised only in its key derivation
299
- * would reach the right subscription and then be skipped as an unserved pair.
300
- *
301
- * @deprecated An RFQ pair leg, not an asset id — the client builds the pair from the route. The v2 asset id is `arkadeAsset(network, id)`. Moved off the package root to `@arkade-os/swap/protocol`.
302
- */
303
- declare const arkadeAssetLeg: (id: asset.AssetId) => string;
304
- /** The implemented pair: pay a BOLT11 invoice out of an Arkade balance.
305
- *
306
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
307
- */
308
- declare const LIGHTNING_SEND_PAIR: string;
309
- /** On-board via Lightning: pay the solver's hold invoice, land on Arkade.
310
- *
311
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
312
- */
313
- declare const LIGHTNING_RECEIVE_PAIR: string;
314
- /** Off-board: Arkade sats out to a Bitcoin-L1 HTLC.
315
- *
316
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
317
- */
318
- declare const ONCHAIN_SEND_PAIR: string;
319
- /** On-board: a Bitcoin-L1 HTLC in, Arkade sats out.
320
- *
321
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
322
- */
323
- declare const ONCHAIN_RECEIVE_PAIR: string;
324
- /** The closed refusal set. Treat any unknown reason as a generic decline.
325
- *
326
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
327
- */
328
- type RfqRefusalReason = "unsupported_pair" | "unsupported_payload" | "amount_out_of_range" | "exposure_cap" | "invoice_expired" | "quote_conflict" | "pricing_unavailable" | "rate_limited";
329
- /** A refusal from the solver, carrying its closed-set reason. */
330
- declare class SwapRefusal extends Error {
331
- /** Literal-typed so the v2 error taxonomy's union discriminates on `name`
332
- * — a `string` here collapses the discriminant for every member. Same value
333
- * the constructor has always set, moved to a field initializer. */
334
- readonly name = "SwapRefusal";
335
- readonly reason: string;
336
- readonly rfqId: string | undefined;
337
- constructor(reason: string, rfqId?: string);
338
- }
339
- /**
340
- * The solver's address does not match the local derivation. NEVER fund past
341
- * this. `derived` is every candidate address tried — more than one when the
342
- * derivation itself is ambiguous, see {@link verifyLockupAddress}.
343
- *
344
- * @deprecated Folded into `QuoteVerificationFailed`, which `client.quote()` throws. Moved off the package root to `@arkade-os/swap/protocol`.
345
- */
346
- declare class AddressMismatch extends Error {
347
- readonly derived: string | string[];
348
- readonly quoted: string | undefined;
349
- constructor(derived: string | string[], quoted?: string);
350
- }
351
- /** @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`. */
352
- interface RfqQuote {
353
- v: 1;
354
- type: "rfq_quote";
355
- rfq_id: string;
356
- pair: string;
357
- from_amount: number;
358
- to_amount: number;
359
- solver_pubkey: string;
360
- valid_until: number;
361
- /** HTLC-class quotes only; absent for arkade↔arkade. */
362
- refund_locktime?: number;
363
- profile: {
364
- [key: string]: unknown;
365
- payment_hash?: string;
366
- lockup_address?: string;
367
- };
368
- [key: string]: unknown;
369
- }
370
- /** @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`. */
371
- interface RfqStatus {
372
- v: 1;
373
- type: "rfq_status";
374
- rfq_id: string;
375
- state: string;
376
- updated_at: number;
377
- profile: Record<string, unknown>;
378
- [key: string]: unknown;
379
- }
380
- /** The rfq_request for the lightning send profile. A BOLT11 profile is always
381
- * exact-out: the invoice fixes the amount, so none is restated here.
382
- * `senderPubkey` is the trader's own key for the VHTLC's sender-side leaves
383
- * (see {@link lightningSendContract}) — required, never sent anywhere else,
384
- * never trusted by the solver as anything but a pubkey to bind into the
385
- * script. On the wire it's `client_refund_pubkey` (the payload schemas are
386
- * public at https://docs.arkadeos.com/intents/reference/rfq — the solver's schema
387
- * is `.strict()`, so both the wrong name AND the missing required field would
388
- * refuse every request).
389
- *
390
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
391
- */
392
- declare const lightningSendRequest: (input: {
393
- rfqId: string;
394
- invoice: string;
395
- refundAddress: string;
396
- senderPubkey: Uint8Array;
397
- }) => Record<string, unknown>;
398
- /** The rfq_request for an arkade↔arkade swap. Exactly one side may name an
399
- * asset id per direction (BTC has none), and the id is the leg itself — see
400
- * {@link arkadeAssetLeg}. Forward-looking: the wire shape is specified, the
401
- * reference solver does not serve it yet.
402
- *
403
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
404
- */
405
- declare const arkadeSwapRequest: (input: {
406
- rfqId: string;
407
- /** Asset the trader deposits; omit when depositing BTC. */
408
- offerAsset?: asset.AssetId;
409
- /** Asset the trader wants; omit when wanting BTC. */
410
- wantAsset?: asset.AssetId;
411
- amountSide: "from" | "to";
412
- /** Integer base units of the side named by `amountSide`. */
413
- amount: number;
414
- }) => Record<string, unknown>;
415
- /**
416
- * Compare-only check of the solver's address against YOUR OWN derivation(s)
417
- * — never extends trust, only narrows it.
418
- *
419
- * `derivedAddress` may be a single address or an array of candidates. Pass an
420
- * array when your own derivation is ambiguous — as it is for the covenant
421
- * lockups while solvers roll out the timelocked non-interactive refund leaf:
422
- * nothing on the wire says whether a given quote's covenant carries it (the
423
- * shape is fixed by the solver's own build, not negotiated per quote), so the
424
- * only safe move is to derive BOTH shapes and accept whichever one the quote's
425
- * own `lockup_address` matches. This loses no security: every candidate shape
426
- * pins the refund to the trader's own refund destination, so a solver gains
427
- * nothing by choosing which one to quote.
428
- *
429
- * Throws {@link AddressMismatch} only when NONE of the candidates match.
430
- * Returns the address that matched, so calls chain exactly as before.
431
- *
432
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
433
- */
434
- declare const verifyLockupAddress: (quote: RfqQuote, derivedAddress: string | string[]) => string;
435
- /** @deprecated Transport is an inference; `@arkade-os/swap/nostr` stays the hand-built floor. Moved off the package root to `@arkade-os/swap/protocol`. */
436
- interface RfqTransport {
437
- requestQuote(payload: Record<string, unknown>): Promise<RfqQuote>;
438
- status(rfqId: string): Promise<RfqStatus | null>;
439
- close(): Promise<void>;
440
- }
441
- /** HTTP: POST /v1/swap for quotes, GET /v1/rfq/<rfq_id> for status.
442
- * `fetchImpl` is injectable for tests and non-global-fetch runtimes.
443
- *
444
- * @deprecated A dev transport; `client.quote()` opens the card's rendezvous itself. Moved off the package root to `@arkade-os/swap/protocol`.
445
- */
446
- declare const httpTransport: (baseUrl: string, options?: {
447
- fetchImpl?: typeof fetch;
448
- }) => RfqTransport;
449
- /** Minimal WebSocket surface the relay transport needs — satisfied by the DOM
450
- * WebSocket and by `ws` alike, so neither becomes a dependency.
451
- *
452
- * @deprecated A dev transport; `client.quote()` opens the card's rendezvous itself. Moved off the package root to `@arkade-os/swap/protocol`.
453
- */
454
- interface RelaySocket {
455
- send(data: string): void;
456
- close(): void;
457
- addEventListener(type: "open" | "message" | "error", listener: (event: any) => void): void;
458
- }
459
- /** Relay: both parties outbound, addressed by x-only pubkey, speaking the dev
460
- * broker framing. Nostr (directed kind + NIP-44) replaces only this function.
461
- * One socket; replies correlated by rfq_id.
462
- *
463
- * @deprecated A dev transport; `client.quote()` opens the card's rendezvous itself. Moved off the package root to `@arkade-os/swap/protocol`.
464
- */
465
- declare const relayTransport: (relayUrl: string, options: {
466
- solverPubkey: string;
467
- clientPubkey: string;
468
- WebSocketCtor?: new (url: string) => RelaySocket;
469
- timeoutMs?: number;
470
- }) => RfqTransport;
471
- /** The solver's unilateral-claim delay, derived from the Ark server's reported
472
- * exit delay exactly as the reference solver derives it — both sides read the
473
- * SAME server, so the derivation (not a quote field) is what keeps the two
474
- * scripts identical.
475
- *
476
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
477
- */
478
- declare const unilateralClaimDelay: (operatorExitDelaySeconds: number) => number;
479
- /** VHTLC's `unilateralRefund` tier: sender + receiver, no server — LEVEL with
480
- * `claimDelay`, not above it. Neither party can spend a two-signature leaf
481
- * alone, so separating it buys no safety, and every second spent separating it
482
- * is a second taken off the headroom that does matter.
483
- *
484
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
485
- */
486
- declare const unilateralRefundDelay: (claimDelay: number) => number;
487
- /** VHTLC's `unilateralRefundWithoutReceiver` tier: sender alone, needing
488
- * nobody. The only leaf whose timing can steal — a funder able to refund
489
- * before the claimant can claim takes money from someone holding the preimage
490
- * — so it opens last, by {@link SOLO_REFUND_HEADROOM_SECONDS}.
491
- *
492
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
493
- */
494
- declare const unilateralRefundWithoutReceiverDelay: (claimDelay: number) => number;
495
- /** Compile the lightning-send VHTLC from the quote's binding fields plus the
496
- * trader's own data. `paymentHash` is the BOLT11 payment hash (`sha256(P)`,
497
- * hex); the script's HASH160 commitment is derived from it here, which is why
498
- * the trader never needs to see `P`.
499
- *
500
- * Every quote gets the full emulator-covenant suite on top of VHTLC's own six
501
- * (`claim`/`refund`/`refundWithoutReceiver`/`unilateralClaim`/
502
- * `unilateralRefund`/`unilateralRefundWithoutReceiver`): `nonInteractiveClaim`
503
- * (server + emulator, pays the solver's own `receiverPkScript`, no solver
504
- * signature needed), `nonInteractiveRefund` (server + solver + emulator, pays
505
- * the trader's own `refundPkScript`, no timelock and no trader signature
506
- * needed — see {@link VHTLC.Options.nonInteractiveParameters}'s doc comment for why
507
- * that matters), and its timelocked twin `nonInteractiveRefundWithoutReceiver`
508
- * (server + emulator alone, after `refundLocktime` — the only refund tier
509
- * needing no participant at all). Nine leaves in all, unless `legacy` says
510
- * otherwise.
511
- *
512
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
513
- */
514
- declare function lightningSendContract(params: {
515
- /** Binding field #1: the solver's x-only key, from the quote. */
516
- solverPubkey: Uint8Array;
517
- /** Binding field #2: when the trader's refund path opens, from the quote. */
518
- refundLocktime: number;
519
- /** The Ark server's x-only key — the trader's OWN connection. */
520
- operatorPubkey: Uint8Array;
521
- /** BOLT11 payment hash, hex — from the trader's OWN invoice decode. */
522
- paymentHash: string;
523
- /** From {@link unilateralClaimDelay} over the trader's OWN server info.
524
- * {@link unilateralRefundDelay} and {@link unilateralRefundWithoutReceiverDelay}
525
- * derive from this same value — one rounding, shared across all three tiers. */
526
- claimDelay: number;
527
- /** Emulator x-only key (32 bytes). */
528
- emulatorPubkey: Uint8Array;
529
- /** Where a refund must pay: the trader's P2TR pkScript (34 bytes). Also
530
- * the refund covenants' destination. */
531
- refundPkScript: Uint8Array;
532
- /** The trader's own key — VHTLC's `sender` role. Required on every
533
- * interactive refund-side leaf; the trader generates and persists it
534
- * (see {@link requestLightningSend}'s own obligations). */
535
- senderPubkey: Uint8Array;
536
- /** The solver's own claim destination, from the quote
537
- * (`profile.receiver_pk_script`) — needed only so `nonInteractiveClaim`'s
538
- * covenant key can be derived; the trader does not otherwise use or trust
539
- * this value. P2TR pkScript, 34 bytes. */
540
- receiverPkScript: Uint8Array;
541
- /** LEGACY REBUILD ONLY — see {@link VHTLC.Options.nonInteractiveParameters}'s
542
- * `legacy` field. Set only to re-derive a lockup funded before the
543
- * timelocked refund leaf shipped; {@link matchQuotedLockup} passes it when
544
- * the quote's own address says the solver quoted that shape. */
545
- legacy?: "preTimelockedRefund";
546
- }): InstanceType<typeof VHTLC.ScriptV2>;
547
- /** Every input {@link lightningSendContract} builds from. Derived from the
548
- * builder rather than restated, so the two cannot drift.
549
- *
550
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
551
- */
552
- type LightningSendContractParams = Parameters<typeof lightningSendContract>[0];
553
- /** The BOLT11 facts the trader read from its OWN decode — this module takes
554
- * the facts, not the decoder, so any wallet's existing decoder serves.
555
- *
556
- * @deprecated Bolt11 strings at the boundary; `client.quote()` decodes them. Moved off the package root to `@arkade-os/swap/protocol`.
557
- */
558
- interface InvoiceFacts {
559
- /** The raw BOLT11 — what travels in the request profile. */
560
- raw: string;
561
- /** `sha256(P)`, LOWERCASE hex (64 chars) — {@link verifyReceiveInvoice}
562
- * compares it byte-for-byte against `paymentHashOf`, which emits lowercase. */
563
- paymentHash: string;
564
- amountSats: number;
565
- /** Absolute expiry, unix seconds. */
566
- expiresAt: number;
567
- }
568
- /**
569
- * The lightning-send user flow, mirroring `createOffer`'s shape: quote →
570
- * derive locally → verify → gate. Pure of funding on purpose — it returns the
571
- * address and amount, and the caller funds with its own wallet
572
- * (`wallet.send({ address, amount })`) before `quote.valid_until`, after
573
- * which the user may go OFFLINE: filling is non-interactive. Success reveals
574
- * the preimage in the solver's claim witness (also served via status as
575
- * `settled`); failure refunds to `refundAddress`.
576
- *
577
- * Throws {@link SwapRefusal} (closed reason), {@link AddressMismatch} (never
578
- * fund), a gate error with a stable `reason`, or
579
- * {@link LockupRegistrationFailed} — the last one alone means the quote is
580
- * still good and the same call can be retried once local storage is.
581
- *
582
- * Broadcasts nothing, but does write locally: the lockup is registered with the
583
- * wallet's contract manager before the address is returned, exactly as
584
- * `createOffer` registers its covenant — so the lockup is watched from the
585
- * moment it lands and out of generic coin selection, and a persistence failure
586
- * throws while nothing is funded. `RfqSwapManager` re-registers as a backstop
587
- * for older records; a repeat write is a no-op.
588
- *
589
- * The `sender` key is the wallet's identity key, as {@link provisionRefundKey}
590
- * pins it — returned as `senderPubkey` plus `secrets`. `secrets` holds only a
591
- * public descriptor; the signer re-derives from the wallet, so nothing secret
592
- * is at rest. Persist `secrets` with the record anyway: it is how the refund
593
- * signer is found again. `nonInteractiveRefund` recovers the funds even
594
- * without it — but it needs the SOLVER's active cooperation, not just
595
- * infrastructure uptime.
596
- *
597
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
598
- */
599
- declare function requestLightningSend(wallet: IWallet, transport: RfqTransport, params: {
600
- invoice: InvoiceFacts;
601
- rfqId?: string;
602
- /** Co-signer key override (33-byte compressed hex); see
603
- * {@link resolveEmulatorPubkey}. */
604
- emulatorPubkey?: string;
605
- }): Promise<{
606
- rfqId: string;
607
- quote: RfqQuote;
608
- /** The trader's OWN derivation — the only address to fund. */
609
- address: string;
610
- /** What the lockup must carry: the quote's `from_amount` (the invoice
611
- * amount plus the corridor's fee), in sats. */
612
- fundAmount: number;
613
- /** The covenant's scriptPubKey, for watching the lockup and its spend. */
614
- swapPkScript: Uint8Array;
615
- /** The covenant itself. Hand it to `RfqSwapManager` as the record's
616
- * `lockup` (with `address`): without it the manager can only poll, and
617
- * cannot retire the row this call just wrote. */
618
- script: InstanceType<typeof VHTLC.ScriptV2>;
619
- /** Where a failed swap refunds — the same address `secrets.pkScript` was
620
- * decoded from, so the quote and the covenant always name one script. */
621
- refundAddress: string;
622
- /** The VHTLC `sender` x-only key, bound into the covenant. Public. */
623
- senderPubkey: Uint8Array;
624
- /** How the `sender` key is recovered later. Persist it with the record;
625
- * it holds nothing secret. */
626
- secrets: ProvisionedKey;
627
- /**
628
- * Every input the covenant was built from, as it was AT REQUEST TIME.
629
- *
630
- * Returned so a consumer can persist the swap without re-deriving any of
631
- * it. Half of these are not on the quote: `serverPubkey` and `claimDelay`
632
- * come from this wallet's own `getArkadeInfo()`, `emulatorPubkey` from a
633
- * per-network pin, `refundPkScript` from `secrets` — decoded from the
634
- * refund address at provisioning time, the same address this call returns
635
- * as `refundAddress`.
636
- *
637
- * All public. Persisting them is optional: this call also registers the
638
- * lockup as a contract, and that row is where `rebuildRfqSwap` takes its
639
- * covenant from — see `rfqRecord.ts`. Keep a copy only to hold a record
640
- * that rebuilds without the wallet's contract store, and keep it as
641
- * `VHTLCV2ContractHandler.serializeParams(script.options)`, the shape the
642
- * rebuild accepts.
643
- */
644
- contractParams: LightningSendContractParams;
645
- }>;
646
- /** The rfq_request for `arkade:BTC->onchain:BTC`. Exact-out means "this much
647
- * lands in the L1 HTLC". `senderPubkey` is the user's own key for the
648
- * VHTLC's sender-side leaves — same role as in {@link lightningSendRequest}.
649
- * On the wire it's `client_refund_pubkey`, same as there.
650
- *
651
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
652
- */
653
- declare const onchainSendRequest: (input: {
654
- rfqId: string;
655
- /** `sha256(P)`, hex — user-chosen; see {@link paymentHashOf}. */
656
- paymentHash: string;
657
- /** User's x-only L1 key for the HTLC's claim leaf. */
658
- payoutPubkey: Uint8Array;
659
- /** User's arkade address — where the covenant refund must pay. */
660
- refundAddress: string;
661
- senderPubkey: Uint8Array;
662
- amount: number;
663
- amountSide: "from" | "to";
664
- }) => Record<string, unknown>;
665
- /** The rfq_request for `lightning:BTC->arkade:BTC`: pay the solver's hold
666
- * invoice, land on Arkade. The trader generates `P`, keeps it, and sends only
667
- * `H` plus `P` sealed to covclaimd — the solver never sees `P` until it
668
- * appears in a claim witness. `payoutPubkey` is the trader's own x-only
669
- * Arkade key — the covenant's `receiver` role on this leg, so the trader can
670
- * claim the lockup itself without covclaimd.
671
- *
672
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
673
- */
674
- declare const lightningReceiveRequest: (input: {
675
- rfqId: string;
676
- /** `H = sha256(P)`, hex — trader-chosen; see {@link paymentHashOf}. */
677
- paymentHash: string;
678
- /** Trader's arkade address — where the swapped sats land. */
679
- payoutAddress: string;
680
- /** Trader's x-only arkade key — the covenant's `receiver` role. */
681
- payoutPubkey: Uint8Array;
682
- /** `P` sealed to covclaimd, base64 — `sealClaimPacket(...).ciphertext`. */
683
- claimPacket: string;
684
- amount: number;
685
- amountSide: "from" | "to";
686
- }) => Record<string, unknown>;
687
- /** The rfq_request for `onchain:BTC->arkade:BTC`. The user funds the L1 HTLC
688
- * (holding its refund role) and receives Arkade; P travels sealed to
689
- * covclaimd (see `sealClaimPacket`) so the user can go offline after
690
- * funding. `payoutPubkey` is the trader's own x-only Arkade key — the
691
- * covenant's `receiver` role, same as the Lightning receive leg's.
692
- *
693
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
694
- */
695
- declare const onchainReceiveRequest: (input: {
696
- rfqId: string;
697
- paymentHash: string;
698
- /** Trader's arkade address — where the swapped sats land. */
699
- payoutAddress: string;
700
- /** Trader's x-only arkade key — the covenant's `receiver` role. */
701
- payoutPubkey: Uint8Array;
702
- /** Trader's x-only L1 key for the HTLC's refund leaf. */
703
- refundPubkey: Uint8Array;
704
- /** `P` sealed to covclaimd, base64 — `sealClaimPacket(...).ciphertext`. */
705
- claimPacket: string;
706
- amount: number;
707
- amountSide: "from" | "to";
708
- }) => Record<string, unknown>;
709
- /**
710
- * The pure core of {@link requestOnchainSend}: derive BOTH contracts locally
711
- * from the quote's binding fields plus the user's own data, and refuse on any
712
- * mismatch. Binding: `solver_pubkey`, `refund_locktime`, `htlc_pubkey`,
713
- * `htlc_locktime`, `min_confirmations`; `lockup_address` and `htlc_address`
714
- * are compare-only.
715
- *
716
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
717
- */
718
- declare function deriveOnchainSend(input: {
719
- quote: RfqQuote;
720
- paymentHash: string;
721
- payoutPubkey: Uint8Array;
722
- operatorPubkey: Uint8Array;
723
- emulatorPubkey: Uint8Array;
724
- claimDelay: number;
725
- hrp: string;
726
- l1Network: OnchainNetwork;
727
- refundAddress: string;
728
- /** The user's own key for the VHTLC's sender-side leaves — same role as
729
- * in {@link requestLightningSend}. */
730
- senderPubkey: Uint8Array;
731
- }): {
732
- address: string;
733
- swapPkScript: Uint8Array;
734
- /** The lockup covenant itself — what the contract row is registered from,
735
- * so the row can never key on a script other than the derived one. */
736
- script: InstanceType<typeof VHTLC.ScriptV2>;
737
- htlc: OnchainHtlc;
738
- /** The inputs {@link htlc} was built from. Returned because nothing else
739
- * can give them back: `OnchainHtlc` exposes only derived values, and this
740
- * contract is Bitcoin L1 — there is no Arkade contract row for it, so a
741
- * consumer persisting the swap has no other route to rebuilding it. */
742
- htlcParams: OnchainHtlcParams;
743
- /** Echoed from the input, so a result is a complete description of the L1
744
- * half rather than one a caller has to re-assemble from what it passed in.
745
- * {@link onchainSendProfile} reads it from here. */
746
- l1Network: OnchainNetwork;
747
- refundLocktime: number;
748
- htlcLocktime: number;
749
- minConfirmations: number;
750
- };
751
- /**
752
- * The `arkade:BTC->onchain:BTC` user flow, mirroring `requestLightningSend`:
753
- * quote → derive BOTH contracts locally → verify → gate. Pure of funding —
754
- * the caller funds `address` with its own wallet before `quote.valid_until`.
755
- *
756
- * Registers the arkade lockup before returning the address, on the same terms
757
- * as {@link requestLightningSend} — including {@link LockupRegistrationFailed},
758
- * the one throw here that does not mean "walk away from this quote". The L1
759
- * HTLC is not a contract row: it lives on bitcoin, not on Ark, and the wallet's
760
- * contract manager knows nothing of it.
761
- *
762
- * Two obligations, both LOUD:
763
- * - **Persist `secrets` (with the record) BEFORE funding.** On an HD wallet it
764
- * is a public descriptor and both the preimage and the `sender` key
765
- * re-derive from the seed; otherwise it carries the raw secrets, and losing
766
- * them forfeits the L1 claim and every interactive refund path — leaving
767
- * recovery dependent on the solver via `nonInteractiveRefund`.
768
- * - **Stay claim-capable.** Unlike lightning-send the user cannot go fully
769
- * offline: it must claim the L1 HTLC (`awaitOnchainFill` →
770
- * `claimOnchainFill`) before `htlc.refundLocktime`. Missing that window
771
- * forfeits the fill and falls back to the Arkade covenant refund.
772
- *
773
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
774
- */
775
- declare function requestOnchainSend(wallet: IWallet, transport: RfqTransport, params: {
776
- amount: number;
777
- amountSide: "from" | "to";
778
- /** User's x-only L1 key that will claim the HTLC. */
779
- payoutPubkey: Uint8Array;
780
- /** Optional caller-owned P. Persist it with the returned secrets before funding. */
781
- preimage?: Uint8Array;
782
- rfqId?: string;
783
- /** Co-signer key override (33-byte compressed hex); see
784
- * {@link resolveEmulatorPubkey}. */
785
- emulatorPubkey?: string;
786
- }): Promise<{
787
- rfqId: string;
788
- quote: RfqQuote;
789
- /** The user's OWN arkade lockup derivation — the only address to fund. */
790
- address: string;
791
- fundAmount: number;
792
- swapPkScript: Uint8Array;
793
- /** The arkade covenant itself — the record's `lockup` for
794
- * `RfqSwapManager`, same role as {@link requestLightningSend}'s. */
795
- script: InstanceType<typeof VHTLC.ScriptV2>;
796
- refundAddress: string;
797
- /** The EXPECTED L1 fill, derived locally — watch and claim against this. */
798
- htlc: OnchainHtlc;
799
- /** The inputs {@link htlc} was built from — persist these to rebuild it
800
- * after a restart. Nothing else gives them back: `OnchainHtlc` exposes only
801
- * derived values, and this contract is Bitcoin L1, so unlike the arkade
802
- * lockup there is no contract row holding its parameters. Persist
803
- * `htlc.address` alongside them (`OnchainSendProfile.htlcAddress`): the
804
- * rebuild checks the two against each other, which is the only check
805
- * available on a leg with no second copy of its covenant.
806
- *
807
- * `onchainSendProfile(result)` does all of that mapping for you; prefer it
808
- * to reading these fields across by hand. */
809
- htlcParams: OnchainHtlcParams;
810
- /**
811
- * Which bitcoin network the L1 HTLC was derived for.
812
- *
813
- * Returned because it is NOT the ark network name and cannot be recovered
814
- * from one by inspection: this call maps `info.network` through a private
815
- * narrowing where signet, mutinynet and testnet4 all become `"testnet"`.
816
- * A caller reconstructing it from context would be re-deriving a mapping
817
- * it cannot see, and a value the profile needs verbatim.
818
- */
819
- l1Network: OnchainNetwork;
820
- /** `profile.min_confirmations`; gates when the L1 fill becomes claimable,
821
- * and part of what a restored swap needs to drive its own claim. */
822
- minConfirmations: number;
823
- /** The arkade lockup's refund deadline, as the covenant was built with it.
824
- * Read this rather than `quote.refund_locktime`: that field is optional on
825
- * the wire, a solver may carry the value in `profile` instead, and
826
- * `deriveOnchainSend` is what settles which one this contract used. */
827
- refundLocktime: number;
828
- /** The VHTLC `sender` x-only key, bound into the covenant. Public. */
829
- senderPubkey: Uint8Array;
830
- /** How the preimage and the `sender` key are recovered later — map it
831
- * through `swapSecretsToRecord` and persist BEFORE funding. Public unless
832
- * `mustPersistPreimage` says the wallet could not derive P. */
833
- secrets: ProvisionedClaimSecret;
834
- }>;
835
- /**
836
- * Bind the SOLVER's hold invoice to the quote and to the trader's own `H`.
837
- *
838
- * This is the only field the trader hands to a third party, and the only
839
- * attack on this corridor with no on-chain trace: an invoice on some other
840
- * payment hash is paid to the solver in full and no lockup on `H` is ever
841
- * funded. NEVER publish an invoice that has not passed this.
842
- *
843
- * The decoder is injected — `@arkade-os/swap` takes no BOLT11 dependency — but
844
- * unlike {@link requestLightningSend}, which takes the caller's facts about
845
- * the caller's OWN invoice, the comparison lives here: a caller-supplied
846
- * summary of an adversary's invoice checks nothing.
847
- *
848
- * There is no check for "is this actually a hold invoice": on the wire it is
849
- * indistinguishable from an ordinary one.
850
- *
851
- * Reasons: `invoice_undecodable` | `invoice_hash_mismatch` |
852
- * `invoice_amount_mismatch` | `quote_malformed`.
853
- *
854
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
855
- */
856
- declare const verifyReceiveInvoice: (input: {
857
- invoice: string;
858
- decode: (bolt11: string) => InvoiceFacts;
859
- /** `sha256(P)`, hex — the trader's OWN. */
860
- paymentHash: string;
861
- quote: RfqQuote;
862
- }) => {
863
- payDeadline: number;
864
- };
865
- /** Compile the RECEIVE-direction VHTLC: the same suite-carrying tree as {@link
866
- * lightningSendContract} with the roles inverted — the trader is the
867
- * `receiver` (it generated `P` and claims the lockup with it), the solver is
868
- * the `sender` (it funds the lockup and holds the refund recourse). One
869
- * function shared by both receive corridors, mirroring the send legs' sharing
870
- * of `lightningSendContract`.
871
- *
872
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
873
- */
874
- declare function lightningReceiveContract(params: {
875
- /** Binding field #1: the solver's x-only key, from the quote — VHTLC's
876
- * `sender` role on the receive corridors. */
877
- solverPubkey: Uint8Array;
878
- /** Binding field #2: the SOLVER's own refund deadline on these legs, from
879
- * the quote — after it the solver may reclaim an unclaimed lockup. */
880
- refundLocktime: number;
881
- /** The Ark server's x-only key — the trader's OWN connection. */
882
- operatorPubkey: Uint8Array;
883
- /** `sha256(P)`, hex — the trader's OWN preimage hash. */
884
- paymentHash: string;
885
- /** From {@link unilateralClaimDelay} over the trader's OWN server info. */
886
- claimDelay: number;
887
- /** Emulator x-only key — see {@link requestLightningSend}'s parameter. */
888
- emulatorPubkey: Uint8Array;
889
- /** The solver's covenant refund destination, from the quote
890
- * (`profile.solver_refund_pk_script`) — the one tree parameter nothing
891
- * else on the wire determines. */
892
- solverRefundPkScript: Uint8Array;
893
- /** The trader's own x-only Arkade key — VHTLC's `receiver` role on these
894
- * legs, so the trader can claim without covclaimd. */
895
- payoutPubkey: Uint8Array;
896
- /** The trader's own Arkade payout pkScript (decoded from its payout
897
- * address) — `nonInteractiveClaim`'s pinned destination. */
898
- payoutPkScript: Uint8Array;
899
- /** LEGACY REBUILD ONLY — see {@link lightningSendVtxoScript}'s `legacy`. */
900
- legacy?: "preTimelockedRefund";
901
- }): InstanceType<typeof VHTLC.ScriptV2>;
902
- /** Every input {@link lightningReceiveContract} builds from; see
903
- * {@link LightningSendContractParams}.
904
- *
905
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
906
- */
907
- type LightningReceiveContractParams = Parameters<typeof lightningReceiveContract>[0];
908
- /**
909
- * The pure core of {@link requestLightningReceive}: derive the solver-funded
910
- * covenant locally from the quote's binding fields plus the trader's own data
911
- * and refuse on any address mismatch. The trader funds nothing on Arkade on
912
- * this leg — verification is still what makes paying the hold invoice safe:
913
- * the lockup the solver will fund must be the tree whose claim paths pay the
914
- * trader.
915
- *
916
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
917
- */
918
- declare function deriveLightningReceive(input: {
919
- quote: RfqQuote;
920
- paymentHash: string;
921
- payoutPubkey: Uint8Array;
922
- payoutAddress: string;
923
- operatorPubkey: Uint8Array;
924
- emulatorPubkey: Uint8Array;
925
- claimDelay: number;
926
- hrp: string;
927
- }): {
928
- address: string;
929
- swapPkScript: Uint8Array;
930
- script: InstanceType<typeof VHTLC.ScriptV2>;
931
- /** The solver's hold invoice on `H` — what the trader pays to arm the swap. */
932
- invoice: string;
933
- refundLocktime: number;
934
- /** Every input the covenant was built from — see the same field on
935
- * `requestLightningSend`'s result for why a consumer needs them. */
936
- contractParams: LightningReceiveContractParams;
937
- };
938
- /**
939
- * The `lightning:BTC->arkade:BTC` user flow: quote → derive the covenant
940
- * locally → verify → gate. Returns the solver's hold invoice to PAY — the
941
- * payment itself is the trader's own Lightning wallet's job, exactly as
942
- * funding is the caller's job on the send corridors. Once the paid HTLC is
943
- * held, the solver funds the lockup; the trader claims it with `P` (its own,
944
- * generated here) — itself via the collaborative claim leaf
945
- * ({@link claimReceiveLockup} in `claim.ts`), or via covclaimd if it is
946
- * offline.
947
- *
948
- * Three obligations, all of them before the invoice is handed to a payer:
949
- *
950
- * 1. Persist `secrets` and `expectedAmount`. The preimage and the payout key
951
- * re-derive from `secrets` (or, on a non-HD wallet, are carried by it), and
952
- * without `expectedAmount` the claim has nothing to compare the funded
953
- * value against.
954
- * 2. Stay online. covclaimd cannot claim this covenant today, so the offline
955
- * path the claim packet exists for does not run yet: an unclaimed lockup is
956
- * reclaimed by the solver at `refund_locktime` and the payer refunded.
957
- * 3. On {@link LockupRegistrationFailed}, call this function again once the
958
- * store is working. The failed attempt is inert — it returned no invoice,
959
- * so nothing can be paid into the lockup nobody is watching — and the new
960
- * call derives its own preimage and `rfq_id`. Re-registering `error.script`
961
- * does NOT resume it: the invoice and `secrets` were never handed back.
962
- *
963
- * The invoice is the solver's, so it is verified here against the trader's own
964
- * `H` and the quote ({@link verifyReceiveInvoice}) before it is returned —
965
- * nothing publishable comes back from a failed check, registration included.
966
- * Pay before `invoiceExpiresAt`: the hold-invoice window is minutes, not the
967
- * quote's `valid_until`.
968
- *
969
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
970
- */
971
- declare function requestLightningReceive(wallet: IWallet, transport: RfqTransport, params: {
972
- amount: number;
973
- amountSide: "from" | "to";
974
- /** Co-signer key override (33-byte compressed hex); see
975
- * {@link resolveEmulatorPubkey}. */
976
- emulatorPubkey?: string;
977
- /** covclaimd's 33-byte compressed pubkey (from its own info endpoint)
978
- * — the claim packet seals to it and only it can ever read `P` early. */
979
- covclaimdPubkey: Uint8Array;
980
- /** The caller's own BOLT11 decoder, applied to the SOLVER's invoice.
981
- * Required: an optional verifier is one integrators skip, and this is
982
- * the check whose absence loses the whole payment. */
983
- decodeInvoice: (bolt11: string) => InvoiceFacts;
984
- /** Opt-in ceiling, in sats, on what the payer will be asked for. */
985
- maxPayAmount?: number;
986
- rfqId?: string;
987
- }): Promise<{
988
- rfqId: string;
989
- quote: RfqQuote;
990
- /** The solver's hold invoice — what the trader pays, for `payAmount`.
991
- * Verified against this swap's `H` and the quote's `from_amount`. */
992
- invoice: string;
993
- /** What the trader pays: the quote's `from_amount`. */
994
- payAmount: number;
995
- /** What the solver's lockup must carry: the quote's `to_amount`. Persist
996
- * it with the record — `pushClaim` refuses to publish `P` for less, and
997
- * captured at claim time instead it would be whatever the solver funded. */
998
- expectedAmount: number;
999
- /** Last moment the invoice can be paid, unix seconds: `min(invoice
1000
- * expiry, valid_until)`. Absolute on purpose — a countdown returned from
1001
- * here is stale before the caller reads it; derive one at display time. */
1002
- invoiceExpiresAt: number;
1003
- /** The trader's OWN derivation of the lockup the solver must fund. */
1004
- address: string;
1005
- swapPkScript: Uint8Array;
1006
- script: InstanceType<typeof VHTLC.ScriptV2>;
1007
- payoutAddress: string;
1008
- /** The trader's covenant `receiver` key, bound into the tree. Public. */
1009
- payoutPubkey: Uint8Array;
1010
- /** How the preimage and the payout key are recovered later — map it
1011
- * through `swapSecretsToRecord` and persist BEFORE paying the invoice.
1012
- * Public unless `mustPersistPreimage` says the wallet could not derive P. */
1013
- secrets: ProvisionedClaimSecret;
1014
- /** Every input the covenant was built from; see the same field on
1015
- * `requestLightningSend`'s result. */
1016
- contractParams: LightningReceiveContractParams;
1017
- }>;
1018
- /**
1019
- * The pure core of {@link requestOnchainReceive}: derive BOTH contracts
1020
- * locally — the solver-funded Arkade covenant and the L1 HTLC the trader
1021
- * funds — and refuse on any mismatch. Binding: `solver_pubkey`,
1022
- * `refund_locktime`, `claim_pubkey`, `htlc_locktime`, `min_confirmations`;
1023
- * `lockup_address` and `htlc_address` are compare-only.
1024
- *
1025
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
1026
- */
1027
- declare function deriveOnchainReceive(input: {
1028
- quote: RfqQuote;
1029
- paymentHash: string;
1030
- payoutPubkey: Uint8Array;
1031
- payoutAddress: string;
1032
- /** The trader's own x-only L1 key — the HTLC's refund role. */
1033
- refundPubkey: Uint8Array;
1034
- operatorPubkey: Uint8Array;
1035
- emulatorPubkey: Uint8Array;
1036
- claimDelay: number;
1037
- hrp: string;
1038
- l1Network: OnchainNetwork;
1039
- }): {
1040
- address: string;
1041
- swapPkScript: Uint8Array;
1042
- script: InstanceType<typeof VHTLC.ScriptV2>;
1043
- /** The L1 HTLC the trader funds, derived locally — fund only this. */
1044
- htlc: OnchainHtlc;
1045
- refundLocktime: number;
1046
- htlcLocktime: number;
1047
- minConfirmations: number;
1048
- };
1049
- /**
1050
- * The `onchain:BTC->arkade:BTC` user flow: quote → derive BOTH contracts
1051
- * locally → verify → gate. Returns the L1 HTLC to fund (`htlc.address`, for
1052
- * `fundAmount`) — the funding transaction itself is the trader's own L1
1053
- * wallet's job, exactly as on the send corridors. After `min_confirmations`
1054
- * the solver funds the Arkade lockup; the trader claims it with `P` (its
1055
- * own), itself or via covclaimd.
1056
- *
1057
- * Persist `secrets` BEFORE funding, and note the direction's own deadline:
1058
- * if the swap never settles, the L1 HTLC's refund leaf (the trader's
1059
- * `refundPubkey`) opens at `htlc.refundLocktime` — `buildHtlcRefund` takes it
1060
- * back from there.
1061
- *
1062
- * @deprecated Internal to `client.quote()` and `client.accept()`. Moved off the package root to `@arkade-os/swap/protocol`.
1063
- */
1064
- declare function requestOnchainReceive(wallet: IWallet, transport: RfqTransport, params: {
1065
- amount: number;
1066
- amountSide: "from" | "to";
1067
- /** Co-signer key override (33-byte compressed hex); see
1068
- * {@link resolveEmulatorPubkey}. */
1069
- emulatorPubkey?: string;
1070
- /** Trader's x-only L1 key for the HTLC's refund leaf. */
1071
- refundPubkey: Uint8Array;
1072
- /** covclaimd's 33-byte compressed pubkey — see {@link requestLightningReceive}. */
1073
- covclaimdPubkey: Uint8Array;
1074
- rfqId?: string;
1075
- }): Promise<{
1076
- rfqId: string;
1077
- quote: RfqQuote;
1078
- /** The trader's OWN derivation of the lockup the solver must fund. */
1079
- address: string;
1080
- /** What the trader's L1 funding must carry: the quote's `from_amount`. */
1081
- fundAmount: number;
1082
- /** What the solver's lockup must carry: the quote's `to_amount`. Persist
1083
- * it with the record — see {@link requestLightningReceive}. */
1084
- expectedAmount: number;
1085
- swapPkScript: Uint8Array;
1086
- script: InstanceType<typeof VHTLC.ScriptV2>;
1087
- /** The EXPECTED L1 contract, derived locally — fund only this address. */
1088
- htlc: OnchainHtlc;
1089
- payoutAddress: string;
1090
- payoutPubkey: Uint8Array;
1091
- /** How the preimage and the payout key are recovered later — map it
1092
- * through `swapSecretsToRecord` and persist BEFORE funding. Public unless
1093
- * `mustPersistPreimage` says the wallet could not derive P. */
1094
- secrets: ProvisionedClaimSecret;
1095
- }>;
1096
-
1097
- export { paymentHashOf as $, ARKADE_BTC as A, buildHtlcClaim as B, type ChainSource as C, buildHtlcRefund as D, claimOnchainFill as E, classifyOnchainHtlc as F, deriveLightningReceive as G, type HtlcUtxo as H, type InvoiceFacts as I, deriveOnchainReceive as J, deriveOnchainSend as K, type LightningSendContractParams as L, MAX_MIN_CONFIRMATIONS as M, extractPreimage as N, type OnchainHtlc as O, httpTransport as P, l1ScriptForAddress as Q, type RfqQuote as R, SwapRefusal as S, lightningReceiveContract as T, lightningReceiveRequest as U, lightningSendContract as V, lightningSendRequest as W, newPreimage as X, onchainHtlcScript as Y, onchainReceiveRequest as Z, onchainSendRequest as _, type RfqTransport as a, relayTransport as a0, requestLightningReceive as a1, requestOnchainReceive as a2, unilateralClaimDelay as a3, unilateralRefundDelay as a4, unilateralRefundWithoutReceiverDelay as a5, verifyLockupAddress as a6, verifyReceiveInvoice as a7, type LightningReceiveContractParams as b, type OnchainHtlcParams as c, type OnchainNetwork as d, requestOnchainSend as e, AddressMismatch as f, type ChainUtxo as g, LIGHTNING_BTC as h, LIGHTNING_RECEIVE_PAIR as i, LIGHTNING_SEND_PAIR as j, LOCKTIME_THRESHOLD as k, ONCHAIN_BTC as l, ONCHAIN_CLAIM_MARGIN_SECONDS as m, ONCHAIN_DUST_SATS as n, ONCHAIN_ORDER_MARGIN_SECONDS as o, ONCHAIN_RECEIVE_PAIR as p, ONCHAIN_SECONDS_PER_BLOCK as q, requestLightningSend as r, ONCHAIN_SEND_PAIR as s, type OnchainHtlcPhase as t, type RelaySocket as u, type RfqRefusalReason as v, type RfqStatus as w, arkadeAssetLeg as x, arkadeSwapRequest as y, awaitOnchainFill as z };