challenger

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const Subsystem = "CHLL"

Subsystem defines the sub system name of this package.

Variables

This section is empty.

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) (*lnrpc.Invoice, error)

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

type InvoiceTracker added in v0.6.0

type InvoiceTracker interface {
	// TracksInvoices reports whether this client can list its invoices and
	// subscribe to their state changes.
	TracksInvoices() bool
}

InvoiceTracker is an optional capability of an InvoiceClient. A client that mints its invoices somewhere it cannot then enumerate them, such as a wallet daemon reached over an HTTP gateway, implements it and reports false.

It is deliberately a separate interface rather than a method on InvoiceClient. The lnd-backed clients are lnrpc types we do not own and cannot add a method to, so the capability has to be optional, and a client that says nothing is taken to track its invoices exactly as before.

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 L402 payment challenges.

func NewLNCChallenger

func NewLNCChallenger(session *lnc.Session, lncStore lnc.Store,
	invoiceBatchSize int, genInvoiceReq InvoiceRequestGenerator,
	errChan chan<- error, strictVerify bool,
	opts ...LndChallengerOption) (*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) (string, lntypes.Hash,
	error)

NewChallenge creates a new L402 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 L402 payment challenges.

func NewLndChallenger

func NewLndChallenger(client InvoiceClient, batchSize int,
	genInvoiceReq InvoiceRequestGenerator, ctxFunc func() context.Context,
	errChan chan<- error, strictVerification bool,
	opts ...LndChallengerOption) (*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) (string, lntypes.Hash,
	error)

NewChallenge creates a new L402 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 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 LndChallengerOption added in v0.5.0

type LndChallengerOption func(*LndChallenger)

LndChallengerOption is a functional option that can be used to modify the behavior of the LndChallenger.

func WithSettlementCallback added in v0.5.0

func WithSettlementCallback(fn func(hash lntypes.Hash)) LndChallengerOption

WithSettlementCallback sets a callback that will be invoked when an invoice is settled. This can be used to trigger side effects such as recording transaction settlements.

type LndPaymentSender added in v0.5.0

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

LndPaymentSender sends Lightning payments via LND's SendPaymentV2 RPC. This is used by the MPP session authenticator to refund unspent session balances to the client's return invoice.

func NewLndPaymentSender added in v0.5.0

func NewLndPaymentSender(client PaymentClient) *LndPaymentSender

NewLndPaymentSender creates a new LndPaymentSender.

func (*LndPaymentSender) SendPayment added in v0.5.0

func (s *LndPaymentSender) SendPayment(ctx context.Context, invoice string,
	amtSats int64) (string, error)

SendPayment sends a payment to the given invoice with the specified amount in satoshis. Returns the payment preimage hex on success.

type PaymentClient added in v0.5.0

type PaymentClient interface {
	// SendPaymentV2 sends a payment and returns a stream of payment
	// updates.
	SendPaymentV2(ctx context.Context, in *routerrpc.SendPaymentRequest,
		opts ...grpc.CallOption) (routerrpc.Router_SendPaymentV2Client,
		error)
}

PaymentClient is the subset of the lnrpc.LightningClient interface needed for sending payments.

type WavelengthInvoiceClient added in v0.6.0

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

WavelengthInvoiceClient mints L402 challenge invoices from a Wavelength wallet daemon instead of from an lnd node.

The point of it is what the seller no longer has to run. An invoice from waved is backed by an inbound swap, so the swap server supplies the inbound liquidity and settles the payment into the wallet's Ark balance. The seller therefore needs no Lightning node, no channels, and no inbound capacity to get paid, which is the part of standing up an L402 seller that usually costs the most effort.

It satisfies InvoiceClient, so it drives the existing LndChallenger rather than duplicating it. Only AddInvoice does any work: the other two methods exist to track invoice state, which this backend cannot do, and it says so through InvoiceTracker so the challenger knows not to ask.

func NewWavelengthInvoiceClient added in v0.6.0

func NewWavelengthInvoiceClient(gateway string, strictVerify bool,
	macaroonPath string) (*WavelengthInvoiceClient, error)

NewWavelengthInvoiceClient creates an invoice client against the wallet daemon's HTTP/JSON gateway, given its base URL (for example http://localhost:10061).

strictVerify is rejected rather than ignored. Strict verification means the challenger watches every invoice's state and refuses a token whose invoice it has not seen settle, which it does by listing and subscribing to invoices. This backend can do neither, so accepting the flag would leave aperture believing it was verifying settlement when it was not: the failure would be silent and would only show up as tokens honoured for invoices that were never paid.

macaroonPath authorizes the calls. It may be empty, which is only usable against a daemon started with rpc.no-macaroons; the caller is expected to say so, since from here an unauthenticated gateway is indistinguishable from an operator who forgot. The file is read now rather than on each call so a path that does not exist fails at start-up instead of on the first 402 a real client is waiting on.

func (*WavelengthInvoiceClient) AddInvoice added in v0.6.0

AddInvoice mints a challenge invoice, translating lnd's request and response shapes onto the wallet's receive call.

func (*WavelengthInvoiceClient) ListInvoices added in v0.6.0

ListInvoices is not supported on this backend. The challenger asks for the capability through InvoiceTracker before it calls this, so reaching it means something bypassed that check, and an error is the right answer.

func (*WavelengthInvoiceClient) SubscribeInvoices added in v0.6.0

SubscribeInvoices is not supported on this backend, for the same reason as ListInvoices.

func (*WavelengthInvoiceClient) TracksInvoices added in v0.6.0

func (w *WavelengthInvoiceClient) TracksInvoices() bool

TracksInvoices reports that this backend cannot be asked about invoice state. The wallet daemon's gateway exposes minting and nothing else, so there is no way to enumerate the invoices we have handed out or to learn when one of them settles.

NOTE: This is part of the InvoiceTracker interface.

Jump to

Keyboard shortcuts

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