Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @taquito/utils

Index

Variables

Const VERSION

VERSION: { commitHash: string; version: string } = ...

Type declaration

  • commitHash: string
  • version: string

Const prefix

prefix: { B: Uint8Array; BLpk: Uint8Array; Co: Uint8Array; KT: Uint8Array; KT1: Uint8Array; LLo: Uint8Array; Lo: Uint8Array; Net: Uint8Array; P: Uint8Array; TZ: Uint8Array; edesk: Uint8Array; edpk: Uint8Array; edsig: Uint8Array; edsk: Uint8Array; edsk2: Uint8Array; expr: Uint8Array; id: Uint8Array; nce: Uint8Array; o: Uint8Array; p2esk: Uint8Array; p2pk: Uint8Array; p2sig: Uint8Array; p2sk: Uint8Array; sask: Uint8Array; sig: Uint8Array; spesk: Uint8Array; sppk: Uint8Array; spsig: Uint8Array; spsk: Uint8Array; sr1: Uint8Array; src1: Uint8Array; txM: Uint8Array; txc: Uint8Array; txi: Uint8Array; txm: Uint8Array; txmr: Uint8Array; txr1: Uint8Array; txw: Uint8Array; tz1: Uint8Array; tz2: Uint8Array; tz3: Uint8Array; tz4: Uint8Array; vh: Uint8Array; zet1: Uint8Array } = ...

Type declaration

  • B: Uint8Array
  • BLpk: Uint8Array
  • Co: Uint8Array
  • KT: Uint8Array
  • KT1: Uint8Array
  • LLo: Uint8Array
  • Lo: Uint8Array
  • Net: Uint8Array
  • P: Uint8Array
  • TZ: Uint8Array
  • edesk: Uint8Array
  • edpk: Uint8Array
  • edsig: Uint8Array
  • edsk: Uint8Array
  • edsk2: Uint8Array
  • expr: Uint8Array
  • id: Uint8Array
  • nce: Uint8Array
  • o: Uint8Array
  • p2esk: Uint8Array
  • p2pk: Uint8Array
  • p2sig: Uint8Array
  • p2sk: Uint8Array
  • sask: Uint8Array
  • sig: Uint8Array
  • spesk: Uint8Array
  • sppk: Uint8Array
  • spsig: Uint8Array
  • spsk: Uint8Array
  • sr1: Uint8Array
  • src1: Uint8Array
  • txM: Uint8Array
  • txc: Uint8Array
  • txi: Uint8Array
  • txm: Uint8Array
  • txmr: Uint8Array
  • txr1: Uint8Array
  • txw: Uint8Array
  • tz1: Uint8Array
  • tz2: Uint8Array
  • tz3: Uint8Array
  • tz4: Uint8Array
  • vh: Uint8Array
  • zet1: Uint8Array

Const prefixLength

prefixLength: {} = ...

Type declaration

  • [key: string]: number

Functions

Const b58cdecode

  • b58cdecode(enc: string, prefixArg: Uint8Array): Uint8Array

b58cencode

  • b58cencode(value: string | Uint8Array, prefix: Uint8Array): string
  • description

    Base58 encode a string or a Uint8Array and append a prefix to it

    Parameters

    • value: string | Uint8Array

      Value to base58 encode

    • prefix: Uint8Array

      prefix to append to the encoded string

    Returns string

b58decode

  • b58decode(payload: string): string

b58decodeL2Address

  • b58decodeL2Address(payload: string): string

Const buf2hex

  • buf2hex(buffer: Buffer): string

bytes2Char

  • bytes2Char(hex: string): string

char2Bytes

  • char2Bytes(str: string): string

encodeExpr

  • encodeExpr(value: string): string
  • description

    Hash a string using the BLAKE2b algorithm, base58 encode the hash obtained and appends the prefix 'expr' to it

    Parameters

    • value: string

      Value in hex

    Returns string

encodeKey

  • encodeKey(value: string): undefined | string

encodeKeyHash

  • encodeKeyHash(value: string): undefined | string

encodeL2Address

  • encodeL2Address(value: string): string

encodeOpHash

  • encodeOpHash(value: string): string

encodePubKey

  • encodePubKey(value: string): string

format

  • format(from?: Format, to?: Format, amount: number | string | BigNumber): string | number | BigNumber

Const getPkhfromPk

  • getPkhfromPk(publicKey: string): string
  • description

    Gets Tezos address (PKH) from Public Key

    Parameters

    • publicKey: string

      Public Key

    Returns string

    A string of the Tezos address (PKH) that was derived from the given Public Key

hex2Bytes

  • hex2Bytes(hex: string): Buffer

Const hex2buf

  • hex2buf(hex: string): Uint8Array

invalidDetail

isValidPrefix

  • isValidPrefix(value: unknown): value is Prefix

Const mergebuf

  • mergebuf(b1: Uint8Array, b2: Uint8Array): Uint8Array

Const mic2arr

  • mic2arr(s: any): any

num2PaddedHex

  • num2PaddedHex(val: number | BigNumber, bitLength?: number): string
  • description

    Converts a number or BigNumber to a padded hexadecimal string

    Parameters

    • val: number | BigNumber

      The value that will be converted into a padded hexadecimal string value

    • bitLength: number = 8

      The length of bits

    Returns string

stripHexPrefix

  • stripHexPrefix(hex: string): string

toHexBuf

  • toHexBuf(val: number | BigNumber, bitLength?: number): Buffer
  • description

    Converts a number or Bignumber to hexadecimal string

    Parameters

    • val: number | BigNumber

      The value that will be converted to a hexadecimal string value

    • bitLength: number = 8

    Returns Buffer

