@waku/rln 0.1.3-f6d5deb → 0.1.4-2a94244.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -186
- package/bundle/_virtual/__node-resolve_empty.js +6 -0
- package/bundle/_virtual/_assert.js +3 -0
- package/bundle/_virtual/_commonjs-dynamic-modules.js +5 -0
- package/bundle/_virtual/_commonjsHelpers.js +32 -0
- package/bundle/_virtual/_node-resolve_empty.js +3 -0
- package/bundle/_virtual/_sha2.js +3 -0
- package/bundle/_virtual/_u64.js +3 -0
- package/bundle/_virtual/aes.js +3 -0
- package/bundle/_virtual/bn.js +3 -0
- package/bundle/_virtual/browser.js +3 -0
- package/bundle/_virtual/checksum.js +3 -0
- package/bundle/_virtual/cipher.js +3 -0
- package/bundle/_virtual/class.js +3 -0
- package/bundle/_virtual/common.js +3 -0
- package/bundle/_virtual/common2.js +3 -0
- package/bundle/_virtual/cryptoBrowser.js +3 -0
- package/bundle/_virtual/functional.js +3 -0
- package/bundle/_virtual/hash.js +3 -0
- package/bundle/_virtual/hmac.js +3 -0
- package/bundle/_virtual/index.js +3 -0
- package/bundle/_virtual/index2.js +6 -0
- package/bundle/_virtual/inherits_browser.js +3 -0
- package/bundle/_virtual/kdf.js +3 -0
- package/bundle/_virtual/lodash.js +3 -0
- package/bundle/_virtual/password.js +3 -0
- package/bundle/_virtual/pbkdf2.js +3 -0
- package/bundle/_virtual/pbkdf22.js +3 -0
- package/bundle/_virtual/random.js +3 -0
- package/bundle/_virtual/ripemd.js +3 -0
- package/bundle/_virtual/schema-validation-generated.js +3 -0
- package/bundle/_virtual/schema-validation.js +3 -0
- package/bundle/_virtual/scrypt.js +3 -0
- package/bundle/_virtual/scrypt2.js +3 -0
- package/bundle/_virtual/sha.js +3 -0
- package/bundle/_virtual/sha256.js +3 -0
- package/bundle/_virtual/sha2562.js +3 -0
- package/bundle/_virtual/sha3.js +3 -0
- package/bundle/_virtual/sha512.js +3 -0
- package/bundle/_virtual/types.js +3 -0
- package/bundle/_virtual/utils.js +3 -0
- package/bundle/_virtual/utils2.js +3 -0
- package/bundle/_virtual/utils3.js +3 -0
- package/bundle/index.js +12 -74804
- package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +96 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +148 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +20 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +210 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +18 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +30 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +22 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +43 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +19 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +58 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +854 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +609 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +66 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +302 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +110 -0
- package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +20 -0
- package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +287 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +402 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +3 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +8 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +893 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +256 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +36 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +135 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +8 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +64 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +443 -0
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +8 -0
- package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +660 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +352 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +248 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +127 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +2007 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +422 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +674 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +132 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +8 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +2430 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +76 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +219 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +279 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +69 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +404 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +15 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +20 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +92 -0
- package/bundle/node_modules/@noble/hashes/esm/_assert.js +37 -0
- package/bundle/node_modules/@noble/hashes/esm/_md.js +132 -0
- package/bundle/node_modules/@noble/hashes/esm/_u64.js +29 -0
- package/bundle/node_modules/@noble/hashes/esm/sha256.js +113 -0
- package/bundle/node_modules/@noble/hashes/esm/sha3.js +210 -0
- package/bundle/node_modules/@noble/hashes/esm/utils.js +144 -0
- package/bundle/node_modules/@waku/zerokit-rln-wasm/rln_wasm.js +756 -0
- package/bundle/node_modules/bech32/index.js +187 -0
- package/bundle/node_modules/bn.js/lib/bn.js +3361 -0
- package/bundle/node_modules/debug/src/browser.js +283 -0
- package/bundle/node_modules/debug/src/common.js +295 -0
- package/bundle/node_modules/ethereum-cryptography/esm/keccak.js +10 -0
- package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +6 -0
- package/bundle/node_modules/ethereum-cryptography/esm/utils.js +24 -0
- package/bundle/node_modules/hash.js/lib/hash/common.js +97 -0
- package/bundle/node_modules/hash.js/lib/hash/hmac.js +51 -0
- package/bundle/node_modules/hash.js/lib/hash/ripemd.js +152 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/1.js +81 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/224.js +33 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/256.js +113 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/384.js +39 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/512.js +336 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/common.js +53 -0
- package/bundle/node_modules/hash.js/lib/hash/sha.js +14 -0
- package/bundle/node_modules/hash.js/lib/hash/utils.js +282 -0
- package/bundle/node_modules/hash.js/lib/hash.js +33 -0
- package/bundle/node_modules/inherits/inherits_browser.js +33 -0
- package/bundle/node_modules/it-length-prefixed/dist/src/decode.js +6 -0
- package/bundle/node_modules/lodash/lodash.js +17207 -0
- package/bundle/node_modules/minimalistic-assert/index.js +13 -0
- package/bundle/node_modules/ms/index.js +172 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base.js +205 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base10.js +9 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base16.js +16 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base2.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base256emoji.js +41 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base32.js +58 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base36.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base58.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base64.js +28 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base8.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/identity.js +11 -0
- package/bundle/node_modules/multiformats/dist/src/basics.js +15 -0
- package/bundle/node_modules/multiformats/dist/src/bytes.js +18 -0
- package/bundle/node_modules/multiformats/dist/src/codecs/json.js +2 -0
- package/bundle/node_modules/multiformats/dist/src/vendor/base-x.js +170 -0
- package/bundle/node_modules/protons-runtime/dist/src/codec.js +20 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/enum.js +24 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/message.js +7 -0
- package/bundle/node_modules/protons-runtime/dist/src/decode.js +8 -0
- package/bundle/node_modules/protons-runtime/dist/src/encode.js +11 -0
- package/bundle/node_modules/protons-runtime/dist/src/index.js +30 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/float.js +54 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/longbits.js +175 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/pool.js +28 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/reader.js +367 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/utf8.js +99 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/writer.js +438 -0
- package/bundle/node_modules/uint8-varint/dist/src/index.js +124 -0
- package/bundle/node_modules/uint8arrays/dist/src/alloc.js +17 -0
- package/bundle/node_modules/uint8arrays/dist/src/from-string.js +19 -0
- package/bundle/node_modules/uint8arrays/dist/src/util/bases.js +49 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +21 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +18 -0
- package/bundle/packages/core/dist/lib/filter/filter.js +27 -0
- package/bundle/packages/core/dist/lib/light_push/light_push.js +27 -0
- package/bundle/packages/core/dist/lib/message/version_0.js +154 -0
- package/bundle/packages/core/dist/lib/metadata/metadata.js +27 -0
- package/bundle/packages/core/dist/lib/store/store.js +27 -0
- package/bundle/packages/interfaces/dist/connection_manager.js +19 -0
- package/bundle/packages/interfaces/dist/constants.js +6 -0
- package/bundle/packages/interfaces/dist/health_indicator.js +12 -0
- package/bundle/packages/interfaces/dist/protocols.js +92 -0
- package/bundle/packages/proto/dist/generated/filter.js +445 -0
- package/bundle/packages/proto/dist/generated/filter_v2.js +424 -0
- package/bundle/packages/proto/dist/generated/light_push.js +389 -0
- package/bundle/packages/proto/dist/generated/message.js +213 -0
- package/bundle/packages/proto/dist/generated/metadata.js +130 -0
- package/bundle/packages/proto/dist/generated/peer_exchange.js +209 -0
- package/bundle/packages/proto/dist/generated/sds_message.js +105 -0
- package/bundle/packages/proto/dist/generated/store_v3.js +490 -0
- package/bundle/packages/proto/dist/generated/topic_only_message.js +61 -0
- package/bundle/packages/rln/dist/codec.js +93 -0
- package/bundle/packages/rln/dist/contract/abi.js +394 -0
- package/bundle/packages/rln/dist/contract/constants.js +27 -0
- package/bundle/packages/rln/dist/contract/rln_contract.js +438 -0
- package/bundle/packages/rln/dist/create.js +9 -0
- package/bundle/packages/rln/dist/identity.js +30 -0
- package/bundle/packages/rln/dist/keystore/cipher.js +31 -0
- package/bundle/packages/rln/dist/keystore/credential_validation_generated.js +119 -0
- package/bundle/packages/rln/dist/keystore/keystore.js +223 -0
- package/bundle/packages/rln/dist/keystore/keystore_validation_generated.js +74 -0
- package/bundle/packages/rln/dist/keystore/schema_validator.js +20 -0
- package/bundle/packages/rln/dist/message.js +51 -0
- package/bundle/packages/rln/dist/proof.js +54 -0
- package/bundle/packages/rln/dist/resources/verification_key.js +112 -0
- package/bundle/packages/rln/dist/resources/witness_calculator.js +330 -0
- package/bundle/packages/rln/dist/rln.js +220 -0
- package/bundle/packages/rln/dist/root_tracker.js +76 -0
- package/bundle/packages/rln/dist/utils/bytes.js +65 -0
- package/bundle/packages/rln/dist/utils/epoch.js +39 -0
- package/bundle/packages/rln/dist/utils/hash.js +10 -0
- package/bundle/packages/rln/dist/utils/metamask.js +14 -0
- package/bundle/packages/rln/dist/zerokit.js +128 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +52 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +65 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +99 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/index.js +28 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +78 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1253 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +40 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/types.js +5 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +41 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +23 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +12 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +77 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +9 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +215 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +35 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +21 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +66 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +24 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +7 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +11 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +52 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +124 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +71 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +10 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +88 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +99 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +233 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +133 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +243 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +167 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/native.js +4 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/rng.js +13 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/stringify.js +28 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/v4.js +19 -0
- package/bundle/packages/utils/dist/bytes/index.js +44 -0
- package/bundle/packages/utils/dist/common/sharding/index.js +91 -0
- package/bundle/packages/utils/dist/logger/index.js +31 -0
- package/bundle/resources/verification_key.d.ts +13 -0
- package/bundle/resources/verification_key.js +112 -0
- package/bundle/resources/witness_calculator.d.ts +11 -0
- package/bundle/resources/witness_calculator.js +328 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/codec.d.ts +5 -5
- package/dist/codec.js +6 -6
- package/dist/codec.js.map +1 -1
- package/dist/contract/abi.d.ts +42 -0
- package/dist/contract/abi.js +393 -0
- package/dist/contract/abi.js.map +1 -0
- package/dist/contract/constants.d.ts +59 -3
- package/dist/contract/constants.js +21 -63
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_contract.d.ts +98 -17
- package/dist/contract/rln_contract.js +292 -71
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/identity.js +5 -2
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/keystore/cipher.js +3 -3
- package/dist/keystore/cipher.js.map +1 -1
- package/dist/keystore/credential_validation_generated.js.map +1 -1
- package/dist/keystore/keystore.js +4 -4
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/keystore_validation_generated.js.map +1 -1
- package/dist/message.js +3 -3
- package/dist/message.js.map +1 -1
- package/dist/proof.js +3 -2
- package/dist/proof.js.map +1 -1
- package/dist/resources/verification_key.d.ts +12 -11
- package/dist/resources/verification_key.js +103 -103
- package/dist/resources/witness_calculator.d.ts +10 -15
- package/dist/resources/witness_calculator.js +302 -265
- package/dist/rln.d.ts +5 -1
- package/dist/rln.js +56 -28
- package/dist/rln.js.map +1 -1
- package/dist/root_tracker.js.map +1 -1
- package/dist/utils/epoch.js +5 -5
- package/dist/utils/epoch.js.map +1 -1
- package/dist/zerokit.d.ts +13 -9
- package/dist/zerokit.js +40 -20
- package/dist/zerokit.js.map +1 -1
- package/package.json +1 -146
- package/src/codec.ts +26 -22
- package/src/contract/abi.ts +392 -0
- package/src/contract/constants.ts +28 -0
- package/src/contract/index.ts +2 -0
- package/src/contract/rln_contract.ts +686 -0
- package/src/identity.ts +8 -4
- package/src/index.ts +4 -9
- package/src/keystore/cipher.ts +54 -0
- package/src/keystore/credential_validation_generated.ts +7 -0
- package/src/keystore/index.ts +5 -0
- package/src/keystore/keystore.ts +330 -0
- package/src/keystore/keystore_validation_generated.ts +7 -0
- package/src/keystore/schema_validator.ts +34 -0
- package/src/keystore/types.ts +36 -0
- package/src/message.ts +10 -10
- package/src/proof.ts +13 -11
- package/src/resources/verification_key.d.ts +13 -0
- package/src/resources/witness_calculator.d.ts +11 -0
- package/src/rln.ts +76 -31
- package/src/root_tracker.ts +7 -6
- package/src/utils/bytes.ts +84 -0
- package/src/utils/epoch.ts +30 -0
- package/src/utils/hash.ts +15 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/metamask.ts +17 -0
- package/src/zerokit.ts +95 -33
- package/bundle/assets/rln_wasm_bg-a503e304.wasm +0 -0
- package/dist/resources/verification_key.js.map +0 -1
- package/dist/resources/witness_calculator.js.map +0 -1
- /package/bundle/{assets/rln-6ded2896.wasm → resources/rln.wasm} +0 -0
- /package/bundle/{assets/rln_final-8b299152.zkey → resources/rln_final.zkey} +0 -0
package/src/rln.ts
CHANGED
@@ -4,6 +4,7 @@ import type {
|
|
4
4
|
IDecodedMessage,
|
5
5
|
EncoderOptions as WakuEncoderOptions
|
6
6
|
} from "@waku/interfaces";
|
7
|
+
import { Logger } from "@waku/utils";
|
7
8
|
import init from "@waku/zerokit-rln-wasm";
|
8
9
|
import * as zerokitRLN from "@waku/zerokit-rln-wasm";
|
9
10
|
import { ethers } from "ethers";
|
@@ -14,6 +15,7 @@ import {
|
|
14
15
|
type RLNDecoder,
|
15
16
|
type RLNEncoder
|
16
17
|
} from "./codec.js";
|
18
|
+
import { DEFAULT_RATE_LIMIT } from "./contract/constants.js";
|
17
19
|
import { RLNContract, SEPOLIA_CONTRACT } from "./contract/index.js";
|
18
20
|
import { IdentityCredential } from "./identity.js";
|
19
21
|
import { Keystore } from "./keystore/index.js";
|
@@ -22,22 +24,55 @@ import type {
|
|
22
24
|
EncryptedCredentials
|
23
25
|
} from "./keystore/index.js";
|
24
26
|
import { KeystoreEntity, Password } from "./keystore/types.js";
|
25
|
-
import verificationKey from "./resources/verification_key
|
26
|
-
import * as wc from "./resources/witness_calculator
|
27
|
-
import { WitnessCalculator } from "./resources/witness_calculator
|
27
|
+
import verificationKey from "./resources/verification_key";
|
28
|
+
import * as wc from "./resources/witness_calculator";
|
29
|
+
import { WitnessCalculator } from "./resources/witness_calculator";
|
28
30
|
import { extractMetaMaskSigner } from "./utils/index.js";
|
29
31
|
import { Zerokit } from "./zerokit.js";
|
30
32
|
|
33
|
+
const log = new Logger("waku:rln");
|
34
|
+
|
31
35
|
async function loadWitnessCalculator(): Promise<WitnessCalculator> {
|
32
|
-
|
33
|
-
|
34
|
-
|
36
|
+
try {
|
37
|
+
const url = new URL("./resources/rln.wasm", import.meta.url);
|
38
|
+
const response = await fetch(url);
|
39
|
+
|
40
|
+
if (!response.ok) {
|
41
|
+
throw new Error(
|
42
|
+
`Failed to fetch witness calculator: ${response.status} ${response.statusText}`
|
43
|
+
);
|
44
|
+
}
|
45
|
+
|
46
|
+
return await wc.builder(
|
47
|
+
new Uint8Array(await response.arrayBuffer()),
|
48
|
+
false
|
49
|
+
);
|
50
|
+
} catch (error) {
|
51
|
+
log.error("Error loading witness calculator:", error);
|
52
|
+
throw new Error(
|
53
|
+
`Failed to load witness calculator: ${error instanceof Error ? error.message : String(error)}`
|
54
|
+
);
|
55
|
+
}
|
35
56
|
}
|
36
57
|
|
37
58
|
async function loadZkey(): Promise<Uint8Array> {
|
38
|
-
|
39
|
-
|
40
|
-
|
59
|
+
try {
|
60
|
+
const url = new URL("./resources/rln_final.zkey", import.meta.url);
|
61
|
+
const response = await fetch(url);
|
62
|
+
|
63
|
+
if (!response.ok) {
|
64
|
+
throw new Error(
|
65
|
+
`Failed to fetch zkey: ${response.status} ${response.statusText}`
|
66
|
+
);
|
67
|
+
}
|
68
|
+
|
69
|
+
return new Uint8Array(await response.arrayBuffer());
|
70
|
+
} catch (error) {
|
71
|
+
log.error("Error loading zkey:", error);
|
72
|
+
throw new Error(
|
73
|
+
`Failed to load zkey: ${error instanceof Error ? error.message : String(error)}`
|
74
|
+
);
|
75
|
+
}
|
41
76
|
}
|
42
77
|
|
43
78
|
/**
|
@@ -45,21 +80,26 @@ async function loadZkey(): Promise<Uint8Array> {
|
|
45
80
|
* @returns RLNInstance
|
46
81
|
*/
|
47
82
|
export async function create(): Promise<RLNInstance> {
|
48
|
-
|
49
|
-
|
50
|
-
|
83
|
+
try {
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
85
|
+
await (init as any)?.();
|
86
|
+
zerokitRLN.init_panic_hook();
|
51
87
|
|
52
|
-
|
53
|
-
|
88
|
+
const witnessCalculator = await loadWitnessCalculator();
|
89
|
+
const zkey = await loadZkey();
|
54
90
|
|
55
|
-
|
56
|
-
|
91
|
+
const stringEncoder = new TextEncoder();
|
92
|
+
const vkey = stringEncoder.encode(JSON.stringify(verificationKey));
|
57
93
|
|
58
|
-
|
59
|
-
|
60
|
-
|
94
|
+
const DEPTH = 20;
|
95
|
+
const zkRLN = zerokitRLN.newRLN(DEPTH, zkey, vkey);
|
96
|
+
const zerokit = new Zerokit(zkRLN, witnessCalculator, DEFAULT_RATE_LIMIT);
|
61
97
|
|
62
|
-
|
98
|
+
return new RLNInstance(zerokit);
|
99
|
+
} catch (error) {
|
100
|
+
log.error("Failed to initialize RLN:", error);
|
101
|
+
throw error;
|
102
|
+
}
|
63
103
|
}
|
64
104
|
|
65
105
|
type StartRLNOptions = {
|
@@ -70,12 +110,16 @@ type StartRLNOptions = {
|
|
70
110
|
/**
|
71
111
|
* If not set - will use default SEPOLIA_CONTRACT address.
|
72
112
|
*/
|
73
|
-
|
113
|
+
address?: string;
|
74
114
|
/**
|
75
115
|
* Credentials to use for generating proofs and connecting to the contract and network.
|
76
116
|
* If provided used for validating the network chainId and connecting to registry contract.
|
77
117
|
*/
|
78
118
|
credentials?: EncryptedCredentials | DecryptedCredentials;
|
119
|
+
/**
|
120
|
+
* Rate limit for the member.
|
121
|
+
*/
|
122
|
+
rateLimit?: number;
|
79
123
|
};
|
80
124
|
|
81
125
|
type RegisterMembershipOptions =
|
@@ -96,7 +140,7 @@ export class RLNInstance {
|
|
96
140
|
private keystore = Keystore.create();
|
97
141
|
private _credentials: undefined | DecryptedCredentials;
|
98
142
|
|
99
|
-
constructor(public zerokit: Zerokit) {}
|
143
|
+
public constructor(public zerokit: Zerokit) {}
|
100
144
|
|
101
145
|
public get contract(): undefined | RLNContract {
|
102
146
|
return this._contract;
|
@@ -116,7 +160,7 @@ export class RLNInstance {
|
|
116
160
|
try {
|
117
161
|
const { credentials, keystore } =
|
118
162
|
await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
|
119
|
-
const { signer,
|
163
|
+
const { signer, address } = await this.determineStartOptions(
|
120
164
|
options,
|
121
165
|
credentials
|
122
166
|
);
|
@@ -128,8 +172,9 @@ export class RLNInstance {
|
|
128
172
|
this._credentials = credentials;
|
129
173
|
this._signer = signer!;
|
130
174
|
this._contract = await RLNContract.init(this, {
|
131
|
-
|
132
|
-
signer: signer
|
175
|
+
address: address!,
|
176
|
+
signer: signer!,
|
177
|
+
rateLimit: options.rateLimit ?? this.zerokit.getRateLimit
|
133
178
|
});
|
134
179
|
this.started = true;
|
135
180
|
} finally {
|
@@ -142,12 +187,12 @@ export class RLNInstance {
|
|
142
187
|
credentials: KeystoreEntity | undefined
|
143
188
|
): Promise<StartRLNOptions> {
|
144
189
|
let chainId = credentials?.membership.chainId;
|
145
|
-
const
|
190
|
+
const address =
|
146
191
|
credentials?.membership.address ||
|
147
|
-
options.
|
192
|
+
options.address ||
|
148
193
|
SEPOLIA_CONTRACT.address;
|
149
194
|
|
150
|
-
if (
|
195
|
+
if (address === SEPOLIA_CONTRACT.address) {
|
151
196
|
chainId = SEPOLIA_CONTRACT.chainId;
|
152
197
|
}
|
153
198
|
|
@@ -162,7 +207,7 @@ export class RLNInstance {
|
|
162
207
|
|
163
208
|
return {
|
164
209
|
signer,
|
165
|
-
|
210
|
+
address
|
166
211
|
};
|
167
212
|
}
|
168
213
|
|
@@ -258,7 +303,7 @@ export class RLNInstance {
|
|
258
303
|
}
|
259
304
|
|
260
305
|
const registryAddress = credentials.membership.address;
|
261
|
-
const currentRegistryAddress = this._contract.
|
306
|
+
const currentRegistryAddress = this._contract.address;
|
262
307
|
if (registryAddress !== currentRegistryAddress) {
|
263
308
|
throw Error(
|
264
309
|
`Failed to verify chain coordinates: credentials contract address=${registryAddress} is not equal to registryContract address=${currentRegistryAddress}`
|
@@ -266,7 +311,7 @@ export class RLNInstance {
|
|
266
311
|
}
|
267
312
|
|
268
313
|
const chainId = credentials.membership.chainId;
|
269
|
-
const network = await this._contract.
|
314
|
+
const network = await this._contract.provider.getNetwork();
|
270
315
|
const currentChainId = network.chainId;
|
271
316
|
if (chainId !== currentChainId) {
|
272
317
|
throw Error(
|
package/src/root_tracker.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class RootPerBlock {
|
2
|
-
constructor(
|
2
|
+
public constructor(
|
3
3
|
public root: Uint8Array,
|
4
4
|
public blockNumber: number
|
5
5
|
) {}
|
@@ -10,14 +10,15 @@ const maxBufferSize = 20;
|
|
10
10
|
export class MerkleRootTracker {
|
11
11
|
private validMerkleRoots: Array<RootPerBlock> = new Array<RootPerBlock>();
|
12
12
|
private merkleRootBuffer: Array<RootPerBlock> = new Array<RootPerBlock>();
|
13
|
-
|
13
|
+
|
14
|
+
public constructor(
|
14
15
|
private acceptableRootWindowSize: number,
|
15
16
|
initialRoot: Uint8Array
|
16
17
|
) {
|
17
18
|
this.pushRoot(0, initialRoot);
|
18
19
|
}
|
19
20
|
|
20
|
-
backFill(fromBlockNumber: number): void {
|
21
|
+
public backFill(fromBlockNumber: number): void {
|
21
22
|
if (this.validMerkleRoots.length == 0) return;
|
22
23
|
|
23
24
|
let numBlocks = 0;
|
@@ -66,7 +67,7 @@ export class MerkleRootTracker {
|
|
66
67
|
}
|
67
68
|
}
|
68
69
|
|
69
|
-
pushRoot(blockNumber: number, root: Uint8Array): void {
|
70
|
+
public pushRoot(blockNumber: number, root: Uint8Array): void {
|
70
71
|
this.validMerkleRoots.push(new RootPerBlock(root, blockNumber));
|
71
72
|
|
72
73
|
// Maintain valid merkle root window
|
@@ -81,11 +82,11 @@ export class MerkleRootTracker {
|
|
81
82
|
}
|
82
83
|
}
|
83
84
|
|
84
|
-
roots(): Array<Uint8Array> {
|
85
|
+
public roots(): Array<Uint8Array> {
|
85
86
|
return this.validMerkleRoots.map((x) => x.root);
|
86
87
|
}
|
87
88
|
|
88
|
-
buffer(): Array<Uint8Array> {
|
89
|
+
public buffer(): Array<Uint8Array> {
|
89
90
|
return this.merkleRootBuffer.map((x) => x.root);
|
90
91
|
}
|
91
92
|
}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
/**
|
2
|
+
* Concatenate Uint8Arrays
|
3
|
+
* @param input
|
4
|
+
* @returns concatenation of all Uint8Array received as input
|
5
|
+
*/
|
6
|
+
export function concatenate(...input: Uint8Array[]): Uint8Array {
|
7
|
+
let totalLength = 0;
|
8
|
+
for (const arr of input) {
|
9
|
+
totalLength += arr.length;
|
10
|
+
}
|
11
|
+
const result = new Uint8Array(totalLength);
|
12
|
+
let offset = 0;
|
13
|
+
for (const arr of input) {
|
14
|
+
result.set(arr, offset);
|
15
|
+
offset += arr.length;
|
16
|
+
}
|
17
|
+
return result;
|
18
|
+
}
|
19
|
+
|
20
|
+
// Adapted from https://github.com/feross/buffer
|
21
|
+
function checkInt(
|
22
|
+
buf: Uint8Array,
|
23
|
+
value: number,
|
24
|
+
offset: number,
|
25
|
+
ext: number,
|
26
|
+
max: number,
|
27
|
+
min: number
|
28
|
+
): void {
|
29
|
+
if (value > max || value < min)
|
30
|
+
throw new RangeError('"value" argument is out of bounds');
|
31
|
+
if (offset + ext > buf.length) throw new RangeError("Index out of range");
|
32
|
+
}
|
33
|
+
|
34
|
+
export function writeUIntLE(
|
35
|
+
buf: Uint8Array,
|
36
|
+
value: number,
|
37
|
+
offset: number,
|
38
|
+
byteLength: number,
|
39
|
+
noAssert?: boolean
|
40
|
+
): Uint8Array {
|
41
|
+
value = +value;
|
42
|
+
offset = offset >>> 0;
|
43
|
+
byteLength = byteLength >>> 0;
|
44
|
+
if (!noAssert) {
|
45
|
+
const maxBytes = Math.pow(2, 8 * byteLength) - 1;
|
46
|
+
checkInt(buf, value, offset, byteLength, maxBytes, 0);
|
47
|
+
}
|
48
|
+
|
49
|
+
let mul = 1;
|
50
|
+
let i = 0;
|
51
|
+
buf[offset] = value & 0xff;
|
52
|
+
while (++i < byteLength && (mul *= 0x100)) {
|
53
|
+
buf[offset + i] = (value / mul) & 0xff;
|
54
|
+
}
|
55
|
+
|
56
|
+
return buf;
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Transforms Uint8Array into BigInt
|
61
|
+
* @param array: Uint8Array
|
62
|
+
* @returns BigInt
|
63
|
+
*/
|
64
|
+
export function buildBigIntFromUint8Array(
|
65
|
+
array: Uint8Array,
|
66
|
+
byteOffset: number = 0
|
67
|
+
): bigint {
|
68
|
+
const dataView = new DataView(array.buffer);
|
69
|
+
return dataView.getBigUint64(byteOffset, true);
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Fills with zeros to set length
|
74
|
+
* @param array little endian Uint8Array
|
75
|
+
* @param length amount to pad
|
76
|
+
* @returns little endian Uint8Array padded with zeros to set length
|
77
|
+
*/
|
78
|
+
export function zeroPadLE(array: Uint8Array, length: number): Uint8Array {
|
79
|
+
const result = new Uint8Array(length);
|
80
|
+
for (let i = 0; i < length; i++) {
|
81
|
+
result[i] = array[i] || 0;
|
82
|
+
}
|
83
|
+
return result;
|
84
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { Logger } from "@waku/utils";
|
2
|
+
|
3
|
+
const DefaultEpochUnitSeconds = 10; // the rln-relay epoch length in seconds
|
4
|
+
|
5
|
+
const log = new Logger("waku:rln:epoch");
|
6
|
+
|
7
|
+
export function dateToEpoch(
|
8
|
+
timestamp: Date,
|
9
|
+
epochUnitSeconds: number = DefaultEpochUnitSeconds
|
10
|
+
): number {
|
11
|
+
const time = timestamp.getTime();
|
12
|
+
const epoch = Math.floor(time / 1000 / epochUnitSeconds);
|
13
|
+
log.info("generated epoch", epoch);
|
14
|
+
return epoch;
|
15
|
+
}
|
16
|
+
|
17
|
+
export function epochIntToBytes(epoch: number): Uint8Array {
|
18
|
+
const bytes = new Uint8Array(32);
|
19
|
+
const db = new DataView(bytes.buffer);
|
20
|
+
db.setUint32(0, epoch, true);
|
21
|
+
log.info("encoded epoch", epoch, bytes);
|
22
|
+
return bytes;
|
23
|
+
}
|
24
|
+
|
25
|
+
export function epochBytesToInt(bytes: Uint8Array): number {
|
26
|
+
const dv = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
27
|
+
const epoch = dv.getUint32(0, true);
|
28
|
+
log.info("decoded epoch", epoch, bytes);
|
29
|
+
return epoch;
|
30
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import * as zerokitRLN from "@waku/zerokit-rln-wasm";
|
2
|
+
|
3
|
+
import { concatenate, writeUIntLE } from "./bytes.js";
|
4
|
+
|
5
|
+
export function poseidonHash(...input: Array<Uint8Array>): Uint8Array {
|
6
|
+
const inputLen = writeUIntLE(new Uint8Array(8), input.length, 0, 8);
|
7
|
+
const lenPrefixedData = concatenate(inputLen, ...input);
|
8
|
+
return zerokitRLN.poseidonHash(lenPrefixedData);
|
9
|
+
}
|
10
|
+
|
11
|
+
export function sha256(input: Uint8Array): Uint8Array {
|
12
|
+
const inputLen = writeUIntLE(new Uint8Array(8), input.length, 0, 8);
|
13
|
+
const lenPrefixedData = concatenate(inputLen, input);
|
14
|
+
return zerokitRLN.hash(lenPrefixedData);
|
15
|
+
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export { extractMetaMaskSigner } from "./metamask.js";
|
2
|
+
export {
|
3
|
+
concatenate,
|
4
|
+
writeUIntLE,
|
5
|
+
buildBigIntFromUint8Array,
|
6
|
+
zeroPadLE
|
7
|
+
} from "./bytes.js";
|
8
|
+
export { sha256, poseidonHash } from "./hash.js";
|
9
|
+
export { dateToEpoch, epochIntToBytes, epochBytesToInt } from "./epoch.js";
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { ethers } from "ethers";
|
2
|
+
|
3
|
+
export const extractMetaMaskSigner = async (): Promise<ethers.Signer> => {
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
5
|
+
const ethereum = (window as any).ethereum;
|
6
|
+
|
7
|
+
if (!ethereum) {
|
8
|
+
throw Error(
|
9
|
+
"Missing or invalid Ethereum provider. Please install a Web3 wallet such as MetaMask."
|
10
|
+
);
|
11
|
+
}
|
12
|
+
|
13
|
+
await ethereum.request({ method: "eth_requestAccounts" });
|
14
|
+
const provider = new ethers.providers.Web3Provider(ethereum, "any");
|
15
|
+
|
16
|
+
return provider.getSigner();
|
17
|
+
};
|
package/src/zerokit.ts
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
import type { IRateLimitProof } from "@waku/interfaces";
|
2
2
|
import * as zerokitRLN from "@waku/zerokit-rln-wasm";
|
3
3
|
|
4
|
+
import { DEFAULT_RATE_LIMIT, RATE_LIMIT_PARAMS } from "./contract/constants.js";
|
4
5
|
import { IdentityCredential } from "./identity.js";
|
5
6
|
import { Proof, proofToBytes } from "./proof.js";
|
6
|
-
import { WitnessCalculator } from "./resources/witness_calculator
|
7
|
+
import { WitnessCalculator } from "./resources/witness_calculator";
|
7
8
|
import {
|
8
9
|
concatenate,
|
9
10
|
dateToEpoch,
|
@@ -12,17 +13,30 @@ import {
|
|
12
13
|
} from "./utils/index.js";
|
13
14
|
|
14
15
|
export class Zerokit {
|
15
|
-
constructor(
|
16
|
-
private zkRLN: number,
|
17
|
-
private witnessCalculator: WitnessCalculator
|
16
|
+
public constructor(
|
17
|
+
private readonly zkRLN: number,
|
18
|
+
private readonly witnessCalculator: WitnessCalculator,
|
19
|
+
private readonly rateLimit: number = DEFAULT_RATE_LIMIT
|
18
20
|
) {}
|
19
21
|
|
20
|
-
|
22
|
+
public get getZkRLN(): number {
|
23
|
+
return this.zkRLN;
|
24
|
+
}
|
25
|
+
|
26
|
+
public get getWitnessCalculator(): WitnessCalculator {
|
27
|
+
return this.witnessCalculator;
|
28
|
+
}
|
29
|
+
|
30
|
+
public get getRateLimit(): number {
|
31
|
+
return this.rateLimit;
|
32
|
+
}
|
33
|
+
|
34
|
+
public generateIdentityCredentials(): IdentityCredential {
|
21
35
|
const memKeys = zerokitRLN.generateExtendedMembershipKey(this.zkRLN); // TODO: rename this function in zerokit rln-wasm
|
22
36
|
return IdentityCredential.fromBytes(memKeys);
|
23
37
|
}
|
24
38
|
|
25
|
-
generateSeededIdentityCredential(seed: string): IdentityCredential {
|
39
|
+
public generateSeededIdentityCredential(seed: string): IdentityCredential {
|
26
40
|
const stringEncoder = new TextEncoder();
|
27
41
|
const seedBytes = stringEncoder.encode(seed);
|
28
42
|
// TODO: rename this function in zerokit rln-wasm
|
@@ -33,11 +47,14 @@ export class Zerokit {
|
|
33
47
|
return IdentityCredential.fromBytes(memKeys);
|
34
48
|
}
|
35
49
|
|
36
|
-
insertMember(idCommitment: Uint8Array): void {
|
50
|
+
public insertMember(idCommitment: Uint8Array): void {
|
37
51
|
zerokitRLN.insertMember(this.zkRLN, idCommitment);
|
38
52
|
}
|
39
53
|
|
40
|
-
insertMembers(
|
54
|
+
public insertMembers(
|
55
|
+
index: number,
|
56
|
+
...idCommitments: Array<Uint8Array>
|
57
|
+
): void {
|
41
58
|
// serializes a seq of IDCommitments to a byte seq
|
42
59
|
// the order of serialization is |id_commitment_len<8>|id_commitment<var>|
|
43
60
|
const idCommitmentLen = writeUIntLE(
|
@@ -50,51 +67,75 @@ export class Zerokit {
|
|
50
67
|
zerokitRLN.setLeavesFrom(this.zkRLN, index, idCommitmentBytes);
|
51
68
|
}
|
52
69
|
|
53
|
-
deleteMember(index: number): void {
|
70
|
+
public deleteMember(index: number): void {
|
54
71
|
zerokitRLN.deleteLeaf(this.zkRLN, index);
|
55
72
|
}
|
56
73
|
|
57
|
-
getMerkleRoot(): Uint8Array {
|
74
|
+
public getMerkleRoot(): Uint8Array {
|
58
75
|
return zerokitRLN.getRoot(this.zkRLN);
|
59
76
|
}
|
60
77
|
|
61
|
-
serializeMessage(
|
78
|
+
public serializeMessage(
|
62
79
|
uint8Msg: Uint8Array,
|
63
80
|
memIndex: number,
|
64
81
|
epoch: Uint8Array,
|
65
|
-
idKey: Uint8Array
|
82
|
+
idKey: Uint8Array,
|
83
|
+
rateLimit?: number
|
66
84
|
): Uint8Array {
|
67
85
|
// calculate message length
|
68
86
|
const msgLen = writeUIntLE(new Uint8Array(8), uint8Msg.length, 0, 8);
|
69
|
-
|
70
|
-
// Converting index to LE bytes
|
71
87
|
const memIndexBytes = writeUIntLE(new Uint8Array(8), memIndex, 0, 8);
|
88
|
+
const rateLimitBytes = writeUIntLE(
|
89
|
+
new Uint8Array(8),
|
90
|
+
rateLimit ?? this.rateLimit,
|
91
|
+
0,
|
92
|
+
8
|
93
|
+
);
|
72
94
|
|
73
|
-
// [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> ]
|
74
|
-
return concatenate(
|
95
|
+
// [ id_key<32> | id_index<8> | epoch<32> | signal_len<8> | signal<var> | rate_limit<8> ]
|
96
|
+
return concatenate(
|
97
|
+
idKey,
|
98
|
+
memIndexBytes,
|
99
|
+
epoch,
|
100
|
+
msgLen,
|
101
|
+
uint8Msg,
|
102
|
+
rateLimitBytes
|
103
|
+
);
|
75
104
|
}
|
76
105
|
|
77
|
-
async generateRLNProof(
|
106
|
+
public async generateRLNProof(
|
78
107
|
msg: Uint8Array,
|
79
108
|
index: number,
|
80
109
|
epoch: Uint8Array | Date | undefined,
|
81
|
-
idSecretHash: Uint8Array
|
110
|
+
idSecretHash: Uint8Array,
|
111
|
+
rateLimit?: number
|
82
112
|
): Promise<IRateLimitProof> {
|
83
|
-
if (epoch
|
113
|
+
if (epoch === undefined) {
|
84
114
|
epoch = epochIntToBytes(dateToEpoch(new Date()));
|
85
115
|
} else if (epoch instanceof Date) {
|
86
116
|
epoch = epochIntToBytes(dateToEpoch(epoch));
|
87
117
|
}
|
88
118
|
|
89
|
-
|
90
|
-
|
91
|
-
if (
|
119
|
+
const effectiveRateLimit = rateLimit ?? this.rateLimit;
|
120
|
+
|
121
|
+
if (epoch.length !== 32) throw new Error("invalid epoch");
|
122
|
+
if (idSecretHash.length !== 32) throw new Error("invalid id secret hash");
|
123
|
+
if (index < 0) throw new Error("index must be >= 0");
|
124
|
+
if (
|
125
|
+
effectiveRateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
|
126
|
+
effectiveRateLimit > RATE_LIMIT_PARAMS.MAX_RATE
|
127
|
+
) {
|
128
|
+
throw new Error(
|
129
|
+
`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`
|
130
|
+
);
|
131
|
+
}
|
92
132
|
|
93
133
|
const serialized_msg = this.serializeMessage(
|
94
134
|
msg,
|
95
135
|
index,
|
96
136
|
epoch,
|
97
|
-
idSecretHash
|
137
|
+
idSecretHash,
|
138
|
+
effectiveRateLimit
|
98
139
|
);
|
99
140
|
const rlnWitness = zerokitRLN.getSerializedRLNWitness(
|
100
141
|
this.zkRLN,
|
@@ -104,7 +145,7 @@ export class Zerokit {
|
|
104
145
|
const calculatedWitness = await this.witnessCalculator.calculateWitness(
|
105
146
|
inputs,
|
106
147
|
false
|
107
|
-
);
|
148
|
+
);
|
108
149
|
|
109
150
|
const proofBytes = zerokitRLN.generate_rln_proof_with_witness(
|
110
151
|
this.zkRLN,
|
@@ -115,9 +156,10 @@ export class Zerokit {
|
|
115
156
|
return new Proof(proofBytes);
|
116
157
|
}
|
117
158
|
|
118
|
-
verifyRLNProof(
|
159
|
+
public verifyRLNProof(
|
119
160
|
proof: IRateLimitProof | Uint8Array,
|
120
|
-
msg: Uint8Array
|
161
|
+
msg: Uint8Array,
|
162
|
+
rateLimit?: number
|
121
163
|
): boolean {
|
122
164
|
let pBytes: Uint8Array;
|
123
165
|
if (proof instanceof Uint8Array) {
|
@@ -128,17 +170,24 @@ export class Zerokit {
|
|
128
170
|
|
129
171
|
// calculate message length
|
130
172
|
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
173
|
+
const rateLimitBytes = writeUIntLE(
|
174
|
+
new Uint8Array(8),
|
175
|
+
rateLimit ?? this.rateLimit,
|
176
|
+
0,
|
177
|
+
8
|
178
|
+
);
|
131
179
|
|
132
180
|
return zerokitRLN.verifyRLNProof(
|
133
181
|
this.zkRLN,
|
134
|
-
concatenate(pBytes, msgLen, msg)
|
182
|
+
concatenate(pBytes, msgLen, msg, rateLimitBytes)
|
135
183
|
);
|
136
184
|
}
|
137
185
|
|
138
|
-
verifyWithRoots(
|
186
|
+
public verifyWithRoots(
|
139
187
|
proof: IRateLimitProof | Uint8Array,
|
140
188
|
msg: Uint8Array,
|
141
|
-
|
189
|
+
roots: Array<Uint8Array>,
|
190
|
+
rateLimit?: number
|
142
191
|
): boolean {
|
143
192
|
let pBytes: Uint8Array;
|
144
193
|
if (proof instanceof Uint8Array) {
|
@@ -148,19 +197,26 @@ export class Zerokit {
|
|
148
197
|
}
|
149
198
|
// calculate message length
|
150
199
|
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
200
|
+
const rateLimitBytes = writeUIntLE(
|
201
|
+
new Uint8Array(8),
|
202
|
+
rateLimit ?? this.rateLimit,
|
203
|
+
0,
|
204
|
+
8
|
205
|
+
);
|
151
206
|
|
152
207
|
const rootsBytes = concatenate(...roots);
|
153
208
|
|
154
209
|
return zerokitRLN.verifyWithRoots(
|
155
210
|
this.zkRLN,
|
156
|
-
concatenate(pBytes, msgLen, msg),
|
211
|
+
concatenate(pBytes, msgLen, msg, rateLimitBytes),
|
157
212
|
rootsBytes
|
158
213
|
);
|
159
214
|
}
|
160
215
|
|
161
|
-
verifyWithNoRoot(
|
216
|
+
public verifyWithNoRoot(
|
162
217
|
proof: IRateLimitProof | Uint8Array,
|
163
|
-
msg: Uint8Array
|
218
|
+
msg: Uint8Array,
|
219
|
+
rateLimit?: number
|
164
220
|
): boolean {
|
165
221
|
let pBytes: Uint8Array;
|
166
222
|
if (proof instanceof Uint8Array) {
|
@@ -171,10 +227,16 @@ export class Zerokit {
|
|
171
227
|
|
172
228
|
// calculate message length
|
173
229
|
const msgLen = writeUIntLE(new Uint8Array(8), msg.length, 0, 8);
|
230
|
+
const rateLimitBytes = writeUIntLE(
|
231
|
+
new Uint8Array(8),
|
232
|
+
rateLimit ?? this.rateLimit,
|
233
|
+
0,
|
234
|
+
8
|
235
|
+
);
|
174
236
|
|
175
237
|
return zerokitRLN.verifyWithRoots(
|
176
238
|
this.zkRLN,
|
177
|
-
concatenate(pBytes, msgLen, msg),
|
239
|
+
concatenate(pBytes, msgLen, msg, rateLimitBytes),
|
178
240
|
new Uint8Array()
|
179
241
|
);
|
180
242
|
}
|
Binary file
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"verification_key.js","sourceRoot":"","sources":["../../src/resources/verification_key.js"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG;IACtB,QAAQ,EAAE,SAAS;IACnB,KAAK,EAAE,OAAO;IACd,OAAO,EAAE,CAAC;IACV,UAAU,EAAE;QACV,+EAA+E;QAC/E,8EAA8E;QAC9E,GAAG;KACJ;IACD,SAAS,EAAE;QACT;YACE,8EAA8E;YAC9E,+EAA+E;SAChF;QACD;YACE,+EAA+E;YAC/E,6EAA6E;SAC9E;QACD,CAAC,GAAG,EAAE,GAAG,CAAC;KACX;IACD,UAAU,EAAE;QACV;YACE,+EAA+E;YAC/E,+EAA+E;SAChF;QACD;YACE,8EAA8E;YAC9E,8EAA8E;SAC/E;QACD,CAAC,GAAG,EAAE,GAAG,CAAC;KACX;IACD,UAAU,EAAE;QACV;YACE,8EAA8E;YAC9E,8EAA8E;SAC/E;QACD;YACE,+EAA+E;YAC/E,+EAA+E;SAChF;QACD,CAAC,GAAG,EAAE,GAAG,CAAC;KACX;IACD,eAAe,EAAE;QACf;YACE;gBACE,+EAA+E;gBAC/E,8EAA8E;aAC/E;YACD;gBACE,8EAA8E;gBAC9E,8EAA8E;aAC/E;YACD;gBACE,+EAA+E;gBAC/E,8EAA8E;aAC/E;SACF;QACD;YACE;gBACE,8EAA8E;gBAC9E,+EAA+E;aAChF;YACD;gBACE,8EAA8E;gBAC9E,+EAA+E;aAChF;YACD;gBACE,+EAA+E;gBAC/E,+EAA+E;aAChF;SACF;KACF;IACD,EAAE,EAAE;QACF;YACE,+EAA+E;YAC/E,+EAA+E;YAC/E,GAAG;SACJ;QACD;YACE,+EAA+E;YAC/E,+EAA+E;YAC/E,GAAG;SACJ;QACD;YACE,+EAA+E;YAC/E,+EAA+E;YAC/E,GAAG;SACJ;QACD;YACE,+EAA+E;YAC/E,+EAA+E;YAC/E,GAAG;SACJ;QACD;YACE,+EAA+E;YAC/E,8EAA8E;YAC9E,GAAG;SACJ;QACD;YACE,6EAA6E;YAC7E,+EAA+E;YAC/E,GAAG;SACJ;QACD;YACE,+EAA+E;YAC/E,8EAA8E;YAC9E,GAAG;SACJ;KACF;CACF,CAAC;AAEF,eAAe,eAAe,CAAC"}
|