@sphereon/oid4vci-client 0.10.3 → 0.10.4-next.119

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 (142) hide show
  1. package/README.md +24 -5
  2. package/dist/AccessTokenClient.d.ts +5 -5
  3. package/dist/AccessTokenClient.d.ts.map +1 -1
  4. package/dist/AccessTokenClient.js +51 -37
  5. package/dist/AccessTokenClient.js.map +1 -1
  6. package/dist/AccessTokenClientV1_0_11.d.ts +29 -0
  7. package/dist/AccessTokenClientV1_0_11.d.ts.map +1 -0
  8. package/dist/AccessTokenClientV1_0_11.js +209 -0
  9. package/dist/AccessTokenClientV1_0_11.js.map +1 -0
  10. package/dist/AuthorizationCodeClient.d.ts +9 -4
  11. package/dist/AuthorizationCodeClient.d.ts.map +1 -1
  12. package/dist/AuthorizationCodeClient.js +102 -18
  13. package/dist/AuthorizationCodeClient.js.map +1 -1
  14. package/dist/AuthorizationCodeClientV1_0_11.d.ts +9 -0
  15. package/dist/AuthorizationCodeClientV1_0_11.d.ts.map +1 -0
  16. package/dist/AuthorizationCodeClientV1_0_11.js +134 -0
  17. package/dist/AuthorizationCodeClientV1_0_11.js.map +1 -0
  18. package/dist/CredentialOfferClient.d.ts.map +1 -1
  19. package/dist/CredentialOfferClient.js +18 -13
  20. package/dist/CredentialOfferClient.js.map +1 -1
  21. package/dist/CredentialOfferClientV1_0_11.d.ts +10 -0
  22. package/dist/CredentialOfferClientV1_0_11.d.ts.map +1 -0
  23. package/dist/CredentialOfferClientV1_0_11.js +101 -0
  24. package/dist/CredentialOfferClientV1_0_11.js.map +1 -0
  25. package/dist/CredentialOfferClientV1_0_13.d.ts +10 -0
  26. package/dist/CredentialOfferClientV1_0_13.d.ts.map +1 -0
  27. package/dist/CredentialOfferClientV1_0_13.js +94 -0
  28. package/dist/CredentialOfferClientV1_0_13.js.map +1 -0
  29. package/dist/CredentialRequestClient.d.ts +20 -7
  30. package/dist/CredentialRequestClient.d.ts.map +1 -1
  31. package/dist/CredentialRequestClient.js +46 -30
  32. package/dist/CredentialRequestClient.js.map +1 -1
  33. package/dist/CredentialRequestClientBuilder.d.ts +11 -6
  34. package/dist/CredentialRequestClientBuilder.d.ts.map +1 -1
  35. package/dist/CredentialRequestClientBuilder.js +22 -9
  36. package/dist/CredentialRequestClientBuilder.js.map +1 -1
  37. package/dist/CredentialRequestClientBuilderV1_0_11.d.ts +48 -0
  38. package/dist/CredentialRequestClientBuilderV1_0_11.d.ts.map +1 -0
  39. package/dist/CredentialRequestClientBuilderV1_0_11.js +121 -0
  40. package/dist/CredentialRequestClientBuilderV1_0_11.js.map +1 -0
  41. package/dist/CredentialRequestClientV1_0_11.d.ts +50 -0
  42. package/dist/CredentialRequestClientV1_0_11.d.ts.map +1 -0
  43. package/dist/CredentialRequestClientV1_0_11.js +151 -0
  44. package/dist/CredentialRequestClientV1_0_11.js.map +1 -0
  45. package/dist/MetadataClient.d.ts +5 -15
  46. package/dist/MetadataClient.d.ts.map +1 -1
  47. package/dist/MetadataClient.js +41 -44
  48. package/dist/MetadataClient.js.map +1 -1
  49. package/dist/MetadataClientV1_0_11.d.ts +31 -0
  50. package/dist/MetadataClientV1_0_11.d.ts.map +1 -0
  51. package/dist/MetadataClientV1_0_11.js +182 -0
  52. package/dist/MetadataClientV1_0_11.js.map +1 -0
  53. package/dist/MetadataClientV1_0_13.d.ts +31 -0
  54. package/dist/MetadataClientV1_0_13.d.ts.map +1 -0
  55. package/dist/MetadataClientV1_0_13.js +181 -0
  56. package/dist/MetadataClientV1_0_13.js.map +1 -0
  57. package/dist/OpenID4VCIClient.d.ts +14 -19
  58. package/dist/OpenID4VCIClient.d.ts.map +1 -1
  59. package/dist/OpenID4VCIClient.js +111 -61
  60. package/dist/OpenID4VCIClient.js.map +1 -1
  61. package/dist/OpenID4VCIClientV1_0_11.d.ts +108 -0
  62. package/dist/OpenID4VCIClientV1_0_11.d.ts.map +1 -0
  63. package/dist/OpenID4VCIClientV1_0_11.js +449 -0
  64. package/dist/OpenID4VCIClientV1_0_11.js.map +1 -0
  65. package/dist/OpenID4VCIClientV1_0_13.d.ts +112 -0
  66. package/dist/OpenID4VCIClientV1_0_13.d.ts.map +1 -0
  67. package/dist/OpenID4VCIClientV1_0_13.js +478 -0
  68. package/dist/OpenID4VCIClientV1_0_13.js.map +1 -0
  69. package/dist/ProofOfPossessionBuilder.d.ts +14 -3
  70. package/dist/ProofOfPossessionBuilder.d.ts.map +1 -1
  71. package/dist/ProofOfPossessionBuilder.js +20 -21
  72. package/dist/ProofOfPossessionBuilder.js.map +1 -1
  73. package/dist/functions/OpenIDUtils.d.ts +12 -0
  74. package/dist/functions/OpenIDUtils.d.ts.map +1 -0
  75. package/dist/functions/OpenIDUtils.js +37 -0
  76. package/dist/functions/OpenIDUtils.js.map +1 -0
  77. package/dist/functions/index.d.ts +2 -3
  78. package/dist/functions/index.d.ts.map +1 -1
  79. package/dist/functions/index.js +2 -3
  80. package/dist/functions/index.js.map +1 -1
  81. package/dist/functions/notifications.d.ts +4 -0
  82. package/dist/functions/notifications.d.ts.map +1 -0
  83. package/dist/functions/notifications.js +39 -0
  84. package/dist/functions/notifications.js.map +1 -0
  85. package/dist/index.d.ts +13 -1
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +14 -1
  88. package/dist/index.js.map +1 -1
  89. package/dist/types/index.d.ts +2 -0
  90. package/dist/types/index.d.ts.map +1 -1
  91. package/dist/types/index.js +5 -0
  92. package/dist/types/index.js.map +1 -1
  93. package/lib/AccessTokenClient.ts +59 -34
  94. package/lib/AccessTokenClientV1_0_11.ts +250 -0
  95. package/lib/AuthorizationCodeClient.ts +131 -28
  96. package/lib/AuthorizationCodeClientV1_0_11.ts +170 -0
  97. package/lib/CredentialOfferClient.ts +21 -8
  98. package/lib/CredentialOfferClientV1_0_11.ts +112 -0
  99. package/lib/CredentialOfferClientV1_0_13.ts +103 -0
  100. package/lib/CredentialRequestClient.ts +65 -26
  101. package/lib/CredentialRequestClientBuilder.ts +34 -16
  102. package/lib/CredentialRequestClientBuilderV1_0_11.ts +163 -0
  103. package/lib/CredentialRequestClientV1_0_11.ts +197 -0
  104. package/lib/MetadataClient.ts +64 -49
  105. package/lib/MetadataClientV1_0_11.ts +189 -0
  106. package/lib/MetadataClientV1_0_13.ts +188 -0
  107. package/lib/OpenID4VCIClient.ts +132 -68
  108. package/lib/OpenID4VCIClientV1_0_11.ts +635 -0
  109. package/lib/OpenID4VCIClientV1_0_13.ts +677 -0
  110. package/lib/ProofOfPossessionBuilder.ts +41 -11
  111. package/lib/__tests__/AccessTokenClient.spec.ts +40 -12
  112. package/lib/__tests__/AuthorizationDetailsBuilder.spec.ts +0 -12
  113. package/lib/__tests__/CredentialRequestClient.spec.ts +87 -50
  114. package/lib/__tests__/CredentialRequestClientBuilder.spec.ts +18 -12
  115. package/lib/__tests__/CredentialRequestClientV1_0_11.spec.ts +317 -0
  116. package/lib/__tests__/EBSIE2E.spec.test.ts +2 -2
  117. package/lib/__tests__/HttpUtils.spec.ts +1 -1
  118. package/lib/__tests__/IT.spec.ts +264 -14
  119. package/lib/__tests__/IssuanceInitiation.spec.ts +59 -4
  120. package/lib/__tests__/IssuanceInitiationV1_0_11.spec.ts +62 -0
  121. package/lib/__tests__/MattrE2E.spec.test.ts +2 -2
  122. package/lib/__tests__/MetadataClient.spec.ts +53 -3
  123. package/lib/__tests__/MetadataMocks.ts +42 -2
  124. package/lib/__tests__/OpenID4VCIClient.spec.ts +58 -2
  125. package/lib/__tests__/{OpenID4VCIClientPAR.spec.ts → OpenID4VCIClientPARV1_0_11.spec.ts} +5 -5
  126. package/lib/__tests__/OpenID4VCIClientV1_0_11.spec.ts +226 -0
  127. package/lib/__tests__/OpenID4VCIClientV1_0_13.spec.ts +204 -0
  128. package/lib/__tests__/ProofOfPossessionBuilder.spec.ts +1 -1
  129. package/lib/__tests__/SdJwt.spec.ts +36 -30
  130. package/lib/__tests__/SphereonE2E.spec.test.ts +10 -7
  131. package/lib/__tests__/data/VciDataFixtures.ts +712 -27
  132. package/lib/functions/OpenIDUtils.ts +25 -0
  133. package/lib/functions/index.ts +2 -3
  134. package/lib/functions/notifications.ts +32 -0
  135. package/lib/index.ts +16 -1
  136. package/lib/types/index.ts +6 -0
  137. package/package.json +4 -4
  138. package/dist/functions/ProofUtil.d.ts +0 -30
  139. package/dist/functions/ProofUtil.d.ts.map +0 -1
  140. package/dist/functions/ProofUtil.js +0 -106
  141. package/dist/functions/ProofUtil.js.map +0 -1
  142. package/lib/functions/ProofUtil.ts +0 -128
@@ -0,0 +1,25 @@
1
+ import { getJson, OpenIDResponse, WellKnownEndpoints } from '@sphereon/oid4vci-common';
2
+ import Debug from 'debug';
3
+
4
+ const debug = Debug('sphereon:openid4vci:openid-utils');
5
+ /**
6
+ * Allows to retrieve information from a well-known location
7
+ *
8
+ * @param host The host
9
+ * @param endpointType The endpoint type, currently supports OID4VCI, OIDC and OAuth2 endpoint types
10
+ * @param opts Options, like for instance whether an error should be thrown in case the endpoint doesn't exist
11
+ */
12
+ export const retrieveWellknown = async <T>(
13
+ host: string,
14
+ endpointType: WellKnownEndpoints,
15
+ opts?: { errorOnNotFound?: boolean },
16
+ ): Promise<OpenIDResponse<T>> => {
17
+ const result: OpenIDResponse<T> = await getJson(`${host.endsWith('/') ? host.slice(0, -1) : host}${endpointType}`, {
18
+ exceptionOnHttpErrorStatus: opts?.errorOnNotFound,
19
+ });
20
+ if (result.origResponse.status >= 400) {
21
+ // We only get here when error on not found is false
22
+ debug(`host ${host} with endpoint type ${endpointType} status: ${result.origResponse.status}, ${result.origResponse.statusText}`);
23
+ }
24
+ return result;
25
+ };
@@ -1,3 +1,2 @@
1
- export * from '@sphereon/oid4vci-common/dist/functions/Encoding';
2
- export * from '@sphereon/oid4vci-common/dist/functions/HttpUtils';
3
- export * from './ProofUtil';
1
+ export * from './AuthorizationUtil';
2
+ export * from './notifications';
@@ -0,0 +1,32 @@
1
+ import { NotificationErrorResponse, NotificationRequest, NotificationResult, post } from '@sphereon/oid4vci-common';
2
+
3
+ import { CredentialRequestOpts } from '../CredentialRequestClient';
4
+ import { LOG } from '../types';
5
+
6
+ export async function sendNotification(
7
+ credentialRequestOpts: Partial<CredentialRequestOpts>,
8
+ request: NotificationRequest,
9
+ accessToken?: string,
10
+ ): Promise<NotificationResult> {
11
+ LOG.info(`Sending status notification event '${request.event}' for id ${request.notification_id}`);
12
+ if (!credentialRequestOpts.notificationEndpoint) {
13
+ throw Error(`Cannot send notification when no notification endpoint is provided`);
14
+ }
15
+ const token = accessToken ?? credentialRequestOpts.token;
16
+ const response = await post<NotificationErrorResponse>(credentialRequestOpts.notificationEndpoint, JSON.stringify(request), {
17
+ ...(token && { bearerToken: token }),
18
+ });
19
+ const error = response.errorBody?.error !== undefined;
20
+ const result = {
21
+ error,
22
+ response: error ? await response.errorBody?.json() : undefined,
23
+ };
24
+ if (error) {
25
+ LOG.warning(
26
+ `Notification endpoint returned an error for event '${request.event}' and id ${request.notification_id}: ${await response.errorBody?.json()}`,
27
+ );
28
+ } else {
29
+ LOG.debug(`Notification endpoint returned success for event '${request.event}' and id ${request.notification_id}`);
30
+ }
31
+ return result;
32
+ }
package/lib/index.ts CHANGED
@@ -1,9 +1,24 @@
1
+ import { VCI_LOGGERS } from '@sphereon/oid4vci-common';
2
+ import { ISimpleLogger } from '@sphereon/ssi-types';
3
+
4
+ export const LOG: ISimpleLogger<string> = VCI_LOGGERS.get('sphereon:oid4vci:client');
5
+
1
6
  export * from './AccessTokenClient';
