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,796 +1,796 @@
1
- /**
2
- * A Typed object allows a value to have its type explicitly
3
- * specified.
4
- *
5
- * For example, in Solidity, the value ``45`` could represent a
6
- * ``uint8`` or a ``uint256``. The value ``0x1234`` could represent
7
- * a ``bytes2`` or ``bytes``.
8
- *
9
- * Since JavaScript has no meaningful way to explicitly inform any
10
- * APIs which what the type is, this allows transparent interoperation
11
- * with Soldity.
12
- *
13
- * @_subsection: api/abi:Typed Values
14
- */
15
-
16
- import { assertPrivate, defineProperties } from "../utils/index.js";
17
-
18
- import type { Addressable } from "../address/index.js";
19
- import type { BigNumberish, BytesLike } from "../utils/index.js";
20
-
21
- import type { Result } from "./coders/abstract-coder.js";
22
-
23
- const _gaurd = { };
24
-
25
- function n(value: BigNumberish, width: number): Typed {
26
- let signed = false;
27
- if (width < 0) {
28
- signed = true;
29
- width *= -1;
30
- }
31
-
32
- // @TODO: Check range is valid for value
33
- return new Typed(_gaurd, `${ signed ? "": "u" }int${ width }`, value, { signed, width });
34
- }
35
-
36
- function b(value: BytesLike, size?: number): Typed {
37
- // @TODO: Check range is valid for value
38
- return new Typed(_gaurd, `bytes${ (size) ? size: "" }`, value, { size });
39
- }
40
-
41
- // @TODO: Remove this in v7, it was replaced by TypedBigInt
42
- /**
43
- * @_ignore:
44
- */
45
- export interface TypedNumber extends Typed {
46
- value: number;
47
- defaultValue(): number;
48
- minValue(): number;
49
- maxValue(): number;
50
- }
51
-
52
- /**
53
- * A **Typed** that represents a numeric value.
54
- */
55
- export interface TypedBigInt extends Typed {
56
- /**
57
- * The value.
58
- */
59
- value: bigint;
60
-
61
- /**
62
- * The default value for all numeric types is ``0``.
63
- */
64
- defaultValue(): bigint;
65
-
66
- /**
67
- * The minimum value for this type, accounting for bit-width and signed-ness.
68
- */
69
- minValue(): bigint;
70
-
71
- /**
72
- * The minimum value for this type, accounting for bit-width.
73
- */
74
- maxValue(): bigint;
75
- }
76
-
77
- /**
78
- * A **Typed** that represents a binary sequence of data as bytes.
79
- */
80
- export interface TypedData extends Typed {
81
- /**
82
- * The value.
83
- */
84
- value: string;
85
-
86
- /**
87
- * The default value for this type.
88
- */
89
- defaultValue(): string;
90
- }
91
-
92
- /**
93
- * A **Typed** that represents a UTF-8 sequence of bytes.
94
- */
95
- export interface TypedString extends Typed {
96
- /**
97
- * The value.
98
- */
99
- value: string;
100
-
101
- /**
102
- * The default value for the string type is the empty string (i.e. ``""``).
103
- */
104
- defaultValue(): string;
105
- }
106
-
107
- const _typedSymbol = Symbol.for("_ethers_typed");
108
-
109
- /**
110
- * The **Typed** class to wrap values providing explicit type information.
111
- */
112
- export class Typed {
113
-
114
- /**
115
- * The type, as a Solidity-compatible type.
116
- */
117
- readonly type!: string;
118
-
119
- /**
120
- * The actual value.
121
- */
122
- readonly value!: any;
123
-
124
- readonly #options: any;
125
-
126
- /**
127
- * @_ignore:
128
- */
129
- readonly _typedSymbol!: Symbol;
130
-
131
- /**
132
- * @_ignore:
133
- */
134
- constructor(gaurd: any, type: string, value: any, options?: any) {
135
- if (options == null) { options = null; }
136
- assertPrivate(_gaurd, gaurd, "Typed");
137
- defineProperties<Typed>(this, { _typedSymbol, type, value });
138
- this.#options = options;
139
-
140
- // Check the value is valid
141
- this.format();
142
- }
143
-
144
- /**
145
- * Format the type as a Human-Readable type.
146
- */
147
- format(): string {
148
- if (this.type === "array") {
149
- throw new Error("");
150
- } else if (this.type === "dynamicArray") {
151
- throw new Error("");
152
- } else if (this.type === "tuple") {
153
- return `tuple(${ this.value.map((v: Typed) => v.format()).join(",") })`
154
- }
155
-
156
- return this.type;
157
- }
158
-
159
- /**
160
- * The default value returned by this type.
161
- */
162
- defaultValue(): string | number | bigint | Result {
163
- return 0;
164
- }
165
-
166
- /**
167
- * The minimum value for numeric types.
168
- */
169
- minValue(): string | number | bigint {
170
- return 0;
171
- }
172
-
173
- /**
174
- * The maximum value for numeric types.
175
- */
176
- maxValue(): string | number | bigint {
177
- return 0;
178
- }
179
-
180
- /**
181
- * Returns ``true`` and provides a type guard is this is a [[TypedBigInt]].
182
- */
183
- isBigInt(): this is TypedBigInt {
184
- return !!(this.type.match(/^u?int[0-9]+$/));
185
- }
186
-
187
- /**
188
- * Returns ``true`` and provides a type guard is this is a [[TypedData]].
189
- */
190
- isData(): this is TypedData {
191
- return this.type.startsWith("bytes");
192
- }
193
-
194
- /**
195
- * Returns ``true`` and provides a type guard is this is a [[TypedString]].
196
- */
197
- isString(): this is TypedString {
198
- return (this.type === "string");
199
- }
200
-
201
- /**
202
- * Returns the tuple name, if this is a tuple. Throws otherwise.
203
- */
204
- get tupleName(): null | string {
205
- if (this.type !== "tuple") { throw TypeError("not a tuple"); }
206
- return this.#options;
207
- }
208
-
209
- // Returns the length of this type as an array
210
- // - `null` indicates the length is unforced, it could be dynamic
211
- // - `-1` indicates the length is dynamic
212
- // - any other value indicates it is a static array and is its length
213
-
214
- /**
215
- * Returns the length of the array type or ``-1`` if it is dynamic.
216
- *
217
- * Throws if the type is not an array.
218
- */
219
- get arrayLength(): null | number {
220
- if (this.type !== "array") { throw TypeError("not an array"); }
221
- if (this.#options === true) { return -1; }
222
- if (this.#options === false) { return (<Array<any>>(this.value)).length; }
223
- return null;
224
- }
225
-
226
- /**
227
- * Returns a new **Typed** of %%type%% with the %%value%%.
228
- */
229
- static from(type: string, value: any): Typed {
230
- return new Typed(_gaurd, type, value);
231
- }
232
-
233
- /**
234
- * Return a new ``uint8`` type for %%v%%.
235
- */
236
- static uint8(v: BigNumberish): Typed { return n(v, 8); }
237
-
238
- /**
239
- * Return a new ``uint16`` type for %%v%%.
240
- */
241
- static uint16(v: BigNumberish): Typed { return n(v, 16); }
242
-
243
- /**
244
- * Return a new ``uint24`` type for %%v%%.
245
- */
246
- static uint24(v: BigNumberish): Typed { return n(v, 24); }
247
-
248
- /**
249
- * Return a new ``uint32`` type for %%v%%.
250
- */
251
- static uint32(v: BigNumberish): Typed { return n(v, 32); }
252
-
253
- /**
254
- * Return a new ``uint40`` type for %%v%%.
255
- */
256
- static uint40(v: BigNumberish): Typed { return n(v, 40); }
257
-
258
- /**
259
- * Return a new ``uint48`` type for %%v%%.
260
- */
261
- static uint48(v: BigNumberish): Typed { return n(v, 48); }
262
-
263
- /**
264
- * Return a new ``uint56`` type for %%v%%.
265
- */
266
- static uint56(v: BigNumberish): Typed { return n(v, 56); }
267
-
268
- /**
269
- * Return a new ``uint64`` type for %%v%%.
270
- */
271
- static uint64(v: BigNumberish): Typed { return n(v, 64); }
272
-
273
- /**
274
- * Return a new ``uint72`` type for %%v%%.
275
- */
276
- static uint72(v: BigNumberish): Typed { return n(v, 72); }
277
-
278
- /**
279
- * Return a new ``uint80`` type for %%v%%.
280
- */
281
- static uint80(v: BigNumberish): Typed { return n(v, 80); }
282
-
283
- /**
284
- * Return a new ``uint88`` type for %%v%%.
285
- */
286
- static uint88(v: BigNumberish): Typed { return n(v, 88); }
287
-
288
- /**
289
- * Return a new ``uint96`` type for %%v%%.
290
- */
291
- static uint96(v: BigNumberish): Typed { return n(v, 96); }
292
-
293
- /**
294
- * Return a new ``uint104`` type for %%v%%.
295
- */
296
- static uint104(v: BigNumberish): Typed { return n(v, 104); }
297
-
298
- /**
299
- * Return a new ``uint112`` type for %%v%%.
300
- */
301
- static uint112(v: BigNumberish): Typed { return n(v, 112); }
302
-
303
- /**
304
- * Return a new ``uint120`` type for %%v%%.
305
- */
306
- static uint120(v: BigNumberish): Typed { return n(v, 120); }
307
-
308
- /**
309
- * Return a new ``uint128`` type for %%v%%.
310
- */
311
- static uint128(v: BigNumberish): Typed { return n(v, 128); }
312
-
313
- /**
314
- * Return a new ``uint136`` type for %%v%%.
315
- */
316
- static uint136(v: BigNumberish): Typed { return n(v, 136); }
317
-
318
- /**
319
- * Return a new ``uint144`` type for %%v%%.
320
- */
321
- static uint144(v: BigNumberish): Typed { return n(v, 144); }
322
-
323
- /**
324
- * Return a new ``uint152`` type for %%v%%.
325
- */
326
- static uint152(v: BigNumberish): Typed { return n(v, 152); }
327
-
328
- /**
329
- * Return a new ``uint160`` type for %%v%%.
330
- */
331
- static uint160(v: BigNumberish): Typed { return n(v, 160); }
332
-
333
- /**
334
- * Return a new ``uint168`` type for %%v%%.
335
- */
336
- static uint168(v: BigNumberish): Typed { return n(v, 168); }
337
-
338
- /**
339
- * Return a new ``uint176`` type for %%v%%.
340
- */
341
- static uint176(v: BigNumberish): Typed { return n(v, 176); }
342
-
343
- /**
344
- * Return a new ``uint184`` type for %%v%%.
345
- */
346
- static uint184(v: BigNumberish): Typed { return n(v, 184); }
347
-
348
- /**
349
- * Return a new ``uint192`` type for %%v%%.
350
- */
351
- static uint192(v: BigNumberish): Typed { return n(v, 192); }
352
-
353
- /**
354
- * Return a new ``uint200`` type for %%v%%.
355
- */
356
- static uint200(v: BigNumberish): Typed { return n(v, 200); }
357
-
358
- /**
359
- * Return a new ``uint208`` type for %%v%%.
360
- */
361
- static uint208(v: BigNumberish): Typed { return n(v, 208); }
362
-
363
- /**
364
- * Return a new ``uint216`` type for %%v%%.
365
- */
366
- static uint216(v: BigNumberish): Typed { return n(v, 216); }
367
-
368
- /**
369
- * Return a new ``uint224`` type for %%v%%.
370
- */
371
- static uint224(v: BigNumberish): Typed { return n(v, 224); }
372
-
373
- /**
374
- * Return a new ``uint232`` type for %%v%%.
375
- */
376
- static uint232(v: BigNumberish): Typed { return n(v, 232); }
377
-
378
- /**
379
- * Return a new ``uint240`` type for %%v%%.
380
- */
381
- static uint240(v: BigNumberish): Typed { return n(v, 240); }
382
-
383
- /**
384
- * Return a new ``uint248`` type for %%v%%.
385
- */
386
- static uint248(v: BigNumberish): Typed { return n(v, 248); }
387
-
388
- /**
389
- * Return a new ``uint256`` type for %%v%%.
390
- */
391
- static uint256(v: BigNumberish): Typed { return n(v, 256); }
392
-
393
- /**
394
- * Return a new ``uint256`` type for %%v%%.
395
- */
396
- static uint(v: BigNumberish): Typed { return n(v, 256); }
397
-
398
- /**
399
- * Return a new ``int8`` type for %%v%%.
400
- */
401
- static int8(v: BigNumberish): Typed { return n(v, -8); }
402
-
403
- /**
404
- * Return a new ``int16`` type for %%v%%.
405
- */
406
- static int16(v: BigNumberish): Typed { return n(v, -16); }
407
-
408
- /**
409
- * Return a new ``int24`` type for %%v%%.
410
- */
411
- static int24(v: BigNumberish): Typed { return n(v, -24); }
412
-
413
- /**
414
- * Return a new ``int32`` type for %%v%%.
415
- */
416
- static int32(v: BigNumberish): Typed { return n(v, -32); }
417
-
418
- /**
419
- * Return a new ``int40`` type for %%v%%.
420
- */
421
- static int40(v: BigNumberish): Typed { return n(v, -40); }
422
-
423
- /**
424
- * Return a new ``int48`` type for %%v%%.
425
- */
426
- static int48(v: BigNumberish): Typed { return n(v, -48); }
427
-
428
- /**
429
- * Return a new ``int56`` type for %%v%%.
430
- */
431
- static int56(v: BigNumberish): Typed { return n(v, -56); }
432
-
433
- /**
434
- * Return a new ``int64`` type for %%v%%.
435
- */
436
- static int64(v: BigNumberish): Typed { return n(v, -64); }
437
-
438
- /**
439
- * Return a new ``int72`` type for %%v%%.
440
- */
441
- static int72(v: BigNumberish): Typed { return n(v, -72); }
442
-
443
- /**
444
- * Return a new ``int80`` type for %%v%%.
445
- */
446
- static int80(v: BigNumberish): Typed { return n(v, -80); }
447
-
448
- /**
449
- * Return a new ``int88`` type for %%v%%.
450
- */
451
- static int88(v: BigNumberish): Typed { return n(v, -88); }
452
-
453
- /**
454
- * Return a new ``int96`` type for %%v%%.
455
- */
456
- static int96(v: BigNumberish): Typed { return n(v, -96); }
457
-
458
- /**
459
- * Return a new ``int104`` type for %%v%%.
460
- */
461
- static int104(v: BigNumberish): Typed { return n(v, -104); }
462
-
463
- /**
464
- * Return a new ``int112`` type for %%v%%.
465
- */
466
- static int112(v: BigNumberish): Typed { return n(v, -112); }
467
-
468
- /**
469
- * Return a new ``int120`` type for %%v%%.
470
- */
471
- static int120(v: BigNumberish): Typed { return n(v, -120); }
472
-
473
- /**
474
- * Return a new ``int128`` type for %%v%%.
475
- */
476
- static int128(v: BigNumberish): Typed { return n(v, -128); }
477
-
478
- /**
479
- * Return a new ``int136`` type for %%v%%.
480
- */
481
- static int136(v: BigNumberish): Typed { return n(v, -136); }
482
-
483
- /**
484
- * Return a new ``int144`` type for %%v%%.
485
- */
486
- static int144(v: BigNumberish): Typed { return n(v, -144); }
487
-
488
- /**
489
- * Return a new ``int52`` type for %%v%%.
490
- */
491
- static int152(v: BigNumberish): Typed { return n(v, -152); }
492
-
493
- /**
494
- * Return a new ``int160`` type for %%v%%.
495
- */
496
- static int160(v: BigNumberish): Typed { return n(v, -160); }
497
-
498
- /**
499
- * Return a new ``int168`` type for %%v%%.
500
- */
501
- static int168(v: BigNumberish): Typed { return n(v, -168); }
502
-
503
- /**
504
- * Return a new ``int176`` type for %%v%%.
505
- */
506
- static int176(v: BigNumberish): Typed { return n(v, -176); }
507
-
508
- /**
509
- * Return a new ``int184`` type for %%v%%.
510
- */
511
- static int184(v: BigNumberish): Typed { return n(v, -184); }
512
-
513
- /**
514
- * Return a new ``int92`` type for %%v%%.
515
- */
516
- static int192(v: BigNumberish): Typed { return n(v, -192); }
517
-
518
- /**
519
- * Return a new ``int200`` type for %%v%%.
520
- */
521
- static int200(v: BigNumberish): Typed { return n(v, -200); }
522
-
523
- /**
524
- * Return a new ``int208`` type for %%v%%.
525
- */
526
- static int208(v: BigNumberish): Typed { return n(v, -208); }
527
-
528
- /**
529
- * Return a new ``int216`` type for %%v%%.
530
- */
531
- static int216(v: BigNumberish): Typed { return n(v, -216); }
532
-
533
- /**
534
- * Return a new ``int224`` type for %%v%%.
535
- */
536
- static int224(v: BigNumberish): Typed { return n(v, -224); }
537
-
538
- /**
539
- * Return a new ``int232`` type for %%v%%.
540
- */
541
- static int232(v: BigNumberish): Typed { return n(v, -232); }
542
-
543
- /**
544
- * Return a new ``int240`` type for %%v%%.
545
- */
546
- static int240(v: BigNumberish): Typed { return n(v, -240); }
547
-
548
- /**
549
- * Return a new ``int248`` type for %%v%%.
550
- */
551
- static int248(v: BigNumberish): Typed { return n(v, -248); }
552
-
553
- /**
554
- * Return a new ``int256`` type for %%v%%.
555
- */
556
- static int256(v: BigNumberish): Typed { return n(v, -256); }
557
-
558
- /**
559
- * Return a new ``int256`` type for %%v%%.
560
- */
561
- static int(v: BigNumberish): Typed { return n(v, -256); }
562
-
563
- /**
564
- * Return a new ``bytes1`` type for %%v%%.
565
- */
566
- static bytes1(v: BytesLike): Typed { return b(v, 1); }
567
-
568
- /**
569
- * Return a new ``bytes2`` type for %%v%%.
570
- */
571
- static bytes2(v: BytesLike): Typed { return b(v, 2); }
572
-
573
- /**
574
- * Return a new ``bytes3`` type for %%v%%.
575
- */
576
- static bytes3(v: BytesLike): Typed { return b(v, 3); }
577
-
578
- /**
579
- * Return a new ``bytes4`` type for %%v%%.
580
- */
581
- static bytes4(v: BytesLike): Typed { return b(v, 4); }
582
-
583
- /**
584
- * Return a new ``bytes5`` type for %%v%%.
585
- */
586
- static bytes5(v: BytesLike): Typed { return b(v, 5); }
587
-
588
- /**
589
- * Return a new ``bytes6`` type for %%v%%.
590
- */
591
- static bytes6(v: BytesLike): Typed { return b(v, 6); }
592
-
593
- /**
594
- * Return a new ``bytes7`` type for %%v%%.
595
- */
596
- static bytes7(v: BytesLike): Typed { return b(v, 7); }
597
-
598
- /**
599
- * Return a new ``bytes8`` type for %%v%%.
600
- */
601
- static bytes8(v: BytesLike): Typed { return b(v, 8); }
602
-
603
- /**
604
- * Return a new ``bytes9`` type for %%v%%.
605
- */
606
- static bytes9(v: BytesLike): Typed { return b(v, 9); }
607
-
608
- /**
609
- * Return a new ``bytes10`` type for %%v%%.
610
- */
611
- static bytes10(v: BytesLike): Typed { return b(v, 10); }
612
-
613
- /**
614
- * Return a new ``bytes11`` type for %%v%%.
615
- */
616
- static bytes11(v: BytesLike): Typed { return b(v, 11); }
617
-
618
- /**
619
- * Return a new ``bytes12`` type for %%v%%.
620
- */
621
- static bytes12(v: BytesLike): Typed { return b(v, 12); }
622
-
623
- /**
624
- * Return a new ``bytes13`` type for %%v%%.
625
- */
626
- static bytes13(v: BytesLike): Typed { return b(v, 13); }
627
-
628
- /**
629
- * Return a new ``bytes14`` type for %%v%%.
630
- */
631
- static bytes14(v: BytesLike): Typed { return b(v, 14); }
632
-
633
- /**
634
- * Return a new ``bytes15`` type for %%v%%.
635
- */
636
- static bytes15(v: BytesLike): Typed { return b(v, 15); }
637
-
638
- /**
639
- * Return a new ``bytes16`` type for %%v%%.
640
- */
641
- static bytes16(v: BytesLike): Typed { return b(v, 16); }
642
-
643
- /**
644
- * Return a new ``bytes17`` type for %%v%%.
645
- */
646
- static bytes17(v: BytesLike): Typed { return b(v, 17); }
647
-
648
- /**
649
- * Return a new ``bytes18`` type for %%v%%.
650
- */
651
- static bytes18(v: BytesLike): Typed { return b(v, 18); }
652
-
653
- /**
654
- * Return a new ``bytes19`` type for %%v%%.
655
- */
656
- static bytes19(v: BytesLike): Typed { return b(v, 19); }
657
-
658
- /**
659
- * Return a new ``bytes20`` type for %%v%%.
660
- */
661
- static bytes20(v: BytesLike): Typed { return b(v, 20); }
662
-
663
- /**
664
- * Return a new ``bytes21`` type for %%v%%.
665
- */
666
- static bytes21(v: BytesLike): Typed { return b(v, 21); }
667
-
668
- /**
669
- * Return a new ``bytes22`` type for %%v%%.
670
- */
671
- static bytes22(v: BytesLike): Typed { return b(v, 22); }
672
-
673
- /**
674
- * Return a new ``bytes23`` type for %%v%%.
675
- */
676
- static bytes23(v: BytesLike): Typed { return b(v, 23); }
677
-
678
- /**
679
- * Return a new ``bytes24`` type for %%v%%.
680
- */
681
- static bytes24(v: BytesLike): Typed { return b(v, 24); }
682
-
683
- /**
684
- * Return a new ``bytes25`` type for %%v%%.
685
- */
686
- static bytes25(v: BytesLike): Typed { return b(v, 25); }
687
-
688
- /**
689
- * Return a new ``bytes26`` type for %%v%%.
690
- */
691
- static bytes26(v: BytesLike): Typed { return b(v, 26); }
692
-
693
- /**
694
- * Return a new ``bytes27`` type for %%v%%.
695
- */
696
- static bytes27(v: BytesLike): Typed { return b(v, 27); }
697
-
698
- /**
699
- * Return a new ``bytes28`` type for %%v%%.
700
- */
701
- static bytes28(v: BytesLike): Typed { return b(v, 28); }
702
-
703
- /**
704
- * Return a new ``bytes29`` type for %%v%%.
705
- */
706
- static bytes29(v: BytesLike): Typed { return b(v, 29); }
707
-
708
- /**
709
- * Return a new ``bytes30`` type for %%v%%.
710
- */
711
- static bytes30(v: BytesLike): Typed { return b(v, 30); }
712
-
713
- /**
714
- * Return a new ``bytes31`` type for %%v%%.
715
- */
716
- static bytes31(v: BytesLike): Typed { return b(v, 31); }
717
-
718
- /**
719
- * Return a new ``bytes32`` type for %%v%%.
720
- */
721
- static bytes32(v: BytesLike): Typed { return b(v, 32); }
722
-
723
-
724
- /**
725
- * Return a new ``address`` type for %%v%%.
726
- */
727
- static address(v: string | Addressable): Typed { return new Typed(_gaurd, "address", v); }
728
-
729
- /**
730
- * Return a new ``bool`` type for %%v%%.
731
- */
732
- static bool(v: any): Typed { return new Typed(_gaurd, "bool", !!v); }
733
-
734
- /**
735
- * Return a new ``bytes`` type for %%v%%.
736
- */
737
- static bytes(v: BytesLike): Typed { return new Typed(_gaurd, "bytes", v); }
738
-
739
- /**
740
- * Return a new ``string`` type for %%v%%.
741
- */
742
- static string(v: string): Typed { return new Typed(_gaurd, "string", v); }
743
-
744
-
745
- /**
746
- * Return a new ``array`` type for %%v%%, allowing %%dynamic%% length.
747
- */
748
- static array(v: Array<any | Typed>, dynamic?: null | boolean): Typed {
749
- throw new Error("not implemented yet");
750
- return new Typed(_gaurd, "array", v, dynamic);
751
- }
752
-
753
-
754
- /**
755
- * Return a new ``tuple`` type for %%v%%, with the optional %%name%%.
756
- */
757
- static tuple(v: Array<any | Typed> | Record<string, any | Typed>, name?: string): Typed {
758
- throw new Error("not implemented yet");
759
- return new Typed(_gaurd, "tuple", v, name);
760
- }
761
-
762
-
763
- /**
764
- * Return a new ``uint8`` type for %%v%%.
765
- */
766
- static overrides(v: Record<string, any>): Typed {
767
- return new Typed(_gaurd, "overrides", Object.assign({ }, v));
768
- }
769
-
770
- /**
771
- * Returns true only if %%value%% is a [[Typed]] instance.
772
- */
773
- static isTyped(value: any): value is Typed {
774
- return (value
775
- && typeof(value) === "object"
776
- && "_typedSymbol" in value
777
- && value._typedSymbol === _typedSymbol);
778
- }
779
-
780
- /**
781
- * If the value is a [[Typed]] instance, validates the underlying value
782
- * and returns it, otherwise returns value directly.
783
- *
784
- * This is useful for functions that with to accept either a [[Typed]]
785
- * object or values.
786
- */
787
- static dereference<T>(value: Typed | T, type: string): T {
788
- if (Typed.isTyped(value)) {
789
- if (value.type !== type) {
790
- throw new Error(`invalid type: expecetd ${ type }, got ${ value.type }`);
791
- }
792
- return value.value;
793
- }
794
- return value;
795
- }
796
- }
1
+ /**
2
+ * A Typed object allows a value to have its type explicitly
3
+ * specified.
4
+ *
5
+ * For example, in Solidity, the value ``45`` could represent a
6
+ * ``uint8`` or a ``uint256``. The value ``0x1234`` could represent
7
+ * a ``bytes2`` or ``bytes``.
8
+ *
9
+ * Since JavaScript has no meaningful way to explicitly inform any
10
+ * APIs which what the type is, this allows transparent interoperation
11
+ * with Soldity.
12
+ *
13
+ * @_subsection: api/abi:Typed Values
14
+ */
15
+
16
+ import { assertPrivate, defineProperties } from "../utils/index.js";
17
+
18
+ import type { Addressable } from "../address/index.js";
19
+ import type { BigNumberish, BytesLike } from "../utils/index.js";
20
+
21
+ import type { Result } from "./coders/abstract-coder.js";
22
+
23
+ const _gaurd = { };
24
+
25
+ function n(value: BigNumberish, width: number): Typed {
26
+ let signed = false;
27
+ if (width < 0) {
28
+ signed = true;
29
+ width *= -1;
30
+ }
31
+
32
+ // @TODO: Check range is valid for value
33
+ return new Typed(_gaurd, `${ signed ? "": "u" }int${ width }`, value, { signed, width });
34
+ }
35
+
36
+ function b(value: BytesLike, size?: number): Typed {
37
+ // @TODO: Check range is valid for value
38
+ return new Typed(_gaurd, `bytes${ (size) ? size: "" }`, value, { size });
39
+ }
40
+
41
+ // @TODO: Remove this in v7, it was replaced by TypedBigInt
42
+ /**
43
+ * @_ignore:
44
+ */
45
+ export interface TypedNumber extends Typed {
46
+ value: number;
47
+ defaultValue(): number;
48
+ minValue(): number;
49
+ maxValue(): number;
50
+ }
51
+
52
+ /**
53
+ * A **Typed** that represents a numeric value.
54
+ */
55
+ export interface TypedBigInt extends Typed {
56
+ /**
57
+ * The value.
58
+ */
59
+ value: bigint;
60
+
61
+ /**
62
+ * The default value for all numeric types is ``0``.
63
+ */
64
+ defaultValue(): bigint;
65
+
66
+ /**
67
+ * The minimum value for this type, accounting for bit-width and signed-ness.
68
+ */
69
+ minValue(): bigint;
70
+
71
+ /**
72
+ * The minimum value for this type, accounting for bit-width.
73
+ */
74
+ maxValue(): bigint;
75
+ }
76
+
77
+ /**
78
+ * A **Typed** that represents a binary sequence of data as bytes.
79
+ */
80
+ export interface TypedData extends Typed {
81
+ /**
82
+ * The value.
83
+ */
84
+ value: string;
85
+
86
+ /**
87
+ * The default value for this type.
88
+ */
89
+ defaultValue(): string;
90
+ }
91
+
92
+ /**
93
+ * A **Typed** that represents a UTF-8 sequence of bytes.
94
+ */
95
+ export interface TypedString extends Typed {
96
+ /**
97
+ * The value.
98
+ */
99
+ value: string;
100
+
101
+ /**
102
+ * The default value for the string type is the empty string (i.e. ``""``).
103
+ */
104
+ defaultValue(): string;
105
+ }
106
+
107
+ const _typedSymbol = Symbol.for("_ethers_typed");
108
+
109
+ /**
110
+ * The **Typed** class to wrap values providing explicit type information.
111
+ */
112
+ export class Typed {
113
+
114
+ /**
115
+ * The type, as a Solidity-compatible type.
116
+ */
117
+ readonly type!: string;
118
+
119
+ /**
120
+ * The actual value.
121
+ */
122
+ readonly value!: any;
123
+
124
+ readonly #options: any;
125
+
126
+ /**
127
+ * @_ignore:
128
+ */
129
+ readonly _typedSymbol!: Symbol;
130
+
131
+ /**
132
+ * @_ignore:
133
+ */
134
+ constructor(gaurd: any, type: string, value: any, options?: any) {
135
+ if (options == null) { options = null; }
136
+ assertPrivate(_gaurd, gaurd, "Typed");
137
+ defineProperties<Typed>(this, { _typedSymbol, type, value });
138
+ this.#options = options;
139
+
140
+ // Check the value is valid
141
+ this.format();
142
+ }
143
+
144
+ /**
145
+ * Format the type as a Human-Readable type.
146
+ */
147
+ format(): string {
148
+ if (this.type === "array") {
149
+ throw new Error("");
150
+ } else if (this.type === "dynamicArray") {
151
+ throw new Error("");
152
+ } else if (this.type === "tuple") {
153
+ return `tuple(${ this.value.map((v: Typed) => v.format()).join(",") })`
154
+ }
155
+
156
+ return this.type;
157
+ }
158
+
159
+ /**
160
+ * The default value returned by this type.
161
+ */
162
+ defaultValue(): string | number | bigint | Result {
163
+ return 0;
164
+ }
165
+
166
+ /**
167
+ * The minimum value for numeric types.
168
+ */
169
+ minValue(): string | number | bigint {
170
+ return 0;
171
+ }
172
+
173
+ /**
174
+ * The maximum value for numeric types.
175
+ */
176
+ maxValue(): string | number | bigint {
177
+ return 0;
178
+ }
179
+
180
+ /**
181
+ * Returns ``true`` and provides a type guard is this is a [[TypedBigInt]].
182
+ */
183
+ isBigInt(): this is TypedBigInt {
184
+ return !!(this.type.match(/^u?int[0-9]+$/));
185
+ }
186
+
187
+ /**
188
+ * Returns ``true`` and provides a type guard is this is a [[TypedData]].
189
+ */
190
+ isData(): this is TypedData {
191
+ return this.type.startsWith("bytes");
192
+ }
193
+
194
+ /**
195
+ * Returns ``true`` and provides a type guard is this is a [[TypedString]].
196
+ */
197
+ isString(): this is TypedString {
198
+ return (this.type === "string");
199
+ }
200
+
201
+ /**
202
+ * Returns the tuple name, if this is a tuple. Throws otherwise.
203
+ */
204
+ get tupleName(): null | string {
205
+ if (this.type !== "tuple") { throw TypeError("not a tuple"); }
206
+ return this.#options;
207
+ }
208
+
209
+ // Returns the length of this type as an array
210
+ // - `null` indicates the length is unforced, it could be dynamic
211
+ // - `-1` indicates the length is dynamic
212
+ // - any other value indicates it is a static array and is its length
213
+
214
+ /**
215
+ * Returns the length of the array type or ``-1`` if it is dynamic.
216
+ *
217
+ * Throws if the type is not an array.
218
+ */
219
+ get arrayLength(): null | number {
220
+ if (this.type !== "array") { throw TypeError("not an array"); }
221
+ if (this.#options === true) { return -1; }
222
+ if (this.#options === false) { return (<Array<any>>(this.value)).length; }
223
+ return null;
224
+ }
225
+
226
+ /**
227
+ * Returns a new **Typed** of %%type%% with the %%value%%.
228
+ */
229
+ static from(type: string, value: any): Typed {
230
+ return new Typed(_gaurd, type, value);
231
+ }
232
+
233
+ /**
234
+ * Return a new ``uint8`` type for %%v%%.
235
+ */
236
+ static uint8(v: BigNumberish): Typed { return n(v, 8); }
237
+
238
+ /**
239
+ * Return a new ``uint16`` type for %%v%%.
240
+ */
241
+ static uint16(v: BigNumberish): Typed { return n(v, 16); }
242
+
243
+ /**
244
+ * Return a new ``uint24`` type for %%v%%.
245
+ */
246
+ static uint24(v: BigNumberish): Typed { return n(v, 24); }
247
+
248
+ /**
249
+ * Return a new ``uint32`` type for %%v%%.
250
+ */
251
+ static uint32(v: BigNumberish): Typed { return n(v, 32); }
252
+
253
+ /**
254
+ * Return a new ``uint40`` type for %%v%%.
255
+ */
256
+ static uint40(v: BigNumberish): Typed { return n(v, 40); }
257
+
258
+ /**
259
+ * Return a new ``uint48`` type for %%v%%.
260
+ */
261
+ static uint48(v: BigNumberish): Typed { return n(v, 48); }
262
+
263
+ /**
264
+ * Return a new ``uint56`` type for %%v%%.
265
+ */
266
+ static uint56(v: BigNumberish): Typed { return n(v, 56); }
267
+
268
+ /**
269
+ * Return a new ``uint64`` type for %%v%%.
270
+ */
271
+ static uint64(v: BigNumberish): Typed { return n(v, 64); }
272
+
273
+ /**
274
+ * Return a new ``uint72`` type for %%v%%.
275
+ */
276
+ static uint72(v: BigNumberish): Typed { return n(v, 72); }
277
+
278
+ /**
279
+ * Return a new ``uint80`` type for %%v%%.
280
+ */
281
+ static uint80(v: BigNumberish): Typed { return n(v, 80); }
282
+
283
+ /**
284
+ * Return a new ``uint88`` type for %%v%%.
285
+ */
286
+ static uint88(v: BigNumberish): Typed { return n(v, 88); }
287
+
288
+ /**
289
+ * Return a new ``uint96`` type for %%v%%.
290
+ */
291
+ static uint96(v: BigNumberish): Typed { return n(v, 96); }
292
+
293
+ /**
294
+ * Return a new ``uint104`` type for %%v%%.
295
+ */
296
+ static uint104(v: BigNumberish): Typed { return n(v, 104); }
297
+
298
+ /**
299
+ * Return a new ``uint112`` type for %%v%%.
300
+ */
301
+ static uint112(v: BigNumberish): Typed { return n(v, 112); }
302
+
303
+ /**
304
+ * Return a new ``uint120`` type for %%v%%.
305
+ */
306
+ static uint120(v: BigNumberish): Typed { return n(v, 120); }
307
+
308
+ /**
309
+ * Return a new ``uint128`` type for %%v%%.
310
+ */
311
+ static uint128(v: BigNumberish): Typed { return n(v, 128); }
312
+
313
+ /**
314
+ * Return a new ``uint136`` type for %%v%%.
315
+ */
316
+ static uint136(v: BigNumberish): Typed { return n(v, 136); }
317
+
318
+ /**
319
+ * Return a new ``uint144`` type for %%v%%.
320
+ */
321
+ static uint144(v: BigNumberish): Typed { return n(v, 144); }
322
+
323
+ /**
324
+ * Return a new ``uint152`` type for %%v%%.
325
+ */
326
+ static uint152(v: BigNumberish): Typed { return n(v, 152); }
327
+
328
+ /**
329
+ * Return a new ``uint160`` type for %%v%%.
330
+ */
331
+ static uint160(v: BigNumberish): Typed { return n(v, 160); }
332
+
333
+ /**
334
+ * Return a new ``uint168`` type for %%v%%.
335
+ */
336
+ static uint168(v: BigNumberish): Typed { return n(v, 168); }
337
+
338
+ /**
339
+ * Return a new ``uint176`` type for %%v%%.
340
+ */
341
+ static uint176(v: BigNumberish): Typed { return n(v, 176); }
342
+
343
+ /**
344
+ * Return a new ``uint184`` type for %%v%%.
345
+ */
346
+ static uint184(v: BigNumberish): Typed { return n(v, 184); }
347
+
348
+ /**
349
+ * Return a new ``uint192`` type for %%v%%.
350
+ */
351
+ static uint192(v: BigNumberish): Typed { return n(v, 192); }
352
+
353
+ /**
354
+ * Return a new ``uint200`` type for %%v%%.
355
+ */
356
+ static uint200(v: BigNumberish): Typed { return n(v, 200); }
357
+
358
+ /**
359
+ * Return a new ``uint208`` type for %%v%%.
360
+ */
361
+ static uint208(v: BigNumberish): Typed { return n(v, 208); }
362
+
363
+ /**
364
+ * Return a new ``uint216`` type for %%v%%.
365
+ */
366
+ static uint216(v: BigNumberish): Typed { return n(v, 216); }
367
+
368
+ /**
369
+ * Return a new ``uint224`` type for %%v%%.
370
+ */
371
+ static uint224(v: BigNumberish): Typed { return n(v, 224); }
372
+
373
+ /**
374
+ * Return a new ``uint232`` type for %%v%%.
375
+ */
376
+ static uint232(v: BigNumberish): Typed { return n(v, 232); }
377
+
378
+ /**
379
+ * Return a new ``uint240`` type for %%v%%.
380
+ */
381
+ static uint240(v: BigNumberish): Typed { return n(v, 240); }
382
+
383
+ /**
384
+ * Return a new ``uint248`` type for %%v%%.
385
+ */
386
+ static uint248(v: BigNumberish): Typed { return n(v, 248); }
387
+
388
+ /**
389
+ * Return a new ``uint256`` type for %%v%%.
390
+ */
391
+ static uint256(v: BigNumberish): Typed { return n(v, 256); }
392
+
393
+ /**
394
+ * Return a new ``uint256`` type for %%v%%.
395
+ */
396
+ static uint(v: BigNumberish): Typed { return n(v, 256); }
397
+
398
+ /**
399
+ * Return a new ``int8`` type for %%v%%.
400
+ */
401
+ static int8(v: BigNumberish): Typed { return n(v, -8); }
402
+
403
+ /**
404
+ * Return a new ``int16`` type for %%v%%.
405
+ */
406
+ static int16(v: BigNumberish): Typed { return n(v, -16); }
407
+
408
+ /**
409
+ * Return a new ``int24`` type for %%v%%.
410
+ */
411
+ static int24(v: BigNumberish): Typed { return n(v, -24); }
412
+
413
+ /**
414
+ * Return a new ``int32`` type for %%v%%.
415
+ */
416
+ static int32(v: BigNumberish): Typed { return n(v, -32); }
417
+
418
+ /**
419
+ * Return a new ``int40`` type for %%v%%.
420
+ */
421
+ static int40(v: BigNumberish): Typed { return n(v, -40); }
422
+
423
+ /**
424
+ * Return a new ``int48`` type for %%v%%.
425
+ */
426
+ static int48(v: BigNumberish): Typed { return n(v, -48); }
427
+
428
+ /**
429
+ * Return a new ``int56`` type for %%v%%.
430
+ */
431
+ static int56(v: BigNumberish): Typed { return n(v, -56); }
432
+
433
+ /**
434
+ * Return a new ``int64`` type for %%v%%.
435
+ */
436
+ static int64(v: BigNumberish): Typed { return n(v, -64); }
437
+
438
+ /**
439
+ * Return a new ``int72`` type for %%v%%.
440
+ */
441
+ static int72(v: BigNumberish): Typed { return n(v, -72); }
442
+
443
+ /**
444
+ * Return a new ``int80`` type for %%v%%.
445
+ */
446
+ static int80(v: BigNumberish): Typed { return n(v, -80); }
447
+
448
+ /**
449
+ * Return a new ``int88`` type for %%v%%.
450
+ */
451
+ static int88(v: BigNumberish): Typed { return n(v, -88); }
452
+
453
+ /**
454
+ * Return a new ``int96`` type for %%v%%.
455
+ */
456
+ static int96(v: BigNumberish): Typed { return n(v, -96); }
457
+
458
+ /**
459
+ * Return a new ``int104`` type for %%v%%.
460
+ */
461
+ static int104(v: BigNumberish): Typed { return n(v, -104); }
462
+
463
+ /**
464
+ * Return a new ``int112`` type for %%v%%.
465
+ */
466
+ static int112(v: BigNumberish): Typed { return n(v, -112); }
467
+
468
+ /**
469
+ * Return a new ``int120`` type for %%v%%.
470
+ */
471
+ static int120(v: BigNumberish): Typed { return n(v, -120); }
472
+
473
+ /**
474
+ * Return a new ``int128`` type for %%v%%.
475
+ */
476
+ static int128(v: BigNumberish): Typed { return n(v, -128); }
477
+
478
+ /**
479
+ * Return a new ``int136`` type for %%v%%.
480
+ */
481
+ static int136(v: BigNumberish): Typed { return n(v, -136); }
482
+
483
+ /**
484
+ * Return a new ``int144`` type for %%v%%.
485
+ */
486
+ static int144(v: BigNumberish): Typed { return n(v, -144); }
487
+
488
+ /**
489
+ * Return a new ``int52`` type for %%v%%.
490
+ */
491
+ static int152(v: BigNumberish): Typed { return n(v, -152); }
492
+
493
+ /**
494
+ * Return a new ``int160`` type for %%v%%.
495
+ */
496
+ static int160(v: BigNumberish): Typed { return n(v, -160); }
497
+
498
+ /**
499
+ * Return a new ``int168`` type for %%v%%.
500
+ */
501
+ static int168(v: BigNumberish): Typed { return n(v, -168); }
502
+
503
+ /**
504
+ * Return a new ``int176`` type for %%v%%.
505
+ */
506
+ static int176(v: BigNumberish): Typed { return n(v, -176); }
507
+
508
+ /**
509
+ * Return a new ``int184`` type for %%v%%.
510
+ */
511
+ static int184(v: BigNumberish): Typed { return n(v, -184); }
512
+
513
+ /**
514
+ * Return a new ``int92`` type for %%v%%.
515
+ */
516
+ static int192(v: BigNumberish): Typed { return n(v, -192); }
517
+
518
+ /**
519
+ * Return a new ``int200`` type for %%v%%.
520
+ */
521
+ static int200(v: BigNumberish): Typed { return n(v, -200); }
522
+
523
+ /**
524
+ * Return a new ``int208`` type for %%v%%.
525
+ */
526
+ static int208(v: BigNumberish): Typed { return n(v, -208); }
527
+
528
+ /**
529
+ * Return a new ``int216`` type for %%v%%.
530
+ */
531
+ static int216(v: BigNumberish): Typed { return n(v, -216); }
532
+
533
+ /**
534
+ * Return a new ``int224`` type for %%v%%.
535
+ */
536
+ static int224(v: BigNumberish): Typed { return n(v, -224); }
537
+
538
+ /**
539
+ * Return a new ``int232`` type for %%v%%.
540
+ */
541
+ static int232(v: BigNumberish): Typed { return n(v, -232); }
542
+
543
+ /**
544
+ * Return a new ``int240`` type for %%v%%.
545
+ */
546
+ static int240(v: BigNumberish): Typed { return n(v, -240); }
547
+
548
+ /**
549
+ * Return a new ``int248`` type for %%v%%.
550
+ */
551
+ static int248(v: BigNumberish): Typed { return n(v, -248); }
552
+
553
+ /**
554
+ * Return a new ``int256`` type for %%v%%.
555
+ */
556
+ static int256(v: BigNumberish): Typed { return n(v, -256); }
557
+
558
+ /**
559
+ * Return a new ``int256`` type for %%v%%.
560
+ */
561
+ static int(v: BigNumberish): Typed { return n(v, -256); }
562
+
563
+ /**
564
+ * Return a new ``bytes1`` type for %%v%%.
565
+ */
566
+ static bytes1(v: BytesLike): Typed { return b(v, 1); }
567
+
568
+ /**
569
+ * Return a new ``bytes2`` type for %%v%%.
570
+ */
571
+ static bytes2(v: BytesLike): Typed { return b(v, 2); }
572
+
573
+ /**
574
+ * Return a new ``bytes3`` type for %%v%%.
575
+ */
576
+ static bytes3(v: BytesLike): Typed { return b(v, 3); }
577
+
578
+ /**
579
+ * Return a new ``bytes4`` type for %%v%%.
580
+ */
581
+ static bytes4(v: BytesLike): Typed { return b(v, 4); }
582
+
583
+ /**
584
+ * Return a new ``bytes5`` type for %%v%%.
585
+ */
586
+ static bytes5(v: BytesLike): Typed { return b(v, 5); }
587
+
588
+ /**
589
+ * Return a new ``bytes6`` type for %%v%%.
590
+ */
591
+ static bytes6(v: BytesLike): Typed { return b(v, 6); }
592
+
593
+ /**
594
+ * Return a new ``bytes7`` type for %%v%%.
595
+ */
596
+ static bytes7(v: BytesLike): Typed { return b(v, 7); }
597
+
598
+ /**
599
+ * Return a new ``bytes8`` type for %%v%%.
600
+ */
601
+ static bytes8(v: BytesLike): Typed { return b(v, 8); }
602
+
603
+ /**
604
+ * Return a new ``bytes9`` type for %%v%%.
605
+ */
606
+ static bytes9(v: BytesLike): Typed { return b(v, 9); }
607
+
608
+ /**
609
+ * Return a new ``bytes10`` type for %%v%%.
610
+ */
611
+ static bytes10(v: BytesLike): Typed { return b(v, 10); }
612
+
613
+ /**
614
+ * Return a new ``bytes11`` type for %%v%%.
615
+ */
616
+ static bytes11(v: BytesLike): Typed { return b(v, 11); }
617
+
618
+ /**
619
+ * Return a new ``bytes12`` type for %%v%%.
620
+ */
621
+ static bytes12(v: BytesLike): Typed { return b(v, 12); }
622
+
623
+ /**
624
+ * Return a new ``bytes13`` type for %%v%%.
625
+ */
626
+ static bytes13(v: BytesLike): Typed { return b(v, 13); }
627
+
628
+ /**
629
+ * Return a new ``bytes14`` type for %%v%%.
630
+ */
631
+ static bytes14(v: BytesLike): Typed { return b(v, 14); }
632
+
633
+ /**
634
+ * Return a new ``bytes15`` type for %%v%%.
635
+ */
636
+ static bytes15(v: BytesLike): Typed { return b(v, 15); }
637
+
638
+ /**
639
+ * Return a new ``bytes16`` type for %%v%%.
640
+ */
641
+ static bytes16(v: BytesLike): Typed { return b(v, 16); }
642
+
643
+ /**
644
+ * Return a new ``bytes17`` type for %%v%%.
645
+ */
646
+ static bytes17(v: BytesLike): Typed { return b(v, 17); }
647
+
648
+ /**
649
+ * Return a new ``bytes18`` type for %%v%%.
650
+ */
651
+ static bytes18(v: BytesLike): Typed { return b(v, 18); }
652
+
653
+ /**
654
+ * Return a new ``bytes19`` type for %%v%%.
655
+ */
656
+ static bytes19(v: BytesLike): Typed { return b(v, 19); }
657
+
658
+ /**
659
+ * Return a new ``bytes20`` type for %%v%%.
660
+ */
661
+ static bytes20(v: BytesLike): Typed { return b(v, 20); }
662
+
663
+ /**
664
+ * Return a new ``bytes21`` type for %%v%%.
665
+ */
666
+ static bytes21(v: BytesLike): Typed { return b(v, 21); }
667
+
668
+ /**
669
+ * Return a new ``bytes22`` type for %%v%%.
670
+ */
671
+ static bytes22(v: BytesLike): Typed { return b(v, 22); }
672
+
673
+ /**
674
+ * Return a new ``bytes23`` type for %%v%%.
675
+ */
676
+ static bytes23(v: BytesLike): Typed { return b(v, 23); }
677
+
678
+ /**
679
+ * Return a new ``bytes24`` type for %%v%%.
680
+ */
681
+ static bytes24(v: BytesLike): Typed { return b(v, 24); }
682
+
683
+ /**
684
+ * Return a new ``bytes25`` type for %%v%%.
685
+ */
686
+ static bytes25(v: BytesLike): Typed { return b(v, 25); }
687
+
688
+ /**
689
+ * Return a new ``bytes26`` type for %%v%%.
690
+ */
691
+ static bytes26(v: BytesLike): Typed { return b(v, 26); }
692
+
693
+ /**
694
+ * Return a new ``bytes27`` type for %%v%%.
695
+ */
696
+ static bytes27(v: BytesLike): Typed { return b(v, 27); }
697
+
698
+ /**
699
+ * Return a new ``bytes28`` type for %%v%%.
700
+ */
701
+ static bytes28(v: BytesLike): Typed { return b(v, 28); }
702
+
703
+ /**
704
+ * Return a new ``bytes29`` type for %%v%%.
705
+ */
706
+ static bytes29(v: BytesLike): Typed { return b(v, 29); }
707
+
708
+ /**
709
+ * Return a new ``bytes30`` type for %%v%%.
710
+ */
711
+ static bytes30(v: BytesLike): Typed { return b(v, 30); }
712
+
713
+ /**
714
+ * Return a new ``bytes31`` type for %%v%%.
715
+ */
716
+ static bytes31(v: BytesLike): Typed { return b(v, 31); }
717
+
718
+ /**
719
+ * Return a new ``bytes32`` type for %%v%%.
720
+ */
721
+ static bytes32(v: BytesLike): Typed { return b(v, 32); }
722
+
723
+
724
+ /**
725
+ * Return a new ``address`` type for %%v%%.
726
+ */
727
+ static address(v: string | Addressable): Typed { return new Typed(_gaurd, "address", v); }
728
+
729
+ /**
730
+ * Return a new ``bool`` type for %%v%%.
731
+ */
732
+ static bool(v: any): Typed { return new Typed(_gaurd, "bool", !!v); }
733
+
734
+ /**
735
+ * Return a new ``bytes`` type for %%v%%.
736
+ */
737
+ static bytes(v: BytesLike): Typed { return new Typed(_gaurd, "bytes", v); }
738
+
739
+ /**
740
+ * Return a new ``string`` type for %%v%%.
741
+ */
742
+ static string(v: string): Typed { return new Typed(_gaurd, "string", v); }
743
+
744
+
745
+ /**
746
+ * Return a new ``array`` type for %%v%%, allowing %%dynamic%% length.
747
+ */
748
+ static array(v: Array<any | Typed>, dynamic?: null | boolean): Typed {
749
+ throw new Error("not implemented yet");
750
+ return new Typed(_gaurd, "array", v, dynamic);
751
+ }
752
+
753
+
754
+ /**
755
+ * Return a new ``tuple`` type for %%v%%, with the optional %%name%%.
756
+ */
757
+ static tuple(v: Array<any | Typed> | Record<string, any | Typed>, name?: string): Typed {
758
+ throw new Error("not implemented yet");
759
+ return new Typed(_gaurd, "tuple", v, name);
760
+ }
761
+
762
+
763
+ /**
764
+ * Return a new ``uint8`` type for %%v%%.
765
+ */
766
+ static overrides(v: Record<string, any>): Typed {
767
+ return new Typed(_gaurd, "overrides", Object.assign({ }, v));
768
+ }
769
+
770
+ /**
771
+ * Returns true only if %%value%% is a [[Typed]] instance.
772
+ */
773
+ static isTyped(value: any): value is Typed {
774
+ return (value
775
+ && typeof(value) === "object"
776
+ && "_typedSymbol" in value
777
+ && value._typedSymbol === _typedSymbol);
778
+ }
779
+
780
+ /**
781
+ * If the value is a [[Typed]] instance, validates the underlying value
782
+ * and returns it, otherwise returns value directly.
783
+ *
784
+ * This is useful for functions that with to accept either a [[Typed]]
785
+ * object or values.
786
+ */
787
+ static dereference<T>(value: Typed | T, type: string): T {
788
+ if (Typed.isTyped(value)) {
789
+ if (value.type !== type) {
790
+ throw new Error(`invalid type: expecetd ${ type }, got ${ value.type }`);
791
+ }
792
+ return value.value;
793
+ }
794
+ return value;
795
+ }
796
+ }