An OpenAPI-compatible API for interacting with Spark. With a lightweight payments API to enable backend payment flows on Spark, no Javascript required.
Use the Wallets API to do everything you can do with the Spark SDK, from creating a Lightning invoice to sending stablecoins, all over a REST API.
curl -X 'POST' \
'http://sparkproxy.kevz.dev/wallet/lightning/create' \
-H 'accept: application/json' \
-H 'spark-network: MAINNET' \
-H 'spark-mnemonic: pledge bid coral pitch slight cabbage slice mobile sound swallow brush luxury' \
-H 'Content-Type: application/json' \
-d '{
"amount": 10,
"memo": "Sparkproxy rocks!",
"expirySeconds": 86400
}'
Check out the API documentation for more examples!
Use the Payments API to build backend payment flows. Allow users to pay with any asset, from Bitcoin to stablecoins, with webhooks to manage the payment lifecycle.
curl -X 'POST' \
'http://sparkproxy.kevz.dev/payment' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"network": "MAINNET",
"webhook_url": "https://your-webhook-url.com/webhook",
"spark_address": "sp1pgssxfl73kl4z0zdr3rp2v9dcvsuwk7h77ctylk5eds9ylqs3lpftnxy5eatep",
"offers": [
{
"asset": "BITCOIN",
"amount": 1000,
"token_pubkey": ""
},
{
"asset": "TOKEN",
"amount": 1000,
"token_pubkey": "0369b2fdf62a56e9d21728478d5971e1af6d91b33bd6d4150a137048bdc35fecfb"
}
]
}'
The above will return an invoice ID which you can use to track the payment. Once the payment is received, you will receive a webhook at your specified URL which can be verified with the public key.
import logging
import json
import uvicorn
import requests
import base64
from fastapi import FastAPI
from pydantic import BaseModel
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives.serialization import load_pem_public_key
app = FastAPI()
logger = logging.getLogger(__name__)
public_key = load_pem_public_key(
requests.get(
"https://sparkproxy.kevz.dev/.well-known/webhook-public-key.pem"
).text.encode()
)
def verify_asymmetric(payload, signature):
public_key.verify(
base64.b64decode(signature),
payload.encode("utf-8"),
padding.PKCS1v15(),
hashes.SHA256(),
)
return True
class WebhookPayload(BaseModel):
payload: str
signature: str
@app.post("/webhook")
def webhook(payload: WebhookPayload):
if not verify_asymmetric(payload.payload, payload.signature):
return {"message": "Invalid signature"}
payload = json.loads(payload.payload)
logger.info(payload)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
uvicorn.run(app, host="0.0.0.0", port=8000)
Note that the funds are automatically swept to the Spark address you specified before the webhook is sent.