Skip to content

fix: pex query fix #1903

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

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { decodeSdJwtSync } from '@sd-jwt/decode'

import { BaseRecord } from '../../../storage/BaseRecord'
import { Query, SimpleQuery } from '../../../storage/StorageService'

Check warning on line 8 in packages/core/src/modules/sd-jwt-vc/repository/SdJwtVcRecord.ts

View workflow job for this annotation

GitHub Actions / Validate

'Query' is defined but never used

Check warning on line 8 in packages/core/src/modules/sd-jwt-vc/repository/SdJwtVcRecord.ts

View workflow job for this annotation

GitHub Actions / Validate

'SimpleQuery' is defined but never used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be unused

import { Hasher, JsonTransformer } from '../../../utils'
import { uuid } from '../../../utils/uuid'

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