Skip to main content
@thru/helpers is the root entrypoint for the package. It exports the small set of encoding and runtime helpers that most app integrations need.

Install

npm install @thru/helpers

Import

import {
  decodeAddress,
  decodeBase64,
  decodeSignature,
  encodeAddress,
  encodeSignature,
  ensureBytes,
  getWebCrypto,
  hexToBytes,
  isHexString,
} from '@thru/helpers';

When to use it

Use @thru/helpers when you need low-level encoding and runtime helpers without pulling in wallet, RPC, or React abstractions. Use @thru/crypto when you need mnemonic generation or HD wallet derivation on top of these helpers.

Export groups

GroupExportsUse it for
Address encodingencodeAddress, decodeAddressConverting between raw 32-byte account data and ta... addresses.
Signature encodingencodeSignature, decodeSignatureConverting between raw 64-byte signatures and ts... strings.
Byte handlingdecodeBase64, hexToBytes, isHexString, ensureBytesNormalizing binary inputs from app code or API payloads.
Runtime supportgetWebCryptoAccessing Web Crypto in browser-facing code.

Address helpers

Use encodeAddress and decodeAddress when you need to move between raw 32-byte account data and the Thru address format. encodeAddress(bytes) expects a 32-byte Uint8Array and returns a ta... address string. decodeAddress(value) accepts a ta... address string and returns the original 32-byte value after validating the checksum.

Signature helpers

Use encodeSignature and decodeSignature when you need to convert between raw 64-byte signatures and the Thru signature format. encodeSignature(bytes) expects a 64-byte Uint8Array and returns a ts... signature string. decodeSignature(value) accepts a ts... signature string and returns the original 64-byte signature after validating the checksum.

Byte helpers

decodeBase64(value) converts a base64 string to bytes and requires globalThis.atob to be available. hexToBytes(value) accepts hex strings with or without a 0x prefix. isHexString(value) checks whether a string is a non-empty even-length hex string. ensureBytes(value, field) is the strict input normalizer: it accepts either a non-empty Uint8Array or a non-empty base64 string and throws a field-specific error if the value is missing or empty.

Web Crypto

getWebCrypto() returns globalThis.crypto when the Web Crypto API is available and throws if the runtime does not provide it. Use it in browser-facing code that needs getRandomValues without pulling in a separate polyfill path.

Example

import { decodeAddress, encodeSignature } from '@thru/helpers';

const rawAddress = decodeAddress('ta...');
const signature = encodeSignature(new Uint8Array(64));