Overview
The libwallet address module provides comprehensive Bitcoin address generation and payment URI parsing functionality. It supports multiple address versions, BIP70/BIP72 payment requests, and unified QR codes with both on-chain and Lightning Network payments.Address Versions
The library supports multiple address scheme versions:MuunPaymentURI Structure
Represents a parsed payment URI containing on-chain and/or Lightning payment information.The Bitcoin address (bech32, P2PKH, P2SH, etc.)
Optional label for the payment
Optional message describing the payment
Payment amount in BTC (decimal notation)
The original URI string
BIP70 payment request URL (if present)
Lightning invoice (for unified QR codes)
GetPaymentURI
Parses a Bitcoin URI, address, or unified QR code into a MuunPaymentURI structure.Bitcoin URI (bitcoin:), plain address, or unified QR code
Network configuration (mainnet, testnet, regtest)
*MuunPaymentURI - Parsed payment URI structureErrors:
ErrInvalidURI, ErrInvalidInvoice
Examples
DoPaymentRequestCall
Fetches and parses a BIP70/BIP72 payment request from a URL.BIP70 payment request URL
Network configuration
*MuunPaymentURI - Parsed payment requestErrors:
ErrNetwork - Network error or invalid response
Example
MuunAddress Interface
Defines the interface for Muun-generated addresses with derivation path information.Address scheme version (V1-V5, SubmarineSwapV1/V2)
HD wallet derivation path (e.g., “m/schema:1’/recovery:1’/external:0/42”)
The actual Bitcoin address string
URI Scheme Support
The library handles multiple URI schemes:bitcoin:- Standard Bitcoin URI (BIP21)bitcoin://- Alternative format (iOS compatibility)muun:- Muun-specific scheme (converted to bitcoin:)
Error Handling
- Invalid address encoding
- Network mismatch (testnet address on mainnet)
- Amount mismatch in unified QR codes
- Invalid BIP70 response
- Malformed URI parameters
Validation
The library performs comprehensive validation:- Address validation: Checks address format and network compatibility
- Amount validation: Handles scientific notation, validates numeric values
- Unified QR validation: Ensures on-chain and Lightning amounts match
- BIP70 validation: Verifies payment request structure and scripts
When both on-chain and Lightning amounts are present in a unified QR code, they must match exactly or an
ErrInvalidURI error is returned.Advanced Features
Amount Parsing
The library handles flexible amount formats:- Standard decimal notation (“0.001”)
- Scientific notation (converted to decimal)
- Automatic validation for NaN/Inf values
BIP70 Support
Full support for BIP70 payment protocol:- Payment request fetching with proper Accept headers
- Payment details parsing (protobuf)
- Multiple outputs handling
- Expiration time tracking