Nostr. Bolt11
(Nostr Lib v0.2.1)
View Source
BOLT-11 Lightning Invoice parser.
Parses Lightning Network invoices according to the BOLT-11 specification. Used by NIP-57 for extracting payment information from zap receipts.
Examples
iex> {:ok, invoice} = Bolt11.decode("lnbc10u1...")
iex> Bolt11.amount_sats(invoice)
1000See: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
Summary
Functions
Returns the amount in millisatoshis, or nil if no amount specified.
Returns the amount in satoshis, or nil if no amount specified.
Decodes a BOLT-11 invoice string.
Checks if the invoice has expired.
Returns the expiry time as a DateTime.
Types
@type t() :: %Nostr.Bolt11{ amount_msats: non_neg_integer() | nil, description: binary() | nil, description_hash: binary() | nil, expiry: non_neg_integer(), network: :mainnet | :testnet | :regtest, payee_pubkey: binary() | nil, payment_hash: binary() | nil, prefix: binary(), raw: binary(), recovery_flag: non_neg_integer() | nil, signature: binary() | nil, timestamp: non_neg_integer() }
Parsed BOLT-11 invoice
Functions
@spec amount_msats(t()) :: non_neg_integer() | nil
Returns the amount in millisatoshis, or nil if no amount specified.
@spec amount_sats(t()) :: non_neg_integer() | nil
Returns the amount in satoshis, or nil if no amount specified.
Examples
iex> {:ok, inv} = Bolt11.decode("lnbc10u1...")
iex> Bolt11.amount_sats(inv)
1000
Decodes a BOLT-11 invoice string.
Returns {:ok, invoice} on success, {:error, reason} on failure.
Examples
iex> Bolt11.decode("lnbc10u1pjq...")
{:ok, %Bolt11{amount_msats: 1_000_000, ...}}
iex> Bolt11.decode("invalid")
{:error, :invalid_prefix}
Checks if the invoice has expired.
@spec expires_at(t()) :: DateTime.t()
Returns the expiry time as a DateTime.