@waku/rln 0.0.1 → 0.0.2-c41b319.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -108
- package/bundle/_virtual/__node-resolve_empty.js +6 -0
- package/bundle/_virtual/_assert.js +3 -0
- package/bundle/_virtual/_commonjs-dynamic-modules.js +5 -0
- package/bundle/_virtual/_commonjsHelpers.js +32 -0
- package/bundle/_virtual/_node-resolve_empty.js +3 -0
- package/bundle/_virtual/_sha2.js +3 -0
- package/bundle/_virtual/_u64.js +3 -0
- package/bundle/_virtual/aes.js +3 -0
- package/bundle/_virtual/bn.js +3 -0
- package/bundle/_virtual/browser.js +3 -0
- package/bundle/_virtual/checksum.js +3 -0
- package/bundle/_virtual/cipher.js +3 -0
- package/bundle/_virtual/class.js +3 -0
- package/bundle/_virtual/common.js +3 -0
- package/bundle/_virtual/common2.js +3 -0
- package/bundle/_virtual/cryptoBrowser.js +3 -0
- package/bundle/_virtual/functional.js +3 -0
- package/bundle/_virtual/hash.js +3 -0
- package/bundle/_virtual/hmac.js +3 -0
- package/bundle/_virtual/index.js +3 -0
- package/bundle/_virtual/index2.js +6 -0
- package/bundle/_virtual/inherits_browser.js +3 -0
- package/bundle/_virtual/kdf.js +3 -0
- package/bundle/_virtual/lodash.js +3 -0
- package/bundle/_virtual/password.js +3 -0
- package/bundle/_virtual/pbkdf2.js +3 -0
- package/bundle/_virtual/pbkdf22.js +3 -0
- package/bundle/_virtual/random.js +3 -0
- package/bundle/_virtual/ripemd.js +3 -0
- package/bundle/_virtual/schema-validation-generated.js +3 -0
- package/bundle/_virtual/schema-validation.js +3 -0
- package/bundle/_virtual/scrypt.js +3 -0
- package/bundle/_virtual/scrypt2.js +3 -0
- package/bundle/_virtual/sha.js +3 -0
- package/bundle/_virtual/sha256.js +3 -0
- package/bundle/_virtual/sha2562.js +3 -0
- package/bundle/_virtual/sha3.js +3 -0
- package/bundle/_virtual/sha512.js +3 -0
- package/bundle/_virtual/types.js +3 -0
- package/bundle/_virtual/utils.js +3 -0
- package/bundle/_virtual/utils2.js +3 -0
- package/bundle/_virtual/utils3.js +3 -0
- package/bundle/index.js +12 -10
- package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +96 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +148 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +20 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +210 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +18 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +30 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +22 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +43 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +19 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +58 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +854 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +609 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +66 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +302 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +110 -0
- package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +20 -0
- package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +287 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +402 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +3 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +8 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +893 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +256 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +36 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +135 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +8 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +64 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +443 -0
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +8 -0
- package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +660 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +352 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +248 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +127 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +2007 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +422 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +674 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +132 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +8 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +2430 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +76 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +219 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +279 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +69 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +404 -0
- package/bundle/node_modules/@iden3/js-crypto/dist/browser/esm/index.js +7 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +15 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +20 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +92 -0
- package/bundle/node_modules/@noble/hashes/esm/_assert.js +37 -0
- package/bundle/node_modules/@noble/hashes/esm/_md.js +132 -0
- package/bundle/node_modules/@noble/hashes/esm/_u64.js +29 -0
- package/bundle/node_modules/@noble/hashes/esm/sha256.js +113 -0
- package/bundle/node_modules/@noble/hashes/esm/sha3.js +210 -0
- package/bundle/node_modules/@noble/hashes/esm/utils.js +144 -0
- package/bundle/node_modules/@stablelib/binary/lib/binary.js +22 -0
- package/bundle/node_modules/@stablelib/chacha/lib/chacha.js +245 -0
- package/bundle/node_modules/@stablelib/wipe/lib/wipe.js +26 -0
- package/bundle/node_modules/@waku/zerokit-rln-wasm/rln_wasm.js +756 -0
- package/bundle/node_modules/bech32/index.js +187 -0
- package/bundle/node_modules/bn.js/lib/bn.js +3361 -0
- package/bundle/node_modules/debug/src/browser.js +283 -0
- package/bundle/node_modules/debug/src/common.js +295 -0
- package/bundle/node_modules/ethereum-cryptography/esm/keccak.js +10 -0
- package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +6 -0
- package/bundle/node_modules/ethereum-cryptography/esm/utils.js +24 -0
- package/bundle/node_modules/hash.js/lib/hash/common.js +97 -0
- package/bundle/node_modules/hash.js/lib/hash/hmac.js +51 -0
- package/bundle/node_modules/hash.js/lib/hash/ripemd.js +152 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/1.js +81 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/224.js +33 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/256.js +113 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/384.js +39 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/512.js +336 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/common.js +53 -0
- package/bundle/node_modules/hash.js/lib/hash/sha.js +14 -0
- package/bundle/node_modules/hash.js/lib/hash/utils.js +282 -0
- package/bundle/node_modules/hash.js/lib/hash.js +33 -0
- package/bundle/node_modules/inherits/inherits_browser.js +33 -0
- package/bundle/node_modules/it-length-prefixed/dist/src/decode.js +6 -0
- package/bundle/node_modules/lodash/lodash.js +17207 -0
- package/bundle/node_modules/minimalistic-assert/index.js +13 -0
- package/bundle/node_modules/ms/index.js +172 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base.js +205 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base10.js +9 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base16.js +16 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base2.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base256emoji.js +41 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base32.js +58 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base36.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base58.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base64.js +28 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base8.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/identity.js +11 -0
- package/bundle/node_modules/multiformats/dist/src/basics.js +15 -0
- package/bundle/node_modules/multiformats/dist/src/bytes.js +18 -0
- package/bundle/node_modules/multiformats/dist/src/codecs/json.js +2 -0
- package/bundle/node_modules/multiformats/dist/src/vendor/base-x.js +170 -0
- package/bundle/node_modules/protons-runtime/dist/src/codec.js +20 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/enum.js +24 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/message.js +7 -0
- package/bundle/node_modules/protons-runtime/dist/src/decode.js +8 -0
- package/bundle/node_modules/protons-runtime/dist/src/encode.js +11 -0
- package/bundle/node_modules/protons-runtime/dist/src/index.js +30 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/float.js +54 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/longbits.js +175 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/pool.js +28 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/reader.js +367 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/utf8.js +99 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/writer.js +438 -0
- package/bundle/node_modules/uint8-varint/dist/src/index.js +124 -0
- package/bundle/node_modules/uint8arrays/dist/src/alloc.js +17 -0
- package/bundle/node_modules/uint8arrays/dist/src/from-string.js +19 -0
- package/bundle/node_modules/uint8arrays/dist/src/util/bases.js +49 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +21 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +18 -0
- package/bundle/packages/core/dist/lib/filter/filter.js +27 -0
- package/bundle/packages/core/dist/lib/light_push/light_push.js +27 -0
- package/bundle/packages/core/dist/lib/message/version_0.js +154 -0
- package/bundle/packages/core/dist/lib/metadata/metadata.js +27 -0
- package/bundle/packages/core/dist/lib/store/store.js +27 -0
- package/bundle/packages/interfaces/dist/connection_manager.js +19 -0
- package/bundle/packages/interfaces/dist/constants.js +6 -0
- package/bundle/packages/interfaces/dist/health_indicator.js +12 -0
- package/bundle/packages/interfaces/dist/protocols.js +97 -0
- package/bundle/packages/proto/dist/generated/filter.js +445 -0
- package/bundle/packages/proto/dist/generated/filter_v2.js +424 -0
- package/bundle/packages/proto/dist/generated/light_push.js +389 -0
- package/bundle/packages/proto/dist/generated/message.js +213 -0
- package/bundle/packages/proto/dist/generated/metadata.js +130 -0
- package/bundle/packages/proto/dist/generated/peer_exchange.js +209 -0
- package/bundle/packages/proto/dist/generated/sds_message.js +105 -0
- package/bundle/packages/proto/dist/generated/store_v3.js +490 -0
- package/bundle/packages/proto/dist/generated/topic_only_message.js +61 -0
- package/bundle/packages/rln/dist/codec.js +93 -0
- package/bundle/packages/rln/dist/contract/abi/rlnv2.js +394 -0
- package/bundle/packages/rln/dist/contract/constants.js +33 -0
- package/bundle/packages/rln/dist/contract/rln_contract.js +427 -0
- package/bundle/packages/rln/dist/create.js +9 -0
- package/bundle/packages/rln/dist/identity.js +54 -0
- package/bundle/packages/rln/dist/keystore/cipher.js +31 -0
- package/bundle/packages/rln/dist/keystore/credential_validation_generated.js +119 -0
- package/bundle/packages/rln/dist/keystore/keystore.js +223 -0
- package/bundle/packages/rln/dist/keystore/keystore_validation_generated.js +74 -0
- package/bundle/packages/rln/dist/keystore/schema_validator.js +20 -0
- package/bundle/packages/rln/dist/message.js +51 -0
- package/bundle/packages/rln/dist/proof.js +54 -0
- package/bundle/packages/rln/dist/resources/verification_key.js +112 -0
- package/bundle/packages/rln/dist/resources/witness_calculator.js +330 -0
- package/bundle/packages/rln/dist/rln.js +204 -0
- package/bundle/packages/rln/dist/root_tracker.js +76 -0
- package/bundle/packages/rln/dist/utils/bytes.js +65 -0
- package/bundle/packages/rln/dist/utils/epoch.js +39 -0
- package/bundle/packages/rln/dist/utils/hash.js +10 -0
- package/bundle/packages/rln/dist/utils/metamask.js +14 -0
- package/bundle/packages/rln/dist/zerokit.js +122 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +52 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +65 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +99 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/index.js +28 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +78 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1253 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +40 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/types.js +5 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +41 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +23 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +12 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +77 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +9 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +215 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +35 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +21 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +66 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +24 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +7 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +11 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +52 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +124 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +71 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +10 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +88 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +99 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +233 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +133 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +243 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +167 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/native.js +4 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/rng.js +13 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/stringify.js +28 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/v4.js +19 -0
- package/bundle/packages/utils/dist/bytes/index.js +44 -0
- package/bundle/packages/utils/dist/common/sharding/index.js +91 -0
- package/bundle/packages/utils/dist/logger/index.js +31 -0
- package/bundle/resources/rln.wasm +0 -0
- package/bundle/resources/rln_final.zkey +0 -0
- package/bundle/resources/verification_key.d.ts +13 -0
- package/bundle/resources/verification_key.js +112 -0
- package/bundle/resources/witness_calculator.d.ts +11 -0
- package/bundle/resources/witness_calculator.js +328 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/codec.d.ts +39 -0
- package/dist/codec.js +77 -0
- package/dist/codec.js.map +1 -0
- package/dist/contract/abi/rlnv2.d.ts +42 -0
- package/dist/contract/abi/rlnv2.js +393 -0
- package/dist/contract/abi/rlnv2.js.map +1 -0
- package/dist/contract/constants.d.ts +68 -0
- package/dist/contract/constants.js +31 -0
- package/dist/contract/constants.js.map +1 -0
- package/dist/contract/index.d.ts +2 -0
- package/dist/contract/index.js +3 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/rln_contract.d.ts +119 -0
- package/dist/contract/rln_contract.js +421 -0
- package/dist/contract/rln_contract.js.map +1 -0
- package/dist/create.d.ts +2 -0
- package/dist/create.js +8 -0
- package/dist/create.js.map +1 -0
- package/dist/identity.d.ts +10 -0
- package/dist/identity.js +51 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/dist/keystore/cipher.d.ts +4 -0
- package/dist/keystore/cipher.js +28 -0
- package/dist/keystore/cipher.js.map +1 -0
- package/dist/keystore/credential_validation_generated.d.ts +8 -0
- package/dist/keystore/credential_validation_generated.js +121 -0
- package/dist/keystore/credential_validation_generated.js.map +1 -0
- package/dist/keystore/index.d.ts +4 -0
- package/dist/keystore/index.js +3 -0
- package/dist/keystore/index.js.map +1 -0
- package/dist/keystore/keystore.d.ts +50 -0
- package/dist/keystore/keystore.js +205 -0
- package/dist/keystore/keystore.js.map +1 -0
- package/dist/keystore/keystore_validation_generated.d.ts +8 -0
- package/dist/keystore/keystore_validation_generated.js +75 -0
- package/dist/keystore/keystore_validation_generated.js.map +1 -0
- package/dist/keystore/schema_validator.d.ts +2 -0
- package/dist/keystore/schema_validator.js +18 -0
- package/dist/keystore/schema_validator.js.map +1 -0
- package/dist/keystore/types.d.ts +29 -0
- package/dist/keystore/types.js +2 -0
- package/dist/keystore/types.js.map +1 -0
- package/dist/message.d.ts +18 -0
- package/dist/message.js +49 -0
- package/dist/message.js.map +1 -0
- package/dist/proof.d.ts +21 -0
- package/dist/proof.js +50 -0
- package/dist/proof.js.map +1 -0
- package/dist/resources/rln.wasm +0 -0
- package/dist/resources/rln_final.zkey +0 -0
- package/dist/resources/verification_key.d.ts +13 -0
- package/dist/resources/verification_key.js +112 -0
- package/dist/resources/witness_calculator.d.ts +11 -0
- package/dist/resources/witness_calculator.js +328 -0
- package/dist/rln.d.ts +59 -13
- package/dist/rln.js +164 -81
- package/dist/rln.js.map +1 -1
- package/dist/root_tracker.d.ts +10 -0
- package/dist/root_tracker.js +75 -0
- package/dist/root_tracker.js.map +1 -0
- package/dist/utils/bytes.d.ts +20 -0
- package/dist/utils/bytes.js +64 -0
- package/dist/utils/bytes.js.map +1 -0
- package/dist/utils/epoch.d.ts +3 -0
- package/dist/utils/epoch.js +23 -0
- package/dist/utils/epoch.js.map +1 -0
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.js +13 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/metamask.d.ts +2 -0
- package/dist/utils/metamask.js +12 -0
- package/dist/utils/metamask.js.map +1 -0
- package/dist/zerokit.d.ts +19 -0
- package/dist/zerokit.js +119 -0
- package/dist/zerokit.js.map +1 -0
- package/package.json +1 -126
- package/src/codec.ts +134 -0
- package/src/contract/abi/rlnv2.ts +392 -0
- package/src/contract/constants.ts +35 -0
- package/src/contract/index.ts +2 -0
- package/src/contract/rln_contract.ts +673 -0
- package/src/create.ts +9 -0
- package/src/identity.ts +73 -0
- package/src/index.ts +24 -10
- package/src/keystore/cipher.ts +54 -0
- package/src/keystore/credential_validation_generated.ts +7 -0
- package/src/keystore/index.ts +5 -0
- package/src/keystore/keystore.ts +330 -0
- package/src/keystore/keystore_validation_generated.ts +7 -0
- package/src/keystore/schema_validator.ts +34 -0
- package/src/keystore/types.ts +36 -0
- package/src/message.ts +70 -0
- package/src/proof.ts +69 -0
- package/src/resources/verification_key.d.ts +13 -0
- package/src/resources/witness_calculator.d.ts +11 -0
- package/src/rln.ts +270 -106
- package/src/root_tracker.ts +92 -0
- package/src/utils/bytes.ts +84 -0
- package/src/utils/epoch.ts +30 -0
- package/src/utils/hash.ts +15 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/metamask.ts +17 -0
- package/src/zerokit.ts +214 -0
- package/bundle/02bce7e5f3bcf834.wasm +0 -0
- package/bundle/rln-f87f6dbe.js +0 -563
- package/dist/resources.d.ts +0 -4
- package/dist/resources.js +0 -5
- package/dist/resources.js.map +0 -1
- package/dist/witness_calculator.d.ts +0 -16
- package/dist/witness_calculator.js +0 -291
- package/dist/witness_calculator.js.map +0 -1
- package/dist/zerokit/rln_wasm.d.ts +0 -1
- package/dist/zerokit/rln_wasm.js +0 -2
- package/dist/zerokit/rln_wasm.js.map +0 -1
- package/dist/zerokit/rln_wasm_bg.d.ts +0 -108
- package/dist/zerokit/rln_wasm_bg.js +0 -592
- package/dist/zerokit/rln_wasm_bg.js.map +0 -1
- package/dist/zerokit/rln_wasm_bg.wasm +0 -0
- package/src/resources.ts +0 -10
- package/src/witness_calculator.d.ts +0 -4
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
import { Signer } from '../../abstract-signer/lib.esm/index.js';
|
|
2
|
+
import { hexZeroPad, hexValue, hexlify, isHexString } from '../../bytes/lib.esm/index.js';
|
|
3
|
+
import { TypedDataEncoder } from '../../hash/lib.esm/typed-data.js';
|
|
4
|
+
import { getStatic, defineReadOnly, shallowCopy, deepCopy, checkProperties, resolveProperties } from '../../properties/lib.esm/index.js';
|
|
5
|
+
import { toUtf8Bytes } from '../../strings/lib.esm/utf8.js';
|
|
6
|
+
import { accessListify } from '../../transactions/lib.esm/index.js';
|
|
7
|
+
import { fetchJson, poll } from '../../web/lib.esm/index.js';
|
|
8
|
+
import { Logger } from '../../logger/lib.esm/index.js';
|
|
9
|
+
import { version } from './_version.js';
|
|
10
|
+
import { BaseProvider } from './base-provider.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
|
+
const errorGas = ["call", "estimateGas"];
|
|
24
|
+
function spelunk(value, requireData) {
|
|
25
|
+
if (value == null) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
// These *are* the droids we're looking for.
|
|
29
|
+
if (typeof (value.message) === "string" && value.message.match("reverted")) {
|
|
30
|
+
const data = isHexString(value.data) ? value.data : null;
|
|
31
|
+
if (!requireData || data) {
|
|
32
|
+
return { message: value.message, data };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Spelunk further...
|
|
36
|
+
if (typeof (value) === "object") {
|
|
37
|
+
for (const key in value) {
|
|
38
|
+
const result = spelunk(value[key], requireData);
|
|
39
|
+
if (result) {
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
// Might be a JSON string we can further descend...
|
|
46
|
+
if (typeof (value) === "string") {
|
|
47
|
+
try {
|
|
48
|
+
return spelunk(JSON.parse(value), requireData);
|
|
49
|
+
}
|
|
50
|
+
catch (error) { }
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function checkError(method, error, params) {
|
|
55
|
+
const transaction = params.transaction || params.signedTransaction;
|
|
56
|
+
// Undo the "convenience" some nodes are attempting to prevent backwards
|
|
57
|
+
// incompatibility; maybe for v6 consider forwarding reverts as errors
|
|
58
|
+
if (method === "call") {
|
|
59
|
+
const result = spelunk(error, true);
|
|
60
|
+
if (result) {
|
|
61
|
+
return result.data;
|
|
62
|
+
}
|
|
63
|
+
// Nothing descriptive..
|
|
64
|
+
logger.throwError("missing revert data in call exception; Transaction reverted without a reason string", Logger.errors.CALL_EXCEPTION, {
|
|
65
|
+
data: "0x", transaction, error
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (method === "estimateGas") {
|
|
69
|
+
// Try to find something, with a preference on SERVER_ERROR body
|
|
70
|
+
let result = spelunk(error.body, false);
|
|
71
|
+
if (result == null) {
|
|
72
|
+
result = spelunk(error, false);
|
|
73
|
+
}
|
|
74
|
+
// Found "reverted", this is a CALL_EXCEPTION
|
|
75
|
+
if (result) {
|
|
76
|
+
logger.throwError("cannot estimate gas; transaction may fail or may require manual gas limit", Logger.errors.UNPREDICTABLE_GAS_LIMIT, {
|
|
77
|
+
reason: result.message, method, transaction, error
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// @TODO: Should we spelunk for message too?
|
|
82
|
+
let message = error.message;
|
|
83
|
+
if (error.code === Logger.errors.SERVER_ERROR && error.error && typeof (error.error.message) === "string") {
|
|
84
|
+
message = error.error.message;
|
|
85
|
+
}
|
|
86
|
+
else if (typeof (error.body) === "string") {
|
|
87
|
+
message = error.body;
|
|
88
|
+
}
|
|
89
|
+
else if (typeof (error.responseText) === "string") {
|
|
90
|
+
message = error.responseText;
|
|
91
|
+
}
|
|
92
|
+
message = (message || "").toLowerCase();
|
|
93
|
+
// "insufficient funds for gas * price + value + cost(data)"
|
|
94
|
+
if (message.match(/insufficient funds|base fee exceeds gas limit|InsufficientFunds/i)) {
|
|
95
|
+
logger.throwError("insufficient funds for intrinsic transaction cost", Logger.errors.INSUFFICIENT_FUNDS, {
|
|
96
|
+
error, method, transaction
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// "nonce too low"
|
|
100
|
+
if (message.match(/nonce (is )?too low/i)) {
|
|
101
|
+
logger.throwError("nonce has already been used", Logger.errors.NONCE_EXPIRED, {
|
|
102
|
+
error, method, transaction
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// "replacement transaction underpriced"
|
|
106
|
+
if (message.match(/replacement transaction underpriced|transaction gas price.*too low/i)) {
|
|
107
|
+
logger.throwError("replacement fee too low", Logger.errors.REPLACEMENT_UNDERPRICED, {
|
|
108
|
+
error, method, transaction
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
// "replacement transaction underpriced"
|
|
112
|
+
if (message.match(/only replay-protected/i)) {
|
|
113
|
+
logger.throwError("legacy pre-eip-155 transactions not supported", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
114
|
+
error, method, transaction
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
if (errorGas.indexOf(method) >= 0 && message.match(/gas required exceeds allowance|always failing transaction|execution reverted|revert/)) {
|
|
118
|
+
logger.throwError("cannot estimate gas; transaction may fail or may require manual gas limit", Logger.errors.UNPREDICTABLE_GAS_LIMIT, {
|
|
119
|
+
error, method, transaction
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
function timer(timeout) {
|
|
125
|
+
return new Promise(function (resolve) {
|
|
126
|
+
setTimeout(resolve, timeout);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function getResult(payload) {
|
|
130
|
+
if (payload.error) {
|
|
131
|
+
// @TODO: not any
|
|
132
|
+
const error = new Error(payload.error.message);
|
|
133
|
+
error.code = payload.error.code;
|
|
134
|
+
error.data = payload.error.data;
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
return payload.result;
|
|
138
|
+
}
|
|
139
|
+
function getLowerCase(value) {
|
|
140
|
+
if (value) {
|
|
141
|
+
return value.toLowerCase();
|
|
142
|
+
}
|
|
143
|
+
return value;
|
|
144
|
+
}
|
|
145
|
+
const _constructorGuard = {};
|
|
146
|
+
class JsonRpcSigner extends Signer {
|
|
147
|
+
constructor(constructorGuard, provider, addressOrIndex) {
|
|
148
|
+
super();
|
|
149
|
+
if (constructorGuard !== _constructorGuard) {
|
|
150
|
+
throw new Error("do not call the JsonRpcSigner constructor directly; use provider.getSigner");
|
|
151
|
+
}
|
|
152
|
+
defineReadOnly(this, "provider", provider);
|
|
153
|
+
if (addressOrIndex == null) {
|
|
154
|
+
addressOrIndex = 0;
|
|
155
|
+
}
|
|
156
|
+
if (typeof (addressOrIndex) === "string") {
|
|
157
|
+
defineReadOnly(this, "_address", this.provider.formatter.address(addressOrIndex));
|
|
158
|
+
defineReadOnly(this, "_index", null);
|
|
159
|
+
}
|
|
160
|
+
else if (typeof (addressOrIndex) === "number") {
|
|
161
|
+
defineReadOnly(this, "_index", addressOrIndex);
|
|
162
|
+
defineReadOnly(this, "_address", null);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
logger.throwArgumentError("invalid address or index", "addressOrIndex", addressOrIndex);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
connect(provider) {
|
|
169
|
+
return logger.throwError("cannot alter JSON-RPC Signer connection", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
170
|
+
operation: "connect"
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
connectUnchecked() {
|
|
174
|
+
return new UncheckedJsonRpcSigner(_constructorGuard, this.provider, this._address || this._index);
|
|
175
|
+
}
|
|
176
|
+
getAddress() {
|
|
177
|
+
if (this._address) {
|
|
178
|
+
return Promise.resolve(this._address);
|
|
179
|
+
}
|
|
180
|
+
return this.provider.send("eth_accounts", []).then((accounts) => {
|
|
181
|
+
if (accounts.length <= this._index) {
|
|
182
|
+
logger.throwError("unknown account #" + this._index, Logger.errors.UNSUPPORTED_OPERATION, {
|
|
183
|
+
operation: "getAddress"
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return this.provider.formatter.address(accounts[this._index]);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
sendUncheckedTransaction(transaction) {
|
|
190
|
+
transaction = shallowCopy(transaction);
|
|
191
|
+
const fromAddress = this.getAddress().then((address) => {
|
|
192
|
+
if (address) {
|
|
193
|
+
address = address.toLowerCase();
|
|
194
|
+
}
|
|
195
|
+
return address;
|
|
196
|
+
});
|
|
197
|
+
// The JSON-RPC for eth_sendTransaction uses 90000 gas; if the user
|
|
198
|
+
// wishes to use this, it is easy to specify explicitly, otherwise
|
|
199
|
+
// we look it up for them.
|
|
200
|
+
if (transaction.gasLimit == null) {
|
|
201
|
+
const estimate = shallowCopy(transaction);
|
|
202
|
+
estimate.from = fromAddress;
|
|
203
|
+
transaction.gasLimit = this.provider.estimateGas(estimate);
|
|
204
|
+
}
|
|
205
|
+
if (transaction.to != null) {
|
|
206
|
+
transaction.to = Promise.resolve(transaction.to).then((to) => __awaiter(this, undefined, undefined, function* () {
|
|
207
|
+
if (to == null) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
const address = yield this.provider.resolveName(to);
|
|
211
|
+
if (address == null) {
|
|
212
|
+
logger.throwArgumentError("provided ENS name resolves to null", "tx.to", to);
|
|
213
|
+
}
|
|
214
|
+
return address;
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
return resolveProperties({
|
|
218
|
+
tx: resolveProperties(transaction),
|
|
219
|
+
sender: fromAddress
|
|
220
|
+
}).then(({ tx, sender }) => {
|
|
221
|
+
if (tx.from != null) {
|
|
222
|
+
if (tx.from.toLowerCase() !== sender) {
|
|
223
|
+
logger.throwArgumentError("from address mismatch", "transaction", transaction);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
tx.from = sender;
|
|
228
|
+
}
|
|
229
|
+
const hexTx = this.provider.constructor.hexlifyTransaction(tx, { from: true });
|
|
230
|
+
return this.provider.send("eth_sendTransaction", [hexTx]).then((hash) => {
|
|
231
|
+
return hash;
|
|
232
|
+
}, (error) => {
|
|
233
|
+
if (typeof (error.message) === "string" && error.message.match(/user denied/i)) {
|
|
234
|
+
logger.throwError("user rejected transaction", Logger.errors.ACTION_REJECTED, {
|
|
235
|
+
action: "sendTransaction",
|
|
236
|
+
transaction: tx
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return checkError("sendTransaction", error, hexTx);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
signTransaction(transaction) {
|
|
244
|
+
return logger.throwError("signing transactions is unsupported", Logger.errors.UNSUPPORTED_OPERATION, {
|
|
245
|
+
operation: "signTransaction"
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
sendTransaction(transaction) {
|
|
249
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
250
|
+
// This cannot be mined any earlier than any recent block
|
|
251
|
+
const blockNumber = yield this.provider._getInternalBlockNumber(100 + 2 * this.provider.pollingInterval);
|
|
252
|
+
// Send the transaction
|
|
253
|
+
const hash = yield this.sendUncheckedTransaction(transaction);
|
|
254
|
+
try {
|
|
255
|
+
// Unfortunately, JSON-RPC only provides and opaque transaction hash
|
|
256
|
+
// for a response, and we need the actual transaction, so we poll
|
|
257
|
+
// for it; it should show up very quickly
|
|
258
|
+
return yield poll(() => __awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
const tx = yield this.provider.getTransaction(hash);
|
|
260
|
+
if (tx === null) {
|
|
261
|
+
return undefined;
|
|
262
|
+
}
|
|
263
|
+
return this.provider._wrapTransaction(tx, hash, blockNumber);
|
|
264
|
+
}), { oncePoll: this.provider });
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
error.transactionHash = hash;
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
signMessage(message) {
|
|
273
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
274
|
+
const data = ((typeof (message) === "string") ? toUtf8Bytes(message) : message);
|
|
275
|
+
const address = yield this.getAddress();
|
|
276
|
+
try {
|
|
277
|
+
return yield this.provider.send("personal_sign", [hexlify(data), address.toLowerCase()]);
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
if (typeof (error.message) === "string" && error.message.match(/user denied/i)) {
|
|
281
|
+
logger.throwError("user rejected signing", Logger.errors.ACTION_REJECTED, {
|
|
282
|
+
action: "signMessage",
|
|
283
|
+
from: address,
|
|
284
|
+
messageData: message
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
_legacySignMessage(message) {
|
|
292
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
293
|
+
const data = ((typeof (message) === "string") ? toUtf8Bytes(message) : message);
|
|
294
|
+
const address = yield this.getAddress();
|
|
295
|
+
try {
|
|
296
|
+
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
|
|
297
|
+
return yield this.provider.send("eth_sign", [address.toLowerCase(), hexlify(data)]);
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
if (typeof (error.message) === "string" && error.message.match(/user denied/i)) {
|
|
301
|
+
logger.throwError("user rejected signing", Logger.errors.ACTION_REJECTED, {
|
|
302
|
+
action: "_legacySignMessage",
|
|
303
|
+
from: address,
|
|
304
|
+
messageData: message
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
_signTypedData(domain, types, value) {
|
|
312
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
313
|
+
// Populate any ENS names (in-place)
|
|
314
|
+
const populated = yield TypedDataEncoder.resolveNames(domain, types, value, (name) => {
|
|
315
|
+
return this.provider.resolveName(name);
|
|
316
|
+
});
|
|
317
|
+
const address = yield this.getAddress();
|
|
318
|
+
try {
|
|
319
|
+
return yield this.provider.send("eth_signTypedData_v4", [
|
|
320
|
+
address.toLowerCase(),
|
|
321
|
+
JSON.stringify(TypedDataEncoder.getPayload(populated.domain, types, populated.value))
|
|
322
|
+
]);
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
if (typeof (error.message) === "string" && error.message.match(/user denied/i)) {
|
|
326
|
+
logger.throwError("user rejected signing", Logger.errors.ACTION_REJECTED, {
|
|
327
|
+
action: "_signTypedData",
|
|
328
|
+
from: address,
|
|
329
|
+
messageData: { domain: populated.domain, types, value: populated.value }
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
throw error;
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
unlock(password) {
|
|
337
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
338
|
+
const provider = this.provider;
|
|
339
|
+
const address = yield this.getAddress();
|
|
340
|
+
return provider.send("personal_unlockAccount", [address.toLowerCase(), password, null]);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
class UncheckedJsonRpcSigner extends JsonRpcSigner {
|
|
345
|
+
sendTransaction(transaction) {
|
|
346
|
+
return this.sendUncheckedTransaction(transaction).then((hash) => {
|
|
347
|
+
return {
|
|
348
|
+
hash: hash,
|
|
349
|
+
nonce: null,
|
|
350
|
+
gasLimit: null,
|
|
351
|
+
gasPrice: null,
|
|
352
|
+
data: null,
|
|
353
|
+
value: null,
|
|
354
|
+
chainId: null,
|
|
355
|
+
confirmations: 0,
|
|
356
|
+
from: null,
|
|
357
|
+
wait: (confirmations) => { return this.provider.waitForTransaction(hash, confirmations); }
|
|
358
|
+
};
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
const allowedTransactionKeys = {
|
|
363
|
+
chainId: true, data: true, gasLimit: true, gasPrice: true, nonce: true, to: true, value: true,
|
|
364
|
+
type: true, accessList: true,
|
|
365
|
+
maxFeePerGas: true, maxPriorityFeePerGas: true
|
|
366
|
+
};
|
|
367
|
+
class JsonRpcProvider extends BaseProvider {
|
|
368
|
+
constructor(url, network) {
|
|
369
|
+
let networkOrReady = network;
|
|
370
|
+
// The network is unknown, query the JSON-RPC for it
|
|
371
|
+
if (networkOrReady == null) {
|
|
372
|
+
networkOrReady = new Promise((resolve, reject) => {
|
|
373
|
+
setTimeout(() => {
|
|
374
|
+
this.detectNetwork().then((network) => {
|
|
375
|
+
resolve(network);
|
|
376
|
+
}, (error) => {
|
|
377
|
+
reject(error);
|
|
378
|
+
});
|
|
379
|
+
}, 0);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
super(networkOrReady);
|
|
383
|
+
// Default URL
|
|
384
|
+
if (!url) {
|
|
385
|
+
url = getStatic(this.constructor, "defaultUrl")();
|
|
386
|
+
}
|
|
387
|
+
if (typeof (url) === "string") {
|
|
388
|
+
defineReadOnly(this, "connection", Object.freeze({
|
|
389
|
+
url: url
|
|
390
|
+
}));
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
defineReadOnly(this, "connection", Object.freeze(shallowCopy(url)));
|
|
394
|
+
}
|
|
395
|
+
this._nextId = 42;
|
|
396
|
+
}
|
|
397
|
+
get _cache() {
|
|
398
|
+
if (this._eventLoopCache == null) {
|
|
399
|
+
this._eventLoopCache = {};
|
|
400
|
+
}
|
|
401
|
+
return this._eventLoopCache;
|
|
402
|
+
}
|
|
403
|
+
static defaultUrl() {
|
|
404
|
+
return "http:/\/localhost:8545";
|
|
405
|
+
}
|
|
406
|
+
detectNetwork() {
|
|
407
|
+
if (!this._cache["detectNetwork"]) {
|
|
408
|
+
this._cache["detectNetwork"] = this._uncachedDetectNetwork();
|
|
409
|
+
// Clear this cache at the beginning of the next event loop
|
|
410
|
+
setTimeout(() => {
|
|
411
|
+
this._cache["detectNetwork"] = null;
|
|
412
|
+
}, 0);
|
|
413
|
+
}
|
|
414
|
+
return this._cache["detectNetwork"];
|
|
415
|
+
}
|
|
416
|
+
_uncachedDetectNetwork() {
|
|
417
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
418
|
+
yield timer(0);
|
|
419
|
+
let chainId = null;
|
|
420
|
+
try {
|
|
421
|
+
chainId = yield this.send("eth_chainId", []);
|
|
422
|
+
}
|
|
423
|
+
catch (error) {
|
|
424
|
+
try {
|
|
425
|
+
chainId = yield this.send("net_version", []);
|
|
426
|
+
}
|
|
427
|
+
catch (error) { }
|
|
428
|
+
}
|
|
429
|
+
if (chainId != null) {
|
|
430
|
+
const getNetwork = getStatic(this.constructor, "getNetwork");
|
|
431
|
+
try {
|
|
432
|
+
return getNetwork(BigNumber.from(chainId).toNumber());
|
|
433
|
+
}
|
|
434
|
+
catch (error) {
|
|
435
|
+
return logger.throwError("could not detect network", Logger.errors.NETWORK_ERROR, {
|
|
436
|
+
chainId: chainId,
|
|
437
|
+
event: "invalidNetwork",
|
|
438
|
+
serverError: error
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return logger.throwError("could not detect network", Logger.errors.NETWORK_ERROR, {
|
|
443
|
+
event: "noNetwork"
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
getSigner(addressOrIndex) {
|
|
448
|
+
return new JsonRpcSigner(_constructorGuard, this, addressOrIndex);
|
|
449
|
+
}
|
|
450
|
+
getUncheckedSigner(addressOrIndex) {
|
|
451
|
+
return this.getSigner(addressOrIndex).connectUnchecked();
|
|
452
|
+
}
|
|
453
|
+
listAccounts() {
|
|
454
|
+
return this.send("eth_accounts", []).then((accounts) => {
|
|
455
|
+
return accounts.map((a) => this.formatter.address(a));
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
send(method, params) {
|
|
459
|
+
const request = {
|
|
460
|
+
method: method,
|
|
461
|
+
params: params,
|
|
462
|
+
id: (this._nextId++),
|
|
463
|
+
jsonrpc: "2.0"
|
|
464
|
+
};
|
|
465
|
+
this.emit("debug", {
|
|
466
|
+
action: "request",
|
|
467
|
+
request: deepCopy(request),
|
|
468
|
+
provider: this
|
|
469
|
+
});
|
|
470
|
+
// We can expand this in the future to any call, but for now these
|
|
471
|
+
// are the biggest wins and do not require any serializing parameters.
|
|
472
|
+
const cache = (["eth_chainId", "eth_blockNumber"].indexOf(method) >= 0);
|
|
473
|
+
if (cache && this._cache[method]) {
|
|
474
|
+
return this._cache[method];
|
|
475
|
+
}
|
|
476
|
+
const result = fetchJson(this.connection, JSON.stringify(request), getResult).then((result) => {
|
|
477
|
+
this.emit("debug", {
|
|
478
|
+
action: "response",
|
|
479
|
+
request: request,
|
|
480
|
+
response: result,
|
|
481
|
+
provider: this
|
|
482
|
+
});
|
|
483
|
+
return result;
|
|
484
|
+
}, (error) => {
|
|
485
|
+
this.emit("debug", {
|
|
486
|
+
action: "response",
|
|
487
|
+
error: error,
|
|
488
|
+
request: request,
|
|
489
|
+
provider: this
|
|
490
|
+
});
|
|
491
|
+
throw error;
|
|
492
|
+
});
|
|
493
|
+
// Cache the fetch, but clear it on the next event loop
|
|
494
|
+
if (cache) {
|
|
495
|
+
this._cache[method] = result;
|
|
496
|
+
setTimeout(() => {
|
|
497
|
+
this._cache[method] = null;
|
|
498
|
+
}, 0);
|
|
499
|
+
}
|
|
500
|
+
return result;
|
|
501
|
+
}
|
|
502
|
+
prepareRequest(method, params) {
|
|
503
|
+
switch (method) {
|
|
504
|
+
case "getBlockNumber":
|
|
505
|
+
return ["eth_blockNumber", []];
|
|
506
|
+
case "getGasPrice":
|
|
507
|
+
return ["eth_gasPrice", []];
|
|
508
|
+
case "getBalance":
|
|
509
|
+
return ["eth_getBalance", [getLowerCase(params.address), params.blockTag]];
|
|
510
|
+
case "getTransactionCount":
|
|
511
|
+
return ["eth_getTransactionCount", [getLowerCase(params.address), params.blockTag]];
|
|
512
|
+
case "getCode":
|
|
513
|
+
return ["eth_getCode", [getLowerCase(params.address), params.blockTag]];
|
|
514
|
+
case "getStorageAt":
|
|
515
|
+
return ["eth_getStorageAt", [getLowerCase(params.address), hexZeroPad(params.position, 32), params.blockTag]];
|
|
516
|
+
case "sendTransaction":
|
|
517
|
+
return ["eth_sendRawTransaction", [params.signedTransaction]];
|
|
518
|
+
case "getBlock":
|
|
519
|
+
if (params.blockTag) {
|
|
520
|
+
return ["eth_getBlockByNumber", [params.blockTag, !!params.includeTransactions]];
|
|
521
|
+
}
|
|
522
|
+
else if (params.blockHash) {
|
|
523
|
+
return ["eth_getBlockByHash", [params.blockHash, !!params.includeTransactions]];
|
|
524
|
+
}
|
|
525
|
+
return null;
|
|
526
|
+
case "getTransaction":
|
|
527
|
+
return ["eth_getTransactionByHash", [params.transactionHash]];
|
|
528
|
+
case "getTransactionReceipt":
|
|
529
|
+
return ["eth_getTransactionReceipt", [params.transactionHash]];
|
|
530
|
+
case "call": {
|
|
531
|
+
const hexlifyTransaction = getStatic(this.constructor, "hexlifyTransaction");
|
|
532
|
+
return ["eth_call", [hexlifyTransaction(params.transaction, { from: true }), params.blockTag]];
|
|
533
|
+
}
|
|
534
|
+
case "estimateGas": {
|
|
535
|
+
const hexlifyTransaction = getStatic(this.constructor, "hexlifyTransaction");
|
|
536
|
+
return ["eth_estimateGas", [hexlifyTransaction(params.transaction, { from: true })]];
|
|
537
|
+
}
|
|
538
|
+
case "getLogs":
|
|
539
|
+
if (params.filter && params.filter.address != null) {
|
|
540
|
+
params.filter.address = getLowerCase(params.filter.address);
|
|
541
|
+
}
|
|
542
|
+
return ["eth_getLogs", [params.filter]];
|
|
543
|
+
}
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
perform(method, params) {
|
|
547
|
+
return __awaiter(this, undefined, undefined, function* () {
|
|
548
|
+
// Legacy networks do not like the type field being passed along (which
|
|
549
|
+
// is fair), so we delete type if it is 0 and a non-EIP-1559 network
|
|
550
|
+
if (method === "call" || method === "estimateGas") {
|
|
551
|
+
const tx = params.transaction;
|
|
552
|
+
if (tx && tx.type != null && BigNumber.from(tx.type).isZero()) {
|
|
553
|
+
// If there are no EIP-1559 properties, it might be non-EIP-1559
|
|
554
|
+
if (tx.maxFeePerGas == null && tx.maxPriorityFeePerGas == null) {
|
|
555
|
+
const feeData = yield this.getFeeData();
|
|
556
|
+
if (feeData.maxFeePerGas == null && feeData.maxPriorityFeePerGas == null) {
|
|
557
|
+
// Network doesn't know about EIP-1559 (and hence type)
|
|
558
|
+
params = shallowCopy(params);
|
|
559
|
+
params.transaction = shallowCopy(tx);
|
|
560
|
+
delete params.transaction.type;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
const args = this.prepareRequest(method, params);
|
|
566
|
+
if (args == null) {
|
|
567
|
+
logger.throwError(method + " not implemented", Logger.errors.NOT_IMPLEMENTED, { operation: method });
|
|
568
|
+
}
|
|
569
|
+
try {
|
|
570
|
+
return yield this.send(args[0], args[1]);
|
|
571
|
+
}
|
|
572
|
+
catch (error) {
|
|
573
|
+
return checkError(method, error, params);
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
_startEvent(event) {
|
|
578
|
+
if (event.tag === "pending") {
|
|
579
|
+
this._startPending();
|
|
580
|
+
}
|
|
581
|
+
super._startEvent(event);
|
|
582
|
+
}
|
|
583
|
+
_startPending() {
|
|
584
|
+
if (this._pendingFilter != null) {
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
const self = this;
|
|
588
|
+
const pendingFilter = this.send("eth_newPendingTransactionFilter", []);
|
|
589
|
+
this._pendingFilter = pendingFilter;
|
|
590
|
+
pendingFilter.then(function (filterId) {
|
|
591
|
+
function poll() {
|
|
592
|
+
self.send("eth_getFilterChanges", [filterId]).then(function (hashes) {
|
|
593
|
+
if (self._pendingFilter != pendingFilter) {
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
let seq = Promise.resolve();
|
|
597
|
+
hashes.forEach(function (hash) {
|
|
598
|
+
// @TODO: This should be garbage collected at some point... How? When?
|
|
599
|
+
self._emitted["t:" + hash.toLowerCase()] = "pending";
|
|
600
|
+
seq = seq.then(function () {
|
|
601
|
+
return self.getTransaction(hash).then(function (tx) {
|
|
602
|
+
self.emit("pending", tx);
|
|
603
|
+
return null;
|
|
604
|
+
});
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
return seq.then(function () {
|
|
608
|
+
return timer(1000);
|
|
609
|
+
});
|
|
610
|
+
}).then(function () {
|
|
611
|
+
if (self._pendingFilter != pendingFilter) {
|
|
612
|
+
self.send("eth_uninstallFilter", [filterId]);
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
setTimeout(function () { poll(); }, 0);
|
|
616
|
+
return null;
|
|
617
|
+
}).catch((error) => { });
|
|
618
|
+
}
|
|
619
|
+
poll();
|
|
620
|
+
return filterId;
|
|
621
|
+
}).catch((error) => { });
|
|
622
|
+
}
|
|
623
|
+
_stopEvent(event) {
|
|
624
|
+
if (event.tag === "pending" && this.listenerCount("pending") === 0) {
|
|
625
|
+
this._pendingFilter = null;
|
|
626
|
+
}
|
|
627
|
+
super._stopEvent(event);
|
|
628
|
+
}
|
|
629
|
+
// Convert an ethers.js transaction into a JSON-RPC transaction
|
|
630
|
+
// - gasLimit => gas
|
|
631
|
+
// - All values hexlified
|
|
632
|
+
// - All numeric values zero-striped
|
|
633
|
+
// - All addresses are lowercased
|
|
634
|
+
// NOTE: This allows a TransactionRequest, but all values should be resolved
|
|
635
|
+
// before this is called
|
|
636
|
+
// @TODO: This will likely be removed in future versions and prepareRequest
|
|
637
|
+
// will be the preferred method for this.
|
|
638
|
+
static hexlifyTransaction(transaction, allowExtra) {
|
|
639
|
+
// Check only allowed properties are given
|
|
640
|
+
const allowed = shallowCopy(allowedTransactionKeys);
|
|
641
|
+
if (allowExtra) {
|
|
642
|
+
for (const key in allowExtra) {
|
|
643
|
+
if (allowExtra[key]) {
|
|
644
|
+
allowed[key] = true;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
checkProperties(transaction, allowed);
|
|
649
|
+
const result = {};
|
|
650
|
+
// JSON-RPC now requires numeric values to be "quantity" values
|
|
651
|
+
["chainId", "gasLimit", "gasPrice", "type", "maxFeePerGas", "maxPriorityFeePerGas", "nonce", "value"].forEach(function (key) {
|
|
652
|
+
if (transaction[key] == null) {
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
const value = hexValue(BigNumber.from(transaction[key]));
|
|
656
|
+
if (key === "gasLimit") {
|
|
657
|
+
key = "gas";
|
|
658
|
+
}
|
|
659
|
+
result[key] = value;
|
|
660
|
+
});
|
|
661
|
+
["from", "to", "data"].forEach(function (key) {
|
|
662
|
+
if (transaction[key] == null) {
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
result[key] = hexlify(transaction[key]);
|
|
666
|
+
});
|
|
667
|
+
if (transaction.accessList) {
|
|
668
|
+
result["accessList"] = accessListify(transaction.accessList);
|
|
669
|
+
}
|
|
670
|
+
return result;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
export { JsonRpcProvider, JsonRpcSigner };
|