npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

now-paywall

v0.3.0

Published

Zeit lambda deployment for a Nodejs Lightning-powered Paywall

Downloads

10

Readme

The Lightning Paywall Builder

An easy to deploy gateway for enabling payments and authentication with other compatible applications.

Usage

Copy the example directory in this project. index.js exposes the api endpoint you want behind the paywall[1]. Make sure you have now and OpenNode setup, then in the directory run:

# in the project directory copied from `example`
$ now -e OPEN_NODE_KEY=[OpenNode API Key] -e CAVEAT_KEY=[Macaroon Signing Key]

See section below on architecture for more on what these environment variables are for.

Overview

The Lightning Paywall Builder is a relatively simple lambda service built with Zeit's Now service. Currently, the API supports the specific use case of interacting with the Prism Reader application. It serves two primary functions:

  1. Generate invoices for payments based off of received criteria (time based- 1 satoshi/second)
  2. Supports 3rd party, OAuth-style authentication by returning a discharge macaroon after successful payment

In practice, what this means is that you can put this API layer in front of a compatible lightning node (currently the ln-builder only supports the OpenNode API) to provide users with an authorization that can be used in another application.

In the case of Prism, the app is waiting until a user has authenticated with the owner of a document that is being shared on the platform. The user pays the owner of the content, which authenticates you with the app.

Installation

Setting up your own ln-builder payments gateway can be done in just a few steps (most are related to creating accounts to enable deployment).

Setup Zeit

  1. Create a free Zeit account for serverless deployments
  2. Install the now cli for deploying projects directly from your computer

Setup Open Node

  1. Create an OpenNode account on their dev platform [2]
  2. Generate an API key to authenticate with your OpenNode dev account. This will allow you to generate invoices and check on the status of payments. Make sure you save this as you will need it for later steps

Setup deployment

  1. In the project where you want to enable the paywall, setup a now.json configuration file, and use the now-paywall builder for the endpoint you would like protected. See example/now.json in this repo for a sample route that is protected behind the /api/protected endpoint.
  2. Generate or come up with another passphrase. This is called your Caveat Key and is used to sign discharge macaroons so third parties can verify this came from your server.
  3. Next we need to save our secrets for deployment. Once the now cli is installed, run the following command. Make sure to replace anything in brackets [ ] with your own secrets generated above
now secrets add open-node-key "[OPEN_NODE_KEY]" # generated in step 4
now secrets add caveat-key "[CAVEAT_KEY]" # generated in step 6
  1. Run now in your project directory. Zeit will now deploy your ln-builder service and return the uri where it is hosted. Save this and the caveat key (i.e. the passphrase created earlier in step 6)

Architecture

The below image should give an idea of the authentication flow between the ln-builder api, lightning node, 3rd party App requesting the authentication, and the client being authenticated. ln builder diagram

[1]: Full paywall functionality isn't officially supported yet. Currently, content is managed on another platform and this lambda service gives you an endpoint for other services to interact with. [2]: NOTE the dev platform interacts with the Lightning Network on testnet. Currently only testnet is supported but mainnet would be trivial to add in in the future.