-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |