Skip to content

@thru/programs

View as Markdown

@thru/programs contains program-specific bindings for built-in Thru programs. It is published as one package with subpath exports for each program surface.

Terminal window
npm install @thru/programs @thru/sdk
ImportWhat it provides
@thru/programs/tokenToken program instruction builders, account parsers, address derivation, ABI builders, and formatting helpers.
@thru/programs/passkey-managerPasskey-manager instruction encoders, challenge helpers, account-context builders, derivation helpers, account parsers, and P-256/WebAuthn encoding utilities.

There is no root runtime import. Import from the program subpath you need.

Use @thru/programs/token when you are creating token mints, creating token accounts, transferring or minting tokens, parsing token account state, or formatting raw token amounts.

import {
createTransferInstruction,
deriveTokenAccountAddress,
formatRawAmount,
parseTokenAccountData,
} from "@thru/programs/token";
const destination = deriveTokenAccountAddress(
ownerAddress,
mintAddress,
tokenProgramAddress
);
const instructionData = createTransferInstruction({
sourceAccountBytes,
destinationAccountBytes: destination.bytes,
amount: 1_000_000n,
});
const parsed = parseTokenAccountData(account);
const displayAmount = formatRawAmount(parsed.amount, 6);

Important token exports include:

  • createInitializeMintInstruction
  • createInitializeAccountInstruction
  • createMintToInstruction
  • createTransferInstruction
  • deriveMintAddress
  • deriveTokenAccountAddress
  • deriveWalletSeed
  • parseMintAccountData
  • parseTokenAccountData
  • formatRawAmount

Use @thru/programs/passkey-manager when you need to build passkey-managed wallet instructions, create validate challenges, derive wallet or credential lookup addresses, parse wallet state, or compose passkey-manager instruction bytes.

import {
buildAccountContext,
concatenateInstructions,
createValidateChallenge,
encodeTransferInstruction,
encodeValidateInstruction,
} from "@thru/programs/passkey-manager";
const accountContext = buildAccountContext({
feePayerAddress,
walletAddress,
readWriteAccounts: [destinationAddress],
});
const transfer = encodeTransferInstruction({
accountContext,
toAddress: destinationAddress,
amount: 1_000_000n,
});
const challenge = createValidateChallenge({
nonce,
accountAddresses: accountContext.accountAddresses,
instructionData: transfer,
});
const validate = encodeValidateInstruction({
accountContext,
authorityIndex,
challenge,
signature,
authenticatorData,
clientDataJSON,
});
const instructionData = concatenateInstructions(validate, transfer);

Important passkey-manager exports include:

  • encodeCreateInstruction
  • encodeValidateInstruction
  • encodeTransferInstruction
  • encodeInvokeInstruction
  • encodeAddAuthorityInstruction
  • encodeRemoveAuthorityInstruction
  • encodeRegisterCredentialInstruction
  • createValidateChallenge
  • deriveWalletAddress
  • deriveCredentialLookupAddress
  • buildAccountContext
  • parseWalletNonce
  • fetchWalletNonce
  • parseWalletAuthorities
  • P-256 and byte/base64 helpers used by WebAuthn flows