@pezkuwi/util-crypto 14.0.2 → 14.0.4
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/LICENSE +201 -0
- package/README.md +4 -4
- package/address/addressToEvm.d.ts +5 -0
- package/address/addressToEvm.js +8 -0
- package/address/check.d.ts +8 -0
- package/address/check.js +26 -0
- package/address/checksum.d.ts +1 -0
- package/address/checksum.js +16 -0
- package/address/decode.d.ts +2 -0
- package/address/decode.js +29 -0
- package/address/defaults.d.ts +6 -0
- package/address/defaults.js +8 -0
- package/address/derive.d.ts +8 -0
- package/address/derive.js +24 -0
- package/address/encode.d.ts +2 -0
- package/address/encode.js +23 -0
- package/address/encodeDerived.d.ts +9 -0
- package/address/encodeDerived.js +12 -0
- package/address/encodeMulti.d.ts +9 -0
- package/address/encodeMulti.js +11 -0
- package/address/eq.d.ts +15 -0
- package/{src/address/eq.ts → address/eq.js} +2 -7
- package/address/evmToAddress.d.ts +7 -0
- package/address/evmToAddress.js +14 -0
- package/{src/address/index.ts → address/index.d.ts} +0 -5
- package/address/index.js +16 -0
- package/address/is.d.ts +2 -0
- package/address/is.js +9 -0
- package/address/keyDerived.d.ts +2 -0
- package/address/keyDerived.js +8 -0
- package/address/keyMulti.d.ts +2 -0
- package/address/keyMulti.js +8 -0
- package/address/setSS58Format.d.ts +6 -0
- package/address/setSS58Format.js +11 -0
- package/address/sort.d.ts +2 -0
- package/address/sort.js +7 -0
- package/address/sshash.d.ts +1 -0
- package/address/sshash.js +6 -0
- package/address/types.d.ts +1 -0
- package/address/types.js +1 -0
- package/address/util.d.ts +1 -0
- package/address/util.js +4 -0
- package/address/validate.d.ts +2 -0
- package/address/validate.js +4 -0
- package/base32/bs32.d.ts +26 -0
- package/{src/base32/bs32.ts → base32/bs32.js} +8 -21
- package/base32/helpers.d.ts +25 -0
- package/base32/helpers.js +61 -0
- package/{src/base32/index.ts → base32/index.d.ts} +0 -4
- package/base32/index.js +4 -0
- package/base58/bs58.d.ts +26 -0
- package/{src/base58/bs58.ts → base58/bs58.js} +4 -13
- package/{src/base58/index.ts → base58/index.d.ts} +0 -4
- package/base58/index.js +4 -0
- package/base64/bs64.d.ts +26 -0
- package/{src/base64/bs64.ts → base64/bs64.js} +4 -13
- package/{src/base64/index.ts → base64/index.d.ts} +0 -4
- package/base64/index.js +6 -0
- package/base64/pad.d.ts +5 -0
- package/base64/pad.js +7 -0
- package/base64/trim.d.ts +5 -0
- package/base64/trim.js +10 -0
- package/blake2/asU8a.d.ts +20 -0
- package/{src/blake2/asU8a.ts → blake2/asU8a.js} +8 -16
- package/{src/blake2/index.ts → blake2/index.d.ts} +0 -4
- package/blake2/index.js +4 -0
- package/bn.d.ts +30 -0
- package/{src/bn.ts → bn.js} +0 -7
- package/bridge.d.ts +82 -0
- package/bridge.js +168 -0
- package/bundle-polkadot-util-crypto.js +11813 -0
- package/{src/bundle.ts → bundle.d.ts} +0 -7
- package/bundle.js +26 -0
- package/bundleInit.d.ts +1 -0
- package/bundleInit.js +5 -0
- package/cjs/address/addressToEvm.d.ts +5 -0
- package/cjs/address/addressToEvm.js +11 -0
- package/cjs/address/check.d.ts +8 -0
- package/cjs/address/check.js +29 -0
- package/cjs/address/checksum.d.ts +1 -0
- package/cjs/address/checksum.js +19 -0
- package/cjs/address/decode.d.ts +2 -0
- package/cjs/address/decode.js +32 -0
- package/cjs/address/defaults.d.ts +6 -0
- package/cjs/address/defaults.js +11 -0
- package/cjs/address/derive.d.ts +8 -0
- package/cjs/address/derive.js +27 -0
- package/cjs/address/encode.d.ts +2 -0
- package/cjs/address/encode.js +26 -0
- package/cjs/address/encodeDerived.d.ts +9 -0
- package/cjs/address/encodeDerived.js +15 -0
- package/cjs/address/encodeMulti.d.ts +9 -0
- package/cjs/address/encodeMulti.js +14 -0
- package/cjs/address/eq.d.ts +15 -0
- package/cjs/address/eq.js +22 -0
- package/cjs/address/evmToAddress.d.ts +7 -0
- package/cjs/address/evmToAddress.js +17 -0
- package/cjs/address/index.d.ts +16 -0
- package/cjs/address/index.js +35 -0
- package/cjs/address/is.d.ts +2 -0
- package/cjs/address/is.js +12 -0
- package/cjs/address/keyDerived.d.ts +2 -0
- package/cjs/address/keyDerived.js +11 -0
- package/cjs/address/keyMulti.d.ts +2 -0
- package/cjs/address/keyMulti.js +11 -0
- package/cjs/address/setSS58Format.d.ts +6 -0
- package/cjs/address/setSS58Format.js +14 -0
- package/cjs/address/sort.d.ts +2 -0
- package/cjs/address/sort.js +10 -0
- package/cjs/address/sshash.d.ts +1 -0
- package/cjs/address/sshash.js +9 -0
- package/cjs/address/types.d.ts +1 -0
- package/cjs/address/types.js +2 -0
- package/cjs/address/util.d.ts +1 -0
- package/cjs/address/util.js +7 -0
- package/cjs/address/validate.d.ts +2 -0
- package/cjs/address/validate.js +7 -0
- package/cjs/base32/bs32.d.ts +26 -0
- package/cjs/base32/bs32.js +43 -0
- package/cjs/base32/helpers.d.ts +25 -0
- package/cjs/base32/helpers.js +67 -0
- package/cjs/base32/index.d.ts +4 -0
- package/cjs/base32/index.js +11 -0
- package/cjs/base58/bs58.d.ts +26 -0
- package/cjs/base58/bs58.js +37 -0
- package/cjs/base58/index.d.ts +4 -0
- package/cjs/base58/index.js +11 -0
- package/cjs/base64/bs64.d.ts +26 -0
- package/cjs/base64/bs64.js +37 -0
- package/cjs/base64/index.d.ts +6 -0
- package/cjs/base64/index.js +15 -0
- package/cjs/base64/pad.d.ts +5 -0
- package/cjs/base64/pad.js +10 -0
- package/cjs/base64/trim.d.ts +5 -0
- package/cjs/base64/trim.js +13 -0
- package/cjs/blake2/asU8a.d.ts +20 -0
- package/cjs/blake2/asU8a.js +36 -0
- package/cjs/blake2/index.d.ts +4 -0
- package/cjs/blake2/index.js +9 -0
- package/cjs/bn.d.ts +30 -0
- package/cjs/bn.js +11 -0
- package/cjs/bridge.d.ts +82 -0
- package/cjs/bridge.js +172 -0
- package/cjs/bundle.d.ts +26 -0
- package/cjs/bundle.js +31 -0
- package/cjs/bundleInit.d.ts +1 -0
- package/cjs/bundleInit.js +7 -0
- package/cjs/crypto.d.ts +3 -0
- package/cjs/crypto.js +16 -0
- package/cjs/ed25519/deriveHard.d.ts +1 -0
- package/cjs/ed25519/deriveHard.js +12 -0
- package/{src/ed25519/index.ts → cjs/ed25519/index.d.ts} +0 -3
- package/cjs/ed25519/index.js +20 -0
- package/cjs/ed25519/pair/fromRandom.d.ts +16 -0
- package/cjs/ed25519/pair/fromRandom.js +22 -0
- package/cjs/ed25519/pair/fromSecret.d.ts +16 -0
- package/{src/ed25519/pair/fromSecret.ts → cjs/ed25519/pair/fromSecret.js} +11 -14
- package/cjs/ed25519/pair/fromSeed.d.ts +16 -0
- package/cjs/ed25519/pair/fromSeed.js +34 -0
- package/cjs/ed25519/pair/fromString.d.ts +16 -0
- package/cjs/ed25519/pair/fromString.js +23 -0
- package/cjs/ed25519/sign.d.ts +16 -0
- package/cjs/ed25519/sign.js +33 -0
- package/cjs/ed25519/verify.d.ts +15 -0
- package/cjs/ed25519/verify.js +39 -0
- package/cjs/ethereum/encode.d.ts +2 -0
- package/cjs/ethereum/encode.js +28 -0
- package/{src/ethereum/index.ts → cjs/ethereum/index.d.ts} +0 -3
- package/cjs/ethereum/index.js +9 -0
- package/cjs/ethereum/isAddress.d.ts +1 -0
- package/cjs/ethereum/isAddress.js +14 -0
- package/cjs/ethereum/isChecksum.d.ts +1 -0
- package/cjs/ethereum/isChecksum.js +20 -0
- package/cjs/hd/ethereum/index.d.ts +2 -0
- package/cjs/hd/ethereum/index.js +47 -0
- package/{src/hd/index.ts → cjs/hd/index.d.ts} +0 -3
- package/cjs/hd/index.js +9 -0
- package/cjs/hd/ledger/derivePrivate.d.ts +1 -0
- package/cjs/hd/ledger/derivePrivate.js +15 -0
- package/cjs/hd/ledger/index.d.ts +2 -0
- package/cjs/hd/ledger/index.js +33 -0
- package/cjs/hd/ledger/master.d.ts +1 -0
- package/cjs/hd/ledger/master.js +19 -0
- package/cjs/hd/validatePath.d.ts +2 -0
- package/cjs/hd/validatePath.js +20 -0
- package/cjs/helpers.d.ts +12 -0
- package/cjs/helpers.js +24 -0
- package/cjs/hmac/index.d.ts +1 -0
- package/cjs/hmac/index.js +7 -0
- package/cjs/hmac/shaAsU8a.d.ts +15 -0
- package/cjs/hmac/shaAsU8a.js +40 -0
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +5 -0
- package/cjs/init.d.ts +10 -0
- package/cjs/init.js +43 -0
- package/cjs/json/constants.d.ts +6 -0
- package/cjs/json/constants.js +8 -0
- package/cjs/json/decrypt.d.ts +2 -0
- package/cjs/json/decrypt.js +16 -0
- package/cjs/json/decryptData.d.ts +2 -0
- package/cjs/json/decryptData.js +32 -0
- package/cjs/json/encrypt.d.ts +2 -0
- package/cjs/json/encrypt.js +18 -0
- package/cjs/json/encryptFormat.d.ts +2 -0
- package/cjs/json/encryptFormat.js +17 -0
- package/{src/json/index.ts → cjs/json/index.d.ts} +0 -3
- package/cjs/json/index.js +11 -0
- package/cjs/json/types.d.ts +16 -0
- package/cjs/json/types.js +2 -0
- package/cjs/keccak/asU8a.d.ts +30 -0
- package/cjs/keccak/asU8a.js +36 -0
- package/{src/keccak/index.ts → cjs/keccak/index.d.ts} +0 -4
- package/cjs/keccak/index.js +11 -0
- package/cjs/key/DeriveJunction.d.ts +12 -0
- package/cjs/key/DeriveJunction.js +62 -0
- package/cjs/key/extractPath.d.ts +9 -0
- package/cjs/key/extractPath.js +26 -0
- package/cjs/key/extractSuri.d.ts +11 -0
- package/cjs/key/extractSuri.js +25 -0
- package/cjs/key/fromPath.d.ts +3 -0
- package/cjs/key/fromPath.js +21 -0
- package/cjs/key/hdkdDerive.d.ts +3 -0
- package/cjs/key/hdkdDerive.js +11 -0
- package/cjs/key/hdkdEcdsa.d.ts +1 -0
- package/cjs/key/hdkdEcdsa.js +7 -0
- package/cjs/key/hdkdEd25519.d.ts +1 -0
- package/cjs/key/hdkdEd25519.js +6 -0
- package/cjs/key/hdkdSr25519.d.ts +3 -0
- package/cjs/key/hdkdSr25519.js +10 -0
- package/{src/key/index.ts → cjs/key/index.d.ts} +0 -3
- package/cjs/key/index.js +18 -0
- package/cjs/mnemonic/bip39.d.ts +5 -0
- package/cjs/mnemonic/bip39.js +90 -0
- package/cjs/mnemonic/generate.d.ts +13 -0
- package/cjs/mnemonic/generate.js +23 -0
- package/{src/mnemonic/index.ts → cjs/mnemonic/index.d.ts} +0 -3
- package/cjs/mnemonic/index.js +16 -0
- package/cjs/mnemonic/toEntropy.d.ts +1 -0
- package/cjs/mnemonic/toEntropy.js +11 -0
- package/cjs/mnemonic/toLegacySeed.d.ts +18 -0
- package/cjs/mnemonic/toLegacySeed.js +37 -0
- package/cjs/mnemonic/toMiniSecret.d.ts +1 -0
- package/cjs/mnemonic/toMiniSecret.js +20 -0
- package/cjs/mnemonic/validate.d.ts +14 -0
- package/cjs/mnemonic/validate.js +24 -0
- package/cjs/mnemonic/wordlists/en.d.ts +2 -0
- package/cjs/mnemonic/wordlists/en.js +3 -0
- package/cjs/mnemonic/wordlists/es.d.ts +2 -0
- package/cjs/mnemonic/wordlists/es.js +3 -0
- package/cjs/mnemonic/wordlists/fr.d.ts +2 -0
- package/cjs/mnemonic/wordlists/fr.js +3 -0
- package/{src/mnemonic/wordlists/index.ts → cjs/mnemonic/wordlists/index.d.ts} +0 -3
- package/cjs/mnemonic/wordlists/index.js +20 -0
- package/cjs/mnemonic/wordlists/it.d.ts +2 -0
- package/cjs/mnemonic/wordlists/it.js +3 -0
- package/cjs/mnemonic/wordlists/jp.d.ts +2 -0
- package/cjs/mnemonic/wordlists/jp.js +3 -0
- package/cjs/mnemonic/wordlists/ko.d.ts +2 -0
- package/cjs/mnemonic/wordlists/ko.js +3 -0
- package/cjs/mnemonic/wordlists/zh-s.d.ts +2 -0
- package/cjs/mnemonic/wordlists/zh-s.js +3 -0
- package/cjs/mnemonic/wordlists/zh-t.d.ts +2 -0
- package/cjs/mnemonic/wordlists/zh-t.js +3 -0
- package/cjs/nacl/decrypt.d.ts +15 -0
- package/cjs/nacl/decrypt.js +21 -0
- package/cjs/nacl/encrypt.d.ts +20 -0
- package/cjs/nacl/encrypt.js +25 -0
- package/{src/nacl/index.ts → cjs/nacl/index.d.ts} +0 -3
- package/cjs/nacl/index.js +10 -0
- package/cjs/nacl/tweetnacl.d.ts +2 -0
- package/cjs/nacl/tweetnacl.js +238 -0
- package/cjs/networks.d.ts +1 -0
- package/cjs/networks.js +7 -0
- package/cjs/package.json +3 -0
- package/cjs/packageDetect.d.ts +1 -0
- package/cjs/packageDetect.js +8 -0
- package/cjs/packageInfo.d.ts +6 -0
- package/cjs/packageInfo.js +4 -0
- package/cjs/pbkdf2/encode.d.ts +7 -0
- package/cjs/pbkdf2/encode.js +19 -0
- package/cjs/pbkdf2/index.d.ts +1 -0
- package/cjs/pbkdf2/index.js +5 -0
- package/cjs/random/asNumber.d.ts +15 -0
- package/cjs/random/asNumber.js +23 -0
- package/cjs/random/asU8a.d.ts +20 -0
- package/cjs/random/asU8a.js +28 -0
- package/{src/random/index.ts → cjs/random/index.d.ts} +0 -4
- package/cjs/random/index.js +11 -0
- package/cjs/scrypt/defaults.d.ts +3 -0
- package/cjs/scrypt/defaults.js +16 -0
- package/cjs/scrypt/encode.d.ts +8 -0
- package/cjs/scrypt/encode.js +18 -0
- package/cjs/scrypt/fromU8a.d.ts +7 -0
- package/cjs/scrypt/fromU8a.js +27 -0
- package/{src/scrypt/index.ts → cjs/scrypt/index.d.ts} +0 -3
- package/cjs/scrypt/index.js +9 -0
- package/cjs/scrypt/toU8a.d.ts +2 -0
- package/cjs/scrypt/toU8a.js +8 -0
- package/cjs/scrypt/types.d.ts +6 -0
- package/cjs/scrypt/types.js +2 -0
- package/cjs/secp256k1/compress.d.ts +1 -0
- package/cjs/secp256k1/compress.js +17 -0
- package/cjs/secp256k1/deriveHard.d.ts +1 -0
- package/cjs/secp256k1/deriveHard.js +13 -0
- package/cjs/secp256k1/expand.d.ts +1 -0
- package/cjs/secp256k1/expand.js +20 -0
- package/cjs/secp256k1/hasher.d.ts +2 -0
- package/cjs/secp256k1/hasher.js +10 -0
- package/{src/secp256k1/index.ts → cjs/secp256k1/index.d.ts} +0 -3
- package/cjs/secp256k1/index.js +17 -0
- package/cjs/secp256k1/pair/fromSeed.d.ts +6 -0
- package/cjs/secp256k1/pair/fromSeed.js +34 -0
- package/cjs/secp256k1/recover.d.ts +6 -0
- package/cjs/secp256k1/recover.js +29 -0
- package/cjs/secp256k1/sign.d.ts +7 -0
- package/cjs/secp256k1/sign.js +23 -0
- package/cjs/secp256k1/tweakAdd.d.ts +1 -0
- package/cjs/secp256k1/tweakAdd.js +48 -0
- package/cjs/secp256k1/types.d.ts +1 -0
- package/cjs/secp256k1/types.js +2 -0
- package/cjs/secp256k1/verify.d.ts +6 -0
- package/cjs/secp256k1/verify.js +23 -0
- package/cjs/sha/asU8a.d.ts +15 -0
- package/cjs/sha/asU8a.js +22 -0
- package/{src/sha/index.ts → cjs/sha/index.d.ts} +0 -4
- package/cjs/sha/index.js +10 -0
- package/cjs/signature/index.d.ts +4 -0
- package/cjs/signature/index.js +8 -0
- package/cjs/signature/verify.d.ts +2 -0
- package/cjs/signature/verify.js +81 -0
- package/cjs/sr25519/agreement.d.ts +5 -0
- package/cjs/sr25519/agreement.js +20 -0
- package/cjs/sr25519/derive.d.ts +2 -0
- package/cjs/sr25519/derive.js +16 -0
- package/cjs/sr25519/deriveHard.d.ts +1 -0
- package/cjs/sr25519/deriveHard.js +7 -0
- package/cjs/sr25519/derivePublic.d.ts +1 -0
- package/cjs/sr25519/derivePublic.js +16 -0
- package/cjs/sr25519/deriveSoft.d.ts +1 -0
- package/cjs/sr25519/deriveSoft.js +7 -0
- package/{src/sr25519/index.ts → cjs/sr25519/index.d.ts} +0 -3
- package/cjs/sr25519/index.js +21 -0
- package/cjs/sr25519/pair/fromSeed.d.ts +6 -0
- package/cjs/sr25519/pair/fromSeed.js +22 -0
- package/cjs/sr25519/pair/fromU8a.d.ts +2 -0
- package/cjs/sr25519/pair/fromU8a.js +17 -0
- package/cjs/sr25519/pair/toU8a.d.ts +2 -0
- package/cjs/sr25519/pair/toU8a.js +7 -0
- package/cjs/sr25519/sign.d.ts +6 -0
- package/cjs/sr25519/sign.js +19 -0
- package/cjs/sr25519/verify.d.ts +5 -0
- package/cjs/sr25519/verify.js +21 -0
- package/cjs/sr25519/vrfSign.d.ts +6 -0
- package/cjs/sr25519/vrfSign.js +19 -0
- package/cjs/sr25519/vrfVerify.d.ts +5 -0
- package/cjs/sr25519/vrfVerify.js +22 -0
- package/cjs/types.d.ts +26 -0
- package/cjs/types.js +5 -0
- package/cjs/wbg.d.ts +36 -0
- package/cjs/wbg.js +65 -0
- package/cjs/xxhash/asU8a.d.ts +20 -0
- package/cjs/xxhash/asU8a.js +39 -0
- package/{src/xxhash/index.ts → cjs/xxhash/index.d.ts} +0 -4
- package/cjs/xxhash/index.js +9 -0
- package/cjs/xxhash/xxhash64.d.ts +1 -0
- package/cjs/xxhash/xxhash64.js +103 -0
- package/crypto.d.ts +3 -0
- package/crypto.js +12 -0
- package/ed25519/deriveHard.d.ts +1 -0
- package/ed25519/deriveHard.js +9 -0
- package/ed25519/index.d.ts +10 -0
- package/ed25519/index.js +10 -0
- package/ed25519/pair/fromRandom.d.ts +16 -0
- package/{src/ed25519/pair/fromRandom.ts → ed25519/pair/fromRandom.js} +2 -8
- package/ed25519/pair/fromSecret.d.ts +16 -0
- package/ed25519/pair/fromSecret.js +23 -0
- package/ed25519/pair/fromSeed.d.ts +16 -0
- package/{src/ed25519/pair/fromSeed.ts → ed25519/pair/fromSeed.js} +11 -21
- package/ed25519/pair/fromString.d.ts +16 -0
- package/{src/ed25519/pair/fromString.ts → ed25519/pair/fromString.js} +2 -13
- package/ed25519/sign.d.ts +16 -0
- package/ed25519/sign.js +30 -0
- package/ed25519/verify.d.ts +15 -0
- package/ed25519/verify.js +36 -0
- package/ethereum/encode.d.ts +2 -0
- package/ethereum/encode.js +25 -0
- package/ethereum/index.d.ts +3 -0
- package/ethereum/index.js +3 -0
- package/ethereum/isAddress.d.ts +1 -0
- package/ethereum/isAddress.js +11 -0
- package/ethereum/isChecksum.d.ts +1 -0
- package/ethereum/isChecksum.js +17 -0
- package/hd/ethereum/index.d.ts +2 -0
- package/hd/ethereum/index.js +44 -0
- package/hd/index.d.ts +3 -0
- package/hd/index.js +3 -0
- package/hd/ledger/derivePrivate.d.ts +1 -0
- package/hd/ledger/derivePrivate.js +12 -0
- package/hd/ledger/index.d.ts +2 -0
- package/hd/ledger/index.js +30 -0
- package/hd/ledger/master.d.ts +1 -0
- package/hd/ledger/master.js +16 -0
- package/hd/validatePath.d.ts +2 -0
- package/hd/validatePath.js +16 -0
- package/helpers.d.ts +12 -0
- package/helpers.js +19 -0
- package/hmac/index.d.ts +1 -0
- package/hmac/index.js +1 -0
- package/hmac/shaAsU8a.d.ts +15 -0
- package/{src/hmac/shaAsU8a.ts → hmac/shaAsU8a.js} +11 -23
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/init.d.ts +10 -0
- package/init.js +40 -0
- package/json/constants.d.ts +6 -0
- package/json/constants.js +5 -0
- package/json/decrypt.d.ts +2 -0
- package/json/decrypt.js +13 -0
- package/json/decryptData.d.ts +2 -0
- package/json/decryptData.js +29 -0
- package/json/encrypt.d.ts +2 -0
- package/json/encrypt.js +15 -0
- package/json/encryptFormat.d.ts +2 -0
- package/json/encryptFormat.js +14 -0
- package/json/index.d.ts +4 -0
- package/json/index.js +4 -0
- package/json/types.d.ts +16 -0
- package/json/types.js +1 -0
- package/keccak/asU8a.d.ts +30 -0
- package/{src/keccak/asU8a.ts → keccak/asU8a.js} +1 -13
- package/keccak/index.d.ts +4 -0
- package/keccak/index.js +4 -0
- package/key/DeriveJunction.d.ts +12 -0
- package/key/DeriveJunction.js +58 -0
- package/key/extractPath.d.ts +9 -0
- package/key/extractPath.js +23 -0
- package/key/extractSuri.d.ts +11 -0
- package/key/extractSuri.js +22 -0
- package/key/fromPath.d.ts +3 -0
- package/key/fromPath.js +18 -0
- package/key/hdkdDerive.d.ts +3 -0
- package/key/hdkdDerive.js +8 -0
- package/key/hdkdEcdsa.d.ts +1 -0
- package/{src/key/hdkdEcdsa.ts → key/hdkdEcdsa.js} +0 -4
- package/key/hdkdEd25519.d.ts +1 -0
- package/{src/key/hdkdEd25519.ts → key/hdkdEd25519.js} +0 -4
- package/key/hdkdSr25519.d.ts +3 -0
- package/key/hdkdSr25519.js +7 -0
- package/key/index.d.ts +9 -0
- package/key/index.js +9 -0
- package/mnemonic/bip39.d.ts +5 -0
- package/mnemonic/bip39.js +82 -0
- package/mnemonic/generate.d.ts +13 -0
- package/{src/mnemonic/generate.ts → mnemonic/generate.js} +4 -9
- package/mnemonic/index.d.ts +8 -0
- package/mnemonic/index.js +8 -0
- package/mnemonic/toEntropy.d.ts +1 -0
- package/mnemonic/toEntropy.js +8 -0
- package/mnemonic/toLegacySeed.d.ts +18 -0
- package/{src/mnemonic/toLegacySeed.ts → mnemonic/toLegacySeed.js} +12 -17
- package/mnemonic/toMiniSecret.d.ts +1 -0
- package/mnemonic/toMiniSecret.js +17 -0
- package/mnemonic/validate.d.ts +14 -0
- package/{src/mnemonic/validate.ts → mnemonic/validate.js} +4 -9
- package/mnemonic/wordlists/en.d.ts +2 -0
- package/{src/mnemonic/wordlists/en.ts → mnemonic/wordlists/en.js} +0 -6
- package/mnemonic/wordlists/es.d.ts +2 -0
- package/{src/mnemonic/wordlists/es.ts → mnemonic/wordlists/es.js} +0 -6
- package/mnemonic/wordlists/fr.d.ts +2 -0
- package/{src/mnemonic/wordlists/fr.ts → mnemonic/wordlists/fr.js} +0 -6
- package/mnemonic/wordlists/index.d.ts +8 -0
- package/mnemonic/wordlists/index.js +8 -0
- package/mnemonic/wordlists/it.d.ts +2 -0
- package/{src/mnemonic/wordlists/it.ts → mnemonic/wordlists/it.js} +0 -6
- package/mnemonic/wordlists/jp.d.ts +2 -0
- package/{src/mnemonic/wordlists/jp.ts → mnemonic/wordlists/jp.js} +0 -6
- package/mnemonic/wordlists/ko.d.ts +2 -0
- package/{src/mnemonic/wordlists/ko.ts → mnemonic/wordlists/ko.js} +0 -6
- package/mnemonic/wordlists/zh-s.d.ts +2 -0
- package/{src/mnemonic/wordlists/zh-s.ts → mnemonic/wordlists/zh-s.js} +0 -6
- package/mnemonic/wordlists/zh-t.d.ts +2 -0
- package/{src/mnemonic/wordlists/zh-t.ts → mnemonic/wordlists/zh-t.js} +0 -6
- package/nacl/decrypt.d.ts +15 -0
- package/{src/nacl/decrypt.ts → nacl/decrypt.js} +2 -6
- package/nacl/encrypt.d.ts +20 -0
- package/{src/nacl/encrypt.ts → nacl/encrypt.js} +5 -14
- package/nacl/index.d.ts +5 -0
- package/nacl/index.js +5 -0
- package/nacl/tweetnacl.d.ts +2 -0
- package/nacl/tweetnacl.js +234 -0
- package/networks.d.ts +1 -0
- package/networks.js +1 -0
- package/package.json +2022 -10
- package/packageDetect.d.ts +1 -0
- package/{src/packageDetect.ts → packageDetect.js} +0 -8
- package/packageInfo.d.ts +6 -0
- package/packageInfo.js +1 -0
- package/pbkdf2/encode.d.ts +7 -0
- package/pbkdf2/encode.js +16 -0
- package/pbkdf2/index.d.ts +1 -0
- package/pbkdf2/index.js +1 -0
- package/random/asNumber.d.ts +15 -0
- package/{src/random/asNumber.ts → random/asNumber.js} +2 -10
- package/random/asU8a.d.ts +20 -0
- package/{src/random/asU8a.ts → random/asU8a.js} +2 -8
- package/random/index.d.ts +5 -0
- package/random/index.js +5 -0
- package/scrypt/defaults.d.ts +3 -0
- package/scrypt/defaults.js +13 -0
- package/scrypt/encode.d.ts +8 -0
- package/scrypt/encode.js +15 -0
- package/scrypt/fromU8a.d.ts +7 -0
- package/scrypt/fromU8a.js +24 -0
- package/scrypt/index.d.ts +3 -0
- package/scrypt/index.js +3 -0
- package/scrypt/toU8a.d.ts +2 -0
- package/scrypt/toU8a.js +5 -0
- package/scrypt/types.d.ts +6 -0
- package/scrypt/types.js +1 -0
- package/secp256k1/compress.d.ts +1 -0
- package/secp256k1/compress.js +14 -0
- package/secp256k1/deriveHard.d.ts +1 -0
- package/secp256k1/deriveHard.js +10 -0
- package/secp256k1/expand.d.ts +1 -0
- package/secp256k1/expand.js +17 -0
- package/secp256k1/hasher.d.ts +2 -0
- package/secp256k1/hasher.js +7 -0
- package/secp256k1/index.d.ts +7 -0
- package/secp256k1/index.js +7 -0
- package/secp256k1/pair/fromSeed.d.ts +6 -0
- package/secp256k1/pair/fromSeed.js +31 -0
- package/secp256k1/recover.d.ts +6 -0
- package/secp256k1/recover.js +26 -0
- package/secp256k1/sign.d.ts +7 -0
- package/secp256k1/sign.js +20 -0
- package/secp256k1/tweakAdd.d.ts +1 -0
- package/secp256k1/tweakAdd.js +45 -0
- package/secp256k1/types.d.ts +1 -0
- package/secp256k1/types.js +1 -0
- package/secp256k1/verify.d.ts +6 -0
- package/secp256k1/verify.js +20 -0
- package/sha/asU8a.d.ts +15 -0
- package/{src/sha/asU8a.ts → sha/asU8a.js} +1 -12
- package/sha/index.d.ts +4 -0
- package/sha/index.js +4 -0
- package/signature/index.d.ts +4 -0
- package/signature/index.js +4 -0
- package/signature/verify.d.ts +2 -0
- package/signature/verify.js +78 -0
- package/sr25519/agreement.d.ts +5 -0
- package/sr25519/agreement.js +17 -0
- package/sr25519/derive.d.ts +2 -0
- package/sr25519/derive.js +12 -0
- package/sr25519/deriveHard.d.ts +1 -0
- package/{src/sr25519/deriveHard.ts → sr25519/deriveHard.js} +0 -6
- package/sr25519/derivePublic.d.ts +1 -0
- package/sr25519/derivePublic.js +12 -0
- package/sr25519/deriveSoft.d.ts +1 -0
- package/{src/sr25519/deriveSoft.ts → sr25519/deriveSoft.js} +0 -6
- package/sr25519/index.d.ts +9 -0
- package/sr25519/index.js +9 -0
- package/sr25519/pair/fromSeed.d.ts +6 -0
- package/sr25519/pair/fromSeed.js +18 -0
- package/sr25519/pair/fromU8a.d.ts +2 -0
- package/sr25519/pair/fromU8a.js +14 -0
- package/sr25519/pair/toU8a.d.ts +2 -0
- package/sr25519/pair/toU8a.js +4 -0
- package/sr25519/sign.d.ts +6 -0
- package/sr25519/sign.js +15 -0
- package/sr25519/verify.d.ts +5 -0
- package/sr25519/verify.js +17 -0
- package/sr25519/vrfSign.d.ts +6 -0
- package/sr25519/vrfSign.js +15 -0
- package/sr25519/vrfVerify.d.ts +5 -0
- package/sr25519/vrfVerify.js +18 -0
- package/types.d.ts +26 -0
- package/types.js +2 -0
- package/wbg.d.ts +36 -0
- package/wbg.js +61 -0
- package/xxhash/asU8a.d.ts +20 -0
- package/{src/xxhash/asU8a.ts → xxhash/asU8a.js} +11 -21
- package/xxhash/index.d.ts +4 -0
- package/xxhash/index.js +4 -0
- package/xxhash/xxhash64.d.ts +1 -0
- package/xxhash/xxhash64.js +100 -0
- package/src/address/addressToEvm.spec.ts +0 -16
- package/src/address/addressToEvm.ts +0 -12
- package/src/address/check.spec.ts +0 -44
- package/src/address/check.ts +0 -34
- package/src/address/checksum.spec.ts +0 -45
- package/src/address/checksum.ts +0 -25
- package/src/address/decode.spec.ts +0 -138
- package/src/address/decode.ts +0 -41
- package/src/address/defaults.ts +0 -12
- package/src/address/derive.spec.ts +0 -26
- package/src/address/derive.ts +0 -36
- package/src/address/encode.spec.ts +0 -177
- package/src/address/encode.ts +0 -43
- package/src/address/encodeDerived.spec.ts +0 -14
- package/src/address/encodeDerived.ts +0 -19
- package/src/address/encodeMulti.spec.ts +0 -18
- package/src/address/encodeMulti.ts +0 -18
- package/src/address/eq.spec.ts +0 -45
- package/src/address/evmToAddress.spec.ts +0 -20
- package/src/address/evmToAddress.ts +0 -24
- package/src/address/is.spec.ts +0 -113
- package/src/address/is.ts +0 -14
- package/src/address/keyDerived.spec.ts +0 -24
- package/src/address/keyDerived.ts +0 -22
- package/src/address/keyMulti.spec.ts +0 -20
- package/src/address/keyMulti.ts +0 -23
- package/src/address/setSS58Format.spec.ts +0 -21
- package/src/address/setSS58Format.ts +0 -20
- package/src/address/sort.spec.ts +0 -22
- package/src/address/sort.ts +0 -17
- package/src/address/sshash.ts +0 -12
- package/src/address/types.ts +0 -6
- package/src/address/util.ts +0 -8
- package/src/address/validate.spec.ts +0 -113
- package/src/address/validate.ts +0 -10
- package/src/base32/decode.spec.ts +0 -34
- package/src/base32/encode.spec.ts +0 -30
- package/src/base32/helpers.ts +0 -93
- package/src/base32/is.spec.ts +0 -32
- package/src/base32/validate.spec.ts +0 -44
- package/src/base58/decode.spec.ts +0 -31
- package/src/base58/encode.spec.ts +0 -26
- package/src/base58/validate.spec.ts +0 -20
- package/src/base64/decode.spec.ts +0 -42
- package/src/base64/encode.spec.ts +0 -14
- package/src/base64/pad.spec.ts +0 -14
- package/src/base64/pad.ts +0 -10
- package/src/base64/trim.spec.ts +0 -14
- package/src/base64/trim.ts +0 -14
- package/src/base64/validate.spec.ts +0 -32
- package/src/blake2/asHex.spec.ts +0 -57
- package/src/blake2/asU8a.spec.ts +0 -74
- package/src/bundleInit.ts +0 -11
- package/src/crypto.spec.ts +0 -18
- package/src/crypto.ts +0 -18
- package/src/ed25519/deriveHard.ts +0 -18
- package/src/ed25519/pair/fromRandom.spec.ts +0 -28
- package/src/ed25519/pair/fromSecret.spec.ts +0 -33
- package/src/ed25519/pair/fromSeed.spec.ts +0 -42
- package/src/ed25519/pair/fromString.spec.ts +0 -17
- package/src/ed25519/sign.spec.ts +0 -40
- package/src/ed25519/sign.ts +0 -38
- package/src/ed25519/verify.spec.ts +0 -84
- package/src/ed25519/verify.ts +0 -41
- package/src/ethereum/encode.spec.ts +0 -59
- package/src/ethereum/encode.ts +0 -39
- package/src/ethereum/isAddress.spec.ts +0 -34
- package/src/ethereum/isAddress.ts +0 -16
- package/src/ethereum/isChecksum.ts +0 -27
- package/src/ethereum/isCheksum.spec.ts +0 -30
- package/src/hd/ethereum/index.spec.ts +0 -54
- package/src/hd/ethereum/index.ts +0 -69
- package/src/hd/ledger/derivePrivate.ts +0 -34
- package/src/hd/ledger/index.spec.ts +0 -64
- package/src/hd/ledger/index.ts +0 -42
- package/src/hd/ledger/master.spec.ts +0 -19
- package/src/hd/ledger/master.ts +0 -26
- package/src/hd/validatePath.spec.ts +0 -30
- package/src/hd/validatePath.ts +0 -24
- package/src/helpers.ts +0 -38
- package/src/hmac/index.ts +0 -4
- package/src/hmac/shaAsU8a.spec.ts +0 -45
- package/src/index.ts +0 -6
- package/src/json/constants.ts +0 -11
- package/src/json/decrypt.ts +0 -25
- package/src/json/decryptData.ts +0 -45
- package/src/json/encrypt.ts +0 -25
- package/src/json/encryptFormat.ts +0 -20
- package/src/json/types.ts +0 -22
- package/src/keccak/asHex.spec.ts +0 -30
- package/src/keccak/asU8a.spec.ts +0 -56
- package/src/key/DeriveJunction.ts +0 -79
- package/src/key/extractPath.spec.ts +0 -51
- package/src/key/extractPath.ts +0 -37
- package/src/key/extractSuri.spec.ts +0 -147
- package/src/key/extractSuri.ts +0 -40
- package/src/key/fromPath.ts +0 -28
- package/src/key/hdkdDerive.ts +0 -17
- package/src/key/hdkdSr25519.ts +0 -14
- package/src/mnemonic/bip39.spec.ts +0 -80
- package/src/mnemonic/bip39.ts +0 -127
- package/src/mnemonic/generate.spec.ts +0 -58
- package/src/mnemonic/toEntropy.spec.ts +0 -36
- package/src/mnemonic/toEntropy.ts +0 -13
- package/src/mnemonic/toLegacySeed.spec.ts +0 -52
- package/src/mnemonic/toMiniSecret.spec.ts +0 -67
- package/src/mnemonic/toMiniSecret.ts +0 -23
- package/src/mnemonic/toMiniSecretCmp.spec.ts +0 -64
- package/src/mnemonic/validate.spec.ts +0 -39
- package/src/mod.ts +0 -4
- package/src/nacl/decrypt.spec.ts +0 -26
- package/src/nacl/encrypt.spec.ts +0 -20
- package/src/nacl/tweetnacl-secretbox-data.spec.ts +0 -4629
- package/src/nacl/tweetnacl-secretbox.spec.ts +0 -161
- package/src/nacl/tweetnacl.ts +0 -1159
- package/src/networks.ts +0 -5
- package/src/packageInfo.ts +0 -6
- package/src/pbkdf2/encode.spec.ts +0 -54
- package/src/pbkdf2/encode.ts +0 -29
- package/src/pbkdf2/index.ts +0 -4
- package/src/random/asHex.spec.ts +0 -38
- package/src/random/asNumber.spec.ts +0 -16
- package/src/random/asU8a.spec.ts +0 -36
- package/src/scrypt/defaults.ts +0 -19
- package/src/scrypt/encode.spec.ts +0 -43
- package/src/scrypt/encode.ts +0 -30
- package/src/scrypt/fromU8a.ts +0 -44
- package/src/scrypt/toU8a.ts +0 -17
- package/src/scrypt/types.ts +0 -9
- package/src/secp256k1/compress.spec.ts +0 -47
- package/src/secp256k1/compress.ts +0 -21
- package/src/secp256k1/deriveHard.ts +0 -17
- package/src/secp256k1/expand.spec.ts +0 -47
- package/src/secp256k1/expand.ts +0 -30
- package/src/secp256k1/hasher.spec.ts +0 -24
- package/src/secp256k1/hasher.ts +0 -13
- package/src/secp256k1/pair/fromSeed.spec.ts +0 -75
- package/src/secp256k1/pair/fromSeed.ts +0 -42
- package/src/secp256k1/recover.spec.ts +0 -35
- package/src/secp256k1/recover.ts +0 -36
- package/src/secp256k1/sign.spec.ts +0 -39
- package/src/secp256k1/sign.ts +0 -37
- package/src/secp256k1/signVerify.spec.ts +0 -94
- package/src/secp256k1/tweakAdd.spec.ts +0 -35
- package/src/secp256k1/tweakAdd.ts +0 -65
- package/src/secp256k1/types.ts +0 -4
- package/src/secp256k1/verify.spec.ts +0 -81
- package/src/secp256k1/verify.ts +0 -32
- package/src/sha/asU8a256.spec.ts +0 -55
- package/src/sha/asU8a512.spec.ts +0 -33
- package/src/signature/index.ts +0 -8
- package/src/signature/verify.spec.ts +0 -230
- package/src/signature/verify.ts +0 -114
- package/src/sr25519/agreement.spec.ts +0 -31
- package/src/sr25519/agreement.ts +0 -23
- package/src/sr25519/derive.ts +0 -21
- package/src/sr25519/derivePublic.ts +0 -18
- package/src/sr25519/pair/fromSeed.spec.ts +0 -35
- package/src/sr25519/pair/fromSeed.ts +0 -28
- package/src/sr25519/pair/fromU8a.ts +0 -23
- package/src/sr25519/pair/testing.spec.ts +0 -161
- package/src/sr25519/pair/toU8a.ts +0 -10
- package/src/sr25519/sign.spec.ts +0 -28
- package/src/sr25519/sign.ts +0 -22
- package/src/sr25519/verify.spec.ts +0 -42
- package/src/sr25519/verify.ts +0 -23
- package/src/sr25519/vrfSign.ts +0 -24
- package/src/sr25519/vrfSignVerify.spec.ts +0 -73
- package/src/sr25519/vrfVerify.ts +0 -25
- package/src/test/index.ts +0 -8
- package/src/test/performance.ts +0 -17
- package/src/types.ts +0 -33
- package/src/xxhash/asHex.spec.ts +0 -36
- package/src/xxhash/asU8a.spec.ts +0 -48
- package/src/xxhash/xxhash64.ts +0 -155
- package/tsconfig.build.json +0 -18
- package/tsconfig.spec.json +0 -20
package/src/blake2/asHex.spec.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import { hexToU8a } from '@pezkuwi/util';
|
|
7
|
-
import { waitReady } from '@pezkuwi/wasm-crypto';
|
|
8
|
-
|
|
9
|
-
import { blake2AsHex } from './index.js';
|
|
10
|
-
|
|
11
|
-
describe('blake2AsHex', (): void => {
|
|
12
|
-
beforeEach(async (): Promise<void> => {
|
|
13
|
-
await waitReady();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
for (const onlyJs of [false, true]) {
|
|
17
|
-
describe(`onlyJs=${(onlyJs && 'true') || 'false'}`, (): void => {
|
|
18
|
-
it('returns a 64-bit value (specified)', (): void => {
|
|
19
|
-
expect(
|
|
20
|
-
blake2AsHex('abc', 64, null, onlyJs)
|
|
21
|
-
).toEqual('0xd8bb14d833d59559');
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('returns a 128-bit value (as specified)', (): void => {
|
|
25
|
-
expect(
|
|
26
|
-
blake2AsHex('abc', 128, null, onlyJs)
|
|
27
|
-
).toEqual('0xcf4ab791c62b8d2b2109c90275287816');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('returns a 128-bit value (as specified, with key)', (): void => {
|
|
31
|
-
expect(
|
|
32
|
-
blake2AsHex('abc', 128, new Uint8Array([1, 2]), onlyJs)
|
|
33
|
-
).toEqual('0x36f3d08cda72a00ddf2be103eb5770d9');
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('returns a 256-bit value (default)', (): void => {
|
|
37
|
-
expect(
|
|
38
|
-
blake2AsHex('abc', undefined, null, onlyJs)
|
|
39
|
-
).toEqual('0xbddd813c634239723171ef3fee98579b94964e3bb1cb3e427262c8c068d52319');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('returns a 512-bit value (as specified)', (): void => {
|
|
43
|
-
expect(
|
|
44
|
-
blake2AsHex('abc', 512, null, onlyJs)
|
|
45
|
-
).toEqual('0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('matches with the Rust implementation', (): void => {
|
|
49
|
-
expect(
|
|
50
|
-
blake2AsHex(
|
|
51
|
-
hexToU8a('0x454545454545454545454545454545454545454545454545454545454545454501000000000000002481853da20b9f4322f34650fea5f240dcbfb266d02db94bfa0153c31f4a29dbdbf025dd4a69a6f4ee6e1577b251b655097e298b692cb34c18d3182cac3de0dc00000000'), 256, undefined, onlyJs
|
|
52
|
-
)
|
|
53
|
-
).toEqual('0x1025e5db74fdaf4d2818822dccf0e1604ae9ccc62f26cecfde23448ff0248abf');
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
});
|
package/src/blake2/asU8a.spec.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import { hexToU8a } from '@pezkuwi/util';
|
|
7
|
-
import { waitReady } from '@pezkuwi/wasm-crypto';
|
|
8
|
-
|
|
9
|
-
import { perfWasm } from '../test/index.js';
|
|
10
|
-
import { blake2AsU8a } from './index.js';
|
|
11
|
-
|
|
12
|
-
describe('blake2AsU8a', (): void => {
|
|
13
|
-
beforeEach(async (): Promise<void> => {
|
|
14
|
-
await waitReady();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
for (const onlyJs of [false, true]) {
|
|
18
|
-
describe(`onlyJs=${(onlyJs && 'true') || 'false'}`, (): void => {
|
|
19
|
-
it('returns a 64-bit value by default', (): void => {
|
|
20
|
-
expect(
|
|
21
|
-
blake2AsU8a('abc', undefined, undefined, onlyJs)
|
|
22
|
-
).toEqual(
|
|
23
|
-
new Uint8Array([189, 221, 129, 60, 99, 66, 57, 114, 49, 113, 239, 63, 238, 152, 87, 155, 148, 150, 78, 59, 177, 203, 62, 66, 114, 98, 200, 192, 104, 213, 35, 25])
|
|
24
|
-
);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('returns a 128-bit value (as specified,)', (): void => {
|
|
28
|
-
expect(
|
|
29
|
-
blake2AsU8a('abc', 128, undefined, onlyJs)
|
|
30
|
-
).toEqual(
|
|
31
|
-
new Uint8Array([207, 74, 183, 145, 198, 43, 141, 43, 33, 9, 201, 2, 117, 40, 120, 22])
|
|
32
|
-
);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('returns a 256-bit value (as specified)', (): void => {
|
|
36
|
-
expect(
|
|
37
|
-
blake2AsU8a('abc', 256, undefined, onlyJs)
|
|
38
|
-
).toEqual(
|
|
39
|
-
new Uint8Array([189, 221, 129, 60, 99, 66, 57, 114, 49, 113, 239, 63, 238, 152, 87, 155, 148, 150, 78, 59, 177, 203, 62, 66, 114, 98, 200, 192, 104, 213, 35, 25])
|
|
40
|
-
);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('returns a 512-bit value (as specified)', (): void => {
|
|
44
|
-
expect(
|
|
45
|
-
blake2AsU8a('abc', 512, undefined, onlyJs)
|
|
46
|
-
).toEqual(
|
|
47
|
-
hexToU8a('0xba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923')
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
it('has equivalent Wasm/Js outputs on hex inputs', (): void => {
|
|
54
|
-
const a = blake2AsU8a('0x123456', 256, null, false);
|
|
55
|
-
const b = blake2AsU8a('0x123456', 256, null, true);
|
|
56
|
-
|
|
57
|
-
expect(a).toEqual(b);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('has equivalent Wasm/Js outputs with key inputs', (): void => {
|
|
61
|
-
const a = blake2AsU8a('0x123456', 256, new Uint8Array([1, 2]), false);
|
|
62
|
-
const b = blake2AsU8a('0x123456', 256, new Uint8Array([1, 2]), true);
|
|
63
|
-
|
|
64
|
-
expect(a).toEqual(b);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
for (const bitLength of [256, 512] as const) {
|
|
68
|
-
describe(`bitLength=${bitLength}`, (): void => {
|
|
69
|
-
perfWasm(`blake2AsU8a, bitLength=${bitLength}`, 64000, (input, onlyJs) =>
|
|
70
|
-
blake2AsU8a(input, bitLength, null, onlyJs)
|
|
71
|
-
);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
});
|
package/src/bundleInit.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import '@polkadot/x-bigint/shim';
|
|
5
|
-
|
|
6
|
-
import { cryptoWaitReady } from './crypto.js';
|
|
7
|
-
|
|
8
|
-
// start init process immediately
|
|
9
|
-
cryptoWaitReady().catch((): void => {
|
|
10
|
-
// shouldn't happen, logged and caught inside cryptoWaitReady
|
|
11
|
-
});
|
package/src/crypto.spec.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
describe('cryptoWaitReady', (): void => {
|
|
7
|
-
it('should return false when it cannot initialize', async (): Promise<void> => {
|
|
8
|
-
const old = global.WebAssembly;
|
|
9
|
-
|
|
10
|
-
global.WebAssembly = null as unknown as typeof WebAssembly;
|
|
11
|
-
|
|
12
|
-
const { cryptoWaitReady } = await import('./crypto.js');
|
|
13
|
-
|
|
14
|
-
expect(await cryptoWaitReady()).toBe(false);
|
|
15
|
-
|
|
16
|
-
global.WebAssembly = old;
|
|
17
|
-
});
|
|
18
|
-
});
|
package/src/crypto.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { isReady, waitReady } from '@pezkuwi/wasm-crypto';
|
|
5
|
-
|
|
6
|
-
export const cryptoIsReady = isReady;
|
|
7
|
-
|
|
8
|
-
export function cryptoWaitReady (): Promise<boolean> {
|
|
9
|
-
return waitReady()
|
|
10
|
-
.then((): boolean => {
|
|
11
|
-
if (!isReady()) {
|
|
12
|
-
throw new Error('Unable to initialize @polkadot/util-crypto');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return true;
|
|
16
|
-
})
|
|
17
|
-
.catch(() => false);
|
|
18
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { compactAddLength, isU8a, stringToU8a, u8aConcat } from '@pezkuwi/util';
|
|
5
|
-
|
|
6
|
-
import { blake2AsU8a } from '../blake2/asU8a.js';
|
|
7
|
-
|
|
8
|
-
const HDKD = compactAddLength(stringToU8a('Ed25519HDKD'));
|
|
9
|
-
|
|
10
|
-
export function ed25519DeriveHard (seed: Uint8Array, chainCode: Uint8Array): Uint8Array {
|
|
11
|
-
if (!isU8a(chainCode) || chainCode.length !== 32) {
|
|
12
|
-
throw new Error('Invalid chainCode passed to derive');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return blake2AsU8a(
|
|
16
|
-
u8aConcat(HDKD, seed, chainCode)
|
|
17
|
-
);
|
|
18
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import type { Keypair } from '../../types.js';
|
|
7
|
-
|
|
8
|
-
import { ed25519PairFromRandom } from '../index.js';
|
|
9
|
-
|
|
10
|
-
describe('ed25519PairFromRandom', (): void => {
|
|
11
|
-
let keypair: Keypair;
|
|
12
|
-
|
|
13
|
-
beforeEach((): void => {
|
|
14
|
-
keypair = ed25519PairFromRandom();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('generates a valid publicKey', (): void => {
|
|
18
|
-
expect(
|
|
19
|
-
keypair.publicKey
|
|
20
|
-
).toHaveLength(32);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('generates a valid secretKey', (): void => {
|
|
24
|
-
expect(
|
|
25
|
-
keypair.secretKey
|
|
26
|
-
).toHaveLength(64);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import { ed25519PairFromSecret } from '../index.js';
|
|
7
|
-
|
|
8
|
-
describe('ed25519PairFromSecret', (): void => {
|
|
9
|
-
const secretKey = new Uint8Array([
|
|
10
|
-
18, 52, 86, 120, 144, 18, 52, 86,
|
|
11
|
-
120, 144, 18, 52, 86, 120, 144, 18,
|
|
12
|
-
18, 52, 86, 120, 144, 18, 52, 86,
|
|
13
|
-
120, 144, 18, 52, 86, 120, 144, 18,
|
|
14
|
-
180, 114, 93, 155, 165, 255, 217, 82,
|
|
15
|
-
16, 250, 209, 11, 193, 10, 88, 218,
|
|
16
|
-
190, 190, 41, 193, 236, 252, 1, 152,
|
|
17
|
-
216, 214, 0, 41, 45, 138, 13, 53
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
it('generates a valid publicKey/secretKey pair', (): void => {
|
|
21
|
-
expect(
|
|
22
|
-
ed25519PairFromSecret(secretKey)
|
|
23
|
-
).toEqual({
|
|
24
|
-
publicKey: new Uint8Array([
|
|
25
|
-
180, 114, 93, 155, 165, 255, 217, 82,
|
|
26
|
-
16, 250, 209, 11, 193, 10, 88, 218,
|
|
27
|
-
190, 190, 41, 193, 236, 252, 1, 152,
|
|
28
|
-
216, 214, 0, 41, 45, 138, 13, 53
|
|
29
|
-
]),
|
|
30
|
-
secretKey
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import { stringToU8a } from '@pezkuwi/util';
|
|
7
|
-
import { waitReady } from '@pezkuwi/wasm-crypto';
|
|
8
|
-
|
|
9
|
-
import { ed25519PairFromSeed } from '../index.js';
|
|
10
|
-
|
|
11
|
-
describe('ed25519PairFromSeed', (): void => {
|
|
12
|
-
// NOTE: Aligned with Rust test, b"12345678901234567890123456789012"
|
|
13
|
-
const TEST = stringToU8a('12345678901234567890123456789012');
|
|
14
|
-
const RESULT = {
|
|
15
|
-
publicKey: new Uint8Array([
|
|
16
|
-
0x2f, 0x8c, 0x61, 0x29, 0xd8, 0x16, 0xcf, 0x51,
|
|
17
|
-
0xc3, 0x74, 0xbc, 0x7f, 0x08, 0xc3, 0xe6, 0x3e,
|
|
18
|
-
0xd1, 0x56, 0xcf, 0x78, 0xae, 0xfb, 0x4a, 0x65,
|
|
19
|
-
0x50, 0xd9, 0x7b, 0x87, 0x99, 0x79, 0x77, 0xee
|
|
20
|
-
]),
|
|
21
|
-
secretKey: new Uint8Array([
|
|
22
|
-
49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50,
|
|
23
|
-
// public part
|
|
24
|
-
0x2f, 0x8c, 0x61, 0x29, 0xd8, 0x16, 0xcf, 0x51,
|
|
25
|
-
0xc3, 0x74, 0xbc, 0x7f, 0x08, 0xc3, 0xe6, 0x3e,
|
|
26
|
-
0xd1, 0x56, 0xcf, 0x78, 0xae, 0xfb, 0x4a, 0x65,
|
|
27
|
-
0x50, 0xd9, 0x7b, 0x87, 0x99, 0x79, 0x77, 0xee
|
|
28
|
-
])
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
beforeEach(async (): Promise<void> => {
|
|
32
|
-
await waitReady();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('generates a valid publicKey/secretKey pair (u8a)', (): void => {
|
|
36
|
-
[true, false].forEach((onlyJs): void => {
|
|
37
|
-
expect(
|
|
38
|
-
ed25519PairFromSeed(TEST, onlyJs)
|
|
39
|
-
).toEqual(RESULT);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import { ed25519PairFromString } from '../index.js';
|
|
7
|
-
|
|
8
|
-
describe('ed25519PairFromSeed', (): void => {
|
|
9
|
-
it('generates a valid publicKey/secretKey pair', (): void => {
|
|
10
|
-
expect(
|
|
11
|
-
ed25519PairFromString('test')
|
|
12
|
-
).toEqual({
|
|
13
|
-
publicKey: new Uint8Array([188, 108, 179, 142, 36, 142, 76, 87, 77, 193, 147, 139, 254, 110, 196, 217, 117, 233, 167, 165, 250, 150, 247, 237, 198, 68, 129, 4, 211, 209, 136, 48]),
|
|
14
|
-
secretKey: new Uint8Array([146, 139, 32, 54, 105, 67, 226, 175, 209, 30, 188, 14, 174, 46, 83, 169, 59, 241, 119, 164, 252, 243, 91, 204, 100, 213, 3, 112, 78, 101, 226, 2, 188, 108, 179, 142, 36, 142, 76, 87, 77, 193, 147, 139, 254, 110, 196, 217, 117, 233, 167, 165, 250, 150, 247, 237, 198, 68, 129, 4, 211, 209, 136, 48])
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
});
|
package/src/ed25519/sign.spec.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import { stringToU8a } from '@pezkuwi/util';
|
|
7
|
-
import { waitReady } from '@pezkuwi/wasm-crypto';
|
|
8
|
-
|
|
9
|
-
import { perfWasm } from '../test/index.js';
|
|
10
|
-
import { ed25519PairFromSeed, ed25519Sign } from './index.js';
|
|
11
|
-
|
|
12
|
-
const PAIR = ed25519PairFromSeed(
|
|
13
|
-
stringToU8a('12345678901234567890123456789012')
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
describe('ed25519Sign', (): void => {
|
|
17
|
-
beforeEach(async (): Promise<void> => {
|
|
18
|
-
await waitReady();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
for (const onlyJs of [false, true]) {
|
|
22
|
-
describe(`onlyJs=${(onlyJs && 'true') || 'false'}`, (): void => {
|
|
23
|
-
it('returns a valid signature for the message', (): void => {
|
|
24
|
-
expect(
|
|
25
|
-
ed25519Sign(
|
|
26
|
-
new Uint8Array([0x61, 0x62, 0x63, 0x64]),
|
|
27
|
-
PAIR,
|
|
28
|
-
onlyJs
|
|
29
|
-
)
|
|
30
|
-
).toEqual(
|
|
31
|
-
new Uint8Array([28, 58, 206, 239, 249, 70, 59, 191, 166, 40, 219, 218, 235, 170, 25, 79, 10, 94, 9, 197, 34, 126, 1, 150, 246, 68, 28, 238, 36, 26, 172, 163, 168, 90, 202, 211, 126, 246, 57, 212, 43, 24, 88, 197, 240, 113, 118, 76, 37, 81, 91, 110, 236, 50, 144, 134, 100, 223, 220, 238, 34, 185, 211, 7])
|
|
32
|
-
);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
perfWasm('ed25519Sign', 250, (input, onlyJs) =>
|
|
38
|
-
ed25519Sign(input, PAIR, onlyJs)
|
|
39
|
-
);
|
|
40
|
-
});
|
package/src/ed25519/sign.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { Keypair } from '../types.js';
|
|
5
|
-
|
|
6
|
-
import { ed25519 } from '@noble/curves/ed25519';
|
|
7
|
-
|
|
8
|
-
import { hasBigInt, u8aToU8a } from '@pezkuwi/util';
|
|
9
|
-
import { ed25519Sign as wasmSign, isReady } from '@pezkuwi/wasm-crypto';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @name ed25519Sign
|
|
13
|
-
* @summary Signs a message using the supplied secretKey
|
|
14
|
-
* @description
|
|
15
|
-
* Returns message signature of `message`, using the `secretKey`.
|
|
16
|
-
* @example
|
|
17
|
-
* <BR>
|
|
18
|
-
*
|
|
19
|
-
* ```javascript
|
|
20
|
-
* import { ed25519Sign } from '@pezkuwi/util-crypto';
|
|
21
|
-
*
|
|
22
|
-
* ed25519Sign([...], [...]); // => [...]
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export function ed25519Sign (message: string | Uint8Array, { publicKey, secretKey }: Partial<Keypair>, onlyJs?: boolean): Uint8Array {
|
|
26
|
-
if (!secretKey) {
|
|
27
|
-
throw new Error('Expected a valid secretKey');
|
|
28
|
-
} else if (!publicKey) {
|
|
29
|
-
throw new Error('Expected a valid publicKey');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const messageU8a = u8aToU8a(message);
|
|
33
|
-
const privateU8a = secretKey.subarray(0, 32);
|
|
34
|
-
|
|
35
|
-
return !hasBigInt || (!onlyJs && isReady())
|
|
36
|
-
? wasmSign(publicKey, privateU8a, messageU8a)
|
|
37
|
-
: ed25519.sign(messageU8a, privateU8a);
|
|
38
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import { stringToU8a } from '@pezkuwi/util';
|
|
7
|
-
import { waitReady } from '@pezkuwi/wasm-crypto';
|
|
8
|
-
|
|
9
|
-
import { ed25519PairFromSeed, ed25519Verify } from './index.js';
|
|
10
|
-
|
|
11
|
-
describe('ed25519Verify', (): void => {
|
|
12
|
-
let publicKey: Uint8Array;
|
|
13
|
-
let signature: Uint8Array;
|
|
14
|
-
|
|
15
|
-
beforeEach(async (): Promise<void> => {
|
|
16
|
-
await waitReady();
|
|
17
|
-
|
|
18
|
-
publicKey = ed25519PairFromSeed(
|
|
19
|
-
stringToU8a('12345678901234567890123456789012')
|
|
20
|
-
).publicKey;
|
|
21
|
-
signature = new Uint8Array([28, 58, 206, 239, 249, 70, 59, 191, 166, 40, 219, 218, 235, 170, 25, 79, 10, 94, 9, 197, 34, 126, 1, 150, 246, 68, 28, 238, 36, 26, 172, 163, 168, 90, 202, 211, 126, 246, 57, 212, 43, 24, 88, 197, 240, 113, 118, 76, 37, 81, 91, 110, 236, 50, 144, 134, 100, 223, 220, 238, 34, 185, 211, 7]);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
for (const onlyJs of [false, true]) {
|
|
25
|
-
describe(`onlyJs=${(onlyJs && 'true') || 'false'}`, (): void => {
|
|
26
|
-
it('validates a correctly signed message', (): void => {
|
|
27
|
-
expect(
|
|
28
|
-
ed25519Verify(
|
|
29
|
-
new Uint8Array([0x61, 0x62, 0x63, 0x64]),
|
|
30
|
-
signature,
|
|
31
|
-
publicKey,
|
|
32
|
-
onlyJs
|
|
33
|
-
)
|
|
34
|
-
).toEqual(true);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('fails a correctly signed message (message changed)', (): void => {
|
|
38
|
-
expect(
|
|
39
|
-
ed25519Verify(
|
|
40
|
-
new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65]),
|
|
41
|
-
signature,
|
|
42
|
-
publicKey,
|
|
43
|
-
onlyJs
|
|
44
|
-
)
|
|
45
|
-
).toEqual(false);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('fails a correctly signed message (signature changed)', (): void => {
|
|
49
|
-
signature[0] = 0xff;
|
|
50
|
-
|
|
51
|
-
expect(
|
|
52
|
-
ed25519Verify(
|
|
53
|
-
new Uint8Array([0x61, 0x62, 0x63, 0x64]),
|
|
54
|
-
signature,
|
|
55
|
-
publicKey,
|
|
56
|
-
onlyJs
|
|
57
|
-
)
|
|
58
|
-
).toEqual(false);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('throws error when publicKey lengths do not match', (): void => {
|
|
62
|
-
expect(
|
|
63
|
-
() => ed25519Verify(
|
|
64
|
-
new Uint8Array([0x61, 0x62, 0x63, 0x64]),
|
|
65
|
-
signature,
|
|
66
|
-
new Uint8Array([1, 2]),
|
|
67
|
-
onlyJs
|
|
68
|
-
)
|
|
69
|
-
).toThrow(/Invalid publicKey/);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('throws error when signature lengths do not match', (): void => {
|
|
73
|
-
expect(
|
|
74
|
-
() => ed25519Verify(
|
|
75
|
-
new Uint8Array([0x61, 0x62, 0x63, 0x64]),
|
|
76
|
-
new Uint8Array([1, 2]),
|
|
77
|
-
publicKey,
|
|
78
|
-
onlyJs
|
|
79
|
-
)
|
|
80
|
-
).toThrow(/Invalid signature/);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
});
|
package/src/ed25519/verify.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { ed25519 } from '@noble/curves/ed25519';
|
|
5
|
-
|
|
6
|
-
import { hasBigInt, u8aToU8a } from '@pezkuwi/util';
|
|
7
|
-
import { ed25519Verify as wasmVerify, isReady } from '@pezkuwi/wasm-crypto';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @name ed25519Sign
|
|
11
|
-
* @summary Verifies the signature on the supplied message.
|
|
12
|
-
* @description
|
|
13
|
-
* Verifies the `signature` on `message` with the supplied `publicKey`. Returns `true` on sucess, `false` otherwise.
|
|
14
|
-
* @example
|
|
15
|
-
* <BR>
|
|
16
|
-
*
|
|
17
|
-
* ```javascript
|
|
18
|
-
* import { ed25519Verify } from '@pezkuwi/util-crypto';
|
|
19
|
-
*
|
|
20
|
-
* ed25519Verify([...], [...], [...]); // => true/false
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export function ed25519Verify (message: string | Uint8Array, signature: string | Uint8Array, publicKey: string | Uint8Array, onlyJs?: boolean): boolean {
|
|
24
|
-
const messageU8a = u8aToU8a(message);
|
|
25
|
-
const publicKeyU8a = u8aToU8a(publicKey);
|
|
26
|
-
const signatureU8a = u8aToU8a(signature);
|
|
27
|
-
|
|
28
|
-
if (publicKeyU8a.length !== 32) {
|
|
29
|
-
throw new Error(`Invalid publicKey, received ${publicKeyU8a.length}, expected 32`);
|
|
30
|
-
} else if (signatureU8a.length !== 64) {
|
|
31
|
-
throw new Error(`Invalid signature, received ${signatureU8a.length} bytes, expected 64`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
try {
|
|
35
|
-
return !hasBigInt || (!onlyJs && isReady())
|
|
36
|
-
? wasmVerify(signatureU8a, messageU8a, publicKeyU8a)
|
|
37
|
-
: ed25519.verify(signatureU8a, messageU8a, publicKeyU8a);
|
|
38
|
-
} catch {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import { keccakAsU8a } from '../keccak/index.js';
|
|
7
|
-
import { ethereumEncode } from './index.js';
|
|
8
|
-
|
|
9
|
-
describe('formatAddress', () => {
|
|
10
|
-
describe('address to address encoding', (): void => {
|
|
11
|
-
const ADDRESS = '0x00a329c0648769A73afAc7F9381E08FB43dBEA72';
|
|
12
|
-
|
|
13
|
-
it('returns 0x for no address', () => {
|
|
14
|
-
expect(ethereumEncode()).toBe('0x');
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('returns fails on invalid address', () => {
|
|
18
|
-
expect(
|
|
19
|
-
() => ethereumEncode('0xnotaddress')
|
|
20
|
-
).toThrow(/Invalid address or publicKey provided/);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('converts lowercase to the checksummed address', () => {
|
|
24
|
-
expect(ethereumEncode(ADDRESS.toLowerCase())).toBe(ADDRESS);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('converts uppercase to the checksummed address', () => {
|
|
28
|
-
expect(ethereumEncode(ADDRESS.toUpperCase().replace('0X', '0x'))).toBe(ADDRESS);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('returns formatted address on checksum input', () => {
|
|
32
|
-
expect(ethereumEncode(ADDRESS)).toBe(ADDRESS);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('from publicKey', (): void => {
|
|
37
|
-
const ADDRESS = '0x4119b2e6c3Cb618F4f0B93ac77f9BeeC7FF02887';
|
|
38
|
-
|
|
39
|
-
it('encodes a compressed publicKey', (): void => {
|
|
40
|
-
expect(
|
|
41
|
-
ethereumEncode('0x03b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb13077')
|
|
42
|
-
).toEqual(ADDRESS);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('encodes an expanded publicKey', (): void => {
|
|
46
|
-
expect(
|
|
47
|
-
ethereumEncode('0x04b9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb1307763fe926c273235fd979a134076d00fd1683cbd35868cb485d4a3a640e52184af')
|
|
48
|
-
).toEqual(ADDRESS);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('encodes a pre-hashed key', (): void => {
|
|
52
|
-
expect(
|
|
53
|
-
ethereumEncode(
|
|
54
|
-
keccakAsU8a('0xb9dc646dd71118e5f7fda681ad9eca36eb3ee96f344f582fbe7b5bcdebb1307763fe926c273235fd979a134076d00fd1683cbd35868cb485d4a3a640e52184af')
|
|
55
|
-
)
|
|
56
|
-
).toEqual(ADDRESS);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
package/src/ethereum/encode.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import type { HexString } from '@pezkuwi/util/types';
|
|
5
|
-
|
|
6
|
-
import { u8aToHex, u8aToU8a } from '@pezkuwi/util';
|
|
7
|
-
|
|
8
|
-
import { keccakAsU8a } from '../keccak/index.js';
|
|
9
|
-
import { secp256k1Expand } from '../secp256k1/index.js';
|
|
10
|
-
|
|
11
|
-
function getH160 (u8a: Uint8Array): Uint8Array {
|
|
12
|
-
if ([33, 65].includes(u8a.length)) {
|
|
13
|
-
u8a = keccakAsU8a(secp256k1Expand(u8a));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return u8a.slice(-20);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function ethereumEncode (addressOrPublic?: string | Uint8Array): HexString {
|
|
20
|
-
if (!addressOrPublic) {
|
|
21
|
-
return '0x';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const u8aAddress = u8aToU8a(addressOrPublic);
|
|
25
|
-
|
|
26
|
-
if (![20, 32, 33, 65].includes(u8aAddress.length)) {
|
|
27
|
-
throw new Error(`Invalid address or publicKey provided, received ${u8aAddress.length} bytes input`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const address = u8aToHex(getH160(u8aAddress), -1, false);
|
|
31
|
-
const hash = u8aToHex(keccakAsU8a(address), -1, false);
|
|
32
|
-
let result = '';
|
|
33
|
-
|
|
34
|
-
for (let i = 0; i < 40; i++) {
|
|
35
|
-
result = `${result}${parseInt(hash[i], 16) > 7 ? address[i].toUpperCase() : address[i]}`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return `0x${result}`;
|
|
39
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/// <reference types="@polkadot/dev-test/globals.d.ts" />
|
|
5
|
-
|
|
6
|
-
import { isEthereumAddress } from './index.js';
|
|
7
|
-
|
|
8
|
-
const ADDRESS = '0x00a329c0648769A73afAc7F9381E08FB43dBEA72';
|
|
9
|
-
|
|
10
|
-
describe('isEthereumAddress', () => {
|
|
11
|
-
it('returns true when fully lowercase', () => {
|
|
12
|
-
expect(isEthereumAddress(ADDRESS.toLowerCase())).toBe(true);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('returns true when fully uppercase', () => {
|
|
16
|
-
expect(isEthereumAddress(ADDRESS.toUpperCase().replace('0X', '0x'))).toBe(true);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('returns true when checksummed', () => {
|
|
20
|
-
expect(isEthereumAddress(ADDRESS)).toBe(true);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('returns false when empty address', () => {
|
|
24
|
-
expect(isEthereumAddress()).toBe(false);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('returns false when invalid address', () => {
|
|
28
|
-
expect(isEthereumAddress('0xinvalid')).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('returns false when invalid address of correct length', () => {
|
|
32
|
-
expect(isEthereumAddress('0xinvalid000123456789012345678901234567890')).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
});
|