@sphereon/ssi-sdk.sd-jwt 0.36.1-feature.integration.fides.88 → 0.36.1-feature.vdx24.einvoice.endpoints.122
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 +94 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -43
- package/dist/index.d.ts +43 -43
- package/dist/index.js +94 -84
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
- package/src/action-handler.ts +49 -14
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,52 @@
|
|
|
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 {
|
|
6
|
+
import { SDJwtInstance, VerifierOptions, SdJwtPayload } from '@sd-jwt/core';
|
|
7
7
|
import { ManagedIdentifierResult, IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution';
|
|
8
8
|
import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service';
|
|
9
9
|
import { ImDLMdoc } from '@sphereon/ssi-sdk.mdl-mdoc';
|
|
10
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
|
+
}
|
|
49
|
+
|
|
11
50
|
declare const sdJwtPluginContextMethods: Array<string>;
|
|
12
51
|
/**
|
|
13
52
|
* My Agent Plugin description.
|
|
@@ -253,45 +292,6 @@ type PartialSdJwtKbJwt = {
|
|
|
253
292
|
payload: Partial<SdJwtVcKbJwtPayload>;
|
|
254
293
|
};
|
|
255
294
|
|
|
256
|
-
interface SdJwtVcdm2VerificationResult extends Omit<VerificationResult, 'payload'> {
|
|
257
|
-
payload: SdJwtVcdm2Payload;
|
|
258
|
-
}
|
|
259
|
-
declare class SDJwtVcdm2Instance extends SDJwtInstance<SdJwtVcdm2Payload> {
|
|
260
|
-
/**
|
|
261
|
-
* The type of the SD-JWT VCDM2 set in the header.typ field.
|
|
262
|
-
*/
|
|
263
|
-
protected static type: string;
|
|
264
|
-
protected userConfig: SDJWTVCDM2Config;
|
|
265
|
-
constructor(userConfig?: SDJWTVCDM2Config);
|
|
266
|
-
/**
|
|
267
|
-
* Validates if the disclosureFrame contains any reserved fields. If so it will throw an error.
|
|
268
|
-
* @param disclosureFrame
|
|
269
|
-
*/
|
|
270
|
-
protected validateReservedFields(disclosureFrame: DisclosureFrame<SdJwtVcdm2Payload>): void;
|
|
271
|
-
/**
|
|
272
|
-
* Verifies the SD-JWT-VC. It will validate the signature, the keybindings when required, the status, and the VCT.
|
|
273
|
-
* @param encodedSDJwt
|
|
274
|
-
* @param options
|
|
275
|
-
*/
|
|
276
|
-
verify(encodedSDJwt: string, options?: VerifierOptions): Promise<SdJwtVcdm2VerificationResult>;
|
|
277
|
-
/**
|
|
278
|
-
* Validates the integrity of the response if the integrity is passed. If the integrity does not match, an error is thrown.
|
|
279
|
-
* @param integrity
|
|
280
|
-
* @param response
|
|
281
|
-
*/
|
|
282
|
-
private validateIntegrity;
|
|
283
|
-
/**
|
|
284
|
-
* Fetches the content from the url with a timeout of 10 seconds.
|
|
285
|
-
* @param url
|
|
286
|
-
* @param integrity
|
|
287
|
-
* @returns
|
|
288
|
-
*/
|
|
289
|
-
protected fetch<T>(url: string, integrity?: string): Promise<T>;
|
|
290
|
-
issue<Payload extends SdJwtVcdm2Payload>(payload: Payload, disclosureFrame?: DisclosureFrame<Payload>, options?: {
|
|
291
|
-
header?: object;
|
|
292
|
-
}): Promise<SDJWTCompact>;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
295
|
/**
|
|
296
296
|
* @beta
|
|
297
297
|
* SD-JWT plugin
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,52 @@
|
|
|
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 {
|
|
6
|
+
import { SDJwtInstance, VerifierOptions, SdJwtPayload } from '@sd-jwt/core';
|
|
7
7
|
import { ManagedIdentifierResult, IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution';
|
|
8
8
|
import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service';
|
|
9
9
|
import { ImDLMdoc } from '@sphereon/ssi-sdk.mdl-mdoc';
|
|
10
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
|
+
}
|
|
49
|
+
|
|
11
50
|
declare const sdJwtPluginContextMethods: Array<string>;
|
|
12
51
|
/**
|
|
13
52
|
* My Agent Plugin description.
|
|
@@ -253,45 +292,6 @@ type PartialSdJwtKbJwt = {
|
|
|
253
292
|
payload: Partial<SdJwtVcKbJwtPayload>;
|
|
254
293
|
};
|
|
255
294
|
|
|
256
|
-
interface SdJwtVcdm2VerificationResult extends Omit<VerificationResult, 'payload'> {
|
|
257
|
-
payload: SdJwtVcdm2Payload;
|
|
258
|
-
}
|
|
259
|
-
declare class SDJwtVcdm2Instance extends SDJwtInstance<SdJwtVcdm2Payload> {
|
|
260
|
-
/**
|
|
261
|
-
* The type of the SD-JWT VCDM2 set in the header.typ field.
|
|
262
|
-
*/
|
|
263
|
-
protected static type: string;
|
|
264
|
-
protected userConfig: SDJWTVCDM2Config;
|
|
265
|
-
constructor(userConfig?: SDJWTVCDM2Config);
|
|
266
|
-
/**
|
|
267
|
-
* Validates if the disclosureFrame contains any reserved fields. If so it will throw an error.
|
|
268
|
-
* @param disclosureFrame
|
|
269
|
-
*/
|
|
270
|
-
protected validateReservedFields(disclosureFrame: DisclosureFrame<SdJwtVcdm2Payload>): void;
|
|
271
|
-
/**
|
|
272
|
-
* Verifies the SD-JWT-VC. It will validate the signature, the keybindings when required, the status, and the VCT.
|
|
273
|
-
* @param encodedSDJwt
|
|
274
|
-
* @param options
|
|
275
|
-
*/
|
|
276
|
-
verify(encodedSDJwt: string, options?: VerifierOptions): Promise<SdJwtVcdm2VerificationResult>;
|
|
277
|
-
/**
|
|
278
|
-
* Validates the integrity of the response if the integrity is passed. If the integrity does not match, an error is thrown.
|
|
279
|
-
* @param integrity
|
|
280
|
-
* @param response
|
|
281
|
-
*/
|
|
282
|
-
private validateIntegrity;
|
|
283
|
-
/**
|
|
284
|
-
* Fetches the content from the url with a timeout of 10 seconds.
|
|
285
|
-
* @param url
|
|
286
|
-
* @param integrity
|
|
287
|
-
* @returns
|
|
288
|
-
*/
|
|
289
|
-
protected fetch<T>(url: string, integrity?: string): Promise<T>;
|
|
290
|
-
issue<Payload extends SdJwtVcdm2Payload>(payload: Payload, disclosureFrame?: DisclosureFrame<Payload>, options?: {
|
|
291
|
-
header?: object;
|
|
292
|
-
}): Promise<SDJWTCompact>;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
295
|
/**
|
|
296
296
|
* @beta
|
|
297
297
|
* SD-JWT plugin
|
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,87 +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/H3VQv72gwCgYIKoZIzj0EAwIwgYgxCzAJBgNVBAYTAkRFMQ8wDQYDVQQHDAZCZXJsaW4xHTAbBgNVBAoMFEJ1bmRlc2RydWNrZXJlaSBHbWJIMREwDwYDVQQLDAhUIENTIElERTE2MDQGA1UEAwwtU1BSSU5EIEZ1bmtlIEVVREkgV2FsbGV0IFByb3RvdHlwZSBJc3N1aW5nIENBMB4XDTI0MDUzMTA2NDgwOVoXDTM0MDU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wvlVFdqdiLXnk2pQq\nT1vZnDG0I+x+iz2EbdsG0aajUzBRMB0GA1UdDgQWBBTnB8pdlVz5yKD+zuNkRR6A\nsywywTAOBgNVHQ8BAf8EBAMCAaYwDwYDVR0lBAgwBgYEVR0lADAPBgNVHRMBAf8E\nBTADAQH/MAoGCCqGSM49BAMCA0gAMEUCIHH7ie1OAAbff5262rzZVQa8J9zENG8A\nQlHHFydMdgaXAiEA1Ib82mhHIYDziE0DDbHEAXOs98al+7dpo8fPGVGTeKI=\n-----END CERTIFICATE-----";
|
|
33
|
-
|
|
34
|
-
// src/utils.ts
|
|
35
|
-
import * as u8a from "uint8arrays";
|
|
36
|
-
import { toString as toString2 } from "uint8arrays/to-string";
|
|
37
|
-
async function fetchUrlWithErrorHandling(url) {
|
|
38
|
-
const response = await fetch(url);
|
|
39
|
-
if (!response.ok) {
|
|
40
|
-
throw new Error(`${response.status}: ${response.statusText}`);
|
|
41
|
-
}
|
|
42
|
-
return response;
|
|
43
|
-
}
|
|
44
|
-
__name(fetchUrlWithErrorHandling, "fetchUrlWithErrorHandling");
|
|
45
|
-
function extractHashAlgFromIntegrity(integrityValue) {
|
|
46
|
-
const val = integrityValue?.toLowerCase().trim().split("-")[0];
|
|
47
|
-
if (val === "sha256" || val === "sha384" || val === "sha512") {
|
|
48
|
-
return val;
|
|
49
|
-
}
|
|
50
|
-
return void 0;
|
|
51
|
-
}
|
|
52
|
-
__name(extractHashAlgFromIntegrity, "extractHashAlgFromIntegrity");
|
|
53
|
-
function extractHashFromIntegrity(integrityValue) {
|
|
54
|
-
return integrityValue?.toLowerCase().trim().split("-")[1];
|
|
55
|
-
}
|
|
56
|
-
__name(extractHashFromIntegrity, "extractHashFromIntegrity");
|
|
57
|
-
async function validateIntegrity({ input, integrityValue, hasher }) {
|
|
58
|
-
if (!integrityValue) {
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
const alg = extractHashAlgFromIntegrity(integrityValue);
|
|
62
|
-
if (!alg) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
const calculatedHash = await createIntegrity({
|
|
66
|
-
hasher,
|
|
67
|
-
input,
|
|
68
|
-
alg
|
|
69
|
-
});
|
|
70
|
-
return calculatedHash == integrityValue;
|
|
71
|
-
}
|
|
72
|
-
__name(validateIntegrity, "validateIntegrity");
|
|
73
|
-
async function createIntegrity({ input, hasher, alg = "sha256" }) {
|
|
74
|
-
const calculatedHash = await hasher(typeof input === "string" ? input : JSON.stringify(input), alg);
|
|
75
|
-
return `${alg}-${toString2(calculatedHash, "base64")}`;
|
|
76
|
-
}
|
|
77
|
-
__name(createIntegrity, "createIntegrity");
|
|
78
|
-
function assertValidTypeMetadata(metadata, vct) {
|
|
79
|
-
if (metadata.vct !== vct) {
|
|
80
|
-
throw new Error("VCT mismatch in metadata and credential");
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
__name(assertValidTypeMetadata, "assertValidTypeMetadata");
|
|
84
|
-
function isVcdm2SdJwtPayload(payload) {
|
|
85
|
-
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"));
|
|
86
|
-
}
|
|
87
|
-
__name(isVcdm2SdJwtPayload, "isVcdm2SdJwtPayload");
|
|
88
|
-
function isSdjwtVcPayload(payload) {
|
|
89
|
-
return !isVcdm2SdJwtPayload(payload) && "vct" in payload && typeof payload.vct === "string";
|
|
90
|
-
}
|
|
91
|
-
__name(isSdjwtVcPayload, "isSdjwtVcPayload");
|
|
92
|
-
function getIssuerFromSdJwt(payload) {
|
|
93
|
-
let issuer;
|
|
94
|
-
if (isSdjwtVcPayload(payload) || "iss" in payload) {
|
|
95
|
-
issuer = payload.iss;
|
|
96
|
-
} else if (isVcdm2SdJwtPayload(payload) || "issuer" in payload && payload.issuer) {
|
|
97
|
-
issuer = typeof payload.issuer === "string" ? payload.issuer : payload.issuer?.id;
|
|
98
|
-
}
|
|
99
|
-
if (!issuer) {
|
|
100
|
-
throw new Error("No issuer (iss or VCDM 2 issuer) found in SD-JWT or no VCDM2 SD-JWT or SD-JWT VC");
|
|
101
|
-
}
|
|
102
|
-
return issuer;
|
|
103
|
-
}
|
|
104
|
-
__name(getIssuerFromSdJwt, "getIssuerFromSdJwt");
|
|
105
|
-
function calculateSdHash(compactSdJwtVc, alg, hasher) {
|
|
106
|
-
const digest = hasher(compactSdJwtVc, alg);
|
|
107
|
-
return u8a.toString(digest, "base64url");
|
|
108
|
-
}
|
|
109
|
-
__name(calculateSdHash, "calculateSdHash");
|
|
110
|
-
|
|
111
31
|
// src/sdJwtVcdm2Instance.ts
|
|
112
32
|
import { SDJwtInstance } from "@sd-jwt/core";
|
|
113
33
|
import { SDJWTException } from "@sd-jwt/utils";
|
|
@@ -267,9 +187,99 @@ function toVcdm2Date(value) {
|
|
|
267
187
|
}
|
|
268
188
|
__name(toVcdm2Date, "toVcdm2Date");
|
|
269
189
|
|
|
190
|
+
// src/trustAnchors.ts
|
|
191
|
+
var funkeTestCA = "-----BEGIN CERTIFICATE-----\nMIICeTCCAiCgAwIBAgIUB5E9QVZtmUYcDtCjKB/H3VQv72gwCgYIKoZIzj0EAwIwgYgxCzAJBgNVBAYTAkRFMQ8wDQYDVQQHDAZCZXJsaW4xHTAbBgNVBAoMFEJ1bmRlc2RydWNrZXJlaSBHbWJIMREwDwYDVQQLDAhUIENTIElERTE2MDQGA1UEAwwtU1BSSU5EIEZ1bmtlIEVVREkgV2FsbGV0IFByb3RvdHlwZSBJc3N1aW5nIENBMB4XDTI0MDUzMTA2NDgwOVoXDTM0MDUyOTA2NDgwOVowgYgxCzAJBgNVBAYTAkRFMQ8wDQYDVQQHDAZCZXJsaW4xHTAbBgNVBAoMFEJ1bmRlc2RydWNrZXJlaSBHbWJIMREwDwYDVQQLDAhUIENTIElERTE2MDQGA1UEAwwtU1BSSU5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MBAf8E\nBTADAQH/MAoGCCqGSM49BAMCA0gAMEUCIHH7ie1OAAbff5262rzZVQa8J9zENG8A\nQlHHFydMdgaXAiEA1Ib82mhHIYDziE0DDbHEAXOs98al+7dpo8fPGVGTeKI=\n-----END CERTIFICATE-----";
|
|
193
|
+
|
|
194
|
+
// src/utils.ts
|
|
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
|
+
|
|
270
271
|
// src/action-handler.ts
|
|
271
|
-
import * as u8a2 from "uint8arrays";
|
|
272
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");
|
|
273
283
|
var SDJwtPlugin = class {
|
|
274
284
|
static {
|
|
275
285
|
__name(this, "SDJwtPlugin");
|
|
@@ -635,7 +645,7 @@ var SDJwtPlugin = class {
|
|
|
635
645
|
if (!didDoc) {
|
|
636
646
|
throw new Error("invalid_issuer: issuer did not resolve to a did document");
|
|
637
647
|
}
|
|
638
|
-
const didDocumentKey = didDoc.didDocument?.verificationMethod?.find((key) => key
|
|
648
|
+
const didDocumentKey = didDoc.didDocument?.verificationMethod?.find((key) => matchVerificationMethodByKid(key, header.kid));
|
|
639
649
|
if (!didDocumentKey) {
|
|
640
650
|
throw new Error("invalid_issuer: issuer did document does not include referenced key");
|
|
641
651
|
}
|
|
@@ -648,7 +658,7 @@ var SDJwtPlugin = class {
|
|
|
648
658
|
if (!didDoc) {
|
|
649
659
|
throw new Error("invalid_issuer: issuer did not resolve to a did document");
|
|
650
660
|
}
|
|
651
|
-
const didDocumentKey = didDoc.didDocument?.verificationMethod?.find((key) => key
|
|
661
|
+
const didDocumentKey = didDoc.didDocument?.verificationMethod?.find((key) => matchVerificationMethodByKid(key, header.kid));
|
|
652
662
|
if (!didDocumentKey) {
|
|
653
663
|
throw new Error("invalid_issuer: issuer did document does not include referenced key");
|
|
654
664
|
}
|