Skip to content

Commit

Permalink
fix(present-proof): resolved feedback but proof is not included
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
berendsliedrecht committed Jan 3, 2024
1 parent 985b19b commit f3e1534
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 98 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/agent/AgentModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DiscoverFeaturesModule } from '../modules/discover-features'
import { GenericRecordsModule } from '../modules/generic-records'
import { MessagePickupModule } from '../modules/message-pickup'
import { OutOfBandModule } from '../modules/oob'
import { PresentationExchangeModule } from '../modules/presentation-exchange'
import { ProofsModule } from '../modules/proofs'
import { MediationRecipientModule, MediatorModule } from '../modules/routing'
import { W3cCredentialsModule } from '../modules/vc'
Expand Down Expand Up @@ -131,6 +132,7 @@ function getDefaultAgentModules() {
oob: () => new OutOfBandModule(),
w3cCredentials: () => new W3cCredentialsModule(),
cache: () => new CacheModule(),
pex: () => new PresentationExchangeModule(),
} as const
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import { AriesFrameworkError } from '../../error'

export class PresentationExchangeError extends AriesFrameworkError {}
export class PresentationExchangeError extends AriesFrameworkError {
public additionalMessages?: Array<string>

public constructor(
message: string,
{ cause, additionalMessages }: { cause?: Error; additionalMessages?: Array<string> } = {}
) {
super(message, { cause })
this.additionalMessages = additionalMessages
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class PresentationExchangeModule implements Module {
"The 'PresentationExchangeModule' module is experimental and could have unexpected breaking changes. When using this module, make sure to use strict versions for all @aries-framework packages."
)

// service
dependencyManager.registerSingleton(PresentationExchangeService)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
} from '@sphereon/pex'
import type {
InputDescriptorV2,
PresentationSubmission as PexPresentationSubmission,
PresentationSubmission as PePresentationSubmission,
PresentationDefinitionV1,
} from '@sphereon/pex-models'
import type { IVerifiablePresentation, OriginalVerifiableCredential } from '@sphereon/ssi-types'
Expand Down Expand Up @@ -40,8 +40,8 @@ import {

export type ProofStructure = Record<string, Record<string, Array<W3cVerifiableCredential>>>
export type PresentationDefinition = IPresentationDefinition & Record<string, unknown>

export type VerifiablePresentation = IVerifiablePresentation & Record<string, unknown>
export type PexPresentationSubmission = PePresentationSubmission & Record<string, unknown>

@injectable()
export class PresentationExchangeService {
Expand All @@ -64,19 +64,15 @@ export class PresentationExchangeService {
const validation = PEX.validateDefinition(presentationDefinition)
const errorMessages = this.formatValidated(validation)
if (errorMessages.length > 0) {
throw new PresentationExchangeError(
`Invalid presentation definition. The following errors were found: ${errorMessages.join(', ')}`
)
throw new PresentationExchangeError(`Invalid presentation definition`, { additionalMessages: errorMessages })
}
}

public validatePresentationSubmission(presentationSubmission: PexPresentationSubmission) {
const validation = PEX.validateSubmission(presentationSubmission)
const errorMessages = this.formatValidated(validation)
if (errorMessages.length > 0) {
throw new PresentationExchangeError(
`Invalid presentation submission. The following errors were found: ${errorMessages.join(', ')}`
)
throw new PresentationExchangeError(`Invalid presentation submission`, { additionalMessages: errorMessages })
}
}

Expand All @@ -86,22 +82,17 @@ export class PresentationExchangeService {
if (errors) {
const errorMessages = this.formatValidated(errors as Validated)
if (errorMessages.length > 0) {
throw new PresentationExchangeError(
`Invalid presentation. The following errors were found: ${errorMessages.join(', ')}`
)
throw new PresentationExchangeError(`Invalid presentation`, { additionalMessages: errorMessages })
}
}
}

private formatValidated(v: Validated) {
return Array.isArray(v)
? (v
.filter((r) => r.tag === Status.ERROR)
.map((r) => r.message)
.filter((m) => Boolean(m)) as Array<string>)
: v.tag === Status.ERROR && typeof v.message === 'string'
? [v.message]
: []
const validated = Array.isArray(v) ? v : [v]
return validated
.filter((r) => r.tag === Status.ERROR)
.map((r) => r.message)
.filter((r): r is string => Boolean(r))
}

/**
Expand All @@ -118,9 +109,9 @@ export class PresentationExchangeService {

if (!presentationDefinitionVersion.version) {
throw new PresentationExchangeError(
`Unable to determine the Presentation Exchange version from the presentation definition. ${
presentationDefinitionVersion.error ?? 'Unknown error'
}`
`Unable to determine the Presentation Exchange version from the presentation definition
`,
presentationDefinitionVersion.error ? { additionalMessages: [presentationDefinitionVersion.error] } : {}
)
}

Expand Down Expand Up @@ -284,11 +275,11 @@ export class PresentationExchangeService {
}

if (!verifiablePresentationResultsWithFormat[0]) {
throw new PresentationExchangeError('No verifiable presentations created.')
throw new PresentationExchangeError('No verifiable presentations created')
}

if (subjectToInputDescriptors.length !== verifiablePresentationResultsWithFormat.length) {
throw new PresentationExchangeError('Invalid amount of verifiable presentations created.')
throw new PresentationExchangeError('Invalid amount of verifiable presentations created')
}

const presentationSubmission: PexPresentationSubmission = {
Expand Down Expand Up @@ -357,13 +348,13 @@ export class PresentationExchangeService {
algorithmsSatisfyingPdAndDescriptorRestrictions.length === 0
) {
throw new PresentationExchangeError(
`No signature algorithm found for satisfying restrictions of the presentation definition and input descriptors.`
`No signature algorithm found for satisfying restrictions of the presentation definition and input descriptors`
)
}

if (allDescriptorAlgorithms.length > 0 && algorithmsSatisfyingDescriptors.length === 0) {
throw new PresentationExchangeError(
`No signature algorithm found for satisfying restrictions of the input descriptors.`
`No signature algorithm found for satisfying restrictions of the input descriptors`
)
}

Expand Down Expand Up @@ -419,7 +410,7 @@ export class PresentationExchangeService {
const supportedSignatureSuite = signatureSuiteRegistry.getByVerificationMethodType(verificationMethod.type)
if (!supportedSignatureSuite) {
throw new PresentationExchangeError(
`Couldn't find a supported signature suite for the given verification method type '${verificationMethod.type}'.`
`Couldn't find a supported signature suite for the given verification method type '${verificationMethod.type}'`
)
}

Expand Down Expand Up @@ -456,7 +447,7 @@ export class PresentationExchangeService {

if (verificationMethodId && verificationMethodId !== verificationMethod.id) {
throw new PresentationExchangeError(
`Verification method from signing options ${verificationMethodId} does not match verification method ${verificationMethod.id}.`
`Verification method from signing options ${verificationMethodId} does not match verification method ${verificationMethod.id}`
)
}

Expand Down Expand Up @@ -490,7 +481,7 @@ export class PresentationExchangeService {
})
} else {
throw new PresentationExchangeError(
`Only JWT credentials or JSONLD credentials are supported for a single presentation.`
`Only JWT credentials or JSONLD credentials are supported for a single presentation`
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export async function selectCredentialsForRequest(
verifiableCredential: selectResultsRaw.verifiableCredential?.map((encoded) => {
const credentialRecord = credentialRecords.find((record) => {
const originalVc = getSphereonOriginalVerifiableCredential(record.credential)

return deepEquality(originalVc, encoded)
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { PresentationDefinition } from '../../../presentation-exchange'
import type { W3cCredentialRecord } from '../../../vc'
import type { InputDescriptorToCredentials, PresentationDefinition } from '../../../presentation-exchange'
import type {
PresentationExchangePresentation,
PresentationExchangeProposal,
PresentationExchangeRequest,
} from '../../models/v2'
import type { ProofFormat } from '../ProofFormat'

export interface PresentationExchangeProofFormat extends ProofFormat {
Expand All @@ -17,24 +21,34 @@ export interface PresentationExchangeProofFormat extends ProofFormat {

createRequest: {
presentationDefinition: PresentationDefinition
options?: {
challenge?: string
domain?: string
}
}

acceptRequest: never
acceptRequest: {
credentials?: InputDescriptorToCredentials
}

getCredentialsForRequest: {
input: never
output: Array<W3cCredentialRecord>
output: {
credentials: InputDescriptorToCredentials
}
}

selectCredentialsForRequest: {
input: never
output: Array<W3cCredentialRecord>
output: {
credentials: InputDescriptorToCredentials
}
}
}

formatData: {
proposal: unknown
request: unknown
presentation: unknown
proposal: PresentationExchangeProposal
request: PresentationExchangeRequest
presentation: PresentationExchangePresentation
}
}
Loading

0 comments on commit f3e1534

Please sign in to comment.