@sphereon/ssi-sdk.sd-jwt 0.36.1-feature.SSISDK.70.integrate.digidentity.57 → 0.36.1-feature.SSISDK.78.41
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 +84 -94
- 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 +84 -94
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
- package/src/action-handler.ts +15 -49
- package/src/defaultCallbacks.ts +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,52 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { SdJwtVcPayload as SdJwtVcPayload$1, VerificationResult, SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
|
|
2
|
+
import { SaltGenerator, KBOptions, kbHeader, kbPayload, Hasher, Signer, DisclosureFrame, SDJWTCompact, HasherSync as HasherSync$1 } from '@sd-jwt/types';
|
|
3
3
|
import { X509CertificateChainValidationOpts } from '@sphereon/ssi-sdk-ext.x509-utils';
|
|
4
|
-
import {
|
|
4
|
+
import { HasherSync, JsonWebKey, SdJwtVcType, SdJwtVpType, SdJwtVcdm2Payload, SdJwtTypeMetadata, JoseSignatureAlgorithm, SdJwtType, SdJwtVcKbJwtHeader, SdJwtVcKbJwtPayload, SDJWTVCDM2Config } from '@sphereon/ssi-types';
|
|
5
5
|
import { IPluginMethodMap, IAgentContext, IDIDManager, IResolver, IKeyManager, DIDDocumentSection, IAgentPlugin } from '@veramo/core';
|
|
6
|
-
import { SDJwtInstance, VerifierOptions
|
|
6
|
+
import { SdJwtPayload, SDJwtInstance, VerifierOptions } 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
|
-
|
|
50
11
|
declare const sdJwtPluginContextMethods: Array<string>;
|
|
51
12
|
/**
|
|
52
13
|
* My Agent Plugin description.
|
|
@@ -292,6 +253,45 @@ type PartialSdJwtKbJwt = {
|
|
|
292
253
|
payload: Partial<SdJwtVcKbJwtPayload>;
|
|
293
254
|
};
|
|
294
255
|
|
|
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,52 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { SdJwtVcPayload as SdJwtVcPayload$1, VerificationResult, SDJwtVcInstance } from '@sd-jwt/sd-jwt-vc';
|
|
2
|
+
import { SaltGenerator, KBOptions, kbHeader, kbPayload, Hasher, Signer, DisclosureFrame, SDJWTCompact, HasherSync as HasherSync$1 } from '@sd-jwt/types';
|
|
3
3
|
import { X509CertificateChainValidationOpts } from '@sphereon/ssi-sdk-ext.x509-utils';
|
|
4
|
-
import {
|
|
4
|
+
import { HasherSync, JsonWebKey, SdJwtVcType, SdJwtVpType, SdJwtVcdm2Payload, SdJwtTypeMetadata, JoseSignatureAlgorithm, SdJwtType, SdJwtVcKbJwtHeader, SdJwtVcKbJwtPayload, SDJWTVCDM2Config } from '@sphereon/ssi-types';
|
|
5
5
|
import { IPluginMethodMap, IAgentContext, IDIDManager, IResolver, IKeyManager, DIDDocumentSection, IAgentPlugin } from '@veramo/core';
|
|
6
|
-
import { SDJwtInstance, VerifierOptions
|
|
6
|
+
import { SdJwtPayload, SDJwtInstance, VerifierOptions } 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
|
-
|
|
50
11
|
declare const sdJwtPluginContextMethods: Array<string>;
|
|
51
12
|
/**
|
|
52
13
|
* My Agent Plugin description.
|
|
@@ -292,6 +253,45 @@ type PartialSdJwtKbJwt = {
|
|
|
292
253
|
payload: Partial<SdJwtVcKbJwtPayload>;
|
|
293
254
|
};
|
|
294
255
|
|
|
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,7 +6,6 @@ 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";
|
|
10
9
|
|
|
11
10
|
// src/defaultCallbacks.ts
|
|
12
11
|
import { digestMethodParams } from "@sphereon/ssi-sdk-ext.key-utils";
|
|
@@ -28,6 +27,87 @@ var defaultVerifySignature = /* @__PURE__ */ __name((context) => async (data, si
|
|
|
28
27
|
return !result.error;
|
|
29
28
|
}, "defaultVerifySignature");
|
|
30
29
|
|
|
30
|
+
// src/trustAnchors.ts
|
|
31
|
+
var funkeTestCA = "-----BEGIN CERTIFICATE-----\nMIICeTCCAiCgAwIBAgIUB5E9QVZtmUYcDtCjKB/H3VQv72gwCgYIKoZIzj0EAwIwgYgxCzAJBgNVBAYTAkRFMQ8wDQYDVQQHDAZCZXJsaW4xHTAbBgNVBAoMFEJ1bmRlc2RydWNrZXJlaSBHbWJIMREwDwYDVQQLDAhUIENTIElERTE2MDQGA1UEAwwtU1BSSU5EIEZ1bmtlIEVVREkgV2FsbGV0IFByb3RvdHlwZSBJc3N1aW5nIENBMB4XDTI0MDUzMTA2NDgwOVoXDTM0MDUyOTA2NDgwOVowgYgxCzAJBgNVBAYTAkRFMQ8wDQYDVQQHDAZCZXJsaW4xHTAbBgNVBAoMFEJ1bmRlc2RydWNrZXJlaSBHbWJIMREwDwYDVQQLDAhUIENTIElERTE2MDQ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gYEVR0lADAPBgNVHRMBAf8E\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
|
+
|
|
31
111
|
// src/sdJwtVcdm2Instance.ts
|
|
32
112
|
import { SDJwtInstance } from "@sd-jwt/core";
|
|
33
113
|
import { SDJWTException } from "@sd-jwt/utils";
|
|
@@ -187,99 +267,9 @@ function toVcdm2Date(value) {
|
|
|
187
267
|
}
|
|
188
268
|
__name(toVcdm2Date, "toVcdm2Date");
|
|
189
269
|
|
|
190
|
-
// src/trustAnchors.ts
|
|
191
|
-
var funkeTestCA = "-----BEGIN CERTIFICATE-----\nMIICeTCCAiCgAwIBAgIUB5E9QVZtmUYcDtCjKB/H3VQv72gwCgYIKoZIzj0EAwIwgYgxCzAJBgNVBAYTAkRFMQ8wDQYDVQQHDAZCZXJsaW4xHTAbBgNVBAoMFEJ1bmRlc2RydWNrZXJlaSBHbWJIMREwDwYDVQQLDAhUIENTIElERTE2MDQGA1UEAwwtU1BSSU5EIEZ1bmtlIEVVREkgV2FsbGV0IFByb3RvdHlwZSBJc3N1aW5nIENBMB4XDTI0MDUzMTA2NDgwOVoXDTM0MDUyOTA2NDgwOVowgYgxCzAJBgNVBAYTAkRFMQ8wDQYDVQQHDAZCZXJsaW4xHTAbBgNVBAoMFEJ1bmRlc2RydWNrZXJlaSBHbWJIMREwDwYDVQQLDAhUIENTIElERTE2MDQGA1UEAwwtU1BSSU5EIEZ1bmtlIEVVREkgV2FsbGV0IFByb3RvdHlwZSBJc3N1aW5nIENBMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEYGzdwFDnc7+Kn5ibAvCOM8ke77VQxqfMcwZL8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\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
|
-
|
|
271
270
|
// 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");
|
|
283
273
|
var SDJwtPlugin = class {
|
|
284
274
|
static {
|
|
285
275
|
__name(this, "SDJwtPlugin");
|
|
@@ -645,7 +635,7 @@ var SDJwtPlugin = class {
|
|
|
645
635
|
if (!didDoc) {
|
|
646
636
|
throw new Error("invalid_issuer: issuer did not resolve to a did document");
|
|
647
637
|
}
|
|
648
|
-
const didDocumentKey = didDoc.didDocument?.verificationMethod?.find((key) =>
|
|
638
|
+
const didDocumentKey = didDoc.didDocument?.verificationMethod?.find((key) => key.id);
|
|
649
639
|
if (!didDocumentKey) {
|
|
650
640
|
throw new Error("invalid_issuer: issuer did document does not include referenced key");
|
|
651
641
|
}
|
|
@@ -658,7 +648,7 @@ var SDJwtPlugin = class {
|
|
|
658
648
|
if (!didDoc) {
|
|
659
649
|
throw new Error("invalid_issuer: issuer did not resolve to a did document");
|
|
660
650
|
}
|
|
661
|
-
const didDocumentKey = didDoc.didDocument?.verificationMethod?.find((key) =>
|
|
651
|
+
const didDocumentKey = didDoc.didDocument?.verificationMethod?.find((key) => key.id);
|
|
662
652
|
if (!didDocumentKey) {
|
|
663
653
|
throw new Error("invalid_issuer: issuer did document does not include referenced key");
|
|
664
654
|
}
|