@waku/rln 0.1.4 → 0.1.5-164df63.0

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 (223) hide show
  1. package/README.md +5 -0
  2. package/bundle/_virtual/index2.js +1 -1
  3. package/bundle/index.js +4 -1
  4. package/bundle/packages/rln/dist/contract/abi.js +502 -248
  5. package/bundle/packages/rln/dist/contract/constants.js +5 -4
  6. package/bundle/packages/rln/dist/contract/rln_base_contract.js +483 -0
  7. package/bundle/packages/rln/dist/contract/rln_contract.js +32 -358
  8. package/bundle/packages/rln/dist/contract/types.js +9 -0
  9. package/bundle/packages/rln/dist/create.js +1 -1
  10. package/bundle/packages/rln/dist/credentials_manager.js +215 -0
  11. package/bundle/packages/rln/dist/keystore/cipher.js +3 -3
  12. package/bundle/packages/rln/dist/keystore/keystore.js +12 -7
  13. package/bundle/packages/rln/dist/rln.js +56 -166
  14. package/bundle/packages/rln/dist/utils/bytes.js +8 -2
  15. package/bundle/packages/rln/dist/utils/metamask.js +2 -2
  16. package/bundle/packages/rln/dist/zerokit.js +5 -5
  17. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/checksum.js +3 -3
  18. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/cipher.js +4 -4
  19. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/class.js +7 -7
  20. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/functional.js +7 -7
  21. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/index.js +6 -6
  22. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/kdf.js +5 -5
  23. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/password.js +1 -1
  24. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1 -1
  25. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/schema-validation.js +2 -2
  26. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/lib/types.js +1 -1
  27. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +3 -3
  28. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +7 -7
  29. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +3 -3
  30. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +3 -3
  31. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +3 -3
  32. package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +7 -7
  33. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/_assert.js +1 -1
  34. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/_sha2.js +3 -3
  35. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/_u64.js +1 -1
  36. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/cryptoBrowser.js +1 -1
  37. package/bundle/packages/rln/node_modules/@noble/hashes/esm/_assert.js +43 -0
  38. package/bundle/packages/rln/node_modules/@noble/hashes/esm/_sha2.js +116 -0
  39. package/bundle/packages/rln/node_modules/@noble/hashes/esm/hmac.js +79 -0
  40. package/bundle/packages/rln/node_modules/@noble/hashes/esm/sha256.js +126 -0
  41. package/bundle/packages/rln/node_modules/@noble/hashes/esm/utils.js +43 -0
  42. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/hmac.js +3 -3
  43. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/pbkdf2.js +4 -4
  44. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/scrypt.js +5 -5
  45. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/sha256.js +3 -3
  46. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/sha512.js +4 -4
  47. package/bundle/{node_modules/@chainsafe/bls-keystore → packages/rln}/node_modules/@noble/hashes/utils.js +2 -2
  48. package/dist/.tsbuildinfo +1 -1
  49. package/dist/codec.test-utils.d.ts +36 -0
  50. package/dist/codec.test-utils.js +56 -0
  51. package/dist/codec.test-utils.js.map +1 -0
  52. package/dist/contract/abi.d.ts +21 -17
  53. package/dist/contract/abi.js +502 -248
  54. package/dist/contract/abi.js.map +1 -1
  55. package/dist/contract/constants.d.ts +22 -18
  56. package/dist/contract/constants.js +3 -3
  57. package/dist/contract/constants.js.map +1 -1
  58. package/dist/contract/index.d.ts +1 -0
  59. package/dist/contract/index.js +1 -0
  60. package/dist/contract/index.js.map +1 -1
  61. package/dist/contract/rln_base_contract.d.ts +90 -0
  62. package/dist/contract/rln_base_contract.js +466 -0
  63. package/dist/contract/rln_base_contract.js.map +1 -0
  64. package/dist/contract/rln_contract.d.ts +5 -115
  65. package/dist/contract/rln_contract.js +30 -355
  66. package/dist/contract/rln_contract.js.map +1 -1
  67. package/dist/contract/test-setup.d.ts +26 -0
  68. package/dist/contract/test-setup.js +56 -0
  69. package/dist/contract/test-setup.js.map +1 -0
  70. package/dist/contract/test-utils.d.ts +39 -0
  71. package/dist/contract/test-utils.js +118 -0
  72. package/dist/contract/test-utils.js.map +1 -0
  73. package/dist/contract/types.d.ts +45 -0
  74. package/dist/contract/types.js +8 -0
  75. package/dist/contract/types.js.map +1 -0
  76. package/dist/create.js +1 -1
  77. package/dist/create.js.map +1 -1
  78. package/dist/credentials_manager.d.ts +44 -0
  79. package/dist/credentials_manager.js +197 -0
  80. package/dist/credentials_manager.js.map +1 -0
  81. package/dist/index.d.ts +6 -2
  82. package/dist/index.js +5 -2
  83. package/dist/index.js.map +1 -1
  84. package/dist/keystore/keystore.js +11 -6
  85. package/dist/keystore/keystore.js.map +1 -1
  86. package/dist/keystore/types.d.ts +4 -3
  87. package/dist/rln.d.ts +9 -52
  88. package/dist/rln.js +54 -163
  89. package/dist/rln.js.map +1 -1
  90. package/dist/types.d.ts +27 -0
  91. package/dist/types.js +2 -0
  92. package/dist/types.js.map +1 -0
  93. package/dist/utils/bytes.js +8 -2
  94. package/dist/utils/bytes.js.map +1 -1
  95. package/dist/zerokit.d.ts +3 -3
  96. package/dist/zerokit.js +5 -5
  97. package/dist/zerokit.js.map +1 -1
  98. package/package.json +1 -91
  99. package/src/codec.test-utils.ts +80 -0
  100. package/src/contract/abi.ts +502 -248
  101. package/src/contract/constants.ts +3 -3
  102. package/src/contract/index.ts +1 -0
  103. package/src/contract/rln_base_contract.ts +712 -0
  104. package/src/contract/rln_contract.ts +37 -579
  105. package/src/contract/test-setup.ts +86 -0
  106. package/src/contract/test-utils.ts +179 -0
  107. package/src/contract/types.ts +53 -0
  108. package/src/create.ts +1 -1
  109. package/src/credentials_manager.ts +282 -0
  110. package/src/index.ts +19 -2
  111. package/src/keystore/keystore.ts +23 -12
  112. package/src/keystore/types.ts +4 -3
  113. package/src/rln.ts +67 -258
  114. package/src/types.ts +31 -0
  115. package/src/utils/bytes.ts +10 -2
  116. package/src/zerokit.ts +3 -3
  117. package/bundle/_virtual/__node-resolve_empty.js +0 -6
  118. package/bundle/_virtual/_node-resolve_empty.js +0 -3
  119. package/bundle/_virtual/bn.js +0 -3
  120. package/bundle/_virtual/common.js +0 -3
  121. package/bundle/_virtual/common2.js +0 -3
  122. package/bundle/_virtual/hash.js +0 -3
  123. package/bundle/_virtual/inherits_browser.js +0 -3
  124. package/bundle/_virtual/ripemd.js +0 -3
  125. package/bundle/_virtual/sha.js +0 -3
  126. package/bundle/_virtual/sha3.js +0 -3
  127. package/bundle/_virtual/utils3.js +0 -3
  128. package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +0 -3
  129. package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +0 -96
  130. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +0 -148
  131. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +0 -26
  132. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +0 -20
  133. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +0 -210
  134. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +0 -18
  135. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +0 -30
  136. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +0 -26
  137. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +0 -22
  138. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +0 -43
  139. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +0 -19
  140. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +0 -58
  141. package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +0 -854
  142. package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +0 -609
  143. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +0 -3
  144. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +0 -66
  145. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +0 -3
  146. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +0 -302
  147. package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +0 -3
  148. package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +0 -110
  149. package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +0 -20
  150. package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +0 -120
  151. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +0 -3
  152. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +0 -287
  153. package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +0 -3
  154. package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +0 -402
  155. package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +0 -3
  156. package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +0 -8
  157. package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +0 -3
  158. package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +0 -3
  159. package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +0 -893
  160. package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +0 -3
  161. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +0 -256
  162. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +0 -36
  163. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +0 -135
  164. package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +0 -8
  165. package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +0 -64
  166. package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +0 -443
  167. package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +0 -8
  168. package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +0 -3
  169. package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +0 -352
  170. package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +0 -3
  171. package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +0 -266
  172. package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +0 -3
  173. package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +0 -127
  174. package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +0 -3
  175. package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +0 -2007
  176. package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +0 -422
  177. package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +0 -674
  178. package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +0 -132
  179. package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +0 -3
  180. package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +0 -120
  181. package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +0 -8
  182. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +0 -3
  183. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +0 -2478
  184. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +0 -76
  185. package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +0 -3
  186. package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +0 -219
  187. package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +0 -3
  188. package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +0 -279
  189. package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +0 -3
  190. package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +0 -69
  191. package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +0 -404
  192. package/bundle/node_modules/bech32/index.js +0 -187
  193. package/bundle/node_modules/bn.js/lib/bn.js +0 -3361
  194. package/bundle/node_modules/hash.js/lib/hash/common.js +0 -97
  195. package/bundle/node_modules/hash.js/lib/hash/hmac.js +0 -51
  196. package/bundle/node_modules/hash.js/lib/hash/ripemd.js +0 -152
  197. package/bundle/node_modules/hash.js/lib/hash/sha/1.js +0 -81
  198. package/bundle/node_modules/hash.js/lib/hash/sha/224.js +0 -33
  199. package/bundle/node_modules/hash.js/lib/hash/sha/256.js +0 -113
  200. package/bundle/node_modules/hash.js/lib/hash/sha/384.js +0 -39
  201. package/bundle/node_modules/hash.js/lib/hash/sha/512.js +0 -336
  202. package/bundle/node_modules/hash.js/lib/hash/sha/common.js +0 -53
  203. package/bundle/node_modules/hash.js/lib/hash/sha.js +0 -14
  204. package/bundle/node_modules/hash.js/lib/hash/utils.js +0 -282
  205. package/bundle/node_modules/hash.js/lib/hash.js +0 -33
  206. package/bundle/node_modules/inherits/inherits_browser.js +0 -33
  207. package/bundle/node_modules/js-sha3/src/sha3.js +0 -660
  208. package/bundle/node_modules/minimalistic-assert/index.js +0 -13
  209. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +0 -0
  210. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +0 -0
  211. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +0 -0
  212. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +0 -0
  213. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +0 -0
  214. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +0 -0
  215. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +0 -0
  216. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +0 -0
  217. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +0 -0
  218. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +0 -0
  219. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +0 -0
  220. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +0 -0
  221. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +0 -0
  222. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +0 -0
  223. /package/bundle/{node_modules → packages/rln/node_modules}/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +0 -0
@@ -1,422 +0,0 @@
1
- import { getAddress, getContractAddress } from '../../address/lib.esm/index.js';
2
- import { isHexString, hexDataSlice, hexValue, hexDataLength, hexZeroPad } from '../../bytes/lib.esm/index.js';
3
- import { shallowCopy } from '../../properties/lib.esm/index.js';
4
- import { accessListify, parse } from '../../transactions/lib.esm/index.js';
5
- import { Logger } from '../../logger/lib.esm/index.js';
6
- import { version } from './_version.js';
7
- import { BigNumber } from '../../bignumber/lib.esm/bignumber.js';
8
- import { AddressZero } from '../../constants/lib.esm/addresses.js';
9
-
10
- const logger = new Logger(version);
11
- class Formatter {
12
- constructor() {
13
- this.formats = this.getDefaultFormats();
14
- }
15
- getDefaultFormats() {
16
- const formats = ({});
17
- const address = this.address.bind(this);
18
- const bigNumber = this.bigNumber.bind(this);
19
- const blockTag = this.blockTag.bind(this);
20
- const data = this.data.bind(this);
21
- const hash = this.hash.bind(this);
22
- const hex = this.hex.bind(this);
23
- const number = this.number.bind(this);
24
- const type = this.type.bind(this);
25
- const strictData = (v) => { return this.data(v, true); };
26
- formats.transaction = {
27
- hash: hash,
28
- type: type,
29
- accessList: Formatter.allowNull(this.accessList.bind(this), null),
30
- blockHash: Formatter.allowNull(hash, null),
31
- blockNumber: Formatter.allowNull(number, null),
32
- transactionIndex: Formatter.allowNull(number, null),
33
- confirmations: Formatter.allowNull(number, null),
34
- from: address,
35
- // either (gasPrice) or (maxPriorityFeePerGas + maxFeePerGas)
36
- // must be set
37
- gasPrice: Formatter.allowNull(bigNumber),
38
- maxPriorityFeePerGas: Formatter.allowNull(bigNumber),
39
- maxFeePerGas: Formatter.allowNull(bigNumber),
40
- gasLimit: bigNumber,
41
- to: Formatter.allowNull(address, null),
42
- value: bigNumber,
43
- nonce: number,
44
- data: data,
45
- r: Formatter.allowNull(this.uint256),
46
- s: Formatter.allowNull(this.uint256),
47
- v: Formatter.allowNull(number),
48
- creates: Formatter.allowNull(address, null),
49
- raw: Formatter.allowNull(data),
50
- };
51
- formats.transactionRequest = {
52
- from: Formatter.allowNull(address),
53
- nonce: Formatter.allowNull(number),
54
- gasLimit: Formatter.allowNull(bigNumber),
55
- gasPrice: Formatter.allowNull(bigNumber),
56
- maxPriorityFeePerGas: Formatter.allowNull(bigNumber),
57
- maxFeePerGas: Formatter.allowNull(bigNumber),
58
- to: Formatter.allowNull(address),
59
- value: Formatter.allowNull(bigNumber),
60
- data: Formatter.allowNull(strictData),
61
- type: Formatter.allowNull(number),
62
- accessList: Formatter.allowNull(this.accessList.bind(this), null),
63
- };
64
- formats.receiptLog = {
65
- transactionIndex: number,
66
- blockNumber: number,
67
- transactionHash: hash,
68
- address: address,
69
- topics: Formatter.arrayOf(hash),
70
- data: data,
71
- logIndex: number,
72
- blockHash: hash,
73
- };
74
- formats.receipt = {
75
- to: Formatter.allowNull(this.address, null),
76
- from: Formatter.allowNull(this.address, null),
77
- contractAddress: Formatter.allowNull(address, null),
78
- transactionIndex: number,
79
- // should be allowNull(hash), but broken-EIP-658 support is handled in receipt
80
- root: Formatter.allowNull(hex),
81
- gasUsed: bigNumber,
82
- logsBloom: Formatter.allowNull(data),
83
- blockHash: hash,
84
- transactionHash: hash,
85
- logs: Formatter.arrayOf(this.receiptLog.bind(this)),
86
- blockNumber: number,
87
- confirmations: Formatter.allowNull(number, null),
88
- cumulativeGasUsed: bigNumber,
89
- effectiveGasPrice: Formatter.allowNull(bigNumber),
90
- status: Formatter.allowNull(number),
91
- type: type
92
- };
93
- formats.block = {
94
- hash: Formatter.allowNull(hash),
95
- parentHash: hash,
96
- number: number,
97
- timestamp: number,
98
- nonce: Formatter.allowNull(hex),
99
- difficulty: this.difficulty.bind(this),
100
- gasLimit: bigNumber,
101
- gasUsed: bigNumber,
102
- miner: Formatter.allowNull(address),
103
- extraData: data,
104
- transactions: Formatter.allowNull(Formatter.arrayOf(hash)),
105
- baseFeePerGas: Formatter.allowNull(bigNumber)
106
- };
107
- formats.blockWithTransactions = shallowCopy(formats.block);
108
- formats.blockWithTransactions.transactions = Formatter.allowNull(Formatter.arrayOf(this.transactionResponse.bind(this)));
109
- formats.filter = {
110
- fromBlock: Formatter.allowNull(blockTag, undefined),
111
- toBlock: Formatter.allowNull(blockTag, undefined),
112
- blockHash: Formatter.allowNull(hash, undefined),
113
- address: Formatter.allowNull(address, undefined),
114
- topics: Formatter.allowNull(this.topics.bind(this), undefined),
115
- };
116
- formats.filterLog = {
117
- blockNumber: Formatter.allowNull(number),
118
- blockHash: Formatter.allowNull(hash),
119
- transactionIndex: number,
120
- removed: Formatter.allowNull(this.boolean.bind(this)),
121
- address: address,
122
- data: Formatter.allowFalsish(data, "0x"),
123
- topics: Formatter.arrayOf(hash),
124
- transactionHash: hash,
125
- logIndex: number,
126
- };
127
- return formats;
128
- }
129
- accessList(accessList) {
130
- return accessListify(accessList || []);
131
- }
132
- // Requires a BigNumberish that is within the IEEE754 safe integer range; returns a number
133
- // Strict! Used on input.
134
- number(number) {
135
- if (number === "0x") {
136
- return 0;
137
- }
138
- return BigNumber.from(number).toNumber();
139
- }
140
- type(number) {
141
- if (number === "0x" || number == null) {
142
- return 0;
143
- }
144
- return BigNumber.from(number).toNumber();
145
- }
146
- // Strict! Used on input.
147
- bigNumber(value) {
148
- return BigNumber.from(value);
149
- }
150
- // Requires a boolean, "true" or "false"; returns a boolean
151
- boolean(value) {
152
- if (typeof (value) === "boolean") {
153
- return value;
154
- }
155
- if (typeof (value) === "string") {
156
- value = value.toLowerCase();
157
- if (value === "true") {
158
- return true;
159
- }
160
- if (value === "false") {
161
- return false;
162
- }
163
- }
164
- throw new Error("invalid boolean - " + value);
165
- }
166
- hex(value, strict) {
167
- if (typeof (value) === "string") {
168
- if (!strict && value.substring(0, 2) !== "0x") {
169
- value = "0x" + value;
170
- }
171
- if (isHexString(value)) {
172
- return value.toLowerCase();
173
- }
174
- }
175
- return logger.throwArgumentError("invalid hash", "value", value);
176
- }
177
- data(value, strict) {
178
- const result = this.hex(value, strict);
179
- if ((result.length % 2) !== 0) {
180
- throw new Error("invalid data; odd-length - " + value);
181
- }
182
- return result;
183
- }
184
- // Requires an address
185
- // Strict! Used on input.
186
- address(value) {
187
- return getAddress(value);
188
- }
189
- callAddress(value) {
190
- if (!isHexString(value, 32)) {
191
- return null;
192
- }
193
- const address = getAddress(hexDataSlice(value, 12));
194
- return (address === AddressZero) ? null : address;
195
- }
196
- contractAddress(value) {
197
- return getContractAddress(value);
198
- }
199
- // Strict! Used on input.
200
- blockTag(blockTag) {
201
- if (blockTag == null) {
202
- return "latest";
203
- }
204
- if (blockTag === "earliest") {
205
- return "0x0";
206
- }
207
- switch (blockTag) {
208
- case "earliest": return "0x0";
209
- case "latest":
210
- case "pending":
211
- case "safe":
212
- case "finalized":
213
- return blockTag;
214
- }
215
- if (typeof (blockTag) === "number" || isHexString(blockTag)) {
216
- return hexValue(blockTag);
217
- }
218
- throw new Error("invalid blockTag");
219
- }
220
- // Requires a hash, optionally requires 0x prefix; returns prefixed lowercase hash.
221
- hash(value, strict) {
222
- const result = this.hex(value, strict);
223
- if (hexDataLength(result) !== 32) {
224
- return logger.throwArgumentError("invalid hash", "value", value);
225
- }
226
- return result;
227
- }
228
- // Returns the difficulty as a number, or if too large (i.e. PoA network) null
229
- difficulty(value) {
230
- if (value == null) {
231
- return null;
232
- }
233
- const v = BigNumber.from(value);
234
- try {
235
- return v.toNumber();
236
- }
237
- catch (error) { }
238
- return null;
239
- }
240
- uint256(value) {
241
- if (!isHexString(value)) {
242
- throw new Error("invalid uint256");
243
- }
244
- return hexZeroPad(value, 32);
245
- }
246
- _block(value, format) {
247
- if (value.author != null && value.miner == null) {
248
- value.miner = value.author;
249
- }
250
- // The difficulty may need to come from _difficulty in recursed blocks
251
- const difficulty = (value._difficulty != null) ? value._difficulty : value.difficulty;
252
- const result = Formatter.check(format, value);
253
- result._difficulty = ((difficulty == null) ? null : BigNumber.from(difficulty));
254
- return result;
255
- }
256
- block(value) {
257
- return this._block(value, this.formats.block);
258
- }
259
- blockWithTransactions(value) {
260
- return this._block(value, this.formats.blockWithTransactions);
261
- }
262
- // Strict! Used on input.
263
- transactionRequest(value) {
264
- return Formatter.check(this.formats.transactionRequest, value);
265
- }
266
- transactionResponse(transaction) {
267
- // Rename gas to gasLimit
268
- if (transaction.gas != null && transaction.gasLimit == null) {
269
- transaction.gasLimit = transaction.gas;
270
- }
271
- // Some clients (TestRPC) do strange things like return 0x0 for the
272
- // 0 address; correct this to be a real address
273
- if (transaction.to && BigNumber.from(transaction.to).isZero()) {
274
- transaction.to = "0x0000000000000000000000000000000000000000";
275
- }
276
- // Rename input to data
277
- if (transaction.input != null && transaction.data == null) {
278
- transaction.data = transaction.input;
279
- }
280
- // If to and creates are empty, populate the creates from the transaction
281
- if (transaction.to == null && transaction.creates == null) {
282
- transaction.creates = this.contractAddress(transaction);
283
- }
284
- if ((transaction.type === 1 || transaction.type === 2) && transaction.accessList == null) {
285
- transaction.accessList = [];
286
- }
287
- const result = Formatter.check(this.formats.transaction, transaction);
288
- if (transaction.chainId != null) {
289
- let chainId = transaction.chainId;
290
- if (isHexString(chainId)) {
291
- chainId = BigNumber.from(chainId).toNumber();
292
- }
293
- result.chainId = chainId;
294
- }
295
- else {
296
- let chainId = transaction.networkId;
297
- // geth-etc returns chainId
298
- if (chainId == null && result.v == null) {
299
- chainId = transaction.chainId;
300
- }
301
- if (isHexString(chainId)) {
302
- chainId = BigNumber.from(chainId).toNumber();
303
- }
304
- if (typeof (chainId) !== "number" && result.v != null) {
305
- chainId = (result.v - 35) / 2;
306
- if (chainId < 0) {
307
- chainId = 0;
308
- }
309
- chainId = parseInt(chainId);
310
- }
311
- if (typeof (chainId) !== "number") {
312
- chainId = 0;
313
- }
314
- result.chainId = chainId;
315
- }
316
- // 0x0000... should actually be null
317
- if (result.blockHash && result.blockHash.replace(/0/g, "") === "x") {
318
- result.blockHash = null;
319
- }
320
- return result;
321
- }
322
- transaction(value) {
323
- return parse(value);
324
- }
325
- receiptLog(value) {
326
- return Formatter.check(this.formats.receiptLog, value);
327
- }
328
- receipt(value) {
329
- const result = Formatter.check(this.formats.receipt, value);
330
- // RSK incorrectly implemented EIP-658, so we munge things a bit here for it
331
- if (result.root != null) {
332
- if (result.root.length <= 4) {
333
- // Could be 0x00, 0x0, 0x01 or 0x1
334
- const value = BigNumber.from(result.root).toNumber();
335
- if (value === 0 || value === 1) {
336
- // Make sure if both are specified, they match
337
- if (result.status != null && (result.status !== value)) {
338
- logger.throwArgumentError("alt-root-status/status mismatch", "value", { root: result.root, status: result.status });
339
- }
340
- result.status = value;
341
- delete result.root;
342
- }
343
- else {
344
- logger.throwArgumentError("invalid alt-root-status", "value.root", result.root);
345
- }
346
- }
347
- else if (result.root.length !== 66) {
348
- // Must be a valid bytes32
349
- logger.throwArgumentError("invalid root hash", "value.root", result.root);
350
- }
351
- }
352
- if (result.status != null) {
353
- result.byzantium = true;
354
- }
355
- return result;
356
- }
357
- topics(value) {
358
- if (Array.isArray(value)) {
359
- return value.map((v) => this.topics(v));
360
- }
361
- else if (value != null) {
362
- return this.hash(value, true);
363
- }
364
- return null;
365
- }
366
- filter(value) {
367
- return Formatter.check(this.formats.filter, value);
368
- }
369
- filterLog(value) {
370
- return Formatter.check(this.formats.filterLog, value);
371
- }
372
- static check(format, object) {
373
- const result = {};
374
- for (const key in format) {
375
- try {
376
- const value = format[key](object[key]);
377
- if (value !== undefined) {
378
- result[key] = value;
379
- }
380
- }
381
- catch (error) {
382
- error.checkKey = key;
383
- error.checkValue = object[key];
384
- throw error;
385
- }
386
- }
387
- return result;
388
- }
389
- // if value is null-ish, nullValue is returned
390
- static allowNull(format, nullValue) {
391
- return (function (value) {
392
- if (value == null) {
393
- return nullValue;
394
- }
395
- return format(value);
396
- });
397
- }
398
- // If value is false-ish, replaceValue is returned
399
- static allowFalsish(format, replaceValue) {
400
- return (function (value) {
401
- if (!value) {
402
- return replaceValue;
403
- }
404
- return format(value);
405
- });
406
- }
407
- // Requires an Array satisfying check
408
- static arrayOf(format) {
409
- return (function (array) {
410
- if (!Array.isArray(array)) {
411
- throw new Error("not an array");
412
- }
413
- const result = [];
414
- array.forEach(function (value) {
415
- result.push(format(value));
416
- });
417
- return result;
418
- });
419
- }
420
- }
421
-
422
- export { Formatter };