-
Notifications
You must be signed in to change notification settings - Fork 200
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
feat: mdoc-support #2054
Merged
TimoGlastra
merged 18 commits into
openwallet-foundation:main
from
auer-martin:mdoc-new
Oct 24, 2024
Merged
feat: mdoc-support #2054
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8c14678
feat: mdoc alpha
auer-martin 1be0fbf
feat: fix: some nits
auer-martin 2fcde60
docs(changeset): feat: mdoc-support
auer-martin 8728d37
Merge branch 'main' of github.com:openwallet-foundation/credo-ts into…
auer-martin 95eb0db
fix: some nits
auer-martin 6282482
fix(x509): correctly parse uncompressed P256 keys
berendsliedrecht 0dd4621
Merge branch 'main' of github.com:openwallet-foundation/credo-ts into…
auer-martin 7ccf8e6
fix: some more nits
auer-martin 10b7c2b
Merge branch 'mdoc-new' of github.com:auer-martin/aries-framework-jav…
auer-martin c3e186c
chore(x509): remove key prefix for buggy compression algo
berendsliedrecht fce2553
Merge branch 'mdoc-new' of github.com:auer-martin/aries-framework-jav…
auer-martin 2fffb5f
fix: incorporate some feedback
auer-martin 911a504
fix: nits
auer-martin 4daffbc
fix: update lockfile
auer-martin 65acce7
fix: remove unused import
auer-martin f08fa37
refactor: update HolderInquirer to use issuerSignedNamespaces
auer-martin f9961e0
fix: tests
auer-martin 2738270
fix: feedback
auer-martin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@credo-ts/core': patch | ||
--- | ||
|
||
feat: mdoc-support |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,15 @@ import type { | |
W3CVerifiablePresentation, | ||
} from '@sphereon/ssi-types' | ||
|
||
import { PEVersion, PEX, Status } from '@sphereon/pex' | ||
import { PEVersion, PEX, PresentationSubmissionLocation, Status } from '@sphereon/pex' | ||
import { injectable } from 'tsyringe' | ||
|
||
import { Hasher, getJwkFromKey } from '../../crypto' | ||
import { CredoError } from '../../error' | ||
import { JsonTransformer } from '../../utils' | ||
import { DidsApi, getKeyFromVerificationMethod } from '../dids' | ||
import { Mdoc, MdocApi, MdocOpenId4VpSessionTranscriptOptions, MdocRecord } from '../mdoc' | ||
import { MdocDeviceResponse } from '../mdoc/MdocDeviceResponse' | ||
import { SdJwtVcApi } from '../sd-jwt-vc' | ||
import { | ||
ClaimFormat, | ||
|
@@ -151,9 +153,10 @@ export class DifPresentationExchangeService { | |
presentationSubmissionLocation?: DifPresentationExchangeSubmissionLocation | ||
challenge: string | ||
domain?: string | ||
openid4vp?: MdocOpenId4VpSessionTranscriptOptions | ||
} | ||
) { | ||
const { presentationDefinition, domain, challenge } = options | ||
const { presentationDefinition, domain, challenge, openid4vp } = options | ||
const presentationSubmissionLocation = | ||
options.presentationSubmissionLocation ?? DifPresentationExchangeSubmissionLocation.PRESENTATION | ||
|
||
|
@@ -172,11 +175,6 @@ export class DifPresentationExchangeService { | |
presentationDefinition as DifPresentationExchangeDefinitionV1 | ||
).input_descriptors.filter((inputDescriptor) => inputDescriptorIds.includes(inputDescriptor.id)) | ||
|
||
// Get all the credentials for the presentation | ||
const credentialsForPresentation = presentationToCreate.verifiableCredentials.map((c) => | ||
getSphereonOriginalVerifiableCredential(c.credential) | ||
) | ||
|
||
const presentationDefinitionForSubject: DifPresentationExchangeDefinition = { | ||
...presentationDefinition, | ||
input_descriptors: inputDescriptorsForPresentation, | ||
|
@@ -185,6 +183,42 @@ export class DifPresentationExchangeService { | |
submission_requirements: undefined, | ||
} | ||
|
||
if (presentationToCreate.claimFormat === ClaimFormat.MsoMdoc) { | ||
if (presentationToCreate.verifiableCredentials.length !== 1) { | ||
throw new DifPresentationExchangeError( | ||
'Currently a Mdoc presentation can only be created from a single credential' | ||
) | ||
} | ||
const mdocRecord = presentationToCreate.verifiableCredentials[0].credential | ||
if (!openid4vp) { | ||
throw new DifPresentationExchangeError('Missing openid4vp options for creating MDOC presentation.') | ||
} | ||
|
||
const { deviceResponseBase64Url, presentationSubmission } = await MdocDeviceResponse.openId4Vp(agentContext, { | ||
mdocs: [Mdoc.fromBase64Url(mdocRecord.base64Url)], | ||
presentationDefinition: presentationDefinition as DifPresentationExchangeDefinitionV2, | ||
sessionTranscriptOptions: { | ||
...openid4vp, | ||
}, | ||
}) | ||
|
||
verifiablePresentationResultsWithFormat.push({ | ||
verifiablePresentationResult: { | ||
presentationSubmission: presentationSubmission, | ||
verifiablePresentation: deviceResponseBase64Url, | ||
presentationSubmissionLocation: PresentationSubmissionLocation.EXTERNAL, | ||
}, | ||
claimFormat: presentationToCreate.claimFormat, | ||
}) | ||
|
||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think instead of |
||
} | ||
|
||
// Get all the credentials for the presentation | ||
const credentialsForPresentation = presentationToCreate.verifiableCredentials.map((c) => | ||
getSphereonOriginalVerifiableCredential(c.credential) | ||
) | ||
|
||
const verifiablePresentationResult = await this.pex.verifiablePresentationFrom( | ||
presentationDefinitionForSubject, | ||
credentialsForPresentation, | ||
|
@@ -564,10 +598,12 @@ export class DifPresentationExchangeService { | |
private async queryCredentialForPresentationDefinition( | ||
agentContext: AgentContext, | ||
presentationDefinition: DifPresentationExchangeDefinition | ||
): Promise<Array<SdJwtVcRecord | W3cCredentialRecord>> { | ||
): Promise<Array<SdJwtVcRecord | W3cCredentialRecord | MdocRecord>> { | ||
const w3cCredentialRepository = agentContext.dependencyManager.resolve(W3cCredentialRepository) | ||
const w3cQuery: Array<Query<W3cCredentialRecord>> = [] | ||
const sdJwtVcQuery: Array<Query<SdJwtVcRecord>> = [] | ||
const mdocQuery: Array<Query<MdocRecord>> = [] | ||
|
||
const presentationDefinitionVersion = PEX.definitionVersionDiscovery(presentationDefinition) | ||
|
||
if (!presentationDefinitionVersion.version) { | ||
|
@@ -591,6 +627,9 @@ export class DifPresentationExchangeService { | |
w3cQuery.push({ | ||
$or: [{ expandedTypes: [schema.uri] }, { contexts: [schema.uri] }, { types: [schema.uri] }], | ||
}) | ||
mdocQuery.push({ | ||
docType: inputDescriptor.id, | ||
}) | ||
} | ||
} | ||
} else if (presentationDefinitionVersion.version === PEVersion.v2) { | ||
|
@@ -603,33 +642,33 @@ export class DifPresentationExchangeService { | |
) | ||
} | ||
|
||
const allRecords: Array<SdJwtVcRecord | W3cCredentialRecord> = [] | ||
const allRecords: Array<SdJwtVcRecord | W3cCredentialRecord | MdocRecord> = [] | ||
|
||
// query the wallet ourselves first to avoid the need to query the pex library for all | ||
// credentials for every proof request | ||
const w3cCredentialRecords = | ||
w3cQuery.length > 0 | ||
? await w3cCredentialRepository.findByQuery(agentContext, { | ||
$or: w3cQuery, | ||
}) | ||
? await w3cCredentialRepository.findByQuery(agentContext, { $or: w3cQuery }) | ||
: await w3cCredentialRepository.getAll(agentContext) | ||
|
||
allRecords.push(...w3cCredentialRecords) | ||
|
||
const sdJwtVcApi = this.getSdJwtVcApi(agentContext) | ||
const sdJwtVcRecords = | ||
sdJwtVcQuery.length > 0 | ||
? await sdJwtVcApi.findAllByQuery({ | ||
$or: sdJwtVcQuery, | ||
}) | ||
: await sdJwtVcApi.getAll() | ||
|
||
sdJwtVcQuery.length > 0 ? await sdJwtVcApi.findAllByQuery({ $or: sdJwtVcQuery }) : await sdJwtVcApi.getAll() | ||
allRecords.push(...sdJwtVcRecords) | ||
|
||
const mdocApi = this.getMdocApi(agentContext) | ||
const mdocRecords = mdocQuery.length > 0 ? await mdocApi.findAllByQuery({ $or: mdocQuery }) : await mdocApi.getAll() | ||
allRecords.push(...mdocRecords) | ||
|
||
return allRecords | ||
} | ||
|
||
private getSdJwtVcApi(agentContext: AgentContext) { | ||
return agentContext.dependencyManager.resolve(SdJwtVcApi) | ||
} | ||
|
||
private getMdocApi(agentContext: AgentContext) { | ||
return agentContext.dependencyManager.resolve(MdocApi) | ||
} | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if v1 is used?