use bitcoin::secp256k1::{KeyPair, Parity, PublicKey, Secp256k1, SecretKey, self};
use crate::utils::test_logger;
-use core::convert::{Infallible, TryFrom};
+use core::convert::TryFrom;
use lightning::blinded_path::BlindedPath;
use lightning::sign::EntropySource;
use lightning::ln::PaymentHash;
let even_pubkey = x_only_pubkey.public_key(Parity::Even);
if signing_pubkey == odd_pubkey || signing_pubkey == even_pubkey {
unsigned_invoice
- .sign(|message: &UnsignedBolt12Invoice| -> Result<_, Infallible> {
+ .sign(|message: &UnsignedBolt12Invoice|
Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
- })
+ )
.unwrap()
.write(&mut buffer)
.unwrap();
} else {
unsigned_invoice
- .sign(|message: &UnsignedBolt12Invoice| -> Result<_, Infallible> {
+ .sign(|message: &UnsignedBolt12Invoice|
Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
- })
+ )
.unwrap_err();
}
}
use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
use crate::utils::test_logger;
-use core::convert::{Infallible, TryFrom};
+use core::convert::TryFrom;
use lightning::offers::invoice_request::UnsignedInvoiceRequest;
use lightning::offers::offer::{Amount, Offer, Quantity};
use lightning::offers::parse::Bolt12SemanticError;
if let Ok(invoice_request) = build_response(&offer, pubkey) {
invoice_request
- .sign(|message: &UnsignedInvoiceRequest| -> Result<_, Infallible> {
+ .sign(|message: &UnsignedInvoiceRequest|
Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
- })
+ )
.unwrap()
.write(&mut buffer)
.unwrap();
use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey, self};
use crate::utils::test_logger;
-use core::convert::{Infallible, TryFrom};
+use core::convert::TryFrom;
use lightning::blinded_path::BlindedPath;
use lightning::sign::EntropySource;
use lightning::ln::PaymentHash;
if let Ok(invoice) = build_response(&refund, pubkey, &secp_ctx) {
invoice
- .sign(|message: &UnsignedBolt12Invoice| -> Result<_, Infallible> {
+ .sign(|message: &UnsignedBolt12Invoice|
Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
- })
+ )
.unwrap()
.write(&mut buffer)
.unwrap();
self.node_signer.sign_bolt12_invoice(invoice)
) {
Ok(invoice) => Ok(OffersMessage::Invoice(invoice)),
- Err(SignError::Signing(())) => Err(OffersMessage::InvoiceError(
+ Err(SignError::Signing) => Err(OffersMessage::InvoiceError(
InvoiceError::from_string("Failed signing invoice".to_string())
)),
Err(SignError::Verification(_)) => Err(OffersMessage::InvoiceError(
//!
//! use bitcoin::hashes::Hash;
//! use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
-//! use core::convert::{Infallible, TryFrom};
+//! use core::convert::TryFrom;
//! use lightning::offers::invoice::UnsignedBolt12Invoice;
//! use lightning::offers::invoice_request::InvoiceRequest;
//! use lightning::offers::refund::Refund;
//! .allow_mpp()
//! .fallback_v0_p2wpkh(&wpubkey_hash)
//! .build()?
-//! .sign(|message: &UnsignedBolt12Invoice| -> Result<_, Infallible> {
+//! .sign(|message: &UnsignedBolt12Invoice|
//! Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
-//! })
+//! )
//! .expect("failed verifying signature")
//! .write(&mut buffer)
//! .unwrap();
//! .allow_mpp()
//! .fallback_v0_p2wpkh(&wpubkey_hash)
//! .build()?
-//! .sign(|message: &UnsignedBolt12Invoice| -> Result<_, Infallible> {
+//! .sign(|message: &UnsignedBolt12Invoice|
//! Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
-//! })
+//! )
//! .expect("failed verifying signature")
//! .write(&mut buffer)
//! .unwrap();
use bitcoin::secp256k1::schnorr::Signature;
use bitcoin::address::{Address, Payload, WitnessProgram, WitnessVersion};
use bitcoin::key::TweakedPublicKey;
-use core::convert::{AsRef, Infallible, TryFrom};
+use core::convert::{AsRef, TryFrom};
use core::time::Duration;
use crate::io;
use crate::blinded_path::BlindedPath;
let mut unsigned_invoice = UnsignedBolt12Invoice::new(invreq_bytes, invoice.clone());
let invoice = unsigned_invoice
- .sign(|message: &UnsignedBolt12Invoice| -> Result<_, Infallible> {
+ .sign(|message: &UnsignedBolt12Invoice|
Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
- })
+ )
.unwrap();
Ok(invoice)
}
/// A function for signing an [`UnsignedBolt12Invoice`].
pub trait SignBolt12InvoiceFn {
- /// Error type returned by the function.
- type Error;
-
/// Signs a [`TaggedHash`] computed over the merkle root of `message`'s TLV stream.
- fn sign_invoice(&self, message: &UnsignedBolt12Invoice) -> Result<Signature, Self::Error>;
+ fn sign_invoice(&self, message: &UnsignedBolt12Invoice) -> Result<Signature, ()>;
}
-impl<F, E> SignBolt12InvoiceFn for F
+impl<F> SignBolt12InvoiceFn for F
where
- F: Fn(&UnsignedBolt12Invoice) -> Result<Signature, E>,
+ F: Fn(&UnsignedBolt12Invoice) -> Result<Signature, ()>,
{
- type Error = E;
-
- fn sign_invoice(&self, message: &UnsignedBolt12Invoice) -> Result<Signature, E> {
+ fn sign_invoice(&self, message: &UnsignedBolt12Invoice) -> Result<Signature, ()> {
self(message)
}
}
-impl<F, E> SignFn<UnsignedBolt12Invoice> for F
+impl<F> SignFn<UnsignedBolt12Invoice> for F
where
- F: SignBolt12InvoiceFn<Error = E>,
+ F: SignBolt12InvoiceFn,
{
- type Error = E;
-
- fn sign(&self, message: &UnsignedBolt12Invoice) -> Result<Signature, Self::Error> {
+ fn sign(&self, message: &UnsignedBolt12Invoice) -> Result<Signature, ()> {
self.sign_invoice(message)
}
}
/// Note: The hash computation may have included unknown, odd TLV records.
pub fn sign<F: SignBolt12InvoiceFn>(
$($self_mut)* $self: $self_type, sign: F
- ) -> Result<Bolt12Invoice, SignError<F::Error>> {
+ ) -> Result<Bolt12Invoice, SignError> {
let pubkey = $self.contents.fields().signing_pubkey;
let signature = merkle::sign_message(sign, &$self, pubkey)?;
.sign(fail_sign)
{
Ok(_) => panic!("expected error"),
- Err(e) => assert_eq!(e, SignError::Signing(())),
+ Err(e) => assert_eq!(e, SignError::Signing),
}
match OfferBuilder::new("foo".into(), recipient_pubkey())
//!
//! use bitcoin::network::constants::Network;
//! use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
-//! use core::convert::Infallible;
//! use lightning::ln::features::OfferFeatures;
//! use lightning::offers::invoice_request::UnsignedInvoiceRequest;
//! use lightning::offers::offer::Offer;
//! .quantity(5)?
//! .payer_note("foo".to_string())
//! .build()?
-//! .sign(|message: &UnsignedInvoiceRequest| -> Result<_, Infallible> {
+//! .sign(|message: &UnsignedInvoiceRequest|
//! Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
-//! })
+//! )
//! .expect("failed verifying signature")
//! .write(&mut buffer)
//! .unwrap();
use bitcoin::network::constants::Network;
use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, self};
use bitcoin::secp256k1::schnorr::Signature;
-use core::convert::{AsRef, Infallible, TryFrom};
+use core::convert::{AsRef, TryFrom};
use core::ops::Deref;
use crate::sign::EntropySource;
use crate::io;
let secp_ctx = secp_ctx.unwrap();
let keys = keys.unwrap();
let invoice_request = unsigned_invoice_request
- .sign(|message: &UnsignedInvoiceRequest| -> Result<_, Infallible> {
+ .sign(|message: &UnsignedInvoiceRequest|
Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
- })
+ )
.unwrap();
Ok(invoice_request)
}
/// A function for signing an [`UnsignedInvoiceRequest`].
pub trait SignInvoiceRequestFn {
- /// Error type returned by the function.
- type Error;
-
/// Signs a [`TaggedHash`] computed over the merkle root of `message`'s TLV stream.
- fn sign_invoice_request(&self, message: &UnsignedInvoiceRequest) -> Result<Signature, Self::Error>;
+ fn sign_invoice_request(&self, message: &UnsignedInvoiceRequest) -> Result<Signature, ()>;
}
-impl<F, E> SignInvoiceRequestFn for F
+impl<F> SignInvoiceRequestFn for F
where
- F: Fn(&UnsignedInvoiceRequest) -> Result<Signature, E>,
+ F: Fn(&UnsignedInvoiceRequest) -> Result<Signature, ()>,
{
- type Error = E;
-
- fn sign_invoice_request(&self, message: &UnsignedInvoiceRequest) -> Result<Signature, E> {
+ fn sign_invoice_request(&self, message: &UnsignedInvoiceRequest) -> Result<Signature, ()> {
self(message)
}
}
-impl<F, E> SignFn<UnsignedInvoiceRequest> for F
+impl<F> SignFn<UnsignedInvoiceRequest> for F
where
- F: SignInvoiceRequestFn<Error = E>,
+ F: SignInvoiceRequestFn,
{
- type Error = E;
-
- fn sign(&self, message: &UnsignedInvoiceRequest) -> Result<Signature, Self::Error> {
+ fn sign(&self, message: &UnsignedInvoiceRequest) -> Result<Signature, ()> {
self.sign_invoice_request(message)
}
}
/// Note: The hash computation may have included unknown, odd TLV records.
pub fn sign<F: SignInvoiceRequestFn>(
$($self_mut)* $self: $self_type, sign: F
- ) -> Result<InvoiceRequest, SignError<F::Error>> {
+ ) -> Result<InvoiceRequest, SignError> {
let pubkey = $self.contents.payer_id;
let signature = merkle::sign_message(sign, &$self, pubkey)?;
use bitcoin::blockdata::constants::ChainHash;
use bitcoin::network::constants::Network;
use bitcoin::secp256k1::{KeyPair, Secp256k1, SecretKey, self};
- use core::convert::{Infallible, TryFrom};
+ use core::convert::TryFrom;
use core::num::NonZeroU64;
#[cfg(feature = "std")]
use core::time::Duration;
.sign(fail_sign)
{
Ok(_) => panic!("expected error"),
- Err(e) => assert_eq!(e, SignError::Signing(())),
+ Err(e) => assert_eq!(e, SignError::Signing),
}
match OfferBuilder::new("foo".into(), recipient_pubkey())
.build().unwrap()
.request_invoice(vec![1; 32], keys.public_key()).unwrap()
.build().unwrap()
- .sign(|message: &UnsignedInvoiceRequest| -> Result<_, Infallible> {
+ .sign(|message: &UnsignedInvoiceRequest|
Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
- })
+ )
.unwrap();
let mut encoded_invoice_request = Vec::new();
/// Error when signing messages.
#[derive(Debug, PartialEq)]
-pub enum SignError<E = ()> {
+pub enum SignError {
/// User-defined error when signing the message.
- Signing(E),
+ Signing,
/// Error when verifying the produced signature using the given pubkey.
Verification(secp256k1::Error),
}
/// A function for signing a [`TaggedHash`].
pub(super) trait SignFn<T: AsRef<TaggedHash>> {
- /// Error type returned by the function.
- type Error;
-
/// Signs a [`TaggedHash`] computed over the merkle root of `message`'s TLV stream.
- fn sign(&self, message: &T) -> Result<Signature, Self::Error>;
+ fn sign(&self, message: &T) -> Result<Signature, ()>;
}
-impl<F, E> SignFn<TaggedHash> for F
+impl<F> SignFn<TaggedHash> for F
where
- F: Fn(&TaggedHash) -> Result<Signature, E>,
+ F: Fn(&TaggedHash) -> Result<Signature, ()>,
{
- type Error = E;
-
- fn sign(&self, message: &TaggedHash) -> Result<Signature, E> {
+ fn sign(&self, message: &TaggedHash) -> Result<Signature, ()> {
self(message)
}
}
///
/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
-pub(super) fn sign_message<F, T, E>(
+pub(super) fn sign_message<F, T>(
f: F, message: &T, pubkey: PublicKey,
-) -> Result<Signature, SignError<E>>
+) -> Result<Signature, SignError>
where
- F: SignFn<T, Error = E>,
+ F: SignFn<T>,
T: AsRef<TaggedHash>,
{
- let signature = f.sign(message).map_err(|e| SignError::Signing(e))?;
+ let signature = f.sign(message).map_err(|()| SignError::Signing)?;
let digest = message.as_ref().as_digest();
let pubkey = pubkey.into();
use bitcoin::hashes::hex::FromHex;
use bitcoin::secp256k1::{KeyPair, Message, Secp256k1, SecretKey};
use bitcoin::secp256k1::schnorr::Signature;
- use core::convert::Infallible;
use crate::offers::offer::{Amount, OfferBuilder};
use crate::offers::invoice_request::{InvoiceRequest, UnsignedInvoiceRequest};
use crate::offers::parse::Bech32Encode;
.build_unchecked()
.request_invoice(vec![0; 8], payer_keys.public_key()).unwrap()
.build_unchecked()
- .sign(|message: &UnsignedInvoiceRequest| -> Result<_, Infallible> {
+ .sign(|message: &UnsignedInvoiceRequest|
Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &payer_keys))
- })
+ )
.unwrap();
assert_eq!(
invoice_request.to_string(),
.build_unchecked()
.request_invoice(vec![0; 8], payer_keys.public_key()).unwrap()
.build_unchecked()
- .sign(|message: &UnsignedInvoiceRequest| -> Result<_, Infallible> {
+ .sign(|message: &UnsignedInvoiceRequest|
Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &payer_keys))
- })
+ )
.unwrap();
let mut bytes_without_signature = Vec::new();
.build_unchecked()
.request_invoice(vec![0; 8], payer_keys.public_key()).unwrap()
.build_unchecked()
- .sign(|message: &UnsignedInvoiceRequest| -> Result<_, Infallible> {
+ .sign(|message: &UnsignedInvoiceRequest|
Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &payer_keys))
- })
+ )
.unwrap();
let tlv_stream = TlvStream::new(&invoice_request.bytes).range(0..1)
use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
use bitcoin::secp256k1::schnorr::Signature;
-use core::convert::{AsRef, Infallible};
+use core::convert::AsRef;
use core::time::Duration;
use crate::blinded_path::{BlindedHop, BlindedPath};
use crate::sign::EntropySource;
KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap())
}
-pub(crate) fn payer_sign<T: AsRef<TaggedHash>>(message: &T) -> Result<Signature, Infallible> {
+pub(crate) fn payer_sign<T: AsRef<TaggedHash>>(message: &T) -> Result<Signature, ()> {
let secp_ctx = Secp256k1::new();
let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))
KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[43; 32]).unwrap())
}
-pub(crate) fn recipient_sign<T: AsRef<TaggedHash>>(message: &T) -> Result<Signature, Infallible> {
+pub(crate) fn recipient_sign<T: AsRef<TaggedHash>>(message: &T) -> Result<Signature, ()> {
let secp_ctx = Secp256k1::new();
let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[43; 32]).unwrap());
Ok(secp_ctx.sign_schnorr_no_aux_rand(message.as_ref().as_digest(), &keys))