@sphereon/oid4vci-client 0.16.1-next.3 → 0.16.1-next.48

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 (53) hide show
  1. package/dist/AccessTokenClient.d.ts.map +1 -1
  2. package/dist/AccessTokenClient.js +11 -10
  3. package/dist/AccessTokenClient.js.map +1 -1
  4. package/dist/AccessTokenClientV1_0_11.d.ts.map +1 -1
  5. package/dist/AccessTokenClientV1_0_11.js +10 -9
  6. package/dist/AccessTokenClientV1_0_11.js.map +1 -1
  7. package/dist/AuthorizationCodeClient.d.ts.map +1 -1
  8. package/dist/AuthorizationCodeClient.js +3 -2
  9. package/dist/AuthorizationCodeClient.js.map +1 -1
  10. package/dist/AuthorizationCodeClientV1_0_11.js.map +1 -1
  11. package/dist/CredentialRequestClient.d.ts +36 -12
  12. package/dist/CredentialRequestClient.d.ts.map +1 -1
  13. package/dist/CredentialRequestClient.js +59 -23
  14. package/dist/CredentialRequestClient.js.map +1 -1
  15. package/dist/CredentialRequestClientV1_0_11.d.ts.map +1 -1
  16. package/dist/CredentialRequestClientV1_0_11.js +11 -1
  17. package/dist/CredentialRequestClientV1_0_11.js.map +1 -1
  18. package/dist/MetadataClient.d.ts +1 -0
  19. package/dist/MetadataClient.d.ts.map +1 -1
  20. package/dist/MetadataClient.js +5 -4
  21. package/dist/MetadataClient.js.map +1 -1
  22. package/dist/MetadataClientV1_0_13.d.ts +1 -0
  23. package/dist/MetadataClientV1_0_13.d.ts.map +1 -1
  24. package/dist/MetadataClientV1_0_13.js +5 -4
  25. package/dist/MetadataClientV1_0_13.js.map +1 -1
  26. package/dist/OpenID4VCIClient.d.ts +10 -10
  27. package/dist/OpenID4VCIClient.d.ts.map +1 -1
  28. package/dist/OpenID4VCIClient.js +11 -5
  29. package/dist/OpenID4VCIClient.js.map +1 -1
  30. package/dist/OpenID4VCIClientV1_0_11.d.ts +10 -10
  31. package/dist/OpenID4VCIClientV1_0_11.d.ts.map +1 -1
  32. package/dist/OpenID4VCIClientV1_0_11.js +14 -7
  33. package/dist/OpenID4VCIClientV1_0_11.js.map +1 -1
  34. package/dist/OpenID4VCIClientV1_0_13.d.ts +27 -10
  35. package/dist/OpenID4VCIClientV1_0_13.d.ts.map +1 -1
  36. package/dist/OpenID4VCIClientV1_0_13.js +64 -28
  37. package/dist/OpenID4VCIClientV1_0_13.js.map +1 -1
  38. package/dist/ProofOfPossessionBuilder.d.ts +1 -1
  39. package/dist/ProofOfPossessionBuilder.d.ts.map +1 -1
  40. package/lib/AccessTokenClient.ts +15 -13
  41. package/lib/AccessTokenClientV1_0_11.ts +13 -12
  42. package/lib/AuthorizationCodeClient.ts +3 -1
  43. package/lib/AuthorizationCodeClientV1_0_11.ts +2 -2
  44. package/lib/CredentialRequestClient.ts +97 -24
  45. package/lib/CredentialRequestClientV1_0_11.ts +11 -1
  46. package/lib/MetadataClient.ts +2 -1
  47. package/lib/MetadataClientV1_0_13.ts +2 -1
  48. package/lib/OpenID4VCIClient.ts +23 -14
  49. package/lib/OpenID4VCIClientV1_0_11.ts +25 -14
  50. package/lib/OpenID4VCIClientV1_0_13.ts +103 -41
  51. package/lib/ProofOfPossessionBuilder.ts +1 -1
  52. package/lib/__tests__/IT.spec.ts +1 -1
  53. package/package.json +5 -5
@@ -1,5 +1,6 @@
1
- import { JWK } from '@sphereon/oid4vc-common';
1
+ import { CreateDPoPClientOpts, JWK } from '@sphereon/oid4vc-common';
2
2
  import {
3
+ AccessTokenRequestOpts,
3
4
  AccessTokenResponse,
4
5
  Alg,
5
6
  AuthorizationRequestOpts,
@@ -12,6 +13,7 @@ import {
12
13
  CredentialOfferRequestWithBaseUrl,
13
14
  CredentialResponse,
14
15
  DefaultURISchemes,
16
+ DPoPResponseParams,
15
17
  EndpointMetadataResultV1_0_13,
16
18
  ExperimentalSubjectIssuance,
17
19
  getClientIdFromCredentialOfferPayload,
@@ -27,14 +29,14 @@ import {
27
29
  ProofOfPossessionCallbacks,
28
30
  toAuthorizationResponsePayload,
29
31
  } from '@sphereon/oid4vci-common';
30
- import { CredentialFormat } from '@sphereon/ssi-types';
32
+ import { CredentialFormat, DIDDocument } from '@sphereon/ssi-types';
31
33
  import Debug from 'debug';
32
34
 
33
35
  import { AccessTokenClient } from './AccessTokenClient';
34
36
  import { createAuthorizationRequestUrl } from './AuthorizationCodeClient';
35
37
  import { CredentialOfferClient } from './CredentialOfferClient';
36
38
  import { CredentialRequestOpts } from './CredentialRequestClient';
37
- import { CredentialRequestClientBuilder } from './CredentialRequestClientBuilder';
39
+ import { CredentialRequestClientBuilderV1_0_13 } from './CredentialRequestClientBuilderV1_0_13';
38
40
  import { MetadataClientV1_0_13 } from './MetadataClientV1_0_13';
39
41
  import { ProofOfPossessionBuilder } from './ProofOfPossessionBuilder';
40
42
  import { generateMissingPKCEOpts, sendNotification } from './functions';
@@ -50,6 +52,7 @@ export interface OpenID4VCIClientStateV1_0_13 {
50
52
  alg?: Alg | string;
51
53
  endpointMetadata?: EndpointMetadataResultV1_0_13;
52
54
  accessTokenResponse?: AccessTokenResponse;
55
+ dpopResponseParams?: DPoPResponseParams;
53
56
  authorizationRequestOpts?: AuthorizationRequestOpts;
54
57
  authorizationCodeResponse?: AuthorizationResponse;
55
58
  pkce: PKCEOpts;
@@ -258,16 +261,13 @@ export class OpenID4VCIClientV1_0_13 {
258
261
  this._state.pkce = generateMissingPKCEOpts({ ...this._state.pkce, ...pkce });
259
262
  }
260
263
 
261
- public async acquireAccessToken(opts?: {
262
- pin?: string;
263
- clientId?: string;
264
- codeVerifier?: string;
265
- authorizationResponse?: string | AuthorizationResponse; // Pass in an auth response, either as URI/redirect, or object
266
- code?: string; // Directly pass in a code from an auth response
267
- redirectUri?: string;
268
- additionalRequestParams?: Record<string, any>;
269
- asOpts?: AuthorizationServerOpts;
270
- }): Promise<AccessTokenResponse> {
264
+ public async acquireAccessToken(
265
+ opts?: Omit<AccessTokenRequestOpts, 'credentialOffer' | 'credentialIssuer' | 'metadata' | 'additionalParams'> & {
266
+ clientId?: string;
267
+ authorizationResponse?: string | AuthorizationResponse; // Pass in an auth response, either as URI/redirect, or object
268
+ additionalRequestParams?: Record<string, any>;
269
+ },
270
+ ): Promise<AccessTokenResponse & { params?: DPoPResponseParams }> {
271
271
  const { pin, clientId = this._state.clientId ?? this._state.authorizationRequestOpts?.clientId } = opts ?? {};
272
272
  let { redirectUri } = opts ?? {};
273
273
  if (opts?.authorizationResponse) {
@@ -324,6 +324,7 @@ export class OpenID4VCIClientV1_0_13 {
324
324
  code,
325
325
  redirectUri,
326
326
  asOpts,
327
+ ...(opts?.createDPoPOpts && { createDPoPOpts: opts.createDPoPOpts }),
327
328
  ...(opts?.additionalRequestParams && { additionalParams: opts.additionalRequestParams }),
328
329
  });
329
330
 
@@ -343,13 +344,48 @@ export class OpenID4VCIClientV1_0_13 {
343
344
  );
344
345
  }
345
346
  this._state.accessTokenResponse = response.successBody;
347
+ this._state.dpopResponseParams = response.params;
346
348
  this._state.accessToken = response.successBody.access_token;
347
349
  }
348
350
 
349
- return this.accessTokenResponse;
351
+ return { ...this.accessTokenResponse, ...(this.dpopResponseParams && { params: this.dpopResponseParams }) };
350
352
  }
351
353
 
352
- public async acquireCredentials({
354
+ public async acquireCredentialsWithoutProof(args: {
355
+ credentialIdentifier?: string;
356
+ credentialTypes?: string | string[];
357
+ context?: string[];
358
+ format?: CredentialFormat | OID4VCICredentialFormat;
359
+ kid?: string;
360
+ jwk?: JWK;
361
+ alg?: Alg | string;
362
+ jti?: string;
363
+ deferredCredentialAwait?: boolean;
364
+ deferredCredentialIntervalInMS?: number;
365
+ experimentalHolderIssuanceSupported?: boolean;
366
+ createDPoPOpts?: CreateDPoPClientOpts;
367
+ }): Promise<CredentialResponse & { access_token: string }> {
368
+ return await this.acquireCredentialsImpl(args);
369
+ }
370
+ public async acquireCredentials(args: {
371
+ credentialIdentifier?: string;
372
+ credentialTypes?: string | string[];
373
+ context?: string[];
374
+ proofCallbacks: ProofOfPossessionCallbacks<any>;
375
+ format?: CredentialFormat | OID4VCICredentialFormat;
376
+ kid?: string;
377
+ jwk?: JWK;
378
+ alg?: Alg | string;
379
+ jti?: string;
380
+ deferredCredentialAwait?: boolean;
381
+ deferredCredentialIntervalInMS?: number;
382
+ experimentalHolderIssuanceSupported?: boolean;
383
+ createDPoPOpts?: CreateDPoPClientOpts;
384
+ }): Promise<CredentialResponse & { access_token: string }> {
385
+ return await this.acquireCredentialsImpl(args);
386
+ }
387
+
388
+ private async acquireCredentialsImpl({
353
389
  credentialIdentifier,
354
390
  credentialTypes,
355
391
  context,
@@ -361,11 +397,12 @@ export class OpenID4VCIClientV1_0_13 {
361
397
  jti,
362
398
  deferredCredentialAwait,
363
399
  deferredCredentialIntervalInMS,
400
+ createDPoPOpts,
364
401
  }: {
365
402
  credentialIdentifier?: string;
366
403
  credentialTypes?: string | string[];
367
404
  context?: string[];
368
- proofCallbacks: ProofOfPossessionCallbacks<any>;
405
+ proofCallbacks?: ProofOfPossessionCallbacks<any>;
369
406
  format?: CredentialFormat | OID4VCICredentialFormat;
370
407
  kid?: string;
371
408
  jwk?: JWK;
@@ -374,6 +411,7 @@ export class OpenID4VCIClientV1_0_13 {
374
411
  deferredCredentialAwait?: boolean;
375
412
  deferredCredentialIntervalInMS?: number;
376
413
  experimentalHolderIssuanceSupported?: boolean;
414
+ createDPoPOpts?: CreateDPoPClientOpts;
377
415
  }): Promise<CredentialResponse & { access_token: string }> {
378
416
  if ([jwk, kid].filter((v) => v !== undefined).length > 1) {
379
417
  throw new Error(KID_JWK_X5C_ERROR + `. jwk: ${jwk !== undefined}, kid: ${kid !== undefined}`);
@@ -384,11 +422,11 @@ export class OpenID4VCIClientV1_0_13 {
384
422
  if (kid) this._state.kid = kid;
385
423
 
386
424
  const requestBuilder = this.credentialOffer
387
- ? CredentialRequestClientBuilder.fromCredentialOffer({
425
+ ? CredentialRequestClientBuilderV1_0_13.fromCredentialOffer({
388
426
  credentialOffer: this.credentialOffer,
389
427
  metadata: this.endpointMetadata,
390
428
  })
391
- : CredentialRequestClientBuilder.fromCredentialIssuer({
429
+ : CredentialRequestClientBuilderV1_0_13.fromCredentialIssuer({
392
430
  credentialIssuer: this.getIssuer(),
393
431
  credentialIdentifier: credentialIdentifier,
394
432
  metadata: this.endpointMetadata,
@@ -447,31 +485,51 @@ export class OpenID4VCIClientV1_0_13 {
447
485
  }
448
486
 
449
487
  const credentialRequestClient = requestBuilder.build();
450
- const proofBuilder = ProofOfPossessionBuilder.fromAccessTokenResponse({
451
- accessTokenResponse: this.accessTokenResponse,
452
- callbacks: proofCallbacks,
453
- version: this.version(),
454
- })
455
- .withIssuer(this.getIssuer())
456
- .withAlg(this.alg);
457
488
 
458
- if (this._state.jwk) {
459
- proofBuilder.withJWK(this._state.jwk);
460
- }
461
- if (this._state.kid) {
462
- proofBuilder.withKid(this._state.kid);
463
- }
489
+ let proofBuilder: ProofOfPossessionBuilder<any> | undefined;
490
+ if (proofCallbacks) {
491
+ proofBuilder = ProofOfPossessionBuilder.fromAccessTokenResponse({
492
+ accessTokenResponse: this.accessTokenResponse,
493
+ callbacks: proofCallbacks,
494
+ version: this.version(),
495
+ })
496
+ .withIssuer(this.getIssuer())
497
+ .withAlg(this.alg);
464
498
 
465
- if (this.clientId) {
466
- proofBuilder.withClientId(this.clientId);
467
- }
468
- if (jti) {
469
- proofBuilder.withJti(jti);
499
+ if (this._state.jwk) {
500
+ proofBuilder.withJWK(this._state.jwk);
501
+ }
502
+ if (this._state.kid) {
503
+ proofBuilder.withKid(this._state.kid);
504
+ }
505
+
506
+ if (this.clientId) {
507
+ proofBuilder.withClientId(this.clientId);
508
+ }
509
+ if (jti) {
510
+ proofBuilder.withJti(jti);
511
+ }
470
512
  }
471
- const response = await credentialRequestClient.acquireCredentialsUsingProof({
472
- proofInput: proofBuilder,
473
- ...(credentialIdentifier ? { credentialIdentifier, subjectIssuance } : { format, context, credentialTypes, subjectIssuance }),
474
- });
513
+ const request = proofBuilder
514
+ ? await credentialRequestClient.createCredentialRequest<DIDDocument>({
515
+ proofInput: proofBuilder,
516
+ credentialTypes,
517
+ context,
518
+ format,
519
+ version: this.version(),
520
+ credentialIdentifier,
521
+ subjectIssuance,
522
+ })
523
+ : await credentialRequestClient.createCredentialRequestWithoutProof<DIDDocument>({
524
+ credentialTypes,
525
+ context,
526
+ format,
527
+ version: this.version(),
528
+ credentialIdentifier,
529
+ subjectIssuance,
530
+ });
531
+ const response = await credentialRequestClient.acquireCredentialsUsingRequest(request, createDPoPOpts);
532
+ this._state.dpopResponseParams = response.params;
475
533
  if (response.errorBody) {
476
534
  debug(`Credential request error:\r\n${JSON.stringify(response.errorBody)}`);
477
535
  throw Error(
@@ -487,7 +545,7 @@ export class OpenID4VCIClientV1_0_13 {
487
545
  } for issuer ${this.getIssuer()} failed as there was no success response body`,
488
546
  );
489
547
  }
490
- return { ...response.successBody, access_token: response.access_token };
548
+ return { ...response.successBody, ...(this.dpopResponseParams && { params: this.dpopResponseParams }), access_token: response.access_token };
491
549
  }
492
550
 
493
551
  public async exportState(): Promise<string> {
@@ -604,6 +662,10 @@ export class OpenID4VCIClientV1_0_13 {
604
662
  return this._state.accessTokenResponse!;
605
663
  }
606
664
 
665
+ get dpopResponseParams(): DPoPResponseParams | undefined {
666
+ return this._state.dpopResponseParams;
667
+ }
668
+
607
669
  public getIssuer(): string {
608
670
  this.assertIssuerData();
609
671
  return this._state.credentialIssuer;
@@ -14,7 +14,7 @@ import {
14
14
  Typ,
15
15
  } from '@sphereon/oid4vci-common';
16
16
 
17
- export class ProofOfPossessionBuilder<DIDDoc> {
17
+ export class ProofOfPossessionBuilder<DIDDoc = never> {
18
18
  private readonly proof?: ProofOfPossession;
19
19
  private readonly callbacks?: ProofOfPossessionCallbacks<DIDDoc>;
20
20
  private readonly version: OpenId4VCIVersion;
@@ -198,7 +198,7 @@ describe('OID4VCI-Client should', () => {
198
198
 
199
199
  const credentialResponse = await client.acquireCredentials({
200
200
  credentialIdentifier: 'OpenBadgeCredential',
201
- format: 'jwt_vc_json-ld',
201
+ // format: 'jwt_vc_json-ld',
202
202
  proofCallbacks: {
203
203
  signCallback: proofOfPossessionCallbackFunction,
204
204
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/oid4vci-client",
3
- "version": "0.16.1-next.3+ac29c5d",
3
+ "version": "0.16.1-next.48+74b00cb",
4
4
  "description": "OpenID for Verifiable Credential Issuance (OpenID4VCI) client",
5
5
  "source": "lib/index.ts",
6
6
  "main": "dist/index.js",
@@ -15,9 +15,9 @@
15
15
  "build": "tsc"
16
16
  },
17
17
  "dependencies": {
18
- "@sphereon/oid4vc-common": "0.16.1-next.3+ac29c5d",
19
- "@sphereon/oid4vci-common": "0.16.1-next.3+ac29c5d",
20
- "@sphereon/ssi-types": "0.28.0",
18
+ "@sphereon/oid4vc-common": "0.16.1-next.48+74b00cb",
19
+ "@sphereon/oid4vci-common": "0.16.1-next.48+74b00cb",
20
+ "@sphereon/ssi-types": "0.29.1-unstable.208",
21
21
  "cross-fetch": "^3.1.8",
22
22
  "debug": "^4.3.5"
23
23
  },
@@ -70,5 +70,5 @@
70
70
  "OIDC4VCI",
71
71
  "OID4VCI"
72
72
  ],
73
- "gitHead": "ac29c5d66c421fcac24fd31241c94669b868ee75"
73
+ "gitHead": "74b00cb66d8e7d7f1fc7148c8861930e8f8dbf98"
74
74
  }