@sphereon/oid4vci-client 0.12.1-unstable.9 → 0.13.0

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 (48) hide show
  1. package/dist/AccessTokenClient.d.ts.map +1 -1
  2. package/dist/AccessTokenClient.js +11 -5
  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 +12 -5
  6. package/dist/AccessTokenClientV1_0_11.js.map +1 -1
  7. package/dist/AuthorizationCodeClient.js +2 -2
  8. package/dist/CredentialRequestClientBuilder.d.ts.map +1 -1
  9. package/dist/CredentialRequestClientBuilder.js.map +1 -1
  10. package/dist/OpenID4VCIClient.d.ts +3 -1
  11. package/dist/OpenID4VCIClient.d.ts.map +1 -1
  12. package/dist/OpenID4VCIClient.js +30 -14
  13. package/dist/OpenID4VCIClient.js.map +1 -1
  14. package/dist/OpenID4VCIClientV1_0_11.d.ts +4 -2
  15. package/dist/OpenID4VCIClientV1_0_11.d.ts.map +1 -1
  16. package/dist/OpenID4VCIClientV1_0_11.js +32 -16
  17. package/dist/OpenID4VCIClientV1_0_11.js.map +1 -1
  18. package/dist/OpenID4VCIClientV1_0_13.d.ts +3 -1
  19. package/dist/OpenID4VCIClientV1_0_13.d.ts.map +1 -1
  20. package/dist/OpenID4VCIClientV1_0_13.js +29 -15
  21. package/dist/OpenID4VCIClientV1_0_13.js.map +1 -1
  22. package/dist/ProofOfPossessionBuilder.js +6 -6
  23. package/dist/ProofOfPossessionBuilder.js.map +1 -1
  24. package/dist/functions/AccessTokenUtil.d.ts +5 -0
  25. package/dist/functions/AccessTokenUtil.d.ts.map +1 -0
  26. package/dist/functions/AccessTokenUtil.js +63 -0
  27. package/dist/functions/AccessTokenUtil.js.map +1 -0
  28. package/dist/functions/index.d.ts +2 -0
  29. package/dist/functions/index.d.ts.map +1 -1
  30. package/dist/functions/index.js +2 -0
  31. package/dist/functions/index.js.map +1 -1
  32. package/lib/AccessTokenClient.ts +9 -4
  33. package/lib/AccessTokenClientV1_0_11.ts +11 -3
  34. package/lib/AuthorizationCodeClient.ts +2 -2
  35. package/lib/CredentialRequestClientBuilder.ts +14 -14
  36. package/lib/OpenID4VCIClient.ts +31 -3
  37. package/lib/OpenID4VCIClientV1_0_11.ts +35 -6
  38. package/lib/OpenID4VCIClientV1_0_13.ts +33 -6
  39. package/lib/ProofOfPossessionBuilder.ts +6 -6
  40. package/lib/__tests__/CredentialRequestClient.spec.ts +1 -1
  41. package/lib/__tests__/CredentialRequestClientBuilder.spec.ts +1 -1
  42. package/lib/__tests__/CredentialRequestClientV1_0_11.spec.ts +2 -2
  43. package/lib/__tests__/IT.spec.ts +23 -29
  44. package/lib/__tests__/ProofOfPossessionBuilder.spec.ts +23 -23
  45. package/lib/__tests__/SdJwt.spec.ts +26 -26
  46. package/lib/functions/AccessTokenUtil.ts +52 -0
  47. package/lib/functions/index.ts +2 -0
  48. package/package.json +4 -4
@@ -215,37 +215,37 @@ describe('sd-jwt vc', () => {
215
215
  const offered = supported['SdJwtCredentialId'] as CredentialSupportedSdJwtVc;
216
216
 
217
217
  nock(issuerMetadata.token_endpoint as string)
218
- .post('/')
219
- .reply(200, async (_, body: string) => {
220
- const parsedBody = Object.fromEntries(body.split('&').map((x) => x.split('=')));
221
- return createAccessTokenResponse(parsedBody as AccessTokenRequest, {
222
- credentialOfferSessions: vcIssuer.credentialOfferSessions,
223
- accessTokenIssuer: 'https://issuer.example.com',
224
- cNonces: vcIssuer.cNonces,
225
- cNonce: 'a-c-nonce',
226
- accessTokenSignerCallback: async () => 'ey.val.ue',
227
- tokenExpiresIn: 500,
218
+ .post('/')
219
+ .reply(200, async (_, body: string) => {
220
+ const parsedBody = Object.fromEntries(body.split('&').map((x) => x.split('=')));
221
+ return createAccessTokenResponse(parsedBody as AccessTokenRequest, {
222
+ credentialOfferSessions: vcIssuer.credentialOfferSessions,
223
+ accessTokenIssuer: 'https://issuer.example.com',
224
+ cNonces: vcIssuer.cNonces,
225
+ cNonce: 'a-c-nonce',
226
+ accessTokenSignerCallback: async () => 'ey.val.ue',
227
+ tokenExpiresIn: 500,
228
+ });
228
229
  });
229
- });
230
230
 
231
231
  await client.acquireAccessToken({ pin: '123' });
232
232
  nock(issuerMetadata.credential_endpoint as string)
233
- .post('/')
234
- .reply(200, async (_, body) =>
235
- vcIssuer.issueCredential({
236
- credentialRequest: { ...(body as CredentialRequestV1_0_13), credential_identifier: offered.vct },
237
- credential: {
238
- vct: 'Hello',
239
- iss: 'example.com',
240
- iat: 123,
241
- // Defines what can be disclosed (optional)
242
- __disclosureFrame: {
243
- name: true,
233
+ .post('/')
234
+ .reply(200, async (_, body) =>
235
+ vcIssuer.issueCredential({
236
+ credentialRequest: { ...(body as CredentialRequestV1_0_13), credential_identifier: offered.vct },
237
+ credential: {
238
+ vct: 'Hello',
239
+ iss: 'example.com',
240
+ iat: 123,
241
+ // Defines what can be disclosed (optional)
242
+ __disclosureFrame: {
243
+ name: true,
244
+ },
244
245
  },
245
- },
246
- newCNonce: 'new-c-nonce',
247
- }),
248
- );
246
+ newCNonce: 'new-c-nonce',
247
+ }),
248
+ );
249
249
 
250
250
  const credentials = await client.acquireCredentials({
251
251
  credentialIdentifier: offered.vct,
@@ -0,0 +1,52 @@
1
+ import { AccessTokenRequest, AccessTokenRequestOpts, Jwt, OpenId4VCIVersion } from '@sphereon/oid4vci-common';
2
+ import { v4 } from 'uuid';
3
+
4
+ import { ProofOfPossessionBuilder } from '../ProofOfPossessionBuilder';
5
+
6
+ export const createJwtBearerClientAssertion = async (
7
+ request: Partial<AccessTokenRequest>,
8
+ opts: AccessTokenRequestOpts & {
9
+ version?: OpenId4VCIVersion;
10
+ },
11
+ ): Promise<void> => {
12
+ const { asOpts, credentialIssuer } = opts;
13
+ if (asOpts?.clientOpts?.clientAssertionType === 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer') {
14
+ const { clientId = request.client_id, signCallbacks, alg } = asOpts.clientOpts;
15
+ let { kid } = asOpts.clientOpts;
16
+ if (!clientId) {
17
+ return Promise.reject(Error(`Not client_id supplied, but client-assertion jwt-bearer requested.`));
18
+ } else if (!kid) {
19
+ return Promise.reject(Error(`No kid supplied, but client-assertion jwt-bearer requested.`));
20
+ } else if (typeof signCallbacks?.signCallback !== 'function') {
21
+ return Promise.reject(Error(`No sign callback supplied, but client-assertion jwt-bearer requested.`));
22
+ } else if (!credentialIssuer) {
23
+ return Promise.reject(Error(`No credential issuer supplied, but client-assertion jwt-bearer requested.`));
24
+ }
25
+ if (clientId.startsWith('http') && kid.includes('#')) {
26
+ kid = kid.split('#')[1];
27
+ }
28
+ const jwt: Jwt = {
29
+ header: {
30
+ typ: 'JWT',
31
+ kid,
32
+ alg: alg ?? 'ES256',
33
+ },
34
+ payload: {
35
+ iss: clientId,
36
+ sub: clientId,
37
+ aud: credentialIssuer,
38
+ jti: v4(),
39
+ exp: Date.now() / 1000 + 60,
40
+ iat: Date.now() / 1000 - 60,
41
+ },
42
+ };
43
+ const pop = await ProofOfPossessionBuilder.fromJwt({
44
+ jwt,
45
+ callbacks: signCallbacks,
46
+ version: opts.version ?? OpenId4VCIVersion.VER_1_0_13,
47
+ mode: 'JWT',
48
+ }).build();
49
+ request.client_assertion_type = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer';
50
+ request.client_assertion = pop.jwt;
51
+ }
52
+ };
@@ -1,2 +1,4 @@
1
1
  export * from './AuthorizationUtil';
2
2
  export * from './notifications';
3
+ export * from './OpenIDUtils';
4
+ export * from './AccessTokenUtil';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/oid4vci-client",
3
- "version": "0.12.1-unstable.9+9db2c63",
3
+ "version": "0.13.0",
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.12.1-unstable.9+9db2c63",
19
- "@sphereon/ssi-types": "0.25.1-unstable.87",
18
+ "@sphereon/oid4vci-common": "0.13.0",
19
+ "@sphereon/ssi-types": "0.26.1-next.6",
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": "9db2c63ee201cd6569caa668c82b9a00dedc89fd"
72
+ "gitHead": "4ae9812531dfb8bd45809127a215cdc5d02c6d4f"
73
73
  }