@waku/rln 0.1.3-f6d5deb → 0.1.4-2a94244.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -186
- package/bundle/_virtual/__node-resolve_empty.js +6 -0
- package/bundle/_virtual/_assert.js +3 -0
- package/bundle/_virtual/_commonjs-dynamic-modules.js +5 -0
- package/bundle/_virtual/_commonjsHelpers.js +32 -0
- package/bundle/_virtual/_node-resolve_empty.js +3 -0
- package/bundle/_virtual/_sha2.js +3 -0
- package/bundle/_virtual/_u64.js +3 -0
- package/bundle/_virtual/aes.js +3 -0
- package/bundle/_virtual/bn.js +3 -0
- package/bundle/_virtual/browser.js +3 -0
- package/bundle/_virtual/checksum.js +3 -0
- package/bundle/_virtual/cipher.js +3 -0
- package/bundle/_virtual/class.js +3 -0
- package/bundle/_virtual/common.js +3 -0
- package/bundle/_virtual/common2.js +3 -0
- package/bundle/_virtual/cryptoBrowser.js +3 -0
- package/bundle/_virtual/functional.js +3 -0
- package/bundle/_virtual/hash.js +3 -0
- package/bundle/_virtual/hmac.js +3 -0
- package/bundle/_virtual/index.js +3 -0
- package/bundle/_virtual/index2.js +6 -0
- package/bundle/_virtual/inherits_browser.js +3 -0
- package/bundle/_virtual/kdf.js +3 -0
- package/bundle/_virtual/lodash.js +3 -0
- package/bundle/_virtual/password.js +3 -0
- package/bundle/_virtual/pbkdf2.js +3 -0
- package/bundle/_virtual/pbkdf22.js +3 -0
- package/bundle/_virtual/random.js +3 -0
- package/bundle/_virtual/ripemd.js +3 -0
- package/bundle/_virtual/schema-validation-generated.js +3 -0
- package/bundle/_virtual/schema-validation.js +3 -0
- package/bundle/_virtual/scrypt.js +3 -0
- package/bundle/_virtual/scrypt2.js +3 -0
- package/bundle/_virtual/sha.js +3 -0
- package/bundle/_virtual/sha256.js +3 -0
- package/bundle/_virtual/sha2562.js +3 -0
- package/bundle/_virtual/sha3.js +3 -0
- package/bundle/_virtual/sha512.js +3 -0
- package/bundle/_virtual/types.js +3 -0
- package/bundle/_virtual/utils.js +3 -0
- package/bundle/_virtual/utils2.js +3 -0
- package/bundle/_virtual/utils3.js +3 -0
- package/bundle/index.js +12 -74804
- package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +96 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +148 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +20 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +210 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +18 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +30 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +22 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +43 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +19 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +58 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +854 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +609 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +66 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +302 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +110 -0
- package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +20 -0
- package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +287 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +402 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +3 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +8 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +893 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +256 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +36 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +135 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +8 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +64 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +443 -0
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +8 -0
- package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +660 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +352 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +248 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +127 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +2007 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +422 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +674 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +132 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +8 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +2430 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +76 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +219 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +279 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +69 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +404 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +15 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +20 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +92 -0
- package/bundle/node_modules/@noble/hashes/esm/_assert.js +37 -0
- package/bundle/node_modules/@noble/hashes/esm/_md.js +132 -0
- package/bundle/node_modules/@noble/hashes/esm/_u64.js +29 -0
- package/bundle/node_modules/@noble/hashes/esm/sha256.js +113 -0
- package/bundle/node_modules/@noble/hashes/esm/sha3.js +210 -0
- package/bundle/node_modules/@noble/hashes/esm/utils.js +144 -0
- package/bundle/node_modules/@waku/zerokit-rln-wasm/rln_wasm.js +756 -0
- package/bundle/node_modules/bech32/index.js +187 -0
- package/bundle/node_modules/bn.js/lib/bn.js +3361 -0
- package/bundle/node_modules/debug/src/browser.js +283 -0
- package/bundle/node_modules/debug/src/common.js +295 -0
- package/bundle/node_modules/ethereum-cryptography/esm/keccak.js +10 -0
- package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +6 -0
- package/bundle/node_modules/ethereum-cryptography/esm/utils.js +24 -0
- package/bundle/node_modules/hash.js/lib/hash/common.js +97 -0
- package/bundle/node_modules/hash.js/lib/hash/hmac.js +51 -0
- package/bundle/node_modules/hash.js/lib/hash/ripemd.js +152 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/1.js +81 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/224.js +33 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/256.js +113 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/384.js +39 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/512.js +336 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/common.js +53 -0
- package/bundle/node_modules/hash.js/lib/hash/sha.js +14 -0
- package/bundle/node_modules/hash.js/lib/hash/utils.js +282 -0
- package/bundle/node_modules/hash.js/lib/hash.js +33 -0
- package/bundle/node_modules/inherits/inherits_browser.js +33 -0
- package/bundle/node_modules/it-length-prefixed/dist/src/decode.js +6 -0
- package/bundle/node_modules/lodash/lodash.js +17207 -0
- package/bundle/node_modules/minimalistic-assert/index.js +13 -0
- package/bundle/node_modules/ms/index.js +172 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base.js +205 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base10.js +9 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base16.js +16 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base2.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base256emoji.js +41 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base32.js +58 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base36.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base58.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base64.js +28 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base8.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/identity.js +11 -0
- package/bundle/node_modules/multiformats/dist/src/basics.js +15 -0
- package/bundle/node_modules/multiformats/dist/src/bytes.js +18 -0
- package/bundle/node_modules/multiformats/dist/src/codecs/json.js +2 -0
- package/bundle/node_modules/multiformats/dist/src/vendor/base-x.js +170 -0
- package/bundle/node_modules/protons-runtime/dist/src/codec.js +20 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/enum.js +24 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/message.js +7 -0
- package/bundle/node_modules/protons-runtime/dist/src/decode.js +8 -0
- package/bundle/node_modules/protons-runtime/dist/src/encode.js +11 -0
- package/bundle/node_modules/protons-runtime/dist/src/index.js +30 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/float.js +54 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/longbits.js +175 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/pool.js +28 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/reader.js +367 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/utf8.js +99 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/writer.js +438 -0
- package/bundle/node_modules/uint8-varint/dist/src/index.js +124 -0
- package/bundle/node_modules/uint8arrays/dist/src/alloc.js +17 -0
- package/bundle/node_modules/uint8arrays/dist/src/from-string.js +19 -0
- package/bundle/node_modules/uint8arrays/dist/src/util/bases.js +49 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +21 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +18 -0
- package/bundle/packages/core/dist/lib/filter/filter.js +27 -0
- package/bundle/packages/core/dist/lib/light_push/light_push.js +27 -0
- package/bundle/packages/core/dist/lib/message/version_0.js +154 -0
- package/bundle/packages/core/dist/lib/metadata/metadata.js +27 -0
- package/bundle/packages/core/dist/lib/store/store.js +27 -0
- package/bundle/packages/interfaces/dist/connection_manager.js +19 -0
- package/bundle/packages/interfaces/dist/constants.js +6 -0
- package/bundle/packages/interfaces/dist/health_indicator.js +12 -0
- package/bundle/packages/interfaces/dist/protocols.js +92 -0
- package/bundle/packages/proto/dist/generated/filter.js +445 -0
- package/bundle/packages/proto/dist/generated/filter_v2.js +424 -0
- package/bundle/packages/proto/dist/generated/light_push.js +389 -0
- package/bundle/packages/proto/dist/generated/message.js +213 -0
- package/bundle/packages/proto/dist/generated/metadata.js +130 -0
- package/bundle/packages/proto/dist/generated/peer_exchange.js +209 -0
- package/bundle/packages/proto/dist/generated/sds_message.js +105 -0
- package/bundle/packages/proto/dist/generated/store_v3.js +490 -0
- package/bundle/packages/proto/dist/generated/topic_only_message.js +61 -0
- package/bundle/packages/rln/dist/codec.js +93 -0
- package/bundle/packages/rln/dist/contract/abi.js +394 -0
- package/bundle/packages/rln/dist/contract/constants.js +27 -0
- package/bundle/packages/rln/dist/contract/rln_contract.js +438 -0
- package/bundle/packages/rln/dist/create.js +9 -0
- package/bundle/packages/rln/dist/identity.js +30 -0
- package/bundle/packages/rln/dist/keystore/cipher.js +31 -0
- package/bundle/packages/rln/dist/keystore/credential_validation_generated.js +119 -0
- package/bundle/packages/rln/dist/keystore/keystore.js +223 -0
- package/bundle/packages/rln/dist/keystore/keystore_validation_generated.js +74 -0
- package/bundle/packages/rln/dist/keystore/schema_validator.js +20 -0
- package/bundle/packages/rln/dist/message.js +51 -0
- package/bundle/packages/rln/dist/proof.js +54 -0
- package/bundle/packages/rln/dist/resources/verification_key.js +112 -0
- package/bundle/packages/rln/dist/resources/witness_calculator.js +330 -0
- package/bundle/packages/rln/dist/rln.js +220 -0
- package/bundle/packages/rln/dist/root_tracker.js +76 -0
- package/bundle/packages/rln/dist/utils/bytes.js +65 -0
- package/bundle/packages/rln/dist/utils/epoch.js +39 -0
- package/bundle/packages/rln/dist/utils/hash.js +10 -0
- package/bundle/packages/rln/dist/utils/metamask.js +14 -0
- package/bundle/packages/rln/dist/zerokit.js +128 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +52 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +65 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +99 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/index.js +28 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +78 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1253 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +40 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/types.js +5 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +41 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +23 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +12 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +77 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +9 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +215 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +35 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +21 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +66 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +24 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +7 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +11 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +52 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +124 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +71 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +10 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +88 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +99 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +233 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +133 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +243 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +167 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/native.js +4 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/rng.js +13 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/stringify.js +28 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/v4.js +19 -0
- package/bundle/packages/utils/dist/bytes/index.js +44 -0
- package/bundle/packages/utils/dist/common/sharding/index.js +91 -0
- package/bundle/packages/utils/dist/logger/index.js +31 -0
- package/bundle/resources/verification_key.d.ts +13 -0
- package/bundle/resources/verification_key.js +112 -0
- package/bundle/resources/witness_calculator.d.ts +11 -0
- package/bundle/resources/witness_calculator.js +328 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/codec.d.ts +5 -5
- package/dist/codec.js +6 -6
- package/dist/codec.js.map +1 -1
- package/dist/contract/abi.d.ts +42 -0
- package/dist/contract/abi.js +393 -0
- package/dist/contract/abi.js.map +1 -0
- package/dist/contract/constants.d.ts +59 -3
- package/dist/contract/constants.js +21 -63
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_contract.d.ts +98 -17
- package/dist/contract/rln_contract.js +292 -71
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/identity.js +5 -2
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/keystore/cipher.js +3 -3
- package/dist/keystore/cipher.js.map +1 -1
- package/dist/keystore/credential_validation_generated.js.map +1 -1
- package/dist/keystore/keystore.js +4 -4
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/keystore_validation_generated.js.map +1 -1
- package/dist/message.js +3 -3
- package/dist/message.js.map +1 -1
- package/dist/proof.js +3 -2
- package/dist/proof.js.map +1 -1
- package/dist/resources/verification_key.d.ts +12 -11
- package/dist/resources/verification_key.js +103 -103
- package/dist/resources/witness_calculator.d.ts +10 -15
- package/dist/resources/witness_calculator.js +302 -265
- package/dist/rln.d.ts +5 -1
- package/dist/rln.js +56 -28
- package/dist/rln.js.map +1 -1
- package/dist/root_tracker.js.map +1 -1
- package/dist/utils/epoch.js +5 -5
- package/dist/utils/epoch.js.map +1 -1
- package/dist/zerokit.d.ts +13 -9
- package/dist/zerokit.js +40 -20
- package/dist/zerokit.js.map +1 -1
- package/package.json +1 -146
- package/src/codec.ts +26 -22
- package/src/contract/abi.ts +392 -0
- package/src/contract/constants.ts +28 -0
- package/src/contract/index.ts +2 -0
- package/src/contract/rln_contract.ts +686 -0
- package/src/identity.ts +8 -4
- package/src/index.ts +4 -9
- package/src/keystore/cipher.ts +54 -0
- package/src/keystore/credential_validation_generated.ts +7 -0
- package/src/keystore/index.ts +5 -0
- package/src/keystore/keystore.ts +330 -0
- package/src/keystore/keystore_validation_generated.ts +7 -0
- package/src/keystore/schema_validator.ts +34 -0
- package/src/keystore/types.ts +36 -0
- package/src/message.ts +10 -10
- package/src/proof.ts +13 -11
- package/src/resources/verification_key.d.ts +13 -0
- package/src/resources/witness_calculator.d.ts +11 -0
- package/src/rln.ts +76 -31
- package/src/root_tracker.ts +7 -6
- package/src/utils/bytes.ts +84 -0
- package/src/utils/epoch.ts +30 -0
- package/src/utils/hash.ts +15 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/metamask.ts +17 -0
- package/src/zerokit.ts +95 -33
- package/bundle/assets/rln_wasm_bg-a503e304.wasm +0 -0
- package/dist/resources/verification_key.js.map +0 -1
- package/dist/resources/witness_calculator.js.map +0 -1
- /package/bundle/{assets/rln-6ded2896.wasm → resources/rln.wasm} +0 -0
- /package/bundle/{assets/rln_final-8b299152.zkey → resources/rln_final.zkey} +0 -0
@@ -0,0 +1,330 @@
|
|
1
|
+
// File generated with https://github.com/iden3/circom
|
2
|
+
// following the instructions from:
|
3
|
+
// https://github.com/vacp2p/zerokit/tree/master/rln#compiling-circuits
|
4
|
+
|
5
|
+
async function builder(code, options) {
|
6
|
+
options = options || {};
|
7
|
+
|
8
|
+
let wasmModule;
|
9
|
+
try {
|
10
|
+
wasmModule = await WebAssembly.compile(code);
|
11
|
+
} catch (err) {
|
12
|
+
console.log(err);
|
13
|
+
console.log(
|
14
|
+
"\nTry to run circom --c in order to generate c++ code instead\n"
|
15
|
+
);
|
16
|
+
throw new Error(err);
|
17
|
+
}
|
18
|
+
|
19
|
+
let wc;
|
20
|
+
|
21
|
+
let errStr = "";
|
22
|
+
let msgStr = "";
|
23
|
+
|
24
|
+
const instance = await WebAssembly.instantiate(wasmModule, {
|
25
|
+
runtime: {
|
26
|
+
exceptionHandler: function (code) {
|
27
|
+
let err;
|
28
|
+
if (code == 1) {
|
29
|
+
err = "Signal not found.\n";
|
30
|
+
} else if (code == 2) {
|
31
|
+
err = "Too many signals set.\n";
|
32
|
+
} else if (code == 3) {
|
33
|
+
err = "Signal already set.\n";
|
34
|
+
} else if (code == 4) {
|
35
|
+
err = "Assert Failed.\n";
|
36
|
+
} else if (code == 5) {
|
37
|
+
err = "Not enough memory.\n";
|
38
|
+
} else if (code == 6) {
|
39
|
+
err = "Input signal array access exceeds the size.\n";
|
40
|
+
} else {
|
41
|
+
err = "Unknown error.\n";
|
42
|
+
}
|
43
|
+
throw new Error(err + errStr);
|
44
|
+
},
|
45
|
+
printErrorMessage: function () {
|
46
|
+
errStr += getMessage() + "\n";
|
47
|
+
// console.error(getMessage());
|
48
|
+
},
|
49
|
+
writeBufferMessage: function () {
|
50
|
+
const msg = getMessage();
|
51
|
+
// Any calls to `log()` will always end with a `\n`, so that's when we print and reset
|
52
|
+
if (msg === "\n") {
|
53
|
+
console.log(msgStr);
|
54
|
+
msgStr = "";
|
55
|
+
} else {
|
56
|
+
// If we've buffered other content, put a space in between the items
|
57
|
+
if (msgStr !== "") {
|
58
|
+
msgStr += " ";
|
59
|
+
}
|
60
|
+
// Then append the message to the message we are creating
|
61
|
+
msgStr += msg;
|
62
|
+
}
|
63
|
+
},
|
64
|
+
showSharedRWMemory: function () {
|
65
|
+
printSharedRWMemory();
|
66
|
+
}
|
67
|
+
}
|
68
|
+
});
|
69
|
+
|
70
|
+
const sanityCheck = options;
|
71
|
+
// options &&
|
72
|
+
// (
|
73
|
+
// options.sanityCheck ||
|
74
|
+
// options.logGetSignal ||
|
75
|
+
// options.logSetSignal ||
|
76
|
+
// options.logStartComponent ||
|
77
|
+
// options.logFinishComponent
|
78
|
+
// );
|
79
|
+
|
80
|
+
wc = new WitnessCalculator(instance, sanityCheck);
|
81
|
+
return wc;
|
82
|
+
|
83
|
+
function getMessage() {
|
84
|
+
var message = "";
|
85
|
+
var c = instance.exports.getMessageChar();
|
86
|
+
while (c != 0) {
|
87
|
+
message += String.fromCharCode(c);
|
88
|
+
c = instance.exports.getMessageChar();
|
89
|
+
}
|
90
|
+
return message;
|
91
|
+
}
|
92
|
+
|
93
|
+
function printSharedRWMemory() {
|
94
|
+
const shared_rw_memory_size = instance.exports.getFieldNumLen32();
|
95
|
+
const arr = new Uint32Array(shared_rw_memory_size);
|
96
|
+
for (let j = 0; j < shared_rw_memory_size; j++) {
|
97
|
+
arr[shared_rw_memory_size - 1 - j] =
|
98
|
+
instance.exports.readSharedRWMemory(j);
|
99
|
+
}
|
100
|
+
|
101
|
+
// If we've buffered other content, put a space in between the items
|
102
|
+
if (msgStr !== "") {
|
103
|
+
msgStr += " ";
|
104
|
+
}
|
105
|
+
// Then append the value to the message we are creating
|
106
|
+
msgStr += fromArray32(arr).toString();
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
class WitnessCalculator {
|
111
|
+
constructor(instance, sanityCheck) {
|
112
|
+
this.instance = instance;
|
113
|
+
|
114
|
+
this.version = this.instance.exports.getVersion();
|
115
|
+
this.n32 = this.instance.exports.getFieldNumLen32();
|
116
|
+
|
117
|
+
this.instance.exports.getRawPrime();
|
118
|
+
const arr = new Uint32Array(this.n32);
|
119
|
+
for (let i = 0; i < this.n32; i++) {
|
120
|
+
arr[this.n32 - 1 - i] = this.instance.exports.readSharedRWMemory(i);
|
121
|
+
}
|
122
|
+
this.prime = fromArray32(arr);
|
123
|
+
|
124
|
+
this.witnessSize = this.instance.exports.getWitnessSize();
|
125
|
+
|
126
|
+
this.sanityCheck = sanityCheck;
|
127
|
+
}
|
128
|
+
|
129
|
+
circom_version() {
|
130
|
+
return this.instance.exports.getVersion();
|
131
|
+
}
|
132
|
+
|
133
|
+
async _doCalculateWitness(input, sanityCheck) {
|
134
|
+
//input is assumed to be a map from signals to arrays of bigints
|
135
|
+
this.instance.exports.init(this.sanityCheck || sanityCheck ? 1 : 0);
|
136
|
+
const keys = Object.keys(input);
|
137
|
+
var input_counter = 0;
|
138
|
+
keys.forEach((k) => {
|
139
|
+
const h = fnvHash(k);
|
140
|
+
const hMSB = parseInt(h.slice(0, 8), 16);
|
141
|
+
const hLSB = parseInt(h.slice(8, 16), 16);
|
142
|
+
const fArr = flatArray(input[k]);
|
143
|
+
let signalSize = this.instance.exports.getInputSignalSize(hMSB, hLSB);
|
144
|
+
if (signalSize < 0) {
|
145
|
+
throw new Error(`Signal ${k} not found\n`);
|
146
|
+
}
|
147
|
+
if (fArr.length < signalSize) {
|
148
|
+
throw new Error(`Not enough values for input signal ${k}\n`);
|
149
|
+
}
|
150
|
+
if (fArr.length > signalSize) {
|
151
|
+
throw new Error(`Too many values for input signal ${k}\n`);
|
152
|
+
}
|
153
|
+
for (let i = 0; i < fArr.length; i++) {
|
154
|
+
const arrFr = toArray32(BigInt(fArr[i]) % this.prime, this.n32);
|
155
|
+
for (let j = 0; j < this.n32; j++) {
|
156
|
+
this.instance.exports.writeSharedRWMemory(j, arrFr[this.n32 - 1 - j]);
|
157
|
+
}
|
158
|
+
try {
|
159
|
+
this.instance.exports.setInputSignal(hMSB, hLSB, i);
|
160
|
+
input_counter++;
|
161
|
+
} catch (err) {
|
162
|
+
// console.log(`After adding signal ${i} of ${k}`)
|
163
|
+
throw new Error(err);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
});
|
167
|
+
if (input_counter < this.instance.exports.getInputSize()) {
|
168
|
+
throw new Error(
|
169
|
+
`Not all inputs have been set. Only ${input_counter} out of ${this.instance.exports.getInputSize()}`
|
170
|
+
);
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
async calculateWitness(input, sanityCheck) {
|
175
|
+
const w = [];
|
176
|
+
|
177
|
+
await this._doCalculateWitness(input, sanityCheck);
|
178
|
+
|
179
|
+
for (let i = 0; i < this.witnessSize; i++) {
|
180
|
+
this.instance.exports.getWitness(i);
|
181
|
+
const arr = new Uint32Array(this.n32);
|
182
|
+
for (let j = 0; j < this.n32; j++) {
|
183
|
+
arr[this.n32 - 1 - j] = this.instance.exports.readSharedRWMemory(j);
|
184
|
+
}
|
185
|
+
w.push(fromArray32(arr));
|
186
|
+
}
|
187
|
+
|
188
|
+
return w;
|
189
|
+
}
|
190
|
+
|
191
|
+
async calculateBinWitness(input, sanityCheck) {
|
192
|
+
const buff32 = new Uint32Array(this.witnessSize * this.n32);
|
193
|
+
const buff = new Uint8Array(buff32.buffer);
|
194
|
+
await this._doCalculateWitness(input, sanityCheck);
|
195
|
+
|
196
|
+
for (let i = 0; i < this.witnessSize; i++) {
|
197
|
+
this.instance.exports.getWitness(i);
|
198
|
+
const pos = i * this.n32;
|
199
|
+
for (let j = 0; j < this.n32; j++) {
|
200
|
+
buff32[pos + j] = this.instance.exports.readSharedRWMemory(j);
|
201
|
+
}
|
202
|
+
}
|
203
|
+
|
204
|
+
return buff;
|
205
|
+
}
|
206
|
+
|
207
|
+
async calculateWTNSBin(input, sanityCheck) {
|
208
|
+
const buff32 = new Uint32Array(this.witnessSize * this.n32 + this.n32 + 11);
|
209
|
+
const buff = new Uint8Array(buff32.buffer);
|
210
|
+
await this._doCalculateWitness(input, sanityCheck);
|
211
|
+
|
212
|
+
//"wtns"
|
213
|
+
buff[0] = "w".charCodeAt(0);
|
214
|
+
buff[1] = "t".charCodeAt(0);
|
215
|
+
buff[2] = "n".charCodeAt(0);
|
216
|
+
buff[3] = "s".charCodeAt(0);
|
217
|
+
|
218
|
+
//version 2
|
219
|
+
buff32[1] = 2;
|
220
|
+
|
221
|
+
//number of sections: 2
|
222
|
+
buff32[2] = 2;
|
223
|
+
|
224
|
+
//id section 1
|
225
|
+
buff32[3] = 1;
|
226
|
+
|
227
|
+
const n8 = this.n32 * 4;
|
228
|
+
//id section 1 length in 64bytes
|
229
|
+
const idSection1length = 8 + n8;
|
230
|
+
const idSection1lengthHex = idSection1length.toString(16);
|
231
|
+
buff32[4] = parseInt(idSection1lengthHex.slice(0, 8), 16);
|
232
|
+
buff32[5] = parseInt(idSection1lengthHex.slice(8, 16), 16);
|
233
|
+
|
234
|
+
//this.n32
|
235
|
+
buff32[6] = n8;
|
236
|
+
|
237
|
+
//prime number
|
238
|
+
this.instance.exports.getRawPrime();
|
239
|
+
|
240
|
+
var pos = 7;
|
241
|
+
for (let j = 0; j < this.n32; j++) {
|
242
|
+
buff32[pos + j] = this.instance.exports.readSharedRWMemory(j);
|
243
|
+
}
|
244
|
+
pos += this.n32;
|
245
|
+
|
246
|
+
// witness size
|
247
|
+
buff32[pos] = this.witnessSize;
|
248
|
+
pos++;
|
249
|
+
|
250
|
+
//id section 2
|
251
|
+
buff32[pos] = 2;
|
252
|
+
pos++;
|
253
|
+
|
254
|
+
// section 2 length
|
255
|
+
const idSection2length = n8 * this.witnessSize;
|
256
|
+
const idSection2lengthHex = idSection2length.toString(16);
|
257
|
+
buff32[pos] = parseInt(idSection2lengthHex.slice(0, 8), 16);
|
258
|
+
buff32[pos + 1] = parseInt(idSection2lengthHex.slice(8, 16), 16);
|
259
|
+
|
260
|
+
pos += 2;
|
261
|
+
for (let i = 0; i < this.witnessSize; i++) {
|
262
|
+
this.instance.exports.getWitness(i);
|
263
|
+
for (let j = 0; j < this.n32; j++) {
|
264
|
+
buff32[pos + j] = this.instance.exports.readSharedRWMemory(j);
|
265
|
+
}
|
266
|
+
pos += this.n32;
|
267
|
+
}
|
268
|
+
|
269
|
+
return buff;
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
function toArray32(rem, size) {
|
274
|
+
const res = []; //new Uint32Array(size); //has no unshift
|
275
|
+
const radix = BigInt(0x100000000);
|
276
|
+
while (rem) {
|
277
|
+
res.unshift(Number(rem % radix));
|
278
|
+
rem = rem / radix;
|
279
|
+
}
|
280
|
+
if (size) {
|
281
|
+
var i = size - res.length;
|
282
|
+
while (i > 0) {
|
283
|
+
res.unshift(0);
|
284
|
+
i--;
|
285
|
+
}
|
286
|
+
}
|
287
|
+
return res;
|
288
|
+
}
|
289
|
+
|
290
|
+
function fromArray32(arr) {
|
291
|
+
//returns a BigInt
|
292
|
+
var res = BigInt(0);
|
293
|
+
const radix = BigInt(0x100000000);
|
294
|
+
for (let i = 0; i < arr.length; i++) {
|
295
|
+
res = res * radix + BigInt(arr[i]);
|
296
|
+
}
|
297
|
+
return res;
|
298
|
+
}
|
299
|
+
|
300
|
+
function flatArray(a) {
|
301
|
+
var res = [];
|
302
|
+
fillArray(res, a);
|
303
|
+
return res;
|
304
|
+
|
305
|
+
function fillArray(res, a) {
|
306
|
+
if (Array.isArray(a)) {
|
307
|
+
for (let i = 0; i < a.length; i++) {
|
308
|
+
fillArray(res, a[i]);
|
309
|
+
}
|
310
|
+
} else {
|
311
|
+
res.push(a);
|
312
|
+
}
|
313
|
+
}
|
314
|
+
}
|
315
|
+
|
316
|
+
function fnvHash(str) {
|
317
|
+
const uint64_max = BigInt(2) ** BigInt(64);
|
318
|
+
let hash = BigInt("0xCBF29CE484222325");
|
319
|
+
for (var i = 0; i < str.length; i++) {
|
320
|
+
hash ^= BigInt(str[i].charCodeAt());
|
321
|
+
hash *= BigInt(0x100000001b3);
|
322
|
+
hash %= uint64_max;
|
323
|
+
}
|
324
|
+
let shash = hash.toString(16);
|
325
|
+
let n = 16 - shash.length;
|
326
|
+
shash = "0".repeat(n).concat(shash);
|
327
|
+
return shash;
|
328
|
+
}
|
329
|
+
|
330
|
+
export { builder };
|
@@ -0,0 +1,220 @@
|
|
1
|
+
import { createEncoder, createDecoder } from '../../core/dist/lib/message/version_0.js';
|
2
|
+
import '../../core/dist/lib/filter/filter.js';
|
3
|
+
import '../../core/dist/lib/light_push/light_push.js';
|
4
|
+
import '../../core/dist/lib/store/store.js';
|
5
|
+
import '../../core/dist/lib/connection_manager/connection_manager.js';
|
6
|
+
import '../../interfaces/dist/protocols.js';
|
7
|
+
import '../../interfaces/dist/connection_manager.js';
|
8
|
+
import '../../interfaces/dist/health_indicator.js';
|
9
|
+
import '../../../node_modules/multiformats/dist/src/bases/base10.js';
|
10
|
+
import '../../../node_modules/multiformats/dist/src/bases/base16.js';
|
11
|
+
import '../../../node_modules/multiformats/dist/src/bases/base2.js';
|
12
|
+
import '../../../node_modules/multiformats/dist/src/bases/base256emoji.js';
|
13
|
+
import '../../../node_modules/multiformats/dist/src/bases/base32.js';
|
14
|
+
import '../../../node_modules/multiformats/dist/src/bases/base36.js';
|
15
|
+
import '../../../node_modules/multiformats/dist/src/bases/base58.js';
|
16
|
+
import '../../../node_modules/multiformats/dist/src/bases/base64.js';
|
17
|
+
import '../../../node_modules/multiformats/dist/src/bases/base8.js';
|
18
|
+
import '../../../node_modules/multiformats/dist/src/bases/identity.js';
|
19
|
+
import '../../../node_modules/multiformats/dist/src/codecs/json.js';
|
20
|
+
import { Logger } from '../../utils/dist/logger/index.js';
|
21
|
+
import '../../core/dist/lib/metadata/metadata.js';
|
22
|
+
import __wbg_init, { init_panic_hook, newRLN } from '../../../node_modules/@waku/zerokit-rln-wasm/rln_wasm.js';
|
23
|
+
import { createRLNEncoder, createRLNDecoder } from './codec.js';
|
24
|
+
import { DEFAULT_RATE_LIMIT, SEPOLIA_CONTRACT } from './contract/constants.js';
|
25
|
+
import { RLNContract } from './contract/rln_contract.js';
|
26
|
+
import { Keystore } from './keystore/keystore.js';
|
27
|
+
import verificationKey from './resources/verification_key.js';
|
28
|
+
import { builder } from './resources/witness_calculator.js';
|
29
|
+
import { extractMetaMaskSigner } from './utils/metamask.js';
|
30
|
+
import './utils/epoch.js';
|
31
|
+
import { Zerokit } from './zerokit.js';
|
32
|
+
|
33
|
+
const log = new Logger("waku:rln");
|
34
|
+
async function loadWitnessCalculator() {
|
35
|
+
try {
|
36
|
+
const url = new URL("./resources/rln.wasm", import.meta.url);
|
37
|
+
const response = await fetch(url);
|
38
|
+
if (!response.ok) {
|
39
|
+
throw new Error(`Failed to fetch witness calculator: ${response.status} ${response.statusText}`);
|
40
|
+
}
|
41
|
+
return await builder(new Uint8Array(await response.arrayBuffer()), false);
|
42
|
+
}
|
43
|
+
catch (error) {
|
44
|
+
log.error("Error loading witness calculator:", error);
|
45
|
+
throw new Error(`Failed to load witness calculator: ${error instanceof Error ? error.message : String(error)}`);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
async function loadZkey() {
|
49
|
+
try {
|
50
|
+
const url = new URL("./resources/rln_final.zkey", import.meta.url);
|
51
|
+
const response = await fetch(url);
|
52
|
+
if (!response.ok) {
|
53
|
+
throw new Error(`Failed to fetch zkey: ${response.status} ${response.statusText}`);
|
54
|
+
}
|
55
|
+
return new Uint8Array(await response.arrayBuffer());
|
56
|
+
}
|
57
|
+
catch (error) {
|
58
|
+
log.error("Error loading zkey:", error);
|
59
|
+
throw new Error(`Failed to load zkey: ${error instanceof Error ? error.message : String(error)}`);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
/**
|
63
|
+
* Create an instance of RLN
|
64
|
+
* @returns RLNInstance
|
65
|
+
*/
|
66
|
+
async function create() {
|
67
|
+
try {
|
68
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
69
|
+
await __wbg_init?.();
|
70
|
+
init_panic_hook();
|
71
|
+
const witnessCalculator = await loadWitnessCalculator();
|
72
|
+
const zkey = await loadZkey();
|
73
|
+
const stringEncoder = new TextEncoder();
|
74
|
+
const vkey = stringEncoder.encode(JSON.stringify(verificationKey));
|
75
|
+
const DEPTH = 20;
|
76
|
+
const zkRLN = newRLN(DEPTH, zkey, vkey);
|
77
|
+
const zerokit = new Zerokit(zkRLN, witnessCalculator, DEFAULT_RATE_LIMIT);
|
78
|
+
return new RLNInstance(zerokit);
|
79
|
+
}
|
80
|
+
catch (error) {
|
81
|
+
log.error("Failed to initialize RLN:", error);
|
82
|
+
throw error;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
class RLNInstance {
|
86
|
+
zerokit;
|
87
|
+
started = false;
|
88
|
+
starting = false;
|
89
|
+
_contract;
|
90
|
+
_signer;
|
91
|
+
keystore = Keystore.create();
|
92
|
+
_credentials;
|
93
|
+
constructor(zerokit) {
|
94
|
+
this.zerokit = zerokit;
|
95
|
+
}
|
96
|
+
get contract() {
|
97
|
+
return this._contract;
|
98
|
+
}
|
99
|
+
get signer() {
|
100
|
+
return this._signer;
|
101
|
+
}
|
102
|
+
async start(options = {}) {
|
103
|
+
if (this.started || this.starting) {
|
104
|
+
return;
|
105
|
+
}
|
106
|
+
this.starting = true;
|
107
|
+
try {
|
108
|
+
const { credentials, keystore } = await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
|
109
|
+
const { signer, address } = await this.determineStartOptions(options, credentials);
|
110
|
+
if (keystore) {
|
111
|
+
this.keystore = keystore;
|
112
|
+
}
|
113
|
+
this._credentials = credentials;
|
114
|
+
this._signer = signer;
|
115
|
+
this._contract = await RLNContract.init(this, {
|
116
|
+
address: address,
|
117
|
+
signer: signer,
|
118
|
+
rateLimit: options.rateLimit ?? this.zerokit.getRateLimit
|
119
|
+
});
|
120
|
+
this.started = true;
|
121
|
+
}
|
122
|
+
finally {
|
123
|
+
this.starting = false;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
async determineStartOptions(options, credentials) {
|
127
|
+
let chainId = credentials?.membership.chainId;
|
128
|
+
const address = credentials?.membership.address ||
|
129
|
+
options.address ||
|
130
|
+
SEPOLIA_CONTRACT.address;
|
131
|
+
if (address === SEPOLIA_CONTRACT.address) {
|
132
|
+
chainId = SEPOLIA_CONTRACT.chainId;
|
133
|
+
}
|
134
|
+
const signer = options.signer || (await extractMetaMaskSigner());
|
135
|
+
const currentChainId = await signer.getChainId();
|
136
|
+
if (chainId && chainId !== currentChainId) {
|
137
|
+
throw Error(`Failed to start RLN contract, chain ID of contract is different from current one: contract-${chainId}, current network-${currentChainId}`);
|
138
|
+
}
|
139
|
+
return {
|
140
|
+
signer,
|
141
|
+
address
|
142
|
+
};
|
143
|
+
}
|
144
|
+
static async decryptCredentialsIfNeeded(credentials) {
|
145
|
+
if (!credentials) {
|
146
|
+
return {};
|
147
|
+
}
|
148
|
+
if ("identity" in credentials) {
|
149
|
+
return { credentials };
|
150
|
+
}
|
151
|
+
const keystore = Keystore.fromString(credentials.keystore);
|
152
|
+
if (!keystore) {
|
153
|
+
return {};
|
154
|
+
}
|
155
|
+
const decryptedCredentials = await keystore.readCredential(credentials.id, credentials.password);
|
156
|
+
return {
|
157
|
+
keystore,
|
158
|
+
credentials: decryptedCredentials
|
159
|
+
};
|
160
|
+
}
|
161
|
+
async registerMembership(options) {
|
162
|
+
if (!this.contract) {
|
163
|
+
throw Error("RLN Contract is not initialized.");
|
164
|
+
}
|
165
|
+
let identity = "identity" in options && options.identity;
|
166
|
+
if ("signature" in options) {
|
167
|
+
identity = this.zerokit.generateSeededIdentityCredential(options.signature);
|
168
|
+
}
|
169
|
+
if (!identity) {
|
170
|
+
throw Error("Missing signature or identity to register membership.");
|
171
|
+
}
|
172
|
+
return this.contract.registerWithIdentity(identity);
|
173
|
+
}
|
174
|
+
/**
|
175
|
+
* Changes credentials in use by relying on provided Keystore earlier in rln.start
|
176
|
+
* @param id: string, hash of credentials to select from Keystore
|
177
|
+
* @param password: string or bytes to use to decrypt credentials from Keystore
|
178
|
+
*/
|
179
|
+
async useCredentials(id, password) {
|
180
|
+
this._credentials = await this.keystore?.readCredential(id, password);
|
181
|
+
}
|
182
|
+
async createEncoder(options) {
|
183
|
+
const { credentials: decryptedCredentials } = await RLNInstance.decryptCredentialsIfNeeded(options.credentials);
|
184
|
+
const credentials = decryptedCredentials || this._credentials;
|
185
|
+
if (!credentials) {
|
186
|
+
throw Error("Failed to create Encoder: missing RLN credentials. Use createRLNEncoder directly.");
|
187
|
+
}
|
188
|
+
await this.verifyCredentialsAgainstContract(credentials);
|
189
|
+
return createRLNEncoder({
|
190
|
+
encoder: createEncoder(options),
|
191
|
+
rlnInstance: this,
|
192
|
+
index: credentials.membership.treeIndex,
|
193
|
+
credential: credentials.identity
|
194
|
+
});
|
195
|
+
}
|
196
|
+
async verifyCredentialsAgainstContract(credentials) {
|
197
|
+
if (!this._contract) {
|
198
|
+
throw Error("Failed to verify chain coordinates: no contract initialized.");
|
199
|
+
}
|
200
|
+
const registryAddress = credentials.membership.address;
|
201
|
+
const currentRegistryAddress = this._contract.address;
|
202
|
+
if (registryAddress !== currentRegistryAddress) {
|
203
|
+
throw Error(`Failed to verify chain coordinates: credentials contract address=${registryAddress} is not equal to registryContract address=${currentRegistryAddress}`);
|
204
|
+
}
|
205
|
+
const chainId = credentials.membership.chainId;
|
206
|
+
const network = await this._contract.provider.getNetwork();
|
207
|
+
const currentChainId = network.chainId;
|
208
|
+
if (chainId !== currentChainId) {
|
209
|
+
throw Error(`Failed to verify chain coordinates: credentials chainID=${chainId} is not equal to registryContract chainID=${currentChainId}`);
|
210
|
+
}
|
211
|
+
}
|
212
|
+
createDecoder(contentTopic) {
|
213
|
+
return createRLNDecoder({
|
214
|
+
rlnInstance: this,
|
215
|
+
decoder: createDecoder(contentTopic)
|
216
|
+
});
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
export { RLNInstance, create };
|
@@ -0,0 +1,76 @@
|
|
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
|
+
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
|
+
|
76
|
+
export { MerkleRootTracker };
|
@@ -0,0 +1,65 @@
|
|
1
|
+
/**
|
2
|
+
* Concatenate Uint8Arrays
|
3
|
+
* @param input
|
4
|
+
* @returns concatenation of all Uint8Array received as input
|
5
|
+
*/
|
6
|
+
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
|
+
function writeUIntLE(buf, value, offset, byteLength, noAssert) {
|
27
|
+
value = +value;
|
28
|
+
offset = offset >>> 0;
|
29
|
+
byteLength = byteLength >>> 0;
|
30
|
+
{
|
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
|
+
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
|
+
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
|
+
|
65
|
+
export { buildBigIntFromUint8Array, concatenate, writeUIntLE, zeroPadLE };
|