projects
/
rust-lightning
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #1476 from tnull/2022-05-maximum-path-length
[rust-lightning]
/
lightning-invoice
/
src
/
lib.rs
diff --git
a/lightning-invoice/src/lib.rs
b/lightning-invoice/src/lib.rs
index 5784607dde937b85fa384ed65a630d7af1d3ca3a..9fcb4af1b624257b6818d1c121c4dd9f7c6c6eaa 100644
(file)
--- a/
lightning-invoice/src/lib.rs
+++ b/
lightning-invoice/src/lib.rs
@@
-25,6
+25,8
@@
compile_error!("at least one of the `std` or `no-std` features must be enabled")
pub mod payment;
pub mod utils;
pub mod payment;
pub mod utils;
+pub(crate) mod time_utils;
+
extern crate bech32;
extern crate bitcoin_hashes;
#[macro_use] extern crate lightning;
extern crate bech32;
extern crate bitcoin_hashes;
#[macro_use] extern crate lightning;
@@
-47,9
+49,9
@@
use lightning::routing::network_graph::RoutingFees;
use lightning::routing::router::RouteHint;
use lightning::util::invoice::construct_invoice_preimage;
use lightning::routing::router::RouteHint;
use lightning::util::invoice::construct_invoice_preimage;
-use secp256k1::
key::
PublicKey;
+use secp256k1::PublicKey;
use secp256k1::{Message, Secp256k1};
use secp256k1::{Message, Secp256k1};
-use secp256k1::
recovery
::RecoverableSignature;
+use secp256k1::
ecdsa
::RecoverableSignature;
use core::fmt::{Display, Formatter, self};
use core::iter::FilterMap;
use core::fmt::{Display, Formatter, self};
use core::iter::FilterMap;
@@
-163,7
+165,7
@@
pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = 18;
/// use bitcoin_hashes::sha256;
///
/// use secp256k1::Secp256k1;
/// use bitcoin_hashes::sha256;
///
/// use secp256k1::Secp256k1;
-/// use secp256k1::
key::
SecretKey;
+/// use secp256k1::SecretKey;
///
/// use lightning::ln::PaymentSecret;
///
///
/// use lightning::ln::PaymentSecret;
///
@@
-191,7
+193,7
@@
pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = 18;
/// .current_timestamp()
/// .min_final_cltv_expiry(144)
/// .build_signed(|hash| {
/// .current_timestamp()
/// .min_final_cltv_expiry(144)
/// .build_signed(|hash| {
-/// Secp256k1::new().sign_recoverable(hash, &private_key)
+/// Secp256k1::new().sign_
ecdsa_
recoverable(hash, &private_key)
/// })
/// .unwrap();
///
/// })
/// .unwrap();
///
@@
-749,7
+751,7
@@
impl SignedRawInvoice {
let hash = Message::from_slice(&self.hash[..])
.expect("Hash is 32 bytes long, same as MESSAGE_SIZE");
let hash = Message::from_slice(&self.hash[..])
.expect("Hash is 32 bytes long, same as MESSAGE_SIZE");
- Ok(PayeePubKey(Secp256k1::new().recover(
+ Ok(PayeePubKey(Secp256k1::new().recover
_ecdsa
(
&hash,
&self.signature
)?))
&hash,
&self.signature
)?))
@@
-776,7
+778,7
@@
impl SignedRawInvoice {
.expect("Hash is 32 bytes long, same as MESSAGE_SIZE");
let secp_context = Secp256k1::new();
.expect("Hash is 32 bytes long, same as MESSAGE_SIZE");
let secp_context = Secp256k1::new();
- let verification_result = secp_context.verify(
+ let verification_result = secp_context.verify
_ecdsa
(
&hash,
&self.signature.to_standard(),
pub_key
&hash,
&self.signature.to_standard(),
pub_key
@@
-1576,8
+1578,8
@@
mod test {
fn test_check_signature() {
use TaggedField::*;
use secp256k1::Secp256k1;
fn test_check_signature() {
use TaggedField::*;
use secp256k1::Secp256k1;
- use secp256k1::
recovery
::{RecoveryId, RecoverableSignature};
- use secp256k1::
key::
{SecretKey, PublicKey};
+ use secp256k1::
ecdsa
::{RecoveryId, RecoverableSignature};
+ use secp256k1::{SecretKey, PublicKey};
use {SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
PositiveTimestamp};
use {SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
PositiveTimestamp};
@@
-1635,7
+1637,7
@@
mod test {
let (raw_invoice, _, _) = invoice.into_parts();
let new_signed = raw_invoice.sign::<_, ()>(|hash| {
let (raw_invoice, _, _) = invoice.into_parts();
let new_signed = raw_invoice.sign::<_, ()>(|hash| {
- Ok(Secp256k1::new().sign_recoverable(hash, &private_key))
+ Ok(Secp256k1::new().sign_
ecdsa_
recoverable(hash, &private_key))
}).unwrap();
assert!(new_signed.check_signature());
}).unwrap();
assert!(new_signed.check_signature());
@@
-1646,7
+1648,7
@@
mod test {
use TaggedField::*;
use lightning::ln::features::InvoiceFeatures;
use secp256k1::Secp256k1;
use TaggedField::*;
use lightning::ln::features::InvoiceFeatures;
use secp256k1::Secp256k1;
- use secp256k1::
key::
SecretKey;
+ use secp256k1::SecretKey;
use {RawInvoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp, Invoice,
SemanticError};
use {RawInvoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp, Invoice,
SemanticError};
@@
-1677,7
+1679,7
@@
mod test {
let invoice = {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
let invoice = {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
- invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_recoverable(hash, &private_key)))
+ invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_
ecdsa_
recoverable(hash, &private_key)))
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::InvalidFeatures));
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::InvalidFeatures));
@@
-1686,7
+1688,7
@@
mod test {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
invoice.data.tagged_fields.push(Features(InvoiceFeatures::empty()).into());
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
invoice.data.tagged_fields.push(Features(InvoiceFeatures::empty()).into());
- invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_recoverable(hash, &private_key)))
+ invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_
ecdsa_
recoverable(hash, &private_key)))
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::InvalidFeatures));
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::InvalidFeatures));
@@
-1695,14
+1697,14
@@
mod test {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
invoice.data.tagged_fields.push(Features(InvoiceFeatures::known()).into());
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
invoice.data.tagged_fields.push(Features(InvoiceFeatures::known()).into());
- invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_recoverable(hash, &private_key)))
+ invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_
ecdsa_
recoverable(hash, &private_key)))
}.unwrap();
assert!(Invoice::from_signed(invoice).is_ok());
// No payment secret or features
let invoice = {
let invoice = invoice_template.clone();
}.unwrap();
assert!(Invoice::from_signed(invoice).is_ok());
// No payment secret or features
let invoice = {
let invoice = invoice_template.clone();
- invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_recoverable(hash, &private_key)))
+ invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_
ecdsa_
recoverable(hash, &private_key)))
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
@@
-1710,7
+1712,7
@@
mod test {
let invoice = {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(Features(InvoiceFeatures::empty()).into());
let invoice = {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(Features(InvoiceFeatures::empty()).into());
- invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_recoverable(hash, &private_key)))
+ invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_
ecdsa_
recoverable(hash, &private_key)))
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
@@
-1718,7
+1720,7
@@
mod test {
let invoice = {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(Features(InvoiceFeatures::known()).into());
let invoice = {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(Features(InvoiceFeatures::known()).into());
- invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_recoverable(hash, &private_key)))
+ invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_
ecdsa_
recoverable(hash, &private_key)))
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
@@
-1727,7
+1729,7
@@
mod test {
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
let mut invoice = invoice_template.clone();
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
- invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_recoverable(hash, &private_key)))
+ invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_
ecdsa_
recoverable(hash, &private_key)))
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::MultiplePaymentSecrets));
}
}.unwrap();
assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::MultiplePaymentSecrets));
}
@@
-1764,7
+1766,7
@@
mod test {
use ::*;
use lightning::routing::router::RouteHintHop;
use std::iter::FromIterator;
use ::*;
use lightning::routing::router::RouteHintHop;
use std::iter::FromIterator;
- use secp256k1::
key::
PublicKey;
+ use secp256k1::PublicKey;
let builder = InvoiceBuilder::new(Currency::Bitcoin)
.payment_hash(sha256::Hash::from_slice(&[0;32][..]).unwrap())
let builder = InvoiceBuilder::new(Currency::Bitcoin)
.payment_hash(sha256::Hash::from_slice(&[0;32][..]).unwrap())
@@
-1818,7
+1820,7
@@
mod test {
use ::*;
use lightning::routing::router::RouteHintHop;
use secp256k1::Secp256k1;
use ::*;
use lightning::routing::router::RouteHintHop;
use secp256k1::Secp256k1;
- use secp256k1::
key::
{SecretKey, PublicKey};
+ use secp256k1::{SecretKey, PublicKey};
use std::time::{UNIX_EPOCH, Duration};
let secp_ctx = Secp256k1::new();
use std::time::{UNIX_EPOCH, Duration};
let secp_ctx = Secp256k1::new();
@@
-1897,7
+1899,7
@@
mod test {
.basic_mpp();
let invoice = builder.clone().build_signed(|hash| {
.basic_mpp();
let invoice = builder.clone().build_signed(|hash| {
- secp_ctx.sign_recoverable(hash, &private_key)
+ secp_ctx.sign_
ecdsa_
recoverable(hash, &private_key)
}).unwrap();
assert!(invoice.check_signature().is_ok());
}).unwrap();
assert!(invoice.check_signature().is_ok());
@@
-1932,7
+1934,7
@@
mod test {
fn test_default_values() {
use ::*;
use secp256k1::Secp256k1;
fn test_default_values() {
use ::*;
use secp256k1::Secp256k1;
- use secp256k1::
key::
SecretKey;
+ use secp256k1::SecretKey;
let signed_invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("Test".into())
let signed_invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("Test".into())
@@
-1944,7
+1946,7
@@
mod test {
.sign::<_, ()>(|hash| {
let privkey = SecretKey::from_slice(&[41; 32]).unwrap();
let secp_ctx = Secp256k1::new();
.sign::<_, ()>(|hash| {
let privkey = SecretKey::from_slice(&[41; 32]).unwrap();
let secp_ctx = Secp256k1::new();
- Ok(secp_ctx.sign_recoverable(hash, &privkey))
+ Ok(secp_ctx.sign_
ecdsa_
recoverable(hash, &privkey))
})
.unwrap();
let invoice = Invoice::from_signed(signed_invoice).unwrap();
})
.unwrap();
let invoice = Invoice::from_signed(signed_invoice).unwrap();
@@
-1958,7
+1960,7
@@
mod test {
fn test_expiration() {
use ::*;
use secp256k1::Secp256k1;
fn test_expiration() {
use ::*;
use secp256k1::Secp256k1;
- use secp256k1::
key::
SecretKey;
+ use secp256k1::SecretKey;
let signed_invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("Test".into())
let signed_invoice = InvoiceBuilder::new(Currency::Bitcoin)
.description("Test".into())
@@
-1970,7
+1972,7
@@
mod test {
.sign::<_, ()>(|hash| {
let privkey = SecretKey::from_slice(&[41; 32]).unwrap();
let secp_ctx = Secp256k1::new();
.sign::<_, ()>(|hash| {
let privkey = SecretKey::from_slice(&[41; 32]).unwrap();
let secp_ctx = Secp256k1::new();
- Ok(secp_ctx.sign_recoverable(hash, &privkey))
+ Ok(secp_ctx.sign_
ecdsa_
recoverable(hash, &privkey))
})
.unwrap();
let invoice = Invoice::from_signed(signed_invoice).unwrap();
})
.unwrap();
let invoice = Invoice::from_signed(signed_invoice).unwrap();