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

refactor: cleanup credential exchange code #602

Merged
merged 1 commit into from
Jul 19, 2022
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
1 change: 1 addition & 0 deletions docs/api/classes/modules_claims.ClaimsService.md
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ ___
Verifies:
- That credential proof is valid
- That credential was issued by authorized issuer
- That credential was not revoked

#### Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
PEX,
SelectResults,
} from '@sphereon/pex';
import { InputDescriptorV1, InputDescriptorV2 } from '@sphereon/pex-models';
import { v4 as uuid } from 'uuid';
import axios from 'axios';
import {
Expand Down Expand Up @@ -37,6 +38,7 @@ import {
import { ERROR_MESSAGES } from '../../errors';
import { CacheClient } from '../cache-client';
import { KEY_TYPE } from './verifiable-credentials.const';
import { Claim } from '../claims/claims.types';

/**
* Service responsible for managing verifiable credentials and presentations.
Expand Down Expand Up @@ -517,25 +519,18 @@ export abstract class VerifiableCredentialsServiceBase {
isAccepted: true,
}
);

const claimWithVp = (
claim: Claim
): claim is Claim & { vp: VerifiablePresentation } => !!claim.vp;

const vc = claims
.filter((claim) => claim.vp)
.flatMap((claim) => claim.vp!.verifiableCredential);
.filter(claimWithVp)
.flatMap((claim) => claim.vp.verifiableCredential);

const pex = new PEX();
return pex.selectFrom(presentationDefinition, vc);
}
/*
* We have observed that pex may have bugs when dealing with subject_is_issuer credentials
* and when handling a presentation definition with more than one input descriptor.
* This could be related to these issues:
* - https://github.com/Sphereon-Opensource/pex/issues/96
* - https://github.com/Sphereon-Opensource/pex/issues/91
* We are therefore trying to simplify the input to pex so remove the possibility of it generating incorrect results.
* Once the above issues are fixed, pex can be updated and perhaps this filtering will not needed.
*/
private filterSelfSignDescriptors(descriptors) {
return descriptors?.filter((desc) => !desc?.constraints?.subject_is_issuer);
}

/**
* Create a credential with given parameters.
Expand Down Expand Up @@ -702,4 +697,22 @@ export abstract class VerifiableCredentialsServiceBase {
return null;
}
}

/**
* We have observed that pex may have bugs when dealing with subject_is_issuer credentials
* and when handling a presentation definition with more than one input descriptor.
* This could be related to these issues:
* - https://github.com/Sphereon-Opensource/pex/issues/96
* - https://github.com/Sphereon-Opensource/pex/issues/91
* We are therefore trying to simplify the input to pex so remove the possibility of it generating incorrect results.
* Once the above issues are fixed, pex can be updated and perhaps this filtering will not needed.
*
* @param {InputDescriptorV1 | InputDescriptorV2} descriptors input descriptors
* @returns filtered input descriptors
*/
private filterSelfSignDescriptors(
jrhender marked this conversation as resolved.
Show resolved Hide resolved
descriptors: Array<InputDescriptorV1 | InputDescriptorV2>
): Array<InputDescriptorV1 | InputDescriptorV2> {
return descriptors?.filter((desc) => !desc?.constraints?.subject_is_issuer);
}
}