@arkade-os/swap 0.1.0-rc.8 → 0.1.0

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 (59) hide show
  1. package/README.md +45 -10
  2. package/dist/advanced.cjs +6429 -3083
  3. package/dist/advanced.d.cts +325 -282
  4. package/dist/advanced.d.ts +325 -282
  5. package/dist/advanced.js +343 -34
  6. package/dist/chunk-A3SHHRX4.js +104 -0
  7. package/dist/chunk-FMRAV77W.js +3065 -0
  8. package/dist/{chunk-HV7EIUE2.js → chunk-HRMWBULL.js} +1773 -634
  9. package/dist/chunk-WKJFXXSR.js +3382 -0
  10. package/dist/index.cjs +6868 -3837
  11. package/dist/index.d.cts +71 -243
  12. package/dist/index.d.ts +71 -243
  13. package/dist/index.js +139 -167
  14. package/dist/lockupContract-D7BNjksX.d.ts +148 -0
  15. package/dist/lockupContract-G-9CNRMq.d.cts +148 -0
  16. package/dist/node/index.cjs +61 -10
  17. package/dist/node/index.d.cts +310 -639
  18. package/dist/node/index.d.ts +310 -639
  19. package/dist/node/index.js +65 -10
  20. package/dist/nostr.cjs +428 -49
  21. package/dist/nostr.d.cts +59 -70
  22. package/dist/nostr.d.ts +59 -70
  23. package/dist/nostr.js +268 -36
  24. package/dist/offer-CcJfx5Fj.d.cts +269 -0
  25. package/dist/offer-DdB1M6FZ.d.ts +269 -0
  26. package/dist/offerFillPlan-BII0PW92.d.cts +1642 -0
  27. package/dist/offerFillPlan-CNTLVD7j.d.ts +1642 -0
  28. package/dist/protocol.cjs +5591 -4064
  29. package/dist/protocol.d.cts +258 -355
  30. package/dist/protocol.d.ts +258 -355
  31. package/dist/protocol.js +209 -228
  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-DmPzpbd7.d.ts +2342 -0
  41. package/dist/repository-DqdLVrVv.d.cts +2342 -0
  42. package/dist/rfq-C0tHOvn6.d.cts +983 -0
  43. package/dist/rfq-C0tHOvn6.d.ts +983 -0
  44. package/dist/watch-BonYT9af.d.cts +74 -0
  45. package/dist/watch-CmJQDtsy.d.ts +74 -0
  46. package/package.json +12 -12
  47. package/dist/chunk-4PATNGYQ.js +0 -3297
  48. package/dist/chunk-ARYFNDJY.js +0 -1432
  49. package/dist/chunk-U7VWWTL6.js +0 -66
  50. package/dist/errors-CSpOUdCN.d.ts +0 -2216
  51. package/dist/errors-DVn92LQd.d.cts +0 -2216
  52. package/dist/lockupContract-6TYZOBbn.d.ts +0 -490
  53. package/dist/lockupContract-aLCQQiSu.d.cts +0 -490
  54. package/dist/repository-D0gFF_GA.d.cts +0 -3491
  55. package/dist/repository-tDT8p-Nx.d.ts +0 -3491
  56. package/dist/rfq-DhkgiwQ7.d.cts +0 -1126
  57. package/dist/rfq-DhkgiwQ7.d.ts +0 -1126
  58. package/dist/watch-C4cMEeZT.d.cts +0 -96
  59. package/dist/watch-DbWXdpzm.d.ts +0 -96
