-
Notifications
You must be signed in to change notification settings - Fork 12
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
base: develop
Are you sure you want to change the base?
Extract CVCMerkleProof from the VC creation #226
Conversation
…r supporting features that rely on CvcMerkleRoot like attestations
@@ -0,0 +1,59 @@ | |||
/* eslint-disable @typescript-eslint/no-explicit-any */ |
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.
Instead of doing this file wide could we do this next to the any usage :)
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've made the change where it makes sense... there is one file that is completely riddled with any
s
|
||
const vm = await didUtil.findVerificationMethod(did, this._verificationMethod); | ||
|
||
if(!vm) return false; |
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.
Should we return an error?
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.
No... it was like that... but, following suite on other libraries, if it is unable to verify (for whatever reason) return false
import validUrl from 'valid-url'; | ||
|
||
function validIdentifiers() { | ||
const vi = _.map(definitions, (d: { identifier: any; }) => d.identifier); |
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 think we should use the typescript array functions instead of lodash?
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.
Lodash is all over... mostly just copy/paste from the existing implementation
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 have created a separate ticket for this
"@context": this["@context"], | ||
id: this.id, | ||
issuer: this.issuer, | ||
issuanceDate: this.issuanceDate, | ||
identifier: this.identifier, | ||
expirationDate: this.expirationDate, | ||
version: this.version, | ||
// version: this.version, |
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.
Do we need this?
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 added a TODO with ticket number
src/vc/VerifiableCredential.ts
Outdated
type: this.type, | ||
credentialSubject: this.credentialSubject, | ||
} | ||
} | ||
} | ||
|
||
isMatch = (constraints: any) => { |
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 think we should stay consistant with our types of functions? What do you think?
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.
Agreed, mostly because I'd spend another few days fixing pre-existing broken types
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.
Sorry I totally misunderstood you - ignore previous comment.
Agreed, fixing
if(!foundKey) { | ||
throw new Error(`No Verification Method found for ${iri}`); | ||
} | ||
const foundKey = doc.verificationMethod?.find((pk: any) => pk.id.startsWith(iri)); |
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.
should we check if foundKey
is undefined
?
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 would silently fail (correctly imo), but have updated it to be more explicit
const unsignedCred = await VerifiableCredential.create({ | ||
issuer: didTestUtil.DID_CONTROLLER, | ||
identifier: 'credential-cvc:Identity-v3', | ||
subject: credentialSubject, | ||
claims: [name, dob], | ||
expiry: null, | ||
}); |
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.
In general, if we're copying large blocks of boilerplate code over and over, we need to please refactor it into a single location.
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 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 :)
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); |
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 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.
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]>
6ed9936
to
941d73e
Compare
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]>
941d73e
to
24026f5
Compare
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]>
a6f5cac
to
941d73e
Compare
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]>
941d73e
to
ae6a8fc
Compare
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.
Please wait for Tighe too 🙏
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]