@arkade-os/sdk 0.4.71 → 0.4.73

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 (80) hide show
  1. package/README.md +29 -0
  2. package/dist/adapters/expo.cjs +5 -5
  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/adapters/indexedDB.cjs +5 -5
  7. package/dist/adapters/indexedDB.js +4 -4
  8. package/dist/{asyncStorageTaskQueue-CjKAUiuj.d.ts → asyncStorageTaskQueue-C5IwA_Hs.d.ts} +1 -1
  9. package/dist/{asyncStorageTaskQueue-DgXf4iuU.d.cts → asyncStorageTaskQueue-DA2OdpJ0.d.cts} +1 -1
  10. package/dist/{chunk-P6EXRY5L.cjs → chunk-2D7F5IU3.cjs} +49 -49
  11. package/dist/{chunk-P6EXRY5L.cjs.map → chunk-2D7F5IU3.cjs.map} +1 -1
  12. package/dist/{chunk-NOWVA5CM.js → chunk-5YCAC6XE.js} +4 -4
  13. package/dist/{chunk-NOWVA5CM.js.map → chunk-5YCAC6XE.js.map} +1 -1
  14. package/dist/{chunk-MK5EPTTB.cjs → chunk-C4RKZY7D.cjs} +798 -513
  15. package/dist/chunk-C4RKZY7D.cjs.map +1 -0
  16. package/dist/{chunk-FM263GKH.cjs → chunk-D5DLGVN4.cjs} +51 -25
  17. package/dist/chunk-D5DLGVN4.cjs.map +1 -0
  18. package/dist/{chunk-ALZ2CZ3T.js → chunk-G5RPUZJE.js} +3 -3
  19. package/dist/{chunk-ALZ2CZ3T.js.map → chunk-G5RPUZJE.js.map} +1 -1
  20. package/dist/{chunk-5J5PDZRR.cjs → chunk-KJ5E646Y.cjs} +30 -4
  21. package/dist/chunk-KJ5E646Y.cjs.map +1 -0
  22. package/dist/{chunk-7PHMT3T4.cjs → chunk-L7IEXVXI.cjs} +10 -10
  23. package/dist/{chunk-7PHMT3T4.cjs.map → chunk-L7IEXVXI.cjs.map} +1 -1
  24. package/dist/{chunk-ZT3EM4CE.js → chunk-M6HIWM5N.js} +37 -11
  25. package/dist/chunk-M6HIWM5N.js.map +1 -0
  26. package/dist/{chunk-2ZX4Z2IP.js → chunk-OV4GLPZI.js} +30 -5
  27. package/dist/chunk-OV4GLPZI.js.map +1 -0
  28. package/dist/{chunk-SCSLCU66.js → chunk-QX2M67YI.js} +8 -4
  29. package/dist/chunk-QX2M67YI.js.map +1 -0
  30. package/dist/{chunk-E5JNYFOF.js → chunk-YHJJSLE5.js} +367 -83
  31. package/dist/chunk-YHJJSLE5.js.map +1 -0
  32. package/dist/{chunk-I7ZNWBBU.cjs → chunk-ZLDO4QDR.cjs} +21 -17
  33. package/dist/chunk-ZLDO4QDR.cjs.map +1 -0
  34. package/dist/contracts/handlers/index.cjs +9 -9
  35. package/dist/contracts/handlers/index.d.cts +3 -3
  36. package/dist/contracts/handlers/index.d.ts +3 -3
  37. package/dist/contracts/handlers/index.js +2 -2
  38. package/dist/{delegate-D-gEEqrP.d.cts → delegate-BJp8f6LT.d.cts} +1 -1
  39. package/dist/{delegate-CKJdsC99.d.ts → delegate-Ckz_TWzM.d.ts} +1 -1
  40. package/dist/{hdWalletCapable-CwLPmWct.d.cts → hdWalletCapable-DA9bJ5eB.d.cts} +2 -2
  41. package/dist/{hdWalletCapable-BJ4pvkai.d.ts → hdWalletCapable-DABgAD-T.d.ts} +2 -2
  42. package/dist/{index-Boppyqav.d.ts → index-B8xrELXY.d.ts} +2 -2
  43. package/dist/{index-BE1uFXrV.d.cts → index-DSbDm0Io.d.cts} +2 -2
  44. package/dist/{index-CyGnhCSS.d.ts → index-Dg0-TvBQ.d.cts} +51 -3
  45. package/dist/{index-CyGnhCSS.d.cts → index-Dg0-TvBQ.d.ts} +51 -3
  46. package/dist/index.cjs +306 -298
  47. package/dist/index.d.cts +57 -10
  48. package/dist/index.d.ts +57 -10
  49. package/dist/index.js +4 -4
  50. package/dist/repositories/realm/index.cjs +19 -19
  51. package/dist/repositories/realm/index.d.cts +2 -2
  52. package/dist/repositories/realm/index.d.ts +2 -2
  53. package/dist/repositories/realm/index.js +5 -5
  54. package/dist/repositories/sqlite/index.cjs +18 -18
  55. package/dist/repositories/sqlite/index.d.cts +2 -2
  56. package/dist/repositories/sqlite/index.d.ts +2 -2
  57. package/dist/repositories/sqlite/index.js +5 -5
  58. package/dist/{taskRunner-CjmMH_rW.d.cts → taskRunner-C_uAJDsn.d.cts} +1 -1
  59. package/dist/{taskRunner-l3zyfW_Q.d.ts → taskRunner-DARTFnZN.d.ts} +1 -1
  60. package/dist/wallet/expo/background.cjs +14 -14
  61. package/dist/wallet/expo/background.d.cts +3 -3
  62. package/dist/wallet/expo/background.d.ts +3 -3
  63. package/dist/wallet/expo/background.js +6 -6
  64. package/dist/wallet/expo/index.cjs +14 -14
  65. package/dist/wallet/expo/index.d.cts +4 -4
  66. package/dist/wallet/expo/index.d.ts +4 -4
  67. package/dist/wallet/expo/index.js +5 -5
  68. package/dist/worker/expo/index.cjs +9 -9
  69. package/dist/worker/expo/index.d.cts +4 -4
  70. package/dist/worker/expo/index.d.ts +4 -4
  71. package/dist/worker/expo/index.js +5 -5
  72. package/package.json +1 -1
  73. package/dist/chunk-2ZX4Z2IP.js.map +0 -1
  74. package/dist/chunk-5J5PDZRR.cjs.map +0 -1
  75. package/dist/chunk-E5JNYFOF.js.map +0 -1
  76. package/dist/chunk-FM263GKH.cjs.map +0 -1
  77. package/dist/chunk-I7ZNWBBU.cjs.map +0 -1
  78. package/dist/chunk-MK5EPTTB.cjs.map +0 -1
  79. package/dist/chunk-SCSLCU66.js.map +0 -1
  80. package/dist/chunk-ZT3EM4CE.js.map +0 -1
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkFM263GKH_cjs = require('./chunk-FM263GKH.cjs');
4
- var chunkP6EXRY5L_cjs = require('./chunk-P6EXRY5L.cjs');
5
- var chunk5J5PDZRR_cjs = require('./chunk-5J5PDZRR.cjs');
3
+ var chunkD5DLGVN4_cjs = require('./chunk-D5DLGVN4.cjs');
4
+ var chunk2D7F5IU3_cjs = require('./chunk-2D7F5IU3.cjs');
5
+ var chunkKJ5E646Y_cjs = require('./chunk-KJ5E646Y.cjs');
6
6
  var chunk5BLDMQED_cjs = require('./chunk-5BLDMQED.cjs');
7
7
  var utils_js = require('@scure/btc-signer/utils.js');
8
8
  var btcSigner = require('@scure/btc-signer');
