Skip to content

Commit

Permalink
wpi
Browse files Browse the repository at this point in the history
  • Loading branch information
elribonazo committed Apr 25, 2024
1 parent 10730a1 commit 8272969
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/pollux/models/JWTVerifiableCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export class JWTCredential
return JWTCredential.fromJWT(jsonParsed, jws)
}

static createPayload(obj: any): JWTCredentialPayload {
return obj
}

get id() {
return this.jti;
}
Expand Down Expand Up @@ -159,6 +163,20 @@ export class JWTCredential
};
}

verificableCredential() {
// TODO - Type information
return {
"@context": [
"https://www.w3.org/2018/credentials/v1"
],
type: ["VerifiableCredential"],
"issuer": this.issuer,
"issuanceDate": this.issuanceDate,
"expirationDate": this.expirationDate,
"credentialSubject": this.subject
};
}

toStorable() {
const id = this.jti || this.getProperty(JWTVerifiableCredentialProperties.jti);
const data = { id, ...Object.fromEntries(this.properties) };
Expand Down
45 changes: 41 additions & 4 deletions tests/pollux/Pollux.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as sinon from "sinon";
import SinonChai from "sinon-chai";
import { expect } from "chai";

import { AttachmentDescriptor, CredentialRequestOptions, CredentialType, Curve, DID, LinkSecret, Message, PresentationOptions } from "../../src/domain";
import { AttachmentDescriptor, CredentialRequestOptions, CredentialType, Curve, DID, LinkSecret, Message, PresentationOptions, PrivateKey } from "../../src/domain";
import { JWTCredential } from "../../src/pollux/models/JWTVerifiableCredential";
import Castor from "../../src/castor/Castor";
import { Apollo } from "../../src/domain/buildingBlocks/Apollo";
Expand All @@ -14,6 +14,8 @@ import { base64 } from "multiformats/bases/base64";
import { AnonCredsCredential, AnonCredsRecoveryId } from "../../src/pollux/models/AnonCredsVerifiableCredential";
import { PresentationRequest } from "../../src/pollux/models/PresentationRequest";
import * as Fixtures from "../fixtures";
import { JWT } from "../../src/apollo/utils/jwt/JWT";
import { JWTPayload } from "did-jwt";

chai.use(SinonChai);
chai.use(chaiAsPromised);
Expand All @@ -39,12 +41,14 @@ const jwtParts = [
const jwtString = jwtParts.join(".");

describe("Pollux", () => {
let apollo: Apollo;
let pollux: Pollux;
let castor: Castor;

beforeEach(async () => {
sandbox = sinon.createSandbox();
const apollo = {} as Apollo;
const castor = new Castor(apollo);
apollo = {} as Apollo;
castor = new Castor(apollo);
pollux = new Pollux(castor);
await pollux.start();
});
Expand Down Expand Up @@ -855,6 +859,8 @@ describe("Pollux", () => {


it("Should be able to create a presentationDefinitionRequest for a JWT Credential", async () => {
jest.restoreAllMocks();


const presentationDefinitionRequest = await pollux.createPresentationDefinitionRequest(
CredentialType.JWT,
Expand Down Expand Up @@ -891,6 +897,34 @@ describe("Pollux", () => {
})

it("Should create a valid presentationSubmission from a valid presentationRequest", async () => {
jest.restoreAllMocks();

const Pollux = jest.requireActual("../../src/pollux/Pollux").default;
const Castor = jest.requireActual("../../src/castor/Castor").default;
const Apollo = jest.requireActual("../../src/apollo/Apollo").default;
const JWT = jest.requireActual("../../src/apollo/utils/jwt/JWT").JWT;

type VerificationTestCase = {
apollo: Apollo,
castor: Castor,
jwt: JWT,
pollux: Pollux,
issuer: DID,
holder: DID,
}

function createVerificationTestCase(options: VerificationTestCase) {

}

const apollo = new Apollo();
const castor = new Castor(apollo);
const jwt = new JWT(castor)
const pollux = new Pollux(
castor,
undefined,
jwt
)

const presentationDefinition = await pollux.createPresentationDefinitionRequest(
CredentialType.JWT,
Expand Down Expand Up @@ -922,7 +956,10 @@ describe("Pollux", () => {
privateKey
);

const verify = await pollux.verifyPresentationSubmission(presentaationSubmissionJSON)
const verify = await pollux.verifyPresentationSubmission(presentaationSubmissionJSON, {
presentationDefinitionRequest: presentationDefinition
});

expect(verify).to.eq(true)


Expand Down

0 comments on commit 8272969

Please sign in to comment.