A boilerplate project to build proof of concept paywalls with lightning service authentication tokens (LSATs)

Overview

lsat-workshop-boilerplate

A boilerplate project to build proof of concept paywalls with lightning service authentication tokens (LSATs)

Install

$ git clone [email protected]:bucko13/lsat-workshop-boilerplate.git
$ cd lsat-workshop-boilerplate
$ npm install

Setup Regtest Network

You can choose to connect to a network however you wish, even a live mainnet node. However, for the purposes of this boilerplate, we'll use Polar.

Go to https://polarlightning.com and download the application. Next, you'll want to start a new network. This will create a bitcoin node on simulated local network, spin up 3 lightning nodes by default, mine blocks and fund all the wallets. Make sure at least one of your nodes is lnd since that's the only API boltwall currently supports.

Once that's running, create channels between your nodes in the Polar network.

Setup Environment Variables

Copy the .env.example file to a .env file locally. This is where you will be setting your configs for connecting to your lightning node.

If you want to persist LSAT validation between restarts, you'll want to generate a random secret. You can do this in a Node REPL pretty easily:

const crypto = require('crypto')
crypto.randomBytes(32).toString('hex')

Copy and paste the output to your .env file.

LND configs

Head back to Polar and choose your lnd node from the network. From the toolbar on the side, select "Connect", and then you should be able to get the hex versions of the connection details. Copy these over to the corresponding variables in the .env file.

Usage

You should have everything you need to run the testing server now

Run the following command to spin up a test server. This will restart anytime a file changes and it automatically compiles your typescript.

$ npm run dev

This will run a server at the localhost port 3000 by default.

A recommended way to interact with the endpoint is using a tool like Postman. This is a convenient way to read and edit headers which you will need to use the LSATs.

Free endpoint

Now, try and hit the endpoint: GET localhost:3000/ and you should get a welcome message.

Protected Endpoint - baseline

Next, try and hit the first protected endpoint: GET localhost:3000/protected. This will return a 402 endpoint requiring payment to reach.

To get access to the payment, look at the WWW-Authenticate header. To parse the LSAT challenge you can paste in to the LSAT Playground here.

Find the invoice and copy it to get ready for payment. You will want to pay with a tool that will return the preimage as proof of payment.

With polar you do this by launching the terminal and then entering:

# cli depends on the node implementation, e.g. could be `lncli`
$ lightning-cli pay [bolt11 invoice]

Copy the preimage and then go to Satisfy the LSAT in the playground. This is as simple as filling in: LSAT [MACAROON]:[PREIMAGE] but the playground can do this for you just in case.

Copy the satisfied LSAT and add an Authorization header to your request for the protected endpoint with the LSAT as its value.

Try and hit GET localhost:3000/protected again with the Authorization header and it should let you through.

Service-level endpoints

To show the power of caveats, you can try and hit the service level endpoints. GET localhost:3000/protected/service/1 will fail with the baseline Authorization LSAT from the previous steps. To get access to the services, head on over to the playground to add some caveats.

Try adding service=1, then copy the resulting macaroon, replacing the existing macaroon in your LSAT header with the new one. Now, GET localhost:3000/protected/service/1 should work. If you try and hit /service/2 however, you won't be allowed.

