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,793 +1,793 @@
1
- /**
2
- * All errors in ethers include properties to ensure they are both
3
- * human-readable (i.e. ``.message``) and machine-readable (i.e. ``.code``).
4
- *
5
- * The [[isError]] function can be used to check the error ``code`` and
6
- * provide a type guard for the properties present on that error interface.
7
- *
8
- * @_section: api/utils/errors:Errors [about-errors]
9
- */
10
-
11
- import { version } from "../_version.js";
12
-
13
- import { defineProperties } from "./properties.js";
14
-
15
- import type {
16
- TransactionRequest, TransactionReceipt, TransactionResponse
17
- } from "../providers/index.js";
18
-
19
- import type { FetchRequest, FetchResponse } from "./fetch.js";
20
-
21
- /**
22
- * An error may contain additional properties, but those must not
23
- * conflict with any implicit properties.
24
- */
25
- export type ErrorInfo<T> = Omit<T, "code" | "name" | "message" | "shortMessage"> & { shortMessage?: string };
26
-
27
-
28
- function stringify(value: any): any {
29
- if (value == null) { return "null"; }
30
-
31
- if (Array.isArray(value)) {
32
- return "[ " + (value.map(stringify)).join(", ") + " ]";
33
- }
34
-
35
- if (value instanceof Uint8Array) {
36
- const HEX = "0123456789abcdef";
37
- let result = "0x";
38
- for (let i = 0; i < value.length; i++) {
39
- result += HEX[value[i] >> 4];
40
- result += HEX[value[i] & 0xf];
41
- }
42
- return result;
43
- }
44
-
45
- if (typeof(value) === "object" && typeof(value.toJSON) === "function") {
46
- return stringify(value.toJSON());
47
- }
48
-
49
- switch (typeof(value)) {
50
- case "boolean": case "symbol":
51
- return value.toString();
52
- case "bigint":
53
- return BigInt(value).toString();
54
- case "number":
55
- return (value).toString();
56
- case "string":
57
- return JSON.stringify(value);
58
- case "object": {
59
- const keys = Object.keys(value);
60
- keys.sort();
61
- return "{ " + keys.map((k) => `${ stringify(k) }: ${ stringify(value[k]) }`).join(", ") + " }";
62
- }
63
- }
64
-
65
- return `[ COULD NOT SERIALIZE ]`;
66
- }
67
-
68
- /**
69
- * All errors emitted by ethers have an **ErrorCode** to help
70
- * identify and coalesce errors to simplify programmatic analysis.
71
- *
72
- * Each **ErrorCode** is the %%code%% proerty of a coresponding
73
- * [[EthersError]].
74
- *
75
- * **Generic Errors**
76
- *
77
- * **``"UNKNOWN_ERROR"``** - see [[UnknownError]]
78
- *
79
- * **``"NOT_IMPLEMENTED"``** - see [[NotImplementedError]]
80
- *
81
- * **``"UNSUPPORTED_OPERATION"``** - see [[UnsupportedOperationError]]
82
- *
83
- * **``"NETWORK_ERROR"``** - see [[NetworkError]]
84
- *
85
- * **``"SERVER_ERROR"``** - see [[ServerError]]
86
- *
87
- * **``"TIMEOUT"``** - see [[TimeoutError]]
88
- *
89
- * **``"BAD_DATA"``** - see [[BadDataError]]
90
- *
91
- * **``"CANCELLED"``** - see [[CancelledError]]
92
- *
93
- * **Operational Errors**
94
- *
95
- * **``"BUFFER_OVERRUN"``** - see [[BufferOverrunError]]
96
- *
97
- * **``"NUMERIC_FAULT"``** - see [[NumericFaultError]]
98
- *
99
- * **Argument Errors**
100
- *
101
- * **``"INVALID_ARGUMENT"``** - see [[InvalidArgumentError]]
102
- *
103
- * **``"MISSING_ARGUMENT"``** - see [[MissingArgumentError]]
104
- *
105
- * **``"UNEXPECTED_ARGUMENT"``** - see [[UnexpectedArgumentError]]
106
- *
107
- * **``"VALUE_MISMATCH"``** - //unused//
108
- *
109
- * **Blockchain Errors**
110
- *
111
- * **``"CALL_EXCEPTION"``** - see [[CallExceptionError]]
112
- *
113
- * **``"INSUFFICIENT_FUNDS"``** - see [[InsufficientFundsError]]
114
- *
115
- * **``"NONCE_EXPIRED"``** - see [[NonceExpiredError]]
116
- *
117
- * **``"REPLACEMENT_UNDERPRICED"``** - see [[ReplacementUnderpricedError]]
118
- *
119
- * **``"TRANSACTION_REPLACED"``** - see [[TransactionReplacedError]]
120
- *
121
- * **``"UNCONFIGURED_NAME"``** - see [[UnconfiguredNameError]]
122
- *
123
- * **``"OFFCHAIN_FAULT"``** - see [[OffchainFaultError]]
124
- *
125
- * **User Interaction Errors**
126
- *
127
- * **``"ACTION_REJECTED"``** - see [[ActionRejectedError]]
128
- */
129
- export type ErrorCode =
130
-
131
- // Generic Errors
132
- "UNKNOWN_ERROR" | "NOT_IMPLEMENTED" | "UNSUPPORTED_OPERATION" |
133
- "NETWORK_ERROR" | "SERVER_ERROR" | "TIMEOUT" | "BAD_DATA" |
134
- "CANCELLED" |
135
-
136
- // Operational Errors
137
- "BUFFER_OVERRUN" | "NUMERIC_FAULT" |
138
-
139
- // Argument Errors
140
- "INVALID_ARGUMENT" | "MISSING_ARGUMENT" | "UNEXPECTED_ARGUMENT" |
141
- "VALUE_MISMATCH" |
142
-
143
- // Blockchain Errors
144
- "CALL_EXCEPTION" | "INSUFFICIENT_FUNDS" | "NONCE_EXPIRED" |
145
- "REPLACEMENT_UNDERPRICED" | "TRANSACTION_REPLACED" |
146
- "UNCONFIGURED_NAME" | "OFFCHAIN_FAULT" |
147
-
148
- // User Interaction
149
- "ACTION_REJECTED"
150
- ;
151
-
152
- /**
153
- * All errors in Ethers include properties to assist in
154
- * machine-readable errors.
155
- */
156
- export interface EthersError<T extends ErrorCode = ErrorCode> extends Error {
157
- /**
158
- * The string error code.
159
- */
160
- code: ErrorCode;
161
-
162
- /**
163
- * A short message describing the error, with minimal additional
164
- * details.
165
- */
166
- shortMessage: string;
167
-
168
- /**
169
- * Additional info regarding the error that may be useful.
170
- *
171
- * This is generally helpful mostly for human-based debugging.
172
- */
173
- info?: Record<string, any>;
174
-
175
- /**
176
- * Any related error.
177
- */
178
- error?: Error;
179
- }
180
-
181
- // Generic Errors
182
-
183
- /**
184
- * This Error is a catch-all for when there is no way for Ethers to
185
- * know what the underlying problem is.
186
- */
187
- export interface UnknownError extends EthersError<"UNKNOWN_ERROR"> {
188
- [ key: string ]: any;
189
- }
190
-
191
- /**
192
- * This Error is mostly used as a stub for functionality that is
193
- * intended for the future, but is currently not implemented.
194
- */
195
- export interface NotImplementedError extends EthersError<"NOT_IMPLEMENTED"> {
196
- /**
197
- * The attempted operation.
198
- */
199
- operation: string;
200
- }
201
-
202
- /**
203
- * This Error indicates that the attempted operation is not supported.
204
- *
205
- * This could range from a specific JSON-RPC end-point not supporting
206
- * a feature to a specific configuration of an object prohibiting the
207
- * operation.
208
- *
209
- * For example, a [[Wallet]] with no connected [[Provider]] is unable
210
- * to send a transaction.
211
- */
212
- export interface UnsupportedOperationError extends EthersError<"UNSUPPORTED_OPERATION"> {
213
- /**
214
- * The attempted operation.
215
- */
216
- operation: string;
217
- }
218
-
219
- /**
220
- * This Error indicates a problem connecting to a network.
221
- */
222
- export interface NetworkError extends EthersError<"NETWORK_ERROR"> {
223
- /**
224
- * The network event.
225
- */
226
- event: string;
227
- }
228
-
229
- /**
230
- * This Error indicates there was a problem fetching a resource from
231
- * a server.
232
- */
233
- export interface ServerError extends EthersError<"SERVER_ERROR"> {
234
- /**
235
- * The requested resource.
236
- */
237
- request: FetchRequest | string;
238
-
239
- /**
240
- * The response received from the server, if available.
241
- */
242
- response?: FetchResponse;
243
- }
244
-
245
- /**
246
- * This Error indicates that the timeout duration has expired and
247
- * that the operation has been implicitly cancelled.
248
- *
249
- * The side-effect of the operation may still occur, as this
250
- * generally means a request has been sent and there has simply
251
- * been no response to indicate whether it was processed or not.
252
- */
253
- export interface TimeoutError extends EthersError<"TIMEOUT"> {
254
- /**
255
- * The attempted operation.
256
- */
257
- operation: string;
258
-
259
- /**
260
- * The reason.
261
- */
262
- reason: string;
263
-
264
- /**
265
- * The resource request, if available.
266
- */
267
- request?: FetchRequest;
268
- }
269
-
270
- /**
271
- * This Error indicates that a provided set of data cannot
272
- * be correctly interpreted.
273
- */
274
- export interface BadDataError extends EthersError<"BAD_DATA"> {
275
- /**
276
- * The data.
277
- */
278
- value: any;
279
- }
280
-
281
- /**
282
- * This Error indicates that the operation was cancelled by a
283
- * programmatic call, for example to ``cancel()``.
284
- */
285
- export interface CancelledError extends EthersError<"CANCELLED"> {
286
- }
287
-
288
-
289
- // Operational Errors
290
-
291
- /**
292
- * This Error indicates an attempt was made to read outside the bounds
293
- * of protected data.
294
- *
295
- * Most operations in Ethers are protected by bounds checks, to mitigate
296
- * exploits when parsing data.
297
- */
298
- export interface BufferOverrunError extends EthersError<"BUFFER_OVERRUN"> {
299
- /**
300
- * The buffer that was overrun.
301
- */
302
- buffer: Uint8Array;
303
-
304
- /**
305
- * The length of the buffer.
306
- */
307
- length: number;
308
-
309
- /**
310
- * The offset that was requested.
311
- */
312
- offset: number;
313
- }
314
-
315
- /**
316
- * This Error indicates an operation which would result in incorrect
317
- * arithmetic output has occurred.
318
- *
319
- * For example, trying to divide by zero or using a ``uint8`` to store
320
- * a negative value.
321
- */
322
- export interface NumericFaultError extends EthersError<"NUMERIC_FAULT"> {
323
- /**
324
- * The attempted operation.
325
- */
326
- operation: string;
327
-
328
- /**
329
- * The fault reported.
330
- */
331
- fault: string;
332
-
333
- /**
334
- * The value the operation was attempted against.
335
- */
336
- value: any;
337
- }
338
-
339
-
340
- // Argument Errors
341
-
342
- /**
343
- * This Error indicates an incorrect type or value was passed to
344
- * a function or method.
345
- */
346
- export interface InvalidArgumentError extends EthersError<"INVALID_ARGUMENT"> {
347
- /**
348
- * The name of the argument.
349
- */
350
- argument: string;
351
-
352
- /**
353
- * The value that was provided.
354
- */
355
- value: any;
356
-
357
- info?: Record<string, any>
358
- }
359
-
360
- /**
361
- * This Error indicates there were too few arguments were provided.
362
- */
363
- export interface MissingArgumentError extends EthersError<"MISSING_ARGUMENT"> {
364
- /**
365
- * The number of arguments received.
366
- */
367
- count: number;
368
-
369
- /**
370
- * The number of arguments expected.
371
- */
372
- expectedCount: number;
373
- }
374
-
375
- /**
376
- * This Error indicates too many arguments were provided.
377
- */
378
- export interface UnexpectedArgumentError extends EthersError<"UNEXPECTED_ARGUMENT"> {
379
- /**
380
- * The number of arguments received.
381
- */
382
- count: number;
383
-
384
- /**
385
- * The number of arguments expected.
386
- */
387
- expectedCount: number;
388
- }
389
-
390
-
391
- // Blockchain Errors
392
-
393
- /**
394
- * The action that resulted in the call exception.
395
- */
396
- export type CallExceptionAction = "call" | "estimateGas" | "getTransactionResult" | "sendTransaction" | "unknown";
397
-
398
- /**
399
- * The related transaction that caused the error.
400
- */
401
- export type CallExceptionTransaction = {
402
- to: null | string;
403
- from?: string;
404
- data: string;
405
- };
406
-
407
- /**
408
- * This **Error** indicates a transaction reverted.
409
- */
410
- export interface CallExceptionError extends EthersError<"CALL_EXCEPTION"> {
411
-
412
- /**
413
- * The action being performed when the revert was encountered.
414
- */
415
- action: CallExceptionAction;
416
-
417
- /**
418
- * The revert data returned.
419
- */
420
- data: null | string;
421
-
422
- /**
423
- * A human-readable representation of data, if possible.
424
- */
425
- reason: null | string;
426
-
427
- /**
428
- * The transaction that triggered the exception.
429
- */
430
- transaction: CallExceptionTransaction,
431
-
432
- /**
433
- * The contract invocation details, if available.
434
- */
435
- invocation: null | {
436
- method: string;
437
- signature: string;
438
- args: Array<any>;
439
- }
440
-
441
- /**
442
- * The built-in or custom revert error, if available
443
- */
444
- revert: null | {
445
- signature: string;
446
- name: string;
447
- args: Array<any>;
448
- }
449
-
450
- /**
451
- * If the error occurred in a transaction that was mined
452
- * (with a status of ``0``), this is the receipt.
453
- */
454
- receipt?: TransactionReceipt; // @TODO: in v7, make this `null | TransactionReceipt`
455
- }
456
-
457
-
458
- /**
459
- * The sending account has insufficient funds to cover the
460
- * entire transaction cost.
461
- */
462
- export interface InsufficientFundsError extends EthersError<"INSUFFICIENT_FUNDS"> {
463
- /**
464
- * The transaction.
465
- */
466
- transaction: TransactionRequest;
467
- }
468
-
469
- /**
470
- * The sending account has already used this nonce in a
471
- * transaction that has been included.
472
- */
473
- export interface NonceExpiredError extends EthersError<"NONCE_EXPIRED"> {
474
- /**
475
- * The transaction.
476
- */
477
- transaction: TransactionRequest;
478
- }
479
-
480
- /**
481
- * A CCIP-read exception, which cannot be recovered from or
482
- * be further processed.
483
- */
484
- export interface OffchainFaultError extends EthersError<"OFFCHAIN_FAULT"> {
485
- /**
486
- * The transaction.
487
- */
488
- transaction?: TransactionRequest;
489
-
490
- /**
491
- * The reason the CCIP-read failed.
492
- */
493
- reason: string;
494
- }
495
-
496
- /**
497
- * An attempt was made to replace a transaction, but with an
498
- * insufficient additional fee to afford evicting the old
499
- * transaction from the memory pool.
500
- */
501
- export interface ReplacementUnderpricedError extends EthersError<"REPLACEMENT_UNDERPRICED"> {
502
- /**
503
- * The transaction.
504
- */
505
- transaction: TransactionRequest;
506
- }
507
-
508
- /**
509
- * A pending transaction was replaced by another.
510
- */
511
- export interface TransactionReplacedError extends EthersError<"TRANSACTION_REPLACED"> {
512
- /**
513
- * If the transaction was cancelled, such that the original
514
- * effects of the transaction cannot be assured.
515
- */
516
- cancelled: boolean;
517
-
518
- /**
519
- * The reason the transaction was replaced.
520
- */
521
- reason: "repriced" | "cancelled" | "replaced";
522
-
523
- /**
524
- * The hash of the replaced transaction.
525
- */
526
- hash: string;
527
-
528
- /**
529
- * The transaction that replaced the transaction.
530
- */
531
- replacement: TransactionResponse;
532
-
533
- /**
534
- * The receipt of the transaction that replace the transaction.
535
- */
536
- receipt: TransactionReceipt;
537
- }
538
-
539
- /**
540
- * This Error indicates an ENS name was used, but the name has not
541
- * been configured.
542
- *
543
- * This could indicate an ENS name is unowned or that the current
544
- * address being pointed to is the [[ZeroAddress]].
545
- */
546
- export interface UnconfiguredNameError extends EthersError<"UNCONFIGURED_NAME"> {
547
- /**
548
- * The ENS name that was requested
549
- */
550
- value: string;
551
- }
552
-
553
- /**
554
- * This Error indicates a request was rejected by the user.
555
- *
556
- * In most clients (such as MetaMask), when an operation requires user
557
- * authorization (such as ``signer.sendTransaction``), the client
558
- * presents a dialog box to the user. If the user denies the request
559
- * this error is thrown.
560
- */
561
- export interface ActionRejectedError extends EthersError<"ACTION_REJECTED"> {
562
- /**
563
- * The requested action.
564
- */
565
- action: "requestAccess" | "sendTransaction" | "signMessage" | "signTransaction" | "signTypedData" | "unknown",
566
-
567
- /**
568
- * The reason the action was rejected.
569
- *
570
- * If there is already a pending request, some clients may indicate
571
- * there is already a ``"pending"`` action. This prevents an app
572
- * from spamming the user.
573
- */
574
- reason: "expired" | "rejected" | "pending"
575
- }
576
-
577
- // Coding; converts an ErrorCode its Typed Error
578
-
579
- /**
580
- * A conditional type that transforms the [[ErrorCode]] T into
581
- * its EthersError type.
582
- *
583
- * @flatworm-skip-docs
584
- */
585
- export type CodedEthersError<T> =
586
- T extends "UNKNOWN_ERROR" ? UnknownError:
587
- T extends "NOT_IMPLEMENTED" ? NotImplementedError:
588
- T extends "UNSUPPORTED_OPERATION" ? UnsupportedOperationError:
589
- T extends "NETWORK_ERROR" ? NetworkError:
590
- T extends "SERVER_ERROR" ? ServerError:
591
- T extends "TIMEOUT" ? TimeoutError:
592
- T extends "BAD_DATA" ? BadDataError:
593
- T extends "CANCELLED" ? CancelledError:
594
-
595
- T extends "BUFFER_OVERRUN" ? BufferOverrunError:
596
- T extends "NUMERIC_FAULT" ? NumericFaultError:
597
-
598
- T extends "INVALID_ARGUMENT" ? InvalidArgumentError:
599
- T extends "MISSING_ARGUMENT" ? MissingArgumentError:
600
- T extends "UNEXPECTED_ARGUMENT" ? UnexpectedArgumentError:
601
-
602
- T extends "CALL_EXCEPTION" ? CallExceptionError:
603
- T extends "INSUFFICIENT_FUNDS" ? InsufficientFundsError:
604
- T extends "NONCE_EXPIRED" ? NonceExpiredError:
605
- T extends "OFFCHAIN_FAULT" ? OffchainFaultError:
606
- T extends "REPLACEMENT_UNDERPRICED" ? ReplacementUnderpricedError:
607
- T extends "TRANSACTION_REPLACED" ? TransactionReplacedError:
608
- T extends "UNCONFIGURED_NAME" ? UnconfiguredNameError:
609
-
610
- T extends "ACTION_REJECTED" ? ActionRejectedError:
611
-
612
- never;
613
-
614
-
615
-
616
- /**
617
- * Returns true if the %%error%% matches an error thrown by ethers
618
- * that matches the error %%code%%.
619
- *
620
- * In TypeScript environments, this can be used to check that %%error%%
621
- * matches an EthersError type, which means the expected properties will
622
- * be set.
623
- *
624
- * @See [ErrorCodes](api:ErrorCode)
625
- * @example
626
- * try {
627
- * // code....
628
- * } catch (e) {
629
- * if (isError(e, "CALL_EXCEPTION")) {
630
- * // The Type Guard has validated this object
631
- * console.log(e.data);
632
- * }
633
- * }
634
- */
635
- export function isError<K extends ErrorCode, T extends CodedEthersError<K>>(error: any, code: K): error is T {
636
- return (error && (<EthersError>error).code === code);
637
- }
638
-
639
- /**
640
- * Returns true if %%error%% is a [[CallExceptionError].
641
- */
642
- export function isCallException(error: any): error is CallExceptionError {
643
- return isError(error, "CALL_EXCEPTION");
644
- }
645
-
646
- /**
647
- * Returns a new Error configured to the format ethers emits errors, with
648
- * the %%message%%, [[api:ErrorCode]] %%code%% and additional properties
649
- * for the corresponding EthersError.
650
- *
651
- * Each error in ethers includes the version of ethers, a
652
- * machine-readable [[ErrorCode]], and depending on %%code%%, additional
653
- * required properties. The error message will also include the %%message%%,
654
- * ethers version, %%code%% and all additional properties, serialized.
655
- */
656
- export function makeError<K extends ErrorCode, T extends CodedEthersError<K>>(message: string, code: K, info?: ErrorInfo<T>): T {
657
- let shortMessage = message;
658
-
659
- {
660
- const details: Array<string> = [];
661
- if (info) {
662
- if ("message" in info || "code" in info || "name" in info) {
663
- throw new Error(`value will overwrite populated values: ${ stringify(info) }`);
664
- }
665
- for (const key in info) {
666
- if (key === "shortMessage") { continue; }
667
- const value = <any>(info[<keyof ErrorInfo<T>>key]);
668
- // try {
669
- details.push(key + "=" + stringify(value));
670
- // } catch (error: any) {
671
- // console.log("MMM", error.message);
672
- // details.push(key + "=[could not serialize object]");
673
- // }
674
- }
675
- }
676
- details.push(`code=${ code }`);
677
- details.push(`version=${ version }`);
678
-
679
- if (details.length) {
680
- message += " (" + details.join(", ") + ")";
681
- }
682
- }
683
-
684
- let error;
685
- switch (code) {
686
- case "INVALID_ARGUMENT":
687
- error = new TypeError(message);
688
- break;
689
- case "NUMERIC_FAULT":
690
- case "BUFFER_OVERRUN":
691
- error = new RangeError(message);
692
- break;
693
- default:
694
- error = new Error(message);
695
- }
696
-
697
- defineProperties<EthersError>(<EthersError>error, { code });
698
-
699
- if (info) { Object.assign(error, info); }
700
-
701
- if ((<any>error).shortMessage == null) {
702
- defineProperties<EthersError>(<EthersError>error, { shortMessage });
703
- }
704
-
705
- return <T>error;
706
- }
707
-
708
- /**
709
- * Throws an EthersError with %%message%%, %%code%% and additional error
710
- * %%info%% when %%check%% is falsish..
711
- *
712
- * @see [[api:makeError]]
713
- */
714
- export function assert<K extends ErrorCode, T extends CodedEthersError<K>>(check: unknown, message: string, code: K, info?: ErrorInfo<T>): asserts check {
715
- if (!check) { throw makeError(message, code, info); }
716
- }
717
-
718
-
719
- /**
720
- * A simple helper to simply ensuring provided arguments match expected
721
- * constraints, throwing if not.
722
- *
723
- * In TypeScript environments, the %%check%% has been asserted true, so
724
- * any further code does not need additional compile-time checks.
725
- */
726
- export function assertArgument(check: unknown, message: string, name: string, value: unknown): asserts check {
727
- assert(check, message, "INVALID_ARGUMENT", { argument: name, value: value });
728
- }
729
-
730
- export function assertArgumentCount(count: number, expectedCount: number, message?: string): void {
731
- if (message == null) { message = ""; }
732
- if (message) { message = ": " + message; }
733
-
734
- assert(count >= expectedCount, "missing argument" + message, "MISSING_ARGUMENT", {
735
- count: count,
736
- expectedCount: expectedCount
737
- });
738
-
739
- assert(count <= expectedCount, "too many arguments" + message, "UNEXPECTED_ARGUMENT", {
740
- count: count,
741
- expectedCount: expectedCount
742
- });
743
- }
744
-
745
- const _normalizeForms = ["NFD", "NFC", "NFKD", "NFKC"].reduce((accum, form) => {
746
- try {
747
- // General test for normalize
748
- /* c8 ignore start */
749
- if ("test".normalize(form) !== "test") { throw new Error("bad"); };
750
- /* c8 ignore stop */
751
-
752
- if (form === "NFD") {
753
- const check = String.fromCharCode(0xe9).normalize("NFD");
754
- const expected = String.fromCharCode(0x65, 0x0301)
755
- /* c8 ignore start */
756
- if (check !== expected) { throw new Error("broken") }
757
- /* c8 ignore stop */
758
- }
759
-
760
- accum.push(form);
761
- } catch(error) { }
762
-
763
- return accum;
764
- }, <Array<string>>[]);
765
-
766
- /**
767
- * Throws if the normalization %%form%% is not supported.
768
- */
769
- export function assertNormalize(form: string): void {
770
- assert(_normalizeForms.indexOf(form) >= 0, "platform missing String.prototype.normalize", "UNSUPPORTED_OPERATION", {
771
- operation: "String.prototype.normalize", info: { form }
772
- });
773
- }
774
-
775
- /**
776
- * Many classes use file-scoped values to guard the constructor,
777
- * making it effectively private. This facilitates that pattern
778
- * by ensuring the %%givenGaurd%% matches the file-scoped %%guard%%,
779
- * throwing if not, indicating the %%className%% if provided.
780
- */
781
- export function assertPrivate(givenGuard: any, guard: any, className?: string): void {
782
- if (className == null) { className = ""; }
783
- if (givenGuard !== guard) {
784
- let method = className, operation = "new";
785
- if (className) {
786
- method += ".";
787
- operation += " " + className;
788
- }
789
- assert(false, `private constructor; use ${ method }from* methods`, "UNSUPPORTED_OPERATION", {
790
- operation
791
- });
792
- }
793
- }
1
+ /**
2
+ * All errors in ethers include properties to ensure they are both
3
+ * human-readable (i.e. ``.message``) and machine-readable (i.e. ``.code``).
4
+ *
5
+ * The [[isError]] function can be used to check the error ``code`` and
6
+ * provide a type guard for the properties present on that error interface.
7
+ *
8
+ * @_section: api/utils/errors:Errors [about-errors]
9
+ */
10
+
11
+ import { version } from "../_version.js";
12
+
13
+ import { defineProperties } from "./properties.js";
14
+
15
+ import type {
16
+ TransactionRequest, TransactionReceipt, TransactionResponse
17
+ } from "../providers/index.js";
18
+
19
+ import type { FetchRequest, FetchResponse } from "./fetch.js";
20
+
21
+ /**
22
+ * An error may contain additional properties, but those must not
23
+ * conflict with any implicit properties.
24
+ */
25
+ export type ErrorInfo<T> = Omit<T, "code" | "name" | "message" | "shortMessage"> & { shortMessage?: string };
26
+
27
+
28
+ function stringify(value: any): any {
29
+ if (value == null) { return "null"; }
30
+
31
+ if (Array.isArray(value)) {
32
+ return "[ " + (value.map(stringify)).join(", ") + " ]";
33
+ }
34
+
35
+ if (value instanceof Uint8Array) {
36
+ const HEX = "0123456789abcdef";
37
+ let result = "0x";
38
+ for (let i = 0; i < value.length; i++) {
39
+ result += HEX[value[i] >> 4];
40
+ result += HEX[value[i] & 0xf];
41
+ }
42
+ return result;
43
+ }
44
+
45
+ if (typeof(value) === "object" && typeof(value.toJSON) === "function") {
46
+ return stringify(value.toJSON());
47
+ }
48
+
49
+ switch (typeof(value)) {
50
+ case "boolean": case "symbol":
51
+ return value.toString();
52
+ case "bigint":
53
+ return BigInt(value).toString();
54
+ case "number":
55
+ return (value).toString();
56
+ case "string":
57
+ return JSON.stringify(value);
58
+ case "object": {
59
+ const keys = Object.keys(value);
60
+ keys.sort();
61
+ return "{ " + keys.map((k) => `${ stringify(k) }: ${ stringify(value[k]) }`).join(", ") + " }";
62
+ }
63
+ }
64
+
65
+ return `[ COULD NOT SERIALIZE ]`;
66
+ }
67
+
68
+ /**
69
+ * All errors emitted by ethers have an **ErrorCode** to help
70
+ * identify and coalesce errors to simplify programmatic analysis.
71
+ *
72
+ * Each **ErrorCode** is the %%code%% proerty of a coresponding
73
+ * [[EthersError]].
74
+ *
75
+ * **Generic Errors**
76
+ *
77
+ * **``"UNKNOWN_ERROR"``** - see [[UnknownError]]
78
+ *
79
+ * **``"NOT_IMPLEMENTED"``** - see [[NotImplementedError]]
80
+ *
81
+ * **``"UNSUPPORTED_OPERATION"``** - see [[UnsupportedOperationError]]
82
+ *
83
+ * **``"NETWORK_ERROR"``** - see [[NetworkError]]
84
+ *
85
+ * **``"SERVER_ERROR"``** - see [[ServerError]]
86
+ *
87
+ * **``"TIMEOUT"``** - see [[TimeoutError]]
88
+ *
89
+ * **``"BAD_DATA"``** - see [[BadDataError]]
90
+ *
91
+ * **``"CANCELLED"``** - see [[CancelledError]]
92
+ *
93
+ * **Operational Errors**
94
+ *
95
+ * **``"BUFFER_OVERRUN"``** - see [[BufferOverrunError]]
96
+ *
97
+ * **``"NUMERIC_FAULT"``** - see [[NumericFaultError]]
98
+ *
99
+ * **Argument Errors**
100
+ *
101
+ * **``"INVALID_ARGUMENT"``** - see [[InvalidArgumentError]]
102
+ *
103
+ * **``"MISSING_ARGUMENT"``** - see [[MissingArgumentError]]
104
+ *
105
+ * **``"UNEXPECTED_ARGUMENT"``** - see [[UnexpectedArgumentError]]
106
+ *
107
+ * **``"VALUE_MISMATCH"``** - //unused//
108
+ *
109
+ * **Blockchain Errors**
110
+ *
111
+ * **``"CALL_EXCEPTION"``** - see [[CallExceptionError]]
112
+ *
113
+ * **``"INSUFFICIENT_FUNDS"``** - see [[InsufficientFundsError]]
114
+ *
115
+ * **``"NONCE_EXPIRED"``** - see [[NonceExpiredError]]
116
+ *
117
+ * **``"REPLACEMENT_UNDERPRICED"``** - see [[ReplacementUnderpricedError]]
118
+ *
119
+ * **``"TRANSACTION_REPLACED"``** - see [[TransactionReplacedError]]
120
+ *
121
+ * **``"UNCONFIGURED_NAME"``** - see [[UnconfiguredNameError]]
122
+ *
123
+ * **``"OFFCHAIN_FAULT"``** - see [[OffchainFaultError]]
124
+ *
125
+ * **User Interaction Errors**
126
+ *
127
+ * **``"ACTION_REJECTED"``** - see [[ActionRejectedError]]
128
+ */
129
+ export type ErrorCode =
130
+
131
+ // Generic Errors
132
+ "UNKNOWN_ERROR" | "NOT_IMPLEMENTED" | "UNSUPPORTED_OPERATION" |
133
+ "NETWORK_ERROR" | "SERVER_ERROR" | "TIMEOUT" | "BAD_DATA" |
134
+ "CANCELLED" |
135
+
136
+ // Operational Errors
137
+ "BUFFER_OVERRUN" | "NUMERIC_FAULT" |
138
+
139
+ // Argument Errors
140
+ "INVALID_ARGUMENT" | "MISSING_ARGUMENT" | "UNEXPECTED_ARGUMENT" |
141
+ "VALUE_MISMATCH" |
142
+
143
+ // Blockchain Errors
144
+ "CALL_EXCEPTION" | "INSUFFICIENT_FUNDS" | "NONCE_EXPIRED" |
145
+ "REPLACEMENT_UNDERPRICED" | "TRANSACTION_REPLACED" |
146
+ "UNCONFIGURED_NAME" | "OFFCHAIN_FAULT" |
147
+
148
+ // User Interaction
149
+ "ACTION_REJECTED"
150
+ ;
151
+
152
+ /**
153
+ * All errors in Ethers include properties to assist in
154
+ * machine-readable errors.
155
+ */
156
+ export interface EthersError<T extends ErrorCode = ErrorCode> extends Error {
157
+ /**
158
+ * The string error code.
159
+ */
160
+ code: ErrorCode;
161
+
162
+ /**
163
+ * A short message describing the error, with minimal additional
164
+ * details.
165
+ */
166
+ shortMessage: string;
167
+
168
+ /**
169
+ * Additional info regarding the error that may be useful.
170
+ *
171
+ * This is generally helpful mostly for human-based debugging.
172
+ */
173
+ info?: Record<string, any>;
174
+
175
+ /**
176
+ * Any related error.
177
+ */
178
+ error?: Error;
179
+ }
180
+
181
+ // Generic Errors
182
+
183
+ /**
184
+ * This Error is a catch-all for when there is no way for Ethers to
185
+ * know what the underlying problem is.
186
+ */
187
+ export interface UnknownError extends EthersError<"UNKNOWN_ERROR"> {
188
+ [ key: string ]: any;
189
+ }
190
+
191
+ /**
192
+ * This Error is mostly used as a stub for functionality that is
193
+ * intended for the future, but is currently not implemented.
194
+ */
195
+ export interface NotImplementedError extends EthersError<"NOT_IMPLEMENTED"> {
196
+ /**
197
+ * The attempted operation.
198
+ */
199
+ operation: string;
200
+ }
201
+
202
+ /**
203
+ * This Error indicates that the attempted operation is not supported.
204
+ *
205
+ * This could range from a specific JSON-RPC end-point not supporting
206
+ * a feature to a specific configuration of an object prohibiting the
207
+ * operation.
208
+ *
209
+ * For example, a [[Wallet]] with no connected [[Provider]] is unable
210
+ * to send a transaction.
211
+ */
212
+ export interface UnsupportedOperationError extends EthersError<"UNSUPPORTED_OPERATION"> {
213
+ /**
214
+ * The attempted operation.
215
+ */
216
+ operation: string;
217
+ }
218
+
219
+ /**
220
+ * This Error indicates a problem connecting to a network.
221
+ */
222
+ export interface NetworkError extends EthersError<"NETWORK_ERROR"> {
223
+ /**
224
+ * The network event.
225
+ */
226
+ event: string;
227
+ }
228
+
229
+ /**
230
+ * This Error indicates there was a problem fetching a resource from
231
+ * a server.
232
+ */
233
+ export interface ServerError extends EthersError<"SERVER_ERROR"> {
234
+ /**
235
+ * The requested resource.
236
+ */
237
+ request: FetchRequest | string;
238
+
239
+ /**
240
+ * The response received from the server, if available.
241
+ */
242
+ response?: FetchResponse;
243
+ }
244
+
245
+ /**
246
+ * This Error indicates that the timeout duration has expired and
247
+ * that the operation has been implicitly cancelled.
248
+ *
249
+ * The side-effect of the operation may still occur, as this
250
+ * generally means a request has been sent and there has simply
251
+ * been no response to indicate whether it was processed or not.
252
+ */
253
+ export interface TimeoutError extends EthersError<"TIMEOUT"> {
254
+ /**
255
+ * The attempted operation.
256
+ */
257
+ operation: string;
258
+
259
+ /**
260
+ * The reason.
261
+ */
262
+ reason: string;
263
+
264
+ /**
265
+ * The resource request, if available.
266
+ */
267
+ request?: FetchRequest;
268
+ }
269
+
270
+ /**
271
+ * This Error indicates that a provided set of data cannot
272
+ * be correctly interpreted.
273
+ */
274
+ export interface BadDataError extends EthersError<"BAD_DATA"> {
275
+ /**
276
+ * The data.
277
+ */
278
+ value: any;
279
+ }
280
+
281
+ /**
282
+ * This Error indicates that the operation was cancelled by a
283
+ * programmatic call, for example to ``cancel()``.
284
+ */
285
+ export interface CancelledError extends EthersError<"CANCELLED"> {
286
+ }
287
+
288
+
289
+ // Operational Errors
290
+
291
+ /**
292
+ * This Error indicates an attempt was made to read outside the bounds
293
+ * of protected data.
294
+ *
295
+ * Most operations in Ethers are protected by bounds checks, to mitigate
296
+ * exploits when parsing data.
297
+ */
298
+ export interface BufferOverrunError extends EthersError<"BUFFER_OVERRUN"> {
299
+ /**
300
+ * The buffer that was overrun.
301
+ */
302
+ buffer: Uint8Array;
303
+
304
+ /**
305
+ * The length of the buffer.
306
+ */
307
+ length: number;
308
+
309
+ /**
310
+ * The offset that was requested.
311
+ */
312
+ offset: number;
313
+ }
314
+
315
+ /**
316
+ * This Error indicates an operation which would result in incorrect
317
+ * arithmetic output has occurred.
318
+ *
319
+ * For example, trying to divide by zero or using a ``uint8`` to store
320
+ * a negative value.
321
+ */
322
+ export interface NumericFaultError extends EthersError<"NUMERIC_FAULT"> {
323
+ /**
324
+ * The attempted operation.
325
+ */
326
+ operation: string;
327
+
328
+ /**
329
+ * The fault reported.
330
+ */
331
+ fault: string;
332
+
333
+ /**
334
+ * The value the operation was attempted against.
335
+ */
336
+ value: any;
337
+ }
338
+
339
+
340
+ // Argument Errors
341
+
342
+ /**
343
+ * This Error indicates an incorrect type or value was passed to
344
+ * a function or method.
345
+ */
346
+ export interface InvalidArgumentError extends EthersError<"INVALID_ARGUMENT"> {
347
+ /**
348
+ * The name of the argument.
349
+ */
350
+ argument: string;
351
+
352
+ /**
353
+ * The value that was provided.
354
+ */
355
+ value: any;
356
+
357
+ info?: Record<string, any>
358
+ }
359
+
360
+ /**
361
+ * This Error indicates there were too few arguments were provided.
362
+ */
363
+ export interface MissingArgumentError extends EthersError<"MISSING_ARGUMENT"> {
364
+ /**
365
+ * The number of arguments received.
366
+ */
367
+ count: number;
368
+
369
+ /**
370
+ * The number of arguments expected.
371
+ */
372
+ expectedCount: number;
373
+ }
374
+
375
+ /**
376
+ * This Error indicates too many arguments were provided.
377
+ */
378
+ export interface UnexpectedArgumentError extends EthersError<"UNEXPECTED_ARGUMENT"> {
379
+ /**
380
+ * The number of arguments received.
381
+ */
382
+ count: number;
383
+
384
+ /**
385
+ * The number of arguments expected.
386
+ */
387
+ expectedCount: number;
388
+ }
389
+
390
+
391
+ // Blockchain Errors
392
+
393
+ /**
394
+ * The action that resulted in the call exception.
395
+ */
396
+ export type CallExceptionAction = "call" | "estimateGas" | "getTransactionResult" | "sendTransaction" | "unknown";
397
+
398
+ /**
399
+ * The related transaction that caused the error.
400
+ */
401
+ export type CallExceptionTransaction = {
402
+ to: null | string;
403
+ from?: string;
404
+ data: string;
405
+ };
406
+
407
+ /**
408
+ * This **Error** indicates a transaction reverted.
409
+ */
410
+ export interface CallExceptionError extends EthersError<"CALL_EXCEPTION"> {
411
+
412
+ /**
413
+ * The action being performed when the revert was encountered.
414
+ */
415
+ action: CallExceptionAction;
416
+
417
+ /**
418
+ * The revert data returned.
419
+ */
420
+ data: null | string;
421
+
422
+ /**
423
+ * A human-readable representation of data, if possible.
424
+ */
425
+ reason: null | string;
426
+
427
+ /**
428
+ * The transaction that triggered the exception.
429
+ */
430
+ transaction: CallExceptionTransaction,
431
+
432
+ /**
433
+ * The contract invocation details, if available.
434
+ */
435
+ invocation: null | {
436
+ method: string;
437
+ signature: string;
438
+ args: Array<any>;
439
+ }
440
+
441
+ /**
442
+ * The built-in or custom revert error, if available
443
+ */
444
+ revert: null | {
445
+ signature: string;
446
+ name: string;
447
+ args: Array<any>;
448
+ }
449
+
450
+ /**
451
+ * If the error occurred in a transaction that was mined
452
+ * (with a status of ``0``), this is the receipt.
453
+ */
454
+ receipt?: TransactionReceipt; // @TODO: in v7, make this `null | TransactionReceipt`
455
+ }
456
+
457
+
458
+ /**
459
+ * The sending account has insufficient funds to cover the
460
+ * entire transaction cost.
461
+ */
462
+ export interface InsufficientFundsError extends EthersError<"INSUFFICIENT_FUNDS"> {
463
+ /**
464
+ * The transaction.
465
+ */
466
+ transaction: TransactionRequest;
467
+ }
468
+
469
+ /**
470
+ * The sending account has already used this nonce in a
471
+ * transaction that has been included.
472
+ */
473
+ export interface NonceExpiredError extends EthersError<"NONCE_EXPIRED"> {
474
+ /**
475
+ * The transaction.
476
+ */
477
+ transaction: TransactionRequest;
478
+ }
479
+
480
+ /**
481
+ * A CCIP-read exception, which cannot be recovered from or
482
+ * be further processed.
483
+ */
484
+ export interface OffchainFaultError extends EthersError<"OFFCHAIN_FAULT"> {
485
+ /**
486
+ * The transaction.
487
+ */
488
+ transaction?: TransactionRequest;
489
+
490
+ /**
491
+ * The reason the CCIP-read failed.
492
+ */
493
+ reason: string;
494
+ }
495
+
496
+ /**
497
+ * An attempt was made to replace a transaction, but with an
498
+ * insufficient additional fee to afford evicting the old
499
+ * transaction from the memory pool.
500
+ */
501
+ export interface ReplacementUnderpricedError extends EthersError<"REPLACEMENT_UNDERPRICED"> {
502
+ /**
503
+ * The transaction.
504
+ */
505
+ transaction: TransactionRequest;
506
+ }
507
+
508
+ /**
509
+ * A pending transaction was replaced by another.
510
+ */
511
+ export interface TransactionReplacedError extends EthersError<"TRANSACTION_REPLACED"> {
512
+ /**
513
+ * If the transaction was cancelled, such that the original
514
+ * effects of the transaction cannot be assured.
515
+ */
516
+ cancelled: boolean;
517
+
518
+ /**
519
+ * The reason the transaction was replaced.
520
+ */
521
+ reason: "repriced" | "cancelled" | "replaced";
522
+
523
+ /**
524
+ * The hash of the replaced transaction.
525
+ */
526
+ hash: string;
527
+
528
+ /**
529
+ * The transaction that replaced the transaction.
530
+ */
531
+ replacement: TransactionResponse;
532
+
533
+ /**
534
+ * The receipt of the transaction that replace the transaction.
535
+ */
536
+ receipt: TransactionReceipt;
537
+ }
538
+
539
+ /**
540
+ * This Error indicates an ENS name was used, but the name has not
541
+ * been configured.
542
+ *
543
+ * This could indicate an ENS name is unowned or that the current
544
+ * address being pointed to is the [[ZeroAddress]].
545
+ */
546
+ export interface UnconfiguredNameError extends EthersError<"UNCONFIGURED_NAME"> {
547
+ /**
548
+ * The ENS name that was requested
549
+ */
550
+ value: string;
551
+ }
552
+
553
+ /**
554
+ * This Error indicates a request was rejected by the user.
555
+ *
556
+ * In most clients (such as MetaMask), when an operation requires user
557
+ * authorization (such as ``signer.sendTransaction``), the client
558
+ * presents a dialog box to the user. If the user denies the request
559
+ * this error is thrown.
560
+ */
561
+ export interface ActionRejectedError extends EthersError<"ACTION_REJECTED"> {
562
+ /**
563
+ * The requested action.
564
+ */
565
+ action: "requestAccess" | "sendTransaction" | "signMessage" | "signTransaction" | "signTypedData" | "unknown",
566
+
567
+ /**
568
+ * The reason the action was rejected.
569
+ *
570
+ * If there is already a pending request, some clients may indicate
571
+ * there is already a ``"pending"`` action. This prevents an app
572
+ * from spamming the user.
573
+ */
574
+ reason: "expired" | "rejected" | "pending"
575
+ }
576
+
577
+ // Coding; converts an ErrorCode its Typed Error
578
+
579
+ /**
580
+ * A conditional type that transforms the [[ErrorCode]] T into
581
+ * its EthersError type.
582
+ *
583
+ * @flatworm-skip-docs
584
+ */
585
+ export type CodedEthersError<T> =
586
+ T extends "UNKNOWN_ERROR" ? UnknownError:
587
+ T extends "NOT_IMPLEMENTED" ? NotImplementedError:
588
+ T extends "UNSUPPORTED_OPERATION" ? UnsupportedOperationError:
589
+ T extends "NETWORK_ERROR" ? NetworkError:
590
+ T extends "SERVER_ERROR" ? ServerError:
591
+ T extends "TIMEOUT" ? TimeoutError:
592
+ T extends "BAD_DATA" ? BadDataError:
593
+ T extends "CANCELLED" ? CancelledError:
594
+
595
+ T extends "BUFFER_OVERRUN" ? BufferOverrunError:
596
+ T extends "NUMERIC_FAULT" ? NumericFaultError:
597
+
598
+ T extends "INVALID_ARGUMENT" ? InvalidArgumentError:
599
+ T extends "MISSING_ARGUMENT" ? MissingArgumentError:
600
+ T extends "UNEXPECTED_ARGUMENT" ? UnexpectedArgumentError:
601
+
602
+ T extends "CALL_EXCEPTION" ? CallExceptionError:
603
+ T extends "INSUFFICIENT_FUNDS" ? InsufficientFundsError:
604
+ T extends "NONCE_EXPIRED" ? NonceExpiredError:
605
+ T extends "OFFCHAIN_FAULT" ? OffchainFaultError:
606
+ T extends "REPLACEMENT_UNDERPRICED" ? ReplacementUnderpricedError:
607
+ T extends "TRANSACTION_REPLACED" ? TransactionReplacedError:
608
+ T extends "UNCONFIGURED_NAME" ? UnconfiguredNameError:
609
+
610
+ T extends "ACTION_REJECTED" ? ActionRejectedError:
611
+
612
+ never;
613
+
614
+
615
+
616
+ /**
617
+ * Returns true if the %%error%% matches an error thrown by ethers
618
+ * that matches the error %%code%%.
619
+ *
620
+ * In TypeScript environments, this can be used to check that %%error%%
621
+ * matches an EthersError type, which means the expected properties will
622
+ * be set.
623
+ *
624
+ * @See [ErrorCodes](api:ErrorCode)
625
+ * @example
626
+ * try {
627
+ * // code....
628
+ * } catch (e) {
629
+ * if (isError(e, "CALL_EXCEPTION")) {
630
+ * // The Type Guard has validated this object
631
+ * console.log(e.data);
632
+ * }
633
+ * }
634
+ */
635
+ export function isError<K extends ErrorCode, T extends CodedEthersError<K>>(error: any, code: K): error is T {
636
+ return (error && (<EthersError>error).code === code);
637
+ }
638
+
639
+ /**
640
+ * Returns true if %%error%% is a [[CallExceptionError].
641
+ */
642
+ export function isCallException(error: any): error is CallExceptionError {
643
+ return isError(error, "CALL_EXCEPTION");
644
+ }
645
+
646
+ /**
647
+ * Returns a new Error configured to the format ethers emits errors, with
648
+ * the %%message%%, [[api:ErrorCode]] %%code%% and additional properties
649
+ * for the corresponding EthersError.
650
+ *
651
+ * Each error in ethers includes the version of ethers, a
652
+ * machine-readable [[ErrorCode]], and depending on %%code%%, additional
653
+ * required properties. The error message will also include the %%message%%,
654
+ * ethers version, %%code%% and all additional properties, serialized.
655
+ */
656
+ export function makeError<K extends ErrorCode, T extends CodedEthersError<K>>(message: string, code: K, info?: ErrorInfo<T>): T {
657
+ let shortMessage = message;
658
+
659
+ {
660
+ const details: Array<string> = [];
661
+ if (info) {
662
+ if ("message" in info || "code" in info || "name" in info) {
663
+ throw new Error(`value will overwrite populated values: ${ stringify(info) }`);
664
+ }
665
+ for (const key in info) {
666
+ if (key === "shortMessage") { continue; }
667
+ const value = <any>(info[<keyof ErrorInfo<T>>key]);
668
+ // try {
669
+ details.push(key + "=" + stringify(value));
670
+ // } catch (error: any) {
671
+ // console.log("MMM", error.message);
672
+ // details.push(key + "=[could not serialize object]");
673
+ // }
674
+ }
675
+ }
676
+ details.push(`code=${ code }`);
677
+ details.push(`version=${ version }`);
678
+
679
+ if (details.length) {
680
+ message += " (" + details.join(", ") + ")";
681
+ }
682
+ }
683
+
684
+ let error;
685
+ switch (code) {
686
+ case "INVALID_ARGUMENT":
687
+ error = new TypeError(message);
688
+ break;
689
+ case "NUMERIC_FAULT":
690
+ case "BUFFER_OVERRUN":
691
+ error = new RangeError(message);
692
+ break;
693
+ default:
694
+ error = new Error(message);
695
+ }
696
+
697
+ defineProperties<EthersError>(<EthersError>error, { code });
698
+
699
+ if (info) { Object.assign(error, info); }
700
+
701
+ if ((<any>error).shortMessage == null) {
702
+ defineProperties<EthersError>(<EthersError>error, { shortMessage });
703
+ }
704
+
705
+ return <T>error;
706
+ }
707
+
708
+ /**
709
+ * Throws an EthersError with %%message%%, %%code%% and additional error
710
+ * %%info%% when %%check%% is falsish..
711
+ *
712
+ * @see [[api:makeError]]
713
+ */
714
+ export function assert<K extends ErrorCode, T extends CodedEthersError<K>>(check: unknown, message: string, code: K, info?: ErrorInfo<T>): asserts check {
715
+ if (!check) { throw makeError(message, code, info); }
716
+ }
717
+
718
+
719
+ /**
720
+ * A simple helper to simply ensuring provided arguments match expected
721
+ * constraints, throwing if not.
722
+ *
723
+ * In TypeScript environments, the %%check%% has been asserted true, so
724
+ * any further code does not need additional compile-time checks.
725
+ */
726
+ export function assertArgument(check: unknown, message: string, name: string, value: unknown): asserts check {
727
+ assert(check, message, "INVALID_ARGUMENT", { argument: name, value: value });
728
+ }
729
+
730
+ export function assertArgumentCount(count: number, expectedCount: number, message?: string): void {
731
+ if (message == null) { message = ""; }
732
+ if (message) { message = ": " + message; }
733
+
734
+ assert(count >= expectedCount, "missing argument" + message, "MISSING_ARGUMENT", {
735
+ count: count,
736
+ expectedCount: expectedCount
737
+ });
738
+
739
+ assert(count <= expectedCount, "too many arguments" + message, "UNEXPECTED_ARGUMENT", {
740
+ count: count,
741
+ expectedCount: expectedCount
742
+ });
743
+ }
744
+
745
+ const _normalizeForms = ["NFD", "NFC", "NFKD", "NFKC"].reduce((accum, form) => {
746
+ try {
747
+ // General test for normalize
748
+ /* c8 ignore start */
749
+ if ("test".normalize(form) !== "test") { throw new Error("bad"); };
750
+ /* c8 ignore stop */
751
+
752
+ if (form === "NFD") {
753
+ const check = String.fromCharCode(0xe9).normalize("NFD");
754
+ const expected = String.fromCharCode(0x65, 0x0301)
755
+ /* c8 ignore start */
756
+ if (check !== expected) { throw new Error("broken") }
757
+ /* c8 ignore stop */
758
+ }
759
+
760
+ accum.push(form);
761
+ } catch(error) { }
762
+
763
+ return accum;
764
+ }, <Array<string>>[]);
765
+
766
+ /**
767
+ * Throws if the normalization %%form%% is not supported.
768
+ */
769
+ export function assertNormalize(form: string): void {
770
+ assert(_normalizeForms.indexOf(form) >= 0, "platform missing String.prototype.normalize", "UNSUPPORTED_OPERATION", {
771
+ operation: "String.prototype.normalize", info: { form }
772
+ });
773
+ }
774
+
775
+ /**
776
+ * Many classes use file-scoped values to guard the constructor,
777
+ * making it effectively private. This facilitates that pattern
778
+ * by ensuring the %%givenGaurd%% matches the file-scoped %%guard%%,
779
+ * throwing if not, indicating the %%className%% if provided.
780
+ */
781
+ export function assertPrivate(givenGuard: any, guard: any, className?: string): void {
782
+ if (className == null) { className = ""; }
783
+ if (givenGuard !== guard) {
784
+ let method = className, operation = "new";
785
+ if (className) {
786
+ method += ".";
787
+ operation += " " + className;
788
+ }
789
+ assert(false, `private constructor; use ${ method }from* methods`, "UNSUPPORTED_OPERATION", {
790
+ operation
791
+ });
792
+ }
793
+ }