Skip to content

Commit

Permalink
Merge pull request #179 from docknetwork/fix-deps
Browse files Browse the repository at this point in the history
Fix jsonld-signature and jsonld dependency issues
  • Loading branch information
cykoder authored Sep 30, 2020
2 parents dd7124f + 02c6ff9 commit 9c818b0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 209 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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "@docknetwork/sdk",
"version": "0.3.3",
"version": "0.3.4",
"main": "index.js",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/docknetwork/sdk"
},
"resolutions": {
"jsonld-signatures": "https://github.com/docknetwork/jsonld-signatures"
"jsonld-signatures": "https://github.com/docknetwork/jsonld-signatures",
"jsonld": "^2.0.2"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
Expand Down Expand Up @@ -76,12 +77,11 @@
"credentials-context": "^1.0.0",
"did-resolver": "^1.1.0",
"dotenv": "^8.2.0",
"ecdsa-secp256k1-signature-2019": "^1.0.0",
"elliptic": "^6.5.3",
"ethr-did-resolver": "^2.2.0",
"js-sha256": "^0.9.0",
"json-canonicalize": "^1.0.3",
"jsonld": "^3.1.1",
"jsonld": "^2.0.2",
"jsonld-signatures": "https://github.com/docknetwork/jsonld-signatures",
"jsonschema": "^1.2.6",
"rify": "^0.4.0",
Expand Down
6 changes: 5 additions & 1 deletion src/utils/vc.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ export function checkCredentialContext(credential) {
function hasDockRevocation(status) {
const id = status[credentialIDField];
if (status
&& jsonld.getValues(status, credentialTypeField).includes(RevRegType)
&& (
jsonld.getValues(status, credentialTypeField).includes(RevRegType)
|| jsonld.getValues(status, credentialTypeField).includes(`/${RevRegType}`)
)
&& id.startsWith(DockRevRegQualifier)
&& isHexWithGivenByteSize(id.slice(DockRevRegQualifier.length), RevRegIdByteSize)) {
return true;
Expand Down Expand Up @@ -240,6 +243,7 @@ export async function verifyCredential(credential, {
// Check for revocation only if the credential is verified and revocation check is needed.
if (credVer.verified && isRevocationCheckNeeded(expandedCredential, forceRevocationCheck, revocationApi)) {
const revResult = await checkRevocationStatus(expandedCredential, revocationApi);

// If revocation check fails, return the error else return the result of credential verification to avoid data loss.
if (!revResult.verified) {
return revResult;
Expand Down
51 changes: 3 additions & 48 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2854,20 +2854,12 @@ ecc-jsbn@~0.1.1:
jsbn "~0.1.0"
safer-buffer "^2.1.0"

ecdsa-secp256k1-signature-2019@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/ecdsa-secp256k1-signature-2019/-/ecdsa-secp256k1-signature-2019-1.0.1.tgz#0674299fa9206c1b3204c048dd97f6e0c5f89ca2"
integrity sha512-KtTpUQwl3h6mKff7M9i1iphh65862zrEObnS9gdSWa2kr6Y97jODTlWQFEotODPdmIMa27SA9cN1a9bAu324Og==
dependencies:
jsonld-signatures "^4.4.0"
secp256k1-key-pair "^1.0.0"

electron-to-chromium@^1.3.571:
version "1.3.574"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.574.tgz#bdd87f62fe70165e5c862a0acf0cee9889e23aa3"
integrity sha512-kF8Bfe1h8X1pPwlw6oRoIXj0DevowviP6fl0wcljm+nZjy/7+Fos4THo1N/7dVGEJlyEqK9C8qNnbheH+Eazfw==

elliptic@^6.5.0, elliptic@^6.5.3:
elliptic@^6.5.3:
version "6.5.3"
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.3.tgz#cb59eb2efdaf73a0bd78ccd7015a62ad6e0f93d6"
integrity sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==
Expand Down Expand Up @@ -4866,10 +4858,9 @@ jsonfile@^4.0.0:
optionalDependencies:
graceful-fs "^4.1.6"

jsonld-signatures@^4.4.0, jsonld-signatures@^5.0.0, "jsonld-signatures@https://github.com/docknetwork/jsonld-signatures":
jsonld-signatures@^5.0.0, "jsonld-signatures@https://github.com/docknetwork/jsonld-signatures":
version "5.1.1-0"
uid d11dd07326c257ffba0caf9373e1dcb61f1e3b36
resolved "https://github.com/docknetwork/jsonld-signatures#d11dd07326c257ffba0caf9373e1dcb61f1e3b36"
resolved "https://github.com/docknetwork/jsonld-signatures#164509c5708acf5ff15b4d6c3e4d8c5eb5f9ad8a"
dependencies:
base64url "^3.0.1"
crypto-ld "^3.7.0"
Expand All @@ -4890,19 +4881,6 @@ jsonld@^2.0.2:
semver "^6.3.0"
xmldom "0.1.19"

jsonld@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/jsonld/-/jsonld-3.1.1.tgz#ec9cf9f8aaacc17642a73715dfd788d2c1a51a74"
integrity sha512-GrqERUMZtMcdP8WgTt7drF3Ixf0dERA2Q4X3hTLyKt7CJTTQ5cM1vAHuX797piAejuh/KwNdKklKVB1kfYcJbw==
dependencies:
canonicalize "^1.0.1"
lru-cache "^5.1.1"
object.fromentries "^2.0.2"
rdf-canonize "^1.0.2"
request "^2.88.0"
semver "^6.3.0"
xmldom "0.1.19"

jsonschema@^1.2.6:
version "1.2.7"
resolved "https://registry.yarnpkg.com/jsonschema/-/jsonschema-1.2.7.tgz#4e6d6dc4d83dc80707055ba22c00ec6152c0e6e9"
Expand Down Expand Up @@ -5376,11 +5354,6 @@ node-fetch@^2.6.1:
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==

node-forge@^0.8.5:
version "0.8.5"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.8.5.tgz#57906f07614dc72762c84cef442f427c0e1b86ee"
integrity sha512-vFMQIWt+J/7FLNyKouZ9TazT74PRV3wgv9UT4cRjC8BffxFbKXkgIWR42URCPSnHm/QDz6BOlb2Q0U4+VQT67Q==

node-forge@^0.9.1, node-forge@~0.9.0:
version "0.9.2"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.9.2.tgz#b35a44c28889b2ea55cabf8c79e3563f9676190a"
Expand Down Expand Up @@ -5553,16 +5526,6 @@ object.entries@^1.1.2:
es-abstract "^1.17.5"
has "^1.0.3"

object.fromentries@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/object.fromentries/-/object.fromentries-2.0.2.tgz#4a09c9b9bb3843dd0f89acdb517a794d4f355ac9"
integrity sha512-r3ZiBH7MQppDJVLx6fhD618GKNG40CZYH9wgwdhKxBDDbQgjeWGGd4AtkZad84d291YxvWe7bJGuE65Anh0dxQ==
dependencies:
define-properties "^1.1.3"
es-abstract "^1.17.0-next.1"
function-bind "^1.1.1"
has "^1.0.3"

object.getownpropertydescriptors@^2.0.3, object.getownpropertydescriptors@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.1.0.tgz#369bf1f9592d8ab89d712dced5cb81c7c5352649"
Expand Down Expand Up @@ -6439,14 +6402,6 @@ scryptsy@^2.1.0:
resolved "https://registry.yarnpkg.com/scryptsy/-/scryptsy-2.1.0.tgz#8d1e8d0c025b58fdd25b6fa9a0dc905ee8faa790"
integrity sha512-1CdSqHQowJBnMAFyPEBRfqag/YP9OF394FV+4YREIJX4ljD7OxvQRDayyoyyCk+senRjSkP6VnUNQmVQqB6g7w==

secp256k1-key-pair@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/secp256k1-key-pair/-/secp256k1-key-pair-1.1.0.tgz#91bbb2ec294621f1bd9e0e7bff5219a4d91e72d8"
integrity sha512-XoNof6yZ4hiT3/dt+Nj7maWIqVyYIja1Z6Kv7nE5UQerdTLsoIuqyjlCT/bYItwb5k4Lni8IVyZvpi5GGeuXLQ==
dependencies:
elliptic "^6.5.0"
node-forge "^0.8.5"

security-context@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/security-context/-/security-context-4.0.0.tgz#e73f5d22bee9c7699a02eaaced359d001dc948e9"
Expand Down

0 comments on commit 9c818b0

Please sign in to comment.