@arkade-os/sdk 0.5.0-rc.11 → 0.5.0-rc.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/README.md +43 -12
  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/{asyncStorageTaskQueue-DBaZsltv.d.cts → asyncStorageTaskQueue-0EeSeCAt.d.cts} +1 -1
  7. package/dist/{asyncStorageTaskQueue-uAG3XLyg.d.ts → asyncStorageTaskQueue-DV94jhwq.d.ts} +1 -1
  8. package/dist/{chunk-WSQAWSEH.js → chunk-3JLYJ5KZ.js} +75 -237
  9. package/dist/chunk-3JLYJ5KZ.js.map +1 -0
  10. package/dist/{chunk-VMLLYEYM.js → chunk-4EU2Q6YT.js} +12 -14
  11. package/dist/chunk-4EU2Q6YT.js.map +1 -0
  12. package/dist/{chunk-IA32YGLH.cjs → chunk-7BACS4XK.cjs} +10 -10
  13. package/dist/chunk-7BACS4XK.cjs.map +1 -0
  14. package/dist/{chunk-5OBGYL6U.cjs → chunk-7NK6XFC3.cjs} +120 -194
  15. package/dist/chunk-7NK6XFC3.cjs.map +1 -0
  16. package/dist/{chunk-CQPQ7D4U.cjs → chunk-BFQX2KS3.cjs} +87 -248
  17. package/dist/chunk-BFQX2KS3.cjs.map +1 -0
  18. package/dist/{chunk-DD6MTNAS.js → chunk-D7JLTHSZ.js} +5 -5
  19. package/dist/chunk-D7JLTHSZ.js.map +1 -0
  20. package/dist/{chunk-CMLSTGOC.js → chunk-EJYWGTZ7.js} +119 -194
  21. package/dist/chunk-EJYWGTZ7.js.map +1 -0
  22. package/dist/{chunk-T2ILYGWE.cjs → chunk-FDQQOF3F.cjs} +327 -1080
  23. package/dist/chunk-FDQQOF3F.cjs.map +1 -0
  24. package/dist/{chunk-MGDXN74N.cjs → chunk-I4YBVHAK.cjs} +2357 -3374
  25. package/dist/chunk-I4YBVHAK.cjs.map +1 -0
  26. package/dist/{chunk-M2ZUPLKQ.js → chunk-IV2252XM.js} +1946 -2977
  27. package/dist/chunk-IV2252XM.js.map +1 -0
  28. package/dist/{chunk-OMJRW2D5.js → chunk-JOUPIZ32.js} +263 -1036
  29. package/dist/chunk-JOUPIZ32.js.map +1 -0
  30. package/dist/{chunk-PWEBQNIE.cjs → chunk-RDQSVIXD.cjs} +22 -24
  31. package/dist/chunk-RDQSVIXD.cjs.map +1 -0
  32. package/dist/contracts/handlers/index.cjs +9 -9
  33. package/dist/contracts/handlers/index.d.cts +3 -3
  34. package/dist/contracts/handlers/index.d.ts +3 -3
  35. package/dist/contracts/handlers/index.js +2 -2
  36. package/dist/{delegate-DFwlkVYR.d.cts → delegate-BgpUJW5B.d.cts} +1 -1
  37. package/dist/{delegate-D3YHDERL.d.ts → delegate-BuagcGnG.d.ts} +1 -1
  38. package/dist/{index-DTvUv5lD.d.cts → index-CKmB14Yu.d.cts} +1145 -2263
  39. package/dist/{index-DTvUv5lD.d.ts → index-CKmB14Yu.d.ts} +1145 -2263
  40. package/dist/index-D0BuYwhF.d.cts +637 -0
  41. package/dist/index-DbzyrqK7.d.ts +637 -0
  42. package/dist/index.cjs +341 -297
  43. package/dist/index.d.cts +379 -788
  44. package/dist/index.d.ts +379 -788
  45. package/dist/index.js +4 -4
  46. package/dist/repositories/realm/index.cjs +142 -101
  47. package/dist/repositories/realm/index.cjs.map +1 -1
  48. package/dist/repositories/realm/index.d.cts +13 -11
  49. package/dist/repositories/realm/index.d.ts +13 -11
  50. package/dist/repositories/realm/index.js +130 -89
  51. package/dist/repositories/realm/index.js.map +1 -1
  52. package/dist/repositories/sqlite/index.cjs +158 -118
  53. package/dist/repositories/sqlite/index.cjs.map +1 -1
  54. package/dist/repositories/sqlite/index.d.cts +14 -13
  55. package/dist/repositories/sqlite/index.d.ts +14 -13
  56. package/dist/repositories/sqlite/index.js +147 -107
  57. package/dist/repositories/sqlite/index.js.map +1 -1
  58. package/dist/{taskRunner-B5bl0YRt.d.ts → taskRunner-BX-pB0sv.d.ts} +1 -1
  59. package/dist/{taskRunner--sKy9Inv.d.cts → taskRunner-DJrFFyus.d.cts} +1 -1
  60. package/dist/wallet/expo/background.cjs +14 -14
  61. package/dist/wallet/expo/background.cjs.map +1 -1
  62. package/dist/wallet/expo/background.d.cts +8 -14
  63. package/dist/wallet/expo/background.d.ts +8 -14
  64. package/dist/wallet/expo/background.js +6 -6
  65. package/dist/wallet/expo/background.js.map +1 -1
  66. package/dist/wallet/expo/index.cjs +14 -14
  67. package/dist/wallet/expo/index.cjs.map +1 -1
  68. package/dist/wallet/expo/index.d.cts +5 -5
  69. package/dist/wallet/expo/index.d.ts +5 -5
  70. package/dist/wallet/expo/index.js +5 -5
  71. package/dist/wallet/expo/index.js.map +1 -1
  72. package/dist/wallet-BsL2G3Qb.d.cts +1542 -0
  73. package/dist/wallet-DXNiCmq8.d.ts +1542 -0
  74. package/dist/worker/expo/index.cjs +9 -9
  75. package/dist/worker/expo/index.d.cts +4 -4
  76. package/dist/worker/expo/index.d.ts +4 -4
  77. package/dist/worker/expo/index.js +5 -5
  78. package/package.json +3 -2
  79. package/dist/chunk-5OBGYL6U.cjs.map +0 -1
  80. package/dist/chunk-CMLSTGOC.js.map +0 -1
  81. package/dist/chunk-CQPQ7D4U.cjs.map +0 -1
  82. package/dist/chunk-DD6MTNAS.js.map +0 -1
  83. package/dist/chunk-IA32YGLH.cjs.map +0 -1
  84. package/dist/chunk-M2ZUPLKQ.js.map +0 -1
  85. package/dist/chunk-MGDXN74N.cjs.map +0 -1
  86. package/dist/chunk-OMJRW2D5.js.map +0 -1
  87. package/dist/chunk-PWEBQNIE.cjs.map +0 -1
  88. package/dist/chunk-T2ILYGWE.cjs.map +0 -1
  89. package/dist/chunk-VMLLYEYM.js.map +0 -1
  90. package/dist/chunk-WSQAWSEH.js.map +0 -1
  91. package/dist/hdWalletCapable-C350s3bP.d.ts +0 -2206
  92. package/dist/hdWalletCapable-rrOmXcbT.d.cts +0 -2206
  93. package/dist/index-C0ZyGoyP.d.cts +0 -850
  94. package/dist/index-DASN1cVk.d.ts +0 -850
