Skip to content

Commit

Permalink
fix: make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
10d9e committed Dec 14, 2024
1 parent 4234750 commit b46a056
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions examples/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use quantum_bitcoin::Wallet;

fn main() {
// Create wallets using Secp256k1Algorithm
let wallet1: Wallet<Secp256k1Algorithm> = Wallet::new();
let wallet2: Wallet<Secp256k1Algorithm> = Wallet::new();
let wallet1: Wallet<Secp256k1Algorithm> = Wallet::default();
let wallet2: Wallet<Secp256k1Algorithm> = Wallet::default();

println!("Wallet 1 Address: {}", wallet1.get_address());
println!("Wallet 2 Address: {}", wallet2.get_address());
Expand Down
4 changes: 2 additions & 2 deletions examples/quantum_bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use quantum_bitcoin::Wallet;

fn main() {
// Create wallets using DilithiumAlgorithm
let wallet1: Wallet<DilithiumAlgorithm> = Wallet::new();
let wallet2: Wallet<DilithiumAlgorithm> = Wallet::new();
let wallet1: Wallet<DilithiumAlgorithm> = Wallet::default();
let wallet2: Wallet<DilithiumAlgorithm> = Wallet::default();

println!("Wallet 1 Address: {}", wallet1.get_address());
println!("Wallet 2 Address: {}", wallet2.get_address());
Expand Down
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ pub struct Wallet<A: SigningAlgorithm> {
public_key: A::PublicKey,
}

impl<A: SigningAlgorithm> Default for Wallet<A> {
fn default() -> Self {
Self::new()
}
}

impl<A: SigningAlgorithm> Wallet<A> {
pub fn new() -> Self {
let (private_key, public_key) = A::generate_keypair();
Expand Down Expand Up @@ -112,7 +118,7 @@ impl Block {
let target = "0".repeat(difficulty);
self.hash = self.calculate_hash(); // Ensure hash is initialized

while &self.hash[..difficulty.min(self.hash.len())] != target {
while self.hash[..difficulty.min(self.hash.len())] != target {
self.nonce += 1;
self.hash = self.calculate_hash();
}
Expand Down
8 changes: 4 additions & 4 deletions src/signing/dilithium.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::signing::SigningAlgorithm;
use pqcrypto_dilithium::dilithium2::*;
use pqcrypto_traits::sign::PublicKey as PublicKeyTrait;
use pqcrypto_dilithium::dilithium2::{keypair, open, sign, SecretKey};
use pqcrypto_traits::sign::PublicKey;
use pqcrypto_traits::sign::SignedMessage;

#[derive(Debug)]
pub struct DilithiumAlgorithm;

impl SigningAlgorithm for DilithiumAlgorithm {
type PrivateKey = pqcrypto_dilithium::dilithium2::SecretKey;
type PrivateKey = SecretKey;
type PublicKey = pqcrypto_dilithium::dilithium2::PublicKey;
type Signature = pqcrypto_dilithium::dilithium2::SignedMessage;

Expand All @@ -25,7 +25,7 @@ impl SigningAlgorithm for DilithiumAlgorithm {
message: &str,
signature: &Self::Signature,
) -> bool {
let verifiedmsg = open(&signature, &public_key).unwrap();
let verifiedmsg = open(signature, public_key).unwrap();
verifiedmsg == message.as_bytes()
}

Expand Down
3 changes: 1 addition & 2 deletions src/signing/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ impl SigningAlgorithm for Secp256k1Algorithm {
}

fn serialize_signature(signature: &Self::Signature) -> Vec<u8> {
let sig = signature.serialize_der();
sig.to_vec()
signature.serialize_der().to_vec()
}
}

0 comments on commit b46a056

Please sign in to comment.