The Lightning Client API provides endpoints for managing atomic swaps between Lightning Network and Citrea using Schnorr signature proofs.
- Development:
http://localhost:3001/api - Production:
https://your-domain.com/api
Currently, no authentication is required. In production, consider implementing API keys or JWT tokens.
All responses are in JSON format. Error responses include an error field with a descriptive message.
{
"data": "response_data"
}{
"error": "Error message describing what went wrong"
}Fetch Lightning address data and capabilities.
Parameters:
address(string, required): Lightning address (e.g.,user@domain.com)
Response:
{
"address": "user@domain.com",
"lnurlpData": {
"callback": "https://domain.com/lnurlp/callback",
"maxSendable": 1000000,
"minSendable": 1000,
"metadata": "[[\"text/plain\",\"Payment description\"]]",
"tag": "payRequest"
},
"keysendData": {
"callback": "https://domain.com/keysend/callback",
"maxSendable": 1000000,
"minSendable": 1000,
"tag": "keysend"
},
"isSupported": true
}Request an invoice from a Lightning address.
Request Body:
{
"address": "user@domain.com",
"amount": 1000,
"description": "Payment description (optional)"
}Response:
{
"paymentRequest": "lnbc10u1p3...",
"paymentHash": "abc123...",
"amount": 1000,
"description": "Payment description",
"timestamp": 1234567890,
"expiry": 3600
}Verify if an invoice has been paid.
Request Body:
{
"paymentRequest": "lnbc10u1p3..."
}Response:
{
"isPaid": true,
"invoice": {
"paymentRequest": "lnbc10u1p3...",
"paymentHash": "abc123...",
"amount": 1000,
"description": "Payment description",
"timestamp": 1234567890,
"expiry": 3600
},
"preimage": "def456..." // Only present if paid
}Create a payment proof with Schnorr signature.
Request Body:
{
"paymentHash": "abc123...",
"preimage": "def456...",
"amount": 1000,
"lightningAddress": "user@domain.com"
}Response:
{
"paymentHash": "abc123...",
"preimage": "def456...",
"signature": "r_value_s_value_concatenated...",
"publicKey": "public_key_hex...",
"timestamp": 1234567890,
"amount": 1000
}Create a boost payment (value-for-value).
Request Body:
{
"address": "user@domain.com",
"amount": 1000,
"metadata": {
"app_name": "Lightning Client",
"app_version": "1.0.0",
"name": "Sender Name",
"sender_name": "Sender Name"
}
}Response:
{
"preimage": "def456..."
}Create a zap payment (Nostr integration).
Request Body:
{
"address": "user@domain.com",
"amount": 1000,
"options": {
"comment": "Awesome post!",
"relays": ["wss://relay.damus.io"],
"e": "event_id",
"p": "pubkey"
}
}Response:
{
"preimage": "def456..."
}Create a new atomic swap.
Request Body:
{
"lightningAddress": "recipient@lightning.address",
"amount": 1000,
"defiAction": {
"type": "release_tokens",
"recipient": "0x...",
"amount": 1000,
"metadata": {
"description": "Swap description"
}
}
}Response:
{
"id": "swap_1234567890_abc123",
"lightningAddress": "recipient@lightning.address",
"amount": 1000,
"defiAction": {
"type": "release_tokens",
"recipient": "0x...",
"amount": 1000,
"metadata": {
"description": "Swap description"
}
},
"status": "pending",
"createdAt": 1234567890
}Get swap details by ID.
Parameters:
id(string, required): Swap ID
Response:
{
"id": "swap_1234567890_abc123",
"lightningAddress": "recipient@lightning.address",
"amount": 1000,
"defiAction": {
"type": "release_tokens",
"recipient": "0x...",
"amount": 1000
},
"status": "completed",
"createdAt": 1234567890,
"paymentProof": {
"paymentHash": "abc123...",
"preimage": "def456...",
"signature": "r_value_s_value...",
"publicKey": "public_key_hex...",
"timestamp": 1234567890,
"amount": 1000
},
"transactionHash": "0x..."
}List all swaps with optional filtering.
Query Parameters:
status(string, optional): Filter by status (pending,paid,verified,completed,failed)
Response:
[
{
"id": "swap_1234567890_abc123",
"lightningAddress": "recipient@lightning.address",
"amount": 1000,
"defiAction": {
"type": "release_tokens",
"recipient": "0x...",
"amount": 1000
},
"status": "completed",
"createdAt": 1234567890
}
]Process a Lightning payment for a swap.
Parameters:
id(string, required): Swap ID
Request Body:
{
"paymentHash": "abc123..."
}Response:
{
"success": true
}Verify payment proof and complete swap.
Parameters:
id(string, required): Swap ID
Request Body:
{
"preimage": "def456..."
}Response:
{
"success": true
}Get swap statistics.
Response:
{
"total": 100,
"pending": 5,
"paid": 10,
"verified": 15,
"completed": 65,
"failed": 5
}Verify a payment proof on-chain.
Request Body:
{
"proof": {
"paymentHash": "abc123...",
"preimage": "def456...",
"signature": "r_value_s_value...",
"publicKey": "public_key_hex...",
"timestamp": 1234567890,
"amount": 1000
}
}Response:
{
"isValid": true,
"paymentHash": "abc123...",
"amount": 1000,
"timestamp": 1234567890
}Check if a payment has been verified on-chain.
Parameters:
hash(string, required): Payment hash
Response:
{
"isVerified": true
}Get payment details from the oracle contract.
Parameters:
hash(string, required): Payment hash
Response:
{
"amount": 1000,
"timestamp": 1234567890,
"verified": true
}Get transaction details.
Parameters:
hash(string, required): Transaction hash
Response:
{
"hash": "0x...",
"from": "0x...",
"to": "0x...",
"value": "1000000000000000000",
"gasUsed": "21000",
"status": "confirmed",
"blockNumber": 12345,
"timestamp": 1234567890
}Get current block number.
Response:
{
"blockNumber": 12345
}Get wallet information.
Response:
{
"address": "0x...",
"balance": "1.5"
}Connect to ws://localhost:3002 for real-time updates.
const ws = new WebSocket("ws://localhost:3002");ws.send(
JSON.stringify({
type: "subscribe_payment",
paymentHash: "abc123...",
})
);ws.send(
JSON.stringify({
type: "subscribe_swap",
swapId: "swap_1234567890_abc123",
})
);{
"type": "payment_event",
"event": {
"type": "PaymentVerified",
"paymentHash": "abc123...",
"verifier": "0x...",
"amount": 1000,
"timestamp": 1234567890,
"transactionHash": "0x..."
}
}{
"type": "payment_event",
"event": {
"type": "PaymentRejected",
"paymentHash": "abc123...",
"reason": "Invalid signature",
"transactionHash": "0x..."
}
}{
"type": "swap_updated",
"swap": {
"id": "swap_1234567890_abc123",
"status": "completed",
"transactionHash": "0x..."
}
}| Code | Description |
|---|---|
| 400 | Bad Request - Invalid input parameters |
| 404 | Not Found - Resource not found |
| 500 | Internal Server Error - Server error |
Currently, no rate limiting is implemented. In production, consider implementing rate limiting to prevent abuse.
CORS is enabled for all origins in development. In production, configure CORS to only allow trusted domains.
-
Create Swap:
curl -X POST http://localhost:3001/api/swap/create \ -H "Content-Type: application/json" \ -d '{ "lightningAddress": "test@getalby.com", "amount": 1000, "defiAction": { "type": "release_tokens", "recipient": "0x...", "amount": 1000 } }'
-
Request Invoice:
curl -X POST http://localhost:3001/api/lightning/invoice \ -H "Content-Type: application/json" \ -d '{ "address": "test@getalby.com", "amount": 1000, "description": "Test payment" }'
-
Verify Payment:
curl -X POST http://localhost:3001/api/lightning/verify \ -H "Content-Type: application/json" \ -d '{ "paymentRequest": "lnbc10u1p3..." }'
-
Process Payment:
curl -X POST http://localhost:3001/api/swap/swap_123/payment \ -H "Content-Type: application/json" \ -d '{ "paymentHash": "abc123..." }'
-
Verify and Complete:
curl -X POST http://localhost:3001/api/swap/swap_123/verify \ -H "Content-Type: application/json" \ -d '{ "preimage": "def456..." }'