From c37d349f87fc5e88fde8c68ca38eeeba0a35d533 Mon Sep 17 00:00:00 2001 From: Orie Steele Date: Mon, 8 Jul 2024 14:34:22 -0500 Subject: [PATCH 1/2] 0.3.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 10b5027..287fb81 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@transmute/verifiable-credentials", - "version": "0.2.3", + "version": "0.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@transmute/verifiable-credentials", - "version": "0.2.3", + "version": "0.3.0", "license": "Apache-2.0", "dependencies": { "@transmute/cose": "^0.1.1", diff --git a/package.json b/package.json index 5003c01..f49aa52 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@transmute/verifiable-credentials", - "version": "0.2.3", + "version": "0.3.0", "description": "An opinionated typescript library for w3c verifiable credentials.", "main": "./dist/index.js", "typings": "dist/index.d.ts", From 080e1bcf434ab6fde23ea4f6218b2d789d5290d0 Mon Sep 17 00:00:00 2001 From: Orie Steele Date: Wed, 10 Jul 2024 17:20:01 -0500 Subject: [PATCH 2/2] add test --- test/json-schema-tests/no-dollar-id.test.ts | 115 ++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 test/json-schema-tests/no-dollar-id.test.ts diff --git a/test/json-schema-tests/no-dollar-id.test.ts b/test/json-schema-tests/no-dollar-id.test.ts new file mode 100644 index 0000000..a6786f0 --- /dev/null +++ b/test/json-schema-tests/no-dollar-id.test.ts @@ -0,0 +1,115 @@ +import * as jose from "jose"; +import moment from "moment"; + +import * as transmute from "../../src"; + +const alg = `ES256`; +const issuer = `did:example:123`; +const baseURL = `https://vendor.example/api`; + +let privateKey: any +let publicKey: any +let issued: any + +describe("json schema tests", () => { + beforeAll(async () => { + privateKey = await transmute.key.generate({ + alg, + type: "application/jwk+json", + }); + publicKey = await transmute.key.publicFromPrivate({ + type: "application/jwk+json", + content: privateKey, + }); + issued = await transmute + .issuer({ + alg, + type: "application/vc+ld+json+jwt", + signer: { + sign: async (bytes: Uint8Array) => { + const jws = await new jose.CompactSign(bytes) + .setProtectedHeader({ kid: `${issuer}#key-42`, alg }) + .sign( + await transmute.key.importKeyLike({ + type: "application/jwk+json", + content: privateKey, + }) + ); + return transmute.text.encoder.encode(jws); + }, + }, + }) + .issue({ + claimset: transmute.text.encoder.encode(` +"@context": + - https://www.w3.org/ns/credentials/v2 + - ${baseURL}/context/v2 + +id: ${baseURL}/credentials/3732 +type: + - VerifiableCredential + - ExampleDegreeCredential +issuer: + id: ${issuer} + name: "Example University" +validFrom: ${moment().toISOString()} +credentialSchema: + id: ${baseURL}/schemas/product-passport + type: JsonSchema +credentialSubject: + id: did:example:ebfeb1f712ebc6f1c276e12ec21 + degree: + type: ExampleBachelorDegree + subtype: Bachelor of Science and Arts +`), + }); + }) + it("validate twice without error", async () => { + const validator = await transmute.validator({ + resolver: { + resolve: async ({ id, type, content }) => { + if (id === `${baseURL}/schemas/product-passport`) { + return { + type: `application/schema+json`, + content: transmute.text.encoder.encode(` +{ + "title": "Example JSON Schema", + "description": "This is a test schema", + "type": "object", + "properties": { + "credentialSubject": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + } + } + } +} + `), + }; + } + if (content != undefined && type === `application/vc+ld+json+jwt`) { + return { + type: "application/jwk+json", + content: publicKey, + }; + } + throw new Error("Resolver option not supported."); + }, + }, + }); + // call valdiate twice for sanity + const valid1 = await validator.validate({ + type: "application/vc+ld+json+jwt", + content: issued, + }); + expect(valid1.verified).toBe(true); + const valid2 = await validator.validate({ + type: "application/vc+ld+json+jwt", + content: issued, + }); + expect(valid2.verified).toBe(true); + }); +});