If you try and add a greater service level to your existing LSAT, you'll find that our authorization middleware won't allow it. This is because we've set up a delegation system, whereby you can give out more restrictive access (service level 2 can add a caveat that restricts to level 1) but you can't give out less restrictive access (someone with level 1 access shouldn't be able to give out level 2 access).

Try mixing around adding different caveats and see how it works!

Enable time based caveats

Finally, you can enable time-based caveats using boltwall's built in configs. This will make it such that you have limited access once you've paid for your LSAT such that for every satoshi paid, you'll have 1 second of access.

To enable this set the ENABLE_TIME_CONFIG to true in the .env file. You will need to turn your server off entirely and start it again for the change to take effect so that the new environment variable is available at runtime.

Customize protected routes

All the protected route logic is in /src/protected.ts. Fiddle with the different settings, add new caveat satisfiers for your own custom restrictions, and use logging to understand how everything is parsed and handled.

Useful Resources

You might also like...

We are creating a Library that would ensure developers do not reinvent the wheel anymore as far as Authentication is concerned. Developers can easily register and download authentication codes that suits their need at any point.

We are creating a Library that would ensure developers do not reinvent the wheel anymore as far as Authentication is concerned. Developers can easily register and download authentication codes that suits their need at any point.

#AuthWiki Resource Product Documentation Figma Database Schema First Presentation Live Link API Documentation Individual Contributions User Activity U

Dec 2, 2022

Simple yet flexible charting Lightning Web Component using Chart.js for admins & developers

Simple yet flexible charting Lightning Web Component using Chart.js for admins & developers

Lightning Web Chart.js Component Simple yet flexible charting Lightning Web Component using Chart.js for admins & developers Documentation Getting sta

Dec 9, 2022

A website for tracking community support for BIP21 QR codes that support on-chain and lightning bitcoin payments.

BIP21 Microsite This is a WIP microsite to promote the usage of a BIP21 payment URI QR code that can include lightning invoices or offers. Wallet supp

Nov 27, 2022

Inter Process Communication Module for node supporting Unix sockets, TCP, TLS, and UDP. Giving lightning speed on Linux, Mac, and Windows. Neural Networking in Node.JS

Inter Process Communication Module for node supporting Unix sockets, TCP, TLS, and UDP. Giving lightning speed on Linux, Mac, and Windows. Neural Networking in Node.JS

Inter Process Communication Module for node supporting Unix sockets, TCP, TLS, and UDP. Giving lightning speed on Linux, Mac, and Windows. Neural Networking in Node.JS

Dec 9, 2022

🦆 lightning fast duckdb bindings for bun runtime

@evan/duckdb lightning fast duckdb bindings for bun runtime Install bun add @evan/duckdb Features 🔋 batteries included 🚀 jit optimized bindings 🐇 4

Oct 20, 2022

Web app that generates BOLT11 invoices from an LNURL or Lightning Address.

LNURL Pay ⚡️ Web app that generates BOLT11 invoices from an LNURL or Lightning Address. Getting Started First, run the development server: npm run dev

Nov 3, 2022

ln-charts parses the output of bos accounting commands into various charts for your Lightning Node.

ln-charts parses the output of bos accounting commands into various charts for your Lightning Node.

ln-charts ln-charts parses the output of bos accounting commands into various charts for your Lightning Node. It runs on Angular, JS, HTML, CSS, ngx-c

Dec 18, 2022

A tiny, lightning fast jQuery-like library for modern browsers.

Sprint.js Sprint is a high-performance, 5KB (gzipped) DOM library for modern browsers. Sprint notably shines on bandwidth and resource constrained dev

Jan 3, 2023

⚡️ Lightning Time: a new way to measure time

Lightning Time ⚡️ Lightning Time ⚡️ is a new way to measure time. It's a spin on hexadecimal time: the day is split into 16 parts over and over. The f

Nov 22, 2022
Owner
Buck Perley
Buck Perley
NFT vending machine proof of concept built on Solana Pay, Metaplex, Phantom Mobile and Next.js.

Solana NFT Vending Machine This is a proof of concept of an NFT vending machine built using Solana Pay, Metaplex, Phantom Mobile, and Next.js. This wa

Matt Rosenzweig 55 Dec 15, 2022
True P2P concept for your p2p powered website/app/client. MSC/MEP (Multiple Strategy Concept/Multiple Entry Points)

TRUE P2P CONCEPT - Lets redecentralize the web This repo is just conceptual. Active development of the endproduct (TRUE P2P) happens here https://gith

Bo 6 Mar 29, 2022
Proof of concept: support immutable trpc servers using lambdas to ensure client/server compatibility

auto-versioned-trpc-aws-lambda Proof of concept to support an automatically versioned AWS Lambda running tRPC to ensure a somewhat graceful and automa

Kenneth Skovhus 5 Aug 30, 2022
Simple Jai to WASM Proof-of-Concept

Simple Jai to WASM Proof-of-Concept Jai does not officially support WebAssembly compilation target. BUT! It allows you to dump LLVM IR via the llvm_op

Tsoding 52 Dec 14, 2022
A proof-of-concept malicious Chrome extension

Crux: Demonstration Malicious Chrome Extension This repository is for educational purposes only. If you use this outside of security research or autho

Michael Taggart 18 Nov 9, 2022
CVE-2022-22629 Proof of Concept

CVE-2022-22629 Proof of concept This post is about the poc for the WebGL bug that was patched in Safari 15.4 security updates. If you want to learn in

PARS Defense 45 Jan 9, 2023
Demodal is a browser extension that automatically removes content blocking modals including paywalls, discount offers, promts to sign up or enter your email address and more.

Demodal Demodal is a browser extension that automatically removes content blocking modals including paywalls, discount offers, promts to sign up or en

Elbert Alias 225 Jan 4, 2023
An Opensource Peer-to-peer Social Network with Zero-Knowledge-Proof based authentication.

HexHoot This is an attempt to create an Opensource Peer-to-peer Social Network with Zero-Knowledge-Proof based authentication. The objective is to dem

Zenin Easa Panthakkalakath 6 Dec 28, 2022
Receive crypto payments from anywhere around the world, options including native tokens (MATIC, ETHER,BUSD), Tokens (USDT,BUSD), NFTs and more.

Receive payments for service rendered in crypto using different options. Go borderless with bonpay, gain access to varities of crypto assets, safe and

Johnson awah Alfred 6 Nov 11, 2022
Discord Like Tokens for Authentication for Everyone. Uses HMAC with SHA-256

DC Tokens About DCTokens are the discord like tokens that can be used for authentiction in your website, api, or anything you want (you can even trick

Arnav Kumar 3 Oct 31, 2022