validateAddress

  • description

    Used to check if an address or a contract address is valid.

    example
    import { validateAddress } from '@taquito/utils';
    const pkh = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
    const validation = validateAddress(pkh)
    console.log(validation)
    // This example return 3 which correspond to VALID
    

    Parameters

    • value: string

    Returns ValidationResult

    0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).

validateBlock

  • description

    Used to check if a block hash is valid.

    example
    import { validateBlock } from '@taquito/utils';
    const blockHash = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
    const validation = validateBlock(blockHash)
    console.log(validation)
    // This example return 3 which correspond to VALID
    

    Parameters

    • value: string

    Returns ValidationResult

    0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).

validateChain

  • description

    Used to check if a chain id is valid.

    example
    import { validateChain } from '@taquito/utils';
    const chainId = 'NetXdQprcVkpaWU'
    const validation = validateChain(chainId)
    console.log(validation)
    // This example return 3 which correspond to VALID
    

    Parameters

    • value: string

    Returns ValidationResult

    0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).

validateContractAddress

  • description

    Used to check if a contract address is valid.

    example
    import { validateContractAddress } from '@taquito/utils';
    const contractAddress = 'KT1JVErLYTgtY8uGGZ4mso2npTSxqVLDRVbC'
    const validation = validateContractAddress(contractAddress)
    console.log(validation)
    // This example return 3 which correspond to VALID
    

    Parameters

    • value: string

    Returns ValidationResult

    0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).

validateKeyHash

  • description

    Used to check if a key hash is valid.

    example
    import { validateKeyHash } from '@taquito/utils';
    const keyHashWithoutPrefix = '1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx'
    const validation = validateKeyHash(keyHashWithoutPrefix)
    console.log(validation)
    // This example return 0 which correspond to NO_PREFIX_MATCHED
    

    Parameters

    • value: string

    Returns ValidationResult

    0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).

validateOperation

  • description

    Used to check if an operation hash is valid.

    example
    import { validateOperation } from '@taquito/utils';
    const operationHash = 'oo6JPEAy8VuMRGaFuMmLNFFGdJgiaKfnmT1CpHJfKP3Ye5ZahiP'
    const validation = validateOperation(operationHash)
    console.log(validation)
    // This example return 3 which correspond to VALID
    

    Parameters

    • value: string

    Returns ValidationResult

    0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).

validatePkAndExtractPrefix

  • validatePkAndExtractPrefix(publicKey: string): PkPrefix

validateProtocol

  • description

    Used to check if a protocol hash is valid.

    example
    import { validateProtocol } from '@taquito/utils';
    const protocolHash = 'PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx'
    const validation = validateProtocol(protocolHash)
    console.log(validation)
    // This example return 3 which correspond to VALID
    

    Parameters

    • value: string

    Returns ValidationResult

    0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).

validatePublicKey

  • description

    Used to check if a public key is valid.

    example
    import { validatePublicKey } from '@taquito/utils';
    const publicKey = 'edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g'
    const validation = validatePublicKey(publicKey)
    console.log(validation)
    // This example return 3 which correspond to VALID
    

    Parameters

    • value: string

    Returns ValidationResult

    0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).

validateSignature

  • description

    Used to check if a signature is valid.

    example
    import { validateSignature } from '@taquito/utils';
    const signature = 'edsigtkpiSSschcaCt9pUVrpNPf7TTcgvgDEDD6NCEHMy8NNQJCGnMfLZzYoQj74yLjo9wx6MPVV29CvVzgi7qEcEUok3k7AuMg'
    const validation = validateSignature(signature)
    console.log(validation)
    // This example return 3 which correspond to VALID
    

    Parameters

    • value: string

    Returns ValidationResult

    0 (NO_PREFIX_MATCHED), 1 (INVALID_CHECKSUM), 2 (INVALID_LENGTH) or 3 (VALID).

validateSmartRollupAddress

validateSpendingKey

verifySignature

  • verifySignature(messageBytes: string, publicKey: string, signature: string, watermark?: Uint8Array): boolean
  • description

    Verify signature of a payload

    throws

    InvalidPublicKeyError | InvalidSignatureError | InvalidMessageError

    example
    const message = '03d0c10e3ed11d7c6e3357f6ef335bab9e8f2bd54d0ce20c482e241191a6e4b8ce6c01be917311d9ac46959750e405d57e268e2ed9e174a80794fbd504e12a4a000141eb3781afed2f69679ff2bbe1c5375950b0e40d00ff000000005e05050505050507070100000024747a32526773486e74516b72794670707352466261313652546656503539684b72654a4d07070100000024747a315a6672455263414c42776d4171776f6e525859565142445439426a4e6a42484a750001';
    const pk = 'sppk7c7hkPj47yjYFEHX85q46sFJGw6RBrqoVSHwAJAT4e14KJwzoey';
    const sig = 'spsig1cdLkp1RLgUHAp13aRFkZ6MQDPp7xCnjAExGL3MBSdMDmT6JgQSX8cufyDgJRM3sinFtiCzLbsyP6d365EHoNevxhT47nx'
    
    const response = verifySignature(message, pk, sig);
    

    Parameters

    • messageBytes: string

      The forged message including the magic byte (11 for block, 12 for preendorsement, 13 for endorsement, 3 for generic, 5 for the PACK format of michelson)

    • publicKey: string

      The public key to verify the signature against

    • signature: string

      The signature to verify

    • Optional watermark: Uint8Array

    Returns boolean

    A boolean indicating if the signature matches

Generated using TypeDoc