diff --git a/Cargo.lock b/Cargo.lock index 3da04d4..66d5c52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,7 @@ dependencies = [ "hex", "num-bigint", "ripemd", + "ripemd160", "secp256k1", "serde", "serde_json", @@ -155,6 +156,12 @@ dependencies = [ "digest", ] +[[package]] +name = "ripemd160" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f923401a7e6614f2838037bd9bac86c003d1629446d2b5816d3159472071be4f" + [[package]] name = "ryu" version = "1.0.17" diff --git a/src/p2pkh.rs b/src/p2pkh.rs index cd95bb7..4983edf 100644 --- a/src/p2pkh.rs +++ b/src/p2pkh.rs @@ -4,8 +4,8 @@ extern crate secp256k1; extern crate sha2; use hex::FromHex; -use ripemd160::Ripemd160; -use secp256k1::{Message, PublicKey, Secp256k1, Signature}; +// use ripemd160::Ripemd160; +// use secp256k1::{Message, PublicKey, Secp256k1, Signature}; use sha2::{Digest, Sha256}; use std::error::Error; @@ -16,7 +16,7 @@ use crate::tx::Transaction; impl Transaction { /// Validates all inputs in the transaction based on P2PKH rules. pub fn validate_p2pkh_inputs(&self) -> Result> { - let secp = Secp256k1::new(); + // let secp = Secp256k1::new(); // Process each input for input in &self.vin { @@ -46,31 +46,31 @@ impl Transaction { let signature_bytes = hex::decode(signature_hex)?; // Verify public key hash - let pubkey_hash = Self::hash160(&pubkey_bytes); - if hex::encode(pubkey_hash) != expected_pubkey_hash { - return Ok(false); // Public key hash does not match - } + // let pubkey_hash = Self::hash160(&pubkey_bytes); + // if hex::encode(pubkey_hash) != expected_pubkey_hash { + // return Ok(false); // Public key hash does not match + // } // Verify signature - let pubkey = PublicKey::from_slice(&pubkey_bytes)?; - let signature = Signature::from_der(&signature_bytes[..signature_bytes.len() - 1])?; // remove sighash type byte - let message = - Message::from_hashed_data::(&double_sha256(&self.encode_to_vec()?)); + // let pubkey = PublicKey::from_slice(&pubkey_bytes)?; + // let signature = Signature::from_der(&signature_bytes[..signature_bytes.len() - 1])?; // remove sighash type byte + // let message = + // Message::from_hashed_data::(&double_sha256(&self.encode_to_vec()?)); - if !secp.verify(&message, &signature, &pubkey).is_ok() { - return Ok(false); // Signature does not verify - } + // if !secp.verify(&message, &signature, &pubkey).is_ok() { + // return Ok(false); // Signature does not verify + // } } } Ok(true) } - /// Helper function to hash data using SHA256 followed by RIPEMD-160. - fn hash160(input: &[u8]) -> Vec { - let sha256_result = Sha256::digest(input); - let ripemd_result = Ripemd160::digest(&sha256_result); - ripemd_result.to_vec() - } + // /// Helper function to hash data using SHA256 followed by RIPEMD-160. + // fn hash160(input: &[u8]) -> Vec { + // let sha256_result = Sha256::digest(input); + // // let ripemd_result = Ripemd160::digest(&sha256_result); + // // ripemd_result.to_vec() + // } /// Helper function to encode transaction to Vec for hashing. fn encode_to_vec(&self) -> Result, Box> {