Skip to content

Qualify BOLT 11/12 invoice and related types #2416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 15, 2023
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ jobs:
check_commits:
runs-on: ubuntu-latest
env:
TOOLCHAIN: 1.57.0
TOOLCHAIN: stable
steps:
- name: Checkout source code
uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions fuzz/src/bech32_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use crate::utils::test_logger;
use core::convert::TryFrom;
use lightning::offers::parse::{Bech32Encode, ParseError};
use lightning::offers::parse::{Bech32Encode, Bolt12ParseError};

#[inline]
pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
Expand All @@ -35,8 +35,8 @@ impl AsRef<[u8]> for Bytes {
}

impl TryFrom<Vec<u8>> for Bytes {
type Error = ParseError;
fn try_from(data: Vec<u8>) -> Result<Self, ParseError> {
type Error = Bolt12ParseError;
fn try_from(data: Vec<u8>) -> Result<Self, Bolt12ParseError> {
Ok(Bytes(data))
}
}
Expand Down
4 changes: 2 additions & 2 deletions fuzz/src/invoice_deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
// licenses.

use crate::utils::test_logger;
use lightning::offers::invoice::Invoice;
use lightning::offers::invoice::Bolt12Invoice;
use lightning::util::ser::Writeable;
use std::convert::TryFrom;

#[inline]
pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
if let Ok(invoice) = Invoice::try_from(data.to_vec()) {
if let Ok(invoice) = Bolt12Invoice::try_from(data.to_vec()) {
let mut bytes = Vec::with_capacity(data.len());
invoice.write(&mut bytes).unwrap();
assert_eq!(data, bytes);
Expand Down
6 changes: 3 additions & 3 deletions fuzz/src/invoice_request_deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use lightning::blinded_path::BlindedPath;
use lightning::sign::EntropySource;
use lightning::ln::PaymentHash;
use lightning::ln::features::BlindedHopFeatures;
use lightning::offers::invoice::{BlindedPayInfo, UnsignedInvoice};
use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
use lightning::offers::invoice_request::InvoiceRequest;
use lightning::offers::parse::SemanticError;
use lightning::offers::parse::Bolt12SemanticError;
use lightning::util::ser::Writeable;

#[inline]
Expand Down Expand Up @@ -71,7 +71,7 @@ fn privkey(byte: u8) -> SecretKey {

fn build_response<'a, T: secp256k1::Signing + secp256k1::Verification>(
invoice_request: &'a InvoiceRequest, secp_ctx: &Secp256k1<T>
) -> Result<UnsignedInvoice<'a>, SemanticError> {
) -> Result<UnsignedBolt12Invoice<'a>, Bolt12SemanticError> {
let entropy_source = Randomness {};
let paths = vec![
BlindedPath::new_for_message(&[pubkey(43), pubkey(44), pubkey(42)], &entropy_source, secp_ctx).unwrap(),
Expand Down
6 changes: 3 additions & 3 deletions fuzz/src/offer_deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::utils::test_logger;
use core::convert::{Infallible, TryFrom};
use lightning::offers::invoice_request::UnsignedInvoiceRequest;
use lightning::offers::offer::{Amount, Offer, Quantity};
use lightning::offers::parse::SemanticError;
use lightning::offers::parse::Bolt12SemanticError;
use lightning::util::ser::Writeable;

#[inline]
Expand Down Expand Up @@ -41,13 +41,13 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {

fn build_response<'a>(
offer: &'a Offer, pubkey: PublicKey
) -> Result<UnsignedInvoiceRequest<'a>, SemanticError> {
) -> Result<UnsignedInvoiceRequest<'a>, Bolt12SemanticError> {
let mut builder = offer.request_invoice(vec![42; 64], pubkey)?;

builder = match offer.amount() {
None => builder.amount_msats(1000).unwrap(),
Some(Amount::Bitcoin { amount_msats }) => builder.amount_msats(amount_msats + 1)?,
Some(Amount::Currency { .. }) => return Err(SemanticError::UnsupportedCurrency),
Some(Amount::Currency { .. }) => return Err(Bolt12SemanticError::UnsupportedCurrency),
};

builder = match offer.supported_quantity() {
Expand Down
6 changes: 3 additions & 3 deletions fuzz/src/refund_deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use lightning::blinded_path::BlindedPath;
use lightning::sign::EntropySource;
use lightning::ln::PaymentHash;
use lightning::ln::features::BlindedHopFeatures;
use lightning::offers::invoice::{BlindedPayInfo, UnsignedInvoice};
use lightning::offers::parse::SemanticError;
use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
use lightning::offers::parse::Bolt12SemanticError;
use lightning::offers::refund::Refund;
use lightning::util::ser::Writeable;

Expand Down Expand Up @@ -60,7 +60,7 @@ fn privkey(byte: u8) -> SecretKey {

fn build_response<'a, T: secp256k1::Signing + secp256k1::Verification>(
refund: &'a Refund, signing_pubkey: PublicKey, secp_ctx: &Secp256k1<T>
) -> Result<UnsignedInvoice<'a>, SemanticError> {
) -> Result<UnsignedBolt12Invoice<'a>, Bolt12SemanticError> {
let entropy_source = Randomness {};
let paths = vec![
BlindedPath::new_for_message(&[pubkey(43), pubkey(44), pubkey(42)], &entropy_source, secp_ctx).unwrap(),
Expand Down
Loading