Skip to content

Commit

Permalink
feat(core-types): allow inline @context for Credentials and Presentat…
Browse files Browse the repository at this point in the history
…ions

fixes #1073
  • Loading branch information
mirceanis committed Feb 9, 2023
1 parent ba7a303 commit ae3e10c
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 257 deletions.
322 changes: 182 additions & 140 deletions packages/core-types/src/plugin.schema.json

Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions packages/core-types/src/types/vc-data-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ export interface ProofType {
[x: string]: any
}

/**
* The data type for `@context` properties of credentials, presentations, etc.
*
* @beta This API may change without a BREAKING CHANGE notice.
*/
export type ContextType = string | Record<string, any> | (string | Record<string, any>)[]

/**
* Represents an unsigned W3C Credential payload.
* See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model}
Expand All @@ -86,7 +93,7 @@ export interface UnsignedCredential {
issuer: IssuerType
credentialSubject: CredentialSubject
type?: string[] | string
'@context': string[] | string
'@context': ContextType
issuanceDate: string
expirationDate?: string
credentialStatus?: CredentialStatusReference
Expand Down Expand Up @@ -121,7 +128,7 @@ export interface UnsignedPresentation {
holder: string
verifiableCredential?: W3CVerifiableCredential[]
type?: string[] | string
'@context': string[] | string
'@context': ContextType
verifier?: string[]
issuanceDate?: string
expirationDate?: string
Expand Down Expand Up @@ -162,7 +169,7 @@ export interface CredentialPayload {
issuer: IssuerType
credentialSubject?: CredentialSubject
type?: string[]
'@context'?: string[]
'@context'?: ContextType
issuanceDate?: DateType
expirationDate?: DateType
credentialStatus?: CredentialStatusReference
Expand All @@ -180,7 +187,7 @@ export interface PresentationPayload {
holder: string
verifiableCredential?: W3CVerifiableCredential[]
type?: string[]
'@context'?: string[]
'@context'?: ContextType
verifier?: string[]
issuanceDate?: DateType
expirationDate?: DateType
Expand Down
58 changes: 28 additions & 30 deletions packages/credential-eip712/src/plugin.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
}
},
"@context": {
"type": "array",
"items": {
"type": "string"
}
"$ref": "#/components/schemas/ContextType"
},
"issuanceDate": {
"$ref": "#/components/schemas/DateType"
Expand Down Expand Up @@ -86,6 +83,30 @@
},
"description": "The value of the credentialSubject property is defined as a set of objects that contain one or more properties that are each related to a subject of the verifiable credential. Each object MAY contain an id.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#credential-subject | Credential Subject }"
},
"ContextType": {
"anyOf": [
{
"type": "string"
},
{
"type": "object"
},
{
"type": "array",
"items": {
"anyOf": [
{
"type": "string"
},
{
"type": "object"
}
]
}
}
],
"description": "The data type for `@context` properties of credentials, presentations, etc."
},
"DateType": {
"type": "string",
"description": "Represents an issuance or expiration date for Credentials / Presentations. This is used as input when creating them."
Expand Down Expand Up @@ -132,17 +153,7 @@
]
},
"@context": {
"anyOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "string"
}
]
"$ref": "#/components/schemas/ContextType"
},
"issuanceDate": {
"type": "string"
Expand Down Expand Up @@ -211,10 +222,7 @@
}
},
"@context": {
"type": "array",
"items": {
"type": "string"
}
"$ref": "#/components/schemas/ContextType"
},
"verifier": {
"type": "array",
Expand Down Expand Up @@ -281,17 +289,7 @@
]
},
"@context": {
"anyOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "string"
}
]
"$ref": "#/components/schemas/ContextType"
},
"verifier": {
"type": "array",
Expand Down
58 changes: 28 additions & 30 deletions packages/credential-ld/src/plugin.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@
}
},
"@context": {
"type": "array",
"items": {
"type": "string"
}
"$ref": "#/components/schemas/ContextType"
},
"issuanceDate": {
"$ref": "#/components/schemas/DateType"
Expand Down Expand Up @@ -93,6 +90,30 @@
},
"description": "The value of the credentialSubject property is defined as a set of objects that contain one or more properties that are each related to a subject of the verifiable credential. Each object MAY contain an id.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#credential-subject | Credential Subject }"
},
"ContextType": {
"anyOf": [
{
"type": "string"
},
{
"type": "object"
},
{
"type": "array",
"items": {
"anyOf": [
{
"type": "string"
},
{
"type": "object"
}
]
}
}
],
"description": "The data type for `@context` properties of credentials, presentations, etc."
},
"DateType": {
"type": "string",
"description": "Represents an issuance or expiration date for Credentials / Presentations. This is used as input when creating them."
Expand Down Expand Up @@ -139,17 +160,7 @@
]
},
"@context": {
"anyOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "string"
}
]
"$ref": "#/components/schemas/ContextType"
},
"issuanceDate": {
"type": "string"
Expand Down Expand Up @@ -233,10 +244,7 @@
}
},
"@context": {
"type": "array",
"items": {
"type": "string"
}
"$ref": "#/components/schemas/ContextType"
},
"verifier": {
"type": "array",
Expand Down Expand Up @@ -303,17 +311,7 @@
]
},
"@context": {
"anyOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "string"
}
]
"$ref": "#/components/schemas/ContextType"
},
"verifier": {
"type": "array",
Expand Down
15 changes: 10 additions & 5 deletions packages/credential-ld/src/suites/JsonWebSignature2020.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { CredentialPayload, DIDDocument, IAgentContext, IKey, TKeyType } from "@
import { RequiredAgentMethods, VeramoLdSignature } from "../ld-suites.js";
import * as u8a from "uint8arrays";
import { JsonWebKey, JsonWebSignature } from "@transmute/json-web-signature";
import { encodeJoseBlob } from "@veramo/utils";
import { asArray, encodeJoseBlob } from "@veramo/utils";


/**
* Veramo wrapper for the JsonWebSignature2020 suite by Transmute Industries
*
*
* @alpha This API is experimental and is very likely to change or disappear in future releases without notice.
*/
export class VeramoJsonWebSignature2020 extends VeramoLdSignature {
getSupportedVerificationType(): 'JsonWebKey2020' {
return 'JsonWebKey2020'
}

getSupportedVeramoKeyType(): TKeyType {
return 'Ed25519'
}
Expand Down Expand Up @@ -68,6 +68,10 @@ export class VeramoJsonWebSignature2020 extends VeramoLdSignature {
key: verificationKey,
})

suite.ensureSuiteContext = ({ document }: { document: any, addSuiteContext: boolean }) => {
document['@context'] = [...asArray(document['@context'] || []), 'https://w3id.org/security/suites/jws-2020/v1']
}

return suite
}

Expand All @@ -76,10 +80,11 @@ export class VeramoJsonWebSignature2020 extends VeramoLdSignature {
}

preSigningCredModification(credential: CredentialPayload): void {
credential['@context'] = [...credential['@context'] || [], 'https://w3id.org/security/suites/jws-2020/v1']
// nop
}

preDidResolutionModification(didUrl: string, didDoc: DIDDocument): void {
// do nothing
}
}

}
48 changes: 26 additions & 22 deletions packages/did-comm/src/plugin.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,7 @@
]
},
"@context": {
"anyOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "string"
}
]
"$ref": "#/components/schemas/ContextType"
},
"issuanceDate": {
"type": "string"
Expand Down Expand Up @@ -462,6 +452,30 @@
},
"description": "The value of the credentialSubject property is defined as a set of objects that contain one or more properties that are each related to a subject of the verifiable credential. Each object MAY contain an id.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#credential-subject | Credential Subject }"
},
"ContextType": {
"anyOf": [
{
"type": "string"
},
{
"type": "object"
},
{
"type": "array",
"items": {
"anyOf": [
{
"type": "string"
},
{
"type": "object"
}
]
}
}
],
"description": "The data type for `@context` properties of credentials, presentations, etc."
},
"CredentialStatusReference": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -507,17 +521,7 @@
]
},
"@context": {
"anyOf": [
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "string"
}
]
"$ref": "#/components/schemas/ContextType"
},
"verifier": {
"type": "array",
Expand Down
Loading

0 comments on commit ae3e10c

Please sign in to comment.