@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/dist/rln.js CHANGED
@@ -1,99 +1,184 @@
1
- import * as resources from "./resources";
2
- import * as wc from "./witness_calculator";
3
- import * as zerokitRLN from "./zerokit/rln_wasm";
4
- /**
5
- * Convert a base64 string into uint8Array
6
- * @param base64
7
- * @returns Uint8Array
8
- */
9
- function base64ToUint8Array(base64) {
10
- const binary_string = window.atob(base64);
11
- const len = binary_string.length;
12
- const bytes = new Uint8Array(len);
13
- for (let i = 0; i < len; i++) {
14
- bytes[i] = binary_string.charCodeAt(i);
1
+ import { createDecoder, createEncoder } from "@waku/core";
2
+ import { Logger } from "@waku/utils";
3
+ import init from "@waku/zerokit-rln-wasm";
4
+ import * as zerokitRLN from "@waku/zerokit-rln-wasm";
5
+ import { createRLNDecoder, createRLNEncoder } from "./codec.js";
6
+ import { RLNContract, SEPOLIA_CONTRACT } from "./contract/index.js";
7
+ import { Keystore } from "./keystore/index.js";
8
+ import verificationKey from "./resources/verification_key";
9
+ import * as wc from "./resources/witness_calculator";
10
+ import { extractMetaMaskSigner } from "./utils/index.js";
11
+ import { Zerokit } from "./zerokit.js";
12
+ const log = new Logger("waku:rln");
13
+ async function loadWitnessCalculator() {
14
+ const res = await fetch("/base/rln.wasm");
15
+ if (!res.ok) {
16
+ throw new Error(`Failed to fetch rln.wasm: ${res.statusText}`);
15
17
  }
16
- return bytes;
18
+ const witnessBuffer = await res.arrayBuffer();
19
+ return wc.builder(new Uint8Array(witnessBuffer), false);
17
20
  }
18
- /**
19
- * Concatenate Uint8Arrays
20
- * @param input
21
- * @returns concatenation of all Uint8Array received as input
22
- */
23
- function concatenate(...input) {
24
- let totalLength = 0;
25
- for (const arr of input) {
26
- totalLength += arr.length;
27
- }
28
- const result = new Uint8Array(totalLength);
29
- let offset = 0;
30
- for (const arr of input) {
31
- result.set(arr, offset);
32
- offset += arr.length;
21
+ async function loadZkey() {
22
+ const res = await fetch("/base/rln_final.zkey");
23
+ if (!res.ok) {
24
+ throw new Error(`Failed to fetch rln_final.zkey: ${res.statusText}`);
33
25
  }
34
- return result;
26
+ return new Uint8Array(await res.arrayBuffer());
35
27
  }
36
- const DEPTH = 20;
37
- const VERIFICATION_KEY = base64ToUint8Array(resources.verification_key);
38
- const ZKEY = base64ToUint8Array(resources.zkey);
39
- const CIRCUIT = base64ToUint8Array(resources.circuit);
40
- zerokitRLN.init_panic_hook();
41
28
  /**
42
29
  * Create an instance of RLN
43
30
  * @returns RLNInstance
44
31
  */
45
32
  export async function create() {
46
- const witnessCalculator = await wc.builder(CIRCUIT, false);
47
- const zkRLN = zerokitRLN.newRLN(DEPTH, ZKEY, VERIFICATION_KEY);
48
- return new RLNInstance(zkRLN, witnessCalculator);
49
- }
50
- export class MembershipKey {
51
- constructor(memKeys) {
52
- this.IDKey = memKeys.subarray(0, 32);
53
- this.IDCommitment = memKeys.subarray(32);
33
+ try {
34
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
+ await init?.();
36
+ zerokitRLN.init_panic_hook();
37
+ const witnessCalculator = await loadWitnessCalculator();
38
+ const zkey = await loadZkey();
39
+ const stringEncoder = new TextEncoder();
40
+ const vkey = stringEncoder.encode(JSON.stringify(verificationKey));
41
+ const DEPTH = 20;
42
+ const zkRLN = zerokitRLN.newRLN(DEPTH, zkey, vkey);
43
+ const zerokit = new Zerokit(zkRLN, witnessCalculator);
44
+ return new RLNInstance(zerokit);
45
+ }
46
+ catch (error) {
47
+ log.error("Failed to initialize RLN:", error);
48
+ throw error;
54
49
  }
55
50
  }
56
51
  export class RLNInstance {
57
- constructor(zkRLN, wc) {
58
- this.zkRLN = zkRLN;
59
- this.witnessCalculator = wc;
52
+ zerokit;
53
+ started = false;
54
+ starting = false;
55
+ _contract;
56
+ _signer;
57
+ keystore = Keystore.create();
58
+ _credentials;
59
+ constructor(zerokit) {
60
+ this.zerokit = zerokit;
61
+ }
62
+ get contract() {
63
+ return this._contract;
64
+ }
65
+ get signer() {
66
+ return this._signer;
67
+ }
68
+ async start(options = {}) {
69
+ if (this.started || this.starting) {
70
+ return;
71
+ }
72
+ this.starting = true;
73
+ try {
74
+ const { credentials, keystore } = await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
75
+ const { signer, registryAddress } = await this.determineStartOptions(options, credentials);
76
+ if (keystore) {
77
+ this.keystore = keystore;
78
+ }
79
+ this._credentials = credentials;
80
+ this._signer = signer;
81
+ this._contract = await RLNContract.init(this, {
82
+ registryAddress: registryAddress,
83
+ signer: signer
84
+ });
85
+ this.started = true;
86
+ }
87
+ finally {
88
+ this.starting = false;
89
+ }
90
+ }
91
+ async determineStartOptions(options, credentials) {
92
+ let chainId = credentials?.membership.chainId;
93
+ const registryAddress = credentials?.membership.address ||
94
+ options.registryAddress ||
95
+ SEPOLIA_CONTRACT.address;
96
+ if (registryAddress === SEPOLIA_CONTRACT.address) {
97
+ chainId = SEPOLIA_CONTRACT.chainId;
98
+ }
99
+ const signer = options.signer || (await extractMetaMaskSigner());
100
+ const currentChainId = await signer.getChainId();
101
+ if (chainId && chainId !== currentChainId) {
102
+ throw Error(`Failed to start RLN contract, chain ID of contract is different from current one: contract-${chainId}, current network-${currentChainId}`);
103
+ }
104
+ return {
105
+ signer,
106
+ registryAddress
107
+ };
108
+ }
109
+ static async decryptCredentialsIfNeeded(credentials) {
110
+ if (!credentials) {
111
+ return {};
112
+ }
113
+ if ("identity" in credentials) {
114
+ return { credentials };
115
+ }
116
+ const keystore = Keystore.fromString(credentials.keystore);
117
+ if (!keystore) {
118
+ return {};
119
+ }
120
+ const decryptedCredentials = await keystore.readCredential(credentials.id, credentials.password);
121
+ return {
122
+ keystore,
123
+ credentials: decryptedCredentials
124
+ };
60
125
  }
61
- generateMembershipKey() {
62
- const memKeys = zerokitRLN.generateMembershipKey(this.zkRLN);
63
- return new MembershipKey(memKeys);
126
+ async registerMembership(options) {
127
+ if (!this.contract) {
128
+ throw Error("RLN Contract is not initialized.");
129
+ }
130
+ let identity = "identity" in options && options.identity;
131
+ if ("signature" in options) {
132
+ identity = this.zerokit.generateSeededIdentityCredential(options.signature);
133
+ }
134
+ if (!identity) {
135
+ throw Error("Missing signature or identity to register membership.");
136
+ }
137
+ return this.contract.registerWithIdentity(identity);
64
138
  }
65
- inserMember(idCommitment) {
66
- zerokitRLN.insertMember(this.zkRLN, idCommitment);
139
+ /**
140
+ * Changes credentials in use by relying on provided Keystore earlier in rln.start
141
+ * @param id: string, hash of credentials to select from Keystore
142
+ * @param password: string or bytes to use to decrypt credentials from Keystore
143
+ */
144
+ async useCredentials(id, password) {
145
+ this._credentials = await this.keystore?.readCredential(id, password);
67
146
  }
68
- serializeMessage(uint8Msg, memIndex, epoch, idKey) {
69
- if (epoch.length != 32)
70
- throw "invalid epoch";
71
- if (idKey.length != 32)
72
- throw "invalid id key";
73
- // calculate message length
74
- const msgLen = Buffer.allocUnsafe(8);
75
- msgLen.writeUIntLE(uint8Msg.length, 0, 8);
76
- // Converting index to LE bytes
77
- const memIndexBytes = Buffer.allocUnsafe(8);
78
- memIndexBytes.writeUIntLE(memIndex, 0, 8);
79
- // [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> ]
80
- return concatenate(idKey, memIndexBytes, epoch, msgLen, uint8Msg);
147
+ async createEncoder(options) {
148
+ const { credentials: decryptedCredentials } = await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
149
+ const credentials = decryptedCredentials || this._credentials;
150
+ if (!credentials) {
151
+ throw Error("Failed to create Encoder: missing RLN credentials. Use createRLNEncoder directly.");
152
+ }
153
+ await this.verifyCredentialsAgainstContract(credentials);
154
+ return createRLNEncoder({
155
+ encoder: createEncoder(options),
156
+ rlnInstance: this,
157
+ index: credentials.membership.treeIndex,
158
+ credential: credentials.identity
159
+ });
81
160
  }
82
- async generateProof(msg, index, epoch, idKey) {
83
- if (epoch.length != 32)
84
- throw "invalid epoch";
85
- if (idKey.length != 32)
86
- throw "invalid id key";
87
- if (index < 0)
88
- throw "index must be >= 0";
89
- const serialized_msg = this.serializeMessage(msg, index, epoch, idKey);
90
- const rlnWitness = zerokitRLN.getSerializedRLNWitness(this.zkRLN, serialized_msg);
91
- const inputs = zerokitRLN.RLNWitnessToJson(this.zkRLN, rlnWitness);
92
- const calculatedWitness = await this.witnessCalculator.calculateWitness(inputs, false); // no sanity check being used in zerokit
93
- return zerokitRLN.generate_rln_proof_with_witness(this.zkRLN, calculatedWitness, rlnWitness);
161
+ async verifyCredentialsAgainstContract(credentials) {
162
+ if (!this._contract) {
163
+ throw Error("Failed to verify chain coordinates: no contract initialized.");
164
+ }
165
+ const registryAddress = credentials.membership.address;
166
+ const currentRegistryAddress = this._contract.registry.address;
167
+ if (registryAddress !== currentRegistryAddress) {
168
+ throw Error(`Failed to verify chain coordinates: credentials contract address=${registryAddress} is not equal to registryContract address=${currentRegistryAddress}`);
169
+ }
170
+ const chainId = credentials.membership.chainId;
171
+ const network = await this._contract.registry.provider.getNetwork();
172
+ const currentChainId = network.chainId;
173
+ if (chainId !== currentChainId) {
174
+ throw Error(`Failed to verify chain coordinates: credentials chainID=${chainId} is not equal to registryContract chainID=${currentChainId}`);
175
+ }
94
176
  }
95
- verifyProof(proof) {
96
- return zerokitRLN.verifyProof(this.zkRLN, proof);
177
+ createDecoder(contentTopic) {
178
+ return createRLNDecoder({
179
+ rlnInstance: this,
180
+ decoder: createDecoder(contentTopic)
181
+ });
97
182
  }
98
183
  }
99
184
  //# sourceMappingURL=rln.js.map
package/dist/rln.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"rln.js","sourceRoot":"","sources":["../src/rln.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AAEjD;;;;GAIG;AACH,SAAS,kBAAkB,CAAC,MAAc;IACxC,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1C,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC;IACjC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;QAC5B,KAAK,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;KACxC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CA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AAK,CACT,2DAA2D,OAAO,6CAA6C,cAAc,EAAE,CAChI,CAAC;QACJ,CAAC;IACH,CAAC;IAEM,aAAa,CAClB,YAA0B;QAE1B,OAAO,gBAAgB,CAAC;YACtB,WAAW,EAAE,IAAI;YACjB,OAAO,EAAE,aAAa,CAAC,YAAY,CAAC;SACrC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ export declare class MerkleRootTracker {
2
+ private acceptableRootWindowSize;
3
+ private validMerkleRoots;
4
+ private merkleRootBuffer;
5
+ constructor(acceptableRootWindowSize: number, initialRoot: Uint8Array);
6
+ backFill(fromBlockNumber: number): void;
7
+ pushRoot(blockNumber: number, root: Uint8Array): void;
8
+ roots(): Array<Uint8Array>;
9
+ buffer(): Array<Uint8Array>;
10
+ }
@@ -0,0 +1,75 @@
1
+ class RootPerBlock {
2
+ root;
3
+ blockNumber;
4
+ constructor(root, blockNumber) {
5
+ this.root = root;
6
+ this.blockNumber = blockNumber;
7
+ }
8
+ }
9
+ const maxBufferSize = 20;
10
+ export class MerkleRootTracker {
11
+ acceptableRootWindowSize;
12
+ validMerkleRoots = new Array();
13
+ merkleRootBuffer = new Array();
14
+ constructor(acceptableRootWindowSize, initialRoot) {
15
+ this.acceptableRootWindowSize = acceptableRootWindowSize;
16
+ this.pushRoot(0, initialRoot);
17
+ }
18
+ backFill(fromBlockNumber) {
19
+ if (this.validMerkleRoots.length == 0)
20
+ return;
21
+ let numBlocks = 0;
22
+ for (let i = this.validMerkleRoots.length - 1; i >= 0; i--) {
23
+ if (this.validMerkleRoots[i].blockNumber >= fromBlockNumber) {
24
+ numBlocks++;
25
+ }
26
+ }
27
+ if (numBlocks == 0)
28
+ return;
29
+ const olderBlock = fromBlockNumber < this.validMerkleRoots[0].blockNumber;
30
+ // Remove last roots
31
+ let rootsToPop = numBlocks;
32
+ if (this.validMerkleRoots.length < rootsToPop) {
33
+ rootsToPop = this.validMerkleRoots.length;
34
+ }
35
+ this.validMerkleRoots = this.validMerkleRoots.slice(0, this.validMerkleRoots.length - rootsToPop);
36
+ if (this.merkleRootBuffer.length == 0)
37
+ return;
38
+ if (olderBlock) {
39
+ const idx = this.merkleRootBuffer.findIndex((x) => x.blockNumber == fromBlockNumber);
40
+ if (idx > -1) {
41
+ this.merkleRootBuffer = this.merkleRootBuffer.slice(0, idx);
42
+ }
43
+ }
44
+ // Backfill the tree's acceptable roots
45
+ let rootsToRestore = this.acceptableRootWindowSize - this.validMerkleRoots.length;
46
+ if (this.merkleRootBuffer.length < rootsToRestore) {
47
+ rootsToRestore = this.merkleRootBuffer.length;
48
+ }
49
+ for (let i = 0; i < rootsToRestore; i++) {
50
+ const x = this.merkleRootBuffer.pop();
51
+ if (x)
52
+ this.validMerkleRoots.unshift(x);
53
+ }
54
+ }
55
+ pushRoot(blockNumber, root) {
56
+ this.validMerkleRoots.push(new RootPerBlock(root, blockNumber));
57
+ // Maintain valid merkle root window
58
+ if (this.validMerkleRoots.length > this.acceptableRootWindowSize) {
59
+ const x = this.validMerkleRoots.shift();
60
+ if (x)
61
+ this.merkleRootBuffer.push(x);
62
+ }
63
+ // Maintain merkle root buffer
64
+ if (this.merkleRootBuffer.length > maxBufferSize) {
65
+ this.merkleRootBuffer.shift();
66
+ }
67
+ }
68
+ roots() {
69
+ return this.validMerkleRoots.map((x) => x.root);
70
+ }
71
+ buffer() {
72
+ return this.merkleRootBuffer.map((x) => x.root);
73
+ }
74
+ }
75
+ //# sourceMappingURL=root_tracker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"root_tracker.js","sourceRoot":"","sources":["../src/root_tracker.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY;IAEP;IACA;IAFT,YACS,IAAgB,EAChB,WAAmB;QADnB,SAAI,GAAJ,IAAI,CAAY;QAChB,gBAAW,GAAX,WAAW,CAAQ;IACzB,CAAC;CACL;AAED,MAAM,aAAa,GAAG,EAAE,CAAC;AAEzB,MAAM,OAAO,iBAAiB;IAKlB;IAJF,gBA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,aAAa,EAAE,CAAC;YACjD,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAChC,CAAC;IACH,CAAC;IAEM,KAAK;QACV,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IAEM,MAAM;QACX,OAAO,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Concatenate Uint8Arrays
3
+ * @param input
4
+ * @returns concatenation of all Uint8Array received as input
5
+ */
6
+ export declare function concatenate(...input: Uint8Array[]): Uint8Array;
7
+ export declare function writeUIntLE(buf: Uint8Array, value: number, offset: number, byteLength: number, noAssert?: boolean): Uint8Array;
8
+ /**
9
+ * Transforms Uint8Array into BigInt
10
+ * @param array: Uint8Array
11
+ * @returns BigInt
12
+ */
13
+ export declare function buildBigIntFromUint8Array(array: Uint8Array, byteOffset?: number): bigint;
14
+ /**
15
+ * Fills with zeros to set length
16
+ * @param array little endian Uint8Array
17
+ * @param length amount to pad
18
+ * @returns little endian Uint8Array padded with zeros to set length
19
+ */
20
+ export declare function zeroPadLE(array: Uint8Array, length: number): Uint8Array;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Concatenate Uint8Arrays
3
+ * @param input
4
+ * @returns concatenation of all Uint8Array received as input
5
+ */
6
+ export function concatenate(...input) {
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
+ // Adapted from https://github.com/feross/buffer
20
+ function checkInt(buf, value, offset, ext, max, min) {
21
+ if (value > max || value < min)
22
+ throw new RangeError('"value" argument is out of bounds');
23
+ if (offset + ext > buf.length)
24
+ throw new RangeError("Index out of range");
25
+ }
26
+ export function writeUIntLE(buf, value, offset, byteLength, noAssert) {
27
+ value = +value;
28
+ offset = offset >>> 0;
29
+ byteLength = byteLength >>> 0;
30
+ if (!noAssert) {
31
+ const maxBytes = Math.pow(2, 8 * byteLength) - 1;
32
+ checkInt(buf, value, offset, byteLength, maxBytes, 0);
33
+ }
34
+ let mul = 1;
35
+ let i = 0;
36
+ buf[offset] = value & 0xff;
37
+ while (++i < byteLength && (mul *= 0x100)) {
38
+ buf[offset + i] = (value / mul) & 0xff;
39
+ }
40
+ return buf;
41
+ }
42
+ /**
43
+ * Transforms Uint8Array into BigInt
44
+ * @param array: Uint8Array
45
+ * @returns BigInt
46
+ */
47
+ export function buildBigIntFromUint8Array(array, byteOffset = 0) {
48
+ const dataView = new DataView(array.buffer);
49
+ return dataView.getBigUint64(byteOffset, true);
50
+ }
51
+ /**
52
+ * Fills with zeros to set length
53
+ * @param array little endian Uint8Array
54
+ * @param length amount to pad
55
+ * @returns little endian Uint8Array padded with zeros to set length
56
+ */
57
+ export function zeroPadLE(array, length) {
58
+ const result = new Uint8Array(length);
59
+ for (let i = 0; i < length; i++) {
60
+ result[i] = array[i] || 0;
61
+ }
62
+ return result;
63
+ }
64
+ //# sourceMappingURL=bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/utils/bytes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,GAAG,KAAmB;IAChD,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,WAAW,IAAI,GAAG,CAAC,MAAM,CAAC;IAC5B,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC3C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK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KAAK,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC;IACzC,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,KAAiB,EACjB,aAAqB,CAAC;IAEtB,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5C,OAAO,QAAQ,CAAC,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AACjD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,KAAiB,EAAE,MAAc;IACzD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function dateToEpoch(timestamp: Date, epochUnitSeconds?: number): number;
2
+ export declare function epochIntToBytes(epoch: number): Uint8Array;
3
+ export declare function epochBytesToInt(bytes: Uint8Array): number;
@@ -0,0 +1,23 @@
1
+ import { Logger } from "@waku/utils";
2
+ const DefaultEpochUnitSeconds = 10; // the rln-relay epoch length in seconds
3
+ const log = new Logger("waku:rln:epoch");
4
+ export function dateToEpoch(timestamp, epochUnitSeconds = DefaultEpochUnitSeconds) {
5
+ const time = timestamp.getTime();
6
+ const epoch = Math.floor(time / 1000 / epochUnitSeconds);
7
+ log.info("generated epoch", epoch);
8
+ return epoch;
9
+ }
10
+ export function epochIntToBytes(epoch) {
11
+ const bytes = new Uint8Array(32);
12
+ const db = new DataView(bytes.buffer);
13
+ db.setUint32(0, epoch, true);
14
+ log.info("encoded epoch", epoch, bytes);
15
+ return bytes;
16
+ }
17
+ export function epochBytesToInt(bytes) {
18
+ const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
19
+ const epoch = dv.getUint32(0, true);
20
+ log.info("decoded epoch", epoch, bytes);
21
+ return epoch;
22
+ }
23
+ //# sourceMappingURL=epoch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"epoch.js","sourceRoot":"","sources":["../../src/utils/epoch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,uBAAuB,GAAG,EAAE,CAAC,CAAC,wCAAwC;AAE5E,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAEzC,MAAM,UAAU,WAAW,CACzB,SAAe,EACf,mBAA2B,uBAAuB;IAElD,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC;IACjC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,GAAG,gBAAgB,CAAC,CAAC;IACzD,GAAG,CAAC,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;IACnC,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACjC,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC7B,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACxC,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAiB;IAC/C,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC1E,MAAM,KAAK,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACpC,GAAG,CAAC,IAAI,CAAC,eAAe,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IACxC,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function poseidonHash(...input: Array<Uint8Array>): Uint8Array;
2
+ export declare function sha256(input: Uint8Array): Uint8Array;
@@ -0,0 +1,13 @@
1
+ import * as zerokitRLN from "@waku/zerokit-rln-wasm";
2
+ import { concatenate, writeUIntLE } from "./bytes.js";
3
+ export function poseidonHash(...input) {
4
+ const inputLen = writeUIntLE(new Uint8Array(8), input.length, 0, 8);
5
+ const lenPrefixedData = concatenate(inputLen, ...input);
6
+ return zerokitRLN.poseidonHash(lenPrefixedData);
7
+ }
8
+ export function sha256(input) {
9
+ const inputLen = writeUIntLE(new Uint8Array(8), input.length, 0, 8);
10
+ const lenPrefixedData = concatenate(inputLen, input);
11
+ return zerokitRLN.hash(lenPrefixedData);
12
+ }
13
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/utils/hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,UAAU,YAAY,CAAC,GAAG,KAAwB;IACtD,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACpE,MAAM,eAAe,GAAG,WAAW,CAAC,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC;IACxD,OAAO,UAAU,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,KAAiB;IACtC,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACpE,MAAM,eAAe,GAAG,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACrD,OAAO,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { extractMetaMaskSigner } from "./metamask.js";
2
+ export { concatenate, writeUIntLE, buildBigIntFromUint8Array, zeroPadLE } from "./bytes.js";
3
+ export { sha256, poseidonHash } from "./hash.js";
4
+ export { dateToEpoch, epochIntToBytes, epochBytesToInt } from "./epoch.js";
@@ -0,0 +1,5 @@
1
+ export { extractMetaMaskSigner } from "./metamask.js";
2
+ export { concatenate, writeUIntLE, buildBigIntFromUint8Array, zeroPadLE } from "./bytes.js";
3
+ export { sha256, poseidonHash } from "./hash.js";
4
+ export { dateToEpoch, epochIntToBytes, epochBytesToInt } from "./epoch.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EACL,WAAW,EACX,WAAW,EACX,yBAAyB,EACzB,SAAS,EACV,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { ethers } from "ethers";
2
+ export declare const extractMetaMaskSigner: () => Promise<ethers.Signer>;
@@ -0,0 +1,12 @@
1
+ import { ethers } from "ethers";
2
+ export const extractMetaMaskSigner = async () => {
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
+ const ethereum = window.ethereum;
5
+ if (!ethereum) {
6
+ throw Error("Missing or invalid Ethereum provider. Please install a Web3 wallet such as MetaMask.");
7
+ }
8
+ await ethereum.request({ method: "eth_requestAccounts" });
9
+ const provider = new ethers.providers.Web3Provider(ethereum, "any");
10
+ return provider.getSigner();
11
+ };
12
+ //# sourceMappingURL=metamask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metamask.js","sourceRoot":"","sources":["../../src/utils/metamask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,IAA4B,EAAE;IACtE,8DAA8D;IAC9D,MAAM,QAAQ,GAAI,MAAc,CAAC,QAAQ,CAAC;IAE1C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,KAAK,CACT,sFAAsF,CACvF,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAEpE,OAAO,QAAQ,CAAC,SAAS,EAAE,CAAC;AAC9B,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { IRateLimitProof } from "@waku/interfaces";
2
+ import { IdentityCredential } from "./identity.js";
3
+ import { WitnessCalculator } from "./resources/witness_calculator";
4
+ export declare class Zerokit {
5
+ private readonly zkRLN;
6
+ private readonly witnessCalculator;
7
+ constructor(zkRLN: number, witnessCalculator: WitnessCalculator);
8
+ generateIdentityCredentials(): IdentityCredential;
9
+ generateSeededIdentityCredential(seed: string): IdentityCredential;
10
+ insertMember(idCommitment: Uint8Array): void;
11
+ insertMembers(index: number, ...idCommitments: Array<Uint8Array>): void;
12
+ deleteMember(index: number): void;
13
+ getMerkleRoot(): Uint8Array;
14
+ serializeMessage(uint8Msg: Uint8Array, memIndex: number, epoch: Uint8Array, idKey: Uint8Array): Uint8Array;
15
+ generateRLNProof(msg: Uint8Array, index: number, epoch: Uint8Array | Date | undefined, idSecretHash: Uint8Array): Promise<IRateLimitProof>;
16
+ verifyRLNProof(proof: IRateLimitProof | Uint8Array, msg: Uint8Array): boolean;
17
+ verifyWithRoots(proof: IRateLimitProof | Uint8Array, msg: Uint8Array, ...roots: Array<Uint8Array>): boolean;
18
+ verifyWithNoRoot(proof: IRateLimitProof | Uint8Array, msg: Uint8Array): boolean;
19
+ }