Overview
Medusa Wallet uses LNbits as its Lightning Network backend, providing a robust API layer for wallet management, payments, and Lightning-specific features. The integration is primarily handled through thelnbits.ts API module.
API Configuration
The wallet connects to the LNbits instance atwallet.medusa.bz:
Authentication Flow
User Registration
User Registration
The registration process creates a new LNbits user account and automatically provisions a default wallet:Post-Registration Steps:
- Parse and validate authentication response with Zod schema
- Fetch user data to retrieve default wallet
- Automatically create a paylink for receiving payments
- Return access token for session management
~/workspace/source/api/lnbits.ts:47-92User Login
User Login
Login uses standard credential authentication:The access token is stored in the auth store and used for subsequent requests via cookie header.See
~/workspace/source/api/lnbits.ts:94-120Wallet Operations
Fetching User Data
Fetching User Data
User data includes all wallets and their balances:See
~/workspace/source/api/lnbits.ts:179-211Creating Wallets
Creating Wallets
New wallets can be created using an admin key:Each wallet has three keys:
- Admin key: Full access (create, pay, manage)
- Invoice key: Can create invoices and view payments
- Read key: View-only access
~/workspace/source/api/lnbits.ts:447-465Payment Operations
Creating Invoices
Creating Invoices
Invoices are created using the invoice key (inkey):See
~/workspace/source/api/lnbits.ts:495-510Paying Invoices
Paying Invoices
The wallet supports two payment types:1. Bolt11 Invoices:2. LNURL Payments:See
~/workspace/source/api/lnbits.ts:528-595Fetching Payment History
Fetching Payment History
Payment history includes historical fiat conversion data:See
~/workspace/source/api/lnbits.ts:318-398WebSocket Integration
Payment Status Monitoring
Payment Status Monitoring
Real-time payment monitoring via WebSocket:See
~/workspace/source/api/lnbits.ts:402-423Wallet Updates Monitoring
Wallet Updates Monitoring
Monitor incoming payments for a wallet:See
~/workspace/source/api/lnbits.ts:425-445LNURL-Pay (Paylinks)
Creating Paylinks
Creating Paylinks
Paylinks allow users to receive payments via LNURL-Pay:A paylink is automatically created during registration.See
~/workspace/source/api/lnbits.ts:122-152Boltz Swaps
Submarine Swaps
Submarine Swaps
The wallet integrates with Boltz for on-chain/Lightning swaps:Swap Types:
- Submarine Swap (in): On-chain → Lightning
- Reverse Swap (out): Lightning → On-chain
- Auto Swap: Automated reverse swaps based on wallet balance
~/workspace/source/api/lnbits.ts:696-746