-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply Shield Wallet Interaction Part 2 #355
Changes from 1 commit
1a52f44
fdea748
9015925
e7fd884
54e9967
20cbf2a
25188e9
4d8fc6d
f2babd1
12704e2
58fc8cb
4007bae
0ce2b35
5529715
15e0558
252f2bd
3489880
3ac37f3
ebde221
be7fdca
f567ae3
79ef5a7
c36de91
6e8a14a
30ebbdc
f24f196
383d131
0de346a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use crate::prelude::*; | ||
use radix_engine_interface::blueprints::access_controller::{ | ||
AccessControllerInitiateRecoveryAsPrimaryInput as ScryptoAccessControllerInitiateRecoveryAsPrimaryInput, | ||
AccessControllerInitiateRecoveryAsRecoveryInput as ScryptoAccessControllerInitiateRecoveryAsRecoveryInput, | ||
AccessControllerQuickConfirmPrimaryRoleRecoveryProposalInput as ScryptoAccessControllerQuickConfirmPrimaryRoleRecoveryProposalInput, | ||
AccessControllerQuickConfirmRecoveryRoleRecoveryProposalInput as ScryptoAccessControllerQuickConfirmRecoveryRoleRecoveryProposalInput, | ||
AccessControllerTimedConfirmRecoveryInput as ScryptoAccessControllerTimedConfirmRecoveryInput, | ||
}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct AccessControllerFactorsAndTimeInput { | ||
rule_set: ScryptoRuleSet, | ||
timed_recovery_delay_in_minutes: u32, | ||
} | ||
|
||
impl AccessControllerFactorsAndTimeInput { | ||
pub fn new( | ||
Check warning on line 17 in crates/transaction/manifests/src/manifests_security_shield/access_controller_factors_and_time_input.rs
|
||
security_structure_of_factor_instances: &SecurityStructureOfFactorInstances, | ||
) -> Self { | ||
let rule_set = ScryptoRuleSet::from( | ||
security_structure_of_factor_instances | ||
.matrix_of_factors | ||
.clone(), | ||
Check warning on line 23 in crates/transaction/manifests/src/manifests_security_shield/access_controller_factors_and_time_input.rs
|
||
); | ||
|
||
let timed_recovery_delay_in_minutes = | ||
security_structure_of_factor_instances | ||
Check warning on line 27 in crates/transaction/manifests/src/manifests_security_shield/access_controller_factors_and_time_input.rs
|
||
.timed_recovery_delay_in_minutes(); | ||
|
||
Self { | ||
rule_set, | ||
timed_recovery_delay_in_minutes, | ||
} | ||
} | ||
} | ||
|
||
impl From<&AccessControllerFactorsAndTimeInput> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MINOR rust style point: It's rare (although certainly not unheard of) to create a Often an alternative is a From impl on the type itself, and a |
||
for ScryptoAccessControllerInitiateRecoveryAsRecoveryInput | ||
{ | ||
fn from(value: &AccessControllerFactorsAndTimeInput) -> Self { | ||
Check warning on line 40 in crates/transaction/manifests/src/manifests_security_shield/access_controller_factors_and_time_input.rs
|
||
Self { | ||
rule_set: value.rule_set.clone(), | ||
timed_recovery_delay_in_minutes: Some( | ||
Check warning on line 43 in crates/transaction/manifests/src/manifests_security_shield/access_controller_factors_and_time_input.rs
|
||
value.timed_recovery_delay_in_minutes, | ||
), | ||
} | ||
} | ||
} | ||
|
||
impl From<&AccessControllerFactorsAndTimeInput> | ||
for ScryptoAccessControllerInitiateRecoveryAsPrimaryInput | ||
{ | ||
fn from(value: &AccessControllerFactorsAndTimeInput) -> Self { | ||
Check warning on line 53 in crates/transaction/manifests/src/manifests_security_shield/access_controller_factors_and_time_input.rs
|
||
Self { | ||
rule_set: value.rule_set.clone(), | ||
timed_recovery_delay_in_minutes: Some( | ||
Check warning on line 56 in crates/transaction/manifests/src/manifests_security_shield/access_controller_factors_and_time_input.rs
|
||
value.timed_recovery_delay_in_minutes, | ||
), | ||
} | ||
} | ||
} | ||
|
||
impl From<&AccessControllerFactorsAndTimeInput> | ||
for ScryptoAccessControllerQuickConfirmRecoveryRoleRecoveryProposalInput | ||
{ | ||
fn from(value: &AccessControllerFactorsAndTimeInput) -> Self { | ||
Check warning on line 66 in crates/transaction/manifests/src/manifests_security_shield/access_controller_factors_and_time_input.rs
|
||
Self { | ||
rule_set: value.rule_set.clone(), | ||
timed_recovery_delay_in_minutes: Some( | ||
Check warning on line 69 in crates/transaction/manifests/src/manifests_security_shield/access_controller_factors_and_time_input.rs
|
||
value.timed_recovery_delay_in_minutes, | ||
), | ||
} | ||
} | ||
} | ||
|
||
impl From<&AccessControllerFactorsAndTimeInput> | ||
for ScryptoAccessControllerQuickConfirmPrimaryRoleRecoveryProposalInput | ||
{ | ||
fn from(value: &AccessControllerFactorsAndTimeInput) -> Self { | ||
Check warning on line 79 in crates/transaction/manifests/src/manifests_security_shield/access_controller_factors_and_time_input.rs
|
||
Self { | ||
rule_set: value.rule_set.clone(), | ||
timed_recovery_delay_in_minutes: Some( | ||
Check warning on line 82 in crates/transaction/manifests/src/manifests_security_shield/access_controller_factors_and_time_input.rs
|
||
value.timed_recovery_delay_in_minutes, | ||
), | ||
} | ||
} | ||
} | ||
|
||
impl From<&AccessControllerFactorsAndTimeInput> | ||
for ScryptoAccessControllerTimedConfirmRecoveryInput | ||
{ | ||
fn from(value: &AccessControllerFactorsAndTimeInput) -> Self { | ||
Check warning on line 92 in crates/transaction/manifests/src/manifests_security_shield/access_controller_factors_and_time_input.rs
|
||
Self { | ||
rule_set: value.rule_set.clone(), | ||
timed_recovery_delay_in_minutes: Some( | ||
Check warning on line 95 in crates/transaction/manifests/src/manifests_security_shield/access_controller_factors_and_time_input.rs
|
||
value.timed_recovery_delay_in_minutes, | ||
), | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
#![allow(dead_code)] | ||
use profile_supporting_types::AnySecurifiedEntity; | ||
|
||
use crate::prelude::*; | ||
use std::ops::Deref; | ||
|
||
use profile_supporting_types::AnySecurifiedEntity; | ||
|
||
pub trait TransactionManifestSecurifySecurifiedEntity: | ||
TransactionManifestSetRolaKey | ||
|
@@ -10,61 +11,76 @@ | |
securified_entity: AnySecurifiedEntity, | ||
input: TransactionManifestApplySecurityShieldSecurifiedInput, | ||
) -> Result<TransactionManifest>; | ||
|
||
fn _update_shield_exercising_recovery_and_explicit_confirmation( | ||
builder: ScryptoTransactionManifestBuilder, | ||
securified_entity: &AnySecurifiedEntity, | ||
input: &TransactionManifestApplySecurityShieldSecurifiedInput, | ||
) -> Result<ScryptoTransactionManifestBuilder> { | ||
todo!() | ||
} | ||
} | ||
|
||
impl TransactionManifestSecurifySecurifiedEntity for TransactionManifest { | ||
fn apply_security_shield_for_securified_entity( | ||
Check warning on line 17 in crates/transaction/manifests/src/manifests_security_shield/manifests_securify_shield_securified_entity.rs
|
||
securified_entity: AnySecurifiedEntity, | ||
input: TransactionManifestApplySecurityShieldSecurifiedInput, | ||
) -> Result<Self> { | ||
let TransactionManifestApplySecurityShieldSecurifiedInput { | ||
security_structure_of_factor_instances, | ||
apply_shield_manifest_kind: kind, | ||
} = input.clone(); | ||
Check warning on line 24 in crates/transaction/manifests/src/manifests_security_shield/manifests_securify_shield_securified_entity.rs
|
||
|
||
let entity_address = securified_entity.entity.address(); | ||
Check warning on line 26 in crates/transaction/manifests/src/manifests_security_shield/manifests_securify_shield_securified_entity.rs
|
||
|
||
let mut builder = ScryptoTransactionManifestBuilder::new(); | ||
// ACCESS_CONTROLLER_CREATE_PROOF_IDENT | ||
let mut builder = TransactionManifest::produce_owner_badge( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does:
|
||
ScryptoTransactionManifestBuilder::new(), | ||
&securified_entity.entity, | ||
Check warning on line 31 in crates/transaction/manifests/src/manifests_security_shield/manifests_securify_shield_securified_entity.rs
|
||
); | ||
|
||
let access_controller_address = securified_entity | ||
.securified_entity_control | ||
.access_controller_address; | ||
Check warning on line 36 in crates/transaction/manifests/src/manifests_security_shield/manifests_securify_shield_securified_entity.rs
|
||
|
||
CyonAlexRDX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let factors_and_time_input = &AccessControllerFactorsAndTimeInput::new( | ||
&security_structure_of_factor_instances, | ||
Check warning on line 39 in crates/transaction/manifests/src/manifests_security_shield/manifests_securify_shield_securified_entity.rs
|
||
); | ||
|
||
use TransactionManifestApplySecurityShieldKindSelector::*; | ||
builder = match kind { | ||
PrimaryAndRecoveryWithExplicitConfirmation => Self::_update_shield_exercising_recovery_and_explicit_confirmation(builder, &securified_entity, &input)?, | ||
PrimaryAndRecoveryWithTimedAutoConfirm => todo!(), | ||
PrimaryAndExplicitConfirmation => todo!(), | ||
PrimaryWithTimedAutoConfirm => todo!(), | ||
RecoveryAndExplicitConfirmation => todo!(), | ||
RecoveryWithTimedAutoConfirm => todo!(), | ||
}; | ||
// INITIATE RECOVERY | ||
let (init_method, init_input) = | ||
kind.input_for_initialization(factors_and_time_input); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depending on For details see |
||
builder = builder.call_method( | ||
access_controller_address.scrypto(), | ||
init_method, | ||
(init_input.deref(),), | ||
Check warning on line 48 in crates/transaction/manifests/src/manifests_security_shield/manifests_securify_shield_securified_entity.rs
|
||
); | ||
|
||
// CONFIRM RECOVERY | ||
// TODO: for timed, should we really call it here, now? Should | ||
// we not call it AFTER the time has elapsed??? | ||
let (confirm_method, confirm_input) = | ||
kind.input_for_confirm(factors_and_time_input); | ||
builder = builder.call_method( | ||
access_controller_address.scrypto(), | ||
confirm_method, | ||
CyonAlexRDX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(confirm_input.deref(),), | ||
Check warning on line 59 in crates/transaction/manifests/src/manifests_security_shield/manifests_securify_shield_securified_entity.rs
|
||
); | ||
|
||
// Set Rola Key | ||
let should_set_rola_key = security_structure_of_factor_instances | ||
.authentication_signing_factor_instance | ||
!= securified_entity | ||
CyonAlexRDX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.current_authentication_signing_factor_instance(); | ||
Check warning on line 66 in crates/transaction/manifests/src/manifests_security_shield/manifests_securify_shield_securified_entity.rs
|
||
|
||
if should_set_rola_key { | ||
if kind.can_set_rola_key() { | ||
builder = TransactionManifest::set_rola_key( | ||
builder, | ||
&security_structure_of_factor_instances | ||
.authentication_signing_factor_instance, | ||
&entity_address, | ||
Check warning on line 74 in crates/transaction/manifests/src/manifests_security_shield/manifests_securify_shield_securified_entity.rs
|
||
); | ||
} else { | ||
return Err(CommonError::Unknown); // TODO: new error variant | ||
Check warning on line 77 in crates/transaction/manifests/src/manifests_security_shield/manifests_securify_shield_securified_entity.rs
|
||
} | ||
} | ||
|
||
let manifest = TransactionManifest::sargon_built( | ||
builder, | ||
securified_entity.network_id(), | ||
Check warning on line 83 in crates/transaction/manifests/src/manifests_security_shield/manifests_securify_shield_securified_entity.rs
|
||
); | ||
|
||
// N.B. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is fine, although it's generally better to lock a fee of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Harder to modify later There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@dhedey Wallet has logic to include the cost of the lock fee instruction in the total transaction fee |
||
|
@@ -74,154 +90,6 @@ | |
// after user has selected account to pay in wallet GUI. | ||
// (and as usual also call `modify_manifest_lock_fee`) | ||
|
||
Ok(manifest) | ||
Check warning on line 93 in crates/transaction/manifests/src/manifests_security_shield/manifests_securify_shield_securified_entity.rs
|
||
} | ||
} | ||
|
||
impl TransactionManifestApplySecurityShieldKindSelector { | ||
fn can_exercise_primary_role(&self) -> bool { | ||
match self { | ||
Self::PrimaryAndRecoveryWithExplicitConfirmation => true, | ||
Self::PrimaryAndRecoveryWithTimedAutoConfirm => true, | ||
Self::PrimaryAndExplicitConfirmation => true, | ||
Self::PrimaryWithTimedAutoConfirm => true, | ||
Self::RecoveryAndExplicitConfirmation => false, | ||
Self::RecoveryWithTimedAutoConfirm => false, | ||
} | ||
} | ||
|
||
fn can_set_rola_key(&self) -> bool { | ||
self.can_exercise_primary_role() | ||
} | ||
|
||
fn should_confirm_recovery_with_explicit(&self) -> bool { | ||
match self { | ||
Self::PrimaryAndRecoveryWithExplicitConfirmation => true, | ||
Self::PrimaryAndRecoveryWithTimedAutoConfirm => false, | ||
Self::PrimaryAndExplicitConfirmation => true, | ||
Self::PrimaryWithTimedAutoConfirm => false, | ||
Self::RecoveryAndExplicitConfirmation => true, | ||
Self::RecoveryWithTimedAutoConfirm => false, | ||
} | ||
} | ||
|
||
fn should_confirm_recovery_with_time(&self) -> bool { | ||
match self { | ||
Self::PrimaryAndRecoveryWithExplicitConfirmation => false, | ||
Self::PrimaryAndRecoveryWithTimedAutoConfirm => true, | ||
Self::PrimaryAndExplicitConfirmation => false, | ||
Self::PrimaryWithTimedAutoConfirm => true, | ||
Self::RecoveryAndExplicitConfirmation => false, | ||
Self::RecoveryWithTimedAutoConfirm => true, | ||
} | ||
} | ||
|
||
fn should_confirm_recovery(&self) -> bool { | ||
self.should_confirm_recovery_with_explicit() | ||
|| self.should_confirm_recovery_with_time() | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub enum TransactionManifestApplySecurityShieldKindSelector { | ||
/// (Primary Recovery Confirmation) | ||
PrimaryAndRecoveryWithExplicitConfirmation, | ||
|
||
/// (Primary Recovery Time) | ||
PrimaryAndRecoveryWithTimedAutoConfirm, | ||
|
||
/// (Primary Confirmation) | ||
PrimaryAndExplicitConfirmation, | ||
|
||
/// (Primary Time) ‼️ REQUIRES "Dugong" ‼️ | ||
PrimaryWithTimedAutoConfirm, | ||
|
||
/// (Recovery Confirmation) | ||
RecoveryAndExplicitConfirmation, | ||
|
||
/// (Recovery Time) | ||
RecoveryWithTimedAutoConfirm, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct TransactionManifestApplySecurityShieldAnyInput { | ||
pub security_structure_of_factor_instances: | ||
SecurityStructureOfFactorInstances, | ||
pub apply_shield_manifest_kind: | ||
Option<TransactionManifestApplySecurityShieldKindSelector>, | ||
} | ||
impl TransactionManifestApplySecurityShieldAnyInput { | ||
fn new( | ||
security_structure_of_factor_instances: | ||
SecurityStructureOfFactorInstances, | ||
apply_shield_manifest_kind: impl Into< | ||
Option<TransactionManifestApplySecurityShieldKindSelector>, | ||
>, | ||
) -> Self { | ||
Self { | ||
security_structure_of_factor_instances, | ||
apply_shield_manifest_kind: apply_shield_manifest_kind.into(), | ||
} | ||
} | ||
pub fn for_securified( | ||
security_structure_of_factor_instances: | ||
SecurityStructureOfFactorInstances, | ||
apply_shield_manifest_kind: TransactionManifestApplySecurityShieldKindSelector, | ||
) -> Self { | ||
Self::new( | ||
security_structure_of_factor_instances, | ||
apply_shield_manifest_kind, | ||
) | ||
} | ||
pub fn as_securified( | ||
&self, | ||
) -> Result<TransactionManifestApplySecurityShieldSecurifiedInput> { | ||
let apply_shield_manifest_kind = self | ||
.apply_shield_manifest_kind | ||
.clone() | ||
.ok_or(CommonError::Unknown)?; // TODO: replace with proper error | ||
Ok(TransactionManifestApplySecurityShieldSecurifiedInput { | ||
security_structure_of_factor_instances: self | ||
.security_structure_of_factor_instances | ||
.clone(), | ||
apply_shield_manifest_kind, | ||
}) | ||
} | ||
pub fn for_unsecurified( | ||
security_structure_of_factor_instances: | ||
SecurityStructureOfFactorInstances, | ||
) -> Self { | ||
Self::new(security_structure_of_factor_instances, None) | ||
} | ||
|
||
pub fn as_unsecurified( | ||
&self, | ||
) -> Result<TransactionManifestApplySecurityShieldUnsecurifiedInput> { | ||
Ok(TransactionManifestApplySecurityShieldUnsecurifiedInput { | ||
security_structure_of_factor_instances: self | ||
.security_structure_of_factor_instances | ||
.clone(), | ||
}) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct TransactionManifestApplySecurityShieldSecurifiedInput { | ||
pub security_structure_of_factor_instances: | ||
SecurityStructureOfFactorInstances, | ||
pub apply_shield_manifest_kind: | ||
TransactionManifestApplySecurityShieldKindSelector, | ||
} | ||
|
||
impl TransactionManifestApplySecurityShieldSecurifiedInput { | ||
pub fn new( | ||
security_structure_of_factor_instances: | ||
SecurityStructureOfFactorInstances, | ||
apply_shield_manifest_kind: TransactionManifestApplySecurityShieldKindSelector, | ||
) -> Self { | ||
Self { | ||
security_structure_of_factor_instances, | ||
apply_shield_manifest_kind, | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shared type to create:
AccessControllerInitiateRecoveryAsPrimaryInput
AccessControllerInitiateRecoveryAsRecoveryInput
AccessControllerQuickConfirmPrimaryRoleRecoveryProposalInput
AccessControllerQuickConfirmRecoveryRoleRecoveryProposalInput
AccessControllerTimedConfirmRecoveryInput
Input to
call_method
instruction, usingSecurityStructureOfFactorInstances
- which isInto<RuleSet>
(and time u32).