Skip to content
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

feature/funke-mdoc #166

Merged
merged 23 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions lib/PEX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {

import { Status } from './ConstraintUtils';
import { EvaluationClientWrapper, EvaluationResults, SelectResults } from './evaluation';
import { PresentationEvaluationResults } from './evaluation/core';
import { PresentationEvaluationResults } from './evaluation';
import {
PresentationFromOpts,
PresentationResult,
Expand Down Expand Up @@ -72,16 +72,16 @@ export class PEX {
*/
public evaluatePresentation(
presentationDefinition: IPresentationDefinition,
presentations: OrArray<OriginalVerifiablePresentation | IPresentation>,
presentations: OrArray<OriginalVerifiablePresentation | IPresentation | SdJwtDecodedVerifiableCredentialWithKbJwtInput>,
sanderPostma marked this conversation as resolved.
Show resolved Hide resolved
opts?: {
limitDisclosureSignatureSuites?: string[];
restrictToFormats?: Format;
restrictToDIDMethods?: string[];
presentationSubmission?: PresentationSubmission;
/**
* The location of the presentation submission. By default {@link PresentationSubmissionLocation.PRESENTATION}
* is used when one W3C presentation is passed (not as array) , while {@link PresentationSubmissionLocation.EXTERNAL} is
* used when an array is passed or the presentation is not a W3C presentation
* is used when one presentation is passed (not as array), while {@link PresentationSubmissionLocation.EXTERNAL} is
* used when an array is passed
*/
presentationSubmissionLocation?: PresentationSubmissionLocation;
generatePresentationSubmission?: boolean;
Expand Down Expand Up @@ -117,7 +117,10 @@ export class PEX {
CredentialMapper.isW3cPresentation(wrappedPresentations[0].presentation) &&
!generatePresentationSubmission
) {
presentationSubmission = wrappedPresentations[0].decoded.presentation_submission;
const decoded = wrappedPresentations[0].decoded;
if ('presentation_submission' in decoded) {
presentationSubmission = decoded.presentation_submission;
}
if (!presentationSubmission) {
throw Error(`Either a presentation submission as part of the VP or provided in options was expected`);
}
Expand All @@ -134,7 +137,9 @@ export class PEX {
// TODO: we should probably add support for holder dids in the kb-jwt of an SD-JWT. We can extract this from the
// `wrappedPresentation.original.compactKbJwt`, but as HAIP doesn't use dids, we'll leave it for now.
const holderDIDs = wrappedPresentations
.map((p) => (CredentialMapper.isW3cPresentation(p.presentation) && p.presentation.holder ? p.presentation.holder : undefined))
.map((p) => {
return CredentialMapper.isW3cPresentation(p.presentation) && p.presentation.holder ? p.presentation.holder : undefined;
})
.filter((d): d is string => d !== undefined);

const updatedOpts = {
Expand Down Expand Up @@ -336,7 +341,7 @@ export class PEX {
// that a valid assumption? It seems to be this way for BBS SD as well
const decoded = (
CredentialMapper.isSdJwtEncoded(credentials[0]) ? CredentialMapper.decodeVerifiableCredential(credentials[0], opts?.hasher) : credentials[0]
) as SdJwtDecodedVerifiableCredential;
) as Omit<SdJwtDecodedVerifiableCredential, 'kbJwt'>;

if (!opts?.hasher) {
throw new Error('Hasher must be provided when creating a presentation with an SD-JWT VC');
Expand Down Expand Up @@ -525,7 +530,8 @@ export class PEX {

let presentation = presentationResult.presentation;

if (CredentialMapper.isSdJwtDecodedCredential(presentationResult.presentation)) {
if (CredentialMapper.isSdJwtDecodedCredential(presentationResult.presentation as unknown as SdJwtDecodedVerifiableCredential)) {
sanderPostma marked this conversation as resolved.
Show resolved Hide resolved
// FIXME? SdJwtDecodedVerifiableCredentialWithKbJwtInput is local type and is not supported in ssi-sdk
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has a FIXME in there, but this is not a new situation. We still pass the same data into isSdJwtDecodedCredential, typescript just got in the way suddenly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That comment makes no sense IMO. Obviously the types changed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SdJwtDecodedVerifiableCredentialWithKbJwtInput does not overlap with SdJwtDecodedVerifiableCredential
Was is not matching is local type

export interface SdJwtKbJwtInput {
  header: {
    typ: 'kb+jwt';
  };
  payload: {
    iat: number;
    sd_hash: string;
    nonce?: string;
  };
}

vs in SSI-SDK

  kbJwt?: {
    compact: CompactJWT
    payload: SdJwtVcKbJwtPayload
  }

Copy link
Contributor Author

@sanderPostma sanderPostma Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nklomp
We have the latest SSI types available now in PEX, so perhaps PresentationResult should be like this now

export interface PresentationResult {
  /**
   * The resulting presentation, can have an embedded submission data depending on the location parameter
   */
  presentation: OriginalVerifiablePresentation;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I synched it up with ssi-types, but since some of the fields in header & payload have to be loaded by the signer I had to change the types a bit

export type PartialSdJwtKbJwt = {
  header: Partial<SdJwtVcKbJwtHeader>;
  payload: Partial<SdJwtVcKbJwtPayload>;
};

export type PartialSdJwtDecodedVerifiableCredential = Omit<SdJwtDecodedVerifiableCredential, 'kbJwt'> & { kbJwt: PartialSdJwtKbJwt };

if (!this.options?.hasher) {
throw new Error('Hasher must be provided when creating a presentation with an SD-JWT VC');
}
Expand Down
6 changes: 5 additions & 1 deletion lib/evaluation/handlers/didRestrictionEvaluationHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ export class DIDRestrictionEvaluationHandler extends AbstractEvaluationHandler {
return typeof wrappedVc.credential.issuer === 'object' ? wrappedVc.credential.issuer.id : wrappedVc.credential.issuer;
} else if (CredentialMapper.isSdJwtDecodedCredential(wrappedVc.credential)) {
return wrappedVc.credential.decodedPayload.iss;
} else if (CredentialMapper.isWrappedMdocCredential(wrappedVc)) {
if (typeof wrappedVc.decoded === 'object' && wrappedVc.decoded.iss !== undefined) {
return wrappedVc.decoded.iss;
}
throw new Error('cannot get issuer from the supplied mdoc credential');
}

throw new Error('Unsupported credential type');
}

Expand Down
2 changes: 1 addition & 1 deletion lib/signing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export interface SdJwtKbJwtInput {
};
}

export type SdJwtDecodedVerifiableCredentialWithKbJwtInput = SdJwtDecodedVerifiableCredential & { kbJwt: SdJwtKbJwtInput };
export type SdJwtDecodedVerifiableCredentialWithKbJwtInput = Omit<SdJwtDecodedVerifiableCredential, 'kbJwt'> & { kbJwt: SdJwtKbJwtInput };

/**
* The result object containing the presentation and presentation submission
Expand Down
1 change: 1 addition & 0 deletions lib/validation/bundlers/presentationSubmissionVB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class PresentationSubmissionVB extends ValidationBundler<PresentationSubm
'di_vc',
'di_vp',
'vc+sd-jwt',
'mso_mdoc',
];

for (let i = 0; i < descriptor_map.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sphereon/pex",
"version": "4.1.0",
"version": "4.1.1-unstable.1",
"description": "A Typescript implementation of the v1 and v2 DIF Presentation Exchange specification",
"main": "dist/main/index.js",
"module": "dist/module/index.js",
Expand Down Expand Up @@ -47,7 +47,7 @@
"@sd-jwt/present": "^0.6.1",
"@sd-jwt/types": "^0.6.1",
"@sphereon/pex-models": "^2.3.1",
"@sphereon/ssi-types": "0.22.0",
"@sphereon/ssi-types": "0.29.1-unstable.113",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"jwt-decode": "^3.1.2",
Expand Down
Loading
Loading