@waku/rln 0.0.1 → 0.0.2-ce9a6ae.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -108
- package/bundle/_virtual/__node-resolve_empty.js +6 -0
- package/bundle/_virtual/_assert.js +3 -0
- package/bundle/_virtual/_commonjs-dynamic-modules.js +5 -0
- package/bundle/_virtual/_commonjsHelpers.js +32 -0
- package/bundle/_virtual/_node-resolve_empty.js +3 -0
- package/bundle/_virtual/_sha2.js +3 -0
- package/bundle/_virtual/_u64.js +3 -0
- package/bundle/_virtual/aes.js +3 -0
- package/bundle/_virtual/bn.js +3 -0
- package/bundle/_virtual/browser.js +3 -0
- package/bundle/_virtual/checksum.js +3 -0
- package/bundle/_virtual/cipher.js +3 -0
- package/bundle/_virtual/class.js +3 -0
- package/bundle/_virtual/common.js +3 -0
- package/bundle/_virtual/common2.js +3 -0
- package/bundle/_virtual/cryptoBrowser.js +3 -0
- package/bundle/_virtual/functional.js +3 -0
- package/bundle/_virtual/hash.js +3 -0
- package/bundle/_virtual/hmac.js +3 -0
- package/bundle/_virtual/index.js +3 -0
- package/bundle/_virtual/index2.js +6 -0
- package/bundle/_virtual/inherits_browser.js +3 -0
- package/bundle/_virtual/kdf.js +3 -0
- package/bundle/_virtual/lodash.js +3 -0
- package/bundle/_virtual/password.js +3 -0
- package/bundle/_virtual/pbkdf2.js +3 -0
- package/bundle/_virtual/pbkdf22.js +3 -0
- package/bundle/_virtual/random.js +3 -0
- package/bundle/_virtual/ripemd.js +3 -0
- package/bundle/_virtual/schema-validation-generated.js +3 -0
- package/bundle/_virtual/schema-validation.js +3 -0
- package/bundle/_virtual/scrypt.js +3 -0
- package/bundle/_virtual/scrypt2.js +3 -0
- package/bundle/_virtual/sha.js +3 -0
- package/bundle/_virtual/sha256.js +3 -0
- package/bundle/_virtual/sha2562.js +3 -0
- package/bundle/_virtual/sha3.js +3 -0
- package/bundle/_virtual/sha512.js +3 -0
- package/bundle/_virtual/types.js +3 -0
- package/bundle/_virtual/utils.js +3 -0
- package/bundle/_virtual/utils2.js +3 -0
- package/bundle/_virtual/utils3.js +3 -0
- package/bundle/index.js +12 -10
- package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +96 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +148 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +20 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +210 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +18 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +30 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +22 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +43 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +19 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +58 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +854 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +609 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +66 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +302 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +110 -0
- package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +20 -0
- package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +287 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +402 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +3 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +8 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +893 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +256 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +36 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +135 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +8 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +64 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +443 -0
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +8 -0
- package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +660 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +352 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +248 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +127 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +2007 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +422 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +674 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +132 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +8 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +2430 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +76 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +219 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +279 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +69 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +404 -0
- package/bundle/node_modules/@iden3/js-crypto/dist/browser/esm/index.js +7 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +15 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +20 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +92 -0
- package/bundle/node_modules/@noble/hashes/esm/_assert.js +37 -0
- package/bundle/node_modules/@noble/hashes/esm/_md.js +132 -0
- package/bundle/node_modules/@noble/hashes/esm/_u64.js +29 -0
- package/bundle/node_modules/@noble/hashes/esm/sha256.js +113 -0
- package/bundle/node_modules/@noble/hashes/esm/sha3.js +210 -0
- package/bundle/node_modules/@noble/hashes/esm/utils.js +144 -0
- package/bundle/node_modules/@stablelib/binary/lib/binary.js +22 -0
- package/bundle/node_modules/@stablelib/chacha/lib/chacha.js +245 -0
- package/bundle/node_modules/@stablelib/wipe/lib/wipe.js +26 -0
- package/bundle/node_modules/@waku/zerokit-rln-wasm/rln_wasm.js +756 -0
- package/bundle/node_modules/bech32/index.js +187 -0
- package/bundle/node_modules/bn.js/lib/bn.js +3361 -0
- package/bundle/node_modules/debug/src/browser.js +283 -0
- package/bundle/node_modules/debug/src/common.js +295 -0
- package/bundle/node_modules/ethereum-cryptography/esm/keccak.js +10 -0
- package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +6 -0
- package/bundle/node_modules/ethereum-cryptography/esm/utils.js +24 -0
- package/bundle/node_modules/hash.js/lib/hash/common.js +97 -0
- package/bundle/node_modules/hash.js/lib/hash/hmac.js +51 -0
- package/bundle/node_modules/hash.js/lib/hash/ripemd.js +152 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/1.js +81 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/224.js +33 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/256.js +113 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/384.js +39 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/512.js +336 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/common.js +53 -0
- package/bundle/node_modules/hash.js/lib/hash/sha.js +14 -0
- package/bundle/node_modules/hash.js/lib/hash/utils.js +282 -0
- package/bundle/node_modules/hash.js/lib/hash.js +33 -0
- package/bundle/node_modules/inherits/inherits_browser.js +33 -0
- package/bundle/node_modules/it-length-prefixed/dist/src/decode.js +6 -0
- package/bundle/node_modules/lodash/lodash.js +17207 -0
- package/bundle/node_modules/minimalistic-assert/index.js +13 -0
- package/bundle/node_modules/ms/index.js +172 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base.js +205 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base10.js +9 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base16.js +16 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base2.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base256emoji.js +41 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base32.js +58 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base36.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base58.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base64.js +28 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base8.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/identity.js +11 -0
- package/bundle/node_modules/multiformats/dist/src/basics.js +15 -0
- package/bundle/node_modules/multiformats/dist/src/bytes.js +18 -0
- package/bundle/node_modules/multiformats/dist/src/codecs/json.js +2 -0
- package/bundle/node_modules/multiformats/dist/src/vendor/base-x.js +170 -0
- package/bundle/node_modules/protons-runtime/dist/src/codec.js +20 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/enum.js +24 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/message.js +7 -0
- package/bundle/node_modules/protons-runtime/dist/src/decode.js +8 -0
- package/bundle/node_modules/protons-runtime/dist/src/encode.js +11 -0
- package/bundle/node_modules/protons-runtime/dist/src/index.js +30 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/float.js +54 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/longbits.js +175 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/pool.js +28 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/reader.js +367 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/utf8.js +99 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/writer.js +438 -0
- package/bundle/node_modules/uint8-varint/dist/src/index.js +124 -0
- package/bundle/node_modules/uint8arrays/dist/src/alloc.js +17 -0
- package/bundle/node_modules/uint8arrays/dist/src/from-string.js +19 -0
- package/bundle/node_modules/uint8arrays/dist/src/util/bases.js +49 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +21 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +18 -0
- package/bundle/packages/core/dist/lib/filter/filter.js +27 -0
- package/bundle/packages/core/dist/lib/light_push/light_push.js +27 -0
- package/bundle/packages/core/dist/lib/message/version_0.js +154 -0
- package/bundle/packages/core/dist/lib/metadata/metadata.js +27 -0
- package/bundle/packages/core/dist/lib/store/store.js +27 -0
- package/bundle/packages/interfaces/dist/connection_manager.js +19 -0
- package/bundle/packages/interfaces/dist/constants.js +6 -0
- package/bundle/packages/interfaces/dist/health_indicator.js +12 -0
- package/bundle/packages/interfaces/dist/protocols.js +97 -0
- package/bundle/packages/proto/dist/generated/filter.js +445 -0
- package/bundle/packages/proto/dist/generated/filter_v2.js +424 -0
- package/bundle/packages/proto/dist/generated/light_push.js +389 -0
- package/bundle/packages/proto/dist/generated/message.js +213 -0
- package/bundle/packages/proto/dist/generated/metadata.js +130 -0
- package/bundle/packages/proto/dist/generated/peer_exchange.js +209 -0
- package/bundle/packages/proto/dist/generated/sds_message.js +105 -0
- package/bundle/packages/proto/dist/generated/store_v3.js +490 -0
- package/bundle/packages/proto/dist/generated/topic_only_message.js +61 -0
- package/bundle/packages/rln/dist/codec.js +93 -0
- package/bundle/packages/rln/dist/contract/abi/rlnv2.js +394 -0
- package/bundle/packages/rln/dist/contract/constants.js +33 -0
- package/bundle/packages/rln/dist/contract/rln_contract.js +427 -0
- package/bundle/packages/rln/dist/create.js +9 -0
- package/bundle/packages/rln/dist/identity.js +76 -0
- package/bundle/packages/rln/dist/keystore/cipher.js +31 -0
- package/bundle/packages/rln/dist/keystore/credential_validation_generated.js +119 -0
- package/bundle/packages/rln/dist/keystore/keystore.js +223 -0
- package/bundle/packages/rln/dist/keystore/keystore_validation_generated.js +74 -0
- package/bundle/packages/rln/dist/keystore/schema_validator.js +20 -0
- package/bundle/packages/rln/dist/message.js +51 -0
- package/bundle/packages/rln/dist/proof.js +54 -0
- package/bundle/packages/rln/dist/resources/verification_key.js +112 -0
- package/bundle/packages/rln/dist/resources/witness_calculator.js +330 -0
- package/bundle/packages/rln/dist/rln.js +204 -0
- package/bundle/packages/rln/dist/root_tracker.js +76 -0
- package/bundle/packages/rln/dist/utils/bytes.js +65 -0
- package/bundle/packages/rln/dist/utils/epoch.js +39 -0
- package/bundle/packages/rln/dist/utils/hash.js +10 -0
- package/bundle/packages/rln/dist/utils/metamask.js +14 -0
- package/bundle/packages/rln/dist/zerokit.js +122 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +52 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +65 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +99 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/index.js +28 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +78 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1253 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +40 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/types.js +5 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +41 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +23 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +12 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +77 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +9 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +215 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +35 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +21 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +66 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +24 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +7 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +11 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +52 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +124 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +71 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +10 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +88 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +99 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +233 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +133 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +243 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +167 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/native.js +4 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/rng.js +13 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/stringify.js +28 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/v4.js +19 -0
- package/bundle/packages/utils/dist/bytes/index.js +44 -0
- package/bundle/packages/utils/dist/common/sharding/index.js +91 -0
- package/bundle/packages/utils/dist/logger/index.js +31 -0
- package/bundle/resources/rln.wasm +0 -0
- package/bundle/resources/rln_final.zkey +0 -0
- package/bundle/resources/verification_key.d.ts +13 -0
- package/bundle/resources/verification_key.js +112 -0
- package/bundle/resources/witness_calculator.d.ts +11 -0
- package/bundle/resources/witness_calculator.js +328 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/__tests__/identity.test.d.ts +1 -0
- package/dist/__tests__/identity.test.js +40 -0
- package/dist/__tests__/identity.test.js.map +1 -0
- package/dist/codec.d.ts +39 -0
- package/dist/codec.js +77 -0
- package/dist/codec.js.map +1 -0
- package/dist/contract/abi/rlnv2.d.ts +42 -0
- package/dist/contract/abi/rlnv2.js +393 -0
- package/dist/contract/abi/rlnv2.js.map +1 -0
- package/dist/contract/constants.d.ts +68 -0
- package/dist/contract/constants.js +31 -0
- package/dist/contract/constants.js.map +1 -0
- package/dist/contract/index.d.ts +2 -0
- package/dist/contract/index.js +3 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/rln_contract.d.ts +119 -0
- package/dist/contract/rln_contract.js +421 -0
- package/dist/contract/rln_contract.js.map +1 -0
- package/dist/create.d.ts +2 -0
- package/dist/create.js +8 -0
- package/dist/create.js.map +1 -0
- package/dist/identity.d.ts +16 -0
- package/dist/identity.js +73 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/dist/keystore/cipher.d.ts +4 -0
- package/dist/keystore/cipher.js +28 -0
- package/dist/keystore/cipher.js.map +1 -0
- package/dist/keystore/credential_validation_generated.d.ts +8 -0
- package/dist/keystore/credential_validation_generated.js +121 -0
- package/dist/keystore/credential_validation_generated.js.map +1 -0
- package/dist/keystore/index.d.ts +4 -0
- package/dist/keystore/index.js +3 -0
- package/dist/keystore/index.js.map +1 -0
- package/dist/keystore/keystore.d.ts +50 -0
- package/dist/keystore/keystore.js +205 -0
- package/dist/keystore/keystore.js.map +1 -0
- package/dist/keystore/keystore_validation_generated.d.ts +8 -0
- package/dist/keystore/keystore_validation_generated.js +75 -0
- package/dist/keystore/keystore_validation_generated.js.map +1 -0
- package/dist/keystore/schema_validator.d.ts +2 -0
- package/dist/keystore/schema_validator.js +18 -0
- package/dist/keystore/schema_validator.js.map +1 -0
- package/dist/keystore/types.d.ts +29 -0
- package/dist/keystore/types.js +2 -0
- package/dist/keystore/types.js.map +1 -0
- package/dist/message.d.ts +18 -0
- package/dist/message.js +49 -0
- package/dist/message.js.map +1 -0
- package/dist/proof.d.ts +21 -0
- package/dist/proof.js +50 -0
- package/dist/proof.js.map +1 -0
- package/dist/resources/rln.wasm +0 -0
- package/dist/resources/rln_final.zkey +0 -0
- package/dist/resources/verification_key.d.ts +13 -0
- package/dist/resources/verification_key.js +112 -0
- package/dist/resources/witness_calculator.d.ts +11 -0
- package/dist/resources/witness_calculator.js +328 -0
- package/dist/rln.d.ts +59 -13
- package/dist/rln.js +164 -81
- package/dist/rln.js.map +1 -1
- package/dist/root_tracker.d.ts +10 -0
- package/dist/root_tracker.js +75 -0
- package/dist/root_tracker.js.map +1 -0
- package/dist/utils/bytes.d.ts +20 -0
- package/dist/utils/bytes.js +64 -0
- package/dist/utils/bytes.js.map +1 -0
- package/dist/utils/epoch.d.ts +3 -0
- package/dist/utils/epoch.js +23 -0
- package/dist/utils/epoch.js.map +1 -0
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.js +13 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/metamask.d.ts +2 -0
- package/dist/utils/metamask.js +12 -0
- package/dist/utils/metamask.js.map +1 -0
- package/dist/zerokit.d.ts +19 -0
- package/dist/zerokit.js +119 -0
- package/dist/zerokit.js.map +1 -0
- package/package.json +1 -126
- package/src/__tests__/identity.test.ts +50 -0
- package/src/codec.ts +134 -0
- package/src/contract/abi/rlnv2.ts +392 -0
- package/src/contract/constants.ts +35 -0
- package/src/contract/index.ts +2 -0
- package/src/contract/rln_contract.ts +673 -0
- package/src/create.ts +9 -0
- package/src/identity.ts +101 -0
- package/src/index.ts +24 -10
- package/src/keystore/cipher.ts +54 -0
- package/src/keystore/credential_validation_generated.ts +7 -0
- package/src/keystore/index.ts +5 -0
- package/src/keystore/keystore.ts +330 -0
- package/src/keystore/keystore_validation_generated.ts +7 -0
- package/src/keystore/schema_validator.ts +34 -0
- package/src/keystore/types.ts +36 -0
- package/src/message.ts +70 -0
- package/src/proof.ts +69 -0
- package/src/resources/verification_key.d.ts +13 -0
- package/src/resources/witness_calculator.d.ts +11 -0
- package/src/rln.ts +270 -106
- package/src/root_tracker.ts +92 -0
- package/src/utils/bytes.ts +84 -0
- package/src/utils/epoch.ts +30 -0
- package/src/utils/hash.ts +15 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/metamask.ts +17 -0
- package/src/zerokit.ts +214 -0
- package/bundle/02bce7e5f3bcf834.wasm +0 -0
- package/bundle/rln-f87f6dbe.js +0 -563
- package/dist/resources.d.ts +0 -4
- package/dist/resources.js +0 -5
- package/dist/resources.js.map +0 -1
- package/dist/witness_calculator.d.ts +0 -16
- package/dist/witness_calculator.js +0 -291
- package/dist/witness_calculator.js.map +0 -1
- package/dist/zerokit/rln_wasm.d.ts +0 -1
- package/dist/zerokit/rln_wasm.js +0 -2
- package/dist/zerokit/rln_wasm.js.map +0 -1
- package/dist/zerokit/rln_wasm_bg.d.ts +0 -108
- package/dist/zerokit/rln_wasm_bg.js +0 -592
- package/dist/zerokit/rln_wasm_bg.js.map +0 -1
- package/dist/zerokit/rln_wasm_bg.wasm +0 -0
- package/src/resources.ts +0 -10
- package/src/witness_calculator.d.ts +0 -4
@@ -0,0 +1,443 @@
|
|
1
|
+
import { getAddress } from '../../address/lib.esm/index.js';
|
2
|
+
import { hexZeroPad, hexConcat, isHexString, hexlify, arrayify } from '../../bytes/lib.esm/index.js';
|
3
|
+
import { keccak256 } from '../../keccak256/lib.esm/index.js';
|
4
|
+
import { defineReadOnly, deepCopy, shallowCopy } from '../../properties/lib.esm/index.js';
|
5
|
+
import { Logger } from '../../logger/lib.esm/index.js';
|
6
|
+
import { version } from './_version.js';
|
7
|
+
import { id } from './id.js';
|
8
|
+
import { BigNumber } from '../../bignumber/lib.esm/bignumber.js';
|
9
|
+
|
10
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
11
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
12
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
13
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
14
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
15
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
16
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
17
|
+
});
|
18
|
+
};
|
19
|
+
const logger = new Logger(version);
|
20
|
+
const padding = new Uint8Array(32);
|
21
|
+
padding.fill(0);
|
22
|
+
const NegativeOne = BigNumber.from(-1);
|
23
|
+
const Zero = BigNumber.from(0);
|
24
|
+
const One = BigNumber.from(1);
|
25
|
+
const MaxUint256 = BigNumber.from("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
26
|
+
function hexPadRight(value) {
|
27
|
+
const bytes = arrayify(value);
|
28
|
+
const padOffset = bytes.length % 32;
|
29
|
+
if (padOffset) {
|
30
|
+
return hexConcat([bytes, padding.slice(padOffset)]);
|
31
|
+
}
|
32
|
+
return hexlify(bytes);
|
33
|
+
}
|
34
|
+
const hexTrue = hexZeroPad(One.toHexString(), 32);
|
35
|
+
const hexFalse = hexZeroPad(Zero.toHexString(), 32);
|
36
|
+
const domainFieldTypes = {
|
37
|
+
name: "string",
|
38
|
+
version: "string",
|
39
|
+
chainId: "uint256",
|
40
|
+
verifyingContract: "address",
|
41
|
+
salt: "bytes32"
|
42
|
+
};
|
43
|
+
const domainFieldNames = [
|
44
|
+
"name", "version", "chainId", "verifyingContract", "salt"
|
45
|
+
];
|
46
|
+
function checkString(key) {
|
47
|
+
return function (value) {
|
48
|
+
if (typeof (value) !== "string") {
|
49
|
+
logger.throwArgumentError(`invalid domain value for ${JSON.stringify(key)}`, `domain.${key}`, value);
|
50
|
+
}
|
51
|
+
return value;
|
52
|
+
};
|
53
|
+
}
|
54
|
+
const domainChecks = {
|
55
|
+
name: checkString("name"),
|
56
|
+
version: checkString("version"),
|
57
|
+
chainId: function (value) {
|
58
|
+
try {
|
59
|
+
return BigNumber.from(value).toString();
|
60
|
+
}
|
61
|
+
catch (error) { }
|
62
|
+
return logger.throwArgumentError(`invalid domain value for "chainId"`, "domain.chainId", value);
|
63
|
+
},
|
64
|
+
verifyingContract: function (value) {
|
65
|
+
try {
|
66
|
+
return getAddress(value).toLowerCase();
|
67
|
+
}
|
68
|
+
catch (error) { }
|
69
|
+
return logger.throwArgumentError(`invalid domain value "verifyingContract"`, "domain.verifyingContract", value);
|
70
|
+
},
|
71
|
+
salt: function (value) {
|
72
|
+
try {
|
73
|
+
const bytes = arrayify(value);
|
74
|
+
if (bytes.length !== 32) {
|
75
|
+
throw new Error("bad length");
|
76
|
+
}
|
77
|
+
return hexlify(bytes);
|
78
|
+
}
|
79
|
+
catch (error) { }
|
80
|
+
return logger.throwArgumentError(`invalid domain value "salt"`, "domain.salt", value);
|
81
|
+
}
|
82
|
+
};
|
83
|
+
function getBaseEncoder(type) {
|
84
|
+
// intXX and uintXX
|
85
|
+
{
|
86
|
+
const match = type.match(/^(u?)int(\d*)$/);
|
87
|
+
if (match) {
|
88
|
+
const signed = (match[1] === "");
|
89
|
+
const width = parseInt(match[2] || "256");
|
90
|
+
if (width % 8 !== 0 || width > 256 || (match[2] && match[2] !== String(width))) {
|
91
|
+
logger.throwArgumentError("invalid numeric width", "type", type);
|
92
|
+
}
|
93
|
+
const boundsUpper = MaxUint256.mask(signed ? (width - 1) : width);
|
94
|
+
const boundsLower = signed ? boundsUpper.add(One).mul(NegativeOne) : Zero;
|
95
|
+
return function (value) {
|
96
|
+
const v = BigNumber.from(value);
|
97
|
+
if (v.lt(boundsLower) || v.gt(boundsUpper)) {
|
98
|
+
logger.throwArgumentError(`value out-of-bounds for ${type}`, "value", value);
|
99
|
+
}
|
100
|
+
return hexZeroPad(v.toTwos(256).toHexString(), 32);
|
101
|
+
};
|
102
|
+
}
|
103
|
+
}
|
104
|
+
// bytesXX
|
105
|
+
{
|
106
|
+
const match = type.match(/^bytes(\d+)$/);
|
107
|
+
if (match) {
|
108
|
+
const width = parseInt(match[1]);
|
109
|
+
if (width === 0 || width > 32 || match[1] !== String(width)) {
|
110
|
+
logger.throwArgumentError("invalid bytes width", "type", type);
|
111
|
+
}
|
112
|
+
return function (value) {
|
113
|
+
const bytes = arrayify(value);
|
114
|
+
if (bytes.length !== width) {
|
115
|
+
logger.throwArgumentError(`invalid length for ${type}`, "value", value);
|
116
|
+
}
|
117
|
+
return hexPadRight(value);
|
118
|
+
};
|
119
|
+
}
|
120
|
+
}
|
121
|
+
switch (type) {
|
122
|
+
case "address": return function (value) {
|
123
|
+
return hexZeroPad(getAddress(value), 32);
|
124
|
+
};
|
125
|
+
case "bool": return function (value) {
|
126
|
+
return ((!value) ? hexFalse : hexTrue);
|
127
|
+
};
|
128
|
+
case "bytes": return function (value) {
|
129
|
+
return keccak256(value);
|
130
|
+
};
|
131
|
+
case "string": return function (value) {
|
132
|
+
return id(value);
|
133
|
+
};
|
134
|
+
}
|
135
|
+
return null;
|
136
|
+
}
|
137
|
+
function encodeType(name, fields) {
|
138
|
+
return `${name}(${fields.map(({ name, type }) => (type + " " + name)).join(",")})`;
|
139
|
+
}
|
140
|
+
class TypedDataEncoder {
|
141
|
+
constructor(types) {
|
142
|
+
defineReadOnly(this, "types", Object.freeze(deepCopy(types)));
|
143
|
+
defineReadOnly(this, "_encoderCache", {});
|
144
|
+
defineReadOnly(this, "_types", {});
|
145
|
+
// Link struct types to their direct child structs
|
146
|
+
const links = {};
|
147
|
+
// Link structs to structs which contain them as a child
|
148
|
+
const parents = {};
|
149
|
+
// Link all subtypes within a given struct
|
150
|
+
const subtypes = {};
|
151
|
+
Object.keys(types).forEach((type) => {
|
152
|
+
links[type] = {};
|
153
|
+
parents[type] = [];
|
154
|
+
subtypes[type] = {};
|
155
|
+
});
|
156
|
+
for (const name in types) {
|
157
|
+
const uniqueNames = {};
|
158
|
+
types[name].forEach((field) => {
|
159
|
+
// Check each field has a unique name
|
160
|
+
if (uniqueNames[field.name]) {
|
161
|
+
logger.throwArgumentError(`duplicate variable name ${JSON.stringify(field.name)} in ${JSON.stringify(name)}`, "types", types);
|
162
|
+
}
|
163
|
+
uniqueNames[field.name] = true;
|
164
|
+
// Get the base type (drop any array specifiers)
|
165
|
+
const baseType = field.type.match(/^([^\x5b]*)(\x5b|$)/)[1];
|
166
|
+
if (baseType === name) {
|
167
|
+
logger.throwArgumentError(`circular type reference to ${JSON.stringify(baseType)}`, "types", types);
|
168
|
+
}
|
169
|
+
// Is this a base encoding type?
|
170
|
+
const encoder = getBaseEncoder(baseType);
|
171
|
+
if (encoder) {
|
172
|
+
return;
|
173
|
+
}
|
174
|
+
if (!parents[baseType]) {
|
175
|
+
logger.throwArgumentError(`unknown type ${JSON.stringify(baseType)}`, "types", types);
|
176
|
+
}
|
177
|
+
// Add linkage
|
178
|
+
parents[baseType].push(name);
|
179
|
+
links[name][baseType] = true;
|
180
|
+
});
|
181
|
+
}
|
182
|
+
// Deduce the primary type
|
183
|
+
const primaryTypes = Object.keys(parents).filter((n) => (parents[n].length === 0));
|
184
|
+
if (primaryTypes.length === 0) {
|
185
|
+
logger.throwArgumentError("missing primary type", "types", types);
|
186
|
+
}
|
187
|
+
else if (primaryTypes.length > 1) {
|
188
|
+
logger.throwArgumentError(`ambiguous primary types or unused types: ${primaryTypes.map((t) => (JSON.stringify(t))).join(", ")}`, "types", types);
|
189
|
+
}
|
190
|
+
defineReadOnly(this, "primaryType", primaryTypes[0]);
|
191
|
+
// Check for circular type references
|
192
|
+
function checkCircular(type, found) {
|
193
|
+
if (found[type]) {
|
194
|
+
logger.throwArgumentError(`circular type reference to ${JSON.stringify(type)}`, "types", types);
|
195
|
+
}
|
196
|
+
found[type] = true;
|
197
|
+
Object.keys(links[type]).forEach((child) => {
|
198
|
+
if (!parents[child]) {
|
199
|
+
return;
|
200
|
+
}
|
201
|
+
// Recursively check children
|
202
|
+
checkCircular(child, found);
|
203
|
+
// Mark all ancestors as having this decendant
|
204
|
+
Object.keys(found).forEach((subtype) => {
|
205
|
+
subtypes[subtype][child] = true;
|
206
|
+
});
|
207
|
+
});
|
208
|
+
delete found[type];
|
209
|
+
}
|
210
|
+
checkCircular(this.primaryType, {});
|
211
|
+
// Compute each fully describe type
|
212
|
+
for (const name in subtypes) {
|
213
|
+
const st = Object.keys(subtypes[name]);
|
214
|
+
st.sort();
|
215
|
+
this._types[name] = encodeType(name, types[name]) + st.map((t) => encodeType(t, types[t])).join("");
|
216
|
+
}
|
217
|
+
}
|
218
|
+
getEncoder(type) {
|
219
|
+
let encoder = this._encoderCache[type];
|
220
|
+
if (!encoder) {
|
221
|
+
encoder = this._encoderCache[type] = this._getEncoder(type);
|
222
|
+
}
|
223
|
+
return encoder;
|
224
|
+
}
|
225
|
+
_getEncoder(type) {
|
226
|
+
// Basic encoder type (address, bool, uint256, etc)
|
227
|
+
{
|
228
|
+
const encoder = getBaseEncoder(type);
|
229
|
+
if (encoder) {
|
230
|
+
return encoder;
|
231
|
+
}
|
232
|
+
}
|
233
|
+
// Array
|
234
|
+
const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
|
235
|
+
if (match) {
|
236
|
+
const subtype = match[1];
|
237
|
+
const subEncoder = this.getEncoder(subtype);
|
238
|
+
const length = parseInt(match[3]);
|
239
|
+
return (value) => {
|
240
|
+
if (length >= 0 && value.length !== length) {
|
241
|
+
logger.throwArgumentError("array length mismatch; expected length ${ arrayLength }", "value", value);
|
242
|
+
}
|
243
|
+
let result = value.map(subEncoder);
|
244
|
+
if (this._types[subtype]) {
|
245
|
+
result = result.map(keccak256);
|
246
|
+
}
|
247
|
+
return keccak256(hexConcat(result));
|
248
|
+
};
|
249
|
+
}
|
250
|
+
// Struct
|
251
|
+
const fields = this.types[type];
|
252
|
+
if (fields) {
|
253
|
+
const encodedType = id(this._types[type]);
|
254
|
+
return (value) => {
|
255
|
+
const values = fields.map(({ name, type }) => {
|
256
|
+
const result = this.getEncoder(type)(value[name]);
|
257
|
+
if (this._types[type]) {
|
258
|
+
return keccak256(result);
|
259
|
+
}
|
260
|
+
return result;
|
261
|
+
});
|
262
|
+
values.unshift(encodedType);
|
263
|
+
return hexConcat(values);
|
264
|
+
};
|
265
|
+
}
|
266
|
+
return logger.throwArgumentError(`unknown type: ${type}`, "type", type);
|
267
|
+
}
|
268
|
+
encodeType(name) {
|
269
|
+
const result = this._types[name];
|
270
|
+
if (!result) {
|
271
|
+
logger.throwArgumentError(`unknown type: ${JSON.stringify(name)}`, "name", name);
|
272
|
+
}
|
273
|
+
return result;
|
274
|
+
}
|
275
|
+
encodeData(type, value) {
|
276
|
+
return this.getEncoder(type)(value);
|
277
|
+
}
|
278
|
+
hashStruct(name, value) {
|
279
|
+
return keccak256(this.encodeData(name, value));
|
280
|
+
}
|
281
|
+
encode(value) {
|
282
|
+
return this.encodeData(this.primaryType, value);
|
283
|
+
}
|
284
|
+
hash(value) {
|
285
|
+
return this.hashStruct(this.primaryType, value);
|
286
|
+
}
|
287
|
+
_visit(type, value, callback) {
|
288
|
+
// Basic encoder type (address, bool, uint256, etc)
|
289
|
+
{
|
290
|
+
const encoder = getBaseEncoder(type);
|
291
|
+
if (encoder) {
|
292
|
+
return callback(type, value);
|
293
|
+
}
|
294
|
+
}
|
295
|
+
// Array
|
296
|
+
const match = type.match(/^(.*)(\x5b(\d*)\x5d)$/);
|
297
|
+
if (match) {
|
298
|
+
const subtype = match[1];
|
299
|
+
const length = parseInt(match[3]);
|
300
|
+
if (length >= 0 && value.length !== length) {
|
301
|
+
logger.throwArgumentError("array length mismatch; expected length ${ arrayLength }", "value", value);
|
302
|
+
}
|
303
|
+
return value.map((v) => this._visit(subtype, v, callback));
|
304
|
+
}
|
305
|
+
// Struct
|
306
|
+
const fields = this.types[type];
|
307
|
+
if (fields) {
|
308
|
+
return fields.reduce((accum, { name, type }) => {
|
309
|
+
accum[name] = this._visit(type, value[name], callback);
|
310
|
+
return accum;
|
311
|
+
}, {});
|
312
|
+
}
|
313
|
+
return logger.throwArgumentError(`unknown type: ${type}`, "type", type);
|
314
|
+
}
|
315
|
+
visit(value, callback) {
|
316
|
+
return this._visit(this.primaryType, value, callback);
|
317
|
+
}
|
318
|
+
static from(types) {
|
319
|
+
return new TypedDataEncoder(types);
|
320
|
+
}
|
321
|
+
static getPrimaryType(types) {
|
322
|
+
return TypedDataEncoder.from(types).primaryType;
|
323
|
+
}
|
324
|
+
static hashStruct(name, types, value) {
|
325
|
+
return TypedDataEncoder.from(types).hashStruct(name, value);
|
326
|
+
}
|
327
|
+
static hashDomain(domain) {
|
328
|
+
const domainFields = [];
|
329
|
+
for (const name in domain) {
|
330
|
+
const type = domainFieldTypes[name];
|
331
|
+
if (!type) {
|
332
|
+
logger.throwArgumentError(`invalid typed-data domain key: ${JSON.stringify(name)}`, "domain", domain);
|
333
|
+
}
|
334
|
+
domainFields.push({ name, type });
|
335
|
+
}
|
336
|
+
domainFields.sort((a, b) => {
|
337
|
+
return domainFieldNames.indexOf(a.name) - domainFieldNames.indexOf(b.name);
|
338
|
+
});
|
339
|
+
return TypedDataEncoder.hashStruct("EIP712Domain", { EIP712Domain: domainFields }, domain);
|
340
|
+
}
|
341
|
+
static encode(domain, types, value) {
|
342
|
+
return hexConcat([
|
343
|
+
"0x1901",
|
344
|
+
TypedDataEncoder.hashDomain(domain),
|
345
|
+
TypedDataEncoder.from(types).hash(value)
|
346
|
+
]);
|
347
|
+
}
|
348
|
+
static hash(domain, types, value) {
|
349
|
+
return keccak256(TypedDataEncoder.encode(domain, types, value));
|
350
|
+
}
|
351
|
+
// Replaces all address types with ENS names with their looked up address
|
352
|
+
static resolveNames(domain, types, value, resolveName) {
|
353
|
+
return __awaiter(this, undefined, undefined, function* () {
|
354
|
+
// Make a copy to isolate it from the object passed in
|
355
|
+
domain = shallowCopy(domain);
|
356
|
+
// Look up all ENS names
|
357
|
+
const ensCache = {};
|
358
|
+
// Do we need to look up the domain's verifyingContract?
|
359
|
+
if (domain.verifyingContract && !isHexString(domain.verifyingContract, 20)) {
|
360
|
+
ensCache[domain.verifyingContract] = "0x";
|
361
|
+
}
|
362
|
+
// We are going to use the encoder to visit all the base values
|
363
|
+
const encoder = TypedDataEncoder.from(types);
|
364
|
+
// Get a list of all the addresses
|
365
|
+
encoder.visit(value, (type, value) => {
|
366
|
+
if (type === "address" && !isHexString(value, 20)) {
|
367
|
+
ensCache[value] = "0x";
|
368
|
+
}
|
369
|
+
return value;
|
370
|
+
});
|
371
|
+
// Lookup each name
|
372
|
+
for (const name in ensCache) {
|
373
|
+
ensCache[name] = yield resolveName(name);
|
374
|
+
}
|
375
|
+
// Replace the domain verifyingContract if needed
|
376
|
+
if (domain.verifyingContract && ensCache[domain.verifyingContract]) {
|
377
|
+
domain.verifyingContract = ensCache[domain.verifyingContract];
|
378
|
+
}
|
379
|
+
// Replace all ENS names with their address
|
380
|
+
value = encoder.visit(value, (type, value) => {
|
381
|
+
if (type === "address" && ensCache[value]) {
|
382
|
+
return ensCache[value];
|
383
|
+
}
|
384
|
+
return value;
|
385
|
+
});
|
386
|
+
return { domain, value };
|
387
|
+
});
|
388
|
+
}
|
389
|
+
static getPayload(domain, types, value) {
|
390
|
+
// Validate the domain fields
|
391
|
+
TypedDataEncoder.hashDomain(domain);
|
392
|
+
// Derive the EIP712Domain Struct reference type
|
393
|
+
const domainValues = {};
|
394
|
+
const domainTypes = [];
|
395
|
+
domainFieldNames.forEach((name) => {
|
396
|
+
const value = domain[name];
|
397
|
+
if (value == null) {
|
398
|
+
return;
|
399
|
+
}
|
400
|
+
domainValues[name] = domainChecks[name](value);
|
401
|
+
domainTypes.push({ name, type: domainFieldTypes[name] });
|
402
|
+
});
|
403
|
+
const encoder = TypedDataEncoder.from(types);
|
404
|
+
const typesWithDomain = shallowCopy(types);
|
405
|
+
if (typesWithDomain.EIP712Domain) {
|
406
|
+
logger.throwArgumentError("types must not contain EIP712Domain type", "types.EIP712Domain", types);
|
407
|
+
}
|
408
|
+
else {
|
409
|
+
typesWithDomain.EIP712Domain = domainTypes;
|
410
|
+
}
|
411
|
+
// Validate the data structures and types
|
412
|
+
encoder.encode(value);
|
413
|
+
return {
|
414
|
+
types: typesWithDomain,
|
415
|
+
domain: domainValues,
|
416
|
+
primaryType: encoder.primaryType,
|
417
|
+
message: encoder.visit(value, (type, value) => {
|
418
|
+
// bytes
|
419
|
+
if (type.match(/^bytes(\d*)/)) {
|
420
|
+
return hexlify(arrayify(value));
|
421
|
+
}
|
422
|
+
// uint or int
|
423
|
+
if (type.match(/^u?int/)) {
|
424
|
+
return BigNumber.from(value).toString();
|
425
|
+
}
|
426
|
+
switch (type) {
|
427
|
+
case "address":
|
428
|
+
return value.toLowerCase();
|
429
|
+
case "bool":
|
430
|
+
return !!value;
|
431
|
+
case "string":
|
432
|
+
if (typeof (value) !== "string") {
|
433
|
+
logger.throwArgumentError(`invalid string`, "value", value);
|
434
|
+
}
|
435
|
+
return value;
|
436
|
+
}
|
437
|
+
return logger.throwArgumentError("unsupported type", "type", type);
|
438
|
+
})
|
439
|
+
};
|
440
|
+
}
|
441
|
+
}
|
442
|
+
|
443
|
+
export { TypedDataEncoder };
|