Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/SPHEREON-1182 #189

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions test/SdJwt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ const decodedSdJwtVc = {
],
} satisfies SdJwtDecodedVerifiableCredential;

const decodedSdJwtVcNewPid = {
compactSdJwtVc:
'eyJ0eXAiOiJ2YytzZC1qd3QiLCJraWQiOiJkaWQ6andrOmV5SmhiR2NpT2lKRlV6STFOaUlzSW5WelpTSTZJbk5wWnlJc0ltdDBlU0k2SWtWRElpd2lZM0oySWpvaVVDMHlOVFlpTENKNElqb2lVemR3V0d0S1RVaGpWR0l5ZG5CU2RIZzVhVzFFZURCNFUzSm5WSGRMWDFGWU1qUldOMGRUV1U5Tk1DSXNJbmtpT2lKM1VYWjJiM054YW1Ga1ltOTVhbWhzWDFCb1JtTnlkRGQzWlVsSU5EaDZaVTl2VFcxcWJpMHljbEJqSW4wIzAiLCJhbGciOiJFUzI1NiJ9.eyJzdWIiOiJkaWQ6andrOmV5SmhiR2NpT2lKRlV6STFOaUlzSW5WelpTSTZJbk5wWnlJc0ltdDBlU0k2SWtWRElpd2lZM0oySWpvaVVDMHlOVFlpTENKNElqb2ljVU50Y0dsNWFtOVlVblkxUm1WalgwRnhPR0Z5VUU5bVRrdEZSSFl5U0ZkSFUyRm1UVGR5TkVGSGJ5SXNJbmtpT2lKc1ZscERZVGhTZHpscFkyRnVhVTlYU2tVeWVHTmFVM1J1WVhKdVZYSklhek5qVmxwUFpubFFiVlE0SW4wIzAiLCJpc3MiOiJkaWQ6andrO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YW1pbHlfbmFtZSIsIkRvZSJd~WyJmZDViMTFmNC04ZDllLTQzYmYtYTVkMC04ODE5YTJjYjg2MzEiLCJlbWFpbCIsImpvaG5kZW9AZXhhbXBsZS5jb20iXQ~WyJkY2IwNTJjYS02ZDFiLTQ3NDktODNmYi1lNjkxYzIyZTY2ZjAiLCJwaG9uZSIsIisxLTIwMi01NTUtMDEwMSJd~WyI1MDdjM2MyNi0yZjQxLTQwNWEtOTZkMS1lNTI1ZWM2Y2VjNTQiLCJhZGRyZXNzIix7InN0cmVldF9hZGRyZXNzIjoiMTIzIE1haW4gU3QiLCJsb2NhbGl0eSI6IkFueXRvd24iLCJyZWdpb24iOiJBbnlzdGF0ZSIsImNvdW50cnkiOiJVUyJ9XQ~WyIwNzBlZjYyNy05NTAyLTRkMTYtYTNjYi1lNTAwZTViOTk0YWIiLCJiaXJ0aGRhdGUiLCIxOTQwLTAxLTAxIl0~',
};

// This is the expected output SD-JWT based on the presentation definition defined below
const decodedSdJwtVcWithDisclosuresRemoved = {
// 3 disclosures not included
Expand Down Expand Up @@ -159,6 +169,96 @@ function getPresentationDefinitionV2(): PresentationDefinitionV2 {
};
}

function getPresentationDefinitionV2_with_enum(): PresentationDefinitionV2 {
return {
id: '32f54163-7166-48f1-93d8-ff217bdb0653',
name: 'Conference Entry Requirements',
purpose: 'We can only allow people associated with Washington State business representatives into conference areas',
format: {
'vc+sd-jwt': {},
},
input_descriptors: [
{
id: 'wa_driver_license',
name: 'Washington State Business License',
purpose: 'We can only allow licensed Washington State business representatives into the WA Business Conference',
constraints: {
limit_disclosure: 'required',
fields: [
{
path: ['$.vct'],
filter: {
type: 'string',
enum: ['https://example.bmi.bund.de/credential/pid/1.0', 'urn:eu.europa.ec.eudi:pid:1'],
},
},
],
},
},
],
};
}

function getPresentationDefinitionV2_const_new_pid(): PresentationDefinitionV2 {
return {
id: '32f54163-7166-48f1-93d8-ff217bdb0653',
name: 'Conference Entry Requirements',
purpose: 'We can only allow people associated with Washington State business representatives into conference areas',
format: {
'vc+sd-jwt': {},
},
input_descriptors: [
{
id: 'wa_driver_license',
name: 'Washington State Business License',
purpose: 'We can only allow licensed Washington State business representatives into the WA Business Conference',
constraints: {
limit_disclosure: 'required',
fields: [
{
path: ['$.vct'],
filter: {
type: 'string',
const: 'https://example.bmi.bund.de/credential/pid/1.0',
},
},
],
},
},
],
};
}

