@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:
| Provider | Adapter id | Name | Signer kind |
|---|---|---|---|
window.unisat | injected:bitcoin:unisat | Unisat | unisat |
window.okxwallet.bitcoin | injected:bitcoin:okx | OKX Wallet | unisat |
window.XverseProviders.BitcoinProvider | injected:bitcoin:xverse | Xverse | sats-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:
| Method | Feature | Resolves |
|---|---|---|
sendTx | bitcoin:sendTransfer | The txid. |
signMessage | bitcoin:signMessage | { signature, signedMessage }. |
signTransaction | bitcoin:signPsbt | The 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.
| Transport | Wallet receives | Non-UTF-8 bytes |
|---|---|---|
| Wallet Standard | the bytes | signed |
| Ledger | the bytes, as hex | signed |
Unisat, OKX, window.btc | bitcoinMessageText | rejected |
| Xverse (sats-connect) | bitcoinMessageText | rejected |
| WalletConnect | bitcoinMessageText | rejected |
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'srequest(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.