Skip to content

Commit

Permalink
fix: subjectId could be undefined
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Auer <martin.auer97@gmail.com>
  • Loading branch information
auer-martin committed Mar 11, 2024
1 parent 3698733 commit 14d9fef
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ export class DifPresentationExchangeService {
}

if (presentationToCreate.claimFormat === ClaimFormat.JwtVp) {
if (!presentationToCreate.subjectIds) {
throw new DifPresentationExchangeError(`Cannot create presentation for credentials without subject id`)
}

// Determine a suitable verification method for the presentation
const verificationMethod = await this.getVerificationMethodForSubjectId(
agentContext,
Expand Down Expand Up @@ -468,6 +472,9 @@ export class DifPresentationExchangeService {
} as unknown as SphereonW3cVerifiablePresentation
}

if (!presentationToCreate.subjectIds) {
throw new DifPresentationExchangeError(`Cannot create presentation for credentials without subject id`)
}
// Determine a suitable verification method for the presentation
const verificationMethod = await this.getVerificationMethodForSubjectId(
agentContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface LdpVpPresentationToCreate {
claimFormat: ClaimFormat.LdpVp
// NOTE: we only support one subject id at the moment as we don't have proper
// support yet for adding multiple proofs to an LDP-VP
subjectIds: [string]
subjectIds: undefined | [string]
verifiableCredentials: Array<{
credential: W3cCredentialRecord
inputDescriptorId: string
Expand All @@ -52,10 +52,6 @@ export function getPresentationsToCreate(credentialsForInputDescriptor: DifPexIn
for (const credential of credentials) {
if (credential instanceof W3cCredentialRecord) {
const subjectId = credential.credential.credentialSubjectIds[0]
if (!subjectId) {
// FIXME: AnonCreds Presentations must not have a credential subject id
//throw new DifPresentationExchangeError('Missing required credential subject for creating the presentation.')
}

// NOTE: we only support one subjectId per VP -- once we have proper support
// for multiple proofs on an LDP-VP we can add multiple subjectIds to a single VP for LDP-vp only
Expand All @@ -64,7 +60,7 @@ export function getPresentationsToCreate(credentialsForInputDescriptor: DifPexIn

const matchingClaimFormatAndSubject = presentationsToCreate.find(
(p): p is JwtVpPresentationToCreate =>
p.claimFormat === expectedClaimFormat && p.subjectIds.includes(subjectId)
p.claimFormat === expectedClaimFormat && Boolean(p.subjectIds?.includes(subjectId))
)

if (matchingClaimFormatAndSubject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import type { ProofFormat } from '../ProofFormat'

export type DifPresentationExchangeProposal = DifPresentationExchangeDefinitionV1

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DifPexGetCredentialsForProofRequestOptions {}

export type DifPresentationExchangeRequest = {
options?: {
challenge?: string
Expand Down Expand Up @@ -50,13 +53,13 @@ export interface DifPresentationExchangeProofFormat extends ProofFormat {
}

getCredentialsForRequest: {
input: never
input: DifPexGetCredentialsForProofRequestOptions
// Presentation submission details which the options that are available
output: DifPexCredentialsForRequest
}

selectCredentialsForRequest: {
input: never
input: DifPexGetCredentialsForProofRequestOptions
// Input descriptor to credentials specifically details which credentials
// should be used for which input descriptor
output: {
Expand Down

0 comments on commit 14d9fef

Please sign in to comment.