@waku/rln 0.0.1 → 0.0.2-09108d9.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 (392) hide show
  1. package/README.md +12 -108
  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 +11 -10
  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/constants.js +68 -0
  197. package/bundle/packages/rln/dist/contract/rln_contract.js +218 -0
  198. package/bundle/packages/rln/dist/create.js +9 -0
  199. package/bundle/packages/rln/dist/identity.js +30 -0
  200. package/bundle/packages/rln/dist/keystore/cipher.js +31 -0
  201. package/bundle/packages/rln/dist/keystore/credential_validation_generated.js +119 -0
  202. package/bundle/packages/rln/dist/keystore/keystore.js +223 -0
  203. package/bundle/packages/rln/dist/keystore/keystore_validation_generated.js +74 -0
  204. package/bundle/packages/rln/dist/keystore/schema_validator.js +20 -0
  205. package/bundle/packages/rln/dist/message.js +51 -0
  206. package/bundle/packages/rln/dist/proof.js +54 -0
  207. package/bundle/packages/rln/dist/resources/verification_key.js +112 -0
  208. package/bundle/packages/rln/dist/resources/witness_calculator.js +330 -0
  209. package/bundle/packages/rln/dist/rln.js +206 -0
  210. package/bundle/packages/rln/dist/root_tracker.js +76 -0
  211. package/bundle/packages/rln/dist/utils/bytes.js +65 -0
  212. package/bundle/packages/rln/dist/utils/epoch.js +39 -0
  213. package/bundle/packages/rln/dist/utils/hash.js +10 -0
  214. package/bundle/packages/rln/dist/utils/metamask.js +14 -0
  215. package/bundle/packages/rln/dist/zerokit.js +108 -0
  216. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +52 -0
  217. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +65 -0
  218. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +99 -0
  219. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +103 -0
  220. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/index.js +28 -0
  221. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +78 -0
  222. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +17 -0
  223. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1253 -0
  224. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +40 -0
  225. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/types.js +5 -0
  226. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +103 -0
  227. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +41 -0
  228. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +17 -0
  229. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +23 -0
  230. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +12 -0
  231. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +77 -0
  232. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +9 -0
  233. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +215 -0
  234. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +3 -0
  235. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +35 -0
  236. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +3 -0
  237. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +21 -0
  238. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
  239. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
  240. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +96 -0
  241. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +6 -0
  242. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +66 -0
  243. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +24 -0
  244. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +6 -0
  245. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +7 -0
  246. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +11 -0
  247. package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +52 -0
  248. package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +124 -0
  249. package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +71 -0
  250. package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +10 -0
  251. package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +88 -0
  252. package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +99 -0
  253. package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +233 -0
  254. package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +133 -0
  255. package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +243 -0
  256. package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +167 -0
  257. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/native.js +4 -0
  258. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/rng.js +13 -0
  259. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/stringify.js +28 -0
  260. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/v4.js +19 -0
  261. package/bundle/packages/utils/dist/bytes/index.js +44 -0
  262. package/bundle/packages/utils/dist/common/sharding/index.js +91 -0
  263. package/bundle/packages/utils/dist/logger/index.js +31 -0
  264. package/bundle/resources/rln.wasm +0 -0
  265. package/bundle/resources/rln_final.zkey +0 -0
  266. package/bundle/resources/verification_key.d.ts +13 -0
  267. package/bundle/resources/verification_key.js +112 -0
  268. package/bundle/resources/witness_calculator.d.ts +11 -0
  269. package/bundle/resources/witness_calculator.js +328 -0
  270. package/dist/.tsbuildinfo +1 -1
  271. package/dist/codec.d.ts +39 -0
  272. package/dist/codec.js +77 -0
  273. package/dist/codec.js.map +1 -0
  274. package/dist/contract/constants.d.ts +7 -0
  275. package/dist/contract/constants.js +67 -0
  276. package/dist/contract/constants.js.map +1 -0
  277. package/dist/contract/index.d.ts +2 -0
  278. package/dist/contract/index.js +3 -0
  279. package/dist/contract/index.js.map +1 -0
  280. package/dist/contract/rln_contract.d.ts +46 -0
  281. package/dist/contract/rln_contract.js +211 -0
  282. package/dist/contract/rln_contract.js.map +1 -0
  283. package/dist/create.d.ts +2 -0
  284. package/dist/create.js +8 -0
  285. package/dist/create.js.map +1 -0
  286. package/dist/identity.d.ts +9 -0
  287. package/dist/identity.js +27 -0
  288. package/dist/identity.js.map +1 -0
  289. package/dist/index.d.ts +11 -2
  290. package/dist/index.js +11 -8
  291. package/dist/index.js.map +1 -1
  292. package/dist/keystore/cipher.d.ts +4 -0
  293. package/dist/keystore/cipher.js +28 -0
  294. package/dist/keystore/cipher.js.map +1 -0
  295. package/dist/keystore/credential_validation_generated.d.ts +8 -0
  296. package/dist/keystore/credential_validation_generated.js +121 -0
  297. package/dist/keystore/credential_validation_generated.js.map +1 -0
  298. package/dist/keystore/index.d.ts +4 -0
  299. package/dist/keystore/index.js +3 -0
  300. package/dist/keystore/index.js.map +1 -0
  301. package/dist/keystore/keystore.d.ts +50 -0
  302. package/dist/keystore/keystore.js +205 -0
  303. package/dist/keystore/keystore.js.map +1 -0
  304. package/dist/keystore/keystore_validation_generated.d.ts +8 -0
  305. package/dist/keystore/keystore_validation_generated.js +75 -0
  306. package/dist/keystore/keystore_validation_generated.js.map +1 -0
  307. package/dist/keystore/schema_validator.d.ts +2 -0
  308. package/dist/keystore/schema_validator.js +18 -0
  309. package/dist/keystore/schema_validator.js.map +1 -0
  310. package/dist/keystore/types.d.ts +29 -0
  311. package/dist/keystore/types.js +2 -0
  312. package/dist/keystore/types.js.map +1 -0
  313. package/dist/message.d.ts +18 -0
  314. package/dist/message.js +49 -0
  315. package/dist/message.js.map +1 -0
  316. package/dist/proof.d.ts +21 -0
  317. package/dist/proof.js +50 -0
  318. package/dist/proof.js.map +1 -0
  319. package/dist/resources/rln.wasm +0 -0
  320. package/dist/resources/rln_final.zkey +0 -0
  321. package/dist/resources/verification_key.d.ts +13 -0
  322. package/dist/resources/verification_key.js +112 -0
  323. package/dist/resources/witness_calculator.d.ts +11 -0
  324. package/dist/resources/witness_calculator.js +328 -0
  325. package/dist/rln.d.ts +55 -13
  326. package/dist/rln.js +164 -79
  327. package/dist/rln.js.map +1 -1
  328. package/dist/root_tracker.d.ts +10 -0
  329. package/dist/root_tracker.js +75 -0
  330. package/dist/root_tracker.js.map +1 -0
  331. package/dist/utils/bytes.d.ts +20 -0
  332. package/dist/utils/bytes.js +64 -0
  333. package/dist/utils/bytes.js.map +1 -0
  334. package/dist/utils/epoch.d.ts +3 -0
  335. package/dist/utils/epoch.js +23 -0
  336. package/dist/utils/epoch.js.map +1 -0
  337. package/dist/utils/hash.d.ts +2 -0
  338. package/dist/utils/hash.js +13 -0
  339. package/dist/utils/hash.js.map +1 -0
  340. package/dist/utils/index.d.ts +4 -0
  341. package/dist/utils/index.js +5 -0
  342. package/dist/utils/index.js.map +1 -0
  343. package/dist/utils/metamask.d.ts +2 -0
  344. package/dist/utils/metamask.js +12 -0
  345. package/dist/utils/metamask.js.map +1 -0
  346. package/dist/zerokit.d.ts +19 -0
  347. package/dist/zerokit.js +105 -0
  348. package/dist/zerokit.js.map +1 -0
  349. package/package.json +1 -126
  350. package/src/codec.ts +134 -0
  351. package/src/contract/constants.ts +68 -0
  352. package/src/contract/index.ts +2 -0
  353. package/src/contract/rln_contract.ts +353 -0
  354. package/src/create.ts +9 -0
  355. package/src/identity.ts +31 -0
  356. package/src/index.ts +29 -10
  357. package/src/keystore/cipher.ts +54 -0
  358. package/src/keystore/credential_validation_generated.ts +7 -0
  359. package/src/keystore/index.ts +5 -0
  360. package/src/keystore/keystore.ts +330 -0
  361. package/src/keystore/keystore_validation_generated.ts +7 -0
  362. package/src/keystore/schema_validator.ts +34 -0
  363. package/src/keystore/types.ts +36 -0
  364. package/src/message.ts +70 -0
  365. package/src/proof.ts +69 -0
  366. package/src/resources/verification_key.d.ts +13 -0
  367. package/src/resources/witness_calculator.d.ts +11 -0
  368. package/src/rln.ts +266 -104
  369. package/src/root_tracker.ts +92 -0
  370. package/src/utils/bytes.ts +84 -0
  371. package/src/utils/epoch.ts +30 -0
  372. package/src/utils/hash.ts +15 -0
  373. package/src/utils/index.ts +9 -0
  374. package/src/utils/metamask.ts +17 -0
  375. package/src/zerokit.ts +184 -0
  376. package/bundle/02bce7e5f3bcf834.wasm +0 -0
  377. package/bundle/rln-f87f6dbe.js +0 -563
  378. package/dist/resources.d.ts +0 -4
  379. package/dist/resources.js +0 -5
  380. package/dist/resources.js.map +0 -1
  381. package/dist/witness_calculator.d.ts +0 -16
  382. package/dist/witness_calculator.js +0 -291
  383. package/dist/witness_calculator.js.map +0 -1
  384. package/dist/zerokit/rln_wasm.d.ts +0 -1
  385. package/dist/zerokit/rln_wasm.js +0 -2
  386. package/dist/zerokit/rln_wasm.js.map +0 -1
  387. package/dist/zerokit/rln_wasm_bg.d.ts +0 -108
  388. package/dist/zerokit/rln_wasm_bg.js +0 -592
  389. package/dist/zerokit/rln_wasm_bg.js.map +0 -1
  390. package/dist/zerokit/rln_wasm_bg.wasm +0 -0
  391. package/src/resources.ts +0 -10
  392. package/src/witness_calculator.d.ts +0 -4
package/src/rln.ts CHANGED
@@ -1,136 +1,298 @@
1
- import * as resources from "./resources";
2
- import * as wc from "./witness_calculator";
3
- import * as zerokitRLN from "./zerokit/rln_wasm";
1
+ import { createDecoder, createEncoder } from "@waku/core";
2
+ import type {
3
+ ContentTopic,
4
+ IDecodedMessage,
5
+ EncoderOptions as WakuEncoderOptions
6
+ } from "@waku/interfaces";
7
+ import { Logger } from "@waku/utils";
8
+ import init from "@waku/zerokit-rln-wasm";
9
+ import * as zerokitRLN from "@waku/zerokit-rln-wasm";
10
+ import { ethers } from "ethers";
4
11
 
5
- /**
6
- * Convert a base64 string into uint8Array
7
- * @param base64
8
- * @returns Uint8Array
9
- */
10
- function base64ToUint8Array(base64: string): Uint8Array {
11
- const binary_string = window.atob(base64);
12
- const len = binary_string.length;
13
- const bytes = new Uint8Array(len);
14
- for (let i = 0; i < len; i++) {
15
- bytes[i] = binary_string.charCodeAt(i);
12
+ import {
13
+ createRLNDecoder,
14
+ createRLNEncoder,
15
+ type RLNDecoder,
16
+ type RLNEncoder
17
+ } from "./codec.js";
18
+ import { RLNContract, SEPOLIA_CONTRACT } from "./contract/index.js";
19
+ import { IdentityCredential } from "./identity.js";
20
+ import { Keystore } from "./keystore/index.js";
21
+ import type {
22
+ DecryptedCredentials,
23
+ EncryptedCredentials
24
+ } from "./keystore/index.js";
25
+ import { KeystoreEntity, Password } from "./keystore/types.js";
26
+ import verificationKey from "./resources/verification_key";
27
+ import * as wc from "./resources/witness_calculator";
28
+ import { extractMetaMaskSigner } from "./utils/index.js";
29
+ import { Zerokit } from "./zerokit.js";
30
+
31
+ const log = new Logger("waku:rln");
32
+
33
+ async function loadWitnessCalculator(): Promise<wc.WitnessCalculator> {
34
+ const res = await fetch("/base/rln.wasm");
35
+ if (!res.ok) {
36
+ throw new Error(`Failed to fetch rln.wasm: ${res.statusText}`);
16
37
  }
17
- return bytes;
38
+ const witnessBuffer = await res.arrayBuffer();
39
+ return wc.builder(new Uint8Array(witnessBuffer), false);
18
40
  }
19
41
 
20
- /**
21
- * Concatenate Uint8Arrays
22
- * @param input
23
- * @returns concatenation of all Uint8Array received as input
24
- */
25
- function concatenate(...input: Uint8Array[]): Uint8Array {
26
- let totalLength = 0;
27
- for (const arr of input) {
28
- totalLength += arr.length;
29
- }
30
- const result = new Uint8Array(totalLength);
31
- let offset = 0;
32
- for (const arr of input) {
33
- result.set(arr, offset);
34
- offset += arr.length;
42
+ async function loadZkey(): Promise<Uint8Array> {
43
+ const res = await fetch("/base/rln_final.zkey");
44
+ if (!res.ok) {
45
+ throw new Error(`Failed to fetch rln_final.zkey: ${res.statusText}`);
35
46
  }
36
- return result;
47
+ return new Uint8Array(await res.arrayBuffer());
37
48
  }
38
49
 
39
- const DEPTH = 20;
40
- const VERIFICATION_KEY = base64ToUint8Array(resources.verification_key);
41
- const ZKEY = base64ToUint8Array(resources.zkey);
42
- const CIRCUIT = base64ToUint8Array(resources.circuit);
43
-
44
- zerokitRLN.init_panic_hook();
45
-
46
50
  /**
47
51
  * Create an instance of RLN
48
52
  * @returns RLNInstance
49
53
  */
50
54
  export async function create(): Promise<RLNInstance> {
51
- const witnessCalculator = await wc.builder(CIRCUIT, false);
52
- const zkRLN = zerokitRLN.newRLN(DEPTH, ZKEY, VERIFICATION_KEY);
53
- return new RLNInstance(zkRLN, witnessCalculator);
54
- }
55
+ try {
56
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
+ await (init as any)?.();
58
+ zerokitRLN.init_panic_hook();
55
59
 
56
- export class MembershipKey {
57
- readonly IDKey: Uint8Array;
58
- readonly IDCommitment: Uint8Array;
60
+ const witnessCalculator = await loadWitnessCalculator();
61
+ const zkey = await loadZkey();
59
62
 
60
- constructor(memKeys: Uint8Array) {
61
- this.IDKey = memKeys.subarray(0, 32);
62
- this.IDCommitment = memKeys.subarray(32);
63
+ const stringEncoder = new TextEncoder();
64
+ const vkey = stringEncoder.encode(JSON.stringify(verificationKey));
65
+
66
+ const DEPTH = 20;
67
+ const zkRLN = zerokitRLN.newRLN(DEPTH, zkey, vkey);
68
+ const zerokit = new Zerokit(zkRLN, witnessCalculator);
69
+
70
+ return new RLNInstance(zerokit);
71
+ } catch (error) {
72
+ log.error("Failed to initialize RLN:", error);
73
+ throw error;
63
74
  }
64
75
  }
65
76
 
77
+ type StartRLNOptions = {
78
+ /**
79
+ * If not set - will extract MetaMask account and get signer from it.
80
+ */
81
+ signer?: ethers.Signer;
82
+ /**
83
+ * If not set - will use default SEPOLIA_CONTRACT address.
84
+ */
85
+ registryAddress?: string;
86
+ /**
87
+ * Credentials to use for generating proofs and connecting to the contract and network.
88
+ * If provided used for validating the network chainId and connecting to registry contract.
89
+ */
90
+ credentials?: EncryptedCredentials | DecryptedCredentials;
91
+ };
92
+
93
+ type RegisterMembershipOptions =
94
+ | { signature: string }
95
+ | { identity: IdentityCredential };
96
+
97
+ type WakuRLNEncoderOptions = WakuEncoderOptions & {
98
+ credentials: EncryptedCredentials | DecryptedCredentials;
99
+ };
100
+
66
101
  export class RLNInstance {
67
- zkRLN: number;
68
- witnessCalculator: any;
102
+ private started = false;
103
+ private starting = false;
104
+
105
+ private _contract: undefined | RLNContract;
106
+ private _signer: undefined | ethers.Signer;
69
107
 
70
- constructor(zkRLN: number, wc: any) {
71
- this.zkRLN = zkRLN;
72
- this.witnessCalculator = wc;
108
+ private keystore = Keystore.create();
109
+ private _credentials: undefined | DecryptedCredentials;
110
+
111
+ public constructor(public zerokit: Zerokit) {}
112
+
113
+ public get contract(): undefined | RLNContract {
114
+ return this._contract;
73
115
  }
74
116
 
75
- generateMembershipKey(): MembershipKey {
76
- const memKeys = zerokitRLN.generateMembershipKey(this.zkRLN);
77
- return new MembershipKey(memKeys);
117
+ public get signer(): undefined | ethers.Signer {
118
+ return this._signer;
78
119
  }
79
120
 
80
- inserMember(idCommitment: Uint8Array): void {
81
- zerokitRLN.insertMember(this.zkRLN, idCommitment);
121
+ public async start(options: StartRLNOptions = {}): Promise<void> {
122
+ if (this.started || this.starting) {
123
+ return;
124
+ }
125
+
126
+ this.starting = true;
127
+
128
+ try {
129
+ const { credentials, keystore } =
130
+ await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
131
+ const { signer, registryAddress } = await this.determineStartOptions(
132
+ options,
133
+ credentials
134
+ );
135
+
136
+ if (keystore) {
137
+ this.keystore = keystore;
138
+ }
139
+
140
+ this._credentials = credentials;
141
+ this._signer = signer!;
142
+ this._contract = await RLNContract.init(this, {
143
+ registryAddress: registryAddress!,
144
+ signer: signer!
145
+ });
146
+ this.started = true;
147
+ } finally {
148
+ this.starting = false;
149
+ }
82
150
  }
83
151
 
84
- serializeMessage(
85
- uint8Msg: Uint8Array,
86
- memIndex: number,
87
- epoch: Uint8Array,
88
- idKey: Uint8Array
89
- ): Uint8Array {
90
- if (epoch.length != 32) throw "invalid epoch";
91
- if (idKey.length != 32) throw "invalid id key";
92
-
93
- // calculate message length
94
- const msgLen = Buffer.allocUnsafe(8);
95
- msgLen.writeUIntLE(uint8Msg.length, 0, 8);
96
-
97
- // Converting index to LE bytes
98
- const memIndexBytes = Buffer.allocUnsafe(8);
99
- memIndexBytes.writeUIntLE(memIndex, 0, 8);
100
-
101
- // [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> ]
102
- return concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg);
152
+ private async determineStartOptions(
153
+ options: StartRLNOptions,
154
+ credentials: KeystoreEntity | undefined
155
+ ): Promise<StartRLNOptions> {
156
+ let chainId = credentials?.membership.chainId;
157
+ const registryAddress =
158
+ credentials?.membership.address ||
159
+ options.registryAddress ||
160
+ SEPOLIA_CONTRACT.address;
161
+
162
+ if (registryAddress === SEPOLIA_CONTRACT.address) {
163
+ chainId = SEPOLIA_CONTRACT.chainId;
164
+ }
165
+
166
+ const signer = options.signer || (await extractMetaMaskSigner());
167
+ const currentChainId = await signer.getChainId();
168
+
169
+ if (chainId && chainId !== currentChainId) {
170
+ throw Error(
171
+ `Failed to start RLN contract, chain ID of contract is different from current one: contract-${chainId}, current network-${currentChainId}`
172
+ );
173
+ }
174
+
175
+ return {
176
+ signer,
177
+ registryAddress
178
+ };
103
179
  }
104
180
 
105
- async generateProof(
106
- msg: Uint8Array,
107
- index: number,
108
- epoch: Uint8Array,
109
- idKey: Uint8Array
110
- ): Promise<Uint8Array> {
111
- if (epoch.length != 32) throw "invalid epoch";
112
- if (idKey.length != 32) throw "invalid id key";
113
- if (index < 0) throw "index must be >= 0";
114
-
115
- const serialized_msg = this.serializeMessage(msg, index, epoch, idKey);
116
- const rlnWitness = zerokitRLN.getSerializedRLNWitness(
117
- this.zkRLN,
118
- serialized_msg
119
- );
120
- const inputs = zerokitRLN.RLNWitnessToJson(this.zkRLN, rlnWitness);
121
- const calculatedWitness = await this.witnessCalculator.calculateWitness(
122
- inputs,
123
- false
124
- ); // no sanity check being used in zerokit
125
-
126
- return zerokitRLN.generate_rln_proof_with_witness(
127
- this.zkRLN,
128
- calculatedWitness,
129
- rlnWitness
181
+ private static async decryptCredentialsIfNeeded(
182
+ credentials?: EncryptedCredentials | DecryptedCredentials
183
+ ): Promise<{ credentials?: DecryptedCredentials; keystore?: Keystore }> {
184
+ if (!credentials) {
185
+ return {};
186
+ }
187
+
188
+ if ("identity" in credentials) {
189
+ return { credentials };
190
+ }
191
+
192
+ const keystore = Keystore.fromString(credentials.keystore);
193
+
194
+ if (!keystore) {
195
+ return {};
196
+ }
197
+
198
+ const decryptedCredentials = await keystore.readCredential(
199
+ credentials.id,
200
+ credentials.password
130
201
  );
202
+
203
+ return {
204
+ keystore,
205
+ credentials: decryptedCredentials
206
+ };
207
+ }
208
+
209
+ public async registerMembership(
210
+ options: RegisterMembershipOptions
211
+ ): Promise<undefined | DecryptedCredentials> {
212
+ if (!this.contract) {
213
+ throw Error("RLN Contract is not initialized.");
214
+ }
215
+
216
+ let identity = "identity" in options && options.identity;
217
+
218
+ if ("signature" in options) {
219
+ identity = this.zerokit.generateSeededIdentityCredential(
220
+ options.signature
221
+ );
222
+ }
223
+
224
+ if (!identity) {
225
+ throw Error("Missing signature or identity to register membership.");
226
+ }
227
+
228
+ return this.contract.registerWithIdentity(identity);
229
+ }
230
+
231
+ /**
232
+ * Changes credentials in use by relying on provided Keystore earlier in rln.start
233
+ * @param id: string, hash of credentials to select from Keystore
234
+ * @param password: string or bytes to use to decrypt credentials from Keystore
235
+ */
236
+ public async useCredentials(id: string, password: Password): Promise<void> {
237
+ this._credentials = await this.keystore?.readCredential(id, password);
238
+ }
239
+
240
+ public async createEncoder(
241
+ options: WakuRLNEncoderOptions
242
+ ): Promise<RLNEncoder> {
243
+ const { credentials: decryptedCredentials } =
244
+ await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
245
+ const credentials = decryptedCredentials || this._credentials;
246
+
247
+ if (!credentials) {
248
+ throw Error(
249
+ "Failed to create Encoder: missing RLN credentials. Use createRLNEncoder directly."
250
+ );
251
+ }
252
+
253
+ await this.verifyCredentialsAgainstContract(credentials);
254
+
255
+ return createRLNEncoder({
256
+ encoder: createEncoder(options),
257
+ rlnInstance: this,
258
+ index: credentials.membership.treeIndex,
259
+ credential: credentials.identity
260
+ });
261
+ }
262
+
263
+ private async verifyCredentialsAgainstContract(
264
+ credentials: KeystoreEntity
265
+ ): Promise<void> {
266
+ if (!this._contract) {
267
+ throw Error(
268
+ "Failed to verify chain coordinates: no contract initialized."
269
+ );
270
+ }
271
+
272
+ const registryAddress = credentials.membership.address;
273
+ const currentRegistryAddress = this._contract.registry.address;
274
+ if (registryAddress !== currentRegistryAddress) {
275
+ throw Error(
276
+ `Failed to verify chain coordinates: credentials contract address=${registryAddress} is not equal to registryContract address=${currentRegistryAddress}`
277
+ );
278
+ }
279
+
280
+ const chainId = credentials.membership.chainId;
281
+ const network = await this._contract.registry.provider.getNetwork();
282
+ const currentChainId = network.chainId;
283
+ if (chainId !== currentChainId) {
284
+ throw Error(
285
+ `Failed to verify chain coordinates: credentials chainID=${chainId} is not equal to registryContract chainID=${currentChainId}`
286
+ );
287
+ }
131
288
  }
132
289
 
133
- verifyProof(proof: Uint8Array): boolean {
134
- return zerokitRLN.verifyProof(this.zkRLN, proof);
290
+ public createDecoder(
291
+ contentTopic: ContentTopic
292
+ ): RLNDecoder<IDecodedMessage> {
293
+ return createRLNDecoder({
294
+ rlnInstance: this,
295
+ decoder: createDecoder(contentTopic)
296
+ });
135
297
  }
136
298
  }
@@ -0,0 +1,92 @@
1
+ class RootPerBlock {
2
+ public constructor(
3
+ public root: Uint8Array,
4
+ public blockNumber: number
5
+ ) {}
6
+ }
7
+
8
+ const maxBufferSize = 20;
9
+
10
+ export class MerkleRootTracker {
11
+ private validMerkleRoots: Array<RootPerBlock> = new Array<RootPerBlock>();
12
+ private merkleRootBuffer: Array<RootPerBlock> = new Array<RootPerBlock>();
13
+
14
+ public constructor(
15
+ private acceptableRootWindowSize: number,
16
+ initialRoot: Uint8Array
17
+ ) {
18
+ this.pushRoot(0, initialRoot);
19
+ }
20
+
21
+ public backFill(fromBlockNumber: number): void {
22
+ if (this.validMerkleRoots.length == 0) return;
23
+
24
+ let numBlocks = 0;
25
+ for (let i = this.validMerkleRoots.length - 1; i >= 0; i--) {
26
+ if (this.validMerkleRoots[i].blockNumber >= fromBlockNumber) {
27
+ numBlocks++;
28
+ }
29
+ }
30
+
31
+ if (numBlocks == 0) return;
32
+
33
+ const olderBlock = fromBlockNumber < this.validMerkleRoots[0].blockNumber;
34
+
35
+ // Remove last roots
36
+ let rootsToPop = numBlocks;
37
+ if (this.validMerkleRoots.length < rootsToPop) {
38
+ rootsToPop = this.validMerkleRoots.length;
39
+ }
40
+
41
+ this.validMerkleRoots = this.validMerkleRoots.slice(
42
+ 0,
43
+ this.validMerkleRoots.length - rootsToPop
44
+ );
45
+
46
+ if (this.merkleRootBuffer.length == 0) return;
47
+
48
+ if (olderBlock) {
49
+ const idx = this.merkleRootBuffer.findIndex(
50
+ (x) => x.blockNumber == fromBlockNumber
51
+ );
52
+ if (idx > -1) {
53
+ this.merkleRootBuffer = this.merkleRootBuffer.slice(0, idx);
54
+ }
55
+ }
56
+
57
+ // Backfill the tree's acceptable roots
58
+ let rootsToRestore =
59
+ this.acceptableRootWindowSize - this.validMerkleRoots.length;
60
+ if (this.merkleRootBuffer.length < rootsToRestore) {
61
+ rootsToRestore = this.merkleRootBuffer.length;
62
+ }
63
+
64
+ for (let i = 0; i < rootsToRestore; i++) {
65
+ const x = this.merkleRootBuffer.pop();
66
+ if (x) this.validMerkleRoots.unshift(x);
67
+ }
68
+ }
69
+
70
+ public pushRoot(blockNumber: number, root: Uint8Array): void {
71
+ this.validMerkleRoots.push(new RootPerBlock(root, blockNumber));
72
+
73
+ // Maintain valid merkle root window
74
+ if (this.validMerkleRoots.length > this.acceptableRootWindowSize) {
75
+ const x = this.validMerkleRoots.shift();
76
+ if (x) this.merkleRootBuffer.push(x);
77
+ }
78
+
79
+ // Maintain merkle root buffer
80
+ if (this.merkleRootBuffer.length > maxBufferSize) {
81
+ this.merkleRootBuffer.shift();
82
+ }
83
+ }
84
+
85
+ public roots(): Array<Uint8Array> {
86
+ return this.validMerkleRoots.map((x) => x.root);
87
+ }
88
+
89
+ public buffer(): Array<Uint8Array> {
90
+ return this.merkleRootBuffer.map((x) => x.root);
91
+ }
92
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Concatenate Uint8Arrays
3
+ * @param input
4
+ * @returns concatenation of all Uint8Array received as input
5
+ */
6
+ export function concatenate(...input: Uint8Array[]): Uint8Array {
7
+ let totalLength = 0;
8
+ for (const arr of input) {
9
+ totalLength += arr.length;
10
+ }
11
+ const result = new Uint8Array(totalLength);
12
+ let offset = 0;
13
+ for (const arr of input) {
14
+ result.set(arr, offset);
15
+ offset += arr.length;
16
+ }
17
+ return result;
18
+ }
19
+
20
+ // Adapted from https://github.com/feross/buffer
21
+ function checkInt(
22
+ buf: Uint8Array,
23
+ value: number,
24
+ offset: number,
25
+ ext: number,
26
+ max: number,
27
+ min: number
28
+ ): void {
29
+ if (value > max || value < min)
30
+ throw new RangeError('"value" argument is out of bounds');
31
+ if (offset + ext > buf.length) throw new RangeError("Index out of range");
32
+ }
33
+
34
+ export function writeUIntLE(
35
+ buf: Uint8Array,
36
+ value: number,
37
+ offset: number,
38
+ byteLength: number,
39
+ noAssert?: boolean
40
+ ): Uint8Array {
41
+ value = +value;
42
+ offset = offset >>> 0;
43
+ byteLength = byteLength >>> 0;
44
+ if (!noAssert) {
45
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
46
+ checkInt(buf, value, offset, byteLength, maxBytes, 0);
47
+ }
48
+
49
+ let mul = 1;
50
+ let i = 0;
51
+ buf[offset] = value & 0xff;
52
+ while (++i < byteLength && (mul *= 0x100)) {
53
+ buf[offset + i] = (value / mul) & 0xff;
54
+ }
55
+
56
+ return buf;
57
+ }
58
+
59
+ /**
60
+ * Transforms Uint8Array into BigInt
61
+ * @param array: Uint8Array
62
+ * @returns BigInt
63
+ */
64
+ export function buildBigIntFromUint8Array(
65
+ array: Uint8Array,
66
+ byteOffset: number = 0
67
+ ): bigint {
68
+ const dataView = new DataView(array.buffer);
69
+ return dataView.getBigUint64(byteOffset, true);
70
+ }
71
+
72
+ /**
73
+ * Fills with zeros to set length
74
+ * @param array little endian Uint8Array
75
+ * @param length amount to pad
76
+ * @returns little endian Uint8Array padded with zeros to set length
77
+ */
78
+ export function zeroPadLE(array: Uint8Array, length: number): Uint8Array {
79
+ const result = new Uint8Array(length);
80
+ for (let i = 0; i < length; i++) {
81
+ result[i] = array[i] || 0;
82
+ }
83
+ return result;
84
+ }
@@ -0,0 +1,30 @@
1
+ import { Logger } from "@waku/utils";
2
+
3
+ const DefaultEpochUnitSeconds = 10; // the rln-relay epoch length in seconds
4
+
5
+ const log = new Logger("waku:rln:epoch");
6
+
7
+ export function dateToEpoch(
8
+ timestamp: Date,
9
+ epochUnitSeconds: number = DefaultEpochUnitSeconds
10
+ ): number {
11
+ const time = timestamp.getTime();
12
+ const epoch = Math.floor(time / 1000 / epochUnitSeconds);
13
+ log.info("generated epoch", epoch);
14
+ return epoch;
15
+ }
16
+
17
+ export function epochIntToBytes(epoch: number): Uint8Array {
18
+ const bytes = new Uint8Array(32);
19
+ const db = new DataView(bytes.buffer);
20
+ db.setUint32(0, epoch, true);
21
+ log.info("encoded epoch", epoch, bytes);
22
+ return bytes;
23
+ }
24
+
25
+ export function epochBytesToInt(bytes: Uint8Array): number {
26
+ const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
27
+ const epoch = dv.getUint32(0, true);
28
+ log.info("decoded epoch", epoch, bytes);
29
+ return epoch;
30
+ }
@@ -0,0 +1,15 @@
1
+ import * as zerokitRLN from "@waku/zerokit-rln-wasm";
2
+
3
+ import { concatenate, writeUIntLE } from "./bytes.js";
4
+
5
+ export function poseidonHash(...input: Array<Uint8Array>): Uint8Array {
6
+ const inputLen = writeUIntLE(new Uint8Array(8), input.length, 0, 8);
7
+ const lenPrefixedData = concatenate(inputLen, ...input);
8
+ return zerokitRLN.poseidonHash(lenPrefixedData);
9
+ }
10
+
11
+ export function sha256(input: Uint8Array): Uint8Array {
12
+ const inputLen = writeUIntLE(new Uint8Array(8), input.length, 0, 8);
13
+ const lenPrefixedData = concatenate(inputLen, input);
14
+ return zerokitRLN.hash(lenPrefixedData);
15
+ }
@@ -0,0 +1,9 @@
1
+ export { extractMetaMaskSigner } from "./metamask.js";
2
+ export {
3
+ concatenate,
4
+ writeUIntLE,
5
+ buildBigIntFromUint8Array,
6
+ zeroPadLE
7
+ } from "./bytes.js";
8
+ export { sha256, poseidonHash } from "./hash.js";
9
+ export { dateToEpoch, epochIntToBytes, epochBytesToInt } from "./epoch.js";
@@ -0,0 +1,17 @@
1
+ import { ethers } from "ethers";
2
+
3
+ export const extractMetaMaskSigner = async (): Promise<ethers.Signer> => {
4
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
+ const ethereum = (window as any).ethereum;
6
+
7
+ if (!ethereum) {
8
+ throw Error(
9
+ "Missing or invalid Ethereum provider. Please install a Web3 wallet such as MetaMask."
10
+ );
11
+ }
12
+
13
+ await ethereum.request({ method: "eth_requestAccounts" });
14
+ const provider = new ethers.providers.Web3Provider(ethereum, "any");
15
+
16
+ return provider.getSigner();
17
+ };