quantum-coin-js-sdk 2.0.1 → 2.1.1

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 (233) hide show
  1. package/README.md +13 -0
  2. package/index.d.ts +9 -0
  3. package/index.js +37 -4
  4. package/package.json +12 -4
  5. package/wasmBase64.js +3 -2
  6. package/.gitignore +0 -4
  7. package/.idea/.name +0 -1
  8. package/.idea/modules.xml +0 -8
  9. package/.idea/quantum-coin-js-sdk.iml +0 -12
  10. package/.idea/vcs.xml +0 -6
  11. package/.vs/ProjectSettings.json +0 -3
  12. package/.vs/VSWorkspaceState.json +0 -8
  13. package/.vs/quantum-coin-js-sdk/FileContentIndex/a9d6de82-cfc3-4c22-ac38-06d706ff3673.vsidx +0 -0
  14. package/.vs/quantum-coin-js-sdk/FileContentIndex/fdc816df-1898-4153-99f2-c69ef4c2283b.vsidx +0 -0
  15. package/.vs/quantum-coin-js-sdk/config/applicationhost.config +0 -1011
  16. package/.vs/quantum-coin-js-sdk/v17/.wsuo +0 -0
  17. package/.vs/quantum-coin-js-sdk/v17/DocumentLayout.backup.json +0 -39
  18. package/.vs/quantum-coin-js-sdk/v17/DocumentLayout.json +0 -57
  19. package/.vs/slnx.sqlite +0 -0
  20. package/example/README.md +0 -14
  21. package/example/conversion-example.js +0 -19
  22. package/example/example-create-contract.js +0 -396
  23. package/example/example-encode-decode-rlp.js +0 -225
  24. package/example/example-event-pack-unpack.js +0 -391
  25. package/example/example-misc.js +0 -96
  26. package/example/example-token-pack-unpack.js +0 -960
  27. package/example/example-wallet-version4.js +0 -34
  28. package/example/example-wallet.js +0 -39
  29. package/example/example.js +0 -115
  30. package/example/node_modules/.bin/sdkgen +0 -16
  31. package/example/node_modules/.bin/sdkgen.cmd +0 -17
  32. package/example/node_modules/.bin/sdkgen.ps1 +0 -28
  33. package/example/node_modules/.package-lock.json +0 -51
  34. package/example/node_modules/quantumcoin/.github/workflows/publish-npmjs.yaml +0 -22
  35. package/example/node_modules/quantumcoin/LICENSE +0 -21
  36. package/example/node_modules/quantumcoin/README-SDK.md +0 -828
  37. package/example/node_modules/quantumcoin/README.md +0 -197
  38. package/example/node_modules/quantumcoin/config.d.ts +0 -50
  39. package/example/node_modules/quantumcoin/config.js +0 -123
  40. package/example/node_modules/quantumcoin/examples/AllSolidityTypes.sol +0 -184
  41. package/example/node_modules/quantumcoin/examples/SimpleIERC20.sol +0 -74
  42. package/example/node_modules/quantumcoin/examples/events.js +0 -41
  43. package/example/node_modules/quantumcoin/examples/events.ts +0 -35
  44. package/example/node_modules/quantumcoin/examples/example-generator-sdk-js.js +0 -100
  45. package/example/node_modules/quantumcoin/examples/example-generator-sdk-js.ts +0 -77
  46. package/example/node_modules/quantumcoin/examples/example-generator-sdk-ts.js +0 -100
  47. package/example/node_modules/quantumcoin/examples/example-generator-sdk-ts.ts +0 -77
  48. package/example/node_modules/quantumcoin/examples/example.js +0 -67
  49. package/example/node_modules/quantumcoin/examples/example.ts +0 -56
  50. package/example/node_modules/quantumcoin/examples/offline-signing.js +0 -77
  51. package/example/node_modules/quantumcoin/examples/offline-signing.ts +0 -65
  52. package/example/node_modules/quantumcoin/examples/package-lock.json +0 -596
  53. package/example/node_modules/quantumcoin/examples/package.json +0 -32
  54. package/example/node_modules/quantumcoin/examples/read-operations.js +0 -32
  55. package/example/node_modules/quantumcoin/examples/read-operations.ts +0 -31
  56. package/example/node_modules/quantumcoin/examples/sdk-generator-erc20.inline.json +0 -251
  57. package/example/node_modules/quantumcoin/examples/solidity-types.ts +0 -43
  58. package/example/node_modules/quantumcoin/examples/wallet-offline.js +0 -36
  59. package/example/node_modules/quantumcoin/examples/wallet-offline.ts +0 -26
  60. package/example/node_modules/quantumcoin/generate-sdk.js +0 -1846
  61. package/example/node_modules/quantumcoin/index.js +0 -12
  62. package/example/node_modules/quantumcoin/package.json +0 -95
  63. package/example/node_modules/quantumcoin/scripts/copy-declarations.js +0 -31
  64. package/example/node_modules/quantumcoin/scripts/run-all-one-by-one.js +0 -151
  65. package/example/node_modules/quantumcoin/src/abi/fragments.d.ts +0 -42
  66. package/example/node_modules/quantumcoin/src/abi/fragments.js +0 -63
  67. package/example/node_modules/quantumcoin/src/abi/index.d.ts +0 -13
  68. package/example/node_modules/quantumcoin/src/abi/index.js +0 -9
  69. package/example/node_modules/quantumcoin/src/abi/interface.d.ts +0 -128
  70. package/example/node_modules/quantumcoin/src/abi/interface.js +0 -605
  71. package/example/node_modules/quantumcoin/src/abi/js-abi-coder.d.ts +0 -8
  72. package/example/node_modules/quantumcoin/src/abi/js-abi-coder.js +0 -538
  73. package/example/node_modules/quantumcoin/src/constants.d.ts +0 -61
  74. package/example/node_modules/quantumcoin/src/constants.js +0 -94
  75. package/example/node_modules/quantumcoin/src/contract/contract-factory.d.ts +0 -28
  76. package/example/node_modules/quantumcoin/src/contract/contract-factory.js +0 -111
  77. package/example/node_modules/quantumcoin/src/contract/contract.d.ts +0 -113
  78. package/example/node_modules/quantumcoin/src/contract/contract.js +0 -408
  79. package/example/node_modules/quantumcoin/src/contract/index.d.ts +0 -9
  80. package/example/node_modules/quantumcoin/src/contract/index.js +0 -9
  81. package/example/node_modules/quantumcoin/src/errors/index.d.ts +0 -92
  82. package/example/node_modules/quantumcoin/src/errors/index.js +0 -200
  83. package/example/node_modules/quantumcoin/src/generator/index.d.ts +0 -81
  84. package/example/node_modules/quantumcoin/src/generator/index.js +0 -1571
  85. package/example/node_modules/quantumcoin/src/index.d.ts +0 -122
  86. package/example/node_modules/quantumcoin/src/index.js +0 -41
  87. package/example/node_modules/quantumcoin/src/internal/hex.d.ts +0 -68
  88. package/example/node_modules/quantumcoin/src/internal/hex.js +0 -180
  89. package/example/node_modules/quantumcoin/src/providers/extra-providers.d.ts +0 -139
  90. package/example/node_modules/quantumcoin/src/providers/extra-providers.js +0 -614
  91. package/example/node_modules/quantumcoin/src/providers/index.d.ts +0 -17
  92. package/example/node_modules/quantumcoin/src/providers/index.js +0 -10
  93. package/example/node_modules/quantumcoin/src/providers/json-rpc-provider.d.ts +0 -12
  94. package/example/node_modules/quantumcoin/src/providers/json-rpc-provider.js +0 -89
  95. package/example/node_modules/quantumcoin/src/providers/provider.d.ts +0 -206
  96. package/example/node_modules/quantumcoin/src/providers/provider.js +0 -524
  97. package/example/node_modules/quantumcoin/src/types/index.d.ts +0 -214
  98. package/example/node_modules/quantumcoin/src/types/index.js +0 -9
  99. package/example/node_modules/quantumcoin/src/utils/address.d.ts +0 -58
  100. package/example/node_modules/quantumcoin/src/utils/address.js +0 -144
  101. package/example/node_modules/quantumcoin/src/utils/encoding.d.ts +0 -120
  102. package/example/node_modules/quantumcoin/src/utils/encoding.js +0 -306
  103. package/example/node_modules/quantumcoin/src/utils/fixednumber.d.ts +0 -57
  104. package/example/node_modules/quantumcoin/src/utils/fixednumber.js +0 -366
  105. package/example/node_modules/quantumcoin/src/utils/hashing.d.ts +0 -76
  106. package/example/node_modules/quantumcoin/src/utils/hashing.js +0 -298
  107. package/example/node_modules/quantumcoin/src/utils/index.d.ts +0 -63
  108. package/example/node_modules/quantumcoin/src/utils/index.js +0 -14
  109. package/example/node_modules/quantumcoin/src/utils/result.d.ts +0 -57
  110. package/example/node_modules/quantumcoin/src/utils/result.js +0 -128
  111. package/example/node_modules/quantumcoin/src/utils/rlp.d.ts +0 -12
  112. package/example/node_modules/quantumcoin/src/utils/rlp.js +0 -215
  113. package/example/node_modules/quantumcoin/src/utils/units.d.ts +0 -29
  114. package/example/node_modules/quantumcoin/src/utils/units.js +0 -107
  115. package/example/node_modules/quantumcoin/src/wallet/index.d.ts +0 -10
  116. package/example/node_modules/quantumcoin/src/wallet/index.js +0 -8
  117. package/example/node_modules/quantumcoin/src/wallet/wallet.d.ts +0 -192
  118. package/example/node_modules/quantumcoin/src/wallet/wallet.js +0 -713
  119. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.dynamic.test.js +0 -207
  120. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.dynamic.test.ts +0 -191
  121. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.fixtures.js +0 -231
  122. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +0 -387
  123. package/example/node_modules/quantumcoin/test/e2e/all-solidity-types.generated-sdks.e2e.test.ts +0 -350
  124. package/example/node_modules/quantumcoin/test/e2e/generator-interface.e2e.test.js +0 -165
  125. package/example/node_modules/quantumcoin/test/e2e/generator-interface.e2e.test.ts +0 -160
  126. package/example/node_modules/quantumcoin/test/e2e/helpers.js +0 -59
  127. package/example/node_modules/quantumcoin/test/e2e/signing-context-and-fee.e2e.test.js +0 -141
  128. package/example/node_modules/quantumcoin/test/e2e/signing-context-and-fee.e2e.test.ts +0 -128
  129. package/example/node_modules/quantumcoin/test/e2e/simple-erc20.generated-sdks.e2e.test.js +0 -168
  130. package/example/node_modules/quantumcoin/test/e2e/simple-erc20.generated-sdks.e2e.test.ts +0 -141
  131. package/example/node_modules/quantumcoin/test/e2e/transactional.test.js +0 -245
  132. package/example/node_modules/quantumcoin/test/e2e/transactional.test.ts +0 -208
  133. package/example/node_modules/quantumcoin/test/e2e/typed-generator.e2e.test.js +0 -407
  134. package/example/node_modules/quantumcoin/test/e2e/typed-generator.e2e.test.ts +0 -337
  135. package/example/node_modules/quantumcoin/test/fixtures/ConstructorParam.sol +0 -23
  136. package/example/node_modules/quantumcoin/test/fixtures/MultiContracts.sol +0 -37
  137. package/example/node_modules/quantumcoin/test/fixtures/SimpleStorage.sol +0 -18
  138. package/example/node_modules/quantumcoin/test/fixtures/StakingContract.abi.json +0 -1
  139. package/example/node_modules/quantumcoin/test/integration/ipc-provider.test.js +0 -49
  140. package/example/node_modules/quantumcoin/test/integration/ipc-provider.test.ts +0 -44
  141. package/example/node_modules/quantumcoin/test/integration/provider.test.js +0 -88
  142. package/example/node_modules/quantumcoin/test/integration/provider.test.ts +0 -85
  143. package/example/node_modules/quantumcoin/test/integration/ws-provider.test.js +0 -41
  144. package/example/node_modules/quantumcoin/test/integration/ws-provider.test.ts +0 -38
  145. package/example/node_modules/quantumcoin/test/security/abi-decoder-bounds.test.js +0 -122
  146. package/example/node_modules/quantumcoin/test/security/contract-overrides.test.js +0 -112
  147. package/example/node_modules/quantumcoin/test/security/generator-injection.test.js +0 -195
  148. package/example/node_modules/quantumcoin/test/security/malformed-input.test.js +0 -330
  149. package/example/node_modules/quantumcoin/test/security/malformed-input.test.ts +0 -35
  150. package/example/node_modules/quantumcoin/test/security/rpc-numeric-bounds.test.js +0 -81
  151. package/example/node_modules/quantumcoin/test/security/rpc-trust.test.js +0 -202
  152. package/example/node_modules/quantumcoin/test/unit/_encrypted-output.txt +0 -6
  153. package/example/node_modules/quantumcoin/test/unit/_log-encrypted-jsons.js +0 -45
  154. package/example/node_modules/quantumcoin/test/unit/_write-keystore-fixture.js +0 -16
  155. package/example/node_modules/quantumcoin/test/unit/abi-interface.test.js +0 -110
  156. package/example/node_modules/quantumcoin/test/unit/abi-interface.test.ts +0 -109
  157. package/example/node_modules/quantumcoin/test/unit/address-wallet.test.js +0 -923
  158. package/example/node_modules/quantumcoin/test/unit/address-wallet.test.ts +0 -877
  159. package/example/node_modules/quantumcoin/test/unit/browser-provider.test.js +0 -85
  160. package/example/node_modules/quantumcoin/test/unit/browser-provider.test.ts +0 -79
  161. package/example/node_modules/quantumcoin/test/unit/contract.test.js +0 -85
  162. package/example/node_modules/quantumcoin/test/unit/contract.test.ts +0 -83
  163. package/example/node_modules/quantumcoin/test/unit/encoding-units-rlp.test.js +0 -127
  164. package/example/node_modules/quantumcoin/test/unit/encoding-units-rlp.test.ts +0 -91
  165. package/example/node_modules/quantumcoin/test/unit/errors.test.js +0 -77
  166. package/example/node_modules/quantumcoin/test/unit/errors.test.ts +0 -76
  167. package/example/node_modules/quantumcoin/test/unit/filter-by-blockhash.test.js +0 -55
  168. package/example/node_modules/quantumcoin/test/unit/filter-by-blockhash.test.ts +0 -54
  169. package/example/node_modules/quantumcoin/test/unit/fixednumber.test.js +0 -656
  170. package/example/node_modules/quantumcoin/test/unit/fixednumber.test.ts +0 -660
  171. package/example/node_modules/quantumcoin/test/unit/fixtures/encrypted-keystores-48-32-36.js +0 -9
  172. package/example/node_modules/quantumcoin/test/unit/generate-contract-cli.test.js +0 -42
  173. package/example/node_modules/quantumcoin/test/unit/generate-contract-cli.test.ts +0 -41
  174. package/example/node_modules/quantumcoin/test/unit/generate-sdk-artifacts-json.test.js +0 -113
  175. package/example/node_modules/quantumcoin/test/unit/generate-sdk-artifacts-json.test.ts +0 -110
  176. package/example/node_modules/quantumcoin/test/unit/generator.test.js +0 -149
  177. package/example/node_modules/quantumcoin/test/unit/generator.test.ts +0 -148
  178. package/example/node_modules/quantumcoin/test/unit/hashing.test.js +0 -64
  179. package/example/node_modules/quantumcoin/test/unit/hashing.test.ts +0 -63
  180. package/example/node_modules/quantumcoin/test/unit/init.test.js +0 -39
  181. package/example/node_modules/quantumcoin/test/unit/init.test.ts +0 -38
  182. package/example/node_modules/quantumcoin/test/unit/interface.test.js +0 -56
  183. package/example/node_modules/quantumcoin/test/unit/interface.test.ts +0 -54
  184. package/example/node_modules/quantumcoin/test/unit/internal-hex.test.js +0 -81
  185. package/example/node_modules/quantumcoin/test/unit/internal-hex.test.ts +0 -80
  186. package/example/node_modules/quantumcoin/test/unit/populate-transaction.test.js +0 -98
  187. package/example/node_modules/quantumcoin/test/unit/populate-transaction.test.ts +0 -64
  188. package/example/node_modules/quantumcoin/test/unit/providers.test.js +0 -252
  189. package/example/node_modules/quantumcoin/test/unit/providers.test.ts +0 -251
  190. package/example/node_modules/quantumcoin/test/unit/result.test.js +0 -80
  191. package/example/node_modules/quantumcoin/test/unit/result.test.ts +0 -79
  192. package/example/node_modules/quantumcoin/test/unit/solidity-types.test.js +0 -49
  193. package/example/node_modules/quantumcoin/test/unit/solidity-types.test.ts +0 -39
  194. package/example/node_modules/quantumcoin/test/unit/utils.test.js +0 -57
  195. package/example/node_modules/quantumcoin/test/unit/utils.test.ts +0 -56
  196. package/example/node_modules/quantumcoin/test/verbose-logger.js +0 -74
  197. package/example/node_modules/quantumcoin/tsconfig.build.json +0 -14
  198. package/example/node_modules/seed-words/.github/workflows/publish-npmjs.yaml +0 -22
  199. package/example/node_modules/seed-words/BUILD.md +0 -7
  200. package/example/node_modules/seed-words/LICENSE +0 -121
  201. package/example/node_modules/seed-words/README.md +0 -67
  202. package/example/node_modules/seed-words/dist/seedwords.d.ts +0 -39
  203. package/example/node_modules/seed-words/package.json +0 -27
  204. package/example/node_modules/seed-words/seedwords.js +0 -315
  205. package/example/node_modules/seed-words/seedwords.txt +0 -65536
  206. package/example/node_modules/seed-words/tsconfig.json +0 -21
  207. package/example/package-lock.json +0 -60
  208. package/example/package.json +0 -15
  209. package/scripts/build-browser-tests.js +0 -29
  210. package/scripts/build-wasm.js +0 -85
  211. package/tests/browser/bundle.js +0 -97643
  212. package/tests/browser/entry.js +0 -57
  213. package/tests/browser/harness.html +0 -20
  214. package/tests/browser/run-browser.js +0 -50
  215. package/tests/encrypted-32.json +0 -1
  216. package/tests/encrypted-36.json +0 -1
  217. package/tests/encrypted-48.json +0 -1
  218. package/tests/generate-verify-vectors.js +0 -88
  219. package/tests/get-gas-price.test.js +0 -59
  220. package/tests/hashing.test.js +0 -34
  221. package/tests/non-transactional.preinit.test.js +0 -33
  222. package/tests/non-transactional.test.js +0 -1318
  223. package/tests/sign-raw-keytype5-context-null.test.js +0 -105
  224. package/tests/sign-raw-transaction.test.js +0 -194
  225. package/tests/sign-verify.test.js +0 -308
  226. package/tests/specs/assert.js +0 -74
  227. package/tests/specs/crypto.spec.js +0 -104
  228. package/tests/specs/hex.js +0 -31
  229. package/tests/specs/preinit.spec.js +0 -19
  230. package/tests/specs/sign.spec.js +0 -90
  231. package/tests/specs/wallet.spec.js +0 -98
  232. package/tests/transactional.rpc.test.js +0 -102
  233. package/tests/verify-vectors.json +0 -95035
