BOLT12 Implementation Technical Summary¶
Overview¶
We have implemented the BOLT12 (Offers Protocol) for the Anya-core Lightning Network integration. This implementation enables offers, invoice requests, payments, and refunds as outlined in the BOLT12 specification. This is a critical component for Layer 2 interoperability.
Components Implemented¶
- Bolt12Offer
- Creation and serialization of BOLT12 offers
- Support for amount, description, expiry, and issuer specification
-
Deserialization from raw bytes
-
Bolt12InvoiceRequest
- Generation from offers
- Support for payer identification and notes
-
Serialization and deserialization
-
Bolt12Invoice
- Creation from invoice requests
- Payment hash support for secure payments
-
Node identification
-
Bolt12Payment
- Creation from invoices with payment preimages
- Full payment lifecycle management
-
Serialization and deserialization
-
Bolt12Refund
- Support for refunding payments
- Partial and full refund capabilities
- Serialization and deserialization
Usage Examples¶
Creating an Offer¶
let offer = Bolt12Offer::new(
100_000, // 100k sats
"API Service".to_string(),
3600, // 1 hour expiry
"Service Provider".to_string(),
)?;
let serialized = offer.serialize()?;
Complete Payment Flow¶
// 1. Create an offer
let offer = Bolt12Offer::new(
150_000, // 150k sats
"Digital Product".to_string(),
3600, // 1 hour
"Merchant".to_string(),
)?;
// 2. Create invoice request from offer
let request = Bolt12InvoiceRequest::new(
&offer,
payer_id,
Some("Order #12345".to_string()),
)?;
// 3. Create invoice from request
let invoice = Bolt12Invoice::from_request(
&request,
payment_hash,
node_id,
)?;
// 4. Create payment from invoice
let payment = Bolt12Payment::new(
&invoice,
payment_preimage,
)?;
// 5. For refunds if needed
let refund = Bolt12Refund::new(
&payment,
refund_amount,
)?;
Testing¶
Comprehensive tests have been added that verify:
- Offer creation and serialization/deserialization
- Invoice request flow
- Complete payment flow including refunds
Integration with DAO¶
The BOLT12 implementation enhances the DAO functionality by enabling:
- Micro-payments - Efficient handling of small value transfers for DAO operations
- Off-chain Voting - Support for off-chain voting mechanisms
- Instant DAO Actions - Reduced latency for DAO operations
- Cross-layer Interoperability - Seamless interaction with the Lightning Network
Next Steps¶
- Integration Tests - Add more comprehensive integration tests
- Performance Optimization - Optimize for high-volume transaction scenarios
- Documentation - Add usage guides for developers
- Security Audit - Conduct a thorough security review