@arkade-os/sdk 0.4.48 → 0.4.49

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 (77) hide show
  1. package/dist/adapters/expo.cjs +5 -5
  2. package/dist/adapters/expo.d.cts +2 -2
  3. package/dist/adapters/expo.d.ts +2 -2
  4. package/dist/adapters/expo.js +3 -3
  5. package/dist/adapters/indexedDB.cjs +5 -5
  6. package/dist/adapters/indexedDB.js +4 -4
  7. package/dist/{ark-CjE0KkGp.d.cts → ark-nkSiPYNf.d.cts} +86 -24
  8. package/dist/{ark-CjE0KkGp.d.ts → ark-nkSiPYNf.d.ts} +86 -24
  9. package/dist/{asyncStorageTaskQueue-D9SOPMPC.d.ts → asyncStorageTaskQueue-DCaEE83p.d.ts} +1 -1
  10. package/dist/{asyncStorageTaskQueue-CeLZhZFU.d.cts → asyncStorageTaskQueue-DdxhsEz6.d.cts} +1 -1
  11. package/dist/{chunk-ENZ4YPR2.cjs → chunk-2LAJ3RTH.cjs} +491 -418
  12. package/dist/chunk-2LAJ3RTH.cjs.map +1 -0
  13. package/dist/{chunk-NYR5H6GR.js → chunk-5QVBJUOG.js} +154 -81
  14. package/dist/chunk-5QVBJUOG.js.map +1 -0
  15. package/dist/{chunk-SYDANBJI.cjs → chunk-6UI5BFE7.cjs} +9 -9
  16. package/dist/{chunk-SYDANBJI.cjs.map → chunk-6UI5BFE7.cjs.map} +1 -1
  17. package/dist/{chunk-G6J6AEMH.js → chunk-BLJQV3N4.js} +4 -4
  18. package/dist/{chunk-G6J6AEMH.js.map → chunk-BLJQV3N4.js.map} +1 -1
  19. package/dist/{chunk-BHHLRZCS.js → chunk-CPO2UB7L.js} +4 -4
  20. package/dist/{chunk-BHHLRZCS.js.map → chunk-CPO2UB7L.js.map} +1 -1
  21. package/dist/{chunk-7TXSPRN5.cjs → chunk-E7HB3GKK.cjs} +31 -2
  22. package/dist/chunk-E7HB3GKK.cjs.map +1 -0
  23. package/dist/{chunk-ZDDBTFVO.js → chunk-EFNLTS6Q.js} +29 -3
  24. package/dist/chunk-EFNLTS6Q.js.map +1 -0
  25. package/dist/{chunk-XFMGIFBL.js → chunk-HN25T276.js} +4 -4
  26. package/dist/{chunk-XFMGIFBL.js.map → chunk-HN25T276.js.map} +1 -1
  27. package/dist/{chunk-5XMVTK5S.cjs → chunk-LJQ2VQBE.cjs} +211 -230
  28. package/dist/chunk-LJQ2VQBE.cjs.map +1 -0
  29. package/dist/{chunk-4VVTRPH3.js → chunk-MBSYQ3WX.js} +183 -201
  30. package/dist/chunk-MBSYQ3WX.js.map +1 -0
  31. package/dist/{chunk-EB3ALGTM.cjs → chunk-QDXQULVM.cjs} +13 -13
  32. package/dist/{chunk-EB3ALGTM.cjs.map → chunk-QDXQULVM.cjs.map} +1 -1
  33. package/dist/{chunk-ENDNQPZA.cjs → chunk-XOLH3LFO.cjs} +17 -17
  34. package/dist/{chunk-ENDNQPZA.cjs.map → chunk-XOLH3LFO.cjs.map} +1 -1
  35. package/dist/contracts/handlers/index.cjs +8 -8
  36. package/dist/contracts/handlers/index.d.cts +3 -3
  37. package/dist/contracts/handlers/index.d.ts +3 -3
  38. package/dist/contracts/handlers/index.js +2 -2
  39. package/dist/{delegate-D3dY-2vS.d.cts → delegate-Cqqw1T1J.d.cts} +1 -1
  40. package/dist/{delegate-DhGZk1r2.d.ts → delegate-D6Orvyq7.d.ts} +1 -1
  41. package/dist/{index-DK4_iWYy.d.ts → index-CWoogah0.d.ts} +2 -2
  42. package/dist/{index-D6RQROds.d.cts → index-Yd4hecbM.d.cts} +2 -2
  43. package/dist/index.cjs +181 -181
  44. package/dist/index.d.cts +8 -8
  45. package/dist/index.d.ts +8 -8
  46. package/dist/index.js +4 -4
  47. package/dist/repositories/realm/index.cjs +19 -19
  48. package/dist/repositories/realm/index.d.cts +2 -2
  49. package/dist/repositories/realm/index.d.ts +2 -2
  50. package/dist/repositories/realm/index.js +5 -5
  51. package/dist/repositories/sqlite/index.cjs +18 -18
  52. package/dist/repositories/sqlite/index.d.cts +2 -2
  53. package/dist/repositories/sqlite/index.d.ts +2 -2
  54. package/dist/repositories/sqlite/index.js +5 -5
  55. package/dist/{taskRunner-Brnak0Rc.d.cts → taskRunner-BjB5QINR.d.cts} +1 -1
  56. package/dist/{taskRunner-B-2MHCYG.d.ts → taskRunner-Dw7xs60Q.d.ts} +1 -1
  57. package/dist/wallet/expo/background.cjs +14 -14
  58. package/dist/wallet/expo/background.d.cts +3 -3
  59. package/dist/wallet/expo/background.d.ts +3 -3
  60. package/dist/wallet/expo/background.js +6 -6
  61. package/dist/wallet/expo/index.cjs +14 -14
  62. package/dist/wallet/expo/index.d.cts +4 -4
  63. package/dist/wallet/expo/index.d.ts +4 -4
  64. package/dist/wallet/expo/index.js +5 -5
  65. package/dist/{wallet-B5bwixQa.d.ts → wallet-CGkWu3xV.d.cts} +2 -2
  66. package/dist/{wallet-DiOrtYic.d.cts → wallet-DyUHrPyN.d.ts} +2 -2
  67. package/dist/worker/expo/index.cjs +9 -9
  68. package/dist/worker/expo/index.d.cts +4 -4
  69. package/dist/worker/expo/index.d.ts +4 -4
  70. package/dist/worker/expo/index.js +5 -5
  71. package/package.json +1 -1
  72. package/dist/chunk-4VVTRPH3.js.map +0 -1
  73. package/dist/chunk-5XMVTK5S.cjs.map +0 -1
  74. package/dist/chunk-7TXSPRN5.cjs.map +0 -1
  75. package/dist/chunk-ENZ4YPR2.cjs.map +0 -1
  76. package/dist/chunk-NYR5H6GR.js.map +0 -1
  77. package/dist/chunk-ZDDBTFVO.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunk7TXSPRN5_cjs = require('./chunk-7TXSPRN5.cjs');