package/dist/index.js CHANGED
@@ -2,20 +2,21 @@ import {
2
2
  ARKADE_ASSET_NAMESPACE,
3
3
  AcceptConflict,
4
4
  AmbiguousDestination,
5
- Amount,
6
5
  AmountEncodingUnsupported,
7
- AmountFormatError,
8
6
  AmountMismatch,
9
7
  AssetIdError,
10
8
  BITCOIN_RAILS,
11
9
  BTC_ASSET_PART,
12
10
  ClientDisposed,
11
+ DEFAULT_MAX_REFUND_WINDOW_SECONDS,
13
12
  DiscoverySnapshotUnavailable,
14
13
  InconsistentRoute,
15
14
  InsufficientFunds,
16
15
  MaxFeeExceeded,
17
16
  MissingCorridorDep,
18
17
  NotCancellable,
18
+ OFFER_FILL_OWNERS,
19
+ OFFER_FILL_TEMPLATE,
19
20
  ONCHAIN_SWAP_RAIL,
20
21
  OperatorUnreachable,
21
22
  PAYMENT_STATUS,
@@ -29,18 +30,20 @@ import {
29
30
  UnsupportedRoute,
30
31
  arkadeAsset,
31
32
  assetPartOf,
32
- assetSwapIdOf,
33
33
  bitcoinNetworkOf,
34
+ btcAssetPart,
34
35
  btcOn,
36
+ buildOfferFillPlan,
35
37
  canonicalAssetId,
36
38
  claimFeeSats,
37
39
  createSwapClient,
40
+ deepFreeze,
41
+ digestJointGraph,
38
42
  exchange,
39
- familyOfSwapId,
40
43
  formatAssetId,
41
- fromAtomicDecimal,
42
44
  isAssetId,
43
- isAtomicDecimal,
45
+ isBtcAsset,
46
+ isBtcAssetLenient,
44
47
  isNetworkRef,
45
48
  isSwapError,
46
49
  isTerminalStatus,
@@ -49,45 +52,62 @@ import {
49
52
  parseAssetId,
50
53
  pay,
51
54
  paymentStatusOf,
52
- quoteIdOfSwapId,
55
+ quoteMeta,
53
56
  railAvailable,
54
57
  railOf,
55
58
  receive,
56
59
  receiverExact,
57
60
  sameAsset,
58
61
  swapHandle,
59
- toAtomicDecimal
60
- } from "./chunk-HV7EIUE2.js";
62
+ unsignedPsbtBytes,
63
+ verifyJointGraph,
64
+ verifyOfferFillPlan
65
+ } from "./chunk-HRMWBULL.js";
61
66
  import {
62
- getAssetSwapsOrThrow,
67
+ Amount,
68
+ AmountFormatError,
69
+ assetSwapIdOf,
70
+ familyOfSwapId,
71
+ fromAtomicDecimal,
72
+ isAtomicDecimal,
63
73
  isRfqSwapTerminal,
64
- restoreAssetSwaps,
65
- restoreOfferCoverage
66
- } from "./chunk-4PATNGYQ.js";
74
+ quoteIdOfSwapId,
75
+ toAtomicDecimal
76
+ } from "./chunk-WKJFXXSR.js";
67
77
  import {
78
+ CLAIM_PACKET_TYPE,
68
79
  LockupRegistrationFailed,
69
80
  RFQ_REFUSAL_ERROR_CODES,
81
+ SEALED_CIPHERTEXT_LENGTH,
70
82
  SwapRefusal,
83
+ appendArkadeScript,
84
+ claimPacketShape,
71
85
  isRfqRefusalErrorCode
72
- } from "./chunk-ARYFNDJY.js";
86
+ } from "./chunk-FMRAV77W.js";
73
87
  import {
74
88
  InMemoryAssetSwapRepository,
89
+ assertRfqSwapPageFilter,
75
90
  marketsCacheKey
76
- } from "./chunk-U7VWWTL6.js";
91
+ } from "./chunk-A3SHHRX4.js";
77
92
 
78
93
  // src/indexedDbRepository.ts
79
94
  import {
80
95
  awaitTransaction,
81
96
  createManagedConnection,
82
- promisifyRequest
97
+ promisifyRequest,
98
+ assertPageRequest,
99
+ pageResult
83
100
  } from "@arkade-os/sdk";
84
101
  var DEFAULT_DB_NAME = "arkade-intents";
85
- var DB_VERSION = 3;
102
+ var DB_VERSION = 5;
86
103
  var STORE_SWAPS = "swaps";
87
104
  var STORE_RFQ_SWAPS = "rfqSwaps";
88
105
  var STORE_SWAP_RECORDS = "swapRecords";
89
106
  var STORE_SCANNED = "scannedTxids";
90
107
  var STORE_MARKETS = "markets";
108
+ var STATE_HISTORY_INDEX = "byStateUpdatedAtAndRfqId";
109
+ var HISTORY_INDEX = "byUpdatedAtAndRfqId";
110
+ var LEGACY_STATE_ID_INDEX = "byStateAndRfqId";
91
111
  var STORES = [
92
112
  [STORE_SWAPS, { keyPath: "id" }],
93
113
  // v2. Separate from `swaps` rather than sharing it: the two record types
@@ -101,12 +121,19 @@ var STORES = [
101
121
  [STORE_SCANNED],
102
122
  [STORE_MARKETS]
103
123
  ];
104
- function initDatabase(db, oldVersion, transaction) {
105
- void oldVersion;
106
- void transaction;
124
+ function initDatabase(db, _oldVersion, transaction) {
107
125
  for (const [name, options] of STORES) {
108
126
  if (!db.objectStoreNames.contains(name)) db.createObjectStore(name, options);
109
127
  }
128
+ if (!transaction) throw new Error("IndexedDB upgrade transaction is missing");
129
+ const rfq = transaction.objectStore(STORE_RFQ_SWAPS);
130
+ if (!rfq.indexNames.contains(STATE_HISTORY_INDEX)) {
131
+ rfq.createIndex(STATE_HISTORY_INDEX, ["state", "updatedAt", "rfqId"]);
132
+ }
133
+ if (!rfq.indexNames.contains(HISTORY_INDEX)) {
134
+ rfq.createIndex(HISTORY_INDEX, ["updatedAt", "rfqId"]);
135
+ }
136
+ if (rfq.indexNames.contains(LEGACY_STATE_ID_INDEX)) rfq.deleteIndex(LEGACY_STATE_ID_INDEX);
110
137
  }
111
138
  var IndexedDbAssetSwapRepository = class {
112
139
  version = 5;
@@ -134,8 +161,8 @@ var IndexedDbAssetSwapRepository = class {
134
161
  store.put(swap);
135
162
  });
136
163
  }
137
- async getAllSwaps() {
138
- return promisifyRequest((await this.readStore(STORE_SWAPS)).getAll());
164
+ async getAssetSwapsPage(page) {
165
+ return this.pageStore(STORE_SWAPS, page);
139
166
  }
140
167
  async saveRfqSwap(record) {
141
168
  await this.write(STORE_RFQ_SWAPS, (store) => {
@@ -145,8 +172,44 @@ var IndexedDbAssetSwapRepository = class {
145
172
  async getRfqSwap(rfqId) {
146
173
  return promisifyRequest((await this.readStore(STORE_RFQ_SWAPS)).get(rfqId));
147
174
  }
148
- async getAllRfqSwaps() {
149
- return promisifyRequest((await this.readStore(STORE_RFQ_SWAPS)).getAll());
175
+ async getRfqSwapsPage(filter, page) {
176
+ assertPageRequest(page);
177
+ assertRfqSwapPageFilter(filter);
178
+ const store = await this.readStore(STORE_RFQ_SWAPS);
179
+ const state = filter.state;
180
+ const index = store.index(state === void 0 ? HISTORY_INDEX : STATE_HISTORY_INDEX);
181
+ const after = page.after;
182
+ const useAfter = after !== void 0 && after.updatedAt >= (filter.since ?? 0);
183
+ const start = state === void 0 ? [] : [state];
184
+ const range = useAfter ? IDBKeyRange.lowerBound([...start, after.updatedAt, after.rfqId], true) : IDBKeyRange.lowerBound([...start, filter.since ?? 0]);
185
+ const request = index.openCursor(range);
186
+ return new Promise((resolve, reject) => {
187
+ const rows = [];
188
+ request.onerror = () => reject(request.error);
189
+ request.onsuccess = () => {
190
+ const cursor = request.result;
191
+ if (!cursor || state !== void 0 && cursor.key[0] !== state) {
192
+ resolve(
193
+ pageResult(rows, page.limit, (row) => ({
194
+ updatedAt: row.updatedAt,
195
+ rfqId: row.rfqId
196
+ }))
197
+ );
198
+ return;
199
+ }
200
+ rows.push(cursor.value);
201
+ if (rows.length > page.limit) {
202
+ resolve(
203
+ pageResult(rows, page.limit, (row) => ({
204
+ updatedAt: row.updatedAt,
205
+ rfqId: row.rfqId
206
+ }))
207
+ );
208
+ return;
209
+ }
210
+ cursor.continue();
211
+ };
212
+ });
150
213
  }
151
214
  async removeRfqSwap(rfqId) {
152
215
  await this.write(STORE_RFQ_SWAPS, (store) => {
@@ -161,8 +224,38 @@ var IndexedDbAssetSwapRepository = class {
161
224
  async getSwapRecord(id) {
162
225
  return promisifyRequest((await this.readStore(STORE_SWAP_RECORDS)).get(id));
163
226
  }
164
- async getAllSwapRecords() {
165
- return promisifyRequest((await this.readStore(STORE_SWAP_RECORDS)).getAll());
227
+ async getSwapRecordsPage(page) {
228
+ return this.pageStore(STORE_SWAP_RECORDS, page);
229
+ }
230
+ async pageStore(name, page) {
231
+ assertPageRequest(page);
232
+ const store = await this.readStore(name);
233
+ const range = page.after === void 0 ? void 0 : IDBKeyRange.lowerBound(page.after, true);
234
+ const request = store.openCursor(range);
235
+ return new Promise((resolve, reject) => {
236
+ const rows = [];
237
+ request.onerror = () => reject(request.error);
238
+ request.onsuccess = () => {
239
+ const cursor = request.result;
240
+ if (!cursor) {
241
+ resolve(this.resultOfPage(rows, page.limit));
242
+ return;
243
+ }
244
+ rows.push({ key: cursor.key, value: cursor.value });
245
+ if (rows.length > page.limit) {
246
+ resolve(this.resultOfPage(rows, page.limit));
247
+ return;
248
+ }
249
+ cursor.continue();
250
+ };
251
+ });
252
+ }
253
+ resultOfPage(rows, limit) {
254
+ const result = pageResult(rows, limit, (row) => row.key);
255
+ return {
256
+ items: result.items.map((row) => row.value),
257
+ ...result.nextCursor === void 0 ? {} : { nextCursor: result.nextCursor }
258
+ };
166
259
  }
167
260
  async removeSwapRecord(id) {
168
261
  await this.write(STORE_SWAP_RECORDS, (store) => {
@@ -202,124 +295,6 @@ var IndexedDbAssetSwapRepository = class {
202
295
  }
203
296
  };
204
297
 
205
- // src/restoreRepository.ts
206
- var isOpen = (swap) => swap.status === "pending" || swap.status === "cancelling";
207
- var isOfferSwap = (swap) => typeof swap.offerHex === "string";
208
- var restoreCoverage = async (wallet, swaps) => {
209
- const offers = swaps.filter(isOfferSwap);
210
- if (offers.length > 0) await restoreOfferCoverage(wallet, offers);
211
- };
212
- var aborted = (swaps) => ({
213
- swaps,
214
- changes: [],
215
- scannedTxids: [],
216
- aborted: true
217
- });
218
- async function restoreAssetSwapRepository(opts) {
219
- const { wallet, indexer, repository, txs, operatorPubkey, prepareNew, signal } = opts;
220
- const [existing, scanned] = await Promise.all([
221
- getAssetSwapsOrThrow(repository),
222
- repository.getScannedTxids()
223
- ]);
224
- if (signal?.aborted) return aborted(existing);
225
- let scan;
226
- try {
227
- scan = await restoreAssetSwaps(indexer, txs, new Set(existing.map((swap) => swap.id)), {
228
- operatorPubkey,
229
- scanned,
230
- reopen: existing.filter((swap) => isOpen(swap) && isOfferSwap(swap))
231
- });
232
- } catch (scanError) {
233
- if (!signal?.aborted) {
234
- try {
235
- await restoreCoverage(wallet, existing);
236
- } catch (coverageError2) {
237
- throw new AggregateError(
238
- [scanError, coverageError2],
239
- "asset-swap scan and covenant coverage restore both failed"
240
- );
241
- }
242
- }
243
- throw scanError;
244
- }
245
- if (signal?.aborted) return aborted(existing);
246
- const before = new Map(existing.map((swap) => [swap.id, swap]));
247
- const changes = [];
248
- const cancelledAfterCommit = async (scannedTxids = []) => ({
249
- swaps: await getAssetSwapsOrThrow(repository),
250
- changes,
251
- scannedTxids,
252
- aborted: true
253
- });
254
- for (const restored of scan.restored) {
255
- if (signal?.aborted) return cancelledAfterCommit();
256
- const previous = before.get(restored.id);
257
- const current = previous !== void 0 || !prepareNew ? restored : await prepareNew(restored);
258
- if (current.id !== restored.id) {
259
- throw new Error("prepareNew must not change an asset swap id");
260
- }
261
- if (signal?.aborted) return cancelledAfterCommit();
262
- await repository.saveSwap(current);
263
- changes.push(previous ? { previous, current } : { current });
264
- if (signal?.aborted) return cancelledAfterCommit();
265
- }
266
- if (signal?.aborted) return cancelledAfterCommit();
267
- if (scan.scannedTxids.length > 0) {
268
- await repository.markTxidsScanned(scan.scannedTxids);
269
- }
270
- const swaps = await getAssetSwapsOrThrow(repository);
271
- if (signal?.aborted) return cancelledAfterCommit(scan.scannedTxids);
272
- let coverageError;
273
- try {
274
- await restoreCoverage(wallet, swaps);
275
- } catch (error) {
276
- coverageError = error;
277
- }
278
- return {
279
- swaps,
280
- changes,
281
- scannedTxids: scan.scannedTxids,
282
- aborted: false,
283
- ...coverageError === void 0 ? {} : { coverageError }
284
- };
285
- }
286
-
287
- // src/registerRestore.ts
288
- import { hex } from "@scure/base";
289
- import {
290
- registerWalletRestoreHook,
291
- toXOnlySignerHex
292
- } from "@arkade-os/sdk";
293
- var toRestoreTx = (tx) => ({
294
- type: tx.type.toLowerCase(),
295
- redeemTxid: tx.key.arkTxid,
296
- boardingTxid: tx.key.boardingTxid,
297
- roundTxid: tx.key.commitmentTxid,
298
- createdAt: Math.floor(tx.createdAt / 1e3)
299
- });
300
- function registerAssetSwapRestore(wallet, options) {
301
- return registerWalletRestoreHook(wallet, {
302
- id: "arkade-os:asset-swap",
303
- restore: async (restoredWallet) => {
304
- const [history, indexer, info] = await Promise.all([
305
- restoredWallet.getTransactionHistory(),
306
- options.indexer ?? restoredWallet.getArkadeReader(),
307
- options.operatorPubkey ? void 0 : restoredWallet.getArkadeInfo({ requireLive: true })
308
- ]);
309
- const operatorPubkey = options.operatorPubkey ?? hex.decode(toXOnlySignerHex(info.signerPubkey));
310
- const result = await restoreAssetSwapRepository({
311
- wallet: restoredWallet,
312
- indexer,
313
- repository: options.repository,
314
- txs: history.map(toRestoreTx),
315
- operatorPubkey,
316
- prepareNew: options.prepareNew
317
- });
318
- await options.onResult?.(result);
319
- }
320
- });
321
- }
322
-
323
298
  // src/payment/lightning.ts
324
299
  import { assertNoAssets, assetsOf, invoiceTarget } from "@arkade-os/sdk";
325
300
  var LIGHTNING_RAIL = "lightning";
@@ -330,8 +305,7 @@ var inputFor = (invoice, amount) => ({
330
305
  function lightningRail(client) {
331
306
  return {
332
307
  id: LIGHTNING_RAIL,
333
- // Amount-blind and non-throwing: classification only, which is what
334
- // keeps `match` from being a second gate on top of `available`.
308
+ // classification only, so `match` is not a second gate on top of `available`
335
309
  match: (req) => invoiceTarget(req.raw) !== void 0,
336
310
  available: async (req) => {
337
311
  if (assetsOf(req).length > 0) return false;
@@ -354,18 +328,7 @@ function lightningRail(client) {
354
328
  return {
355
329
  railId: LIGHTNING_RAIL,
356
330
  ...amounts,
357
- meta: {
358
- quoteId: quote.id,
359
- // A `RouteQuote` carries no expiry of its own, so a held one
360
- // can outlive the terms behind it. This is where a caller
361
- // can see that; `send()` refuses with `QuoteExpired` rather
362
- // than silently re-quoting.
363
- expiresAt: quote.expiresAt,
364
- ...quote.refundLocktime === void 0 ? {} : { refundLocktime: quote.refundLocktime },
365
- ...quote.solver === void 0 ? {} : { solver: quote.solver },
366
- ...quote.lock === void 0 ? {} : { paymentHash: quote.lock.hash },
367
- market: quote.market.key
368
- },
331
+ meta: quoteMeta(quote),
369
332
  send: () => swapHandle(LIGHTNING_RAIL, client, quote)
370
333
  };
371
334
  }
@@ -384,12 +347,7 @@ function createSwapPaymentRouter(wallet, client, config) {
384
347
  return new Router({
385
348
  wallet,
386
349
  prefs: { priority: [...SWAP_ROUTER_PRIORITY], ...config.prefs }
387
- }).use(arkRail()).use(onchainRail({ feeInfo: walletFeeSource(wallet) })).use(lightningRail(client)).use(
388
- onchainSwapRail(client, {
389
- claimFeeRateSatVb: config.claimFeeRateSatVb,
390
- ...config.claimVsize === void 0 ? {} : { claimVsize: config.claimVsize }
391
- })
392
- );
350
+ }).use(arkRail()).use(onchainRail({ feeInfo: walletFeeSource(wallet) })).use(lightningRail(client)).use(onchainSwapRail(client, config));
393
351
  }
394
352
  export {
395
353
  ARKADE_ASSET_NAMESPACE,
@@ -402,7 +360,9 @@ export {
402
360
  AssetIdError,
403
361
  BITCOIN_RAILS,
404
362
  BTC_ASSET_PART,
363
+ CLAIM_PACKET_TYPE,
405
364
  ClientDisposed,
365
+ DEFAULT_MAX_REFUND_WINDOW_SECONDS,
406
366
  DiscoverySnapshotUnavailable,
407
367
  InMemoryAssetSwapRepository,
408
368
  InconsistentRoute,
@@ -413,6 +373,8 @@ export {
413
373
  MaxFeeExceeded,
414
374
  MissingCorridorDep,
415
375
  NotCancellable,
376
+ OFFER_FILL_OWNERS,
377
+ OFFER_FILL_TEMPLATE,
416
378
  ONCHAIN_SWAP_RAIL,
417
379
  OperatorUnreachable,
418
380
  PAYMENT_STATUS,
@@ -421,27 +383,36 @@ export {
421
383
  RAILS,
422
384
  REGISTRY_URL,
423
385
  RFQ_REFUSAL_ERROR_CODES,
386
+ SEALED_CIPHERTEXT_LENGTH,
424
387
  SWAP_ERROR_NAMES,
425
388
  SWAP_ROUTER_PRIORITY,
426
389
  SwapDriveRefusedError,
427
390
  SwapPaymentFailedError,
428
391
  SwapRefusal,
429
392
  UnsupportedRoute,
393
+ appendArkadeScript,
430
394
  arkadeAsset,
431
395
  assetPartOf,
432
396
  assetSwapIdOf,
433
397
  bitcoinNetworkOf,
398
+ btcAssetPart,
434
399
  btcOn,
400
+ buildOfferFillPlan,
435
401
  canonicalAssetId,
436
402
  claimFeeSats,
403
+ claimPacketShape,
437
404
  createSwapClient,
438
405
  createSwapPaymentRouter,
406
+ deepFreeze,
407
+ digestJointGraph,
439
408
  exchange,
440
409
  familyOfSwapId,
441
410
  formatAssetId,
442
411
  fromAtomicDecimal,
443
412
  isAssetId,
444
413
  isAtomicDecimal,
414
+ isBtcAsset,
415
+ isBtcAssetLenient,
445
416
  isNetworkRef,
446
417
  isRfqRefusalErrorCode,
447
418
  isRfqSwapTerminal,
@@ -458,9 +429,10 @@ export {
458
429
  railOf,
459
430
  receive,
460
431
  receiverExact,
461
- registerAssetSwapRestore,
462
- restoreAssetSwapRepository,
463
432
  sameAsset,
464
433
  swapHandle,
465
- toAtomicDecimal
434
+ toAtomicDecimal,
435
+ unsignedPsbtBytes,
436
+ verifyJointGraph,
437
+ verifyOfferFillPlan
466
438
  };
@@ -0,0 +1,148 @@
1
+ import { C as CoverageRegistrationOptions } from './offer-DdB1M6FZ.js';
2
+ import { VHTLC, IContractManager } from '@arkade-os/sdk';
3
+
4
+ interface SealedClaimPacket {
5
+ /** `ephPub(33) ‖ nonce(12) ‖ ciphertext`, base64 (93 bytes decoded). The legacy
6
+ * `claim_packet` shape: usable only via covclaimd's Reveal API, which silently
7
+ * needs both sides on the SAME covclaimd, and opens only beside the same `min_amount`
8
+ * when sealed with one. Prefer {@link SealedClaimPacket.packet}. */
9
+ ciphertext: string;
10
+ /**
11
+ * covclaimd's serialised `ClaimPacket` body, base64: TLV `0x01` ciphertext and `0x03`
12
+ * covclaimd_pub_key. **This is what `claim_packet` should carry** (§ 7.1.2). The
13
+ * solver stamps it as Arkade extension packet `0x04`; covclaimd filters on `0x03`, so
14
+ * the client alone chooses which covclaimd.
15
+ *
16
+ * `0x02` arkade_script is deliberately absent: the covenant commits to
17
+ * `taggedHash("ArkScriptHash", script)`, so only the funder's copy is guaranteed to
18
+ * match (see {@link appendArkadeScript}); a client-derived one could strand the claim.
19
+ */
20
+ packet: string;
21
+ }
22
+ interface ClaimPacketInput {
23
+ preimage: Uint8Array;
24
+ /** covclaimd's public key, 33-byte compressed (from its /v1 info). */
25
+ covclaimdPubkey: Uint8Array;
26
+ /** Sats the funded lockup must carry for covclaimd to claim it, as TLV `0x04` and in the
27
+ * AEAD's additional data so a courier cannot strip it. Unset: the unbound legacy bytes. */
28
+ minAmount?: bigint;
29
+ }
30
+ /**
31
+ * Seal a preimage to covclaimd.
32
+ *
33
+ * The ephemeral key and nonce CANNOT be caller-supplied: AES-GCM under a repeated
34
+ * (key, nonce) pair is a total break (forgery and plaintext recovery).
35
+ */
36
+ declare function sealClaimPacket(input: ClaimPacketInput): Promise<SealedClaimPacket>;
37
+ /** `ephPub(33) ‖ nonce(12) ‖ preimage(32) ‖ GCM tag(16)`. Distinguishes the two
38
+ * `claim_packet` shapes: a TLV body carrying it is ≥96 bytes, so lengths cannot collide. */
39
+ declare const SEALED_CIPHERTEXT_LENGTH = 93;
40
+ /** The Arkade extension packet type covclaimd scans the arkd tx stream for. */
41
+ declare const CLAIM_PACKET_TYPE = 4;
42
+ /**
43
+ * Stamp the covenant script into a client's packet — the solver's half.
44
+ *
45
+ * Appending rather than rebuilding is safe: covclaimd's `DeserializeClaim` is
46
+ * order-agnostic, so `0x01, 0x03, 0x02` reads back like its own `0x01, 0x02, 0x03`.
47
+ */
48
+ declare const appendArkadeScript: (body: Uint8Array, arkadeScript: Uint8Array) => Uint8Array;
49
+ type ClaimPacketShape = {
50
+ kind: "ciphertext";
51
+ } | {
52
+ kind: "packet";
53
+ body: Uint8Array;
54
+ covclaimdPubkey?: Uint8Array;
55
+ needsArkadeScript: boolean;
56
+ };
57
+ /**
58
+ * Which of the two `claim_packet` shapes a base64 field carries.
59
+ *
60
+ * Never throws: anything not unambiguously a packet reads as the legacy ciphertext,
61
+ * keeping the Reveal-API path rather than failing a swap over an unfamiliar field.
62
+ */
63
+ declare const claimPacketShape: (b64: string) => ClaimPacketShape;
64
+
65
+ /**
66
+ * The contract row an RFQ lockup registers as — one definition, two writers (`request*Send` and
67
+ * `RfqSwapManager.ensureRegistered`). `createContract` is first-writer-wins, so the second write
68
+ * is a no-op only while both write the SAME row, hence this module.
69
+ */
70
+
71
+ /** The contract type a swap lockup registers under: the SDK's handler for `VHTLC.ScriptV2`.
72
+ *
73
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
74
+ */
75
+ declare const SWAP_LOCKUP_CONTRACT_TYPE = "vhtlc-v2";
76
+ /** @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
77
+ declare const SWAP_LOCKUP_CONTRACT_LABEL = "Arkade RFQ swap lockup";
78
+ /** @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`. */
79
+ declare const SWAP_LOCKUP_CONTRACT_KIND = "rfq-swap-lockup";
80
+ /** The write seam registration needs; a real `ContractManager` satisfies it.
81
+ *
82
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
83
+ */
84
+ type LockupContractWriter = Pick<IContractManager, "createContract">;
85
+ /** The read seam {@link lockupContractParams} needs.
86
+ *
87
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
88
+ */
89
+ type LockupContractReader = Pick<IContractManager, "getContracts">;
90
+ /**
91
+ * No row for a lockup a record claims was funded. The record is fine and its money may be at the
92
+ * address; the wallet's copy of the covenant is missing (store cleared, or a different store
93
+ * registered it). The remedy is a store, not a re-quote.
94
+ *
95
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
96
+ */
97
+ declare class LockupContractMissing extends Error {
98
+ /** The lockup whose row is absent. */
99
+ readonly address: string;
100
+ /** Its pkScript hex — the key the row would have been under. */
101
+ readonly script: string;
102
+ constructor(address: string, script: string);
103
+ }
104
+ /**
105
+ * The lockup could not be written locally: "the quote is fine and your own store failed", unlike
106
+ * {@link SwapRefusal} / {@link AddressMismatch} ("never fund it"). Thrown by `client.accept()`.
107
+ *
108
+ * Nothing is funded yet and on receive legs the invoice never left, so retrying the request is
109
+ * the recovery. `script` lets a caller still holding the swap retry `registerLockupContract`
110
+ * alone; it is NOT enough to resume a request that threw here (no invoice or `secrets`).
111
+ */
112
+ declare class LockupRegistrationFailed extends Error {
113
+ /** The lockup address that was never registered — never fund it: nothing
114
+ * is watching it. */
115
+ readonly address: string;
116
+ /** The covenant the row would have been written from, so the write is retryable without a
117
+ * quote. */
118
+ readonly script: InstanceType<typeof VHTLC.ScriptV2>;
119
+ constructor(script: InstanceType<typeof VHTLC.ScriptV2>, address: string, cause: unknown);
120
+ }
121
+ /**
122
+ * Register a lockup covenant so its VTXOs are watched and — via `vhtlc-v2`'s handler, never
123
+ * generically spendable — kept out of ordinary coin selection.
124
+ *
125
+ * The row carries script-level facts only: rows are keyed by script and first-writer-wins, so
126
+ * anything per-swap written here is stale from the second swap onward. Taking the derived script
127
+ * means the row cannot describe a script other than its key.
128
+ *
129
+ * @throws {LockupRegistrationFailed} so a caller can tell local storage trouble from a bad quote.
130
+ *
131
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
132
+ */
133
+ declare function registerLockupContract(contracts: LockupContractWriter, script: InstanceType<typeof VHTLC.ScriptV2>, address: string, options?: CoverageRegistrationOptions): Promise<void>;
134
+ /**
135
+ * The stored covenant parameters of a funded lockup — the other half of `rebuildRfqSwap`. The row
136
+ * is the wallet's own copy of the tree (`createContract` refuses params that do not reproduce the
137
+ * script), which is why an RFQ swap record stores no tree parameters.
138
+ *
139
+ * Looked up by script, decoded from the address here, so a bad address fails as such rather than
140
+ * as a missing row.
141
+ *
142
+ * @throws {LockupContractMissing} when there is no row.
143
+ *
144
+ * @deprecated Lockup registration is internal to `accept()`; no replacement. Moved off the package root to `@arkade-os/swap/protocol`.
145
+ */
146
+ declare function lockupContractParams(contracts: LockupContractReader, lockupAddress: string): Promise<Record<string, string>>;
147
+
148
+ export { CLAIM_PACKET_TYPE as C, LockupRegistrationFailed as L, SEALED_CIPHERTEXT_LENGTH as S, type ClaimPacketShape as a, appendArkadeScript as b, claimPacketShape as c, type ClaimPacketInput as d, LockupContractMissing as e, type LockupContractReader as f, type LockupContractWriter as g, SWAP_LOCKUP_CONTRACT_KIND as h, SWAP_LOCKUP_CONTRACT_LABEL as i, SWAP_LOCKUP_CONTRACT_TYPE as j, type SealedClaimPacket as k, lockupContractParams as l, registerLockupContract as r, sealClaimPacket as s };