@thruputchain/client 0.0.0-stage → 0.26.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 (186) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +953 -2
  3. package/dist/actions-CXx6qzsv.cjs +513 -0
  4. package/dist/actions-CXx6qzsv.cjs.map +1 -0
  5. package/dist/actions-QHgiCqT6.js +430 -0
  6. package/dist/actions-QHgiCqT6.js.map +1 -0
  7. package/dist/actions.cjs +23 -0
  8. package/dist/actions.d.cts +4 -0
  9. package/dist/actions.d.ts +4 -0
  10. package/dist/actions.js +3 -0
  11. package/dist/artifact-BM_MVzhL.d.cts +35 -0
  12. package/dist/artifact-BM_MVzhL.d.cts.map +1 -0
  13. package/dist/artifact-BM_MVzhL.d.ts +35 -0
  14. package/dist/artifact-BM_MVzhL.d.ts.map +1 -0
  15. package/dist/client-JixxskeH.d.cts +746 -0
  16. package/dist/client-JixxskeH.d.cts.map +1 -0
  17. package/dist/client-JixxskeH.d.ts +746 -0
  18. package/dist/client-JixxskeH.d.ts.map +1 -0
  19. package/dist/codec-BHKoSaOP.js +9506 -0
  20. package/dist/codec-BHKoSaOP.js.map +1 -0
  21. package/dist/codec-C3OlYm98.cjs +9566 -0
  22. package/dist/codec-C3OlYm98.cjs.map +1 -0
  23. package/dist/contract-C7T2H2Oi.cjs +1628 -0
  24. package/dist/contract-C7T2H2Oi.cjs.map +1 -0
  25. package/dist/contract-DzvyyFCI.js +1472 -0
  26. package/dist/contract-DzvyyFCI.js.map +1 -0
  27. package/dist/contract.cjs +63 -0
  28. package/dist/contract.d.cts +4 -0
  29. package/dist/contract.d.ts +4 -0
  30. package/dist/contract.js +2 -0
  31. package/dist/contracts.cjs +1050 -0
  32. package/dist/contracts.cjs.map +1 -0
  33. package/dist/contracts.d.cts +397 -0
  34. package/dist/contracts.d.cts.map +1 -0
  35. package/dist/contracts.d.ts +397 -0
  36. package/dist/contracts.d.ts.map +1 -0
  37. package/dist/contracts.js +1030 -0
  38. package/dist/contracts.js.map +1 -0
  39. package/dist/dev_wallet-CSMA1PCt.js +497 -0
  40. package/dist/dev_wallet-CSMA1PCt.js.map +1 -0
  41. package/dist/dev_wallet-GX-NCAFk.cjs +530 -0
  42. package/dist/dev_wallet-GX-NCAFk.cjs.map +1 -0
  43. package/dist/domainSeparator-B_vU_zUD.cjs +102 -0
  44. package/dist/domainSeparator-B_vU_zUD.cjs.map +1 -0
  45. package/dist/domainSeparator-CBCvxIj-.js +79 -0
  46. package/dist/domainSeparator-CBCvxIj-.js.map +1 -0
  47. package/dist/execution-DYqPDn4O.d.cts +227 -0
  48. package/dist/execution-DYqPDn4O.d.cts.map +1 -0
  49. package/dist/execution-Dj6E4B_b.d.ts +227 -0
  50. package/dist/execution-Dj6E4B_b.d.ts.map +1 -0
  51. package/dist/hex-DIcaALXL.js +112 -0
  52. package/dist/hex-DIcaALXL.js.map +1 -0
  53. package/dist/hex-DkGpiZ5e.cjs +189 -0
  54. package/dist/hex-DkGpiZ5e.cjs.map +1 -0
  55. package/dist/index--5LsCotr.d.ts +192 -0
  56. package/dist/index--5LsCotr.d.ts.map +1 -0
  57. package/dist/index-1-rFirYe.d.cts +90 -0
  58. package/dist/index-1-rFirYe.d.cts.map +1 -0
  59. package/dist/index-B5KqSHeL.d.cts +192 -0
  60. package/dist/index-B5KqSHeL.d.cts.map +1 -0
  61. package/dist/index-BraLWObY.d.cts +164 -0
  62. package/dist/index-BraLWObY.d.cts.map +1 -0
  63. package/dist/index-ByNNqY7S.d.cts +83 -0
  64. package/dist/index-ByNNqY7S.d.cts.map +1 -0
  65. package/dist/index-ByvV2UF6.d.ts +164 -0
  66. package/dist/index-ByvV2UF6.d.ts.map +1 -0
  67. package/dist/index-CG2WRtGa.d.cts +164 -0
  68. package/dist/index-CG2WRtGa.d.cts.map +1 -0
  69. package/dist/index-CIHK7Ew9.d.cts +303 -0
  70. package/dist/index-CIHK7Ew9.d.cts.map +1 -0
  71. package/dist/index-CIHK7Ew9.d.ts +303 -0
  72. package/dist/index-CIHK7Ew9.d.ts.map +1 -0
  73. package/dist/index-CVrhB9Dr.d.cts +263 -0
  74. package/dist/index-CVrhB9Dr.d.cts.map +1 -0
  75. package/dist/index-D89ur7mO.d.ts +164 -0
  76. package/dist/index-D89ur7mO.d.ts.map +1 -0
  77. package/dist/index-DzrLv3EA.d.cts +82 -0
  78. package/dist/index-DzrLv3EA.d.cts.map +1 -0
  79. package/dist/index-DzrLv3EA.d.ts +82 -0
  80. package/dist/index-DzrLv3EA.d.ts.map +1 -0
  81. package/dist/index-SV-inhhO.d.ts +90 -0
  82. package/dist/index-SV-inhhO.d.ts.map +1 -0
  83. package/dist/index-dJ65V8se.d.ts +263 -0
  84. package/dist/index-dJ65V8se.d.ts.map +1 -0
  85. package/dist/index-fdTURpBk.d.ts +83 -0
  86. package/dist/index-fdTURpBk.d.ts.map +1 -0
  87. package/dist/index.cjs +445 -0
  88. package/dist/index.cjs.map +1 -0
  89. package/dist/index.d.cts +174 -0
  90. package/dist/index.d.cts.map +1 -0
  91. package/dist/index.d.ts +174 -0
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/index.js +189 -0
  94. package/dist/index.js.map +1 -0
  95. package/dist/provider.cjs +101 -0
  96. package/dist/provider.cjs.map +1 -0
  97. package/dist/provider.d.cts +2 -0
  98. package/dist/provider.d.ts +2 -0
  99. package/dist/provider.js +76 -0
  100. package/dist/provider.js.map +1 -0
  101. package/dist/readError-AoNjzW75.cjs +604 -0
  102. package/dist/readError-AoNjzW75.cjs.map +1 -0
  103. package/dist/readError-CZPYcW__.js +551 -0
  104. package/dist/readError-CZPYcW__.js.map +1 -0
  105. package/dist/readViews-DJyqc7im.d.cts +604 -0
  106. package/dist/readViews-DJyqc7im.d.cts.map +1 -0
  107. package/dist/readViews-DQoaUORa.d.ts +604 -0
  108. package/dist/readViews-DQoaUORa.d.ts.map +1 -0
  109. package/dist/rolldown-runtime-D6vf50IK.cjs +28 -0
  110. package/dist/sendInvocation-BwabRa2N.js +505 -0
  111. package/dist/sendInvocation-BwabRa2N.js.map +1 -0
  112. package/dist/sendInvocation-qO8AZcmU.cjs +661 -0
  113. package/dist/sendInvocation-qO8AZcmU.cjs.map +1 -0
  114. package/dist/sign-BewmV_EL.cjs +139 -0
  115. package/dist/sign-BewmV_EL.cjs.map +1 -0
  116. package/dist/sign-DVIRyW8Y.js +122 -0
  117. package/dist/sign-DVIRyW8Y.js.map +1 -0
  118. package/dist/sign-Ve0eetRO.d.ts +48 -0
  119. package/dist/sign-Ve0eetRO.d.ts.map +1 -0
  120. package/dist/sign-eUT0iGQG.d.cts +48 -0
  121. package/dist/sign-eUT0iGQG.d.cts.map +1 -0
  122. package/dist/signed-op.cjs +9 -0
  123. package/dist/signed-op.d.cts +3 -0
  124. package/dist/signed-op.d.ts +3 -0
  125. package/dist/signed-op.js +3 -0
  126. package/dist/signedOp-C52gOgpR.js +166 -0
  127. package/dist/signedOp-C52gOgpR.js.map +1 -0
  128. package/dist/signedOp-oqAXEqmE.cjs +183 -0
  129. package/dist/signedOp-oqAXEqmE.cjs.map +1 -0
  130. package/dist/signed_op-BokEDWr-.js +154 -0
  131. package/dist/signed_op-BokEDWr-.js.map +1 -0
  132. package/dist/signed_op-C4lY_TCc.d.ts +58 -0
  133. package/dist/signed_op-C4lY_TCc.d.ts.map +1 -0
  134. package/dist/signed_op-DX5WuyEh.d.cts +58 -0
  135. package/dist/signed_op-DX5WuyEh.d.cts.map +1 -0
  136. package/dist/signed_op-q8KKSm5e.cjs +175 -0
  137. package/dist/signed_op-q8KKSm5e.cjs.map +1 -0
  138. package/dist/signers-BFP84wJP.cjs +137 -0
  139. package/dist/signers-BFP84wJP.cjs.map +1 -0
  140. package/dist/signers-CzOSedwJ.js +120 -0
  141. package/dist/signers-CzOSedwJ.js.map +1 -0
  142. package/dist/signers.cjs +5 -0
  143. package/dist/signers.d.cts +3 -0
  144. package/dist/signers.d.ts +3 -0
  145. package/dist/signers.js +2 -0
  146. package/dist/size-506oTE28.js +91 -0
  147. package/dist/size-506oTE28.js.map +1 -0
  148. package/dist/size-OAFfOthl.cjs +108 -0
  149. package/dist/size-OAFfOthl.cjs.map +1 -0
  150. package/dist/transaction-CwkQxQOx.js +24 -0
  151. package/dist/transaction-CwkQxQOx.js.map +1 -0
  152. package/dist/transaction-DrSrCJ5y.cjs +47 -0
  153. package/dist/transaction-DrSrCJ5y.cjs.map +1 -0
  154. package/dist/transaction.cjs +13 -0
  155. package/dist/transaction.d.cts +3 -0
  156. package/dist/transaction.d.ts +3 -0
  157. package/dist/transaction.js +4 -0
  158. package/dist/transactionHash-CO9ajbvU.js +24 -0
  159. package/dist/transactionHash-CO9ajbvU.js.map +1 -0
  160. package/dist/transactionHash-D5yf4KoL.cjs +29 -0
  161. package/dist/transactionHash-D5yf4KoL.cjs.map +1 -0
  162. package/dist/transport-CBFwAIIv.js +261 -0
  163. package/dist/transport-CBFwAIIv.js.map +1 -0
  164. package/dist/transport-tWxKhXUt.cjs +279 -0
  165. package/dist/transport-tWxKhXUt.cjs.map +1 -0
  166. package/dist/transport.cjs +19 -0
  167. package/dist/transport.d.cts +3 -0
  168. package/dist/transport.d.ts +3 -0
  169. package/dist/transport.js +4 -0
  170. package/dist/types-BE40oD_Q.d.cts +18 -0
  171. package/dist/types-BE40oD_Q.d.cts.map +1 -0
  172. package/dist/types-BE40oD_Q.d.ts +18 -0
  173. package/dist/types-BE40oD_Q.d.ts.map +1 -0
  174. package/dist/validation-4w-vDGAi.cjs +543 -0
  175. package/dist/validation-4w-vDGAi.cjs.map +1 -0
  176. package/dist/validation-eXATmgO0.js +411 -0
  177. package/dist/validation-eXATmgO0.js.map +1 -0
  178. package/dist/wallet-7RELuTkf.js +667 -0
  179. package/dist/wallet-7RELuTkf.js.map +1 -0
  180. package/dist/wallet-T_JazXRc.cjs +709 -0
  181. package/dist/wallet-T_JazXRc.cjs.map +1 -0
  182. package/dist/wallet.cjs +27 -0
  183. package/dist/wallet.d.cts +3 -0
  184. package/dist/wallet.d.ts +3 -0
  185. package/dist/wallet.js +3 -0
  186. package/package.json +122 -4
