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,614 +0,0 @@
1
- /**
2
- * @fileoverview Additional provider classes (compatibility stubs).
3
- *
4
- * These are included to match the API shape described in SPEC.md. Only
5
- * JsonRpcProvider is fully implemented for network operations.
6
- */
7
-
8
- const { AbstractProvider } = require("./provider");
9
- const { JsonRpcProvider } = require("./json-rpc-provider");
10
- const { makeError } = require("../errors");
11
- const net = require("node:net");
12
- const { JsonRpcSigner } = require("../wallet/wallet");
13
- const { normalizeHex, isHexString } = require("../internal/hex");
14
-
15
- const MAX_RESPONSE_SIZE = 16 * 1024 * 1024;
16
- const MAX_IPC_BUFFER = 16 * 1024 * 1024;
17
-
18
- function _bigIntReplacer(_key, value) {
19
- return typeof value === "bigint" ? "0x" + value.toString(16) : value;
20
- }
21
-
22
- /**
23
- * Extract the first complete JSON object from a stream buffer.
24
- *
25
- * geth's IPC JSON-RPC typically uses newline-delimited JSON, but we also support
26
- * non-newline framing by scanning for balanced braces and respecting strings.
27
- *
28
- * @param {string} buffer
29
- * @returns {{ json: string, rest: string } | null}
30
- */
31
- function _extractFirstJsonObject(buffer) {
32
- const start = buffer.indexOf("{");
33
- if (start === -1) return null;
34
-
35
- let depth = 0;
36
- let inString = false;
37
- let escape = false;
38
-
39
- for (let i = start; i < buffer.length; i++) {
40
- const ch = buffer[i];
41
-
42
- if (inString) {
43
- if (escape) {
44
- escape = false;
45
- continue;
46
- }
47
- if (ch === "\\") {
48
- escape = true;
49
- continue;
50
- }
51
- if (ch === '"') {
52
- inString = false;
53
- }
54
- continue;
55
- }
56
-
57
- if (ch === '"') {
58
- inString = true;
59
- continue;
60
- }
61
-
62
- if (ch === "{") depth++;
63
- if (ch === "}") depth--;
64
-
65
- if (depth === 0) {
66
- const json = buffer.slice(start, i + 1);
67
- const rest = buffer.slice(i + 1);
68
- return { json, rest };
69
- }
70
- }
71
-
72
- return null;
73
- }
74
-
75
- class WebSocketProvider extends AbstractProvider {
76
- /**
77
- * Create a WebSocket JSON-RPC provider.
78
- *
79
- * This uses the built-in global `WebSocket` available in recent Node.js
80
- * versions (via undici). No additional npm dependencies are required.
81
- *
82
- * @param {string} url WebSocket endpoint (e.g. ws://127.0.0.1:8546)
83
- * @param {number=} chainId Optional chain id (compat)
84
- */
85
- constructor(url, chainId) {
86
- super();
87
- if (typeof url !== "string" || url.trim().length === 0) {
88
- throw makeError("missing WebSocket url", "INVALID_ARGUMENT", { url });
89
- }
90
- this.url = url.trim();
91
- this.chainId = chainId == null ? 123123 : chainId;
92
- this._wsRpcId = 1;
93
-
94
- /** @type {any|null} */
95
- this._ws = null;
96
- /** @type {Promise<void>|null} */
97
- this._wsReady = null;
98
- /** @type {Map<number, { resolve: Function, reject: Function, timer: any }>} */
99
- this._pending = new Map();
100
- }
101
-
102
- /**
103
- * Close the underlying WebSocket connection and reject any pending requests.
104
- * This is important for tests so the Node.js event loop can exit cleanly.
105
- */
106
- destroy() {
107
- try {
108
- if (this._ws && typeof this._ws.close === "function") this._ws.close();
109
- } catch {
110
- // ignore
111
- }
112
- this._ws = null;
113
- this._wsReady = null;
114
- this._rejectAllPending(makeError("WebSocket closed", "UNKNOWN_ERROR", { url: this.url }));
115
- }
116
-
117
- _rejectAllPending(err) {
118
- for (const [id, p] of this._pending.entries()) {
119
- try {
120
- clearTimeout(p.timer);
121
- p.reject(err);
122
- } catch {
123
- // ignore
124
- }
125
- this._pending.delete(id);
126
- }
127
- }
128
-
129
- async _connect() {
130
- if (this._ws && this._ws.readyState === 1) return;
131
- if (this._wsReady) return this._wsReady;
132
-
133
- const WS = globalThis.WebSocket;
134
- if (typeof WS !== "function") {
135
- throw makeError("WebSocket not available in this Node.js runtime", "NOT_IMPLEMENTED", {});
136
- }
137
-
138
- this._wsReady = new Promise((resolve, reject) => {
139
- const ws = new WS(this.url);
140
- this._ws = ws;
141
-
142
- const connectTimer = setTimeout(() => {
143
- try {
144
- ws.close();
145
- } catch {
146
- // ignore
147
- }
148
- reject(makeError("WebSocket connect timeout", "UNKNOWN_ERROR", { url: this.url }));
149
- }, 10_000);
150
-
151
- const onOpen = () => {
152
- clearTimeout(connectTimer);
153
- resolve();
154
- };
155
-
156
- const onError = (event) => {
157
- clearTimeout(connectTimer);
158
- reject(
159
- makeError("WebSocket error", "UNKNOWN_ERROR", {
160
- url: this.url,
161
- error: event && event.message ? event.message : String(event),
162
- }),
163
- );
164
- };
165
-
166
- const onClose = () => {
167
- clearTimeout(connectTimer);
168
- this._ws = null;
169
- this._wsReady = null;
170
- this._rejectAllPending(makeError("WebSocket closed", "UNKNOWN_ERROR", { url: this.url }));
171
- };
172
-
173
- const onMessage = (event) => {
174
- const data = event && event.data != null ? event.data : "";
175
- const text = typeof data === "string" ? data : data.toString();
176
- if (text.length > MAX_RESPONSE_SIZE) return;
177
- let msg;
178
- try {
179
- msg = JSON.parse(text);
180
- } catch {
181
- return;
182
- }
183
- if (!msg || typeof msg !== "object") return;
184
- if (typeof msg.id !== "number") return;
185
-
186
- const pending = this._pending.get(msg.id);
187
- if (!pending) return;
188
- this._pending.delete(msg.id);
189
- clearTimeout(pending.timer);
190
-
191
- if (msg.error) {
192
- pending.reject(makeError("JSON-RPC error", "UNKNOWN_ERROR", { error: msg.error }));
193
- return;
194
- }
195
- pending.resolve(msg.result);
196
- };
197
-
198
- // Prefer addEventListener API, but fall back to on* properties if needed.
199
- if (typeof ws.addEventListener === "function") {
200
- ws.addEventListener("open", onOpen);
201
- ws.addEventListener("error", onError);
202
- ws.addEventListener("close", onClose);
203
- ws.addEventListener("message", onMessage);
204
- } else {
205
- ws.onopen = onOpen;
206
- ws.onerror = onError;
207
- ws.onclose = onClose;
208
- ws.onmessage = onMessage;
209
- }
210
- }).finally(() => {
211
- // If connection failed, allow retries.
212
- if (!this._ws || this._ws.readyState !== 1) {
213
- this._ws = null;
214
- this._wsReady = null;
215
- }
216
- });
217
-
218
- return this._wsReady;
219
- }
220
-
221
- /**
222
- * @param {string} method
223
- * @param {any[]=} params
224
- * @returns {Promise<any>}
225
- */
226
- async _perform(method, params) {
227
- await this._connect();
228
- const ws = this._ws;
229
- if (!ws || ws.readyState !== 1) {
230
- throw makeError("WebSocket not connected", "UNKNOWN_ERROR", { url: this.url, method });
231
- }
232
-
233
- const id = this._wsRpcId++;
234
- const body = JSON.stringify({ jsonrpc: "2.0", id, method, params: params || [] }, _bigIntReplacer);
235
-
236
- return new Promise((resolve, reject) => {
237
- const timer = setTimeout(() => {
238
- this._pending.delete(id);
239
- reject(makeError("WebSocket JSON-RPC timeout", "UNKNOWN_ERROR", { url: this.url, method }));
240
- }, 30_000);
241
-
242
- this._pending.set(id, { resolve, reject, timer });
243
-
244
- try {
245
- ws.send(body);
246
- } catch (e) {
247
- clearTimeout(timer);
248
- this._pending.delete(id);
249
- reject(
250
- makeError("WebSocket send failed", "UNKNOWN_ERROR", {
251
- url: this.url,
252
- method,
253
- error: e && e.message ? e.message : String(e),
254
- }),
255
- );
256
- }
257
- });
258
- }
259
- }
260
-
261
- class IpcSocketProvider extends AbstractProvider {
262
- /**
263
- * Create an IPC provider.
264
- *
265
- * On Windows, use a named pipe path like: `\\\\.\\pipe\\geth.ipc`
266
- * On Unix, use a domain socket path like: `/path/to/geth.ipc`
267
- *
268
- * @param {string} path IPC socket path
269
- */
270
- constructor(path) {
271
- super();
272
- if (typeof path !== "string" || path.length === 0) {
273
- throw makeError("missing IPC path", "INVALID_ARGUMENT", { path });
274
- }
275
- this.path = path;
276
- this._ipcRpcId = 1;
277
- }
278
-
279
- /**
280
- * @param {string} method
281
- * @param {any[]=} params
282
- * @returns {Promise<any>}
283
- */
284
- async _perform(method, params) {
285
- const id = this._ipcRpcId++;
286
- const body =
287
- JSON.stringify({
288
- jsonrpc: "2.0",
289
- id,
290
- method,
291
- params: params || [],
292
- }, _bigIntReplacer) + "\n";
293
-
294
- return new Promise((resolve, reject) => {
295
- /** @type {boolean} */
296
- let done = false;
297
- /** @type {string} */
298
- let buffer = "";
299
-
300
- const socket = net.createConnection(this.path);
301
- socket.setEncoding("utf8");
302
- socket.setTimeout(30_000);
303
-
304
- function finish(err, value) {
305
- if (done) return;
306
- done = true;
307
- try {
308
- socket.destroy();
309
- } catch {
310
- // ignore
311
- }
312
- if (err) reject(err);
313
- else resolve(value);
314
- }
315
-
316
- socket.on("connect", () => {
317
- try {
318
- socket.write(body);
319
- } catch (e) {
320
- finish(
321
- makeError("IPC write failed", "UNKNOWN_ERROR", {
322
- method,
323
- path: this.path,
324
- error: e && e.message ? e.message : String(e),
325
- }),
326
- );
327
- }
328
- });
329
-
330
- socket.on("timeout", () => {
331
- finish(makeError("IPC request timeout", "UNKNOWN_ERROR", { method, path: this.path }));
332
- });
333
-
334
- socket.on("error", (e) => {
335
- finish(
336
- makeError("IPC socket error", "UNKNOWN_ERROR", {
337
- method,
338
- path: this.path,
339
- error: e && e.message ? e.message : String(e),
340
- }),
341
- );
342
- });
343
-
344
- socket.on("data", (chunk) => {
345
- buffer += String(chunk);
346
-
347
- if (buffer.length > MAX_IPC_BUFFER) {
348
- finish(makeError("IPC response too large", "UNKNOWN_ERROR", {
349
- method, path: this.path, size: buffer.length, limit: MAX_IPC_BUFFER,
350
- }));
351
- return;
352
- }
353
-
354
- // Fast path: newline-delimited JSON responses.
355
- while (buffer.includes("\n")) {
356
- const idx = buffer.indexOf("\n");
357
- const line = buffer.slice(0, idx).trim();
358
- buffer = buffer.slice(idx + 1);
359
- if (!line) continue;
360
- try {
361
- const json = JSON.parse(line);
362
- if (json && json.id === id) {
363
- if (json.error) {
364
- finish(makeError("JSON-RPC error", "UNKNOWN_ERROR", { method, error: json.error }));
365
- return;
366
- }
367
- finish(null, json.result);
368
- return;
369
- }
370
- } catch {
371
- // If parsing fails, fall through to brace-balanced extraction on the accumulated buffer.
372
- buffer = line + "\n" + buffer;
373
- break;
374
- }
375
- }
376
-
377
- // Robust path: find a complete JSON object by balanced braces.
378
- while (true) {
379
- const extracted = _extractFirstJsonObject(buffer);
380
- if (!extracted) return;
381
- buffer = extracted.rest;
382
- try {
383
- const json = JSON.parse(extracted.json);
384
- if (json && json.id === id) {
385
- if (json.error) {
386
- finish(makeError("JSON-RPC error", "UNKNOWN_ERROR", { method, error: json.error }));
387
- return;
388
- }
389
- finish(null, json.result);
390
- return;
391
- }
392
- } catch {
393
- // ignore malformed object and continue scanning remainder
394
- }
395
- }
396
- });
397
-
398
- socket.on("end", () => {
399
- if (!done) finish(makeError("IPC connection ended before response", "UNKNOWN_ERROR", { method, path: this.path }));
400
- });
401
- });
402
- }
403
- }
404
-
405
- class BrowserProvider extends AbstractProvider {
406
- /**
407
- * Create a BrowserProvider from an EIP-1193 provider (e.g. MetaMask).
408
- *
409
- * This is a lightweight implementation that focuses on the core behaviors:
410
- * - `send(method, params)` dispatches EIP-1193 requests
411
- * - `getSigner()` resolves the connected account
412
- * - emits ethers-like `debug` events for request/response tracking
413
- *
414
- * @param {{ request: Function }} eip1193Provider
415
- * @param {any=} network Unused (compat)
416
- * @param {{ providerInfo?: any }=} options
417
- */
418
- constructor(eip1193Provider, network, options) {
419
- super();
420
- void network;
421
- this.provider = eip1193Provider;
422
- this.providerInfo = options && options.providerInfo ? options.providerInfo : null;
423
-
424
- if (!this.provider || typeof this.provider.request !== "function") {
425
- throw makeError("invalid EIP-1193 provider (missing request)", "INVALID_ARGUMENT", { provider: this.provider });
426
- }
427
- }
428
-
429
- /**
430
- * Send an EIP-1193 JSON-RPC request.
431
- * @param {string} method
432
- * @param {any[]|Record<string, any>=} params
433
- * @returns {Promise<any>}
434
- */
435
- async send(method, params) {
436
- const payload = { method, params: params == null ? [] : params };
437
- this.emit("debug", { action: "sendEip1193Payload", payload });
438
-
439
- try {
440
- const result = await this.provider.request(payload);
441
- this.emit("debug", { action: "receiveEip1193Result", result });
442
- return result;
443
- } catch (e) {
444
- const err = this.getRpcError(payload, e);
445
- this.emit("debug", { action: "receiveEip1193Error", error: err });
446
- throw err;
447
- }
448
- }
449
-
450
- /**
451
- * Map an EIP-1193 error into a normalized Error.
452
- * @param {{ method: string, params?: any }} payload
453
- * @param {any} error
454
- * @returns {Error}
455
- */
456
- getRpcError(payload, error) {
457
- if (error instanceof Error) return error;
458
- return makeError("EIP-1193 error", "UNKNOWN_ERROR", { payload, error });
459
- }
460
-
461
- /**
462
- * Ethers compatibility: internal send for single or batched payloads.
463
- * @param {any|any[]} payload
464
- * @returns {Promise<any>}
465
- */
466
- async _send(payload) {
467
- if (Array.isArray(payload)) {
468
- const out = [];
469
- for (const p of payload) {
470
- // eslint-disable-next-line no-await-in-loop
471
- out.push(await this.send(p.method, p.params));
472
- }
473
- return out;
474
- }
475
- return this.send(payload.method, payload.params);
476
- }
477
-
478
- /**
479
- * @param {string} method
480
- * @param {any[]=} params
481
- * @returns {Promise<any>}
482
- */
483
- async _perform(method, params) {
484
- return this.send(method, params || []);
485
- }
486
-
487
- /**
488
- * Returns a signer for the specified account index or address.
489
- * @param {number|string=} address
490
- * @returns {Promise<JsonRpcSigner>}
491
- */
492
- async getSigner(address) {
493
- const accounts = await this.send("eth_accounts", []);
494
- if (!Array.isArray(accounts) || accounts.length === 0) {
495
- throw makeError("no accounts available from EIP-1193 provider", "UNKNOWN_ERROR", {});
496
- }
497
-
498
- if (address == null) {
499
- return new JsonRpcSigner(this, accounts[0]);
500
- }
501
-
502
- if (typeof address === "number") {
503
- const a = accounts[address];
504
- if (!a) throw makeError("account index out of range", "INVALID_ARGUMENT", { address });
505
- return new JsonRpcSigner(this, a);
506
- }
507
-
508
- if (typeof address === "string") {
509
- const found = accounts.find((a) => typeof a === "string" && a.toLowerCase() === address.toLowerCase());
510
- if (!found) throw makeError("account not found", "INVALID_ARGUMENT", { address });
511
- return new JsonRpcSigner(this, found);
512
- }
513
-
514
- throw makeError("invalid signer address/index", "INVALID_ARGUMENT", { address });
515
- }
516
-
517
- /**
518
- * Resolve whether this provider manages the address/index.
519
- * @param {number|string} address
520
- * @returns {Promise<boolean>}
521
- */
522
- async hasSigner(address) {
523
- const accounts = await this.send("eth_accounts", []);
524
- if (!Array.isArray(accounts)) return false;
525
- if (typeof address === "number") return address >= 0 && address < accounts.length;
526
- if (typeof address === "string") return accounts.some((a) => typeof a === "string" && a.toLowerCase() === address.toLowerCase());
527
- return false;
528
- }
529
- }
530
-
531
- /**
532
- * FallbackProvider - uses the first provider in the list.
533
- */
534
- class FallbackProvider extends AbstractProvider {
535
- /**
536
- * @param {AbstractProvider[]|AbstractProvider} providers
537
- */
538
- constructor(providers) {
539
- super();
540
- this.providers = Array.isArray(providers) ? providers : [providers];
541
- if (!this.providers.length) throw makeError("no providers provided", "INVALID_ARGUMENT", {});
542
- }
543
-
544
- async _perform(method, params) {
545
- // Simple strategy: try providers in order.
546
- let lastErr;
547
- for (const p of this.providers) {
548
- try {
549
- // eslint-disable-next-line no-await-in-loop
550
- return await p._perform(method, params);
551
- } catch (e) {
552
- lastErr = e;
553
- }
554
- }
555
- throw lastErr || makeError("all providers failed", "UNKNOWN_ERROR", { method });
556
- }
557
- }
558
-
559
- /**
560
- * FilterByBlockHash placeholder.
561
- */
562
- class FilterByBlockHash {
563
- constructor(blockHash, address, topics) {
564
- if (typeof blockHash !== "string" || !isHexString(blockHash, 32)) {
565
- throw makeError("invalid blockHash", "INVALID_ARGUMENT", { blockHash });
566
- }
567
- this.blockHash = normalizeHex(blockHash);
568
- if (address != null) this.address = address;
569
- if (topics != null) this.topics = topics;
570
- }
571
-
572
- toJSON() {
573
- // Ensure JSON serialization includes only the filter fields.
574
- return {
575
- blockHash: this.blockHash,
576
- address: this.address,
577
- topics: this.topics,
578
- };
579
- }
580
- }
581
-
582
- /**
583
- * Create a provider from an endpoint string. Detects connection type by scheme/path:
584
- * - http:// or https:// → JsonRpcProvider
585
- * - ws:// or wss:// → WebSocketProvider
586
- * - otherwise (e.g. \\\\.\\pipe\\geth.ipc or /path/to/geth.ipc) → IpcSocketProvider
587
- *
588
- * @param {string=} endpoint - RPC URL (http/https), WebSocket URL (ws/wss), or IPC path. If omitted or empty, uses default from Config (HTTP).
589
- * @param {number=} chainId - Chain ID (default 123123). Used for HTTP and WebSocket; ignored for IPC.
590
- * @returns {AbstractProvider}
591
- */
592
- function getProvider(endpoint, chainId) {
593
- const url = typeof endpoint === "string" ? endpoint.trim() : "";
594
- const lower = url.toLowerCase();
595
- if (!url || lower.startsWith("http://") || lower.startsWith("https://")) {
596
- return new JsonRpcProvider(url || undefined, chainId);
597
- }
598
- if (lower.startsWith("ws://") || lower.startsWith("wss://")) {
599
- return new WebSocketProvider(url, chainId);
600
- }
601
- // IPC path (e.g. \\.\pipe\geth.ipc on Windows or /path/to/geth.ipc on Unix)
602
- if (!url) throw makeError("missing endpoint", "INVALID_ARGUMENT", { endpoint });
603
- return new IpcSocketProvider(url);
604
- }
605
-
606
- module.exports = {
607
- WebSocketProvider,
608
- IpcSocketProvider,
609
- BrowserProvider,
610
- FallbackProvider,
611
- FilterByBlockHash,
612
- getProvider,
613
- };
614
-
@@ -1,17 +0,0 @@
1
- declare const _exports: {
2
- getProvider(endpoint?: string | undefined, chainId?: number | undefined): import("./provider").AbstractProvider;
3
- WebSocketProvider: typeof import("./extra-providers").WebSocketProvider;
4
- IpcSocketProvider: typeof import("./extra-providers").IpcSocketProvider;
5
- BrowserProvider: typeof import("./extra-providers").BrowserProvider;
6
- FallbackProvider: typeof import("./extra-providers").FallbackProvider;
7
- FilterByBlockHash: typeof import("./extra-providers").FilterByBlockHash;
8
- JsonRpcProvider: typeof import("./json-rpc-provider").JsonRpcProvider;
9
- JsonRpcApiProvider: typeof import("./json-rpc-provider").JsonRpcApiProvider;
10
- Provider: typeof import("./provider").Provider;
11
- AbstractProvider: typeof import("./provider").AbstractProvider;
12
- Block: typeof import("./provider").Block;
13
- TransactionResponse: typeof import("./provider").TransactionResponse;
14
- TransactionReceipt: typeof import("./provider").TransactionReceipt;
15
- Log: typeof import("./provider").Log;
16
- };
17
- export = _exports;
@@ -1,10 +0,0 @@
1
- /**
2
- * @fileoverview Provider exports.
3
- */
4
-
5
- module.exports = {
6
- ...require("./provider"),
7
- ...require("./json-rpc-provider"),
8
- ...require("./extra-providers"),
9
- };
10
-
@@ -1,12 +0,0 @@
1
- export class JsonRpcProvider extends AbstractProvider {
2
- /**
3
- * @param {string=} url RPC endpoint (defaults to Config.rpcEndpoint or https://public.rpc.quantumcoinapi.com)
4
- * @param {number=} chainId Chain ID (defaults to 123123)
5
- */
6
- constructor(url?: string | undefined, chainId?: number | undefined);
7
- url: string;
8
- chainId: number;
9
- }
10
- export class JsonRpcApiProvider extends JsonRpcProvider {
11
- }
12
- import { AbstractProvider } from "./provider";