From 92543cd702c2ac40c0d155864faa43afdf4ea221 Mon Sep 17 00:00:00 2001 From: Neal Date: Fri, 12 Apr 2024 12:01:16 -0500 Subject: [PATCH 1/7] cred schema impl --- .../credentials/src/verifiable-credential.ts | 13 +++++- .../tests/verifiable-credential.spec.ts | 42 +++++++++++++------ 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/packages/credentials/src/verifiable-credential.ts b/packages/credentials/src/verifiable-credential.ts index 4ca6d31d2..b7722a7db 100644 --- a/packages/credentials/src/verifiable-credential.ts +++ b/packages/credentials/src/verifiable-credential.ts @@ -19,6 +19,14 @@ export const DEFAULT_VC_TYPE = 'VerifiableCredential'; */ export type VcDataModel = ICredential; +/** + * A credential schema defines the structure and content of the data, enabling verifiers to assess if the data adheres to the established schema. + */ +export type CredentialSchema = { + id: string; + type: string; +}; + /** * Options for creating a verifiable credential. * @param type Optional. The type of the credential, can be a string or an array of strings. @@ -43,6 +51,8 @@ export type VerifiableCredentialCreateOptions = { issuanceDate?: string; /** The expiration date of the credential, as a string. */ expirationDate?: string; + /** The credential schema of the credential */ + credentialSchema?: CredentialSchema; /** The evidence of the credential, as an array of any. */ evidence?: any[]; }; @@ -147,7 +157,7 @@ export class VerifiableCredential { * @returns A [VerifiableCredential] instance. */ public static async create(options: VerifiableCredentialCreateOptions): Promise { - const { type, issuer, subject, data, issuanceDate, expirationDate, evidence } = options; + const { type, issuer, subject, data, issuanceDate, expirationDate, credentialSchema, evidence } = options; const jsonData = JSON.parse(JSON.stringify(data)); @@ -179,6 +189,7 @@ export class VerifiableCredential { credentialSubject : credentialSubject, // Include optional properties only if they have values ...(expirationDate && { expirationDate }), + ...(credentialSchema && { credentialSchema }), ...(evidence && { evidence }), }; diff --git a/packages/credentials/tests/verifiable-credential.spec.ts b/packages/credentials/tests/verifiable-credential.spec.ts index 356b33546..38451f2ba 100644 --- a/packages/credentials/tests/verifiable-credential.spec.ts +++ b/packages/credentials/tests/verifiable-credential.spec.ts @@ -7,7 +7,7 @@ import { DidDht, DidKey, DidIon, DidJwk } from '@web5/dids'; import { Jwt } from '../src/jwt.js'; import { VerifiableCredential } from '../src/verifiable-credential.js'; import CredentialsVerifyTestVector from '../../../web5-spec/test-vectors/credentials/verify.json' assert { type: 'json' }; -import { getCurrentXmlSchema112Timestamp, getXmlSchema112Timestamp } from '../src/utils.js'; +import { getCurrentXmlSchema112Timestamp } from '../src/utils.js'; describe('Verifiable Credential Tests', async() => { let issuerDid: BearerDid; @@ -92,28 +92,46 @@ describe('Verifiable Credential Tests', async() => { }); it('create and sign kyc vc with did:jwk', async () => { - const did = await DidJwk.create(); + const subjectDid = await DidJwk.create(); + const issuerDid = await DidJwk.create(); const vc = await VerifiableCredential.create({ type : 'KnowYourCustomerCred', - subject : did.uri, - issuer : did.uri, - expirationDate : getXmlSchema112Timestamp(2687920690), // 2055-03-05 + subject : subjectDid.uri, + issuer : issuerDid.uri, + issuanceDate : '2023-05-19T08:02:04Z', + expirationDate : `2055-05-19T08:02:04Z`, data : { - country: 'us' - } + id : subjectDid.uri, + country_of_residence : 'US', + tier : 'Tier 1' + }, + credentialSchema: { + id : ' https://schema.org/PFI', + type : 'JsonSchema' + }, + evidence: [ + { kind: 'document_verification', checks: ['passport', 'utility_bill'] }, + { kind: 'sanctions_check', checks: ['daily'] } + ] }); - const vcJwt = await vc.sign({ did }); + const vcJwt = await vc.sign({ did: issuerDid }); await VerifiableCredential.verify({ vcJwt }); for( const currentVc of [vc, VerifiableCredential.parseJwt({ vcJwt })]){ - expect(currentVc.issuer).to.equal(did.uri); - expect(currentVc.subject).to.equal(did.uri); + expect(currentVc.issuer).to.equal(issuerDid.uri); + expect(currentVc.subject).to.equal(subjectDid.uri); expect(currentVc.type).to.equal('KnowYourCustomerCred'); - expect(currentVc.vcDataModel.issuanceDate).to.not.be.undefined; - expect(currentVc.vcDataModel.credentialSubject).to.deep.equal({ id: did.uri, country: 'us'}); + expect(currentVc.vcDataModel.issuanceDate).to.equal('2023-05-19T08:02:04Z'); + expect(currentVc.vcDataModel.expirationDate).to.equal('2055-05-19T08:02:04Z'); + expect(currentVc.vcDataModel.credentialSubject).to.deep.equal({ id: subjectDid.uri, country_of_residence: 'US', tier: 'Tier 1'}); + expect(currentVc.vcDataModel.credentialSchema).to.deep.equal({ id: ' https://schema.org/PFI', type: 'JsonSchema'}); + expect(currentVc.vcDataModel.evidence).to.deep.equal([ + { kind: 'document_verification', checks: ['passport', 'utility_bill'] }, + { kind: 'sanctions_check', checks: ['daily'] } + ]); } }); From 13a083dd3cd6275bb74b0bfb5e7dcf638bbab90e Mon Sep 17 00:00:00 2001 From: Neal Date: Fri, 12 Apr 2024 13:31:39 -0500 Subject: [PATCH 2/7] bump package version --- packages/credentials/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/credentials/package.json b/packages/credentials/package.json index 582d0f5f8..fbf7288be 100644 --- a/packages/credentials/package.json +++ b/packages/credentials/package.json @@ -1,6 +1,6 @@ { "name": "@web5/credentials", - "version": "1.0.0", + "version": "1.0.1", "description": "Verifiable Credentials", "type": "module", "main": "./dist/cjs/index.js", From f18a7d3fc8d0fe308829fc1eac029f7e6f003491 Mon Sep 17 00:00:00 2001 From: Neal Date: Mon, 15 Apr 2024 16:09:59 -0500 Subject: [PATCH 3/7] remove 1.0.1 --- packages/credentials/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/credentials/package.json b/packages/credentials/package.json index fbf7288be..582d0f5f8 100644 --- a/packages/credentials/package.json +++ b/packages/credentials/package.json @@ -1,6 +1,6 @@ { "name": "@web5/credentials", - "version": "1.0.1", + "version": "1.0.0", "description": "Verifiable Credentials", "type": "module", "main": "./dist/cjs/index.js", From a3f80b5c197661e8889fe3be4b4c9b961a789a70 Mon Sep 17 00:00:00 2001 From: Neal Date: Mon, 15 Apr 2024 16:12:14 -0500 Subject: [PATCH 4/7] add changesets --- packages/credentials/.changeset/README.md | 8 ++++++++ packages/credentials/.changeset/config.json | 11 +++++++++++ .../credentials/.changeset/tasty-otters-approve.md | 5 +++++ 3 files changed, 24 insertions(+) create mode 100644 packages/credentials/.changeset/README.md create mode 100644 packages/credentials/.changeset/config.json create mode 100644 packages/credentials/.changeset/tasty-otters-approve.md diff --git a/packages/credentials/.changeset/README.md b/packages/credentials/.changeset/README.md new file mode 100644 index 000000000..e5b6d8d6a --- /dev/null +++ b/packages/credentials/.changeset/README.md @@ -0,0 +1,8 @@ +# Changesets + +Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works +with multi-package repos, or single-package repos to help you version and publish your code. You can +find the full documentation for it [in our repository](https://github.com/changesets/changesets) + +We have a quick list of common questions to get you started engaging with this project in +[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) diff --git a/packages/credentials/.changeset/config.json b/packages/credentials/.changeset/config.json new file mode 100644 index 000000000..91b6a9512 --- /dev/null +++ b/packages/credentials/.changeset/config.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", + "changelog": "@changesets/cli/changelog", + "commit": false, + "fixed": [], + "linked": [], + "access": "restricted", + "baseBranch": "main", + "updateInternalDependencies": "patch", + "ignore": [] +} diff --git a/packages/credentials/.changeset/tasty-otters-approve.md b/packages/credentials/.changeset/tasty-otters-approve.md new file mode 100644 index 000000000..b3097448a --- /dev/null +++ b/packages/credentials/.changeset/tasty-otters-approve.md @@ -0,0 +1,5 @@ +--- +"@web5/credentials": minor +--- + +Updating Verifiable Credential Data Model to have support for credentialSchema From 7d4934daee8a7b0696240307db1b21a54a96a0fe Mon Sep 17 00:00:00 2001 From: Neal Date: Mon, 15 Apr 2024 16:14:39 -0500 Subject: [PATCH 5/7] wrong dir changeset --- packages/credentials/.changeset/README.md | 8 -------- packages/credentials/.changeset/config.json | 11 ----------- .../credentials/.changeset/tasty-otters-approve.md | 5 ----- 3 files changed, 24 deletions(-) delete mode 100644 packages/credentials/.changeset/README.md delete mode 100644 packages/credentials/.changeset/config.json delete mode 100644 packages/credentials/.changeset/tasty-otters-approve.md diff --git a/packages/credentials/.changeset/README.md b/packages/credentials/.changeset/README.md deleted file mode 100644 index e5b6d8d6a..000000000 --- a/packages/credentials/.changeset/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Changesets - -Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works -with multi-package repos, or single-package repos to help you version and publish your code. You can -find the full documentation for it [in our repository](https://github.com/changesets/changesets) - -We have a quick list of common questions to get you started engaging with this project in -[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) diff --git a/packages/credentials/.changeset/config.json b/packages/credentials/.changeset/config.json deleted file mode 100644 index 91b6a9512..000000000 --- a/packages/credentials/.changeset/config.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", - "changelog": "@changesets/cli/changelog", - "commit": false, - "fixed": [], - "linked": [], - "access": "restricted", - "baseBranch": "main", - "updateInternalDependencies": "patch", - "ignore": [] -} diff --git a/packages/credentials/.changeset/tasty-otters-approve.md b/packages/credentials/.changeset/tasty-otters-approve.md deleted file mode 100644 index b3097448a..000000000 --- a/packages/credentials/.changeset/tasty-otters-approve.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@web5/credentials": minor ---- - -Updating Verifiable Credential Data Model to have support for credentialSchema From 167c3bed557dd3e902284528765c4f10452561d6 Mon Sep 17 00:00:00 2001 From: Neal Date: Mon, 15 Apr 2024 16:15:43 -0500 Subject: [PATCH 6/7] update changeset --- .changeset/famous-pianos-drum.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/famous-pianos-drum.md diff --git a/.changeset/famous-pianos-drum.md b/.changeset/famous-pianos-drum.md new file mode 100644 index 000000000..dcbb979ee --- /dev/null +++ b/.changeset/famous-pianos-drum.md @@ -0,0 +1,5 @@ +--- +"@web5/credentials": minor +--- + +Adding credentialSchema to our Verifiable Credential Data Model From b3c0f69967ad5e3c50122ca4f4fec5c0301b489f Mon Sep 17 00:00:00 2001 From: Neal Date: Mon, 15 Apr 2024 16:42:03 -0500 Subject: [PATCH 7/7] updated --- .changeset/famous-pianos-drum.md | 5 ----- .changeset/seven-horses-clap.md | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 .changeset/famous-pianos-drum.md create mode 100644 .changeset/seven-horses-clap.md diff --git a/.changeset/famous-pianos-drum.md b/.changeset/famous-pianos-drum.md deleted file mode 100644 index dcbb979ee..000000000 --- a/.changeset/famous-pianos-drum.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@web5/credentials": minor ---- - -Adding credentialSchema to our Verifiable Credential Data Model diff --git a/.changeset/seven-horses-clap.md b/.changeset/seven-horses-clap.md new file mode 100644 index 000000000..eea61cc00 --- /dev/null +++ b/.changeset/seven-horses-clap.md @@ -0,0 +1,5 @@ +--- +"@web5/credentials": patch +--- + +Added credentialSchema to the VcDataModel