-
Notifications
You must be signed in to change notification settings - Fork 83
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
Conversation
Codecov ReportAttention:
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
7c399a9
to
f4f7b5e
Compare
c572e24
to
550ae5d
Compare
impl DidWallet for crate::wallet::indy::IndySdkWallet { | ||
async fn create_and_store_my_did( | ||
&self, | ||
seed: &str, |
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.
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?
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.
I reverted it back, it is Option<&str>
now.
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.
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.
aries/aries_vcx_core/src/wallet2/indy_wallet/indy_did_wallet.rs
Outdated
Show resolved
Hide resolved
aries/aries_vcx_core/src/wallet2/indy_wallet/indy_did_wallet.rs
Outdated
Show resolved
Hide resolved
aries/aries_vcx_core/src/wallet2/indy_wallet/indy_did_wallet.rs
Outdated
Show resolved
Hide resolved
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.
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
d7199da
to
748ab8a
Compare
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, | ||
} | ||
} | ||
} |
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.
why not to reuse UnpackMessageOutput
?
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.
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)
- For that you can use
- 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 withtest_mysql_init_issuer_with_mysql_wallet
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.
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.
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.
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.
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.
Tracking issue #1101 .
bc3a5c6
to
91c0004
Compare
@@ -0,0 +1,9 @@ | |||
use rand::{distributions::Alphanumeric, Rng}; | |||
|
|||
pub fn random_seed() -> String { |
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.
There already is a similar function in test_utils
.
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.
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.
const WALLET_OPTIONS: &str = | ||
r#"{"retrieveType": true, "retrieveValue": true, "retrieveTags": true}"#; | ||
|
||
const SEARCH_OPTIONS: &str = r#"{"retrieveType": true, "retrieveValue": true, "retrieveTags": true, "retrieveRecords": true}"#; |
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.
I assume these can be associated constants. Not sure but maybe we might want to optimize access by allowing the client specify these.
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.
I see any such optimisations as out of scope for this. These are also pretty implementation-specific options.
} | ||
|
||
pub enum SearchFilter { | ||
JsonFilter(String), |
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.
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.
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.
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.
seed: Option<&str>, | ||
method_name: Option<&str>, |
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.
I wonder whether this should be an optional. Every DID creation requires a seed and method name. There should be no arbitrary defaults IMO.
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.
} | ||
|
||
#[cfg(feature = "vdrtools_wallet")] | ||
impl From<HashMap<String, String>> for EntryTags { |
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.
Is this conversion (i.e. the order of items in the resulting vec) deterministic?
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.
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?
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.
I am not sure, but superficially seems potentially problematic.
@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 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 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? |
Also, regarding multiple keys for a single DID: Looking at the |
8cccc79
to
0105b1b
Compare
Signed-off-by: Ondrej Prazak <ondrej.prazak@absa.africa>
1cf5beb
to
f85aedc
Compare
Signed-off-by: Ondrej Prazak <ondrej.prazak@absa.africa>
f85aedc
to
55cbf0a
Compare
Obsoletes #1071 and takes an approach outlined in #1071 (review), meaning: