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

anoncreds-rs integration #1110

Merged
merged 2 commits into from
Feb 2, 2024
Merged

anoncreds-rs integration #1110

merged 2 commits into from
Feb 2, 2024

Conversation

mirgee
Copy link
Contributor

@mirgee mirgee commented Jan 22, 2024

A first working implementation of BaseAnoncreds trait using anoncreds-rs. Not final. Will be improved significantly in the forthcoming PRs.

@mirgee mirgee added the skip-ci label Jan 22, 2024
@mirgee mirgee force-pushed the feature/anoncreds-rs-ctd branch 5 times, most recently from 3a79dbc to 570f8e8 Compare January 24, 2024 10:41
@mirgee mirgee removed the skip-ci label Jan 24, 2024
@mirgee mirgee force-pushed the feature/anoncreds-rs-ctd branch 5 times, most recently from e424f28 to b7f2a91 Compare January 24, 2024 11:04
@codecov-commenter
Copy link

codecov-commenter commented Jan 24, 2024

Codecov Report

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

Comparison is base (b837fcb) 0.05% compared to head (7061837) 0.05%.

Files Patch % Lines
aries/aries_vcx/src/handlers/issuance/issuer.rs 0.00% 10 Missing ⚠️
...s_vcx/src/common/primitives/revocation_registry.rs 0.00% 7 Missing ⚠️
aries/aries_vcx/tests/test_anoncreds.rs 0.00% 6 Missing ⚠️
...vcx/src/protocols/issuance/holder/state_machine.rs 0.00% 5 Missing ⚠️
aries/aries_vcx/tests/test_credentials.rs 0.00% 5 Missing ⚠️
aries/aries_vcx_core/src/errors/mapping_others.rs 0.00% 5 Missing ⚠️
...es_vcx/src/common/proofs/prover/prover_internal.rs 0.00% 3 Missing ⚠️
...vcx/src/common/primitives/credential_definition.rs 0.00% 2 Missing ⚠️
aries/aries_vcx/tests/test_primitives.rs 0.00% 2 Missing ⚠️
...es_vcx/tests/utils/scenarios/proof_presentation.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main   #1110      +/-   ##
========================================
- Coverage   0.05%   0.05%   -0.01%     
========================================
  Files        479     479              
  Lines      24338   24366      +28     
  Branches    4367    4374       +7     
========================================
  Hits          13      13              
- Misses     24324   24352      +28     
  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.

@mirgee mirgee force-pushed the feature/anoncreds-rs-ctd branch 2 times, most recently from 5af7353 to 5a3c359 Compare January 24, 2024 11:38
Signed-off-by: Miroslav Kovar <miroslav.kovar@absa.africa>
aries/aries_vcx_core/Cargo.toml Show resolved Hide resolved
aries/aries_vcx_core/Cargo.toml Show resolved Hide resolved
aries/aries_vcx_core/src/anoncreds/mod.rs Show resolved Hide resolved
aries/aries_vcx_core/src/errors/mapping_anoncreds.rs Outdated Show resolved Hide resolved
@@ -192,8 +192,14 @@ pub async fn dev_build_featured_anoncreds() -> impl BaseAnonCreds {
return IndyCredxAnonCreds;
Copy link
Contributor

Choose a reason for hiding this comment

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

If I compile with both credx and anoncreds flags enabled, by mistake, the build will go through and this function and return credx implementation (while I perhaps only intended to run with anoncreds).

Something like

#[cfg(all(feature = "credx", feature = "anoncreds"))]
compile_error!("You can not enable 'credx' and 'anoncreds' features simultaneously. Choose one.");

Then the cfg conditions bellow can maybe also can be simplified by dropping the not part.

Copy link
Contributor Author

@mirgee mirgee Jan 31, 2024

Choose a reason for hiding this comment

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

We are using --all-features flag in CI, and I am using it myself in my current LSP config. Although this should be avoided if at all possible, I can still change both (and switch feature flags manually), but I think for now, following a priority order of credx, anoncreds-rs, mock in case of "conflicting" feature flags as suggested by the Cargo Book is fine.

@mirgee mirgee marked this pull request as ready for review January 31, 2024 12:41
Signed-off-by: Miroslav Kovar <miroslav.kovar@absa.africa>
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.

good job 👍 left some comments, nothing big though

Haven't yet covered everything in the anoncreds.rs file

}

impl Anoncreds {
async fn get_wallet_record_value<T>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: Wouldn't mind to make this part of wallet API, not in this PR though.

None
};

// WTF, anoncreds-rs expects the whole status list just to use the accumulator :|
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand the sometimes emotional nature of the job, but lets keep the comments assertive in the source code ;-)

Copy link
Contributor

Choose a reason for hiding this comment

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

