@waku/rln 0.1.3 → 0.1.4-d27db21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -186
- package/bundle/_virtual/__node-resolve_empty.js +6 -0
- package/bundle/_virtual/_assert.js +3 -0
- package/bundle/_virtual/_commonjs-dynamic-modules.js +5 -0
- package/bundle/_virtual/_commonjsHelpers.js +32 -0
- package/bundle/_virtual/_node-resolve_empty.js +3 -0
- package/bundle/_virtual/_sha2.js +3 -0
- package/bundle/_virtual/_u64.js +3 -0
- package/bundle/_virtual/aes.js +3 -0
- package/bundle/_virtual/bn.js +3 -0
- package/bundle/_virtual/browser.js +3 -0
- package/bundle/_virtual/checksum.js +3 -0
- package/bundle/_virtual/cipher.js +3 -0
- package/bundle/_virtual/class.js +3 -0
- package/bundle/_virtual/common.js +3 -0
- package/bundle/_virtual/common2.js +3 -0
- package/bundle/_virtual/cryptoBrowser.js +3 -0
- package/bundle/_virtual/functional.js +3 -0
- package/bundle/_virtual/hash.js +3 -0
- package/bundle/_virtual/hmac.js +3 -0
- package/bundle/_virtual/index.js +3 -0
- package/bundle/_virtual/index2.js +6 -0
- package/bundle/_virtual/inherits_browser.js +3 -0
- package/bundle/_virtual/kdf.js +3 -0
- package/bundle/_virtual/lodash.js +3 -0
- package/bundle/_virtual/password.js +3 -0
- package/bundle/_virtual/pbkdf2.js +3 -0
- package/bundle/_virtual/pbkdf22.js +3 -0
- package/bundle/_virtual/random.js +3 -0
- package/bundle/_virtual/ripemd.js +3 -0
- package/bundle/_virtual/schema-validation-generated.js +3 -0
- package/bundle/_virtual/schema-validation.js +3 -0
- package/bundle/_virtual/scrypt.js +3 -0
- package/bundle/_virtual/scrypt2.js +3 -0
- package/bundle/_virtual/sha.js +3 -0
- package/bundle/_virtual/sha256.js +3 -0
- package/bundle/_virtual/sha2562.js +3 -0
- package/bundle/_virtual/sha3.js +3 -0
- package/bundle/_virtual/sha512.js +3 -0
- package/bundle/_virtual/types.js +3 -0
- package/bundle/_virtual/utils.js +3 -0
- package/bundle/_virtual/utils2.js +3 -0
- package/bundle/_virtual/utils3.js +3 -0
- package/bundle/index.js +12 -74804
- package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +96 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +148 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +20 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +210 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +18 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +30 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +22 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +43 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +19 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +58 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +854 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +609 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +66 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +302 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +110 -0
- package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +20 -0
- package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +287 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +402 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +3 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +8 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +893 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +256 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +36 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +135 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +8 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +64 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +443 -0
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +8 -0
- package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +660 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +352 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +248 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +127 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +2007 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +422 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +674 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +132 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +8 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +2430 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +76 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +219 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +279 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +69 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +404 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +15 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +20 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +92 -0
- package/bundle/node_modules/@noble/hashes/esm/_assert.js +37 -0
- package/bundle/node_modules/@noble/hashes/esm/_md.js +132 -0
- package/bundle/node_modules/@noble/hashes/esm/_u64.js +29 -0
- package/bundle/node_modules/@noble/hashes/esm/sha256.js +113 -0
- package/bundle/node_modules/@noble/hashes/esm/sha3.js +210 -0
- package/bundle/node_modules/@noble/hashes/esm/utils.js +144 -0
- package/bundle/node_modules/@waku/zerokit-rln-wasm/rln_wasm.js +756 -0
- package/bundle/node_modules/bech32/index.js +187 -0
- package/bundle/node_modules/bn.js/lib/bn.js +3361 -0
- package/bundle/node_modules/debug/src/browser.js +283 -0
- package/bundle/node_modules/debug/src/common.js +295 -0
- package/bundle/node_modules/ethereum-cryptography/esm/keccak.js +10 -0
- package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +6 -0
- package/bundle/node_modules/ethereum-cryptography/esm/utils.js +24 -0
- package/bundle/node_modules/hash.js/lib/hash/common.js +97 -0
- package/bundle/node_modules/hash.js/lib/hash/hmac.js +51 -0
- package/bundle/node_modules/hash.js/lib/hash/ripemd.js +152 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/1.js +81 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/224.js +33 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/256.js +113 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/384.js +39 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/512.js +336 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/common.js +53 -0
- package/bundle/node_modules/hash.js/lib/hash/sha.js +14 -0
- package/bundle/node_modules/hash.js/lib/hash/utils.js +282 -0
- package/bundle/node_modules/hash.js/lib/hash.js +33 -0
- package/bundle/node_modules/inherits/inherits_browser.js +33 -0
- package/bundle/node_modules/it-length-prefixed/dist/src/decode.js +6 -0
- package/bundle/node_modules/lodash/lodash.js +17207 -0
- package/bundle/node_modules/minimalistic-assert/index.js +13 -0
- package/bundle/node_modules/ms/index.js +172 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base.js +205 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base10.js +9 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base16.js +16 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base2.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base256emoji.js +41 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base32.js +58 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base36.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base58.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base64.js +28 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base8.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/identity.js +11 -0
- package/bundle/node_modules/multiformats/dist/src/basics.js +15 -0
- package/bundle/node_modules/multiformats/dist/src/bytes.js +18 -0
- package/bundle/node_modules/multiformats/dist/src/codecs/json.js +2 -0
- package/bundle/node_modules/multiformats/dist/src/vendor/base-x.js +170 -0
- package/bundle/node_modules/protons-runtime/dist/src/codec.js +20 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/enum.js +24 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/message.js +7 -0
- package/bundle/node_modules/protons-runtime/dist/src/decode.js +8 -0
- package/bundle/node_modules/protons-runtime/dist/src/encode.js +11 -0
- package/bundle/node_modules/protons-runtime/dist/src/index.js +30 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/float.js +54 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/longbits.js +175 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/pool.js +28 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/reader.js +367 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/utf8.js +99 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/writer.js +438 -0
- package/bundle/node_modules/uint8-varint/dist/src/index.js +124 -0
- package/bundle/node_modules/uint8arrays/dist/src/alloc.js +17 -0
- package/bundle/node_modules/uint8arrays/dist/src/from-string.js +19 -0
- package/bundle/node_modules/uint8arrays/dist/src/util/bases.js +49 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +21 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +18 -0
- package/bundle/packages/core/dist/lib/filter/filter.js +27 -0
- package/bundle/packages/core/dist/lib/light_push/light_push.js +27 -0
- package/bundle/packages/core/dist/lib/message/version_0.js +154 -0
- package/bundle/packages/core/dist/lib/metadata/metadata.js +27 -0
- package/bundle/packages/core/dist/lib/store/store.js +27 -0
- package/bundle/packages/interfaces/dist/connection_manager.js +19 -0
- package/bundle/packages/interfaces/dist/constants.js +6 -0
- package/bundle/packages/interfaces/dist/health_indicator.js +12 -0
- package/bundle/packages/interfaces/dist/protocols.js +92 -0
- package/bundle/packages/proto/dist/generated/filter.js +445 -0
- package/bundle/packages/proto/dist/generated/filter_v2.js +424 -0
- package/bundle/packages/proto/dist/generated/light_push.js +389 -0
- package/bundle/packages/proto/dist/generated/message.js +213 -0
- package/bundle/packages/proto/dist/generated/metadata.js +130 -0
- package/bundle/packages/proto/dist/generated/peer_exchange.js +209 -0
- package/bundle/packages/proto/dist/generated/sds_message.js +105 -0
- package/bundle/packages/proto/dist/generated/store_v3.js +490 -0
- package/bundle/packages/proto/dist/generated/topic_only_message.js +61 -0
- package/bundle/packages/rln/dist/codec.js +93 -0
- package/bundle/packages/rln/dist/contract/abi.js +394 -0
- package/bundle/packages/rln/dist/contract/constants.js +27 -0
- package/bundle/packages/rln/dist/contract/rln_contract.js +438 -0
- package/bundle/packages/rln/dist/create.js +9 -0
- package/bundle/packages/rln/dist/identity.js +30 -0
- package/bundle/packages/rln/dist/keystore/cipher.js +31 -0
- package/bundle/packages/rln/dist/keystore/credential_validation_generated.js +119 -0
- package/bundle/packages/rln/dist/keystore/keystore.js +223 -0
- package/bundle/packages/rln/dist/keystore/keystore_validation_generated.js +74 -0
- package/bundle/packages/rln/dist/keystore/schema_validator.js +20 -0
- package/bundle/packages/rln/dist/message.js +51 -0
- package/bundle/packages/rln/dist/proof.js +54 -0
- package/bundle/packages/rln/dist/resources/verification_key.js +112 -0
- package/bundle/packages/rln/dist/resources/witness_calculator.js +330 -0
- package/bundle/packages/rln/dist/rln.js +220 -0
- package/bundle/packages/rln/dist/root_tracker.js +76 -0
- package/bundle/packages/rln/dist/utils/bytes.js +65 -0
- package/bundle/packages/rln/dist/utils/epoch.js +39 -0
- package/bundle/packages/rln/dist/utils/hash.js +10 -0
- package/bundle/packages/rln/dist/utils/metamask.js +14 -0
- package/bundle/packages/rln/dist/zerokit.js +128 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +52 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +65 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +99 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/index.js +28 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +78 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1253 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +40 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/types.js +5 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +41 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +23 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +12 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +77 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +9 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +215 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +35 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +21 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +66 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +24 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +7 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +11 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +52 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +124 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +71 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +10 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +88 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +99 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +233 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +133 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +243 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +167 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/native.js +4 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/rng.js +13 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/stringify.js +28 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/v4.js +19 -0
- package/bundle/packages/utils/dist/bytes/index.js +44 -0
- package/bundle/packages/utils/dist/common/sharding/index.js +91 -0
- package/bundle/packages/utils/dist/logger/index.js +31 -0
- package/bundle/resources/verification_key.d.ts +13 -0
- package/bundle/resources/verification_key.js +112 -0
- package/bundle/resources/witness_calculator.d.ts +11 -0
- package/bundle/resources/witness_calculator.js +328 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/codec.d.ts +5 -5
- package/dist/codec.js +6 -6
- package/dist/codec.js.map +1 -1
- package/dist/contract/abi.d.ts +42 -0
- package/dist/contract/abi.js +393 -0
- package/dist/contract/abi.js.map +1 -0
- package/dist/contract/constants.d.ts +59 -3
- package/dist/contract/constants.js +21 -63
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_contract.d.ts +98 -17
- package/dist/contract/rln_contract.js +292 -71
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/identity.js +5 -2
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/keystore/cipher.js +3 -3
- package/dist/keystore/cipher.js.map +1 -1
- package/dist/keystore/credential_validation_generated.js.map +1 -1
- package/dist/keystore/keystore.js +4 -4
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/keystore_validation_generated.js.map +1 -1
- package/dist/message.js +3 -3
- package/dist/message.js.map +1 -1
- package/dist/proof.js +3 -2
- package/dist/proof.js.map +1 -1
- package/dist/resources/verification_key.d.ts +12 -11
- package/dist/resources/verification_key.js +103 -103
- package/dist/resources/witness_calculator.d.ts +10 -15
- package/dist/resources/witness_calculator.js +302 -265
- package/dist/rln.d.ts +5 -1
- package/dist/rln.js +56 -28
- package/dist/rln.js.map +1 -1
- package/dist/root_tracker.js.map +1 -1
- package/dist/utils/epoch.js +5 -5
- package/dist/utils/epoch.js.map +1 -1
- package/dist/zerokit.d.ts +13 -9
- package/dist/zerokit.js +40 -20
- package/dist/zerokit.js.map +1 -1
- package/package.json +1 -146
- package/src/codec.ts +26 -22
- package/src/contract/abi.ts +392 -0
- package/src/contract/constants.ts +28 -0
- package/src/contract/index.ts +2 -0
- package/src/contract/rln_contract.ts +686 -0
- package/src/identity.ts +8 -4
- package/src/index.ts +4 -9
- package/src/keystore/cipher.ts +54 -0
- package/src/keystore/credential_validation_generated.ts +7 -0
- package/src/keystore/index.ts +5 -0
- package/src/keystore/keystore.ts +330 -0
- package/src/keystore/keystore_validation_generated.ts +7 -0
- package/src/keystore/schema_validator.ts +34 -0
- package/src/keystore/types.ts +36 -0
- package/src/message.ts +10 -10
- package/src/proof.ts +13 -11
- package/src/resources/verification_key.d.ts +13 -0
- package/src/resources/witness_calculator.d.ts +11 -0
- package/src/rln.ts +76 -31
- package/src/root_tracker.ts +7 -6
- package/src/utils/bytes.ts +84 -0
- package/src/utils/epoch.ts +30 -0
- package/src/utils/hash.ts +15 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/metamask.ts +17 -0
- package/src/zerokit.ts +95 -33
- package/bundle/assets/rln_wasm_bg-a503e304.wasm +0 -0
- package/dist/resources/verification_key.js.map +0 -1
- package/dist/resources/witness_calculator.js.map +0 -1
- /package/bundle/{assets/rln-6ded2896.wasm → resources/rln.wasm} +0 -0
- /package/bundle/{assets/rln_final-8b299152.zkey → resources/rln_final.zkey} +0 -0
@@ -0,0 +1,88 @@
|
|
1
|
+
import { __exports as hmac } from '../../../../../_virtual/hmac.js';
|
2
|
+
import './_assert.js';
|
3
|
+
import './utils.js';
|
4
|
+
import { __exports as _assert } from '../../../../../_virtual/_assert.js';
|
5
|
+
import { __exports as utils } from '../../../../../_virtual/utils.js';
|
6
|
+
|
7
|
+
(function (exports) {
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
9
|
+
exports.hmac = undefined;
|
10
|
+
const _assert_js_1 = _assert;
|
11
|
+
const utils_js_1 = utils;
|
12
|
+
// HMAC (RFC 2104)
|
13
|
+
class HMAC extends utils_js_1.Hash {
|
14
|
+
constructor(hash, _key) {
|
15
|
+
super();
|
16
|
+
this.finished = false;
|
17
|
+
this.destroyed = false;
|
18
|
+
_assert_js_1.default.hash(hash);
|
19
|
+
const key = (0, utils_js_1.toBytes)(_key);
|
20
|
+
this.iHash = hash.create();
|
21
|
+
if (typeof this.iHash.update !== 'function')
|
22
|
+
throw new TypeError('Expected instance of class which extends utils.Hash');
|
23
|
+
this.blockLen = this.iHash.blockLen;
|
24
|
+
this.outputLen = this.iHash.outputLen;
|
25
|
+
const blockLen = this.blockLen;
|
26
|
+
const pad = new Uint8Array(blockLen);
|
27
|
+
// blockLen can be bigger than outputLen
|
28
|
+
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
29
|
+
for (let i = 0; i < pad.length; i++)
|
30
|
+
pad[i] ^= 0x36;
|
31
|
+
this.iHash.update(pad);
|
32
|
+
// By doing update (processing of first block) of outer hash here we can re-use it between multiple calls via clone
|
33
|
+
this.oHash = hash.create();
|
34
|
+
// Undo internal XOR && apply outer XOR
|
35
|
+
for (let i = 0; i < pad.length; i++)
|
36
|
+
pad[i] ^= 0x36 ^ 0x5c;
|
37
|
+
this.oHash.update(pad);
|
38
|
+
pad.fill(0);
|
39
|
+
}
|
40
|
+
update(buf) {
|
41
|
+
_assert_js_1.default.exists(this);
|
42
|
+
this.iHash.update(buf);
|
43
|
+
return this;
|
44
|
+
}
|
45
|
+
digestInto(out) {
|
46
|
+
_assert_js_1.default.exists(this);
|
47
|
+
_assert_js_1.default.bytes(out, this.outputLen);
|
48
|
+
this.finished = true;
|
49
|
+
this.iHash.digestInto(out);
|
50
|
+
this.oHash.update(out);
|
51
|
+
this.oHash.digestInto(out);
|
52
|
+
this.destroy();
|
53
|
+
}
|
54
|
+
digest() {
|
55
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
56
|
+
this.digestInto(out);
|
57
|
+
return out;
|
58
|
+
}
|
59
|
+
_cloneInto(to) {
|
60
|
+
// Create new instance without calling constructor since key already in state and we don't know it.
|
61
|
+
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
62
|
+
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
63
|
+
to = to;
|
64
|
+
to.finished = finished;
|
65
|
+
to.destroyed = destroyed;
|
66
|
+
to.blockLen = blockLen;
|
67
|
+
to.outputLen = outputLen;
|
68
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
69
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
70
|
+
return to;
|
71
|
+
}
|
72
|
+
destroy() {
|
73
|
+
this.destroyed = true;
|
74
|
+
this.oHash.destroy();
|
75
|
+
this.iHash.destroy();
|
76
|
+
}
|
77
|
+
}
|
78
|
+
/**
|
79
|
+
* HMAC: RFC2104 message authentication code.
|
80
|
+
* @param hash - function that would be used e.g. sha256
|
81
|
+
* @param key - message key
|
82
|
+
* @param message - message data
|
83
|
+
*/
|
84
|
+
const hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
85
|
+
exports.hmac = hmac;
|
86
|
+
exports.hmac.create = (hash, key) => new HMAC(hash, key);
|
87
|
+
|
88
|
+
} (hmac));
|
@@ -0,0 +1,99 @@
|
|
1
|
+
import { __exports as pbkdf2$1 } from '../../../../../_virtual/pbkdf22.js';
|
2
|
+
import './_assert.js';
|
3
|
+
import './hmac.js';
|
4
|
+
import './utils.js';
|
5
|
+
import { __exports as utils } from '../../../../../_virtual/utils.js';
|
6
|
+
import { __exports as _assert } from '../../../../../_virtual/_assert.js';
|
7
|
+
import { __exports as hmac } from '../../../../../_virtual/hmac.js';
|
8
|
+
|
9
|
+
Object.defineProperty(pbkdf2$1, "__esModule", { value: true });
|
10
|
+
pbkdf2$1.pbkdf2Async = pbkdf2$1.pbkdf2 = undefined;
|
11
|
+
const _assert_js_1 = _assert;
|
12
|
+
const hmac_js_1 = hmac;
|
13
|
+
const utils_js_1 = utils;
|
14
|
+
// Common prologue and epilogue for sync/async functions
|
15
|
+
function pbkdf2Init(hash, _password, _salt, _opts) {
|
16
|
+
_assert_js_1.default.hash(hash);
|
17
|
+
const opts = (0, utils_js_1.checkOpts)({ dkLen: 32, asyncTick: 10 }, _opts);
|
18
|
+
const { c, dkLen, asyncTick } = opts;
|
19
|
+
_assert_js_1.default.number(c);
|
20
|
+
_assert_js_1.default.number(dkLen);
|
21
|
+
_assert_js_1.default.number(asyncTick);
|
22
|
+
if (c < 1)
|
23
|
+
throw new Error('PBKDF2: iterations (c) should be >= 1');
|
24
|
+
const password = (0, utils_js_1.toBytes)(_password);
|
25
|
+
const salt = (0, utils_js_1.toBytes)(_salt);
|
26
|
+
// DK = PBKDF2(PRF, Password, Salt, c, dkLen);
|
27
|
+
const DK = new Uint8Array(dkLen);
|
28
|
+
// U1 = PRF(Password, Salt + INT_32_BE(i))
|
29
|
+
const PRF = hmac_js_1.hmac.create(hash, password);
|
30
|
+
const PRFSalt = PRF._cloneInto().update(salt);
|
31
|
+
return { c, dkLen, asyncTick, DK, PRF, PRFSalt };
|
32
|
+
}
|
33
|
+
function pbkdf2Output(PRF, PRFSalt, DK, prfW, u) {
|
34
|
+
PRF.destroy();
|
35
|
+
PRFSalt.destroy();
|
36
|
+
if (prfW)
|
37
|
+
prfW.destroy();
|
38
|
+
u.fill(0);
|
39
|
+
return DK;
|
40
|
+
}
|
41
|
+
/**
|
42
|
+
* PBKDF2-HMAC: RFC 2898 key derivation function
|
43
|
+
* @param hash - hash function that would be used e.g. sha256
|
44
|
+
* @param password - password from which a derived key is generated
|
45
|
+
* @param salt - cryptographic salt
|
46
|
+
* @param opts - {c, dkLen} where c is work factor and dkLen is output message size
|
47
|
+
*/
|
48
|
+
function pbkdf2(hash, password, salt, opts) {
|
49
|
+
const { c, dkLen, DK, PRF, PRFSalt } = pbkdf2Init(hash, password, salt, opts);
|
50
|
+
let prfW; // Working copy
|
51
|
+
const arr = new Uint8Array(4);
|
52
|
+
const view = (0, utils_js_1.createView)(arr);
|
53
|
+
const u = new Uint8Array(PRF.outputLen);
|
54
|
+
// DK = T1 + T2 + ⋯ + Tdklen/hlen
|
55
|
+
for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += PRF.outputLen) {
|
56
|
+
// Ti = F(Password, Salt, c, i)
|
57
|
+
const Ti = DK.subarray(pos, pos + PRF.outputLen);
|
58
|
+
view.setInt32(0, ti, false);
|
59
|
+
// F(Password, Salt, c, i) = U1 ^ U2 ^ ⋯ ^ Uc
|
60
|
+
// U1 = PRF(Password, Salt + INT_32_BE(i))
|
61
|
+
(prfW = PRFSalt._cloneInto(prfW)).update(arr).digestInto(u);
|
62
|
+
Ti.set(u.subarray(0, Ti.length));
|
63
|
+
for (let ui = 1; ui < c; ui++) {
|
64
|
+
// Uc = PRF(Password, Uc−1)
|
65
|
+
PRF._cloneInto(prfW).update(u).digestInto(u);
|
66
|
+
for (let i = 0; i < Ti.length; i++)
|
67
|
+
Ti[i] ^= u[i];
|
68
|
+
}
|
69
|
+
}
|
70
|
+
return pbkdf2Output(PRF, PRFSalt, DK, prfW, u);
|
71
|
+
}
|
72
|
+
pbkdf2$1.pbkdf2 = pbkdf2;
|
73
|
+
async function pbkdf2Async(hash, password, salt, opts) {
|
74
|
+
const { c, dkLen, asyncTick, DK, PRF, PRFSalt } = pbkdf2Init(hash, password, salt, opts);
|
75
|
+
let prfW; // Working copy
|
76
|
+
const arr = new Uint8Array(4);
|
77
|
+
const view = (0, utils_js_1.createView)(arr);
|
78
|
+
const u = new Uint8Array(PRF.outputLen);
|
79
|
+
// DK = T1 + T2 + ⋯ + Tdklen/hlen
|
80
|
+
for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += PRF.outputLen) {
|
81
|
+
// Ti = F(Password, Salt, c, i)
|
82
|
+
const Ti = DK.subarray(pos, pos + PRF.outputLen);
|
83
|
+
view.setInt32(0, ti, false);
|
84
|
+
// F(Password, Salt, c, i) = U1 ^ U2 ^ ⋯ ^ Uc
|
85
|
+
// U1 = PRF(Password, Salt + INT_32_BE(i))
|
86
|
+
(prfW = PRFSalt._cloneInto(prfW)).update(arr).digestInto(u);
|
87
|
+
Ti.set(u.subarray(0, Ti.length));
|
88
|
+
await (0, utils_js_1.asyncLoop)(c - 1, asyncTick, (i) => {
|
89
|
+
// Uc = PRF(Password, Uc−1)
|
90
|
+
PRF._cloneInto(prfW).update(u).digestInto(u);
|
91
|
+
for (let i = 0; i < Ti.length; i++)
|
92
|
+
Ti[i] ^= u[i];
|
93
|
+
});
|
94
|
+
}
|
95
|
+
return pbkdf2Output(PRF, PRFSalt, DK, prfW, u);
|
96
|
+
}
|
97
|
+
pbkdf2$1.pbkdf2Async = pbkdf2Async;
|
98
|
+
|
99
|
+
export { pbkdf2$1 as default };
|
@@ -0,0 +1,233 @@
|
|
1
|
+
import { __exports as scrypt$1 } from '../../../../../_virtual/scrypt2.js';
|
2
|
+
import './_assert.js';
|
3
|
+
import './sha256.js';
|
4
|
+
import './pbkdf2.js';
|
5
|
+
import './utils.js';
|
6
|
+
import { __exports as utils } from '../../../../../_virtual/utils.js';
|
7
|
+
import { __exports as _assert } from '../../../../../_virtual/_assert.js';
|
8
|
+
import { __exports as sha256 } from '../../../../../_virtual/sha2562.js';
|
9
|
+
import { __exports as pbkdf2 } from '../../../../../_virtual/pbkdf22.js';
|
10
|
+
|
11
|
+
Object.defineProperty(scrypt$1, "__esModule", { value: true });
|
12
|
+
scrypt$1.scryptAsync = scrypt$1.scrypt = undefined;
|
13
|
+
const _assert_js_1 = _assert;
|
14
|
+
const sha256_js_1 = sha256;
|
15
|
+
const pbkdf2_js_1 = pbkdf2;
|
16
|
+
const utils_js_1 = utils;
|
17
|
+
// RFC 7914 Scrypt KDF
|
18
|
+
// Left rotate for uint32
|
19
|
+
const rotl = (a, b) => (a << b) | (a >>> (32 - b));
|
20
|
+
// The main Scrypt loop: uses Salsa extensively.
|
21
|
+
// Six versions of the function were tried, this is the fastest one.
|
22
|
+
// prettier-ignore
|
23
|
+
function XorAndSalsa(prev, pi, input, ii, out, oi) {
|
24
|
+
// Based on https://cr.yp.to/salsa20.html
|
25
|
+
// Xor blocks
|
26
|
+
let y00 = prev[pi++] ^ input[ii++], y01 = prev[pi++] ^ input[ii++];
|
27
|
+
let y02 = prev[pi++] ^ input[ii++], y03 = prev[pi++] ^ input[ii++];
|
28
|
+
let y04 = prev[pi++] ^ input[ii++], y05 = prev[pi++] ^ input[ii++];
|
29
|
+
let y06 = prev[pi++] ^ input[ii++], y07 = prev[pi++] ^ input[ii++];
|
30
|
+
let y08 = prev[pi++] ^ input[ii++], y09 = prev[pi++] ^ input[ii++];
|
31
|
+
let y10 = prev[pi++] ^ input[ii++], y11 = prev[pi++] ^ input[ii++];
|
32
|
+
let y12 = prev[pi++] ^ input[ii++], y13 = prev[pi++] ^ input[ii++];
|
33
|
+
let y14 = prev[pi++] ^ input[ii++], y15 = prev[pi++] ^ input[ii++];
|
34
|
+
// Save state to temporary variables (salsa)
|
35
|
+
let x00 = y00, x01 = y01, x02 = y02, x03 = y03, x04 = y04, x05 = y05, x06 = y06, x07 = y07, x08 = y08, x09 = y09, x10 = y10, x11 = y11, x12 = y12, x13 = y13, x14 = y14, x15 = y15;
|
36
|
+
// Main loop (salsa)
|
37
|
+
for (let i = 0; i < 8; i += 2) {
|
38
|
+
x04 ^= rotl(x00 + x12 | 0, 7);
|
39
|
+
x08 ^= rotl(x04 + x00 | 0, 9);
|
40
|
+
x12 ^= rotl(x08 + x04 | 0, 13);
|
41
|
+
x00 ^= rotl(x12 + x08 | 0, 18);
|
42
|
+
x09 ^= rotl(x05 + x01 | 0, 7);
|
43
|
+
x13 ^= rotl(x09 + x05 | 0, 9);
|
44
|
+
x01 ^= rotl(x13 + x09 | 0, 13);
|
45
|
+
x05 ^= rotl(x01 + x13 | 0, 18);
|
46
|
+
x14 ^= rotl(x10 + x06 | 0, 7);
|
47
|
+
x02 ^= rotl(x14 + x10 | 0, 9);
|
48
|
+
x06 ^= rotl(x02 + x14 | 0, 13);
|
49
|
+
x10 ^= rotl(x06 + x02 | 0, 18);
|
50
|
+
x03 ^= rotl(x15 + x11 | 0, 7);
|
51
|
+
x07 ^= rotl(x03 + x15 | 0, 9);
|
52
|
+
x11 ^= rotl(x07 + x03 | 0, 13);
|
53
|
+
x15 ^= rotl(x11 + x07 | 0, 18);
|
54
|
+
x01 ^= rotl(x00 + x03 | 0, 7);
|
55
|
+
x02 ^= rotl(x01 + x00 | 0, 9);
|
56
|
+
x03 ^= rotl(x02 + x01 | 0, 13);
|
57
|
+
x00 ^= rotl(x03 + x02 | 0, 18);
|
58
|
+
x06 ^= rotl(x05 + x04 | 0, 7);
|
59
|
+
x07 ^= rotl(x06 + x05 | 0, 9);
|
60
|
+
x04 ^= rotl(x07 + x06 | 0, 13);
|
61
|
+
x05 ^= rotl(x04 + x07 | 0, 18);
|
62
|
+
x11 ^= rotl(x10 + x09 | 0, 7);
|
63
|
+
x08 ^= rotl(x11 + x10 | 0, 9);
|
64
|
+
x09 ^= rotl(x08 + x11 | 0, 13);
|
65
|
+
x10 ^= rotl(x09 + x08 | 0, 18);
|
66
|
+
x12 ^= rotl(x15 + x14 | 0, 7);
|
67
|
+
x13 ^= rotl(x12 + x15 | 0, 9);
|
68
|
+
x14 ^= rotl(x13 + x12 | 0, 13);
|
69
|
+
x15 ^= rotl(x14 + x13 | 0, 18);
|
70
|
+
}
|
71
|
+
// Write output (salsa)
|
72
|
+
out[oi++] = (y00 + x00) | 0;
|
73
|
+
out[oi++] = (y01 + x01) | 0;
|
74
|
+
out[oi++] = (y02 + x02) | 0;
|
75
|
+
out[oi++] = (y03 + x03) | 0;
|
76
|
+
out[oi++] = (y04 + x04) | 0;
|
77
|
+
out[oi++] = (y05 + x05) | 0;
|
78
|
+
out[oi++] = (y06 + x06) | 0;
|
79
|
+
out[oi++] = (y07 + x07) | 0;
|
80
|
+
out[oi++] = (y08 + x08) | 0;
|
81
|
+
out[oi++] = (y09 + x09) | 0;
|
82
|
+
out[oi++] = (y10 + x10) | 0;
|
83
|
+
out[oi++] = (y11 + x11) | 0;
|
84
|
+
out[oi++] = (y12 + x12) | 0;
|
85
|
+
out[oi++] = (y13 + x13) | 0;
|
86
|
+
out[oi++] = (y14 + x14) | 0;
|
87
|
+
out[oi++] = (y15 + x15) | 0;
|
88
|
+
}
|
89
|
+
function BlockMix(input, ii, out, oi, r) {
|
90
|
+
// The block B is r 128-byte chunks (which is equivalent of 2r 64-byte chunks)
|
91
|
+
let head = oi + 0;
|
92
|
+
let tail = oi + 16 * r;
|
93
|
+
for (let i = 0; i < 16; i++)
|
94
|
+
out[tail + i] = input[ii + (2 * r - 1) * 16 + i]; // X ← B[2r−1]
|
95
|
+
for (let i = 0; i < r; i++, head += 16, ii += 16) {
|
96
|
+
// We write odd & even Yi at same time. Even: 0bXXXXX0 Odd: 0bXXXXX1
|
97
|
+
XorAndSalsa(out, tail, input, ii, out, head); // head[i] = Salsa(blockIn[2*i] ^ tail[i-1])
|
98
|
+
if (i > 0)
|
99
|
+
tail += 16; // First iteration overwrites tmp value in tail
|
100
|
+
XorAndSalsa(out, head, input, (ii += 16), out, tail); // tail[i] = Salsa(blockIn[2*i+1] ^ head[i])
|
101
|
+
}
|
102
|
+
}
|
103
|
+
// Common prologue and epilogue for sync/async functions
|
104
|
+
function scryptInit(password, salt, _opts) {
|
105
|
+
// Maxmem - 1GB+1KB by default
|
106
|
+
const opts = (0, utils_js_1.checkOpts)({
|
107
|
+
dkLen: 32,
|
108
|
+
asyncTick: 10,
|
109
|
+
maxmem: 1024 ** 3 + 1024,
|
110
|
+
}, _opts);
|
111
|
+
const { N, r, p, dkLen, asyncTick, maxmem, onProgress } = opts;
|
112
|
+
_assert_js_1.default.number(N);
|
113
|
+
_assert_js_1.default.number(r);
|
114
|
+
_assert_js_1.default.number(p);
|
115
|
+
_assert_js_1.default.number(dkLen);
|
116
|
+
_assert_js_1.default.number(asyncTick);
|
117
|
+
_assert_js_1.default.number(maxmem);
|
118
|
+
if (onProgress !== undefined && typeof onProgress !== 'function')
|
119
|
+
throw new Error('progressCb should be function');
|
120
|
+
const blockSize = 128 * r;
|
121
|
+
const blockSize32 = blockSize / 4;
|
122
|
+
if (N <= 1 || (N & (N - 1)) !== 0 || N >= 2 ** (blockSize / 8) || N > 2 ** 32) {
|
123
|
+
// NOTE: we limit N to be less than 2**32 because of 32 bit variant of Integrify function
|
124
|
+
// There is no JS engines that allows alocate more than 4GB per single Uint8Array for now, but can change in future.
|
125
|
+
throw new Error('Scrypt: N must be larger than 1, a power of 2, less than 2^(128 * r / 8) and less than 2^32');
|
126
|
+
}
|
127
|
+
if (p < 0 || p > ((2 ** 32 - 1) * 32) / blockSize) {
|
128
|
+
throw new Error('Scrypt: p must be a positive integer less than or equal to ((2^32 - 1) * 32) / (128 * r)');
|
129
|
+
}
|
130
|
+
if (dkLen < 0 || dkLen > (2 ** 32 - 1) * 32) {
|
131
|
+
throw new Error('Scrypt: dkLen should be positive integer less than or equal to (2^32 - 1) * 32');
|
132
|
+
}
|
133
|
+
const memUsed = blockSize * (N + p);
|
134
|
+
if (memUsed > maxmem) {
|
135
|
+
throw new Error(`Scrypt: parameters too large, ${memUsed} (128 * r * (N + p)) > ${maxmem} (maxmem)`);
|
136
|
+
}
|
137
|
+
// [B0...Bp−1] ← PBKDF2HMAC-SHA256(Passphrase, Salt, 1, blockSize*ParallelizationFactor)
|
138
|
+
// Since it has only one iteration there is no reason to use async variant
|
139
|
+
const B = (0, pbkdf2_js_1.pbkdf2)(sha256_js_1.sha256, password, salt, { c: 1, dkLen: blockSize * p });
|
140
|
+
const B32 = (0, utils_js_1.u32)(B);
|
141
|
+
// Re-used between parallel iterations. Array(iterations) of B
|
142
|
+
const V = (0, utils_js_1.u32)(new Uint8Array(blockSize * N));
|
143
|
+
const tmp = (0, utils_js_1.u32)(new Uint8Array(blockSize));
|
144
|
+
let blockMixCb = () => { };
|
145
|
+
if (onProgress) {
|
146
|
+
const totalBlockMix = 2 * N * p;
|
147
|
+
// Invoke callback if progress changes from 10.01 to 10.02
|
148
|
+
// Allows to draw smooth progress bar on up to 8K screen
|
149
|
+
const callbackPer = Math.max(Math.floor(totalBlockMix / 10000), 1);
|
150
|
+
let blockMixCnt = 0;
|
151
|
+
blockMixCb = () => {
|
152
|
+
blockMixCnt++;
|
153
|
+
if (onProgress && (!(blockMixCnt % callbackPer) || blockMixCnt === totalBlockMix))
|
154
|
+
onProgress(blockMixCnt / totalBlockMix);
|
155
|
+
};
|
156
|
+
}
|
157
|
+
return { N, r, p, dkLen, blockSize32, V, B32, B, tmp, blockMixCb, asyncTick };
|
158
|
+
}
|
159
|
+
function scryptOutput(password, dkLen, B, V, tmp) {
|
160
|
+
const res = (0, pbkdf2_js_1.pbkdf2)(sha256_js_1.sha256, password, B, { c: 1, dkLen });
|
161
|
+
B.fill(0);
|
162
|
+
V.fill(0);
|
163
|
+
tmp.fill(0);
|
164
|
+
return res;
|
165
|
+
}
|
166
|
+
/**
|
167
|
+
* Scrypt KDF from RFC 7914.
|
168
|
+
* @param password - pass
|
169
|
+
* @param salt - salt
|
170
|
+
* @param opts - parameters
|
171
|
+
* - `N` is cpu/mem work factor (power of 2 e.g. 2**18)
|
172
|
+
* - `r` is block size (8 is common), fine-tunes sequential memory read size and performance
|
173
|
+
* - `p` is parallelization factor (1 is common)
|
174
|
+
* - `dkLen` is output key length in bytes e.g. 32.
|
175
|
+
* - `asyncTick` - (default: 10) max time in ms for which async function can block execution
|
176
|
+
* - `maxmem` - (default: `1024 ** 3 + 1024` aka 1GB+1KB). A limit that the app could use for scrypt
|
177
|
+
* - `onProgress` - callback function that would be executed for progress report
|
178
|
+
* @returns Derived key
|
179
|
+
*/
|
180
|
+
function scrypt(password, salt, opts) {
|
181
|
+
const { N, r, p, dkLen, blockSize32, V, B32, B, tmp, blockMixCb } = scryptInit(password, salt, opts);
|
182
|
+
for (let pi = 0; pi < p; pi++) {
|
183
|
+
const Pi = blockSize32 * pi;
|
184
|
+
for (let i = 0; i < blockSize32; i++)
|
185
|
+
V[i] = B32[Pi + i]; // V[0] = B[i]
|
186
|
+
for (let i = 0, pos = 0; i < N - 1; i++) {
|
187
|
+
BlockMix(V, pos, V, (pos += blockSize32), r); // V[i] = BlockMix(V[i-1]);
|
188
|
+
blockMixCb();
|
189
|
+
}
|
190
|
+
BlockMix(V, (N - 1) * blockSize32, B32, Pi, r); // Process last element
|
191
|
+
blockMixCb();
|
192
|
+
for (let i = 0; i < N; i++) {
|
193
|
+
// First u32 of the last 64-byte block (u32 is LE)
|
194
|
+
const j = B32[Pi + blockSize32 - 16] % N; // j = Integrify(X) % iterations
|
195
|
+
for (let k = 0; k < blockSize32; k++)
|
196
|
+
tmp[k] = B32[Pi + k] ^ V[j * blockSize32 + k]; // tmp = B ^ V[j]
|
197
|
+
BlockMix(tmp, 0, B32, Pi, r); // B = BlockMix(B ^ V[j])
|
198
|
+
blockMixCb();
|
199
|
+
}
|
200
|
+
}
|
201
|
+
return scryptOutput(password, dkLen, B, V, tmp);
|
202
|
+
}
|
203
|
+
scrypt$1.scrypt = scrypt;
|
204
|
+
/**
|
205
|
+
* Scrypt KDF from RFC 7914.
|
206
|
+
*/
|
207
|
+
async function scryptAsync(password, salt, opts) {
|
208
|
+
const { N, r, p, dkLen, blockSize32, V, B32, B, tmp, blockMixCb, asyncTick } = scryptInit(password, salt, opts);
|
209
|
+
for (let pi = 0; pi < p; pi++) {
|
210
|
+
const Pi = blockSize32 * pi;
|
211
|
+
for (let i = 0; i < blockSize32; i++)
|
212
|
+
V[i] = B32[Pi + i]; // V[0] = B[i]
|
213
|
+
let pos = 0;
|
214
|
+
await (0, utils_js_1.asyncLoop)(N - 1, asyncTick, (i) => {
|
215
|
+
BlockMix(V, pos, V, (pos += blockSize32), r); // V[i] = BlockMix(V[i-1]);
|
216
|
+
blockMixCb();
|
217
|
+
});
|
218
|
+
BlockMix(V, (N - 1) * blockSize32, B32, Pi, r); // Process last element
|
219
|
+
blockMixCb();
|
220
|
+
await (0, utils_js_1.asyncLoop)(N, asyncTick, (i) => {
|
221
|
+
// First u32 of the last 64-byte block (u32 is LE)
|
222
|
+
const j = B32[Pi + blockSize32 - 16] % N; // j = Integrify(X) % iterations
|
223
|
+
for (let k = 0; k < blockSize32; k++)
|
224
|
+
tmp[k] = B32[Pi + k] ^ V[j * blockSize32 + k]; // tmp = B ^ V[j]
|
225
|
+
BlockMix(tmp, 0, B32, Pi, r); // B = BlockMix(B ^ V[j])
|
226
|
+
blockMixCb();
|
227
|
+
});
|
228
|
+
}
|
229
|
+
return scryptOutput(password, dkLen, B, V, tmp);
|
230
|
+
}
|
231
|
+
scrypt$1.scryptAsync = scryptAsync;
|
232
|
+
|
233
|
+
export { scrypt$1 as default };
|
@@ -0,0 +1,133 @@
|
|
1
|
+
import { __exports as sha256 } from '../../../../../_virtual/sha2562.js';
|
2
|
+
import './_sha2.js';
|
3
|
+
import './utils.js';
|
4
|
+
import { __exports as _sha2 } from '../../../../../_virtual/_sha2.js';
|
5
|
+
import { __exports as utils } from '../../../../../_virtual/utils.js';
|
6
|
+
|
7
|
+
Object.defineProperty(sha256, "__esModule", { value: true });
|
8
|
+
sha256.sha224 = sha256.sha256 = undefined;
|
9
|
+
const _sha2_js_1 = _sha2;
|
10
|
+
const utils_js_1 = utils;
|
11
|
+
// Choice: a ? b : c
|
12
|
+
const Chi = (a, b, c) => (a & b) ^ (~a & c);
|
13
|
+
// Majority function, true if any two inpust is true
|
14
|
+
const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
|
15
|
+
// Round constants:
|
16
|
+
// first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
|
17
|
+
// prettier-ignore
|
18
|
+
const SHA256_K = new Uint32Array([
|
19
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
20
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
21
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
22
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
23
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
24
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
25
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
26
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
27
|
+
]);
|
28
|
+
// Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
|
29
|
+
// prettier-ignore
|
30
|
+
const IV = new Uint32Array([
|
31
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
32
|
+
]);
|
33
|
+
// Temporary buffer, not used to store anything between runs
|
34
|
+
// Named this way because it matches specification.
|
35
|
+
const SHA256_W = new Uint32Array(64);
|
36
|
+
class SHA256 extends _sha2_js_1.SHA2 {
|
37
|
+
constructor() {
|
38
|
+
super(64, 32, 8, false);
|
39
|
+
// We cannot use array here since array allows indexing by variable
|
40
|
+
// which means optimizer/compiler cannot use registers.
|
41
|
+
this.A = IV[0] | 0;
|
42
|
+
this.B = IV[1] | 0;
|
43
|
+
this.C = IV[2] | 0;
|
44
|
+
this.D = IV[3] | 0;
|
45
|
+
this.E = IV[4] | 0;
|
46
|
+
this.F = IV[5] | 0;
|
47
|
+
this.G = IV[6] | 0;
|
48
|
+
this.H = IV[7] | 0;
|
49
|
+
}
|
50
|
+
get() {
|
51
|
+
const { A, B, C, D, E, F, G, H } = this;
|
52
|
+
return [A, B, C, D, E, F, G, H];
|
53
|
+
}
|
54
|
+
// prettier-ignore
|
55
|
+
set(A, B, C, D, E, F, G, H) {
|
56
|
+
this.A = A | 0;
|
57
|
+
this.B = B | 0;
|
58
|
+
this.C = C | 0;
|
59
|
+
this.D = D | 0;
|
60
|
+
this.E = E | 0;
|
61
|
+
this.F = F | 0;
|
62
|
+
this.G = G | 0;
|
63
|
+
this.H = H | 0;
|
64
|
+
}
|
65
|
+
process(view, offset) {
|
66
|
+
// Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
|
67
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
68
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
69
|
+
for (let i = 16; i < 64; i++) {
|
70
|
+
const W15 = SHA256_W[i - 15];
|
71
|
+
const W2 = SHA256_W[i - 2];
|
72
|
+
const s0 = (0, utils_js_1.rotr)(W15, 7) ^ (0, utils_js_1.rotr)(W15, 18) ^ (W15 >>> 3);
|
73
|
+
const s1 = (0, utils_js_1.rotr)(W2, 17) ^ (0, utils_js_1.rotr)(W2, 19) ^ (W2 >>> 10);
|
74
|
+
SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
|
75
|
+
}
|
76
|
+
// Compression function main loop, 64 rounds
|
77
|
+
let { A, B, C, D, E, F, G, H } = this;
|
78
|
+
for (let i = 0; i < 64; i++) {
|
79
|
+
const sigma1 = (0, utils_js_1.rotr)(E, 6) ^ (0, utils_js_1.rotr)(E, 11) ^ (0, utils_js_1.rotr)(E, 25);
|
80
|
+
const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
|
81
|
+
const sigma0 = (0, utils_js_1.rotr)(A, 2) ^ (0, utils_js_1.rotr)(A, 13) ^ (0, utils_js_1.rotr)(A, 22);
|
82
|
+
const T2 = (sigma0 + Maj(A, B, C)) | 0;
|
83
|
+
H = G;
|
84
|
+
G = F;
|
85
|
+
F = E;
|
86
|
+
E = (D + T1) | 0;
|
87
|
+
D = C;
|
88
|
+
C = B;
|
89
|
+
B = A;
|
90
|
+
A = (T1 + T2) | 0;
|
91
|
+
}
|
92
|
+
// Add the compressed chunk to the current hash value
|
93
|
+
A = (A + this.A) | 0;
|
94
|
+
B = (B + this.B) | 0;
|
95
|
+
C = (C + this.C) | 0;
|
96
|
+
D = (D + this.D) | 0;
|
97
|
+
E = (E + this.E) | 0;
|
98
|
+
F = (F + this.F) | 0;
|
99
|
+
G = (G + this.G) | 0;
|
100
|
+
H = (H + this.H) | 0;
|
101
|
+
this.set(A, B, C, D, E, F, G, H);
|
102
|
+
}
|
103
|
+
roundClean() {
|
104
|
+
SHA256_W.fill(0);
|
105
|
+
}
|
106
|
+
destroy() {
|
107
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
108
|
+
this.buffer.fill(0);
|
109
|
+
}
|
110
|
+
}
|
111
|
+
// Constants from https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
|
112
|
+
class SHA224 extends SHA256 {
|
113
|
+
constructor() {
|
114
|
+
super();
|
115
|
+
this.A = 0xc1059ed8 | 0;
|
116
|
+
this.B = 0x367cd507 | 0;
|
117
|
+
this.C = 0x3070dd17 | 0;
|
118
|
+
this.D = 0xf70e5939 | 0;
|
119
|
+
this.E = 0xffc00b31 | 0;
|
120
|
+
this.F = 0x68581511 | 0;
|
121
|
+
this.G = 0x64f98fa7 | 0;
|
122
|
+
this.H = 0xbefa4fa4 | 0;
|
123
|
+
this.outputLen = 28;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
/**
|
127
|
+
* SHA2-256 hash function
|
128
|
+
* @param message - data that would be hashed
|
129
|
+
*/
|
130
|
+
sha256.sha256 = (0, utils_js_1.wrapConstructor)(() => new SHA256());
|
131
|
+
sha256.sha224 = (0, utils_js_1.wrapConstructor)(() => new SHA224());
|
132
|
+
|
133
|
+
export { sha256 as default };
|