quantumcoin 7.0.2 → 7.0.4

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 (155) hide show
  1. package/.github/workflows/publish-npmjs.yaml +22 -22
  2. package/.gitignore +15 -15
  3. package/LICENSE +21 -21
  4. package/README-SDK.md +756 -756
  5. package/README.md +165 -152
  6. package/SPEC.md +3845 -3845
  7. package/config.d.ts +50 -50
  8. package/config.js +115 -115
  9. package/examples/AllSolidityTypes.sol +184 -184
  10. package/examples/SimpleIERC20.sol +74 -74
  11. package/examples/events.js +41 -35
  12. package/examples/events.ts +35 -0
  13. package/examples/example-generator-sdk-js.js +100 -95
  14. package/examples/example-generator-sdk-js.ts +77 -0
  15. package/examples/example-generator-sdk-ts.js +100 -95
  16. package/examples/example-generator-sdk-ts.ts +77 -0
  17. package/examples/example.js +72 -61
  18. package/examples/example.ts +61 -0
  19. package/examples/offline-signing.js +79 -0
  20. package/examples/offline-signing.ts +66 -0
  21. package/examples/package-lock.json +48 -57
  22. package/examples/package.json +32 -16
  23. package/examples/read-operations.js +32 -27
  24. package/examples/read-operations.ts +31 -0
  25. package/examples/sdk-generator-erc20.inline.json +251 -251
  26. package/examples/solidity-types.ts +43 -43
  27. package/examples/wallet-offline.js +35 -29
  28. package/examples/wallet-offline.ts +34 -0
  29. package/generate-sdk.js +1824 -1383
  30. package/index.js +12 -12
  31. package/package.json +95 -75
  32. package/scripts/copy-declarations.js +31 -0
  33. package/scripts/run-all-one-by-one.js +151 -0
  34. package/src/abi/fragments.d.ts +42 -42
  35. package/src/abi/fragments.js +63 -63
  36. package/src/abi/index.d.ts +13 -13
  37. package/src/abi/index.js +9 -9
  38. package/src/abi/interface.d.ts +128 -132
  39. package/src/abi/interface.js +590 -590
  40. package/src/abi/js-abi-coder.d.ts +8 -0
  41. package/src/abi/js-abi-coder.js +474 -474
  42. package/src/constants.d.ts +66 -61
  43. package/src/constants.js +101 -94
  44. package/src/contract/contract-factory.d.ts +28 -28
  45. package/src/contract/contract-factory.js +105 -105
  46. package/src/contract/contract.d.ts +113 -105
  47. package/src/contract/contract.js +354 -312
  48. package/src/contract/index.d.ts +9 -9
  49. package/src/contract/index.js +9 -9
  50. package/src/errors/index.d.ts +92 -92
  51. package/src/errors/index.js +188 -188
  52. package/src/generator/index.d.ts +74 -0
  53. package/src/generator/index.js +1404 -1201
  54. package/src/index.d.ts +125 -127
  55. package/src/index.js +41 -41
  56. package/src/internal/hex.d.ts +61 -61
  57. package/src/internal/hex.js +144 -144
  58. package/src/providers/extra-providers.d.ts +139 -128
  59. package/src/providers/extra-providers.js +600 -575
  60. package/src/providers/index.d.ts +17 -16
  61. package/src/providers/index.js +10 -10
  62. package/src/providers/json-rpc-provider.d.ts +12 -12
  63. package/src/providers/json-rpc-provider.js +79 -79
  64. package/src/providers/provider.d.ts +207 -196
  65. package/src/providers/provider.js +392 -359
  66. package/src/types/index.d.ts +214 -462
  67. package/src/types/index.js +9 -9
  68. package/src/utils/address.d.ts +72 -72
  69. package/src/utils/address.js +181 -182
  70. package/src/utils/encoding.d.ts +120 -120
  71. package/src/utils/encoding.js +306 -306
  72. package/src/utils/hashing.d.ts +82 -76
  73. package/src/utils/hashing.js +313 -298
  74. package/src/utils/index.d.ts +65 -55
  75. package/src/utils/index.js +13 -13
  76. package/src/utils/result.d.ts +57 -57
  77. package/src/utils/result.js +128 -128
  78. package/src/utils/rlp.d.ts +12 -12
  79. package/src/utils/rlp.js +200 -200
  80. package/src/utils/units.d.ts +29 -29
  81. package/src/utils/units.js +107 -107
  82. package/src/wallet/index.d.ts +10 -10
  83. package/src/wallet/index.js +8 -8
  84. package/src/wallet/wallet.d.ts +160 -160
  85. package/src/wallet/wallet.js +483 -489
  86. package/test/e2e/all-solidity-types.dynamic.test.js +207 -200
  87. package/test/e2e/all-solidity-types.dynamic.test.ts +191 -0
  88. package/test/e2e/all-solidity-types.fixtures.js +231 -231
  89. package/test/e2e/all-solidity-types.generated-sdks.e2e.test.js +387 -361
  90. package/test/e2e/all-solidity-types.generated-sdks.e2e.test.ts +350 -0
  91. package/test/e2e/helpers.js +59 -47
  92. package/test/e2e/signing-context-and-fee.e2e.test.js +137 -0
  93. package/test/e2e/signing-context-and-fee.e2e.test.ts +128 -0
  94. package/test/e2e/simple-erc20.generated-sdks.e2e.test.js +168 -144
  95. package/test/e2e/simple-erc20.generated-sdks.e2e.test.ts +141 -0
  96. package/test/e2e/transactional.test.js +245 -191
  97. package/test/e2e/transactional.test.ts +208 -0
  98. package/test/e2e/typed-generator.e2e.test.js +407 -402
  99. package/test/e2e/typed-generator.e2e.test.ts +337 -0
  100. package/test/fixtures/ConstructorParam.sol +23 -23
  101. package/test/fixtures/MultiContracts.sol +37 -37
  102. package/test/fixtures/SimpleStorage.sol +18 -18
  103. package/test/fixtures/StakingContract.abi.json +1 -1
  104. package/test/integration/ipc-provider.test.js +49 -44
  105. package/test/integration/ipc-provider.test.ts +44 -0
  106. package/test/integration/provider.test.js +88 -72
  107. package/test/integration/provider.test.ts +85 -0
  108. package/test/integration/ws-provider.test.js +41 -33
  109. package/test/integration/ws-provider.test.ts +38 -0
  110. package/test/security/malformed-input.test.js +37 -31
  111. package/test/security/malformed-input.test.ts +35 -0
  112. package/test/unit/_encrypted-output.txt +6 -0
  113. package/test/unit/_log-encrypted-jsons.js +45 -0
  114. package/test/unit/_write-keystore-fixture.js +16 -0
  115. package/test/unit/abi-interface.test.js +103 -98
  116. package/test/unit/abi-interface.test.ts +102 -0
  117. package/test/unit/address-wallet.test.js +355 -257
  118. package/test/unit/address-wallet.test.ts +342 -0
  119. package/test/unit/browser-provider.test.js +85 -82
  120. package/test/unit/browser-provider.test.ts +79 -0
  121. package/test/unit/contract.test.js +85 -82
  122. package/test/unit/contract.test.ts +83 -0
  123. package/test/unit/encoding-units-rlp.test.js +92 -89
  124. package/test/unit/encoding-units-rlp.test.ts +91 -0
  125. package/test/unit/errors.test.js +77 -74
  126. package/test/unit/errors.test.ts +76 -0
  127. package/test/unit/filter-by-blockhash.test.js +55 -52
  128. package/test/unit/filter-by-blockhash.test.ts +54 -0
  129. package/test/unit/fixtures/encrypted-keystores-48-32-36.js +9 -0
  130. package/test/unit/generate-contract-cli.test.js +42 -39
  131. package/test/unit/generate-contract-cli.test.ts +41 -0
  132. package/test/unit/generate-sdk-artifacts-json.test.js +113 -110
  133. package/test/unit/generate-sdk-artifacts-json.test.ts +110 -0
  134. package/test/unit/generator.test.js +102 -98
  135. package/test/unit/generator.test.ts +101 -0
  136. package/test/unit/hashing.test.js +68 -54
  137. package/test/unit/hashing.test.ts +67 -0
  138. package/test/unit/init.test.js +39 -36
  139. package/test/unit/init.test.ts +38 -0
  140. package/test/unit/interface.test.js +56 -53
  141. package/test/unit/interface.test.ts +54 -0
  142. package/test/unit/internal-hex.test.js +50 -47
  143. package/test/unit/internal-hex.test.ts +49 -0
  144. package/test/unit/populate-transaction.test.js +65 -0
  145. package/test/unit/populate-transaction.test.ts +64 -0
  146. package/test/unit/providers.test.js +200 -144
  147. package/test/unit/providers.test.ts +196 -0
  148. package/test/unit/result.test.js +80 -77
  149. package/test/unit/result.test.ts +79 -0
  150. package/test/unit/solidity-types.test.js +49 -46
  151. package/test/unit/solidity-types.test.ts +39 -0
  152. package/test/unit/utils.test.js +57 -54
  153. package/test/unit/utils.test.ts +56 -0
  154. package/test/verbose-logger.js +74 -0
  155. package/tsconfig.build.json +14 -0
