← Verifying a Document
JS Node.js verifier
Uses ajv with loadSchema to fetch the schema at validation time.
1
Install
npm install ajv ajv-formats2
Verify
verify-dbom.mjs
import Ajv2020 from "ajv/dist/2020.js";
import addFormats from "ajv-formats";
import { readFileSync } from "fs";
const SCHEMA_URL = "https://usemakoto.dev/schema/v0.1.json";
const load = uri => fetch(uri).then(r => r.json());
const dbom = JSON.parse(readFileSync(process.argv[2], "utf8"));
const ajv = new Ajv2020({ allErrors: true, loadSchema: load });
addFormats(ajv);
const validate = await ajv.compileAsync(await load(SCHEMA_URL));
const errors = [];
// structural
if (!validate(dbom))
validate.errors.forEach(e => errors.push(`[${e.instancePath||"root"}] ${e.message}`));
// provenance
const steps = dbom.lineage;
for (let i = 1; i < steps.length; i++)
if (steps[i].input_hash !== steps[i-1].output_hash)
errors.push(`step ${steps[i].step} input_hash does not match step ${steps[i-1].step} output_hash`);
if (steps.at(-1).output_hash !== dbom.source.hash.value)
errors.push("final output_hash does not match source.hash.value");
errors.forEach(e => console.error(`✗ ${e}`));
process.exit(errors.length ? 1 : 0);For production use with full error reporting, see the GitHub repo →