use lightning::util::ser::{Readable, ReadableArgs, Writeable, Writer};
use lightning::util::test_channel_signer::{EnforcementState, TestChannelSigner};
+use lightning_invoice::RawBolt11Invoice;
+
use crate::utils::test_logger::{self, Output};
use crate::utils::test_persister::TestPersister;
use bitcoin::secp256k1::schnorr;
use bitcoin::secp256k1::{self, Message, PublicKey, Scalar, Secp256k1, SecretKey};
-use bech32::u5;
use std::cmp::{self, Ordering};
use std::io::Cursor;
use std::mem;
}
fn sign_invoice(
- &self, _hrp_bytes: &[u8], _invoice_data: &[u5], _recipient: Recipient,
+ &self, _invoice: &RawBolt11Invoice, _recipient: Recipient,
) -> Result<RecoverableSignature, ()> {
unreachable!()
}
use lightning::util::ser::{Readable, ReadableArgs, Writeable};
use lightning::util::test_channel_signer::{EnforcementState, TestChannelSigner};
+use lightning_invoice::RawBolt11Invoice;
+
use crate::utils::test_logger;
use crate::utils::test_persister::TestPersister;
use bitcoin::secp256k1::schnorr;
use bitcoin::secp256k1::{self, Message, PublicKey, Scalar, Secp256k1, SecretKey};
-use bech32::u5;
use std::cell::RefCell;
use std::cmp;
use std::convert::TryInto;
}
fn sign_invoice(
- &self, _hrp_bytes: &[u8], _invoice_data: &[u5], _recipient: Recipient,
+ &self, _invoice: &RawBolt11Invoice, _recipient: Recipient,
) -> Result<RecoverableSignature, ()> {
unreachable!()
}
// Imports that need to be added manually
-use bech32::u5;
use bitcoin::script::ScriptBuf;
use bitcoin::secp256k1::ecdh::SharedSecret;
use bitcoin::secp256k1::ecdsa::RecoverableSignature;
use lightning::util::ser::{Readable, Writeable, Writer};
use lightning::util::test_channel_signer::TestChannelSigner;
+use lightning_invoice::RawBolt11Invoice;
+
use crate::utils::test_logger;
use std::io::{self, Cursor};
}
fn sign_invoice(
- &self, _hrp_bytes: &[u8], _invoice_data: &[u5], _recipient: Recipient,
+ &self, _invoice: &RawBolt11Invoice, _recipient: Recipient,
) -> Result<RecoverableSignature, ()> {
unreachable!()
}
use crate::prelude::*;
-use bech32::ToBase32;
use bitcoin::hashes::Hash;
use crate::chain;
use crate::chain::chaininterface::{BroadcasterInterface, FeeEstimator};
Ok(inv) => inv,
Err(e) => return Err(SignOrCreationError::CreationError(e))
};
- let hrp_str = raw_invoice.hrp.to_string();
- let hrp_bytes = hrp_str.as_bytes();
- let data_without_signature = raw_invoice.data.to_base32();
- let signed_raw_invoice = raw_invoice.sign(|_| node_signer.sign_invoice(hrp_bytes, &data_without_signature, Recipient::PhantomNode));
+ let signature = node_signer.sign_invoice(&raw_invoice, Recipient::PhantomNode);
+ let signed_raw_invoice = raw_invoice.sign(|_| signature);
match signed_raw_invoice {
Ok(inv) => Ok(Bolt11Invoice::from_signed(inv).unwrap()),
Err(e) => Err(SignOrCreationError::SignError(e))
Ok(inv) => inv,
Err(e) => return Err(SignOrCreationError::CreationError(e))
};
- let hrp_str = raw_invoice.hrp.to_string();
- let hrp_bytes = hrp_str.as_bytes();
- let data_without_signature = raw_invoice.data.to_base32();
- let signed_raw_invoice = raw_invoice.sign(|_| node_signer.sign_invoice(hrp_bytes, &data_without_signature, Recipient::Node));
+ let signature = node_signer.sign_invoice(&raw_invoice, Recipient::Node);
+ let signed_raw_invoice = raw_invoice.sign(|_| signature);
match signed_raw_invoice {
Ok(inv) => Ok(Bolt11Invoice::from_signed(inv).unwrap()),
Err(e) => Err(SignOrCreationError::SignError(e))
use bitcoin::transaction::Version;
use bitcoin::transaction::{Transaction, TxIn, TxOut};
-use bech32::u5;
use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::hashes::sha256d::Hash as Sha256dHash;
use bitcoin::hashes::{Hash, HashEngine};
use bitcoin::secp256k1::{Keypair, PublicKey, Scalar, Secp256k1, SecretKey, Signing};
use bitcoin::{secp256k1, Psbt, Sequence, Txid, WPubkeyHash, Witness};
+use lightning_invoice::RawBolt11Invoice;
+
use crate::chain::transaction::OutPoint;
use crate::crypto::utils::{hkdf_extract_expand_twice, sign, sign_with_aux_rand};
use crate::ln::chan_utils;
#[cfg(taproot)]
use crate::sign::taproot::TaprootChannelSigner;
use crate::util::atomic_counter::AtomicCounter;
-use crate::util::invoice::construct_invoice_preimage;
use core::convert::TryInto;
use core::ops::Deref;
use core::sync::atomic::{AtomicUsize, Ordering};
///
/// Errors if the [`Recipient`] variant is not supported by the implementation.
fn sign_invoice(
- &self, hrp_bytes: &[u8], invoice_data: &[u5], recipient: Recipient,
+ &self, invoice: &RawBolt11Invoice, recipient: Recipient,
) -> Result<RecoverableSignature, ()>;
/// Signs the [`TaggedHash`] of a BOLT 12 invoice request.
}
fn sign_invoice(
- &self, hrp_bytes: &[u8], invoice_data: &[u5], recipient: Recipient,
+ &self, invoice: &RawBolt11Invoice, recipient: Recipient,
) -> Result<RecoverableSignature, ()> {
- let preimage = construct_invoice_preimage(&hrp_bytes, &invoice_data);
+ let hash = invoice.signable_hash();
let secret = match recipient {
Recipient::Node => Ok(&self.node_secret),
Recipient::PhantomNode => Err(()),
}?;
- Ok(self.secp_ctx.sign_ecdsa_recoverable(
- &hash_to_message!(&Sha256::hash(&preimage).to_byte_array()),
- secret,
- ))
+ Ok(self.secp_ctx.sign_ecdsa_recoverable(&hash_to_message!(&hash), secret))
}
fn sign_bolt12_invoice_request(
}
fn sign_invoice(
- &self, hrp_bytes: &[u8], invoice_data: &[u5], recipient: Recipient,
+ &self, invoice: &RawBolt11Invoice, recipient: Recipient,
) -> Result<RecoverableSignature, ()> {
- let preimage = construct_invoice_preimage(&hrp_bytes, &invoice_data);
+ let hash = invoice.signable_hash();
let secret = match recipient {
Recipient::Node => &self.inner.node_secret,
Recipient::PhantomNode => &self.phantom_secret,
};
- Ok(self.inner.secp_ctx.sign_ecdsa_recoverable(
- &hash_to_message!(&Sha256::hash(&preimage).to_byte_array()),
- secret,
- ))
+ Ok(self.inner.secp_ctx.sign_ecdsa_recoverable(&hash_to_message!(&hash), secret))
}
fn sign_bolt12_invoice_request(
+++ /dev/null
-//! Low level invoice utilities.
-
-use bech32::{u5, FromBase32};
-
-#[allow(unused)]
-use crate::prelude::*;
-
-/// Construct the invoice's HRP and signatureless data into a preimage to be hashed.
-pub fn construct_invoice_preimage(hrp_bytes: &[u8], data_without_signature: &[u5]) -> Vec<u8> {
- let mut preimage = Vec::<u8>::from(hrp_bytes);
-
- let mut data_part = Vec::from(data_without_signature);
- let overhang = (data_part.len() * 5) % 8;
- if overhang > 0 {
- // add padding if data does not end at a byte boundary
- data_part.push(u5::try_from_u8(0).unwrap());
-
- // if overhang is in (1..3) we need to add u5(0) padding two times
- if overhang < 3 {
- data_part.push(u5::try_from_u8(0).unwrap());
- }
- }
-
- preimage.extend_from_slice(&Vec::<u8>::from_base32(&data_part)
- .expect("No padding error may occur due to appended zero above."));
- preimage
-}
-
pub mod errors;
pub mod ser;
pub mod message_signing;
-pub mod invoice;
pub mod persist;
pub mod scid_utils;
pub mod sweep;
use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature};
use bitcoin::secp256k1::schnorr;
+use lightning_invoice::RawBolt11Invoice;
+
use crate::io;
use crate::prelude::*;
use core::cell::RefCell;
use crate::sync::{Mutex, Arc};
use core::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use core::mem;
-use bech32::u5;
use crate::sign::{InMemorySigner, RandomBytes, Recipient, EntropySource, NodeSigner, SignerProvider};
#[cfg(feature = "std")]
Ok(SharedSecret::new(other_key, &node_secret))
}
- fn sign_invoice(&self, _: &[u8], _: &[bech32::u5], _: Recipient) -> Result<bitcoin::secp256k1::ecdsa::RecoverableSignature, ()> {
+ fn sign_invoice(&self, _: &RawBolt11Invoice, _: Recipient) -> Result<RecoverableSignature, ()> {
unreachable!()
}
self.backing.get_inbound_payment_key_material()
}
- fn sign_invoice(&self, hrp_bytes: &[u8], invoice_data: &[u5], recipient: Recipient) -> Result<RecoverableSignature, ()> {
- self.backing.sign_invoice(hrp_bytes, invoice_data, recipient)
+ fn sign_invoice(&self, invoice: &RawBolt11Invoice, recipient: Recipient) -> Result<RecoverableSignature, ()> {
+ self.backing.sign_invoice(invoice, recipient)
}
fn sign_bolt12_invoice_request(