0.1.2 • Published 2 years ago
l402ify-middleware v0.1.2
L402ify-middleware
Getting started
Installationnpx
Download an install via npm:
npm i l402ify-middleware
Adding it to your projects
Simply add and configure the middleware for the routes that should be protected with L402.
import express, { Request, Response, Router } from "express";
import { lsatMiddleware } from "l402ify-middleware";
import bodyParser from "body-parser";
const app = express();
app.use(bodyParser.json());
app.get(
"/",
lsatMiddleware(21, {
lnAddress: "egge@getcurrent.io",
rootKey: "Super secret secret",
location: "http://localhost",
}),
(req: Request, res: Response) => {
res.json({
message: "Great Success!",
});
}
);
app.listen(8000, () => {
console.log(`L402 running on http://localhost:8000`);
});
Reference
function lsatMiddleware(
priceInSats: number, // The price of the requested resource in Satoshi
config: MiddlewareConfig // A config option for the middleware to create valid L402 macaroons
)
type MiddlewareConfig = {
lnAddress: string; // The Lightning Address that should be used to fetch an invoice
rootKey: string; // The secret used to sign the Macaroon
location: string; // The location that the macaroon was created at
}