@sphereon/oid4vci-client 0.16.0 → 0.16.1-feature.from.funke.103

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 (57) 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 +74 -31
  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/dist/functions/AccessTokenUtil.js +2 -2
  41. package/dist/functions/AccessTokenUtil.js.map +1 -1
  42. package/lib/AccessTokenClient.ts +15 -13
  43. package/lib/AccessTokenClientV1_0_11.ts +13 -12
  44. package/lib/AuthorizationCodeClient.ts +3 -1
  45. package/lib/AuthorizationCodeClientV1_0_11.ts +2 -2
  46. package/lib/CredentialRequestClient.ts +97 -24
  47. package/lib/CredentialRequestClientV1_0_11.ts +11 -1
  48. package/lib/MetadataClient.ts +2 -1
  49. package/lib/MetadataClientV1_0_13.ts +2 -1
  50. package/lib/OpenID4VCIClient.ts +23 -14
  51. package/lib/OpenID4VCIClientV1_0_11.ts +25 -14
  52. package/lib/OpenID4VCIClientV1_0_13.ts +116 -44
  53. package/lib/ProofOfPossessionBuilder.ts +1 -1
  54. package/lib/__tests__/IT.spec.ts +1 -1
  55. package/lib/__tests__/SphereonE2E.spec.test.ts +1 -0
  56. package/lib/functions/AccessTokenUtil.ts +2 -2
  57. 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 }) };
352
+ }
353
+
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);
350
386
  }
351
387
 
