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