From: Arik Sosman Date: Wed, 14 Aug 2024 20:07:24 +0000 (-0700) Subject: Remove secp256k1 dependency. X-Git-Tag: v0.0.124-beta~9^2~6 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=0cc9378afc8a9b05966664f9ecefa87cf686490d;p=rust-lightning Remove secp256k1 dependency. --- diff --git a/lightning-invoice/Cargo.toml b/lightning-invoice/Cargo.toml index 59f411409..f03875d67 100644 --- a/lightning-invoice/Cargo.toml +++ b/lightning-invoice/Cargo.toml @@ -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"} diff --git a/lightning-invoice/src/de.rs b/lightning-invoice/src/de.rs index be1a21aa2..e5ba67ccc 100644 --- a/lightning-invoice/src/de.rs +++ b/lightning-invoice/src/de.rs @@ -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 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}; diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index fea0b6850..bbb8dc8d5 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -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 { + pub fn recover_payee_pub_key(&self) -> Result { 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()) diff --git a/lightning-invoice/src/ser.rs b/lightning-invoice/src/ser.rs index b4f7c778d..69ef3693c 100644 --- a/lightning-invoice/src/ser.rs +++ b/lightning-invoice/src/ser.rs @@ -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) } } diff --git a/lightning-invoice/tests/ser_de.rs b/lightning-invoice/tests/ser_de.rs index d9d6ad4c1..68404817f 100644 --- a/lightning-invoice/tests/ser_de.rs +++ b/lightning-invoice/tests/ser_de.rs @@ -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;