Skip to content
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

Build many TXIntents for batch of TX applying Security Shield #349

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
d014fee
[no-ci] WIP
CyonAlexRDX Jan 29, 2025
0909f49
Merge branch 'main' into ac/payloads_to_sign_for_applying_shield_abw-…
Sajjon Jan 30, 2025
9a6e841
wip
Sajjon Jan 30, 2025
7b9b5a4
[no ci] WIP
Sajjon Jan 30, 2025
0302a1a
[no ci] wip
CyonAlexRDX Jan 30, 2025
7950810
[no ci] wip
CyonAlexRDX Jan 30, 2025
cd0467b
[no ci] WIP
Sajjon Jan 30, 2025
c85dacd
[no ci] wip
CyonAlexRDX Jan 30, 2025
bc6ef9c
[no ci] WIP
Sajjon Jan 30, 2025
2f0f6c6
[no ci] WIP
Sajjon Jan 30, 2025
0f7fc7f
[no ci] WIP
Sajjon Jan 30, 2025
a4a8a75
[no ci] WIP
Sajjon Jan 30, 2025
652a7db
[no ci] WIP
Sajjon Jan 31, 2025
4bbea33
[no ci] WIP
Sajjon Jan 31, 2025
911cb44
[no ci] wip
CyonAlexRDX Jan 31, 2025
4182575
[no ci] wip
CyonAlexRDX Jan 31, 2025
1119a7d
[no ci] wip
CyonAlexRDX Jan 31, 2025
d5f2d6f
Merge branch 'main' into ac/payloads_to_sign_for_applying_shield_abw-…
Sajjon Jan 31, 2025
6ce4a60
add XRD vault address to SecuredEntityControl
Sajjon Jan 31, 2025
dcfbe8b
Reject Shaku since hard to retrofit with SargonOS. Or at least I fail…
Sajjon Jan 31, 2025
bc1e5d2
Do Reject Shaku since hard to retrofit with SargonOS. Or at least I f…
CyonAlexRDX Jan 31, 2025
acfb3ab
[no ci] wip
CyonAlexRDX Jan 31, 2025
fb7a37b
[no ci] wip
CyonAlexRDX Jan 31, 2025
9ec9850
[no ci] WIP
Sajjon Feb 3, 2025
0af5525
[no ci] WIP
Sajjon Feb 3, 2025
66ddd5e
[no ci] WIP
Sajjon Feb 3, 2025
729a690
[no ci] wip
CyonAlexRDX Feb 3, 2025
2b6213f
[no ci] wip
CyonAlexRDX Feb 3, 2025
359f26f
[no ci] wip
CyonAlexRDX Feb 3, 2025
fe0b2bf
[no ci] WIP
Sajjon Feb 3, 2025
adae814
[no ci] WIP
Sajjon Feb 3, 2025
6dc55a7
[no ci] WIP
Sajjon Feb 3, 2025
7cb25a3
[no ci] WIP
Sajjon Feb 3, 2025
c1a9792
[no ci] WIP
Sajjon Feb 3, 2025
05903de
[no ci] WIP
Sajjon Feb 3, 2025
0376a9e
cleanup
Sajjon Feb 4, 2025
53c2d6d
lock fee against fee payer of unsecurified account if any
Sajjon Feb 4, 2025
c0de34e
merge
CyonAlexRDX Feb 4, 2025
b5fa66b
[no ci] wip
CyonAlexRDX Feb 4, 2025
248aabf
[no ci] wip
CyonAlexRDX Feb 5, 2025
73f94f9
Merge branch 'main' into ac/payloads_to_sign_for_applying_shield_abw-…
CyonAlexRDX Feb 5, 2025
8a9f610
[no ci] wip
CyonAlexRDX Feb 5, 2025
81e7197
[no ci] wip
CyonAlexRDX Feb 6, 2025
8b722bd
[no ci] WIP
Sajjon Feb 6, 2025
ad3bd25
[no ci] WIP
Sajjon Feb 6, 2025
5876363
ci
Sajjon Feb 6, 2025
0635a54
refactor mock driver
Sajjon Feb 6, 2025
9ea8d4f
fix typos
Sajjon Feb 6, 2025
99f3bfc
cleanup
Sajjon Feb 6, 2025
4d98bc2
test securified account
Sajjon Feb 6, 2025
99c7f59
[no ci] WIP
Sajjon Feb 6, 2025
63ae988
[no ci] wip
CyonAlexRDX Feb 6, 2025
9d09f71
doc and cleanup
Sajjon Feb 6, 2025
4601dc5
cleanup and doc more
Sajjon Feb 7, 2025
d72a8d7
[no ci] WIP
Sajjon Feb 7, 2025
04d523b
polish
CyonAlexRDX Feb 7, 2025
99baa0b
Merge branch 'main' into ac/payloads_to_sign_for_applying_shield_abw-…
Sajjon Feb 7, 2025
5b1f232
update links
Sajjon Feb 7, 2025
a5e2e68
more tests
CyonAlexRDX Feb 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[no ci] wip
  • Loading branch information
