From 29c6b0efc37f181d40aff560d4d481eb84e0ea9a Mon Sep 17 00:00:00 2001 From: Simonas Karuzas Date: Fri, 9 Oct 2020 11:58:28 +0300 Subject: [PATCH] fix: Local copy of W3C types --- packages/daf-core/src/types/IMessage.ts | 77 ++++++- packages/daf-w3c/api/daf-w3c.api.json | 14 +- packages/daf-w3c/api/daf-w3c.api.md | 156 +++++++------- .../daf-w3c/src/schemas/ICredentialIssuer.ts | 204 +++++++++--------- 4 files changed, 265 insertions(+), 186 deletions(-) diff --git a/packages/daf-core/src/types/IMessage.ts b/packages/daf-core/src/types/IMessage.ts index a8f27bdfb..ae788b157 100644 --- a/packages/daf-core/src/types/IMessage.ts +++ b/packages/daf-core/src/types/IMessage.ts @@ -1,18 +1,87 @@ -import { Verifiable, W3CCredential, W3CPresentation } from 'did-jwt-vc' -export { W3CCredential, W3CPresentation } /** * Verifiable Credential {@link https://github.com/decentralized-identity/did-jwt-vc} * @public */ -export type VerifiableCredential = Verifiable +export interface VerifiableCredential { + '@context': string[] + id?: string + type: string[] + issuer: { id: string; [x: string]: any } + issuanceDate: string + expirationDate?: string + credentialSubject: { + id?: string + [x: string]: any + } + credentialStatus?: { + id: string + type: string + } + proof: { + type?: string + [x: string]: any + } + [x: string]: any +} /** * Verifiable Presentation {@link https://github.com/decentralized-identity/did-jwt-vc} * @public */ -export type VerifiablePresentation = Verifiable +export interface VerifiablePresentation { + id?: string + holder: string + issuanceDate?: string + expirationDate?: string + '@context': string[] + type: string[] + verifier: string[] + verifiableCredential: VerifiableCredential[] + proof: { + type?: string + [x: string]: any + } + [x: string]: any +} +/** + * W3CCredential {@link https://github.com/decentralized-identity/did-jwt-vc} + * @public + */ +export interface W3CCredential { + '@context': string[] + id?: string + type: string[] + issuer: { id: string; [x: string]: any } + issuanceDate: string + expirationDate?: string + credentialSubject: { + id?: string + [x: string]: any + } + credentialStatus?: { + id: string + type: string + } + [x: string]: any +} + +/** + * W3CPresentation {@link https://github.com/decentralized-identity/did-jwt-vc} + * @public + */ +export interface W3CPresentation { + id?: string + holder: string + issuanceDate?: string + expirationDate?: string + '@context': string[] + type: string[] + verifier: string[] + verifiableCredential: VerifiableCredential[] + [x: string]: any +} /** * Message meta data diff --git a/packages/daf-w3c/api/daf-w3c.api.json b/packages/daf-w3c/api/daf-w3c.api.json index 1788976ea..f469d07d1 100644 --- a/packages/daf-w3c/api/daf-w3c.api.json +++ b/packages/daf-w3c/api/daf-w3c.api.json @@ -90,7 +90,7 @@ { "kind": "Reference", "text": "VerifiableCredential", - "canonicalReference": "daf-core!VerifiableCredential:type" + "canonicalReference": "daf-core!VerifiableCredential:interface" }, { "kind": "Content", @@ -165,7 +165,7 @@ { "kind": "Reference", "text": "VerifiablePresentation", - "canonicalReference": "daf-core!VerifiablePresentation:type" + "canonicalReference": "daf-core!VerifiablePresentation:interface" }, { "kind": "Content", @@ -239,7 +239,7 @@ }, { "kind": "Content", - "text": "{\n components: {\n schemas: {\n ICreateVerifiableCredentialArgs: {\n type: string;\n properties: {\n credential: {\n $ref: string;\n description: string;\n };\n save: {\n type: string;\n description: string;\n };\n proofFormat: {\n $ref: string;\n description: string;\n };\n };\n required: string[];\n additionalProperties: boolean;\n description: string;\n };\n W3CCredential: {\n type: string;\n properties: {\n \"@context\": {\n type: string;\n items: {\n type: string;\n };\n };\n type: {\n type: string;\n items: {\n type: string;\n };\n };\n issuer: {\n type: string;\n properties: {\n id: {\n type: string;\n };\n };\n required: string[];\n };\n issuanceDate: {\n type: string;\n };\n expirationDate: {\n type: string;\n };\n id: {\n type: string;\n };\n credentialSubject: {\n type: string;\n properties: {\n id: {\n type: string;\n };\n };\n };\n credentialStatus: {\n $ref: string;\n };\n };\n required: string[];\n description: string;\n };\n CredentialStatus: {\n type: string;\n properties: {\n id: {\n type: string;\n };\n type: {\n type: string;\n };\n };\n required: string[];\n additionalProperties: boolean;\n };\n EncodingFormat: {\n type: string;\n const: string;\n description: string;\n };\n VerifiableCredential: {\n $ref: string;\n description: string;\n };\n \"Verifiable-W3CCredential\": {\n type: string;\n additionalProperties: boolean;\n properties: {\n proof: {\n $ref: string;\n };\n id: {\n type: string;\n };\n credentialSubject: {\n type: string;\n properties: {\n id: {\n type: string;\n };\n };\n };\n credentialStatus: {\n type: string;\n properties: {\n id: {\n type: string;\n };\n type: {\n type: string;\n };\n };\n required: string[];\n };\n \"@context\": {\n type: string;\n properties: {};\n };\n type: {\n type: string;\n properties: {};\n };\n issuer: {\n type: string;\n properties: {\n id: {\n type: string;\n };\n };\n required: string[];\n };\n issuanceDate: {\n type: string;\n };\n expirationDate: {\n type: string;\n };\n };\n required: string[];\n description: string;\n };\n Proof: {\n type: string;\n properties: {\n type: {\n type: string;\n };\n };\n };\n ICreateVerifiablePresentationArgs: {\n type: string;\n properties: {\n presentation: {\n $ref: string;\n description: string;\n };\n save: {\n type: string;\n description: string;\n };\n proofFormat: {\n $ref: string;\n description: string;\n };\n };\n required: string[];\n additionalProperties: boolean;\n description: string;\n };\n W3CPresentation: {\n type: string;\n properties: {\n \"@context\": {\n type: string;\n items: {\n type: string;\n };\n };\n type: {\n type: string;\n items: {\n type: string;\n };\n };\n verifier: {\n type: string;\n items: {\n type: string;\n };\n };\n verifiableCredential: {\n type: string;\n items: {\n $ref: string;\n };\n };\n id: {\n type: string;\n };\n holder: {\n type: string;\n };\n issuanceDate: {\n type: string;\n };\n expirationDate: {\n type: string;\n };\n };\n required: string[];\n description: string;\n };\n VerifiablePresentation: {\n $ref: string;\n description: string;\n };\n \"Verifiable-W3CPresentation\": {\n type: string;\n additionalProperties: boolean;\n properties: {\n proof: {\n $ref: string;\n };\n id: {\n type: string;\n };\n holder: {\n type: string;\n };\n issuanceDate: {\n type: string;\n };\n expirationDate: {\n type: string;\n };\n \"@context\": {\n type: string;\n properties: {};\n };\n type: {\n type: string;\n properties: {};\n };\n verifier: {\n type: string;\n properties: {};\n };\n verifiableCredential: {\n type: string;\n properties: {};\n };\n };\n required: string[];\n description: string;\n };\n };\n methods: {\n createVerifiableCredential: {\n description: string;\n arguments: {\n $ref: string;\n };\n returnType: {\n $ref: string;\n };\n };\n createVerifiablePresentation: {\n description: string;\n arguments: {\n $ref: string;\n };\n returnType: {\n $ref: string;\n };\n };\n };\n };\n }" + "text": "{\n components: {\n schemas: {\n ICreateVerifiableCredentialArgs: {\n type: string;\n properties: {\n credential: {\n $ref: string;\n description: string;\n };\n save: {\n type: string;\n description: string;\n };\n proofFormat: {\n $ref: string;\n description: string;\n };\n };\n required: string[];\n additionalProperties: boolean;\n description: string;\n };\n W3CCredential: {\n type: string;\n properties: {\n \"@context\": {\n type: string;\n items: {\n type: string;\n };\n };\n id: {\n type: string;\n };\n type: {\n type: string;\n items: {\n type: string;\n };\n };\n issuer: {\n type: string;\n properties: {\n id: {\n type: string; /**\n * The json payload of the Credential according to the\n * {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model}\n *\n * The signer of the Credential is chosen based on the `issuer.id` property\n * of the `credential`\n */\n };\n };\n required: string[];\n };\n issuanceDate: {\n type: string;\n };\n expirationDate: {\n type: string;\n };\n credentialSubject: {\n type: string;\n properties: {\n id: {\n type: string;\n };\n };\n };\n credentialStatus: {\n type: string;\n properties: {\n id: {\n type: string;\n };\n type: {\n type: string;\n };\n };\n required: string[];\n additionalProperties: boolean;\n };\n };\n required: string[];\n description: string;\n };\n EncodingFormat: {\n type: string;\n const: string;\n description: string;\n };\n VerifiableCredential: {\n type: string;\n properties: {\n \"@context\": {\n type: string;\n items: {\n type: string;\n };\n };\n id: {\n type: string;\n };\n type: {\n type: string;\n items: {\n type: string;\n };\n };\n issuer: {\n type: string;\n properties: {\n id: {\n type: string;\n };\n };\n required: string[];\n };\n issuanceDate: {\n type: string;\n };\n expirationDate: {\n type: string;\n };\n credentialSubject: {\n type: string;\n properties: {\n id: {\n type: string;\n };\n };\n };\n credentialStatus: {\n type: string;\n properties: {\n id: {\n type: string;\n };\n type: {\n type: string;\n };\n };\n required: string[];\n additionalProperties: boolean;\n };\n proof: {\n type: string;\n properties: {\n type: {\n type: string;\n };\n };\n };\n };\n required: string[];\n description: string;\n };\n ICreateVerifiablePresentationArgs: {\n type: string;\n properties: {\n presentation: {\n $ref: string;\n description: string;\n };\n save: {\n type: string;\n description: string;\n };\n proofFormat: {\n $ref: string;\n description: string;\n };\n };\n required: string[];\n additionalProperties: boolean;\n description: string;\n };\n W3CPresentation: {\n type: string;\n properties: {\n id: {\n type: string;\n };\n holder: {\n type: string;\n };\n issuanceDate: {\n type: string;\n };\n expirationDate: {\n type: string;\n };\n \"@context\": {\n type: string;\n items: {\n type: string;\n };\n };\n type: {\n type: string;\n items: {\n type: string;\n };\n };\n verifier: {\n type: string;\n items: {\n type: string;\n };\n };\n verifiableCredential: {\n type: string;\n items: {\n $ref: string;\n };\n };\n };\n required: string[];\n description: string;\n };\n VerifiablePresentation: {\n type: string;\n properties: {\n id: {\n type: string;\n };\n holder: {\n type: string;\n };\n issuanceDate: {\n type: string;\n };\n expirationDate: {\n type: string;\n };\n \"@context\": {\n type: string;\n items: {\n type: string;\n };\n };\n type: {\n type: string;\n items: {\n type: string;\n };\n };\n verifier: {\n type: string;\n items: {\n type: string;\n };\n };\n verifiableCredential: {\n type: string;\n items: {\n $ref: string;\n };\n };\n proof: {\n type: string;\n properties: {\n type: {\n type: string;\n };\n };\n };\n };\n required: string[];\n description: string;\n };\n };\n methods: {\n createVerifiableCredential: {\n description: string;\n arguments: {\n $ref: string;\n };\n returnType: {\n $ref: string;\n };\n };\n createVerifiablePresentation: {\n description: string;\n arguments: {\n $ref: string;\n };\n returnType: {\n $ref: string;\n };\n };\n };\n };\n }" }, { "kind": "Content", @@ -287,7 +287,7 @@ { "kind": "Reference", "text": "W3CCredential", - "canonicalReference": "did-jwt-vc!W3CCredential:type" + "canonicalReference": "daf-core!W3CCredential:interface" }, { "kind": "Content", @@ -380,7 +380,7 @@ { "kind": "Reference", "text": "W3CPresentation", - "canonicalReference": "did-jwt-vc!W3CPresentation:type" + "canonicalReference": "daf-core!W3CPresentation:interface" }, { "kind": "Content", @@ -509,7 +509,7 @@ { "kind": "Reference", "text": "VerifiableCredential", - "canonicalReference": "daf-core!VerifiableCredential:type" + "canonicalReference": "daf-core!VerifiableCredential:interface" }, { "kind": "Content", @@ -583,7 +583,7 @@ { "kind": "Reference", "text": "VerifiablePresentation", - "canonicalReference": "daf-core!VerifiablePresentation:type" + "canonicalReference": "daf-core!VerifiablePresentation:interface" }, { "kind": "Content", diff --git a/packages/daf-w3c/api/daf-w3c.api.md b/packages/daf-w3c/api/daf-w3c.api.md index e66e095b3..468c52865 100644 --- a/packages/daf-w3c/api/daf-w3c.api.md +++ b/packages/daf-w3c/api/daf-w3c.api.md @@ -59,6 +59,9 @@ export class CredentialIssuer implements IAgentPlugin { type: string; }; }; + id: { + type: string; + }; type: { type: string; items: { @@ -69,7 +72,13 @@ export class CredentialIssuer implements IAgentPlugin { type: string; properties: { id: { - type: string; + type: string; /** + * The json payload of the Credential according to the + * {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model} + * + * The signer of the Credential is chosen based on the `issuer.id` property + * of the `credential` + */ }; }; required: string[]; @@ -80,9 +89,6 @@ export class CredentialIssuer implements IAgentPlugin { expirationDate: { type: string; }; - id: { - type: string; - }; credentialSubject: { type: string; properties: { @@ -92,24 +98,21 @@ export class CredentialIssuer implements IAgentPlugin { }; }; credentialStatus: { - $ref: string; - }; - }; - required: string[]; - description: string; - }; - CredentialStatus: { - type: string; - properties: { - id: { - type: string; - }; - type: { type: string; + properties: { + id: { + type: string; + }; + type: { + type: string; + }; + }; + required: string[]; + additionalProperties: boolean; }; }; required: string[]; - additionalProperties: boolean; + description: string; }; EncodingFormat: { type: string; @@ -117,74 +120,71 @@ export class CredentialIssuer implements IAgentPlugin { description: string; }; VerifiableCredential: { - $ref: string; - description: string; - }; - "Verifiable-W3CCredential": { type: string; - additionalProperties: boolean; properties: { - proof: { - $ref: string; + "@context": { + type: string; + items: { + type: string; + }; }; id: { type: string; }; - credentialSubject: { + type: { type: string; - properties: { - id: { - type: string; - }; + items: { + type: string; }; }; - credentialStatus: { + issuer: { type: string; properties: { id: { type: string; }; - type: { - type: string; - }; }; required: string[]; }; - "@context": { + issuanceDate: { type: string; - properties: {}; }; - type: { + expirationDate: { type: string; - properties: {}; }; - issuer: { + credentialSubject: { type: string; properties: { id: { type: string; }; }; - required: string[]; }; - issuanceDate: { + credentialStatus: { type: string; + properties: { + id: { + type: string; + }; + type: { + type: string; + }; + }; + required: string[]; + additionalProperties: boolean; }; - expirationDate: { + proof: { type: string; + properties: { + type: { + type: string; + }; + }; }; }; required: string[]; description: string; }; - Proof: { - type: string; - properties: { - type: { - type: string; - }; - }; - }; ICreateVerifiablePresentationArgs: { type: string; properties: { @@ -208,6 +208,18 @@ export class CredentialIssuer implements IAgentPlugin { W3CPresentation: { type: string; properties: { + id: { + type: string; + }; + holder: { + type: string; + }; + issuanceDate: { + type: string; + }; + expirationDate: { + type: string; + }; "@context": { type: string; items: { @@ -232,33 +244,13 @@ export class CredentialIssuer implements IAgentPlugin { $ref: string; }; }; - id: { - type: string; - }; - holder: { - type: string; - }; - issuanceDate: { - type: string; - }; - expirationDate: { - type: string; - }; }; required: string[]; description: string; }; VerifiablePresentation: { - $ref: string; - description: string; - }; - "Verifiable-W3CPresentation": { type: string; - additionalProperties: boolean; properties: { - proof: { - $ref: string; - }; id: { type: string; }; @@ -273,19 +265,35 @@ export class CredentialIssuer implements IAgentPlugin { }; "@context": { type: string; - properties: {}; + items: { + type: string; + }; }; type: { type: string; - properties: {}; + items: { + type: string; + }; }; verifier: { type: string; - properties: {}; + items: { + type: string; + }; }; verifiableCredential: { type: string; - properties: {}; + items: { + $ref: string; + }; + }; + proof: { + type: string; + properties: { + type: { + type: string; + }; + }; }; }; required: string[]; diff --git a/packages/daf-w3c/src/schemas/ICredentialIssuer.ts b/packages/daf-w3c/src/schemas/ICredentialIssuer.ts index 23805eb8f..452fbd173 100644 --- a/packages/daf-w3c/src/schemas/ICredentialIssuer.ts +++ b/packages/daf-w3c/src/schemas/ICredentialIssuer.ts @@ -33,6 +33,9 @@ export default { "type": "string" } }, + "id": { + "type": "string" + }, "type": { "type": "array", "items": { @@ -56,9 +59,6 @@ export default { "expirationDate": { "type": "string" }, - "id": { - "type": "string" - }, "credentialSubject": { "type": "object", "properties": { @@ -68,33 +68,30 @@ export default { } }, "credentialStatus": { - "$ref": "#/components/schemas/CredentialStatus" + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "type": { + "type": "string" + } + }, + "required": [ + "id", + "type" + ], + "additionalProperties": false } }, "required": [ "@context", - "credentialSubject", - "issuanceDate", + "type", "issuer", - "type" - ], - "description": "This data type represents a parsed VerifiableCredential. It is meant to be an unambiguous representation of the properties of a Credential and is usually the result of a transformation method.\n\n`issuer` is always an object with an `id` property and potentially other app specific issuer claims `issuanceDate` is an ISO DateTime string `expirationDate`, is a nullable ISO DateTime string\n\nAny JWT specific properties are transformed to the broader W3C variant and any app specific properties are left intact" - }, - "CredentialStatus": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "type": { - "type": "string" - } - }, - "required": [ - "id", - "type" + "issuanceDate", + "credentialSubject" ], - "additionalProperties": false + "description": "W3CCredential {@link https://github.com/decentralized-identity/did-jwt-vc}" }, "EncodingFormat": { "type": "string", @@ -102,19 +99,40 @@ export default { "description": "The type of encoding to be used for the Verifiable Credential or Presentation to be generated.\n\nOnly `jwt` is supported at the moment." }, "VerifiableCredential": { - "$ref": "#/components/schemas/Verifiable-W3CCredential", - "description": "Verifiable Credential {@link https://github.com/decentralized-identity/did-jwt-vc}" - }, - "Verifiable-W3CCredential": { "type": "object", - "additionalProperties": false, "properties": { - "proof": { - "$ref": "#/components/schemas/Proof" + "@context": { + "type": "array", + "items": { + "type": "string" + } }, "id": { "type": "string" }, + "type": { + "type": "array", + "items": { + "type": "string" + } + }, + "issuer": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "required": [ + "id" + ] + }, + "issuanceDate": { + "type": "string" + }, + "expirationDate": { + "type": "string" + }, "credentialSubject": { "type": "object", "properties": { @@ -136,51 +154,27 @@ export default { "required": [ "id", "type" - ] - }, - "@context": { - "type": "object", - "properties": {} - }, - "type": { - "type": "object", - "properties": {} + ], + "additionalProperties": false }, - "issuer": { + "proof": { "type": "object", "properties": { - "id": { + "type": { "type": "string" } - }, - "required": [ - "id" - ] - }, - "issuanceDate": { - "type": "string" - }, - "expirationDate": { - "type": "string" + } } }, "required": [ "@context", - "credentialSubject", - "issuanceDate", + "type", "issuer", - "proof", - "type" + "issuanceDate", + "credentialSubject", + "proof" ], - "description": "Represents a readonly representation of a verifiable object, including the {@link Proof} property that can be used to verify it." - }, - "Proof": { - "type": "object", - "properties": { - "type": { - "type": "string" - } - } + "description": "Verifiable Credential {@link https://github.com/decentralized-identity/did-jwt-vc}" }, "ICreateVerifiablePresentationArgs": { "type": "object", @@ -208,6 +202,18 @@ export default { "W3CPresentation": { "type": "object", "properties": { + "id": { + "type": "string" + }, + "holder": { + "type": "string" + }, + "issuanceDate": { + "type": "string" + }, + "expirationDate": { + "type": "string" + }, "@context": { "type": "array", "items": { @@ -229,42 +235,22 @@ export default { "verifiableCredential": { "type": "array", "items": { - "$ref": "#/components/schemas/Verifiable-W3CCredential" + "$ref": "#/components/schemas/VerifiableCredential" } - }, - "id": { - "type": "string" - }, - "holder": { - "type": "string" - }, - "issuanceDate": { - "type": "string" - }, - "expirationDate": { - "type": "string" } }, "required": [ - "@context", "holder", + "@context", "type", - "verifiableCredential", - "verifier" + "verifier", + "verifiableCredential" ], - "description": "This data type represents a parsed Presentation payload. It is meant to be an unambiguous representation of the properties of a Presentation and is usually the result of a transformation method.\n\nThe `verifiableCredential` array should contain parsed `Verifiable-Credential` elements. Any JWT specific properties are transformed to the broader W3C variant and any other app specific properties are left intact." + "description": "W3CPresentation {@link https://github.com/decentralized-identity/did-jwt-vc}" }, "VerifiablePresentation": { - "$ref": "#/components/schemas/Verifiable-W3CPresentation", - "description": "Verifiable Presentation {@link https://github.com/decentralized-identity/did-jwt-vc}" - }, - "Verifiable-W3CPresentation": { "type": "object", - "additionalProperties": false, "properties": { - "proof": { - "$ref": "#/components/schemas/Proof" - }, "id": { "type": "string" }, @@ -278,31 +264,47 @@ export default { "type": "string" }, "@context": { - "type": "object", - "properties": {} + "type": "array", + "items": { + "type": "string" + } }, "type": { - "type": "object", - "properties": {} + "type": "array", + "items": { + "type": "string" + } }, "verifier": { - "type": "object", - "properties": {} + "type": "array", + "items": { + "type": "string" + } }, "verifiableCredential": { + "type": "array", + "items": { + "$ref": "#/components/schemas/VerifiableCredential" + } + }, + "proof": { "type": "object", - "properties": {} + "properties": { + "type": { + "type": "string" + } + } } }, "required": [ - "@context", "holder", - "proof", + "@context", "type", + "verifier", "verifiableCredential", - "verifier" + "proof" ], - "description": "Represents a readonly representation of a verifiable object, including the {@link Proof} property that can be used to verify it." + "description": "Verifiable Presentation {@link https://github.com/decentralized-identity/did-jwt-vc}" } }, "methods": {