Options
All
  • Public
  • Public/Protected
  • All
Menu

Package common

@stacks/common

Common utilities used by Stacks.js packages.

Installation

npm install @stacks/common

Index

Type Aliases

IntegerType: number | string | bigint | Uint8Array | BN

Functions

  • asciiToBytes(str: string): Uint8Array
  • Converts an ASCII string to the equivalent bytes

    example
    asciiToBytes('stacks $'); // Uint8Array(8) [ 115, 116, 97, 99, 107, 115, 32, 36 ]
    

    Parameters

    • str: string

    Returns Uint8Array

  • bigIntToBytes(value: bigint, length?: number): Uint8Array
  • Converts bigint to byte array

    Parameters

    • value: bigint

      bigint value to be converted

    • length: number = 16

      byte array optional length

    Returns Uint8Array

    byte array

  • bytesToAscii(arr: Uint8Array): string
  • Converts bytes to the equivalent ASCII string

    example
    bytesToAscii(Uint8Array.from([115, 116, 97, 99, 107, 115, 32, 36])); // 'stacks $'
    

    Parameters

    • arr: Uint8Array

    Returns string

  • bytesToHex(uint8a: Uint8Array): string
  • Converts bytes to the equivalent hex string

    example
    bytesToHex(Uint8Array.from([0xde, 0xad, 0xbe, 0xef])) // 'deadbeef'
    

    Parameters

    • uint8a: Uint8Array

    Returns string

  • bytesToUtf8(arr: Uint8Array): string
  • Converts bytes to the equivalent UTF-8 string

    example
    bytesToUtf8(Uint8Array.from([115, 116, 97, 99, 107, 115, 32, 211, 190])); // 'stacks Ӿ'
    

    Parameters

    • arr: Uint8Array

    Returns string

  • getBase64OutputLength(inputByteLength: number): number
  • Calculate the base64 encoded string length for a given input length. This is equivalent to the byte length when the string is ASCII or UTF8-8 encoded.

    Parameters

    • inputByteLength: number

    Returns number

  • hexToBytes(hex: string): Uint8Array
  • Converts a hex string to the equivalent bytes

    example
    hexToBytes('deadbeef') // Uint8Array(4) [ 222, 173, 190, 239 ]
    

    Parameters

    • hex: string

    Returns Uint8Array

  • intToBigInt(value: IntegerType, signed: boolean): bigint
  • Parameters

    Returns bigint

  • intToBytes(value: IntegerType, signed: boolean, byteLength: number): Uint8Array
  • Parameters

    Returns Uint8Array

  • utf8ToBytes(str: string): Uint8Array
  • Converts a UTF-8 string to the equivalent bytes

    example
    utf8ToBytes('stacks Ӿ'); // Uint8Array(9) [ 115, 116, 97, 99, 107, 115, 32, 211, 190 ];
    

    Parameters

    • str: string

    Returns Uint8Array

  • with0x(value: string): string
  • Parameters

    • value: string

    Returns string

Generated using TypeDoc