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

feat: add new Wallet trait, implement for indy wallet #1084

Merged
merged 2 commits into from
Jan 12, 2024

Conversation

xprazak2
Copy link
Contributor

@xprazak2 xprazak2 commented Dec 6, 2023

Obsoletes #1071 and takes an approach outlined in #1071 (review), meaning:

  • no associated types
  • new trait does not expose any implementation-specific types
  • initial implementation for vdrtools wallet

@codecov-commenter
Copy link

codecov-commenter commented Dec 6, 2023

Codecov Report

Attention: 224 lines in your changes are missing coverage. Please review.

Comparison is base (41ea29f) 0.05% compared to head (55cbf0a) 0.05%.

Files Patch % Lines
...core/src/wallet2/indy_wallet/indy_record_wallet.rs 0.00% 80 Missing ⚠️
...cx_core/src/wallet2/indy_wallet/indy_did_wallet.rs 0.00% 76 Missing ⚠️
aries/aries_vcx_core/src/wallet2/entry_tag.rs 0.00% 26 Missing ⚠️
...ries/aries_vcx_core/src/wallet2/indy_wallet/mod.rs 0.00% 24 Missing ⚠️
aries/aries_vcx_core/src/wallet2/mod.rs 0.00% 14 Missing ⚠️
aries/aries_vcx_core/src/wallet2/utils.rs 0.00% 3 Missing ⚠️
aries/aries_vcx/src/errors/mapping_others.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main   #1084      +/-   ##
========================================
- Coverage   0.05%   0.05%   -0.01%     
========================================
  Files        472     478       +6     
  Lines      24109   24334     +225     
  Branches    4336    4370      +34     
========================================
  Hits          13      13              
- Misses     24095   24320     +225     
  Partials       1       1              
Flag Coverage Δ
unittests-aries-vcx 0.05% <0.00%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xprazak2 xprazak2 force-pushed the indy-record-wallet branch 6 times, most recently from 7c399a9 to f4f7b5e Compare December 20, 2023 09:12
@xprazak2 xprazak2 marked this pull request as ready for review December 20, 2023 13:34
aries/aries_vcx_core/src/wallet2/mod.rs Outdated Show resolved Hide resolved
aries/aries_vcx_core/src/wallet2/mod.rs Outdated Show resolved Hide resolved
aries/aries_vcx_core/src/wallet2/mod.rs Show resolved Hide resolved
aries/aries_vcx_core/src/wallet2/indy_wallet/mod.rs Outdated Show resolved Hide resolved
aries/aries_vcx_core/src/wallet2/mod.rs Show resolved Hide resolved
@xprazak2 xprazak2 force-pushed the indy-record-wallet branch 2 times, most recently from c572e24 to 550ae5d Compare December 21, 2023 11:10
impl DidWallet for crate::wallet::indy::IndySdkWallet {
async fn create_and_store_my_did(
&self,
seed: &str,
Copy link
Contributor

Choose a reason for hiding this comment

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

The existing BaseWallet interface has this as seed: Option<&str>. When None is specified, a random seed is generated. In fact, most of the code where create_and_store_my_did is being called passed None.
Is there a reason why, seemingly, you've decided to strip this feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted it back, it is Option<&str> now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see it as a simpler and safer API design force the client to explicitly choose the RNG and randomness source instead of allowing multiple code paths by hiding an implementation which may unknowing change beneath their feet.

Copy link
Contributor

@Patrik-Stas Patrik-Stas left a comment

Choose a reason for hiding this comment

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

Left some comments.

However, either way; before we merge this, I would like to see this #1093 passing, proving that vdrtools wallet implementation of the new traits in fact satisfy the contract the rest of the codebase expects.

I suggest to follow order:

  • get 1093 passing
  • merge this
  • merge 1093
  • merge the askar related implementations

@xprazak2 xprazak2 force-pushed the indy-record-wallet branch 10 times, most recently from d7199da to 748ab8a Compare January 3, 2024 06:58
aries/aries_vcx_core/src/wallet2/mod.rs Outdated Show resolved Hide resolved
aries/aries_vcx_core/src/wallet2/mod.rs Outdated Show resolved Hide resolved
Comment on lines 80 to 36
pub struct UnpackedMessage {
pub message: String,
pub recipient_verkey: String,
pub sender_verkey: Option<String>,
}

#[cfg(feature = "vdrtools_wallet")]
impl From<UnpackMessageOutput> for UnpackedMessage {
fn from(value: UnpackMessageOutput) -> Self {
Self {
message: value.message,
recipient_verkey: value.recipient_verkey,
sender_verkey: value.sender_verkey,
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why not to reuse UnpackMessageOutput?

Copy link
Contributor

@Patrik-Stas Patrik-Stas Jan 3, 2024

Choose a reason for hiding this comment

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

Probably the most important comment within this review:

You placed the tests into indy implementations directly, but the tests themselves are not necessarily indy specific - they rely on the DidWallet, RecordWallet traits in general, regardless of the underlying implementations. Am I perhaps missing something?

The current approach would indicate that given you have test test_indy_should_sign_and_verify, you will likewise have test_askar_should_sign_and_verify where the test case would only differ by its setup.
Also, you are using create_indy_test_wallet_handle for all of the tests you have added, which sets up mysql wallet - that's somewhat unexpected, most of the test for sake of simplicity are using the default sqlite version of vdrtools wallet. There's only 1 particular test which specifically aims to verify that mysql works (test_mysql_wallet.rs).

So in my view, solving that boils down to:

  • Make tests agnostic of underlying implementations - test against interfaces, not specific implementation
    • For that you can use dev_build_featured_wallet(seed).await; (all existing tests, except for the mysql one, are using this)
  • Because dev_build_featured_wallet is choosing wallet implementation based on feature flags, it will be easy to use the same test cases for testing askar implementation too
  • Consequently you shouldn't need create_indy_test_wallet_handle, which sets up mysql wallet, anymore. If it for some reason should stay, it would be nice to deduplicate it with test_mysql_init_issuer_with_mysql_wallet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, there is one small complication though. dev_build_featured_wallet cannot really be used in aries_vcx_core, because that means adding test_utils crate as a dependency for aries_vcs_core thus creating a dependency cycle. While cargo initially does not object, having cycles in deps is generally not a good idea and problems start to surface quite rapidly with failing type checks.

I created a custom setup for now, any thoughts on this are appreciated.

Copy link
Contributor

Choose a reason for hiding this comment

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

As agreed to, we will look into removing aries_vcx_core as test_utils dependency and use the setup code in aries_vcx_core tests directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tracking issue #1101 .

@Patrik-Stas Patrik-Stas added the review:level-2 At least 2 approvals required for merge label Jan 3, 2024
@xprazak2 xprazak2 force-pushed the indy-record-wallet branch 6 times, most recently from bc3a5c6 to 91c0004 Compare January 4, 2024 15:16
Patrik-Stas
Patrik-Stas previously approved these changes Jan 5, 2024
@@ -0,0 +1,9 @@
use rand::{distributions::Alphanumeric, Rng};

pub fn random_seed() -> String {
Copy link
Contributor

Choose a reason for hiding this comment

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

There already is a similar function in test_utils.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps, but using it means adding test_utils as a dependency for aries_vcx_core and creating dependency cycle aries_vcx_core -> test_utils -> aries_vcx_core.

aries/misc/test_utils/src/devsetup.rs Outdated Show resolved Hide resolved
aries/aries_vcx/src/errors/error.rs Outdated Show resolved Hide resolved
aries/aries_vcx_core/src/wallet2/mod.rs Outdated Show resolved Hide resolved
aries/aries_vcx_core/src/wallet2/mod.rs Show resolved Hide resolved
Comment on lines +7 to +15
const WALLET_OPTIONS: &str =
r#"{"retrieveType": true, "retrieveValue": true, "retrieveTags": true}"#;

const SEARCH_OPTIONS: &str = r#"{"retrieveType": true, "retrieveValue": true, "retrieveTags": true, "retrieveRecords": true}"#;
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume these can be associated constants. Not sure but maybe we might want to optimize access by allowing the client specify these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see any such optimisations as out of scope for this. These are also pretty implementation-specific options.

}

pub enum SearchFilter {
JsonFilter(String),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a pattern we wanted to avoid by the refactor. The clinet serializing a json just for the implementation to deserialize it, incurring overhead while losing type information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that using json is unfortunate, but these changes are about introducing a new backward-compatible trait that would allow us a transition to different wallet implementation(s). These changes are not about improving the existing wallet implementation.

Even though I could come up with a new type to use here, it would still need to be turned into json at some point because that is what vdrtools wallet requires and that would just result in more overhead.

Comment on lines +58 to +56
seed: Option<&str>,
method_name: Option<&str>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder whether this should be an optional. Every DID creation requires a seed and method name. There should be no arbitrary defaults IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aries/aries_vcx_core/src/wallet2/mod.rs Show resolved Hide resolved
}

#[cfg(feature = "vdrtools_wallet")]
impl From<HashMap<String, String>> for EntryTags {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this conversion (i.e. the order of items in the resulting vec) deterministic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently, iterator over hash map visits elements in arbitrary order and the iteration is stable if the map is not changed. Are there any requirements on tag ordering?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure, but superficially seems potentially problematic.

@xprazak2
Copy link
Contributor Author

xprazak2 commented Jan 8, 2024

@mirgee thank you for a detailed review. I see a lot of suggestions for improvements that would be valuable but they would mean significant differences between BaseWallet and BaseWallet2 which would mean introducing impactful changes to the vdrtools wallet in order to move to the new trait.

While that was initially the plan, it was suggested to keep the new trait as close to the existing one so it would be easier to swap them and then gradually improve the new trait. That is also a reason this PR no longer contains create_did and create_key methods that we initially wanted as an improvement over create_and_store_my_did.

The approach here is to introduce a new, slightly better trait that would maintain a high degree of backward compatibility so it would be relatively easy to replace the old one and new trait not being tailored to a specific wallet implementation. Would you prefer we took a different way?

@xprazak2
Copy link
Contributor Author

xprazak2 commented Jan 8, 2024

Also, regarding multiple keys for a single DID: Looking at the BaseWallet methods, I do not think the trait supports that behaviour. Is that something that BaseWallet2 should address?

Signed-off-by: Ondrej Prazak <ondrej.prazak@absa.africa>
@xprazak2 xprazak2 force-pushed the indy-record-wallet branch 2 times, most recently from 1cf5beb to f85aedc Compare January 12, 2024 08:48
Signed-off-by: Ondrej Prazak <ondrej.prazak@absa.africa>
@Patrik-Stas Patrik-Stas merged commit 88541f2 into main Jan 12, 2024
28 checks passed
@Patrik-Stas Patrik-Stas deleted the indy-record-wallet branch January 12, 2024 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review:level-2 At least 2 approvals required for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants