diff --git a/Cargo.toml b/Cargo.toml index 3f4e8a7a..b7809f43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,11 +46,11 @@ tiny-keccak = { version = "2", features = ["keccak"] } bincode = { version = "1", optional = true } curve25519-dalek = { version = "3", features = ["serde"] } -ecdsa_fun = { git = "https://github.com/farcaster-project/secp256kfun.git", branch = "secp256k1/0.22", default-features = false, features = ["all"], optional = true } +ecdsa_fun = { version = "0.7", default-features = false, features = ["all"], optional = true } rand = { version = "0.8.4", optional = true } rand_alt = { package = "rand", version = "0.7.3", features = ["std"] } rand_chacha = { version = "0.3.1", optional = true } -secp256kfun = { git = "https://github.com/farcaster-project/secp256kfun.git", branch = "secp256k1/0.22", default-features = false, features = ["std", "serde", "libsecp_compat"], optional = true } +secp256kfun = { version = "0.7", default-features = false, features = ["std", "serde", "libsecp_compat"], optional = true } sha2 = { version = "0.9", optional = true } sha3 = "0.10" diff --git a/src/swap/btcxmr.rs b/src/swap/btcxmr.rs index 7c9b2d89..d6065012 100644 --- a/src/swap/btcxmr.rs +++ b/src/swap/btcxmr.rs @@ -24,11 +24,14 @@ use ecdsa_fun::{ fun::{Point, Scalar}, nonce, ECDSA, }; +// FIXME: when secp256kfun as new crates.io release #[cfg(feature = "experimental")] use rand::rngs::ThreadRng; #[cfg(feature = "experimental")] use rand_chacha::ChaCha20Rng; #[cfg(feature = "experimental")] +use secp256kfun::marker::*; +#[cfg(feature = "experimental")] use sha2::Sha256; #[cfg(feature = "experimental")] @@ -306,7 +309,12 @@ impl Sign for KeyManager { ) -> Result { let secret_key = self.get_or_derive_bitcoin_key(key)?; - let secret_key = Scalar::from(secret_key); + // FIXME: when new version is released on crates.io + // let secret_key = Scalar::from(secret_key); + let secret_key = Scalar::from_slice(&secret_key[..]) + .unwrap() + .mark::() + .expect("SecretKey is never zero"); let message_hash: &[u8; 32] = { use bitcoin::hashes::Hash; msg.as_inner() @@ -315,7 +323,12 @@ impl Sign for KeyManager { let nonce_gen = nonce::Synthetic::>::default(); let ecdsa = ECDSA::new(nonce_gen); - Ok(ecdsa.sign(&secret_key, message_hash).into()) + // FIXME + // Ok(ecdsa.sign(&secret_key, message_hash).into()) + Ok( + Signature::from_compact(ecdsa.sign(&secret_key, message_hash).to_bytes().as_ref()) + .unwrap(), + ) } fn verify_signature( @@ -343,8 +356,15 @@ impl EncSign for KeyManag let secret_key = self.get_or_derive_bitcoin_key(signing_key)?; let engine = Adaptor::::default(); - let secret_signing_key = Scalar::from(secret_key); - let encryption_key = Point::from(*encryption_key); + // FIXME + // let secret_signing_key = Scalar::from(secret_key); + let secret_signing_key = Scalar::from_slice(&secret_key[..]) + .unwrap() + .mark::() + .expect("SecretKey is never zero"); + // FIXME + // let encryption_key = Point::from(*encryption_key); + let encryption_key = Point::from_bytes(encryption_key.serialize()).unwrap(); let message_hash: &[u8; 32] = { use bitcoin::hashes::Hash; msg.as_inner() @@ -361,8 +381,11 @@ impl EncSign for KeyManag sig: &EncryptedSignature, ) -> Result<(), crypto::Error> { let engine = Adaptor::::default(); - let verification_key = Point::from(*signing_key); - let encryption_key = Point::from(*encryption_key); + // FIXME + // let verification_key = Point::from(*signing_key); + // let encryption_key = Point::from(*encryption_key); + let verification_key = Point::from_bytes(signing_key.serialize()).unwrap(); + let encryption_key = Point::from_bytes(encryption_key.serialize()).unwrap(); let message_hash: &[u8; 32] = { use bitcoin::hashes::Hash; msg.as_inner() @@ -394,9 +417,22 @@ impl EncSign for KeyManag .map_err(crypto::Error::new)?; let adaptor = Adaptor::::default(); - let decryption_key = Scalar::from(secret_key); - - Ok(adaptor.decrypt_signature(&decryption_key, sig).into()) + // FIXME + // let decryption_key = Scalar::from(secret_key); + let decryption_key = Scalar::from_slice(&secret_key[..]) + .unwrap() + .mark::() + .expect("SecretKey is never zero"); + + // FIXME + // Ok(adaptor.decrypt_signature(&decryption_key, sig).into()) + Ok(Signature::from_compact( + adaptor + .decrypt_signature(&decryption_key, sig) + .to_bytes() + .as_ref(), + ) + .unwrap()) } } @@ -410,11 +446,18 @@ impl RecoverSecret for KeyM sig: Signature, ) -> SecretKey { let adaptor = Adaptor::::default(); - let encryption_key = Point::from(*encryption_key); - let signature = ecdsa_fun::Signature::from(sig); + // FIXME + // let encryption_key = Point::from(*encryption_key); + //let signature = ecdsa_fun::Signature::from(sig); + let encryption_key = Point::from_bytes(encryption_key.serialize()).unwrap(); + let signature = ecdsa_fun::Signature::from_bytes(sig.serialize_compact()).unwrap(); match adaptor.recover_decryption_key(&encryption_key, &signature, &encrypted_sig) { - Some(decryption_key) => decryption_key.into(), + // FIXME + // Some(decryption_key) => decryption_key.into(), + Some(decryption_key) => { + SecretKey::from_slice(decryption_key.to_bytes().as_ref()).unwrap() + } None => panic!("signature is not the decryption of our original encrypted signature"), } } @@ -456,7 +499,9 @@ impl ProveCrossGroupDleq for KeyManager .point .decompress() .expect("Valid point to decompress"), - ecdsa_fun::fun::Point::from(*encryption_key), + // FIXME + //ecdsa_fun::fun::Point::from(*encryption_key), + Point::from_bytes(encryption_key.serialize()).unwrap(), ) } }