@waku/rln 0.1.3-f6d5deb → 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,404 @@
|
|
1
|
+
import { isBytesLike, hexlify } from '../../bytes/lib.esm/index.js';
|
2
|
+
import { shallowCopy } from '../../properties/lib.esm/index.js';
|
3
|
+
import { toUtf8Bytes, toUtf8String } from '../../strings/lib.esm/utf8.js';
|
4
|
+
import { Logger } from '../../logger/lib.esm/index.js';
|
5
|
+
import { version } from './_version.js';
|
6
|
+
import { getUrl } from './geturl.js';
|
7
|
+
import { encode, decode } from '../../base64/lib.esm/base64.js';
|
8
|
+
|
9
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
10
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
12
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
13
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
14
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
15
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
16
|
+
});
|
17
|
+
};
|
18
|
+
const logger = new Logger(version);
|
19
|
+
function staller(duration) {
|
20
|
+
return new Promise((resolve) => {
|
21
|
+
setTimeout(resolve, duration);
|
22
|
+
});
|
23
|
+
}
|
24
|
+
function bodyify(value, type) {
|
25
|
+
if (value == null) {
|
26
|
+
return null;
|
27
|
+
}
|
28
|
+
if (typeof (value) === "string") {
|
29
|
+
return value;
|
30
|
+
}
|
31
|
+
if (isBytesLike(value)) {
|
32
|
+
if (type && (type.split("/")[0] === "text" || type.split(";")[0].trim() === "application/json")) {
|
33
|
+
try {
|
34
|
+
return toUtf8String(value);
|
35
|
+
}
|
36
|
+
catch (error) { }
|
37
|
+
}
|
38
|
+
return hexlify(value);
|
39
|
+
}
|
40
|
+
return value;
|
41
|
+
}
|
42
|
+
function unpercent(value) {
|
43
|
+
return toUtf8Bytes(value.replace(/%([0-9a-f][0-9a-f])/gi, (all, code) => {
|
44
|
+
return String.fromCharCode(parseInt(code, 16));
|
45
|
+
}));
|
46
|
+
}
|
47
|
+
// This API is still a work in progress; the future changes will likely be:
|
48
|
+
// - ConnectionInfo => FetchDataRequest<T = any>
|
49
|
+
// - FetchDataRequest.body? = string | Uint8Array | { contentType: string, data: string | Uint8Array }
|
50
|
+
// - If string => text/plain, Uint8Array => application/octet-stream (if content-type unspecified)
|
51
|
+
// - FetchDataRequest.processFunc = (body: Uint8Array, response: FetchDataResponse) => T
|
52
|
+
// For this reason, it should be considered internal until the API is finalized
|
53
|
+
function _fetchData(connection, body, processFunc) {
|
54
|
+
// How many times to retry in the event of a throttle
|
55
|
+
const attemptLimit = (typeof (connection) === "object" && connection.throttleLimit != null) ? connection.throttleLimit : 12;
|
56
|
+
logger.assertArgument((attemptLimit > 0 && (attemptLimit % 1) === 0), "invalid connection throttle limit", "connection.throttleLimit", attemptLimit);
|
57
|
+
const throttleCallback = ((typeof (connection) === "object") ? connection.throttleCallback : null);
|
58
|
+
const throttleSlotInterval = ((typeof (connection) === "object" && typeof (connection.throttleSlotInterval) === "number") ? connection.throttleSlotInterval : 100);
|
59
|
+
logger.assertArgument((throttleSlotInterval > 0 && (throttleSlotInterval % 1) === 0), "invalid connection throttle slot interval", "connection.throttleSlotInterval", throttleSlotInterval);
|
60
|
+
const errorPassThrough = ((typeof (connection) === "object") ? !!(connection.errorPassThrough) : false);
|
61
|
+
const headers = {};
|
62
|
+
let url = null;
|
63
|
+
// @TODO: Allow ConnectionInfo to override some of these values
|
64
|
+
const options = {
|
65
|
+
method: "GET",
|
66
|
+
};
|
67
|
+
let allow304 = false;
|
68
|
+
let timeout = 2 * 60 * 1000;
|
69
|
+
if (typeof (connection) === "string") {
|
70
|
+
url = connection;
|
71
|
+
}
|
72
|
+
else if (typeof (connection) === "object") {
|
73
|
+
if (connection == null || connection.url == null) {
|
74
|
+
logger.throwArgumentError("missing URL", "connection.url", connection);
|
75
|
+
}
|
76
|
+
url = connection.url;
|
77
|
+
if (typeof (connection.timeout) === "number" && connection.timeout > 0) {
|
78
|
+
timeout = connection.timeout;
|
79
|
+
}
|
80
|
+
if (connection.headers) {
|
81
|
+
for (const key in connection.headers) {
|
82
|
+
headers[key.toLowerCase()] = { key: key, value: String(connection.headers[key]) };
|
83
|
+
if (["if-none-match", "if-modified-since"].indexOf(key.toLowerCase()) >= 0) {
|
84
|
+
allow304 = true;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
options.allowGzip = !!connection.allowGzip;
|
89
|
+
if (connection.user != null && connection.password != null) {
|
90
|
+
if (url.substring(0, 6) !== "https:" && connection.allowInsecureAuthentication !== true) {
|
91
|
+
logger.throwError("basic authentication requires a secure https url", Logger.errors.INVALID_ARGUMENT, { argument: "url", url: url, user: connection.user, password: "[REDACTED]" });
|
92
|
+
}
|
93
|
+
const authorization = connection.user + ":" + connection.password;
|
94
|
+
headers["authorization"] = {
|
95
|
+
key: "Authorization",
|
96
|
+
value: "Basic " + encode(toUtf8Bytes(authorization))
|
97
|
+
};
|
98
|
+
}
|
99
|
+
if (connection.skipFetchSetup != null) {
|
100
|
+
options.skipFetchSetup = !!connection.skipFetchSetup;
|
101
|
+
}
|
102
|
+
if (connection.fetchOptions != null) {
|
103
|
+
options.fetchOptions = shallowCopy(connection.fetchOptions);
|
104
|
+
}
|
105
|
+
}
|
106
|
+
const reData = new RegExp("^data:([^;:]*)?(;base64)?,(.*)$", "i");
|
107
|
+
const dataMatch = ((url) ? url.match(reData) : null);
|
108
|
+
if (dataMatch) {
|
109
|
+
try {
|
110
|
+
const response = {
|
111
|
+
statusCode: 200,
|
112
|
+
statusMessage: "OK",
|
113
|
+
headers: { "content-type": (dataMatch[1] || "text/plain") },
|
114
|
+
body: (dataMatch[2] ? decode(dataMatch[3]) : unpercent(dataMatch[3]))
|
115
|
+
};
|
116
|
+
let result = response.body;
|
117
|
+
if (processFunc) {
|
118
|
+
result = processFunc(response.body, response);
|
119
|
+
}
|
120
|
+
return Promise.resolve(result);
|
121
|
+
}
|
122
|
+
catch (error) {
|
123
|
+
logger.throwError("processing response error", Logger.errors.SERVER_ERROR, {
|
124
|
+
body: bodyify(dataMatch[1], dataMatch[2]),
|
125
|
+
error: error,
|
126
|
+
requestBody: null,
|
127
|
+
requestMethod: "GET",
|
128
|
+
url: url
|
129
|
+
});
|
130
|
+
}
|
131
|
+
}
|
132
|
+
if (body) {
|
133
|
+
options.method = "POST";
|
134
|
+
options.body = body;
|
135
|
+
if (headers["content-type"] == null) {
|
136
|
+
headers["content-type"] = { key: "Content-Type", value: "application/octet-stream" };
|
137
|
+
}
|
138
|
+
if (headers["content-length"] == null) {
|
139
|
+
headers["content-length"] = { key: "Content-Length", value: String(body.length) };
|
140
|
+
}
|
141
|
+
}
|
142
|
+
const flatHeaders = {};
|
143
|
+
Object.keys(headers).forEach((key) => {
|
144
|
+
const header = headers[key];
|
145
|
+
flatHeaders[header.key] = header.value;
|
146
|
+
});
|
147
|
+
options.headers = flatHeaders;
|
148
|
+
const runningTimeout = (function () {
|
149
|
+
let timer = null;
|
150
|
+
const promise = new Promise(function (resolve, reject) {
|
151
|
+
if (timeout) {
|
152
|
+
timer = setTimeout(() => {
|
153
|
+
if (timer == null) {
|
154
|
+
return;
|
155
|
+
}
|
156
|
+
timer = null;
|
157
|
+
reject(logger.makeError("timeout", Logger.errors.TIMEOUT, {
|
158
|
+
requestBody: bodyify(options.body, flatHeaders["content-type"]),
|
159
|
+
requestMethod: options.method,
|
160
|
+
timeout: timeout,
|
161
|
+
url: url
|
162
|
+
}));
|
163
|
+
}, timeout);
|
164
|
+
}
|
165
|
+
});
|
166
|
+
const cancel = function () {
|
167
|
+
if (timer == null) {
|
168
|
+
return;
|
169
|
+
}
|
170
|
+
clearTimeout(timer);
|
171
|
+
timer = null;
|
172
|
+
};
|
173
|
+
return { promise, cancel };
|
174
|
+
})();
|
175
|
+
const runningFetch = (function () {
|
176
|
+
return __awaiter(this, undefined, undefined, function* () {
|
177
|
+
for (let attempt = 0; attempt < attemptLimit; attempt++) {
|
178
|
+
let response = null;
|
179
|
+
try {
|
180
|
+
response = yield getUrl(url, options);
|
181
|
+
if (attempt < attemptLimit) {
|
182
|
+
if (response.statusCode === 301 || response.statusCode === 302) {
|
183
|
+
// Redirection; for now we only support absolute locataions
|
184
|
+
const location = response.headers.location || "";
|
185
|
+
if (options.method === "GET" && location.match(/^https:/)) {
|
186
|
+
url = response.headers.location;
|
187
|
+
continue;
|
188
|
+
}
|
189
|
+
}
|
190
|
+
else if (response.statusCode === 429) {
|
191
|
+
// Exponential back-off throttling
|
192
|
+
let tryAgain = true;
|
193
|
+
if (throttleCallback) {
|
194
|
+
tryAgain = yield throttleCallback(attempt, url);
|
195
|
+
}
|
196
|
+
if (tryAgain) {
|
197
|
+
let stall = 0;
|
198
|
+
const retryAfter = response.headers["retry-after"];
|
199
|
+
if (typeof (retryAfter) === "string" && retryAfter.match(/^[1-9][0-9]*$/)) {
|
200
|
+
stall = parseInt(retryAfter) * 1000;
|
201
|
+
}
|
202
|
+
else {
|
203
|
+
stall = throttleSlotInterval * parseInt(String(Math.random() * Math.pow(2, attempt)));
|
204
|
+
}
|
205
|
+
//console.log("Stalling 429");
|
206
|
+
yield staller(stall);
|
207
|
+
continue;
|
208
|
+
}
|
209
|
+
}
|
210
|
+
}
|
211
|
+
}
|
212
|
+
catch (error) {
|
213
|
+
response = error.response;
|
214
|
+
if (response == null) {
|
215
|
+
runningTimeout.cancel();
|
216
|
+
logger.throwError("missing response", Logger.errors.SERVER_ERROR, {
|
217
|
+
requestBody: bodyify(options.body, flatHeaders["content-type"]),
|
218
|
+
requestMethod: options.method,
|
219
|
+
serverError: error,
|
220
|
+
url: url
|
221
|
+
});
|
222
|
+
}
|
223
|
+
}
|
224
|
+
let body = response.body;
|
225
|
+
if (allow304 && response.statusCode === 304) {
|
226
|
+
body = null;
|
227
|
+
}
|
228
|
+
else if (!errorPassThrough && (response.statusCode < 200 || response.statusCode >= 300)) {
|
229
|
+
runningTimeout.cancel();
|
230
|
+
logger.throwError("bad response", Logger.errors.SERVER_ERROR, {
|
231
|
+
status: response.statusCode,
|
232
|
+
headers: response.headers,
|
233
|
+
body: bodyify(body, ((response.headers) ? response.headers["content-type"] : null)),
|
234
|
+
requestBody: bodyify(options.body, flatHeaders["content-type"]),
|
235
|
+
requestMethod: options.method,
|
236
|
+
url: url
|
237
|
+
});
|
238
|
+
}
|
239
|
+
{
|
240
|
+
try {
|
241
|
+
const result = yield processFunc(body, response);
|
242
|
+
runningTimeout.cancel();
|
243
|
+
return result;
|
244
|
+
}
|
245
|
+
catch (error) {
|
246
|
+
// Allow the processFunc to trigger a throttle
|
247
|
+
if (error.throttleRetry && attempt < attemptLimit) {
|
248
|
+
let tryAgain = true;
|
249
|
+
if (throttleCallback) {
|
250
|
+
tryAgain = yield throttleCallback(attempt, url);
|
251
|
+
}
|
252
|
+
if (tryAgain) {
|
253
|
+
const timeout = throttleSlotInterval * parseInt(String(Math.random() * Math.pow(2, attempt)));
|
254
|
+
//console.log("Stalling callback");
|
255
|
+
yield staller(timeout);
|
256
|
+
continue;
|
257
|
+
}
|
258
|
+
}
|
259
|
+
runningTimeout.cancel();
|
260
|
+
logger.throwError("processing response error", Logger.errors.SERVER_ERROR, {
|
261
|
+
body: bodyify(body, ((response.headers) ? response.headers["content-type"] : null)),
|
262
|
+
error: error,
|
263
|
+
requestBody: bodyify(options.body, flatHeaders["content-type"]),
|
264
|
+
requestMethod: options.method,
|
265
|
+
url: url
|
266
|
+
});
|
267
|
+
}
|
268
|
+
}
|
269
|
+
runningTimeout.cancel();
|
270
|
+
// If we had a processFunc, it either returned a T or threw above.
|
271
|
+
// The "body" is now a Uint8Array.
|
272
|
+
return body;
|
273
|
+
}
|
274
|
+
return logger.throwError("failed response", Logger.errors.SERVER_ERROR, {
|
275
|
+
requestBody: bodyify(options.body, flatHeaders["content-type"]),
|
276
|
+
requestMethod: options.method,
|
277
|
+
url: url
|
278
|
+
});
|
279
|
+
});
|
280
|
+
})();
|
281
|
+
return Promise.race([runningTimeout.promise, runningFetch]);
|
282
|
+
}
|
283
|
+
function fetchJson(connection, json, processFunc) {
|
284
|
+
let processJsonFunc = (value, response) => {
|
285
|
+
let result = null;
|
286
|
+
if (value != null) {
|
287
|
+
try {
|
288
|
+
result = JSON.parse(toUtf8String(value));
|
289
|
+
}
|
290
|
+
catch (error) {
|
291
|
+
logger.throwError("invalid JSON", Logger.errors.SERVER_ERROR, {
|
292
|
+
body: value,
|
293
|
+
error: error
|
294
|
+
});
|
295
|
+
}
|
296
|
+
}
|
297
|
+
if (processFunc) {
|
298
|
+
result = processFunc(result, response);
|
299
|
+
}
|
300
|
+
return result;
|
301
|
+
};
|
302
|
+
// If we have json to send, we must
|
303
|
+
// - add content-type of application/json (unless already overridden)
|
304
|
+
// - convert the json to bytes
|
305
|
+
let body = null;
|
306
|
+
if (json != null) {
|
307
|
+
body = toUtf8Bytes(json);
|
308
|
+
// Create a connection with the content-type set for JSON
|
309
|
+
const updated = (typeof (connection) === "string") ? ({ url: connection }) : shallowCopy(connection);
|
310
|
+
if (updated.headers) {
|
311
|
+
const hasContentType = (Object.keys(updated.headers).filter((k) => (k.toLowerCase() === "content-type")).length) !== 0;
|
312
|
+
if (!hasContentType) {
|
313
|
+
updated.headers = shallowCopy(updated.headers);
|
314
|
+
updated.headers["content-type"] = "application/json";
|
315
|
+
}
|
316
|
+
}
|
317
|
+
else {
|
318
|
+
updated.headers = { "content-type": "application/json" };
|
319
|
+
}
|
320
|
+
connection = updated;
|
321
|
+
}
|
322
|
+
return _fetchData(connection, body, processJsonFunc);
|
323
|
+
}
|
324
|
+
function poll(func, options) {
|
325
|
+
if (!options) {
|
326
|
+
options = {};
|
327
|
+
}
|
328
|
+
options = shallowCopy(options);
|
329
|
+
if (options.floor == null) {
|
330
|
+
options.floor = 0;
|
331
|
+
}
|
332
|
+
if (options.ceiling == null) {
|
333
|
+
options.ceiling = 10000;
|
334
|
+
}
|
335
|
+
if (options.interval == null) {
|
336
|
+
options.interval = 250;
|
337
|
+
}
|
338
|
+
return new Promise(function (resolve, reject) {
|
339
|
+
let timer = null;
|
340
|
+
let done = false;
|
341
|
+
// Returns true if cancel was successful. Unsuccessful cancel means we're already done.
|
342
|
+
const cancel = () => {
|
343
|
+
if (done) {
|
344
|
+
return false;
|
345
|
+
}
|
346
|
+
done = true;
|
347
|
+
if (timer) {
|
348
|
+
clearTimeout(timer);
|
349
|
+
}
|
350
|
+
return true;
|
351
|
+
};
|
352
|
+
if (options.timeout) {
|
353
|
+
timer = setTimeout(() => {
|
354
|
+
if (cancel()) {
|
355
|
+
reject(new Error("timeout"));
|
356
|
+
}
|
357
|
+
}, options.timeout);
|
358
|
+
}
|
359
|
+
const retryLimit = options.retryLimit;
|
360
|
+
let attempt = 0;
|
361
|
+
function check() {
|
362
|
+
return func().then(function (result) {
|
363
|
+
// If we have a result, or are allowed null then we're done
|
364
|
+
if (result !== undefined) {
|
365
|
+
if (cancel()) {
|
366
|
+
resolve(result);
|
367
|
+
}
|
368
|
+
}
|
369
|
+
else if (options.oncePoll) {
|
370
|
+
options.oncePoll.once("poll", check);
|
371
|
+
}
|
372
|
+
else if (options.onceBlock) {
|
373
|
+
options.onceBlock.once("block", check);
|
374
|
+
// Otherwise, exponential back-off (up to 10s) our next request
|
375
|
+
}
|
376
|
+
else if (!done) {
|
377
|
+
attempt++;
|
378
|
+
if (attempt > retryLimit) {
|
379
|
+
if (cancel()) {
|
380
|
+
reject(new Error("retry limit reached"));
|
381
|
+
}
|
382
|
+
return;
|
383
|
+
}
|
384
|
+
let timeout = options.interval * parseInt(String(Math.random() * Math.pow(2, attempt)));
|
385
|
+
if (timeout < options.floor) {
|
386
|
+
timeout = options.floor;
|
387
|
+
}
|
388
|
+
if (timeout > options.ceiling) {
|
389
|
+
timeout = options.ceiling;
|
390
|
+
}
|
391
|
+
setTimeout(check, timeout);
|
392
|
+
}
|
393
|
+
return null;
|
394
|
+
}, function (error) {
|
395
|
+
if (cancel()) {
|
396
|
+
reject(error);
|
397
|
+
}
|
398
|
+
});
|
399
|
+
}
|
400
|
+
check();
|
401
|
+
});
|
402
|
+
}
|
403
|
+
|
404
|
+
export { _fetchData, fetchJson, poll };
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import '../../../../multiformats/dist/src/bases/base32.js';
|
2
|
+
import '../../../../multiformats/dist/src/bases/base58.js';
|
3
|
+
import { bases } from '../../../../multiformats/dist/src/basics.js';
|
4
|
+
import '../../../../multiformats/dist/src/bases/base36.js';
|
5
|
+
import { getProtocol } from './protocols-table.js';
|
6
|
+
|
7
|
+
getProtocol('ip4');
|
8
|
+
getProtocol('ip6');
|
9
|
+
getProtocol('ipcidr');
|
10
|
+
const decoders = Object.values(bases).map((c) => c.decoder);
|
11
|
+
((function () {
|
12
|
+
let acc = decoders[0].or(decoders[1]);
|
13
|
+
decoders.slice(2).forEach((d) => (acc = acc.or(d)));
|
14
|
+
return acc;
|
15
|
+
}))();
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import '../../../../multiformats/dist/src/bases/base58.js';
|
2
|
+
import '../../../../multiformats/dist/src/bases/base32.js';
|
3
|
+
import '../../../../multiformats/dist/src/bases/base36.js';
|
4
|
+
import '../../../../multiformats/dist/src/bases/base10.js';
|
5
|
+
import '../../../../multiformats/dist/src/bases/base16.js';
|
6
|
+
import '../../../../multiformats/dist/src/bases/base2.js';
|
7
|
+
import '../../../../multiformats/dist/src/bases/base256emoji.js';
|
8
|
+
import '../../../../multiformats/dist/src/bases/base64.js';
|
9
|
+
import '../../../../multiformats/dist/src/bases/base8.js';
|
10
|
+
import '../../../../multiformats/dist/src/bases/identity.js';
|
11
|
+
import '../../../../multiformats/dist/src/codecs/json.js';
|
12
|
+
import './convert.js';
|
13
|
+
import { getProtocol } from './protocols-table.js';
|
14
|
+
|
15
|
+
[
|
16
|
+
getProtocol('dns').code,
|
17
|
+
getProtocol('dns4').code,
|
18
|
+
getProtocol('dns6').code,
|
19
|
+
getProtocol('dnsaddr').code
|
20
|
+
];
|
@@ -0,0 +1,92 @@
|
|
1
|
+
const V = -1;
|
2
|
+
const names = {};
|
3
|
+
const codes = {};
|
4
|
+
const table = [
|
5
|
+
[4, 32, 'ip4'],
|
6
|
+
[6, 16, 'tcp'],
|
7
|
+
[33, 16, 'dccp'],
|
8
|
+
[41, 128, 'ip6'],
|
9
|
+
[42, V, 'ip6zone'],
|
10
|
+
[43, 8, 'ipcidr'],
|
11
|
+
[53, V, 'dns', true],
|
12
|
+
[54, V, 'dns4', true],
|
13
|
+
[55, V, 'dns6', true],
|
14
|
+
[56, V, 'dnsaddr', true],
|
15
|
+
[132, 16, 'sctp'],
|
16
|
+
[273, 16, 'udp'],
|
17
|
+
[275, 0, 'p2p-webrtc-star'],
|
18
|
+
[276, 0, 'p2p-webrtc-direct'],
|
19
|
+
[277, 0, 'p2p-stardust'],
|
20
|
+
[280, 0, 'webrtc-direct'],
|
21
|
+
[281, 0, 'webrtc'],
|
22
|
+
[290, 0, 'p2p-circuit'],
|
23
|
+
[301, 0, 'udt'],
|
24
|
+
[302, 0, 'utp'],
|
25
|
+
[400, V, 'unix', false, true],
|
26
|
+
// `ipfs` is added before `p2p` for legacy support.
|
27
|
+
// All text representations will default to `p2p`, but `ipfs` will
|
28
|
+
// still be supported
|
29
|
+
[421, V, 'ipfs'],
|
30
|
+
// `p2p` is the preferred name for 421, and is now the default
|
31
|
+
[421, V, 'p2p'],
|
32
|
+
[443, 0, 'https'],
|
33
|
+
[444, 96, 'onion'],
|
34
|
+
[445, 296, 'onion3'],
|
35
|
+
[446, V, 'garlic64'],
|
36
|
+
[448, 0, 'tls'],
|
37
|
+
[449, V, 'sni'],
|
38
|
+
[460, 0, 'quic'],
|
39
|
+
[461, 0, 'quic-v1'],
|
40
|
+
[465, 0, 'webtransport'],
|
41
|
+
[466, V, 'certhash'],
|
42
|
+
[477, 0, 'ws'],
|
43
|
+
[478, 0, 'wss'],
|
44
|
+
[479, 0, 'p2p-websocket-star'],
|
45
|
+
[480, 0, 'http'],
|
46
|
+
[481, V, 'http-path'],
|
47
|
+
[777, V, 'memory']
|
48
|
+
];
|
49
|
+
// populate tables
|
50
|
+
table.forEach(row => {
|
51
|
+
const proto = createProtocol(...row);
|
52
|
+
codes[proto.code] = proto;
|
53
|
+
names[proto.name] = proto;
|
54
|
+
});
|
55
|
+
function createProtocol(code, size, name, resolvable, path) {
|
56
|
+
return {
|
57
|
+
code,
|
58
|
+
size,
|
59
|
+
name,
|
60
|
+
resolvable: Boolean(resolvable),
|
61
|
+
path: Boolean(path)
|
62
|
+
};
|
63
|
+
}
|
64
|
+
/**
|
65
|
+
* For the passed proto string or number, return a {@link Protocol}
|
66
|
+
*
|
67
|
+
* @example
|
68
|
+
*
|
69
|
+
* ```js
|
70
|
+
* import { protocol } from '@multiformats/multiaddr'
|
71
|
+
*
|
72
|
+
* console.info(protocol(4))
|
73
|
+
* // { code: 4, size: 32, name: 'ip4', resolvable: false, path: false }
|
74
|
+
* ```
|
75
|
+
*/
|
76
|
+
function getProtocol(proto) {
|
77
|
+
if (typeof proto === 'number') {
|
78
|
+
if (codes[proto] != null) {
|
79
|
+
return codes[proto];
|
80
|
+
}
|
81
|
+
throw new Error(`no protocol with code: ${proto}`);
|
82
|
+
}
|
83
|
+
else if (typeof proto === 'string') {
|
84
|
+
if (names[proto] != null) {
|
85
|
+
return names[proto];
|
86
|
+
}
|
87
|
+
throw new Error(`no protocol with name: ${proto}`);
|
88
|
+
}
|
89
|
+
throw new Error(`invalid protocol id type: ${typeof proto}`);
|
90
|
+
}
|
91
|
+
|
92
|
+
export { codes, createProtocol, getProtocol, names, table };
|
@@ -0,0 +1,37 @@
|
|
1
|
+
/**
|
2
|
+
* Internal assertion helpers.
|
3
|
+
* @module
|
4
|
+
*/
|
5
|
+
/** Asserts something is positive integer. */
|
6
|
+
function anumber(n) {
|
7
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
8
|
+
throw new Error('positive integer expected, got ' + n);
|
9
|
+
}
|
10
|
+
/** Is number an Uint8Array? Copied from utils for perf. */
|
11
|
+
function isBytes(a) {
|
12
|
+
return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
|
13
|
+
}
|
14
|
+
/** Asserts something is Uint8Array. */
|
15
|
+
function abytes(b, ...lengths) {
|
16
|
+
if (!isBytes(b))
|
17
|
+
throw new Error('Uint8Array expected');
|
18
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
19
|
+
throw new Error('Uint8Array expected of length ' + lengths + ', got length=' + b.length);
|
20
|
+
}
|
21
|
+
/** Asserts a hash instance has not been destroyed / finished */
|
22
|
+
function aexists(instance, checkFinished = true) {
|
23
|
+
if (instance.destroyed)
|
24
|
+
throw new Error('Hash instance has been destroyed');
|
25
|
+
if (checkFinished && instance.finished)
|
26
|
+
throw new Error('Hash#digest() has already been called');
|
27
|
+
}
|
28
|
+
/** Asserts output is properly-sized byte array */
|
29
|
+
function aoutput(out, instance) {
|
30
|
+
abytes(out);
|
31
|
+
const min = instance.outputLen;
|
32
|
+
if (out.length < min) {
|
33
|
+
throw new Error('digestInto() expects output buffer of length at least ' + min);
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
export { abytes, aexists, anumber, aoutput };
|