@@ -188,7 +188,7 @@ var TreeSignerSession = class _TreeSignerSession {
188
188
  noncesByPubkey.set(base.hex.encode(myPublicKey.subarray(1)), myNonce);
189
189
  const tx = this.graph.find(txid);
190
190
  if (!tx) throw new Error(`missing tx for txid ${txid}`);
191
- const cosigners = chunk5J5PDZRR_cjs.getArkPsbtFields(tx.root, 0, chunk5J5PDZRR_cjs.CosignerPublicKey).map(
191
+ const cosigners = chunkKJ5E646Y_cjs.getArkPsbtFields(tx.root, 0, chunkKJ5E646Y_cjs.CosignerPublicKey).map(
192
192
  (c) => base.hex.encode(c.key.subarray(1))
193
193
  // xonly pubkey
194
194
  );
@@ -240,7 +240,7 @@ var TreeSignerSession = class _TreeSignerSession {
240
240
  if (!aggNonce) throw new Error("missing aggregate nonce");
241
241
  const prevoutAmounts = [];
242
242
  const prevoutScripts = [];
243
- const cosigners = chunk5J5PDZRR_cjs.getArkPsbtFields(g.root, 0, chunk5J5PDZRR_cjs.CosignerPublicKey).map((c) => c.key);
243
+ const cosigners = chunkKJ5E646Y_cjs.getArkPsbtFields(g.root, 0, chunkKJ5E646Y_cjs.CosignerPublicKey).map((c) => c.key);
244
244
  const { finalKey } = aggregateKeys(cosigners, true, {
245
245
  taprootTweak: this.scriptRoot
246
246
  });
@@ -323,7 +323,7 @@ var SingleKey = class _SingleKey {
323
323
  async sign(tx, inputIndexes) {
324
324
  const txCpy = tx.clone();
325
325
  if (!inputIndexes) {
326
- chunk5J5PDZRR_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH);
326
+ chunkKJ5E646Y_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH);
327
327
  try {
328
328
  if (!txCpy.sign(this.key, ALLOWED_SIGHASH)) {
329
329
  throw new Error("Failed to sign transaction");
@@ -432,7 +432,7 @@ var SeedIdentity = class _SeedIdentity {
432
432
  let network;
433
433
  if ("descriptor" in opts && typeof opts.descriptor === "string") {
434
434
  descriptor = opts.descriptor;
435
- network = chunkP6EXRY5L_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
435
+ network = chunk2D7F5IU3_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
436
436
  } else {
437
437
  network = opts.isMainnet ?? true ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
438
438
  descriptor = descriptorsScure.scriptExpressions.trBIP32({
@@ -530,7 +530,7 @@ var SeedIdentity = class _SeedIdentity {
530
530
  * `StaticDescriptorProvider` for legacy single-key wallets.
531
531
  */
532
532
  isOurs(descriptor) {
533
- return chunkP6EXRY5L_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
533
+ return chunk2D7F5IU3_cjs.descriptorIsOurs(descriptor, this.descriptor, utils_js.pubSchnorr(this.derivedKey));
534
534
  }
535
535
  /**
536
536
  * Signs each request with the key derived from its descriptor.
@@ -579,7 +579,7 @@ var SeedIdentity = class _SeedIdentity {
579
579
  }
580
580
  // ── internal helpers ─────────────────────────────────────────────
581
581
  derivePrivateKeyForDescriptor(descriptor) {
582
- const network = chunkP6EXRY5L_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
582
+ const network = chunk2D7F5IU3_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
583
583
  const expansion = descriptorsScure.expand({ descriptor, network });
584
584
  if (expansion.isRanged) {
585
585
  throw new Error(
@@ -604,7 +604,7 @@ var SeedIdentity = class _SeedIdentity {
604
604
  signTxWithKey(tx, key, inputIndexes) {
605
605
  const txCpy = tx.clone();
606
606
  if (!inputIndexes) {
607
- chunk5J5PDZRR_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH2);
607
+ chunkKJ5E646Y_cjs.assertAllowedSighashTypes(txCpy, ALLOWED_SIGHASH2);
608
608
  try {
609
609
  if (!txCpy.sign(key, ALLOWED_SIGHASH2)) {
610
610
  throw new Error("Failed to sign transaction");
@@ -666,7 +666,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
666
666
  */
667
667
  descriptor;
668
668
  constructor(descriptor) {
669
- const network = chunkP6EXRY5L_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
669
+ const network = chunk2D7F5IU3_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
670
670
  let expansion;
671
671
  try {
672
672
  expansion = descriptorsScure.expand({ descriptor, network, index: 0 });
@@ -716,7 +716,7 @@ var ReadonlyDescriptorIdentity = class _ReadonlyDescriptorIdentity {
716
716
  * `StaticDescriptorProvider` for legacy single-key wallets.
717
717
  */
718
718
  isOurs(descriptor) {
719
- return chunkP6EXRY5L_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
719
+ return chunk2D7F5IU3_cjs.descriptorIsOurs(descriptor, this.descriptor, this.indexZero.pubkey);
720
720
  }
721
721
  };
722
722
  function serializeSeedOwnedSigningIdentity(identity) {
@@ -878,10 +878,10 @@ var DescriptorIdentity = class {
878
878
  this.base = base;
879
879
  }
880
880
  async xOnlyPublicKey() {
881
- return chunkP6EXRY5L_cjs.deriveDescriptorLeafPubKey(this.descriptor);
881
+ return chunk2D7F5IU3_cjs.deriveDescriptorLeafPubKey(this.descriptor);
882
882
  }
883
883
  async compressedPublicKey() {
884
- return chunkP6EXRY5L_cjs.deriveDescriptorLeafCompressedPubKey(this.descriptor);
884
+ return chunk2D7F5IU3_cjs.deriveDescriptorLeafCompressedPubKey(this.descriptor);
885
885
  }
886
886
  async sign(tx, inputIndexes) {
887
887
  const [signed] = await this.signer.signWithDescriptor([
@@ -949,12 +949,12 @@ var WalletCannotAllocateAddressError = class extends Error {
949
949
  };
950
950
  async function resolveDescriptorSigner(descriptor, identity, provider) {
951
951
  const owner = provider?.isOurs(descriptor) ? provider : isHDCapableIdentity(identity) && identity.isOurs(descriptor) ? identity : void 0;
952
- if (owner && chunkP6EXRY5L_cjs.parseHDDescriptor(descriptor)) {
952
+ if (owner && chunk2D7F5IU3_cjs.parseHDDescriptor(descriptor)) {
953
953
  return new DescriptorIdentity({ descriptor, signer: owner, base: identity });
954
954
  }
955
955
  let key;
956
956
  try {
957
- key = chunkP6EXRY5L_cjs.deriveDescriptorLeafPubKey(descriptor);
957
+ key = chunk2D7F5IU3_cjs.deriveDescriptorLeafPubKey(descriptor);
958
958
  } catch {
959
959
  throw new ForeignDescriptorError(descriptor);
960
960
  }
@@ -1329,14 +1329,14 @@ function buildSaltedPreimageMessage(xonly, salt) {
1329
1329
  }
1330
1330
  var PREIMAGE_INDEX = 0;
1331
1331
  function isPerArtifactDescriptor(descriptor) {
1332
- return chunkP6EXRY5L_cjs.parseHDDescriptor(descriptor) !== null;
1332
+ return chunk2D7F5IU3_cjs.parseHDDescriptor(descriptor) !== null;
1333
1333
  }
1334
1334
  async function provisionDescriptor(wallet) {
1335
1335
  const allocated = isHDAllocationCapable(wallet) ? await wallet.getNextSigningDescriptor() : void 0;
1336
- return allocated ?? await chunkP6EXRY5L_cjs.identityDescriptor(wallet.identity);
1336
+ return allocated ?? await chunk2D7F5IU3_cjs.identityDescriptor(wallet.identity);
1337
1337
  }
1338
1338
  async function provisionRefundKey(wallet) {
1339
- const descriptor = await chunkP6EXRY5L_cjs.identityDescriptor(wallet.identity);
1339
+ const descriptor = await chunk2D7F5IU3_cjs.identityDescriptor(wallet.identity);
1340
1340
  const signer = await contractSigner(wallet, descriptor);
1341
1341
  const pubkey = await signer.xOnlyPublicKey();
1342
1342
  const identityPubkey = await wallet.identity.xOnlyPublicKey();
@@ -1346,7 +1346,7 @@ async function provisionRefundKey(wallet) {
1346
1346
  );
1347
1347
  }
1348
1348
  const address = await wallet.getAddress();
1349
- const { pkScript } = chunk5J5PDZRR_cjs.ArkAddress.decode(address);
1349
+ const { pkScript } = chunkKJ5E646Y_cjs.ArkAddress.decode(address);
1350
1350
  return { descriptor, pubkey, pkScript, address };
1351
1351
  }
1352
1352
  async function provisionClaimSecret(wallet, opts = {}) {
@@ -1392,7 +1392,7 @@ async function contractSigner(wallet, descriptor) {
1392
1392
  const signer = isHDWalletCapable(wallet) ? await wallet.signerForDescriptor(descriptor) : wallet.identity;
1393
1393
  let expected;
1394
1394
  try {
1395
- expected = chunkP6EXRY5L_cjs.deriveDescriptorLeafPubKey(descriptor);
1395
+ expected = chunk2D7F5IU3_cjs.deriveDescriptorLeafPubKey(descriptor);
1396
1396
  } catch (cause) {
1397
1397
  throw new ForeignDescriptorError(descriptor, { cause });
1398
1398
  }
@@ -1611,14 +1611,14 @@ var RestDelegateProvider = class {
1611
1611
  */
1612
1612
  async delegate(intent, forfeitTxs, options) {
1613
1613
  const url = `${this.url}/v1/delegate`;
1614
- const response = await chunk5J5PDZRR_cjs.baseFetch(url, {
1614
+ const response = await chunkKJ5E646Y_cjs.baseFetch(url, {
1615
1615
  method: "POST",
1616
1616
  headers: {
1617
1617
  "Content-Type": "application/json"
1618
1618
  },
1619
1619
  body: JSON.stringify({
1620
1620
  intent: {
1621
- message: chunk5J5PDZRR_cjs.Intent.encodeMessage(intent.message),
1621
+ message: chunkKJ5E646Y_cjs.Intent.encodeMessage(intent.message),
1622
1622
  proof: intent.proof
1623
1623
  },
1624
1624
  forfeit_txs: forfeitTxs,
@@ -1638,7 +1638,7 @@ var RestDelegateProvider = class {
1638
1638
  */
1639
1639
  async getDelegateInfo() {
1640
1640
  const url = `${this.url}/v1/delegator/info`;
1641
- const response = await chunk5J5PDZRR_cjs.rateGate.runHttp(url, () => chunk5J5PDZRR_cjs.baseFetch(url));
1641
+ const response = await chunkKJ5E646Y_cjs.rateGate.runHttp(url, () => chunkKJ5E646Y_cjs.baseFetch(url));
1642
1642
  if (!response.ok) {
1643
1643
  const errorText2 = await response.text();
1644
1644
  throw new Error(`Failed to get delegate info: ${errorText2}`);
@@ -1663,7 +1663,7 @@ var ESPLORA_URL = {
1663
1663
  regtest: "http://localhost:3000/api"
1664
1664
  };
1665
1665
  var EsploraProvider = class {
1666
- constructor(baseUrl = ESPLORA_URL[chunk5J5PDZRR_cjs.DEFAULT_NETWORK_NAME], opts) {
1666
+ constructor(baseUrl = ESPLORA_URL[chunkKJ5E646Y_cjs.DEFAULT_NETWORK_NAME], opts) {
1667
1667
  this.baseUrl = baseUrl;
1668
1668
  this.pollingInterval = opts?.pollingInterval ?? 15e3;
1669
1669
  this.forcePolling = opts?.forcePolling ?? false;
@@ -1682,14 +1682,14 @@ var EsploraProvider = class {
1682
1682
  */
1683
1683
  addressWatches = /* @__PURE__ */ new Map();
1684
1684
  async getCoins(address) {
1685
- const response = await chunk5J5PDZRR_cjs.baseFetch(`${this.baseUrl}/address/${address}/utxo`);
1685
+ const response = await chunkKJ5E646Y_cjs.baseFetch(`${this.baseUrl}/address/${address}/utxo`);
1686
1686
  if (!response.ok) {
1687
1687
  throw new Error(`Failed to fetch UTXOs: ${response.statusText}`);
1688
1688
  }
1689
1689
  return response.json();
1690
1690
  }
1691
1691
  async getFeeRate() {
1692
- const response = await chunk5J5PDZRR_cjs.baseFetch(`${this.baseUrl}/fee-estimates`);
1692
+ const response = await chunkKJ5E646Y_cjs.baseFetch(`${this.baseUrl}/fee-estimates`);
1693
1693
  if (response.status === 404) {
1694
1694
  return void 0;
1695
1695
  }
@@ -1710,7 +1710,7 @@ var EsploraProvider = class {
1710
1710
  }
1711
1711
  }
1712
1712
  async getTxOutspends(txid) {
1713
- const response = await chunk5J5PDZRR_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/outspends`);
1713
+ const response = await chunkKJ5E646Y_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/outspends`);
1714
1714
  if (!response.ok) {
1715
1715
  const error = await response.text();
1716
1716
  throw new Error(`Failed to get transaction outspends: ${error}`);
@@ -1718,7 +1718,7 @@ var EsploraProvider = class {
1718
1718
  return response.json();
1719
1719
  }
1720
1720
  async getTransactions(address) {
1721
- const response = await chunk5J5PDZRR_cjs.baseFetch(`${this.baseUrl}/address/${address}/txs`);
1721
+ const response = await chunkKJ5E646Y_cjs.baseFetch(`${this.baseUrl}/address/${address}/txs`);
1722
1722
  if (!response.ok) {
1723
1723
  const error = await response.text();
1724
1724
  throw new Error(`Failed to get transactions: ${error}`);
@@ -1731,14 +1731,14 @@ var EsploraProvider = class {
1731
1731
  * usable as a change probe for the polling fallback.
1732
1732
  */
1733
1733
  async getAddressStats(address) {
1734
- const response = await chunk5J5PDZRR_cjs.baseFetch(`${this.baseUrl}/address/${address}`);
1734
+ const response = await chunkKJ5E646Y_cjs.baseFetch(`${this.baseUrl}/address/${address}`);
1735
1735
  if (!response.ok) {
1736
1736
  throw new Error(`Failed to get address stats: ${response.statusText}`);
1737
1737
  }
1738
1738
  return response.json();
1739
1739
  }
1740
1740
  async getRawTransaction(txid) {
1741
- const response = await chunk5J5PDZRR_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/hex`);
1741
+ const response = await chunkKJ5E646Y_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/hex`);
1742
1742
  if (!response.ok) {
1743
1743
  const error = await response.text();
1744
1744
  throw new Error(`Failed to get raw transaction ${txid}: ${error}`);
@@ -1746,7 +1746,7 @@ var EsploraProvider = class {
1746
1746
  return base.hex.decode((await response.text()).trim());
1747
1747
  }
1748
1748
  async getTxStatus(txid) {
1749
- const txresponse = await chunk5J5PDZRR_cjs.baseFetch(`${this.baseUrl}/tx/${txid}`);
1749
+ const txresponse = await chunkKJ5E646Y_cjs.baseFetch(`${this.baseUrl}/tx/${txid}`);
1750
1750
  if (!txresponse.ok) {
1751
1751
  throw new Error(txresponse.statusText);
1752
1752
  }
@@ -1754,7 +1754,7 @@ var EsploraProvider = class {
1754
1754
  if (!tx.status.confirmed) {
1755
1755
  return { confirmed: false };
1756
1756
  }
1757
- const response = await chunk5J5PDZRR_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/status`);
1757
+ const response = await chunkKJ5E646Y_cjs.baseFetch(`${this.baseUrl}/tx/${txid}/status`);
1758
1758
  if (!response.ok) {
1759
1759
  throw new Error(`Failed to get transaction status: ${response.statusText}`);
1760
1760
  }
@@ -2038,9 +2038,9 @@ var EsploraProvider = class {
2038
2038
  return { subscribers, teardown, started };
2039
2039
  }
2040
2040
  async getChainTip() {
2041
- let tipBlocks = await chunk5J5PDZRR_cjs.baseFetch(`${this.baseUrl}/blocks`);
2041
+ let tipBlocks = await chunkKJ5E646Y_cjs.baseFetch(`${this.baseUrl}/blocks`);
2042
2042
  if (tipBlocks.status === 404) {
2043
- tipBlocks = await chunk5J5PDZRR_cjs.baseFetch(`${this.baseUrl}/v1/blocks`);
2043
+ tipBlocks = await chunkKJ5E646Y_cjs.baseFetch(`${this.baseUrl}/v1/blocks`);
2044
2044
  }
2045
2045
  if (!tipBlocks.ok) {
2046
2046
  throw new Error(`Failed to get chain tip: ${tipBlocks.statusText}`);
@@ -2062,7 +2062,7 @@ var EsploraProvider = class {
2062
2062
  };
2063
2063
  }
2064
2064
  async broadcastPackage(parent, child) {
2065
- const response = await chunk5J5PDZRR_cjs.baseFetch(`${this.baseUrl}/txs/package`, {
2065
+ const response = await chunkKJ5E646Y_cjs.baseFetch(`${this.baseUrl}/txs/package`, {
2066
2066
  method: "POST",
2067
2067
  headers: {
2068
2068
  "Content-Type": "application/json"
@@ -2078,7 +2078,7 @@ var EsploraProvider = class {
2078
2078
  return result;
2079
2079
  }
2080
2080
  async broadcastTx(tx) {
2081
- const response = await chunk5J5PDZRR_cjs.baseFetch(`${this.baseUrl}/tx`, {
2081
+ const response = await chunkKJ5E646Y_cjs.baseFetch(`${this.baseUrl}/tx`, {
2082
2082
  method: "POST",
2083
2083
  headers: {
2084
2084
  "Content-Type": "text/plain"
@@ -2261,7 +2261,7 @@ function findP2AOutput(tx) {
2261
2261
  var CHILD_DUST_AMOUNT = 546;
2262
2262
  function buildAnchorChild(params) {
2263
2263
  const { parent, feeRate, fundingCoins, changeAddress, tapInternalKey, network } = params;
2264
- const child = new chunk5J5PDZRR_cjs.Transaction({ version: 3, allowLegacyWitnessUtxo: true });
2264
+ const child = new chunkKJ5E646Y_cjs.Transaction({ version: 3, allowLegacyWitnessUtxo: true });
2265
2265
  child.addInput(findP2AOutput(parent));
2266
2266
  const estimator = TxWeightEstimator.create().addP2AInput();
2267
2267
  for (const _ of fundingCoins) {
@@ -2309,7 +2309,7 @@ function buildForfeitTx(inputs, forfeitPkScript, txLocktime) {
2309
2309
  );
2310
2310
  }
2311
2311
  function buildForfeitTxWithOutput(inputs, output, txLocktime) {
2312
- const tx = new chunk5J5PDZRR_cjs.Transaction({
2312
+ const tx = new chunkKJ5E646Y_cjs.Transaction({
2313
2313
  version: 3,
2314
2314
  lockTime: txLocktime
2315
2315
  });
@@ -2385,7 +2385,7 @@ function validateVtxoTxGraph(graph, roundTransaction, sweepTapTreeRoot) {
2385
2385
  if (previousScriptKey.length !== 32) {
2386
2386
  throw new Error(`parent output ${childIndex} has invalid script`);
2387
2387
  }
2388
- const cosigners = chunk5J5PDZRR_cjs.getArkPsbtFields(child.root, 0, chunk5J5PDZRR_cjs.CosignerPublicKey);
2388
+ const cosigners = chunkKJ5E646Y_cjs.getArkPsbtFields(child.root, 0, chunkKJ5E646Y_cjs.CosignerPublicKey);
2389
2389
  if (cosigners.length === 0) {
2390
2390
  throw ErrMissingCosignersPublicKeys;
2391
2391
  }
@@ -2443,7 +2443,7 @@ var EmulatorPacket = class _EmulatorPacket {
2443
2443
  return new _EmulatorPacket(entries);
2444
2444
  }
2445
2445
  static fromBytes(data) {
2446
- const reader = new chunkFM263GKH_cjs.BufferReader(data);
2446
+ const reader = new chunkD5DLGVN4_cjs.BufferReader(data);
2447
2447
  const entryCount = reader.readCompactSize();
2448
2448
  const entries = [];
2449
2449
  for (let i = 0; i < entryCount; i++) {
@@ -2461,7 +2461,7 @@ var EmulatorPacket = class _EmulatorPacket {
2461
2461
  return _EmulatorPacket.PACKET_TYPE;
2462
2462
  }
2463
2463
  serialize() {
2464
- const writer = new chunkFM263GKH_cjs.BufferWriter();
2464
+ const writer = new chunkD5DLGVN4_cjs.BufferWriter();
2465
2465
  writer.writeCompactSize(this.entries.length);
2466
2466
  for (const entry of this.entries) {
2467
2467
  writer.writeUint16LE(entry.vin);
@@ -2548,7 +2548,7 @@ var Extension = class _Extension {
2548
2548
  `expected magic prefix ${base.hex.encode(ARKADE_MAGIC)}, got ${base.hex.encode(payload.slice(0, Math.min(payload.length, ARKADE_MAGIC.length)))}`
2549
2549
  );
2550
2550
  }
2551
- const reader = new chunkFM263GKH_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
2551
+ const reader = new chunkD5DLGVN4_cjs.BufferReader(payload.slice(ARKADE_MAGIC.length));
2552
2552
  const packets = [];
2553
2553
  while (reader.remaining() > 0) {
2554
2554
  const packetType = reader.readByte();
@@ -2622,7 +2622,7 @@ var Extension = class _Extension {
2622
2622
  */
2623
2623
  getAssetPacket() {
2624
2624
  for (const p of this.packets) {
2625
- if (p instanceof chunkFM263GKH_cjs.Packet) {
2625
+ if (p instanceof chunkD5DLGVN4_cjs.Packet) {
2626
2626
  return p;
2627
2627
  }
2628
2628
  }
@@ -2660,8 +2660,8 @@ var Extension = class _Extension {
2660
2660
  };
2661
2661
  function parsePacket(packetType, data) {
2662
2662
  switch (packetType) {
2663
- case chunkFM263GKH_cjs.Packet.PACKET_TYPE:
2664
- return chunkFM263GKH_cjs.Packet.fromBytes(data);
2663
+ case chunkD5DLGVN4_cjs.Packet.PACKET_TYPE:
2664
+ return chunkD5DLGVN4_cjs.Packet.fromBytes(data);
2665
2665
  case EmulatorPacket.PACKET_TYPE:
2666
2666
  return EmulatorPacket.fromBytes(data);
2667
2667
  default:
@@ -2708,25 +2708,31 @@ function buildOpReturnScript(data) {
2708
2708
  }
2709
2709
  return script;
2710
2710
  }
2711
- var ErrOffchainOutputNotFound = (address) => new chunk5J5PDZRR_cjs.ServerResponseMismatchError(`offchain send output not found: ${address}`);
2712
- var ErrInvalidAssetOutputAmount = (got, want, assetId) => new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
2711
+ var ErrOffchainOutputNotFound = (address) => new chunkKJ5E646Y_cjs.ServerResponseMismatchError(`offchain send output not found: ${address}`);
2712
+ var ErrInvalidAssetOutputAmount = (got, want, assetId) => new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
2713
2713
  `invalid asset output amount for ${assetId}: got ${got}, want ${want}`
2714
2714
  );
2715
- var ErrAssetGroupNotFound = (assetId) => new chunk5J5PDZRR_cjs.ServerResponseMismatchError(`asset group not found in batch leaf: ${assetId}`);
2716
- var ErrAssetOutputNotFound = (assetId, outputIndex) => new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
2715
+ var ErrAssetGroupNotFound = (assetId) => new chunkKJ5E646Y_cjs.ServerResponseMismatchError(`asset group not found in batch leaf: ${assetId}`);
2716
+ var ErrAssetOutputNotFound = (assetId, outputIndex) => new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
2717
2717
  `asset output not found in asset group ${assetId} at index ${outputIndex}`
2718
2718
  );
2719
- var ErrOnchainOutputNotFound = (address) => new chunk5J5PDZRR_cjs.ServerResponseMismatchError(`onchain output not found: ${address}`);
2720
- var ErrUnvalidatedOffchainOutput = (address) => new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
2719
+ var ErrOnchainOutputNotFound = (address) => new chunkKJ5E646Y_cjs.ServerResponseMismatchError(`onchain output not found: ${address}`);
2720
+ var ErrUnvalidatedOffchainOutput = (address) => new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
2721
2721
  `offchain output ${address} cannot be validated: virtual output tree signing did not run`
2722
2722
  );
2723
+ var ErrIntentOutputNotFound = (index, kind) => new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
2724
+ `${kind} output ${index} of the intent proof is not present in what the server built`
2725
+ );
2726
+ var ErrUnvalidatedIntentOutput = (index) => new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
2727
+ `offchain output ${index} of the intent proof cannot be validated: virtual output tree signing did not run`
2728
+ );
2723
2729
  var ErrInvalidOnchainOutputAmount = (address) => new Error(`invalid onchain output amount: ${address}`);
2724
2730
  var ErrInvalidOnchainOutputAssets = (address) => new Error(`onchain output ${address} cannot have assets`);
2725
2731
  var ErrInvalidOffchainOutputAmount = (address) => new Error(`invalid offchain output ${address}, missing amount`);
2726
2732
  function assertFinalCommitmentMatchesValidated(finalCommitmentTx, validatedCommitmentTxid, context) {
2727
2733
  if (!validatedCommitmentTxid) return;
2728
2734
  if (finalCommitmentTx.id === validatedCommitmentTxid) return;
2729
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
2735
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
2730
2736
  `${context}: finalization commitment tx ${finalCommitmentTx.id} differs from the validated commitment tx ${validatedCommitmentTxid}`
2731
2737
  );
2732
2738
  }
@@ -2736,7 +2742,7 @@ function validateBatchRecipients(commitmentTx, vtxoTreeLeaves, recipients, netwo
2736
2742
  for (const recipient of recipients) {
2737
2743
  let arkAddress;
2738
2744
  try {
2739
- arkAddress = chunk5J5PDZRR_cjs.ArkAddress.decode(recipient.address);
2745
+ arkAddress = chunkKJ5E646Y_cjs.ArkAddress.decode(recipient.address);
2740
2746
  } catch {
2741
2747
  validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
2742
2748
  continue;
@@ -2748,7 +2754,7 @@ function validateBatchRecipientsWithoutTree(commitmentTx, recipients, network) {
2748
2754
  const usedOnchainOutputs = /* @__PURE__ */ new Set();
2749
2755
  for (const recipient of recipients) {
2750
2756
  try {
2751
- chunk5J5PDZRR_cjs.ArkAddress.decode(recipient.address);
2757
+ chunkKJ5E646Y_cjs.ArkAddress.decode(recipient.address);
2752
2758
  } catch {
2753
2759
  validateOnchainRecipient(commitmentTx, recipient, network, usedOnchainOutputs);
2754
2760
  continue;
@@ -2756,6 +2762,74 @@ function validateBatchRecipientsWithoutTree(commitmentTx, recipients, network) {
2756
2762
  throw ErrUnvalidatedOffchainOutput(recipient.address);
2757
2763
  }
2758
2764
  }
2765
+ function declaredIntentOutputs(signedProof, onchainOutputIndexes) {
2766
+ const proof = chunkKJ5E646Y_cjs.Transaction.fromPSBT(base.base64.decode(signedProof));
2767
+ const onchain = new Set(onchainOutputIndexes);
2768
+ const declared = [];
2769
+ for (let i = 0; i < proof.outputsLength; i++) {
2770
+ const output = proof.getOutput(i);
2771
+ if (!output?.script || output.script.length === 0 || !output.amount) continue;
2772
+ declared.push({
2773
+ index: i,
2774
+ script: output.script,
2775
+ amount: output.amount,
2776
+ onchain: onchain.has(i)
2777
+ });
2778
+ }
2779
+ return declared;
2780
+ }
2781
+ function validateBatchAgainstIntent(commitmentTx, vtxoTreeLeaves, declared) {
2782
+ const usedOnchain = /* @__PURE__ */ new Set();
2783
+ const usedLeaf = /* @__PURE__ */ new Set();
2784
+ for (const output of declared) {
2785
+ if (output.onchain) {
2786
+ if (!takeOnchainOutput(commitmentTx, output, usedOnchain)) {
2787
+ throw ErrIntentOutputNotFound(output.index, "onchain");
2788
+ }
2789
+ continue;
2790
+ }
2791
+ if (!takeLeafOutput(vtxoTreeLeaves, output, usedLeaf)) {
2792
+ throw ErrIntentOutputNotFound(output.index, "offchain");
2793
+ }
2794
+ }
2795
+ }
2796
+ function validateBatchAgainstIntentWithoutTree(commitmentTx, declared) {
2797
+ const usedOnchain = /* @__PURE__ */ new Set();
2798
+ for (const output of declared) {
2799
+ if (!output.onchain) {
2800
+ throw ErrUnvalidatedIntentOutput(output.index);
2801
+ }
2802
+ if (!takeOnchainOutput(commitmentTx, output, usedOnchain)) {
2803
+ throw ErrIntentOutputNotFound(output.index, "onchain");
2804
+ }
2805
+ }
2806
+ }
2807
+ function takeOnchainOutput(commitmentTx, declared, used) {
2808
+ for (let i = 0; i < commitmentTx.outputsLength; i++) {
2809
+ if (used.has(i)) continue;
2810
+ const output = commitmentTx.getOutput(i);
2811
+ if (!output?.script || output.amount !== declared.amount) continue;
2812
+ if (!utils_js.equalBytes(output.script, declared.script)) continue;
2813
+ used.add(i);
2814
+ return true;
2815
+ }
2816
+ return false;
2817
+ }
2818
+ function takeLeafOutput(leaves, declared, used) {
2819
+ for (let leafIdx = 0; leafIdx < leaves.length; leafIdx++) {
2820
+ const leaf = leaves[leafIdx];
2821
+ for (let i = 0; i < leaf.outputsLength; i++) {
2822
+ const key = `${leafIdx}:${i}`;
2823
+ if (used.has(key)) continue;
2824
+ const output = leaf.getOutput(i);
2825
+ if (!output?.script || output.amount !== declared.amount) continue;
2826
+ if (!utils_js.equalBytes(output.script, declared.script)) continue;
2827
+ used.add(key);
2828
+ return true;
2829
+ }
2830
+ }
2831
+ return false;
2832
+ }
2759
2833
  function validateOnchainRecipient(commitmentTx, recipient, network, usedOutputs) {
2760
2834
  const addr = btcSigner.Address(network).decode(recipient.address);
2761
2835
  const expectedPkScript = btcSigner.OutScript.encode(addr);
@@ -2981,7 +3055,7 @@ function assetMintResolver() {
2981
3055
  if (!tx.assets?.length || !tx.key.arkTxid) return void 0;
2982
3056
  const minted = tx.assets.filter((a) => {
2983
3057
  try {
2984
- return base.hex.encode(chunkFM263GKH_cjs.AssetId.fromString(a.assetId).txid) === tx.key.arkTxid;
3058
+ return base.hex.encode(chunkD5DLGVN4_cjs.AssetId.fromString(a.assetId).txid) === tx.key.arkTxid;
2985
3059
  } catch {
2986
3060
  return false;
2987
3061
  }
@@ -3005,6 +3079,39 @@ function createDefaultActivityRegistry() {
3005
3079
  return registry;
3006
3080
  }
3007
3081
 
3082
+ // src/wallet/restoreHooks.ts
3083
+ var restoreHooks = /* @__PURE__ */ new WeakMap();
3084
+ function registerWalletRestoreHook(wallet, hook) {
3085
+ const hooks = restoreHooks.get(wallet) ?? [];
3086
+ const entry = { ...hook };
3087
+ const existing = hooks.findIndex(({ id }) => id === hook.id);
3088
+ if (existing === -1) hooks.push(entry);
3089
+ else hooks[existing] = entry;
3090
+ restoreHooks.set(wallet, hooks);
3091
+ return () => {
3092
+ const current = restoreHooks.get(wallet);
3093
+ if (!current) return;
3094
+ const index = current.indexOf(entry);
3095
+ if (index === -1) return;
3096
+ current.splice(index, 1);
3097
+ if (current.length === 0) restoreHooks.delete(wallet);
3098
+ };
3099
+ }
3100
+ async function runWalletRestoreHooks(wallet) {
3101
+ const snapshot = [...restoreHooks.get(wallet) ?? []];
3102
+ const errors = [];
3103
+ for (const hook of snapshot) {
3104
+ try {
3105
+ await hook.restore(wallet);
3106
+ } catch (error) {
3107
+ errors.push(error);
3108
+ }
3109
+ }
3110
+ if (errors.length > 0) {
3111
+ throw new AggregateError(errors, "Wallet restore hooks failed");
3112
+ }
3113
+ }
3114
+
3008
3115
  // src/wallet/index.ts
3009
3116
  var TxType = /* @__PURE__ */ ((TxType2) => {
3010
3117
  TxType2["TxSent"] = "SENT";
@@ -3024,7 +3131,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
3024
3131
  const existing = inputsByAssetId.get(asset.assetId);
3025
3132
  inputsByAssetId.set(asset.assetId, [
3026
3133
  ...existing ?? [],
3027
- chunkFM263GKH_cjs.AssetInput.create(inputIndex, asset.amount)
3134
+ chunkD5DLGVN4_cjs.AssetInput.create(inputIndex, asset.amount)
3028
3135
  ]);
3029
3136
  }
3030
3137
  }
@@ -3036,7 +3143,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
3036
3143
  const existing = outputsByAssetId.get(asset.assetId);
3037
3144
  outputsByAssetId.set(asset.assetId, [
3038
3145
  ...existing ?? [],
3039
- chunkFM263GKH_cjs.AssetOutput.create(outputIndex, asset.amount)
3146
+ chunkD5DLGVN4_cjs.AssetOutput.create(outputIndex, asset.amount)
3040
3147
  ]);
3041
3148
  }
3042
3149
  }
@@ -3047,7 +3154,7 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
3047
3154
  const existing = outputsByAssetId.get(asset.assetId);
3048
3155
  outputsByAssetId.set(asset.assetId, [
3049
3156
  ...existing ?? [],
3050
- chunkFM263GKH_cjs.AssetOutput.create(outputIndex, asset.amount)
3157
+ chunkD5DLGVN4_cjs.AssetOutput.create(outputIndex, asset.amount)
3051
3158
  ]);
3052
3159
  }
3053
3160
  }
@@ -3056,11 +3163,11 @@ function createAssetPacket(assetInputs, receivers, changeReceiver) {
3056
3163
  for (const assetIdStr of allAssetIds) {
3057
3164
  const inputs = inputsByAssetId.get(assetIdStr);
3058
3165
  const outputs = outputsByAssetId.get(assetIdStr);
3059
- const assetId = chunkFM263GKH_cjs.AssetId.fromString(assetIdStr);
3060
- const group = chunkFM263GKH_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
3166
+ const assetId = chunkD5DLGVN4_cjs.AssetId.fromString(assetIdStr);
3167
+ const group = chunkD5DLGVN4_cjs.AssetGroup.create(assetId, null, inputs ?? [], outputs ?? [], []);
3061
3168
  groups.push(group);
3062
3169
  }
3063
- return chunkFM263GKH_cjs.Packet.create(groups);
3170
+ return chunkD5DLGVN4_cjs.Packet.create(groups);
3064
3171
  }
3065
3172
  function selectCoinsWithAsset(coins, assetId, requiredAmount) {
3066
3173
  const coinsWithAsset = coins.filter((coin) => coin.assets?.some((a) => a.assetId === assetId));
@@ -3097,7 +3204,7 @@ function selectedCoinsToAssetInputs(selectedCoins) {
3097
3204
  }
3098
3205
  function toXOnlySignerHex(pubkeyHex) {
3099
3206
  const bytes = base.hex.decode(pubkeyHex);
3100
- if (bytes.length === 32 || bytes.length === 33) return base.hex.encode(chunkP6EXRY5L_cjs.toXOnly(bytes, "signer key"));
3207
+ if (bytes.length === 32 || bytes.length === 33) return base.hex.encode(chunk2D7F5IU3_cjs.toXOnly(bytes, "signer key"));
3101
3208
  throw new Error(`invalid signer pubkey length: expected 32 or 33 bytes, got ${bytes.length}`);
3102
3209
  }
3103
3210
  function signerSetFromInfo(info) {
@@ -3144,13 +3251,13 @@ var toTimelock = (value) => ({
3144
3251
  var toSeconds = (t) => t.type === "seconds" ? t.value : t.value * NOMINAL_BLOCK_SECONDS;
3145
3252
  function assertTimelockInPolicy(timelock, policy, label, overrideOption) {
3146
3253
  if (policy.requireSeconds && timelock.type === "blocks") {
3147
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3254
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3148
3255
  `${label} rejected: block-typed timelocks are not accepted (got ${timelock.value})`
3149
3256
  );
3150
3257
  }
3151
3258
  const seconds = toSeconds(timelock);
3152
3259
  if (seconds < policy.minSeconds) {
3153
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3260
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3154
3261
  `${label} rejected: ${timelock.value} ${timelock.type} is below the ${policy.minSeconds}s floor; pass ${overrideOption}: ${seconds}n to Wallet.create to lower it`
3155
3262
  );
3156
3263
  }
@@ -3171,7 +3278,7 @@ function resolveBatchExpiryPolicy(network, overrides) {
3171
3278
  }
3172
3279
  function assertValidBatchExpiry(batchExpiry, policy) {
3173
3280
  if (policy.advertisedVtxoTreeExpiry !== void 0 && batchExpiry !== policy.advertisedVtxoTreeExpiry) {
3174
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3281
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3175
3282
  `batch expiry rejected: ${batchExpiry} does not match the advertised vtxoTreeExpiry ${policy.advertisedVtxoTreeExpiry}`
3176
3283
  );
3177
3284
  }
@@ -3201,21 +3308,21 @@ function resolveCheckpointExitDelayPolicy(network, overrides) {
3201
3308
  function assertValidServerUnrollScript(checkpointTapscript, policy) {
3202
3309
  let script;
3203
3310
  try {
3204
- script = chunk5J5PDZRR_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
3311
+ script = chunkKJ5E646Y_cjs.CSVMultisigTapscript.decode(base.hex.decode(checkpointTapscript));
3205
3312
  } catch (e) {
3206
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3313
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3207
3314
  `checkpoint exit delay rejected: invalid checkpointTapscript from server (${e instanceof Error ? e.message : String(e)})`
3208
3315
  );
3209
3316
  }
3210
3317
  if (policy.advertisedForfeitPubkey !== void 0) {
3211
3318
  const { pubkeys } = script.params;
3212
3319
  if (pubkeys.length !== 1) {
3213
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3320
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3214
3321
  `checkpoint exit delay rejected: checkpointTapscript must commit to exactly one pubkey, got ${pubkeys.length} [${pubkeys.map(base.hex.encode).join(", ")}]`
3215
3322
  );
3216
3323
  }
3217
3324
  if (!utils_js.equalBytes(pubkeys[0], policy.advertisedForfeitPubkey)) {
3218
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3325
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3219
3326
  `checkpoint exit delay rejected: checkpointTapscript pubkey ${base.hex.encode(pubkeys[0])} does not match the advertised forfeitPubkey ${base.hex.encode(policy.advertisedForfeitPubkey)}`
3220
3327
  );
3221
3328
  }
@@ -3259,8 +3366,8 @@ function buildOffchainTx(inputs, outputs, serverUnrollScript) {
3259
3366
  function buildVirtualTx(inputs, outputs) {
3260
3367
  let lockTime = 0n;
3261
3368
  for (const input of inputs) {
3262
- const tapscript = chunk5J5PDZRR_cjs.decodeTapscript(chunk5J5PDZRR_cjs.scriptFromTapLeafScript(input.tapLeafScript));
3263
- if (chunk5J5PDZRR_cjs.CLTVMultisigTapscript.is(tapscript)) {
3369
+ const tapscript = chunkKJ5E646Y_cjs.decodeTapscript(chunkKJ5E646Y_cjs.scriptFromTapLeafScript(input.tapLeafScript));
3370
+ if (chunkKJ5E646Y_cjs.CLTVMultisigTapscript.is(tapscript)) {
3264
3371
  if (lockTime !== 0n) {
3265
3372
  if (isSeconds(lockTime) !== isSeconds(tapscript.params.absoluteTimelock)) {
3266
3373
  throw new Error("cannot mix seconds and blocks locktime");
@@ -3271,7 +3378,7 @@ function buildVirtualTx(inputs, outputs) {
3271
3378
  }
3272
3379
  }
3273
3380
  }
3274
- const tx = new chunk5J5PDZRR_cjs.Transaction({
3381
+ const tx = new chunkKJ5E646Y_cjs.Transaction({
3275
3382
  version: 3,
3276
3383
  lockTime: Number(lockTime)
3277
3384
  });
@@ -3281,12 +3388,12 @@ function buildVirtualTx(inputs, outputs) {
3281
3388
  index: input.vout,
3282
3389
  sequence: lockTime ? btcSigner.DEFAULT_SEQUENCE - 1 : void 0,
3283
3390
  witnessUtxo: {
3284
- script: chunk5J5PDZRR_cjs.VtxoScript.decode(input.tapTree).pkScript,
3391
+ script: chunkKJ5E646Y_cjs.VtxoScript.decode(input.tapTree).pkScript,
3285
3392
  amount: BigInt(input.value)
3286
3393
  },
3287
3394
  tapLeafScript: [input.tapLeafScript]
3288
3395
  });
3289
- chunk5J5PDZRR_cjs.setArkPsbtField(tx, i, chunk5J5PDZRR_cjs.VtxoTaprootTree, input.tapTree);
3396
+ chunkKJ5E646Y_cjs.setArkPsbtField(tx, i, chunkKJ5E646Y_cjs.VtxoTaprootTree, input.tapTree);
3290
3397
  }
3291
3398
  for (const output of outputs) {
3292
3399
  tx.addOutput(output);
@@ -3295,8 +3402,8 @@ function buildVirtualTx(inputs, outputs) {
3295
3402
  return tx;
3296
3403
  }
3297
3404
  function buildCheckpointTx(vtxo, serverUnrollScript) {
3298
- const collaborativeClosure = chunk5J5PDZRR_cjs.decodeTapscript(chunk5J5PDZRR_cjs.scriptFromTapLeafScript(vtxo.tapLeafScript));
3299
- const checkpointVtxoScript = new chunk5J5PDZRR_cjs.VtxoScript([
3405
+ const collaborativeClosure = chunkKJ5E646Y_cjs.decodeTapscript(chunkKJ5E646Y_cjs.scriptFromTapLeafScript(vtxo.tapLeafScript));
3406
+ const checkpointVtxoScript = new chunkKJ5E646Y_cjs.VtxoScript([
3300
3407
  serverUnrollScript.script,
3301
3408
  collaborativeClosure.script
3302
3409
  ]);
@@ -3372,7 +3479,7 @@ function verifyTapscriptSignatures(tx, inputIndex, requiredSigners, excludePubke
3372
3479
  const sighashType = signature.length === 65 ? signature[64] : btcSigner.SigHash.DEFAULT;
3373
3480
  const sig = signature.subarray(0, 64);
3374
3481
  if (!allowedSighashTypes.includes(sighashType)) {
3375
- const sighashName = chunk5J5PDZRR_cjs.formatSighash(sighashType);
3482
+ const sighashName = chunkKJ5E646Y_cjs.formatSighash(sighashType);
3376
3483
  throw new Error(
3377
3484
  `Unallowed sighash type ${sighashName} for input ${inputIndex}, pubkey ${pubKeyHex}.`
3378
3485
  );
@@ -3446,7 +3553,7 @@ function combineTapscriptSigs(signedTx, originalTx) {
3446
3553
  }
3447
3554
  function isValidArkAddress(address) {
3448
3555
  try {
3449
- chunk5J5PDZRR_cjs.ArkAddress.decode(address);
3556
+ chunkKJ5E646Y_cjs.ArkAddress.decode(address);
3450
3557
  return true;
3451
3558
  } catch (e) {
3452
3559
  return false;
@@ -3454,16 +3561,16 @@ function isValidArkAddress(address) {
3454
3561
  }
3455
3562
  function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, context) {
3456
3563
  if (serverCheckpointTxs.length !== expectedCheckpoints.length) {
3457
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3564
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3458
3565
  `${context} returned ${serverCheckpointTxs.length} checkpoints, expected ${expectedCheckpoints.length}`
3459
3566
  );
3460
3567
  }
3461
3568
  const byTxid = new Map(expectedCheckpoints.map((c) => [c.id, c]));
3462
3569
  return serverCheckpointTxs.map((encoded, index) => {
3463
- const server = chunk5J5PDZRR_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
3570
+ const server = chunkKJ5E646Y_cjs.Transaction.fromPSBT(base.base64.decode(encoded));
3464
3571
  const local = byTxid.get(server.id);
3465
3572
  if (!local) {
3466
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3573
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3467
3574
  `${context} checkpoint ${index} txid ${server.id} does not match any submitted checkpoint`
3468
3575
  );
3469
3576
  }
@@ -3473,36 +3580,53 @@ function matchServerCheckpoints(serverCheckpointTxs, expectedCheckpoints, contex
3473
3580
  }
3474
3581
  function assertSubmittedArkTxid(response, signedArkTx, context) {
3475
3582
  if (response.arkTxid !== signedArkTx.id) {
3476
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3583
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3477
3584
  `${context} returned ark txid ${response.arkTxid}, expected ${signedArkTx.id}`
3478
3585
  );
3479
3586
  }
3480
3587
  if (response.finalArkTx === void 0) return;
3481
- const finalTxid = chunk5J5PDZRR_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx)).id;
3588
+ const finalTxid = chunkKJ5E646Y_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx)).id;
3482
3589
  if (finalTxid !== signedArkTx.id) {
3483
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3590
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3484
3591
  `${context} returned final ark tx ${finalTxid}, expected ${signedArkTx.id}`
3485
3592
  );
3486
3593
  }
3487
3594
  }
3488
- function assertServerSignedLeaf(serverTx, localTx, inputIndex, serverPubkeyHex, context) {
3595
+ function assertServerSignedLeaf(serverTx, localTx, inputIndex, serverPubkeys, context) {
3489
3596
  const leaf = localTx.getInput(inputIndex).tapLeafScript?.[0];
3490
3597
  if (!leaf) {
3491
3598
  throw new Error(
3492
3599
  `${context}: input ${inputIndex} carries no spend leaf to verify the server signature against`
3493
3600
  );
3494
3601
  }
3602
+ const script = chunkKJ5E646Y_cjs.scriptFromTapLeafScript(leaf);
3603
+ let leafPubkeys;
3604
+ try {
3605
+ leafPubkeys = chunkKJ5E646Y_cjs.decodeTapscript(script).params.pubkeys.map(
3606
+ (key) => base.hex.encode(chunk2D7F5IU3_cjs.toXOnly(key, "leaf key"))
3607
+ );
3608
+ } catch (error) {
3609
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3610
+ `${context}: input ${inputIndex} spend leaf cannot be decoded (${error instanceof Error ? error.message : String(error)})`
3611
+ );
3612
+ }
3613
+ const signer = leafPubkeys.find((key) => serverPubkeys.has(key));
3614
+ if (!signer) {
3615
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3616
+ `${context}: input ${inputIndex} spend leaf names no signer key the server advertises`
3617
+ );
3618
+ }
3495
3619
  try {
3496
3620
  verifyTapscriptSignatures(
3497
3621
  serverTx,
3498
3622
  inputIndex,
3499
- [serverPubkeyHex],
3623
+ [signer],
3500
3624
  void 0,
3501
3625
  void 0,
3502
- payment_js.tapLeafHash(chunk5J5PDZRR_cjs.scriptFromTapLeafScript(leaf))
3626
+ payment_js.tapLeafHash(script)
3503
3627
  );
3504
3628
  } catch (error) {
3505
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3629
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3506
3630
  `${context}: input ${inputIndex} is not signed by the server on the leaf being spent (${error instanceof Error ? error.message : String(error)})`
3507
3631
  );
3508
3632
  }
@@ -3511,20 +3635,20 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
3511
3635
  const byOutpoint = new Map(inputs.map((input) => [`${input.txid}:${input.vout}`, input]));
3512
3636
  for (const [index, checkpoint] of checkpoints.entries()) {
3513
3637
  if (checkpoint.inputsLength !== 1) {
3514
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3638
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3515
3639
  `${context}: checkpoint ${index} spends ${checkpoint.inputsLength} inputs, expected 1`
3516
3640
  );
3517
3641
  }
3518
3642
  const spent = checkpoint.getInput(0);
3519
3643
  if (!spent.txid || spent.index === void 0) {
3520
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3644
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3521
3645
  `${context}: checkpoint ${index} has no input outpoint`
3522
3646
  );
3523
3647
  }
3524
3648
  const outpoint = `${base.hex.encode(spent.txid)}:${spent.index}`;
3525
3649
  const input = byOutpoint.get(outpoint);
3526
3650
  if (!input) {
3527
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3651
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3528
3652
  `${context}: checkpoint ${index} spends ${outpoint}, which is not one of the requested virtual outputs`
3529
3653
  );
3530
3654
  }
@@ -3532,7 +3656,7 @@ function assertCheckpointsMatchInputs(checkpoints, inputs, unrollCandidates, con
3532
3656
  (unroll) => buildCheckpointTx(input, unroll).tx.id === checkpoint.id
3533
3657
  );
3534
3658
  if (!rebuilt) {
3535
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3659
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3536
3660
  `${context}: checkpoint ${index} txid ${checkpoint.id} differs from the checkpoint built locally for ${outpoint}`
3537
3661
  );
3538
3662
  }
@@ -3558,9 +3682,9 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
3558
3682
  const matched = matchServerCheckpoints(signedCheckpointTxs, offchainTx.checkpoints, "submitTx");
3559
3683
  matched.forEach(({ server }, index) => {
3560
3684
  try {
3561
- chunk5J5PDZRR_cjs.assertAllowedSighashTypes(server);
3685
+ chunkKJ5E646Y_cjs.assertAllowedSighashTypes(server);
3562
3686
  } catch (error) {
3563
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3687
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3564
3688
  `submitTx checkpoint ${index}: ${error instanceof Error ? error.message : String(error)}`
3565
3689
  );
3566
3690
  }
@@ -3568,29 +3692,27 @@ async function submitOffchainTx(provider, offchainTx, signer, hooks, options) {
3568
3692
  const verify = options?.verifyServerSignatures;
3569
3693
  if (verify) {
3570
3694
  if (response.finalArkTx === void 0) {
3571
- throw new chunk5J5PDZRR_cjs.ServerResponseMismatchError(
3695
+ throw new chunkKJ5E646Y_cjs.ServerResponseMismatchError(
3572
3696
  "submitTx: server returned no final ark tx to verify its signatures against"
3573
3697
  );
3574
3698
  }
3575
- const finalArkTx = chunk5J5PDZRR_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx));
3576
- const serverPubkeyHex = base.hex.encode(chunkP6EXRY5L_cjs.toXOnly(verify.serverPubkey, "server key"));
3699
+ const finalArkTx = chunkKJ5E646Y_cjs.Transaction.fromPSBT(base.base64.decode(response.finalArkTx));
3700
+ const serverPubkeys = new Set(
3701
+ [verify.serverPubkey, ...verify.deprecatedServerPubkeys ?? []].map(
3702
+ (key) => base.hex.encode(chunk2D7F5IU3_cjs.toXOnly(key, "server key"))
3703
+ )
3704
+ );
3577
3705
  for (let i = 0; i < offchainTx.arkTx.inputsLength; i++) {
3578
3706
  assertServerSignedLeaf(
3579
3707
  finalArkTx,
3580
3708
  offchainTx.arkTx,
3581
3709
  i,
3582
- serverPubkeyHex,
3710
+ serverPubkeys,
3583
3711
  "submitTx ark tx"
3584
3712
  );
3585
3713
  }
3586
3714
  matched.forEach(
3587
- ({ server, local }, index) => assertServerSignedLeaf(
3588
- server,
3589
- local,
3590
- 0,
3591
- serverPubkeyHex,
3592
- `submitTx checkpoint ${index}`
3593
- )
3715
+ ({ server, local }, index) => assertServerSignedLeaf(server, local, 0, serverPubkeys, `submitTx checkpoint ${index}`)
3594
3716
  );
3595
3717
  }
3596
3718
  let finalCheckpoints;
@@ -3629,12 +3751,12 @@ function claimWithPreimageIdentity(identity, preimage) {
3629
3751
  return {
3630
3752
  ...identity,
3631
3753
  sign: async (tx, inputIndexes) => {
3632
- const signed = chunk5J5PDZRR_cjs.Transaction.fromPSBT(
3754
+ const signed = chunkKJ5E646Y_cjs.Transaction.fromPSBT(
3633
3755
  (await identity.sign(tx.clone(), inputIndexes)).toPSBT()
3634
3756
  );
3635
3757
  const indexes = inputIndexes ?? Array.from({ length: signed.inputsLength }, (_, i) => i);
3636
3758
  for (const index of indexes) {
3637
- chunk5J5PDZRR_cjs.setArkPsbtField(signed, index, chunk5J5PDZRR_cjs.ConditionWitness, [preimage]);
3759
+ chunkKJ5E646Y_cjs.setArkPsbtField(signed, index, chunkKJ5E646Y_cjs.ConditionWitness, [preimage]);
3638
3760
  }
3639
3761
  return signed;
3640
3762
  }
@@ -3829,7 +3951,7 @@ function extendCoinWithTapscript(boardingTapscript, utxo) {
3829
3951
  };
3830
3952
  }
3831
3953
  function deriveContractTapscripts(contract) {
3832
- const handler = chunkP6EXRY5L_cjs.contractHandlers.get(contract.type);
3954
+ const handler = chunk2D7F5IU3_cjs.contractHandlers.get(contract.type);
3833
3955
  if (!handler) {
3834
3956
  throw new Error(`No handler for contract type '${contract.type}'`);
3835
3957
  }
@@ -3900,7 +4022,7 @@ function getRandomId() {
3900
4022
  }
3901
4023
  function isValidArkAddress2(address) {
3902
4024
  try {
3903
- chunk5J5PDZRR_cjs.ArkAddress.decode(address);
4025
+ chunkKJ5E646Y_cjs.ArkAddress.decode(address);
3904
4026
  return true;
3905
4027
  } catch (e) {
3906
4028
  return false;
@@ -3928,7 +4050,7 @@ function assertRecipientArkAddress(encoded, address, context) {
3928
4050
  function assertTapTreeDerivesAddress(encoded, tapTree, address) {
3929
4051
  let derived;
3930
4052
  try {
3931
- derived = chunk5J5PDZRR_cjs.VtxoScript.decode(tapTree).pkScript;
4053
+ derived = chunkKJ5E646Y_cjs.VtxoScript.decode(tapTree).pkScript;
3932
4054
  } catch (e) {
3933
4055
  throw new Error(
3934
4056
  `Invalid tapTree for ${encoded}: ${e instanceof Error ? e.message : String(e)}`
@@ -3945,7 +4067,7 @@ function validateRecipients(recipients, dustAmount, context) {
3945
4067
  for (const recipient of recipients) {
3946
4068
  let address;
3947
4069
  try {
3948
- address = chunk5J5PDZRR_cjs.ArkAddress.decode(recipient.address);
4070
+ address = chunkKJ5E646Y_cjs.ArkAddress.decode(recipient.address);
3949
4071
  } catch (e) {
3950
4072
  throw new Error(`Invalid Arkade address: ${recipient.address}`);
3951
4073
  }
@@ -3970,7 +4092,7 @@ function validateRecipients(recipients, dustAmount, context) {
3970
4092
 
3971
4093
  // src/contracts/spendability.ts
3972
4094
  function isContractGenericallySpendable(contract) {
3973
- return chunkP6EXRY5L_cjs.contractHandlers.get(contract.type)?.isGenericallySpendable?.(contract) === true;
4095
+ return chunk2D7F5IU3_cjs.contractHandlers.get(contract.type)?.isGenericallySpendable?.(contract) === true;
3974
4096
  }
3975
4097
  function gatedContracts(contracts) {
3976
4098
  const gated = /* @__PURE__ */ new Map();
@@ -3979,11 +4101,20 @@ function gatedContracts(contracts) {
3979
4101
  }
3980
4102
  return gated;
3981
4103
  }
4104
+ function gatedFrom(snapshot) {
4105
+ return gatedContracts(snapshot.map((entry) => entry.contract));
4106
+ }
4107
+ function gatedTypeOf(vtxo, gated) {
4108
+ return vtxo.script === void 0 ? void 0 : gated.get(vtxo.script);
4109
+ }
4110
+ function isGatedVtxo(vtxo, gated) {
4111
+ return gatedTypeOf(vtxo, gated) !== void 0;
4112
+ }
3982
4113
  function gateExclusion(gated) {
3983
4114
  return (vtxo) => {
3984
- const type = vtxo.script === void 0 ? void 0 : gated.get(vtxo.script);
4115
+ const type = gatedTypeOf(vtxo, gated);
3985
4116
  if (type === void 0) return void 0;
3986
- if (!chunkP6EXRY5L_cjs.contractHandlers.has(type)) {
4117
+ if (!chunk2D7F5IU3_cjs.contractHandlers.has(type)) {
3987
4118
  return `at ${vtxo.script} (contract type '${type}') has no handler registered in this build`;
3988
4119
  }
3989
4120
  return `at ${vtxo.script} (contract type '${type}') is not generically spendable`;
@@ -4019,7 +4150,7 @@ function selectPendingRecoveryOutpoints(contractsWithVtxos, signerSet, nowSecond
4019
4150
  continue;
4020
4151
  }
4021
4152
  for (const v of vtxos) {
4022
- if (!chunk5J5PDZRR_cjs.hasTerminalSpend(v) && !v.isSwept && !v.isUnrolled) {
4153
+ if (!chunkKJ5E646Y_cjs.hasTerminalSpend(v) && !v.isSwept && !v.isUnrolled) {
4023
4154
  out.add(`${v.txid}:${v.vout}`);
4024
4155
  }
4025
4156
  }
@@ -4054,10 +4185,10 @@ function byValueDescending(vtxos) {
4054
4185
  return [...vtxos].sort((a, b) => b.value - a.value);
4055
4186
  }
4056
4187
  async function fetchTimeHeight(wallet) {
4057
- return chunk5J5PDZRR_cjs.resolveTimeHeight(wallet.onchainProvider);
4188
+ return chunkKJ5E646Y_cjs.resolveTimeHeight(wallet.onchainProvider);
4058
4189
  }
4059
4190
  function canMigrateBySend(vtxo, now) {
4060
- if (!chunk5J5PDZRR_cjs.canSpendOffchain(vtxo, now)) return false;
4191
+ if (!chunkKJ5E646Y_cjs.canSpendOffchain(vtxo, now)) return false;
4061
4192
  return vtxo.expiresAt !== void 0 || vtxo.expiresAtHeight !== void 0;
4062
4193
  }
4063
4194
  function byExpiryAscending(vtxos, now) {
@@ -4065,7 +4196,7 @@ function byExpiryAscending(vtxos, now) {
4065
4196
  if (vtxo.isSwept) return -Infinity;
4066
4197
  if (vtxo.expiresAt !== void 0) return vtxo.expiresAt.getTime();
4067
4198
  if (vtxo.expiresAtHeight !== void 0) {
4068
- return chunk5J5PDZRR_cjs.isPastExpiry(vtxo, now) ? -Infinity : Infinity;
4199
+ return chunkKJ5E646Y_cjs.isPastExpiry(vtxo, now) ? -Infinity : Infinity;
4069
4200
  }
4070
4201
  return Infinity;
4071
4202
  };
@@ -4092,7 +4223,7 @@ function priceSettlementInputs(vtxos, estimator) {
4092
4223
  const payable = [];
4093
4224
  const net = /* @__PURE__ */ new Map();
4094
4225
  for (const vtxo of vtxos) {
4095
- const inputFee = estimator.evalOffchainInput(chunk5J5PDZRR_cjs.toOffchainInputFeeParams(vtxo));
4226
+ const inputFee = estimator.evalOffchainInput(chunkKJ5E646Y_cjs.toOffchainInputFeeParams(vtxo));
4096
4227
  if (inputFee.satoshis >= vtxo.value) {
4097
4228
  continue;
4098
4229
  }
@@ -4118,7 +4249,7 @@ function deductOffchainOutputFee(subtotal, estimator, arkAddress) {
4118
4249
  }
4119
4250
  const outputFee = estimator.evalOffchainOutput({
4120
4251
  amount: subtotal,
4121
- script: base.hex.encode(chunk5J5PDZRR_cjs.ArkAddress.decode(arkAddress).pkScript)
4252
+ script: base.hex.encode(chunkKJ5E646Y_cjs.ArkAddress.decode(arkAddress).pkScript)
4122
4253
  });
4123
4254
  return subtotal - BigInt(outputFee.satoshis);
4124
4255
  }
@@ -4136,10 +4267,10 @@ var DEFAULT_SETTLEMENT_CONFIG = {
4136
4267
  };
4137
4268
  function getRecoverableVtxos(vtxos, dustAmount, now) {
4138
4269
  return vtxos.filter((vtxo) => {
4139
- if (chunk5J5PDZRR_cjs.canRecoverOnchain(vtxo, now)) {
4270
+ if (chunkKJ5E646Y_cjs.canRecoverOnchain(vtxo, now)) {
4140
4271
  return true;
4141
4272
  }
4142
- if (chunk5J5PDZRR_cjs.canSpendOffchain(vtxo, now) && vtxo.isPreconfirmed && isSubdust(vtxo, dustAmount)) {
4273
+ if (chunkKJ5E646Y_cjs.canSpendOffchain(vtxo, now) && vtxo.isPreconfirmed && isSubdust(vtxo, dustAmount)) {
4143
4274
  return true;
4144
4275
  }
4145
4276
  return false;
@@ -4171,7 +4302,7 @@ function getRecoverableWithSubdust(vtxos, dustAmount, now) {
4171
4302
  function isVtxoExpiringSoon(vtxo, thresholdMs) {
4172
4303
  if (vtxo.isUnrolled) return false;
4173
4304
  const realThresholdMs = thresholdMs <= 100 ? DEFAULT_THRESHOLD_MS : thresholdMs;
4174
- const expiresAt = chunk5J5PDZRR_cjs.normalizeVtxo(vtxo).expiresAt;
4305
+ const expiresAt = chunkKJ5E646Y_cjs.normalizeVtxo(vtxo).expiresAt;
4175
4306
  if (expiresAt === void 0) return false;
4176
4307
  const now = Date.now();
4177
4308
  const batchExpiry = expiresAt.getTime();
@@ -4182,7 +4313,7 @@ function getExpiringAndRecoverableVtxos(vtxos, thresholdMs, dustAmount, now) {
4182
4313
  return vtxos.filter(
4183
4314
  // The leading exclusion covers the `isSubdust` arm too, which is a value
4184
4315
  // property and would otherwise re-admit an exited coin on its own.
4185
- (vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) || chunk5J5PDZRR_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dustAmount))
4316
+ (vtxo) => !vtxo.isUnrolled && (isVtxoExpiringSoon(vtxo, thresholdMs) || chunkKJ5E646Y_cjs.canRecoverOnchain(vtxo, now) || isSubdust(vtxo, dustAmount))
4186
4317
  );
4187
4318
  }
4188
4319
  function isMigrationCapable(wallet) {
@@ -4781,11 +4912,11 @@ var VtxoManager = class _VtxoManager {
4781
4912
  `Sweep not economical: output ${outputAmount} sats after ${fee} sats fee is below dust (${dustAmount} sats)`
4782
4913
  );
4783
4914
  }
4784
- const tx = new chunk5J5PDZRR_cjs.Transaction();
4915
+ const tx = new chunkKJ5E646Y_cjs.Transaction();
4785
4916
  for (const utxo of expiredUtxos) {
4786
- const utxoScript = chunk5J5PDZRR_cjs.VtxoScript.decode(utxo.tapTree);
4917
+ const utxoScript = chunkKJ5E646Y_cjs.VtxoScript.decode(utxo.tapTree);
4787
4918
  const utxoExitLeaf = utxoScript.leaves.find(
4788
- (leaf) => chunk5J5PDZRR_cjs.CSVMultisigTapscript.isScriptValid(chunk5J5PDZRR_cjs.scriptFromTapLeafScript(leaf)) === true
4919
+ (leaf) => chunkKJ5E646Y_cjs.CSVMultisigTapscript.isScriptValid(chunkKJ5E646Y_cjs.scriptFromTapLeafScript(leaf)) === true
4789
4920
  );
4790
4921
  if (!utxoExitLeaf) {
4791
4922
  throw new Error(
@@ -4800,7 +4931,7 @@ var VtxoManager = class _VtxoManager {
4800
4931
  amount: BigInt(utxo.value)
4801
4932
  },
4802
4933
  tapLeafScript: [utxoExitLeaf],
4803
- sequence: chunk5J5PDZRR_cjs.getSequence(utxoExitLeaf)
4934
+ sequence: chunkKJ5E646Y_cjs.getSequence(utxoExitLeaf)
4804
4935
  });
4805
4936
  }
4806
4937
  tx.addOutputAddress(boardingAddress, outputAmount, this.getNetwork());
@@ -5043,8 +5174,8 @@ var VtxoManager = class _VtxoManager {
5043
5174
  const cls = classifyAgainstSignerSet(serverPubKey, signerSet, nowSeconds);
5044
5175
  if (cls.status === "CURRENT") continue;
5045
5176
  const live = vtxos.filter((v) => !v.isUnrolled);
5046
- const recoverable = live.filter((v) => v.isSwept && !chunk5J5PDZRR_cjs.hasTerminalSpend(v));
5047
- const spendable = live.filter((v) => !chunk5J5PDZRR_cjs.hasTerminalSpend(v) && !v.isSwept);
5177
+ const recoverable = live.filter((v) => v.isSwept && !chunkKJ5E646Y_cjs.hasTerminalSpend(v));
5178
+ const spendable = live.filter((v) => !chunkKJ5E646Y_cjs.hasTerminalSpend(v) && !v.isSwept);
5048
5179
  const value = spendable.reduce((sum, v) => sum + v.value, 0);
5049
5180
  let recoverableCount = 0;
5050
5181
  let recoverableValue = 0;
@@ -5057,7 +5188,7 @@ var VtxoManager = class _VtxoManager {
5057
5188
  awaitingSweepCount = spendable.length;
5058
5189
  awaitingSweepValue = value;
5059
5190
  for (const v of spendable) {
5060
- const exp = chunk5J5PDZRR_cjs.toBatchExpiry(v);
5191
+ const exp = chunkKJ5E646Y_cjs.toBatchExpiry(v);
5061
5192
  if (exp !== void 0 && (nextSweepEta === void 0 || exp < nextSweepEta)) {
5062
5193
  nextSweepEta = exp;
5063
5194
  }
@@ -5318,7 +5449,7 @@ var VtxoManager = class _VtxoManager {
5318
5449
  /** Decodes the boarding tapscript exit path to extract the CSV timelock. */
5319
5450
  getBoardingTimelock() {
5320
5451
  const wallet = this.getSweepWallet();
5321
- const exitScript = chunk5J5PDZRR_cjs.CSVMultisigTapscript.decode(
5452
+ const exitScript = chunkKJ5E646Y_cjs.CSVMultisigTapscript.decode(
5322
5453
  base.hex.decode(wallet.boardingTapscript.exitScript)
5323
5454
  );
5324
5455
  return exitScript.params.timelock;
@@ -5449,8 +5580,8 @@ var VtxoManager = class _VtxoManager {
5449
5580
  * or doesn't carry the metadata.
5450
5581
  */
5451
5582
  extractSpentOutpoint(error) {
5452
- const ark = chunk5J5PDZRR_cjs.maybeArkError(error);
5453
- if (!chunk5J5PDZRR_cjs.isArkError(ark, chunk5J5PDZRR_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
5583
+ const ark = chunkKJ5E646Y_cjs.maybeArkError(error);
5584
+ if (!chunkKJ5E646Y_cjs.isArkError(ark, chunkKJ5E646Y_cjs.ArkErrorName.VTXO_ALREADY_SPENT)) return void 0;
5454
5585
  const raw = ark.metadata?.vtxo_outpoint;
5455
5586
  if (typeof raw !== "string") return void 0;
5456
5587
  const [txid, voutStr] = raw.split(":");
@@ -5640,7 +5771,7 @@ var VtxoManager = class _VtxoManager {
5640
5771
  if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
5641
5772
  break;
5642
5773
  }
5643
- const inputFee = estimator.evalOffchainInput(chunk5J5PDZRR_cjs.toOffchainInputFeeParams(v));
5774
+ const inputFee = estimator.evalOffchainInput(chunkKJ5E646Y_cjs.toOffchainInputFeeParams(v));
5644
5775
  if (inputFee.satoshis >= v.value) {
5645
5776
  continue;
5646
5777
  }
@@ -5660,7 +5791,7 @@ var VtxoManager = class _VtxoManager {
5660
5791
  const arkAddress = await this.wallet.getAddress();
5661
5792
  const outputFee = estimator.evalOffchainOutput({
5662
5793
  amount: totalAmount,
5663
- script: base.hex.encode(chunk5J5PDZRR_cjs.ArkAddress.decode(arkAddress).pkScript)
5794
+ script: base.hex.encode(chunkKJ5E646Y_cjs.ArkAddress.decode(arkAddress).pkScript)
5664
5795
  });
5665
5796
  totalAmount -= BigInt(outputFee.satoshis);
5666
5797
  if (totalAmount < dustAmount) return;
@@ -5740,7 +5871,7 @@ var ArkNote = class _ArkNote {
5740
5871
  this.value = value;
5741
5872
  this.HRP = HRP;
5742
5873
  const preimageHash = utils_js.sha256(this.preimage);
5743
- this.vtxoScript = new chunk5J5PDZRR_cjs.VtxoScript([noteTapscript(preimageHash)]);
5874
+ this.vtxoScript = new chunkKJ5E646Y_cjs.VtxoScript([noteTapscript(preimageHash)]);
5744
5875
  const leaf = this.vtxoScript.leaves[0];
5745
5876
  this.txid = base.hex.encode(new Uint8Array(preimageHash).reverse());
5746
5877
  this.tapTree = this.vtxoScript.encode();
@@ -5907,7 +6038,7 @@ var ArkadeCash = class _ArkadeCash {
5907
6038
  const privateKey = data.slice(1, 33);
5908
6039
  const serverPubKey = data.slice(33, 65);
5909
6040
  const sequence = new DataView(data.buffer, data.byteOffset + 65, 4).getUint32(0, false);
5910
- const csvTimelock = chunk5J5PDZRR_cjs.sequenceToTimelock(sequence);
6041
+ const csvTimelock = chunkKJ5E646Y_cjs.sequenceToTimelock(sequence);
5911
6042
  return new _ArkadeCash(privateKey, serverPubKey, csvTimelock, decoded.prefix);
5912
6043
  }
5913
6044
  toString() {
@@ -5915,7 +6046,7 @@ var ArkadeCash = class _ArkadeCash {
5915
6046
  data[0] = _ArkadeCash.Version;
5916
6047
  data.set(this._privateKey, 1);
5917
6048
  data.set(this._serverPubKey, 33);
5918
- const sequence = chunk5J5PDZRR_cjs.timelockToSequence(this.csvTimelock);
6049
+ const sequence = chunkKJ5E646Y_cjs.timelockToSequence(this.csvTimelock);
5919
6050
  new DataView(data.buffer, data.byteOffset + 65, 4).setUint32(0, sequence, false);
5920
6051
  const words = base.bech32m.toWords(data);
5921
6052
  return base.bech32m.encode(this.hrp, words, 1023);
@@ -5924,7 +6055,7 @@ var ArkadeCash = class _ArkadeCash {
5924
6055
  return SingleKey.fromPrivateKey(this._privateKey);
5925
6056
  }
5926
6057
  get vtxoScript() {
5927
- return new chunkP6EXRY5L_cjs.DefaultVtxo.Script({
6058
+ return new chunk2D7F5IU3_cjs.DefaultVtxo.Script({
5928
6059
  pubKey: this._publicKey,
5929
6060
  serverPubKey: this._serverPubKey,
5930
6061
  csvTimelock: this.csvTimelock
@@ -6185,7 +6316,7 @@ async function captureExitBranch(params) {
6185
6316
  const nonCommitment = ordered.filter((c) => chainTxTypeToChainedExit(c.type) !== 1 /* Commitment */).map((c) => c.txid);
6186
6317
  if (nonCommitment.length > 0) {
6187
6318
  for (const psbt of await resolver.getVirtualTxs(nonCommitment)) {
6188
- psbtByTxid.set(chunk5J5PDZRR_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
6319
+ psbtByTxid.set(chunkKJ5E646Y_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
6189
6320
  }
6190
6321
  }
6191
6322
  }
@@ -6228,10 +6359,10 @@ var IndexerExitDataSource = class {
6228
6359
  while (hasMore) {
6229
6360
  const { chain: page, page: meta } = await this.indexer.getVtxoChain(
6230
6361
  { txid: vtxo.txid, vout: vtxo.vout },
6231
- { pageIndex, pageSize: chunk5J5PDZRR_cjs.DEFAULT_PAGE_SIZE }
6362
+ { pageIndex, pageSize: chunkKJ5E646Y_cjs.DEFAULT_PAGE_SIZE }
6232
6363
  );
6233
6364
  chain.push(...page);
6234
- hasMore = meta ? page.length === chunk5J5PDZRR_cjs.DEFAULT_PAGE_SIZE : false;
6365
+ hasMore = meta ? page.length === chunkKJ5E646Y_cjs.DEFAULT_PAGE_SIZE : false;
6235
6366
  pageIndex++;
6236
6367
  }
6237
6368
  return chain;
@@ -6243,12 +6374,12 @@ var IndexerExitDataSource = class {
6243
6374
  while (hasMore) {
6244
6375
  const { txs, page } = await this.indexer.getVirtualTxs(txids, {
6245
6376
  pageIndex,
6246
- pageSize: chunk5J5PDZRR_cjs.DEFAULT_PAGE_SIZE
6377
+ pageSize: chunkKJ5E646Y_cjs.DEFAULT_PAGE_SIZE
6247
6378
  });
6248
6379
  for (const psbt of txs) {
6249
- out.set(chunk5J5PDZRR_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
6380
+ out.set(chunkKJ5E646Y_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
6250
6381
  }
6251
- hasMore = page ? txs.length === chunk5J5PDZRR_cjs.DEFAULT_PAGE_SIZE : false;
6382
+ hasMore = page ? txs.length === chunkKJ5E646Y_cjs.DEFAULT_PAGE_SIZE : false;
6252
6383
  pageIndex++;
6253
6384
  }
6254
6385
  return out;
@@ -6269,7 +6400,7 @@ function chainedTxTypeToChainTxType(t) {
6269
6400
  }
6270
6401
  }
6271
6402
  function psbtInputTxids(psbtBase64) {
6272
- const tx = chunk5J5PDZRR_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
6403
+ const tx = chunkKJ5E646Y_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
6273
6404
  const ids = [];
6274
6405
  for (let i = 0; i < tx.inputsLength; i++) {
6275
6406
  const txid = tx.getInput(i).txid;
@@ -6628,10 +6759,10 @@ async function resolveArkInfo(arkProvider, walletRepository) {
6628
6759
  try {
6629
6760
  info = await arkProvider.getInfo();
6630
6761
  } catch (err) {
6631
- if (!chunk5J5PDZRR_cjs.isRetryableProviderError(err)) throw err;
6762
+ if (!chunkKJ5E646Y_cjs.isRetryableProviderError(err)) throw err;
6632
6763
  const snapshot = await loadArkInfoSnapshot(walletRepository);
6633
6764
  if (!snapshot) {
6634
- throw new chunk5J5PDZRR_cjs.ProviderUnavailableError(
6765
+ throw new chunkKJ5E646Y_cjs.ProviderUnavailableError(
6635
6766
  "Arkade server info is unavailable and no cached snapshot exists",
6636
6767
  { cause: err }
6637
6768
  );
@@ -6959,6 +7090,24 @@ exports.Batch = void 0;
6959
7090
  })(exports.Batch || (exports.Batch = {}));
6960
7091
 
6961
7092
  // src/utils/transactionHistory.ts
7093
+ function localCreatedAtByTxid(vtxos) {
7094
+ const createdAt = /* @__PURE__ */ new Map();
7095
+ for (const vtxo of vtxos) {
7096
+ if (vtxo.txid && !createdAt.has(vtxo.txid)) {
7097
+ createdAt.set(vtxo.txid, vtxo.createdAt.getTime());
7098
+ }
7099
+ }
7100
+ return createdAt;
7101
+ }
7102
+ function gatedTouchpoints(gated) {
7103
+ const paidIn = /* @__PURE__ */ new Set();
7104
+ const paidOut = /* @__PURE__ */ new Set();
7105
+ for (const vtxo of gated) {
7106
+ if (vtxo.txid) paidIn.add(vtxo.txid);
7107
+ if (vtxo.isSpent && vtxo.arkTxId) paidOut.add(vtxo.arkTxId);
7108
+ }
7109
+ return { paidIn, paidOut };
7110
+ }
6962
7111
  var txKey = {
6963
7112
  commitmentTxid: "",
6964
7113
  boardingTxid: "",
@@ -7010,24 +7159,27 @@ function subtractAssets(spent, change) {
7010
7159
  if (map.size === 0) return void 0;
7011
7160
  return Array.from(map, ([assetId, amount]) => ({ assetId, amount }));
7012
7161
  }
7013
- function collectArkTxidsNeedingCreatedAt(vtxos) {
7014
- const ownTxids = new Set(vtxos.map((v) => v.txid));
7162
+ function collectArkTxidsNeedingCreatedAt(vtxos, localCreatedAt) {
7015
7163
  const txids = /* @__PURE__ */ new Set();
7016
7164
  for (const vtxo of vtxos) {
7017
- if (vtxo.isSpent && vtxo.arkTxId && !ownTxids.has(vtxo.arkTxId)) {
7165
+ if (vtxo.isSpent && vtxo.arkTxId && !localCreatedAt.has(vtxo.arkTxId)) {
7018
7166
  txids.add(vtxo.arkTxId);
7019
7167
  }
7020
7168
  }
7021
7169
  return [...txids];
7022
7170
  }
7023
- async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, resolveTxCreatedAt) {
7024
- const fromOldestVtxo = vtxos.map(chunk5J5PDZRR_cjs.normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
7025
- const txidsNeedingCreatedAt = resolveTxCreatedAt ? collectArkTxidsNeedingCreatedAt(fromOldestVtxo) : [];
7171
+ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnore, resolveTxCreatedAt, gatedScripts = /* @__PURE__ */ new Map()) {
7172
+ const normalized = vtxos.map(chunkKJ5E646Y_cjs.normalizeVtxo).sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
7173
+ const localCreatedAt = localCreatedAtByTxid(normalized);
7174
+ const gatedVtxos = normalized.filter((vtxo) => isGatedVtxo(vtxo, gatedScripts));
7175
+ const ownVtxos = normalized.filter((vtxo) => !isGatedVtxo(vtxo, gatedScripts));
7176
+ const { paidIn: paidIntoGated, paidOut: paidOutOfGated } = gatedTouchpoints(gatedVtxos);
7177
+ const txidsNeedingCreatedAt = resolveTxCreatedAt ? collectArkTxidsNeedingCreatedAt(ownVtxos, localCreatedAt) : [];
7026
7178
  const resolvedCreatedAt = resolveTxCreatedAt && txidsNeedingCreatedAt.length > 0 ? await resolveTxCreatedAt(txidsNeedingCreatedAt) : /* @__PURE__ */ new Map();
7027
7179
  const unmatchedSettledBoardingTxs = allBoardingTxs.filter(isSettledBoardingReceive).sort((a, b) => a.createdAt - b.createdAt);
7028
7180
  const sent = [];
7029
7181
  let received = [];
7030
- for (const vtxo of fromOldestVtxo) {
7182
+ for (const vtxo of ownVtxos) {
7031
7183
  if (vtxo.status.isLeaf) {
7032
7184
  const commitmentTxid = vtxo.commitmentTxIds[0];
7033
7185
  const vtxoCreatedAt = vtxo.createdAt.getTime();
@@ -7037,7 +7189,7 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
7037
7189
  unmatchedSettledBoardingTxs,
7038
7190
  (tx) => tx.createdAt <= vtxoCreatedAt && (tx.key.commitmentTxid === commitmentTxid || tx.key.commitmentTxid === vtxo.settledBy)
7039
7191
  );
7040
- } else if (fromOldestVtxo.filter((v) => v.settledBy === vtxo.commitmentTxIds[0]).length === 0) {
7192
+ } else if (ownVtxos.filter((v) => v.settledBy === vtxo.commitmentTxIds[0]).length === 0) {
7041
7193
  const duplicateBoardingReceive = consumeBoardingReceive(
7042
7194
  unmatchedSettledBoardingTxs,
7043
7195
  (tx) => tx.amount === vtxo.value && tx.createdAt <= vtxoCreatedAt
@@ -7058,11 +7210,14 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
7058
7210
  });
7059
7211
  }
7060
7212
  }
7061
- } else if (fromOldestVtxo.filter((v) => v.arkTxId === vtxo.txid).length === 0) {
7213
+ } else if (ownVtxos.filter((v) => v.arkTxId === vtxo.txid).length === 0) {
7062
7214
  const assets = collectAssets([vtxo]);
7063
7215
  received.push({
7064
7216
  key: { ...txKey, arkTxid: vtxo.txid },
7065
- tag: "offchain",
7217
+ // The escrow paying out: a swap fill or a cancel spends the
7218
+ // gated coin and lands the proceeds here. Nothing else about
7219
+ // the row changes — the tag only names the counterparty.
7220
+ tag: paidOutOfGated.has(vtxo.txid) ? "gated" : "offchain",
7066
7221
  type: "RECEIVED" /* TxReceived */,
7067
7222
  amount: vtxo.value,
7068
7223
  settled: vtxo.status.isLeaf || vtxo.isSpent,
@@ -7072,8 +7227,8 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
7072
7227
  }
7073
7228
  if (vtxo.isSpent) {
7074
7229
  if (vtxo.arkTxId && !sent.some((s) => s.key.arkTxid === vtxo.arkTxId)) {
7075
- const changes = fromOldestVtxo.filter((_) => _.txid === vtxo.arkTxId);
7076
- const allSpent = fromOldestVtxo.filter((v) => v.arkTxId === vtxo.arkTxId);
7230
+ const changes = ownVtxos.filter((_) => _.txid === vtxo.arkTxId);
7231
+ const allSpent = ownVtxos.filter((v) => v.arkTxId === vtxo.arkTxId);
7077
7232
  const spentAmount = allSpent.reduce((acc, v) => acc + v.value, 0);
7078
7233
  let txAmount = 0;
7079
7234
  let txTime = 0;
@@ -7083,13 +7238,16 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
7083
7238
  txTime = changes[0].createdAt.getTime();
7084
7239
  } else {
7085
7240
  txAmount = spentAmount;
7086
- txTime = resolvedCreatedAt.get(vtxo.arkTxId) ?? vtxo.createdAt.getTime() + 1;
7241
+ txTime = localCreatedAt.get(vtxo.arkTxId) ?? resolvedCreatedAt.get(vtxo.arkTxId) ?? vtxo.createdAt.getTime() + 1;
7087
7242
  }
7088
7243
  const assets = subtractAssets(allSpent, changes);
7089
7244
  if (txAmount !== 0 || assets) {
7090
7245
  sent.push({
7091
7246
  key: { ...txKey, arkTxid: vtxo.arkTxId },
7092
- tag: "offchain",
7247
+ // Funding the escrow: an output of this tx landed on a
7248
+ // gated contract of the wallet's, so the send is to the
7249
+ // user's own covenant rather than to a stranger.
7250
+ tag: paidIntoGated.has(vtxo.arkTxId) ? "gated" : "offchain",
7093
7251
  type: "SENT" /* TxSent */,
7094
7252
  amount: txAmount,
7095
7253
  settled: true,
@@ -7099,10 +7257,10 @@ async function buildTransactionHistory(vtxos, allBoardingTxs, commitmentsToIgnor
7099
7257
  }
7100
7258
  }
7101
7259
  if (vtxo.settledBy && !commitmentsToIgnore.has(vtxo.settledBy) && !sent.some((s) => s.key.commitmentTxid === vtxo.settledBy)) {
7102
- const changes = fromOldestVtxo.filter(
7260
+ const changes = ownVtxos.filter(
7103
7261
  (v) => v.status.isLeaf && v.commitmentTxIds.length > 0 && v.commitmentTxIds.every((_) => vtxo.settledBy === _)
7104
7262
  );
7105
- const forfeitVtxos = fromOldestVtxo.filter((v) => v.settledBy === vtxo.settledBy);
7263
+ const forfeitVtxos = ownVtxos.filter((v) => v.settledBy === vtxo.settledBy);
7106
7264
  const forfeitAmount = forfeitVtxos.reduce((acc, v) => acc + v.value, 0);
7107
7265
  if (changes.length > 0) {
7108
7266
  const settledAmount = changes.reduce((acc, v) => acc + v.value, 0);
@@ -7185,7 +7343,7 @@ var AssetManager = class extends ReadonlyAssetManager {
7185
7343
  const virtualCoins = await this.wallet.getSpendableVtxos({
7186
7344
  withRecoverable: false
7187
7345
  });
7188
- const controlAssetRef = params.controlAssetId ? chunkFM263GKH_cjs.AssetRef.fromId(chunkFM263GKH_cjs.AssetId.fromString(params.controlAssetId)) : null;
7346
+ const controlAssetRef = params.controlAssetId ? chunkD5DLGVN4_cjs.AssetRef.fromId(chunkD5DLGVN4_cjs.AssetId.fromString(params.controlAssetId)) : null;
7189
7347
  const coinSelection = selectVirtualCoins(virtualCoins, Number(this.wallet.dustAmount));
7190
7348
  let totalBtcSelected = 0n;
7191
7349
  const assetChanges = /* @__PURE__ */ new Map();
@@ -7198,8 +7356,8 @@ var AssetManager = class extends ReadonlyAssetManager {
7198
7356
  }
7199
7357
  }
7200
7358
  const groups = [];
7201
- const issuedAssetOutput = chunkFM263GKH_cjs.AssetOutput.create(0, params.amount);
7202
- const issuedAssetGroup = chunkFM263GKH_cjs.AssetGroup.create(
7359
+ const issuedAssetOutput = chunkD5DLGVN4_cjs.AssetOutput.create(0, params.amount);
7360
+ const issuedAssetGroup = chunkD5DLGVN4_cjs.AssetGroup.create(
7203
7361
  null,
7204
7362
  controlAssetRef,
7205
7363
  [],
@@ -7214,28 +7372,28 @@ var AssetManager = class extends ReadonlyAssetManager {
7214
7372
  for (const [inputIndex, assets] of assetInputs) {
7215
7373
  for (const asset of assets) {
7216
7374
  if (asset.assetId !== assetId) continue;
7217
- changeInputs.push(chunkFM263GKH_cjs.AssetInput.create(inputIndex, asset.amount));
7375
+ changeInputs.push(chunkD5DLGVN4_cjs.AssetInput.create(inputIndex, asset.amount));
7218
7376
  }
7219
7377
  }
7220
7378
  groups.push(
7221
- chunkFM263GKH_cjs.AssetGroup.create(
7222
- chunkFM263GKH_cjs.AssetId.fromString(assetId),
7379
+ chunkD5DLGVN4_cjs.AssetGroup.create(
7380
+ chunkD5DLGVN4_cjs.AssetId.fromString(assetId),
7223
7381
  null,
7224
7382
  changeInputs,
7225
- [chunkFM263GKH_cjs.AssetOutput.create(0, amount)],
7383
+ [chunkD5DLGVN4_cjs.AssetOutput.create(0, amount)],
7226
7384
  []
7227
7385
  )
7228
7386
  );
7229
7387
  }
7230
7388
  }
7231
7389
  const address = await this.wallet.getAddress();
7232
- const outputAddress = chunk5J5PDZRR_cjs.ArkAddress.decode(address);
7390
+ const outputAddress = chunkKJ5E646Y_cjs.ArkAddress.decode(address);
7233
7391
  const outputs = [
7234
7392
  {
7235
7393
  script: outputAddress.pkScript,
7236
7394
  amount: BigInt(totalBtcSelected)
7237
7395
  },
7238
- Extension.create([chunkFM263GKH_cjs.Packet.create(groups)]).txOut()
7396
+ Extension.create([chunkD5DLGVN4_cjs.Packet.create(groups)]).txOut()
7239
7397
  ];
7240
7398
  const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(
7241
7399
  coinSelection.inputs,
@@ -7243,7 +7401,7 @@ var AssetManager = class extends ReadonlyAssetManager {
7243
7401
  );
7244
7402
  return {
7245
7403
  arkTxId: arkTxid,
7246
- assetId: chunkFM263GKH_cjs.AssetId.create(arkTxid, 0).toString()
7404
+ assetId: chunkD5DLGVN4_cjs.AssetId.create(arkTxid, 0).toString()
7247
7405
  };
7248
7406
  }
7249
7407
  /**
@@ -7315,16 +7473,16 @@ var AssetManager = class extends ReadonlyAssetManager {
7315
7473
  for (const [inputIndex, assets] of assetInputs) {
7316
7474
  for (const asset of assets) {
7317
7475
  if (asset.assetId !== params.assetId) continue;
7318
- reissueInputs.push(chunkFM263GKH_cjs.AssetInput.create(inputIndex, asset.amount));
7476
+ reissueInputs.push(chunkD5DLGVN4_cjs.AssetInput.create(inputIndex, asset.amount));
7319
7477
  }
7320
7478
  }
7321
7479
  const totalAssetAmount = assetToReissueAmount + params.amount;
7322
- const reissueAssetIdObj = chunkFM263GKH_cjs.AssetId.fromString(params.assetId);
7323
- const reissueAssetGroup = chunkFM263GKH_cjs.AssetGroup.create(
7480
+ const reissueAssetIdObj = chunkD5DLGVN4_cjs.AssetId.fromString(params.assetId);
7481
+ const reissueAssetGroup = chunkD5DLGVN4_cjs.AssetGroup.create(
7324
7482
  reissueAssetIdObj,
7325
7483
  null,
7326
7484
  reissueInputs,
7327
- [chunkFM263GKH_cjs.AssetOutput.create(0, totalAssetAmount)],
7485
+ [chunkD5DLGVN4_cjs.AssetOutput.create(0, totalAssetAmount)],
7328
7486
  []
7329
7487
  );
7330
7488
  const groups = [reissueAssetGroup];
@@ -7333,27 +7491,27 @@ var AssetManager = class extends ReadonlyAssetManager {
7333
7491
  for (const [inputIndex, assets] of assetInputs) {
7334
7492
  for (const asset of assets) {
7335
7493
  if (asset.assetId !== assetId) continue;
7336
- changeInputs.push(chunkFM263GKH_cjs.AssetInput.create(inputIndex, asset.amount));
7494
+ changeInputs.push(chunkD5DLGVN4_cjs.AssetInput.create(inputIndex, asset.amount));
7337
7495
  }
7338
7496
  }
7339
7497
  groups.push(
7340
- chunkFM263GKH_cjs.AssetGroup.create(
7341
- chunkFM263GKH_cjs.AssetId.fromString(assetId),
7498
+ chunkD5DLGVN4_cjs.AssetGroup.create(
7499
+ chunkD5DLGVN4_cjs.AssetId.fromString(assetId),
7342
7500
  null,
7343
7501
  changeInputs,
7344
- [chunkFM263GKH_cjs.AssetOutput.create(0, amount)],
7502
+ [chunkD5DLGVN4_cjs.AssetOutput.create(0, amount)],
7345
7503
  []
7346
7504
  )
7347
7505
  );
7348
7506
  }
7349
7507
  const address = await this.wallet.getAddress();
7350
- const outputAddress = chunk5J5PDZRR_cjs.ArkAddress.decode(address);
7508
+ const outputAddress = chunkKJ5E646Y_cjs.ArkAddress.decode(address);
7351
7509
  const outputs = [
7352
7510
  {
7353
7511
  script: outputAddress.pkScript,
7354
7512
  amount: BigInt(totalBtcSelected)
7355
7513
  },
7356
- Extension.create([chunkFM263GKH_cjs.Packet.create(groups)]).txOut()
7514
+ Extension.create([chunkD5DLGVN4_cjs.Packet.create(groups)]).txOut()
7357
7515
  ];
7358
7516
  const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
7359
7517
  return arkTxid;
@@ -7420,27 +7578,27 @@ var AssetManager = class extends ReadonlyAssetManager {
7420
7578
  for (const [inputIndex, assets] of assetInputs) {
7421
7579
  for (const asset of assets) {
7422
7580
  if (asset.assetId !== assetId) continue;
7423
- changeInputs.push(chunkFM263GKH_cjs.AssetInput.create(inputIndex, asset.amount));
7581
+ changeInputs.push(chunkD5DLGVN4_cjs.AssetInput.create(inputIndex, asset.amount));
7424
7582
  }
7425
7583
  }
7426
7584
  groups.push(
7427
- chunkFM263GKH_cjs.AssetGroup.create(
7428
- chunkFM263GKH_cjs.AssetId.fromString(assetId),
7585
+ chunkD5DLGVN4_cjs.AssetGroup.create(
7586
+ chunkD5DLGVN4_cjs.AssetId.fromString(assetId),
7429
7587
  null,
7430
7588
  changeInputs,
7431
- amount > 0n ? [chunkFM263GKH_cjs.AssetOutput.create(0, amount)] : [],
7589
+ amount > 0n ? [chunkD5DLGVN4_cjs.AssetOutput.create(0, amount)] : [],
7432
7590
  []
7433
7591
  )
7434
7592
  );
7435
7593
  }
7436
7594
  const address = await this.wallet.getAddress();
7437
- const outputAddress = chunk5J5PDZRR_cjs.ArkAddress.decode(address);
7595
+ const outputAddress = chunkKJ5E646Y_cjs.ArkAddress.decode(address);
7438
7596
  const outputs = [
7439
7597
  {
7440
7598
  script: outputAddress.pkScript,
7441
7599
  amount: BigInt(totalBtcSelected)
7442
7600
  },
7443
- Extension.create([chunkFM263GKH_cjs.Packet.create(groups)]).txOut()
7601
+ Extension.create([chunkD5DLGVN4_cjs.Packet.create(groups)]).txOut()
7444
7602
  ];
7445
7603
  const { arkTxid } = await this.wallet.buildAndSubmitOffchainTx(selectedCoins, outputs);
7446
7604
  return arkTxid;
@@ -7465,7 +7623,7 @@ function castMetadata(metadata) {
7465
7623
  } else {
7466
7624
  throw new Error("Invalid metadata value type");
7467
7625
  }
7468
- md.push(chunkFM263GKH_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
7626
+ md.push(chunkD5DLGVN4_cjs.Metadata.create(textEncoder.encode(key), valueBytes));
7469
7627
  }
7470
7628
  return md;
7471
7629
  }
@@ -7486,10 +7644,10 @@ var DelegateManagerImpl = class {
7486
7644
  if (vtxos.length === 0) {
7487
7645
  return { delegated: [], failed: [] };
7488
7646
  }
7489
- const destinationScript = chunk5J5PDZRR_cjs.ArkAddress.decode(destination).pkScript;
7647
+ const destinationScript = chunkKJ5E646Y_cjs.ArkAddress.decode(destination).pkScript;
7490
7648
  const arkInfo = await this.arkInfoProvider.getInfo();
7491
7649
  const delegateInfo = await this.delegateProvider.getDelegateInfo();
7492
- const eligible = vtxos.map(chunk5J5PDZRR_cjs.normalizeVtxo).filter(
7650
+ const eligible = vtxos.map(chunkKJ5E646Y_cjs.normalizeVtxo).filter(
7493
7651
  (v) => isAnnotated(v) && findDelegateTapLeaf(v, delegateInfo.pubkey) !== void 0
7494
7652
  );
7495
7653
  if (eligible.length === 0) {
@@ -7518,11 +7676,11 @@ var DelegateManagerImpl = class {
7518
7676
  const groupByExpiry = /* @__PURE__ */ new Map();
7519
7677
  let recoverableVtxos = [];
7520
7678
  for (const vtxo of eligible) {
7521
- if (chunk5J5PDZRR_cjs.canRecoverOnchain(vtxo, now)) {
7679
+ if (chunkKJ5E646Y_cjs.canRecoverOnchain(vtxo, now)) {
7522
7680
  recoverableVtxos.push(vtxo);
7523
7681
  continue;
7524
7682
  }
7525
- const expiry = chunk5J5PDZRR_cjs.toBatchExpiry(vtxo);
7683
+ const expiry = chunkKJ5E646Y_cjs.toBatchExpiry(vtxo);
7526
7684
  if (!expiry) continue;
7527
7685
  const dayKey = getDayTimestamp(expiry);
7528
7686
  groupByExpiry.set(dayKey, [...groupByExpiry.get(dayKey) ?? [], vtxo]);
@@ -7587,16 +7745,11 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
7587
7745
  }
7588
7746
  if (!delegateAt) {
7589
7747
  const now = { timestamp: /* @__PURE__ */ new Date() };
7590
- const expiryTimestamp = vtxos.filter((coin) => !chunk5J5PDZRR_cjs.canRecoverOnchain(coin, now) && chunk5J5PDZRR_cjs.toBatchExpiry(coin)).reduce((min, coin) => Math.min(min, chunk5J5PDZRR_cjs.toBatchExpiry(coin)), Number.MAX_SAFE_INTEGER);
7748
+ const expiryTimestamp = vtxos.filter((coin) => !chunkKJ5E646Y_cjs.canRecoverOnchain(coin, now) && chunkKJ5E646Y_cjs.toBatchExpiry(coin)).reduce((min, coin) => Math.min(min, chunkKJ5E646Y_cjs.toBatchExpiry(coin)), Number.MAX_SAFE_INTEGER);
7591
7749
  if (!expiryTimestamp || expiryTimestamp === Number.MAX_SAFE_INTEGER) {
7592
7750
  delegateAt = new Date(Date.now() + 1 * 60 * 1e3);
7593
7751
  } else {
7594
- const remainingTimeMs = expiryTimestamp - Date.now();
7595
- if (remainingTimeMs <= 0) {
7596
- delegateAt = new Date(Date.now() + 1 * 60 * 1e3);
7597
- } else {
7598
- delegateAt = new Date(expiryTimestamp - remainingTimeMs * 0.1);
7599
- }
7752
+ delegateAt = defaultDelegateAt(expiryTimestamp, arkInfo.sessionDuration);
7600
7753
  }
7601
7754
  }
7602
7755
  const { fees, dust, forfeitAddress, network } = arkInfo;
@@ -7616,7 +7769,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
7616
7769
  let amount = 0n;
7617
7770
  for (const coin of vtxos) {
7618
7771
  const inputFee = estimator.evalOffchainInput({
7619
- ...chunk5J5PDZRR_cjs.toOffchainInputFeeParams(coin),
7772
+ ...chunkKJ5E646Y_cjs.toOffchainInputFeeParams(coin),
7620
7773
  type: "vtxo"
7621
7774
  });
7622
7775
  if (inputFee.value >= coin.value) {
@@ -7630,7 +7783,7 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
7630
7783
  const delegateFee = BigInt(Number(fee));
7631
7784
  if (delegateFee > 0n) {
7632
7785
  outputs.push({
7633
- script: chunk5J5PDZRR_cjs.ArkAddress.decode(delegateAddress).pkScript,
7786
+ script: chunkKJ5E646Y_cjs.ArkAddress.decode(delegateAddress).pkScript,
7634
7787
  amount: delegateFee
7635
7788
  });
7636
7789
  }
@@ -7663,10 +7816,10 @@ async function delegate(identity, delegateProvider, arkInfo, delegateInfo, vtxos
7663
7816
  destinationScript
7664
7817
  );
7665
7818
  const forfeitOutputScript = btcSigner.OutScript.encode(
7666
- btcSigner.Address(chunk5J5PDZRR_cjs.getNetwork(network)).decode(forfeitAddress)
7819
+ btcSigner.Address(chunkKJ5E646Y_cjs.getNetwork(network)).decode(forfeitAddress)
7667
7820
  );
7668
7821
  const forfeits = await Promise.all(
7669
- vtxos.filter((v) => !chunk5J5PDZRR_cjs.canRecoverOnchain(v, { timestamp: /* @__PURE__ */ new Date() })).map(async (coin) => {
7822
+ vtxos.filter((v) => !chunkKJ5E646Y_cjs.canRecoverOnchain(v, { timestamp: /* @__PURE__ */ new Date() })).map(async (coin) => {
7670
7823
  const forfeit = await makeDelegateForfeitTx(
7671
7824
  coin,
7672
7825
  dust,
@@ -7691,7 +7844,7 @@ async function makeDelegateForfeitTx(input, connectorAmount, delegatePubkey, for
7691
7844
  index: input.vout,
7692
7845
  witnessUtxo: {
7693
7846
  amount: BigInt(input.value),
7694
- script: chunk5J5PDZRR_cjs.VtxoScript.decode(input.tapTree).pkScript
7847
+ script: chunkKJ5E646Y_cjs.VtxoScript.decode(input.tapTree).pkScript
7695
7848
  },
7696
7849
  sighashType: btcSigner.SigHash.ALL_ANYONECANPAY,
7697
7850
  tapLeafScript: [delegateTapLeaf]
@@ -7749,13 +7902,21 @@ async function makeSignedDelegateIntent(identity, coins, outputs, onchainOutputs
7749
7902
  expire_at: 0,
7750
7903
  cosigners_public_keys: cosignerPubKeys
7751
7904
  };
7752
- const proof = chunk5J5PDZRR_cjs.Intent.create(message, coins, outputs);
7905
+ const proof = chunkKJ5E646Y_cjs.Intent.create(message, coins, outputs);
7753
7906
  const signedProof = await identity.sign(proof);
7754
7907
  return {
7755
7908
  proof: base.base64.encode(signedProof.toPSBT()),
7756
7909
  message
7757
7910
  };
7758
7911
  }
7912
+ function defaultDelegateAt(expiryTimestamp, sessionDurationSeconds, now = Date.now()) {
7913
+ const remainingTimeMs = expiryTimestamp - now;
7914
+ if (remainingTimeMs <= 0) return new Date(now + 6e4);
7915
+ const sessionLeadMs = Number(sessionDurationSeconds * 1000n);
7916
+ const leadTimeMs = Math.max(remainingTimeMs * 0.1, sessionLeadMs);
7917
+ const delegateAt = expiryTimestamp - leadTimeMs;
7918
+ return new Date(delegateAt > now ? delegateAt : now + 2e3);
7919
+ }
7759
7920
  function findDestinationOutputIndex(outputs, destinationScript) {
7760
7921
  return outputs.findIndex((o) => o.script && utils_js.equalBytes(o.script, destinationScript));
7761
7922
  }
@@ -7767,10 +7928,10 @@ function getDayTimestamp(timestamp) {
7767
7928
  function findDelegateTapLeaf(vtxo, delegatePubkey) {
7768
7929
  if (!vtxo.tapTree) return void 0;
7769
7930
  const pk = delegatePubkey.length === 66 ? delegatePubkey.slice(2) : delegatePubkey;
7770
- const vtxoScript = chunk5J5PDZRR_cjs.VtxoScript.decode(vtxo.tapTree);
7931
+ const vtxoScript = chunkKJ5E646Y_cjs.VtxoScript.decode(vtxo.tapTree);
7771
7932
  return vtxoScript.leaves.find((tapLeaf) => {
7772
- const arkTapscript = chunk5J5PDZRR_cjs.decodeTapscript(chunk5J5PDZRR_cjs.scriptFromTapLeafScript(tapLeaf));
7773
- if (!chunk5J5PDZRR_cjs.MultisigTapscript.is(arkTapscript)) return false;
7933
+ const arkTapscript = chunkKJ5E646Y_cjs.decodeTapscript(chunkKJ5E646Y_cjs.scriptFromTapLeafScript(tapLeaf));
7934
+ if (!chunkKJ5E646Y_cjs.MultisigTapscript.is(arkTapscript)) return false;
7774
7935
  return arkTapscript.params.pubkeys.map(base.hex.encode).includes(pk);
7775
7936
  });
7776
7937
  }
@@ -8051,7 +8212,7 @@ function createManagedConnection(dbName, version, initDatabase2) {
8051
8212
  };
8052
8213
  }
8053
8214
  function scriptFromArkAddress(address) {
8054
- return base.hex.encode(chunk5J5PDZRR_cjs.ArkAddress.decode(address).pkScript);
8215
+ return base.hex.encode(chunkKJ5E646Y_cjs.ArkAddress.decode(address).pkScript);
8055
8216
  }
8056
8217
 
8057
8218
  // src/repositories/indexedDB/schema.ts
@@ -8546,7 +8707,7 @@ function validateVtxosForScript(vtxos, script, context) {
8546
8707
  }
8547
8708
  async function getVtxosForContract(repo, contract) {
8548
8709
  const vtxos = repo.getVtxosForScript ? await repo.getVtxosForScript(contract.script) : filterVtxosForScript(await repo.getVtxos(contract.address), contract.script);
8549
- return vtxos.map(chunk5J5PDZRR_cjs.normalizeVtxo);
8710
+ return vtxos.map(chunkKJ5E646Y_cjs.normalizeVtxo);
8550
8711
  }
8551
8712
  async function saveVtxosForContract(repo, contract, vtxos) {
8552
8713
  if (repo.saveVtxosForScript) {
@@ -8688,7 +8849,7 @@ function decodeArkContract(encoded) {
8688
8849
  }
8689
8850
  function contractFromArkContract(encoded, options = {}) {
8690
8851
  const parsed = decodeArkContract(encoded);
8691
- const handler = chunkP6EXRY5L_cjs.contractHandlers.get(parsed.type);
8852
+ const handler = chunk2D7F5IU3_cjs.contractHandlers.get(parsed.type);
8692
8853
  if (!handler) {
8693
8854
  throw new Error(`No handler registered for contract type '${parsed.type}'`);
8694
8855
  }
@@ -8702,9 +8863,9 @@ function contractFromArkContract(encoded, options = {}) {
8702
8863
  metadata: options.metadata
8703
8864
  };
8704
8865
  }
8705
- function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunk5J5PDZRR_cjs.DEFAULT_NETWORK.hrp, options = {}) {
8866
+ function contractFromArkContractWithAddress(encoded, serverPubKey, addressPrefix = chunkKJ5E646Y_cjs.DEFAULT_NETWORK.hrp, options = {}) {
8706
8867
  const parsed = decodeArkContract(encoded);
8707
- const handler = chunkP6EXRY5L_cjs.contractHandlers.getOrThrow(parsed.type);
8868
+ const handler = chunk2D7F5IU3_cjs.contractHandlers.getOrThrow(parsed.type);
8708
8869
  const params = parsed.data;
8709
8870
  const vtxoScript = handler.createScript(params);
8710
8871
  return {
@@ -9001,9 +9162,9 @@ var ContractWatcher = class {
9001
9162
  this.connectionState = "connected";
9002
9163
  this.reconnectAttempts = 0;
9003
9164
  this.listenLoop().catch((e) => {
9004
- if (chunk5J5PDZRR_cjs.isEventSourceError(e)) {
9165
+ if (chunkKJ5E646Y_cjs.isEventSourceError(e)) {
9005
9166
  console.debug("ContractWatcher subscription disconnected; reconnecting");
9006
- } else if (!chunk5J5PDZRR_cjs.isEventSourceUnavailableError(e)) {
9167
+ } else if (!chunkKJ5E646Y_cjs.isEventSourceUnavailableError(e)) {
9007
9168
  console.error(e);
9008
9169
  }
9009
9170
  this.connectionState = "disconnected";
@@ -9015,7 +9176,7 @@ var ContractWatcher = class {
9015
9176
  this.scheduleReconnect();
9016
9177
  });
9017
9178
  } catch (error) {
9018
- if (!chunk5J5PDZRR_cjs.isEventSourceUnavailableError(error)) {
9179
+ if (!chunkKJ5E646Y_cjs.isEventSourceUnavailableError(error)) {
9019
9180
  console.error("ContractWatcher connection failed:", error);
9020
9181
  }
9021
9182
  this.connectionState = "disconnected";
@@ -9041,7 +9202,7 @@ var ContractWatcher = class {
9041
9202
  * slower; what it loses is push latency.
9042
9203
  */
9043
9204
  reportEventSourceUnavailable(error) {
9044
- if (!chunk5J5PDZRR_cjs.isEventSourceUnavailableError(error)) return false;
9205
+ if (!chunkKJ5E646Y_cjs.isEventSourceUnavailableError(error)) return false;
9045
9206
  if (!this.eventSourceReported) {
9046
9207
  this.eventSourceReported = true;
9047
9208
  console.warn(
@@ -9113,7 +9274,7 @@ var ContractWatcher = class {
9113
9274
  const now = Date.now();
9114
9275
  let current;
9115
9276
  try {
9116
- current = await chunk5J5PDZRR_cjs.getAllNormalizedVtxos(this.config.indexerProvider, scripts, {
9277
+ current = await chunkKJ5E646Y_cjs.getAllNormalizedVtxos(this.config.indexerProvider, scripts, {
9117
9278
  spendableOnly: true
9118
9279
  });
9119
9280
  } catch (error) {
@@ -9166,13 +9327,14 @@ var ContractWatcher = class {
9166
9327
  try {
9167
9328
  const vtxosMap = await this.getContractVtxos({
9168
9329
  contractScripts,
9169
- includeSpent: false
9170
- // only spendable ones!
9330
+ includeSpent: true
9171
9331
  });
9172
9332
  for (const contractScript of contractScripts) {
9173
9333
  const state = this.contracts.get(contractScript);
9174
9334
  if (!state) continue;
9175
- const currentVtxos = vtxosMap.get(contractScript) || [];
9335
+ const known = vtxosMap.get(contractScript) || [];
9336
+ const knownByKey = new Map(known.map((v) => [`${v.txid}:${v.vout}`, v]));
9337
+ const currentVtxos = known.filter((v) => !v.isSpent);
9176
9338
  const currentKeys = new Set(currentVtxos.map((v) => `${v.txid}:${v.vout}`));
9177
9339
  const newVtxos = [];
9178
9340
  for (const vtxo of currentVtxos) {
@@ -9185,7 +9347,7 @@ var ContractWatcher = class {
9185
9347
  const spentVtxos = [];
9186
9348
  for (const [key, vtxo] of state.lastKnownVtxos) {
9187
9349
  if (!currentKeys.has(key)) {
9188
- spentVtxos.push(vtxo);
9350
+ spentVtxos.push(knownByKey.get(key) ?? vtxo);
9189
9351
  state.lastKnownVtxos.delete(key);
9190
9352
  }
9191
9353
  }
@@ -9321,14 +9483,14 @@ var ContractWatcher = class {
9321
9483
  const timestamp = Date.now();
9322
9484
  if (update.newVtxos?.length) {
9323
9485
  this.processSubscriptionVtxos(
9324
- update.newVtxos.map(chunk5J5PDZRR_cjs.normalizeVtxo),
9486
+ update.newVtxos.map(chunkKJ5E646Y_cjs.normalizeVtxo),
9325
9487
  "vtxo_received",
9326
9488
  timestamp
9327
9489
  );
9328
9490
  }
9329
9491
  if (update.spentVtxos?.length) {
9330
9492
  this.processSubscriptionVtxos(
9331
- update.spentVtxos.map(chunk5J5PDZRR_cjs.normalizeVtxo),
9493
+ update.spentVtxos.map(chunkKJ5E646Y_cjs.normalizeVtxo),
9332
9494
  "vtxo_spent",
9333
9495
  timestamp
9334
9496
  );
@@ -9356,8 +9518,8 @@ var ContractWatcher = class {
9356
9518
  continue;
9357
9519
  }
9358
9520
  if (target === byWatchedScript && eventType === "vtxo_received") {
9359
- const n = chunk5J5PDZRR_cjs.normalizeVtxo(vtxo);
9360
- if (chunk5J5PDZRR_cjs.hasTerminalSpend(n) || n.isSwept || chunk5J5PDZRR_cjs.isPastExpiry(n, now)) continue;
9521
+ const n = chunkKJ5E646Y_cjs.normalizeVtxo(vtxo);
9522
+ if (chunkKJ5E646Y_cjs.hasTerminalSpend(n) || n.isSwept || chunkKJ5E646Y_cjs.isPastExpiry(n, now)) continue;
9361
9523
  }
9362
9524
  let bucket = target.get(vtxo.script);
9363
9525
  if (!bucket) {
@@ -9456,7 +9618,7 @@ var NON_TERMINAL_INTENT_STATES = ALL_INTENT_STATES.filter(
9456
9618
  (s) => !isTerminalIntentState(s)
9457
9619
  );
9458
9620
  function isConsumed(vtxo) {
9459
- return vtxo !== void 0 && chunk5J5PDZRR_cjs.hasTerminalSpend(vtxo);
9621
+ return vtxo !== void 0 && chunkKJ5E646Y_cjs.hasTerminalSpend(vtxo);
9460
9622
  }
9461
9623
  async function classifyIntent(intent, vtxosByOutpoint, now) {
9462
9624
  if (isTerminalIntentState(intent.state)) return void 0;
@@ -9499,7 +9661,7 @@ async function reconcileIntents(deps) {
9499
9661
  let vtxosByOutpoint = /* @__PURE__ */ new Map();
9500
9662
  if (outpoints.length > 0) {
9501
9663
  try {
9502
- const { vtxos } = await chunk5J5PDZRR_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
9664
+ const { vtxos } = await chunkKJ5E646Y_cjs.getNormalizedVtxos(deps.indexerProvider, { outpoints });
9503
9665
  vtxosByOutpoint = new Map(vtxos.map((v) => [outpointKey(v), v]));
9504
9666
  } catch (e) {
9505
9667
  console.error("reconcileIntents: failed to fetch input VTXO state", e);
@@ -9579,6 +9741,7 @@ var ContractManager = class _ContractManager {
9579
9741
  syncDegradedReason;
9580
9742
  /** Epoch-ms of the last successful provider sync, if any. */
9581
9743
  lastSyncedAt;
9744
+ syncedAtByScript = /* @__PURE__ */ new Map();
9582
9745
  /** Last chain tip read, with the epoch-ms it was read at. @see currentChainTip */
9583
9746
  chainTipCache;
9584
9747
  /** In-flight chain tip read, so concurrent cache misses share one. */
@@ -9632,6 +9795,10 @@ var ContractManager = class _ContractManager {
9632
9795
  lastSyncedAt: this.lastSyncedAt
9633
9796
  };
9634
9797
  }
9798
+ /** @see ContractManagerConfig.vtxoSyncMaxAgeMs — for factory-built managers. */
9799
+ setVtxoSyncMaxAge(maxAgeMs) {
9800
+ this.config.vtxoSyncMaxAgeMs = maxAgeMs;
9801
+ }
9635
9802
  markSyncOnline() {
9636
9803
  this.lastSyncedAt = Date.now();
9637
9804
  this.syncDegradedReason = this.annotationDegradedReason();
@@ -9673,7 +9840,7 @@ var ContractManager = class _ContractManager {
9673
9840
  await this.reconcileWatched();
9674
9841
  this.markSyncOnline();
9675
9842
  } catch (err) {
9676
- if (!chunk5J5PDZRR_cjs.isRetryableProviderError(err)) throw err;
9843
+ if (!chunkKJ5E646Y_cjs.isRetryableProviderError(err)) throw err;
9677
9844
  this.markSyncDegraded(err);
9678
9845
  }
9679
9846
  this.initialized = true;
@@ -9805,7 +9972,7 @@ var ContractManager = class _ContractManager {
9805
9972
  const from = Math.max(0, watermark - lookAhead.size);
9806
9973
  const to = watermark + lookAhead.size;
9807
9974
  const deps = lookAhead.candidateDeps();
9808
- const handlers = chunkP6EXRY5L_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkP6EXRY5L_cjs.contractHandlers.get(t)).filter(hasCandidates);
9975
+ const handlers = chunk2D7F5IU3_cjs.contractHandlers.getRegisteredTypes().map((t) => chunk2D7F5IU3_cjs.contractHandlers.get(t)).filter(hasCandidates);
9809
9976
  const band = /* @__PURE__ */ new Map();
9810
9977
  for (let index = from; index <= to; index++) {
9811
9978
  const descriptor = lookAhead.materialize(index);
@@ -9816,7 +9983,7 @@ var ContractManager = class _ContractManager {
9816
9983
  index,
9817
9984
  params: {
9818
9985
  ...candidate,
9819
- ...chunkP6EXRY5L_cjs.speculativeReceiveMetadata(descriptor)
9986
+ ...chunk2D7F5IU3_cjs.speculativeReceiveMetadata(descriptor)
9820
9987
  }
9821
9988
  });
9822
9989
  }
@@ -9878,7 +10045,7 @@ var ContractManager = class _ContractManager {
9878
10045
  });
9879
10046
  for (const entry of pending) entry.catchUpPending = false;
9880
10047
  } catch (err) {
9881
- if (!chunk5J5PDZRR_cjs.isRetryableProviderError(err)) throw err;
10048
+ if (!chunkKJ5E646Y_cjs.isRetryableProviderError(err)) throw err;
9882
10049
  this.markSyncDegraded(err);
9883
10050
  }
9884
10051
  }
@@ -9928,13 +10095,48 @@ var ContractManager = class _ContractManager {
9928
10095
  await this.fetchContractVxosFromIndexer([contract]);
9929
10096
  this.markSyncOnline();
9930
10097
  } catch (err) {
9931
- if (!chunk5J5PDZRR_cjs.isRetryableProviderError(err)) throw err;
10098
+ if (!chunkKJ5E646Y_cjs.isRetryableProviderError(err)) throw err;
9932
10099
  this.markSyncDegraded(err);
9933
10100
  }
9934
10101
  await this.watcher.addContract(contract);
9935
10102
  }
9936
10103
  return contract;
9937
10104
  }
10105
+ /**
10106
+ * `createContract`'s step order, fetch batched: persist all, hydrate once,
10107
+ * then watch. Hydrating first keeps it equivalent — the watcher seeds from
10108
+ * the repository, so an unhydrated row reads as all-new. A part-way failure
10109
+ * still watches what it wrote; a retry reports those rows as existing.
10110
+ */
10111
+ async createContracts(paramsList) {
10112
+ if (paramsList.length === 0) return [];
10113
+ return this.watcher.withCoalescedSubscription(async () => {
10114
+ const upserted = [];
10115
+ try {
10116
+ for (const params of paramsList) upserted.push(await this.upsertContract(params));
10117
+ } catch (err) {
10118
+ for (const u of upserted) {
10119
+ if (!u.persisted) continue;
10120
+ await this.watcher.addContract(u.contract).catch(
10121
+ (e) => console.error(`ContractManager: ${u.contract.script} left dark`, e)
10122
+ );
10123
+ }
10124
+ throw err;
10125
+ }
10126
+ const fresh = upserted.filter((u) => u.persisted).map((u) => u.contract);
10127
+ if (fresh.length > 0) {
10128
+ try {
10129
+ await this.fetchContractVxosFromIndexer(fresh);
10130
+ this.markSyncOnline();
10131
+ } catch (err) {
10132
+ if (!chunkKJ5E646Y_cjs.isRetryableProviderError(err)) throw err;
10133
+ this.markSyncDegraded(err);
10134
+ }
10135
+ for (const contract of fresh) await this.watcher.addContract(contract);
10136
+ }
10137
+ return upserted.map((u) => u.contract);
10138
+ });
10139
+ }
9938
10140
  /**
9939
10141
  * Lightweight variant of {@link createContract} for batch discovery
9940
10142
  * paths (currently: {@link scanContracts}). Validates, dedupes, persists,
@@ -9965,7 +10167,7 @@ var ContractManager = class _ContractManager {
9965
10167
  return result;
9966
10168
  }
9967
10169
  async upsertContractRow(params) {
9968
- const handler = chunkP6EXRY5L_cjs.contractHandlers.get(params.type);
10170
+ const handler = chunk2D7F5IU3_cjs.contractHandlers.get(params.type);
9969
10171
  if (!handler) {
9970
10172
  throw new Error(`No handler registered for contract type '${params.type}'`);
9971
10173
  }
@@ -10065,7 +10267,7 @@ var ContractManager = class _ContractManager {
10065
10267
  `scanContracts: batchSize must be a positive integer (got ${String(opts.batchSize)})`
10066
10268
  );
10067
10269
  }
10068
- const registered = chunkP6EXRY5L_cjs.contractHandlers.getRegisteredTypes().map((t) => chunkP6EXRY5L_cjs.contractHandlers.get(t)).filter(isDiscoverable);
10270
+ const registered = chunk2D7F5IU3_cjs.contractHandlers.getRegisteredTypes().map((t) => chunk2D7F5IU3_cjs.contractHandlers.get(t)).filter(isDiscoverable);
10069
10271
  const discoverables = [
10070
10272
  ...registered.filter((h) => h.type === "boarding"),
10071
10273
  ...registered.filter((h) => h.type !== "boarding")
@@ -10196,12 +10398,16 @@ var ContractManager = class _ContractManager {
10196
10398
  }
10197
10399
  async getContractsWithVtxos(filter, pageSize) {
10198
10400
  const contracts = await this.getContracts(filter);
10199
- try {
10200
- await this.syncContracts({ contracts, pageSize });
10201
- this.markSyncOnline();
10202
- } catch (err) {
10203
- if (!chunk5J5PDZRR_cjs.isRetryableProviderError(err)) throw err;
10204
- this.markSyncDegraded(err);
10401
+ if (this.syncedWithin(contracts, this.config.vtxoSyncMaxAgeMs ?? 0)) {
10402
+ await this.demoteFundedAwaitingContracts(contracts);
10403
+ } else {
10404
+ try {
10405
+ await this.syncContracts({ contracts, pageSize });
10406
+ this.markSyncOnline();
10407
+ } catch (err) {
10408
+ if (!chunkKJ5E646Y_cjs.isRetryableProviderError(err)) throw err;
10409
+ this.markSyncDegraded(err);
10410
+ }
10205
10411
  }
10206
10412
  const vtxos = await this.getVtxosForContracts(contracts);
10207
10413
  return contracts.map((contract) => ({
@@ -10221,7 +10427,7 @@ var ContractManager = class _ContractManager {
10221
10427
  }
10222
10428
  const tapscriptCache = tapscripts ?? /* @__PURE__ */ new Map();
10223
10429
  return vtxos.map(
10224
- (vtxo) => extendVirtualCoinForContract(chunk5J5PDZRR_cjs.normalizeVtxo(vtxo), byScript, tapscriptCache)
10430
+ (vtxo) => extendVirtualCoinForContract(chunkKJ5E646Y_cjs.normalizeVtxo(vtxo), byScript, tapscriptCache)
10225
10431
  );
10226
10432
  }
10227
10433
  /** @inheritdoc */
@@ -10265,14 +10471,14 @@ var ContractManager = class _ContractManager {
10265
10471
  const byScript = new Map(contracts.map((contract) => [contract.script, contract]));
10266
10472
  const asking = vtxos.filter((vtxo) => {
10267
10473
  const contract = byScript.get(vtxo.script);
10268
- return contract !== void 0 && chunkP6EXRY5L_cjs.contractHandlers.get(contract.type)?.assertSpendableNow !== void 0;
10474
+ return contract !== void 0 && chunk2D7F5IU3_cjs.contractHandlers.get(contract.type)?.assertSpendableNow !== void 0;
10269
10475
  });
10270
10476
  if (asking.length === 0) return refused;
10271
10477
  const tip = await this.currentChainTip();
10272
10478
  const walletKey = await walletPubKey?.();
10273
10479
  for (const vtxo of asking) {
10274
10480
  const contract = byScript.get(vtxo.script);
10275
- const handler = chunkP6EXRY5L_cjs.contractHandlers.get(contract.type);
10481
+ const handler = chunk2D7F5IU3_cjs.contractHandlers.get(contract.type);
10276
10482
  if (!handler?.assertSpendableNow) continue;
10277
10483
  const context = {
10278
10484
  collaborative: true,
@@ -10287,7 +10493,7 @@ var ContractManager = class _ContractManager {
10287
10493
  // the next handler to answer a CSV question would meet a
10288
10494
  // TypeError instead of a `false`. Carry the coin only when it
10289
10495
  // really is one.
10290
- vtxo: chunk5J5PDZRR_cjs.isVirtualCoin(vtxo) && "status" in vtxo ? vtxo : void 0
10496
+ vtxo: chunkKJ5E646Y_cjs.isVirtualCoin(vtxo) && "status" in vtxo ? vtxo : void 0
10291
10497
  };
10292
10498
  try {
10293
10499
  await handler.assertSpendableNow(
@@ -10443,7 +10649,7 @@ var ContractManager = class _ContractManager {
10443
10649
  const { contractScript, collaborative = true, walletPubKey, vtxo } = options;
10444
10650
  const [contract] = await this.getContracts({ script: contractScript });
10445
10651
  if (!contract) return [];
10446
- const handler = chunkP6EXRY5L_cjs.contractHandlers.get(contract.type);
10652
+ const handler = chunk2D7F5IU3_cjs.contractHandlers.get(contract.type);
10447
10653
  if (!handler) return [];
10448
10654
  const script = handler.createScript(contract.params);
10449
10655
  const tip = await this.currentChainTip();
@@ -10471,7 +10677,7 @@ var ContractManager = class _ContractManager {
10471
10677
  const { contractScript, collaborative = true, walletPubKey } = options;
10472
10678
  const [contract] = await this.getContracts({ script: contractScript });
10473
10679
  if (!contract) return [];
10474
- const handler = chunkP6EXRY5L_cjs.contractHandlers.get(contract.type);
10680
+ const handler = chunk2D7F5IU3_cjs.contractHandlers.get(contract.type);
10475
10681
  if (!handler) return [];
10476
10682
  const script = handler.createScript(contract.params);
10477
10683
  const context = {
@@ -10527,7 +10733,7 @@ var ContractManager = class _ContractManager {
10527
10733
  }
10528
10734
  async refreshOutpoints(outpoints) {
10529
10735
  if (outpoints.length === 0) return;
10530
- const { vtxos } = await chunk5J5PDZRR_cjs.getNormalizedVtxos(this.config.indexerProvider, {
10736
+ const { vtxos } = await chunkKJ5E646Y_cjs.getNormalizedVtxos(this.config.indexerProvider, {
10531
10737
  outpoints
10532
10738
  });
10533
10739
  if (vtxos.length === 0) return;
@@ -10616,13 +10822,14 @@ var ContractManager = class _ContractManager {
10616
10822
  }
10617
10823
  break;
10618
10824
  case "connection_reset":
10825
+ this.syncedAtByScript.clear();
10619
10826
  await this.scheduleLookAheadDrain();
10620
10827
  await this.reconcileWatched();
10621
10828
  this.markSyncOnline();
10622
10829
  break;
10623
10830
  }
10624
10831
  } catch (err) {
10625
- if (!chunk5J5PDZRR_cjs.isRetryableProviderError(err)) throw err;
10832
+ if (!chunkKJ5E646Y_cjs.isRetryableProviderError(err)) throw err;
10626
10833
  this.markSyncDegraded(err);
10627
10834
  }
10628
10835
  this.emitEvent(event);
@@ -10662,9 +10869,21 @@ var ContractManager = class _ContractManager {
10662
10869
  const cutoff = cursorCutoff(requestStartedAt);
10663
10870
  await advanceSyncCursor(this.config.walletRepository, cutoff);
10664
10871
  }
10872
+ if (options.window === void 0) {
10873
+ for (const contract of contracts) {
10874
+ this.syncedAtByScript.set(contract.script, requestStartedAt);
10875
+ }
10876
+ }
10665
10877
  await this.demoteFundedAwaitingContracts(contracts);
10666
10878
  return result;
10667
10879
  }
10880
+ syncedWithin(contracts, maxAgeMs) {
10881
+ if (maxAgeMs <= 0) return false;
10882
+ const floor = Date.now() - maxAgeMs;
10883
+ return contracts.every(
10884
+ (contract) => (this.syncedAtByScript.get(contract.script) ?? 0) >= floor
10885
+ );
10886
+ }
10668
10887
  /**
10669
10888
  * Demote every `awaiting-funds` contract in `contracts` that has been
10670
10889
  * funded — the automatic half of {@link ContractWatchState}.
@@ -10701,7 +10920,7 @@ var ContractManager = class _ContractManager {
10701
10920
  */
10702
10921
  async reconcilePendingFrontier(contracts) {
10703
10922
  const scriptToContract = new Map(contracts.map((c) => [c.script, c]));
10704
- const vtxos = await chunk5J5PDZRR_cjs.getAllNormalizedVtxos(
10923
+ const vtxos = await chunkKJ5E646Y_cjs.getAllNormalizedVtxos(
10705
10924
  this.config.indexerProvider,
10706
10925
  contracts.map((c) => c.script),
10707
10926
  { pendingOnly: true }
@@ -10784,7 +11003,7 @@ var ContractManager = class _ContractManager {
10784
11003
  }
10785
11004
  return result;
10786
11005
  }
10787
- async fetchContractVtxosBulk(contracts, pageSize = chunk5J5PDZRR_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
11006
+ async fetchContractVtxosBulk(contracts, pageSize = chunkKJ5E646Y_cjs.DEFAULT_PAGE_SIZE, syncWindow) {
10788
11007
  if (contracts.length === 0) {
10789
11008
  return { vtxosByScript: /* @__PURE__ */ new Map(), promoted: /* @__PURE__ */ new Map() };
10790
11009
  }
@@ -10800,7 +11019,7 @@ var ContractManager = class _ContractManager {
10800
11019
  before: syncWindow.before
10801
11020
  }
10802
11021
  } : {};
10803
- const vtxos = await chunk5J5PDZRR_cjs.getAllNormalizedVtxos(
11022
+ const vtxos = await chunkKJ5E646Y_cjs.getAllNormalizedVtxos(
10804
11023
  this.config.indexerProvider,
10805
11024
  contracts.map((c) => c.script),
10806
11025
  { ...windowOpts, pageSize }
@@ -10945,7 +11164,7 @@ var deserializeTapLeaf = (t) => {
10945
11164
  const s = base.hex.decode(t.s);
10946
11165
  return [cb, s];
10947
11166
  };
10948
- var deserializeVtxo = (o) => chunk5J5PDZRR_cjs.normalizeVtxo({
11167
+ var deserializeVtxo = (o) => chunkKJ5E646Y_cjs.normalizeVtxo({
10949
11168
  ...o,
10950
11169
  createdAt: new Date(o.createdAt),
10951
11170
  tapTree: base.hex.decode(o.tapTree),
@@ -11768,7 +11987,7 @@ var HDDescriptorProvider = class _HDDescriptorProvider {
11768
11987
  */
11769
11988
  materializeDescriptorAt(index) {
11770
11989
  const descriptor = this.identity.descriptor;
11771
- const network = chunkP6EXRY5L_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
11990
+ const network = chunk2D7F5IU3_cjs.isMainnetDescriptor(descriptor) ? descriptorsScure.networks.bitcoin : descriptorsScure.networks.testnet;
11772
11991
  const expansion = descriptorsScure.expand({ descriptor, network, index });
11773
11992
  const keyInfo = expansion.expansionMap?.["@0"];
11774
11993
  if (!keyInfo?.keyExpression) {
@@ -11916,7 +12135,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
11916
12135
  const provider = await resolveDescriptorProvider(config, setup.walletRepository);
11917
12136
  if (!provider) return void 0;
11918
12137
  const allowSilentFallback = (config.walletMode ?? "auto") === "auto";
11919
- const expectedContractType = setup.offchainTapscript instanceof chunkP6EXRY5L_cjs.DelegateVtxo.Script ? "delegate" : "default";
12138
+ const expectedContractType = setup.offchainTapscript instanceof chunk2D7F5IU3_cjs.DelegateVtxo.Script ? "delegate" : "default";
11920
12139
  const factoryOpts = {
11921
12140
  walletRepository: setup.walletRepository,
11922
12141
  contractRepository: setup.contractRepository,
@@ -12117,7 +12336,7 @@ var WalletReceiveRotator = class _WalletReceiveRotator {
12117
12336
  };
12118
12337
  function deriveLeafPubkey(descriptor) {
12119
12338
  try {
12120
- return chunkP6EXRY5L_cjs.deriveDescriptorLeafPubKey(descriptor);
12339
+ return chunk2D7F5IU3_cjs.deriveDescriptorLeafPubKey(descriptor);
12121
12340
  } catch (e) {
12122
12341
  throw new NonRangeableDescriptorError(
12123
12342
  "Cannot derive leaf pubkey: descriptor is not a materialized, parsable tr(...) shape.",
@@ -12129,7 +12348,7 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
12129
12348
  const pubKey = deriveLeafPubkey(descriptor);
12130
12349
  const tapscript = rebuildTapscript(current, pubKey);
12131
12350
  const serverPubKey = tapscript.options.serverPubKey;
12132
- const csvTimelock = chunk5J5PDZRR_cjs.timelockToSequence(tapscript.options.csvTimelock).toString();
12351
+ const csvTimelock = chunkKJ5E646Y_cjs.timelockToSequence(tapscript.options.csvTimelock).toString();
12133
12352
  const base$1 = {
12134
12353
  script: base.hex.encode(tapscript.pkScript),
12135
12354
  address: tapscript.address(hrp, serverPubKey).encode(),
@@ -12140,11 +12359,11 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
12140
12359
  // index-0 key. Without it, spends produce unsigned PSBTs that the
12141
12360
  // server rejects with `INVALID_PSBT_INPUT (5): missing tapscript spend sig`.
12142
12361
  metadata: {
12143
- ...tagSource && { source: chunkP6EXRY5L_cjs.WALLET_RECEIVE_SOURCE },
12362
+ ...tagSource && { source: chunk2D7F5IU3_cjs.WALLET_RECEIVE_SOURCE },
12144
12363
  signingDescriptor: descriptor
12145
12364
  }
12146
12365
  };
12147
- const params = tapscript instanceof chunkP6EXRY5L_cjs.DelegateVtxo.Script ? {
12366
+ const params = tapscript instanceof chunk2D7F5IU3_cjs.DelegateVtxo.Script ? {
12148
12367
  ...base$1,
12149
12368
  type: "delegate",
12150
12369
  params: {
@@ -12165,10 +12384,10 @@ function buildReceiveContract(current, descriptor, hrp, tagSource) {
12165
12384
  return { tapscript, params };
12166
12385
  }
12167
12386
  function rebuildTapscript(current, pubKey) {
12168
- if (current instanceof chunkP6EXRY5L_cjs.DelegateVtxo.Script) {
12169
- return new chunkP6EXRY5L_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
12387
+ if (current instanceof chunk2D7F5IU3_cjs.DelegateVtxo.Script) {
12388
+ return new chunk2D7F5IU3_cjs.DelegateVtxo.Script({ ...current.options, pubKey });
12170
12389
  }
12171
- return new chunkP6EXRY5L_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
12390
+ return new chunk2D7F5IU3_cjs.DefaultVtxo.Script({ ...current.options, pubKey });
12172
12391
  }
12173
12392
  async function pickActiveReceive(contractRepository, serverPubKey, expectedType) {
12174
12393
  const candidates = await contractRepository.getContracts({
@@ -12177,7 +12396,7 @@ async function pickActiveReceive(contractRepository, serverPubKey, expectedType)
12177
12396
  });
12178
12397
  const serverPubKeyHex = base.hex.encode(serverPubKey);
12179
12398
  const matching = candidates.filter(
12180
- (c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkP6EXRY5L_cjs.WALLET_RECEIVE_SOURCE
12399
+ (c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunk2D7F5IU3_cjs.WALLET_RECEIVE_SOURCE
12181
12400
  ).sort((a, b) => {
12182
12401
  if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
12183
12402
  return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
@@ -12233,7 +12452,7 @@ function computeOffchainBalance(vtxos, caps) {
12233
12452
  }
12234
12453
  };
12235
12454
  for (const vtxo of vtxos) {
12236
- if (chunk5J5PDZRR_cjs.hasTerminalSpend(vtxo)) continue;
12455
+ if (chunkKJ5E646Y_cjs.hasTerminalSpend(vtxo)) continue;
12237
12456
  addAssets(owned, vtxo);
12238
12457
  if (vtxo.isUnrolled) {
12239
12458
  unrolled += vtxo.value;
@@ -12243,11 +12462,11 @@ function computeOffchainBalance(vtxos, caps) {
12243
12462
  pendingRecovery += vtxo.value;
12244
12463
  continue;
12245
12464
  }
12246
- if (chunk5J5PDZRR_cjs.canRecoverOnchain(vtxo, now)) {
12465
+ if (chunkKJ5E646Y_cjs.canRecoverOnchain(vtxo, now)) {
12247
12466
  recoverable += vtxo.value;
12248
12467
  continue;
12249
12468
  }
12250
- if (!chunk5J5PDZRR_cjs.canSpendOffchain(vtxo, now)) continue;
12469
+ if (!chunkKJ5E646Y_cjs.canSpendOffchain(vtxo, now)) continue;
12251
12470
  if (vtxo.isPreconfirmed) {
12252
12471
  preconfirmed += vtxo.value;
12253
12472
  } else {
@@ -12417,12 +12636,12 @@ var InputSignerRouter = class {
12417
12636
  };
12418
12637
 
12419
12638
  // src/wallet/wallet.ts
12420
- var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl || chunk5J5PDZRR_cjs.DEFAULT_ARKADE_SERVER_URL;
12639
+ var getArkadeServerUrl = ({ arkServerUrl }) => arkServerUrl || chunkKJ5E646Y_cjs.DEFAULT_ARKADE_SERVER_URL;
12421
12640
  function intentProofJobs(coins) {
12422
12641
  if (coins.length === 0) return [];
12423
12642
  const coinJobs = coins.map((coin, i) => ({
12424
12643
  index: i + 1,
12425
- lookupScript: chunk5J5PDZRR_cjs.VtxoScript.decode(coin.tapTree).pkScript
12644
+ lookupScript: chunkKJ5E646Y_cjs.VtxoScript.decode(coin.tapTree).pkScript
12426
12645
  }));
12427
12646
  return [{ index: 0, lookupScript: coinJobs[0].lookupScript }, ...coinJobs];
12428
12647
  }
@@ -12454,7 +12673,7 @@ function dedupeTimelocks(timelocks) {
12454
12673
  const seen = /* @__PURE__ */ new Set();
12455
12674
  const deduped = [];
12456
12675
  for (const timelock of timelocks) {
12457
- const sequence = chunk5J5PDZRR_cjs.timelockToSequence(timelock).toString();
12676
+ const sequence = chunkKJ5E646Y_cjs.timelockToSequence(timelock).toString();
12458
12677
  if (seen.has(sequence)) continue;
12459
12678
  seen.add(sequence);
12460
12679
  deduped.push(timelock);
@@ -12471,7 +12690,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
12471
12690
  state: "active"
12472
12691
  });
12473
12692
  const newest = candidates.filter(
12474
- (c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunkP6EXRY5L_cjs.WALLET_RECEIVE_SOURCE
12693
+ (c) => c.params.serverPubKey === serverPubKeyHex && c.metadata?.source === chunk2D7F5IU3_cjs.WALLET_RECEIVE_SOURCE
12475
12694
  ).sort((a, b) => {
12476
12695
  if (b.createdAt !== a.createdAt) return b.createdAt - a.createdAt;
12477
12696
  return signingDescriptorIndex(b.metadata?.signingDescriptor) - signingDescriptorIndex(a.metadata?.signingDescriptor);
@@ -12479,7 +12698,7 @@ async function resolveBoardingBootTapscript(contractRepository, serverPubKey, ba
12479
12698
  if (!newest?.params.pubKey) return baseline;
12480
12699
  try {
12481
12700
  const pubKey = base.hex.decode(newest.params.pubKey);
12482
- return new chunkP6EXRY5L_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
12701
+ return new chunk2D7F5IU3_cjs.DefaultVtxo.Script({ ...baseline.options, pubKey });
12483
12702
  } catch (e) {
12484
12703
  console.warn("Skipping malformed boarding contract at boot", newest.script, e);
12485
12704
  return baseline;
@@ -12498,10 +12717,10 @@ function filterSnapshotVtxos(snapshot, filter, pendingSpendOutpoints) {
12498
12717
  if (vtxo.isUnrolled) {
12499
12718
  return !!f.withUnrolled;
12500
12719
  }
12501
- if (chunk5J5PDZRR_cjs.hasTerminalSpend(vtxo)) {
12720
+ if (chunkKJ5E646Y_cjs.hasTerminalSpend(vtxo)) {
12502
12721
  return false;
12503
12722
  }
12504
- if (!f.withRecoverable && chunk5J5PDZRR_cjs.canRecoverOnchain(vtxo, now)) {
12723
+ if (!f.withRecoverable && chunkKJ5E646Y_cjs.canRecoverOnchain(vtxo, now)) {
12505
12724
  return false;
12506
12725
  }
12507
12726
  return true;
@@ -12841,7 +13060,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
12841
13060
  */
12842
13061
  static async setupWalletConfig(config, pubKey) {
12843
13062
  const arkadeServerUrl = getArkadeServerUrl(config);
12844
- const arkProvider = config.arkProvider || new chunk5J5PDZRR_cjs.RestArkProvider(arkadeServerUrl);
13063
+ const arkProvider = config.arkProvider || new chunkKJ5E646Y_cjs.RestArkProvider(arkadeServerUrl);
12845
13064
  let indexerProvider = config.indexerProvider;
12846
13065
  if (!indexerProvider) {
12847
13066
  let indexerUrl = config.indexerUrl;
@@ -12858,7 +13077,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
12858
13077
  indexerUrl = arkadeServerUrl;
12859
13078
  }
12860
13079
  }
12861
- indexerProvider = new chunkFM263GKH_cjs.RestIndexerProvider(indexerUrl);
13080
+ indexerProvider = new chunkD5DLGVN4_cjs.RestIndexerProvider(indexerUrl);
12862
13081
  }
12863
13082
  const walletRepository = config.storage?.walletRepository ?? new IndexedDBWalletRepository();
12864
13083
  const contractRepository = config.storage?.contractRepository ?? new IndexedDBContractRepository();
@@ -12867,7 +13086,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
12867
13086
  source: serverInfoSource,
12868
13087
  lastOnlineAt: serverInfoLastOnlineAt
12869
13088
  } = await resolveArkInfo(arkProvider, walletRepository);
12870
- const network = chunk5J5PDZRR_cjs.getNetwork(info.network);
13089
+ const network = chunkKJ5E646Y_cjs.getNetwork(info.network);
12871
13090
  if ("descriptor" in config.identity) {
12872
13091
  const descriptor = config.identity.descriptor;
12873
13092
  const identityIsMainnet = !descriptor.includes("tpub");
@@ -12907,18 +13126,18 @@ var ReadonlyWallet = class _ReadonlyWallet {
12907
13126
  value: info.boardingExitDelay,
12908
13127
  type: info.boardingExitDelay < 512n ? "blocks" : "seconds"
12909
13128
  };
12910
- const serverPubKey = chunkP6EXRY5L_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
12911
- const delegatePubKey = config.delegateProvider ? await config.delegateProvider.getDelegateInfo().then((info2) => chunkP6EXRY5L_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0) : config.delegatorProvider ? await config.delegatorProvider.getDelegateInfo().then((info2) => chunkP6EXRY5L_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0) : void 0;
13129
+ const serverPubKey = chunk2D7F5IU3_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
13130
+ const delegatePubKey = config.delegateProvider ? await config.delegateProvider.getDelegateInfo().then((info2) => chunk2D7F5IU3_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0) : config.delegatorProvider ? await config.delegatorProvider.getDelegateInfo().then((info2) => chunk2D7F5IU3_cjs.toXOnly(base.hex.decode(info2.pubkey), "delegate key")).catch(() => void 0) : void 0;
12912
13131
  const offchainOptions = {
12913
13132
  pubKey,
12914
13133
  serverPubKey,
12915
13134
  csvTimelock: exitTimelock
12916
13135
  };
12917
- const offchainTapscript = !delegatePubKey ? new chunkP6EXRY5L_cjs.DefaultVtxo.Script(offchainOptions) : new chunkP6EXRY5L_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
12918
- const boardingTapscript = chunkP6EXRY5L_cjs.BoardingContractHandler.createScript({
13136
+ const offchainTapscript = !delegatePubKey ? new chunk2D7F5IU3_cjs.DefaultVtxo.Script(offchainOptions) : new chunk2D7F5IU3_cjs.DelegateVtxo.Script({ ...offchainOptions, delegatePubKey });
13137
+ const boardingTapscript = chunk2D7F5IU3_cjs.BoardingContractHandler.createScript({
12919
13138
  pubKey: base.hex.encode(pubKey),
12920
13139
  serverPubKey: base.hex.encode(serverPubKey),
12921
- csvTimelock: chunk5J5PDZRR_cjs.timelockToSequence(boardingTimelock).toString()
13140
+ csvTimelock: chunkKJ5E646Y_cjs.timelockToSequence(boardingTimelock).toString()
12922
13141
  });
12923
13142
  return {
12924
13143
  arkProvider,
@@ -13070,7 +13289,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
13070
13289
  const vtxos = filterSnapshotVtxos(snapshot, filter, this._pendingSpendOutpoints);
13071
13290
  const { gated, pendingRecovery } = this.spendabilityView(snapshot);
13072
13291
  const selectable = vtxos.filter(
13073
- (vtxo) => !gated.has(vtxo.script) && !pendingRecovery.has(`${vtxo.txid}:${vtxo.vout}`)
13292
+ (vtxo) => !isGatedVtxo(vtxo, gated) && !pendingRecovery.has(`${vtxo.txid}:${vtxo.vout}`)
13074
13293
  );
13075
13294
  const unlocked = await spendableVtxosExcludingLocked(selectable, this.intentRepository);
13076
13295
  logExcludedVtxos("getSpendableVtxos", vtxos, [
@@ -13084,7 +13303,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
13084
13303
  if (!filter?.withUnrolled) {
13085
13304
  logExcludedVtxos(
13086
13305
  "getSpendableVtxos",
13087
- snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !chunk5J5PDZRR_cjs.hasTerminalSpend(vtxo)),
13306
+ snapshot.flatMap((contract) => contract.vtxos).filter((vtxo) => vtxo.isUnrolled && !chunkKJ5E646Y_cjs.hasTerminalSpend(vtxo)),
13088
13307
  [() => UNROLLED_REASON]
13089
13308
  );
13090
13309
  }
@@ -13168,7 +13387,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
13168
13387
  */
13169
13388
  spendabilityView(snapshot) {
13170
13389
  return {
13171
- gated: gatedContracts(snapshot.map((_) => _.contract)),
13390
+ gated: gatedFrom(snapshot),
13172
13391
  pendingRecovery: this.selectPendingRecovery(snapshot)
13173
13392
  };
13174
13393
  }
@@ -13183,7 +13402,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
13183
13402
  return {
13184
13403
  now: { timestamp: /* @__PURE__ */ new Date() },
13185
13404
  isPendingRecovery: (vtxo) => pendingRecovery.has(`${vtxo.txid}:${vtxo.vout}`),
13186
- isGenericallySpendable: (vtxo) => !gated.has(vtxo.script),
13405
+ isGenericallySpendable: (vtxo) => !isGatedVtxo(vtxo, gated),
13187
13406
  isUnlocked: (vtxo) => unlocked.has(`${vtxo.txid}:${vtxo.vout}`)
13188
13407
  };
13189
13408
  }
@@ -13223,16 +13442,18 @@ var ReadonlyWallet = class _ReadonlyWallet {
13223
13442
  * Return wallet transaction history derived from Arkade state and boarding transactions.
13224
13443
  */
13225
13444
  async getTransactionHistory() {
13226
- const contractManager = await this.getContractManager();
13227
- const response = await contractManager.getContractsWithVtxos();
13228
- const allVtxos = response.flatMap((_) => _.vtxos);
13229
- const { boardingTxs, commitmentsToIgnore } = await this.getBoardingTxs();
13230
- const resolveTxCreatedAt = (txids) => chunk5J5PDZRR_cjs.fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
13445
+ const [snapshot, { boardingTxs, commitmentsToIgnore }] = await Promise.all([
13446
+ this.contractSnapshot(),
13447
+ this.getBoardingTxs()
13448
+ ]);
13449
+ const allVtxos = snapshot.flatMap((_) => _.vtxos);
13450
+ const resolveTxCreatedAt = (txids) => chunkKJ5E646Y_cjs.fetchVtxoCreatedAtByTxid(this.indexerProvider, txids);
13231
13451
  return buildTransactionHistory(
13232
13452
  allVtxos,
13233
13453
  boardingTxs,
13234
13454
  commitmentsToIgnore,
13235
- resolveTxCreatedAt
13455
+ resolveTxCreatedAt,
13456
+ gatedFrom(snapshot)
13236
13457
  );
13237
13458
  }
13238
13459
  /**
@@ -13321,7 +13542,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
13321
13542
  },
13322
13543
  isUnrolled: true,
13323
13544
  ...boardingFacts,
13324
- virtualStatus: chunk5J5PDZRR_cjs.toVirtualStatus(boardingFacts),
13545
+ virtualStatus: chunkKJ5E646Y_cjs.toVirtualStatus(boardingFacts),
13325
13546
  spentBy: "",
13326
13547
  createdAt: tx.status.confirmed ? new Date(tx.status.block_time * 1e3) : /* @__PURE__ */ new Date(0),
13327
13548
  script: scriptHex
@@ -13377,9 +13598,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
13377
13598
  async getBoardingTapscripts(allowedSigners) {
13378
13599
  const byScript = /* @__PURE__ */ new Map();
13379
13600
  const add = (s) => byScript.set(base.hex.encode(s.pkScript), s);
13380
- const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunkP6EXRY5L_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
13601
+ const boardingCsv = this.boardingTapscript.options.csvTimelock ?? chunk2D7F5IU3_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
13381
13602
  add(
13382
- new chunkP6EXRY5L_cjs.DefaultVtxo.Script({
13603
+ new chunk2D7F5IU3_cjs.DefaultVtxo.Script({
13383
13604
  pubKey: await this.identity.xOnlyPublicKey(),
13384
13605
  serverPubKey: this.boardingTapscript.options.serverPubKey,
13385
13606
  csvTimelock: boardingCsv
@@ -13394,7 +13615,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
13394
13615
  for (const c of boardingContracts) {
13395
13616
  if (!allowed.has(toXOnlySignerHex(c.params.serverPubKey))) continue;
13396
13617
  try {
13397
- add(chunkP6EXRY5L_cjs.BoardingContractHandler.createScript(c.params));
13618
+ add(chunk2D7F5IU3_cjs.BoardingContractHandler.createScript(c.params));
13398
13619
  } catch (e) {
13399
13620
  console.warn("Skipping malformed boarding contract", c.script, e);
13400
13621
  }
@@ -13432,7 +13653,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
13432
13653
  // Per-row CSV delay decoded from THIS tapscript's exit leaf —
13433
13654
  // not the wallet's current boarding timelock, which a signer
13434
13655
  // rotation may have changed.
13435
- csvTimelock: chunk5J5PDZRR_cjs.CSVMultisigTapscript.decode(base.hex.decode(tapscript.exitScript)).params.timelock,
13656
+ csvTimelock: chunkKJ5E646Y_cjs.CSVMultisigTapscript.decode(base.hex.decode(tapscript.exitScript)).params.timelock,
13436
13657
  coins: utxos
13437
13658
  });
13438
13659
  }
@@ -13565,7 +13786,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
13565
13786
  /** Fetch Arkade transaction ids that are still pending final settlement. */
13566
13787
  async fetchPendingTxs() {
13567
13788
  const scripts = await this.getWalletScripts();
13568
- const vtxos = await chunk5J5PDZRR_cjs.getAllNormalizedVtxos(this.indexerProvider, scripts);
13789
+ const vtxos = await chunkKJ5E646Y_cjs.getAllNormalizedVtxos(this.indexerProvider, scripts);
13569
13790
  return vtxos.filter(
13570
13791
  (vtxo) => (vtxo.isSpent || vtxo.isPreconfirmed && !vtxo.isSwept) && vtxo.arkTxId !== void 0
13571
13792
  ).map((_) => _.arkTxId);
@@ -13596,7 +13817,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
13596
13817
  });
13597
13818
  for (const contract of contracts) {
13598
13819
  if (map.has(contract.script)) continue;
13599
- const handler = chunkP6EXRY5L_cjs.contractHandlers.get(contract.type);
13820
+ const handler = chunk2D7F5IU3_cjs.contractHandlers.get(contract.type);
13600
13821
  if (handler) {
13601
13822
  const script = handler.createScript(contract.params);
13602
13823
  map.set(contract.script, script);
@@ -13708,7 +13929,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
13708
13929
  }
13709
13930
  });
13710
13931
  const baselinePubkey = await this.identity.xOnlyPublicKey();
13711
- const delegatePubKey = this.offchainTapscript instanceof chunkP6EXRY5L_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
13932
+ const delegatePubKey = this.offchainTapscript instanceof chunk2D7F5IU3_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
13712
13933
  const baselineSigners = [
13713
13934
  this.offchainTapscript.options.serverPubKey,
13714
13935
  ...[...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h))
@@ -13716,8 +13937,8 @@ var ReadonlyWallet = class _ReadonlyWallet {
13716
13937
  const seenBaselineScripts = /* @__PURE__ */ new Set();
13717
13938
  for (const serverPubKey of baselineSigners) {
13718
13939
  for (const csvTimelock of this.walletContractTimelocks) {
13719
- const csvTimelockStr = chunk5J5PDZRR_cjs.timelockToSequence(csvTimelock).toString();
13720
- const defaultScript = new chunkP6EXRY5L_cjs.DefaultVtxo.Script({
13940
+ const csvTimelockStr = chunkKJ5E646Y_cjs.timelockToSequence(csvTimelock).toString();
13941
+ const defaultScript = new chunk2D7F5IU3_cjs.DefaultVtxo.Script({
13721
13942
  pubKey: baselinePubkey,
13722
13943
  serverPubKey,
13723
13944
  csvTimelock
@@ -13738,7 +13959,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
13738
13959
  });
13739
13960
  }
13740
13961
  if (delegatePubKey) {
13741
- const delegateScript = new chunkP6EXRY5L_cjs.DelegateVtxo.Script({
13962
+ const delegateScript = new chunk2D7F5IU3_cjs.DelegateVtxo.Script({
13742
13963
  pubKey: baselinePubkey,
13743
13964
  serverPubKey,
13744
13965
  delegatePubKey,
@@ -13762,9 +13983,9 @@ var ReadonlyWallet = class _ReadonlyWallet {
13762
13983
  }
13763
13984
  }
13764
13985
  }
13765
- const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunkP6EXRY5L_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
13986
+ const boardingCsvTimelock = this.boardingTapscript.options.csvTimelock ?? chunk2D7F5IU3_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
13766
13987
  for (const serverPubKey of baselineSigners) {
13767
- const baselineBoarding = new chunkP6EXRY5L_cjs.DefaultVtxo.Script({
13988
+ const baselineBoarding = new chunk2D7F5IU3_cjs.DefaultVtxo.Script({
13768
13989
  pubKey: baselinePubkey,
13769
13990
  serverPubKey,
13770
13991
  csvTimelock: boardingCsvTimelock
@@ -13777,7 +13998,7 @@ var ReadonlyWallet = class _ReadonlyWallet {
13777
13998
  params: {
13778
13999
  pubKey: base.hex.encode(baselineBoarding.options.pubKey),
13779
14000
  serverPubKey: base.hex.encode(serverPubKey),
13780
- csvTimelock: chunk5J5PDZRR_cjs.timelockToSequence(boardingCsvTimelock).toString()
14001
+ csvTimelock: chunkKJ5E646Y_cjs.timelockToSequence(boardingCsvTimelock).toString()
13781
14002
  },
13782
14003
  script: boardingScriptHex,
13783
14004
  address: baselineBoarding.address(this.network.hrp, serverPubKey).encode(),
@@ -13977,7 +14198,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
13977
14198
  serverPubKey: this.offchainTapscript.options.serverPubKey,
13978
14199
  deprecatedSignerPubKeys: [...this._deprecatedSigners.keys()].map((h) => base.hex.decode(h)),
13979
14200
  csvTimelocks: this.walletContractTimelocks,
13980
- delegatePubKey: this.offchainTapscript instanceof chunkP6EXRY5L_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0
14201
+ delegatePubKey: this.offchainTapscript instanceof chunk2D7F5IU3_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0
13981
14202
  };
13982
14203
  }
13983
14204
  _signerRouter;
@@ -14222,7 +14443,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14222
14443
  const [row] = await manager.getContracts({ script: base.hex.encode(display.pkScript) });
14223
14444
  const persisted = row?.metadata?.signingDescriptor;
14224
14445
  if (typeof persisted === "string") return persisted;
14225
- return chunkP6EXRY5L_cjs.identityDescriptor(this.identity);
14446
+ return chunk2D7F5IU3_cjs.identityDescriptor(this.identity);
14226
14447
  }
14227
14448
  /**
14228
14449
  * Build, persist and shape one address of `type` owned by `descriptor` —
@@ -14238,7 +14459,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14238
14459
  async mintAddress(manager, type, descriptor, tagSource, allocated) {
14239
14460
  if (type === "boarding") {
14240
14461
  const built2 = this.buildBoardingContract(
14241
- chunkP6EXRY5L_cjs.deriveDescriptorLeafPubKey(descriptor),
14462
+ chunk2D7F5IU3_cjs.deriveDescriptorLeafPubKey(descriptor),
14242
14463
  descriptor,
14243
14464
  tagSource
14244
14465
  );
@@ -14283,11 +14504,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14283
14504
  * {@link buildReceiveContract}.
14284
14505
  */
14285
14506
  buildBoardingContract(pubKey, descriptor, tagSource) {
14286
- const tapscript = new chunkP6EXRY5L_cjs.DefaultVtxo.Script({
14507
+ const tapscript = new chunk2D7F5IU3_cjs.DefaultVtxo.Script({
14287
14508
  ...this._boardingTapscript.options,
14288
14509
  pubKey
14289
14510
  });
14290
- const csvTimelock = tapscript.options.csvTimelock ?? chunkP6EXRY5L_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
14511
+ const csvTimelock = tapscript.options.csvTimelock ?? chunk2D7F5IU3_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
14291
14512
  return {
14292
14513
  tapscript,
14293
14514
  params: {
@@ -14295,13 +14516,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14295
14516
  params: {
14296
14517
  pubKey: base.hex.encode(pubKey),
14297
14518
  serverPubKey: base.hex.encode(tapscript.options.serverPubKey),
14298
- csvTimelock: chunk5J5PDZRR_cjs.timelockToSequence(csvTimelock).toString()
14519
+ csvTimelock: chunkKJ5E646Y_cjs.timelockToSequence(csvTimelock).toString()
14299
14520
  },
14300
14521
  script: base.hex.encode(tapscript.pkScript),
14301
14522
  address: tapscript.address(this.network.hrp, this.arkServerPublicKey).encode(),
14302
14523
  state: "active",
14303
14524
  metadata: {
14304
- ...tagSource && { source: chunkP6EXRY5L_cjs.WALLET_RECEIVE_SOURCE },
14525
+ ...tagSource && { source: chunk2D7F5IU3_cjs.WALLET_RECEIVE_SOURCE },
14305
14526
  signingDescriptor: descriptor
14306
14527
  }
14307
14528
  }
@@ -14330,7 +14551,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14330
14551
  if (this._descriptorProvider instanceof HDDescriptorProvider) {
14331
14552
  return (await this.getContractManager()).getNextSigningDescriptor();
14332
14553
  }
14333
- return chunkP6EXRY5L_cjs.identityDescriptor(this.identity);
14554
+ return chunk2D7F5IU3_cjs.identityDescriptor(this.identity);
14334
14555
  }
14335
14556
  /**
14336
14557
  * @see HDAllocationCapable.advanceSigningDescriptorWatermark
@@ -14426,7 +14647,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14426
14647
  * the stable public API.
14427
14648
  */
14428
14649
  async rotateServerSigner(newServerPubKey, checkpointTapscript) {
14429
- const xonly = chunkP6EXRY5L_cjs.toXOnly(newServerPubKey, "ark signer key");
14650
+ const xonly = chunk2D7F5IU3_cjs.toXOnly(newServerPubKey, "ark signer key");
14430
14651
  const newServerUnrollScript = assertValidServerUnrollScript(
14431
14652
  checkpointTapscript,
14432
14653
  resolveCheckpointExitDelayPolicy(this.network, this.checkpointExitDelayPolicy)
@@ -14455,21 +14676,21 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14455
14676
  const [currentBoardingRow] = await manager.getContracts({
14456
14677
  script: currentBoardingScript
14457
14678
  });
14458
- const newOffchain = this.offchainTapscript instanceof chunkP6EXRY5L_cjs.DelegateVtxo.Script ? new chunkP6EXRY5L_cjs.DelegateVtxo.Script({
14679
+ const newOffchain = this.offchainTapscript instanceof chunk2D7F5IU3_cjs.DelegateVtxo.Script ? new chunk2D7F5IU3_cjs.DelegateVtxo.Script({
14459
14680
  ...this.offchainTapscript.options,
14460
14681
  serverPubKey: xonly
14461
- }) : new chunkP6EXRY5L_cjs.DefaultVtxo.Script({
14682
+ }) : new chunk2D7F5IU3_cjs.DefaultVtxo.Script({
14462
14683
  ...this.offchainTapscript.options,
14463
14684
  serverPubKey: xonly
14464
14685
  });
14465
- const newBoarding = new chunkP6EXRY5L_cjs.DefaultVtxo.Script({
14686
+ const newBoarding = new chunk2D7F5IU3_cjs.DefaultVtxo.Script({
14466
14687
  ...this._boardingTapscript.options,
14467
14688
  serverPubKey: xonly
14468
14689
  });
14469
- const offchainCsv = chunk5J5PDZRR_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
14690
+ const offchainCsv = chunkKJ5E646Y_cjs.timelockToSequence(newOffchain.options.csvTimelock).toString();
14470
14691
  const newOffchainScript = base.hex.encode(newOffchain.pkScript);
14471
14692
  const newOffchainAddress = newOffchain.address(this.network.hrp, xonly).encode();
14472
- if (newOffchain instanceof chunkP6EXRY5L_cjs.DelegateVtxo.Script) {
14693
+ if (newOffchain instanceof chunk2D7F5IU3_cjs.DelegateVtxo.Script) {
14473
14694
  await manager.createContract({
14474
14695
  type: "delegate",
14475
14696
  params: {
@@ -14497,13 +14718,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14497
14718
  metadata: currentOffchainRow?.metadata
14498
14719
  });
14499
14720
  }
14500
- const boardingCsv = newBoarding.options.csvTimelock ?? chunkP6EXRY5L_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
14721
+ const boardingCsv = newBoarding.options.csvTimelock ?? chunk2D7F5IU3_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK;
14501
14722
  await manager.createContract({
14502
14723
  type: "boarding",
14503
14724
  params: {
14504
14725
  pubKey: base.hex.encode(newBoarding.options.pubKey),
14505
14726
  serverPubKey: base.hex.encode(xonly),
14506
- csvTimelock: chunk5J5PDZRR_cjs.timelockToSequence(boardingCsv).toString()
14727
+ csvTimelock: chunkKJ5E646Y_cjs.timelockToSequence(boardingCsv).toString()
14507
14728
  },
14508
14729
  script: base.hex.encode(newBoarding.pkScript),
14509
14730
  address: newBoarding.address(this.network.hrp, xonly).encode(),
@@ -14536,14 +14757,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14536
14757
  _restoreInFlight;
14537
14758
  _addPendingSpends(inputs) {
14538
14759
  for (const input of inputs) {
14539
- if (chunk5J5PDZRR_cjs.isVirtualCoin(input)) {
14760
+ if (chunkKJ5E646Y_cjs.isVirtualCoin(input)) {
14540
14761
  this._pendingSpendOutpoints.add(`${input.txid}:${input.vout}`);
14541
14762
  }
14542
14763
  }
14543
14764
  }
14544
14765
  _removePendingSpends(inputs) {
14545
14766
  for (const input of inputs) {
14546
- if (chunk5J5PDZRR_cjs.isVirtualCoin(input)) {
14767
+ if (chunkKJ5E646Y_cjs.isVirtualCoin(input)) {
14547
14768
  this._pendingSpendOutpoints.delete(`${input.txid}:${input.vout}`);
14548
14769
  }
14549
14770
  }
@@ -14592,7 +14813,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14592
14813
  `restore: gapLimit must be a positive integer (got ${String(opts?.gapLimit)})`
14593
14814
  );
14594
14815
  }
14595
- this._restoreInFlight = this._runRestore(gapLimit).finally(() => {
14816
+ this._restoreInFlight = (async () => {
14817
+ await this._runRestore(gapLimit);
14818
+ await runWalletRestoreHooks(this);
14819
+ })().finally(() => {
14596
14820
  this._restoreInFlight = void 0;
14597
14821
  });
14598
14822
  return this._restoreInFlight;
@@ -14601,13 +14825,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14601
14825
  const manager = await this.getContractManager();
14602
14826
  const provider = this._descriptorProvider;
14603
14827
  const hd = provider instanceof HDDescriptorProvider;
14604
- const staticDescriptor = hd ? void 0 : await chunkP6EXRY5L_cjs.identityDescriptor(this.identity);
14828
+ const staticDescriptor = hd ? void 0 : await chunk2D7F5IU3_cjs.identityDescriptor(this.identity);
14605
14829
  const materialize = (index) => hd ? provider.materializeDescriptorAt(index) : staticDescriptor;
14606
- const delegatePubKey = this.offchainTapscript instanceof chunkP6EXRY5L_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
14830
+ const delegatePubKey = this.offchainTapscript instanceof chunk2D7F5IU3_cjs.DelegateVtxo.Script ? this.offchainTapscript.options.delegatePubKey : void 0;
14607
14831
  const arkInfo = await this.arkProvider.getInfo();
14608
- const currentSignerPubKey = chunkP6EXRY5L_cjs.toXOnly(base.hex.decode(arkInfo.signerPubkey), "ark signer key");
14832
+ const currentSignerPubKey = chunk2D7F5IU3_cjs.toXOnly(base.hex.decode(arkInfo.signerPubkey), "ark signer key");
14609
14833
  const deprecatedSignerPubKeys = arkInfo.deprecatedSigners.map(
14610
- (s) => chunkP6EXRY5L_cjs.toXOnly(base.hex.decode(s.pubkey), "deprecated signer key")
14834
+ (s) => chunk2D7F5IU3_cjs.toXOnly(base.hex.decode(s.pubkey), "deprecated signer key")
14611
14835
  );
14612
14836
  const deps = {
14613
14837
  indexerProvider: this.indexerProvider,
@@ -14622,7 +14846,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14622
14846
  csvTimelocks: this.walletContractTimelocks,
14623
14847
  // Boarding-exit CSV so the boarding handler can build its
14624
14848
  // candidate script (distinct from the unilateral-exit matrix).
14625
- boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunkP6EXRY5L_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
14849
+ boardingTimelock: this.boardingTapscript.options.csvTimelock ?? chunk2D7F5IU3_cjs.DefaultVtxo.Script.DEFAULT_TIMELOCK,
14626
14850
  delegatePubKey
14627
14851
  };
14628
14852
  const result = await manager.scanContracts({
@@ -14736,7 +14960,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14736
14960
  throw new Error("Invalid configured public key");
14737
14961
  }
14738
14962
  const setup = await ReadonlyWallet.setupWalletConfig(config, pubkey);
14739
- const forfeitPubkey = chunkP6EXRY5L_cjs.toXOnly(base.hex.decode(setup.info.forfeitPubkey), "forfeit key");
14963
+ const forfeitPubkey = chunk2D7F5IU3_cjs.toXOnly(base.hex.decode(setup.info.forfeitPubkey), "forfeit key");
14740
14964
  const forfeitAddress = btcSigner.Address(setup.network).decode(setup.info.forfeitAddress);
14741
14965
  const forfeitOutputScript = btcSigner.OutScript.encode(forfeitAddress);
14742
14966
  const checkpointExitDelayOverrides = {
@@ -14885,7 +15109,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14885
15109
  inputs: params.selectedVtxos,
14886
15110
  changeAmount: BigInt(changeAmount)
14887
15111
  };
14888
- const outputAddress = chunk5J5PDZRR_cjs.ArkAddress.decode(params.address);
15112
+ const outputAddress = chunkKJ5E646Y_cjs.ArkAddress.decode(params.address);
14889
15113
  assertRecipientArkAddress(
14890
15114
  params.address,
14891
15115
  outputAddress,
@@ -14951,13 +15175,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14951
15175
  void this.logUngatedInputs("settle({ inputs })", params.inputs);
14952
15176
  }
14953
15177
  const offchainAddress = await this.getAddress();
14954
- const offchainPkScript = chunk5J5PDZRR_cjs.ArkAddress.decode(offchainAddress).pkScript;
15178
+ const offchainPkScript = chunkKJ5E646Y_cjs.ArkAddress.decode(offchainAddress).pkScript;
14955
15179
  const offchainOutputScript = base.hex.encode(offchainPkScript);
14956
15180
  if (!params) {
14957
15181
  const { fees, vtxoMaxAmount } = await this.arkProvider.getInfo();
14958
15182
  const estimator = new Estimator(fees.intentFee);
14959
15183
  let amount = 0;
14960
- const exitScript = chunk5J5PDZRR_cjs.CSVMultisigTapscript.decode(
15184
+ const exitScript = chunkKJ5E646Y_cjs.CSVMultisigTapscript.decode(
14961
15185
  base.hex.decode(this.boardingTapscript.exitScript)
14962
15186
  );
14963
15187
  const boardingTimelock = exitScript.params.timelock;
@@ -14986,7 +15210,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
14986
15210
  if (filteredVtxos.length >= MAX_VTXOS_PER_SETTLEMENT) {
14987
15211
  break;
14988
15212
  }
14989
- const inputFee = estimator.evalOffchainInput(chunk5J5PDZRR_cjs.toOffchainInputFeeParams(vtxo));
15213
+ const inputFee = estimator.evalOffchainInput(chunkKJ5E646Y_cjs.toOffchainInputFeeParams(vtxo));
14990
15214
  if (inputFee.satoshis >= vtxo.value) {
14991
15215
  continue;
14992
15216
  }
@@ -15033,7 +15257,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15033
15257
  let script;
15034
15258
  let arkAddress;
15035
15259
  try {
15036
- arkAddress = chunk5J5PDZRR_cjs.ArkAddress.decode(output.address);
15260
+ arkAddress = chunkKJ5E646Y_cjs.ArkAddress.decode(output.address);
15037
15261
  } catch {
15038
15262
  arkAddress = void 0;
15039
15263
  }
@@ -15123,7 +15347,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15123
15347
  const abortController = new AbortController();
15124
15348
  let stream;
15125
15349
  let committedTxid;
15126
- const settleInputVtxos = params.inputs.filter(chunk5J5PDZRR_cjs.isVirtualCoin);
15350
+ const settleInputVtxos = params.inputs.filter(chunkKJ5E646Y_cjs.isVirtualCoin);
15127
15351
  const contractManager = await this.getContractManager();
15128
15352
  await contractManager.assertAnnotatable(settleInputVtxos);
15129
15353
  await contractManager.assertSpendableNow?.(
@@ -15235,7 +15459,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15235
15459
  async maybeRotateBoardingAfterBoard(inputs) {
15236
15460
  if (!this._descriptorProvider) return;
15237
15461
  const consumedBoarding = inputs.some(
15238
- (input) => typeof input !== "string" && !chunk5J5PDZRR_cjs.isVirtualCoin(input)
15462
+ (input) => typeof input !== "string" && !chunkKJ5E646Y_cjs.isVirtualCoin(input)
15239
15463
  );
15240
15464
  if (!consumedBoarding) return;
15241
15465
  try {
@@ -15259,7 +15483,8 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15259
15483
  let connectorIndex = 0;
15260
15484
  const connectorsLeaves = connectorsGraph?.leaves() || [];
15261
15485
  for (const input of inputs) {
15262
- if (!chunk5J5PDZRR_cjs.isVirtualCoin(input)) {
15486
+ if (!chunkKJ5E646Y_cjs.isVirtualCoin(input)) {
15487
+ let matched = false;
15263
15488
  for (let i = 0; i < settlementPsbt.inputsLength; i++) {
15264
15489
  const settlementInput = settlementPsbt.getInput(i);
15265
15490
  if (!settlementInput.txid || settlementInput.index === void 0) {
@@ -15286,11 +15511,17 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15286
15511
  throw new Error(await this.unsignableBoardingInputError(input, script));
15287
15512
  }
15288
15513
  hasBoardingUtxos = true;
15514
+ matched = true;
15289
15515
  break;
15290
15516
  }
15517
+ if (!matched && !(input instanceof ArkNote)) {
15518
+ throw new Error(
15519
+ `boarding input ${input.txid}:${input.vout} is not an input of the commitment tx`
15520
+ );
15521
+ }
15291
15522
  continue;
15292
15523
  }
15293
- if (chunk5J5PDZRR_cjs.canRecoverOnchain(input, { timestamp: /* @__PURE__ */ new Date() }) || isSubdust({ value: input.value }, this.dustAmount)) {
15524
+ if (chunkKJ5E646Y_cjs.canRecoverOnchain(input, { timestamp: /* @__PURE__ */ new Date() }) || isSubdust({ value: input.value }, this.dustAmount)) {
15294
15525
  continue;
15295
15526
  }
15296
15527
  if (connectorsLeaves.length === 0) {
@@ -15318,7 +15549,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15318
15549
  index: input.vout,
15319
15550
  witnessUtxo: {
15320
15551
  amount: BigInt(input.value),
15321
- script: chunk5J5PDZRR_cjs.VtxoScript.decode(input.tapTree).pkScript
15552
+ script: chunkKJ5E646Y_cjs.VtxoScript.decode(input.tapTree).pkScript
15322
15553
  },
15323
15554
  sighashType: btcSigner.SigHash.DEFAULT,
15324
15555
  tapLeafScript: [input.forfeitTapLeafScript]
@@ -15337,7 +15568,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15337
15568
  forfeitTx = await this._signerRouter.sign(forfeitTx, [
15338
15569
  {
15339
15570
  index: 0,
15340
- lookupScript: chunk5J5PDZRR_cjs.VtxoScript.decode(input.tapTree).pkScript
15571
+ lookupScript: chunkKJ5E646Y_cjs.VtxoScript.decode(input.tapTree).pkScript
15341
15572
  }
15342
15573
  ]);
15343
15574
  signedForfeits.push(base.base64.encode(forfeitTx.toPSBT()));
@@ -15395,7 +15626,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15395
15626
  resolveBatchExpiryPolicy(this.network, this.batchExpiryPolicy)
15396
15627
  );
15397
15628
  await this.arkProvider.confirmRegistration(intentId);
15398
- const sweepTapscript = chunk5J5PDZRR_cjs.CSVMultisigTapscript.encode({
15629
+ const sweepTapscript = chunkKJ5E646Y_cjs.CSVMultisigTapscript.encode({
15399
15630
  timelock,
15400
15631
  pubkeys: [this.forfeitPubkey]
15401
15632
  }).script;
@@ -15410,10 +15641,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15410
15641
  throw new Error("Sweep tap tree root not set");
15411
15642
  }
15412
15643
  const xOnlyPublicKeys = event.cosignersPublicKeys.map(
15413
- (k) => base.hex.encode(chunkP6EXRY5L_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
15644
+ (k) => base.hex.encode(chunk2D7F5IU3_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
15414
15645
  );
15415
15646
  const signerPublicKey = await session.getPublicKey();
15416
- const xonlySignerPublicKey = chunkP6EXRY5L_cjs.toXOnly(signerPublicKey, "signer key");
15647
+ const xonlySignerPublicKey = chunk2D7F5IU3_cjs.toXOnly(signerPublicKey, "signer key");
15417
15648
  if (!xOnlyPublicKeys.includes(base.hex.encode(xonlySignerPublicKey))) {
15418
15649
  return { skip: true };
15419
15650
  }
@@ -15503,9 +15734,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15503
15734
  ...existing ?? {},
15504
15735
  intentTxId,
15505
15736
  registerProof: intent.proof,
15506
- registerProofMessage: chunk5J5PDZRR_cjs.Intent.encodeMessage(intent.message),
15737
+ registerProofMessage: chunkKJ5E646Y_cjs.Intent.encodeMessage(intent.message),
15507
15738
  deleteProof: deleteIntent.proof,
15508
- deleteProofMessage: chunk5J5PDZRR_cjs.Intent.encodeMessage(deleteIntent.message),
15739
+ deleteProofMessage: chunkKJ5E646Y_cjs.Intent.encodeMessage(deleteIntent.message),
15509
15740
  intentVtxos: inputs.map((i) => ({
15510
15741
  txid: i.txid,
15511
15742
  vout: i.vout
@@ -15537,7 +15768,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15537
15768
  try {
15538
15769
  return await this.arkProvider.registerIntent(intent);
15539
15770
  } catch (error) {
15540
- if (error instanceof chunk5J5PDZRR_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
15771
+ if (error instanceof chunkKJ5E646Y_cjs.ArkError && error.code === 0 && error.message.includes("duplicated input")) {
15541
15772
  const deleteIntent = await this.makeDeleteIntentSignature(inputs);
15542
15773
  await this.arkProvider.deleteIntent(deleteIntent);
15543
15774
  return this.arkProvider.registerIntent(intent);
@@ -15553,7 +15784,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15553
15784
  expire_at: 0,
15554
15785
  cosigners_public_keys: cosignerPubKeys
15555
15786
  };
15556
- const proof = chunk5J5PDZRR_cjs.Intent.create(message, coins, outputs);
15787
+ const proof = chunkKJ5E646Y_cjs.Intent.create(message, coins, outputs);
15557
15788
  const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
15558
15789
  return {
15559
15790
  proof: base.base64.encode(signedProof.toPSBT()),
@@ -15565,7 +15796,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15565
15796
  type: "delete",
15566
15797
  expire_at: 0
15567
15798
  };
15568
- const proof = chunk5J5PDZRR_cjs.Intent.create(message, coins, []);
15799
+ const proof = chunkKJ5E646Y_cjs.Intent.create(message, coins, []);
15569
15800
  const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
15570
15801
  return {
15571
15802
  proof: base.base64.encode(signedProof.toPSBT()),
@@ -15577,7 +15808,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15577
15808
  type: "get-pending-tx",
15578
15809
  expire_at: 0
15579
15810
  };
15580
- const proof = chunk5J5PDZRR_cjs.Intent.create(message, coins, []);
15811
+ const proof = chunkKJ5E646Y_cjs.Intent.create(message, coins, []);
15581
15812
  const signedProof = await this._signerRouter.sign(proof, intentProofJobs(coins));
15582
15813
  return {
15583
15814
  proof: base.base64.encode(signedProof.toPSBT()),
@@ -15598,7 +15829,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15598
15829
  if (!vtxos || vtxos.length === 0) {
15599
15830
  const scriptMap = await this.getScriptMap();
15600
15831
  const allExtended = [];
15601
- const fetchedVtxos = await chunk5J5PDZRR_cjs.getAllNormalizedVtxos(this.indexerProvider, [
15832
+ const fetchedVtxos = await chunkKJ5E646Y_cjs.getAllNormalizedVtxos(this.indexerProvider, [
15602
15833
  ...scriptMap.keys()
15603
15834
  ]);
15604
15835
  for (const vtxo of fetchedVtxos) {
@@ -15642,7 +15873,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15642
15873
  try {
15643
15874
  const checkpointTxs = pendingTx.signedCheckpointTxs.map((c) => {
15644
15875
  const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(c));
15645
- chunk5J5PDZRR_cjs.assertAllowedSighashTypes(tx);
15876
+ chunkKJ5E646Y_cjs.assertAllowedSighashTypes(tx);
15646
15877
  return tx;
15647
15878
  });
15648
15879
  assertCheckpointsMatchInputs(
@@ -15714,11 +15945,11 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15714
15945
  * against the current key alone would leave it pending forever.
15715
15946
  */
15716
15947
  checkpointUnrollCandidates(info) {
15717
- const current = chunk5J5PDZRR_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
15948
+ const current = chunkKJ5E646Y_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
15718
15949
  const candidates = [this._serverUnrollScript, current];
15719
15950
  for (const deprecated of signerSetFromInfo(info).deprecated.keys()) {
15720
15951
  candidates.push(
15721
- chunk5J5PDZRR_cjs.CSVMultisigTapscript.encode({
15952
+ chunkKJ5E646Y_cjs.CSVMultisigTapscript.encode({
15722
15953
  ...current.params,
15723
15954
  pubkeys: [base.hex.decode(deprecated)]
15724
15955
  })
@@ -15809,7 +16040,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15809
16040
  if (vtxos.length === 0) {
15810
16041
  throw new Error("No VTXOs found for this arkadeCash");
15811
16042
  }
15812
- const myPkScript = chunk5J5PDZRR_cjs.ArkAddress.decode(await this.getAddress()).pkScript;
16043
+ const myPkScript = chunkKJ5E646Y_cjs.ArkAddress.decode(await this.getAddress()).pkScript;
15813
16044
  let { spendable, unclaimed } = this.classifyCashVtxos(vtxos);
15814
16045
  let swept = 0;
15815
16046
  const drainable = vtxos.filter(
@@ -15885,7 +16116,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15885
16116
  const spendable = [];
15886
16117
  const unclaimed = [];
15887
16118
  for (const vtxo of vtxos) {
15888
- if (chunk5J5PDZRR_cjs.hasTerminalSpend(vtxo)) {
16119
+ if (chunkKJ5E646Y_cjs.hasTerminalSpend(vtxo)) {
15889
16120
  unclaimed.push(cashReport(vtxo, "already-spent"));
15890
16121
  } else if (vtxo.isUnrolled) {
15891
16122
  unclaimed.push(cashReport(vtxo, "exited"));
@@ -15907,7 +16138,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15907
16138
  const all = [];
15908
16139
  const seen = /* @__PURE__ */ new Set();
15909
16140
  for (let pageIndex = 0; ; pageIndex++) {
15910
- const { vtxos, page } = await chunk5J5PDZRR_cjs.getNormalizedVtxos(this.indexerProvider, {
16141
+ const { vtxos, page } = await chunkKJ5E646Y_cjs.getNormalizedVtxos(this.indexerProvider, {
15911
16142
  scripts,
15912
16143
  pageIndex,
15913
16144
  pageSize
@@ -15954,7 +16185,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15954
16185
  for (let i = 0; i < inputs.length; i += MAX_INPUTS_PER_INTENT) {
15955
16186
  const batch = inputs.slice(i, i + MAX_INPUTS_PER_INTENT);
15956
16187
  const message = { type: "get-pending-tx", expire_at: 0 };
15957
- const proof = chunk5J5PDZRR_cjs.Intent.create(message, batch, []);
16188
+ const proof = chunkKJ5E646Y_cjs.Intent.create(message, batch, []);
15958
16189
  const signedProof = await identity.sign(
15959
16190
  proof,
15960
16191
  Array.from({ length: batch.length + 1 }, (_, j) => j)
@@ -15976,7 +16207,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
15976
16207
  try {
15977
16208
  const checkpointTxs = pendingTx.signedCheckpointTxs.map((checkpoint) => {
15978
16209
  const tx = btcSigner.Transaction.fromPSBT(base.base64.decode(checkpoint));
15979
- chunk5J5PDZRR_cjs.assertAllowedSighashTypes(tx);
16210
+ chunkKJ5E646Y_cjs.assertAllowedSighashTypes(tx);
15980
16211
  return tx;
15981
16212
  });
15982
16213
  assertCheckpointsMatchInputs(
@@ -16175,7 +16406,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
16175
16406
  script: recipient.script,
16176
16407
  amount: BigInt(recipient.amount),
16177
16408
  // Already checked against the recipient address in `validateRecipients`.
16178
- ...recipient.tapTree ? { tapTree: chunk5J5PDZRR_cjs.TapTreeCoder.decode(recipient.tapTree) } : {}
16409
+ ...recipient.tapTree ? { tapTree: chunkKJ5E646Y_cjs.TapTreeCoder.decode(recipient.tapTree) } : {}
16179
16410
  }));
16180
16411
  const totalBtcOutput = outputs.reduce((sum, o) => sum + Number(o.amount), 0);
16181
16412
  let changeAmount = totalBtcSelected - totalBtcOutput;
@@ -16319,10 +16550,10 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
16319
16550
  const serverPubKey = this.arkServerPublicKey;
16320
16551
  const serverUnrollScript = this.serverUnrollScript;
16321
16552
  const arkAddress = offchainTapscript.address(this.network.hrp, serverPubKey);
16322
- const normalizedInputs = inputs.map(chunk5J5PDZRR_cjs.normalizeVtxo);
16323
- const at = now ?? await chunk5J5PDZRR_cjs.resolveTimeHeight(this.onchainProvider);
16553
+ const normalizedInputs = inputs.map(chunkKJ5E646Y_cjs.normalizeVtxo);
16554
+ const at = now ?? await chunkKJ5E646Y_cjs.resolveTimeHeight(this.onchainProvider);
16324
16555
  for (const input of normalizedInputs) {
16325
- if (!chunk5J5PDZRR_cjs.canSpendOffchain(input, at)) {
16556
+ if (!chunkKJ5E646Y_cjs.canSpendOffchain(input, at)) {
16326
16557
  throw new Error(
16327
16558
  `sendSelectedVtxosToSelf: input ${input.txid}:${input.vout} is not cooperatively spendable`
16328
16559
  );
@@ -16392,7 +16623,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
16392
16623
  );
16393
16624
  const arkTxJobs = inputs.map((input, index) => ({
16394
16625
  index,
16395
- lookupScript: chunk5J5PDZRR_cjs.VtxoScript.decode(input.tapTree).pkScript
16626
+ lookupScript: chunkKJ5E646Y_cjs.VtxoScript.decode(input.tapTree).pkScript
16396
16627
  }));
16397
16628
  const identity = this.identity;
16398
16629
  const signer = {
@@ -16428,18 +16659,33 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
16428
16659
  this.inputSigningJobsFromWitnessUtxos(checkpoint)
16429
16660
  )
16430
16661
  };
16431
- return submitOffchainTx(this.arkProvider, offchainTx, signer, {
16432
- // Mark pending before submitting — if we crash between submit and
16433
- // finalize, the next init recovers via finalizePendingTxs.
16434
- beforeSubmit: () => this.setPendingTxFlag(true),
16435
- afterFinalize: async () => {
16436
- try {
16437
- await this.setPendingTxFlag(false);
16438
- } catch (error) {
16439
- console.error("Failed to clear pending tx flag:", error);
16662
+ return submitOffchainTx(
16663
+ this.arkProvider,
16664
+ offchainTx,
16665
+ signer,
16666
+ {
16667
+ // Mark pending before submitting — if we crash between submit and
16668
+ // finalize, the next init recovers via finalizePendingTxs.
16669
+ beforeSubmit: () => this.setPendingTxFlag(true),
16670
+ afterFinalize: async () => {
16671
+ try {
16672
+ await this.setPendingTxFlag(false);
16673
+ } catch (error) {
16674
+ console.error("Failed to clear pending tx flag:", error);
16675
+ }
16676
+ }
16677
+ },
16678
+ {
16679
+ // Deprecated keys too: a vtxo built before a rotation is still
16680
+ // spent under the signer its leaf names.
16681
+ verifyServerSignatures: {
16682
+ serverPubkey: this._arkServerPublicKey,
16683
+ deprecatedServerPubkeys: [...this._deprecatedSigners.keys()].map(
16684
+ (h) => base.hex.decode(h)
16685
+ )
16440
16686
  }
16441
16687
  }
16442
- });
16688
+ );
16443
16689
  }
16444
16690
  // mark virtual outputs as spent, save change outputs if any.
16445
16691
  // `offchainTapscript` and `serverPubKey` are the epoch snapshot the
@@ -16478,14 +16724,14 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
16478
16724
  const spentBy = checkpointIdByOutpoint.get(`${vtxo.txid}:${vtxo.vout}`);
16479
16725
  spentVtxos.push({
16480
16726
  ...spentFacts,
16481
- virtualStatus: chunk5J5PDZRR_cjs.toVirtualStatus(spentFacts),
16727
+ virtualStatus: chunkKJ5E646Y_cjs.toVirtualStatus(spentFacts),
16482
16728
  ...spentBy ? { spentBy } : {},
16483
16729
  arkTxId: arkTxid
16484
16730
  });
16485
16731
  for (const id of vtxo.commitmentTxIds) {
16486
16732
  commitmentTxIds.add(id);
16487
16733
  }
16488
- const vtxoExpiry = chunk5J5PDZRR_cjs.toBatchExpiry(vtxo);
16734
+ const vtxoExpiry = chunkKJ5E646Y_cjs.toBatchExpiry(vtxo);
16489
16735
  if (vtxoExpiry) {
16490
16736
  batchExpiry = Math.min(batchExpiry, vtxoExpiry);
16491
16737
  }
@@ -16498,7 +16744,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
16498
16744
  isSwept: false,
16499
16745
  isPreconfirmed: true,
16500
16746
  commitmentTxIds: Array.from(commitmentTxIds),
16501
- ...chunk5J5PDZRR_cjs.parseLegacyExpiry(batchExpiry)
16747
+ ...chunkKJ5E646Y_cjs.parseLegacyExpiry(batchExpiry)
16502
16748
  };
16503
16749
  changeVtxo = {
16504
16750
  txid: arkTxid,
@@ -16510,7 +16756,7 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
16510
16756
  tapTree: offchainTapscript.encode(),
16511
16757
  value: Number(changeAmount),
16512
16758
  ...changeFacts,
16513
- virtualStatus: chunk5J5PDZRR_cjs.toVirtualStatus(changeFacts),
16759
+ virtualStatus: chunkKJ5E646Y_cjs.toVirtualStatus(changeFacts),
16514
16760
  spentBy: "",
16515
16761
  status: {
16516
16762
  confirmed: false
@@ -16579,12 +16825,12 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
16579
16825
  const spentVtxos = [];
16580
16826
  const inputArkTxIds = /* @__PURE__ */ new Set();
16581
16827
  const boardingRemovalsByAddress = /* @__PURE__ */ new Map();
16582
- const vtxoInputs = inputs.filter(chunk5J5PDZRR_cjs.isVirtualCoin);
16828
+ const vtxoInputs = inputs.filter(chunkKJ5E646Y_cjs.isVirtualCoin);
16583
16829
  const cm = await this.getContractManager();
16584
16830
  const annotatedVtxos = await cm.annotateVtxos(vtxoInputs);
16585
16831
  const annotatedByKey = new Map(annotatedVtxos.map((v) => [`${v.txid}:${v.vout}`, v]));
16586
16832
  for (const input of inputs) {
16587
- if (chunk5J5PDZRR_cjs.isVirtualCoin(input)) {
16833
+ if (chunkKJ5E646Y_cjs.isVirtualCoin(input)) {
16588
16834
  const outpoint = `${input.txid}:${input.vout}`;
16589
16835
  const vtxo = annotatedByKey.get(outpoint);
16590
16836
  if (!vtxo) {
@@ -16596,13 +16842,13 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
16596
16842
  const settledFacts = { ...vtxo, isSpent: true };
16597
16843
  spentVtxos.push({
16598
16844
  ...settledFacts,
16599
- virtualStatus: chunk5J5PDZRR_cjs.toVirtualStatus(settledFacts),
16845
+ virtualStatus: chunkKJ5E646Y_cjs.toVirtualStatus(settledFacts),
16600
16846
  settledBy: commitmentTxid
16601
16847
  });
16602
16848
  } else {
16603
16849
  let sourceAddress;
16604
16850
  try {
16605
- sourceAddress = chunk5J5PDZRR_cjs.VtxoScript.decode(input.tapTree).onchainAddress(
16851
+ sourceAddress = chunkKJ5E646Y_cjs.VtxoScript.decode(input.tapTree).onchainAddress(
16606
16852
  this.network
16607
16853
  );
16608
16854
  } catch {
@@ -16660,9 +16906,9 @@ var Wallet2 = class _Wallet extends ReadonlyWallet {
16660
16906
  }
16661
16907
  };
16662
16908
  function selectVirtualCoins(coins, targetAmount) {
16663
- const sortedCoins = coins.map(chunk5J5PDZRR_cjs.normalizeVtxo).sort((a, b) => {
16664
- const expiryA = chunk5J5PDZRR_cjs.toBatchExpiry(a) || Number.MAX_SAFE_INTEGER;
16665
- const expiryB = chunk5J5PDZRR_cjs.toBatchExpiry(b) || Number.MAX_SAFE_INTEGER;
16909
+ const sortedCoins = coins.map(chunkKJ5E646Y_cjs.normalizeVtxo).sort((a, b) => {
16910
+ const expiryA = chunkKJ5E646Y_cjs.toBatchExpiry(a) || Number.MAX_SAFE_INTEGER;
16911
+ const expiryB = chunkKJ5E646Y_cjs.toBatchExpiry(b) || Number.MAX_SAFE_INTEGER;
16666
16912
  if (expiryA !== expiryB) {
16667
16913
  return expiryA - expiryB;
16668
16914
  }
@@ -17031,7 +17277,7 @@ var MessageBus = class {
17031
17277
  this.initialized = true;
17032
17278
  }
17033
17279
  async buildServices(config) {
17034
- const arkProvider = new chunk5J5PDZRR_cjs.RestArkProvider(config.arkServer.url);
17280
+ const arkProvider = new chunkKJ5E646Y_cjs.RestArkProvider(config.arkServer.url);
17035
17281
  const storage = {
17036
17282
  walletRepository: this.walletRepository,
17037
17283
  contractRepository: this.contractRepository,
@@ -17373,7 +17619,7 @@ var offboardNetworkNames = [
17373
17619
  function offboardDestinationScript(destinationAddress) {
17374
17620
  for (const networkName of offboardNetworkNames) {
17375
17621
  try {
17376
- const network = chunk5J5PDZRR_cjs.networks[networkName];
17622
+ const network = chunkKJ5E646Y_cjs.networks[networkName];
17377
17623
  const addr = btcSigner.Address(network).decode(destinationAddress);
17378
17624
  return btcSigner.OutScript.encode(addr);
17379
17625
  } catch {
@@ -17437,7 +17683,7 @@ var Ramps = class {
17437
17683
  }
17438
17684
  amount = amount ?? totalAmount;
17439
17685
  const offchainAddress = await this.wallet.getAddress();
17440
- const offchainAddr = chunk5J5PDZRR_cjs.ArkAddress.decode(offchainAddress);
17686
+ const offchainAddr = chunkKJ5E646Y_cjs.ArkAddress.decode(offchainAddress);
17441
17687
  const offchainScript = base.hex.encode(offchainAddr.pkScript);
17442
17688
  const outputFee = estimator.evalOffchainOutput({
17443
17689
  amount,
@@ -17497,7 +17743,7 @@ var Ramps = class {
17497
17743
  const filteredVtxos = [];
17498
17744
  let totalAmount = 0n;
17499
17745
  for (const vtxo of vtxos) {
17500
- const inputFee = estimator.evalOffchainInput(chunk5J5PDZRR_cjs.toOffchainInputFeeParams(vtxo));
17746
+ const inputFee = estimator.evalOffchainInput(chunkKJ5E646Y_cjs.toOffchainInputFeeParams(vtxo));
17501
17747
  if (inputFee.satoshis >= vtxo.value) {
17502
17748
  continue;
17503
17749
  }
@@ -17912,8 +18158,7 @@ var WalletMessageHandler = class {
17912
18158
  });
17913
18159
  }
17914
18160
  case "GET_TRANSACTION_HISTORY": {
17915
- const allVtxos = await this.getVtxosFromRepo();
17916
- const transactions = await this.buildTransactionHistoryFromCache(allVtxos) ?? [];
18161
+ const transactions = await this.buildTransactionHistoryFromCache() ?? [];
17917
18162
  return this.tagged({
17918
18163
  id,
17919
18164
  type: "TRANSACTION_HISTORY",
@@ -18369,7 +18614,7 @@ var WalletMessageHandler = class {
18369
18614
  // Wallet methods
18370
18615
  async handleInitWallet({ payload }) {
18371
18616
  const { arkServerUrl } = payload;
18372
- this.indexerProvider = new chunkFM263GKH_cjs.RestIndexerProvider(arkServerUrl);
18617
+ this.indexerProvider = new chunkD5DLGVN4_cjs.RestIndexerProvider(arkServerUrl);
18373
18618
  await this.onWalletInitialized();
18374
18619
  }
18375
18620
  /**
@@ -18395,7 +18640,7 @@ var WalletMessageHandler = class {
18395
18640
  unconfirmed += utxo.value;
18396
18641
  }
18397
18642
  }
18398
- const gated = gatedContracts(snapshot.map((_) => _.contract));
18643
+ const gated = gatedFrom(snapshot);
18399
18644
  const unlocked = new Set(
18400
18645
  (await spendableVtxosExcludingLocked(allVtxos, this.readonlyWallet?.intentRepository)).map((vtxo) => `${vtxo.txid}:${vtxo.vout}`)
18401
18646
  );
@@ -18403,7 +18648,7 @@ var WalletMessageHandler = class {
18403
18648
  const offchain = computeOffchainBalance(allVtxos, {
18404
18649
  now: { timestamp: /* @__PURE__ */ new Date() },
18405
18650
  isPendingRecovery: (vtxo) => pendingOutpoints.has(`${vtxo.txid}:${vtxo.vout}`),
18406
- isGenericallySpendable: (vtxo) => !gated.has(vtxo.script),
18651
+ isGenericallySpendable: (vtxo) => !isGatedVtxo(vtxo, gated),
18407
18652
  isUnlocked: (vtxo) => unlocked.has(`${vtxo.txid}:${vtxo.vout}`)
18408
18653
  });
18409
18654
  return {
@@ -18543,7 +18788,6 @@ var WalletMessageHandler = class {
18543
18788
  if (!this.readonlyWallet || !this.walletRepository) {
18544
18789
  return;
18545
18790
  }
18546
- const vtxos = await this.getVtxosFromRepo();
18547
18791
  const boardingAddresses = await this.readonlyWallet.getBoardingAddresses();
18548
18792
  const fresh = await this.readonlyWallet.getBoardingUtxos();
18549
18793
  const freshKeys = new Set(fresh.map((u) => `${u.txid}:${u.vout}`));
@@ -18555,7 +18799,7 @@ var WalletMessageHandler = class {
18555
18799
  if (kept.length > 0) await this.walletRepository.saveUtxos(addr, kept);
18556
18800
  }
18557
18801
  const address = await this.readonlyWallet.getAddress();
18558
- const txs = await this.buildTransactionHistoryFromCache(vtxos);
18802
+ const txs = await this.buildTransactionHistoryFromCache();
18559
18803
  if (txs) await this.walletRepository.saveTransactions(address, txs);
18560
18804
  }
18561
18805
  /**
@@ -18658,7 +18902,7 @@ var WalletMessageHandler = class {
18658
18902
  if (v.isUnrolled) {
18659
18903
  return withUnrolled;
18660
18904
  }
18661
- if (chunk5J5PDZRR_cjs.hasTerminalSpend(v)) {
18905
+ if (chunkKJ5E646Y_cjs.hasTerminalSpend(v)) {
18662
18906
  return false;
18663
18907
  }
18664
18908
  if (includeRecoverable) {
@@ -18667,10 +18911,10 @@ var WalletMessageHandler = class {
18667
18911
  if (dustAmount != null && isSubdust(v, dustAmount)) {
18668
18912
  return false;
18669
18913
  }
18670
- if (chunk5J5PDZRR_cjs.isRecoverable(v)) {
18914
+ if (chunkKJ5E646Y_cjs.isRecoverable(v)) {
18671
18915
  return false;
18672
18916
  }
18673
- if (chunk5J5PDZRR_cjs.isExpired(v)) {
18917
+ if (chunkKJ5E646Y_cjs.isExpired(v)) {
18674
18918
  return false;
18675
18919
  }
18676
18920
  return true;
@@ -18763,13 +19007,29 @@ var WalletMessageHandler = class {
18763
19007
  /**
18764
19008
  * Build transaction history from cached virtual outputs, hitting the indexer only for
18765
19009
  * uncached timestamps. Best-effort, like the plain Wallet path.
18766
- */
18767
- async buildTransactionHistoryFromCache(vtxos) {
19010
+ *
19011
+ * Takes its own {@link repoSnapshot} rather than a caller-supplied VTXO
19012
+ * list: the coins and the gate that judges them have to come off one read
19013
+ * or they answer about different instants, and being the worker's only
19014
+ * history builder means neither caller can supply one without the other.
19015
+ * The snapshot and the boarding read are independent, so they run together
19016
+ * — the same pairing `handleGetBalance` makes.
19017
+ */
19018
+ async buildTransactionHistoryFromCache() {
18768
19019
  if (!this.readonlyWallet) return null;
18769
- const { boardingTxs, commitmentsToIgnore } = await this.readonlyWallet.getBoardingTxs();
19020
+ const [{ snapshot, vtxos }, { boardingTxs, commitmentsToIgnore }] = await Promise.all([
19021
+ this.repoSnapshot(),
19022
+ this.readonlyWallet.getBoardingTxs()
19023
+ ]);
18770
19024
  const indexerProvider = this.indexerProvider;
18771
- const resolveTxCreatedAt = indexerProvider ? (txids) => chunk5J5PDZRR_cjs.fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
18772
- return buildTransactionHistory(vtxos, boardingTxs, commitmentsToIgnore, resolveTxCreatedAt);
19025
+ const resolveTxCreatedAt = indexerProvider ? (txids) => chunkKJ5E646Y_cjs.fetchVtxoCreatedAtByTxid(indexerProvider, txids) : void 0;
19026
+ return buildTransactionHistory(
19027
+ vtxos,
19028
+ boardingTxs,
19029
+ commitmentsToIgnore,
19030
+ resolveTxCreatedAt,
19031
+ gatedFrom(snapshot)
19032
+ );
18773
19033
  }
18774
19034
  async ensureContractEventBroadcasting() {
18775
19035
  const wallet = this.readonlyWallet;
@@ -19470,7 +19730,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
19470
19730
  };
19471
19731
  try {
19472
19732
  const response = await this.sendMessage(message);
19473
- return response.payload.vtxos.map(chunk5J5PDZRR_cjs.normalizeVtxo);
19733
+ return response.payload.vtxos.map(chunkKJ5E646Y_cjs.normalizeVtxo);
19474
19734
  } catch (error) {
19475
19735
  throw new Error(`Failed to get vtxos: ${error}`);
19476
19736
  }
@@ -19495,7 +19755,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
19495
19755
  };
19496
19756
  try {
19497
19757
  const response = await this.sendMessage(message);
19498
- return response.payload.vtxos.map(chunk5J5PDZRR_cjs.normalizeVtxo);
19758
+ return response.payload.vtxos.map(chunkKJ5E646Y_cjs.normalizeVtxo);
19499
19759
  } catch (error) {
19500
19760
  throw new Error(`Failed to get spendable vtxos: ${error}`);
19501
19761
  }
@@ -19666,7 +19926,7 @@ var ServiceWorkerReadonlyWallet = class _ServiceWorkerReadonlyWallet {
19666
19926
  };
19667
19927
  try {
19668
19928
  const response = await sendContractMessage(message);
19669
- return response.payload.vtxos.map(chunk5J5PDZRR_cjs.normalizeVtxo);
19929
+ return response.payload.vtxos.map(chunkKJ5E646Y_cjs.normalizeVtxo);
19670
19930
  } catch (e) {
19671
19931
  throw new Error("Failed to annotate vtxos");
19672
19932
  }
@@ -19865,6 +20125,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
19865
20125
  identity;
19866
20126
  _assetManager;
19867
20127
  hasDelegate;
20128
+ _restoreInFlight;
19868
20129
  get assetManager() {
19869
20130
  return this._assetManager;
19870
20131
  }
@@ -20127,6 +20388,16 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
20127
20388
  * reconstructed here so callers can inspect `.errors`.
20128
20389
  */
20129
20390
  async restore(opts) {
20391
+ if (this._restoreInFlight) return this._restoreInFlight;
20392
+ this._restoreInFlight = (async () => {
20393
+ await this._restoreWorkerWallet(opts);
20394
+ await runWalletRestoreHooks(this);
20395
+ })().finally(() => {
20396
+ this._restoreInFlight = void 0;
20397
+ });
20398
+ return this._restoreInFlight;
20399
+ }
20400
+ async _restoreWorkerWallet(opts) {
20130
20401
  const message = {
20131
20402
  id: getRandomId(),
20132
20403
  tag: this.messageTag,
@@ -20267,7 +20538,7 @@ var ServiceWorkerWallet = class _ServiceWorkerWallet extends ServiceWorkerReadon
20267
20538
  };
20268
20539
  try {
20269
20540
  const response = await wallet.sendMessage(message);
20270
- return response.payload.vtxos.map(chunk5J5PDZRR_cjs.normalizeVtxo);
20541
+ return response.payload.vtxos.map(chunkKJ5E646Y_cjs.normalizeVtxo);
20271
20542
  } catch (e) {
20272
20543
  throw new Error(`Failed to get expiring vtxos: ${e}`);
20273
20544
  }
@@ -20379,12 +20650,12 @@ var OnchainWallet = class _OnchainWallet {
20379
20650
  * @returns Configured onchain wallet
20380
20651
  * @throws Error if the configured identity cannot produce a valid x-only public key
20381
20652
  */
20382
- static async create(identity, networkName = chunk5J5PDZRR_cjs.DEFAULT_NETWORK_NAME, provider) {
20653
+ static async create(identity, networkName = chunkKJ5E646Y_cjs.DEFAULT_NETWORK_NAME, provider) {
20383
20654
  const pubkey = await identity.xOnlyPublicKey();
20384
20655
  if (!pubkey) {
20385
20656
  throw new Error("Invalid configured public key");
20386
20657
  }
20387
- const network = chunk5J5PDZRR_cjs.getNetwork(networkName);
20658
+ const network = chunkKJ5E646Y_cjs.getNetwork(networkName);
20388
20659
  const onchainProvider = provider || new EsploraProvider(ESPLORA_URL[networkName]);
20389
20660
  const onchainP2TR = btcSigner.p2tr(pubkey, void 0, network);
20390
20661
  return new _OnchainWallet(identity, network, onchainP2TR, onchainProvider);
@@ -20490,7 +20761,7 @@ var OnchainWallet = class _OnchainWallet {
20490
20761
  if (!inputs) {
20491
20762
  throw new Error("Fee estimation failed");
20492
20763
  }
20493
- let tx = new chunk5J5PDZRR_cjs.Transaction();
20764
+ let tx = new chunkKJ5E646Y_cjs.Transaction();
20494
20765
  for (const input of inputs) {
20495
20766
  tx.addInput({
20496
20767
  txid: input.txid,
@@ -20548,7 +20819,7 @@ var OnchainWallet = class _OnchainWallet {
20548
20819
  * @throws If the parent has no anchor, or funding cannot be selected/signed
20549
20820
  */
20550
20821
  async bumpAnchor(parentHex, feeRate) {
20551
- const parent = chunk5J5PDZRR_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
20822
+ const parent = chunkKJ5E646Y_cjs.Transaction.fromRaw(base.hex.decode(parentHex));
20552
20823
  const coins = (await this.getCoins()).filter((c) => c.status.confirmed);
20553
20824
  const child = await this.buildBumpPackage(parent, feeRate, coins);
20554
20825
  return [parent.hex, child.hex];
@@ -21455,7 +21726,7 @@ async function resolvePrevTxs(txids, source, onchain) {
21455
21726
  try {
21456
21727
  const { txs } = await source.getVirtualTxs(wanted);
21457
21728
  for (const psbt of txs) {
21458
- const tx = chunk5J5PDZRR_cjs.Transaction.fromPSBT(base.base64.decode(psbt));
21729
+ const tx = chunkKJ5E646Y_cjs.Transaction.fromPSBT(base.base64.decode(psbt));
21459
21730
  resolved.set(tx.id, tx.toBytes());
21460
21731
  }
21461
21732
  } catch (err) {
@@ -21488,7 +21759,7 @@ async function resolvePrevTxs(txids, source, onchain) {
21488
21759
  async function attachPrevArkTxs(tx, txids, source, onchain) {
21489
21760
  const pending = [];
21490
21761
  for (let i = 0; i < tx.inputsLength; i++) {
21491
- if (chunk5J5PDZRR_cjs.getArkPsbtFields(tx, i, chunk5J5PDZRR_cjs.PrevArkTxField).length === 0) pending.push(i);
21762
+ if (chunkKJ5E646Y_cjs.getArkPsbtFields(tx, i, chunkKJ5E646Y_cjs.PrevArkTxField).length === 0) pending.push(i);
21492
21763
  }
21493
21764
  if (pending.length === 0) return;
21494
21765
  const resolved = await resolvePrevTxs(
@@ -21497,13 +21768,13 @@ async function attachPrevArkTxs(tx, txids, source, onchain) {
21497
21768
  onchain
21498
21769
  );
21499
21770
  for (const i of pending) {
21500
- chunk5J5PDZRR_cjs.setArkPsbtField(tx, i, chunk5J5PDZRR_cjs.PrevArkTxField, resolved.get(txidAt(txids, i)));
21771
+ chunkKJ5E646Y_cjs.setArkPsbtField(tx, i, chunkKJ5E646Y_cjs.PrevArkTxField, resolved.get(txidAt(txids, i)));
21501
21772
  }
21502
21773
  }
21503
21774
  async function attachPrevoutTxs(tx, source) {
21504
21775
  const pending = [];
21505
21776
  for (let i = 0; i < tx.inputsLength; i++) {
21506
- if (chunk5J5PDZRR_cjs.getArkPsbtFields(tx, i, chunk5J5PDZRR_cjs.PrevoutTxField).length > 0) continue;
21777
+ if (chunkKJ5E646Y_cjs.getArkPsbtFields(tx, i, chunkKJ5E646Y_cjs.PrevoutTxField).length > 0) continue;
21507
21778
  const input = tx.getInput(i);
21508
21779
  if (!input?.txid) throw new PrevTxUnavailableError(`input ${i} has no outpoint`);
21509
21780
  pending.push({ index: i, txid: base.hex.encode(input.txid) });
@@ -21514,7 +21785,7 @@ async function attachPrevoutTxs(tx, source) {
21514
21785
  resolved.set(txid, await source.getRawTransaction(txid));
21515
21786
  }
21516
21787
  for (const { index, txid } of pending) {
21517
- chunk5J5PDZRR_cjs.setArkPsbtField(tx, index, chunk5J5PDZRR_cjs.PrevoutTxField, resolved.get(txid));
21788
+ chunkKJ5E646Y_cjs.setArkPsbtField(tx, index, chunkKJ5E646Y_cjs.PrevoutTxField, resolved.get(txid));
21518
21789
  }
21519
21790
  }
21520
21791
  async function withPrevTxs(coins, source, onchain) {
@@ -21540,7 +21811,7 @@ exports.BIP322 = void 0;
21540
21811
  async function sign2(message, identity, network) {
21541
21812
  const xOnlyPubKey = await identity.xOnlyPublicKey();
21542
21813
  const payment = btcSigner.p2tr(xOnlyPubKey, void 0, network);
21543
- const toSpend = chunk5J5PDZRR_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
21814
+ const toSpend = chunkKJ5E646Y_cjs.craftToSpendTx(message, payment.script, TAG_BIP322);
21544
21815
  const toSign = craftBIP322ToSignP2TR(toSpend, payment.script, xOnlyPubKey);
21545
21816
  const signed = await identity.sign(toSign, [0]);
21546
21817
  signed.finalizeIdx(0);
@@ -21598,7 +21869,7 @@ function verifyP2TR(message, witnessItems, pkScript, pubkey) {
21598
21869
  if (sighashType !== btcSigner.SigHash.DEFAULT && sighashType !== btcSigner.SigHash.ALL) {
21599
21870
  return false;
21600
21871
  }
21601
- const toSpend = chunk5J5PDZRR_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
21872
+ const toSpend = chunkKJ5E646Y_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
21602
21873
  const toSign = craftBIP322ToSignP2TR(toSpend, pkScript, pubkey);
21603
21874
  const sighash = toSign.preimageWitnessV1(0, [pkScript], sighashType, [0n]);
21604
21875
  const rawSig = sig.length === 65 ? sig.subarray(0, 64) : sig;
@@ -21619,7 +21890,7 @@ function verifyP2WPKH(message, witnessItems, pkScript, addressHash) {
21619
21890
  }
21620
21891
  const sighashType = sigWithHash[sigWithHash.length - 1];
21621
21892
  const derSig = sigWithHash.subarray(0, sigWithHash.length - 1);
21622
- const toSpend = chunk5J5PDZRR_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
21893
+ const toSpend = chunkKJ5E646Y_cjs.craftToSpendTx(message, pkScript, TAG_BIP322);
21623
21894
  const toSign = craftBIP322ToSignSimple(toSpend, pkScript);
21624
21895
  const scriptCode = btcSigner.OutScript.encode({ type: "pkh", hash: addressHash });
21625
21896
  const sighash = toSign.preimageWitnessV0(0, scriptCode, sighashType, 0n);
@@ -21672,7 +21943,7 @@ function encodeCompactSize(n) {
21672
21943
  return buf;
21673
21944
  }
21674
21945
  function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
21675
- const tx = new chunk5J5PDZRR_cjs.Transaction({ version: 0 });
21946
+ const tx = new chunkKJ5E646Y_cjs.Transaction({ version: 0 });
21676
21947
  tx.addInput({
21677
21948
  txid: toSpend.id,
21678
21949
  index: 0,
@@ -21686,12 +21957,12 @@ function craftBIP322ToSignP2TR(toSpend, pkScript, tapInternalKey) {
21686
21957
  });
21687
21958
  tx.addOutput({
21688
21959
  amount: 0n,
21689
- script: chunk5J5PDZRR_cjs.OP_RETURN_EMPTY_PKSCRIPT
21960
+ script: chunkKJ5E646Y_cjs.OP_RETURN_EMPTY_PKSCRIPT
21690
21961
  });
21691
21962
  return tx;
21692
21963
  }
21693
21964
  function craftBIP322ToSignSimple(toSpend, pkScript) {
21694
- const tx = new chunk5J5PDZRR_cjs.Transaction({ version: 0 });
21965
+ const tx = new chunkKJ5E646Y_cjs.Transaction({ version: 0 });
21695
21966
  tx.addInput({
21696
21967
  txid: toSpend.id,
21697
21968
  index: 0,
@@ -21703,7 +21974,7 @@ function craftBIP322ToSignSimple(toSpend, pkScript) {
21703
21974
  });
21704
21975
  tx.addOutput({
21705
21976
  amount: 0n,
21706
- script: chunk5J5PDZRR_cjs.OP_RETURN_EMPTY_PKSCRIPT
21977
+ script: chunkKJ5E646Y_cjs.OP_RETURN_EMPTY_PKSCRIPT
21707
21978
  });
21708
21979
  return tx;
21709
21980
  }
@@ -21716,7 +21987,7 @@ var RestEmulatorProvider = class {
21716
21987
  serverUrl;
21717
21988
  async getInfo() {
21718
21989
  const url = `${this.serverUrl}/v1/info`;
21719
- const response = await fetch(url);
21990
+ const response = await chunkKJ5E646Y_cjs.baseFetch(url);
21720
21991
  if (!response.ok) {
21721
21992
  const errorText2 = await response.text();
21722
21993
  throw new Error(`Failed to get emulator info: ${errorText2}`);
@@ -21834,7 +22105,7 @@ var RestEmulatorProvider = class {
21834
22105
  }
21835
22106
  };
21836
22107
  function finalizeVirtualTx(type, psbtBase64) {
21837
- const tx = chunk5J5PDZRR_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
22108
+ const tx = chunkKJ5E646Y_cjs.Transaction.fromPSBT(base.base64.decode(psbtBase64));
21838
22109
  if (type === "INDEXER_CHAINED_TX_TYPE_TREE" /* TREE */) {
21839
22110
  const input = tx.getInput(0);
21840
22111
  if (!input) {
@@ -21861,14 +22132,14 @@ var ExitPathError = class extends Error {
21861
22132
  reason;
21862
22133
  };
21863
22134
  function delayWeight(sequence) {
21864
- const t = chunk5J5PDZRR_cjs.sequenceToTimelock(sequence);
22135
+ const t = chunkKJ5E646Y_cjs.sequenceToTimelock(sequence);
21865
22136
  return t.type === "blocks" ? Number(t.value) : Number(t.value) / 600;
21866
22137
  }
21867
22138
  async function resolveUnilateralPath(params) {
21868
22139
  const { vtxo, scriptHex, contractRepository } = params;
21869
22140
  const contract = contractRepository ? (await contractRepository.getContracts({ script: scriptHex }))[0] : void 0;
21870
22141
  if (contract) {
21871
- const handler = chunkP6EXRY5L_cjs.contractHandlers.get(contract.type);
22142
+ const handler = chunk2D7F5IU3_cjs.contractHandlers.get(contract.type);
21872
22143
  if (!handler) {
21873
22144
  throw new ExitPathError(
21874
22145
  "no-handler",
@@ -21891,12 +22162,12 @@ async function resolveUnilateralPath(params) {
21891
22162
  paths.sort((a, b) => delayWeight(a.sequence) - delayWeight(b.sequence));
21892
22163
  return { selection: paths[0], label: `${contract.type}:unilateral` };
21893
22164
  }
21894
- const decoded = chunk5J5PDZRR_cjs.VtxoScript.decode(vtxo.tapTree);
22165
+ const decoded = chunkKJ5E646Y_cjs.VtxoScript.decode(vtxo.tapTree);
21895
22166
  let best;
21896
22167
  for (const exit of decoded.exitPaths()) {
21897
22168
  const leaf = decoded.findLeaf(base.hex.encode(exit.script));
21898
22169
  if (!leaf) continue;
21899
- const sequence = chunk5J5PDZRR_cjs.timelockToSequence(exit.params.timelock);
22170
+ const sequence = chunkKJ5E646Y_cjs.timelockToSequence(exit.params.timelock);
21900
22171
  const weight = delayWeight(sequence);
21901
22172
  if (!best || weight < best.weight) {
21902
22173
  best = { selection: { leaf, sequence }, weight };
@@ -22116,7 +22387,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
22116
22387
  let totalAmount = 0n;
22117
22388
  const txWeightEstimator = TxWeightEstimator.create();
22118
22389
  for (const vtxo of vtxos) {
22119
- if (!chunk5J5PDZRR_cjs.canSweepOnchain(vtxo)) {
22390
+ if (!chunkKJ5E646Y_cjs.canSweepOnchain(vtxo)) {
22120
22391
  throw new Error(
22121
22392
  `Vtxo ${vtxo.txid}:${vtxo.vout} cannot be swept onchain: it is not fully unrolled (use unroll first), or its exit output was already spent`
22122
22393
  );
@@ -22127,14 +22398,14 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
22127
22398
  }
22128
22399
  const resolved = await resolveUnilateralPath({
22129
22400
  vtxo,
22130
- scriptHex: base.hex.encode(chunk5J5PDZRR_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
22401
+ scriptHex: base.hex.encode(chunkKJ5E646Y_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
22131
22402
  contractRepository: wallet.contractRepository,
22132
22403
  walletPubKeyHex: base.hex.encode(await wallet.identity.xOnlyPublicKey()),
22133
22404
  currentTime: Date.now()
22134
22405
  });
22135
22406
  const spendingLeaf = resolved.selection.leaf;
22136
22407
  const sequence = resolved.selection.sequence;
22137
- const timelock = chunk5J5PDZRR_cjs.sequenceToTimelock(sequence);
22408
+ const timelock = chunkKJ5E646Y_cjs.sequenceToTimelock(sequence);
22138
22409
  const elapsed = timelock.type === "blocks" ? chainTip.height >= txStatus.blockHeight + Number(timelock.value) : chainTip.time >= txStatus.blockTime + Number(timelock.value);
22139
22410
  if (!elapsed) {
22140
22411
  throw new Error(`no available exit path found for vtxo ${vtxo.txid}:${vtxo.vout}`);
@@ -22147,7 +22418,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
22147
22418
  sequence,
22148
22419
  witnessUtxo: {
22149
22420
  amount: BigInt(vtxo.value),
22150
- script: chunk5J5PDZRR_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
22421
+ script: chunkKJ5E646Y_cjs.VtxoScript.decode(vtxo.tapTree).pkScript
22151
22422
  },
22152
22423
  sighashType: btcSigner.SigHash.DEFAULT
22153
22424
  });
@@ -22157,7 +22428,7 @@ async function prepareUnrollTransaction(wallet, vtxoTxIds, outputAddress) {
22157
22428
  btcSigner.TaprootControlBlock.encode(spendingLeaf[0]).length
22158
22429
  );
22159
22430
  }
22160
- const tx = new chunk5J5PDZRR_cjs.Transaction({ version: 2 });
22431
+ const tx = new chunkKJ5E646Y_cjs.Transaction({ version: 2 });
22161
22432
  for (const input of inputs) {
22162
22433
  tx.addInput(input);
22163
22434
  }
@@ -22240,7 +22511,7 @@ async function buildSignedSweep(params) {
22240
22511
  `uneconomic vtxo ${vtxo.txid}:${vtxo.vout}: value ${vtxo.value} - fee ${fee} < dust`
22241
22512
  );
22242
22513
  }
22243
- const tx = new chunk5J5PDZRR_cjs.Transaction({ version: 2 });
22514
+ const tx = new chunkKJ5E646Y_cjs.Transaction({ version: 2 });
22244
22515
  tx.addInput({
22245
22516
  txid: vtxo.txid,
22246
22517
  index: vtxo.vout,
@@ -22265,7 +22536,7 @@ async function buildSignedSweep(params) {
22265
22536
  finalScriptWitness: [
22266
22537
  tapScriptSig[0][1],
22267
22538
  ...path.extraWitness,
22268
- chunk5J5PDZRR_cjs.scriptFromTapLeafScript(path.leaf),
22539
+ chunkKJ5E646Y_cjs.scriptFromTapLeafScript(path.leaf),
22269
22540
  btcSigner.TaprootControlBlock.encode(controlBlock)
22270
22541
  ]
22271
22542
  });
@@ -22295,7 +22566,7 @@ async function resolveFeeRate(opts) {
22295
22566
  }
22296
22567
  async function selectExitVtxos(opts) {
22297
22568
  if (!opts.vtxos) return opts.wallet.getVtxos();
22298
- const res = await chunk5J5PDZRR_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
22569
+ const res = await chunkKJ5E646Y_cjs.getNormalizedVtxos(opts.wallet.indexerProvider, { outpoints: opts.vtxos });
22299
22570
  const tapTrees = /* @__PURE__ */ new Map();
22300
22571
  const out = [];
22301
22572
  for (const vtxo of res.vtxos) {
@@ -22310,7 +22581,7 @@ async function selectExitVtxos(opts) {
22310
22581
  `no contract registered for vtxo script ${vtxo.script} \u2014 register the contract before exiting`
22311
22582
  );
22312
22583
  }
22313
- const handler = chunkP6EXRY5L_cjs.contractHandlers.get(contract.type);
22584
+ const handler = chunk2D7F5IU3_cjs.contractHandlers.get(contract.type);
22314
22585
  if (!handler) {
22315
22586
  throw new Error(`no contract handler registered for type '${contract.type}'`);
22316
22587
  }
@@ -22340,7 +22611,7 @@ async function computeExitLayout(opts, feeRate) {
22340
22611
  if (pendingNodes.length > 0) {
22341
22612
  const txs = await resolver.getVirtualTxs(pendingNodes.map((n) => n.txid));
22342
22613
  for (const psbt of txs) {
22343
- psbts.set(chunk5J5PDZRR_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
22614
+ psbts.set(chunkKJ5E646Y_cjs.Transaction.fromPSBT(base.base64.decode(psbt)).id, psbt);
22344
22615
  }
22345
22616
  }
22346
22617
  const childVsize = Number(
@@ -22376,7 +22647,7 @@ async function computeExitLayout(opts, feeRate) {
22376
22647
  try {
22377
22648
  const resolved = await resolveUnilateralPath({
22378
22649
  vtxo,
22379
- scriptHex: base.hex.encode(chunk5J5PDZRR_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
22650
+ scriptHex: base.hex.encode(chunkKJ5E646Y_cjs.VtxoScript.decode(vtxo.tapTree).pkScript),
22380
22651
  contractRepository: wallet.contractRepository,
22381
22652
  walletPubKeyHex,
22382
22653
  currentTime: Date.now()
@@ -22395,7 +22666,7 @@ async function computeExitLayout(opts, feeRate) {
22395
22666
  });
22396
22667
  continue;
22397
22668
  }
22398
- const t = chunk5J5PDZRR_cjs.sequenceToTimelock(resolved.selection.sequence);
22669
+ const t = chunkKJ5E646Y_cjs.sequenceToTimelock(resolved.selection.sequence);
22399
22670
  const delay = { type: t.type, value: Number(t.value) };
22400
22671
  infos.push({ outpoint, value: vtxo.value, sweepFee, path: resolved.label, delay });
22401
22672
  sweeps.push({ vtxo, resolved, sweepFee, delay });
@@ -22796,7 +23067,7 @@ async function prepare(opts) {
22796
23067
  txid: sweep.vtxo.txid,
22797
23068
  vout: sweep.vtxo.vout,
22798
23069
  value: sweep.vtxo.value,
22799
- pkScript: chunk5J5PDZRR_cjs.VtxoScript.decode(sweep.vtxo.tapTree).pkScript
23070
+ pkScript: chunkKJ5E646Y_cjs.VtxoScript.decode(sweep.vtxo.tapTree).pkScript
22800
23071
  },
22801
23072
  path: sweep.resolved.selection,
22802
23073
  outputAddress: opts.sweepAddress,
@@ -22884,7 +23155,7 @@ async function prepare(opts) {
22884
23155
  if (newFee <= splitterFee) break;
22885
23156
  splitterFee = newFee;
22886
23157
  }
22887
- const splitter = new chunk5J5PDZRR_cjs.Transaction({ version: 2 });
23158
+ const splitter = new chunkKJ5E646Y_cjs.Transaction({ version: 2 });
22888
23159
  for (const coin of selected.inputs) {
22889
23160
  splitter.addInput({
22890
23161
  txid: coin.txid,
@@ -23028,41 +23299,41 @@ var UnilateralExit = {
23028
23299
  // src/arkade/index.ts
23029
23300
  var arkade_exports = {};
23030
23301
  chunk5BLDMQED_cjs.__export(arkade_exports, {
23031
- ARKADE_OP: () => chunkP6EXRY5L_cjs.ARKADE_OP,
23032
- ARKADE_OPCODES: () => chunkP6EXRY5L_cjs.ARKADE_OPCODES,
23033
- ARKADE_OPCODE_NAMES: () => chunkP6EXRY5L_cjs.ARKADE_OPCODE_NAMES,
23034
- ARKADE_OPCODE_VALUES: () => chunkP6EXRY5L_cjs.ARKADE_OPCODE_VALUES,
23035
- ARKADE_OPS: () => chunkP6EXRY5L_cjs.ARKADE_OPS,
23302
+ ARKADE_OP: () => chunk2D7F5IU3_cjs.ARKADE_OP,
23303
+ ARKADE_OPCODES: () => chunk2D7F5IU3_cjs.ARKADE_OPCODES,
23304
+ ARKADE_OPCODE_NAMES: () => chunk2D7F5IU3_cjs.ARKADE_OPCODE_NAMES,
23305
+ ARKADE_OPCODE_VALUES: () => chunk2D7F5IU3_cjs.ARKADE_OPCODE_VALUES,
23306
+ ARKADE_OPS: () => chunk2D7F5IU3_cjs.ARKADE_OPS,
23036
23307
  Arkade: () => Arkade,
23037
23308
  ArkadeContract: () => ArkadeContract,
23038
- ArkadeProgramScript: () => chunkP6EXRY5L_cjs.ArkadeProgramScript,
23039
- ArkadeScript: () => chunkP6EXRY5L_cjs.ArkadeScript,
23309
+ ArkadeProgramScript: () => chunk2D7F5IU3_cjs.ArkadeProgramScript,
23310
+ ArkadeScript: () => chunk2D7F5IU3_cjs.ArkadeScript,
23040
23311
  ArkadeTransactionBuilder: () => ArkadeTransactionBuilder,
23041
- BigNum: () => chunkP6EXRY5L_cjs.bignum_exports,
23312
+ BigNum: () => chunk2D7F5IU3_cjs.bignum_exports,
23042
23313
  OP: () => btcSigner.OP,
23043
- OPCODE_NAMES: () => chunkP6EXRY5L_cjs.OPCODE_NAMES,
23044
- OPCODE_VALUES: () => chunkP6EXRY5L_cjs.OPCODE_VALUES,
23045
- SUPPORTED_PROGRAM_VERSION: () => chunkP6EXRY5L_cjs.SUPPORTED_PROGRAM_VERSION,
23314
+ OPCODE_NAMES: () => chunk2D7F5IU3_cjs.OPCODE_NAMES,
23315
+ OPCODE_VALUES: () => chunk2D7F5IU3_cjs.OPCODE_VALUES,
23316
+ SUPPORTED_PROGRAM_VERSION: () => chunk2D7F5IU3_cjs.SUPPORTED_PROGRAM_VERSION,
23046
23317
  Script: () => btcSigner.Script,
23047
- arkadeScriptHash: () => chunkP6EXRY5L_cjs.arkadeScriptHash,
23048
- arkadeWitnessHash: () => chunkP6EXRY5L_cjs.arkadeWitnessHash,
23049
- asmToBytes: () => chunkP6EXRY5L_cjs.asmToBytes,
23050
- bytesToASM: () => chunkP6EXRY5L_cjs.bytesToASM,
23051
- computeArkadeScriptPublicKey: () => chunkP6EXRY5L_cjs.computeArkadeScriptPublicKey,
23318
+ arkadeScriptHash: () => chunk2D7F5IU3_cjs.arkadeScriptHash,
23319
+ arkadeWitnessHash: () => chunk2D7F5IU3_cjs.arkadeWitnessHash,
23320
+ asmToBytes: () => chunk2D7F5IU3_cjs.asmToBytes,
23321
+ bytesToASM: () => chunk2D7F5IU3_cjs.bytesToASM,
23322
+ computeArkadeScriptPublicKey: () => chunk2D7F5IU3_cjs.computeArkadeScriptPublicKey,
23052
23323
  createArkadeBatchHandler: () => createArkadeBatchHandler,
23053
- deserializeArkadeContractParams: () => chunkP6EXRY5L_cjs.deserializeArkadeContractParams,
23054
- fromASM: () => chunkP6EXRY5L_cjs.fromASM,
23055
- getOpcodeName: () => chunkP6EXRY5L_cjs.getOpcodeName,
23056
- getOpcodeValue: () => chunkP6EXRY5L_cjs.getOpcodeValue,
23057
- parseArtifact: () => chunkP6EXRY5L_cjs.parseArtifact,
23058
- resolveAsm: () => chunkP6EXRY5L_cjs.resolveAsm,
23059
- serializeArkadeContractParams: () => chunkP6EXRY5L_cjs.serializeArkadeContractParams,
23060
- stringifyArtifact: () => chunkP6EXRY5L_cjs.stringifyArtifact,
23061
- toASM: () => chunkP6EXRY5L_cjs.toASM,
23062
- validateProgram: () => chunkP6EXRY5L_cjs.validateProgram,
23063
- witnessRefToBytes: () => chunkP6EXRY5L_cjs.witnessRefToBytes
23324
+ deserializeArkadeContractParams: () => chunk2D7F5IU3_cjs.deserializeArkadeContractParams,
23325
+ fromASM: () => chunk2D7F5IU3_cjs.fromASM,
23326
+ getOpcodeName: () => chunk2D7F5IU3_cjs.getOpcodeName,
23327
+ getOpcodeValue: () => chunk2D7F5IU3_cjs.getOpcodeValue,
23328
+ parseArtifact: () => chunk2D7F5IU3_cjs.parseArtifact,
23329
+ resolveAsm: () => chunk2D7F5IU3_cjs.resolveAsm,
23330
+ serializeArkadeContractParams: () => chunk2D7F5IU3_cjs.serializeArkadeContractParams,
23331
+ stringifyArtifact: () => chunk2D7F5IU3_cjs.stringifyArtifact,
23332
+ toASM: () => chunk2D7F5IU3_cjs.toASM,
23333
+ validateProgram: () => chunk2D7F5IU3_cjs.validateProgram,
23334
+ witnessRefToBytes: () => chunk2D7F5IU3_cjs.witnessRefToBytes
23064
23335
  });
23065
- var isVtxoCoin = (input) => chunk5J5PDZRR_cjs.isVirtualCoin(input);
23336
+ var isVtxoCoin = (input) => chunkKJ5E646Y_cjs.isVirtualCoin(input);
23066
23337
  function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message, session, arkProvider, emulator, network, recipients, batchExpiryPolicy) {
23067
23338
  let batchId;
23068
23339
  let sweepTapTreeRoot;
@@ -23083,26 +23354,32 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
23083
23354
  );
23084
23355
  await arkProvider.confirmRegistration(intentId);
23085
23356
  batchId = event.id;
23086
- const sweepTapscript = chunk5J5PDZRR_cjs.CSVMultisigTapscript.encode({
23357
+ const sweepTapscript = chunkKJ5E646Y_cjs.CSVMultisigTapscript.encode({
23087
23358
  timelock,
23088
- pubkeys: [chunkP6EXRY5L_cjs.toXOnly(base.hex.decode(info.forfeitPubkey), "forfeit key")]
23359
+ pubkeys: [chunk2D7F5IU3_cjs.toXOnly(base.hex.decode(info.forfeitPubkey), "forfeit key")]
23089
23360
  }).script;
23090
23361
  sweepTapTreeRoot = payment_js.tapLeafHash(sweepTapscript);
23091
23362
  return { skip: false };
23092
23363
  },
23093
23364
  onTreeSigningStarted: async (event, vtxoTree) => {
23094
23365
  const signerPubKey = await session.getPublicKey();
23095
- const xonlySignerPubKey = chunkP6EXRY5L_cjs.toXOnly(signerPubKey, "signer key");
23366
+ const xonlySignerPubKey = chunk2D7F5IU3_cjs.toXOnly(signerPubKey, "signer key");
23096
23367
  const xOnlyPubkeys = event.cosignersPublicKeys.map(
23097
- (k) => base.hex.encode(chunkP6EXRY5L_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
23368
+ (k) => base.hex.encode(chunk2D7F5IU3_cjs.toXOnly(base.hex.decode(k), "cosigner key"))
23098
23369
  );
23099
23370
  if (!xOnlyPubkeys.includes(base.hex.encode(xonlySignerPubKey))) {
23100
23371
  return { skip: true };
23101
23372
  }
23102
- const commitmentTx = chunk5J5PDZRR_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
23373
+ const commitmentTx = chunkKJ5E646Y_cjs.Transaction.fromPSBT(base.base64.decode(event.unsignedCommitmentTx));
23103
23374
  validateVtxoTxGraph(vtxoTree, commitmentTx, sweepTapTreeRoot);
23104
23375
  if (recipients && recipients.length > 0) {
23105
23376
  validateBatchRecipients(commitmentTx, vtxoTree.leaves(), recipients, network);
23377
+ } else {
23378
+ validateBatchAgainstIntent(
23379
+ commitmentTx,
23380
+ vtxoTree.leaves(),
23381
+ declaredIntentOutputs(signedProof, message.onchain_output_indexes)
23382
+ );
23106
23383
  }
23107
23384
  const sharedOutput = commitmentTx.getOutput(0);
23108
23385
  if (!sharedOutput?.amount) {
@@ -23131,14 +23408,21 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
23131
23408
  if (connectorTree) {
23132
23409
  validateConnectorsTxGraph(event.commitmentTx, connectorTree);
23133
23410
  }
23134
- let commitmentPsbt = chunk5J5PDZRR_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
23411
+ let commitmentPsbt = chunkKJ5E646Y_cjs.Transaction.fromPSBT(base.base64.decode(event.commitmentTx));
23135
23412
  assertFinalCommitmentMatchesValidated(
23136
23413
  commitmentPsbt,
23137
23414
  validatedCommitmentTxid,
23138
23415
  "arkade batch finalization"
23139
23416
  );
23140
- if (!validatedCommitmentTxid && recipients && recipients.length > 0) {
23141
- validateBatchRecipientsWithoutTree(commitmentPsbt, recipients, network);
23417
+ if (!validatedCommitmentTxid) {
23418
+ if (recipients && recipients.length > 0) {
23419
+ validateBatchRecipientsWithoutTree(commitmentPsbt, recipients, network);
23420
+ } else {
23421
+ validateBatchAgainstIntentWithoutTree(
23422
+ commitmentPsbt,
23423
+ declaredIntentOutputs(signedProof, message.onchain_output_indexes)
23424
+ );
23425
+ }
23142
23426
  }
23143
23427
  const signedForfeits = [];
23144
23428
  let connectorIndex = 0;
@@ -23166,7 +23450,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
23166
23450
  boardingIndices.push(boardingIdx);
23167
23451
  continue;
23168
23452
  }
23169
- if (chunk5J5PDZRR_cjs.isRecoverable(input) || isSubdust(input, info.dust)) {
23453
+ if (chunkKJ5E646Y_cjs.isRecoverable(input) || isSubdust(input, info.dust)) {
23170
23454
  continue;
23171
23455
  }
23172
23456
  if (connectorIndex >= connectorLeaves.length) {
@@ -23187,7 +23471,7 @@ function createArkadeBatchHandler(intentId, inputs, signer, signedProof, message
23187
23471
  index: input.vout,
23188
23472
  witnessUtxo: {
23189
23473
  amount: BigInt(input.value),
23190
- script: chunk5J5PDZRR_cjs.VtxoScript.decode(input.tapTree).pkScript
23474
+ script: chunkKJ5E646Y_cjs.VtxoScript.decode(input.tapTree).pkScript
23191
23475
  },
23192
23476
  sighashType: btcSigner.SigHash.DEFAULT,
23193
23477
  tapLeafScript: [input.forfeitTapLeafScript]
@@ -23278,16 +23562,16 @@ var Arkade = class _Arkade {
23278
23562
  /** Connect and resolve the server key, checkpoint closure and (if present) the co-signer key. */
23279
23563
  static async connect(opts) {
23280
23564
  const info = await opts.arkade.getInfo();
23281
- const serverKey = chunkP6EXRY5L_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
23282
- const checkpoint = chunk5J5PDZRR_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
23283
- const network = opts.network ?? chunk5J5PDZRR_cjs.DEFAULT_NETWORK;
23565
+ const serverKey = chunk2D7F5IU3_cjs.toXOnly(base.hex.decode(info.signerPubkey), "ark signer key");
23566
+ const checkpoint = chunkKJ5E646Y_cjs.CSVMultisigTapscript.decode(base.hex.decode(info.checkpointTapscript));
23567
+ const network = opts.network ?? chunkKJ5E646Y_cjs.DEFAULT_NETWORK;
23284
23568
  let emulatorKey;
23285
23569
  if (opts.emulator) {
23286
- emulatorKey = base.hex.decode(chunk5J5PDZRR_cjs.resolveEmulatorPubkey(network, opts.emulatorPubkey));
23570
+ emulatorKey = base.hex.decode(chunkKJ5E646Y_cjs.resolveEmulatorPubkey(network, opts.emulatorPubkey));
23287
23571
  }
23288
23572
  let userKey;
23289
23573
  if (opts.identity) {
23290
- userKey = chunkP6EXRY5L_cjs.toXOnly(await opts.identity.xOnlyPublicKey(), "identity key");
23574
+ userKey = chunk2D7F5IU3_cjs.toXOnly(await opts.identity.xOnlyPublicKey(), "identity key");
23291
23575
  }
23292
23576
  return new _Arkade({
23293
23577
  arkProvider: opts.arkade,
@@ -23313,7 +23597,7 @@ var Arkade = class _Arkade {
23313
23597
  * key respectively; explicit args always win.
23314
23598
  */
23315
23599
  contract(program, args = {}) {
23316
- const declared = (program.params ?? []).map(chunkP6EXRY5L_cjs.inputName);
23600
+ const declared = (program.params ?? []).map(chunk2D7F5IU3_cjs.inputName);
23317
23601
  if (declared.includes("server") && args.server === void 0) {
23318
23602
  args = { ...args, server: this.serverKey };
23319
23603
  }
@@ -23333,7 +23617,7 @@ var ArkadeContract = class _ArkadeContract {
23333
23617
  userKey: client.userKey,
23334
23618
  emulatorKey: client.emulatorKey
23335
23619
  };
23336
- this.vtxoScript = new chunkP6EXRY5L_cjs.ArkadeProgramScript(program, args, this.keys);
23620
+ this.vtxoScript = new chunk2D7F5IU3_cjs.ArkadeProgramScript(program, args, this.keys);
23337
23621
  this.tapTree = this.vtxoScript.encode();
23338
23622
  this.compiled = this.vtxoScript.compiled;
23339
23623
  }
@@ -23361,7 +23645,7 @@ var ArkadeContract = class _ArkadeContract {
23361
23645
  `ArkadeContract.fromContract: expected contract type 'arkade', got '${contract.type}'`
23362
23646
  );
23363
23647
  }
23364
- const typed = chunkP6EXRY5L_cjs.deserializeArkadeContractParams(contract.params);
23648
+ const typed = chunk2D7F5IU3_cjs.deserializeArkadeContractParams(contract.params);
23365
23649
  return new _ArkadeContract(client, typed.program, typed.args, {
23366
23650
  serverKey: typed.serverKey,
23367
23651
  userKey: typed.userKey,
@@ -23402,7 +23686,7 @@ var ArkadeContract = class _ArkadeContract {
23402
23686
  toContractParams() {
23403
23687
  return {
23404
23688
  type: "arkade",
23405
- params: chunkP6EXRY5L_cjs.serializeArkadeContractParams({
23689
+ params: chunk2D7F5IU3_cjs.serializeArkadeContractParams({
23406
23690
  program: this.program,
23407
23691
  args: this.args,
23408
23692
  serverKey: this.keys.serverKey,
@@ -23452,18 +23736,18 @@ var ArkadeContract = class _ArkadeContract {
23452
23736
  if (registered) {
23453
23737
  const [withVtxos] = await manager.getContractsWithVtxos({ script: scriptHex });
23454
23738
  return (withVtxos?.vtxos ?? []).filter(
23455
- (v) => !chunk5J5PDZRR_cjs.hasTerminalSpend(v) && !v.isUnrolled
23739
+ (v) => !chunkKJ5E646Y_cjs.hasTerminalSpend(v) && !v.isUnrolled
23456
23740
  );
23457
23741
  }
23458
23742
  }
23459
23743
  if (!this.client.indexer) {
23460
23744
  throw new Error("ArkadeContract.getUtxos: an indexer is required");
23461
23745
  }
23462
- const { vtxos } = await chunk5J5PDZRR_cjs.getNormalizedVtxos(this.client.indexer, {
23746
+ const { vtxos } = await chunkKJ5E646Y_cjs.getNormalizedVtxos(this.client.indexer, {
23463
23747
  scripts: [scriptHex],
23464
23748
  spendableOnly: true
23465
23749
  });
23466
- return vtxos.filter((v) => !chunk5J5PDZRR_cjs.hasTerminalSpend(v) && !v.isUnrolled);
23750
+ return vtxos.filter((v) => !chunkKJ5E646Y_cjs.hasTerminalSpend(v) && !v.isUnrolled);
23467
23751
  }
23468
23752
  /** Total spendable balance (requires an indexer). */
23469
23753
  async getBalance() {
@@ -23561,7 +23845,7 @@ var ArkadeTransactionBuilder = class {
23561
23845
  this.contract.client.checkpoint
23562
23846
  );
23563
23847
  if (coin.sourceTx) {
23564
- chunk5J5PDZRR_cjs.setArkPsbtField(arkTx, 0, chunk5J5PDZRR_cjs.PrevArkTxField, coin.sourceTx);
23848
+ chunkKJ5E646Y_cjs.setArkPsbtField(arkTx, 0, chunkKJ5E646Y_cjs.PrevArkTxField, coin.sourceTx);
23565
23849
  }
23566
23850
  if (this.fn.arkadeScript) {
23567
23851
  const indexer = this.contract.client.indexer;
@@ -23578,8 +23862,8 @@ var ArkadeTransactionBuilder = class {
23578
23862
  }
23579
23863
  const condition = (def.tapscript.witness ?? []).map((w) => this.witnessBytes(w));
23580
23864
  if (condition.length > 0) {
23581
- chunk5J5PDZRR_cjs.setArkPsbtField(arkTx, 0, chunk5J5PDZRR_cjs.ConditionWitness, condition);
23582
- chunk5J5PDZRR_cjs.setArkPsbtField(checkpoints[0], 0, chunk5J5PDZRR_cjs.ConditionWitness, condition);
23865
+ chunkKJ5E646Y_cjs.setArkPsbtField(arkTx, 0, chunkKJ5E646Y_cjs.ConditionWitness, condition);
23866
+ chunkKJ5E646Y_cjs.setArkPsbtField(checkpoints[0], 0, chunkKJ5E646Y_cjs.ConditionWitness, condition);
23583
23867
  }
23584
23868
  const packets = [];
23585
23869
  if (this.assetSpecs.length > 0) {
@@ -23618,7 +23902,7 @@ var ArkadeTransactionBuilder = class {
23618
23902
  base.base64.encode(signedArk2.toPSBT()),
23619
23903
  signedCps.map((c) => base.base64.encode(c.toPSBT()))
23620
23904
  );
23621
- const txid = chunk5J5PDZRR_cjs.Transaction.fromPSBT(base.base64.decode(res2.signedArkTx)).id;
23905
+ const txid = chunkKJ5E646Y_cjs.Transaction.fromPSBT(base.base64.decode(res2.signedArkTx)).id;
23622
23906
  return {
23623
23907
  txid,
23624
23908
  signedArkTx: res2.signedArkTx,
@@ -23677,23 +23961,23 @@ var ArkadeTransactionBuilder = class {
23677
23961
  }
23678
23962
  buildAssetPacket() {
23679
23963
  const groups = this.assetSpecs.map((s) => {
23680
- const id = typeof s.assetId === "string" ? chunkFM263GKH_cjs.AssetId.fromString(s.assetId) : chunkFM263GKH_cjs.AssetId.fromBytes(s.assetId);
23681
- return chunkFM263GKH_cjs.AssetGroup.create(
23964
+ const id = typeof s.assetId === "string" ? chunkD5DLGVN4_cjs.AssetId.fromString(s.assetId) : chunkD5DLGVN4_cjs.AssetId.fromBytes(s.assetId);
23965
+ return chunkD5DLGVN4_cjs.AssetGroup.create(
23682
23966
  id,
23683
23967
  null,
23684
- s.inputs.map((i) => chunkFM263GKH_cjs.AssetInput.create(i.vin, i.amount)),
23685
- s.outputs.map((o) => chunkFM263GKH_cjs.AssetOutput.create(o.vout, o.amount)),
23686
- (s.metadata ?? []).map((m) => chunkFM263GKH_cjs.Metadata.create(m.key, m.value))
23968
+ s.inputs.map((i) => chunkD5DLGVN4_cjs.AssetInput.create(i.vin, i.amount)),
23969
+ s.outputs.map((o) => chunkD5DLGVN4_cjs.AssetOutput.create(o.vout, o.amount)),
23970
+ (s.metadata ?? []).map((m) => chunkD5DLGVN4_cjs.Metadata.create(m.key, m.value))
23687
23971
  );
23688
23972
  });
23689
- return chunkFM263GKH_cjs.Packet.create(groups);
23973
+ return chunkD5DLGVN4_cjs.Packet.create(groups);
23690
23974
  }
23691
23975
  witnessBytes(ref) {
23692
- return chunkP6EXRY5L_cjs.witnessRefToBytes(ref, this.args, this.contract.args);
23976
+ return chunk2D7F5IU3_cjs.witnessRefToBytes(ref, this.args, this.contract.args);
23693
23977
  }
23694
23978
  };
23695
23979
  function bindInputs(fn, callArgs) {
23696
- const names = (fn.def.inputs ?? []).map(chunkP6EXRY5L_cjs.inputName);
23980
+ const names = (fn.def.inputs ?? []).map(chunk2D7F5IU3_cjs.inputName);
23697
23981
  if (callArgs.length !== names.length) {
23698
23982
  throw new Error(`${fn.name}: expected ${names.length} argument(s), got ${callArgs.length}`);
23699
23983
  }
@@ -24345,6 +24629,7 @@ exports.outpointReasons = outpointReasons;
24345
24629
  exports.promisifyRequest = promisifyRequest;
24346
24630
  exports.provisionClaimSecret = provisionClaimSecret;
24347
24631
  exports.provisionRefundKey = provisionRefundKey;
24632
+ exports.registerWalletRestoreHook = registerWalletRestoreHook;
24348
24633
  exports.requiresMigration = requiresMigration;
24349
24634
  exports.resolveAssetAmount = resolveAssetAmount;
24350
24635
  exports.resolveBatchExpiryPolicy = resolveBatchExpiryPolicy;
@@ -24376,5 +24661,5 @@ exports.waitForIncomingFunds = waitForIncomingFunds;
24376
24661
  exports.walletFeeSource = walletFeeSource;
24377
24662
  exports.warnAndFilterVtxosForScript = warnAndFilterVtxosForScript;
24378
24663
  exports.withPrevTxs = withPrevTxs;
24379
- //# sourceMappingURL=chunk-MK5EPTTB.cjs.map
24380
- //# sourceMappingURL=chunk-MK5EPTTB.cjs.map
24664
+ //# sourceMappingURL=chunk-C4RKZY7D.cjs.map
24665
+ //# sourceMappingURL=chunk-C4RKZY7D.cjs.map