Skip to content

Commit

Permalink
Merge pull request #179 from TimoGlastra/feat/mdoc-parsing
Browse files Browse the repository at this point in the history
feat: mdoc selectFrom, evaluation and parsing
  • Loading branch information
sanderPostma authored Oct 31, 2024
2 parents dc542dc + 3840944 commit 22c230c
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 1,475 deletions.
2 changes: 1 addition & 1 deletion lib/evaluation/evaluationClientWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ export class EvaluationClientWrapper {

vc = extractionResult.wvc;
vcPath += ` with nested credential ${descriptor.path_nested.path}`;
} else if (descriptor.format === 'vc+sd-jwt') {
} else if (descriptor.format === 'vc+sd-jwt' || descriptor.format === 'mso_mdoc') {
if (!vp.vcs || !vp.vcs.length) {
result.areRequiredCredentialsPresent = Status.ERROR;
result.errors?.push({
Expand Down
9 changes: 4 additions & 5 deletions lib/evaluation/handlers/didRestrictionEvaluationHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ 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');
}
// mdoc is not bound to did
else if (CredentialMapper.isWrappedMdocCredential(wrappedVc)) {
return undefined;
}
throw new Error('Unsupported credential type');
}
Expand Down
11 changes: 8 additions & 3 deletions lib/evaluation/handlers/limitDisclosureEvaluationHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export class LimitDisclosureEvaluationHandler extends AbstractEvaluationHandler
wvc: WrappedVerifiableCredential,
vcIndex: number,
): boolean {
if (wvc.format === 'vc+sd-jwt') return true;
if (wvc.format === 'vc+sd-jwt' || wvc.format === 'mso_mdoc') return true;
if (wvc.format === 'ldp' || wvc.format === 'jwt') return false;

const limitDisclosureSignatures = this.client.limitDisclosureSignatureSuites;
const decoded = wvc.decoded as IVerifiableCredential;
Expand Down Expand Up @@ -109,7 +110,11 @@ export class LimitDisclosureEvaluationHandler extends AbstractEvaluationHandler
this.createSuccessResult(inputDescriptorIndex, `$[${vcIndex}]`, inputDescriptor.constraints?.limit_disclosure);
}
}
} else if (CredentialMapper.isW3cCredential(wvc.credential)) {
} else if (CredentialMapper.isWrappedMdocCredential(wvc)) {
for (const { inputDescriptorIndex, inputDescriptor } of eligibleInputDescriptors) {
this.createSuccessResult(inputDescriptorIndex, `$[${vcIndex}]`, inputDescriptor.constraints?.limit_disclosure);
}
} else if (CredentialMapper.isWrappedW3CVerifiableCredential(wvc)) {
const internalCredentialToSend = this.createVcWithRequiredFields(eligibleInputDescriptors, wvc.credential, vcIndex);
/* When verifiableCredentialToSend is null/undefined an error is raised, the credential will
* remain untouched and the verifiable credential won't be submitted.
Expand All @@ -121,7 +126,7 @@ export class LimitDisclosureEvaluationHandler extends AbstractEvaluationHandler
}
}
} else {
throw new Error(`Unsupported format for selective disclosure ${wvc.format}`);
throw new Error('Unsupported format for selective disclosure');
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/evaluation/handlers/uriEvaluationHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
CredentialMapper,
ICredential,
ICredentialSchema,
MdocDocument,
OriginalType,
SdJwtDecodedVerifiableCredential,
WrappedVerifiableCredential,
Expand Down Expand Up @@ -125,7 +126,7 @@ export class UriEvaluationHandler extends AbstractEvaluationHandler {
}
}

private static buildVcContextAndSchemaUris(credential: ICredential | SdJwtDecodedVerifiableCredential, version: PEVersion) {
private static buildVcContextAndSchemaUris(credential: ICredential | SdJwtDecodedVerifiableCredential | MdocDocument, version: PEVersion) {
const uris: string[] = [];

// W3C credential
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@sd-jwt/present": "^0.7.2",
"@sd-jwt/types": "^0.7.2",
"@sphereon/pex-models": "^2.3.1",
"@sphereon/ssi-types": "0.30.1",
"@sphereon/ssi-types": "0.30.2-next.129",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"jwt-decode": "^3.1.2",
Expand Down
1,514 changes: 51 additions & 1,463 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

192 changes: 192 additions & 0 deletions test/Mdoc.spec.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/SdJwt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ describe('evaluate', () => {
// Expect the KB-JWT to be appended
expect(presentationResult.verifiablePresentations[0]).toEqual(decodedSdJwtVcWithDisclosuresRemoved.compactSdJwtVc + kbJwt);

const evaluateResults = pex.evaluatePresentation(presentationDefinition, presentationResult.verifiablePresentations, {
const evaluateResults = pex.evaluatePresentation(presentationDefinition, presentationResult.verifiablePresentations[0], {
presentationSubmission: presentationResult.presentationSubmission,
});

Expand Down

0 comments on commit 22c230c

Please sign in to comment.