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(verifyVC): add verifyVC method to Claims Service #592

Merged
merged 15 commits into from
Jul 13, 2022

Conversation

whitneypurdum
Copy link
Contributor

@whitneypurdum whitneypurdum commented Jun 30, 2022

Description

  • Moves verifyVc and verifyIssuer to Claims Service (as was in original ICL-210, no additional changes)

Contributor checklist

  • Breaking changes - check for any existing interfaces changes that are not backward compatible, removed method etc.
  • Documentation - document your code, add comments for method, remember to check if auto generated docs were updated.
  • Tests - add new or updated existed test for changes you made.
  • Migration guide - add migration guide for every breaking change.
  • Configuration correctness - check that any configuration changes are correct ex. default URLs, chain ids, smart contract verification on Volta explorer or EWC explorer.

@whitneypurdum whitneypurdum marked this pull request as draft June 30, 2022 08:41
@whitneypurdum whitneypurdum marked this pull request as ready for review June 30, 2022 10:40
@whitneypurdum whitneypurdum requested a review from JGiter June 30, 2022 10:52
@whitneypurdum whitneypurdum changed the title feat(verifyVC): add verifyVC method to VC Base Service feat(verifyVC): add verifyVC method to Claims Service Jun 30, 2022
src/modules/claims/claims.service.ts Outdated Show resolved Hide resolved
src/modules/claims/claims.service.ts Outdated Show resolved Hide resolved
src/modules/claims/claims.service.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@jrhender jrhender left a comment

Choose a reason for hiding this comment

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

It looks like it's coming along, thanks @whitneypurdum . I think the biggest thing to do is to update the @energyweb/vc-verification package to use the latest library API.

Also, it seems like the changes to domains.service and verifiable-credentials-base.service are just styling. IMO, I would remove these changes from the PR to avoid having them included in the history and limit the PR to the relevant functional changes.

@whitneypurdum
Copy link
Contributor Author

It looks like it's coming along, thanks @whitneypurdum . I think the biggest thing to do is to update the @energyweb/vc-verification package to use the latest library API.

Also, it seems like the changes to domains.service and verifiable-credentials-base.service are just styling. IMO, I would remove these changes from the PR to avoid having them included in the history and limit the PR to the relevant functional changes.

It looks like it's coming along, thanks @whitneypurdum . I think the biggest thing to do is to update the @energyweb/vc-verification package to use the latest library API.

Also, it seems like the changes to domains.service and verifiable-credentials-base.service are just styling. IMO, I would remove these changes from the PR to avoid having them included in the history and limit the PR to the relevant functional changes.

Sure thing, these have been removed from PR.

@whitneypurdum
Copy link
Contributor Author

whitneypurdum commented Jun 30, 2022

@JGiter @jrhender Hopefully my changes align with what you intended above! I removed the error handling from verifyIssuer because I think the method in ew-credentials throws descriptive errors already, plus it does not return boolean value anymore for conditional check. I have squashed my commits.

@whitneypurdum whitneypurdum force-pushed the task/ICL-210_verify_ewf_vc branch from c62e14e to a573e51 Compare June 30, 2022 21:37
@Harasz Harasz mentioned this pull request Jul 1, 2022
5 tasks
Copy link
Collaborator

@jrhender jrhender left a comment

Choose a reason for hiding this comment

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

Looks like strong progress to the PR, thank you for all of your efforts @whitneypurdum . However, I think there might be a couple tweaks and ideally some tests to add

src/modules/claims/claims.service.ts Outdated Show resolved Hide resolved
Comment on lines 1363 to 1368
/**
* Verifies that credential was issued by authorized issuer
*
* @param {VerifiableCredential<RoleCredentialSubject} vc to be verified
*/
async verifyVc(vc: VerifiableCredential<RoleCredentialSubject>) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be good to:

  • Add the return type
  • Add to the documentation that the expected behaviour is that errors are thrown if verification passes (it would be good to include this in the tests as well)

src/modules/claims/claims.service.ts Outdated Show resolved Hide resolved
@@ -1,17 +1,14 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { providers, utils, Wallet } from 'ethers';
import { verifyCredential } from 'didkit-wasm-node';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jrhender @JGiter we will need to create separate services based on env. for claims service now, right? For 'didkit-wasm-node' and 'didkit-wasm' - like for VC Service?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@whitneypurdum We can use verifyCredential from VC service. Actually I added it already when updated vc-verification. You just need to merge develop

@CLAassistant
Copy link

CLAassistant commented Jul 4, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@jrhender jrhender left a comment

Choose a reason for hiding this comment

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

Some comments, I will continue to review further

@@ -1354,6 +1350,23 @@ export class ClaimsService {
);
}

/**
* Verifies that credential was issued by authorized issuer
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Verifies that credential was issued by authorized issuer
* Verifies:
* - That credential proof is valid
* - That credential was issued by authorized issuer

src/modules/claims/claims.service.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@jrhender jrhender left a comment

Choose a reason for hiding this comment

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

I think the API should be

resolveCredentialAndVerify(subjectDID, roleNamespace) {
  ...some code to resolve the credential 
  if (foundOffChainClaim) {
    return verifyOffChainClaim(offChainClaim);
  }
  if (foundVc) {
    return verifyVc(vc);
  }

where resolveCredentialAndVerify is a rename of the current verify method.

This allow us to have methods which can accept the offChainClaim and VCs directly without needing the credentials to be "resolvable"

How does this sound @whitneypurdum @nichonien ?

src/modules/claims/claims.service.ts Outdated Show resolved Hide resolved
src/modules/claims/claims.service.ts Show resolved Hide resolved
@whitneypurdum whitneypurdum force-pushed the task/ICL-210_verify_ewf_vc branch from 9496e0b to 0da3229 Compare July 6, 2022 12:01
* @param roleNamesapce The role to try to get a credential for. Should be a full role namespace (for example, "myrole.roles.myorg.auth.ewc")
* @return Boolean indicating if verified and array of error messages
*/
async verifyOffChainClaim(subjectDID: string, roleNamespace: string): Promise<CredentialVerificationResult> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO, this should accept the OffChainClaim interface of ew-credentials https://github.com/energywebfoundation/ew-credentials/blob/55b84926b85a7e2261fffad[…]6/packages/vc-verification/src/models/verifiable-credentials.ts

The idea is that there should be some symmetry between async verifyVc(vc: VerifiableCredential<RoleCredentialSubject>): Promise<CredentialVerificationResult> (which accepts the actual VerifiableCredential) and this verifyOffChainClaim method (which will accept an actual offChainClaim)

Suggested change
async verifyOffChainClaim(subjectDID: string, roleNamespace: string): Promise<CredentialVerificationResult> {
async verifyOffChainClaim(offChainClaim: OffChainClaim): Promise<CredentialVerificationResult> {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, can do, but the two methods used for offchain verification only use the subject did and role name. How can I resolve those in ICL from the claim?

expect(result.errors).toHaveLength(0);
expect(result.isVerified).toBeTruthy;
});
test('verifyVc should: not verify a credential and return an issuer error if the issuer is not authorized', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This passes

* @param roleNamesapce The role to try to get a credential for. Should be a full role namespace (for example, "myrole.roles.myorg.auth.ewc")
* @return void. Returns "Proof Not Verified" error if VC not verified. Returns error if issuer not verified
*/
async resolveCredentialAndVerify(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JGiter @jrhender This is the new verify code based on previous comments. I have a few of the tests passing, but questions on others - I think maybe I am misunderstanding the limitations of ew-credentials, but I don't think I need to mock anything else out as _verifyIssuer is verifying the credential successfully.

console.log(result, 'THE RESOLVE RESULT');
});
test('verifyOffChainClaim should verify an issued off chain claim', async () => {
const roleName = `${verifyOffChainClaimRole}.${root}`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@whitneypurdum Sorry, I think I made a mistake. I think that the signature of verifyOffChainClaim should be async verifyOffChainClaim(eip191JWT: string): Promise<CredentialVerificationResult>

And then you can use the jsonwebtoken package to decode the body.

import jsonwebtoken from 'jsonwebtoken';

where a decoded body should look something like:

{
  "claimData": {
    "claimType": "myrole.roles.myorg.iam.ewc",
    "claimTypeVersion": 1
  },
  "signer": "did:ethr:volta:0xb764D50751fF83e66FCF5A08Fb0De3f830248728",
  "iss": "did:ethr:volta:0xb764D50751fF83e66FCF5A08Fb0De3f830248728",
  "sub": "did:ethr:volta:0x0fAe481148C2DF77886CE3874f0fb2E7118acDa0"
}

Copy link
Collaborator

@jrhender jrhender left a comment

Choose a reason for hiding this comment

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

Great work, thanks for all of your efforts on this @whitneypurdum

src/modules/claims/claims.service.ts Outdated Show resolved Hide resolved
@whitneypurdum whitneypurdum merged commit f34445f into develop Jul 13, 2022
@ewf-devops
Copy link

🎉 This PR is included in version 6.0.0-alpha.29 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ewf-devops
Copy link

🎉 This PR is included in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jrhender jrhender deleted the task/ICL-210_verify_ewf_vc branch March 6, 2023 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants