Skip to content

Commit

Permalink
Merge pull request #4 from elmariachi111/schemaorg_credentials
Browse files Browse the repository at this point in the history
Schema.org credentials | root trust verification
  • Loading branch information
elmariachi111 authored Feb 16, 2021
2 parents 8f41052 + 0166674 commit cb176f7
Show file tree
Hide file tree
Showing 47 changed files with 2,595 additions and 2,577 deletions.
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ a verifier that displays presentiation requests for validateable credential type

https://github.com/decentralized-identity/ethr-did-resolver/pull/106 : the resolver would be able to resolve key material in base58 encoding (instead of base64url) as required by most crypto did libraries at the moment.


curated list of all vaccination passport providers in the world:
https://docs.google.com/document/d/1MQfZzlkYkXCXvnUXd7Cd6Y5g0RRXrKxGGqVcbBnSk1k/edit


# Background

## DID backgrounders
Expand Down Expand Up @@ -97,8 +102,8 @@ https://medium.com/uport/erc1056-erc780-an-open-identity-and-claims-protocol-for
Lightweight Identity:
https://eips.ethereum.org/EIPS/eip-1056

Claims Registry:
https://github.com/ethereum/EIPs/issues/780
On Chain Credentials Registry:
https://github.com/ethereum/EIPs/issues/780 (not really recommended)

followed by:

Expand Down Expand Up @@ -132,11 +137,13 @@ A nonfinal vc http api interface spec
https://github.com/w3c-ccg/vc-http-api

https://w3c-ccg.github.io/vc-extension-registry/#proof-methods
(-> `Ed25519Signature2018` )

DIF specs
https://github.com/decentralized-identity/claims-credentials

Credential Status Registry
https://w3c-ccg.github.io/vc-csl2017/#introduction

#### Verifiable Presentation Requests

https://w3c-ccg.github.io/vp-request-spec/
Expand Down Expand Up @@ -262,7 +269,9 @@ CVX (Vacc codes): https://www2a.cdc.gov/vaccines/IIS/IISStandards/vaccines.asp?r
MVX (Vacc manufacturer codes): https://www2a.cdc.gov/vaccines/IIS/IISStandards/vaccines.asp?rpt=mvx
CPT (Snomed?) -> CVXmappings: https://www2a.cdc.gov/vaccines/IIS/IISStandards/vaccines.asp?rpt=cpt

#### FHIR4 Immunization JSON schema
#### Immunization schemas

FHIR4 immunization general
https://www.hl7.org/fhir/immunization.schema.json.html

The preliminary FHIR4 spec, driven by M$ Smart Health Cards project:
Expand All @@ -274,13 +283,25 @@ Covid 19 sample:
https://github.com/microsoft-healthcare-madison/health-wallet-demo/blob/master/src/fixtures/vc.pcr.json
(in action: https://smarthealth.cards/credential-modeling/)

CCC4 initiative's schema, based on a Canadian effort, driven by Consensas / Sovrin e.a.
https://docs.google.com/document/d/1pCyS_lhbMGhOkq1jFEkI_od-9QunURKzGWA7ty5DCII/edit

with a spec background described here: https://docs.google.com/document/d/1a4j0-6kJonEfSlX50ZEfAEbx2ab2IW8UuBK8vigsoLU/edit#heading=h.y43f7b8rk9yr

Qatar open data:
https://www.data.gov.qa/explore/dataset/h4-vaccination/information/

Schema.org can be utilized for that:
https://schema.org/docs/meddocs.html
https://schema.org/docs/health-lifesci.home.html
https://schema.org/MedicalTherapy
impl and extended by Consensas: https://github.com/Consensas/information-passport/blob/main/docs/Vaccination.md

A ruby impl of health cards (DVCI)
https://github.com/dvci/health_cards



### Vaccination credential initiatives

An umbrella initiative for VCI / CCI and others is the Good Health Collaborative:
Expand Down
54 changes: 54 additions & 0 deletions docs/samples/ccc4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"@context": "http://schema.org/",
"@type": "ImmunizationRecord",
"patient": {
"@type": "Patient",
"birthDate": "••••-••-25",
"familyName": "Steele",
"givenName": "Adrian",
"name": "Adrian Steele",
"healthCard": {
"@type": "HealthCard",
"identifier-healthCard": "•••••••••••2097",
"issuedBy": "CA-BC",
"validUntil": "2025-06"
}
},
"primaryPrevention": {
"@type": "ImmunizationRecommendation",
"drug": {
"@type": "Drug",
"code": {
"@type": "MedicalCode",
"codeValue": "MVX-MOD.CVX-207",
"codingSystem": "CDC-MVX.CVX"
},
"manufacturer": {
"@type": "Organization-CDC-MVX",
"identifier": "MVX-MOD",
"name": "Moderna US, Inc."
},
"name": "Moderna COVID-19 Vaccine"
},
"healthCondition": {
"@type": "MedicalCondition",
"code": {
"@type": "MedicalCode",
"codeValue": "U07",
"codingSystem": "ICD-10"
}
}
},
"location": {
"@type": "Hospital",
"address": {
"@type": "PostalAddress",
"addressCountry": "CA",
"addressRegion": "BC"
},
"name": "Shopper's"
},
"doseSequence": 2,
"lotNumber": "1234-5678-90A",
"immunizationDate": "2021-01-01"
}
1 change: 1 addition & 0 deletions packages/immu-comm/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PORT=8080
NODE_ENV=development
DB_FILENAME=cred.db
1 change: 1 addition & 0 deletions packages/immu-comm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ build/
logs/

