Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Accounts

Accounts represent the key material used to sign transactions. The SDK supports two account types: local accounts (private key available in-process) and JSON-RPC accounts (signing delegated to a browser extension wallet).

Account Types

LocalAccount

A local account holds the private key directly and can sign without external calls. Created via mnemonicToAccount, hdKeyToAccount, privateKeyToAccount, or toLocalAccount.

type LocalAccount = {
  address: Address
  xOnlyPubKey: XOnlyPubKey
  source: string
  type: "local"
  signMessage: (params: { message: SignableMessage }) => Promise<Hex>
  signPsbt: (params: SignPsbtParams) => Promise<{ txid: string; psbt: Hex }>
}

JsonRpcAccount

A JSON-RPC account delegates signing to an external provider (e.g. Leather, XVerse). It only stores the address and public key.

type JsonRpcAccount = {
  address: Address
  xOnlyPubKey: XOnlyPubKey
  type: "json-rpc"
}

Creating Accounts

mnemonicToAccount

Derives an HD account from a BIP-39 mnemonic phrase.

import { mnemonicToAccount, signet } from "@kontor/kontor-sdk";
 
const account = mnemonicToAccount("your mnemonic phrase here", { 
  networkConfig: signet.networkConfig, 
  coinType: 1, // testnet 
}); 
 
account.address;
account.xOnlyPubKey;

Options:

  • networkConfig — the Bitcoin network parameters (e.g. signet.networkConfig)
  • coinType0 for mainnet, 1 for testnet (default: 0)
  • accountIndex — BIP-86 account index (default: 0)
  • addressIndex — address index (default: 0)

hdKeyToAccount

Creates an account from an existing HDKey instance (from @scure/bip32).

import { HDKey } from "@scure/bip32";
import { hdKeyToAccount } from "@kontor/kontor-sdk";
 
const seed = new Uint8Array([112, 111, 108, 121, 99, 114, 105, 115, 105, 115]);
const key = HDKey.fromMasterSeed(seed);
 
const account = hdKeyToAccount(key); 

Accepts the same options as mnemonicToAccount.

privateKeyToAccount

Creates an account from a raw private key hex string.

import { privateKeyToAccount, signet } from "@kontor/kontor-sdk";
 
const account = privateKeyToAccount("0xdabdad", { 
  networkConfig: signet.networkConfig, 
}); 

Utilities

toLocalAccount

Converts a CustomSource into a LocalAccount. Use this when you have a custom signing implementation.

import { toLocalAccount } from "@kontor/kontor-sdk";
 
const account = toLocalAccount({
  address: "tb1p...",
  xOnlyPubKey: "abcd...",
  signMessage: async ({ message }) => { /* ... */ },
  signPsbt: async ({ psbt, signInputs, broadcast }) => { /* ... */ },
});

parseAccount

Normalizes an [Address, XOnlyPubKey] tuple into a JsonRpcAccount. If already an Account, passes through unchanged.

import { parseAccount } from "@kontor/kontor-sdk";
 
const account = parseAccount(["tb1p...", "abcd..."]);
// => { address: "tb1p...", xOnlyPubKey: "abcd...", type: "json-rpc" }

publicKeyToP2TRPayment

Derives a P2TR (Taproot) payment object from a compressed public key.

import { publicKeyToP2TRPayment, signet } from "@kontor/kontor-sdk";
 
const payment = publicKeyToP2TRPayment("0x02abc...", signet.networkConfig);

Type Annotations

The SDK exports specific account subtypes for type annotations:

  • HDAccount — returned by mnemonicToAccount and hdKeyToAccount, includes getHdKey()
  • PrivateKeyAccount — returned by privateKeyToAccount
import type { HDAccount, PrivateKeyAccount } from "@kontor/kontor-sdk";