@sphereon/oid4vc-common 0.17.0 → 0.17.1-feature.esm.cjs.25

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.
Files changed (81) hide show
  1. package/dist/index.cjs +485 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +297 -0
  4. package/dist/index.d.ts +296 -8
  5. package/dist/index.js +425 -26
  6. package/dist/index.js.map +1 -1
  7. package/package.json +22 -13
  8. package/dist/dpop/DPoP.d.ts +0 -60
  9. package/dist/dpop/DPoP.d.ts.map +0 -1
  10. package/dist/dpop/DPoP.js +0 -184
  11. package/dist/dpop/DPoP.js.map +0 -1
  12. package/dist/dpop/index.d.ts +0 -2
  13. package/dist/dpop/index.d.ts.map +0 -1
  14. package/dist/dpop/index.js +0 -18
  15. package/dist/dpop/index.js.map +0 -1
  16. package/dist/hasher.d.ts +0 -3
  17. package/dist/hasher.d.ts.map +0 -1
  18. package/dist/hasher.js +0 -19
  19. package/dist/hasher.js.map +0 -1
  20. package/dist/index.d.ts.map +0 -1
  21. package/dist/jwt/Jwk.types.d.ts +0 -36
  22. package/dist/jwt/Jwk.types.d.ts.map +0 -1
  23. package/dist/jwt/Jwk.types.js +0 -3
  24. package/dist/jwt/Jwk.types.js.map +0 -1
  25. package/dist/jwt/JwkThumbprint.d.ts +0 -6
  26. package/dist/jwt/JwkThumbprint.d.ts.map +0 -1
  27. package/dist/jwt/JwkThumbprint.js +0 -102
  28. package/dist/jwt/JwkThumbprint.js.map +0 -1
  29. package/dist/jwt/Jwt.types.d.ts +0 -23
  30. package/dist/jwt/Jwt.types.d.ts.map +0 -1
  31. package/dist/jwt/Jwt.types.js +0 -12
  32. package/dist/jwt/Jwt.types.js.map +0 -1
  33. package/dist/jwt/JwtIssuer.d.ts +0 -51
  34. package/dist/jwt/JwtIssuer.d.ts.map +0 -1
  35. package/dist/jwt/JwtIssuer.js +0 -3
  36. package/dist/jwt/JwtIssuer.js.map +0 -1
  37. package/dist/jwt/JwtVerifier.d.ts +0 -72
  38. package/dist/jwt/JwtVerifier.d.ts.map +0 -1
  39. package/dist/jwt/JwtVerifier.js +0 -80
  40. package/dist/jwt/JwtVerifier.js.map +0 -1
  41. package/dist/jwt/index.d.ts +0 -7
  42. package/dist/jwt/index.d.ts.map +0 -1
  43. package/dist/jwt/index.js +0 -23
  44. package/dist/jwt/index.js.map +0 -1
  45. package/dist/jwt/jwtUtils.d.ts +0 -26
  46. package/dist/jwt/jwtUtils.d.ts.map +0 -1
  47. package/dist/jwt/jwtUtils.js +0 -62
  48. package/dist/jwt/jwtUtils.js.map +0 -1
  49. package/dist/oauth/DynamicClientRegistration.types.d.ts +0 -19
  50. package/dist/oauth/DynamicClientRegistration.types.d.ts.map +0 -1
  51. package/dist/oauth/DynamicClientRegistration.types.js +0 -3
  52. package/dist/oauth/DynamicClientRegistration.types.js.map +0 -1
  53. package/dist/oauth/index.d.ts +0 -2
  54. package/dist/oauth/index.d.ts.map +0 -1
  55. package/dist/oauth/index.js +0 -18
  56. package/dist/oauth/index.js.map +0 -1
  57. package/dist/types/digest.types.d.ts +0 -2
  58. package/dist/types/digest.types.d.ts.map +0 -1
  59. package/dist/types/digest.types.js +0 -3
  60. package/dist/types/digest.types.js.map +0 -1
  61. package/dist/types/index.d.ts +0 -2
  62. package/dist/types/index.d.ts.map +0 -1
  63. package/dist/types/index.js +0 -18
  64. package/dist/types/index.js.map +0 -1
  65. package/lib/__tests__/dpop.spec.ts +0 -124
  66. package/lib/dpop/DPoP.ts +0 -242
  67. package/lib/dpop/index.ts +0 -1
  68. package/lib/hasher.ts +0 -18
  69. package/lib/index.ts +0 -11
  70. package/lib/jwt/Jwk.types.ts +0 -38
  71. package/lib/jwt/JwkThumbprint.ts +0 -65
  72. package/lib/jwt/Jwt.types.ts +0 -26
  73. package/lib/jwt/JwtIssuer.ts +0 -60
  74. package/lib/jwt/JwtVerifier.ts +0 -130
  75. package/lib/jwt/__tests__/JwkThumbprint.spec.ts +0 -16
  76. package/lib/jwt/index.ts +0 -6
  77. package/lib/jwt/jwtUtils.ts +0 -71
  78. package/lib/oauth/DynamicClientRegistration.types.ts +0 -20
  79. package/lib/oauth/index.ts +0 -1
  80. package/lib/types/digest.types.ts +0 -1
  81. package/lib/types/index.ts +0 -1
