Skip to main content

Vault API Reference

Vault Creation

createVault(options)

End-to-end vault creation — fetches validator keys, builds tapscripts, and derives the P2TR address.

const vault = await createVault({
network: "regtest",
userWallet,
validators: { endpoint: "https://rpc-regtest.tachibtc.com/tachi_validators" }, // or https://rpc-signet.tachibtc.com/tachi_validators for signet
// csvBlocks: 1008, // optional: override exit-leaf CSV
});
OptionTypeDescription
networkVaultNetworkNamemainnet / signet / regtest
userWalletWalletWallet from @tachibtc/taurus-wallet-aggregator
validators{ endpoint: string }KDHT validator endpoint
nodePubkeysstring[]Alternative: pass pubkeys directly, skip HTTP fetch
csvBlocksnumberExit-leaf CSV blocks (default: 1008)

verifyVaultP2tr(p2tr)

Re-derives both leaves, the NUMS internal key, and the tweaked output key. Throws on any mismatch.

verifyVaultP2tr(vault.p2tr); // throws if invalid

depositToVault(options)

Funds a vault from a P2WPKH wallet.

const deposit = await depositToVault({
vault,
userWallet,
rpc,
amountSats: 100_000n,
feeRateSatVb: 2,
});

Registration & Discovery

createVault is local — it derives an address and nothing else knows about it. Registering the funded vault on-ledger is what makes it discoverable from any device.

registerVault(options)

Registers a funded vault by building, signing, and broadcasting a TxVaultOpen. Orchestrates payload → nonce → build → sign → broadcast in one call, then returns the derived VaultID.

const reg = await registerVault({
vault,
outpoint: { txid: deposit.txid, vout: 0 },
userSigner,
inputs, // ledger VTXOs paying the (typically zero) open fee
outputs, // change VTXOs from the open spend
feeSats: 0n,
broadcast: { url: `${DAEMON_URL}/tachi_txBroadcastSync` },
confirm: { baseUrl: DAEMON_URL }, // see note below
name: "cold storage", // optional display label
});

console.log(reg.vaultIdHex);
OptionTypeDescription
vaultVaultMust be built from a compressed user key — TxVaultOpen commits the 33-byte owner key
outpoint{ txid, vout }The vault's confirmed L1 funding outpoint
userSignerTaprootSignerSigns the TxVaultOpen; x-only key must equal vault.userKey.xOnly
inputsVaultOpenSpendInput[]Ledger VTXOs paying the open fee — onboard one first if the account holds none
outputsVaultOpenChangeOutput[]Change VTXOs; sum(inputs) - sum(outputs) must equal feeSats
feeSatsbigintOpen fee in sats (commonly 0n)
broadcast{ url }Tachi REST broadcast endpoint
confirm{ baseUrl }Poll until the tx commits before resolving — see below
namestringOptional 1–64 byte printable-ASCII display label, no leading/trailing space
noncebigintExplicit nonce; fetched via account when omitted
accountGetAccountNonceOptionsHow to fetch the nonce when nonce is omitted

Pass confirm. Without it, registerVault resolves as soon as the mempool admits the tx — that is not registration. Quorum/threshold and fee-balance checks run later at FinalizeBlock, so an unconfirmed open can be accepted and then dropped from the block.

One call per funded vault. The daemon rejects re-registering the same funding outpoint (CodeVaultAlreadyExists).

name is set once and never changeable, not unique, and stored in plaintext consensus state — treat it as a display hint, not an identifier, and escape it before rendering.

discoverVaults(options)

Rebuilds every vault registered under a wallet's owner keys directly from daemon state — no local storage involved.

const vaults = await discoverVaults({
network: "regtest",
userWallet, // or userPubkey for a single known key
validators: { endpoint: "https://rpc-regtest.tachibtc.com/tachi_validators" },
query: { baseUrl: DAEMON_URL },
});
OptionTypeDescription
networkVaultNetworkNameMust match how the vaults were built
userWalletWalletGap-scans receive-key indices for vaults. Mutually exclusive with userPubkey
userPubkeystring | BufferA single compressed owner key — no index scan
validators{ endpoint: string }KDHT validator endpoint used to rebuild each vault
nodePubkeysstring[]Alternative: pass node pubkeys directly, skip the fetch
queryTachiQueryOptions/tachi_listVaults transport options; set apiKey to rebuild from the daemon's own registered parameters instead of guessing
threshold / csvBlocksnumberBuild-time values used only when the daemon record carries no snapshot — a guess, not a fact
requireAddressMatchbooleanThrow on a rebuilt-vs-registered address mismatch instead of reporting it

Returns DiscoveredVault[] — each entry carries the rebuilt Vault, the daemon's VaultSummary, and the wallet index it was found at.

An empty result is not "no vaults." Only registered vaults are indexed, and a daemon that cannot verify a registration against L1 (e.g. mainnet without a validator quorum) indexes nothing — so this always returns [] there.

The quorum a vault commits to is the genesis CometBFT validator set, not configuration. An env-var list of node keys is a guess at it; check it with fetchConsensusQuorum first.

Tapscript

buildCooperativeScript(userPubkey, nodePubkeys, threshold)

Builds the cooperative leaf script: user CHECKSIGVERIFY + N-of-M KDHT CHECKSIGADD.

buildExitScript(userPubkey, csvBlocks)

Builds the exit leaf script: CSV timelock + user CHECKSIG.

describeTapscript(script)

Returns a human-readable description of a tapscript.

NUMS_INTERNAL_KEY

The BIP-341 NUMS point (lift_x(SHA256(G))). Used as the internal key to disable key-path spending.

P2TR

buildVaultP2tr(options)

Builds the P2TR output from user key, node keys, and CSV config. Lower-level than createVault.

Pubkey Utilities

parsePubkeyHex(hex)

Parses a compressed public key hex string.

toXOnly(pubkey)

Converts a 33-byte compressed pubkey to 32-byte x-only.

hexToXOnly(hex)

Shorthand: hex string → x-only buffer.