@@ -0,0 +1,28 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ Object.defineProperty(exports, "__toESM", {
24
+ enumerable: true,
25
+ get: function() {
26
+ return __toESM;
27
+ }
28
+ });
@@ -0,0 +1,505 @@
1
+ import { r as createTransaction, t as signTransaction } from "./sign-DVIRyW8Y.js";
2
+ import { o as bytesEqual$1 } from "./contract-DzvyyFCI.js";
3
+ import { n as RpcRequestValidationError, r as UnsupportedRpcValue, t as RpcDecodingError } from "./codec-BHKoSaOP.js";
4
+ import { g as toBase58 } from "./hex-DIcaALXL.js";
5
+ import { t as hashSignedTransaction } from "./transactionHash-CO9ajbvU.js";
6
+ import { i as NativeRpcError, n as RpcCompatibilityError, t as classifyReadError } from "./readError-CZPYcW__.js";
7
+ import { r as DefaultWallet, t as DevWallet } from "./dev_wallet-CSMA1PCt.js";
8
+ import "./validation-eXATmgO0.js";
9
+ import { blockHeight, codec, contractAddress, deserialize, gasAmount, serialize, sha256Hash } from "@thruputchain/protocol";
10
+ import { fixedBytes } from "@thruputchain/xdr";
11
+ //#region src/actions/deadline.ts
12
+ /** Run one operation within the caller's wall-clock budget and cancellation signal. */
13
+ async function beforeDeadline(operation, deadline, caller, timeout) {
14
+ caller?.throwIfAborted();
15
+ if (performance.now() >= deadline) throw timeout();
16
+ const controller = new AbortController();
17
+ const signal = caller ? AbortSignal.any([caller, controller.signal]) : controller.signal;
18
+ let timer;
19
+ let onAbort = () => {};
20
+ try {
21
+ return await Promise.race([new Promise((_, reject) => {
22
+ onAbort = () => reject(signal.reason);
23
+ signal.addEventListener("abort", onAbort, { once: true });
24
+ timer = setTimeout(() => controller.abort(timeout()), Math.ceil(Math.max(0, deadline - performance.now())));
25
+ }), operation(signal)]);
26
+ } finally {
27
+ if (timer !== void 0) clearTimeout(timer);
28
+ signal.removeEventListener("abort", onAbort);
29
+ controller.abort();
30
+ }
31
+ }
32
+ function validateTimer(value, field) {
33
+ if (!Number.isFinite(value) || value < 0 || value > 2147483647) throw new RangeError(`${field} must be between 0 and 2147483647`);
34
+ }
35
+ function waitDelay(delay, signal) {
36
+ return new Promise((resolve, reject) => {
37
+ signal.throwIfAborted();
38
+ const finish = () => {
39
+ signal.removeEventListener("abort", abort);
40
+ resolve();
41
+ };
42
+ const timer = setTimeout(finish, delay);
43
+ const abort = () => {
44
+ clearTimeout(timer);
45
+ signal.removeEventListener("abort", abort);
46
+ reject(signal.reason);
47
+ };
48
+ signal.addEventListener("abort", abort, { once: true });
49
+ });
50
+ }
51
+ //#endregion
52
+ //#region src/actions/public/waitForTransactionReceipt.ts
53
+ /** Observation stopped; neither timeout nor cancellation proves nonexecution. */
54
+ var TransactionReceiptObservationError = class extends Error {
55
+ transactionHash;
56
+ knownCommitment;
57
+ lastStatus;
58
+ constructor(transactionHash, knownCommitment, lastStatus, cause) {
59
+ super(`Could not observe transaction ${toBase58(transactionHash)}`, { cause });
60
+ this.transactionHash = transactionHash;
61
+ this.knownCommitment = knownCommitment;
62
+ this.lastStatus = lastStatus;
63
+ this.name = "TransactionReceiptObservationError";
64
+ }
65
+ };
66
+ var TransactionReceiptTimeoutError = class extends TransactionReceiptObservationError {
67
+ constructor(transactionHash, knownCommitment, lastStatus, cause) {
68
+ super(transactionHash, knownCommitment, lastStatus, cause);
69
+ this.name = "TransactionReceiptTimeoutError";
70
+ this.message = `Timed out waiting for transaction ${toBase58(transactionHash)}`;
71
+ }
72
+ };
73
+ const equal = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
74
+ /** Return any committed receipt, including failed execution. Never sign or resubmit. */
75
+ async function waitForTransactionReceipt(client, transactionHash, options = {}) {
76
+ return await observe(client, transactionHash, options, false);
77
+ }
78
+ /** Observe commitment independently of receipt availability or execution success. */
79
+ async function waitForCommitment(client, transactionHash, options = {}) {
80
+ return await observe(client, transactionHash, options, true);
81
+ }
82
+ function snapshotStatus(status) {
83
+ const copy = (value) => {
84
+ if (value instanceof UnsupportedRpcValue) return new UnsupportedRpcValue(structuredClone(value.raw));
85
+ if (Array.isArray(value)) return value.map(copy);
86
+ if (ArrayBuffer.isView(value)) return structuredClone(value);
87
+ if (value !== null && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, copy(entry)]));
88
+ return value;
89
+ };
90
+ return copy(status);
91
+ }
92
+ async function observe(client, hash, options, commitmentOnly) {
93
+ const timeoutMs = options.timeoutMs ?? 3e4;
94
+ const interval = options.pollingIntervalMs ?? 250;
95
+ validateTimer(timeoutMs, "timeoutMs");
96
+ validateTimer(interval, "pollingIntervalMs");
97
+ const transactionHash = new Uint8Array(hash);
98
+ const networkHash = new Uint8Array(options.expectedNetworkHash ?? client.discovery.network.networkHash);
99
+ if (transactionHash.length !== 32 || networkHash.length !== 32) throw new RangeError("Transaction and network hashes must contain 32 bytes");
100
+ let commitment;
101
+ let lastStatus;
102
+ if (options.knownCommitment) {
103
+ const known = options.knownCommitment;
104
+ if (!equal(known.transactionHash, transactionHash) || !equal(known.networkHash, networkHash) || typeof known.blockHeight !== "bigint" || known.blockHeight < 0n || known.blockHeight > 9223372036854775807n) throw new RpcCompatibilityError("Known commitment does not match the transaction/network context");
105
+ commitment = {
106
+ transactionHash: transactionHash.slice(),
107
+ networkHash: networkHash.slice(),
108
+ blockHeight: known.blockHeight
109
+ };
110
+ lastStatus = {
111
+ status: "committed",
112
+ blockHeight: known.blockHeight
113
+ };
114
+ }
115
+ client.requireMethods([
116
+ "getNetworkInfo",
117
+ "getTransactionReceipt",
118
+ "getTransactionStatus"
119
+ ]);
120
+ const deadline = performance.now() + timeoutMs;
121
+ let lastFailure;
122
+ let failures = 0;
123
+ const timeout = () => new TransactionReceiptTimeoutError(transactionHash.slice(), commitment && structuredClone(commitment), lastStatus, lastFailure);
124
+ const run = (operation) => beforeDeadline(operation, deadline, options.signal, timeout);
125
+ const retain = (blockHeight) => {
126
+ if (commitment && commitment.blockHeight !== blockHeight) throw new RpcCompatibilityError("Conflicting commitment heights for the same transaction");
127
+ commitment = {
128
+ transactionHash: transactionHash.slice(),
129
+ networkHash: networkHash.slice(),
130
+ blockHeight
131
+ };
132
+ lastStatus = {
133
+ status: "committed",
134
+ blockHeight
135
+ };
136
+ };
137
+ try {
138
+ while (true) {
139
+ let retryAfterMs;
140
+ let networkVerified = false;
141
+ let failed = false;
142
+ try {
143
+ if (!equal((await run((signal) => client.getNetworkInfo({}, { signal }))).networkHash, networkHash)) throw new RpcCompatibilityError("Observation endpoint network changed");
144
+ networkVerified = true;
145
+ if (commitmentOnly && commitment) return structuredClone(commitment);
146
+ const receipt = await run((signal) => client.getTransactionReceipt({ transactionHash }, { signal }));
147
+ if (receipt) {
148
+ retain(receipt.blockHeight);
149
+ return commitmentOnly ? structuredClone(commitment) : receipt;
150
+ }
151
+ } catch (cause) {
152
+ lastFailure = cause;
153
+ failed = true;
154
+ if (cause instanceof NativeRpcError && cause.decoded.classification === "known") {
155
+ const data = cause.decoded.data;
156
+ if (data.kind === "backendDataInvalid" && data.observation) {
157
+ retain(data.observation.blockHeight);
158
+ if (commitmentOnly) return structuredClone(commitment);
159
+ }
160
+ if ("retryAfterMs" in data) retryAfterMs = data.retryAfterMs;
161
+ }
162
+ if (options.signal?.aborted || classifyReadError(cause, options) !== "transient") throw cause;
163
+ }
164
+ let observedStatus;
165
+ if (networkVerified) try {
166
+ const status = await run((signal) => client.getTransactionStatus({ transactionHash }, { signal }));
167
+ if (!(status instanceof UnsupportedRpcValue) && status.status === "committed") retain(status.blockHeight);
168
+ else if (!commitment) lastStatus = snapshotStatus(status);
169
+ observedStatus = status;
170
+ } catch (cause) {
171
+ if (cause instanceof RpcCompatibilityError || cause instanceof RpcDecodingError || cause instanceof RpcRequestValidationError || classifyReadError(cause, options) === "permanent") throw cause;
172
+ options.signal?.throwIfAborted();
173
+ lastFailure = cause;
174
+ failed = true;
175
+ if (cause instanceof NativeRpcError && cause.decoded.classification === "known" && "retryAfterMs" in cause.decoded.data) {
176
+ const hint = cause.decoded.data.retryAfterMs;
177
+ if (hint !== void 0 && (retryAfterMs === void 0 || hint > retryAfterMs)) retryAfterMs = hint;
178
+ }
179
+ }
180
+ if (observedStatus !== void 0) options.onStatus?.(observedStatus);
181
+ if (failed) failures++;
182
+ else {
183
+ failures = 0;
184
+ lastFailure = void 0;
185
+ }
186
+ if (commitmentOnly && commitment) return structuredClone(commitment);
187
+ const backoff = failures ? Math.min(5e3, Math.max(1, interval) * 2 ** Math.min(failures - 1, 8)) * (.5 + Math.random() / 2) : interval;
188
+ const remaining = deadline - performance.now();
189
+ if (retryAfterMs !== void 0 && retryAfterMs > BigInt(Math.max(0, Math.floor(remaining)))) throw timeout();
190
+ const delay = Math.max(backoff, Number(retryAfterMs ?? 0n));
191
+ await run((signal) => waitDelay(Math.min(delay, Math.max(0, remaining)), signal));
192
+ }
193
+ } catch (cause) {
194
+ if (cause instanceof TransactionReceiptTimeoutError) throw cause;
195
+ throw new TransactionReceiptObservationError(transactionHash, commitment && structuredClone(commitment), lastStatus, cause);
196
+ }
197
+ }
198
+ //#endregion
199
+ //#region src/wallet/invocationAdapter.ts
200
+ /** Build a root batch directly, copying call bytes before asynchronous work. */
201
+ function createDefaultWalletBatchInvocation(accountAddress, request) {
202
+ if (!Array.isArray(request.invocations) || request.invocations.length < 1 || request.invocations.length > 16) throw new RangeError("DefaultWallet requires 1 to 16 calls");
203
+ return DefaultWallet.v0_1.execute.invocation(contractAddress(new Uint8Array(accountAddress)), request.gasLimit, { calls: request.invocations.map((inner) => ({
204
+ target: contractAddress(new Uint8Array(inner.invoked_address)),
205
+ entrypoint: fixedBytes(new Uint8Array(inner.entrypoint), 8),
206
+ gas_limit: inner.gas_limit,
207
+ calldata: new Uint8Array(inner.calldata)
208
+ })) });
209
+ }
210
+ /** Define an invocation adapter while preserving its request type. */
211
+ function defineWalletInvocationAdapter(adapter) {
212
+ return adapter;
213
+ }
214
+ /** Wrap one call through the native-compatible DefaultWallet interface. */
215
+ const defaultWalletAdapter = defineWalletInvocationAdapter({
216
+ createBatchRootInvocation: createDefaultWalletBatchInvocation,
217
+ decodeExecutionReturns: (receipt) => DefaultWallet.v0_1.execute.decodeReceipt(receipt).value,
218
+ createDeploymentInvocation(account, deployment, options) {
219
+ if (options.initializer && !bytesEqual$1(options.initializer.invoked_address, deployment.address)) throw new Error("Initializer must target the predicted deployment address");
220
+ if (options.amount < 0n) throw new RangeError("Deployment amount must not be negative");
221
+ return DefaultWallet.v0_1.deploy.invocation(account, options.gasLimit, {
222
+ nonce: fixedBytes(deployment.deploymentNonce, 32),
223
+ contractHash: fixedBytes(deployment.contractHash, 32),
224
+ amount: options.amount,
225
+ initializer: options.initializer ? {
226
+ entrypoint: fixedBytes(options.initializer.entrypoint, 8),
227
+ gas_limit: options.initializer.gas_limit,
228
+ calldata: options.initializer.calldata
229
+ } : null
230
+ });
231
+ },
232
+ decodeDeploymentReceipt: (receipt) => DefaultWallet.v0_1.deploy.decodeReceipt(receipt).value,
233
+ createRootInvocation(accountAddress, request) {
234
+ return createDefaultWalletBatchInvocation(accountAddress, {
235
+ invocations: [request.invocation],
236
+ gasLimit: request.gasLimit
237
+ });
238
+ }
239
+ });
240
+ /** Wrap one call through the legacy DevWallet. Unified deployment is unsupported. */
241
+ const devWalletAdapter = defineWalletInvocationAdapter({
242
+ decodeExecutionReturns: () => null,
243
+ createRootInvocation(accountAddress, request) {
244
+ return DevWallet.v0_1.doAction.invocation(contractAddress(new Uint8Array(accountAddress)), request.gasLimit, { invocationBytes: serialize(request.invocation, codec.Invocation) });
245
+ }
246
+ });
247
+ //#endregion
248
+ //#region src/wallet/execution.ts
249
+ /** A committed execution failure, retaining the complete native receipt. */
250
+ var TransactionExecutionError = class extends Error {
251
+ receipt;
252
+ submission;
253
+ constructor(receipt, submission) {
254
+ super(receipt.execution instanceof UnsupportedRpcValue ? `Transaction ${toBase58(receipt.transactionHash)} has an unsupported execution outcome` : `Transaction ${toBase58(receipt.transactionHash)} execution failed (${receipt.execution.result})`);
255
+ this.receipt = receipt;
256
+ this.submission = submission;
257
+ this.name = "TransactionExecutionError";
258
+ }
259
+ };
260
+ /** A future execution variant is unsupported, never inferred to be success or failure. */
261
+ var UnsupportedTransactionOutcomeError = class extends TransactionExecutionError {
262
+ constructor(receipt, submission) {
263
+ super(receipt, submission);
264
+ this.name = "UnsupportedTransactionOutcomeError";
265
+ }
266
+ };
267
+ function assertTransactionSuccess(receipt, submission) {
268
+ if (receipt.execution instanceof UnsupportedRpcValue) throw new UnsupportedTransactionOutcomeError(receipt, submission);
269
+ if (receipt.execution.result !== "return") throw new TransactionExecutionError(receipt, submission);
270
+ }
271
+ /** A submit response that does not establish the currently supported admission outcome. */
272
+ var UnsupportedTransactionAdmissionError = class extends Error {
273
+ response;
274
+ constructor(response) {
275
+ super("Transaction submission returned an unsupported admission outcome");
276
+ this.response = response;
277
+ this.name = "UnsupportedTransactionAdmissionError";
278
+ }
279
+ };
280
+ /** Keep low-level future values intact, but never project them into an admitted hash. */
281
+ function assertTransactionAdmission(response) {
282
+ if (response.admission !== "accepted") throw new UnsupportedTransactionAdmissionError(response);
283
+ }
284
+ /** Snapshot approved bytes before submission; accessor copies protect the retained record. */
285
+ function createSubmissionEvidence(bytes, network) {
286
+ const signedTransaction = new Uint8Array(bytes);
287
+ const networkHash = new Uint8Array(network);
288
+ if (networkHash.length !== 32) throw new RangeError("networkHash must contain 32 bytes");
289
+ const transactionHash = hashSignedTransaction(deserialize(signedTransaction, codec.SignedTransaction));
290
+ return Object.freeze({
291
+ get signedTransaction() {
292
+ return signedTransaction.slice();
293
+ },
294
+ get transactionHash() {
295
+ return transactionHash.slice();
296
+ },
297
+ get networkHash() {
298
+ return networkHash.slice();
299
+ }
300
+ });
301
+ }
302
+ /** Submission or observation stopped, preserving exact approved bytes and commitment. */
303
+ var TransactionObservationError = class extends Error {
304
+ submission;
305
+ submissionCause;
306
+ knownCommitment;
307
+ phase;
308
+ constructor(submission, cause, submissionCause, knownCommitment, phase = "observation") {
309
+ super(`Could not complete transaction ${toBase58(submission.transactionHash)}`, { cause });
310
+ this.submission = submission;
311
+ this.submissionCause = submissionCause;
312
+ this.knownCommitment = knownCommitment;
313
+ this.phase = phase;
314
+ this.name = "TransactionObservationError";
315
+ }
316
+ get transactionHash() {
317
+ return this.submission.transactionHash;
318
+ }
319
+ };
320
+ /** Submit once, then reconcile only by reads. No path replaces or repeats signed bytes. */
321
+ async function submitAndObserve(client, evidence, submit, options, wasDispatched) {
322
+ const submission = createSubmissionEvidence(evidence.signedTransaction, evidence.networkHash);
323
+ const timeoutMs = options?.timeoutMs ?? 3e4;
324
+ validateTimer(timeoutMs, "timeoutMs");
325
+ const deadline = performance.now() + timeoutMs;
326
+ let submissionCause;
327
+ try {
328
+ options?.signal?.throwIfAborted();
329
+ if (timeoutMs === 0) throw new Error("Transaction submission timed out before dispatch");
330
+ } catch (cause) {
331
+ throw new TransactionObservationError(submission, cause, void 0, void 0, "beforeSubmission");
332
+ }
333
+ try {
334
+ await beforeDeadline(submit, deadline, options?.signal, () => /* @__PURE__ */ new Error("Transaction submission timed out"));
335
+ } catch (cause) {
336
+ if (wasDispatched?.() === false || cause instanceof RpcRequestValidationError || cause instanceof RpcCompatibilityError) throw new TransactionObservationError(submission, cause, void 0, void 0, "beforeSubmission");
337
+ if (cause instanceof NativeRpcError && cause.decoded.classification === "known" && (cause.decoded.data.kind === "invalidParams" || cause.decoded.data.kind === "transactionInvalid" || cause.decoded.data.kind === "transactionRejected")) throw new TransactionObservationError(submission, cause, void 0, void 0, "submission");
338
+ submissionCause = cause;
339
+ if (options?.signal?.aborted || performance.now() >= deadline) throw new TransactionObservationError(submission, cause, submissionCause, void 0, "submission");
340
+ }
341
+ try {
342
+ const receipt = await client.waitForTransactionReceipt(submission.transactionHash, {
343
+ ...options,
344
+ expectedNetworkHash: submission.networkHash,
345
+ timeoutMs: Math.max(0, deadline - performance.now())
346
+ });
347
+ return {
348
+ transactionHash: receipt.transactionHash,
349
+ receipt,
350
+ submission
351
+ };
352
+ } catch (cause) {
353
+ throw new TransactionObservationError(submission, cause, submissionCause, cause instanceof TransactionReceiptObservationError ? cause.knownCommitment : void 0);
354
+ }
355
+ }
356
+ /** Wait for a committed receipt, then require execution success. */
357
+ async function waitForExecution(client, hash, options) {
358
+ const receipt = await client.waitForTransactionReceipt(hash, options);
359
+ assertTransactionSuccess(receipt);
360
+ return {
361
+ transactionHash: receipt.transactionHash,
362
+ receipt
363
+ };
364
+ }
365
+ /**
366
+ * Decode DefaultWallet child returns without modifying the root receipt.
367
+ * Works after disconnect and preserves call order. Supply an adapter for other
368
+ * wallets. Wallets such as DevWallet that discard child return data report
369
+ * unavailable results. Failed wallet receipts are not decoded with a child ABI:
370
+ * even a single child call does not establish where an abort originated.
371
+ */
372
+ function decodeExecution(receipt, calls, adapter = defaultWalletAdapter, submission) {
373
+ assertTransactionSuccess(receipt, submission);
374
+ try {
375
+ const buffers = adapter.decodeExecutionReturns?.(receipt);
376
+ if (buffers == null) throw new ExecutionReturnUnavailableError(receipt, submission);
377
+ if (buffers.length !== calls.length) throw new Error(`Returned ${buffers.length} child results; expected ${calls.length}`);
378
+ return calls.map((call, index) => call.method.decodeReturn(buffers[index]));
379
+ } catch (cause) {
380
+ if (cause instanceof ExecutionReturnUnavailableError) throw cause;
381
+ throw new ExecutionDecodeError(receipt, cause, submission);
382
+ }
383
+ }
384
+ /** A committed successful execution whose return data could not be decoded. */
385
+ var ExecutionDecodeError = class extends Error {
386
+ receipt;
387
+ submission;
388
+ constructor(receipt, cause, submission) {
389
+ super(`Transaction ${toBase58(receipt.transactionHash)} committed, but result decoding failed: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
390
+ this.receipt = receipt;
391
+ this.submission = submission;
392
+ this.name = "ExecutionDecodeError";
393
+ }
394
+ };
395
+ /** Execution succeeded, but this wallet does not preserve child return buffers. */
396
+ var ExecutionReturnUnavailableError = class extends Error {
397
+ receipt;
398
+ submission;
399
+ constructor(receipt, submission) {
400
+ super(`Transaction ${toBase58(receipt.transactionHash)} committed successfully, but its wallet does not expose child return data`);
401
+ this.receipt = receipt;
402
+ this.submission = submission;
403
+ this.name = "ExecutionReturnUnavailableError";
404
+ }
405
+ };
406
+ /**
407
+ * Sum explicit child budgets and a calibrated wallet overhead, checking u64 bounds.
408
+ * This is not gas estimation. Calibrate budgets against the target runtime and
409
+ * workload; there is no universally safe wallet overhead. Root gas reserves
410
+ * scheduling capacity against the sender's free native-token balance. Storage
411
+ * deposits are a separate requirement, and funding a target contract does not
412
+ * sponsor root gas.
413
+ */
414
+ function walletGasLimit(calls, overhead) {
415
+ const limits = [overhead, ...calls.map((call) => call.gas_limit)];
416
+ if (limits.some((limit) => typeof limit !== "bigint" || limit < 0n)) throw new RangeError("Gas budgets must be nonnegative bigint values");
417
+ const total = limits.reduce((sum, limit) => sum + limit, 0n);
418
+ if (total > 18446744073709551615n) throw new RangeError("Root gas budget exceeds u64");
419
+ return gasAmount(total);
420
+ }
421
+ //#endregion
422
+ //#region src/actions/wallet/prepareTransaction.ts
423
+ const int64Max = 9223372036854775807n;
424
+ const uint64Max = 18446744073709551615n;
425
+ const defaultExpiryBlocks = 100n;
426
+ /** Prepare an unsigned transaction for a wallet account. */
427
+ async function prepareTransaction(client, account, request) {
428
+ const invocation = deserialize(serialize(request.invocation, codec.Invocation), codec.Invocation);
429
+ const contractsToDeploy = (request.contractsToDeploy ?? []).map((contract) => deserialize(serialize(contract, codec.Contract), codec.Contract));
430
+ const authClaim = deserialize(serialize(account.authClaim, codec.AuthClaim), codec.AuthClaim);
431
+ if (!bytesEqual(invocation.invoked_address, account.address)) throw new Error("Root invocation address must match the wallet account");
432
+ if (request.blockExpiryHeight !== void 0 && request.expiryBlocks !== void 0) throw new Error("blockExpiryHeight and expiryBlocks are mutually exclusive");
433
+ const nonce = request.nonce ?? randomUint64();
434
+ validateRange(nonce, 0n, uint64Max, "nonce");
435
+ let expiry;
436
+ if (request.blockExpiryHeight !== void 0) {
437
+ expiry = request.blockExpiryHeight;
438
+ validateRange(expiry, 0n, int64Max, "blockExpiryHeight");
439
+ } else {
440
+ const expiryBlocks = request.expiryBlocks ?? defaultExpiryBlocks;
441
+ validateRange(expiryBlocks, 1n, int64Max, "expiryBlocks");
442
+ expiry = (await client.getChainTip()).blockHeight + expiryBlocks;
443
+ validateRange(expiry, 0n, int64Max, "blockExpiryHeight");
444
+ }
445
+ return createTransaction({
446
+ invocation,
447
+ uniquifier: {
448
+ block_expiry_height: blockHeight(expiry),
449
+ nonce
450
+ },
451
+ contracts_to_deploy: contractsToDeploy,
452
+ auth_claim: authClaim
453
+ });
454
+ }
455
+ function randomUint64() {
456
+ const bytes = crypto.getRandomValues(new Uint8Array(8));
457
+ return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getBigUint64(0);
458
+ }
459
+ function validateRange(value, min, max, name) {
460
+ if (typeof value !== "bigint" || value < min || value > max) throw new RangeError(`${name} must be between ${min} and ${max}`);
461
+ }
462
+ function bytesEqual(left, right) {
463
+ if (left.length !== right.length) return false;
464
+ return left.every((byte, index) => byte === right[index]);
465
+ }
466
+ //#endregion
467
+ //#region src/actions/wallet/sendInvocation.ts
468
+ /** Sign a transaction with a wallet account's configured signers. */
469
+ function signWalletTransaction(account, transaction, networkHash) {
470
+ return signTransaction(transaction, account.signers, networkHash);
471
+ }
472
+ /** Prepare, sign, and submit one explicit root invocation. */
473
+ async function sendInvocation(client, account, networkHash, request, controls = {}) {
474
+ controls.signal?.throwIfAborted();
475
+ client.requireMethods(["getChainTip", "sendTransaction"]);
476
+ const signingNetwork = new Uint8Array(networkHash);
477
+ const checkNetwork = () => {
478
+ const discovered = client.discovery.network.networkHash;
479
+ if (signingNetwork.length !== 32 || discovered.length !== 32 || signingNetwork.some((value, index) => value !== discovered[index])) throw new RpcCompatibilityError("Signing network does not match endpoint discovery");
480
+ };
481
+ checkNetwork();
482
+ const signers = account.signers.map(({ signer, publicKeyId }) => ({
483
+ signer,
484
+ publicKeyId
485
+ }));
486
+ const transaction = await prepareTransaction(client, account, request);
487
+ checkNetwork();
488
+ const evidence = createSubmissionEvidence(serialize(await signTransaction(transaction, signers, signingNetwork), codec.SignedTransaction), signingNetwork);
489
+ let phase = "beforeSubmission";
490
+ try {
491
+ await controls.onSigned?.(evidence);
492
+ controls.signal?.throwIfAborted();
493
+ checkNetwork();
494
+ phase = "submission";
495
+ const result = await client.sendTransaction({ signedTransaction: evidence.signedTransaction }, { signal: controls.signal });
496
+ assertTransactionAdmission(result);
497
+ return sha256Hash(result.transactionHash);
498
+ } catch (cause) {
499
+ throw new TransactionObservationError(evidence, cause, void 0, void 0, cause instanceof RpcRequestValidationError || cause instanceof RpcCompatibilityError ? "beforeSubmission" : phase);
500
+ }
501
+ }
502
+ //#endregion
503
+ export { waitForCommitment as C, validateTimer as E, TransactionReceiptTimeoutError as S, beforeDeadline as T, createDefaultWalletBatchInvocation as _, ExecutionReturnUnavailableError as a, devWalletAdapter as b, UnsupportedTransactionAdmissionError as c, assertTransactionSuccess as d, createSubmissionEvidence as f, walletGasLimit as g, waitForExecution as h, ExecutionDecodeError as i, UnsupportedTransactionOutcomeError as l, submitAndObserve as m, signWalletTransaction as n, TransactionExecutionError as o, decodeExecution as p, prepareTransaction as r, TransactionObservationError as s, sendInvocation as t, assertTransactionAdmission as u, defaultWalletAdapter as v, waitForTransactionReceipt as w, TransactionReceiptObservationError as x, defineWalletInvocationAdapter as y };
504
+
505
+ //# sourceMappingURL=sendInvocation-BwabRa2N.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sendInvocation-BwabRa2N.js","names":["bytesEqual","sign"],"sources":["../src/actions/deadline.ts","../src/actions/public/waitForTransactionReceipt.ts","../src/wallet/invocationAdapter.ts","../src/wallet/execution.ts","../src/actions/wallet/prepareTransaction.ts","../src/actions/wallet/sendInvocation.ts"],"sourcesContent":["/** Run one operation within the caller's wall-clock budget and cancellation signal. */\nexport async function beforeDeadline<T>(\n operation: (signal: AbortSignal) => Promise<T>,\n deadline: number,\n caller: AbortSignal | undefined,\n timeout: () => Error,\n): Promise<T> {\n caller?.throwIfAborted();\n if (performance.now() >= deadline) throw timeout();\n const controller = new AbortController();\n const signal = caller\n ? AbortSignal.any([caller, controller.signal])\n : controller.signal;\n let timer: ReturnType<typeof setTimeout> | undefined;\n let onAbort = () => {};\n try {\n return await Promise.race([\n new Promise<T>((_, reject) => {\n onAbort = () => reject(signal.reason);\n signal.addEventListener(\"abort\", onAbort, { once: true });\n timer = setTimeout(\n () => controller.abort(timeout()),\n Math.ceil(Math.max(0, deadline - performance.now())),\n );\n }),\n operation(signal),\n ]);\n } finally {\n if (timer !== undefined) clearTimeout(timer);\n signal.removeEventListener(\"abort\", onAbort);\n controller.abort();\n }\n}\nexport function validateTimer(value: number, field: string): void {\n if (!Number.isFinite(value) || value < 0 || value > 2147483647)\n throw new RangeError(`${field} must be between 0 and 2147483647`);\n}\nexport function waitDelay(delay: number, signal: AbortSignal): Promise<void> {\n return new Promise((resolve, reject) => {\n signal.throwIfAborted();\n const finish = () => {\n signal.removeEventListener(\"abort\", abort);\n resolve();\n };\n const timer = setTimeout(finish, delay);\n const abort = () => {\n clearTimeout(timer);\n signal.removeEventListener(\"abort\", abort);\n reject(signal.reason);\n };\n signal.addEventListener(\"abort\", abort, { once: true });\n });\n}\n","import { toBase58 } from \"../../encoding.js\";\nimport type { RpcClient } from \"../../rpc/client.js\";\nimport { RpcCompatibilityError } from \"../../rpc/client.js\";\nimport { NativeRpcError } from \"../../rpc/errorReader.js\";\nimport {\n UnsupportedRpcValue,\n RpcDecodingError,\n RpcRequestValidationError,\n} from \"../../rpc/codec.js\";\nimport type { TransactionReceipt, TransactionStatus } from \"../../types/rpc.js\";\nimport { classifyReadError } from \"../../transport/readError.js\";\nimport { beforeDeadline, validateTimer, waitDelay } from \"../deadline.js\";\n\nexport interface KnownCommitment {\n readonly networkHash: Uint8Array;\n readonly transactionHash: Uint8Array;\n readonly blockHeight: bigint;\n}\nexport interface WaitForTransactionReceiptOptions {\n signal?: AbortSignal;\n /** Verified before each observation; omission uses discovery's validated network. */\n expectedNetworkHash?: Uint8Array;\n knownCommitment?: KnownCommitment;\n /** Observed status, including optional advisory attempt diagnostics. Never retry permission. */\n onStatus?: (status: TransactionStatus) => void;\n timeoutMs?: number;\n pollingIntervalMs?: number;\n}\n/** Observation stopped; neither timeout nor cancellation proves nonexecution. */\nexport class TransactionReceiptObservationError extends Error {\n constructor(\n readonly transactionHash: Uint8Array,\n readonly knownCommitment: KnownCommitment | undefined,\n readonly lastStatus: TransactionStatus | undefined,\n cause: unknown,\n ) {\n super(`Could not observe transaction ${toBase58(transactionHash)}`, {\n cause,\n });\n this.name = \"TransactionReceiptObservationError\";\n }\n}\nexport class TransactionReceiptTimeoutError extends TransactionReceiptObservationError {\n constructor(\n transactionHash: Uint8Array,\n knownCommitment: KnownCommitment | undefined,\n lastStatus: TransactionStatus | undefined,\n cause?: unknown,\n ) {\n super(transactionHash, knownCommitment, lastStatus, cause);\n this.name = \"TransactionReceiptTimeoutError\";\n this.message = `Timed out waiting for transaction ${toBase58(transactionHash)}`;\n }\n}\nconst equal = (a: Uint8Array, b: Uint8Array) =>\n a.length === b.length && a.every((v, i) => v === b[i]);\n/** Read-only capabilities used by commitment and receipt observation. */\nexport type ReceiptObserver = Pick<\n RpcClient,\n | \"getNetworkInfo\"\n | \"getTransactionReceipt\"\n | \"getTransactionStatus\"\n | \"discovery\"\n | \"requireMethods\"\n>;\n\n/** Return any committed receipt, including failed execution. Never sign or resubmit. */\nexport async function waitForTransactionReceipt(\n client: ReceiptObserver,\n transactionHash: Uint8Array,\n options: WaitForTransactionReceiptOptions = {},\n): Promise<TransactionReceipt> {\n return (await observe(\n client,\n transactionHash,\n options,\n false,\n )) as TransactionReceipt;\n}\n/** Observe commitment independently of receipt availability or execution success. */\nexport async function waitForCommitment(\n client: ReceiptObserver,\n transactionHash: Uint8Array,\n options: WaitForTransactionReceiptOptions = {},\n): Promise<KnownCommitment> {\n return (await observe(\n client,\n transactionHash,\n options,\n true,\n )) as KnownCommitment;\n}\n// Status evidence includes extensible values at arbitrary nested schema positions.\n// structuredClone alone drops their UnsupportedRpcValue class identity.\nfunction snapshotStatus(status: TransactionStatus): TransactionStatus {\n const copy = (value: unknown): unknown => {\n if (value instanceof UnsupportedRpcValue)\n return new UnsupportedRpcValue(structuredClone(value.raw));\n if (Array.isArray(value)) return value.map(copy);\n if (ArrayBuffer.isView(value)) return structuredClone(value);\n if (value !== null && typeof value === \"object\")\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => [key, copy(entry)]),\n );\n return value;\n };\n return copy(status) as TransactionStatus;\n}\n\nasync function observe(\n client: ReceiptObserver,\n hash: Uint8Array,\n options: WaitForTransactionReceiptOptions,\n commitmentOnly: boolean,\n): Promise<TransactionReceipt | KnownCommitment> {\n const timeoutMs = options.timeoutMs ?? 30000;\n const interval = options.pollingIntervalMs ?? 250;\n validateTimer(timeoutMs, \"timeoutMs\");\n validateTimer(interval, \"pollingIntervalMs\");\n const transactionHash = new Uint8Array(hash);\n const networkHash = new Uint8Array(\n options.expectedNetworkHash ?? client.discovery.network.networkHash,\n );\n if (transactionHash.length !== 32 || networkHash.length !== 32)\n throw new RangeError(\n \"Transaction and network hashes must contain 32 bytes\",\n );\n let commitment: KnownCommitment | undefined;\n let lastStatus: TransactionStatus | undefined;\n if (options.knownCommitment) {\n const known = options.knownCommitment;\n if (\n !equal(known.transactionHash, transactionHash) ||\n !equal(known.networkHash, networkHash) ||\n typeof known.blockHeight !== \"bigint\" ||\n known.blockHeight < 0n ||\n known.blockHeight > 9223372036854775807n\n )\n throw new RpcCompatibilityError(\n \"Known commitment does not match the transaction/network context\",\n );\n commitment = {\n transactionHash: transactionHash.slice(),\n networkHash: networkHash.slice(),\n blockHeight: known.blockHeight,\n };\n lastStatus = { status: \"committed\", blockHeight: known.blockHeight };\n }\n client.requireMethods([\n \"getNetworkInfo\",\n \"getTransactionReceipt\",\n \"getTransactionStatus\",\n ]);\n const deadline = performance.now() + timeoutMs;\n let lastFailure: unknown;\n let failures = 0;\n const timeout = () =>\n new TransactionReceiptTimeoutError(\n transactionHash.slice(),\n commitment && structuredClone(commitment),\n lastStatus,\n lastFailure,\n );\n const run = <T>(operation: (signal: AbortSignal) => Promise<T>) =>\n beforeDeadline(operation, deadline, options.signal, timeout);\n const retain = (blockHeight: bigint) => {\n if (commitment && commitment.blockHeight !== blockHeight)\n throw new RpcCompatibilityError(\n \"Conflicting commitment heights for the same transaction\",\n );\n commitment = {\n transactionHash: transactionHash.slice(),\n networkHash: networkHash.slice(),\n blockHeight,\n };\n lastStatus = { status: \"committed\", blockHeight };\n };\n try {\n while (true) {\n let retryAfterMs: bigint | undefined;\n let networkVerified = false;\n let failed = false;\n try {\n const network = await run((signal) =>\n client.getNetworkInfo({}, { signal }),\n );\n if (!equal(network.networkHash, networkHash))\n throw new RpcCompatibilityError(\n \"Observation endpoint network changed\",\n );\n networkVerified = true;\n if (commitmentOnly && commitment) return structuredClone(commitment);\n const receipt = await run((signal) =>\n client.getTransactionReceipt({ transactionHash }, { signal }),\n );\n if (receipt) {\n retain(receipt.blockHeight);\n return commitmentOnly ? structuredClone(commitment!) : receipt;\n }\n } catch (cause) {\n lastFailure = cause;\n failed = true;\n if (\n cause instanceof NativeRpcError &&\n cause.decoded.classification === \"known\"\n ) {\n const data = cause.decoded.data;\n if (data.kind === \"backendDataInvalid\" && data.observation) {\n retain(data.observation.blockHeight);\n if (commitmentOnly) return structuredClone(commitment!);\n }\n if (\"retryAfterMs\" in data) retryAfterMs = data.retryAfterMs;\n }\n if (\n options.signal?.aborted ||\n classifyReadError(cause, options) !== \"transient\"\n )\n throw cause;\n }\n // Status failures cannot erase a previously validated commitment.\n let observedStatus: TransactionStatus | undefined;\n if (networkVerified)\n try {\n const status = await run((signal) =>\n client.getTransactionStatus({ transactionHash }, { signal }),\n );\n if (\n !(status instanceof UnsupportedRpcValue) &&\n status.status === \"committed\"\n )\n retain(status.blockHeight);\n else if (!commitment) lastStatus = snapshotStatus(status);\n observedStatus = status;\n } catch (cause) {\n if (\n cause instanceof RpcCompatibilityError ||\n cause instanceof RpcDecodingError ||\n cause instanceof RpcRequestValidationError ||\n classifyReadError(cause, options) === \"permanent\"\n )\n throw cause;\n options.signal?.throwIfAborted();\n lastFailure = cause;\n failed = true;\n if (\n cause instanceof NativeRpcError &&\n cause.decoded.classification === \"known\" &&\n \"retryAfterMs\" in cause.decoded.data\n ) {\n const hint = cause.decoded.data.retryAfterMs;\n if (\n hint !== undefined &&\n (retryAfterMs === undefined || hint > retryAfterMs)\n )\n retryAfterMs = hint;\n }\n }\n if (observedStatus !== undefined) options.onStatus?.(observedStatus);\n if (failed) failures++;\n else {\n failures = 0;\n lastFailure = undefined;\n }\n if (commitmentOnly && commitment) return structuredClone(commitment);\n const backoff = failures\n ? Math.min(\n 5000,\n Math.max(1, interval) * 2 ** Math.min(failures - 1, 8),\n ) *\n (0.5 + Math.random() / 2)\n : interval;\n const remaining = deadline - performance.now();\n if (\n retryAfterMs !== undefined &&\n retryAfterMs > BigInt(Math.max(0, Math.floor(remaining)))\n )\n throw timeout();\n const delay = Math.max(backoff, Number(retryAfterMs ?? 0n));\n await run((signal) =>\n waitDelay(Math.min(delay, Math.max(0, remaining)), signal),\n );\n }\n } catch (cause) {\n if (cause instanceof TransactionReceiptTimeoutError) throw cause;\n throw new TransactionReceiptObservationError(\n transactionHash,\n commitment && structuredClone(commitment),\n lastStatus,\n cause,\n );\n }\n}\n","import {\n codec,\n contractAddress,\n serialize,\n type ContractAddress,\n type GasAmount,\n type Invocation,\n} from \"@thruputchain/protocol\";\nimport { fixedBytes } from \"@thruputchain/xdr\";\nimport { bytesEqual } from \"../contract/event.js\";\nimport { DefaultWallet } from \"../contracts/default_wallet.js\";\nimport { DevWallet } from \"../contracts/dev_wallet.js\";\nimport { MAX_DEFAULT_WALLET_CALLS } from \"../provider/validation.js\";\nimport type { ContractDeployment, DeploymentOptions } from \"./deployment.js\";\nimport type { TransactionReceipt } from \"../types/rpc.js\";\n\n/** Common inputs for wrapping one inner invocation through a wallet contract. */\nexport interface WalletExecutionRequest {\n readonly invocation: Invocation;\n /** Gas available to the wallet's root invocation. */\n readonly gasLimit: GasAmount;\n}\n\n/** Ordered inner calls for one atomic DefaultWallet execution. */\nexport interface WalletBatchExecutionRequest {\n readonly invocations: readonly Invocation[];\n /** Gas available to the complete wallet root, including all calls. */\n readonly gasLimit: GasAmount;\n}\n\n/** Build a root batch directly, copying call bytes before asynchronous work. */\nexport function createDefaultWalletBatchInvocation(\n accountAddress: ContractAddress,\n request: WalletBatchExecutionRequest,\n): Invocation {\n if (\n !Array.isArray(request.invocations) ||\n request.invocations.length < 1 ||\n request.invocations.length > MAX_DEFAULT_WALLET_CALLS\n )\n throw new RangeError(\"DefaultWallet requires 1 to 16 calls\");\n return DefaultWallet.v0_1.execute.invocation(\n contractAddress(new Uint8Array(accountAddress)),\n request.gasLimit,\n {\n calls: request.invocations.map((inner) => ({\n target: contractAddress(new Uint8Array(inner.invoked_address)),\n entrypoint: fixedBytes(new Uint8Array(inner.entrypoint), 8),\n gas_limit: inner.gas_limit,\n calldata: new Uint8Array(inner.calldata),\n })),\n },\n );\n}\n\n/** Converts a wallet-specific execution request into a root invocation. */\nexport interface WalletInvocationAdapter<\n TRequest extends WalletExecutionRequest = WalletExecutionRequest,\n> {\n /** Build a root deployment when supported by this wallet. */\n createDeploymentInvocation?(\n account: ContractAddress,\n deployment: ContractDeployment,\n options: DeploymentOptions,\n ): Invocation;\n /** Decode the address returned by a root deployment. */\n decodeDeploymentReceipt?(receipt: TransactionReceipt): ContractAddress;\n /** Child return buffers in call order, or null when this wallet discards them. */\n decodeExecutionReturns?(\n receipt: TransactionReceipt,\n ): readonly Uint8Array[] | null;\n /** Build one atomic root for multiple calls when this wallet supports it. */\n createBatchRootInvocation?(\n account: ContractAddress,\n request: WalletBatchExecutionRequest,\n ): Invocation;\n createRootInvocation(\n accountAddress: ContractAddress,\n request: TRequest,\n ): Invocation;\n}\n\n/** Define an invocation adapter while preserving its request type. */\nexport function defineWalletInvocationAdapter<\n TRequest extends WalletExecutionRequest,\n>(\n adapter: WalletInvocationAdapter<TRequest>,\n): WalletInvocationAdapter<TRequest> {\n return adapter;\n}\n\n/** Wrap one call through the native-compatible DefaultWallet interface. */\nexport const defaultWalletAdapter = defineWalletInvocationAdapter({\n createBatchRootInvocation: createDefaultWalletBatchInvocation,\n decodeExecutionReturns: (receipt) =>\n DefaultWallet.v0_1.execute.decodeReceipt(receipt).value,\n createDeploymentInvocation(account, deployment, options) {\n if (\n options.initializer &&\n !bytesEqual(options.initializer.invoked_address, deployment.address)\n )\n throw new Error(\n \"Initializer must target the predicted deployment address\",\n );\n // The wallet takes an i128, but a deployment never funds a negative amount.\n if (options.amount < 0n)\n throw new RangeError(\"Deployment amount must not be negative\");\n return DefaultWallet.v0_1.deploy.invocation(account, options.gasLimit, {\n nonce: fixedBytes(deployment.deploymentNonce, 32),\n contractHash: fixedBytes(deployment.contractHash, 32),\n amount: options.amount,\n initializer: options.initializer\n ? {\n entrypoint: fixedBytes(options.initializer.entrypoint, 8),\n gas_limit: options.initializer.gas_limit,\n calldata: options.initializer.calldata,\n }\n : null,\n });\n },\n decodeDeploymentReceipt: (receipt) =>\n DefaultWallet.v0_1.deploy.decodeReceipt(receipt).value,\n createRootInvocation(\n accountAddress: ContractAddress,\n request: WalletExecutionRequest,\n ): Invocation {\n return createDefaultWalletBatchInvocation(accountAddress, {\n invocations: [request.invocation],\n gasLimit: request.gasLimit,\n });\n },\n});\n\n/** Wrap one call through the legacy DevWallet. Unified deployment is unsupported. */\nexport const devWalletAdapter = defineWalletInvocationAdapter({\n decodeExecutionReturns: () => null,\n createRootInvocation(\n accountAddress: ContractAddress,\n request: WalletExecutionRequest,\n ): Invocation {\n return DevWallet.v0_1.doAction.invocation(\n contractAddress(new Uint8Array(accountAddress)),\n request.gasLimit,\n {\n invocationBytes: serialize(request.invocation, codec.Invocation),\n },\n );\n },\n});\n","import { codec, deserialize } from \"@thruputchain/protocol\";\nimport { hashSignedTransaction } from \"../derivation/transactionHash.js\";\nimport { RpcCompatibilityError } from \"../rpc/client.js\";\nimport {\n RpcRequestValidationError,\n UnsupportedRpcValue,\n} from \"../rpc/codec.js\";\nimport { NativeRpcError } from \"../rpc/errorReader.js\";\nimport {\n TransactionReceiptObservationError,\n type KnownCommitment,\n} from \"../actions/public/waitForTransactionReceipt.js\";\nimport { gasAmount, type GasAmount } from \"@thruputchain/protocol\";\nimport type { CoreThruputClient } from \"../client.js\";\nimport type { TransactionReceipt } from \"../types/rpc.js\";\nimport type { WaitForTransactionReceiptOptions } from \"../actions/public/waitForTransactionReceipt.js\";\nimport type { ContractCall } from \"../contract/method.js\";\nimport {\n defaultWalletAdapter,\n type WalletInvocationAdapter,\n} from \"./invocationAdapter.js\";\nimport { beforeDeadline, validateTimer } from \"../actions/deadline.js\";\nimport { toBase58 } from \"../encoding.js\";\nimport type { RpcSendTransactionResult } from \"../rpc/generated.js\";\n\n/** A committed execution failure, retaining the complete native receipt. */\nexport class TransactionExecutionError extends Error {\n constructor(\n readonly receipt: TransactionReceipt,\n readonly submission?: SubmissionEvidence,\n ) {\n super(\n receipt.execution instanceof UnsupportedRpcValue\n ? `Transaction ${toBase58(receipt.transactionHash)} has an unsupported execution outcome`\n : `Transaction ${toBase58(receipt.transactionHash)} execution failed (${receipt.execution.result})`,\n );\n this.name = \"TransactionExecutionError\";\n }\n}\n/** A future execution variant is unsupported, never inferred to be success or failure. */\nexport class UnsupportedTransactionOutcomeError extends TransactionExecutionError {\n constructor(receipt: TransactionReceipt, submission?: SubmissionEvidence) {\n super(receipt, submission);\n this.name = \"UnsupportedTransactionOutcomeError\";\n }\n}\nexport function assertTransactionSuccess(\n receipt: TransactionReceipt,\n submission?: SubmissionEvidence,\n): asserts receipt is TransactionReceipt & {\n execution: { result: \"return\"; returnData: Uint8Array };\n} {\n if (receipt.execution instanceof UnsupportedRpcValue)\n throw new UnsupportedTransactionOutcomeError(receipt, submission);\n if (receipt.execution.result !== \"return\")\n throw new TransactionExecutionError(receipt, submission);\n}\n\n/** A submit response that does not establish the currently supported admission outcome. */\nexport class UnsupportedTransactionAdmissionError extends Error {\n constructor(readonly response: RpcSendTransactionResult) {\n super(\"Transaction submission returned an unsupported admission outcome\");\n this.name = \"UnsupportedTransactionAdmissionError\";\n }\n}\n\n/** Keep low-level future values intact, but never project them into an admitted hash. */\nexport function assertTransactionAdmission(\n response: RpcSendTransactionResult,\n): void {\n if (response.admission !== \"accepted\")\n throw new UnsupportedTransactionAdmissionError(response);\n}\nexport interface SubmissionEvidence {\n readonly signedTransaction: Uint8Array;\n readonly transactionHash: Uint8Array;\n readonly networkHash: Uint8Array;\n}\n/** Snapshot approved bytes before submission; accessor copies protect the retained record. */\nexport function createSubmissionEvidence(\n bytes: Uint8Array,\n network: Uint8Array,\n): SubmissionEvidence {\n const signedTransaction = new Uint8Array(bytes);\n const networkHash = new Uint8Array(network);\n if (networkHash.length !== 32)\n throw new RangeError(\"networkHash must contain 32 bytes\");\n const transactionHash = hashSignedTransaction(\n deserialize(signedTransaction, codec.SignedTransaction),\n );\n return Object.freeze({\n get signedTransaction() {\n return signedTransaction.slice();\n },\n get transactionHash() {\n return transactionHash.slice();\n },\n get networkHash() {\n return networkHash.slice();\n },\n });\n}\nexport interface ExecutionResult {\n transactionHash: Uint8Array;\n receipt: TransactionReceipt;\n submission?: SubmissionEvidence;\n}\n/** Submission or observation stopped, preserving exact approved bytes and commitment. */\nexport class TransactionObservationError extends Error {\n constructor(\n readonly submission: SubmissionEvidence,\n cause: unknown,\n readonly submissionCause?: unknown,\n readonly knownCommitment?: KnownCommitment,\n readonly phase:\n | \"beforeSubmission\"\n | \"submission\"\n | \"observation\" = \"observation\",\n ) {\n super(\n `Could not complete transaction ${toBase58(submission.transactionHash)}`,\n { cause },\n );\n this.name = \"TransactionObservationError\";\n }\n get transactionHash(): Uint8Array {\n return this.submission.transactionHash;\n }\n}\n/** Submit once, then reconcile only by reads. No path replaces or repeats signed bytes. */\nexport async function submitAndObserve(\n client: Pick<CoreThruputClient, \"waitForTransactionReceipt\">,\n evidence: SubmissionEvidence,\n submit: (signal: AbortSignal) => Promise<void>,\n options?: WaitForTransactionReceiptOptions,\n wasDispatched?: () => boolean,\n): Promise<ExecutionResult> {\n const submission = createSubmissionEvidence(\n evidence.signedTransaction,\n evidence.networkHash,\n );\n const timeoutMs = options?.timeoutMs ?? 30000;\n validateTimer(timeoutMs, \"timeoutMs\");\n const deadline = performance.now() + timeoutMs;\n let submissionCause: unknown;\n try {\n options?.signal?.throwIfAborted();\n if (timeoutMs === 0)\n throw new Error(\"Transaction submission timed out before dispatch\");\n } catch (cause) {\n throw new TransactionObservationError(\n submission,\n cause,\n undefined,\n undefined,\n \"beforeSubmission\",\n );\n }\n try {\n await beforeDeadline(\n submit,\n deadline,\n options?.signal,\n () => new Error(\"Transaction submission timed out\"),\n );\n } catch (cause) {\n if (\n wasDispatched?.() === false ||\n cause instanceof RpcRequestValidationError ||\n cause instanceof RpcCompatibilityError\n )\n throw new TransactionObservationError(\n submission,\n cause,\n undefined,\n undefined,\n \"beforeSubmission\",\n );\n if (\n cause instanceof NativeRpcError &&\n cause.decoded.classification === \"known\" &&\n (cause.decoded.data.kind === \"invalidParams\" ||\n cause.decoded.data.kind === \"transactionInvalid\" ||\n cause.decoded.data.kind === \"transactionRejected\")\n )\n throw new TransactionObservationError(\n submission,\n cause,\n undefined,\n undefined,\n \"submission\",\n );\n submissionCause = cause;\n if (options?.signal?.aborted || performance.now() >= deadline)\n throw new TransactionObservationError(\n submission,\n cause,\n submissionCause,\n undefined,\n \"submission\",\n );\n }\n try {\n const receipt = await client.waitForTransactionReceipt(\n submission.transactionHash,\n {\n ...options,\n expectedNetworkHash: submission.networkHash,\n timeoutMs: Math.max(0, deadline - performance.now()),\n },\n );\n return { transactionHash: receipt.transactionHash, receipt, submission };\n } catch (cause) {\n throw new TransactionObservationError(\n submission,\n cause,\n submissionCause,\n cause instanceof TransactionReceiptObservationError\n ? cause.knownCommitment\n : undefined,\n );\n }\n}\n/** Wait for a committed receipt, then require execution success. */\nexport async function waitForExecution(\n client: Pick<CoreThruputClient, \"waitForTransactionReceipt\">,\n hash: Uint8Array,\n options?: WaitForTransactionReceiptOptions,\n): Promise<ExecutionResult> {\n const receipt = await client.waitForTransactionReceipt(hash, options);\n assertTransactionSuccess(receipt);\n return { transactionHash: receipt.transactionHash, receipt };\n}\n\n/** Ordered result types for a tuple of calls. */\nexport type CallResults<T extends readonly ContractCall[]> = {\n [K in keyof T]: T[K] extends ContractCall<infer R> ? R : never;\n};\n\n/**\n * Decode DefaultWallet child returns without modifying the root receipt.\n * Works after disconnect and preserves call order. Supply an adapter for other\n * wallets. Wallets such as DevWallet that discard child return data report\n * unavailable results. Failed wallet receipts are not decoded with a child ABI:\n * even a single child call does not establish where an abort originated.\n */\nexport function decodeExecution<T extends readonly ContractCall[]>(\n receipt: TransactionReceipt,\n calls: T,\n adapter: WalletInvocationAdapter = defaultWalletAdapter,\n submission?: SubmissionEvidence,\n): CallResults<T> {\n // Even one child call can fail in the wallet root; its abort bytes are not a child receipt.\n assertTransactionSuccess(receipt, submission);\n try {\n const buffers = adapter.decodeExecutionReturns?.(receipt);\n if (buffers == null)\n throw new ExecutionReturnUnavailableError(receipt, submission);\n if (buffers.length !== calls.length)\n throw new Error(\n `Returned ${buffers.length} child results; expected ${calls.length}`,\n );\n return calls.map((call, index) =>\n call.method.decodeReturn(buffers[index]!),\n ) as CallResults<T>;\n } catch (cause) {\n if (cause instanceof ExecutionReturnUnavailableError) throw cause;\n throw new ExecutionDecodeError(receipt, cause, submission);\n }\n}\n\n/** A committed successful execution whose return data could not be decoded. */\nexport class ExecutionDecodeError extends Error {\n constructor(\n readonly receipt: TransactionReceipt,\n cause: unknown,\n readonly submission?: SubmissionEvidence,\n ) {\n super(\n `Transaction ${toBase58(receipt.transactionHash)} committed, but result decoding failed: ${cause instanceof Error ? cause.message : String(cause)}`,\n { cause },\n );\n this.name = \"ExecutionDecodeError\";\n }\n}\n\n/** Execution succeeded, but this wallet does not preserve child return buffers. */\nexport class ExecutionReturnUnavailableError extends Error {\n constructor(\n readonly receipt: TransactionReceipt,\n readonly submission?: SubmissionEvidence,\n ) {\n super(\n `Transaction ${toBase58(receipt.transactionHash)} committed successfully, but its wallet does not expose child return data`,\n );\n this.name = \"ExecutionReturnUnavailableError\";\n }\n}\n\n/**\n * Sum explicit child budgets and a calibrated wallet overhead, checking u64 bounds.\n * This is not gas estimation. Calibrate budgets against the target runtime and\n * workload; there is no universally safe wallet overhead. Root gas reserves\n * scheduling capacity against the sender's free native-token balance. Storage\n * deposits are a separate requirement, and funding a target contract does not\n * sponsor root gas.\n */\nexport function walletGasLimit(\n calls: readonly { gas_limit: GasAmount }[],\n overhead: GasAmount,\n): GasAmount {\n const limits = [overhead, ...calls.map((call) => call.gas_limit)];\n if (limits.some((limit) => typeof limit !== \"bigint\" || limit < 0n))\n throw new RangeError(\"Gas budgets must be nonnegative bigint values\");\n const total = limits.reduce((sum, limit) => sum + limit, 0n);\n if (total > 0xffff_ffff_ffff_ffffn)\n throw new RangeError(\"Root gas budget exceeds u64\");\n return gasAmount(total);\n}\n","import {\n blockHeight,\n codec,\n deserialize,\n serialize,\n type BlockHeight,\n type Contract,\n type Invocation,\n type Transaction,\n} from \"@thruputchain/protocol\";\nimport type { CoreThruputClient } from \"../../client.js\";\nimport type { WalletAccount } from \"../../wallet/account.js\";\nimport { createTransaction } from \"../../transaction/build.js\";\n\nconst int64Max = 0x7fff_ffff_ffff_ffffn;\nconst uint64Max = 0xffff_ffff_ffff_ffffn;\nconst defaultExpiryBlocks = 100n;\n\n/** Inputs for preparing one wallet-authorized transaction. */\nexport interface PrepareTransactionRequest {\n /** Explicit root invocation. Smart-wallet wrapping is caller-controlled. */\n readonly invocation: Invocation;\n readonly contractsToDeploy?: readonly Contract[];\n readonly nonce?: bigint;\n readonly blockExpiryHeight?: BlockHeight;\n readonly expiryBlocks?: bigint;\n}\n\n/** Prepare an unsigned transaction for a wallet account. */\nexport async function prepareTransaction(\n client: Pick<CoreThruputClient, \"getChainTip\">,\n account: Pick<WalletAccount, \"address\" | \"authClaim\">,\n request: PrepareTransactionRequest,\n): Promise<Transaction> {\n const invocation = deserialize(\n serialize(request.invocation, codec.Invocation),\n codec.Invocation,\n );\n const contractsToDeploy = (request.contractsToDeploy ?? []).map((contract) =>\n deserialize(serialize(contract, codec.Contract), codec.Contract),\n );\n const authClaim = deserialize(\n serialize(account.authClaim, codec.AuthClaim),\n codec.AuthClaim,\n );\n\n if (!bytesEqual(invocation.invoked_address, account.address)) {\n throw new Error(\"Root invocation address must match the wallet account\");\n }\n if (\n request.blockExpiryHeight !== undefined &&\n request.expiryBlocks !== undefined\n ) {\n throw new Error(\n \"blockExpiryHeight and expiryBlocks are mutually exclusive\",\n );\n }\n\n const nonce = request.nonce ?? randomUint64();\n validateRange(nonce, 0n, uint64Max, \"nonce\");\n\n let expiry: bigint;\n if (request.blockExpiryHeight !== undefined) {\n expiry = request.blockExpiryHeight;\n validateRange(expiry, 0n, int64Max, \"blockExpiryHeight\");\n } else {\n const expiryBlocks = request.expiryBlocks ?? defaultExpiryBlocks;\n validateRange(expiryBlocks, 1n, int64Max, \"expiryBlocks\");\n const tip = await client.getChainTip();\n expiry = tip.blockHeight + expiryBlocks;\n validateRange(expiry, 0n, int64Max, \"blockExpiryHeight\");\n }\n\n return createTransaction({\n invocation,\n uniquifier: {\n block_expiry_height: blockHeight(expiry),\n nonce,\n },\n contracts_to_deploy: contractsToDeploy,\n auth_claim: authClaim,\n });\n}\n\nfunction randomUint64(): bigint {\n const bytes = crypto.getRandomValues(new Uint8Array(8));\n return new DataView(\n bytes.buffer,\n bytes.byteOffset,\n bytes.byteLength,\n ).getBigUint64(0);\n}\n\nfunction validateRange(\n value: bigint,\n min: bigint,\n max: bigint,\n name: string,\n): void {\n if (typeof value !== \"bigint\" || value < min || value > max) {\n throw new RangeError(`${name} must be between ${min} and ${max}`);\n }\n}\n\nfunction bytesEqual(left: Uint8Array, right: Uint8Array): boolean {\n if (left.length !== right.length) return false;\n return left.every((byte, index) => byte === right[index]);\n}\n","import type {\n SHA256Hash,\n SignedTransaction,\n Transaction,\n NetworkHash,\n} from \"@thruputchain/protocol\";\nimport { codec, serialize, sha256Hash } from \"@thruputchain/protocol\";\nimport {\n createSubmissionEvidence,\n assertTransactionAdmission,\n TransactionObservationError,\n type SubmissionEvidence,\n} from \"../../wallet/execution.js\";\nimport { RpcRequestValidationError } from \"../../rpc/codec.js\";\nimport { RpcCompatibilityError } from \"../../rpc/client.js\";\nimport type { CoreThruputClient } from \"../../client.js\";\nimport type { WalletAccount } from \"../../wallet/account.js\";\nimport { signTransaction as sign } from \"../../transaction/sign.js\";\nimport {\n prepareTransaction,\n type PrepareTransactionRequest,\n} from \"./prepareTransaction.js\";\n\n/** Sign a transaction with a wallet account's configured signers. */\nexport function signWalletTransaction(\n account: WalletAccount,\n transaction: Transaction,\n networkHash: NetworkHash,\n): Promise<SignedTransaction> {\n return sign(transaction, account.signers, networkHash);\n}\n\n/** Prepare, sign, and submit one explicit root invocation. */\nexport async function sendInvocation(\n client: Pick<\n CoreThruputClient,\n \"getChainTip\" | \"sendTransaction\" | \"requireMethods\" | \"discovery\"\n >,\n account: WalletAccount,\n networkHash: NetworkHash,\n request: PrepareTransactionRequest,\n controls: {\n signal?: AbortSignal;\n onSigned?: (evidence: SubmissionEvidence) => void | Promise<void>;\n } = {},\n): Promise<SHA256Hash> {\n controls.signal?.throwIfAborted();\n client.requireMethods([\"getChainTip\", \"sendTransaction\"]);\n const signingNetwork = new Uint8Array(networkHash) as NetworkHash;\n const checkNetwork = () => {\n const discovered = client.discovery.network.networkHash;\n if (\n signingNetwork.length !== 32 ||\n discovered.length !== 32 ||\n signingNetwork.some((value, index) => value !== discovered[index])\n )\n throw new RpcCompatibilityError(\n \"Signing network does not match endpoint discovery\",\n );\n };\n checkNetwork();\n const signers = account.signers.map(({ signer, publicKeyId }) => ({\n signer,\n publicKeyId,\n }));\n const transaction = await prepareTransaction(client, account, request);\n checkNetwork();\n const signed = await sign(transaction, signers, signingNetwork);\n const evidence = createSubmissionEvidence(\n serialize(signed, codec.SignedTransaction),\n signingNetwork,\n );\n let phase: \"beforeSubmission\" | \"submission\" = \"beforeSubmission\";\n try {\n await controls.onSigned?.(evidence);\n controls.signal?.throwIfAborted();\n checkNetwork();\n phase = \"submission\";\n const result = await client.sendTransaction(\n { signedTransaction: evidence.signedTransaction },\n { signal: controls.signal },\n );\n assertTransactionAdmission(result);\n return sha256Hash(result.transactionHash);\n } catch (cause) {\n throw new TransactionObservationError(\n evidence,\n cause,\n undefined,\n undefined,\n cause instanceof RpcRequestValidationError ||\n cause instanceof RpcCompatibilityError\n ? \"beforeSubmission\"\n : phase,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;AACA,eAAsB,eACpB,WACA,UACA,QACA,SACY;CACZ,QAAQ,eAAe;CACvB,IAAI,YAAY,IAAI,KAAK,UAA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