0.0
The project is in a healthy, maintained state
A Ruby middleware implementation for the L402 protocol, leveraging macaroons and the Lightning Network for secure authentication and payments.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 0

Runtime

 Project Readme

L402 Logo L402 Middleware for Rails

⚑ Boltwall for Rails: seamless L402 paywalls and API monetization with Lightning

L402 Middleware is a Ruby gem that seamlessly integrates with your Rails application, enabling L402 protocol functionality. Build microservices, APIs, or payment gateways with pay-per-request authentication using the Lightning Network β€” effortlessly.


πŸš€ Key Features

  • Plug-and-Play: Integrate with Rails with just a single line of configuration.
  • Lightning Network Ready: Enforces payment and authentication standards based on L402.
  • Highly Configurable: Customize request handling, payments, and caveats.
  • Lightweight & Fast: Minimal dependencies for optimal performance.

πŸ› οΈ Installation

Add the gem to your application's Gemfile:

gem 'l402_middleware'

Then install:

bundle install

βš™οΈ Configuration

  1. Add the middleware to your Rails stack in application.rb:
# config/application.rb
config.middleware.use L402Middleware, config.l402_middleware
  1. Define configuration options:
config.l402_middleware = {
  network_type: :lnd,
  root_key: 'your_root_key',
  caveats: [],
  lnd: {
    address: '<lnd-node-address>',
    tls_certificate_path: '<tls-cert-path>',
    macaroon_path: '<macaroon_path>'
  },
  invoice: {
    millisatoshis: 100,
    description: 'Payment required to access the API',
    payable: 'once'  # or 'indefinitely'
  },
  endpoints: ['/protected'] # Endpoints to protect with L402 paywall
}

πŸ“– Usage

Once configured, the middleware will:

  • Inspect incoming HTTP headers for L402-compliant payment tokens.
  • Validate the token with the configured validator.
  • Reject requests that don’t meet the payment threshold with HTTP 402 Payment Required.

Example Request Flow

  1. Client sends a request:
GET /protected-resource HTTP/1.1
Host: example.com
Authorization: L402 <token>
  1. Middleware validates the token and processes payment.

  2. Rails app continues processing if the payment is successful.


πŸ”§ Development

Clone the repository:

git clone https://github.com/rits1272/l402_middleware.git
cd l402_middleware

Run tests:

bundle exec rspec

πŸ“« Contact & Support

If you have questions, feedback, or need support:

Bring the power of the Lightning Network to your Rails apps in minutes. Happy coding! ⚑