Skip to content

Commit

Permalink
Create multi_sig.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Dec 8, 2024
1 parent ea6446a commit ef93adb
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/security/multi_sig.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use ed25519_dalek::{Keypair, Signature, Signer, Verifier};
use std::collections::HashMap;

pub struct MultiSigWallet {
pub threshold: u32,
pub public_keys: Vec<ed25519_dalek::PublicKey>,
pub signatures: HashMap<ed25519_dalek::PublicKey, Signature>,
}

impl MultiSigWallet {
pub fn new(threshold: u32, public_keys: Vec<ed25519_dalek::PublicKey>) -> Self {
Self {
threshold,
public_keys,
signatures: HashMap::new(),
}
}

pub fn add_signature(&mut self, public_key: ed25519_dalek::PublicKey, signature: Signature) {
self.signatures.insert(public_key, signature);
}

pub fn verify(&self, message: &[u8]) -> bool {
let mut valid_signatures = 0;
for (public_key, signature) in &self.signatures {
if public_key.verify(message, signature).is_ok() {
valid_signatures += 1;
}
}
valid_signatures >= self.threshold
}
}

0 comments on commit ef93adb

Please sign in to comment.