@sphereon/ssi-sdk.oid4vci-holder 0.34.1-next.88 → 0.36.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.
@@ -1,16 +1,15 @@
1
1
  import { LOG } from '@sphereon/oid4vci-client'
2
2
  import {
3
+ AuthorizationChallengeCodeResponse,
3
4
  CredentialConfigurationSupported,
4
- CredentialSupportedSdJwtVc,
5
5
  CredentialConfigurationSupportedSdJwtVcV1_0_15,
6
- CredentialOfferFormatV1_0_11,
7
6
  CredentialResponse,
7
+ CredentialResponseV1_0_15,
8
+ CredentialSupportedSdJwtVc,
8
9
  getSupportedCredentials,
9
10
  getTypesFromCredentialSupported,
10
11
  getTypesFromObject,
11
12
  MetadataDisplay,
12
- OpenId4VCIVersion,
13
- AuthorizationChallengeCodeResponse,
14
13
  } from '@sphereon/oid4vci-common'
15
14
  import { KeyUse } from '@sphereon/ssi-sdk-ext.did-resolver-jwk'
16
15
  import { getOrCreatePrimaryIdentifier, SupportedDidMethodEnum } from '@sphereon/ssi-sdk-ext.did-utils'
@@ -23,7 +22,8 @@ import {
23
22
  managedIdentifierToJwk,
24
23
  } from '@sphereon/ssi-sdk-ext.identifier-resolution'
25
24
  import { keyTypeFromCryptographicSuite } from '@sphereon/ssi-sdk-ext.key-utils'
