Skip to content

Commit

Permalink
fix schema example
Browse files Browse the repository at this point in the history
  • Loading branch information
cykoder committed Sep 29, 2020
1 parent b0609ee commit 02c6ff9
Showing 1 changed file with 1 addition and 156 deletions.
157 changes: 1 addition & 156 deletions example/standard_schemas.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,10 @@
import Schema from '../src/modules/schema';
import { validateCredentialSchema, expandJSONLD } from '../src/utils/vc';

import bolSchema from '../src/utils/vc/schemas/bol';
import prCardSchema from '../src/utils/vc/schemas/pr_card';
import qpInbonSchema from '../src/utils/vc/schemas/qp_inbond';
import healthWorkerPassportSchema from '../src/utils/vc/schemas/health_worker_passport';
import infectionDiagnosisSchema from '../src/utils/vc/schemas/infection_diagnosis';
import immunityEventRecordSchema from '../src/utils/vc/schemas/immunity_event_record';
import noInfectionSchema from '../src/utils/vc/schemas/non_infection_check';

// Schema from here https://github.com/w3c-ccg/vc-examples/blob/master/plugfest-2020/vendors/mavennet/credentials/BillOfLading.json
const bolCred = {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://schema.org/',
'https://mavennet.github.io/contexts/bill-of-lading-v1.0.jsonld',
],
id: 'http://neo-flow.com/credentials/e94a16cb-35b2-4301-9fb6-7af3d8fe7b81',
type: ['VerifiableCredential', 'BillOfLadingCredential'],
name: 'Bill of Lading',
description: 'Detailed shipment document provided by the carrier to the receiver of products.',
issuer: 'did:v1:test:nym:z6MkfG5HTrBXzsAP8AbayNpG3ZaoyM4PCqNPrdWQRSpHDV6J',
issuanceDate: '2020-04-09T21:13:13Z',
credentialSubject: {
productIdentifier: '3a185b8f-078a-4646-8343-76a45c2856a5',
bolNumber: 'BOL000104976',
carrier: 'did:v1:test:nym:z6MkhdmzFu659ZJ4XKj31vtEDmjvsi5yDZG5L7Caz63oP39k',
recipient: 'did:v1:test:nym:z6MknQLHcwKwopce5ji1Ftsurn8mNL58wTxZB238uEMsegUj',
transportType: 'Pipeline',
originAddress: {
address: 'Quebec, CAN',
latitude: 52.9399,
longitude: 73.5491,
},
deliveryAddress: {
address: 'Chicago, USA',
latitude: 41.8781,
longitude: 87.6298,
},
valuePerItem: 46,
totalOrderValue: 126500,
freightChargeTerms: 'Freight Prepaid',
expectedDeliveryDates: '2020-04-12',
comments: '',
},
};

// Schema from here https://github.com/w3c-ccg/vc-examples/blob/master/plugfest-2020/vendors/sicpa/credentials/PermanentResidentCard.json
const credPRCard = {
'@context': [
Expand Down Expand Up @@ -80,119 +39,11 @@ const credPRCard = {
description: 'Government of Example Permanent Resident Card.',
};

const qPInbondCred = {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://schema.org/',
'https://mavennet.github.io/contexts/qp-in-bond-v1.0.jsonld',
],
id: 'http://neo-flow.com/credentials/3aee17e7-8c50-4551-a8b4-9bc129c106e8',
type: ['VerifiableCredential', 'QPInbondCredential'],
name: 'QP Inbond',
description: 'Permit document for import/export of shipments that have not been cleared by US Customs.',
issuer: 'did:v1:test:nym:z6MkhdmzFu659ZJ4XKj31vtEDmjvsi5yDZG5L7Caz63oP39k',
issuanceDate: '2020-04-09T21:13:43Z',
credentialSubject: {
productIdentifier: '3a185b8f-078a-4646-8343-76a45c2856a5',
inBondNumber: '123456789',
inBondType: 'IT (61)',
portOfEntry: 'Superior, WI, USA',
carrier: 'did:v1:test:nym:z6MkhdmzFu659ZJ4XKj31vtEDmjvsi5yDZG5L7Caz63oP39k',
irsNumber: '12345678-01',
transportType: 'Pipeline',
recipient: 'did:v1:test:nym:z6MknQLHcwKwopce5ji1Ftsurn8mNL58wTxZB238uEMsegUj',
originAddress: {
address: 'Quebec, CAN',
latitude: 52.9399,
longitude: 73.5491,
},
deliveryAddress: {
address: 'Chicago, USA',
latitude: 41.8781,
longitude: 87.6298,
},
bolNumber: 'BOL000104976',
valuePerItem: 46,
totalOrderValue: 126500,
expectedDeliveryDates: '2020-04-12',
comment: 'None',
},
};

// Schema from here https://docs.google.com/document/d/1F5TLvAqCxj1kaPuPe6JhdECixwpbhKpEAb8eeQuDGT4/edit#heading=h.kdkhzpmqto5s
const healthCareWorkerCred = {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://www.w3.org/2018/credentials/examples/v1',
'https://schema.org/',
],
id: 'https://example.com/credentials/1872',
type: ['VerifiableCredential', 'HealthCareWorkerPassportCredential'],
issuer: 'did:v1:test:nym:z6MkhdmzFu659ZJ4XKj31vtEDmjvsi5yDZG5L7Caz63oP39k',
issuanceDate: '2020-04-09T21:13:43Z',
credentialSubject: {
firstName: 'John',
lastName: 'Smith',
photo: 'https://example.com/photos/102',
biometricTemplate: {
fingerprint: 'c2856a76a785b8fa185a45c',
retina: '8fa185a45cc2856a76a785b',
},
degreeHeld: [
{
institution: 'Albany Medical College',
degree: 'MD',
},
],
licenses: [
{
licenseName: 'Medical License',
licenser: 'New York',
licensedFor: 'USA',
expiresDate: '2020-11-25',
},
],
},
};

// Schema from here https://docs.google.com/document/d/1F5TLvAqCxj1kaPuPe6JhdECixwpbhKpEAb8eeQuDGT4/edit#heading=h.ppf3i61y3kbc
const infectionDiagnosisCred = {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://www.w3.org/2018/credentials/examples/v1',
'https://schema.org/',
],
id: 'https://example.com/credentials/1872',
type: ['VerifiableCredential', 'InfectionDiagnosisCredential'],
issuer: 'did:v1:test:nym:z6MkhdmzFu659ZJ4XKj31vtEDmjvsi5yDZG5L7Caz63oP39k',
issuanceDate: '2020-04-09T21:13:43Z',
credentialSubject: {
firstName: 'John',
firstInitial: 'J',
lastName: 'Smith',
lastInitial: 'S',
yearOfBirth: 1990,
photo: 'https://example.com/photos/102',
biometricTemplate: {
fingerprint: 'c2856a76a785b8fa185a45c',
retina: '8fa185a45cc2856a76a785b',
},
diagnosisCode: 'CodeA',
diagnosisTime: '2020-02-13T20:20:39+00:00',
diagnosisLocation: 'New York City, New York, USA',
diagnosedBy: 'Anne Lyons, MD',
diagnosisFacility: 'Cedar Sinai Memorial Hospital',
diagnosisMethods: ['personal interview and observation', 'rRT-PCR'],
declaredSafeDate: '2020-03-15',
},
};

// Schema from here https://docs.google.com/document/d/1F5TLvAqCxj1kaPuPe6JhdECixwpbhKpEAb8eeQuDGT4/edit#heading=h.uuhsd64qh6k2
const immunityEventRecordCred = {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://www.w3.org/2018/credentials/examples/v1',
'https://schema.org/',
],
id: 'https://example.com/credentials/1872',
type: ['VerifiableCredential', 'ImmunityEventRecordCredential'],
Expand Down Expand Up @@ -223,7 +74,6 @@ const noInfectionCred = {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://www.w3.org/2018/credentials/examples/v1',
'https://schema.org/',
],
id: 'https://example.com/credentials/1872',
type: ['VerifiableCredential', 'NoInfectionCredential'],
Expand Down Expand Up @@ -252,20 +102,15 @@ const noInfectionCred = {
async function validateSchema(schema, credential) {
console.log('Validating schema:', schema.description);
await Schema.validateSchema(schema);
console.log('Validating credential against schema...');
console.log('Validating credential against schema...', credential);

const expanded = await expandJSONLD(credential);
validateCredentialSchema(expanded, schema, credential['@context']);
console.log('Success!');
}

async function main() {
await validateSchema(bolSchema, bolCred);
await validateSchema(prCardSchema, credPRCard);
await validateSchema(qpInbonSchema, qPInbondCred);
await validateSchema(healthWorkerPassportSchema, healthCareWorkerCred);

await validateSchema(infectionDiagnosisSchema, infectionDiagnosisCred);
await validateSchema(immunityEventRecordSchema, immunityEventRecordCred);
await validateSchema(noInfectionSchema, noInfectionCred);

Expand Down

0 comments on commit 02c6ff9

Please sign in to comment.