A library to enable parsing and verifying a Blockcert. This can be used as a node package or in a browser. The browserified script is available as verifier.js
.
npm run test
var fs = require('fs');
fs.readFile('./tests/sample_cert-valid-1.2.0.json', 'utf8', function (err, data) {
if (err) {
console.log(err);
}
let cert = Certificate.parseJson(JSON.parse(data));
console.log(cert.name);
});
var fs = require('fs');
function statusCallback(arg1) {
console.log("status=" + arg1);
}
fs.readFile('../tests/sample_cert-valid-2.0.json', 'utf8', function (err, data) {
if (err) {
console.log(err);
}
var certVerifier = new CertificateVerifier(data, statusCallback);
certVerifier.verify(function (err, data) {
if (err) {
console.log("failed");
} else {
console.log("done");
}
});
});
npm run build
generates the browserified script verifier.js
.
The following shows how you can use it:
<script src="./verifier.js"></script>
const certificateContentsString = ...
const certJson = JSON.parse(certificateContentsString);
const cert = Verifier.Certificate.parseJson(certJson);
See cert-web-component for an example.