7
+ export * from './AccessTokenClientV1_0_11';
8
+ export * from './AuthorizationCodeClient';
9
+ export * from './AuthorizationCodeClientV1_0_11';
2
10
  export * from './CredentialRequestClient';
3
11
  export * from './CredentialOfferClient';
4
- export * from './CredentialRequestClient';
12
+ export * from './CredentialOfferClientV1_0_11';
13
+ export * from './CredentialOfferClientV1_0_13';
14
+ export * from './CredentialRequestClientV1_0_11';
5
15
  export * from './CredentialRequestClientBuilder';
16
+ export * from './CredentialRequestClientBuilderV1_0_11';
6
17
  export * from './functions';
7
18
  export * from './MetadataClient';
19
+ export * from './MetadataClientV1_0_13';
20
+ export * from './MetadataClientV1_0_11';
8
21
  export * from './OpenID4VCIClient';
22
+ export * from './OpenID4VCIClientV1_0_13';
23
+ export * from './OpenID4VCIClientV1_0_11';
9
24
  export * from './ProofOfPossessionBuilder';
@@ -0,0 +1,6 @@
1
+ import { VCI_LOGGERS } from '@sphereon/oid4vci-common';
2
+ import { ISimpleLogger, LogMethod } from '@sphereon/ssi-types';
3
+
4
+ export const LOG: ISimpleLogger<string> = VCI_LOGGERS.options('sphereon:oid4vci:client', { methods: [LogMethod.EVENT, LogMethod.DEBUG_PKG] }).get(
5
+ 'sphereon:oid4vci:client',
6
+ );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/oid4vci-client",
3
- "version": "0.10.3",
3
+ "version": "0.10.4-next.119+a0d8ad3",
4
4
  "description": "OpenID for Verifiable Credential Issuance (OpenID4VCI) client",
