diff --git a/README.md b/README.md index e74f397..cf17e42 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,26 @@ on the tagged issuer and verifier endpoints. * `bbs-2023` - This tag will run the [VC Data Integrity BBS Test Suite](https://github.com/w3c/vc-di-bbs-test-suite) on the tagged issuer and verifier endpoints. +### Validating Description + +Implementation details may include more verbose vendor and implementation +descriptions by adding the following to the description JSON: + +```jsonc +{ + "@context": "https://raw.githubusercontent.com/digitalbazaar/mocha-w3c-interop-reporter/refs/heads/main/context.json", + "vendor": { + "type": "Organization", + "name": "...", + "url": "...", + "email": "..." + }, + "type": ["TestSubject", "Software"], + "name": "...implementation name...", + // the rest of the implementation details as described above +} +``` + ## Contribute See [the CONTRIBUTING.md file](CONTRIBUTING.md). diff --git a/check.js b/check.js new file mode 100644 index 0000000..feebbd9 --- /dev/null +++ b/check.js @@ -0,0 +1,65 @@ +#!/usr/bin/env node + +/* +Copyright 2025 Digital Bazaar, Inc. + +SPDX-License-Identifier: BSD-3-Clause +*/ + +import {createRequire} from 'node:module'; +import fs from 'node:fs'; +import {glob} from 'glob'; +import jsonld from 'jsonld'; +import {JsonLdDocumentLoader} from 'jsonld-document-loader'; + +const require = createRequire(import.meta.url); + +// Pass in `extract` to get context list instead of safe mode check results +const method = process.argv.at(2); + +const jdl = new JsonLdDocumentLoader(); + +// collection to track all loaded contexts +const contextUrls = new Set(); + +jdl.addStatic( + 'https://raw.githubusercontent.com/digitalbazaar/mocha-w3c-interop-reporter/refs/heads/main/context.json', + require('./context.json') +); + +const loader = jdl.build(); +jsonld.documentLoader = loader; + +let failure = false; +const paths = await glob([ + `./implementations/*.json` +]); +await Promise.all(paths.map(async implementationPath => { + const implementation = JSON.parse( + await fs.promises.readFile(implementationPath) + ); + // non-JSON-LD description, so skip it + if(!('@context' in implementation)) { + return; + } + try { + await jsonld.expand(implementation, {safe: true}); + if(method !== 'extract') { + console.log('👍 All terms correctly defined in', implementationPath); + } + } catch(err) { + if(method !== 'extract') { + console.log('😢 Errors found in', implementationPath); + } + console.dir(err, {depth: 5}); + failure = true; + } +})); + +if(failure) { + process.exit(1); +} + +if(method === 'extract') { + console.log(JSON.stringify([...contextUrls].sort(), null, 2)); +} diff --git a/package.json b/package.json index 25756f1..7bd1053 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,9 @@ "eslint-config-digitalbazaar": "^4.0.1", "eslint-plugin-jsdoc": "^39.3.3", "eslint-plugin-unicorn": "^43.0.0", + "glob": "^11.0.1", + "jsonld": "^8.3.3", + "jsonld-document-loader": "^2.2.0", "mocha": "^10.0.0", "nyc": "^15.1.0" }, @@ -70,6 +73,7 @@ "coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text-summary npm run test-node", "coverage-ci": "cross-env NODE_ENV=test nyc --reporter=lcovonly npm run test-node", "coverage-report": "nyc report", + "check": "node check.js", "lint": "eslint ." } }