test

package module
v0.0.0-...-eb10282 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2023 License: MIT Imports: 4 Imported by: 0

README

LSAT-Middleware

A middleware library for Gin and Echo framework that uses LSAT (a protocol standard for authentication and paid APIs) and provides handler functions to accept microtransactions before serving ad-free content or any paid APIs.

The middleware:-

  1. Checks the preference of the user whether they need paid content or free content.
  2. Verify the LSAT before serving paid content.
  3. Send macaroon and invoice if the user prefers paid content and fails to present a valid LSAT.

Installation

Assuming you've installed Go and Gin

  1. Run this:
go get github.com/getAlby/lsat-middleware
  1. Create .env file (refer .env_example) and configure LND_ADDRESS and MACAROON_HEX for LND client or LNURL_ADDRESS for LNURL client, LN_CLIENT_TYPE (out of LND, LNURL) and ROOT_KEY (for minting macaroons).

Usage

See the examples directory.

This example shows how to use LSAT-Middleware with Gin framework for serving simple JSON response:-

This repo demonstrates serving of static files and creating a paywall for paid resources using LSAT-Middleware.

Nakaphoto, A platform to buy and sell images for sats made using LSAT-Middleware (link to repo).

Testing

Run go test to run tests.

Documentation

Index

Constants

View Source
const (
	TEST_MACAROON_VALID = "" /* 460-byte string literal not displayed */
	TEST_PREIMAGE_VALID = "3965343963626361373962353265376339646632623534373234343163623766"

	TEST_MACAROON_WITHOUT_CAVEATS          = "" /* 368-byte string literal not displayed */
	TEST_MACAROON_WITHOUT_CAVEATS_PREIMAGE = "651505fae9ea341c770c6ebef207d8560d546eb3aee26985e584c15d1c987875"

	TEST_PREIMAGE_INVALID = "fbe9ac25c04e14b10177514e2d57b0e39224e70277ac1a2cd23c28e58cd4ea35"

	ROOT_KEY = "ABDEGHKLMPTC"
)
View Source
const MIN_SATS_TO_BE_PAID = 1
View Source
const SATS_PER_BTC = 100000000

Variables

This section is empty.

Functions

func FiatToBTC

func FiatToBTC(currency string, value float64) *http.Request

Types

type FiatRateConfig

type FiatRateConfig struct {
	Currency string
	Amount   float64
}

func (*FiatRateConfig) FiatToBTCAmountFunc

func (fr *FiatRateConfig) FiatToBTCAmountFunc(req *http.Request) (amount int64)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL