-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from elmariachi111/schemaorg_credentials
Schema.org credentials | root trust verification
- Loading branch information
Showing
47 changed files
with
2,595 additions
and
2,577 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
PORT=8080 | ||
NODE_ENV=development | ||
DB_FILENAME=cred.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ build/ | |
logs/ | ||
|
||
src/app/.notes | ||
*.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const COMM_ENDPOINT = '/comm'; | ||
export const VC_ENDPOINT = '/vc'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.