@@ -75,12 +75,7 @@ function setArkPsbtField(tx, inputIndex, coder, value) {
75
75
  }
76
76
  function getArkPsbtFields(tx, inputIndex, coder) {
77
77
  const unknown = tx.getInput(inputIndex)?.unknown ?? [];
78
- const fields = [];
79
- for (const u of unknown) {
80
- const v = coder.decode(u);
81
- if (v !== null) fields.push(v);
82
- }
83
- return fields;
78
+ return unknown.map((u) => coder.decode(u)).filter((v) => v !== null);
84
79
  }
85
80
  var VtxoTaprootTree = {
86
81
  key: "taptree" /* VtxoTaprootTree */,
@@ -162,7 +157,7 @@ var VtxoTreeExpiry = {
162
157
  type: ArkPsbtFieldKeyType,
163
158
  key: encodedPsbtFieldKey["expiry" /* VtxoTreeExpiry */]
164
159
  },
165
- ScriptNum(6, true).encode(value.value === 0n ? 0n : value.value)
160
+ ScriptNum(6, true).encode(value.value)
166
161
  ],
167
162
  decode: (unknown) => nullIfCatch(() => {
168
163
  if (!checkKeyMatch(unknown[0], "expiry" /* VtxoTreeExpiry */)) return null;
@@ -574,6 +569,16 @@ var CSVMultisigTapscript;
574
569
  }
575
570
  CSVMultisigTapscript2.isScriptValid = isScriptValid;
576
571
  })(CSVMultisigTapscript || (CSVMultisigTapscript = {}));
572
+ function isConditionScriptValid(script) {
573
+ const asm = Script.decode(script);
574
+ if (asm.length < 1) {
575
+ return new Error(`Invalid script: too short (expected at least 1)`);
576
+ }
577
+ if (asm.lastIndexOf("VERIFY") === -1) {
578
+ return new Error("Invalid script: missing VERIFY operation");
579
+ }
580
+ return true;
581
+ }
577
582
  var ConditionCSVMultisigTapscript;
578
583
  ((ConditionCSVMultisigTapscript2) => {
579
584
  function encode2(params) {
@@ -598,7 +603,7 @@ var ConditionCSVMultisigTapscript;
598
603
  throw isValid;
599
604
  }
600
605
  const asm = Script.decode(script);
601
- let verifyIndex = getVerifyIndex(asm);
606
+ const verifyIndex = asm.lastIndexOf("VERIFY");
602
607
  if (verifyIndex === -1) {
603
608
  throw Error("Invalid script: missing VERIFY operation");
604
609
  }
@@ -633,26 +638,8 @@ var ConditionCSVMultisigTapscript;
633
638
  return tapscript.type === "condition-csv-multisig" /* ConditionCSVMultisig */;
634
639
  }
635
640
  ConditionCSVMultisigTapscript2.is = is;
636
- function getVerifyIndex(asm) {
637
- let verifyIndex = -1;
638
- for (let i = asm.length - 1; i >= 0; i--) {
639
- if (asm[i] === "VERIFY") {
640
- verifyIndex = i;
641
- return verifyIndex;
642
- }
643
- }
644
- return verifyIndex;
645
- }
646
641
  function isScriptValid(script) {
647
- const asm = Script.decode(script);
648
- if (asm.length < 1) {
649
- return new Error(`Invalid script: too short (expected at least 1)`);
650
- }
651
- let verifyIndex = getVerifyIndex(asm);
652
- if (verifyIndex === -1) {
653
- return new Error("Invalid script: missing VERIFY operation");
654
- }
655
- return true;
642
+ return isConditionScriptValid(script);
656
643
  }
657
644
  ConditionCSVMultisigTapscript2.isScriptValid = isScriptValid;
658
645
  })(ConditionCSVMultisigTapscript || (ConditionCSVMultisigTapscript = {}));
@@ -680,7 +667,7 @@ var ConditionMultisigTapscript;
680
667
  throw isValid;
681
668
  }
682
669
  const asm = Script.decode(script);
683
- let verifyIndex = getVerifyIndex(asm);
670
+ const verifyIndex = asm.lastIndexOf("VERIFY");
684
671
  if (verifyIndex === -1) {
685
672
  throw Error("Invalid script: missing VERIFY operation");
686
673
  }
@@ -715,26 +702,8 @@ var ConditionMultisigTapscript;
715
702
  return tapscript.type === "condition-multisig" /* ConditionMultisig */;
716
703
  }
717
704
  ConditionMultisigTapscript2.is = is;
718
- function getVerifyIndex(asm) {
719
- let verifyIndex = -1;
720
- for (let i = asm.length - 1; i >= 0; i--) {
721
- if (asm[i] === "VERIFY") {
722
- verifyIndex = i;
723
- return verifyIndex;
724
- }
725
- }
726
- return verifyIndex;
727
- }
728
705
  function isScriptValid(script) {
729
- const asm = Script.decode(script);
730
- if (asm.length < 1) {
731
- return new Error(`Invalid script: too short (expected at least 1)`);
732
- }
733
- let verifyIndex = getVerifyIndex(asm);
734
- if (verifyIndex === -1) {
735
- return new Error("Invalid script: missing VERIFY operation");
736
- }
737
- return true;
706
+ return isConditionScriptValid(script);
738
707
  }
739
708
  ConditionMultisigTapscript2.isScriptValid = isScriptValid;
740
709
  })(ConditionMultisigTapscript || (ConditionMultisigTapscript = {}));
@@ -1027,7 +996,7 @@ function resolveEventSource(override) {
1027
996
  }
1028
997
 
1029
998
  // package.json
1030
- var version = "0.5.0-rc.11";
999
+ var version = "0.5.0-rc.13";
1031
1000
 
1032
1001
  // src/utils/fetch.ts
1033
1002
  var buildVersion = "0.9.9";
@@ -1084,27 +1053,12 @@ function baseFetch(input, init) {
1084
1053
  }
1085
1054
  function fetch(input, init) {
1086
1055
  const headers = new Headers(init?.headers);
1087
- headers.set("X-Build-Version", buildVersion);
1088
- headers.set("X-SDK-VERSION", sdkVersion);
1056
+ for (const [name, value] of Object.entries(ARKADE_VERSION_HEADERS)) headers.set(name, value);
1089
1057
  return baseFetch(input, { ...init, headers });
1090
1058
  }
1091
1059
  function describeRequest(input, init) {
1092
- let url;
1093
- if (typeof input === "string") {
1094
- url = input;
1095
- } else if (input instanceof URL) {
1096
- url = input.href;
1097
- } else {
1098
- url = input.url;
1099
- }
1100
- let method;
1101
- if (init?.method !== void 0) {
1102
- method = init.method;
1103
- } else if (input instanceof Request) {
1104
- method = input.method;
1105
- } else {
1106
- method = "GET";
1107
- }
1060
+ const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
1061
+ const method = init?.method !== void 0 ? init.method : input instanceof Request ? input.method : "GET";
1108
1062
  return { url, method };
1109
1063
  }
1110
1064
 
@@ -1128,13 +1082,10 @@ var ArkErrorName = {
1128
1082
  INVALID_TX_FILTER: "INVALID_TX_FILTER",
1129
1083
  TX_FILTERS_LIMIT_EXCEEDED: "TX_FILTERS_LIMIT_EXCEEDED",
1130
1084
  /**
1131
- * A CLTV closure was spent before its absolute locktime matured. Raised only by
1132
- * `submitTx` (never `finalizeTx`), with metadata
1133
- * `{ locktime, current_locktime, type: "height" | "time" }`.
1134
- *
1135
- * Self-healing, so defer and retry rather than fail: the server matures a
1136
- * seconds-locktime against the **chain tip block's timestamp**, not its wall clock,
1137
- * so a spend attempted promptly at maturity is rejected until a later block lands.
1085
+ * A CLTV closure was spent before its absolute locktime matured. `submitTx` only, with
1086
+ * metadata `{ locktime, current_locktime, type: "height" | "time" }`. Self-healing, so defer
1087
+ * and retry: the server matures a seconds-locktime against the **chain tip block's
1088
+ * timestamp**, not wall clock, so a prompt spend is rejected until a later block lands.
1138
1089
  */
1139
1090
  FORFEIT_CLOSURE_LOCKED: "FORFEIT_CLOSURE_LOCKED"
1140
1091
  };
@@ -1212,8 +1163,8 @@ var Intent;
1212
1163
  }
1213
1164
  if (ins.length == 0) throw new Error("intent proof requires at least one input");
1214
1165
  const inputs = ins.map(prepareCoinAsIntentProofInput);
1215
- if (!validateInputs(inputs)) ;
1216
- if (!validateOutputs(outputs)) ;
1166
+ validateInputs(inputs);
1167
+ validateOutputs(outputs);
1217
1168
  const toSpend = craftToSpendTx(message, inputs[0].witnessUtxo.script);
1218
1169
  return craftToSignTx(toSpend, inputs, outputs, message);
1219
1170
  }
@@ -1278,7 +1229,6 @@ function validateInput(input) {
1278
1229
  }
1279
1230
  function validateInputs(inputs) {
1280
1231
  inputs.forEach(validateInput);
1281
- return true;
1282
1232
  }
1283
1233
  function validateOutput(output) {
1284
1234
  if (output.amount === void 0) throw new Error("intent proof output requires amount");
@@ -1287,7 +1237,6 @@ function validateOutput(output) {
1287
1237
  }
1288
1238
  function validateOutputs(outputs) {
1289
1239
  outputs.forEach(validateOutput);
1290
- return true;
1291
1240
  }
1292
1241
  function craftToSpendTx(message, pkScript, tag = TAG_INTENT_PROOF) {
1293
1242
  const messageHash = hashMessage(message, tag);
@@ -1732,6 +1681,20 @@ var RestArkProvider = class {
1732
1681
  "Arkade server reported a configuration digest mismatch; server info was refreshed. Rebuild and retry the request under the new server info."
1733
1682
  );
1734
1683
  }
1684
+ async postJson(url, body, failureMessage) {
1685
+ const response = await this.authedFetch(url, {
1686
+ method: "POST",
1687
+ headers: {
1688
+ "Content-Type": "application/json"
1689
+ },
1690
+ body: JSON.stringify(body)
1691
+ });
1692
+ if (!response.ok) {
1693
+ const errorText = await response.text();
1694
+ handleError(errorText, failureMessage(errorText, response));
1695
+ }
1696
+ return response;
1697
+ }
1735
1698
  async getInfo() {
1736
1699
  const url = `${this.serverUrl}/v1/info`;
1737
1700
  const response = await rateGate.runHttp(
@@ -1797,20 +1760,14 @@ var RestArkProvider = class {
1797
1760
  }
1798
1761
  async submitTx(signedArkTx, checkpointTxs) {
1799
1762
  const url = `${this.serverUrl}/v1/tx/submit`;
1800
- const response = await this.authedFetch(url, {
1801
- method: "POST",
1802
- headers: {
1803
- "Content-Type": "application/json"
1804
- },
1805
- body: JSON.stringify({
1763
+ const response = await this.postJson(
1764
+ url,
1765
+ {
1806
1766
  signedArkTx,
1807
1767
  checkpointTxs
1808
- })
1809
- });
1810
- if (!response.ok) {
1811
- const errorText = await response.text();
1812
- handleError(errorText, `Failed to submit virtual transaction: ${errorText}`);
1813
- }
1768
+ },
1769
+ (errorText) => `Failed to submit virtual transaction: ${errorText}`
1770
+ );
1814
1771
  const data = await response.json();
1815
1772
  return {
1816
1773
  arkTxid: data.arkTxid,
@@ -1820,129 +1777,87 @@ var RestArkProvider = class {
1820
1777
  }
1821
1778
  async finalizeTx(arkTxid, finalCheckpointTxs) {
1822
1779
  const url = `${this.serverUrl}/v1/tx/finalize`;
1823
- const response = await this.authedFetch(url, {
1824
- method: "POST",
1825
- headers: {
1826
- "Content-Type": "application/json"
1827
- },
1828
- body: JSON.stringify({
1780
+ await this.postJson(
1781
+ url,
1782
+ {
1829
1783
  arkTxid,
1830
1784
  finalCheckpointTxs
1831
- })
1832
- });
1833
- if (!response.ok) {
1834
- const errorText = await response.text();
1835
- handleError(errorText, `Failed to finalize offchain transaction: ${errorText}`);
1836
- }
1785
+ },
1786
+ (errorText) => `Failed to finalize offchain transaction: ${errorText}`
1787
+ );
1837
1788
  }
1838
1789
  async registerIntent(intent) {
1839
1790
  const url = `${this.serverUrl}/v1/batch/registerIntent`;
1840
- const response = await this.authedFetch(url, {
1841
- method: "POST",
1842
- headers: {
1843
- "Content-Type": "application/json"
1844
- },
1845
- body: JSON.stringify({
1791
+ const response = await this.postJson(
1792
+ url,
1793
+ {
1846
1794
  intent: {
1847
1795
  proof: intent.proof,
1848
1796
  message: Intent.encodeMessage(intent.message)
1849
1797
  }
1850
- })
1851
- });
1852
- if (!response.ok) {
1853
- const errorText = await response.text();
1854
- handleError(errorText, `Failed to register intent: ${errorText}`);
1855
- }
1798
+ },
1799
+ (errorText) => `Failed to register intent: ${errorText}`
1800
+ );
1856
1801
  const data = await response.json();
1857
1802
  return data.intentId;
1858
1803
  }
1859
1804
  async deleteIntent(intent) {
1860
1805
  const url = `${this.serverUrl}/v1/batch/deleteIntent`;
1861
- const response = await this.authedFetch(url, {
1862
- method: "POST",
1863
- headers: {
1864
- "Content-Type": "application/json"
1865
- },
1866
- body: JSON.stringify({
1806
+ await this.postJson(
1807
+ url,
1808
+ {
1867
1809
  intent: {
1868
1810
  proof: intent.proof,
1869
1811
  message: Intent.encodeMessage(intent.message)
1870
1812
  }
1871
- })
1872
- });
1873
- if (!response.ok) {
1874
- const errorText = await response.text();
1875
- handleError(errorText, `Failed to delete intent: ${errorText}`);
1876
- }
1813
+ },
1814
+ (errorText) => `Failed to delete intent: ${errorText}`
1815
+ );
1877
1816
  }
1878
1817
  async confirmRegistration(intentId) {
1879
1818
  const url = `${this.serverUrl}/v1/batch/ack`;
1880
- const response = await this.authedFetch(url, {
1881
- method: "POST",
1882
- headers: {
1883
- "Content-Type": "application/json"
1884
- },
1885
- body: JSON.stringify({
1819
+ await this.postJson(
1820
+ url,
1821
+ {
1886
1822
  intentId
1887
- })
1888
- });
1889
- if (!response.ok) {
1890
- const errorText = await response.text();
1891
- handleError(errorText, `Failed to confirm registration: ${errorText}`);
1892
- }
1823
+ },
1824
+ (errorText) => `Failed to confirm registration: ${errorText}`
1825
+ );
1893
1826
  }
1894
1827
  async submitTreeNonces(batchId, pubkey, nonces) {
1895
1828
  const url = `${this.serverUrl}/v1/batch/tree/submitNonces`;
1896
- const response = await this.authedFetch(url, {
1897
- method: "POST",
1898
- headers: {
1899
- "Content-Type": "application/json"
1900
- },
1901
- body: JSON.stringify({
1829
+ await this.postJson(
1830
+ url,
1831
+ {
1902
1832
  batchId,
1903
1833
  pubkey,
1904
1834
  treeNonces: encodeMusig2Nonces(nonces)
1905
- })
1906
- });
1907
- if (!response.ok) {
1908
- const errorText = await response.text();
1909
- handleError(errorText, `Failed to submit tree nonces: ${errorText}`);
1910
- }
1835
+ },
1836
+ (errorText) => `Failed to submit tree nonces: ${errorText}`
1837
+ );
1911
1838
  }
1912
1839
  async submitTreeSignatures(batchId, pubkey, signatures) {
1913
1840
  const url = `${this.serverUrl}/v1/batch/tree/submitSignatures`;
1914
- const response = await this.authedFetch(url, {
1915
- method: "POST",
1916
- headers: {
1917
- "Content-Type": "application/json"
1918
- },
1919
- body: JSON.stringify({
1841
+ await this.postJson(
1842
+ url,
1843
+ {
1920
1844
  batchId,
1921
1845
  pubkey,
1922
1846
  treeSignatures: encodeMusig2Signatures(signatures)
1923
- })
1924
- });
1925
- if (!response.ok) {
1926
- const errorText = await response.text();
1927
- handleError(errorText, `Failed to submit tree signatures: ${errorText}`);
1928
- }
1847
+ },
1848
+ (errorText) => `Failed to submit tree signatures: ${errorText}`
1849
+ );
1929
1850
  }
1930
1851
  async submitSignedForfeitTxs(signedForfeitTxs, signedCommitmentTx) {
1931
1852
  const url = `${this.serverUrl}/v1/batch/submitForfeitTxs`;
1932
- const response = await this.authedFetch(url, {
1933
- method: "POST",
1934
- headers: {
1935
- "Content-Type": "application/json"
1936
- },
1937
- body: JSON.stringify({
1853
+ await this.postJson(
1854
+ url,
1855
+ {
1938
1856
  signedForfeitTxs,
1939
1857
  signedCommitmentTx
1940
- })
1941
- });
1942
- if (!response.ok) {
1943
- const errorText = await response.text();
1944
- handleError(errorText, `Failed to submit forfeit transactions: ${response.statusText}`);
1945
- }
1858
+ },
1859
+ (_, res) => `Failed to submit forfeit transactions: ${res.statusText}`
1860
+ );
1946
1861
  }
1947
1862
  getEventStream(signal, topics) {
1948
1863
  const url = `${this.serverUrl}/v1/batch/events`;
@@ -2065,22 +1980,16 @@ var RestArkProvider = class {
2065
1980
  }
2066
1981
  async getPendingTxs(intent) {
2067
1982
  const url = `${this.serverUrl}/v1/tx/pending`;
2068
- const response = await this.authedFetch(url, {
2069
- method: "POST",
2070
- headers: {
2071
- "Content-Type": "application/json"
2072
- },
2073
- body: JSON.stringify({
1983
+ const response = await this.postJson(
1984
+ url,
1985
+ {
2074
1986
  intent: {
2075
1987
  proof: intent.proof,
2076
1988
  message: Intent.encodeMessage(intent.message)
2077
1989
  }
2078
- })
2079
- });
2080
- if (!response.ok) {
2081
- const errorText = await response.text();
2082
- handleError(errorText, `Failed to get pending transactions: ${errorText}`);
2083
- }
1990
+ },
1991
+ (errorText) => `Failed to get pending transactions: ${errorText}`
1992
+ );
2084
1993
  const data = await response.json();
2085
1994
  return data.pendingTxs;
2086
1995
  }
@@ -2346,11 +2255,16 @@ async function getNormalizedVtxos(provider, opts) {
2346
2255
  const { vtxos, page } = await provider.getVtxos(opts);
2347
2256
  return { vtxos: vtxos.map(normalizeVtxo), page };
2348
2257
  }
2258
+ var SCRIPT_CHUNK_CONCURRENCY = 4;
2349
2259
  async function getAllNormalizedVtxos(provider, scripts, opts = {}) {
2350
2260
  const { pageSize = DEFAULT_PAGE_SIZE, ...filters } = opts;
2351
2261
  const all = [];
2262
+ const chunks = [];
2352
2263
  for (let i = 0; i < scripts.length; i += SCRIPT_QUERY_CHUNK_SIZE) {
2353
- const chunk = scripts.slice(i, i + SCRIPT_QUERY_CHUNK_SIZE);
2264
+ chunks.push(scripts.slice(i, i + SCRIPT_QUERY_CHUNK_SIZE));
2265
+ }
2266
+ const fetchChunk = async (chunk) => {
2267
+ const result = [];
2354
2268
  let pageIndex = 0;
2355
2269
  let hasMore = true;
2356
2270
  while (hasMore) {
@@ -2360,11 +2274,18 @@ async function getAllNormalizedVtxos(provider, scripts, opts = {}) {
2360
2274
  pageIndex,
2361
2275
  pageSize
2362
2276
  });
2363
- all.push(...vtxos);
2277
+ result.push(...vtxos);
2364
2278
  hasMore = page ? vtxos.length === pageSize : false;
2365
2279
  pageIndex++;
2366
2280
  if (hasMore) await new Promise((r) => setTimeout(r, 500));
2367
2281
  }
2282
+ return result;
2283
+ };
2284
+ for (let i = 0; i < chunks.length; i += SCRIPT_CHUNK_CONCURRENCY) {
2285
+ const batch = await Promise.all(
2286
+ chunks.slice(i, i + SCRIPT_CHUNK_CONCURRENCY).map(fetchChunk)
2287
+ );
2288
+ for (const result of batch) all.push(...result);
2368
2289
  }
2369
2290
  return all;
2370
2291
  }
@@ -2387,7 +2308,7 @@ async function fetchVtxoCreatedAtByTxid(provider, txids) {
2387
2308
  }
2388
2309
  return createdAt;
2389
2310
  }
2390
- function hasTerminalSpend(vtxo) {
2311
+ function isVtxoSpent(vtxo) {
2391
2312
  const n = normalizeVtxo(vtxo);
2392
2313
  return !!n.isSpent || !!n.spentBy || !!n.settledBy;
2393
2314
  }
@@ -2398,15 +2319,19 @@ function isPastExpiry(vtxo, now) {
2398
2319
  }
2399
2320
  function canSpendOffchain(vtxo, now) {
2400
2321
  const n = normalizeVtxo(vtxo);
2401
- return !hasTerminalSpend(n) && !n.isUnrolled && !(n.isSwept || isPastExpiry(n, now));
2322
+ return !isVtxoSpent(n) && !n.isUnrolled && !(n.isSwept || isPastExpiry(n, now));
2402
2323
  }
2403
2324
  function canRecoverOnchain(vtxo, now) {
2404
2325
  const n = normalizeVtxo(vtxo);
2405
- return !hasTerminalSpend(n) && !n.isUnrolled && (n.isSwept || isPastExpiry(n, now));
2326
+ return !isVtxoSpent(n) && !n.isUnrolled && (n.isSwept || isPastExpiry(n, now));
2406
2327
  }
2407
2328
  function canSweepOnchain(vtxo) {
2408
2329
  const n = normalizeVtxo(vtxo);
2409
- return !hasTerminalSpend(n) && !!n.isUnrolled;
2330
+ return !isVtxoSpent(n) && !!n.isUnrolled;
2331
+ }
2332
+ function requiresForfeit(vtxo) {
2333
+ const n = normalizeVtxo(vtxo);
2334
+ return !n.isSwept && !n.isUnrolled;
2410
2335
  }
2411
2336
  function toOffchainInputFeeParams(vtxo) {
2412
2337
  return {
@@ -2421,6 +2346,6 @@ function isVirtualCoin(input) {
2421
2346
  return typeof input === "object" && input !== null && typeof input.script === "string";
2422
2347
  }
2423
2348
 
2424
- export { ARKADE_VERSION_HEADERS, ArkAddress, ArkError, ArkErrorName, ArkPsbtFieldKey, ArkPsbtFieldKeyType, BITCOIN_EMULATOR_PUBKEY, CLTVMultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, ConditionWitness, CosignerPublicKey, DEFAULT_ARKADE_SERVER_URL, DEFAULT_NETWORK, DEFAULT_NETWORK_NAME, DEFAULT_PAGE_SIZE, DigestMismatchError, EXPIRY_MIN_PLAUSIBLE_MS, EventSourceUnavailableError, FetchError, INFO_FETCH_TIMEOUT_MS, Intent, MUTINYNET_EMULATOR_PUBKEY, MultisigTapscript, OP_RETURN_EMPTY_PKSCRIPT, PrevArkTxField, PrevoutTxField, ProviderUnavailableError, READ_TIMEOUT_MS, REGTEST_EMULATOR_PUBKEY, RestArkProvider, SCRIPT_QUERY_CHUNK_SIZE, ServerResponseMismatchError, SettlementEventType, TapTreeCoder, Transaction, VtxoScript, VtxoTaprootTree, VtxoTreeExpiry, __export, assembleBtcdTaprootTree, assertAllowedSighashTypes, baseFetch, buildVersion, canRecoverOnchain, canSpendOffchain, canSweepOnchain, configureEventSource, convertVtxo, craftToSpendTx, decodeTapscript, defaultEmulatorPubkey, eventSourceIterator, fetchVtxoCreatedAtByTxid, formatSighash, getAllNormalizedVtxos, getArkPsbtFields, getConfiguredEventSource, getNetwork, getNormalizedVtxos, getSequence, hasTerminalSpend, isArkError, isEventSourceError, isEventSourceUnavailableError, isFetchTimeoutError, isPastExpiry, isRetryableProviderError, isVirtualCoin, maybeArkError, networkFromArkadeInfo, networks, normalizeVtxo, rateGate, resolveEmulatorPubkey, resolveEventSource, resolveTimeHeight, scriptFromTapLeafScript, sdkVersion, sequenceToTimelock, setArkPsbtField, throwIfHttpUnavailable, timelockToSequence, toOffchainInputFeeParams, toProviderUnavailable };
2425
- //# sourceMappingURL=chunk-CMLSTGOC.js.map
2426
- //# sourceMappingURL=chunk-CMLSTGOC.js.map
2349
+ export { ARKADE_VERSION_HEADERS, ArkAddress, ArkError, ArkErrorName, ArkPsbtFieldKey, ArkPsbtFieldKeyType, BITCOIN_EMULATOR_PUBKEY, CLTVMultisigTapscript, CSVMultisigTapscript, ConditionCSVMultisigTapscript, ConditionMultisigTapscript, ConditionWitness, CosignerPublicKey, DEFAULT_ARKADE_SERVER_URL, DEFAULT_NETWORK, DEFAULT_NETWORK_NAME, DEFAULT_PAGE_SIZE, DigestMismatchError, EXPIRY_MIN_PLAUSIBLE_MS, EventSourceUnavailableError, FetchError, INFO_FETCH_TIMEOUT_MS, Intent, MUTINYNET_EMULATOR_PUBKEY, MultisigTapscript, OP_RETURN_EMPTY_PKSCRIPT, PrevArkTxField, PrevoutTxField, ProviderUnavailableError, READ_TIMEOUT_MS, REGTEST_EMULATOR_PUBKEY, RestArkProvider, SCRIPT_QUERY_CHUNK_SIZE, ServerResponseMismatchError, SettlementEventType, TapTreeCoder, Transaction, VtxoScript, VtxoTaprootTree, VtxoTreeExpiry, __export, assembleBtcdTaprootTree, assertAllowedSighashTypes, baseFetch, buildVersion, canRecoverOnchain, canSpendOffchain, canSweepOnchain, configureEventSource, convertVtxo, craftToSpendTx, decodeTapscript, defaultEmulatorPubkey, eventSourceIterator, fetchVtxoCreatedAtByTxid, formatSighash, getAllNormalizedVtxos, getArkPsbtFields, getConfiguredEventSource, getNetwork, getNormalizedVtxos, getSequence, isArkError, isEventSourceError, isEventSourceUnavailableError, isFetchTimeoutError, isPastExpiry, isRetryableProviderError, isVirtualCoin, isVtxoSpent, maybeArkError, networkFromArkadeInfo, networks, normalizeVtxo, rateGate, requiresForfeit, resolveEmulatorPubkey, resolveEventSource, resolveTimeHeight, scriptFromTapLeafScript, sdkVersion, sequenceToTimelock, setArkPsbtField, throwIfHttpUnavailable, timelockToSequence, toOffchainInputFeeParams, toProviderUnavailable };
2350
+ //# sourceMappingURL=chunk-EJYWGTZ7.js.map
2351
+ //# sourceMappingURL=chunk-EJYWGTZ7.js.map