@credo-ts/openid4vc 0.5.8 → 0.5.9-alpha-20240718141958

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 (30) hide show
  1. package/build/openid4vc-holder/OpenId4VcHolderApi.d.ts +27 -1
  2. package/build/openid4vc-holder/OpenId4VcHolderApi.js +54 -2
  3. package/build/openid4vc-holder/OpenId4VcHolderApi.js.map +1 -1
  4. package/build/openid4vc-holder/OpenId4VciHolderService.d.ts +13 -3
  5. package/build/openid4vc-holder/OpenId4VciHolderService.js +128 -127
  6. package/build/openid4vc-holder/OpenId4VciHolderService.js.map +1 -1
  7. package/build/openid4vc-holder/OpenId4VciHolderServiceOptions.d.ts +63 -4
  8. package/build/openid4vc-holder/OpenId4VciHolderServiceOptions.js.map +1 -1
  9. package/build/openid4vc-issuer/OpenId4VcIssuerApi.d.ts +3 -2
  10. package/build/openid4vc-issuer/OpenId4VcIssuerApi.js +9 -1
  11. package/build/openid4vc-issuer/OpenId4VcIssuerApi.js.map +1 -1
  12. package/build/openid4vc-issuer/OpenId4VcIssuerService.js +74 -22
  13. package/build/openid4vc-issuer/OpenId4VcIssuerService.js.map +1 -1
  14. package/build/openid4vc-issuer/OpenId4VcIssuerServiceOptions.d.ts +24 -3
  15. package/build/openid4vc-issuer/repository/OpenId4VcCredentialOfferSessionStateManager.js +18 -8
  16. package/build/openid4vc-issuer/repository/OpenId4VcCredentialOfferSessionStateManager.js.map +1 -1
  17. package/build/openid4vc-issuer/repository/OpenId4VcIssuerRecord.d.ts +12 -4
  18. package/build/openid4vc-issuer/repository/OpenId4VcIssuerRecord.js +5 -2
  19. package/build/openid4vc-issuer/repository/OpenId4VcIssuerRecord.js.map +1 -1
  20. package/build/openid4vc-issuer/router/metadataEndpoint.js +4 -0
  21. package/build/openid4vc-issuer/router/metadataEndpoint.js.map +1 -1
  22. package/build/shared/issuerMetadataUtils.d.ts +14 -5
  23. package/build/shared/issuerMetadataUtils.js +134 -26
  24. package/build/shared/issuerMetadataUtils.js.map +1 -1
  25. package/build/shared/models/index.d.ts +9 -6
  26. package/build/shared/models/index.js.map +1 -1
  27. package/build/shared/utils.d.ts +2 -0
  28. package/build/shared/utils.js +5 -0
  29. package/build/shared/utils.js.map +1 -1
  30. package/package.json +7 -7
@@ -1,4 +1,4 @@
1
- import type { OpenId4VciResolvedCredentialOffer, OpenId4VciResolvedAuthorizationRequest, OpenId4VciAuthCodeFlowOptions, OpenId4VciAcceptCredentialOfferOptions } from './OpenId4VciHolderServiceOptions';
1
+ import type { OpenId4VciResolvedCredentialOffer, OpenId4VciResolvedAuthorizationRequest, OpenId4VciAuthCodeFlowOptions, OpenId4VciAcceptCredentialOfferOptions, OpenId4VciTokenRequestOptions as OpenId4VciRequestTokenOptions, OpenId4VciCredentialRequestOptions as OpenId4VciRequestCredentialOptions, OpenId4VciSendNotificationOptions, OpenId4VciRequestTokenResponse } from './OpenId4VciHolderServiceOptions';
2
2
  import type { OpenId4VcSiopAcceptAuthorizationRequestOptions } from './OpenId4vcSiopHolderServiceOptions';
3
3
  import { AgentContext } from '@credo-ts/core';
4
4
  import { OpenId4VciHolderService } from './OpenId4VciHolderService';
@@ -68,16 +68,42 @@ export declare class OpenId4VcHolderApi {
68
68
  resolveIssuanceAuthorizationRequest(resolvedCredentialOffer: OpenId4VciResolvedCredentialOffer, authCodeFlowOptions: OpenId4VciAuthCodeFlowOptions): Promise<OpenId4VciResolvedAuthorizationRequest>;
69
69
  /**
70
70
  * Accepts a credential offer using the pre-authorized code flow.
71
+ * @deprecated use @see requestToken and @see requestCredentials instead
72
+ *
71
73
  * @param resolvedCredentialOffer Obtained through @see resolveCredentialOffer
72
74
  * @param acceptCredentialOfferOptions
73
75
  */
74
76
  acceptCredentialOfferUsingPreAuthorizedCode(resolvedCredentialOffer: OpenId4VciResolvedCredentialOffer, acceptCredentialOfferOptions: OpenId4VciAcceptCredentialOfferOptions): Promise<import("@credo-ts/core").VerifiableCredential[]>;
75
77
  /**
76
78
  * Accepts a credential offer using the authorization code flow.
79
+ * @deprecated use @see requestToken and @see requestCredentials instead
80
+ *
77
81
  * @param resolvedCredentialOffer Obtained through @see resolveCredentialOffer
78
82
  * @param resolvedAuthorizationRequest Obtained through @see resolveIssuanceAuthorizationRequest
79
83
  * @param code The authorization code obtained via the authorization request URI
80
84
  * @param acceptCredentialOfferOptions
81
85
  */
82
86
  acceptCredentialOfferUsingAuthorizationCode(resolvedCredentialOffer: OpenId4VciResolvedCredentialOffer, resolvedAuthorizationRequest: OpenId4VciResolvedAuthorizationRequest, code: string, acceptCredentialOfferOptions: OpenId4VciAcceptCredentialOfferOptions): Promise<import("@credo-ts/core").VerifiableCredential[]>;
87
+ /**
88
+ * Requests the token to be used for credential requests.
89
+ *
90
+ * @param options.resolvedCredentialOffer Obtained through @see resolveCredentialOffer
91
+ * @param options.userPin The user's PIN
92
+ * @param options.resolvedAuthorizationRequest Obtained through @see resolveIssuanceAuthorizationRequest
93
+ * @param options.code The authorization code obtained via the authorization request URI
94
+ */
95
+ requestToken(options: OpenId4VciRequestTokenOptions): Promise<OpenId4VciRequestTokenResponse>;
96
+ /**
97
+ * Request a credential. Can be used with both the pre-authorized code flow and the authorization code flow.
98
+ *
99
+ * @param options.resolvedCredentialOffer Obtained through @see resolveCredentialOffer
100
+ * @param options.tokenResponse Obtained through @see requestAccessToken
101
+ */
102
+ requestCredentials(options: OpenId4VciRequestCredentialOptions): Promise<import("./OpenId4VciHolderServiceOptions").OpenId4VciCredentialResponse[]>;
103
+ /**
104
+ * Send a notification event to the credential issuer
105
+ *
106
+ * @param options OpenId4VciSendNotificationOptions
107
+ */
108
+ sendNotification(options: OpenId4VciSendNotificationOptions): Promise<void>;
83
109
  }
