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,524 +0,0 @@
1
- /**
2
- * @fileoverview Provider base classes and common types.
3
- *
4
- * This module models ethers.js v6 Provider patterns, adapted for QuantumCoin.
5
- * The concrete JSON-RPC implementation lives in `json-rpc-provider.js`.
6
- */
7
-
8
- const { EventEmitter } = require("events");
9
- const { makeError, assertArgument } = require("../errors");
10
- const { normalizeHex, toQuantityHex, isHexString } = require("../internal/hex");
11
-
12
- /**
13
- * @typedef {import("../utils/encoding").BytesLike} BytesLike
14
- */
15
-
16
- /**
17
- * @typedef {Object} TransactionRequest
18
- * @property {string=} to
19
- * @property {string=} from
20
- * @property {bigint|string|number=} value
21
- * @property {string=} data
22
- * @property {bigint|string|number=} gasLimit
23
- * @property {number=} nonce
24
- * @property {number=} chainId
25
- * @property {string=} remarks Optional remark field (hex, max 32 bytes)
26
- * @property {number|null=} signingContext Optional signing context (0, 1, 2, or null). Passed to SDK TransactionSigningRequest; default null.
27
- */
28
-
29
- /**
30
- * @typedef {Object} Filter
31
- * @property {string|string[]=} address
32
- * @property {(string|string[]|null)[]=} topics
33
- * @property {number|string=} fromBlock
34
- * @property {number|string=} toBlock
35
- * @property {string=} blockHash
36
- */
37
-
38
- function _hexToBigInt(hex) {
39
- if (typeof hex === "bigint") return hex;
40
- if (typeof hex === "number") return BigInt(hex);
41
- if (hex === "0x" || hex === "0X") return 0n;
42
- assertArgument(typeof hex === "string" && /^0x[0-9a-fA-F]+$/.test(hex), "invalid hex quantity", "hex", hex);
43
- return BigInt(hex);
44
- }
45
-
46
- function _hexToNumber(hex) {
47
- // RPC quantities are untrusted. Previously `Number(bigint)` silently
48
- // truncated values above 2^53, corrupting blockNumber/nonce/status/indices used
49
- // in confirmation math. We keep returning a `number` (no signature/type change),
50
- // but fail loudly for out-of-range values instead of returning a corrupted one.
51
- // Real chain values are far below MAX_SAFE_INTEGER, so honest flows are
52
- // unaffected. (Returning bigint would break field types and wait() arithmetic.)
53
- const bi = _hexToBigInt(hex);
54
- if (bi > BigInt(Number.MAX_SAFE_INTEGER) || bi < BigInt(Number.MIN_SAFE_INTEGER)) {
55
- throw makeError("RPC quantity exceeds safe integer range", "NUMERIC_FAULT", { value: bi.toString() });
56
- }
57
- return Number(bi);
58
- }
59
-
60
- /**
61
- * Convert block tag (number or string) to the format eth_getLogs expects (hex with 0x or "latest"/"pending"/"earliest").
62
- * @param {number|string|undefined} blockTag
63
- * @returns {string|undefined}
64
- */
65
- /**
66
- * Build a lowercase Set of allowed log addresses from a filter's `address` field
67
- * (string or string[]). Returns null when no address constraint is present.
68
- * @param {string|string[]|undefined|null} address
69
- * @returns {Set<string>|null}
70
- */
71
- function _normalizeAddressFilter(address) {
72
- if (address == null) return null;
73
- const list = Array.isArray(address) ? address : [address];
74
- const set = new Set();
75
- for (const a of list) {
76
- if (typeof a === "string" && a.length > 0) set.add(a.toLowerCase());
77
- }
78
- return set.size ? set : null;
79
- }
80
-
81
- /**
82
- * Check a log's topics against a requested topics filter (eth_getLogs
83
- * semantics). Each filter position may be null (wildcard), a string (exact
84
- * match), or an array of strings (any match). Used to drop logs a malicious node
85
- * returns that do not actually match the requested event topic(s).
86
- * @param {any[]} logTopics
87
- * @param {(string|string[]|null)[]} filterTopics
88
- * @returns {boolean}
89
- */
90
- function _topicsMatch(logTopics, filterTopics) {
91
- if (!Array.isArray(filterTopics)) return true;
92
- const topics = Array.isArray(logTopics) ? logTopics : [];
93
- for (let i = 0; i < filterTopics.length; i++) {
94
- const want = filterTopics[i];
95
- if (want == null) continue; // wildcard position
96
- const have = typeof topics[i] === "string" ? topics[i].toLowerCase() : null;
97
- if (have == null) return false;
98
- const allowed = (Array.isArray(want) ? want : [want])
99
- .filter((t) => typeof t === "string")
100
- .map((t) => t.toLowerCase());
101
- if (allowed.length && !allowed.includes(have)) return false;
102
- }
103
- return true;
104
- }
105
-
106
- function _blockTagToHex(blockTag) {
107
- if (blockTag === undefined || blockTag === null) return undefined;
108
- const s = String(blockTag).toLowerCase();
109
- if (s === "latest" || s === "pending" || s === "earliest") return s;
110
- const n = typeof blockTag === "number" ? blockTag : Number(blockTag);
111
- if (!Number.isInteger(n) || n < 0) return undefined;
112
- return toQuantityHex(n);
113
- }
114
-
115
- /**
116
- * Minimal Log wrapper (ethers-like).
117
- */
118
- class Log {
119
- /**
120
- * @param {any} log
121
- * @param {AbstractProvider=} provider
122
- */
123
- constructor(log, provider) {
124
- this.provider = provider || null;
125
- this.address = log.address;
126
- this.topics = log.topics || [];
127
- this.data = log.data || "0x";
128
- this.blockHash = log.blockHash || null;
129
- this.blockNumber = log.blockNumber != null ? _hexToNumber(log.blockNumber) : null;
130
- this.transactionHash = log.transactionHash || null;
131
- this.transactionIndex = log.transactionIndex != null ? _hexToNumber(log.transactionIndex) : null;
132
- this.logIndex = log.logIndex != null ? _hexToNumber(log.logIndex) : null;
133
- this.removed = Boolean(log.removed);
134
- }
135
-
136
- async getBlock() {
137
- if (!this.provider || this.blockNumber == null) return null;
138
- return this.provider.getBlock(this.blockNumber);
139
- }
140
-
141
- async getTransaction() {
142
- if (!this.provider || !this.transactionHash) return null;
143
- return this.provider.getTransaction(this.transactionHash);
144
- }
145
-
146
- async getTransactionReceipt() {
147
- if (!this.provider || !this.transactionHash) return null;
148
- return this.provider.getTransactionReceipt(this.transactionHash);
149
- }
150
- }
151
-
152
- /**
153
- * Minimal TransactionReceipt wrapper (ethers-like).
154
- */
155
- class TransactionReceipt {
156
- /**
157
- * @param {any} receipt
158
- * @param {AbstractProvider=} provider
159
- */
160
- constructor(receipt, provider) {
161
- this.provider = provider || null;
162
- this.to = receipt.to || null;
163
- this.from = receipt.from || null;
164
- this.contractAddress = receipt.contractAddress || null;
165
- this.transactionHash = receipt.transactionHash;
166
- this.blockHash = receipt.blockHash;
167
- this.blockNumber = receipt.blockNumber != null ? _hexToNumber(receipt.blockNumber) : null;
168
- this.transactionIndex = receipt.transactionIndex != null ? _hexToNumber(receipt.transactionIndex) : null;
169
- this.gasUsed = receipt.gasUsed != null ? _hexToBigInt(receipt.gasUsed) : null;
170
- this.status = receipt.status != null ? _hexToNumber(receipt.status) : null;
171
- this.logs = Array.isArray(receipt.logs) ? receipt.logs.map((l) => new Log(l, provider)) : [];
172
- }
173
- }
174
-
175
- /**
176
- * Minimal TransactionResponse wrapper (ethers-like).
177
- */
178
- class TransactionResponse {
179
- /**
180
- * @param {any} tx
181
- * @param {AbstractProvider=} provider
182
- */
183
- constructor(tx, provider) {
184
- this.provider = provider || null;
185
- this.hash = tx.hash;
186
- this.to = tx.to || null;
187
- this.from = tx.from || null;
188
- this.nonce = tx.nonce != null ? _hexToNumber(tx.nonce) : null;
189
- this.data = tx.input || tx.data || "0x";
190
- this.value = tx.value != null ? _hexToBigInt(tx.value) : 0n;
191
- this.gasLimit = tx.gas != null ? _hexToBigInt(tx.gas) : null;
192
- this.chainId = tx.chainId != null ? _hexToNumber(tx.chainId) : null;
193
- this.blockNumber = tx.blockNumber != null ? _hexToNumber(tx.blockNumber) : null;
194
- this.txType = tx.type != null ? _hexToNumber(tx.type) : null;
195
- this.remarks = tx.remarks != null ? normalizeHex(tx.remarks) : null;
196
- }
197
-
198
- /**
199
- * Wait for confirmations.
200
- * @param {number=} confirmations
201
- * @param {number=} timeoutMs
202
- * @returns {Promise<TransactionReceipt>}
203
- */
204
- async wait(confirmations, timeoutMs) {
205
- if (!this.provider) throw makeError("missing provider", "UNKNOWN_ERROR", { operation: "wait" });
206
- const conf = confirmations == null ? 1 : confirmations;
207
- const start = Date.now();
208
- const timeout = timeoutMs == null ? 120_000 : timeoutMs;
209
-
210
- while (true) {
211
- const receipt = await this.provider.getTransactionReceipt(this.hash);
212
- if (receipt && receipt.blockNumber != null) {
213
- if (conf <= 1) return receipt;
214
- const current = await this.provider.getBlockNumber();
215
- if (current - receipt.blockNumber + 1 >= conf) return receipt;
216
- }
217
- if (Date.now() - start > timeout) {
218
- throw makeError("timeout waiting for transaction", "UNKNOWN_ERROR", { hash: this.hash });
219
- }
220
- await new Promise((r) => setTimeout(r, 2_000));
221
- }
222
- }
223
- }
224
-
225
- /**
226
- * Minimal Block wrapper (ethers-like).
227
- */
228
- class Block {
229
- /**
230
- * @param {any} block
231
- * @param {AbstractProvider=} provider
232
- */
233
- constructor(block, provider) {
234
- this.provider = provider || null;
235
- this.hash = block.hash || null;
236
- this.parentHash = block.parentHash || null;
237
- this.number = block.number != null ? _hexToNumber(block.number) : null;
238
- this.timestamp = block.timestamp != null ? _hexToNumber(block.timestamp) : null;
239
- this.transactions = block.transactions || [];
240
- }
241
-
242
- async getTransaction(indexOrHash) {
243
- if (!this.provider) return null;
244
- if (typeof indexOrHash === "number") {
245
- const hash = this.transactions[indexOrHash];
246
- if (!hash) return null;
247
- return this.provider.getTransaction(hash);
248
- }
249
- if (typeof indexOrHash === "string") return this.provider.getTransaction(indexOrHash);
250
- return null;
251
- }
252
-
253
- async getTransactionReceipt(indexOrHash) {
254
- if (!this.provider) return null;
255
- const tx = await this.getTransaction(indexOrHash);
256
- if (!tx) return null;
257
- return this.provider.getTransactionReceipt(tx.hash);
258
- }
259
-
260
- getPrefetchedTransactions() {
261
- // This implementation returns only hashes unless `eth_getBlockByNumber(..., true)` is used.
262
- return [];
263
- }
264
- }
265
-
266
- /**
267
- * Base Provider class.
268
- */
269
- class Provider extends EventEmitter {
270
- constructor() {
271
- super();
272
- }
273
- }
274
-
275
- /**
276
- * AbstractProvider base class (ethers-like).
277
- */
278
- class AbstractProvider extends Provider {
279
- constructor() {
280
- super();
281
- }
282
-
283
- /**
284
- * Implemented by subclasses to perform JSON-RPC.
285
- * @param {string} method
286
- * @param {any[]=} params
287
- * @returns {Promise<any>}
288
- */
289
- async _perform(method, params) {
290
- void method;
291
- void params;
292
- throw makeError("_perform not implemented", "NOT_IMPLEMENTED", {});
293
- }
294
-
295
- async getBlockNumber() {
296
- const hex = await this._perform("eth_blockNumber", []);
297
- return _hexToNumber(hex);
298
- }
299
-
300
- /**
301
- * @param {number|"latest"} blockNumber
302
- * @returns {Promise<Block>}
303
- */
304
- async getBlock(blockNumber) {
305
- const tag = blockNumber === "latest" ? "latest" : toQuantityHex(blockNumber);
306
- const block = await this._perform("eth_getBlockByNumber", [tag, false]);
307
- return new Block(block, this);
308
- }
309
-
310
- /**
311
- * @param {string} txHash
312
- * @returns {Promise<TransactionResponse>}
313
- */
314
- async getTransaction(txHash) {
315
- const tx = await this._perform("eth_getTransactionByHash", [txHash]);
316
- if (!tx) return null;
317
- const result = new TransactionResponse(tx, this);
318
- // Do not trust the node to return the transaction we actually asked for.
319
- // When the response carries a hash, it must match the requested hash;
320
- // otherwise a malicious node could substitute a different transaction.
321
- if (
322
- typeof txHash === "string" &&
323
- typeof result.hash === "string" &&
324
- result.hash.length > 0 &&
325
- result.hash.toLowerCase() !== txHash.toLowerCase()
326
- ) {
327
- throw makeError("RPC node returned a transaction whose hash does not match the requested hash", "UNKNOWN_ERROR", {
328
- operation: "getTransaction",
329
- expected: txHash,
330
- got: result.hash,
331
- });
332
- }
333
- return result;
334
- }
335
-
336
- /**
337
- * @param {string} txHash
338
- * @returns {Promise<TransactionReceipt>}
339
- */
340
- async getTransactionReceipt(txHash) {
341
- const receipt = await this._perform("eth_getTransactionReceipt", [txHash]);
342
- if (!receipt) return null;
343
- const result = new TransactionReceipt(receipt, this);
344
- // The receipt must belong to the transaction we asked about. A node must
345
- // not be able to confirm an unrelated/fabricated transaction (which would let
346
- // wait() report success for the wrong tx).
347
- if (
348
- typeof txHash === "string" &&
349
- typeof result.transactionHash === "string" &&
350
- result.transactionHash.length > 0 &&
351
- result.transactionHash.toLowerCase() !== txHash.toLowerCase()
352
- ) {
353
- throw makeError("RPC node returned a receipt whose hash does not match the requested hash", "UNKNOWN_ERROR", {
354
- operation: "getTransactionReceipt",
355
- expected: txHash,
356
- got: result.transactionHash,
357
- });
358
- }
359
- return result;
360
- }
361
-
362
- /**
363
- * @param {string} address
364
- * @returns {Promise<bigint>}
365
- */
366
- async getBalance(address) {
367
- const bal = await this._perform("eth_getBalance", [address, "latest"]);
368
- return _hexToBigInt(bal);
369
- }
370
-
371
- /**
372
- * @param {string} address
373
- * @param {string=} blockTag
374
- * @returns {Promise<number>}
375
- */
376
- async getTransactionCount(address, blockTag) {
377
- const tag = blockTag || "latest";
378
- const nonce = await this._perform("eth_getTransactionCount", [address, tag]);
379
- return _hexToNumber(nonce);
380
- }
381
-
382
- /**
383
- * Broadcasts a signed transaction.
384
- * @param {TransactionRequest|string} tx
385
- * @param {{ expectedHash?: string }=} opts Optional. When `expectedHash` is set,
386
- * the hash returned by the node (and the fetched-back transaction's hash) must
387
- * match it, otherwise an error is thrown (do not trust the RPC node to
388
- * broadcast the exact transaction that was signed).
389
- * @returns {Promise<TransactionResponse>}
390
- */
391
- async sendTransaction(tx, opts) {
392
- // For QuantumCoin.js, tx is expected to be a signed raw transaction hex string.
393
- const raw = typeof tx === "string" ? tx : tx?.raw;
394
- if (typeof raw !== "string") throw makeError("sendTransaction requires a signed raw transaction string", "INVALID_ARGUMENT", { tx });
395
- const expectedHash =
396
- opts && typeof opts.expectedHash === "string" && opts.expectedHash.length > 0 ? opts.expectedHash.toLowerCase() : null;
397
-
398
- const hash = await this._perform("eth_sendRawTransaction", [raw]);
399
-
400
- // The node returns the hash it claims to have accepted. If we know the
401
- // hash of the transaction we signed, reject any mismatch — a malicious or
402
- // buggy node must not be able to silently substitute a different transaction.
403
- if (expectedHash != null && typeof hash === "string" && hash.length > 0) {
404
- if (hash.toLowerCase() !== expectedHash) {
405
- throw makeError("RPC node returned a transaction hash that does not match the signed transaction", "UNKNOWN_ERROR", {
406
- operation: "sendTransaction",
407
- expected: expectedHash,
408
- got: hash,
409
- });
410
- }
411
- }
412
-
413
- // Fetch back transaction (best-effort)
414
- const result = await this.getTransaction(hash);
415
-
416
- // Verify the fetched-back transaction's hash too, so a node cannot return
417
- // a fabricated transaction object under the correct hash lookup.
418
- if (result && expectedHash != null && typeof result.hash === "string" && result.hash.toLowerCase() !== expectedHash) {
419
- throw makeError("RPC node returned a transaction whose hash does not match the signed transaction", "UNKNOWN_ERROR", {
420
- operation: "sendTransaction",
421
- expected: expectedHash,
422
- got: result.hash,
423
- });
424
- }
425
-
426
- return result || new TransactionResponse({ hash }, this);
427
- }
428
-
429
- /**
430
- * Broadcast a signed raw transaction.
431
- * Alias of sendTransaction(rawTx) for clarity when doing offline signing flows.
432
- *
433
- * @param {string} rawTx
434
- * @returns {Promise<TransactionResponse>}
435
- */
436
- async sendRawTransaction(rawTx) {
437
- assertArgument(typeof rawTx === "string", "invalid rawTx", "rawTx", rawTx);
438
- return this.sendTransaction(rawTx);
439
- }
440
-
441
- /**
442
- * Perform a call (read-only) and return hex data.
443
- * @param {TransactionRequest} tx
444
- * @param {string=} blockTag
445
- * @returns {Promise<string>}
446
- */
447
- async call(tx, blockTag) {
448
- const tag = blockTag || "latest";
449
- return this._perform("eth_call", [tx, tag]);
450
- }
451
-
452
- /**
453
- * Estimate gas for a call/transaction.
454
- * @param {TransactionRequest} tx
455
- * @returns {Promise<bigint>}
456
- */
457
- async estimateGas(tx) {
458
- const gas = await this._perform("eth_estimateGas", [tx]);
459
- return _hexToBigInt(gas);
460
- }
461
-
462
- /**
463
- * @param {string} address
464
- * @param {string=} blockTag
465
- * @returns {Promise<string>}
466
- */
467
- async getCode(address, blockTag) {
468
- const tag = blockTag || "latest";
469
- return this._perform("eth_getCode", [address, tag]);
470
- }
471
-
472
- /**
473
- * @param {string} address
474
- * @param {bigint} position
475
- * @param {string=} blockTag
476
- * @returns {Promise<string>}
477
- */
478
- async getStorageAt(address, position, blockTag) {
479
- const tag = blockTag || "latest";
480
- return this._perform("eth_getStorageAt", [address, "0x" + position.toString(16), tag]);
481
- }
482
-
483
- /**
484
- * @param {Filter} filter
485
- * @returns {Promise<Log[]>}
486
- */
487
- async getLogs(filter) {
488
- const fromBlock = _blockTagToHex(filter.fromBlock);
489
- const toBlock = _blockTagToHex(filter.toBlock);
490
- const normalized = { ...filter };
491
- if (fromBlock !== undefined) normalized.fromBlock = fromBlock;
492
- if (toBlock !== undefined) normalized.toBlock = toBlock;
493
- const logs = await this._perform("eth_getLogs", [normalized]);
494
- const mapped = (logs || []).map((l) => new Log(l, this));
495
-
496
- // A malicious node could return logs emitted by contracts other than the
497
- // one(s) requested. When the filter constrains the address, drop any log whose
498
- // address is not in that set so foreign-contract events cannot be injected.
499
- const allowed = _normalizeAddressFilter(filter.address);
500
- // A malicious node could return logs for a different event (different
501
- // topic0) or from foreign contracts. Drop anything that does not match the
502
- // requested address and topic constraints.
503
- const hasTopicFilter = Array.isArray(filter.topics) && filter.topics.some((t) => t != null);
504
- if (allowed || hasTopicFilter) {
505
- return mapped.filter((l) => {
506
- if (!l) return false;
507
- if (allowed && !(typeof l.address === "string" && allowed.has(l.address.toLowerCase()))) return false;
508
- if (hasTopicFilter && !_topicsMatch(l.topics, filter.topics)) return false;
509
- return true;
510
- });
511
- }
512
- return mapped;
513
- }
514
- }
515
-
516
- module.exports = {
517
- Provider,
518
- AbstractProvider,
519
- Block,
520
- TransactionResponse,
521
- TransactionReceipt,
522
- Log,
523
- };
524
-