Skip to content

Commit

Permalink
Merge pull request #107 from blockchain-certificates/feat/proof-purpose
Browse files Browse the repository at this point in the history
Feat/proof purpose
  • Loading branch information
lemoustachiste authored Dec 2, 2024
2 parents b0354e6 + 7f12d97 commit 547b9f4
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 2 deletions.
18 changes: 17 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export interface MerkleProof2019API {
verificationMethod?: IDidDocumentPublicKey;
document: VCDocument;
proof?: VCProof;
// the purpose of proof that the verifier will be used for, defaults to assertionMethod
proofPurpose?: string;
}

export interface MerkleProof2019VerificationResult {
Expand Down Expand Up @@ -61,6 +63,7 @@ export class LDMerkleProof2019 extends LinkedDataProof {
public verificationMethod: IDidDocumentPublicKey = null;
public proof: VCProof = null;
public proofValue: DecodedProof = null;
public proofPurpose: string;
public document: VCDocument = null;
public explorerAPIs: ExplorerAPI[] = [];
public chain: IBlockchainObject;
Expand Down Expand Up @@ -89,7 +92,8 @@ export class LDMerkleProof2019 extends LinkedDataProof {
verificationMethod = null,
document = null,
proof = null,
options = {}
options = {},
proofPurpose = 'assertionMethod'
}: MerkleProof2019API) {
super({ type: 'MerkleProof2019' });

Expand All @@ -100,6 +104,7 @@ export class LDMerkleProof2019 extends LinkedDataProof {
this.issuer = issuer;
this.verificationMethod = verificationMethod;
this.document = document;
this.proofPurpose = proofPurpose;
this.setProof(proof);
this.setOptions(options);
this.getChain();
Expand Down Expand Up @@ -131,6 +136,17 @@ export class LDMerkleProof2019 extends LinkedDataProof {
this.documentLoader = documentLoader;
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 {
await this.verifyProcess(this.proofVerificationProcess);
if (verifyIdentity) {
Expand Down
Loading

0 comments on commit 547b9f4

Please sign in to comment.