@@ -8,6 +8,17 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.OpenId4VcHolderApi = void 0;
13
24
  const core_1 = require("@credo-ts/core");
@@ -81,28 +92,69 @@ let OpenId4VcHolderApi = class OpenId4VcHolderApi {
81
92
  }
82
93
  /**
83
94
  * Accepts a credential offer using the pre-authorized code flow.
95
+ * @deprecated use @see requestToken and @see requestCredentials instead
96
+ *
84
97
  * @param resolvedCredentialOffer Obtained through @see resolveCredentialOffer
85
98
  * @param acceptCredentialOfferOptions
86
99
  */
87
100
  async acceptCredentialOfferUsingPreAuthorizedCode(resolvedCredentialOffer, acceptCredentialOfferOptions) {
88
- return this.openId4VciHolderService.acceptCredentialOffer(this.agentContext, {
101
+ const credentialResponse = await this.openId4VciHolderService.acceptCredentialOffer(this.agentContext, {
89
102
  resolvedCredentialOffer,
90
103
  acceptCredentialOfferOptions,
91
104
  });
105
+ return credentialResponse.map((credentialResponse) => credentialResponse.credential);
92
106
  }
93
107
  /**
94
108
  * Accepts a credential offer using the authorization code flow.
109
+ * @deprecated use @see requestToken and @see requestCredentials instead
110
+ *
95
111
  * @param resolvedCredentialOffer Obtained through @see resolveCredentialOffer
96
112
  * @param resolvedAuthorizationRequest Obtained through @see resolveIssuanceAuthorizationRequest
97
113
  * @param code The authorization code obtained via the authorization request URI
98
114
  * @param acceptCredentialOfferOptions
99
115
  */
100
116
  async acceptCredentialOfferUsingAuthorizationCode(resolvedCredentialOffer, resolvedAuthorizationRequest, code, acceptCredentialOfferOptions) {
101
- return this.openId4VciHolderService.acceptCredentialOffer(this.agentContext, {
117
+ const credentialResponse = await this.openId4VciHolderService.acceptCredentialOffer(this.agentContext, {
102
118
  resolvedCredentialOffer,
103
119
  resolvedAuthorizationRequestWithCode: Object.assign(Object.assign({}, resolvedAuthorizationRequest), { code }),
104
120
  acceptCredentialOfferOptions,
105
121
  });
122
+ return credentialResponse.map((credentialResponse) => credentialResponse.credential);
123
+ }
124
+ /**
125
+ * Requests the token to be used for credential requests.
126
+ *
127
+ * @param options.resolvedCredentialOffer Obtained through @see resolveCredentialOffer
128
+ * @param options.userPin The user's PIN
129
+ * @param options.resolvedAuthorizationRequest Obtained through @see resolveIssuanceAuthorizationRequest
130
+ * @param options.code The authorization code obtained via the authorization request URI
131
+ */
132
+ async requestToken(options) {
133
+ const { access_token: accessToken, c_nonce: cNonce } = await this.openId4VciHolderService.requestAccessToken(this.agentContext, options);
134
+ return { accessToken, cNonce };
135
+ }
136
+ /**
137
+ * Request a credential. Can be used with both the pre-authorized code flow and the authorization code flow.
138
+ *
139
+ * @param options.resolvedCredentialOffer Obtained through @see resolveCredentialOffer
140
+ * @param options.tokenResponse Obtained through @see requestAccessToken
141
+ */
142
+ async requestCredentials(options) {
143
+ const { resolvedCredentialOffer, cNonce, accessToken } = options, credentialRequestOptions = __rest(options, ["resolvedCredentialOffer", "cNonce", "accessToken"]);
144
+ return this.openId4VciHolderService.acceptCredentialOffer(this.agentContext, {
145
+ resolvedCredentialOffer,
146
+ acceptCredentialOfferOptions: credentialRequestOptions,
147
+ accessToken,
148
+ cNonce,
149
+ });
150
+ }
151
+ /**
152
+ * Send a notification event to the credential issuer
153
+ *
154
+ * @param options OpenId4VciSendNotificationOptions
155
+ */
156
+ async sendNotification(options) {
157
+ return this.openId4VciHolderService.sendNotification(options);
106
158
  }
107
159
  };
108
160
  exports.OpenId4VcHolderApi = OpenId4VcHolderApi;
@@ -1 +1 @@
1
- {"version":3,"file":"OpenId4VcHolderApi.js","sourceRoot":"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1G,IAAI,CAAC,YAAY,EACjB,OAAO,CACR,CAAA;QACD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAA;IAChC,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,kBAAkB,CAAC,OAA2C;QACzE,MAAM,EAAE,uBAAuB,EAAE,MAAM,EAAE,WAAW,KAAkC,OAAO,EAApC,wBAAwB,UAAK,OAAO,EAAvF,oDAA6E,CAAU,CAAA;QAE7F,OAAO,IAAI,CAAC,uBAAuB,CAAC,qBAAqB,CAAC,IAAI,CAAC,YAAY,EAAE;YAC3E,uBAAuB;YACvB,4BAA4B,EAAE,wBAAwB;YACtD,WAAW;YACX,MAAM;SACP,CAAC,CAAA;IACJ,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,gBAAgB,CAAC,OAA0C;QACtE,OAAO,IAAI,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAC/D,CAAC;CACF,CAAA;AA/JY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,iBAAU,GAAE;qCAGa,mBAAY;QACD,iDAAuB;QACpB,uDAA0B;GAJrD,kBAAkB,CA+J9B"}
@@ -1,6 +1,8 @@
1
- import type { OpenId4VciAuthCodeFlowOptions, OpenId4VciAcceptCredentialOfferOptions, OpenId4VciResolvedCredentialOffer, OpenId4VciResolvedAuthorizationRequest, OpenId4VciResolvedAuthorizationRequestWithCode } from './OpenId4VciHolderServiceOptions';
2
- import type { AgentContext, VerifiableCredential } from '@credo-ts/core';
1
+ import type { OpenId4VciAuthCodeFlowOptions, OpenId4VciResolvedCredentialOffer, OpenId4VciResolvedAuthorizationRequest, OpenId4VciResolvedAuthorizationRequestWithCode, OpenId4VciCredentialResponse, OpenId4VciNotificationEvent, OpenId4VciAcceptCredentialOfferOptions, OpenId4VciTokenRequestOptions } from './OpenId4VciHolderServiceOptions';
2
+ import type { AgentContext } from '@credo-ts/core';
3
+ import type { AccessTokenResponse } from '@sphereon/oid4vci-common';
3
4
  import { JwsService, Logger, W3cCredentialService } from '@credo-ts/core';
5
+ import { OpenId4VciNotificationMetadata } from './OpenId4VciHolderServiceOptions';
4
6
  export declare class OpenId4VciHolderService {
5
7
  private logger;
6
8
  private w3cCredentialService;
@@ -9,11 +11,19 @@ export declare class OpenId4VciHolderService {
9
11
  resolveCredentialOffer(credentialOffer: string): Promise<OpenId4VciResolvedCredentialOffer>;
10
12
  private getAuthDetailsFromOfferedCredential;
11
13
  resolveAuthorizationRequest(agentContext: AgentContext, resolvedCredentialOffer: OpenId4VciResolvedCredentialOffer, authCodeFlowOptions: OpenId4VciAuthCodeFlowOptions): Promise<OpenId4VciResolvedAuthorizationRequest>;
14
+ sendNotification(options: {
15
+ notificationMetadata: OpenId4VciNotificationMetadata;
16
+ notificationEvent: OpenId4VciNotificationEvent;
17
+ accessToken: string;
18
+ }): Promise<void>;
19
+ requestAccessToken(agentContext: AgentContext, options: OpenId4VciTokenRequestOptions): Promise<AccessTokenResponse>;
12
20
  acceptCredentialOffer(agentContext: AgentContext, options: {
13
21
  resolvedCredentialOffer: OpenId4VciResolvedCredentialOffer;
14
22
  acceptCredentialOfferOptions: OpenId4VciAcceptCredentialOfferOptions;
15
23
  resolvedAuthorizationRequestWithCode?: OpenId4VciResolvedAuthorizationRequestWithCode;
16
- }): Promise<VerifiableCredential[]>;
24
+ accessToken?: string;
25
+ cNonce?: string;
26
+ }): Promise<OpenId4VciCredentialResponse[]>;
17
27
  /**
18
28
  * Get the options for the credential request. Internally this will resolve the proof of possession
19
29
  * requirements, and based on that it will call the proofOfPossessionVerificationMethodResolver to
@@ -38,7 +38,7 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
38
38
  this.logger = logger;
39
39
  }
40
40
  async resolveCredentialOffer(credentialOffer) {
41
- var _a;
41
+ var _a, _b;
42
42
  const client = await oid4vci_client_1.OpenID4VCIClient.fromURI({
43
43
  uri: credentialOffer,
44
44
  resolveOfferUri: true,
@@ -49,22 +49,27 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
49
49
  if (!((_a = client.credentialOffer) === null || _a === void 0 ? void 0 : _a.credential_offer)) {
50
50
  throw new core_1.CredoError(`Could not resolve credential offer from '${credentialOffer}'`);
51
51
  }
52
- const credentialOfferPayload = client.credentialOffer.credential_offer;
53
- const metadata = await client.retrieveServerMetadata();
54
- if (!metadata.credentialIssuerMetadata) {
52
+ const metadata = client.endpointMetadata;
53
+ const credentialIssuerMetadata = metadata.credentialIssuerMetadata;
54
+ if (!credentialIssuerMetadata) {
55
55
  throw new core_1.CredoError(`Could not retrieve issuer metadata from '${metadata.issuer}'`);
56
56
  }
57
- const issuerMetadata = metadata.credentialIssuerMetadata;
58
57
  this.logger.info('Fetched server metadata', {
59
58
  issuer: metadata.issuer,
60
59
  credentialEndpoint: metadata.credential_endpoint,
61
60
  tokenEndpoint: metadata.token_endpoint,
62
61
  });
63
62
  this.logger.debug('Full server metadata', metadata);
63
+ const credentialOfferPayload = client.credentialOffer.credential_offer;
64
+ const offeredCredentialsData = (0, utils_1.isCredentialOfferV1Draft13)(credentialOfferPayload)
65
+ ? credentialOfferPayload.credential_configuration_ids
66
+ : credentialOfferPayload.credentials;
67
+ const offeredCredentials = (0, issuerMetadataUtils_1.getOfferedCredentials)(offeredCredentialsData, (_b = credentialIssuerMetadata.credentials_supported) !== null && _b !== void 0 ? _b : credentialIssuerMetadata.credential_configurations_supported);
64
68
  return {
65
- metadata: Object.assign(Object.assign({}, metadata), { credentialIssuerMetadata: issuerMetadata }),
69
+ metadata: Object.assign(Object.assign({}, metadata), { credentialIssuerMetadata: credentialIssuerMetadata }),
70
+ offeredCredentials,
66
71
  credentialOfferPayload,
67
- offeredCredentials: (0, issuerMetadataUtils_1.getOfferedCredentials)(credentialOfferPayload.credentials, issuerMetadata.credentials_supported),
72
+ credentialOfferRequestWithBaseUrl: client.credentialOffer,
68
73
  version: client.version(),
69
74
  };
70
75
  }
@@ -98,8 +103,8 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
98
103
  }
99
104
  }
100
105
  async resolveAuthorizationRequest(agentContext, resolvedCredentialOffer, authCodeFlowOptions) {
101
- const { credentialOfferPayload, metadata, offeredCredentials } = resolvedCredentialOffer;
102
- const codeVerifier = (await Promise.allSettled([agentContext.wallet.generateNonce(), agentContext.wallet.generateNonce()])).join();
106
+ const { metadata, offeredCredentials } = resolvedCredentialOffer;
107
+ const codeVerifier = (await Promise.all([agentContext.wallet.generateNonce(), agentContext.wallet.generateNonce()])).join();
103
108
  const codeVerifierSha256 = core_1.Hasher.hash(codeVerifier, 'sha-256');
104
109
  const codeChallenge = core_1.TypedArrayEncoder.toBase64URL(codeVerifierSha256);
105
110
  this.logger.debug('Converted code_verifier to code_challenge', {
@@ -114,52 +119,58 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
114
119
  .map((credential) => this.getAuthDetailsFromOfferedCredential(credential, authDetailsLocation))
115
120
  .filter((authDetail) => authDetail !== undefined);
116
121
  const { clientId, redirectUri, scope } = authCodeFlowOptions;
117
- const authorizationRequestUri = await createAuthorizationRequestUri({
118
- clientId,
119
- codeChallenge,
120
- redirectUri,
121
- credentialOffer: credentialOfferPayload,
122
- codeChallengeMethod: oid4vci_common_1.CodeChallengeMethod.S256,
123
- // TODO: Read HAIP SdJwtVc's should always be requested via scopes
124
- // TODO: should we now always use scopes instead of authDetails? or both????
125
- scope: scope !== null && scope !== void 0 ? scope : [],
126
- authDetails,
127
- metadata,
122
+ const vciClientState = {
123
+ state: {
124
+ credentialOffer: resolvedCredentialOffer.credentialOfferRequestWithBaseUrl,
125
+ clientId,
126
+ credentialIssuer: metadata.issuer,
127
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
128
+ endpointMetadata: metadata, // will be v11 / v13 based on version
129
+ pkce: {
130
+ codeChallenge,
131
+ codeChallengeMethod: oid4vci_common_1.CodeChallengeMethod.S256,
132
+ codeVerifier,
133
+ },
134
+ },
135
+ };
136
+ const client = resolvedCredentialOffer.version === oid4vci_common_1.OpenId4VCIVersion.VER_1_0_11
137
+ ? await oid4vci_client_1.OpenID4VCIClientV1_0_11.fromState(vciClientState)
138
+ : await oid4vci_client_1.OpenID4VCIClientV1_0_13.fromState(vciClientState);
139
+ const authorizationRequestUri = await client.createAuthorizationRequestUrl({
140
+ authorizationRequest: {
141
+ redirectUri,
142
+ scope: scope ? scope[0] : 'openid',
143
+ authorizationDetails: authDetails,
144
+ parMode: oid4vci_common_1.PARMode.AUTO,
145
+ },
128
146
  });
129
147
  return Object.assign(Object.assign({}, authCodeFlowOptions), { codeVerifier,
130
148
  authorizationRequestUri });
131
149
  }
132
- async acceptCredentialOffer(agentContext, options) {
133
- var _a, _b, _c, _d;
134
- const { resolvedCredentialOffer, acceptCredentialOfferOptions, resolvedAuthorizationRequestWithCode } = options;
135
- const { credentialOfferPayload, metadata, version, offeredCredentials } = resolvedCredentialOffer;
136
- const { credentialsToRequest, userPin, credentialBindingResolver, verifyCredentialStatus } = acceptCredentialOfferOptions;
137
- if ((credentialsToRequest === null || credentialsToRequest === void 0 ? void 0 : credentialsToRequest.length) === 0) {
138
- this.logger.warn(`Accepting 0 credential offers. Returning`);
139
- return [];
140
- }
141
- this.logger.info(`Accepting the following credential offers '${credentialsToRequest}'`);
142
- const supportedJwaSignatureAlgorithms = (0, utils_1.getSupportedJwaSignatureAlgorithms)(agentContext);
143
- const allowedProofOfPossessionSigAlgs = acceptCredentialOfferOptions.allowedProofOfPossessionSignatureAlgorithms;
144
- const possibleProofOfPossessionSigAlgs = allowedProofOfPossessionSigAlgs
145
- ? allowedProofOfPossessionSigAlgs.filter((algorithm) => supportedJwaSignatureAlgorithms.includes(algorithm))
146
- : supportedJwaSignatureAlgorithms;
147
- if (possibleProofOfPossessionSigAlgs.length === 0) {
148
- throw new core_1.CredoError([
149
- `No possible proof of possession signature algorithm found.`,
150
- `Signature algorithms supported by the Agent '${supportedJwaSignatureAlgorithms.join(', ')}'`,
151
- `Allowed Signature algorithms '${allowedProofOfPossessionSigAlgs === null || allowedProofOfPossessionSigAlgs === void 0 ? void 0 : allowedProofOfPossessionSigAlgs.join(', ')}'`,
152
- ].join('\n'));
150
+ async sendNotification(options) {
151
+ const { notificationMetadata, notificationEvent } = options;
152
+ const { notificationId, notificationEndpoint } = notificationMetadata;
153
+ const response = await (0, oid4vci_common_1.post)(notificationEndpoint, { notification_id: notificationId, event: notificationEvent }, {
154
+ bearerToken: options.accessToken,
155
+ contentType: 'application/json',
156
+ });
157
+ if (!response.successBody) {
158
+ throw new core_1.CredoError(`Failed to send notification event '${notificationId}' to '${notificationEndpoint}'`);
153
159
  }
160
+ }
161
+ async requestAccessToken(agentContext, options) {
162
+ var _a, _b;
163
+ const { resolvedCredentialOffer, txCode, resolvedAuthorizationRequest, code } = options;
164
+ const { metadata, credentialOfferRequestWithBaseUrl } = resolvedCredentialOffer;
154
165
  // acquire the access token
155
166
  let accessTokenResponse;
156
167
  const accessTokenClient = new oid4vci_client_1.AccessTokenClient();
157
- if (resolvedAuthorizationRequestWithCode) {
158
- const { code, codeVerifier, redirectUri } = resolvedAuthorizationRequestWithCode;
168
+ if (resolvedAuthorizationRequest) {
169
+ const { codeVerifier, redirectUri } = resolvedAuthorizationRequest;
159
170
  accessTokenResponse = await accessTokenClient.acquireAccessToken({
160
171
  metadata: metadata,
161
- credentialOffer: { credential_offer: credentialOfferPayload },
162
- pin: userPin,
172
+ credentialOffer: { credential_offer: credentialOfferRequestWithBaseUrl.credential_offer },
173
+ pin: txCode,
163
174
  code,
164
175
  codeVerifier,
165
176
  redirectUri,
@@ -168,25 +179,59 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
168
179
  else {
169
180
  accessTokenResponse = await accessTokenClient.acquireAccessToken({
170
181
  metadata: metadata,
171
- credentialOffer: { credential_offer: credentialOfferPayload },
172
- pin: userPin,
182
+ credentialOffer: { credential_offer: credentialOfferRequestWithBaseUrl.credential_offer },
183
+ pin: txCode,
173
184
  });
174
185
  }
175
186
  if (!accessTokenResponse.successBody) {
176
187
  throw new core_1.CredoError(`could not acquire access token from '${metadata.issuer}'. ${(_a = accessTokenResponse.errorBody) === null || _a === void 0 ? void 0 : _a.error}: ${(_b = accessTokenResponse.errorBody) === null || _b === void 0 ? void 0 : _b.error_description}`);
177
188
  }
178
189
  this.logger.debug('Requested OpenId4VCI Access Token.');
179
- const accessToken = accessTokenResponse.successBody;
190
+ return accessTokenResponse.successBody;
191
+ }
192
+ async acceptCredentialOffer(agentContext, options) {
193
+ var _a, _b, _c;
194
+ const { resolvedCredentialOffer, acceptCredentialOfferOptions } = options;
195
+ const { metadata, version, offeredCredentials } = resolvedCredentialOffer;
196
+ const { credentialsToRequest, credentialBindingResolver, verifyCredentialStatus } = acceptCredentialOfferOptions;
197
+ if ((credentialsToRequest === null || credentialsToRequest === void 0 ? void 0 : credentialsToRequest.length) === 0) {
198
+ this.logger.warn(`Accepting 0 credential offers. Returning`);
199
+ return [];
200
+ }
201
+ this.logger.info(`Accepting the following credential offers '${credentialsToRequest}'`);
202
+ const supportedJwaSignatureAlgorithms = (0, utils_1.getSupportedJwaSignatureAlgorithms)(agentContext);
203
+ const allowedProofOfPossessionSigAlgs = acceptCredentialOfferOptions.allowedProofOfPossessionSignatureAlgorithms;
204
+ const possibleProofOfPossessionSigAlgs = allowedProofOfPossessionSigAlgs
205
+ ? allowedProofOfPossessionSigAlgs.filter((algorithm) => supportedJwaSignatureAlgorithms.includes(algorithm))
206
+ : supportedJwaSignatureAlgorithms;
207
+ if (possibleProofOfPossessionSigAlgs.length === 0) {
208
+ throw new core_1.CredoError([
209
+ `No possible proof of possession signature algorithm found.`,
210
+ `Signature algorithms supported by the Agent '${supportedJwaSignatureAlgorithms.join(', ')}'`,
211
+ `Allowed Signature algorithms '${allowedProofOfPossessionSigAlgs === null || allowedProofOfPossessionSigAlgs === void 0 ? void 0 : allowedProofOfPossessionSigAlgs.join(', ')}'`,
212
+ ].join('\n'));
213
+ }
214
+ const tokenRequestOptions = {
215
+ resolvedCredentialOffer,
216
+ resolvedAuthorizationRequest: options.resolvedAuthorizationRequestWithCode,
217
+ code: (_a = options.resolvedAuthorizationRequestWithCode) === null || _a === void 0 ? void 0 : _a.code,
218
+ txCode: acceptCredentialOfferOptions.userPin,
219
+ };
220
+ const tokenResponse = options.accessToken
221
+ ? { access_token: options.accessToken, c_nonce: options.cNonce }
222
+ : await this.requestAccessToken(agentContext, tokenRequestOptions);
180
223
  const receivedCredentials = [];
181
224
  let newCNonce;
182
- const credentialsSupportedToRequest = (_c = credentialsToRequest === null || credentialsToRequest === void 0 ? void 0 : credentialsToRequest.map((id) => offeredCredentials.find((credential) => credential.id === id)).filter((c, i) => {
225
+ const credentialsSupportedToRequest = (_b = credentialsToRequest === null || credentialsToRequest === void 0 ? void 0 : credentialsToRequest.map((id) => offeredCredentials.find((credential) => credential.id === id)).filter((c, i) => {
183
226
  if (!c) {
184
227
  const offeredCredentialIds = offeredCredentials.map((c) => c.id).join(', ');
185
228
  throw new core_1.CredoError(`Credential to request '${credentialsToRequest[i]}' is not present in offered credentials. Offered credentials are ${offeredCredentialIds}`);
186
229
  }
187
230
  return true;
188
- })) !== null && _c !== void 0 ? _c : offeredCredentials;
189
- for (const offeredCredential of credentialsSupportedToRequest) {
231
+ })) !== null && _b !== void 0 ? _b : offeredCredentials;
232
+ const offeredCredentialConfigurations = (0, issuerMetadataUtils_1.credentialsSupportedV11ToV13)(agentContext, credentialsSupportedToRequest);
233
+ for (const offeredCredentialConfiguration of Object.entries(offeredCredentialConfigurations)) {
234
+ const offeredCredential = offeredCredentialConfiguration[1];
190
235
  // Get all options for the credential request (such as which kid to use, the signature algorithm, etc)
191
236
  const { credentialBinding, signatureAlgorithm } = await this.getCredentialRequestOptions(agentContext, {
192
237
  possibleProofOfPossessionSignatureAlgorithms: possibleProofOfPossessionSigAlgs,
@@ -195,7 +240,7 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
195
240
  });
196
241
  // Create the proof of possession
197
242
  const proofOfPossessionBuilder = oid4vci_client_1.ProofOfPossessionBuilder.fromAccessTokenResponse({
198
- accessTokenResponse: accessToken,
243
+ accessTokenResponse: tokenResponse,
199
244
  callbacks: { signCallback: this.proofOfPossessionSignCallback(agentContext) },
200
245
  version,
201
246
  })
@@ -212,21 +257,25 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
212
257
  const proofOfPossession = await proofOfPossessionBuilder.build();
213
258
  this.logger.debug('Generated JWS', proofOfPossession);
214
259
  // Acquire the credential
215
- const credentialRequestBuilder = new oid4vci_client_1.CredentialRequestClientBuilder();
260
+ const credentialRequestBuilder = oid4vci_client_1.CredentialRequestClientBuilder.fromCredentialOffer({
261
+ credentialOffer: resolvedCredentialOffer.credentialOfferRequestWithBaseUrl,
262
+ metadata: resolvedCredentialOffer.metadata,
263
+ });
216
264
  credentialRequestBuilder
217
265
  .withVersion(version)
218
266
  .withCredentialEndpoint(metadata.credential_endpoint)
219
- .withTokenFromResponse(accessToken);
267
+ .withToken(tokenResponse.access_token);
220
268
  const credentialRequestClient = credentialRequestBuilder.build();
221
269
  const credentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({
222
270
  proofInput: proofOfPossession,
223
271
  credentialTypes: (0, issuerMetadataUtils_1.getTypesFromCredentialSupported)(offeredCredential),
224
272
  format: offeredCredential.format,
225
273
  });
226
- newCNonce = (_d = credentialResponse.successBody) === null || _d === void 0 ? void 0 : _d.c_nonce;
274
+ newCNonce = (_c = credentialResponse.successBody) === null || _c === void 0 ? void 0 : _c.c_nonce;
227
275
  // Create credential, but we don't store it yet (only after the user has accepted the credential)
228
276
  const credential = await this.handleCredentialResponse(agentContext, credentialResponse, {
229
277
  verifyCredentialStatus: verifyCredentialStatus !== null && verifyCredentialStatus !== void 0 ? verifyCredentialStatus : false,
278
+ credentialIssuerMetadata: metadata.credentialIssuerMetadata,
230
279
  });
231
280
  this.logger.debug('Full credential', credential);
232
281
  receivedCredentials.push(credential);
@@ -292,7 +341,7 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
292
341
  * algorithm to use, based on the order of preference.
293
342
  */
294
343
  getProofOfPossessionRequirements(agentContext, options) {
295
- var _a, _b;
344
+ var _a, _b, _c, _d;
296
345
  const { credentialToRequest } = options;
297
346
  if (!OpenId4VciHolderServiceOptions_1.openId4VciSupportedCredentialFormats.includes(credentialToRequest.format)) {
298
347
  throw new core_1.CredoError([
@@ -304,11 +353,16 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
304
353
  // For each of the supported algs, find the key types, then find the proof types
305
354
  const signatureSuiteRegistry = agentContext.dependencyManager.resolve(core_1.SignatureSuiteRegistry);
306
355
  let signatureAlgorithm;
307
- const issuerSupportedCryptographicSuites = credentialToRequest.cryptographic_suites_supported;
308
- const issuerSupportedBindingMethods = credentialToRequest.cryptographic_binding_methods_supported;
356
+ if (credentialToRequest.proof_types_supported) {
357
+ if (!credentialToRequest.proof_types_supported.jwt) {
358
+ throw new core_1.CredoError(`Unsupported proof type(s) ${Object.keys(credentialToRequest.proof_types_supported).join(', ')}. Supported proof type(s) are: jwt`);
359
+ }
360
+ }
361
+ // FIXME credentialToRequest.credential_signing_alg_values_supported is only required for v11 compat
362
+ const proofSigningAlgsSupported = (_b = (_a = credentialToRequest.proof_types_supported) === null || _a === void 0 ? void 0 : _a.jwt.proof_signing_alg_values_supported) !== null && _b !== void 0 ? _b : credentialToRequest.credential_signing_alg_values_supported;
309
363
  // If undefined, it means the issuer didn't include the cryptographic suites in the metadata
310
364
  // We just guess that the first one is supported
311
- if (issuerSupportedCryptographicSuites === undefined) {
365
+ if (proofSigningAlgsSupported === undefined) {
312
366
  signatureAlgorithm = options.possibleProofOfPossessionSignatureAlgorithms[0];
313
367
  }
314
368
  else {
@@ -316,7 +370,7 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
316
370
  case shared_1.OpenId4VciCredentialFormatProfile.JwtVcJson:
317
371
  case shared_1.OpenId4VciCredentialFormatProfile.JwtVcJsonLd:
318
372
  case shared_1.OpenId4VciCredentialFormatProfile.SdJwtVc:
319
- signatureAlgorithm = options.possibleProofOfPossessionSignatureAlgorithms.find((signatureAlgorithm) => issuerSupportedCryptographicSuites.includes(signatureAlgorithm));
373
+ signatureAlgorithm = options.possibleProofOfPossessionSignatureAlgorithms.find((signatureAlgorithm) => proofSigningAlgsSupported.includes(signatureAlgorithm));
320
374
  break;
321
375
  case shared_1.OpenId4VciCredentialFormatProfile.LdpVc:
322
376
  signatureAlgorithm = options.possibleProofOfPossessionSignatureAlgorithms.find((signatureAlgorithm) => {
@@ -326,7 +380,7 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
326
380
  const matchingSuite = signatureSuiteRegistry.getAllByKeyType(JwkClass.keyType);
327
381
  if (matchingSuite.length === 0)
328
382
  return false;
329
- return issuerSupportedCryptographicSuites.includes(matchingSuite[0].proofType);
383
+ return proofSigningAlgsSupported.includes(matchingSuite[0].proofType);
330
384
  });
331
385
  break;
332
386
  default:
@@ -336,9 +390,10 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
336
390
  if (!signatureAlgorithm) {
337
391
  throw new core_1.CredoError(`Could not establish signature algorithm for format ${credentialToRequest.format} and id ${credentialToRequest.id}`);
338
392
  }
339
- const supportsAllDidMethods = (_a = issuerSupportedBindingMethods === null || issuerSupportedBindingMethods === void 0 ? void 0 : issuerSupportedBindingMethods.includes('did')) !== null && _a !== void 0 ? _a : false;
393
+ const issuerSupportedBindingMethods = credentialToRequest.cryptographic_binding_methods_supported;
394
+ const supportsAllDidMethods = (_c = issuerSupportedBindingMethods === null || issuerSupportedBindingMethods === void 0 ? void 0 : issuerSupportedBindingMethods.includes('did')) !== null && _c !== void 0 ? _c : false;
340
395
  const supportedDidMethods = issuerSupportedBindingMethods === null || issuerSupportedBindingMethods === void 0 ? void 0 : issuerSupportedBindingMethods.filter((method) => method.startsWith('did:'));
341
- const supportsJwk = (_b = issuerSupportedBindingMethods === null || issuerSupportedBindingMethods === void 0 ? void 0 : issuerSupportedBindingMethods.includes('jwk')) !== null && _b !== void 0 ? _b : false;
396
+ const supportsJwk = (_d = issuerSupportedBindingMethods === null || issuerSupportedBindingMethods === void 0 ? void 0 : issuerSupportedBindingMethods.includes('jwk')) !== null && _d !== void 0 ? _d : false;
342
397
  return {
343
398
  signatureAlgorithm,
344
399
  supportedDidMethods,
@@ -348,11 +403,17 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
348
403
  }
349
404
  async handleCredentialResponse(agentContext, credentialResponse, options) {
350
405
  var _a, _b, _c, _d, _e, _f;
351
- const { verifyCredentialStatus } = options;
406
+ const { verifyCredentialStatus, credentialIssuerMetadata } = options;
352
407
  this.logger.debug('Credential request response', credentialResponse);
353
408
  if (!credentialResponse.successBody || !credentialResponse.successBody.credential) {
354
409
  throw new core_1.CredoError(`Did not receive a successful credential response. ${(_a = credentialResponse.errorBody) === null || _a === void 0 ? void 0 : _a.error}: ${(_b = credentialResponse.errorBody) === null || _b === void 0 ? void 0 : _b.error_description}`);
355
410
  }
411
+ const notificationMetadata = credentialIssuerMetadata.notification_endpoint && credentialResponse.successBody.notification_id
412
+ ? {
413
+ notificationEndpoint: credentialIssuerMetadata.notification_endpoint,
414
+ notificationId: credentialResponse.successBody.notification_id,
415
+ }
416
+ : undefined;
356
417
  const format = credentialResponse.successBody.format;
357
418
  if (format === shared_1.OpenId4VciCredentialFormatProfile.SdJwtVc) {
358
419
  if (typeof credentialResponse.successBody.credential !== 'string')
@@ -365,7 +426,7 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
365
426
  agentContext.config.logger.error('Failed to validate credential', { verificationResult });
366
427
  throw new core_1.CredoError(`Failed to validate sd-jwt-vc credential. Results = ${JSON.stringify(verificationResult)}`);
367
428
  }
368
- return verificationResult.sdJwtVc;
429
+ return { credential: verificationResult.sdJwtVc, notificationMetadata };
369
430
  }
370
431
  else if (format === shared_1.OpenId4VciCredentialFormatProfile.JwtVcJson ||
371
432
  format === shared_1.OpenId4VciCredentialFormatProfile.JwtVcJsonLd) {
@@ -378,7 +439,7 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
378
439
  agentContext.config.logger.error('Failed to validate credential', { result });
379
440
  throw new core_1.CredoError(`Failed to validate credential, error = ${(_d = (_c = result.error) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : 'Unknown'}`);
380
441
  }
381
- return credential;
442
+ return { credential, notificationMetadata };
382
443
  }
383
444
  else if (format === shared_1.OpenId4VciCredentialFormatProfile.LdpVc) {
384
445
  const credential = core_1.W3cJsonLdVerifiableCredential.fromJson(credentialResponse.successBody.credential);
@@ -390,7 +451,7 @@ let OpenId4VciHolderService = class OpenId4VciHolderService {
390
451
  agentContext.config.logger.error('Failed to validate credential', { result });
391
452
  throw new core_1.CredoError(`Failed to validate credential, error = ${(_f = (_e = result.error) === null || _e === void 0 ? void 0 : _e.message) !== null && _f !== void 0 ? _f : 'Unknown'}`);
392
453
  }
393
- return credential;
454
+ return { credential, notificationMetadata };
394
455
  }
395
456
  throw new core_1.CredoError(`Unsupported credential format ${credentialResponse.successBody.format}`);
396
457
  }
@@ -449,64 +510,4 @@ exports.OpenId4VciHolderService = OpenId4VciHolderService = __decorate([
449
510
  __metadata("design:paramtypes", [Object, core_1.W3cCredentialService,
450
511
  core_1.JwsService])
451
512
  ], OpenId4VciHolderService);
452
- // NOTE: this is also defined in the sphereon lib, but we use
453
- // this custom method to get PAR working and because we don't
454
- // use the oid4vci client in sphereon's lib
455
- // Once PAR is supported in the sphereon lib, we should to try remove this
456
- // and use the one from the sphereon lib
457
- async function createAuthorizationRequestUri(options) {
458
- var _a, _b, _c;
459
- const { scope, authDetails, metadata, clientId, codeChallenge, codeChallengeMethod, redirectUri } = options;
460
- let nonEmptyScope = !scope || scope.length === 0 ? undefined : scope;
461
- const nonEmptyAuthDetails = !authDetails || authDetails.length === 0 ? undefined : authDetails;
462
- // Scope and authorization_details can be used in the same authorization request
463
- // https://datatracker.ietf.org/doc/html/draft-ietf-oauth-rar-23#name-relationship-to-scope-param
464
- if (!nonEmptyScope && !nonEmptyAuthDetails) {
465
- throw new core_1.CredoError(`Please provide a 'scope' or 'authDetails' via the options.`);
466
- }
467
- // Authorization servers supporting PAR SHOULD include the URL of their pushed authorization request endpoint in their authorization server metadata document
468
- // Note that the presence of pushed_authorization_request_endpoint is sufficient for a client to determine that it may use the PAR flow.
469
- const parEndpoint = metadata.credentialIssuerMetadata.pushed_authorization_request_endpoint;
470
- const authorizationEndpoint = (_a = metadata.credentialIssuerMetadata) === null || _a === void 0 ? void 0 : _a.authorization_endpoint;
471
- if (!authorizationEndpoint && !parEndpoint) {
472
- throw new core_1.CredoError("Server metadata does not contain an 'authorization_endpoint' which is required for the 'Authorization Code Flow'");
473
- }
474
- // add 'openid' scope if not present
475
- if (nonEmptyScope && !(nonEmptyScope === null || nonEmptyScope === void 0 ? void 0 : nonEmptyScope.includes('openid'))) {
476
- nonEmptyScope = ['openid', ...nonEmptyScope];
477
- }
478
- const queryObj = {
479
- client_id: clientId,
480
- response_type: oid4vci_common_1.ResponseType.AUTH_CODE,
481
- code_challenge_method: codeChallengeMethod,
482
- code_challenge: codeChallenge,
483
- redirect_uri: redirectUri,
484
- };
485
- if (nonEmptyScope)
486
- queryObj['scope'] = nonEmptyScope.join(' ');
487
- if (nonEmptyAuthDetails)
488
- queryObj['authorization_details'] = JSON.stringify((0, issuerMetadataUtils_1.handleAuthorizationDetails)(nonEmptyAuthDetails, metadata));
489
- const issuerState = (_c = (_b = options.credentialOffer.grants) === null || _b === void 0 ? void 0 : _b.authorization_code) === null || _c === void 0 ? void 0 : _c.issuer_state;
490
- if (issuerState)
491
- queryObj['issuer_state'] = issuerState;
492
- if (parEndpoint) {
493
- const body = new URLSearchParams(queryObj);
494
- const response = await (0, oid4vci_client_1.formPost)(parEndpoint, body);
495
- if (!response.successBody) {
496
- throw new core_1.CredoError(`Could not acquire the authorization request uri from '${parEndpoint}'`);
497
- }
498
- return (0, oid4vci_common_1.convertJsonToURI)({ request_uri: response.successBody.request_uri, client_id: clientId, response_type: oid4vci_common_1.ResponseType.AUTH_CODE }, {
499
- baseUrl: authorizationEndpoint,
500
- uriTypeProperties: ['request_uri', 'client_id', 'response_type'],
501
- mode: oid4vci_common_1.JsonURIMode.X_FORM_WWW_URLENCODED,
502
- });
503
- }
504
- else {
505
- return (0, oid4vci_common_1.convertJsonToURI)(queryObj, {
506
- baseUrl: authorizationEndpoint,
507
- uriTypeProperties: ['redirect_uri', 'scope', 'authorization_details', 'issuer_state'],
508
- mode: oid4vci_common_1.JsonURIMode.X_FORM_WWW_URLENCODED,
509
- });
510
- }
511
- }
512
513
  //# sourceMappingURL=OpenId4VciHolderService.js.map