Overview
This guide shows you how to sign messages with your Bitcoin wallet. Message signing uses the BIP-322 standard, which provides a unified way to sign messages across all Bitcoin address types. The signature is returned as a base64 string.Prerequisites
Basic Message Signing
walletMetadata is the object returned by createWalletAccount (or importPrivateKey), and password is the password you set when you created the wallet. network is required: use BitcoinNetwork.MAINNET or BitcoinNetwork.TESTNET.
Simple Message Signing
Whether you need to provideexternalServerKeyShares depends on how you created your wallet:
With Automatic Backup (Recommended)
If you created your wallet withbackUpToDynamic: true, you don’t need to provide external key shares. A password is required for these wallets, so pass it:
With Manual Backup
If you created your wallet withbackUpToDynamic: false, you must provide external key shares:
- If your wallet was created without a password, omit the
passwordparameter - If your wallet was created with a password, you must provide it for all operations
- Wallets created with
backUpToDynamic: truealways have a password, because one is required at creation
BIP-322 Message Signing
The SDK automatically uses BIP-322 for message signing, which works with both Native SegWit and Taproot addresses:Native SegWit (P2WPKH)
Taproot (P2TR)
Taproot message signing requires
@dynamic-labs-wallet/node-btc 1.1.59 or later. In earlier versions it fails with Invalid type: Expected bigint but received 0 or Uint8Array expected.Common Use Cases
Authentication
Data Integrity
Proof of Ownership
Signing on Testnet
PassBitcoinNetwork.TESTNET as network and keep passing the walletMetadata you got from createWalletAccount, unchanged:
walletMetadata.accountAddress is always the mainnet-encoded address (bc1q...), and signing on testnet works with it. If you omit network, or pass BitcoinNetwork.MAINNET with a wallet whose address you replaced with its tb1q... form, you get Address verification failed: expected tb1q..., got bc1q.... See Working with testnet.
Understanding BIP-322
BIP-322 (Generic Signed Message Format) provides a standardized way to sign and verify messages for all Bitcoin address types:- Native SegWit (P2WPKH): Uses ECDSA signatures
- Taproot (P2TR): Uses Schnorr signatures (BIP-340)