BOLT11 Invoice Support
The Lightning Network integration uses BOLT11 (Basis of Lightning Technology #11) for invoice encoding and decoding.Invoice Decoding
Library:@gandlaf21/bolt11-decode
Sovran decodes BOLT11 invoices to extract payment information:
- Amount: Extracted from invoice sections and converted from millisatoshis to satoshis
- Timestamp: Creation timestamp for invoice tracking
- Payment hash: Unique identifier for payment routing
- Expiry: Invoice expiration time
Invoice Validation
Invoices are validated before processing:Mint Quote Operations
Creating Mint Quotes (Receiving)
Mint quotes generate Lightning invoices for receiving Bitcoin and converting it to ecash. Implementation (hooks/coco/useLightningOperations.ts:16-32):
- User requests to receive sats at a specific mint
- Mint generates a BOLT11 invoice
- User pays invoice from external Lightning wallet
- Mint detects payment and issues ecash tokens
Melt Quote Operations (Sending)
Melt quotes enable paying Lightning invoices with ecash tokens. Flow (hooks/coco/useProcessPaymentString.ts:346-356):
- User scans/pastes BOLT11 invoice
- Amount is extracted from invoice
- Mint creates melt quote (fee estimate)
- User confirms payment
- Mint pays Lightning invoice and burns ecash
If a BOLT11 invoice doesn’t contain an amount, Sovran routes to the currency input screen (
/(send-flow)/currency) where users can specify the amount before creating the melt quote.Payment String Processing
Sovran automatically detects and processes Lightning payment strings:Supported Formats
- BOLT11 Invoices:
lnbc1...orlightning:lnbc1... - Lightning Addresses:
user@domain.com - LNURL-Pay:
lnurl1...orlightning:lnurl1...
hooks/coco/useProcessPaymentString.ts:333-368):
Input Trimming
Lightning payment strings are automatically trimmed to handle various formats:Scan History Tracking
All Lightning payment operations are tracked in scan history:'qr': QR code scan'paste': Clipboard paste'deeplink': Deep link (cashu:// or sovran://)'nfc': NFC tap payment
NFC Payments
Sovran supports NFC tap-to-pay for Lightning invoices: Implementation (helper/nfc.ts):
- NDEF Type 4 Tag protocol
- Automatic invoice detection from NFC tags
- Mint selection with balance validation
- Amount limit enforcement
- Rollback handling for failed payments
app/(drawer)/(tabs)/index/_layout.tsx):
- User taps NFC tag containing BOLT11 invoice
- Sovran validates mint selection and balance
- Creates melt quote automatically
- Processes payment with POS recovery support
Transaction Timelines
Lightning operations show real-time progress: Timeline Components (components/blocks/Transaction/):
HistoryEntryTimeline.tsx: Step-by-step transaction progressHistoryEntryHeader.tsx: Transaction detail headersHistoryEntryRefresh.tsx: Status refresh component
- Mint quotes: Countdown to expiry
- Sends: Preparation → Finalization
- Melts: Pending → Paid
Integration with Cashu
Lightning operations integrate seamlessly with Cashu ecash: Minting Flow:useLightningOperations: Quote creation wrapperuseMeltWithHistory: Melt operations with transaction trackinguseHistoryWithMelts: Combined history view
Dependencies
BOLT11 decoding is handled by the
@gandlaf21/bolt11-decode library, which provides reliable parsing of Lightning invoices without requiring a full Lightning node implementation.Error Handling
Lightning operations include comprehensive error handling:isProcessing: Loading state for UI feedbackerror: Error object for displayreset(): Clear error state
Reference Implementation
- Lightning Operations:
hooks/coco/useLightningOperations.ts - BOLT11 Utils:
helper/coco/utils.ts:29-88 - Payment Processing:
hooks/coco/useProcessPaymentString.ts:333-368 - Melt Operations:
hooks/coco/useMeltWithHistory.ts - NFC Integration:
helper/nfc.ts
Learn More
Cashu NUTs
Explore Cashu protocol integration
Payment Requests
NUT-18 Nostr-based payment requests
Wallet Security
BIP-39 seed phrase management
BOLT Specifications
Official Lightning Network specifications