From fce3abd846c0382322e26546eafcd1ad903e4d78 Mon Sep 17 00:00:00 2001 From: Allain Magyar Date: Tue, 4 Apr 2023 12:21:46 -0300 Subject: [PATCH] test: update unit test --- domain/models/JWTVerifiableCredential.ts | 4 +- tests/pluto/Pluto.test.ts | 262 +++------------------- tests/pollux/Pollux.test.ts | 267 ++++++++--------------- 3 files changed, 125 insertions(+), 408 deletions(-) diff --git a/domain/models/JWTVerifiableCredential.ts b/domain/models/JWTVerifiableCredential.ts index c927d3700..6cb0fdd87 100644 --- a/domain/models/JWTVerifiableCredential.ts +++ b/domain/models/JWTVerifiableCredential.ts @@ -58,9 +58,9 @@ export class JWTVerifiablePayload implements VerifiableCredential { if (sub) { this.subject = DID.fromString(sub); } - this.issuanceDate = new Date(nbf).toDateString(); + this.issuanceDate = new Date(nbf).toISOString(); if (exp) { - this.expirationDate = new Date(exp).toDateString(); + this.expirationDate = new Date(exp).toISOString(); } if (verifiableCredential.credentialSchema) { this.credentialSchema = verifiableCredential.credentialSchema; diff --git a/tests/pluto/Pluto.test.ts b/tests/pluto/Pluto.test.ts index 40fa0c0bc..8e9021551 100644 --- a/tests/pluto/Pluto.test.ts +++ b/tests/pluto/Pluto.test.ts @@ -7,28 +7,24 @@ import { } from "../../domain"; import { expect } from "chai"; import { randomUUID } from "crypto"; -import { MessageDirection } from "../../domain/models/Message"; -import { CredentialType } from "../../domain/models/VerifiableCredential"; +import { MessageDirection } from "../../domain"; +import { CredentialType } from "../../domain"; describe("Pluto tests", () => { - it("should start successfully", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); - }); - it("should store prism DID", async function () { - const instance = new Pluto({ + let instance: Pluto + + beforeEach(async () => { + instance = new Pluto({ type: "sqlite", dropSchema: true, database: "pluto.db", logger: "debug", - synchronize: true, + synchronize: true }); - await instance.start(); + await instance.start() + }) + + it("should store prism DID", async function () { const did = DID.fromString( "did:prism:a7bacdc91c264066f5858ae3c2e8a159982e8292dc4bf94e58ef8dd982ea9f38:ChwKGhIYCgdtYXN0ZXIwEAFKCwoJc2VjcDI1Nmsx" ); @@ -42,13 +38,6 @@ describe("Pluto tests", () => { }); it("should store message", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const messageId = randomUUID(); const message = { piuri: "test a", @@ -73,13 +62,6 @@ describe("Pluto tests", () => { }); it("should store messages", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const messageId = randomUUID(); const message = { @@ -108,13 +90,6 @@ describe("Pluto tests", () => { }); // it("should store private keys", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const privateKey: PrivateKey = { value: Buffer.from("some value"), keyCurve: getKeyCurveByNameAndIndex(Curve.X25519), @@ -124,12 +99,6 @@ describe("Pluto tests", () => { }); it("should store mediator", async function () { - const instance = new Pluto({ - type: "sqlite", - database: "pluto.db", - dropSchema: true, - }); - await instance.start(); const mediator = DID.fromString("did:prism:123"); const host = DID.fromString("did:prism:321"); const routing = DID.fromString("did:prism:432"); @@ -138,13 +107,6 @@ describe("Pluto tests", () => { }); it("should store credential", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); await instance.storeCredential({ id: "", credentialType: CredentialType.JWT, @@ -154,7 +116,7 @@ describe("Pluto tests", () => { id: randomUUID(), type: "decode_jwt", }, - credentialSubject: "", + credentialSubject: { name: "" }, credentialStatus: { id: randomUUID(), type: "test", @@ -172,8 +134,8 @@ describe("Pluto tests", () => { type: "test", }, issuer: DID.fromString("did:prism:123"), - issuanceDate: new Date().toDateString(), - expirationDate: new Date().toDateString(), + issuanceDate: new Date().toISOString(), + expirationDate: new Date().toISOString(), validFrom: { id: randomUUID(), type: "test", @@ -188,13 +150,6 @@ describe("Pluto tests", () => { }); it("should get all prism DIDs", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const did = DID.fromString( "did:prism:a7bacdc91c264066f5858ae3c2e8a159982e8292dc4bf94e58ef8dd982ea9f38:ChwKGhIYCgdtYXN0ZXIwEAFKCwoJc2VjcDI1Nmsx" ); @@ -213,13 +168,6 @@ describe("Pluto tests", () => { }); it("should get DID info by DID", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const did = DID.fromString( "did:prism:a7bacdc91c264066f5858ae3c2e8a159982e8292dc4bf94e58ef8dd982ea9f38:ChwKGhIYCgdtYXN0ZXIwEAFKCwoJc2VjcDI1Nmsx" ); @@ -239,13 +187,6 @@ describe("Pluto tests", () => { }); it("should get DID info by alias", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const did = DID.fromString("did:prism:dadsa:asdpijasiopdj"); const keyPathIndex = 0; const alias = "Did test"; @@ -261,13 +202,6 @@ describe("Pluto tests", () => { }); it("should get prism DID key path index", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const did = DID.fromString("did:prism:dadsa:1231321dhsauda23847"); const keyPathIndex = 10; const alias = "Did test"; @@ -284,13 +218,6 @@ describe("Pluto tests", () => { }); it("should get prism last key path index", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const did = DID.fromString("did:prism:dadsa:92jsadn1"); const keyPathIndex = 11; const alias = "Did test"; @@ -306,13 +233,6 @@ describe("Pluto tests", () => { }); // it("should get all peer DIDs", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const peerDid = DID.fromString("did:peer:3i21d"); const privateKey1: PrivateKey = { value: Buffer.from("some value"), @@ -347,14 +267,7 @@ describe("Pluto tests", () => { }); it("should get DID private keys by DID", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); const peerDid = DID.fromString("did:peer:3i21d"); - await instance.start(); const privateKey: PrivateKey = { value: Buffer.from("some value"), keyCurve: getKeyCurveByNameAndIndex(Curve.ED25519), @@ -371,13 +284,6 @@ describe("Pluto tests", () => { // it("should get DID private key by ID", async function () { const id = randomUUID(); - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const peerDid = DID.fromString("did:prism:3i21d"); const privateKey: PrivateKey = { value: Buffer.from("some value"), @@ -390,13 +296,6 @@ describe("Pluto tests", () => { }); it("should get all did pairs", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const host = DID.fromString("did:prism:123"); const receiver = DID.fromString("did:prism:321"); const name = "test"; @@ -415,13 +314,6 @@ describe("Pluto tests", () => { }); it("should get pair by DID", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const host = DID.fromString("did:prism:123"); const receiver = DID.fromString("did:prism:321"); const name = "test"; @@ -442,13 +334,6 @@ describe("Pluto tests", () => { }); it("should get pair by name", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const host = DID.fromString("did:prism:123"); const receiver = DID.fromString("did:prism:321"); const name = "test"; @@ -468,13 +353,6 @@ describe("Pluto tests", () => { }); // it("should get all messages", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); await instance.storeMessage({ id: randomUUID(), thid: "", @@ -484,24 +362,17 @@ describe("Pluto tests", () => { fromPrior: "", ack: ["test"], body: "Message", - createdTime: new Date().toDateString(), + createdTime: new Date().toISOString(), attachments: [], piuri: "", extraHeaders: ["x-extra-header"], - expiresTimePlus: new Date().toString(), + expiresTimePlus: new Date().toISOString(), }); const messages = await instance.getAllMessages(); expect(messages).not.empty; }); it("should get all messages by DID", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const message = { id: randomUUID(), thid: "", @@ -511,11 +382,11 @@ describe("Pluto tests", () => { fromPrior: "", ack: ["test"], body: "Message", - createdTime: new Date().toDateString(), + createdTime: new Date().toISOString(), attachments: [], piuri: "", extraHeaders: ["x-extra-header"], - expiresTimePlus: new Date().toString(), + expiresTimePlus: new Date().toISOString(), }; await instance.storeMessage(message); const messages = await instance.getAllMessagesByDID(message.from); @@ -523,13 +394,6 @@ describe("Pluto tests", () => { }); it("should get all messages sent", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const message = { id: randomUUID(), thid: "", @@ -539,11 +403,11 @@ describe("Pluto tests", () => { fromPrior: "", ack: ["test"], body: "Message", - createdTime: new Date().toDateString(), + createdTime: new Date().toISOString(), attachments: [], piuri: "", extraHeaders: ["x-extra-header"], - expiresTimePlus: new Date().toString(), + expiresTimePlus: new Date().toISOString(), }; await instance.storeMessage(message); const messages = await instance.getAllMessagesSent(); @@ -551,13 +415,6 @@ describe("Pluto tests", () => { }); // it("should get all messages received", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); const message = { id: randomUUID(), thid: "", @@ -567,11 +424,11 @@ describe("Pluto tests", () => { fromPrior: "", ack: ["test"], body: "Message", - createdTime: new Date().toDateString(), + createdTime: new Date().toISOString(), attachments: [], piuri: "", extraHeaders: ["x-extra-header"], - expiresTimePlus: new Date().toString(), + expiresTimePlus: new Date().toISOString(), }; await instance.storeMessage(message); const messages = await instance.getAllMessagesReceived(); @@ -579,15 +436,8 @@ describe("Pluto tests", () => { }); // it("should get all messages sent to", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); const to = DID.fromString("did:prism:123"); const from = DID.fromString("did:prism:321"); - await instance.start(); await instance.storeMessage({ id: randomUUID(), thid: "", @@ -597,26 +447,19 @@ describe("Pluto tests", () => { fromPrior: "", ack: ["test"], body: "Message", - createdTime: new Date().toDateString(), + createdTime: new Date().toISOString(), attachments: [], piuri: "", extraHeaders: ["x-extra-header"], - expiresTimePlus: new Date().toString(), + expiresTimePlus: new Date().toISOString(), }); const messages = await instance.getAllMessagesSentTo(to); expect(messages).not.empty; }); // it("should get all messages received from", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); const to = DID.fromString("did:prism:123"); const from = DID.fromString("did:prism:321"); - await instance.start(); await instance.storeMessage({ id: randomUUID(), thid: "", @@ -626,26 +469,19 @@ describe("Pluto tests", () => { fromPrior: "", ack: ["test"], body: "Message", - createdTime: new Date().toDateString(), + createdTime: new Date().toISOString(), attachments: [], piuri: "", extraHeaders: ["x-extra-header"], - expiresTimePlus: new Date().toString(), + expiresTimePlus: new Date().toISOString(), }); const messages = await instance.getAllMessagesReceivedFrom(from); expect(messages).not.empty; }); // it("should get all messages of type", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); const to = DID.fromString("did:prism:123"); const from = DID.fromString("did:prism:321"); - await instance.start(); const message = { id: randomUUID(), thid: "", @@ -655,11 +491,11 @@ describe("Pluto tests", () => { fromPrior: "", ack: ["test"], body: "Message", - createdTime: new Date().toDateString(), + createdTime: new Date().toISOString(), attachments: [], piuri: "type-example", extraHeaders: ["x-extra-header"], - expiresTimePlus: new Date().toString(), + expiresTimePlus: new Date().toISOString(), }; await instance.storeMessage(message); const messages = await instance.getAllMessagesOfType(message.piuri, to); @@ -667,15 +503,8 @@ describe("Pluto tests", () => { }); // it("should get all messages by from to DID", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); const to = DID.fromString("did:prism:123"); const from = DID.fromString("did:prism:321"); - await instance.start(); const message = { id: randomUUID(), @@ -686,11 +515,11 @@ describe("Pluto tests", () => { fromPrior: "", ack: ["test"], body: "Message", - createdTime: new Date().toDateString(), + createdTime: new Date().toISOString(), attachments: [], piuri: "type-example", extraHeaders: ["x-extra-header"], - expiresTimePlus: new Date().toString(), + expiresTimePlus: new Date().toISOString(), }; await instance.storeMessage(message); const result = await instance.getAllMessagesByFromToDID( @@ -702,15 +531,8 @@ describe("Pluto tests", () => { }); it("should get message", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); const to = DID.fromString("did:prism:123"); const from = DID.fromString("did:prism:321"); - await instance.start(); const message = { id: randomUUID(), @@ -721,11 +543,11 @@ describe("Pluto tests", () => { fromPrior: "", ack: ["test"], body: "Message", - createdTime: new Date().toDateString(), + createdTime: new Date().toISOString(), attachments: [], piuri: "type-example", extraHeaders: ["x-extra-header"], - expiresTimePlus: new Date().toString(), + expiresTimePlus: new Date().toISOString() }; await instance.storeMessage(message); const messages = await instance.getAllMessages(); @@ -735,14 +557,6 @@ describe("Pluto tests", () => { }); // it("should get all mediators", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); - const mediator = DID.fromString("did:prism:123"); const host = DID.fromString("did:prism:321"); const routing = DID.fromString("did:prism:432"); @@ -781,14 +595,6 @@ describe("Pluto tests", () => { }); it("should get all credentials", async function () { - const instance = new Pluto({ - type: "sqlite", - dropSchema: true, - database: "pluto.db", - synchronize: true, - }); - await instance.start(); - await instance.storeCredential({ id: "", credentialType: CredentialType.JWT, @@ -819,8 +625,8 @@ describe("Pluto tests", () => { }, issuer: DID.fromString("did:prism:123"), subject: DID.fromString("did:prism:123"), - issuanceDate: 1234345, - expirationDate: 45321, + issuanceDate: "2023-04-04T13:40:08.435Z", + expirationDate: "2023-04-04T13:40:08.435Z", validFrom: { id: randomUUID(), type: "test", diff --git a/tests/pollux/Pollux.test.ts b/tests/pollux/Pollux.test.ts index be7797955..54bab0a5e 100644 --- a/tests/pollux/Pollux.test.ts +++ b/tests/pollux/Pollux.test.ts @@ -1,15 +1,8 @@ -import { expect } from "chai"; -import { DID } from "../../domain"; +import {expect} from "chai"; +import {CredentialType, DID, VerifiableCredential} from "../../domain"; import Castor from "../../castor/Castor"; import Apollo from "../../domain/buildingBlocks/Apollo"; -import { - InvalidCredentialError, - InvalidJWTString, -} from "../../domain/models/errors/Pollux"; -import { - CredentialType, - VerifiableCredential, -} from "../../domain/models/VerifiableCredential"; +import {InvalidJWTString,} from "../../domain/models/errors/Pollux"; import Pollux from "../../pollux/Pollux"; const jwtParts = [ @@ -66,197 +59,115 @@ describe("Pollux", () => { const encodeCredential = (cred: object): string => { const json = JSON.stringify(cred); const encoded = Buffer.from(json).toString("base64"); - const value = `${jwtParts[0]}.${encoded}.${jwtParts[2]}`; - return value; + return `${jwtParts[0]}.${encoded}.${jwtParts[2]}`; }; describe("Valid Credential", () => { it(`should return JWTVerifiableCredential`, () => { - const cred: VerifiableCredential = { - id: "jwtid", - credentialType: CredentialType.JWT, - type: [CredentialType.JWT], - aud: ["aud-cred"], - context: ["context"], - credentialSubject: { subj: "credSubject" }, - evidence: { - id: "evidenceId", - type: "evidenceType", - }, - expirationDate: new Date().toDateString(), - issuanceDate: new Date().toDateString(), - issuer: new DID( - "did", - "peer", - "2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOiJodHRwczovL21lZGlhdG9yLnJvb3RzaWQuY2xvdWQiLCJhIjpbImRpZGNvbW0vdjIiXX0" - ), - refreshService: { - id: "refreshServiceId", - type: "refreshServiceType", - }, - termsOfUse: { - id: "termsOfUseId", - type: "termsOfUseType", - }, - validFrom: { - id: "validFromId", - type: "validFromType", - }, - validUntil: { - id: "validUntilId", - type: "validUntilType", - }, - credentialSchema: { - id: "credentialSchemaId", - type: "credentialSchemaType", - }, - credentialStatus: { - id: "credentialStatusId", - type: "credentialStatusType", - }, - proof: "proof", - }; - - const jsonPayload: any = { - id: "123", - iss: "did:peer:2.issuer", - nbf: "nbf", - sub: "sub", - exp: "exp", - aud: ["aud-json"], - vc: cred - }; - - const encoded = encodeCredential(jsonPayload); + const jwtPayload = createPayload("jwtid", "proof", CredentialType.JWT) + const encoded = encodeCredential(jwtPayload); const result = pollux.parseVerifiableCredential(encoded); expect(result).to.not.be.undefined; expect(result.id).to.equal(encoded); - - expect(result.aud).to.eql(jsonPayload.aud); - expect(result.context).to.eql(cred.context); - expect(result.credentialSubject).to.eql(cred.credentialSubject); - expect(result.credentialType).to.equal(CredentialType.JWT); - - expect(result.expirationDate).to.equal(new Date(jsonPayload.exp).toDateString()); - expect(result.issuanceDate).to.equal(new Date(jsonPayload.nbf).toDateString()); - - expect(result.type).to.eql(cred.type); - - // expect(result.proof).to.equal(cred.proof); - - expect(result.issuer).to.be.an.instanceOf(DID); - expect(result.issuer.toString()).to.eql(jsonPayload.iss); - - expect(result.evidence).to.be.deep.equal(cred.evidence); - expect(result.evidence).to.eql(cred.evidence); - - expect(result.refreshService).to.deep.equal(cred.refreshService); - expect(result.refreshService).to.eql(cred.refreshService); - - expect(result.termsOfUse).to.deep.equal(cred.termsOfUse); - expect(result.termsOfUse).to.eql(cred.termsOfUse); - - // expect(result.validFrom).to.deep.equal(cred.validFrom); - // expect(result.validUntil).to.deep.equal(cred.validUntil); - - expect(result.credentialSchema).to.deep.equal(cred.credentialSchema); - expect(result.credentialStatus).to.deep.equal(cred.credentialStatus); + validateCredential(result, jwtPayload) }); // currently not handled it.skip(`should return W3CVerifiableCredential`, () => { - const cred: VerifiableCredential = { - id: "w3cid", - credentialType: CredentialType.W3C, - type: [CredentialType.W3C], - aud: ["aud"], - context: ["context"], - credentialSubject: { whatever: "credSubject" }, - evidence: { - id: "evidenceId", - type: "evidenceType", - }, - expirationDate: new Date().toDateString(), - issuanceDate: new Date().toDateString(), - issuer: new DID( - "did", - "peer", - "2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOiJodHRwczovL21lZGlhdG9yLnJvb3RzaWQuY2xvdWQiLCJhIjpbImRpZGNvbW0vdjIiXX0" - ), - refreshService: { - id: "refreshServiceId", - type: "refreshServiceType", - }, - termsOfUse: { - id: "termsOfUseId", - type: "termsOfUseType", - }, - validFrom: { - id: "validFromId", - type: "validFromType", - }, - validUntil: { - id: "validUntilId", - type: "validUntilType", - }, - credentialSchema: { - id: "credentialSchemaId", - type: "credentialSchemaType", - }, - credentialStatus: { - id: "credentialStatusId", - type: "credentialStatusType", - }, - proof: "proofW3c", - }; - - const jsonPayload: any = { - id: "123", - iss: "did:peer:2.issuer", - nbf: "nbf", - sub: "sub", - exp: "exp", - aud: ["aud-json"], - vc: cred - }; - - const encoded = encodeCredential(jsonPayload); + const jwtPayload = createPayload("w3cid", "proofW3c", CredentialType.W3C) + const encoded = encodeCredential(jwtPayload); const result = pollux.parseVerifiableCredential(encoded); expect(result).to.not.be.undefined; expect(result.id).to.equal(encoded); + validateCredential(result, jwtPayload.vc) + }); + }); + }); - expect(result.aud).to.eql(jsonPayload.aud); - expect(result.context).to.eql(cred.context); - expect(result.credentialSubject).to.eql(cred.credentialSubject); - expect(result.credentialType).to.equal(CredentialType.W3C); - - expect(result.expirationDate).to.equal(jsonPayload.exp); - expect(result.issuanceDate).to.equal(jsonPayload.nbf); + function createPayload(id: string, proof: string, credentialType: CredentialType) { + const cred: VerifiableCredential = { + id, + credentialType: credentialType, + type: [credentialType], + aud: ["aud"], + context: ["context"], + credentialSubject: { whatever: "credSubject" }, + evidence: { + id: "evidenceId", + type: "evidenceType", + }, + expirationDate: new Date().toISOString(), + issuanceDate: new Date().toISOString(), + issuer: new DID( + "did", + "peer", + "2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOiJodHRwczovL21lZGlhdG9yLnJvb3RzaWQuY2xvdWQiLCJhIjpbImRpZGNvbW0vdjIiXX0" + ), + refreshService: { + id: "refreshServiceId", + type: "refreshServiceType", + }, + termsOfUse: { + id: "termsOfUseId", + type: "termsOfUseType", + }, + validFrom: { + id: "validFromId", + type: "validFromType", + }, + validUntil: { + id: "validUntilId", + type: "validUntilType", + }, + credentialSchema: { + id: "credentialSchemaId", + type: "credentialSchemaType", + }, + credentialStatus: { + id: "credentialStatusId", + type: "credentialStatusType", + }, + proof: proof, + }; - expect(result.type).to.eql(cred.type); + const jwtPayload: any = { + id: "123", + iss: "did:peer:2.issuer", + nbf: 1680615608435, + sub: "sub", + exp: 1680615608435, + aud: ["aud-json"], + vc: cred + }; + return jwtPayload + } + function validateCredential(result: VerifiableCredential, jwtPayload: any) { + let credential = jwtPayload.vc; - // expect(result.proof).to.equal(cred.proof); + expect(result.aud).to.be.deep.equal(jwtPayload.aud); + expect(result.context).to.be.deep.equal(credential.context); + expect(result.credentialSubject).to.be.deep.equal(credential.credentialSubject); + expect(result.credentialType).to.be.equal(credential.credentialType); - expect(result.issuer).to.be.an.instanceOf(DID); - expect(result.issuer.toString()).to.eql(jsonPayload.iss); + expect(result.expirationDate).to.be.equal(new Date(jwtPayload.exp).toISOString()); + expect(result.issuanceDate).to.be.equal(new Date(jwtPayload.nbf).toISOString()); - expect(result.evidence).to.deep.equal(cred.evidence); - expect(result.evidence).to.eql(cred.evidence); + expect(result.type).to.be.deep.equal(credential.type); - expect(result.refreshService).to.deep.equal(cred.refreshService); - expect(result.refreshService).to.eql(cred.refreshService); + // expect(result.proof).to.be.equal(cred.proof); - expect(result.termsOfUse).to.deep.equal(cred.termsOfUse); - expect(result.termsOfUse).to.eql(cred.termsOfUse); + expect(result.issuer).to.be.an.instanceOf(DID); + expect(result.issuer.toString()).to.be.equal(jwtPayload.iss); + expect(result.evidence).to.be.deep.equal(credential.evidence); + expect(result.refreshService).to.deep.equal(credential.refreshService); + expect(result.termsOfUse).to.deep.equal(credential.termsOfUse); - // expect(result.validFrom).to.deep.equal(cred.validFrom); - // expect(result.validUntil).to.deep.equal(cred.validUntil); + // expect(result.validFrom).to.be.deep.equal(credential.validFrom); + // expect(result.validUntil).to.be.deep.equal(credential.validUntil); - expect(result.credentialSchema).to.deep.equal(cred.credentialSchema); - expect(result.credentialStatus).to.deep.equal(cred.credentialStatus); - }); - }); - }); + expect(result.credentialSchema).to.be.deep.equal(credential.credentialSchema); + expect(result.credentialStatus).to.be.deep.equal(credential.credentialStatus); + } });