Skip to content

lightning-digital-entertainment/l402ify-middleware

Repository files navigation

L402ify-middleware


An express middleware to add L402 pay gates to your routes, using only a Lightning Address.
Report Bug · Request Feature

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: "[email protected]",
        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
}

About

A L402 middleware to protect your express routes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published