src/app/.notes
*.db
11 changes: 9 additions & 2 deletions packages/immu-comm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
"@types/consolidate": "^0.14.0",
"@types/cors": "^2.8.9",
"@types/dotenv-flow": "^3.1.0",
"@types/encoding-down": "^5.0.0",
"@types/express": "^4.17.11",
"@types/express-session": "^1.17.3",
"@types/leveldown": "^4.0.2",
"@types/levelup": "^4.3.0",
"@types/morgan": "^1.9.2",
"@types/node": "^14.14.22",
"@types/twig": "^1.12.5",
Expand All @@ -41,13 +44,17 @@
"typescript": "^4.1.3"
},
"dependencies": {
"@immu/core": "workspace:*",
"bs58": "^4.0.1",
"cors": "^2.8.5",
"dotenv-flow": "^3.2.0",
"encoding-down": "^6.3.0",
"express": "^4.17.1",
"fs": "0.0.1-security",
"helmet": "^4.4.1",
"leveldown": "^5.6.0",
"levelup": "^4.4.0",
"morgan": "^1.10.0",
"web3": "^1.3.4"
"web3": "1.3.3"
}
}
}
66 changes: 66 additions & 0 deletions packages/immu-comm/src/app/vc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Router } from 'express';
import { VC_ENDPOINT } from '../../constants/endpoint';
import { Verifiable, W3CCredential } from '@immu/core';
import levelup, { LevelUp } from 'levelup';
import leveldown from 'leveldown';
import encodingDown from 'encoding-down';

export const router: Router = Router();

export const DB_FILENAME = './records.db';

interface CredentialStore {
[did: string]: {
[vctype: string]: Verifiable<W3CCredential>[];
};
}

const credStore: LevelUp = levelup(
encodingDown(leveldown(process.env.DB_FILENAME || 'cred.db'), {
keyEncoding: 'string',
valueEncoding: 'json'
})
);

export default credStore;

//todo: poster (verifier) must sign a self chosen nonce and present a bearer jwt to be allowed to do this.
router.get(VC_ENDPOINT + '/:did', async (req, res) => {
const type = req.query.vctype as string;
const did = req.params.did;
const key = `[${did}][${type}]`;
try {
const credentials = await credStore.get(key);
res.status(200).json(credentials);
} catch (e) {
console.error(e);
res.status(404).json({ reason: 'not found' });
}
});

//todo: poster must be issuer or holder and
// sign a self chosen nonce and present a bearer jwt to be allowed to do this.
router.post(VC_ENDPOINT, async (req, res) => {
const credential = req.body as Verifiable<W3CCredential>;

if (!credential.credentialSubject.id) throw Error('we only support credentials with unique subjects');

const did: string = credential.credentialSubject.id;
const types: string[] = credential.type;

const type = types.find((t) => t != 'VerifiableCredential');

const key = `[${did}][${type}]`;

let credentials;
try {
credentials = await credStore.get(key);
} catch (e) {
credentials = [];
}

credentials.push(credential);
await credStore.put(key, credentials);

res.status(200).send({ msg: 'ok' });
});
1 change: 1 addition & 0 deletions packages/immu-comm/src/constants/endpoint.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const COMM_ENDPOINT = '/comm';
export const VC_ENDPOINT = '/vc';
2 changes: 2 additions & 0 deletions packages/immu-comm/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import express, { Express } from 'express';
import helmet from 'helmet';
import morgan from 'morgan';
import { router as CommRouter } from './app/comm';
import { router as VCRouter } from './app/vc';

const app: Express = express();

Expand All @@ -27,6 +28,7 @@ if (process.env.NODE_ENV === 'production') {
}

app.use('/', CommRouter);
app.use('/', VCRouter);

/************************************************************************************
* Express Error Handling
Expand Down
59 changes: 59 additions & 0 deletions packages/immu-comm/test.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
POST http://127.0.0.1:8080/vc
Content-Type: application/json

{
"@context": [
"https://www.w3.org/2018/credentials/v1"
],
"issuanceDate": "2021-02-15T00:29:33.139Z",
"credentialSubject": {
"id": "did:ethr:goerli:0xb17251023f45ca29c1d89747a37f0da703fdd717",
"fhirVersion": "4.0.1",
"fhirResource": {
"resource": {
"resourceType": "Practitioner",
"id": "did:ethr:goerli:0xb17251023f45ca29c1d89747a37f0da703fdd717",
"identifier": [
{
"use": "official",
"system": "did",
"value": "did:ethr:goerli:0xb17251023f45ca29c1d89747a37f0da703fdd717"
}
],
"name": [
{
"use": "official",
"family": "Adolf",
"given": [
"Stefan"
]
}
]
}
}
},
"issuer": {
"id": "did:ethr:goerli:0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1"
},
"type": [
"VerifiableCredential",
"ProofOfProvider"
],
"proof": {
"type": "EcdsaSecp256k1Signature2019",
"verificationMethod": "did:ethr:goerli:0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1#controller",
"created": "2021-02-15T00:29:41.972Z",
"proofPurpose": "assertionMethod",
"jws": "eyJhbGciOiJFUzI1NksifQ..L1gSOn2SyhqQcm0wYfPfGF6RgjaznPADxoFSw-7D56dCkCVIHg9nZfO2V7pryJMvyqUhN-ixRHPDIfW3nTABuw"
}
}

###

GET http://127.0.0.1:8080/vc/did:ethr:development:0xffcf8fdee72ac11b5c542428b35eef5769c409f0?vctype=ProofOfProvider
Accept: application/json

###

GET http://localhost:8080/vc/did:ethr:development:0x23270bf93e1d6cba4a844107e1be58200a1ee804?vctype=ProofOfProvider
Accept: application/json
12 changes: 7 additions & 5 deletions packages/immu-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@truffle/contract": "^4.3.5",
"@types/dotenv-flow": "^3.1.0",
"@types/jest": "^26.0.20",
"@types/jsonld": "^1.5.2",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "^4.12.0",
"@typescript-eslint/parser": "^4.12.0",
Expand Down Expand Up @@ -57,13 +58,14 @@
"ethereumjs-util": "^7.0.7",
"ethr-did-registry": "^0.0.3",
"ethr-did-resolver": "git@github.com:cod1ng-earth/ethr-did-resolver.git",
"jsonld": "^4.0.1",
"key-did-resolver": "^0.2.4",
"secp256k1": "^4.0.2",
"vc-js": "^0.6.4",
"web3": "^1.3.1",
"web3-core": "^1.3.1",
"web3-eth": "^1.3.1",
"web3-eth-contract": "^1.3.1",
"web3-utils": "^1.3.1"
"web3": "1.3.3",
"web3-core": "1.3.3",
"web3-eth": "1.3.3",
"web3-eth-contract": "1.3.3",
"web3-utils": "1.3.3"
}
}
6 changes: 5 additions & 1 deletion packages/immu-core/src/@types/Fhir.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export interface FHIRBundle {
fhirVersion: string;
fhirResource: FHIRResource;
}
export interface FHIRResource {
resource: Record<string, any>;
}

export interface FHIRImmunizationInputParams {
export interface ImmunizationInputParams {
lotNumber: string;
vaccineCode: string;
occurrenceDateTime: Date;
Expand Down
Loading

0 comments on commit cb176f7

Please sign in to comment.