lnurl

package module
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: MIT Imports: 22 Imported by: 22

README

lnurl

A bunch of helpers for building lnurl support into services.

See GoDoc.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FALSE *bool = &f
	TRUE  *bool = &t
)
View Source
var Client = &http.Client{
	Timeout: 5 * time.Second,
}
View Source
var TorClient *http.Client

Functions

func AESCipher

func AESCipher(key, plaintext []byte) (ciphertext []byte, iv []byte, err error)

func AESDecipher

func AESDecipher(key, ciphertext, iv []byte) (plaintext []byte, err error)

func Encode

func Encode(s string) (string, error)

func FindLNURLInText

func FindLNURLInText(text string) (lnurl string, ok bool)

FindLNURLInText uses a Regular Expression to find a bech32-encoded lnurl string in a blob of text.

func IsDomainName added in v1.12.0

func IsDomainName(s string) bool

IsDomainName (from net package) checks if a string is a presentation-format domain name (currently restricted to hostname-compatible "preferred name" LDH labels and SRV-like "underscore labels"; see golang.org/issue/12421).

func LNURLDecode

func LNURLDecode(code string) (string, error)

LNURLDecode takes a bech32-encoded lnurl string and returns a plain-text https URL.

func LNURLDecodeStrict added in v1.12.0

func LNURLDecodeStrict(code string) (string, error)

LNURLDecodeStrict takes a string and returns a valid lnurl, if possible. code can be

func LNURLEncode

func LNURLEncode(actualurl string) (lnurl string, err error)

LNURLEncode takes a plain-text https URL and returns a bech32-encoded uppercased lnurl string.

func LNURLEncodeStrict added in v1.12.0

func LNURLEncodeStrict(actualurl string) (string, error)

LNURLEncodeStrict will encode the actualurl to lnurl. based on the input url, it will determine whether bech32 encoding / url manipulation is necessary

func ParseInternetIdentifier added in v1.4.0

func ParseInternetIdentifier(text string) (name, domain string, ok bool)

ParseInternetIdentifier extracts name and domain from an email-like string like username@example.com

func RandomK1

func RandomK1() string

RandomK1 returns a 32-byte random hex-encoded string for usage as k1 in lnurl-auth and anywhere else.

func VerifySignature

func VerifySignature(k1, sig, key string) (ok bool, err error)

VerifySignature takes the hex-encoded parameters passed to an lnurl-login endpoint and verifies the signature against the key and challenge.

func WithCustomClient added in v1.12.0

func WithCustomClient(c *http.Client)

Types

type LNURLAuthParams

type LNURLAuthParams struct {
	Tag         string   `json:"tag"`
	K1          string   `json:"k1"`
	Callback    string   `json:"callback"`
	CallbackURL *url.URL `json:"-"`
	Host        string   `json:"host"`
}

func (LNURLAuthParams) LNURLKind

func (_ LNURLAuthParams) LNURLKind() string

type LNURLChannelResponse

type LNURLChannelResponse struct {
	LNURLResponse
	Tag         string   `json:"tag"`
	K1          string   `json:"k1"`
	Callback    string   `json:"callback"`
	CallbackURL *url.URL `json:"-"`
	URI         string   `json:"uri"`
}

func (LNURLChannelResponse) LNURLKind

func (_ LNURLChannelResponse) LNURLKind() string

type LNURLErrorResponse

type LNURLErrorResponse struct {
	Status string   `json:"status,omitempty"`
	Reason string   `json:"reason,omitempty"`
	URL    *url.URL `json:"-"`
}

func ErrorResponse

func ErrorResponse(reason string) LNURLErrorResponse

func (LNURLErrorResponse) Error

func (r LNURLErrorResponse) Error() string

type LNURLParams

type LNURLParams interface {
	LNURLKind() string
}

func HandleAuth

func HandleAuth(rawurl string, parsed *url.URL, query url.Values) (LNURLParams, error)

func HandleChannel

func HandleChannel(raw []byte) (LNURLParams, error)

func HandleFastWithdraw

func HandleFastWithdraw(query url.Values) (LNURLParams, bool)

func HandleLNURL

func HandleLNURL(rawlnurl string) (string, LNURLParams, error)

HandleLNURL takes a bech32-encoded lnurl and either gets its parameters from the query- string or calls the URL to get the parameters. Returns a different struct for each of the lnurl subprotocols, the .LNURLKind() method of which should be checked next to see how the wallet is going to proceed.

func HandlePay

func HandlePay(raw []byte) (LNURLParams, error)

func HandleWithdraw

func HandleWithdraw(raw []byte) (LNURLParams, error)

type LNURLPayParams added in v1.6.0

type LNURLPayParams struct {
	LNURLResponse
	Callback        string         `json:"callback"`
	Tag             string         `json:"tag"`
	MaxSendable     int64          `json:"maxSendable"`
	MinSendable     int64          `json:"minSendable"`
	EncodedMetadata string         `json:"metadata"`
	CommentAllowed  int64          `json:"commentAllowed"`
	PayerData       *PayerDataSpec `json:"payerData,omitempty"`

	Metadata Metadata `json:"-"`
}

