Skip to content

Commit f65a98d

Browse files
committed
chore: update mdoc and ssi-types
Signed-off-by: Timo Glastra <[email protected]>
1 parent 384a344 commit f65a98d

File tree

10 files changed

+99
-170
lines changed

10 files changed

+99
-170
lines changed

lib/PEX.ts

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class PEX {
100100
const presentationsCopy: OriginalVerifiablePresentation[] = JSON.parse(JSON.stringify(presentationsArray));
101101

102102
const wrappedPresentations: WrappedVerifiablePresentation[] = presentationsCopy.map((p) =>
103-
SSITypesBuilder.mapExternalVerifiablePresentationToWrappedVP(p, this.options?.hasher),
103+
SSITypesBuilder.mapExternalVerifiablePresentationToWrappedVP(p),
104104
);
105105

106106
let presentationSubmission = opts?.presentationSubmission;
@@ -189,10 +189,8 @@ export class PEX {
189189
restrictToDIDMethods?: string[];
190190
},
191191
): EvaluationResults {
192-
const wrappedVerifiableCredentials: WrappedVerifiableCredential[] = SSITypesBuilder.mapExternalVerifiableCredentialsToWrappedVcs(
193-
verifiableCredentials,
194-
this.options?.hasher,
195-
);
192+
const wrappedVerifiableCredentials: WrappedVerifiableCredential[] =
193+
SSITypesBuilder.mapExternalVerifiableCredentialsToWrappedVcs(verifiableCredentials);
196194

197195
// TODO: So we have state in the form of this property which is set in the constructor, but we are overwriting it here. We need to retrhink how to instantiate PEX
198196
this._evaluationClientWrapper = new EvaluationClientWrapper();
@@ -234,11 +232,7 @@ export class PEX {
234232
const pd: IInternalPresentationDefinition = SSITypesBuilder.toInternalPresentationDefinition(presentationDefinition);
235233
// TODO: So we have state in the form of this property which is set in the constructor, but we are overwriting it here. We need to retrhink how to instantiate PEX
236234
this._evaluationClientWrapper = new EvaluationClientWrapper();
237-
return this._evaluationClientWrapper.selectFrom(
238-
pd,
239-
SSITypesBuilder.mapExternalVerifiableCredentialsToWrappedVcs(verifiableCredentialCopy, this.options?.hasher),
240-
opts,
241-
);
235+
return this._evaluationClientWrapper.selectFrom(pd, SSITypesBuilder.mapExternalVerifiableCredentialsToWrappedVcs(verifiableCredentialCopy), opts);
242236
}
243237

244238
public presentationSubmissionFrom(
@@ -255,11 +249,7 @@ export class PEX {
255249
},
256250
): PresentationSubmission {
257251
const pd: IInternalPresentationDefinition = SSITypesBuilder.toInternalPresentationDefinition(presentationDefinition);
258-
return this._evaluationClientWrapper.submissionFrom(
259-
pd,
260-
SSITypesBuilder.mapExternalVerifiableCredentialsToWrappedVcs(selectedCredentials, this.options?.hasher),
261-
opts,
262-
);
252+
return this._evaluationClientWrapper.submissionFrom(pd, SSITypesBuilder.mapExternalVerifiableCredentialsToWrappedVcs(selectedCredentials), opts);
263253
}
264254

265255
/**
@@ -294,7 +284,6 @@ export class PEX {
294284
...opts,
295285
// We only pass in the submission in case it needs to be included in the presentation
296286
presentationSubmission: presentationSubmissionLocation === PresentationSubmissionLocation.PRESENTATION ? presentationSubmission : undefined,
297-
hasher: this.options?.hasher,
298287
});
299288
this.updateSdJwtCredentials(presentations);
300289
return {
@@ -320,13 +309,8 @@ export class PEX {
320309
throw Error(`At least a verifiable credential needs to be passed in to create a presentation`);
321310
}
322311
const verifiableCredential = (Array.isArray(selectedCredentials) ? selectedCredentials : [selectedCredentials]) as W3CVerifiableCredential[];
323-
if (verifiableCredential.some((c) => CredentialMapper.isSdJwtDecodedCredential(c) || CredentialMapper.isSdJwtEncoded(c))) {
324-
if (!this.options?.hasher) {
325-
throw new Error('Hasher must be provided when creating a presentation with an SD-JWT VC');
326-
}
327-
}
328312

329-
const wVCs = verifiableCredential.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc, { hasher: this.options?.hasher }));
313+
const wVCs = verifiableCredential.map((vc) => CredentialMapper.toWrappedVerifiableCredential(vc));
330314
const holders = Array.from(new Set(wVCs.flatMap((wvc) => getSubjectIdsAsString(wvc.credential as ICredential))));
331315
const holder = opts?.holderDID ?? (holders.length === 1 ? holders[0] : undefined);
332316

@@ -371,7 +355,7 @@ export class PEX {
371355
if (CredentialMapper.isSdJwtDecodedCredential(vc)) {
372356
result.push(vc as PartialSdJwtDecodedVerifiableCredential);
373357
} else if (CredentialMapper.isSdJwtEncoded(vc)) {
374-
const decoded = CredentialMapper.decodeVerifiableCredential(vc, opts?.hasher);
358+
const decoded = CredentialMapper.decodeVerifiableCredential(vc);
375359
result.push(decoded as PartialSdJwtDecodedVerifiableCredential);
376360
} else {
377361
// This should be jwt or json-ld
@@ -586,13 +570,10 @@ export class PEX {
586570
// Select type without kbJwt as isSdJwtDecodedCredential and won't accept the partial sdvc type
587571
if (CredentialMapper.isSdJwtDecodedCredential(presentation as SdJwtDecodedVerifiableCredential)) {
588572
const sdJwtCredential = presentation as SdJwtDecodedVerifiableCredential;
589-
if (!this.options?.hasher) {
590-
throw new Error('Hasher must be provided when creating a presentation with an SD-JWT VC');
591-
}
592573

593574
// extract sd_alg or default to sha-256
594575
const hashAlg = sdJwtCredential.signedPayload._sd_alg ?? 'sha-256';
595-
const sdHash = calculateSdHash(sdJwtCredential.compactSdJwtVc, hashAlg, this.options.hasher);
576+
const sdHash = calculateSdHash(sdJwtCredential.compactSdJwtVc, hashAlg);
596577

597578
const kbJwt = {
598579
// alg MUST be set by the signer

lib/types/SSITypesBuilder.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
} from '@sphereon/pex-models';
77
import {
88
CredentialMapper,
9-
Hasher,
109
JwtDecodedVerifiablePresentation,
1110
OriginalVerifiableCredential,
1211
OriginalVerifiablePresentation,
@@ -46,18 +45,17 @@ export class SSITypesBuilder {
4645

4746
static mapExternalVerifiablePresentationToWrappedVP(
4847
presentation: OriginalVerifiablePresentation | JwtDecodedVerifiablePresentation,
49-
hasher?: Hasher,
5048
): WrappedVerifiablePresentation {
51-
return CredentialMapper.toWrappedVerifiablePresentation(presentation, { hasher });
49+
return CredentialMapper.toWrappedVerifiablePresentation(presentation);
5250
}
5351

5452
static mapExternalVerifiableCredentialsToWrappedVcs(
5553
verifiableCredentials: OriginalVerifiableCredential | OriginalVerifiableCredential[],
56-
hasher?: Hasher,
5754
): WrappedVerifiableCredential[] {
58-
return CredentialMapper.toWrappedVerifiableCredentials(Array.isArray(verifiableCredentials) ? verifiableCredentials : [verifiableCredentials], {
59-
hasher,
60-
});
55+
return CredentialMapper.toWrappedVerifiableCredentials(
56+
Array.isArray(verifiableCredentials) ? verifiableCredentials : [verifiableCredentials],
57+
{},
58+
);
6159
}
6260

6361
static toInternalPresentationDefinition(presentationDefinition: IPresentationDefinition): IInternalPresentationDefinition {

lib/utils/sdJwt.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getSDAlgAndPayload, unpackObj } from '@sd-jwt/decode';
22
import { createHashMappingForSerializedDisclosure, selectDisclosures } from '@sd-jwt/present';
33
import { PresentationFrame } from '@sd-jwt/types';
44
import {
5-
Hasher,
5+
defaultHasher,
66
SdJwtDecodedDisclosure,
77
SdJwtDecodedVerifiableCredential,
88
SdJwtDecodedVerifiableCredentialPayload,
@@ -12,8 +12,8 @@ import * as u8a from 'uint8arrays';
1212

1313
import { ObjectUtils } from './ObjectUtils';
1414

15-
export function calculateSdHash(compactSdJwtVc: string, alg: string, hasher: Hasher): string {
16-
const digest = hasher(compactSdJwtVc, alg);
15+
export function calculateSdHash(compactSdJwtVc: string, alg: string): string {
16+
const digest = defaultHasher(compactSdJwtVc, alg);
1717
return u8a.toString(digest, 'base64url');
1818
}
1919

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
"@sd-jwt/decode": "^0.7.2",
5050
"@sd-jwt/present": "^0.7.2",
5151
"@sd-jwt/types": "^0.7.2",
52-
"@sphereon/pex-models": "^2.3.1",
53-
"@sphereon/ssi-types": "0.30.2-next.135",
52+
"@sphereon/pex-models": "^2.3.2",
53+
"@sphereon/ssi-types": "0.33.0",
5454
"ajv": "^8.12.0",
5555
"ajv-formats": "^2.1.1",
5656
"jwt-decode": "^3.1.2",

pnpm-lock.yaml

Lines changed: 54 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)