Module breez_sdk_core::lightning::offers::invoice
Expand description
Data structures and encoding for invoice
messages.
A Bolt12Invoice
can be built from a parsed InvoiceRequest
for the “offer to be paid”
flow or from a Refund
as an “offer for money” flow. The expected recipient of the payment
then sends the invoice to the intended payer, who will then pay it.
The payment recipient must include a PaymentHash
, so as to reveal the preimage upon payment
receipt, and one or more BlindedPath
s for the payer to use when sending the payment.
extern crate bitcoin;
extern crate lightning;
use bitcoin::hashes::Hash;
use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
use core::convert::{Infallible, TryFrom};
use lightning::offers::invoice_request::InvoiceRequest;
use lightning::offers::refund::Refund;
use lightning::util::ser::Writeable;
let payment_paths = create_payment_paths();
let payment_hash = create_payment_hash();
let secp_ctx = Secp256k1::new();
let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32])?);
let pubkey = PublicKey::from(keys);
let wpubkey_hash = bitcoin::util::key::PublicKey::new(pubkey).wpubkey_hash().unwrap();
let mut buffer = Vec::new();
// Invoice for the "offer to be paid" flow.
InvoiceRequest::try_from(bytes)?
.respond_with(payment_paths, payment_hash)?
.relative_expiry(3600)
.allow_mpp()
.fallback_v0_p2wpkh(&wpubkey_hash)
.build()?
.sign::<_, Infallible>(
|message| Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
)
.expect("failed verifying signature")
.write(&mut buffer)
.unwrap();
// Invoice for the "offer for money" flow.
"lnr1qcp4256ypq"
.parse::<Refund>()?
.respond_with(payment_paths, payment_hash, pubkey)?
.relative_expiry(3600)
.allow_mpp()
.fallback_v0_p2wpkh(&wpubkey_hash)
.build()?
.sign::<_, Infallible>(
|message| Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
)
.expect("failed verifying signature")
.write(&mut buffer)
.unwrap();
Structs§
- Information needed to route a payment across a
BlindedPath
. Bolt12Invoice::signing_pubkey
was derived.Bolt12Invoice::signing_pubkey
was explicitly set.- Builds a
Bolt12Invoice
from either: - A semantically valid
Bolt12Invoice
that hasn’t been signed.
Constants§
- Tag for the hash function used when signing a
Bolt12Invoice
’s merkle root.
Traits§
- Indicates how
Bolt12Invoice::signing_pubkey
was set.