challenger

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const Subsystem = "CHLL"

Subsystem defines the sub system name of this package.

Variables

View Source
var (
	N_SEC_KEY = os.Getenv("N_SEC_KEY")
	N_PUB_KEY = os.Getenv("N_PUB_KEY")

	MockNostrClient = &NostrClient{}
)

Functions

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type Challenger

type Challenger interface {
	mint.Challenger
	auth.InvoiceChecker
}

Challenger is an interface that combines the mint.Challenger and the auth.InvoiceChecker interfaces.

type InvoiceClient

type InvoiceClient interface {
	// ListInvoices returns a paginated list of all invoices known to lnd.
	ListInvoices(ctx context.Context, in *lnrpc.ListInvoiceRequest,
		opts ...grpc.CallOption) (*lnrpc.ListInvoiceResponse, error)

	// SubscribeInvoices subscribes to updates on invoices.
	SubscribeInvoices(ctx context.Context, in *lnrpc.InvoiceSubscription,
		opts ...grpc.CallOption) (
		lnrpc.Lightning_SubscribeInvoicesClient, error)

	// AddInvoice adds a new invoice to lnd.
	AddInvoice(ctx context.Context, in *lnrpc.Invoice,
		opts ...grpc.CallOption) (*lnrpc.AddInvoiceResponse, error)
}

InvoiceClient is an interface that only implements part of a full lnd client, namely the part around the invoices we need for the challenger to work.

type InvoiceRequestGenerator

type InvoiceRequestGenerator func(price int64, memo MemoParam) (*lnrpc.Invoice, error)

InvoiceRequestGenerator is a function type that returns a new request for the lnrpc.AddInvoice call.

type LNCChallenger

type LNCChallenger struct {
	// contains filtered or unexported fields
}

LNCChallenger is a challenger that uses LNC to connect to an lnd backend to create new LSAT payment challenges.

func NewLNCChallenger

func NewLNCChallenger(session *lnc.Session, lncStore lnc.Store,
	genInvoiceReq InvoiceRequestGenerator, nclient NostrClient,
	errChan chan<- error) (*LNCChallenger, error)

NewLNCChallenger creates a new challenger that uses the given LNC session to connect to an lnd backend to create payment challenges.

func (*LNCChallenger) NewChallenge

func (l *LNCChallenger) NewChallenge(price int64, memo MemoParam) (string, lntypes.Hash,
	error)

NewChallenge creates a new LSAT payment challenge, returning a payment request (invoice) and the corresponding payment hash.

NOTE: This is part of the mint.Challenger interface.

func (*LNCChallenger) Stop

func (l *LNCChallenger) Stop()

Stop stops the challenger.

func (*LNCChallenger) VerifyInvoiceStatus

func (l *LNCChallenger) VerifyInvoiceStatus(hash lntypes.Hash,
	state lnrpc.Invoice_InvoiceState, timeout time.Duration) error

VerifyInvoiceStatus checks that an invoice identified by a payment hash has the desired status. To make sure we don't fail while the invoice update is still on its way, we try several times until either the desired status is set or the given timeout is reached.

NOTE: This is part of the auth.InvoiceChecker interface.

type LndChallenger

type LndChallenger struct {
	// contains filtered or unexported fields
}

LndChallenger is a challenger that uses an lnd backend to create new LSAT payment challenges.

func NewLndChallenger

func NewLndChallenger(client InvoiceClient,
	genInvoiceReq InvoiceRequestGenerator, nclient NostrClient,
	ctxFunc func() context.Context,
	errChan chan<- error) (*LndChallenger, error)

NewLndChallenger creates a new challenger that uses the given connection to an lnd backend to create payment challenges.

func (*LndChallenger) NewChallenge

func (l *LndChallenger) NewChallenge(price int64, memo MemoParam) (string, lntypes.Hash,
	error)

NewChallenge creates a new LSAT payment challenge, returning a payment request (invoice) and the corresponding payment hash.

NOTE: This is part of the mint.Challenger interface.

func (*LndChallenger) Start

func (l *LndChallenger) Start() error

Start starts the challenger's main work which is to keep track of all invoices and their states. For that the backing lnd node is queried for all invoices on startup and the a subscription to all subsequent invoice updates is created.

func (*LndChallenger) Stop

func (l *LndChallenger) Stop()

Stop shuts down the challenger.

func (*LndChallenger) VerifyInvoiceStatus

func (l *LndChallenger) VerifyInvoiceStatus(hash lntypes.Hash,
	state lnrpc.Invoice_InvoiceState, timeout time.Duration) error

VerifyInvoiceStatus checks that an invoice identified by a payment hash has the desired status. To make sure we don't fail while the invoice update is still on its way, we try several times until either the desired status is set or the given timeout is reached.

NOTE: This is part of the auth.InvoiceChecker interface.

type MemoParam added in v0.0.1

type MemoParam = mint.MemoParam

For simple-l402-server

type NostrClient added in v0.0.2

type NostrClient struct {
	// contains filtered or unexported fields
}

func NewNostrClient added in v0.0.2

func NewNostrClient(servicename string, userNPubkey string, slug string, userRelays []string) (*NostrClient, error)

Jump to

Keyboard shortcuts

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