@@ -21,6 +21,8 @@ import {
2121 getTypesFromCredentialSupported ,
2222 JWK ,
2323 KID_JWK_X5C_ERROR ,
24+ NotificationRequest ,
25+ NotificationResult ,
2426 OID4VCICredentialFormat ,
2527 OpenId4VCIVersion ,
2628 PKCEOpts ,
@@ -33,18 +35,21 @@ import Debug from 'debug';
3335import { AccessTokenClientV1_0_11 } from './AccessTokenClientV1_0_11' ;
3436import { createAuthorizationRequestUrl } from './AuthorizationCodeClient' ;
3537import { createAuthorizationRequestUrlV1_0_11 } from './AuthorizationCodeClientV1_0_11' ;
36- import { CredentialOfferClientV1_0_11 } from './CredentialOfferClientV1_0_11' ;
38+ import { CredentialOfferClient } from './CredentialOfferClient' ;
39+ import { CredentialRequestOpts } from './CredentialRequestClient' ;
3740import { CredentialRequestClientBuilderV1_0_11 } from './CredentialRequestClientBuilderV1_0_11' ;
3841import { MetadataClient } from './MetadataClient' ;
3942import { OpenID4VCIClientStateV1_0_11 } from './OpenID4VCIClientV1_0_11' ;
4043import { OpenID4VCIClientStateV1_0_13 } from './OpenID4VCIClientV1_0_13' ;
4144import { ProofOfPossessionBuilder } from './ProofOfPossessionBuilder' ;
42- import { generateMissingPKCEOpts } from './functions' ;
45+ import { generateMissingPKCEOpts , sendNotification } from './functions' ;
4346
4447const debug = Debug ( 'sphereon:oid4vci' ) ;
4548
4649export type OpenID4VCIClientState = OpenID4VCIClientStateV1_0_11 | OpenID4VCIClientStateV1_0_13 ;
4750
51+ export type EndpointMetadataResult = EndpointMetadataResultV1_0_11 | EndpointMetadataResultV1_0_13 ;
52+
4853export class OpenID4VCIClient {
4954 private readonly _state : OpenID4VCIClientState ;
5055
@@ -71,7 +76,7 @@ export class OpenID4VCIClient {
7176 pkce ?: PKCEOpts ;
7277 authorizationRequest ?: AuthorizationRequestOpts ; // Can be provided here, or when manually calling createAuthorizationUrl
7378 jwk ?: JWK ;
74- endpointMetadata ?: EndpointMetadataResultV1_0_11 | EndpointMetadataResultV1_0_13 ;
79+ endpointMetadata ?: EndpointMetadataResult ;
7580 accessTokenResponse ?: AccessTokenResponse ;
7681 authorizationRequestOpts ?: AuthorizationRequestOpts ;
7782 authorizationCodeResponse ?: AuthorizationResponse ;
@@ -141,7 +146,7 @@ export class OpenID4VCIClient {
141146 return client ;
142147 }
143148
144- public static async fromState ( { state } : { state : OpenID4VCIClientStateV1_0_11 | string } ) : Promise < OpenID4VCIClient > {
149+ public static async fromState ( { state } : { state : OpenID4VCIClientState | string } ) : Promise < OpenID4VCIClient > {
145150 const clientState = typeof state === 'string' ? JSON . parse ( state ) : state ;
146151
147152 return new OpenID4VCIClient ( clientState ) ;
@@ -168,7 +173,7 @@ export class OpenID4VCIClient {
168173 clientId ?: string ;
169174 authorizationRequest ?: AuthorizationRequestOpts ; // Can be provided here, or when manually calling createAuthorizationUrl
170175 } ) : Promise < OpenID4VCIClient > {
171- const credentialOfferClient = await CredentialOfferClientV1_0_11 . fromURI ( uri , { resolve : resolveOfferUri } ) ;
176+ const credentialOfferClient = await CredentialOfferClient . fromURI ( uri , { resolve : resolveOfferUri } ) ;
172177 const client = new OpenID4VCIClient ( {
173178 credentialOffer : credentialOfferClient ,
174179 kid,
@@ -235,7 +240,7 @@ export class OpenID4VCIClient {
235240 return this . _state . authorizationURL ;
236241 }
237242
238- public async retrieveServerMetadata ( ) : Promise < EndpointMetadataResultV1_0_11 | EndpointMetadataResultV1_0_13 > {
243+ public async retrieveServerMetadata ( ) : Promise < EndpointMetadataResult > {
239244 this . assertIssuerData ( ) ;
240245 if ( ! this . _state . endpointMetadata ) {
241246 if ( this . credentialOffer ) {
@@ -474,6 +479,14 @@ export class OpenID4VCIClient {
474479 } ) as Record < string , CredentialConfigurationSupported > ;
475480 }
476481
482+ public async sendNotification (
483+ credentialRequestOpts : Partial < CredentialRequestOpts > ,
484+ request : NotificationRequest ,
485+ accessToken ?: string ,
486+ ) : Promise < NotificationResult > {
487+ return sendNotification ( credentialRequestOpts , request , accessToken ?? this . _state . accessToken ?? this . _state . accessTokenResponse ?. access_token ) ;
488+ }
489+
477490 getCredentialOfferTypes ( ) : string [ ] [ ] {
478491 if ( ! this . credentialOffer ) {
479492 return [ ] ;
@@ -527,7 +540,7 @@ export class OpenID4VCIClient {
527540 return this . credentialOffer ?. version ?? OpenId4VCIVersion . VER_1_0_11 ;
528541 }
529542
530- public get endpointMetadata ( ) : EndpointMetadataResultV1_0_11 | EndpointMetadataResultV1_0_13 {
543+ public get endpointMetadata ( ) : EndpointMetadataResult {
531544 this . assertServerMetadata ( ) ;
532545 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
533546 return this . _state . endpointMetadata ! ;
0 commit comments