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

ROLA using Signatures Collector #310

Merged
merged 14 commits into from
Dec 19, 2024

Conversation

micbakos-rdx
Copy link
Contributor

This PR integrates signing auth with signatures collector. There are some steps to achieve this:

  • Deleted the old implementation which was only capable of signing only one entity at a time.
  • Implemented a Signable version for signing auth:
    • AuthIntent became a Signable and it is the request made to signatures collector when signing auth.
    • Since AuthIntent's footprint is small, the Signable::Payload is still an AuthIntent (No need for CompiledAuthIntent. If you feel this is necessary, I could amend.
    • AuthIntentHash is the SignableID. This is essentially the rola challenge.
    • SignedAuthIntent follows the same logic as SignedIntent but it also carries the signatures of each owner (AddressOfAccountOrPersona), since such information is needed to the hosts.
  • Removed the sample methods from the Signable trait and moved them to a separate trait. There was no need to be in the same trait before. It was my lack of experience in rust.
  • Introduced SigningPurpose into SignaturesCollector which can be either SignTX or ROLA.
  • @GhenadieVP According to your latest changes when resolving the signers, I followed the same logic of just ignoring the signers from input that could not be resolved in profile.

@micbakos-rdx micbakos-rdx added Swift 🍏 Changes in Swift Sargon Rust 🦀 Changes in Rust Sargon Kotlin 🤖 Changes in Kotlin Sargon UniFFI 🦄 Changes in UniFFI exported APIs labels Dec 19, 2024
@micbakos-rdx micbakos-rdx self-assigned this Dec 19, 2024
Comment on lines +64 to +66
decl_transaction_sign_request_input!(
signable_and_payload: AuthIntent
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Special case for this one. AuthIntent can act as a payload too.

@@ -37,7 +37,7 @@ impl HasSampleValues for DappToWalletInteractionMetadata {
fn sample() -> Self {
Self::new(
WalletInteractionVersion::sample(),
NetworkID::Stokenet,
NetworkID::Mainnet,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These samples were invalid. The dAppDefinigionAddress was in mainnet, but the NetworkID was in Stokenet.

Comment on lines 33 to 50
let origin = TryInto::<Url>::try_into(metadata.origin.clone())?;

if metadata.network_id != metadata.dapp_definition_address.network_id()
{
return Err(CommonError::NetworkDiscrepancy {
expected: metadata.network_id,
actual: metadata.dapp_definition_address.network_id(),
});
}

for entity in &entities_to_sign {
if entity.network_id() != metadata.network_id {
return Err(CommonError::NetworkDiscrepancy {
expected: metadata.network_id,
actual: entity.network_id(),
});
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some validation when generating an AuthIntent. I think this is what we need.

let entities = self
.entities_to_sign
.iter()
.filter_map(|address| match address {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@GhenadieVP Ignoring the entities which cannot be resolved in profile.

Copy link

codecov bot commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 94.80519% with 8 lines in your changes missing coverage. Please review.

Project coverage is 93.3%. Comparing base (a04b2c3) to head (99a5a41).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...s/sargon/src/signing/authentication/auth_intent.rs 93.5% 2 Missing ⚠️
...s/sargon/src/system/sargon_os/sargon_os_signing.rs 83.3% 2 Missing ⚠️
...argonOS/ThrowingHostInteractor+Static+Shared.swift 0.0% 1 Missing ⚠️
...ctor_of_instances_required_to_sign_transactions.rs 0.0% 1 Missing ⚠️
...rgon/src/signing/collector/signatures_collector.rs 66.6% 1 Missing ⚠️
.../src/signing/petition_types/petition_for_entity.rs 92.8% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main    #310   +/-   ##
=====================================
  Coverage   93.3%   93.3%           
=====================================
  Files       1109    1110    +1     
  Lines      23567   23595   +28     
  Branches      79      79           
=====================================
+ Hits       21994   22025   +31     
+ Misses      1558    1555    -3     
  Partials      15      15           
Flag Coverage Δ
kotlin 97.1% <100.0%> (ø)
rust 92.8% <95.3%> (+<0.1%) ⬆️
swift 94.8% <0.0%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...es/sargon/src/radix_connect/interaction_version.rs 100.0% <ø> (ø)
...pp_to_wallet/dapp_metadata/interaction_metadata.rs 100.0% <100.0%> (ø)
...gon/src/signing/authentication/auth_intent_hash.rs 100.0% <100.0%> (ø)
...n/src/signing/authentication/signed_auth_intent.rs 100.0% <100.0%> (ø)
...ing/collector/signatures_collector_preprocessor.rs 93.4% <100.0%> (ø)
...signing/petition_types/petition_for_transaction.rs 95.7% <ø> (ø)
...tes/sargon/src/signing/petition_types/petitions.rs 98.3% <ø> (ø)
...rgon/src/signing/petition_types/signing_purpose.rs 100.0% <100.0%> (ø)
...rates/sargon/src/signing/signable_with_entities.rs 95.6% <ø> (ø)
crates/sargon/src/signing/signables/signable.rs 96.5% <ø> (ø)
... and 14 more

@@ -38,6 +38,19 @@ macro_rules! decl_transaction_sign_request_input {
);
}
};
(signable_and_payload: $signable:ty) => {
paste! {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use new macro system - preinterpret. See the matrix macro

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Rationale: crate paste is no longer maintained and is gonna be deprecated.

preinterpret is also better.

Created by @dhedey so ask in Rust channel for help from him

Copy link
Contributor

Choose a reason for hiding this comment

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

But also we have bigger fish to fry... feel free to ignore

(value.security_structure.matrix_of_factors, role_kind)
).unwrap();

PetitionForEntity::new_securified(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you change PetitionForEntity -> Self (probably my old code)

vec![value.authentication_signing_factor_instance()],
1,
);
PetitionForEntity::new(
Copy link
Contributor

Choose a reason for hiding this comment

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

PetitionForEntity -> Self

pub fn new_from_request(
challenge_nonce: DappToWalletInteractionAuthChallengeNonce,
metadata: DappToWalletInteractionMetadata,
entities_to_sign: Vec<AddressOfAccountOrPersona>,
Copy link
Contributor

@CyonAlexRDX CyonAlexRDX Dec 19, 2024

Choose a reason for hiding this comment

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

prefer impl IntoIterator<Item = AddressOfAccountOrPersona>

let auth_intent = AuthIntent::new_from_request(
nonce,
metadata,
vec![AddressOfAccountOrPersona::Account(account.address)],
Copy link
Contributor

Choose a reason for hiding this comment

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

.entities_to_sign
.iter()
.filter_map(|address| match address {
AddressOfAccountOrPersona::Account(account_address) => profile
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be a method on Profile - getting of entities

let intent = AuthIntent::new_from_request(
DappToWalletInteractionAuthChallengeNonce(nonce),
metadata.clone(),
vec![AddressOfAccountOrPersona::Account(AccountAddress::random(
Copy link
Contributor

Choose a reason for hiding this comment

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

can drop vec! if ctor uses impl intoiterator

Copy link
Contributor

@CyonAlexRDX CyonAlexRDX left a comment

Choose a reason for hiding this comment

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

Good job!

@micbakos-rdx
Copy link
Contributor Author

Added some tests regarding Rola. I don't understand why coverage thinks that some code is not tested. The tests clearly pass from such places.

@micbakos-rdx micbakos-rdx merged commit c4ed26a into main Dec 19, 2024
13 checks passed
@micbakos-rdx micbakos-rdx deleted the feature/ABW-4017-signatures-collector-auth branch December 19, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Kotlin 🤖 Changes in Kotlin Sargon Rust 🦀 Changes in Rust Sargon Swift 🍏 Changes in Swift Sargon UniFFI 🦄 Changes in UniFFI exported APIs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants