@sphereon/ssi-sdk.sd-jwt 0.36.1-next.11 → 0.36.1-next.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +97 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +49 -44
- package/dist/index.d.ts +49 -44
- package/dist/index.js +97 -80
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
- package/src/action-handler.ts +50 -16
- package/src/defaultCallbacks.ts +1 -1
- package/src/types.ts +9 -2
- package/src/utils.ts +10 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,51 @@
|
|
|
1
|
-
import { SdJwtVcPayload as SdJwtVcPayload$1,
|
|
2
|
-
import { SaltGenerator, KBOptions, kbHeader, kbPayload, Hasher, Signer,
|
|
1
|
+
import { VerificationResult, SdJwtVcPayload as SdJwtVcPayload$1, SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
|
|
2
|
+
import { DisclosureFrame, SDJWTCompact, SaltGenerator, KBOptions, kbHeader, kbPayload, Hasher, Signer, HasherSync as HasherSync$1 } from '@sd-jwt/types';
|
|
3
3
|
import { X509CertificateChainValidationOpts } from '@sphereon/ssi-sdk-ext.x509-utils';
|
|
4
|
-
import { HasherSync, JsonWebKey, SdJwtVcType, SdJwtVpType,
|
|
4
|
+
import { SdJwtVcdm2Payload, SDJWTVCDM2Config, HasherSync, JsonWebKey, SdJwtVcType, SdJwtVpType, SdJwtTypeMetadata, JoseSignatureAlgorithm, SdJwtType, SdJwtVcKbJwtHeader, SdJwtVcKbJwtPayload } from '@sphereon/ssi-types';
|
|
5
5
|
import { IPluginMethodMap, IAgentContext, IDIDManager, IResolver, IKeyManager, DIDDocumentSection, IAgentPlugin } from '@veramo/core';
|
|
6
|
+
import { SDJwtInstance, VerifierOptions, SdJwtPayload } from '@sd-jwt/core';
|
|
6
7
|
import { ManagedIdentifierResult, IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution';
|
|
7
8
|
import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service';
|
|
8
9
|
import { ImDLMdoc } from '@sphereon/ssi-sdk.mdl-mdoc';
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
interface SdJwtVcdm2VerificationResult extends Omit<VerificationResult, 'payload'> {
|
|
12
|
+
payload: SdJwtVcdm2Payload;
|
|
13
|
+
}
|
|
14
|
+
declare class SDJwtVcdm2Instance extends SDJwtInstance<SdJwtVcdm2Payload> {
|
|
15
|
+
/**
|
|
16
|
+
* The type of the SD-JWT VCDM2 set in the header.typ field.
|
|
17
|
+
*/
|
|
18
|
+
protected static type: string;
|
|
19
|
+
protected userConfig: SDJWTVCDM2Config;
|
|
20
|
+
constructor(userConfig?: SDJWTVCDM2Config);
|
|
21
|
+
/**
|
|
22
|
+
* Validates if the disclosureFrame contains any reserved fields. If so it will throw an error.
|
|
23
|
+
* @param disclosureFrame
|
|
24
|
+
*/
|
|
25
|
+
protected validateReservedFields(disclosureFrame: DisclosureFrame<SdJwtVcdm2Payload>): void;
|
|
26
|
+
/**
|
|
27
|
+
* Verifies the SD-JWT-VC. It will validate the signature, the keybindings when required, the status, and the VCT.
|
|
28
|
+
* @param encodedSDJwt
|
|
29
|
+
* @param options
|
|
30
|
+
*/
|
|
31
|
+
verify(encodedSDJwt: string, options?: VerifierOptions): Promise<SdJwtVcdm2VerificationResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Validates the integrity of the response if the integrity is passed. If the integrity does not match, an error is thrown.
|
|
34
|
+
* @param integrity
|
|
35
|
+
* @param response
|
|
36
|
+
*/
|
|
37
|
+
private validateIntegrity;
|
|
38
|
+
/**
|
|
39
|
+
* Fetches the content from the url with a timeout of 10 seconds.
|
|
40
|
+
* @param url
|
|
41
|
+
* @param integrity
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
protected fetch<T>(url: string, integrity?: string): Promise<T>;
|
|
45
|
+
issue<Payload extends SdJwtVcdm2Payload>(payload: Payload, disclosureFrame?: DisclosureFrame<Payload>, options?: {
|
|
46
|
+
header?: object;
|
|
47
|
+
}): Promise<SDJWTCompact>;
|
|
48
|
+
}
|
|
10
49
|
|
|
11
50
|
declare const sdJwtPluginContextMethods: Array<string>;
|
|
12
51
|
/**
|
|
@@ -248,45 +287,10 @@ type GetSignerResult = {
|
|
|
248
287
|
alg?: string;
|
|
249
288
|
signingKey?: SignKeyResult;
|
|
250
289
|
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
payload:
|
|
254
|
-
}
|
|
255
|
-
declare class SDJwtVcdm2Instance extends SDJwtInstance<SdJwtVcdm2Payload> {
|
|
256
|
-
/**
|
|
257
|
-
* The type of the SD-JWT VCDM2 set in the header.typ field.
|
|
258
|
-
*/
|
|
259
|
-
protected static type: string;
|
|
260
|
-
protected userConfig: SDJWTVCDM2Config;
|
|
261
|
-
constructor(userConfig?: SDJWTVCDM2Config);
|
|
262
|
-
/**
|
|
263
|
-
* Validates if the disclosureFrame contains any reserved fields. If so it will throw an error.
|
|
264
|
-
* @param disclosureFrame
|
|
265
|
-
*/
|
|
266
|
-
protected validateReservedFields(disclosureFrame: DisclosureFrame<SdJwtVcdm2Payload>): void;
|
|
267
|
-
/**
|
|
268
|
-
* Verifies the SD-JWT-VC. It will validate the signature, the keybindings when required, the status, and the VCT.
|
|
269
|
-
* @param encodedSDJwt
|
|
270
|
-
* @param options
|
|
271
|
-
*/
|
|
272
|
-
verify(encodedSDJwt: string, options?: VerifierOptions): Promise<SdJwtVcdm2VerificationResult>;
|
|
273
|
-
/**
|
|
274
|
-
* Validates the integrity of the response if the integrity is passed. If the integrity does not match, an error is thrown.
|
|
275
|
-
* @param integrity
|
|
276
|
-
* @param response
|
|
277
|
-
*/
|
|
278
|
-
private validateIntegrity;
|
|
279
|
-
/**
|
|
280
|
-
* Fetches the content from the url with a timeout of 10 seconds.
|
|
281
|
-
* @param url
|
|
282
|
-
* @param integrity
|
|
283
|
-
* @returns
|
|
284
|
-
*/
|
|
285
|
-
protected fetch<T>(url: string, integrity?: string): Promise<T>;
|
|
286
|
-
issue<Payload extends SdJwtVcdm2Payload>(payload: Payload, disclosureFrame?: DisclosureFrame<Payload>, options?: {
|
|
287
|
-
header?: object;
|
|
288
|
-
}): Promise<SDJWTCompact>;
|
|
289
|
-
}
|
|
290
|
+
type PartialSdJwtKbJwt = {
|
|
291
|
+
header: Partial<SdJwtVcKbJwtHeader>;
|
|
292
|
+
payload: Partial<SdJwtVcKbJwtPayload>;
|
|
293
|
+
};
|
|
290
294
|
|
|
291
295
|
/**
|
|
292
296
|
* @beta
|
|
@@ -390,5 +394,6 @@ declare function assertValidTypeMetadata(metadata: SdJwtTypeMetadata, vct: strin
|
|
|
390
394
|
declare function isVcdm2SdJwtPayload(payload: SdJwtPayload): payload is SdJwtVcdm2Payload;
|
|
391
395
|
declare function isSdjwtVcPayload(payload: SdJwtPayload): payload is SdJwtVcPayload$1;
|
|
392
396
|
declare function getIssuerFromSdJwt(payload: SdJwtPayload): string;
|
|
397
|
+
declare function calculateSdHash(compactSdJwtVc: string, alg: string, hasher: Hasher): string;
|
|
393
398
|
|
|
394
|
-
export { type Claims, type FetchSdJwtTypeMetadataFromVctUrlArgs, type FetchSdJwtTypeMetadataFromVctUrlOpts, type GetSignerForIdentifierArgs, type GetSignerResult, type ICreateSdJwtPresentationArgs, type ICreateSdJwtPresentationResult, type ICreateSdJwtVcArgs, type ICreateSdJwtVcResult, type IDisclosureFrame, type IPresentationFrame, type IRequiredContext, type ISDJwtPlugin, type IVerifySdJwtPresentationArgs, type IVerifySdJwtPresentationResult, type IVerifySdJwtVcArgs, type IVerifySdJwtVcResult, type IntegrityAlg, SDJwtPlugin, type SdJWTImplementation, type SdJwtVcPayload, type SdJwtVerifySignature, type SignKeyArgs, type SignKeyResult, type Vcdm2Enveloped, assertValidTypeMetadata, contextHasSDJwtPlugin, createIntegrity, defaultGenerateDigest, extractHashFromIntegrity, fetchUrlWithErrorHandling, getIssuerFromSdJwt, isSdjwtVcPayload, isVcdm2SdJwt, isVcdm2SdJwtPayload, sdJwtPluginContextMethods, validateIntegrity };
|
|
399
|
+
export { type Claims, type FetchSdJwtTypeMetadataFromVctUrlArgs, type FetchSdJwtTypeMetadataFromVctUrlOpts, type GetSignerForIdentifierArgs, type GetSignerResult, type ICreateSdJwtPresentationArgs, type ICreateSdJwtPresentationResult, type ICreateSdJwtVcArgs, type ICreateSdJwtVcResult, type IDisclosureFrame, type IPresentationFrame, type IRequiredContext, type ISDJwtPlugin, type IVerifySdJwtPresentationArgs, type IVerifySdJwtPresentationResult, type IVerifySdJwtVcArgs, type IVerifySdJwtVcResult, type IntegrityAlg, type PartialSdJwtKbJwt, SDJwtPlugin, type SdJWTImplementation, type SdJwtVcPayload, type SdJwtVerifySignature, type SignKeyArgs, type SignKeyResult, type Vcdm2Enveloped, assertValidTypeMetadata, calculateSdHash, contextHasSDJwtPlugin, createIntegrity, defaultGenerateDigest, extractHashFromIntegrity, fetchUrlWithErrorHandling, getIssuerFromSdJwt, isSdjwtVcPayload, isVcdm2SdJwt, isVcdm2SdJwtPayload, sdJwtPluginContextMethods, validateIntegrity };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,51 @@
|
|
|
1
|
-
import { SdJwtVcPayload as SdJwtVcPayload$1,
|
|
2
|
-
import { SaltGenerator, KBOptions, kbHeader, kbPayload, Hasher, Signer,
|
|
1
|
+
import { VerificationResult, SdJwtVcPayload as SdJwtVcPayload$1, SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
|
|
2
|
+
import { DisclosureFrame, SDJWTCompact, SaltGenerator, KBOptions, kbHeader, kbPayload, Hasher, Signer, HasherSync as HasherSync$1 } from '@sd-jwt/types';
|
|
3
3
|
import { X509CertificateChainValidationOpts } from '@sphereon/ssi-sdk-ext.x509-utils';
|
|
4
|
-
import { HasherSync, JsonWebKey, SdJwtVcType, SdJwtVpType,
|
|
4
|
+
import { SdJwtVcdm2Payload, SDJWTVCDM2Config, HasherSync, JsonWebKey, SdJwtVcType, SdJwtVpType, SdJwtTypeMetadata, JoseSignatureAlgorithm, SdJwtType, SdJwtVcKbJwtHeader, SdJwtVcKbJwtPayload } from '@sphereon/ssi-types';
|
|
5
5
|
import { IPluginMethodMap, IAgentContext, IDIDManager, IResolver, IKeyManager, DIDDocumentSection, IAgentPlugin } from '@veramo/core';
|
|
6
|
+
import { SDJwtInstance, VerifierOptions, SdJwtPayload } from '@sd-jwt/core';
|
|
6
7
|
import { ManagedIdentifierResult, IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution';
|
|
7
8
|
import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service';
|
|
8
9
|
import { ImDLMdoc } from '@sphereon/ssi-sdk.mdl-mdoc';
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
interface SdJwtVcdm2VerificationResult extends Omit<VerificationResult, 'payload'> {
|
|
12
|
+
payload: SdJwtVcdm2Payload;
|
|
13
|
+
}
|
|
14
|
+
declare class SDJwtVcdm2Instance extends SDJwtInstance<SdJwtVcdm2Payload> {
|
|
15
|
+
/**
|
|
16
|
+
* The type of the SD-JWT VCDM2 set in the header.typ field.
|
|
17
|
+
*/
|
|
18
|
+
protected static type: string;
|
|
19
|
+
protected userConfig: SDJWTVCDM2Config;
|
|
20
|
+
constructor(userConfig?: SDJWTVCDM2Config);
|
|
21
|
+
/**
|
|
22
|
+
* Validates if the disclosureFrame contains any reserved fields. If so it will throw an error.
|
|
23
|
+
* @param disclosureFrame
|
|
24
|
+
*/
|
|
25
|
+
protected validateReservedFields(disclosureFrame: DisclosureFrame<SdJwtVcdm2Payload>): void;
|
|
26
|
+
/**
|
|
27
|
+
* Verifies the SD-JWT-VC. It will validate the signature, the keybindings when required, the status, and the VCT.
|
|
28
|
+
* @param encodedSDJwt
|
|
29
|
+
* @param options
|
|
30
|
+
*/
|
|
31
|
+
verify(encodedSDJwt: string, options?: VerifierOptions): Promise<SdJwtVcdm2VerificationResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Validates the integrity of the response if the integrity is passed. If the integrity does not match, an error is thrown.
|
|
34
|
+
* @param integrity
|
|
35
|
+
* @param response
|
|
36
|
+
*/
|
|
37
|
+
private validateIntegrity;
|
|
38
|
+
/**
|
|
39
|
+
* Fetches the content from the url with a timeout of 10 seconds.
|
|
40
|
+
* @param url
|
|
41
|
+
* @param integrity
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
protected fetch<T>(url: string, integrity?: string): Promise<T>;
|
|
45
|
+
issue<Payload extends SdJwtVcdm2Payload>(payload: Payload, disclosureFrame?: DisclosureFrame<Payload>, options?: {
|
|
46
|
+
header?: object;
|
|
47
|
+
}): Promise<SDJWTCompact>;
|
|
48
|
+
}
|
|
10
49
|
|
|
11
50
|
declare const sdJwtPluginContextMethods: Array<string>;
|
|
12
51
|
/**
|
|
@@ -248,45 +287,10 @@ type GetSignerResult = {
|
|
|
248
287
|
alg?: string;
|
|
249
288
|
signingKey?: SignKeyResult;
|
|
250
289
|
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
payload:
|
|
254
|
-
}
|
|
255
|
-
declare class SDJwtVcdm2Instance extends SDJwtInstance<SdJwtVcdm2Payload> {
|
|
256
|
-
/**
|
|
257
|
-
* The type of the SD-JWT VCDM2 set in the header.typ field.
|
|
258
|
-
*/
|
|
259
|
-
protected static type: string;
|
|
260
|
-
protected userConfig: SDJWTVCDM2Config;
|
|
261
|
-
constructor(userConfig?: SDJWTVCDM2Config);
|
|
262
|
-
/**
|
|
263
|
-
* Validates if the disclosureFrame contains any reserved fields. If so it will throw an error.
|
|
264
|
-
* @param disclosureFrame
|
|
265
|
-
*/
|
|
266
|
-
protected validateReservedFields(disclosureFrame: DisclosureFrame<SdJwtVcdm2Payload>): void;
|
|
267
|
-
/**
|
|
268
|
-
* Verifies the SD-JWT-VC. It will validate the signature, the keybindings when required, the status, and the VCT.
|
|
269
|
-
* @param encodedSDJwt
|
|
270
|
-
* @param options
|
|
271
|
-
*/
|
|
272
|
-
verify(encodedSDJwt: string, options?: VerifierOptions): Promise<SdJwtVcdm2VerificationResult>;
|
|
273
|
-
/**
|
|
274
|
-
* Validates the integrity of the response if the integrity is passed. If the integrity does not match, an error is thrown.
|
|
275
|
-
* @param integrity
|
|
276
|
-
* @param response
|
|
277
|
-
*/
|
|
278
|
-
private validateIntegrity;
|
|
279
|
-
/**
|
|
280
|
-
* Fetches the content from the url with a timeout of 10 seconds.
|
|
281
|
-
* @param url
|
|
282
|
-
* @param integrity
|
|
283
|
-
* @returns
|
|
284
|
-
*/
|
|
285
|
-
protected fetch<T>(url: string, integrity?: string): Promise<T>;
|
|
286
|
-
issue<Payload extends SdJwtVcdm2Payload>(payload: Payload, disclosureFrame?: DisclosureFrame<Payload>, options?: {
|
|
287
|
-
header?: object;
|
|
288
|
-
}): Promise<SDJWTCompact>;
|
|
289
|
-
}
|
|
290
|
+
type PartialSdJwtKbJwt = {
|
|
291
|
+
header: Partial<SdJwtVcKbJwtHeader>;
|
|
292
|
+
payload: Partial<SdJwtVcKbJwtPayload>;
|
|
293
|
+
};
|
|
290
294
|
|
|
291
295
|
/**
|
|
292
296
|
* @beta
|
|
@@ -390,5 +394,6 @@ declare function assertValidTypeMetadata(metadata: SdJwtTypeMetadata, vct: strin
|
|
|
390
394
|
declare function isVcdm2SdJwtPayload(payload: SdJwtPayload): payload is SdJwtVcdm2Payload;
|
|
391
395
|
declare function isSdjwtVcPayload(payload: SdJwtPayload): payload is SdJwtVcPayload$1;
|
|
392
396
|
declare function getIssuerFromSdJwt(payload: SdJwtPayload): string;
|
|
397
|
+
declare function calculateSdHash(compactSdJwtVc: string, alg: string, hasher: Hasher): string;
|
|
393
398
|
|
|
394
|
-
export { type Claims, type FetchSdJwtTypeMetadataFromVctUrlArgs, type FetchSdJwtTypeMetadataFromVctUrlOpts, type GetSignerForIdentifierArgs, type GetSignerResult, type ICreateSdJwtPresentationArgs, type ICreateSdJwtPresentationResult, type ICreateSdJwtVcArgs, type ICreateSdJwtVcResult, type IDisclosureFrame, type IPresentationFrame, type IRequiredContext, type ISDJwtPlugin, type IVerifySdJwtPresentationArgs, type IVerifySdJwtPresentationResult, type IVerifySdJwtVcArgs, type IVerifySdJwtVcResult, type IntegrityAlg, SDJwtPlugin, type SdJWTImplementation, type SdJwtVcPayload, type SdJwtVerifySignature, type SignKeyArgs, type SignKeyResult, type Vcdm2Enveloped, assertValidTypeMetadata, contextHasSDJwtPlugin, createIntegrity, defaultGenerateDigest, extractHashFromIntegrity, fetchUrlWithErrorHandling, getIssuerFromSdJwt, isSdjwtVcPayload, isVcdm2SdJwt, isVcdm2SdJwtPayload, sdJwtPluginContextMethods, validateIntegrity };
|
|
399
|
+
export { type Claims, type FetchSdJwtTypeMetadataFromVctUrlArgs, type FetchSdJwtTypeMetadataFromVctUrlOpts, type GetSignerForIdentifierArgs, type GetSignerResult, type ICreateSdJwtPresentationArgs, type ICreateSdJwtPresentationResult, type ICreateSdJwtVcArgs, type ICreateSdJwtVcResult, type IDisclosureFrame, type IPresentationFrame, type IRequiredContext, type ISDJwtPlugin, type IVerifySdJwtPresentationArgs, type IVerifySdJwtPresentationResult, type IVerifySdJwtVcArgs, type IVerifySdJwtVcResult, type IntegrityAlg, type PartialSdJwtKbJwt, SDJwtPlugin, type SdJWTImplementation, type SdJwtVcPayload, type SdJwtVerifySignature, type SignKeyArgs, type SignKeyResult, type Vcdm2Enveloped, assertValidTypeMetadata, calculateSdHash, contextHasSDJwtPlugin, createIntegrity, defaultGenerateDigest, extractHashFromIntegrity, fetchUrlWithErrorHandling, getIssuerFromSdJwt, isSdjwtVcPayload, isVcdm2SdJwt, isVcdm2SdJwtPayload, sdJwtPluginContextMethods, validateIntegrity };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { SDJwt } from "@sd-jwt/core";
|
|
|
6
6
|
import { SDJwtVcInstance as SDJwtVcInstance2 } from "@sd-jwt/sd-jwt-vc";
|
|
7
7
|
import { calculateJwkThumbprint, signatureAlgorithmFromKey } from "@sphereon/ssi-sdk-ext.key-utils";
|
|
8
8
|
import Debug from "debug";
|
|
9
|
+
import * as u8a2 from "uint8arrays";
|
|
9
10
|
|
|
10
11
|
// src/defaultCallbacks.ts
|
|
11
12
|
import { digestMethodParams } from "@sphereon/ssi-sdk-ext.key-utils";
|
|
@@ -27,81 +28,6 @@ var defaultVerifySignature = /* @__PURE__ */ __name((context) => async (data, si
|
|
|
27
28
|
return !result.error;
|
|
28
29
|
}, "defaultVerifySignature");
|
|
29
30
|
|
|
30
|
-
// src/trustAnchors.ts
|
|
31
|
-
var funkeTestCA = "-----BEGIN CERTIFICATE-----\nMIICeTCCAiCgAwIBAgIUB5E9QVZtmUYcDtCjKB/H3VQv72gwCgYIKoZIzj0EAwIwgYgxCzAJBgNVBAYTAkRFMQ8wDQYDVQQHDAZCZXJsaW4xHTAbBgNVBAoMFEJ1bmRlc2RydWNrZXJlaSBHbWJIMREwDwYDVQQLDAhUIENTIElERTE2MDQGA1UEAwwtU1BSSU5EIEZ1bmtlIEVVREkgV2FsbGV0IFByb3RvdHlwZSBJc3N1aW5nIENBMB4XDTI0MDUzMTA2NDgwOVoXDTM0MDUyOTA2NDgwOVowgYgxCzAJBgNVBAYTAkRFMQ8wDQYDVQQHDAZCZXJsaW4xHTAbBgNVBAoMFEJ1bmRlc2RydWNrZXJlaSBHbWJIMREwDwYDVQQLDAhUIENTIElERTE2MDQGA1UEAwwtU1BSSU5EIEZ1bmtlIEVVREkgV2FsbGV0IFByb3RvdHlwZSBJc3N1aW5nIENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEYGzdwFDnc7+Kn5ibAvCOM8ke77VQxqfMcwZL8IaIA+WCROcCfmY/giH92qMru5p/kyOivE0RC/IbdMONvDoUyaNmMGQwHQYDVR0OBBYEFNRWGMCJOOgOWIQYyXZiv6u7xZC+MB8GA1UdIwQYMBaAFNRWGMCJOOgOWIQYyXZiv6u7xZC+MBIGA1UdEwEB/wQIMAYBAf8CAQAwDgYDVR0PAQH/BAQDAgGGMAoGCCqGSM49BAMCA0cAMEQCIGEm7wkZKHt/atb4MdFnXW6yrnwMUT2u136gdtl10Y6hAiBuTFqvVYth1rbxzCP0xWZHmQK9kVyxn8GPfX27EIzzsw==\n-----END CERTIFICATE-----";
|
|
32
|
-
var sphereonCA = "-----BEGIN CERTIFICATE-----\nMIICCDCCAa6gAwIBAgITAPMgqwtYzWPBXaobHhxG9iSydTAKBggqhkjOPQQDAjBa\nMQswCQYDVQQGEwJOTDEkMCIGA1UECgwbU3BoZXJlb24gSW50ZXJuYXRpb25hbCBC\nLlYuMQswCQYDVQQLDAJJVDEYMBYGA1UEAwwPY2Euc3BoZXJlb24uY29tMB4XDTI0\nMDcyODIxMjY0OVoXDTM0MDcyODIxMjY0OVowWjELMAkGA1UEBhMCTkwxJDAiBgNV\nBAoMG1NwaGVyZW9uIEludGVybmF0aW9uYWwgQi5WLjELMAkGA1UECwwCSVQxGDAW\nBgNVBAMMD2NhLnNwaGVyZW9uLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA\nBEiA0KeESSNrOcmCDga8YsBkUTgowZGwqvL2n91JUpAMdRSwvlVFdqdiLXnk2pQq\nT1vZnDG0I+x+iz2EbdsG0aajUzBRMB0GA1UdDgQWBBTnB8pdlVz5yKD+zuNkRR6A\nsywywTAOBgNVHQ8BAf8EBAMCAaYwDwYDVR0lBAgwBgYEVR0lADAPBgNVHRMBAf8E\nBTADAQH/MAoGCCqGSM49BAMCA0gAMEUCIHH7ie1OAAbff5262rzZVQa8J9zENG8A\nQlHHFydMdgaXAiEA1Ib82mhHIYDziE0DDbHEAXOs98al+7dpo8fPGVGTeKI=\n-----END CERTIFICATE-----";
|
|
33
|
-
|
|
34
|
-
// src/utils.ts
|
|
35
|
-
import { toString } from "uint8arrays/to-string";
|
|
36
|
-
async function fetchUrlWithErrorHandling(url) {
|
|
37
|
-
const response = await fetch(url);
|
|
38
|
-
if (!response.ok) {
|
|
39
|
-
throw new Error(`${response.status}: ${response.statusText}`);
|
|
40
|
-
}
|
|
41
|
-
return response;
|
|
42
|
-
}
|
|
43
|
-
__name(fetchUrlWithErrorHandling, "fetchUrlWithErrorHandling");
|
|
44
|
-
function extractHashAlgFromIntegrity(integrityValue) {
|
|
45
|
-
const val = integrityValue?.toLowerCase().trim().split("-")[0];
|
|
46
|
-
if (val === "sha256" || val === "sha384" || val === "sha512") {
|
|
47
|
-
return val;
|
|
48
|
-
}
|
|
49
|
-
return void 0;
|
|
50
|
-
}
|
|
51
|
-
__name(extractHashAlgFromIntegrity, "extractHashAlgFromIntegrity");
|
|
52
|
-
function extractHashFromIntegrity(integrityValue) {
|
|
53
|
-
return integrityValue?.toLowerCase().trim().split("-")[1];
|
|
54
|
-
}
|
|
55
|
-
__name(extractHashFromIntegrity, "extractHashFromIntegrity");
|
|
56
|
-
async function validateIntegrity({ input, integrityValue, hasher }) {
|
|
57
|
-
if (!integrityValue) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
const alg = extractHashAlgFromIntegrity(integrityValue);
|
|
61
|
-
if (!alg) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
const calculatedHash = await createIntegrity({
|
|
65
|
-
hasher,
|
|
66
|
-
input,
|
|
67
|
-
alg
|
|
68
|
-
});
|
|
69
|
-
return calculatedHash == integrityValue;
|
|
70
|
-
}
|
|
71
|
-
__name(validateIntegrity, "validateIntegrity");
|
|
72
|
-
async function createIntegrity({ input, hasher, alg = "sha256" }) {
|
|
73
|
-
const calculatedHash = await hasher(typeof input === "string" ? input : JSON.stringify(input), alg);
|
|
74
|
-
return `${alg}-${toString(calculatedHash, "base64")}`;
|
|
75
|
-
}
|
|
76
|
-
__name(createIntegrity, "createIntegrity");
|
|
77
|
-
function assertValidTypeMetadata(metadata, vct) {
|
|
78
|
-
if (metadata.vct !== vct) {
|
|
79
|
-
throw new Error("VCT mismatch in metadata and credential");
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
__name(assertValidTypeMetadata, "assertValidTypeMetadata");
|
|
83
|
-
function isVcdm2SdJwtPayload(payload) {
|
|
84
|
-
return "type" in payload && Array.isArray(payload.type) && payload.type.includes("VerifiableCredential") && "@context" in payload && (typeof payload["@context"] === "string" && payload["@context"].length > 0 || Array.isArray(payload["@context"]) && payload["@context"].length > 0 && payload["@context"].includes("https://www.w3.org/ns/credentials/v2"));
|
|
85
|
-
}
|
|
86
|
-
__name(isVcdm2SdJwtPayload, "isVcdm2SdJwtPayload");
|
|
87
|
-
function isSdjwtVcPayload(payload) {
|
|
88
|
-
return !isVcdm2SdJwtPayload(payload) && "vct" in payload && typeof payload.vct === "string";
|
|
89
|
-
}
|
|
90
|
-
__name(isSdjwtVcPayload, "isSdjwtVcPayload");
|
|
91
|
-
function getIssuerFromSdJwt(payload) {
|
|
92
|
-
let issuer;
|
|
93
|
-
if (isSdjwtVcPayload(payload) || "iss" in payload) {
|
|
94
|
-
issuer = payload.iss;
|
|
95
|
-
} else if (isVcdm2SdJwtPayload(payload) || "issuer" in payload && payload.issuer) {
|
|
96
|
-
issuer = typeof payload.issuer === "string" ? payload.issuer : payload.issuer?.id;
|
|
97
|
-
}
|
|
98
|
-
if (!issuer) {
|
|
99
|
-
throw new Error("No issuer (iss or VCDM 2 issuer) found in SD-JWT or no VCDM2 SD-JWT or SD-JWT VC");
|
|
100
|
-
}
|
|
101
|
-
return issuer;
|
|
102
|
-
}
|
|
103
|
-
__name(getIssuerFromSdJwt, "getIssuerFromSdJwt");
|
|
104
|
-
|
|
105
31
|
// src/sdJwtVcdm2Instance.ts
|
|
106
32
|
import { SDJwtInstance } from "@sd-jwt/core";
|
|
107
33
|
import { SDJWTException } from "@sd-jwt/utils";
|
|
@@ -261,9 +187,99 @@ function toVcdm2Date(value) {
|
|
|
261
187
|
}
|
|
262
188
|
__name(toVcdm2Date, "toVcdm2Date");
|
|
263
189
|
|
|
264
|
-
// src/
|
|
190
|
+
// src/trustAnchors.ts
|
|
191
|
+
var funkeTestCA = "-----BEGIN CERTIFICATE-----\nMIICeTCCAiCgAwIBAgIUB5E9QVZtmUYcDtCjKB/H3VQv72gwCgYIKoZIzj0EAwIwgYgxCzAJBgNVBAYTAkRFMQ8wDQYDVQQHDAZCZXJsaW4xHTAbBgNVBAoMFEJ1bmRlc2RydWNrZXJlaSBHbWJIMREwDwYDVQQLDAhUIENTIElERTE2MDQGA1UEAwwtU1BSSU5EIEZ1bmtlIEVVREkgV2FsbGV0IFByb3RvdHlwZSBJc3N1aW5nIENBMB4XDTI0MDUzMTA2NDgwOVoXDTM0MDUyOTA2NDgwOVowgYgxCzAJBgNVBAYTAkRFMQ8wDQYDVQQHDAZCZXJsaW4xHTAbBgNVBAoMFEJ1bmRlc2RydWNrZXJlaSBHbWJIMREwDwYDVQQLDAhUIENTIElERTE2MDQGA1UEAwwtU1BSSU5EIEZ1bmtlIEVVREkgV2FsbGV0IFByb3RvdHlwZSBJc3N1aW5nIENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEYGzdwFDnc7+Kn5ibAvCOM8ke77VQxqfMcwZL8IaIA+WCROcCfmY/giH92qMru5p/kyOivE0RC/IbdMONvDoUyaNmMGQwHQYDVR0OBBYEFNRWGMCJOOgOWIQYyXZiv6u7xZC+MB8GA1UdIwQYMBaAFNRWGMCJOOgOWIQYyXZiv6u7xZC+MBIGA1UdEwEB/wQIMAYBAf8CAQAwDgYDVR0PAQH/BAQDAgGGMAoGCCqGSM49BAMCA0cAMEQCIGEm7wkZKHt/atb4MdFnXW6yrnwMUT2u136gdtl10Y6hAiBuTFqvVYth1rbxzCP0xWZHmQK9kVyxn8GPfX27EIzzsw==\n-----END CERTIFICATE-----";
|
|
192
|
+
var sphereonCA = "-----BEGIN CERTIFICATE-----\nMIICCDCCAa6gAwIBAgITAPMgqwtYzWPBXaobHhxG9iSydTAKBggqhkjOPQQDAjBa\nMQswCQYDVQQGEwJOTDEkMCIGA1UECgwbU3BoZXJlb24gSW50ZXJuYXRpb25hbCBC\nLlYuMQswCQYDVQQLDAJJVDEYMBYGA1UEAwwPY2Euc3BoZXJlb24uY29tMB4XDTI0\nMDcyODIxMjY0OVoXDTM0MDcyODIxMjY0OVowWjELMAkGA1UEBhMCTkwxJDAiBgNV\nBAoMG1NwaGVyZW9uIEludGVybmF0aW9uYWwgQi5WLjELMAkGA1UECwwCSVQxGDAW\nBgNVBAMMD2NhLnNwaGVyZW9uLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IA\nBEiA0KeESSNrOcmCDga8YsBkUTgowZGwqvL2n91JUpAMdRSwvlVFdqdiLXnk2pQq\nT1vZnDG0I+x+iz2EbdsG0aajUzBRMB0GA1UdDgQWBBTnB8pdlVz5yKD+zuNkRR6A\nsywywTAOBgNVHQ8BAf8EBAMCAaYwDwYDVR0lBAgwBgYEVR0lADAPBgNVHRMBAf8E\nBTADAQH/MAoGCCqGSM49BAMCA0gAMEUCIHH7ie1OAAbff5262rzZVQa8J9zENG8A\nQlHHFydMdgaXAiEA1Ib82mhHIYDziE0DDbHEAXOs98al+7dpo8fPGVGTeKI=\n-----END CERTIFICATE-----";
|
|
193
|
+
|
|
194
|
+
// src/utils.ts
|
|
265
195
|
import * as u8a from "uint8arrays";
|
|
196
|
+
import { toString as toString2 } from "uint8arrays/to-string";
|
|
197
|
+
async function fetchUrlWithErrorHandling(url) {
|
|
198
|
+
const response = await fetch(url);
|
|
199
|
+
if (!response.ok) {
|
|
200
|
+
throw new Error(`${response.status}: ${response.statusText}`);
|
|
201
|
+
}
|
|
202
|
+
return response;
|
|
203
|
+
}
|
|
204
|
+
__name(fetchUrlWithErrorHandling, "fetchUrlWithErrorHandling");
|
|
205
|
+
function extractHashAlgFromIntegrity(integrityValue) {
|
|
206
|
+
const val = integrityValue?.toLowerCase().trim().split("-")[0];
|
|
207
|
+
if (val === "sha256" || val === "sha384" || val === "sha512") {
|
|
208
|
+
return val;
|
|
209
|
+
}
|
|
210
|
+
return void 0;
|
|
211
|
+
}
|
|
212
|
+
__name(extractHashAlgFromIntegrity, "extractHashAlgFromIntegrity");
|
|
213
|
+
function extractHashFromIntegrity(integrityValue) {
|
|
214
|
+
return integrityValue?.toLowerCase().trim().split("-")[1];
|
|
215
|
+
}
|
|
216
|
+
__name(extractHashFromIntegrity, "extractHashFromIntegrity");
|
|
217
|
+
async function validateIntegrity({ input, integrityValue, hasher }) {
|
|
218
|
+
if (!integrityValue) {
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
const alg = extractHashAlgFromIntegrity(integrityValue);
|
|
222
|
+
if (!alg) {
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
const calculatedHash = await createIntegrity({
|
|
226
|
+
hasher,
|
|
227
|
+
input,
|
|
228
|
+
alg
|
|
229
|
+
});
|
|
230
|
+
return calculatedHash == integrityValue;
|
|
231
|
+
}
|
|
232
|
+
__name(validateIntegrity, "validateIntegrity");
|
|
233
|
+
async function createIntegrity({ input, hasher, alg = "sha256" }) {
|
|
234
|
+
const calculatedHash = await hasher(typeof input === "string" ? input : JSON.stringify(input), alg);
|
|
235
|
+
return `${alg}-${toString2(calculatedHash, "base64")}`;
|
|
236
|
+
}
|
|
237
|
+
__name(createIntegrity, "createIntegrity");
|
|
238
|
+
function assertValidTypeMetadata(metadata, vct) {
|
|
239
|
+
if (metadata.vct !== vct) {
|
|
240
|
+
throw new Error("VCT mismatch in metadata and credential");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
__name(assertValidTypeMetadata, "assertValidTypeMetadata");
|
|
244
|
+
function isVcdm2SdJwtPayload(payload) {
|
|
245
|
+
return "type" in payload && Array.isArray(payload.type) && payload.type.includes("VerifiableCredential") && "@context" in payload && (typeof payload["@context"] === "string" && payload["@context"].length > 0 || Array.isArray(payload["@context"]) && payload["@context"].length > 0 && payload["@context"].includes("https://www.w3.org/ns/credentials/v2"));
|
|
246
|
+
}
|
|
247
|
+
__name(isVcdm2SdJwtPayload, "isVcdm2SdJwtPayload");
|
|
248
|
+
function isSdjwtVcPayload(payload) {
|
|
249
|
+
return !isVcdm2SdJwtPayload(payload) && "vct" in payload && typeof payload.vct === "string";
|
|
250
|
+
}
|
|
251
|
+
__name(isSdjwtVcPayload, "isSdjwtVcPayload");
|
|
252
|
+
function getIssuerFromSdJwt(payload) {
|
|
253
|
+
let issuer;
|
|
254
|
+
if (isSdjwtVcPayload(payload) || "iss" in payload) {
|
|
255
|
+
issuer = payload.iss;
|
|
256
|
+
} else if (isVcdm2SdJwtPayload(payload) || "issuer" in payload && payload.issuer) {
|
|
257
|
+
issuer = typeof payload.issuer === "string" ? payload.issuer : payload.issuer?.id;
|
|
258
|
+
}
|
|
259
|
+
if (!issuer) {
|
|
260
|
+
throw new Error("No issuer (iss or VCDM 2 issuer) found in SD-JWT or no VCDM2 SD-JWT or SD-JWT VC");
|
|
261
|
+
}
|
|
262
|
+
return issuer;
|
|
263
|
+
}
|
|
264
|
+
__name(getIssuerFromSdJwt, "getIssuerFromSdJwt");
|
|
265
|
+
function calculateSdHash(compactSdJwtVc, alg, hasher) {
|
|
266
|
+
const digest = hasher(compactSdJwtVc, alg);
|
|
267
|
+
return u8a.toString(digest, "base64url");
|
|
268
|
+
}
|
|
269
|
+
__name(calculateSdHash, "calculateSdHash");
|
|
270
|
+
|
|
271
|
+
// src/action-handler.ts
|
|
266
272
|
var debug = Debug("@sphereon/ssi-sdk.sd-jwt");
|
|
273
|
+
var matchVerificationMethodByKid = /* @__PURE__ */ __name((verificationMethod, kid) => {
|
|
274
|
+
if (!kid) return false;
|
|
275
|
+
if (verificationMethod.id === kid) {
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
if (verificationMethod.id.endsWith(kid)) {
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
return verificationMethod.id.endsWith(`#${kid}`);
|
|
282
|
+
}, "matchVerificationMethodByKid");
|
|
267
283
|
var SDJwtPlugin = class {
|
|
268
284
|
static {
|
|
269
285
|
__name(this, "SDJwtPlugin");
|
|
@@ -599,7 +615,7 @@ var SDJwtPlugin = class {
|
|
|
599
615
|
const header = decodedVC.jwt.header;
|
|
600
616
|
const x5c = header?.x5c;
|
|
601
617
|
let jwk = header.jwk;
|
|
602
|
-
if (x5c) {
|
|
618
|
+
if (x5c?.length) {
|
|
603
619
|
const trustAnchors = /* @__PURE__ */ new Set([
|
|
604
620
|
...this.trustAnchorsInPEM
|
|
605
621
|
]);
|
|
@@ -629,7 +645,7 @@ var SDJwtPlugin = class {
|
|
|
629
645
|
if (!didDoc) {
|
|
630
646
|
throw new Error("invalid_issuer: issuer did not resolve to a did document");
|
|
631
647
|
}
|
|
632
|
-
const didDocumentKey = didDoc.didDocument?.verificationMethod?.find((key) => key.
|
|
648
|
+
const didDocumentKey = didDoc.didDocument?.verificationMethod?.find((key) => matchVerificationMethodByKid(key, header.kid));
|
|
633
649
|
if (!didDocumentKey) {
|
|
634
650
|
throw new Error("invalid_issuer: issuer did document does not include referenced key");
|
|
635
651
|
}
|
|
@@ -642,7 +658,7 @@ var SDJwtPlugin = class {
|
|
|
642
658
|
if (!didDoc) {
|
|
643
659
|
throw new Error("invalid_issuer: issuer did not resolve to a did document");
|
|
644
660
|
}
|
|
645
|
-
const didDocumentKey = didDoc.didDocument?.verificationMethod?.find((key) => key.
|
|
661
|
+
const didDocumentKey = didDoc.didDocument?.verificationMethod?.find((key) => matchVerificationMethodByKid(key, header.kid));
|
|
646
662
|
if (!didDocumentKey) {
|
|
647
663
|
throw new Error("invalid_issuer: issuer did document does not include referenced key");
|
|
648
664
|
}
|
|
@@ -743,7 +759,7 @@ var SDJwtPlugin = class {
|
|
|
743
759
|
return payload.cnf.jwk;
|
|
744
760
|
} else if (payload.cnf !== void 0 && "kid" in payload.cnf && typeof payload.cnf.kid === "string" && payload.cnf.kid.startsWith("did:jwk:")) {
|
|
745
761
|
const encoded = this.extractBase64FromDIDJwk(payload.cnf.kid);
|
|
746
|
-
const decoded =
|
|
762
|
+
const decoded = u8a2.toString(u8a2.fromString(encoded, "base64url"), "utf-8");
|
|
747
763
|
const jwt = JSON.parse(decoded);
|
|
748
764
|
return jwt;
|
|
749
765
|
}
|
|
@@ -760,6 +776,7 @@ var SDJwtPlugin = class {
|
|
|
760
776
|
export {
|
|
761
777
|
SDJwtPlugin,
|
|
762
778
|
assertValidTypeMetadata,
|
|
779
|
+
calculateSdHash,
|
|
763
780
|
contextHasSDJwtPlugin,
|
|
764
781
|
createIntegrity,
|
|
765
782
|
defaultGenerateDigest,
|