@polkadot/util-crypto

  • Version 9.1.1
  • Published
  • 863 kB
  • 11 dependencies
  • Apache-2.0 license

Install

npm i @polkadot/util-crypto
yarn add @polkadot/util-crypto
pnpm add @polkadot/util-crypto

Overview

A collection of useful crypto utilities for @polkadot

Index

Variables

Functions

Variables

variable cryptoIsReady

const cryptoIsReady: any;

    variable packageInfo

    const packageInfo: { name: string; path: string; type: string; version: string };

      Functions

      function addressEq

      addressEq: (
      a: HexString | string | Uint8Array,
      b: HexString | string | Uint8Array
      ) => boolean;
      • addressEq Compares two addresses, either in ss58, Uint8Array or hex format. For the input values, return true is the underlying public keys do match.

        Example 1

        import { u8aEq } from '@polkadot/util';
        u8aEq(new Uint8Array([0x68, 0x65]), new Uint8Array([0x68, 0x65])); // true

      function addressToEvm

      addressToEvm: (
      address: HexString | string | Uint8Array,
      ignoreChecksum?: boolean
      ) => Uint8Array;
      • addressToEvm Converts an SS58 address to its corresponding EVM address.

      function base32Decode

      base32Decode: (value: string, ipfsCompat?: boolean | undefined) => Uint8Array;
      • base32Decode Delookup a base32 value. From the provided input, decode the base32 and return the result as an Uint8Array.

      function base32Encode

      base32Encode: (value: any, ipfsCompat?: boolean | undefined) => string;
      • base32Encode Creates a base32 value. From the provided input, create the base32 and return the result as a string.

      function base32Validate

      base32Validate: (
      value?: unknown,
      ipfsCompat?: boolean | undefined
      ) => value is string;
      • base32Validate Validates a base32 value. Validates that the supplied value is valid base32, throwing exceptions if not

      function base58Decode

      base58Decode: (value: string, ipfsCompat?: boolean | undefined) => Uint8Array;
      • base58Decode Decodes a base58 value. From the provided input, decode the base58 and return the result as an Uint8Array.

      function base58Encode

      base58Encode: (value: any, ipfsCompat?: boolean | undefined) => string;
      • base58Encode Creates a base58 value. From the provided input, create the base58 and return the result as a string.

      function base58Validate

      base58Validate: (
      value?: unknown,
      ipfsCompat?: boolean | undefined
      ) => value is string;
      • base58Validate Validates a base58 value. Validates that the supplied value is valid base58, throwing exceptions if not

      function base64Decode

      base64Decode: (value: string, ipfsCompat?: boolean | undefined) => Uint8Array;
      • base64Decode Decodes a base64 value. From the provided input, decode the base64 and return the result as an Uint8Array.

      function base64Encode

      base64Encode: (value: any, ipfsCompat?: boolean | undefined) => string;
      • base64Encode Creates a base64 value. From the provided input, create the base64 and return the result as a string.

      function base64Pad

      base64Pad: (value: string) => string;
      • base64Pad Adds padding characters for correct length

      function base64Trim

      base64Trim: (value: string) => string;
      • base64Trim Trims padding characters

      function base64Validate

      base64Validate: (
      value?: unknown,
      ipfsCompat?: boolean | undefined
      ) => value is string;
      • base64Validate Validates a base64 value. Validates that the supplied value is valid base64

      function blake2AsHex

      blake2AsHex: (
      data: string | Uint8Array,
      bitLength?: BitLength | undefined,
      key?: Uint8Array | null | undefined,
      onlyJs?: boolean | undefined
      ) => `0x${string}`;
      • blake2AsHex Creates a blake2b hex from the input.

      function blake2AsU8a

      blake2AsU8a: (
      data: HexString | Uint8Array | string,
      bitLength?: BitLength,
      key?: Uint8Array | null,
      onlyJs?: boolean
      ) => Uint8Array;
      • blake2AsU8a Creates a blake2b u8a from the input. From a Uint8Array input, create the blake2b and return the result as a u8a with the specified bitLength.

        Example 1

        import { blake2AsU8a } from '@polkadot/util-crypto';
        blake2AsU8a('abc'); // => [0xba, 0x80, 0xa5, 0x3f, 0x98, 0x1c, 0x4d, 0x0d]

      function checkAddress

      checkAddress: (
      address: HexString | string,
      prefix: Prefix
      ) => [boolean, string | null];
      • checkAddress Validates an ss58 address. From the provided input, validate that the address is a valid input.

      function checkAddressChecksum

      checkAddressChecksum: (decoded: Uint8Array) => [boolean, number, number, number];

        function convertPublicKeyToCurve25519

        convertPublicKeyToCurve25519: (publicKey: Uint8Array) => Uint8Array;

          function convertSecretKeyToCurve25519

          convertSecretKeyToCurve25519: (secretKey: Uint8Array) => Uint8Array;

            function createKeyDerived

            createKeyDerived: (
            who: HexString | Uint8Array | string,
            index: bigint | BN | number
            ) => Uint8Array;

              function createKeyMulti

              createKeyMulti: (
              who: (HexString | Uint8Array | string)[],
              threshold: bigint | BN | number
              ) => Uint8Array;

                function cryptoWaitReady

                cryptoWaitReady: () => Promise<boolean>;

                  function decodeAddress

                  decodeAddress: (
                  encoded?: HexString | string | Uint8Array | null,
                  ignoreChecksum?: boolean,
                  ss58Format?: Prefix
                  ) => Uint8Array;

                    function deriveAddress

                    deriveAddress: (
                    who: HexString | Uint8Array | string,
                    suri: string,
                    ss58Format?: Prefix
                    ) => string;
                    • deriveAddress Creates a sr25519 derived address from the supplied and path. Creates a sr25519 derived address based on the input address/publicKey and the uri supplied.

                    function ed25519DeriveHard

                    ed25519DeriveHard: (seed: Uint8Array, chainCode: Uint8Array) => Uint8Array;

                      function ed25519PairFromRandom

                      ed25519PairFromRandom: () => Keypair;
                      • ed25519PairFromRandom Creates a new public/secret keypair. Returns a new generate object containing a publicKey & secretKey.

                        Example 1

                        import { ed25519PairFromRandom } from '@polkadot/util-crypto';
                        ed25519PairFromRandom(); // => { secretKey: [...], publicKey: [...] }

                      function ed25519PairFromSecret

                      ed25519PairFromSecret: (secret: Uint8Array) => Keypair;
                      • ed25519PairFromSecret Creates a new public/secret keypair from a secret. Returns a object containing a publicKey & secretKey generated from the supplied secret.

                        Example 1

                        import { ed25519PairFromSecret } from '@polkadot/util-crypto';
                        ed25519PairFromSecret(...); // => { secretKey: [...], publicKey: [...] }

                      function ed25519PairFromSeed

                      ed25519PairFromSeed: (seed: Uint8Array, onlyJs?: boolean) => Keypair;
                      • ed25519PairFromSeed Creates a new public/secret keypair from a seed. Returns a object containing a publicKey & secretKey generated from the supplied seed.

                        Example 1

                        import { ed25519PairFromSeed } from '@polkadot/util-crypto';
                        ed25519PairFromSeed(...); // => { secretKey: [...], publicKey: [...] }

                      function ed25519PairFromString

                      ed25519PairFromString: (value: string) => Keypair;
                      • ed25519PairFromString Creates a new public/secret keypair from a string. Returns a object containing a publicKey & secretKey generated from the supplied string. The string is hashed and the value used as the input seed.

                        Example 1

                        import { ed25519PairFromString } from '@polkadot/util-crypto';
                        ed25519PairFromString('test'); // => { secretKey: [...], publicKey: [...] }

                      function ed25519Sign

                      ed25519Sign: (
                      message: HexString | Uint8Array | string,
                      { publicKey, secretKey }: Partial<Keypair>,
                      onlyJs?: boolean
                      ) => Uint8Array;
                      • ed25519Sign Signs a message using the supplied secretKey Returns message signature of message, using the secretKey.

                        Example 1

                        import { ed25519Sign } from '@polkadot/util-crypto';
                        ed25519Sign([...], [...]); // => [...]

                      function ed25519Verify

                      ed25519Verify: (
                      message: HexString | Uint8Array | string,
                      signature: HexString | Uint8Array | string,
                      publicKey: HexString | Uint8Array | string,
                      onlyJs?: boolean
                      ) => boolean;
                      • ed25519Sign Verifies the signature on the supplied message. Verifies the signature on message with the supplied publicKey. Returns true on sucess, false otherwise.

                        Example 1

                        import { ed25519Verify } from '@polkadot/util-crypto';
                        ed25519Verify([...], [...], [...]); // => true/false

                      function encodeAddress

                      encodeAddress: (
                      key: HexString | Uint8Array | string,
                      ss58Format?: Prefix
                      ) => string;

                        function encodeDerivedAddress

                        encodeDerivedAddress: (
                        who: HexString | Uint8Array | string,
                        index: bigint | BN | number,
                        ss58Format?: Prefix
                        ) => string;
                        • encodeDerivedAddress Creates a derived address as used in Substrate utility. Creates a Substrate derived address based on the input address/publicKey and the index supplied.

                        function encodeMultiAddress

                        encodeMultiAddress: (
                        who: (HexString | Uint8Array | string)[],
                        threshold: bigint | BN | number,
                        ss58Format?: Prefix
                        ) => string;
                        • encodeMultiAddress Creates a multisig address. Creates a Substrate multisig address based on the input address and the required threshold.

                        function ethereumEncode

                        ethereumEncode: (addressOrPublic?: HexString | string | Uint8Array) => HexString;

                          function evmToAddress

                          evmToAddress: (
                          evmAddress: HexString | string | Uint8Array,
                          ss58Format?: Prefix,
                          hashType?: HashType
                          ) => string;
                          • evmToAddress Converts an EVM address to its corresponding SS58 address.

                          function hdEthereum

                          hdEthereum: (seed: Uint8Array, path?: string) => Keypair;

                            function hdLedger

                            hdLedger: (_mnemonic: string, path: string) => Keypair;

                              function hdValidatePath

                              hdValidatePath: (path: string) => boolean;

                                function hmacSha256AsU8a

                                hmacSha256AsU8a: (
                                key: Uint8Array | string,
                                data: Uint8Array,
                                onlyJs?: boolean | undefined
                                ) => Uint8Array;
                                • hmacSha256AsU8a creates a Hmac Sha256 Uint8Array from the key & data

                                function hmacSha512AsU8a

                                hmacSha512AsU8a: (
                                key: Uint8Array | string,
                                data: Uint8Array,
                                onlyJs?: boolean | undefined
                                ) => Uint8Array;
                                • hmacSha512AsU8a creates a Hmac Sha512 Uint8Array from the key & data

                                function hmacShaAsU8a

                                hmacShaAsU8a: (
                                key: Uint8Array | string,
                                data: Uint8Array,
                                bitLength?: BitLength,
                                onlyJs?: boolean
                                ) => Uint8Array;
                                • hmacShaAsU8a creates a Hmac Sha (256/512) Uint8Array from the key & data

                                function isAddress

                                isAddress: (
                                address?: HexString | string | null,
                                ignoreChecksum?: boolean,
                                ss58Format?: Prefix
                                ) => address is string;

                                  function isBase32

                                  isBase32: (value?: unknown, ipfsCompat?: boolean | undefined) => value is string;
                                  • isBase32 Checks if the input is in base32, returning true/false

                                  function isBase58

                                  isBase58: (value?: unknown, ipfsCompat?: boolean | undefined) => value is string;
                                  • isBase58 Checks if the input is in base58, returning true/false

                                  function isBase64

                                  isBase64: (value?: unknown, ipfsCompat?: boolean | undefined) => value is string;
                                  • isBase64 Checks if the input is in base64, returning true/false

                                  function isEthereumAddress

                                  isEthereumAddress: (address?: HexString | string) => boolean;

                                    function isEthereumChecksum

                                    isEthereumChecksum: (_address: string) => boolean;

                                      function jsonDecrypt

                                      jsonDecrypt: (
                                      { encoded, encoding }: EncryptedJson,
                                      passphrase?: string | null
                                      ) => Uint8Array;

                                        function jsonDecryptData

                                        jsonDecryptData: (
                                        encrypted?: Uint8Array | null,
                                        passphrase?: string | null,
                                        encType?: EncryptedJsonEncoding[]
                                        ) => Uint8Array;

                                          function jsonEncrypt

                                          jsonEncrypt: (
                                          data: Uint8Array,
                                          contentType: string[],
                                          passphrase?: string | null
                                          ) => EncryptedJson;

                                            function jsonEncryptFormat

                                            jsonEncryptFormat: (
                                            encoded: Uint8Array,
                                            contentType: string[],
                                            isEncrypted: boolean
                                            ) => EncryptedJson;

                                              function keccak256AsU8a

                                              keccak256AsU8a: (
                                              data: string | Uint8Array | Buffer,
                                              onlyJs?: boolean | undefined
                                              ) => Uint8Array;
                                              • keccak256AsU8a Creates a keccak256 Uint8Array from the input.

                                              function keccak512AsU8a

                                              keccak512AsU8a: (
                                              data: string | Uint8Array | Buffer,
                                              onlyJs?: boolean | undefined
                                              ) => Uint8Array;
                                              • keccak512AsU8a Creates a keccak512 Uint8Array from the input.

                                              function keccakAsHex

                                              keccakAsHex: (
                                              value: string | Uint8Array | Buffer,
                                              bitLength?: 256 | 512 | undefined,
                                              onlyJs?: boolean | undefined
                                              ) => `0x${string}`;
                                              • keccakAsHex Creates a keccak hex string from the input.

                                              function keccakAsU8a

                                              keccakAsU8a: (
                                              value: string | Uint8Array | Buffer,
                                              bitLength?: 256 | 512 | undefined,
                                              onlyJs?: boolean | undefined
                                              ) => Uint8Array;
                                              • keccakAsU8a Creates a keccak Uint8Array from the input. From either a string or a Buffer input, create the keccak and return the result as a Uint8Array.

                                                Example 1

                                                import { keccakAsU8a } from '@polkadot/util-crypto';
                                                keccakAsU8a('123'); // => Uint8Array

                                              function keyExtractPath

                                              keyExtractPath: (derivePath: string) => ExtractResult;
                                              • Extract derivation junctions from the supplied path

                                              function keyExtractSuri

                                              keyExtractSuri: (suri: string) => ExtractResult;
                                              • Extracts the phrase, path and password from a SURI format for specifying secret keys <secret>/<soft-key>//<hard-key>///<password> (the ///password may be omitted, and /<soft-key> and //<hard-key> maybe repeated and mixed).

                                              function keyFromPath

                                              keyFromPath: (
                                              pair: Keypair,
                                              path: DeriveJunction[],
                                              type: KeypairType
                                              ) => Keypair;

                                                function keyHdkdEcdsa

                                                keyHdkdEcdsa: (
                                                keypair: import('../types').Keypair,
                                                junction: import('./DeriveJunction').DeriveJunction
                                                ) => import('../types').Keypair;

                                                  function keyHdkdEd25519

                                                  keyHdkdEd25519: (
                                                  keypair: import('../types').Keypair,
                                                  junction: import('./DeriveJunction').DeriveJunction
                                                  ) => import('../types').Keypair;

                                                    function keyHdkdSr25519

                                                    keyHdkdSr25519: (
                                                    keypair: Keypair,
                                                    { chainCode, isSoft }: DeriveJunction
                                                    ) => Keypair;

                                                      function mnemonicGenerate

                                                      mnemonicGenerate: (numWords?: WordCount, onlyJs?: boolean) => string;
                                                      • mnemonicGenerate Creates a valid mnemonic string using using [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki).

                                                        Example 1

                                                        import { mnemonicGenerate } from '@polkadot/util-crypto';
                                                        const mnemonic = mnemonicGenerate(); // => string

                                                      function mnemonicToEntropy

                                                      mnemonicToEntropy: (mnemonic: string, onlyJs?: boolean) => Uint8Array;

                                                        function mnemonicToLegacySeed

                                                        mnemonicToLegacySeed: (
                                                        mnemonic: string,
                                                        password?: string,
                                                        onlyJs?: boolean,
                                                        byteLength?: 32 | 64
                                                        ) => Uint8Array;
                                                        • mnemonicToLegacySeed Creates a valid Ethereum/Bitcoin-compatible seed from a mnemonic input

                                                          Example 1

                                                          import { mnemonicGenerate, mnemonicToLegacySeed, mnemonicValidate } from '@polkadot/util-crypto';
                                                          const mnemonic = mnemonicGenerate(); // => string
                                                          const isValidMnemonic = mnemonicValidate(mnemonic); // => boolean
                                                          if (isValidMnemonic) {
                                                          console.log(`Seed generated from mnemonic: ${mnemonicToLegacySeed(mnemonic)}`); => u8a
                                                          }

                                                        function mnemonicToMiniSecret

                                                        mnemonicToMiniSecret: (
                                                        mnemonic: string,
                                                        password?: string,
                                                        onlyJs?: boolean
                                                        ) => Uint8Array;

                                                          function mnemonicValidate

                                                          mnemonicValidate: (mnemonic: string, onlyJs?: boolean) => boolean;
                                                          • mnemonicValidate Validates a mnemonic input using [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki).

                                                            Example 1

                                                            import { mnemonicGenerate, mnemonicValidate } from '@polkadot/util-crypto';
                                                            const mnemonic = mnemonicGenerate(); // => string
                                                            const isValidMnemonic = mnemonicValidate(mnemonic); // => boolean

                                                          function naclBoxPairFromSecret

                                                          naclBoxPairFromSecret: (secret: Uint8Array) => Keypair;
                                                          • naclBoxPairFromSecret Creates a new public/secret box keypair from a secret. Returns a object containing a box publicKey & secretKey generated from the supplied secret.

                                                            Example 1

                                                            import { naclBoxPairFromSecret } from '@polkadot/util-crypto';
                                                            naclBoxPairFromSecret(...); // => { secretKey: [...], publicKey: [...] }

                                                          function naclDecrypt

                                                          naclDecrypt: (
                                                          encrypted: Uint8Array,
                                                          nonce: Uint8Array,
                                                          secret: Uint8Array
                                                          ) => Uint8Array | null;
                                                          • naclDecrypt Decrypts a message using the supplied secretKey and nonce Returns an decrypted message, using the secret and nonce.

                                                            Example 1

                                                            import { naclDecrypt } from '@polkadot/util-crypto';
                                                            naclDecrypt([...], [...], [...]); // => [...]

                                                          function naclEncrypt

                                                          naclEncrypt: (
                                                          message: Uint8Array,
                                                          secret: Uint8Array,
                                                          nonce?: Uint8Array
                                                          ) => Encrypted;
                                                          • naclEncrypt Encrypts a message using the supplied secretKey and nonce Returns an encrypted message, using the secretKey and nonce. If the nonce was not supplied, a random value is generated.

                                                            Example 1

                                                            import { naclEncrypt } from '@polkadot/util-crypto';
                                                            naclEncrypt([...], [...]); // => [...]

                                                          function naclOpen

                                                          naclOpen: (
                                                          sealed: Uint8Array,
                                                          nonce: Uint8Array,
                                                          senderBoxPublic: Uint8Array,
                                                          receiverBoxSecret: Uint8Array
                                                          ) => Uint8Array | null;
                                                          • naclOpen Opens a message using the receiver's secretKey and nonce Returns a message sealed by the sender, using the receiver's secret and nonce.

                                                            Example 1

                                                            import { naclOpen } from '@polkadot/util-crypto';
                                                            naclOpen([...], [...], [...]); // => [...]

                                                          function naclSeal

                                                          naclSeal: (
                                                          message: Uint8Array,
                                                          senderBoxSecret: Uint8Array,
                                                          receiverBoxPublic: Uint8Array,
                                                          nonce?: Uint8Array
                                                          ) => Sealed;
                                                          • naclSeal Seals a message using the sender's encrypting secretKey, receiver's public key, and nonce Returns an encrypted message which can be open only by receiver's secretKey. If the nonce was not supplied, a random value is generated.

                                                            Example 1

                                                            import { naclSeal } from '@polkadot/util-crypto';
                                                            naclSeal([...], [...], [...], [...]); // => [...]

                                                          function pbkdf2Encode

                                                          pbkdf2Encode: (
                                                          passphrase?: HexString | Buffer | Uint8Array | string,
                                                          salt?: Buffer | Uint8Array,
                                                          rounds?: number,
                                                          onlyJs?: boolean
                                                          ) => Result;

                                                            function randomAsHex

                                                            randomAsHex: (length?: number | undefined) => `0x${string}`;
                                                            • randomAsHex Creates a hex string filled with random bytes.

                                                            function randomAsNumber

                                                            randomAsNumber: () => number;
                                                            • randomAsNumber Creates a random number from random bytes. Returns a random number generated from the secure bytes.

                                                              Example 1

                                                              import { randomAsNumber } from '@polkadot/util-crypto';
                                                              randomAsNumber(); // => <random number>

                                                            function randomAsU8a

                                                            randomAsU8a: (length?: number) => Uint8Array;
                                                            • randomAsU8a Creates a Uint8Array filled with random bytes. Returns a Uint8Array with the specified (optional) length filled with random bytes.

                                                              Example 1

                                                              import { randomAsU8a } from '@polkadot/util-crypto';
                                                              randomAsU8a(); // => Uint8Array([...])

                                                            function scryptEncode

                                                            scryptEncode: (
                                                            passphrase?: HexString | Uint8Array | string,
                                                            salt?: Uint8Array,
                                                            params?: { N: number; p: number; r: number },
                                                            onlyJs?: boolean
                                                            ) => Result;

                                                              function scryptFromU8a

                                                              scryptFromU8a: (data: Uint8Array) => Result;

                                                                function scryptToU8a

                                                                scryptToU8a: (salt: Uint8Array, { N, p, r }: Params) => Uint8Array;

                                                                  function secp256k1Compress

                                                                  secp256k1Compress: (publicKey: Uint8Array, onlyJs?: boolean) => Uint8Array;

                                                                    function secp256k1Expand

                                                                    secp256k1Expand: (publicKey: Uint8Array, onlyJs?: boolean) => Uint8Array;

                                                                      function secp256k1PairFromSeed

                                                                      secp256k1PairFromSeed: (seed: Uint8Array, onlyJs?: boolean) => Keypair;
                                                                      • secp256k1PairFromSeed Returns a object containing a publicKey & secretKey generated from the supplied seed.

                                                                      function secp256k1PrivateKeyTweakAdd

                                                                      secp256k1PrivateKeyTweakAdd: (
                                                                      seckey: Uint8Array,
                                                                      tweak: Uint8Array,
                                                                      onlyBn?: boolean
                                                                      ) => Uint8Array;

                                                                        function secp256k1Recover

                                                                        secp256k1Recover: (
                                                                        msgHash: HexString | Uint8Array | string,
                                                                        signature: HexString | Uint8Array | string,
                                                                        recovery: number,
                                                                        hashType?: HashType,
                                                                        onlyJs?: boolean
                                                                        ) => Uint8Array;
                                                                        • secp256k1Recover Recovers a publicKey from the supplied signature

                                                                        function secp256k1Sign

                                                                        secp256k1Sign: (
                                                                        message: Uint8Array | string,
                                                                        { secretKey }: Partial<Keypair>,
                                                                        hashType?: HashType,
                                                                        onlyJs?: boolean
                                                                        ) => Uint8Array;
                                                                        • secp256k1Sign Returns message signature of message, using the supplied pair

                                                                        function secp256k1Verify

                                                                        secp256k1Verify: (
                                                                        msgHash: HexString | Uint8Array | string,
                                                                        signature: HexString | Uint8Array | string,
                                                                        address: HexString | Uint8Array | string,
                                                                        hashType?: HashType,
                                                                        onlyJs?: boolean
                                                                        ) => boolean;
                                                                        • secp256k1Verify Verifies the signature of message, using the supplied pair

                                                                        function setSS58Format

                                                                        setSS58Format: (prefix: Prefix) => void;
                                                                        • Sets the global SS58 format to use for address encoding

                                                                          Deprecated

                                                                          Use keyring.setSS58Format

                                                                        function sha256AsU8a

                                                                        sha256AsU8a: (
                                                                        data: string | Uint8Array | Buffer,
                                                                        onlyJs?: boolean | undefined
                                                                        ) => Uint8Array;
                                                                        • sha256AsU8a Creates a sha256 Uint8Array from the input.

                                                                        function sha512AsU8a

                                                                        sha512AsU8a: (
                                                                        data: string | Uint8Array | Buffer,
                                                                        onlyJs?: boolean | undefined
                                                                        ) => Uint8Array;
                                                                        • sha512AsU8a Creates a sha512 Uint8Array from the input.

                                                                        function shaAsU8a

                                                                        shaAsU8a: (
                                                                        value: string | Uint8Array | Buffer,
                                                                        bitLength?: 256 | 512 | undefined,
                                                                        onlyJs?: boolean | undefined
                                                                        ) => Uint8Array;
                                                                        • shaAsU8a Creates a sha Uint8Array from the input.

                                                                        function signatureVerify

                                                                        signatureVerify: (
                                                                        message: HexString | Uint8Array | string,
                                                                        signature: HexString | Uint8Array | string,
                                                                        addressOrPublicKey: HexString | Uint8Array | string
                                                                        ) => VerifyResult;

                                                                          function sortAddresses

                                                                          sortAddresses: (
                                                                          addresses: (HexString | Uint8Array | string)[],
                                                                          ss58Format?: Prefix
                                                                          ) => string[];

                                                                            function sr25519Agreement

                                                                            sr25519Agreement: (
                                                                            secretKey: HexString | Uint8Array | string,
                                                                            publicKey: HexString | Uint8Array | string
                                                                            ) => Uint8Array;
                                                                            • sr25519Agreement Key agreement between other's public key and self secret key

                                                                            function sr25519DeriveHard

                                                                            sr25519DeriveHard: (
                                                                            keypair: import('../types').Keypair,
                                                                            chainCode: Uint8Array
                                                                            ) => import('../types').Keypair;

                                                                              function sr25519DerivePublic

                                                                              sr25519DerivePublic: (
                                                                              publicKey: HexString | Uint8Array | string,
                                                                              chainCode: Uint8Array
                                                                              ) => Uint8Array;

                                                                                function sr25519DeriveSoft

                                                                                sr25519DeriveSoft: (
                                                                                keypair: import('../types').Keypair,
                                                                                chainCode: Uint8Array
                                                                                ) => import('../types').Keypair;

                                                                                  function sr25519PairFromSeed

                                                                                  sr25519PairFromSeed: (seed: HexString | Uint8Array | string) => Keypair;
                                                                                  • sr25519PairFromSeed Returns a object containing a publicKey & secretKey generated from the supplied seed.

                                                                                  function sr25519Sign

                                                                                  sr25519Sign: (
                                                                                  message: HexString | Uint8Array | string,
                                                                                  { publicKey, secretKey }: Partial<Keypair>
                                                                                  ) => Uint8Array;
                                                                                  • sr25519Sign Returns message signature of message, using the supplied pair

                                                                                  function sr25519Verify

                                                                                  sr25519Verify: (
                                                                                  message: HexString | Uint8Array | string,
                                                                                  signature: HexString | Uint8Array | string,
                                                                                  publicKey: HexString | Uint8Array | string
                                                                                  ) => boolean;
                                                                                  • sr25519Verify Verifies the signature of message, using the supplied pair

                                                                                  function sr25519VrfSign

                                                                                  sr25519VrfSign: (
                                                                                  message: HexString | Uint8Array | string,
                                                                                  { secretKey }: Partial<Keypair>,
                                                                                  context?: HexString | string | Uint8Array,
                                                                                  extra?: HexString | string | Uint8Array
                                                                                  ) => Uint8Array;
                                                                                  • sr25519VrfSign Sign with sr25519 vrf signing (deterministic)

                                                                                  function sr25519VrfVerify

                                                                                  sr25519VrfVerify: (
                                                                                  message: HexString | Uint8Array | string,
                                                                                  signOutput: HexString | string | Uint8Array,
                                                                                  publicKey: HexString | Uint8Array | string,
                                                                                  context?: HexString | string | Uint8Array,
                                                                                  extra?: HexString | string | Uint8Array
                                                                                  ) => boolean;
                                                                                  • sr25519VrfVerify Verify with sr25519 vrf verification

                                                                                  function validateAddress

                                                                                  validateAddress: (
                                                                                  encoded?: HexString | string | null,
                                                                                  ignoreChecksum?: boolean,
                                                                                  ss58Format?: Prefix
                                                                                  ) => encoded is string;

                                                                                    function xxhashAsHex

                                                                                    xxhashAsHex: (
                                                                                    data: string | Uint8Array | Buffer,
                                                                                    bitLength?: BitLength | undefined,
                                                                                    onlyJs?: boolean | undefined
                                                                                    ) => `0x${string}`;
                                                                                    • xxhashAsHex Creates a xxhash64 hex from the input.

                                                                                    function xxhashAsU8a

                                                                                    xxhashAsU8a: (
                                                                                    data: HexString | Buffer | Uint8Array | string,
                                                                                    bitLength?: BitLength,
                                                                                    onlyJs?: boolean
                                                                                    ) => Uint8Array;
                                                                                    • xxhashAsU8a Creates a xxhash64 u8a from the input. From either a string, Uint8Array or a Buffer input, create the xxhash64 and return the result as a Uint8Array with the specified bitLength.

                                                                                      Example 1

                                                                                      import { xxhashAsU8a } from '@polkadot/util-crypto';
                                                                                      xxhashAsU8a('abc'); // => 0x44bc2cf5ad770999

                                                                                    Package Files (86)

                                                                                    Dependencies (11)

                                                                                    Dev Dependencies (0)

                                                                                    No dev dependencies.

                                                                                    Peer Dependencies (1)

                                                                                    Badge

                                                                                    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@polkadot/util-crypto.

                                                                                    • Markdown
                                                                                      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@polkadot/util-crypto)
                                                                                    • HTML
                                                                                      <a href="https://www.jsdocs.io/package/@polkadot/util-crypto"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>