@waku/rln 0.1.3-f6d5deb → 0.1.4-29a4c3f.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -186
- package/bundle/_virtual/__node-resolve_empty.js +6 -0
- package/bundle/_virtual/_assert.js +3 -0
- package/bundle/_virtual/_commonjs-dynamic-modules.js +5 -0
- package/bundle/_virtual/_commonjsHelpers.js +32 -0
- package/bundle/_virtual/_node-resolve_empty.js +3 -0
- package/bundle/_virtual/_sha2.js +3 -0
- package/bundle/_virtual/_u64.js +3 -0
- package/bundle/_virtual/aes.js +3 -0
- package/bundle/_virtual/bn.js +3 -0
- package/bundle/_virtual/browser.js +3 -0
- package/bundle/_virtual/checksum.js +3 -0
- package/bundle/_virtual/cipher.js +3 -0
- package/bundle/_virtual/class.js +3 -0
- package/bundle/_virtual/common.js +3 -0
- package/bundle/_virtual/common2.js +3 -0
- package/bundle/_virtual/cryptoBrowser.js +3 -0
- package/bundle/_virtual/functional.js +3 -0
- package/bundle/_virtual/hash.js +3 -0
- package/bundle/_virtual/hmac.js +3 -0
- package/bundle/_virtual/index.js +3 -0
- package/bundle/_virtual/index2.js +6 -0
- package/bundle/_virtual/inherits_browser.js +3 -0
- package/bundle/_virtual/kdf.js +3 -0
- package/bundle/_virtual/lodash.js +3 -0
- package/bundle/_virtual/password.js +3 -0
- package/bundle/_virtual/pbkdf2.js +3 -0
- package/bundle/_virtual/pbkdf22.js +3 -0
- package/bundle/_virtual/random.js +3 -0
- package/bundle/_virtual/ripemd.js +3 -0
- package/bundle/_virtual/schema-validation-generated.js +3 -0
- package/bundle/_virtual/schema-validation.js +3 -0
- package/bundle/_virtual/scrypt.js +3 -0
- package/bundle/_virtual/scrypt2.js +3 -0
- package/bundle/_virtual/sha.js +3 -0
- package/bundle/_virtual/sha256.js +3 -0
- package/bundle/_virtual/sha2562.js +3 -0
- package/bundle/_virtual/sha3.js +3 -0
- package/bundle/_virtual/sha512.js +3 -0
- package/bundle/_virtual/types.js +3 -0
- package/bundle/_virtual/utils.js +3 -0
- package/bundle/_virtual/utils2.js +3 -0
- package/bundle/_virtual/utils3.js +3 -0
- package/bundle/index.js +12 -74804
- package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +96 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +148 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +20 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +210 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +18 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +30 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +26 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +22 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +43 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +19 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +58 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +854 -0
- package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +609 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +66 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +302 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +110 -0
- package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +20 -0
- package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +287 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +402 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +3 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +8 -0
- package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +893 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +256 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +36 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +135 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +8 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +64 -0
- package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +443 -0
- package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +8 -0
- package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +660 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +352 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +248 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +127 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +2007 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +422 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +674 -0
- package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +132 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +120 -0
- package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +8 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +2430 -0
- package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +76 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +219 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +279 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +3 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +69 -0
- package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +404 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/convert.js +15 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/multiaddr.js +20 -0
- package/bundle/node_modules/@multiformats/multiaddr/dist/src/protocols-table.js +92 -0
- package/bundle/node_modules/@noble/hashes/esm/_assert.js +37 -0
- package/bundle/node_modules/@noble/hashes/esm/_md.js +132 -0
- package/bundle/node_modules/@noble/hashes/esm/_u64.js +29 -0
- package/bundle/node_modules/@noble/hashes/esm/sha256.js +113 -0
- package/bundle/node_modules/@noble/hashes/esm/sha3.js +210 -0
- package/bundle/node_modules/@noble/hashes/esm/utils.js +144 -0
- package/bundle/node_modules/@waku/zerokit-rln-wasm/rln_wasm.js +756 -0
- package/bundle/node_modules/bech32/index.js +187 -0
- package/bundle/node_modules/bn.js/lib/bn.js +3361 -0
- package/bundle/node_modules/debug/src/browser.js +283 -0
- package/bundle/node_modules/debug/src/common.js +295 -0
- package/bundle/node_modules/ethereum-cryptography/esm/keccak.js +10 -0
- package/bundle/node_modules/ethereum-cryptography/esm/sha256.js +6 -0
- package/bundle/node_modules/ethereum-cryptography/esm/utils.js +24 -0
- package/bundle/node_modules/hash.js/lib/hash/common.js +97 -0
- package/bundle/node_modules/hash.js/lib/hash/hmac.js +51 -0
- package/bundle/node_modules/hash.js/lib/hash/ripemd.js +152 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/1.js +81 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/224.js +33 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/256.js +113 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/384.js +39 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/512.js +336 -0
- package/bundle/node_modules/hash.js/lib/hash/sha/common.js +53 -0
- package/bundle/node_modules/hash.js/lib/hash/sha.js +14 -0
- package/bundle/node_modules/hash.js/lib/hash/utils.js +282 -0
- package/bundle/node_modules/hash.js/lib/hash.js +33 -0
- package/bundle/node_modules/inherits/inherits_browser.js +33 -0
- package/bundle/node_modules/it-length-prefixed/dist/src/decode.js +6 -0
- package/bundle/node_modules/lodash/lodash.js +17207 -0
- package/bundle/node_modules/minimalistic-assert/index.js +13 -0
- package/bundle/node_modules/ms/index.js +172 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base.js +205 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base10.js +9 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base16.js +16 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base2.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base256emoji.js +41 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base32.js +58 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base36.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base58.js +14 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base64.js +28 -0
- package/bundle/node_modules/multiformats/dist/src/bases/base8.js +10 -0
- package/bundle/node_modules/multiformats/dist/src/bases/identity.js +11 -0
- package/bundle/node_modules/multiformats/dist/src/basics.js +15 -0
- package/bundle/node_modules/multiformats/dist/src/bytes.js +18 -0
- package/bundle/node_modules/multiformats/dist/src/codecs/json.js +2 -0
- package/bundle/node_modules/multiformats/dist/src/vendor/base-x.js +170 -0
- package/bundle/node_modules/protons-runtime/dist/src/codec.js +20 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/enum.js +24 -0
- package/bundle/node_modules/protons-runtime/dist/src/codecs/message.js +7 -0
- package/bundle/node_modules/protons-runtime/dist/src/decode.js +8 -0
- package/bundle/node_modules/protons-runtime/dist/src/encode.js +11 -0
- package/bundle/node_modules/protons-runtime/dist/src/index.js +30 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/float.js +54 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/longbits.js +175 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/pool.js +28 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/reader.js +367 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/utf8.js +99 -0
- package/bundle/node_modules/protons-runtime/dist/src/utils/writer.js +438 -0
- package/bundle/node_modules/uint8-varint/dist/src/index.js +124 -0
- package/bundle/node_modules/uint8arrays/dist/src/alloc.js +17 -0
- package/bundle/node_modules/uint8arrays/dist/src/from-string.js +19 -0
- package/bundle/node_modules/uint8arrays/dist/src/util/bases.js +49 -0
- package/bundle/packages/core/dist/lib/connection_manager/connection_manager.js +21 -0
- package/bundle/packages/core/dist/lib/connection_manager/keep_alive_manager.js +18 -0
- package/bundle/packages/core/dist/lib/filter/filter.js +27 -0
- package/bundle/packages/core/dist/lib/light_push/light_push.js +27 -0
- package/bundle/packages/core/dist/lib/message/version_0.js +154 -0
- package/bundle/packages/core/dist/lib/metadata/metadata.js +27 -0
- package/bundle/packages/core/dist/lib/store/store.js +27 -0
- package/bundle/packages/interfaces/dist/connection_manager.js +19 -0
- package/bundle/packages/interfaces/dist/constants.js +6 -0
- package/bundle/packages/interfaces/dist/health_indicator.js +12 -0
- package/bundle/packages/interfaces/dist/protocols.js +92 -0
- package/bundle/packages/proto/dist/generated/filter.js +445 -0
- package/bundle/packages/proto/dist/generated/filter_v2.js +424 -0
- package/bundle/packages/proto/dist/generated/light_push.js +389 -0
- package/bundle/packages/proto/dist/generated/message.js +213 -0
- package/bundle/packages/proto/dist/generated/metadata.js +130 -0
- package/bundle/packages/proto/dist/generated/peer_exchange.js +209 -0
- package/bundle/packages/proto/dist/generated/sds_message.js +105 -0
- package/bundle/packages/proto/dist/generated/store_v3.js +490 -0
- package/bundle/packages/proto/dist/generated/topic_only_message.js +61 -0
- package/bundle/packages/rln/dist/codec.js +93 -0
- package/bundle/packages/rln/dist/contract/abi.js +394 -0
- package/bundle/packages/rln/dist/contract/constants.js +27 -0
- package/bundle/packages/rln/dist/contract/rln_contract.js +438 -0
- package/bundle/packages/rln/dist/create.js +9 -0
- package/bundle/packages/rln/dist/identity.js +30 -0
- package/bundle/packages/rln/dist/keystore/cipher.js +31 -0
- package/bundle/packages/rln/dist/keystore/credential_validation_generated.js +119 -0
- package/bundle/packages/rln/dist/keystore/keystore.js +223 -0
- package/bundle/packages/rln/dist/keystore/keystore_validation_generated.js +74 -0
- package/bundle/packages/rln/dist/keystore/schema_validator.js +20 -0
- package/bundle/packages/rln/dist/message.js +51 -0
- package/bundle/packages/rln/dist/proof.js +54 -0
- package/bundle/packages/rln/dist/resources/verification_key.js +112 -0
- package/bundle/packages/rln/dist/resources/witness_calculator.js +330 -0
- package/bundle/packages/rln/dist/rln.js +220 -0
- package/bundle/packages/rln/dist/root_tracker.js +76 -0
- package/bundle/packages/rln/dist/utils/bytes.js +65 -0
- package/bundle/packages/rln/dist/utils/epoch.js +39 -0
- package/bundle/packages/rln/dist/utils/hash.js +10 -0
- package/bundle/packages/rln/dist/utils/metamask.js +14 -0
- package/bundle/packages/rln/dist/zerokit.js +128 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/checksum.js +52 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/cipher.js +65 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/class.js +99 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/functional.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/index.js +28 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/kdf.js +78 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/password.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation-generated.js +1253 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/schema-validation.js +40 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/lib/types.js +5 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/aes.js +103 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/pbkdf2.js +41 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/random.js +17 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/scrypt.js +23 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/sha256.js +12 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/ethereum-cryptography/utils.js +77 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/index.js +9 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/md5.js +215 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/nil.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/parse.js +35 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/regex.js +3 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/rng.js +21 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/sha1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/stringify.js +31 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v1.js +96 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v3.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v35.js +66 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v4.js +24 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/v5.js +6 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/validate.js +7 -0
- package/bundle/packages/rln/node_modules/@chainsafe/bls-keystore/node_modules/uuid/dist/esm-browser/version.js +11 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_assert.js +52 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_sha2.js +124 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/_u64.js +71 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/cryptoBrowser.js +10 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/hmac.js +88 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/pbkdf2.js +99 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/scrypt.js +233 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha256.js +133 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/sha512.js +243 -0
- package/bundle/packages/rln/node_modules/@noble/hashes/utils.js +167 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/native.js +4 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/rng.js +13 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/stringify.js +28 -0
- package/bundle/packages/rln/node_modules/uuid/dist/esm-browser/v4.js +19 -0
- package/bundle/packages/utils/dist/bytes/index.js +44 -0
- package/bundle/packages/utils/dist/common/sharding/index.js +91 -0
- package/bundle/packages/utils/dist/logger/index.js +31 -0
- package/bundle/resources/verification_key.d.ts +13 -0
- package/bundle/resources/verification_key.js +112 -0
- package/bundle/resources/witness_calculator.d.ts +11 -0
- package/bundle/resources/witness_calculator.js +328 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/codec.d.ts +5 -5
- package/dist/codec.js +6 -6
- package/dist/codec.js.map +1 -1
- package/dist/contract/abi.d.ts +42 -0
- package/dist/contract/abi.js +393 -0
- package/dist/contract/abi.js.map +1 -0
- package/dist/contract/constants.d.ts +59 -3
- package/dist/contract/constants.js +21 -63
- package/dist/contract/constants.js.map +1 -1
- package/dist/contract/rln_contract.d.ts +98 -17
- package/dist/contract/rln_contract.js +292 -71
- package/dist/contract/rln_contract.js.map +1 -1
- package/dist/identity.js +5 -2
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/keystore/cipher.js +3 -3
- package/dist/keystore/cipher.js.map +1 -1
- package/dist/keystore/credential_validation_generated.js.map +1 -1
- package/dist/keystore/keystore.js +4 -4
- package/dist/keystore/keystore.js.map +1 -1
- package/dist/keystore/keystore_validation_generated.js.map +1 -1
- package/dist/message.js +3 -3
- package/dist/message.js.map +1 -1
- package/dist/proof.js +3 -2
- package/dist/proof.js.map +1 -1
- package/dist/resources/verification_key.d.ts +12 -11
- package/dist/resources/verification_key.js +103 -103
- package/dist/resources/witness_calculator.d.ts +10 -15
- package/dist/resources/witness_calculator.js +302 -265
- package/dist/rln.d.ts +5 -1
- package/dist/rln.js +56 -28
- package/dist/rln.js.map +1 -1
- package/dist/root_tracker.js.map +1 -1
- package/dist/utils/epoch.js +5 -5
- package/dist/utils/epoch.js.map +1 -1
- package/dist/zerokit.d.ts +13 -9
- package/dist/zerokit.js +40 -20
- package/dist/zerokit.js.map +1 -1
- package/package.json +1 -146
- package/src/codec.ts +26 -22
- package/src/contract/abi.ts +392 -0
- package/src/contract/constants.ts +28 -0
- package/src/contract/index.ts +2 -0
- package/src/contract/rln_contract.ts +686 -0
- package/src/identity.ts +8 -4
- package/src/index.ts +4 -9
- package/src/keystore/cipher.ts +54 -0
- package/src/keystore/credential_validation_generated.ts +7 -0
- package/src/keystore/index.ts +5 -0
- package/src/keystore/keystore.ts +330 -0
- package/src/keystore/keystore_validation_generated.ts +7 -0
- package/src/keystore/schema_validator.ts +34 -0
- package/src/keystore/types.ts +36 -0
- package/src/message.ts +10 -10
- package/src/proof.ts +13 -11
- package/src/resources/verification_key.d.ts +13 -0
- package/src/resources/witness_calculator.d.ts +11 -0
- package/src/rln.ts +76 -31
- package/src/root_tracker.ts +7 -6
- package/src/utils/bytes.ts +84 -0
- package/src/utils/epoch.ts +30 -0
- package/src/utils/hash.ts +15 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/metamask.ts +17 -0
- package/src/zerokit.ts +95 -33
- package/bundle/assets/rln_wasm_bg-a503e304.wasm +0 -0
- package/dist/resources/verification_key.js.map +0 -1
- package/dist/resources/witness_calculator.js.map +0 -1
- /package/bundle/{assets/rln-6ded2896.wasm → resources/rln.wasm} +0 -0
- /package/bundle/{assets/rln_final-8b299152.zkey → resources/rln_final.zkey} +0 -0
@@ -0,0 +1,302 @@
|
|
1
|
+
import { defineReadOnly, resolveProperties, shallowCopy } from '../../properties/lib.esm/index.js';
|
2
|
+
import { Logger } from '../../logger/lib.esm/index.js';
|
3
|
+
import { version } from './_version.js';
|
4
|
+
|
5
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
12
|
+
});
|
13
|
+
};
|
14
|
+
const logger = new Logger(version);
|
15
|
+
const allowedTransactionKeys = [
|
16
|
+
"accessList", "ccipReadEnabled", "chainId", "customData", "data", "from", "gasLimit", "gasPrice", "maxFeePerGas", "maxPriorityFeePerGas", "nonce", "to", "type", "value"
|
17
|
+
];
|
18
|
+
const forwardErrors = [
|
19
|
+
Logger.errors.INSUFFICIENT_FUNDS,
|
20
|
+
Logger.errors.NONCE_EXPIRED,
|
21
|
+
Logger.errors.REPLACEMENT_UNDERPRICED,
|
22
|
+
];
|
23
|
+
class Signer {
|
24
|
+
///////////////////
|
25
|
+
// Sub-classes MUST call super
|
26
|
+
constructor() {
|
27
|
+
logger.checkAbstract(new.target, Signer);
|
28
|
+
defineReadOnly(this, "_isSigner", true);
|
29
|
+
}
|
30
|
+
///////////////////
|
31
|
+
// Sub-classes MAY override these
|
32
|
+
getBalance(blockTag) {
|
33
|
+
return __awaiter(this, undefined, undefined, function* () {
|
34
|
+
this._checkProvider("getBalance");
|
35
|
+
return yield this.provider.getBalance(this.getAddress(), blockTag);
|
36
|
+
});
|
37
|
+
}
|
38
|
+
getTransactionCount(blockTag) {
|
39
|
+
return __awaiter(this, undefined, undefined, function* () {
|
40
|
+
this._checkProvider("getTransactionCount");
|
41
|
+
return yield this.provider.getTransactionCount(this.getAddress(), blockTag);
|
42
|
+
});
|
43
|
+
}
|
44
|
+
// Populates "from" if unspecified, and estimates the gas for the transaction
|
45
|
+
estimateGas(transaction) {
|
46
|
+
return __awaiter(this, undefined, undefined, function* () {
|
47
|
+
this._checkProvider("estimateGas");
|
48
|
+
const tx = yield resolveProperties(this.checkTransaction(transaction));
|
49
|
+
return yield this.provider.estimateGas(tx);
|
50
|
+
});
|
51
|
+
}
|
52
|
+
// Populates "from" if unspecified, and calls with the transaction
|
53
|
+
call(transaction, blockTag) {
|
54
|
+
return __awaiter(this, undefined, undefined, function* () {
|
55
|
+
this._checkProvider("call");
|
56
|
+
const tx = yield resolveProperties(this.checkTransaction(transaction));
|
57
|
+
return yield this.provider.call(tx, blockTag);
|
58
|
+
});
|
59
|
+
}
|
60
|
+
// Populates all fields in a transaction, signs it and sends it to the network
|
61
|
+
sendTransaction(transaction) {
|
62
|
+
return __awaiter(this, undefined, undefined, function* () {
|
63
|
+
this._checkProvider("sendTransaction");
|
64
|
+
const tx = yield this.populateTransaction(transaction);
|
65
|
+
const signedTx = yield this.signTransaction(tx);
|
66
|
+
return yield this.provider.sendTransaction(signedTx);
|
67
|
+
});
|
68
|
+
}
|
69
|
+
getChainId() {
|
70
|
+
return __awaiter(this, undefined, undefined, function* () {
|
71
|
+
this._checkProvider("getChainId");
|
72
|
+
const network = yield this.provider.getNetwork();
|
73
|
+
return network.chainId;
|
74
|
+
});
|
75
|
+
}
|
76
|
+
getGasPrice() {
|
77
|
+
return __awaiter(this, undefined, undefined, function* () {
|
78
|
+
this._checkProvider("getGasPrice");
|
79
|
+
return yield this.provider.getGasPrice();
|
80
|
+
});
|
81
|
+
}
|
82
|
+
getFeeData() {
|
83
|
+
return __awaiter(this, undefined, undefined, function* () {
|
84
|
+
this._checkProvider("getFeeData");
|
85
|
+
return yield this.provider.getFeeData();
|
86
|
+
});
|
87
|
+
}
|
88
|
+
resolveName(name) {
|
89
|
+
return __awaiter(this, undefined, undefined, function* () {
|
90
|
+
this._checkProvider("resolveName");
|
91
|
+
return yield this.provider.resolveName(name);
|
92
|
+
});
|
93
|
+
}
|
94
|
+
// Checks a transaction does not contain invalid keys and if
|
95
|
+
// no "from" is provided, populates it.
|
96
|
+
// - does NOT require a provider
|
97
|
+
// - adds "from" is not present
|
98
|
+
// - returns a COPY (safe to mutate the result)
|
99
|
+
// By default called from: (overriding these prevents it)
|
100
|
+
// - call
|
101
|
+
// - estimateGas
|
102
|
+
// - populateTransaction (and therefor sendTransaction)
|
103
|
+
checkTransaction(transaction) {
|
104
|
+
for (const key in transaction) {
|
105
|
+
if (allowedTransactionKeys.indexOf(key) === -1) {
|
106
|
+
logger.throwArgumentError("invalid transaction key: " + key, "transaction", transaction);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
const tx = shallowCopy(transaction);
|
110
|
+
if (tx.from == null) {
|
111
|
+
tx.from = this.getAddress();
|
112
|
+
}
|
113
|
+
else {
|
114
|
+
// Make sure any provided address matches this signer
|
115
|
+
tx.from = Promise.all([
|
116
|
+
Promise.resolve(tx.from),
|
117
|
+
this.getAddress()
|
118
|
+
]).then((result) => {
|
119
|
+
if (result[0].toLowerCase() !== result[1].toLowerCase()) {
|
120
|
+
logger.throwArgumentError("from address mismatch", "transaction", transaction);
|
121
|
+
}
|
122
|
+
return result[0];
|
123
|
+
});
|
124
|
+
}
|
125
|
+
return tx;
|
126
|
+
}
|
127
|
+
// Populates ALL keys for a transaction and checks that "from" matches
|
128
|
+
// this Signer. Should be used by sendTransaction but NOT by signTransaction.
|
129
|
+
// By default called from: (overriding these prevents it)
|
130
|
+
// - sendTransaction
|
131
|
+
//
|
132
|
+
// Notes:
|
133
|
+
// - We allow gasPrice for EIP-1559 as long as it matches maxFeePerGas
|
134
|
+
populateTransaction(transaction) {
|
135
|
+
return __awaiter(this, undefined, undefined, function* () {
|
136
|
+
const tx = yield resolveProperties(this.checkTransaction(transaction));
|
137
|
+
if (tx.to != null) {
|
138
|
+
tx.to = Promise.resolve(tx.to).then((to) => __awaiter(this, undefined, undefined, function* () {
|
139
|
+
if (to == null) {
|
140
|
+
return null;
|
141
|
+
}
|
142
|
+
const address = yield this.resolveName(to);
|
143
|
+
if (address == null) {
|
144
|
+
logger.throwArgumentError("provided ENS name resolves to null", "tx.to", to);
|
145
|
+
}
|
146
|
+
return address;
|
147
|
+
}));
|
148
|
+
// Prevent this error from causing an UnhandledPromiseException
|
149
|
+
tx.to.catch((error) => { });
|
150
|
+
}
|
151
|
+
// Do not allow mixing pre-eip-1559 and eip-1559 properties
|
152
|
+
const hasEip1559 = (tx.maxFeePerGas != null || tx.maxPriorityFeePerGas != null);
|
153
|
+
if (tx.gasPrice != null && (tx.type === 2 || hasEip1559)) {
|
154
|
+
logger.throwArgumentError("eip-1559 transaction do not support gasPrice", "transaction", transaction);
|
155
|
+
}
|
156
|
+
else if ((tx.type === 0 || tx.type === 1) && hasEip1559) {
|
157
|
+
logger.throwArgumentError("pre-eip-1559 transaction do not support maxFeePerGas/maxPriorityFeePerGas", "transaction", transaction);
|
158
|
+
}
|
159
|
+
if ((tx.type === 2 || tx.type == null) && (tx.maxFeePerGas != null && tx.maxPriorityFeePerGas != null)) {
|
160
|
+
// Fully-formed EIP-1559 transaction (skip getFeeData)
|
161
|
+
tx.type = 2;
|
162
|
+
}
|
163
|
+
else if (tx.type === 0 || tx.type === 1) {
|
164
|
+
// Explicit Legacy or EIP-2930 transaction
|
165
|
+
// Populate missing gasPrice
|
166
|
+
if (tx.gasPrice == null) {
|
167
|
+
tx.gasPrice = this.getGasPrice();
|
168
|
+
}
|
169
|
+
}
|
170
|
+
else {
|
171
|
+
// We need to get fee data to determine things
|
172
|
+
const feeData = yield this.getFeeData();
|
173
|
+
if (tx.type == null) {
|
174
|
+
// We need to auto-detect the intended type of this transaction...
|
175
|
+
if (feeData.maxFeePerGas != null && feeData.maxPriorityFeePerGas != null) {
|
176
|
+
// The network supports EIP-1559!
|
177
|
+
// Upgrade transaction from null to eip-1559
|
178
|
+
tx.type = 2;
|
179
|
+
if (tx.gasPrice != null) {
|
180
|
+
// Using legacy gasPrice property on an eip-1559 network,
|
181
|
+
// so use gasPrice as both fee properties
|
182
|
+
const gasPrice = tx.gasPrice;
|
183
|
+
delete tx.gasPrice;
|
184
|
+
tx.maxFeePerGas = gasPrice;
|
185
|
+
tx.maxPriorityFeePerGas = gasPrice;
|
186
|
+
}
|
187
|
+
else {
|
188
|
+
// Populate missing fee data
|
189
|
+
if (tx.maxFeePerGas == null) {
|
190
|
+
tx.maxFeePerGas = feeData.maxFeePerGas;
|
191
|
+
}
|
192
|
+
if (tx.maxPriorityFeePerGas == null) {
|
193
|
+
tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
|
194
|
+
}
|
195
|
+
}
|
196
|
+
}
|
197
|
+
else if (feeData.gasPrice != null) {
|
198
|
+
// Network doesn't support EIP-1559...
|
199
|
+
// ...but they are trying to use EIP-1559 properties
|
200
|
+
if (hasEip1559) {
|
201
|
+
logger.throwError("network does not support EIP-1559", Logger.errors.UNSUPPORTED_OPERATION, {
|
202
|
+
operation: "populateTransaction"
|
203
|
+
});
|
204
|
+
}
|
205
|
+
// Populate missing fee data
|
206
|
+
if (tx.gasPrice == null) {
|
207
|
+
tx.gasPrice = feeData.gasPrice;
|
208
|
+
}
|
209
|
+
// Explicitly set untyped transaction to legacy
|
210
|
+
tx.type = 0;
|
211
|
+
}
|
212
|
+
else {
|
213
|
+
// getFeeData has failed us.
|
214
|
+
logger.throwError("failed to get consistent fee data", Logger.errors.UNSUPPORTED_OPERATION, {
|
215
|
+
operation: "signer.getFeeData"
|
216
|
+
});
|
217
|
+
}
|
218
|
+
}
|
219
|
+
else if (tx.type === 2) {
|
220
|
+
// Explicitly using EIP-1559
|
221
|
+
// Populate missing fee data
|
222
|
+
if (tx.maxFeePerGas == null) {
|
223
|
+
tx.maxFeePerGas = feeData.maxFeePerGas;
|
224
|
+
}
|
225
|
+
if (tx.maxPriorityFeePerGas == null) {
|
226
|
+
tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
|
227
|
+
}
|
228
|
+
}
|
229
|
+
}
|
230
|
+
if (tx.nonce == null) {
|
231
|
+
tx.nonce = this.getTransactionCount("pending");
|
232
|
+
}
|
233
|
+
if (tx.gasLimit == null) {
|
234
|
+
tx.gasLimit = this.estimateGas(tx).catch((error) => {
|
235
|
+
if (forwardErrors.indexOf(error.code) >= 0) {
|
236
|
+
throw error;
|
237
|
+
}
|
238
|
+
return logger.throwError("cannot estimate gas; transaction may fail or may require manual gas limit", Logger.errors.UNPREDICTABLE_GAS_LIMIT, {
|
239
|
+
error: error,
|
240
|
+
tx: tx
|
241
|
+
});
|
242
|
+
});
|
243
|
+
}
|
244
|
+
if (tx.chainId == null) {
|
245
|
+
tx.chainId = this.getChainId();
|
246
|
+
}
|
247
|
+
else {
|
248
|
+
tx.chainId = Promise.all([
|
249
|
+
Promise.resolve(tx.chainId),
|
250
|
+
this.getChainId()
|
251
|
+
]).then((results) => {
|
252
|
+
if (results[1] !== 0 && results[0] !== results[1]) {
|
253
|
+
logger.throwArgumentError("chainId address mismatch", "transaction", transaction);
|
254
|
+
}
|
255
|
+
return results[0];
|
256
|
+
});
|
257
|
+
}
|
258
|
+
return yield resolveProperties(tx);
|
259
|
+
});
|
260
|
+
}
|
261
|
+
///////////////////
|
262
|
+
// Sub-classes SHOULD leave these alone
|
263
|
+
_checkProvider(operation) {
|
264
|
+
if (!this.provider) {
|
265
|
+
logger.throwError("missing provider", Logger.errors.UNSUPPORTED_OPERATION, {
|
266
|
+
operation: (operation || "_checkProvider")
|
267
|
+
});
|
268
|
+
}
|
269
|
+
}
|
270
|
+
static isSigner(value) {
|
271
|
+
return !!(value && value._isSigner);
|
272
|
+
}
|
273
|
+
}
|
274
|
+
class VoidSigner extends Signer {
|
275
|
+
constructor(address, provider) {
|
276
|
+
super();
|
277
|
+
defineReadOnly(this, "address", address);
|
278
|
+
defineReadOnly(this, "provider", provider || null);
|
279
|
+
}
|
280
|
+
getAddress() {
|
281
|
+
return Promise.resolve(this.address);
|
282
|
+
}
|
283
|
+
_fail(message, operation) {
|
284
|
+
return Promise.resolve().then(() => {
|
285
|
+
logger.throwError(message, Logger.errors.UNSUPPORTED_OPERATION, { operation: operation });
|
286
|
+
});
|
287
|
+
}
|
288
|
+
signMessage(message) {
|
289
|
+
return this._fail("VoidSigner cannot sign messages", "signMessage");
|
290
|
+
}
|
291
|
+
signTransaction(transaction) {
|
292
|
+
return this._fail("VoidSigner cannot sign transactions", "signTransaction");
|
293
|
+
}
|
294
|
+
_signTypedData(domain, types, value) {
|
295
|
+
return this._fail("VoidSigner cannot sign typed data", "signTypedData");
|
296
|
+
}
|
297
|
+
connect(provider) {
|
298
|
+
return new VoidSigner(this.address, provider);
|
299
|
+
}
|
300
|
+
}
|
301
|
+
|
302
|
+
export { Signer, VoidSigner };
|
@@ -0,0 +1,110 @@
|
|
1
|
+
import { stripZeros, arrayify, hexDataSlice, isHexString } from '../../bytes/lib.esm/index.js';
|
2
|
+
import { keccak256 } from '../../keccak256/lib.esm/index.js';
|
3
|
+
import { encode } from '../../rlp/lib.esm/index.js';
|
4
|
+
import { Logger } from '../../logger/lib.esm/index.js';
|
5
|
+
import { version } from './_version.js';
|
6
|
+
import { _base36To16, BigNumber } from '../../bignumber/lib.esm/bignumber.js';
|
7
|
+
|
8
|
+
const logger = new Logger(version);
|
9
|
+
function getChecksumAddress(address) {
|
10
|
+
if (!isHexString(address, 20)) {
|
11
|
+
logger.throwArgumentError("invalid address", "address", address);
|
12
|
+
}
|
13
|
+
address = address.toLowerCase();
|
14
|
+
const chars = address.substring(2).split("");
|
15
|
+
const expanded = new Uint8Array(40);
|
16
|
+
for (let i = 0; i < 40; i++) {
|
17
|
+
expanded[i] = chars[i].charCodeAt(0);
|
18
|
+
}
|
19
|
+
const hashed = arrayify(keccak256(expanded));
|
20
|
+
for (let i = 0; i < 40; i += 2) {
|
21
|
+
if ((hashed[i >> 1] >> 4) >= 8) {
|
22
|
+
chars[i] = chars[i].toUpperCase();
|
23
|
+
}
|
24
|
+
if ((hashed[i >> 1] & 0x0f) >= 8) {
|
25
|
+
chars[i + 1] = chars[i + 1].toUpperCase();
|
26
|
+
}
|
27
|
+
}
|
28
|
+
return "0x" + chars.join("");
|
29
|
+
}
|
30
|
+
// Shims for environments that are missing some required constants and functions
|
31
|
+
const MAX_SAFE_INTEGER = 0x1fffffffffffff;
|
32
|
+
function log10(x) {
|
33
|
+
if (Math.log10) {
|
34
|
+
return Math.log10(x);
|
35
|
+
}
|
36
|
+
return Math.log(x) / Math.LN10;
|
37
|
+
}
|
38
|
+
// See: https://en.wikipedia.org/wiki/International_Bank_Account_Number
|
39
|
+
// Create lookup table
|
40
|
+
const ibanLookup = {};
|
41
|
+
for (let i = 0; i < 10; i++) {
|
42
|
+
ibanLookup[String(i)] = String(i);
|
43
|
+
}
|
44
|
+
for (let i = 0; i < 26; i++) {
|
45
|
+
ibanLookup[String.fromCharCode(65 + i)] = String(10 + i);
|
46
|
+
}
|
47
|
+
// How many decimal digits can we process? (for 64-bit float, this is 15)
|
48
|
+
const safeDigits = Math.floor(log10(MAX_SAFE_INTEGER));
|
49
|
+
function ibanChecksum(address) {
|
50
|
+
address = address.toUpperCase();
|
51
|
+
address = address.substring(4) + address.substring(0, 2) + "00";
|
52
|
+
let expanded = address.split("").map((c) => { return ibanLookup[c]; }).join("");
|
53
|
+
// Javascript can handle integers safely up to 15 (decimal) digits
|
54
|
+
while (expanded.length >= safeDigits) {
|
55
|
+
let block = expanded.substring(0, safeDigits);
|
56
|
+
expanded = parseInt(block, 10) % 97 + expanded.substring(block.length);
|
57
|
+
}
|
58
|
+
let checksum = String(98 - (parseInt(expanded, 10) % 97));
|
59
|
+
while (checksum.length < 2) {
|
60
|
+
checksum = "0" + checksum;
|
61
|
+
}
|
62
|
+
return checksum;
|
63
|
+
}
|
64
|
+
function getAddress(address) {
|
65
|
+
let result = null;
|
66
|
+
if (typeof (address) !== "string") {
|
67
|
+
logger.throwArgumentError("invalid address", "address", address);
|
68
|
+
}
|
69
|
+
if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
|
70
|
+
// Missing the 0x prefix
|
71
|
+
if (address.substring(0, 2) !== "0x") {
|
72
|
+
address = "0x" + address;
|
73
|
+
}
|
74
|
+
result = getChecksumAddress(address);
|
75
|
+
// It is a checksummed address with a bad checksum
|
76
|
+
if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) && result !== address) {
|
77
|
+
logger.throwArgumentError("bad address checksum", "address", address);
|
78
|
+
}
|
79
|
+
// Maybe ICAP? (we only support direct mode)
|
80
|
+
}
|
81
|
+
else if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) {
|
82
|
+
// It is an ICAP address with a bad checksum
|
83
|
+
if (address.substring(2, 4) !== ibanChecksum(address)) {
|
84
|
+
logger.throwArgumentError("bad icap checksum", "address", address);
|
85
|
+
}
|
86
|
+
result = _base36To16(address.substring(4));
|
87
|
+
while (result.length < 40) {
|
88
|
+
result = "0" + result;
|
89
|
+
}
|
90
|
+
result = getChecksumAddress("0x" + result);
|
91
|
+
}
|
92
|
+
else {
|
93
|
+
logger.throwArgumentError("invalid address", "address", address);
|
94
|
+
}
|
95
|
+
return result;
|
96
|
+
}
|
97
|
+
// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
|
98
|
+
function getContractAddress(transaction) {
|
99
|
+
let from = null;
|
100
|
+
try {
|
101
|
+
from = getAddress(transaction.from);
|
102
|
+
}
|
103
|
+
catch (error) {
|
104
|
+
logger.throwArgumentError("missing from address", "transaction", transaction);
|
105
|
+
}
|
106
|
+
const nonce = stripZeros(arrayify(BigNumber.from(transaction.nonce).toHexString()));
|
107
|
+
return getAddress(hexDataSlice(keccak256(encode([from, nonce])), 12));
|
108
|
+
}
|
109
|
+
|
110
|
+
export { getAddress, getContractAddress };
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { arrayify } from '../../bytes/lib.esm/index.js';
|
2
|
+
|
3
|
+
function decode(textData) {
|
4
|
+
textData = atob(textData);
|
5
|
+
const data = [];
|
6
|
+
for (let i = 0; i < textData.length; i++) {
|
7
|
+
data.push(textData.charCodeAt(i));
|
8
|
+
}
|
9
|
+
return arrayify(data);
|
10
|
+
}
|
11
|
+
function encode(data) {
|
12
|
+
data = arrayify(data);
|
13
|
+
let textData = "";
|
14
|
+
for (let i = 0; i < data.length; i++) {
|
15
|
+
textData += String.fromCharCode(data[i]);
|
16
|
+
}
|
17
|
+
return btoa(textData);
|
18
|
+
}
|
19
|
+
|
20
|
+
export { decode, encode };
|
@@ -0,0 +1,120 @@
|
|
1
|
+
import { arrayify } from '../../bytes/lib.esm/index.js';
|
2
|
+
import { defineReadOnly } from '../../properties/lib.esm/index.js';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* var basex = require("base-x");
|
6
|
+
*
|
7
|
+
* This implementation is heavily based on base-x. The main reason to
|
8
|
+
* deviate was to prevent the dependency of Buffer.
|
9
|
+
*
|
10
|
+
* Contributors:
|
11
|
+
*
|
12
|
+
* base-x encoding
|
13
|
+
* Forked from https://github.com/cryptocoinjs/bs58
|
14
|
+
* Originally written by Mike Hearn for BitcoinJ
|
15
|
+
* Copyright (c) 2011 Google Inc
|
16
|
+
* Ported to JavaScript by Stefan Thomas
|
17
|
+
* Merged Buffer refactorings from base58-native by Stephen Pair
|
18
|
+
* Copyright (c) 2013 BitPay Inc
|
19
|
+
*
|
20
|
+
* The MIT License (MIT)
|
21
|
+
*
|
22
|
+
* Copyright base-x contributors (c) 2016
|
23
|
+
*
|
24
|
+
* Permission is hereby granted, free of charge, to any person obtaining a
|
25
|
+
* copy of this software and associated documentation files (the "Software"),
|
26
|
+
* to deal in the Software without restriction, including without limitation
|
27
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
28
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
29
|
+
* Software is furnished to do so, subject to the following conditions:
|
30
|
+
*
|
31
|
+
* The above copyright notice and this permission notice shall be included in
|
32
|
+
* all copies or substantial portions of the Software.
|
33
|
+
|
34
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
35
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
36
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
37
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
38
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
39
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
40
|
+
* IN THE SOFTWARE.
|
41
|
+
*
|
42
|
+
*/
|
43
|
+
class BaseX {
|
44
|
+
constructor(alphabet) {
|
45
|
+
defineReadOnly(this, "alphabet", alphabet);
|
46
|
+
defineReadOnly(this, "base", alphabet.length);
|
47
|
+
defineReadOnly(this, "_alphabetMap", {});
|
48
|
+
defineReadOnly(this, "_leader", alphabet.charAt(0));
|
49
|
+
// pre-compute lookup table
|
50
|
+
for (let i = 0; i < alphabet.length; i++) {
|
51
|
+
this._alphabetMap[alphabet.charAt(i)] = i;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
encode(value) {
|
55
|
+
let source = arrayify(value);
|
56
|
+
if (source.length === 0) {
|
57
|
+
return "";
|
58
|
+
}
|
59
|
+
let digits = [0];
|
60
|
+
for (let i = 0; i < source.length; ++i) {
|
61
|
+
let carry = source[i];
|
62
|
+
for (let j = 0; j < digits.length; ++j) {
|
63
|
+
carry += digits[j] << 8;
|
64
|
+
digits[j] = carry % this.base;
|
65
|
+
carry = (carry / this.base) | 0;
|
66
|
+
}
|
67
|
+
while (carry > 0) {
|
68
|
+
digits.push(carry % this.base);
|
69
|
+
carry = (carry / this.base) | 0;
|
70
|
+
}
|
71
|
+
}
|
72
|
+
let string = "";
|
73
|
+
// deal with leading zeros
|
74
|
+
for (let k = 0; source[k] === 0 && k < source.length - 1; ++k) {
|
75
|
+
string += this._leader;
|
76
|
+
}
|
77
|
+
// convert digits to a string
|
78
|
+
for (let q = digits.length - 1; q >= 0; --q) {
|
79
|
+
string += this.alphabet[digits[q]];
|
80
|
+
}
|
81
|
+
return string;
|
82
|
+
}
|
83
|
+
decode(value) {
|
84
|
+
if (typeof (value) !== "string") {
|
85
|
+
throw new TypeError("Expected String");
|
86
|
+
}
|
87
|
+
let bytes = [];
|
88
|
+
if (value.length === 0) {
|
89
|
+
return new Uint8Array(bytes);
|
90
|
+
}
|
91
|
+
bytes.push(0);
|
92
|
+
for (let i = 0; i < value.length; i++) {
|
93
|
+
let byte = this._alphabetMap[value[i]];
|
94
|
+
if (byte === undefined) {
|
95
|
+
throw new Error("Non-base" + this.base + " character");
|
96
|
+
}
|
97
|
+
let carry = byte;
|
98
|
+
for (let j = 0; j < bytes.length; ++j) {
|
99
|
+
carry += bytes[j] * this.base;
|
100
|
+
bytes[j] = carry & 0xff;
|
101
|
+
carry >>= 8;
|
102
|
+
}
|
103
|
+
while (carry > 0) {
|
104
|
+
bytes.push(carry & 0xff);
|
105
|
+
carry >>= 8;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
// deal with leading zeros
|
109
|
+
for (let k = 0; value[k] === this._leader && k < value.length - 1; ++k) {
|
110
|
+
bytes.push(0);
|
111
|
+
}
|
112
|
+
return arrayify(new Uint8Array(bytes.reverse()));
|
113
|
+
}
|
114
|
+
}
|
115
|
+
new BaseX("abcdefghijklmnopqrstuvwxyz234567");
|
116
|
+
const Base58 = new BaseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
117
|
+
//console.log(Base58.decode("Qmd2V777o5XvJbYMeMb8k2nU5f8d3ciUQ5YpYuWhzv8iDj"))
|
118
|
+
//console.log(Base58.encode(Base58.decode("Qmd2V777o5XvJbYMeMb8k2nU5f8d3ciUQ5YpYuWhzv8iDj")))
|
119
|
+
|
120
|
+
export { Base58, BaseX };
|