CyonAlexRDX committed Jan 30, 2025
commit 7950810646e59ee1e6d2b8c2e2aa8d4316d8dd21
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
use crate::prelude::*;

pub trait HasEntityAddress {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I did not use this, can remove...

fn address_erased(&self) -> AddressOfAccountOrPersona;
}

impl<T: IsBaseEntity> HasEntityAddress for T {
fn address_erased(&self) -> AddressOfAccountOrPersona {
self.address().into()
}
}

/// A trait bridging AccountOrPersona, Account and Persona.
pub trait IsBaseEntity:
HasEntityKindObjectSafe + IsNetworkAware + HasSecurityState
HasEntityKindObjectSafe + IsNetworkAware + HasSecurityState
{
type Address: IsBaseEntityAddress
+ PartialEq
Expand All @@ -14,6 +24,7 @@ pub trait IsBaseEntity:

fn address(&self) -> Self::Address;


/// An order set of `EntityFlag`s used to describe certain Off-ledger
/// user state about Accounts or Personas, such as if an entity is
/// marked as hidden or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ impl<E: IsBaseEntity + std::hash::Hash + Eq + Clone> Identifiable
}
}

impl<E: IsBaseEntity + std::hash::Hash + Eq + Clone> HasEntityAddress
for AbstractSecurifiedEntity<E>
{
fn address_erased(&self) -> AddressOfAccountOrPersona {
self.entity.address_erased()
}
}

impl<E: IsBaseEntity + std::hash::Hash + Eq + Clone> IsNetworkAware
for AbstractSecurifiedEntity<E>
{
Expand Down
10 changes: 10 additions & 0 deletions crates/profile/models/supporting-types/src/unsecurified_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ pub struct AbstractUnsecurifiedEntity<
pub provisional_securified_config: Option<ProvisionalSecurifiedConfig>,
}

impl<E: IsBaseEntity + std::hash::Hash + Eq + Clone> HasEntityAddress
for AbstractUnsecurifiedEntity<E>
where
E::Address: Into<AddressOfAccountOrPersona>,
{
fn address_erased(&self) -> AddressOfAccountOrPersona {
self.entity.address_erased()
}
}

impl<E: IsBaseEntity + std::hash::Hash + Eq + Clone> Identifiable
for AbstractUnsecurifiedEntity<E>
where
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ use enum_as_inner::EnumAsInner;

use crate::prelude::*;

impl HasEntityAddress for EntityApplyingShield {
fn address_erased(&self) -> AddressOfAccountOrPersona {
match self {
EntityApplyingShield::Securified(e) => e.address_erased(),
EntityApplyingShield::Unsecurified(e) => e.address_erased(),
}
}
}

#[derive(Clone, PartialEq, Eq, derive_more::Debug)]
pub struct AbstractShieldApplicationInputWithOrWithoutBalance<
Entity,
Entity: HasEntityAddress + Clone,
XrdBalance,
> {
#[allow(dead_code)]
Expand All @@ -30,15 +39,30 @@ pub struct AbstractShieldApplicationInputWithOrWithoutBalance<
_balance_of_entity_applying_shield: XrdBalance,
}

struct XrdBalanceOfEntity<Entity> {
impl<E: HasEntityAddress + Clone, X> HasEntityAddress
for AbstractShieldApplicationInputWithOrWithoutBalance<E, X>
{
fn address_erased(&self) -> AddressOfAccountOrPersona {
self.entity_applying_shield.address_erased()
}
}

struct XrdBalanceOfEntity<Entity: HasEntityAddress + Clone> {
pub entity: Entity,
pub balance: Decimal,
}
impl<Entity: HasEntityAddress + Clone> HasEntityAddress
for XrdBalanceOfEntity<Entity>
{
fn address_erased(&self) -> AddressOfAccountOrPersona {
self.entity.address_erased()
}
}

type AbstractShieldApplicationInput<Entity> =
AbstractShieldApplicationInputWithOrWithoutBalance<Entity, Decimal>;

impl<Entity> AbstractShieldApplicationInput<Entity> {
impl<Entity: HasEntityAddress + Clone> AbstractShieldApplicationInput<Entity> {
pub fn get_payer_and_balance(&self) -> Option<XrdBalanceOfEntity<Account>> {
self._payer.as_ref().map(|payer| XrdBalanceOfEntity {
entity: payer.clone(),
Expand All @@ -47,7 +71,6 @@ impl<Entity> AbstractShieldApplicationInput<Entity> {
.expect("Must be Some if payer is Some"),
})
}

pub fn get_entity_applying_shield_and_balance(
&self,
) -> XrdBalanceOfEntity<Entity> {
Expand Down Expand Up @@ -116,7 +139,26 @@ pub type SecurifiedAccountShieldApplicationInput =
pub type SecurifiedPersonaShieldApplicationInput =
AbstractShieldApplicationInput<SecurifiedPersona>;

impl<Entity> AbstractShieldApplicationInput<Entity> {
impl ShieldApplicationInputWithoutXrdBalance {
fn new(
payer: impl Into<Option<Account>>,
entity_applying_shield: EntityApplyingShield,
manifest: TransactionManifest,
) -> Self {
let payer = payer.into();
let balance_of_payer: Option<()> = payer.as_ref().map(|_| ());
Self {
hidden: HiddenConstructor,
_payer: payer,
entity_applying_shield,
manifest,
_balance_of_payer: balance_of_payer,
_balance_of_entity_applying_shield: (),
}
}
}

impl<Entity: HasEntityAddress + Clone> AbstractShieldApplicationInput<Entity> {
fn new(
payer_with_balance: impl Into<Option<XrdBalanceOfEntity<Account>>>,
entity_applying_shield_and_balance: XrdBalanceOfEntity<Entity>,
Expand All @@ -138,7 +180,7 @@ impl<Entity> AbstractShieldApplicationInput<Entity> {
entity_applying_shield_and_balance.balance,
}
}
fn with_entity_applying_shield<T>(
fn with_entity_applying_shield<T: HasEntityAddress + Clone>(
some: AbstractShieldApplicationInput<T>,
entity_applying_shield: impl Into<Entity>,
) -> Self
Expand All @@ -147,16 +189,17 @@ where {

let uncasted_entity_with_balance =
some.get_entity_applying_shield_and_balance();
// assert_eq!(
// uncasted_entity_with_balance.entity.address(),
// entity_applying_shield.address()
// );

assert_eq!(
uncasted_entity_with_balance.address_erased(),
entity_applying_shield.address_erased()
);

let casted_entity_with_balance = XrdBalanceOfEntity {
entity: entity_applying_shield,
balance: uncasted_entity_with_balance.balance,
};

Self::new(
some.get_payer_and_balance(),
casted_entity_with_balance,
Expand Down Expand Up @@ -292,12 +335,12 @@ pub trait BatchApplySecurityShieldSigning {
let manifest = input.manifest;
let modified_manifest = manifest;
let account_applying_shield = input.entity_applying_shield;
let maybe_payer = input.payer;
Ok(SecurityShieldApplicationForUnsecurifiedAccount::with_modified_manifest(
account_applying_shield,
maybe_payer,
modified_manifest,
))
todo!("use xrd addresses");
// Ok(SecurityShieldApplicationForUnsecurifiedAccount::with_modified_manifest(
// account_applying_shield,
// maybe_payer,
// modified_manifest,
// ))
}

fn shield_application_for_unsecurified_persona(
Expand Down Expand Up @@ -405,7 +448,7 @@ impl BatchApplySecurityShieldSigning for SargonOS {
&self,
manifest_and_payer_tuples: IndexSet<ManifestWithPayerByAddress>,
) -> Result<IndexSet<TransactionIntentHash>> {
let manifests_with_entities = manifest_and_payer_tuples
let manifests_with_entities_without_xrd_balances = manifest_and_payer_tuples
.into_iter()
.map(|manifest_with_payer_by_address| {
let manifest = manifest_with_payer_by_address.manifest;
Expand All @@ -421,22 +464,28 @@ impl BatchApplySecurityShieldSigning for SargonOS {
manifest_with_payer_by_address.payer
{
let payer = self.account_by_address(payer_address)?;
Ok(ShieldApplicationInput::new(
Ok(ShieldApplicationInputWithoutXrdBalance::new(
payer,
entity_applying_shield,
manifest,
))
} else {
Ok(ShieldApplicationInput::new(
Ok(ShieldApplicationInputWithoutXrdBalance::new(
None,
entity_applying_shield,
manifest,
))
}
})
.collect::<Result<Vec<ShieldApplicationInput>>>()?;
.collect::<Result<Vec<ShieldApplicationInputWithoutXrdBalance>>>()?;

let manifests_with_entities_with_xrd_balance =
manifests_with_entities_without_xrd_balances
.into_iter()
.map(|with_balance| todo!())
.collect::<Result<Vec<ShieldApplicationInput>>>()?;

manifests_with_entities
manifests_with_entities_with_xrd_balance
.into_iter()
.map(|manifest_with_payer| {
match &manifest_with_payer.entity_applying_shield {
Expand Down