Overview
The transaction module provides comprehensive Bitcoin transaction creation, signing, and verification capabilities. It supports multiple address versions, submarine swaps, incoming swaps, and both partial and full signing workflows.PartiallySignedTransaction
Represents a transaction with inputs that need user signatures.NewPartiallySignedTransaction
Creates a new partially signed transaction from inputs and raw transaction bytes.List of transaction inputs with signing data
Serialized unsigned transaction
MuSig2 nonces for taproot (V5/V6) inputs
*PartiallySignedTransactionErrors: Transaction deserialization errors
Example
Sign
Signs the transaction with the user’s private key. Muun’s signature must already be present in inputs.User’s HD private key for signing
Muun’s HD public key for multisig validation
*Transaction - Fully signed transactionErrors: Signing errors, missing Muun signature
Example
FullySign
Signs the transaction with both user and Muun private keys. Used for emergency recovery.User’s HD private key
Muun’s HD private key (emergency recovery only)
*Transaction - Fully signed transactionErrors: Signing errors
Example
Verify
Verifies the transaction matches expected parameters before signing.Expected transaction parameters (destination, amount, fee, change)
User’s public key for change address validation
Muun’s public key for change address validation
error if verification failsValidates:
- Output count (destination + optional change)
- Destination address and amount
- Change address ownership and derivation
- Fee calculation
- No dust outputs being burned as fees
Example
SigningExpectations
Defines the expected parameters for transaction verification.NewSigningExpectations
Expected destination address
Expected amount in satoshis
Expected change address (nil if no change)
Expected fee in satoshis
Whether this is an alternative transaction (fee bump)
Input Interfaces
The Input interface provides access to input data for signing.Outpoint Interface
InputList
Container for managing transaction inputs.Add
Input to add to the list
Example
Transaction Structure
The signed transaction result.Supported Address Versions
The library supports signing for multiple address types:Security Validations
The Verify method performs critical security checks:Output Validation
- Ensures exactly 1 or 2 outputs (destination + optional change)
- Verifies destination address matches expectations
- Confirms destination amount matches expectations
Change Address Security
- Validates change address is owned by the wallet
- Verifies proper key derivation from user and Muun keys
- Checks change amount calculation (inputs - amount - fee)
Fee Protection
- Prevents excessive fees
- Ensures dust outputs aren’t burned as fees (dust threshold: 546 sats)
- Validates fee matches expected value
Alternative Transaction Handling
For fee bumps (RBF), allows:- Reduced destination amount
- Missing destination output if change present
- Adjusted fee expectations
Segwit inputs (V3+) include the input amount in the signature data, preventing amount manipulation attacks.
Constants
Error Scenarios
Common errors during transaction operations:- Signature verification failed: Muun signature invalid
- Output mismatch: Unexpected number of outputs
- Amount mismatch: Destination or change amount incorrect
- Address mismatch: Change address not owned by wallet
- Fee mismatch: Calculated fee doesn’t match expectations
- Dust as fee: Change output below dust threshold