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,28 +0,0 @@
1
- export class ContractFactory {
2
- /**
3
- * @param {any[]|Interface} abi
4
- * @param {string} bytecode
5
- * @param {any} signer
6
- */
7
- constructor(abi: any[] | Interface, bytecode: string, signer: any);
8
- abi: any;
9
- interface: Interface;
10
- bytecode: string;
11
- signer: any;
12
- /**
13
- * Compute deploy transaction request.
14
- * @param {...any} args
15
- * @returns {import("../providers/provider").TransactionRequest}
16
- */
17
- getDeployTransaction(...args: any[]): import("../providers/provider").TransactionRequest;
18
- /**
19
- * Deploy contract.
20
- * @param {...any} args
21
- * @returns {Promise<Contract>}
22
- */
23
- deploy(...args: any[]): Promise<Contract>;
24
- attach(address: any): Contract;
25
- connect(signer: any): ContractFactory;
26
- }
27
- import { Interface } from "../abi/interface";
28
- import { Contract } from "./contract";
@@ -1,111 +0,0 @@
1
- /**
2
- * @fileoverview ContractFactory implementation.
3
- */
4
-
5
- const qcsdk = require("quantum-coin-js-sdk");
6
- const { Interface } = require("../abi/interface");
7
- const jsAbi = require("../abi/js-abi-coder");
8
- const { Contract } = require("./contract");
9
- const { makeError, assertArgument } = require("../errors");
10
- const { normalizeHex, strip0x, bytesToHex } = require("../internal/hex");
11
- const { getCreateAddress } = require("../utils/address");
12
-
13
- function _requireInitialized() {
14
- // eslint-disable-next-line global-require
15
- const { isInitialized, getInitializationPromise } = require("../../config");
16
- if (isInitialized()) return;
17
- if (getInitializationPromise() != null) {
18
- throw makeError(
19
- "QuantumCoin SDK is still initializing. Await the Initialize() promise before using SDK methods.",
20
- "UNKNOWN_ERROR",
21
- { operation: "requireInitialized" },
22
- );
23
- }
24
- throw makeError("QuantumCoin SDK not initialized. Call Initialize() first.", "UNKNOWN_ERROR", { operation: "contract-factory" });
25
- }
26
-
27
- class ContractFactory {
28
- /**
29
- * @param {any[]|Interface} abi
30
- * @param {string} bytecode
31
- * @param {any} signer
32
- */
33
- constructor(abi, bytecode, signer) {
34
- _requireInitialized();
35
- this.abi = abi instanceof Interface ? JSON.parse(abi.formatJson()) : abi;
36
- this.interface = abi instanceof Interface ? abi : new Interface(abi);
37
- this.bytecode = normalizeHex(bytecode);
38
- this.signer = signer;
39
- }
40
-
41
- /**
42
- * Compute deploy transaction request.
43
- * @param {...any} args
44
- * @returns {import("../providers/provider").TransactionRequest}
45
- */
46
- getDeployTransaction(...args) {
47
- _requireInitialized();
48
- const ctor = this.interface.getConstructor();
49
- const ctorInputs = ctor ? ctor.inputs : [];
50
-
51
- // If the constructor includes tuples/structs, use the JS ABI encoder fallback.
52
- if (jsAbi.hasTuple(ctorInputs)) {
53
- const enc = jsAbi.encodeTupleLike(ctorInputs, args);
54
- const data = normalizeHex(this.bytecode + strip0x(bytesToHex(enc)));
55
- return { to: null, data, value: 0n };
56
- }
57
-
58
- const normArgs = this.interface._qcsdkNormalizeValues(ctorInputs, args);
59
- const res = qcsdk.packCreateContractData(this.interface._qcsdkFormatJson(), this.bytecode, ...normArgs);
60
- if (!res || typeof res.error !== "string") throw makeError("packCreateContractData failed", "UNKNOWN_ERROR", {});
61
- if (res.error) throw makeError(res.error, "UNKNOWN_ERROR", { operation: "packCreateContractData" });
62
- return { to: null, data: normalizeHex(res.result), value: 0n };
63
- }
64
-
65
- /**
66
- * Deploy contract.
67
- * @param {...any} args
68
- * @returns {Promise<Contract>}
69
- */
70
- async deploy(...args) {
71
- if (!this.signer) throw makeError("missing signer", "UNKNOWN_ERROR", { operation: "deploy" });
72
- const tx = this.getDeployTransaction(...args);
73
-
74
- // Compute deterministic address from (from, nonce)
75
- const from =
76
- typeof this.signer.getAddress === "function"
77
- ? await this.signer.getAddress()
78
- : this.signer.address;
79
- if (typeof from !== "string") throw makeError("unable to resolve deployer address", "UNKNOWN_ERROR", {});
80
-
81
- const provider = this.signer.provider || null;
82
- if (!provider || typeof provider.getTransactionCount !== "function") {
83
- throw makeError("missing provider for deploy", "UNKNOWN_ERROR", { operation: "deploy" });
84
- }
85
-
86
- // Prefer pending nonce to avoid collisions with in-flight transactions.
87
- let nonce;
88
- try {
89
- nonce = await provider.getTransactionCount(from, "pending");
90
- } catch {
91
- nonce = await provider.getTransactionCount(from, "latest");
92
- }
93
- const address = getCreateAddress({ from, nonce });
94
-
95
- const resp = await this.signer.sendTransaction({ ...tx, nonce });
96
- const contract = new Contract(address, this.interface, this.signer, this.bytecode);
97
- contract._deployTx = resp;
98
- return contract;
99
- }
100
-
101
- attach(address) {
102
- return new Contract(address, this.interface, this.signer, this.bytecode);
103
- }
104
-
105
- connect(signer) {
106
- return new ContractFactory(this.interface, this.bytecode, signer);
107
- }
108
- }
109
-
110
- module.exports = { ContractFactory };
111
-
@@ -1,113 +0,0 @@
1
- /**
2
- * BaseContract placeholder (ethers-like).
3
- */
4
- export class BaseContract {
5
- }
6
- export class Contract extends BaseContract {
7
- static from(target: any, abi: any, runner: any): Contract;
8
- /**
9
- * @param {string} address
10
- * @param {any[]|Interface} abi
11
- * @param {any=} providerOrSigner
12
- * @param {string=} bytecode
13
- */
14
- constructor(address: string, abi: any[] | Interface, providerOrSigner?: any | undefined, bytecode?: string | undefined);
15
- address: string;
16
- target: string;
17
- bytecode: string;
18
- interface: Interface;
19
- provider: any;
20
- signer: any;
21
- runner: any;
22
- _listeners: Map<any, any>;
23
- populateTransaction: {};
24
- getAddress(): string;
25
- /**
26
- * Invoke a contract function, dispatching to call() or send().
27
- * @param {string} methodName
28
- * @param {any[]} args
29
- * @returns {Promise<any>}
30
- */
31
- _invoke(methodName: string, args: any[]): Promise<any>;
32
- /**
33
- * Build an unsigned transaction request for a contract method call.
34
- * @param {string} methodName
35
- * @param {any[]} args
36
- * @returns {Promise<import("../providers/provider").TransactionRequest>}
37
- */
38
- _populate(methodName: string, args: any[]): Promise<import("../providers/provider").TransactionRequest>;
39
- /**
40
- * Perform a read-only call.
41
- * @param {string} methodName
42
- * @param {any[]} args
43
- * @param {import("../providers/provider").TransactionRequest=} overrides
44
- * @returns {Promise<any>}
45
- */
46
- call(methodName: string, args: any[], overrides?: import("../providers/provider").TransactionRequest | undefined): Promise<any>;
47
- /**
48
- * Send a state-changing transaction.
49
- * @param {string} methodName
50
- * @param {any[]} args
51
- * @param {import("../providers/provider").TransactionRequest=} overrides
52
- * @returns {Promise<ContractTransactionResponse>}
53
- */
54
- send(methodName: string, args: any[], overrides?: import("../providers/provider").TransactionRequest | undefined): Promise<ContractTransactionResponse>;
55
- /**
56
- * Query logs for an event.
57
- * @param {any} event
58
- * @param {number|string=} fromBlock
59
- * @param {number|string=} toBlock
60
- * @returns {Promise<EventLog[]>}
61
- */
62
- queryFilter(event: any, fromBlock?: (number | string) | undefined, toBlock?: (number | string) | undefined): Promise<EventLog[]>;
63
- on(event: any, callback: any): this;
64
- once(event: any, callback: any): this;
65
- removeListener(event: any, callback: any): this;
66
- removeAllListeners(event: any): this;
67
- connect(signerOrProvider: any): Contract;
68
- attach(address: any): Contract;
69
- deployTransaction(): any;
70
- getTransactionReceipt(hash: any): Promise<ContractTransactionReceipt>;
71
- waitForDeployment(): Promise<this>;
72
- getDeployedCode(): Promise<any>;
73
- }
74
- /**
75
- * ContractTransactionResponse (aliasing provider TransactionResponse).
76
- */
77
- export class ContractTransactionResponse {
78
- /**
79
- * @param {any} tx
80
- */
81
- constructor(tx: any);
82
- _tx: any;
83
- /**
84
- * Wait for confirmations (delegated to underlying TransactionResponse).
85
- * @param {number=} confirmations
86
- * @param {number=} timeoutMs
87
- * @returns {Promise<any>}
88
- */
89
- wait(confirmations?: number | undefined, timeoutMs?: number | undefined): Promise<any>;
90
- /**
91
- * Return the underlying transaction response object.
92
- * @returns {any}
93
- */
94
- getTransaction(): any;
95
- }
96
- /**
97
- * ContractTransactionReceipt (aliasing provider TransactionReceipt).
98
- */
99
- export class ContractTransactionReceipt {
100
- /**
101
- * @param {any} receipt
102
- */
103
- constructor(receipt: any);
104
- getEvent(eventName: any): any;
105
- getEvents(eventName: any): any;
106
- }
107
- /**
108
- * EventLog placeholder.
109
- */
110
- export class EventLog {
111
- constructor(log: any);
112
- }
113
- import { Interface } from "../abi/interface";
@@ -1,408 +0,0 @@
1
- /**
2
- * @fileoverview Contract implementation (ethers.js v6 compatible shape).
3
- */
4
-
5
- const qcsdk = require("quantum-coin-js-sdk");
6
- const { Interface } = require("../abi/interface");
7
- const { makeError, assertArgument } = require("../errors");
8
- const { getAddress } = require("../utils/address");
9
- const { normalizeHex } = require("../internal/hex");
10
-
11
- function _requireInitialized() {
12
- // eslint-disable-next-line global-require
13
- const { isInitialized, getInitializationPromise } = require("../../config");
14
- if (isInitialized()) return;
15
- if (getInitializationPromise() != null) {
16
- throw makeError(
17
- "QuantumCoin SDK is still initializing. Await the Initialize() promise before using SDK methods.",
18
- "UNKNOWN_ERROR",
19
- { operation: "requireInitialized" },
20
- );
21
- }
22
- throw makeError("QuantumCoin SDK not initialized. Call Initialize() first.", "UNKNOWN_ERROR", { operation: "contract" });
23
- }
24
-
25
- function _isProvider(obj) {
26
- return Boolean(obj && typeof obj === "object" && typeof obj.call === "function" && typeof obj.getBlockNumber === "function");
27
- }
28
-
29
- function _isSigner(obj) {
30
- return Boolean(obj && typeof obj === "object" && typeof obj.signTransaction === "function");
31
- }
32
-
33
- function _isOverridesLike(value) {
34
- if (!value || typeof value !== "object") return false;
35
- if (Array.isArray(value)) return false;
36
- if (value instanceof Uint8Array) return false;
37
- return true;
38
- }
39
-
40
- // Fields a caller is allowed to set via `overrides`. Protected routing /
41
- // payload fields (`to`, `data`, `from`) are intentionally excluded so that a
42
- // caller-supplied overrides object can never redirect the transaction to a
43
- // different contract or replace the encoded calldata. Unknown keys are dropped.
44
- const _ALLOWED_OVERRIDE_KEYS = [
45
- "value",
46
- "gasLimit",
47
- "gasPrice",
48
- "maxFeePerGas",
49
- "maxPriorityFeePerGas",
50
- "nonce",
51
- "chainId",
52
- "remarks",
53
- "signingContext",
54
- ];
55
-
56
- /**
57
- * Return a copy of `overrides` containing only the allow-listed fields.
58
- * Drops `to`, `data`, `from`, and any unknown/prototype keys so the protected
59
- * fields computed by the contract layer always win.
60
- * @param {any} overrides
61
- * @returns {Record<string, any>}
62
- */
63
- function _sanitizeOverrides(overrides) {
64
- const out = {};
65
- if (!_isOverridesLike(overrides)) return out;
66
- for (const key of _ALLOWED_OVERRIDE_KEYS) {
67
- if (Object.prototype.hasOwnProperty.call(overrides, key) && overrides[key] !== undefined) {
68
- out[key] = overrides[key];
69
- }
70
- }
71
- return out;
72
- }
73
-
74
- /**
75
- * BaseContract placeholder (ethers-like).
76
- */
77
- class BaseContract {
78
- constructor() {}
79
- }
80
-
81
- /**
82
- * ContractTransactionResponse (aliasing provider TransactionResponse).
83
- */
84
- class ContractTransactionResponse {
85
- /**
86
- * @param {any} tx
87
- */
88
- constructor(tx) {
89
- this._tx = tx;
90
- // Copy common enumerable fields (hash, from, to, etc.)
91
- Object.assign(this, tx);
92
- }
93
-
94
- /**
95
- * Wait for confirmations (delegated to underlying TransactionResponse).
96
- * @param {number=} confirmations
97
- * @param {number=} timeoutMs
98
- * @returns {Promise<any>}
99
- */
100
- wait(confirmations, timeoutMs) {
101
- if (!this._tx || typeof this._tx.wait !== "function") {
102
- throw makeError("underlying transaction does not support wait()", "UNKNOWN_ERROR", {});
103
- }
104
- return this._tx.wait(confirmations, timeoutMs);
105
- }
106
-
107
- /**
108
- * Return the underlying transaction response object.
109
- * @returns {any}
110
- */
111
- getTransaction() {
112
- return this._tx;
113
- }
114
- }
115
-
116
- /**
117
- * ContractTransactionReceipt (aliasing provider TransactionReceipt).
118
- */
119
- class ContractTransactionReceipt {
120
- /**
121
- * @param {any} receipt
122
- */
123
- constructor(receipt) {
124
- Object.assign(this, receipt);
125
- }
126
-
127
- getEvent(eventName) {
128
- const list = this.getEvents(eventName);
129
- return list.length ? list[0] : null;
130
- }
131
-
132
- getEvents(eventName) {
133
- if (!this.logs) return [];
134
- return this.logs.filter((l) => l && l.eventName === eventName);
135
- }
136
- }
137
-
138
- /**
139
- * EventLog placeholder.
140
- */
141
- class EventLog {
142
- constructor(log) {
143
- Object.assign(this, log);
144
- }
145
- }
146
-
147
- class Contract extends BaseContract {
148
- /**
149
- * @param {string} address
150
- * @param {any[]|Interface} abi
151
- * @param {any=} providerOrSigner
152
- * @param {string=} bytecode
153
- */
154
- constructor(address, abi, providerOrSigner, bytecode) {
155
- super();
156
- _requireInitialized();
157
- this.address = getAddress(address);
158
- this.target = this.address;
159
- this.bytecode = bytecode || null;
160
- this.interface = abi instanceof Interface ? abi : new Interface(abi);
161
-
162
- this.provider = null;
163
- this.signer = null;
164
- this.runner = null;
165
- if (providerOrSigner) {
166
- if (_isProvider(providerOrSigner)) this.provider = providerOrSigner;
167
- if (_isSigner(providerOrSigner)) this.signer = providerOrSigner;
168
- // Ethers' ContractRunner can be a provider or signer
169
- this.runner = providerOrSigner;
170
- if (!this.provider && this.signer && this.signer.provider) this.provider = this.signer.provider;
171
- }
172
-
173
- this._listeners = new Map();
174
-
175
- // ethers-style populateTransaction namespace:
176
- // await contract.populateTransaction.someMethod(arg1, ..., overrides?)
177
- //
178
- // NOTE: This will shadow any ABI function literally named "populateTransaction".
179
- // Such a function can still be invoked via `contract.call("populateTransaction", ...)`
180
- // or `contract.send("populateTransaction", ...)`.
181
- const self = this;
182
- this.populateTransaction = new Proxy(
183
- {},
184
- {
185
- get(_t, prop) {
186
- if (typeof prop !== "string") return undefined;
187
- const fn = self.interface.abi.find((f) => f && f.type === "function" && f.name === prop);
188
- if (!fn) return undefined;
189
- return (...args) => self._populate(prop, args);
190
- },
191
- },
192
- );
193
-
194
- // Proxy to support dynamic method names: contract.someMethod(...)
195
- return new Proxy(this, {
196
- get: (target, prop, receiver) => {
197
- if (typeof prop === "string" && !(prop in target)) {
198
- // Treat unknown properties as function invocations if present in ABI
199
- const fn = target.interface.abi.find((f) => f && f.type === "function" && f.name === prop);
200
- if (fn) {
201
- return (...args) => target._invoke(prop, args);
202
- }
203
- }
204
- return Reflect.get(target, prop, receiver);
205
- },
206
- });
207
- }
208
-
209
- getAddress() {
210
- return this.address;
211
- }
212
-
213
- /**
214
- * Invoke a contract function, dispatching to call() or send().
215
- * @param {string} methodName
216
- * @param {any[]} args
217
- * @returns {Promise<any>}
218
- */
219
- async _invoke(methodName, args) {
220
- const fn = this.interface.abi.find((f) => f && f.type === "function" && f.name === methodName);
221
- if (!fn) throw makeError("function not found", "INVALID_ARGUMENT", { methodName });
222
-
223
- const mut = fn.stateMutability || "";
224
- const isView = mut === "view" || mut === "pure";
225
-
226
- // ethers-style overrides:
227
- // - for nonpayable/payable: last arg may be overrides object
228
- // - for view/pure: last arg may be overrides (call overrides)
229
- const inputCount = Array.isArray(fn.inputs) ? fn.inputs.length : 0;
230
- let overrides = undefined;
231
- let callArgs = Array.isArray(args) ? args : [];
232
-
233
- if (callArgs.length === inputCount + 1 && _isOverridesLike(callArgs[callArgs.length - 1])) {
234
- overrides = callArgs[callArgs.length - 1];
235
- callArgs = callArgs.slice(0, inputCount);
236
- }
237
-
238
- if (isView) {
239
- return this.call(methodName, callArgs, overrides);
240
- }
241
-
242
- return this.send(methodName, callArgs, overrides);
243
- }
244
-
245
- /**
246
- * Build an unsigned transaction request for a contract method call.
247
- * @param {string} methodName
248
- * @param {any[]} args
249
- * @returns {Promise<import("../providers/provider").TransactionRequest>}
250
- */
251
- async _populate(methodName, args) {
252
- const fn = this.interface.abi.find((f) => f && f.type === "function" && f.name === methodName);
253
- if (!fn) throw makeError("function not found", "INVALID_ARGUMENT", { methodName });
254
-
255
- const inputCount = Array.isArray(fn.inputs) ? fn.inputs.length : 0;
256
- let overrides = undefined;
257
- let callArgs = Array.isArray(args) ? args : [];
258
-
259
- if (callArgs.length === inputCount + 1 && _isOverridesLike(callArgs[callArgs.length - 1])) {
260
- overrides = callArgs[callArgs.length - 1];
261
- callArgs = callArgs.slice(0, inputCount);
262
- }
263
-
264
- const data = this.interface.encodeFunctionData(methodName, callArgs);
265
- // Protected fields (to/data) must win over caller-supplied overrides.
266
- return { ..._sanitizeOverrides(overrides), to: this.address, data };
267
- }
268
-
269
- /**
270
- * Perform a read-only call.
271
- * @param {string} methodName
272
- * @param {any[]} args
273
- * @param {import("../providers/provider").TransactionRequest=} overrides
274
- * @returns {Promise<any>}
275
- */
276
- async call(methodName, args, overrides) {
277
- if (!this.provider) throw makeError("missing provider", "UNKNOWN_ERROR", { operation: "call" });
278
- const data = this.interface.encodeFunctionData(methodName, args);
279
- // Protected fields (to/data) must win over caller-supplied overrides.
280
- const tx = { ..._sanitizeOverrides(overrides), to: this.address, data };
281
- const raw = await this.provider.call(tx, "latest");
282
- const decoded = this.interface.decodeFunctionResult(methodName, raw);
283
- return decoded;
284
- }
285
-
286
- /**
287
- * Send a state-changing transaction.
288
- * @param {string} methodName
289
- * @param {any[]} args
290
- * @param {import("../providers/provider").TransactionRequest=} overrides
291
- * @returns {Promise<ContractTransactionResponse>}
292
- */
293
- async send(methodName, args, overrides) {
294
- if (!this.signer) throw makeError("missing signer", "UNKNOWN_ERROR", { operation: "send" });
295
- const data = this.interface.encodeFunctionData(methodName, args);
296
- // Protected fields (to/data) must win over caller-supplied overrides.
297
- const tx = { ..._sanitizeOverrides(overrides), to: this.address, data };
298
- const resp = await this.signer.sendTransaction(tx);
299
- return new ContractTransactionResponse(resp);
300
- }
301
-
302
- /**
303
- * Query logs for an event.
304
- * @param {any} event
305
- * @param {number|string=} fromBlock
306
- * @param {number|string=} toBlock
307
- * @returns {Promise<EventLog[]>}
308
- */
309
- async queryFilter(event, fromBlock, toBlock) {
310
- if (!this.provider) throw makeError("missing provider", "UNKNOWN_ERROR", { operation: "queryFilter" });
311
- const name = typeof event === "string" ? event : event?.name;
312
- assertArgument(typeof name === "string", "invalid event", "event", event);
313
-
314
- // Bind the query to the requested event's topic0 so a malicious node cannot
315
- // return same-address logs for a *different* event. We both constrain the RPC
316
- // filter and verify the returned logs' topic0 client-side.
317
- const topic0 = this.interface.getEventTopic(name);
318
- const filter = { address: this.address, topics: [topic0], fromBlock, toBlock };
319
- const logs = await this.provider.getLogs(filter);
320
- return logs
321
- .filter((l) => {
322
- const t = Array.isArray(l && l.topics) ? l.topics[0] : null;
323
- return typeof t === "string" && normalizeHex(t).toLowerCase() === topic0.toLowerCase();
324
- })
325
- .map((l) => new EventLog(l));
326
- }
327
-
328
- on(event, callback) {
329
- const name = typeof event === "string" ? event : event?.name;
330
- if (!name) throw makeError("invalid event", "INVALID_ARGUMENT", { event });
331
- const list = this._listeners.get(name) || [];
332
- list.push(callback);
333
- this._listeners.set(name, list);
334
- return this;
335
- }
336
-
337
- once(event, callback) {
338
- const wrap = (...args) => {
339
- this.removeListener(event, wrap);
340
- callback(...args);
341
- };
342
- return this.on(event, wrap);
343
- }
344
-
345
- removeListener(event, callback) {
346
- const name = typeof event === "string" ? event : event?.name;
347
- const list = this._listeners.get(name) || [];
348
- this._listeners.set(
349
- name,
350
- list.filter((cb) => cb !== callback),
351
- );
352
- return this;
353
- }
354
-
355
- removeAllListeners(event) {
356
- if (!event) {
357
- this._listeners.clear();
358
- return this;
359
- }
360
- const name = typeof event === "string" ? event : event?.name;
361
- this._listeners.delete(name);
362
- return this;
363
- }
364
-
365
- connect(signerOrProvider) {
366
- return new Contract(this.address, this.interface, signerOrProvider, this.bytecode);
367
- }
368
-
369
- attach(address) {
370
- return new Contract(address, this.interface, this.runner, this.bytecode);
371
- }
372
-
373
- deployTransaction() {
374
- return this._deployTx || null;
375
- }
376
-
377
- async getTransactionReceipt(hash) {
378
- if (!this.provider) return null;
379
- const receipt = await this.provider.getTransactionReceipt(hash);
380
- return receipt ? new ContractTransactionReceipt(receipt) : null;
381
- }
382
-
383
- async waitForDeployment() {
384
- if (!this._deployTx) return this;
385
- await this._deployTx.wait();
386
- return this;
387
- }
388
-
389
- async getDeployedCode() {
390
- if (!this.provider) return null;
391
- return this.provider.getCode(this.address, "latest");
392
- }
393
-
394
- static from(target, abi, runner) {
395
- const address = typeof target === "string" ? target : target?.address || target?.target;
396
- return new Contract(address, abi, runner);
397
- }
398
- }
399
-
400
- module.exports = {
401
- BaseContract,
402
- Contract,
403
- ContractTransactionResponse,
404
- ContractTransactionReceipt,
405
- EventLog,
406
- _sanitizeOverrides,
407
- };
408
-
@@ -1,9 +0,0 @@
1
- declare const _exports: {
2
- ContractFactory: typeof import("./contract-factory").ContractFactory;
3
- BaseContract: typeof import("./contract").BaseContract;
4
- Contract: typeof import("./contract").Contract;
5
- ContractTransactionResponse: typeof import("./contract").ContractTransactionResponse;
6
- ContractTransactionReceipt: typeof import("./contract").ContractTransactionReceipt;
7
- EventLog: typeof import("./contract").EventLog;
8
- };
9
- export = _exports;
@@ -1,9 +0,0 @@
1
- /**
2
- * @fileoverview Contract exports.
3
- */
4
-
5
- module.exports = {
6
- ...require("./contract"),
7
- ...require("./contract-factory"),
8
- };
9
-