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,55 +1,65 @@
1
- declare const _exports: {
2
- formatUnits: typeof import("./units").formatUnits;
3
- parseUnits: typeof import("./units").parseUnits;
4
- formatEther: typeof import("./units").formatEther;
5
- parseEther: typeof import("./units").parseEther;
6
- WeiPerEther: bigint;
7
- Result: typeof import("./result").Result;
8
- checkResultErrors: typeof import("./result").checkResultErrors;
9
- encodeRlp: typeof import("./rlp").encodeRlp;
10
- decodeRlp: typeof import("./rlp").decodeRlp;
11
- keccak256: typeof import("./hashing").keccak256;
12
- sha256: typeof import("./hashing").sha256;
13
- sha512: typeof import("./hashing").sha512;
14
- ripemd160: typeof import("./hashing").ripemd160;
15
- id: typeof import("./hashing").id;
16
- randomBytes: typeof import("./hashing").randomBytes;
17
- computeHmac: typeof import("./hashing").computeHmac;
18
- pbkdf2: typeof import("./hashing").pbkdf2;
19
- scrypt: typeof import("./hashing").scrypt;
20
- scryptSync: typeof import("./hashing").scryptSync;
21
- toUtf8String: typeof import("./encoding").toUtf8String;
22
- toUtf8Bytes: typeof import("./encoding").toUtf8Bytes;
23
- toHex: typeof import("./encoding").toHex;
24
- hexlify: typeof import("./encoding").hexlify;
25
- arrayify: typeof import("./encoding").arrayify;
26
- concat: typeof import("./encoding").concat;
27
- stripZerosLeft: typeof import("./encoding").stripZerosLeft;
28
- encodeBytes32String: typeof import("./encoding").encodeBytes32String;
29
- decodeBytes32String: typeof import("./encoding").decodeBytes32String;
30
- decodeBase58: typeof import("./encoding").decodeBase58;
31
- decodeBase64: typeof import("./encoding").decodeBase64;
32
- encodeBase58: typeof import("./encoding").encodeBase58;
33
- encodeBase64: typeof import("./encoding").encodeBase64;
34
- toUtf8CodePoints: typeof import("./encoding").toUtf8CodePoints;
35
- isHexString: typeof import("./encoding").isHexString;
36
- isBytesLike: typeof import("./encoding").isBytesLike;
37
- zeroPad: typeof import("./encoding").zeroPad;
38
- zeroPadValue: typeof import("./encoding").zeroPadValue;
39
- solidityPacked: typeof import("./encoding").solidityPacked;
40
- solidityPackedKeccak256: typeof import("./encoding").solidityPackedKeccak256;
41
- solidityPackedSha256: typeof import("./encoding").solidityPackedSha256;
42
- bytesToHex: typeof import("./encoding").bytesToHex;
43
- hexToBytes: typeof import("./encoding").hexToBytes;
44
- isAddress: typeof import("./address").isAddress;
45
- getAddress: typeof import("./address").getAddress;
46
- isAddressable: typeof import("./address").isAddressable;
47
- resolveAddress: typeof import("./address").resolveAddress;
48
- getContractAddress: typeof import("./address").getContractAddress;
49
- getCreateAddress: typeof import("./address").getCreateAddress;
50
- getCreate2Address: typeof import("./address").getCreate2Address;
51
- computeAddress: typeof import("./address").computeAddress;
52
- verifyMessage: typeof import("./address").verifyMessage;
53
- recoverAddress: typeof import("./address").recoverAddress;
54
- };
55
- export = _exports;
1
+ declare const _exports: {
2
+ formatUnits(value: import("./units").BigNumberish, decimals?: number | undefined): string;
3
+ parseUnits(value: string, decimals?: number | undefined): bigint;
4
+ formatEther(value: import("./units").BigNumberish): string;
5
+ parseEther(value: string): bigint;
6
+ WeiPerEther: bigint;
7
+ checkResultErrors(result: any): Array<{
8
+ error: Error;
9
+ path: Array<string | number>;
10
+ }>;
11
+ Result: typeof import("./result").Result;
12
+ encodeRlp(value: any): string;
13
+ decodeRlp(data: string): any;
14
+ keccak256(data: string | Uint8Array): string;
15
+ hashMessage(message: string | Uint8Array): string;
16
+ sha256(data: string | Uint8Array): string;
17
+ sha512(data: string | Uint8Array): string;
18
+ ripemd160(data: string | Uint8Array): string;
19
+ id(text: string): string;
20
+ randomBytes(length: number): Uint8Array;
21
+ computeHmac(algorithm: string, key: string | Uint8Array, data: string | Uint8Array): string;
22
+ pbkdf2(password: string | Uint8Array, salt: string | Uint8Array, iterations: number, keylen: number, algorithm?: string | undefined): string;
23
+ scrypt(password: string | Uint8Array, salt: string | Uint8Array, N: number, r: number, p: number, dkLen: number): Promise<string>;
24
+ scryptSync(password: string | Uint8Array, salt: string | Uint8Array, N: number, r: number, p: number, dkLen: number): string;
25
+ toUtf8String(data: import("./encoding").BytesLike): string;
26
+ toUtf8Bytes(str: string): Uint8Array;
27
+ toHex(data: import("./encoding").BytesLike): string;
28
+ hexlify(data: import("./encoding").BytesLike): string;
29
+ arrayify(data: import("./encoding").BytesLike): Uint8Array;
30
+ concat(items: import("./encoding").BytesLike[]): string;
31
+ stripZerosLeft(data: import("./encoding").BytesLike): string;
32
+ encodeBytes32String(text: string): string;
33
+ decodeBytes32String(bytes: import("./encoding").BytesLike): string;
34
+ decodeBase58(data: string): Uint8Array;
35
+ decodeBase64(data: string): Uint8Array;
36
+ encodeBase58(data: import("./encoding").BytesLike): string;
37
+ encodeBase64(data: import("./encoding").BytesLike): string;
38
+ toUtf8CodePoints(str: string): number[];
39
+ isBytesLike(value: any): boolean;
40
+ zeroPad(value: import("./encoding").BytesLike, length: number): string;
41
+ zeroPadValue(value: import("./encoding").BytesLike, length: number): string;
42
+ solidityPacked(): void;
43
+ solidityPackedKeccak256(): void;
44
+ solidityPackedSha256(): void;
45
+ isHexString: typeof import("./encoding").isHexString;
46
+ bytesToHex: typeof import("./encoding").bytesToHex;
47
+ hexToBytes: typeof import("./encoding").hexToBytes;
48
+ isAddress(address: string): boolean;
49
+ getAddress(address: string): string;
50
+ isAddressable(value: any): boolean;
51
+ resolveAddress(target: any): string | Promise<string>;
52
+ getContractAddress(tx: {
53
+ from: string;
54
+ nonce: number;
55
+ }): string;
56
+ getCreateAddress(tx: {
57
+ from: string;
58
+ nonce: number;
59
+ }): string;
60
+ getCreate2Address(from: string, salt: string, initCodeHash: string): string;
61
+ computeAddress(key: string | Uint8Array): string;
62
+ verifyMessage(message: string | Uint8Array, signature: string): string;
63
+ recoverAddress(message: string | Uint8Array, signature: string): string;
64
+ };
65
+ export = _exports;
@@ -1,13 +1,13 @@
1
- /**
2
- * @fileoverview Utilities export barrel.
3
- */
4
-
5
- module.exports = {
6
- ...require("./address"),
7
- ...require("./encoding"),
8
- ...require("./hashing"),
9
- ...require("./rlp"),
10
- ...require("./result"),
11
- ...require("./units"),
12
- };
13
-
1
+ /**
2
+ * @fileoverview Utilities export barrel.
3
+ */
4
+
5
+ module.exports = {
6
+ ...require("./address"),
7
+ ...require("./encoding"),
8
+ ...require("./hashing"),
9
+ ...require("./rlp"),
10
+ ...require("./result"),
11
+ ...require("./units"),
12
+ };
13
+
@@ -1,57 +1,57 @@
1
- /**
2
- * @fileoverview Result utility (ethers.js v6 compatible).
3
- *
4
- * ethers.js Result is an Array-like with optional named keys.
5
- * This simplified implementation covers the common patterns used in this SDK.
6
- */
7
- export class Result extends Array<any> {
8
- /**
9
- * @param {Array<any>} items
10
- * @param {Array<null|string>=} keys
11
- * @returns {Result}
12
- */
13
- static fromItems(items: Array<any>, keys?: Array<null | string> | undefined): Result;
14
- /**
15
- * @param {any[]=} items
16
- * @param {(null|string)[]=} keys
17
- */
18
- constructor(items?: any[] | undefined, keys?: (null | string)[] | undefined);
19
- /** @type {(null|string)[]|null} */
20
- _keys: (null | string)[] | null;
21
- /**
22
- * Get a value by key.
23
- * @param {string} name
24
- * @returns {any}
25
- */
26
- getValue(name: string): any;
27
- /**
28
- * Convert to array (optionally deep).
29
- * @param {boolean=} deep
30
- * @returns {any[]}
31
- */
32
- toArray(deep?: boolean | undefined): any[];
33
- /**
34
- * Convert to object (optionally deep).
35
- * @param {boolean=} deep
36
- * @returns {Record<string, any>}
37
- */
38
- toObject(deep?: boolean | undefined): Record<string, any>;
39
- }
40
- /**
41
- * Scan a decoded Result (or nested structure) for embedded Error objects.
42
- *
43
- * ethers.js uses this to surface nested decode errors (especially for tuples
44
- * and structs). This lightweight implementation walks:
45
- * - Result instances (by index; prefers named keys in the path when available)
46
- * - Arrays
47
- * - Plain objects (for struct-like outputs)
48
- *
49
- * It is cycle-safe.
50
- *
51
- * @param {any} result
52
- * @returns {Array<{ error: Error, path: Array<string|number> }>}
53
- */
54
- export function checkResultErrors(result: any): Array<{
55
- error: Error;
56
- path: Array<string | number>;
57
- }>;
1
+ /**
2
+ * @fileoverview Result utility (ethers.js v6 compatible).
3
+ *
4
+ * ethers.js Result is an Array-like with optional named keys.
5
+ * This simplified implementation covers the common patterns used in this SDK.
6
+ */
7
+ export class Result extends Array<any> {
8
+ /**
9
+ * @param {Array<any>} items
10
+ * @param {Array<null|string>=} keys
11
+ * @returns {Result}
12
+ */
13
+ static fromItems(items: Array<any>, keys?: Array<null | string> | undefined): Result;
14
+ /**
15
+ * @param {any[]=} items
16
+ * @param {(null|string)[]=} keys
17
+ */
18
+ constructor(items?: any[] | undefined, keys?: (null | string)[] | undefined);
19
+ /** @type {(null|string)[]|null} */
20
+ _keys: (null | string)[] | null;
21
+ /**
22
+ * Get a value by key.
23
+ * @param {string} name
24
+ * @returns {any}
25
+ */
26
+ getValue(name: string): any;
27
+ /**
28
+ * Convert to array (optionally deep).
29
+ * @param {boolean=} deep
30
+ * @returns {any[]}
31
+ */
32
+ toArray(deep?: boolean | undefined): any[];
33
+ /**
34
+ * Convert to object (optionally deep).
35
+ * @param {boolean=} deep
36
+ * @returns {Record<string, any>}
37
+ */
38
+ toObject(deep?: boolean | undefined): Record<string, any>;
39
+ }
40
+ /**
41
+ * Scan a decoded Result (or nested structure) for embedded Error objects.
42
+ *
43
+ * ethers.js uses this to surface nested decode errors (especially for tuples
44
+ * and structs). This lightweight implementation walks:
45
+ * - Result instances (by index; prefers named keys in the path when available)
46
+ * - Arrays
47
+ * - Plain objects (for struct-like outputs)
48
+ *
49
+ * It is cycle-safe.
50
+ *
51
+ * @param {any} result
52
+ * @returns {Array<{ error: Error, path: Array<string|number> }>}
53
+ */
54
+ export function checkResultErrors(result: any): Array<{
55
+ error: Error;
56
+ path: Array<string | number>;
57
+ }>;
@@ -1,128 +1,128 @@
1
- /**
2
- * @fileoverview Result utility (ethers.js v6 compatible).
3
- *
4
- * ethers.js Result is an Array-like with optional named keys.
5
- * This simplified implementation covers the common patterns used in this SDK.
6
- */
7
-
8
- class Result extends Array {
9
- /**
10
- * @param {any[]=} items
11
- * @param {(null|string)[]=} keys
12
- */
13
- constructor(items, keys) {
14
- super();
15
- if (Array.isArray(items)) this.push(...items);
16
- /** @type {(null|string)[]|null} */
17
- this._keys = Array.isArray(keys) ? keys : null;
18
-
19
- if (this._keys) {
20
- for (let i = 0; i < this._keys.length; i++) {
21
- const k = this._keys[i];
22
- if (k) this[k] = this[i];
23
- }
24
- }
25
- }
26
-
27
- /**
28
- * @param {Array<any>} items
29
- * @param {Array<null|string>=} keys
30
- * @returns {Result}
31
- */
32
- static fromItems(items, keys) {
33
- return new Result(items, keys);
34
- }
35
-
36
- /**
37
- * Get a value by key.
38
- * @param {string} name
39
- * @returns {any}
40
- */
41
- getValue(name) {
42
- return this[name];
43
- }
44
-
45
- /**
46
- * Convert to array (optionally deep).
47
- * @param {boolean=} deep
48
- * @returns {any[]}
49
- */
50
- toArray(deep) {
51
- if (!deep) return Array.from(this);
52
- return Array.from(this).map((v) => (v instanceof Result ? v.toArray(true) : v));
53
- }
54
-
55
- /**
56
- * Convert to object (optionally deep).
57
- * @param {boolean=} deep
58
- * @returns {Record<string, any>}
59
- */
60
- toObject(deep) {
61
- const out = {};
62
- if (!this._keys) return out;
63
- for (const k of this._keys) {
64
- if (!k) continue;
65
- const v = this[k];
66
- out[k] = deep && v instanceof Result ? v.toObject(true) : v;
67
- }
68
- return out;
69
- }
70
- }
71
-
72
- /**
73
- * Scan a decoded Result (or nested structure) for embedded Error objects.
74
- *
75
- * ethers.js uses this to surface nested decode errors (especially for tuples
76
- * and structs). This lightweight implementation walks:
77
- * - Result instances (by index; prefers named keys in the path when available)
78
- * - Arrays
79
- * - Plain objects (for struct-like outputs)
80
- *
81
- * It is cycle-safe.
82
- *
83
- * @param {any} result
84
- * @returns {Array<{ error: Error, path: Array<string|number> }>}
85
- */
86
- function checkResultErrors(result) {
87
- /** @type {Array<{ error: Error, path: Array<string|number> }>} */
88
- const out = [];
89
- const seen = new WeakSet();
90
-
91
- /**
92
- * @param {any} value
93
- * @param {Array<string|number>} path
94
- */
95
- function walk(value, path) {
96
- if (value instanceof Error) {
97
- out.push({ error: value, path });
98
- return;
99
- }
100
- if (!value || (typeof value !== "object" && typeof value !== "function")) return;
101
- if (seen.has(value)) return;
102
- seen.add(value);
103
-
104
- // Prefer walking Result/Array by index to avoid duplicates (Result also has named keys).
105
- if (value instanceof Result || Array.isArray(value)) {
106
- const keys = value instanceof Result ? value._keys : null;
107
- for (let i = 0; i < value.length; i++) {
108
- const k = Array.isArray(keys) && keys[i] ? keys[i] : i;
109
- walk(value[i], path.concat([k]));
110
- }
111
- return;
112
- }
113
-
114
- // Walk only plain objects to avoid traversing things like Buffers, Dates, etc.
115
- const proto = Object.getPrototypeOf(value);
116
- if (proto === Object.prototype || proto === null) {
117
- for (const k of Object.keys(value)) {
118
- walk(value[k], path.concat([k]));
119
- }
120
- }
121
- }
122
-
123
- walk(result, []);
124
- return out;
125
- }
126
-
127
- module.exports = { Result, checkResultErrors };
128
-
1
+ /**
2
+ * @fileoverview Result utility (ethers.js v6 compatible).
3
+ *
4
+ * ethers.js Result is an Array-like with optional named keys.
5
+ * This simplified implementation covers the common patterns used in this SDK.
6
+ */
7
+
8
+ class Result extends Array {
9
+ /**
10
+ * @param {any[]=} items
11
+ * @param {(null|string)[]=} keys
12
+ */
13
+ constructor(items, keys) {
14
+ super();
15
+ if (Array.isArray(items)) this.push(...items);
16
+ /** @type {(null|string)[]|null} */
17
+ this._keys = Array.isArray(keys) ? keys : null;
18
+
19
+ if (this._keys) {
20
+ for (let i = 0; i < this._keys.length; i++) {
21
+ const k = this._keys[i];
22
+ if (k) this[k] = this[i];
23
+ }
24
+ }
25
+ }
26
+
27
+ /**
28
+ * @param {Array<any>} items
29
+ * @param {Array<null|string>=} keys
30
+ * @returns {Result}
31
+ */
32
+ static fromItems(items, keys) {
33
+ return new Result(items, keys);
34
+ }
35
+
36
+ /**
37
+ * Get a value by key.
38
+ * @param {string} name
39
+ * @returns {any}
40
+ */
41
+ getValue(name) {
42
+ return this[name];
43
+ }
44
+
45
+ /**
46
+ * Convert to array (optionally deep).
47
+ * @param {boolean=} deep
48
+ * @returns {any[]}
49
+ */
50
+ toArray(deep) {
51
+ if (!deep) return Array.from(this);
52
+ return Array.from(this).map((v) => (v instanceof Result ? v.toArray(true) : v));
53
+ }
54
+
55
+ /**
56
+ * Convert to object (optionally deep).
57
+ * @param {boolean=} deep
58
+ * @returns {Record<string, any>}
59
+ */
60
+ toObject(deep) {
61
+ const out = {};
62
+ if (!this._keys) return out;
63
+ for (const k of this._keys) {
64
+ if (!k) continue;
65
+ const v = this[k];
66
+ out[k] = deep && v instanceof Result ? v.toObject(true) : v;
67
+ }
68
+ return out;
69
+ }
70
+ }
71
+
72
+ /**
73
+ * Scan a decoded Result (or nested structure) for embedded Error objects.
74
+ *
75
+ * ethers.js uses this to surface nested decode errors (especially for tuples
76
+ * and structs). This lightweight implementation walks:
77
+ * - Result instances (by index; prefers named keys in the path when available)
78
+ * - Arrays
79
+ * - Plain objects (for struct-like outputs)
80
+ *
81
+ * It is cycle-safe.
82
+ *
83
+ * @param {any} result
84
+ * @returns {Array<{ error: Error, path: Array<string|number> }>}
85
+ */
86
+ function checkResultErrors(result) {
87
+ /** @type {Array<{ error: Error, path: Array<string|number> }>} */
88
+ const out = [];
89
+ const seen = new WeakSet();
90
+
91
+ /**
92
+ * @param {any} value
93
+ * @param {Array<string|number>} path
94
+ */
95
+ function walk(value, path) {
96
+ if (value instanceof Error) {
97
+ out.push({ error: value, path });
98
+ return;
99
+ }
100
+ if (!value || (typeof value !== "object" && typeof value !== "function")) return;
101
+ if (seen.has(value)) return;
102
+ seen.add(value);
103
+
104
+ // Prefer walking Result/Array by index to avoid duplicates (Result also has named keys).
105
+ if (value instanceof Result || Array.isArray(value)) {
106
+ const keys = value instanceof Result ? value._keys : null;
107
+ for (let i = 0; i < value.length; i++) {
108
+ const k = Array.isArray(keys) && keys[i] ? keys[i] : i;
109
+ walk(value[i], path.concat([k]));
110
+ }
111
+ return;
112
+ }
113
+
114
+ // Walk only plain objects to avoid traversing things like Buffers, Dates, etc.
115
+ const proto = Object.getPrototypeOf(value);
116
+ if (proto === Object.prototype || proto === null) {
117
+ for (const k of Object.keys(value)) {
118
+ walk(value[k], path.concat([k]));
119
+ }
120
+ }
121
+ }
122
+
123
+ walk(result, []);
124
+ return out;
125
+ }
126
+
127
+ module.exports = { Result, checkResultErrors };
128
+
@@ -1,12 +1,12 @@
1
- /**
2
- * RLP-encode a value.
3
- * @param {any} value
4
- * @returns {string}
5
- */
6
- export function encodeRlp(value: any): string;
7
- /**
8
- * RLP-decode a hex string.
9
- * @param {string} data
10
- * @returns {any}
11
- */
12
- export function decodeRlp(data: string): any;
1
+ /**
2
+ * RLP-encode a value.
3
+ * @param {any} value
4
+ * @returns {string}
5
+ */
6
+ export function encodeRlp(value: any): string;
7
+ /**
8
+ * RLP-decode a hex string.
9
+ * @param {string} data
10
+ * @returns {any}
11
+ */
12
+ export function decodeRlp(data: string): any;