@waku/rln 0.1.3 → 0.1.4-2a94244.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 (341) hide show
  1. package/README.md +10 -186
  2. package/bundle/_virtual/__node-resolve_empty.js +6 -0
  3. package/bundle/_virtual/_assert.js +3 -0
  4. package/bundle/_virtual/_commonjs-dynamic-modules.js +5 -0
  5. package/bundle/_virtual/_commonjsHelpers.js +32 -0
  6. package/bundle/_virtual/_node-resolve_empty.js +3 -0
  7. package/bundle/_virtual/_sha2.js +3 -0
  8. package/bundle/_virtual/_u64.js +3 -0
  9. package/bundle/_virtual/aes.js +3 -0
  10. package/bundle/_virtual/bn.js +3 -0
  11. package/bundle/_virtual/browser.js +3 -0
  12. package/bundle/_virtual/checksum.js +3 -0
  13. package/bundle/_virtual/cipher.js +3 -0
  14. package/bundle/_virtual/class.js +3 -0
  15. package/bundle/_virtual/common.js +3 -0
  16. package/bundle/_virtual/common2.js +3 -0
  17. package/bundle/_virtual/cryptoBrowser.js +3 -0
  18. package/bundle/_virtual/functional.js +3 -0
  19. package/bundle/_virtual/hash.js +3 -0
  20. package/bundle/_virtual/hmac.js +3 -0
  21. package/bundle/_virtual/index.js +3 -0
  22. package/bundle/_virtual/index2.js +6 -0
  23. package/bundle/_virtual/inherits_browser.js +3 -0
  24. package/bundle/_virtual/kdf.js +3 -0
  25. package/bundle/_virtual/lodash.js +3 -0
  26. package/bundle/_virtual/password.js +3 -0
  27. package/bundle/_virtual/pbkdf2.js +3 -0
  28. package/bundle/_virtual/pbkdf22.js +3 -0
  29. package/bundle/_virtual/random.js +3 -0
  30. package/bundle/_virtual/ripemd.js +3 -0
  31. package/bundle/_virtual/schema-validation-generated.js +3 -0
  32. package/bundle/_virtual/schema-validation.js +3 -0
  33. package/bundle/_virtual/scrypt.js +3 -0
  34. package/bundle/_virtual/scrypt2.js +3 -0
  35. package/bundle/_virtual/sha.js +3 -0
  36. package/bundle/_virtual/sha256.js +3 -0
  37. package/bundle/_virtual/sha2562.js +3 -0
  38. package/bundle/_virtual/sha3.js +3 -0
  39. package/bundle/_virtual/sha512.js +3 -0
  40. package/bundle/_virtual/types.js +3 -0
  41. package/bundle/_virtual/utils.js +3 -0
  42. package/bundle/_virtual/utils2.js +3 -0
  43. package/bundle/_virtual/utils3.js +3 -0
  44. package/bundle/index.js +12 -74804
  45. package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +3 -0
  46. package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +96 -0
  47. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +148 -0
  48. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +26 -0
  49. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +20 -0
  50. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +210 -0
  51. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +18 -0
  52. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +30 -0
  53. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +26 -0
  54. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +22 -0
  55. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +43 -0
  56. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +19 -0
  57. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +58 -0
  58. package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +854 -0
  59. package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +609 -0
  60. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +3 -0
  61. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +66 -0
  62. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +3 -0
  63. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +302 -0
  64. package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +3 -0
  65. package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +110 -0
  66. package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +20 -0
  67. package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +120 -0
  68. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +3 -0
  69. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +287 -0
  70. package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +3 -0
  71. package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +402 -0
  72. package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +3 -0
  73. package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +8 -0
  74. package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +3 -0
  75. package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +3 -0
  76. package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +893 -0
  77. package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +3 -0
  78. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +256 -0
  79. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +36 -0
  80. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +135 -0
  81. package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +8 -0
  82. package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +64 -0
  83. package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +443 -0
  84. package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +8 -0
  85. package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +660 -0
  86. package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +3 -0
  87. package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +352 -0
  88. package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +3 -0
  89. package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +248 -0
  90. package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +3 -0
  91. package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +127 -0
  92. package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +3 -0
  93. package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +2007 -0
  94. package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +422 -0
  95. package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +674 -0
  96. package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +132 -0
  97. package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +3 -0
  98. package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +120 -0
  99. package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +8 -0
  100. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +3 -0
  101. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +2430 -0
  102. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +76 -0
  103. package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +3 -0
  104. package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +219 -0
  105. package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +3 -0
  106. package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +279 -0
  107. package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +3 -0
  108. package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +69 -0
  109. package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +404 -0
  110. package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +15 -0
  111. package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +20 -0
  112. package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +92 -0
  113. package/bundle/node_modules/@noble/hashes/esm/_assert.js +37 -0
  114. package/bundle/node_modules/@noble/hashes/esm/_md.js +132 -0
  115. package/bundle/node_modules/@noble/hashes/esm/_u64.js +29 -0
  116. package/bundle/node_modules/@noble/hashes/esm/sha256.js +113 -0
  117. package/bundle/node_modules/@noble/hashes/esm/sha3.js +210 -0
  118. package/bundle/node_modules/@noble/hashes/esm/utils.js +144 -0
  119. package/bundle/node_modules/@waku/zerokit-rln-wasm/rln_wasm.js +756 -0
  120. package/bundle/node_modules/bech32/index.js +187 -0
  121. package/bundle/node_modules/bn.js/lib/bn.js +3361 -0
  122. package/bundle/node_modules/debug/src/browser.js +283 -0
  123. package/bundle/node_modules/debug/src/common.js +295 -0
  124. package/bundle/node_modules/ethereum-cryptography/esm/keccak.js +10 -0
  125. package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +6 -0
  126. package/bundle/node_modules/ethereum-cryptography/esm/utils.js +24 -0
  127. package/bundle/node_modules/hash.js/lib/hash/common.js +97 -0
  128. package/bundle/node_modules/hash.js/lib/hash/hmac.js +51 -0
  129. package/bundle/node_modules/hash.js/lib/hash/ripemd.js +152 -0
  130. package/bundle/node_modules/hash.js/lib/hash/sha/1.js +81 -0
  131. package/bundle/node_modules/hash.js/lib/hash/sha/224.js +33 -0
  132. package/bundle/node_modules/hash.js/lib/hash/sha/256.js +113 -0
  133. package/bundle/node_modules/hash.js/lib/hash/sha/384.js +39 -0
  134. package/bundle/node_modules/hash.js/lib/hash/sha/512.js +336 -0
  135. package/bundle/node_modules/hash.js/lib/hash/sha/common.js +53 -0
  136. package/bundle/node_modules/hash.js/lib/hash/sha.js +14 -0
  137. package/bundle/node_modules/hash.js/lib/hash/utils.js +282 -0
  138. package/bundle/node_modules/hash.js/lib/hash.js +33 -0
  139. package/bundle/node_modules/inherits/inherits_browser.js +33 -0
  140. package/bundle/node_modules/it-length-prefixed/dist/src/decode.js +6 -0
  141. package/bundle/node_modules/lodash/lodash.js +17207 -0
  142. package/bundle/node_modules/minimalistic-assert/index.js +13 -0
  143. package/bundle/node_modules/ms/index.js +172 -0
  144. package/bundle/node_modules/multiformats/dist/src/bases/base.js +205 -0
  145. package/bundle/node_modules/multiformats/dist/src/bases/base10.js +9 -0
  146. package/bundle/node_modules/multiformats/dist/src/bases/base16.js +16 -0
  147. package/bundle/node_modules/multiformats/dist/src/bases/base2.js +10 -0
  148. package/bundle/node_modules/multiformats/dist/src/bases/base256emoji.js +41 -0
  149. package/bundle/node_modules/multiformats/dist/src/bases/base32.js +58 -0
  150. package/bundle/node_modules/multiformats/dist/src/bases/base36.js +14 -0
  151. package/bundle/node_modules/multiformats/dist/src/bases/base58.js +14 -0
  152. package/bundle/node_modules/multiformats/dist/src/bases/base64.js +28 -0
  153. package/bundle/node_modules/multiformats/dist/src/bases/base8.js +10 -0
  154. package/bundle/node_modules/multiformats/dist/src/bases/identity.js +11 -0
  155. package/bundle/node_modules/multiformats/dist/src/basics.js +15 -0
  156. package/bundle/node_modules/multiformats/dist/src/bytes.js +18 -0
  157. package/bundle/node_modules/multiformats/dist/src/codecs/json.js +2 -0
  158. package/bundle/node_modules/multiformats/dist/src/vendor/base-x.js +170 -0
  159. package/bundle/node_modules/protons-runtime/dist/src/codec.js +20 -0
  160. package/bundle/node_modules/protons-runtime/dist/src/codecs/enum.js +24 -0
  161. package/bundle/node_modules/protons-runtime/dist/src/codecs/message.js +7 -0
  162. package/bundle/node_modules/protons-runtime/dist/src/decode.js +8 -0
  163. package/bundle/node_modules/protons-runtime/dist/src/encode.js +11 -0
  164. package/bundle/node_modules/protons-runtime/dist/src/index.js +30 -0
  165. package/bundle/node_modules/protons-runtime/dist/src/utils/float.js +54 -0
  166. package/bundle/node_modules/protons-runtime/dist/src/utils/longbits.js +175 -0
  167. package/bundle/node_modules/protons-runtime/dist/src/utils/pool.js +28 -0
  168. package/bundle/node_modules/protons-runtime/dist/src/utils/reader.js +367 -0
  169. package/bundle/node_modules/protons-runtime/dist/src/utils/utf8.js +99 -0
  170. package/bundle/node_modules/protons-runtime/dist/src/utils/writer.js +438 -0
  171. package/bundle/node_modules/uint8-varint/dist/src/index.js +124 -0
  172. package/bundle/node_modules/uint8arrays/dist/src/alloc.js +17 -0
  173. package/bundle/node_modules/uint8arrays/dist/src/from-string.js +19 -0
  174. package/bundle/node_modules/uint8arrays/dist/src/util/bases.js +49 -0
  175. package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +21 -0
  176. package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +18 -0
  177. package/bundle/packages/core/dist/lib/filter/filter.js +27 -0
  178. package/bundle/packages/core/dist/lib/light_push/light_push.js +27 -0
  179. package/bundle/packages/core/dist/lib/message/version_0.js +154 -0
  180. package/bundle/packages/core/dist/lib/metadata/metadata.js +27 -0
  181. package/bundle/packages/core/dist/lib/store/store.js +27 -0
  182. package/bundle/packages/interfaces/dist/connection_manager.js +19 -0
  183. package/bundle/packages/interfaces/dist/constants.js +6 -0
  184. package/bundle/packages/interfaces/dist/health_indicator.js +12 -0
  185. package/bundle/packages/interfaces/dist/protocols.js +92 -0
  186. package/bundle/packages/proto/dist/generated/filter.js +445 -0
  187. package/bundle/packages/proto/dist/generated/filter_v2.js +424 -0
  188. package/bundle/packages/proto/dist/generated/light_push.js +389 -0
  189. package/bundle/packages/proto/dist/generated/message.js +213 -0
  190. package/bundle/packages/proto/dist/generated/metadata.js +130 -0
  191. package/bundle/packages/proto/dist/generated/peer_exchange.js +209 -0
  192. package/bundle/packages/proto/dist/generated/sds_message.js +105 -0
  193. package/bundle/packages/proto/dist/generated/store_v3.js +490 -0
  194. package/bundle/packages/proto/dist/generated/topic_only_message.js +61 -0
  195. package/bundle/packages/rln/dist/codec.js +93 -0
  196. package/bundle/packages/rln/dist/contract/abi.js +394 -0
  197. package/bundle/packages/rln/dist/contract/constants.js +27 -0
  198. package/bundle/packages/rln/dist/contract/rln_contract.js +438 -0
  199. package/bundle/packages/rln/dist/create.js +9 -0
  200. package/bundle/packages/rln/dist/identity.js +30 -0
  201. package/bundle/packages/rln/dist/keystore/cipher.js +31 -0
  202. package/bundle/packages/rln/dist/keystore/credential_validation_generated.js +119 -0
  203. package/bundle/packages/rln/dist/keystore/keystore.js +223 -0
  204. package/bundle/packages/rln/dist/keystore/keystore_validation_generated.js +74 -0
  205. package/bundle/packages/rln/dist/keystore/schema_validator.js +20 -0
  206. package/bundle/packages/rln/dist/message.js +51 -0
  207. package/bundle/packages/rln/dist/proof.js +54 -0
  208. package/bundle/packages/rln/dist/resources/verification_key.js +112 -0
  209. package/bundle/packages/rln/dist/resources/witness_calculator.js +330 -0
  210. package/bundle/packages/rln/dist/rln.js +220 -0
  211. package/bundle/packages/rln/dist/root_tracker.js +76 -0
  212. package/bundle/packages/rln/dist/utils/bytes.js +65 -0
  213. package/bundle/packages/rln/dist/utils/epoch.js +39 -0
  214. package/bundle/packages/rln/dist/utils/hash.js +10 -0
  215. package/bundle/packages/rln/dist/utils/metamask.js +14 -0
  216. package/bundle/packages/rln/dist/zerokit.js +128 -0
  217. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +52 -0
  218. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +65 -0
  219. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +99 -0
  220. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +103 -0
  221. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/index.js +28 -0
  222. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +78 -0
  223. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +17 -0
  224. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1253 -0
  225. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +40 -0
  226. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/types.js +5 -0
  227. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +103 -0
  228. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +41 -0
  229. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +17 -0
  230. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +23 -0
  231. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +12 -0
  232. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +77 -0
  233. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +9 -0
  234. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +215 -0
  235. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +3 -0
  236. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +35 -0
  237. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +3 -0
  238. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +21 -0
  239. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
  240. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
  241. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +96 -0
  242. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +6 -0
  243. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +66 -0
  244. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +24 -0
  245. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +6 -0
  246. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +7 -0
  247. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +11 -0
  248. package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +52 -0
  249. package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +124 -0
  250. package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +71 -0
  251. package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +10 -0
  252. package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +88 -0
  253. package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +99 -0
  254. package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +233 -0
  255. package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +133 -0
  256. package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +243 -0
  257. package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +167 -0
  258. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/native.js +4 -0
  259. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/rng.js +13 -0
  260. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/stringify.js +28 -0
  261. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/v4.js +19 -0
  262. package/bundle/packages/utils/dist/bytes/index.js +44 -0
  263. package/bundle/packages/utils/dist/common/sharding/index.js +91 -0
  264. package/bundle/packages/utils/dist/logger/index.js +31 -0
  265. package/bundle/resources/verification_key.d.ts +13 -0
  266. package/bundle/resources/verification_key.js +112 -0
  267. package/bundle/resources/witness_calculator.d.ts +11 -0
  268. package/bundle/resources/witness_calculator.js +328 -0
  269. package/dist/.tsbuildinfo +1 -0
  270. package/dist/codec.d.ts +5 -5
  271. package/dist/codec.js +6 -6
  272. package/dist/codec.js.map +1 -1
  273. package/dist/contract/abi.d.ts +42 -0
  274. package/dist/contract/abi.js +393 -0
  275. package/dist/contract/abi.js.map +1 -0
  276. package/dist/contract/constants.d.ts +59 -3
  277. package/dist/contract/constants.js +21 -63
  278. package/dist/contract/constants.js.map +1 -1
  279. package/dist/contract/rln_contract.d.ts +98 -17
  280. package/dist/contract/rln_contract.js +292 -71
  281. package/dist/contract/rln_contract.js.map +1 -1
  282. package/dist/identity.js +5 -2
  283. package/dist/identity.js.map +1 -1
  284. package/dist/index.d.ts +3 -3
  285. package/dist/index.js +3 -3
  286. package/dist/index.js.map +1 -1
  287. package/dist/keystore/cipher.js +3 -3
  288. package/dist/keystore/cipher.js.map +1 -1
  289. package/dist/keystore/credential_validation_generated.js.map +1 -1
  290. package/dist/keystore/keystore.js +4 -4
  291. package/dist/keystore/keystore.js.map +1 -1
  292. package/dist/keystore/keystore_validation_generated.js.map +1 -1
  293. package/dist/message.js +3 -3
  294. package/dist/message.js.map +1 -1
  295. package/dist/proof.js +3 -2
  296. package/dist/proof.js.map +1 -1
  297. package/dist/resources/verification_key.d.ts +12 -11
  298. package/dist/resources/verification_key.js +103 -103
  299. package/dist/resources/witness_calculator.d.ts +10 -15
  300. package/dist/resources/witness_calculator.js +302 -265
  301. package/dist/rln.d.ts +5 -1
  302. package/dist/rln.js +56 -28
  303. package/dist/rln.js.map +1 -1
  304. package/dist/root_tracker.js.map +1 -1
  305. package/dist/utils/epoch.js +5 -5
  306. package/dist/utils/epoch.js.map +1 -1
  307. package/dist/zerokit.d.ts +13 -9
  308. package/dist/zerokit.js +40 -20
  309. package/dist/zerokit.js.map +1 -1
  310. package/package.json +1 -146
  311. package/src/codec.ts +26 -22
  312. package/src/contract/abi.ts +392 -0
  313. package/src/contract/constants.ts +28 -0
  314. package/src/contract/index.ts +2 -0
  315. package/src/contract/rln_contract.ts +686 -0
  316. package/src/identity.ts +8 -4
  317. package/src/index.ts +4 -9
  318. package/src/keystore/cipher.ts +54 -0
  319. package/src/keystore/credential_validation_generated.ts +7 -0
  320. package/src/keystore/index.ts +5 -0
  321. package/src/keystore/keystore.ts +330 -0
  322. package/src/keystore/keystore_validation_generated.ts +7 -0
  323. package/src/keystore/schema_validator.ts +34 -0
  324. package/src/keystore/types.ts +36 -0
  325. package/src/message.ts +10 -10
  326. package/src/proof.ts +13 -11
  327. package/src/resources/verification_key.d.ts +13 -0
  328. package/src/resources/witness_calculator.d.ts +11 -0
  329. package/src/rln.ts +76 -31
  330. package/src/root_tracker.ts +7 -6
  331. package/src/utils/bytes.ts +84 -0
  332. package/src/utils/epoch.ts +30 -0
  333. package/src/utils/hash.ts +15 -0
  334. package/src/utils/index.ts +9 -0
  335. package/src/utils/metamask.ts +17 -0
  336. package/src/zerokit.ts +95 -33
  337. package/bundle/assets/rln_wasm_bg-a503e304.wasm +0 -0
  338. package/dist/resources/verification_key.js.map +0 -1
  339. package/dist/resources/witness_calculator.js.map +0 -1
  340. /package/bundle/{assets/rln-6ded2896.wasm → resources/rln.wasm} +0 -0
  341. /package/bundle/{assets/rln_final-8b299152.zkey → resources/rln_final.zkey} +0 -0
@@ -0,0 +1,854 @@
1
+ import { defineReadOnly } from '../../properties/lib.esm/index.js';
2
+ import { Logger } from '../../logger/lib.esm/index.js';
3
+ import { version } from './_version.js';
4
+ import { BigNumber } from '../../bignumber/lib.esm/bignumber.js';
5
+
6
+ const logger = new Logger(version);
7
+ const _constructorGuard = {};
8
+ let ModifiersBytes = { calldata: true, memory: true, storage: true };
9
+ let ModifiersNest = { calldata: true, memory: true };
10
+ function checkModifier(type, name) {
11
+ if (type === "bytes" || type === "string") {
12
+ if (ModifiersBytes[name]) {
13
+ return true;
14
+ }
15
+ }
16
+ else if (type === "address") {
17
+ if (name === "payable") {
18
+ return true;
19
+ }
20
+ }
21
+ else if (type.indexOf("[") >= 0 || type === "tuple") {
22
+ if (ModifiersNest[name]) {
23
+ return true;
24
+ }
25
+ }
26
+ if (ModifiersBytes[name] || name === "payable") {
27
+ logger.throwArgumentError("invalid modifier", "name", name);
28
+ }
29
+ return false;
30
+ }
31
+ // @TODO: Make sure that children of an indexed tuple are marked with a null indexed
32
+ function parseParamType(param, allowIndexed) {
33
+ let originalParam = param;
34
+ function throwError(i) {
35
+ logger.throwArgumentError(`unexpected character at position ${i}`, "param", param);
36
+ }
37
+ param = param.replace(/\s/g, " ");
38
+ function newNode(parent) {
39
+ let node = { type: "", name: "", parent: parent, state: { allowType: true } };
40
+ if (allowIndexed) {
41
+ node.indexed = false;
42
+ }
43
+ return node;
44
+ }
45
+ let parent = { type: "", name: "", state: { allowType: true } };
46
+ let node = parent;
47
+ for (let i = 0; i < param.length; i++) {
48
+ let c = param[i];
49
+ switch (c) {
50
+ case "(":
51
+ if (node.state.allowType && node.type === "") {
52
+ node.type = "tuple";
53
+ }
54
+ else if (!node.state.allowParams) {
55
+ throwError(i);
56
+ }
57
+ node.state.allowType = false;
58
+ node.type = verifyType(node.type);
59
+ node.components = [newNode(node)];
60
+ node = node.components[0];
61
+ break;
62
+ case ")":
63
+ delete node.state;
64
+ if (node.name === "indexed") {
65
+ if (!allowIndexed) {
66
+ throwError(i);
67
+ }
68
+ node.indexed = true;
69
+ node.name = "";
70
+ }
71
+ if (checkModifier(node.type, node.name)) {
72
+ node.name = "";
73
+ }
74
+ node.type = verifyType(node.type);
75
+ let child = node;
76
+ node = node.parent;
77
+ if (!node) {
78
+ throwError(i);
79
+ }
80
+ delete child.parent;
81
+ node.state.allowParams = false;
82
+ node.state.allowName = true;
83
+ node.state.allowArray = true;
84
+ break;
85
+ case ",":
86
+ delete node.state;
87
+ if (node.name === "indexed") {
88
+ if (!allowIndexed) {
89
+ throwError(i);
90
+ }
91
+ node.indexed = true;
92
+ node.name = "";
93
+ }
94
+ if (checkModifier(node.type, node.name)) {
95
+ node.name = "";
96
+ }
97
+ node.type = verifyType(node.type);
98
+ let sibling = newNode(node.parent);
99
+ //{ type: "", name: "", parent: node.parent, state: { allowType: true } };
100
+ node.parent.components.push(sibling);
101
+ delete node.parent;
102
+ node = sibling;
103
+ break;
104
+ // Hit a space...
105
+ case " ":
106
+ // If reading type, the type is done and may read a param or name
107
+ if (node.state.allowType) {
108
+ if (node.type !== "") {
109
+ node.type = verifyType(node.type);
110
+ delete node.state.allowType;
111
+ node.state.allowName = true;
112
+ node.state.allowParams = true;
113
+ }
114
+ }
115
+ // If reading name, the name is done
116
+ if (node.state.allowName) {
117
+ if (node.name !== "") {
118
+ if (node.name === "indexed") {
119
+ if (!allowIndexed) {
120
+ throwError(i);
121
+ }
122
+ if (node.indexed) {
123
+ throwError(i);
124
+ }
125
+ node.indexed = true;
126
+ node.name = "";
127
+ }
128
+ else if (checkModifier(node.type, node.name)) {
129
+ node.name = "";
130
+ }
131
+ else {
132
+ node.state.allowName = false;
133
+ }
134
+ }
135
+ }
136
+ break;
137
+ case "[":
138
+ if (!node.state.allowArray) {
139
+ throwError(i);
140
+ }
141
+ node.type += c;
142
+ node.state.allowArray = false;
143
+ node.state.allowName = false;
144
+ node.state.readArray = true;
145
+ break;
146
+ case "]":
147
+ if (!node.state.readArray) {
148
+ throwError(i);
149
+ }
150
+ node.type += c;
151
+ node.state.readArray = false;
152
+ node.state.allowArray = true;
153
+ node.state.allowName = true;
154
+ break;
155
+ default:
156
+ if (node.state.allowType) {
157
+ node.type += c;
158
+ node.state.allowParams = true;
159
+ node.state.allowArray = true;
160
+ }
161
+ else if (node.state.allowName) {
162
+ node.name += c;
163
+ delete node.state.allowArray;
164
+ }
165
+ else if (node.state.readArray) {
166
+ node.type += c;
167
+ }
168
+ else {
169
+ throwError(i);
170
+ }
171
+ }
172
+ }
173
+ if (node.parent) {
174
+ logger.throwArgumentError("unexpected eof", "param", param);
175
+ }
176
+ delete parent.state;
177
+ if (node.name === "indexed") {
178
+ if (!allowIndexed) {
179
+ throwError(originalParam.length - 7);
180
+ }
181
+ if (node.indexed) {
182
+ throwError(originalParam.length - 7);
183
+ }
184
+ node.indexed = true;
185
+ node.name = "";
186
+ }
187
+ else if (checkModifier(node.type, node.name)) {
188
+ node.name = "";
189
+ }
190
+ parent.type = verifyType(parent.type);
191
+ return parent;
192
+ }
193
+ function populate(object, params) {
194
+ for (let key in params) {
195
+ defineReadOnly(object, key, params[key]);
196
+ }
197
+ }
198
+ const FormatTypes = Object.freeze({
199
+ // Bare formatting, as is needed for computing a sighash of an event or function
200
+ sighash: "sighash",
201
+ // Human-Readable with Minimal spacing and without names (compact human-readable)
202
+ minimal: "minimal",
203
+ // Human-Readable with nice spacing, including all names
204
+ full: "full",
205
+ // JSON-format a la Solidity
206
+ json: "json"
207
+ });
208
+ const paramTypeArray = new RegExp(/^(.*)\[([0-9]*)\]$/);
209
+ class ParamType {
210
+ constructor(constructorGuard, params) {
211
+ if (constructorGuard !== _constructorGuard) {
212
+ logger.throwError("use fromString", Logger.errors.UNSUPPORTED_OPERATION, {
213
+ operation: "new ParamType()"
214
+ });
215
+ }
216
+ populate(this, params);
217
+ let match = this.type.match(paramTypeArray);
218
+ if (match) {
219
+ populate(this, {
220
+ arrayLength: parseInt(match[2] || "-1"),
221
+ arrayChildren: ParamType.fromObject({
222
+ type: match[1],
223
+ components: this.components
224
+ }),
225
+ baseType: "array"
226
+ });
227
+ }
228
+ else {
229
+ populate(this, {
230
+ arrayLength: null,
231
+ arrayChildren: null,
232
+ baseType: ((this.components != null) ? "tuple" : this.type)
233
+ });
234
+ }
235
+ this._isParamType = true;
236
+ Object.freeze(this);
237
+ }
238
+ // Format the parameter fragment
239
+ // - sighash: "(uint256,address)"
240
+ // - minimal: "tuple(uint256,address) indexed"
241
+ // - full: "tuple(uint256 foo, address bar) indexed baz"
242
+ format(format) {
243
+ if (!format) {
244
+ format = FormatTypes.sighash;
245
+ }
246
+ if (!FormatTypes[format]) {
247
+ logger.throwArgumentError("invalid format type", "format", format);
248
+ }
249
+ if (format === FormatTypes.json) {
250
+ let result = {
251
+ type: ((this.baseType === "tuple") ? "tuple" : this.type),
252
+ name: (this.name || undefined)
253
+ };
254
+ if (typeof (this.indexed) === "boolean") {
255
+ result.indexed = this.indexed;
256
+ }
257
+ if (this.components) {
258
+ result.components = this.components.map((comp) => JSON.parse(comp.format(format)));
259
+ }
260
+ return JSON.stringify(result);
261
+ }
262
+ let result = "";
263
+ // Array
264
+ if (this.baseType === "array") {
265
+ result += this.arrayChildren.format(format);
266
+ result += "[" + (this.arrayLength < 0 ? "" : String(this.arrayLength)) + "]";
267
+ }
268
+ else {
269
+ if (this.baseType === "tuple") {
270
+ if (format !== FormatTypes.sighash) {
271
+ result += this.type;
272
+ }
273
+ result += "(" + this.components.map((comp) => comp.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ")";
274
+ }
275
+ else {
276
+ result += this.type;
277
+ }
278
+ }
279
+ if (format !== FormatTypes.sighash) {
280
+ if (this.indexed === true) {
281
+ result += " indexed";
282
+ }
283
+ if (format === FormatTypes.full && this.name) {
284
+ result += " " + this.name;
285
+ }
286
+ }
287
+ return result;
288
+ }
289
+ static from(value, allowIndexed) {
290
+ if (typeof (value) === "string") {
291
+ return ParamType.fromString(value, allowIndexed);
292
+ }
293
+ return ParamType.fromObject(value);
294
+ }
295
+ static fromObject(value) {
296
+ if (ParamType.isParamType(value)) {
297
+ return value;
298
+ }
299
+ return new ParamType(_constructorGuard, {
300
+ name: (value.name || null),
301
+ type: verifyType(value.type),
302
+ indexed: ((value.indexed == null) ? null : !!value.indexed),
303
+ components: (value.components ? value.components.map(ParamType.fromObject) : null)
304
+ });
305
+ }
306
+ static fromString(value, allowIndexed) {
307
+ function ParamTypify(node) {
308
+ return ParamType.fromObject({
309
+ name: node.name,
310
+ type: node.type,
311
+ indexed: node.indexed,
312
+ components: node.components
313
+ });
314
+ }
315
+ return ParamTypify(parseParamType(value, !!allowIndexed));
316
+ }
317
+ static isParamType(value) {
318
+ return !!(value != null && value._isParamType);
319
+ }
320
+ }
321
+ function parseParams(value, allowIndex) {
322
+ return splitNesting(value).map((param) => ParamType.fromString(param, allowIndex));
323
+ }
324
+ class Fragment {
325
+ constructor(constructorGuard, params) {
326
+ if (constructorGuard !== _constructorGuard) {
327
+ logger.throwError("use a static from method", Logger.errors.UNSUPPORTED_OPERATION, {
328
+ operation: "new Fragment()"
329
+ });
330
+ }
331
+ populate(this, params);
332
+ this._isFragment = true;
333
+ Object.freeze(this);
334
+ }
335
+ static from(value) {
336
+ if (Fragment.isFragment(value)) {
337
+ return value;
338
+ }
339
+ if (typeof (value) === "string") {
340
+ return Fragment.fromString(value);
341
+ }
342
+ return Fragment.fromObject(value);
343
+ }
344
+ static fromObject(value) {
345
+ if (Fragment.isFragment(value)) {
346
+ return value;
347
+ }
348
+ switch (value.type) {
349
+ case "function":
350
+ return FunctionFragment.fromObject(value);
351
+ case "event":
352
+ return EventFragment.fromObject(value);
353
+ case "constructor":
354
+ return ConstructorFragment.fromObject(value);
355
+ case "error":
356
+ return ErrorFragment.fromObject(value);
357
+ case "fallback":
358
+ case "receive":
359
+ // @TODO: Something? Maybe return a FunctionFragment? A custom DefaultFunctionFragment?
360
+ return null;
361
+ }
362
+ return logger.throwArgumentError("invalid fragment object", "value", value);
363
+ }
364
+ static fromString(value) {
365
+ // Make sure the "returns" is surrounded by a space and all whitespace is exactly one space
366
+ value = value.replace(/\s/g, " ");
367
+ value = value.replace(/\(/g, " (").replace(/\)/g, ") ").replace(/\s+/g, " ");
368
+ value = value.trim();
369
+ if (value.split(" ")[0] === "event") {
370
+ return EventFragment.fromString(value.substring(5).trim());
371
+ }
372
+ else if (value.split(" ")[0] === "function") {
373
+ return FunctionFragment.fromString(value.substring(8).trim());
374
+ }
375
+ else if (value.split("(")[0].trim() === "constructor") {
376
+ return ConstructorFragment.fromString(value.trim());
377
+ }
378
+ else if (value.split(" ")[0] === "error") {
379
+ return ErrorFragment.fromString(value.substring(5).trim());
380
+ }
381
+ return logger.throwArgumentError("unsupported fragment", "value", value);
382
+ }
383
+ static isFragment(value) {
384
+ return !!(value && value._isFragment);
385
+ }
386
+ }
387
+ class EventFragment extends Fragment {
388
+ format(format) {
389
+ if (!format) {
390
+ format = FormatTypes.sighash;
391
+ }
392
+ if (!FormatTypes[format]) {
393
+ logger.throwArgumentError("invalid format type", "format", format);
394
+ }
395
+ if (format === FormatTypes.json) {
396
+ return JSON.stringify({
397
+ type: "event",
398
+ anonymous: this.anonymous,
399
+ name: this.name,
400
+ inputs: this.inputs.map((input) => JSON.parse(input.format(format)))
401
+ });
402
+ }
403
+ let result = "";
404
+ if (format !== FormatTypes.sighash) {
405
+ result += "event ";
406
+ }
407
+ result += this.name + "(" + this.inputs.map((input) => input.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ") ";
408
+ if (format !== FormatTypes.sighash) {
409
+ if (this.anonymous) {
410
+ result += "anonymous ";
411
+ }
412
+ }
413
+ return result.trim();
414
+ }
415
+ static from(value) {
416
+ if (typeof (value) === "string") {
417
+ return EventFragment.fromString(value);
418
+ }
419
+ return EventFragment.fromObject(value);
420
+ }
421
+ static fromObject(value) {
422
+ if (EventFragment.isEventFragment(value)) {
423
+ return value;
424
+ }
425
+ if (value.type !== "event") {
426
+ logger.throwArgumentError("invalid event object", "value", value);
427
+ }
428
+ const params = {
429
+ name: verifyIdentifier(value.name),
430
+ anonymous: value.anonymous,
431
+ inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
432
+ type: "event"
433
+ };
434
+ return new EventFragment(_constructorGuard, params);
435
+ }
436
+ static fromString(value) {
437
+ let match = value.match(regexParen);
438
+ if (!match) {
439
+ logger.throwArgumentError("invalid event string", "value", value);
440
+ }
441
+ let anonymous = false;
442
+ match[3].split(" ").forEach((modifier) => {
443
+ switch (modifier.trim()) {
444
+ case "anonymous":
445
+ anonymous = true;
446
+ break;
447
+ case "":
448
+ break;
449
+ default:
450
+ logger.warn("unknown modifier: " + modifier);
451
+ }
452
+ });
453
+ return EventFragment.fromObject({
454
+ name: match[1].trim(),
455
+ anonymous: anonymous,
456
+ inputs: parseParams(match[2], true),
457
+ type: "event"
458
+ });
459
+ }
460
+ static isEventFragment(value) {
461
+ return (value && value._isFragment && value.type === "event");
462
+ }
463
+ }
464
+ function parseGas(value, params) {
465
+ params.gas = null;
466
+ let comps = value.split("@");
467
+ if (comps.length !== 1) {
468
+ if (comps.length > 2) {
469
+ logger.throwArgumentError("invalid human-readable ABI signature", "value", value);
470
+ }
471
+ if (!comps[1].match(/^[0-9]+$/)) {
472
+ logger.throwArgumentError("invalid human-readable ABI signature gas", "value", value);
473
+ }
474
+ params.gas = BigNumber.from(comps[1]);
475
+ return comps[0];
476
+ }
477
+ return value;
478
+ }
479
+ function parseModifiers(value, params) {
480
+ params.constant = false;
481
+ params.payable = false;
482
+ params.stateMutability = "nonpayable";
483
+ value.split(" ").forEach((modifier) => {
484
+ switch (modifier.trim()) {
485
+ case "constant":
486
+ params.constant = true;
487
+ break;
488
+ case "payable":
489
+ params.payable = true;
490
+ params.stateMutability = "payable";
491
+ break;
492
+ case "nonpayable":
493
+ params.payable = false;
494
+ params.stateMutability = "nonpayable";
495
+ break;
496
+ case "pure":
497
+ params.constant = true;
498
+ params.stateMutability = "pure";
499
+ break;
500
+ case "view":
501
+ params.constant = true;
502
+ params.stateMutability = "view";
503
+ break;
504
+ case "external":
505
+ case "public":
506
+ case "":
507
+ break;
508
+ default:
509
+ console.log("unknown modifier: " + modifier);
510
+ }
511
+ });
512
+ }
513
+ function verifyState(value) {
514
+ let result = {
515
+ constant: false,
516
+ payable: true,
517
+ stateMutability: "payable"
518
+ };
519
+ if (value.stateMutability != null) {
520
+ result.stateMutability = value.stateMutability;
521
+ // Set (and check things are consistent) the constant property
522
+ result.constant = (result.stateMutability === "view" || result.stateMutability === "pure");
523
+ if (value.constant != null) {
524
+ if ((!!value.constant) !== result.constant) {
525
+ logger.throwArgumentError("cannot have constant function with mutability " + result.stateMutability, "value", value);
526
+ }
527
+ }
528
+ // Set (and check things are consistent) the payable property
529
+ result.payable = (result.stateMutability === "payable");
530
+ if (value.payable != null) {
531
+ if ((!!value.payable) !== result.payable) {
532
+ logger.throwArgumentError("cannot have payable function with mutability " + result.stateMutability, "value", value);
533
+ }
534
+ }
535
+ }
536
+ else if (value.payable != null) {
537
+ result.payable = !!value.payable;
538
+ // If payable we can assume non-constant; otherwise we can't assume
539
+ if (value.constant == null && !result.payable && value.type !== "constructor") {
540
+ logger.throwArgumentError("unable to determine stateMutability", "value", value);
541
+ }
542
+ result.constant = !!value.constant;
543
+ if (result.constant) {
544
+ result.stateMutability = "view";
545
+ }
546
+ else {
547
+ result.stateMutability = (result.payable ? "payable" : "nonpayable");
548
+ }
549
+ if (result.payable && result.constant) {
550
+ logger.throwArgumentError("cannot have constant payable function", "value", value);
551
+ }
552
+ }
553
+ else if (value.constant != null) {
554
+ result.constant = !!value.constant;
555
+ result.payable = !result.constant;
556
+ result.stateMutability = (result.constant ? "view" : "payable");
557
+ }
558
+ else if (value.type !== "constructor") {
559
+ logger.throwArgumentError("unable to determine stateMutability", "value", value);
560
+ }
561
+ return result;
562
+ }
563
+ class ConstructorFragment extends Fragment {
564
+ format(format) {
565
+ if (!format) {
566
+ format = FormatTypes.sighash;
567
+ }
568
+ if (!FormatTypes[format]) {
569
+ logger.throwArgumentError("invalid format type", "format", format);
570
+ }
571
+ if (format === FormatTypes.json) {
572
+ return JSON.stringify({
573
+ type: "constructor",
574
+ stateMutability: ((this.stateMutability !== "nonpayable") ? this.stateMutability : undefined),
575
+ payable: this.payable,
576
+ gas: (this.gas ? this.gas.toNumber() : undefined),
577
+ inputs: this.inputs.map((input) => JSON.parse(input.format(format)))
578
+ });
579
+ }
580
+ if (format === FormatTypes.sighash) {
581
+ logger.throwError("cannot format a constructor for sighash", Logger.errors.UNSUPPORTED_OPERATION, {
582
+ operation: "format(sighash)"
583
+ });
584
+ }
585
+ let result = "constructor(" + this.inputs.map((input) => input.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ") ";
586
+ if (this.stateMutability && this.stateMutability !== "nonpayable") {
587
+ result += this.stateMutability + " ";
588
+ }
589
+ return result.trim();
590
+ }
591
+ static from(value) {
592
+ if (typeof (value) === "string") {
593
+ return ConstructorFragment.fromString(value);
594
+ }
595
+ return ConstructorFragment.fromObject(value);
596
+ }
597
+ static fromObject(value) {
598
+ if (ConstructorFragment.isConstructorFragment(value)) {
599
+ return value;
600
+ }
601
+ if (value.type !== "constructor") {
602
+ logger.throwArgumentError("invalid constructor object", "value", value);
603
+ }
604
+ let state = verifyState(value);
605
+ if (state.constant) {
606
+ logger.throwArgumentError("constructor cannot be constant", "value", value);
607
+ }
608
+ const params = {
609
+ name: null,
610
+ type: value.type,
611
+ inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
612
+ payable: state.payable,
613
+ stateMutability: state.stateMutability,
614
+ gas: (value.gas ? BigNumber.from(value.gas) : null)
615
+ };
616
+ return new ConstructorFragment(_constructorGuard, params);
617
+ }
618
+ static fromString(value) {
619
+ let params = { type: "constructor" };
620
+ value = parseGas(value, params);
621
+ let parens = value.match(regexParen);
622
+ if (!parens || parens[1].trim() !== "constructor") {
623
+ logger.throwArgumentError("invalid constructor string", "value", value);
624
+ }
625
+ params.inputs = parseParams(parens[2].trim(), false);
626
+ parseModifiers(parens[3].trim(), params);
627
+ return ConstructorFragment.fromObject(params);
628
+ }
629
+ static isConstructorFragment(value) {
630
+ return (value && value._isFragment && value.type === "constructor");
631
+ }
632
+ }
633
+ class FunctionFragment extends ConstructorFragment {
634
+ format(format) {
635
+ if (!format) {
636
+ format = FormatTypes.sighash;
637
+ }
638
+ if (!FormatTypes[format]) {
639
+ logger.throwArgumentError("invalid format type", "format", format);
640
+ }
641
+ if (format === FormatTypes.json) {
642
+ return JSON.stringify({
643
+ type: "function",
644
+ name: this.name,
645
+ constant: this.constant,
646
+ stateMutability: ((this.stateMutability !== "nonpayable") ? this.stateMutability : undefined),
647
+ payable: this.payable,
648
+ gas: (this.gas ? this.gas.toNumber() : undefined),
649
+ inputs: this.inputs.map((input) => JSON.parse(input.format(format))),
650
+ outputs: this.outputs.map((output) => JSON.parse(output.format(format))),
651
+ });
652
+ }
653
+ let result = "";
654
+ if (format !== FormatTypes.sighash) {
655
+ result += "function ";
656
+ }
657
+ result += this.name + "(" + this.inputs.map((input) => input.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ") ";
658
+ if (format !== FormatTypes.sighash) {
659
+ if (this.stateMutability) {
660
+ if (this.stateMutability !== "nonpayable") {
661
+ result += (this.stateMutability + " ");
662
+ }
663
+ }
664
+ else if (this.constant) {
665
+ result += "view ";
666
+ }
667
+ if (this.outputs && this.outputs.length) {
668
+ result += "returns (" + this.outputs.map((output) => output.format(format)).join(", ") + ") ";
669
+ }
670
+ if (this.gas != null) {
671
+ result += "@" + this.gas.toString() + " ";
672
+ }
673
+ }
674
+ return result.trim();
675
+ }
676
+ static from(value) {
677
+ if (typeof (value) === "string") {
678
+ return FunctionFragment.fromString(value);
679
+ }
680
+ return FunctionFragment.fromObject(value);
681
+ }
682
+ static fromObject(value) {
683
+ if (FunctionFragment.isFunctionFragment(value)) {
684
+ return value;
685
+ }
686
+ if (value.type !== "function") {
687
+ logger.throwArgumentError("invalid function object", "value", value);
688
+ }
689
+ let state = verifyState(value);
690
+ const params = {
691
+ type: value.type,
692
+ name: verifyIdentifier(value.name),
693
+ constant: state.constant,
694
+ inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
695
+ outputs: (value.outputs ? value.outputs.map(ParamType.fromObject) : []),
696
+ payable: state.payable,
697
+ stateMutability: state.stateMutability,
698
+ gas: (value.gas ? BigNumber.from(value.gas) : null)
699
+ };
700
+ return new FunctionFragment(_constructorGuard, params);
701
+ }
702
+ static fromString(value) {
703
+ let params = { type: "function" };
704
+ value = parseGas(value, params);
705
+ let comps = value.split(" returns ");
706
+ if (comps.length > 2) {
707
+ logger.throwArgumentError("invalid function string", "value", value);
708
+ }
709
+ let parens = comps[0].match(regexParen);
710
+ if (!parens) {
711
+ logger.throwArgumentError("invalid function signature", "value", value);
712
+ }
713
+ params.name = parens[1].trim();
714
+ if (params.name) {
715
+ verifyIdentifier(params.name);
716
+ }
717
+ params.inputs = parseParams(parens[2], false);
718
+ parseModifiers(parens[3].trim(), params);
719
+ // We have outputs
720
+ if (comps.length > 1) {
721
+ let returns = comps[1].match(regexParen);
722
+ if (returns[1].trim() != "" || returns[3].trim() != "") {
723
+ logger.throwArgumentError("unexpected tokens", "value", value);
724
+ }
725
+ params.outputs = parseParams(returns[2], false);
726
+ }
727
+ else {
728
+ params.outputs = [];
729
+ }
730
+ return FunctionFragment.fromObject(params);
731
+ }
732
+ static isFunctionFragment(value) {
733
+ return (value && value._isFragment && value.type === "function");
734
+ }
735
+ }
736
+ //export class StructFragment extends Fragment {
737
+ //}
738
+ function checkForbidden(fragment) {
739
+ const sig = fragment.format();
740
+ if (sig === "Error(string)" || sig === "Panic(uint256)") {
741
+ logger.throwArgumentError(`cannot specify user defined ${sig} error`, "fragment", fragment);
742
+ }
743
+ return fragment;
744
+ }
745
+ class ErrorFragment extends Fragment {
746
+ format(format) {
747
+ if (!format) {
748
+ format = FormatTypes.sighash;
749
+ }
750
+ if (!FormatTypes[format]) {
751
+ logger.throwArgumentError("invalid format type", "format", format);
752
+ }
753
+ if (format === FormatTypes.json) {
754
+ return JSON.stringify({
755
+ type: "error",
756
+ name: this.name,
757
+ inputs: this.inputs.map((input) => JSON.parse(input.format(format))),
758
+ });
759
+ }
760
+ let result = "";
761
+ if (format !== FormatTypes.sighash) {
762
+ result += "error ";
763
+ }
764
+ result += this.name + "(" + this.inputs.map((input) => input.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ") ";
765
+ return result.trim();
766
+ }
767
+ static from(value) {
768
+ if (typeof (value) === "string") {
769
+ return ErrorFragment.fromString(value);
770
+ }
771
+ return ErrorFragment.fromObject(value);
772
+ }
773
+ static fromObject(value) {
774
+ if (ErrorFragment.isErrorFragment(value)) {
775
+ return value;
776
+ }
777
+ if (value.type !== "error") {
778
+ logger.throwArgumentError("invalid error object", "value", value);
779
+ }
780
+ const params = {
781
+ type: value.type,
782
+ name: verifyIdentifier(value.name),
783
+ inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : [])
784
+ };
785
+ return checkForbidden(new ErrorFragment(_constructorGuard, params));
786
+ }
787
+ static fromString(value) {
788
+ let params = { type: "error" };
789
+ let parens = value.match(regexParen);
790
+ if (!parens) {
791
+ logger.throwArgumentError("invalid error signature", "value", value);
792
+ }
793
+ params.name = parens[1].trim();
794
+ if (params.name) {
795
+ verifyIdentifier(params.name);
796
+ }
797
+ params.inputs = parseParams(parens[2], false);
798
+ return checkForbidden(ErrorFragment.fromObject(params));
799
+ }
800
+ static isErrorFragment(value) {
801
+ return (value && value._isFragment && value.type === "error");
802
+ }
803
+ }
804
+ function verifyType(type) {
805
+ // These need to be transformed to their full description
806
+ if (type.match(/^uint($|[^1-9])/)) {
807
+ type = "uint256" + type.substring(4);
808
+ }
809
+ else if (type.match(/^int($|[^1-9])/)) {
810
+ type = "int256" + type.substring(3);
811
+ }
812
+ // @TODO: more verification
813
+ return type;
814
+ }
815
+ // See: https://github.com/ethereum/solidity/blob/1f8f1a3db93a548d0555e3e14cfc55a10e25b60e/docs/grammar/SolidityLexer.g4#L234
816
+ const regexIdentifier = new RegExp("^[a-zA-Z$_][a-zA-Z0-9$_]*$");
817
+ function verifyIdentifier(value) {
818
+ if (!value || !value.match(regexIdentifier)) {
819
+ logger.throwArgumentError(`invalid identifier "${value}"`, "value", value);
820
+ }
821
+ return value;
822
+ }
823
+ const regexParen = new RegExp("^([^)(]*)\\((.*)\\)([^)(]*)$");
824
+ function splitNesting(value) {
825
+ value = value.trim();
826
+ let result = [];
827
+ let accum = "";
828
+ let depth = 0;
829
+ for (let offset = 0; offset < value.length; offset++) {
830
+ let c = value[offset];
831
+ if (c === "," && depth === 0) {
832
+ result.push(accum);
833
+ accum = "";
834
+ }
835
+ else {
836
+ accum += c;
837
+ if (c === "(") {
838
+ depth++;
839
+ }
840
+ else if (c === ")") {
841
+ depth--;
842
+ if (depth === -1) {
843
+ logger.throwArgumentError("unbalanced parenthesis", "value", value);
844
+ }
845
+ }
846
+ }
847
+ }
848
+ if (accum) {
849
+ result.push(accum);
850
+ }
851
+ return result;
852
+ }
853
+
854
+ export { ConstructorFragment, ErrorFragment, EventFragment, FormatTypes, Fragment, FunctionFragment, ParamType };