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

fix: pex query fix #1903

Merged
merged 5 commits into from
Jun 20, 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
5 changes: 5 additions & 0 deletions .changeset/fifty-bulldogs-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@credo-ts/core": patch
---

pex query fix
Original file line number Diff line number Diff line change
Expand Up @@ -584,21 +584,23 @@ export class DifPresentationExchangeService {

// FIXME: in the query we should take into account the supported proof types of the verifier
// this could help enormously in the amount of credentials we have to retrieve from storage.
// NOTE: for now we don't support SD-JWT for v1, as I don't know what the schema.uri should be?
if (presentationDefinitionVersion.version === PEVersion.v1) {
const pd = presentationDefinition as DifPresentationExchangeDefinitionV1

// The schema.uri can contain either an expanded type, or a context uri
for (const inputDescriptor of pd.input_descriptors) {
for (const schema of inputDescriptor.schema) {
sdJwtVcQuery.push({
vct: schema.uri,
})
w3cQuery.push({
$or: [{ expandedType: [schema.uri] }, { contexts: [schema.uri] }, { type: [schema.uri] }],
$or: [{ expandedTypes: [schema.uri] }, { contexts: [schema.uri] }, { types: [schema.uri] }],
})
}
}
} else if (presentationDefinitionVersion.version === PEVersion.v2) {
// FIXME: As PE version 2 does not have the `schema` anymore, we can't query by schema anymore.
// For now we retrieve ALL credentials, as we did the same for V1 with JWT credentials. We probably need
// We probably need
// to find some way to do initial filtering, hopefully if there's a filter on the `type` field or something.
} else {
throw new DifPresentationExchangeError(
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/storage/StorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import type { AgentContext } from '../agent'
import type { Constructor } from '../utils/mixins'

// https://stackoverflow.com/questions/51954558/how-can-i-remove-a-wider-type-from-a-union-type-without-removing-its-subtypes-in/51955852#51955852
export type SimpleQuery<T extends BaseRecord<any, any, any>> = Partial<ReturnType<T['getTags']>> & TagsBase
export type SimpleQuery<T extends BaseRecord<any, any, any>> = T extends BaseRecord<infer DefaultTags, infer CustomTags>
? DefaultTags extends TagsBase
? Partial<ReturnType<T['getTags']>> & TagsBase
: CustomTags extends TagsBase
? Partial<ReturnType<T['getTags']>> & TagsBase
: Partial<DefaultTags & CustomTags> & TagsBase
: Partial<ReturnType<T['getTags']>> & TagsBase

interface AdvancedQuery<T extends BaseRecord> {
interface AdvancedQuery<T extends BaseRecord<any, any, any>> {
$and?: Query<T>[]
$or?: Query<T>[]
$not?: Query<T>
Expand Down
Loading