# Fiber Cross-Chain Payment Routing Design
## Metadata
**Status**:: #x
**Zettel**:: #zettel/fleeting
**Created**:: [[2024-07-31]]
## Fiber Pays Lightning
### Via Lightning Invoice (BOLT11)
- Cross-chain hub Fiber node announces its cross-chain capability in node announcements via the P2P network. All Fiber nodes should index the cross-chain hub nodes.
- Lightning user generates an invoice.
- Fiber node sends the payment message to a indexed cross-chain hub node, optionally via a onion message for better privacy. Embed the Lightning invoice in the last hop payload.
- When the cross-chain hub receives a payment message and a Lightning invoice is found in the payload, it executes the Lightning payment when it has accepted the corresponding Fiber HTLC.
- The cross-chain hub uses the preimage received from the Lightning user to settle the payment in Fiber.
```mermaid
sequenceDiagram
participant Fiber
participant CCH
participant Lightning
Lightning ->> Fiber: Lightning Invoice
Fiber -->> CCH: Payment with Lightning Invoice
CCH -->> Lightning: Payment
Lightning -->> CCH: Settlement
CCH -->> Fiber: Settlement
```
### Via Lightning Offer (BOLT12)
- Cross-chain hub Fiber node announces its cross-chain capability in node announcements via the P2P network. All Fiber nodes should index the cross-chain hub nodes.
- Lightning user generates an offer.
- Fiber node sends the invoice request message to a indexed cross-chain hub node, optionally via a onion message for better privacy. Embed the Lightning offer in the last hop payload.
- When the cross-chain hub receives a invoice request message and a Lightning offer is found in the payload, it sends the Lightning invoice request to get a Lightning invoice.
- The cross-chain hub responds the Fiber invoice request with a invoice message with a embedded Lightning invoice.
- The lightning user continues the payment process using the steps described in the section "Via Lightning Invoice (BOLT11)".
```mermaid
sequenceDiagram
participant Fiber
participant CCH
participant Lightning
Lightning ->> Fiber: Lightning Offer
Fiber -->> CCH: Invoice Request with Lightning Offer
CCH -->> Lightning: Invoice Request
Lightning -->> CCH: Invoice
CCH -->> Fiber: Lightning Invoice
Note over Fiber,Lightning: CCH Payment Via Lightning Invoice
```
## Lightning Pays Fiber
### Via Lightning Invoice (BOLT11)
- Cross-chain hub Fiber node announces its cross-chain capability in node announcements via the P2P network. All Fiber nodes should index the cross-chain hub nodes.
- The Fiber user sends the invoice request to a indexed cross-chain hub to request a HODL Lightning invoice which preimage is only known by the Fiber user..
- The cross-chain hub returns the Lightning invoice via the Fiber P2P network.
- The Fiber use shows the invoice to the payee.
- The Lightning payee pays the invoice.
- Once the cross-chain hub has received the payment and the corresponding HTLC, it initiates the payment in Fiber.
- The Fiber user settles the Fiber payment using the preimage.
- The cross-chain hub settle the Lightning payment once it has received the preimage from the Fiber user.
```mermaid
sequenceDiagram
participant Lightning
participant CCH
participant Fiber
Fiber -->> CCH: CCH Invoice Request
CCH ->> Fiber: Lightning HODL Invoice
Fiber -->> Lightning: Lightning HODL Invoice
Lightning -->> CCH: Payment
CCH -->> Fiber: Payment
Fiber -->> CCH: Settlement
CCH -->> Lightning: Settlement
```
### Via Lightning Offer (BOLT12)
- Cross-chain hub Fiber node announces its cross-chain capability in node announcements via the P2P network. All Fiber nodes should index the cross-chain hub nodes.
- The Fiber user sends the offer request to a indexed cross-chain hub to request a Lightning offer to accept payments from Lightning users.
- The cross-chain hub returns the Lightning offer via the Fiber P2P network.
- The Fiber use shows the offer to the payee.
- The Lightning payee requests an invoice via the offer.
- The cross-chain hub will request the Fiber invoice when it receives the invoice request from the Lightning user.
- The Fiber node returns the invoice.
- The cross-chain hub returns the invoice.
- The Lightning payee pays the invoice.
- The cross-chain hub pays the invoice.
- The Fiber node settles the payment.
- The cross-chain hub settles the payment.
```mermaid
sequenceDiagram
participant Lightning
participant CCH
participant Fiber
Fiber -->> CCH: CCH Offer Request
CCH ->> Fiber: Lightning Offer
Fiber -->> Lightning: Lightning Offer
Lightning -->> CCH: Invoice Request
CCH -->> Fiber: Invoice Request
Fiber -->> CCH: Invoice
CCH -->> Lightning: Invoice
Lightning -->> CCH: Payment
CCH -->> Fiber: Payment
Fiber -->> CCH: Settlement
CCH -->> Lightning: Settlement
```
## Encoding
### Offer
> Offers are a precursor to an `invoice_request`: readers will request an invoice (or multiple) based on the offer. An offer can be much longer-lived than a particular invoice, so it has some different characteristics; in particular the amount can be in a non-lightning currency. It's also designed for compactness to fit inside a QR code easily.
See more details in the [Lightning BOLT12 Spec](https://github.com/lightning/bolts/blob/1563d13999d342680140c693de0b9d65aa522372/12-offer-encoding.md).
### Invoice Request
P2P message to request an invoice
### Invoice
The success response to the Invoice Request message.
### Invoice Error
The failure response to the Invoice Request message.
### CCH Offer Request
P2P message to request a cross-chain Lightning offer.
### CCH Offer
A special Lightning offer for cross-chain payments.
### CCH Offer Error
The failure response to the CCH Offer Request message.