├── .eslintignore ├── .gitignore ├── scripts ├── makeCerts.sh └── benchmark.sh ├── test ├── helpers.js ├── fixtures │ └── schema │ │ ├── 1.0 │ │ ├── 1.json │ │ └── 2.json │ │ ├── 1.1 │ │ ├── 1.json │ │ └── 2.json │ │ ├── 1.2 │ │ ├── 1.json │ │ └── 2.json │ │ ├── 1.3 │ │ ├── 1.json │ │ └── 2.json │ │ ├── 1.4 │ │ ├── 1.json │ │ └── 2.json │ │ ├── 1.5 │ │ ├── 1.json │ │ └── 2.json │ │ └── 2.0 │ │ ├── 1.json │ │ ├── 3.json │ │ └── 2.json └── e2e.test.js ├── .travis.yml ├── docs ├── OnChainOffChain.md ├── VulnerabilityPatch-SpoofingOtherCerts.md ├── MerkleProofAlgorithm.md └── SelectivePrivacy.md ├── lib └── logger.js ├── .eslintrc.json ├── src ├── batchVerify.js ├── diskUtils.js ├── crypto.js ├── crypto.test.js ├── batchIssue.js └── batchIssue.test.js ├── package.json ├── README.md ├── examples └── sample-certs │ ├── example.0.json │ ├── example.1.json │ └── example.2.json ├── index.js └── LICENSE /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | coverage/ 3 | certificates/ 4 | npm-debug.log 5 | .nyc_output 6 | yarn-error.log 7 | yarn.lock 8 | signed 9 | benchmark/ -------------------------------------------------------------------------------- /scripts/makeCerts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # USAGE: 4 | # ./makeCerts.sh 5 | mkdir -p ./benchmark/unsigned_certs 6 | seq $1 | xargs -P 4 -I $0 sh -c "cat ./examples/sample-certs/example.0.json | jq '.id = \"ID$0\"' > ./benchmark/unsigned_certs/cert$0.json" -------------------------------------------------------------------------------- /test/helpers.js: -------------------------------------------------------------------------------- 1 | const { addConsole } = require("../lib/logger"); 2 | 3 | addConsole("debug"); 4 | 5 | const chai = require("chai"); 6 | const chaiAsPromised = require("chai-as-promised"); 7 | 8 | chai.should(); 9 | chai.use(chaiAsPromised); 10 | 11 | global.expect = chai.expect; 12 | global.assert = chai.assert; 13 | -------------------------------------------------------------------------------- /scripts/benchmark.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | time node index.js batch ./benchmark/unsigned_certs ./benchmark/signed_certs 4 | rm -rf ./benchmark/signed_certs 5 | time node index.js batch ./benchmark/unsigned_certs ./benchmark/signed_certs 6 | rm -rf ./benchmark/signed_certs 7 | time node index.js batch ./benchmark/unsigned_certs ./benchmark/signed_certs 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - lts/* 4 | cache: npm install 5 | jobs: 6 | include: 7 | - stage: test 8 | script: 9 | - npm ci 10 | - npm run lint 11 | - npm run test 12 | - stage: deploy 13 | if: branch = master AND type != pull_request 14 | script: 15 | - npm run semantic-release 16 | stages: 17 | - test 18 | - deploy -------------------------------------------------------------------------------- /docs/OnChainOffChain.md: -------------------------------------------------------------------------------- 1 | 2 | ## On-chain or off-chain certificate/claim proof 3 | 4 | Blockcert is doing off-chain verification, that means all users who wants to verify data have to run the program or institutes will need to host these web app for them to use. 5 | 6 | On-chain verification using smart contract will allow participants to use any web-app that can interface with smart contracts to verify a certificate. This will require this to be implemented on a blockchain which supports smart contract though. -------------------------------------------------------------------------------- /lib/logger.js: -------------------------------------------------------------------------------- 1 | const { createLogger, format, transports } = require("winston"); 2 | 3 | const { combine, timestamp, printf, colorize } = format; 4 | 5 | const formatter = printf( 6 | info => `${info.timestamp} ${info.level}: ${info.message}` 7 | ); 8 | 9 | const logger = createLogger({ 10 | format: combine(timestamp(), colorize(), formatter), 11 | level: "debug" 12 | }); 13 | 14 | // Add console to winston logger 15 | const addConsole = logLevel => { 16 | logger.add( 17 | new transports.Console({ 18 | level: logLevel, 19 | colorize: true, 20 | timestamp: true, 21 | json: false, 22 | // log everything to stderr 23 | stderrLevels: ["error"] 24 | }) 25 | ); 26 | }; 27 | 28 | module.exports = { 29 | addConsole, 30 | logger, 31 | default: logger 32 | }; 33 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "airbnb-base", 4 | "prettier" 5 | ], 6 | "env": { 7 | "mocha": true 8 | }, 9 | "plugins": [ 10 | "prettier", 11 | "chai-friendly", 12 | "chai-expect", 13 | "mocha" 14 | ], 15 | "globals": { 16 | "artifacts": false, 17 | "contract": false, 18 | "assert": false, 19 | "expect": true, 20 | "web3": false 21 | }, 22 | "rules": { 23 | "no-unused-vars": [ 24 | "error", 25 | { 26 | "argsIgnorePattern": "^_" 27 | } 28 | ], 29 | "func-names": [ 30 | "error", 31 | "as-needed" 32 | ], 33 | "prettier/prettier": "error", 34 | "no-unused-expressions": "off", 35 | "mocha/no-exclusive-tests": "error", 36 | "chai-friendly/no-unused-expressions": "error", 37 | "chai-expect/no-inner-compare": "error", 38 | "chai-expect/missing-assertion": "error", 39 | "chai-expect/terminating-properties": "error" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/batchVerify.js: -------------------------------------------------------------------------------- 1 | const { readCert, certificatesInDirectory } = require("./diskUtils"); 2 | const { 3 | verifySignature, 4 | validateSchema 5 | } = require("@govtechsg/open-certificate"); 6 | const { logger } = require("../lib/logger"); 7 | 8 | const batchVerify = async (undigestedCertDir, schemaVersion) => { 9 | const certFileNames = await certificatesInDirectory(undigestedCertDir); 10 | let allVerified = true; 11 | certFileNames.forEach(file => { 12 | const certificate = readCert(undigestedCertDir, file); 13 | const validSignature = verifySignature(certificate); 14 | const validSchema = validateSchema(certificate, schemaVersion); 15 | const isValid = validSchema && validSignature; 16 | allVerified = allVerified && isValid; 17 | if (isValid) { 18 | logger.debug(`${file}: Verified`); 19 | } else { 20 | logger.error(`${file}: ======= VERIFICATION FAILED =======`); 21 | } 22 | }); 23 | return allVerified; 24 | }; 25 | 26 | module.exports = batchVerify; 27 | -------------------------------------------------------------------------------- /test/fixtures/schema/1.0/1.json: -------------------------------------------------------------------------------- 1 | { 2 | "issuedOn": "2018-08-01", 3 | "expiredOn": "2118-08-01", 4 | "name": "Master of Blockchain", 5 | "issuer": { 6 | "name": "Blockchain Academy", 7 | "did": "DID:SG-UEN:U18274928E", 8 | "url": "https://blockchainacademy.com", 9 | "email": "registrar@blockchainacademy.com", 10 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012" 11 | }, 12 | "recipient": { 13 | "name": "Mr Blockchain", 14 | "did": "DID:SG-NRIC:S99999999A", 15 | "email": "mr-blockchain@gmail.com", 16 | "phone": "+65 88888888" 17 | }, 18 | "transcript": [ 19 | { 20 | "name": "Bitcoin", 21 | "grade": "A+", 22 | "courseCredit": 3, 23 | "courseCode": "BTC-01", 24 | "url": "https://blockchainacademy.com/subject/BTC-01", 25 | "description": "Everything and more about bitcoin!" 26 | }, 27 | { 28 | "name": "Ethereum", 29 | "grade": "A+", 30 | "courseCredit": "3.5", 31 | "courseCode": "ETH-01", 32 | "url": "https://blockchainacademy.com/subject/ETH-01", 33 | "description": "Everything and more about ethereum!" 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /test/fixtures/schema/1.0/2.json: -------------------------------------------------------------------------------- 1 | { 2 | "issuedOn": "2018-08-01", 3 | "expiredOn": "2118-08-01", 4 | "name": "Master of Blockchain", 5 | "issuer": { 6 | "name": "Blockchain Academy", 7 | "did": "DID:SG-UEN:U18274928E", 8 | "url": "https://blockchainacademy.com", 9 | "email": "registrar@blockchainacademy.com", 10 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012" 11 | }, 12 | "recipient": { 13 | "name": "Mr Blockchain2", 14 | "did": "DID:SG-NRIC:S99999999A", 15 | "email": "mr-blockchain@gmail.com", 16 | "phone": "+65 88888888" 17 | }, 18 | "transcript": [ 19 | { 20 | "name": "Bitcoin", 21 | "grade": "A+", 22 | "courseCredit": 3, 23 | "courseCode": "BTC-01", 24 | "url": "https://blockchainacademy.com/subject/BTC-01", 25 | "description": "Everything and more about bitcoin!" 26 | }, 27 | { 28 | "name": "Ethereum", 29 | "grade": "A+", 30 | "courseCredit": "3.5", 31 | "courseCode": "ETH-01", 32 | "url": "https://blockchainacademy.com/subject/ETH-01", 33 | "description": "Everything and more about ethereum!" 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /src/diskUtils.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const util = require("util"); 3 | const path = require("path"); 4 | const { filter, some } = require("lodash"); 5 | const { logger } = require("../lib/logger"); 6 | 7 | const readdir = util.promisify(fs.readdir); 8 | 9 | const opencertsFileExtensions = [/(.*)(\.)(opencert)$/, /(.*)(\.)(json)$/]; 10 | 11 | function readCert(directory, filename) { 12 | try { 13 | return JSON.parse(fs.readFileSync(path.join(directory, filename))); 14 | } catch (e) { 15 | logger.error(`Failed at ${directory}${filename}`); 16 | throw e; 17 | } 18 | } 19 | 20 | function isOpenCertFileExtension(filename) { 21 | return some( 22 | opencertsFileExtensions.map(mask => mask.test(filename.toLowerCase())) 23 | ); 24 | } 25 | 26 | const certificatesInDirectory = async dir => { 27 | const items = await readdir(dir); 28 | return filter(items, isOpenCertFileExtension); 29 | }; 30 | 31 | function writeCertToDisk(destinationDir, filename, certificate) { 32 | fs.writeFileSync( 33 | path.join(path.resolve(destinationDir), filename), 34 | JSON.stringify(certificate, null, 2) 35 | ); 36 | } 37 | 38 | module.exports = { 39 | certificatesInDirectory, 40 | writeCertToDisk, 41 | readCert, 42 | readdir 43 | }; 44 | -------------------------------------------------------------------------------- /src/crypto.js: -------------------------------------------------------------------------------- 1 | const ethereumjsUtil = require("ethereumjs-util"); 2 | 3 | /* 4 | * FUNCTIONS TAKEN FROM OPEN_ATTESTATION FRAMEWORK 5 | */ 6 | 7 | /** 8 | * Sorts the given Buffers lexicographically and then concatenates them to form one continuous Buffer 9 | * @param {[Buffer]} args The buffers to concatenate 10 | */ 11 | function bufSortJoin(...args) { 12 | return Buffer.concat([...args].sort(Buffer.compare)); 13 | } 14 | 15 | /** 16 | * Returns the keccak hash of two buffers after concatenating them and sorting them 17 | * If either hash is not given, the input is returned 18 | * @param {Buffer} first A buffer to be hashed 19 | * @param {Buffer} second A buffer to be hashed 20 | */ 21 | function combinedHash(first, second) { 22 | if (!second) { 23 | return first; 24 | } 25 | if (!first) { 26 | return second; 27 | } 28 | return ethereumjsUtil.keccak256(bufSortJoin(first, second)); 29 | } 30 | 31 | /** 32 | * Returns a buffer of a given hash string 33 | * @param {Buffer} hash A hex string to be hashed (should not start with 0x) 34 | */ 35 | function hashToBuffer(hash) { 36 | return Buffer.isBuffer(hash) && hash.length === 32 37 | ? hash 38 | : Buffer.from(hash, "hex"); 39 | } 40 | 41 | module.exports = { 42 | bufSortJoin, 43 | combinedHash, 44 | hashToBuffer 45 | }; 46 | -------------------------------------------------------------------------------- /docs/VulnerabilityPatch-SpoofingOtherCerts.md: -------------------------------------------------------------------------------- 1 | ## Vulnerability Patch - Spoofing Other Certificates 2 | 3 | With both features of selective privacy and batched issurance, recipient could spoof one another's certificate data. Below is an example. 4 | 5 | ***Certificate 1*** 6 | 7 | ``` 8 | { 9 | evidence.0.name: 'Algorithms', 10 | evidence.0.description: 'E' 11 | } 12 | 13 | Issued to Recipient A 14 | MerkleRoot: 0x00A 15 | ``` 16 | 17 | ***Certificate 2*** 18 | 19 | ``` 20 | { 21 | evidence.0.name: 'Data Structure', 22 | evidence.0.description: 'A' 23 | } 24 | 25 | Issued to Recipient B 26 | MerkleRoot: 0x00B 27 | ``` 28 | 29 | Recipient A could claim to have 'A' for his Algorithms class and provide a valid claim to the merkle root. 30 | 31 | ##Solutions## 32 | 33 | 1. Issue each certificate individually. However, the gas cost is found to be linear, it will be very expensive to scale. 34 | 2. Verify entire certificate with masked data, instead of using individual claims. However, there may be information leak as we can enumerate through known grades/subjects/etc. 35 | 3. Add a salt that is unique to every certificate, allowing us to see if the data has been spoofed. Example below: 36 | 37 | ``` 38 | { 39 | evidence.0.name: '[66f5ad0]Algorithms', 40 | evidence.0.description: '[66f5ad0]E' 41 | salt:'[66f5ad0]' 42 | } 43 | 44 | Issued to Recipient A 45 | MerkleRoot: 0x00A 46 | ``` 47 | or 48 | 49 | ``` 50 | { 51 | [66f5ad0].evidence.0.name: 'Algorithms', 52 | [66f5ad0].evidence.0.description: 'E' 53 | } 54 | 55 | Issued to Recipient A 56 | MerkleRoot: 0x00A 57 | ``` -------------------------------------------------------------------------------- /test/e2e.test.js: -------------------------------------------------------------------------------- 1 | const util = require("util"); 2 | const exec = util.promisify(require("child_process").exec); 3 | const { dirSync } = require("tmp"); 4 | const fs = require("fs"); 5 | 6 | const readdir = util.promisify(fs.readdir); 7 | 8 | const testHash = hash => { 9 | const regex = /^0x[a-fA-F0-9]{64}$/; 10 | return regex.test(hash); 11 | }; 12 | 13 | const runEndToEndOnSchemaVersion = async schemaVersion => { 14 | // Setup tmp directory to store batched certificates 15 | const { name: tmpDirName, removeCallback: tmpDirCleanup } = dirSync({ 16 | unsafeCleanup: true 17 | }); 18 | 19 | try { 20 | // Batching certificates return merkle root that looks correct 21 | const batchCmd = await exec( 22 | `node . batch ./test/fixtures/schema/${schemaVersion} ${tmpDirName} --schema ${schemaVersion}` 23 | ); 24 | const outputHash = batchCmd.stdout.trim(); 25 | expect(testHash(outputHash)).to.be.eql(true); 26 | expect(batchCmd.stderr).to.be.eql(""); 27 | 28 | // Batched certificates can be verified 29 | const verifyAllCmd = await exec( 30 | `node . verify-all ${tmpDirName} --schema ${schemaVersion}` 31 | ); 32 | expect(verifyAllCmd.stdout.trim()).to.be.eql("true"); 33 | expect(verifyAllCmd.stderr).to.be.eql(""); 34 | } catch (e) { 35 | // eslint-disable-next-line no-console 36 | console.error(e); 37 | throw Error(`Failed at ${schemaVersion}`); 38 | } 39 | 40 | // Cleanup tmp dir 41 | tmpDirCleanup(); 42 | }; 43 | 44 | describe("[E2E] batch & verify-all", () => { 45 | it("batch and verify for all schema versions", async () => { 46 | const schemaVersions = await readdir("./test/fixtures/schema"); 47 | const validationPromises = schemaVersions.map(runEndToEndOnSchemaVersion); 48 | await Promise.all(validationPromises); 49 | }).timeout(60000); 50 | }); 51 | -------------------------------------------------------------------------------- /test/fixtures/schema/1.1/1.json: -------------------------------------------------------------------------------- 1 | { 2 | "issuedOn": "2018-08-01", 3 | "expiredOn": "2118-08-01", 4 | "name": "Master of Blockchain", 5 | "issuer": { 6 | "name": "Blockchain Academy", 7 | "did": "DID:SG-UEN:U18274928E", 8 | "url": "https://blockchainacademy.com", 9 | "email": "registrar@blockchainacademy.com", 10 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012" 11 | }, 12 | "recipient": { 13 | "name": "Mr Blockchain", 14 | "did": "DID:SG-NRIC:S99999999A", 15 | "email": "mr-blockchain@gmail.com", 16 | "phone": "88888888" 17 | }, 18 | "transcript": [ 19 | { 20 | "name": "Bitcoin", 21 | "grade": "A+", 22 | "courseCredit": 3, 23 | "courseCode": "BTC-01", 24 | "url": "https://blockchainacademy.com/subject/BTC-01", 25 | "description": "Everything and more about bitcoin!" 26 | }, 27 | { 28 | "name": "Ethereum", 29 | "grade": "A+", 30 | "courseCredit": "3.5", 31 | "courseCode": "ETH-01", 32 | "url": "https://blockchainacademy.com/subject/ETH-01", 33 | "description": "Everything and more about ethereum!" 34 | } 35 | ], 36 | "metadata": { 37 | "coCurricularActivities": [ 38 | { 39 | "name": "Crypto-investment Club", 40 | "position": "Club President", 41 | "startDate": "2017-08-01", 42 | "endDate": "2018-08-01", 43 | "remarks": "Top trader (2018)" 44 | } 45 | ], 46 | "npfa": "silver", 47 | "visuals": { 48 | "signature1": { 49 | "name": "Mr Important", 50 | "designation": "President", 51 | "signature": "<-- Base64 Image -->" 52 | }, 53 | "signature2": { 54 | "name": "Mr Not-So-Important", 55 | "designation": "Chairman, Blockchain Faculty", 56 | "signature": "<-- Base64 Image -->" 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test/fixtures/schema/1.1/2.json: -------------------------------------------------------------------------------- 1 | { 2 | "issuedOn": "2018-08-01", 3 | "expiredOn": "2118-08-01", 4 | "name": "Master of Blockchain", 5 | "issuer": { 6 | "name": "Blockchain Academy", 7 | "did": "DID:SG-UEN:U18274928E", 8 | "url": "https://blockchainacademy.com", 9 | "email": "registrar@blockchainacademy.com", 10 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012" 11 | }, 12 | "recipient": { 13 | "name": "Mr Blockchain", 14 | "did": "DID:SG-NRIC:S99999999A", 15 | "email": "mr-blockchain@gmail.com", 16 | "phone": "88888888" 17 | }, 18 | "transcript": [ 19 | { 20 | "name": "Bitcoin", 21 | "grade": "A+", 22 | "courseCredit": 3, 23 | "courseCode": "BTC-01", 24 | "url": "https://blockchainacademy.com/subject/BTC-01", 25 | "description": "Everything and more about bitcoin!" 26 | }, 27 | { 28 | "name": "Ethereum", 29 | "grade": "A+", 30 | "courseCredit": "3.5", 31 | "courseCode": "ETH-01", 32 | "url": "https://blockchainacademy.com/subject/ETH-01", 33 | "description": "Everything and more about ethereum!" 34 | } 35 | ], 36 | "metadata": { 37 | "coCurricularActivities": [ 38 | { 39 | "name": "Crypto-investment Club", 40 | "position": "Club President", 41 | "startDate": "2017-08-01", 42 | "endDate": "2018-08-01", 43 | "remarks": "Top trader (2018)" 44 | } 45 | ], 46 | "npfa": "silver", 47 | "visuals": { 48 | "signature1": { 49 | "name": "Mr Important", 50 | "designation": "President", 51 | "signature": "<-- Base64 Image -->" 52 | }, 53 | "signature2": { 54 | "name": "Mr Not-So-Important", 55 | "designation": "Chairman, Blockchain Faculty", 56 | "signature": "<-- Base64 Image -->" 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /docs/MerkleProofAlgorithm.md: -------------------------------------------------------------------------------- 1 | ## Merkle Proof Algorithm 2 | 3 | Blockcert makes use of [MerkleProof2017](https://w3c-dvcg.github.io/lds-merkleproof2017/) algorithm and the current implementation makes use of a [simpler merkle proof](https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/MerkleProof.sol) algorithm. 4 | 5 | MerkleProof2017 follows the standards laid out by w3c and chainpoint but takes up more data and is hard to be verified on smart contract. The simpler proof allows for merkle proof to be on the smart contract itself. 6 | 7 | **MerkleProof2017** 8 | 9 | ``` 10 | "signature": { 11 | "@context": ["http://schema.org/", "https://w3id.org/security/v1"], 12 | "type": "MerkleProof2017", 13 | "targetHash": "637ec732fa4b7b56f4c15a6a12680519a17a9e9eade09f5b424a48eb0e6f5ad0", 14 | "merkleRoot": "f029b45bb1a7b1f0b970f6de35344b73cccd16177b4c037acbc2541c7fc27078", 15 | "anchors": [ 16 | { 17 | "sourceId": "d75b7a5bdb3d5244b753e6b84e987267cfa4ffa7a532a2ed49ad3848be1d82f8", 18 | "type": "BTCOpReturn" 19 | } 20 | ], 21 | "proof": [ 22 | { 23 | "right": "11174e220fe74de907d1107e2a357e41434123f2948fc6b946fbfd7e3e3eecd1" 24 | } 25 | ] 26 | } 27 | ``` 28 | 29 | **Current Implementation** 30 | 31 | ``` 32 | "merkleRoot": "458a80232eda8a816972be8ac731feb50727149aff6287d70142821ae160caf7", 33 | "targetHash": "9e4480202dada872369b987a9550a4af3f00e5889c542a4caf6f1d22aaff629a", 34 | "proof": [ 35 | "9321c3437a3057b6b7e2ac560deb36bf35e5de3f37cb205f7202e13e9eee9572", 36 | "6c0c0f5b71203c93fcb58bfc728f91b952a51767a8c4c2a065bac50112eed67f", 37 | "1938b479936220efc593ef5b6cc8919cff0a0800b54be49f5fb285d7f28f3ab0", 38 | "87c332c2a439f52fd41c6d818925776f503b7094e599b74bcd13af2698fa82d4", 39 | "35414d4dd3c0cd275bfec92cc7ba0cd28b3dbcf40e8074f8672d5bc6195067ef", 40 | "90de2449c8102ed2ab6334b5fa09b4cb604ca444ddfe77100694d84b09df4bfb" 41 | ] 42 | ``` 43 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@govtechsg/certificate-cli", 3 | "version": "3.1.3", 4 | "description": "", 5 | "main": "index.js", 6 | "bin": { 7 | "opencert": "./index.js" 8 | }, 9 | "scripts": { 10 | "test": "nyc --reporter=html mocha --timeout 5000 -- ./test/helpers.js './test/**/*.test.js' './src/**/*.test.js'", 11 | "test-watch": "mocha ./test/helpers.js './test/**/*.test.js' './src/**/*.test.js' --watch --recursive", 12 | "lint": "eslint . --ext .js --max-warnings 0", 13 | "lint:fix": "eslint . --ext .js --fix", 14 | "benchmark:make-certs": "./scripts/makeCerts.sh 20000", 15 | "benchmark:run": "./scripts/benchmark.sh", 16 | "benchmark:clean": "rm -rf ./benchmark", 17 | "benchmark:full": "npm run benchmark:make-certs && npm run benchmark:run && npm run benchmark:clean", 18 | "semantic-release": "semantic-release" 19 | }, 20 | "author": "", 21 | "license": "ISC", 22 | "devDependencies": { 23 | "chai": "^4.1.2", 24 | "chai-as-promised": "^7.1.1", 25 | "eslint": "^4.17.0", 26 | "eslint-config-airbnb-base": "^12.1.0", 27 | "eslint-config-prettier": "^2.9.0", 28 | "eslint-plugin-chai-expect": "^1.1.1", 29 | "eslint-plugin-chai-friendly": "^0.4.1", 30 | "eslint-plugin-import": "^2.8.0", 31 | "eslint-plugin-mocha": "^4.11.0", 32 | "eslint-plugin-prettier": "^2.6.0", 33 | "mocha": "^4.1.0", 34 | "nyc": "^13.3.0", 35 | "prettier": "^1.10.2", 36 | "sinon": "^7.2.3" 37 | }, 38 | "dependencies": { 39 | "@govtechsg/open-certificate": "2.0.17", 40 | "ethereumjs-util": "^6.0.0", 41 | "json-schema-faker": "^0.5.0-rc9", 42 | "lodash": "^4.17.5", 43 | "mkdirp": "^0.5.1", 44 | "proxyquire": "^2.1.0", 45 | "semantic-release": "^15.13.18", 46 | "tmp": "^0.0.33", 47 | "winston": "^3.0.0-rc1", 48 | "yargs": "^11.0.0" 49 | }, 50 | "publishConfig": { 51 | "access": "public" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/crypto.test.js: -------------------------------------------------------------------------------- 1 | const crypto = require("./crypto"); 2 | 3 | describe("crypto", () => { 4 | describe("bufSortJoin", () => { 5 | it("should work", () => { 6 | const res = crypto.bufSortJoin( 7 | Buffer.from("c"), 8 | Buffer.from("b"), 9 | Buffer.from("a") 10 | ); 11 | const expectedResults = "616263"; 12 | expect(res.hexSlice()).to.deep.equal(expectedResults); 13 | }); 14 | }); 15 | 16 | describe("hashToBuffer", () => { 17 | it("should work", () => { 18 | expect(crypto.hashToBuffer("foo")).to.deep.equal( 19 | Buffer.from("foo", "hex") 20 | ); 21 | }); 22 | 23 | it("should do nothing if the input is a hash", () => { 24 | const originalBuffer = Buffer.from("foo", "utf8"); 25 | expect(crypto.hashToBuffer(originalBuffer)).to.deep.equal(originalBuffer); 26 | }); 27 | }); 28 | 29 | describe("combinedhash", () => { 30 | it("join two hashes in deterministic order", () => { 31 | const h1 = Buffer.from("a1", "hex"); 32 | const h2 = Buffer.from("a2", "hex"); 33 | const h12 = crypto.combinedHash(h1, h2); 34 | const h21 = crypto.combinedHash(h2, h1); 35 | 36 | expect(h12.toString("hex")).to.eql( 37 | "e95ec1a8fd9150296b7b972879f2b15d636fded6d2f2a5bc68784945eab5bd2f" 38 | ); 39 | expect(h21.toString("hex")).to.eql( 40 | "e95ec1a8fd9150296b7b972879f2b15d636fded6d2f2a5bc68784945eab5bd2f" 41 | ); 42 | }); 43 | 44 | it("returns input if only one is provided", () => { 45 | const h1 = Buffer.from( 46 | "e95ec1a8fd9150296b7b972879f2b15d636fded6d2f2a5bc68784945eab5bd2f", 47 | "hex" 48 | ); 49 | const h1x = crypto.combinedHash(h1); 50 | const hx1 = crypto.combinedHash(null, h1); 51 | 52 | expect(h1x.toString("hex")).to.eql( 53 | "e95ec1a8fd9150296b7b972879f2b15d636fded6d2f2a5bc68784945eab5bd2f" 54 | ); 55 | expect(hx1.toString("hex")).to.eql( 56 | "e95ec1a8fd9150296b7b972879f2b15d636fded6d2f2a5bc68784945eab5bd2f" 57 | ); 58 | }); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /test/fixtures/schema/1.2/1.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "SERIAL-2018-08-01-112", 3 | "$template": "BLOCKCHAIN-ACADEMY-2018-001", 4 | "issuedOn": "2018-08-01T00:00:00+08:00", 5 | "expiredOn": "2118-08-01T00:00:00+08:00", 6 | "name": "Master of Blockchain", 7 | "admissionDate": "2017-08-01T00:00:00+08:00", 8 | "graduationDate": "2018-08-01T00:00:00+08:00", 9 | "issuers": [ 10 | { 11 | "name": "Blockchain Academy", 12 | "did": "DID:SG-UEN:U18274928E", 13 | "url": "https://blockchainacademy.com", 14 | "email": "registrar@blockchainacademy.com", 15 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012" 16 | }, 17 | { 18 | "name": "School of Crypto-economics", 19 | "url": "https://ceschool.sg", 20 | "certificateStore": "0xA33ddAEE02369D18A21E29dD2E7A12d65eE671d2" 21 | } 22 | ], 23 | "recipient": { 24 | "name": "Mr Blockchain", 25 | "did": "DID:SG-NRIC:S99999999A", 26 | "email": "mr-blockchain@gmail.com", 27 | "phone": "+65 88888888" 28 | }, 29 | "transcript": [ 30 | { 31 | "name": "Bitcoin", 32 | "grade": "A+", 33 | "courseCredit": 3, 34 | "courseCode": "BTC-01", 35 | "examinationDate": "2018-08-01T00:00:00+08:00", 36 | "url": "https://blockchainacademy.com/subject/BTC-01", 37 | "description": "Everything and more about bitcoin!" 38 | }, 39 | { 40 | "name": "Ethereum", 41 | "grade": "A+", 42 | "courseCredit": "3.5", 43 | "courseCode": "ETH-01", 44 | "examinationDate": "2018-08-01T00:00:00+08:00", 45 | "url": "https://blockchainacademy.com/subject/ETH-01", 46 | "description": "Everything and more about ethereum!" 47 | } 48 | ], 49 | "cumulativeScore": 3.9935, 50 | "additionalData": { 51 | "coCurricularActivities": [ 52 | { 53 | "name": "Crypto-investment Club", 54 | "position": "Club President", 55 | "startDate": "2017-08-01T00:00:00+08:00", 56 | "endDate": "2018-08-01T00:00:00+08:00", 57 | "remarks": "Top trader (2018)" 58 | } 59 | ], 60 | "npfa": "silver", 61 | "images": { 62 | "signature1": { 63 | "name": "Mr Important", 64 | "designation": "President", 65 | "signature": "<-- Base64 Image -->" 66 | }, 67 | "signature2": { 68 | "name": "Mr Not-So-Important", 69 | "designation": "Chairman, Blockchain Faculty", 70 | "signature": "<-- Base64 Image -->" 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/fixtures/schema/1.2/2.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "SERIAL-2018-08-01-112", 3 | "$template": "BLOCKCHAIN-ACADEMY-2018-001", 4 | "issuedOn": "2018-08-01T00:00:00+08:00", 5 | "expiredOn": "2118-08-01T00:00:00+08:00", 6 | "name": "Master of Blockchain", 7 | "admissionDate": "2017-08-01T00:00:00+08:00", 8 | "graduationDate": "2018-08-01T00:00:00+08:00", 9 | "issuers": [ 10 | { 11 | "name": "Blockchain Academy", 12 | "did": "DID:SG-UEN:U18274928E", 13 | "url": "https://blockchainacademy.com", 14 | "email": "registrar@blockchainacademy.com", 15 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012" 16 | }, 17 | { 18 | "name": "School of Crypto-economics", 19 | "url": "https://ceschool.sg", 20 | "certificateStore": "0xA33ddAEE02369D18A21E29dD2E7A12d65eE671d2" 21 | } 22 | ], 23 | "recipient": { 24 | "name": "Mr Blockchain", 25 | "did": "DID:SG-NRIC:S99999999A", 26 | "email": "mr-blockchain@gmail.com", 27 | "phone": "+65 88888888" 28 | }, 29 | "transcript": [ 30 | { 31 | "name": "Bitcoin", 32 | "grade": "A+", 33 | "courseCredit": 3, 34 | "courseCode": "BTC-01", 35 | "examinationDate": "2018-08-01T00:00:00+08:00", 36 | "url": "https://blockchainacademy.com/subject/BTC-01", 37 | "description": "Everything and more about bitcoin!" 38 | }, 39 | { 40 | "name": "Ethereum", 41 | "grade": "A+", 42 | "courseCredit": "3.5", 43 | "courseCode": "ETH-01", 44 | "examinationDate": "2018-08-01T00:00:00+08:00", 45 | "url": "https://blockchainacademy.com/subject/ETH-01", 46 | "description": "Everything and more about ethereum!" 47 | } 48 | ], 49 | "cumulativeScore": 3.9935, 50 | "additionalData": { 51 | "coCurricularActivities": [ 52 | { 53 | "name": "Crypto-investment Club", 54 | "position": "Club President", 55 | "startDate": "2017-08-01T00:00:00+08:00", 56 | "endDate": "2018-08-01T00:00:00+08:00", 57 | "remarks": "Top trader (2018)" 58 | } 59 | ], 60 | "npfa": "silver", 61 | "images": { 62 | "signature1": { 63 | "name": "Mr Important", 64 | "designation": "President", 65 | "signature": "<-- Base64 Image -->" 66 | }, 67 | "signature2": { 68 | "name": "Mr Not-So-Important", 69 | "designation": "Chairman, Blockchain Faculty", 70 | "signature": "<-- Base64 Image -->" 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/fixtures/schema/1.3/1.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "SERIAL-2018-08-01-112", 3 | "$template": "BLOCKCHAIN-ACADEMY-2018-001", 4 | "issuedOn": "2018-08-01T00:00:00+08:00", 5 | "expiresOn": "2118-08-01T00:00:00+08:00", 6 | "name": "Master of Blockchain", 7 | "admissionDate": "2017-08-01T00:00:00+08:00", 8 | "graduationDate": "2018-08-01T00:00:00+08:00", 9 | "issuers": [ 10 | { 11 | "name": "Blockchain Academy", 12 | "did": "DID:SG-UEN:U18274928E", 13 | "url": "https://blockchainacademy.com", 14 | "email": "registrar@blockchainacademy.com", 15 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012" 16 | }, 17 | { 18 | "name": "School of Crypto-economics", 19 | "url": "https://ceschool.sg", 20 | "certificateStore": "0xA33ddAEE02369D18A21E29dD2E7A12d65eE671d2" 21 | } 22 | ], 23 | "recipient": { 24 | "name": "Mr Blockchain", 25 | "did": "DID:SG-NRIC:S99999999A", 26 | "email": "mr-blockchain@gmail.com", 27 | "phone": "+65 88888888" 28 | }, 29 | "transcript": [ 30 | { 31 | "name": "Bitcoin", 32 | "grade": "A+", 33 | "courseCredit": 3, 34 | "courseCode": "BTC-01", 35 | "examinationDate": "2018-08-01T00:00:00+08:00", 36 | "url": "https://blockchainacademy.com/subject/BTC-01", 37 | "description": "Everything and more about bitcoin!" 38 | }, 39 | { 40 | "name": "Ethereum", 41 | "grade": "A+", 42 | "courseCredit": "3.5", 43 | "courseCode": "ETH-01", 44 | "examinationDate": "2018-08-01T00:00:00+08:00", 45 | "url": "https://blockchainacademy.com/subject/ETH-01", 46 | "description": "Everything and more about ethereum!" 47 | } 48 | ], 49 | "cumulativeScore": 3.9935, 50 | "additionalData": { 51 | "coCurricularActivities": [ 52 | { 53 | "name": "Crypto-investment Club", 54 | "position": "Club President", 55 | "startDate": "2017-08-01T00:00:00+08:00", 56 | "endDate": "2018-08-01T00:00:00+08:00", 57 | "remarks": "Top trader (2018)" 58 | } 59 | ], 60 | "npfa": "silver", 61 | "images": { 62 | "signature1": { 63 | "name": "Mr Important", 64 | "designation": "President", 65 | "signature": "<-- Base64 Image -->" 66 | }, 67 | "signature2": { 68 | "name": "Mr Not-So-Important", 69 | "designation": "Chairman, Blockchain Faculty", 70 | "signature": "<-- Base64 Image -->" 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/fixtures/schema/1.3/2.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "SERIAL-2018-08-01-112", 3 | "$template": "BLOCKCHAIN-ACADEMY-2018-001", 4 | "issuedOn": "2018-08-01T00:00:00+08:00", 5 | "expiresOn": "2118-08-01T00:00:00+08:00", 6 | "name": "Master of Blockchain", 7 | "admissionDate": "2017-08-01T00:00:00+08:00", 8 | "graduationDate": "2018-08-01T00:00:00+08:00", 9 | "issuers": [ 10 | { 11 | "name": "Blockchain Academy", 12 | "did": "DID:SG-UEN:U18274928E", 13 | "url": "https://blockchainacademy.com", 14 | "email": "registrar@blockchainacademy.com", 15 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012" 16 | }, 17 | { 18 | "name": "School of Crypto-economics", 19 | "url": "https://ceschool.sg", 20 | "certificateStore": "0xA33ddAEE02369D18A21E29dD2E7A12d65eE671d2" 21 | } 22 | ], 23 | "recipient": { 24 | "name": "Mr Blockchain", 25 | "did": "DID:SG-NRIC:S99999999A", 26 | "email": "mr-blockchain@gmail.com", 27 | "phone": "+65 88888888" 28 | }, 29 | "transcript": [ 30 | { 31 | "name": "Bitcoin", 32 | "grade": "A+", 33 | "courseCredit": 3, 34 | "courseCode": "BTC-01", 35 | "examinationDate": "2018-08-01T00:00:00+08:00", 36 | "url": "https://blockchainacademy.com/subject/BTC-01", 37 | "description": "Everything and more about bitcoin!" 38 | }, 39 | { 40 | "name": "Ethereum", 41 | "grade": "A+", 42 | "courseCredit": "3.5", 43 | "courseCode": "ETH-01", 44 | "examinationDate": "2018-08-01T00:00:00+08:00", 45 | "url": "https://blockchainacademy.com/subject/ETH-01", 46 | "description": "Everything and more about ethereum!" 47 | } 48 | ], 49 | "cumulativeScore": 3.9935, 50 | "additionalData": { 51 | "coCurricularActivities": [ 52 | { 53 | "name": "Crypto-investment Club", 54 | "position": "Club President", 55 | "startDate": "2017-08-01T00:00:00+08:00", 56 | "endDate": "2018-08-01T00:00:00+08:00", 57 | "remarks": "Top trader (2018)" 58 | } 59 | ], 60 | "npfa": "silver", 61 | "images": { 62 | "signature1": { 63 | "name": "Mr Important", 64 | "designation": "President", 65 | "signature": "<-- Base64 Image -->" 66 | }, 67 | "signature2": { 68 | "name": "Mr Not-So-Important", 69 | "designation": "Chairman, Blockchain Faculty", 70 | "signature": "<-- Base64 Image -->" 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/fixtures/schema/1.4/1.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "SERIAL-2018-08-01-112", 3 | "$template": "BLOCKCHAIN-ACADEMY-2018-001", 4 | "description": "This masters is awarded to developers who can blockchain", 5 | "issuedOn": "2018-08-01T00:00:00+08:00", 6 | "expiresOn": "2118-08-01T00:00:00+08:00", 7 | "name": "Master of Blockchain", 8 | "admissionDate": "2017-08-01T00:00:00+08:00", 9 | "graduationDate": "2018-08-01T00:00:00+08:00", 10 | "issuers": [ 11 | { 12 | "name": "Blockchain Academy", 13 | "did": "DID:SG-UEN:U18274928E", 14 | "url": "https://blockchainacademy.com", 15 | "email": "registrar@blockchainacademy.com", 16 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012", 17 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000" 18 | }, 19 | { 20 | "name": "School of Crypto-economics", 21 | "url": "https://ceschool.sg", 22 | "certificateStore": "0xA33ddAEE02369D18A21E29dD2E7A12d65eE671d2" 23 | } 24 | ], 25 | "recipient": { 26 | "name": "Mr Blockchain", 27 | "did": "DID:SG-NRIC:S99999999A", 28 | "email": "mr-blockchain@gmail.com", 29 | "phone": "+65 88888888", 30 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000" 31 | }, 32 | "transcript": [ 33 | { 34 | "name": "Bitcoin", 35 | "grade": "A+", 36 | "courseCredit": 3, 37 | "courseCode": "BTC-01", 38 | "examinationDate": "2018-08-01T00:00:00+08:00", 39 | "url": "https://blockchainacademy.com/subject/BTC-01", 40 | "description": "Everything and more about bitcoin!" 41 | }, 42 | { 43 | "name": "Ethereum", 44 | "grade": "A+", 45 | "courseCredit": "3.5", 46 | "courseCode": "ETH-01", 47 | "examinationDate": "2018-08-01T00:00:00+08:00", 48 | "url": "https://blockchainacademy.com/subject/ETH-01", 49 | "description": "Everything and more about ethereum!" 50 | } 51 | ], 52 | "cumulativeScore": 3.9935, 53 | "additionalData": { 54 | "coCurricularActivities": [ 55 | { 56 | "name": "Crypto-investment Club", 57 | "position": "Club President", 58 | "startDate": "2017-08-01T00:00:00+08:00", 59 | "endDate": "2018-08-01T00:00:00+08:00", 60 | "remarks": "Top trader (2018)" 61 | } 62 | ], 63 | "npfa": "silver", 64 | "images": { 65 | "signature1": { 66 | "name": "Mr Important", 67 | "designation": "President", 68 | "signature": "<-- Base64 Image -->" 69 | }, 70 | "signature2": { 71 | "name": "Mr Not-So-Important", 72 | "designation": "Chairman, Blockchain Faculty", 73 | "signature": "<-- Base64 Image -->" 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /test/fixtures/schema/1.4/2.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "SERIAL-2018-08-01-112", 3 | "$template": "BLOCKCHAIN-ACADEMY-2018-001", 4 | "description": "This masters is awarded to developers who can blockchain", 5 | "issuedOn": "2018-08-01T00:00:00+08:00", 6 | "expiresOn": "2118-08-01T00:00:00+08:00", 7 | "name": "Master of Blockchain", 8 | "admissionDate": "2017-08-01T00:00:00+08:00", 9 | "graduationDate": "2018-08-01T00:00:00+08:00", 10 | "issuers": [ 11 | { 12 | "name": "Blockchain Academy", 13 | "did": "DID:SG-UEN:U18274928E", 14 | "url": "https://blockchainacademy.com", 15 | "email": "registrar@blockchainacademy.com", 16 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012", 17 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000" 18 | }, 19 | { 20 | "name": "School of Crypto-economics", 21 | "url": "https://ceschool.sg", 22 | "certificateStore": "0xA33ddAEE02369D18A21E29dD2E7A12d65eE671d2" 23 | } 24 | ], 25 | "recipient": { 26 | "name": "Mr Blockchain", 27 | "did": "DID:SG-NRIC:S99999999A", 28 | "email": "mr-blockchain@gmail.com", 29 | "phone": "+65 88888888", 30 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000" 31 | }, 32 | "transcript": [ 33 | { 34 | "name": "Bitcoin", 35 | "grade": "A+", 36 | "courseCredit": 3, 37 | "courseCode": "BTC-01", 38 | "examinationDate": "2018-08-01T00:00:00+08:00", 39 | "url": "https://blockchainacademy.com/subject/BTC-01", 40 | "description": "Everything and more about bitcoin!" 41 | }, 42 | { 43 | "name": "Ethereum", 44 | "grade": "A+", 45 | "courseCredit": "3.5", 46 | "courseCode": "ETH-01", 47 | "examinationDate": "2018-08-01T00:00:00+08:00", 48 | "url": "https://blockchainacademy.com/subject/ETH-01", 49 | "description": "Everything and more about ethereum!" 50 | } 51 | ], 52 | "cumulativeScore": 3.9935, 53 | "additionalData": { 54 | "coCurricularActivities": [ 55 | { 56 | "name": "Crypto-investment Club", 57 | "position": "Club President", 58 | "startDate": "2017-08-01T00:00:00+08:00", 59 | "endDate": "2018-08-01T00:00:00+08:00", 60 | "remarks": "Top trader (2018)" 61 | } 62 | ], 63 | "npfa": "silver", 64 | "images": { 65 | "signature1": { 66 | "name": "Mr Important", 67 | "designation": "President", 68 | "signature": "<-- Base64 Image -->" 69 | }, 70 | "signature2": { 71 | "name": "Mr Not-So-Important", 72 | "designation": "Chairman, Blockchain Faculty", 73 | "signature": "<-- Base64 Image -->" 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This package has been deprecated 2 | If you need to: 3 | - wrap/issue/obfuscate/ verify(cli) document, use https://github.com/Open-Attestation/open-attestation-cli 4 | - verify (programmatically) v2 document (only), use https://github.com/Open-Attestation/oa-verify 5 | - verify (programmatically) v1 and v2 documents, use https://github.com/OpenCerts/verify/ 6 | 7 | # Certificate CLI tool 8 | 9 | ## Setup 10 | 11 | ```bash 12 | npm install -g @govtechsg/certificate-cli 13 | ``` 14 | 15 | ### Windows 16 | 17 | For Windows you need to set up the toolchain for node-gyp before installing this repository, follow the instructions in https://github.com/nodejs/node-gyp#on-windows. 18 | 19 | ## Batching Certificates 20 | 21 | This command process all certificates in the input directory and issue all of them in a single 22 | batch. It will then add the signature to the individual certificates. 23 | 24 | ```bash 25 | ./index.js batch 26 | ``` 27 | 28 | Example: 29 | 30 | ```bash 31 | ./index.js batch ./certificates/raw-certificates/ ./certificates/processed-certificates/ 32 | 33 | 2019-02-11T08:37:44.848Z info: Batch Certificate Root: 0xf51030c5751a646284c898cff0f9d833c64a50d6f307b61f2c96c3c838b13bfc 34 | ``` 35 | 36 | ## Verifying All Signed Certificate in a Directory 37 | 38 | This command verifies that the certificate (and all it's evidence) is valid and is part of the certificate batch. However, it does not verify that the batch's merkle root is stored on the blockchain. User will need to verify that the certificate has indeed been issued by checking with the issuer's smart contract. 39 | 40 | ```bash 41 | ./index.js verify-all 42 | ``` 43 | 44 | Example: 45 | 46 | ```bash 47 | ./index.js verify-all ./certificates/processed-certificates 48 | 49 | 2019-02-11T08:38:36.767Z info: All certificates in ./certificates/processed-certificates is verified 50 | ``` 51 | 52 | ## Verifying Single Signed Certificate 53 | sign 54 | This command verifies that the certificate (and all it's evidence) is valid and is part of the certificate batch. However, it does not verify that the batch's merkle root is stored on the blockchain. User will need to verify that the certificate has indeed been issued by checking with the issuer's smart contract. 55 | 56 | ```bash 57 | ./index.js verify 58 | ``` 59 | 60 | Example: 61 | 62 | ```bash 63 | ./index.js verify ./certificates/processed-certificates/urn:uuid:08b1f10a-6bf0-46c8-bbfd-64750b0d73ef.json 64 | 65 | 2019-02-11T08:41:17.301Z info: Certificate's signature is valid! 66 | 2019-02-11T08:41:17.302Z warn: Warning: Please verify this certificate on the blockchain with the issuer's certificate store. 67 | ``` 68 | 69 | ## Certificate privacy filter 70 | 71 | This allows certificate holders to generate valid certificates which hides certain evidences. Useful for hiding grades lol. 72 | 73 | ```bash 74 | ./index.js filter [filters...] 75 | ``` 76 | 77 | Example: 78 | 79 | ```bash 80 | ./index.js filter signed/example1.json signed/example1.out.json transcript.0.grade transcript.1.grade 81 | 82 | 2019-02-11T08:43:50.643Z info: Obfuscated certificate saved to: signed/example1.out.json 83 | ``` 84 | 85 | ## Version 86 | 87 | ``` 88 | ./index.js --version 89 | ``` 90 | 91 | ## Test 92 | 93 | ``` 94 | npm run test 95 | ``` 96 | -------------------------------------------------------------------------------- /test/fixtures/schema/1.5/1.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "SERIAL-2018-08-01-112", 3 | "$template": "BLOCKCHAIN-ACADEMY-2018-001", 4 | "description": "This masters is awarded to developers who can blockchain", 5 | "issuedOn": "2018-08-01T00:00:00+08:00", 6 | "expiresOn": "2118-08-01T00:00:00+08:00", 7 | "name": "Master of Blockchain", 8 | "admissionDate": "2017-07-01T00:00:00+08:00", 9 | "graduationDate": "2018-08-01T00:00:00+08:00", 10 | "attainmentDate": "2018-07-25T00:00:00+08:00", 11 | "issuers": [ 12 | { 13 | "name": "Blockchain Academy", 14 | "did": "DID:SG-UEN:U18274928E", 15 | "url": "https://blockchainacademy.com", 16 | "email": "registrar@blockchainacademy.com", 17 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012", 18 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000" 19 | }, 20 | { 21 | "name": "School of Crypto-economics", 22 | "url": "https://ceschool.sg", 23 | "certificateStore": "0xA33ddAEE02369D18A21E29dD2E7A12d65eE671d2" 24 | } 25 | ], 26 | "recipient": { 27 | "name": "Mr Blockchain", 28 | "did": "DID:SG-NRIC:S99999999A", 29 | "email": "mr-blockchain@gmail.com", 30 | "phone": "+65 88888888", 31 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000", 32 | "nric": "S0000001Z", 33 | "fin": "F0000001Z", 34 | "studentId": "1232" 35 | }, 36 | "qualificationLevel": [ 37 | { 38 | "frameworkName": "singapore/ssec-eqa", 39 | "frameworkVersion": "2015", 40 | "code": "51", 41 | "description": "Polytechnic Diploma" 42 | }, 43 | { 44 | "frameworkName": "international/isced", 45 | "frameworkVersion": "2011", 46 | "code": "55", 47 | "description": "(Short-cycle tertiary education) Vocational" 48 | } 49 | ], 50 | "fieldOfStudy": [ 51 | { 52 | "frameworkName": "singapore/ssec-fos", 53 | "frameworkVersion": "2015", 54 | "code": "0897", 55 | "description": "Biomedical Science" 56 | } 57 | ], 58 | "transcript": [ 59 | { 60 | "name": "Bitcoin", 61 | "grade": "A+", 62 | "courseCredit": 3, 63 | "courseCode": "BTC-01", 64 | "examinationDate": "2018-08-01T00:00:00+08:00", 65 | "url": "https://blockchainacademy.com/subject/BTC-01", 66 | "description": "Everything and more about bitcoin!" 67 | }, 68 | { 69 | "name": "Ethereum", 70 | "grade": "A+", 71 | "courseCredit": "3.5", 72 | "courseCode": "ETH-01", 73 | "examinationDate": "2018-08-01T00:00:00+08:00", 74 | "url": "https://blockchainacademy.com/subject/ETH-01", 75 | "description": "Everything and more about ethereum!" 76 | } 77 | ], 78 | "cumulativeScore": 3.9935, 79 | "additionalData": { 80 | "coCurricularActivities": [ 81 | { 82 | "name": "Crypto-investment Club", 83 | "position": "Club President", 84 | "startDate": "2017-08-01T00:00:00+08:00", 85 | "endDate": "2018-08-01T00:00:00+08:00", 86 | "remarks": "Top trader (2018)" 87 | } 88 | ], 89 | "npfa": "silver", 90 | "images": { 91 | "signature1": { 92 | "name": "Mr Important", 93 | "designation": "President", 94 | "signature": "<-- Base64 Image -->" 95 | }, 96 | "signature2": { 97 | "name": "Mr Not-So-Important", 98 | "designation": "Chairman, Blockchain Faculty", 99 | "signature": "<-- Base64 Image -->" 100 | } 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /test/fixtures/schema/1.5/2.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "SERIAL-2018-08-01-112", 3 | "$template": "BLOCKCHAIN-ACADEMY-2018-001", 4 | "description": "This masters is awarded to developers who can blockchain", 5 | "issuedOn": "2018-08-01T00:00:00+08:00", 6 | "expiresOn": "2118-08-01T00:00:00+08:00", 7 | "name": "Master of Blockchain", 8 | "admissionDate": "2017-07-01T00:00:00+08:00", 9 | "graduationDate": "2018-08-01T00:00:00+08:00", 10 | "attainmentDate": "2018-07-25T00:00:00+08:00", 11 | "issuers": [ 12 | { 13 | "name": "Blockchain Academy", 14 | "did": "DID:SG-UEN:U18274928E", 15 | "url": "https://blockchainacademy.com", 16 | "email": "registrar@blockchainacademy.com", 17 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012", 18 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000" 19 | }, 20 | { 21 | "name": "School of Crypto-economics", 22 | "url": "https://ceschool.sg", 23 | "certificateStore": "0xA33ddAEE02369D18A21E29dD2E7A12d65eE671d2" 24 | } 25 | ], 26 | "recipient": { 27 | "name": "Mr Blockchain", 28 | "did": "DID:SG-NRIC:S99999999A", 29 | "email": "mr-blockchain@gmail.com", 30 | "phone": "+65 88888888", 31 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000", 32 | "nric": "S0000001Z", 33 | "fin": "F0000001Z", 34 | "studentId": "1232" 35 | }, 36 | "qualificationLevel": [ 37 | { 38 | "frameworkName": "singapore/ssec-eqa", 39 | "frameworkVersion": "2015", 40 | "code": "51", 41 | "description": "Polytechnic Diploma" 42 | }, 43 | { 44 | "frameworkName": "international/isced", 45 | "frameworkVersion": "2011", 46 | "code": "55", 47 | "description": "(Short-cycle tertiary education) Vocational" 48 | } 49 | ], 50 | "fieldOfStudy": [ 51 | { 52 | "frameworkName": "singapore/ssec-fos", 53 | "frameworkVersion": "2015", 54 | "code": "0897", 55 | "description": "Biomedical Science" 56 | } 57 | ], 58 | "transcript": [ 59 | { 60 | "name": "Bitcoin", 61 | "grade": "A+", 62 | "courseCredit": 3, 63 | "courseCode": "BTC-01", 64 | "examinationDate": "2018-08-01T00:00:00+08:00", 65 | "url": "https://blockchainacademy.com/subject/BTC-01", 66 | "description": "Everything and more about bitcoin!" 67 | }, 68 | { 69 | "name": "Ethereum", 70 | "grade": "A+", 71 | "courseCredit": "3.5", 72 | "courseCode": "ETH-01", 73 | "examinationDate": "2018-08-01T00:00:00+08:00", 74 | "url": "https://blockchainacademy.com/subject/ETH-01", 75 | "description": "Everything and more about ethereum!" 76 | } 77 | ], 78 | "cumulativeScore": 3.9935, 79 | "additionalData": { 80 | "coCurricularActivities": [ 81 | { 82 | "name": "Crypto-investment Club", 83 | "position": "Club President", 84 | "startDate": "2017-08-01T00:00:00+08:00", 85 | "endDate": "2018-08-01T00:00:00+08:00", 86 | "remarks": "Top trader (2018)" 87 | } 88 | ], 89 | "npfa": "silver", 90 | "images": { 91 | "signature1": { 92 | "name": "Mr Important", 93 | "designation": "President", 94 | "signature": "<-- Base64 Image -->" 95 | }, 96 | "signature2": { 97 | "name": "Mr Not-So-Important", 98 | "designation": "Chairman, Blockchain Faculty", 99 | "signature": "<-- Base64 Image -->" 100 | } 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /examples/sample-certs/example.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "SERIAL-2018-08-01-112", 3 | "$template": { 4 | "name": "GOVTECH_DEMO", 5 | "type": "EMBEDDED_RENDERER", 6 | "url": "https://demo-renderer.opencerts.io" 7 | }, 8 | "description": "This masters is awarded to developers who can blockchain", 9 | "issuedOn": "2018-08-01T00:00:00+08:00", 10 | "expiresOn": "2118-08-01T00:00:00+08:00", 11 | "name": "Master of Blockchain", 12 | "admissionDate": "2017-07-01T00:00:00+08:00", 13 | "graduationDate": "2018-08-01T00:00:00+08:00", 14 | "attainmentDate": "2018-07-25T00:00:00+08:00", 15 | "issuers": [ 16 | { 17 | "name": "Blockchain Academy", 18 | "did": "DID:SG-UEN:U18274928E", 19 | "url": "https://blockchainacademy.com", 20 | "email": "registrar@blockchainacademy.com", 21 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012", 22 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000" 23 | }, 24 | { 25 | "name": "School of Crypto-economics", 26 | "url": "https://ceschool.sg", 27 | "certificateStore": "0xA33ddAEE02369D18A21E29dD2E7A12d65eE671d2" 28 | } 29 | ], 30 | "recipient": { 31 | "name": "Mr Blockchain", 32 | "did": "DID:SG-NRIC:S99999999A", 33 | "email": "mr-blockchain@gmail.com", 34 | "phone": "+65 88888888", 35 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000", 36 | "nric": "S0000001Z", 37 | "fin": "F0000001Z", 38 | "studentId": "1232" 39 | }, 40 | "qualificationLevel": [ 41 | { 42 | "frameworkName": "singapore/ssec-eqa", 43 | "frameworkVersion": "2015", 44 | "code": "51", 45 | "description": "Polytechnic Diploma" 46 | }, 47 | { 48 | "frameworkName": "international/isced", 49 | "frameworkVersion": "2011", 50 | "code": "55", 51 | "description": "(Short-cycle tertiary education) Vocational" 52 | } 53 | ], 54 | "fieldOfStudy": [ 55 | { 56 | "frameworkName": "singapore/ssec-fos", 57 | "frameworkVersion": "2015", 58 | "code": "0897", 59 | "description": "Biomedical Science" 60 | } 61 | ], 62 | "transcript": [ 63 | { 64 | "name": "Bitcoin", 65 | "grade": "A+", 66 | "courseCredit": 3, 67 | "courseCode": "BTC-01", 68 | "examinationDate": "2018-08-01T00:00:00+08:00", 69 | "url": "https://blockchainacademy.com/subject/BTC-01", 70 | "description": "Everything and more about bitcoin!" 71 | }, 72 | { 73 | "name": "Ethereum", 74 | "grade": "A+", 75 | "courseCredit": "3.5", 76 | "courseCode": "ETH-01", 77 | "examinationDate": "2018-08-01T00:00:00+08:00", 78 | "url": "https://blockchainacademy.com/subject/ETH-01", 79 | "description": "Everything and more about ethereum!" 80 | } 81 | ], 82 | "cumulativeScore": 3.9935, 83 | "additionalData": { 84 | "coCurricularActivities": [ 85 | { 86 | "name": "Crypto-investment Club", 87 | "position": "Club President", 88 | "startDate": "2017-08-01T00:00:00+08:00", 89 | "endDate": "2018-08-01T00:00:00+08:00", 90 | "remarks": "Top trader (2018)" 91 | } 92 | ], 93 | "npfa": "silver", 94 | "images": { 95 | "signature1": { 96 | "name": "Mr Important", 97 | "designation": "President", 98 | "signature": "<-- Base64 Image -->" 99 | }, 100 | "signature2": { 101 | "name": "Mr Not-So-Important", 102 | "designation": "Chairman, Blockchain Faculty", 103 | "signature": "<-- Base64 Image -->" 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /examples/sample-certs/example.1.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "SERIAL-2018-08-01-113", 3 | "$template": { 4 | "name": "GOVTECH_DEMO", 5 | "type": "EMBEDDED_RENDERER", 6 | "url": "https://demo-renderer.opencerts.io" 7 | }, 8 | "description": "This masters is awarded to developers who can blockchain", 9 | "issuedOn": "2018-08-01T00:00:00+08:00", 10 | "expiresOn": "2118-08-01T00:00:00+08:00", 11 | "name": "Master of Blockchain", 12 | "admissionDate": "2017-07-01T00:00:00+08:00", 13 | "graduationDate": "2018-08-01T00:00:00+08:00", 14 | "attainmentDate": "2018-07-25T00:00:00+08:00", 15 | "issuers": [ 16 | { 17 | "name": "Blockchain Academy", 18 | "did": "DID:SG-UEN:U18274928E", 19 | "url": "https://blockchainacademy.com", 20 | "email": "registrar@blockchainacademy.com", 21 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012", 22 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000" 23 | }, 24 | { 25 | "name": "School of Crypto-economics", 26 | "url": "https://ceschool.sg", 27 | "certificateStore": "0xA33ddAEE02369D18A21E29dD2E7A12d65eE671d2" 28 | } 29 | ], 30 | "recipient": { 31 | "name": "Mr Blockchain", 32 | "did": "DID:SG-NRIC:S99999999A", 33 | "email": "mr-blockchain@gmail.com", 34 | "phone": "+65 88888888", 35 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000", 36 | "nric": "S0000001Z", 37 | "fin": "F0000001Z", 38 | "studentId": "1232" 39 | }, 40 | "qualificationLevel": [ 41 | { 42 | "frameworkName": "singapore/ssec-eqa", 43 | "frameworkVersion": "2015", 44 | "code": "51", 45 | "description": "Polytechnic Diploma" 46 | }, 47 | { 48 | "frameworkName": "international/isced", 49 | "frameworkVersion": "2011", 50 | "code": "55", 51 | "description": "(Short-cycle tertiary education) Vocational" 52 | } 53 | ], 54 | "fieldOfStudy": [ 55 | { 56 | "frameworkName": "singapore/ssec-fos", 57 | "frameworkVersion": "2015", 58 | "code": "0897", 59 | "description": "Biomedical Science" 60 | } 61 | ], 62 | "transcript": [ 63 | { 64 | "name": "Bitcoin", 65 | "grade": "A+", 66 | "courseCredit": 3, 67 | "courseCode": "BTC-01", 68 | "examinationDate": "2018-08-01T00:00:00+08:00", 69 | "url": "https://blockchainacademy.com/subject/BTC-01", 70 | "description": "Everything and more about bitcoin!" 71 | }, 72 | { 73 | "name": "Ethereum", 74 | "grade": "A+", 75 | "courseCredit": "3.5", 76 | "courseCode": "ETH-01", 77 | "examinationDate": "2018-08-01T00:00:00+08:00", 78 | "url": "https://blockchainacademy.com/subject/ETH-01", 79 | "description": "Everything and more about ethereum!" 80 | } 81 | ], 82 | "cumulativeScore": 3.9935, 83 | "additionalData": { 84 | "coCurricularActivities": [ 85 | { 86 | "name": "Crypto-investment Club", 87 | "position": "Club President", 88 | "startDate": "2017-08-01T00:00:00+08:00", 89 | "endDate": "2018-08-01T00:00:00+08:00", 90 | "remarks": "Top trader (2018)" 91 | } 92 | ], 93 | "npfa": "silver", 94 | "images": { 95 | "signature1": { 96 | "name": "Mr Important", 97 | "designation": "President", 98 | "signature": "<-- Base64 Image -->" 99 | }, 100 | "signature2": { 101 | "name": "Mr Not-So-Important", 102 | "designation": "Chairman, Blockchain Faculty", 103 | "signature": "<-- Base64 Image -->" 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /examples/sample-certs/example.2.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "SERIAL-2018-08-01-114", 3 | "$template": { 4 | "name": "GOVTECH_DEMO", 5 | "type": "EMBEDDED_RENDERER", 6 | "url": "https://demo-renderer.opencerts.io" 7 | }, 8 | "description": "This masters is awarded to developers who can blockchain", 9 | "issuedOn": "2018-08-01T00:00:00+08:00", 10 | "expiresOn": "2118-08-01T00:00:00+08:00", 11 | "name": "Master of Blockchain", 12 | "admissionDate": "2017-07-01T00:00:00+08:00", 13 | "graduationDate": "2018-08-01T00:00:00+08:00", 14 | "attainmentDate": "2018-07-25T00:00:00+08:00", 15 | "issuers": [ 16 | { 17 | "name": "Blockchain Academy", 18 | "did": "DID:SG-UEN:U18274928E", 19 | "url": "https://blockchainacademy.com", 20 | "email": "registrar@blockchainacademy.com", 21 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012", 22 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000" 23 | }, 24 | { 25 | "name": "School of Crypto-economics", 26 | "url": "https://ceschool.sg", 27 | "certificateStore": "0xA33ddAEE02369D18A21E29dD2E7A12d65eE671d2" 28 | } 29 | ], 30 | "recipient": { 31 | "name": "Mr Blockchain", 32 | "did": "DID:SG-NRIC:S99999999A", 33 | "email": "mr-blockchain@gmail.com", 34 | "phone": "+65 88888888", 35 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000", 36 | "nric": "S0000001Z", 37 | "fin": "F0000001Z", 38 | "studentId": "1232" 39 | }, 40 | "qualificationLevel": [ 41 | { 42 | "frameworkName": "singapore/ssec-eqa", 43 | "frameworkVersion": "2015", 44 | "code": "51", 45 | "description": "Polytechnic Diploma" 46 | }, 47 | { 48 | "frameworkName": "international/isced", 49 | "frameworkVersion": "2011", 50 | "code": "55", 51 | "description": "(Short-cycle tertiary education) Vocational" 52 | } 53 | ], 54 | "fieldOfStudy": [ 55 | { 56 | "frameworkName": "singapore/ssec-fos", 57 | "frameworkVersion": "2015", 58 | "code": "0897", 59 | "description": "Biomedical Science" 60 | } 61 | ], 62 | "transcript": [ 63 | { 64 | "name": "Bitcoin", 65 | "grade": "A+", 66 | "courseCredit": 3, 67 | "courseCode": "BTC-01", 68 | "examinationDate": "2018-08-01T00:00:00+08:00", 69 | "url": "https://blockchainacademy.com/subject/BTC-01", 70 | "description": "Everything and more about bitcoin!" 71 | }, 72 | { 73 | "name": "Ethereum", 74 | "grade": "A+", 75 | "courseCredit": "3.5", 76 | "courseCode": "ETH-01", 77 | "examinationDate": "2018-08-01T00:00:00+08:00", 78 | "url": "https://blockchainacademy.com/subject/ETH-01", 79 | "description": "Everything and more about ethereum!" 80 | } 81 | ], 82 | "cumulativeScore": 3.9935, 83 | "additionalData": { 84 | "coCurricularActivities": [ 85 | { 86 | "name": "Crypto-investment Club", 87 | "position": "Club President", 88 | "startDate": "2017-08-01T00:00:00+08:00", 89 | "endDate": "2018-08-01T00:00:00+08:00", 90 | "remarks": "Top trader (2018)" 91 | } 92 | ], 93 | "npfa": "silver", 94 | "images": { 95 | "signature1": { 96 | "name": "Mr Important", 97 | "designation": "President", 98 | "signature": "<-- Base64 Image -->" 99 | }, 100 | "signature2": { 101 | "name": "Mr Not-So-Important", 102 | "designation": "Chairman, Blockchain Faculty", 103 | "signature": "<-- Base64 Image -->" 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /test/fixtures/schema/2.0/1.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "SERIAL-2018-08-01-112", 3 | "$template": { 4 | "name": "CUSTOM_TEMPLATE", 5 | "type": "EMBEDDED_RENDERER", 6 | "url": "https://demo-renderer.opencerts.io" 7 | }, 8 | "description": "This masters is awarded to developers who can blockchain", 9 | "issuedOn": "2018-08-01T00:00:00+08:00", 10 | "expiresOn": "2118-08-01T00:00:00+08:00", 11 | "name": "Master of Blockchain", 12 | "admissionDate": "2017-07-01T00:00:00+08:00", 13 | "graduationDate": "2018-08-01T00:00:00+08:00", 14 | "attainmentDate": "2018-07-25T00:00:00+08:00", 15 | "issuers": [ 16 | { 17 | "name": "Blockchain Academy", 18 | "did": "DID:SG-UEN:U18274928E", 19 | "url": "https://blockchainacademy.com", 20 | "email": "registrar@blockchainacademy.com", 21 | "documentStore": "0xd9580260be45c3c0c2fb259a82f219b513054012", 22 | "identityProof": { 23 | "type": "DNS-TXT", 24 | "location": "example.com" 25 | }, 26 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000" 27 | }, 28 | { 29 | "name": "School of Crypto-economics", 30 | "url": "https://ceschool.sg", 31 | "documentStore": "0xA33ddAEE02369D18A21E29dD2E7A12d65eE671d2" 32 | } 33 | ], 34 | "recipient": { 35 | "name": "Mr Blockchain", 36 | "did": "DID:SG-NRIC:S99999999A", 37 | "email": "mr-blockchain@gmail.com", 38 | "phone": "+65 88888888", 39 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000", 40 | "nric": "S0000001Z", 41 | "fin": "F0000001Z", 42 | "studentId": "1232" 43 | }, 44 | "qualificationLevel": [ 45 | { 46 | "frameworkName": "singapore/ssec-eqa", 47 | "frameworkVersion": "2015", 48 | "code": "51", 49 | "description": "Polytechnic Diploma" 50 | }, 51 | { 52 | "frameworkName": "international/isced", 53 | "frameworkVersion": "2011", 54 | "code": "55", 55 | "description": "(Short-cycle tertiary education) Vocational" 56 | } 57 | ], 58 | "fieldOfStudy": [ 59 | { 60 | "frameworkName": "singapore/ssec-fos", 61 | "frameworkVersion": "2015", 62 | "code": "0897", 63 | "description": "Biomedical Science" 64 | } 65 | ], 66 | "transcript": [ 67 | { 68 | "name": "Bitcoin", 69 | "grade": "A+", 70 | "courseCredit": 3, 71 | "courseCode": "BTC-01", 72 | "examinationDate": "2018-08-01T00:00:00+08:00", 73 | "url": "https://blockchainacademy.com/subject/BTC-01", 74 | "description": "Everything and more about bitcoin!" 75 | }, 76 | { 77 | "name": "Ethereum", 78 | "grade": "A+", 79 | "courseCredit": "3.5", 80 | "courseCode": "ETH-01", 81 | "examinationDate": "2018-08-01T00:00:00+08:00", 82 | "url": "https://blockchainacademy.com/subject/ETH-01", 83 | "description": "Everything and more about ethereum!" 84 | } 85 | ], 86 | "cumulativeScore": 3.9935, 87 | "additionalData": { 88 | "coCurricularActivities": [ 89 | { 90 | "name": "Crypto-investment Club", 91 | "position": "Club President", 92 | "startDate": "2017-08-01T00:00:00+08:00", 93 | "endDate": "2018-08-01T00:00:00+08:00", 94 | "remarks": "Top trader (2018)" 95 | } 96 | ], 97 | "npfa": "silver", 98 | "images": { 99 | "signature1": { 100 | "name": "Mr Important", 101 | "designation": "President", 102 | "signature": "<-- Base64 Image -->" 103 | }, 104 | "signature2": { 105 | "name": "Mr Not-So-Important", 106 | "designation": "Chairman, Blockchain Faculty", 107 | "signature": "<-- Base64 Image -->" 108 | } 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /test/fixtures/schema/2.0/3.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "SERIAL-2018-08-01-112", 3 | "$template": { 4 | "name": "CUSTOM_TEMPLATE", 5 | "type": "EMBEDDED_RENDERER", 6 | "url": "https://demo-renderer.opencerts.io" 7 | }, 8 | "description": "This masters is awarded to developers who can blockchain", 9 | "issuedOn": "2018-08-01T00:00:00+08:00", 10 | "expiresOn": "2118-08-01T00:00:00+08:00", 11 | "name": "Master of Blockchain", 12 | "admissionDate": "2017-07-01T00:00:00+08:00", 13 | "graduationDate": "2018-08-01T00:00:00+08:00", 14 | "attainmentDate": "2018-07-25T00:00:00+08:00", 15 | "issuers": [ 16 | { 17 | "name": "Blockchain Academy", 18 | "did": "DID:SG-UEN:U18274928E", 19 | "url": "https://blockchainacademy.com", 20 | "email": "registrar@blockchainacademy.com", 21 | "certificateStore": "0xd9580260be45c3c0c2fb259a82f219b513054012", 22 | "identityProof": { 23 | "type": "DNS-TXT", 24 | "location": "example.com" 25 | }, 26 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000" 27 | }, 28 | { 29 | "name": "School of Crypto-economics", 30 | "url": "https://ceschool.sg", 31 | "certificateStore": "0xA33ddAEE02369D18A21E29dD2E7A12d65eE671d2" 32 | } 33 | ], 34 | "recipient": { 35 | "name": "Mr Blockchain", 36 | "did": "DID:SG-NRIC:S99999999A", 37 | "email": "mr-blockchain@gmail.com", 38 | "phone": "+65 88888888", 39 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000", 40 | "nric": "S0000001Z", 41 | "fin": "F0000001Z", 42 | "studentId": "1232" 43 | }, 44 | "qualificationLevel": [ 45 | { 46 | "frameworkName": "singapore/ssec-eqa", 47 | "frameworkVersion": "2015", 48 | "code": "51", 49 | "description": "Polytechnic Diploma" 50 | }, 51 | { 52 | "frameworkName": "international/isced", 53 | "frameworkVersion": "2011", 54 | "code": "55", 55 | "description": "(Short-cycle tertiary education) Vocational" 56 | } 57 | ], 58 | "fieldOfStudy": [ 59 | { 60 | "frameworkName": "singapore/ssec-fos", 61 | "frameworkVersion": "2015", 62 | "code": "0897", 63 | "description": "Biomedical Science" 64 | } 65 | ], 66 | "transcript": [ 67 | { 68 | "name": "Bitcoin", 69 | "grade": "A+", 70 | "courseCredit": 3, 71 | "courseCode": "BTC-01", 72 | "examinationDate": "2018-08-01T00:00:00+08:00", 73 | "url": "https://blockchainacademy.com/subject/BTC-01", 74 | "description": "Everything and more about bitcoin!" 75 | }, 76 | { 77 | "name": "Ethereum", 78 | "grade": "A+", 79 | "courseCredit": "3.5", 80 | "courseCode": "ETH-01", 81 | "examinationDate": "2018-08-01T00:00:00+08:00", 82 | "url": "https://blockchainacademy.com/subject/ETH-01", 83 | "description": "Everything and more about ethereum!" 84 | } 85 | ], 86 | "cumulativeScore": 3.9935, 87 | "additionalData": { 88 | "coCurricularActivities": [ 89 | { 90 | "name": "Crypto-investment Club", 91 | "position": "Club President", 92 | "startDate": "2017-08-01T00:00:00+08:00", 93 | "endDate": "2018-08-01T00:00:00+08:00", 94 | "remarks": "Top trader (2018)" 95 | } 96 | ], 97 | "npfa": "silver", 98 | "images": { 99 | "signature1": { 100 | "name": "Mr Important", 101 | "designation": "President", 102 | "signature": "<-- Base64 Image -->" 103 | }, 104 | "signature2": { 105 | "name": "Mr Not-So-Important", 106 | "designation": "Chairman, Blockchain Faculty", 107 | "signature": "<-- Base64 Image -->" 108 | } 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /test/fixtures/schema/2.0/2.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "SERIAL-2018-08-01-113", 3 | "$template": { 4 | "name": "CUSTOM_TEMPLATE", 5 | "type": "EMBEDDED_RENDERER", 6 | "url": "https://demo-renderer.opencerts.io" 7 | }, 8 | "description": "This masters is awarded to developers who can blockchain", 9 | "issuedOn": "2018-08-01T00:00:00+08:00", 10 | "expiresOn": "2118-08-01T00:00:00+08:00", 11 | "name": "Master of Blockchain", 12 | "admissionDate": "2017-07-01T00:00:00+08:00", 13 | "graduationDate": "2018-08-01T00:00:00+08:00", 14 | "attainmentDate": "2018-07-25T00:00:00+08:00", 15 | "issuers": [ 16 | { 17 | "name": "Blockchain Academy", 18 | "did": "DID:SG-UEN:U18274928E", 19 | "url": "https://blockchainacademy.com", 20 | "email": "registrar@blockchainacademy.com", 21 | "documentStore": "0xd9580260be45c3c0c2fb259a82f219b513054012", 22 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000" 23 | }, 24 | { 25 | "name": "School of Crypto-economics", 26 | "url": "https://ceschool.sg", 27 | "documentStore": "0xA33ddAEE02369D18A21E29dD2E7A12d65eE671d2" 28 | } 29 | ], 30 | "recipient": { 31 | "name": "Mr Blockchain 2", 32 | "did": "DID:SG-NRIC:S99999999A", 33 | "email": "mr-blockchain@gmail.com", 34 | "phone": "+65 88888888", 35 | "additionalProp": "0x0000000000000000000000000000000000000000000000000000000000000000", 36 | "nric": "S0000001Z", 37 | "fin": "F0000001Z", 38 | "studentId": "1232" 39 | }, 40 | "qualificationLevel": [ 41 | { 42 | "frameworkName": "singapore/ssec-eqa", 43 | "frameworkVersion": "2015", 44 | "code": "51", 45 | "description": "Polytechnic Diploma" 46 | }, 47 | { 48 | "frameworkName": "international/isced", 49 | "frameworkVersion": "2011", 50 | "code": "55", 51 | "description": "(Short-cycle tertiary education) Vocational" 52 | } 53 | ], 54 | "fieldOfStudy": [ 55 | { 56 | "frameworkName": "singapore/ssec-fos", 57 | "frameworkVersion": "2015", 58 | "code": "0897", 59 | "description": "Biomedical Science" 60 | } 61 | ], 62 | "transcript": [ 63 | { 64 | "name": "Bitcoin", 65 | "grade": "A+", 66 | "courseCredit": 3, 67 | "courseCode": "BTC-01", 68 | "examinationDate": "2018-08-01T00:00:00+08:00", 69 | "url": "https://blockchainacademy.com/subject/BTC-01", 70 | "description": "Everything and more about bitcoin!" 71 | }, 72 | { 73 | "name": "Ethereum", 74 | "grade": "A+", 75 | "courseCredit": "3.5", 76 | "courseCode": "ETH-01", 77 | "examinationDate": "2018-08-01T00:00:00+08:00", 78 | "url": "https://blockchainacademy.com/subject/ETH-01", 79 | "description": "Everything and more about ethereum!" 80 | } 81 | ], 82 | "cumulativeScore": 3.9935, 83 | "additionalData": { 84 | "coCurricularActivities": [ 85 | { 86 | "name": "Crypto-investment Club", 87 | "position": "Club President", 88 | "startDate": "2017-08-01T00:00:00+08:00", 89 | "endDate": "2018-08-01T00:00:00+08:00", 90 | "remarks": "Top trader (2018)" 91 | } 92 | ], 93 | "npfa": "silver", 94 | "images": { 95 | "signature1": { 96 | "name": "Mr Important", 97 | "designation": "President", 98 | "signature": "<-- Base64 Image -->" 99 | }, 100 | "signature2": { 101 | "name": "Mr Not-So-Important", 102 | "designation": "Chairman, Blockchain Faculty", 103 | "signature": "<-- Base64 Image -->" 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/batchIssue.js: -------------------------------------------------------------------------------- 1 | const { 2 | readCert, 3 | writeCertToDisk, 4 | certificatesInDirectory 5 | } = require("./diskUtils"); 6 | const { dirSync } = require("tmp"); 7 | const mkdirp = require("mkdirp"); 8 | const { issueCertificate } = require("@govtechsg/open-certificate"); 9 | const { combinedHash, hashToBuffer } = require("./crypto"); 10 | 11 | const digestCertificate = async ( 12 | undigestedCertDir, 13 | digestedCertDir, 14 | schemaVersion 15 | ) => { 16 | const hashArray = []; 17 | const certFileNames = await certificatesInDirectory(undigestedCertDir); 18 | certFileNames.forEach(file => { 19 | // Read individual certificate 20 | const certificate = readCert(undigestedCertDir, file); 21 | // Digest individual certificate 22 | const digest = issueCertificate(certificate, schemaVersion); 23 | hashArray.push(hashToBuffer(digest.signature.merkleRoot)); 24 | // Write digested certificate to new directory 25 | writeCertToDisk(digestedCertDir, file, digest); 26 | }); 27 | return hashArray; 28 | }; 29 | 30 | const appendProofToCerts = async ( 31 | intermediateDir, 32 | digestedCertDir, 33 | hashMap 34 | ) => { 35 | const certFileNames = await certificatesInDirectory(intermediateDir); 36 | let merkleRoot; 37 | certFileNames.forEach(file => { 38 | const certificate = readCert(intermediateDir, file); 39 | 40 | const certificateHash = certificate.signature.targetHash; 41 | const proof = []; 42 | let candidateRoot = certificateHash; 43 | let nextStep = hashMap[certificateHash]; 44 | while (nextStep) { 45 | // nextStep will be empty when there is no parent 46 | proof.push(nextStep.sibling); 47 | candidateRoot = nextStep.parent; 48 | nextStep = hashMap[candidateRoot]; 49 | } 50 | 51 | certificate.signature.proof = proof; 52 | certificate.signature.merkleRoot = candidateRoot; 53 | if (!merkleRoot) merkleRoot = candidateRoot; 54 | 55 | writeCertToDisk(digestedCertDir, file, certificate); 56 | }); 57 | 58 | return merkleRoot; 59 | }; 60 | 61 | const merkleHashmap = leafHashes => { 62 | const hashMap = {}; 63 | const hashArray = [leafHashes]; 64 | 65 | let merklingCompleted = false; 66 | while (!merklingCompleted) { 67 | const currentLayerIndex = hashArray.length - 1; 68 | const nextLayerIndex = hashArray.length; 69 | const currentLayer = hashArray[currentLayerIndex]; 70 | hashArray.push([]); 71 | 72 | const layerLength = currentLayer.length; 73 | for (let i = 0; i < layerLength - 1; i += 2) { 74 | const element1 = currentLayer[i]; 75 | const element2 = currentLayer[i + 1]; 76 | 77 | const nextHash = combinedHash(element1, element2); 78 | 79 | hashMap[element1.toString("hex")] = { 80 | sibling: element2.toString("hex"), 81 | parent: nextHash.toString("hex") 82 | }; 83 | hashMap[element2.toString("hex")] = { 84 | sibling: element1.toString("hex"), 85 | parent: nextHash.toString("hex") 86 | }; 87 | 88 | hashArray[nextLayerIndex].push(nextHash); 89 | } 90 | // If odd number, push last element to next layer 91 | if (currentLayer.length % 2 === 1) { 92 | hashArray[nextLayerIndex].push(currentLayer[currentLayer.length - 1]); 93 | } 94 | 95 | if (hashArray[nextLayerIndex].length === 1) merklingCompleted = true; 96 | } 97 | 98 | return hashMap; 99 | }; 100 | 101 | const batchIssue = async (inputDir, outputDir, schemaVersion) => { 102 | // Create output dir 103 | mkdirp.sync(outputDir); 104 | 105 | // Create intermediate dir 106 | const { name: intermediateDir, removeCallback } = dirSync({ 107 | unsafeCleanup: true 108 | }); 109 | 110 | // Phase 1: For each certificate, read content, digest and write to file 111 | const individualCertificateHashes = await digestCertificate( 112 | inputDir, 113 | intermediateDir, 114 | schemaVersion 115 | ); 116 | 117 | if (!individualCertificateHashes || individualCertificateHashes.length === 0) 118 | throw new Error(`No certificates found in ${inputDir}`); 119 | 120 | // Phase 2: Efficient merkling to build hashmap 121 | const hashMap = merkleHashmap(individualCertificateHashes); 122 | 123 | // Phase 3: Add proofs to signedCertificates 124 | const merkleRoot = await appendProofToCerts( 125 | intermediateDir, 126 | outputDir, 127 | hashMap, 128 | () => removeCallback() 129 | ); 130 | 131 | // Remove intermediate dir 132 | removeCallback(); 133 | 134 | return merkleRoot; 135 | }; 136 | 137 | module.exports = { 138 | digestCertificate, 139 | appendProofToCerts, 140 | merkleHashmap, 141 | batchIssue 142 | }; 143 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const fs = require("fs"); 3 | const mkdirp = require("mkdirp"); 4 | const yargs = require("yargs"); 5 | const { 6 | validateSchema, 7 | verifySignature, 8 | obfuscateFields, 9 | schemas 10 | } = require("@govtechsg/open-certificate"); 11 | const batchVerify = require("./src/batchVerify"); 12 | const { batchIssue } = require("./src/batchIssue"); 13 | const { logger, addConsole } = require("./lib/logger"); 14 | const { version } = require("./package.json"); 15 | 16 | // Pass argv with $1 and $2 sliced 17 | const parseArguments = argv => 18 | yargs 19 | .version(version) 20 | .usage("Certificate issuing, verification and revocation tool.") 21 | .strict() 22 | .epilogue( 23 | "The common subcommands you might be interested in are:\n" + 24 | "- batch\n" + 25 | "- verify\n" + 26 | "- verify-all\n" + 27 | "- filter" 28 | ) 29 | .options({ 30 | "log-level": { 31 | choices: ["error", "warn", "info", "verbose", "debug", "silly"], 32 | default: "info", 33 | description: "Set the log level", 34 | global: true 35 | }, 36 | schema: { 37 | choices: Object.keys(schemas), 38 | description: "Set the schema to use", 39 | default: Object.keys(schemas)[Object.keys(schemas).length - 1], 40 | global: true, 41 | type: "string" 42 | } 43 | }) 44 | .command({ 45 | command: "filter [fields..]", 46 | description: "Obfuscate fields in the certificate", 47 | builder: sub => 48 | sub 49 | .positional("source", { 50 | description: "Source signed certificate filename", 51 | normalize: true 52 | }) 53 | .positional("destination", { 54 | description: "Destination to write obfuscated certificate file to", 55 | normalize: true 56 | }) 57 | }) 58 | .command({ 59 | command: "verify [options] ", 60 | description: "Verify the certificate", 61 | builder: sub => 62 | sub.positional("file", { 63 | description: "Certificate file to verify", 64 | normalize: true 65 | }) 66 | }) 67 | .command({ 68 | command: "verify-all [options] ", 69 | description: "Verify all certiifcate in a directory", 70 | builder: sub => 71 | sub.positional("dir", { 72 | description: "Directory with all certificates to verify", 73 | normalize: true 74 | }) 75 | }) 76 | .command({ 77 | command: "batch [options] ", 78 | description: 79 | "Combine a directory of certificates into a certificate batch", 80 | builder: sub => 81 | sub 82 | .positional("raw-dir", { 83 | description: 84 | "Directory containing the raw unissued and unsigned certificates", 85 | normalize: true 86 | }) 87 | .positional("batched-dir", { 88 | description: "Directory to output the batched certificates to.", 89 | normalize: true 90 | }) 91 | }) 92 | .parse(argv); 93 | 94 | const batch = async (raw, batched, schemaVersion) => { 95 | mkdirp.sync(batched); 96 | return batchIssue(raw, batched, schemaVersion) 97 | .then(merkleRoot => { 98 | logger.debug(`Batch Certificate Root: 0x${merkleRoot}`); 99 | return `0x${merkleRoot}`; 100 | }) 101 | .catch(err => { 102 | logger.error(err); 103 | }); 104 | }; 105 | 106 | const verifyAll = async (dir, schemaVersion) => { 107 | const verified = await batchVerify(dir, schemaVersion); 108 | if (verified) { 109 | logger.debug(`All certificates in ${dir} is verified`); 110 | return true; 111 | } 112 | logger.error("At least one certificate failed verification"); 113 | return false; 114 | }; 115 | 116 | const verify = (file, schemaVersion) => { 117 | const certificateJson = JSON.parse(fs.readFileSync(file, "utf8")); 118 | if ( 119 | verifySignature(certificateJson) && 120 | validateSchema(certificateJson, schemaVersion) 121 | ) { 122 | logger.debug("Certificate's signature is valid!"); 123 | logger.warn( 124 | "Warning: Please verify this certificate on the blockchain with the issuer's certificate store." 125 | ); 126 | } else { 127 | logger.error("Certificate's signature is invalid"); 128 | } 129 | 130 | return true; 131 | }; 132 | 133 | const obfuscate = (input, output, fields) => { 134 | const certificateJson = JSON.parse(fs.readFileSync(input, "utf8")); 135 | const obfuscatedCertificate = obfuscateFields(certificateJson, fields); 136 | const isValid = 137 | verifySignature(obfuscatedCertificate) && 138 | validateSchema(obfuscatedCertificate); 139 | 140 | if (!isValid) { 141 | logger.error( 142 | "Privacy filtering caused document to fail schema or signature validation" 143 | ); 144 | } else { 145 | fs.writeFileSync(output, JSON.stringify(obfuscatedCertificate, null, 2)); 146 | logger.debug(`Obfuscated certificate saved to: ${output}`); 147 | } 148 | }; 149 | 150 | const main = async argv => { 151 | const args = parseArguments(argv); 152 | addConsole(args.logLevel); 153 | logger.debug(`Parsed args: ${JSON.stringify(args)}`); 154 | 155 | const selectedSchema = schemas[args.schema]; 156 | 157 | if (args._.length !== 1) { 158 | yargs.showHelp("log"); 159 | return false; 160 | } 161 | switch (args._[0]) { 162 | case "batch": 163 | return batch(args.rawDir, args.batchedDir, selectedSchema); 164 | case "verify": 165 | return verify(args.file, selectedSchema); 166 | case "verify-all": 167 | return verifyAll(args.dir, selectedSchema); 168 | case "filter": 169 | return obfuscate(args.source, args.destination, args.fields); 170 | default: 171 | throw new Error(`Unknown command ${args._[0]}. Possible bug.`); 172 | } 173 | }; 174 | 175 | if (typeof require !== "undefined" && require.main === module) { 176 | main(process.argv.slice(2)) 177 | .then(res => { 178 | // eslint-disable-next-line no-console 179 | if (res) console.log(res); 180 | process.exit(0); 181 | }) 182 | .catch(err => { 183 | logger.error(`Error executing: ${err}`); 184 | if (typeof err.stack !== "undefined") { 185 | logger.debug(err.stack); 186 | } 187 | logger.debug(JSON.stringify(err)); 188 | process.exit(1); 189 | }); 190 | } 191 | -------------------------------------------------------------------------------- /src/batchIssue.test.js: -------------------------------------------------------------------------------- 1 | const proxyquire = require("proxyquire"); 2 | const { hashToBuffer: tb } = require("./crypto"); 3 | const sinon = require("sinon"); 4 | const sampleUndigestedCert = require("../test/fixtures/schema/2.0/1.json"); 5 | 6 | const readCert = sinon.stub(); 7 | const writeCertToDisk = sinon.stub(); 8 | const certificatesInDirectory = sinon.stub(); 9 | const { digestCertificate, appendProofToCerts, merkleHashmap } = proxyquire( 10 | "./batchIssue", 11 | { 12 | "./diskUtils": { 13 | readCert, 14 | writeCertToDisk, 15 | certificatesInDirectory 16 | } 17 | } 18 | ); 19 | 20 | describe("batchIssue", () => { 21 | beforeEach(() => { 22 | readCert.reset(); 23 | writeCertToDisk.reset(); 24 | certificatesInDirectory.reset(); 25 | }); 26 | 27 | describe("appendProofToCerts", () => { 28 | it("determines the proof for each cert using the hashmap and writes the new cert back", async () => { 29 | const hashMap = { 30 | a: { sibling: "b", parent: "d" }, 31 | b: { sibling: "a", parent: "d" }, 32 | c: { sibling: "d", parent: "e" }, 33 | d: { sibling: "c", parent: "e" } 34 | }; 35 | certificatesInDirectory.returns([ 36 | "file_1.json", 37 | "file_2.json", 38 | "file_3.json" 39 | ]); 40 | readCert.onCall(0).returns({ 41 | signature: { 42 | targetHash: "a" 43 | } 44 | }); 45 | readCert.onCall(1).returns({ 46 | signature: { 47 | targetHash: "b" 48 | } 49 | }); 50 | readCert.onCall(2).returns({ 51 | signature: { 52 | targetHash: "c" 53 | } 54 | }); 55 | 56 | const root = await appendProofToCerts("DIR", "DIR", hashMap); 57 | 58 | expect(root).to.be.eql("e"); 59 | 60 | expect(writeCertToDisk.args[0]).to.eql([ 61 | "DIR", 62 | "file_1.json", 63 | { 64 | signature: { 65 | targetHash: "a", 66 | proof: ["b", "c"], 67 | merkleRoot: "e" 68 | } 69 | } 70 | ]); 71 | expect(writeCertToDisk.args[1]).to.eql([ 72 | "DIR", 73 | "file_2.json", 74 | { 75 | signature: { 76 | targetHash: "b", 77 | proof: ["a", "c"], 78 | merkleRoot: "e" 79 | } 80 | } 81 | ]); 82 | expect(writeCertToDisk.args[2]).to.eql([ 83 | "DIR", 84 | "file_3.json", 85 | { 86 | signature: { 87 | targetHash: "c", 88 | proof: ["d"], 89 | merkleRoot: "e" 90 | } 91 | } 92 | ]); 93 | }); 94 | }); 95 | 96 | describe("digestCertificate", () => { 97 | it("digest all certificates, writes the digested certs to output_dir and returns array of all hashes", async () => { 98 | certificatesInDirectory.returns([ 99 | "file_1.json", 100 | "file_2.json", 101 | "file_3.json" 102 | ]); 103 | readCert.returns(sampleUndigestedCert); 104 | const hashArray = await digestCertificate("input_dir", "output_dir"); 105 | 106 | expect(hashArray.length).to.be.eql(3); 107 | 108 | expect(writeCertToDisk.args[0][0]).to.be.eql("output_dir"); 109 | expect(writeCertToDisk.args[1][0]).to.be.eql("output_dir"); 110 | expect(writeCertToDisk.args[2][0]).to.be.eql("output_dir"); 111 | expect(writeCertToDisk.args[0][1]).to.be.eql("file_1.json"); 112 | expect(writeCertToDisk.args[1][1]).to.be.eql("file_2.json"); 113 | expect(writeCertToDisk.args[2][1]).to.be.eql("file_3.json"); 114 | 115 | expect(writeCertToDisk.args[0][2].signature.merkleRoot).to.be.eql( 116 | hashArray[0].toString("hex") 117 | ); 118 | expect(writeCertToDisk.args[1][2].signature.merkleRoot).to.be.eql( 119 | hashArray[1].toString("hex") 120 | ); 121 | expect(writeCertToDisk.args[2][2].signature.merkleRoot).to.be.eql( 122 | hashArray[2].toString("hex") 123 | ); 124 | }); 125 | }); 126 | 127 | const h1 = "41b1a0649752af1b28b3dc29a1556eee781e4a4c3a1f7f53f90fa834de098c4d"; 128 | const h2 = "435cd288e3694b535549c3af56ad805c149f92961bf84a1c647f7d86fc2431b4"; 129 | const h12 = 130 | "744766909640c85c19ca00139e7af3c5d9cb8dbfbc6635812eedc4e3cbf4fce6"; 131 | 132 | describe("merkleHashmap", () => { 133 | it("returns empty object for one hash (root)", () => { 134 | const hmap = merkleHashmap([tb(h1)]); 135 | expect(hmap).to.deep.equal({}); 136 | }); 137 | it("returns hashmap for two hashes", () => { 138 | const hmap = merkleHashmap([tb(h1), tb(h2)]); 139 | expect(hmap).to.deep.equal({ 140 | [h1]: { sibling: h2, parent: h12 }, 141 | [h2]: { sibling: h1, parent: h12 } 142 | }); 143 | }); 144 | it("returns hashmap for odd number (5) hashes", () => { 145 | const hashArray = [ 146 | "3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb", 147 | "b5553de315e0edf504d9150af82dafa5c4667fa618ed0a6f19c69b41166c5510", 148 | "0b42b6393c1f53060fe3ddbfcd7aadcca894465a5a438f69c87d790b2299b9b2", 149 | "f1918e8562236eb17adc8502332f4c9c82bc14e19bfc0aa10ab674ff75b3d2f3", 150 | "a8982c89d80987fb9a510e25981ee9170206be21af3c8e0eb312ef1d3382e761" 151 | ]; 152 | const hashArrayBuf = hashArray.map(tb); 153 | const hmap = merkleHashmap(hashArrayBuf); 154 | const expectedHmap = { 155 | "3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb": { 156 | sibling: 157 | "b5553de315e0edf504d9150af82dafa5c4667fa618ed0a6f19c69b41166c5510", 158 | parent: 159 | "805b21d846b189efaeb0377d6bb0d201b3872a363e607c25088f025b0c6ae1f8" 160 | }, 161 | b5553de315e0edf504d9150af82dafa5c4667fa618ed0a6f19c69b41166c5510: { 162 | sibling: 163 | "3ac225168df54212a25c1c01fd35bebfea408fdac2e31ddd6f80a4bbf9a5f1cb", 164 | parent: 165 | "805b21d846b189efaeb0377d6bb0d201b3872a363e607c25088f025b0c6ae1f8" 166 | }, 167 | "0b42b6393c1f53060fe3ddbfcd7aadcca894465a5a438f69c87d790b2299b9b2": { 168 | sibling: 169 | "f1918e8562236eb17adc8502332f4c9c82bc14e19bfc0aa10ab674ff75b3d2f3", 170 | parent: 171 | "d253a52d4cb00de2895e85f2529e2976e6aaaa5c18106b68ab66813e14415669" 172 | }, 173 | f1918e8562236eb17adc8502332f4c9c82bc14e19bfc0aa10ab674ff75b3d2f3: { 174 | sibling: 175 | "0b42b6393c1f53060fe3ddbfcd7aadcca894465a5a438f69c87d790b2299b9b2", 176 | parent: 177 | "d253a52d4cb00de2895e85f2529e2976e6aaaa5c18106b68ab66813e14415669" 178 | }, 179 | "805b21d846b189efaeb0377d6bb0d201b3872a363e607c25088f025b0c6ae1f8": { 180 | sibling: 181 | "d253a52d4cb00de2895e85f2529e2976e6aaaa5c18106b68ab66813e14415669", 182 | parent: 183 | "68203f90e9d07dc5859259d7536e87a6ba9d345f2552b5b9de2999ddce9ce1bf" 184 | }, 185 | d253a52d4cb00de2895e85f2529e2976e6aaaa5c18106b68ab66813e14415669: { 186 | sibling: 187 | "805b21d846b189efaeb0377d6bb0d201b3872a363e607c25088f025b0c6ae1f8", 188 | parent: 189 | "68203f90e9d07dc5859259d7536e87a6ba9d345f2552b5b9de2999ddce9ce1bf" 190 | }, 191 | "68203f90e9d07dc5859259d7536e87a6ba9d345f2552b5b9de2999ddce9ce1bf": { 192 | sibling: 193 | "a8982c89d80987fb9a510e25981ee9170206be21af3c8e0eb312ef1d3382e761", 194 | parent: 195 | "1dd0d2a6ae466d665cb26e1a31f07c57ae5df7d2bc559cd5826d417be9141a5d" 196 | }, 197 | a8982c89d80987fb9a510e25981ee9170206be21af3c8e0eb312ef1d3382e761: { 198 | sibling: 199 | "68203f90e9d07dc5859259d7536e87a6ba9d345f2552b5b9de2999ddce9ce1bf", 200 | parent: 201 | "1dd0d2a6ae466d665cb26e1a31f07c57ae5df7d2bc559cd5826d417be9141a5d" 202 | } 203 | }; 204 | 205 | expect(hmap).to.deep.equal(expectedHmap); 206 | }); 207 | }); 208 | }); 209 | -------------------------------------------------------------------------------- /docs/SelectivePrivacy.md: -------------------------------------------------------------------------------- 1 | ## Selective Privacy 2 | 3 | Storing more data on the certificate may mean the user is exposing too much information than he want to other parties. Say that a student does not want to share his transcript, he will not be able to verify his entire certificate using the current blockcert implementation. 4 | 5 | Suggestion is to hash each line of the canoncalised version of the certificate (less the signature) before hashing all the results. This allow the certificate to be validated even without the original content of the certificate. 6 | 7 | **Sample Certificate** 8 | 9 | ``` 10 | { 11 | "@context": "https://w3id.org/openbadges/v2", 12 | "id": "https://example.org/assertions/123", 13 | "type": "Assertion", 14 | "recipient": { 15 | "type": "email", 16 | "identity": "alice@example.org" 17 | }, 18 | "issuedOn": "2016-12-31T23:59:59+00:00", 19 | "verification": { 20 | "type": "hosted" 21 | }, 22 | "badge": { 23 | "type": "BadgeClass", 24 | "id": "https://example.org/badges/5", 25 | "name": "3-D Printmaster", 26 | "description": "This badge is awarded for passing the 3-D printing knowledge and safety test.", 27 | "image": "https://example.org/badges/5/image", 28 | "criteria": { 29 | "narrative": "Students are tested on knowledge and safety, both through a paper test and a supervised performance evaluation on live equipment" 30 | }, 31 | "issuer": { 32 | "id": "https://example.org/issuer", 33 | "type": "Profile", 34 | "name": "Example Maker Society", 35 | "url": "https://example.org", 36 | "email": "contact@example.org", 37 | "verification": { 38 | "allowedOrigins": "example.org" 39 | } 40 | } 41 | }, 42 | "evidence": [ 43 | { 44 | "id": "https://example.org/beths-robot-photos.html", 45 | "name": "Robot Photoshoot", 46 | "description": "A gallery of photos of the student's robot", 47 | "genre": "Photography" 48 | }, 49 | { 50 | "id": "https://example.org/beths-robot-work.html", 51 | "name": "Robotics Reflection #1", 52 | "description": "Reflective writing about the first week of a robotics learning journey." 53 | } 54 | ] 55 | } 56 | ``` 57 | 58 | **Normalized Data** 59 | 60 | ``` 61 | . 62 | . 63 | . 64 | . 65 | "2016-12-31T23:59:59+00:00"^^ . 66 | _:c14n3 . 67 | _:c14n2 . 68 | "This badge is awarded for passing the 3-D printing knowledge and safety test." . 69 | . 70 | "3-D Printmaster" . 71 | . 72 | _:c14n0 . 73 | . 74 | "A gallery of photos of the student's robot" . 75 | "Photography" . 76 | "Robot Photoshoot" . 77 | "Reflective writing about the first week of a robotics learning journey." . 78 | "Robotics Reflection #1" . 79 | "contact@example.org" . 80 | "Example Maker Society" . 81 | . 82 | . 83 | _:c14n1 . 84 | _:c14n0 "Students are tested on knowledge and safety, both through a paper test and a supervised performance evaluation on live equipment" . 85 | _:c14n1 "example.org" . 86 | _:c14n2 . 87 | _:c14n3 . 88 | _:c14n3 "alice@example.org" . 89 | ``` 90 | 91 | **Sorted SHA256 Results (New steps to add selective privacy to Blockcert)** 92 | 93 | ``` 94 | [ '00025dc34052dc80c7284591a24aee7f7fa38bf598f799bf394054ecd154ede0', 95 | '0611cf9cc83ed6c7faf419cff8608133a3d896d267a1f8a0f1ad6a3fdfbe41df', 96 | '11f543e27a02b23514d36395b91b8c87b72775aa1de80deca56f6f88cb4074c0', 97 | '171e2557a69c66c90b7a541b990ef19e13629327de6e66da363e882d8eca8880', 98 | '1d94a1315659be022f2faba837e8dd80fead1350e7956f25a450af5dc7a6979d', 99 | '23d3e9632ca97b4d8d922004e52bcd022e835dada7908977c6aa571d7cd15c52', 100 | '28cea87b87aab3bce2d24fef1ad7f0a50e7beb117f4122dd75eceafcad93cce3', 101 | '3afdb5792056e6102987fedb56919e64efbb61ca33207112a821e5f67a77cf33', 102 | '5aba95ba1b44b01ef081af7473a439b4e153132f2c1f71bb1e108e82cc9c3542', 103 | '5c0afb405ab88cab24c1156aab2745ef66e4862455d3c41a5f781750ed690412', 104 | '65bc2f14c33f5baaf5dab56cbc5fa1719fc81818b09e2814b2540fa28796e8b4', 105 | '65d755ce457c05f430c27199fd4785a9ee74c57995a656e2b5e91a828e480916', 106 | '69e434742c09ecdcbfe05feb5bd302a2ac42ee230d666d3149632fec63010202', 107 | '6a3887e673c1b4942d584734f6b1f8f9c76093e5d6369da1abeefea7a0b91a1f', 108 | '6a5765a788f4e637790bb1e68862a94deec2880c367468f690311260806f50d8', 109 | '7e9915045a7fd1c0e10d281798aa317ce731c28cfd70aea5864294fe821056d8', 110 | '8f4f16cb32bdd0317a78a73920fcf6a6912142411d497743ba91a9fb49eed309', 111 | '93e246a62d44f8da072bbba35015d9b1277870a4f206e4d47747e57f92c260a6', 112 | 'a78e632098c2218b8265f065209740912b164e60d16c76d0f103c21a89b7d938', 113 | 'ad903bf969312170c79164ca5768ce8d5d682939f0cd529241559ec261696db6', 114 | 'b2fe74f5bacdf2805e501eb5b052fd5d8998c620f63a0ebad0f4ae7351ead660', 115 | 'caceb425a4dbb20f9f6666a341104d72d3a3368a038f9e86d06965e6ee4d24df', 116 | 'd37d9f338595e3d514a3229a1f1f7ce3f83878156f5083b5c0ecd1bc2d54569c', 117 | 'd732f2b238d6129f1a90d12b335f5ed7210a74fa992c6ec4f4c474139a5eb6e6', 118 | 'de91db4cc6ec36bfcf55b7496579438bfc04fc8b2b5d1982c84e72716e67be11', 119 | 'ecc9769a06115181795c4378fe5e12a8f9f8948c2960e45930226156f11066b5', 120 | 'edab91324a99271637bcab4512ba28e09f131a2ed975d5c6df191714e8c98536', 121 | 'f6928f3bec7dc858f33c80b1390e97c4925c2522a3aa1ced36941062e72e1d66' ] 122 | ``` 123 | 124 | **Target Hash** 125 | 126 | ``` 127 | 08747f48db1ed91a532f6040ff42b7e1af0ce684c8f7e031f9c7287fc9ea8bb8 128 | ``` 129 | 130 | **Sample Private Certificate** 131 | 132 | ``` 133 | { 134 | "@context": "https://w3id.org/openbadges/v2", 135 | "id": "https://example.org/assertions/123", 136 | "type": "Assertion", 137 | "recipient": { 138 | "type": "email", 139 | "identity": "alice@example.org" 140 | }, 141 | "issuedOn": "2016-12-31T23:59:59+00:00", 142 | "verification": { 143 | "type": "hosted" 144 | }, 145 | "badge": { 146 | "type": "BadgeClass", 147 | "id": "https://example.org/badges/5", 148 | "name": "3-D Printmaster", 149 | "description": "This badge is awarded for passing the 3-D printing knowledge and safety test.", 150 | "image": "https://example.org/badges/5/image", 151 | "criteria": { 152 | "narrative": "Students are tested on knowledge and safety, both through a paper test and a supervised performance evaluation on live equipment" 153 | }, 154 | "issuer": { 155 | "id": "https://example.org/issuer", 156 | "type": "Profile", 157 | "name": "Example Maker Society", 158 | "url": "https://example.org", 159 | "email": "contact@example.org", 160 | "verification": { 161 | "allowedOrigins": "example.org" 162 | } 163 | } 164 | } 165 | } 166 | ``` 167 | 168 | ``` 169 | [ 170 | 'd37d9f338595e3d514a3229a1f1f7ce3f83878156f5083b5c0ecd1bc2d54569c', 171 | '93e246a62d44f8da072bbba35015d9b1277870a4f206e4d47747e57f92c260a6', 172 | '23d3e9632ca97b4d8d922004e52bcd022e835dada7908977c6aa571d7cd15c52', 173 | 'de91db4cc6ec36bfcf55b7496579438bfc04fc8b2b5d1982c84e72716e67be11', 174 | '28cea87b87aab3bce2d24fef1ad7f0a50e7beb117f4122dd75eceafcad93cce3' 175 | ] 176 | ``` 177 | > All evidence information are now hidden in the hash and the new certificate can still be validated on the blockchain. 178 | 179 | 180 | **Suggested Improvements to Blockcert Schema** 181 | 182 | 1. MerkleProof2017 Algorithm 183 | * Hashing normalised JSON-LD results 184 | 2. Privacy Schema 185 | 186 | ``` 187 | { 188 | "@context": "https://w3id.org/openbadges/v2", 189 | "id": "https://example.org/assertions/123", 190 | "type": "Assertion", 191 | "recipient": { 192 | "type": "email", 193 | "identity": "alice@example.org" 194 | }, 195 | "issuedOn": "2016-12-31T23:59:59+00:00", 196 | "verification": { 197 | "type": [ 198 | "MerkleProofPrivacyExtension2018", 199 | "Extension" 200 | ] 201 | }, 202 | "signature": { 203 | "anchors": [ 204 | { 205 | "chain": "ethereumRopsten", 206 | "type": "ETHContract", 207 | "sourceId": "0xc4e7c98867e7eff0ec33c01ae0c14d881a94d65508961aebf77faf4da2746bf6" 208 | } 209 | ], 210 | "type": [ 211 | "MerkleProofPrivacyExtension2018", 212 | "Extension" 213 | ], 214 | "proof": [ 215 | "51b4e22ed024ec7f38dc68b0bf78c87eda525ab0896b75d2064bdb9fc60b2698", 216 | "51b4e22ed024ec7f38dc68b0bf78c87eda525ab0896b75d2064bdb9fc60b2698" 217 | ], 218 | "concealed":[ 219 | "d37d9f338595e3d514a3229a1f1f7ce3f83878156f5083b5c0ecd1bc2d54569c", 220 | "93e246a62d44f8da072bbba35015d9b1277870a4f206e4d47747e57f92c260a6", 221 | "23d3e9632ca97b4d8d922004e52bcd022e835dada7908977c6aa571d7cd15c52", 222 | "de91db4cc6ec36bfcf55b7496579438bfc04fc8b2b5d1982c84e72716e67be11", 223 | "28cea87b87aab3bce2d24fef1ad7f0a50e7beb117f4122dd75eceafcad93cce3" 224 | ], 225 | "merkleRoot": "57a9f493cad16f3a12839a8cb2c460d54e950121dccec9a57c9014a08604ef7e", 226 | "targetHash": "08747f48db1ed91a532f6040ff42b7e1af0ce684c8f7e031f9c7287fc9ea8bb8" 227 | }, 228 | "badge": { 229 | "type": "BadgeClass", 230 | "id": "https://example.org/badges/5", 231 | "name": "3-D Printmaster", 232 | "description": "This badge is awarded for passing the 3-D printing knowledge and safety test.", 233 | "image": "https://example.org/badges/5/image", 234 | "criteria": { 235 | "narrative": "Students are tested on knowledge and safety, both through a paper test and a supervised performance evaluation on live equipment" 236 | }, 237 | "issuer": { 238 | "id": "https://example.org/issuer", 239 | "type": "Profile", 240 | "name": "Example Maker Society", 241 | "url": "https://example.org", 242 | "email": "contact@example.org", 243 | "verification": { 244 | "allowedOrigins": "example.org" 245 | } 246 | } 247 | } 248 | ] 249 | } 250 | ``` 251 | 252 | > Added concealed in signature 253 | 254 | > Added "ETHContract" as enum for anchor type -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------