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

FetchFn: (url: string, init?: RequestInit) => Promise<Response>

Type declaration

    • (url: string, init?: RequestInit): Promise<Response>
    • Parameters

      • url: string
      • Optional init: RequestInit

      Returns Promise<Response>

IntegerType: number | string | bigint | Uint8Array | BN

Variables

Buffer: typeof NodeJSBuffer = ...

Network Functions

  • Creates a new middleware from an API key.

    example
    const apiMiddleware = createApiKeyMiddleware("example_e8e044a3_41d8b0fe_3dd3988ef302");
    

    Parameters

    Returns FetchMiddleware

  • Creates a new network fetching function, which combines an optional fetch-compatible library with optional middlware.

    example
    const customFetch = createFetchFn(someMiddleware)
    const customFetch = createFetchFn(fetch, someMiddleware)
    const customFetch = createFetchFn(fetch, middlewareA, middlewareB)

    Parameters

    Returns FetchFn

  • Parameters

    Returns FetchFn

  • getFetchOptions(): RequestInit
  • Get fetch options

    Returns RequestInit

  • setFetchOptions(ops: RequestInit): RequestInit
  • Sets global fetch options for stacks.js network calls.

    example

    Users can change the default referrer as well as other options when fetch is used internally by stacks.js:

    setFetchOptions({ referrer: 'no-referrer', referrerPolicy: 'no-referrer', ...otherRequestOptions });
    

    After calling setFetchOptions all subsequent network calls will use the specified options above.

    see

    MDN Request: https://developer.mozilla.org/en-US/docs/Web/API/Request/Request

    related

    getFetchOptions

    Parameters

    • ops: RequestInit

    Returns RequestInit

    global fetch options after merging with previous options (or defaults)

Other Functions

  • 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

  • hexToBigInt(hex: string): bigint
  • Converts hex input string to bigint

    example

    "6c7cde4d702830c1db34ef7c19e2776f59107afef39084776fc88bc78dbb9656"

    Parameters

    • hex: string

      hex input string without 0x prefix and in big endian format

    Returns bigint

  • Parameters

    Returns BN

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

    Returns bigint

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

    Returns Buffer

  • utf8ToBytes(content: string): Uint8Array
  • Parameters

    • content: string

    Returns Uint8Array

  • with0x(value: string): string
  • Parameters

    • value: string

    Returns string

Generated using TypeDoc