@waku/rln 0.1.3 → 0.1.4-d27db21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -186
- package/bundle/_virtual/__node-resolve_empty.js +6 -0
- package/bundle/_virtual/_assert.js +3 -0
- package/bundle/_virtual/_commonjs-dynamic-modules.js +5 -0
- package/bundle/_virtual/_commonjsHelpers.js +32 -0
- package/bundle/_virtual/_node-resolve_empty.js +3 -0
- package/bundle/_virtual/_sha2.js +3 -0
- package/bundle/_virtual/_u64.js +3 -0
- package/bundle/_virtual/aes.js +3 -0
- package/bundle/_virtual/bn.js +3 -0
- package/bundle/_virtual/browser.js +3 -0
- package/bundle/_virtual/checksum.js +3 -0
- package/bundle/_virtual/cipher.js +3 -0
- package/bundle/_virtual/class.js +3 -0
- package/bundle/_virtual/common.js +3 -0
- package/bundle/_virtual/common2.js +3 -0
- package/bundle/_virtual/cryptoBrowser.js +3 -0
- package/bundle/_virtual/functional.js +3 -0
- package/bundle/_virtual/hash.js +3 -0
- package/bundle/_virtual/hmac.js +3 -0
- package/bundle/_virtual/index.js +3 -0
- package/bundle/_virtual/index2.js +6 -0
- package/bundle/_virtual/inherits_browser.js +3 -0
- package/bundle/_virtual/kdf.js +3 -0
- package/bundle/_virtual/lodash.js +3 -0
- package/bundle/_virtual/password.js +3 -0
- package/bundle/_virtual/pbkdf2.js +3 -0
- package/bundle/_virtual/pbkdf22.js +3 -0
- package/bundle/_virtual/random.js +3 -0
- package/bundle/_virtual/ripemd.js +3 -0
- package/bundle/_virtual/schema-validation-generated.js +3 -0
- package/bundle/_virtual/schema-validation.js +3 -0
- package/bundle/_virtual/scrypt.js +3 -0
- package/bundle/_virtual/scrypt2.js +3 -0
- package/bundle/_virtual/sha.js +3 -0
- package/bundle/_virtual/sha256.js +3 -0
- package/bundle/_virtual/sha2562.js +3 -0
- package/bundle/_virtual/sha3.js +3 -0
- package/bundle/_virtual/sha512.js +3 -0
- package/bundle/_virtual/types.js +3 -0
- package/bundle/_virtual/utils.js +3 -0
- package/bundle/_virtual/utils2.js +3 -0
- package/bundle/_virtual/utils3.js +3 -0
- package/bundle/index.js +12 -74804
- package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +96 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +148 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +20 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +210 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +18 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +30 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +22 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +43 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +19 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +58 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +854 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +609 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +66 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +302 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +110 -0
- package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +20 -0
- package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +287 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +402 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +3 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +8 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +893 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +256 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +36 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +135 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +8 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +64 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +443 -0
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +8 -0
- package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +660 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +352 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +248 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +127 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +2007 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +422 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +674 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +132 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +8 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +2430 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +76 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +219 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +279 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +69 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +404 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +15 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +20 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +92 -0
- package/bundle/node_modules/@noble/hashes/esm/_assert.js +37 -0
- package/bundle/node_modules/@noble/hashes/esm/_md.js +132 -0
- package/bundle/node_modules/@noble/hashes/esm/_u64.js +29 -0
- package/bundle/node_modules/@noble/hashes/esm/sha256.js +113 -0
- package/bundle/node_modules/@noble/hashes/esm/sha3.js +210 -0
- package/bundle/node_modules/@noble/hashes/esm/utils.js +144 -0
- package/bundle/node_modules/@waku/zerokit-rln-wasm/rln_wasm.js +756 -0
- package/bundle/node_modules/bech32/index.js +187 -0
- package/bundle/node_modules/bn.js/lib/bn.js +3361 -0
- package/bundle/node_modules/debug/src/browser.js +283 -0
- package/bundle/node_modules/debug/src/common.js +295 -0
- package/bundle/node_modules/ethereum-cryptography/esm/keccak.js +10 -0
- package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +6 -0
- package/bundle/node_modules/ethereum-cryptography/esm/utils.js +24 -0
- package/bundle/node_modules/hash.js/lib/hash/common.js +97 -0
- package/bundle/node_modules/hash.js/lib/hash/hmac.js +51 -0
- package/bundle/node_modules/hash.js/lib/hash/ripemd.js +152 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/1.js +81 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/224.js +33 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/256.js +113 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/384.js +39 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/512.js +336 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/common.js +53 -0
- package/bundle/node_modules/hash.js/lib/hash/sha.js +14 -0
- package/bundle/node_modules/hash.js/lib/hash/utils.js +282 -0
- package/bundle/node_modules/hash.js/lib/hash.js +33 -0
- package/bundle/node_modules/inherits/inherits_browser.js +33 -0
- package/bundle/node_modules/it-length-prefixed/dist/src/decode.js +6 -0
- package/bundle/node_modules/lodash/lodash.js +17207 -0
- package/bundle/node_modules/minimalistic-assert/index.js +13 -0
- package/bundle/node_modules/ms/index.js +172 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base.js +205 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base10.js +9 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base16.js +16 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base2.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base256emoji.js +41 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base32.js +58 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base36.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base58.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base64.js +28 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base8.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/identity.js +11 -0
- package/bundle/node_modules/multiformats/dist/src/basics.js +15 -0
- package/bundle/node_modules/multiformats/dist/src/bytes.js +18 -0
- package/bundle/node_modules/multiformats/dist/src/codecs/json.js +2 -0
- package/bundle/node_modules/multiformats/dist/src/vendor/base-x.js +170 -0
- package/bundle/node_modules/protons-runtime/dist/src/codec.js +20 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/enum.js +24 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/message.js +7 -0
- package/bundle/node_modules/protons-runtime/dist/src/decode.js +8 -0
- package/bundle/node_modules/protons-runtime/dist/src/encode.js +11 -0
- package/bundle/node_modules/protons-runtime/dist/src/index.js +30 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/float.js +54 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/longbits.js +175 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/pool.js +28 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/reader.js +367 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/utf8.js +99 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/writer.js +438 -0
- package/bundle/node_modules/uint8-varint/dist/src/index.js +124 -0
- package/bundle/node_modules/uint8arrays/dist/src/alloc.js +17 -0
- package/bundle/node_modules/uint8arrays/dist/src/from-string.js +19 -0
- package/bundle/node_modules/uint8arrays/dist/src/util/bases.js +49 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +21 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +18 -0
- package/bundle/packages/core/dist/lib/filter/filter.js +27 -0
- package/bundle/packages/core/dist/lib/light_push/light_push.js +27 -0
- package/bundle/packages/core/dist/lib/message/version_0.js +154 -0
- package/bundle/packages/core/dist/lib/metadata/metadata.js +27 -0
- package/bundle/packages/core/dist/lib/store/store.js +27 -0
- package/bundle/packages/interfaces/dist/connection_manager.js +19 -0
- package/bundle/packages/interfaces/dist/constants.js +6 -0
- package/bundle/packages/interfaces/dist/health_indicator.js +12 -0
- package/bundle/packages/interfaces/dist/protocols.js +92 -0
- package/bundle/packages/proto/dist/generated/filter.js +445 -0
- package/bundle/packages/proto/dist/generated/filter_v2.js +424 -0
- package/bundle/packages/proto/dist/generated/light_push.js +389 -0
- package/bundle/packages/proto/dist/generated/message.js +213 -0
- package/bundle/packages/proto/dist/generated/metadata.js +130 -0
- package/bundle/packages/proto/dist/generated/peer_exchange.js +209 -0
- package/bundle/packages/proto/dist/generated/sds_message.js +105 -0
- package/bundle/packages/proto/dist/generated/store_v3.js +490 -0
- package/bundle/packages/proto/dist/generated/topic_only_message.js +61 -0
- package/bundle/packages/rln/dist/codec.js +93 -0
- package/bundle/packages/rln/dist/contract/abi.js +394 -0
- package/bundle/packages/rln/dist/contract/constants.js +27 -0
- package/bundle/packages/rln/dist/contract/rln_contract.js +438 -0
- package/bundle/packages/rln/dist/create.js +9 -0
- package/bundle/packages/rln/dist/identity.js +30 -0
- package/bundle/packages/rln/dist/keystore/cipher.js +31 -0
- package/bundle/packages/rln/dist/keystore/credential_validation_generated.js +119 -0
- package/bundle/packages/rln/dist/keystore/keystore.js +223 -0
- package/bundle/packages/rln/dist/keystore/keystore_validation_generated.js +74 -0
- package/bundle/packages/rln/dist/keystore/schema_validator.js +20 -0
- package/bundle/packages/rln/dist/message.js +51 -0
- package/bundle/packages/rln/dist/proof.js +54 -0
- package/bundle/packages/rln/dist/resources/verification_key.js +112 -0
- package/bundle/packages/rln/dist/resources/witness_calculator.js +330 -0
- package/bundle/packages/rln/dist/rln.js +220 -0
- package/bundle/packages/rln/dist/root_tracker.js +76 -0
- package/bundle/packages/rln/dist/utils/bytes.js +65 -0
- package/bundle/packages/rln/dist/utils/epoch.js +39 -0
- package/bundle/packages/rln/dist/utils/hash.js +10 -0
- package/bundle/packages/rln/dist/utils/metamask.js +14 -0
- package/bundle/packages/rln/dist/zerokit.js +128 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +52 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +65 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +99 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/index.js +28 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +78 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1253 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +40 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/types.js +5 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +41 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +23 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +12 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +77 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +9 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +215 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +35 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +21 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +66 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +24 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +7 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +11 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +52 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +124 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +71 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +10 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +88 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +99 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +233 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +133 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +243 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +167 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/native.js +4 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/rng.js +13 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/stringify.js +28 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/v4.js +19 -0
- package/bundle/packages/utils/dist/bytes/index.js +44 -0
- package/bundle/packages/utils/dist/common/sharding/index.js +91 -0
- package/bundle/packages/utils/dist/logger/index.js +31 -0
- package/bundle/resources/verification_key.d.ts +13 -0
- package/bundle/resources/verification_key.js +112 -0
- package/bundle/resources/witness_calculator.d.ts +11 -0
- package/bundle/resources/witness_calculator.js +328 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/codec.d.ts +5 -5
- package/dist/codec.js +6 -6
- package/dist/codec.js.map +1 -1
- package/dist/contract/abi.d.ts +42 -0
- package/dist/contract/abi.js +393 -0
- package/dist/contract/abi.js.map +1 -0
- package/dist/contract/constants.d.ts +59 -3
- package/dist/contract/constants.js +21 -63
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_contract.d.ts +98 -17
- package/dist/contract/rln_contract.js +292 -71
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/identity.js +5 -2
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/keystore/cipher.js +3 -3
- package/dist/keystore/cipher.js.map +1 -1
- package/dist/keystore/credential_validation_generated.js.map +1 -1
- package/dist/keystore/keystore.js +4 -4
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/keystore_validation_generated.js.map +1 -1
- package/dist/message.js +3 -3
- package/dist/message.js.map +1 -1
- package/dist/proof.js +3 -2
- package/dist/proof.js.map +1 -1
- package/dist/resources/verification_key.d.ts +12 -11
- package/dist/resources/verification_key.js +103 -103
- package/dist/resources/witness_calculator.d.ts +10 -15
- package/dist/resources/witness_calculator.js +302 -265
- package/dist/rln.d.ts +5 -1
- package/dist/rln.js +56 -28
- package/dist/rln.js.map +1 -1
- package/dist/root_tracker.js.map +1 -1
- package/dist/utils/epoch.js +5 -5
- package/dist/utils/epoch.js.map +1 -1
- package/dist/zerokit.d.ts +13 -9
- package/dist/zerokit.js +40 -20
- package/dist/zerokit.js.map +1 -1
- package/package.json +1 -146
- package/src/codec.ts +26 -22
- package/src/contract/abi.ts +392 -0
- package/src/contract/constants.ts +28 -0
- package/src/contract/index.ts +2 -0
- package/src/contract/rln_contract.ts +686 -0
- package/src/identity.ts +8 -4
- package/src/index.ts +4 -9
- package/src/keystore/cipher.ts +54 -0
- package/src/keystore/credential_validation_generated.ts +7 -0
- package/src/keystore/index.ts +5 -0
- package/src/keystore/keystore.ts +330 -0
- package/src/keystore/keystore_validation_generated.ts +7 -0
- package/src/keystore/schema_validator.ts +34 -0
- package/src/keystore/types.ts +36 -0
- package/src/message.ts +10 -10
- package/src/proof.ts +13 -11
- package/src/resources/verification_key.d.ts +13 -0
- package/src/resources/witness_calculator.d.ts +11 -0
- package/src/rln.ts +76 -31
- package/src/root_tracker.ts +7 -6
- package/src/utils/bytes.ts +84 -0
- package/src/utils/epoch.ts +30 -0
- package/src/utils/hash.ts +15 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/metamask.ts +17 -0
- package/src/zerokit.ts +95 -33
- package/bundle/assets/rln_wasm_bg-a503e304.wasm +0 -0
- package/dist/resources/verification_key.js.map +0 -1
- package/dist/resources/witness_calculator.js.map +0 -1
- /package/bundle/{assets/rln-6ded2896.wasm → resources/rln.wasm} +0 -0
- /package/bundle/{assets/rln_final-8b299152.zkey → resources/rln_final.zkey} +0 -0
@@ -0,0 +1,96 @@
|
|
1
|
+
import { arrayify } from '../../bytes/lib.esm/index.js';
|
2
|
+
import { defineReadOnly } from '../../properties/lib.esm/index.js';
|
3
|
+
import { Logger } from '../../logger/lib.esm/index.js';
|
4
|
+
import { version } from './_version.js';
|
5
|
+
import { Reader, Writer } from './coders/abstract-coder.js';
|
6
|
+
import { AddressCoder } from './coders/address.js';
|
7
|
+
import { ArrayCoder } from './coders/array.js';
|
8
|
+
import { BooleanCoder } from './coders/boolean.js';
|
9
|
+
import { BytesCoder } from './coders/bytes.js';
|
10
|
+
import { FixedBytesCoder } from './coders/fixed-bytes.js';
|
11
|
+
import { NullCoder } from './coders/null.js';
|
12
|
+
import { NumberCoder } from './coders/number.js';
|
13
|
+
import { StringCoder } from './coders/string.js';
|
14
|
+
import { TupleCoder } from './coders/tuple.js';
|
15
|
+
import { ParamType } from './fragments.js';
|
16
|
+
|
17
|
+
const logger = new Logger(version);
|
18
|
+
const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
|
19
|
+
const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
|
20
|
+
class AbiCoder {
|
21
|
+
constructor(coerceFunc) {
|
22
|
+
defineReadOnly(this, "coerceFunc", coerceFunc || null);
|
23
|
+
}
|
24
|
+
_getCoder(param) {
|
25
|
+
switch (param.baseType) {
|
26
|
+
case "address":
|
27
|
+
return new AddressCoder(param.name);
|
28
|
+
case "bool":
|
29
|
+
return new BooleanCoder(param.name);
|
30
|
+
case "string":
|
31
|
+
return new StringCoder(param.name);
|
32
|
+
case "bytes":
|
33
|
+
return new BytesCoder(param.name);
|
34
|
+
case "array":
|
35
|
+
return new ArrayCoder(this._getCoder(param.arrayChildren), param.arrayLength, param.name);
|
36
|
+
case "tuple":
|
37
|
+
return new TupleCoder((param.components || []).map((component) => {
|
38
|
+
return this._getCoder(component);
|
39
|
+
}), param.name);
|
40
|
+
case "":
|
41
|
+
return new NullCoder(param.name);
|
42
|
+
}
|
43
|
+
// u?int[0-9]*
|
44
|
+
let match = param.type.match(paramTypeNumber);
|
45
|
+
if (match) {
|
46
|
+
let size = parseInt(match[2] || "256");
|
47
|
+
if (size === 0 || size > 256 || (size % 8) !== 0) {
|
48
|
+
logger.throwArgumentError("invalid " + match[1] + " bit length", "param", param);
|
49
|
+
}
|
50
|
+
return new NumberCoder(size / 8, (match[1] === "int"), param.name);
|
51
|
+
}
|
52
|
+
// bytes[0-9]+
|
53
|
+
match = param.type.match(paramTypeBytes);
|
54
|
+
if (match) {
|
55
|
+
let size = parseInt(match[1]);
|
56
|
+
if (size === 0 || size > 32) {
|
57
|
+
logger.throwArgumentError("invalid bytes length", "param", param);
|
58
|
+
}
|
59
|
+
return new FixedBytesCoder(size, param.name);
|
60
|
+
}
|
61
|
+
return logger.throwArgumentError("invalid type", "type", param.type);
|
62
|
+
}
|
63
|
+
_getWordSize() { return 32; }
|
64
|
+
_getReader(data, allowLoose) {
|
65
|
+
return new Reader(data, this._getWordSize(), this.coerceFunc, allowLoose);
|
66
|
+
}
|
67
|
+
_getWriter() {
|
68
|
+
return new Writer(this._getWordSize());
|
69
|
+
}
|
70
|
+
getDefaultValue(types) {
|
71
|
+
const coders = types.map((type) => this._getCoder(ParamType.from(type)));
|
72
|
+
const coder = new TupleCoder(coders, "_");
|
73
|
+
return coder.defaultValue();
|
74
|
+
}
|
75
|
+
encode(types, values) {
|
76
|
+
if (types.length !== values.length) {
|
77
|
+
logger.throwError("types/values length mismatch", Logger.errors.INVALID_ARGUMENT, {
|
78
|
+
count: { types: types.length, values: values.length },
|
79
|
+
value: { types: types, values: values }
|
80
|
+
});
|
81
|
+
}
|
82
|
+
const coders = types.map((type) => this._getCoder(ParamType.from(type)));
|
83
|
+
const coder = (new TupleCoder(coders, "_"));
|
84
|
+
const writer = this._getWriter();
|
85
|
+
coder.encode(writer, values);
|
86
|
+
return writer.data;
|
87
|
+
}
|
88
|
+
decode(types, data, loose) {
|
89
|
+
const coders = types.map((type) => this._getCoder(ParamType.from(type)));
|
90
|
+
const coder = new TupleCoder(coders, "_");
|
91
|
+
return coder.decode(this._getReader(arrayify(data), loose));
|
92
|
+
}
|
93
|
+
}
|
94
|
+
const defaultAbiCoder = new AbiCoder();
|
95
|
+
|
96
|
+
export { AbiCoder, defaultAbiCoder };
|
@@ -0,0 +1,148 @@
|
|
1
|
+
import { hexConcat, concat, arrayify, hexlify } from '../../../bytes/lib.esm/index.js';
|
2
|
+
import { defineReadOnly } from '../../../properties/lib.esm/index.js';
|
3
|
+
import { Logger } from '../../../logger/lib.esm/index.js';
|
4
|
+
import { version } from '../_version.js';
|
5
|
+
import { BigNumber } from '../../../bignumber/lib.esm/bignumber.js';
|
6
|
+
|
7
|
+
const logger = new Logger(version);
|
8
|
+
function checkResultErrors(result) {
|
9
|
+
// Find the first error (if any)
|
10
|
+
const errors = [];
|
11
|
+
const checkErrors = function (path, object) {
|
12
|
+
if (!Array.isArray(object)) {
|
13
|
+
return;
|
14
|
+
}
|
15
|
+
for (let key in object) {
|
16
|
+
const childPath = path.slice();
|
17
|
+
childPath.push(key);
|
18
|
+
try {
|
19
|
+
checkErrors(childPath, object[key]);
|
20
|
+
}
|
21
|
+
catch (error) {
|
22
|
+
errors.push({ path: childPath, error: error });
|
23
|
+
}
|
24
|
+
}
|
25
|
+
};
|
26
|
+
checkErrors([], result);
|
27
|
+
return errors;
|
28
|
+
}
|
29
|
+
class Coder {
|
30
|
+
constructor(name, type, localName, dynamic) {
|
31
|
+
// @TODO: defineReadOnly these
|
32
|
+
this.name = name;
|
33
|
+
this.type = type;
|
34
|
+
this.localName = localName;
|
35
|
+
this.dynamic = dynamic;
|
36
|
+
}
|
37
|
+
_throwError(message, value) {
|
38
|
+
logger.throwArgumentError(message, this.localName, value);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
class Writer {
|
42
|
+
constructor(wordSize) {
|
43
|
+
defineReadOnly(this, "wordSize", wordSize || 32);
|
44
|
+
this._data = [];
|
45
|
+
this._dataLength = 0;
|
46
|
+
this._padding = new Uint8Array(wordSize);
|
47
|
+
}
|
48
|
+
get data() {
|
49
|
+
return hexConcat(this._data);
|
50
|
+
}
|
51
|
+
get length() { return this._dataLength; }
|
52
|
+
_writeData(data) {
|
53
|
+
this._data.push(data);
|
54
|
+
this._dataLength += data.length;
|
55
|
+
return data.length;
|
56
|
+
}
|
57
|
+
appendWriter(writer) {
|
58
|
+
return this._writeData(concat(writer._data));
|
59
|
+
}
|
60
|
+
// Arrayish items; padded on the right to wordSize
|
61
|
+
writeBytes(value) {
|
62
|
+
let bytes = arrayify(value);
|
63
|
+
const paddingOffset = bytes.length % this.wordSize;
|
64
|
+
if (paddingOffset) {
|
65
|
+
bytes = concat([bytes, this._padding.slice(paddingOffset)]);
|
66
|
+
}
|
67
|
+
return this._writeData(bytes);
|
68
|
+
}
|
69
|
+
_getValue(value) {
|
70
|
+
let bytes = arrayify(BigNumber.from(value));
|
71
|
+
if (bytes.length > this.wordSize) {
|
72
|
+
logger.throwError("value out-of-bounds", Logger.errors.BUFFER_OVERRUN, {
|
73
|
+
length: this.wordSize,
|
74
|
+
offset: bytes.length
|
75
|
+
});
|
76
|
+
}
|
77
|
+
if (bytes.length % this.wordSize) {
|
78
|
+
bytes = concat([this._padding.slice(bytes.length % this.wordSize), bytes]);
|
79
|
+
}
|
80
|
+
return bytes;
|
81
|
+
}
|
82
|
+
// BigNumberish items; padded on the left to wordSize
|
83
|
+
writeValue(value) {
|
84
|
+
return this._writeData(this._getValue(value));
|
85
|
+
}
|
86
|
+
writeUpdatableValue() {
|
87
|
+
const offset = this._data.length;
|
88
|
+
this._data.push(this._padding);
|
89
|
+
this._dataLength += this.wordSize;
|
90
|
+
return (value) => {
|
91
|
+
this._data[offset] = this._getValue(value);
|
92
|
+
};
|
93
|
+
}
|
94
|
+
}
|
95
|
+
class Reader {
|
96
|
+
constructor(data, wordSize, coerceFunc, allowLoose) {
|
97
|
+
defineReadOnly(this, "_data", arrayify(data));
|
98
|
+
defineReadOnly(this, "wordSize", wordSize || 32);
|
99
|
+
defineReadOnly(this, "_coerceFunc", coerceFunc);
|
100
|
+
defineReadOnly(this, "allowLoose", allowLoose);
|
101
|
+
this._offset = 0;
|
102
|
+
}
|
103
|
+
get data() { return hexlify(this._data); }
|
104
|
+
get consumed() { return this._offset; }
|
105
|
+
// The default Coerce function
|
106
|
+
static coerce(name, value) {
|
107
|
+
let match = name.match("^u?int([0-9]+)$");
|
108
|
+
if (match && parseInt(match[1]) <= 48) {
|
109
|
+
value = value.toNumber();
|
110
|
+
}
|
111
|
+
return value;
|
112
|
+
}
|
113
|
+
coerce(name, value) {
|
114
|
+
if (this._coerceFunc) {
|
115
|
+
return this._coerceFunc(name, value);
|
116
|
+
}
|
117
|
+
return Reader.coerce(name, value);
|
118
|
+
}
|
119
|
+
_peekBytes(offset, length, loose) {
|
120
|
+
let alignedLength = Math.ceil(length / this.wordSize) * this.wordSize;
|
121
|
+
if (this._offset + alignedLength > this._data.length) {
|
122
|
+
if (this.allowLoose && loose && this._offset + length <= this._data.length) {
|
123
|
+
alignedLength = length;
|
124
|
+
}
|
125
|
+
else {
|
126
|
+
logger.throwError("data out-of-bounds", Logger.errors.BUFFER_OVERRUN, {
|
127
|
+
length: this._data.length,
|
128
|
+
offset: this._offset + alignedLength
|
129
|
+
});
|
130
|
+
}
|
131
|
+
}
|
132
|
+
return this._data.slice(this._offset, this._offset + alignedLength);
|
133
|
+
}
|
134
|
+
subReader(offset) {
|
135
|
+
return new Reader(this._data.slice(this._offset + offset), this.wordSize, this._coerceFunc, this.allowLoose);
|
136
|
+
}
|
137
|
+
readBytes(length, loose) {
|
138
|
+
let bytes = this._peekBytes(0, length, !!loose);
|
139
|
+
this._offset += bytes.length;
|
140
|
+
// @TODO: Make sure the length..end bytes are all 0?
|
141
|
+
return bytes.slice(0, length);
|
142
|
+
}
|
143
|
+
readValue() {
|
144
|
+
return BigNumber.from(this.readBytes(this.wordSize));
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
export { Coder, Reader, Writer, checkResultErrors };
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { getAddress } from '../../../address/lib.esm/index.js';
|
2
|
+
import { hexZeroPad } from '../../../bytes/lib.esm/index.js';
|
3
|
+
import { Coder } from './abstract-coder.js';
|
4
|
+
|
5
|
+
class AddressCoder extends Coder {
|
6
|
+
constructor(localName) {
|
7
|
+
super("address", "address", localName, false);
|
8
|
+
}
|
9
|
+
defaultValue() {
|
10
|
+
return "0x0000000000000000000000000000000000000000";
|
11
|
+
}
|
12
|
+
encode(writer, value) {
|
13
|
+
try {
|
14
|
+
value = getAddress(value);
|
15
|
+
}
|
16
|
+
catch (error) {
|
17
|
+
this._throwError(error.message, value);
|
18
|
+
}
|
19
|
+
return writer.writeValue(value);
|
20
|
+
}
|
21
|
+
decode(reader) {
|
22
|
+
return getAddress(hexZeroPad(reader.readValue().toHexString(), 20));
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
export { AddressCoder };
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { Coder } from './abstract-coder.js';
|
2
|
+
|
3
|
+
// Clones the functionality of an existing Coder, but without a localName
|
4
|
+
class AnonymousCoder extends Coder {
|
5
|
+
constructor(coder) {
|
6
|
+
super(coder.name, coder.type, undefined, coder.dynamic);
|
7
|
+
this.coder = coder;
|
8
|
+
}
|
9
|
+
defaultValue() {
|
10
|
+
return this.coder.defaultValue();
|
11
|
+
}
|
12
|
+
encode(writer, value) {
|
13
|
+
return this.coder.encode(writer, value);
|
14
|
+
}
|
15
|
+
decode(reader) {
|
16
|
+
return this.coder.decode(reader);
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
export { AnonymousCoder };
|
@@ -0,0 +1,210 @@
|
|
1
|
+
import { Logger } from '../../../logger/lib.esm/index.js';
|
2
|
+
import { version } from '../_version.js';
|
3
|
+
import { Coder, Writer } from './abstract-coder.js';
|
4
|
+
import { AnonymousCoder } from './anonymous.js';
|
5
|
+
|
6
|
+
const logger = new Logger(version);
|
7
|
+
function pack(writer, coders, values) {
|
8
|
+
let arrayValues = null;
|
9
|
+
if (Array.isArray(values)) {
|
10
|
+
arrayValues = values;
|
11
|
+
}
|
12
|
+
else if (values && typeof (values) === "object") {
|
13
|
+
let unique = {};
|
14
|
+
arrayValues = coders.map((coder) => {
|
15
|
+
const name = coder.localName;
|
16
|
+
if (!name) {
|
17
|
+
logger.throwError("cannot encode object for signature with missing names", Logger.errors.INVALID_ARGUMENT, {
|
18
|
+
argument: "values",
|
19
|
+
coder: coder,
|
20
|
+
value: values
|
21
|
+
});
|
22
|
+
}
|
23
|
+
if (unique[name]) {
|
24
|
+
logger.throwError("cannot encode object for signature with duplicate names", Logger.errors.INVALID_ARGUMENT, {
|
25
|
+
argument: "values",
|
26
|
+
coder: coder,
|
27
|
+
value: values
|
28
|
+
});
|
29
|
+
}
|
30
|
+
unique[name] = true;
|
31
|
+
return values[name];
|
32
|
+
});
|
33
|
+
}
|
34
|
+
else {
|
35
|
+
logger.throwArgumentError("invalid tuple value", "tuple", values);
|
36
|
+
}
|
37
|
+
if (coders.length !== arrayValues.length) {
|
38
|
+
logger.throwArgumentError("types/value length mismatch", "tuple", values);
|
39
|
+
}
|
40
|
+
let staticWriter = new Writer(writer.wordSize);
|
41
|
+
let dynamicWriter = new Writer(writer.wordSize);
|
42
|
+
let updateFuncs = [];
|
43
|
+
coders.forEach((coder, index) => {
|
44
|
+
let value = arrayValues[index];
|
45
|
+
if (coder.dynamic) {
|
46
|
+
// Get current dynamic offset (for the future pointer)
|
47
|
+
let dynamicOffset = dynamicWriter.length;
|
48
|
+
// Encode the dynamic value into the dynamicWriter
|
49
|
+
coder.encode(dynamicWriter, value);
|
50
|
+
// Prepare to populate the correct offset once we are done
|
51
|
+
let updateFunc = staticWriter.writeUpdatableValue();
|
52
|
+
updateFuncs.push((baseOffset) => {
|
53
|
+
updateFunc(baseOffset + dynamicOffset);
|
54
|
+
});
|
55
|
+
}
|
56
|
+
else {
|
57
|
+
coder.encode(staticWriter, value);
|
58
|
+
}
|
59
|
+
});
|
60
|
+
// Backfill all the dynamic offsets, now that we know the static length
|
61
|
+
updateFuncs.forEach((func) => { func(staticWriter.length); });
|
62
|
+
let length = writer.appendWriter(staticWriter);
|
63
|
+
length += writer.appendWriter(dynamicWriter);
|
64
|
+
return length;
|
65
|
+
}
|
66
|
+
function unpack(reader, coders) {
|
67
|
+
let values = [];
|
68
|
+
// A reader anchored to this base
|
69
|
+
let baseReader = reader.subReader(0);
|
70
|
+
coders.forEach((coder) => {
|
71
|
+
let value = null;
|
72
|
+
if (coder.dynamic) {
|
73
|
+
let offset = reader.readValue();
|
74
|
+
let offsetReader = baseReader.subReader(offset.toNumber());
|
75
|
+
try {
|
76
|
+
value = coder.decode(offsetReader);
|
77
|
+
}
|
78
|
+
catch (error) {
|
79
|
+
// Cannot recover from this
|
80
|
+
if (error.code === Logger.errors.BUFFER_OVERRUN) {
|
81
|
+
throw error;
|
82
|
+
}
|
83
|
+
value = error;
|
84
|
+
value.baseType = coder.name;
|
85
|
+
value.name = coder.localName;
|
86
|
+
value.type = coder.type;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
else {
|
90
|
+
try {
|
91
|
+
value = coder.decode(reader);
|
92
|
+
}
|
93
|
+
catch (error) {
|
94
|
+
// Cannot recover from this
|
95
|
+
if (error.code === Logger.errors.BUFFER_OVERRUN) {
|
96
|
+
throw error;
|
97
|
+
}
|
98
|
+
value = error;
|
99
|
+
value.baseType = coder.name;
|
100
|
+
value.name = coder.localName;
|
101
|
+
value.type = coder.type;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
if (value != undefined) {
|
105
|
+
values.push(value);
|
106
|
+
}
|
107
|
+
});
|
108
|
+
// We only output named properties for uniquely named coders
|
109
|
+
const uniqueNames = coders.reduce((accum, coder) => {
|
110
|
+
const name = coder.localName;
|
111
|
+
if (name) {
|
112
|
+
if (!accum[name]) {
|
113
|
+
accum[name] = 0;
|
114
|
+
}
|
115
|
+
accum[name]++;
|
116
|
+
}
|
117
|
+
return accum;
|
118
|
+
}, {});
|
119
|
+
// Add any named parameters (i.e. tuples)
|
120
|
+
coders.forEach((coder, index) => {
|
121
|
+
let name = coder.localName;
|
122
|
+
if (!name || uniqueNames[name] !== 1) {
|
123
|
+
return;
|
124
|
+
}
|
125
|
+
if (name === "length") {
|
126
|
+
name = "_length";
|
127
|
+
}
|
128
|
+
if (values[name] != null) {
|
129
|
+
return;
|
130
|
+
}
|
131
|
+
const value = values[index];
|
132
|
+
if (value instanceof Error) {
|
133
|
+
Object.defineProperty(values, name, {
|
134
|
+
enumerable: true,
|
135
|
+
get: () => { throw value; }
|
136
|
+
});
|
137
|
+
}
|
138
|
+
else {
|
139
|
+
values[name] = value;
|
140
|
+
}
|
141
|
+
});
|
142
|
+
for (let i = 0; i < values.length; i++) {
|
143
|
+
const value = values[i];
|
144
|
+
if (value instanceof Error) {
|
145
|
+
Object.defineProperty(values, i, {
|
146
|
+
enumerable: true,
|
147
|
+
get: () => { throw value; }
|
148
|
+
});
|
149
|
+
}
|
150
|
+
}
|
151
|
+
return Object.freeze(values);
|
152
|
+
}
|
153
|
+
class ArrayCoder extends Coder {
|
154
|
+
constructor(coder, length, localName) {
|
155
|
+
const type = (coder.type + "[" + (length >= 0 ? length : "") + "]");
|
156
|
+
const dynamic = (length === -1 || coder.dynamic);
|
157
|
+
super("array", type, localName, dynamic);
|
158
|
+
this.coder = coder;
|
159
|
+
this.length = length;
|
160
|
+
}
|
161
|
+
defaultValue() {
|
162
|
+
// Verifies the child coder is valid (even if the array is dynamic or 0-length)
|
163
|
+
const defaultChild = this.coder.defaultValue();
|
164
|
+
const result = [];
|
165
|
+
for (let i = 0; i < this.length; i++) {
|
166
|
+
result.push(defaultChild);
|
167
|
+
}
|
168
|
+
return result;
|
169
|
+
}
|
170
|
+
encode(writer, value) {
|
171
|
+
if (!Array.isArray(value)) {
|
172
|
+
this._throwError("expected array value", value);
|
173
|
+
}
|
174
|
+
let count = this.length;
|
175
|
+
if (count === -1) {
|
176
|
+
count = value.length;
|
177
|
+
writer.writeValue(value.length);
|
178
|
+
}
|
179
|
+
logger.checkArgumentCount(value.length, count, "coder array" + (this.localName ? (" " + this.localName) : ""));
|
180
|
+
let coders = [];
|
181
|
+
for (let i = 0; i < value.length; i++) {
|
182
|
+
coders.push(this.coder);
|
183
|
+
}
|
184
|
+
return pack(writer, coders, value);
|
185
|
+
}
|
186
|
+
decode(reader) {
|
187
|
+
let count = this.length;
|
188
|
+
if (count === -1) {
|
189
|
+
count = reader.readValue().toNumber();
|
190
|
+
// Check that there is *roughly* enough data to ensure
|
191
|
+
// stray random data is not being read as a length. Each
|
192
|
+
// slot requires at least 32 bytes for their value (or 32
|
193
|
+
// bytes as a link to the data). This could use a much
|
194
|
+
// tighter bound, but we are erroring on the side of safety.
|
195
|
+
if (count * 32 > reader._data.length) {
|
196
|
+
logger.throwError("insufficient data length", Logger.errors.BUFFER_OVERRUN, {
|
197
|
+
length: reader._data.length,
|
198
|
+
count: count
|
199
|
+
});
|
200
|
+
}
|
201
|
+
}
|
202
|
+
let coders = [];
|
203
|
+
for (let i = 0; i < count; i++) {
|
204
|
+
coders.push(new AnonymousCoder(this.coder));
|
205
|
+
}
|
206
|
+
return reader.coerce(this.name, unpack(reader, coders));
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
export { ArrayCoder, pack, unpack };
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Coder } from './abstract-coder.js';
|
2
|
+
|
3
|
+
class BooleanCoder extends Coder {
|
4
|
+
constructor(localName) {
|
5
|
+
super("bool", "bool", localName, false);
|
6
|
+
}
|
7
|
+
defaultValue() {
|
8
|
+
return false;
|
9
|
+
}
|
10
|
+
encode(writer, value) {
|
11
|
+
return writer.writeValue(value ? 1 : 0);
|
12
|
+
}
|
13
|
+
decode(reader) {
|
14
|
+
return reader.coerce(this.type, !reader.readValue().isZero());
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
export { BooleanCoder };
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { hexlify, arrayify } from '../../../bytes/lib.esm/index.js';
|
2
|
+
import { Coder } from './abstract-coder.js';
|
3
|
+
|
4
|
+
class DynamicBytesCoder extends Coder {
|
5
|
+
constructor(type, localName) {
|
6
|
+
super(type, type, localName, true);
|
7
|
+
}
|
8
|
+
defaultValue() {
|
9
|
+
return "0x";
|
10
|
+
}
|
11
|
+
encode(writer, value) {
|
12
|
+
value = arrayify(value);
|
13
|
+
let length = writer.writeValue(value.length);
|
14
|
+
length += writer.writeBytes(value);
|
15
|
+
return length;
|
16
|
+
}
|
17
|
+
decode(reader) {
|
18
|
+
return reader.readBytes(reader.readValue().toNumber(), true);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
class BytesCoder extends DynamicBytesCoder {
|
22
|
+
constructor(localName) {
|
23
|
+
super("bytes", localName);
|
24
|
+
}
|
25
|
+
decode(reader) {
|
26
|
+
return reader.coerce(this.name, hexlify(super.decode(reader)));
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
export { BytesCoder, DynamicBytesCoder };
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { arrayify, hexlify } from '../../../bytes/lib.esm/index.js';
|
2
|
+
import { Coder } from './abstract-coder.js';
|
3
|
+
|
4
|
+
// @TODO: Merge this with bytes
|
5
|
+
class FixedBytesCoder extends Coder {
|
6
|
+
constructor(size, localName) {
|
7
|
+
let name = "bytes" + String(size);
|
8
|
+
super(name, name, localName, false);
|
9
|
+
this.size = size;
|
10
|
+
}
|
11
|
+
defaultValue() {
|
12
|
+
return ("0x0000000000000000000000000000000000000000000000000000000000000000").substring(0, 2 + this.size * 2);
|
13
|
+
}
|
14
|
+
encode(writer, value) {
|
15
|
+
let data = arrayify(value);
|
16
|
+
if (data.length !== this.size) {
|
17
|
+
this._throwError("incorrect data length", value);
|
18
|
+
}
|
19
|
+
return writer.writeBytes(data);
|
20
|
+
}
|
21
|
+
decode(reader) {
|
22
|
+
return reader.coerce(this.name, hexlify(reader.readBytes(this.size)));
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
export { FixedBytesCoder };
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { Coder } from './abstract-coder.js';
|
2
|
+
|
3
|
+
class NullCoder extends Coder {
|
4
|
+
constructor(localName) {
|
5
|
+
super("null", "", localName, false);
|
6
|
+
}
|
7
|
+
defaultValue() {
|
8
|
+
return null;
|
9
|
+
}
|
10
|
+
encode(writer, value) {
|
11
|
+
if (value != null) {
|
12
|
+
this._throwError("not null", value);
|
13
|
+
}
|
14
|
+
return writer.writeBytes([]);
|
15
|
+
}
|
16
|
+
decode(reader) {
|
17
|
+
reader.readBytes(0);
|
18
|
+
return reader.coerce(this.name, null);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
export { NullCoder };
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { Coder } from './abstract-coder.js';
|
2
|
+
import { BigNumber } from '../../../bignumber/lib.esm/bignumber.js';
|
3
|
+
import { MaxUint256, One, NegativeOne, Zero } from '../../../constants/lib.esm/bignumbers.js';
|
4
|
+
|
5
|
+
class NumberCoder extends Coder {
|
6
|
+
constructor(size, signed, localName) {
|
7
|
+
const name = ((signed ? "int" : "uint") + (size * 8));
|
8
|
+
super(name, name, localName, false);
|
9
|
+
this.size = size;
|
10
|
+
this.signed = signed;
|
11
|
+
}
|
12
|
+
defaultValue() {
|
13
|
+
return 0;
|
14
|
+
}
|
15
|
+
encode(writer, value) {
|
16
|
+
let v = BigNumber.from(value);
|
17
|
+
// Check bounds are safe for encoding
|
18
|
+
let maxUintValue = MaxUint256.mask(writer.wordSize * 8);
|
19
|
+
if (this.signed) {
|
20
|
+
let bounds = maxUintValue.mask(this.size * 8 - 1);
|
21
|
+
if (v.gt(bounds) || v.lt(bounds.add(One).mul(NegativeOne))) {
|
22
|
+
this._throwError("value out-of-bounds", value);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
else if (v.lt(Zero) || v.gt(maxUintValue.mask(this.size * 8))) {
|
26
|
+
this._throwError("value out-of-bounds", value);
|
27
|
+
}
|
28
|
+
v = v.toTwos(this.size * 8).mask(this.size * 8);
|
29
|
+
if (this.signed) {
|
30
|
+
v = v.fromTwos(this.size * 8).toTwos(8 * writer.wordSize);
|
31
|
+
}
|
32
|
+
return writer.writeValue(v);
|
33
|
+
}
|
34
|
+
decode(reader) {
|
35
|
+
let value = reader.readValue().mask(this.size * 8);
|
36
|
+
if (this.signed) {
|
37
|
+
value = value.fromTwos(this.size * 8);
|
38
|
+
}
|
39
|
+
return reader.coerce(this.name, value);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
export { NumberCoder };
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { toUtf8Bytes, toUtf8String } from '../../../strings/lib.esm/utf8.js';
|
2
|
+
import { DynamicBytesCoder } from './bytes.js';
|
3
|
+
|
4
|
+
class StringCoder extends DynamicBytesCoder {
|
5
|
+
constructor(localName) {
|
6
|
+
super("string", localName);
|
7
|
+
}
|
8
|
+
defaultValue() {
|
9
|
+
return "";
|
10
|
+
}
|
11
|
+
encode(writer, value) {
|
12
|
+
return super.encode(writer, toUtf8Bytes(value));
|
13
|
+
}
|
14
|
+
decode(reader) {
|
15
|
+
return toUtf8String(super.decode(reader));
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
export { StringCoder };
|