Skip to Content
butr
API reference

@usebutr/bitcoin

Wallet Standard discovery plus injected fallbacks, the adapter builder, and the Bitcoin feature types.

Discovery

discoverBitcoinAdapters(onAdapter, loadModule?): () => void

Subscribes to Wallet Standard registrations for Bitcoin wallets (Phantom, Magic Eden, Leather, …). Lazily imports @wallet-standard/app, an optional peer dependency; loadModule replaces that import (tests). It is a WalletSource as-is.

discoverInjectedBitcoinAdapter(onAdapter): () => void

The fallback for wallets that never announce through Wallet Standard. When subscribed, it emits an adapter for each provider it finds:

ProviderAdapter idNameSigner kind
window.unisatinjected:bitcoin:unisatUnisatunisat
window.okxwallet.bitcoininjected:bitcoin:okxOKX Walletunisat
window.XverseProviders.BitcoinProviderinjected:bitcoin:xverseXversesats-connect

discoverLegacyBitcoinAdapter(onAdapter): () => void

Emits injected:bitcoin:legacy ("Browser Bitcoin wallet", signer kind unisat) for window.btc, unless it is the same object as window.unisat or window.okxwallet.bitcoin.

On their own, the injected sources list a wallet present on both channels twice. autoDiscovery(["bitcoin"]) from @usebutr/wallets lists each wallet once: an injected wallet that Wallet Standard also announced is dropped, and window.btc lists only when no other Bitcoin wallet was found.

Adapter builder

buildBitcoinAdapter(wallet, registerDisconnector?): BitcoinAdapter | null

Wraps a WalletStandardWallet, or returns null when it speaks no Bitcoin. The id is slugify("btc", wallet.name). Each optional method exists only when the wallet advertises its feature:

MethodFeatureResolves
sendTxbitcoin:sendTransferThe txid.
signMessagebitcoin:signMessage{ signature, signedMessage }.
signTransactionbitcoin:signPsbtThe signed PSBT bytes.

signMessage hands the wallet the message bytes as they are. sendTx takes a BitcoinTransfer ({ amount, recipient }, satoshis); signTransaction takes PSBT bytes. The Bitcoin connector covers the injected adapters, which switch or refuse a network instead of routing it per call.

Message signing

bitcoinMessageText(message, wallet): string

Import from @usebutr/bitcoin/message. Text-only wallets sign the UTF-8 encoding of a string, so this decodes the message bytes strictly, keeping a byte-order mark, and throws for bytes that are not valid UTF-8 rather than let the wallet sign other bytes. wallet names the wallet in the error.

TransportWallet receivesNon-UTF-8 bytes
Wallet Standardthe bytessigned
Ledgerthe bytes, as hexsigned
Unisat, OKX, window.btcbitcoinMessageTextrejected
Xverse (sats-connect)bitcoinMessageTextrejected
WalletConnectbitcoinMessageTextrejected

The Wallet Standard adapter resolves the wallet's own signedMessage. Every other transport resolves the input bytes, which is what the signature covers.

Signers

Wallet Standard adapters resolve { kind: "wallet-standard", wallet }. Importing the package registers the injected kinds:

  • unisat: { provider }, the UniSat-style provider the adapter drives.
  • sats-connect: { provider }, Xverse's request(method, params) provider.

Constants

GENERIC_BITCOIN_ICON: the injected adapters' icon.

Types

BitcoinSignMessageFeature, BitcoinSignMessageInput, BitcoinSignMessageOutput, BitcoinSignPsbtFeature, BitcoinSignPsbtInput, BitcoinSignPsbtOutput, BitcoinSendTransferFeature, BitcoinSendTransferInput, BitcoinSendTransferOutput.

The Bitcoin chain registry (BITCOIN_CHAINS, CHAINS_BY_PLATFORM.bitcoin) lives in @usebutr/core.

Source: packages/bitcoin/src/index.ts, packages/bitcoin/src/message.ts.