quantumcoin 6.14.2 → 6.14.5

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 (317) hide show
  1. package/CHANGELOG.md +442 -442
  2. package/FUNDING.json +10 -10
  3. package/LICENSE.md +21 -21
  4. package/README.md +132 -142
  5. package/SECURITY.md +34 -34
  6. package/dist/README.md +22 -22
  7. package/dist/quantumcoin.js +1127 -1324
  8. package/dist/quantumcoin.js.map +1 -1
  9. package/dist/quantumcoin.min.js +1 -1
  10. package/dist/quantumcoin.umd.js +1128 -1327
  11. package/dist/quantumcoin.umd.js.map +1 -1
  12. package/dist/quantumcoin.umd.min.js +1 -1
  13. package/dist/wordlists-extra.js +1 -1
  14. package/dist/wordlists-extra.js.map +1 -1
  15. package/dist/wordlists-extra.min.js +1 -1
  16. package/lib.commonjs/README.md +16 -16
  17. package/lib.commonjs/_version.js +1 -1
  18. package/lib.commonjs/crypto/signature.d.ts +3 -76
  19. package/lib.commonjs/crypto/signature.d.ts.map +1 -1
  20. package/lib.commonjs/crypto/signature.js +15 -199
  21. package/lib.commonjs/crypto/signature.js.map +1 -1
  22. package/lib.commonjs/crypto/signing-key.d.ts +1 -1
  23. package/lib.commonjs/crypto/signing-key.d.ts.map +1 -1
  24. package/lib.commonjs/crypto/signing-key.js +19 -10
  25. package/lib.commonjs/crypto/signing-key.js.map +1 -1
  26. package/lib.commonjs/package.json +12 -12
  27. package/lib.commonjs/providers/provider-jsonrpc.d.ts +0 -1
  28. package/lib.commonjs/providers/provider-jsonrpc.d.ts.map +1 -1
  29. package/lib.commonjs/providers/provider-jsonrpc.js +0 -1
  30. package/lib.commonjs/providers/provider-jsonrpc.js.map +1 -1
  31. package/lib.commonjs/quantumcoin.d.ts +2 -0
  32. package/lib.commonjs/quantumcoin.d.ts.map +1 -1
  33. package/lib.commonjs/quantumcoin.js +11 -5
  34. package/lib.commonjs/quantumcoin.js.map +1 -1
  35. package/lib.commonjs/transaction/address.d.ts.map +1 -1
  36. package/lib.commonjs/transaction/address.js +8 -3
  37. package/lib.commonjs/transaction/address.js.map +1 -1
  38. package/lib.commonjs/transaction/transaction.d.ts.map +1 -1
  39. package/lib.commonjs/transaction/transaction.js +7 -40
  40. package/lib.commonjs/transaction/transaction.js.map +1 -1
  41. package/lib.commonjs/wallet/json-keystore.d.ts.map +1 -1
  42. package/lib.commonjs/wallet/json-keystore.js +7 -7
  43. package/lib.commonjs/wallet/json-keystore.js.map +1 -1
  44. package/lib.commonjs/wallet/wallet.d.ts.map +1 -1
  45. package/lib.commonjs/wallet/wallet.js +2 -2
  46. package/lib.commonjs/wallet/wallet.js.map +1 -1
  47. package/lib.esm/README.md +16 -16
  48. package/lib.esm/_version.js +1 -1
  49. package/lib.esm/crypto/signature.d.ts +3 -76
  50. package/lib.esm/crypto/signature.d.ts.map +1 -1
  51. package/lib.esm/crypto/signature.js +16 -202
  52. package/lib.esm/crypto/signature.js.map +1 -1
  53. package/lib.esm/crypto/signing-key.d.ts +1 -1
  54. package/lib.esm/crypto/signing-key.d.ts.map +1 -1
  55. package/lib.esm/crypto/signing-key.js +20 -9
  56. package/lib.esm/crypto/signing-key.js.map +1 -1
  57. package/lib.esm/package.json +12 -12
  58. package/lib.esm/providers/provider-jsonrpc.d.ts +0 -1
  59. package/lib.esm/providers/provider-jsonrpc.d.ts.map +1 -1
  60. package/lib.esm/providers/provider-jsonrpc.js +0 -1
  61. package/lib.esm/providers/provider-jsonrpc.js.map +1 -1
  62. package/lib.esm/quantumcoin.d.ts +2 -0
  63. package/lib.esm/quantumcoin.d.ts.map +1 -1
  64. package/lib.esm/quantumcoin.js +6 -0
  65. package/lib.esm/quantumcoin.js.map +1 -1
  66. package/lib.esm/transaction/address.d.ts.map +1 -1
  67. package/lib.esm/transaction/address.js +8 -2
  68. package/lib.esm/transaction/address.js.map +1 -1
  69. package/lib.esm/transaction/transaction.d.ts.map +1 -1
  70. package/lib.esm/transaction/transaction.js +7 -40
  71. package/lib.esm/transaction/transaction.js.map +1 -1
  72. package/lib.esm/wallet/json-keystore.d.ts.map +1 -1
  73. package/lib.esm/wallet/json-keystore.js +11 -5
  74. package/lib.esm/wallet/json-keystore.js.map +1 -1
  75. package/lib.esm/wallet/wallet.d.ts.map +1 -1
  76. package/lib.esm/wallet/wallet.js +3 -1
  77. package/lib.esm/wallet/wallet.js.map +1 -1
  78. package/package.json +6 -5
  79. package/rollup.config.mjs +50 -50
  80. package/src.ts/_version.ts +1 -1
  81. package/src.ts/abi/abi-coder.ts +237 -237
  82. package/src.ts/abi/bytes32.ts +45 -45
  83. package/src.ts/abi/coders/abstract-coder.ts +541 -541
  84. package/src.ts/abi/coders/address.ts +36 -36
  85. package/src.ts/abi/coders/anonymous.ts +29 -29
  86. package/src.ts/abi/coders/array.ts +199 -199
  87. package/src.ts/abi/coders/boolean.ts +27 -27
  88. package/src.ts/abi/coders/bytes.ts +43 -43
  89. package/src.ts/abi/coders/fixed-bytes.ts +37 -37
  90. package/src.ts/abi/coders/null.ts +28 -28
  91. package/src.ts/abi/coders/number.ts +63 -63
  92. package/src.ts/abi/coders/string.ts +29 -29
  93. package/src.ts/abi/coders/tuple.ts +69 -69
  94. package/src.ts/abi/fragments.ts +1617 -1617
  95. package/src.ts/abi/index.ts +41 -41
  96. package/src.ts/abi/interface.ts +1271 -1271
  97. package/src.ts/abi/typed.ts +796 -796
  98. package/src.ts/address/address.ts +148 -148
  99. package/src.ts/address/checks.ts +123 -123
  100. package/src.ts/address/contract-address.ts +80 -80
  101. package/src.ts/address/index.ts +57 -57
  102. package/src.ts/constants/addresses.ts +8 -8
  103. package/src.ts/constants/hashes.ts +7 -7
  104. package/src.ts/constants/index.ts +16 -16
  105. package/src.ts/constants/numbers.ts +35 -35
  106. package/src.ts/constants/strings.ts +16 -16
  107. package/src.ts/contract/contract.ts +1120 -1120
  108. package/src.ts/contract/factory.ts +143 -143
  109. package/src.ts/contract/index.ts +31 -31
  110. package/src.ts/contract/types.ts +236 -236
  111. package/src.ts/contract/wrappers.ts +225 -225
  112. package/src.ts/crypto/crypto-browser.ts +64 -64
  113. package/src.ts/crypto/crypto.ts +4 -4
  114. package/src.ts/crypto/hmac.ts +51 -51
  115. package/src.ts/crypto/index.ts +59 -59
  116. package/src.ts/crypto/keccak.ts +54 -54
  117. package/src.ts/crypto/pbkdf2.ts +55 -55
  118. package/src.ts/crypto/random.ts +36 -36
  119. package/src.ts/crypto/ripemd160.ts +43 -43
  120. package/src.ts/crypto/scrypt.ts +114 -114
  121. package/src.ts/crypto/sha2.ts +78 -78
  122. package/src.ts/crypto/signature.ts +145 -349
  123. package/src.ts/crypto/signing-key.ts +126 -118
  124. package/src.ts/hash/authorization.ts +38 -38
  125. package/src.ts/hash/id.ts +17 -17
  126. package/src.ts/hash/index.ts +18 -18
  127. package/src.ts/hash/message.ts +51 -51
  128. package/src.ts/hash/namehash.ts +101 -101
  129. package/src.ts/hash/solidity.ts +117 -117
  130. package/src.ts/hash/typed-data.ts +658 -658
  131. package/src.ts/index.ts +12 -12
  132. package/src.ts/providers/abstract-provider.ts +1761 -1761
  133. package/src.ts/providers/abstract-signer.ts +314 -314
  134. package/src.ts/providers/community.ts +49 -49
  135. package/src.ts/providers/contracts.ts +42 -42
  136. package/src.ts/providers/default-provider.ts +96 -96
  137. package/src.ts/providers/ens-resolver.ts +606 -606
  138. package/src.ts/providers/format.ts +320 -320
  139. package/src.ts/providers/formatting.ts +418 -418
  140. package/src.ts/providers/index.ts +125 -125
  141. package/src.ts/providers/network.ts +327 -327
  142. package/src.ts/providers/pagination.ts +8 -8
  143. package/src.ts/providers/plugin-fallback.ts +35 -35
  144. package/src.ts/providers/plugins-network.ts +281 -281
  145. package/src.ts/providers/provider-browser.ts +334 -334
  146. package/src.ts/providers/provider-fallback.ts +801 -801
  147. package/src.ts/providers/provider-ipcsocket-browser.ts +3 -3
  148. package/src.ts/providers/provider-ipcsocket.ts +81 -81
  149. package/src.ts/providers/provider-jsonrpc.ts +1334 -1335
  150. package/src.ts/providers/provider-socket.ts +352 -352
  151. package/src.ts/providers/provider-websocket.ts +103 -103
  152. package/src.ts/providers/provider.ts +2136 -2136
  153. package/src.ts/providers/signer-noncemanager.ts +98 -98
  154. package/src.ts/providers/signer.ts +166 -166
  155. package/src.ts/providers/subscriber-connection.ts +74 -74
  156. package/src.ts/providers/subscriber-filterid.ts +199 -199
  157. package/src.ts/providers/subscriber-polling.ts +321 -321
  158. package/src.ts/providers/ws-browser.ts +11 -11
  159. package/src.ts/providers/ws.ts +3 -3
  160. package/src.ts/quantumcoin.ts +219 -211
  161. package/src.ts/thirdparty.d.ts +16 -16
  162. package/src.ts/transaction/accesslist.ts +43 -43
  163. package/src.ts/transaction/address.ts +35 -31
  164. package/src.ts/transaction/authorization.ts +14 -14
  165. package/src.ts/transaction/index.ts +51 -51
  166. package/src.ts/transaction/transaction.ts +1349 -1379
  167. package/src.ts/utils/base58.ts +73 -73
  168. package/src.ts/utils/base64-browser.ts +25 -25
  169. package/src.ts/utils/base64.ts +56 -56
  170. package/src.ts/utils/data.ts +199 -199
  171. package/src.ts/utils/errors.ts +793 -793
  172. package/src.ts/utils/events.ts +105 -105
  173. package/src.ts/utils/fetch.ts +970 -970
  174. package/src.ts/utils/fixednumber.ts +643 -643
  175. package/src.ts/utils/geturl-browser.ts +81 -81
  176. package/src.ts/utils/geturl.ts +134 -134
  177. package/src.ts/utils/index.ts +95 -95
  178. package/src.ts/utils/maths.ts +240 -240
  179. package/src.ts/utils/properties.ts +60 -60
  180. package/src.ts/utils/rlp-decode.ts +104 -104
  181. package/src.ts/utils/rlp-encode.ts +64 -64
  182. package/src.ts/utils/rlp.ts +20 -20
  183. package/src.ts/utils/units.ts +91 -91
  184. package/src.ts/utils/utf8.ts +325 -325
  185. package/src.ts/utils/uuid.ts +36 -36
  186. package/src.ts/wallet/base-wallet.ts +160 -160
  187. package/src.ts/wallet/index.ts +32 -32
  188. package/src.ts/wallet/json-keystore.ts +108 -106
  189. package/src.ts/wallet/utils.ts +147 -147
  190. package/src.ts/wallet/wallet.ts +138 -139
  191. package/src.ts/wordlists/bit-reader.ts +35 -35
  192. package/src.ts/wordlists/decode-owl.ts +58 -58
  193. package/src.ts/wordlists/decode-owla.ts +33 -33
  194. package/src.ts/wordlists/generation/encode-latin.ts +370 -370
  195. package/src.ts/wordlists/index.ts +26 -26
  196. package/src.ts/wordlists/lang-cz.ts +33 -33
  197. package/src.ts/wordlists/lang-en.ts +33 -33
  198. package/src.ts/wordlists/lang-es.ts +35 -35
  199. package/src.ts/wordlists/lang-fr.ts +34 -34
  200. package/src.ts/wordlists/lang-it.ts +33 -33
  201. package/src.ts/wordlists/lang-ja.ts +181 -181
  202. package/src.ts/wordlists/lang-ko.ts +104 -104
  203. package/src.ts/wordlists/lang-pt.ts +34 -34
  204. package/src.ts/wordlists/lang-zh.ts +112 -112
  205. package/src.ts/wordlists/wordlist-owl.ts +77 -77
  206. package/src.ts/wordlists/wordlist-owla.ts +41 -41
  207. package/src.ts/wordlists/wordlist.ts +59 -59
  208. package/src.ts/wordlists/wordlists-browser.ts +8 -8
  209. package/src.ts/wordlists/wordlists-extra.ts +9 -9
  210. package/src.ts/wordlists/wordlists.ts +38 -38
  211. package/dist/quantumcoin.min.js'.gz' +0 -0
  212. package/dist/quantumcoin.umd.min.js'.gz' +0 -0
  213. package/dist/wordlists-extra.min.js'.gz' +0 -0
  214. package/lib.commonjs/providers/provider-alchemy.d.ts +0 -50
  215. package/lib.commonjs/providers/provider-alchemy.d.ts.map +0 -1
  216. package/lib.commonjs/providers/provider-alchemy.js +0 -151
  217. package/lib.commonjs/providers/provider-alchemy.js.map +0 -1
  218. package/lib.commonjs/providers/provider-ankr.d.ts +0 -61
  219. package/lib.commonjs/providers/provider-ankr.d.ts.map +0 -1
  220. package/lib.commonjs/providers/provider-ankr.js +0 -137
  221. package/lib.commonjs/providers/provider-ankr.js.map +0 -1
  222. package/lib.commonjs/providers/provider-blockscout.d.ts +0 -59
  223. package/lib.commonjs/providers/provider-blockscout.d.ts.map +0 -1
  224. package/lib.commonjs/providers/provider-blockscout.js +0 -145
  225. package/lib.commonjs/providers/provider-blockscout.js.map +0 -1
  226. package/lib.commonjs/providers/provider-chainstack.d.ts +0 -46
  227. package/lib.commonjs/providers/provider-chainstack.d.ts.map +0 -1
  228. package/lib.commonjs/providers/provider-chainstack.js +0 -102
  229. package/lib.commonjs/providers/provider-chainstack.js.map +0 -1
  230. package/lib.commonjs/providers/provider-cloudflare.d.ts +0 -14
  231. package/lib.commonjs/providers/provider-cloudflare.d.ts.map +0 -1
  232. package/lib.commonjs/providers/provider-cloudflare.js +0 -26
  233. package/lib.commonjs/providers/provider-cloudflare.js.map +0 -1
  234. package/lib.commonjs/providers/provider-etherscan.d.ts +0 -147
  235. package/lib.commonjs/providers/provider-etherscan.d.ts.map +0 -1
  236. package/lib.commonjs/providers/provider-etherscan.js +0 -587
  237. package/lib.commonjs/providers/provider-etherscan.js.map +0 -1
  238. package/lib.commonjs/providers/provider-infura.d.ts +0 -101
  239. package/lib.commonjs/providers/provider-infura.d.ts.map +0 -1
  240. package/lib.commonjs/providers/provider-infura.js +0 -206
  241. package/lib.commonjs/providers/provider-infura.js.map +0 -1
  242. package/lib.commonjs/providers/provider-pocket.d.ts +0 -54
  243. package/lib.commonjs/providers/provider-pocket.d.ts.map +0 -1
  244. package/lib.commonjs/providers/provider-pocket.js +0 -109
  245. package/lib.commonjs/providers/provider-pocket.js.map +0 -1
  246. package/lib.commonjs/providers/provider-quicknode.d.ts +0 -59
  247. package/lib.commonjs/providers/provider-quicknode.d.ts.map +0 -1
  248. package/lib.commonjs/providers/provider-quicknode.js +0 -163
  249. package/lib.commonjs/providers/provider-quicknode.js.map +0 -1
  250. package/lib.commonjs/wallet/hdwallet.d.ts +0 -248
  251. package/lib.commonjs/wallet/hdwallet.d.ts.map +0 -1
  252. package/lib.commonjs/wallet/hdwallet.js +0 -505
  253. package/lib.commonjs/wallet/hdwallet.js.map +0 -1
  254. package/lib.commonjs/wallet/json-crowdsale.d.ts +0 -27
  255. package/lib.commonjs/wallet/json-crowdsale.d.ts.map +0 -1
  256. package/lib.commonjs/wallet/json-crowdsale.js +0 -60
  257. package/lib.commonjs/wallet/json-crowdsale.js.map +0 -1
  258. package/lib.commonjs/wallet/mnemonic.d.ts +0 -65
  259. package/lib.commonjs/wallet/mnemonic.d.ts.map +0 -1
  260. package/lib.commonjs/wallet/mnemonic.js +0 -169
  261. package/lib.commonjs/wallet/mnemonic.js.map +0 -1
  262. package/lib.commonjs/wallet/seedwallet.d.ts +0 -4
  263. package/lib.commonjs/wallet/seedwallet.d.ts.map +0 -1
  264. package/lib.commonjs/wallet/seedwallet.js +0 -8
  265. package/lib.commonjs/wallet/seedwallet.js.map +0 -1
  266. package/lib.esm/providers/provider-alchemy.d.ts +0 -50
  267. package/lib.esm/providers/provider-alchemy.d.ts.map +0 -1
  268. package/lib.esm/providers/provider-alchemy.js +0 -147
  269. package/lib.esm/providers/provider-alchemy.js.map +0 -1
  270. package/lib.esm/providers/provider-ankr.d.ts +0 -61
  271. package/lib.esm/providers/provider-ankr.d.ts.map +0 -1
  272. package/lib.esm/providers/provider-ankr.js +0 -133
  273. package/lib.esm/providers/provider-ankr.js.map +0 -1
  274. package/lib.esm/providers/provider-blockscout.d.ts +0 -59
  275. package/lib.esm/providers/provider-blockscout.d.ts.map +0 -1
  276. package/lib.esm/providers/provider-blockscout.js +0 -141
  277. package/lib.esm/providers/provider-blockscout.js.map +0 -1
  278. package/lib.esm/providers/provider-chainstack.d.ts +0 -46
  279. package/lib.esm/providers/provider-chainstack.d.ts.map +0 -1
  280. package/lib.esm/providers/provider-chainstack.js +0 -98
  281. package/lib.esm/providers/provider-chainstack.js.map +0 -1
  282. package/lib.esm/providers/provider-cloudflare.d.ts +0 -14
  283. package/lib.esm/providers/provider-cloudflare.d.ts.map +0 -1
  284. package/lib.esm/providers/provider-cloudflare.js +0 -22
  285. package/lib.esm/providers/provider-cloudflare.js.map +0 -1
  286. package/lib.esm/providers/provider-etherscan.d.ts +0 -147
  287. package/lib.esm/providers/provider-etherscan.d.ts.map +0 -1
  288. package/lib.esm/providers/provider-etherscan.js +0 -584
  289. package/lib.esm/providers/provider-etherscan.js.map +0 -1
  290. package/lib.esm/providers/provider-infura.d.ts +0 -101
  291. package/lib.esm/providers/provider-infura.d.ts.map +0 -1
  292. package/lib.esm/providers/provider-infura.js +0 -201
  293. package/lib.esm/providers/provider-infura.js.map +0 -1
  294. package/lib.esm/providers/provider-pocket.d.ts +0 -54
  295. package/lib.esm/providers/provider-pocket.d.ts.map +0 -1
  296. package/lib.esm/providers/provider-pocket.js +0 -105
  297. package/lib.esm/providers/provider-pocket.js.map +0 -1
  298. package/lib.esm/providers/provider-quicknode.d.ts +0 -59
  299. package/lib.esm/providers/provider-quicknode.d.ts.map +0 -1
  300. package/lib.esm/providers/provider-quicknode.js +0 -159
  301. package/lib.esm/providers/provider-quicknode.js.map +0 -1
  302. package/lib.esm/wallet/hdwallet.d.ts +0 -248
  303. package/lib.esm/wallet/hdwallet.d.ts.map +0 -1
  304. package/lib.esm/wallet/hdwallet.js +0 -498
  305. package/lib.esm/wallet/hdwallet.js.map +0 -1
  306. package/lib.esm/wallet/json-crowdsale.d.ts +0 -27
  307. package/lib.esm/wallet/json-crowdsale.d.ts.map +0 -1
  308. package/lib.esm/wallet/json-crowdsale.js +0 -55
  309. package/lib.esm/wallet/json-crowdsale.js.map +0 -1
  310. package/lib.esm/wallet/mnemonic.d.ts +0 -65
  311. package/lib.esm/wallet/mnemonic.d.ts.map +0 -1
  312. package/lib.esm/wallet/mnemonic.js +0 -165
  313. package/lib.esm/wallet/mnemonic.js.map +0 -1
  314. package/lib.esm/wallet/seedwallet.d.ts +0 -4
  315. package/lib.esm/wallet/seedwallet.d.ts.map +0 -1
  316. package/lib.esm/wallet/seedwallet.js +0 -4
  317. package/lib.esm/wallet/seedwallet.js.map +0 -1
@@ -1,541 +1,541 @@
1
-
2
- import {
3
- defineProperties, concat, getBytesCopy, getNumber, hexlify,
4
- toBeArray, toBigInt, toNumber,
5
- assert, assertArgument
6
- /*, isError*/
7
- } from "../../utils/index.js";
8
-
9
- import type { BigNumberish, BytesLike } from "../../utils/index.js";
10
-
11
- /**
12
- * @_ignore:
13
- */
14
- export const WordSize: number = 32;
15
- const Padding = new Uint8Array(WordSize);
16
-
17
- // Properties used to immediate pass through to the underlying object
18
- // - `then` is used to detect if an object is a Promise for await
19
- const passProperties = [ "then" ];
20
-
21
- const _guard = { };
22
-
23
- const resultNames: WeakMap<Result, ReadonlyArray<null | string>> = new WeakMap();
24
-
25
- function getNames(result: Result): ReadonlyArray<null | string> {
26
- return resultNames.get(result)!;
27
- }
28
- function setNames(result: Result, names: ReadonlyArray<null | string>): void {
29
- resultNames.set(result, names);
30
- }
31
-
32
- function throwError(name: string, error: Error): never {
33
- const wrapped = new Error(`deferred error during ABI decoding triggered accessing ${ name }`);
34
- (<any>wrapped).error = error;
35
- throw wrapped;
36
- }
37
-
38
- function toObject(names: ReadonlyArray<null | string>, items: Result, deep?: boolean): Record<string, any> | Array<any> {
39
- if (names.indexOf(null) >= 0) {
40
- return items.map((item, index) => {
41
- if (item instanceof Result) {
42
- return toObject(getNames(item), item, deep);
43
- }
44
- return item;
45
- });
46
- }
47
-
48
- return (<Array<string>>names).reduce((accum, name, index) => {
49
- let item = items.getValue(name);
50
- if (!(name in accum)) {
51
- if (deep && item instanceof Result) {
52
- item = toObject(getNames(item), item, deep);
53
- }
54
- accum[name] = item;
55
- }
56
- return accum;
57
- }, <Record<string, any>>{ });
58
- }
59
-
60
-
61
- /**
62
- * A [[Result]] is a sub-class of Array, which allows accessing any
63
- * of its values either positionally by its index or, if keys are
64
- * provided by its name.
65
- *
66
- * @_docloc: api/abi
67
- */
68
- export class Result extends Array<any> {
69
- // No longer used; but cannot be removed as it will remove the
70
- // #private field from the .d.ts which may break backwards
71
- // compatibility
72
- readonly #names: ReadonlyArray<null | string>;
73
-
74
- [ K: string | number ]: any
75
-
76
- /**
77
- * @private
78
- */
79
- constructor(...args: Array<any>) {
80
- // To properly sub-class Array so the other built-in
81
- // functions work, the constructor has to behave fairly
82
- // well. So, in the event we are created via fromItems()
83
- // we build the read-only Result object we want, but on
84
- // any other input, we use the default constructor
85
-
86
- // constructor(guard: any, items: Array<any>, keys?: Array<null | string>);
87
- const guard = args[0];
88
- let items: Array<any> = args[1];
89
- let names: Array<null | string> = (args[2] || [ ]).slice();
90
-
91
- let wrap = true;
92
- if (guard !== _guard) {
93
- items = args;
94
- names = [ ];
95
- wrap = false;
96
- }
97
-
98
- // Can't just pass in ...items since an array of length 1
99
- // is a special case in the super.
100
- super(items.length);
101
- items.forEach((item, index) => { this[index] = item; });
102
-
103
- // Find all unique keys
104
- const nameCounts = names.reduce((accum, name) => {
105
- if (typeof(name) === "string") {
106
- accum.set(name, (accum.get(name) || 0) + 1);
107
- }
108
- return accum;
109
- }, <Map<string, number>>(new Map()));
110
-
111
- // Remove any key thats not unique
112
- setNames(this, Object.freeze(items.map((item, index) => {
113
- const name = names[index];
114
- if (name != null && nameCounts.get(name) === 1) {
115
- return name;
116
- }
117
- return null;
118
- })));
119
-
120
- // Dummy operations to prevent TypeScript from complaining
121
- this.#names = [ ];
122
- if (this.#names == null) { void(this.#names); }
123
-
124
- if (!wrap) { return; }
125
-
126
- // A wrapped Result is immutable
127
- Object.freeze(this);
128
-
129
- // Proxy indices and names so we can trap deferred errors
130
- const proxy = new Proxy(this, {
131
- get: (target, prop, receiver) => {
132
- if (typeof(prop) === "string") {
133
-
134
- // Index accessor
135
- if (prop.match(/^[0-9]+$/)) {
136
- const index = getNumber(prop, "%index");
137
- if (index < 0 || index >= this.length) {
138
- throw new RangeError("out of result range");
139
- }
140
-
141
- const item = target[index];
142
- if (item instanceof Error) {
143
- throwError(`index ${ index }`, item);
144
- }
145
- return item;
146
- }
147
-
148
- // Pass important checks (like `then` for Promise) through
149
- if (passProperties.indexOf(prop) >= 0) {
150
- return Reflect.get(target, prop, receiver);
151
- }
152
-
153
- const value = target[prop];
154
- if (value instanceof Function) {
155
- // Make sure functions work with private variables
156
- // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#no_private_property_forwarding
157
- return function(this: any, ...args: Array<any>) {
158
- return value.apply((this === receiver) ? target: this, args);
159
- };
160
-
161
- } else if (!(prop in target)) {
162
- // Possible name accessor
163
- return target.getValue.apply((this === receiver) ? target: this, [ prop ]);
164
- }
165
- }
166
-
167
- return Reflect.get(target, prop, receiver);
168
- }
169
- });
170
- setNames(proxy, getNames(this));
171
- return proxy;
172
- }
173
-
174
- /**
175
- * Returns the Result as a normal Array. If %%deep%%, any children
176
- * which are Result objects are also converted to a normal Array.
177
- *
178
- * This will throw if there are any outstanding deferred
179
- * errors.
180
- */
181
- toArray(deep?: boolean): Array<any> {
182
- const result: Array<any> = [ ];
183
- this.forEach((item, index) => {
184
- if (item instanceof Error) { throwError(`index ${ index }`, item); }
185
- if (deep && item instanceof Result) {
186
- item = item.toArray(deep);
187
- }
188
- result.push(item);
189
- });
190
- return result;
191
- }
192
-
193
- /**
194
- * Returns the Result as an Object with each name-value pair. If
195
- * %%deep%%, any children which are Result objects are also
196
- * converted to an Object.
197
- *
198
- * This will throw if any value is unnamed, or if there are
199
- * any outstanding deferred errors.
200
- */
201
- toObject(deep?: boolean): Record<string, any> {
202
- const names = getNames(this);
203
- return names.reduce((accum, name, index) => {
204
-
205
- assert(name != null, `value at index ${ index } unnamed`, "UNSUPPORTED_OPERATION", {
206
- operation: "toObject()"
207
- });
208
-
209
- return toObject(names, this, deep);
210
- }, <Record<string, any>>{});
211
- }
212
-
213
- /**
214
- * @_ignore
215
- */
216
- slice(start?: number | undefined, end?: number | undefined): Result {
217
- if (start == null) { start = 0; }
218
- if (start < 0) {
219
- start += this.length;
220
- if (start < 0) { start = 0; }
221
- }
222
-
223
- if (end == null) { end = this.length; }
224
- if (end < 0) {
225
- end += this.length;
226
- if (end < 0) { end = 0; }
227
- }
228
- if (end > this.length) { end = this.length; }
229
-
230
- const _names = getNames(this);
231
-
232
- const result: Array<any> = [ ], names: Array<null | string> = [ ];
233
- for (let i = start; i < end; i++) {
234
- result.push(this[i]);
235
- names.push(_names[i]);
236
- }
237
-
238
- return new Result(_guard, result, names);
239
- }
240
-
241
- /**
242
- * @_ignore
243
- */
244
- filter(callback: (el: any, index: number, array: Result) => boolean, thisArg?: any): Result {
245
- const _names = getNames(this);
246
-
247
- const result: Array<any> = [ ], names: Array<null | string> = [ ];
248
- for (let i = 0; i < this.length; i++) {
249
- const item = this[i];
250
- if (item instanceof Error) {
251
- throwError(`index ${ i }`, item);
252
- }
253
-
254
- if (callback.call(thisArg, item, i, this)) {
255
- result.push(item);
256
- names.push(_names[i]);
257
- }
258
- }
259
-
260
- return new Result(_guard, result, names);
261
- }
262
-
263
- /**
264
- * @_ignore
265
- */
266
- map<T extends any = any>(callback: (el: any, index: number, array: Result) => T, thisArg?: any): Array<T> {
267
- const result: Array<T> = [ ];
268
- for (let i = 0; i < this.length; i++) {
269
- const item = this[i];
270
- if (item instanceof Error) {
271
- throwError(`index ${ i }`, item);
272
- }
273
-
274
- result.push(callback.call(thisArg, item, i, this));
275
- }
276
-
277
- return result;
278
- }
279
-
280
-
281
- /**
282
- * Returns the value for %%name%%.
283
- *
284
- * Since it is possible to have a key whose name conflicts with
285
- * a method on a [[Result]] or its superclass Array, or any
286
- * JavaScript keyword, this ensures all named values are still
287
- * accessible by name.
288
- */
289
- getValue(name: string): any {
290
- const index = getNames(this).indexOf(name);
291
- if (index === -1) { return undefined; }
292
-
293
- const value = this[index];
294
-
295
- if (value instanceof Error) {
296
- throwError(`property ${ JSON.stringify(name) }`, (<any>value).error);
297
- }
298
-
299
- return value;
300
- }
301
-
302
- /**
303
- * Creates a new [[Result]] for %%items%% with each entry
304
- * also accessible by its corresponding name in %%keys%%.
305
- */
306
- static fromItems(items: Array<any>, keys?: Array<null | string>): Result {
307
- return new Result(_guard, items, keys);
308
- }
309
- }
310
-
311
- /**
312
- * Returns all errors found in a [[Result]].
313
- *
314
- * Since certain errors encountered when creating a [[Result]] do
315
- * not impact the ability to continue parsing data, they are
316
- * deferred until they are actually accessed. Hence a faulty string
317
- * in an Event that is never used does not impact the program flow.
318
- *
319
- * However, sometimes it may be useful to access, identify or
320
- * validate correctness of a [[Result]].
321
- *
322
- * @_docloc api/abi
323
- */
324
- export function checkResultErrors(result: Result): Array<{ path: Array<string | number>, error: Error }> {
325
- // Find the first error (if any)
326
- const errors: Array<{ path: Array<string | number>, error: Error }> = [ ];
327
-
328
- const checkErrors = function(path: Array<string | number>, object: any): void {
329
- if (!Array.isArray(object)) { return; }
330
- for (let key in object) {
331
- const childPath = path.slice();
332
- childPath.push(key);
333
-
334
- try {
335
- checkErrors(childPath, object[key]);
336
- } catch (error: any) {
337
- errors.push({ path: childPath, error: error });
338
- }
339
- }
340
- }
341
- checkErrors([ ], result);
342
-
343
- return errors;
344
-
345
- }
346
-
347
- function getValue(value: BigNumberish): Uint8Array {
348
- let bytes = toBeArray(value);
349
-
350
- assert (bytes.length <= WordSize, "value out-of-bounds",
351
- "BUFFER_OVERRUN", { buffer: bytes, length: WordSize, offset: bytes.length });
352
-
353
- if (bytes.length !== WordSize) {
354
- bytes = getBytesCopy(concat([ Padding.slice(bytes.length % WordSize), bytes ]));
355
- }
356
-
357
- return bytes;
358
- }
359
-
360
- /**
361
- * @_ignore
362
- */
363
- export abstract class Coder {
364
-
365
- // The coder name:
366
- // - address, uint256, tuple, array, etc.
367
- readonly name!: string;
368
-
369
- // The fully expanded type, including composite types:
370
- // - address, uint256, tuple(address,bytes), uint256[3][4][], etc.
371
- readonly type!: string;
372
-
373
- // The localName bound in the signature, in this example it is "baz":
374
- // - tuple(address foo, uint bar) baz
375
- readonly localName!: string;
376
-
377
- // Whether this type is dynamic:
378
- // - Dynamic: bytes, string, address[], tuple(boolean[]), etc.
379
- // - Not Dynamic: address, uint256, boolean[3], tuple(address, uint8)
380
- readonly dynamic!: boolean;
381
-
382
- constructor(name: string, type: string, localName: string, dynamic: boolean) {
383
- defineProperties<Coder>(this, { name, type, localName, dynamic }, {
384
- name: "string", type: "string", localName: "string", dynamic: "boolean"
385
- });
386
- }
387
-
388
- _throwError(message: string, value: any): never {
389
- assertArgument(false, message, this.localName, value);
390
- }
391
-
392
- abstract encode(writer: Writer, value: any): number;
393
- abstract decode(reader: Reader): any;
394
-
395
- abstract defaultValue(): any;
396
- }
397
-
398
- /**
399
- * @_ignore
400
- */
401
- export class Writer {
402
- // An array of WordSize lengthed objects to concatenation
403
- #data: Array<Uint8Array>;
404
- #dataLength: number;
405
-
406
- constructor() {
407
- this.#data = [ ];
408
- this.#dataLength = 0;
409
- }
410
-
411
- get data(): string {
412
- return concat(this.#data);
413
- }
414
- get length(): number { return this.#dataLength; }
415
-
416
- #writeData(data: Uint8Array): number {
417
- this.#data.push(data);
418
- this.#dataLength += data.length;
419
- return data.length;
420
- }
421
-
422
- appendWriter(writer: Writer): number {
423
- return this.#writeData(getBytesCopy(writer.data));
424
- }
425
-
426
- // Arrayish item; pad on the right to *nearest* WordSize
427
- writeBytes(value: BytesLike): number {
428
- let bytes = getBytesCopy(value);
429
- const paddingOffset = bytes.length % WordSize;
430
- if (paddingOffset) {
431
- bytes = getBytesCopy(concat([ bytes, Padding.slice(paddingOffset) ]))
432
- }
433
- return this.#writeData(bytes);
434
- }
435
-
436
- // Numeric item; pad on the left *to* WordSize
437
- writeValue(value: BigNumberish): number {
438
- return this.#writeData(getValue(value));
439
- }
440
-
441
- // Inserts a numeric place-holder, returning a callback that can
442
- // be used to asjust the value later
443
- writeUpdatableValue(): (value: BigNumberish) => void {
444
- const offset = this.#data.length;
445
- this.#data.push(Padding);
446
- this.#dataLength += WordSize;
447
- return (value: BigNumberish) => {
448
- this.#data[offset] = getValue(value);
449
- };
450
- }
451
- }
452
-
453
- /**
454
- * @_ignore
455
- */
456
- export class Reader {
457
- // Allows incomplete unpadded data to be read; otherwise an error
458
- // is raised if attempting to overrun the buffer. This is required
459
- // to deal with an old Solidity bug, in which event data for
460
- // external (not public thoguh) was tightly packed.
461
- readonly allowLoose!: boolean;
462
-
463
- readonly #data: Uint8Array;
464
- #offset: number;
465
-
466
- #bytesRead: number;
467
- #parent: null | Reader;
468
- #maxInflation: number;
469
-
470
- constructor(data: BytesLike, allowLoose?: boolean, maxInflation?: number) {
471
- defineProperties<Reader>(this, { allowLoose: !!allowLoose });
472
-
473
- this.#data = getBytesCopy(data);
474
- this.#bytesRead = 0;
475
- this.#parent = null;
476
- this.#maxInflation = (maxInflation != null) ? maxInflation: 1024;
477
-
478
- this.#offset = 0;
479
- }
480
-
481
- get data(): string { return hexlify(this.#data); }
482
- get dataLength(): number { return this.#data.length; }
483
- get consumed(): number { return this.#offset; }
484
- get bytes(): Uint8Array { return new Uint8Array(this.#data); }
485
-
486
- #incrementBytesRead(count: number): void {
487
- if (this.#parent) { return this.#parent.#incrementBytesRead(count); }
488
-
489
- this.#bytesRead += count;
490
-
491
- // Check for excessive inflation (see: #4537)
492
- assert(this.#maxInflation < 1 || this.#bytesRead <= this.#maxInflation * this.dataLength, `compressed ABI data exceeds inflation ratio of ${ this.#maxInflation } ( see: https:/\/github.com/ethers-io/ethers.js/issues/4537 )`, "BUFFER_OVERRUN", {
493
- buffer: getBytesCopy(this.#data), offset: this.#offset,
494
- length: count, info: {
495
- bytesRead: this.#bytesRead,
496
- dataLength: this.dataLength
497
- }
498
- });
499
- }
500
-
501
- #peekBytes(offset: number, length: number, loose?: boolean): Uint8Array {
502
- let alignedLength = Math.ceil(length / WordSize) * WordSize;
503
- if (this.#offset + alignedLength > this.#data.length) {
504
- if (this.allowLoose && loose && this.#offset + length <= this.#data.length) {
505
- alignedLength = length;
506
- } else {
507
- assert(false, "data out-of-bounds", "BUFFER_OVERRUN", {
508
- buffer: getBytesCopy(this.#data),
509
- length: this.#data.length,
510
- offset: this.#offset + alignedLength
511
- });
512
- }
513
- }
514
- return this.#data.slice(this.#offset, this.#offset + alignedLength)
515
- }
516
-
517
- // Create a sub-reader with the same underlying data, but offset
518
- subReader(offset: number): Reader {
519
- const reader = new Reader(this.#data.slice(this.#offset + offset), this.allowLoose, this.#maxInflation);
520
- reader.#parent = this;
521
- return reader;
522
- }
523
-
524
- // Read bytes
525
- readBytes(length: number, loose?: boolean): Uint8Array {
526
- let bytes = this.#peekBytes(0, length, !!loose);
527
- this.#incrementBytesRead(length);
528
- this.#offset += bytes.length;
529
- // @TODO: Make sure the length..end bytes are all 0?
530
- return bytes.slice(0, length);
531
- }
532
-
533
- // Read a numeric values
534
- readValue(): bigint {
535
- return toBigInt(this.readBytes(WordSize));
536
- }
537
-
538
- readIndex(): number {
539
- return toNumber(this.readBytes(WordSize));
540
- }
541
- }
1
+
2
+ import {
3
+ defineProperties, concat, getBytesCopy, getNumber, hexlify,
4
+ toBeArray, toBigInt, toNumber,
5
+ assert, assertArgument
6
+ /*, isError*/
7
+ } from "../../utils/index.js";
8
+
9
+ import type { BigNumberish, BytesLike } from "../../utils/index.js";
10
+
11
+ /**
12
+ * @_ignore:
13
+ */
14
+ export const WordSize: number = 32;
15
+ const Padding = new Uint8Array(WordSize);
16
+
17
+ // Properties used to immediate pass through to the underlying object
18
+ // - `then` is used to detect if an object is a Promise for await
19
+ const passProperties = [ "then" ];
20
+
21
+ const _guard = { };
22
+
23
+ const resultNames: WeakMap<Result, ReadonlyArray<null | string>> = new WeakMap();
24
+
25
+ function getNames(result: Result): ReadonlyArray<null | string> {
26
+ return resultNames.get(result)!;
27
+ }
28
+ function setNames(result: Result, names: ReadonlyArray<null | string>): void {
29
+ resultNames.set(result, names);
30
+ }
31
+
32
+ function throwError(name: string, error: Error): never {
33
+ const wrapped = new Error(`deferred error during ABI decoding triggered accessing ${ name }`);
34
+ (<any>wrapped).error = error;
35
+ throw wrapped;
36
+ }
37
+
38
+ function toObject(names: ReadonlyArray<null | string>, items: Result, deep?: boolean): Record<string, any> | Array<any> {
39
+ if (names.indexOf(null) >= 0) {
40
+ return items.map((item, index) => {
41
+ if (item instanceof Result) {
42
+ return toObject(getNames(item), item, deep);
43
+ }
44
+ return item;
45
+ });
46
+ }
47
+
48
+ return (<Array<string>>names).reduce((accum, name, index) => {
49
+ let item = items.getValue(name);
50
+ if (!(name in accum)) {
51
+ if (deep && item instanceof Result) {
52
+ item = toObject(getNames(item), item, deep);
53
+ }
54
+ accum[name] = item;
55
+ }
56
+ return accum;
57
+ }, <Record<string, any>>{ });
58
+ }
59
+
60
+
61
+ /**
62
+ * A [[Result]] is a sub-class of Array, which allows accessing any
63
+ * of its values either positionally by its index or, if keys are
64
+ * provided by its name.
65
+ *
66
+ * @_docloc: api/abi
67
+ */
68
+ export class Result extends Array<any> {
69
+ // No longer used; but cannot be removed as it will remove the
70
+ // #private field from the .d.ts which may break backwards
71
+ // compatibility
72
+ readonly #names: ReadonlyArray<null | string>;
73
+
74
+ [ K: string | number ]: any
75
+
76
+ /**
77
+ * @private
78
+ */
79
+ constructor(...args: Array<any>) {
80
+ // To properly sub-class Array so the other built-in
81
+ // functions work, the constructor has to behave fairly
82
+ // well. So, in the event we are created via fromItems()
83
+ // we build the read-only Result object we want, but on
84
+ // any other input, we use the default constructor
85
+
86
+ // constructor(guard: any, items: Array<any>, keys?: Array<null | string>);
87
+ const guard = args[0];
88
+ let items: Array<any> = args[1];
89
+ let names: Array<null | string> = (args[2] || [ ]).slice();
90
+
91
+ let wrap = true;
92
+ if (guard !== _guard) {
93
+ items = args;
94
+ names = [ ];
95
+ wrap = false;
96
+ }
97
+
98
+ // Can't just pass in ...items since an array of length 1
99
+ // is a special case in the super.
100
+ super(items.length);
101
+ items.forEach((item, index) => { this[index] = item; });
102
+
103
+ // Find all unique keys
104
+ const nameCounts = names.reduce((accum, name) => {
105
+ if (typeof(name) === "string") {
106
+ accum.set(name, (accum.get(name) || 0) + 1);
107
+ }
108
+ return accum;
109
+ }, <Map<string, number>>(new Map()));
110
+
111
+ // Remove any key thats not unique
112
+ setNames(this, Object.freeze(items.map((item, index) => {
113
+ const name = names[index];
114
+ if (name != null && nameCounts.get(name) === 1) {
115
+ return name;
116
+ }
117
+ return null;
118
+ })));
119
+
120
+ // Dummy operations to prevent TypeScript from complaining
121
+ this.#names = [ ];
122
+ if (this.#names == null) { void(this.#names); }
123
+
124
+ if (!wrap) { return; }
125
+
126
+ // A wrapped Result is immutable
127
+ Object.freeze(this);
128
+
129
+ // Proxy indices and names so we can trap deferred errors
130
+ const proxy = new Proxy(this, {
131
+ get: (target, prop, receiver) => {
132
+ if (typeof(prop) === "string") {
133
+
134
+ // Index accessor
135
+ if (prop.match(/^[0-9]+$/)) {
136
+ const index = getNumber(prop, "%index");
137
+ if (index < 0 || index >= this.length) {
138
+ throw new RangeError("out of result range");
139
+ }
140
+
141
+ const item = target[index];
142
+ if (item instanceof Error) {
143
+ throwError(`index ${ index }`, item);
144
+ }
145
+ return item;
146
+ }
147
+
148
+ // Pass important checks (like `then` for Promise) through
149
+ if (passProperties.indexOf(prop) >= 0) {
150
+ return Reflect.get(target, prop, receiver);
151
+ }
152
+
153
+ const value = target[prop];
154
+ if (value instanceof Function) {
155
+ // Make sure functions work with private variables
156
+ // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy#no_private_property_forwarding
157
+ return function(this: any, ...args: Array<any>) {
158
+ return value.apply((this === receiver) ? target: this, args);
159
+ };
160
+
161
+ } else if (!(prop in target)) {
162
+ // Possible name accessor
163
+ return target.getValue.apply((this === receiver) ? target: this, [ prop ]);
164
+ }
165
+ }
166
+
167
+ return Reflect.get(target, prop, receiver);
168
+ }
169
+ });
170
+ setNames(proxy, getNames(this));
171
+ return proxy;
172
+ }
173
+
174
+ /**
175
+ * Returns the Result as a normal Array. If %%deep%%, any children
176
+ * which are Result objects are also converted to a normal Array.
177
+ *
178
+ * This will throw if there are any outstanding deferred
179
+ * errors.
180
+ */
181
+ toArray(deep?: boolean): Array<any> {
182
+ const result: Array<any> = [ ];
183
+ this.forEach((item, index) => {
184
+ if (item instanceof Error) { throwError(`index ${ index }`, item); }
185
+ if (deep && item instanceof Result) {
186
+ item = item.toArray(deep);
187
+ }
188
+ result.push(item);
189
+ });
190
+ return result;
191
+ }
192
+
193
+ /**
194
+ * Returns the Result as an Object with each name-value pair. If
195
+ * %%deep%%, any children which are Result objects are also
196
+ * converted to an Object.
197
+ *
198
+ * This will throw if any value is unnamed, or if there are
199
+ * any outstanding deferred errors.
200
+ */
201
+ toObject(deep?: boolean): Record<string, any> {
202
+ const names = getNames(this);
203
+ return names.reduce((accum, name, index) => {
204
+
205
+ assert(name != null, `value at index ${ index } unnamed`, "UNSUPPORTED_OPERATION", {
206
+ operation: "toObject()"
207
+ });
208
+
209
+ return toObject(names, this, deep);
210
+ }, <Record<string, any>>{});
211
+ }
212
+
213
+ /**
214
+ * @_ignore
215
+ */
216
+ slice(start?: number | undefined, end?: number | undefined): Result {
217
+ if (start == null) { start = 0; }
218
+ if (start < 0) {
219
+ start += this.length;
220
+ if (start < 0) { start = 0; }
221
+ }
222
+
223
+ if (end == null) { end = this.length; }
224
+ if (end < 0) {
225
+ end += this.length;
226
+ if (end < 0) { end = 0; }
227
+ }
228
+ if (end > this.length) { end = this.length; }
229
+
230
+ const _names = getNames(this);
231
+
232
+ const result: Array<any> = [ ], names: Array<null | string> = [ ];
233
+ for (let i = start; i < end; i++) {
234
+ result.push(this[i]);
235
+ names.push(_names[i]);
236
+ }
237
+
238
+ return new Result(_guard, result, names);
239
+ }
240
+
241
+ /**
242
+ * @_ignore
243
+ */
244
+ filter(callback: (el: any, index: number, array: Result) => boolean, thisArg?: any): Result {
245
+ const _names = getNames(this);
246
+
247
+ const result: Array<any> = [ ], names: Array<null | string> = [ ];
248
+ for (let i = 0; i < this.length; i++) {
249
+ const item = this[i];
250
+ if (item instanceof Error) {
251
+ throwError(`index ${ i }`, item);
252
+ }
253
+
254
+ if (callback.call(thisArg, item, i, this)) {
255
+ result.push(item);
256
+ names.push(_names[i]);
257
+ }
258
+ }
259
+
260
+ return new Result(_guard, result, names);
261
+ }
262
+
263
+ /**
264
+ * @_ignore
265
+ */
266
+ map<T extends any = any>(callback: (el: any, index: number, array: Result) => T, thisArg?: any): Array<T> {
267
+ const result: Array<T> = [ ];
268
+ for (let i = 0; i < this.length; i++) {
269
+ const item = this[i];
270
+ if (item instanceof Error) {
271
+ throwError(`index ${ i }`, item);
272
+ }
273
+
274
+ result.push(callback.call(thisArg, item, i, this));
275
+ }
276
+
277
+ return result;
278
+ }
279
+
280
+
281
+ /**
282
+ * Returns the value for %%name%%.
283
+ *
284
+ * Since it is possible to have a key whose name conflicts with
285
+ * a method on a [[Result]] or its superclass Array, or any
286
+ * JavaScript keyword, this ensures all named values are still
287
+ * accessible by name.
288
+ */
289
+ getValue(name: string): any {
290
+ const index = getNames(this).indexOf(name);
291
+ if (index === -1) { return undefined; }
292
+
293
+ const value = this[index];
294
+
295
+ if (value instanceof Error) {
296
+ throwError(`property ${ JSON.stringify(name) }`, (<any>value).error);
297
+ }
298
+
299
+ return value;
300
+ }
301
+
302
+ /**
303
+ * Creates a new [[Result]] for %%items%% with each entry
304
+ * also accessible by its corresponding name in %%keys%%.
305
+ */
306
+ static fromItems(items: Array<any>, keys?: Array<null | string>): Result {
307
+ return new Result(_guard, items, keys);
308
+ }
309
+ }
310
+
311
+ /**
312
+ * Returns all errors found in a [[Result]].
313
+ *
314
+ * Since certain errors encountered when creating a [[Result]] do
315
+ * not impact the ability to continue parsing data, they are
316
+ * deferred until they are actually accessed. Hence a faulty string
317
+ * in an Event that is never used does not impact the program flow.
318
+ *
319
+ * However, sometimes it may be useful to access, identify or
320
+ * validate correctness of a [[Result]].
321
+ *
322
+ * @_docloc api/abi
323
+ */
324
+ export function checkResultErrors(result: Result): Array<{ path: Array<string | number>, error: Error }> {
325
+ // Find the first error (if any)
326
+ const errors: Array<{ path: Array<string | number>, error: Error }> = [ ];
327
+
328
+ const checkErrors = function(path: Array<string | number>, object: any): void {
329
+ if (!Array.isArray(object)) { return; }
330
+ for (let key in object) {
331
+ const childPath = path.slice();
332
+ childPath.push(key);
333
+
334
+ try {
335
+ checkErrors(childPath, object[key]);
336
+ } catch (error: any) {
337
+ errors.push({ path: childPath, error: error });
338
+ }
339
+ }
340
+ }
341
+ checkErrors([ ], result);
342
+
343
+ return errors;
344
+
345
+ }
346
+
347
+ function getValue(value: BigNumberish): Uint8Array {
348
+ let bytes = toBeArray(value);
349
+
350
+ assert (bytes.length <= WordSize, "value out-of-bounds",
351
+ "BUFFER_OVERRUN", { buffer: bytes, length: WordSize, offset: bytes.length });
352
+
353
+ if (bytes.length !== WordSize) {
354
+ bytes = getBytesCopy(concat([ Padding.slice(bytes.length % WordSize), bytes ]));
355
+ }
356
+
357
+ return bytes;
358
+ }
359
+
360
+ /**
361
+ * @_ignore
362
+ */
363
+ export abstract class Coder {
364
+
365
+ // The coder name:
366
+ // - address, uint256, tuple, array, etc.
367
+ readonly name!: string;
368
+
369
+ // The fully expanded type, including composite types:
370
+ // - address, uint256, tuple(address,bytes), uint256[3][4][], etc.
371
+ readonly type!: string;
372
+
373
+ // The localName bound in the signature, in this example it is "baz":
374
+ // - tuple(address foo, uint bar) baz
375
+ readonly localName!: string;
376
+
377
+ // Whether this type is dynamic:
378
+ // - Dynamic: bytes, string, address[], tuple(boolean[]), etc.
379
+ // - Not Dynamic: address, uint256, boolean[3], tuple(address, uint8)
380
+ readonly dynamic!: boolean;
381
+
382
+ constructor(name: string, type: string, localName: string, dynamic: boolean) {
383
+ defineProperties<Coder>(this, { name, type, localName, dynamic }, {
384
+ name: "string", type: "string", localName: "string", dynamic: "boolean"
385
+ });
386
+ }
387
+
388
+ _throwError(message: string, value: any): never {
389
+ assertArgument(false, message, this.localName, value);
390
+ }
391
+
392
+ abstract encode(writer: Writer, value: any): number;
393
+ abstract decode(reader: Reader): any;
394
+
395
+ abstract defaultValue(): any;
396
+ }
397
+
398
+ /**
399
+ * @_ignore
400
+ */
401
+ export class Writer {
402
+ // An array of WordSize lengthed objects to concatenation
403
+ #data: Array<Uint8Array>;
404
+ #dataLength: number;
405
+
406
+ constructor() {
407
+ this.#data = [ ];
408
+ this.#dataLength = 0;
409
+ }
410
+
411
+ get data(): string {
412
+ return concat(this.#data);
413
+ }
414
+ get length(): number { return this.#dataLength; }
415
+
416
+ #writeData(data: Uint8Array): number {
417
+ this.#data.push(data);
418
+ this.#dataLength += data.length;
419
+ return data.length;
420
+ }
421
+
422
+ appendWriter(writer: Writer): number {
423
+ return this.#writeData(getBytesCopy(writer.data));
424
+ }
425
+
426
+ // Arrayish item; pad on the right to *nearest* WordSize
427
+ writeBytes(value: BytesLike): number {
428
+ let bytes = getBytesCopy(value);
429
+ const paddingOffset = bytes.length % WordSize;
430
+ if (paddingOffset) {
431
+ bytes = getBytesCopy(concat([ bytes, Padding.slice(paddingOffset) ]))
432
+ }
433
+ return this.#writeData(bytes);
434
+ }
435
+
436
+ // Numeric item; pad on the left *to* WordSize
437
+ writeValue(value: BigNumberish): number {
438
+ return this.#writeData(getValue(value));
439
+ }
440
+
441
+ // Inserts a numeric place-holder, returning a callback that can
442
+ // be used to asjust the value later
443
+ writeUpdatableValue(): (value: BigNumberish) => void {
444
+ const offset = this.#data.length;
445
+ this.#data.push(Padding);
446
+ this.#dataLength += WordSize;
447
+ return (value: BigNumberish) => {
448
+ this.#data[offset] = getValue(value);
449
+ };
450
+ }
451
+ }
452
+
453
+ /**
454
+ * @_ignore
455
+ */
456
+ export class Reader {
457
+ // Allows incomplete unpadded data to be read; otherwise an error
458
+ // is raised if attempting to overrun the buffer. This is required
459
+ // to deal with an old Solidity bug, in which event data for
460
+ // external (not public thoguh) was tightly packed.
461
+ readonly allowLoose!: boolean;
462
+
463
+ readonly #data: Uint8Array;
464
+ #offset: number;
465
+
466
+ #bytesRead: number;
467
+ #parent: null | Reader;
468
+ #maxInflation: number;
469
+
470
+ constructor(data: BytesLike, allowLoose?: boolean, maxInflation?: number) {
471
+ defineProperties<Reader>(this, { allowLoose: !!allowLoose });
472
+
473
+ this.#data = getBytesCopy(data);
474
+ this.#bytesRead = 0;
475
+ this.#parent = null;
476
+ this.#maxInflation = (maxInflation != null) ? maxInflation: 1024;
477
+
478
+ this.#offset = 0;
479
+ }
480
+
481
+ get data(): string { return hexlify(this.#data); }
482
+ get dataLength(): number { return this.#data.length; }
483
+ get consumed(): number { return this.#offset; }
484
+ get bytes(): Uint8Array { return new Uint8Array(this.#data); }
485
+
486
+ #incrementBytesRead(count: number): void {
487
+ if (this.#parent) { return this.#parent.#incrementBytesRead(count); }
488
+
489
+ this.#bytesRead += count;
490
+
491
+ // Check for excessive inflation (see: #4537)
492
+ assert(this.#maxInflation < 1 || this.#bytesRead <= this.#maxInflation * this.dataLength, `compressed ABI data exceeds inflation ratio of ${ this.#maxInflation } ( see: https:/\/github.com/ethers-io/ethers.js/issues/4537 )`, "BUFFER_OVERRUN", {
493
+ buffer: getBytesCopy(this.#data), offset: this.#offset,
494
+ length: count, info: {
495
+ bytesRead: this.#bytesRead,
496
+ dataLength: this.dataLength
497
+ }
498
+ });
499
+ }
500
+
501
+ #peekBytes(offset: number, length: number, loose?: boolean): Uint8Array {
502
+ let alignedLength = Math.ceil(length / WordSize) * WordSize;
503
+ if (this.#offset + alignedLength > this.#data.length) {
504
+ if (this.allowLoose && loose && this.#offset + length <= this.#data.length) {
505
+ alignedLength = length;
506
+ } else {
507
+ assert(false, "data out-of-bounds", "BUFFER_OVERRUN", {
508
+ buffer: getBytesCopy(this.#data),
509
+ length: this.#data.length,
510
+ offset: this.#offset + alignedLength
511
+ });
512
+ }
513
+ }
514
+ return this.#data.slice(this.#offset, this.#offset + alignedLength)
515
+ }
516
+
517
+ // Create a sub-reader with the same underlying data, but offset
518
+ subReader(offset: number): Reader {
519
+ const reader = new Reader(this.#data.slice(this.#offset + offset), this.allowLoose, this.#maxInflation);
520
+ reader.#parent = this;
521
+ return reader;
522
+ }
523
+
524
+ // Read bytes
525
+ readBytes(length: number, loose?: boolean): Uint8Array {
526
+ let bytes = this.#peekBytes(0, length, !!loose);
527
+ this.#incrementBytesRead(length);
528
+ this.#offset += bytes.length;
529
+ // @TODO: Make sure the length..end bytes are all 0?
530
+ return bytes.slice(0, length);
531
+ }
532
+
533
+ // Read a numeric values
534
+ readValue(): bigint {
535
+ return toBigInt(this.readBytes(WordSize));
536
+ }
537
+
538
+ readIndex(): number {
539
+ return toNumber(this.readBytes(WordSize));
540
+ }
541
+ }