-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Timo Glastra <[email protected]>
- Loading branch information
1 parent
35c2c96
commit 28a63dc
Showing
32 changed files
with
1,524 additions
and
2,631 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/core/src/modules/dif-presentation-exchange/utils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './transform' | ||
export * from './credentialSelection' | ||
export * from './presentationsToCreate' | ||
export * from './presentationSelection' |
93 changes: 93 additions & 0 deletions
93
packages/core/src/modules/dif-presentation-exchange/utils/presentationSelection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import type { SingleOrArray } from '../../../utils' | ||
import type { W3cJsonLdVerifiableCredential, W3cJwtVerifiableCredential } from '../../vc' | ||
import type { | ||
DifPresentationExchangeDefinition, | ||
DifPresentationExchangeSubmission, | ||
VerifiablePresentation, | ||
} from '../models' | ||
|
||
import { default as jp } from 'jsonpath' | ||
|
||
import { CredoError } from '../../../error' | ||
import { MdocDeviceResponse } from '../../mdoc' | ||
import { ClaimFormat, W3cJsonLdVerifiablePresentation, W3cJwtVerifiablePresentation } from '../../vc' | ||
|
||
export type DifPexPresentationWithDescriptor = ReturnType< | ||
typeof extractPresentationsWithDescriptorsFromSubmission | ||
>[number] | ||
export function extractPresentationsWithDescriptorsFromSubmission( | ||
presentations: SingleOrArray<VerifiablePresentation>, | ||
submission: DifPresentationExchangeSubmission, | ||
definition: DifPresentationExchangeDefinition | ||
) { | ||
return submission.descriptor_map.map((descriptor) => { | ||
const [presentation] = jp.query(presentations, descriptor.path) as [VerifiablePresentation | undefined] | ||
const inputDescriptor = definition.input_descriptors.find(({ id }) => id === descriptor.id) | ||
|
||
if (!presentation) { | ||
throw new CredoError( | ||
`Unable to extract presentation at path '${descriptor.path}' for submission descriptor '${descriptor.id}'` | ||
) | ||
} | ||
|
||
if (!inputDescriptor) { | ||
throw new Error( | ||
`Unable to extract input descriptor '${descriptor.id}' from definition '${definition.id}' for submission '${submission.id}'` | ||
) | ||
} | ||
|
||
if (presentation instanceof MdocDeviceResponse) { | ||
const document = presentation.documents.find((document) => document.docType === descriptor.id) | ||
if (!document) { | ||
throw new Error( | ||
`Unable to extract mdoc document with doctype '${descriptor.id}' from mdoc device response for submission '${submission.id}'.` | ||
) | ||
} | ||
|
||
return { | ||
format: ClaimFormat.MsoMdoc, | ||
descriptor, | ||
presentation, | ||
credential: document, | ||
inputDescriptor, | ||
} as const | ||
} else if ( | ||
presentation instanceof W3cJwtVerifiablePresentation || | ||
presentation instanceof W3cJsonLdVerifiablePresentation | ||
) { | ||
if (!descriptor.path_nested) { | ||
throw new Error( | ||
`Submission descriptor '${descriptor.id}' for submission '${submission.id}' has no 'path_nested' but presentation is format '${presentation.claimFormat}'` | ||
) | ||
} | ||
|
||
const [verifiableCredential] = jp.query( | ||
// Path is `$.vp.verifiableCredential[]` in case of jwt vp | ||
presentation.claimFormat === ClaimFormat.JwtVp ? { vp: presentation } : presentation, | ||
descriptor.path_nested.path | ||
) as [W3cJwtVerifiableCredential | W3cJsonLdVerifiableCredential | undefined] | ||
|
||
if (!verifiableCredential) { | ||
throw new CredoError( | ||
`Unable to extract credential at path '${descriptor.path_nested.path}' from presentation at path '${descriptor.path}' for submission descriptor '${descriptor.id}'` | ||
) | ||
} | ||
|
||
return { | ||
format: presentation.claimFormat, | ||
descriptor, | ||
presentation, | ||
credential: verifiableCredential, | ||
inputDescriptor, | ||
} as const | ||
} else { | ||
return { | ||
format: ClaimFormat.SdJwtVc, | ||
descriptor, | ||
presentation, | ||
credential: presentation, | ||
inputDescriptor, | ||
} as const | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.