diff --git a/Cargo.lock b/Cargo.lock index 03d16a25de5..dc50e97e909 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1966,7 +1966,7 @@ dependencies = [ "opentelemetry-jaeger", "rand 0.6.5", "rayon", - "secp256k1-zkp", + "secp256k1", "serde", "serde_json", "sha3", @@ -1995,7 +1995,6 @@ dependencies = [ "lightning-invoice", "minimint-derive", "rand 0.6.5", - "secp256k1-zkp", "serde", "serde_json", "sled", @@ -2110,6 +2109,7 @@ dependencies = [ "minimint-ln", "minimint-mint", "minimint-wallet", + "miniscript", "mint-client", "rand 0.6.5", "serde", @@ -2133,7 +2133,6 @@ dependencies = [ "minimint-derive", "miniscript", "rand 0.6.5", - "secp256k1", "serde", "test-log", "thiserror", @@ -2184,7 +2183,6 @@ dependencies = [ "minimint-core", "miniscript", "rand 0.6.5", - "secp256k1-zkp", "serde", "serde_json", "tbs", @@ -3155,7 +3153,6 @@ dependencies = [ "rand 0.6.5", "secp256k1", "secp256k1-zkp-sys", - "serde", ] [[package]] diff --git a/client/cli/src/main.rs b/client/cli/src/main.rs index 3a397d75b62..c93e5307333 100644 --- a/client/cli/src/main.rs +++ b/client/cli/src/main.rs @@ -8,6 +8,7 @@ use minimint_core::modules::wallet::txoproof::TxOutProof; use mint_client::mint::SpendableCoin; use mint_client::utils::{from_hex, parse_bitcoin_amount, parse_coins, serialize_coins}; use mint_client::{ClientAndGatewayConfig, UserClient}; +use rand::rngs::OsRng; use serde::{Deserialize, Serialize}; use std::path::PathBuf; use std::time::Duration; @@ -84,7 +85,7 @@ async fn main() { .open_tree("mint-client") .unwrap(); - let mut rng = rand::rngs::OsRng::new().unwrap(); + let mut rng = OsRng::new().unwrap(); let client = UserClient::new(cfg.client, Box::new(db), Default::default()).await; diff --git a/client/client-lib/Cargo.toml b/client/client-lib/Cargo.toml index f35977af135..9d540a1451f 100644 --- a/client/client-lib/Cargo.toml +++ b/client/client-lib/Cargo.toml @@ -21,7 +21,6 @@ miniscript = "7.0.0" minimint-core = { path = "../../minimint-core" } minimint-api = { path = "../../minimint-api" } rand = "0.6.5" -secp256k1-zkp = { version = "0.6.0", features = [ "serde", "bitcoin_hashes" ] } serde = "1.0.118" tbs = { path = "../../crypto/tbs" } thiserror = "1.0.23" diff --git a/client/client-lib/src/api.rs b/client/client-lib/src/api.rs index 1d35361270e..b3dcfa62b53 100644 --- a/client/client-lib/src/api.rs +++ b/client/client-lib/src/api.rs @@ -1,5 +1,5 @@ use async_trait::async_trait; -use bitcoin_hashes::sha256::Hash as Sha256Hash; +use bitcoin_hashes::sha256; use futures::StreamExt; use jsonrpsee_core::client::ClientT; use jsonrpsee_core::Error as JsonRpcError; @@ -29,7 +29,7 @@ pub trait FederationApi: Send + Sync { async fn fetch_contract(&self, contract: ContractId) -> Result; /// Fetch preimage offer for incoming lightning payments - async fn fetch_offer(&self, payment_hash: Sha256Hash) -> Result; + async fn fetch_offer(&self, payment_hash: sha256::Hash) -> Result; /// Fetch the current consensus block height (trailing actual block height) async fn fetch_consensus_block_height(&self) -> Result; @@ -134,7 +134,7 @@ impl FederationApi for WsFederationApi { self.request("/wallet/block_height", ()).await } - async fn fetch_offer(&self, payment_hash: Sha256Hash) -> Result { + async fn fetch_offer(&self, payment_hash: sha256::Hash) -> Result { self.request("/ln/offer", payment_hash).await } } diff --git a/client/client-lib/src/clients/gateway.rs b/client/client-lib/src/clients/gateway.rs index 0b475ea8885..bac8eb784f7 100644 --- a/client/client-lib/src/clients/gateway.rs +++ b/client/client-lib/src/clients/gateway.rs @@ -21,6 +21,7 @@ use minimint_core::modules::ln::contracts::{ use minimint_core::modules::ln::{ContractOrOfferOutput, ContractOutput}; use minimint_core::transaction::Input; use rand::{CryptoRng, RngCore}; +use bitcoin::secp256k1::{KeyPair, Secp256k1, XOnlyPublicKey}; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -32,7 +33,7 @@ pub struct GatewayClient { pub struct GatewayClientConfig { pub common: ClientConfig, #[serde(with = "serde_keypair")] - pub redeem_key: bitcoin::KeyPair, + pub redeem_key: KeyPair, pub timelock_delta: u64, } @@ -72,7 +73,7 @@ impl GatewayClient { config, db, api, - secp: secp256k1_zkp::Secp256k1::new(), + secp: Secp256k1::new(), }, } } @@ -108,8 +109,7 @@ impl GatewayClient { &self, account: &OutgoingContractAccount, ) -> Result { - let our_pub_key = - secp256k1_zkp::XOnlyPublicKey::from_keypair(&self.context.config.redeem_key); + let our_pub_key = XOnlyPublicKey::from_keypair(&self.context.config.redeem_key); if account.contract.gateway_key != our_pub_key { return Err(GatewayClientError::NotOurKey); @@ -223,7 +223,7 @@ impl GatewayClient { pub async fn buy_preimage_offer( &self, - payment_hash: &bitcoin_hashes::sha256::Hash, + payment_hash: &bitcoin::hashes::sha256::Hash, amount: &Amount, mut rng: impl RngCore + CryptoRng, ) -> Result<(minimint_api::TransactionId, ContractId)> { @@ -241,8 +241,7 @@ impl GatewayClient { .create_coin_input(batch.transaction(), offer.amount)?; // Outputs - let our_pub_key = - secp256k1_zkp::XOnlyPublicKey::from_keypair(&self.context.config.redeem_key); + let our_pub_key = XOnlyPublicKey::from_keypair(&self.context.config.redeem_key); let contract = Contract::Incoming(IncomingContract { hash: offer.hash, encrypted_preimage: offer.encrypted_preimage.clone(), @@ -441,8 +440,7 @@ mod db { } pub mod serde_keypair { - use bitcoin::KeyPair; - use secp256k1_zkp::SecretKey; + use bitcoin::secp256k1::{KeyPair, SecretKey, SECP256K1}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[allow(missing_docs)] @@ -460,9 +458,6 @@ pub mod serde_keypair { { let secret_key = SecretKey::deserialize(deserializer)?; - Ok(KeyPair::from_secret_key( - secp256k1_zkp::SECP256K1, - secret_key, - )) + Ok(KeyPair::from_secret_key(SECP256K1, secret_key)) } } diff --git a/client/client-lib/src/clients/transaction.rs b/client/client-lib/src/clients/transaction.rs index 65558285ce1..10ac4b03fb5 100644 --- a/client/client-lib/src/clients/transaction.rs +++ b/client/client-lib/src/clients/transaction.rs @@ -1,9 +1,9 @@ -use rand::{CryptoRng, RngCore}; - use bitcoin::KeyPair; use minimint_api::Amount; use minimint_core::config::FeeConsensus; use minimint_core::transaction::{Input, Output, Transaction}; +use rand::{CryptoRng, RngCore}; +use bitcoin::secp256k1::{All, Secp256k1}; pub struct TransactionBuilder { keys: Vec, @@ -39,7 +39,7 @@ impl TransactionBuilder { pub fn build( mut self, - secp: &secp256k1_zkp::Secp256k1, + secp: &Secp256k1, mut rng: R, ) -> Transaction { if !self.keys.is_empty() { diff --git a/client/client-lib/src/clients/user.rs b/client/client-lib/src/clients/user.rs index 4b0f4d126fd..cff401ddceb 100644 --- a/client/client-lib/src/clients/user.rs +++ b/client/client-lib/src/clients/user.rs @@ -5,9 +5,10 @@ use crate::ln::{LnClient, LnClientError}; use crate::mint::{MintClient, MintClientError, SpendableCoin}; use crate::wallet::{WalletClient, WalletClientError}; use crate::{api, OwnedClientContext}; +use bitcoin::secp256k1::{All, Secp256k1}; use bitcoin::util::key::KeyPair; use bitcoin::{Address, Network, Transaction as BitcoinTransaction}; -use bitcoin_hashes::Hash; +use bitcoin_hashes::{sha256, Hash}; use lightning::ln::PaymentSecret; use lightning_invoice::{CreationError, Currency, Invoice, InvoiceBuilder}; use minimint_api::db::batch::{Accumulator, BatchItem, DbBatch}; @@ -25,7 +26,6 @@ use minimint_core::modules::mint::BlindToken; use minimint_core::modules::wallet::txoproof::TxOutProof; use minimint_core::transaction::{Input, Output, TransactionItem}; use rand::{CryptoRng, RngCore}; -use secp256k1_zkp::{All, Secp256k1}; use std::time::Duration; use thiserror::Error; @@ -338,7 +338,7 @@ impl UserClient { ) -> Result<(KeyPair, UnconfirmedInvoice), ClientError> { let payment_keypair = KeyPair::new(&self.context.secp, &mut rng); let raw_payment_secret = payment_keypair.public_key().serialize(); - let payment_hash = bitcoin::secp256k1::hashes::sha256::Hash::hash(&raw_payment_secret); + let payment_hash = sha256::Hash::hash(&raw_payment_secret); let payment_secret = PaymentSecret(raw_payment_secret); // Temporary lightning node pubkey diff --git a/client/client-lib/src/lib.rs b/client/client-lib/src/lib.rs index ee070e8745d..e999416f76e 100644 --- a/client/client-lib/src/lib.rs +++ b/client/client-lib/src/lib.rs @@ -7,6 +7,7 @@ pub mod wallet; use crate::api::FederationApi; use crate::ln::gateway::LightningGateway; +use bitcoin::secp256k1::{All, Secp256k1}; pub use clients::user::UserClient; use minimint_api::db::Database; use minimint_core::config::ClientConfig; @@ -16,14 +17,14 @@ pub struct BorrowedClientContext<'a, C> { config: &'a C, db: &'a dyn Database, api: &'a dyn FederationApi, - secp: &'a secp256k1_zkp::Secp256k1, + secp: &'a Secp256k1, } struct OwnedClientContext { config: C, db: Box, api: Box, - secp: secp256k1_zkp::Secp256k1, + secp: Secp256k1, } impl OwnedClientContext { diff --git a/client/client-lib/src/ln/gateway.rs b/client/client-lib/src/ln/gateway.rs index 4fd0a7e234f..121c54710d9 100644 --- a/client/client-lib/src/ln/gateway.rs +++ b/client/client-lib/src/ln/gateway.rs @@ -1,9 +1,9 @@ -use bitcoin::secp256k1; +use bitcoin::secp256k1::{PublicKey, XOnlyPublicKey}; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct LightningGateway { - pub mint_pub_key: secp256k1::XOnlyPublicKey, - pub node_pub_key: secp256k1::PublicKey, + pub mint_pub_key: XOnlyPublicKey, + pub node_pub_key: PublicKey, pub api: String, } diff --git a/client/client-lib/src/ln/mod.rs b/client/client-lib/src/ln/mod.rs index bf22cf103a5..e54584a9e1c 100644 --- a/client/client-lib/src/ln/mod.rs +++ b/client/client-lib/src/ln/mod.rs @@ -177,6 +177,8 @@ mod tests { use crate::ln::LnClient; use crate::OwnedClientContext; use async_trait::async_trait; + use bitcoin::secp256k1::{PublicKey, XOnlyPublicKey}; + use bitcoin_hashes::sha256; use lightning_invoice::Invoice; use minimint_api::db::batch::DbBatch; use minimint_api::db::mem_impl::MemDatabase; @@ -238,7 +240,7 @@ mod tests { async fn fetch_offer( &self, - _payment_hash: bitcoin::hashes::sha256::Hash, + _payment_hash: sha256::Hash, ) -> crate::api::Result { unimplemented!(); } @@ -263,7 +265,7 @@ mod tests { config: fed.lock().await.client_cfg().clone(), db: Box::new(MemDatabase::new()), api: Box::new(api), - secp: secp256k1_zkp::Secp256k1::new(), + secp: bitcoin::secp256k1::Secp256k1::new(), }; (fed, client_context) @@ -294,8 +296,8 @@ mod tests { .unwrap(); let invoice_amt_msat = invoice.amount_milli_satoshis().unwrap(); let gateway = { - let mint_pub_key = secp256k1_zkp::XOnlyPublicKey::from_slice(&[42; 32][..]).unwrap(); - let node_pub_key = secp256k1_zkp::PublicKey::from_slice(&[2; 33][..]).unwrap(); + let mint_pub_key = XOnlyPublicKey::from_slice(&[42; 32][..]).unwrap(); + let node_pub_key = PublicKey::from_slice(&[2; 33][..]).unwrap(); LightningGateway { mint_pub_key, node_pub_key, @@ -360,7 +362,7 @@ mod tests { fed.lock().await.set_block_height(timelock as u64); let meta = fed.lock().await.verify_input(&refund_input).unwrap(); - let refund_pk = secp256k1_zkp::XOnlyPublicKey::from_keypair(refund_key); + let refund_pk = XOnlyPublicKey::from_keypair(refund_key); assert_eq!(meta.keys, vec![refund_pk]); assert_eq!(meta.amount, expected_amount); diff --git a/client/client-lib/src/mint/mod.rs b/client/client-lib/src/mint/mod.rs index 02322a46b04..46236b69557 100644 --- a/client/client-lib/src/mint/mod.rs +++ b/client/client-lib/src/mint/mod.rs @@ -3,7 +3,7 @@ mod db; use crate::api::ApiError; use crate::clients::transaction::TransactionBuilder; use crate::BorrowedClientContext; -use bitcoin::KeyPair; +use bitcoin::secp256k1::{KeyPair, Secp256k1, Signing}; use db::{CoinKey, CoinKeyPrefix, OutputFinalizationKey, OutputFinalizationKeyPrefix}; use minimint_api::db::batch::{BatchItem, BatchTx}; use minimint_api::encoding::{Decodable, Encodable}; @@ -15,7 +15,6 @@ use minimint_core::modules::mint::{ }; use minimint_core::transaction::{Output, Transaction}; use rand::{CryptoRng, Rng, RngCore}; -use secp256k1_zkp::{Secp256k1, Signing}; use serde::{Deserialize, Serialize}; use std::time::Duration; use tbs::{blind_message, unblind_signature, AggregatePublicKey, BlindedMessage, BlindingKey}; @@ -119,9 +118,8 @@ impl<'c> MintClient<'c> { let coin_key_pairs = coins .into_iter() .map(|(amt, coin)| { - let spend_key = - bitcoin::KeyPair::from_seckey_slice(self.context.secp, &coin.spend_key) - .map_err(|_| MintClientError::ReceivedUspendableCoin)?; + let spend_key = KeyPair::from_seckey_slice(self.context.secp, &coin.spend_key) + .map_err(|_| MintClientError::ReceivedUspendableCoin)?; // We check for coin validity in case we got it from an untrusted third party. We // don't want to needlessly create invalid tx and bother the federation with them. @@ -343,7 +341,7 @@ impl CoinRequest { where C: Signing, { - let spend_key = bitcoin::KeyPair::new(ctx, &mut rng); + let spend_key = KeyPair::new(ctx, &mut rng); let nonce = CoinNonce(spend_key.public_key()); let (blinding_key, blinded_nonce) = blind_message(nonce.to_message()); @@ -416,6 +414,8 @@ mod tests { use crate::OwnedClientContext; use async_trait::async_trait; use bitcoin::hashes::Hash; + use bitcoin::secp256k1::{Secp256k1, XOnlyPublicKey}; + use bitcoin_hashes::sha256; use futures::executor::block_on; use minimint_api::db::batch::DbBatch; use minimint_api::db::mem_impl::MemDatabase; @@ -429,7 +429,9 @@ mod tests { use minimint_core::modules::mint::Mint; use minimint_core::outcome::{OutputOutcome, TransactionStatus}; use minimint_core::transaction::Transaction; + use rand::rngs::OsRng; use std::sync::Arc; + use tokio::sync::Mutex; type Fed = FakeFed; @@ -473,17 +475,14 @@ mod tests { async fn fetch_offer( &self, - _payment_hash: bitcoin::hashes::sha256::Hash, + _payment_hash: sha256::Hash, ) -> crate::api::Result { unimplemented!(); } } - async fn new_mint_and_client() -> ( - Arc>, - OwnedClientContext, - ) { - let fed = Arc::new(tokio::sync::Mutex::new( + async fn new_mint_and_client() -> (Arc>, OwnedClientContext) { + let fed = Arc::new(Mutex::new( FakeFed::::new( 4, 1, @@ -498,7 +497,7 @@ mod tests { config: fed.lock().await.client_cfg().clone(), db: Box::new(MemDatabase::new()), api: Box::new(api), - secp: secp256k1_zkp::Secp256k1::new(), + secp: Secp256k1::new(), }; (fed, client_context) @@ -533,7 +532,7 @@ mod tests { #[test_log::test(tokio::test)] async fn create_output() { - let mut rng = rand::rngs::OsRng::new().unwrap(); + let mut rng = OsRng::new().unwrap(); let (fed, client_context) = new_mint_and_client().await; let client = MintClient { @@ -555,7 +554,7 @@ mod tests { #[test_log::test(tokio::test)] async fn create_input() { - let mut rng = rand::rngs::OsRng::new().unwrap(); + let mut rng = OsRng::new().unwrap(); const SPEND_AMOUNT: Amount = Amount::from_sat(21); @@ -587,7 +586,7 @@ mod tests { meta.keys, spend_keys .into_iter() - .map(|key| secp256k1_zkp::XOnlyPublicKey::from_keypair(&key)) + .map(|key| XOnlyPublicKey::from_keypair(&key)) .collect::>() ); @@ -616,7 +615,7 @@ mod tests { meta.keys, spend_keys .into_iter() - .map(|key| secp256k1_zkp::XOnlyPublicKey::from_keypair(&key)) + .map(|key| XOnlyPublicKey::from_keypair(&key)) .collect::>() ); diff --git a/client/client-lib/src/utils.rs b/client/client-lib/src/utils.rs index b81e549ba98..736b8e4f8b6 100644 --- a/client/client-lib/src/utils.rs +++ b/client/client-lib/src/utils.rs @@ -1,4 +1,5 @@ use crate::mint::SpendableCoin; +use bitcoin::Denomination::Satoshi; use minimint_api::encoding::Decodable; use minimint_core::modules::mint::tiered::coins::Coins; @@ -20,5 +21,5 @@ pub fn from_hex(s: &str) -> Result { pub fn parse_bitcoin_amount( s: &str, ) -> Result { - bitcoin::Amount::from_str_in(s, bitcoin::Denomination::Satoshi) + bitcoin::Amount::from_str_in(s, Satoshi) } diff --git a/client/client-lib/src/wallet/mod.rs b/client/client-lib/src/wallet/mod.rs index 098fc3dbb57..02377a9c377 100644 --- a/client/client-lib/src/wallet/mod.rs +++ b/client/client-lib/src/wallet/mod.rs @@ -1,6 +1,6 @@ use crate::BorrowedClientContext; +use bitcoin::secp256k1::{KeyPair, XOnlyPublicKey}; use bitcoin::Address; -use bitcoin::KeyPair; use db::PegInKey; use minimint_api::db::batch::BatchTx; use minimint_api::Amount; @@ -29,8 +29,8 @@ impl<'c> WalletClient<'c> { mut batch: BatchTx<'_>, mut rng: R, ) -> Address { - let peg_in_keypair = bitcoin::KeyPair::new(self.context.secp, &mut rng); - let peg_in_pub_key = secp256k1_zkp::XOnlyPublicKey::from_keypair(&peg_in_keypair); + let peg_in_keypair = KeyPair::new(self.context.secp, &mut rng); + let peg_in_pub_key = XOnlyPublicKey::from_keypair(&peg_in_keypair); // TODO: check at startup that no bare descriptor is used in config // TODO: check if there are other failure cases @@ -76,7 +76,7 @@ impl<'c> WalletClient<'c> { }) .ok_or(WalletClientError::NoMatchingPegInFound)?; let secret_tweak_key = - bitcoin::KeyPair::from_seckey_slice(self.context.secp, &secret_tweak_key_bytes) + KeyPair::from_seckey_slice(self.context.secp, &secret_tweak_key_bytes) .expect("sec key was generated and saved by us"); let peg_in_proof = PegInProof::new( @@ -102,11 +102,7 @@ impl<'c> WalletClient<'c> { Ok((secret_tweak_key, peg_in_proof)) } - pub fn create_pegout_output( - &self, - amount: bitcoin::Amount, - recipient: bitcoin::Address, - ) -> PegOut { + pub fn create_pegout_output(&self, amount: bitcoin::Amount, recipient: Address) -> PegOut { PegOut { recipient, amount } } } @@ -131,6 +127,8 @@ mod tests { use async_trait::async_trait; use bitcoin::Address; + use bitcoin::secp256k1::Secp256k1; + use bitcoin_hashes::sha256; use minimint_api::db::mem_impl::MemDatabase; use minimint_api::module::testing::FakeFed; use minimint_api::{Amount, OutPoint, TransactionId}; @@ -187,7 +185,7 @@ mod tests { async fn fetch_offer( &self, - _payment_hash: bitcoin::hashes::sha256::Hash, + _payment_hash: sha256::Hash, ) -> crate::api::Result { unimplemented!(); } @@ -226,7 +224,7 @@ mod tests { config: fed.lock().await.client_cfg().clone(), db: Box::new(MemDatabase::new()), api: Box::new(api), - secp: secp256k1_zkp::Secp256k1::new(), + secp: Secp256k1::new(), }; (fed, client, btc_rpc_controller) diff --git a/integrationtests/Cargo.toml b/integrationtests/Cargo.toml index 0073850569f..fe1f15ea240 100644 --- a/integrationtests/Cargo.toml +++ b/integrationtests/Cargo.toml @@ -20,6 +20,7 @@ minimint-api = { path = "../minimint-api" } minimint-ln = { path = "../modules/minimint-ln" } minimint-mint = { path = "../modules/minimint-mint" } minimint-wallet = { path = "../modules/minimint-wallet" } +miniscript = { version = "7.0.0", features = [ "compiler", "use-serde" ] } mint-client = { path = "../client/client-lib" } rand = "0.6.5" serde = { version = "1.0.118", features = [ "derive" ] } diff --git a/integrationtests/tests/fixtures/fake.rs b/integrationtests/tests/fixtures/fake.rs index f406669acc2..84eda134e69 100644 --- a/integrationtests/tests/fixtures/fake.rs +++ b/integrationtests/tests/fixtures/fake.rs @@ -4,7 +4,7 @@ use std::sync::{Arc, Mutex}; use async_trait::async_trait; use bitcoin::hash_types::Txid; use bitcoin::hashes::{sha256, Hash}; -use bitcoin::secp256k1::{PublicKey, SecretKey}; +use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; use bitcoin::util::merkleblock::PartialMerkleTree; use bitcoin::{ secp256k1, Address, Block, BlockHash, BlockHeader, KeyPair, Network, Transaction, TxOut, @@ -18,6 +18,7 @@ use minimint_api::Amount; use minimint_wallet::bitcoind::BitcoindRpc; use minimint_wallet::txoproof::TxOutProof; use minimint_wallet::Feerate; +use miniscript::ToPublicKey; use crate::fixtures::{BitcoinTest, LightningTest}; @@ -172,10 +173,10 @@ impl BitcoinTest for FakeBitcoinTest { } fn get_new_address(&self) -> Address { - let ctx = bitcoin::secp256k1::Secp256k1::new(); + let ctx = Secp256k1::new(); let (_, public_key) = ctx.generate_keypair(&mut OsRng::new().unwrap()); - - Address::p2wpkh(&bitcoin::PublicKey::new(public_key), Network::Regtest).unwrap() + let public_key = public_key.to_public_key(); + Address::p2wpkh(&public_key, Network::Regtest).unwrap() } fn mine_block_and_get_received(&self, address: &Address) -> Amount { diff --git a/integrationtests/tests/fixtures/mod.rs b/integrationtests/tests/fixtures/mod.rs index df064702272..4e13c6f60ad 100644 --- a/integrationtests/tests/fixtures/mod.rs +++ b/integrationtests/tests/fixtures/mod.rs @@ -11,6 +11,8 @@ use std::time::Duration; use bitcoin::hashes::{sha256, Hash}; use bitcoin::KeyPair; +use bitcoin::secp256k1::PublicKey; +use bitcoin::secp256k1::Secp256k1; use bitcoin::{secp256k1, Address, Transaction}; use cln_rpc::ClnRpc; use futures::executor::block_on; @@ -206,10 +208,10 @@ impl GatewayTest { async fn new( ln_client: Box, client_config: ClientConfig, - node_pub_key: secp256k1::PublicKey, + node_pub_key: PublicKey, ) -> Self { let mut rng = OsRng::new().unwrap(); - let ctx = bitcoin::secp256k1::Secp256k1::new(); + let ctx = Secp256k1::new(); let kp = KeyPair::new(&ctx, &mut rng); let federation_client = GatewayClientConfig { diff --git a/ln-gateway/src/bin/gw_configgen.rs b/ln-gateway/src/bin/gw_configgen.rs index 51d5ce35cd9..34680b3c1f4 100644 --- a/ln-gateway/src/bin/gw_configgen.rs +++ b/ln-gateway/src/bin/gw_configgen.rs @@ -5,7 +5,7 @@ use mint_client::clients::gateway::GatewayClientConfig; use mint_client::ln::gateway::LightningGateway; use mint_client::ClientAndGatewayConfig; use rand::thread_rng; -use secp256k1::{KeyPair, PublicKey}; +use secp256k1::{KeyPair, PublicKey, Secp256k1}; use std::path::PathBuf; #[derive(Parser)] @@ -22,7 +22,7 @@ fn main() { load_from_file(&federation_client_cfg_path); let mut rng = thread_rng(); - let ctx = secp256k1::Secp256k1::new(); + let ctx = Secp256k1::new(); let kp = KeyPair::new(&ctx, &mut rng); diff --git a/ln-gateway/src/bin/ln_gateway.rs b/ln-gateway/src/bin/ln_gateway.rs index eaac699df47..53ec23a0373 100644 --- a/ln-gateway/src/bin/ln_gateway.rs +++ b/ln-gateway/src/bin/ln_gateway.rs @@ -2,6 +2,7 @@ use clap::Parser; use ln_gateway::{LnGateway, LnGatewayConfig}; use minimint::config::load_from_file; use minimint::modules::ln::contracts::ContractId; +use rand::rngs::OsRng; use std::path::PathBuf; use std::sync::Arc; use tide::Response; @@ -20,7 +21,7 @@ struct Opts { #[instrument(skip_all, err)] async fn pay_invoice(mut req: tide::Request) -> tide::Result { - let rng = rand::rngs::OsRng::new().unwrap(); + let rng = OsRng::new().unwrap(); let contract_id: ContractId = req.body_json().await?; let State { ref gateway } = req.state(); diff --git a/ln-gateway/src/lib.rs b/ln-gateway/src/lib.rs index 34896db2e37..07b059b0b64 100644 --- a/ln-gateway/src/lib.rs +++ b/ln-gateway/src/lib.rs @@ -2,6 +2,8 @@ pub mod ln; use crate::ln::{LightningError, LnRpc}; use bitcoin_hashes::sha256::Hash; +use cln_rpc::ClnRpc; +use futures::{executor, future}; use minimint::modules::ln::contracts::{incoming::Preimage, ContractId}; use minimint_api::{db::Database, Amount, OutPoint, TransactionId}; use mint_client::clients::gateway::{GatewayClient, GatewayClientConfig, GatewayClientError}; @@ -34,9 +36,7 @@ impl LnGateway { ln_socket, } = cfg; let federation_client = GatewayClient::new(federation_client, db).await; - let ln_client = cln_rpc::ClnRpc::new(ln_socket) - .await - .expect("connect to ln_socket"); + let ln_client = ClnRpc::new(ln_socket).await.expect("connect to ln_socket"); let ln_client = Mutex::new(ln_client); Self::new(Arc::new(federation_client), Box::new(ln_client)).await @@ -170,7 +170,7 @@ async fn background_fetch(federation_client: Arc, _ln_client: Arc } }) .collect::>(); - futures::future::join_all(pending_fetches).await; + future::join_all(pending_fetches).await; minimint_api::task::sleep_until(least_wait_until).await; } } @@ -178,7 +178,7 @@ async fn background_fetch(federation_client: Arc, _ln_client: Arc impl Drop for LnGateway { fn drop(&mut self) { self.fetcher.abort(); - assert!(futures::executor::block_on(&mut self.fetcher).is_err()); + assert!(executor::block_on(&mut self.fetcher).is_err()); } } diff --git a/ln-gateway/src/ln.rs b/ln-gateway/src/ln.rs index 05954e301bd..2f282d9ffa3 100644 --- a/ln-gateway/src/ln.rs +++ b/ln-gateway/src/ln.rs @@ -1,7 +1,7 @@ use std::convert::TryInto; use async_trait::async_trait; -use cln_rpc::model::requests::PayRequest; +use cln_rpc::{model::requests::PayRequest, ClnRpc, Request, Response, RpcError}; use tokio::sync::Mutex; use tracing::{debug, instrument}; @@ -20,7 +20,7 @@ pub trait LnRpc: Send + Sync + 'static { pub struct LightningError(Option); #[async_trait] -impl LnRpc for Mutex { +impl LnRpc for Mutex { #[instrument(name = "LnRpc::pay", skip(self))] async fn pay( &self, @@ -33,7 +33,7 @@ impl LnRpc for Mutex { let pay_result = self .lock() .await - .call(cln_rpc::Request::Pay(PayRequest { + .call(Request::Pay(PayRequest { bolt11: invoice.to_string(), msatoshi: None, label: None, @@ -50,12 +50,12 @@ impl LnRpc for Mutex { .await; match pay_result { - Ok(cln_rpc::Response::Pay(pay_success)) => { + Ok(Response::Pay(pay_success)) => { debug!("Successfully paid invoice"); Ok(pay_success.payment_preimage.to_vec().try_into().unwrap()) } Ok(_) => unreachable!("unexpected response from C-lightning"), - Err(cln_rpc::RpcError { code, message }) => { + Err(RpcError { code, message }) => { if let Some(code) = code { debug!(%code, %message, "c-lightning pay returned error"); } else { diff --git a/minimint-api/Cargo.toml b/minimint-api/Cargo.toml index 72c87b02049..14387c3662c 100644 --- a/minimint-api/Cargo.toml +++ b/minimint-api/Cargo.toml @@ -8,14 +8,13 @@ edition = "2018" [dependencies] anyhow = "1.0.58" async-trait = "0.1" -bitcoin = { version = "0.28.1", features = [ "rand", "serde" ] } +bitcoin = { version = "0.28.1", features = [ "rand", "serde", "use-serde"] } bitcoin_hashes = { version = "0.10", features = ["serde"] } futures = "0.3.21" hex = "0.4.3" lightning-invoice = "0.16.0" minimint-derive = { path = "../minimint-derive" } rand = "0.6.0" -secp256k1-zkp = { version = "0.6.0", features = [ "use-serde", "bitcoin_hashes", "global-context" ] } serde = { version = "1.0.118", features = [ "derive" ] } serde_json = "1.0.79" sled = "0.34" diff --git a/minimint-api/src/encoding/btc.rs b/minimint-api/src/encoding/btc.rs index f4af6fc49ef..31ca8705f13 100644 --- a/minimint-api/src/encoding/btc.rs +++ b/minimint-api/src/encoding/btc.rs @@ -1,5 +1,5 @@ use crate::encoding::{Decodable, DecodeError, Encodable}; -use bitcoin::hashes::Hash as BitcoinHash; +use bitcoin_hashes::{sha256, Hash}; use std::io::Error; macro_rules! impl_encode_decode_bridge { @@ -65,34 +65,31 @@ impl Decodable for bitcoin::Address { } } -impl Encodable for bitcoin::hashes::sha256::Hash { +impl Encodable for sha256::Hash { fn consensus_encode(&self, writer: W) -> Result { self.into_inner().consensus_encode(writer) } } -impl Decodable for bitcoin::hashes::sha256::Hash { +impl Decodable for sha256::Hash { fn consensus_decode(d: D) -> Result { - Ok(bitcoin::hashes::sha256::Hash::from_inner( - Decodable::consensus_decode(d)?, - )) + Ok(sha256::Hash::from_inner(Decodable::consensus_decode(d)?)) } } #[cfg(test)] mod tests { use crate::encoding::{Decodable, Encodable}; - use bitcoin::hashes::Hash as BitcoinHash; + use bitcoin_hashes::{sha256, Hash}; use std::io::Cursor; use std::str::FromStr; #[test_log::test] fn sha256_roundtrip() { - let hash = bitcoin::hashes::sha256::Hash::hash(b"Hello world!"); + let hash = sha256::Hash::hash(b"Hello world!"); let mut encoded = Vec::new(); hash.consensus_encode(&mut encoded).unwrap(); - let hash_decoded = - bitcoin::hashes::sha256::Hash::consensus_decode(Cursor::new(encoded)).unwrap(); + let hash_decoded = sha256::Hash::consensus_decode(Cursor::new(encoded)).unwrap(); assert_eq!(hash, hash_decoded); } diff --git a/minimint-api/src/encoding/secp256k1.rs b/minimint-api/src/encoding/secp256k1.rs index 64268941cb8..bb6d950672c 100644 --- a/minimint-api/src/encoding/secp256k1.rs +++ b/minimint-api/src/encoding/secp256k1.rs @@ -1,8 +1,13 @@ use crate::encoding::{Decodable, DecodeError, Encodable}; -use secp256k1_zkp::ecdsa::Signature; +use bitcoin::secp256k1::{ + constants, + ecdsa::{self, Signature}, + global, schnorr, XOnlyPublicKey, +}; + use std::io::{Error, Read, Write}; -impl Encodable for secp256k1_zkp::ecdsa::Signature { +impl Encodable for ecdsa::Signature { fn consensus_encode(&self, mut writer: W) -> Result { let bytes = self.serialize_compact(); writer.write_all(&bytes)?; @@ -10,7 +15,7 @@ impl Encodable for secp256k1_zkp::ecdsa::Signature { } } -impl Decodable for secp256k1_zkp::ecdsa::Signature { +impl Decodable for ecdsa::Signature { fn consensus_decode(mut d: D) -> Result { let mut bytes = [0u8; 64]; d.read_exact(&mut bytes).map_err(DecodeError::from_err)?; @@ -18,7 +23,7 @@ impl Decodable for secp256k1_zkp::ecdsa::Signature { } } -impl Encodable for secp256k1_zkp::XOnlyPublicKey { +impl Encodable for XOnlyPublicKey { fn consensus_encode(&self, mut writer: W) -> Result { let bytes = self.serialize(); writer.write_all(&bytes[..])?; @@ -26,31 +31,28 @@ impl Encodable for secp256k1_zkp::XOnlyPublicKey { } } -impl Decodable for secp256k1_zkp::XOnlyPublicKey { +impl Decodable for XOnlyPublicKey { fn consensus_decode(mut d: D) -> Result { let mut bytes = [0u8; 32]; d.read_exact(&mut bytes).map_err(DecodeError::from_err)?; - secp256k1_zkp::XOnlyPublicKey::from_slice(&bytes[..]).map_err(DecodeError::from_err) + XOnlyPublicKey::from_slice(&bytes[..]).map_err(DecodeError::from_err) } } -impl Encodable for secp256k1_zkp::schnorr::Signature { +impl Encodable for schnorr::Signature { fn consensus_encode(&self, mut writer: W) -> Result { let bytes = &self[..]; - assert_eq!( - bytes.len(), - secp256k1_zkp::constants::SCHNORR_SIGNATURE_SIZE - ); + assert_eq!(bytes.len(), constants::SCHNORR_SIGNATURE_SIZE); writer.write_all(bytes)?; - Ok(secp256k1_zkp::constants::SCHNORR_SIGNATURE_SIZE) + Ok(constants::SCHNORR_SIGNATURE_SIZE) } } -impl Decodable for secp256k1_zkp::schnorr::Signature { +impl Decodable for schnorr::Signature { fn consensus_decode(mut d: D) -> Result { - let mut bytes = [0u8; secp256k1_zkp::constants::SCHNORR_SIGNATURE_SIZE]; + let mut bytes = [0u8; constants::SCHNORR_SIGNATURE_SIZE]; d.read_exact(&mut bytes).map_err(DecodeError::from_err)?; - secp256k1_zkp::schnorr::Signature::from_slice(&bytes).map_err(DecodeError::from_err) + schnorr::Signature::from_slice(&bytes).map_err(DecodeError::from_err) } } @@ -63,7 +65,7 @@ impl Encodable for bitcoin::KeyPair { impl Decodable for bitcoin::KeyPair { fn consensus_decode(d: D) -> Result { let sec_bytes = <[u8; 32]>::consensus_decode(d)?; - Self::from_seckey_slice(secp256k1_zkp::global::SECP256K1, &sec_bytes) // FIXME: evaluate security risk of global ctx + Self::from_seckey_slice(global::SECP256K1, &sec_bytes) // FIXME: evaluate security risk of global ctx .map_err(DecodeError::from_err) } } @@ -71,15 +73,16 @@ impl Decodable for bitcoin::KeyPair { #[cfg(test)] mod tests { use super::super::tests::test_roundtrip; - use secp256k1_zkp::hashes::Hash as BitcoinHash; - use secp256k1_zkp::Message; + use bitcoin::secp256k1::{global, Message, Secp256k1}; + use bitcoin_hashes::{sha256, Hash}; + use rand::rngs::OsRng; #[test_log::test] fn test_ecdsa_sig() { - let ctx = secp256k1_zkp::Secp256k1::new(); + let ctx = Secp256k1::new(); let (sk, _pk) = ctx.generate_keypair(&mut rand::thread_rng()); let sig = ctx.sign_ecdsa( - &Message::from_hashed_data::(b"Hello World!"), + &Message::from_hashed_data::(b"Hello World!"), &sk, ); @@ -88,16 +91,13 @@ mod tests { #[test_log::test] fn test_schnorr_pub_key() { - let ctx = secp256k1_zkp::global::SECP256K1; - let mut rng = rand::rngs::OsRng::new().unwrap(); + let ctx = global::SECP256K1; + let mut rng = OsRng::new().unwrap(); let sec_key = bitcoin::KeyPair::new(ctx, &mut rng); let pub_key = sec_key.public_key(); test_roundtrip(pub_key); - let sig = ctx.sign_schnorr( - &secp256k1_zkp::hashes::sha256::Hash::hash(b"Hello World!").into(), - &sec_key, - ); + let sig = ctx.sign_schnorr(&sha256::Hash::hash(b"Hello World!").into(), &sec_key); test_roundtrip(sig); } diff --git a/minimint-api/src/module/mod.rs b/minimint-api/src/module/mod.rs index af93cd63846..731c299dccc 100644 --- a/minimint-api/src/module/mod.rs +++ b/minimint-api/src/module/mod.rs @@ -5,10 +5,9 @@ pub mod testing; use crate::db::batch::BatchTx; use crate::{Amount, PeerId}; use async_trait::async_trait; +use bitcoin::secp256k1::{rand::RngCore, XOnlyPublicKey}; use futures::future::BoxFuture; use rand::CryptoRng; -use secp256k1_zkp::rand::RngCore; -use secp256k1_zkp::XOnlyPublicKey; use std::collections::HashSet; use crate::module::audit::Audit; diff --git a/minimint-api/src/module/testing.rs b/minimint-api/src/module/testing.rs index c58bf9bd498..8cef53c1d19 100644 --- a/minimint-api/src/module/testing.rs +++ b/minimint-api/src/module/testing.rs @@ -1,4 +1,6 @@ use async_trait::async_trait; +use bitcoin::secp256k1::XOnlyPublicKey; +use rand::rngs::OsRng; use crate::config::GenerateConfig; use crate::db::batch::DbBatch; @@ -24,7 +26,7 @@ pub struct FakeFed { #[derive(Debug, PartialEq, Eq)] pub struct TestInputMeta { pub amount: Amount, - pub keys: Vec, + pub keys: Vec, } impl FakeFed @@ -49,7 +51,7 @@ where .map(|idx| PeerId::from(idx as u16)) .collect::>(); let (server_cfg, client_cfg) = - C::trusted_dealer_gen(&peers, max_evil, params, rand::rngs::OsRng::new().unwrap()); + C::trusted_dealer_gen(&peers, max_evil, params, OsRng::new().unwrap()); let mut members = vec![]; for (peer, cfg) in server_cfg { @@ -99,7 +101,7 @@ where ) where ::TxInput: Send + Sync, { - let mut rng = rand::rngs::OsRng::new().unwrap(); + let mut rng = OsRng::new().unwrap(); let fake_ic = FakeInterconnect::new_block_height_responder(self.block_height.clone()); // TODO: only include some of the proposals for realism diff --git a/minimint-core/src/transaction.rs b/minimint-core/src/transaction.rs index 717d3b1c0bd..5db0f917965 100644 --- a/minimint-core/src/transaction.rs +++ b/minimint-core/src/transaction.rs @@ -1,6 +1,6 @@ use crate::config::FeeConsensus; use bitcoin::hashes::Hash as BitcoinHash; -use bitcoin::XOnlyPublicKey; +use bitcoin::secp256k1::XOnlyPublicKey; use minimint_api::encoding::{Decodable, Encodable}; use minimint_api::{Amount, FederationModule, TransactionId}; use rand::Rng; diff --git a/minimint/Cargo.toml b/minimint/Cargo.toml index f8291d6755a..0c90f540bcf 100644 --- a/minimint/Cargo.toml +++ b/minimint/Cargo.toml @@ -29,7 +29,7 @@ opentelemetry = { version = "0.17.0", optional = true } opentelemetry-jaeger = { version = "0.16.0", optional = true } rand = "0.6.5" rayon = "1.5.0" -secp256k1-zkp = { version = "0.6.0", features = [ "global-context", "bitcoin_hashes" ] } +secp256k1 = { version = "0.22.1", features = [ "global-context", "bitcoin_hashes" ] } serde = { version = "1.0.118", features = [ "derive" ] } serde_json = "1.0.61" sha3 = "0.9.1" diff --git a/minimint/src/consensus/interconnect.rs b/minimint/src/consensus/interconnect.rs index cf72179c0a2..d50d1733392 100644 --- a/minimint/src/consensus/interconnect.rs +++ b/minimint/src/consensus/interconnect.rs @@ -5,7 +5,7 @@ use minimint_api::module::interconnect::ModuleInterconect; use minimint_api::module::ApiError; use minimint_api::FederationModule; use rand::CryptoRng; -use secp256k1_zkp::rand::RngCore; +use secp256k1::rand::RngCore; use serde_json::Value; pub struct MinimintInterconnect<'a, R: RngCore + CryptoRng> { diff --git a/minimint/src/lib.rs b/minimint/src/lib.rs index 674c738ad66..6b6fb78b177 100644 --- a/minimint/src/lib.rs +++ b/minimint/src/lib.rs @@ -5,6 +5,7 @@ use std::sync::{Arc, Mutex}; use hbbft::honey_badger::{HoneyBadger, Message}; use hbbft::NetworkInfo; +use minimint_core::modules::mint::Mint; use rand::rngs::OsRng; use rand::{CryptoRng, RngCore}; use tokio::sync::Notify; @@ -87,7 +88,7 @@ impl MinimintServer { let threshold = cfg.peers.len() - cfg.max_faulty(); let mint = - minimint_core::modules::mint::Mint::new(cfg.mint.clone(), threshold, database.clone()); + Mint::new(cfg.mint.clone(), threshold, database.clone()); let wallet = Wallet::new_with_bitcoind(cfg.wallet.clone(), database.clone(), bitcoind) .await diff --git a/minimint/src/net/api.rs b/minimint/src/net/api.rs index b49d095ed31..8ac7b4953e0 100644 --- a/minimint/src/net/api.rs +++ b/minimint/src/net/api.rs @@ -8,6 +8,7 @@ use minimint_api::{ FederationModule, TransactionId, }; use minimint_core::outcome::TransactionStatus; +use rand::rngs::OsRng; use std::fmt::Formatter; use std::sync::Arc; use tracing::debug; @@ -20,7 +21,7 @@ use jsonrpsee::{ #[derive(Clone)] struct State { - minimint: Arc>, + minimint: Arc>, } impl std::fmt::Debug for State { @@ -29,7 +30,7 @@ impl std::fmt::Debug for State { } } -pub async fn run_server(cfg: ServerConfig, minimint: Arc>) { +pub async fn run_server(cfg: ServerConfig, minimint: Arc>) { let state = State { minimint: minimint.clone(), }; @@ -68,7 +69,7 @@ fn attach_endpoints( endpoints: &'static [ApiEndpoint], base_name: Option<&str>, ) where - MinimintConsensus: AsRef, + MinimintConsensus: AsRef, M: Sync, { for endpoint in endpoints { @@ -97,11 +98,11 @@ fn attach_endpoints( } } -fn server_endpoints() -> &'static [ApiEndpoint>] { - const ENDPOINTS: &[ApiEndpoint>] = &[ +fn server_endpoints() -> &'static [ApiEndpoint>] { + const ENDPOINTS: &[ApiEndpoint>] = &[ api_endpoint! { "/transaction", - async |minimint: &MinimintConsensus, transaction: serde_json::Value| -> TransactionId { + async |minimint: &MinimintConsensus, transaction: serde_json::Value| -> TransactionId { // deserializing Transaction from json Value always fails // we need to convert it to string first let string = serde_json::to_string(&transaction).expect("encoding error"); @@ -117,7 +118,7 @@ fn server_endpoints() -> &'static [ApiEndpoint, tx_hash: TransactionId| -> TransactionStatus { + async |minimint: &MinimintConsensus, tx_hash: TransactionId| -> TransactionStatus { debug!(transaction = %tx_hash, "Recieved request"); let tx_status = minimint.transaction_status(tx_hash).ok_or_else(|| ApiError::not_found(String::from("transaction not found")))?; diff --git a/modules/minimint-ln/src/contracts/account.rs b/modules/minimint-ln/src/contracts/account.rs index 2bc1d995605..e5176aea3cb 100644 --- a/modules/minimint-ln/src/contracts/account.rs +++ b/modules/minimint-ln/src/contracts/account.rs @@ -1,12 +1,13 @@ use crate::contracts::{ContractId, IdentifyableContract}; -use bitcoin_hashes::Hash as BitcoinHash; +use bitcoin_hashes::Hash; use minimint_api::encoding::{Decodable, Encodable}; +use secp256k1::XOnlyPublicKey; use serde::{Deserialize, Serialize}; /// A generic contract to hold money in a pub key locked account #[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, Encodable, Decodable)] pub struct AccountContract { - pub key: secp256k1::XOnlyPublicKey, + pub key: XOnlyPublicKey, } impl IdentifyableContract for AccountContract { diff --git a/modules/minimint-ln/src/contracts/incoming.rs b/modules/minimint-ln/src/contracts/incoming.rs index 6075f7f98a1..19aad3b26f4 100644 --- a/modules/minimint-ln/src/contracts/incoming.rs +++ b/modules/minimint-ln/src/contracts/incoming.rs @@ -4,6 +4,7 @@ use bitcoin_hashes::Hash as BitcoinHash; use bitcoin_hashes::{borrow_slice_impl, hash_newtype, hex_fmt_impl, index_impl, serde_impl}; use minimint_api::encoding::{Decodable, DecodeError, Encodable}; use minimint_api::OutPoint; +use secp256k1::XOnlyPublicKey; use serde::{Deserialize, Serialize}; use std::io::Error; @@ -56,7 +57,7 @@ pub struct IncomingContract { /// the contract, allowing the offer creator to redeem their money. pub decrypted_preimage: DecryptedPreimage, /// Key that can unlock contract in case the decrypted preimage was invalid - pub gateway_key: secp256k1::XOnlyPublicKey, + pub gateway_key: XOnlyPublicKey, } /// The funded version of an [`IncomingContract`] contains the [`OutPoint`] of it's creation. Since @@ -93,7 +94,7 @@ hash_newtype!( /// A preimage in the context of incoming contracts. In this context it is a public key chosen /// by the creator of the [`IncomingContractOffer`]. #[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, Encodable, Decodable)] -pub struct Preimage(pub secp256k1::XOnlyPublicKey); +pub struct Preimage(pub XOnlyPublicKey); /// Threshold-encrypted [`Preimage`] #[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)] diff --git a/modules/minimint-ln/src/contracts/outgoing.rs b/modules/minimint-ln/src/contracts/outgoing.rs index 7848f4322ce..c140039a9d1 100644 --- a/modules/minimint-ln/src/contracts/outgoing.rs +++ b/modules/minimint-ln/src/contracts/outgoing.rs @@ -1,6 +1,7 @@ use crate::contracts::{ContractId, IdentifyableContract}; -use bitcoin_hashes::Hash as BitcoinHash; +use bitcoin_hashes::{sha256, Hash}; use minimint_api::encoding::{Decodable, Encodable}; +use secp256k1::XOnlyPublicKey; use serde::{Deserialize, Serialize}; /// Specialized smart contract for outgoing payments. @@ -11,13 +12,13 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, Encodable, Decodable)] pub struct OutgoingContract { /// Hash that can be used to spend the output before the timelock expires - pub hash: bitcoin_hashes::sha256::Hash, + pub hash: sha256::Hash, /// Public key of the LN gateway allowed to claim the HTLC before the timelock expires - pub gateway_key: secp256k1::XOnlyPublicKey, + pub gateway_key: XOnlyPublicKey, /// Block height at which the money will be spendable by the pubkey pub timelock: u32, /// Public key of the user that can claim the money back after the timelock expires - pub user_key: secp256k1::XOnlyPublicKey, + pub user_key: XOnlyPublicKey, // FIXME: use pruned, privacy friendly version without description etc. /// Invoice containing metadata on how to obtain the preimage pub invoice: String, diff --git a/modules/minimint-ln/src/lib.rs b/modules/minimint-ln/src/lib.rs index 81457a60185..b5b30742544 100644 --- a/modules/minimint-ln/src/lib.rs +++ b/modules/minimint-ln/src/lib.rs @@ -25,7 +25,7 @@ use crate::db::{ ProposeDecryptionShareKeyPrefix, }; use async_trait::async_trait; -use bitcoin_hashes::Hash as BitcoinHash; +use bitcoin_hashes::{sha256, Hash}; use itertools::Itertools; use minimint_api::db::batch::{BatchItem, BatchTx}; @@ -37,6 +37,7 @@ use minimint_api::module::{api_endpoint, ApiEndpoint, ApiError}; use minimint_api::{Amount, FederationModule, PeerId}; use minimint_api::{InputMeta, OutPoint}; use secp256k1::rand::{CryptoRng, RngCore}; +use secp256k1::XOnlyPublicKey; use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; use std::ops::Sub; @@ -465,8 +466,8 @@ impl FederationModule for LightningModule { let decrypted_preimage = if preimage.len() != 32 { DecryptedPreimage::Invalid - } else if incoming_contract.hash == bitcoin_hashes::sha256::Hash::hash(&preimage) { - if let Ok(preimage_key) = secp256k1::XOnlyPublicKey::from_slice(&preimage) { + } else if incoming_contract.hash == sha256::Hash::hash(&preimage) { + if let Ok(preimage_key) = XOnlyPublicKey::from_slice(&preimage) { DecryptedPreimage::Some(crate::contracts::incoming::Preimage(preimage_key)) } else { DecryptedPreimage::Invalid @@ -548,7 +549,7 @@ impl FederationModule for LightningModule { }, api_endpoint! { "/offer", - async |module: &LightningModule, payment_hash: bitcoin_hashes::sha256::Hash| -> IncomingContractOffer { + async |module: &LightningModule, payment_hash: sha256::Hash| -> IncomingContractOffer { let offer = module .get_offer(payment_hash) .ok_or_else(|| ApiError::not_found(String::from("Offer not found")))?; @@ -578,10 +579,7 @@ impl LightningModule { .verify_decryption_share(&share.0, &message.0) } - pub fn get_offer( - &self, - payment_hash: bitcoin_hashes::sha256::Hash, - ) -> Option { + pub fn get_offer(&self, payment_hash: sha256::Hash) -> Option { self.db .get_value(&OfferKey(payment_hash)) .expect("DB error") @@ -635,5 +633,5 @@ pub enum LightningModuleError { )] InsufficientIncomingFunding(Amount, Amount), #[error("No offer found for payment hash {0}")] - NoOffer(secp256k1::hashes::sha256::Hash), + NoOffer(sha256::Hash), } diff --git a/modules/minimint-ln/tests/ln_contracts.rs b/modules/minimint-ln/tests/ln_contracts.rs index e1ed4df8a4d..955a16a2e1c 100644 --- a/modules/minimint-ln/tests/ln_contracts.rs +++ b/modules/minimint-ln/tests/ln_contracts.rs @@ -1,4 +1,4 @@ -use bitcoin_hashes::Hash as BitcoinHash; +use bitcoin_hashes::{sha256, Hash as BitcoinHash}; use minimint_api::module::testing::FakeFed; use minimint_api::{Amount, OutPoint}; use minimint_ln::config::LightningModuleClientConfig; @@ -15,12 +15,13 @@ use minimint_ln::{ ContractInput, ContractOrOfferOutput, ContractOutput, LightningModule, LightningModuleError, OutputOutcome, }; -use secp256k1::KeyPair; +use secp256k1::rand::rngs::OsRng; +use secp256k1::{KeyPair, Secp256k1}; use std::sync::Arc; #[test_log::test(tokio::test)] async fn test_account() { - let mut rng = secp256k1::rand::rngs::OsRng::new().unwrap(); + let mut rng = OsRng::new().unwrap(); let mut fed = FakeFed::::new( 4, @@ -30,7 +31,7 @@ async fn test_account() { ) .await; - let ctx = secp256k1::Secp256k1::new(); + let ctx = Secp256k1::new(); let kp = KeyPair::new(&ctx, &mut rng); let contract = Contract::Account(AccountContract { key: kp.public_key(), @@ -69,7 +70,7 @@ async fn test_account() { #[test_log::test(tokio::test)] async fn test_outgoing() { - let mut rng = secp256k1::rand::rngs::OsRng::new().unwrap(); + let mut rng = OsRng::new().unwrap(); let mut fed = FakeFed::::new( 4, @@ -79,11 +80,11 @@ async fn test_outgoing() { ) .await; - let ctx = secp256k1::Secp256k1::new(); + let ctx = Secp256k1::new(); let gw_pk = KeyPair::new(&ctx, &mut rng).public_key(); let user_pk = KeyPair::new(&ctx, &mut rng).public_key(); let preimage = [42u8; 32]; - let hash = secp256k1::hashes::sha256::Hash::hash(&preimage); + let hash = sha256::Hash::hash(&preimage); let contract = Contract::Outgoing(OutgoingContract { hash, @@ -145,7 +146,7 @@ async fn test_outgoing() { #[test_log::test(tokio::test)] async fn test_incoming() { - let mut rng = secp256k1::rand::rngs::OsRng::new().unwrap(); + let mut rng = OsRng::new().unwrap(); let mut fed = FakeFed::::new( 4, @@ -155,12 +156,12 @@ async fn test_incoming() { ) .await; - let ctx = secp256k1::Secp256k1::new(); + let ctx = Secp256k1::new(); let gw_pk = KeyPair::new(&ctx, &mut rng).public_key(); let user_pk = KeyPair::new(&ctx, &mut rng).public_key(); let preimage = user_pk.serialize(); - let hash = secp256k1::hashes::sha256::Hash::hash(&preimage); + let hash = sha256::Hash::hash(&preimage); let offer = IncomingContractOffer { amount: Amount::from_sat(42), diff --git a/modules/minimint-mint/src/lib.rs b/modules/minimint-mint/src/lib.rs index f6e61e3a3f8..b350eeaca35 100644 --- a/modules/minimint-mint/src/lib.rs +++ b/modules/minimint-mint/src/lib.rs @@ -15,6 +15,7 @@ use minimint_api::module::ApiEndpoint; use minimint_api::{Amount, FederationModule, InputMeta, OutPoint, PeerId}; use rand::{CryptoRng, RngCore}; use rayon::iter::{IntoParallelIterator, ParallelBridge, ParallelIterator}; +use secp256k1_zkp::XOnlyPublicKey; use serde::{Deserialize, Serialize}; use std::collections::{BTreeMap, HashMap, HashSet}; @@ -76,7 +77,7 @@ pub struct Coin(pub CoinNonce, pub tbs::Signature); /// A unique coin nonce which is also a MuSig pub key so that transactions can be signed by the /// spent coin's spending keys to avoid mint frontrunning. #[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, Encodable, Decodable)] -pub struct CoinNonce(pub secp256k1_zkp::XOnlyPublicKey); +pub struct CoinNonce(pub XOnlyPublicKey); #[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize, Encodable, Decodable)] pub struct BlindToken(pub tbs::BlindedMessage); @@ -630,7 +631,7 @@ impl Coin { } /// Access the nonce as the public key to the spend key - pub fn spend_key(&self) -> &secp256k1_zkp::XOnlyPublicKey { + pub fn spend_key(&self) -> &XOnlyPublicKey { &self.0 .0 } } diff --git a/modules/minimint-wallet/Cargo.toml b/modules/minimint-wallet/Cargo.toml index afe1ea49372..ce65bbe4491 100644 --- a/modules/minimint-wallet/Cargo.toml +++ b/modules/minimint-wallet/Cargo.toml @@ -20,7 +20,6 @@ minimint-api = { path = "../../minimint-api" } minimint-derive = { path = "../../minimint-derive" } miniscript = { version = "7.0.0", features = [ "compiler", "use-serde" ] } rand = "0.6.0" -secp256k1 = { version = "0.22.1", features = [ "serde" ] } serde = { version = "1.0.118", features = [ "derive" ] } thiserror = "1.0.23" tokio = { version = "1.0.1", features = ["sync"], optional = true } diff --git a/modules/minimint-wallet/src/bitcoincore_rpc.rs b/modules/minimint-wallet/src/bitcoincore_rpc.rs index b6de706029b..4f9ba6cf298 100644 --- a/modules/minimint-wallet/src/bitcoincore_rpc.rs +++ b/modules/minimint-wallet/src/bitcoincore_rpc.rs @@ -3,13 +3,13 @@ use crate::{bitcoind::BitcoindRpc, Feerate}; use async_trait::async_trait; use bitcoin::{Block, BlockHash, Network, Transaction}; use bitcoincore_rpc::bitcoincore_rpc_json::EstimateMode; -use bitcoincore_rpc::{Auth, RpcApi}; +use bitcoincore_rpc::{Auth, RpcApi, Client}; use tracing::warn; pub fn bitcoind_gen(cfg: WalletConfig) -> impl Fn() -> Box { move || -> Box { Box::new( - bitcoincore_rpc::Client::new( + Client::new( &cfg.btc_rpc_address, Auth::UserPass(cfg.btc_rpc_user.clone(), cfg.btc_rpc_pass.clone()), ) @@ -19,7 +19,7 @@ pub fn bitcoind_gen(cfg: WalletConfig) -> impl Fn() -> Box { } #[async_trait] -impl BitcoindRpc for bitcoincore_rpc::Client { +impl BitcoindRpc for Client { async fn get_network(&self) -> Network { let network = minimint_api::task::block_in_place(|| self.get_blockchain_info()) .expect("Bitcoind returned an error"); @@ -37,12 +37,12 @@ impl BitcoindRpc for bitcoincore_rpc::Client { } async fn get_block_hash(&self, height: u64) -> BlockHash { - minimint_api::task::block_in_place(|| bitcoincore_rpc::RpcApi::get_block_hash(self, height)) + minimint_api::task::block_in_place(|| RpcApi::get_block_hash(self, height)) .expect("Bitcoind returned an error") } async fn get_block(&self, hash: &BlockHash) -> Block { - minimint_api::task::block_in_place(|| bitcoincore_rpc::RpcApi::get_block(self, hash)) + minimint_api::task::block_in_place(|| RpcApi::get_block(self, hash)) .expect("Bitcoind returned an error") } diff --git a/modules/minimint-wallet/src/config.rs b/modules/minimint-wallet/src/config.rs index 2af48779bee..79e928ec326 100644 --- a/modules/minimint-wallet/src/config.rs +++ b/modules/minimint-wallet/src/config.rs @@ -1,5 +1,6 @@ use crate::keys::CompressedPublicKey; use crate::{Feerate, PegInDescriptor}; +use bitcoin::secp256k1::{SecretKey, Secp256k1}; use bitcoin::secp256k1::rand::{CryptoRng, RngCore}; use bitcoin::Network; use minimint_api::config::GenerateConfig; @@ -13,7 +14,7 @@ pub struct WalletConfig { pub network: Network, pub peg_in_descriptor: PegInDescriptor, pub peer_peg_in_keys: BTreeMap, - pub peg_in_key: secp256k1::SecretKey, + pub peg_in_key: SecretKey, pub finalty_delay: u32, pub default_fee: Feerate, pub btc_rpc_address: String, @@ -37,7 +38,7 @@ impl GenerateConfig for WalletConfig { _params: &Self::Params, mut rng: impl RngCore + CryptoRng, ) -> (BTreeMap, Self::ClientConfig) { - let secp = secp256k1::Secp256k1::new(); + let secp = Secp256k1::new(); let btc_pegin_keys = peers .iter() diff --git a/modules/minimint-wallet/src/db.rs b/modules/minimint-wallet/src/db.rs index d5b3ea0eb45..f0cadb40f21 100644 --- a/modules/minimint-wallet/src/db.rs +++ b/modules/minimint-wallet/src/db.rs @@ -1,10 +1,10 @@ use crate::{ PendingPegOut, PendingTransaction, RoundConsensus, SpendableUTXO, UnsignedTransaction, }; +use bitcoin::secp256k1::ecdsa::Signature; use bitcoin::{BlockHash, OutPoint, Txid}; use minimint_api::db::DatabaseKeyPrefixConst; use minimint_api::encoding::{Decodable, Encodable}; -use secp256k1::ecdsa::Signature; const DB_PREFIX_BLOCK_HASH: u8 = 0x30; const DB_PREFIX_UTXO: u8 = 0x31; diff --git a/modules/minimint-wallet/src/keys.rs b/modules/minimint-wallet/src/keys.rs index b75536c8cc0..f4a8872ea77 100644 --- a/modules/minimint-wallet/src/keys.rs +++ b/modules/minimint-wallet/src/keys.rs @@ -1,18 +1,17 @@ use crate::tweakable::{Contract, Tweakable}; use bitcoin::hashes::Hash; -use bitcoin::secp256k1::{Secp256k1, Verification}; -use bitcoin::PublicKey; +use bitcoin::secp256k1::{PublicKey, Secp256k1, Verification}; use miniscript::{MiniscriptKey, ToPublicKey}; use serde::{Deserialize, Serialize}; use std::str::FromStr; #[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)] pub struct CompressedPublicKey { - pub key: secp256k1::PublicKey, + pub key: PublicKey, } impl CompressedPublicKey { - pub fn new(key: secp256k1::PublicKey) -> Self { + pub fn new(key: PublicKey) -> Self { CompressedPublicKey { key } } } @@ -30,11 +29,8 @@ impl MiniscriptKey for CompressedPublicKey { } impl ToPublicKey for CompressedPublicKey { - fn to_public_key(&self) -> PublicKey { - PublicKey { - compressed: true, - inner: self.key, - } + fn to_public_key(&self) -> bitcoin::PublicKey { + self.key.to_public_key() } fn hash_to_hash160(hash: &Self::Hash) -> bitcoin::hashes::hash160::Hash { @@ -49,11 +45,11 @@ impl std::fmt::Display for CompressedPublicKey { } impl FromStr for CompressedPublicKey { - type Err = secp256k1::Error; + type Err = bitcoin::secp256k1::Error; fn from_str(s: &str) -> Result { Ok(CompressedPublicKey { - key: secp256k1::PublicKey::from_str(s)?, + key: PublicKey::from_str(s)?, }) } } @@ -66,11 +62,14 @@ impl Tweakable for CompressedPublicKey { } } -impl From for bitcoin::PublicKey { +impl From for PublicKey { fn from(key: CompressedPublicKey) -> Self { - bitcoin::PublicKey { - compressed: true, - inner: key.key, - } + key.key + } +} + +impl Into for CompressedPublicKey { + fn into(self) -> bitcoin::PublicKey { + self.key.to_public_key() } } diff --git a/modules/minimint-wallet/src/lib.rs b/modules/minimint-wallet/src/lib.rs index d6d2c78c8c7..f370e222b4b 100644 --- a/modules/minimint-wallet/src/lib.rs +++ b/modules/minimint-wallet/src/lib.rs @@ -15,8 +15,8 @@ use crate::keys::CompressedPublicKey; use crate::tweakable::Tweakable; use crate::txoproof::{PegInProof, PegInProofError}; use async_trait::async_trait; -use bitcoin::hashes::{sha256, Hash as BitcoinHash, HashEngine, Hmac, HmacEngine}; -use bitcoin::secp256k1::{All, Secp256k1}; +use bitcoin::hashes::{sha256, Hash, HashEngine, Hmac, HmacEngine}; +use bitcoin::secp256k1::{ecdsa, All, Message, PublicKey, Secp256k1, SecretKey, self}; use bitcoin::util::psbt::raw::ProprietaryKey; use bitcoin::util::psbt::{Input, PartiallySignedTransaction}; use bitcoin::util::sighash::SighashCache; @@ -34,9 +34,8 @@ use minimint_api::module::ApiEndpoint; use minimint_api::{FederationModule, InputMeta, OutPoint, PeerId}; use minimint_derive::UnzipConsensus; use miniscript::psbt::PsbtExt; -use miniscript::{Descriptor, DescriptorTrait, TranslatePk2}; +use miniscript::{Descriptor, DescriptorTrait, ToPublicKey, TranslatePk2}; use rand::{CryptoRng, Rng, RngCore}; -use secp256k1::Message; use serde::{Deserialize, Serialize}; use std::ops::Sub; @@ -83,7 +82,7 @@ pub struct RoundConsensusItem { #[derive(Clone, Debug, Serialize, Deserialize, Encodable, Decodable)] pub struct PegOutSignatureItem { pub txid: Txid, - pub signature: Vec, + pub signature: Vec, } #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Encodable, Decodable)] @@ -133,8 +132,8 @@ pub struct UnsignedTransaction { struct StatelessWallet<'a> { descriptor: &'a Descriptor, - secret_key: &'a secp256k1::SecretKey, - secp: &'a secp256k1::Secp256k1, + secret_key: &'a SecretKey, + secp: &'a Secp256k1, } #[derive( @@ -430,7 +429,7 @@ impl FederationModule for Wallet { // We drop SIGHASH_ALL, because we always use that and it is only present in the // PSBT for compatibility with other tools. - secp256k1::ecdsa::Signature::from_der(&sig.to_vec()[..sig.to_vec().len() - 1]) + ecdsa::Signature::from_der(&sig.to_vec()[..sig.to_vec().len() - 1]) .expect("we serialized it ourselves that way") }) .collect::>(); @@ -1101,7 +1100,7 @@ impl<'a> StatelessWallet<'a> { .proprietary .get(&proprietary_tweak_key()) .expect("Malformed PSBT: expected tweak"); - let pub_key = secp256k1::PublicKey::from_secret_key(self.secp, &secret_key); + let pub_key = PublicKey::from_secret_key(self.secp, &secret_key); let tweak = { let mut hasher = HmacEngine::::new(&pub_key.serialize()[..]); @@ -1135,13 +1134,10 @@ impl<'a> StatelessWallet<'a> { .secp .sign_ecdsa(&Message::from_slice(&tx_hash[..]).unwrap(), &tweaked_secret); - psbt_input.partial_sigs.insert( - bitcoin::PublicKey { - compressed: true, - inner: secp256k1::PublicKey::from_secret_key(self.secp, &tweaked_secret), - }, - EcdsaSig::sighash_all(signature), - ); + let pubkey = PublicKey::from_secret_key(self.secp, &tweaked_secret); + psbt_input + .partial_sigs + .insert(pubkey.to_public_key(), EcdsaSig::sighash_all(signature)); } } @@ -1285,11 +1281,13 @@ mod tests { use std::str::FromStr; use bitcoin::hashes::Hash as BitcoinHash; + use bitcoin::secp256k1::Secp256k1; use bitcoin::{Address, Amount, OutPoint, TxOut}; use miniscript::descriptor::Wsh; use miniscript::policy::Concrete; use miniscript::psbt::PsbtExt; use miniscript::{Descriptor, DescriptorTrait, Segwitv0}; + use rand::rngs::OsRng; use crate::db::UTXOKey; use crate::keys::CompressedPublicKey; @@ -1302,8 +1300,8 @@ mod tests { fn sign_tx() { const CHANGE_TWEAK: [u8; 32] = [42u8; 32]; - let ctx = secp256k1::Secp256k1::new(); - let mut rng = rand::rngs::OsRng::new().unwrap(); + let ctx = Secp256k1::new(); + let mut rng = OsRng::new().unwrap(); let (sec_key, pub_key) = ctx.generate_keypair(&mut rng); let descriptor = Descriptor::Wsh( diff --git a/modules/minimint-wallet/src/tweakable.rs b/modules/minimint-wallet/src/tweakable.rs index b1051c3f32f..627d449341f 100644 --- a/modules/minimint-wallet/src/tweakable.rs +++ b/modules/minimint-wallet/src/tweakable.rs @@ -1,5 +1,5 @@ -use bitcoin::hashes::{sha256, Hash as BitcoinHash, Hmac, HmacEngine}; -use secp256k1::{Secp256k1, Verification}; +use bitcoin::hashes::{sha256, Hash, Hmac, HmacEngine}; +use bitcoin::secp256k1::{PublicKey, Secp256k1, Verification, XOnlyPublicKey}; use std::io::Write; /// An object that can be used as a ricardian contract to tweak a key @@ -14,7 +14,7 @@ pub trait Tweakable { fn tweak(&self, tweak: &Ctr, secp: &Secp256k1) -> Self; } -impl Tweakable for secp256k1::PublicKey { +impl Tweakable for PublicKey { fn tweak(&self, tweak: &Ctr, secp: &Secp256k1) -> Self { let mut hasher = HmacEngine::::new(&self.serialize()[..]); tweak.encode(&mut hasher).expect("hashing is infallible"); @@ -28,7 +28,7 @@ impl Tweakable for secp256k1::PublicKey { } } -impl Contract for secp256k1::PublicKey { +impl Contract for PublicKey { fn encode(&self, writer: &mut W) -> std::io::Result<()> { writer.write_all(&self.serialize()) } @@ -46,7 +46,7 @@ impl Contract for [u8; 32] { } } -impl Contract for secp256k1::XOnlyPublicKey { +impl Contract for XOnlyPublicKey { fn encode(&self, writer: &mut W) -> std::io::Result<()> { writer.write_all(&self.serialize()[..]) } diff --git a/modules/minimint-wallet/src/txoproof.rs b/modules/minimint-wallet/src/txoproof.rs index 4175134d803..5a8b5e580eb 100644 --- a/modules/minimint-wallet/src/txoproof.rs +++ b/modules/minimint-wallet/src/txoproof.rs @@ -1,10 +1,10 @@ use crate::keys::CompressedPublicKey; use crate::tweakable::{Contract, Tweakable}; +use bitcoin::secp256k1::{Secp256k1, Verification, XOnlyPublicKey}; use bitcoin::util::merkleblock::PartialMerkleTree; use bitcoin::{BlockHash, BlockHeader, OutPoint, Transaction, Txid}; use minimint_api::encoding::{Decodable, DecodeError, Encodable}; use miniscript::{Descriptor, DescriptorTrait, TranslatePk2}; -use secp256k1::{Secp256k1, Verification}; use serde::de::Error; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::hash::Hash; @@ -23,7 +23,7 @@ pub struct PegInProof { transaction: Transaction, // Check that the idx is in range output_idx: u32, - tweak_contract_key: secp256k1::XOnlyPublicKey, + tweak_contract_key: XOnlyPublicKey, } #[derive(Clone, Debug)] @@ -91,7 +91,7 @@ impl PegInProof { txout_proof: TxOutProof, transaction: Transaction, output_idx: u32, - tweak_contract_key: secp256k1::XOnlyPublicKey, + tweak_contract_key: XOnlyPublicKey, ) -> Result { // TODO: remove redundancy with serde validation if !txout_proof.contains_tx(transaction.txid()) { @@ -143,11 +143,11 @@ impl PegInProof { self.txout_proof.block() } - pub fn tweak_contract_key(&self) -> &secp256k1::XOnlyPublicKey { + pub fn tweak_contract_key(&self) -> &XOnlyPublicKey { &self.tweak_contract_key } - pub fn identity(&self) -> (secp256k1::XOnlyPublicKey, bitcoin::Txid) { + pub fn identity(&self) -> (XOnlyPublicKey, bitcoin::Txid) { (self.tweak_contract_key, self.transaction.txid()) } @@ -258,7 +258,7 @@ impl Decodable for PegInProof { txout_proof: TxOutProof::consensus_decode(&mut d)?, transaction: Transaction::consensus_decode(&mut d)?, output_idx: u32::consensus_decode(&mut d)?, - tweak_contract_key: secp256k1::XOnlyPublicKey::consensus_decode(&mut d)?, + tweak_contract_key: XOnlyPublicKey::consensus_decode(&mut d)?, }; validate_peg_in_proof(&slf).map_err(DecodeError::from_err)?;