352
- public async acquireCredentials({
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,
@@ -434,9 +472,19 @@ export class OpenID4VCIClientV1_0_13 {
434
472
  console.log(`Not all credential types ${JSON.stringify(credentialTypes)} are present in metadata for ${this.getIssuer()}`);
435
473
  // throw Error(`Not all credential types ${JSON.stringify(credentialTypes)} are supported by issuer ${this.getIssuer()}`);
436
474
  }
437
- } else if (metadata.credential_configurations_supported && !Array.isArray(metadata.credential_configurations_supported)) {
438
- const credentialsSupported = metadata.credential_configurations_supported;
439
- if (types.some((type) => !metadata.credential_configurations_supported || !credentialsSupported[type])) {
475
+ } else if (metadata.credential_configurations_supported && typeof(metadata.credential_configurations_supported) === 'object') {
476
+ let typeSupported = false;
477
+ Object.values(metadata.credential_configurations_supported).forEach((supportedCredential) => {
478
+ const subTypes = getTypesFromCredentialSupported(supportedCredential);
479
+ if (
480
+ subTypes.every((t, i) => types[i] === t) ||
481
+ (types.length === 1 && (types[0] === supportedCredential.id || subTypes.includes(types[0])))
482
+ ) {
483
+ typeSupported = true;
484
+ }
485
+ })
486
+
487
+ if (!typeSupported) {
440
488
  throw Error(`Not all credential types ${JSON.stringify(credentialTypes)} are supported by issuer ${this.getIssuer()}`);
441
489
  }
442
490
  }
@@ -447,31 +495,51 @@ export class OpenID4VCIClientV1_0_13 {
447
495
  }
448
496
 
449
497
  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
498
 
458
- if (this._state.jwk) {
459
- proofBuilder.withJWK(this._state.jwk);
460
- }
461
- if (this._state.kid) {
462
- proofBuilder.withKid(this._state.kid);
463
- }
499
+ let proofBuilder: ProofOfPossessionBuilder<any> | undefined;
500
+ if (proofCallbacks) {
501
+ proofBuilder = ProofOfPossessionBuilder.fromAccessTokenResponse({
502
+ accessTokenResponse: this.accessTokenResponse,
503
+ callbacks: proofCallbacks,
504
+ version: this.version(),
505
+ })
506
+ .withIssuer(this.getIssuer())
507
+ .withAlg(this.alg);
464
508
 
465
- if (this.clientId) {
466
- proofBuilder.withClientId(this.clientId);
467
- }
468
- if (jti) {
469
- proofBuilder.withJti(jti);
509
+ if (this._state.jwk) {
510
+ proofBuilder.withJWK(this._state.jwk);
511
+ }
512
+ if (this._state.kid) {
513
+ proofBuilder.withKid(this._state.kid);
514
+ }
515
+
516
+ if (this.clientId) {
517
+ proofBuilder.withClientId(this.clientId);
518
+ }
519
+ if (jti) {
520
+ proofBuilder.withJti(jti);
521
+ }
470
522
  }
471
- const response = await credentialRequestClient.acquireCredentialsUsingProof({
472
- proofInput: proofBuilder,
473
- ...(credentialIdentifier ? { credentialIdentifier, subjectIssuance } : { format, context, credentialTypes, subjectIssuance }),
474
- });
523
+ const request = proofBuilder
524
+ ? await credentialRequestClient.createCredentialRequest<DIDDocument>({
525
+ proofInput: proofBuilder,
526
+ credentialTypes,
527
+ context,
528
+ format,
529
+ version: this.version(),
530
+ credentialIdentifier,
531
+ subjectIssuance,
532
+ })
533
+ : await credentialRequestClient.createCredentialRequestWithoutProof<DIDDocument>({
534
+ credentialTypes,
535
+ context,
536
+ format,
537
+ version: this.version(),
538
+ credentialIdentifier,
539
+ subjectIssuance,
540
+ });
541
+ const response = await credentialRequestClient.acquireCredentialsUsingRequest(request, createDPoPOpts);
542
+ this._state.dpopResponseParams = response.params;
475
543
  if (response.errorBody) {
476
544
  debug(`Credential request error:\r\n${JSON.stringify(response.errorBody)}`);
477
545
  throw Error(
@@ -487,7 +555,7 @@ export class OpenID4VCIClientV1_0_13 {
487
555
  } for issuer ${this.getIssuer()} failed as there was no success response body`,
488
556
  );
489
557
  }
490
- return { ...response.successBody, access_token: response.access_token };
558
+ return { ...response.successBody, ...(this.dpopResponseParams && { params: this.dpopResponseParams }), access_token: response.access_token };
491
559
  }
492
560
 
493
561
  public async exportState(): Promise<string> {
@@ -604,6 +672,10 @@ export class OpenID4VCIClientV1_0_13 {
604
672
  return this._state.accessTokenResponse!;
605
673
  }
606
674
 
675
+ get dpopResponseParams(): DPoPResponseParams | undefined {
676
+ return this._state.dpopResponseParams;
677
+ }
678
+
607
679
  public getIssuer(): string {
608
680
  this.assertIssuerData();
609
681
  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
  },
@@ -170,3 +170,4 @@ describe('ismapolis bug report #63, https://github.com/Sphereon-Opensource/OID4V
170
170
  console.log(JSON.stringify(credentialResponse.credential));
171
171
  });
172
172
  });
173
+
@@ -36,8 +36,8 @@ export const createJwtBearerClientAssertion = async (
36
36
  sub: clientId,
37
37
  aud: credentialIssuer,
38
38
  jti: uuidv4(),
39
- exp: Date.now() / 1000 + 60,
40
- iat: Date.now() / 1000 - 60,
39
+ exp: Math.floor(Date.now()) / 1000 + 60,
40
+ iat: Math.floor(Date.now()) / 1000 - 60,
41
41
  },
42
42
  };
43
43
  const pop = await ProofOfPossessionBuilder.fromJwt({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/oid4vci-client",
3
- "version": "0.16.0",
3
+ "version": "0.16.1-feature.from.funke.103+104a2b5",
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.0",
19
- "@sphereon/oid4vci-common": "0.16.0",
20
- "@sphereon/ssi-types": "0.28.0",
18
+ "@sphereon/oid4vc-common": "0.16.1-feature.from.funke.103+104a2b5",
19
+ "@sphereon/oid4vci-common": "0.16.1-feature.from.funke.103+104a2b5",
20
+ "@sphereon/ssi-types": "0.30.1",
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": "7d938320eba5818dfe2bf6ae5291bb3c614085e1"
73
+ "gitHead": "104a2b5b69b6d18a43779e35609160b4aa6e81a6"
74
74
  }