@govtechsg/workpass-schema
v1.0.9
Published
This library supplies the schemas used for SGworkpass 2.0, in the form of [json schemas](http://json-schema.org)
Downloads
31
Keywords
Readme
Workpass Schema v1.1
This library supplies the schemas used for SGworkpass 2.0, in the form of json schemas
Installation
Using npm:
npm install @govtechsg/workpass-schema
Usage
If you are writing a document issuer: you probably want to issue a document or issue multiple documents
If you are writing a document verifier or viewer: you probably want to issue a document or issue multiple documents
If you are writing a document verifier or viewer: you probably want to
Using OpenCerts
const openDocument = require("@govtechsg/workpass-schema")
const exampleDocument = require("example.json") // reading an example document file
openDocument.verify(exampleDocument)
Validate Schema
This library comes with the schemas in the ./schema
folder, all of them are loaded as valid schemas upon initialization.
openDocument.validateSchema(exampleDocument)
Verifying Document Signature
Documents are considered untampered-with if they have a valid signature field. Refer to the Open Attestation library for more details on this.
openDocument.verifySignature(exampleDocument)
Issue a Document
A single Document can be issued using the .issueDocument(document)
method.
Issuing a document in this manner will append a signature field to the document.
The return value of the method will be the signed document.
const issuedCert = openDocument.issueDocument(exampleDocument)
Issue Multiple Documents
Multiple Documents can be issued at once with the .issueDocuments(document[])
method.
The return value of the method will be an array of signed documents.
const exampleDocuments = [cert1, cert2, cert3, ...]
const issuedCerts = openDocument.issueDocuments(exampleDocuments)
Retrieving Document contents
The raw document has salt in the fields to prevent enumeration, we provide a convenience method to retrieve the unsalted contents of the document using the method .documentData(document)
const data = openDocument.documentData(exampleDocument)
Obfuscating Fields in a Document
To obfuscate fields in a cert, the method .obfuscateFields(document, paths[])
is provided.
The paths[] parameter is simply the JSON path for the fields to be obfuscated.
The method returns the obfuscated document.
const obfuscatedCert = openDocument.obfuscateFields(exampleDocument, [
"recipient.fin",
"recipient.occupation"
]);
Developers
The code is written to ES6 specs with stage-3 presets and is compiled by Babel.
Test
npm run test
Build
npm run build