Skip to content

Commit

Permalink
chore(proofs): use core pex implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <sliedrecht@berend.io>
  • Loading branch information
Berend Sliedrecht committed Dec 19, 2023
1 parent 4d1dcfc commit c170c98
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 1,169 deletions.
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"prepublishOnly": "yarn run build"
},
"dependencies": {
"@aries-framework/presentation-exchange": "^0.4.2",
"@digitalcredentials/jsonld": "^5.2.1",
"@digitalcredentials/jsonld-signatures": "^9.3.1",
"@digitalcredentials/vc": "^1.1.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { W3cCredentialRecord, W3cVerifiableCredential } from '../../../vc'
import type { PresentationDefinition } from '../../services'
import type { ProofFormat } from '../ProofFormat'
import type { PresentationDefinition } from '@aries-framework/presentation-exchange'

export interface PresentationExchangeProofFormat extends ProofFormat {
formatKey: 'presentationExchange'
Expand All @@ -15,7 +15,9 @@ export interface PresentationExchangeProofFormat extends ProofFormat {
version?: string
}

createRequest: { presentationDefinition: PresentationDefinition }
createRequest: {
presentationDefinition: PresentationDefinition
}

acceptRequest: {
credentials: Record<string, Array<W3cVerifiableCredential>>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable import/no-cycle */
/* eslint-disable workspaces/require-dependency */

import type { PresentationExchangeProofFormat } from './PresentationExchangeProofFormat'
import type { AgentContext } from '../../../../agent'
import type { W3cCredentialRecord } from '../../../vc'
import type { InputDescriptorToCredentials } from '../../models'
import type { PresentationDefinition, VerifiablePresentation } from '../../services'
import type { ProofFormatService } from '../ProofFormatService'
import type {
ProofFormatCreateProposalOptions,
Expand All @@ -20,19 +18,13 @@ import type {
ProofFormatAutoRespondRequestOptions,
ProofFormatAutoRespondPresentationOptions,
} from '../ProofFormatServiceOptions'
import type {
InputDescriptorToCredentials,
PexPresentationSubmission,
PresentationDefinition,
VerifiablePresentation,
} from '@aries-framework/presentation-exchange'

import { PresentationExchangeService } from '@aries-framework/presentation-exchange'
import type { PresentationSubmission as PexPresentationSubmission } from '@sphereon/pex-models'

import { Attachment, AttachmentData } from '../../../../decorators/attachment/Attachment'
import { AriesFrameworkError } from '../../../../error'
import { deepEquality } from '../../../../utils'
import { ProofFormatSpec } from '../../models'
import { PresentationExchangeService } from '../../services'

const PRESENTATION_EXCHANGE_PRESENTATION_PROPOSAL = 'dif/presentation-exchange/definitions@v1.0'
const PRESENTATION_EXCHANGE_PRESENTATION_REQUEST = 'dif/presentation-exchange/definitions@v1.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { AgentContext } from '../../../../../agent'
import type { PresentationDefinition } from '../../../services'
import type { ProofFormatService } from '../../ProofFormatService'
import type { PresentationExchangeProofFormat } from '../PresentationExchangeProofFormat'
import type { PresentationDefinition } from '@aries-framework/presentation-exchange'

import { PresentationExchangeModule } from '@aries-framework/presentation-exchange'

import { getIndySdkModules } from '../../../../../../../indy-sdk/tests/setupIndySdkModule'
import { getAgentOptions } from '../../../../../../tests'
import { Agent } from '../../../../../agent/Agent'
import { PresentationExchangeModule } from '../../../../presentation-exchange'
import { ProofsModule } from '../../../ProofsModule'
import { ProofState } from '../../../models'
import { V2ProofProtocol } from '../../../protocol'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ import type { InputDescriptorToCredentials, PresentationSubmission } from '../mo
import type {
IPresentationDefinition,
PresentationSignCallBackParams,
Validated,
VerifiablePresentationResult,
} from '@sphereon/pex'
import type {
InputDescriptorV2,
PresentationSubmission as PexPresentationSubmission,
PresentationDefinitionV1,
} from '@sphereon/pex-models'
import type { OriginalVerifiableCredential } from '@sphereon/ssi-types'
import type { IVerifiablePresentation, OriginalVerifiableCredential } from '@sphereon/ssi-types'

import { PEVersion, PEX, PresentationSubmissionLocation } from '@sphereon/pex'
import { Status, PEVersion, PEX, PresentationSubmissionLocation } from '@sphereon/pex'
import { injectable } from 'tsyringe'

import { getJwkFromKey } from '../../../crypto'
import { AriesFrameworkError } from '../../../error'
import { JsonTransformer } from '../../../utils'
import { getKeyFromVerificationMethod, DidsApi } from '../../dids'
import { PresentationExchangeError } from '../../presentation-exchange'
import { SignatureSuiteRegistry, W3cPresentation, W3cCredentialService, ClaimFormat } from '../../vc'
import { W3cCredentialRepository } from '../../vc/repository'
import { selectCredentialsForRequest } from '../utils/credentialSelection'
Expand All @@ -32,7 +34,9 @@ import {
} from '../utils/transform'

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

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

@injectable()
export class PresentationExchangeService {
Expand All @@ -51,6 +55,50 @@ export class PresentationExchangeService {
return selectCredentialsForRequest(presentationDefinition, credentialRecords, holderDids)
}

public validatePresentationDefinition(presentationDefinition: PresentationDefinition) {
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(', ')}`
)
}
}

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(', ')}`
)
}
}

public validatePresentation(presentationDefinition: PresentationDefinition, presentation: VerifiablePresentation) {
const { errors } = this.pex.evaluatePresentation(presentationDefinition, presentation)

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(', ')}`
)
}
}
}

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]
: []
}

/**
* Queries the wallet for credentials that match the given presentation definition. This only does an initial query based on the
* schema of the input descriptors. It does not do any further filtering based on the constraints in the input descriptors.
Expand Down
14 changes: 0 additions & 14 deletions packages/presentation-exchange/jest.config.ts

This file was deleted.

37 changes: 0 additions & 37 deletions packages/presentation-exchange/package.json

This file was deleted.

This file was deleted.

25 changes: 0 additions & 25 deletions packages/presentation-exchange/src/PresentationExchangeModule.ts

This file was deleted.

Loading

0 comments on commit c170c98

Please sign in to comment.