lssa/nssa/src/public_transaction/witness_set.rs

36 lines
1.1 KiB
Rust
Raw Normal View History

use serde::{Deserialize, Serialize};
use crate::{PrivateKey, PublicKey, Signature, public_transaction::Message};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
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-11 20:22:41 -03:00
let message_bytes = message.message_to_bytes();
let signatures_and_public_keys = private_keys
.iter()
.map(|&key| (Signature::new(key, &message_bytes), PublicKey::new(key)))
.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-11 20:22:41 -03:00
let message_bytes = message.message_to_bytes();
for (signature, public_key) in self.iter_signatures() {
if !signature.is_valid_for(&message_bytes, &public_key) {
return false;
}
}
true
}
pub fn iter_signatures(&self) -> impl Iterator<Item = &(Signature, PublicKey)> {
self.signatures_and_public_keys.iter()
}
}