@arkade-os/sdk 0.5.6 → 0.5.8

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 (94) hide show
  1. package/README.md +2 -2
  2. package/dist/adapters/expo.cjs +6 -6
  3. package/dist/adapters/expo.d.cts +2 -2
  4. package/dist/adapters/expo.d.ts +2 -2
  5. package/dist/adapters/expo.js +3 -3
  6. package/dist/{asyncStorageTaskQueue-Bh2n0msM.d.cts → asyncStorageTaskQueue-B5NPtkXo.d.cts} +1 -1
  7. package/dist/{asyncStorageTaskQueue-CpkstKZ5.d.ts → asyncStorageTaskQueue-YPwiJyVA.d.ts} +1 -1
  8. package/dist/{chunk-47Z4LEIW.js → chunk-3F5AJ235.js} +4 -4
  9. package/dist/{chunk-47Z4LEIW.js.map → chunk-3F5AJ235.js.map} +1 -1
  10. package/dist/{chunk-HKEPJBTY.cjs → chunk-4IDCSOP2.cjs} +22 -16
  11. package/dist/chunk-4IDCSOP2.cjs.map +1 -0
  12. package/dist/{chunk-JFJNB7ZH.cjs → chunk-5PWL7WOT.cjs} +7 -5
  13. package/dist/chunk-5PWL7WOT.cjs.map +1 -0
  14. package/dist/{chunk-C7NY6WSA.js → chunk-E7LKKEVR.js} +10 -4
  15. package/dist/chunk-E7LKKEVR.js.map +1 -0
  16. package/dist/{chunk-Y3CDDPWI.cjs → chunk-EQ3JVVUR.cjs} +932 -558
  17. package/dist/chunk-EQ3JVVUR.cjs.map +1 -0
  18. package/dist/{chunk-DJYX73W2.js → chunk-F5O6JI2H.js} +8 -6
  19. package/dist/chunk-F5O6JI2H.js.map +1 -0
  20. package/dist/{chunk-VWW2ZBPI.js → chunk-H7GT3QC4.js} +4 -4
  21. package/dist/{chunk-VWW2ZBPI.js.map → chunk-H7GT3QC4.js.map} +1 -1
  22. package/dist/{chunk-4X67IB2V.cjs → chunk-JQSHFSME.cjs} +19 -17
  23. package/dist/chunk-JQSHFSME.cjs.map +1 -0
  24. package/dist/{chunk-NDQ4LB4X.cjs → chunk-JYQXB7OH.cjs} +19 -19
  25. package/dist/{chunk-NDQ4LB4X.cjs.map → chunk-JYQXB7OH.cjs.map} +1 -1
  26. package/dist/{chunk-YS76JSGP.cjs → chunk-KWR37J6L.cjs} +10 -10
  27. package/dist/{chunk-YS76JSGP.cjs.map → chunk-KWR37J6L.cjs.map} +1 -1
  28. package/dist/{chunk-X6ZI53DZ.cjs → chunk-L7OOPAUG.cjs} +14 -26
  29. package/dist/chunk-L7OOPAUG.cjs.map +1 -0
  30. package/dist/{chunk-YKT4NAQG.js → chunk-OLKZUJIN.js} +463 -95
  31. package/dist/chunk-OLKZUJIN.js.map +1 -0
  32. package/dist/{chunk-LZAINCGU.cjs → chunk-SOJDUKY6.cjs} +271 -225
  33. package/dist/chunk-SOJDUKY6.cjs.map +1 -0
  34. package/dist/{chunk-V3ZLL5VY.js → chunk-U34GU5RM.js} +9 -21
  35. package/dist/chunk-U34GU5RM.js.map +1 -0
  36. package/dist/{chunk-DNFTHG73.js → chunk-XXNPX4MK.js} +7 -5
  37. package/dist/chunk-XXNPX4MK.js.map +1 -0
  38. package/dist/{chunk-QTMK34TP.js → chunk-YTOABP6J.js} +268 -226
  39. package/dist/chunk-YTOABP6J.js.map +1 -0
  40. package/dist/compiler.cjs +3 -3
  41. package/dist/compiler.d.cts +1 -1
  42. package/dist/compiler.d.ts +1 -1
  43. package/dist/compiler.js +2 -2
  44. package/dist/contracts/handlers/index.cjs +10 -10
  45. package/dist/contracts/handlers/index.d.cts +3 -3
  46. package/dist/contracts/handlers/index.d.ts +3 -3
  47. package/dist/contracts/handlers/index.js +3 -3
  48. package/dist/{index-46g577Ka.d.cts → index-CKzBYoDa.d.cts} +2 -2
  49. package/dist/{index-2wKMrT0a.d.ts → index-COs69e8T.d.ts} +2 -2
  50. package/dist/{index-C66rjxz2.d.ts → index-Pk3i_MMU.d.ts} +13 -3
  51. package/dist/{index-Dqk07NwJ.d.cts → index-czozpKPT.d.cts} +13 -3
  52. package/dist/index.cjs +343 -315
  53. package/dist/index.d.cts +118 -138
  54. package/dist/index.d.ts +118 -138
  55. package/dist/index.js +6 -6
  56. package/dist/{keyringDescriptorProvider-DiBM4GmB.d.ts → keyringDescriptorProvider-CbNzWwbS.d.ts} +163 -2
  57. package/dist/{keyringDescriptorProvider-DnaLUC7v.d.cts → keyringDescriptorProvider-nC8fIjBN.d.cts} +163 -2
  58. package/dist/{program-BARSNg3X.d.ts → program-38A2Twvj.d.ts} +4 -2
  59. package/dist/{program-znrWkxE4.d.cts → program-DPzf5qsk.d.cts} +4 -2
  60. package/dist/repositories/realm/index.cjs +39 -39
  61. package/dist/repositories/realm/index.d.cts +2 -2
  62. package/dist/repositories/realm/index.d.ts +2 -2
  63. package/dist/repositories/realm/index.js +7 -7
  64. package/dist/repositories/sqlite/index.cjs +37 -37
  65. package/dist/repositories/sqlite/index.d.cts +2 -2
  66. package/dist/repositories/sqlite/index.d.ts +2 -2
  67. package/dist/repositories/sqlite/index.js +7 -7
  68. package/dist/{taskRunner-BM6IAKlS.d.ts → taskRunner-DBOqvP33.d.ts} +1 -1
  69. package/dist/{taskRunner-BmDIZiSl.d.cts → taskRunner-DXivOJHc.d.cts} +1 -1
  70. package/dist/wallet/expo/background.cjs +16 -16
  71. package/dist/wallet/expo/background.d.cts +3 -3
  72. package/dist/wallet/expo/background.d.ts +3 -3
  73. package/dist/wallet/expo/background.js +8 -8
  74. package/dist/wallet/expo/index.cjs +17 -17
  75. package/dist/wallet/expo/index.d.cts +3 -3
  76. package/dist/wallet/expo/index.d.ts +3 -3
  77. package/dist/wallet/expo/index.js +7 -7
  78. package/dist/worker/expo/index.cjs +11 -11
  79. package/dist/worker/expo/index.d.cts +4 -4
  80. package/dist/worker/expo/index.d.ts +4 -4
  81. package/dist/worker/expo/index.js +7 -7
  82. package/package.json +2 -2
  83. package/dist/chunk-4X67IB2V.cjs.map +0 -1
  84. package/dist/chunk-C7NY6WSA.js.map +0 -1
  85. package/dist/chunk-DJYX73W2.js.map +0 -1
  86. package/dist/chunk-DNFTHG73.js.map +0 -1
  87. package/dist/chunk-HKEPJBTY.cjs.map +0 -1
  88. package/dist/chunk-JFJNB7ZH.cjs.map +0 -1
  89. package/dist/chunk-LZAINCGU.cjs.map +0 -1
  90. package/dist/chunk-QTMK34TP.js.map +0 -1
  91. package/dist/chunk-V3ZLL5VY.js.map +0 -1
  92. package/dist/chunk-X6ZI53DZ.cjs.map +0 -1
  93. package/dist/chunk-Y3CDDPWI.cjs.map +0 -1
  94. package/dist/chunk-YKT4NAQG.js.map +0 -1
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var chunkX6ZI53DZ_cjs = require('./chunk-X6ZI53DZ.cjs');
4
- var chunkHKEPJBTY_cjs = require('./chunk-HKEPJBTY.cjs');
5
- var chunkNDQ4LB4X_cjs = require('./chunk-NDQ4LB4X.cjs');
6
- var chunkJFJNB7ZH_cjs = require('./chunk-JFJNB7ZH.cjs');
7
- var chunkLZAINCGU_cjs = require('./chunk-LZAINCGU.cjs');
3
+ var chunkL7OOPAUG_cjs = require('./chunk-L7OOPAUG.cjs');
4
+ var chunk4IDCSOP2_cjs = require('./chunk-4IDCSOP2.cjs');
5
+ var chunkJYQXB7OH_cjs = require('./chunk-JYQXB7OH.cjs');
6
+ var chunk5PWL7WOT_cjs = require('./chunk-5PWL7WOT.cjs');
7
+ var chunkSOJDUKY6_cjs = require('./chunk-SOJDUKY6.cjs');
8
8
  var chunkFLPWNMX3_cjs = require('./chunk-FLPWNMX3.cjs');
9
9
  var bip39 = require('@scure/bip39');
10
10
  var english_js = require('@scure/bip39/wordlists/english.js');
@@ -43,8 +43,13 @@ var musig2__namespace = /*#__PURE__*/_interopNamespace(musig2);
43
43
 
44
44
  var PrfUnavailable = class extends Error {
45
45
  name = "PrfUnavailable";
46
- /** Set when the passkey was created before this failure, so an app can still use it some other way. */
46
+ /** Set when the passkey was created before this failure; check `reason` before using it some other way. */
47
47
  credentialId;
48
+ reason;
49
+ constructor(message, options) {
50
+ super(message, options);
51
+ this.reason = options?.reason;
52
+ }
48
53
  };
49
54
  var PasskeyCancelled = class extends Error {
50
55
  name = "PasskeyCancelled";
@@ -54,6 +59,7 @@ var PasskeyCancelled = class extends Error {
54
59
  };
55
60
  var PasskeyUnconfirmed = class extends PrfUnavailable {
56
61
  name = "PasskeyUnconfirmed";
62
+ reason = "unconfirmed";
57
63
  };
58
64
  var DEFAULT_PASSKEY_LABEL = "Default";
59
65
  var UNUSABLE = "This passkey returned no usable secret.";
@@ -61,17 +67,17 @@ function bytes(x) {
61
67
  if (Object.prototype.toString.call(x) === "[object ArrayBuffer]")
62
68
  return new Uint8Array(x.slice(0));
63
69
  if (ArrayBuffer.isView(x)) return new Uint8Array(x.buffer, x.byteOffset, x.byteLength).slice();
64
- if (!Array.isArray(x)) throw new PrfUnavailable(UNUSABLE);
70
+ if (!Array.isArray(x)) throw new PrfUnavailable(UNUSABLE, { reason: "malformed" });
65
71
  for (let i = 0; i < x.length; i++) {
66
72
  const v = x[i];
67
73
  if (!(i in x) || !Number.isInteger(v) || v < 0 || v > 255)
68
- throw new PrfUnavailable(UNUSABLE);
74
+ throw new PrfUnavailable(UNUSABLE, { reason: "malformed" });
69
75
  }
70
76
  return Uint8Array.from(x);
71
77
  }
72
78
  function secret(x) {
73
79
  const b = typeof x === "object" && x !== null ? bytes(x) : null;
74
- if (!b || b.length !== 32) throw new PrfUnavailable(UNUSABLE);
80
+ if (!b || b.length !== 32) throw new PrfUnavailable(UNUSABLE, { reason: "malformed" });
75
81
  return b;
76
82
  }
77
83
  var same = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
@@ -80,7 +86,7 @@ var prf = (salt) => ({ prf: { eval: { first: bytes(salt) } } });
80
86
  var prfOf = (c) => c.getClientExtensionResults().prf;
81
87
  function browser() {
82
88
  if (typeof navigator === "undefined" || !navigator.credentials) {
83
- throw new PrfUnavailable("No WebAuthn here; pass a client.");
89
+ throw new PrfUnavailable("No WebAuthn here; pass a client.", { reason: "unsupported" });
84
90
  }
85
91
  return navigator.credentials;
86
92
  }
@@ -135,8 +141,10 @@ async function createPrfPasskey(o) {
135
141
  }
136
142
  async function confirmPrf(cred, credentialId, o, client) {
137
143
  const out = prfOf(cred);
138
- if (!out?.results?.first && (!out || out.enabled === false))
139
- throw new PrfUnavailable("This passkey cannot derive a key.");
144
+ if (!out)
145
+ throw new PrfUnavailable("This browser returned no PRF result.", { reason: "unknown" });
146
+ if (!out.results?.first && out.enabled === false)
147
+ throw new PrfUnavailable("This passkey cannot derive a key.", { reason: "unsupported" });
140
148
  const made = out.results?.first ? secret(out.results.first) : null;
141
149
  const { prf: used } = await evaluatePrf({
142
150
  rpId: o.rp.id,
@@ -145,7 +153,9 @@ async function confirmPrf(cred, credentialId, o, client) {
145
153
  client
146
154
  });
147
155
  if (made && !same(made, used)) {
148
- throw new PrfUnavailable("This passkey gave a different secret on its next use.");
156
+ throw new PrfUnavailable("This passkey gave a different secret on its next use.", {
157
+ reason: "secret-changed"
158
+ });
149
159
  }
150
160
  return used;
151
161
  }
@@ -166,7 +176,8 @@ async function evaluatePrf(o) {
166
176
  })
167
177
  );
168
178
  const first = prfOf(cred)?.results?.first;
169
- if (first === void 0) throw new PrfUnavailable("This passkey cannot derive a key.");
179
+ if (first === void 0)
180
+ throw new PrfUnavailable("This passkey cannot derive a key.", { reason: "no-secret" });
170
181
  const handle = cred.response.userHandle;
171
182
  return {
172
183
  credentialId: bytes(cred.rawId),
@@ -325,7 +336,7 @@ var TreeSignerSession = class _TreeSignerSession {
325
336
  noncesByPubkey.set(base.hex.encode(myPublicKey.subarray(1)), myNonce);
326
337
  const tx = this.graph.find(txid);
327
338
  if (!tx) throw new Error(`missing tx for txid ${txid}`);
328
- const cosigners = chunkLZAINCGU_cjs.getArkPsbtFields(tx.root, 0, chunkLZAINCGU_cjs.CosignerPublicKey).map(
339
+ const cosigners = chunkSOJDUKY6_cjs.getArkPsbtFields(tx.root, 0, chunkSOJDUKY6_cjs.CosignerPublicKey).map(
329
340
  (c) => base.hex.encode(c.key.subarray(1))
330
341
  // xonly pubkey
331
342
  );
@@ -377,7 +388,7 @@ var TreeSignerSession = class _TreeSignerSession {
377
388
  if (!aggNonce) throw new Error("missing aggregate nonce");
378
389
  const prevoutAmounts = [];
379
390
  const prevoutScripts = [];
380
- const cosigners = chunkLZAINCGU_cjs.getArkPsbtFields(g.root, 0, chunkLZAINCGU_cjs.CosignerPublicKey).map((c) => c.key);
391
+ const cosigners = chunkSOJDUKY6_cjs.getArkPsbtFields(g.root, 0, chunkSOJDUKY6_cjs.CosignerPublicKey).map((c) => c.key);
381
392
  const { finalKey } = aggregateKeys(cosigners, true, {
382
393
  taprootTweak: this.scriptRoot
383
394
  });
@@ -460,7 +471,7 @@ var SingleKey = class _SingleKey {
460
471
  async sign(tx, inputIndexes) {
461
472
  const txCpy = tx.clone();
462
473
  if (!inputIndexes) {
463
- chunkLZAINCGU_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH);
474
+ chunkSOJDUKY6_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH);
464
475
  try {
465
476
  if (!txCpy.sign(this.key, ALLOWED_SIGHASH)) {
466
477
  throw new Error("Failed to sign transaction");
@@ -560,7 +571,7 @@ var SeedIdentity = class _SeedIdentity {
560
571
  let network;
561
572
  if ("descriptor" in opts && typeof opts.descriptor === "string") {
562
573
  descriptor = opts.descriptor;
563
- network = chunkNDQ4LB4X_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
574
+ network = chunkJYQXB7OH_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
564
575
  } else {
565
576
  network = opts.isMainnet ?? true ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
566
577
  descriptor = descriptorsScure.scriptExpressions.trBIP32({
@@ -637,7 +648,7 @@ var SeedIdentity = class _SeedIdentity {
637
648
  }
638
649
  /** Returns true when `descriptor` is derived from this identity's seed. */
639
650
  ownsDescriptor(descriptor) {
640
- return chunkNDQ4LB4X_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
651
+ return chunkJYQXB7OH_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
641
652
  }
642
653
  /**
643
654
  * Signs each request with the key derived from its descriptor.
@@ -676,7 +687,7 @@ var SeedIdentity = class _SeedIdentity {
676
687
  }
677
688
  // ── internal helpers ─────────────────────────────────────────────
678
689
  derivePrivateKeyForDescriptor(descriptor) {
679
- const network = chunkNDQ4LB4X_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
690
+ const network = chunkJYQXB7OH_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
680
691
  const expansion = descriptorsScure.expand({ descriptor, network });
681
692
  if (expansion.isRanged) {
682
693
  throw new Error(
@@ -701,7 +712,7 @@ var SeedIdentity = class _SeedIdentity {
701
712
  signTxWithKey(tx, key, inputIndexes) {
702
713
  const txCpy = tx.clone();
703
714
  if (!inputIndexes) {
704
- chunkLZAINCGU_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH2);
715
+ chunkSOJDUKY6_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH2);
705
716
  try {
706
717
  if (!txCpy.sign(key, ALLOWED_SIGHASH2)) {
707
718
  throw new Error("Failed to sign transaction");
@@ -802,7 +813,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
802
813
  /** Wildcard account-descriptor template (e.g. `tr([fp/86'/0'/0']xpub/0/*)`). */
803
814
  descriptor;
804
815
  constructor(descriptor) {
805
- const network = chunkNDQ4LB4X_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
816
+ const network = chunkJYQXB7OH_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
806
817
  let expansion;
807
818
  try {
808
819
  expansion = descriptorsScure.expand({ descriptor, network, index: 0 });
@@ -837,7 +848,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
837
848
  }
838
849
  /** Returns true when `descriptor` derives from this identity's xpub. */
839
850
  ownsDescriptor(descriptor) {
840
- return chunkNDQ4LB4X_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
851
+ return chunkJYQXB7OH_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
841
852
  }
842
853
  };
843
854
  function serializeSeedOwnedSigningIdentity(identity) {
@@ -980,10 +991,10 @@ var DescriptorIdentity = class {
980
991
  this.base = base;
981
992
  }
982
993
  async xOnlyPublicKey() {
983
- return chunkNDQ4LB4X_cjs.deriveDescriptorLeafPubKey(this.descriptor);
994
+ return chunkJYQXB7OH_cjs.deriveDescriptorLeafPubKey(this.descriptor);
984
995
  }
985
996
  async compressedPublicKey() {
986
- return chunkNDQ4LB4X_cjs.deriveDescriptorLeafCompressedPubKey(this.descriptor);
997
+ return chunkJYQXB7OH_cjs.deriveDescriptorLeafCompressedPubKey(this.descriptor);
987
998
  }
988
999
  async sign(tx, inputIndexes) {
989
1000
  const [signed] = await this.signer.signWithDescriptor([
@@ -1043,8 +1054,8 @@ var StaticDescriptorProvider = class _StaticDescriptorProvider {
1043
1054
  }
1044
1055
  isOurs(descriptor) {
1045
1056
  try {
1046
- const normalized = chunkNDQ4LB4X_cjs.normalizeToDescriptor(descriptor);
1047
- const pubKey = chunkNDQ4LB4X_cjs.extractPubKey(normalized);
1057
+ const normalized = chunkJYQXB7OH_cjs.normalizeToDescriptor(descriptor);
1058
+ const pubKey = chunkJYQXB7OH_cjs.extractPubKey(normalized);
1048
1059
  return pubKey.toLowerCase() === this.pubKeyHex.toLowerCase();
1049
1060
  } catch {
1050
1061
  return false;
@@ -1386,7 +1397,7 @@ function unwrapKeyring(provider) {
1386
1397
  }
1387
1398
  function keyOf(descriptor) {
1388
1399
  try {
1389
- return chunkNDQ4LB4X_cjs.extractPubKey(chunkNDQ4LB4X_cjs.normalizeToDescriptor(descriptor)).toLowerCase();
1400
+ return chunkJYQXB7OH_cjs.extractPubKey(chunkJYQXB7OH_cjs.normalizeToDescriptor(descriptor)).toLowerCase();
1390
1401
  } catch {
1391
1402
  return void 0;
1392
1403
  }
@@ -1477,12 +1488,12 @@ async function resolveDescriptorSigner(descriptor, identity, provider) {
1477
1488
  signMessageWithDescriptor: (ownedDescriptor, message, signatureType) => identity.signDescriptorMessage(ownedDescriptor, message, signatureType)
1478
1489
  } : void 0;
1479
1490
  const owner = providerOwner ?? identityOwner;
1480
- if (owner && chunkNDQ4LB4X_cjs.parseHDDescriptor(descriptor)) {
1491
+ if (owner && chunkJYQXB7OH_cjs.parseHDDescriptor(descriptor)) {
1481
1492
  return new DescriptorIdentity({ descriptor, signer: owner, base: identity });
1482
1493
  }
1483
1494
  let key;
1484
1495
  try {
1485
- key = chunkNDQ4LB4X_cjs.deriveDescriptorLeafPubKey(descriptor);
1496
+ key = chunkJYQXB7OH_cjs.deriveDescriptorLeafPubKey(descriptor);
1486
1497
  } catch {
1487
1498
  throw new ForeignDescriptorError(descriptor);
1488
1499
  }
@@ -1535,14 +1546,14 @@ function buildSaltedPreimageMessage(xonly, salt) {
1535
1546
  }
1536
1547
  var PREIMAGE_INDEX = 0;
1537
1548
  function isPerArtifactDescriptor(descriptor) {
1538
- return chunkNDQ4LB4X_cjs.parseHDDescriptor(descriptor) !== null;
1549
+ return chunkJYQXB7OH_cjs.parseHDDescriptor(descriptor) !== null;
1539
1550
  }
1540
1551
  async function provisionDescriptor(wallet) {
1541
1552
  const allocated = isHDAllocationCapable(wallet) ? await wallet.getNextSigningDescriptor() : void 0;
1542
- return allocated ?? await chunkNDQ4LB4X_cjs.identityDescriptor(wallet.identity);
1553
+ return allocated ?? await chunkJYQXB7OH_cjs.identityDescriptor(wallet.identity);
1543
1554
  }
1544
1555
  async function provisionRefundKey(wallet) {
1545
- const descriptorPromise = chunkNDQ4LB4X_cjs.identityDescriptor(wallet.identity);
1556
+ const descriptorPromise = chunkJYQXB7OH_cjs.identityDescriptor(wallet.identity);
1546
1557
  const identityPubkeyPromise = wallet.identity.xOnlyPublicKey();
1547
1558
  void identityPubkeyPromise.catch(() => void 0);
1548
1559
  const descriptor = await descriptorPromise;
@@ -1605,7 +1616,7 @@ async function contractSigner(wallet, descriptor) {
1605
1616
  const signer = isHDWalletCapable(wallet) ? await wallet.signerForDescriptor(descriptor) : wallet.identity;
1606
1617
  let expected;
1607
1618
  try {
1608
- expected = chunkNDQ4LB4X_cjs.deriveDescriptorLeafPubKey(descriptor);
1619
+ expected = chunkJYQXB7OH_cjs.deriveDescriptorLeafPubKey(descriptor);
1609
1620
  } catch (cause) {
1610
1621
  throw new ForeignDescriptorError(descriptor, { cause });
1611
1622
  }
@@ -1687,7 +1698,7 @@ function debugLog(debug, ...args) {
1687
1698
  }
1688
1699
  function normalizeOptions(pathOrOptions) {
1689
1700
  const o = typeof pathOrOptions === "string" ? { path: pathOrOptions } : pathOrOptions;
1690
- chunkLZAINCGU_cjs.assertTimerMs("activationTimeoutMs", o.activationTimeoutMs);
1701
+ chunkSOJDUKY6_cjs.assertTimerMs("activationTimeoutMs", o.activationTimeoutMs);
1691
1702
  return {
1692
1703
  path: o.path,
1693
1704
  updateViaCache: o.updateViaCache ?? "none",
@@ -1810,14 +1821,14 @@ var RestDelegateProvider = class {
1810
1821
  */
1811
1822
  async delegate(intent, forfeitTxs, options) {
1812
1823
  const url = `${this.url}/v1/delegate`;
1813
- const response = await chunkLZAINCGU_cjs.baseFetch(url, {
1824
+ const response = await chunkSOJDUKY6_cjs.baseFetch(url, {
1814
1825
  method: "POST",
1815
1826
  headers: {
1816
1827
  "Content-Type": "application/json"
1817
1828
  },
1818
1829
  body: JSON.stringify({
1819
1830
  intent: {
1820
- message: chunkLZAINCGU_cjs.Proof.encodeMessage(intent.message),
1831
+ message: chunkSOJDUKY6_cjs.Proof.encodeMessage(intent.message),
1821
1832
  proof: intent.proof
1822
1833
  },
1823
1834
  forfeit_txs: forfeitTxs,
@@ -1836,7 +1847,7 @@ var RestDelegateProvider = class {
1836
1847
  */
1837
1848
  async getDelegateInfo() {
1838
1849
  const url = `${this.url}/v1/delegator/info`;
1839
- const response = await chunkLZAINCGU_cjs.rateGate.runHttp(url, () => chunkLZAINCGU_cjs.baseFetch(url));
1850
+ const response = await chunkSOJDUKY6_cjs.rateGate.runHttp(url, () => chunkSOJDUKY6_cjs.baseFetch(url));
1840
1851
  if (!response.ok) {
1841
1852
  const errorText2 = await response.text();
1842
1853
  throw new Error(`Failed to get delegate info: ${errorText2}`);
@@ -1973,33 +1984,37 @@ var EsploraProvider = class {
1973
1984
  */
1974
1985
  addressWatches = /* @__PURE__ */ new Map();
1975
1986
  async getCoins(address) {
1976
- const response = await chunkLZAINCGU_cjs.baseFetch(`${this.baseUrl}/address/${address}/utxo`);
1987
+ const response = await chunkSOJDUKY6_cjs.baseFetch(`${this.baseUrl}/address/${address}/utxo`);
1977
1988
  if (!response.ok) {
1978
- throw new Error(`Failed to fetch UTXOs: ${response.statusText}`);
1989
+ throw new chunkSOJDUKY6_cjs.HttpResponseError("Failed to fetch UTXOs", response);
1979
1990
  }
1980
1991
  return response.json();
1981
1992
  }
1982
1993
  async getFeeRate() {
1983
1994
  let url = `${this.baseUrl}/fee-estimates`;
1984
1995
  let key = "1";
1985
- let response = await chunkLZAINCGU_cjs.baseFetch(url);
1996
+ let response = await chunkSOJDUKY6_cjs.baseFetch(url);
1986
1997
  if (response.status === 404) {
1987
- await response.body?.cancel();
1998
+ await response.body?.cancel().catch(() => {
1999
+ });
1988
2000
  url = `${this.baseUrl}/v1/fees/recommended`;
1989
2001
  key = "fastestFee";
1990
- response = await chunkLZAINCGU_cjs.baseFetch(url);
2002
+ response = await chunkSOJDUKY6_cjs.baseFetch(url);
1991
2003
  }
1992
2004
  if (response.status === 404) {
1993
- await response.body?.cancel();
2005
+ await response.body?.cancel().catch(() => {
2006
+ });
1994
2007
  return void 0;
1995
2008
  }
1996
2009
  if (!response.ok) {
1997
- await response.body?.cancel();
1998
- throw new Error(`Failed to fetch fee rate: ${response.statusText}`);
2010
+ await response.body?.cancel().catch(() => {
2011
+ });
2012
+ throw new chunkSOJDUKY6_cjs.HttpResponseError("Failed to fetch fee rate", response);
1999
2013
  }
2000
2014
  const mediaType = response.headers.get("content-type")?.split(";", 1)[0].trim().toLowerCase();
2001
2015
  if (mediaType === "text/html") {
2002
- await response.body?.cancel();
2016
+ await response.body?.cancel().catch(() => {
2017
+ });
2003
2018
  throw new Error(`Invalid fee estimate from ${url}: received HTML`);
2004
2019
  }
2005
2020
  const fees = await response.json();
@@ -2024,49 +2039,49 @@ var EsploraProvider = class {
2024
2039
  }
2025
2040
  }
2026
2041
  async getTxOutspends(txid) {
2027
- const response = await chunkLZAINCGU_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/outspends`);
2042
+ const response = await chunkSOJDUKY6_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/outspends`);
2028
2043
  if (!response.ok) {
2029
- const error = await response.text();
2030
- throw new Error(`Failed to get transaction outspends: ${error}`);
2044
+ const error = await response.text().catch(() => void 0);
2045
+ throw new chunkSOJDUKY6_cjs.HttpResponseError("Failed to get transaction outspends", response, error);
2031
2046
  }
2032
2047
  return response.json();
2033
2048
  }
2034
2049
  async getTransactions(address) {
2035
- const response = await chunkLZAINCGU_cjs.baseFetch(`${this.baseUrl}/address/${address}/txs`);
2050
+ const response = await chunkSOJDUKY6_cjs.baseFetch(`${this.baseUrl}/address/${address}/txs`);
2036
2051
  if (!response.ok) {
2037
- const error = await response.text();
2038
- throw new Error(`Failed to get transactions: ${error}`);
2052
+ const error = await response.text().catch(() => void 0);
2053
+ throw new chunkSOJDUKY6_cjs.HttpResponseError("Failed to get transactions", response, error);
2039
2054
  }
2040
2055
  return response.json();
2041
2056
  }
2042
2057
  /** Orders of magnitude smaller than `/address/{addr}/txs`: the polling fallback's probe. */
2043
2058
  async getAddressStats(address) {
2044
- const response = await chunkLZAINCGU_cjs.baseFetch(`${this.baseUrl}/address/${address}`);
2059
+ const response = await chunkSOJDUKY6_cjs.baseFetch(`${this.baseUrl}/address/${address}`);
2045
2060
  if (!response.ok) {
2046
- throw new Error(`Failed to get address stats: ${response.statusText}`);
2061
+ throw new chunkSOJDUKY6_cjs.HttpResponseError("Failed to get address stats", response);
2047
2062
  }
2048
2063
  return response.json();
2049
2064
  }
2050
2065
  async getRawTransaction(txid) {
2051
- const response = await chunkLZAINCGU_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/hex`);
2066
+ const response = await chunkSOJDUKY6_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/hex`);
2052
2067
  if (!response.ok) {
2053
- const error = await response.text();
2054
- throw new Error(`Failed to get raw transaction ${txid}: ${error}`);
2068
+ const error = await response.text().catch(() => void 0);
2069
+ throw new chunkSOJDUKY6_cjs.HttpResponseError(`Failed to get raw transaction ${txid}`, response, error);
2055
2070
  }
2056
2071
  return base.hex.decode((await response.text()).trim());
2057
2072
  }
2058
2073
  async getTxStatus(txid) {
2059
- const txresponse = await chunkLZAINCGU_cjs.baseFetch(`${this.baseUrl}/tx/${txid}`);
2074
+ const txresponse = await chunkSOJDUKY6_cjs.baseFetch(`${this.baseUrl}/tx/${txid}`);
2060
2075
  if (!txresponse.ok) {
2061
- throw new Error(txresponse.statusText);
2076
+ throw new chunkSOJDUKY6_cjs.HttpResponseError(`Failed to get transaction ${txid}`, txresponse);
2062
2077
  }
2063
2078
  const tx = await txresponse.json();
2064
2079
  if (!tx.status.confirmed) {
2065
2080
  return { confirmed: false };
2066
2081
  }
2067
- const response = await chunkLZAINCGU_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/status`);
2082
+ const response = await chunkSOJDUKY6_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/status`);
2068
2083
  if (!response.ok) {
2069
- throw new Error(`Failed to get transaction status: ${response.statusText}`);
2084
+ throw new chunkSOJDUKY6_cjs.HttpResponseError("Failed to get transaction status", response);
2070
2085
  }
2071
2086
  const data = await response.json();
2072
2087
  if (!data.confirmed) {
@@ -2145,14 +2160,22 @@ var EsploraProvider = class {
2145
2160
  let anchorHeight;
2146
2161
  const baseline = (async () => {
2147
2162
  const [history, tip] = await Promise.allSettled([getAllTxs(), this.getChainTip()]);
2163
+ let failure;
2148
2164
  if (history.status === "fulfilled") {
2149
- for (const tx of history.value) seen.add(txKey2(tx));
2150
- baselined = true;
2151
- return;
2165
+ try {
2166
+ const keys = history.value.map(txKey2);
2167
+ for (const key of keys) seen.add(key);
2168
+ baselined = true;
2169
+ return;
2170
+ } catch (error) {
2171
+ failure = error;
2172
+ }
2173
+ } else {
2174
+ failure = history.reason;
2152
2175
  }
2153
2176
  console.warn(
2154
2177
  "Could not baseline watched addresses; the first poll pass will establish it instead:",
2155
- history.reason
2178
+ failure
2156
2179
  );
2157
2180
  if (tip.status === "fulfilled") anchorHeight = tip.value.height;
2158
2181
  })();
@@ -2338,12 +2361,12 @@ var EsploraProvider = class {
2338
2361
  return { subscribers, teardown, started };
2339
2362
  }
2340
2363
  async getChainTip() {
2341
- let tipBlocks = await chunkLZAINCGU_cjs.baseFetch(`${this.baseUrl}/blocks`);
2364
+ let tipBlocks = await chunkSOJDUKY6_cjs.baseFetch(`${this.baseUrl}/blocks`);
2342
2365
  if (tipBlocks.status === 404) {
2343
- tipBlocks = await chunkLZAINCGU_cjs.baseFetch(`${this.baseUrl}/v1/blocks`);
2366
+ tipBlocks = await chunkSOJDUKY6_cjs.baseFetch(`${this.baseUrl}/v1/blocks`);
2344
2367
  }
2345
2368
  if (!tipBlocks.ok) {
2346
- throw new Error(`Failed to get chain tip: ${tipBlocks.statusText}`);
2369
+ throw new chunkSOJDUKY6_cjs.HttpResponseError("Failed to get chain tip", tipBlocks);
2347
2370
  }
2348
2371
  const tip = await tipBlocks.json();
2349
2372
  if (!isValidBlocksTip(tip)) {
@@ -2364,17 +2387,18 @@ var EsploraProvider = class {
2364
2387
  if (!Number.isInteger(height) || height < 0) {
2365
2388
  throw new Error(`Invalid block height for median-time-past: ${height}`);
2366
2389
  }
2367
- const hashResponse = await chunkLZAINCGU_cjs.baseFetch(`${this.baseUrl}/block-height/${height}`);
2390
+ const hashResponse = await chunkSOJDUKY6_cjs.baseFetch(`${this.baseUrl}/block-height/${height}`);
2368
2391
  if (!hashResponse.ok) {
2369
- throw new Error(
2370
- `Failed to get block hash at height ${height}: ${hashResponse.statusText}`
2392
+ throw new chunkSOJDUKY6_cjs.HttpResponseError(
2393
+ `Failed to get block hash at height ${height}`,
2394
+ hashResponse
2371
2395
  );
2372
2396
  }
2373
2397
  const hash = (await hashResponse.text()).trim();
2374
2398
  if (!hash) throw new Error(`No block hash returned at height ${height}`);
2375
- const blockResponse = await chunkLZAINCGU_cjs.baseFetch(`${this.baseUrl}/block/${hash}`);
2399
+ const blockResponse = await chunkSOJDUKY6_cjs.baseFetch(`${this.baseUrl}/block/${hash}`);
2376
2400
  if (!blockResponse.ok) {
2377
- throw new Error(`Failed to get block ${hash}: ${blockResponse.statusText}`);
2401
+ throw new chunkSOJDUKY6_cjs.HttpResponseError(`Failed to get block ${hash}`, blockResponse);
2378
2402
  }
2379
2403
  const block = await blockResponse.json();
2380
2404
  if (!block || typeof block !== "object" || typeof block.mediantime !== "number" || !Number.isFinite(block.mediantime)) {
@@ -2383,7 +2407,7 @@ var EsploraProvider = class {
2383
2407
  return block.mediantime;
2384
2408
  }
2385
2409
  async broadcastPackage(parent, child) {
2386
- const response = await chunkLZAINCGU_cjs.baseFetch(`${this.baseUrl}/txs/package`, {
2410
+ const response = await chunkSOJDUKY6_cjs.baseFetch(`${this.baseUrl}/txs/package`, {
2387
2411
  method: "POST",
2388
2412
  headers: {
2389
2413
  "Content-Type": "application/json"
@@ -2391,15 +2415,15 @@ var EsploraProvider = class {
2391
2415
  body: JSON.stringify([parent, child])
2392
2416
  });
2393
2417
  if (!response.ok) {
2394
- const error = await response.text();
2395
- throw new Error(`Failed to broadcast package: ${error}`);
2418
+ const error = await response.text().catch(() => void 0);
2419
+ throw new chunkSOJDUKY6_cjs.HttpResponseError("Failed to broadcast package", response, error);
2396
2420
  }
2397
2421
  const result = await response.json();
2398
2422
  assertPackageAccepted(result);
2399
2423
  return result;
2400
2424
  }
2401
2425
  async broadcastTx(tx) {
2402
- const response = await chunkLZAINCGU_cjs.baseFetch(`${this.baseUrl}/tx`, {
2426
+ const response = await chunkSOJDUKY6_cjs.baseFetch(`${this.baseUrl}/tx`, {
2403
2427
  method: "POST",
2404
2428
  headers: {
2405
2429
  "Content-Type": "text/plain"
@@ -2407,8 +2431,8 @@ var EsploraProvider = class {
2407
2431
  body: tx
2408
2432
  });
2409
2433
  if (!response.ok) {
2410
- const error = await response.text();
2411
- throw new Error(`Failed to broadcast transaction: ${error}`);
2434
+ const error = await response.text().catch(() => void 0);
2435
+ throw new chunkSOJDUKY6_cjs.HttpResponseError("Failed to broadcast transaction", response, error);
2412
2436
  }
2413
2437
  return response.text();
2414
2438
  }
@@ -2571,7 +2595,7 @@ function findP2AOutput(tx) {
2571
2595
  var CHILD_DUST_AMOUNT = 546;
2572
2596
  function buildAnchorChild(params) {
2573
2597
  const { parent, feeRate, fundingCoins, changeAddress, tapInternalKey, network } = params;
2574
- const child = new chunkLZAINCGU_cjs.Transaction({ version: 3, allowLegacyWitnessUtxo: true });
2598
+ const child = new chunkSOJDUKY6_cjs.Transaction({ version: 3, allowLegacyWitnessUtxo: true });
2575
2599
  const anchor = findP2AOutput(parent);
2576
2600
  child.addInput(anchor);
2577
2601
  const estimator = TxWeightEstimator.create().addP2AInput();
@@ -2620,7 +2644,7 @@ function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
2620
2644
  );
2621
2645
  }
2622
2646
  function buildForfeitTxWithOutput(inputs, output, txLocktime) {
2623
- const tx = new chunkLZAINCGU_cjs.Transaction({
2647
+ const tx = new chunkSOJDUKY6_cjs.Transaction({
2624
2648
  version: 3,
2625
2649
  lockTime: txLocktime
2626
2650
  });
@@ -2647,7 +2671,7 @@ function validateConnectorsTxGraph(settlementTxB64, connectorsGraph) {
2647
2671
  connectorsGraph.validate();
2648
2672
  if (connectorsGraph.root.inputsLength !== 1) throw ErrNumberOfInputs;
2649
2673
  const rootInput = connectorsGraph.root.getInput(0);
2650
- const settlementTx = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(settlementTxB64));
2674
+ const settlementTx = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(settlementTxB64));
2651
2675
  if (settlementTx.outputsLength <= BATCH_OUTPUT_CONNECTORS_INDEX)
2652
2676
  throw ErrInvalidSettlementTxOutputs;
2653
2677
  const expectedRootTxid = settlementTx.id;
@@ -2696,7 +2720,7 @@ function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
2696
2720
  if (previousScriptKey.length !== 32) {
2697
2721
  throw new Error(`parent output ${childIndex} has invalid script`);
2698
2722
  }
2699
- const cosigners = chunkLZAINCGU_cjs.getArkPsbtFields(child.root, 0, chunkLZAINCGU_cjs.CosignerPublicKey);
2723
+ const cosigners = chunkSOJDUKY6_cjs.getArkPsbtFields(child.root, 0, chunkSOJDUKY6_cjs.CosignerPublicKey);
2700
2724
  if (cosigners.length === 0) {
2701
2725
  throw ErrMissingCosignersPublicKeys;
2702
2726
  }
@@ -2754,7 +2778,7 @@ var EmulatorPacket = class _EmulatorPacket {
2754
2778
  return new _EmulatorPacket(entries);
2755
2779
  }
2756
2780
  static fromBytes(data) {
2757
- const reader = new chunkHKEPJBTY_cjs.BufferReader(data);
2781
+ const reader = new chunk4IDCSOP2_cjs.BufferReader(data);
2758
2782
  const entryCount = reader.readCompactSize();
2759
2783
  const entries = [];
2760
2784
  for (let i = 0; i < entryCount; i++) {
@@ -2772,7 +2796,7 @@ var EmulatorPacket = class _EmulatorPacket {
2772
2796
  return _EmulatorPacket.PACKET_TYPE;
2773
2797
  }
2774
2798
  serialize() {
2775
- const writer = new chunkHKEPJBTY_cjs.BufferWriter();
2799
+ const writer = new chunk4IDCSOP2_cjs.BufferWriter();
2776
2800
  writer.writeCompactSize(this.entries.length);
2777
2801
  for (const entry of this.entries) {
2778
2802
  writer.writeUint16LE(entry.vin);
@@ -2859,7 +2883,7 @@ var Extension = class _Extension {
2859
2883
  `expected magic prefix ${base.hex.encode(ARKADE_MAGIC)}, got ${base.hex.encode(payload.slice(0, Math.min(payload.length, ARKADE_MAGIC.length)))}`
2860
2884
  );
2861
2885
  }
2862
- const reader = new chunkHKEPJBTY_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
2886
+ const reader = new chunk4IDCSOP2_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
2863
2887
  const packets = [];
2864
2888
  while (reader.remaining() > 0) {
2865
2889
  const packetType = reader.readByte();
@@ -2932,7 +2956,7 @@ var Extension = class _Extension {
2932
2956
  * getAssetPacket returns the embedded Packet, or null if not present.
2933
2957
  */
2934
2958
  getAssetPacket() {
2935
- return this.packets.find((p) => p instanceof chunkHKEPJBTY_cjs.Packet) ?? null;
2959
+ return this.packets.find((p) => p instanceof chunk4IDCSOP2_cjs.Packet) ?? null;
2936
2960
  }
2937
2961
  /**
2938
2962
  * getEmulatorPacket returns the embedded EmulatorPacket, or null if not present.
@@ -2956,8 +2980,8 @@ var Extension = class _Extension {
2956
2980
  };
2957
2981
  function parsePacket(packetType, data) {
2958
2982
  switch (packetType) {
2959
- case chunkHKEPJBTY_cjs.Packet.PACKET_TYPE:
2960
- return chunkHKEPJBTY_cjs.Packet.fromBytes(data);
2983
+ case chunk4IDCSOP2_cjs.Packet.PACKET_TYPE:
2984
+ return chunk4IDCSOP2_cjs.Packet.fromBytes(data);
2961
2985
  case EmulatorPacket.PACKET_TYPE:
2962
2986
  return EmulatorPacket.fromBytes(data);
2963
2987
  default:
@@ -3004,22 +3028,22 @@ function buildOpReturnScript(data) {
3004
3028
  }
3005
3029
  return script;
3006
3030
  }
3007
- var ErrOffchainOutputNotFound = (address) => new chunkLZAINCGU_cjs.ServerResponseMismatchError(`offchain send output not found: ${address}`);
3008
- var ErrInvalidAssetOutputAmount = (got, want, assetId) => new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3031
+ var ErrOffchainOutputNotFound = (address) => new chunkSOJDUKY6_cjs.ServerResponseMismatchError(`offchain send output not found: ${address}`);
3032
+ var ErrInvalidAssetOutputAmount = (got, want, assetId) => new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3009
3033
  `invalid asset output amount for ${assetId}: got ${got}, want ${want}`
3010
3034
  );
3011
- var ErrAssetGroupNotFound = (assetId) => new chunkLZAINCGU_cjs.ServerResponseMismatchError(`asset group not found in batch leaf: ${assetId}`);
3012
- var ErrAssetOutputNotFound = (assetId, outputIndex) => new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3035
+ var ErrAssetGroupNotFound = (assetId) => new chunkSOJDUKY6_cjs.ServerResponseMismatchError(`asset group not found in batch leaf: ${assetId}`);
3036
+ var ErrAssetOutputNotFound = (assetId, outputIndex) => new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3013
3037
  `asset output not found in asset group ${assetId} at index ${outputIndex}`
3014
3038
  );
3015
- var ErrOnchainOutputNotFound = (address) => new chunkLZAINCGU_cjs.ServerResponseMismatchError(`onchain output not found: ${address}`);
3016
- var ErrUnvalidatedOffchainOutput = (address) => new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3039
+ var ErrOnchainOutputNotFound = (address) => new chunkSOJDUKY6_cjs.ServerResponseMismatchError(`onchain output not found: ${address}`);
3040
+ var ErrUnvalidatedOffchainOutput = (address) => new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3017
3041
  `offchain output ${address} cannot be validated: virtual output tree signing did not run`
3018
3042
  );
3019
- var ErrIntentOutputNotFound = (index, kind) => new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3043
+ var ErrIntentOutputNotFound = (index, kind) => new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3020
3044
  `${kind} output ${index} of the proof is not present in what the server built`
3021
3045
  );
3022
- var ErrUnvalidatedIntentOutput = (index) => new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3046
+ var ErrUnvalidatedIntentOutput = (index) => new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3023
3047
  `offchain output ${index} of the proof cannot be validated: virtual output tree signing did not run`
3024
3048
  );
3025
3049
  var ErrInvalidOnchainOutputAmount = (address) => new Error(`invalid onchain output amount: ${address}`);
@@ -3028,7 +3052,7 @@ var ErrInvalidOffchainOutputAmount = (address) => new Error(`invalid offchain ou
3028
3052
  function assertFinalCommitmentMatchesValidated(finalCommitmentTx, validatedCommitmentTxid, context) {
3029
3053
  if (!validatedCommitmentTxid) return;
3030
3054
  if (finalCommitmentTx.id === validatedCommitmentTxid) return;
3031
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3055
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3032
3056
  `${context}: finalization commitment tx ${finalCommitmentTx.id} differs from the validated commitment tx ${validatedCommitmentTxid}`
3033
3057
  );
3034
3058
  }
@@ -3059,7 +3083,7 @@ function validateBatchRecipientsWithoutTree(commitmentTx, recipients, network) {
3059
3083
  }
3060
3084
  }
3061
3085
  function declaredIntentOutputs(signedProof, onchainOutputIndexes) {
3062
- const proof = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(signedProof));
3086
+ const proof = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(signedProof));
3063
3087
  const onchain = new Set(onchainOutputIndexes);
3064
3088
  const declared = [];
3065
3089
  for (let i = 0; i < proof.outputsLength; i++) {
@@ -3351,7 +3375,7 @@ function assetMintResolver() {
3351
3375
  if (!tx.assets?.length || !tx.key.arkTxid) return void 0;
3352
3376
  const minted = tx.assets.filter((a) => {
3353
3377
  try {
3354
- return base.hex.encode(chunkHKEPJBTY_cjs.AssetId.fromString(a.assetId).txid) === tx.key.arkTxid;
3378
+ return base.hex.encode(chunk4IDCSOP2_cjs.AssetId.fromString(a.assetId).txid) === tx.key.arkTxid;
3355
3379
  } catch {
3356
3380
  return false;
3357
3381
  }
@@ -3428,7 +3452,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
3428
3452
  const existing = inputsByAssetId.get(asset.assetId);
3429
3453
  inputsByAssetId.set(asset.assetId, [
3430
3454
  ...existing ?? [],
3431
- chunkHKEPJBTY_cjs.AssetInput.create(inputIndex, asset.amount)
3455
+ chunk4IDCSOP2_cjs.AssetInput.create(inputIndex, asset.amount)
3432
3456
  ]);
3433
3457
  }
3434
3458
  }
@@ -3440,7 +3464,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
3440
3464
  const existing = outputsByAssetId.get(asset.assetId);
3441
3465
  outputsByAssetId.set(asset.assetId, [
3442
3466
  ...existing ?? [],
3443
- chunkHKEPJBTY_cjs.AssetOutput.create(outputIndex, asset.amount)
3467
+ chunk4IDCSOP2_cjs.AssetOutput.create(outputIndex, asset.amount)
3444
3468
  ]);
3445
3469
  }
3446
3470
  }
@@ -3451,7 +3475,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
3451
3475
  const existing = outputsByAssetId.get(asset.assetId);
3452
3476
  outputsByAssetId.set(asset.assetId, [
3453
3477
  ...existing ?? [],
3454
- chunkHKEPJBTY_cjs.AssetOutput.create(outputIndex, asset.amount)
3478
+ chunk4IDCSOP2_cjs.AssetOutput.create(outputIndex, asset.amount)
3455
3479
  ]);
3456
3480
  }
3457
3481
  }
@@ -3460,11 +3484,11 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
3460
3484
  for (const assetIdStr of allAssetIds) {
3461
3485
  const inputs = inputsByAssetId.get(assetIdStr);
3462
3486
  const outputs = outputsByAssetId.get(assetIdStr);
3463
- const assetId = chunkHKEPJBTY_cjs.AssetId.fromString(assetIdStr);
3464
- const group = chunkHKEPJBTY_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
3487
+ const assetId = chunk4IDCSOP2_cjs.AssetId.fromString(assetIdStr);
3488
+ const group = chunk4IDCSOP2_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
3465
3489
  groups.push(group);
3466
3490
  }
3467
- return chunkHKEPJBTY_cjs.Packet.create(groups);
3491
+ return chunk4IDCSOP2_cjs.Packet.create(groups);
3468
3492
  }
3469
3493
  function selectCoinsWithAsset(coins, assetId, requiredAmount) {
3470
3494
  const coinsWithAsset = coins.filter((coin) => coin.assets?.some((a) => a.assetId === assetId));
@@ -3548,7 +3572,7 @@ function meetsInputExpiryFloor(coin, floor) {
3548
3572
  }
3549
3573
  function toXOnlySignerHex(pubkeyHex) {
3550
3574
  const bytes2 = base.hex.decode(pubkeyHex);
3551
- if (bytes2.length === 32 || bytes2.length === 33) return base.hex.encode(chunkJFJNB7ZH_cjs.toXOnly(bytes2, "signer key"));
3575
+ if (bytes2.length === 32 || bytes2.length === 33) return base.hex.encode(chunk5PWL7WOT_cjs.toXOnly(bytes2, "signer key"));
3552
3576
  throw new Error(`invalid signer pubkey length: expected 32 or 33 bytes, got ${bytes2.length}`);
3553
3577
  }
3554
3578
  function signerSetFromInfo(info) {
@@ -3595,14 +3619,14 @@ var toTimelock = (value) => ({
3595
3619
  var toSeconds = (t) => t.type === "seconds" ? t.value : t.value * NOMINAL_BLOCK_SECONDS;
3596
3620
  function assertTimelockInPolicy(timelock, policy, label, overrideOption) {
3597
3621
  if (policy.requireSeconds && timelock.type === "blocks") {
3598
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3622
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3599
3623
  `${label} rejected: block-typed timelocks are not accepted (got ${timelock.value})`
3600
3624
  );
3601
3625
  }
3602
3626
  const seconds = toSeconds(timelock);
3603
3627
  if (seconds < policy.minSeconds) {
3604
3628
  const remedy = overrideOption ? `; pass ${overrideOption}: ${seconds}n to Wallet.create to lower it` : "";
3605
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3629
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3606
3630
  `${label} rejected: ${timelock.value} ${timelock.type} is below the ${policy.minSeconds}s floor${remedy}`
3607
3631
  );
3608
3632
  }
@@ -3623,7 +3647,7 @@ function resolveBatchExpiryPolicy(network, overrides) {
3623
3647
  }
3624
3648
  function assertValidBatchExpiry(batchExpiry, policy) {
3625
3649
  if (policy.advertisedVtxoTreeExpiry !== void 0 && batchExpiry !== policy.advertisedVtxoTreeExpiry) {
3626
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3650
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3627
3651
  `batch expiry rejected: ${batchExpiry} does not match the advertised vtxoTreeExpiry ${policy.advertisedVtxoTreeExpiry}`
3628
3652
  );
3629
3653
  }
@@ -3634,19 +3658,19 @@ function assertValidServerUnrollScript(checkpointTapscript, network, advertisedF
3634
3658
  try {
3635
3659
  script = chunkFLPWNMX3_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
3636
3660
  } catch (e) {
3637
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3661
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3638
3662
  `checkpoint exit delay rejected: invalid checkpointTapscript from server (${e instanceof Error ? e.message : String(e)})`
3639
3663
  );
3640
3664
  }
3641
3665
  if (advertisedForfeitPubkey !== void 0) {
3642
3666
  const { pubkeys } = script.params;
3643
3667
  if (pubkeys.length !== 1) {
3644
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3668
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3645
3669
  `checkpoint exit delay rejected: checkpointTapscript must commit to exactly one pubkey, got ${pubkeys.length} [${pubkeys.map(base.hex.encode).join(", ")}]`
3646
3670
  );
3647
3671
  }
3648
3672
  if (!utils_js.equalBytes(pubkeys[0], advertisedForfeitPubkey)) {
3649
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3673
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3650
3674
  `checkpoint exit delay rejected: checkpointTapscript pubkey ${base.hex.encode(pubkeys[0])} does not match the advertised forfeitPubkey ${base.hex.encode(advertisedForfeitPubkey)}`
3651
3675
  );
3652
3676
  }
@@ -3701,7 +3725,7 @@ function buildVirtualTx(inputs, outputs) {
3701
3725
  }
3702
3726
  }
3703
3727
  }
3704
- const tx = new chunkLZAINCGU_cjs.Transaction({
3728
+ const tx = new chunkSOJDUKY6_cjs.Transaction({
3705
3729
  version: 3,
3706
3730
  lockTime: Number(lockTime)
3707
3731
  });
@@ -3716,7 +3740,7 @@ function buildVirtualTx(inputs, outputs) {
3716
3740
  },
3717
3741
  tapLeafScript: [input.tapLeafScript]
3718
3742
  });
3719
- chunkLZAINCGU_cjs.setArkPsbtField(tx, i, chunkLZAINCGU_cjs.VtxoTaprootTree, input.tapTree);
3743
+ chunkSOJDUKY6_cjs.setArkPsbtField(tx, i, chunkSOJDUKY6_cjs.VtxoTaprootTree, input.tapTree);
3720
3744
  }
3721
3745
  for (const output of outputs) {
3722
3746
  tx.addOutput(output);
@@ -3862,7 +3886,7 @@ function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubke
3862
3886
  const sighashType = signature.length === 65 ? signature[64] : btcSigner.SigHash.DEFAULT;
3863
3887
  const sig = signature.subarray(0, 64);
3864
3888
  if (!allowedSighashTypes.includes(sighashType)) {
3865
- const sighashName = chunkLZAINCGU_cjs.formatSighash(sighashType);
3889
+ const sighashName = chunkSOJDUKY6_cjs.formatSighash(sighashType);
3866
3890
  throw new Error(
3867
3891
  `Unallowed sighash type ${sighashName} for input ${inputIndex}, pubkey ${pubKeyHex}.`
3868
3892
  );
@@ -3944,16 +3968,16 @@ function isValidArkAddress(address) {
3944
3968
  }
3945
3969
  function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, context) {
3946
3970
  if (serverCheckpointTxs.length !== expectedCheckpoints.length) {
3947
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3971
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3948
3972
  `${context} returned ${serverCheckpointTxs.length} checkpoints, expected ${expectedCheckpoints.length}`
3949
3973
  );
3950
3974
  }
3951
3975
  const byTxid = new Map(expectedCheckpoints.map((c) => [c.id, c]));
3952
3976
  return serverCheckpointTxs.map((encoded, index) => {
3953
- const server = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
3977
+ const server = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
3954
3978
  const local = byTxid.get(server.id);
3955
3979
  if (!local) {
3956
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3980
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3957
3981
  `${context} checkpoint ${index} txid ${server.id} does not match any submitted checkpoint`
3958
3982
  );
3959
3983
  }
@@ -3963,14 +3987,14 @@ function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, contex
3963
3987
  }
3964
3988
  function assertSubmittedArkTxid(response, signedArkTx, context) {
3965
3989
  if (response.arkTxid !== signedArkTx.id) {
3966
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3990
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3967
3991
  `${context} returned ark txid ${response.arkTxid}, expected ${signedArkTx.id}`
3968
3992
  );
3969
3993
  }
3970
3994
  if (response.finalArkTx === void 0) return;
3971
- const finalTxid = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx)).id;
3995
+ const finalTxid = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx)).id;
3972
3996
  if (finalTxid !== signedArkTx.id) {
3973
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
3997
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3974
3998
  `${context} returned final ark tx ${finalTxid}, expected ${signedArkTx.id}`
3975
3999
  );
3976
4000
  }
@@ -3986,16 +4010,16 @@ function assertServerSignedLeaf(serverTx, localTx, inputIndex, serverPubkeys, co
3986
4010
  let leafPubkeys;
3987
4011
  try {
3988
4012
  leafPubkeys = chunkFLPWNMX3_cjs.decodeTapscript(script).params.pubkeys.map(
3989
- (key) => base.hex.encode(chunkJFJNB7ZH_cjs.toXOnly(key, "leaf key"))
4013
+ (key) => base.hex.encode(chunk5PWL7WOT_cjs.toXOnly(key, "leaf key"))
3990
4014
  );
3991
4015
  } catch (error) {
3992
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
4016
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3993
4017
  `${context}: input ${inputIndex} spend leaf cannot be decoded (${error instanceof Error ? error.message : String(error)})`
3994
4018
  );
3995
4019
  }
3996
4020
  const signer = leafPubkeys.find((key) => serverPubkeys.has(key));
3997
4021
  if (!signer) {
3998
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
4022
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
3999
4023
  `${context}: input ${inputIndex} spend leaf names no signer key the server advertises`
4000
4024
  );
4001
4025
  }
@@ -4009,7 +4033,7 @@ function assertServerSignedLeaf(serverTx, localTx, inputIndex, serverPubkeys, co
4009
4033
  payment_js.tapLeafHash(script)
4010
4034
  );
4011
4035
  } catch (error) {
4012
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
4036
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
4013
4037
  `${context}: input ${inputIndex} is not signed by the server on the leaf being spent (${error instanceof Error ? error.message : String(error)})`
4014
4038
  );
4015
4039
  }
@@ -4018,20 +4042,20 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
4018
4042
  const byOutpoint = new Map(inputs.map((input) => [`${input.txid}:${input.vout}`, input]));
4019
4043
  for (const [index, checkpoint] of checkpoints.entries()) {
4020
4044
  if (checkpoint.inputsLength !== 1) {
4021
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
4045
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
4022
4046
  `${context}: checkpoint ${index} spends ${checkpoint.inputsLength} inputs, expected 1`
4023
4047
  );
4024
4048
  }
4025
4049
  const spent = checkpoint.getInput(0);
4026
4050
  if (!spent.txid || spent.index === void 0) {
4027
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
4051
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
4028
4052
  `${context}: checkpoint ${index} has no input outpoint`
4029
4053
  );
4030
4054
  }
4031
4055
  const outpoint = `${base.hex.encode(spent.txid)}:${spent.index}`;
4032
4056
  const input = byOutpoint.get(outpoint);
4033
4057
  if (!input) {
4034
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
4058
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
4035
4059
  `${context}: checkpoint ${index} spends ${outpoint}, which is not one of the requested virtual outputs`
4036
4060
  );
4037
4061
  }
@@ -4039,7 +4063,7 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
4039
4063
  (unroll) => buildCheckpointTx(input, unroll).tx.id === checkpoint.id
4040
4064
  );
4041
4065
  if (!rebuilt) {
4042
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
4066
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
4043
4067
  `${context}: checkpoint ${index} txid ${checkpoint.id} differs from the checkpoint built locally for ${outpoint}`
4044
4068
  );
4045
4069
  }
@@ -4068,9 +4092,9 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
4068
4092
  if (!oneShot) {
4069
4093
  matched.forEach(({ server }, index) => {
4070
4094
  try {
4071
- chunkLZAINCGU_cjs.assertAllowedSighashTypes(server);
4095
+ chunkSOJDUKY6_cjs.assertAllowedSighashTypes(server);
4072
4096
  } catch (error) {
4073
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
4097
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
4074
4098
  `submitTx checkpoint ${index}: ${error instanceof Error ? error.message : String(error)}`
4075
4099
  );
4076
4100
  }
@@ -4079,14 +4103,14 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
4079
4103
  const verify = options?.verifyServerSignatures;
4080
4104
  if (verify) {
4081
4105
  if (response.finalArkTx === void 0) {
4082
- throw new chunkLZAINCGU_cjs.ServerResponseMismatchError(
4106
+ throw new chunkSOJDUKY6_cjs.ServerResponseMismatchError(
4083
4107
  "submitTx: server returned no final ark tx to verify its signatures against"
4084
4108
  );
4085
4109
  }
4086
- const finalArkTx = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx));
4110
+ const finalArkTx = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx));
4087
4111
  const serverPubkeys = new Set(
4088
4112
  [verify.serverPubkey, ...verify.deprecatedServerPubkeys ?? []].map(
4089
- (key) => base.hex.encode(chunkJFJNB7ZH_cjs.toXOnly(key, "server key"))
4113
+ (key) => base.hex.encode(chunk5PWL7WOT_cjs.toXOnly(key, "server key"))
4090
4114
  )
4091
4115
  );
4092
4116
  for (let i = 0; i < offchainTx.arkTx.inputsLength; i++) {
@@ -4134,19 +4158,19 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
4134
4158
  return result;
4135
4159
  }
4136
4160
  function carryConditionWitness(ours, server) {
4137
- if (chunkLZAINCGU_cjs.getArkPsbtFields(server, 0, chunkLZAINCGU_cjs.ConditionWitness).length > 0) return;
4138
- const [witness] = chunkLZAINCGU_cjs.getArkPsbtFields(ours, 0, chunkLZAINCGU_cjs.ConditionWitness);
4139
- if (witness) chunkLZAINCGU_cjs.setArkPsbtField(server, 0, chunkLZAINCGU_cjs.ConditionWitness, witness);
4161
+ if (chunkSOJDUKY6_cjs.getArkPsbtFields(server, 0, chunkSOJDUKY6_cjs.ConditionWitness).length > 0) return;
4162
+ const [witness] = chunkSOJDUKY6_cjs.getArkPsbtFields(ours, 0, chunkSOJDUKY6_cjs.ConditionWitness);
4163
+ if (witness) chunkSOJDUKY6_cjs.setArkPsbtField(server, 0, chunkSOJDUKY6_cjs.ConditionWitness, witness);
4140
4164
  }
4141
4165
  function withArkInputWitness(checkpoint, signedArkTx) {
4142
- if (chunkLZAINCGU_cjs.getArkPsbtFields(checkpoint, 0, chunkLZAINCGU_cjs.ConditionWitness).length > 0) return checkpoint;
4166
+ if (chunkSOJDUKY6_cjs.getArkPsbtFields(checkpoint, 0, chunkSOJDUKY6_cjs.ConditionWitness).length > 0) return checkpoint;
4143
4167
  for (let i = 0; i < signedArkTx.inputsLength; i++) {
4144
4168
  const { txid } = signedArkTx.getInput(i);
4145
4169
  if (!txid || base.hex.encode(txid) !== checkpoint.id) continue;
4146
- const [witness] = chunkLZAINCGU_cjs.getArkPsbtFields(signedArkTx, i, chunkLZAINCGU_cjs.ConditionWitness);
4170
+ const [witness] = chunkSOJDUKY6_cjs.getArkPsbtFields(signedArkTx, i, chunkSOJDUKY6_cjs.ConditionWitness);
4147
4171
  if (!witness) return checkpoint;
4148
4172
  const carried = checkpoint.clone();
4149
- chunkLZAINCGU_cjs.setArkPsbtField(carried, 0, chunkLZAINCGU_cjs.ConditionWitness, witness);
4173
+ chunkSOJDUKY6_cjs.setArkPsbtField(carried, 0, chunkSOJDUKY6_cjs.ConditionWitness, witness);
4150
4174
  return carried;
4151
4175
  }
4152
4176
  return checkpoint;
@@ -4187,7 +4211,7 @@ async function submitViaEmulator(emulator, offchainTx, signer, opts) {
4187
4211
  base.base64.encode(arkTx.toPSBT()),
4188
4212
  checkpoints.map((c) => base.base64.encode(c.toPSBT()))
4189
4213
  );
4190
- const txid = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(res.signedArkTx)).id;
4214
+ const txid = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(res.signedArkTx)).id;
4191
4215
  assertSubmittedArkTxid({ arkTxid: txid }, arkTx, "emulator submitTx");
4192
4216
  return { txid, signedArkTx: res.signedArkTx, signedCheckpointTxs: res.signedCheckpointTxs };
4193
4217
  }
@@ -4195,12 +4219,12 @@ function claimWithPreimageIdentity(identity, preimage) {
4195
4219
  return {
4196
4220
  ...identity,
4197
4221
  sign: async (tx, inputIndexes) => {
4198
- const signed = chunkLZAINCGU_cjs.Transaction.fromPSBT(
4222
+ const signed = chunkSOJDUKY6_cjs.Transaction.fromPSBT(
4199
4223
  (await identity.sign(tx.clone(), inputIndexes)).toPSBT()
4200
4224
  );
4201
4225
  const indexes = inputIndexes ?? Array.from({ length: signed.inputsLength }, (_, i) => i);
4202
4226
  for (const index of indexes) {
4203
- chunkLZAINCGU_cjs.setArkPsbtField(signed, index, chunkLZAINCGU_cjs.ConditionWitness, [preimage]);
4227
+ chunkSOJDUKY6_cjs.setArkPsbtField(signed, index, chunkSOJDUKY6_cjs.ConditionWitness, [preimage]);
4204
4228
  }
4205
4229
  return signed;
4206
4230
  }
@@ -4209,7 +4233,7 @@ function claimWithPreimageIdentity(identity, preimage) {
4209
4233
 
4210
4234
  // src/contracts/scope.ts
4211
4235
  function scopeOf(contract) {
4212
- return contract.scope ?? chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type)?.defaultScope ?? "offchain";
4236
+ return contract.scope ?? chunkJYQXB7OH_cjs.contractHandlers.get(contract.type)?.defaultScope ?? "offchain";
4213
4237
  }
4214
4238
  function isOnchainScoped(contract) {
4215
4239
  return scopeOf(contract) !== "offchain";
@@ -4286,9 +4310,9 @@ async function collectScriptVtxos(repository, script, options) {
4286
4310
  return [...byOutpoint.values()].map((row) => row.vtxo);
4287
4311
  }
4288
4312
  function unspentScriptVtxos(rows, copies) {
4289
- const spent = copies.filter((copy) => chunkLZAINCGU_cjs.isVtxoSpent(copy.vtxo));
4313
+ const spent = copies.filter((copy) => chunkSOJDUKY6_cjs.isVtxoSpent(copy.vtxo));
4290
4314
  return rows.filter(
4291
- (row) => !chunkLZAINCGU_cjs.isVtxoSpent(row.vtxo) && !spent.some(
4315
+ (row) => !chunkSOJDUKY6_cjs.isVtxoSpent(row.vtxo) && !spent.some(
4292
4316
  (copy) => copy.address !== row.address && copy.vtxo.txid === row.vtxo.txid && copy.vtxo.vout === row.vtxo.vout && shouldReplaceScriptVtxo(row, copy)
4293
4317
  )
4294
4318
  );
@@ -4345,7 +4369,7 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
4345
4369
  };
4346
4370
  }
4347
4371
  function deriveContractTapscripts(contract) {
4348
- const handler = chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type);
4372
+ const handler = chunkJYQXB7OH_cjs.contractHandlers.get(contract.type);
4349
4373
  if (!handler) {
4350
4374
  throw new Error(`No handler for contract type '${contract.type}'`);
4351
4375
  }
@@ -4548,8 +4572,8 @@ function checkSaveVtxosForScript(backend, key, vtxos) {
4548
4572
  }
4549
4573
  async function getVtxosForContract(repo, contract, options) {
4550
4574
  const vtxos = repo.getVtxosForScriptPage ? await collectScriptVtxos(repo, contract.script, options) : filterVtxosForScript(await collectVtxos(repo, contract.address), contract.script);
4551
- const normalized = vtxos.map(chunkLZAINCGU_cjs.normalizeVtxo);
4552
- return options?.unspentOnly ? normalized.filter((vtxo) => !chunkLZAINCGU_cjs.isVtxoSpent(vtxo)) : normalized;
4575
+ const normalized = vtxos.map(chunkSOJDUKY6_cjs.normalizeVtxo);
4576
+ return options?.unspentOnly ? normalized.filter((vtxo) => !chunkSOJDUKY6_cjs.isVtxoSpent(vtxo)) : normalized;
4553
4577
  }
4554
4578
  async function hasVtxosForContract(repo, contract) {
4555
4579
  if (repo.getVtxosForScriptPage) {
@@ -4631,7 +4655,7 @@ async function saveVtxosForContract(repo, contract, vtxos) {
4631
4655
  // src/contracts/onchainCoins.ts
4632
4656
  var MIGRATED_KEY = "legacyUtxosMigrated";
4633
4657
  function createScript(contract) {
4634
- const handler = chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type);
4658
+ const handler = chunkJYQXB7OH_cjs.contractHandlers.get(contract.type);
4635
4659
  if (!handler) throw new Error(`No handler for contract type '${contract.type}'`);
4636
4660
  return handler.createScript(contract.params);
4637
4661
  }
@@ -4690,7 +4714,7 @@ async function migrateLegacyUtxos(deps) {
4690
4714
  let migrated = 0;
4691
4715
  for (const contract of await collectContracts(contractRepository)) {
4692
4716
  if (!isOnchainScoped(contract)) continue;
4693
- if (!chunkNDQ4LB4X_cjs.contractHandlers.has(contract.type)) {
4717
+ if (!chunkJYQXB7OH_cjs.contractHandlers.has(contract.type)) {
4694
4718
  console.warn("Skipping legacy utxos of a contract with no handler", contract.type);
4695
4719
  continue;
4696
4720
  }
@@ -4716,7 +4740,7 @@ var DEFAULT_COSIGN_MARGIN_BLOCKS = 6;
4716
4740
  var MAX_COSIGN_INPUTS = 64;
4717
4741
  var ONCHAIN_RENEW_WINDOW_BLOCKS = 144;
4718
4742
  function exitCsvOf(contract) {
4719
- const sequence = chunkNDQ4LB4X_cjs.exitSequence(contract);
4743
+ const sequence = chunkJYQXB7OH_cjs.exitSequence(contract);
4720
4744
  return sequence === void 0 ? void 0 : chunkFLPWNMX3_cjs.sequenceToTimelock(sequence);
4721
4745
  }
4722
4746
  var ONCHAIN_COSIGN_PREFLIGHT_PREFIX = "Onchain cosign preflight failed: ";
@@ -4734,7 +4758,7 @@ function prepareOwnedInput(tx, { index, coin, path, tapTree }) {
4734
4758
  tx.updateInput(index, { tapLeafScript: void 0, tapScriptSig: void 0 }, true);
4735
4759
  }
4736
4760
  const kept = unknown?.filter(
4737
- (u) => chunkLZAINCGU_cjs.VtxoTaprootTree.decode(u) === null && chunkLZAINCGU_cjs.ConditionWitness.decode(u) === null
4761
+ (u) => chunkSOJDUKY6_cjs.VtxoTaprootTree.decode(u) === null && chunkSOJDUKY6_cjs.ConditionWitness.decode(u) === null
4738
4762
  );
4739
4763
  if (kept && kept.length !== unknown.length) {
4740
4764
  tx.updateInput(index, { unknown: void 0 }, true);
@@ -4745,9 +4769,9 @@ function prepareOwnedInput(tx, { index, coin, path, tapTree }) {
4745
4769
  tapLeafScript: [path.leaf],
4746
4770
  sighashType: btcSigner.SigHash.DEFAULT
4747
4771
  });
4748
- chunkLZAINCGU_cjs.setArkPsbtField(tx, index, chunkLZAINCGU_cjs.VtxoTaprootTree, tapTree);
4772
+ chunkSOJDUKY6_cjs.setArkPsbtField(tx, index, chunkSOJDUKY6_cjs.VtxoTaprootTree, tapTree);
4749
4773
  if (path.extraWitness?.length) {
4750
- chunkLZAINCGU_cjs.setArkPsbtField(tx, index, chunkLZAINCGU_cjs.ConditionWitness, path.extraWitness);
4774
+ chunkSOJDUKY6_cjs.setArkPsbtField(tx, index, chunkSOJDUKY6_cjs.ConditionWitness, path.extraWitness);
4751
4775
  }
4752
4776
  }
4753
4777
  function emulatorInputIndexes(tx) {
@@ -4794,7 +4818,7 @@ function isBoardingContract(contract, boardingCsv) {
4794
4818
  if (!isOnchainScoped(contract)) return false;
4795
4819
  if (contract.type === "boarding") return true;
4796
4820
  if (contract.type !== "default" || scopeOf(contract) !== "both") return false;
4797
- return chunkNDQ4LB4X_cjs.exitSequence(contract) === chunkFLPWNMX3_cjs.timelockToSequence(boardingCsv);
4821
+ return chunkJYQXB7OH_cjs.exitSequence(contract) === chunkFLPWNMX3_cjs.timelockToSequence(boardingCsv);
4798
4822
  }
4799
4823
  function needsOnchainSweep(coin, contract, boardingCsv, tip, marginBlocks = DEFAULT_COSIGN_MARGIN_BLOCKS) {
4800
4824
  if (!isBoardingContract(contract, boardingCsv) || !isExplorerCoin(coin)) return false;
@@ -4806,7 +4830,7 @@ function needsOnchainSweep(coin, contract, boardingCsv, tip, marginBlocks = DEFA
4806
4830
  return left.remaining > margin && left.remaining <= margin + window2;
4807
4831
  }
4808
4832
  function finalizeOwnedInput(tx, index) {
4809
- const condition = chunkLZAINCGU_cjs.getArkPsbtFields(tx, index, chunkLZAINCGU_cjs.ConditionWitness)[0];
4833
+ const condition = chunkSOJDUKY6_cjs.getArkPsbtFields(tx, index, chunkSOJDUKY6_cjs.ConditionWitness)[0];
4810
4834
  if (!condition) {
4811
4835
  tx.finalizeIdx(index);
4812
4836
  return;
@@ -4829,27 +4853,27 @@ var DEFINITE_COSIGN_REJECTIONS = /* @__PURE__ */ new Set([
4829
4853
  "TX_TOO_LARGE"
4830
4854
  ]);
4831
4855
  function isCosignRejectedAfterSigning(e) {
4832
- return e instanceof chunkLZAINCGU_cjs.OnchainCosignRejectedError && !isCosignFallback(e);
4856
+ return e instanceof chunkSOJDUKY6_cjs.OnchainCosignRejectedError && !isCosignFallback(e);
4833
4857
  }
4834
4858
  function isCosignFallback(e) {
4835
- if (e instanceof chunkLZAINCGU_cjs.OnchainCosignRejectedError) {
4859
+ if (e instanceof chunkSOJDUKY6_cjs.OnchainCosignRejectedError) {
4836
4860
  return !!e.arkErrorName && DEFINITE_COSIGN_REJECTIONS.has(e.arkErrorName);
4837
4861
  }
4838
- return e instanceof chunkLZAINCGU_cjs.OnchainCosignUnsupportedError || e instanceof OnchainCosignPreflightError;
4862
+ return e instanceof chunkSOJDUKY6_cjs.OnchainCosignUnsupportedError || e instanceof OnchainCosignPreflightError;
4839
4863
  }
4840
4864
  function rehydrateCosignError(e) {
4841
- if (!(e instanceof Error) || e instanceof chunkLZAINCGU_cjs.OnchainCosignRejectedError || e instanceof chunkLZAINCGU_cjs.OnchainCosignAmbiguousError || e instanceof chunkLZAINCGU_cjs.OnchainCosignUnsupportedError || e instanceof OnchainCosignPreflightError) {
4865
+ if (!(e instanceof Error) || e instanceof chunkSOJDUKY6_cjs.OnchainCosignRejectedError || e instanceof chunkSOJDUKY6_cjs.OnchainCosignAmbiguousError || e instanceof chunkSOJDUKY6_cjs.OnchainCosignUnsupportedError || e instanceof OnchainCosignPreflightError) {
4842
4866
  return e;
4843
4867
  }
4844
4868
  const { message } = e;
4845
- if (message.startsWith(chunkLZAINCGU_cjs.ONCHAIN_COSIGN_REJECTED_PREFIX)) {
4846
- const rest = message.slice(chunkLZAINCGU_cjs.ONCHAIN_COSIGN_REJECTED_PREFIX.length);
4869
+ if (message.startsWith(chunkSOJDUKY6_cjs.ONCHAIN_COSIGN_REJECTED_PREFIX)) {
4870
+ const rest = message.slice(chunkSOJDUKY6_cjs.ONCHAIN_COSIGN_REJECTED_PREFIX.length);
4847
4871
  const named = rest.match(/^\[([A-Z0-9_]+)\] ([\s\S]*)$/);
4848
- return named ? new chunkLZAINCGU_cjs.OnchainCosignRejectedError(named[2], named[1]) : new chunkLZAINCGU_cjs.OnchainCosignRejectedError(rest);
4872
+ return named ? new chunkSOJDUKY6_cjs.OnchainCosignRejectedError(named[2], named[1]) : new chunkSOJDUKY6_cjs.OnchainCosignRejectedError(rest);
4849
4873
  }
4850
- if (message.startsWith(chunkLZAINCGU_cjs.ONCHAIN_COSIGN_AMBIGUOUS_PREFIX)) {
4851
- return new chunkLZAINCGU_cjs.OnchainCosignAmbiguousError(
4852
- message.slice(chunkLZAINCGU_cjs.ONCHAIN_COSIGN_AMBIGUOUS_PREFIX.length)
4874
+ if (message.startsWith(chunkSOJDUKY6_cjs.ONCHAIN_COSIGN_AMBIGUOUS_PREFIX)) {
4875
+ return new chunkSOJDUKY6_cjs.OnchainCosignAmbiguousError(
4876
+ message.slice(chunkSOJDUKY6_cjs.ONCHAIN_COSIGN_AMBIGUOUS_PREFIX.length)
4853
4877
  );
4854
4878
  }
4855
4879
  if (message.startsWith(ONCHAIN_COSIGN_PREFLIGHT_PREFIX)) {
@@ -4857,8 +4881,8 @@ function rehydrateCosignError(e) {
4857
4881
  message.slice(ONCHAIN_COSIGN_PREFLIGHT_PREFIX.length)
4858
4882
  );
4859
4883
  }
4860
- if (message.startsWith(chunkLZAINCGU_cjs.ONCHAIN_COSIGN_UNSUPPORTED_PREFIX))
4861
- return new chunkLZAINCGU_cjs.OnchainCosignUnsupportedError();
4884
+ if (message.startsWith(chunkSOJDUKY6_cjs.ONCHAIN_COSIGN_UNSUPPORTED_PREFIX))
4885
+ return new chunkSOJDUKY6_cjs.OnchainCosignUnsupportedError();
4862
4886
  return e;
4863
4887
  }
4864
4888
  function estimateOnchainCosignFee(nIn, nOut, feeRate) {
@@ -4874,13 +4898,13 @@ async function submitOnchainSpend(tx, arkInputs, deps) {
4874
4898
  throw new Error("emulator inputs present but no emulator provider configured");
4875
4899
  }
4876
4900
  const { signedTx } = await deps.emulator.submitOnchainTx(base.base64.encode(tx.toPSBT()));
4877
- tx = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(signedTx));
4901
+ tx = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(signedTx));
4878
4902
  }
4879
4903
  if (arkInputs.size > 0) {
4880
4904
  if (!deps.arkProvider) {
4881
4905
  throw new Error("arkd-cosigned inputs present but no arkProvider configured");
4882
4906
  }
4883
- if (!deps.arkProvider.cosignOnchainTx) throw new chunkLZAINCGU_cjs.OnchainCosignUnsupportedError();
4907
+ if (!deps.arkProvider.cosignOnchainTx) throw new chunkSOJDUKY6_cjs.OnchainCosignUnsupportedError();
4884
4908
  return deps.arkProvider.cosignOnchainTx(base.base64.encode(tx.toPSBT()));
4885
4909
  }
4886
4910
  for (let i = 0; i < tx.inputsLength; i++) {
@@ -5031,7 +5055,7 @@ function parseProgram(text, env) {
5031
5055
 
5032
5056
  // src/contracts/spendability.ts
5033
5057
  function isContractGenericallySpendable(contract) {
5034
- return chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type)?.isGenericallySpendable?.(contract) === true;
5058
+ return chunkJYQXB7OH_cjs.contractHandlers.get(contract.type)?.isGenericallySpendable?.(contract) === true;
5035
5059
  }
5036
5060
  function gatedContracts(contracts) {
5037
5061
  const gated = /* @__PURE__ */ new Map();
@@ -5053,7 +5077,7 @@ function gateExclusion(gated) {
5053
5077
  return (vtxo) => {
5054
5078
  const type = gatedTypeOf(vtxo, gated);
5055
5079
  if (type === void 0) return void 0;
5056
- if (!chunkNDQ4LB4X_cjs.contractHandlers.has(type)) {
5080
+ if (!chunkJYQXB7OH_cjs.contractHandlers.has(type)) {
5057
5081
  return `at ${vtxo.script} (contract type '${type}') has no handler registered in this build`;
5058
5082
  }
5059
5083
  return `at ${vtxo.script} (contract type '${type}') is not generically spendable`;
@@ -5089,7 +5113,7 @@ function selectPendingRecoveryOutpoints(contractsWithVtxos, signerSet, nowSecond
5089
5113
  continue;
5090
5114
  }
5091
5115
  for (const v of vtxos) {
5092
- if (!chunkLZAINCGU_cjs.isVtxoSpent(v) && !v.isSwept && !v.isUnrolled) {
5116
+ if (!chunkSOJDUKY6_cjs.isVtxoSpent(v) && !v.isSwept && !v.isUnrolled) {
5093
5117
  out.add(`${v.txid}:${v.vout}`);
5094
5118
  }
5095
5119
  }
@@ -5131,14 +5155,14 @@ function byValueDescending(vtxos) {
5131
5155
  return [...vtxos].sort((a, b) => b.value - a.value);
5132
5156
  }
5133
5157
  async function fetchTimeHeight(wallet) {
5134
- return chunkLZAINCGU_cjs.resolveTimeHeight(wallet.onchainProvider);
5158
+ return chunkSOJDUKY6_cjs.resolveTimeHeight(wallet.onchainProvider);
5135
5159
  }
5136
5160
  function heldVtxosOf(wallet) {
5137
5161
  const held = wallet.getHeldVtxos;
5138
5162
  return typeof held === "function" ? held.call(wallet) : Promise.resolve([]);
5139
5163
  }
5140
5164
  function canMigrateBySend(vtxo, now) {
5141
- if (!chunkLZAINCGU_cjs.canSpendOffchain(vtxo, now)) return false;
5165
+ if (!chunkSOJDUKY6_cjs.canSpendOffchain(vtxo, now)) return false;
5142
5166
  return vtxo.expiresAt !== void 0 || vtxo.expiresAtHeight !== void 0;
5143
5167
  }
5144
5168
  function byExpiryAscending(vtxos, now) {
@@ -5146,7 +5170,7 @@ function byExpiryAscending(vtxos, now) {
5146
5170
  if (vtxo.isSwept) return -Infinity;
5147
5171
  if (vtxo.expiresAt !== void 0) return vtxo.expiresAt.getTime();
5148
5172
  if (vtxo.expiresAtHeight !== void 0) {
5149
- return chunkLZAINCGU_cjs.isPastExpiry(vtxo, now) ? -Infinity : Infinity;
5173
+ return chunkSOJDUKY6_cjs.isPastExpiry(vtxo, now) ? -Infinity : Infinity;
5150
5174
  }
5151
5175
  return Infinity;
5152
5176
  };
@@ -5173,7 +5197,7 @@ function priceSettlementInputs(vtxos, estimator) {
5173
5197
  const payable = [];
5174
5198
  const net = /* @__PURE__ */ new Map();
5175
5199
  for (const vtxo of vtxos) {
5176
- const inputFee = estimator.evalOffchainInput(chunkLZAINCGU_cjs.toOffchainInputFeeParams(vtxo));
5200
+ const inputFee = estimator.evalOffchainInput(chunkSOJDUKY6_cjs.toOffchainInputFeeParams(vtxo));
5177
5201
  if (inputFee.satoshis >= vtxo.value) {
5178
5202
  continue;
5179
5203
  }
@@ -5253,10 +5277,10 @@ var DEFAULT_SETTLEMENT_CONFIG = {
5253
5277
  };
5254
5278
  function getRecoverableVtxos(vtxos, dustAmount, now) {
5255
5279
  return vtxos.filter((vtxo) => {
5256
- if (chunkLZAINCGU_cjs.canRecoverOnchain(vtxo, now)) {
5280
+ if (chunkSOJDUKY6_cjs.canRecoverOnchain(vtxo, now)) {
5257
5281
  return true;
5258
5282
  }
5259
- if (chunkLZAINCGU_cjs.canSpendOffchain(vtxo, now) && vtxo.isPreconfirmed && isSubdust(vtxo, dustAmount)) {
5283
+ if (chunkSOJDUKY6_cjs.canSpendOffchain(vtxo, now) && vtxo.isPreconfirmed && isSubdust(vtxo, dustAmount)) {
5260
5284
  return true;
5261
5285
  }
5262
5286
  return false;
@@ -5288,7 +5312,7 @@ function getRecoverableWithSubdust(vtxos, dustAmount, now) {
5288
5312
  function isVtxoExpiringSoon(vtxo, thresholdMs) {
5289
5313
  if (vtxo.isUnrolled) return false;
5290
5314
  const realThresholdMs = thresholdMs <= 100 ? DEFAULT_THRESHOLD_MS : thresholdMs;
5291
- const expiresAt = chunkLZAINCGU_cjs.normalizeVtxo(vtxo).expiresAt;
5315
+ const expiresAt = chunkSOJDUKY6_cjs.normalizeVtxo(vtxo).expiresAt;
5292
5316
  if (expiresAt === void 0) return false;
5293
5317
  const now = Date.now();
5294
5318
  const batchExpiry = expiresAt.getTime();
@@ -5299,7 +5323,7 @@ function getExpiringAndRecoverableVtxos(vtxos, thresholdMs, dustAmount, now) {
5299
5323
  return vtxos.filter(
5300
5324
  // The leading exclusion covers the `isSubdust` arm too, which is a value
5301
5325
  // property and would otherwise re-admit an exited coin on its own.
5302
- (vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) || chunkLZAINCGU_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dustAmount))
5326
+ (vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) || chunkSOJDUKY6_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dustAmount))
5303
5327
  );
5304
5328
  }
5305
5329
  function isMigrationCapable(wallet) {
@@ -5359,7 +5383,7 @@ var VtxoManager = class _VtxoManager {
5359
5383
  constructor(wallet, settlementConfig) {
5360
5384
  this.wallet = wallet;
5361
5385
  if (settlementConfig !== false) {
5362
- chunkLZAINCGU_cjs.assertTimerMs("pollIntervalMs", settlementConfig?.pollIntervalMs);
5386
+ chunkSOJDUKY6_cjs.assertTimerMs("pollIntervalMs", settlementConfig?.pollIntervalMs);
5363
5387
  }
5364
5388
  this.settlementConfig = settlementConfig !== void 0 ? settlementConfig : { ...DEFAULT_SETTLEMENT_CONFIG };
5365
5389
  this.contractEventsSubscriptionReady = this.initializeSubscription();
@@ -5671,7 +5695,7 @@ var VtxoManager = class _VtxoManager {
5671
5695
  * {@link recoverImportedContracts}).
5672
5696
  */
5673
5697
  async recoverOneImportedContract(wallet, contract, vtxos, info, dustAmount) {
5674
- const recoverable = vtxos.filter((vtxo) => vtxo.isSwept && !chunkLZAINCGU_cjs.isVtxoSpent(vtxo));
5698
+ const recoverable = vtxos.filter((vtxo) => vtxo.isSwept && !chunkSOJDUKY6_cjs.isVtxoSpent(vtxo));
5675
5699
  const estimator = new Estimator(info?.fees.intentFee ?? {});
5676
5700
  const { payable, net } = priceSettlementInputs(recoverable, estimator);
5677
5701
  const vtxoMaxAmount = info?.vtxoMaxAmount ?? -1n;
@@ -5685,15 +5709,27 @@ var VtxoManager = class _VtxoManager {
5685
5709
  const arkAddress = await wallet.getAddress();
5686
5710
  const totalAmount = deductOffchainOutputFee(subtotal, estimator, arkAddress);
5687
5711
  if (totalAmount < dustAmount) return;
5688
- await wallet.settle({
5712
+ const settledTxid = await wallet.settle({
5689
5713
  inputs: batch,
5690
5714
  outputs: [{ address: arkAddress, amount: totalAmount }]
5691
5715
  });
5716
+ try {
5717
+ await wallet.correlateArkadeCashRecovery?.(
5718
+ contract.script,
5719
+ settledTxid,
5720
+ Number(totalAmount)
5721
+ );
5722
+ } catch (error) {
5723
+ console.error(
5724
+ `Failed to record arkcash recovery ${settledTxid} for ${contract.script}:`,
5725
+ error
5726
+ );
5727
+ }
5692
5728
  }
5693
5729
  if (vtxos.length === 0) return;
5694
5730
  const spent = new Set(batch.map((vtxo) => `${vtxo.txid}:${vtxo.vout}`));
5695
5731
  const stillSpendable = vtxos.some(
5696
- (vtxo) => !chunkLZAINCGU_cjs.isVtxoSpent(vtxo) && !spent.has(`${vtxo.txid}:${vtxo.vout}`)
5732
+ (vtxo) => !chunkSOJDUKY6_cjs.isVtxoSpent(vtxo) && !spent.has(`${vtxo.txid}:${vtxo.vout}`)
5697
5733
  );
5698
5734
  if (!stillSpendable) {
5699
5735
  await wallet.removeRecoveryContract(contract.script);
@@ -5935,7 +5971,7 @@ var VtxoManager = class _VtxoManager {
5935
5971
  return txid;
5936
5972
  } catch (e) {
5937
5973
  if (!isCosignFallback(e)) throw e;
5938
- if (e instanceof chunkLZAINCGU_cjs.OnchainCosignRejectedError) {
5974
+ if (e instanceof chunkSOJDUKY6_cjs.OnchainCosignRejectedError) {
5939
5975
  console.warn("Onchain cosign sweep rejected, falling back to CSV exit:", e.message);
5940
5976
  }
5941
5977
  return void 0;
@@ -6012,7 +6048,7 @@ var VtxoManager = class _VtxoManager {
6012
6048
  `Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
6013
6049
  );
6014
6050
  }
6015
- const tx = new chunkLZAINCGU_cjs.Transaction();
6051
+ const tx = new chunkSOJDUKY6_cjs.Transaction();
6016
6052
  for (const { utxo, script, leaf } of inputs) {
6017
6053
  tx.addInput({
6018
6054
  txid: utxo.txid,
@@ -6250,8 +6286,8 @@ var VtxoManager = class _VtxoManager {
6250
6286
  const cls = classifyAgainstSignerSet(serverPubKey, signerSet, nowSeconds);
6251
6287
  if (cls.status === "CURRENT") continue;
6252
6288
  const live = vtxos.filter((v) => !v.isUnrolled);
6253
- const recoverable = live.filter((v) => v.isSwept && !chunkLZAINCGU_cjs.isVtxoSpent(v));
6254
- const spendable = live.filter((v) => !chunkLZAINCGU_cjs.isVtxoSpent(v) && !v.isSwept);
6289
+ const recoverable = live.filter((v) => v.isSwept && !chunkSOJDUKY6_cjs.isVtxoSpent(v));
6290
+ const spendable = live.filter((v) => !chunkSOJDUKY6_cjs.isVtxoSpent(v) && !v.isSwept);
6255
6291
  const value = spendable.reduce((sum, v) => sum + v.value, 0);
6256
6292
  let recoverableCount = 0;
6257
6293
  let recoverableValue = 0;
@@ -6607,8 +6643,8 @@ var VtxoManager = class _VtxoManager {
6607
6643
  }
6608
6644
  /** The outpoint a `VTXO_ALREADY_SPENT` error carries in `metadata.vtxo_outpoint`, if any. */
6609
6645
  extractSpentOutpoint(error) {
6610
- const ark = chunkLZAINCGU_cjs.maybeArkError(error);
6611
- if (!chunkLZAINCGU_cjs.isArkError(ark, chunkLZAINCGU_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
6646
+ const ark = chunkSOJDUKY6_cjs.maybeArkError(error);
6647
+ if (!chunkSOJDUKY6_cjs.isArkError(ark, chunkSOJDUKY6_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
6612
6648
  const raw = ark.metadata?.vtxo_outpoint;
6613
6649
  if (typeof raw !== "string") return void 0;
6614
6650
  const [txid, voutStr] = raw.split(":");
@@ -6789,7 +6825,7 @@ var VtxoManager = class _VtxoManager {
6789
6825
  if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
6790
6826
  break;
6791
6827
  }
6792
- const inputFee = estimator.evalOffchainInput(chunkLZAINCGU_cjs.toOffchainInputFeeParams(v));
6828
+ const inputFee = estimator.evalOffchainInput(chunkSOJDUKY6_cjs.toOffchainInputFeeParams(v));
6793
6829
  if (inputFee.satoshis >= v.value) {
6794
6830
  continue;
6795
6831
  }
@@ -7098,7 +7134,7 @@ var ArkadeCash = class _ArkadeCash {
7098
7134
  return SingleKey.fromPrivateKey(this._privateKey);
7099
7135
  }
7100
7136
  get vtxoScript() {
7101
- return new chunkNDQ4LB4X_cjs.DefaultVtxo.Script({
7137
+ return new chunkJYQXB7OH_cjs.DefaultVtxo.Script({
7102
7138
  pubKey: this._publicKey,
7103
7139
  serverPubKey: this._serverPubKey,
7104
7140
  csvTimelock: this.csvTimelock
@@ -7108,11 +7144,97 @@ var ArkadeCash = class _ArkadeCash {
7108
7144
  return this.vtxoScript.address(addressHrp, this._serverPubKey);
7109
7145
  }
7110
7146
  };
7147
+ var ArkadeCashTracker = class {
7148
+ records = /* @__PURE__ */ new Map();
7149
+ get(id) {
7150
+ return this.records.get(id);
7151
+ }
7152
+ list() {
7153
+ return [...this.records.values()].sort((a, b) => b.createdAt - a.createdAt);
7154
+ }
7155
+ };
7156
+ function createArkadeCashTracker() {
7157
+ return new ArkadeCashTracker();
7158
+ }
7159
+ var unionByTxid = (a, b) => [
7160
+ ...new Map([...a, ...b].map((entry) => [entry.txid, entry])).values()
7161
+ ];
7162
+ function mergeArkadeCashRecord(prev, next) {
7163
+ if (!prev) return next;
7164
+ const lead = prev.action === "claimed" && next.action === "issued" ? prev : next;
7165
+ return {
7166
+ id: next.id,
7167
+ action: lead.action,
7168
+ outcome: lead.outcome,
7169
+ createdAt: Math.min(prev.createdAt, next.createdAt),
7170
+ issues: unionByTxid(prev.issues, next.issues),
7171
+ claims: unionByTxid(prev.claims, next.claims)
7172
+ };
7173
+ }
7174
+ function isArkadeCashRecord(value) {
7175
+ if (!value || typeof value !== "object") return false;
7176
+ const v = value;
7177
+ return typeof v.id === "string" && (v.action === "issued" || v.action === "claimed") && typeof v.createdAt === "number" && typeof v.outcome === "string" && Array.isArray(v.issues) && Array.isArray(v.claims);
7178
+ }
7179
+ function addArkadeCashRecord(records, record) {
7180
+ records.records.set(record.id, mergeArkadeCashRecord(records.get(record.id), record));
7181
+ }
7182
+ function arkadeCashId(cash) {
7183
+ return base.hex.encode(cash.vtxoScript.pkScript);
7184
+ }
7185
+ function arkadeCashResolver(records) {
7186
+ let index;
7187
+ const build = () => {
7188
+ const next = /* @__PURE__ */ new Map();
7189
+ for (const record of records.list()) {
7190
+ for (const { txid } of [...record.issues, ...record.claims]) {
7191
+ const touching = next.get(txid) ?? [];
7192
+ if (touching[touching.length - 1] !== record) touching.push(record);
7193
+ next.set(txid, touching);
7194
+ }
7195
+ }
7196
+ return next;
7197
+ };
7198
+ return {
7199
+ id: "arkade-cash",
7200
+ async prepare() {
7201
+ index = build();
7202
+ },
7203
+ resolve(tx) {
7204
+ if (tx.key.boardingTxid) return [];
7205
+ index ??= build();
7206
+ const txid = tx.key.arkTxid || tx.key.commitmentTxid;
7207
+ const isBatchRow = !tx.key.arkTxid;
7208
+ const direction = tx.type === "SENT" /* TxSent */ ? "issued" : "claimed";
7209
+ return (index.get(txid) ?? []).flatMap((record) => {
7210
+ const entries = direction === "issued" ? record.issues : record.claims;
7211
+ const match = entries.find(
7212
+ (entry) => entry.txid === txid && (!isBatchRow || entry.amount === tx.amount)
7213
+ );
7214
+ if (!match) return [];
7215
+ return [
7216
+ {
7217
+ groupId: `arkade-cash:${record.id}:${direction}`,
7218
+ label: direction === "issued" ? "Cash issued" : "Cash claimed",
7219
+ kind: "arkade-cash",
7220
+ outcome: record.outcome,
7221
+ metadata: { cashId: record.id, direction },
7222
+ amount: match.amount
7223
+ }
7224
+ ];
7225
+ });
7226
+ }
7227
+ };
7228
+ }
7229
+ async function arkadeCashActivity(records, txs) {
7230
+ const activities = await buildActivities(txs, [arkadeCashResolver(records)]);
7231
+ return activities.filter((activity) => activity.intent?.kind === "arkade-cash");
7232
+ }
7111
7233
 
7112
7234
  // src/wallet/intentReconciliation.ts
7113
7235
  var NON_TERMINAL_INTENT_STATES = ALL_BATCH_REGISTRATION_STATES.filter((s) => !isTerminalBatchRegistrationState(s));
7114
7236
  function isConsumed(vtxo) {
7115
- return vtxo !== void 0 && chunkLZAINCGU_cjs.isVtxoSpent(vtxo);
7237
+ return vtxo !== void 0 && chunkSOJDUKY6_cjs.isVtxoSpent(vtxo);
7116
7238
  }
7117
7239
  async function classifyIntent(intent, vtxosByOutpoint, now) {
7118
7240
  if (isTerminalBatchRegistrationState(intent.state)) return void 0;
@@ -7150,7 +7272,7 @@ async function reconcileIntents(deps) {
7150
7272
  let vtxosByOutpoint = /* @__PURE__ */ new Map();
7151
7273
  if (outpoints.length > 0) {
7152
7274
  try {
7153
- const { vtxos } = await chunkLZAINCGU_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
7275
+ const { vtxos } = await chunkSOJDUKY6_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
7154
7276
  vtxosByOutpoint = new Map(vtxos.map((v) => [outpointKey(v), v]));
7155
7277
  } catch (e) {
7156
7278
  console.error("reconcileIntents: failed to fetch input VTXO state", e);
@@ -7210,7 +7332,7 @@ async function releaseFromServer(intent, deps, now) {
7210
7332
  });
7211
7333
  }
7212
7334
  function isNoMatchingIntentsError(e) {
7213
- return chunkLZAINCGU_cjs.isArkError(e, chunkLZAINCGU_cjs.ArkErrorName.INVALID_INTENT_PROOF) && e.message.includes("no matching intents found");
7335
+ return chunkSOJDUKY6_cjs.isArkError(e, chunkSOJDUKY6_cjs.ArkErrorName.INVALID_INTENT_PROOF) && e.message.includes("no matching intents found");
7214
7336
  }
7215
7337
  function terminal(intent, state, now, patch) {
7216
7338
  return { ...intent, ...patch, state, updatedAt: now };
@@ -7437,7 +7559,7 @@ async function captureExitBranch(params) {
7437
7559
  const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
7438
7560
  if (nonCommitment.length > 0) {
7439
7561
  for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
7440
- psbtByTxid.set(chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
7562
+ psbtByTxid.set(chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
7441
7563
  }
7442
7564
  }
7443
7565
  }
@@ -7480,10 +7602,10 @@ var IndexerExitDataSource = class {
7480
7602
  while (hasMore) {
7481
7603
  const { chain: page, page: meta } = await this.indexer.getVtxoChain(
7482
7604
  { txid: vtxo.txid, vout: vtxo.vout },
7483
- { pageIndex, pageSize: chunkLZAINCGU_cjs.DEFAULT_PAGE_SIZE }
7605
+ { pageIndex, pageSize: chunkSOJDUKY6_cjs.DEFAULT_PAGE_SIZE }
7484
7606
  );
7485
7607
  chain.push(...page);
7486
- hasMore = meta ? page.length === chunkLZAINCGU_cjs.DEFAULT_PAGE_SIZE : false;
7608
+ hasMore = meta ? page.length === chunkSOJDUKY6_cjs.DEFAULT_PAGE_SIZE : false;
7487
7609
  pageIndex++;
7488
7610
  }
7489
7611
  return chain;
@@ -7495,12 +7617,12 @@ var IndexerExitDataSource = class {
7495
7617
  while (hasMore) {
7496
7618
  const { txs, page } = await this.indexer.getVirtualTxs(txids, {
7497
7619
  pageIndex,
7498
- pageSize: chunkLZAINCGU_cjs.DEFAULT_PAGE_SIZE
7620
+ pageSize: chunkSOJDUKY6_cjs.DEFAULT_PAGE_SIZE
7499
7621
  });
7500
7622
  for (const psbt of txs) {
7501
- out.set(chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
7623
+ out.set(chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
7502
7624
  }
7503
- hasMore = page ? txs.length === chunkLZAINCGU_cjs.DEFAULT_PAGE_SIZE : false;
7625
+ hasMore = page ? txs.length === chunkSOJDUKY6_cjs.DEFAULT_PAGE_SIZE : false;
7504
7626
  pageIndex++;
7505
7627
  }
7506
7628
  return out;
@@ -7521,7 +7643,7 @@ function chainedTxTypeToChainTxType(t) {
7521
7643
  }
7522
7644
  }
7523
7645
  function psbtInputTxids(psbtBase64) {
7524
- return txInputTxids(chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64)));
7646
+ return txInputTxids(chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64)));
7525
7647
  }
7526
7648
  function txInputTxids(tx) {
7527
7649
  const ids = [];
@@ -7828,10 +7950,10 @@ async function resolveArkInfo(arkProvider, walletRepository, opts) {
7828
7950
  try {
7829
7951
  info = await arkProvider.getInfo();
7830
7952
  } catch (err) {
7831
- if (opts?.requireLive || !chunkLZAINCGU_cjs.isRetryableProviderError(err)) throw err;
7953
+ if (opts?.requireLive || !chunkSOJDUKY6_cjs.isRetryableProviderError(err)) throw err;
7832
7954
  const snapshot = await loadArkInfoSnapshot(walletRepository);
7833
7955
  if (!snapshot) {
7834
- throw new chunkLZAINCGU_cjs.ProviderUnavailableError(
7956
+ throw new chunkSOJDUKY6_cjs.ProviderUnavailableError(
7835
7957
  "Operator info is unavailable and no cached snapshot exists",
7836
7958
  { cause: err }
7837
7959
  );
@@ -8023,7 +8145,7 @@ function buildGraph(rootTxid, chunksByTxid) {
8023
8145
  return new TxTree(rootTx, children);
8024
8146
  }
8025
8147
  function decodeNode(chunk) {
8026
- const tx = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(chunk.tx));
8148
+ const tx = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(chunk.tx));
8027
8149
  return { tx, children: chunk.children };
8028
8150
  }
8029
8151
  exports.Batch = void 0;
@@ -8247,7 +8369,7 @@ function collectArkTxidsNeedingCreatedAt(vtxos, localCreatedAt) {
8247
8369
  return [...txids];
8248
8370
  }
8249
8371
  async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, resolveTxCreatedAt, gatedScripts = /* @__PURE__ */ new Map()) {
8250
- const normalized = vtxos.map(chunkLZAINCGU_cjs.normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
8372
+ const normalized = vtxos.map(chunkSOJDUKY6_cjs.normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
8251
8373
  const localCreatedAt = localCreatedAtByTxid(normalized);
8252
8374
  const gatedVtxos = normalized.filter((vtxo) => isGatedVtxo(vtxo, gatedScripts));
8253
8375
  const ownVtxos = normalized.filter((vtxo) => !isGatedVtxo(vtxo, gatedScripts));
@@ -8434,7 +8556,7 @@ var AssetManager = class extends ReadonlyAssetManager {
8434
8556
  withRecoverable: false,
8435
8557
  genericallySpendableOnly: true
8436
8558
  });
8437
- const controlAssetRef = params.controlAssetId ? chunkHKEPJBTY_cjs.AssetRef.fromId(chunkHKEPJBTY_cjs.AssetId.fromString(params.controlAssetId)) : null;
8559
+ const controlAssetRef = params.controlAssetId ? chunk4IDCSOP2_cjs.AssetRef.fromId(chunk4IDCSOP2_cjs.AssetId.fromString(params.controlAssetId)) : null;
8438
8560
  const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
8439
8561
  let totalBtcSelected = 0n;
8440
8562
  const assetChanges = /* @__PURE__ */ new Map();
@@ -8447,8 +8569,8 @@ var AssetManager = class extends ReadonlyAssetManager {
8447
8569
  }
8448
8570
  }
8449
8571
  const groups = [];
8450
- const issuedAssetOutput = chunkHKEPJBTY_cjs.AssetOutput.create(0, params.amount);
8451
- const issuedAssetGroup = chunkHKEPJBTY_cjs.AssetGroup.create(
8572
+ const issuedAssetOutput = chunk4IDCSOP2_cjs.AssetOutput.create(0, params.amount);
8573
+ const issuedAssetGroup = chunk4IDCSOP2_cjs.AssetGroup.create(
8452
8574
  null,
8453
8575
  controlAssetRef,
8454
8576
  [],
@@ -8461,11 +8583,11 @@ var AssetManager = class extends ReadonlyAssetManager {
8461
8583
  for (const [assetId, amount] of assetChanges) {
8462
8584
  const changeInputs = inputsForAsset(assetInputs, assetId);
8463
8585
  groups.push(
8464
- chunkHKEPJBTY_cjs.AssetGroup.create(
8465
- chunkHKEPJBTY_cjs.AssetId.fromString(assetId),
8586
+ chunk4IDCSOP2_cjs.AssetGroup.create(
8587
+ chunk4IDCSOP2_cjs.AssetId.fromString(assetId),
8466
8588
  null,
8467
8589
  changeInputs,
8468
- [chunkHKEPJBTY_cjs.AssetOutput.create(0, amount)],
8590
+ [chunk4IDCSOP2_cjs.AssetOutput.create(0, amount)],
8469
8591
  []
8470
8592
  )
8471
8593
  );
@@ -8480,7 +8602,7 @@ var AssetManager = class extends ReadonlyAssetManager {
8480
8602
  );
8481
8603
  return {
8482
8604
  arkTxId: arkTxid,
8483
- assetId: chunkHKEPJBTY_cjs.AssetId.create(arkTxid, 0).toString()
8605
+ assetId: chunk4IDCSOP2_cjs.AssetId.create(arkTxid, 0).toString()
8484
8606
  };
8485
8607
  }
8486
8608
  /**
@@ -8554,23 +8676,23 @@ var AssetManager = class extends ReadonlyAssetManager {
8554
8676
  const assetInputs = selectedCoinsToAssetInputs(selectedCoins);
8555
8677
  const reissueInputs = inputsForAsset(assetInputs, params.assetId);
8556
8678
  const totalAssetAmount = assetToReissueAmount + params.amount;
8557
- const reissueAssetIdObj = chunkHKEPJBTY_cjs.AssetId.fromString(params.assetId);
8558
- const reissueAssetGroup = chunkHKEPJBTY_cjs.AssetGroup.create(
8679
+ const reissueAssetIdObj = chunk4IDCSOP2_cjs.AssetId.fromString(params.assetId);
8680
+ const reissueAssetGroup = chunk4IDCSOP2_cjs.AssetGroup.create(
8559
8681
  reissueAssetIdObj,
8560
8682
  null,
8561
8683
  reissueInputs,
8562
- [chunkHKEPJBTY_cjs.AssetOutput.create(0, totalAssetAmount)],
8684
+ [chunk4IDCSOP2_cjs.AssetOutput.create(0, totalAssetAmount)],
8563
8685
  []
8564
8686
  );
8565
8687
  const groups = [reissueAssetGroup];
8566
8688
  for (const [assetId, amount] of assetChanges) {
8567
8689
  const changeInputs = inputsForAsset(assetInputs, assetId);
8568
8690
  groups.push(
8569
- chunkHKEPJBTY_cjs.AssetGroup.create(
8570
- chunkHKEPJBTY_cjs.AssetId.fromString(assetId),
8691
+ chunk4IDCSOP2_cjs.AssetGroup.create(
8692
+ chunk4IDCSOP2_cjs.AssetId.fromString(assetId),
8571
8693
  null,
8572
8694
  changeInputs,
8573
- [chunkHKEPJBTY_cjs.AssetOutput.create(0, amount)],
8695
+ [chunk4IDCSOP2_cjs.AssetOutput.create(0, amount)],
8574
8696
  []
8575
8697
  )
8576
8698
  );
@@ -8641,11 +8763,11 @@ var AssetManager = class extends ReadonlyAssetManager {
8641
8763
  for (const [assetId, amount] of assetChanges) {
8642
8764
  const changeInputs = inputsForAsset(assetInputs, assetId);
8643
8765
  groups.push(
8644
- chunkHKEPJBTY_cjs.AssetGroup.create(
8645
- chunkHKEPJBTY_cjs.AssetId.fromString(assetId),
8766
+ chunk4IDCSOP2_cjs.AssetGroup.create(
8767
+ chunk4IDCSOP2_cjs.AssetId.fromString(assetId),
8646
8768
  null,
8647
8769
  changeInputs,
8648
- amount > 0n ? [chunkHKEPJBTY_cjs.AssetOutput.create(0, amount)] : [],
8770
+ amount > 0n ? [chunk4IDCSOP2_cjs.AssetOutput.create(0, amount)] : [],
8649
8771
  []
8650
8772
  )
8651
8773
  );
@@ -8658,7 +8780,7 @@ function inputsForAsset(assetInputs, assetId) {
8658
8780
  for (const [inputIndex, assets] of assetInputs) {
8659
8781
  for (const asset of assets) {
8660
8782
  if (asset.assetId !== assetId) continue;
8661
- inputs.push(chunkHKEPJBTY_cjs.AssetInput.create(inputIndex, asset.amount));
8783
+ inputs.push(chunk4IDCSOP2_cjs.AssetInput.create(inputIndex, asset.amount));
8662
8784
  }
8663
8785
  }
8664
8786
  return inputs;
@@ -8667,7 +8789,7 @@ async function submitToSelf(submit, wallet, inputs, amount, groups) {
8667
8789
  const outputAddress = chunkFLPWNMX3_cjs.ArkAddress.decode(await wallet.getAddress());
8668
8790
  const outputs = [
8669
8791
  { script: outputAddress.pkScript, amount: BigInt(amount) },
8670
- Extension.create([chunkHKEPJBTY_cjs.Packet.create(groups)]).txOut()
8792
+ Extension.create([chunk4IDCSOP2_cjs.Packet.create(groups)]).txOut()
8671
8793
  ];
8672
8794
  const { arkTxid } = await submit(inputs, outputs);
8673
8795
  return arkTxid;
@@ -8691,7 +8813,7 @@ function castMetadata(metadata) {
8691
8813
  } else {
8692
8814
  throw new Error("Invalid metadata value type");
8693
8815
  }
8694
- md.push(chunkHKEPJBTY_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
8816
+ md.push(chunk4IDCSOP2_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
8695
8817
  }
8696
8818
  return md;
8697
8819
  }
@@ -8717,7 +8839,7 @@ var DelegateManagerImpl = class {
8717
8839
  this.arkInfoProvider.getInfo(),
8718
8840
  this.delegateProvider.getDelegateInfo()
8719
8841
  ]);
8720
- const eligible = vtxos.map(chunkLZAINCGU_cjs.normalizeVtxo).filter(
8842
+ const eligible = vtxos.map(chunkSOJDUKY6_cjs.normalizeVtxo).filter(
8721
8843
  (v) => isAnnotated(v) && findDelegateTapLeaf(v, delegateInfo.pubkey) !== void 0
8722
8844
  );
8723
8845
  if (eligible.length === 0) {
@@ -8749,7 +8871,7 @@ var DelegateManagerImpl = class {
8749
8871
  const groupByExpiry = /* @__PURE__ */ new Map();
8750
8872
  let recoverableVtxos = [];
8751
8873
  for (const vtxo of eligible) {
8752
- if (chunkLZAINCGU_cjs.canRecoverOnchain(vtxo, now)) {
8874
+ if (chunkSOJDUKY6_cjs.canRecoverOnchain(vtxo, now)) {
8753
8875
  recoverableVtxos.push(vtxo);
8754
8876
  continue;
8755
8877
  }
@@ -8801,7 +8923,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
8801
8923
  }
8802
8924
  if (!delegateAt) {
8803
8925
  const now = { timestamp: /* @__PURE__ */ new Date() };
8804
- const expiryTimestamp = vtxos.filter((coin) => !chunkLZAINCGU_cjs.canRecoverOnchain(coin, now) && coin.expiresAt).reduce(
8926
+ const expiryTimestamp = vtxos.filter((coin) => !chunkSOJDUKY6_cjs.canRecoverOnchain(coin, now) && coin.expiresAt).reduce(
8805
8927
  (min, coin) => Math.min(min, coin.expiresAt.getTime()),
8806
8928
  Number.MAX_SAFE_INTEGER
8807
8929
  );
@@ -8821,7 +8943,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
8821
8943
  let amount = 0n;
8822
8944
  for (const coin of vtxos) {
8823
8945
  const inputFee = estimator.evalOffchainInput({
8824
- ...chunkLZAINCGU_cjs.toOffchainInputFeeParams(coin),
8946
+ ...chunkSOJDUKY6_cjs.toOffchainInputFeeParams(coin),
8825
8947
  type: "vtxo"
8826
8948
  });
8827
8949
  if (inputFee.satoshis >= coin.value) {
@@ -8871,7 +8993,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
8871
8993
  btcSigner.Address(chunkFLPWNMX3_cjs.getNetwork(network)).decode(forfeitAddress)
8872
8994
  );
8873
8995
  const forfeits = await Promise.all(
8874
- vtxos.filter((v) => chunkLZAINCGU_cjs.requiresForfeit(v)).map(async (coin) => {
8996
+ vtxos.filter((v) => chunkSOJDUKY6_cjs.requiresForfeit(v)).map(async (coin) => {
8875
8997
  const forfeit = await makeDelegateForfeitTx(
8876
8998
  coin,
8877
8999
  dust,
@@ -8954,7 +9076,7 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
8954
9076
  expire_at: 0,
8955
9077
  cosigners_public_keys: cosignerPubKeys
8956
9078
  };
8957
- const proof = chunkLZAINCGU_cjs.Proof.create(message, coins, outputs);
9079
+ const proof = chunkSOJDUKY6_cjs.Proof.create(message, coins, outputs);
8958
9080
  const signedProof = await identity.sign(proof);
8959
9081
  return {
8960
9082
  proof: base.base64.encode(signedProof.toPSBT()),
@@ -9696,7 +9818,7 @@ function decodeArkContract(encoded) {
9696
9818
  }
9697
9819
  function contractFromArkContract(encoded, options = {}) {
9698
9820
  const parsed = decodeArkContract(encoded);
9699
- const handler = chunkNDQ4LB4X_cjs.contractHandlers.get(parsed.type);
9821
+ const handler = chunkJYQXB7OH_cjs.contractHandlers.get(parsed.type);
9700
9822
  if (!handler) {
9701
9823
  throw new Error(`No handler registered for contract type '${parsed.type}'`);
9702
9824
  }
@@ -9712,7 +9834,7 @@ function contractFromArkContract(encoded, options = {}) {
9712
9834
  }
9713
9835
  function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunkFLPWNMX3_cjs.DEFAULT_NETWORK.hrp, options = {}) {
9714
9836
  const parsed = decodeArkContract(encoded);
9715
- const handler = chunkNDQ4LB4X_cjs.contractHandlers.getOrThrow(parsed.type);
9837
+ const handler = chunkJYQXB7OH_cjs.contractHandlers.getOrThrow(parsed.type);
9716
9838
  const params = parsed.data;
9717
9839
  const vtxoScript = handler.createScript(params);
9718
9840
  return {
@@ -9734,10 +9856,11 @@ function isArkContract(str) {
9734
9856
  function computeReconnectDelay(attempt, baseMs, maxMs) {
9735
9857
  return Math.min(baseMs * Math.pow(2, attempt - 1), maxMs);
9736
9858
  }
9859
+ var STABLE_CONNECTION_MS = 3e4;
9737
9860
  var DEFAULT_CONTRACT_WATCHER_CONFIG = {
9738
9861
  failsafePollIntervalMs: 2e4,
9739
9862
  reconnectDelayMs: 1e3,
9740
- maxReconnectDelayMs: 5e3,
9863
+ maxReconnectDelayMs: 6e4,
9741
9864
  maxReconnectAttempts: 0,
9742
9865
  // unlimited
9743
9866
  subscriptionRequestTimeoutMs: 3e4
@@ -9753,6 +9876,7 @@ var ContractWatcher = class {
9753
9876
  eventCallback;
9754
9877
  connectionState = "disconnected";
9755
9878
  reconnectAttempts = 0;
9879
+ connectedAt;
9756
9880
  reconnectTimeoutId;
9757
9881
  failsafePollIntervalId;
9758
9882
  /** See {@link withCoalescedSubscription}. */
@@ -9769,10 +9893,10 @@ var ContractWatcher = class {
9769
9893
  eventSourceReported = false;
9770
9894
  /** @see ContractWatcherConfig */
9771
9895
  constructor(config) {
9772
- chunkLZAINCGU_cjs.assertTimerMs("failsafePollIntervalMs", config.failsafePollIntervalMs);
9773
- chunkLZAINCGU_cjs.assertTimerMs("reconnectDelayMs", config.reconnectDelayMs);
9774
- chunkLZAINCGU_cjs.assertTimerMs("maxReconnectDelayMs", config.maxReconnectDelayMs);
9775
- chunkLZAINCGU_cjs.assertTimerMs("subscriptionRequestTimeoutMs", config.subscriptionRequestTimeoutMs);
9896
+ chunkSOJDUKY6_cjs.assertTimerMs("failsafePollIntervalMs", config.failsafePollIntervalMs);
9897
+ chunkSOJDUKY6_cjs.assertTimerMs("reconnectDelayMs", config.reconnectDelayMs);
9898
+ chunkSOJDUKY6_cjs.assertTimerMs("maxReconnectDelayMs", config.maxReconnectDelayMs);
9899
+ chunkSOJDUKY6_cjs.assertTimerMs("subscriptionRequestTimeoutMs", config.subscriptionRequestTimeoutMs);
9776
9900
  if (config.subscriptionRequestTimeoutMs === 0) {
9777
9901
  throw new Error("subscriptionRequestTimeoutMs must be greater than 0");
9778
9902
  }
@@ -9938,6 +10062,7 @@ var ContractWatcher = class {
9938
10062
  const session = new AbortController();
9939
10063
  this.abortController = session;
9940
10064
  this.reconnectAttempts = 0;
10065
+ this.connectedAt = void 0;
9941
10066
  this.subscriptionUpdate = Promise.resolve();
9942
10067
  await this.connect();
9943
10068
  if (session.signal.aborted) return () => this.stopWatching();
@@ -9947,6 +10072,7 @@ var ContractWatcher = class {
9947
10072
  async stopWatching() {
9948
10073
  this.isWatching = false;
9949
10074
  this.connectionState = "disconnected";
10075
+ this.connectedAt = void 0;
9950
10076
  this.abortController?.abort();
9951
10077
  this.cancelSubscriptionRetry();
9952
10078
  this.subscriptionRetryAttempts = 0;
@@ -9992,28 +10118,28 @@ var ContractWatcher = class {
9992
10118
  await this.pollAllContracts();
9993
10119
  if (!this.isWatching || signal?.aborted) return;
9994
10120
  this.connectionState = "connected";
9995
- this.reconnectAttempts = 0;
10121
+ this.connectedAt = Date.now();
9996
10122
  this.listenLoop().catch((e) => {
9997
10123
  if (!this.isWatching || signal?.aborted) return;
9998
- if (chunkLZAINCGU_cjs.isEventSourceError(e)) {
10124
+ if (chunkSOJDUKY6_cjs.isEventSourceError(e)) {
9999
10125
  console.debug("ContractWatcher subscription disconnected; reconnecting");
10000
- } else if (!chunkLZAINCGU_cjs.isEventSourceUnavailableError(e)) {
10126
+ } else if (!chunkSOJDUKY6_cjs.isEventSourceUnavailableError(e)) {
10001
10127
  console.error(e);
10002
10128
  }
10003
10129
  this.connectionState = "disconnected";
10004
10130
  if (this.reportEventSourceUnavailable(e)) return;
10005
10131
  this.emitConnectionReset();
10006
- this.scheduleReconnect();
10132
+ this.scheduleReconnect(e);
10007
10133
  });
10008
10134
  } catch (error) {
10009
10135
  if (!this.isWatching || signal?.aborted) return;
10010
- if (!chunkLZAINCGU_cjs.isEventSourceUnavailableError(error)) {
10136
+ if (!chunkSOJDUKY6_cjs.isEventSourceUnavailableError(error)) {
10011
10137
  console.error("ContractWatcher connection failed:", error);
10012
10138
  }
10013
10139
  this.connectionState = "disconnected";
10014
10140
  if (this.reportEventSourceUnavailable(error)) return;
10015
10141
  this.emitConnectionReset();
10016
- this.scheduleReconnect();
10142
+ this.scheduleReconnect(error);
10017
10143
  }
10018
10144
  }
10019
10145
  /**
@@ -10023,7 +10149,7 @@ var ContractWatcher = class {
10023
10149
  * few seconds.
10024
10150
  */
10025
10151
  reportEventSourceUnavailable(error) {
10026
- if (!chunkLZAINCGU_cjs.isEventSourceUnavailableError(error)) return false;
10152
+ if (!chunkSOJDUKY6_cjs.isEventSourceUnavailableError(error)) return false;
10027
10153
  if (!this.eventSourceReported) {
10028
10154
  this.eventSourceReported = true;
10029
10155
  console.warn(
@@ -10032,9 +10158,13 @@ var ContractWatcher = class {
10032
10158
  }
10033
10159
  return true;
10034
10160
  }
10035
- scheduleReconnect() {
10161
+ scheduleReconnect(failure) {
10036
10162
  if (!this.isWatching) return;
10037
10163
  this.cancelSubscriptionRetry();
10164
+ const refused = typeof failure?.status === "number";
10165
+ const wasStable = !refused && this.connectedAt !== void 0 && Date.now() - this.connectedAt >= Math.min(this.config.maxReconnectDelayMs, STABLE_CONNECTION_MS);
10166
+ if (wasStable) this.reconnectAttempts = 0;
10167
+ this.connectedAt = void 0;
10038
10168
  if (this.config.maxReconnectAttempts > 0 && this.reconnectAttempts >= this.config.maxReconnectAttempts) {
10039
10169
  console.error(
10040
10170
  `ContractWatcher: Max reconnection attempts (${this.config.maxReconnectAttempts}) reached`
@@ -10043,15 +10173,27 @@ var ContractWatcher = class {
10043
10173
  }
10044
10174
  this.connectionState = "reconnecting";
10045
10175
  this.reconnectAttempts++;
10046
- const delay = computeReconnectDelay(
10176
+ this.reconnectTimeoutId = setTimeout(() => {
10177
+ this.reconnectTimeoutId = void 0;
10178
+ this.connect();
10179
+ }, this.nextReconnectDelay(failure));
10180
+ }
10181
+ /**
10182
+ * Equal jitter over the exponential backoff, never shorter than a `Retry-After` the server
10183
+ * asked for (clamped like the rate gate's own cooldown, so a bogus header cannot park the
10184
+ * stream). Without jitter the clients one restart dropped all return in the same instant, so
10185
+ * a dominant `Retry-After` is spread over half its own length too.
10186
+ */
10187
+ nextReconnectDelay(failure) {
10188
+ const capped = computeReconnectDelay(
10047
10189
  this.reconnectAttempts,
10048
10190
  this.config.reconnectDelayMs,
10049
10191
  this.config.maxReconnectDelayMs
10050
10192
  );
10051
- this.reconnectTimeoutId = setTimeout(() => {
10052
- this.reconnectTimeoutId = void 0;
10053
- this.connect();
10054
- }, delay);
10193
+ const askedFor = Math.min(chunkSOJDUKY6_cjs.retryAfterMsFromError(failure) ?? 0, chunkSOJDUKY6_cjs.MAX_COOLDOWN_MS);
10194
+ const floor = Math.max(capped / 2, askedFor);
10195
+ const ceiling = Math.max(capped, askedFor * 1.5);
10196
+ return floor + Math.random() * (ceiling - floor);
10055
10197
  }
10056
10198
  /** Replays repository state — only what a sync stored; watch-only scripts poll the indexer. */
10057
10199
  startFailsafePolling() {
@@ -10088,7 +10230,7 @@ var ContractWatcher = class {
10088
10230
  const now = Date.now();
10089
10231
  let current;
10090
10232
  try {
10091
- current = await chunkLZAINCGU_cjs.getAllNormalizedVtxos(this.config.indexerProvider, scripts, {
10233
+ current = await chunkSOJDUKY6_cjs.getAllNormalizedVtxos(this.config.indexerProvider, scripts, {
10092
10234
  spendableOnly: true
10093
10235
  });
10094
10236
  } catch (error) {
@@ -10370,14 +10512,14 @@ var ContractWatcher = class {
10370
10512
  const timestamp = Date.now();
10371
10513
  if (update.newVtxos?.length) {
10372
10514
  this.processSubscriptionVtxos(
10373
- update.newVtxos.map(chunkLZAINCGU_cjs.normalizeVtxo),
10515
+ update.newVtxos.map(chunkSOJDUKY6_cjs.normalizeVtxo),
10374
10516
  "vtxo_received",
10375
10517
  timestamp
10376
10518
  );
10377
10519
  }
10378
10520
  if (update.spentVtxos?.length) {
10379
10521
  this.processSubscriptionVtxos(
10380
- update.spentVtxos.map(chunkLZAINCGU_cjs.normalizeVtxo),
10522
+ update.spentVtxos.map(chunkSOJDUKY6_cjs.normalizeVtxo),
10381
10523
  "vtxo_spent",
10382
10524
  timestamp
10383
10525
  );
@@ -10402,8 +10544,8 @@ var ContractWatcher = class {
10402
10544
  continue;
10403
10545
  }
10404
10546
  if (target === byWatchedScript && eventType === "vtxo_received") {
10405
- const n = chunkLZAINCGU_cjs.normalizeVtxo(vtxo);
10406
- if (chunkLZAINCGU_cjs.isVtxoSpent(n) || n.isSwept || chunkLZAINCGU_cjs.isPastExpiry(n, now)) continue;
10547
+ const n = chunkSOJDUKY6_cjs.normalizeVtxo(vtxo);
10548
+ if (chunkSOJDUKY6_cjs.isVtxoSpent(n) || n.isSwept || chunkSOJDUKY6_cjs.isPastExpiry(n, now)) continue;
10407
10549
  }
10408
10550
  let bucket = target.get(vtxo.script);
10409
10551
  if (!bucket) {
@@ -10591,7 +10733,7 @@ function annotatableIn(scriptToContract, vtxos, memo) {
10591
10733
  if (!contract) continue;
10592
10734
  try {
10593
10735
  const key = contractKey(contract);
10594
- const handler = chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type);
10736
+ const handler = chunkJYQXB7OH_cjs.contractHandlers.get(contract.type);
10595
10737
  const hit = memo?.get(script);
10596
10738
  let tapscripts;
10597
10739
  if (hit && hit.key === key && hit.handler === handler) {
@@ -10612,7 +10754,7 @@ function annotatableIn(scriptToContract, vtxos, memo) {
10612
10754
  scripts.add(script);
10613
10755
  } catch (err) {
10614
10756
  const reason = `'${contract.type}' at ${script}: ${err instanceof Error ? err.message : String(err)}`;
10615
- if (err instanceof chunkJFJNB7ZH_cjs.UnsupportedProgramVersionError) {
10757
+ if (err instanceof chunk5PWL7WOT_cjs.UnsupportedProgramVersionError) {
10616
10758
  unsupported.set(script, { key: contractKey(contract), reason });
10617
10759
  } else {
10618
10760
  failures.set(script, reason);
@@ -10623,7 +10765,7 @@ function annotatableIn(scriptToContract, vtxos, memo) {
10623
10765
  }
10624
10766
  function annotateAgainst(vtxos, byScript, tapscripts = /* @__PURE__ */ new Map()) {
10625
10767
  return vtxos.map(
10626
- (vtxo) => extendVirtualCoinForContract(chunkLZAINCGU_cjs.normalizeVtxo(vtxo), byScript, tapscripts)
10768
+ (vtxo) => extendVirtualCoinForContract(chunkSOJDUKY6_cjs.normalizeVtxo(vtxo), byScript, tapscripts)
10627
10769
  );
10628
10770
  }
10629
10771
  var SCAN_MAX_INDEX = 1e4;
@@ -10672,8 +10814,8 @@ var ContractManager = class _ContractManager {
10672
10814
  /** Serializes onchain read-modify-writes so a pending spender is never overwritten. */
10673
10815
  onchainChain = Promise.resolve();
10674
10816
  constructor(config) {
10675
- chunkLZAINCGU_cjs.assertNonNegativeMs("vtxoSyncMaxAgeMs", config.vtxoSyncMaxAgeMs);
10676
- chunkLZAINCGU_cjs.assertNonNegativeMs("vtxoSyncOverlapMs", config.vtxoSyncOverlapMs);
10817
+ chunkSOJDUKY6_cjs.assertNonNegativeMs("vtxoSyncMaxAgeMs", config.vtxoSyncMaxAgeMs);
10818
+ chunkSOJDUKY6_cjs.assertNonNegativeMs("vtxoSyncOverlapMs", config.vtxoSyncOverlapMs);
10677
10819
  this.config = { ...config };
10678
10820
  if (config.onchainProvider && config.network) {
10679
10821
  this.onchainWatcher = new OnchainContractWatcher({
@@ -10718,12 +10860,12 @@ var ContractManager = class _ContractManager {
10718
10860
  }
10719
10861
  /** @see ContractManagerConfig.vtxoSyncMaxAgeMs — for factory-built managers. */
10720
10862
  setVtxoSyncMaxAge(maxAgeMs) {
10721
- chunkLZAINCGU_cjs.assertNonNegativeMs("vtxoSyncMaxAgeMs", maxAgeMs);
10863
+ chunkSOJDUKY6_cjs.assertNonNegativeMs("vtxoSyncMaxAgeMs", maxAgeMs);
10722
10864
  this.config.vtxoSyncMaxAgeMs = maxAgeMs;
10723
10865
  }
10724
10866
  /** @see ContractManagerConfig.vtxoSyncOverlapMs — for factory-built managers. */
10725
10867
  setVtxoSyncOverlap(overlapMs) {
10726
- chunkLZAINCGU_cjs.assertNonNegativeMs("vtxoSyncOverlapMs", overlapMs);
10868
+ chunkSOJDUKY6_cjs.assertNonNegativeMs("vtxoSyncOverlapMs", overlapMs);
10727
10869
  this.config.vtxoSyncOverlapMs = overlapMs;
10728
10870
  }
10729
10871
  markSyncOnline() {
@@ -10787,10 +10929,10 @@ var ContractManager = class _ContractManager {
10787
10929
  if (this.unsupportedContracts.get(contract.script) === key) return true;
10788
10930
  if (this.tapscriptMemo.get(contract.script)?.key === key) return false;
10789
10931
  try {
10790
- chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type)?.createScript(contract.params);
10932
+ chunkJYQXB7OH_cjs.contractHandlers.get(contract.type)?.createScript(contract.params);
10791
10933
  return false;
10792
10934
  } catch (err) {
10793
- if (!(err instanceof chunkJFJNB7ZH_cjs.UnsupportedProgramVersionError)) return false;
10935
+ if (!(err instanceof chunk5PWL7WOT_cjs.UnsupportedProgramVersionError)) return false;
10794
10936
  this.unsupportedContracts.set(contract.script, key);
10795
10937
  return true;
10796
10938
  }
@@ -10803,7 +10945,7 @@ var ContractManager = class _ContractManager {
10803
10945
  this.markSyncOnline();
10804
10946
  return void 0;
10805
10947
  } catch (err) {
10806
- if (!chunkLZAINCGU_cjs.isRetryableProviderError(err)) throw err;
10948
+ if (!chunkSOJDUKY6_cjs.isRetryableProviderError(err)) throw err;
10807
10949
  this.markSyncDegraded(err);
10808
10950
  return err;
10809
10951
  }
@@ -10826,7 +10968,7 @@ var ContractManager = class _ContractManager {
10826
10968
  try {
10827
10969
  await this.scheduleLookAheadDrain();
10828
10970
  } catch (err) {
10829
- if (!chunkLZAINCGU_cjs.isRetryableProviderError(err)) throw err;
10971
+ if (!chunkSOJDUKY6_cjs.isRetryableProviderError(err)) throw err;
10830
10972
  this.lookAheadRefillOwed = true;
10831
10973
  this.markSyncDegraded(err);
10832
10974
  }
@@ -10889,7 +11031,7 @@ var ContractManager = class _ContractManager {
10889
11031
  /** No throw: construction returned long ago, so the state is the channel. */
10890
11032
  reportBackgroundFailure(stage, err) {
10891
11033
  this.markSyncDegraded(err);
10892
- if (!chunkLZAINCGU_cjs.isRetryableProviderError(err)) {
11034
+ if (!chunkSOJDUKY6_cjs.isRetryableProviderError(err)) {
10893
11035
  console.error(`[contracts] background ${stage} failed`, err);
10894
11036
  }
10895
11037
  }
@@ -10991,7 +11133,7 @@ var ContractManager = class _ContractManager {
10991
11133
  const from = Math.max(0, watermark - lookAhead.size);
10992
11134
  const to = watermark + lookAhead.size;
10993
11135
  const deps = lookAhead.candidateDeps();
10994
- const handlers = chunkNDQ4LB4X_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkNDQ4LB4X_cjs.contractHandlers.get(t)).filter(hasCandidates);
11136
+ const handlers = chunkJYQXB7OH_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkJYQXB7OH_cjs.contractHandlers.get(t)).filter(hasCandidates);
10995
11137
  const band = /* @__PURE__ */ new Map();
10996
11138
  for (let index = from; index <= to; index++) {
10997
11139
  const descriptor = lookAhead.materialize(index);
@@ -11002,7 +11144,7 @@ var ContractManager = class _ContractManager {
11002
11144
  index,
11003
11145
  params: {
11004
11146
  ...candidate,
11005
- ...chunkNDQ4LB4X_cjs.speculativeReceiveMetadata(descriptor)
11147
+ ...chunkJYQXB7OH_cjs.speculativeReceiveMetadata(descriptor)
11006
11148
  }
11007
11149
  });
11008
11150
  }
@@ -11061,7 +11203,7 @@ var ContractManager = class _ContractManager {
11061
11203
  });
11062
11204
  for (const entry of pending) entry.catchUpPending = false;
11063
11205
  } catch (err) {
11064
- if (!chunkLZAINCGU_cjs.isRetryableProviderError(err)) throw err;
11206
+ if (!chunkSOJDUKY6_cjs.isRetryableProviderError(err)) throw err;
11065
11207
  this.markSyncDegraded(err);
11066
11208
  }
11067
11209
  }
@@ -11152,7 +11294,7 @@ var ContractManager = class _ContractManager {
11152
11294
  return result;
11153
11295
  }
11154
11296
  async upsertContractRow(params) {
11155
- const handler = chunkNDQ4LB4X_cjs.contractHandlers.get(params.type);
11297
+ const handler = chunkJYQXB7OH_cjs.contractHandlers.get(params.type);
11156
11298
  if (!handler) {
11157
11299
  throw new Error(`No handler registered for contract type '${params.type}'`);
11158
11300
  }
@@ -11254,7 +11396,7 @@ var ContractManager = class _ContractManager {
11254
11396
  `scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
11255
11397
  );
11256
11398
  }
11257
- const registered = chunkNDQ4LB4X_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkNDQ4LB4X_cjs.contractHandlers.get(t)).filter(isDiscoverable);
11399
+ const registered = chunkJYQXB7OH_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkJYQXB7OH_cjs.contractHandlers.get(t)).filter(isDiscoverable);
11258
11400
  const discoverables = [
11259
11401
  ...registered.filter((h) => h.type === "boarding"),
11260
11402
  ...registered.filter((h) => h.type !== "boarding")
@@ -11385,7 +11527,7 @@ var ContractManager = class _ContractManager {
11385
11527
  return contracts.filter((contract) => this.isUnsupported(contract));
11386
11528
  }
11387
11529
  async getContractsWithVtxos(filter, pageSize, options) {
11388
- chunkLZAINCGU_cjs.assertNonNegativeMs("maxSyncAgeMs", options?.maxSyncAgeMs);
11530
+ chunkSOJDUKY6_cjs.assertNonNegativeMs("maxSyncAgeMs", options?.maxSyncAgeMs);
11389
11531
  const contracts = await this.getContracts(filter);
11390
11532
  if (this.syncedWithin(
11391
11533
  contracts,
@@ -11493,7 +11635,7 @@ var ContractManager = class _ContractManager {
11493
11635
  const byScript = new Map(contracts.map((contract) => [contract.script, contract]));
11494
11636
  const asking = vtxos.filter((vtxo) => {
11495
11637
  const contract = byScript.get(vtxo.script);
11496
- return contract !== void 0 && chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type)?.assertSpendableNow !== void 0;
11638
+ return contract !== void 0 && chunkJYQXB7OH_cjs.contractHandlers.get(contract.type)?.assertSpendableNow !== void 0;
11497
11639
  });
11498
11640
  if (asking.length === 0) return refused;
11499
11641
  const [tip, walletDescriptorValue] = await Promise.all([
@@ -11502,7 +11644,7 @@ var ContractManager = class _ContractManager {
11502
11644
  ]);
11503
11645
  for (const vtxo of asking) {
11504
11646
  const contract = byScript.get(vtxo.script);
11505
- const handler = chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type);
11647
+ const handler = chunkJYQXB7OH_cjs.contractHandlers.get(contract.type);
11506
11648
  if (!handler?.assertSpendableNow) continue;
11507
11649
  const context = {
11508
11650
  collaborative: true,
@@ -11512,7 +11654,7 @@ var ContractManager = class _ContractManager {
11512
11654
  walletDescriptor: walletDescriptorValue,
11513
11655
  // `isVirtualCoin` only checks `script`, which every input has; `isCsvSpendable`
11514
11656
  // reads `vtxo.status.block_time` unguarded, so require `status` too.
11515
- vtxo: chunkLZAINCGU_cjs.isVirtualCoin(vtxo) && "status" in vtxo ? vtxo : void 0
11657
+ vtxo: chunkSOJDUKY6_cjs.isVirtualCoin(vtxo) && "status" in vtxo ? vtxo : void 0
11516
11658
  };
11517
11659
  try {
11518
11660
  await handler.assertSpendableNow(
@@ -11626,7 +11768,7 @@ var ContractManager = class _ContractManager {
11626
11768
  const { contractScript, collaborative = true, walletDescriptor, vtxo } = options;
11627
11769
  const [contract] = await this.getContracts({ script: contractScript });
11628
11770
  if (!contract) return [];
11629
- const handler = chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type);
11771
+ const handler = chunkJYQXB7OH_cjs.contractHandlers.get(contract.type);
11630
11772
  if (!handler) return [];
11631
11773
  const script = handler.createScript(contract.params);
11632
11774
  const tip = await this.currentChainTip();
@@ -11648,7 +11790,7 @@ var ContractManager = class _ContractManager {
11648
11790
  const { contractScript, collaborative = true, walletDescriptor } = options;
11649
11791
  const [contract] = await this.getContracts({ script: contractScript });
11650
11792
  if (!contract) return [];
11651
- const handler = chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type);
11793
+ const handler = chunkJYQXB7OH_cjs.contractHandlers.get(contract.type);
11652
11794
  if (!handler) return [];
11653
11795
  const script = handler.createScript(contract.params);
11654
11796
  const context = {
@@ -11694,7 +11836,7 @@ var ContractManager = class _ContractManager {
11694
11836
  }
11695
11837
  async refreshOutpoints(outpoints) {
11696
11838
  if (outpoints.length === 0) return;
11697
- const { vtxos } = await chunkLZAINCGU_cjs.getNormalizedVtxos(this.config.indexerProvider, {
11839
+ const { vtxos } = await chunkSOJDUKY6_cjs.getNormalizedVtxos(this.config.indexerProvider, {
11698
11840
  outpoints
11699
11841
  });
11700
11842
  if (vtxos.length === 0) return;
@@ -11819,7 +11961,7 @@ var ContractManager = class _ContractManager {
11819
11961
  ...Object.values(pending).map((p) => p.script)
11820
11962
  ]);
11821
11963
  const targets = contracts.filter(
11822
- (c) => chunkNDQ4LB4X_cjs.contractHandlers.has(c.type) && (c.state === "active" && isOnchainScoped(c) || owners.has(c.script))
11964
+ (c) => chunkJYQXB7OH_cjs.contractHandlers.has(c.type) && (c.state === "active" && isOnchainScoped(c) || owners.has(c.script))
11823
11965
  );
11824
11966
  const wanted = scripts && new Set(scripts);
11825
11967
  const settled = [];
@@ -11854,7 +11996,7 @@ var ContractManager = class _ContractManager {
11854
11996
  ).catch((e) => console.warn("[contracts] onchain watch failed", e));
11855
11997
  }
11856
11998
  async syncOnchainContract(contract, onchainProvider, network, pending, tipHeight, prefetched) {
11857
- chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type).createScript(contract.params);
11999
+ chunkJYQXB7OH_cjs.contractHandlers.get(contract.type).createScript(contract.params);
11858
12000
  const coins = prefetched ?? await onchainProvider.getCoins(onchainAddressOf(contract, network));
11859
12001
  const stored = new Map(
11860
12002
  (await getVtxosForContract(this.config.walletRepository, contract)).map((v) => [
@@ -11952,8 +12094,8 @@ var ContractManager = class _ContractManager {
11952
12094
  const found = /* @__PURE__ */ new Map();
11953
12095
  if (!indexerProvider.getUtxos || rows.length === 0) return found;
11954
12096
  try {
11955
- for (let i = 0; i < rows.length; i += chunkLZAINCGU_cjs.OUTPOINT_QUERY_CHUNK_SIZE) {
11956
- const outpoints = rows.slice(i, i + chunkLZAINCGU_cjs.OUTPOINT_QUERY_CHUNK_SIZE).map(({ txid, vout }) => ({ txid, vout }));
12097
+ for (let i = 0; i < rows.length; i += chunkSOJDUKY6_cjs.OUTPOINT_QUERY_CHUNK_SIZE) {
12098
+ const outpoints = rows.slice(i, i + chunkSOJDUKY6_cjs.OUTPOINT_QUERY_CHUNK_SIZE).map(({ txid, vout }) => ({ txid, vout }));
11957
12099
  let pageIndex;
11958
12100
  let pages = 0;
11959
12101
  do {
@@ -11963,7 +12105,7 @@ var ContractManager = class _ContractManager {
11963
12105
  const { utxos, page } = await indexerProvider.getUtxos({
11964
12106
  outpoints,
11965
12107
  pageIndex,
11966
- pageSize: chunkLZAINCGU_cjs.OUTPOINT_QUERY_CHUNK_SIZE
12108
+ pageSize: chunkSOJDUKY6_cjs.OUTPOINT_QUERY_CHUNK_SIZE
11967
12109
  });
11968
12110
  for (const utxo of utxos) found.set(vtxoOutpoint(utxo), utxo);
11969
12111
  const more = page && page.current < page.total && page.next > page.current;
@@ -11971,7 +12113,7 @@ var ContractManager = class _ContractManager {
11971
12113
  } while (pageIndex !== void 0);
11972
12114
  }
11973
12115
  } catch (e) {
11974
- if (e instanceof chunkHKEPJBTY_cjs.IndexerUtxosUnsupportedError) return found;
12116
+ if (e instanceof chunk4IDCSOP2_cjs.IndexerUtxosUnsupportedError) return found;
11975
12117
  console.warn("[contracts] arkd spend lookup failed; using the explorer", e);
11976
12118
  return void 0;
11977
12119
  }
@@ -12024,7 +12166,7 @@ var ContractManager = class _ContractManager {
12024
12166
  break;
12025
12167
  }
12026
12168
  } catch (err) {
12027
- if (!chunkLZAINCGU_cjs.isRetryableProviderError(err)) throw err;
12169
+ if (!chunkSOJDUKY6_cjs.isRetryableProviderError(err)) throw err;
12028
12170
  this.markSyncDegraded(err);
12029
12171
  synced = false;
12030
12172
  }
@@ -12112,7 +12254,7 @@ var ContractManager = class _ContractManager {
12112
12254
  */
12113
12255
  async reconcilePendingFrontier(contracts) {
12114
12256
  const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
12115
- const vtxos = await chunkLZAINCGU_cjs.getAllNormalizedVtxos(
12257
+ const vtxos = await chunkSOJDUKY6_cjs.getAllNormalizedVtxos(
12116
12258
  this.config.indexerProvider,
12117
12259
  contracts.map((c) => c.script),
12118
12260
  { pendingOnly: true }
@@ -12187,7 +12329,7 @@ var ContractManager = class _ContractManager {
12187
12329
  }
12188
12330
  return result;
12189
12331
  }
12190
- async fetchContractVtxosBulk(contracts, pageSize = chunkLZAINCGU_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
12332
+ async fetchContractVtxosBulk(contracts, pageSize = chunkSOJDUKY6_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
12191
12333
  if (contracts.length === 0) {
12192
12334
  return { vtxosByScript: /* @__PURE__ */ new Map(), promoted: /* @__PURE__ */ new Map() };
12193
12335
  }
@@ -12203,7 +12345,7 @@ var ContractManager = class _ContractManager {
12203
12345
  before: syncWindow.before
12204
12346
  }
12205
12347
  } : {};
12206
- const vtxos = await chunkLZAINCGU_cjs.getAllNormalizedVtxos(
12348
+ const vtxos = await chunkSOJDUKY6_cjs.getAllNormalizedVtxos(
12207
12349
  this.config.indexerProvider,
12208
12350
  contracts.map((c) => c.script),
12209
12351
  { ...windowOpts, pageSize }
@@ -12310,7 +12452,7 @@ function parseLegacyExpiry(batchExpiry) {
12310
12452
  if (typeof batchExpiry !== "number" || !Number.isFinite(batchExpiry) || batchExpiry <= 0) {
12311
12453
  return {};
12312
12454
  }
12313
- if (batchExpiry >= chunkLZAINCGU_cjs.EXPIRY_MIN_PLAUSIBLE_MS) return { expiresAt: new Date(batchExpiry) };
12455
+ if (batchExpiry >= chunkSOJDUKY6_cjs.EXPIRY_MIN_PLAUSIBLE_MS) return { expiresAt: new Date(batchExpiry) };
12314
12456
  return { expiresAtHeight: batchExpiry / 1e3 };
12315
12457
  }
12316
12458
  function legacyVtxoFacts(status) {
@@ -12548,7 +12690,7 @@ function backfillContractWatchState(store) {
12548
12690
  };
12549
12691
  readPage();
12550
12692
  }
12551
- var unspentFlag = (vtxo) => chunkLZAINCGU_cjs.isVtxoSpent(vtxo) ? {} : { unspent: 1 };
12693
+ var unspentFlag = (vtxo) => chunkSOJDUKY6_cjs.isVtxoSpent(vtxo) ? {} : { unspent: 1 };
12552
12694
  function backfillVtxoIndexFields(transaction) {
12553
12695
  const store = transaction.objectStore(STORE_VTXOS);
12554
12696
  const pageSize = 1e3;
@@ -12579,7 +12721,7 @@ var DEFAULT_DB_NAME = "arkade-service-worker";
12579
12721
  var DEFAULT_SERVICE_WORKER_ACTIVATION_TIMEOUT_MS = 1e4;
12580
12722
  function normalizeOptions2(pathOrOptions) {
12581
12723
  const o = typeof pathOrOptions === "string" ? { path: pathOrOptions } : pathOrOptions;
12582
- chunkLZAINCGU_cjs.assertTimerMs("activationTimeoutMs", o.activationTimeoutMs);
12724
+ chunkSOJDUKY6_cjs.assertTimerMs("activationTimeoutMs", o.activationTimeoutMs);
12583
12725
  return {
12584
12726
  path: o.path,
12585
12727
  activationTimeoutMs: o.activationTimeoutMs ?? DEFAULT_SERVICE_WORKER_ACTIVATION_TIMEOUT_MS
@@ -12807,7 +12949,7 @@ var deserializeTapLeaf = (t) => {
12807
12949
  var deserializeVtxo = ({
12808
12950
  intentTapLeafScript,
12809
12951
  ...o
12810
- }) => chunkLZAINCGU_cjs.normalizeVtxo({
12952
+ }) => chunkSOJDUKY6_cjs.normalizeVtxo({
12811
12953
  ...o,
12812
12954
  createdAt: new Date(o.createdAt),
12813
12955
  tapTree: base.hex.decode(o.tapTree),
@@ -13207,7 +13349,7 @@ var RestEmulatorProvider = class {
13207
13349
  serverUrl;
13208
13350
  async getInfo() {
13209
13351
  const url = `${this.serverUrl}/v1/info`;
13210
- const response = await chunkLZAINCGU_cjs.baseFetch(url);
13352
+ const response = await chunkSOJDUKY6_cjs.baseFetch(url);
13211
13353
  if (!response.ok) {
13212
13354
  const errorText2 = await response.text();
13213
13355
  throw new Error(`Failed to get emulator info: ${errorText2}`);
@@ -13331,7 +13473,7 @@ function arkadeServiceUrl(service) {
13331
13473
  }
13332
13474
  async function resolveArkadeService(service, opts = {}) {
13333
13475
  const operatorUrl = arkadeServiceUrl(service);
13334
- const arkProvider = opts.arkProvider ?? new chunkLZAINCGU_cjs.RestOperatorProvider(operatorUrl);
13476
+ const arkProvider = opts.arkProvider ?? new chunkSOJDUKY6_cjs.RestOperatorProvider(operatorUrl);
13335
13477
  const info = opts.info ?? await arkProvider.getInfo();
13336
13478
  if ("network" in service && service.network !== info.network) {
13337
13479
  throw new Error(
@@ -13350,7 +13492,7 @@ async function resolveArkadeService(service, opts = {}) {
13350
13492
  }
13351
13493
  return {
13352
13494
  arkProvider,
13353
- indexerProvider: new chunkHKEPJBTY_cjs.RestIndexerProvider(operatorUrl),
13495
+ indexerProvider: new chunk4IDCSOP2_cjs.RestIndexerProvider(operatorUrl),
13354
13496
  onchainProvider: new EsploraProvider(esploraUrl),
13355
13497
  emulator,
13356
13498
  info
@@ -13434,7 +13576,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
13434
13576
  */
13435
13577
  materializeDescriptorAt(index) {
13436
13578
  const descriptor = this.identity.descriptor;
13437
- const network = chunkNDQ4LB4X_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
13579
+ const network = chunkJYQXB7OH_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
13438
13580
  const expansion = descriptorsScure.expand({ descriptor, network, index });
13439
13581
  const keyInfo = expansion.expansionMap?.["@0"];
13440
13582
  if (!keyInfo?.keyExpression) {
@@ -13502,7 +13644,7 @@ function signingDescriptorIndex(descriptor) {
13502
13644
  }
13503
13645
  function newestWalletReceiveContract(contracts, serverPubKeyHex) {
13504
13646
  return contracts.filter(
13505
- (c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkNDQ4LB4X_cjs.WALLET_RECEIVE_SOURCE
13647
+ (c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkJYQXB7OH_cjs.WALLET_RECEIVE_SOURCE
13506
13648
  ).sort((a, b) => {
13507
13649
  if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
13508
13650
  return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
@@ -13553,7 +13695,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
13553
13695
  const provider = await resolveDescriptorProvider(config, setup.walletRepository);
13554
13696
  if (!provider) return void 0;
13555
13697
  const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
13556
- const expectedContractType = setup.offchainTapscript instanceof chunkNDQ4LB4X_cjs.DelegateVtxo.Script ? "delegate" : "default";
13698
+ const expectedContractType = setup.offchainTapscript instanceof chunkJYQXB7OH_cjs.DelegateVtxo.Script ? "delegate" : "default";
13557
13699
  const factoryOpts = {
13558
13700
  walletRepository: setup.walletRepository,
13559
13701
  contractRepository: setup.contractRepository,
@@ -13713,7 +13855,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
13713
13855
  };
13714
13856
  function deriveLeafPubkey(descriptor) {
13715
13857
  try {
13716
- return chunkNDQ4LB4X_cjs.deriveDescriptorLeafPubKey(descriptor);
13858
+ return chunkJYQXB7OH_cjs.deriveDescriptorLeafPubKey(descriptor);
13717
13859
  } catch (e) {
13718
13860
  throw new NonRangeableDescriptorError(
13719
13861
  "Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
@@ -13733,11 +13875,11 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
13733
13875
  // Read at sign time to route rotated-pubkey inputs through `signWithDescriptor`; without
13734
13876
  // it spends are rejected with `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
13735
13877
  metadata: {
13736
- ...tagSource && { source: chunkNDQ4LB4X_cjs.WALLET_RECEIVE_SOURCE },
13878
+ ...tagSource && { source: chunkJYQXB7OH_cjs.WALLET_RECEIVE_SOURCE },
13737
13879
  signingDescriptor: descriptor
13738
13880
  }
13739
13881
  };
13740
- const params = tapscript instanceof chunkNDQ4LB4X_cjs.DelegateVtxo.Script ? {
13882
+ const params = tapscript instanceof chunkJYQXB7OH_cjs.DelegateVtxo.Script ? {
13741
13883
  ...base$1,
13742
13884
  type: "delegate",
13743
13885
  params: {
@@ -13758,10 +13900,10 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
13758
13900
  return { tapscript, params };
13759
13901
  }
13760
13902
  function rebuildTapscript(current, pubKey) {
13761
- if (current instanceof chunkNDQ4LB4X_cjs.DelegateVtxo.Script) {
13762
- return new chunkNDQ4LB4X_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
13903
+ if (current instanceof chunkJYQXB7OH_cjs.DelegateVtxo.Script) {
13904
+ return new chunkJYQXB7OH_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
13763
13905
  }
13764
- return new chunkNDQ4LB4X_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
13906
+ return new chunkJYQXB7OH_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
13765
13907
  }
13766
13908
  async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
13767
13909
  const candidates = await collectContracts(contractRepository, {
@@ -13814,7 +13956,7 @@ async function resolvePrevTxs(txids, source, onchain) {
13814
13956
  try {
13815
13957
  const { txs } = await source.getVirtualTxs(wanted);
13816
13958
  for (const psbt of txs) {
13817
- const tx = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(psbt));
13959
+ const tx = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(psbt));
13818
13960
  resolved.set(tx.id, tx.toBytes());
13819
13961
  }
13820
13962
  } catch (err) {
@@ -13847,7 +13989,7 @@ async function resolvePrevTxs(txids, source, onchain) {
13847
13989
  async function attachPrevArkTxs(tx, txids, source, onchain) {
13848
13990
  const pending = [];
13849
13991
  for (let i = 0; i < tx.inputsLength; i++) {
13850
- if (chunkLZAINCGU_cjs.getArkPsbtFields(tx, i, chunkLZAINCGU_cjs.PrevArkTxField).length === 0) pending.push(i);
13992
+ if (chunkSOJDUKY6_cjs.getArkPsbtFields(tx, i, chunkSOJDUKY6_cjs.PrevArkTxField).length === 0) pending.push(i);
13851
13993
  }
13852
13994
  if (pending.length === 0) return;
13853
13995
  const resolved = await resolvePrevTxs(
@@ -13856,13 +13998,13 @@ async function attachPrevArkTxs(tx, txids, source, onchain) {
13856
13998
  onchain
13857
13999
  );
13858
14000
  for (const i of pending) {
13859
- chunkLZAINCGU_cjs.setArkPsbtField(tx, i, chunkLZAINCGU_cjs.PrevArkTxField, resolved.get(txidAt(txids, i)));
14001
+ chunkSOJDUKY6_cjs.setArkPsbtField(tx, i, chunkSOJDUKY6_cjs.PrevArkTxField, resolved.get(txidAt(txids, i)));
13860
14002
  }
13861
14003
  }
13862
14004
  async function attachPrevoutTxs(tx, source) {
13863
14005
  const pending = [];
13864
14006
  for (let i = 0; i < tx.inputsLength; i++) {
13865
- if (chunkLZAINCGU_cjs.getArkPsbtFields(tx, i, chunkLZAINCGU_cjs.PrevoutTxField).length > 0) continue;
14007
+ if (chunkSOJDUKY6_cjs.getArkPsbtFields(tx, i, chunkSOJDUKY6_cjs.PrevoutTxField).length > 0) continue;
13866
14008
  const input = tx.getInput(i);
13867
14009
  if (!input?.txid) throw new PrevTxUnavailableError(`input ${i} has no outpoint`);
13868
14010
  pending.push({ index: i, txid: base.hex.encode(input.txid) });
@@ -13877,7 +14019,7 @@ async function attachPrevoutTxs(tx, source) {
13877
14019
  resolved.set(txids[i], result.value);
13878
14020
  }
13879
14021
  for (const { index, txid } of pending) {
13880
- chunkLZAINCGU_cjs.setArkPsbtField(tx, index, chunkLZAINCGU_cjs.PrevoutTxField, resolved.get(txid));
14022
+ chunkSOJDUKY6_cjs.setArkPsbtField(tx, index, chunkSOJDUKY6_cjs.PrevoutTxField, resolved.get(txid));
13881
14023
  }
13882
14024
  }
13883
14025
  async function withPrevTxs(coins, source, onchain) {
@@ -13918,7 +14060,7 @@ function computeOffchainBalance(vtxos, caps) {
13918
14060
  }
13919
14061
  };
13920
14062
  for (const vtxo of vtxos) {
13921
- if (chunkLZAINCGU_cjs.isVtxoSpent(vtxo)) continue;
14063
+ if (chunkSOJDUKY6_cjs.isVtxoSpent(vtxo)) continue;
13922
14064
  addAssets(owned, vtxo);
13923
14065
  if (vtxo.isUnrolled) {
13924
14066
  unrolled += vtxo.value;
@@ -13928,11 +14070,11 @@ function computeOffchainBalance(vtxos, caps) {
13928
14070
  deprecatedSignerLocked += vtxo.value;
13929
14071
  continue;
13930
14072
  }
13931
- if (chunkLZAINCGU_cjs.canRecoverOnchain(vtxo, now)) {
14073
+ if (chunkSOJDUKY6_cjs.canRecoverOnchain(vtxo, now)) {
13932
14074
  recoverable += vtxo.value;
13933
14075
  continue;
13934
14076
  }
13935
- if (!chunkLZAINCGU_cjs.canSpendOffchain(vtxo, now)) continue;
14077
+ if (!chunkSOJDUKY6_cjs.canSpendOffchain(vtxo, now)) continue;
13936
14078
  if (vtxo.isPreconfirmed) {
13937
14079
  preconfirmed += vtxo.value;
13938
14080
  } else {
@@ -14207,7 +14349,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
14207
14349
  if (!newest?.params.pubKey) return baseline;
14208
14350
  try {
14209
14351
  const pubKey = base.hex.decode(newest.params.pubKey);
14210
- return new chunkNDQ4LB4X_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
14352
+ return new chunkJYQXB7OH_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
14211
14353
  } catch (e) {
14212
14354
  console.warn("Skipping malformed boarding contract at boot", newest.script, e);
14213
14355
  return baseline;
@@ -14239,21 +14381,21 @@ function filterFlatVtxos(vtxos, filter, pendingSpendOutpoints) {
14239
14381
  if (vtxo.isUnrolled) {
14240
14382
  return !!f.withUnrolled;
14241
14383
  }
14242
- if (chunkLZAINCGU_cjs.isVtxoSpent(vtxo)) {
14384
+ if (chunkSOJDUKY6_cjs.isVtxoSpent(vtxo)) {
14243
14385
  return false;
14244
14386
  }
14245
- if (!f.withRecoverable && chunkLZAINCGU_cjs.canRecoverOnchain(vtxo, now)) {
14387
+ if (!f.withRecoverable && chunkSOJDUKY6_cjs.canRecoverOnchain(vtxo, now)) {
14246
14388
  return false;
14247
14389
  }
14248
14390
  return true;
14249
14391
  });
14250
14392
  }
14251
14393
  async function refreshSweptStateOfExpiredInputs(wallet, inputs) {
14252
- const candidates = inputs.filter(chunkLZAINCGU_cjs.isVirtualCoin).map(chunkLZAINCGU_cjs.normalizeVtxo).filter((v) => !v.isSwept);
14394
+ const candidates = inputs.filter(chunkSOJDUKY6_cjs.isVirtualCoin).map(chunkSOJDUKY6_cjs.normalizeVtxo).filter((v) => !v.isSwept);
14253
14395
  if (candidates.length === 0) return inputs;
14254
- const now = candidates.some((v) => v.expiresAtHeight !== void 0) ? await chunkLZAINCGU_cjs.resolveTimeHeight(wallet.onchainProvider) : { timestamp: /* @__PURE__ */ new Date() };
14396
+ const now = candidates.some((v) => v.expiresAtHeight !== void 0) ? await chunkSOJDUKY6_cjs.resolveTimeHeight(wallet.onchainProvider) : { timestamp: /* @__PURE__ */ new Date() };
14255
14397
  const suspects = candidates.filter(
14256
- (v) => chunkLZAINCGU_cjs.isPastExpiry(v, now) || v.expiresAtHeight !== void 0 && now.height === void 0
14398
+ (v) => chunkSOJDUKY6_cjs.isPastExpiry(v, now) || v.expiresAtHeight !== void 0 && now.height === void 0
14257
14399
  );
14258
14400
  if (suspects.length === 0) return inputs;
14259
14401
  let sweptNow;
@@ -14267,12 +14409,12 @@ async function refreshSweptStateOfExpiredInputs(wallet, inputs) {
14267
14409
  );
14268
14410
  } catch (e) {
14269
14411
  const message = "could not confirm the swept state of expired settlement inputs; retry the settlement";
14270
- throw chunkLZAINCGU_cjs.isRetryableProviderError(e) ? new chunkLZAINCGU_cjs.ProviderUnavailableError(message, { cause: e }) : new Error(message, { cause: e });
14412
+ throw chunkSOJDUKY6_cjs.isRetryableProviderError(e) ? new chunkSOJDUKY6_cjs.ProviderUnavailableError(message, { cause: e }) : new Error(message, { cause: e });
14271
14413
  }
14272
14414
  if (sweptNow.size === 0) return inputs;
14273
14415
  return inputs.map((input) => {
14274
- if (!chunkLZAINCGU_cjs.isVirtualCoin(input) || !sweptNow.has(`${input.txid}:${input.vout}`)) return input;
14275
- return { ...chunkLZAINCGU_cjs.normalizeVtxo(input), isSwept: true };
14416
+ if (!chunkSOJDUKY6_cjs.isVirtualCoin(input) || !sweptNow.has(`${input.txid}:${input.vout}`)) return input;
14417
+ return { ...chunkSOJDUKY6_cjs.normalizeVtxo(input), isSwept: true };
14276
14418
  });
14277
14419
  }
14278
14420
  var PENDING_RECOVERY_REASON = "is past its operator signer's rotation cutoff \u2014 the operator will not co-sign it until it recovers";
@@ -14571,7 +14713,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
14571
14713
  async getArkadeReader() {
14572
14714
  const indexer = this.indexerProvider;
14573
14715
  return {
14574
- getVtxos: (opts) => chunkLZAINCGU_cjs.getNormalizedVtxos(indexer, opts),
14716
+ getVtxos: (opts) => chunkSOJDUKY6_cjs.getNormalizedVtxos(indexer, opts),
14575
14717
  getVirtualTxs: (txids, opts) => indexer.getVirtualTxs(txids, opts)
14576
14718
  };
14577
14719
  }
@@ -14621,7 +14763,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
14621
14763
  "Pass either `service` or `operatorProvider`/`indexerProvider`/`onchainProvider`, not both"
14622
14764
  );
14623
14765
  }
14624
- const arkProvider = callerProvider || new chunkLZAINCGU_cjs.RestOperatorProvider(config.service ? arkadeServiceUrl(config.service) : void 0);
14766
+ const arkProvider = callerProvider || new chunkSOJDUKY6_cjs.RestOperatorProvider(config.service ? arkadeServiceUrl(config.service) : void 0);
14625
14767
  let indexerProvider = config.indexerProvider;
14626
14768
  if (!indexerProvider && !config.service) {
14627
14769
  const derived = extractOperatorProviderUrl(arkProvider);
@@ -14630,11 +14772,11 @@ var ReadonlyWallet = class _ReadonlyWallet {
14630
14772
  "indexerProvider is required when operatorProvider is provided without a discoverable serverUrl"
14631
14773
  );
14632
14774
  }
14633
- indexerProvider = new chunkHKEPJBTY_cjs.RestIndexerProvider(derived ?? chunkFLPWNMX3_cjs.DEFAULT_ARKADE_SERVER_URL);
14775
+ indexerProvider = new chunk4IDCSOP2_cjs.RestIndexerProvider(derived ?? chunkFLPWNMX3_cjs.DEFAULT_ARKADE_SERVER_URL);
14634
14776
  }
14635
14777
  const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
14636
14778
  const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
14637
- const delegatePubKeyPromise = config.delegateProvider?.getDelegateInfo().then((info2) => chunkJFJNB7ZH_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0);
14779
+ const delegatePubKeyPromise = config.delegateProvider?.getDelegateInfo().then((info2) => chunk5PWL7WOT_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0);
14638
14780
  const {
14639
14781
  info,
14640
14782
  source: serverInfoSource,
@@ -14681,15 +14823,15 @@ var ReadonlyWallet = class _ReadonlyWallet {
14681
14823
  }
14682
14824
  }
14683
14825
  const boardingTimelock = config.boardingTimelock ?? toTimelock(info.boardingExitDelay);
14684
- const serverPubKey = chunkJFJNB7ZH_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
14826
+ const serverPubKey = chunk5PWL7WOT_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
14685
14827
  const delegatePubKey = await delegatePubKeyPromise;
14686
14828
  const offchainOptions = {
14687
14829
  pubKey,
14688
14830
  serverPubKey,
14689
14831
  csvTimelock: exitTimelock
14690
14832
  };
14691
- const offchainTapscript = !delegatePubKey ? new chunkNDQ4LB4X_cjs.DefaultVtxo.Script(offchainOptions) : new chunkNDQ4LB4X_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
14692
- const boardingTapscript = chunkNDQ4LB4X_cjs.BoardingContractHandler.createScript({
14833
+ const offchainTapscript = !delegatePubKey ? new chunkJYQXB7OH_cjs.DefaultVtxo.Script(offchainOptions) : new chunkJYQXB7OH_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
14834
+ const boardingTapscript = chunkJYQXB7OH_cjs.BoardingContractHandler.createScript({
14693
14835
  pubKey: base.hex.encode(pubKey),
14694
14836
  serverPubKey: base.hex.encode(serverPubKey),
14695
14837
  csvTimelock: chunkFLPWNMX3_cjs.timelockToSequence(boardingTimelock).toString()
@@ -14858,7 +15000,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
14858
15000
  if (!filter?.withUnrolled) {
14859
15001
  logExcludedVtxos(
14860
15002
  "getSpendableVtxos",
14861
- snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !chunkLZAINCGU_cjs.isVtxoSpent(vtxo)),
15003
+ snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !chunkSOJDUKY6_cjs.isVtxoSpent(vtxo)),
14862
15004
  [() => UNROLLED_REASON]
14863
15005
  );
14864
15006
  }
@@ -14998,12 +15140,13 @@ var ReadonlyWallet = class _ReadonlyWallet {
14998
15140
  * Return wallet transaction history derived from Arkade state and boarding transactions.
14999
15141
  */
15000
15142
  async getTransactionHistory() {
15001
- const [snapshot, { boardingTxs, commitmentsToIgnore }] = await Promise.all([
15143
+ const [fullSnapshot, { boardingTxs, commitmentsToIgnore }] = await Promise.all([
15002
15144
  this.contractSnapshot(),
15003
15145
  this.getBoardingTxs()
15004
15146
  ]);
15147
+ const snapshot = fullSnapshot.filter(({ contract }) => !isRecoveryOnlyContract(contract));
15005
15148
  const allVtxos = snapshot.flatMap((_) => _.vtxos);
15006
- const resolveTxCreatedAt = (txids) => chunkLZAINCGU_cjs.fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
15149
+ const resolveTxCreatedAt = (txids) => chunkSOJDUKY6_cjs.fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
15007
15150
  return buildTransactionHistory(
15008
15151
  allVtxos,
15009
15152
  boardingTxs,
@@ -15203,11 +15346,11 @@ var ReadonlyWallet = class _ReadonlyWallet {
15203
15346
  const currentServerPubKey = this.boardingTapscript.options.serverPubKey;
15204
15347
  const currentServerSigner = toXOnlySignerHex(base.hex.encode(currentServerPubKey));
15205
15348
  const signers = /* @__PURE__ */ new Set([currentServerSigner, ...allowedSigners ?? []]);
15206
- const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkNDQ4LB4X_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
15349
+ const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkJYQXB7OH_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
15207
15350
  const baselinePubkey = await this.identity.xOnlyPublicKey();
15208
15351
  for (const signer of signers) {
15209
15352
  add(
15210
- new chunkNDQ4LB4X_cjs.DefaultVtxo.Script({
15353
+ new chunkJYQXB7OH_cjs.DefaultVtxo.Script({
15211
15354
  pubKey: baselinePubkey,
15212
15355
  serverPubKey: base.hex.decode(signer),
15213
15356
  csvTimelock: boardingCsv
@@ -15228,7 +15371,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
15228
15371
  continue;
15229
15372
  }
15230
15373
  add(
15231
- c.type === "default" ? chunkNDQ4LB4X_cjs.DefaultContractHandler.createScript(c.params) : chunkNDQ4LB4X_cjs.BoardingContractHandler.createScript(c.params)
15374
+ c.type === "default" ? chunkJYQXB7OH_cjs.DefaultContractHandler.createScript(c.params) : chunkJYQXB7OH_cjs.BoardingContractHandler.createScript(c.params)
15232
15375
  );
15233
15376
  } catch (e) {
15234
15377
  console.warn("Skipping malformed boarding contract", c.script, e);
@@ -15277,7 +15420,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
15277
15420
  tapscripts.map(async (tapscript, i) => {
15278
15421
  const contract = contracts.get(scripts[i]);
15279
15422
  const spent = new Set(
15280
- contract ? (await getVtxosForContract(this.walletRepository, contract)).filter(chunkLZAINCGU_cjs.isVtxoSpent).map(vtxoOutpoint) : []
15423
+ contract ? (await getVtxosForContract(this.walletRepository, contract)).filter(chunkSOJDUKY6_cjs.isVtxoSpent).map(vtxoOutpoint) : []
15281
15424
  );
15282
15425
  const utxos = fetched[i].filter((c) => !spent.has(vtxoOutpoint(c))).map((utxo) => extendCoinWithTapscript(tapscript, utxo));
15283
15426
  return {
@@ -15306,10 +15449,10 @@ var ReadonlyWallet = class _ReadonlyWallet {
15306
15449
  timer = setTimeout(
15307
15450
  () => reject(
15308
15451
  new Error(
15309
- `Boarding address lookup timed out after ${chunkLZAINCGU_cjs.READ_TIMEOUT_MS}ms`
15452
+ `Boarding address lookup timed out after ${chunkSOJDUKY6_cjs.READ_TIMEOUT_MS}ms`
15310
15453
  )
15311
15454
  ),
15312
- chunkLZAINCGU_cjs.READ_TIMEOUT_MS
15455
+ chunkSOJDUKY6_cjs.READ_TIMEOUT_MS
15313
15456
  );
15314
15457
  })
15315
15458
  ]);
@@ -15495,7 +15638,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
15495
15638
  /** Fetch Arkade transaction ids that are still pending final settlement. */
15496
15639
  async fetchPendingTxs() {
15497
15640
  const scripts = await this.getWalletScripts();
15498
- const vtxos = await chunkLZAINCGU_cjs.getAllNormalizedVtxos(this.indexerProvider, scripts);
15641
+ const vtxos = await chunkSOJDUKY6_cjs.getAllNormalizedVtxos(this.indexerProvider, scripts);
15499
15642
  return vtxos.filter(
15500
15643
  (vtxo) => (vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept) && vtxo.arkTxId !== void 0
15501
15644
  ).map((_) => _.arkTxId);
@@ -15526,7 +15669,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
15526
15669
  });
15527
15670
  for (const contract of contracts) {
15528
15671
  if (map.has(contract.script)) continue;
15529
- const handler = chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type);
15672
+ const handler = chunkJYQXB7OH_cjs.contractHandlers.get(contract.type);
15530
15673
  if (handler) {
15531
15674
  const script = handler.createScript(contract.params);
15532
15675
  map.set(contract.script, script);
@@ -15645,7 +15788,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
15645
15788
  });
15646
15789
  try {
15647
15790
  const baselinePubkey = await baselinePubkeyPromise;
15648
- const delegatePubKey = this.offchainTapscript instanceof chunkNDQ4LB4X_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
15791
+ const delegatePubKey = this.offchainTapscript instanceof chunkJYQXB7OH_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
15649
15792
  const baselineSigners = [
15650
15793
  this.offchainTapscript.options.serverPubKey,
15651
15794
  ...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
@@ -15655,7 +15798,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
15655
15798
  for (const serverPubKey of baselineSigners) {
15656
15799
  for (const csvTimelock of this.walletContractTimelocks) {
15657
15800
  const csvTimelockStr = chunkFLPWNMX3_cjs.timelockToSequence(csvTimelock).toString();
15658
- const defaultScript = new chunkNDQ4LB4X_cjs.DefaultVtxo.Script({
15801
+ const defaultScript = new chunkJYQXB7OH_cjs.DefaultVtxo.Script({
15659
15802
  pubKey: baselinePubkey,
15660
15803
  serverPubKey,
15661
15804
  csvTimelock
@@ -15676,7 +15819,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
15676
15819
  });
15677
15820
  }
15678
15821
  if (delegatePubKey) {
15679
- const delegateScript = new chunkNDQ4LB4X_cjs.DelegateVtxo.Script({
15822
+ const delegateScript = new chunkJYQXB7OH_cjs.DelegateVtxo.Script({
15680
15823
  pubKey: baselinePubkey,
15681
15824
  serverPubKey,
15682
15825
  delegatePubKey,
@@ -15700,9 +15843,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
15700
15843
  }
15701
15844
  }
15702
15845
  }
15703
- const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkNDQ4LB4X_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
15846
+ const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkJYQXB7OH_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
15704
15847
  for (const serverPubKey of baselineSigners) {
15705
- const baselineBoarding = new chunkNDQ4LB4X_cjs.DefaultVtxo.Script({
15848
+ const baselineBoarding = new chunkJYQXB7OH_cjs.DefaultVtxo.Script({
15706
15849
  pubKey: baselinePubkey,
15707
15850
  serverPubKey,
15708
15851
  csvTimelock: boardingCsvTimelock
@@ -15919,7 +16062,7 @@ var Wallet2 = class extends ReadonlyWallet {
15919
16062
  serverPubKey: this.offchainTapscript.options.serverPubKey,
15920
16063
  deprecatedSignerPubKeys: [...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h)),
15921
16064
  csvTimelocks: this.walletContractTimelocks,
15922
- delegatePubKey: this.offchainTapscript instanceof chunkNDQ4LB4X_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0
16065
+ delegatePubKey: this.offchainTapscript instanceof chunkJYQXB7OH_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0
15923
16066
  };
15924
16067
  }
15925
16068
  _signerRouter;
@@ -16081,7 +16224,7 @@ var Wallet2 = class extends ReadonlyWallet {
16081
16224
  const [row] = await manager.getContracts({ script: base.hex.encode(display.pkScript) });
16082
16225
  const persisted = row?.metadata?.signingDescriptor;
16083
16226
  if (typeof persisted === "string") return persisted;
16084
- return chunkNDQ4LB4X_cjs.identityDescriptor(this.identity);
16227
+ return chunkJYQXB7OH_cjs.identityDescriptor(this.identity);
16085
16228
  }
16086
16229
  /**
16087
16230
  * Build, persist and shape one address of `type` owned by `descriptor`. The descriptor is the
@@ -16091,7 +16234,7 @@ var Wallet2 = class extends ReadonlyWallet {
16091
16234
  async mintAddress(manager, type, descriptor, tagSource, allocated) {
16092
16235
  if (type === "boarding") {
16093
16236
  const built2 = this.buildBoardingContract(
16094
- chunkNDQ4LB4X_cjs.deriveDescriptorLeafPubKey(descriptor),
16237
+ chunkJYQXB7OH_cjs.deriveDescriptorLeafPubKey(descriptor),
16095
16238
  descriptor,
16096
16239
  tagSource
16097
16240
  );
@@ -16128,11 +16271,11 @@ var Wallet2 = class extends ReadonlyWallet {
16128
16271
  * (offchain analogue: {@link buildReceiveContract}).
16129
16272
  */
16130
16273
  buildBoardingContract(pubKey, descriptor, tagSource) {
16131
- const tapscript = new chunkNDQ4LB4X_cjs.DefaultVtxo.Script({
16274
+ const tapscript = new chunkJYQXB7OH_cjs.DefaultVtxo.Script({
16132
16275
  ...this._boardingTapscript.options,
16133
16276
  pubKey
16134
16277
  });
16135
- const csvTimelock = tapscript.options.csvTimelock ?? chunkNDQ4LB4X_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
16278
+ const csvTimelock = tapscript.options.csvTimelock ?? chunkJYQXB7OH_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
16136
16279
  return {
16137
16280
  tapscript,
16138
16281
  params: {
@@ -16146,7 +16289,7 @@ var Wallet2 = class extends ReadonlyWallet {
16146
16289
  address: tapscript.address(this.network.hrp, this.arkServerPublicKey).encode(),
16147
16290
  state: "active",
16148
16291
  metadata: {
16149
- ...tagSource && { source: chunkNDQ4LB4X_cjs.WALLET_RECEIVE_SOURCE },
16292
+ ...tagSource && { source: chunkJYQXB7OH_cjs.WALLET_RECEIVE_SOURCE },
16150
16293
  signingDescriptor: descriptor
16151
16294
  }
16152
16295
  }
@@ -16168,7 +16311,7 @@ var Wallet2 = class extends ReadonlyWallet {
16168
16311
  if (this._hdProvider) {
16169
16312
  return (await this.getContractManager()).getNextSigningDescriptor();
16170
16313
  }
16171
- return chunkNDQ4LB4X_cjs.identityDescriptor(this.identity);
16314
+ return chunkJYQXB7OH_cjs.identityDescriptor(this.identity);
16172
16315
  }
16173
16316
  /**
16174
16317
  * @see HDAllocationCapable.advanceSigningDescriptorWatermark
@@ -16244,7 +16387,7 @@ var Wallet2 = class extends ReadonlyWallet {
16244
16387
  * the stable public API.
16245
16388
  */
16246
16389
  async rotateServerSigner(newServerPubKey, checkpointTapscript) {
16247
- const xonly = chunkJFJNB7ZH_cjs.toXOnly(newServerPubKey, "ark signer key");
16390
+ const xonly = chunk5PWL7WOT_cjs.toXOnly(newServerPubKey, "ark signer key");
16248
16391
  const newServerUnrollScript = assertValidServerUnrollScript(
16249
16392
  checkpointTapscript,
16250
16393
  this.network,
@@ -16274,21 +16417,21 @@ var Wallet2 = class extends ReadonlyWallet {
16274
16417
  ]);
16275
16418
  const [currentOffchainRow] = offchainRows2;
16276
16419
  const [currentBoardingRow] = boardingRows;
16277
- const newOffchain = this.offchainTapscript instanceof chunkNDQ4LB4X_cjs.DelegateVtxo.Script ? new chunkNDQ4LB4X_cjs.DelegateVtxo.Script({
16420
+ const newOffchain = this.offchainTapscript instanceof chunkJYQXB7OH_cjs.DelegateVtxo.Script ? new chunkJYQXB7OH_cjs.DelegateVtxo.Script({
16278
16421
  ...this.offchainTapscript.options,
16279
16422
  serverPubKey: xonly
16280
- }) : new chunkNDQ4LB4X_cjs.DefaultVtxo.Script({
16423
+ }) : new chunkJYQXB7OH_cjs.DefaultVtxo.Script({
16281
16424
  ...this.offchainTapscript.options,
16282
16425
  serverPubKey: xonly
16283
16426
  });
16284
- const newBoarding = new chunkNDQ4LB4X_cjs.DefaultVtxo.Script({
16427
+ const newBoarding = new chunkJYQXB7OH_cjs.DefaultVtxo.Script({
16285
16428
  ...this._boardingTapscript.options,
16286
16429
  serverPubKey: xonly
16287
16430
  });
16288
16431
  const offchainCsv = chunkFLPWNMX3_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
16289
16432
  const newOffchainScript = base.hex.encode(newOffchain.pkScript);
16290
16433
  const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
16291
- if (newOffchain instanceof chunkNDQ4LB4X_cjs.DelegateVtxo.Script) {
16434
+ if (newOffchain instanceof chunkJYQXB7OH_cjs.DelegateVtxo.Script) {
16292
16435
  await manager.createContract({
16293
16436
  type: "delegate",
16294
16437
  params: {
@@ -16316,7 +16459,7 @@ var Wallet2 = class extends ReadonlyWallet {
16316
16459
  metadata: currentOffchainRow?.metadata
16317
16460
  });
16318
16461
  }
16319
- const boardingCsv = newBoarding.options.csvTimelock ?? chunkNDQ4LB4X_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
16462
+ const boardingCsv = newBoarding.options.csvTimelock ?? chunkJYQXB7OH_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
16320
16463
  await manager.createContract({
16321
16464
  type: "boarding",
16322
16465
  params: {
@@ -16350,14 +16493,14 @@ var Wallet2 = class extends ReadonlyWallet {
16350
16493
  _restoreInFlight;
16351
16494
  _addPendingSpends(inputs) {
16352
16495
  for (const input of inputs) {
16353
- if (chunkLZAINCGU_cjs.isVirtualCoin(input)) {
16496
+ if (chunkSOJDUKY6_cjs.isVirtualCoin(input)) {
16354
16497
  this._pendingSpendOutpoints.add(`${input.txid}:${input.vout}`);
16355
16498
  }
16356
16499
  }
16357
16500
  }
16358
16501
  _removePendingSpends(inputs) {
16359
16502
  for (const input of inputs) {
16360
- if (chunkLZAINCGU_cjs.isVirtualCoin(input)) {
16503
+ if (chunkSOJDUKY6_cjs.isVirtualCoin(input)) {
16361
16504
  this._pendingSpendOutpoints.delete(`${input.txid}:${input.vout}`);
16362
16505
  }
16363
16506
  }
@@ -16421,7 +16564,7 @@ var Wallet2 = class extends ReadonlyWallet {
16421
16564
  if (clashing.length > 0) throw new VtxoReservedError(clashing, "in-flight");
16422
16565
  }
16423
16566
  _assertNotHeld(inputs) {
16424
- const held = coinKeys(inputs.filter(chunkLZAINCGU_cjs.isVirtualCoin)).filter(
16567
+ const held = coinKeys(inputs.filter(chunkSOJDUKY6_cjs.isVirtualCoin)).filter(
16425
16568
  (key) => this._heldOutpoints.has(key)
16426
16569
  );
16427
16570
  if (held.length > 0) throw new VtxoReservedError(held, "held");
@@ -16460,14 +16603,14 @@ var Wallet2 = class extends ReadonlyWallet {
16460
16603
  const hd = provider !== void 0;
16461
16604
  const [manager, staticDescriptor, arkInfo] = await Promise.all([
16462
16605
  this.getContractManager(),
16463
- hd ? void 0 : chunkNDQ4LB4X_cjs.identityDescriptor(this.identity),
16606
+ hd ? void 0 : chunkJYQXB7OH_cjs.identityDescriptor(this.identity),
16464
16607
  this.arkProvider.getInfo()
16465
16608
  ]);
16466
16609
  const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
16467
- const delegatePubKey = this.offchainTapscript instanceof chunkNDQ4LB4X_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
16468
- const currentSignerPubKey = chunkJFJNB7ZH_cjs.toXOnly(base.hex.decode(arkInfo.signerPubkey), "ark signer key");
16610
+ const delegatePubKey = this.offchainTapscript instanceof chunkJYQXB7OH_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
16611
+ const currentSignerPubKey = chunk5PWL7WOT_cjs.toXOnly(base.hex.decode(arkInfo.signerPubkey), "ark signer key");
16469
16612
  const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
16470
- (s) => chunkJFJNB7ZH_cjs.toXOnly(base.hex.decode(s.pubkey), "deprecated signer key")
16613
+ (s) => chunk5PWL7WOT_cjs.toXOnly(base.hex.decode(s.pubkey), "deprecated signer key")
16471
16614
  );
16472
16615
  const deps = {
16473
16616
  indexerProvider: this.indexerProvider,
@@ -16479,7 +16622,7 @@ var Wallet2 = class extends ReadonlyWallet {
16479
16622
  deprecatedSignerPubKeys,
16480
16623
  csvTimelocks: this.walletContractTimelocks,
16481
16624
  // Boarding-exit CSV, distinct from the unilateral-exit matrix.
16482
- boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkNDQ4LB4X_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
16625
+ boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkJYQXB7OH_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
16483
16626
  delegatePubKey
16484
16627
  };
16485
16628
  const result = await manager.scanContracts({
@@ -16601,7 +16744,7 @@ var Wallet2 = class extends ReadonlyWallet {
16601
16744
  throw new Error("Invalid configured public key");
16602
16745
  }
16603
16746
  const setup = await ReadonlyWallet.setupWalletConfig(config, pubkey);
16604
- const forfeitPubkey = chunkJFJNB7ZH_cjs.toXOnly(base.hex.decode(setup.info.forfeitPubkey), "forfeit key");
16747
+ const forfeitPubkey = chunk5PWL7WOT_cjs.toXOnly(base.hex.decode(setup.info.forfeitPubkey), "forfeit key");
16605
16748
  const forfeitAddress = btcSigner.Address(setup.network).decode(setup.info.forfeitAddress);
16606
16749
  const forfeitOutputScript = btcSigner.OutScript.encode(forfeitAddress);
16607
16750
  const serverUnrollScript = assertValidServerUnrollScript(
@@ -16812,7 +16955,7 @@ var Wallet2 = class extends ReadonlyWallet {
16812
16955
  if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
16813
16956
  break;
16814
16957
  }
16815
- const inputFee = estimator.evalOffchainInput(chunkLZAINCGU_cjs.toOffchainInputFeeParams(vtxo));
16958
+ const inputFee = estimator.evalOffchainInput(chunkSOJDUKY6_cjs.toOffchainInputFeeParams(vtxo));
16816
16959
  if (inputFee.satoshis >= vtxo.value) {
16817
16960
  continue;
16818
16961
  }
@@ -16936,11 +17079,11 @@ var Wallet2 = class extends ReadonlyWallet {
16936
17079
  ]);
16937
17080
  let intentTxId;
16938
17081
  try {
16939
- intentTxId = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(intent.proof)).id;
17082
+ intentTxId = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(intent.proof)).id;
16940
17083
  } catch {
16941
17084
  intentTxId = params.inputs.map((i) => `${i.txid}:${i.vout}`).sort().join("|");
16942
17085
  }
16943
- const settleInputVtxos = params.inputs.filter(chunkLZAINCGU_cjs.isVirtualCoin);
17086
+ const settleInputVtxos = params.inputs.filter(chunkSOJDUKY6_cjs.isVirtualCoin);
16944
17087
  const contractManager = await this.getContractManager();
16945
17088
  await contractManager.assertAnnotatable(settleInputVtxos);
16946
17089
  await contractManager.assertSpendableNow?.(
@@ -16949,7 +17092,7 @@ var Wallet2 = class extends ReadonlyWallet {
16949
17092
  );
16950
17093
  if (picked) this._assertNotHeld(params.inputs);
16951
17094
  this._addPendingSpends(params.inputs);
16952
- const boardingKeys = onReserved ? coinKeys(params.inputs.filter((i) => !chunkLZAINCGU_cjs.isVirtualCoin(i))) : [];
17095
+ const boardingKeys = onReserved ? coinKeys(params.inputs.filter((i) => !chunkSOJDUKY6_cjs.isVirtualCoin(i))) : [];
16953
17096
  for (const key of boardingKeys) this._pendingSpendOutpoints.add(key);
16954
17097
  const settlingKeys = params.inputs.map((i) => `${i.txid}:${i.vout}`);
16955
17098
  for (const key of settlingKeys) this._settlingOutpoints.add(key);
@@ -17059,7 +17202,7 @@ var Wallet2 = class extends ReadonlyWallet {
17059
17202
  async maybeRotateBoardingAfterBoard(inputs) {
17060
17203
  if (!this._descriptorProvider) return;
17061
17204
  const consumedBoarding = inputs.some(
17062
- (input) => typeof input !== "string" && !chunkLZAINCGU_cjs.isVirtualCoin(input)
17205
+ (input) => typeof input !== "string" && !chunkSOJDUKY6_cjs.isVirtualCoin(input)
17063
17206
  );
17064
17207
  if (!consumedBoarding) return;
17065
17208
  try {
@@ -17070,7 +17213,7 @@ var Wallet2 = class extends ReadonlyWallet {
17070
17213
  }
17071
17214
  async handleSettlementFinalizationEvent(event, inputs, forfeitOutputScript, expectedRecipients, connectorsGraph, validatedCommitmentTxid) {
17072
17215
  const signedForfeits = [];
17073
- let settlementPsbt = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
17216
+ let settlementPsbt = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
17074
17217
  assertFinalCommitmentMatchesValidated(
17075
17218
  settlementPsbt,
17076
17219
  validatedCommitmentTxid,
@@ -17083,7 +17226,7 @@ var Wallet2 = class extends ReadonlyWallet {
17083
17226
  let connectorIndex = 0;
17084
17227
  const connectorsLeaves = connectorsGraph?.leaves() || [];
17085
17228
  for (const input of inputs) {
17086
- if (!chunkLZAINCGU_cjs.isVirtualCoin(input)) {
17229
+ if (!chunkSOJDUKY6_cjs.isVirtualCoin(input)) {
17087
17230
  let matched = false;
17088
17231
  for (let i = 0; i < settlementPsbt.inputsLength; i++) {
17089
17232
  const settlementInput = settlementPsbt.getInput(i);
@@ -17121,7 +17264,7 @@ var Wallet2 = class extends ReadonlyWallet {
17121
17264
  }
17122
17265
  continue;
17123
17266
  }
17124
- if (!chunkLZAINCGU_cjs.requiresForfeit(input) || isSubdust({ value: input.value }, this.dustAmount)) {
17267
+ if (!chunkSOJDUKY6_cjs.requiresForfeit(input) || isSubdust({ value: input.value }, this.dustAmount)) {
17125
17268
  continue;
17126
17269
  }
17127
17270
  if (connectorsLeaves.length === 0) {
@@ -17241,14 +17384,14 @@ var Wallet2 = class extends ReadonlyWallet {
17241
17384
  throw new Error("Sweep tap tree root not set");
17242
17385
  }
17243
17386
  const xOnlyPublicKeys = event.cosignersPublicKeys.map(
17244
- (k) => base.hex.encode(chunkJFJNB7ZH_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
17387
+ (k) => base.hex.encode(chunk5PWL7WOT_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
17245
17388
  );
17246
17389
  const signerPublicKey = await session.getPublicKey();
17247
- const xonlySignerPublicKey = chunkJFJNB7ZH_cjs.toXOnly(signerPublicKey, "signer key");
17390
+ const xonlySignerPublicKey = chunk5PWL7WOT_cjs.toXOnly(signerPublicKey, "signer key");
17248
17391
  if (!xOnlyPublicKeys.includes(base.hex.encode(xonlySignerPublicKey))) {
17249
17392
  return { skip: true };
17250
17393
  }
17251
- const commitmentTx = chunkLZAINCGU_cjs.Transaction.fromPSBT(
17394
+ const commitmentTx = chunkSOJDUKY6_cjs.Transaction.fromPSBT(
17252
17395
  base.base64.decode(event.unsignedCommitmentTx)
17253
17396
  );
17254
17397
  validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
@@ -17330,9 +17473,9 @@ var Wallet2 = class extends ReadonlyWallet {
17330
17473
  ...existing ?? {},
17331
17474
  proofTxId: intentTxId,
17332
17475
  registerProof: intent.proof,
17333
- registerProofMessage: chunkLZAINCGU_cjs.Proof.encodeMessage(intent.message),
17476
+ registerProofMessage: chunkSOJDUKY6_cjs.Proof.encodeMessage(intent.message),
17334
17477
  deleteProof: deleteIntent.proof,
17335
- deleteProofMessage: chunkLZAINCGU_cjs.Proof.encodeMessage(deleteIntent.message),
17478
+ deleteProofMessage: chunkSOJDUKY6_cjs.Proof.encodeMessage(deleteIntent.message),
17336
17479
  proofInputs: inputs.map((i) => ({
17337
17480
  txid: i.txid,
17338
17481
  vout: i.vout
@@ -17363,7 +17506,7 @@ var Wallet2 = class extends ReadonlyWallet {
17363
17506
  }
17364
17507
  /** @see IWallet.cosignOnchainTx */
17365
17508
  async cosignOnchainTx(psbt) {
17366
- const tx = typeof psbt === "string" ? chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(psbt)) : psbt;
17509
+ const tx = typeof psbt === "string" ? chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(psbt)) : psbt;
17367
17510
  return this._withTxLock(async () => {
17368
17511
  await (await this.getContractManager()).syncOnchain();
17369
17512
  return this._cosignOnchainTxImpl(tx);
@@ -17428,7 +17571,7 @@ var Wallet2 = class extends ReadonlyWallet {
17428
17571
  if (reasons.length > 0) throw new OnchainCosignPreflightError(reasons.join("; "));
17429
17572
  }
17430
17573
  const feeRate = await this.onchainProvider.getFeeRate() ?? 1;
17431
- const tx = new chunkLZAINCGU_cjs.Transaction({ version: 2 });
17574
+ const tx = new chunkSOJDUKY6_cjs.Transaction({ version: 2 });
17432
17575
  if (sweepTo) {
17433
17576
  const swept = candidates.slice(0, MAX_COSIGN_INPUTS);
17434
17577
  for (const { coin } of swept) {
@@ -17489,7 +17632,7 @@ var Wallet2 = class extends ReadonlyWallet {
17489
17632
  continue;
17490
17633
  }
17491
17634
  const { coin, contract, script } = mine;
17492
- const path = chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type).selectPath(script, contract, {
17635
+ const path = chunkJYQXB7OH_cjs.contractHandlers.get(contract.type).selectPath(script, contract, {
17493
17636
  collaborative: true,
17494
17637
  currentTime: Date.now(),
17495
17638
  blockHeight: tip.height,
@@ -17539,7 +17682,7 @@ var Wallet2 = class extends ReadonlyWallet {
17539
17682
  onchainProvider: this.onchainProvider
17540
17683
  });
17541
17684
  } catch (e) {
17542
- if (e instanceof chunkLZAINCGU_cjs.OnchainCosignAmbiguousError || isCosignRejectedAfterSigning(e)) {
17685
+ if (e instanceof chunkSOJDUKY6_cjs.OnchainCosignAmbiguousError || isCosignRejectedAfterSigning(e)) {
17543
17686
  await markPending(signed.id);
17544
17687
  }
17545
17688
  throw e;
@@ -17559,7 +17702,7 @@ var Wallet2 = class extends ReadonlyWallet {
17559
17702
  this.lockedOutpoints(),
17560
17703
  this.onchainCoins(manager)
17561
17704
  ]);
17562
- const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkNDQ4LB4X_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
17705
+ const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkJYQXB7OH_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
17563
17706
  return coins.filter(
17564
17707
  ({ coin, contract }) => !locked.has(vtxoOutpoint(coin)) && needsOnchainSweep(coin, contract, boardingCsv, tip, this._cosignMarginBlocks)
17565
17708
  ).slice(0, MAX_COSIGN_INPUTS).map(({ coin }) => ({ txid: coin.txid, vout: coin.vout }));
@@ -17571,8 +17714,8 @@ var Wallet2 = class extends ReadonlyWallet {
17571
17714
  unspentOnly: true
17572
17715
  });
17573
17716
  return snapshot.flatMap(({ contract, vtxos }) => {
17574
- const handler = chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type);
17575
- const coins = vtxos.filter((v) => v.isUnrolled && !chunkLZAINCGU_cjs.isVtxoSpent(v));
17717
+ const handler = chunkJYQXB7OH_cjs.contractHandlers.get(contract.type);
17718
+ const coins = vtxos.filter((v) => v.isUnrolled && !chunkSOJDUKY6_cjs.isVtxoSpent(v));
17576
17719
  if (!handler || coins.length === 0) return [];
17577
17720
  const script = handler.createScript(contract.params);
17578
17721
  return coins.map((coin) => ({ coin, contract, script }));
@@ -17582,7 +17725,7 @@ var Wallet2 = class extends ReadonlyWallet {
17582
17725
  try {
17583
17726
  return await this.arkProvider.registerIntent(intent);
17584
17727
  } catch (error) {
17585
- if (error instanceof chunkLZAINCGU_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
17728
+ if (error instanceof chunkSOJDUKY6_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
17586
17729
  const deleteIntent = await this.makeDeleteIntentSignature(inputs);
17587
17730
  await this.arkProvider.deleteIntent(deleteIntent);
17588
17731
  return this.arkProvider.registerIntent(intent);
@@ -17598,7 +17741,7 @@ var Wallet2 = class extends ReadonlyWallet {
17598
17741
  expire_at: 0,
17599
17742
  cosigners_public_keys: cosignerPubKeys
17600
17743
  };
17601
- const proof = chunkLZAINCGU_cjs.Proof.create(message, coins, outputs);
17744
+ const proof = chunkSOJDUKY6_cjs.Proof.create(message, coins, outputs);
17602
17745
  const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
17603
17746
  return {
17604
17747
  proof: base.base64.encode(signedProof.toPSBT()),
@@ -17610,7 +17753,7 @@ var Wallet2 = class extends ReadonlyWallet {
17610
17753
  type: "delete",
17611
17754
  expire_at: 0
17612
17755
  };
17613
- const proof = chunkLZAINCGU_cjs.Proof.create(message, coins, []);
17756
+ const proof = chunkSOJDUKY6_cjs.Proof.create(message, coins, []);
17614
17757
  const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
17615
17758
  return {
17616
17759
  proof: base.base64.encode(signedProof.toPSBT()),
@@ -17622,7 +17765,7 @@ var Wallet2 = class extends ReadonlyWallet {
17622
17765
  type: "get-pending-tx",
17623
17766
  expire_at: 0
17624
17767
  };
17625
- const proof = chunkLZAINCGU_cjs.Proof.create(message, coins, []);
17768
+ const proof = chunkSOJDUKY6_cjs.Proof.create(message, coins, []);
17626
17769
  const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
17627
17770
  return {
17628
17771
  proof: base.base64.encode(signedProof.toPSBT()),
@@ -17643,7 +17786,7 @@ var Wallet2 = class extends ReadonlyWallet {
17643
17786
  if (!vtxos || vtxos.length === 0) {
17644
17787
  const scriptMap = await this.getScriptMap();
17645
17788
  const allExtended = [];
17646
- const fetchedVtxos = await chunkLZAINCGU_cjs.getAllNormalizedVtxos(this.indexerProvider, [
17789
+ const fetchedVtxos = await chunkSOJDUKY6_cjs.getAllNormalizedVtxos(this.indexerProvider, [
17647
17790
  ...scriptMap.keys()
17648
17791
  ]);
17649
17792
  for (const vtxo of fetchedVtxos) {
@@ -17686,8 +17829,8 @@ var Wallet2 = class extends ReadonlyWallet {
17686
17829
  batchPending.push(pendingTx.arkTxid);
17687
17830
  try {
17688
17831
  const checkpointTxs = pendingTx.signedCheckpointTxs.map((c) => {
17689
- const tx = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(c));
17690
- chunkLZAINCGU_cjs.assertAllowedSighashTypes(tx);
17832
+ const tx = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(c));
17833
+ chunkSOJDUKY6_cjs.assertAllowedSighashTypes(tx);
17691
17834
  return tx;
17692
17835
  });
17693
17836
  assertCheckpointsMatchInputs(
@@ -17858,11 +18001,17 @@ var Wallet2 = class extends ReadonlyWallet {
17858
18001
  const myPkScript = chunkFLPWNMX3_cjs.ArkAddress.decode(await this.getAddress()).pkScript;
17859
18002
  let { spendable, recoverable, unclaimed } = this.classifyCashVtxos(vtxos);
17860
18003
  let swept = 0;
18004
+ const claims = [];
17861
18005
  const drainable = vtxos.filter(
17862
18006
  (vtxo) => !isSubdust(vtxo, this.dustAmount) && !vtxo.isUnrolled
17863
18007
  );
17864
18008
  if (drainable.length > 0) {
17865
- let drained = { count: 0, swept: 0, claimed: /* @__PURE__ */ new Set() };
18009
+ let drained = {
18010
+ count: 0,
18011
+ swept: 0,
18012
+ claimed: /* @__PURE__ */ new Set(),
18013
+ claims: []
18014
+ };
17866
18015
  try {
17867
18016
  drained = await this.finalizePendingCashTxs(
17868
18017
  cash,
@@ -17873,6 +18022,7 @@ var Wallet2 = class extends ReadonlyWallet {
17873
18022
  } catch (error) {
17874
18023
  console.error("Failed to drain pending arkadeCash txs:", error);
17875
18024
  }
18025
+ claims.push(...drained.claims);
17876
18026
  if (drained.count > 0) {
17877
18027
  vtxos = await this.fetchAllVtxos(scripts);
17878
18028
  ({ spendable, recoverable, unclaimed } = this.classifyCashVtxos(vtxos));
@@ -17890,7 +18040,7 @@ var Wallet2 = class extends ReadonlyWallet {
17890
18040
  );
17891
18041
  for (const vtxo of spendable) {
17892
18042
  try {
17893
- await signAndSubmitOffchainTx({
18043
+ const registeredTxid = await signAndSubmitOffchainTx({
17894
18044
  identity: cash.identity,
17895
18045
  provider: this.arkProvider,
17896
18046
  inputs: [
@@ -17906,6 +18056,7 @@ var Wallet2 = class extends ReadonlyWallet {
17906
18056
  serverUnrollScript,
17907
18057
  oneShot: this.oneShotSubmit
17908
18058
  });
18059
+ claims.push({ txid: registeredTxid, amount: vtxo.value });
17909
18060
  swept += vtxo.value;
17910
18061
  } catch (error) {
17911
18062
  console.error(
@@ -17936,6 +18087,7 @@ var Wallet2 = class extends ReadonlyWallet {
17936
18087
  }
17937
18088
  }
17938
18089
  return {
18090
+ claims,
17939
18091
  swept,
17940
18092
  recovering: {
17941
18093
  amount: recovering.reduce((total, vtxo) => total + vtxo.value, 0),
@@ -18053,6 +18205,36 @@ var Wallet2 = class extends ReadonlyWallet {
18053
18205
  }
18054
18206
  await manager.deleteContract(script);
18055
18207
  }
18208
+ /**
18209
+ * Correlate an imported voucher's settlement with the voucher record. This
18210
+ * is deliberately kept on wallet state rather than being inferred from the
18211
+ * generic recovery row, which has no safe public correlation key. The
18212
+ * imported contract carries no cash id, so its script is the join key:
18213
+ * the script is the voucher id.
18214
+ */
18215
+ async correlateArkadeCashRecovery(cashId, txid, amount, outcome = "recovered") {
18216
+ await updateWalletState(this.walletRepository, (state) => {
18217
+ const raw = state.settings?.arkadeCashRecovery;
18218
+ const entries = Array.isArray(raw) ? raw : [];
18219
+ const index = entries.findIndex(
18220
+ (entry) => isArkadeCashRecord(entry) && entry.id === cashId
18221
+ );
18222
+ const previous = index >= 0 ? entries[index] : void 0;
18223
+ if (previous?.claims.some((claim) => claim.txid === txid)) return state;
18224
+ const next = mergeArkadeCashRecord(previous, {
18225
+ id: cashId,
18226
+ action: "claimed",
18227
+ outcome,
18228
+ createdAt: Math.floor(Date.now() / 1e3),
18229
+ issues: [],
18230
+ claims: [{ txid, amount }]
18231
+ });
18232
+ const updated = [...entries];
18233
+ if (index >= 0) updated[index] = next;
18234
+ else updated.push(next);
18235
+ return { ...state, settings: { ...state.settings, arkadeCashRecovery: updated } };
18236
+ });
18237
+ }
18056
18238
  /**
18057
18239
  * Split the VTXOs at an arkadeCash address into three buckets: the ones the
18058
18240
  * thin sweep can move (`spendable`), the operator-swept ones that must go
@@ -18064,7 +18246,7 @@ var Wallet2 = class extends ReadonlyWallet {
18064
18246
  const recoverable = [];
18065
18247
  const unclaimed = [];
18066
18248
  for (const vtxo of vtxos) {
18067
- if (chunkLZAINCGU_cjs.isVtxoSpent(vtxo)) {
18249
+ if (chunkSOJDUKY6_cjs.isVtxoSpent(vtxo)) {
18068
18250
  unclaimed.push(cashReport(vtxo, "already-spent"));
18069
18251
  } else if (vtxo.isUnrolled) {
18070
18252
  unclaimed.push(cashReport(vtxo, "exited"));
@@ -18086,7 +18268,7 @@ var Wallet2 = class extends ReadonlyWallet {
18086
18268
  const all = [];
18087
18269
  const seen = /* @__PURE__ */ new Set();
18088
18270
  for (let pageIndex = 0; ; pageIndex++) {
18089
- const { vtxos, page } = await chunkLZAINCGU_cjs.getNormalizedVtxos(this.indexerProvider, {
18271
+ const { vtxos, page } = await chunkSOJDUKY6_cjs.getNormalizedVtxos(this.indexerProvider, {
18090
18272
  scripts,
18091
18273
  pageIndex,
18092
18274
  pageSize
@@ -18110,7 +18292,12 @@ var Wallet2 = class extends ReadonlyWallet {
18110
18292
  * @returns Txs finalized, sats paid to this wallet, and the outpoints consumed to pay it.
18111
18293
  */
18112
18294
  async finalizePendingCashTxs(cash, vtxos, cashScript, myPkScript) {
18113
- const result = { count: 0, swept: 0, claimed: /* @__PURE__ */ new Set() };
18295
+ const result = {
18296
+ count: 0,
18297
+ swept: 0,
18298
+ claimed: /* @__PURE__ */ new Set(),
18299
+ claims: []
18300
+ };
18114
18301
  const inputs = vtxos.map((vtxo) => ({
18115
18302
  ...vtxo,
18116
18303
  forfeitTapLeafScript: cashScript.forfeit(),
@@ -18124,7 +18311,7 @@ var Wallet2 = class extends ReadonlyWallet {
18124
18311
  for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_PROOF) {
18125
18312
  const batch = inputs.slice(i, i + MAX_INPUTS_PER_PROOF);
18126
18313
  const message = { type: "get-pending-tx", expire_at: 0 };
18127
- const proof = chunkLZAINCGU_cjs.Proof.create(message, batch, []);
18314
+ const proof = chunkSOJDUKY6_cjs.Proof.create(message, batch, []);
18128
18315
  const signedProof = await identity.sign(
18129
18316
  proof,
18130
18317
  Array.from({ length: batch.length + 1 }, (_, j) => j)
@@ -18145,8 +18332,8 @@ var Wallet2 = class extends ReadonlyWallet {
18145
18332
  for (const pendingTx of pendingTxs) {
18146
18333
  try {
18147
18334
  const checkpointTxs = pendingTx.signedCheckpointTxs.map((checkpoint) => {
18148
- const tx = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(checkpoint));
18149
- chunkLZAINCGU_cjs.assertAllowedSighashTypes(tx);
18335
+ const tx = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(checkpoint));
18336
+ chunkSOJDUKY6_cjs.assertAllowedSighashTypes(tx);
18150
18337
  return tx;
18151
18338
  });
18152
18339
  assertCheckpointsMatchInputs(
@@ -18167,6 +18354,7 @@ var Wallet2 = class extends ReadonlyWallet {
18167
18354
  result.count++;
18168
18355
  const paidToMe = this.arkTxAmountPaidTo(pendingTx.finalArkTx, myPkScriptHex);
18169
18356
  if (paidToMe === 0) continue;
18357
+ result.claims.push({ txid: pendingTx.arkTxid, amount: paidToMe });
18170
18358
  result.swept += paidToMe;
18171
18359
  for (const checkpoint of checkpointTxs) {
18172
18360
  for (let i = 0; i < checkpoint.inputsLength; i++) {
@@ -18186,7 +18374,7 @@ var Wallet2 = class extends ReadonlyWallet {
18186
18374
  }
18187
18375
  /** Sum the outputs of an ark tx PSBT that pay the given scriptPubKey. */
18188
18376
  arkTxAmountPaidTo(arkTxPsbt, pkScriptHex) {
18189
- const arkTx = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(arkTxPsbt));
18377
+ const arkTx = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(arkTxPsbt));
18190
18378
  let total = 0;
18191
18379
  for (let i = 0; i < arkTx.outputsLength; i++) {
18192
18380
  const output = arkTx.getOutput(i);
@@ -18245,7 +18433,7 @@ var Wallet2 = class extends ReadonlyWallet {
18245
18433
  throw new Error("send({ maxChangeFee }): expected a non-negative safe integer");
18246
18434
  }
18247
18435
  if (selectedVtxos) {
18248
- if (inputExpiryFloor) selectedVtxos = selectedVtxos.map(chunkLZAINCGU_cjs.normalizeVtxo);
18436
+ if (inputExpiryFloor) selectedVtxos = selectedVtxos.map(chunkSOJDUKY6_cjs.normalizeVtxo);
18249
18437
  if (inputExpiryFloor && selectedVtxos.some((coin) => !meetsInputExpiryFloor(coin, inputExpiryFloor))) {
18250
18438
  throw new Error("send({ selectedVtxos }): input expiry floor not met");
18251
18439
  }
@@ -18572,10 +18760,10 @@ var Wallet2 = class extends ReadonlyWallet {
18572
18760
  const serverPubKey = this.arkServerPublicKey;
18573
18761
  const serverUnrollScript = this.serverUnrollScript;
18574
18762
  const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
18575
- const normalizedInputs = inputs.map(chunkLZAINCGU_cjs.normalizeVtxo);
18576
- const at = now ?? await chunkLZAINCGU_cjs.resolveTimeHeight(this.onchainProvider);
18763
+ const normalizedInputs = inputs.map(chunkSOJDUKY6_cjs.normalizeVtxo);
18764
+ const at = now ?? await chunkSOJDUKY6_cjs.resolveTimeHeight(this.onchainProvider);
18577
18765
  for (const input of normalizedInputs) {
18578
- if (!chunkLZAINCGU_cjs.canSpendOffchain(input, at)) {
18766
+ if (!chunkSOJDUKY6_cjs.canSpendOffchain(input, at)) {
18579
18767
  throw new Error(
18580
18768
  `sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} is not cooperatively spendable`
18581
18769
  );
@@ -18769,7 +18957,7 @@ var Wallet2 = class extends ReadonlyWallet {
18769
18957
  }
18770
18958
  const checkpointIdByOutpoint = /* @__PURE__ */ new Map();
18771
18959
  for (const encoded of signedCheckpointTxs) {
18772
- const checkpoint = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
18960
+ const checkpoint = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
18773
18961
  for (let i = 0; i < checkpoint.inputsLength; i++) {
18774
18962
  const input = checkpoint.getInput(i);
18775
18963
  if (!input.txid) continue;
@@ -18886,12 +19074,12 @@ var Wallet2 = class extends ReadonlyWallet {
18886
19074
  const inputArkTxIds = /* @__PURE__ */ new Set();
18887
19075
  const boardingScripts = /* @__PURE__ */ new Set();
18888
19076
  const boardingOutpoints = [];
18889
- const vtxoInputs = inputs.filter(chunkLZAINCGU_cjs.isVirtualCoin);
19077
+ const vtxoInputs = inputs.filter(chunkSOJDUKY6_cjs.isVirtualCoin);
18890
19078
  const cm = await this.getContractManager();
18891
19079
  const annotatedVtxos = await cm.annotateVtxos(vtxoInputs);
18892
19080
  const annotatedByKey = new Map(annotatedVtxos.map((v) => [`${v.txid}:${v.vout}`, v]));
18893
19081
  for (const input of inputs) {
18894
- if (chunkLZAINCGU_cjs.isVirtualCoin(input)) {
19082
+ if (chunkSOJDUKY6_cjs.isVirtualCoin(input)) {
18895
19083
  const outpoint = `${input.txid}:${input.vout}`;
18896
19084
  const vtxo = annotatedByKey.get(outpoint);
18897
19085
  if (!vtxo) {
@@ -18974,7 +19162,7 @@ function bySelectionOrder(a, b) {
18974
19162
  return b.value - a.value;
18975
19163
  }
18976
19164
  function selectVirtualCoins(coins, targetAmount) {
18977
- const sortedCoins = coins.map(chunkLZAINCGU_cjs.normalizeVtxo).sort(bySelectionOrder);
19165
+ const sortedCoins = coins.map(chunkSOJDUKY6_cjs.normalizeVtxo).sort(bySelectionOrder);
18978
19166
  const selectedCoins = [];
18979
19167
  let selectedAmount = 0;
18980
19168
  for (const coin of sortedCoins) {
@@ -19102,7 +19290,7 @@ function assertTimeoutMap(name, timeouts) {
19102
19290
  if (value === void 0) {
19103
19291
  throw new Error(`${name}.${key} must be a non-negative safe integer`);
19104
19292
  }
19105
- chunkLZAINCGU_cjs.assertTimerMs(`${name}.${key}`, value);
19293
+ chunkSOJDUKY6_cjs.assertTimerMs(`${name}.${key}`, value);
19106
19294
  }
19107
19295
  }
19108
19296
  var MessageBus = class {
@@ -19119,8 +19307,8 @@ var MessageBus = class {
19119
19307
  }) {
19120
19308
  this.walletRepository = walletRepository;
19121
19309
  this.contractRepository = contractRepository;
19122
- chunkLZAINCGU_cjs.assertTimerMs("tickIntervalMs", tickIntervalMs);
19123
- chunkLZAINCGU_cjs.assertTimerMs("messageTimeoutMs", messageTimeoutMs);
19310
+ chunkSOJDUKY6_cjs.assertTimerMs("tickIntervalMs", tickIntervalMs);
19311
+ chunkSOJDUKY6_cjs.assertTimerMs("messageTimeoutMs", messageTimeoutMs);
19124
19312
  assertTimeoutMap("messageTimeoutOverrides", messageTimeoutOverrides);
19125
19313
  this.intentRepository = intentRepository;
19126
19314
  this.onchainProvider = onchainProvider;
@@ -19376,14 +19564,14 @@ var MessageBus = class {
19376
19564
  this.initialized = true;
19377
19565
  }
19378
19566
  async buildServices(config) {
19379
- const arkProvider = new chunkLZAINCGU_cjs.RestOperatorProvider(config.arkServer.url);
19567
+ const arkProvider = new chunkSOJDUKY6_cjs.RestOperatorProvider(config.arkServer.url);
19380
19568
  const storage = {
19381
19569
  walletRepository: this.walletRepository,
19382
19570
  contractRepository: this.contractRepository,
19383
19571
  ...this.intentRepository && { intentRepository: this.intentRepository }
19384
19572
  };
19385
19573
  const delegateProvider = config.delegateUrl ? new RestDelegateProvider(config.delegateUrl) : void 0;
19386
- const indexerProvider = new chunkHKEPJBTY_cjs.RestIndexerProvider(config.arkServer.url);
19574
+ const indexerProvider = new chunk4IDCSOP2_cjs.RestIndexerProvider(config.arkServer.url);
19387
19575
  const serialized = normalizeSerializedIdentity(config.wallet);
19388
19576
  if (isSigningSerialized(serialized)) {
19389
19577
  const identity2 = hydrateIdentity(serialized);
@@ -19766,7 +19954,7 @@ function filterOffboardInputs(vtxos, feeInfo, named) {
19766
19954
  const inputs = [];
19767
19955
  let subtotal = 0n;
19768
19956
  for (const vtxo of vtxos) {
19769
- const inputFee = estimator.evalOffchainInput(chunkLZAINCGU_cjs.toOffchainInputFeeParams(vtxo));
19957
+ const inputFee = estimator.evalOffchainInput(chunkSOJDUKY6_cjs.toOffchainInputFeeParams(vtxo));
19770
19958
  if (inputFee.satoshis >= vtxo.value) {
19771
19959
  if (named) {
19772
19960
  throw new Error(
@@ -20031,7 +20219,7 @@ var Ramps = class {
20031
20219
  const ordered = [...candidates].sort(bySelectionOrder);
20032
20220
  let covered = 0n;
20033
20221
  for (let i = 0; i < ordered.length && i < MAX_VTXOS_PER_SETTLEMENT; i++) {
20034
- const fee = estimator.evalOffchainInput(chunkLZAINCGU_cjs.toOffchainInputFeeParams(ordered[i])).satoshis;
20222
+ const fee = estimator.evalOffchainInput(chunkSOJDUKY6_cjs.toOffchainInputFeeParams(ordered[i])).satoshis;
20035
20223
  covered += BigInt(ordered[i].value) - BigInt(fee);
20036
20224
  if (covered < needed) continue;
20037
20225
  try {
@@ -20078,6 +20266,51 @@ var Ramps = class {
20078
20266
  return { change, changeAddress };
20079
20267
  }
20080
20268
  };
20269
+ function groupByTxid(coins) {
20270
+ const totals = /* @__PURE__ */ new Map();
20271
+ for (const { txid, value } of coins) totals.set(txid, (totals.get(txid) ?? 0) + value);
20272
+ return [...totals].map(([txid, amount]) => ({ txid, amount }));
20273
+ }
20274
+ async function readArkadeCash(token, indexer, info, onchain) {
20275
+ const cash = ArkadeCash.fromString(token);
20276
+ const signer = classifyAgainstSignerSet(base.hex.encode(cash.serverPubKey), signerSetFromInfo(info));
20277
+ if (signer.status === "UNKNOWN_SIGNER") {
20278
+ throw new Error("ArkadeCash belongs to another operator");
20279
+ }
20280
+ const coins = await chunkSOJDUKY6_cjs.getAllNormalizedVtxos(indexer, [arkadeCashId(cash)]);
20281
+ return classifyArkadeCash(
20282
+ coins,
20283
+ info.dust,
20284
+ await chunkSOJDUKY6_cjs.resolveTimeHeight(onchain),
20285
+ signer.status === "EXPIRED"
20286
+ );
20287
+ }
20288
+ function classifyArkadeCash(coins, dust, now, awaitingSweep = false) {
20289
+ const eligible = coins.filter(
20290
+ (coin) => coin.value >= Number(dust) && !(coin.assets && coin.assets.length > 0)
20291
+ );
20292
+ const hasSpent = eligible.some(chunkSOJDUKY6_cjs.isVtxoSpent);
20293
+ const hasLive = eligible.some((coin) => !chunkSOJDUKY6_cjs.isVtxoSpent(coin) && !coin.isUnrolled);
20294
+ const hasExit = eligible.some((coin) => !chunkSOJDUKY6_cjs.isVtxoSpent(coin) && coin.isUnrolled);
20295
+ const recoverable = eligible.some((coin) => !chunkSOJDUKY6_cjs.isVtxoSpent(coin) && coin.isSwept);
20296
+ const elapsedBatch = eligible.some(
20297
+ (coin) => !chunkSOJDUKY6_cjs.isVtxoSpent(coin) && !coin.isSwept && chunkSOJDUKY6_cjs.isPastExpiry(coin, now)
20298
+ );
20299
+ return {
20300
+ status: eligible.length === 0 ? "unissued" : hasExit && !hasLive ? "exited" : hasSpent && !hasLive ? "claimed" : recoverable ? "recovering" : elapsedBatch || awaitingSweep ? "expired" : "available",
20301
+ amount: eligible.reduce((sum, coin) => sum + (chunkSOJDUKY6_cjs.isVtxoSpent(coin) ? 0 : coin.value), 0),
20302
+ issues: groupByTxid(eligible),
20303
+ claims: groupByTxid(
20304
+ // `||`: the indexer reports an unset id as an empty string, not as absent.
20305
+ eligible.flatMap((coin) => {
20306
+ const txid = coin.arkTxId || coin.settledBy;
20307
+ return txid ? [{ txid, value: coin.value }] : [];
20308
+ })
20309
+ )
20310
+ };
20311
+ }
20312
+
20313
+ // src/wallet/serviceWorker/wallet-message-handler.ts
20081
20314
  var WalletNotInitializedError = class extends Error {
20082
20315
  constructor() {
20083
20316
  super("Wallet handler not initialized");
@@ -20112,6 +20345,25 @@ function deserializeAggregateError(payload) {
20112
20345
  });
20113
20346
  return new AggregateError(errs, payload.message);
20114
20347
  }
20348
+ function isSerializedArkadeCashCreateError(value) {
20349
+ if (!value || typeof value !== "object") return false;
20350
+ const v = value;
20351
+ return v.name === "ArkadeCashCreateError" && typeof v.message === "string" && typeof v.cash === "string" && !!v.cause && typeof v.cause.name === "string" && typeof v.cause.message === "string";
20352
+ }
20353
+ function serializeArkadeCashCreateError(error) {
20354
+ const cause = error.cause;
20355
+ return {
20356
+ name: "ArkadeCashCreateError",
20357
+ message: error.message,
20358
+ cash: error.cash,
20359
+ cause: cause instanceof Error ? { name: cause.name, message: cause.message } : { name: "Error", message: String(cause) }
20360
+ };
20361
+ }
20362
+ function deserializeArkadeCashCreateError(payload) {
20363
+ const cause = new Error(payload.cause.message);
20364
+ cause.name = payload.cause.name;
20365
+ return new ArkadeCashCreateError(payload.cash, cause);
20366
+ }
20115
20367
  var ReadonlyWalletError = class extends Error {
20116
20368
  constructor() {
20117
20369
  super("Read-only wallet: operation requires signing");
@@ -20125,6 +20377,7 @@ var DelegateNotConfiguredError = class extends Error {
20125
20377
  }
20126
20378
  };
20127
20379
  var DEFAULT_MESSAGE_TAG = "WALLET_UPDATER";
20380
+ var isLongRunningCashAction = (request) => request.action === "create" || request.action === "claim";
20128
20381
  function unsupportedByManager(method) {
20129
20382
  return new Error(`Contract manager does not support ${method}`);
20130
20383
  }
@@ -20360,7 +20613,10 @@ var WalletMessageHandler = class {
20360
20613
  message.type === "MIGRATE_DEPRECATED_SIGNER_VTXOS" || // HD restore walks the index range with one indexer round-trip per
20361
20614
  // step until it hits gapLimit consecutive unused indices. The bus
20362
20615
  // deadline must not race the scan; liveness stays covered by PING.
20363
- message.type === "RESTORE_WALLET" || message.type === "COSIGN_ONCHAIN_TX" || message.type === "SEND_ONCHAIN";
20616
+ message.type === "RESTORE_WALLET" || // `create` and `claim` run sends and sweeps. A bus deadline would
20617
+ // answer with a timeout error and drop the token or txids that the
20618
+ // finished handler could still deliver.
20619
+ message.type === "ARKADE_CASH" && isLongRunningCashAction(message.payload) || message.type === "COSIGN_ONCHAIN_TX" || message.type === "SEND_ONCHAIN";
20364
20620
  }
20365
20621
  async handleMessage(message) {
20366
20622
  const id = message.id;
@@ -20403,6 +20659,82 @@ var WalletMessageHandler = class {
20403
20659
  payload: { address }
20404
20660
  });
20405
20661
  }
20662
+ case "ARKADE_CASH": {
20663
+ const request = message.payload;
20664
+ switch (request.action) {
20665
+ case "get": {
20666
+ const cash = ArkadeCash.fromString(request.token);
20667
+ const report = await readArkadeCash(
20668
+ request.token,
20669
+ this.readonlyWallet.indexerProvider,
20670
+ await this.readonlyWallet.getArkadeInfo(),
20671
+ this.readonlyWallet.onchainProvider
20672
+ );
20673
+ return this.tagged({
20674
+ id,
20675
+ type: "ARKADE_CASH",
20676
+ payload: { action: "get", cashId: arkadeCashId(cash), ...report }
20677
+ });
20678
+ }
20679
+ case "create": {
20680
+ try {
20681
+ const token = await this.requireWallet().createCash(request.amount);
20682
+ return this.tagged({
20683
+ id,
20684
+ type: "ARKADE_CASH",
20685
+ payload: { action: "create", token }
20686
+ });
20687
+ } catch (error) {
20688
+ if (!(error instanceof ArkadeCashCreateError)) throw error;
20689
+ return this.tagged({
20690
+ id,
20691
+ error: serializeArkadeCashCreateError(
20692
+ error
20693
+ )
20694
+ });
20695
+ }
20696
+ }
20697
+ case "activities": {
20698
+ const records = createArkadeCashTracker();
20699
+ request.records.forEach(
20700
+ (record) => addArkadeCashRecord(records, record)
20701
+ );
20702
+ const state = await this.walletRepository?.getWalletState();
20703
+ const recovered = state?.settings?.arkadeCashRecovery;
20704
+ if (Array.isArray(recovered)) {
20705
+ recovered.filter(isArkadeCashRecord).forEach((record) => addArkadeCashRecord(records, record));
20706
+ }
20707
+ return this.tagged({
20708
+ id,
20709
+ type: "ARKADE_CASH",
20710
+ payload: {
20711
+ action: "activities",
20712
+ activities: await arkadeCashActivity(
20713
+ records,
20714
+ await this.buildTransactionHistoryFromCache() ?? []
20715
+ )
20716
+ }
20717
+ });
20718
+ }
20719
+ case "claim": {
20720
+ const result = await this.requireWallet().claimCash(request.token);
20721
+ return this.tagged({
20722
+ id,
20723
+ type: "ARKADE_CASH",
20724
+ payload: { action: "claim", ...result }
20725
+ });
20726
+ }
20727
+ case "reveal": {
20728
+ const record = ArkadeCash.fromString(request.token);
20729
+ return this.tagged({
20730
+ id,
20731
+ type: "ARKADE_CASH",
20732
+ payload: { action: "reveal", cashId: arkadeCashId(record) }
20733
+ });
20734
+ }
20735
+ }
20736
+ return this.tagged({ id, error: new Error("Unknown Arkade Cash action") });
20737
+ }
20406
20738
  case "GET_OPERATOR_INFO":
20407
20739
  case "GET_ARKADE_INFO": {
20408
20740
  const { payload } = message;
@@ -21027,7 +21359,7 @@ var WalletMessageHandler = class {
21027
21359
  this.lazyBoardingInit = payload.lazyBoarding ?? false;
21028
21360
  this.boardingEpoch++;
21029
21361
  this.boardingLoaded = false;
21030
- this.indexerProvider = new chunkHKEPJBTY_cjs.RestIndexerProvider(arkServerUrl);
21362
+ this.indexerProvider = new chunk4IDCSOP2_cjs.RestIndexerProvider(arkServerUrl);
21031
21363
  await this.onWalletInitialized();
21032
21364
  }
21033
21365
  /** @see RequestInitWallet.payload.lazyBoarding */
@@ -21373,9 +21705,8 @@ var WalletMessageHandler = class {
21373
21705
  * arkcash) are excluded by default, mirroring {@link ReadonlyWallet.getVtxos}:
21374
21706
  * they are settled in their own isolated intent and must stay out of the
21375
21707
  * wallet's balance / VTXO / coin-selection / pending-tx views that read this.
21376
- * The transaction-history caller opts back in via `includeRecoveryOnly` to
21377
- * match the non-worker `getTransactionHistory`, which reads contracts
21378
- * directly and does include them.
21708
+ * Transaction history excludes them too, as does the non-worker
21709
+ * `getTransactionHistory`.
21379
21710
  */
21380
21711
  async getVtxosFromRepo(options) {
21381
21712
  return (await this.repoSnapshot(options)).vtxos;
@@ -21393,8 +21724,7 @@ var WalletMessageHandler = class {
21393
21724
  * what it knows is closed — so the coins of a just-registered escrowed
21394
21725
  * contract would count as available until the next poll.
21395
21726
  *
21396
- * Recovery-only contracts are skipped unless `includeRecoveryOnly` (see
21397
- * {@link getVtxosFromRepo}).
21727
+ * Recovery-only contracts are skipped (see {@link getVtxosFromRepo}).
21398
21728
  */
21399
21729
  async repoSnapshot(options = {}) {
21400
21730
  const repository = this.walletRepository;
@@ -21418,9 +21748,7 @@ var WalletMessageHandler = class {
21418
21748
  void addressPromise.catch(() => void 0);
21419
21749
  const manager = await wallet.getContractManager();
21420
21750
  const contracts = await manager.getContracts();
21421
- const eligible = contracts.filter(
21422
- (contract) => options.includeRecoveryOnly || !isRecoveryOnlyContract(contract)
21423
- );
21751
+ const eligible = contracts.filter((contract) => !isRecoveryOnlyContract(contract));
21424
21752
  const listsPromise = Promise.all(
21425
21753
  eligible.map((contract) => getVtxosForContract(repository, contract, options))
21426
21754
  );
@@ -21471,11 +21799,11 @@ var WalletMessageHandler = class {
21471
21799
  async buildTransactionHistoryFromCache() {
21472
21800
  if (!this.readonlyWallet) return null;
21473
21801
  const [{ snapshot, vtxos }, { boardingTxs, commitmentsToIgnore }] = await Promise.all([
21474
- this.repoSnapshot({ includeRecoveryOnly: true }),
21802
+ this.repoSnapshot(),
21475
21803
  this.readonlyWallet.getBoardingTxs()
21476
21804
  ]);
21477
21805
  const indexerProvider = this.indexerProvider;
21478
- const resolveTxCreatedAt = indexerProvider ? (txids) => chunkLZAINCGU_cjs.fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
21806
+ const resolveTxCreatedAt = indexerProvider ? (txids) => chunkSOJDUKY6_cjs.fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
21479
21807
  return buildTransactionHistory(
21480
21808
  vtxos,
21481
21809
  boardingTxs,
@@ -21544,9 +21872,9 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
21544
21872
  // budget so the worker's snapshot fallback stays reachable before this
21545
21873
  // page deadline fires — lowering it below the budget would time the page
21546
21874
  // out while the worker is still seconds from answering from cache.
21547
- GET_OPERATOR_INFO: chunkLZAINCGU_cjs.INFO_FETCH_TIMEOUT_MS + 8e3,
21875
+ GET_OPERATOR_INFO: chunkSOJDUKY6_cjs.INFO_FETCH_TIMEOUT_MS + 8e3,
21548
21876
  /** @deprecated Use `GET_OPERATOR_INFO`. */
21549
- GET_ARKADE_INFO: chunkLZAINCGU_cjs.INFO_FETCH_TIMEOUT_MS + 8e3,
21877
+ GET_ARKADE_INFO: chunkSOJDUKY6_cjs.INFO_FETCH_TIMEOUT_MS + 8e3,
21550
21878
  INDEXER_GET_VTXOS: 2e4,
21551
21879
  INDEXER_GET_VIRTUAL_TXS: 2e4,
21552
21880
  GET_VTXOS: 2e4,
@@ -21586,6 +21914,8 @@ var DEFAULT_MESSAGE_TIMEOUTS = {
21586
21914
  RECOVER_VTXOS: 5e4,
21587
21915
  RENEW_VTXOS: 5e4,
21588
21916
  SWEEP_EXPIRED_BOARDING_UTXOS: 5e4,
21917
+ // Only `get`/`activities`/`reveal`: `create` and `claim` stream with no deadline.
21918
+ ARKADE_CASH: 5e4,
21589
21919
  COSIGN_ONCHAIN_TX: 5e4,
21590
21920
  SEND_ONCHAIN: 5e4,
21591
21921
  // Streaming/long-running like RENEW_VTXOS (rotation + settle); the value is
@@ -21644,10 +21974,10 @@ function getRequestDedupKey(request) {
21644
21974
  }
21645
21975
  function cosignWorkerError(e) {
21646
21976
  if (e instanceof Error && e.message === "Unknown message") {
21647
- return new chunkLZAINCGU_cjs.OnchainCosignUnsupportedError();
21977
+ return new chunkSOJDUKY6_cjs.OnchainCosignUnsupportedError();
21648
21978
  }
21649
21979
  if (e instanceof ServiceWorkerTimeoutError) {
21650
- return new chunkLZAINCGU_cjs.OnchainCosignAmbiguousError(e.message, { cause: e });
21980
+ return new chunkSOJDUKY6_cjs.OnchainCosignAmbiguousError(e.message, { cause: e });
21651
21981
  }
21652
21982
  return rehydrateCosignError(e);
21653
21983
  }
@@ -21702,7 +22032,7 @@ var ServiceWorkerAssetManager = class extends ServiceWorkerReadonlyAssetManager
21702
22032
  }
21703
22033
  };
21704
22034
  var initializeMessageBus = (serviceWorker, config, timeoutMs = 2e3) => {
21705
- chunkLZAINCGU_cjs.assertTimerMs("messageBusTimeoutMs", timeoutMs);
22035
+ chunkSOJDUKY6_cjs.assertTimerMs("messageBusTimeoutMs", timeoutMs);
21706
22036
  const initCmd = {
21707
22037
  tag: "INITIALIZE_MESSAGE_BUS",
21708
22038
  id: getRandomId(),
@@ -21745,6 +22075,28 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
21745
22075
  }
21746
22076
  serviceWorker;
21747
22077
  messageTag;
22078
+ arkadeCash = (request) => this.cashRequest(request);
22079
+ async cashRequest(request) {
22080
+ const message = {
22081
+ id: getRandomId(),
22082
+ tag: this.messageTag,
22083
+ type: "ARKADE_CASH",
22084
+ payload: request
22085
+ };
22086
+ try {
22087
+ const response = isLongRunningCashAction(request) ? await this.sendMessageWithRetry(message, {
22088
+ onEvent: () => {
22089
+ },
22090
+ isComplete: (resp) => resp.type === "ARKADE_CASH"
22091
+ }) : await this.sendMessage(message);
22092
+ return response.payload;
22093
+ } catch (error) {
22094
+ if (isSerializedArkadeCashCreateError(error)) {
22095
+ throw deserializeArkadeCashCreateError(error);
22096
+ }
22097
+ throw error;
22098
+ }
22099
+ }
21748
22100
  walletRepository;
21749
22101
  contractRepository;
21750
22102
  identity;
@@ -21800,7 +22152,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
21800
22152
  Object.entries(options.messageTimeouts ?? {}).filter(([, ms]) => ms !== void 0)
21801
22153
  );
21802
22154
  for (const [key, value] of Object.entries(overrides)) {
21803
- chunkLZAINCGU_cjs.assertTimerMs(`messageTimeouts.${key}`, value);
22155
+ chunkSOJDUKY6_cjs.assertTimerMs(`messageTimeouts.${key}`, value);
21804
22156
  }
21805
22157
  const messageTimeouts = {
21806
22158
  ...DEFAULT_MESSAGE_TIMEOUTS,
@@ -22145,7 +22497,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
22145
22497
  try {
22146
22498
  const response = await this.sendMessage(message);
22147
22499
  const { vtxos, page } = response.payload;
22148
- return { vtxos: vtxos.map(chunkLZAINCGU_cjs.normalizeVtxo), page: page && { ...page } };
22500
+ return { vtxos: vtxos.map(chunkSOJDUKY6_cjs.normalizeVtxo), page: page && { ...page } };
22149
22501
  } catch (cause) {
22150
22502
  throw new Error(`Failed to get vtxos: ${cause}`, { cause });
22151
22503
  }
@@ -22254,7 +22606,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
22254
22606
  };
22255
22607
  try {
22256
22608
  const response = await this.sendMessage(message);
22257
- return response.payload.vtxos.map(chunkLZAINCGU_cjs.normalizeVtxo);
22609
+ return response.payload.vtxos.map(chunkSOJDUKY6_cjs.normalizeVtxo);
22258
22610
  } catch (error) {
22259
22611
  throw new Error(`Failed to get vtxos: ${error}`);
22260
22612
  }
@@ -22285,7 +22637,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
22285
22637
  "Service worker does not support the requested contract scope or freshness check"
22286
22638
  );
22287
22639
  }
22288
- return payload.vtxos.map(chunkLZAINCGU_cjs.normalizeVtxo);
22640
+ return payload.vtxos.map(chunkSOJDUKY6_cjs.normalizeVtxo);
22289
22641
  } catch (error) {
22290
22642
  throw new Error(`Failed to get spendable vtxos: ${error}`);
22291
22643
  }
@@ -22480,7 +22832,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
22480
22832
  };
22481
22833
  try {
22482
22834
  const response = await sendContractMessage(message);
22483
- return response.payload.vtxos.map(chunkLZAINCGU_cjs.normalizeVtxo);
22835
+ return response.payload.vtxos.map(chunkSOJDUKY6_cjs.normalizeVtxo);
22484
22836
  } catch (cause) {
22485
22837
  throw new Error(`Failed to annotate vtxos: ${cause}`, { cause });
22486
22838
  }
@@ -23152,7 +23504,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
23152
23504
  };
23153
23505
  try {
23154
23506
  const response = await wallet.sendMessage(message);
23155
- return response.payload.vtxos.map(chunkLZAINCGU_cjs.normalizeVtxo);
23507
+ return response.payload.vtxos.map(chunkSOJDUKY6_cjs.normalizeVtxo);
23156
23508
  } catch (e) {
23157
23509
  throw new Error(`Failed to get expiring vtxos: ${e}`);
23158
23510
  }
@@ -23374,7 +23726,7 @@ var OnchainWallet = class _OnchainWallet {
23374
23726
  feeRate,
23375
23727
  params.address
23376
23728
  );
23377
- let tx = new chunkLZAINCGU_cjs.Transaction();
23729
+ let tx = new chunkSOJDUKY6_cjs.Transaction();
23378
23730
  for (const input of inputs) {
23379
23731
  tx.addInput({
23380
23732
  txid: input.txid,
@@ -23432,7 +23784,7 @@ var OnchainWallet = class _OnchainWallet {
23432
23784
  * @throws If the parent has no anchor, or funding cannot be selected/signed
23433
23785
  */
23434
23786
  async bumpAnchor(parentHex, feeRate) {
23435
- const parent = chunkLZAINCGU_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
23787
+ const parent = chunkSOJDUKY6_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
23436
23788
  const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
23437
23789
  const child = await this.buildBumpPackage(parent, feeRate, coins);
23438
23790
  return [parent.hex, child.hex];
@@ -24284,7 +24636,7 @@ var CachingOperatorProvider = class {
24284
24636
  constructor(inner, ttlMs = DEFAULT_TTL_MS) {
24285
24637
  this.inner = inner;
24286
24638
  this.ttlMs = ttlMs;
24287
- chunkLZAINCGU_cjs.assertNonNegativeMs("ttlMs", ttlMs);
24639
+ chunkSOJDUKY6_cjs.assertNonNegativeMs("ttlMs", ttlMs);
24288
24640
  this.unsubscribe = inner.onServerInfoChanged?.((info) => {
24289
24641
  this.cached = info;
24290
24642
  this.expiresAt = Date.now() + this.ttlMs;
@@ -24371,7 +24723,7 @@ exports.BIP322 = void 0;
24371
24723
  async function sign2(message, identity, network) {
24372
24724
  const xOnlyPubKey = await identity.xOnlyPublicKey();
24373
24725
  const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
24374
- const toSpend = chunkLZAINCGU_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
24726
+ const toSpend = chunkSOJDUKY6_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
24375
24727
  const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
24376
24728
  const signed = await identity.sign(toSign, [0]);
24377
24729
  signed.finalizeIdx(0);
@@ -24429,7 +24781,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
24429
24781
  if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
24430
24782
  return false;
24431
24783
  }
24432
- const toSpend = chunkLZAINCGU_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
24784
+ const toSpend = chunkSOJDUKY6_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
24433
24785
  const toSign = craftBIP322ToSignP2TR(toSpend, pkScript);
24434
24786
  const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
24435
24787
  const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
@@ -24450,7 +24802,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
24450
24802
  }
24451
24803
  const sighashType = sigWithHash[sigWithHash.length - 1];
24452
24804
  const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
24453
- const toSpend = chunkLZAINCGU_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
24805
+ const toSpend = chunkSOJDUKY6_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
24454
24806
  const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
24455
24807
  const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
24456
24808
  const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
@@ -24503,7 +24855,7 @@ function encodeCompactSize(n) {
24503
24855
  return buf;
24504
24856
  }
24505
24857
  function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
24506
- const tx = new chunkLZAINCGU_cjs.Transaction({ version: 0 });
24858
+ const tx = new chunkSOJDUKY6_cjs.Transaction({ version: 0 });
24507
24859
  tx.addInput({
24508
24860
  txid: toSpend.id,
24509
24861
  index: 0,
@@ -24517,12 +24869,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
24517
24869
  });
24518
24870
  tx.addOutput({
24519
24871
  amount: 0n,
24520
- script: chunkLZAINCGU_cjs.OP_RETURN_EMPTY_PKSCRIPT
24872
+ script: chunkSOJDUKY6_cjs.OP_RETURN_EMPTY_PKSCRIPT
24521
24873
  });
24522
24874
  return tx;
24523
24875
  }
24524
24876
  function craftBIP322ToSignSimple(toSpend, pkScript) {
24525
- const tx = new chunkLZAINCGU_cjs.Transaction({ version: 0 });
24877
+ const tx = new chunkSOJDUKY6_cjs.Transaction({ version: 0 });
24526
24878
  tx.addInput({
24527
24879
  txid: toSpend.id,
24528
24880
  index: 0,
@@ -24534,12 +24886,12 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
24534
24886
  });
24535
24887
  tx.addOutput({
24536
24888
  amount: 0n,
24537
- script: chunkLZAINCGU_cjs.OP_RETURN_EMPTY_PKSCRIPT
24889
+ script: chunkSOJDUKY6_cjs.OP_RETURN_EMPTY_PKSCRIPT
24538
24890
  });
24539
24891
  return tx;
24540
24892
  }
24541
24893
  function finalizeVirtualTx(type, psbtBase64) {
24542
- const tx = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
24894
+ const tx = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
24543
24895
  if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
24544
24896
  const input = tx.getInput(0);
24545
24897
  if (!input) {
@@ -24573,7 +24925,7 @@ async function resolveUnilateralPath(params) {
24573
24925
  const { vtxo, scriptHex, contractRepository } = params;
24574
24926
  const contract = contractRepository ? (await collectContracts(contractRepository, { script: scriptHex }))[0] : void 0;
24575
24927
  if (contract) {
24576
- const handler = chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type);
24928
+ const handler = chunkJYQXB7OH_cjs.contractHandlers.get(contract.type);
24577
24929
  if (!handler) {
24578
24930
  throw new ExitPathError(
24579
24931
  "no-handler",
@@ -24809,7 +25161,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
24809
25161
  let totalAmount = 0n;
24810
25162
  const txWeightEstimator = TxWeightEstimator.create();
24811
25163
  for (const vtxo of vtxos) {
24812
- if (!chunkLZAINCGU_cjs.canSweepOnchain(vtxo)) {
25164
+ if (!chunkSOJDUKY6_cjs.canSweepOnchain(vtxo)) {
24813
25165
  throw new Error(
24814
25166
  `Vtxo ${vtxo.txid}:${vtxo.vout} cannot be swept onchain: it is not fully unrolled (use unroll first), or its exit output was already spent`
24815
25167
  );
@@ -24861,7 +25213,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
24861
25213
  btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
24862
25214
  );
24863
25215
  }
24864
- const tx = new chunkLZAINCGU_cjs.Transaction({ version: 2 });
25216
+ const tx = new chunkSOJDUKY6_cjs.Transaction({ version: 2 });
24865
25217
  for (const input of inputs) {
24866
25218
  tx.addInput(input);
24867
25219
  }
@@ -24944,7 +25296,7 @@ async function buildSignedSweep(params) {
24944
25296
  `uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
24945
25297
  );
24946
25298
  }
24947
- const tx = new chunkLZAINCGU_cjs.Transaction({ version: 2 });
25299
+ const tx = new chunkSOJDUKY6_cjs.Transaction({ version: 2 });
24948
25300
  tx.addInput({
24949
25301
  txid: vtxo.txid,
24950
25302
  index: vtxo.vout,
@@ -24999,7 +25351,7 @@ async function resolveFeeRate(opts) {
24999
25351
  }
25000
25352
  async function selectExitVtxos(opts) {
25001
25353
  if (!opts.vtxos) return opts.wallet.getVtxos();
25002
- const res = await chunkLZAINCGU_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
25354
+ const res = await chunkSOJDUKY6_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
25003
25355
  const scripts = [
25004
25356
  ...new Set(res.vtxos.filter((vtxo) => !vtxo.isSpent).map((vtxo) => vtxo.script))
25005
25357
  ];
@@ -25017,7 +25369,7 @@ async function selectExitVtxos(opts) {
25017
25369
  `no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
25018
25370
  );
25019
25371
  }
25020
- const handler = chunkNDQ4LB4X_cjs.contractHandlers.get(contract.type);
25372
+ const handler = chunkJYQXB7OH_cjs.contractHandlers.get(contract.type);
25021
25373
  if (!handler) {
25022
25374
  throw new Error(`no contract handler registered for type '${contract.type}'`);
25023
25375
  }
@@ -25051,7 +25403,7 @@ async function computeExitLayout(opts, feeRate) {
25051
25403
  if (pendingNodes.length > 0) {
25052
25404
  const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
25053
25405
  for (const psbt of txs) {
25054
- psbts.set(chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
25406
+ psbts.set(chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
25055
25407
  }
25056
25408
  }
25057
25409
  const childVsize = Number(
@@ -25216,7 +25568,7 @@ var Executor = class {
25216
25568
  constructor(pkg, provider, opts) {
25217
25569
  this.pkg = pkg;
25218
25570
  this.provider = provider;
25219
- chunkLZAINCGU_cjs.assertTimerMs("pollIntervalMs", opts?.pollIntervalMs);
25571
+ chunkSOJDUKY6_cjs.assertTimerMs("pollIntervalMs", opts?.pollIntervalMs);
25220
25572
  this.pollIntervalMs = opts?.pollIntervalMs ?? 5e3;
25221
25573
  this.feeWallet = opts?.feeWallet;
25222
25574
  this.signal = opts?.signal;
@@ -25600,7 +25952,7 @@ async function prepare(opts) {
25600
25952
  if (newFee <= splitterFee) break;
25601
25953
  splitterFee = newFee;
25602
25954
  }
25603
- const splitter = new chunkLZAINCGU_cjs.Transaction({ version: 2 });
25955
+ const splitter = new chunkSOJDUKY6_cjs.Transaction({ version: 2 });
25604
25956
  for (const coin of selected.inputs) {
25605
25957
  splitter.addInput({
25606
25958
  txid: coin.txid,
@@ -25740,46 +26092,46 @@ var UnilateralExit = {
25740
26092
  // src/arkade/index.ts
25741
26093
  var arkade_exports = {};
25742
26094
  chunkFLPWNMX3_cjs.__export(arkade_exports, {
25743
- ARKADE_OP: () => chunkJFJNB7ZH_cjs.ARKADE_OP,
25744
- ARKADE_OPCODES: () => chunkJFJNB7ZH_cjs.ARKADE_OPCODES,
25745
- ARKADE_OPCODE_NAMES: () => chunkJFJNB7ZH_cjs.ARKADE_OPCODE_NAMES,
25746
- ARKADE_OPCODE_VALUES: () => chunkJFJNB7ZH_cjs.ARKADE_OPCODE_VALUES,
25747
- ARKADE_OPS: () => chunkJFJNB7ZH_cjs.ARKADE_OPS,
26095
+ ARKADE_OP: () => chunk5PWL7WOT_cjs.ARKADE_OP,
26096
+ ARKADE_OPCODES: () => chunk5PWL7WOT_cjs.ARKADE_OPCODES,
26097
+ ARKADE_OPCODE_NAMES: () => chunk5PWL7WOT_cjs.ARKADE_OPCODE_NAMES,
26098
+ ARKADE_OPCODE_VALUES: () => chunk5PWL7WOT_cjs.ARKADE_OPCODE_VALUES,
26099
+ ARKADE_OPS: () => chunk5PWL7WOT_cjs.ARKADE_OPS,
25748
26100
  Arkade: () => Arkade,
25749
26101
  ArkadeContract: () => ArkadeContract,
25750
- ArkadeProgramScript: () => chunkJFJNB7ZH_cjs.ArkadeProgramScript,
25751
- ArkadeScript: () => chunkJFJNB7ZH_cjs.ArkadeScript,
26102
+ ArkadeProgramScript: () => chunk5PWL7WOT_cjs.ArkadeProgramScript,
26103
+ ArkadeScript: () => chunk5PWL7WOT_cjs.ArkadeScript,
25752
26104
  ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
25753
- BigNum: () => chunkJFJNB7ZH_cjs.bignum_exports,
26105
+ BigNum: () => chunk5PWL7WOT_cjs.bignum_exports,
25754
26106
  OP: () => btcSigner.OP,
25755
- OPCODE_NAMES: () => chunkJFJNB7ZH_cjs.OPCODE_NAMES,
25756
- OPCODE_VALUES: () => chunkJFJNB7ZH_cjs.OPCODE_VALUES,
25757
- SUPPORTED_PROGRAM_VERSION: () => chunkJFJNB7ZH_cjs.SUPPORTED_PROGRAM_VERSION,
26107
+ OPCODE_NAMES: () => chunk5PWL7WOT_cjs.OPCODE_NAMES,
26108
+ OPCODE_VALUES: () => chunk5PWL7WOT_cjs.OPCODE_VALUES,
26109
+ SUPPORTED_PROGRAM_VERSION: () => chunk5PWL7WOT_cjs.SUPPORTED_PROGRAM_VERSION,
25758
26110
  Script: () => btcSigner.Script,
25759
- UnsupportedProgramVersionError: () => chunkJFJNB7ZH_cjs.UnsupportedProgramVersionError,
25760
- arkadeScriptHash: () => chunkJFJNB7ZH_cjs.arkadeScriptHash,
25761
- arkadeWitnessHash: () => chunkJFJNB7ZH_cjs.arkadeWitnessHash,
25762
- asmToBytes: () => chunkJFJNB7ZH_cjs.asmToBytes,
25763
- bytesToASM: () => chunkJFJNB7ZH_cjs.bytesToASM,
25764
- computeArkadeScriptPublicKey: () => chunkJFJNB7ZH_cjs.computeArkadeScriptPublicKey,
26111
+ UnsupportedProgramVersionError: () => chunk5PWL7WOT_cjs.UnsupportedProgramVersionError,
26112
+ arkadeScriptHash: () => chunk5PWL7WOT_cjs.arkadeScriptHash,
26113
+ arkadeWitnessHash: () => chunk5PWL7WOT_cjs.arkadeWitnessHash,
26114
+ asmToBytes: () => chunk5PWL7WOT_cjs.asmToBytes,
26115
+ bytesToASM: () => chunk5PWL7WOT_cjs.bytesToASM,
26116
+ computeArkadeScriptPublicKey: () => chunk5PWL7WOT_cjs.computeArkadeScriptPublicKey,
25765
26117
  createArkadeBatchHandler: () => createArkadeBatchHandler,
25766
- deserializeArkadeContractParams: () => chunkJFJNB7ZH_cjs.deserializeArkadeContractParams,
25767
- fromASM: () => chunkJFJNB7ZH_cjs.fromASM,
25768
- getOpcodeName: () => chunkJFJNB7ZH_cjs.getOpcodeName,
25769
- getOpcodeValue: () => chunkJFJNB7ZH_cjs.getOpcodeValue,
25770
- isContractArtifact: () => chunkX6ZI53DZ_cjs.isContractArtifact,
25771
- parseArtifact: () => chunkJFJNB7ZH_cjs.parseArtifact,
25772
- programFromArtifact: () => chunkX6ZI53DZ_cjs.programFromArtifact,
26118
+ deserializeArkadeContractParams: () => chunk5PWL7WOT_cjs.deserializeArkadeContractParams,
26119
+ fromASM: () => chunk5PWL7WOT_cjs.fromASM,
26120
+ getOpcodeName: () => chunk5PWL7WOT_cjs.getOpcodeName,
26121
+ getOpcodeValue: () => chunk5PWL7WOT_cjs.getOpcodeValue,
26122
+ isContractArtifact: () => chunkL7OOPAUG_cjs.isContractArtifact,
26123
+ parseArtifact: () => chunk5PWL7WOT_cjs.parseArtifact,
26124
+ programFromArtifact: () => chunkL7OOPAUG_cjs.programFromArtifact,
25773
26125
  renewProgramContractOutputs: () => renewProgramContractOutputs,
25774
26126
  resolveArkadeService: () => resolveArkadeService,
25775
- resolveAsm: () => chunkJFJNB7ZH_cjs.resolveAsm,
25776
- serializeArkadeContractParams: () => chunkJFJNB7ZH_cjs.serializeArkadeContractParams,
25777
- stringifyArtifact: () => chunkJFJNB7ZH_cjs.stringifyArtifact,
25778
- toASM: () => chunkJFJNB7ZH_cjs.toASM,
25779
- validateProgram: () => chunkJFJNB7ZH_cjs.validateProgram,
25780
- witnessRefToBytes: () => chunkJFJNB7ZH_cjs.witnessRefToBytes
26127
+ resolveAsm: () => chunk5PWL7WOT_cjs.resolveAsm,
26128
+ serializeArkadeContractParams: () => chunk5PWL7WOT_cjs.serializeArkadeContractParams,
26129
+ stringifyArtifact: () => chunk5PWL7WOT_cjs.stringifyArtifact,
26130
+ toASM: () => chunk5PWL7WOT_cjs.toASM,
26131
+ validateProgram: () => chunk5PWL7WOT_cjs.validateProgram,
26132
+ witnessRefToBytes: () => chunk5PWL7WOT_cjs.witnessRefToBytes
25781
26133
  });
25782
- var isVtxoCoin = (input) => chunkLZAINCGU_cjs.isVirtualCoin(input);
26134
+ var isVtxoCoin = (input) => chunkSOJDUKY6_cjs.isVirtualCoin(input);
25783
26135
  function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients, batchExpiryPolicy) {
25784
26136
  if (!signer && inputs.some((input) => !isVtxoCoin(input))) {
25785
26137
  throw new Error("createArkadeBatchHandler: boarding inputs need a signer");
@@ -25808,21 +26160,21 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
25808
26160
  batchId = event.id;
25809
26161
  const sweepTapscript = chunkFLPWNMX3_cjs.CSVMultisigTapscript.encode({
25810
26162
  timelock,
25811
- pubkeys: [chunkJFJNB7ZH_cjs.toXOnly(base.hex.decode(info.forfeitPubkey), "forfeit key")]
26163
+ pubkeys: [chunk5PWL7WOT_cjs.toXOnly(base.hex.decode(info.forfeitPubkey), "forfeit key")]
25812
26164
  }).script;
25813
26165
  sweepTapTreeRoot = payment_js.tapLeafHash(sweepTapscript);
25814
26166
  return { skip: false };
25815
26167
  },
25816
26168
  onTreeSigningStarted: async (event, vtxoTree) => {
25817
26169
  const signerPubKey = await session.getPublicKey();
25818
- const xonlySignerPubKey = chunkJFJNB7ZH_cjs.toXOnly(signerPubKey, "signer key");
26170
+ const xonlySignerPubKey = chunk5PWL7WOT_cjs.toXOnly(signerPubKey, "signer key");
25819
26171
  const xOnlyPubkeys = event.cosignersPublicKeys.map(
25820
- (k) => base.hex.encode(chunkJFJNB7ZH_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
26172
+ (k) => base.hex.encode(chunk5PWL7WOT_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
25821
26173
  );
25822
26174
  if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
25823
26175
  return { skip: true };
25824
26176
  }
25825
- const commitmentTx = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
26177
+ const commitmentTx = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
25826
26178
  validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
25827
26179
  if (recipients && recipients.length > 0) {
25828
26180
  validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
@@ -25860,7 +26212,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
25860
26212
  if (connectorTree) {
25861
26213
  validateConnectorsTxGraph(event.commitmentTx, connectorTree);
25862
26214
  }
25863
- let commitmentPsbt = chunkLZAINCGU_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
26215
+ let commitmentPsbt = chunkSOJDUKY6_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
25864
26216
  assertFinalCommitmentMatchesValidated(
25865
26217
  commitmentPsbt,
25866
26218
  validatedCommitmentTxid,
@@ -25902,7 +26254,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
25902
26254
  boardingIndices.push(boardingIdx);
25903
26255
  continue;
25904
26256
  }
25905
- if (!chunkLZAINCGU_cjs.requiresForfeit(input) || isSubdust(input, info.dust)) {
26257
+ if (!chunkSOJDUKY6_cjs.requiresForfeit(input) || isSubdust(input, info.dust)) {
25906
26258
  continue;
25907
26259
  }
25908
26260
  if (connectorIndex >= connectorLeaves.length) {
@@ -25940,7 +26292,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
25940
26292
  forfeitOutputScript
25941
26293
  );
25942
26294
  if (input.extraWitness?.length) {
25943
- chunkLZAINCGU_cjs.setArkPsbtField(forfeitTx, 0, chunkLZAINCGU_cjs.ConditionWitness, input.extraWitness);
26295
+ chunkSOJDUKY6_cjs.setArkPsbtField(forfeitTx, 0, chunkSOJDUKY6_cjs.ConditionWitness, input.extraWitness);
25944
26296
  }
25945
26297
  if (signer) forfeitTx = await signer.sign(forfeitTx, [0]);
25946
26298
  signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
@@ -26024,8 +26376,8 @@ async function renewProgramContractOutputs(client, targets, opts = {}) {
26024
26376
  if (compiled.def.tapscript.csv) {
26025
26377
  throw new Error(`renewProgramContractOutputs: ${fn} has a CSV timelock`);
26026
26378
  }
26027
- const condition = chunkJFJNB7ZH_cjs.staticWitness(compiled.def.tapscript.witness, contract.args);
26028
- const stack = chunkJFJNB7ZH_cjs.staticWitness(compiled.def.arkadeScript?.witness, contract.args);
26379
+ const condition = chunk5PWL7WOT_cjs.staticWitness(compiled.def.tapscript.witness, contract.args);
26380
+ const stack = chunk5PWL7WOT_cjs.staticWitness(compiled.def.arkadeScript?.witness, contract.args);
26029
26381
  if (!condition || !stack) {
26030
26382
  throw new Error(
26031
26383
  `renewProgramContractOutputs: ${fn} needs call arguments, which a renewal cannot supply`
@@ -26035,7 +26387,7 @@ async function renewProgramContractOutputs(client, targets, opts = {}) {
26035
26387
  });
26036
26388
  const { fees } = await arkProvider.getInfo();
26037
26389
  const fee = new Estimator(fees?.intentFee ?? {}).evaluate(
26038
- legs.map(({ coin }) => chunkLZAINCGU_cjs.toOffchainInputFeeParams(chunkLZAINCGU_cjs.normalizeVtxo(coin))),
26390
+ legs.map(({ coin }) => chunkSOJDUKY6_cjs.toOffchainInputFeeParams(chunkSOJDUKY6_cjs.normalizeVtxo(coin))),
26039
26391
  [],
26040
26392
  legs.map(({ contract, coin }) => ({
26041
26393
  amount: BigInt(coin.value),
@@ -26098,7 +26450,7 @@ async function renewProgramContractOutputs(client, targets, opts = {}) {
26098
26450
  const [signedProof, deleteProof] = await Promise.all(
26099
26451
  [message, deleteMessage].map(
26100
26452
  (m) => emulator.submitIntent({
26101
- proof: base.base64.encode(chunkLZAINCGU_cjs.Proof.create(m, coins, outputs).toPSBT()),
26453
+ proof: base.base64.encode(chunkSOJDUKY6_cjs.Proof.create(m, coins, outputs).toPSBT()),
26102
26454
  message: m
26103
26455
  })
26104
26456
  )
@@ -26250,7 +26602,7 @@ var Arkade = class _Arkade {
26250
26602
  indexer = opts.indexer;
26251
26603
  info = await opts.arkade.getInfo();
26252
26604
  }
26253
- const serverKey = chunkJFJNB7ZH_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
26605
+ const serverKey = chunk5PWL7WOT_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
26254
26606
  const checkpoint = chunkFLPWNMX3_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
26255
26607
  const network = opts.network ?? (Object.hasOwn(chunkFLPWNMX3_cjs.networks, info.network) ? chunkFLPWNMX3_cjs.getNetwork(info.network) : chunkFLPWNMX3_cjs.DEFAULT_NETWORK);
26256
26608
  let emulatorKey;
@@ -26259,7 +26611,7 @@ var Arkade = class _Arkade {
26259
26611
  }
26260
26612
  let userKey;
26261
26613
  if (opts.identity) {
26262
- userKey = chunkJFJNB7ZH_cjs.toXOnly(await opts.identity.xOnlyPublicKey(), "identity key");
26614
+ userKey = chunk5PWL7WOT_cjs.toXOnly(await opts.identity.xOnlyPublicKey(), "identity key");
26263
26615
  }
26264
26616
  let contractManager = opts.contractManager;
26265
26617
  let ownsContractManager = false;
@@ -26410,7 +26762,7 @@ var ArkadeContract = class _ArkadeContract {
26410
26762
  userKey: client.userKey,
26411
26763
  emulatorKey: client.emulatorKey
26412
26764
  };
26413
- this.vtxoScript = new chunkJFJNB7ZH_cjs.ArkadeProgramScript(program, this.args, this.keys);
26765
+ this.vtxoScript = new chunk5PWL7WOT_cjs.ArkadeProgramScript(program, this.args, this.keys);
26414
26766
  this.tapTree = this.vtxoScript.encode();
26415
26767
  this.compiled = this.vtxoScript.compiled;
26416
26768
  }
@@ -26436,7 +26788,7 @@ var ArkadeContract = class _ArkadeContract {
26436
26788
  `ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
26437
26789
  );
26438
26790
  }
26439
- const typed = chunkJFJNB7ZH_cjs.deserializeArkadeContractParams(contract.params);
26791
+ const typed = chunk5PWL7WOT_cjs.deserializeArkadeContractParams(contract.params);
26440
26792
  return new _ArkadeContract(client, typed.program, typed.args, {
26441
26793
  serverKey: typed.serverKey,
26442
26794
  userKey: typed.userKey,
@@ -26457,14 +26809,17 @@ var ArkadeContract = class _ArkadeContract {
26457
26809
  get pkScript() {
26458
26810
  return this.vtxoScript.pkScript;
26459
26811
  }
26460
- /** Callable spending paths: `functions.<name>(...args)` (see {@link ContractFunctions}). */
26812
+ /**
26813
+ * Callable spending paths: `functions.<name>({ tapscript: [...], arkadeScript: [...] })`
26814
+ * (see {@link ContractFunctions}).
26815
+ */
26461
26816
  get functions() {
26462
26817
  const out = /* @__PURE__ */ Object.create(null);
26463
26818
  for (const fn of this.compiled) {
26464
26819
  out[fn.name] = (...callArgs) => new ArkadeTransactionBuilder(this.client, {
26465
26820
  contract: this,
26466
26821
  fn,
26467
- args: bindInputs(fn, callArgs)
26822
+ args: bindCall(fn, callArgs)
26468
26823
  });
26469
26824
  }
26470
26825
  return out;
@@ -26476,7 +26831,7 @@ var ArkadeContract = class _ArkadeContract {
26476
26831
  out[fn.name] = (...callArgs) => ({
26477
26832
  contract: this,
26478
26833
  fn,
26479
- args: bindInputs(fn, callArgs)
26834
+ args: bindCall(fn, callArgs)
26480
26835
  });
26481
26836
  }
26482
26837
  return out;
@@ -26488,7 +26843,7 @@ var ArkadeContract = class _ArkadeContract {
26488
26843
  toContractParams() {
26489
26844
  return {
26490
26845
  type: "arkade",
26491
- params: chunkJFJNB7ZH_cjs.serializeArkadeContractParams({
26846
+ params: chunk5PWL7WOT_cjs.serializeArkadeContractParams({
26492
26847
  program: this.program,
26493
26848
  args: this.args,
26494
26849
  serverKey: this.keys.serverKey,
@@ -26575,17 +26930,17 @@ var ArkadeContract = class _ArkadeContract {
26575
26930
  const [registered] = await manager.getContracts({ script: scriptHex });
26576
26931
  if (registered) {
26577
26932
  const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
26578
- return (withVtxos?.vtxos ?? []).filter((v) => !chunkLZAINCGU_cjs.isVtxoSpent(v) && !v.isUnrolled);
26933
+ return (withVtxos?.vtxos ?? []).filter((v) => !chunkSOJDUKY6_cjs.isVtxoSpent(v) && !v.isUnrolled);
26579
26934
  }
26580
26935
  }
26581
26936
  if (!this.client.indexer) {
26582
26937
  throw new Error("ArkadeContract.getUtxos: an indexer is required");
26583
26938
  }
26584
- const { vtxos } = await chunkLZAINCGU_cjs.getNormalizedVtxos(this.client.indexer, {
26939
+ const { vtxos } = await chunkSOJDUKY6_cjs.getNormalizedVtxos(this.client.indexer, {
26585
26940
  scripts: [scriptHex],
26586
26941
  spendableOnly: true
26587
26942
  });
26588
- return vtxos.filter((v) => !chunkLZAINCGU_cjs.isVtxoSpent(v) && !v.isUnrolled);
26943
+ return vtxos.filter((v) => !chunkSOJDUKY6_cjs.isVtxoSpent(v) && !v.isUnrolled);
26589
26944
  }
26590
26945
  /** Total spendable balance (requires an indexer). */
26591
26946
  async getBalance() {
@@ -26751,7 +27106,7 @@ var ArkadeTransactionBuilder = class {
26751
27106
  this.client.checkpoint
26752
27107
  );
26753
27108
  inputs.forEach(({ coin }, i) => {
26754
- if (coin.sourceTx) chunkLZAINCGU_cjs.setArkPsbtField(arkTx, i, chunkLZAINCGU_cjs.PrevArkTxField, coin.sourceTx);
27109
+ if (coin.sourceTx) chunkSOJDUKY6_cjs.setArkPsbtField(arkTx, i, chunkSOJDUKY6_cjs.PrevArkTxField, coin.sourceTx);
26755
27110
  });
26756
27111
  if (inputs.some(({ unlocker }) => unlocker.fn.arkadeScript)) {
26757
27112
  const indexer = this.client.indexer;
@@ -26768,11 +27123,11 @@ var ArkadeTransactionBuilder = class {
26768
27123
  }
26769
27124
  inputs.forEach(({ unlocker }, i) => {
26770
27125
  const condition = (unlocker.fn.def.tapscript.witness ?? []).map(
26771
- (w) => witnessBytes(unlocker, w)
27126
+ (w) => witnessBytes(unlocker, "tapscript", w)
26772
27127
  );
26773
27128
  if (condition.length === 0) return;
26774
- chunkLZAINCGU_cjs.setArkPsbtField(arkTx, i, chunkLZAINCGU_cjs.ConditionWitness, condition);
26775
- chunkLZAINCGU_cjs.setArkPsbtField(checkpoints[i], 0, chunkLZAINCGU_cjs.ConditionWitness, condition);
27129
+ chunkSOJDUKY6_cjs.setArkPsbtField(arkTx, i, chunkSOJDUKY6_cjs.ConditionWitness, condition);
27130
+ chunkSOJDUKY6_cjs.setArkPsbtField(checkpoints[i], 0, chunkSOJDUKY6_cjs.ConditionWitness, condition);
26776
27131
  });
26777
27132
  const packets = [];
26778
27133
  if (this.assetSpecs.length > 0) {
@@ -26781,7 +27136,9 @@ var ArkadeTransactionBuilder = class {
26781
27136
  const entries = inputs.flatMap(({ unlocker }, vin) => {
26782
27137
  const { arkadeScript, def } = unlocker.fn;
26783
27138
  if (!arkadeScript) return [];
26784
- const stack = (def.arkadeScript?.witness ?? []).map((w) => witnessBytes(unlocker, w));
27139
+ const stack = (def.arkadeScript?.witness ?? []).map(
27140
+ (w) => witnessBytes(unlocker, "arkadeScript", w)
27141
+ );
26785
27142
  return [{ vin, script: arkadeScript, witness: btcSigner.RawWitness.encode(stack) }];
26786
27143
  });
26787
27144
  if (entries.length > 0) {
@@ -26835,10 +27192,12 @@ var ArkadeTransactionBuilder = class {
26835
27192
  );
26836
27193
  }
26837
27194
  const { sequence, lockTime } = this.leafTimelocks(fn);
26838
- const tx = new chunkLZAINCGU_cjs.Transaction({ version: 2, lockTime });
27195
+ const tx = new chunkSOJDUKY6_cjs.Transaction({ version: 2, lockTime });
26839
27196
  tx.addInput({ txid: base.hex.decode(coin.txid), index: coin.vout, sequence });
26840
27197
  for (const o of outputs) tx.addOutput(o);
26841
- const condition = (fn.def.tapscript.witness ?? []).map((w) => witnessBytes(unlocker, w));
27198
+ const condition = (fn.def.tapscript.witness ?? []).map(
27199
+ (w) => witnessBytes(unlocker, "tapscript", w)
27200
+ );
26842
27201
  prepareOwnedInput(tx, {
26843
27202
  index: 0,
26844
27203
  coin: { value: coin.value, script: base.hex.encode(contract.pkScript) },
@@ -26847,7 +27206,7 @@ var ArkadeTransactionBuilder = class {
26847
27206
  });
26848
27207
  if (fn.arkadeScript) {
26849
27208
  const stack = (fn.def.arkadeScript?.witness ?? []).map(
26850
- (w) => witnessBytes(unlocker, w)
27209
+ (w) => witnessBytes(unlocker, "arkadeScript", w)
26851
27210
  );
26852
27211
  attachExtension(tx, [
26853
27212
  EmulatorPacket.create([
@@ -26999,20 +27358,20 @@ var ArkadeTransactionBuilder = class {
26999
27358
  * A caller's packet counts for every input, unread; arkd checks what it actually routes.
27000
27359
  */
27001
27360
  routesAssetsFrom(vin) {
27002
- return this.extraPackets.some((p) => p.type() === chunkHKEPJBTY_cjs.Packet.PACKET_TYPE) || this.assetSpecs.some((spec) => spec.inputs.some((i) => i.vin === vin));
27361
+ return this.extraPackets.some((p) => p.type() === chunk4IDCSOP2_cjs.Packet.PACKET_TYPE) || this.assetSpecs.some((spec) => spec.inputs.some((i) => i.vin === vin));
27003
27362
  }
27004
27363
  buildAssetPacket() {
27005
27364
  const groups = this.assetSpecs.map((s) => {
27006
- const id = typeof s.assetId === "string" ? chunkHKEPJBTY_cjs.AssetId.fromString(s.assetId) : chunkHKEPJBTY_cjs.AssetId.fromBytes(s.assetId);
27007
- return chunkHKEPJBTY_cjs.AssetGroup.create(
27365
+ const id = typeof s.assetId === "string" ? chunk4IDCSOP2_cjs.AssetId.fromString(s.assetId) : chunk4IDCSOP2_cjs.AssetId.fromBytes(s.assetId);
27366
+ return chunk4IDCSOP2_cjs.AssetGroup.create(
27008
27367
  id,
27009
27368
  null,
27010
- s.inputs.map((i) => chunkHKEPJBTY_cjs.AssetInput.create(i.vin, i.amount)),
27011
- s.outputs.map((o) => chunkHKEPJBTY_cjs.AssetOutput.create(o.vout, o.amount)),
27012
- (s.metadata ?? []).map((m) => chunkHKEPJBTY_cjs.Metadata.create(m.key, m.value))
27369
+ s.inputs.map((i) => chunk4IDCSOP2_cjs.AssetInput.create(i.vin, i.amount)),
27370
+ s.outputs.map((o) => chunk4IDCSOP2_cjs.AssetOutput.create(o.vout, o.amount)),
27371
+ (s.metadata ?? []).map((m) => chunk4IDCSOP2_cjs.Metadata.create(m.key, m.value))
27013
27372
  );
27014
27373
  });
27015
- return chunkHKEPJBTY_cjs.Packet.create(groups);
27374
+ return chunk4IDCSOP2_cjs.Packet.create(groups);
27016
27375
  }
27017
27376
  };
27018
27377
  function unspendable(coin, now) {
@@ -27020,8 +27379,8 @@ function unspendable(coin, now) {
27020
27379
  if (coin.expiresAt && now >= new Date(coin.expiresAt).getTime()) return "has expired";
27021
27380
  return void 0;
27022
27381
  }
27023
- function witnessBytes({ contract, args }, ref) {
27024
- return chunkJFJNB7ZH_cjs.witnessRefToBytes(ref, args, contract.args);
27382
+ function witnessBytes({ contract, args }, segment, ref) {
27383
+ return chunk5PWL7WOT_cjs.witnessRefToBytes(ref, args[segment], contract.args);
27025
27384
  }
27026
27385
  function flattenValue(name, value, out, ancestors = /* @__PURE__ */ new Set()) {
27027
27386
  if (typeof value !== "object" || value === null || ArrayBuffer.isView(value)) {
@@ -27047,35 +27406,44 @@ function flattenValue(name, value, out, ancestors = /* @__PURE__ */ new Set()) {
27047
27406
  for (const [key, item] of entries) flattenValue(`${name}.${key}`, item, out, ancestors);
27048
27407
  ancestors.delete(value);
27049
27408
  }
27050
- function bindInputs(fn, callArgs) {
27051
- const inputs = fn.def.inputs ?? [];
27409
+ function bindCall({ name, def }, callArgs) {
27410
+ const [args = {}] = callArgs;
27411
+ const proto = typeof args === "object" && args !== null && Object.getPrototypeOf(args);
27412
+ if (callArgs.length > 1 || proto !== Object.prototype && proto !== null || Object.entries(args).some(
27413
+ ([key, value]) => key !== "tapscript" && key !== "arkadeScript" || value !== void 0 && !Array.isArray(value)
27414
+ )) {
27415
+ throw new Error(
27416
+ `${name}: expected one { arkadeScript?: [...], tapscript?: [...] } argument`
27417
+ );
27418
+ }
27419
+ const { tapscript = [], arkadeScript = [] } = args;
27420
+ return {
27421
+ arkadeScript: bindInputs(
27422
+ `${name} arkadeScript`,
27423
+ def.arkadeScript?.inputs ?? [],
27424
+ arkadeScript
27425
+ ),
27426
+ tapscript: bindInputs(`${name} tapscript`, def.tapscript.inputs ?? [], tapscript)
27427
+ };
27428
+ }
27429
+ function bindInputs(label, inputs, callArgs) {
27052
27430
  const declared = /* @__PURE__ */ new Set();
27053
27431
  for (const def of inputs) {
27054
- if (declared.has(def.name)) throw new Error(`${fn.name}: duplicate input '${def.name}'`);
27432
+ if (declared.has(def.name)) throw new Error(`${label}: duplicate input '${def.name}'`);
27055
27433
  declared.add(def.name);
27056
27434
  }
27057
- const params = [
27058
- ...new Map(
27059
- inputs.map(({ name }) => {
27060
- const root = name.split(".")[0];
27061
- return [name.includes(".") ? `${root}.` : root, root];
27062
- })
27063
- ).values()
27064
- ];
27435
+ const params = [...new Set(inputs.map(({ name }) => name.split(".")[0]))];
27065
27436
  if (callArgs.length !== params.length) {
27066
- throw new Error(
27067
- `${fn.name}: expected ${params.length} argument(s), got ${callArgs.length}`
27068
- );
27437
+ throw new Error(`${label}: expected ${params.length} argument(s), got ${callArgs.length}`);
27069
27438
  }
27070
27439
  const bound = /* @__PURE__ */ Object.create(null);
27071
27440
  params.forEach((param, i) => flattenValue(param, callArgs[i], bound));
27072
27441
  for (const name of Object.keys(bound)) {
27073
- if (!declared.has(name)) throw new Error(`${fn.name}: unexpected input '${name}'`);
27442
+ if (!declared.has(name)) throw new Error(`${label}: unexpected input '${name}'`);
27074
27443
  }
27075
27444
  for (const def of inputs) {
27076
- if (bound[def.name] === void 0)
27077
- throw new Error(`${fn.name}: missing input '${def.name}'`);
27078
- chunkJFJNB7ZH_cjs.validateParamValue(def, bound[def.name]);
27445
+ if (bound[def.name] === void 0) throw new Error(`${label}: missing input '${def.name}'`);
27446
+ chunk5PWL7WOT_cjs.validateParamValue(def, bound[def.name]);
27079
27447
  }
27080
27448
  return bound;
27081
27449
  }
@@ -27485,14 +27853,14 @@ var walletFeeSource = (wallet) => async () => (await wallet.arkProvider.getInfo(
27485
27853
  function offchainInputFees(vtxos, fees) {
27486
27854
  const estimator = new Estimator(fees?.intentFee ?? {});
27487
27855
  return vtxos.reduce(
27488
- (total, vtxo) => total + estimator.evalOffchainInput(chunkLZAINCGU_cjs.toOffchainInputFeeParams(vtxo)).satoshis,
27856
+ (total, vtxo) => total + estimator.evalOffchainInput(chunkSOJDUKY6_cjs.toOffchainInputFeeParams(vtxo)).satoshis,
27489
27857
  0
27490
27858
  );
27491
27859
  }
27492
27860
  async function changeOutputFee(wallet, inputs, needed, fees) {
27493
27861
  const estimator = new Estimator(fees?.intentFee ?? {});
27494
27862
  const net = inputs.reduce(
27495
- (total, vtxo) => total + BigInt(vtxo.value) - BigInt(estimator.evalOffchainInput(chunkLZAINCGU_cjs.toOffchainInputFeeParams(vtxo)).satoshis),
27863
+ (total, vtxo) => total + BigInt(vtxo.value) - BigInt(estimator.evalOffchainInput(chunkSOJDUKY6_cjs.toOffchainInputFeeParams(vtxo)).satoshis),
27496
27864
  0n
27497
27865
  );
27498
27866
  const script = base.hex.encode(chunkFLPWNMX3_cjs.ArkAddress.decode(await wallet.getAddress()).pkScript);
@@ -27665,11 +28033,14 @@ exports.WalletCannotSignError = WalletCannotSignError;
27665
28033
  exports.WalletMessageHandler = WalletMessageHandler;
27666
28034
  exports.WalletNotInitializedError = WalletNotInitializedError;
27667
28035
  exports.WsElectrumChainSource = WsElectrumChainSource;
28036
+ exports.addArkadeCashRecord = addArkadeCashRecord;
27668
28037
  exports.adoptContractDescriptor = adoptContractDescriptor;
27669
28038
  exports.applyWalletStateUpdate = applyWalletStateUpdate;
27670
28039
  exports.arkAssetRail = arkAssetRail;
27671
28040
  exports.arkRail = arkRail;
27672
28041
  exports.arkTarget = arkTarget;
28042
+ exports.arkadeCashId = arkadeCashId;
28043
+ exports.arkadeCashResolver = arkadeCashResolver;
27673
28044
  exports.arkade_exports = arkade_exports;
27674
28045
  exports.assertFinalCommitmentMatchesValidated = assertFinalCommitmentMatchesValidated;
27675
28046
  exports.assertHistoryPageFilter = assertHistoryPageFilter;
@@ -27716,6 +28087,7 @@ exports.contractFromArkContract = contractFromArkContract;
27716
28087
  exports.contractFromArkContractWithAddress = contractFromArkContractWithAddress;
27717
28088
  exports.contractPreimage = contractPreimage;
27718
28089
  exports.contractSigner = contractSigner;
28090
+ exports.createArkadeCashTracker = createArkadeCashTracker;
27719
28091
  exports.createAssetPacket = createAssetPacket;
27720
28092
  exports.createDefaultActivityRegistry = createDefaultActivityRegistry;
27721
28093
  exports.createDefaultPaymentRouter = createDefaultPaymentRouter;
@@ -27772,6 +28144,7 @@ exports.legacyVtxoFacts = legacyVtxoFacts;
27772
28144
  exports.logExcludedVtxos = logExcludedVtxos;
27773
28145
  exports.makeHandle = makeHandle;
27774
28146
  exports.matchServerCheckpoints = matchServerCheckpoints;
28147
+ exports.mergeArkadeCashRecord = mergeArkadeCashRecord;
27775
28148
  exports.mergeChainedTxType = mergeChainedTxType;
27776
28149
  exports.mnemonicFromPrf = mnemonicFromPrf;
27777
28150
  exports.notifyExitObserved = notifyExitObserved;
@@ -27784,6 +28157,7 @@ exports.prfSupport = prfSupport;
27784
28157
  exports.promisifyRequest = promisifyRequest;
27785
28158
  exports.provisionClaimSecret = provisionClaimSecret;
27786
28159
  exports.provisionRefundKey = provisionRefundKey;
28160
+ exports.readArkadeCash = readArkadeCash;
27787
28161
  exports.registerWalletRestoreHook = registerWalletRestoreHook;
27788
28162
  exports.resolveAssetAmount = resolveAssetAmount;
27789
28163
  exports.resolveBatchExpiryPolicy = resolveBatchExpiryPolicy;
@@ -27817,5 +28191,5 @@ exports.waitForIncomingFunds = waitForIncomingFunds;
27817
28191
  exports.walletFeeSource = walletFeeSource;
27818
28192
  exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
27819
28193
  exports.withPrevTxs = withPrevTxs;
27820
- //# sourceMappingURL=chunk-Y3CDDPWI.cjs.map
27821
- //# sourceMappingURL=chunk-Y3CDDPWI.cjs.map
28194
+ //# sourceMappingURL=chunk-EQ3JVVUR.cjs.map
28195
+ //# sourceMappingURL=chunk-EQ3JVVUR.cjs.map