From 7c53d89086f67a5d7918dc0dbc65c10b568f57c9 Mon Sep 17 00:00:00 2001 From: Jonathan Alvarez Date: Thu, 8 Feb 2024 11:27:39 -0500 Subject: [PATCH] feat: add karatdao schema Signed-off-by: Jonathan Alvarez --- dist/schemas/25-platform-user/1-0-0.json | 164 ++++++++++++++++++ dist/schemas/25-platform-user/latest.json | 1 + .../src/lib/25-platform-user/1-0-0.test.ts | 22 +++ .../schemas/src/lib/25-platform-user/1-0-0.ts | 36 ++++ 4 files changed, 223 insertions(+) create mode 100644 dist/schemas/25-platform-user/1-0-0.json create mode 120000 dist/schemas/25-platform-user/latest.json create mode 100644 packages/schemas/src/lib/25-platform-user/1-0-0.test.ts create mode 100644 packages/schemas/src/lib/25-platform-user/1-0-0.ts diff --git a/dist/schemas/25-platform-user/1-0-0.json b/dist/schemas/25-platform-user/1-0-0.json new file mode 100644 index 0000000..c8a1dc6 --- /dev/null +++ b/dist/schemas/25-platform-user/1-0-0.json @@ -0,0 +1,164 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/25-platform-user/1-0-0.json", + "title": "Platform user", + "description": "You are a user of a certain platform", + "type": "object", + "required": [ + "@context", + "issuer", + "issuanceDate", + "credentialSubject", + "proof" + ], + "properties": { + "@context": { + "type": "array", + "items": { + "type": "string", + "format": "uri" + } + }, + "id": { + "type": "string" + }, + "type": { + "type": "array", + "items": { + "type": "string" + } + }, + "issuer": { + "type": "object", + "required": [ + "id", + "name", + "mrenclave" + ], + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "mrenclave": { + "type": "string" + } + } + }, + "issuanceDate": { + "type": "string", + "format": "date-time" + }, + "proof": { + "type": "object", + "required": [ + "created", + "type", + "proofPurpose", + "proofValue", + "verificationMethod" + ], + "properties": { + "created": { + "type": "string", + "format": "date-time" + }, + "type": { + "type": "string" + }, + "proofPurpose": { + "type": "string" + }, + "proofValue": { + "type": "string" + }, + "verificationMethod": { + "type": "string" + } + } + }, + "credentialSubject": { + "title": "Credential Subject of Platform user", + "type": "object", + "required": [ + "id", + "type", + "values", + "endpoint", + "assertions" + ], + "properties": { + "id": { + "type": "string" + }, + "type": { + "type": "string" + }, + "description": { + "type": "string" + }, + "values": { + "type": "array", + "minItems": 1, + "items": { + "type": "boolean" + } + }, + "endpoint": { + "type": "string", + "format": "uri" + }, + "assertions": { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "required": [ + "and" + ], + "properties": { + "and": { + "type": "array", + "minItems": 1, + "maxItems": 1, + "additionalItems": false, + "items": [ + { + "type": "object", + "required": [ + "src", + "op", + "dst" + ], + "properties": { + "src": { + "type": "string", + "enum": [ + "$platform" + ] + }, + "op": { + "type": "string", + "enum": [ + "==" + ] + }, + "dst": { + "type": "string", + "enum": [ + "KaratDao" + ] + } + } + } + ] + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/dist/schemas/25-platform-user/latest.json b/dist/schemas/25-platform-user/latest.json new file mode 120000 index 0000000..766daa7 --- /dev/null +++ b/dist/schemas/25-platform-user/latest.json @@ -0,0 +1 @@ +1-0-0.json \ No newline at end of file diff --git a/packages/schemas/src/lib/25-platform-user/1-0-0.test.ts b/packages/schemas/src/lib/25-platform-user/1-0-0.test.ts new file mode 100644 index 0000000..cd8221a --- /dev/null +++ b/packages/schemas/src/lib/25-platform-user/1-0-0.test.ts @@ -0,0 +1,22 @@ +import * as fs from 'fs'; +import { globSync as glob } from 'fast-glob'; + +import { ajv } from '../ajv'; +import { schema } from './1-0-0'; + +const jsonFiles = glob('examples/25-platform-user/*.json'); + +describe('25-platform-user/1-0-0', () => { + it.skip.each(jsonFiles)('should work for %s', (example) => { + const validate = ajv.compile(schema); + + expect(validate.errors).toBeNull(); + + const json = JSON.parse(fs.readFileSync(example, 'utf8')); + const valid = validate(json); + + if (!valid) console.log(validate.errors); + + expect(valid).toBeTruthy(); + }); +}); diff --git a/packages/schemas/src/lib/25-platform-user/1-0-0.ts b/packages/schemas/src/lib/25-platform-user/1-0-0.ts new file mode 100644 index 0000000..7a4d1e8 --- /dev/null +++ b/packages/schemas/src/lib/25-platform-user/1-0-0.ts @@ -0,0 +1,36 @@ +import { JSONSchema7 } from 'json-schema'; + +import { schema as base } from '../0-base/1-0-0'; +import { resolveGitHubPath } from '../helpers'; +import { credentialSubject, assertion } from '../schema-helpers'; + +const supportedPlatforms = [ + // https://github.com/litentry/litentry-parachain/blob/dev/tee-worker/litentry/core/credentials-v2/src/platform_user/mod.rs + 'KaratDao', +]; + +export const schema: JSONSchema7 = { + ...base, + + $id: resolveGitHubPath('25-platform-user/1-0-0.json'), + + title: 'Platform user', + description: 'You are a user of a certain platform', + + properties: { + ...base.properties, + + credentialSubject: credentialSubject({ + title: 'Credential Subject of Platform user', + assertions: assertion.and({ + items: [ + assertion.clause({ + src: ['$platform'], + op: ['=='], + dst: supportedPlatforms, + }), + ], + }), + }), + }, +};