@waku/rln 0.1.3-f6d5deb → 0.1.4-29a4c3f.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,893 @@
|
|
1
|
+
import { Interface, Indexed } from '../../abi/lib.esm/interface.js';
|
2
|
+
import { Provider } from '../../abstract-provider/lib.esm/index.js';
|
3
|
+
import { Signer, VoidSigner } from '../../abstract-signer/lib.esm/index.js';
|
4
|
+
import { getAddress, getContractAddress } from '../../address/lib.esm/index.js';
|
5
|
+
import { isHexString, arrayify } from '../../bytes/lib.esm/index.js';
|
6
|
+
import { defineReadOnly, getStatic, shallowCopy, deepCopy, resolveProperties } from '../../properties/lib.esm/index.js';
|
7
|
+
import { accessListify } from '../../transactions/lib.esm/index.js';
|
8
|
+
import { Logger } from '../../logger/lib.esm/index.js';
|
9
|
+
import { version } from './_version.js';
|
10
|
+
import { checkResultErrors } from '../../abi/lib.esm/coders/abstract-coder.js';
|
11
|
+
import { BigNumber } from '../../bignumber/lib.esm/bignumber.js';
|
12
|
+
|
13
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
20
|
+
});
|
21
|
+
};
|
22
|
+
const logger = new Logger(version);
|
23
|
+
function resolveName(resolver, nameOrPromise) {
|
24
|
+
return __awaiter(this, undefined, undefined, function* () {
|
25
|
+
const name = yield nameOrPromise;
|
26
|
+
if (typeof (name) !== "string") {
|
27
|
+
logger.throwArgumentError("invalid address or ENS name", "name", name);
|
28
|
+
}
|
29
|
+
// If it is already an address, just use it (after adding checksum)
|
30
|
+
try {
|
31
|
+
return getAddress(name);
|
32
|
+
}
|
33
|
+
catch (error) { }
|
34
|
+
if (!resolver) {
|
35
|
+
logger.throwError("a provider or signer is needed to resolve ENS names", Logger.errors.UNSUPPORTED_OPERATION, {
|
36
|
+
operation: "resolveName"
|
37
|
+
});
|
38
|
+
}
|
39
|
+
const address = yield resolver.resolveName(name);
|
40
|
+
if (address == null) {
|
41
|
+
logger.throwArgumentError("resolver or addr is not configured for ENS name", "name", name);
|
42
|
+
}
|
43
|
+
return address;
|
44
|
+
});
|
45
|
+
}
|
46
|
+
// Recursively replaces ENS names with promises to resolve the name and resolves all properties
|
47
|
+
function resolveAddresses(resolver, value, paramType) {
|
48
|
+
return __awaiter(this, undefined, undefined, function* () {
|
49
|
+
if (Array.isArray(paramType)) {
|
50
|
+
return yield Promise.all(paramType.map((paramType, index) => {
|
51
|
+
return resolveAddresses(resolver, ((Array.isArray(value)) ? value[index] : value[paramType.name]), paramType);
|
52
|
+
}));
|
53
|
+
}
|
54
|
+
if (paramType.type === "address") {
|
55
|
+
return yield resolveName(resolver, value);
|
56
|
+
}
|
57
|
+
if (paramType.type === "tuple") {
|
58
|
+
return yield resolveAddresses(resolver, value, paramType.components);
|
59
|
+
}
|
60
|
+
if (paramType.baseType === "array") {
|
61
|
+
if (!Array.isArray(value)) {
|
62
|
+
return Promise.reject(logger.makeError("invalid value for array", Logger.errors.INVALID_ARGUMENT, {
|
63
|
+
argument: "value",
|
64
|
+
value
|
65
|
+
}));
|
66
|
+
}
|
67
|
+
return yield Promise.all(value.map((v) => resolveAddresses(resolver, v, paramType.arrayChildren)));
|
68
|
+
}
|
69
|
+
return value;
|
70
|
+
});
|
71
|
+
}
|
72
|
+
function populateTransaction(contract, fragment, args) {
|
73
|
+
return __awaiter(this, undefined, undefined, function* () {
|
74
|
+
// If an extra argument is given, it is overrides
|
75
|
+
let overrides = {};
|
76
|
+
if (args.length === fragment.inputs.length + 1 && typeof (args[args.length - 1]) === "object") {
|
77
|
+
overrides = shallowCopy(args.pop());
|
78
|
+
}
|
79
|
+
// Make sure the parameter count matches
|
80
|
+
logger.checkArgumentCount(args.length, fragment.inputs.length, "passed to contract");
|
81
|
+
// Populate "from" override (allow promises)
|
82
|
+
if (contract.signer) {
|
83
|
+
if (overrides.from) {
|
84
|
+
// Contracts with a Signer are from the Signer's frame-of-reference;
|
85
|
+
// but we allow overriding "from" if it matches the signer
|
86
|
+
overrides.from = resolveProperties({
|
87
|
+
override: resolveName(contract.signer, overrides.from),
|
88
|
+
signer: contract.signer.getAddress()
|
89
|
+
}).then((check) => __awaiter(this, undefined, undefined, function* () {
|
90
|
+
if (getAddress(check.signer) !== check.override) {
|
91
|
+
logger.throwError("Contract with a Signer cannot override from", Logger.errors.UNSUPPORTED_OPERATION, {
|
92
|
+
operation: "overrides.from"
|
93
|
+
});
|
94
|
+
}
|
95
|
+
return check.override;
|
96
|
+
}));
|
97
|
+
}
|
98
|
+
else {
|
99
|
+
overrides.from = contract.signer.getAddress();
|
100
|
+
}
|
101
|
+
}
|
102
|
+
else if (overrides.from) {
|
103
|
+
overrides.from = resolveName(contract.provider, overrides.from);
|
104
|
+
//} else {
|
105
|
+
// Contracts without a signer can override "from", and if
|
106
|
+
// unspecified the zero address is used
|
107
|
+
//overrides.from = AddressZero;
|
108
|
+
}
|
109
|
+
// Wait for all dependencies to be resolved (prefer the signer over the provider)
|
110
|
+
const resolved = yield resolveProperties({
|
111
|
+
args: resolveAddresses(contract.signer || contract.provider, args, fragment.inputs),
|
112
|
+
address: contract.resolvedAddress,
|
113
|
+
overrides: (resolveProperties(overrides) || {})
|
114
|
+
});
|
115
|
+
// The ABI coded transaction
|
116
|
+
const data = contract.interface.encodeFunctionData(fragment, resolved.args);
|
117
|
+
const tx = {
|
118
|
+
data: data,
|
119
|
+
to: resolved.address
|
120
|
+
};
|
121
|
+
// Resolved Overrides
|
122
|
+
const ro = resolved.overrides;
|
123
|
+
// Populate simple overrides
|
124
|
+
if (ro.nonce != null) {
|
125
|
+
tx.nonce = BigNumber.from(ro.nonce).toNumber();
|
126
|
+
}
|
127
|
+
if (ro.gasLimit != null) {
|
128
|
+
tx.gasLimit = BigNumber.from(ro.gasLimit);
|
129
|
+
}
|
130
|
+
if (ro.gasPrice != null) {
|
131
|
+
tx.gasPrice = BigNumber.from(ro.gasPrice);
|
132
|
+
}
|
133
|
+
if (ro.maxFeePerGas != null) {
|
134
|
+
tx.maxFeePerGas = BigNumber.from(ro.maxFeePerGas);
|
135
|
+
}
|
136
|
+
if (ro.maxPriorityFeePerGas != null) {
|
137
|
+
tx.maxPriorityFeePerGas = BigNumber.from(ro.maxPriorityFeePerGas);
|
138
|
+
}
|
139
|
+
if (ro.from != null) {
|
140
|
+
tx.from = ro.from;
|
141
|
+
}
|
142
|
+
if (ro.type != null) {
|
143
|
+
tx.type = ro.type;
|
144
|
+
}
|
145
|
+
if (ro.accessList != null) {
|
146
|
+
tx.accessList = accessListify(ro.accessList);
|
147
|
+
}
|
148
|
+
// If there was no "gasLimit" override, but the ABI specifies a default, use it
|
149
|
+
if (tx.gasLimit == null && fragment.gas != null) {
|
150
|
+
// Compute the intrinsic gas cost for this transaction
|
151
|
+
// @TODO: This is based on the yellow paper as of Petersburg; this is something
|
152
|
+
// we may wish to parameterize in v6 as part of the Network object. Since this
|
153
|
+
// is always a non-nil to address, we can ignore G_create, but may wish to add
|
154
|
+
// similar logic to the ContractFactory.
|
155
|
+
let intrinsic = 21000;
|
156
|
+
const bytes = arrayify(data);
|
157
|
+
for (let i = 0; i < bytes.length; i++) {
|
158
|
+
intrinsic += 4;
|
159
|
+
if (bytes[i]) {
|
160
|
+
intrinsic += 64;
|
161
|
+
}
|
162
|
+
}
|
163
|
+
tx.gasLimit = BigNumber.from(fragment.gas).add(intrinsic);
|
164
|
+
}
|
165
|
+
// Populate "value" override
|
166
|
+
if (ro.value) {
|
167
|
+
const roValue = BigNumber.from(ro.value);
|
168
|
+
if (!roValue.isZero() && !fragment.payable) {
|
169
|
+
logger.throwError("non-payable method cannot override value", Logger.errors.UNSUPPORTED_OPERATION, {
|
170
|
+
operation: "overrides.value",
|
171
|
+
value: overrides.value
|
172
|
+
});
|
173
|
+
}
|
174
|
+
tx.value = roValue;
|
175
|
+
}
|
176
|
+
if (ro.customData) {
|
177
|
+
tx.customData = shallowCopy(ro.customData);
|
178
|
+
}
|
179
|
+
if (ro.ccipReadEnabled) {
|
180
|
+
tx.ccipReadEnabled = !!ro.ccipReadEnabled;
|
181
|
+
}
|
182
|
+
// Remove the overrides
|
183
|
+
delete overrides.nonce;
|
184
|
+
delete overrides.gasLimit;
|
185
|
+
delete overrides.gasPrice;
|
186
|
+
delete overrides.from;
|
187
|
+
delete overrides.value;
|
188
|
+
delete overrides.type;
|
189
|
+
delete overrides.accessList;
|
190
|
+
delete overrides.maxFeePerGas;
|
191
|
+
delete overrides.maxPriorityFeePerGas;
|
192
|
+
delete overrides.customData;
|
193
|
+
delete overrides.ccipReadEnabled;
|
194
|
+
// Make sure there are no stray overrides, which may indicate a
|
195
|
+
// typo or using an unsupported key.
|
196
|
+
const leftovers = Object.keys(overrides).filter((key) => (overrides[key] != null));
|
197
|
+
if (leftovers.length) {
|
198
|
+
logger.throwError(`cannot override ${leftovers.map((l) => JSON.stringify(l)).join(",")}`, Logger.errors.UNSUPPORTED_OPERATION, {
|
199
|
+
operation: "overrides",
|
200
|
+
overrides: leftovers
|
201
|
+
});
|
202
|
+
}
|
203
|
+
return tx;
|
204
|
+
});
|
205
|
+
}
|
206
|
+
function buildPopulate(contract, fragment) {
|
207
|
+
return function (...args) {
|
208
|
+
return populateTransaction(contract, fragment, args);
|
209
|
+
};
|
210
|
+
}
|
211
|
+
function buildEstimate(contract, fragment) {
|
212
|
+
const signerOrProvider = (contract.signer || contract.provider);
|
213
|
+
return function (...args) {
|
214
|
+
return __awaiter(this, undefined, undefined, function* () {
|
215
|
+
if (!signerOrProvider) {
|
216
|
+
logger.throwError("estimate require a provider or signer", Logger.errors.UNSUPPORTED_OPERATION, {
|
217
|
+
operation: "estimateGas"
|
218
|
+
});
|
219
|
+
}
|
220
|
+
const tx = yield populateTransaction(contract, fragment, args);
|
221
|
+
return yield signerOrProvider.estimateGas(tx);
|
222
|
+
});
|
223
|
+
};
|
224
|
+
}
|
225
|
+
function addContractWait(contract, tx) {
|
226
|
+
const wait = tx.wait.bind(tx);
|
227
|
+
tx.wait = (confirmations) => {
|
228
|
+
return wait(confirmations).then((receipt) => {
|
229
|
+
receipt.events = receipt.logs.map((log) => {
|
230
|
+
let event = deepCopy(log);
|
231
|
+
let parsed = null;
|
232
|
+
try {
|
233
|
+
parsed = contract.interface.parseLog(log);
|
234
|
+
}
|
235
|
+
catch (e) { }
|
236
|
+
// Successfully parsed the event log; include it
|
237
|
+
if (parsed) {
|
238
|
+
event.args = parsed.args;
|
239
|
+
event.decode = (data, topics) => {
|
240
|
+
return contract.interface.decodeEventLog(parsed.eventFragment, data, topics);
|
241
|
+
};
|
242
|
+
event.event = parsed.name;
|
243
|
+
event.eventSignature = parsed.signature;
|
244
|
+
}
|
245
|
+
// Useful operations
|
246
|
+
event.removeListener = () => { return contract.provider; };
|
247
|
+
event.getBlock = () => {
|
248
|
+
return contract.provider.getBlock(receipt.blockHash);
|
249
|
+
};
|
250
|
+
event.getTransaction = () => {
|
251
|
+
return contract.provider.getTransaction(receipt.transactionHash);
|
252
|
+
};
|
253
|
+
event.getTransactionReceipt = () => {
|
254
|
+
return Promise.resolve(receipt);
|
255
|
+
};
|
256
|
+
return event;
|
257
|
+
});
|
258
|
+
return receipt;
|
259
|
+
});
|
260
|
+
};
|
261
|
+
}
|
262
|
+
function buildCall(contract, fragment, collapseSimple) {
|
263
|
+
const signerOrProvider = (contract.signer || contract.provider);
|
264
|
+
return function (...args) {
|
265
|
+
return __awaiter(this, undefined, undefined, function* () {
|
266
|
+
// Extract the "blockTag" override if present
|
267
|
+
let blockTag = undefined;
|
268
|
+
if (args.length === fragment.inputs.length + 1 && typeof (args[args.length - 1]) === "object") {
|
269
|
+
const overrides = shallowCopy(args.pop());
|
270
|
+
if (overrides.blockTag != null) {
|
271
|
+
blockTag = yield overrides.blockTag;
|
272
|
+
}
|
273
|
+
delete overrides.blockTag;
|
274
|
+
args.push(overrides);
|
275
|
+
}
|
276
|
+
// If the contract was just deployed, wait until it is mined
|
277
|
+
if (contract.deployTransaction != null) {
|
278
|
+
yield contract._deployed(blockTag);
|
279
|
+
}
|
280
|
+
// Call a node and get the result
|
281
|
+
const tx = yield populateTransaction(contract, fragment, args);
|
282
|
+
const result = yield signerOrProvider.call(tx, blockTag);
|
283
|
+
try {
|
284
|
+
let value = contract.interface.decodeFunctionResult(fragment, result);
|
285
|
+
if (collapseSimple && fragment.outputs.length === 1) {
|
286
|
+
value = value[0];
|
287
|
+
}
|
288
|
+
return value;
|
289
|
+
}
|
290
|
+
catch (error) {
|
291
|
+
if (error.code === Logger.errors.CALL_EXCEPTION) {
|
292
|
+
error.address = contract.address;
|
293
|
+
error.args = args;
|
294
|
+
error.transaction = tx;
|
295
|
+
}
|
296
|
+
throw error;
|
297
|
+
}
|
298
|
+
});
|
299
|
+
};
|
300
|
+
}
|
301
|
+
function buildSend(contract, fragment) {
|
302
|
+
return function (...args) {
|
303
|
+
return __awaiter(this, undefined, undefined, function* () {
|
304
|
+
if (!contract.signer) {
|
305
|
+
logger.throwError("sending a transaction requires a signer", Logger.errors.UNSUPPORTED_OPERATION, {
|
306
|
+
operation: "sendTransaction"
|
307
|
+
});
|
308
|
+
}
|
309
|
+
// If the contract was just deployed, wait until it is mined
|
310
|
+
if (contract.deployTransaction != null) {
|
311
|
+
yield contract._deployed();
|
312
|
+
}
|
313
|
+
const txRequest = yield populateTransaction(contract, fragment, args);
|
314
|
+
const tx = yield contract.signer.sendTransaction(txRequest);
|
315
|
+
// Tweak the tx.wait so the receipt has extra properties
|
316
|
+
addContractWait(contract, tx);
|
317
|
+
return tx;
|
318
|
+
});
|
319
|
+
};
|
320
|
+
}
|
321
|
+
function buildDefault(contract, fragment, collapseSimple) {
|
322
|
+
if (fragment.constant) {
|
323
|
+
return buildCall(contract, fragment, collapseSimple);
|
324
|
+
}
|
325
|
+
return buildSend(contract, fragment);
|
326
|
+
}
|
327
|
+
function getEventTag(filter) {
|
328
|
+
if (filter.address && (filter.topics == null || filter.topics.length === 0)) {
|
329
|
+
return "*";
|
330
|
+
}
|
331
|
+
return (filter.address || "*") + "@" + (filter.topics ? filter.topics.map((topic) => {
|
332
|
+
if (Array.isArray(topic)) {
|
333
|
+
return topic.join("|");
|
334
|
+
}
|
335
|
+
return topic;
|
336
|
+
}).join(":") : "");
|
337
|
+
}
|
338
|
+
class RunningEvent {
|
339
|
+
constructor(tag, filter) {
|
340
|
+
defineReadOnly(this, "tag", tag);
|
341
|
+
defineReadOnly(this, "filter", filter);
|
342
|
+
this._listeners = [];
|
343
|
+
}
|
344
|
+
addListener(listener, once) {
|
345
|
+
this._listeners.push({ listener: listener, once: once });
|
346
|
+
}
|
347
|
+
removeListener(listener) {
|
348
|
+
let done = false;
|
349
|
+
this._listeners = this._listeners.filter((item) => {
|
350
|
+
if (done || item.listener !== listener) {
|
351
|
+
return true;
|
352
|
+
}
|
353
|
+
done = true;
|
354
|
+
return false;
|
355
|
+
});
|
356
|
+
}
|
357
|
+
removeAllListeners() {
|
358
|
+
this._listeners = [];
|
359
|
+
}
|
360
|
+
listeners() {
|
361
|
+
return this._listeners.map((i) => i.listener);
|
362
|
+
}
|
363
|
+
listenerCount() {
|
364
|
+
return this._listeners.length;
|
365
|
+
}
|
366
|
+
run(args) {
|
367
|
+
const listenerCount = this.listenerCount();
|
368
|
+
this._listeners = this._listeners.filter((item) => {
|
369
|
+
const argsCopy = args.slice();
|
370
|
+
// Call the callback in the next event loop
|
371
|
+
setTimeout(() => {
|
372
|
+
item.listener.apply(this, argsCopy);
|
373
|
+
}, 0);
|
374
|
+
// Reschedule it if it not "once"
|
375
|
+
return !(item.once);
|
376
|
+
});
|
377
|
+
return listenerCount;
|
378
|
+
}
|
379
|
+
prepareEvent(event) {
|
380
|
+
}
|
381
|
+
// Returns the array that will be applied to an emit
|
382
|
+
getEmit(event) {
|
383
|
+
return [event];
|
384
|
+
}
|
385
|
+
}
|
386
|
+
class ErrorRunningEvent extends RunningEvent {
|
387
|
+
constructor() {
|
388
|
+
super("error", null);
|
389
|
+
}
|
390
|
+
}
|
391
|
+
// @TODO Fragment should inherit Wildcard? and just override getEmit?
|
392
|
+
// or have a common abstract super class, with enough constructor
|
393
|
+
// options to configure both.
|
394
|
+
// A Fragment Event will populate all the properties that Wildcard
|
395
|
+
// will, and additionally dereference the arguments when emitting
|
396
|
+
class FragmentRunningEvent extends RunningEvent {
|
397
|
+
constructor(address, contractInterface, fragment, topics) {
|
398
|
+
const filter = {
|
399
|
+
address: address
|
400
|
+
};
|
401
|
+
let topic = contractInterface.getEventTopic(fragment);
|
402
|
+
if (topics) {
|
403
|
+
if (topic !== topics[0]) {
|
404
|
+
logger.throwArgumentError("topic mismatch", "topics", topics);
|
405
|
+
}
|
406
|
+
filter.topics = topics.slice();
|
407
|
+
}
|
408
|
+
else {
|
409
|
+
filter.topics = [topic];
|
410
|
+
}
|
411
|
+
super(getEventTag(filter), filter);
|
412
|
+
defineReadOnly(this, "address", address);
|
413
|
+
defineReadOnly(this, "interface", contractInterface);
|
414
|
+
defineReadOnly(this, "fragment", fragment);
|
415
|
+
}
|
416
|
+
prepareEvent(event) {
|
417
|
+
super.prepareEvent(event);
|
418
|
+
event.event = this.fragment.name;
|
419
|
+
event.eventSignature = this.fragment.format();
|
420
|
+
event.decode = (data, topics) => {
|
421
|
+
return this.interface.decodeEventLog(this.fragment, data, topics);
|
422
|
+
};
|
423
|
+
try {
|
424
|
+
event.args = this.interface.decodeEventLog(this.fragment, event.data, event.topics);
|
425
|
+
}
|
426
|
+
catch (error) {
|
427
|
+
event.args = null;
|
428
|
+
event.decodeError = error;
|
429
|
+
}
|
430
|
+
}
|
431
|
+
getEmit(event) {
|
432
|
+
const errors = checkResultErrors(event.args);
|
433
|
+
if (errors.length) {
|
434
|
+
throw errors[0].error;
|
435
|
+
}
|
436
|
+
const args = (event.args || []).slice();
|
437
|
+
args.push(event);
|
438
|
+
return args;
|
439
|
+
}
|
440
|
+
}
|
441
|
+
// A Wildcard Event will attempt to populate:
|
442
|
+
// - event The name of the event name
|
443
|
+
// - eventSignature The full signature of the event
|
444
|
+
// - decode A function to decode data and topics
|
445
|
+
// - args The decoded data and topics
|
446
|
+
class WildcardRunningEvent extends RunningEvent {
|
447
|
+
constructor(address, contractInterface) {
|
448
|
+
super("*", { address: address });
|
449
|
+
defineReadOnly(this, "address", address);
|
450
|
+
defineReadOnly(this, "interface", contractInterface);
|
451
|
+
}
|
452
|
+
prepareEvent(event) {
|
453
|
+
super.prepareEvent(event);
|
454
|
+
try {
|
455
|
+
const parsed = this.interface.parseLog(event);
|
456
|
+
event.event = parsed.name;
|
457
|
+
event.eventSignature = parsed.signature;
|
458
|
+
event.decode = (data, topics) => {
|
459
|
+
return this.interface.decodeEventLog(parsed.eventFragment, data, topics);
|
460
|
+
};
|
461
|
+
event.args = parsed.args;
|
462
|
+
}
|
463
|
+
catch (error) {
|
464
|
+
// No matching event
|
465
|
+
}
|
466
|
+
}
|
467
|
+
}
|
468
|
+
class BaseContract {
|
469
|
+
constructor(addressOrName, contractInterface, signerOrProvider) {
|
470
|
+
// @TODO: Maybe still check the addressOrName looks like a valid address or name?
|
471
|
+
//address = getAddress(address);
|
472
|
+
defineReadOnly(this, "interface", getStatic(new.target, "getInterface")(contractInterface));
|
473
|
+
if (signerOrProvider == null) {
|
474
|
+
defineReadOnly(this, "provider", null);
|
475
|
+
defineReadOnly(this, "signer", null);
|
476
|
+
}
|
477
|
+
else if (Signer.isSigner(signerOrProvider)) {
|
478
|
+
defineReadOnly(this, "provider", signerOrProvider.provider || null);
|
479
|
+
defineReadOnly(this, "signer", signerOrProvider);
|
480
|
+
}
|
481
|
+
else if (Provider.isProvider(signerOrProvider)) {
|
482
|
+
defineReadOnly(this, "provider", signerOrProvider);
|
483
|
+
defineReadOnly(this, "signer", null);
|
484
|
+
}
|
485
|
+
else {
|
486
|
+
logger.throwArgumentError("invalid signer or provider", "signerOrProvider", signerOrProvider);
|
487
|
+
}
|
488
|
+
defineReadOnly(this, "callStatic", {});
|
489
|
+
defineReadOnly(this, "estimateGas", {});
|
490
|
+
defineReadOnly(this, "functions", {});
|
491
|
+
defineReadOnly(this, "populateTransaction", {});
|
492
|
+
defineReadOnly(this, "filters", {});
|
493
|
+
{
|
494
|
+
const uniqueFilters = {};
|
495
|
+
Object.keys(this.interface.events).forEach((eventSignature) => {
|
496
|
+
const event = this.interface.events[eventSignature];
|
497
|
+
defineReadOnly(this.filters, eventSignature, (...args) => {
|
498
|
+
return {
|
499
|
+
address: this.address,
|
500
|
+
topics: this.interface.encodeFilterTopics(event, args)
|
501
|
+
};
|
502
|
+
});
|
503
|
+
if (!uniqueFilters[event.name]) {
|
504
|
+
uniqueFilters[event.name] = [];
|
505
|
+
}
|
506
|
+
uniqueFilters[event.name].push(eventSignature);
|
507
|
+
});
|
508
|
+
Object.keys(uniqueFilters).forEach((name) => {
|
509
|
+
const filters = uniqueFilters[name];
|
510
|
+
if (filters.length === 1) {
|
511
|
+
defineReadOnly(this.filters, name, this.filters[filters[0]]);
|
512
|
+
}
|
513
|
+
else {
|
514
|
+
logger.warn(`Duplicate definition of ${name} (${filters.join(", ")})`);
|
515
|
+
}
|
516
|
+
});
|
517
|
+
}
|
518
|
+
defineReadOnly(this, "_runningEvents", {});
|
519
|
+
defineReadOnly(this, "_wrappedEmits", {});
|
520
|
+
if (addressOrName == null) {
|
521
|
+
logger.throwArgumentError("invalid contract address or ENS name", "addressOrName", addressOrName);
|
522
|
+
}
|
523
|
+
defineReadOnly(this, "address", addressOrName);
|
524
|
+
if (this.provider) {
|
525
|
+
defineReadOnly(this, "resolvedAddress", resolveName(this.provider, addressOrName));
|
526
|
+
}
|
527
|
+
else {
|
528
|
+
try {
|
529
|
+
defineReadOnly(this, "resolvedAddress", Promise.resolve(getAddress(addressOrName)));
|
530
|
+
}
|
531
|
+
catch (error) {
|
532
|
+
// Without a provider, we cannot use ENS names
|
533
|
+
logger.throwError("provider is required to use ENS name as contract address", Logger.errors.UNSUPPORTED_OPERATION, {
|
534
|
+
operation: "new Contract"
|
535
|
+
});
|
536
|
+
}
|
537
|
+
}
|
538
|
+
// Swallow bad ENS names to prevent Unhandled Exceptions
|
539
|
+
this.resolvedAddress.catch((e) => { });
|
540
|
+
const uniqueNames = {};
|
541
|
+
const uniqueSignatures = {};
|
542
|
+
Object.keys(this.interface.functions).forEach((signature) => {
|
543
|
+
const fragment = this.interface.functions[signature];
|
544
|
+
// Check that the signature is unique; if not the ABI generation has
|
545
|
+
// not been cleaned or may be incorrectly generated
|
546
|
+
if (uniqueSignatures[signature]) {
|
547
|
+
logger.warn(`Duplicate ABI entry for ${JSON.stringify(signature)}`);
|
548
|
+
return;
|
549
|
+
}
|
550
|
+
uniqueSignatures[signature] = true;
|
551
|
+
// Track unique names; we only expose bare named functions if they
|
552
|
+
// are ambiguous
|
553
|
+
{
|
554
|
+
const name = fragment.name;
|
555
|
+
if (!uniqueNames[`%${name}`]) {
|
556
|
+
uniqueNames[`%${name}`] = [];
|
557
|
+
}
|
558
|
+
uniqueNames[`%${name}`].push(signature);
|
559
|
+
}
|
560
|
+
if (this[signature] == null) {
|
561
|
+
defineReadOnly(this, signature, buildDefault(this, fragment, true));
|
562
|
+
}
|
563
|
+
// We do not collapse simple calls on this bucket, which allows
|
564
|
+
// frameworks to safely use this without introspection as well as
|
565
|
+
// allows decoding error recovery.
|
566
|
+
if (this.functions[signature] == null) {
|
567
|
+
defineReadOnly(this.functions, signature, buildDefault(this, fragment, false));
|
568
|
+
}
|
569
|
+
if (this.callStatic[signature] == null) {
|
570
|
+
defineReadOnly(this.callStatic, signature, buildCall(this, fragment, true));
|
571
|
+
}
|
572
|
+
if (this.populateTransaction[signature] == null) {
|
573
|
+
defineReadOnly(this.populateTransaction, signature, buildPopulate(this, fragment));
|
574
|
+
}
|
575
|
+
if (this.estimateGas[signature] == null) {
|
576
|
+
defineReadOnly(this.estimateGas, signature, buildEstimate(this, fragment));
|
577
|
+
}
|
578
|
+
});
|
579
|
+
Object.keys(uniqueNames).forEach((name) => {
|
580
|
+
// Ambiguous names to not get attached as bare names
|
581
|
+
const signatures = uniqueNames[name];
|
582
|
+
if (signatures.length > 1) {
|
583
|
+
return;
|
584
|
+
}
|
585
|
+
// Strip off the leading "%" used for prototype protection
|
586
|
+
name = name.substring(1);
|
587
|
+
const signature = signatures[0];
|
588
|
+
// If overwriting a member property that is null, swallow the error
|
589
|
+
try {
|
590
|
+
if (this[name] == null) {
|
591
|
+
defineReadOnly(this, name, this[signature]);
|
592
|
+
}
|
593
|
+
}
|
594
|
+
catch (e) { }
|
595
|
+
if (this.functions[name] == null) {
|
596
|
+
defineReadOnly(this.functions, name, this.functions[signature]);
|
597
|
+
}
|
598
|
+
if (this.callStatic[name] == null) {
|
599
|
+
defineReadOnly(this.callStatic, name, this.callStatic[signature]);
|
600
|
+
}
|
601
|
+
if (this.populateTransaction[name] == null) {
|
602
|
+
defineReadOnly(this.populateTransaction, name, this.populateTransaction[signature]);
|
603
|
+
}
|
604
|
+
if (this.estimateGas[name] == null) {
|
605
|
+
defineReadOnly(this.estimateGas, name, this.estimateGas[signature]);
|
606
|
+
}
|
607
|
+
});
|
608
|
+
}
|
609
|
+
static getContractAddress(transaction) {
|
610
|
+
return getContractAddress(transaction);
|
611
|
+
}
|
612
|
+
static getInterface(contractInterface) {
|
613
|
+
if (Interface.isInterface(contractInterface)) {
|
614
|
+
return contractInterface;
|
615
|
+
}
|
616
|
+
return new Interface(contractInterface);
|
617
|
+
}
|
618
|
+
// @TODO: Allow timeout?
|
619
|
+
deployed() {
|
620
|
+
return this._deployed();
|
621
|
+
}
|
622
|
+
_deployed(blockTag) {
|
623
|
+
if (!this._deployedPromise) {
|
624
|
+
// If we were just deployed, we know the transaction we should occur in
|
625
|
+
if (this.deployTransaction) {
|
626
|
+
this._deployedPromise = this.deployTransaction.wait().then(() => {
|
627
|
+
return this;
|
628
|
+
});
|
629
|
+
}
|
630
|
+
else {
|
631
|
+
// @TODO: Once we allow a timeout to be passed in, we will wait
|
632
|
+
// up to that many blocks for getCode
|
633
|
+
// Otherwise, poll for our code to be deployed
|
634
|
+
this._deployedPromise = this.provider.getCode(this.address, blockTag).then((code) => {
|
635
|
+
if (code === "0x") {
|
636
|
+
logger.throwError("contract not deployed", Logger.errors.UNSUPPORTED_OPERATION, {
|
637
|
+
contractAddress: this.address,
|
638
|
+
operation: "getDeployed"
|
639
|
+
});
|
640
|
+
}
|
641
|
+
return this;
|
642
|
+
});
|
643
|
+
}
|
644
|
+
}
|
645
|
+
return this._deployedPromise;
|
646
|
+
}
|
647
|
+
// @TODO:
|
648
|
+
// estimateFallback(overrides?: TransactionRequest): Promise<BigNumber>
|
649
|
+
// @TODO:
|
650
|
+
// estimateDeploy(bytecode: string, ...args): Promise<BigNumber>
|
651
|
+
fallback(overrides) {
|
652
|
+
if (!this.signer) {
|
653
|
+
logger.throwError("sending a transactions require a signer", Logger.errors.UNSUPPORTED_OPERATION, { operation: "sendTransaction(fallback)" });
|
654
|
+
}
|
655
|
+
const tx = shallowCopy(overrides || {});
|
656
|
+
["from", "to"].forEach(function (key) {
|
657
|
+
if (tx[key] == null) {
|
658
|
+
return;
|
659
|
+
}
|
660
|
+
logger.throwError("cannot override " + key, Logger.errors.UNSUPPORTED_OPERATION, { operation: key });
|
661
|
+
});
|
662
|
+
tx.to = this.resolvedAddress;
|
663
|
+
return this.deployed().then(() => {
|
664
|
+
return this.signer.sendTransaction(tx);
|
665
|
+
});
|
666
|
+
}
|
667
|
+
// Reconnect to a different signer or provider
|
668
|
+
connect(signerOrProvider) {
|
669
|
+
if (typeof (signerOrProvider) === "string") {
|
670
|
+
signerOrProvider = new VoidSigner(signerOrProvider, this.provider);
|
671
|
+
}
|
672
|
+
const contract = new (this.constructor)(this.address, this.interface, signerOrProvider);
|
673
|
+
if (this.deployTransaction) {
|
674
|
+
defineReadOnly(contract, "deployTransaction", this.deployTransaction);
|
675
|
+
}
|
676
|
+
return contract;
|
677
|
+
}
|
678
|
+
// Re-attach to a different on-chain instance of this contract
|
679
|
+
attach(addressOrName) {
|
680
|
+
return new (this.constructor)(addressOrName, this.interface, this.signer || this.provider);
|
681
|
+
}
|
682
|
+
static isIndexed(value) {
|
683
|
+
return Indexed.isIndexed(value);
|
684
|
+
}
|
685
|
+
_normalizeRunningEvent(runningEvent) {
|
686
|
+
// Already have an instance of this event running; we can re-use it
|
687
|
+
if (this._runningEvents[runningEvent.tag]) {
|
688
|
+
return this._runningEvents[runningEvent.tag];
|
689
|
+
}
|
690
|
+
return runningEvent;
|
691
|
+
}
|
692
|
+
_getRunningEvent(eventName) {
|
693
|
+
if (typeof (eventName) === "string") {
|
694
|
+
// Listen for "error" events (if your contract has an error event, include
|
695
|
+
// the full signature to bypass this special event keyword)
|
696
|
+
if (eventName === "error") {
|
697
|
+
return this._normalizeRunningEvent(new ErrorRunningEvent());
|
698
|
+
}
|
699
|
+
// Listen for any event that is registered
|
700
|
+
if (eventName === "event") {
|
701
|
+
return this._normalizeRunningEvent(new RunningEvent("event", null));
|
702
|
+
}
|
703
|
+
// Listen for any event
|
704
|
+
if (eventName === "*") {
|
705
|
+
return this._normalizeRunningEvent(new WildcardRunningEvent(this.address, this.interface));
|
706
|
+
}
|
707
|
+
// Get the event Fragment (throws if ambiguous/unknown event)
|
708
|
+
const fragment = this.interface.getEvent(eventName);
|
709
|
+
return this._normalizeRunningEvent(new FragmentRunningEvent(this.address, this.interface, fragment));
|
710
|
+
}
|
711
|
+
// We have topics to filter by...
|
712
|
+
if (eventName.topics && eventName.topics.length > 0) {
|
713
|
+
// Is it a known topichash? (throws if no matching topichash)
|
714
|
+
try {
|
715
|
+
const topic = eventName.topics[0];
|
716
|
+
if (typeof (topic) !== "string") {
|
717
|
+
throw new Error("invalid topic"); // @TODO: May happen for anonymous events
|
718
|
+
}
|
719
|
+
const fragment = this.interface.getEvent(topic);
|
720
|
+
return this._normalizeRunningEvent(new FragmentRunningEvent(this.address, this.interface, fragment, eventName.topics));
|
721
|
+
}
|
722
|
+
catch (error) { }
|
723
|
+
// Filter by the unknown topichash
|
724
|
+
const filter = {
|
725
|
+
address: this.address,
|
726
|
+
topics: eventName.topics
|
727
|
+
};
|
728
|
+
return this._normalizeRunningEvent(new RunningEvent(getEventTag(filter), filter));
|
729
|
+
}
|
730
|
+
return this._normalizeRunningEvent(new WildcardRunningEvent(this.address, this.interface));
|
731
|
+
}
|
732
|
+
_checkRunningEvents(runningEvent) {
|
733
|
+
if (runningEvent.listenerCount() === 0) {
|
734
|
+
delete this._runningEvents[runningEvent.tag];
|
735
|
+
// If we have a poller for this, remove it
|
736
|
+
const emit = this._wrappedEmits[runningEvent.tag];
|
737
|
+
if (emit && runningEvent.filter) {
|
738
|
+
this.provider.off(runningEvent.filter, emit);
|
739
|
+
delete this._wrappedEmits[runningEvent.tag];
|
740
|
+
}
|
741
|
+
}
|
742
|
+
}
|
743
|
+
// Subclasses can override this to gracefully recover
|
744
|
+
// from parse errors if they wish
|
745
|
+
_wrapEvent(runningEvent, log, listener) {
|
746
|
+
const event = deepCopy(log);
|
747
|
+
event.removeListener = () => {
|
748
|
+
if (!listener) {
|
749
|
+
return;
|
750
|
+
}
|
751
|
+
runningEvent.removeListener(listener);
|
752
|
+
this._checkRunningEvents(runningEvent);
|
753
|
+
};
|
754
|
+
event.getBlock = () => { return this.provider.getBlock(log.blockHash); };
|
755
|
+
event.getTransaction = () => { return this.provider.getTransaction(log.transactionHash); };
|
756
|
+
event.getTransactionReceipt = () => { return this.provider.getTransactionReceipt(log.transactionHash); };
|
757
|
+
// This may throw if the topics and data mismatch the signature
|
758
|
+
runningEvent.prepareEvent(event);
|
759
|
+
return event;
|
760
|
+
}
|
761
|
+
_addEventListener(runningEvent, listener, once) {
|
762
|
+
if (!this.provider) {
|
763
|
+
logger.throwError("events require a provider or a signer with a provider", Logger.errors.UNSUPPORTED_OPERATION, { operation: "once" });
|
764
|
+
}
|
765
|
+
runningEvent.addListener(listener, once);
|
766
|
+
// Track this running event and its listeners (may already be there; but no hard in updating)
|
767
|
+
this._runningEvents[runningEvent.tag] = runningEvent;
|
768
|
+
// If we are not polling the provider, start polling
|
769
|
+
if (!this._wrappedEmits[runningEvent.tag]) {
|
770
|
+
const wrappedEmit = (log) => {
|
771
|
+
let event = this._wrapEvent(runningEvent, log, listener);
|
772
|
+
// Try to emit the result for the parameterized event...
|
773
|
+
if (event.decodeError == null) {
|
774
|
+
try {
|
775
|
+
const args = runningEvent.getEmit(event);
|
776
|
+
this.emit(runningEvent.filter, ...args);
|
777
|
+
}
|
778
|
+
catch (error) {
|
779
|
+
event.decodeError = error.error;
|
780
|
+
}
|
781
|
+
}
|
782
|
+
// Always emit "event" for fragment-base events
|
783
|
+
if (runningEvent.filter != null) {
|
784
|
+
this.emit("event", event);
|
785
|
+
}
|
786
|
+
// Emit "error" if there was an error
|
787
|
+
if (event.decodeError != null) {
|
788
|
+
this.emit("error", event.decodeError, event);
|
789
|
+
}
|
790
|
+
};
|
791
|
+
this._wrappedEmits[runningEvent.tag] = wrappedEmit;
|
792
|
+
// Special events, like "error" do not have a filter
|
793
|
+
if (runningEvent.filter != null) {
|
794
|
+
this.provider.on(runningEvent.filter, wrappedEmit);
|
795
|
+
}
|
796
|
+
}
|
797
|
+
}
|
798
|
+
queryFilter(event, fromBlockOrBlockhash, toBlock) {
|
799
|
+
const runningEvent = this._getRunningEvent(event);
|
800
|
+
const filter = shallowCopy(runningEvent.filter);
|
801
|
+
if (typeof (fromBlockOrBlockhash) === "string" && isHexString(fromBlockOrBlockhash, 32)) {
|
802
|
+
if (toBlock != null) {
|
803
|
+
logger.throwArgumentError("cannot specify toBlock with blockhash", "toBlock", toBlock);
|
804
|
+
}
|
805
|
+
filter.blockHash = fromBlockOrBlockhash;
|
806
|
+
}
|
807
|
+
else {
|
808
|
+
filter.fromBlock = ((fromBlockOrBlockhash != null) ? fromBlockOrBlockhash : 0);
|
809
|
+
filter.toBlock = ((toBlock != null) ? toBlock : "latest");
|
810
|
+
}
|
811
|
+
return this.provider.getLogs(filter).then((logs) => {
|
812
|
+
return logs.map((log) => this._wrapEvent(runningEvent, log, null));
|
813
|
+
});
|
814
|
+
}
|
815
|
+
on(event, listener) {
|
816
|
+
this._addEventListener(this._getRunningEvent(event), listener, false);
|
817
|
+
return this;
|
818
|
+
}
|
819
|
+
once(event, listener) {
|
820
|
+
this._addEventListener(this._getRunningEvent(event), listener, true);
|
821
|
+
return this;
|
822
|
+
}
|
823
|
+
emit(eventName, ...args) {
|
824
|
+
if (!this.provider) {
|
825
|
+
return false;
|
826
|
+
}
|
827
|
+
const runningEvent = this._getRunningEvent(eventName);
|
828
|
+
const result = (runningEvent.run(args) > 0);
|
829
|
+
// May have drained all the "once" events; check for living events
|
830
|
+
this._checkRunningEvents(runningEvent);
|
831
|
+
return result;
|
832
|
+
}
|
833
|
+
listenerCount(eventName) {
|
834
|
+
if (!this.provider) {
|
835
|
+
return 0;
|
836
|
+
}
|
837
|
+
if (eventName == null) {
|
838
|
+
return Object.keys(this._runningEvents).reduce((accum, key) => {
|
839
|
+
return accum + this._runningEvents[key].listenerCount();
|
840
|
+
}, 0);
|
841
|
+
}
|
842
|
+
return this._getRunningEvent(eventName).listenerCount();
|
843
|
+
}
|
844
|
+
listeners(eventName) {
|
845
|
+
if (!this.provider) {
|
846
|
+
return [];
|
847
|
+
}
|
848
|
+
if (eventName == null) {
|
849
|
+
const result = [];
|
850
|
+
for (let tag in this._runningEvents) {
|
851
|
+
this._runningEvents[tag].listeners().forEach((listener) => {
|
852
|
+
result.push(listener);
|
853
|
+
});
|
854
|
+
}
|
855
|
+
return result;
|
856
|
+
}
|
857
|
+
return this._getRunningEvent(eventName).listeners();
|
858
|
+
}
|
859
|
+
removeAllListeners(eventName) {
|
860
|
+
if (!this.provider) {
|
861
|
+
return this;
|
862
|
+
}
|
863
|
+
if (eventName == null) {
|
864
|
+
for (const tag in this._runningEvents) {
|
865
|
+
const runningEvent = this._runningEvents[tag];
|
866
|
+
runningEvent.removeAllListeners();
|
867
|
+
this._checkRunningEvents(runningEvent);
|
868
|
+
}
|
869
|
+
return this;
|
870
|
+
}
|
871
|
+
// Delete any listeners
|
872
|
+
const runningEvent = this._getRunningEvent(eventName);
|
873
|
+
runningEvent.removeAllListeners();
|
874
|
+
this._checkRunningEvents(runningEvent);
|
875
|
+
return this;
|
876
|
+
}
|
877
|
+
off(eventName, listener) {
|
878
|
+
if (!this.provider) {
|
879
|
+
return this;
|
880
|
+
}
|
881
|
+
const runningEvent = this._getRunningEvent(eventName);
|
882
|
+
runningEvent.removeListener(listener);
|
883
|
+
this._checkRunningEvents(runningEvent);
|
884
|
+
return this;
|
885
|
+
}
|
886
|
+
removeListener(eventName, listener) {
|
887
|
+
return this.off(eventName, listener);
|
888
|
+
}
|
889
|
+
}
|
890
|
+
class Contract extends BaseContract {
|
891
|
+
}
|
892
|
+
|
893
|
+
export { BaseContract, Contract };
|