3
+ var chunkE7HB3GKK_cjs = require('./chunk-E7HB3GKK.cjs');
4
4
  var chunk5BLDMQED_cjs = require('./chunk-5BLDMQED.cjs');
5
5
  var base = require('@scure/base');
6
6
  var descriptorsScure = require('@bitcoinerlab/descriptors-scure');
@@ -76,14 +76,14 @@ var ContractHandlerRegistry = class {
76
76
  var contractHandlers = new ContractHandlerRegistry();
77
77
  exports.DefaultVtxo = void 0;
78
78
  ((DefaultVtxo2) => {
79
- class Script3 extends chunk7TXSPRN5_cjs.VtxoScript {
79
+ class Script3 extends chunkE7HB3GKK_cjs.VtxoScript {
80
80
  /** Create the default virtual output script with one forfeit path and one exit path. */
81
81
  constructor(options) {
82
82
  const { pubKey, serverPubKey, csvTimelock } = options;
83
- const forfeitScript = chunk7TXSPRN5_cjs.MultisigTapscript.encode({
83
+ const forfeitScript = chunkE7HB3GKK_cjs.MultisigTapscript.encode({
84
84
  pubkeys: [pubKey, serverPubKey]
85
85
  }).script;
86
- const exitScript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.encode({
86
+ const exitScript = chunkE7HB3GKK_cjs.CSVMultisigTapscript.encode({
87
87
  timelock: csvTimelock,
88
88
  pubkeys: [pubKey]
89
89
  }).script;
@@ -194,8 +194,8 @@ function deriveDescriptorLeafPubKey(descriptor) {
194
194
  return key.pubkey;
195
195
  }
196
196
 
197
- // src/contracts/constants.ts
198
- var DEFAULT_PAGE_SIZE = 500;
197
+ // src/contracts/metadata.ts
198
+ var WALLET_RECEIVE_SOURCE = "wallet-receive";
199
199
 
200
200
  // src/contracts/handlers/helpers.ts
201
201
  function extractRawPubKey(value) {
@@ -240,6 +240,12 @@ function resolveRole(contract, context) {
240
240
  }
241
241
  return void 0;
242
242
  }
243
+ function extractPubKeyBytes(value) {
244
+ return base.hex.decode(extractPubKey(normalizeToDescriptor(value)));
245
+ }
246
+ function deserializeCsvTimelock(value) {
247
+ return value !== void 0 && value !== "" ? chunkE7HB3GKK_cjs.sequenceToTimelock(Number(value)) : exports.DefaultVtxo.Script.DEFAULT_TIMELOCK;
248
+ }
243
249
  var CLTV_HEIGHT_THRESHOLD = 500000000n;
244
250
  function isCltvSatisfied(context, locktime) {
245
251
  if (locktime < CLTV_HEIGHT_THRESHOLD) {
@@ -252,7 +258,7 @@ function isCltvSatisfied(context, locktime) {
252
258
  function isCsvSpendable(context, sequence) {
253
259
  if (sequence === void 0) return true;
254
260
  if (!context.vtxo) return false;
255
- const timelock = chunk7TXSPRN5_cjs.sequenceToTimelock(sequence);
261
+ const timelock = chunkE7HB3GKK_cjs.sequenceToTimelock(sequence);
256
262
  if (timelock.type === "blocks") {
257
263
  if (context.blockHeight === void 0 || context.vtxo.status.block_height === void 0) {
258
264
  return false;
@@ -266,34 +272,112 @@ function isCsvSpendable(context, sequence) {
266
272
  }
267
273
  return false;
268
274
  }
275
+ function exitSequence(contract) {
276
+ return contract.params.csvTimelock ? Number(contract.params.csvTimelock) : void 0;
277
+ }
278
+ function selectForfeitOrExitPath(script, contract, context) {
279
+ if (context.collaborative) {
280
+ return { leaf: script.forfeit() };
281
+ }
282
+ const sequence = exitSequence(contract);
283
+ if (!isCsvSpendable(context, sequence)) {
284
+ return null;
285
+ }
286
+ return { leaf: script.exit(), sequence };
287
+ }
288
+ function forfeitExitAllPaths(script, contract, context) {
289
+ const paths = [];
290
+ if (context.collaborative) {
291
+ paths.push({ leaf: script.forfeit() });
292
+ }
293
+ const exitPath = { leaf: script.exit() };
294
+ const sequence = exitSequence(contract);
295
+ if (sequence !== void 0) {
296
+ exitPath.sequence = sequence;
297
+ }
298
+ paths.push(exitPath);
299
+ return paths;
300
+ }
301
+ function forfeitExitSpendablePaths(script, contract, context) {
302
+ const paths = [];
303
+ if (context.collaborative) {
304
+ paths.push({ leaf: script.forfeit() });
305
+ }
306
+ const sequence = exitSequence(contract);
307
+ if (isCsvSpendable(context, sequence)) {
308
+ const exitPath = { leaf: script.exit() };
309
+ if (sequence !== void 0) {
310
+ exitPath.sequence = sequence;
311
+ }
312
+ paths.push(exitPath);
313
+ }
314
+ return paths;
315
+ }
269
316
  async function detectUsedScripts(indexerProvider, scriptHexes) {
270
317
  const used = /* @__PURE__ */ new Set();
271
- if (scriptHexes.length === 0) return used;
272
- const remaining = new Set(scriptHexes);
273
- let pageIndex = 0;
274
- let hasMore = true;
275
- while (hasMore && remaining.size > 0) {
276
- const { vtxos, page } = await chunk7TXSPRN5_cjs.getNormalizedVtxos(indexerProvider, {
277
- scripts: scriptHexes,
278
- pageIndex,
279
- pageSize: DEFAULT_PAGE_SIZE
280
- });
281
- for (const vtxo of vtxos) {
282
- if (remaining.delete(vtxo.script)) used.add(vtxo.script);
318
+ const unique = [...new Set(scriptHexes)];
319
+ for (let offset = 0; offset < unique.length; offset += chunkE7HB3GKK_cjs.SCRIPT_QUERY_CHUNK_SIZE) {
320
+ const scripts = unique.slice(offset, offset + chunkE7HB3GKK_cjs.SCRIPT_QUERY_CHUNK_SIZE);
321
+ const remaining = new Set(scripts);
322
+ let pageIndex = 0;
323
+ let hasMore = true;
324
+ while (hasMore && remaining.size > 0) {
325
+ const { vtxos, page } = await chunkE7HB3GKK_cjs.getNormalizedVtxos(indexerProvider, {
326
+ scripts,
327
+ pageIndex,
328
+ pageSize: chunkE7HB3GKK_cjs.DEFAULT_PAGE_SIZE
329
+ });
330
+ for (const vtxo of vtxos) {
331
+ if (remaining.delete(vtxo.script)) used.add(vtxo.script);
332
+ }
333
+ hasMore = page ? vtxos.length === chunkE7HB3GKK_cjs.DEFAULT_PAGE_SIZE : false;
334
+ pageIndex++;
283
335
  }
284
- hasMore = page ? vtxos.length === DEFAULT_PAGE_SIZE : false;
285
- pageIndex++;
286
336
  }
287
337
  return used;
288
338
  }
289
-
290
- // src/contracts/metadata.ts
291
- var WALLET_RECEIVE_SOURCE = "wallet-receive";
339
+ async function discoverIndexerCandidates(indexerProvider, entries, buildCandidates, emit) {
340
+ const perIndex = entries.map((entry) => ({
341
+ ...entry,
342
+ candidates: buildCandidates(entry.index, entry.descriptor)
343
+ }));
344
+ const used = await detectUsedScripts(
345
+ indexerProvider,
346
+ perIndex.flatMap((e) => e.candidates.map((c) => c.scriptHex))
347
+ );
348
+ const out = /* @__PURE__ */ new Map();
349
+ for (const { index, descriptor, candidates } of perIndex) {
350
+ out.set(
351
+ index,
352
+ candidates.filter((c) => used.has(c.scriptHex)).map((c) => emit(c, index, descriptor))
353
+ );
354
+ }
355
+ return out;
356
+ }
357
+ function buildSignerTimelockCandidates(descriptor, deps, makeScript) {
358
+ const pubKey = deriveDescriptorLeafPubKey(descriptor);
359
+ const signers = [deps.serverPubKey, ...deps.deprecatedSignerPubKeys ?? []];
360
+ const seen = /* @__PURE__ */ new Set();
361
+ const candidates = [];
362
+ for (const serverPubKey of signers) {
363
+ for (const csvTimelock of deps.csvTimelocks) {
364
+ const script = makeScript({ pubKey, serverPubKey, csvTimelock });
365
+ const scriptHex = base.hex.encode(script.pkScript);
366
+ if (seen.has(scriptHex)) continue;
367
+ seen.add(scriptHex);
368
+ candidates.push({ pubKey, serverPubKey, csvTimelock, script, scriptHex });
369
+ }
370
+ }
371
+ return candidates;
372
+ }
373
+ function rotatedReceiveMetadata(index, descriptor) {
374
+ return index > 0 ? { metadata: { source: WALLET_RECEIVE_SOURCE, signingDescriptor: descriptor } } : {};
375
+ }
376
+ function discoverAtViaRange(discoverRange) {
377
+ return async (index, descriptor, deps) => (await discoverRange([{ index, descriptor }], deps)).get(index) ?? [];
378
+ }
292
379
 
293
380
  // src/contracts/handlers/default.ts
294
- function extractPubKeyBytes(value) {
295
- return base.hex.decode(extractPubKey(normalizeToDescriptor(value)));
296
- }
297
381
  var DefaultContractHandler = {
298
382
  type: "default",
299
383
  createScript(params) {
@@ -304,110 +388,57 @@ var DefaultContractHandler = {
304
388
  return {
305
389
  pubKey: base.hex.encode(params.pubKey),
306
390
  serverPubKey: base.hex.encode(params.serverPubKey),
307
- csvTimelock: chunk7TXSPRN5_cjs.timelockToSequence(params.csvTimelock).toString()
391
+ csvTimelock: chunkE7HB3GKK_cjs.timelockToSequence(params.csvTimelock).toString()
308
392
  };
309
393
  },
310
394
  deserializeParams(params) {
311
- const csvTimelock = params.csvTimelock !== void 0 && params.csvTimelock !== "" ? chunk7TXSPRN5_cjs.sequenceToTimelock(Number(params.csvTimelock)) : exports.DefaultVtxo.Script.DEFAULT_TIMELOCK;
312
395
  return {
313
396
  pubKey: extractPubKeyBytes(params.pubKey),
314
397
  serverPubKey: extractPubKeyBytes(params.serverPubKey),
315
- csvTimelock
398
+ csvTimelock: deserializeCsvTimelock(params.csvTimelock)
316
399
  };
317
400
  },
318
401
  selectPath(script, contract, context) {
319
- if (context.collaborative) {
320
- return { leaf: script.forfeit() };
321
- }
322
- const sequence = contract.params.csvTimelock ? Number(contract.params.csvTimelock) : void 0;
323
- if (!isCsvSpendable(context, sequence)) {
324
- return null;
325
- }
326
- return {
327
- leaf: script.exit(),
328
- sequence
329
- };
402
+ return selectForfeitOrExitPath(script, contract, context);
330
403
  },
331
404
  getAllSpendingPaths(script, contract, context) {
332
- const paths = [];
333
- if (context.collaborative) {
334
- paths.push({ leaf: script.forfeit() });
335
- }
336
- const exitPath = { leaf: script.exit() };
337
- if (contract.params.csvTimelock) {
338
- exitPath.sequence = Number(contract.params.csvTimelock);
339
- }
340
- paths.push(exitPath);
341
- return paths;
405
+ return forfeitExitAllPaths(script, contract, context);
342
406
  },
343
407
  getSpendablePaths(script, contract, context) {
344
- const paths = [];
345
- if (context.collaborative) {
346
- paths.push({ leaf: script.forfeit() });
347
- }
348
- const exitSequence = contract.params.csvTimelock ? Number(contract.params.csvTimelock) : void 0;
349
- if (isCsvSpendable(context, exitSequence)) {
350
- const exitPath = { leaf: script.exit() };
351
- if (exitSequence !== void 0) {
352
- exitPath.sequence = exitSequence;
353
- }
354
- paths.push(exitPath);
355
- }
356
- return paths;
408
+ return forfeitExitSpendablePaths(script, contract, context);
357
409
  },
358
- async discoverAt(index, descriptor, deps) {
359
- const pubKey = deriveDescriptorLeafPubKey(descriptor);
360
- const signers = [deps.serverPubKey, ...deps.deprecatedSignerPubKeys ?? []];
361
- const seen = /* @__PURE__ */ new Set();
362
- const candidates = [];
363
- for (const serverPubKey of signers) {
364
- for (const csvTimelock of deps.csvTimelocks) {
365
- const script = new exports.DefaultVtxo.Script({
366
- pubKey,
367
- serverPubKey,
368
- csvTimelock
369
- });
370
- const scriptHex = base.hex.encode(script.pkScript);
371
- if (seen.has(scriptHex)) continue;
372
- seen.add(scriptHex);
373
- candidates.push({ serverPubKey, csvTimelock, script, scriptHex });
374
- }
375
- }
376
- const used = await detectUsedScripts(
377
- deps.indexerProvider,
378
- candidates.map((c) => c.scriptHex)
379
- );
380
- const out = [];
381
- for (const c of candidates) {
382
- if (!used.has(c.scriptHex)) continue;
383
- out.push({
384
- type: "default",
385
- params: {
386
- pubKey: base.hex.encode(pubKey),
387
- serverPubKey: base.hex.encode(c.serverPubKey),
388
- csvTimelock: chunk7TXSPRN5_cjs.timelockToSequence(c.csvTimelock).toString()
389
- },
390
- script: c.scriptHex,
391
- address: c.script.address(deps.network.hrp, c.serverPubKey).encode(),
392
- ...index > 0 ? {
393
- metadata: {
394
- source: WALLET_RECEIVE_SOURCE,
395
- signingDescriptor: descriptor
396
- }
397
- } : {}
398
- });
399
- }
400
- return out;
401
- }
410
+ discoverAt: discoverAtViaRange(discoverDefaultRange),
411
+ discoverRange: discoverDefaultRange
402
412
  };
413
+ function discoverDefaultRange(entries, deps) {
414
+ return discoverIndexerCandidates(
415
+ deps.indexerProvider,
416
+ entries,
417
+ (_index, descriptor) => buildSignerTimelockCandidates(descriptor, deps, (opts) => new exports.DefaultVtxo.Script(opts)),
418
+ // The matched signer is threaded through the script (already built),
419
+ // the persisted params, and the encoded address so signing/forfeit
420
+ // later resolves the right key.
421
+ (c, index, descriptor) => ({
422
+ type: "default",
423
+ params: {
424
+ pubKey: base.hex.encode(c.pubKey),
425
+ serverPubKey: base.hex.encode(c.serverPubKey),
426
+ csvTimelock: chunkE7HB3GKK_cjs.timelockToSequence(c.csvTimelock).toString()
427
+ },
428
+ script: c.scriptHex,
429
+ address: c.script.address(deps.network.hrp, c.serverPubKey).encode(),
430
+ ...rotatedReceiveMetadata(index, descriptor)
431
+ })
432
+ );
433
+ }
403
434
  exports.DelegateVtxo = void 0;
404
435
  ((DelegateVtxo2) => {
405
- class Script3 extends chunk7TXSPRN5_cjs.VtxoScript {
436
+ class Script3 extends chunkE7HB3GKK_cjs.VtxoScript {
406
437
  /** Create a delegated virtual output script with forfeit, exit, and delegate paths. */
407
438
  constructor(options) {
408
439
  const defaultVtxo = new exports.DefaultVtxo.Script(options);
409
440
  const { delegatePubKey, pubKey, serverPubKey } = options;
410
- const delegateScript = chunk7TXSPRN5_cjs.MultisigTapscript.encode({
441
+ const delegateScript = chunkE7HB3GKK_cjs.MultisigTapscript.encode({
411
442
  pubkeys: [pubKey, delegatePubKey, serverPubKey]
412
443
  }).script;
413
444
  super([...defaultVtxo.scripts, delegateScript]);
@@ -446,112 +477,68 @@ var DelegateContractHandler = {
446
477
  pubKey: base.hex.encode(params.pubKey),
447
478
  serverPubKey: base.hex.encode(params.serverPubKey),
448
479
  delegatePubKey: base.hex.encode(params.delegatePubKey),
449
- csvTimelock: chunk7TXSPRN5_cjs.timelockToSequence(params.csvTimelock).toString()
480
+ csvTimelock: chunkE7HB3GKK_cjs.timelockToSequence(params.csvTimelock).toString()
450
481
  };
451
482
  },
452
483
  deserializeParams(params) {
453
- const csvTimelock = chunk7TXSPRN5_cjs.sequenceToTimelock(Number(params.csvTimelock));
454
484
  return {
455
- pubKey: base.hex.decode(params.pubKey),
456
- serverPubKey: base.hex.decode(params.serverPubKey),
457
- delegatePubKey: base.hex.decode(params.delegatePubKey),
458
- csvTimelock
485
+ pubKey: extractPubKeyBytes(params.pubKey),
486
+ serverPubKey: extractPubKeyBytes(params.serverPubKey),
487
+ delegatePubKey: extractPubKeyBytes(params.delegatePubKey),
488
+ csvTimelock: deserializeCsvTimelock(params.csvTimelock)
459
489
  };
460
490
  },
461
491
  selectPath(script, contract, context) {
462
- if (context.collaborative) {
463
- return { leaf: script.forfeit() };
464
- }
465
- const sequence = contract.params.csvTimelock ? Number(contract.params.csvTimelock) : void 0;
466
- if (!isCsvSpendable(context, sequence)) {
467
- return null;
468
- }
469
- return {
470
- leaf: script.exit(),
471
- sequence
472
- };
492
+ return selectForfeitOrExitPath(script, contract, context);
473
493
  },
474
494
  getAllSpendingPaths(script, contract, context) {
475
- const paths = [];
476
- if (context.collaborative) {
477
- paths.push({ leaf: script.forfeit() });
478
- }
479
- const exitPath = { leaf: script.exit() };
480
- if (contract.params.csvTimelock) {
481
- exitPath.sequence = Number(contract.params.csvTimelock);
482
- }
483
- paths.push(exitPath);
484
- if (context.collaborative) {
485
- paths.push({ leaf: script.delegate() });
486
- }
487
- return paths;
495
+ return [
496
+ ...forfeitExitAllPaths(script, contract, context),
497
+ // Delegate path (Alice + Delegate + Server) — collaborative only,
498
+ // and last so the shared forfeit/exit ordering is unchanged.
499
+ ...context.collaborative ? [{ leaf: script.delegate() }] : []
500
+ ];
488
501
  },
489
502
  getSpendablePaths(script, contract, context) {
490
- const paths = [];
491
- if (context.collaborative) {
492
- paths.push({ leaf: script.forfeit() });
493
- }
494
- const exitSequence = contract.params.csvTimelock ? Number(contract.params.csvTimelock) : void 0;
495
- if (isCsvSpendable(context, exitSequence)) {
496
- const exitPath = { leaf: script.exit() };
497
- if (exitSequence !== void 0) {
498
- exitPath.sequence = exitSequence;
499
- }
500
- paths.push(exitPath);
501
- }
502
- return paths;
503
+ return forfeitExitSpendablePaths(script, contract, context);
503
504
  },
504
- async discoverAt(index, descriptor, deps) {
505
- if (!deps.delegatePubKey) return [];
506
- const pubKey = deriveDescriptorLeafPubKey(descriptor);
507
- const signers = [deps.serverPubKey, ...deps.deprecatedSignerPubKeys ?? []];
508
- const seen = /* @__PURE__ */ new Set();
509
- const candidates = [];
510
- for (const serverPubKey of signers) {
511
- for (const csvTimelock of deps.csvTimelocks) {
512
- const script = new exports.DelegateVtxo.Script({
513
- pubKey,
514
- serverPubKey,
515
- delegatePubKey: deps.delegatePubKey,
516
- csvTimelock
517
- });
518
- const scriptHex = base.hex.encode(script.pkScript);
519
- if (seen.has(scriptHex)) continue;
520
- seen.add(scriptHex);
521
- candidates.push({ serverPubKey, csvTimelock, script, scriptHex });
522
- }
523
- }
524
- const used = await detectUsedScripts(
525
- deps.indexerProvider,
526
- candidates.map((c) => c.scriptHex)
527
- );
528
- const out = [];
529
- for (const c of candidates) {
530
- if (!used.has(c.scriptHex)) continue;
531
- out.push({
532
- type: "delegate",
533
- params: {
534
- pubKey: base.hex.encode(pubKey),
535
- serverPubKey: base.hex.encode(c.serverPubKey),
536
- delegatePubKey: base.hex.encode(deps.delegatePubKey),
537
- csvTimelock: chunk7TXSPRN5_cjs.timelockToSequence(c.csvTimelock).toString()
538
- },
539
- script: c.scriptHex,
540
- address: c.script.address(deps.network.hrp, c.serverPubKey).encode(),
541
- ...index > 0 ? {
542
- metadata: {
543
- source: WALLET_RECEIVE_SOURCE,
544
- signingDescriptor: descriptor
545
- }
546
- } : {}
547
- });
548
- }
549
- return out;
550
- }
505
+ discoverAt: discoverAtViaRange(discoverDelegateRange),
506
+ discoverRange: discoverDelegateRange
551
507
  };
508
+ function discoverDelegateRange(entries, deps) {
509
+ const delegatePubKey = deps.delegatePubKey;
510
+ if (!delegatePubKey) {
511
+ return Promise.resolve(new Map(entries.map((e) => [e.index, []])));
512
+ }
513
+ return discoverIndexerCandidates(
514
+ deps.indexerProvider,
515
+ entries,
516
+ // The delegate key is constant across the cross-product, so it rides
517
+ // the closure rather than being repeated on every candidate.
518
+ (_index, descriptor) => buildSignerTimelockCandidates(
519
+ descriptor,
520
+ deps,
521
+ (opts) => new exports.DelegateVtxo.Script({ ...opts, delegatePubKey })
522
+ ),
523
+ // The matched signer is threaded through script, params, and address so
524
+ // signing/forfeit later resolves the right key.
525
+ (c, index, descriptor) => ({
526
+ type: "delegate",
527
+ params: {
528
+ pubKey: base.hex.encode(c.pubKey),
529
+ serverPubKey: base.hex.encode(c.serverPubKey),
530
+ delegatePubKey: base.hex.encode(delegatePubKey),
531
+ csvTimelock: chunkE7HB3GKK_cjs.timelockToSequence(c.csvTimelock).toString()
532
+ },
533
+ script: c.scriptHex,
534
+ address: c.script.address(deps.network.hrp, c.serverPubKey).encode(),
535
+ ...rotatedReceiveMetadata(index, descriptor)
536
+ })
537
+ );
538
+ }
552
539
  exports.VHTLC = void 0;
553
540
  ((VHTLC2) => {
554
- class Script3 extends chunk7TXSPRN5_cjs.VtxoScript {
541
+ class Script3 extends chunkE7HB3GKK_cjs.VtxoScript {
555
542
  /** Create a VHTLC script from the supplied participant keys, hash, and timelocks. */
556
543
  constructor(options) {
557
544
  validateOptions(options);
@@ -566,27 +553,27 @@ exports.VHTLC = void 0;
566
553
  unilateralRefundWithoutReceiverDelay
567
554
  } = options;
568
555
  const conditionScript = preimageConditionScript(preimageHash);
569
- const claimScript = chunk7TXSPRN5_cjs.ConditionMultisigTapscript.encode({
556
+ const claimScript = chunkE7HB3GKK_cjs.ConditionMultisigTapscript.encode({
570
557
  conditionScript,
571
558
  pubkeys: [receiver, server]
572
559
  }).script;
573
- const refundScript = chunk7TXSPRN5_cjs.MultisigTapscript.encode({
560
+ const refundScript = chunkE7HB3GKK_cjs.MultisigTapscript.encode({
574
561
  pubkeys: [sender, receiver, server]
575
562
  }).script;
576
- const refundWithoutReceiverScript = chunk7TXSPRN5_cjs.CLTVMultisigTapscript.encode({
563
+ const refundWithoutReceiverScript = chunkE7HB3GKK_cjs.CLTVMultisigTapscript.encode({
577
564
  absoluteTimelock: refundLocktime,
578
565
  pubkeys: [sender, server]
579
566
  }).script;
580
- const unilateralClaimScript = chunk7TXSPRN5_cjs.ConditionCSVMultisigTapscript.encode({
567
+ const unilateralClaimScript = chunkE7HB3GKK_cjs.ConditionCSVMultisigTapscript.encode({
581
568
  conditionScript,
582
569
  timelock: unilateralClaimDelay,
583
570
  pubkeys: [receiver]
584
571
  }).script;
585
- const unilateralRefundScript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.encode({
572
+ const unilateralRefundScript = chunkE7HB3GKK_cjs.CSVMultisigTapscript.encode({
586
573
  timelock: unilateralRefundDelay,
587
574
  pubkeys: [sender, receiver]
588
575
  }).script;
589
- const unilateralRefundWithoutReceiverScript = chunk7TXSPRN5_cjs.CSVMultisigTapscript.encode({
576
+ const unilateralRefundWithoutReceiverScript = chunkE7HB3GKK_cjs.CSVMultisigTapscript.encode({
590
577
  timelock: unilateralRefundWithoutReceiverDelay,
591
578
  pubkeys: [sender]
592
579
  }).script;
@@ -714,9 +701,9 @@ var VHTLCContractHandler = {
714
701
  server: base.hex.encode(params.server),
715
702
  hash: base.hex.encode(params.preimageHash),
716
703
  refundLocktime: params.refundLocktime.toString(),
717
- claimDelay: chunk7TXSPRN5_cjs.timelockToSequence(params.unilateralClaimDelay).toString(),
718
- refundDelay: chunk7TXSPRN5_cjs.timelockToSequence(params.unilateralRefundDelay).toString(),
719
- refundNoReceiverDelay: chunk7TXSPRN5_cjs.timelockToSequence(
704
+ claimDelay: chunkE7HB3GKK_cjs.timelockToSequence(params.unilateralClaimDelay).toString(),
705
+ refundDelay: chunkE7HB3GKK_cjs.timelockToSequence(params.unilateralRefundDelay).toString(),
706
+ refundNoReceiverDelay: chunkE7HB3GKK_cjs.timelockToSequence(
720
707
  params.unilateralRefundWithoutReceiverDelay
721
708
  ).toString()
722
709
  };
@@ -728,9 +715,9 @@ var VHTLCContractHandler = {
728
715
  server: base.hex.decode(params.server),
729
716
  preimageHash: base.hex.decode(params.hash),
730
717
  refundLocktime: BigInt(params.refundLocktime),
731
- unilateralClaimDelay: chunk7TXSPRN5_cjs.sequenceToTimelock(Number(params.claimDelay)),
732
- unilateralRefundDelay: chunk7TXSPRN5_cjs.sequenceToTimelock(Number(params.refundDelay)),
733
- unilateralRefundWithoutReceiverDelay: chunk7TXSPRN5_cjs.sequenceToTimelock(
718
+ unilateralClaimDelay: chunkE7HB3GKK_cjs.sequenceToTimelock(Number(params.claimDelay)),
719
+ unilateralRefundDelay: chunkE7HB3GKK_cjs.sequenceToTimelock(Number(params.refundDelay)),
720
+ unilateralRefundWithoutReceiverDelay: chunkE7HB3GKK_cjs.sequenceToTimelock(
734
721
  Number(params.refundNoReceiverDelay)
735
722
  )
736
723
  };
@@ -923,7 +910,7 @@ var BoardingContractHandler = {
923
910
  const coins = await deps.onchainProvider.getCoins(onchainAddress);
924
911
  if (coins.length === 0) return [];
925
912
  const scriptHex = base.hex.encode(script.pkScript);
926
- const boardingSeq = chunk7TXSPRN5_cjs.timelockToSequence(deps.boardingTimelock);
913
+ const boardingSeq = chunkE7HB3GKK_cjs.timelockToSequence(deps.boardingTimelock);
927
914
  return [
928
915
  {
929
916
  type: "boarding",
@@ -943,12 +930,7 @@ var BoardingContractHandler = {
943
930
  // newest boarding address and descriptor-aware signing can
944
931
  // recover the per-index key (plan §6-II/§6-III.3). The index-0
945
932
  // baseline stays untagged, matching `default`/`delegate`.
946
- ...index > 0 ? {
947
- metadata: {
948
- source: WALLET_RECEIVE_SOURCE,
949
- signingDescriptor: descriptor
950
- }
951
- } : {}
933
+ ...rotatedReceiveMetadata(index, descriptor)
952
934
  }
953
935
  ];
954
936
  }
@@ -1909,27 +1891,27 @@ function encodeTapscriptSegment(seg, pubkeys, args) {
1909
1891
  if (seg.csv) {
1910
1892
  const timelock = { type: seg.csv.type, value: resolveTimelockValue(seg.csv.value, args) };
1911
1893
  if (seg.asm) {
1912
- return chunk7TXSPRN5_cjs.ConditionCSVMultisigTapscript.encode({
1894
+ return chunkE7HB3GKK_cjs.ConditionCSVMultisigTapscript.encode({
1913
1895
  conditionScript: resolveAsm(seg.asm, args),
1914
1896
  timelock,
1915
1897
  pubkeys
1916
1898
  });
1917
1899
  }
1918
- return chunk7TXSPRN5_cjs.CSVMultisigTapscript.encode({ timelock, pubkeys });
1900
+ return chunkE7HB3GKK_cjs.CSVMultisigTapscript.encode({ timelock, pubkeys });
1919
1901
  }
1920
1902
  if (seg.cltv !== void 0) {
1921
- return chunk7TXSPRN5_cjs.CLTVMultisigTapscript.encode({
1903
+ return chunkE7HB3GKK_cjs.CLTVMultisigTapscript.encode({
1922
1904
  absoluteTimelock: resolveTimelockValue(seg.cltv, args),
1923
1905
  pubkeys
1924
1906
  });
1925
1907
  }
1926
1908
  if (seg.asm) {
1927
- return chunk7TXSPRN5_cjs.ConditionMultisigTapscript.encode({
1909
+ return chunkE7HB3GKK_cjs.ConditionMultisigTapscript.encode({
1928
1910
  conditionScript: resolveAsm(seg.asm, args),
1929
1911
  pubkeys
1930
1912
  });
1931
1913
  }
1932
- return chunk7TXSPRN5_cjs.MultisigTapscript.encode({ pubkeys });
1914
+ return chunkE7HB3GKK_cjs.MultisigTapscript.encode({ pubkeys });
1933
1915
  }
1934
1916
  function compileFunctions(program, args, keys) {
1935
1917
  if (program.version !== SUPPORTED_PROGRAM_VERSION) {
@@ -1959,7 +1941,7 @@ function compileFunctions(program, args, keys) {
1959
1941
  return { name: names[i], def, leafScript, arkadeScript, signerKeys: pubkeys };
1960
1942
  });
1961
1943
  }
1962
- var ArkadeProgramScript = class extends chunk7TXSPRN5_cjs.VtxoScript {
1944
+ var ArkadeProgramScript = class extends chunkE7HB3GKK_cjs.VtxoScript {
1963
1945
  constructor(program, args, keys) {
1964
1946
  const partial = compileFunctions(program, args, keys);
1965
1947
  super(partial.map((p) => p.leafScript));
@@ -2172,7 +2154,7 @@ function pathsFor(script, context, opts) {
2172
2154
  continue;
2173
2155
  }
2174
2156
  if (requiresServer) continue;
2175
- const sequence = csv ? Number(chunk7TXSPRN5_cjs.timelockToSequence(csv)) : void 0;
2157
+ const sequence = csv ? Number(chunkE7HB3GKK_cjs.timelockToSequence(csv)) : void 0;
2176
2158
  if (opts.checkTimelocks && csv && !isCsvSpendable(context, sequence)) continue;
2177
2159
  if (opts.checkTimelocks && cltv !== void 0 && !isCltvSatisfied(context, cltv)) {
2178
2160
  continue;
@@ -2250,7 +2232,6 @@ exports.ArkadeContractHandler = ArkadeContractHandler;
2250
2232
  exports.ArkadeProgramScript = ArkadeProgramScript;
2251
2233
  exports.ArkadeScript = ArkadeScript;
2252
2234
  exports.BoardingContractHandler = BoardingContractHandler;
2253
- exports.DEFAULT_PAGE_SIZE = DEFAULT_PAGE_SIZE;
2254
2235
  exports.DefaultContractHandler = DefaultContractHandler;
2255
2236
  exports.DelegateContractHandler = DelegateContractHandler;
2256
2237
  exports.OPCODE_NAMES = OPCODE_NAMES;
@@ -2282,5 +2263,5 @@ exports.stringifyArtifact = stringifyArtifact;
2282
2263
  exports.toASM = toASM;
2283
2264
  exports.validateProgram = validateProgram;
2284
2265
  exports.witnessRefToBytes = witnessRefToBytes;
2285
- //# sourceMappingURL=chunk-5XMVTK5S.cjs.map
2286
- //# sourceMappingURL=chunk-5XMVTK5S.cjs.map
2266
+ //# sourceMappingURL=chunk-LJQ2VQBE.cjs.map
2267
+ //# sourceMappingURL=chunk-LJQ2VQBE.cjs.map