diff --git a/src/index.ts b/src/index.ts index 6beacb7..cbea2ab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -137,17 +137,16 @@ export class LDMerkleProof2019 extends LinkedDataProof { let verified: boolean; let error: string = ''; - if (this.proof.proofPurpose) { - if (this.proof.proofPurpose !== this.proofPurpose) { - throw new Error(`Invalid proof purpose. Expected ${this.proofPurpose} but received ${this.proof.proofPurpose}`); - } - - if (this.issuer && !this.issuer[this.proofPurpose]?.includes(this.proof.verificationMethod)) { - throw new Error(`The verification method ${this.proof.verificationMethod} is not allowed for the proof purpose ${this.proofPurpose}`); - } - } - try { + if (this.proof.proofPurpose) { + if (this.proof.proofPurpose !== this.proofPurpose) { + throw new Error(`Invalid proof purpose. Expected ${this.proofPurpose} but received ${this.proof.proofPurpose}`); + } + + if (this.issuer && !this.issuer[this.proofPurpose]?.includes(this.proof.verificationMethod)) { + throw new Error(`The verification method ${this.proof.verificationMethod} is not allowed for the proof purpose ${this.proofPurpose}`); + } + } await this.verifyProcess(this.proofVerificationProcess); if (verifyIdentity) { await this.verifyIdentity(); diff --git a/tests/verification/data-integrity-proof-support.test.ts b/tests/verification/data-integrity-proof-support.test.ts index a82beb2..315bc17 100644 --- a/tests/verification/data-integrity-proof-support.test.ts +++ b/tests/verification/data-integrity-proof-support.test.ts @@ -27,9 +27,12 @@ describe('given the document is signed following the DataIntegrityProof spec', f proofPurpose: 'authentication' }); - await expect(async () => { - await instance.verifyProof(); - }).rejects.toThrow('Invalid proof purpose. Expected authentication but received assertionMethod'); + const result = await instance.verifyProof(); + expect(result).toEqual({ + verified: false, + verificationMethod: null, + error: 'Invalid proof purpose. Expected authentication but received assertionMethod' + }); }); }); @@ -45,9 +48,12 @@ describe('given the document is signed following the DataIntegrityProof spec', f issuer: fixtureIssuerProfile }); - await expect(async () => { - await instance.verifyProof(); - }).rejects.toThrow('The verification method https://www.blockcerts.org/samples/3.0/issuer-blockcerts.json#key-1 is not allowed for the proof purpose authentication'); + const result = await instance.verifyProof(); + expect(result).toEqual({ + verified: false, + verificationMethod: null, + error: 'The verification method https://www.blockcerts.org/samples/3.0/issuer-blockcerts.json#key-1 is not allowed for the proof purpose authentication' + }); }); }); });