Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lift dependencies up to top of file, remove redundant secp/zkp libraries #234

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/cli/src/main.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion client/client-lib/Cargo.toml
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions 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;
Expand Down Expand Up @@ -29,7 +29,7 @@ pub trait FederationApi: Send + Sync {
async fn fetch_contract(&self, contract: ContractId) -> Result<ContractAccount>;

/// Fetch preimage offer for incoming lightning payments
async fn fetch_offer(&self, payment_hash: Sha256Hash) -> Result<IncomingContractOffer>;
async fn fetch_offer(&self, payment_hash: sha256::Hash) -> Result<IncomingContractOffer>;

/// Fetch the current consensus block height (trailing actual block height)
async fn fetch_consensus_block_height(&self) -> Result<u64>;
Expand Down Expand Up @@ -134,7 +134,7 @@ impl<C: ClientT + Send + Sync> FederationApi for WsFederationApi<C> {
self.request("/wallet/block_height", ()).await
}

async fn fetch_offer(&self, payment_hash: Sha256Hash) -> Result<IncomingContractOffer> {
async fn fetch_offer(&self, payment_hash: sha256::Hash) -> Result<IncomingContractOffer> {
self.request("/ln/offer", payment_hash).await
}
}
Expand Down
21 changes: 8 additions & 13 deletions client/client-lib/src/clients/gateway.rs
Expand Up @@ -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;

Expand All @@ -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,
}

Expand Down Expand Up @@ -72,7 +73,7 @@ impl GatewayClient {
config,
db,
api,
secp: secp256k1_zkp::Secp256k1::new(),
secp: Secp256k1::new(),
},
}
}
Expand Down Expand Up @@ -108,8 +109,7 @@ impl GatewayClient {
&self,
account: &OutgoingContractAccount,
) -> Result<PaymentParameters> {
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);
Expand Down Expand Up @@ -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)> {
Expand All @@ -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(),
Expand Down Expand Up @@ -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)]
Expand All @@ -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))
}
}
6 changes: 3 additions & 3 deletions 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<KeyPair>,
Expand Down Expand Up @@ -39,7 +39,7 @@ impl TransactionBuilder {

pub fn build<R: RngCore + CryptoRng>(
mut self,
secp: &secp256k1_zkp::Secp256k1<secp256k1_zkp::All>,
secp: &Secp256k1<All>,
mut rng: R,
) -> Transaction {
if !self.keys.is_empty() {
Expand Down
6 changes: 3 additions & 3 deletions client/client-lib/src/clients/user.rs
Expand Up @@ -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};
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions client/client-lib/src/lib.rs
Expand Up @@ -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;
Expand All @@ -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<secp256k1_zkp::All>,
secp: &'a Secp256k1<All>,
}

struct OwnedClientContext<C> {
config: C,
db: Box<dyn Database>,
api: Box<dyn FederationApi>,
secp: secp256k1_zkp::Secp256k1<secp256k1_zkp::All>,
secp: Secp256k1<All>,
}

impl<CO> OwnedClientContext<CO> {
Expand Down
6 changes: 3 additions & 3 deletions 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,
}
12 changes: 7 additions & 5 deletions client/client-lib/src/ln/mod.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -238,7 +240,7 @@ mod tests {

async fn fetch_offer(
&self,
_payment_hash: bitcoin::hashes::sha256::Hash,
_payment_hash: sha256::Hash,
) -> crate::api::Result<IncomingContractOffer> {
unimplemented!();
}
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down