@sphereon/ssi-sdk.oid4vci-holder 0.33.1-feature.vcdm2.4 → 0.33.1-feature.vcdm2.tsup.19

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 (55) hide show
  1. package/dist/index.cjs +25401 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +786 -0
  4. package/dist/index.d.ts +785 -11
  5. package/dist/index.js +25355 -11
  6. package/dist/index.js.map +1 -1
  7. package/package.json +44 -34
  8. package/src/agent/OID4VCIHolder.ts +1 -1
  9. package/dist/agent/OID4VCIHolder.d.ts +0 -59
  10. package/dist/agent/OID4VCIHolder.d.ts.map +0 -1
  11. package/dist/agent/OID4VCIHolder.js +0 -882
  12. package/dist/agent/OID4VCIHolder.js.map +0 -1
  13. package/dist/index.d.ts.map +0 -1
  14. package/dist/link-handler/index.d.ts +0 -31
  15. package/dist/link-handler/index.d.ts.map +0 -1
  16. package/dist/link-handler/index.js +0 -71
  17. package/dist/link-handler/index.js.map +0 -1
  18. package/dist/listeners/headlessStateNavListener.d.ts +0 -3
  19. package/dist/listeners/headlessStateNavListener.d.ts.map +0 -1
  20. package/dist/listeners/headlessStateNavListener.js +0 -32
  21. package/dist/listeners/headlessStateNavListener.js.map +0 -1
  22. package/dist/localization/Localization.d.ts +0 -9
  23. package/dist/localization/Localization.d.ts.map +0 -1
  24. package/dist/localization/Localization.js +0 -41
  25. package/dist/localization/Localization.js.map +0 -1
  26. package/dist/localization/translations/en.json +0 -19
  27. package/dist/localization/translations/nl.json +0 -18
  28. package/dist/machines/firstPartyMachine.d.ts +0 -15
  29. package/dist/machines/firstPartyMachine.d.ts.map +0 -1
  30. package/dist/machines/firstPartyMachine.js +0 -223
  31. package/dist/machines/firstPartyMachine.js.map +0 -1
  32. package/dist/machines/oid4vciMachine.d.ts +0 -7
  33. package/dist/machines/oid4vciMachine.d.ts.map +0 -1
  34. package/dist/machines/oid4vciMachine.js +0 -708
  35. package/dist/machines/oid4vciMachine.js.map +0 -1
  36. package/dist/mappers/OIDC4VCIBrandingMapper.d.ts +0 -16
  37. package/dist/mappers/OIDC4VCIBrandingMapper.d.ts.map +0 -1
  38. package/dist/mappers/OIDC4VCIBrandingMapper.js +0 -229
  39. package/dist/mappers/OIDC4VCIBrandingMapper.js.map +0 -1
  40. package/dist/services/FirstPartyMachineServices.d.ts +0 -9
  41. package/dist/services/FirstPartyMachineServices.d.ts.map +0 -1
  42. package/dist/services/FirstPartyMachineServices.js +0 -42
  43. package/dist/services/FirstPartyMachineServices.js.map +0 -1
  44. package/dist/services/OID4VCIHolderService.d.ts +0 -28
  45. package/dist/services/OID4VCIHolderService.d.ts.map +0 -1
  46. package/dist/services/OID4VCIHolderService.js +0 -516
  47. package/dist/services/OID4VCIHolderService.js.map +0 -1
  48. package/dist/types/FirstPartyMachine.d.ts +0 -112
  49. package/dist/types/FirstPartyMachine.d.ts.map +0 -1
  50. package/dist/types/FirstPartyMachine.js +0 -27
  51. package/dist/types/FirstPartyMachine.js.map +0 -1
  52. package/dist/types/IOID4VCIHolder.d.ts +0 -558
  53. package/dist/types/IOID4VCIHolder.d.ts.map +0 -1
  54. package/dist/types/IOID4VCIHolder.js +0 -111
  55. package/dist/types/IOID4VCIHolder.js.map +0 -1
