Skip to content

Commit

Permalink
fix: improve test fixtures and jwt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elribonazo committed Apr 25, 2024
1 parent d226046 commit 10730a1
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/pollux/Pollux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default class Pollux implements IPollux {

if (presentationClaims.issuer) {
constaints.fields.push({
path: ["$.issuer", "$.iss", "$.vc.iss", "$.vc.issuer"],
path: ["$.vc.issuer", "$.issuer", "$.iss", "$.vc.iss"],
id: uuid(),
optional: false,
name: "issuer",
Expand Down
13 changes: 10 additions & 3 deletions tests/fixtures/credentials/jwt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AttachmentDescriptor, CredentialType } from "../../../src/domain";
import { AttachmentDescriptor, CredentialType, JWTCredentialPayload } from "../../../src/domain";
import { OfferCredential } from "../../../src/prism-agent/protocols/issueCredential/OfferCredential";
import { list } from "../dids";

Expand Down Expand Up @@ -126,16 +126,23 @@ export const credential = {
};


export const credentialPayloadEncoded = "eyJhbGciOiJFUzI1NksifQ.eyJpc3MiOiJkaWQ6cHJpc206MjU3MTlhOTZiMTUxMjA3MTY5ODFhODQzMGFkMGNiOTY4ZGQ1MzQwNzM1OTNjOGNkM2YxZDI3YTY4MDRlYzUwZTpDcG9DQ3BjQ0Vsb0tCV3RsZVMweEVBSkNUd29KYzJWamNESTFObXN4RWlBRW9TQ241dHlEYTZZNnItSW1TcXBKOFkxbWo3SkMzX29VekUwTnl5RWlDQm9nc2dOYWVSZGNDUkdQbGU4MlZ2OXRKZk53bDZyZzZWY2hSM09xaGlWYlRhOFNXd29HWVhWMGFDMHhFQVJDVHdvSmMyVmpjREkxTm1zeEVpRE1rQmQ2RnRpb0prM1hPRnUtX2N5NVhtUi00dFVRMk5MR2lXOGFJU29ta1JvZzZTZGU5UHduRzBRMFNCVG1GU1REYlNLQnZJVjZDVExYcmp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kxYQlM0M0I0ajlqbHNsS28yWmxkWHpqRWx3S0IyMWhjM1JsY2pBUUFVSlBDZ2x6WldOd01qVTJhekVTSUhrb1B0amp0U1haNmMxRGdZcmN5SW5GM1g4M2dIRTMxZ0RmbUFucmdtOGlHaUNVT0JreU45TFdsWXNISVU5M3RKeTF3VXVOd2VJX1k1YkpTcU5tWlhWODR3In0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiXSwiQGNvbnRleHQiOlsiaHR0cHM6XC9cL3d3dy53My5vcmdcLzIwMThcL2NyZWRlbnRpYWxzXC92MSJdfX0.x0SF17Y0VCDmt7HceOdTxfHlofsZmY18Rn6VQb0-r-k_Bm3hTi1-k2vkdjB25hdxyTCvxam-AkAP-Ag3Ahn5Ng";


// decoded payload value of real credential from the agent
export const credentialPayload = {
export const credentialPayload: JWTCredentialPayload = {
iss: "did:prism:25719a96b15120716981a8430ad0cb968dd534073593c8cd3f1d27a6804ec50e:CpoCCpcCEloKBWtleS0xEAJCTwoJc2VjcDI1NmsxEiAEoSCn5tyDa6Y6r-ImSqpJ8Y1mj7JC3_oUzE0NyyEiCBogsgNaeRdcCRGPle82Vv9tJfNwl6rg6VchR3OqhiVbTa8SWwoGYXV0aC0xEARCTwoJc2VjcDI1NmsxEiDMkBd6FtioJk3XOFu-_cy5XmR-4tUQ2NLGiW8aISomkRog6Sde9PwnG0Q0SBTmFSTDbSKBvIV6CTLXrjIJtteGImASXAoHbWFzdGVyMBABQk8KCXNlY3AyNTZrMRIgO710mt1W_ixDyQM3xIs7TpjLCNODQxgVhx5shfKNX1oaIHWPrw7IUKlfibQtx6Jk4TSjgcWNOfcOtU9D9PuZ7T9t",
sub: "did:prism:beea5234af46804714d8ea8ec77b66cc7f3e815c68abb475f254cf9c30626763:CscBCsQBEmQKD2F1dGhlbnRpY2F0aW9uMBAEQk8KCXNlY3AyNTZrMRIgeSg-2OO1JdnpzUOBitzIicXdfzeAcTfWAN-YCeuCbyIaIJQ4GTI30taViwchT3e0nLXBS43B4j9jlslKo2ZldXzjElwKB21hc3RlcjAQAUJPCglzZWNwMjU2azESIHkoPtjjtSXZ6c1DgYrcyInF3X83gHE31gDfmAnrgm8iGiCUOBkyN9LWlYsHIU93tJy1wUuNweI_Y5bJSqNmZXV84w",
nbf: 1685631995,
exp: 1685635595,
vc: credential,
type: CredentialType.JWT,
vp: undefined,
jti: credentialPayloadEncoded,
aud: ['did:prism:1234'],
revoked: false
};

export const credentialPayloadEncoded = "eyJhbGciOiJFUzI1NksifQ.eyJpc3MiOiJkaWQ6cHJpc206MjU3MTlhOTZiMTUxMjA3MTY5ODFhODQzMGFkMGNiOTY4ZGQ1MzQwNzM1OTNjOGNkM2YxZDI3YTY4MDRlYzUwZTpDcG9DQ3BjQ0Vsb0tCV3RsZVMweEVBSkNUd29KYzJWamNESTFObXN4RWlBRW9TQ241dHlEYTZZNnItSW1TcXBKOFkxbWo3SkMzX29VekUwTnl5RWlDQm9nc2dOYWVSZGNDUkdQbGU4MlZ2OXRKZk53bDZyZzZWY2hSM09xaGlWYlRhOFNXd29HWVhWMGFDMHhFQVJDVHdvSmMyVmpjREkxTm1zeEVpRE1rQmQ2RnRpb0prM1hPRnUtX2N5NVhtUi00dFVRMk5MR2lXOGFJU29ta1JvZzZTZGU5UHduRzBRMFNCVG1GU1REYlNLQnZJVjZDVExYcmpJSnR0ZUdJbUFTWEFvSGJXRnpkR1Z5TUJBQlFrOEtDWE5sWTNBeU5UWnJNUklnTzcxMG10MVdfaXhEeVFNM3hJczdUcGpMQ05PRFF4Z1ZoeDVzaGZLTlgxb2FJSFdQcnc3SVVLbGZpYlF0eDZKazRUU2pnY1dOT2ZjT3RVOUQ5UHVaN1Q5dCIsInN1YiI6ImRpZDpwcmlzbTpiZWVhNTIzNGFmNDY4MDQ3MTRkOGVhOGVjNzdiNjZjYzdmM2U4MTVjNjhhYmI0NzVmMjU0Y2Y5YzMwNjI2NzYzOkNzY0JDc1FCRW1RS0QyRjFkR2hsYm5ScF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dTxfHlofsZmY18Rn6VQb0-r-k_Bm3hTi1-k2vkdjB25hdxyTCvxam-AkAP-Ag3Ahn5Ng";


export const presentationRequest = {
Expand Down
18 changes: 13 additions & 5 deletions tests/pluto/Pluto.Credentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@ describe("Pluto", () => {
describe("Credentials", () => {
describe("JWT", () => {
test("uuid set on Domain instance - same after store", async () => {
const sut = new JWTCredential("did:peer:2.issuer", {}, "jwtString", 1680615608435, "did:peer:2.sub", 1680615608435, ["aud-json"], "jwtString");

const sut = new JWTCredential(
"did:peer:2.issuer",
Fixtures.Credentials.JWT.credentialPayload,
"jwtString",
1680615608435,
"did:peer:2.sub",
1680615608435,
["aud-json"],
"jwtString"
);
const uuid = sut.uuid;
expect(uuid).to.be.a.string;

Expand All @@ -37,13 +47,12 @@ describe("Pluto", () => {
test("Retrieved should match Stored", async () => {
const credentialIn = new JWTCredential(
Fixtures.Credentials.JWT.credentialPayload.iss,
Fixtures.Credentials.JWT.credentialPayload.vc,
Fixtures.Credentials.JWT.credentialPayload,
Fixtures.Credentials.JWT.credentialPayloadEncoded,
Fixtures.Credentials.JWT.credentialPayload.nbf,
Fixtures.Credentials.JWT.credentialPayload.sub,
Fixtures.Credentials.JWT.credentialPayload.exp,
// Fixtures.Credentials.JWT.credentialPayload.aud,
["aud"],
Fixtures.Credentials.JWT.credentialPayload.aud,
Fixtures.Credentials.JWT.credentialPayloadEncoded
);

Expand Down Expand Up @@ -80,7 +89,6 @@ describe("Pluto", () => {
expect(jwtCred.termsOfUse).to.eql(credentialIn.termsOfUse);
expect(jwtCred.type).to.eql(credentialIn.type);
expect(jwtCred.vc).to.deep.eq(credentialIn.vc);
expect(jwtCred.verifiableCredential).to.deep.eq(credentialIn.verifiableCredential);
});
});

Expand Down
28 changes: 14 additions & 14 deletions tests/pluto/Pluto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,26 +265,23 @@ describe("Pluto", () => {
proof: "proof",
};

const jwtPayload: any = {
id: "123",
const jwtPayload: Domain.JWTCredentialPayload = {
iss: "did:peer:2.issuer",
nbf: 1680615608435,
sub: "did:peer:2.sub",
exp: 1680615608435,
aud: ["aud-json"],
vc: vc,
vp: undefined,
jti: jwtString,
revoked: false,
type: CredentialType.JWT
};

const credential = new JWTCredential(
jwtPayload.iss,
vc,
jwtString,
jwtPayload.nbf,
jwtPayload.sub,
jwtPayload.exp,
jwtPayload.aud,
const credential = JWTCredential.fromJWT(
jwtPayload,
jwtString
);
)

await instance.storeCredential(credential);
});
Expand Down Expand Up @@ -724,19 +721,22 @@ describe("Pluto", () => {
proof: "proof",
};

const jwtPayload: any = {
id: "123",
const jwtPayload: Domain.JWTCredentialPayload = {
iss: "did:peer:2.issuer",
nbf: 1680615608435,
sub: "did:peer:2.sub",
exp: 1680615608435,
aud: ["aud-json"],
vc: vc,
vp: undefined,
type: CredentialType.JWT,
revoked: false,
jti: jwtString
};

const credentialIn = new JWTCredential(
jwtPayload.iss,
vc,
jwtPayload,
jwtString,
jwtPayload.nbf,
jwtPayload.sub,
Expand Down
55 changes: 32 additions & 23 deletions tests/pollux/Pollux.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,43 +856,53 @@ describe("Pollux", () => {

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

const presentationDefinition = await pollux.createPresentationDefinitionRequest(
const presentationDefinitionRequest = await pollux.createPresentationDefinitionRequest(
CredentialType.JWT,
[
{
requiredFields: ['name'],
trustIssuers: ["did:prism:12345"],
{
issuer: "did:prism:12345",
claims: {
name: {
type: 'string',
pattern: 'identus'
}
}
],
},
new PresentationOptions({
challenge: 'sign this'
})
);

expect(presentationDefinition).haveOwnProperty("id");
expect(presentationDefinition).haveOwnProperty("format");
expect(presentationDefinition).haveOwnProperty("inputDescriptors");
expect(presentationDefinition.format).haveOwnProperty("jwt");
expect(presentationDefinition.format.jwt?.alg).contains('ES256K');
expect(Array.isArray(presentationDefinition.inputDescriptors)).to.eq(true)
expect(presentationDefinition.inputDescriptors.length).to.eq(1)
expect(presentationDefinition.inputDescriptors.at(0)).haveOwnProperty('constraints');
expect(presentationDefinition.inputDescriptors.at(0)?.constraints.fields.length).to.eq(2);
expect(presentationDefinition.inputDescriptors.at(0)?.constraints.fields[0].path.at(0)).to.eq('$.vc.credentialSubject.name')
expect(presentationDefinition.inputDescriptors.at(0)?.constraints.fields[1].path.at(0)).to.eq('$.vc.issuer')
const { presentation_definition } = presentationDefinitionRequest;

expect(presentation_definition).haveOwnProperty("id");
expect(presentation_definition).haveOwnProperty("format");
expect(presentation_definition).haveOwnProperty("inputDescriptors");


expect(presentation_definition.format).haveOwnProperty("jwt");
expect(presentation_definition.format.jwt?.alg).contains('ES256K');
expect(Array.isArray(presentation_definition.inputDescriptors)).to.eq(true)
expect(presentation_definition.inputDescriptors.length).to.eq(1)
expect(presentation_definition.inputDescriptors.at(0)).haveOwnProperty('constraints');
expect(presentation_definition.inputDescriptors.at(0)?.constraints.fields.length).to.eq(2);
expect(presentation_definition.inputDescriptors.at(0)?.constraints.fields[0].path.at(0)).to.eq('$.vc.credentialSubject.name')
expect(presentation_definition.inputDescriptors.at(0)?.constraints.fields[1].path.at(0)).to.eq('$.vc.issuer')

})

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

const presentationDefinition = await pollux.createPresentationDefinitionRequest(
CredentialType.JWT,
[
{
requiredFields: ['name'],
trustIssuers: ["did:prism:12345"],
{
issuer: "did:prism:12345",
claims: {
name: {
type: 'string',
pattern: 'identus'
}
}
],
},
new PresentationOptions({
challenge: 'sign this'
})
Expand All @@ -908,7 +918,6 @@ describe("Pollux", () => {

const presentaationSubmissionJSON = await pollux.createPresentationSubmission(
presentationDefinition,
'sign this',
jwtCred,
privateKey
);
Expand Down

0 comments on commit 10730a1

Please sign in to comment.