26
- import { IBasicCredentialLocaleBranding, IBasicIssuerLocaleBranding } from '@sphereon/ssi-sdk.data-store'
25
+ import { defaultHasher } from '@sphereon/ssi-sdk.core'
26
+ import { IBasicCredentialLocaleBranding, IBasicIssuerLocaleBranding } from '@sphereon/ssi-sdk.data-store-types'
27
27
  import {
28
28
  CredentialMapper,
29
29
  Hasher,
@@ -40,8 +40,12 @@ import {
40
40
  } from '@sphereon/ssi-types'
41
41
  import { asArray } from '@veramo/utils'
42
42
  import { translate } from '../localization/Localization'
43
+ import { FirstPartyMachine } from '../machines/firstPartyMachine'
44
+ import { issuerLocaleBrandingFrom, oid4vciGetCredentialBrandingFrom, sdJwtGetCredentialBrandingFrom } from '../mappers/OIDC4VCIBrandingMapper'
45
+ import { FirstPartyMachineState, FirstPartyMachineStateTypes } from '../types/FirstPartyMachine'
43
46
  import {
44
47
  DidAgents,
48
+ GetBasicIssuerLocaleBrandingArgs,
45
49
  GetCredentialBrandingArgs,
46
50
  GetCredentialConfigsSupportedArgs,
47
51
  GetCredentialConfigsSupportedBySingleTypeOrIdArgs,
@@ -49,22 +53,17 @@ import {
49
53
  GetIssuanceCryptoSuiteArgs,
50
54
  GetIssuanceDidMethodArgs,
51
55
  GetIssuanceOptsArgs,
52
- GetBasicIssuerLocaleBrandingArgs,
53
56
  GetPreferredCredentialFormatsArgs,
54
57
  IssuanceOpts,
55
58
  MapCredentialToAcceptArgs,
56
59
  MappedCredentialToAccept,
57
60
  OID4VCIHolderEvent,
61
+ RequiredContext,
58
62
  SelectAppLocaleBrandingArgs,
63
+ StartFirstPartApplicationMachine,
59
64
  VerificationResult,
60
65
  VerifyCredentialToAcceptArgs,
61
- StartFirstPartApplicationMachine,
62
- RequiredContext,
63
66
  } from '../types/IOID4VCIHolder'
64
- import { oid4vciGetCredentialBrandingFrom, sdJwtGetCredentialBrandingFrom, issuerLocaleBrandingFrom } from '../mappers/OIDC4VCIBrandingMapper'
65
- import { FirstPartyMachine } from '../machines/firstPartyMachine'
66
- import { FirstPartyMachineState, FirstPartyMachineStateTypes } from '../types/FirstPartyMachine'
67
- import { defaultHasher } from '@sphereon/ssi-sdk.core'
68
67
 
69
68
  export const getCredentialBranding = async (args: GetCredentialBrandingArgs): Promise<Record<string, Array<IBasicCredentialLocaleBranding>>> => {
70
69
  const { credentialsSupported, context } = args
@@ -153,21 +152,7 @@ export const selectCredentialLocaleBranding = async (
153
152
  export const verifyCredentialToAccept = async (args: VerifyCredentialToAcceptArgs): Promise<VerificationResult> => {
154
153
  const { mappedCredential, hasher, onVerifyEBSICredentialIssuer, schemaValidation, context } = args
155
154
 
156
- const credentialResponse = mappedCredential.credentialToAccept.credentialResponse
157
- let credential
158
- if ('credential' in credentialResponse) {
159
- credential = credentialResponse.credential as OriginalVerifiableCredential
160
- } else if (
161
- 'credentials' in credentialResponse &&
162
- credentialResponse.credentials &&
163
- Array.isArray(credentialResponse.credentials) &&
164
- credentialResponse.credentials.length > 0
165
- ) {
166
- credential = credentialResponse.credentials[0].credential as OriginalVerifiableCredential // FIXME SSISDK-13 (no multi-credential support yet)
167
- }
168
- if (!credential) {
169
- return Promise.reject(Error('No credential found in credential response'))
170
- }
155
+ const credential = extractCredentialFromResponse(mappedCredential.credentialToAccept.credentialResponse)
171
156
 
172
157
  const wrappedVC = CredentialMapper.toWrappedVerifiableCredential(credential, { hasher: hasher ?? defaultHasher })
173
158
  if (
@@ -216,21 +201,7 @@ export const verifyCredentialToAccept = async (args: VerifyCredentialToAcceptArg
216
201
  export const mapCredentialToAccept = async (args: MapCredentialToAcceptArgs): Promise<MappedCredentialToAccept> => {
217
202
  const { credentialToAccept, hasher } = args
218
203
 
219
- const credentialResponse: CredentialResponse = credentialToAccept.credentialResponse
220
- let verifiableCredential: W3CVerifiableCredential | undefined
221
- if ('credential' in credentialResponse) {
222
- verifiableCredential = credentialResponse.credential
223
- } else if (
224
- 'credentials' in credentialResponse &&
225
- credentialResponse.credentials &&
226
- Array.isArray(credentialResponse.credentials) &&
227
- credentialResponse.credentials.length > 0
228
- ) {
229
- verifiableCredential = credentialResponse.credentials[0].credential // FIXME SSISDK-13 (no multi-credential support yet)
230
- }
231
- if (!verifiableCredential) {
232
- return Promise.reject(Error('No credential found in credential response'))
233
- }
204
+ const verifiableCredential = extractCredentialFromResponse(credentialToAccept.credentialResponse) as W3CVerifiableCredential
234
205
 
235
206
  const wrappedVerifiableCredential: WrappedVerifiableCredential = CredentialMapper.toWrappedVerifiableCredential(
236
207
  verifiableCredential as OriginalVerifiableCredential,
@@ -238,9 +209,7 @@ export const mapCredentialToAccept = async (args: MapCredentialToAcceptArgs): Pr
238
209
  )
239
210
  let uniformVerifiableCredential: IVerifiableCredential
240
211
  if (CredentialMapper.isSdJwtDecodedCredential(wrappedVerifiableCredential.credential)) {
241
- uniformVerifiableCredential = await sdJwtDecodedCredentialToUniformCredential(
242
- <SdJwtDecodedVerifiableCredential>wrappedVerifiableCredential.credential,
243
- )
212
+ uniformVerifiableCredential = sdJwtDecodedCredentialToUniformCredential(<SdJwtDecodedVerifiableCredential>wrappedVerifiableCredential.credential)
244
213
  } else if (CredentialMapper.isSdJwtEncoded(wrappedVerifiableCredential.credential)) {
245
214
  if (!hasher) {
246
215
  return Promise.reject('a hasher is required for encoded SD-JWT credentials')
@@ -261,6 +230,7 @@ export const mapCredentialToAccept = async (args: MapCredentialToAcceptArgs): Pr
261
230
  ? uniformVerifiableCredential.decodedPayload.iss
262
231
  : uniformVerifiableCredential.issuer.id
263
232
 
233
+ const credentialResponse = credentialToAccept.credentialResponse as CredentialResponseV1_0_15
264
234
  return {
265
235
  correlationId,
266
236
  credentialToAccept,
@@ -271,6 +241,27 @@ export const mapCredentialToAccept = async (args: MapCredentialToAcceptArgs): Pr
271
241
  }
272
242
  }
273
243
 
244
+ export const extractCredentialFromResponse = (credentialResponse: CredentialResponse): OriginalVerifiableCredential => {
245
+ let credential: OriginalVerifiableCredential | undefined
246
+
247
+ if ('credential' in credentialResponse) {
248
+ credential = credentialResponse.credential as OriginalVerifiableCredential
249
+ } else if (
250
+ 'credentials' in credentialResponse &&
251
+ credentialResponse.credentials &&
252
+ Array.isArray(credentialResponse.credentials) &&
253
+ credentialResponse.credentials.length > 0
254
+ ) {
255
+ credential = credentialResponse.credentials[0].credential as OriginalVerifiableCredential // FIXME SSISDK-13 (no multi-credential support yet)
256
+ }
257
+
258
+ if (!credential) {
259
+ throw new Error('No credential found in credential response')
260
+ }
261
+
262
+ return credential
263
+ }
264
+
274
265
  export const getIdentifierOpts = async (args: GetIdentifierArgs): Promise<ManagedIdentifierResult> => {
275
266
  const { issuanceOpt, context } = args
276
267
  const { identifier: identifierArg } = issuanceOpt
@@ -391,7 +382,7 @@ export const getCredentialConfigsSupportedBySingleTypeOrId = async (
391
382
  }
392
383
 
393
384
  if (configurationId) {
394
- const allSupported = client.getCredentialsSupported(false)
385
+ const allSupported = client.getCredentialsSupported(undefined, format)
395
386
  return Object.fromEntries(
396
387
  Object.entries(allSupported).filter(
397
388
  ([id, supported]) => id === configurationId || supported.id === configurationId || createIdFromTypes(supported) === configurationId,
@@ -399,29 +390,15 @@ export const getCredentialConfigsSupportedBySingleTypeOrId = async (
399
390
  )
400
391
  }
401
392
 
402
- if (!types && !client.credentialOffer) {
403
- return Promise.reject(Error('openID4VCIClient has no credentialOffer and no types where provided'))
404
- /*} else if (!format && !client.credentialOffer) {
405
- return Promise.reject(Error('openID4VCIClient has no credentialOffer and no formats where provided'))*/
393
+ if (!client.credentialOffer) {
394
+ return Promise.reject(Error('openID4VCIClient has no credentialOffer'))
406
395
  }
407
- // We should always have a credential offer at this point given the above
408
- if (!Array.isArray(format) && client.credentialOffer) {
409
- if (
410
- client.version() > OpenId4VCIVersion.VER_1_0_09 &&
411
- typeof client.credentialOffer.credential_offer === 'object' &&
412
- 'credentials' in client.credentialOffer.credential_offer
413
- ) {
414
- format = client.credentialOffer.credential_offer.credentials
415
- .filter((cred: CredentialOfferFormatV1_0_11 | string) => typeof cred !== 'string')
416
- .map((cred: CredentialOfferFormatV1_0_11 | string) => (cred as CredentialOfferFormatV1_0_11).format)
417
- if (format?.length === 0) {
418
- format = undefined // Otherwise we would match nothing
419
- }
420
- }
396
+ if (!types) {
397
+ return Promise.reject(Error('openID4VCIClient has no types'))
421
398
  }
422
399
 
423
400
  const offerSupported = getSupportedCredentials({
424
- types: types ? [types] : client.getCredentialOfferTypes(),
401
+ types: [types],
425
402
  format,
426
403
  version: client.version(),
427
404
  issuerMetadata: client.endpointMetadata.credentialIssuerMetadata,
@@ -1,12 +1,12 @@
1
- import { BaseActionObject, Interpreter, ResolveTypegenMeta, ServiceMap, State, StateMachine, StatesConfig, TypegenDisabled } from 'xstate'
2
- import { OpenID4VCIClientState } from '@sphereon/oid4vci-client'
3
- import { DidAuthConfig, Party } from '@sphereon/ssi-sdk.data-store'
4
1
  import { RPRegistrationMetadataPayload } from '@sphereon/did-auth-siop'
5
- import { UniqueDigitalCredential } from '@sphereon/ssi-sdk.credential-store'
2
+ import { OpenID4VCIClientState } from '@sphereon/oid4vci-client'
6
3
  import { AuthorizationChallengeCodeResponse } from '@sphereon/oid4vci-common'
4
+ import { UniqueDigitalCredential } from '@sphereon/ssi-sdk.credential-store'
5
+ import { DidAuthConfig, Party } from '@sphereon/ssi-sdk.data-store-types'
7
6
  import { IIdentifier } from '@veramo/core'
8
- import { ErrorDetails, RequiredContext } from './IOID4VCIHolder'
9
7
  import { DcqlQuery } from 'dcql'
8
+ import { BaseActionObject, Interpreter, ResolveTypegenMeta, ServiceMap, State, StateMachine, StatesConfig, TypegenDisabled } from 'xstate'
9
+ import { ErrorDetails, RequiredContext } from './IOID4VCIHolder'
10
10
 
11
11
  export enum FirstPartyMachineStateTypes {
12
12
  sendAuthorizationChallengeRequest = 'sendAuthorizationChallengeRequest',
@@ -1,4 +1,5 @@
1
- import { OpenID4VCIClient, OpenID4VCIClientState } from '@sphereon/oid4vci-client'
1
+ import { DynamicRegistrationClientMetadata } from '@sphereon/oid4vc-common'
2
+ import { OpenID4VCIClientState, OpenID4VCIClientV1_0_15 } from '@sphereon/oid4vci-client'
2
3
  import {
3
4
  AuthorizationRequestOpts,
4
5
  AuthorizationResponse,
@@ -15,7 +16,6 @@ import {
15
16
  MetadataDisplay,
16
17
  NotificationRequest,
17
18
  } from '@sphereon/oid4vci-common'
18
- import { DynamicRegistrationClientMetadata } from '@sphereon/oid4vc-common'
19
19
  import { CreateOrGetIdentifierOpts, IdentifierProviderOpts, SupportedDidMethodEnum } from '@sphereon/ssi-sdk-ext.did-utils'
20
20
  import {
21
21
  IIdentifierResolution,
@@ -26,6 +26,7 @@ import {
26
26
  import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service'
27
27
  import { IContactManager } from '@sphereon/ssi-sdk.contact-manager'
28
28
  import { ICredentialStore } from '@sphereon/ssi-sdk.credential-store'
29
+ import { ICredentialValidation, SchemaValidation } from '@sphereon/ssi-sdk.credential-validation'
29
30
  import {
30
31
  DigitalCredential,
31
32
  IBasicCredentialClaim,
@@ -34,11 +35,10 @@ import {
34
35
  Identity,
35
36
  IIssuerLocaleBranding,
36
37
  Party,
37
- } from '@sphereon/ssi-sdk.data-store'
38
+ } from '@sphereon/ssi-sdk.data-store-types'
38
39
  import { IIssuanceBranding } from '@sphereon/ssi-sdk.issuance-branding'
39
40
  import { ImDLMdoc } from '@sphereon/ssi-sdk.mdl-mdoc'
40
41
  import { ISDJwtPlugin } from '@sphereon/ssi-sdk.sd-jwt'
41
- import { ICredentialValidation, SchemaValidation } from '@sphereon/ssi-sdk.credential-validation'
42
42
  import { IDidAuthSiopOpAuthenticator } from '@sphereon/ssi-sdk.siopv2-oid4vp-op-auth'
43
43
  import {
44
44
  HasherSync,
@@ -79,6 +79,7 @@ export interface IOID4VCIHolder extends IPluginMethodMap {
79
79
  context: RequiredContext,
80
80
  ): Promise<Array<CredentialToSelectFromResult>>
81
81
 
82
+ oid4vciHolderPrepareAuthorizationRequest(args: PrepareAuthorizationRequestArgs, context: RequiredContext): Promise<PrepareAuthorizationResult>
82
83
  oid4vciHolderGetContact(args: GetContactArgs, context: RequiredContext): Promise<Party | undefined>
83
84
 
84
85
  oid4vciHolderGetCredentials(args: GetCredentialsArgs, context: RequiredContext): Promise<Array<MappedCredentialToAccept>>
@@ -148,6 +149,7 @@ export type PrepareStartArgs = Pick<
148
149
  OID4VCIMachineContext,
149
150
  'requestData' | 'authorizationRequestOpts' | 'didMethodPreferences' | 'issuanceOpt' | 'accessTokenOpts'
150
151
  >
152
+ export type PrepareAuthorizationRequestArgs = Pick<OID4VCIMachineContext, 'openID4VCIClientState' | 'contact'>
151
153
  export type CreateCredentialsToSelectFromArgs = Pick<
152
154
  OID4VCIMachineContext,
153
155
  'credentialsSupported' | 'credentialBranding' | 'selectedCredentials' | 'locale' | 'openID4VCIClientState'
@@ -256,6 +258,7 @@ export enum OID4VCIMachineStates {
256
258
  selectCredentials = 'selectCredentials',
257
259
  transitionFromSelectingCredentials = 'transitionFromSelectingCredentials',
258
260
  verifyPin = 'verifyPin',
261
+ prepareAuthorizationRequest = 'prepareAuthorizationRequest',
259
262
  initiateAuthorizationRequest = 'initiateAuthorizationRequest',
260
263
  waitForAuthorizationResponse = 'waitForAuthorizationResponse',
261
264
  getCredentials = 'getCredentials',
@@ -395,6 +398,7 @@ export enum OID4VCIMachineServices {
395
398
  getFederationTrust = 'getFederationTrust',
396
399
  addContactIdentity = 'addContactIdentity',
397
400
  createCredentialsToSelectFrom = 'createCredentialsToSelectFrom',
401
+ prepareAuthorizationRequest = 'prepareAuthorizationRequest',
398
402
  getIssuerBranding = 'getIssuerBranding',
399
403
  storeIssuerBranding = 'storeIssuerBranding',
400
404
  getCredentials = 'getCredentials',
@@ -460,13 +464,17 @@ export type OID4VCIMachine = {
460
464
  }
461
465
 
462
466
  export type StartResult = {
463
- authorizationCodeURL?: string
464
467
  credentialBranding?: Record<string, Array<IBasicCredentialLocaleBranding>>
465
468
  credentialsSupported: Record<string, CredentialConfigurationSupported>
466
469
  serverMetadata: EndpointMetadataResult
467
470
  oid4vciClientState: OpenID4VCIClientState
468
471
  }
469
472
 
473
+ export type PrepareAuthorizationResult = {
474
+ authorizationCodeURL?: string
475
+ oid4vciClientState: OpenID4VCIClientState
476
+ }
477
+
470
478
  export type SelectAppLocaleBrandingArgs = {
471
479
  locale?: string
472
480
  localeBranding?: Array<IBasicCredentialLocaleBranding | IBasicIssuerLocaleBranding>
@@ -507,7 +515,7 @@ export type CredentialToAccept = {
507
515
  }
508
516
 
509
517
  export type GetCredentialConfigsSupportedArgs = {
510
- client: OpenID4VCIClient
518
+ client: OpenID4VCIClientV1_0_15
511
519
  vcFormatPreferences: Array<string>
512
520
  format?: Array<string>
513
521
  types?: Array<Array<string>>
@@ -519,7 +527,7 @@ export type GetCredentialConfigsSupportedArgs = {
519
527
  * It can potentially return multiple results mainly because of different formats.
520
528
  */
521
529
  export type GetCredentialConfigsSupportedBySingleTypeOrIdArgs = {
522
- client: OpenID4VCIClient
530
+ client: OpenID4VCIClientV1_0_15
523
531
  vcFormatPreferences: Array<string>
524
532
  format?: string[]
525
533
  types?: string[]
@@ -554,7 +562,7 @@ export type GetDefaultIssuanceOptsArgs = {
554
562
  }
555
563
 
556
564
  export type DefaultIssuanceOpts = {
557
- client: OpenID4VCIClient
565
+ client: OpenID4VCIClientV1_0_15
558
566
  }
559
567
 
560
568
  export type GetIdentifierArgs = {
@@ -591,7 +599,7 @@ export type CreateIdentifierCreateOpts = {
591
599
  }
592
600
 
593
601
  export type GetIssuanceOptsArgs = {
594
- client: OpenID4VCIClient
602
+ client: OpenID4VCIClientV1_0_15
595
603
  credentialsSupported: Record<string, CredentialConfigurationSupported>
596
604
  serverMetadata: EndpointMetadataResult
597
605
  context: RequiredContext
@@ -603,13 +611,13 @@ export type GetIssuanceOptsArgs = {
603
611
 
604
612
  export type GetIssuanceDidMethodArgs = {
605
613
  credentialSupported: CredentialConfigurationSupported
606
- client: OpenID4VCIClient
614
+ client: OpenID4VCIClientV1_0_15
607
615
  didMethodPreferences: Array<SupportedDidMethodEnum>
608
616
  }
609
617
 
610
618
  export type GetIssuanceCryptoSuiteArgs = {
611
619
  credentialSupported: CredentialConfigurationSupported
612
- client: OpenID4VCIClient
620
+ client: OpenID4VCIClientV1_0_15
613
621
  jwtCryptographicSuitePreferences: Array<JoseSignatureAlgorithm | JoseSignatureAlgorithmString>
614
622
  jsonldCryptographicSuitePreferences: Array<string>
615
623
  }
@@ -617,7 +625,7 @@ export type GetIssuanceCryptoSuiteArgs = {
617
625
  export type GetCredentialArgs = {
618
626
  pin?: string
619
627
  issuanceOpt: IssuanceOpts
620
- client: OpenID4VCIClient
628
+ client: OpenID4VCIClientV1_0_15
621
629
  accessTokenOpts?: AccessTokenOpts
622
630
  }
623
631