]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Remove secp256k1 dependency.
authorArik Sosman <git@arik.io>
Wed, 14 Aug 2024 20:07:24 +0000 (13:07 -0700)
committerArik Sosman <git@arik.io>
Fri, 16 Aug 2024 17:31:45 +0000 (10:31 -0700)
lightning-invoice/Cargo.toml
lightning-invoice/src/de.rs
lightning-invoice/src/lib.rs
lightning-invoice/src/ser.rs
lightning-invoice/tests/ser_de.rs

index 59f411409cbdfffd2d415c89bd52b9bd42834be0..f03875d67cd76e91ed4bd0e07761e8eea58ce179 100644 (file)
@@ -22,9 +22,8 @@ std = ["bech32/std"]
 [dependencies]
 bech32 = { version = "0.9.1", default-features = false }
 lightning-types = { version = "0.1", path = "../lightning-types", default-features = false }
-secp256k1 = { version = "0.29.0", default-features = false, features = ["recovery", "alloc"] }
 serde = { version = "1.0.118", optional = true }
-bitcoin = { version = "0.32.2", default-features = false }
+bitcoin = { version = "0.32.2", default-features = false, features = ["secp-recovery"] }
 
 [dev-dependencies]
 serde_json = { version = "1"}
index be1a21aa25f73b613fd01c401bce804da324a790..e5ba67cccf9ffc2cd2f2ccd4560d5a06417adcd9 100644 (file)
@@ -17,8 +17,8 @@ use crate::prelude::*;
 use lightning_types::payment::PaymentSecret;
 use lightning_types::routing::{RoutingFees, RouteHint, RouteHintHop};
 
-use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
-use secp256k1::PublicKey;
+use bitcoin::secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
+use bitcoin::secp256k1::PublicKey;
 
 use super::{Bolt11Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiryDelta, Fallback, PayeePubKey, Bolt11InvoiceSignature, PositiveTimestamp,
        Bolt11SemanticError, PrivateRoute, Bolt11ParseError, ParseOrSemanticError, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawBolt11Invoice,
@@ -698,7 +698,7 @@ macro_rules! from_error {
     }
 }
 
-from_error!(Bolt11ParseError::MalformedSignature, secp256k1::Error);
+from_error!(Bolt11ParseError::MalformedSignature, bitcoin::secp256k1::Error);
 from_error!(Bolt11ParseError::ParseAmountError, ParseIntError);
 from_error!(Bolt11ParseError::DescriptionDecodeError, str::Utf8Error);
 
@@ -726,7 +726,7 @@ impl From<crate::Bolt11SemanticError> for ParseOrSemanticError {
 #[cfg(test)]
 mod test {
        use crate::de::Bolt11ParseError;
-       use secp256k1::PublicKey;
+       use bitcoin::secp256k1::PublicKey;
        use bech32::u5;
        use bitcoin::hashes::sha256;
        use std::str::FromStr;
@@ -973,7 +973,7 @@ mod test {
        #[test]
        fn test_payment_secret_and_features_de_and_ser() {
                use lightning_types::features::Bolt11InvoiceFeatures;
-               use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
+               use bitcoin::secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
                use crate::TaggedField::*;
                use crate::{SiPrefix, SignedRawBolt11Invoice, Bolt11InvoiceSignature, RawBolt11Invoice, RawHrp, RawDataPart,
                                 Currency, Sha256, PositiveTimestamp};
@@ -1020,7 +1020,7 @@ mod test {
        #[test]
        fn test_raw_signed_invoice_deserialization() {
                use crate::TaggedField::*;
-               use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
+               use bitcoin::secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
                use crate::{SignedRawBolt11Invoice, Bolt11InvoiceSignature, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256,
                         PositiveTimestamp};
 
index fea0b6850da3c616c0bf08f21eeecb4968627b48..bbb8dc8d5dac8e8ecc73940110caff10a9cf361b 100644 (file)
@@ -27,7 +27,6 @@ compile_error!("at least one of the `std` or `no-std` features must be enabled")
 
 extern crate bech32;
 extern crate lightning_types;
-extern crate secp256k1;
 extern crate alloc;
 #[cfg(any(test, feature = "std"))]
 extern crate core;
@@ -42,9 +41,9 @@ use bitcoin::{Address, Network, PubkeyHash, ScriptHash, WitnessProgram, WitnessV
 use bitcoin::hashes::{Hash, sha256};
 use lightning_types::features::Bolt11InvoiceFeatures;
 
-use secp256k1::PublicKey;
-use secp256k1::{Message, Secp256k1};
-use secp256k1::ecdsa::RecoverableSignature;
+use bitcoin::secp256k1::PublicKey;
+use bitcoin::secp256k1::{Message, Secp256k1};
+use bitcoin::secp256k1::ecdsa::RecoverableSignature;
 
 use core::cmp::Ordering;
 use core::fmt::{Display, Formatter, self};
@@ -84,7 +83,7 @@ use crate::prelude::*;
 pub enum Bolt11ParseError {
        Bech32Error(bech32::Error),
        ParseAmountError(ParseIntError),
-       MalformedSignature(secp256k1::Error),
+       MalformedSignature(bitcoin::secp256k1::Error),
        BadPrefix,
        UnknownCurrency,
        UnknownSiPrefix,
@@ -141,15 +140,14 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;
 /// ensures that only a semantically and syntactically correct invoice can be built using it.
 ///
 /// ```
-/// extern crate secp256k1;
 /// extern crate lightning_invoice;
 /// extern crate bitcoin;
 ///
 /// use bitcoin::hashes::Hash;
 /// use bitcoin::hashes::sha256;
 ///
-/// use secp256k1::Secp256k1;
-/// use secp256k1::SecretKey;
+/// use bitcoin::secp256k1::Secp256k1;
+/// use bitcoin::secp256k1::SecretKey;
 ///
 /// use lightning_types::payment::PaymentSecret;
 ///
@@ -866,7 +864,7 @@ impl SignedRawBolt11Invoice {
        }
 
        /// Recovers the public key used for signing the invoice from the recoverable signature.
-       pub fn recover_payee_pub_key(&self) -> Result<PayeePubKey, secp256k1::Error> {
+       pub fn recover_payee_pub_key(&self) -> Result<PayeePubKey, bitcoin::secp256k1::Error> {
                let hash = Message::from_digest(self.hash);
 
                Ok(PayeePubKey(Secp256k1::new().recover_ecdsa(
@@ -1248,9 +1246,9 @@ impl Bolt11Invoice {
        /// Check that the invoice is signed correctly and that key recovery works
        pub fn check_signature(&self) -> Result<(), Bolt11SemanticError> {
                match self.signed_invoice.recover_payee_pub_key() {
-                       Err(secp256k1::Error::InvalidRecoveryId) =>
+                       Err(bitcoin::secp256k1::Error::InvalidRecoveryId) =>
                                return Err(Bolt11SemanticError::InvalidRecoveryId),
-                       Err(secp256k1::Error::InvalidSignature) =>
+                       Err(bitcoin::secp256k1::Error::InvalidSignature) =>
                                return Err(Bolt11SemanticError::InvalidSignature),
                        Err(e) => panic!("no other error may occur, got {:?}", e),
                        Ok(_) => {},
@@ -1811,9 +1809,9 @@ mod test {
        #[test]
        fn test_check_signature() {
                use crate::TaggedField::*;
-               use secp256k1::Secp256k1;
-               use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
-               use secp256k1::{SecretKey, PublicKey};
+               use bitcoin::secp256k1::Secp256k1;
+               use bitcoin::secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
+               use bitcoin::secp256k1::{SecretKey, PublicKey};
                use crate::{SignedRawBolt11Invoice, Bolt11InvoiceSignature, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256,
                         PositiveTimestamp};
 
@@ -1881,8 +1879,8 @@ mod test {
        fn test_check_feature_bits() {
                use crate::TaggedField::*;
                use lightning_types::features::Bolt11InvoiceFeatures;
-               use secp256k1::Secp256k1;
-               use secp256k1::SecretKey;
+               use bitcoin::secp256k1::Secp256k1;
+               use bitcoin::secp256k1::SecretKey;
                use crate::{Bolt11Invoice, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp,
                         Bolt11SemanticError};
 
@@ -2003,7 +2001,7 @@ mod test {
                use crate::*;
                use lightning_types::routing::RouteHintHop;
                use std::iter::FromIterator;
-               use secp256k1::PublicKey;
+               use bitcoin::secp256k1::PublicKey;
 
                let builder = InvoiceBuilder::new(Currency::Bitcoin)
                        .payment_hash(sha256::Hash::from_slice(&[0;32][..]).unwrap())
@@ -2056,8 +2054,8 @@ mod test {
        fn test_builder_ok() {
                use crate::*;
                use lightning_types::routing::RouteHintHop;
-               use secp256k1::Secp256k1;
-               use secp256k1::{SecretKey, PublicKey};
+               use bitcoin::secp256k1::Secp256k1;
+               use bitcoin::secp256k1::{SecretKey, PublicKey};
                use std::time::Duration;
 
                let secp_ctx = Secp256k1::new();
@@ -2177,8 +2175,8 @@ mod test {
        #[test]
        fn test_default_values() {
                use crate::*;
-               use secp256k1::Secp256k1;
-               use secp256k1::SecretKey;
+               use bitcoin::secp256k1::Secp256k1;
+               use bitcoin::secp256k1::SecretKey;
 
                let signed_invoice = InvoiceBuilder::new(Currency::Bitcoin)
                        .description("Test".into())
@@ -2203,8 +2201,8 @@ mod test {
        #[test]
        fn test_expiration() {
                use crate::*;
-               use secp256k1::Secp256k1;
-               use secp256k1::SecretKey;
+               use bitcoin::secp256k1::Secp256k1;
+               use bitcoin::secp256k1::SecretKey;
 
                let signed_invoice = InvoiceBuilder::new(Currency::Bitcoin)
                        .description("Test".into())
index b4f7c778d8af19294499ea4d93cc46fa07daf909..69ef3693c6133aadea2a19560f80ce683c5fbe71 100644 (file)
@@ -297,7 +297,7 @@ impl ToBase32 for PayeePubKey {
 
 impl Base32Len for PayeePubKey {
        fn base32_len(&self) -> usize {
-               bytes_size_to_base32_size(secp256k1::constants::PUBLIC_KEY_SIZE)
+               bytes_size_to_base32_size(bitcoin::secp256k1::constants::PUBLIC_KEY_SIZE)
        }
 }
 
index d9d6ad4c19548e0da534564bd8c9e4c45a684fe9..68404817ff67965cbd68d45daf46a3db28ef1813 100644 (file)
@@ -1,13 +1,12 @@
 extern crate bech32;
 extern crate lightning_invoice;
-extern crate secp256k1;
 
 use bitcoin::{PubkeyHash, ScriptHash, WitnessVersion};
 use bitcoin::hex::FromHex;
 use bitcoin::hashes::{sha256, Hash};
 use lightning_invoice::*;
-use secp256k1::PublicKey;
-use secp256k1::ecdsa::{RecoverableSignature, RecoveryId};
+use bitcoin::secp256k1::PublicKey;
+use bitcoin::secp256k1::ecdsa::{RecoverableSignature, RecoveryId};
 use std::collections::HashSet;
 use std::time::Duration;
 use std::str::FromStr;