@waku/rln 0.0.1 → 0.0.2-09108d9.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 +11 -10
- package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +96 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +148 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +20 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +210 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +18 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +30 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +22 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +43 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +19 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +58 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +854 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +609 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +66 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +302 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +110 -0
- package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +20 -0
- package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +287 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +402 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +3 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +8 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +893 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +256 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +36 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +135 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +8 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +64 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +443 -0
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +8 -0
- package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +660 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +352 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +248 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +127 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +2007 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +422 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +674 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +132 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +8 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +2430 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +76 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +219 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +279 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +69 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +404 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +15 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +20 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +92 -0
- package/bundle/node_modules/@noble/hashes/esm/_assert.js +37 -0
- package/bundle/node_modules/@noble/hashes/esm/_md.js +132 -0
- package/bundle/node_modules/@noble/hashes/esm/_u64.js +29 -0
- package/bundle/node_modules/@noble/hashes/esm/sha256.js +113 -0
- package/bundle/node_modules/@noble/hashes/esm/sha3.js +210 -0
- package/bundle/node_modules/@noble/hashes/esm/utils.js +144 -0
- package/bundle/node_modules/@waku/zerokit-rln-wasm/rln_wasm.js +756 -0
- package/bundle/node_modules/bech32/index.js +187 -0
- package/bundle/node_modules/bn.js/lib/bn.js +3361 -0
- package/bundle/node_modules/debug/src/browser.js +283 -0
- package/bundle/node_modules/debug/src/common.js +295 -0
- package/bundle/node_modules/ethereum-cryptography/esm/keccak.js +10 -0
- package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +6 -0
- package/bundle/node_modules/ethereum-cryptography/esm/utils.js +24 -0
- package/bundle/node_modules/hash.js/lib/hash/common.js +97 -0
- package/bundle/node_modules/hash.js/lib/hash/hmac.js +51 -0
- package/bundle/node_modules/hash.js/lib/hash/ripemd.js +152 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/1.js +81 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/224.js +33 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/256.js +113 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/384.js +39 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/512.js +336 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/common.js +53 -0
- package/bundle/node_modules/hash.js/lib/hash/sha.js +14 -0
- package/bundle/node_modules/hash.js/lib/hash/utils.js +282 -0
- package/bundle/node_modules/hash.js/lib/hash.js +33 -0
- package/bundle/node_modules/inherits/inherits_browser.js +33 -0
- package/bundle/node_modules/it-length-prefixed/dist/src/decode.js +6 -0
- package/bundle/node_modules/lodash/lodash.js +17207 -0
- package/bundle/node_modules/minimalistic-assert/index.js +13 -0
- package/bundle/node_modules/ms/index.js +172 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base.js +205 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base10.js +9 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base16.js +16 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base2.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base256emoji.js +41 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base32.js +58 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base36.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base58.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base64.js +28 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base8.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/identity.js +11 -0
- package/bundle/node_modules/multiformats/dist/src/basics.js +15 -0
- package/bundle/node_modules/multiformats/dist/src/bytes.js +18 -0
- package/bundle/node_modules/multiformats/dist/src/codecs/json.js +2 -0
- package/bundle/node_modules/multiformats/dist/src/vendor/base-x.js +170 -0
- package/bundle/node_modules/protons-runtime/dist/src/codec.js +20 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/enum.js +24 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/message.js +7 -0
- package/bundle/node_modules/protons-runtime/dist/src/decode.js +8 -0
- package/bundle/node_modules/protons-runtime/dist/src/encode.js +11 -0
- package/bundle/node_modules/protons-runtime/dist/src/index.js +30 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/float.js +54 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/longbits.js +175 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/pool.js +28 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/reader.js +367 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/utf8.js +99 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/writer.js +438 -0
- package/bundle/node_modules/uint8-varint/dist/src/index.js +124 -0
- package/bundle/node_modules/uint8arrays/dist/src/alloc.js +17 -0
- package/bundle/node_modules/uint8arrays/dist/src/from-string.js +19 -0
- package/bundle/node_modules/uint8arrays/dist/src/util/bases.js +49 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +21 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +18 -0
- package/bundle/packages/core/dist/lib/filter/filter.js +27 -0
- package/bundle/packages/core/dist/lib/light_push/light_push.js +27 -0
- package/bundle/packages/core/dist/lib/message/version_0.js +154 -0
- package/bundle/packages/core/dist/lib/metadata/metadata.js +27 -0
- package/bundle/packages/core/dist/lib/store/store.js +27 -0
- package/bundle/packages/interfaces/dist/connection_manager.js +19 -0
- package/bundle/packages/interfaces/dist/constants.js +6 -0
- package/bundle/packages/interfaces/dist/health_indicator.js +12 -0
- package/bundle/packages/interfaces/dist/protocols.js +92 -0
- package/bundle/packages/proto/dist/generated/filter.js +445 -0
- package/bundle/packages/proto/dist/generated/filter_v2.js +424 -0
- package/bundle/packages/proto/dist/generated/light_push.js +389 -0
- package/bundle/packages/proto/dist/generated/message.js +213 -0
- package/bundle/packages/proto/dist/generated/metadata.js +130 -0
- package/bundle/packages/proto/dist/generated/peer_exchange.js +209 -0
- package/bundle/packages/proto/dist/generated/sds_message.js +105 -0
- package/bundle/packages/proto/dist/generated/store_v3.js +490 -0
- package/bundle/packages/proto/dist/generated/topic_only_message.js +61 -0
- package/bundle/packages/rln/dist/codec.js +93 -0
- package/bundle/packages/rln/dist/contract/constants.js +68 -0
- package/bundle/packages/rln/dist/contract/rln_contract.js +218 -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 +206 -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 +108 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +52 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +65 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +99 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/index.js +28 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +78 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1253 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +40 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/types.js +5 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +41 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +23 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +12 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +77 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +9 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +215 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +35 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +21 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +66 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +24 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +7 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +11 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +52 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +124 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +71 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +10 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +88 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +99 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +233 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +133 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +243 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +167 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/native.js +4 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/rng.js +13 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/stringify.js +28 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/v4.js +19 -0
- package/bundle/packages/utils/dist/bytes/index.js +44 -0
- package/bundle/packages/utils/dist/common/sharding/index.js +91 -0
- package/bundle/packages/utils/dist/logger/index.js +31 -0
- package/bundle/resources/rln.wasm +0 -0
- package/bundle/resources/rln_final.zkey +0 -0
- package/bundle/resources/verification_key.d.ts +13 -0
- package/bundle/resources/verification_key.js +112 -0
- package/bundle/resources/witness_calculator.d.ts +11 -0
- package/bundle/resources/witness_calculator.js +328 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/codec.d.ts +39 -0
- package/dist/codec.js +77 -0
- package/dist/codec.js.map +1 -0
- package/dist/contract/constants.d.ts +7 -0
- package/dist/contract/constants.js +67 -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 +46 -0
- package/dist/contract/rln_contract.js +211 -0
- package/dist/contract/rln_contract.js.map +1 -0
- package/dist/create.d.ts +2 -0
- package/dist/create.js +8 -0
- package/dist/create.js.map +1 -0
- package/dist/identity.d.ts +9 -0
- package/dist/identity.js +27 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/dist/keystore/cipher.d.ts +4 -0
- package/dist/keystore/cipher.js +28 -0
- package/dist/keystore/cipher.js.map +1 -0
- package/dist/keystore/credential_validation_generated.d.ts +8 -0
- package/dist/keystore/credential_validation_generated.js +121 -0
- package/dist/keystore/credential_validation_generated.js.map +1 -0
- package/dist/keystore/index.d.ts +4 -0
- package/dist/keystore/index.js +3 -0
- package/dist/keystore/index.js.map +1 -0
- package/dist/keystore/keystore.d.ts +50 -0
- package/dist/keystore/keystore.js +205 -0
- package/dist/keystore/keystore.js.map +1 -0
- package/dist/keystore/keystore_validation_generated.d.ts +8 -0
- package/dist/keystore/keystore_validation_generated.js +75 -0
- package/dist/keystore/keystore_validation_generated.js.map +1 -0
- package/dist/keystore/schema_validator.d.ts +2 -0
- package/dist/keystore/schema_validator.js +18 -0
- package/dist/keystore/schema_validator.js.map +1 -0
- package/dist/keystore/types.d.ts +29 -0
- package/dist/keystore/types.js +2 -0
- package/dist/keystore/types.js.map +1 -0
- package/dist/message.d.ts +18 -0
- package/dist/message.js +49 -0
- package/dist/message.js.map +1 -0
- package/dist/proof.d.ts +21 -0
- package/dist/proof.js +50 -0
- package/dist/proof.js.map +1 -0
- package/dist/resources/rln.wasm +0 -0
- package/dist/resources/rln_final.zkey +0 -0
- package/dist/resources/verification_key.d.ts +13 -0
- package/dist/resources/verification_key.js +112 -0
- package/dist/resources/witness_calculator.d.ts +11 -0
- package/dist/resources/witness_calculator.js +328 -0
- package/dist/rln.d.ts +55 -13
- package/dist/rln.js +164 -79
- 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 +105 -0
- package/dist/zerokit.js.map +1 -0
- package/package.json +1 -126
- package/src/codec.ts +134 -0
- package/src/contract/constants.ts +68 -0
- package/src/contract/index.ts +2 -0
- package/src/contract/rln_contract.ts +353 -0
- package/src/create.ts +9 -0
- package/src/identity.ts +31 -0
- package/src/index.ts +29 -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 +266 -104
- 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 +184 -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
@@ -0,0 +1,353 @@
|
|
1
|
+
import { Logger } from "@waku/utils";
|
2
|
+
import { hexToBytes } from "@waku/utils/bytes";
|
3
|
+
import { ethers } from "ethers";
|
4
|
+
|
5
|
+
import type { IdentityCredential } from "../identity.js";
|
6
|
+
import type { DecryptedCredentials } from "../keystore/index.js";
|
7
|
+
import type { RLNInstance } from "../rln.js";
|
8
|
+
import { MerkleRootTracker } from "../root_tracker.js";
|
9
|
+
import { zeroPadLE } from "../utils/index.js";
|
10
|
+
|
11
|
+
import { RLN_REGISTRY_ABI, RLN_STORAGE_ABI } from "./constants.js";
|
12
|
+
|
13
|
+
const log = new Logger("waku:rln:contract");
|
14
|
+
|
15
|
+
type Member = {
|
16
|
+
idCommitment: string;
|
17
|
+
index: ethers.BigNumber;
|
18
|
+
};
|
19
|
+
|
20
|
+
type Signer = ethers.Signer;
|
21
|
+
|
22
|
+
type RLNContractOptions = {
|
23
|
+
signer: Signer;
|
24
|
+
registryAddress: string;
|
25
|
+
};
|
26
|
+
|
27
|
+
type RLNStorageOptions = {
|
28
|
+
storageIndex?: number;
|
29
|
+
};
|
30
|
+
|
31
|
+
type RLNContractInitOptions = RLNContractOptions & RLNStorageOptions;
|
32
|
+
|
33
|
+
type FetchMembersOptions = {
|
34
|
+
fromBlock?: number;
|
35
|
+
fetchRange?: number;
|
36
|
+
fetchChunks?: number;
|
37
|
+
};
|
38
|
+
|
39
|
+
export class RLNContract {
|
40
|
+
private registryContract: ethers.Contract;
|
41
|
+
private merkleRootTracker: MerkleRootTracker;
|
42
|
+
|
43
|
+
private deployBlock: undefined | number;
|
44
|
+
private storageIndex: undefined | number;
|
45
|
+
private storageContract: undefined | ethers.Contract;
|
46
|
+
private _membersFilter: undefined | ethers.EventFilter;
|
47
|
+
|
48
|
+
private _members: Map<number, Member> = new Map();
|
49
|
+
|
50
|
+
public static async init(
|
51
|
+
rlnInstance: RLNInstance,
|
52
|
+
options: RLNContractInitOptions
|
53
|
+
): Promise<RLNContract> {
|
54
|
+
const rlnContract = new RLNContract(rlnInstance, options);
|
55
|
+
|
56
|
+
await rlnContract.initStorageContract(options.signer);
|
57
|
+
await rlnContract.fetchMembers(rlnInstance);
|
58
|
+
rlnContract.subscribeToMembers(rlnInstance);
|
59
|
+
|
60
|
+
return rlnContract;
|
61
|
+
}
|
62
|
+
|
63
|
+
public constructor(
|
64
|
+
rlnInstance: RLNInstance,
|
65
|
+
{ registryAddress, signer }: RLNContractOptions
|
66
|
+
) {
|
67
|
+
const initialRoot = rlnInstance.zerokit.getMerkleRoot();
|
68
|
+
|
69
|
+
this.registryContract = new ethers.Contract(
|
70
|
+
registryAddress,
|
71
|
+
RLN_REGISTRY_ABI,
|
72
|
+
signer
|
73
|
+
);
|
74
|
+
this.merkleRootTracker = new MerkleRootTracker(5, initialRoot);
|
75
|
+
}
|
76
|
+
|
77
|
+
private async initStorageContract(
|
78
|
+
signer: Signer,
|
79
|
+
options: RLNStorageOptions = {}
|
80
|
+
): Promise<void> {
|
81
|
+
const storageIndex = options?.storageIndex
|
82
|
+
? options.storageIndex
|
83
|
+
: await this.registryContract.usingStorageIndex();
|
84
|
+
const storageAddress = await this.registryContract.storages(storageIndex);
|
85
|
+
|
86
|
+
if (!storageAddress || storageAddress === ethers.constants.AddressZero) {
|
87
|
+
throw Error("No RLN Storage initialized on registry contract.");
|
88
|
+
}
|
89
|
+
|
90
|
+
this.storageIndex = storageIndex;
|
91
|
+
this.storageContract = new ethers.Contract(
|
92
|
+
storageAddress,
|
93
|
+
RLN_STORAGE_ABI,
|
94
|
+
signer
|
95
|
+
);
|
96
|
+
this._membersFilter = this.storageContract.filters.MemberRegistered();
|
97
|
+
|
98
|
+
this.deployBlock = await this.storageContract.deployedBlockNumber();
|
99
|
+
}
|
100
|
+
|
101
|
+
public get registry(): ethers.Contract {
|
102
|
+
if (!this.registryContract) {
|
103
|
+
throw Error("Registry contract was not initialized");
|
104
|
+
}
|
105
|
+
return this.registryContract as ethers.Contract;
|
106
|
+
}
|
107
|
+
|
108
|
+
public get contract(): ethers.Contract {
|
109
|
+
if (!this.storageContract) {
|
110
|
+
throw Error("Storage contract was not initialized");
|
111
|
+
}
|
112
|
+
return this.storageContract as ethers.Contract;
|
113
|
+
}
|
114
|
+
|
115
|
+
public get members(): Member[] {
|
116
|
+
const sortedMembers = Array.from(this._members.values()).sort(
|
117
|
+
(left, right) => left.index.toNumber() - right.index.toNumber()
|
118
|
+
);
|
119
|
+
return sortedMembers;
|
120
|
+
}
|
121
|
+
|
122
|
+
private get membersFilter(): ethers.EventFilter {
|
123
|
+
if (!this._membersFilter) {
|
124
|
+
throw Error("Members filter was not initialized.");
|
125
|
+
}
|
126
|
+
return this._membersFilter as ethers.EventFilter;
|
127
|
+
}
|
128
|
+
|
129
|
+
public async fetchMembers(
|
130
|
+
rlnInstance: RLNInstance,
|
131
|
+
options: FetchMembersOptions = {}
|
132
|
+
): Promise<void> {
|
133
|
+
const registeredMemberEvents = await queryFilter(this.contract, {
|
134
|
+
fromBlock: this.deployBlock,
|
135
|
+
...options,
|
136
|
+
membersFilter: this.membersFilter
|
137
|
+
});
|
138
|
+
this.processEvents(rlnInstance, registeredMemberEvents);
|
139
|
+
}
|
140
|
+
|
141
|
+
public processEvents(rlnInstance: RLNInstance, events: ethers.Event[]): void {
|
142
|
+
const toRemoveTable = new Map<number, number[]>();
|
143
|
+
const toInsertTable = new Map<number, ethers.Event[]>();
|
144
|
+
|
145
|
+
events.forEach((evt) => {
|
146
|
+
if (!evt.args) {
|
147
|
+
return;
|
148
|
+
}
|
149
|
+
|
150
|
+
if (evt.removed) {
|
151
|
+
const index: ethers.BigNumber = evt.args.index;
|
152
|
+
const toRemoveVal = toRemoveTable.get(evt.blockNumber);
|
153
|
+
if (toRemoveVal != undefined) {
|
154
|
+
toRemoveVal.push(index.toNumber());
|
155
|
+
toRemoveTable.set(evt.blockNumber, toRemoveVal);
|
156
|
+
} else {
|
157
|
+
toRemoveTable.set(evt.blockNumber, [index.toNumber()]);
|
158
|
+
}
|
159
|
+
} else {
|
160
|
+
let eventsPerBlock = toInsertTable.get(evt.blockNumber);
|
161
|
+
if (eventsPerBlock == undefined) {
|
162
|
+
eventsPerBlock = [];
|
163
|
+
}
|
164
|
+
|
165
|
+
eventsPerBlock.push(evt);
|
166
|
+
toInsertTable.set(evt.blockNumber, eventsPerBlock);
|
167
|
+
}
|
168
|
+
});
|
169
|
+
|
170
|
+
this.removeMembers(rlnInstance, toRemoveTable);
|
171
|
+
this.insertMembers(rlnInstance, toInsertTable);
|
172
|
+
}
|
173
|
+
|
174
|
+
private insertMembers(
|
175
|
+
rlnInstance: RLNInstance,
|
176
|
+
toInsert: Map<number, ethers.Event[]>
|
177
|
+
): void {
|
178
|
+
toInsert.forEach((events: ethers.Event[], blockNumber: number) => {
|
179
|
+
events.forEach((evt) => {
|
180
|
+
const _idCommitment = evt?.args?.idCommitment;
|
181
|
+
const index: ethers.BigNumber = evt?.args?.index;
|
182
|
+
|
183
|
+
if (!_idCommitment || !index) {
|
184
|
+
return;
|
185
|
+
}
|
186
|
+
|
187
|
+
const idCommitment = zeroPadLE(hexToBytes(_idCommitment?._hex), 32);
|
188
|
+
rlnInstance.zerokit.insertMember(idCommitment);
|
189
|
+
this._members.set(index.toNumber(), {
|
190
|
+
index,
|
191
|
+
idCommitment: _idCommitment?._hex
|
192
|
+
});
|
193
|
+
});
|
194
|
+
|
195
|
+
const currentRoot = rlnInstance.zerokit.getMerkleRoot();
|
196
|
+
this.merkleRootTracker.pushRoot(blockNumber, currentRoot);
|
197
|
+
});
|
198
|
+
}
|
199
|
+
|
200
|
+
private removeMembers(
|
201
|
+
rlnInstance: RLNInstance,
|
202
|
+
toRemove: Map<number, number[]>
|
203
|
+
): void {
|
204
|
+
const removeDescending = new Map([...toRemove].sort().reverse());
|
205
|
+
removeDescending.forEach((indexes: number[], blockNumber: number) => {
|
206
|
+
indexes.forEach((index) => {
|
207
|
+
if (this._members.has(index)) {
|
208
|
+
this._members.delete(index);
|
209
|
+
rlnInstance.zerokit.deleteMember(index);
|
210
|
+
}
|
211
|
+
});
|
212
|
+
|
213
|
+
this.merkleRootTracker.backFill(blockNumber);
|
214
|
+
});
|
215
|
+
}
|
216
|
+
|
217
|
+
public subscribeToMembers(rlnInstance: RLNInstance): void {
|
218
|
+
this.contract.on(this.membersFilter, (_pubkey, _index, event) =>
|
219
|
+
this.processEvents(rlnInstance, [event])
|
220
|
+
);
|
221
|
+
}
|
222
|
+
|
223
|
+
public async registerWithIdentity(
|
224
|
+
identity: IdentityCredential
|
225
|
+
): Promise<DecryptedCredentials | undefined> {
|
226
|
+
if (this.storageIndex === undefined) {
|
227
|
+
throw Error(
|
228
|
+
"Cannot register credential, no storage contract index found."
|
229
|
+
);
|
230
|
+
}
|
231
|
+
const txRegisterResponse: ethers.ContractTransaction =
|
232
|
+
await this.registryContract["register(uint16,uint256)"](
|
233
|
+
this.storageIndex,
|
234
|
+
identity.IDCommitmentBigInt,
|
235
|
+
{ gasLimit: 100000 }
|
236
|
+
);
|
237
|
+
const txRegisterReceipt = await txRegisterResponse.wait();
|
238
|
+
|
239
|
+
// assumption: register(uint16,uint256) emits one event
|
240
|
+
const memberRegistered = txRegisterReceipt?.events?.[0];
|
241
|
+
|
242
|
+
if (!memberRegistered) {
|
243
|
+
return undefined;
|
244
|
+
}
|
245
|
+
|
246
|
+
const decodedData = this.contract.interface.decodeEventLog(
|
247
|
+
"MemberRegistered",
|
248
|
+
memberRegistered.data
|
249
|
+
);
|
250
|
+
|
251
|
+
const network = await this.registryContract.provider.getNetwork();
|
252
|
+
const address = this.registryContract.address;
|
253
|
+
const membershipId = decodedData.index.toNumber();
|
254
|
+
|
255
|
+
return {
|
256
|
+
identity,
|
257
|
+
membership: {
|
258
|
+
address,
|
259
|
+
treeIndex: membershipId,
|
260
|
+
chainId: network.chainId
|
261
|
+
}
|
262
|
+
};
|
263
|
+
}
|
264
|
+
|
265
|
+
public roots(): Uint8Array[] {
|
266
|
+
return this.merkleRootTracker.roots();
|
267
|
+
}
|
268
|
+
}
|
269
|
+
|
270
|
+
type CustomQueryOptions = FetchMembersOptions & {
|
271
|
+
membersFilter: ethers.EventFilter;
|
272
|
+
};
|
273
|
+
|
274
|
+
// these value should be tested on other networks
|
275
|
+
const FETCH_CHUNK = 5;
|
276
|
+
const BLOCK_RANGE = 3000;
|
277
|
+
|
278
|
+
async function queryFilter(
|
279
|
+
contract: ethers.Contract,
|
280
|
+
options: CustomQueryOptions
|
281
|
+
): Promise<ethers.Event[]> {
|
282
|
+
const {
|
283
|
+
fromBlock,
|
284
|
+
membersFilter,
|
285
|
+
fetchRange = BLOCK_RANGE,
|
286
|
+
fetchChunks = FETCH_CHUNK
|
287
|
+
} = options;
|
288
|
+
|
289
|
+
if (!fromBlock) {
|
290
|
+
return contract.queryFilter(membersFilter);
|
291
|
+
}
|
292
|
+
|
293
|
+
if (!contract.signer.provider) {
|
294
|
+
throw Error("No provider found on the contract's signer.");
|
295
|
+
}
|
296
|
+
|
297
|
+
const toBlock = await contract.signer.provider.getBlockNumber();
|
298
|
+
|
299
|
+
if (toBlock - fromBlock < fetchRange) {
|
300
|
+
return contract.queryFilter(membersFilter);
|
301
|
+
}
|
302
|
+
|
303
|
+
const events: ethers.Event[][] = [];
|
304
|
+
const chunks = splitToChunks(fromBlock, toBlock, fetchRange);
|
305
|
+
|
306
|
+
for (const portion of takeN<[number, number]>(chunks, fetchChunks)) {
|
307
|
+
const promises = portion.map(([left, right]) =>
|
308
|
+
ignoreErrors(contract.queryFilter(membersFilter, left, right), [])
|
309
|
+
);
|
310
|
+
const fetchedEvents = await Promise.all(promises);
|
311
|
+
events.push(fetchedEvents.flatMap((v) => v));
|
312
|
+
}
|
313
|
+
|
314
|
+
return events.flatMap((v) => v);
|
315
|
+
}
|
316
|
+
|
317
|
+
function splitToChunks(
|
318
|
+
from: number,
|
319
|
+
to: number,
|
320
|
+
step: number
|
321
|
+
): Array<[number, number]> {
|
322
|
+
const chunks = [];
|
323
|
+
|
324
|
+
let left = from;
|
325
|
+
while (left < to) {
|
326
|
+
const right = left + step < to ? left + step : to;
|
327
|
+
|
328
|
+
chunks.push([left, right] as [number, number]);
|
329
|
+
|
330
|
+
left = right;
|
331
|
+
}
|
332
|
+
|
333
|
+
return chunks;
|
334
|
+
}
|
335
|
+
|
336
|
+
function* takeN<T>(array: T[], size: number): Iterable<T[]> {
|
337
|
+
let start = 0;
|
338
|
+
|
339
|
+
while (start < array.length) {
|
340
|
+
const portion = array.slice(start, start + size);
|
341
|
+
|
342
|
+
yield portion;
|
343
|
+
|
344
|
+
start += size;
|
345
|
+
}
|
346
|
+
}
|
347
|
+
|
348
|
+
function ignoreErrors<T>(promise: Promise<T>, defaultValue: T): Promise<T> {
|
349
|
+
return promise.catch((err) => {
|
350
|
+
log.info(`Ignoring an error during query: ${err?.message}`);
|
351
|
+
return defaultValue;
|
352
|
+
});
|
353
|
+
}
|
package/src/create.ts
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
import type { RLNInstance } from "./rln.js";
|
2
|
+
|
3
|
+
export async function createRLN(): Promise<RLNInstance> {
|
4
|
+
// A dependency graph that contains any wasm must all be imported
|
5
|
+
// asynchronously. This file does the single async import, so
|
6
|
+
// that no one else needs to worry about it again.
|
7
|
+
const rlnModule = await import("./rln.js");
|
8
|
+
return rlnModule.create();
|
9
|
+
}
|
package/src/identity.ts
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
import { buildBigIntFromUint8Array } from "./utils/index.js";
|
2
|
+
|
3
|
+
export class IdentityCredential {
|
4
|
+
public constructor(
|
5
|
+
public readonly IDTrapdoor: Uint8Array,
|
6
|
+
public readonly IDNullifier: Uint8Array,
|
7
|
+
public readonly IDSecretHash: Uint8Array,
|
8
|
+
public readonly IDCommitment: Uint8Array,
|
9
|
+
public readonly IDCommitmentBigInt: bigint
|
10
|
+
) {}
|
11
|
+
|
12
|
+
public static fromBytes(memKeys: Uint8Array): IdentityCredential {
|
13
|
+
if (memKeys.length < 128) {
|
14
|
+
throw new Error("Invalid memKeys length - must be at least 128 bytes");
|
15
|
+
}
|
16
|
+
|
17
|
+
const idTrapdoor = memKeys.subarray(0, 32);
|
18
|
+
const idNullifier = memKeys.subarray(32, 64);
|
19
|
+
const idSecretHash = memKeys.subarray(64, 96);
|
20
|
+
const idCommitment = memKeys.subarray(96, 128);
|
21
|
+
const idCommitmentBigInt = buildBigIntFromUint8Array(idCommitment, 32);
|
22
|
+
|
23
|
+
return new IdentityCredential(
|
24
|
+
idTrapdoor,
|
25
|
+
idNullifier,
|
26
|
+
idSecretHash,
|
27
|
+
idCommitment,
|
28
|
+
idCommitmentBigInt
|
29
|
+
);
|
30
|
+
}
|
31
|
+
}
|
package/src/index.ts
CHANGED
@@ -1,11 +1,30 @@
|
|
1
|
-
import {
|
1
|
+
import { RLNDecoder, RLNEncoder } from "./codec.js";
|
2
|
+
import {
|
3
|
+
RLN_REGISTRY_ABI,
|
4
|
+
RLN_STORAGE_ABI,
|
5
|
+
SEPOLIA_CONTRACT
|
6
|
+
} from "./contract/index.js";
|
7
|
+
import { RLNContract } from "./contract/index.js";
|
8
|
+
import { createRLN } from "./create.js";
|
9
|
+
import { IdentityCredential } from "./identity.js";
|
10
|
+
import { Keystore } from "./keystore/index.js";
|
11
|
+
import { Proof } from "./proof.js";
|
12
|
+
import { RLNInstance } from "./rln.js";
|
13
|
+
import { MerkleRootTracker } from "./root_tracker.js";
|
14
|
+
import { extractMetaMaskSigner } from "./utils/index.js";
|
2
15
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
16
|
+
export {
|
17
|
+
createRLN,
|
18
|
+
Keystore,
|
19
|
+
RLNInstance,
|
20
|
+
IdentityCredential,
|
21
|
+
Proof,
|
22
|
+
RLNEncoder,
|
23
|
+
RLNDecoder,
|
24
|
+
MerkleRootTracker,
|
25
|
+
RLNContract,
|
26
|
+
RLN_STORAGE_ABI,
|
27
|
+
RLN_REGISTRY_ABI,
|
28
|
+
SEPOLIA_CONTRACT,
|
29
|
+
extractMetaMaskSigner
|
30
|
+
};
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import type { IKeystore as IEipKeystore } from "@chainsafe/bls-keystore";
|
2
|
+
import { cipherDecrypt } from "@chainsafe/bls-keystore/lib/cipher";
|
3
|
+
import { kdf } from "@chainsafe/bls-keystore/lib/kdf";
|
4
|
+
import { normalizePassword } from "@chainsafe/bls-keystore/lib/password";
|
5
|
+
import { keccak256 } from "ethereum-cryptography/keccak";
|
6
|
+
import {
|
7
|
+
bytesToHex,
|
8
|
+
concatBytes,
|
9
|
+
hexToBytes
|
10
|
+
} from "ethereum-cryptography/utils";
|
11
|
+
|
12
|
+
import type { Keccak256Hash, Password } from "./types.js";
|
13
|
+
|
14
|
+
// eipKeystore supports only sha256 checksum so we just make an assumption it is keccak256
|
15
|
+
const validateChecksum = async (
|
16
|
+
password: Password,
|
17
|
+
eipKeystore: IEipKeystore
|
18
|
+
): Promise<boolean> => {
|
19
|
+
const computedChecksum = await keccak256Checksum(password, eipKeystore);
|
20
|
+
return computedChecksum === eipKeystore.crypto.checksum.message;
|
21
|
+
};
|
22
|
+
|
23
|
+
// decrypt from @chainsafe/bls-keystore supports only sha256
|
24
|
+
// but nwaku uses keccak256
|
25
|
+
// https://github.com/waku-org/nwaku/blob/25d6e52e3804d15f9b61bc4cc6dd448540c072a1/waku/waku_keystore/keyfile.nim#L367
|
26
|
+
export const decryptEipKeystore = async (
|
27
|
+
password: Password,
|
28
|
+
eipKeystore: IEipKeystore
|
29
|
+
): Promise<Uint8Array> => {
|
30
|
+
const decryptionKey = await kdf(
|
31
|
+
eipKeystore.crypto.kdf,
|
32
|
+
normalizePassword(password)
|
33
|
+
);
|
34
|
+
const isChecksumValid = await validateChecksum(password, eipKeystore);
|
35
|
+
|
36
|
+
if (!isChecksumValid) {
|
37
|
+
throw Error("Password is invalid.");
|
38
|
+
}
|
39
|
+
|
40
|
+
return cipherDecrypt(eipKeystore.crypto.cipher, decryptionKey.slice(0, 16));
|
41
|
+
};
|
42
|
+
|
43
|
+
export const keccak256Checksum = async (
|
44
|
+
password: Password,
|
45
|
+
eipKeystore: IEipKeystore
|
46
|
+
): Promise<Keccak256Hash> => {
|
47
|
+
const key = await kdf(eipKeystore.crypto.kdf, normalizePassword(password));
|
48
|
+
const payload = concatBytes(
|
49
|
+
key.slice(16),
|
50
|
+
hexToBytes(eipKeystore.crypto.cipher.message)
|
51
|
+
);
|
52
|
+
const ciphertext = keccak256(payload);
|
53
|
+
return bytesToHex(ciphertext);
|
54
|
+
};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/* eslint eslint-comments/no-unlimited-disable: "off" */
|
2
|
+
// This file was generated by /scripts/schema-validation-codegen.ts
|
3
|
+
// Do not modify this file by hand.
|
4
|
+
|
5
|
+
/* eslint-disable */
|
6
|
+
// @ts-ignore
|
7
|
+
"use strict";export const Credential = validate11;const schema12 = {"type":"object","properties":{"crypto":{"type":"object","properties":{"cipher":{"type":"string"},"cipherparams":{"type":"object"},"ciphertext":{"type":"string"},"kdf":{"type":"string"},"kdfparams":{"type":"object"},"mac":{"type":"string"}},"required":["cipher","cipherparams","ciphertext","kdf","kdfparams","mac"]}},"required":["crypto"]};function validate11(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(errors === 0){if(data && typeof data == "object" && !Array.isArray(data)){let missing0;if((data.crypto === undefined) && (missing0 = "crypto")){validate11.errors = [{instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: missing0},message:"must have required property '"+missing0+"'"}];return false;}else {if(data.crypto !== undefined){let data0 = data.crypto;const _errs1 = errors;if(errors === _errs1){if(data0 && typeof data0 == "object" && !Array.isArray(data0)){let missing1;if(((((((data0.cipher === undefined) && (missing1 = "cipher")) || ((data0.cipherparams === undefined) && (missing1 = "cipherparams"))) || ((data0.ciphertext === undefined) && (missing1 = "ciphertext"))) || ((data0.kdf === undefined) && (missing1 = "kdf"))) || ((data0.kdfparams === undefined) && (missing1 = "kdfparams"))) || ((data0.mac === undefined) && (missing1 = "mac"))){validate11.errors = [{instancePath:instancePath+"/crypto",schemaPath:"#/properties/crypto/required",keyword:"required",params:{missingProperty: missing1},message:"must have required property '"+missing1+"'"}];return false;}else {if(data0.cipher !== undefined){const _errs3 = errors;if(typeof data0.cipher !== "string"){validate11.errors = [{instancePath:instancePath+"/crypto/cipher",schemaPath:"#/properties/crypto/properties/cipher/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs3 === errors;}else {var valid1 = true;}if(valid1){if(data0.cipherparams !== undefined){let data2 = data0.cipherparams;const _errs5 = errors;if(!(data2 && typeof data2 == "object" && !Array.isArray(data2))){validate11.errors = [{instancePath:instancePath+"/crypto/cipherparams",schemaPath:"#/properties/crypto/properties/cipherparams/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}var valid1 = _errs5 === errors;}else {var valid1 = true;}if(valid1){if(data0.ciphertext !== undefined){const _errs7 = errors;if(typeof data0.ciphertext !== "string"){validate11.errors = [{instancePath:instancePath+"/crypto/ciphertext",schemaPath:"#/properties/crypto/properties/ciphertext/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs7 === errors;}else {var valid1 = true;}if(valid1){if(data0.kdf !== undefined){const _errs9 = errors;if(typeof data0.kdf !== "string"){validate11.errors = [{instancePath:instancePath+"/crypto/kdf",schemaPath:"#/properties/crypto/properties/kdf/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs9 === errors;}else {var valid1 = true;}if(valid1){if(data0.kdfparams !== undefined){let data5 = data0.kdfparams;const _errs11 = errors;if(!(data5 && typeof data5 == "object" && !Array.isArray(data5))){validate11.errors = [{instancePath:instancePath+"/crypto/kdfparams",schemaPath:"#/properties/crypto/properties/kdfparams/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}var valid1 = _errs11 === errors;}else {var valid1 = true;}if(valid1){if(data0.mac !== undefined){const _errs13 = errors;if(typeof data0.mac !== "string"){validate11.errors = [{instancePath:instancePath+"/crypto/mac",schemaPath:"#/properties/crypto/properties/mac/type",keyword:"type",params:{type: "string"},message:"must be string"}];return false;}var valid1 = _errs13 === errors;}else {var valid1 = true;}}}}}}}}else {validate11.errors = [{instancePath:instancePath+"/crypto",schemaPath:"#/properties/crypto/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}}}}else {validate11.errors = [{instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"}];return false;}}validate11.errors = vErrors;return errors === 0;}
|