From 21ff6c40dc06079ada38b2d3f98cba6102decc73 Mon Sep 17 00:00:00 2001 From: Zoe Maas Date: Mon, 2 Dec 2024 18:06:24 +0100 Subject: [PATCH] chore: Added enum and const tests with old and new format --- test/SdJwt.spec.ts | 160 +++++++++++++++++++++++++++++ test/resources/pd_enum_values.json | 55 ++++++++++ 2 files changed, 215 insertions(+) create mode 100644 test/resources/pd_enum_values.json diff --git a/test/SdJwt.spec.ts b/test/SdJwt.spec.ts index 68fc268..4921b35 100644 --- a/test/SdJwt.spec.ts +++ b/test/SdJwt.spec.ts @@ -82,6 +82,16 @@ const decodedSdJwtVc = { ], } satisfies SdJwtDecodedVerifiableCredential; +const decodedSdJwtVcNewPid = { + compactSdJwtVc: + 'eyJ0eXAiOiJ2YytzZC1qd3QiLCJraWQiOiJkaWQ6andrOmV5SmhiR2NpT2lKRlV6STFOaUlzSW5WelpTSTZJbk5wWnlJc0ltdDBlU0k2SWtWRElpd2lZM0oySWpvaVVDMHlOVFlpTENKNElqb2lVemR3V0d0S1RVaGpWR0l5ZG5CU2RIZzVhVzFFZURCNFUzSm5WSGRMWDFGWU1qUldOMGRUV1U5Tk1DSXNJbmtpT2lKM1VYWjJiM054YW1Ga1ltOTVhbWhzWDFCb1JtTnlkRGQzWlVsSU5EaDZaVTl2VFcxcWJpMHljbEJqSW4wIzAiLCJhbGciOiJFUzI1NiJ9.eyJzdWIiOiJkaWQ6andrOmV5SmhiR2NpT2lKRlV6STFOaUlzSW5WelpTSTZJbk5wWnlJc0ltdDBlU0k2SWtWRElpd2lZM0oySWpvaVVDMHlOVFlpTENKNElqb2ljVU50Y0dsNWFtOVlVblkxUm1WalgwRnhPR0Z5VUU5bVRrdEZSSFl5U0ZkSFUyRm1UVGR5TkVGSGJ5SXNJbmtpT2lKc1ZscERZVGhTZHpscFkyRnVhVTlYU2tVeWVHTmFVM1J1WVhKdVZYSklhek5qVmxwUFpubFFiVlE0SW4wIzAiLCJpc3MiOiJkaWQ6andrOmV5SmhiR2NpT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mFtZSIsIkRvZSJd~WyJmZDViMTFmNC04ZDllLTQzYmYtYTVkMC04ODE5YTJjYjg2MzEiLCJlbWFpbCIsImpvaG5kZW9AZXhhbXBsZS5jb20iXQ~WyJkY2IwNTJjYS02ZDFiLTQ3NDktODNmYi1lNjkxYzIyZTY2ZjAiLCJwaG9uZSIsIisxLTIwMi01NTUtMDEwMSJd~WyI1MDdjM2MyNi0yZjQxLTQwNWEtOTZkMS1lNTI1ZWM2Y2VjNTQiLCJhZGRyZXNzIix7InN0cmVldF9hZGRyZXNzIjoiMTIzIE1haW4gU3QiLCJsb2NhbGl0eSI6IkFueXRvd24iLCJyZWdpb24iOiJBbnlzdGF0ZSIsImNvdW50cnkiOiJVUyJ9XQ~WyIwNzBlZjYyNy05NTAyLTRkMTYtYTNjYi1lNTAwZTViOTk0YWIiLCJiaXJ0aGRhdGUiLCIxOTQwLTAxLTAxIl0~', +}; + // This is the expected output SD-JWT based on the presentation definition defined below const decodedSdJwtVcWithDisclosuresRemoved = { // 3 disclosures not included @@ -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 @@ -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'); + }); }); diff --git a/test/resources/pd_enum_values.json b/test/resources/pd_enum_values.json new file mode 100644 index 0000000..87c3066 --- /dev/null +++ b/test/resources/pd_enum_values.json @@ -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 + ] + } + } + ] + } + } + ] + } +}