Skip to content

Commit

Permalink
Expose make interaction for applying shields
Browse files Browse the repository at this point in the history
  • Loading branch information
micbakos-rdx committed Jan 30, 2025
1 parent c349ccf commit ba75143
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,23 @@ impl OsShieldApplying for SargonOS {
IdentifiedVecOf<AccountOrPersona>,
FactorInstancesProviderOutcome,
)> {
if !entity_addresses
.iter()
.map(|a| self.entity_by_address(*a))
.all(|r| match r {
Ok(e) => e.get_provisional().is_none(),
Err(_) => false,
})
{
return Err(
CommonError::CannotSecurifyEntityHasProvisionalSecurityConfig,
);
}
// TODO change when queue is introduced
// `CannotSecurifyEntityHasProvisionalSecurityConfig` should be returned when
// 1. entity's shield is in provisional state
// 2. interaction is in the queue.

// if !entity_addresses
// .iter()
// .map(|a| self.entity_by_address(*a))
// .all(|r| match r {
// Ok(e) => e.get_provisional().is_none(),
// Err(_) => false,
// })
// {
// return Err(
// CommonError::CannotSecurifyEntityHasProvisionalSecurityConfig,
// );
// }

let outcome = self._provide_instances_using_shield_for_entities_by_address_without_consuming_cache(
shield.clone(),
Expand Down Expand Up @@ -181,11 +186,11 @@ impl OsShieldApplying for SargonOS {
InstancesInCacheConsumer,
FactorInstancesProviderOutcome,
)> {
if !entities.iter().all(|a| a.get_provisional().is_none()) {
return Err(
CommonError::CannotSecurifyEntityHasProvisionalSecurityConfig,
);
}
// if !entities.iter().all(|a| a.get_provisional().is_none()) {
// return Err(
// CommonError::CannotSecurifyEntityHasProvisionalSecurityConfig,
// );
// }
let addresses_of_entities = entities
.iter()
.map(|e| e.address())
Expand Down Expand Up @@ -651,6 +656,7 @@ mod tests {
);
}

#[ignore = "Should be tested when queue is integrated"]
#[actix_rt::test]
async fn test_one_unsecurified_account_has_provisional_fails() {
// ARRANGE
Expand Down Expand Up @@ -687,6 +693,7 @@ mod tests {
);
}

#[ignore = "Should be tested when queue is integrated"]
#[actix_rt::test]
async fn test_one_securified_account_has_provisional_fails() {
// ARRANGE
Expand Down Expand Up @@ -729,6 +736,7 @@ mod tests {
);
}

#[ignore = "Should be tested when queue is integrated"]
#[actix_rt::test]
async fn test_one_unsecurified_persona_has_provisional_fails() {
// ARRANGE
Expand Down Expand Up @@ -766,6 +774,7 @@ mod tests {
);
}

#[ignore = "Should be tested when queue is integrated"]
#[actix_rt::test]
async fn test_one_securified_persona_has_provisional_fails() {
// ARRANGE
Expand Down Expand Up @@ -810,6 +819,7 @@ mod tests {
);
}

#[ignore = "Should be tested when queue is integrated"]
#[actix_rt::test]
async fn test_one_unsecurified_account_of_many_entities_has_provisional_fails_the_rest_unchanged(
) {
Expand Down Expand Up @@ -862,6 +872,7 @@ mod tests {
assert_eq!(os.personas_on_current_network().unwrap(), personas); // assert unchanged
}

#[ignore = "Should be tested when queue is integrated"]
#[actix_rt::test]
async fn test_low_level_one_account_has_provisional_fails() {
// ARRANGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ impl TransactionManifestSecurifyUnsecurifiedEntity for TransactionManifest {
security_structure_of_factor_instances
.assert_has_entity_kind(entity_address.get_entity_kind())?;

// Set Rola Key
builder = TransactionManifest::set_rola_key(
builder,
&security_structure_of_factor_instances
.authentication_signing_factor_instance,
&entity_address,
);

// Securify the entity which will return an entity owner badge onto the worktop.
let (mut builder, owner_badge_bucket) = Self::put_owner_badge_in_bucket(
ScryptoTransactionManifestBuilder::new(),
Expand Down Expand Up @@ -82,14 +90,6 @@ impl TransactionManifestSecurifyUnsecurifiedEntity for TransactionManifest {
)
};

// Set Rola Key
builder = TransactionManifest::set_rola_key(
builder,
&security_structure_of_factor_instances
.authentication_signing_factor_instance,
&entity_address,
);

let manifest = TransactionManifest::sargon_built(
builder,
entity_address.network_id(),
Expand Down
2 changes: 2 additions & 0 deletions crates/uniffi/uniffi_SPLIT_ME/src/system/sargon_os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod entities;
mod pre_authorization;
mod profile_state_holder;
mod sargon_os;
mod sargon_os_apply_security_shield_interaction;
mod sargon_os_derive_public_keys;
mod sargon_os_entities_linked_to_factor_source;
mod sargon_os_factors;
Expand All @@ -17,6 +18,7 @@ pub use entities::*;
pub use pre_authorization::*;
pub use profile_state_holder::*;
pub use sargon_os::*;
pub use sargon_os_apply_security_shield_interaction::*;
pub use sargon_os_derive_public_keys::*;
pub use sargon_os_entities_linked_to_factor_source::*;
pub use sargon_os_factors::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::prelude::*;
use sargon::OsApplySecurityShieldInteraction;

#[uniffi::export]
impl SargonOS {
pub async fn make_interaction_for_applying_security_shield(
&self,
security_shield_id: SecurityStructureID,
addresses: Vec<AddressOfAccountOrPersona>,
) -> Result<DappToWalletInteractionBatchOfTransactions> {
self.wrapped
.make_interaction_for_applying_security_shield(
security_shield_id.into(),
IndexSet::from_iter(
addresses.iter().map(|a| a.into_internal()),
),
)
.await
.into_result()
}
}
22 changes: 11 additions & 11 deletions fixtures/transaction/create_access_controller_for_account.rtm
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
SET_METADATA
Address("account_rdx128dtethfy8ujrsfdztemyjk0kvhnah6dafr57frz85dcw2c8z0td87")
"owner_keys"
Enum<143u8>(
Array<Enum>(
Enum<1u8>(
Bytes("cb3f6086cd08a1d0ab10139a9c6d191783edb534059f7b4716dc5d239e")
)
)
)
;
CALL_METHOD
Address("account_rdx128dtethfy8ujrsfdztemyjk0kvhnah6dafr57frz85dcw2c8z0td87")
"securify"
Expand Down Expand Up @@ -92,15 +103,4 @@ CREATE_ACCESS_CONTROLLER
Enum<1u8>(
AddressReservation("reservation1")
)
;
SET_METADATA
Address("account_rdx128dtethfy8ujrsfdztemyjk0kvhnah6dafr57frz85dcw2c8z0td87")
"owner_keys"
Enum<143u8>(
Array<Enum>(
Enum<1u8>(
Bytes("cb3f6086cd08a1d0ab10139a9c6d191783edb534059f7b4716dc5d239e")
)
)
)
;
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
SET_METADATA
Address("account_rdx128dtethfy8ujrsfdztemyjk0kvhnah6dafr57frz85dcw2c8z0td87")
"owner_keys"
Enum<143u8>(
Array<Enum>(
Enum<1u8>(
Bytes("cb3f6086cd08a1d0ab10139a9c6d191783edb534059f7b4716dc5d239e")
)
)
)
;
CALL_METHOD
Address("account_rdx128dtethfy8ujrsfdztemyjk0kvhnah6dafr57frz85dcw2c8z0td87")
"securify"
Expand Down Expand Up @@ -93,17 +104,6 @@ CREATE_ACCESS_CONTROLLER
AddressReservation("reservation1")
)
;
SET_METADATA
Address("account_rdx128dtethfy8ujrsfdztemyjk0kvhnah6dafr57frz85dcw2c8z0td87")
"owner_keys"
Enum<143u8>(
Array<Enum>(
Enum<1u8>(
Bytes("cb3f6086cd08a1d0ab10139a9c6d191783edb534059f7b4716dc5d239e")
)
)
)
;
CALL_METHOD
Address("accesscontroller_rdx1cdgmx69r8532n7e0w6sgs8lrctmdzsmylak75a0khwmp55pau5p8pr")
"create_proof"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
SET_METADATA
Address("account_rdx128dtethfy8ujrsfdztemyjk0kvhnah6dafr57frz85dcw2c8z0td87")
"owner_keys"
Enum<143u8>(
Array<Enum>(
Enum<1u8>(
Bytes("cb3f6086cd08a1d0ab10139a9c6d191783edb534059f7b4716dc5d239e")
)
)
)
;
CALL_METHOD
Address("account_rdx128dtethfy8ujrsfdztemyjk0kvhnah6dafr57frz85dcw2c8z0td87")
"securify"
Expand Down Expand Up @@ -93,17 +104,6 @@ CREATE_ACCESS_CONTROLLER
AddressReservation("reservation1")
)
;
SET_METADATA
Address("account_rdx128dtethfy8ujrsfdztemyjk0kvhnah6dafr57frz85dcw2c8z0td87")
"owner_keys"
Enum<143u8>(
Array<Enum>(
Enum<1u8>(
Bytes("cb3f6086cd08a1d0ab10139a9c6d191783edb534059f7b4716dc5d239e")
)
)
)
;
CALL_METHOD
Address("account_rdx12y02nen8zjrq0k0nku98shjq7n05kvl3j9m5d3a6cpduqwzgmenjq7")
"withdraw"
Expand Down
22 changes: 11 additions & 11 deletions fixtures/transaction/create_access_controller_for_persona.rtm
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
SET_METADATA
Address("identity_rdx12tw6rt9c4l56rz6p866e35tmzp556nymxmpj8hagfewq82kspctdyw")
"owner_keys"
Enum<143u8>(
Array<Enum>(
Enum<1u8>(
Bytes("675506ad8d7ce4c602cb06c593c0f10e1cc4dcdf2c4144360ef33ebeef")
)
)
)
;
CALL_METHOD
Address("identity_rdx12tw6rt9c4l56rz6p866e35tmzp556nymxmpj8hagfewq82kspctdyw")
"securify"
Expand Down Expand Up @@ -86,15 +97,4 @@ CREATE_ACCESS_CONTROLLER
Enum<1u8>(
AddressReservation("reservation1")
)
;
SET_METADATA
Address("identity_rdx12tw6rt9c4l56rz6p866e35tmzp556nymxmpj8hagfewq82kspctdyw")
"owner_keys"
Enum<143u8>(
Array<Enum>(
Enum<1u8>(
Bytes("675506ad8d7ce4c602cb06c593c0f10e1cc4dcdf2c4144360ef33ebeef")
)
)
)
;

0 comments on commit ba75143

Please sign in to comment.