func (LNURLPayParams) Call added in v1.6.0

func (params LNURLPayParams) Call(
	msats int64,
	comment string,
	payerdata *PayerDataValues,
) (*LNURLPayValues, error)

func (LNURLPayParams) CallbackURL added in v1.6.0

func (params LNURLPayParams) CallbackURL() *url.URL

func (LNURLPayParams) LNURLKind added in v1.6.0

func (_ LNURLPayParams) LNURLKind() string

func (LNURLPayParams) MetadataEncoded added in v1.7.0

func (params LNURLPayParams) MetadataEncoded() string

func (*LNURLPayParams) Normalize added in v1.9.0

func (params *LNURLPayParams) Normalize() error

type LNURLPayValues added in v1.6.0

type LNURLPayValues struct {
	LNURLResponse
	SuccessAction *SuccessAction `json:"successAction"`
	Routes        interface{}    `json:"routes"` // ignored
	PR            string         `json:"pr"`
	Disposable    *bool          `json:"disposable,omitempty"`

	ParsedInvoice decodepay.Bolt11 `json:"-"`
	PayerDataJSON string           `json:"-"`
}

func CallPay added in v1.10.2

func CallPay(
	metadata string,
	callback *url.URL,
	msats int64,
	comment string,
	payerdata *PayerDataValues,
) (*LNURLPayValues, error)

type LNURLResponse

type LNURLResponse struct {
	Status string `json:"status,omitempty"`
	Reason string `json:"reason,omitempty"`
}

The base response for all lnurl calls.

func OkResponse

func OkResponse() LNURLResponse

type LNURLWithdrawResponse

type LNURLWithdrawResponse struct {
	LNURLResponse
	Tag                string   `json:"tag"`
	K1                 string   `json:"k1"`
	Callback           string   `json:"callback"`
	CallbackURL        *url.URL `json:"-"`
	MaxWithdrawable    int64    `json:"maxWithdrawable"`
	MinWithdrawable    int64    `json:"minWithdrawable"`
	DefaultDescription string   `json:"defaultDescription"`
	BalanceCheck       string   `json:"balanceCheck,omitempty"`
	PayLink            string   `json:"payLink,omitempty"`
}

func (LNURLWithdrawResponse) LNURLKind

func (_ LNURLWithdrawResponse) LNURLKind() string

type Metadata

type Metadata struct {
	Description     string
	LongDescription string
	Image           struct {
		DataURI string
		Bytes   []byte
		Ext     string
	}
	LightningAddress string
	IsEmail          bool
}

func (Metadata) Encode added in v1.6.1

func (metadata Metadata) Encode() string

type PayerDataItemSpec added in v1.6.0

type PayerDataItemSpec struct {
	Mandatory bool `json:"mandatory"`
}

type PayerDataKeyAuthSpec added in v1.6.0

type PayerDataKeyAuthSpec struct {
	Mandatory bool   `json:"mandatory"`
	K1        string `json:"k1"`
}

type PayerDataKeyAuthValues added in v1.6.0

type PayerDataKeyAuthValues struct {
	K1  string `json:"k1"`
	Sig string `json:"sig"`
	Key string `json:"key"`
}

type PayerDataSpec added in v1.6.0

type PayerDataSpec struct {
	FreeName         *PayerDataItemSpec    `json:"name"`
	PubKey           *PayerDataItemSpec    `json:"pubkey"`
	LightningAddress *PayerDataItemSpec    `json:"identifier"`
	Email            *PayerDataItemSpec    `json:"email"`
	KeyAuth          *PayerDataKeyAuthSpec `json:"auth"`
}

func (PayerDataSpec) Exists added in v1.6.0

func (s PayerDataSpec) Exists() bool

type PayerDataValues added in v1.6.0

type PayerDataValues struct {
	FreeName         string                  `json:"name,omitempty"`
	PubKey           string                  `json:"pubkey,omitempty"`
	LightningAddress string                  `json:"identifier,omitempty"`
	Email            string                  `json:"email,omitempty"`
	KeyAuth          *PayerDataKeyAuthValues `json:"auth,omitempty"`
}

type SuccessAction

type SuccessAction struct {
	Tag         string `json:"tag"`
	Description string `json:"description,omitempty"`
	URL         string `json:"url,omitempty"`
	Message     string `json:"message,omitempty"`
	Ciphertext  string `json:"ciphertext,omitempty"`
	IV          string `json:"iv,omitempty"`
}

func AESAction

func AESAction(description string, preimage []byte, content string) (*SuccessAction, error)

func Action

func Action(text string, url string) *SuccessAction

func (*SuccessAction) Decipher

func (sa *SuccessAction) Decipher(preimage []byte) (content string, err error)

Jump to

Keyboard shortcuts

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