package/dist/index.js CHANGED
@@ -1,28 +1,427 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // lib/index.ts
5
+ import { Loggers } from "@sphereon/ssi-types";
6
+
7
+ // lib/jwt/Jwt.types.ts
8
+ var SigningAlgo = /* @__PURE__ */ function(SigningAlgo2) {
9
+ SigningAlgo2["EDDSA"] = "EdDSA";
10
+ SigningAlgo2["RS256"] = "RS256";
11
+ SigningAlgo2["PS256"] = "PS256";
12
+ SigningAlgo2["ES256"] = "ES256";
13
+ SigningAlgo2["ES256K"] = "ES256K";
14
+ return SigningAlgo2;
15
+ }({});
16
+
17
+ // lib/jwt/JwkThumbprint.ts
18
+ import * as u8a2 from "uint8arrays";
19
+
20
+ // lib/hasher.ts
21
+ import sha from "sha.js";
22
+ import * as u8a from "uint8arrays";
23
+ var supportedAlgorithms = [
24
+ "sha256",
25
+ "sha384",
26
+ "sha512"
27
+ ];
28
+ var defaultHasher = /* @__PURE__ */ __name((data, algorithm) => {
29
+ const sanitizedAlgorithm = algorithm.toLowerCase().replace(/[-_]/g, "");
30
+ if (!supportedAlgorithms.includes(sanitizedAlgorithm)) {
31
+ throw new Error(`Unsupported hashing algorithm ${algorithm}`);
32
+ }
33
+ return new Uint8Array(sha(sanitizedAlgorithm).update(typeof data === "string" ? u8a.fromString(data) : data).digest());
34
+ }, "defaultHasher");
35
+
36
+ // lib/jwt/JwkThumbprint.ts
37
+ var check = /* @__PURE__ */ __name((value, description) => {
38
+ if (typeof value !== "string" || !value) {
39
+ throw Error(`${description} missing or invalid`);
40
+ }
41
+ }, "check");
42
+ async function calculateJwkThumbprint(jwk, digestAlgorithm) {
43
+ if (!jwk || typeof jwk !== "object") {
44
+ throw new TypeError("JWK must be an object");
45
+ }
46
+ const algorithm = digestAlgorithm ?? "sha256";
47
+ if (algorithm !== "sha256" && algorithm !== "sha384" && algorithm !== "sha512") {
48
+ throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');
49
+ }
50
+ let components;
51
+ switch (jwk.kty) {
52
+ case "EC":
53
+ check(jwk.crv, '"crv" (Curve) Parameter');
54
+ check(jwk.x, '"x" (X Coordinate) Parameter');
55
+ check(jwk.y, '"y" (Y Coordinate) Parameter');
56
+ components = {
57
+ crv: jwk.crv,
58
+ kty: jwk.kty,
59
+ x: jwk.x,
60
+ y: jwk.y
61
+ };
62
+ break;
63
+ case "OKP":
64
+ check(jwk.crv, '"crv" (Subtype of Key Pair) Parameter');
65
+ check(jwk.x, '"x" (Public Key) Parameter');
66
+ components = {
67
+ crv: jwk.crv,
68
+ kty: jwk.kty,
69
+ x: jwk.x
70
+ };
71
+ break;
72
+ case "RSA":
73
+ check(jwk.e, '"e" (Exponent) Parameter');
74
+ check(jwk.n, '"n" (Modulus) Parameter');
75
+ components = {
76
+ e: jwk.e,
77
+ kty: jwk.kty,
78
+ n: jwk.n
79
+ };
80
+ break;
81
+ case "oct":
82
+ check(jwk.k, '"k" (Key Value) Parameter');
83
+ components = {
84
+ k: jwk.k,
85
+ kty: jwk.kty
86
+ };
87
+ break;
88
+ default:
89
+ throw Error('"kty" (Key Type) Parameter missing or unsupported');
90
+ }
91
+ return u8a2.toString(defaultHasher(JSON.stringify(components), algorithm), "base64url");
92
+ }
93
+ __name(calculateJwkThumbprint, "calculateJwkThumbprint");
94
+ async function getDigestAlgorithmFromJwkThumbprintUri(uri) {
95
+ const match = uri.match(/^urn:ietf:params:oauth:jwk-thumbprint:sha-(\w+):/);
96
+ if (!match) {
97
+ throw new Error(`Invalid JWK thumbprint URI structure ${uri}`);
98
+ }
99
+ const algorithm = `sha${match[1]}`;
100
+ if (algorithm !== "sha256" && algorithm !== "sha384" && algorithm !== "sha512") {
101
+ throw new Error(`Invalid JWK thumbprint URI digest algorithm ${uri}`);
102
+ }
103
+ return algorithm;
104
+ }
105
+ __name(getDigestAlgorithmFromJwkThumbprintUri, "getDigestAlgorithmFromJwkThumbprintUri");
106
+ async function calculateJwkThumbprintUri(jwk, digestAlgorithm = "sha256") {
107
+ const thumbprint = await calculateJwkThumbprint(jwk, digestAlgorithm);
108
+ return `urn:ietf:params:oauth:jwk-thumbprint:sha-${digestAlgorithm.slice(-3)}:${thumbprint}`;
109
+ }
110
+ __name(calculateJwkThumbprintUri, "calculateJwkThumbprintUri");
111
+
112
+ // lib/jwt/JwtVerifier.ts
113
+ var getDidJwtVerifier = /* @__PURE__ */ __name((jwt, options) => {
114
+ const { type } = options;
115
+ if (!jwt.header.kid) throw new Error(`Received an invalid JWT. Missing kid header.`);
116
+ if (!jwt.header.alg) throw new Error(`Received an invalid JWT. Missing alg header.`);
117
+ if (!jwt.header.kid.includes("#")) {
118
+ throw new Error(`Received an invalid JWT.. '${type}' contains an invalid kid header.`);
119
+ }
120
+ return {
121
+ method: "did",
122
+ didUrl: jwt.header.kid,
123
+ type,
124
+ alg: jwt.header.alg
125
+ };
126
+ }, "getDidJwtVerifier");
127
+ var getIssuer = /* @__PURE__ */ __name((type, payload) => {
128
+ if (type === "request-object") {
129
+ if (!payload.client_id) {
130
+ throw new Error("Missing required field client_id in request object JWT");
131
+ }
132
+ return payload.client_id;
133
+ }
134
+ if (typeof payload.iss !== "string") {
135
+ throw new Error(`Received an invalid JWT. '${type}' contains an invalid iss claim or it is missing.`);
136
+ }
137
+ return payload.iss;
138
+ }, "getIssuer");
139
+ var getX5cVerifier = /* @__PURE__ */ __name((jwt, options) => {
140
+ const { type } = options;
141
+ if (!jwt.header.x5c) throw new Error(`Received an invalid JWT. Missing x5c header.`);
142
+ if (!jwt.header.alg) throw new Error(`Received an invalid JWT. Missing alg header.`);
143
+ if (!Array.isArray(jwt.header.x5c) || jwt.header.x5c.length === 0 || !jwt.header.x5c.every((cert) => typeof cert === "string")) {
144
+ throw new Error(`Received an invalid JWT.. '${type}' contains an invalid x5c header.`);
145
+ }
146
+ return {
147
+ method: "x5c",
148
+ x5c: jwt.header.x5c,
149
+ issuer: getIssuer(type, jwt.payload),
150
+ type,
151
+ alg: jwt.header.alg
152
+ };
153
+ }, "getX5cVerifier");
154
+ var getJwkVerifier = /* @__PURE__ */ __name(async (jwt, options) => {
155
+ const { type } = options;
156
+ if (!jwt.header.jwk) throw new Error(`Received an invalid JWT. Missing jwk header.`);
157
+ if (!jwt.header.alg) throw new Error(`Received an invalid JWT. Missing alg header.`);
158
+ if (typeof jwt.header.jwk !== "object") {
159
+ throw new Error(`Received an invalid JWT. '${type}' contains an invalid jwk header.`);
160
+ }
161
+ return {
162
+ method: "jwk",
163
+ type,
164
+ jwk: jwt.header.jwk,
165
+ alg: jwt.header.alg
166
+ };
167
+ }, "getJwkVerifier");
168
+ var getJwtVerifierWithContext = /* @__PURE__ */ __name(async (jwt, options) => {
169
+ const { header, payload } = jwt;
170
+ if (header.kid?.startsWith("did:")) return getDidJwtVerifier({
171
+ header,
172
+ payload
173
+ }, options);
174
+ else if (jwt.header.x5c) return getX5cVerifier({
175
+ header,
176
+ payload
177
+ }, options);
178
+ else if (jwt.header.jwk) return getJwkVerifier({
179
+ header,
180
+ payload
181
+ }, options);
182
+ return {
183
+ method: "custom",
184
+ type: options.type
185
+ };
186
+ }, "getJwtVerifierWithContext");
187
+
188
+ // lib/jwt/jwtUtils.ts
189
+ import { jwtDecode } from "jwt-decode";
190
+ function parseJWT(jwt) {
191
+ const header = jwtDecode(jwt, {
192
+ header: true
193
+ });
194
+ const payload = jwtDecode(jwt, {
195
+ header: false
196
+ });
197
+ if (!payload || !header) {
198
+ throw new Error("Jwt Payload and/or Header could not be parsed");
199
+ }
200
+ return {
201
+ header,
202
+ payload
203
+ };
204
+ }
205
+ __name(parseJWT, "parseJWT");
206
+ var DEFAULT_SKEW_TIME = 60;
207
+ function getNowSkewed(now, skewTime) {
208
+ const _now = now ? now : epochTime();
209
+ const _skewTime = skewTime ? skewTime : DEFAULT_SKEW_TIME;
210
+ return {
211
+ nowSkewedPast: _now - _skewTime,
212
+ nowSkewedFuture: _now + _skewTime
213
+ };
214
+ }
215
+ __name(getNowSkewed, "getNowSkewed");
216
+ function epochTime() {
217
+ return Math.floor(Date.now() / 1e3);
218
+ }
219
+ __name(epochTime, "epochTime");
220
+ var BASE64_URL_REGEX = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
221
+ var isJws = /* @__PURE__ */ __name((jws) => {
222
+ const jwsParts = jws.split(".");
223
+ return jwsParts.length === 3 && jwsParts.every((part) => BASE64_URL_REGEX.test(part));
224
+ }, "isJws");
225
+ var isJwe = /* @__PURE__ */ __name((jwe) => {
226
+ const jweParts = jwe.split(".");
227
+ return jweParts.length === 5 && jweParts.every((part) => BASE64_URL_REGEX.test(part));
228
+ }, "isJwe");
229
+ var decodeProtectedHeader = /* @__PURE__ */ __name((jwt) => {
230
+ return jwtDecode(jwt, {
231
+ header: true
232
+ });
233
+ }, "decodeProtectedHeader");
234
+ var decodeJwt = /* @__PURE__ */ __name((jwt) => {
235
+ return jwtDecode(jwt, {
236
+ header: false
237
+ });
238
+ }, "decodeJwt");
239
+ var checkExp = /* @__PURE__ */ __name((input) => {
240
+ const { exp, now, clockSkew } = input;
241
+ return exp < (now ?? Date.now() / 1e3) - (clockSkew ?? 120);
242
+ }, "checkExp");
243
+
244
+ // lib/dpop/DPoP.ts
245
+ import { jwtDecode as jwtDecode2 } from "jwt-decode";
246
+ import * as u8a3 from "uint8arrays";
247
+ import { v4 as uuidv4 } from "uuid";
248
+ var dpopTokenRequestNonceError = "use_dpop_nonce";
249
+ function getCreateDPoPOptions(createDPoPClientOpts, endPointUrl, resourceRequestOpts) {
250
+ const htu = endPointUrl.split("?")[0].split("#")[0];
251
+ return {
252
+ ...createDPoPClientOpts,
253
+ jwtPayloadProps: {
254
+ ...createDPoPClientOpts.jwtPayloadProps,
255
+ htu,
256
+ htm: "POST",
257
+ ...resourceRequestOpts && {
258
+ accessToken: resourceRequestOpts.accessToken
259
+ }
260
+ }
261
+ };
262
+ }
263
+ __name(getCreateDPoPOptions, "getCreateDPoPOptions");
264
+ async function createDPoP(options) {
265
+ const { createJwtCallback, jwtIssuer, jwtPayloadProps, dPoPSigningAlgValuesSupported } = options;
266
+ if (jwtPayloadProps.accessToken && (jwtPayloadProps.accessToken?.startsWith("DPoP ") || jwtPayloadProps.accessToken?.startsWith("Bearer "))) {
267
+ throw new Error("expected access token without scheme");
268
+ }
269
+ const ath = jwtPayloadProps.accessToken ? u8a3.toString(defaultHasher(jwtPayloadProps.accessToken, "sha256"), "base64url") : void 0;
270
+ return createJwtCallback({
271
+ method: "jwk",
272
+ type: "dpop",
273
+ alg: jwtIssuer.alg,
274
+ jwk: jwtIssuer.jwk,
275
+ dPoPSigningAlgValuesSupported
276
+ }, {
277
+ header: {
278
+ ...jwtIssuer,
279
+ typ: "dpop+jwt",
280
+ alg: jwtIssuer.alg,
281
+ jwk: jwtIssuer.jwk
282
+ },
283
+ payload: {
284
+ ...jwtPayloadProps,
285
+ iat: epochTime(),
286
+ jti: uuidv4(),
287
+ ...ath && {
288
+ ath
289
+ }
290
+ }
291
+ });
292
+ }
293
+ __name(createDPoP, "createDPoP");
294
+ async function verifyDPoP(request, options) {
295
+ const dpop = request.headers["dpop"];
296
+ if (!dpop || typeof dpop !== "string") {
297
+ throw new Error("missing or invalid dpop header. Expected compact JWT");
298
+ }
299
+ const { header: dPoPHeader, payload: dPoPPayload } = parseJWT(dpop);
300
+ if (dPoPHeader.typ !== "dpop+jwt" || !dPoPHeader.alg || !dPoPHeader.jwk || typeof dPoPHeader.jwk !== "object" || dPoPHeader.jwk.d) {
301
+ throw new Error("invalid_dpop_proof. Invalid header claims");
302
+ }
303
+ if (!dPoPPayload.htm || !dPoPPayload.htu || !dPoPPayload.iat || !dPoPPayload.jti) {
304
+ throw new Error("invalid_dpop_proof. Missing required claims");
305
+ }
306
+ if (options?.acceptedAlgorithms && !options.acceptedAlgorithms.includes(dPoPHeader.alg)) {
307
+ throw new Error(`invalid_dpop_proof. Invalid 'alg' claim '${dPoPHeader.alg}'. Only ${options.acceptedAlgorithms.join(", ")} are supported.`);
308
+ }
309
+ if (options?.expectedNonce && !dPoPPayload.nonce || dPoPPayload.nonce !== options.expectedNonce) {
310
+ throw new Error("invalid_dpop_proof. Nonce mismatch");
311
+ }
312
+ try {
313
+ const verificationResult = await options.jwtVerifyCallback({
314
+ method: "jwk",
315
+ type: "dpop",
316
+ jwk: dPoPHeader.jwk,
317
+ alg: dPoPHeader.alg
318
+ }, {
319
+ header: dPoPHeader,
320
+ payload: dPoPPayload,
321
+ raw: dpop
322
+ });
323
+ if (!verificationResult) {
324
+ throw new Error("invalid_dpop_proof. Invalid JWT signature");
325
+ }
326
+ } catch (error) {
327
+ throw new Error("invalid_dpop_proof. Invalid JWT signature. " + (error instanceof Error ? error.message : "Unknown error"));
328
+ }
329
+ if (dPoPPayload.htm !== request.method) {
330
+ throw new Error(`invalid_dpop_proof. Invalid htm claim. Must match request method '${request.method}'`);
331
+ }
332
+ const currentUri = request.fullUrl.split("?")[0].split("#")[0];
333
+ if (dPoPPayload.htu !== currentUri) {
334
+ throw new Error("invalid_dpop_proof. Invalid htu claim");
335
+ }
336
+ if (options.expectedNonce && dPoPPayload.nonce !== options.expectedNonce || !options.expectedNonce && dPoPPayload.nonce) {
337
+ throw new Error("invalid_dpop_proof. Nonce mismatch");
338
+ }
339
+ const { nowSkewedPast, nowSkewedFuture } = getNowSkewed(options.now);
340
+ if (
341
+ // iat claim is too far in the future
342
+ nowSkewedPast - (options.maxIatAgeInSeconds ?? 60) > dPoPPayload.iat || // iat claim is too old
343
+ nowSkewedFuture + (options.maxIatAgeInSeconds ?? 60) < dPoPPayload.iat
344
+ ) {
345
+ throw new Error("invalid_dpop_proof. Invalid iat claim");
346
+ }
347
+ const authorizationHeader = request.headers.authorization;
348
+ if (!options.expectAccessToken && authorizationHeader) {
349
+ throw new Error("invalid_dpop_proof. Received an unexpected authorization header.");
350
+ }
351
+ if (options.expectAccessToken) {
352
+ if (!dPoPPayload.ath) {
353
+ throw new Error("invalid_dpop_proof. Missing expected ath claim.");
354
+ }
355
+ if (!authorizationHeader || typeof authorizationHeader !== "string" || !authorizationHeader.startsWith("DPoP ")) {
356
+ throw new Error("invalid_dpop_proof. Invalid authorization header.");
357
+ }
358
+ const accessToken = authorizationHeader.replace("DPoP ", "");
359
+ const expectedAth = u8a3.toString(defaultHasher(accessToken, "sha256"), "base64url");
360
+ if (dPoPPayload.ath !== expectedAth) {
361
+ throw new Error("invalid_dpop_proof. Invalid ath claim");
362
+ }
363
+ const accessTokenPayload = jwtDecode2(accessToken, {
364
+ header: false
365
+ });
366
+ if (!accessTokenPayload.cnf?.jkt) {
367
+ throw new Error("invalid_dpop_proof. Access token is missing the jkt claim");
368
+ }
369
+ const thumprint = await calculateJwkThumbprint(dPoPHeader.jwk, "sha256");
370
+ if (accessTokenPayload.cnf?.jkt !== thumprint) {
371
+ throw new Error("invalid_dpop_proof. JwkThumbprint mismatch");
372
+ }
373
+ }
374
+ return dPoPHeader.jwk;
375
+ }
376
+ __name(verifyDPoP, "verifyDPoP");
377
+ async function verifyResourceDPoP(request, options) {
378
+ if (!request.headers.authorization || typeof request.headers.authorization !== "string") {
379
+ throw new Error("Received an invalid resource request. Missing authorization header.");
380
+ }
381
+ const tokenPayload = jwtDecode2(request.headers.authorization, {
382
+ header: false
383
+ });
384
+ const tokenType = tokenPayload.token_type;
385
+ if (tokenType !== "DPoP") {
386
+ return;
387
+ }
388
+ return verifyDPoP(request, {
389
+ ...options,
390
+ expectAccessToken: true
391
+ });
392
+ }
393
+ __name(verifyResourceDPoP, "verifyResourceDPoP");
394
+
395
+ // lib/index.ts
396
+ import { v4 } from "uuid";
397
+ var VCI_LOGGERS = Loggers.DEFAULT;
398
+ var VCI_LOG_COMMON = VCI_LOGGERS.get("sphereon:oid4vci:common");
399
+ export {
400
+ BASE64_URL_REGEX,
401
+ SigningAlgo,
402
+ VCI_LOGGERS,
403
+ VCI_LOG_COMMON,
404
+ calculateJwkThumbprint,
405
+ calculateJwkThumbprintUri,
406
+ checkExp,
407
+ createDPoP,
408
+ decodeJwt,
409
+ decodeProtectedHeader,
410
+ defaultHasher,
411
+ dpopTokenRequestNonceError,
412
+ epochTime,
413
+ getCreateDPoPOptions,
414
+ getDidJwtVerifier,
415
+ getDigestAlgorithmFromJwkThumbprintUri,
416
+ getJwkVerifier,
417
+ getJwtVerifierWithContext,
418
+ getNowSkewed,
419
+ getX5cVerifier,
420
+ isJwe,
421
+ isJws,
422
+ parseJWT,
423
+ v4 as uuidv4,
424
+ verifyDPoP,
425
+ verifyResourceDPoP
15
426
  };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.defaultHasher = exports.uuidv4 = exports.VCI_LOG_COMMON = exports.VCI_LOGGERS = void 0;
