Skip to content

Commit b99fc9c

Browse files
authored
Dcka 5252 wallet adjustment after the proof request fixed on the api (#442)
1 parent b6267f1 commit b99fc9c

4 files changed

Lines changed: 231 additions & 0 deletions

File tree

packages/wasm/src/services/pex/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ export const validation = {
77
assert(params.credentials, 'credentials is required');
88
assert(params.presentationDefinition, 'presentationDefinition is required');
99
},
10+
evaluateCredentials: (params: EvaluateCredentialsParams) => {
11+
assert(params.credentials, 'credentials is required');
12+
assert(params.presentationDefinition, 'presentationDefinition is required');
13+
},
1014
evaluatePresentation: (params: EvaluatePresentationParams) => {
1115
assert(params.presentation, 'presentation is required');
1216
assert(params.presentationDefinition, 'presentationDefinition is required');

packages/wasm/src/services/pex/service-rpc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ export class PEXServiceRPC extends RpcService {
2424
async presentationFrom(params: CreatePresentationParams) {
2525
return this.call('presentationFrom', params);
2626
}
27+
28+
async isCredentialSelectionValid(params: EvaluateCredentialsParams) {
29+
return this.call('isCredentialSelectionValid', params);
30+
}
2731
}

packages/wasm/src/services/pex/service.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class PEXService {
7878
PEXService.prototype.filterCredentials,
7979
PEXService.prototype.evaluatePresentation,
8080
PEXService.prototype.presentationFrom,
81+
PEXService.prototype.isCredentialSelectionValid,
8182
];
8283

8384
filterCredentials(params: FilterCredentialsParams) {
@@ -92,6 +93,18 @@ class PEXService {
9293
return result;
9394
}
9495

96+
isCredentialSelectionValid(params: EvaluateCredentialsParams) {
97+
validation.evaluateCredentials(params);
98+
const {credentials, presentationDefinition, holderDIDs} = params;
99+
const result = pex.selectFrom(
100+
removeOptionalAttribute(presentationDefinition),
101+
credentials,
102+
holderDIDs,
103+
);
104+
105+
return result.errors.length === 0;
106+
}
107+
95108
evaluatePresentation(params: EvaluatePresentationParams) {
96109
validation.evaluatePresentation(params);
97110
const {presentation, presentationDefinition} = params;

packages/wasm/src/services/pex/tests/pex-service.test.js

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,4 +647,214 @@ describe('Pex Examples', () => {
647647
expect(result).not.toBe(template); // Ensure immutability
648648
});
649649
});
650+
651+
describe('isCredentialSelectionValid', () => {
652+
const presentationDefinition = {
653+
id: 'b4a4bcf5-56a6-4e1c-810f-f2161c295b27',
654+
input_descriptors: [
655+
{
656+
id: 'Credential 1',
657+
name: 'api test',
658+
group: ['1'],
659+
purpose: 'blah blah',
660+
constraints: {
661+
fields: [
662+
{
663+
path: ['$.credentialSubject.id'],
664+
optional: true,
665+
},
666+
{
667+
path: ['$.expirationDate'],
668+
optional: true,
669+
},
670+
{
671+
path: ['$.credentialSchema.id'],
672+
filter: {
673+
const:
674+
'https://schema.truvera.io/BasicCredential-V2-1703777584571.json',
675+
},
676+
},
677+
],
678+
},
679+
},
680+
{
681+
id: 'Credential 2',
682+
name: 'api test',
683+
group: ['2'],
684+
purpose: 'blah blah',
685+
constraints: {
686+
fields: [
687+
{
688+
path: ['$.credentialSubject.id'],
689+
optional: true,
690+
},
691+
{
692+
path: ['$.expirationDate'],
693+
optional: true,
694+
},
695+
{
696+
path: ['$.credentialSchema.id'],
697+
filter: {
698+
const:
699+
'https://schema.truvera.io/UniversityDegree-V1-1703767509472.json',
700+
},
701+
},
702+
],
703+
},
704+
},
705+
],
706+
submission_requirements: [
707+
{
708+
from: '1',
709+
name: 'Multi Credential Request',
710+
rule: 'pick',
711+
count: 1,
712+
},
713+
{
714+
from: '2',
715+
name: 'Multi Credential Request',
716+
rule: 'pick',
717+
count: 1,
718+
},
719+
],
720+
};
721+
722+
const basicCredential1 = {
723+
'@context': [
724+
'https://www.w3.org/2018/credentials/v1',
725+
'https://ld.truvera.io/credentials/extensions-v1',
726+
{
727+
BasicCredential: 'dk:BasicCredential',
728+
dk: 'https://ld.truvera.io/credentials#',
729+
},
730+
'https://ld.truvera.io/credentials/prettyvc',
731+
],
732+
id: 'https://creds.truvera.io/29224c9c87c87c5edfcbace893d99d009513a0548e855bcb793ea30e1c5f8ce8',
733+
type: [
734+
'VerifiableCredential',
735+
'BasicCredential',
736+
'PrettyVerifiableCredential',
737+
],
738+
credentialSubject: {
739+
id: 'did:key:z6Mktpass177BSFLMuCpNJzCyrLeAUs16XUmg15VLHCQsnhk',
740+
name: 'Another Cred',
741+
},
742+
issuanceDate: '2025-11-25T13:44:36.365Z',
743+
issuer: 'did:cheqd:testnet:c0890f1c-c7bb-4ea6-be7a-8c31404743b7',
744+
credentialSchema: {
745+
id: 'https://schema.truvera.io/BasicCredential-V2-1703777584571.json',
746+
type: 'JsonSchemaValidator2018',
747+
},
748+
name: 'Another Cred',
749+
proof: {
750+
type: 'Ed25519Signature2018',
751+
created: '2025-11-25T13:45:06Z',
752+
verificationMethod:
753+
'did:cheqd:testnet:c0890f1c-c7bb-4ea6-be7a-8c31404743b7#keys-1',
754+
proofPurpose: 'assertionMethod',
755+
jws: 'eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..x1EjlAHJwJFwKfXtbAegJ8xOycY5m47yvvOQm-0sLzzuvSjbSKerIkphQ8w5J0_MJONb-j1-UE0NWZ9quM4CAQ',
756+
},
757+
};
758+
759+
const basicCredential2 = {
760+
'@context': [
761+
'https://www.w3.org/2018/credentials/v1',
762+
'https://ld.truvera.io/credentials/extensions-v1',
763+
{
764+
BasicCredential: 'dk:BasicCredential',
765+
dk: 'https://ld.truvera.io/credentials#',
766+
},
767+
'https://ld.truvera.io/credentials/prettyvc',
768+
],
769+
id: 'https://creds.truvera.io/86bdd6cc4d4915939bc2c11a0f8c7ebd64ef0872da02627ab9d7e6866fe2effb',
770+
type: [
771+
'VerifiableCredential',
772+
'BasicCredential',
773+
'PrettyVerifiableCredential',
774+
],
775+
credentialSubject: {
776+
name: 'test',
777+
},
778+
issuanceDate: '2025-11-25T13:42:02.877Z',
779+
issuer: 'did:cheqd:testnet:c0890f1c-c7bb-4ea6-be7a-8c31404743b7',
780+
credentialSchema: {
781+
id: 'https://schema.truvera.io/BasicCredential-V2-1703777584571.json',
782+
type: 'JsonSchemaValidator2018',
783+
},
784+
name: 'test',
785+
proof: {
786+
type: 'Ed25519Signature2018',
787+
created: '2025-11-25T13:42:42Z',
788+
verificationMethod:
789+
'did:cheqd:testnet:c0890f1c-c7bb-4ea6-be7a-8c31404743b7#keys-1',
790+
proofPurpose: 'assertionMethod',
791+
jws: 'eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..R-cJhQlBr3TJS6ArSIBwLjLcQO-yuPZ5FUY5zGe6TYIJNm0teHFvgFHjg_-Y9VeuhLZprVNufXyqLoPSkTC7CQ',
792+
},
793+
};
794+
795+
const universityDegreeCredential = {
796+
'@context': [
797+
'https://www.w3.org/2018/credentials/v1',
798+
'https://ld.truvera.io/credentials/extensions-v1',
799+
{
800+
UniversityDegree: 'dk:UniversityDegree',
801+
additionalDistinctions: 'dk:additionalDistinctions',
802+
awardedDate: 'dk:awardedDate',
803+
dateOfBirth: 'dk:dateOfBirth',
804+
degreeName: 'dk:degreeName',
805+
degreeType: 'dk:degreeType',
806+
dk: 'https://ld.truvera.io/credentials#',
807+
},
808+
'https://ld.truvera.io/credentials/prettyvc',
809+
],
810+
id: 'https://creds.truvera.io/4343d71719d56e2a3461f24a522229f2c89a3bef68ad2664e1f48d70002034c4',
811+
type: [
812+
'VerifiableCredential',
813+
'UniversityDegree',
814+
'PrettyVerifiableCredential',
815+
],
816+
credentialSubject: {
817+
id: 'did:key:z6Mktpass177BSFLMuCpNJzCyrLeAUs16XUmg15VLHCQsnhk',
818+
degreeName: 'testing',
819+
degreeType: 'testing',
820+
name: 'Tester',
821+
awardedDate: '2025-11-20',
822+
dateOfBirth: '2025-11-20',
823+
additionalDistinctions: 'test',
824+
},
825+
issuanceDate: '2025-11-25T13:45:25.699Z',
826+
issuer: 'did:cheqd:testnet:c0890f1c-c7bb-4ea6-be7a-8c31404743b7',
827+
credentialSchema: {
828+
id: 'https://schema.truvera.io/UniversityDegree-V1-1703767509472.json',
829+
type: 'JsonSchemaValidator2018',
830+
},
831+
name: 'University Degree',
832+
proof: {
833+
type: 'Ed25519Signature2018',
834+
created: '2025-11-25T13:46:09Z',
835+
verificationMethod:
836+
'did:cheqd:testnet:c0890f1c-c7bb-4ea6-be7a-8c31404743b7#keys-1',
837+
proofPurpose: 'assertionMethod',
838+
jws: 'eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..lb0SOlbNGZAEnGOqnaFg-fTSSOp-EWCMdMtKkjVasRkPjwAVSSK4VZmjis3Czdacbhl8VL0q3f6Ow4rge3eHDQ',
839+
},
840+
};
841+
842+
it('should return true if the credential selection is valid', () => {
843+
expect(
844+
pexService.isCredentialSelectionValid({
845+
credentials: [basicCredential1, universityDegreeCredential],
846+
presentationDefinition: presentationDefinition,
847+
}),
848+
).toBe(true);
849+
});
850+
851+
it('should return false if the credential selection is invalid', () => {
852+
expect(
853+
pexService.isCredentialSelectionValid({
854+
credentials: [basicCredential1, basicCredential2],
855+
presentationDefinition: presentationDefinition,
856+
}),
857+
).toBe(false);
858+
});
859+
});
650860
});

0 commit comments

Comments
 (0)