5
5
  "source": "lib/index.ts",
6
6
  "main": "dist/index.js",
@@ -15,8 +15,8 @@
15
15
  "build": "tsc"
16
16
  },
17
17
  "dependencies": {
18
- "@sphereon/oid4vci-common": "0.10.3",
19
- "@sphereon/ssi-types": "^0.23.0",
18
+ "@sphereon/oid4vci-common": "0.10.4-next.119+a0d8ad3",
19
+ "@sphereon/ssi-types": "0.25.1-unstable.87",
20
20
  "cross-fetch": "^3.1.8",
21
21
  "debug": "^4.3.4"
22
22
  },
@@ -69,5 +69,5 @@
69
69
  "OIDC4VCI",
70
70
  "OID4VCI"
71
71
  ],
72
- "gitHead": "4d46a7282a475c4e78d496f82f24114f700ee5e0"
72
+ "gitHead": "a0d8ad364f228b98c1b4e8aa4350652bd676eec5"
73
73
  }
@@ -1,30 +0,0 @@
1
- import { JWK, Jwt, ProofOfPossession, ProofOfPossessionCallbacks, Typ } from '@sphereon/oid4vci-common';
2
- /**
3
- *
4
- * - proofOfPossessionCallback: JWTSignerCallback
5
- * Mandatory if you want to create (sign) ProofOfPossession
6
- * - proofOfPossessionVerifierCallback?: JWTVerifyCallback
7
- * If exists, verifies the ProofOfPossession
8
- * - proofOfPossessionCallbackArgs: ProofOfPossessionCallbackArgs
9
- * arguments needed for signing ProofOfPossession
10
- * @param callbacks:
11
- * - proofOfPossessionCallback: JWTSignerCallback
12
- * Mandatory to create (sign) ProofOfPossession
13
- * - proofOfPossessionVerifierCallback?: JWTVerifyCallback
14
- * If exists, verifies the ProofOfPossession
15
- * @param jwtProps
16
- * @param existingJwt
17
- * - Optional, clientId of the party requesting the credential
18
- */
19
- export declare const createProofOfPossession: <DIDDoc>(callbacks: ProofOfPossessionCallbacks<DIDDoc>, jwtProps?: JwtProps, existingJwt?: Jwt) => Promise<ProofOfPossession>;
20
- export interface JwtProps {
21
- typ?: Typ;
22
- kid?: string;
23
- jwk?: JWK;
24
- issuer?: string;
25
- clientId?: string;
26
- alg?: string;
27
- jti?: string;
28
- nonce?: string;
29
- }
30
- //# sourceMappingURL=ProofUtil.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ProofUtil.d.ts","sourceRoot":"","sources":["../../lib/functions/ProofUtil.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,GAAG,EAEH,GAAG,EAGH,iBAAiB,EACjB,0BAA0B,EAC1B,GAAG,EACJ,MAAM,0BAA0B,CAAC;AAKlC;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,uBAAuB,qEAEvB,QAAQ,gBACL,GAAG,KAChB,QAAQ,iBAAiB,CA0B3B,CAAC;AAQF,MAAM,WAAW,QAAQ;IACvB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
@@ -1,106 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.createProofOfPossession = void 0;
16
- const oid4vci_common_1 = require("@sphereon/oid4vci-common");
17
- const debug_1 = __importDefault(require("debug"));
18
- const debug = (0, debug_1.default)('sphereon:openid4vci:token');
19
- /**
20
- *
21
- * - proofOfPossessionCallback: JWTSignerCallback
22
- * Mandatory if you want to create (sign) ProofOfPossession
23
- * - proofOfPossessionVerifierCallback?: JWTVerifyCallback
24
- * If exists, verifies the ProofOfPossession
25
- * - proofOfPossessionCallbackArgs: ProofOfPossessionCallbackArgs
26
- * arguments needed for signing ProofOfPossession
27
- * @param callbacks:
28
- * - proofOfPossessionCallback: JWTSignerCallback
29
- * Mandatory to create (sign) ProofOfPossession
30
- * - proofOfPossessionVerifierCallback?: JWTVerifyCallback
31
- * If exists, verifies the ProofOfPossession
32
- * @param jwtProps
33
- * @param existingJwt
34
- * - Optional, clientId of the party requesting the credential
35
- */
36
- const createProofOfPossession = (callbacks, jwtProps, existingJwt) => __awaiter(void 0, void 0, void 0, function* () {
37
- if (!callbacks.signCallback) {
38
- debug(`no jwt signer callback or arguments supplied!`);
39
- throw new Error(oid4vci_common_1.BAD_PARAMS);
40
- }
41
- const signerArgs = createJWT(jwtProps, existingJwt);
42
- const jwt = yield callbacks.signCallback(signerArgs, signerArgs.header.kid);
43
- const proof = {
44
- proof_type: 'jwt',
45
- jwt,
46
- };
47
- try {
48
- partiallyValidateJWS(jwt);
49
- if (callbacks.verifyCallback) {
50
- debug(`Calling supplied verify callback....`);
51
- yield callbacks.verifyCallback({ jwt, kid: signerArgs.header.kid });
52
- debug(`Supplied verify callback return success result`);
53
- }
54
- }
55
- catch (_a) {
56
- debug(`JWS was not valid`);
57
- throw new Error(oid4vci_common_1.JWS_NOT_VALID);
58
- }
59
- debug(`Proof of Possession JWT:\r\n${jwt}`);
60
- return proof;
61
- });
62
- exports.createProofOfPossession = createProofOfPossession;
63
- const partiallyValidateJWS = (jws) => {
64
- if (jws.split('.').length !== 3 || !jws.startsWith('ey')) {
65
- throw new Error(oid4vci_common_1.JWS_NOT_VALID);
66
- }
67
- };
68
- const createJWT = (jwtProps, existingJwt) => {
69
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
70
- const aud = getJwtProperty('aud', true, jwtProps === null || jwtProps === void 0 ? void 0 : jwtProps.issuer, (_a = existingJwt === null || existingJwt === void 0 ? void 0 : existingJwt.payload) === null || _a === void 0 ? void 0 : _a.aud);
71
- const iss = getJwtProperty('iss', false, jwtProps === null || jwtProps === void 0 ? void 0 : jwtProps.clientId, (_b = existingJwt === null || existingJwt === void 0 ? void 0 : existingJwt.payload) === null || _b === void 0 ? void 0 : _b.iss);
72
- const jti = getJwtProperty('jti', false, jwtProps === null || jwtProps === void 0 ? void 0 : jwtProps.jti, (_c = existingJwt === null || existingJwt === void 0 ? void 0 : existingJwt.payload) === null || _c === void 0 ? void 0 : _c.jti);
73
- const typ = getJwtProperty('typ', true, jwtProps === null || jwtProps === void 0 ? void 0 : jwtProps.typ, (_d = existingJwt === null || existingJwt === void 0 ? void 0 : existingJwt.header) === null || _d === void 0 ? void 0 : _d.typ, 'jwt');
74
- const nonce = getJwtProperty('nonce', false, jwtProps === null || jwtProps === void 0 ? void 0 : jwtProps.nonce, (_e = existingJwt === null || existingJwt === void 0 ? void 0 : existingJwt.payload) === null || _e === void 0 ? void 0 : _e.nonce); // Officially this is required, but some implementations don't have it
75
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
76
- const alg = getJwtProperty('alg', false, jwtProps === null || jwtProps === void 0 ? void 0 : jwtProps.alg, (_f = existingJwt === null || existingJwt === void 0 ? void 0 : existingJwt.header) === null || _f === void 0 ? void 0 : _f.alg, 'ES256');
77
- const kid = getJwtProperty('kid', false, jwtProps === null || jwtProps === void 0 ? void 0 : jwtProps.kid, (_g = existingJwt === null || existingJwt === void 0 ? void 0 : existingJwt.header) === null || _g === void 0 ? void 0 : _g.kid);
78
- const jwk = getJwtProperty('jwk', false, jwtProps === null || jwtProps === void 0 ? void 0 : jwtProps.jwk, (_h = existingJwt === null || existingJwt === void 0 ? void 0 : existingJwt.header) === null || _h === void 0 ? void 0 : _h.jwk);
79
- const jwt = existingJwt ? existingJwt : {};
80
- const now = +new Date();
81
- const jwtPayload = Object.assign(Object.assign({ aud, iat: (_k = (_j = jwt.payload) === null || _j === void 0 ? void 0 : _j.iat) !== null && _k !== void 0 ? _k : Math.round(now / 1000 - 60), exp: (_m = (_l = jwt.payload) === null || _l === void 0 ? void 0 : _l.exp) !== null && _m !== void 0 ? _m : Math.round(now / 1000 + 10 * 60), nonce }, (iss ? { iss } : {})), (jti ? { jti } : {}));
82
- const jwtHeader = {
83
- typ,
84
- alg,
85
- kid,
86
- jwk,
87
- };
88
- return {
89
- payload: Object.assign(Object.assign({}, jwt.payload), jwtPayload),
90
- header: Object.assign(Object.assign({}, jwt.header), jwtHeader),
91
- };
92
- };
93
- const getJwtProperty = (propertyName, required, option, jwtProperty, defaultValue) => {
94
- if (typeof option === 'string' && option && jwtProperty && option !== jwtProperty) {
95
- throw Error(`Cannot have a property '${propertyName}' with value '${option}' and different JWT value '${jwtProperty}' at the same time`);
96
- }
97
- let result = (jwtProperty ? jwtProperty : option);
98
- if (!result) {
99
- if (required) {
100
- throw Error(`No ${propertyName} property provided either in a JWT or as option`);
101
- }
102
- result = defaultValue;
103
- }
104
- return result;
105
- };
106
- //# sourceMappingURL=ProofUtil.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ProofUtil.js","sourceRoot":"","sources":["../../lib/functions/ProofUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6DAWkC;AAClC,kDAA0B;AAE1B,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,2BAA2B,CAAC,CAAC;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACI,MAAM,uBAAuB,GAAG,CACrC,SAA6C,EAC7C,QAAmB,EACnB,WAAiB,EACW,EAAE;IAC9B,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC;QAC5B,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,2BAAU,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5E,MAAM,KAAK,GAAG;QACZ,UAAU,EAAE,KAAK;QACjB,GAAG;KACiB,CAAC;IAEvB,IAAI,CAAC;QACH,oBAAoB,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,SAAS,CAAC,cAAc,EAAE,CAAC;YAC7B,KAAK,CAAC,sCAAsC,CAAC,CAAC;YAC9C,MAAM,SAAS,CAAC,cAAc,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,UAAU,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;YACpE,KAAK,CAAC,gDAAgD,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAAC,WAAM,CAAC;QACP,KAAK,CAAC,mBAAmB,CAAC,CAAC;QA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
- ProofOfPossessionCallbacks,
11
- Typ,
12
- } from '@sphereon/oid4vci-common';
13
- import Debug from 'debug';
14
-
15
- const debug = Debug('sphereon:openid4vci:token');
16
-
17
- /**
18
- *
19
- * - proofOfPossessionCallback: JWTSignerCallback
20
- * Mandatory if you want to create (sign) ProofOfPossession
21
- * - proofOfPossessionVerifierCallback?: JWTVerifyCallback
22
- * If exists, verifies the ProofOfPossession
23
- * - proofOfPossessionCallbackArgs: ProofOfPossessionCallbackArgs
24
- * arguments needed for signing ProofOfPossession
25
- * @param callbacks:
26
- * - proofOfPossessionCallback: JWTSignerCallback
27
- * Mandatory to create (sign) ProofOfPossession
28
- * - proofOfPossessionVerifierCallback?: JWTVerifyCallback
29
- * If exists, verifies the ProofOfPossession
30
- * @param jwtProps
31
- * @param existingJwt
32
- * - Optional, clientId of the party requesting the credential
33
- */
34
- export const createProofOfPossession = async <DIDDoc>(
35
- callbacks: ProofOfPossessionCallbacks<DIDDoc>,
36
- jwtProps?: JwtProps,
37
- existingJwt?: Jwt,
38
- ): Promise<ProofOfPossession> => {
39
- if (!callbacks.signCallback) {
40
- debug(`no jwt signer callback or arguments supplied!`);
41
- throw new Error(BAD_PARAMS);
42
- }
43
-
44
- const signerArgs = createJWT(jwtProps, existingJwt);
45
- const jwt = await callbacks.signCallback(signerArgs, signerArgs.header.kid);
46
- const proof = {
47
- proof_type: 'jwt',
48
- jwt,
49
- } as ProofOfPossession;
50
-
51
- try {
52
- partiallyValidateJWS(jwt);
53
- if (callbacks.verifyCallback) {
54
- debug(`Calling supplied verify callback....`);
55
- await callbacks.verifyCallback({ jwt, kid: signerArgs.header.kid });
56
- debug(`Supplied verify callback return success result`);
57
- }
58
- } catch {
59
- debug(`JWS was not valid`);
60
- throw new Error(JWS_NOT_VALID);
61
- }
62
- debug(`Proof of Possession JWT:\r\n${jwt}`);
63
- return proof;
64
- };
65
-
66
- const partiallyValidateJWS = (jws: string): void => {
67
- if (jws.split('.').length !== 3 || !jws.startsWith('ey')) {
68
- throw new Error(JWS_NOT_VALID);
69
- }
70
- };
71
-
72
- export interface JwtProps {
73
- typ?: Typ;
74
- kid?: string;
75
- jwk?: JWK;
76
- issuer?: string;
77
- clientId?: string;
78
- alg?: string;
79
- jti?: string;
80
- nonce?: string;
81
- }
82
-
83
- const createJWT = (jwtProps?: JwtProps, existingJwt?: Jwt): Jwt => {
84
- const aud = getJwtProperty<string | string[]>('aud', true, jwtProps?.issuer, existingJwt?.payload?.aud);
85
- const iss = getJwtProperty<string>('iss', false, jwtProps?.clientId, existingJwt?.payload?.iss);
86
- const jti = getJwtProperty<string>('jti', false, jwtProps?.jti, existingJwt?.payload?.jti);
87
- const typ = getJwtProperty<string>('typ', true, jwtProps?.typ, existingJwt?.header?.typ, 'jwt');
88
- const nonce = getJwtProperty<string>('nonce', false, jwtProps?.nonce, existingJwt?.payload?.nonce); // Officially this is required, but some implementations don't have it
89
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
90
- const alg = getJwtProperty<string>('alg', false, jwtProps?.alg, existingJwt?.header?.alg, 'ES256')!;
91
- const kid = getJwtProperty<string>('kid', false, jwtProps?.kid, existingJwt?.header?.kid);
92
- const jwk = getJwtProperty<BaseJWK>('jwk', false, jwtProps?.jwk, existingJwt?.header?.jwk);
93
- const jwt: Partial<Jwt> = existingJwt ? existingJwt : {};
94
- const now = +new Date();
95
- const jwtPayload: Partial<JWTPayload> = {
96
- aud,
97
- iat: jwt.payload?.iat ?? Math.round(now / 1000 - 60), // Let's ensure we subtract 60 seconds for potential time offsets
98
- exp: jwt.payload?.exp ?? Math.round(now / 1000 + 10 * 60),
99
- nonce,
100
- ...(iss ? { iss } : {}),
101
- ...(jti ? { jti } : {}),
102
- };
103
-
104
- const jwtHeader: JWTHeader = {
105
- typ,
106
- alg,
107
- kid,
108
- jwk,
109
- };
110
- return {
111
- payload: { ...jwt.payload, ...jwtPayload },
112
- header: { ...jwt.header, ...jwtHeader },
113
- };
114
- };
115
-
116
- const getJwtProperty = <T>(propertyName: string, required: boolean, option?: string | JWK, jwtProperty?: T, defaultValue?: T): T | undefined => {
117
- if (typeof option === 'string' && option && jwtProperty && option !== jwtProperty) {
118
- throw Error(`Cannot have a property '${propertyName}' with value '${option}' and different JWT value '${jwtProperty}' at the same time`);
119
- }
120
- let result = (jwtProperty ? jwtProperty : option) as T | undefined;
121
- if (!result) {
122
- if (required) {
123
- throw Error(`No ${propertyName} property provided either in a JWT or as option`);
124
- }
125
- result = defaultValue;
126
- }
127
- return result;
128
- };