@@ -1,708 +0,0 @@
1
- import { AuthzFlowType, toAuthorizationResponsePayload } from '@sphereon/oid4vci-common';
2
- import { assign, createMachine, interpret } from 'xstate';
3
- import { translate } from '../localization/Localization';
4
- import { OID4VCIMachineAddContactStates, OID4VCIMachineEvents, OID4VCIMachineGuards, OID4VCIMachineServices, OID4VCIMachineStates, OID4VCIMachineVerifyPinStates, } from '../types/IOID4VCIHolder';
5
- import { FirstPartyMachineStateTypes } from '../types/FirstPartyMachine';
6
- const oid4vciHasNoContactGuard = (_ctx, _event) => {
7
- const { contact } = _ctx;
8
- return contact === undefined;
9
- };
10
- const oid4vciHasContactGuard = (_ctx, _event) => {
11
- const { contact } = _ctx;
12
- return contact !== undefined;
13
- };
14
- const oid4vciContactHasLowTrustGuard = (_ctx, _event) => {
15
- const { contact, trustedAnchors } = _ctx;
16
- return contact !== undefined && trustedAnchors !== undefined && trustedAnchors.length === 0;
17
- };
18
- const oid4vciCredentialsToSelectRequiredGuard = (_ctx, _event) => {
19
- const { credentialToSelectFrom } = _ctx;
20
- return credentialToSelectFrom && credentialToSelectFrom.length > 1;
21
- };
22
- const oid4vciRequirePinGuard = (_ctx, _event) => {
23
- const { requestData } = _ctx;
24
- return requestData?.credentialOffer?.userPinRequired === true;
25
- };
26
- const oid4vciHasNoContactIdentityGuard = (_ctx, _event) => {
27
- const { contact, credentialsToAccept } = _ctx;
28
- let toAcceptId = credentialsToAccept[0].correlationId;
29
- if (toAcceptId.match(/^https?:\/\/.*/)) {
30
- toAcceptId = new URL(toAcceptId).hostname;
31
- }
32
- return !contact?.identities.some((identity) => identity.identifier.correlationId === toAcceptId);
33
- };
34
- const oid4vciVerificationCodeGuard = (_ctx, _event) => {
35
- const { verificationCode } = _ctx;
36
- return verificationCode !== undefined && verificationCode.length > 0;
37
- };
38
- const oid4vciCreateContactGuard = (_ctx, _event) => {
39
- const { contactAlias, hasContactConsent } = _ctx;
40
- return hasContactConsent && !!contactAlias && contactAlias.length > 0;
41
- };
42
- const oid4vciHasSelectedCredentialsGuard = (_ctx, _event) => {
43
- const { selectedCredentials } = _ctx;
44
- return selectedCredentials !== undefined && selectedCredentials.length > 0;
45
- };
46
- const oid4vciIsOIDFOriginGuard = (_ctx, _event) => {
47
- // TODO in the future we need to establish if a origin is a IDF origin. So we need to check if this metadata is on the well-known location
48
- const { trustAnchors } = _ctx;
49
- return trustAnchors.length > 0;
50
- };
51
- const oid4vciNoAuthorizationGuard = (ctx, _event) => {
52
- return !oid4vciHasAuthorizationResponse(ctx, _event);
53
- };
54
- // FIXME refactor this guard
55
- const oid4vciRequireAuthorizationGuard = (ctx, _event) => {
56
- const { openID4VCIClientState } = ctx;
57
- if (!openID4VCIClientState) {
58
- throw Error('Missing openID4VCI client state in context');
59
- }
60
- if (!openID4VCIClientState.authorizationURL) {
61
- return false;
62
- }
63
- else if (openID4VCIClientState.authorizationRequestOpts) {
64
- // We have authz options or there is not credential offer to begin with.
65
- // We require authz as long as we do not have the authz code response
66
- return !ctx.openID4VCIClientState?.authorizationCodeResponse;
67
- }
68
- else if (openID4VCIClientState.credentialOffer?.supportedFlows?.includes(AuthzFlowType.AUTHORIZATION_CODE_FLOW)) {
69
- return !ctx.openID4VCIClientState?.authorizationCodeResponse;
70
- }
71
- else if (openID4VCIClientState.credentialOffer?.supportedFlows?.includes(AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW)) {
72
- return false;
73
- }
74
- else if (openID4VCIClientState.endpointMetadata?.credentialIssuerMetadata?.authorization_endpoint) {
75
- return !ctx.openID4VCIClientState?.authorizationCodeResponse;
76
- }
77
- return false;
78
- };
79
- const oid4vciHasAuthorizationResponse = (ctx, _event) => {
80
- return !!ctx.openID4VCIClientState?.authorizationCodeResponse;
81
- };
82
- const oid4vciIsFirstPartyApplication = (ctx, _event) => {
83
- return !!ctx.serverMetadata?.authorization_challenge_endpoint;
84
- };
85
- const createOID4VCIMachine = (opts) => {
86
- const initialContext = {
87
- // TODO WAL-671 we need to store the data from OpenIdProvider here in the context and make sure we can restart the machine with it and init the OpenIdProvider
88
- accessTokenOpts: opts?.accessTokenOpts,
89
- requestData: opts?.requestData,
90
- trustAnchors: opts?.trustAnchors ?? [],
91
- issuanceOpt: opts?.issuanceOpt,
92
- didMethodPreferences: opts?.didMethodPreferences,
93
- locale: opts?.locale,
94
- credentialsSupported: {},
95
- credentialToSelectFrom: [],
96
- selectedCredentials: [],
97
- credentialsToAccept: [],
98
- hasContactConsent: true,
99
- contactAlias: '',
100
- };
101
- return createMachine({
102
- id: opts?.machineName ?? 'OID4VCIHolder',
103
- predictableActionArguments: true,
104
- initial: OID4VCIMachineStates.start,
105
- schema: {
106
- events: {},
107
- guards: {},
108
- services: {},
109
- },
110
- context: initialContext,
111
- states: {
112
- [OID4VCIMachineStates.start]: {
113
- id: OID4VCIMachineStates.start,
114
- invoke: {
115
- src: OID4VCIMachineServices.start,
116
- onDone: {
117
- target: OID4VCIMachineStates.createCredentialsToSelectFrom,
118
- actions: assign({
119
- authorizationCodeURL: (_ctx, _event) => _event.data.authorizationCodeURL,
120
- credentialBranding: (_ctx, _event) => _event.data.credentialBranding ?? {},
121
- credentialsSupported: (_ctx, _event) => _event.data.credentialsSupported,
122
- serverMetadata: (_ctx, _event) => _event.data.serverMetadata,
123
- openID4VCIClientState: (_ctx, _event) => _event.data.oid4vciClientState,
124
- }),
125
- },
126
- onError: {
127
- target: OID4VCIMachineStates.handleError,
128
- actions: assign({
129
- error: (_ctx, _event) => ({
130
- title: translate('oid4vci_machine_initiation_error_title'),
131
- message: _event.data.message,
132
- stack: _event.data.stack,
133
- }),
134
- }),
135
- },
136
- },
137
- },
138
- [OID4VCIMachineStates.createCredentialsToSelectFrom]: {
139
- id: OID4VCIMachineStates.createCredentialsToSelectFrom,
140
- invoke: {
141
- src: OID4VCIMachineServices.createCredentialsToSelectFrom,
142
- onDone: {
143
- target: OID4VCIMachineStates.getContact,
144
- actions: assign({
145
- credentialToSelectFrom: (_ctx, _event) => _event.data,
146
- }),
147
- // TODO WAL-670 would be nice if we can have guard that checks if we have at least 1 item in the selection. not sure if this can occur but it would be more defensive.
148
- // Still cannot find a nice way to do this inside of an invoke besides adding another transition state
149
- },
150
- onError: {
151
- target: OID4VCIMachineStates.handleError,
152
- actions: assign({
153
- error: (_ctx, _event) => ({
154
- title: translate('oid4vci_machine_credential_selection_error_title'),
155
- message: _event.data.message,
156
- stack: _event.data.stack,
157
- }),
158
- }),
159
- },
160
- },
161
- },
162
- [OID4VCIMachineStates.getContact]: {
163
- id: OID4VCIMachineStates.getContact,
164
- invoke: {
165
- src: OID4VCIMachineServices.getContact,
166
- onDone: {
167
- target: OID4VCIMachineStates.getIssuerBranding,
168
- actions: assign({ contact: (_ctx, _event) => _event.data }),
169
- },
170
- onError: {
171
- target: OID4VCIMachineStates.handleError,
172
- actions: assign({
173
- error: (_ctx, _event) => ({
174
- title: translate('oid4vci_machine_retrieve_contact_error_title'),
175
- message: _event.data.message,
176
- stack: _event.data.stack,
177
- }),
178
- }),
179
- },
180
- },
181
- },
182
- [OID4VCIMachineStates.getIssuerBranding]: {
183
- id: OID4VCIMachineStates.getIssuerBranding,
184
- invoke: {
185
- src: OID4VCIMachineServices.getIssuerBranding,
186
- onDone: [
187
- {
188
- target: OID4VCIMachineStates.getFederationTrust,
189
- cond: OID4VCIMachineGuards.isOIDFOriginGuard,
190
- actions: assign({
191
- issuerBranding: (_ctx, _event) => _event.data,
192
- }),
193
- },
194
- {
195
- target: OID4VCIMachineStates.transitionFromSetup,
196
- actions: assign({
197
- issuerBranding: (_ctx, _event) => _event.data,
198
- }),
199
- },
200
- ],
201
- onError: {
202
- target: OID4VCIMachineStates.handleError,
203
- actions: assign({
204
- error: (_ctx, _event) => ({
205
- title: translate('oid4vci_machine_retrieve_issuer_branding_error_title'),
206
- message: _event.data.message,
207
- stack: _event.data.stack,
208
- }),
209
- }),
210
- },
211
- },
212
- },
213
- [OID4VCIMachineStates.getFederationTrust]: {
214
- id: OID4VCIMachineStates.getFederationTrust,
215
- invoke: {
216
- src: OID4VCIMachineServices.getFederationTrust,
217
- onDone: {
218
- target: OID4VCIMachineStates.transitionFromSetup,
219
- actions: assign({
220
- trustedAnchors: (_ctx, _event) => _event.data,
221
- }),
222
- },
223
- onError: {
224
- target: OID4VCIMachineStates.handleError,
225
- actions: assign({
226
- error: (_ctx, _event) => ({
227
- title: translate('oid4vci_machine_retrieve_federation_trust_error_title'),
228
- message: _event.data.message,
229
- stack: _event.data.stack,
230
- }),
231
- }),
232
- },
233
- },
234
- },
235
- [OID4VCIMachineStates.transitionFromSetup]: {
236
- id: OID4VCIMachineStates.transitionFromSetup,
237
- always: [
238
- {
239
- target: OID4VCIMachineStates.addContact,
240
- cond: OID4VCIMachineGuards.hasNoContactGuard,
241
- },
242
- {
243
- target: OID4VCIMachineStates.reviewContact,
244
- cond: OID4VCIMachineGuards.contactHasLowTrustGuard,
245
- },
246
- {
247
- target: OID4VCIMachineStates.selectCredentials,
248
- cond: OID4VCIMachineGuards.credentialsToSelectRequiredGuard,
249
- },
250
- {
251
- target: OID4VCIMachineStates.startFirstPartApplicationFlow,
252
- cond: OID4VCIMachineGuards.isFirstPartyApplication,
253
- },
254
- {
255
- target: OID4VCIMachineStates.initiateAuthorizationRequest,
256
- cond: OID4VCIMachineGuards.requireAuthorizationGuard,
257
- },
258
- {
259
- target: OID4VCIMachineStates.verifyPin,
260
- cond: OID4VCIMachineGuards.requirePinGuard,
261
- },
262
- {
263
- target: OID4VCIMachineStates.getCredentials,
264
- },
265
- ],
266
- on: {
267
- [OID4VCIMachineEvents.SET_AUTHORIZATION_CODE_URL]: {
268
- actions: assign({ authorizationCodeURL: (_ctx, _event) => _event.data }),
269
- },
270
- },
271
- },
272
- [OID4VCIMachineStates.addContact]: {
273
- id: OID4VCIMachineStates.addContact,
274
- initial: OID4VCIMachineAddContactStates.idle,
275
- on: {
276
- [OID4VCIMachineEvents.SET_CONTACT_CONSENT]: {
277
- actions: assign({ hasContactConsent: (_ctx, _event) => _event.data }),
278
- },
279
- [OID4VCIMachineEvents.SET_CONTACT_ALIAS]: {
280
- actions: assign({ contactAlias: (_ctx, _event) => _event.data }),
281
- },
282
- [OID4VCIMachineEvents.CREATE_CONTACT]: {
283
- target: `.${OID4VCIMachineAddContactStates.next}`,
284
- actions: assign({ contact: (_ctx, _event) => _event.data }),
285
- cond: OID4VCIMachineGuards.createContactGuard,
286
- },
287
- [OID4VCIMachineEvents.DECLINE]: {
288
- target: OID4VCIMachineStates.declined,
289
- },
290
- [OID4VCIMachineEvents.PREVIOUS]: {
291
- target: OID4VCIMachineStates.aborted,
292
- },
293
- },
294
- states: {
295
- [OID4VCIMachineAddContactStates.idle]: {},
296
- [OID4VCIMachineAddContactStates.next]: {
297
- always: {
298
- target: `#${OID4VCIMachineStates.storeIssuerBranding}`,
299
- cond: OID4VCIMachineGuards.hasContactGuard,
300
- },
301
- },
302
- },
303
- },
304
- [OID4VCIMachineStates.reviewContact]: {
305
- id: OID4VCIMachineStates.reviewContact,
306
- on: {
307
- [OID4VCIMachineEvents.NEXT]: {
308
- target: OID4VCIMachineStates.transitionFromContactSetup,
309
- },
310
- [OID4VCIMachineEvents.DECLINE]: {
311
- target: OID4VCIMachineStates.declined,
312
- },
313
- [OID4VCIMachineEvents.PREVIOUS]: {
314
- target: OID4VCIMachineStates.aborted,
315
- },
316
- },
317
- },
318
- [OID4VCIMachineStates.storeIssuerBranding]: {
319
- id: OID4VCIMachineStates.storeIssuerBranding,
320
- invoke: {
321
- src: OID4VCIMachineServices.storeIssuerBranding,
322
- onDone: {
323
- target: OID4VCIMachineStates.transitionFromContactSetup,
324
- },
325
- onError: {
326
- target: OID4VCIMachineStates.handleError,
327
- actions: assign({
328
- error: (_ctx, _event) => ({
329
- title: translate('oid4vci_machine_store_issuer_branding_error_title'),
330
- message: _event.data.message,
331
- stack: _event.data.stack,
332
- }),
333
- }),
334
- },
335
- },
336
- },
337
- [OID4VCIMachineStates.transitionFromContactSetup]: {
338
- id: OID4VCIMachineStates.transitionFromContactSetup,
339
- always: [
340
- {
341
- target: OID4VCIMachineStates.selectCredentials,
342
- cond: OID4VCIMachineGuards.credentialsToSelectRequiredGuard,
343
- },
344
- {
345
- target: OID4VCIMachineStates.startFirstPartApplicationFlow,
346
- cond: OID4VCIMachineGuards.isFirstPartyApplication,
347
- },
348
- {
349
- target: OID4VCIMachineStates.initiateAuthorizationRequest,
350
- cond: OID4VCIMachineGuards.requireAuthorizationGuard,
351
- },
352
- {
353
- target: OID4VCIMachineStates.verifyPin,
354
- cond: OID4VCIMachineGuards.requirePinGuard,
355
- },
356
- {
357
- target: OID4VCIMachineStates.getCredentials,
358
- },
359
- ],
360
- },
361
- [OID4VCIMachineStates.startFirstPartApplicationFlow]: {
362
- id: OID4VCIMachineStates.startFirstPartApplicationFlow,
363
- invoke: {
364
- src: OID4VCIMachineServices.startFirstPartApplicationFlow,
365
- onDone: [
366
- {
367
- target: OID4VCIMachineStates.aborted,
368
- cond: (_ctx, _event) => _event.data === FirstPartyMachineStateTypes.aborted,
369
- },
370
- {
371
- target: OID4VCIMachineStates.declined,
372
- cond: (_ctx, _event) => _event.data === FirstPartyMachineStateTypes.declined,
373
- },
374
- {
375
- target: OID4VCIMachineStates.getCredentials,
376
- actions: assign({
377
- openID4VCIClientState: (_ctx, _event) => {
378
- const authorizationCodeResponse = toAuthorizationResponsePayload(_event.data);
379
- return { ..._ctx.openID4VCIClientState, authorizationCodeResponse };
380
- },
381
- }),
382
- },
383
- ],
384
- onError: {
385
- target: OID4VCIMachineStates.handleError,
386
- actions: assign({
387
- error: (_ctx, _event) => ({
388
- title: _event.data.title ?? translate('oid4vci_machine_first_party_error_title'),
389
- message: _event.data.message,
390
- stack: _event.data.stack,
391
- }),
392
- }),
393
- },
394
- },
395
- },
396
- [OID4VCIMachineStates.selectCredentials]: {
397
- id: OID4VCIMachineStates.selectCredentials,
398
- on: {
399
- [OID4VCIMachineEvents.SET_SELECTED_CREDENTIALS]: {
400
- actions: assign({ selectedCredentials: (_ctx, _event) => _event.data }),
401
- },
402
- [OID4VCIMachineEvents.NEXT]: {
403
- target: OID4VCIMachineStates.transitionFromSelectingCredentials,
404
- cond: OID4VCIMachineGuards.hasSelectedCredentialsGuard,
405
- },
406
- [OID4VCIMachineEvents.PREVIOUS]: {
407
- target: OID4VCIMachineStates.aborted,
408
- },
409
- },
410
- },
411
- [OID4VCIMachineStates.transitionFromSelectingCredentials]: {
412
- id: OID4VCIMachineStates.transitionFromSelectingCredentials,
413
- always: [
414
- {
415
- target: OID4VCIMachineStates.startFirstPartApplicationFlow,
416
- cond: OID4VCIMachineGuards.isFirstPartyApplication,
417
- },
418
- {
419
- target: OID4VCIMachineStates.verifyPin,
420
- cond: OID4VCIMachineGuards.requirePinGuard,
421
- },
422
- {
423
- target: OID4VCIMachineStates.initiateAuthorizationRequest,
424
- cond: OID4VCIMachineGuards.requireAuthorizationGuard,
425
- },
426
- {
427
- target: OID4VCIMachineStates.getCredentials,
428
- },
429
- ],
430
- },
431
- [OID4VCIMachineStates.initiateAuthorizationRequest]: {
432
- id: OID4VCIMachineStates.initiateAuthorizationRequest,
433
- on: {
434
- [OID4VCIMachineEvents.PREVIOUS]: {
435
- target: OID4VCIMachineStates.selectCredentials,
436
- },
437
- [OID4VCIMachineEvents.INVOKED_AUTHORIZATION_CODE_REQUEST]: {
438
- target: OID4VCIMachineStates.waitForAuthorizationResponse,
439
- },
440
- },
441
- },
442
- [OID4VCIMachineStates.waitForAuthorizationResponse]: {
443
- id: OID4VCIMachineStates.waitForAuthorizationResponse,
444
- on: {
445
- [OID4VCIMachineEvents.PREVIOUS]: {
446
- target: OID4VCIMachineStates.initiateAuthorizationRequest,
447
- },
448
- [OID4VCIMachineEvents.PROVIDE_AUTHORIZATION_CODE_RESPONSE]: {
449
- actions: assign({
450
- openID4VCIClientState: (_ctx, _event) => {
451
- const authorizationCodeResponse = toAuthorizationResponsePayload(_event.data);
452
- return { ..._ctx.openID4VCIClientState, authorizationCodeResponse };
453
- },
454
- }),
455
- },
456
- },
457
- always: [
458
- {
459
- cond: OID4VCIMachineGuards.hasAuthorizationResponse,
460
- target: OID4VCIMachineStates.getCredentials,
461
- },
462
- ],
463
- },
464
- [OID4VCIMachineStates.verifyPin]: {
465
- id: OID4VCIMachineStates.verifyPin,
466
- initial: OID4VCIMachineVerifyPinStates.idle,
467
- on: {
468
- [OID4VCIMachineEvents.SET_VERIFICATION_CODE]: {
469
- target: `.${OID4VCIMachineVerifyPinStates.next}`,
470
- actions: assign({ verificationCode: (_ctx, _event) => _event.data }),
471
- },
472
- [OID4VCIMachineEvents.PREVIOUS]: [
473
- {
474
- target: OID4VCIMachineStates.selectCredentials,
475
- cond: OID4VCIMachineGuards.credentialsToSelectRequiredGuard,
476
- },
477
- {
478
- target: OID4VCIMachineStates.aborted,
479
- },
480
- ],
481
- },
482
- states: {
483
- [OID4VCIMachineVerifyPinStates.idle]: {},
484
- [OID4VCIMachineVerifyPinStates.next]: {
485
- always: {
486
- target: `#${OID4VCIMachineStates.getCredentials}`,
487
- cond: OID4VCIMachineGuards.verificationCodeGuard,
488
- },
489
- },
490
- },
491
- },
492
- [OID4VCIMachineStates.getCredentials]: {
493
- id: OID4VCIMachineStates.getCredentials,
494
- invoke: {
495
- src: OID4VCIMachineServices.getCredentials,
496
- onDone: {
497
- target: OID4VCIMachineStates.verifyCredentials,
498
- actions: assign({
499
- credentialsToAccept: (_ctx, _event) => _event.data,
500
- }),
501
- },
502
- onError: {
503
- target: OID4VCIMachineStates.handleError,
504
- actions: assign({
505
- error: (_ctx, _event) => ({
506
- title: translate('oid4vci_machine_retrieve_credentials_error_title'),
507
- message: _event.data.message,
508
- stack: _event.data.stack,
509
- }),
510
- }),
511
- },
512
- },
513
- exit: assign({ verificationCode: undefined }),
514
- },
515
- [OID4VCIMachineStates.verifyCredentials]: {
516
- id: OID4VCIMachineStates.verifyCredentials,
517
- invoke: {
518
- src: OID4VCIMachineServices.assertValidCredentials,
519
- onDone: {
520
- target: OID4VCIMachineStates.transitionFromWalletInput,
521
- },
522
- onError: {
523
- target: OID4VCIMachineStates.handleError,
524
- actions: assign({
525
- error: (_ctx, _event) => ({
526
- title: translate('oid4vci_machine_verify_credentials_error_title'),
527
- message: _event.data.message,
528
- stack: _event.data.stack,
529
- }),
530
- }),
531
- },
532
- },
533
- },
534
- [OID4VCIMachineStates.transitionFromWalletInput]: {
535
- id: OID4VCIMachineStates.transitionFromWalletInput,
536
- always: [
537
- {
538
- target: OID4VCIMachineStates.addContactIdentity,
539
- cond: OID4VCIMachineGuards.hasNoContactIdentityGuard,
540
- },
541
- {
542
- target: OID4VCIMachineStates.reviewCredentials,
543
- },
544
- ],
545
- },
546
- [OID4VCIMachineStates.addContactIdentity]: {
547
- id: OID4VCIMachineStates.addContactIdentity,
548
- invoke: {
549
- src: OID4VCIMachineServices.addContactIdentity,
550
- onDone: {
551
- target: OID4VCIMachineStates.addIssuerBrandingAfterIdentity,
552
- actions: (_ctx, _event) => {
553
- _ctx.contact?.identities.push(_event.data);
554
- },
555
- },
556
- onError: {
557
- target: OID4VCIMachineStates.handleError,
558
- actions: assign({
559
- error: (_ctx, _event) => ({
560
- title: translate('oid4vci_machine_add_contact_identity_error_title'),
561
- message: _event.data.message,
562
- stack: _event.data.stack,
563
- }),
564
- }),
565
- },
566
- },
567
- },
568
- [OID4VCIMachineStates.addIssuerBrandingAfterIdentity]: {
569
- id: OID4VCIMachineStates.addIssuerBrandingAfterIdentity,
570
- invoke: {
571
- src: OID4VCIMachineServices.storeIssuerBranding,
572
- onDone: {
573
- target: OID4VCIMachineStates.reviewCredentials,
574
- },
575
- onError: {
576
- target: OID4VCIMachineStates.handleError,
577
- actions: assign({
578
- error: (_ctx, _event) => ({
579
- title: translate('oid4vci_machine_store_issuer_branding_error_title'),
580
- message: _event.data.message,
581
- stack: _event.data.stack,
582
- }),
583
- }),
584
- },
585
- },
586
- },
587
- [OID4VCIMachineStates.reviewCredentials]: {
588
- id: OID4VCIMachineStates.reviewCredentials,
589
- on: {
590
- [OID4VCIMachineEvents.NEXT]: {
591
- target: OID4VCIMachineStates.storeCredentialBranding,
592
- },
593
- [OID4VCIMachineEvents.DECLINE]: {
594
- target: OID4VCIMachineStates.declined,
595
- },
596
- [OID4VCIMachineEvents.PREVIOUS]: {
597
- target: OID4VCIMachineStates.aborted,
598
- },
599
- },
600
- },
601
- [OID4VCIMachineStates.storeCredentialBranding]: {
602
- id: OID4VCIMachineStates.storeCredentialBranding,
603
- invoke: {
604
- src: OID4VCIMachineServices.storeCredentialBranding,
605
- onDone: {
606
- target: OID4VCIMachineStates.storeCredentials,
607
- },
608
- onError: {
609
- target: OID4VCIMachineStates.handleError,
610
- actions: assign({
611
- error: (_ctx, _event) => ({
612
- title: translate('oid4vci_machine_store_credential_branding_error_title'),
613
- message: _event.data.message,
614
- stack: _event.data.stack,
615
- }),
616
- }),
617
- },
618
- },
619
- },
620
- [OID4VCIMachineStates.storeCredentials]: {
621
- id: OID4VCIMachineStates.storeCredentials,
622
- invoke: {
623
- src: OID4VCIMachineServices.storeCredentials,
624
- onDone: {
625
- target: OID4VCIMachineStates.done,
626
- },
627
- onError: {
628
- target: OID4VCIMachineStates.handleError,
629
- actions: assign({
630
- error: (_ctx, _event) => ({
631
- title: translate('oid4vci_machine_store_credential_error_title'),
632
- message: _event.data.message,
633
- stack: _event.data.stack,
634
- }),
635
- }),
636
- },
637
- },
638
- },
639
- [OID4VCIMachineStates.handleError]: {
640
- id: OID4VCIMachineStates.handleError,
641
- on: {
642
- [OID4VCIMachineEvents.NEXT]: {
643
- target: OID4VCIMachineStates.error,
644
- },
645
- [OID4VCIMachineEvents.PREVIOUS]: {
646
- target: OID4VCIMachineStates.error,
647
- },
648
- },
649
- },
650
- [OID4VCIMachineStates.aborted]: {
651
- id: OID4VCIMachineStates.aborted,
652
- type: 'final',
653
- },
654
- [OID4VCIMachineStates.declined]: {
655
- id: OID4VCIMachineStates.declined,
656
- type: 'final',
657
- },
658
- [OID4VCIMachineStates.error]: {
659
- id: OID4VCIMachineStates.error,
660
- type: 'final',
661
- },
662
- [OID4VCIMachineStates.done]: {
663
- id: OID4VCIMachineStates.done,
664
- type: 'final',
665
- },
666
- },
667
- });
668
- };
669
- export class OID4VCIMachine {
670
- static async newInstance(opts, context) {
671
- const interpreter = interpret(createOID4VCIMachine(opts).withConfig({
672
- services: {
673
- ...opts?.services,
674
- },
675
- guards: {
676
- oid4vciHasNoContactGuard,
677
- oid4vciCredentialsToSelectRequiredGuard,
678
- oid4vciRequirePinGuard,
679
- oid4vciHasNoContactIdentityGuard,
680
- oid4vciVerificationCodeGuard,
681
- oid4vciHasContactGuard,
682
- oid4vciCreateContactGuard,
683
- oid4vciHasSelectedCredentialsGuard,
684
- oid4vciRequireAuthorizationGuard,
685
- oid4vciNoAuthorizationGuard,
686
- oid4vciHasAuthorizationResponse,
687
- oid4vciIsOIDFOriginGuard,
688
- oid4vciContactHasLowTrustGuard,
689
- oid4vciIsFirstPartyApplication,
690
- ...opts?.guards,
691
- },
692
- }));
693
- if (typeof opts?.subscription === 'function') {
694
- interpreter.onTransition(opts.subscription);
695
- }
696
- if (opts?.requireCustomNavigationHook !== true) {
697
- if (typeof opts?.stateNavigationListener === 'function') {
698
- interpreter.onTransition((snapshot) => {
699
- if (opts?.stateNavigationListener) {
700
- opts.stateNavigationListener(interpreter, snapshot);
701
- }
702
- });
703
- }
704
- }
705
- return { interpreter };
706
- }
707
- }
708
- //# sourceMappingURL=oid4vciMachine.js.map