@@ -1,605 +0,0 @@
1
- /**
2
- * @fileoverview Interface and ABI encoding/decoding helpers.
3
- *
4
- * This is a compatibility layer modelled after ethers.js v6 `Interface`,
5
- * but adapted for QuantumCoin. ABI packing/unpacking is delegated to
6
- * `quantum-coin-js-sdk` (WASM) as required by SPEC.md.
7
- */
8
-
9
- const qcsdk = require("quantum-coin-js-sdk");
10
- const { makeError, assertArgument } = require("../errors");
11
- const { normalizeHex, arrayify, bytesToHex } = require("../internal/hex");
12
- const { EventFragment, FunctionFragment, ErrorFragment, ConstructorFragment } = require("./fragments");
13
- const { Result } = require("../utils/result");
14
- const { id } = require("../utils/hashing");
15
- const jsAbi = require("./js-abi-coder");
16
-
17
- function _requireInitialized() {
18
- // eslint-disable-next-line global-require
19
- const { isInitialized, getInitializationPromise } = require("../../config");
20
- if (isInitialized()) return;
21
- if (getInitializationPromise() != null) {
22
- throw makeError(
23
- "QuantumCoin SDK is still initializing. Await the Initialize() promise before using SDK methods.",
24
- "UNKNOWN_ERROR",
25
- { operation: "requireInitialized" },
26
- );
27
- }
28
- throw makeError("QuantumCoin SDK not initialized. Call Initialize() first.", "UNKNOWN_ERROR", {
29
- operation: "abi",
30
- });
31
- }
32
-
33
- function _sanitizeArg(value) {
34
- // quantum-coin-js-sdk WASM interop does not accept BigInt values directly.
35
- // Convert bigint to a decimal string (ethers-like behaviour).
36
- if (typeof value === "bigint") return value.toString();
37
- if (Array.isArray(value)) return value.map(_sanitizeArg);
38
- if (value && typeof value === "object") {
39
- // Avoid mutating user input; shallow clone.
40
- const out = {};
41
- for (const k of Object.keys(value)) out[k] = _sanitizeArg(value[k]);
42
- return out;
43
- }
44
- return value;
45
- }
46
-
47
- function _sanitizeArgs(values) {
48
- return (Array.isArray(values) ? values : []).map(_sanitizeArg);
49
- }
50
-
51
- function _asAbiArray(abi) {
52
- if (abi == null) return [];
53
- if (Array.isArray(abi)) return abi;
54
- if (typeof abi === "object" && typeof abi.formatJson === "function") return JSON.parse(abi.formatJson());
55
- throw makeError("invalid ABI", "INVALID_ARGUMENT", { abi });
56
- }
57
-
58
- function _isNumericString(v) {
59
- return typeof v === "string" && /^-?\d+$/.test(v.trim());
60
- }
61
-
62
- function _normalizeParamTypeForQcsdk(type, components) {
63
- if (typeof type !== "string") return type;
64
-
65
- // Arrays preserve their shape; normalize the element type.
66
- if (type.endsWith("]")) {
67
- const inner = type.slice(0, type.lastIndexOf("["));
68
- const suffix = type.slice(type.lastIndexOf("["));
69
- return _normalizeParamTypeForQcsdk(inner, components) + suffix;
70
- }
71
-
72
- // Tuples: normalize component types recursively.
73
- if (type === "tuple") return "tuple";
74
-
75
- // quantum-coin-js-sdk currently only reliably packs int256/uint256.
76
- if (type === "uint" || type.startsWith("uint")) return "uint256";
77
- if (type === "int" || type.startsWith("int")) return "int256";
78
-
79
- // Fixed-size bytes (bytes1..bytes32) are encoded as a single 32-byte word.
80
- // Encode them via uint256 (big-endian), with right-padding applied.
81
- if (type.startsWith("bytes")) {
82
- const m = type.match(/^bytes(\d+)$/);
83
- if (m) return "uint256";
84
- }
85
-
86
- return type;
87
- }
88
-
89
- function _normalizeAbiForQcsdk(abi) {
90
- const out = Array.isArray(abi) ? abi.map((f) => ({ ...(f || {}) })) : [];
91
- for (const f of out) {
92
- if (!f || typeof f !== "object") continue;
93
- const inputs = Array.isArray(f.inputs) ? f.inputs : [];
94
- const outputs = Array.isArray(f.outputs) ? f.outputs : [];
95
- const normalizeParams = (params) =>
96
- params.map((p) => {
97
- const np = { ...(p || {}) };
98
- np.type = _normalizeParamTypeForQcsdk(String(np.type || ""), np.components);
99
- if (Array.isArray(np.components) && np.components.length > 0) {
100
- np.components = normalizeParams(np.components);
101
- }
102
- return np;
103
- });
104
- f.inputs = normalizeParams(inputs);
105
- if (f.type === "function") f.outputs = normalizeParams(outputs);
106
- if (f.type === "event") f.inputs = normalizeParams(inputs);
107
- if (f.type === "error") f.inputs = normalizeParams(inputs);
108
- if (f.type === "constructor") f.inputs = normalizeParams(inputs);
109
- }
110
- return out;
111
- }
112
-
113
- function _fixedBytesToUint256Decimal(type, value) {
114
- // Allow already-normalized numeric values.
115
- if (typeof value === "number") return value;
116
- if (_isNumericString(value)) return value.trim();
117
-
118
- const m = String(type || "").match(/^bytes(\d+)$/);
119
- const n = m ? Number(m[1]) : 0;
120
- if (!Number.isFinite(n) || n < 1 || n > 32) return value;
121
-
122
- const b = arrayify(value);
123
- if (b.length > n) throw makeError("fixed bytes value exceeds length", "INVALID_ARGUMENT", { type, length: b.length });
124
-
125
- // Right-pad to N bytes, then right-pad to 32 bytes (Solidity fixed bytes encoding).
126
- const fixed = new Uint8Array(n);
127
- fixed.set(b, 0);
128
- const word = new Uint8Array(32);
129
- word.set(fixed, 0);
130
-
131
- const hexWord = bytesToHex(word); // 0x + 64 hex
132
- // Convert to decimal string for qcsdk (it can parse uint256 from decimal string).
133
- return BigInt(hexWord).toString();
134
- }
135
-
136
- function _uint256ToFixedBytesHex(type, value) {
137
- const m = String(type || "").match(/^bytes(\d+)$/);
138
- const n = m ? Number(m[1]) : 0;
139
- if (!Number.isFinite(n) || n < 1 || n > 32) return value;
140
- if (value == null) return value;
141
-
142
- const bi = typeof value === "bigint" ? value : BigInt(value);
143
- if (bi >= (1n << 256n)) throw makeError("value exceeds uint256", "INVALID_ARGUMENT", { value: bi.toString() });
144
- let hex = bi.toString(16);
145
- hex = hex.padStart(64, "0");
146
- // bytesN is the first N bytes (right-padded in the 32-byte word).
147
- return normalizeHex("0x" + hex.slice(0, n * 2));
148
- }
149
-
150
- function _convertInputValueForQcsdk(param, value) {
151
- const type = String(param && param.type ? param.type : "");
152
-
153
- // Apply bigint sanitization early.
154
- const v = _sanitizeArg(value);
155
-
156
- // Arrays
157
- if (type.endsWith("]")) {
158
- const innerType = type.slice(0, type.lastIndexOf("["));
159
- const innerParam = { ...(param || {}), type: innerType };
160
- if (!Array.isArray(v)) return v;
161
- return v.map((x) => _convertInputValueForQcsdk(innerParam, x));
162
- }
163
-
164
- // Tuples
165
- if (type === "tuple") {
166
- const comps = Array.isArray(param && param.components) ? param.components : [];
167
- if (Array.isArray(v)) {
168
- return v.map((x, idx) => _convertInputValueForQcsdk(comps[idx] || { type: "uint256" }, x));
169
- }
170
- if (v && typeof v === "object") {
171
- const out = {};
172
- for (let i = 0; i < comps.length; i++) {
173
- const c = comps[i];
174
- const name = c && typeof c.name === "string" && c.name ? c.name : String(i);
175
- out[name] = _convertInputValueForQcsdk(c, v[name] != null ? v[name] : v[String(i)]);
176
- }
177
- return out;
178
- }
179
- return v;
180
- }
181
-
182
- // Fixed bytes
183
- const mBytes = type.match(/^bytes(\d+)$/);
184
- if (mBytes) {
185
- return _fixedBytesToUint256Decimal(type, v);
186
- }
187
-
188
- return v;
189
- }
190
-
191
- function _convertOutputValueFromQcsdk(param, value) {
192
- const type = String(param && param.type ? param.type : "");
193
-
194
- if (type.endsWith("]")) {
195
- const innerType = type.slice(0, type.lastIndexOf("["));
196
- const innerParam = { ...(param || {}), type: innerType };
197
- if (!Array.isArray(value)) return value;
198
- return value.map((x) => _convertOutputValueFromQcsdk(innerParam, x));
199
- }
200
-
201
- if (type === "tuple") {
202
- const comps = Array.isArray(param && param.components) ? param.components : [];
203
- if (Array.isArray(value)) {
204
- return value.map((x, idx) => _convertOutputValueFromQcsdk(comps[idx] || { type: "uint256" }, x));
205
- }
206
- if (value && typeof value === "object") {
207
- const out = {};
208
- for (let i = 0; i < comps.length; i++) {
209
- const c = comps[i];
210
- const name = c && typeof c.name === "string" && c.name ? c.name : String(i);
211
- const raw = Object.prototype.hasOwnProperty.call(value, name)
212
- ? value[name]
213
- : Object.prototype.hasOwnProperty.call(value, String(i))
214
- ? value[String(i)]
215
- : undefined;
216
- out[name] = _convertOutputValueFromQcsdk(c, raw);
217
- }
218
- return out;
219
- }
220
- return value;
221
- }
222
-
223
- const mBytes = type.match(/^bytes(\d+)$/);
224
- if (mBytes) {
225
- return _uint256ToFixedBytesHex(type, value);
226
- }
227
-
228
- // Normalize integer outputs to bigint for consistency with core typings.
229
- if (type === "uint" || type.startsWith("uint") || type === "int" || type.startsWith("int")) {
230
- if (value == null) return value;
231
- if (typeof value === "bigint") return value;
232
- try {
233
- return BigInt(value);
234
- } catch {
235
- return value;
236
- }
237
- }
238
-
239
- return value;
240
- }
241
-
242
- class Interface {
243
- /**
244
- * @param {any[]|Interface} abi
245
- */
246
- constructor(abi) {
247
- this.abi = _asAbiArray(abi);
248
- this._abiJson = JSON.stringify(this.abi);
249
- this._qcsdkAbi = _normalizeAbiForQcsdk(this.abi);
250
- this._qcsdkAbiJson = JSON.stringify(this._qcsdkAbi);
251
- }
252
-
253
- /**
254
- * Returns JSON format of ABI.
255
- * @returns {string}
256
- */
257
- formatJson() {
258
- return this._abiJson;
259
- }
260
-
261
- /**
262
- * Internal: normalized ABI JSON for qcsdk.
263
- * @returns {string}
264
- */
265
- _qcsdkFormatJson() {
266
- return this._qcsdkAbiJson;
267
- }
268
-
269
- /**
270
- * Internal: normalize argument values for qcsdk based on original ABI params.
271
- * @param {Array<any>} params
272
- * @param {Array<any>} values
273
- * @returns {Array<any>}
274
- */
275
- _qcsdkNormalizeValues(params, values) {
276
- const ps = Array.isArray(params) ? params : [];
277
- const vs = Array.isArray(values) ? values : [];
278
- return ps.map((p, i) => _convertInputValueForQcsdk(p, vs[i]));
279
- }
280
-
281
- /**
282
- * Basic formatter (ethers supports multiple formats).
283
- * @param {string=} format
284
- * @returns {string}
285
- */
286
- format(format) {
287
- void format;
288
- return this._abiJson;
289
- }
290
-
291
- /**
292
- * Get a function fragment by name (first match).
293
- * @param {string} nameOrSignature
294
- * @returns {FunctionFragment}
295
- */
296
- getFunction(nameOrSignature) {
297
- assertArgument(typeof nameOrSignature === "string", "name must be a string", "nameOrSignature", nameOrSignature);
298
- const found = this.abi.find((f) => f && f.type === "function" && f.name === nameOrSignature);
299
- if (!found) throw makeError("function not found", "INVALID_ARGUMENT", { nameOrSignature });
300
- return new FunctionFragment(found);
301
- }
302
-
303
- /**
304
- * Get an event fragment by name (first match).
305
- * @param {string} nameOrSignature
306
- * @returns {EventFragment}
307
- */
308
- getEvent(nameOrSignature) {
309
- assertArgument(typeof nameOrSignature === "string", "name must be a string", "nameOrSignature", nameOrSignature);
310
- const found = this.abi.find((f) => f && f.type === "event" && f.name === nameOrSignature);
311
- if (!found) throw makeError("event not found", "INVALID_ARGUMENT", { nameOrSignature });
312
- return new EventFragment(found);
313
- }
314
-
315
- /**
316
- * Get an error fragment by name (first match).
317
- * @param {string} nameOrSignature
318
- * @returns {ErrorFragment}
319
- */
320
- getError(nameOrSignature) {
321
- assertArgument(typeof nameOrSignature === "string", "name must be a string", "nameOrSignature", nameOrSignature);
322
- const found = this.abi.find((f) => f && f.type === "error" && f.name === nameOrSignature);
323
- if (!found) throw makeError("error not found", "INVALID_ARGUMENT", { nameOrSignature });
324
- return new ErrorFragment(found);
325
- }
326
-
327
- /**
328
- * Returns the constructor fragment if present.
329
- * @returns {ConstructorFragment|null}
330
- */
331
- getConstructor() {
332
- const found = this.abi.find((f) => f && f.type === "constructor");
333
- return found ? new ConstructorFragment(found) : null;
334
- }
335
-
336
- /**
337
- * Encode function data using quantum-coin-js-sdk.
338
- * @param {FunctionFragment|string} functionFragment
339
- * @param {any[]} values
340
- * @returns {string}
341
- */
342
- encodeFunctionData(functionFragment, values) {
343
- _requireInitialized();
344
- const name = typeof functionFragment === "string" ? functionFragment : functionFragment?.name;
345
- assertArgument(typeof name === "string" && name.length > 0, "invalid function", "functionFragment", functionFragment);
346
- const frag = this.getFunction(name);
347
- const inputs = Array.isArray(frag.inputs) ? frag.inputs : [];
348
- const rawArgs = Array.isArray(values) ? values : [];
349
-
350
- // Fallback for complex ABI surfaces where qcsdk packing is unreliable.
351
- if (jsAbi.needsJsAbi(inputs)) {
352
- return jsAbi.encodeFunctionData(name, inputs, rawArgs);
353
- }
354
-
355
- const args = inputs.map((p, idx) => _convertInputValueForQcsdk(p, rawArgs[idx]));
356
- const res = qcsdk.packMethodData(this._qcsdkAbiJson, name, ...args);
357
- if (!res || typeof res.error !== "string") throw makeError("packMethodData failed", "UNKNOWN_ERROR", {});
358
- if (res.error) throw makeError(res.error, "UNKNOWN_ERROR", { operation: "packMethodData", function: name });
359
- return normalizeHex(res.result);
360
- }
361
-
362
- /**
363
- * Decode function result using quantum-coin-js-sdk.
364
- * @param {FunctionFragment|string} functionFragment
365
- * @param {string} data
366
- * @returns {any}
367
- */
368
- decodeFunctionResult(functionFragment, data) {
369
- _requireInitialized();
370
- const name = typeof functionFragment === "string" ? functionFragment : functionFragment?.name;
371
- assertArgument(typeof name === "string" && name.length > 0, "invalid function", "functionFragment", functionFragment);
372
- assertArgument(typeof data === "string", "data must be a hex string", "data", data);
373
- const frag = this.getFunction(name);
374
- const outputs = Array.isArray(frag.outputs) ? frag.outputs : [];
375
-
376
- // Fallback for complex output surfaces.
377
- if (jsAbi.needsJsAbi(outputs)) {
378
- return jsAbi.decodeFunctionResult(outputs, data);
379
- }
380
-
381
- const res = qcsdk.unpackMethodData(this._qcsdkAbiJson, name, data);
382
- if (!res || typeof res.error !== "string") throw makeError("unpackMethodData failed", "UNKNOWN_ERROR", {});
383
- if (res.error) throw makeError(res.error, "UNKNOWN_ERROR", { operation: "unpackMethodData", function: name });
384
- try {
385
- const decoded = JSON.parse(res.result);
386
- // qcsdk generally returns an array for function outputs; convert bytesN back to hex.
387
- if (Array.isArray(decoded)) {
388
- return decoded.map((v, i) => _convertOutputValueFromQcsdk(outputs[i] || { type: "uint256" }, v));
389
- }
390
- return _convertOutputValueFromQcsdk(outputs[0] || { type: "uint256" }, decoded);
391
- } catch {
392
- return res.result;
393
- }
394
- }
395
-
396
- /**
397
- * Encode an event log from values.
398
- * @param {EventFragment|any} eventFragment
399
- * @param {any[]} values
400
- * @returns {{ topics: string[], data: string }}
401
- */
402
- encodeEventLog(eventFragment, values) {
403
- _requireInitialized();
404
- const name = typeof eventFragment === "string" ? eventFragment : eventFragment?.name;
405
- assertArgument(typeof name === "string" && name.length > 0, "invalid event", "eventFragment", eventFragment);
406
- const frag = this.getEvent(name);
407
- const inputs = Array.isArray(frag.inputs) ? frag.inputs : [];
408
- const rawArgs = Array.isArray(values) ? values : [];
409
- const args = inputs.map((p, idx) => _convertInputValueForQcsdk(p, rawArgs[idx]));
410
- const res = qcsdk.encodeEventLog(this._qcsdkAbiJson, name, ...args);
411
- if (!res || typeof res.error !== "string") throw makeError("encodeEventLog failed", "UNKNOWN_ERROR", {});
412
- if (res.error) throw makeError(res.error, "UNKNOWN_ERROR", { operation: "encodeEventLog", event: name });
413
- return res.result;
414
- }
415
-
416
- /**
417
- * Decode an event log.
418
- * @param {EventFragment|any} eventFragment
419
- * @param {string[]} topics
420
- * @param {string} data
421
- * @returns {any}
422
- */
423
- decodeEventLog(eventFragment, topics, data) {
424
- _requireInitialized();
425
- const name = typeof eventFragment === "string" ? eventFragment : eventFragment?.name;
426
- assertArgument(typeof name === "string" && name.length > 0, "invalid event", "eventFragment", eventFragment);
427
- assertArgument(Array.isArray(topics), "topics must be an array", "topics", topics);
428
- assertArgument(typeof data === "string", "data must be a string", "data", data);
429
- const frag = this.getEvent(name);
430
- const inputs = Array.isArray(frag.inputs) ? frag.inputs : [];
431
- const res = qcsdk.decodeEventLog(this._qcsdkAbiJson, name, topics, data);
432
- if (!res || typeof res.error !== "string") throw makeError("decodeEventLog failed", "UNKNOWN_ERROR", {});
433
- if (res.error) throw makeError(res.error, "UNKNOWN_ERROR", { operation: "decodeEventLog", event: name });
434
- try {
435
- const decoded = JSON.parse(res.result);
436
- if (Array.isArray(decoded)) {
437
- return decoded.map((v, i) => _convertOutputValueFromQcsdk(inputs[i] || { type: "uint256" }, v));
438
- }
439
- return decoded;
440
- } catch {
441
- return res.result;
442
- }
443
- }
444
-
445
- // The following methods exist in ethers.js v6. We provide placeholders to keep API shape.
446
- parseTransaction() {
447
- throw makeError("parseTransaction not implemented", "NOT_IMPLEMENTED", {});
448
- }
449
- parseLog() {
450
- _requireInitialized();
451
- const log = arguments.length > 0 ? arguments[0] : null;
452
- assertArgument(log && typeof log === "object", "log must be an object", "log", log);
453
-
454
- const topics = log.topics;
455
- const data = log.data;
456
- assertArgument(Array.isArray(topics), "log.topics must be an array", "log.topics", topics);
457
- assertArgument(typeof data === "string", "log.data must be a string", "log.data", data);
458
- assertArgument(topics.length > 0, "log.topics must contain at least 1 topic", "log.topics", topics);
459
-
460
- const topic0 = normalizeHex(String(topics[0]));
461
-
462
- // Find event by signature topic. (Anonymous events cannot be auto-detected.)
463
- /** @type {any|null} */
464
- let matched = null;
465
- /** @type {string|null} */
466
- let signature = null;
467
-
468
- for (const f of this.abi) {
469
- if (!f || f.type !== "event") continue;
470
- if (f.anonymous) continue;
471
- if (!f.name) continue;
472
- const inputs = Array.isArray(f.inputs) ? f.inputs : [];
473
- const sig = `${f.name}(${inputs.map((i) => String(i.type || "")).join(",")})`;
474
- const t = normalizeHex(id(sig));
475
- if (t === topic0) {
476
- matched = f;
477
- signature = sig;
478
- break;
479
- }
480
- }
481
-
482
- if (!matched) {
483
- throw makeError("no matching event for log.topics[0]", "INVALID_ARGUMENT", { topic0 });
484
- }
485
-
486
- const fragment = new EventFragment(matched);
487
- const decoded = this.decodeEventLog(fragment.name, topics.map((t) => normalizeHex(String(t))), normalizeHex(data));
488
-
489
- const inputs = Array.isArray(matched.inputs) ? matched.inputs : [];
490
- const keys = inputs.map((i) => (i && typeof i.name === "string" && i.name.length ? i.name : null));
491
-
492
- let items = [];
493
- if (Array.isArray(decoded)) {
494
- items = decoded;
495
- } else if (decoded && typeof decoded === "object") {
496
- items = inputs.map((i, idx) => {
497
- const n = i && typeof i.name === "string" ? i.name : null;
498
- if (n && Object.prototype.hasOwnProperty.call(decoded, n)) return decoded[n];
499
- if (Object.prototype.hasOwnProperty.call(decoded, String(idx))) return decoded[String(idx)];
500
- return undefined;
501
- });
502
- } else {
503
- items = inputs.map(() => decoded);
504
- }
505
-
506
- const args = Result.fromItems(items, keys);
507
- return {
508
- fragment,
509
- name: fragment.name,
510
- signature: signature || fragment.name,
511
- topic: topic0,
512
- args,
513
- };
514
- }
515
- parseError() {
516
- throw makeError("parseError not implemented", "NOT_IMPLEMENTED", {});
517
- }
518
- getSighash() {
519
- throw makeError("getSighash not implemented", "NOT_IMPLEMENTED", {});
520
- }
521
- /**
522
- * Compute the topic0 (event signature hash) for an event.
523
- * @param {string|EventFragment|any} nameOrFragment
524
- * @returns {string} normalized 0x-prefixed topic hash
525
- */
526
- getEventTopic(nameOrFragment) {
527
- const name = typeof nameOrFragment === "string" ? nameOrFragment : nameOrFragment?.name;
528
- const frag = this.getEvent(name);
529
- const inputs = Array.isArray(frag.inputs) ? frag.inputs : [];
530
- const sig = `${frag.name}(${inputs.map((i) => String(i.type || "")).join(",")})`;
531
- return normalizeHex(id(sig));
532
- }
533
- getFallback() {
534
- return null;
535
- }
536
- getReceive() {
537
- return null;
538
- }
539
- }
540
-
541
- class AbiCoder {
542
- /**
543
- * Encode values by types into ABI data.
544
- * @param {(string|any)[]} types
545
- * @param {any[]} values
546
- * @returns {string}
547
- */
548
- encode(types, values) {
549
- _requireInitialized();
550
- assertArgument(Array.isArray(types), "types must be an array", "types", types);
551
- assertArgument(Array.isArray(values), "values must be an array", "values", values);
552
-
553
- const abi = [
554
- {
555
- type: "function",
556
- name: "__encode",
557
- stateMutability: "pure",
558
- inputs: types.map((t, i) => ({ name: `arg${i}`, type: String(t) })),
559
- outputs: [],
560
- },
561
- ];
562
- const iface = new Interface(abi);
563
- const full = iface.encodeFunctionData("__encode", values);
564
- // Strip the 4-byte selector (8 hex chars) + 0x
565
- return "0x" + full.slice(10);
566
- }
567
-
568
- /**
569
- * Decode ABI data by output types.
570
- * @param {(string|any)[]} types
571
- * @param {string} data
572
- * @returns {any}
573
- */
574
- decode(types, data) {
575
- _requireInitialized();
576
- assertArgument(Array.isArray(types), "types must be an array", "types", types);
577
- assertArgument(typeof data === "string", "data must be a string", "data", data);
578
-
579
- const abi = [
580
- {
581
- type: "function",
582
- name: "__decode",
583
- stateMutability: "pure",
584
- inputs: [],
585
- outputs: types.map((t, i) => ({ name: `ret${i}`, type: String(t) })),
586
- },
587
- ];
588
- const iface = new Interface(abi);
589
- return iface.decodeFunctionResult("__decode", data);
590
- }
591
-
592
- /**
593
- * Return a default value for types.
594
- * @param {(string|any)[]} types
595
- * @returns {any}
596
- */
597
- getDefaultValue(types) {
598
- // Lightweight default; ethers returns a Result. Here we return array of nulls.
599
- assertArgument(Array.isArray(types), "types must be an array", "types", types);
600
- return types.map(() => null);
601
- }
602
- }
603
-
604
- module.exports = { Interface, AbiCoder };
605
-
@@ -1,8 +0,0 @@
1
- export function hasTuple(params: any): boolean;
2
- export function hasNestedArrays(params: any): boolean;
3
- export function needsJsAbi(params: any): boolean;
4
- export function canonicalType(param: any): any;
5
- export function functionSelectorHex(name: any, inputs: any): string;
6
- export function encodeFunctionData(name: any, inputs: any, values: any): string;
7
- export function encodeTupleLike(params: any, values: any): Uint8Array<any>;
8
- export function decodeFunctionResult(outputs: any, dataHex: any): any[];