function getPresentationDefinitionV2_const_old_pid(): PresentationDefinitionV2 {
return {
id: '32f54163-7166-48f1-93d8-ff217bdb0653',
name: 'Conference Entry Requirements',
purpose: 'We can only allow people associated with Washington State business representatives into conference areas',
format: {
'vc+sd-jwt': {},
},
input_descriptors: [
{
id: 'wa_driver_license',
name: 'Washington State Business License',
purpose: 'We can only allow licensed Washington State business representatives into the WA Business Conference',
constraints: {
limit_disclosure: 'required',
fields: [
{
path: ['$.vct'],
filter: {
type: 'string',
const: 'urn:eu.europa.ec.eudi:pid:1',
},
},
],
},
},
],
};
}

// TODO:
// - evaluateSubmission / submissionFrom
// - correctly set up KB-JWT payload and sign this in the presentation callback
Expand Down Expand Up @@ -309,4 +409,64 @@ describe('evaluate', () => {
value: presentationResult.presentationSubmission,
});
});

it('selectFrom with vc+sd-jwt format compact - enum new PID format', async () => {
const result = pex.selectFrom(getPresentationDefinitionV2_with_enum(), [decodedSdJwtVcNewPid.compactSdJwtVc]);
expect(result.errors?.length).toEqual(0);
expect(result.matches).toEqual([
{
name: 'Washington State Business License',
rule: 'all',
vc_path: ['$.verifiableCredential[0]'],
type: SubmissionRequirementMatchType.InputDescriptor,
id: 'wa_driver_license',
},
]);
expect(result.areRequiredCredentialsPresent).toBe('info');
});

it('selectFrom with vc+sd-jwt format compact - enum old PID format', async () => {
const result = pex.selectFrom(getPresentationDefinitionV2_with_enum(), [decodedSdJwtVcOldPid.compactSdJwtVc]);
expect(result.errors?.length).toEqual(0);
expect(result.matches).toEqual([
{
name: 'Washington State Business License',
rule: 'all',
vc_path: ['$.verifiableCredential[0]'],
type: SubmissionRequirementMatchType.InputDescriptor,
id: 'wa_driver_license',
},
]);
expect(result.areRequiredCredentialsPresent).toBe('info');
});

it('selectFrom with vc+sd-jwt format compact - const new PID format', async () => {
const result = pex.selectFrom(getPresentationDefinitionV2_const_new_pid(), [decodedSdJwtVcNewPid.compactSdJwtVc]);
expect(result.errors?.length).toEqual(0);
expect(result.matches).toEqual([
{
name: 'Washington State Business License',
rule: 'all',
vc_path: ['$.verifiableCredential[0]'],
type: SubmissionRequirementMatchType.InputDescriptor,
id: 'wa_driver_license',
},
]);
expect(result.areRequiredCredentialsPresent).toBe('info');
});

it('selectFrom with vc+sd-jwt format compact - const old PID format', async () => {
const result = pex.selectFrom(getPresentationDefinitionV2_const_old_pid(), [decodedSdJwtVcOldPid.compactSdJwtVc]);
expect(result.errors?.length).toEqual(0);
expect(result.matches).toEqual([
{
name: 'Washington State Business License',
rule: 'all',
vc_path: ['$.verifiableCredential[0]'],
type: SubmissionRequirementMatchType.InputDescriptor,
id: 'wa_driver_license',
},
]);
expect(result.areRequiredCredentialsPresent).toBe('info');
});
});
55 changes: 55 additions & 0 deletions test/resources/pd_enum_values.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"presentation_definition": {
"id": "56e001a9-c41f-49c5-9b12-440ad4861f58",
"name": "DIIP v3 compliance",
"purpose": "Prove you're compliant with DIIP v3",
"input_descriptors": [
{
"id": "b2a1f1d3-37ee-4494-98e2-ef9853b28197",
"name": "DIIP v3 compliance",
"purpose": "Prove you're compliant with DIIP v3",
"format": {
"vc+sd-jwt": {}
},
"constraints": {
"limit_disclosure": "preferred",
"fields": [
{
"path": ["$.compliant"],
"name": "compliant",
"filter": {
"type": "boolean",
"enum": [
true,
false
]
}
},
{
"path": ["$.name"],
"name": "name",
"filter": {
"type": "string",
"enum": [
"https://example.bmi.bund.de/credential/pid/1.0",
"urn:eu.europa.ec.eudi:pid:1"
]
}
},
{
"path": ["$.age"],
"name": "age",
"filter": {
"type": "number",
"enum": [
12,
135
]
}
}
]
}
}
]
}
}
Loading