Skip to content

Commit

Permalink
Add check script to validate implementation info.
Browse files Browse the repository at this point in the history
  • Loading branch information
BigBlueHat committed Jan 24, 2025
1 parent df13a82 commit a0cabe6
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
65 changes: 65 additions & 0 deletions check.js
Original file line number Diff line number Diff line change
@@ -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',

Check failure on line 26 in check.js

View workflow job for this annotation

GitHub Actions / lint (18.x)

This line has a length of 108. Maximum allowed is 80
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));
}
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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 ."
}
}

0 comments on commit a0cabe6

Please sign in to comment.