@waku/rln 0.1.3-f6d5deb → 0.1.4-0e49a1e.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. package/README.md +10 -186
  2. package/bundle/_virtual/__node-resolve_empty.js +6 -0
  3. package/bundle/_virtual/_assert.js +3 -0
  4. package/bundle/_virtual/_commonjs-dynamic-modules.js +5 -0
  5. package/bundle/_virtual/_commonjsHelpers.js +32 -0
  6. package/bundle/_virtual/_node-resolve_empty.js +3 -0
  7. package/bundle/_virtual/_sha2.js +3 -0
  8. package/bundle/_virtual/_u64.js +3 -0
  9. package/bundle/_virtual/aes.js +3 -0
  10. package/bundle/_virtual/bn.js +3 -0
  11. package/bundle/_virtual/browser.js +3 -0
  12. package/bundle/_virtual/checksum.js +3 -0
  13. package/bundle/_virtual/cipher.js +3 -0
  14. package/bundle/_virtual/class.js +3 -0
  15. package/bundle/_virtual/common.js +3 -0
  16. package/bundle/_virtual/common2.js +3 -0
  17. package/bundle/_virtual/cryptoBrowser.js +3 -0
  18. package/bundle/_virtual/functional.js +3 -0
  19. package/bundle/_virtual/hash.js +3 -0
  20. package/bundle/_virtual/hmac.js +3 -0
  21. package/bundle/_virtual/index.js +3 -0
  22. package/bundle/_virtual/index2.js +6 -0
  23. package/bundle/_virtual/inherits_browser.js +3 -0
  24. package/bundle/_virtual/kdf.js +3 -0
  25. package/bundle/_virtual/lodash.js +3 -0
  26. package/bundle/_virtual/password.js +3 -0
  27. package/bundle/_virtual/pbkdf2.js +3 -0
  28. package/bundle/_virtual/pbkdf22.js +3 -0
  29. package/bundle/_virtual/random.js +3 -0
  30. package/bundle/_virtual/ripemd.js +3 -0
  31. package/bundle/_virtual/schema-validation-generated.js +3 -0
  32. package/bundle/_virtual/schema-validation.js +3 -0
  33. package/bundle/_virtual/scrypt.js +3 -0
  34. package/bundle/_virtual/scrypt2.js +3 -0
  35. package/bundle/_virtual/sha.js +3 -0
  36. package/bundle/_virtual/sha256.js +3 -0
  37. package/bundle/_virtual/sha2562.js +3 -0
  38. package/bundle/_virtual/sha3.js +3 -0
  39. package/bundle/_virtual/sha512.js +3 -0
  40. package/bundle/_virtual/types.js +3 -0
  41. package/bundle/_virtual/utils.js +3 -0
  42. package/bundle/_virtual/utils2.js +3 -0
  43. package/bundle/_virtual/utils3.js +3 -0
  44. package/bundle/index.js +12 -74804
  45. package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +3 -0
  46. package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +96 -0
  47. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +148 -0
  48. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +26 -0
  49. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +20 -0
  50. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +210 -0
  51. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +18 -0
  52. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +30 -0
  53. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +26 -0
  54. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +22 -0
  55. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +43 -0
  56. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +19 -0
  57. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +58 -0
  58. package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +854 -0
  59. package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +609 -0
  60. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +3 -0
  61. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +66 -0
  62. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +3 -0
  63. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +302 -0
  64. package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +3 -0
  65. package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +110 -0
  66. package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +20 -0
  67. package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +120 -0
  68. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +3 -0
  69. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +287 -0
  70. package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +3 -0
  71. package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +402 -0
  72. package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +3 -0
  73. package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +8 -0
  74. package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +3 -0
  75. package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +3 -0
  76. package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +893 -0
  77. package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +3 -0
  78. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +256 -0
  79. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +36 -0
  80. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +135 -0
  81. package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +8 -0
  82. package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +64 -0
  83. package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +443 -0
  84. package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +8 -0
  85. package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +660 -0
  86. package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +3 -0
  87. package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +352 -0
  88. package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +3 -0
  89. package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +248 -0
  90. package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +3 -0
  91. package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +127 -0
  92. package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +3 -0
  93. package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +2007 -0
  94. package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +422 -0
  95. package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +674 -0
  96. package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +132 -0
  97. package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +3 -0
  98. package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +120 -0
  99. package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +8 -0
  100. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +3 -0
  101. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +2430 -0
  102. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +76 -0
  103. package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +3 -0
  104. package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +219 -0
  105. package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +3 -0
  106. package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +279 -0
  107. package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +3 -0
  108. package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +69 -0
  109. package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +404 -0
  110. package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +15 -0
  111. package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +20 -0
  112. package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +92 -0
  113. package/bundle/node_modules/@noble/hashes/esm/_assert.js +37 -0
  114. package/bundle/node_modules/@noble/hashes/esm/_md.js +132 -0
  115. package/bundle/node_modules/@noble/hashes/esm/_u64.js +29 -0
  116. package/bundle/node_modules/@noble/hashes/esm/sha256.js +113 -0
  117. package/bundle/node_modules/@noble/hashes/esm/sha3.js +210 -0
  118. package/bundle/node_modules/@noble/hashes/esm/utils.js +144 -0
  119. package/bundle/node_modules/@waku/zerokit-rln-wasm/rln_wasm.js +756 -0
  120. package/bundle/node_modules/bech32/index.js +187 -0
  121. package/bundle/node_modules/bn.js/lib/bn.js +3361 -0
  122. package/bundle/node_modules/debug/src/browser.js +283 -0
  123. package/bundle/node_modules/debug/src/common.js +295 -0
  124. package/bundle/node_modules/ethereum-cryptography/esm/keccak.js +10 -0
  125. package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +6 -0
  126. package/bundle/node_modules/ethereum-cryptography/esm/utils.js +24 -0
  127. package/bundle/node_modules/hash.js/lib/hash/common.js +97 -0
  128. package/bundle/node_modules/hash.js/lib/hash/hmac.js +51 -0
  129. package/bundle/node_modules/hash.js/lib/hash/ripemd.js +152 -0
  130. package/bundle/node_modules/hash.js/lib/hash/sha/1.js +81 -0
  131. package/bundle/node_modules/hash.js/lib/hash/sha/224.js +33 -0
  132. package/bundle/node_modules/hash.js/lib/hash/sha/256.js +113 -0
  133. package/bundle/node_modules/hash.js/lib/hash/sha/384.js +39 -0
  134. package/bundle/node_modules/hash.js/lib/hash/sha/512.js +336 -0
  135. package/bundle/node_modules/hash.js/lib/hash/sha/common.js +53 -0
  136. package/bundle/node_modules/hash.js/lib/hash/sha.js +14 -0
  137. package/bundle/node_modules/hash.js/lib/hash/utils.js +282 -0
  138. package/bundle/node_modules/hash.js/lib/hash.js +33 -0
  139. package/bundle/node_modules/inherits/inherits_browser.js +33 -0
  140. package/bundle/node_modules/it-length-prefixed/dist/src/decode.js +6 -0
  141. package/bundle/node_modules/lodash/lodash.js +17207 -0
  142. package/bundle/node_modules/minimalistic-assert/index.js +13 -0
  143. package/bundle/node_modules/ms/index.js +172 -0
  144. package/bundle/node_modules/multiformats/dist/src/bases/base.js +205 -0
  145. package/bundle/node_modules/multiformats/dist/src/bases/base10.js +9 -0
  146. package/bundle/node_modules/multiformats/dist/src/bases/base16.js +16 -0
  147. package/bundle/node_modules/multiformats/dist/src/bases/base2.js +10 -0
  148. package/bundle/node_modules/multiformats/dist/src/bases/base256emoji.js +41 -0
  149. package/bundle/node_modules/multiformats/dist/src/bases/base32.js +58 -0
  150. package/bundle/node_modules/multiformats/dist/src/bases/base36.js +14 -0
  151. package/bundle/node_modules/multiformats/dist/src/bases/base58.js +14 -0
  152. package/bundle/node_modules/multiformats/dist/src/bases/base64.js +28 -0
  153. package/bundle/node_modules/multiformats/dist/src/bases/base8.js +10 -0
  154. package/bundle/node_modules/multiformats/dist/src/bases/identity.js +11 -0
  155. package/bundle/node_modules/multiformats/dist/src/basics.js +15 -0
  156. package/bundle/node_modules/multiformats/dist/src/bytes.js +18 -0
  157. package/bundle/node_modules/multiformats/dist/src/codecs/json.js +2 -0
  158. package/bundle/node_modules/multiformats/dist/src/vendor/base-x.js +170 -0
  159. package/bundle/node_modules/protons-runtime/dist/src/codec.js +20 -0
  160. package/bundle/node_modules/protons-runtime/dist/src/codecs/enum.js +24 -0
  161. package/bundle/node_modules/protons-runtime/dist/src/codecs/message.js +7 -0
  162. package/bundle/node_modules/protons-runtime/dist/src/decode.js +8 -0
  163. package/bundle/node_modules/protons-runtime/dist/src/encode.js +11 -0
  164. package/bundle/node_modules/protons-runtime/dist/src/index.js +30 -0
  165. package/bundle/node_modules/protons-runtime/dist/src/utils/float.js +54 -0
  166. package/bundle/node_modules/protons-runtime/dist/src/utils/longbits.js +175 -0
  167. package/bundle/node_modules/protons-runtime/dist/src/utils/pool.js +28 -0
  168. package/bundle/node_modules/protons-runtime/dist/src/utils/reader.js +367 -0
  169. package/bundle/node_modules/protons-runtime/dist/src/utils/utf8.js +99 -0
  170. package/bundle/node_modules/protons-runtime/dist/src/utils/writer.js +438 -0
  171. package/bundle/node_modules/uint8-varint/dist/src/index.js +124 -0
  172. package/bundle/node_modules/uint8arrays/dist/src/alloc.js +17 -0
  173. package/bundle/node_modules/uint8arrays/dist/src/from-string.js +19 -0
  174. package/bundle/node_modules/uint8arrays/dist/src/util/bases.js +49 -0
  175. package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +21 -0
  176. package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +18 -0
  177. package/bundle/packages/core/dist/lib/filter/filter.js +27 -0
  178. package/bundle/packages/core/dist/lib/light_push/light_push.js +27 -0
  179. package/bundle/packages/core/dist/lib/message/version_0.js +154 -0
  180. package/bundle/packages/core/dist/lib/metadata/metadata.js +27 -0
  181. package/bundle/packages/core/dist/lib/store/store.js +27 -0
  182. package/bundle/packages/interfaces/dist/connection_manager.js +19 -0
  183. package/bundle/packages/interfaces/dist/constants.js +6 -0
  184. package/bundle/packages/interfaces/dist/health_indicator.js +12 -0
  185. package/bundle/packages/interfaces/dist/protocols.js +92 -0
  186. package/bundle/packages/proto/dist/generated/filter.js +445 -0
  187. package/bundle/packages/proto/dist/generated/filter_v2.js +424 -0
  188. package/bundle/packages/proto/dist/generated/light_push.js +389 -0
  189. package/bundle/packages/proto/dist/generated/message.js +213 -0
  190. package/bundle/packages/proto/dist/generated/metadata.js +130 -0
  191. package/bundle/packages/proto/dist/generated/peer_exchange.js +209 -0
  192. package/bundle/packages/proto/dist/generated/sds_message.js +105 -0
  193. package/bundle/packages/proto/dist/generated/store_v3.js +490 -0
  194. package/bundle/packages/proto/dist/generated/topic_only_message.js +61 -0
  195. package/bundle/packages/rln/dist/codec.js +93 -0
  196. package/bundle/packages/rln/dist/contract/abi.js +394 -0
  197. package/bundle/packages/rln/dist/contract/constants.js +27 -0
  198. package/bundle/packages/rln/dist/contract/rln_contract.js +438 -0
  199. package/bundle/packages/rln/dist/create.js +9 -0
  200. package/bundle/packages/rln/dist/identity.js +30 -0
  201. package/bundle/packages/rln/dist/keystore/cipher.js +31 -0
  202. package/bundle/packages/rln/dist/keystore/credential_validation_generated.js +119 -0
  203. package/bundle/packages/rln/dist/keystore/keystore.js +223 -0
  204. package/bundle/packages/rln/dist/keystore/keystore_validation_generated.js +74 -0
  205. package/bundle/packages/rln/dist/keystore/schema_validator.js +20 -0
  206. package/bundle/packages/rln/dist/message.js +51 -0
  207. package/bundle/packages/rln/dist/proof.js +54 -0
  208. package/bundle/packages/rln/dist/resources/verification_key.js +112 -0
  209. package/bundle/packages/rln/dist/resources/witness_calculator.js +330 -0
  210. package/bundle/packages/rln/dist/rln.js +220 -0
  211. package/bundle/packages/rln/dist/root_tracker.js +76 -0
  212. package/bundle/packages/rln/dist/utils/bytes.js +65 -0
  213. package/bundle/packages/rln/dist/utils/epoch.js +39 -0
  214. package/bundle/packages/rln/dist/utils/hash.js +10 -0
  215. package/bundle/packages/rln/dist/utils/metamask.js +14 -0
  216. package/bundle/packages/rln/dist/zerokit.js +128 -0
  217. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +52 -0
  218. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +65 -0
  219. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +99 -0
  220. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +103 -0
  221. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/index.js +28 -0
  222. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +78 -0
  223. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +17 -0
  224. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1253 -0
  225. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +40 -0
  226. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/types.js +5 -0
  227. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +103 -0
  228. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +41 -0
  229. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +17 -0
  230. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +23 -0
  231. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +12 -0
  232. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +77 -0
  233. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +9 -0
  234. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +215 -0
  235. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +3 -0
  236. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +35 -0
  237. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +3 -0
  238. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +21 -0
  239. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
  240. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
  241. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +96 -0
  242. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +6 -0
  243. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +66 -0
  244. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +24 -0
  245. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +6 -0
  246. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +7 -0
  247. package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +11 -0
  248. package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +52 -0
  249. package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +124 -0
  250. package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +71 -0
  251. package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +10 -0
  252. package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +88 -0
  253. package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +99 -0
  254. package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +233 -0
  255. package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +133 -0
  256. package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +243 -0
  257. package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +167 -0
  258. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/native.js +4 -0
  259. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/rng.js +13 -0
  260. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/stringify.js +28 -0
  261. package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/v4.js +19 -0
  262. package/bundle/packages/utils/dist/bytes/index.js +44 -0
  263. package/bundle/packages/utils/dist/common/sharding/index.js +91 -0
  264. package/bundle/packages/utils/dist/logger/index.js +31 -0
  265. package/bundle/resources/verification_key.d.ts +13 -0
  266. package/bundle/resources/verification_key.js +112 -0
  267. package/bundle/resources/witness_calculator.d.ts +11 -0
  268. package/bundle/resources/witness_calculator.js +328 -0
  269. package/dist/.tsbuildinfo +1 -0
  270. package/dist/codec.d.ts +5 -5
  271. package/dist/codec.js +6 -6
  272. package/dist/codec.js.map +1 -1
  273. package/dist/contract/abi.d.ts +42 -0
  274. package/dist/contract/abi.js +393 -0
  275. package/dist/contract/abi.js.map +1 -0
  276. package/dist/contract/constants.d.ts +59 -3
  277. package/dist/contract/constants.js +21 -63
  278. package/dist/contract/constants.js.map +1 -1
  279. package/dist/contract/rln_contract.d.ts +98 -17
  280. package/dist/contract/rln_contract.js +292 -71
  281. package/dist/contract/rln_contract.js.map +1 -1
  282. package/dist/identity.js +5 -2
  283. package/dist/identity.js.map +1 -1
  284. package/dist/index.d.ts +3 -3
  285. package/dist/index.js +3 -3
  286. package/dist/index.js.map +1 -1
  287. package/dist/keystore/cipher.js +3 -3
  288. package/dist/keystore/cipher.js.map +1 -1
  289. package/dist/keystore/credential_validation_generated.js.map +1 -1
  290. package/dist/keystore/keystore.js +4 -4
  291. package/dist/keystore/keystore.js.map +1 -1
  292. package/dist/keystore/keystore_validation_generated.js.map +1 -1
  293. package/dist/message.js +3 -3
  294. package/dist/message.js.map +1 -1
  295. package/dist/proof.js +3 -2
  296. package/dist/proof.js.map +1 -1
  297. package/dist/resources/verification_key.d.ts +12 -11
  298. package/dist/resources/verification_key.js +103 -103
  299. package/dist/resources/witness_calculator.d.ts +10 -15
  300. package/dist/resources/witness_calculator.js +302 -265
  301. package/dist/rln.d.ts +5 -1
  302. package/dist/rln.js +56 -28
  303. package/dist/rln.js.map +1 -1
  304. package/dist/root_tracker.js.map +1 -1
  305. package/dist/utils/epoch.js +5 -5
  306. package/dist/utils/epoch.js.map +1 -1
  307. package/dist/zerokit.d.ts +13 -9
  308. package/dist/zerokit.js +40 -20
  309. package/dist/zerokit.js.map +1 -1
  310. package/package.json +1 -146
  311. package/src/codec.ts +26 -22
  312. package/src/contract/abi.ts +392 -0
  313. package/src/contract/constants.ts +28 -0
  314. package/src/contract/index.ts +2 -0
  315. package/src/contract/rln_contract.ts +686 -0
  316. package/src/identity.ts +8 -4
  317. package/src/index.ts +4 -9
  318. package/src/keystore/cipher.ts +54 -0
  319. package/src/keystore/credential_validation_generated.ts +7 -0
  320. package/src/keystore/index.ts +5 -0
  321. package/src/keystore/keystore.ts +330 -0
  322. package/src/keystore/keystore_validation_generated.ts +7 -0
  323. package/src/keystore/schema_validator.ts +34 -0
  324. package/src/keystore/types.ts +36 -0
  325. package/src/message.ts +10 -10
  326. package/src/proof.ts +13 -11
  327. package/src/resources/verification_key.d.ts +13 -0
  328. package/src/resources/witness_calculator.d.ts +11 -0
  329. package/src/rln.ts +76 -31
  330. package/src/root_tracker.ts +7 -6
  331. package/src/utils/bytes.ts +84 -0
  332. package/src/utils/epoch.ts +30 -0
  333. package/src/utils/hash.ts +15 -0
  334. package/src/utils/index.ts +9 -0
  335. package/src/utils/metamask.ts +17 -0
  336. package/src/zerokit.ts +95 -33
  337. package/bundle/assets/rln_wasm_bg-a503e304.wasm +0 -0
  338. package/dist/resources/verification_key.js.map +0 -1
  339. package/dist/resources/witness_calculator.js.map +0 -1
  340. /package/bundle/{assets/rln-6ded2896.wasm → resources/rln.wasm} +0 -0
  341. /package/bundle/{assets/rln_final-8b299152.zkey → resources/rln_final.zkey} +0 -0
package/src/index.ts CHANGED
@@ -1,10 +1,6 @@
1
1
  import { RLNDecoder, RLNEncoder } from "./codec.js";
2
- import {
3
- RLN_REGISTRY_ABI,
4
- RLN_STORAGE_ABI,
5
- SEPOLIA_CONTRACT
6
- } from "./contract/index.js";
7
- import { RLNContract } from "./contract/index.js";
2
+ import { RLN_ABI } from "./contract/abi.js";
3
+ import { RLNContract, SEPOLIA_CONTRACT } from "./contract/index.js";
8
4
  import { createRLN } from "./create.js";
9
5
  import { IdentityCredential } from "./identity.js";
10
6
  import { Keystore } from "./keystore/index.js";
@@ -23,8 +19,7 @@ export {
23
19
  RLNDecoder,
24
20
  MerkleRootTracker,
25
21
  RLNContract,
26
- RLN_STORAGE_ABI,
27
- RLN_REGISTRY_ABI,
28
22
  SEPOLIA_CONTRACT,
29
- extractMetaMaskSigner
23
+ extractMetaMaskSigner,
24
+ RLN_ABI
30
25
  };
@@ -0,0 +1,54 @@
1
+ import type { IKeystore as IEipKeystore } from "@chainsafe/bls-keystore";
2
+ import { cipherDecrypt } from "@chainsafe/bls-keystore/lib/cipher";
3
+ import { kdf } from "@chainsafe/bls-keystore/lib/kdf";
4
+ import { normalizePassword } from "@chainsafe/bls-keystore/lib/password";
5
+ import { keccak256 } from "ethereum-cryptography/keccak";
6
+ import {
7
+ bytesToHex,
8
+ concatBytes,
9
+ hexToBytes
10
+ } from "ethereum-cryptography/utils";
11
+
12
+ import type { Keccak256Hash, Password } from "./types.js";
13
+
14
+ // eipKeystore supports only sha256 checksum so we just make an assumption it is keccak256
15
+ const validateChecksum = async (
16
+ password: Password,
17
+ eipKeystore: IEipKeystore
18
+ ): Promise<boolean> => {
19
+ const computedChecksum = await keccak256Checksum(password, eipKeystore);
20
+ return computedChecksum === eipKeystore.crypto.checksum.message;
21
+ };
22
+
23
+ // decrypt from @chainsafe/bls-keystore supports only sha256
24
+ // but nwaku uses keccak256
25
+ // https://github.com/waku-org/nwaku/blob/25d6e52e3804d15f9b61bc4cc6dd448540c072a1/waku/waku_keystore/keyfile.nim#L367
26
+ export const decryptEipKeystore = async (
27
+ password: Password,
28
+ eipKeystore: IEipKeystore
29
+ ): Promise<Uint8Array> => {
30
+ const decryptionKey = await kdf(
31
+ eipKeystore.crypto.kdf,
32
+ normalizePassword(password)
33
+ );
34
+ const isChecksumValid = await validateChecksum(password, eipKeystore);
35
+
36
+ if (!isChecksumValid) {
37
+ throw Error("Password is invalid.");
38
+ }
39
+
40
+ return cipherDecrypt(eipKeystore.crypto.cipher, decryptionKey.slice(0, 16));
41
+ };
42
+
43
+ export const keccak256Checksum = async (
44
+ password: Password,
45
+ eipKeystore: IEipKeystore
46
+ ): Promise<Keccak256Hash> => {
47
+ const key = await kdf(eipKeystore.crypto.kdf, normalizePassword(password));
48
+ const payload = concatBytes(
49
+ key.slice(16),
50
+ hexToBytes(eipKeystore.crypto.cipher.message)
51
+ );
52
+ const ciphertext = keccak256(payload);
53
+ return bytesToHex(ciphertext);
54
+ };
@@ -0,0 +1,7 @@
1
+ /* eslint eslint-comments/no-unlimited-disable: "off" */
2
+ // This file was generated by /scripts/schema-validation-codegen.ts
3
+ // Do not modify this file by hand.
4
+
5
+ /* eslint-disable */
6
+ // @ts-ignore
7
+ "use strict";export const Credential = validate11;const schema12 = {"type":"object","properties":{"crypto":{"type":"object","properties":{"cipher":{"type":"string"},"cipherparams":{"type":"object"},"ciphertext":{"type":"string"},"kdf":{"type":"string"},"kdfparams":{"type":"object"},"mac":{"type":"string"}},"required":["cipher","cipherparams","ciphertext","kdf","kdfparams","mac"]}},"required":["crypto"]};function validate11(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(errors === 0){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.crypto === undefined) && (missing0 = "crypto")){validate11.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.crypto !== undefined){let data0 = data.crypto;const _errs1 = errors;if(errors === _errs1){if(data0 && typeof data0 == "object" && !Array.isArray(data0)){let missing1;if(((((((data0.cipher === undefined) && (missing1 = "cipher")) || ((data0.cipherparams === undefined) && (missing1 = "cipherparams"))) || ((data0.ciphertext === undefined) && (missing1 = "ciphertext"))) || ((data0.kdf === undefined) && (missing1 = "kdf"))) || ((data0.kdfparams === undefined) && (missing1 = "kdfparams"))) || ((data0.mac === undefined) && (missing1 = "mac"))){validate11.errors = [{instancePath:instancePath+"/crypto",schemaPath:"#/properties/crypto/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;}else {if(data0.cipher !== undefined){const _errs3 = errors;if(typeof data0.cipher !== "string"){validate11.errors = [{instancePath:instancePath+"/crypto/cipher",schemaPath:"#/properties/crypto/properties/cipher/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs3 === errors;}else {var valid1 = true;}if(valid1){if(data0.cipherparams !== undefined){let data2 = data0.cipherparams;const _errs5 = errors;if(!(data2 && typeof data2 == "object" && !Array.isArray(data2))){validate11.errors = [{instancePath:instancePath+"/crypto/cipherparams",schemaPath:"#/properties/crypto/properties/cipherparams/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}var valid1 = _errs5 === errors;}else {var valid1 = true;}if(valid1){if(data0.ciphertext !== undefined){const _errs7 = errors;if(typeof data0.ciphertext !== "string"){validate11.errors = [{instancePath:instancePath+"/crypto/ciphertext",schemaPath:"#/properties/crypto/properties/ciphertext/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs7 === errors;}else {var valid1 = true;}if(valid1){if(data0.kdf !== undefined){const _errs9 = errors;if(typeof data0.kdf !== "string"){validate11.errors = [{instancePath:instancePath+"/crypto/kdf",schemaPath:"#/properties/crypto/properties/kdf/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs9 === errors;}else {var valid1 = true;}if(valid1){if(data0.kdfparams !== undefined){let data5 = data0.kdfparams;const _errs11 = errors;if(!(data5 && typeof data5 == "object" && !Array.isArray(data5))){validate11.errors = [{instancePath:instancePath+"/crypto/kdfparams",schemaPath:"#/properties/crypto/properties/kdfparams/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}var valid1 = _errs11 === errors;}else {var valid1 = true;}if(valid1){if(data0.mac !== undefined){const _errs13 = errors;if(typeof data0.mac !== "string"){validate11.errors = [{instancePath:instancePath+"/crypto/mac",schemaPath:"#/properties/crypto/properties/mac/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs13 === errors;}else {var valid1 = true;}}}}}}}}else {validate11.errors = [{instancePath:instancePath+"/crypto",schemaPath:"#/properties/crypto/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}}}}else {validate11.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate11.errors = vErrors;return errors === 0;}
@@ -0,0 +1,5 @@
1
+ import { Keystore } from "./keystore.js";
2
+ import type { DecryptedCredentials, EncryptedCredentials } from "./types.js";
3
+
4
+ export { Keystore };
5
+ export type { EncryptedCredentials, DecryptedCredentials };
@@ -0,0 +1,330 @@
1
+ import type {
2
+ ICipherModule,
3
+ IKeystore as IEipKeystore,
4
+ IPbkdf2KdfModule
5
+ } from "@chainsafe/bls-keystore";
6
+ import { create as createEipKeystore } from "@chainsafe/bls-keystore";
7
+ import { Logger } from "@waku/utils";
8
+ import { sha256 } from "ethereum-cryptography/sha256";
9
+ import {
10
+ bytesToHex,
11
+ bytesToUtf8,
12
+ utf8ToBytes
13
+ } from "ethereum-cryptography/utils";
14
+ import _ from "lodash";
15
+ import { v4 as uuidV4 } from "uuid";
16
+
17
+ import { buildBigIntFromUint8Array } from "../utils/bytes.js";
18
+
19
+ import { decryptEipKeystore, keccak256Checksum } from "./cipher.js";
20
+ import { isCredentialValid, isKeystoreValid } from "./schema_validator.js";
21
+ import type {
22
+ Keccak256Hash,
23
+ KeystoreEntity,
24
+ MembershipHash,
25
+ MembershipInfo,
26
+ Password,
27
+ Sha256Hash
28
+ } from "./types.js";
29
+
30
+ const log = new Logger("waku:rln:keystore");
31
+
32
+ type NwakuCredential = {
33
+ crypto: {
34
+ cipher: ICipherModule["function"];
35
+ cipherparams: ICipherModule["params"];
36
+ ciphertext: ICipherModule["message"];
37
+ kdf: IPbkdf2KdfModule["function"];
38
+ kdfparams: IPbkdf2KdfModule["params"];
39
+ mac: Sha256Hash;
40
+ };
41
+ };
42
+
43
+ // examples from nwaku
44
+ // https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/tests/test_waku_keystore.nim#L43
45
+ // https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/keystore.nim#L154C35-L154C38
46
+ // important: each credential has it's own password
47
+ // important: not compatible with https://eips.ethereum.org/EIPS/eip-2335
48
+ interface NwakuKeystore {
49
+ application: string;
50
+ version: string;
51
+ appIdentifier: string;
52
+ credentials: {
53
+ [key: MembershipHash]: NwakuCredential;
54
+ };
55
+ }
56
+
57
+ type KeystoreCreateOptions = {
58
+ application?: string;
59
+ version?: string;
60
+ appIdentifier?: string;
61
+ };
62
+
63
+ export class Keystore {
64
+ private data: NwakuKeystore;
65
+
66
+ private constructor(options: KeystoreCreateOptions | NwakuKeystore) {
67
+ this.data = Object.assign(
68
+ {
69
+ application: "waku-rln-relay",
70
+ appIdentifier: "01234567890abcdef",
71
+ version: "0.2",
72
+ credentials: {}
73
+ },
74
+ options
75
+ );
76
+ }
77
+
78
+ public static create(options: KeystoreCreateOptions = {}): Keystore {
79
+ return new Keystore(options);
80
+ }
81
+
82
+ // should be valid JSON string that contains Keystore file
83
+ // https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/keyfile.nim#L376
84
+ public static fromString(str: string): undefined | Keystore {
85
+ try {
86
+ const obj = JSON.parse(str);
87
+
88
+ if (!Keystore.isValidNwakuStore(obj)) {
89
+ throw Error("Invalid string, does not match Nwaku Keystore format.");
90
+ }
91
+
92
+ return new Keystore(obj);
93
+ } catch (err) {
94
+ log.error("Cannot create Keystore from string:", err);
95
+ return;
96
+ }
97
+ }
98
+
99
+ public static fromObject(obj: NwakuKeystore): Keystore {
100
+ if (!Keystore.isValidNwakuStore(obj)) {
101
+ throw Error("Invalid object, does not match Nwaku Keystore format.");
102
+ }
103
+
104
+ return new Keystore(obj);
105
+ }
106
+
107
+ public async addCredential(
108
+ options: KeystoreEntity,
109
+ password: Password
110
+ ): Promise<MembershipHash> {
111
+ const membershipHash: MembershipHash = Keystore.computeMembershipHash(
112
+ options.membership
113
+ );
114
+
115
+ if (this.data.credentials[membershipHash]) {
116
+ throw Error("Credential already exists in the store.");
117
+ }
118
+
119
+ // these are not important
120
+ const stubPath = "/stub/path";
121
+ const stubPubkey = new Uint8Array([0]);
122
+ const secret = Keystore.fromIdentityToBytes(options);
123
+
124
+ const eipKeystore = await createEipKeystore(
125
+ password,
126
+ secret,
127
+ stubPubkey,
128
+ stubPath
129
+ );
130
+ // need to re-compute checksum since nwaku uses keccak256 instead of sha256
131
+ const checksum = await keccak256Checksum(password, eipKeystore);
132
+ const nwakuCredential = Keystore.fromEipToCredential(eipKeystore, checksum);
133
+
134
+ this.data.credentials[membershipHash] = nwakuCredential;
135
+ return membershipHash;
136
+ }
137
+
138
+ public async readCredential(
139
+ membershipHash: MembershipHash,
140
+ password: Password
141
+ ): Promise<undefined | KeystoreEntity> {
142
+ const nwakuCredential = this.data.credentials[membershipHash];
143
+
144
+ if (!nwakuCredential) {
145
+ return;
146
+ }
147
+
148
+ const eipKeystore = Keystore.fromCredentialToEip(nwakuCredential);
149
+ const bytes = await decryptEipKeystore(password, eipKeystore);
150
+
151
+ return Keystore.fromBytesToIdentity(bytes);
152
+ }
153
+
154
+ public removeCredential(hash: MembershipHash): void {
155
+ if (!this.data.credentials[hash]) {
156
+ return;
157
+ }
158
+
159
+ delete this.data.credentials[hash];
160
+ }
161
+
162
+ public toString(): string {
163
+ return JSON.stringify(this.data);
164
+ }
165
+
166
+ public toObject(): NwakuKeystore {
167
+ return this.data;
168
+ }
169
+
170
+ /**
171
+ * Read array of hashes of current credentials
172
+ * @returns array of keys of credentials in current Keystore
173
+ */
174
+ public keys(): string[] {
175
+ return Object.keys(this.toObject().credentials || {});
176
+ }
177
+
178
+ private static isValidNwakuStore(obj: unknown): boolean {
179
+ if (!isKeystoreValid(obj)) {
180
+ return false;
181
+ }
182
+
183
+ const areCredentialsValid = Object.values(_.get(obj, "credentials", {}))
184
+ .map((c) => isCredentialValid(c))
185
+ .every((v) => v);
186
+
187
+ return areCredentialsValid;
188
+ }
189
+
190
+ private static fromCredentialToEip(
191
+ credential: NwakuCredential
192
+ ): IEipKeystore {
193
+ const nwakuCrypto = credential.crypto;
194
+ const eipCrypto: IEipKeystore["crypto"] = {
195
+ kdf: {
196
+ function: nwakuCrypto.kdf,
197
+ params: nwakuCrypto.kdfparams,
198
+ message: ""
199
+ },
200
+ cipher: {
201
+ function: nwakuCrypto.cipher,
202
+ params: nwakuCrypto.cipherparams,
203
+ message: nwakuCrypto.ciphertext
204
+ },
205
+ checksum: {
206
+ // @chainsafe/bls-keystore supports only sha256
207
+ // but nwaku uses keccak256
208
+ // https://github.com/waku-org/nwaku/blob/25d6e52e3804d15f9b61bc4cc6dd448540c072a1/waku/waku_keystore/keyfile.nim#L367
209
+ function: "sha256",
210
+ params: {},
211
+ message: nwakuCrypto.mac
212
+ }
213
+ };
214
+
215
+ return {
216
+ version: 4,
217
+ uuid: uuidV4(),
218
+ description: undefined,
219
+ path: "safe to ignore, not important for decrypt",
220
+ pubkey: "safe to ignore, not important for decrypt",
221
+ crypto: eipCrypto
222
+ };
223
+ }
224
+
225
+ private static fromEipToCredential(
226
+ eipKeystore: IEipKeystore,
227
+ checksum: Keccak256Hash
228
+ ): NwakuCredential {
229
+ const eipCrypto = eipKeystore.crypto;
230
+ const eipKdf = eipCrypto.kdf as IPbkdf2KdfModule;
231
+ return {
232
+ crypto: {
233
+ cipher: eipCrypto.cipher.function,
234
+ cipherparams: eipCrypto.cipher.params,
235
+ ciphertext: eipCrypto.cipher.message,
236
+ kdf: eipKdf.function,
237
+ kdfparams: eipKdf.params,
238
+ // @chainsafe/bls-keystore generates only sha256
239
+ // but nwaku uses keccak256
240
+ // https://github.com/waku-org/nwaku/blob/25d6e52e3804d15f9b61bc4cc6dd448540c072a1/waku/waku_keystore/keyfile.nim#L367
241
+ mac: checksum
242
+ }
243
+ };
244
+ }
245
+
246
+ private static fromBytesToIdentity(
247
+ bytes: Uint8Array
248
+ ): undefined | KeystoreEntity {
249
+ try {
250
+ const str = bytesToUtf8(bytes);
251
+ const obj = JSON.parse(str);
252
+
253
+ // TODO: add runtime validation of nwaku credentials
254
+ return {
255
+ identity: {
256
+ IDCommitment: Keystore.fromArraylikeToBytes(
257
+ _.get(obj, "identityCredential.idCommitment", [])
258
+ ),
259
+ IDTrapdoor: Keystore.fromArraylikeToBytes(
260
+ _.get(obj, "identityCredential.idTrapdoor", [])
261
+ ),
262
+ IDNullifier: Keystore.fromArraylikeToBytes(
263
+ _.get(obj, "identityCredential.idNullifier", [])
264
+ ),
265
+ IDCommitmentBigInt: buildBigIntFromUint8Array(
266
+ Keystore.fromArraylikeToBytes(
267
+ _.get(obj, "identityCredential.idCommitment", [])
268
+ )
269
+ ),
270
+ IDSecretHash: Keystore.fromArraylikeToBytes(
271
+ _.get(obj, "identityCredential.idSecretHash", [])
272
+ )
273
+ },
274
+ membership: {
275
+ treeIndex: _.get(obj, "treeIndex"),
276
+ chainId: _.get(obj, "membershipContract.chainId"),
277
+ address: _.get(obj, "membershipContract.address")
278
+ }
279
+ };
280
+ } catch (err) {
281
+ log.error("Cannot parse bytes to Nwaku Credentials:", err);
282
+ return;
283
+ }
284
+ }
285
+
286
+ private static fromArraylikeToBytes(obj: {
287
+ [key: number]: number;
288
+ }): Uint8Array {
289
+ const bytes = [];
290
+
291
+ let index = 0;
292
+ let lastElement = obj[index];
293
+
294
+ while (lastElement !== undefined) {
295
+ bytes.push(lastElement);
296
+ index += 1;
297
+ lastElement = obj[index];
298
+ }
299
+
300
+ return new Uint8Array(bytes);
301
+ }
302
+
303
+ // follows nwaku implementation
304
+ // https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L111
305
+ private static computeMembershipHash(info: MembershipInfo): MembershipHash {
306
+ return bytesToHex(
307
+ sha256(utf8ToBytes(`${info.chainId}${info.address}${info.treeIndex}`))
308
+ ).toUpperCase();
309
+ }
310
+
311
+ // follows nwaku implementation
312
+ // https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L98
313
+ private static fromIdentityToBytes(options: KeystoreEntity): Uint8Array {
314
+ return utf8ToBytes(
315
+ JSON.stringify({
316
+ treeIndex: options.membership.treeIndex,
317
+ identityCredential: {
318
+ idCommitment: options.identity.IDCommitment,
319
+ idNullifier: options.identity.IDNullifier,
320
+ idSecretHash: options.identity.IDSecretHash,
321
+ idTrapdoor: options.identity.IDTrapdoor
322
+ },
323
+ membershipContract: {
324
+ chainId: options.membership.chainId,
325
+ address: options.membership.address
326
+ }
327
+ })
328
+ );
329
+ }
330
+ }
@@ -0,0 +1,7 @@
1
+ /* eslint eslint-comments/no-unlimited-disable: "off" */
2
+ // This file was generated by /scripts/schema-validation-codegen.ts
3
+ // Do not modify this file by hand.
4
+
5
+ /* eslint-disable */
6
+ // @ts-ignore
7
+ "use strict";export const Keystore = validate11;const schema12 = {"type":"object","properties":{"credentials":{"type":"object"},"appIdentifier":{"type":"string"},"version":{"type":"string"},"application":{"type":"string"}},"required":["application","appIdentifier","credentials","version"]};function validate11(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(errors === 0){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if(((((data.application === undefined) && (missing0 = "application")) || ((data.appIdentifier === undefined) && (missing0 = "appIdentifier"))) || ((data.credentials === undefined) && (missing0 = "credentials"))) || ((data.version === undefined) && (missing0 = "version"))){validate11.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.credentials !== undefined){let data0 = data.credentials;const _errs1 = errors;if(!(data0 && typeof data0 == "object" && !Array.isArray(data0))){validate11.errors = [{instancePath:instancePath+"/credentials",schemaPath:"#/properties/credentials/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}var valid0 = _errs1 === errors;}else {var valid0 = true;}if(valid0){if(data.appIdentifier !== undefined){const _errs3 = errors;if(typeof data.appIdentifier !== "string"){validate11.errors = [{instancePath:instancePath+"/appIdentifier",schemaPath:"#/properties/appIdentifier/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs3 === errors;}else {var valid0 = true;}if(valid0){if(data.version !== undefined){const _errs5 = errors;if(typeof data.version !== "string"){validate11.errors = [{instancePath:instancePath+"/version",schemaPath:"#/properties/version/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs5 === errors;}else {var valid0 = true;}if(valid0){if(data.application !== undefined){const _errs7 = errors;if(typeof data.application !== "string"){validate11.errors = [{instancePath:instancePath+"/application",schemaPath:"#/properties/application/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid0 = _errs7 === errors;}else {var valid0 = true;}}}}}}else {validate11.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate11.errors = vErrors;return errors === 0;}
@@ -0,0 +1,34 @@
1
+ import { Credential as _validateCredentialGenerated } from "./credential_validation_generated.js";
2
+ import { Keystore as _validateKeystoreGenerated } from "./keystore_validation_generated.js";
3
+
4
+ type ErrorObject = {
5
+ instancePath: string;
6
+ schemaPath: string;
7
+ keyword: string;
8
+ params: object;
9
+ message: string;
10
+ };
11
+
12
+ type ValidatorFn = ((data: unknown) => boolean) & { errors: ErrorObject[] };
13
+
14
+ const _validateKeystore = _validateKeystoreGenerated as ValidatorFn;
15
+ const _validateCredential = _validateCredentialGenerated as ValidatorFn;
16
+
17
+ function schemaValidationErrors(
18
+ validator: ValidatorFn,
19
+ data: unknown
20
+ ): ErrorObject[] | null {
21
+ const validated = validator(data);
22
+ if (validated) {
23
+ return null;
24
+ }
25
+ return validator.errors;
26
+ }
27
+
28
+ export function isKeystoreValid(keystore: unknown): boolean {
29
+ return !schemaValidationErrors(_validateKeystore, keystore);
30
+ }
31
+
32
+ export function isCredentialValid(credential: unknown): boolean {
33
+ return !schemaValidationErrors(_validateCredential, credential);
34
+ }
@@ -0,0 +1,36 @@
1
+ import type { IdentityCredential } from "../identity.js";
2
+
3
+ export type MembershipHash = string;
4
+ export type Sha256Hash = string;
5
+ export type Keccak256Hash = string;
6
+ export type Password = string | Uint8Array;
7
+
8
+ // see reference
9
+ // https://github.com/waku-org/nwaku/blob/f05528d4be3d3c876a8b07f9bb7dfaae8aa8ec6e/waku/waku_keystore/protocol_types.nim#L111
10
+ export type MembershipInfo = {
11
+ chainId: number;
12
+ address: string;
13
+ treeIndex: number;
14
+ };
15
+
16
+ export type KeystoreEntity = {
17
+ identity: IdentityCredential;
18
+ membership: MembershipInfo;
19
+ };
20
+
21
+ export type DecryptedCredentials = KeystoreEntity;
22
+
23
+ export type EncryptedCredentials = {
24
+ /**
25
+ * Valid JSON string that contains Keystore
26
+ */
27
+ keystore: string;
28
+ /**
29
+ * ID of credentials from provided Keystore to use
30
+ */
31
+ id: string;
32
+ /**
33
+ * Password to decrypt credentials provided
34
+ */
35
+ password: Password;
36
+ };
package/src/message.ts CHANGED
@@ -16,7 +16,7 @@ export function toRLNSignal(contentTopic: string, msg: IMessage): Uint8Array {
16
16
  export class RlnMessage<T extends IDecodedMessage> implements IDecodedMessage {
17
17
  public pubsubTopic = "";
18
18
 
19
- constructor(
19
+ public constructor(
20
20
  public rlnInstance: RLNInstance,
21
21
  public msg: T,
22
22
  public rateLimitProof: IRateLimitProof | undefined
@@ -27,7 +27,7 @@ export class RlnMessage<T extends IDecodedMessage> implements IDecodedMessage {
27
27
  ? this.rlnInstance.zerokit.verifyWithRoots(
28
28
  this.rateLimitProof,
29
29
  toRLNSignal(this.msg.contentTopic, this.msg),
30
- ...roots
30
+ roots
31
31
  ) // this.rlnInstance.verifyRLNProof once issue status-im/nwaku#1248 is fixed
32
32
  : undefined;
33
33
  }
@@ -41,29 +41,29 @@ export class RlnMessage<T extends IDecodedMessage> implements IDecodedMessage {
41
41
  : undefined;
42
42
  }
43
43
 
44
- get payload(): Uint8Array {
44
+ public get payload(): Uint8Array {
45
45
  return this.msg.payload;
46
46
  }
47
47
 
48
- get contentTopic(): string {
48
+ public get contentTopic(): string {
49
49
  return this.msg.contentTopic;
50
50
  }
51
51
 
52
- get timestamp(): Date | undefined {
52
+ public get timestamp(): Date | undefined {
53
53
  return this.msg.timestamp;
54
54
  }
55
55
 
56
- get ephemeral(): boolean | undefined {
56
+ public get ephemeral(): boolean | undefined {
57
57
  return this.msg.ephemeral;
58
58
  }
59
59
 
60
- get meta(): Uint8Array | undefined {
60
+ public get meta(): Uint8Array | undefined {
61
61
  return this.msg.meta;
62
62
  }
63
63
 
64
- get epoch(): number | undefined {
65
- const bytes = this.msg.rateLimitProof?.epoch;
66
- if (!bytes) return;
64
+ public get epoch(): number | undefined {
65
+ const bytes = this.rateLimitProof?.epoch;
66
+ if (!bytes) return undefined;
67
67
 
68
68
  return epochBytesToInt(bytes);
69
69
  }
package/src/proof.ts CHANGED
@@ -11,7 +11,7 @@ const nullifierOffset = shareYOffset + 32;
11
11
  const rlnIdentifierOffset = nullifierOffset + 32;
12
12
 
13
13
  class ProofMetadata {
14
- constructor(
14
+ public constructor(
15
15
  public readonly nullifier: Uint8Array,
16
16
  public readonly shareX: Uint8Array,
17
17
  public readonly shareY: Uint8Array,
@@ -20,16 +20,18 @@ class ProofMetadata {
20
20
  }
21
21
 
22
22
  export class Proof implements IRateLimitProof {
23
- readonly proof: Uint8Array;
24
- readonly merkleRoot: Uint8Array;
25
- readonly epoch: Uint8Array;
26
- readonly shareX: Uint8Array;
27
- readonly shareY: Uint8Array;
28
- readonly nullifier: Uint8Array;
29
- readonly rlnIdentifier: Uint8Array;
23
+ public readonly proof: Uint8Array;
24
+ public readonly merkleRoot: Uint8Array;
25
+ public readonly epoch: Uint8Array;
26
+ public readonly shareX: Uint8Array;
27
+ public readonly shareY: Uint8Array;
28
+ public readonly nullifier: Uint8Array;
29
+ public readonly rlnIdentifier: Uint8Array;
30
30
 
31
- constructor(proofBytes: Uint8Array) {
32
- if (proofBytes.length < rlnIdentifierOffset) throw "invalid proof";
31
+ public constructor(proofBytes: Uint8Array) {
32
+ if (proofBytes.length < rlnIdentifierOffset) {
33
+ throw new Error("invalid proof");
34
+ }
33
35
  // parse the proof as proof<128> | share_y<32> | nullifier<32> | root<32> | epoch<32> | share_x<32> | rln_identifier<32>
34
36
  this.proof = proofBytes.subarray(0, proofOffset);
35
37
  this.merkleRoot = proofBytes.subarray(proofOffset, rootOffset);
@@ -43,7 +45,7 @@ export class Proof implements IRateLimitProof {
43
45
  );
44
46
  }
45
47
 
46
- extractMetadata(): ProofMetadata {
48
+ public extractMetadata(): ProofMetadata {
47
49
  const externalNullifier = poseidonHash(this.epoch, this.rlnIdentifier);
48
50
  return new ProofMetadata(
49
51
  this.nullifier,
@@ -0,0 +1,13 @@
1
+ declare const verificationKey: {
2
+ protocol: string;
3
+ curve: string;
4
+ nPublic: number;
5
+ vk_alpha_1: string[];
6
+ vk_beta_2: string[][];
7
+ vk_gamma_2: string[][];
8
+ vk_delta_2: string[][];
9
+ vk_alphabeta_12: string[][][];
10
+ IC: string[][];
11
+ };
12
+
13
+ export default verificationKey;
@@ -0,0 +1,11 @@
1
+ export async function builder(
2
+ code: Uint8Array,
3
+ sanityCheck: boolean
4
+ ): Promise<WitnessCalculator>;
5
+
6
+ export class WitnessCalculator {
7
+ public calculateWitness(
8
+ input: unknown,
9
+ sanityCheck: boolean
10
+ ): Promise<Array<bigint>>;
11
+ }