@waku/rln 0.0.1 → 0.0.2-ce9a6ae.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/@iden3/js-crypto/dist/browser/esm/index.js +7 -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/@stablelib/binary/lib/binary.js +22 -0
- package/bundle/node_modules/@stablelib/chacha/lib/chacha.js +245 -0
- package/bundle/node_modules/@stablelib/wipe/lib/wipe.js +26 -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 +97 -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/rlnv2.js +394 -0
- package/bundle/packages/rln/dist/contract/constants.js +33 -0
- package/bundle/packages/rln/dist/contract/rln_contract.js +427 -0
- package/bundle/packages/rln/dist/create.js +9 -0
- package/bundle/packages/rln/dist/identity.js +76 -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 +204 -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 +122 -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/__tests__/identity.test.d.ts +1 -0
- package/dist/__tests__/identity.test.js +40 -0
- package/dist/__tests__/identity.test.js.map +1 -0
- package/dist/codec.d.ts +39 -0
- package/dist/codec.js +77 -0
- package/dist/codec.js.map +1 -0
- package/dist/contract/abi/rlnv2.d.ts +42 -0
- package/dist/contract/abi/rlnv2.js +393 -0
- package/dist/contract/abi/rlnv2.js.map +1 -0
- package/dist/contract/constants.d.ts +68 -0
- package/dist/contract/constants.js +31 -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 +119 -0
- package/dist/contract/rln_contract.js +421 -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 +16 -0
- package/dist/identity.js +73 -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 +164 -81
- 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 +19 -0
- package/dist/zerokit.js +119 -0
- package/dist/zerokit.js.map +1 -0
- package/package.json +1 -126
- package/src/__tests__/identity.test.ts +50 -0
- package/src/codec.ts +134 -0
- package/src/contract/abi/rlnv2.ts +392 -0
- package/src/contract/constants.ts +35 -0
- package/src/contract/index.ts +2 -0
- package/src/contract/rln_contract.ts +673 -0
- package/src/create.ts +9 -0
- package/src/identity.ts +101 -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 +270 -106
- 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 +214 -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/src/message.ts
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
import type {
|
2
|
+
IDecodedMessage,
|
3
|
+
IMessage,
|
4
|
+
IRateLimitProof
|
5
|
+
} from "@waku/interfaces";
|
6
|
+
import * as utils from "@waku/utils/bytes";
|
7
|
+
|
8
|
+
import { RLNInstance } from "./rln.js";
|
9
|
+
import { epochBytesToInt } from "./utils/index.js";
|
10
|
+
|
11
|
+
export function toRLNSignal(contentTopic: string, msg: IMessage): Uint8Array {
|
12
|
+
const contentTopicBytes = utils.utf8ToBytes(contentTopic ?? "");
|
13
|
+
return new Uint8Array([...(msg.payload ?? []), ...contentTopicBytes]);
|
14
|
+
}
|
15
|
+
|
16
|
+
export class RlnMessage<T extends IDecodedMessage> implements IDecodedMessage {
|
17
|
+
public pubsubTopic = "";
|
18
|
+
|
19
|
+
public constructor(
|
20
|
+
public rlnInstance: RLNInstance,
|
21
|
+
public msg: T,
|
22
|
+
public rateLimitProof: IRateLimitProof | undefined
|
23
|
+
) {}
|
24
|
+
|
25
|
+
public verify(roots: Uint8Array[]): boolean | undefined {
|
26
|
+
return this.rateLimitProof
|
27
|
+
? this.rlnInstance.zerokit.verifyWithRoots(
|
28
|
+
this.rateLimitProof,
|
29
|
+
toRLNSignal(this.msg.contentTopic, this.msg),
|
30
|
+
roots
|
31
|
+
) // this.rlnInstance.verifyRLNProof once issue status-im/nwaku#1248 is fixed
|
32
|
+
: undefined;
|
33
|
+
}
|
34
|
+
|
35
|
+
public verifyNoRoot(): boolean | undefined {
|
36
|
+
return this.rateLimitProof
|
37
|
+
? this.rlnInstance.zerokit.verifyWithNoRoot(
|
38
|
+
this.rateLimitProof,
|
39
|
+
toRLNSignal(this.msg.contentTopic, this.msg)
|
40
|
+
) // this.rlnInstance.verifyRLNProof once issue status-im/nwaku#1248 is fixed
|
41
|
+
: undefined;
|
42
|
+
}
|
43
|
+
|
44
|
+
public get payload(): Uint8Array {
|
45
|
+
return this.msg.payload;
|
46
|
+
}
|
47
|
+
|
48
|
+
public get contentTopic(): string {
|
49
|
+
return this.msg.contentTopic;
|
50
|
+
}
|
51
|
+
|
52
|
+
public get timestamp(): Date | undefined {
|
53
|
+
return this.msg.timestamp;
|
54
|
+
}
|
55
|
+
|
56
|
+
public get ephemeral(): boolean | undefined {
|
57
|
+
return this.msg.ephemeral;
|
58
|
+
}
|
59
|
+
|
60
|
+
public get meta(): Uint8Array | undefined {
|
61
|
+
return this.msg.meta;
|
62
|
+
}
|
63
|
+
|
64
|
+
public get epoch(): number | undefined {
|
65
|
+
const bytes = this.rateLimitProof?.epoch;
|
66
|
+
if (!bytes) return undefined;
|
67
|
+
|
68
|
+
return epochBytesToInt(bytes);
|
69
|
+
}
|
70
|
+
}
|
package/src/proof.ts
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
import type { IRateLimitProof } from "@waku/interfaces";
|
2
|
+
|
3
|
+
import { concatenate, poseidonHash } from "./utils/index.js";
|
4
|
+
|
5
|
+
const proofOffset = 128;
|
6
|
+
const rootOffset = proofOffset + 32;
|
7
|
+
const epochOffset = rootOffset + 32;
|
8
|
+
const shareXOffset = epochOffset + 32;
|
9
|
+
const shareYOffset = shareXOffset + 32;
|
10
|
+
const nullifierOffset = shareYOffset + 32;
|
11
|
+
const rlnIdentifierOffset = nullifierOffset + 32;
|
12
|
+
|
13
|
+
class ProofMetadata {
|
14
|
+
public constructor(
|
15
|
+
public readonly nullifier: Uint8Array,
|
16
|
+
public readonly shareX: Uint8Array,
|
17
|
+
public readonly shareY: Uint8Array,
|
18
|
+
public readonly externalNullifier: Uint8Array
|
19
|
+
) {}
|
20
|
+
}
|
21
|
+
|
22
|
+
export class Proof implements IRateLimitProof {
|
23
|
+
public readonly proof: Uint8Array;
|
24
|
+
public readonly merkleRoot: Uint8Array;
|
25
|
+
public readonly epoch: Uint8Array;
|
26
|
+
public readonly shareX: Uint8Array;
|
27
|
+
public readonly shareY: Uint8Array;
|
28
|
+
public readonly nullifier: Uint8Array;
|
29
|
+
public readonly rlnIdentifier: Uint8Array;
|
30
|
+
|
31
|
+
public constructor(proofBytes: Uint8Array) {
|
32
|
+
if (proofBytes.length < rlnIdentifierOffset) {
|
33
|
+
throw new Error("invalid proof");
|
34
|
+
}
|
35
|
+
// parse the proof as proof<128> | share_y<32> | nullifier<32> | root<32> | epoch<32> | share_x<32> | rln_identifier<32>
|
36
|
+
this.proof = proofBytes.subarray(0, proofOffset);
|
37
|
+
this.merkleRoot = proofBytes.subarray(proofOffset, rootOffset);
|
38
|
+
this.epoch = proofBytes.subarray(rootOffset, epochOffset);
|
39
|
+
this.shareX = proofBytes.subarray(epochOffset, shareXOffset);
|
40
|
+
this.shareY = proofBytes.subarray(shareXOffset, shareYOffset);
|
41
|
+
this.nullifier = proofBytes.subarray(shareYOffset, nullifierOffset);
|
42
|
+
this.rlnIdentifier = proofBytes.subarray(
|
43
|
+
nullifierOffset,
|
44
|
+
rlnIdentifierOffset
|
45
|
+
);
|
46
|
+
}
|
47
|
+
|
48
|
+
public extractMetadata(): ProofMetadata {
|
49
|
+
const externalNullifier = poseidonHash(this.epoch, this.rlnIdentifier);
|
50
|
+
return new ProofMetadata(
|
51
|
+
this.nullifier,
|
52
|
+
this.shareX,
|
53
|
+
this.shareY,
|
54
|
+
externalNullifier
|
55
|
+
);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
export function proofToBytes(p: IRateLimitProof): Uint8Array {
|
60
|
+
return concatenate(
|
61
|
+
p.proof,
|
62
|
+
p.merkleRoot,
|
63
|
+
p.epoch,
|
64
|
+
p.shareX,
|
65
|
+
p.shareY,
|
66
|
+
p.nullifier,
|
67
|
+
p.rlnIdentifier
|
68
|
+
);
|
69
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
declare const verificationKey: {
|
2
|
+
protocol: string;
|
3
|
+
curve: string;
|
4
|
+
nPublic: number;
|
5
|
+
vk_alpha_1: string[];
|
6
|
+
vk_beta_2: string[][];
|
7
|
+
vk_gamma_2: string[][];
|
8
|
+
vk_delta_2: string[][];
|
9
|
+
vk_alphabeta_12: string[][][];
|
10
|
+
IC: string[][];
|
11
|
+
};
|
12
|
+
|
13
|
+
export default verificationKey;
|
package/src/rln.ts
CHANGED
@@ -1,136 +1,300 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
|
1
|
+
import { createDecoder, createEncoder } from "@waku/core";
|
2
|
+
import type {
|
3
|
+
ContentTopic,
|
4
|
+
IDecodedMessage,
|
5
|
+
EncoderOptions as WakuEncoderOptions
|
6
|
+
} from "@waku/interfaces";
|
7
|
+
import { Logger } from "@waku/utils";
|
8
|
+
import init from "@waku/zerokit-rln-wasm";
|
9
|
+
import * as zerokitRLN from "@waku/zerokit-rln-wasm";
|
10
|
+
import { ethers } from "ethers";
|
4
11
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
}
|
12
|
+
import {
|
13
|
+
createRLNDecoder,
|
14
|
+
createRLNEncoder,
|
15
|
+
type RLNDecoder,
|
16
|
+
type RLNEncoder
|
17
|
+
} from "./codec.js";
|
18
|
+
import { RLNContract, SEPOLIA_CONTRACT } from "./contract/index.js";
|
19
|
+
import { IdentityCredential } from "./identity.js";
|
20
|
+
import { Keystore } from "./keystore/index.js";
|
21
|
+
import type {
|
22
|
+
DecryptedCredentials,
|
23
|
+
EncryptedCredentials
|
24
|
+
} from "./keystore/index.js";
|
25
|
+
import { KeystoreEntity, Password } from "./keystore/types.js";
|
26
|
+
import verificationKey from "./resources/verification_key";
|
27
|
+
import * as wc from "./resources/witness_calculator";
|
28
|
+
import { WitnessCalculator } from "./resources/witness_calculator";
|
29
|
+
import { extractMetaMaskSigner } from "./utils/index.js";
|
30
|
+
import { Zerokit } from "./zerokit.js";
|
19
31
|
|
20
|
-
|
21
|
-
* Concatenate Uint8Arrays
|
22
|
-
* @param input
|
23
|
-
* @returns concatenation of all Uint8Array received as input
|
24
|
-
*/
|
25
|
-
function concatenate(...input: Uint8Array[]): Uint8Array {
|
26
|
-
let totalLength = 0;
|
27
|
-
for (const arr of input) {
|
28
|
-
totalLength += arr.length;
|
29
|
-
}
|
30
|
-
const result = new Uint8Array(totalLength);
|
31
|
-
let offset = 0;
|
32
|
-
for (const arr of input) {
|
33
|
-
result.set(arr, offset);
|
34
|
-
offset += arr.length;
|
35
|
-
}
|
36
|
-
return result;
|
37
|
-
}
|
32
|
+
const log = new Logger("waku:rln");
|
38
33
|
|
39
|
-
|
40
|
-
const
|
41
|
-
const
|
42
|
-
|
34
|
+
async function loadWitnessCalculator(): Promise<WitnessCalculator> {
|
35
|
+
const url = new URL("./resources/rln.wasm", import.meta.url);
|
36
|
+
const response = await fetch(url);
|
37
|
+
return await wc.builder(new Uint8Array(await response.arrayBuffer()), false);
|
38
|
+
}
|
43
39
|
|
44
|
-
|
40
|
+
async function loadZkey(): Promise<Uint8Array> {
|
41
|
+
const url = new URL("./resources/rln_final.zkey", import.meta.url);
|
42
|
+
const response = await fetch(url);
|
43
|
+
return new Uint8Array(await response.arrayBuffer());
|
44
|
+
}
|
45
45
|
|
46
46
|
/**
|
47
47
|
* Create an instance of RLN
|
48
48
|
* @returns RLNInstance
|
49
49
|
*/
|
50
50
|
export async function create(): Promise<RLNInstance> {
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
try {
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
53
|
+
await (init as any)?.();
|
54
|
+
zerokitRLN.init_panic_hook();
|
55
|
+
|
56
|
+
const witnessCalculator = await loadWitnessCalculator();
|
57
|
+
const zkey = await loadZkey();
|
55
58
|
|
56
|
-
|
57
|
-
|
58
|
-
readonly IDCommitment: Uint8Array;
|
59
|
+
const stringEncoder = new TextEncoder();
|
60
|
+
const vkey = stringEncoder.encode(JSON.stringify(verificationKey));
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
|
62
|
+
const DEPTH = 20;
|
63
|
+
const zkRLN = zerokitRLN.newRLN(DEPTH, zkey, vkey);
|
64
|
+
const zerokit = new Zerokit(zkRLN, witnessCalculator);
|
65
|
+
|
66
|
+
return new RLNInstance(zerokit);
|
67
|
+
} catch (error) {
|
68
|
+
log.error("Failed to initialize RLN:", error);
|
69
|
+
throw error;
|
63
70
|
}
|
64
71
|
}
|
65
72
|
|
73
|
+
type StartRLNOptions = {
|
74
|
+
/**
|
75
|
+
* If not set - will extract MetaMask account and get signer from it.
|
76
|
+
*/
|
77
|
+
signer?: ethers.Signer;
|
78
|
+
/**
|
79
|
+
* If not set - will use default SEPOLIA_CONTRACT address.
|
80
|
+
*/
|
81
|
+
address?: string;
|
82
|
+
/**
|
83
|
+
* Credentials to use for generating proofs and connecting to the contract and network.
|
84
|
+
* If provided used for validating the network chainId and connecting to registry contract.
|
85
|
+
*/
|
86
|
+
credentials?: EncryptedCredentials | DecryptedCredentials;
|
87
|
+
/**
|
88
|
+
* Rate limit for the member.
|
89
|
+
*/
|
90
|
+
rateLimit?: number;
|
91
|
+
};
|
92
|
+
|
93
|
+
type RegisterMembershipOptions =
|
94
|
+
| { signature: string }
|
95
|
+
| { identity: IdentityCredential };
|
96
|
+
|
97
|
+
type WakuRLNEncoderOptions = WakuEncoderOptions & {
|
98
|
+
credentials: EncryptedCredentials | DecryptedCredentials;
|
99
|
+
};
|
100
|
+
|
66
101
|
export class RLNInstance {
|
67
|
-
|
68
|
-
|
102
|
+
private started = false;
|
103
|
+
private starting = false;
|
104
|
+
|
105
|
+
private _contract: undefined | RLNContract;
|
106
|
+
private _signer: undefined | ethers.Signer;
|
107
|
+
|
108
|
+
private keystore = Keystore.create();
|
109
|
+
private _credentials: undefined | DecryptedCredentials;
|
110
|
+
|
111
|
+
public constructor(public zerokit: Zerokit) {}
|
69
112
|
|
70
|
-
|
71
|
-
this.
|
72
|
-
this.witnessCalculator = wc;
|
113
|
+
public get contract(): undefined | RLNContract {
|
114
|
+
return this._contract;
|
73
115
|
}
|
74
116
|
|
75
|
-
|
76
|
-
|
77
|
-
return new MembershipKey(memKeys);
|
117
|
+
public get signer(): undefined | ethers.Signer {
|
118
|
+
return this._signer;
|
78
119
|
}
|
79
120
|
|
80
|
-
|
81
|
-
|
121
|
+
public async start(options: StartRLNOptions = {}): Promise<void> {
|
122
|
+
if (this.started || this.starting) {
|
123
|
+
return;
|
124
|
+
}
|
125
|
+
|
126
|
+
this.starting = true;
|
127
|
+
|
128
|
+
try {
|
129
|
+
const { credentials, keystore } =
|
130
|
+
await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
|
131
|
+
const { signer, address } = await this.determineStartOptions(
|
132
|
+
options,
|
133
|
+
credentials
|
134
|
+
);
|
135
|
+
|
136
|
+
if (keystore) {
|
137
|
+
this.keystore = keystore;
|
138
|
+
}
|
139
|
+
|
140
|
+
this._credentials = credentials;
|
141
|
+
this._signer = signer!;
|
142
|
+
this._contract = await RLNContract.init(this, {
|
143
|
+
address: address!,
|
144
|
+
signer: signer!,
|
145
|
+
rateLimit: options.rateLimit
|
146
|
+
});
|
147
|
+
this.started = true;
|
148
|
+
} finally {
|
149
|
+
this.starting = false;
|
150
|
+
}
|
82
151
|
}
|
83
152
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
const
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
153
|
+
private async determineStartOptions(
|
154
|
+
options: StartRLNOptions,
|
155
|
+
credentials: KeystoreEntity | undefined
|
156
|
+
): Promise<StartRLNOptions> {
|
157
|
+
let chainId = credentials?.membership.chainId;
|
158
|
+
const address =
|
159
|
+
credentials?.membership.address ||
|
160
|
+
options.address ||
|
161
|
+
SEPOLIA_CONTRACT.address;
|
162
|
+
|
163
|
+
if (address === SEPOLIA_CONTRACT.address) {
|
164
|
+
chainId = SEPOLIA_CONTRACT.chainId;
|
165
|
+
}
|
166
|
+
|
167
|
+
const signer = options.signer || (await extractMetaMaskSigner());
|
168
|
+
const currentChainId = await signer.getChainId();
|
169
|
+
|
170
|
+
if (chainId && chainId !== currentChainId) {
|
171
|
+
throw Error(
|
172
|
+
`Failed to start RLN contract, chain ID of contract is different from current one: contract-${chainId}, current network-${currentChainId}`
|
173
|
+
);
|
174
|
+
}
|
175
|
+
|
176
|
+
return {
|
177
|
+
signer,
|
178
|
+
address
|
179
|
+
};
|
103
180
|
}
|
104
181
|
|
105
|
-
async
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
if (
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
const
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
return zerokitRLN.generate_rln_proof_with_witness(
|
127
|
-
this.zkRLN,
|
128
|
-
calculatedWitness,
|
129
|
-
rlnWitness
|
182
|
+
private static async decryptCredentialsIfNeeded(
|
183
|
+
credentials?: EncryptedCredentials | DecryptedCredentials
|
184
|
+
): Promise<{ credentials?: DecryptedCredentials; keystore?: Keystore }> {
|
185
|
+
if (!credentials) {
|
186
|
+
return {};
|
187
|
+
}
|
188
|
+
|
189
|
+
if ("identity" in credentials) {
|
190
|
+
return { credentials };
|
191
|
+
}
|
192
|
+
|
193
|
+
const keystore = Keystore.fromString(credentials.keystore);
|
194
|
+
|
195
|
+
if (!keystore) {
|
196
|
+
return {};
|
197
|
+
}
|
198
|
+
|
199
|
+
const decryptedCredentials = await keystore.readCredential(
|
200
|
+
credentials.id,
|
201
|
+
credentials.password
|
130
202
|
);
|
203
|
+
|
204
|
+
return {
|
205
|
+
keystore,
|
206
|
+
credentials: decryptedCredentials
|
207
|
+
};
|
208
|
+
}
|
209
|
+
|
210
|
+
public async registerMembership(
|
211
|
+
options: RegisterMembershipOptions
|
212
|
+
): Promise<undefined | DecryptedCredentials> {
|
213
|
+
if (!this.contract) {
|
214
|
+
throw Error("RLN Contract is not initialized.");
|
215
|
+
}
|
216
|
+
|
217
|
+
let identity: IdentityCredential | undefined =
|
218
|
+
"identity" in options ? options.identity : undefined;
|
219
|
+
|
220
|
+
if ("signature" in options) {
|
221
|
+
identity = IdentityCredential.generateSeeded(
|
222
|
+
ethers.utils.arrayify(options.signature)
|
223
|
+
);
|
224
|
+
}
|
225
|
+
|
226
|
+
if (!identity) {
|
227
|
+
throw Error("Missing signature or identity to register membership.");
|
228
|
+
}
|
229
|
+
|
230
|
+
return this.contract.registerWithIdentity(identity);
|
231
|
+
}
|
232
|
+
|
233
|
+
/**
|
234
|
+
* Changes credentials in use by relying on provided Keystore earlier in rln.start
|
235
|
+
* @param id: string, hash of credentials to select from Keystore
|
236
|
+
* @param password: string or bytes to use to decrypt credentials from Keystore
|
237
|
+
*/
|
238
|
+
public async useCredentials(id: string, password: Password): Promise<void> {
|
239
|
+
this._credentials = await this.keystore?.readCredential(id, password);
|
240
|
+
}
|
241
|
+
|
242
|
+
public async createEncoder(
|
243
|
+
options: WakuRLNEncoderOptions
|
244
|
+
): Promise<RLNEncoder> {
|
245
|
+
const { credentials: decryptedCredentials } =
|
246
|
+
await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
|
247
|
+
const credentials = decryptedCredentials || this._credentials;
|
248
|
+
|
249
|
+
if (!credentials) {
|
250
|
+
throw Error(
|
251
|
+
"Failed to create Encoder: missing RLN credentials. Use createRLNEncoder directly."
|
252
|
+
);
|
253
|
+
}
|
254
|
+
|
255
|
+
await this.verifyCredentialsAgainstContract(credentials);
|
256
|
+
|
257
|
+
return createRLNEncoder({
|
258
|
+
encoder: createEncoder(options),
|
259
|
+
rlnInstance: this,
|
260
|
+
index: credentials.membership.treeIndex,
|
261
|
+
credential: credentials.identity
|
262
|
+
});
|
263
|
+
}
|
264
|
+
|
265
|
+
private async verifyCredentialsAgainstContract(
|
266
|
+
credentials: KeystoreEntity
|
267
|
+
): Promise<void> {
|
268
|
+
if (!this._contract) {
|
269
|
+
throw Error(
|
270
|
+
"Failed to verify chain coordinates: no contract initialized."
|
271
|
+
);
|
272
|
+
}
|
273
|
+
|
274
|
+
const registryAddress = credentials.membership.address;
|
275
|
+
const currentRegistryAddress = this._contract.contract.address;
|
276
|
+
if (registryAddress !== currentRegistryAddress) {
|
277
|
+
throw Error(
|
278
|
+
`Failed to verify chain coordinates: credentials contract address=${registryAddress} is not equal to registryContract address=${currentRegistryAddress}`
|
279
|
+
);
|
280
|
+
}
|
281
|
+
|
282
|
+
const chainId = credentials.membership.chainId;
|
283
|
+
const network = await this._contract.contract.provider.getNetwork();
|
284
|
+
const currentChainId = network.chainId;
|
285
|
+
if (chainId !== currentChainId) {
|
286
|
+
throw Error(
|
287
|
+
`Failed to verify chain coordinates: credentials chainID=${chainId} is not equal to registryContract chainID=${currentChainId}`
|
288
|
+
);
|
289
|
+
}
|
131
290
|
}
|
132
291
|
|
133
|
-
|
134
|
-
|
292
|
+
public createDecoder(
|
293
|
+
contentTopic: ContentTopic
|
294
|
+
): RLNDecoder<IDecodedMessage> {
|
295
|
+
return createRLNDecoder({
|
296
|
+
rlnInstance: this,
|
297
|
+
decoder: createDecoder(contentTopic)
|
298
|
+
});
|
135
299
|
}
|
136
300
|
}
|
@@ -0,0 +1,92 @@
|
|
1
|
+
class RootPerBlock {
|
2
|
+
public constructor(
|
3
|
+
public root: Uint8Array,
|
4
|
+
public blockNumber: number
|
5
|
+
) {}
|
6
|
+
}
|
7
|
+
|
8
|
+
const maxBufferSize = 20;
|
9
|
+
|
10
|
+
export class MerkleRootTracker {
|
11
|
+
private validMerkleRoots: Array<RootPerBlock> = new Array<RootPerBlock>();
|
12
|
+
private merkleRootBuffer: Array<RootPerBlock> = new Array<RootPerBlock>();
|
13
|
+
|
14
|
+
public constructor(
|
15
|
+
private acceptableRootWindowSize: number,
|
16
|
+
initialRoot: Uint8Array
|
17
|
+
) {
|
18
|
+
this.pushRoot(0, initialRoot);
|
19
|
+
}
|
20
|
+
|
21
|
+
public backFill(fromBlockNumber: number): void {
|
22
|
+
if (this.validMerkleRoots.length == 0) return;
|
23
|
+
|
24
|
+
let numBlocks = 0;
|
25
|
+
for (let i = this.validMerkleRoots.length - 1; i >= 0; i--) {
|
26
|
+
if (this.validMerkleRoots[i].blockNumber >= fromBlockNumber) {
|
27
|
+
numBlocks++;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
if (numBlocks == 0) return;
|
32
|
+
|
33
|
+
const olderBlock = fromBlockNumber < this.validMerkleRoots[0].blockNumber;
|
34
|
+
|
35
|
+
// Remove last roots
|
36
|
+
let rootsToPop = numBlocks;
|
37
|
+
if (this.validMerkleRoots.length < rootsToPop) {
|
38
|
+
rootsToPop = this.validMerkleRoots.length;
|
39
|
+
}
|
40
|
+
|
41
|
+
this.validMerkleRoots = this.validMerkleRoots.slice(
|
42
|
+
0,
|
43
|
+
this.validMerkleRoots.length - rootsToPop
|
44
|
+
);
|
45
|
+
|
46
|
+
if (this.merkleRootBuffer.length == 0) return;
|
47
|
+
|
48
|
+
if (olderBlock) {
|
49
|
+
const idx = this.merkleRootBuffer.findIndex(
|
50
|
+
(x) => x.blockNumber == fromBlockNumber
|
51
|
+
);
|
52
|
+
if (idx > -1) {
|
53
|
+
this.merkleRootBuffer = this.merkleRootBuffer.slice(0, idx);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
// Backfill the tree's acceptable roots
|
58
|
+
let rootsToRestore =
|
59
|
+
this.acceptableRootWindowSize - this.validMerkleRoots.length;
|
60
|
+
if (this.merkleRootBuffer.length < rootsToRestore) {
|
61
|
+
rootsToRestore = this.merkleRootBuffer.length;
|
62
|
+
}
|
63
|
+
|
64
|
+
for (let i = 0; i < rootsToRestore; i++) {
|
65
|
+
const x = this.merkleRootBuffer.pop();
|
66
|
+
if (x) this.validMerkleRoots.unshift(x);
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
public pushRoot(blockNumber: number, root: Uint8Array): void {
|
71
|
+
this.validMerkleRoots.push(new RootPerBlock(root, blockNumber));
|
72
|
+
|
73
|
+
// Maintain valid merkle root window
|
74
|
+
if (this.validMerkleRoots.length > this.acceptableRootWindowSize) {
|
75
|
+
const x = this.validMerkleRoots.shift();
|
76
|
+
if (x) this.merkleRootBuffer.push(x);
|
77
|
+
}
|
78
|
+
|
79
|
+
// Maintain merkle root buffer
|
80
|
+
if (this.merkleRootBuffer.length > maxBufferSize) {
|
81
|
+
this.merkleRootBuffer.shift();
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
public roots(): Array<Uint8Array> {
|
86
|
+
return this.validMerkleRoots.map((x) => x.root);
|
87
|
+
}
|
88
|
+
|
89
|
+
public buffer(): Array<Uint8Array> {
|
90
|
+
return this.merkleRootBuffer.map((x) => x.root);
|
91
|
+
}
|
92
|
+
}
|