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

Extract CVCMerkleProof from the VC creation #226

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

william-brooks
Copy link
Contributor

@william-brooks william-brooks commented Apr 18, 2023

This update separates the CvcMerkleProof from VC creation allowing for alternative proof mechanisms to be used.

PR: #226

Signed-off-by: William Brooks [email protected]
Reviewed-by: Julian Spring [email protected]
Reviewed-by: Tighe Barris [email protected]

@william-brooks william-brooks changed the base branch from master to develop April 18, 2023 10:45
@william-brooks william-brooks marked this pull request as ready for review April 18, 2023 11:28
@@ -0,0 +1,59 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

Choose a reason for hiding this comment

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

Instead of doing this file wide could we do this next to the any usage :)

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've made the change where it makes sense... there is one file that is completely riddled with anys

src/proof/CvcMerkleProof/Ed25519SignerVerifier.ts Outdated Show resolved Hide resolved

const vm = await didUtil.findVerificationMethod(did, this._verificationMethod);

if(!vm) return false;

Choose a reason for hiding this comment

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

Should we return an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No... it was like that... but, following suite on other libraries, if it is unable to verify (for whatever reason) return false

src/proof/Proof.ts Outdated Show resolved Hide resolved
import validUrl from 'valid-url';

function validIdentifiers() {
const vi = _.map(definitions, (d: { identifier: any; }) => d.identifier);

Choose a reason for hiding this comment

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

I think we should use the typescript array functions instead of lodash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lodash is all over... mostly just copy/paste from the existing implementation

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 have created a separate ticket for this

src/vc/VerifiableCredential.ts Outdated Show resolved Hide resolved
"@context": this["@context"],
id: this.id,
issuer: this.issuer,
issuanceDate: this.issuanceDate,
identifier: this.identifier,
expirationDate: this.expirationDate,
version: this.version,
// version: this.version,

Choose a reason for hiding this comment

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

Do we need 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.

I added a TODO with ticket number

type: this.type,
credentialSubject: this.credentialSubject,
}
}
}

isMatch = (constraints: any) => {

Choose a reason for hiding this comment

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

I think we should stay consistant with our types of functions? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, mostly because I'd spend another few days fixing pre-existing broken types

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I totally misunderstood you - ignore previous comment.

Agreed, fixing

__integrations__/credentials/VerifiableCredential.test.js Outdated Show resolved Hide resolved
if(!foundKey) {
throw new Error(`No Verification Method found for ${iri}`);
}
const foundKey = doc.verificationMethod?.find((pk: any) => pk.id.startsWith(iri));

Choose a reason for hiding this comment

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

should we check if foundKey is undefined ?

Copy link
Contributor Author

@william-brooks william-brooks Apr 18, 2023

Choose a reason for hiding this comment

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

This would silently fail (correctly imo), but have updated it to be more explicit

Comment on lines +36 to +42
const unsignedCred = await VerifiableCredential.create({
issuer: didTestUtil.DID_CONTROLLER,
identifier: 'credential-cvc:Identity-v3',
subject: credentialSubject,
claims: [name, dob],
expiry: null,
});
Copy link

Choose a reason for hiding this comment

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

In general, if we're copying large blocks of boilerplate code over and over, we need to please refactor it into a single location.

__test__/index.test.js Outdated Show resolved Hide resolved
Copy link

@tbarri tbarri left a comment

Choose a reason for hiding this comment

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

This is a fairly large commit, and no doubt valuable work. Thank you for putting the effort into this. Something for the future though:

Try break the PR into even smaller commits, and squash the commits that don't matter. For example, commit Extracted CvcMerkleProof with tests doesn't contain anything meaningful. As such, it shouldn't be in this PR. There's 6 commits all named Extract CVCMerkleProof from the VC creation.

Similarly, if you make large sweeping reformat changes as was done in Updates to support CvcMerkleRoot as separate to a VC, along with others, please keep it in a separate commit. It's almost impossible to separate your logic from the reformat changes.

Ideally, we want the PRs to be presented as you intend to merge them. Working diffs need to please be squashed / merged / dropped before sending out for review.

Please don't stress about this PR series - but let's keep this in mind for the next PR :)

Comment on lines 145 to 152
const signer = createSigner(document, keypair);

const credential = await createCredential(document, signer, keyResolver);
const cvcMerkleProof = new CvcMerkleProof(signer);

const credential = await createCredential(document, cvcMerkleProof);

const verified = await credential.verifyMerkletreeSignature();
const verified = await cvcMerkleProof.verify(credential);

expect(verified).toBe(true);
Copy link

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 really valuable if we wrote these unit tests in terms of the interfaces (export default interface Proof<K>). This way, we can drop any concrete implementation into the unit tests, and validate that they work.

william-brooks pushed a commit that referenced this pull request Apr 19, 2023
This update separates the CvcMerkleProof from VC creation allowing for alternative proof mechanisms to be used.

PR: #226

Signed-off-by: William Brooks <[email protected]>
Reviewed-by: Julian Spring <[email protected]>
Reviewed-by: Tighe Barris <[email protected]>
@william-brooks william-brooks force-pushed the dev-william-brooks/cvc_merkle_proof_extraction branch from 6ed9936 to 941d73e Compare April 19, 2023 10:17
william-brooks pushed a commit that referenced this pull request Apr 19, 2023
This update separates the CvcMerkleProof from VC creation allowing for alternative proof mechanisms to be used.

PR: #226

Signed-off-by: William Brooks <[email protected]>
Reviewed-by: Julian Spring <[email protected]>
Reviewed-by: Tighe Barris <[email protected]>
@william-brooks william-brooks force-pushed the dev-william-brooks/cvc_merkle_proof_extraction branch from 941d73e to 24026f5 Compare April 19, 2023 11:40
william-brooks pushed a commit that referenced this pull request Apr 19, 2023
This update separates the CvcMerkleProof from VC creation allowing for alternative proof mechanisms to be used.

PR: #226

Signed-off-by: William Brooks <[email protected]>
Reviewed-by: Julian Spring <[email protected]>
Reviewed-by: Tighe Barris <[email protected]>
@william-brooks william-brooks force-pushed the dev-william-brooks/cvc_merkle_proof_extraction branch 2 times, most recently from a6f5cac to 941d73e Compare April 19, 2023 11:55
This update separates the CvcMerkleProof from VC creation allowing for alternative proof mechanisms to be used.

PR: #226

Signed-off-by: William Brooks <[email protected]>
Reviewed-by: Julian Spring <[email protected]>
Reviewed-by: Tighe Barris <[email protected]>
@william-brooks william-brooks force-pushed the dev-william-brooks/cvc_merkle_proof_extraction branch from 941d73e to ae6a8fc Compare April 19, 2023 13:09
Copy link

@JulianSpring JulianSpring left a comment

Choose a reason for hiding this comment

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

Please wait for Tighe too 🙏

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