18
- const ssi_types_1 = require("@sphereon/ssi-types");
19
- exports.VCI_LOGGERS = ssi_types_1.Loggers.DEFAULT;
20
- exports.VCI_LOG_COMMON = exports.VCI_LOGGERS.get('sphereon:oid4vci:common');
21
- __exportStar(require("./jwt"), exports);
22
- __exportStar(require("./dpop"), exports);
23
- __exportStar(require("./oauth"), exports);
24
- var uuid_1 = require("uuid");
25
- Object.defineProperty(exports, "uuidv4", { enumerable: true, get: function () { return uuid_1.v4; } });
26
- var hasher_1 = require("./hasher");
27
- Object.defineProperty(exports, "defaultHasher", { enumerable: true, get: function () { return hasher_1.defaultHasher; } });
28
427
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAA8C;AAEjC,QAAA,WAAW,GAAG,mBAAO,CAAC,OAAO,CAAC;AAC9B,QAAA,cAAc,GAAG,mBAAW,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAEzE,wCAAsB;AACtB,yCAAuB;AACvB,0CAAwB;AAExB,6BAAoC;AAA3B,8FAAA,EAAE,OAAU;AACrB,mCAAyC;AAAhC,uGAAA,aAAa,OAAA"}
1
+ {"version":3,"sources":["../lib/index.ts","../lib/jwt/Jwt.types.ts","../lib/jwt/JwkThumbprint.ts","../lib/hasher.ts","../lib/jwt/JwtVerifier.ts","../lib/jwt/jwtUtils.ts","../lib/dpop/DPoP.ts"],"sourcesContent":["import { Loggers } from '@sphereon/ssi-types';\n\nexport const VCI_LOGGERS = Loggers.DEFAULT;\nexport const VCI_LOG_COMMON = VCI_LOGGERS.get('sphereon:oid4vci:common');\n\nexport * from './types';\nexport * from './jwt';\nexport * from './dpop';\nexport * from './oauth';\n\nexport { v4 as uuidv4 } from 'uuid';\nexport { defaultHasher } from './hasher';\n","import { JwtHeader as jwtDecodeJwtHeader, JwtPayload as jwtDecodePayload } from 'jwt-decode';\n\nimport { JWK } from './Jwk.types';\n\nexport type JwtHeader = jwtDecodeJwtHeader & {\n alg?: string;\n x5c?: string[];\n kid?: string;\n jwk?: JWK;\n jwt?: string;\n} & Record<string, unknown>;\n\nexport type JwtPayload = jwtDecodePayload & {\n client_id?: string;\n nonce?: string;\n request_uri?: string;\n client_id_scheme?: string;\n} & Record<string, unknown>;\n\nexport enum SigningAlgo {\n EDDSA = 'EdDSA',\n RS256 = 'RS256',\n PS256 = 'PS256',\n ES256 = 'ES256',\n ES256K = 'ES256K',\n}\n","// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport * as u8a from 'uint8arrays';\n\nimport { defaultHasher } from '../hasher';\nimport { DigestAlgorithm } from '../types';\n\nimport { JWK } from './Jwk.types';\n\nconst check = (value: unknown, description: string) => {\n if (typeof value !== 'string' || !value) {\n throw Error(`${description} missing or invalid`);\n }\n};\n\nexport async function calculateJwkThumbprint(jwk: JWK, digestAlgorithm?: DigestAlgorithm): Promise<string> {\n if (!jwk || typeof jwk !== 'object') {\n throw new TypeError('JWK must be an object');\n }\n const algorithm = digestAlgorithm ?? 'sha256';\n if (algorithm !== 'sha256' && algorithm !== 'sha384' && algorithm !== 'sha512') {\n throw new TypeError('digestAlgorithm must one of \"sha256\", \"sha384\", or \"sha512\"');\n }\n let components;\n switch (jwk.kty) {\n case 'EC':\n check(jwk.crv, '\"crv\" (Curve) Parameter');\n check(jwk.x, '\"x\" (X Coordinate) Parameter');\n check(jwk.y, '\"y\" (Y Coordinate) Parameter');\n components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y };\n break;\n case 'OKP':\n check(jwk.crv, '\"crv\" (Subtype of Key Pair) Parameter');\n check(jwk.x, '\"x\" (Public Key) Parameter');\n components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x };\n break;\n case 'RSA':\n check(jwk.e, '\"e\" (Exponent) Parameter');\n check(jwk.n, '\"n\" (Modulus) Parameter');\n components = { e: jwk.e, kty: jwk.kty, n: jwk.n };\n break;\n case 'oct':\n check(jwk.k, '\"k\" (Key Value) Parameter');\n components = { k: jwk.k, kty: jwk.kty };\n break;\n default:\n throw Error('\"kty\" (Key Type) Parameter missing or unsupported');\n }\n return u8a.toString(defaultHasher(JSON.stringify(components), algorithm), 'base64url');\n}\n\nexport async function getDigestAlgorithmFromJwkThumbprintUri(uri: string): Promise<DigestAlgorithm> {\n const match = uri.match(/^urn:ietf:params:oauth:jwk-thumbprint:sha-(\\w+):/);\n if (!match) {\n throw new Error(`Invalid JWK thumbprint URI structure ${uri}`);\n }\n const algorithm = `sha${match[1]}` as DigestAlgorithm;\n if (algorithm !== 'sha256' && algorithm !== 'sha384' && algorithm !== 'sha512') {\n throw new Error(`Invalid JWK thumbprint URI digest algorithm ${uri}`);\n }\n return algorithm;\n}\n\nexport async function calculateJwkThumbprintUri(jwk: JWK, digestAlgorithm: DigestAlgorithm = 'sha256'): Promise<string> {\n const thumbprint = await calculateJwkThumbprint(jwk, digestAlgorithm);\n return `urn:ietf:params:oauth:jwk-thumbprint:sha-${digestAlgorithm.slice(-3)}:${thumbprint}`;\n}\n","import { HasherSync } from '@sphereon/ssi-types';\nimport sha from 'sha.js';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport * as u8a from 'uint8arrays';\n\nconst supportedAlgorithms = ['sha256', 'sha384', 'sha512'] as const;\ntype SupportedAlgorithms = (typeof supportedAlgorithms)[number];\n\nexport const defaultHasher: HasherSync = (data, algorithm) => {\n const sanitizedAlgorithm = algorithm.toLowerCase().replace(/[-_]/g, '');\n if (!supportedAlgorithms.includes(sanitizedAlgorithm as SupportedAlgorithms)) {\n throw new Error(`Unsupported hashing algorithm ${algorithm}`);\n }\n\n return new Uint8Array(\n sha(sanitizedAlgorithm as SupportedAlgorithms)\n .update(typeof data === 'string' ? u8a.fromString(data) : data)\n .digest(),\n );\n};\n","import { JWK } from './Jwk.types';\nimport { JwtHeader, JwtPayload, SigningAlgo } from './Jwt.types';\nimport { JwtProtectionMethod, JwtType } from './jwtUtils';\n\nexport interface JwtVerifierBase {\n type: JwtType;\n method: JwtProtectionMethod;\n}\n\nexport interface DidJwtVerifier extends JwtVerifierBase {\n method: 'did';\n\n alg: SigningAlgo | string;\n didUrl: string;\n}\n\nexport interface X5cJwtVerifier extends JwtVerifierBase {\n method: 'x5c';\n\n alg: SigningAlgo | string;\n\n /**\n *\n * Array of base64-encoded certificate strings in the DER-format.\n *\n * The certificate containing the public key corresponding to the key used to digitally sign the JWS MUST be the first certificate.\n */\n x5c: Array<string>;\n\n /**\n * The jwt issuer\n */\n issuer: string;\n}\n\nexport interface OpenIdFederationJwtVerifier extends JwtVerifierBase {\n method: 'openid-federation';\n\n /**\n * The OpenId federation Entity\n */\n entityId: string;\n}\n\nexport interface JwkJwtVerifier extends JwtVerifierBase {\n method: 'jwk';\n alg: SigningAlgo | string;\n\n jwk: JWK;\n}\n\nexport interface CustomJwtVerifier extends JwtVerifierBase {\n method: 'custom';\n}\n\nexport type JwtVerifier = DidJwtVerifier | X5cJwtVerifier | CustomJwtVerifier | JwkJwtVerifier | OpenIdFederationJwtVerifier;\n\nexport const getDidJwtVerifier = (jwt: { header: JwtHeader; payload: JwtPayload }, options: { type: JwtType }): DidJwtVerifier => {\n const { type } = options;\n if (!jwt.header.kid) throw new Error(`Received an invalid JWT. Missing kid header.`);\n if (!jwt.header.alg) throw new Error(`Received an invalid JWT. Missing alg header.`);\n\n if (!jwt.header.kid.includes('#')) {\n throw new Error(`Received an invalid JWT.. '${type}' contains an invalid kid header.`);\n }\n return { method: 'did', didUrl: jwt.header.kid, type: type, alg: jwt.header.alg };\n};\n\nconst getIssuer = (type: JwtType, payload: JwtPayload): string => {\n // For 'request-object' the `iss` value is not required so we map the issuer to client_id\n if (type === 'request-object') {\n if (!payload.client_id) {\n throw new Error('Missing required field client_id in request object JWT');\n }\n return payload.client_id as string;\n }\n\n if (typeof payload.iss !== 'string') {\n throw new Error(`Received an invalid JWT. '${type}' contains an invalid iss claim or it is missing.`);\n }\n return payload.iss;\n};\n\nexport const getX5cVerifier = (jwt: { header: JwtHeader; payload: JwtPayload }, options: { type: JwtType }): X5cJwtVerifier => {\n const { type } = options;\n if (!jwt.header.x5c) throw new Error(`Received an invalid JWT. Missing x5c header.`);\n if (!jwt.header.alg) throw new Error(`Received an invalid JWT. Missing alg header.`);\n\n if (!Array.isArray(jwt.header.x5c) || jwt.header.x5c.length === 0 || !jwt.header.x5c.every((cert) => typeof cert === 'string')) {\n throw new Error(`Received an invalid JWT.. '${type}' contains an invalid x5c header.`);\n }\n\n return {\n method: 'x5c',\n x5c: jwt.header.x5c,\n issuer: getIssuer(type, jwt.payload),\n type: type,\n alg: jwt.header.alg,\n };\n};\n\nexport const getJwkVerifier = async (jwt: { header: JwtHeader; payload: JwtPayload }, options: { type: JwtType }): Promise<JwkJwtVerifier> => {\n const { type } = options;\n if (!jwt.header.jwk) throw new Error(`Received an invalid JWT. Missing jwk header.`);\n if (!jwt.header.alg) throw new Error(`Received an invalid JWT. Missing alg header.`);\n\n if (typeof jwt.header.jwk !== 'object') {\n throw new Error(`Received an invalid JWT. '${type}' contains an invalid jwk header.`);\n }\n\n return { method: 'jwk', type, jwk: jwt.header.jwk, alg: jwt.header.alg };\n};\n\nexport const getJwtVerifierWithContext = async (\n jwt: { header: JwtHeader; payload: JwtPayload },\n options: { type: JwtType },\n): Promise<JwtVerifier> => {\n const { header, payload } = jwt;\n\n if (header.kid?.startsWith('did:')) return getDidJwtVerifier({ header, payload }, options);\n else if (jwt.header.x5c) return getX5cVerifier({ header, payload }, options);\n else if (jwt.header.jwk) return getJwkVerifier({ header, payload }, options);\n\n return { method: 'custom', type: options.type };\n};\n\nexport type VerifyJwtCallbackBase<T extends JwtVerifier> = (\n jwtVerifier: T,\n jwt: { header: JwtHeader; payload: JwtPayload; raw: string },\n) => Promise<boolean>;\n","import { jwtDecode } from 'jwt-decode';\n\nimport { JwtHeader, JwtPayload } from './Jwt.types';\n\nexport type JwtType = 'id-token' | 'request-object' | 'verifier-attestation' | 'dpop';\n\nexport type JwtProtectionMethod = 'did' | 'x5c' | 'jwk' | 'openid-federation' | 'custom';\n\nexport function parseJWT<Header = JwtHeader, Payload = JwtPayload>(jwt: string) {\n const header = jwtDecode<Header>(jwt, { header: true });\n const payload = jwtDecode<Payload>(jwt, { header: false });\n\n if (!payload || !header) {\n throw new Error('Jwt Payload and/or Header could not be parsed');\n }\n return { header, payload };\n}\n\n/**\n * The maximum allowed clock skew time in seconds. If an time based validation\n * is performed against current time (`now`), the validation can be of by the skew\n * time.\n *\n * See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5\n */\nconst DEFAULT_SKEW_TIME = 60;\n\nexport function getNowSkewed(now?: number, skewTime?: number) {\n const _now = now ? now : epochTime();\n const _skewTime = skewTime ? skewTime : DEFAULT_SKEW_TIME;\n\n return {\n nowSkewedPast: _now - _skewTime,\n nowSkewedFuture: _now + _skewTime,\n };\n}\n\n/**\n * Returns the current unix timestamp in seconds.\n */\nexport function epochTime() {\n return Math.floor(Date.now() / 1000);\n}\n\nexport const BASE64_URL_REGEX = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;\n\nexport const isJws = (jws: string) => {\n const jwsParts = jws.split('.');\n return jwsParts.length === 3 && jwsParts.every((part) => BASE64_URL_REGEX.test(part));\n};\nexport const isJwe = (jwe: string) => {\n const jweParts = jwe.split('.');\n return jweParts.length === 5 && jweParts.every((part) => BASE64_URL_REGEX.test(part));\n};\n\nexport const decodeProtectedHeader = (jwt: string) => {\n return jwtDecode(jwt, { header: true });\n};\n\nexport const decodeJwt = (jwt: string): JwtPayload => {\n return jwtDecode(jwt, { header: false });\n};\n\nexport const checkExp = (input: {\n exp: number;\n now?: number; // The number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC).\n clockSkew?: number;\n}) => {\n const { exp, now, clockSkew } = input;\n return exp < (now ?? Date.now() / 1000) - (clockSkew ?? 120);\n};\n","import { jwtDecode } from 'jwt-decode';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport * as u8a from 'uint8arrays';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { defaultHasher } from '../hasher';\nimport {\n calculateJwkThumbprint,\n CreateJwtCallback,\n epochTime,\n getNowSkewed,\n JWK,\n JwtHeader,\n JwtIssuerJwk,\n JwtPayload,\n parseJWT,\n SigningAlgo,\n VerifyJwtCallbackBase,\n} from '../jwt';\n\nexport const dpopTokenRequestNonceError = 'use_dpop_nonce';\n\nexport interface DPoPJwtIssuerWithContext extends JwtIssuerJwk {\n type: 'dpop';\n dPoPSigningAlgValuesSupported?: string[];\n}\n\nexport type DPoPJwtPayloadProps = {\n htu: string;\n iat: number;\n htm: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'CONNECT' | 'PATCH';\n ath?: string;\n nonce?: string;\n jti: string;\n};\nexport type DPoPJwtHeaderProps = { typ: 'dpop+jwt'; alg: SigningAlgo; jwk: JWK };\nexport type CreateDPoPJwtPayloadProps = Omit<DPoPJwtPayloadProps, 'iat' | 'jti' | 'ath'> & { accessToken?: string };\n\nexport interface CreateDPoPOpts<JwtPayloadProps = CreateDPoPJwtPayloadProps> {\n createJwtCallback: CreateJwtCallback<DPoPJwtIssuerWithContext>;\n jwtIssuer: Omit<JwtIssuerJwk, 'method' | 'type'>;\n jwtPayloadProps: Record<string, unknown> & JwtPayloadProps;\n dPoPSigningAlgValuesSupported?: (string | SigningAlgo)[];\n}\n\nexport type CreateDPoPClientOpts = CreateDPoPOpts<Omit<CreateDPoPJwtPayloadProps, 'htm' | 'htu'>>;\n\nexport function getCreateDPoPOptions(\n createDPoPClientOpts: CreateDPoPClientOpts,\n endPointUrl: string,\n resourceRequestOpts?: { accessToken: string },\n): CreateDPoPOpts {\n const htu = endPointUrl.split('?')[0].split('#')[0];\n return {\n ...createDPoPClientOpts,\n jwtPayloadProps: {\n ...createDPoPClientOpts.jwtPayloadProps,\n htu,\n htm: 'POST',\n ...(resourceRequestOpts && { accessToken: resourceRequestOpts.accessToken }),\n },\n };\n}\n\nexport async function createDPoP(options: CreateDPoPOpts): Promise<string> {\n const { createJwtCallback, jwtIssuer, jwtPayloadProps, dPoPSigningAlgValuesSupported } = options;\n\n if (jwtPayloadProps.accessToken && (jwtPayloadProps.accessToken?.startsWith('DPoP ') || jwtPayloadProps.accessToken?.startsWith('Bearer '))) {\n throw new Error('expected access token without scheme');\n }\n\n const ath = jwtPayloadProps.accessToken ? u8a.toString(defaultHasher(jwtPayloadProps.accessToken, 'sha256'), 'base64url') : undefined;\n return createJwtCallback(\n { method: 'jwk', type: 'dpop', alg: jwtIssuer.alg, jwk: jwtIssuer.jwk, dPoPSigningAlgValuesSupported },\n {\n header: { ...jwtIssuer, typ: 'dpop+jwt', alg: jwtIssuer.alg, jwk: jwtIssuer.jwk },\n payload: {\n ...jwtPayloadProps,\n iat: epochTime(),\n jti: uuidv4(),\n ...(ath && { ath }),\n },\n },\n );\n}\n\nexport type DPoPVerifyJwtCallback = VerifyJwtCallbackBase<JwtIssuerJwk & { type: 'dpop' }>;\nexport interface DPoPVerifyOptions {\n expectedNonce?: string;\n acceptedAlgorithms?: (string | SigningAlgo)[];\n // defaults to 300 seconds (5 minutes)\n maxIatAgeInSeconds?: number;\n expectAccessToken?: boolean;\n jwtVerifyCallback: DPoPVerifyJwtCallback;\n now?: number;\n}\n\nexport async function verifyDPoP(\n request: { headers: Record<string, string | string[] | undefined>; fullUrl: string } & Pick<Request, 'method'>,\n options: DPoPVerifyOptions,\n) {\n // There is not more than one DPoP HTTP request header field.\n const dpop = request.headers['dpop'];\n if (!dpop || typeof dpop !== 'string') {\n throw new Error('missing or invalid dpop header. Expected compact JWT');\n }\n\n // The DPoP HTTP request header field value is a single and well-formed JWT.\n const { header: dPoPHeader, payload: dPoPPayload } = parseJWT<JwtHeader, JwtPayload & Partial<DPoPJwtPayloadProps>>(dpop);\n\n // Ensure all required header claims are present\n if (dPoPHeader.typ !== 'dpop+jwt' || !dPoPHeader.alg || !dPoPHeader.jwk || typeof dPoPHeader.jwk !== 'object' || dPoPHeader.jwk.d) {\n throw new Error('invalid_dpop_proof. Invalid header claims');\n }\n\n // Ensure all required payload claims are present\n if (!dPoPPayload.htm || !dPoPPayload.htu || !dPoPPayload.iat || !dPoPPayload.jti) {\n throw new Error('invalid_dpop_proof. Missing required claims');\n }\n\n // Validate alg is supported\n if (options?.acceptedAlgorithms && !options.acceptedAlgorithms.includes(dPoPHeader.alg)) {\n throw new Error(`invalid_dpop_proof. Invalid 'alg' claim '${dPoPHeader.alg}'. Only ${options.acceptedAlgorithms.join(', ')} are supported.`);\n }\n\n // Validate nonce if provided\n if ((options?.expectedNonce && !dPoPPayload.nonce) || dPoPPayload.nonce !== options.expectedNonce) {\n throw new Error('invalid_dpop_proof. Nonce mismatch');\n }\n\n // Verify JWT signature\n try {\n const verificationResult = await options.jwtVerifyCallback(\n {\n method: 'jwk',\n type: 'dpop',\n jwk: dPoPHeader.jwk,\n alg: dPoPHeader.alg,\n },\n {\n header: dPoPHeader,\n payload: dPoPPayload,\n raw: dpop,\n },\n );\n\n if (!verificationResult) {\n throw new Error('invalid_dpop_proof. Invalid JWT signature');\n }\n } catch (error: unknown) {\n throw new Error('invalid_dpop_proof. Invalid JWT signature. ' + (error instanceof Error ? error.message : 'Unknown error'));\n }\n\n // Validate htm claim\n if (dPoPPayload.htm !== request.method) {\n throw new Error(`invalid_dpop_proof. Invalid htm claim. Must match request method '${request.method}'`);\n }\n\n // The htu claim matches the HTTP URI value for the HTTP request in which the JWT was received, ignoring any query and fragment parts.\n const currentUri = request.fullUrl.split('?')[0].split('#')[0];\n if (dPoPPayload.htu !== currentUri) {\n throw new Error('invalid_dpop_proof. Invalid htu claim');\n }\n\n // Validate nonce if provided\n if ((options.expectedNonce && dPoPPayload.nonce !== options.expectedNonce) || (!options.expectedNonce && dPoPPayload.nonce)) {\n throw new Error('invalid_dpop_proof. Nonce mismatch');\n }\n\n // Validate iat claim\n const { nowSkewedPast, nowSkewedFuture } = getNowSkewed(options.now);\n if (\n // iat claim is too far in the future\n nowSkewedPast - (options.maxIatAgeInSeconds ?? 60) > dPoPPayload.iat ||\n // iat claim is too old\n nowSkewedFuture + (options.maxIatAgeInSeconds ?? 60) < dPoPPayload.iat\n ) {\n // 5 minute window\n throw new Error('invalid_dpop_proof. Invalid iat claim');\n }\n\n // If access token is present, validate ath claim\n const authorizationHeader = request.headers.authorization;\n if (!options.expectAccessToken && authorizationHeader) {\n throw new Error('invalid_dpop_proof. Received an unexpected authorization header.');\n }\n\n if (options.expectAccessToken) {\n if (!dPoPPayload.ath) {\n throw new Error('invalid_dpop_proof. Missing expected ath claim.');\n }\n\n // validate that the DPOP proof is made for the provided access token\n if (!authorizationHeader || typeof authorizationHeader !== 'string' || !authorizationHeader.startsWith('DPoP ')) {\n throw new Error('invalid_dpop_proof. Invalid authorization header.');\n }\n\n const accessToken = authorizationHeader.replace('DPoP ', '');\n const expectedAth = u8a.toString(defaultHasher(accessToken, 'sha256'), 'base64url');\n if (dPoPPayload.ath !== expectedAth) {\n throw new Error('invalid_dpop_proof. Invalid ath claim');\n }\n\n // validate that the access token is signed with the same key as the DPOP proof\n const accessTokenPayload = jwtDecode<JwtPayload & { cnf?: { jkt?: string } }>(accessToken, { header: false });\n if (!accessTokenPayload.cnf?.jkt) {\n throw new Error('invalid_dpop_proof. Access token is missing the jkt claim');\n }\n\n const thumprint = await calculateJwkThumbprint(dPoPHeader.jwk, 'sha256');\n if (accessTokenPayload.cnf?.jkt !== thumprint) {\n throw new Error('invalid_dpop_proof. JwkThumbprint mismatch');\n }\n }\n\n // If all validations pass, return the dpop jwk\n return dPoPHeader.jwk;\n}\n\n/**\n * DPoP verifications for resource requests\n * For Bearer token compatibility jwt's must have a token_type claim\n * The access token itself must be validated before using this method\n * If the token_type is not DPoP, then the request is not a DPoP request\n * and we don't need to verify the DPoP proof\n */\nexport async function verifyResourceDPoP(\n request: { headers: Record<string, string | string[] | undefined>; fullUrl: string } & Pick<Request, 'method'>,\n options: Omit<DPoPVerifyOptions, 'expectAccessToken'>,\n) {\n if (!request.headers.authorization || typeof request.headers.authorization !== 'string') {\n throw new Error('Received an invalid resource request. Missing authorization header.');\n }\n const tokenPayload = jwtDecode<JwtPayload & { token_type?: string }>(request.headers.authorization, { header: false });\n const tokenType = tokenPayload.token_type;\n\n if (tokenType !== 'DPoP') {\n return;\n }\n\n return verifyDPoP(request, { ...options, expectAccessToken: true });\n}\n"],"mappings":";;;;AAAA,SAASA,eAAe;;;ACmBjB,IAAKC,cAAAA,yBAAAA,cAAAA;;;;;;SAAAA;;;;ACjBZ,YAAYC,UAAS;;;ACDrB,OAAOC,SAAS;AAGhB,YAAYC,SAAS;AAErB,IAAMC,sBAAsB;EAAC;EAAU;EAAU;;AAG1C,IAAMC,gBAA4B,wBAACC,MAAMC,cAAAA;AAC9C,QAAMC,qBAAqBD,UAAUE,YAAW,EAAGC,QAAQ,SAAS,EAAA;AACpE,MAAI,CAACN,oBAAoBO,SAASH,kBAAAA,GAA4C;AAC5E,UAAM,IAAII,MAAM,iCAAiCL,SAAAA,EAAW;EAC9D;AAEA,SAAO,IAAIM,WACTC,IAAIN,kBAAAA,EACDO,OAAO,OAAOT,SAAS,WAAeU,eAAWV,IAAAA,IAAQA,IAAAA,EACzDW,OAAM,CAAA;AAEb,GAXyC;;;ADAzC,IAAMC,QAAQ,wBAACC,OAAgBC,gBAAAA;AAC7B,MAAI,OAAOD,UAAU,YAAY,CAACA,OAAO;AACvC,UAAME,MAAM,GAAGD,WAAAA,qBAAgC;EACjD;AACF,GAJc;AAMd,eAAsBE,uBAAuBC,KAAUC,iBAAiC;AACtF,MAAI,CAACD,OAAO,OAAOA,QAAQ,UAAU;AACnC,UAAM,IAAIE,UAAU,uBAAA;EACtB;AACA,QAAMC,YAAYF,mBAAmB;AACrC,MAAIE,cAAc,YAAYA,cAAc,YAAYA,cAAc,UAAU;AAC9E,UAAM,IAAID,UAAU,6DAAA;EACtB;AACA,MAAIE;AACJ,UAAQJ,IAAIK,KAAG;IACb,KAAK;AACHV,YAAMK,IAAIM,KAAK,yBAAA;AACf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AAqD;AAErD,MAAI,CAACsB,QAAQE,QAAQuB,iBAAiB,OAAOzB,QAAQE,QAAQuB,kBAAkB,UAAU;AACvF,UAAM,IAAI1C,MAAM,qEAAA;EAClB;AACA,QAAMqD,eAAeN,WAAgD9B,QAAQE,QAAQuB,eAAe;IAAEjC,QAAQ;EAAM,CAAA;AACpH,QAAM6C,YAAYD,aAAaE;AAE/B,MAAID,cAAc,QAAQ;AACxB;EACF;AAEA,SAAOtC,WAAWC,SAAS;IAAE,GAAGtB;IAASgD,mBAAmB;EAAK,CAAA;AACnE;AAfsBS;;;ANzNtB,SAAeI,UAAc;AARtB,IAAMC,cAAcC,QAAQC;AAC5B,IAAMC,iBAAiBH,YAAYI,IAAI,yBAAA;","names":["Loggers","SigningAlgo","u8a","sha","u8a","supportedAlgorithms","defaultHasher","data","algorithm","sanitizedAlgorithm","toLowerCase","replace","includes","Error","Uint8Array","sha","update","fromString","digest","check","value","description","Error","calculateJwkThumbprint","jwk","digestAlgorithm","TypeError","algorithm","components","kty","crv","x","y","e","n","k","toString","defaultHasher","JSON","stringify","getDigestAlgorithmFromJwkThumbprintUri","uri","match","calculateJwkThumbprintUri","thumbprint","slice","getDidJwtVerifier","jwt","options","type","header","kid","Error","alg","includes","method","didUrl","getIssuer","payload","client_id","iss","getX5cVerifier","x5c","Array","isArray","length","every","cert","issuer","getJwkVerifier","jwk","getJwtVerifierWithContext","startsWith","jwtDecode","parseJWT","jwt","header","jwtDecode","payload","Error","DEFAULT_SKEW_TIME","getNowSkewed","now","skewTime","_now","epochTime","_skewTime","nowSkewedPast","nowSkewedFuture","Math","floor","Date","BASE64_URL_REGEX","isJws","jws","jwsParts","split","length","every","part","test","isJwe","jwe","jweParts","decodeProtectedHeader","decodeJwt","checkExp","input","exp","clockSkew","jwtDecode","u8a","v4","uuidv4","dpopTokenRequestNonceError","getCreateDPoPOptions","createDPoPClientOpts","endPointUrl","resourceRequestOpts","htu","split","jwtPayloadProps","htm","accessToken","createDPoP","options","createJwtCallback","jwtIssuer","dPoPSigningAlgValuesSupported","startsWith","Error","ath","toString","defaultHasher","undefined","method","type","alg","jwk","header","typ","payload","iat","epochTime","jti","uuidv4","verifyDPoP","request","dpop","headers","dPoPHeader","dPoPPayload","parseJWT","d","acceptedAlgorithms","includes","join","expectedNonce","nonce","verificationResult","jwtVerifyCallback","raw","error","message","currentUri","fullUrl","nowSkewedPast","nowSkewedFuture","getNowSkewed","now","maxIatAgeInSeconds","authorizationHeader","authorization","expectAccessToken","replace","expectedAth","accessTokenPayload","jwtDecode","cnf","jkt","thumprint","calculateJwkThumbprint","verifyResourceDPoP","tokenPayload","tokenType","token_type","uuidv4","VCI_LOGGERS","Loggers","DEFAULT","VCI_LOG_COMMON","get"]}
package/package.json CHANGED
@@ -1,33 +1,42 @@
1
1
  {
2
2
  "name": "@sphereon/oid4vc-common",
3
- "version": "0.17.0",
3
+ "version": "0.17.1-feature.esm.cjs.25+006b4d1",
4
4
  "description": "OpenID 4 Verifiable Credentials Common",
5
- "source": "lib/index.ts",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.cts",
16
+ "require": "./dist/index.cjs"
17
+ }
18
+ },
8
19
  "scripts": {
9
- "build": "tsc",
10
- "build:clean": "tsc --build --clean && tsc --build"
20
+ "build": "tsup --config ../../tsup.config.ts --tsconfig ../../tsconfig.tsup.json",
21
+ "test": "vitest run --config ../../vitest.config.ts --coverage"
11
22
  },
12
23
  "dependencies": {
13
- "@sphereon/ssi-types": "^0.32.1-next.161",
24
+ "@sphereon/ssi-types": "^0.33",
14
25
  "jwt-decode": "^4.0.0",
15
26
  "sha.js": "^2.4.11",
16
27
  "uint8arrays": "3.1.1",
17
28
  "uuid": "^9.0.0"
18
29
  },
19
30
  "devDependencies": {
20
- "@types/jest": "^29.5.12",
21
31
  "@types/sha.js": "^2.4.4",
22
32
  "@types/uuid": "^9.0.1",
23
- "typescript": "5.4.5"
33
+ "typescript": "5.8.3"
24
34
  },
25
35
  "engines": {
26
- "node": ">=18"
36
+ "node": ">=20"
27
37
  },
28
38
  "files": [
29
- "lib/**/*",
30
- "dist/**/*"
39
+ "dist"
31
40
  ],
32
41
  "prettier": {
33
42
  "singleQuote": true,
@@ -52,5 +61,5 @@
52
61
  "publishConfig": {
53
62
  "access": "public"
54
63
  },
55
- "gitHead": "730c459314d3831431a924920a0de39500f72c9d"
64
+ "gitHead": "006b4d1bce2f4ca3280b80a53773733be12b829d"
56
65
  }
@@ -1,60 +0,0 @@
1
- import { CreateJwtCallback, JWK, JwtIssuerJwk, SigningAlgo, VerifyJwtCallbackBase } from './../jwt';
2
- export declare const dpopTokenRequestNonceError = "use_dpop_nonce";
3
- export interface DPoPJwtIssuerWithContext extends JwtIssuerJwk {
4
- type: 'dpop';
5
- dPoPSigningAlgValuesSupported?: string[];
6
- }
7
- export type DPoPJwtPayloadProps = {
8
- htu: string;
9
- iat: number;
10
- htm: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE' | 'CONNECT' | 'PATCH';
11
- ath?: string;
12
- nonce?: string;
13
- jti: string;
14
- };
15
- export type DPoPJwtHeaderProps = {
16
- typ: 'dpop+jwt';
17
- alg: SigningAlgo;
18
- jwk: JWK;
19
- };
20
- export type CreateDPoPJwtPayloadProps = Omit<DPoPJwtPayloadProps, 'iat' | 'jti' | 'ath'> & {
21
- accessToken?: string;
22
- };
23
- export interface CreateDPoPOpts<JwtPayloadProps = CreateDPoPJwtPayloadProps> {
24
- createJwtCallback: CreateJwtCallback<DPoPJwtIssuerWithContext>;
25
- jwtIssuer: Omit<JwtIssuerJwk, 'method' | 'type'>;
26
- jwtPayloadProps: Record<string, unknown> & JwtPayloadProps;
27
- dPoPSigningAlgValuesSupported?: (string | SigningAlgo)[];
28
- }
29
- export type CreateDPoPClientOpts = CreateDPoPOpts<Omit<CreateDPoPJwtPayloadProps, 'htm' | 'htu'>>;
30
- export declare function getCreateDPoPOptions(createDPoPClientOpts: CreateDPoPClientOpts, endPointUrl: string, resourceRequestOpts?: {
31
- accessToken: string;
32
- }): CreateDPoPOpts;
33
- export declare function createDPoP(options: CreateDPoPOpts): Promise<string>;
34
- export type DPoPVerifyJwtCallback = VerifyJwtCallbackBase<JwtIssuerJwk & {
35
- type: 'dpop';
36
- }>;
37
- export interface DPoPVerifyOptions {
38
- expectedNonce?: string;
39
- acceptedAlgorithms?: (string | SigningAlgo)[];
40
- maxIatAgeInSeconds?: number;
41
- expectAccessToken?: boolean;
42
- jwtVerifyCallback: DPoPVerifyJwtCallback;
43
- now?: number;
44
- }
45
- export declare function verifyDPoP(request: {
46
- headers: Record<string, string | string[] | undefined>;
47
- fullUrl: string;
48
- } & Pick<Request, 'method'>, options: DPoPVerifyOptions): Promise<JWK>;
49
- /**
50
- * DPoP verifications for resource requests
51
- * For Bearer token compatibility jwt's must have a token_type claim
52
- * The access token itself must be validated before using this method
53
- * If the token_type is not DPoP, then the request is not a DPoP request
54
- * and we don't need to verify the DPoP proof
55
- */
56
- export declare function verifyResourceDPoP(request: {
57
- headers: Record<string, string | string[] | undefined>;
58
- fullUrl: string;
59
- } & Pick<Request, 'method'>, options: Omit<DPoPVerifyOptions, 'expectAccessToken'>): Promise<JWK | undefined>;
60
- //# sourceMappingURL=DPoP.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DPoP.d.ts","sourceRoot":"","sources":["../../lib/dpop/DPoP.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,iBAAiB,EAGjB,GAAG,EAEH,YAAY,EAGZ,WAAW,EACX,qBAAqB,EACtB,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,0BAA0B,mBAAmB,CAAC;AAE3D,MAAM,WAAW,wBAAyB,SA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