mint

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 12 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 = "MINT"

Subsystem defines the logging code for this subsystem.

Variables

View Source
var (
	// ErrSecretNotFound is an error returned when we attempt to retrieve a
	// secret by its key but it is not found.
	ErrSecretNotFound = errors.New("secret not found")
)

Functions

func UseLogger added in v0.5.0

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 {
	// NewChallenge returns a new challenge in the form of a Lightning
	// payment request. The payment hash is also returned as a convenience
	// to avoid having to decode the payment request in order to retrieve
	// its payment hash.
	NewChallenge(price int64) (string, lntypes.Hash, error)

	// Stop shuts down the challenger.
	Stop()
}

Challenger is an interface used to present requesters of L402s with a challenge that must be satisfied before an L402 can be validated. This challenge takes the form of a Lightning payment request.

type Config

type Config struct {
	// Secrets is our source for L402 secrets which will be used for
	// verification purposes.
	Secrets SecretStore

	// Challenger is our source of new challenges to present requesters of
	// an L402 with.
	Challenger Challenger

	// ServiceLimiter provides us with how we should limit a new L402 based
	// on its target services.
	ServiceLimiter ServiceLimiter

	// Now returns the current time.
	Now func() time.Time

	// TransactionStore is an optional store for recording L402 transaction
	// data. If nil, transaction logging is disabled.
	TransactionStore TransactionStore
}

Config packages all of the required dependencies to instantiate a new L402 mint.

type Mint

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

Mint is an entity that is able to mint and verify L402s for a set of services.

func New

func New(cfg *Config) *Mint

New creates a new L402 mint backed by its given dependencies.

func (*Mint) MintL402

func (m *Mint) MintL402(ctx context.Context,
	services ...l402.Service) (*macaroon.Macaroon, string, error)

MintL402 mints a new L402 for the target services.

func (*Mint) VerifyL402

func (m *Mint) VerifyL402(ctx context.Context,
	params *VerificationParams) error

VerifyL402 attempts to verify an L402 with the given parameters.

type SecretStore

type SecretStore interface {
	// NewSecret creates a new cryptographically random secret which is
	// keyed by the given hash.
	NewSecret(context.Context, [sha256.Size]byte) ([l402.SecretSize]byte,
		error)

	// GetSecret returns the cryptographically random secret that
	// corresponds to the given hash. If there is no secret, then
	// ErrSecretNotFound is returned.
	GetSecret(context.Context, [sha256.Size]byte) ([l402.SecretSize]byte,
		error)

	// RevokeSecret removes the cryptographically random secret that
	// corresponds to the given hash. This acts as a NOP if the secret does
	// not exist.
	RevokeSecret(context.Context, [sha256.Size]byte) error
}

SecretStore is the store responsible for storing L402 secrets. These secrets are required for proper verification of each minted L402.

type ServiceLimiter

type ServiceLimiter interface {
	// ServiceCapabilities returns the capabilities caveats for each
	// service. This determines which capabilities of each service can be
	// accessed.
	ServiceCapabilities(context.Context, ...l402.Service) ([]l402.Caveat,
		error)

	// ServiceConstraints returns the constraints for each service. This
	// enforces additional constraints on a particular service/service
	// capability.
	ServiceConstraints(context.Context, ...l402.Service) ([]l402.Caveat,
		error)

	// ServiceTimeouts returns the timeout caveat for each service. This
	// will determine if and when service access can expire.
	ServiceTimeouts(context.Context, ...l402.Service) ([]l402.Caveat,
		error)
}

ServiceLimiter abstracts the source of caveats that should be applied to an L402 for a particular service.

type TransactionStore added in v0.5.0

type TransactionStore interface {
	// RecordTransaction persists a new pending L402 transaction.
	// The identifierHash is the SHA-256 hash of the encoded macaroon
	// identifier bytes, used to link transactions to secrets.
	RecordTransaction(ctx context.Context, tokenID []byte,
		paymentHash []byte, serviceName string,
		priceSats int64, identifierHash []byte) error
}

TransactionStore is an optional store that records L402 transaction data for analytics and admin dashboard purposes.

type VerificationParams

type VerificationParams struct {
	// Macaroon is the macaroon as part of the L402 we'll attempt to verify.
	Macaroon *macaroon.Macaroon

	// Preimage is the preimage that should correspond to the L402's payment
	// hash.
	Preimage lntypes.Preimage

	// TargetService is the target service a user of an L402 is attempting
	// to access.
	TargetService string
}

VerificationParams holds all of the requirements to properly verify an L402.

Jump to

Keyboard shortcuts

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