Skip to content

Commit

Permalink
Prepared dist and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
iherman committed Mar 8, 2024
1 parent 3fc968d commit e9d34c2
Show file tree
Hide file tree
Showing 68 changed files with 231 additions and 191 deletions.
23 changes: 10 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ exports.generateProofGraph = generateProofGraph;
* @returns
*/
async function verifyProofGraph(dataset, proofGraph) {
// start fresh with the results:
const report = { errors: [], warnings: [] };
// this is the value that must be checked...
const hash = await (0, utils_1.calculateDatasetHash)(dataset);
// just to make the handling uniform...
const proofs = (0, utils_1.isDatasetCore)(proofGraph) ? [proofGraph] : proofGraph;
// the "convertToStore" intermediate step is necessary; the proof graph checker needs a n3.Store
const promises = proofs.map(utils_1.convertToStore).map((pr_graph) => (0, proof_utils_1.verifyAProofGraph)(report, hash, pr_graph));
const results = await Promise.all(promises);
const verified = (report.errors.length > 0) ? false : !results.includes(false);
const proofGraphs = (0, utils_1.isDatasetCore)(proofGraph) ? [proofGraph] : proofGraph;
const proofs = proofGraphs.map((pr) => {
return {
dataset: (0, utils_1.convertToStore)(pr),
id: undefined,
};
});
const verified = await (0, proof_utils_1.verifyProofGraphs)(report, hash, proofs);
return {
verified,
verifiedDocument: verified ? dataset : null,
Expand Down Expand Up @@ -154,8 +154,6 @@ exports.embedProofGraph = embedProofGraph;
* @returns
*/
async function verifyEmbeddedProofGraph(dataset, anchor) {
// start fresh with the results:
const report = { errors: [], warnings: [] };
const dataStore = new n3.Store();
const proofGraphs = new utils_1.DatasetMap();
// First, identify the possible dataset graph IDs
Expand Down Expand Up @@ -199,11 +197,10 @@ async function verifyEmbeddedProofGraph(dataset, anchor) {
dataStore.add(q);
}
}
const report = { errors: [], warnings: [] };
const hash = await (0, utils_1.calculateDatasetHash)(dataStore);
const proofs = proofGraphs.data();
const promises = proofs.map((prGraph) => (0, proof_utils_1.verifyAProofGraph)(report, hash, prGraph.dataset, prGraph.id));
const results = await Promise.all(promises);
const verified = (report.errors.length > 0) ? false : !results.includes(false);
const verified = await (0, proof_utils_1.verifyProofGraphs)(report, hash, proofs);
return {
verified,
verifiedDocument: verified ? dataStore : null,
Expand Down
7 changes: 4 additions & 3 deletions dist/lib/crypto_utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@ export declare function sign(report: Errors, message: string, secretKey: JsonWeb
*
* Possible errors are added to the report, no exceptions should be thrown.
*
* @param report
* @param report - placeholder for error reports
* @param message
* @param secretKey
* @param signature
* @param publicKey
* @returns
*/
export declare function verify(report: Errors, message: string, signature: string, publicKey: JsonWebKey): Promise<boolean>;
/**
* Mapping from the JWK data to the corresponding DI cryptosuite identifier.
*
* @param report
* @param report - placeholder for error reports
* @param keyPair
* @returns
*/
Expand Down
7 changes: 4 additions & 3 deletions dist/lib/crypto_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ exports.sign = sign;
*
* Possible errors are added to the report, no exceptions should be thrown.
*
* @param report
* @param report - placeholder for error reports
* @param message
* @param secretKey
* @param signature
* @param publicKey
* @returns
*/
async function verify(report, message, signature, publicKey) {
Expand Down Expand Up @@ -207,7 +208,7 @@ exports.verify = verify;
/**
* Mapping from the JWK data to the corresponding DI cryptosuite identifier.
*
* @param report
* @param report - placeholder for error reports
* @param keyPair
* @returns
*/
Expand Down
16 changes: 9 additions & 7 deletions dist/lib/proof_utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* @packageDocumentation
*/
import * as rdf from '@rdfjs/types';
import * as n3 from 'n3';
import { Errors, KeyData } from './types';
import { GraphWithID } from './utils';
/***************************************************************************************
* Namespaces and specific terms that are used several times
**************************************************************************************/
Expand All @@ -34,15 +34,16 @@ export declare const xsd_datetime: rdf.NamedNode;
* Generate a (separate) proof graph, per the DI spec. The signature is stored in
* [multibase format](https://www.w3.org/TR/vc-data-integrity/#multibase-0), using base64url encoding.
*
* @param report - placeholder for error reports
* @param hashValue - this is the value of the Dataset's canonical hash
* @param keyData
* @returns
*/
export declare function generateAProofGraph(report: Errors, hashValue: string, keyData: KeyData): Promise<rdf.DatasetCore>;
/**
* Check one proof graph, ie, whether the included signature corresponds to the hash value.
* Check a series of proof graphs, ie, check whether the included signature of a proof graph corresponds to the hash value.
*
* The following checks are also made:
* The following checks are also made for each proof graph:
*
* 1. There should be exactly one [proof value](https://www.w3.org/TR/vc-data-integrity/#dfn-proofvalue)
* 2. There should be exactly one [verification method](https://www.w3.org/TR/vc-data-integrity/#dfn-verificationmethod), which should be a separate resource containing the key (in JWK)
Expand All @@ -51,11 +52,12 @@ export declare function generateAProofGraph(report: Errors, hashValue: string, k
* 4. The proof's [creation date](https://www.w3.org/TR/vc-data-integrity/#dfn-created) must be before the current time
* 5. The proof [purpose(s)](https://www.w3.org/TR/vc-data-integrity/#dfn-proofpurpose) must be set, and the values are either [authentication](https://www.w3.org/TR/vc-data-integrity/#dfn-authentication) or [verification](https://www.w3.org/TR/vc-data-integrity/#dfn-verificationmethod)
*
* Errors are stored in the `report` structure. If any error occurs, the result is false.
* Errors are stored in the `report` structure.
* If any error occurs in any proof graph the result is `false`; otherwise, result is the conjunction of each individual proof graph verifications.
*
* @param report
* @param report - placeholder for error reports
* @param hash
* @param proof
* @param proofs
* @returns
*/
export declare function verifyAProofGraph(report: Errors, hash: string, proof: n3.Store, proofId?: rdf.Quad_Graph): Promise<boolean>;
export declare function verifyProofGraphs(report: Errors, hash: string, proofs: GraphWithID[]): Promise<boolean>;
52 changes: 46 additions & 6 deletions dist/lib/proof_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @packageDocumentation
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyAProofGraph = exports.generateAProofGraph = exports.xsd_datetime = exports.sec_created = exports.sec_revoked = exports.sec_expires = exports.sec_verificationMethod = exports.sec_assertionMethod = exports.sec_authenticationMethod = exports.sec_proofPurpose = exports.sec_publicKeyJwk = exports.sec_proofValue = exports.sec_di_proof = exports.sec_proof = exports.rdf_type = exports.xsd_prefix = exports.rdf_prefix = exports.sec_prefix = void 0;
exports.verifyProofGraphs = exports.generateAProofGraph = exports.xsd_datetime = exports.sec_created = exports.sec_revoked = exports.sec_expires = exports.sec_verificationMethod = exports.sec_assertionMethod = exports.sec_authenticationMethod = exports.sec_proofPurpose = exports.sec_publicKeyJwk = exports.sec_proofValue = exports.sec_di_proof = exports.sec_proof = exports.rdf_type = exports.xsd_prefix = exports.rdf_prefix = exports.sec_prefix = void 0;
const n3 = require("n3");
const uuid_1 = require("uuid");
const types = require("./types");
Expand Down Expand Up @@ -42,6 +42,7 @@ exports.xsd_datetime = (0, exports.xsd_prefix)('dateTime');
* Generate a (separate) proof graph, per the DI spec. The signature is stored in
* [multibase format](https://www.w3.org/TR/vc-data-integrity/#multibase-0), using base64url encoding.
*
* @param report - placeholder for error reports
* @param hashValue - this is the value of the Dataset's canonical hash
* @param keyData
* @returns
Expand Down Expand Up @@ -80,7 +81,7 @@ async function generateAProofGraph(report, hashValue, keyData) {
exports.generateAProofGraph = generateAProofGraph;
;
/**
* Check one proof graph, ie, whether the included signature corresponds to the hash value.
* Check a single proof graph, ie, whether the included signature corresponds to the hash value.
*
* The following checks are also made:
*
Expand All @@ -93,9 +94,10 @@ exports.generateAProofGraph = generateAProofGraph;
*
* Errors are stored in the `report` structure. If any error occurs, the result is false.
*
* @param report
* @param report - placeholder for error reports
* @param hash
* @param proof
* @param proof - the proof graph
* @param proofId - Id of the proof graph, if known; used in the error reports only
* @returns
*/
async function verifyAProofGraph(report, hash, proof, proofId) {
Expand Down Expand Up @@ -186,7 +188,7 @@ async function verifyAProofGraph(report, hash, proof, proofId) {
const publicKey = getPublicKey(proof);
const proofValue = getProofValue(proof);
// The final set of error/warning should be modified with the proof graph's ID, if applicable
if (proofId) {
if (proofId !== undefined) {
localErrors.forEach((error) => {
error.detail = `${error.detail} (graph ID: <${proofId.value}>)`;
});
Expand All @@ -206,4 +208,42 @@ async function verifyAProofGraph(report, hash, proof, proofId) {
return false;
}
}
exports.verifyAProofGraph = verifyAProofGraph;
/**
* Check a series of proof graphs, ie, check whether the included signature of a proof graph corresponds to the hash value.
*
* The following checks are also made for each proof graph:
*
* 1. There should be exactly one [proof value](https://www.w3.org/TR/vc-data-integrity/#dfn-proofvalue)
* 2. There should be exactly one [verification method](https://www.w3.org/TR/vc-data-integrity/#dfn-verificationmethod), which should be a separate resource containing the key (in JWK)
* 3. The key's (optional) [expiration](https://www.w3.org/TR/vc-data-integrity/#defn-proof-expires) and
* [revocation](https://www.w3.org/TR/vc-data-integrity/#dfn-revoked) dates are checked and compared to the current time which should be "before"
* 4. The proof's [creation date](https://www.w3.org/TR/vc-data-integrity/#dfn-created) must be before the current time
* 5. The proof [purpose(s)](https://www.w3.org/TR/vc-data-integrity/#dfn-proofpurpose) must be set, and the values are either [authentication](https://www.w3.org/TR/vc-data-integrity/#dfn-authentication) or [verification](https://www.w3.org/TR/vc-data-integrity/#dfn-verificationmethod)
*
* Errors are stored in the `report` structure.
* If any error occurs in any proof graph the result is `false`; otherwise, result is the conjunction of each individual proof graph verifications.
*
* @param report - placeholder for error reports
* @param hash
* @param proofs
* @returns
*/
async function verifyProofGraphs(report, hash, proofs) {
const allErrors = [];
const singleVerification = async (pr) => {
const singleReport = { errors: [], warnings: [] };
allErrors.push(singleReport);
return verifyAProofGraph(singleReport, hash, pr.dataset, pr.id);
};
const promises = proofs.map(singleVerification);
const result = await Promise.all(promises);
// consolidate error messages. By using allErrors the error messages
// follow the same order as the incoming proof graph references,
// and are not possibly shuffled by the async calls
for (const singleReport of allErrors) {
report.errors = [...report.errors, ...singleReport.errors];
report.warnings = [...report.warnings, ...singleReport.warnings];
}
return !result.includes(false);
}
exports.verifyProofGraphs = verifyProofGraphs;
6 changes: 3 additions & 3 deletions dist/lib/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export declare function createPrefix(uri: string): (l: string) => rdf.NamedNode;
/**
* Structure with a separate store and its ID as a graph
*/
export interface MapContent {
id: rdf.Quad_Graph;
export interface GraphWithID {
id: rdf.Quad_Graph | undefined;
dataset: n3.Store;
}
/**
Expand All @@ -55,7 +55,7 @@ export declare class DatasetMap {
item(graph: rdf.Quad_Graph): n3.Store;
has(graph: rdf.Term): boolean;
datasets(): n3.Store[];
data(): MapContent[];
data(): GraphWithID[];
}
/*****************************************************************************************
* Misc Utility Functions
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e9d34c2

Please sign in to comment.