@thruputchain/client 0.28.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 +112 -17
  2. package/dist/{actions-B5-CjpEF.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-D77iA2iY.js → contract-BOlNskwd.js} +235 -87
  15. package/dist/contract-BOlNskwd.js.map +1 -0
  16. package/dist/{contract-DSu2UPPm.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-CAbOSrak.cjs → dev_wallet-BVChhV6j.cjs} +85 -6
  33. package/dist/dev_wallet-BVChhV6j.cjs.map +1 -0
  34. package/dist/{dev_wallet-CU3RpQLm.js → dev_wallet-D9LuPZ-h.js} +84 -5
  35. package/dist/dev_wallet-D9LuPZ-h.js.map +1 -0
  36. package/dist/{execution-J5jkXhV1.d.cts → execution-pSt6k620.d.cts} +23 -50
  37. package/dist/execution-pSt6k620.d.cts.map +1 -0
  38. package/dist/{execution-XJ0iwFaX.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-soFVQX9j.d.cts → index-B1efA-Y_.d.ts} +24 -21
  45. package/dist/index-B1efA-Y_.d.ts.map +1 -0
  46. package/dist/{index-C3HVRvQd.d.ts → index-BGmH_Sm7.d.cts} +12 -62
  47. package/dist/index-BGmH_Sm7.d.cts.map +1 -0
  48. package/dist/{index-Bb01ytjJ.d.ts → index-BZ5j5P5d.d.ts} +11 -9
  49. package/dist/index-BZ5j5P5d.d.ts.map +1 -0
  50. package/dist/{index-CedOvhGY.d.cts → index-BfYEEVHm.d.cts} +3 -13
  51. package/dist/index-BfYEEVHm.d.cts.map +1 -0
  52. package/dist/{index-CtjWsAXV.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-DeS1S0m-.d.ts → index-Btl_jMCT.d.ts} +3 -13
  57. package/dist/index-Btl_jMCT.d.ts.map +1 -0
  58. package/dist/{index-CtjZ61tl.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-DfmDUk5Y.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-Bxlt1gKO.js → readError-B3Rz7rgs.js} +359 -56
  81. package/dist/readError-B3Rz7rgs.js.map +1 -0
  82. package/dist/{codec-BcK8ASsg.cjs → readError-COcEDNoZ.cjs} +363 -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-DAucp6xg.cjs → signedOp-CVyeJ5ig.cjs} +3 -3
  97. package/dist/{signedOp-DAucp6xg.cjs.map → signedOp-CVyeJ5ig.cjs.map} +1 -1
  98. package/dist/{signedOp-DpmUpH-e.js → signedOp-D6WYZG9j.js} +3 -3
  99. package/dist/{signedOp-DpmUpH-e.js.map → signedOp-D6WYZG9j.js.map} +1 -1
  100. package/dist/{signed_op-_lR85dn2.cjs → signed_op-BBsDKOlD.cjs} +4 -4
  101. package/dist/{signed_op-_lR85dn2.cjs.map → signed_op-BBsDKOlD.cjs.map} +1 -1
  102. package/dist/{signed_op-D2usgASc.d.cts → signed_op-BvbOHWKK.d.ts} +3 -3
  103. package/dist/{signed_op-zGq4eBo8.d.ts.map → signed_op-BvbOHWKK.d.ts.map} +1 -1
  104. package/dist/{signed_op-zGq4eBo8.d.ts → signed_op-DoHFpSH4.d.cts} +3 -3
  105. package/dist/{signed_op-D2usgASc.d.cts.map → signed_op-DoHFpSH4.d.cts.map} +1 -1
  106. package/dist/{signed_op-CwN-_CXw.js → signed_op-h9X9-vBL.js} +3 -3
  107. package/dist/{signed_op-CwN-_CXw.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-BNKgOXrF.js → wallet-NlZiI4-3.js} +161 -77
  125. package/dist/wallet-NlZiI4-3.js.map +1 -0
  126. package/dist/{wallet-7R5M_7h4.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-B5-CjpEF.cjs.map +0 -1
  134. package/dist/actions-C1SMLWO5.js +0 -430
  135. package/dist/actions-C1SMLWO5.js.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-jOZxB8yW.d.cts +0 -798
  139. package/dist/client-jOZxB8yW.d.cts.map +0 -1
  140. package/dist/client-jOZxB8yW.d.ts +0 -798
  141. package/dist/client-jOZxB8yW.d.ts.map +0 -1
  142. package/dist/codec-BcK8ASsg.cjs.map +0 -1
  143. package/dist/codec-Bxlt1gKO.js.map +0 -1
  144. package/dist/contract-D77iA2iY.js.map +0 -1
  145. package/dist/contract-DSu2UPPm.cjs.map +0 -1
  146. package/dist/dev_wallet-CAbOSrak.cjs.map +0 -1
  147. package/dist/dev_wallet-CU3RpQLm.js.map +0 -1
  148. package/dist/execution-J5jkXhV1.d.cts.map +0 -1
  149. package/dist/execution-XJ0iwFaX.d.ts.map +0 -1
  150. package/dist/index-Bb01ytjJ.d.ts.map +0 -1
  151. package/dist/index-C3HVRvQd.d.ts.map +0 -1
  152. package/dist/index-CIHK7Ew9.d.cts +0 -303
  153. package/dist/index-CIHK7Ew9.d.cts.map +0 -1
  154. package/dist/index-CIHK7Ew9.d.ts +0 -303
  155. package/dist/index-CIHK7Ew9.d.ts.map +0 -1
  156. package/dist/index-CedOvhGY.d.cts.map +0 -1
  157. package/dist/index-CtjWsAXV.d.cts.map +0 -1
  158. package/dist/index-CtjZ61tl.d.cts.map +0 -1
  159. package/dist/index-DeS1S0m-.d.ts.map +0 -1
  160. package/dist/index-DfmDUk5Y.d.ts.map +0 -1
  161. package/dist/index-soFVQX9j.d.cts.map +0 -1
  162. package/dist/readError-CCVlmBhj.cjs +0 -624
  163. package/dist/readError-CCVlmBhj.cjs.map +0 -1
  164. package/dist/readError-D1dppovI.js +0 -571
  165. package/dist/readError-D1dppovI.js.map +0 -1
  166. package/dist/readViews-DbWELMMq.d.cts +0 -609
  167. package/dist/readViews-DbWELMMq.d.cts.map +0 -1
  168. package/dist/readViews-nV3jbpYc.d.ts +0 -609
  169. package/dist/readViews-nV3jbpYc.d.ts.map +0 -1
  170. package/dist/sendInvocation-Dsr9ij5P.cjs +0 -661
  171. package/dist/sendInvocation-Dsr9ij5P.cjs.map +0 -1
  172. package/dist/sendInvocation-tBmf8haQ.js +0 -505
  173. package/dist/sendInvocation-tBmf8haQ.js.map +0 -1
  174. package/dist/transport-5FPeNwuv.cjs +0 -279
  175. package/dist/transport-5FPeNwuv.cjs.map +0 -1
  176. package/dist/transport-IrhVlS4w.js +0 -261
  177. package/dist/transport-IrhVlS4w.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-7R5M_7h4.cjs.map +0 -1
  181. package/dist/wallet-BNKgOXrF.js.map +0 -1
@@ -1,4 +1,7 @@
1
- const require_hex = require("./hex-DkGpiZ5e.cjs");
1
+ const require_decimal = require("./decimal-BX7abv5J.cjs");
2
+ const require_hex = require("./hex-CSDZ9d6z.cjs");
3
+ const require_transactionHash = require("./transactionHash-D5yf4KoL.cjs");
4
+ let _thruputchain_protocol = require("@thruputchain/protocol");
2
5
  let _thruputchain_protocol_utils = require("@thruputchain/protocol/utils");
3
6
  //#region src/rpc/schema.json
4
7
  var schema_default = {
@@ -11106,55 +11109,30 @@ var schema_default = {
11106
11109
  }
11107
11110
  };
11108
11111
  //#endregion
11109
- //#region src/actions/decimal.ts
11110
- const I64_MAX = (1n << 63n) - 1n;
11111
- const U64_MAX = (1n << 64n) - 1n;
11112
- /** Parse a canonical, range-checked decimal string. Numeric JSON is never accepted. */
11113
- function parseDecimal(value, field, minimum, maximum) {
11114
- if (typeof value !== "string" || value.length > Math.max(minimum.toString().length, maximum.toString().length) || !/^(0|-?[1-9][0-9]*)(?![\s\S])/.test(value)) throw new Error(`Invalid ${field}: expected a canonical decimal string`);
11115
- const parsed = BigInt(value);
11116
- if (parsed < minimum || parsed > maximum) throw new RangeError(`Invalid ${field}: expected an integer from ${minimum} to ${maximum}`);
11117
- return parsed;
11112
+ //#region src/rpc/localError.ts
11113
+ const localErrors = /* @__PURE__ */ new WeakSet();
11114
+ /** Record an error that the client raised before dispatch. */
11115
+ function markLocalError(error) {
11116
+ localErrors.add(error);
11117
+ return error;
11118
11118
  }
11119
- /** Serialize a caller-owned bigint without passing through a JavaScript number. */
11120
- function serializeHeight(value) {
11121
- if (typeof value !== "bigint" || value < 0n || value > I64_MAX) throw new RangeError("height must be a non-negative int64 bigint");
11122
- return value.toString();
11123
- }
11124
- function serializeU64(value, field) {
11125
- if (typeof value !== "bigint" || value < 0n || value > U64_MAX) throw new RangeError(`${field} must be a uint64 bigint`);
11126
- return value.toString();
11119
+ /** True only for an error recorded by {@link markLocalError}. */
11120
+ function isLocalError(error) {
11121
+ return typeof error === "object" && error !== null && localErrors.has(error);
11127
11122
  }
11128
11123
  //#endregion
11129
11124
  //#region src/rpc/codec.ts
11130
- /** An unfamiliar variant is data, never success, absence, or retry permission. */
11131
- var UnsupportedRpcValue = class {
11132
- raw;
11133
- unsupported = true;
11134
- constructor(raw) {
11135
- this.raw = raw;
11136
- }
11137
- };
11138
11125
  /** Malformed known result data, with the complete original result retained. */
11139
- var RpcDecodingError = class extends Error {
11140
- path;
11141
- raw;
11142
- constructor(path, raw) {
11143
- super(`Invalid native RPC value at ${path}`);
11144
- this.path = path;
11145
- this.raw = raw;
11146
- this.name = "RpcDecodingError";
11147
- }
11148
- };
11126
+ function rpcValueInvalid(path, raw) {
11127
+ return new require_decimal.ThruputError("rpcValueInvalid", `Invalid native RPC value at ${path}`, { context: {
11128
+ path,
11129
+ raw
11130
+ } });
11131
+ }
11149
11132
  /** Invalid local input. The transport was not called; this is not retry permission. */
11150
- var RpcRequestValidationError = class extends Error {
11151
- path;
11152
- constructor(path, message = "Invalid native RPC request") {
11153
- super(`${message} at ${path}`);
11154
- this.path = path;
11155
- this.name = "RpcRequestValidationError";
11156
- }
11157
- };
11133
+ function rpcRequestInvalid(path, message = "Invalid native RPC request") {
11134
+ return markLocalError(new require_decimal.ThruputError("rpcRequestInvalid", `${message} at ${path}`, { context: { path } }));
11135
+ }
11158
11136
  const catalog = schema_default;
11159
11137
  const rpcPageMethods = new Set(Object.entries(catalog.methods).filter(([, m]) => m.paged).map(([name]) => name));
11160
11138
  const patterns = /* @__PURE__ */ new Map();
@@ -11167,13 +11145,20 @@ function matches(pattern, text) {
11167
11145
  return regex.test(text);
11168
11146
  }
11169
11147
  const rpcMethodNames = Object.freeze(Object.keys(catalog.methods));
11170
- function record(value) {
11148
+ function record$1(value) {
11171
11149
  return value !== null && typeof value === "object" && !Array.isArray(value);
11172
11150
  }
11151
+ /** Cheap internal decode failure; each boundary converts it to a `ThruputError` once. */
11152
+ var SchemaMismatch = class {
11153
+ path;
11154
+ constructor(path) {
11155
+ this.path = path;
11156
+ }
11157
+ };
11173
11158
  /** The codec implements only the schema forms emitted by the pinned Rust owner. */
11174
11159
  function convert(s, value, encode, path) {
11175
11160
  const fail = () => {
11176
- throw new RpcDecodingError(path, value);
11161
+ throw new SchemaMismatch(path);
11177
11162
  };
11178
11163
  if (s.$ref) {
11179
11164
  const name = s.$ref.split("/").at(-1);
@@ -11204,18 +11189,18 @@ function convert(s, value, encode, path) {
11204
11189
  if (variants) {
11205
11190
  const tag = s["x-tag"];
11206
11191
  if (tag) {
11207
- if (!record(value) || typeof value[tag] !== "string") return fail();
11192
+ if (!record$1(value) || typeof value[tag] !== "string") return fail();
11208
11193
  const variant = variants.find((v) => v.properties[tag].const === value[tag]);
11209
11194
  if (variant) return convert(variant, value, encode, path);
11210
- if (!encode && s["x-extensible"]) return new UnsupportedRpcValue(value);
11195
+ if (!encode && s["x-extensible"]) return new require_decimal.UnsupportedRpcValue(value);
11211
11196
  return fail();
11212
11197
  }
11213
11198
  for (const variant of variants) try {
11214
11199
  return convert(variant, value, encode, path);
11215
11200
  } catch (error) {
11216
- if (!(error instanceof RpcDecodingError)) throw error;
11201
+ if (!(error instanceof SchemaMismatch)) throw error;
11217
11202
  }
11218
- if (!encode && s["x-extensible"] && typeof value === "string") return new UnsupportedRpcValue(value);
11203
+ if (!encode && s["x-extensible"] && typeof value === "string") return new require_decimal.UnsupportedRpcValue(value);
11219
11204
  return fail();
11220
11205
  }
11221
11206
  if (s["x-integer-minimum"] !== void 0) {
@@ -11228,14 +11213,14 @@ function convert(s, value, encode, path) {
11228
11213
  }
11229
11214
  if (typeof value === "string" && !allowed(value)) return fail();
11230
11215
  try {
11231
- return parseDecimal(value, path, minimum, maximum);
11216
+ return require_decimal.parseDecimal(value, path, minimum, maximum);
11232
11217
  } catch {
11233
11218
  return fail();
11234
11219
  }
11235
11220
  }
11236
11221
  if (s.type === "null") return value === null ? null : fail();
11237
11222
  if (s.type === "object") {
11238
- if (!record(value) || value instanceof Uint8Array) return fail();
11223
+ if (!record$1(value) || value instanceof Uint8Array) return fail();
11239
11224
  const properties = s.properties ?? {};
11240
11225
  if (s["x-forbidden"]?.some((k) => Object.hasOwn(value, k))) return fail();
11241
11226
  for (const [field, required] of Object.entries(s.dependencies ?? {})) if (Object.hasOwn(value, field) && required.some((k) => !Object.hasOwn(value, k))) return fail();
@@ -11274,10 +11259,10 @@ function encodeRequest(method, value) {
11274
11259
  if (!entry) throw new Error(`Unknown native RPC method ${method}`);
11275
11260
  try {
11276
11261
  const encoded = convert(entry.params, value, true, "/params");
11277
- if (entry.paged && Object.hasOwn(encoded, "start") === Object.hasOwn(encoded, "cursor")) throw new RpcDecodingError("/params", value);
11262
+ if (entry.paged && Object.hasOwn(encoded, "start") === Object.hasOwn(encoded, "cursor")) throw new SchemaMismatch("/params");
11278
11263
  return encoded;
11279
11264
  } catch (error) {
11280
- if (error instanceof RpcDecodingError) throw new RpcRequestValidationError(error.path);
11265
+ if (error instanceof SchemaMismatch) throw rpcRequestInvalid(error.path);
11281
11266
  throw error;
11282
11267
  }
11283
11268
  }
@@ -11287,76 +11272,358 @@ function decodeResult(method, value) {
11287
11272
  try {
11288
11273
  return convert(entry.result, value, false, "/result");
11289
11274
  } catch (error) {
11290
- if (error instanceof RpcDecodingError) throw new RpcDecodingError(error.path, value);
11275
+ if (error instanceof SchemaMismatch) throw rpcValueInvalid(error.path, value);
11291
11276
  throw error;
11292
11277
  }
11293
11278
  }
11294
11279
  /** Method/code membership and structural evidence; relational identity checks live in the reader. */
11295
11280
  function decodeErrorData(method, code, value) {
11296
11281
  const entry = catalog.errors[method]?.find((entry) => entry.code === code);
11297
- if (!entry) throw new RpcDecodingError("/error", value);
11298
- return convert(entry.schema, value, false, "/error/data");
11282
+ if (!entry) throw rpcValueInvalid("/error", value);
11283
+ try {
11284
+ return convert(entry.schema, value, false, "/error/data");
11285
+ } catch (error) {
11286
+ if (error instanceof SchemaMismatch) throw rpcValueInvalid(error.path, value);
11287
+ throw error;
11288
+ }
11299
11289
  }
11300
11290
  //#endregion
11301
- Object.defineProperty(exports, "RpcDecodingError", {
11302
- enumerable: true,
11303
- get: function() {
11304
- return RpcDecodingError;
11291
+ //#region src/rpc/errorReader.ts
11292
+ const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
11293
+ const equal$1 = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
11294
+ /**
11295
+ * Classifies method-specific causes without granting retries. Unknown, malformed,
11296
+ * or contradictory evidence stays unclassified with the complete raw error.
11297
+ * Supply the locally computed/requested hash to bind admission or observation evidence.
11298
+ */
11299
+ function decodeRpcError(method, raw, expectedTransactionHash) {
11300
+ const unclassified = () => ({
11301
+ classification: "unclassified",
11302
+ raw
11303
+ });
11304
+ if (!record(raw) || typeof raw.code !== "number" || !Number.isInteger(raw.code) || raw.code < -2147483648 || raw.code > 2147483647 || typeof raw.message !== "string") return unclassified();
11305
+ try {
11306
+ const data = decodeErrorData(method, raw.code, raw.data);
11307
+ if (!validFunding(data)) return unclassified();
11308
+ if (expectedTransactionHash) {
11309
+ if (method === "sendTransaction" && "transactionHash" in data && data.transactionHash && !equal$1(data.transactionHash, expectedTransactionHash)) return unclassified();
11310
+ if (method === "getTransactionReceipt" && "observation" in data && data.observation && !equal$1(data.observation.transactionHash, expectedTransactionHash)) return unclassified();
11311
+ }
11312
+ return {
11313
+ classification: "known",
11314
+ data,
11315
+ raw
11316
+ };
11317
+ } catch (error) {
11318
+ if (require_decimal.isThruputError(error, "rpcValueInvalid")) return unclassified();
11319
+ throw error;
11305
11320
  }
11306
- });
11307
- Object.defineProperty(exports, "RpcRequestValidationError", {
11308
- enumerable: true,
11309
- get: function() {
11310
- return RpcRequestValidationError;
11321
+ }
11322
+ function validFunding(data) {
11323
+ if (data.kind !== "fundingAttemptStopped" && data.kind !== "localFundingUnresolved") return true;
11324
+ if (data.signedTransaction) try {
11325
+ if (!data.transactionHash || !equal$1(require_transactionHash.hashSignedTransaction((0, _thruputchain_protocol.deserialize)(data.signedTransaction, _thruputchain_protocol.codec.SignedTransaction)), data.transactionHash)) return false;
11326
+ } catch {
11327
+ return false;
11311
11328
  }
11312
- });
11313
- Object.defineProperty(exports, "UnsupportedRpcValue", {
11314
- enumerable: true,
11315
- get: function() {
11316
- return UnsupportedRpcValue;
11329
+ if (data.kind === "fundingAttemptStopped") return !data.receipt || !!data.transactionHash && equal$1(data.receipt.transactionHash, data.transactionHash);
11330
+ if (data.cause) {
11331
+ if (!validFunding(data.cause)) return false;
11332
+ if (data.cause.transactionHash && !equal$1(data.cause.transactionHash, data.transactionHash)) return false;
11333
+ if (data.cause.signedTransaction && !equal$1(data.cause.signedTransaction, data.signedTransaction)) return false;
11317
11334
  }
11318
- });
11319
- Object.defineProperty(exports, "decodeErrorData", {
11320
- enumerable: true,
11321
- get: function() {
11322
- return decodeErrorData;
11335
+ return true;
11336
+ }
11337
+ /**
11338
+ * Wrap a JSON-RPC error from a native method. Keep the complete raw error and a
11339
+ * conservative typed reading; unknown or contradictory evidence is `unrecognized`.
11340
+ */
11341
+ function nativeRpcError(error, method, expectedTransactionHash) {
11342
+ const raw = record(error.raw) ? error.raw : {
11343
+ ...typeof error.code === "number" ? { code: error.code } : {},
11344
+ ...typeof error.rpcMessage === "string" ? { message: error.rpcMessage } : {},
11345
+ ...error.data === void 0 ? {} : { data: error.data }
11346
+ };
11347
+ const decoded = decodeRpcError(method, raw, expectedTransactionHash);
11348
+ return new require_decimal.ThruputError("nativeRpcError", `${method}: ${error.rpcMessage} (RPC ${error.code})`, { context: {
11349
+ code: error.code,
11350
+ rpcMessage: error.rpcMessage,
11351
+ method,
11352
+ raw,
11353
+ ...decoded.classification === "known" ? {
11354
+ kind: decoded.data.kind,
11355
+ data: decoded.data
11356
+ } : { kind: "unrecognized" }
11357
+ } });
11358
+ }
11359
+ //#endregion
11360
+ //#region src/rpc/client.ts
11361
+ /**
11362
+ * The endpoint, network, or method set does not match what the client requires.
11363
+ * Raised by a local check, so it proves that the request was not dispatched.
11364
+ */
11365
+ function rpcIncompatible(kind, message) {
11366
+ return markLocalError(new require_decimal.ThruputError("rpcIncompatible", message, { context: { kind } }));
11367
+ }
11368
+ const equal = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
11369
+ /**
11370
+ * Connect a native wire-14 client. This layer reads once or sends once; it does
11371
+ * not sign, poll, retry, refresh discovery on failure, or switch wire formats.
11372
+ * Unknown response variants are UnsupportedRpcValue objects retaining raw data.
11373
+ */
11374
+ async function createRpcClient(options) {
11375
+ const transport = options.transport;
11376
+ const expected = options.expectedNetworkHash ? new Uint8Array(options.expectedNetworkHash) : void 0;
11377
+ if (expected && expected.length !== 32) throw new RangeError("expectedNetworkHash must have 32 bytes");
11378
+ const required = [...options.requiredMethods ?? []];
11379
+ let discovery;
11380
+ let configured = /* @__PURE__ */ new Set();
11381
+ const requireMethods = (methods) => {
11382
+ for (const method of methods) if (!configured.has(method)) throw rpcIncompatible("method", `Endpoint does not advertise ${method}`);
11383
+ };
11384
+ const requestOnce = async (method, params, control, hash) => {
11385
+ try {
11386
+ return await transport.request(method, params, control);
11387
+ } catch (error) {
11388
+ if (require_decimal.isThruputError(error, "rpcError")) throw nativeRpcError(error.context, method, hash);
11389
+ throw error;
11390
+ }
11391
+ };
11392
+ const read = async (method, control) => decodeResult(method, await requestOnce(method, {}, control));
11393
+ const refreshDiscovery = async (control) => {
11394
+ const version = await read("getVersionInfo", control);
11395
+ if (!/^14\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/.test(version.wireFormat)) throw rpcIncompatible("wireVersion", `Unsupported RPC wire format ${version.wireFormat}`);
11396
+ const methods = new Set(version.supportedMethods);
11397
+ for (const method of [
11398
+ "getVersionInfo",
11399
+ "getNetworkInfo",
11400
+ ...required
11401
+ ]) if (!methods.has(method)) throw rpcIncompatible("method", `Endpoint does not advertise ${method}`);
11402
+ const network = await read("getNetworkInfo", control);
11403
+ const wanted = expected ?? discovery?.network.networkHash;
11404
+ if (wanted && !equal(wanted, network.networkHash)) throw rpcIncompatible("network", "RPC network identity does not match");
11405
+ const limits = methods.has("getServerLimits") ? await read("getServerLimits", control) : void 0;
11406
+ discovery = {
11407
+ version,
11408
+ network,
11409
+ ...limits ? { limits } : {}
11410
+ };
11411
+ configured = methods;
11412
+ return structuredClone(discovery);
11413
+ };
11414
+ await refreshDiscovery({ signal: options.signal });
11415
+ const methods = Object.fromEntries(rpcMethodNames.map((name) => [name, async (request = {}, control) => {
11416
+ const method = name;
11417
+ control?.signal?.throwIfAborted();
11418
+ requireMethods([method]);
11419
+ const params = encodeRequest(method, request);
11420
+ const input = structuredClone(request);
11421
+ const limits = discovery.limits;
11422
+ checkLimits(method, input, limits);
11423
+ let submittedHash;
11424
+ if (method === "sendTransaction") try {
11425
+ submittedHash = require_transactionHash.hashSignedTransaction((0, _thruputchain_protocol.deserialize)(input.signedTransaction, _thruputchain_protocol.codec.SignedTransaction));
11426
+ } catch {
11427
+ throw rpcRequestInvalid("/params/signedTransaction", "Invalid signed transaction XDR");
11428
+ }
11429
+ const raw = await requestOnce(method, params, control, submittedHash ?? (method === "getTransactionReceipt" ? input.transactionHash : void 0));
11430
+ const result = decodeResult(method, raw);
11431
+ checkResult(method, input, result, raw, submittedHash, limits, discovery.network.networkHash);
11432
+ return result;
11433
+ }]));
11434
+ return Object.defineProperty(Object.assign(methods, {
11435
+ refreshDiscovery,
11436
+ requireMethods
11437
+ }), "discovery", {
11438
+ get: () => structuredClone(discovery),
11439
+ enumerable: true
11440
+ });
11441
+ }
11442
+ function checkLimits(method, input, limits) {
11443
+ if (rpcPageMethods.has(method)) {
11444
+ if (!limits) throw rpcIncompatible("limits", "History calls require advertised server limits");
11445
+ const cap = method === "getEvents" ? limits.maxEventsPerPage : limits.maxTransactionsPerPage;
11446
+ if (input.limit !== void 0 && input.limit > cap) throw rpcRequestInvalid("/params/limit", `limit exceeds endpoint cap ${cap}`);
11447
+ if (typeof input.cursor === "string" && BigInt((input.cursor.length - 2) / 2) > limits.maxCursorBytes) throw rpcRequestInvalid("/params/cursor", "cursor exceeds endpoint cap");
11323
11448
  }
11324
- });
11325
- Object.defineProperty(exports, "decodeResult", {
11326
- enumerable: true,
11327
- get: function() {
11328
- return decodeResult;
11449
+ if (method === "simulateInvocation" || method === "simulateInvocations") {
11450
+ if (!limits) throw rpcIncompatible("limits", "Simulation calls require advertised server limits");
11451
+ const calls = method === "simulateInvocation" ? [input] : input.invocations;
11452
+ let gas = 0n, bytes = 0;
11453
+ for (const call of calls) {
11454
+ const callGas = call.gasLimit;
11455
+ if (callGas !== void 0 && callGas > limits.maxSimulationGas) throw rpcRequestInvalid("/params/gasLimit", "gasLimit exceeds endpoint cap");
11456
+ const size = call.calldata.length;
11457
+ if (BigInt(size) > limits.maxSimulationCalldataBytes) throw rpcRequestInvalid("/params/calldata", "calldata exceeds endpoint cap");
11458
+ gas += callGas ?? limits.maxSimulationGas;
11459
+ bytes += size;
11460
+ }
11461
+ if (method === "simulateInvocations") {
11462
+ const batch = limits.simulationBatch;
11463
+ if (!batch) throw rpcIncompatible("limits", "Batch simulation limits are unavailable");
11464
+ if (calls.length > batch.maxInvocations || bytes > batch.maxCalldataBytes || gas > batch.maxGas) throw rpcRequestInvalid("/params/invocations", "simulation batch exceeds endpoint cap");
11465
+ }
11329
11466
  }
11330
- });
11331
- Object.defineProperty(exports, "encodeRequest", {
11332
- enumerable: true,
11333
- get: function() {
11334
- return encodeRequest;
11467
+ }
11468
+ /**
11469
+ * Local block and time results must match their own request: a pinned
11470
+ * timepoint comes back exactly, a multi-block request returns `count`
11471
+ * blocks, a step change reports the requested step (none when cleared), and a
11472
+ * mode change reports the requested mode and interval.
11473
+ */
11474
+ function checkBlockControlResult(method, input, value, invalid) {
11475
+ if (method === "dev_produceBlock") {
11476
+ const block = value;
11477
+ if (block.blockHeight <= 0n || input.blockTimepoint !== void 0 && block.blockTimepoint !== input.blockTimepoint) invalid();
11335
11478
  }
11336
- });
11337
- Object.defineProperty(exports, "rpcMethodNames", {
11479
+ if (method === "dev_produceBlocks" && value.blocks.length !== input.count) invalid();
11480
+ if (method === "dev_setNextBlockTimepoint" && value.nextBlockTimepoint !== input.blockTimepoint) invalid();
11481
+ if (method === "dev_setBlockTimeStep" && value.stepNanoseconds !== input.stepNanoseconds) invalid();
11482
+ if (method === "dev_setBlockDriver") {
11483
+ const status = value;
11484
+ if (typeof status.mode === "string" && status.mode !== input.mode || input.intervalMilliseconds !== void 0 && status.intervalMilliseconds !== input.intervalMilliseconds) invalid();
11485
+ }
11486
+ }
11487
+ function checkResult(method, input, value, raw, submittedHash, limits, networkHash) {
11488
+ const invalid = () => {
11489
+ throw rpcValueInvalid("/result", raw);
11490
+ };
11491
+ if (value === null) return;
11492
+ const result = value;
11493
+ if (method === "getTransactionReceipt" && !equal(result.transactionHash, input.transactionHash) || submittedHash && !equal(result.transactionHash, submittedHash)) invalid();
11494
+ if (method === "getBlockByHeight" && (result.blockHeight <= 0n || result.blockHeight !== input.blockHeight || !equal(result.networkHash, networkHash))) invalid();
11495
+ if ((method === "getBalance" || method === "getRegisteredAuth") && !equal(result.address, input.address)) invalid();
11496
+ if (method === "simulateInvocations" && result.results.length !== input.invocations.length) invalid();
11497
+ if ((method === "simulateInvocation" || method === "simulateInvocations") && input.minStateBlockHeight !== void 0 && result.stateBlockHeight < input.minStateBlockHeight) invalid();
11498
+ if (method === "dev_fundAccount") {
11499
+ const funding = value;
11500
+ try {
11501
+ if (!equal(funding.recipient, input.recipient) || funding.rawAmount !== input.rawAmount || !equal(funding.transactionHash, require_transactionHash.hashSignedTransaction((0, _thruputchain_protocol.deserialize)(funding.signedTransaction, _thruputchain_protocol.codec.SignedTransaction)))) invalid();
11502
+ } catch {
11503
+ invalid();
11504
+ }
11505
+ }
11506
+ checkBlockControlResult(method, input, value, invalid);
11507
+ if (method === "faucet_requestAirdrop" && "recipient" in result && !equal(result.recipient, input.recipient)) invalid();
11508
+ if (!rpcPageMethods.has(method)) return;
11509
+ const page = value;
11510
+ const entries = method === "getEvents" ? page.events : page.transactions;
11511
+ const cap = method === "getEvents" ? limits.maxEventsPerPage : limits.maxTransactionsPerPage;
11512
+ if (page.oldestIndexedBlockHeight > page.latestIndexedBlockHeight || entries.length > (input.limit ?? Math.min(50, cap)) || page.nextCursor !== null && (page.nextCursor === input.cursor || BigInt((page.nextCursor.length - 2) / 2) > limits.maxCursorBytes)) invalid();
11513
+ if (entries.some((entry) => entry.blockHeight < page.oldestIndexedBlockHeight || entry.blockHeight > page.latestIndexedBlockHeight)) invalid();
11514
+ const start = input.start;
11515
+ if (method === "getTransactionsByBlock") {
11516
+ if (page.oldestIndexedBlockHeight < 1n || !entries.length && page.nextCursor !== null || input.cursor !== void 0 && (input.blockHeight < page.oldestIndexedBlockHeight || input.blockHeight > page.latestIndexedBlockHeight) || entries.some((entry) => entry.blockHeight !== input.blockHeight)) invalid();
11517
+ } else if (start?.anchor.kind === "atHeight") {
11518
+ const anchor = start.anchor.blockHeight;
11519
+ if (anchor < page.oldestIndexedBlockHeight || entries.some((entry) => start.order === "ascending" ? entry.blockHeight < anchor : entry.blockHeight > anchor)) invalid();
11520
+ }
11521
+ const identities = /* @__PURE__ */ new Set();
11522
+ const keys = [];
11523
+ for (const [index, entry] of entries.entries()) {
11524
+ const event = method === "getEvents" ? page.events[index] : void 0;
11525
+ const hash = require_hex.toHex0x(entry.transactionHash);
11526
+ const sequence = event?.sequenceNumber ?? 0;
11527
+ const identity = method === "getEvents" ? `${hash}/${sequence}` : hash;
11528
+ if (identities.has(identity)) invalid();
11529
+ identities.add(identity);
11530
+ keys.push([
11531
+ entry.blockHeight,
11532
+ hash,
11533
+ sequence
11534
+ ]);
11535
+ if (event && !input.filters.some((filter) => filter.addresses.some((address) => equal(address, event.event.address)) && [
11536
+ "topic0",
11537
+ "topic1",
11538
+ "topic2"
11539
+ ].every((key, i) => {
11540
+ const values = filter.topics?.[key];
11541
+ return !values?.length || !!event.event.topics[i] && values.some((topic) => equal(topic, event.event.topics[i]));
11542
+ }))) invalid();
11543
+ }
11544
+ const compare = (left, right) => {
11545
+ for (let i = 0; i < 3; i++) {
11546
+ if (left[i] < right[i]) return -1;
11547
+ if (left[i] > right[i]) return 1;
11548
+ }
11549
+ return 0;
11550
+ };
11551
+ const asc = keys.every((key, i) => i === 0 || compare(keys[i - 1], key) < 0);
11552
+ const desc = keys.every((key, i) => i === 0 || compare(keys[i - 1], key) > 0);
11553
+ if (!(start ? start.order === "ascending" ? asc : desc : asc || desc)) invalid();
11554
+ }
11555
+ //#endregion
11556
+ //#region src/transport/readError.ts
11557
+ /**
11558
+ * Classify an infrastructure read failure without replacing the original error.
11559
+ *
11560
+ * Pass the caller's signal to distinguish explicit cancellation from a transport
11561
+ * timeout. Plain Error wrappers are inspected through their causes; other
11562
+ * `ThruputError` codes and unrecognized failures remain unknown. A bare TypeError
11563
+ * is not evidence of a network failure. Custom transports should throw code
11564
+ * `httpRequestFailed` for that case. Transaction-not-found remains
11565
+ * operation-specific rather than a general retry. This classification never
11566
+ * authorizes transaction resubmission.
11567
+ */
11568
+ function classifyReadError(error, options = {}) {
11569
+ if (options.signal?.aborted) return "cancelled";
11570
+ const seen = /* @__PURE__ */ new Set();
11571
+ while (error !== null && typeof error === "object" && !seen.has(error)) {
11572
+ seen.add(error);
11573
+ if (require_decimal.isThruputError(error, "httpRequestFailed")) return "transient";
11574
+ if (require_decimal.isThruputError(error, "httpResponseError")) return [
11575
+ 408,
11576
+ 429,
11577
+ 500,
11578
+ 502,
11579
+ 503,
11580
+ 504
11581
+ ].includes(error.context.status) ? "transient" : "permanent";
11582
+ if (require_decimal.isThruputError(error, "nativeRpcError")) switch (error.context.kind) {
11583
+ case "backendUnavailable":
11584
+ case "stateHeightUnavailable":
11585
+ case "backendTimeout":
11586
+ case "overloaded": return "transient";
11587
+ case "invalidParams":
11588
+ case "invalidCursor":
11589
+ case "transactionInvalid":
11590
+ case "transactionRejected":
11591
+ case "historyUnavailable": return "permanent";
11592
+ default: return "unknown";
11593
+ }
11594
+ if ("name" in error) {
11595
+ if (error.name === "TimeoutError") return "transient";
11596
+ if (error.name === "AbortError") return "cancelled";
11597
+ }
11598
+ if (!(error instanceof Error) || error.constructor !== Error) return "unknown";
11599
+ error = error.cause;
11600
+ }
11601
+ return "unknown";
11602
+ }
11603
+ //#endregion
11604
+ Object.defineProperty(exports, "classifyReadError", {
11338
11605
  enumerable: true,
11339
11606
  get: function() {
11340
- return rpcMethodNames;
11607
+ return classifyReadError;
11341
11608
  }
11342
11609
  });
11343
- Object.defineProperty(exports, "rpcPageMethods", {
11610
+ Object.defineProperty(exports, "createRpcClient", {
11344
11611
  enumerable: true,
11345
11612
  get: function() {
11346
- return rpcPageMethods;
11613
+ return createRpcClient;
11347
11614
  }
11348
11615
  });
11349
- Object.defineProperty(exports, "serializeHeight", {
11616
+ Object.defineProperty(exports, "isLocalError", {
11350
11617
  enumerable: true,
11351
11618
  get: function() {
11352
- return serializeHeight;
11619
+ return isLocalError;
11353
11620
  }
11354
11621
  });
11355
- Object.defineProperty(exports, "serializeU64", {
11622
+ Object.defineProperty(exports, "rpcIncompatible", {
11356
11623
  enumerable: true,
11357
11624
  get: function() {
11358
- return serializeU64;
11625
+ return rpcIncompatible;
11359
11626
  }
11360
11627
  });
11361
11628
 
11362
- //# sourceMappingURL=codec-BcK8ASsg.cjs.map
11629
+ //# sourceMappingURL=readError-COcEDNoZ.cjs.map