Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Jan 30, 2025
1 parent 0909f49 commit 9a6e841
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 34 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/crypto/addresses/src/address/address_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ macro_rules! address_union {
PartialEq,
Eq,
Hash,
EnumAsInner,
enum_as_inner::EnumAsInner,
derive_more::Display,
derive_more::Debug,
SerializeDisplay,
Expand Down
1 change: 1 addition & 0 deletions crates/crypto/addresses/src/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub use account_address::*;
pub use address::*;
pub use address_format::*;
pub use address_of_account_or_persona::*;
pub use address_union::*;
pub use component_address::*;
pub use entity_address::*;
pub use identity_address::*;
Expand Down
5 changes: 4 additions & 1 deletion crates/system/os/factors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ edition = "2021"
[dependencies]
# === SARGON CRATES ===
prelude = { workspace = true }
sargon-os = { path = "../../../system/os/os" }
sargon-os = { workspace = true }
error = { workspace = true }
addresses = { workspace = true }
profile = { workspace = true }
interactors = { workspace = true }
drivers = { workspace = true }
Expand All @@ -28,7 +29,9 @@ async-trait = { workspace = true }
derive_more = { workspace = true }
enum-as-inner = { workspace = true }
log = { workspace = true }
paste = { workspace = true }
preinterpret = { workspace = true }
pretty_assertions = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_with = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::sync::{Mutex, OnceLock};

use crate::prelude::*;
use addresses::address_union;
use radix_connect::DappToWalletInteractionBatchOfTransactions;

#[async_trait::async_trait]
Expand Down Expand Up @@ -39,33 +42,39 @@ pub trait OsApplySecurityShieldInteraction {
) -> Result<DappToWalletInteractionBatchOfTransactions>;
}

static HACKY_TMP_ENTITIES_APPLYING_SHIELD: RwLock<
IndexMap<EntityApplyingShieldAddress, TransactionManifest>,
> = RwLock::new(IndexMap::new());
address_union!(
enum EntityApplyingShieldAddress: accessController, account, identity
);

fn hacky_tmp_entities_applying_shield(
) -> &'static Mutex<IndexMap<EntityApplyingShieldAddress, TransactionManifest>>
{
static ARRAY: OnceLock<
Mutex<IndexMap<EntityApplyingShieldAddress, TransactionManifest>>,
> = OnceLock::new();
ARRAY.get_or_init(|| Mutex::new(IndexMap::new()))
}

/// Called by `make_interaction_for_applying_security_shield` to set the entities
fn hacky_tmp_set_entities_applying_shield(
entities: IndexMap<EntityApplyingShieldAddress, TransactionManifest>,
) {
*HACKY_TMP_ENTITIES_APPLYING_SHIELD.write().unwrap() = entities;
*hacky_tmp_entities_applying_shield().lock().unwrap() = entities;
}

pub fn hacky_tmp_get_entities_applying_shield(

Check warning on line 65 in crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs

View check run for this annotation

Codecov / codecov/patch

crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs#L65

Added line #L65 was not covered by tests
) -> IndexMap<EntityApplyingShieldAddress, TransactionManifest> {
HACKY_TMP_ENTITIES_APPLYING_SHIELD.read().unwrap()
hacky_tmp_entities_applying_shield().lock().unwrap().clone()

Check warning on line 67 in crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs

View check run for this annotation

Codecov / codecov/patch

crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs#L67

Added line #L67 was not covered by tests
}

address_union!(
enum EntityApplyingShieldAddress: accessController, account, identity
);
impl EntityApplyingShieldAddress {
fn from_unsecurified_entity(entity: &AnyUnsecurifiedEntity) -> Self {
match entity.entity {
AccountOrPersona::AccountEntity(account) => {
Self::AccountAddress(account.address())
match &entity.entity {
AccountOrPersona::AccountEntity(ref account) => {
Self::Account(account.address())
}
AccountOrPersona::PersonaEntity(persona) => {
Self::IdentityAddress(persona.address())
AccountOrPersona::PersonaEntity(ref persona) => {
Self::Identity(persona.address())
}
}
}
Expand All @@ -74,11 +83,11 @@ impl EntityApplyingShieldAddress {
// TODO: when RET PR https://github.com/radixdlt/radix-engine-toolkit/pull/132
// is merge remove this and use static analisys using RET to get this.
fn __hacky_tmp_using_local_global_state_extract_address_of_entity_updating_shield(

Check warning on line 85 in crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs

View check run for this annotation

Codecov / codecov/patch

crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs#L85

Added line #L85 was not covered by tests
manifest: TransactionManifest,
manifest: &TransactionManifest,
) -> Result<EntityApplyingShieldAddress> {
let lookup = hacky_tmp_get_entities_applying_shield();
let address = lookup.iter().find_map(|(address, m)| {
if m == &manifest {
if m == manifest {
Some(address.clone())

Check warning on line 91 in crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs

View check run for this annotation

Codecov / codecov/patch

crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs#L88-L91

Added lines #L88 - L91 were not covered by tests
} else {
None

Check warning on line 93 in crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs

View check run for this annotation

Codecov / codecov/patch

crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs#L93

Added line #L93 was not covered by tests
Expand All @@ -90,17 +99,17 @@ fn __hacky_tmp_using_local_global_state_extract_address_of_entity_updating_shiel
// TODO: when RET PR https://github.com/radixdlt/radix-engine-toolkit/pull/132
// impl this
fn _extract_address_of_entity_updating_shield(

Check warning on line 101 in crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs

View check run for this annotation

Codecov / codecov/patch

crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs#L101

Added line #L101 was not covered by tests
manifest: TransactionManifest,
manifest: &TransactionManifest,
) -> Result<EntityApplyingShieldAddress> {
todo!("cannot be implemented yet, awaiting #132 RET PR")
}

// TODO: when RET PR https://github.com/radixdlt/radix-engine-toolkit/pull/132
// is merge remove this and use static analisys using RET to get this.
pub fn extract_address_of_entity_updating_shield(

Check warning on line 109 in crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs

View check run for this annotation

Codecov / codecov/patch

crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs#L109

Added line #L109 was not covered by tests
manifest: TransactionManifest,
manifest: &TransactionManifest,
) -> Result<EntityApplyingShieldAddress> {
__hacky_tmp_using_local_global_state_extract_address_of_entity(manifest)
__hacky_tmp_using_local_global_state_extract_address_of_entity_updating_shield(manifest)

Check warning on line 112 in crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs

View check run for this annotation

Codecov / codecov/patch

crates/system/os/factors/src/apply_security_shield/sargon_os_apply_security_shield_interaction.rs#L112

Added line #L112 was not covered by tests
}

#[async_trait::async_trait]
Expand All @@ -118,7 +127,7 @@ impl OsApplySecurityShieldInteraction for SargonOS {
.await?;

let mut manifests_for_entity =
IndexMap::<EntityApplyingShieldAddress, TransacionManifest>::new();
IndexMap::<EntityApplyingShieldAddress, TransactionManifest>::new();

let manifests_for_unsecurified = entities_with_provisional
.unsecurified_erased()
Expand All @@ -130,7 +139,7 @@ impl OsApplySecurityShieldInteraction for SargonOS {
e.clone(),
derived.clone()
).inspect(|m| {
manifests_for_entity.insert(EntityApplyingShieldAddress::from_unsecurified_entity(&e), m)
manifests_for_entity.insert(EntityApplyingShieldAddress::from_unsecurified_entity(&e), m.clone());
}).map(UnvalidatedTransactionManifest::from)
}).collect::<Result<Vec<UnvalidatedTransactionManifest>>>()?;

Expand All @@ -145,7 +154,7 @@ impl OsApplySecurityShieldInteraction for SargonOS {
derived.clone(),
RolesExercisableInTransactionManifestCombination::manifest_end_user_gets_to_preview()
).inspect(|m| {
manifests_for_entity.insert(e.securified_entity_control.access_controller_address, m)
manifests_for_entity.insert(EntityApplyingShieldAddress::AccessController(e.securified_entity_control.access_controller_address), m.clone());
})
.map(UnvalidatedTransactionManifest::from).unwrap()
}).collect_vec();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use enum_as_inner::EnumAsInner;
use factor_instances_provider::address_union;
use serde_json::value::Index;

use crate::prelude::*;

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PayerOfTransaction {
/// `None` is invalid if `entity_applying_shield` is a Persona.
/// Some(Account) if `entity_applying_shield` is an Account means "use this other account instead"
Expand Down Expand Up @@ -61,17 +59,22 @@ pub trait BatchApplySecurityShieldSigning {
) -> Result<IndexSet<TransactionIntentHash>>;
}


#[async_trait::async_trait]
impl BatchApplySecurityShieldSigning for SargonOS {
async fn sign_and_enqueue_batch_of_transactions_applying_security_shield(
&self,
manifest_and_payer_tuples: IndexSet<PayerOfTransaction>,
) -> Result<IndexSet<TransactionIntentHash>> {
let manifest_and_payer_tuples = manifest_and_payer_tuples.into_iter().map(|t| {
let address_of_ac_or_entity_applying_shield = extract_address_of_entity_updating_shield(&t.manifest)?;

}).collect::<Result<IndexSet<SecurityShieldApplication>>>()?;
let manifest_and_payer_tuples = manifest_and_payer_tuples

Check warning on line 68 in crates/system/os/factors/src/apply_security_shield_payload_to_sign.rs

View check run for this annotation

Codecov / codecov/patch

crates/system/os/factors/src/apply_security_shield_payload_to_sign.rs#L68

Added line #L68 was not covered by tests
.into_iter()
.map(|t| {
let address_of_ac_or_entity_applying_shield =
extract_address_of_entity_updating_shield(&t.manifest)?;

Check warning on line 72 in crates/system/os/factors/src/apply_security_shield_payload_to_sign.rs

View check run for this annotation

Codecov / codecov/patch

crates/system/os/factors/src/apply_security_shield_payload_to_sign.rs#L70-L72

Added lines #L70 - L72 were not covered by tests
todo!()
})
.collect::<Result<Vec<SecurityShieldApplication>>>()?;

todo!()
}
}

Expand Down Expand Up @@ -142,7 +145,7 @@ pub enum SecurityShieldApplicationForSecurifiedEntity {
///
/// Essentially holds a manifest for exercising the primary role,
/// to create an AccessController with factors specified in the shield.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Clone, PartialEq, Eq, derive_more::Debug)]
pub struct SecurityShieldApplicationForUnsecurifiedAccount {
#[allow(dead_code)]
#[doc(hidden)]
Expand Down Expand Up @@ -183,12 +186,13 @@ impl SecurityShieldApplicationForUnsecurifiedAccount {
paying_account: impl Into<Option<Account>>,
modified_manifest: TransactionManifest,
) -> Self {
let paying_account = paying_account.into();
if let Some(payer) = paying_account.as_ref() {
assert_ne!(payer.address(), address_of_account_applying_shield.address(), "Specify None as payer if it is the same as address_of_account_applying_shield");
assert_ne!(payer.address(), account_applying_shield.entity.address(), "Specify None as payer if it is the same as address_of_account_applying_shield");

Check warning on line 191 in crates/system/os/factors/src/apply_security_shield_payload_to_sign.rs

View check run for this annotation

Codecov / codecov/patch

crates/system/os/factors/src/apply_security_shield_payload_to_sign.rs#L189-L191

Added lines #L189 - L191 were not covered by tests
}

Self {
hidden: HiddenConstructor::new(),
hidden: HiddenConstructor,
account_applying_shield,
paying_account,
modified_manifest,
Expand Down
1 change: 1 addition & 0 deletions crates/system/os/factors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub mod prelude {
pub use crate::sargon_os_entities_linked_to_factor_source::*;
pub use crate::sargon_os_security_structures::*;

pub use addresses::prelude::*;
pub use clients::prelude::*;
pub use factor_instances_provider::prelude::*;
pub use key_derivation_traits::prelude::*;
Expand Down

0 comments on commit 9a6e841

Please sign in to comment.