This package provides a wallet-standard compliant Bitcoin wallet implementation that can be integrated with any dApp supporting the wallet-standard interface.
- Wallet Standard Compliance: Implements the official wallet-standard specification
- Bitcoin Support: Full support for Bitcoin mainnet and testnet
- Multiple Features: Sign messages, sign transactions, sign PSBTs, and more
- Event Handling: Proper event emission for wallet state changes
- TypeScript Support: Full TypeScript definitions included
npm install @xdefi-tech/wallet-standardimport { initialize } from '@xdefi-tech/wallet-standard';
import { ExampleBitcoinProvider } from './your-bitcoin-provider';
// Create your Bitcoin provider (must implement ICtrlBitcoinWallet)
const bitcoinProvider = new ExampleBitcoinProvider();
// Initialize the wallet with wallet-standard
initialize(bitcoinProvider);Your Bitcoin provider must implement the ICtrlBitcoinWallet interface:
interface ICtrlBitcoinWallet {
// Event emitter methods
on(event: string, listener: any, context?: any): void;
off(event: string, listener: any, context?: any): void;
// Core methods
request(payload: XDEFIBitcoinPayload | string, callbackFunction: any): Promise<any>;
getAccounts(): Promise<string[]>;
requestAccounts(): Promise<string[]>;
signPsbt(params: { psbt: string; broadcast?: boolean }): Promise<any>;
}The wallet implements the following wallet-standard features:
standard:connect- Connect to the walletstandard:disconnect- Disconnect from the walletstandard:events- Listen to wallet eventsbitcoin:signMessage- Sign Bitcoin messagesbitcoin:signTransaction- Sign Bitcoin transactionsbitcoin:signPsbt- Sign Bitcoin PSBTsbitcoin:connect- Bitcoin-specific connection
bitcoin:mainnet- Bitcoin mainnet
dApps can discover and use the wallet through the wallet-standard interface:
// Get available wallets
const wallets = await window.navigator.wallets?.get();
// Find Bitcoin wallet
const bitcoinWallet = wallets.find((wallet) => wallet.chains.some((chain) => chain.startsWith('bitcoin:')));
if (bitcoinWallet) {
// Connect to wallet
const connectFeature = bitcoinWallet.features['standard:connect'];
const { accounts } = await connectFeature.connect();
// Sign a message
const signMessageFeature = bitcoinWallet.features['bitcoin:signMessage'];
const { signature } = await signMessageFeature.signMessage({
message: new TextEncoder().encode('Hello Bitcoin!'),
account: accounts[0],
});
// Sign a PSBT
const signPsbtFeature = bitcoinWallet.features['bitcoin:signPsbt'];
const result = await signPsbtFeature.signPsbt({
psbt: 'your_psbt_base64_string',
account: accounts[0],
broadcast: false,
});
}- CtrlWalletBitcoinAccount: Implements the
WalletAccountinterface - CtrlBitcoinWallet: Main wallet implementation implementing the
Walletinterface - Bitcoin Chain Definitions: Chain identifiers for mainnet and testnet
- Wallet Registration: Integration with wallet-standard registration system
- Provider emits events (
connect,disconnect,accountChanged) - Wallet listens to these events and updates internal state
- Wallet emits wallet-standard events (
change) - dApps receive wallet-standard events and update their UI
npm run buildnpm testnpm run tscSee the examples/ directory for complete usage examples:
bitcoin-usage.ts- Basic Bitcoin wallet usagetest-bitcoin.ts- Testing Bitcoin wallet functionality
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Apache-2.0
For support and questions, please open an issue on GitHub or contact the maintainers.