Skip to content

An implementation of the L402 protocol

License

Notifications You must be signed in to change notification settings

Byzantium-ETS/lsat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

108 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

L402

An implementation of the L402 protocol.

Overview

L402 is a protocol that leverages the capabilities of the Lightning Network for token minting and service authorization to enable the monetization of APIs through Bitcoin.

Note

Additionally, it offers an implementation of the phoenixd API for integration with a real Lightning node.

Usage

Currently, this project does not offer standalone server or client implementations. However, it provides essential utilities and an example setup to get started.

Example

The example available in the ./server/ and ./client/ directories demonstrates using a mocked Lightning node to issue and resolve challenges.

To get started, follow these instructions:

  1. Launch the Server

    Open a terminal and run the following command to start the server:

    go run ./examples/server/server.go
  2. Mint a Token and Access the Service

    In another terminal, run the following command to mint a token and access the service:

    go run ./examples/client/server.go

Authorization Flow

The authorization flow for L402 tokens is depicted in the following diagram:

sequenceDiagram
    title L402 : Service authorization flow

    actor C as Client
    participant CNode as Client Node
    participant Auth as Authorization Server
    participant SNode as Auth Server Node
    participant Res as Resource

    alt First time user
        C ->> Auth: PUT /
        activate Auth
        Auth ->> SNode: Create invoice
        activate SNode
        SNode -->> Auth: Invoice
        deactivate SNode
        Auth ->> Auth: Mint token + invoice
        Auth -->> C: 402: Payment Required, token + invoice
        deactivate Auth
        C ->> CNode: Send payment
        CNode ->> SNode: Send payment
        activate SNode
        SNode -->> CNode: Preimage
        deactivate SNode
        CNode -->> C: Preimage
    else User with a token
        C ->> Auth: GET /protected, token + preimage
        activate Auth
        Auth ->> Res:
        activate Res
        Res ->> Res: Check token, validate caveats
        Res -->> Auth: Protected
        deactivate Res
        Auth -->> C:
        deactivate Auth
    end
Loading

Resources

For more information, refer to the following resources:

License

This project is licensed under the terms of the MIT License.

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages