Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
feat: adds support for providing a proofDocument with multiple proofs
Browse files Browse the repository at this point in the history
see issue #79 for additional details
  • Loading branch information
kdenhartog-mattr committed Oct 1, 2020
1 parent 38747e6 commit c28b4b6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
28 changes: 27 additions & 1 deletion __tests__/deriveProof.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import {
testSignedDocument,
customLoader,
testSignedVcDocument,
testRevealVcDocument
testRevealVcDocument,
testSignedDocumentMultiProofs,
testSignedDocumentMultiDifProofs
} from "./__fixtures__";

import { BbsBlsSignatureProof2020, deriveProof } from "../src/index";
Expand Down Expand Up @@ -49,4 +51,28 @@ describe("BbsBlsSignatureProof2020", () => {
);
expect(result).toBeDefined();
});

it("should derive proofs from multiple proof documents", async () => {
const result = await deriveProof(
testSignedDocumentMultiProofs,
testRevealDocument,
{
suite: new BbsBlsSignatureProof2020(),
documentLoader: customLoader
}
);
expect(result).toBeDefined();
});

it("should derive single proof from document with multiple different proofs", async () => {
const result = await deriveProof(
testSignedDocumentMultiDifProofs,
testRevealDocument,
{
suite: new BbsBlsSignatureProof2020(),
documentLoader: customLoader
}
);
expect(result).toBeDefined();
});
});
36 changes: 22 additions & 14 deletions src/deriveProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,37 @@ export const deriveProof = async (
expansionMap
});

const result = await suite.deriveProof({
document,
proof: proofs[0],
revealDocument,
documentLoader,
expansionMap
});
console.log("proofs: " + JSON.stringify(proofs));

let derivedProofs;

for (const proof of proofs) {
derivedProofs = await suite.deriveProof({
document,
proof,
revealDocument,
documentLoader,
expansionMap
});
}

console.log("result: " + JSON.stringify(derivedProofs));

if (!skipProofCompaction) {
/* eslint-disable prefer-const */
let expandedProof: any = {
[SECURITY_PROOF_URL]: { "@graph": result.proof }
[SECURITY_PROOF_URL]: { "@graph": derivedProofs.proof }
};

// account for type-scoped `proof` definition by getting document types
const { types, alias } = await getTypeInfo(result.document, {
const { types, alias } = await getTypeInfo(derivedProofs.document, {
documentLoader,
expansionMap
});

expandedProof["@type"] = types;

const ctx = jsonld.getValues(result.document, "@context");
const ctx = jsonld.getValues(derivedProofs.document, "@context");

const compactProof = await jsonld.compact(expandedProof, ctx, {
documentLoader,
Expand All @@ -76,11 +84,11 @@ export const deriveProof = async (

// add proof to document
const key = Object.keys(compactProof)[0];
jsonld.addValue(result.document, key, compactProof[key]);
jsonld.addValue(derivedProofs.document, key, compactProof[key]);
} else {
delete result.proof["@context"];
jsonld.addValue(result.document, "proof", result.proof);
delete derivedProofs.proof["@context"];
jsonld.addValue(derivedProofs.document, "proof", derivedProofs.proof);
}

return result.document;
return derivedProofs.document;
};

0 comments on commit c28b4b6

Please sign in to comment.