How about you create tracking issue in anoncreds-rs repo to improve this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed, it may be fine to keep the API as thin as possible type-wise. It needs to be carefully considered what changes to anoncreds-rs are necessary. Not my priority right now.

Copy link
Contributor

@Patrik-Stas Patrik-Stas Feb 1, 2024

Choose a reason for hiding this comment

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

Okay, can we track it? If the API was annoying enough to leave that comment, it's probably worthy of tracking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I said, at this point, I only know some changes will be necessary (which is obviated by the fact we are using custom fork - hence no need to track IMO), but I don't know which ones. This question will get deserved attention later.

.add_wallet_record(
CATEGORY_CRED_MAP_SCHEMA_ID,
&cred_def_id.0,
&json!({"schemaId": schema_id}).to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the record category states explicitly enough what the value is. Not strongly against it, not fan either.

But also: I observe that you are willing to give up backwards compatibility (knowingly or unknowingly). If that would be the case, I wonder if there's other breaking changes we can/want to do?

Also I wonder what backwards non-compatibility implies for migration from credx -> anoncreds. Bit late now so I'll save that thinking for later ^_^

Copy link
Contributor Author

@mirgee mirgee Feb 1, 2024

Choose a reason for hiding this comment

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

It's not about explicitness, it needs to be a json (again, this code should not exist)

Copy link
Contributor

Choose a reason for hiding this comment

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

Honest question - how come? Doesn't seem to be json in credx implementation

        wallet
            .add_wallet_record(
                CATEGORY_CRED_MAP_SCHEMA_ID,
                &cred_def_id.0,
                &schema.id().0,
                None,
            )

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, you may be right, I will look into it

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should keep somewhere comment that we currently only support ISSUANCE_ON_DEMAND IssuanceType, and it's the default

let rev_reg = cred.rev_reg.as_ref();

let cred_rev_id =
if let (Some(rev_reg_id), Some(rev_reg), Some((_, _, _, _, rev_reg_info, _))) =
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, I know this is mostly copy-paste, but I'll take opportunity to comment this. We should only be testing one (preferably the input rev_reg_id, as that the initial source of truth as whether we issue revocable or irrevocable credential), not all tree for Some, and throw an error else.
If first of the tuple is Some, but other are None, something must had gone unexpectedly wrong, likely due a bug - so we shouldn't instead silently treat that same way as we treat irrevocable credentials.

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.

✅ Approved from my side, I trust my comments are acknowledged whether they would be addressed here or in the next rounds.

Feel free to merge if you are ready.

None
};

// WTF, anoncreds-rs expects the whole status list just to use the accumulator :|
Copy link
Contributor

@Patrik-Stas Patrik-Stas Feb 1, 2024

Choose a reason for hiding this comment

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

Okay, can we track it? If the API was annoying enough to leave that comment, it's probably worthy of tracking

// Otherwise, create cred def
let (cred_def, cred_def_priv, cred_key_correctness_proof) =
anoncreds::issuer::create_credential_definition(
// Schema ID must be just the schema seq no for some reason
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, please let's track this somewhere. Can be just single comprehensive issue with a brief list of issues we run into with anoncreds-rs and needs to be looked into.

.add_wallet_record(
CATEGORY_CRED_MAP_SCHEMA_ID,
&cred_def_id.0,
&json!({"schemaId": schema_id}).to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Honest question - how come? Doesn't seem to be json in credx implementation

        wallet
            .add_wallet_record(
                CATEGORY_CRED_MAP_SCHEMA_ID,
                &cred_def_id.0,
                &schema.id().0,
                None,
            )

Comment on lines +1117 to +1118
None,
Some(prover_did.did()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: it would be preferable to swap these. Provide first argument entropy of value Some(prover_did), and provide None for the 2nd arg.
I don't know why this became 2 arguments in anoncreds-rs, originally it was prover_did later renamed to entropy to reflect actual purpose of the parameter. But there was a shift from dealing with "prover_did" to more generally "some entropy".

});
let registry = CryptoRevocationRegistry { accum };

// let rev_status_list = create_revocation_status_list(
Copy link
Contributor

Choose a reason for hiding this comment

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

remove?

@mirgee mirgee merged commit 433ba3c into main Feb 2, 2024
29 checks passed
@mirgee mirgee deleted the feature/anoncreds-rs-ctd branch February 2, 2024 07:03
@mirgee mirgee restored the feature/anoncreds-rs-ctd branch February 2, 2024 07:30
mirgee added a commit that referenced this pull request Feb 2, 2024
mirgee added a commit that referenced this pull request Feb 2, 2024
@mirgee mirgee deleted the feature/anoncreds-rs-ctd branch February 2, 2024 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants