@thruputchain/client 0.27.0 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/README.md +120 -22
  2. package/dist/{actions-DK_XBeVy.cjs → actions-B2gV8Vzr.cjs} +297 -73
  3. package/dist/actions-B2gV8Vzr.cjs.map +1 -0
  4. package/dist/actions-UEYKD22C.js +653 -0
  5. package/dist/actions-UEYKD22C.js.map +1 -0
  6. package/dist/actions.cjs +4 -8
  7. package/dist/actions.d.cts +4 -4
  8. package/dist/actions.d.ts +4 -4
  9. package/dist/actions.js +3 -3
  10. package/dist/{artifact-BM_MVzhL.d.ts → artifact-RIAPVmVX.d.cts} +4 -3
  11. package/dist/artifact-RIAPVmVX.d.cts.map +1 -0
  12. package/dist/{artifact-BM_MVzhL.d.cts → artifact-RIAPVmVX.d.ts} +4 -3
  13. package/dist/artifact-RIAPVmVX.d.ts.map +1 -0
  14. package/dist/{contract-Cu8Qv94_.js → contract-BOlNskwd.js} +235 -87
  15. package/dist/contract-BOlNskwd.js.map +1 -0
  16. package/dist/{contract-DPm2BJTu.cjs → contract-D_vxUudr.cjs} +281 -109
  17. package/dist/contract-D_vxUudr.cjs.map +1 -0
  18. package/dist/contract.cjs +1 -5
  19. package/dist/contract.d.cts +4 -4
  20. package/dist/contract.d.ts +4 -4
  21. package/dist/contract.js +2 -2
  22. package/dist/contracts.cjs +5 -5
  23. package/dist/contracts.d.cts +19 -4
  24. package/dist/contracts.d.cts.map +1 -1
  25. package/dist/contracts.d.ts +19 -4
  26. package/dist/contracts.d.ts.map +1 -1
  27. package/dist/contracts.js +4 -4
  28. package/dist/decimal-BX7abv5J.cjs +171 -0
  29. package/dist/decimal-BX7abv5J.cjs.map +1 -0
  30. package/dist/decimal-CoHOISys.js +124 -0
  31. package/dist/decimal-CoHOISys.js.map +1 -0
  32. package/dist/{dev_wallet-BcvX_xT4.cjs → dev_wallet-BVChhV6j.cjs} +85 -6
  33. package/dist/dev_wallet-BVChhV6j.cjs.map +1 -0
  34. package/dist/{dev_wallet-B5R5JJaw.js → dev_wallet-D9LuPZ-h.js} +84 -5
  35. package/dist/dev_wallet-D9LuPZ-h.js.map +1 -0
  36. package/dist/{execution-C8oQgpO3.d.cts → execution-pSt6k620.d.cts} +23 -50
  37. package/dist/execution-pSt6k620.d.cts.map +1 -0
  38. package/dist/{execution-DsZzqv_C.d.ts → execution-uiuFPV0d.d.ts} +23 -50
  39. package/dist/execution-uiuFPV0d.d.ts.map +1 -0
  40. package/dist/{hex-DIcaALXL.js → hex-B8D-jBgz.js} +2 -2
  41. package/dist/{hex-DIcaALXL.js.map → hex-B8D-jBgz.js.map} +1 -1
  42. package/dist/{hex-DkGpiZ5e.cjs → hex-CSDZ9d6z.cjs} +2 -2
  43. package/dist/{hex-DkGpiZ5e.cjs.map → hex-CSDZ9d6z.cjs.map} +1 -1
  44. package/dist/{index-rrP1HJ2Z.d.cts → index-B1efA-Y_.d.ts} +24 -21
  45. package/dist/index-B1efA-Y_.d.ts.map +1 -0
  46. package/dist/{index-Zaz-e8Sy.d.ts → index-BGmH_Sm7.d.cts} +12 -62
  47. package/dist/index-BGmH_Sm7.d.cts.map +1 -0
  48. package/dist/{index-CHnfHuQo.d.ts → index-BZ5j5P5d.d.ts} +11 -9
  49. package/dist/index-BZ5j5P5d.d.ts.map +1 -0
  50. package/dist/{index-BmQN3jAS.d.cts → index-BfYEEVHm.d.cts} +3 -13
  51. package/dist/index-BfYEEVHm.d.cts.map +1 -0
  52. package/dist/{index-CuzB95QT.d.cts → index-BhOeIyrZ.d.cts} +11 -9
  53. package/dist/index-BhOeIyrZ.d.cts.map +1 -0
  54. package/dist/{index-B5KqSHeL.d.cts → index-BsvYcU_Y.d.cts} +2 -2
  55. package/dist/{index-B5KqSHeL.d.cts.map → index-BsvYcU_Y.d.cts.map} +1 -1
  56. package/dist/{index-hqEnT64w.d.ts → index-Btl_jMCT.d.ts} +3 -13
  57. package/dist/index-Btl_jMCT.d.ts.map +1 -0
  58. package/dist/{index-C3qDR1J5.d.cts → index-CG-q0j9w.d.ts} +12 -62
  59. package/dist/index-CG-q0j9w.d.ts.map +1 -0
  60. package/dist/index-CPtBvHE8.d.ts +145 -0
  61. package/dist/index-CPtBvHE8.d.ts.map +1 -0
  62. package/dist/{index-CKqC9N4o.d.ts → index-DBKsOzCN.d.cts} +24 -21
  63. package/dist/index-DBKsOzCN.d.cts.map +1 -0
  64. package/dist/index-Xre-0Jka.d.cts +145 -0
  65. package/dist/index-Xre-0Jka.d.cts.map +1 -0
  66. package/dist/index.cjs +39 -68
  67. package/dist/index.cjs.map +1 -1
  68. package/dist/index.d.cts +12 -17
  69. package/dist/index.d.cts.map +1 -1
  70. package/dist/index.d.ts +12 -17
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +27 -38
  73. package/dist/index.js.map +1 -1
  74. package/dist/provider.cjs +3 -3
  75. package/dist/provider.cjs.map +1 -1
  76. package/dist/provider.d.cts +2 -1
  77. package/dist/provider.d.ts +2 -1
  78. package/dist/provider.js +3 -3
  79. package/dist/provider.js.map +1 -1
  80. package/dist/{codec-BOjoJjC5.js → readError-B3Rz7rgs.js} +673 -56
  81. package/dist/readError-B3Rz7rgs.js.map +1 -0
  82. package/dist/{codec-C4LJ0g8v.cjs → readError-COcEDNoZ.cjs} +677 -96
  83. package/dist/readError-COcEDNoZ.cjs.map +1 -0
  84. package/dist/requestAirdrop-DBCOST2B.d.ts +1818 -0
  85. package/dist/requestAirdrop-DBCOST2B.d.ts.map +1 -0
  86. package/dist/requestAirdrop-T1eVn3l5.d.cts +1818 -0
  87. package/dist/requestAirdrop-T1eVn3l5.d.cts.map +1 -0
  88. package/dist/sendInvocation-185ZJrta.cjs +583 -0
  89. package/dist/sendInvocation-185ZJrta.cjs.map +1 -0
  90. package/dist/sendInvocation-DBaNWhr3.js +439 -0
  91. package/dist/sendInvocation-DBaNWhr3.js.map +1 -0
  92. package/dist/signed-op.cjs +2 -2
  93. package/dist/signed-op.d.cts +2 -2
  94. package/dist/signed-op.d.ts +1 -1
  95. package/dist/signed-op.js +2 -2
  96. package/dist/{signedOp-BDUZhfJn.cjs → signedOp-CVyeJ5ig.cjs} +3 -3
  97. package/dist/{signedOp-BDUZhfJn.cjs.map → signedOp-CVyeJ5ig.cjs.map} +1 -1
  98. package/dist/{signedOp-Kx8u8_3I.js → signedOp-D6WYZG9j.js} +3 -3
  99. package/dist/{signedOp-Kx8u8_3I.js.map → signedOp-D6WYZG9j.js.map} +1 -1
  100. package/dist/{signed_op-CAcYYRm6.cjs → signed_op-BBsDKOlD.cjs} +4 -4
  101. package/dist/{signed_op-CAcYYRm6.cjs.map → signed_op-BBsDKOlD.cjs.map} +1 -1
  102. package/dist/{signed_op-BrLxDrDb.d.cts → signed_op-BvbOHWKK.d.ts} +3 -3
  103. package/dist/{signed_op-DbRq3_Hb.d.ts.map → signed_op-BvbOHWKK.d.ts.map} +1 -1
  104. package/dist/{signed_op-DbRq3_Hb.d.ts → signed_op-DoHFpSH4.d.cts} +3 -3
  105. package/dist/{signed_op-BrLxDrDb.d.cts.map → signed_op-DoHFpSH4.d.cts.map} +1 -1
  106. package/dist/{signed_op-Dxn7-lRu.js → signed_op-h9X9-vBL.js} +3 -3
  107. package/dist/{signed_op-Dxn7-lRu.js.map → signed_op-h9X9-vBL.js.map} +1 -1
  108. package/dist/transport-BhWZxHcz.cjs +528 -0
  109. package/dist/transport-BhWZxHcz.cjs.map +1 -0
  110. package/dist/transport-EyDYuibb.js +504 -0
  111. package/dist/transport-EyDYuibb.js.map +1 -0
  112. package/dist/transport.cjs +6 -13
  113. package/dist/transport.d.cts +3 -3
  114. package/dist/transport.d.ts +3 -3
  115. package/dist/transport.js +4 -4
  116. package/dist/types-VYjJcTip.d.cts +161 -0
  117. package/dist/types-VYjJcTip.d.cts.map +1 -0
  118. package/dist/types-VYjJcTip.d.ts +161 -0
  119. package/dist/types-VYjJcTip.d.ts.map +1 -0
  120. package/dist/{validation-eXATmgO0.js → validation-BLQ64Dfh.js} +3 -3
  121. package/dist/validation-BLQ64Dfh.js.map +1 -0
  122. package/dist/{validation-4w-vDGAi.cjs → validation-CZqtmMLJ.cjs} +3 -3
  123. package/dist/validation-CZqtmMLJ.cjs.map +1 -0
  124. package/dist/{wallet-5wt9wLG3.js → wallet-NlZiI4-3.js} +161 -77
  125. package/dist/wallet-NlZiI4-3.js.map +1 -0
  126. package/dist/{wallet-Blh7oas7.cjs → wallet-UvyXtxh5.cjs} +161 -77
  127. package/dist/wallet-UvyXtxh5.cjs.map +1 -0
  128. package/dist/wallet.cjs +2 -8
  129. package/dist/wallet.d.cts +4 -3
  130. package/dist/wallet.d.ts +4 -3
  131. package/dist/wallet.js +3 -3
  132. package/package.json +2 -2
  133. package/dist/actions-1LmkZcfS.js +0 -430
  134. package/dist/actions-1LmkZcfS.js.map +0 -1
  135. package/dist/actions-DK_XBeVy.cjs.map +0 -1
  136. package/dist/artifact-BM_MVzhL.d.cts.map +0 -1
  137. package/dist/artifact-BM_MVzhL.d.ts.map +0 -1
  138. package/dist/client-DocSdzOL.d.cts +0 -790
  139. package/dist/client-DocSdzOL.d.cts.map +0 -1
  140. package/dist/client-DocSdzOL.d.ts +0 -790
  141. package/dist/client-DocSdzOL.d.ts.map +0 -1
  142. package/dist/codec-BOjoJjC5.js.map +0 -1
  143. package/dist/codec-C4LJ0g8v.cjs.map +0 -1
  144. package/dist/contract-Cu8Qv94_.js.map +0 -1
  145. package/dist/contract-DPm2BJTu.cjs.map +0 -1
  146. package/dist/dev_wallet-B5R5JJaw.js.map +0 -1
  147. package/dist/dev_wallet-BcvX_xT4.cjs.map +0 -1
  148. package/dist/execution-C8oQgpO3.d.cts.map +0 -1
  149. package/dist/execution-DsZzqv_C.d.ts.map +0 -1
  150. package/dist/index-BmQN3jAS.d.cts.map +0 -1
  151. package/dist/index-C3qDR1J5.d.cts.map +0 -1
  152. package/dist/index-CHnfHuQo.d.ts.map +0 -1
  153. package/dist/index-CIHK7Ew9.d.cts +0 -303
  154. package/dist/index-CIHK7Ew9.d.cts.map +0 -1
  155. package/dist/index-CIHK7Ew9.d.ts +0 -303
  156. package/dist/index-CIHK7Ew9.d.ts.map +0 -1
  157. package/dist/index-CKqC9N4o.d.ts.map +0 -1
  158. package/dist/index-CuzB95QT.d.cts.map +0 -1
  159. package/dist/index-Zaz-e8Sy.d.ts.map +0 -1
  160. package/dist/index-hqEnT64w.d.ts.map +0 -1
  161. package/dist/index-rrP1HJ2Z.d.cts.map +0 -1
  162. package/dist/readError-Cz3bveZa.cjs +0 -622
  163. package/dist/readError-Cz3bveZa.cjs.map +0 -1
  164. package/dist/readError-Z5zuylri.js +0 -569
  165. package/dist/readError-Z5zuylri.js.map +0 -1
  166. package/dist/readViews-BvMHbiaF.d.ts +0 -609
  167. package/dist/readViews-BvMHbiaF.d.ts.map +0 -1
  168. package/dist/readViews-CQOY5v4o.d.cts +0 -609
  169. package/dist/readViews-CQOY5v4o.d.cts.map +0 -1
  170. package/dist/sendInvocation-8TEMrJ_M.cjs +0 -661
  171. package/dist/sendInvocation-8TEMrJ_M.cjs.map +0 -1
  172. package/dist/sendInvocation-CkeMyLk1.js +0 -505
  173. package/dist/sendInvocation-CkeMyLk1.js.map +0 -1
  174. package/dist/transport-DqlfAsuH.cjs +0 -279
  175. package/dist/transport-DqlfAsuH.cjs.map +0 -1
  176. package/dist/transport-PstrCcBv.js +0 -261
  177. package/dist/transport-PstrCcBv.js.map +0 -1
  178. package/dist/validation-4w-vDGAi.cjs.map +0 -1
  179. package/dist/validation-eXATmgO0.js.map +0 -1
  180. package/dist/wallet-5wt9wLG3.js.map +0 -1
  181. package/dist/wallet-Blh7oas7.cjs.map +0 -1
@@ -1,30 +1,193 @@
1
- const require_contract = require("./contract-DPm2BJTu.cjs");
2
- const require_codec = require("./codec-C4LJ0g8v.cjs");
3
- const require_hex = require("./hex-DkGpiZ5e.cjs");
4
- const require_readError = require("./readError-Cz3bveZa.cjs");
5
- const require_sendInvocation = require("./sendInvocation-8TEMrJ_M.cjs");
6
- const require_dev_wallet = require("./dev_wallet-BcvX_xT4.cjs");
1
+ const require_decimal = require("./decimal-BX7abv5J.cjs");
2
+ const require_hex = require("./hex-CSDZ9d6z.cjs");
3
+ const require_contract = require("./contract-D_vxUudr.cjs");
4
+ const require_readError = require("./readError-COcEDNoZ.cjs");
5
+ const require_sendInvocation = require("./sendInvocation-185ZJrta.cjs");
6
+ const require_dev_wallet = require("./dev_wallet-BVChhV6j.cjs");
7
7
  let _thruputchain_protocol = require("@thruputchain/protocol");
8
8
  let _noble_hashes_sha2_js = require("@noble/hashes/sha2.js");
9
- //#region src/actions/public/requestAirdrop.ts
10
- /** Funding stopped without permission to call the faucet again. */
11
- var FundingObservationError = class extends Error {
12
- request;
13
- lastResponse;
14
- knownCommitment;
15
- constructor(request, lastResponse, cause, knownCommitment) {
16
- super("Funding observation stopped", { cause });
17
- this.request = request;
18
- this.lastResponse = lastResponse;
19
- this.knownCommitment = knownCommitment;
20
- this.name = "FundingObservationError";
9
+ let _thruputchain_protocol_utils = require("@thruputchain/protocol/utils");
10
+ //#region src/actions/public/waitForTransactionReceipt.ts
11
+ /**
12
+ * Observation stopped: code `transactionOutcomeUnknown`. Neither a timeout nor
13
+ * cancellation proves that the transaction did not execute.
14
+ */
15
+ function outcomeUnknown(transactionHash, reason, timedOut, cause, knownCommitment, lastStatus) {
16
+ return new require_decimal.ThruputError("transactionOutcomeUnknown", timedOut ? `Timed out waiting for transaction ${(0, _thruputchain_protocol_utils.toBase58)(transactionHash)}` : `Could not observe transaction ${(0, _thruputchain_protocol_utils.toBase58)(transactionHash)}`, {
17
+ context: {
18
+ ...knownCommitment ? { knownCommitment } : {},
19
+ ...lastStatus ? { lastStatus } : {}
20
+ },
21
+ ...cause === void 0 ? {} : { cause },
22
+ transaction: {
23
+ hash: transactionHash,
24
+ outcome: "unknown",
25
+ reason
26
+ }
27
+ });
28
+ }
29
+ /** The observation deadline. Private, so read-error handling never retries it. */
30
+ var ObservationTimeout = class extends Error {};
31
+ /** The reason for a timeout: the last read failure or node status, when known. */
32
+ function timeoutReason(lastFailure, lastStatus) {
33
+ if (lastFailure !== void 0) return "disconnected";
34
+ if (lastStatus === void 0) return "timeout";
35
+ if (lastStatus instanceof require_decimal.UnsupportedRpcValue) return "statusUnknown";
36
+ if (lastStatus.status === "unknown" || lastStatus.status === "other") return "statusUnknown";
37
+ if (lastStatus.status === "recentFailure") return "recentFailure";
38
+ return "timeout";
39
+ }
40
+ const equal = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
41
+ /**
42
+ * Return any committed receipt, including failed execution. Never sign or resubmit.
43
+ * When observation stops, throws code `transactionOutcomeUnknown` with
44
+ * `transaction.reason` set to why it stopped.
45
+ */
46
+ async function waitForTransactionReceipt(client, transactionHash, options = {}) {
47
+ return await observe(client, transactionHash, options, false);
48
+ }
49
+ /** Observe commitment independently of receipt availability or execution success. */
50
+ async function waitForCommitment(client, transactionHash, options = {}) {
51
+ return await observe(client, transactionHash, options, true);
52
+ }
53
+ function snapshotStatus(status) {
54
+ const copy = (value) => {
55
+ if (value instanceof require_decimal.UnsupportedRpcValue) return new require_decimal.UnsupportedRpcValue(structuredClone(value.raw));
56
+ if (Array.isArray(value)) return value.map(copy);
57
+ if (ArrayBuffer.isView(value)) return structuredClone(value);
58
+ if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, copy(entry)]));
59
+ return value;
60
+ };
61
+ return copy(status);
62
+ }
63
+ async function observe(client, hash, options, commitmentOnly) {
64
+ const timeoutMs = options.timeoutMs ?? 3e4;
65
+ const interval = options.pollingIntervalMs ?? 250;
66
+ require_sendInvocation.validateTimer(timeoutMs, "timeoutMs");
67
+ require_sendInvocation.validateTimer(interval, "pollingIntervalMs");
68
+ const transactionHash = new Uint8Array(hash);
69
+ const networkHash = new Uint8Array(options.expectedNetworkHash ?? client.discovery.network.networkHash);
70
+ if (transactionHash.length !== 32 || networkHash.length !== 32) throw new RangeError("Transaction and network hashes must contain 32 bytes");
71
+ let commitment;
72
+ let lastStatus;
73
+ if (options.knownCommitment) {
74
+ const known = options.knownCommitment;
75
+ if (!equal(known.transactionHash, transactionHash) || !equal(known.networkHash, networkHash) || typeof known.blockHeight !== "bigint" || known.blockHeight < 0n || known.blockHeight > 9223372036854775807n) throw new TypeError("knownCommitment does not match the transaction hash and network");
76
+ commitment = {
77
+ transactionHash: transactionHash.slice(),
78
+ networkHash: networkHash.slice(),
79
+ blockHeight: known.blockHeight
80
+ };
81
+ lastStatus = {
82
+ status: "committed",
83
+ blockHeight: known.blockHeight
84
+ };
21
85
  }
22
- };
86
+ client.requireMethods([
87
+ "getNetworkInfo",
88
+ "getTransactionReceipt",
89
+ "getTransactionStatus"
90
+ ]);
91
+ const deadline = performance.now() + timeoutMs;
92
+ let lastFailure;
93
+ let failures = 0;
94
+ let timedOut = false;
95
+ let stopReason;
96
+ const stop = (reason, error) => {
97
+ stopReason = reason;
98
+ return error;
99
+ };
100
+ const timeout = () => {
101
+ timedOut = true;
102
+ return new ObservationTimeout("Transaction observation timed out");
103
+ };
104
+ const run = (operation) => require_sendInvocation.beforeDeadline(operation, deadline, options.signal, timeout);
105
+ const retain = (blockHeight) => {
106
+ if (commitment && commitment.blockHeight !== blockHeight) throw stop("commitmentConflict", require_readError.rpcIncompatible("commitment", "Conflicting commitment heights for the same transaction"));
107
+ commitment = {
108
+ transactionHash: transactionHash.slice(),
109
+ networkHash: networkHash.slice(),
110
+ blockHeight
111
+ };
112
+ lastStatus = {
113
+ status: "committed",
114
+ blockHeight
115
+ };
116
+ };
117
+ try {
118
+ while (true) {
119
+ let retryAfterMs;
120
+ let networkVerified = false;
121
+ let failed = false;
122
+ try {
123
+ if (!equal((await run((signal) => client.getNetworkInfo({}, { signal }))).networkHash, networkHash)) throw stop("networkChanged", require_readError.rpcIncompatible("network", "Observation endpoint network changed"));
124
+ networkVerified = true;
125
+ if (commitmentOnly && commitment) return structuredClone(commitment);
126
+ const receipt = await run((signal) => client.getTransactionReceipt({ transactionHash }, { signal }));
127
+ if (receipt) {
128
+ retain(receipt.blockHeight);
129
+ return commitmentOnly ? structuredClone(commitment) : receipt;
130
+ }
131
+ } catch (cause) {
132
+ if (cause instanceof ObservationTimeout || options.signal?.aborted) throw cause;
133
+ lastFailure = cause;
134
+ failed = true;
135
+ if (require_decimal.isThruputError(cause, "nativeRpcError") && cause.context.data) {
136
+ const data = cause.context.data;
137
+ if (data.kind === "backendDataInvalid" && data.observation) {
138
+ retain(data.observation.blockHeight);
139
+ if (commitmentOnly) return structuredClone(commitment);
140
+ }
141
+ if ("retryAfterMs" in data) retryAfterMs = data.retryAfterMs;
142
+ }
143
+ if (options.signal?.aborted || require_readError.classifyReadError(cause, options) !== "transient") throw cause;
144
+ }
145
+ let observedStatus;
146
+ if (networkVerified) try {
147
+ const status = await run((signal) => client.getTransactionStatus({ transactionHash }, { signal }));
148
+ if (!(status instanceof require_decimal.UnsupportedRpcValue) && status.status === "committed") retain(status.blockHeight);
149
+ else if (!commitment) lastStatus = snapshotStatus(status);
150
+ observedStatus = status;
151
+ } catch (cause) {
152
+ if (cause instanceof ObservationTimeout || require_decimal.isThruputError(cause, "rpcIncompatible") || require_decimal.isThruputError(cause, "rpcValueInvalid") || require_decimal.isThruputError(cause, "rpcRequestInvalid") || require_readError.classifyReadError(cause, options) === "permanent") throw cause;
153
+ options.signal?.throwIfAborted();
154
+ lastFailure = cause;
155
+ failed = true;
156
+ if (require_decimal.isThruputError(cause, "nativeRpcError") && cause.context.data && "retryAfterMs" in cause.context.data) {
157
+ const hint = cause.context.data.retryAfterMs;
158
+ if (hint !== void 0 && (retryAfterMs === void 0 || hint > retryAfterMs)) retryAfterMs = hint;
159
+ }
160
+ }
161
+ if (observedStatus !== void 0) options.onStatus?.(observedStatus);
162
+ if (failed) failures++;
163
+ else {
164
+ failures = 0;
165
+ lastFailure = void 0;
166
+ }
167
+ if (commitmentOnly && commitment) return structuredClone(commitment);
168
+ const backoff = failures ? Math.min(5e3, Math.max(1, interval) * 2 ** Math.min(failures - 1, 8)) * (.5 + Math.random() / 2) : interval;
169
+ const remaining = deadline - performance.now();
170
+ if (retryAfterMs !== void 0 && retryAfterMs > BigInt(Math.max(0, Math.floor(remaining)))) throw timeout();
171
+ const delay = Math.max(backoff, Number(retryAfterMs ?? 0n));
172
+ await run((signal) => require_sendInvocation.waitDelay(Math.min(delay, Math.max(0, remaining)), signal));
173
+ }
174
+ } catch (cause) {
175
+ const reason = options.signal?.aborted ? "cancelled" : timedOut ? timeoutReason(lastFailure, lastStatus) : stopReason ?? "observationFailed";
176
+ throw outcomeUnknown(transactionHash, reason, timedOut && reason !== "cancelled", cause instanceof ObservationTimeout ? lastFailure : cause, commitment && structuredClone(commitment), lastStatus);
177
+ }
178
+ }
179
+ //#endregion
180
+ //#region src/actions/public/requestAirdrop.ts
23
181
  /** Perform exactly one faucet call. It neither polls nor repeats an ambiguous attempt. */
24
182
  async function requestAirdropAttempt(client, request, options = {}) {
25
183
  return client.faucet_requestAirdrop(request, options);
26
184
  }
27
- /** Call the faucet once, then observe a returned pending hash using read-only calls. */
185
+ /**
186
+ * Call the faucet once, then observe a returned pending hash using read-only calls.
187
+ * When funding stops, throws code `fundingStopped` without permission to call the
188
+ * faucet again. `transaction` is present when the faucet identified a
189
+ * transaction; reconcile with `context.request.clientNonce`.
190
+ */
28
191
  async function requestAirdrop(client, options) {
29
192
  const timeoutMs = options.timeoutMs ?? 6e4;
30
193
  require_sendInvocation.validateTimer(timeoutMs, "timeoutMs");
@@ -42,21 +205,28 @@ async function requestAirdrop(client, options) {
42
205
  ]);
43
206
  const deadline = performance.now() + timeoutMs;
44
207
  let lastResponse;
45
- const timeout = () => /* @__PURE__ */ new Error("Funding observation timed out");
208
+ let timedOut = false;
209
+ const timeout = () => {
210
+ timedOut = true;
211
+ return new DOMException("Funding observation timed out", "TimeoutError");
212
+ };
46
213
  const run = (operation) => require_sendInvocation.beforeDeadline(operation, deadline, options.signal, timeout);
214
+ let phase = "network";
47
215
  try {
48
- if ((await run((signal) => client.getNetworkInfo({}, { signal }))).networkHash.some((v, i) => v !== request.networkHash[i])) throw new require_readError.RpcCompatibilityError("Funding endpoint network does not match");
216
+ if ((await run((signal) => client.getNetworkInfo({}, { signal }))).networkHash.some((v, i) => v !== request.networkHash[i])) throw require_readError.rpcIncompatible("network", "Funding endpoint network does not match");
217
+ phase = "faucet";
49
218
  lastResponse = await run((signal) => requestAirdropAttempt(client, {
50
219
  recipient: request.recipient,
51
220
  clientNonce: request.clientNonce
52
221
  }, { signal }));
53
- if (lastResponse instanceof require_codec.UnsupportedRpcValue) throw lastResponse;
222
+ if (require_decimal.isUnsupportedRpcValue(lastResponse)) throw unsupported("Unsupported faucet response", lastResponse);
54
223
  if (lastResponse.attemptStatus === "succeeded") {
55
- if (lastResponse.execution instanceof require_codec.UnsupportedRpcValue) throw lastResponse.execution;
224
+ if (require_decimal.isUnsupportedRpcValue(lastResponse.execution)) throw unsupported("Unsupported faucet execution outcome", lastResponse.execution);
56
225
  return lastResponse;
57
226
  }
58
- if (!lastResponse.transactionHash) throw new Error("Pending funding did not identify a transaction");
59
- const receipt = await require_sendInvocation.waitForTransactionReceipt(client, lastResponse.transactionHash, {
227
+ if (!lastResponse.transactionHash) throw new Error("The faucet attempt is pending without a transaction");
228
+ phase = "observe";
229
+ const receipt = await waitForTransactionReceipt(client, lastResponse.transactionHash, {
60
230
  expectedNetworkHash: request.networkHash,
61
231
  timeoutMs: Math.max(0, deadline - performance.now()),
62
232
  signal: options.signal
@@ -71,15 +241,61 @@ async function requestAirdrop(client, options) {
71
241
  execution: receipt.execution
72
242
  };
73
243
  } catch (cause) {
74
- const nativeReceipt = cause instanceof require_readError.NativeRpcError && cause.decoded.classification === "known" && "receipt" in cause.decoded.data ? cause.decoded.data.receipt : void 0;
75
- const committedResult = cause instanceof require_sendInvocation.TransactionExecutionError ? cause.receipt : nativeReceipt ?? (!(lastResponse instanceof require_codec.UnsupportedRpcValue) && lastResponse?.attemptStatus === "succeeded" ? lastResponse : void 0);
76
- throw new FundingObservationError(request, lastResponse, cause, cause instanceof require_sendInvocation.TransactionReceiptObservationError ? cause.knownCommitment : committedResult ? {
244
+ const cancelled = require_sendInvocation.isCancellation(cause, options.signal);
245
+ const response = require_decimal.isUnsupportedRpcValue(lastResponse) ? void 0 : lastResponse;
246
+ const native = !cancelled && phase === "faucet" && require_decimal.isThruputError(cause, "nativeRpcError") ? cause.context.data : void 0;
247
+ const observed = !cancelled && phase === "observe" && require_decimal.isThruputError(cause) && cause.transaction && response?.transactionHash && bytesEqual(cause.transaction.hash, response.transactionHash) ? cause.transaction : void 0;
248
+ const receipt = observed?.receipt ?? (native && "receipt" in native ? native.receipt : void 0);
249
+ const hash = receipt?.transactionHash ?? observed?.hash ?? (native && "transactionHash" in native ? native.transactionHash : void 0) ?? response?.transactionHash;
250
+ const signed = native && "signedTransaction" in native ? native.signedTransaction : void 0;
251
+ const submission = signed && hash ? fundingSubmission(signed, request.networkHash, hash) : void 0;
252
+ const reason = options.signal?.aborted ? "cancelled" : timedOut ? "timeout" : native ? require_readError.classifyReadError(cause) === "transient" ? "disconnected" : "nodeRejected" : "observationFailed";
253
+ const extra = submission ? { submission } : {};
254
+ const transaction = receipt ? {
255
+ ...require_contract.receiptFacts(receipt, reason),
256
+ ...extra
257
+ } : observed ? {
258
+ hash: observed.hash,
259
+ outcome: observed.outcome,
260
+ reason: observed.reason
261
+ } : hash ? {
262
+ hash,
263
+ outcome: "unknown",
264
+ reason: response?.attemptStatus === "succeeded" ? "outcomeUnsupported" : reason,
265
+ ...extra
266
+ } : void 0;
267
+ const committed = receipt ?? (response?.attemptStatus === "succeeded" ? response : void 0);
268
+ const knownCommitment = observed && require_decimal.isThruputError(cause, "transactionOutcomeUnknown") ? cause.context.knownCommitment : committed ? {
77
269
  networkHash: request.networkHash.slice(),
78
- transactionHash: new Uint8Array(committedResult.transactionHash),
79
- blockHeight: committedResult.blockHeight
80
- } : void 0);
270
+ transactionHash: new Uint8Array(committed.transactionHash),
271
+ blockHeight: committed.blockHeight
272
+ } : void 0;
273
+ throw new require_decimal.ThruputError("fundingStopped", "Funding observation stopped", {
274
+ context: {
275
+ request,
276
+ ...lastResponse === void 0 ? {} : { lastResponse },
277
+ ...knownCommitment ? { knownCommitment } : {}
278
+ },
279
+ cause,
280
+ ...transaction ? { transaction } : {}
281
+ });
81
282
  }
82
283
  }
284
+ /** Signed faucet bytes as submission evidence, when they match the hash. */
285
+ function fundingSubmission(signedTransaction, networkHash, hash) {
286
+ try {
287
+ const evidence = require_sendInvocation.createSubmissionEvidence(signedTransaction, networkHash);
288
+ return bytesEqual(evidence.transactionHash, hash) ? evidence : void 0;
289
+ } catch {
290
+ return;
291
+ }
292
+ }
293
+ function bytesEqual(left, right) {
294
+ return left.length === right.length && left.every((byte, i) => byte === right[i]);
295
+ }
296
+ function unsupported(message, value) {
297
+ return new require_decimal.ThruputError("rpcValueUnsupported", message, { context: { value } });
298
+ }
83
299
  //#endregion
84
300
  //#region src/actions/public/getContractEvents.ts
85
301
  /**
@@ -87,7 +303,7 @@ async function requestAirdrop(client, options) {
87
303
  *
88
304
  * No additional pages are fetched. Pass the returned cursor into the next call
89
305
  * with the same filters. Malformed events and unexpected signatures throw
90
- * ContractDecodeError rather than silently disappearing from the page.
306
+ * code `contractDecodeFailed` rather than silently disappearing from the page.
91
307
  *
92
308
  * @example
93
309
  * ```ts
@@ -114,7 +330,7 @@ async function getContractEvents(client, query, options) {
114
330
  ...page,
115
331
  events: page.events.map(({ event: raw, ...identity }) => {
116
332
  const decoded = event.decode(raw);
117
- if (decoded === null) throw new require_contract.ContractDecodeError("Event query returned an unexpected event signature");
333
+ if (decoded === null) throw require_contract.contractDecodeFailed("Event query returned an unexpected event signature");
118
334
  return {
119
335
  ...decoded,
120
336
  ...identity,
@@ -125,14 +341,6 @@ async function getContractEvents(client, query, options) {
125
341
  }
126
342
  //#endregion
127
343
  //#region src/actions/public/historyWalk.ts
128
- var HistoryWalkError = class extends Error {
129
- page;
130
- constructor(message, page) {
131
- super(message);
132
- this.page = page;
133
- this.name = "HistoryWalkError";
134
- }
135
- };
136
344
  const compare = (a, b) => {
137
345
  for (let i = 0; i < 3; i++) {
138
346
  if (a[i] < b[i]) return -1;
@@ -150,7 +358,7 @@ async function* walkHistory(fetch, kind, scope, options) {
150
358
  const page = await fetch(cursor);
151
359
  options.signal?.throwIfAborted();
152
360
  const fail = (message) => {
153
- throw new HistoryWalkError(message, page);
361
+ throw new require_decimal.ThruputError("historyWalkFailed", message, { context: { page } });
154
362
  };
155
363
  const rows = kind === "events" ? page.events : page.transactions;
156
364
  if (watermark === void 0) {
@@ -243,7 +451,7 @@ async function readViews(client, request, options) {
243
451
  stateBlockHeight: response.stateBlockHeight
244
452
  });
245
453
  } catch (cause) {
246
- throw new require_contract.ContractDecodeError(`Failed to decode readViews result ${index} (${call.name})`, { cause });
454
+ throw require_contract.contractDecodeFailed(`Failed to decode readViews result ${index} (${call.name})`, { cause });
247
455
  }
248
456
  });
249
457
  return {
@@ -287,7 +495,7 @@ async function getContractSpec(client, request, options) {
287
495
  client.requireMethods(["getContractDeployment", "getContractArtifact"]);
288
496
  const address = new Uint8Array(request.address);
289
497
  const result = await client.getContractDeployment({ address }, options);
290
- if (!require_contract.bytesEqual(address, result.address)) throw new require_contract.ContractVerificationError("Contract deployment address mismatch");
498
+ if (!require_contract.bytesEqual(address, result.address)) throw require_contract.contractVerificationFailed("Contract deployment address mismatch");
291
499
  if (result.deployment === null) return {
292
500
  ...result,
293
501
  artifactSpec: null
@@ -300,11 +508,11 @@ async function getContractSpec(client, request, options) {
300
508
  /** Shared identity validation for explicit deployments and effective contract selection. */
301
509
  async function readDeploymentSpec(client, deployment, options) {
302
510
  const artifact = await client.getContractArtifact({ hash: deployment.hash }, options);
303
- if (!require_contract.bytesEqual(artifact.hash, deployment.hash)) throw new require_contract.ContractVerificationError("Contract artifact response hash mismatch");
511
+ if (!require_contract.bytesEqual(artifact.hash, deployment.hash)) throw require_contract.contractVerificationFailed("Contract artifact response hash mismatch");
304
512
  const artifactSpec = require_contract.readContractArtifactSpec(artifact.contractXdr, (0, _thruputchain_protocol.sha256Hash)(deployment.hash));
305
513
  const contract = (0, _thruputchain_protocol.deserialize)(artifact.contractXdr, _thruputchain_protocol.codec.Contract);
306
514
  const size = contract.contract_type === _thruputchain_protocol.ContractType.kRv32 ? contract.rv32_contract.data.length : 0;
307
- if (contract.contract_type !== deployment.contractType || size !== deployment.size) throw new require_contract.ContractVerificationError("Contract artifact does not match deployment metadata");
515
+ if (contract.contract_type !== deployment.contractType || size !== deployment.size) throw require_contract.contractVerificationFailed("Contract artifact does not match deployment metadata");
308
516
  return artifactSpec;
309
517
  }
310
518
  //#endregion
@@ -326,14 +534,14 @@ async function getEffectiveContractSpec(client, request, options) {
326
534
  address,
327
535
  context
328
536
  }, options);
329
- if (!require_contract.bytesEqual(address, result.address) || result.context !== context) throw new require_contract.ContractVerificationError("Effective contract request identity mismatch");
330
- if (result.selection instanceof require_codec.UnsupportedRpcValue) throw new require_readError.RpcCompatibilityError("Unsupported effective contract selection");
537
+ if (!require_contract.bytesEqual(address, result.address) || result.context !== context) throw require_contract.contractVerificationFailed("Effective contract request identity mismatch");
538
+ if (result.selection instanceof require_decimal.UnsupportedRpcValue) throw new require_decimal.ThruputError("rpcValueUnsupported", "Unsupported effective contract selection", { context: { value: result.selection } });
331
539
  if (result.selection === null) return {
332
540
  ...result,
333
541
  artifactSpec: null,
334
542
  nativeInterface: null
335
543
  };
336
- if (context === "nested" && result.selection.source === "networkDefault") throw new require_contract.ContractVerificationError("Network default cannot apply to a nested invocation");
544
+ if (context === "nested" && result.selection.source === "networkDefault") throw require_contract.contractVerificationFailed("Network default cannot apply to a nested invocation");
337
545
  const contract = result.selection.contract;
338
546
  const artifactSpec = await readDeploymentSpec(client, contract, options);
339
547
  const nativeInterface = artifactSpec.kind === "native" && require_contract.bytesEqual(contract.hash, nativeWalletHash) ? {
@@ -351,11 +559,13 @@ async function getEffectiveContractSpec(client, request, options) {
351
559
  /**
352
560
  * Interpret a known DefaultWallet root using built-in binding descriptors.
353
561
  * Call only after identifying the root as DefaultWallet; matching selectors
354
- * alone do not establish wallet identity. Malformed recognized inputs throw.
562
+ * alone do not establish wallet identity. Malformed recognized inputs throw,
563
+ * as does an `execute` that mints or forwards auth tokens.
355
564
  */
356
565
  function decodeDefaultWalletRequests(root) {
357
566
  if (require_contract.bytesEqual(root.entrypoint, require_dev_wallet.DefaultWallet.v0_1.execute.entrypoint)) {
358
- const { calls } = require_dev_wallet.DefaultWallet.v0_1.execute.decodeArgs(root.calldata);
567
+ const { mints, calls } = require_dev_wallet.DefaultWallet.v0_1.execute.decodeArgs(root.calldata);
568
+ if (mints.length > 0 || calls.some((call) => call.tokens.length > 0)) throw new Error("DefaultWallet.execute mints or forwards auth tokens, which requested calls cannot represent");
359
569
  return {
360
570
  wrapper: "DefaultWallet.execute",
361
571
  requestedCalls: calls.map((call) => ({
@@ -392,7 +602,7 @@ async function readTransactionInput(client, request, options) {
392
602
  client.requireMethods(["getTransactionInput"]);
393
603
  const hash = new Uint8Array(request.transactionHash);
394
604
  const result = await client.getTransactionInput({ transactionHash: hash }, options);
395
- if (result instanceof require_codec.UnsupportedRpcValue || result.status === "unavailable") return result;
605
+ if (result instanceof require_decimal.UnsupportedRpcValue || result.status === "unavailable") return result;
396
606
  try {
397
607
  if (result.transactionXdr.length > 4 * 1024 * 1024) throw new Error("Transaction input exceeds 4 MiB");
398
608
  if (!require_contract.bytesEqual(result.transactionHash, hash) || !require_contract.bytesEqual((0, _noble_hashes_sha2_js.sha256)(result.transactionXdr), hash)) throw new Error("Retained transaction input hash mismatch");
@@ -403,40 +613,42 @@ async function readTransactionInput(client, request, options) {
403
613
  transaction
404
614
  };
405
615
  } catch (cause) {
406
- throw new require_contract.ContractVerificationError(cause instanceof Error ? cause.message : "Invalid transaction input", { cause });
616
+ throw require_contract.contractVerificationFailed(require_contract.errorText(cause) ?? "Invalid transaction input", { cause });
407
617
  }
408
618
  }
409
619
  //#endregion
410
620
  //#region src/actions/wallet/sendTransaction.ts
411
621
  /**
412
622
  * Serialize and submit once through the native RPC boundary.
413
- * Unknown admission throws TransactionObservationError with the signed bytes and
414
- * destination discovery network; that network does not prove the signing network
415
- * of an already-signed envelope. RPC and transport failures propagate unchanged.
623
+ * Every failure has `transaction` facts with the signed bytes and destination
624
+ * discovery network; that network does not prove the signing network of an
625
+ * already-signed envelope. Unknown admission throws code
626
+ * `transactionAdmissionUnsupported`. RPC and transport failures keep their
627
+ * code, with outcome `unknown`, or `notSubmitted` for a local request error.
416
628
  */
417
629
  async function sendTransaction(client, signedTx, options) {
418
630
  const evidence = require_sendInvocation.createSubmissionEvidence((0, _thruputchain_protocol.serialize)(signedTx, _thruputchain_protocol.codec.SignedTransaction), client.discovery.network.networkHash);
419
- const result = await client.sendTransaction({ signedTransaction: evidence.signedTransaction }, options);
631
+ if (options?.signal?.aborted) throw require_sendInvocation.transactionNotSubmitted(evidence, "cancelled", options.signal.reason);
632
+ let result;
420
633
  try {
421
- require_sendInvocation.assertTransactionAdmission(result);
634
+ result = await client.sendTransaction({ signedTransaction: evidence.signedTransaction }, options);
422
635
  } catch (cause) {
423
- throw new require_sendInvocation.TransactionObservationError(evidence, cause, void 0, void 0, "submission");
636
+ const signal = options?.signal;
637
+ if (require_sendInvocation.isCancellation(cause, signal)) throw require_sendInvocation.transactionOutcomeUnknown(evidence, "cancelled", cause);
638
+ const local = require_sendInvocation.isLocalRequestError(cause, signal);
639
+ const reason = local ? "requestInvalid" : require_sendInvocation.reasonAfterDispatch(cause, signal);
640
+ if (!require_decimal.isThruputError(cause)) throw require_sendInvocation.transactionOutcomeUnknown(evidence, reason, cause);
641
+ throw require_contract.withTransactionFacts(cause, {
642
+ hash: evidence.transactionHash,
643
+ outcome: local ? "notSubmitted" : "unknown",
644
+ reason,
645
+ submission: evidence
646
+ });
424
647
  }
648
+ require_sendInvocation.assertTransactionAdmission(result, evidence);
425
649
  return (0, _thruputchain_protocol.sha256Hash)(result.transactionHash);
426
650
  }
427
651
  //#endregion
428
- Object.defineProperty(exports, "FundingObservationError", {
429
- enumerable: true,
430
- get: function() {
431
- return FundingObservationError;
432
- }
433
- });
434
- Object.defineProperty(exports, "HistoryWalkError", {
435
- enumerable: true,
436
- get: function() {
437
- return HistoryWalkError;
438
- }
439
- });
440
652
  Object.defineProperty(exports, "decodeDefaultWalletRequests", {
441
653
  enumerable: true,
442
654
  get: function() {
@@ -509,5 +721,17 @@ Object.defineProperty(exports, "sendTransaction", {
509
721
  return sendTransaction;
510
722
  }
511
723
  });
724
+ Object.defineProperty(exports, "waitForCommitment", {
725
+ enumerable: true,
726
+ get: function() {
727
+ return waitForCommitment;
728
+ }
729
+ });
730
+ Object.defineProperty(exports, "waitForTransactionReceipt", {
731
+ enumerable: true,
732
+ get: function() {
733
+ return waitForTransactionReceipt;
734
+ }
735
+ });
512
736
 
513
- //# sourceMappingURL=actions-DK_XBeVy.cjs.map
737
+ //# sourceMappingURL=actions-B2gV8Vzr.cjs.map