@waku/rln 0.0.1 → 0.0.2-ce9a6ae.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -108
- package/bundle/_virtual/__node-resolve_empty.js +6 -0
- package/bundle/_virtual/_assert.js +3 -0
- package/bundle/_virtual/_commonjs-dynamic-modules.js +5 -0
- package/bundle/_virtual/_commonjsHelpers.js +32 -0
- package/bundle/_virtual/_node-resolve_empty.js +3 -0
- package/bundle/_virtual/_sha2.js +3 -0
- package/bundle/_virtual/_u64.js +3 -0
- package/bundle/_virtual/aes.js +3 -0
- package/bundle/_virtual/bn.js +3 -0
- package/bundle/_virtual/browser.js +3 -0
- package/bundle/_virtual/checksum.js +3 -0
- package/bundle/_virtual/cipher.js +3 -0
- package/bundle/_virtual/class.js +3 -0
- package/bundle/_virtual/common.js +3 -0
- package/bundle/_virtual/common2.js +3 -0
- package/bundle/_virtual/cryptoBrowser.js +3 -0
- package/bundle/_virtual/functional.js +3 -0
- package/bundle/_virtual/hash.js +3 -0
- package/bundle/_virtual/hmac.js +3 -0
- package/bundle/_virtual/index.js +3 -0
- package/bundle/_virtual/index2.js +6 -0
- package/bundle/_virtual/inherits_browser.js +3 -0
- package/bundle/_virtual/kdf.js +3 -0
- package/bundle/_virtual/lodash.js +3 -0
- package/bundle/_virtual/password.js +3 -0
- package/bundle/_virtual/pbkdf2.js +3 -0
- package/bundle/_virtual/pbkdf22.js +3 -0
- package/bundle/_virtual/random.js +3 -0
- package/bundle/_virtual/ripemd.js +3 -0
- package/bundle/_virtual/schema-validation-generated.js +3 -0
- package/bundle/_virtual/schema-validation.js +3 -0
- package/bundle/_virtual/scrypt.js +3 -0
- package/bundle/_virtual/scrypt2.js +3 -0
- package/bundle/_virtual/sha.js +3 -0
- package/bundle/_virtual/sha256.js +3 -0
- package/bundle/_virtual/sha2562.js +3 -0
- package/bundle/_virtual/sha3.js +3 -0
- package/bundle/_virtual/sha512.js +3 -0
- package/bundle/_virtual/types.js +3 -0
- package/bundle/_virtual/utils.js +3 -0
- package/bundle/_virtual/utils2.js +3 -0
- package/bundle/_virtual/utils3.js +3 -0
- package/bundle/index.js +12 -10
- package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +96 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +148 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +20 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +210 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +18 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +30 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +22 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +43 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +19 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +58 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +854 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +609 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +66 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +302 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +110 -0
- package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +20 -0
- package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +287 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +402 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +3 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +8 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +893 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +256 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +36 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +135 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +8 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +64 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +443 -0
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +8 -0
- package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +660 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +352 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +248 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +127 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +2007 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +422 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +674 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +132 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +8 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +2430 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +76 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +219 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +279 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +69 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +404 -0
- package/bundle/node_modules/@iden3/js-crypto/dist/browser/esm/index.js +7 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +15 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +20 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +92 -0
- package/bundle/node_modules/@noble/hashes/esm/_assert.js +37 -0
- package/bundle/node_modules/@noble/hashes/esm/_md.js +132 -0
- package/bundle/node_modules/@noble/hashes/esm/_u64.js +29 -0
- package/bundle/node_modules/@noble/hashes/esm/sha256.js +113 -0
- package/bundle/node_modules/@noble/hashes/esm/sha3.js +210 -0
- package/bundle/node_modules/@noble/hashes/esm/utils.js +144 -0
- package/bundle/node_modules/@stablelib/binary/lib/binary.js +22 -0
- package/bundle/node_modules/@stablelib/chacha/lib/chacha.js +245 -0
- package/bundle/node_modules/@stablelib/wipe/lib/wipe.js +26 -0
- package/bundle/node_modules/@waku/zerokit-rln-wasm/rln_wasm.js +756 -0
- package/bundle/node_modules/bech32/index.js +187 -0
- package/bundle/node_modules/bn.js/lib/bn.js +3361 -0
- package/bundle/node_modules/debug/src/browser.js +283 -0
- package/bundle/node_modules/debug/src/common.js +295 -0
- package/bundle/node_modules/ethereum-cryptography/esm/keccak.js +10 -0
- package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +6 -0
- package/bundle/node_modules/ethereum-cryptography/esm/utils.js +24 -0
- package/bundle/node_modules/hash.js/lib/hash/common.js +97 -0
- package/bundle/node_modules/hash.js/lib/hash/hmac.js +51 -0
- package/bundle/node_modules/hash.js/lib/hash/ripemd.js +152 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/1.js +81 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/224.js +33 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/256.js +113 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/384.js +39 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/512.js +336 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/common.js +53 -0
- package/bundle/node_modules/hash.js/lib/hash/sha.js +14 -0
- package/bundle/node_modules/hash.js/lib/hash/utils.js +282 -0
- package/bundle/node_modules/hash.js/lib/hash.js +33 -0
- package/bundle/node_modules/inherits/inherits_browser.js +33 -0
- package/bundle/node_modules/it-length-prefixed/dist/src/decode.js +6 -0
- package/bundle/node_modules/lodash/lodash.js +17207 -0
- package/bundle/node_modules/minimalistic-assert/index.js +13 -0
- package/bundle/node_modules/ms/index.js +172 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base.js +205 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base10.js +9 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base16.js +16 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base2.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base256emoji.js +41 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base32.js +58 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base36.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base58.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base64.js +28 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base8.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/identity.js +11 -0
- package/bundle/node_modules/multiformats/dist/src/basics.js +15 -0
- package/bundle/node_modules/multiformats/dist/src/bytes.js +18 -0
- package/bundle/node_modules/multiformats/dist/src/codecs/json.js +2 -0
- package/bundle/node_modules/multiformats/dist/src/vendor/base-x.js +170 -0
- package/bundle/node_modules/protons-runtime/dist/src/codec.js +20 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/enum.js +24 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/message.js +7 -0
- package/bundle/node_modules/protons-runtime/dist/src/decode.js +8 -0
- package/bundle/node_modules/protons-runtime/dist/src/encode.js +11 -0
- package/bundle/node_modules/protons-runtime/dist/src/index.js +30 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/float.js +54 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/longbits.js +175 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/pool.js +28 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/reader.js +367 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/utf8.js +99 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/writer.js +438 -0
- package/bundle/node_modules/uint8-varint/dist/src/index.js +124 -0
- package/bundle/node_modules/uint8arrays/dist/src/alloc.js +17 -0
- package/bundle/node_modules/uint8arrays/dist/src/from-string.js +19 -0
- package/bundle/node_modules/uint8arrays/dist/src/util/bases.js +49 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +21 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +18 -0
- package/bundle/packages/core/dist/lib/filter/filter.js +27 -0
- package/bundle/packages/core/dist/lib/light_push/light_push.js +27 -0
- package/bundle/packages/core/dist/lib/message/version_0.js +154 -0
- package/bundle/packages/core/dist/lib/metadata/metadata.js +27 -0
- package/bundle/packages/core/dist/lib/store/store.js +27 -0
- package/bundle/packages/interfaces/dist/connection_manager.js +19 -0
- package/bundle/packages/interfaces/dist/constants.js +6 -0
- package/bundle/packages/interfaces/dist/health_indicator.js +12 -0
- package/bundle/packages/interfaces/dist/protocols.js +97 -0
- package/bundle/packages/proto/dist/generated/filter.js +445 -0
- package/bundle/packages/proto/dist/generated/filter_v2.js +424 -0
- package/bundle/packages/proto/dist/generated/light_push.js +389 -0
- package/bundle/packages/proto/dist/generated/message.js +213 -0
- package/bundle/packages/proto/dist/generated/metadata.js +130 -0
- package/bundle/packages/proto/dist/generated/peer_exchange.js +209 -0
- package/bundle/packages/proto/dist/generated/sds_message.js +105 -0
- package/bundle/packages/proto/dist/generated/store_v3.js +490 -0
- package/bundle/packages/proto/dist/generated/topic_only_message.js +61 -0
- package/bundle/packages/rln/dist/codec.js +93 -0
- package/bundle/packages/rln/dist/contract/abi/rlnv2.js +394 -0
- package/bundle/packages/rln/dist/contract/constants.js +33 -0
- package/bundle/packages/rln/dist/contract/rln_contract.js +427 -0
- package/bundle/packages/rln/dist/create.js +9 -0
- package/bundle/packages/rln/dist/identity.js +76 -0
- package/bundle/packages/rln/dist/keystore/cipher.js +31 -0
- package/bundle/packages/rln/dist/keystore/credential_validation_generated.js +119 -0
- package/bundle/packages/rln/dist/keystore/keystore.js +223 -0
- package/bundle/packages/rln/dist/keystore/keystore_validation_generated.js +74 -0
- package/bundle/packages/rln/dist/keystore/schema_validator.js +20 -0
- package/bundle/packages/rln/dist/message.js +51 -0
- package/bundle/packages/rln/dist/proof.js +54 -0
- package/bundle/packages/rln/dist/resources/verification_key.js +112 -0
- package/bundle/packages/rln/dist/resources/witness_calculator.js +330 -0
- package/bundle/packages/rln/dist/rln.js +204 -0
- package/bundle/packages/rln/dist/root_tracker.js +76 -0
- package/bundle/packages/rln/dist/utils/bytes.js +65 -0
- package/bundle/packages/rln/dist/utils/epoch.js +39 -0
- package/bundle/packages/rln/dist/utils/hash.js +10 -0
- package/bundle/packages/rln/dist/utils/metamask.js +14 -0
- package/bundle/packages/rln/dist/zerokit.js +122 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +52 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +65 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +99 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/index.js +28 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +78 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1253 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +40 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/types.js +5 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +41 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +23 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +12 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +77 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +9 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +215 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +35 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +21 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +66 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +24 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +7 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +11 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +52 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +124 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +71 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +10 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +88 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +99 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +233 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +133 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +243 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +167 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/native.js +4 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/rng.js +13 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/stringify.js +28 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/v4.js +19 -0
- package/bundle/packages/utils/dist/bytes/index.js +44 -0
- package/bundle/packages/utils/dist/common/sharding/index.js +91 -0
- package/bundle/packages/utils/dist/logger/index.js +31 -0
- package/bundle/resources/rln.wasm +0 -0
- package/bundle/resources/rln_final.zkey +0 -0
- package/bundle/resources/verification_key.d.ts +13 -0
- package/bundle/resources/verification_key.js +112 -0
- package/bundle/resources/witness_calculator.d.ts +11 -0
- package/bundle/resources/witness_calculator.js +328 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/__tests__/identity.test.d.ts +1 -0
- package/dist/__tests__/identity.test.js +40 -0
- package/dist/__tests__/identity.test.js.map +1 -0
- package/dist/codec.d.ts +39 -0
- package/dist/codec.js +77 -0
- package/dist/codec.js.map +1 -0
- package/dist/contract/abi/rlnv2.d.ts +42 -0
- package/dist/contract/abi/rlnv2.js +393 -0
- package/dist/contract/abi/rlnv2.js.map +1 -0
- package/dist/contract/constants.d.ts +68 -0
- package/dist/contract/constants.js +31 -0
- package/dist/contract/constants.js.map +1 -0
- package/dist/contract/index.d.ts +2 -0
- package/dist/contract/index.js +3 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/rln_contract.d.ts +119 -0
- package/dist/contract/rln_contract.js +421 -0
- package/dist/contract/rln_contract.js.map +1 -0
- package/dist/create.d.ts +2 -0
- package/dist/create.js +8 -0
- package/dist/create.js.map +1 -0
- package/dist/identity.d.ts +16 -0
- package/dist/identity.js +73 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/dist/keystore/cipher.d.ts +4 -0
- package/dist/keystore/cipher.js +28 -0
- package/dist/keystore/cipher.js.map +1 -0
- package/dist/keystore/credential_validation_generated.d.ts +8 -0
- package/dist/keystore/credential_validation_generated.js +121 -0
- package/dist/keystore/credential_validation_generated.js.map +1 -0
- package/dist/keystore/index.d.ts +4 -0
- package/dist/keystore/index.js +3 -0
- package/dist/keystore/index.js.map +1 -0
- package/dist/keystore/keystore.d.ts +50 -0
- package/dist/keystore/keystore.js +205 -0
- package/dist/keystore/keystore.js.map +1 -0
- package/dist/keystore/keystore_validation_generated.d.ts +8 -0
- package/dist/keystore/keystore_validation_generated.js +75 -0
- package/dist/keystore/keystore_validation_generated.js.map +1 -0
- package/dist/keystore/schema_validator.d.ts +2 -0
- package/dist/keystore/schema_validator.js +18 -0
- package/dist/keystore/schema_validator.js.map +1 -0
- package/dist/keystore/types.d.ts +29 -0
- package/dist/keystore/types.js +2 -0
- package/dist/keystore/types.js.map +1 -0
- package/dist/message.d.ts +18 -0
- package/dist/message.js +49 -0
- package/dist/message.js.map +1 -0
- package/dist/proof.d.ts +21 -0
- package/dist/proof.js +50 -0
- package/dist/proof.js.map +1 -0
- package/dist/resources/rln.wasm +0 -0
- package/dist/resources/rln_final.zkey +0 -0
- package/dist/resources/verification_key.d.ts +13 -0
- package/dist/resources/verification_key.js +112 -0
- package/dist/resources/witness_calculator.d.ts +11 -0
- package/dist/resources/witness_calculator.js +328 -0
- package/dist/rln.d.ts +59 -13
- package/dist/rln.js +164 -81
- package/dist/rln.js.map +1 -1
- package/dist/root_tracker.d.ts +10 -0
- package/dist/root_tracker.js +75 -0
- package/dist/root_tracker.js.map +1 -0
- package/dist/utils/bytes.d.ts +20 -0
- package/dist/utils/bytes.js +64 -0
- package/dist/utils/bytes.js.map +1 -0
- package/dist/utils/epoch.d.ts +3 -0
- package/dist/utils/epoch.js +23 -0
- package/dist/utils/epoch.js.map +1 -0
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.js +13 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/metamask.d.ts +2 -0
- package/dist/utils/metamask.js +12 -0
- package/dist/utils/metamask.js.map +1 -0
- package/dist/zerokit.d.ts +19 -0
- package/dist/zerokit.js +119 -0
- package/dist/zerokit.js.map +1 -0
- package/package.json +1 -126
- package/src/__tests__/identity.test.ts +50 -0
- package/src/codec.ts +134 -0
- package/src/contract/abi/rlnv2.ts +392 -0
- package/src/contract/constants.ts +35 -0
- package/src/contract/index.ts +2 -0
- package/src/contract/rln_contract.ts +673 -0
- package/src/create.ts +9 -0
- package/src/identity.ts +101 -0
- package/src/index.ts +24 -10
- package/src/keystore/cipher.ts +54 -0
- package/src/keystore/credential_validation_generated.ts +7 -0
- package/src/keystore/index.ts +5 -0
- package/src/keystore/keystore.ts +330 -0
- package/src/keystore/keystore_validation_generated.ts +7 -0
- package/src/keystore/schema_validator.ts +34 -0
- package/src/keystore/types.ts +36 -0
- package/src/message.ts +70 -0
- package/src/proof.ts +69 -0
- package/src/resources/verification_key.d.ts +13 -0
- package/src/resources/witness_calculator.d.ts +11 -0
- package/src/rln.ts +270 -106
- package/src/root_tracker.ts +92 -0
- package/src/utils/bytes.ts +84 -0
- package/src/utils/epoch.ts +30 -0
- package/src/utils/hash.ts +15 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/metamask.ts +17 -0
- package/src/zerokit.ts +214 -0
- package/bundle/02bce7e5f3bcf834.wasm +0 -0
- package/bundle/rln-f87f6dbe.js +0 -563
- package/dist/resources.d.ts +0 -4
- package/dist/resources.js +0 -5
- package/dist/resources.js.map +0 -1
- package/dist/witness_calculator.d.ts +0 -16
- package/dist/witness_calculator.js +0 -291
- package/dist/witness_calculator.js.map +0 -1
- package/dist/zerokit/rln_wasm.d.ts +0 -1
- package/dist/zerokit/rln_wasm.js +0 -2
- package/dist/zerokit/rln_wasm.js.map +0 -1
- package/dist/zerokit/rln_wasm_bg.d.ts +0 -108
- package/dist/zerokit/rln_wasm_bg.js +0 -592
- package/dist/zerokit/rln_wasm_bg.js.map +0 -1
- package/dist/zerokit/rln_wasm_bg.wasm +0 -0
- package/src/resources.ts +0 -10
- package/src/witness_calculator.d.ts +0 -4
@@ -0,0 +1,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 };
|
@@ -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 };
|