@@ -1,9 +1,9 @@
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
+ 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 +1,9 @@
1
- /**
2
- * @fileoverview Contract exports.
3
- */
4
-
5
- module.exports = {
6
- ...require("./contract"),
7
- ...require("./contract-factory"),
8
- };
9
-
1
+ /**
2
+ * @fileoverview Contract exports.
3
+ */
4
+
5
+ module.exports = {
6
+ ...require("./contract"),
7
+ ...require("./contract-factory"),
8
+ };
9
+
@@ -1,92 +1,92 @@
1
- export type ErrorCode = "INVALID_ARGUMENT" | "NUMERIC_FAULT" | "BUFFER_OVERRUN" | "CALL_EXCEPTION" | "UNKNOWN_ERROR" | "NOT_IMPLEMENTED";
2
- /**
3
- * @fileoverview Error helpers and error classes.
4
- *
5
- * The QuantumCoin.js SDK follows ethers.js v6 error patterns:
6
- * - errors include a machine-readable `code`
7
- * - errors include `shortMessage`
8
- * - errors may include extra fields depending on the failure
9
- */
10
- /**
11
- * @typedef {"INVALID_ARGUMENT"|"NUMERIC_FAULT"|"BUFFER_OVERRUN"|"CALL_EXCEPTION"|"UNKNOWN_ERROR"|"NOT_IMPLEMENTED"} ErrorCode
12
- */
13
- /**
14
- * Returns true if the error matches the given code.
15
- * @param {any} error
16
- * @param {string} code
17
- * @returns {boolean}
18
- */
19
- export function isError(error: any, code: string): boolean;
20
- /**
21
- * Returns true if the error is a CALL_EXCEPTION.
22
- * @param {any} error
23
- * @returns {boolean}
24
- */
25
- export function isCallException(error: any): boolean;
26
- /**
27
- * Create an Error configured like ethers emits errors.
28
- *
29
- * @param {string} message
30
- * @param {ErrorCode} code
31
- * @param {Record<string, any>=} info
32
- * @returns {Error & { code: ErrorCode, shortMessage: string }}
33
- */
34
- export function makeError(message: string, code: ErrorCode, info?: Record<string, any> | undefined): Error & {
35
- code: ErrorCode;
36
- shortMessage: string;
37
- };
38
- /**
39
- * Assert a condition, throwing an ethers-style error otherwise.
40
- * @param {any} check
41
- * @param {string} message
42
- * @param {ErrorCode} code
43
- * @param {Record<string, any>=} info
44
- */
45
- export function assert(check: any, message: string, code: ErrorCode, info?: Record<string, any> | undefined): void;
46
- /**
47
- * Assert an argument constraint.
48
- * @param {any} check
49
- * @param {string} message
50
- * @param {string} name
51
- * @param {any} value
52
- */
53
- export function assertArgument(check: any, message: string, name: string, value: any): void;
54
- /**
55
- * Provider error.
56
- */
57
- export class ProviderError extends Error {
58
- /**
59
- * @param {string} message
60
- * @param {Record<string, any>=} info
61
- */
62
- constructor(message: string, info?: Record<string, any> | undefined);
63
- /** @type {ErrorCode} */
64
- code: ErrorCode;
65
- shortMessage: string;
66
- }
67
- /**
68
- * Transaction error.
69
- */
70
- export class TransactionError extends Error {
71
- /**
72
- * @param {string} message
73
- * @param {Record<string, any>=} info
74
- */
75
- constructor(message: string, info?: Record<string, any> | undefined);
76
- /** @type {ErrorCode} */
77
- code: ErrorCode;
78
- shortMessage: string;
79
- }
80
- /**
81
- * Contract error.
82
- */
83
- export class ContractError extends Error {
84
- /**
85
- * @param {string} message
86
- * @param {Record<string, any>=} info
87
- */
88
- constructor(message: string, info?: Record<string, any> | undefined);
89
- /** @type {ErrorCode} */
90
- code: ErrorCode;
91
- shortMessage: string;
92
- }
1
+ export type ErrorCode = "INVALID_ARGUMENT" | "NUMERIC_FAULT" | "BUFFER_OVERRUN" | "CALL_EXCEPTION" | "UNKNOWN_ERROR" | "NOT_IMPLEMENTED";
2
+ /**
3
+ * @fileoverview Error helpers and error classes.
4
+ *
5
+ * The QuantumCoin.js SDK follows ethers.js v6 error patterns:
6
+ * - errors include a machine-readable `code`
7
+ * - errors include `shortMessage`
8
+ * - errors may include extra fields depending on the failure
9
+ */
10
+ /**
11
+ * @typedef {"INVALID_ARGUMENT"|"NUMERIC_FAULT"|"BUFFER_OVERRUN"|"CALL_EXCEPTION"|"UNKNOWN_ERROR"|"NOT_IMPLEMENTED"} ErrorCode
12
+ */
13
+ /**
14
+ * Returns true if the error matches the given code.
15
+ * @param {any} error
16
+ * @param {string} code
17
+ * @returns {boolean}
18
+ */
19
+ export function isError(error: any, code: string): boolean;
20
+ /**
21
+ * Returns true if the error is a CALL_EXCEPTION.
22
+ * @param {any} error
23
+ * @returns {boolean}
24
+ */
25
+ export function isCallException(error: any): boolean;
26
+ /**
27
+ * Create an Error configured like ethers emits errors.
28
+ *
29
+ * @param {string} message
30
+ * @param {ErrorCode} code
31
+ * @param {Record<string, any>=} info
32
+ * @returns {Error & { code: ErrorCode, shortMessage: string }}
33
+ */
34
+ export function makeError(message: string, code: ErrorCode, info?: Record<string, any> | undefined): Error & {
35
+ code: ErrorCode;
36
+ shortMessage: string;
37
+ };
38
+ /**
39
+ * Assert a condition, throwing an ethers-style error otherwise.
40
+ * @param {any} check
41
+ * @param {string} message
42
+ * @param {ErrorCode} code
43
+ * @param {Record<string, any>=} info
44
+ */
45
+ export function assert(check: any, message: string, code: ErrorCode, info?: Record<string, any> | undefined): void;
46
+ /**
47
+ * Assert an argument constraint.
48
+ * @param {any} check
49
+ * @param {string} message
50
+ * @param {string} name
51
+ * @param {any} value
52
+ */
53
+ export function assertArgument(check: any, message: string, name: string, value: any): void;
54
+ /**
55
+ * Provider error.
56
+ */
57
+ export class ProviderError extends Error {
58
+ /**
59
+ * @param {string} message
60
+ * @param {Record<string, any>=} info
61
+ */
62
+ constructor(message: string, info?: Record<string, any> | undefined);
63
+ /** @type {ErrorCode} */
64
+ code: ErrorCode;
65
+ shortMessage: string;
66
+ }
67
+ /**
68
+ * Transaction error.
69
+ */
70
+ export class TransactionError extends Error {
71
+ /**
72
+ * @param {string} message
73
+ * @param {Record<string, any>=} info
74
+ */
75
+ constructor(message: string, info?: Record<string, any> | undefined);
76
+ /** @type {ErrorCode} */
77
+ code: ErrorCode;
78
+ shortMessage: string;
79
+ }
80
+ /**
81
+ * Contract error.
82
+ */
83
+ export class ContractError extends Error {
84
+ /**
85
+ * @param {string} message
86
+ * @param {Record<string, any>=} info
87
+ */
88
+ constructor(message: string, info?: Record<string, any> | undefined);
89
+ /** @type {ErrorCode} */
90
+ code: ErrorCode;
91
+ shortMessage: string;
92
+ }
@@ -1,188 +1,188 @@
1
- /**
2
- * @fileoverview Error helpers and error classes.
3
- *
4
- * The QuantumCoin.js SDK follows ethers.js v6 error patterns:
5
- * - errors include a machine-readable `code`
6
- * - errors include `shortMessage`
7
- * - errors may include extra fields depending on the failure
8
- */
9
-
10
- /**
11
- * @typedef {"INVALID_ARGUMENT"|"NUMERIC_FAULT"|"BUFFER_OVERRUN"|"CALL_EXCEPTION"|"UNKNOWN_ERROR"|"NOT_IMPLEMENTED"} ErrorCode
12
- */
13
-
14
- /**
15
- * Returns true if the error matches the given code.
16
- * @param {any} error
17
- * @param {string} code
18
- * @returns {boolean}
19
- */
20
- function isError(error, code) {
21
- return Boolean(error && typeof error === "object" && error.code === code);
22
- }
23
-
24
- /**
25
- * Returns true if the error is a CALL_EXCEPTION.
26
- * @param {any} error
27
- * @returns {boolean}
28
- */
29
- function isCallException(error) {
30
- return isError(error, "CALL_EXCEPTION");
31
- }
32
-
33
- function _stringify(value, seen) {
34
- if (value == null) return "null";
35
- if (seen == null) seen = new Set();
36
- if (typeof value === "object") {
37
- if (seen.has(value)) return "[Circular]";
38
- seen.add(value);
39
- }
40
- if (Array.isArray(value)) return "[ " + value.map((v) => _stringify(v, seen)).join(", ") + " ]";
41
- if (value instanceof Uint8Array) return `Uint8Array(${value.length})`;
42
- if (typeof value === "object" && typeof value.toJSON === "function") return _stringify(value.toJSON(), seen);
43
- switch (typeof value) {
44
- case "boolean":
45
- case "number":
46
- case "symbol":
47
- return value.toString();
48
- case "bigint":
49
- return BigInt(value).toString();
50
- case "string":
51
- return JSON.stringify(value);
52
- case "object": {
53
- const keys = Object.keys(value).sort();
54
- return "{ " + keys.map((k) => `${_stringify(k, seen)}: ${_stringify(value[k], seen)}`).join(", ") + " }";
55
- }
56
- default:
57
- return `[ COULD NOT SERIALIZE ]`;
58
- }
59
- }
60
-
61
- /**
62
- * Create an Error configured like ethers emits errors.
63
- *
64
- * @param {string} message
65
- * @param {ErrorCode} code
66
- * @param {Record<string, any>=} info
67
- * @returns {Error & { code: ErrorCode, shortMessage: string }}
68
- */
69
- function makeError(message, code, info) {
70
- let shortMessage = message;
71
-
72
- const details = [];
73
- if (info) {
74
- if ("message" in info || "code" in info || "name" in info) {
75
- throw new Error(`value will overwrite populated values: ${_stringify(info)}`);
76
- }
77
- for (const key in info) {
78
- if (key === "shortMessage") continue;
79
- details.push(key + "=" + _stringify(info[key]));
80
- }
81
- }
82
- details.push(`code=${code}`);
83
- if (details.length) message += " (" + details.join(", ") + ")";
84
-
85
- /** @type {any} */
86
- let err;
87
- switch (code) {
88
- case "INVALID_ARGUMENT":
89
- err = new TypeError(message);
90
- break;
91
- case "NUMERIC_FAULT":
92
- case "BUFFER_OVERRUN":
93
- err = new RangeError(message);
94
- break;
95
- default:
96
- err = new Error(message);
97
- }
98
-
99
- Object.defineProperty(err, "code", { enumerable: true, value: code, writable: false });
100
- Object.defineProperty(err, "shortMessage", { enumerable: true, value: shortMessage, writable: false });
101
- if (info) Object.assign(err, info);
102
- return err;
103
- }
104
-
105
- /**
106
- * Assert a condition, throwing an ethers-style error otherwise.
107
- * @param {any} check
108
- * @param {string} message
109
- * @param {ErrorCode} code
110
- * @param {Record<string, any>=} info
111
- */
112
- function assert(check, message, code, info) {
113
- if (!check) throw makeError(message, code, info);
114
- }
115
-
116
- /**
117
- * Assert an argument constraint.
118
- * @param {any} check
119
- * @param {string} message
120
- * @param {string} name
121
- * @param {any} value
122
- */
123
- function assertArgument(check, message, name, value) {
124
- assert(check, message, "INVALID_ARGUMENT", { argument: name, value });
125
- }
126
-
127
- /**
128
- * Provider error.
129
- */
130
- class ProviderError extends Error {
131
- /**
132
- * @param {string} message
133
- * @param {Record<string, any>=} info
134
- */
135
- constructor(message, info) {
136
- super(message);
137
- /** @type {ErrorCode} */
138
- this.code = "UNKNOWN_ERROR";
139
- this.shortMessage = message;
140
- if (info) Object.assign(this, info);
141
- }
142
- }
143
-
144
- /**
145
- * Transaction error.
146
- */
147
- class TransactionError extends Error {
148
- /**
149
- * @param {string} message
150
- * @param {Record<string, any>=} info
151
- */
152
- constructor(message, info) {
153
- super(message);
154
- /** @type {ErrorCode} */
155
- this.code = "UNKNOWN_ERROR";
156
- this.shortMessage = message;
157
- if (info) Object.assign(this, info);
158
- }
159
- }
160
-
161
- /**
162
- * Contract error.
163
- */
164
- class ContractError extends Error {
165
- /**
166
- * @param {string} message
167
- * @param {Record<string, any>=} info
168
- */
169
- constructor(message, info) {
170
- super(message);
171
- /** @type {ErrorCode} */
172
- this.code = "UNKNOWN_ERROR";
173
- this.shortMessage = message;
174
- if (info) Object.assign(this, info);
175
- }
176
- }
177
-
178
- module.exports = {
179
- isError,
180
- isCallException,
181
- makeError,
182
- assert,
183
- assertArgument,
184
- ProviderError,
185
- TransactionError,
186
- ContractError,
187
- };
188
-
1
+ /**
2
+ * @fileoverview Error helpers and error classes.
3
+ *
4
+ * The QuantumCoin.js SDK follows ethers.js v6 error patterns:
5
+ * - errors include a machine-readable `code`
6
+ * - errors include `shortMessage`
7
+ * - errors may include extra fields depending on the failure
8
+ */
9
+
10
+ /**
11
+ * @typedef {"INVALID_ARGUMENT"|"NUMERIC_FAULT"|"BUFFER_OVERRUN"|"CALL_EXCEPTION"|"UNKNOWN_ERROR"|"NOT_IMPLEMENTED"} ErrorCode
12
+ */
13
+
14
+ /**
15
+ * Returns true if the error matches the given code.
16
+ * @param {any} error
17
+ * @param {string} code
18
+ * @returns {boolean}
19
+ */
20
+ function isError(error, code) {
21
+ return Boolean(error && typeof error === "object" && error.code === code);
22
+ }
23
+
24
+ /**
25
+ * Returns true if the error is a CALL_EXCEPTION.
26
+ * @param {any} error
27
+ * @returns {boolean}
28
+ */
29
+ function isCallException(error) {
30
+ return isError(error, "CALL_EXCEPTION");
31
+ }
32
+
33
+ function _stringify(value, seen) {
34
+ if (value == null) return "null";
35
+ if (seen == null) seen = new Set();
36
+ if (typeof value === "object") {
37
+ if (seen.has(value)) return "[Circular]";
38
+ seen.add(value);
39
+ }
40
+ if (Array.isArray(value)) return "[ " + value.map((v) => _stringify(v, seen)).join(", ") + " ]";
41
+ if (value instanceof Uint8Array) return `Uint8Array(${value.length})`;
42
+ if (typeof value === "object" && typeof value.toJSON === "function") return _stringify(value.toJSON(), seen);
43
+ switch (typeof value) {
44
+ case "boolean":
45
+ case "number":
46
+ case "symbol":
47
+ return value.toString();
48
+ case "bigint":
49
+ return BigInt(value).toString();
50
+ case "string":
51
+ return JSON.stringify(value);
52
+ case "object": {
53
+ const keys = Object.keys(value).sort();
54
+ return "{ " + keys.map((k) => `${_stringify(k, seen)}: ${_stringify(value[k], seen)}`).join(", ") + " }";
55
+ }
56
+ default:
57
+ return `[ COULD NOT SERIALIZE ]`;
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Create an Error configured like ethers emits errors.
63
+ *
64
+ * @param {string} message
65
+ * @param {ErrorCode} code
66
+ * @param {Record<string, any>=} info
67
+ * @returns {Error & { code: ErrorCode, shortMessage: string }}
68
+ */
69
+ function makeError(message, code, info) {
70
+ let shortMessage = message;
71
+
72
+ const details = [];
73
+ if (info) {
74
+ if ("message" in info || "code" in info || "name" in info) {
75
+ throw new Error(`value will overwrite populated values: ${_stringify(info)}`);
76
+ }
77
+ for (const key in info) {
78
+ if (key === "shortMessage") continue;
79
+ details.push(key + "=" + _stringify(info[key]));
80
+ }
81
+ }
82
+ details.push(`code=${code}`);
83
+ if (details.length) message += " (" + details.join(", ") + ")";
84
+
85
+ /** @type {any} */
86
+ let err;
87
+ switch (code) {
88
+ case "INVALID_ARGUMENT":
89
+ err = new TypeError(message);
90
+ break;
91
+ case "NUMERIC_FAULT":
92
+ case "BUFFER_OVERRUN":
93
+ err = new RangeError(message);
94
+ break;
95
+ default:
96
+ err = new Error(message);
97
+ }
98
+
99
+ Object.defineProperty(err, "code", { enumerable: true, value: code, writable: false });
100
+ Object.defineProperty(err, "shortMessage", { enumerable: true, value: shortMessage, writable: false });
101
+ if (info) Object.assign(err, info);
102
+ return err;
103
+ }
104
+
105
+ /**
106
+ * Assert a condition, throwing an ethers-style error otherwise.
107
+ * @param {any} check
108
+ * @param {string} message
109
+ * @param {ErrorCode} code
110
+ * @param {Record<string, any>=} info
111
+ */
112
+ function assert(check, message, code, info) {
113
+ if (!check) throw makeError(message, code, info);
114
+ }
115
+
116
+ /**
117
+ * Assert an argument constraint.
118
+ * @param {any} check
119
+ * @param {string} message
120
+ * @param {string} name
121
+ * @param {any} value
122
+ */
123
+ function assertArgument(check, message, name, value) {
124
+ assert(check, message, "INVALID_ARGUMENT", { argument: name, value });
125
+ }
126
+
127
+ /**
128
+ * Provider error.
129
+ */
130
+ class ProviderError extends Error {
131
+ /**
132
+ * @param {string} message
133
+ * @param {Record<string, any>=} info
134
+ */
135
+ constructor(message, info) {
136
+ super(message);
137
+ /** @type {ErrorCode} */
138
+ this.code = "UNKNOWN_ERROR";
139
+ this.shortMessage = message;
140
+ if (info) Object.assign(this, info);
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Transaction error.
146
+ */
147
+ class TransactionError extends Error {
148
+ /**
149
+ * @param {string} message
150
+ * @param {Record<string, any>=} info
151
+ */
152
+ constructor(message, info) {
153
+ super(message);
154
+ /** @type {ErrorCode} */
155
+ this.code = "UNKNOWN_ERROR";
156
+ this.shortMessage = message;
157
+ if (info) Object.assign(this, info);
158
+ }
159
+ }
160
+
161
+ /**
162
+ * Contract error.
163
+ */
164
+ class ContractError extends Error {
165
+ /**
166
+ * @param {string} message
167
+ * @param {Record<string, any>=} info
168
+ */
169
+ constructor(message, info) {
170
+ super(message);
171
+ /** @type {ErrorCode} */
172
+ this.code = "UNKNOWN_ERROR";
173
+ this.shortMessage = message;
174
+ if (info) Object.assign(this, info);
175
+ }
176
+ }
177
+
178
+ module.exports = {
179
+ isError,
180
+ isCallException,
181
+ makeError,
182
+ assert,
183
+ assertArgument,
184
+ ProviderError,
185
+ TransactionError,
186
+ ContractError,
187
+ };
188
+
@@ -0,0 +1,74 @@
1
+ export type GenerateOptions = {
2
+ abiPath: string;
3
+ binPath: string;
4
+ outDir: string;
5
+ contractName: string;
6
+ packageName?: string | undefined;
7
+ createPackage?: boolean | undefined;
8
+ dependencies?: Record<string, string> | undefined;
9
+ };
10
+ /**
11
+ * Generate typed contract files.
12
+ * @param {GenerateOptions} opts
13
+ * @returns {{ contractFile: string, factoryFile: string, typesFile: string, indexFile: string }}
14
+ */
15
+ export function generate(opts: GenerateOptions): {
16
+ contractFile: string;
17
+ factoryFile: string;
18
+ typesFile: string;
19
+ indexFile: string;
20
+ };
21
+ /**
22
+ * @typedef {Object} GenerateOptions
23
+ * @property {string} abiPath
24
+ * @property {string} binPath
25
+ * @property {string} outDir
26
+ * @property {string} contractName
27
+ * @property {string=} packageName
28
+ * @property {boolean=} createPackage
29
+ * @property {Record<string,string>=} dependencies
30
+ */
31
+ /**
32
+ * Generate multiple typed contract files.
33
+ * @param {{ outDir: string, artifacts: Array<{ contractName: string, abi: any[], bytecode: string }> }} opts
34
+ * @returns {{ contracts: Array<{ contractFile: string, factoryFile: string }>, typesFile: string, indexFile: string }}
35
+ */
36
+ export function generateFromArtifacts(opts: {
37
+ outDir: string;
38
+ artifacts: Array<{
39
+ contractName: string;
40
+ abi: any[];
41
+ bytecode: string;
42
+ }>;
43
+ }): {
44
+ contracts: Array<{
45
+ contractFile: string;
46
+ factoryFile: string;
47
+ }>;
48
+ typesFile: string;
49
+ indexFile: string;
50
+ };
51
+ /**
52
+ * Generate a transactional e2e test file (JavaScript) for the typed contract package.
53
+ * The test deploys the contract with constructor args (if any) and invokes one write method.
54
+ *
55
+ * @param {{ contractName: string, abi: any[] }} opts
56
+ * @returns {string}
57
+ */
58
+ export function generateTransactionalTestJs(opts: {
59
+ contractName: string;
60
+ abi: any[];
61
+ }): string;
62
+ /**
63
+ * Generate a single transactional e2e test that deploys and invokes methods on ALL contracts.
64
+ * Used when the package has multiple contracts so one test exercises every contract.
65
+ *
66
+ * @param {{ artifacts: Array<{ contractName: string, abi: any[] }> }} opts
67
+ * @returns {string}
68
+ */
69
+ export function generateAllContractsTransactionalTestJs(opts: {
70
+ artifacts: Array<{
71
+ contractName: string;
72
+ abi: any[];
73
+ }>;
74
+ }): string;