2025-08-12 16:55:56 -03:00
|
|
|
use crate::{PrivateKey, PublicKey, Signature, public_transaction::Message};
|
2025-08-10 14:10:11 -03:00
|
|
|
|
2025-08-12 10:16:04 -03:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
2025-08-10 14:10:11 -03:00
|
|
|
pub struct WitnessSet {
|
|
|
|
|
pub(crate) signatures_and_public_keys: Vec<(Signature, PublicKey)>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl WitnessSet {
|
|
|
|
|
pub fn for_message(message: &Message, private_keys: &[&PrivateKey]) -> Self {
|
2025-08-12 15:20:35 -03:00
|
|
|
let message_bytes = message.to_bytes();
|
2025-08-10 14:10:11 -03:00
|
|
|
let signatures_and_public_keys = private_keys
|
|
|
|
|
.iter()
|
2025-08-13 01:33:11 -03:00
|
|
|
.map(|&key| (Signature::new(key, &message_bytes), PublicKey::new_from_private_key(key)))
|
2025-08-10 14:10:11 -03:00
|
|
|
.collect();
|
|
|
|
|
Self {
|
|
|
|
|
signatures_and_public_keys,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-11 20:38:29 -03:00
|
|
|
pub fn is_valid_for(&self, message: &Message) -> bool {
|
2025-08-12 15:20:35 -03:00
|
|
|
let message_bytes = message.to_bytes();
|
2025-08-11 20:22:41 -03:00
|
|
|
for (signature, public_key) in self.iter_signatures() {
|
2025-08-12 16:55:56 -03:00
|
|
|
if !signature.is_valid_for(&message_bytes, public_key) {
|
2025-08-11 20:22:41 -03:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
true
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-10 14:10:11 -03:00
|
|
|
pub fn iter_signatures(&self) -> impl Iterator<Item = &(Signature, PublicKey)> {
|
|
|
|
|
self.signatures_and_public_keys.iter()
|
|
|
|
|
}
|
|
|
|
|
}
|