@waku/rln 0.1.3-f6d5deb → 0.1.4-29a4c3f.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -186
- package/bundle/_virtual/__node-resolve_empty.js +6 -0
- package/bundle/_virtual/_assert.js +3 -0
- package/bundle/_virtual/_commonjs-dynamic-modules.js +5 -0
- package/bundle/_virtual/_commonjsHelpers.js +32 -0
- package/bundle/_virtual/_node-resolve_empty.js +3 -0
- package/bundle/_virtual/_sha2.js +3 -0
- package/bundle/_virtual/_u64.js +3 -0
- package/bundle/_virtual/aes.js +3 -0
- package/bundle/_virtual/bn.js +3 -0
- package/bundle/_virtual/browser.js +3 -0
- package/bundle/_virtual/checksum.js +3 -0
- package/bundle/_virtual/cipher.js +3 -0
- package/bundle/_virtual/class.js +3 -0
- package/bundle/_virtual/common.js +3 -0
- package/bundle/_virtual/common2.js +3 -0
- package/bundle/_virtual/cryptoBrowser.js +3 -0
- package/bundle/_virtual/functional.js +3 -0
- package/bundle/_virtual/hash.js +3 -0
- package/bundle/_virtual/hmac.js +3 -0
- package/bundle/_virtual/index.js +3 -0
- package/bundle/_virtual/index2.js +6 -0
- package/bundle/_virtual/inherits_browser.js +3 -0
- package/bundle/_virtual/kdf.js +3 -0
- package/bundle/_virtual/lodash.js +3 -0
- package/bundle/_virtual/password.js +3 -0
- package/bundle/_virtual/pbkdf2.js +3 -0
- package/bundle/_virtual/pbkdf22.js +3 -0
- package/bundle/_virtual/random.js +3 -0
- package/bundle/_virtual/ripemd.js +3 -0
- package/bundle/_virtual/schema-validation-generated.js +3 -0
- package/bundle/_virtual/schema-validation.js +3 -0
- package/bundle/_virtual/scrypt.js +3 -0
- package/bundle/_virtual/scrypt2.js +3 -0
- package/bundle/_virtual/sha.js +3 -0
- package/bundle/_virtual/sha256.js +3 -0
- package/bundle/_virtual/sha2562.js +3 -0
- package/bundle/_virtual/sha3.js +3 -0
- package/bundle/_virtual/sha512.js +3 -0
- package/bundle/_virtual/types.js +3 -0
- package/bundle/_virtual/utils.js +3 -0
- package/bundle/_virtual/utils2.js +3 -0
- package/bundle/_virtual/utils3.js +3 -0
- package/bundle/index.js +12 -74804
- package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +96 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +148 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +20 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +210 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +18 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +30 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +22 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +43 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +19 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +58 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +854 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +609 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +66 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +302 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +110 -0
- package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +20 -0
- package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +287 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +402 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +3 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +8 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +893 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +256 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +36 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +135 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +8 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +64 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +443 -0
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +8 -0
- package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +660 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +352 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +248 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +127 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +2007 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +422 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +674 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +132 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +8 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +2430 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +76 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +219 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +279 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +69 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +404 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +15 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +20 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +92 -0
- package/bundle/node_modules/@noble/hashes/esm/_assert.js +37 -0
- package/bundle/node_modules/@noble/hashes/esm/_md.js +132 -0
- package/bundle/node_modules/@noble/hashes/esm/_u64.js +29 -0
- package/bundle/node_modules/@noble/hashes/esm/sha256.js +113 -0
- package/bundle/node_modules/@noble/hashes/esm/sha3.js +210 -0
- package/bundle/node_modules/@noble/hashes/esm/utils.js +144 -0
- package/bundle/node_modules/@waku/zerokit-rln-wasm/rln_wasm.js +756 -0
- package/bundle/node_modules/bech32/index.js +187 -0
- package/bundle/node_modules/bn.js/lib/bn.js +3361 -0
- package/bundle/node_modules/debug/src/browser.js +283 -0
- package/bundle/node_modules/debug/src/common.js +295 -0
- package/bundle/node_modules/ethereum-cryptography/esm/keccak.js +10 -0
- package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +6 -0
- package/bundle/node_modules/ethereum-cryptography/esm/utils.js +24 -0
- package/bundle/node_modules/hash.js/lib/hash/common.js +97 -0
- package/bundle/node_modules/hash.js/lib/hash/hmac.js +51 -0
- package/bundle/node_modules/hash.js/lib/hash/ripemd.js +152 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/1.js +81 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/224.js +33 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/256.js +113 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/384.js +39 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/512.js +336 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/common.js +53 -0
- package/bundle/node_modules/hash.js/lib/hash/sha.js +14 -0
- package/bundle/node_modules/hash.js/lib/hash/utils.js +282 -0
- package/bundle/node_modules/hash.js/lib/hash.js +33 -0
- package/bundle/node_modules/inherits/inherits_browser.js +33 -0
- package/bundle/node_modules/it-length-prefixed/dist/src/decode.js +6 -0
- package/bundle/node_modules/lodash/lodash.js +17207 -0
- package/bundle/node_modules/minimalistic-assert/index.js +13 -0
- package/bundle/node_modules/ms/index.js +172 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base.js +205 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base10.js +9 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base16.js +16 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base2.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base256emoji.js +41 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base32.js +58 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base36.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base58.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base64.js +28 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base8.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/identity.js +11 -0
- package/bundle/node_modules/multiformats/dist/src/basics.js +15 -0
- package/bundle/node_modules/multiformats/dist/src/bytes.js +18 -0
- package/bundle/node_modules/multiformats/dist/src/codecs/json.js +2 -0
- package/bundle/node_modules/multiformats/dist/src/vendor/base-x.js +170 -0
- package/bundle/node_modules/protons-runtime/dist/src/codec.js +20 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/enum.js +24 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/message.js +7 -0
- package/bundle/node_modules/protons-runtime/dist/src/decode.js +8 -0
- package/bundle/node_modules/protons-runtime/dist/src/encode.js +11 -0
- package/bundle/node_modules/protons-runtime/dist/src/index.js +30 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/float.js +54 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/longbits.js +175 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/pool.js +28 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/reader.js +367 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/utf8.js +99 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/writer.js +438 -0
- package/bundle/node_modules/uint8-varint/dist/src/index.js +124 -0
- package/bundle/node_modules/uint8arrays/dist/src/alloc.js +17 -0
- package/bundle/node_modules/uint8arrays/dist/src/from-string.js +19 -0
- package/bundle/node_modules/uint8arrays/dist/src/util/bases.js +49 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +21 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +18 -0
- package/bundle/packages/core/dist/lib/filter/filter.js +27 -0
- package/bundle/packages/core/dist/lib/light_push/light_push.js +27 -0
- package/bundle/packages/core/dist/lib/message/version_0.js +154 -0
- package/bundle/packages/core/dist/lib/metadata/metadata.js +27 -0
- package/bundle/packages/core/dist/lib/store/store.js +27 -0
- package/bundle/packages/interfaces/dist/connection_manager.js +19 -0
- package/bundle/packages/interfaces/dist/constants.js +6 -0
- package/bundle/packages/interfaces/dist/health_indicator.js +12 -0
- package/bundle/packages/interfaces/dist/protocols.js +92 -0
- package/bundle/packages/proto/dist/generated/filter.js +445 -0
- package/bundle/packages/proto/dist/generated/filter_v2.js +424 -0
- package/bundle/packages/proto/dist/generated/light_push.js +389 -0
- package/bundle/packages/proto/dist/generated/message.js +213 -0
- package/bundle/packages/proto/dist/generated/metadata.js +130 -0
- package/bundle/packages/proto/dist/generated/peer_exchange.js +209 -0
- package/bundle/packages/proto/dist/generated/sds_message.js +105 -0
- package/bundle/packages/proto/dist/generated/store_v3.js +490 -0
- package/bundle/packages/proto/dist/generated/topic_only_message.js +61 -0
- package/bundle/packages/rln/dist/codec.js +93 -0
- package/bundle/packages/rln/dist/contract/abi.js +394 -0
- package/bundle/packages/rln/dist/contract/constants.js +27 -0
- package/bundle/packages/rln/dist/contract/rln_contract.js +438 -0
- package/bundle/packages/rln/dist/create.js +9 -0
- package/bundle/packages/rln/dist/identity.js +30 -0
- package/bundle/packages/rln/dist/keystore/cipher.js +31 -0
- package/bundle/packages/rln/dist/keystore/credential_validation_generated.js +119 -0
- package/bundle/packages/rln/dist/keystore/keystore.js +223 -0
- package/bundle/packages/rln/dist/keystore/keystore_validation_generated.js +74 -0
- package/bundle/packages/rln/dist/keystore/schema_validator.js +20 -0
- package/bundle/packages/rln/dist/message.js +51 -0
- package/bundle/packages/rln/dist/proof.js +54 -0
- package/bundle/packages/rln/dist/resources/verification_key.js +112 -0
- package/bundle/packages/rln/dist/resources/witness_calculator.js +330 -0
- package/bundle/packages/rln/dist/rln.js +220 -0
- package/bundle/packages/rln/dist/root_tracker.js +76 -0
- package/bundle/packages/rln/dist/utils/bytes.js +65 -0
- package/bundle/packages/rln/dist/utils/epoch.js +39 -0
- package/bundle/packages/rln/dist/utils/hash.js +10 -0
- package/bundle/packages/rln/dist/utils/metamask.js +14 -0
- package/bundle/packages/rln/dist/zerokit.js +128 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +52 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +65 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +99 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/index.js +28 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +78 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1253 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +40 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/types.js +5 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +41 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +23 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +12 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +77 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +9 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +215 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +35 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +21 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +66 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +24 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +7 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +11 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +52 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +124 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +71 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +10 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +88 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +99 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +233 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +133 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +243 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +167 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/native.js +4 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/rng.js +13 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/stringify.js +28 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/v4.js +19 -0
- package/bundle/packages/utils/dist/bytes/index.js +44 -0
- package/bundle/packages/utils/dist/common/sharding/index.js +91 -0
- package/bundle/packages/utils/dist/logger/index.js +31 -0
- package/bundle/resources/verification_key.d.ts +13 -0
- package/bundle/resources/verification_key.js +112 -0
- package/bundle/resources/witness_calculator.d.ts +11 -0
- package/bundle/resources/witness_calculator.js +328 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/codec.d.ts +5 -5
- package/dist/codec.js +6 -6
- package/dist/codec.js.map +1 -1
- package/dist/contract/abi.d.ts +42 -0
- package/dist/contract/abi.js +393 -0
- package/dist/contract/abi.js.map +1 -0
- package/dist/contract/constants.d.ts +59 -3
- package/dist/contract/constants.js +21 -63
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_contract.d.ts +98 -17
- package/dist/contract/rln_contract.js +292 -71
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/identity.js +5 -2
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/keystore/cipher.js +3 -3
- package/dist/keystore/cipher.js.map +1 -1
- package/dist/keystore/credential_validation_generated.js.map +1 -1
- package/dist/keystore/keystore.js +4 -4
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/keystore_validation_generated.js.map +1 -1
- package/dist/message.js +3 -3
- package/dist/message.js.map +1 -1
- package/dist/proof.js +3 -2
- package/dist/proof.js.map +1 -1
- package/dist/resources/verification_key.d.ts +12 -11
- package/dist/resources/verification_key.js +103 -103
- package/dist/resources/witness_calculator.d.ts +10 -15
- package/dist/resources/witness_calculator.js +302 -265
- package/dist/rln.d.ts +5 -1
- package/dist/rln.js +56 -28
- package/dist/rln.js.map +1 -1
- package/dist/root_tracker.js.map +1 -1
- package/dist/utils/epoch.js +5 -5
- package/dist/utils/epoch.js.map +1 -1
- package/dist/zerokit.d.ts +13 -9
- package/dist/zerokit.js +40 -20
- package/dist/zerokit.js.map +1 -1
- package/package.json +1 -146
- package/src/codec.ts +26 -22
- package/src/contract/abi.ts +392 -0
- package/src/contract/constants.ts +28 -0
- package/src/contract/index.ts +2 -0
- package/src/contract/rln_contract.ts +686 -0
- package/src/identity.ts +8 -4
- package/src/index.ts +4 -9
- package/src/keystore/cipher.ts +54 -0
- package/src/keystore/credential_validation_generated.ts +7 -0
- package/src/keystore/index.ts +5 -0
- package/src/keystore/keystore.ts +330 -0
- package/src/keystore/keystore_validation_generated.ts +7 -0
- package/src/keystore/schema_validator.ts +34 -0
- package/src/keystore/types.ts +36 -0
- package/src/message.ts +10 -10
- package/src/proof.ts +13 -11
- package/src/resources/verification_key.d.ts +13 -0
- package/src/resources/witness_calculator.d.ts +11 -0
- package/src/rln.ts +76 -31
- package/src/root_tracker.ts +7 -6
- package/src/utils/bytes.ts +84 -0
- package/src/utils/epoch.ts +30 -0
- package/src/utils/hash.ts +15 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/metamask.ts +17 -0
- package/src/zerokit.ts +95 -33
- package/bundle/assets/rln_wasm_bg-a503e304.wasm +0 -0
- package/dist/resources/verification_key.js.map +0 -1
- package/dist/resources/witness_calculator.js.map +0 -1
- /package/bundle/{assets/rln-6ded2896.wasm → resources/rln.wasm} +0 -0
- /package/bundle/{assets/rln_final-8b299152.zkey → resources/rln_final.zkey} +0 -0
@@ -0,0 +1,132 @@
|
|
1
|
+
import { aexists, aoutput } from './_assert.js';
|
2
|
+
import { Hash, createView, toBytes } from './utils.js';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Internal Merkle-Damgard hash utils.
|
6
|
+
* @module
|
7
|
+
*/
|
8
|
+
/** Polyfill for Safari 14. https://caniuse.com/mdn-javascript_builtins_dataview_setbiguint64 */
|
9
|
+
function setBigUint64(view, byteOffset, value, isLE) {
|
10
|
+
if (typeof view.setBigUint64 === 'function')
|
11
|
+
return view.setBigUint64(byteOffset, value, isLE);
|
12
|
+
const _32n = BigInt(32);
|
13
|
+
const _u32_max = BigInt(0xffffffff);
|
14
|
+
const wh = Number((value >> _32n) & _u32_max);
|
15
|
+
const wl = Number(value & _u32_max);
|
16
|
+
const h = isLE ? 4 : 0;
|
17
|
+
const l = isLE ? 0 : 4;
|
18
|
+
view.setUint32(byteOffset + h, wh, isLE);
|
19
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
20
|
+
}
|
21
|
+
/** Choice: a ? b : c */
|
22
|
+
function Chi(a, b, c) {
|
23
|
+
return (a & b) ^ (~a & c);
|
24
|
+
}
|
25
|
+
/** Majority function, true if any two inputs is true. */
|
26
|
+
function Maj(a, b, c) {
|
27
|
+
return (a & b) ^ (a & c) ^ (b & c);
|
28
|
+
}
|
29
|
+
/**
|
30
|
+
* Merkle-Damgard hash construction base class.
|
31
|
+
* Could be used to create MD5, RIPEMD, SHA1, SHA2.
|
32
|
+
*/
|
33
|
+
class HashMD extends Hash {
|
34
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
35
|
+
super();
|
36
|
+
this.blockLen = blockLen;
|
37
|
+
this.outputLen = outputLen;
|
38
|
+
this.padOffset = padOffset;
|
39
|
+
this.isLE = isLE;
|
40
|
+
this.finished = false;
|
41
|
+
this.length = 0;
|
42
|
+
this.pos = 0;
|
43
|
+
this.destroyed = false;
|
44
|
+
this.buffer = new Uint8Array(blockLen);
|
45
|
+
this.view = createView(this.buffer);
|
46
|
+
}
|
47
|
+
update(data) {
|
48
|
+
aexists(this);
|
49
|
+
const { view, buffer, blockLen } = this;
|
50
|
+
data = toBytes(data);
|
51
|
+
const len = data.length;
|
52
|
+
for (let pos = 0; pos < len;) {
|
53
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
54
|
+
// Fast path: we have at least one block in input, cast it to view and process
|
55
|
+
if (take === blockLen) {
|
56
|
+
const dataView = createView(data);
|
57
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
58
|
+
this.process(dataView, pos);
|
59
|
+
continue;
|
60
|
+
}
|
61
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
62
|
+
this.pos += take;
|
63
|
+
pos += take;
|
64
|
+
if (this.pos === blockLen) {
|
65
|
+
this.process(view, 0);
|
66
|
+
this.pos = 0;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
this.length += data.length;
|
70
|
+
this.roundClean();
|
71
|
+
return this;
|
72
|
+
}
|
73
|
+
digestInto(out) {
|
74
|
+
aexists(this);
|
75
|
+
aoutput(out, this);
|
76
|
+
this.finished = true;
|
77
|
+
// Padding
|
78
|
+
// We can avoid allocation of buffer for padding completely if it
|
79
|
+
// was previously not allocated here. But it won't change performance.
|
80
|
+
const { buffer, view, blockLen, isLE } = this;
|
81
|
+
let { pos } = this;
|
82
|
+
// append the bit '1' to the message
|
83
|
+
buffer[pos++] = 0b10000000;
|
84
|
+
this.buffer.subarray(pos).fill(0);
|
85
|
+
// we have less than padOffset left in buffer, so we cannot put length in
|
86
|
+
// current block, need process it and pad again
|
87
|
+
if (this.padOffset > blockLen - pos) {
|
88
|
+
this.process(view, 0);
|
89
|
+
pos = 0;
|
90
|
+
}
|
91
|
+
// Pad until full block byte with zeros
|
92
|
+
for (let i = pos; i < blockLen; i++)
|
93
|
+
buffer[i] = 0;
|
94
|
+
// Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
|
95
|
+
// You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
|
96
|
+
// So we just write lowest 64 bits of that value.
|
97
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
98
|
+
this.process(view, 0);
|
99
|
+
const oview = createView(out);
|
100
|
+
const len = this.outputLen;
|
101
|
+
// NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
|
102
|
+
if (len % 4)
|
103
|
+
throw new Error('_sha2: outputLen should be aligned to 32bit');
|
104
|
+
const outLen = len / 4;
|
105
|
+
const state = this.get();
|
106
|
+
if (outLen > state.length)
|
107
|
+
throw new Error('_sha2: outputLen bigger than state');
|
108
|
+
for (let i = 0; i < outLen; i++)
|
109
|
+
oview.setUint32(4 * i, state[i], isLE);
|
110
|
+
}
|
111
|
+
digest() {
|
112
|
+
const { buffer, outputLen } = this;
|
113
|
+
this.digestInto(buffer);
|
114
|
+
const res = buffer.slice(0, outputLen);
|
115
|
+
this.destroy();
|
116
|
+
return res;
|
117
|
+
}
|
118
|
+
_cloneInto(to) {
|
119
|
+
to || (to = new this.constructor());
|
120
|
+
to.set(...this.get());
|
121
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
122
|
+
to.length = length;
|
123
|
+
to.pos = pos;
|
124
|
+
to.finished = finished;
|
125
|
+
to.destroyed = destroyed;
|
126
|
+
if (length % blockLen)
|
127
|
+
to.buffer.set(buffer);
|
128
|
+
return to;
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
export { Chi, HashMD, Maj, setBigUint64 };
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/**
|
2
|
+
* Internal helpers for u64. BigUint64Array is too slow as per 2025, so we implement it using Uint32Array.
|
3
|
+
* @todo re-check https://issues.chromium.org/issues/42212588
|
4
|
+
* @module
|
5
|
+
*/
|
6
|
+
const U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
7
|
+
const _32n = /* @__PURE__ */ BigInt(32);
|
8
|
+
function fromBig(n, le = false) {
|
9
|
+
if (le)
|
10
|
+
return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
|
11
|
+
return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
12
|
+
}
|
13
|
+
function split(lst, le = false) {
|
14
|
+
let Ah = new Uint32Array(lst.length);
|
15
|
+
let Al = new Uint32Array(lst.length);
|
16
|
+
for (let i = 0; i < lst.length; i++) {
|
17
|
+
const { h, l } = fromBig(lst[i], le);
|
18
|
+
[Ah[i], Al[i]] = [h, l];
|
19
|
+
}
|
20
|
+
return [Ah, Al];
|
21
|
+
}
|
22
|
+
// Left rotate for Shift in [1, 32)
|
23
|
+
const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));
|
24
|
+
const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));
|
25
|
+
// Left rotate for Shift in (32, 64), NOTE: 32 is special case.
|
26
|
+
const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
|
27
|
+
const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
|
28
|
+
|
29
|
+
export { fromBig, rotlBH, rotlBL, rotlSH, rotlSL, split };
|
@@ -0,0 +1,113 @@
|
|
1
|
+
import { HashMD, Chi, Maj } from './_md.js';
|
2
|
+
import { wrapConstructor, rotr } from './utils.js';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* SHA2-256 a.k.a. sha256. In JS, it is the fastest hash, even faster than Blake3.
|
6
|
+
*
|
7
|
+
* To break sha256 using birthday attack, attackers need to try 2^128 hashes.
|
8
|
+
* BTC network is doing 2^70 hashes/sec (2^95 hashes/year) as per 2025.
|
9
|
+
*
|
10
|
+
* Check out [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf).
|
11
|
+
* @module
|
12
|
+
*/
|
13
|
+
/** Round constants: first 32 bits of fractional parts of the cube roots of the first 64 primes 2..311). */
|
14
|
+
// prettier-ignore
|
15
|
+
const SHA256_K = /* @__PURE__ */ new Uint32Array([
|
16
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
17
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
18
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
19
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
20
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
21
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
22
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
23
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
24
|
+
]);
|
25
|
+
/** Initial state: first 32 bits of fractional parts of the square roots of the first 8 primes 2..19. */
|
26
|
+
// prettier-ignore
|
27
|
+
const SHA256_IV = /* @__PURE__ */ new Uint32Array([
|
28
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
29
|
+
]);
|
30
|
+
/**
|
31
|
+
* Temporary buffer, not used to store anything between runs.
|
32
|
+
* Named this way because it matches specification.
|
33
|
+
*/
|
34
|
+
const SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
35
|
+
class SHA256 extends HashMD {
|
36
|
+
constructor() {
|
37
|
+
super(64, 32, 8, false);
|
38
|
+
// We cannot use array here since array allows indexing by variable
|
39
|
+
// which means optimizer/compiler cannot use registers.
|
40
|
+
this.A = SHA256_IV[0] | 0;
|
41
|
+
this.B = SHA256_IV[1] | 0;
|
42
|
+
this.C = SHA256_IV[2] | 0;
|
43
|
+
this.D = SHA256_IV[3] | 0;
|
44
|
+
this.E = SHA256_IV[4] | 0;
|
45
|
+
this.F = SHA256_IV[5] | 0;
|
46
|
+
this.G = SHA256_IV[6] | 0;
|
47
|
+
this.H = SHA256_IV[7] | 0;
|
48
|
+
}
|
49
|
+
get() {
|
50
|
+
const { A, B, C, D, E, F, G, H } = this;
|
51
|
+
return [A, B, C, D, E, F, G, H];
|
52
|
+
}
|
53
|
+
// prettier-ignore
|
54
|
+
set(A, B, C, D, E, F, G, H) {
|
55
|
+
this.A = A | 0;
|
56
|
+
this.B = B | 0;
|
57
|
+
this.C = C | 0;
|
58
|
+
this.D = D | 0;
|
59
|
+
this.E = E | 0;
|
60
|
+
this.F = F | 0;
|
61
|
+
this.G = G | 0;
|
62
|
+
this.H = H | 0;
|
63
|
+
}
|
64
|
+
process(view, offset) {
|
65
|
+
// Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
|
66
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
67
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
68
|
+
for (let i = 16; i < 64; i++) {
|
69
|
+
const W15 = SHA256_W[i - 15];
|
70
|
+
const W2 = SHA256_W[i - 2];
|
71
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ (W15 >>> 3);
|
72
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ (W2 >>> 10);
|
73
|
+
SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
|
74
|
+
}
|
75
|
+
// Compression function main loop, 64 rounds
|
76
|
+
let { A, B, C, D, E, F, G, H } = this;
|
77
|
+
for (let i = 0; i < 64; i++) {
|
78
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
79
|
+
const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
|
80
|
+
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
81
|
+
const T2 = (sigma0 + Maj(A, B, C)) | 0;
|
82
|
+
H = G;
|
83
|
+
G = F;
|
84
|
+
F = E;
|
85
|
+
E = (D + T1) | 0;
|
86
|
+
D = C;
|
87
|
+
C = B;
|
88
|
+
B = A;
|
89
|
+
A = (T1 + T2) | 0;
|
90
|
+
}
|
91
|
+
// Add the compressed chunk to the current hash value
|
92
|
+
A = (A + this.A) | 0;
|
93
|
+
B = (B + this.B) | 0;
|
94
|
+
C = (C + this.C) | 0;
|
95
|
+
D = (D + this.D) | 0;
|
96
|
+
E = (E + this.E) | 0;
|
97
|
+
F = (F + this.F) | 0;
|
98
|
+
G = (G + this.G) | 0;
|
99
|
+
H = (H + this.H) | 0;
|
100
|
+
this.set(A, B, C, D, E, F, G, H);
|
101
|
+
}
|
102
|
+
roundClean() {
|
103
|
+
SHA256_W.fill(0);
|
104
|
+
}
|
105
|
+
destroy() {
|
106
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
107
|
+
this.buffer.fill(0);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
/** SHA2-256 hash function */
|
111
|
+
const sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
|
112
|
+
|
113
|
+
export { SHA256, sha256 };
|
@@ -0,0 +1,210 @@
|
|
1
|
+
import { anumber, aexists, abytes, aoutput } from './_assert.js';
|
2
|
+
import { split, rotlBH, rotlSH, rotlBL, rotlSL } from './_u64.js';
|
3
|
+
import { wrapConstructor, Hash, u32, isLE, byteSwap32, toBytes } from './utils.js';
|
4
|
+
|
5
|
+
/**
|
6
|
+
* SHA3 (keccak) hash function, based on a new "Sponge function" design.
|
7
|
+
* Different from older hashes, the internal state is bigger than output size.
|
8
|
+
*
|
9
|
+
* Check out [FIPS-202](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf),
|
10
|
+
* [Website](https://keccak.team/keccak.html),
|
11
|
+
* [the differences between SHA-3 and Keccak](https://crypto.stackexchange.com/questions/15727/what-are-the-key-differences-between-the-draft-sha-3-standard-and-the-keccak-sub).
|
12
|
+
*
|
13
|
+
* Check out `sha3-addons` module for cSHAKE, k12, and others.
|
14
|
+
* @module
|
15
|
+
*/
|
16
|
+
// Various per round constants calculations
|
17
|
+
const SHA3_PI = [];
|
18
|
+
const SHA3_ROTL = [];
|
19
|
+
const _SHA3_IOTA = [];
|
20
|
+
const _0n = /* @__PURE__ */ BigInt(0);
|
21
|
+
const _1n = /* @__PURE__ */ BigInt(1);
|
22
|
+
const _2n = /* @__PURE__ */ BigInt(2);
|
23
|
+
const _7n = /* @__PURE__ */ BigInt(7);
|
24
|
+
const _256n = /* @__PURE__ */ BigInt(256);
|
25
|
+
const _0x71n = /* @__PURE__ */ BigInt(0x71);
|
26
|
+
for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
|
27
|
+
// Pi
|
28
|
+
[x, y] = [y, (2 * x + 3 * y) % 5];
|
29
|
+
SHA3_PI.push(2 * (5 * y + x));
|
30
|
+
// Rotational
|
31
|
+
SHA3_ROTL.push((((round + 1) * (round + 2)) / 2) % 64);
|
32
|
+
// Iota
|
33
|
+
let t = _0n;
|
34
|
+
for (let j = 0; j < 7; j++) {
|
35
|
+
R = ((R << _1n) ^ ((R >> _7n) * _0x71n)) % _256n;
|
36
|
+
if (R & _2n)
|
37
|
+
t ^= _1n << ((_1n << /* @__PURE__ */ BigInt(j)) - _1n);
|
38
|
+
}
|
39
|
+
_SHA3_IOTA.push(t);
|
40
|
+
}
|
41
|
+
const [SHA3_IOTA_H, SHA3_IOTA_L] = /* @__PURE__ */ split(_SHA3_IOTA, true);
|
42
|
+
// Left rotation (without 0, 32, 64)
|
43
|
+
const rotlH = (h, l, s) => (s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s));
|
44
|
+
const rotlL = (h, l, s) => (s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s));
|
45
|
+
/** `keccakf1600` internal function, additionally allows to adjust round count. */
|
46
|
+
function keccakP(s, rounds = 24) {
|
47
|
+
const B = new Uint32Array(5 * 2);
|
48
|
+
// NOTE: all indices are x2 since we store state as u32 instead of u64 (bigints to slow in js)
|
49
|
+
for (let round = 24 - rounds; round < 24; round++) {
|
50
|
+
// Theta θ
|
51
|
+
for (let x = 0; x < 10; x++)
|
52
|
+
B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
|
53
|
+
for (let x = 0; x < 10; x += 2) {
|
54
|
+
const idx1 = (x + 8) % 10;
|
55
|
+
const idx0 = (x + 2) % 10;
|
56
|
+
const B0 = B[idx0];
|
57
|
+
const B1 = B[idx0 + 1];
|
58
|
+
const Th = rotlH(B0, B1, 1) ^ B[idx1];
|
59
|
+
const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
|
60
|
+
for (let y = 0; y < 50; y += 10) {
|
61
|
+
s[x + y] ^= Th;
|
62
|
+
s[x + y + 1] ^= Tl;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
// Rho (ρ) and Pi (π)
|
66
|
+
let curH = s[2];
|
67
|
+
let curL = s[3];
|
68
|
+
for (let t = 0; t < 24; t++) {
|
69
|
+
const shift = SHA3_ROTL[t];
|
70
|
+
const Th = rotlH(curH, curL, shift);
|
71
|
+
const Tl = rotlL(curH, curL, shift);
|
72
|
+
const PI = SHA3_PI[t];
|
73
|
+
curH = s[PI];
|
74
|
+
curL = s[PI + 1];
|
75
|
+
s[PI] = Th;
|
76
|
+
s[PI + 1] = Tl;
|
77
|
+
}
|
78
|
+
// Chi (χ)
|
79
|
+
for (let y = 0; y < 50; y += 10) {
|
80
|
+
for (let x = 0; x < 10; x++)
|
81
|
+
B[x] = s[y + x];
|
82
|
+
for (let x = 0; x < 10; x++)
|
83
|
+
s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
|
84
|
+
}
|
85
|
+
// Iota (ι)
|
86
|
+
s[0] ^= SHA3_IOTA_H[round];
|
87
|
+
s[1] ^= SHA3_IOTA_L[round];
|
88
|
+
}
|
89
|
+
B.fill(0);
|
90
|
+
}
|
91
|
+
/** Keccak sponge function. */
|
92
|
+
class Keccak extends Hash {
|
93
|
+
// NOTE: we accept arguments in bytes instead of bits here.
|
94
|
+
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
95
|
+
super();
|
96
|
+
this.blockLen = blockLen;
|
97
|
+
this.suffix = suffix;
|
98
|
+
this.outputLen = outputLen;
|
99
|
+
this.enableXOF = enableXOF;
|
100
|
+
this.rounds = rounds;
|
101
|
+
this.pos = 0;
|
102
|
+
this.posOut = 0;
|
103
|
+
this.finished = false;
|
104
|
+
this.destroyed = false;
|
105
|
+
// Can be passed from user as dkLen
|
106
|
+
anumber(outputLen);
|
107
|
+
// 1600 = 5x5 matrix of 64bit. 1600 bits === 200 bytes
|
108
|
+
// 0 < blockLen < 200
|
109
|
+
if (0 >= this.blockLen || this.blockLen >= 200)
|
110
|
+
throw new Error('Sha3 supports only keccak-f1600 function');
|
111
|
+
this.state = new Uint8Array(200);
|
112
|
+
this.state32 = u32(this.state);
|
113
|
+
}
|
114
|
+
keccak() {
|
115
|
+
if (!isLE)
|
116
|
+
byteSwap32(this.state32);
|
117
|
+
keccakP(this.state32, this.rounds);
|
118
|
+
if (!isLE)
|
119
|
+
byteSwap32(this.state32);
|
120
|
+
this.posOut = 0;
|
121
|
+
this.pos = 0;
|
122
|
+
}
|
123
|
+
update(data) {
|
124
|
+
aexists(this);
|
125
|
+
const { blockLen, state } = this;
|
126
|
+
data = toBytes(data);
|
127
|
+
const len = data.length;
|
128
|
+
for (let pos = 0; pos < len;) {
|
129
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
130
|
+
for (let i = 0; i < take; i++)
|
131
|
+
state[this.pos++] ^= data[pos++];
|
132
|
+
if (this.pos === blockLen)
|
133
|
+
this.keccak();
|
134
|
+
}
|
135
|
+
return this;
|
136
|
+
}
|
137
|
+
finish() {
|
138
|
+
if (this.finished)
|
139
|
+
return;
|
140
|
+
this.finished = true;
|
141
|
+
const { state, suffix, pos, blockLen } = this;
|
142
|
+
// Do the padding
|
143
|
+
state[pos] ^= suffix;
|
144
|
+
if ((suffix & 0x80) !== 0 && pos === blockLen - 1)
|
145
|
+
this.keccak();
|
146
|
+
state[blockLen - 1] ^= 0x80;
|
147
|
+
this.keccak();
|
148
|
+
}
|
149
|
+
writeInto(out) {
|
150
|
+
aexists(this, false);
|
151
|
+
abytes(out);
|
152
|
+
this.finish();
|
153
|
+
const bufferOut = this.state;
|
154
|
+
const { blockLen } = this;
|
155
|
+
for (let pos = 0, len = out.length; pos < len;) {
|
156
|
+
if (this.posOut >= blockLen)
|
157
|
+
this.keccak();
|
158
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
159
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
160
|
+
this.posOut += take;
|
161
|
+
pos += take;
|
162
|
+
}
|
163
|
+
return out;
|
164
|
+
}
|
165
|
+
xofInto(out) {
|
166
|
+
// Sha3/Keccak usage with XOF is probably mistake, only SHAKE instances can do XOF
|
167
|
+
if (!this.enableXOF)
|
168
|
+
throw new Error('XOF is not possible for this instance');
|
169
|
+
return this.writeInto(out);
|
170
|
+
}
|
171
|
+
xof(bytes) {
|
172
|
+
anumber(bytes);
|
173
|
+
return this.xofInto(new Uint8Array(bytes));
|
174
|
+
}
|
175
|
+
digestInto(out) {
|
176
|
+
aoutput(out, this);
|
177
|
+
if (this.finished)
|
178
|
+
throw new Error('digest() was already called');
|
179
|
+
this.writeInto(out);
|
180
|
+
this.destroy();
|
181
|
+
return out;
|
182
|
+
}
|
183
|
+
digest() {
|
184
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
185
|
+
}
|
186
|
+
destroy() {
|
187
|
+
this.destroyed = true;
|
188
|
+
this.state.fill(0);
|
189
|
+
}
|
190
|
+
_cloneInto(to) {
|
191
|
+
const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
|
192
|
+
to || (to = new Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
|
193
|
+
to.state32.set(this.state32);
|
194
|
+
to.pos = this.pos;
|
195
|
+
to.posOut = this.posOut;
|
196
|
+
to.finished = this.finished;
|
197
|
+
to.rounds = rounds;
|
198
|
+
// Suffix can change in cSHAKE
|
199
|
+
to.suffix = suffix;
|
200
|
+
to.outputLen = outputLen;
|
201
|
+
to.enableXOF = enableXOF;
|
202
|
+
to.destroyed = this.destroyed;
|
203
|
+
return to;
|
204
|
+
}
|
205
|
+
}
|
206
|
+
const gen = (suffix, blockLen, outputLen) => wrapConstructor(() => new Keccak(blockLen, suffix, outputLen));
|
207
|
+
/** keccak-256 hash function. Different from SHA3-256. */
|
208
|
+
const keccak_256 = /* @__PURE__ */ gen(0x01, 136, 256 / 8);
|
209
|
+
|
210
|
+
export { Keccak, keccakP, keccak_256 };
|
@@ -0,0 +1,144 @@
|
|
1
|
+
import { abytes } from './_assert.js';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Utilities for hex, bytes, CSPRNG.
|
5
|
+
* @module
|
6
|
+
*/
|
7
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
8
|
+
// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
|
9
|
+
// node.js versions earlier than v19 don't declare it in global scope.
|
10
|
+
// For node.js, package.json#exports field mapping rewrites import
|
11
|
+
// from `crypto` to `cryptoNode`, which imports native module.
|
12
|
+
// Makes the utils un-importable in browsers without a bundler.
|
13
|
+
// Once node.js 18 is deprecated (2025-04-30), we can just drop the import.
|
14
|
+
function u32(arr) {
|
15
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
16
|
+
}
|
17
|
+
// Cast array to view
|
18
|
+
function createView(arr) {
|
19
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
20
|
+
}
|
21
|
+
/** The rotate right (circular right shift) operation for uint32 */
|
22
|
+
function rotr(word, shift) {
|
23
|
+
return (word << (32 - shift)) | (word >>> shift);
|
24
|
+
}
|
25
|
+
/** Is current platform little-endian? Most are. Big-Endian platform: IBM */
|
26
|
+
const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44)();
|
27
|
+
// The byte swap operation for uint32
|
28
|
+
function byteSwap(word) {
|
29
|
+
return (((word << 24) & 0xff000000) |
|
30
|
+
((word << 8) & 0xff0000) |
|
31
|
+
((word >>> 8) & 0xff00) |
|
32
|
+
((word >>> 24) & 0xff));
|
33
|
+
}
|
34
|
+
/** In place byte swap for Uint32Array */
|
35
|
+
function byteSwap32(arr) {
|
36
|
+
for (let i = 0; i < arr.length; i++) {
|
37
|
+
arr[i] = byteSwap(arr[i]);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
// Array where index 0xf0 (240) is mapped to string 'f0'
|
41
|
+
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0'));
|
42
|
+
/**
|
43
|
+
* Convert byte array to hex string.
|
44
|
+
* @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
|
45
|
+
*/
|
46
|
+
function bytesToHex(bytes) {
|
47
|
+
abytes(bytes);
|
48
|
+
// pre-caching improves the speed 6x
|
49
|
+
let hex = '';
|
50
|
+
for (let i = 0; i < bytes.length; i++) {
|
51
|
+
hex += hexes[bytes[i]];
|
52
|
+
}
|
53
|
+
return hex;
|
54
|
+
}
|
55
|
+
// We use optimized technique to convert hex string to byte array
|
56
|
+
const asciis = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
|
57
|
+
function asciiToBase16(ch) {
|
58
|
+
if (ch >= asciis._0 && ch <= asciis._9)
|
59
|
+
return ch - asciis._0; // '2' => 50-48
|
60
|
+
if (ch >= asciis.A && ch <= asciis.F)
|
61
|
+
return ch - (asciis.A - 10); // 'B' => 66-(65-10)
|
62
|
+
if (ch >= asciis.a && ch <= asciis.f)
|
63
|
+
return ch - (asciis.a - 10); // 'b' => 98-(97-10)
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
/**
|
67
|
+
* Convert hex string to byte array.
|
68
|
+
* @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
|
69
|
+
*/
|
70
|
+
function hexToBytes(hex) {
|
71
|
+
if (typeof hex !== 'string')
|
72
|
+
throw new Error('hex string expected, got ' + typeof hex);
|
73
|
+
const hl = hex.length;
|
74
|
+
const al = hl / 2;
|
75
|
+
if (hl % 2)
|
76
|
+
throw new Error('hex string expected, got unpadded hex of length ' + hl);
|
77
|
+
const array = new Uint8Array(al);
|
78
|
+
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
79
|
+
const n1 = asciiToBase16(hex.charCodeAt(hi));
|
80
|
+
const n2 = asciiToBase16(hex.charCodeAt(hi + 1));
|
81
|
+
if (n1 === undefined || n2 === undefined) {
|
82
|
+
const char = hex[hi] + hex[hi + 1];
|
83
|
+
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
84
|
+
}
|
85
|
+
array[ai] = n1 * 16 + n2; // multiply first octet, e.g. 'a3' => 10*16+3 => 160 + 3 => 163
|
86
|
+
}
|
87
|
+
return array;
|
88
|
+
}
|
89
|
+
/**
|
90
|
+
* Convert JS string to byte array.
|
91
|
+
* @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
|
92
|
+
*/
|
93
|
+
function utf8ToBytes(str) {
|
94
|
+
if (typeof str !== 'string')
|
95
|
+
throw new Error('utf8ToBytes expected string, got ' + typeof str);
|
96
|
+
return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
|
97
|
+
}
|
98
|
+
/**
|
99
|
+
* Normalizes (non-hex) string or Uint8Array to Uint8Array.
|
100
|
+
* Warning: when Uint8Array is passed, it would NOT get copied.
|
101
|
+
* Keep in mind for future mutable operations.
|
102
|
+
*/
|
103
|
+
function toBytes(data) {
|
104
|
+
if (typeof data === 'string')
|
105
|
+
data = utf8ToBytes(data);
|
106
|
+
abytes(data);
|
107
|
+
return data;
|
108
|
+
}
|
109
|
+
/**
|
110
|
+
* Copies several Uint8Arrays into one.
|
111
|
+
*/
|
112
|
+
function concatBytes(...arrays) {
|
113
|
+
let sum = 0;
|
114
|
+
for (let i = 0; i < arrays.length; i++) {
|
115
|
+
const a = arrays[i];
|
116
|
+
abytes(a);
|
117
|
+
sum += a.length;
|
118
|
+
}
|
119
|
+
const res = new Uint8Array(sum);
|
120
|
+
for (let i = 0, pad = 0; i < arrays.length; i++) {
|
121
|
+
const a = arrays[i];
|
122
|
+
res.set(a, pad);
|
123
|
+
pad += a.length;
|
124
|
+
}
|
125
|
+
return res;
|
126
|
+
}
|
127
|
+
/** For runtime check if class implements interface */
|
128
|
+
class Hash {
|
129
|
+
// Safe version that clones internal state
|
130
|
+
clone() {
|
131
|
+
return this._cloneInto();
|
132
|
+
}
|
133
|
+
}
|
134
|
+
/** Wraps hash function, creating an interface on top of it */
|
135
|
+
function wrapConstructor(hashCons) {
|
136
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
137
|
+
const tmp = hashCons();
|
138
|
+
hashC.outputLen = tmp.outputLen;
|
139
|
+
hashC.blockLen = tmp.blockLen;
|
140
|
+
hashC.create = () => hashCons();
|
141
|
+
return hashC;
|
142
|
+
}
|
143
|
+
|
144
|
+
export { Hash, byteSwap, byteSwap32, bytesToHex, concatBytes, createView, hexToBytes, isLE, rotr, toBytes, u32, utf8ToBytes, wrapConstructor };
|