Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CyonAlexRDX committed Aug 29, 2024
1 parent 1e5768d commit 20fec99
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/derivation/collector/key_derivation_outcome.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use crate::prelude::*;

/// A collection of all `HierarchicalDeterministicFactorInstance`
/// (Public Keys) which were derived from the referenced
/// `FactorSource`s at the specified `DerivationPath`s
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct KeyDerivationOutcome {
pub factors_by_source:
IndexMap<FactorSourceIDFromHash, IndexSet<HierarchicalDeterministicFactorInstance>>,
}

impl KeyDerivationOutcome {
pub fn new(
factors_by_source: IndexMap<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;

pub trait FactorSourceReferencing: std::hash::Hash + PartialEq + Eq + Clone {
pub(crate) trait FactorSourceReferencing: std::hash::Hash + PartialEq + Eq + Clone {
fn factor_source_id(&self) -> FactorSourceIDFromHash;
}

Expand Down
2 changes: 1 addition & 1 deletion src/signing/petition_types/petition_factors_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use petition_factors_state::*;
use petition_factors_state_snapshot::*;
use petition_factors_sub_state::*;

pub use factor_source_referencing::*;
pub(crate) use factor_source_referencing::*;
pub use neglected_factor_instance::*;
pub use petition_factors::*;
pub use petition_factors_status::*;
12 changes: 3 additions & 9 deletions src/signing/petition_types/petition_of_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ pub(crate) struct PetitionTransaction {
pub for_entities: RefCell<HashMap<AddressOfAccountOrPersona, PetitionEntity>>,
}

#[derive(Clone, PartialEq, Eq)]
pub struct PetitionTransactionOutcome {
pub transaction_valid: bool,
pub signatures: IndexSet<HDSignature>,
pub neglected_factors: IndexSet<NeglectedFactor>,
}

impl PetitionTransaction {
pub(crate) fn new(
intent_hash: IntentHash,
Expand Down Expand Up @@ -62,11 +55,12 @@ impl PetitionTransaction {
.flat_map(|x| x.all_neglected_factor_sources())
.collect::<IndexSet<NeglectedFactor>>();

PetitionTransactionOutcome {
PetitionTransactionOutcome::new(
transaction_valid,
self.intent_hash.clone(),
signatures,
neglected_factors,
}
)
}

fn _all_factor_instances(&self) -> IndexSet<OwnedFactorInstance> {
Expand Down
4 changes: 4 additions & 0 deletions src/signing/signatures_outcome_types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
mod maybe_signed_transactions;
mod petition_transaction_outcome;
mod sign_with_factors_outcome;
mod signatures_outcome;

pub use maybe_signed_transactions::*;
pub(crate) use petition_transaction_outcome::*;
pub use sign_with_factors_outcome::*;
pub use signatures_outcome::*;
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use crate::prelude::*;

/// The outcome of collecting signatures for a specific
/// transasction - either valid or invalid - and a
/// set of collected signatues (might be empty) and
/// a set of neglected factors (might be empty).
#[derive(Clone, PartialEq, Eq)]
pub struct PetitionTransactionOutcome {
intent_hash: IntentHash,
pub transaction_valid: bool,
pub signatures: IndexSet<HDSignature>,
pub neglected_factors: IndexSet<NeglectedFactor>,
}

impl PetitionTransactionOutcome {
/// # Panics
/// Panics if the intent hash in any signatures does not
/// match `intent_hash`
pub fn new(
transaction_valid: bool,
intent_hash: IntentHash,
signatures: IndexSet<HDSignature>,
neglected_factors: IndexSet<NeglectedFactor>,
) -> Self {
assert!(
signatures.iter().all(|s| *s.intent_hash() == intent_hash),
"Discprenacy! Mismatching intent hash found in a signature."
);
Self {
intent_hash,
transaction_valid,
signatures,
neglected_factors,
}
}
}

#[cfg(test)]
mod tests {
use super::*;

type Sut = PetitionTransactionOutcome;

#[test]
#[should_panic(expected = "Discprenacy! Mismatching intent hash found in a signature.")]
fn panic() {
Sut::new(
true,
IntentHash::sample(),
IndexSet::from_iter([HDSignature::sample_other()]),
IndexSet::new(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,4 @@ impl SignWithFactorsOutcome {
pub fn user_skipped_factor(id: FactorSourceIDFromHash) -> Self {
Self::user_skipped_factors(IndexSet::from_iter([id]))
}

pub fn failure_with_factor(id: FactorSourceIDFromHash) -> Self {
Self::failure_with_factors(IndexSet::from_iter([id]))
}
}
2 changes: 0 additions & 2 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ mod invalid_transaction_if_neglected;
mod new_methods_on_sargon_types;
mod owned_types;
mod sargon_types;
mod sign_with_factor_source_or_sources_outcome;

pub(crate) use factor_sources_of_kind::*;
pub use hd_signature::*;
pub use hd_signature_input::*;
pub use invalid_transaction_if_neglected::*;
pub use owned_types::*;
pub use sargon_types::*;
pub use sign_with_factor_source_or_sources_outcome::*;

0 comments on commit 20fec99

Please sign in to comment.