@sphereon/ssi-sdk.oid4vci-holder 0.34.1-next.3 → 0.34.1-next.323
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.
- package/dist/index.cjs +646 -572
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -17
- package/dist/index.d.ts +28 -17
- package/dist/index.js +629 -555
- package/dist/index.js.map +1 -1
- package/package.json +25 -24
- package/src/agent/OID4VCIHolder.ts +111 -54
- package/src/machines/firstPartyMachine.ts +1 -1
- package/src/machines/oid4vciMachine.ts +39 -6
- package/src/mappers/OIDC4VCIBrandingMapper.ts +1 -1
- package/src/services/OID4VCIHolderService.ts +47 -48
- package/src/types/FirstPartyMachine.ts +6 -5
- package/src/types/IOID4VCIHolder.ts +23 -13
package/dist/index.cjs
CHANGED
|
@@ -100,6 +100,7 @@ __export(index_exports, {
|
|
|
100
100
|
RequestType: () => RequestType,
|
|
101
101
|
SupportedLanguage: () => SupportedLanguage,
|
|
102
102
|
createConfig: () => createConfig,
|
|
103
|
+
extractCredentialFromResponse: () => extractCredentialFromResponse,
|
|
103
104
|
getBasicIssuerLocaleBranding: () => getBasicIssuerLocaleBranding,
|
|
104
105
|
getCredentialBranding: () => getCredentialBranding,
|
|
105
106
|
getCredentialConfigsBasedOnFormatPref: () => getCredentialConfigsBasedOnFormatPref,
|
|
@@ -139,9 +140,11 @@ var import_oid4vci_common4 = require("@sphereon/oid4vci-common");
|
|
|
139
140
|
var import_ssi_sdk_ext5 = require("@sphereon/ssi-sdk-ext.did-utils");
|
|
140
141
|
var import_ssi_sdk_ext6 = require("@sphereon/ssi-sdk-ext.identifier-resolution");
|
|
141
142
|
var import_ssi_sdk_ext7 = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
142
|
-
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.
|
|
143
|
+
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.core");
|
|
144
|
+
var import_ssi_sdk3 = require("@sphereon/ssi-sdk.data-store-types");
|
|
143
145
|
var import_ssi_types2 = require("@sphereon/ssi-types");
|
|
144
146
|
var import_utils2 = require("@veramo/utils");
|
|
147
|
+
var import_cross_fetch = __toESM(require("cross-fetch"), 1);
|
|
145
148
|
var import_did_jwt = require("did-jwt");
|
|
146
149
|
var import_uuid2 = require("uuid");
|
|
147
150
|
|
|
@@ -154,18 +157,18 @@ var import_i18n_js = __toESM(require("i18n-js"), 1);
|
|
|
154
157
|
var import_lodash = __toESM(require("lodash.memoize"), 1);
|
|
155
158
|
|
|
156
159
|
// src/types/IOID4VCIHolder.ts
|
|
157
|
-
var OID4VCIHolderEvent = /* @__PURE__ */ function(OID4VCIHolderEvent2) {
|
|
160
|
+
var OID4VCIHolderEvent = /* @__PURE__ */ (function(OID4VCIHolderEvent2) {
|
|
158
161
|
OID4VCIHolderEvent2["CONTACT_IDENTITY_CREATED"] = "contact_identity_created";
|
|
159
162
|
OID4VCIHolderEvent2["CREDENTIAL_STORED"] = "credential_stored";
|
|
160
163
|
OID4VCIHolderEvent2["IDENTIFIER_CREATED"] = "identifier_created";
|
|
161
164
|
return OID4VCIHolderEvent2;
|
|
162
|
-
}({});
|
|
163
|
-
var SupportedLanguage = /* @__PURE__ */ function(SupportedLanguage2) {
|
|
165
|
+
})({});
|
|
166
|
+
var SupportedLanguage = /* @__PURE__ */ (function(SupportedLanguage2) {
|
|
164
167
|
SupportedLanguage2["ENGLISH"] = "en";
|
|
165
168
|
SupportedLanguage2["DUTCH"] = "nl";
|
|
166
169
|
return SupportedLanguage2;
|
|
167
|
-
}({});
|
|
168
|
-
var OID4VCIMachineStates = /* @__PURE__ */ function(OID4VCIMachineStates2) {
|
|
170
|
+
})({});
|
|
171
|
+
var OID4VCIMachineStates = /* @__PURE__ */ (function(OID4VCIMachineStates2) {
|
|
169
172
|
OID4VCIMachineStates2["start"] = "start";
|
|
170
173
|
OID4VCIMachineStates2["createCredentialsToSelectFrom"] = "createCredentialsToSelectFrom";
|
|
171
174
|
OID4VCIMachineStates2["getContact"] = "getContact";
|
|
@@ -181,6 +184,7 @@ var OID4VCIMachineStates = /* @__PURE__ */ function(OID4VCIMachineStates2) {
|
|
|
181
184
|
OID4VCIMachineStates2["selectCredentials"] = "selectCredentials";
|
|
182
185
|
OID4VCIMachineStates2["transitionFromSelectingCredentials"] = "transitionFromSelectingCredentials";
|
|
183
186
|
OID4VCIMachineStates2["verifyPin"] = "verifyPin";
|
|
187
|
+
OID4VCIMachineStates2["prepareAuthorizationRequest"] = "prepareAuthorizationRequest";
|
|
184
188
|
OID4VCIMachineStates2["initiateAuthorizationRequest"] = "initiateAuthorizationRequest";
|
|
185
189
|
OID4VCIMachineStates2["waitForAuthorizationResponse"] = "waitForAuthorizationResponse";
|
|
186
190
|
OID4VCIMachineStates2["getCredentials"] = "getCredentials";
|
|
@@ -196,18 +200,18 @@ var OID4VCIMachineStates = /* @__PURE__ */ function(OID4VCIMachineStates2) {
|
|
|
196
200
|
OID4VCIMachineStates2["error"] = "error";
|
|
197
201
|
OID4VCIMachineStates2["done"] = "done";
|
|
198
202
|
return OID4VCIMachineStates2;
|
|
199
|
-
}({});
|
|
200
|
-
var OID4VCIMachineAddContactStates = /* @__PURE__ */ function(OID4VCIMachineAddContactStates2) {
|
|
203
|
+
})({});
|
|
204
|
+
var OID4VCIMachineAddContactStates = /* @__PURE__ */ (function(OID4VCIMachineAddContactStates2) {
|
|
201
205
|
OID4VCIMachineAddContactStates2["idle"] = "idle";
|
|
202
206
|
OID4VCIMachineAddContactStates2["next"] = "next";
|
|
203
207
|
return OID4VCIMachineAddContactStates2;
|
|
204
|
-
}({});
|
|
205
|
-
var OID4VCIMachineVerifyPinStates = /* @__PURE__ */ function(OID4VCIMachineVerifyPinStates2) {
|
|
208
|
+
})({});
|
|
209
|
+
var OID4VCIMachineVerifyPinStates = /* @__PURE__ */ (function(OID4VCIMachineVerifyPinStates2) {
|
|
206
210
|
OID4VCIMachineVerifyPinStates2["idle"] = "idle";
|
|
207
211
|
OID4VCIMachineVerifyPinStates2["next"] = "next";
|
|
208
212
|
return OID4VCIMachineVerifyPinStates2;
|
|
209
|
-
}({});
|
|
210
|
-
var OID4VCIMachineEvents = /* @__PURE__ */ function(OID4VCIMachineEvents2) {
|
|
213
|
+
})({});
|
|
214
|
+
var OID4VCIMachineEvents = /* @__PURE__ */ (function(OID4VCIMachineEvents2) {
|
|
211
215
|
OID4VCIMachineEvents2["NEXT"] = "NEXT";
|
|
212
216
|
OID4VCIMachineEvents2["PREVIOUS"] = "PREVIOUS";
|
|
213
217
|
OID4VCIMachineEvents2["DECLINE"] = "DECLINE";
|
|
@@ -220,14 +224,15 @@ var OID4VCIMachineEvents = /* @__PURE__ */ function(OID4VCIMachineEvents2) {
|
|
|
220
224
|
OID4VCIMachineEvents2["INVOKED_AUTHORIZATION_CODE_REQUEST"] = "INVOKED_AUTHORIZATION_CODE_REQUEST";
|
|
221
225
|
OID4VCIMachineEvents2["PROVIDE_AUTHORIZATION_CODE_RESPONSE"] = "PROVIDE_AUTHORIZATION_CODE_RESPONSE";
|
|
222
226
|
return OID4VCIMachineEvents2;
|
|
223
|
-
}({});
|
|
224
|
-
var OID4VCIMachineGuards = /* @__PURE__ */ function(OID4VCIMachineGuards2) {
|
|
227
|
+
})({});
|
|
228
|
+
var OID4VCIMachineGuards = /* @__PURE__ */ (function(OID4VCIMachineGuards2) {
|
|
225
229
|
OID4VCIMachineGuards2["hasContactGuard"] = "oid4vciHasContactGuard";
|
|
226
230
|
OID4VCIMachineGuards2["hasNoContactGuard"] = "oid4vciHasNoContactGuard";
|
|
227
231
|
OID4VCIMachineGuards2["credentialsToSelectRequiredGuard"] = "oid4vciCredentialsToSelectRequiredGuard";
|
|
228
232
|
OID4VCIMachineGuards2["requirePinGuard"] = "oid4vciRequirePinGuard";
|
|
229
233
|
OID4VCIMachineGuards2["requireAuthorizationGuard"] = "oid4vciRequireAuthorizationGuard";
|
|
230
234
|
OID4VCIMachineGuards2["noAuthorizationGuard"] = "oid4vciNoAuthorizationGuard";
|
|
235
|
+
OID4VCIMachineGuards2["hasNonceEndpointGuard"] = "oid4vciHasNonceEndpointGuard ";
|
|
231
236
|
OID4VCIMachineGuards2["hasAuthorizationResponse"] = "oid4vciHasAuthorizationResponse";
|
|
232
237
|
OID4VCIMachineGuards2["hasNoContactIdentityGuard"] = "oid4vciHasNoContactIdentityGuard";
|
|
233
238
|
OID4VCIMachineGuards2["verificationCodeGuard"] = "oid4vciVerificationCodeGuard";
|
|
@@ -237,13 +242,14 @@ var OID4VCIMachineGuards = /* @__PURE__ */ function(OID4VCIMachineGuards2) {
|
|
|
237
242
|
OID4VCIMachineGuards2["contactHasLowTrustGuard"] = "oid4vciContactHasLowTrustGuard";
|
|
238
243
|
OID4VCIMachineGuards2["isFirstPartyApplication"] = "oid4vciIsFirstPartyApplication";
|
|
239
244
|
return OID4VCIMachineGuards2;
|
|
240
|
-
}({});
|
|
241
|
-
var OID4VCIMachineServices = /* @__PURE__ */ function(OID4VCIMachineServices2) {
|
|
245
|
+
})({});
|
|
246
|
+
var OID4VCIMachineServices = /* @__PURE__ */ (function(OID4VCIMachineServices2) {
|
|
242
247
|
OID4VCIMachineServices2["start"] = "start";
|
|
243
248
|
OID4VCIMachineServices2["getContact"] = "getContact";
|
|
244
249
|
OID4VCIMachineServices2["getFederationTrust"] = "getFederationTrust";
|
|
245
250
|
OID4VCIMachineServices2["addContactIdentity"] = "addContactIdentity";
|
|
246
251
|
OID4VCIMachineServices2["createCredentialsToSelectFrom"] = "createCredentialsToSelectFrom";
|
|
252
|
+
OID4VCIMachineServices2["prepareAuthorizationRequest"] = "prepareAuthorizationRequest";
|
|
247
253
|
OID4VCIMachineServices2["getIssuerBranding"] = "getIssuerBranding";
|
|
248
254
|
OID4VCIMachineServices2["storeIssuerBranding"] = "storeIssuerBranding";
|
|
249
255
|
OID4VCIMachineServices2["getCredentials"] = "getCredentials";
|
|
@@ -253,17 +259,17 @@ var OID4VCIMachineServices = /* @__PURE__ */ function(OID4VCIMachineServices2) {
|
|
|
253
259
|
OID4VCIMachineServices2["storeCredentials"] = "storeCredentials";
|
|
254
260
|
OID4VCIMachineServices2["startFirstPartApplicationFlow"] = "startFirstPartApplicationFlow";
|
|
255
261
|
return OID4VCIMachineServices2;
|
|
256
|
-
}({});
|
|
257
|
-
var RequestType = /* @__PURE__ */ function(RequestType2) {
|
|
262
|
+
})({});
|
|
263
|
+
var RequestType = /* @__PURE__ */ (function(RequestType2) {
|
|
258
264
|
RequestType2["OPENID_INITIATE_ISSUANCE"] = "openid-initiate-issuance";
|
|
259
265
|
RequestType2["OPENID_CREDENTIAL_OFFER"] = "openid-credential-offer";
|
|
260
266
|
RequestType2["URL"] = "URL";
|
|
261
267
|
return RequestType2;
|
|
262
|
-
}({});
|
|
263
|
-
var IdentifierAliasEnum = /* @__PURE__ */ function(IdentifierAliasEnum2) {
|
|
268
|
+
})({});
|
|
269
|
+
var IdentifierAliasEnum = /* @__PURE__ */ (function(IdentifierAliasEnum2) {
|
|
264
270
|
IdentifierAliasEnum2["PRIMARY"] = "primary";
|
|
265
271
|
return IdentifierAliasEnum2;
|
|
266
|
-
}({});
|
|
272
|
+
})({});
|
|
267
273
|
|
|
268
274
|
// src/localization/Localization.ts
|
|
269
275
|
var Localization = class Localization2 {
|
|
@@ -305,7 +311,7 @@ var Localization = class Localization2 {
|
|
|
305
311
|
var translate = Localization.translate;
|
|
306
312
|
|
|
307
313
|
// src/types/FirstPartyMachine.ts
|
|
308
|
-
var FirstPartyMachineStateTypes = /* @__PURE__ */ function(FirstPartyMachineStateTypes2) {
|
|
314
|
+
var FirstPartyMachineStateTypes = /* @__PURE__ */ (function(FirstPartyMachineStateTypes2) {
|
|
309
315
|
FirstPartyMachineStateTypes2["sendAuthorizationChallengeRequest"] = "sendAuthorizationChallengeRequest";
|
|
310
316
|
FirstPartyMachineStateTypes2["sendAuthorizationResponse"] = "sendAuthorizationResponse";
|
|
311
317
|
FirstPartyMachineStateTypes2["selectCredentials"] = "selectCredentials";
|
|
@@ -316,21 +322,21 @@ var FirstPartyMachineStateTypes = /* @__PURE__ */ function(FirstPartyMachineStat
|
|
|
316
322
|
FirstPartyMachineStateTypes2["aborted"] = "aborted";
|
|
317
323
|
FirstPartyMachineStateTypes2["declined"] = "declined";
|
|
318
324
|
return FirstPartyMachineStateTypes2;
|
|
319
|
-
}({});
|
|
320
|
-
var FirstPartyMachineServices = /* @__PURE__ */ function(FirstPartyMachineServices2) {
|
|
325
|
+
})({});
|
|
326
|
+
var FirstPartyMachineServices = /* @__PURE__ */ (function(FirstPartyMachineServices2) {
|
|
321
327
|
FirstPartyMachineServices2["sendAuthorizationChallengeRequest"] = "sendAuthorizationChallengeRequest";
|
|
322
328
|
FirstPartyMachineServices2["sendAuthorizationResponse"] = "sendAuthorizationResponse";
|
|
323
329
|
FirstPartyMachineServices2["createConfig"] = "createConfig";
|
|
324
330
|
FirstPartyMachineServices2["getSiopRequest"] = "getSiopRequest";
|
|
325
331
|
return FirstPartyMachineServices2;
|
|
326
|
-
}({});
|
|
327
|
-
var FirstPartyMachineEvents = /* @__PURE__ */ function(FirstPartyMachineEvents2) {
|
|
332
|
+
})({});
|
|
333
|
+
var FirstPartyMachineEvents = /* @__PURE__ */ (function(FirstPartyMachineEvents2) {
|
|
328
334
|
FirstPartyMachineEvents2["NEXT"] = "NEXT";
|
|
329
335
|
FirstPartyMachineEvents2["PREVIOUS"] = "PREVIOUS";
|
|
330
336
|
FirstPartyMachineEvents2["DECLINE"] = "DECLINE";
|
|
331
337
|
FirstPartyMachineEvents2["SET_SELECTED_CREDENTIALS"] = "SET_SELECTED_CREDENTIALS";
|
|
332
338
|
return FirstPartyMachineEvents2;
|
|
333
|
-
}({});
|
|
339
|
+
})({});
|
|
334
340
|
|
|
335
341
|
// src/machines/oid4vciMachine.ts
|
|
336
342
|
var oid4vciHasNoContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
@@ -385,9 +391,7 @@ var oid4vciRequireAuthorizationGuard = /* @__PURE__ */ __name((ctx, _event) => {
|
|
|
385
391
|
if (!openID4VCIClientState) {
|
|
386
392
|
throw Error("Missing openID4VCI client state in context");
|
|
387
393
|
}
|
|
388
|
-
if (
|
|
389
|
-
return false;
|
|
390
|
-
} else if (openID4VCIClientState.authorizationRequestOpts) {
|
|
394
|
+
if (openID4VCIClientState.authorizationURL && openID4VCIClientState.authorizationRequestOpts) {
|
|
391
395
|
return !ctx.openID4VCIClientState?.authorizationCodeResponse;
|
|
392
396
|
} else if (openID4VCIClientState.credentialOffer?.supportedFlows?.includes(import_oid4vci_common.AuthzFlowType.AUTHORIZATION_CODE_FLOW)) {
|
|
393
397
|
return !ctx.openID4VCIClientState?.authorizationCodeResponse;
|
|
@@ -438,7 +442,6 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
|
|
|
438
442
|
onDone: {
|
|
439
443
|
target: OID4VCIMachineStates.createCredentialsToSelectFrom,
|
|
440
444
|
actions: (0, import_xstate.assign)({
|
|
441
|
-
authorizationCodeURL: /* @__PURE__ */ __name((_ctx, _event) => _event.data.authorizationCodeURL, "authorizationCodeURL"),
|
|
442
445
|
credentialBranding: /* @__PURE__ */ __name((_ctx, _event) => _event.data.credentialBranding ?? {}, "credentialBranding"),
|
|
443
446
|
credentialsSupported: /* @__PURE__ */ __name((_ctx, _event) => _event.data.credentialsSupported, "credentialsSupported"),
|
|
444
447
|
serverMetadata: /* @__PURE__ */ __name((_ctx, _event) => _event.data.serverMetadata, "serverMetadata"),
|
|
@@ -675,6 +678,10 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
|
|
|
675
678
|
target: OID4VCIMachineStates.startFirstPartApplicationFlow,
|
|
676
679
|
cond: OID4VCIMachineGuards.isFirstPartyApplication
|
|
677
680
|
},
|
|
681
|
+
{
|
|
682
|
+
target: OID4VCIMachineStates.prepareAuthorizationRequest,
|
|
683
|
+
cond: OID4VCIMachineGuards.requireAuthorizationGuard
|
|
684
|
+
},
|
|
678
685
|
{
|
|
679
686
|
target: OID4VCIMachineStates.initiateAuthorizationRequest,
|
|
680
687
|
cond: OID4VCIMachineGuards.requireAuthorizationGuard
|
|
@@ -750,12 +757,16 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
|
|
|
750
757
|
target: OID4VCIMachineStates.startFirstPartApplicationFlow,
|
|
751
758
|
cond: OID4VCIMachineGuards.isFirstPartyApplication
|
|
752
759
|
},
|
|
760
|
+
{
|
|
761
|
+
target: OID4VCIMachineStates.prepareAuthorizationRequest,
|
|
762
|
+
cond: OID4VCIMachineGuards.requireAuthorizationGuard
|
|
763
|
+
},
|
|
753
764
|
{
|
|
754
765
|
target: OID4VCIMachineStates.verifyPin,
|
|
755
766
|
cond: OID4VCIMachineGuards.requirePinGuard
|
|
756
767
|
},
|
|
757
768
|
{
|
|
758
|
-
target: OID4VCIMachineStates.
|
|
769
|
+
target: OID4VCIMachineStates.prepareAuthorizationRequest,
|
|
759
770
|
cond: OID4VCIMachineGuards.requireAuthorizationGuard
|
|
760
771
|
},
|
|
761
772
|
{
|
|
@@ -763,6 +774,29 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
|
|
|
763
774
|
}
|
|
764
775
|
]
|
|
765
776
|
},
|
|
777
|
+
[OID4VCIMachineStates.prepareAuthorizationRequest]: {
|
|
778
|
+
id: OID4VCIMachineStates.prepareAuthorizationRequest,
|
|
779
|
+
invoke: {
|
|
780
|
+
src: OID4VCIMachineServices.prepareAuthorizationRequest,
|
|
781
|
+
onDone: {
|
|
782
|
+
target: OID4VCIMachineStates.initiateAuthorizationRequest,
|
|
783
|
+
actions: (0, import_xstate.assign)({
|
|
784
|
+
authorizationCodeURL: /* @__PURE__ */ __name((_ctx, _event) => _event.data.authorizationCodeURL, "authorizationCodeURL"),
|
|
785
|
+
openID4VCIClientState: /* @__PURE__ */ __name((_ctx, _event) => _event.data.oid4vciClientState, "openID4VCIClientState")
|
|
786
|
+
})
|
|
787
|
+
},
|
|
788
|
+
onError: {
|
|
789
|
+
target: OID4VCIMachineStates.handleError,
|
|
790
|
+
actions: (0, import_xstate.assign)({
|
|
791
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
792
|
+
title: translate("oid4vci_machine_prepare_authorization_error_title"),
|
|
793
|
+
message: _event.data.message,
|
|
794
|
+
stack: _event.data.stack
|
|
795
|
+
}), "error")
|
|
796
|
+
})
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
},
|
|
766
800
|
[OID4VCIMachineStates.initiateAuthorizationRequest]: {
|
|
767
801
|
id: OID4VCIMachineStates.initiateAuthorizationRequest,
|
|
768
802
|
on: {
|
|
@@ -1060,214 +1094,405 @@ var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.did-resolver-jwk");
|
|
|
1060
1094
|
var import_ssi_sdk_ext2 = require("@sphereon/ssi-sdk-ext.did-utils");
|
|
1061
1095
|
var import_ssi_sdk_ext3 = require("@sphereon/ssi-sdk-ext.identifier-resolution");
|
|
1062
1096
|
var import_ssi_sdk_ext4 = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
1097
|
+
var import_ssi_sdk = require("@sphereon/ssi-sdk.core");
|
|
1063
1098
|
var import_ssi_types = require("@sphereon/ssi-types");
|
|
1064
1099
|
var import_utils = require("@veramo/utils");
|
|
1065
1100
|
|
|
1066
|
-
// src/
|
|
1067
|
-
var
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
credentialDisplay
|
|
1078
|
-
})
|
|
1079
|
-
}
|
|
1101
|
+
// src/machines/firstPartyMachine.ts
|
|
1102
|
+
var import_xstate2 = require("xstate");
|
|
1103
|
+
var import_oid4vci_common2 = require("@sphereon/oid4vci-common");
|
|
1104
|
+
|
|
1105
|
+
// src/services/FirstPartyMachineServices.ts
|
|
1106
|
+
var import_oid4vci_client = require("@sphereon/oid4vci-client");
|
|
1107
|
+
var import_uuid = require("uuid");
|
|
1108
|
+
var sendAuthorizationChallengeRequest = /* @__PURE__ */ __name(async (args) => {
|
|
1109
|
+
const { openID4VCIClientState, authSession, presentationDuringIssuanceSession } = args;
|
|
1110
|
+
const oid4vciClient = await import_oid4vci_client.OpenID4VCIClient.fromState({
|
|
1111
|
+
state: openID4VCIClientState
|
|
1080
1112
|
});
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
const localeKey = display.locale || "";
|
|
1086
|
-
localeDisplays.set(localeKey, display);
|
|
1087
|
-
return localeDisplays;
|
|
1088
|
-
}, /* @__PURE__ */ new Map());
|
|
1089
|
-
}, "oid4vciCredentialDisplayLocalesFrom");
|
|
1090
|
-
var oid4vciIssuerCredentialSubjectLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1091
|
-
const { issuerCredentialSubject } = args;
|
|
1092
|
-
const localeClaims = /* @__PURE__ */ new Map();
|
|
1093
|
-
const processClaimObject = /* @__PURE__ */ __name((claim, parentKey = "") => {
|
|
1094
|
-
Object.entries(claim).forEach(([key, value]) => {
|
|
1095
|
-
if (key === "mandatory" || key === "value_type") {
|
|
1096
|
-
return;
|
|
1097
|
-
}
|
|
1098
|
-
if (key === "display" && Array.isArray(value)) {
|
|
1099
|
-
value.forEach(({ name, locale = "" }) => {
|
|
1100
|
-
if (!name) {
|
|
1101
|
-
return;
|
|
1102
|
-
}
|
|
1103
|
-
if (!localeClaims.has(locale)) {
|
|
1104
|
-
localeClaims.set(locale, []);
|
|
1105
|
-
}
|
|
1106
|
-
localeClaims.get(locale).push({
|
|
1107
|
-
key: parentKey,
|
|
1108
|
-
name
|
|
1109
|
-
});
|
|
1110
|
-
});
|
|
1111
|
-
} else if (typeof value === "object" && value !== null) {
|
|
1112
|
-
processClaimObject(value, parentKey ? `${parentKey}.${key}` : key);
|
|
1113
|
-
}
|
|
1114
|
-
});
|
|
1115
|
-
}, "processClaimObject");
|
|
1116
|
-
processClaimObject(issuerCredentialSubject);
|
|
1117
|
-
return localeClaims;
|
|
1118
|
-
}, "oid4vciIssuerCredentialSubjectLocalesFrom");
|
|
1119
|
-
var oid4vciCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1120
|
-
const { credentialDisplay } = args;
|
|
1121
|
-
return {
|
|
1122
|
-
...credentialDisplay.name && {
|
|
1123
|
-
alias: credentialDisplay.name
|
|
1124
|
-
},
|
|
1125
|
-
...credentialDisplay.locale && {
|
|
1126
|
-
locale: credentialDisplay.locale
|
|
1127
|
-
},
|
|
1128
|
-
...credentialDisplay.logo && {
|
|
1129
|
-
logo: {
|
|
1130
|
-
...(credentialDisplay.logo.url || credentialDisplay.logo.uri) && {
|
|
1131
|
-
uri: credentialDisplay.logo?.url ?? credentialDisplay.logo.uri
|
|
1132
|
-
},
|
|
1133
|
-
...credentialDisplay.logo.alt_text && {
|
|
1134
|
-
alt: credentialDisplay.logo?.alt_text
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1113
|
+
return oid4vciClient.acquireAuthorizationChallengeCode({
|
|
1114
|
+
clientId: oid4vciClient.clientId ?? (0, import_uuid.v4)(),
|
|
1115
|
+
...authSession && {
|
|
1116
|
+
authSession
|
|
1137
1117
|
},
|
|
1138
|
-
|
|
1139
|
-
|
|
1118
|
+
...!authSession && openID4VCIClientState.credentialOffer?.preAuthorizedCode && {
|
|
1119
|
+
issuerState: openID4VCIClientState.credentialOffer?.preAuthorizedCode
|
|
1140
1120
|
},
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
color: credentialDisplay.text_color
|
|
1144
|
-
}
|
|
1121
|
+
...!authSession && openID4VCIClientState.credentialOffer?.issuerState && {
|
|
1122
|
+
issuerState: openID4VCIClientState.credentialOffer?.issuerState
|
|
1145
1123
|
},
|
|
1146
|
-
...
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1124
|
+
...presentationDuringIssuanceSession && {
|
|
1125
|
+
presentationDuringIssuanceSession
|
|
1126
|
+
}
|
|
1127
|
+
});
|
|
1128
|
+
}, "sendAuthorizationChallengeRequest");
|
|
1129
|
+
var createConfig = /* @__PURE__ */ __name(async (args, context) => {
|
|
1130
|
+
const { presentationUri } = args;
|
|
1131
|
+
if (!presentationUri) {
|
|
1132
|
+
return Promise.reject(Error("Missing presentation uri in context"));
|
|
1133
|
+
}
|
|
1134
|
+
return context.agent.siopCreateConfig({
|
|
1135
|
+
url: presentationUri
|
|
1136
|
+
});
|
|
1137
|
+
}, "createConfig");
|
|
1138
|
+
var getSiopRequest = /* @__PURE__ */ __name(async (args, context) => {
|
|
1139
|
+
const { didAuthConfig, presentationUri } = args;
|
|
1140
|
+
if (presentationUri === void 0) {
|
|
1141
|
+
return Promise.reject(Error("Missing presentation uri in context"));
|
|
1142
|
+
}
|
|
1143
|
+
if (didAuthConfig === void 0) {
|
|
1144
|
+
return Promise.reject(Error("Missing did auth config in context"));
|
|
1145
|
+
}
|
|
1146
|
+
return context.agent.siopGetSiopRequest({
|
|
1147
|
+
didAuthConfig,
|
|
1148
|
+
url: presentationUri
|
|
1149
|
+
});
|
|
1150
|
+
}, "getSiopRequest");
|
|
1151
|
+
var sendAuthorizationResponse = /* @__PURE__ */ __name(async (args, context) => {
|
|
1152
|
+
const { didAuthConfig, authorizationRequestData, selectedCredentials } = args;
|
|
1153
|
+
const responseData = await context.agent.siopSendResponse({
|
|
1154
|
+
authorizationRequestData,
|
|
1155
|
+
selectedCredentials,
|
|
1156
|
+
didAuthConfig,
|
|
1157
|
+
isFirstParty: true
|
|
1158
|
+
});
|
|
1159
|
+
return responseData.body.presentation_during_issuance_session;
|
|
1160
|
+
}, "sendAuthorizationResponse");
|
|
1161
|
+
|
|
1162
|
+
// src/machines/firstPartyMachine.ts
|
|
1163
|
+
var firstPartyMachineStates = {
|
|
1164
|
+
[FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest]: {
|
|
1165
|
+
id: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
|
|
1166
|
+
invoke: {
|
|
1167
|
+
src: FirstPartyMachineServices.sendAuthorizationChallengeRequest,
|
|
1168
|
+
onDone: {
|
|
1169
|
+
target: FirstPartyMachineStateTypes.done,
|
|
1170
|
+
actions: (0, import_xstate2.assign)({
|
|
1171
|
+
authorizationCodeResponse: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationCodeResponse")
|
|
1172
|
+
})
|
|
1173
|
+
},
|
|
1174
|
+
onError: [
|
|
1175
|
+
{
|
|
1176
|
+
target: FirstPartyMachineStateTypes.createConfig,
|
|
1177
|
+
cond: /* @__PURE__ */ __name((_ctx, _event) => _event.data.error === import_oid4vci_common2.AuthorizationChallengeError.insufficient_authorization, "cond"),
|
|
1178
|
+
actions: (0, import_xstate2.assign)({
|
|
1179
|
+
authSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data.auth_session, "authSession"),
|
|
1180
|
+
presentationUri: /* @__PURE__ */ __name((_ctx, _event) => _event.data.presentation, "presentationUri")
|
|
1181
|
+
})
|
|
1157
1182
|
},
|
|
1158
|
-
|
|
1159
|
-
|
|
1183
|
+
{
|
|
1184
|
+
target: FirstPartyMachineStateTypes.error,
|
|
1185
|
+
actions: (0, import_xstate2.assign)({
|
|
1186
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1187
|
+
title: translate("oid4vci_machine_send_authorization_challenge_request_error_title"),
|
|
1188
|
+
message: _event.data.message,
|
|
1189
|
+
stack: _event.data.stack
|
|
1190
|
+
}), "error")
|
|
1191
|
+
})
|
|
1160
1192
|
}
|
|
1193
|
+
]
|
|
1194
|
+
}
|
|
1195
|
+
},
|
|
1196
|
+
[FirstPartyMachineStateTypes.createConfig]: {
|
|
1197
|
+
id: FirstPartyMachineStateTypes.createConfig,
|
|
1198
|
+
invoke: {
|
|
1199
|
+
src: FirstPartyMachineServices.createConfig,
|
|
1200
|
+
onDone: {
|
|
1201
|
+
target: FirstPartyMachineStateTypes.getSiopRequest,
|
|
1202
|
+
actions: (0, import_xstate2.assign)({
|
|
1203
|
+
didAuthConfig: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "didAuthConfig")
|
|
1204
|
+
})
|
|
1205
|
+
},
|
|
1206
|
+
onError: {
|
|
1207
|
+
target: FirstPartyMachineStateTypes.error,
|
|
1208
|
+
actions: (0, import_xstate2.assign)({
|
|
1209
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1210
|
+
title: translate("oid4vci_machine_create_config_error_title"),
|
|
1211
|
+
message: _event.data.message,
|
|
1212
|
+
stack: _event.data.stack
|
|
1213
|
+
}), "error")
|
|
1214
|
+
})
|
|
1161
1215
|
}
|
|
1162
1216
|
}
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
const claims = issuerCredentialSubjectLocales.get(locale);
|
|
1174
|
-
return {
|
|
1175
|
-
...display && await oid4vciCredentialLocaleBrandingFrom({
|
|
1176
|
-
credentialDisplay: display
|
|
1177
|
-
}),
|
|
1178
|
-
...locale.length > 0 && {
|
|
1179
|
-
locale
|
|
1217
|
+
},
|
|
1218
|
+
[FirstPartyMachineStateTypes.getSiopRequest]: {
|
|
1219
|
+
id: FirstPartyMachineStateTypes.getSiopRequest,
|
|
1220
|
+
invoke: {
|
|
1221
|
+
src: FirstPartyMachineServices.getSiopRequest,
|
|
1222
|
+
onDone: {
|
|
1223
|
+
target: FirstPartyMachineStateTypes.selectCredentials,
|
|
1224
|
+
actions: (0, import_xstate2.assign)({
|
|
1225
|
+
authorizationRequestData: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationRequestData")
|
|
1226
|
+
})
|
|
1180
1227
|
},
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1228
|
+
onError: {
|
|
1229
|
+
target: FirstPartyMachineStateTypes.error,
|
|
1230
|
+
actions: (0, import_xstate2.assign)({
|
|
1231
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1232
|
+
title: translate("siopV2_machine_get_request_error_title"),
|
|
1233
|
+
message: _event.data.message,
|
|
1234
|
+
stack: _event.data.stack
|
|
1235
|
+
}), "error")
|
|
1236
|
+
})
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
},
|
|
1240
|
+
[FirstPartyMachineStateTypes.selectCredentials]: {
|
|
1241
|
+
id: FirstPartyMachineStateTypes.selectCredentials,
|
|
1242
|
+
on: {
|
|
1243
|
+
[FirstPartyMachineEvents.SET_SELECTED_CREDENTIALS]: {
|
|
1244
|
+
actions: (0, import_xstate2.assign)({
|
|
1245
|
+
selectedCredentials: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectedCredentials")
|
|
1246
|
+
})
|
|
1247
|
+
},
|
|
1248
|
+
[FirstPartyMachineEvents.NEXT]: {
|
|
1249
|
+
target: FirstPartyMachineStateTypes.sendAuthorizationResponse
|
|
1250
|
+
},
|
|
1251
|
+
[FirstPartyMachineEvents.DECLINE]: {
|
|
1252
|
+
target: FirstPartyMachineStateTypes.declined
|
|
1253
|
+
},
|
|
1254
|
+
[FirstPartyMachineEvents.PREVIOUS]: {
|
|
1255
|
+
target: FirstPartyMachineStateTypes.aborted
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
},
|
|
1259
|
+
[FirstPartyMachineStateTypes.sendAuthorizationResponse]: {
|
|
1260
|
+
id: FirstPartyMachineStateTypes.sendAuthorizationResponse,
|
|
1261
|
+
invoke: {
|
|
1262
|
+
src: FirstPartyMachineServices.sendAuthorizationResponse,
|
|
1263
|
+
onDone: {
|
|
1264
|
+
target: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
|
|
1265
|
+
actions: (0, import_xstate2.assign)({
|
|
1266
|
+
presentationDuringIssuanceSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "presentationDuringIssuanceSession")
|
|
1267
|
+
})
|
|
1268
|
+
},
|
|
1269
|
+
onError: {
|
|
1270
|
+
target: FirstPartyMachineStateTypes.error,
|
|
1271
|
+
actions: (0, import_xstate2.assign)({
|
|
1272
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1273
|
+
title: translate("oid4vci_machine_get_request_error_title"),
|
|
1274
|
+
message: _event.data.message,
|
|
1275
|
+
stack: _event.data.stack
|
|
1276
|
+
}), "error")
|
|
1277
|
+
})
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
},
|
|
1281
|
+
[FirstPartyMachineStateTypes.aborted]: {
|
|
1282
|
+
id: FirstPartyMachineStateTypes.aborted,
|
|
1283
|
+
type: "final"
|
|
1284
|
+
},
|
|
1285
|
+
[FirstPartyMachineStateTypes.declined]: {
|
|
1286
|
+
id: FirstPartyMachineStateTypes.declined,
|
|
1287
|
+
type: "final"
|
|
1288
|
+
},
|
|
1289
|
+
[FirstPartyMachineStateTypes.error]: {
|
|
1290
|
+
id: FirstPartyMachineStateTypes.error,
|
|
1291
|
+
type: "final"
|
|
1292
|
+
},
|
|
1293
|
+
[FirstPartyMachineStateTypes.done]: {
|
|
1294
|
+
id: FirstPartyMachineStateTypes.done,
|
|
1295
|
+
type: "final"
|
|
1296
|
+
}
|
|
1297
|
+
};
|
|
1298
|
+
var createFirstPartyActivationMachine = /* @__PURE__ */ __name((opts) => {
|
|
1299
|
+
const initialContext = {
|
|
1300
|
+
openID4VCIClientState: opts.openID4VCIClientState,
|
|
1301
|
+
contact: opts.contact,
|
|
1302
|
+
selectedCredentials: []
|
|
1303
|
+
};
|
|
1304
|
+
return (0, import_xstate2.createMachine)({
|
|
1305
|
+
id: opts?.machineId ?? "FirstParty",
|
|
1306
|
+
predictableActionArguments: true,
|
|
1307
|
+
initial: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
|
|
1308
|
+
context: initialContext,
|
|
1309
|
+
states: firstPartyMachineStates,
|
|
1310
|
+
schema: {
|
|
1311
|
+
events: {},
|
|
1312
|
+
services: {}
|
|
1313
|
+
}
|
|
1314
|
+
});
|
|
1315
|
+
}, "createFirstPartyActivationMachine");
|
|
1316
|
+
var FirstPartyMachine = class _FirstPartyMachine {
|
|
1317
|
+
static {
|
|
1318
|
+
__name(this, "FirstPartyMachine");
|
|
1319
|
+
}
|
|
1320
|
+
static _instance;
|
|
1321
|
+
static hasInstance() {
|
|
1322
|
+
return _FirstPartyMachine._instance !== void 0;
|
|
1323
|
+
}
|
|
1324
|
+
static get instance() {
|
|
1325
|
+
if (!_FirstPartyMachine._instance) {
|
|
1326
|
+
throw Error("Please initialize ESIMActivation machine first");
|
|
1327
|
+
}
|
|
1328
|
+
return _FirstPartyMachine._instance;
|
|
1329
|
+
}
|
|
1330
|
+
static clearInstance(opts) {
|
|
1331
|
+
const { stop } = opts;
|
|
1332
|
+
if (_FirstPartyMachine.hasInstance()) {
|
|
1333
|
+
if (stop) {
|
|
1334
|
+
_FirstPartyMachine.stopInstance();
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
_FirstPartyMachine._instance = void 0;
|
|
1338
|
+
}
|
|
1339
|
+
static stopInstance() {
|
|
1340
|
+
if (!_FirstPartyMachine.hasInstance()) {
|
|
1341
|
+
return;
|
|
1342
|
+
}
|
|
1343
|
+
_FirstPartyMachine.instance.stop();
|
|
1344
|
+
_FirstPartyMachine._instance = void 0;
|
|
1345
|
+
}
|
|
1346
|
+
static newInstance(opts) {
|
|
1347
|
+
const { agentContext } = opts;
|
|
1348
|
+
const services = {
|
|
1349
|
+
[FirstPartyMachineServices.sendAuthorizationChallengeRequest]: sendAuthorizationChallengeRequest,
|
|
1350
|
+
[FirstPartyMachineServices.createConfig]: (args) => createConfig(args, agentContext),
|
|
1351
|
+
[FirstPartyMachineServices.getSiopRequest]: (args) => getSiopRequest(args, agentContext),
|
|
1352
|
+
[FirstPartyMachineServices.sendAuthorizationResponse]: (args) => sendAuthorizationResponse(args, agentContext)
|
|
1353
|
+
};
|
|
1354
|
+
const newInst = (0, import_xstate2.interpret)(createFirstPartyActivationMachine(opts).withConfig({
|
|
1355
|
+
services: {
|
|
1356
|
+
...services,
|
|
1357
|
+
...opts?.services
|
|
1358
|
+
},
|
|
1359
|
+
guards: {
|
|
1360
|
+
...opts?.guards
|
|
1361
|
+
}
|
|
1362
|
+
}));
|
|
1363
|
+
if (typeof opts?.subscription === "function") {
|
|
1364
|
+
newInst.onTransition(opts.subscription);
|
|
1365
|
+
}
|
|
1366
|
+
if (opts?.requireCustomNavigationHook !== true) {
|
|
1367
|
+
newInst.onTransition((snapshot) => {
|
|
1368
|
+
if (opts?.stateNavigationListener) {
|
|
1369
|
+
void opts.stateNavigationListener(newInst, snapshot);
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
}
|
|
1373
|
+
return newInst;
|
|
1374
|
+
}
|
|
1375
|
+
static getInstance(opts) {
|
|
1376
|
+
if (!_FirstPartyMachine._instance) {
|
|
1377
|
+
if (opts?.requireExisting === true) {
|
|
1378
|
+
throw Error(`Existing FirstPartyMachine instance requested, but none was created at this point!`);
|
|
1379
|
+
}
|
|
1380
|
+
_FirstPartyMachine._instance = _FirstPartyMachine.newInstance(opts);
|
|
1381
|
+
}
|
|
1382
|
+
return _FirstPartyMachine._instance;
|
|
1383
|
+
}
|
|
1384
|
+
};
|
|
1385
|
+
|
|
1386
|
+
// src/mappers/OIDC4VCIBrandingMapper.ts
|
|
1387
|
+
var oid4vciGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1388
|
+
const { credentialDisplay, issuerCredentialSubject } = args;
|
|
1389
|
+
return oid4vciCombineDisplayLocalesFrom({
|
|
1390
|
+
...issuerCredentialSubject && {
|
|
1391
|
+
issuerCredentialSubjectLocales: await oid4vciIssuerCredentialSubjectLocalesFrom({
|
|
1392
|
+
issuerCredentialSubject
|
|
1191
1393
|
})
|
|
1192
1394
|
},
|
|
1193
1395
|
...credentialDisplay && {
|
|
1194
|
-
credentialDisplayLocales: await
|
|
1396
|
+
credentialDisplayLocales: await oid4vciCredentialDisplayLocalesFrom({
|
|
1195
1397
|
credentialDisplay
|
|
1196
1398
|
})
|
|
1197
1399
|
}
|
|
1198
1400
|
});
|
|
1199
|
-
}, "
|
|
1200
|
-
var
|
|
1401
|
+
}, "oid4vciGetCredentialBrandingFrom");
|
|
1402
|
+
var oid4vciCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1201
1403
|
const { credentialDisplay } = args;
|
|
1202
1404
|
return credentialDisplay.reduce((localeDisplays, display) => {
|
|
1203
|
-
const localeKey = display.
|
|
1405
|
+
const localeKey = display.locale || "";
|
|
1204
1406
|
localeDisplays.set(localeKey, display);
|
|
1205
1407
|
return localeDisplays;
|
|
1206
1408
|
}, /* @__PURE__ */ new Map());
|
|
1207
|
-
}, "
|
|
1208
|
-
var
|
|
1209
|
-
const {
|
|
1409
|
+
}, "oid4vciCredentialDisplayLocalesFrom");
|
|
1410
|
+
var oid4vciIssuerCredentialSubjectLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1411
|
+
const { issuerCredentialSubject } = args;
|
|
1210
1412
|
const localeClaims = /* @__PURE__ */ new Map();
|
|
1211
|
-
|
|
1212
|
-
claim.
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1413
|
+
const processClaimObject = /* @__PURE__ */ __name((claim, parentKey = "") => {
|
|
1414
|
+
Object.entries(claim).forEach(([key, value]) => {
|
|
1415
|
+
if (key === "mandatory" || key === "value_type") {
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
if (key === "display" && Array.isArray(value)) {
|
|
1419
|
+
value.forEach(({ name, locale = "" }) => {
|
|
1420
|
+
if (!name) {
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
if (!localeClaims.has(locale)) {
|
|
1424
|
+
localeClaims.set(locale, []);
|
|
1425
|
+
}
|
|
1426
|
+
localeClaims.get(locale).push({
|
|
1427
|
+
key: parentKey,
|
|
1428
|
+
name
|
|
1429
|
+
});
|
|
1430
|
+
});
|
|
1431
|
+
} else if (typeof value === "object" && value !== null) {
|
|
1432
|
+
processClaimObject(value, parentKey ? `${parentKey}.${key}` : key);
|
|
1217
1433
|
}
|
|
1218
|
-
localeClaims.get(lang).push({
|
|
1219
|
-
key,
|
|
1220
|
-
name: label
|
|
1221
|
-
});
|
|
1222
1434
|
});
|
|
1223
|
-
});
|
|
1435
|
+
}, "processClaimObject");
|
|
1436
|
+
processClaimObject(issuerCredentialSubject);
|
|
1224
1437
|
return localeClaims;
|
|
1225
|
-
}, "
|
|
1226
|
-
var
|
|
1438
|
+
}, "oid4vciIssuerCredentialSubjectLocalesFrom");
|
|
1439
|
+
var oid4vciCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1227
1440
|
const { credentialDisplay } = args;
|
|
1228
1441
|
return {
|
|
1229
1442
|
...credentialDisplay.name && {
|
|
1230
1443
|
alias: credentialDisplay.name
|
|
1231
1444
|
},
|
|
1232
|
-
...credentialDisplay.
|
|
1233
|
-
locale: credentialDisplay.
|
|
1445
|
+
...credentialDisplay.locale && {
|
|
1446
|
+
locale: credentialDisplay.locale
|
|
1234
1447
|
},
|
|
1235
|
-
...credentialDisplay.
|
|
1448
|
+
...credentialDisplay.logo && {
|
|
1236
1449
|
logo: {
|
|
1237
|
-
...credentialDisplay.
|
|
1238
|
-
uri: credentialDisplay.
|
|
1450
|
+
...(credentialDisplay.logo.url || credentialDisplay.logo.uri) && {
|
|
1451
|
+
uri: credentialDisplay.logo?.url ?? credentialDisplay.logo.uri
|
|
1239
1452
|
},
|
|
1240
|
-
...credentialDisplay.
|
|
1241
|
-
alt: credentialDisplay.
|
|
1453
|
+
...credentialDisplay.logo.alt_text && {
|
|
1454
|
+
alt: credentialDisplay.logo?.alt_text
|
|
1242
1455
|
}
|
|
1243
1456
|
}
|
|
1244
1457
|
},
|
|
1245
1458
|
...credentialDisplay.description && {
|
|
1246
1459
|
description: credentialDisplay.description
|
|
1247
1460
|
},
|
|
1248
|
-
...credentialDisplay.
|
|
1461
|
+
...credentialDisplay.text_color && {
|
|
1249
1462
|
text: {
|
|
1250
|
-
color: credentialDisplay.
|
|
1463
|
+
color: credentialDisplay.text_color
|
|
1251
1464
|
}
|
|
1252
1465
|
},
|
|
1253
|
-
...credentialDisplay.
|
|
1466
|
+
...(credentialDisplay.background_image || credentialDisplay.background_color) && {
|
|
1254
1467
|
background: {
|
|
1255
|
-
|
|
1468
|
+
...credentialDisplay.background_image && {
|
|
1469
|
+
image: {
|
|
1470
|
+
...(credentialDisplay.background_image.url || credentialDisplay.background_image.uri) && {
|
|
1471
|
+
uri: credentialDisplay.background_image?.url ?? credentialDisplay.background_image.uri
|
|
1472
|
+
},
|
|
1473
|
+
...credentialDisplay.background_image.alt_text && {
|
|
1474
|
+
alt: credentialDisplay.background_image?.alt_text
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
},
|
|
1478
|
+
...credentialDisplay.background_color && {
|
|
1479
|
+
color: credentialDisplay.background_color
|
|
1480
|
+
}
|
|
1256
1481
|
}
|
|
1257
1482
|
}
|
|
1258
1483
|
};
|
|
1259
|
-
}, "
|
|
1260
|
-
var
|
|
1261
|
-
const { credentialDisplayLocales = /* @__PURE__ */ new Map(),
|
|
1484
|
+
}, "oid4vciCredentialLocaleBrandingFrom");
|
|
1485
|
+
var oid4vciCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1486
|
+
const { credentialDisplayLocales = /* @__PURE__ */ new Map(), issuerCredentialSubjectLocales = /* @__PURE__ */ new Map() } = args;
|
|
1262
1487
|
const locales = Array.from(/* @__PURE__ */ new Set([
|
|
1263
|
-
...
|
|
1488
|
+
...issuerCredentialSubjectLocales.keys(),
|
|
1264
1489
|
...credentialDisplayLocales.keys()
|
|
1265
1490
|
]));
|
|
1266
1491
|
return Promise.all(locales.map(async (locale) => {
|
|
1267
1492
|
const display = credentialDisplayLocales.get(locale);
|
|
1268
|
-
const claims =
|
|
1493
|
+
const claims = issuerCredentialSubjectLocales.get(locale);
|
|
1269
1494
|
return {
|
|
1270
|
-
...display && await
|
|
1495
|
+
...display && await oid4vciCredentialLocaleBrandingFrom({
|
|
1271
1496
|
credentialDisplay: display
|
|
1272
1497
|
}),
|
|
1273
1498
|
...locale.length > 0 && {
|
|
@@ -1276,348 +1501,157 @@ var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
|
1276
1501
|
claims
|
|
1277
1502
|
};
|
|
1278
1503
|
}));
|
|
1279
|
-
}, "
|
|
1280
|
-
var
|
|
1281
|
-
const {
|
|
1282
|
-
return {
|
|
1283
|
-
...
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
alias: issuerDisplay.name
|
|
1288
|
-
},
|
|
1289
|
-
...issuerDisplay.locale && {
|
|
1290
|
-
locale: issuerDisplay.locale
|
|
1291
|
-
},
|
|
1292
|
-
...(issuerDisplay.logo || dynamicRegistrationClientMetadata?.logo_uri) && {
|
|
1293
|
-
logo: {
|
|
1294
|
-
...dynamicRegistrationClientMetadata?.logo_uri && {
|
|
1295
|
-
uri: dynamicRegistrationClientMetadata?.logo_uri
|
|
1296
|
-
},
|
|
1297
|
-
...(issuerDisplay.logo?.url || issuerDisplay.logo?.uri) && {
|
|
1298
|
-
uri: issuerDisplay.logo?.url ?? issuerDisplay.logo?.uri
|
|
1299
|
-
},
|
|
1300
|
-
...issuerDisplay.logo?.alt_text && {
|
|
1301
|
-
alt: issuerDisplay.logo?.alt_text
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
},
|
|
1305
|
-
...issuerDisplay.description && {
|
|
1306
|
-
description: issuerDisplay.description
|
|
1307
|
-
},
|
|
1308
|
-
...issuerDisplay.text_color && {
|
|
1309
|
-
text: {
|
|
1310
|
-
color: issuerDisplay.text_color
|
|
1311
|
-
}
|
|
1312
|
-
},
|
|
1313
|
-
...dynamicRegistrationClientMetadata?.client_uri && {
|
|
1314
|
-
clientUri: dynamicRegistrationClientMetadata.client_uri
|
|
1315
|
-
},
|
|
1316
|
-
...dynamicRegistrationClientMetadata?.tos_uri && {
|
|
1317
|
-
tosUri: dynamicRegistrationClientMetadata.tos_uri
|
|
1318
|
-
},
|
|
1319
|
-
...dynamicRegistrationClientMetadata?.policy_uri && {
|
|
1320
|
-
policyUri: dynamicRegistrationClientMetadata.policy_uri
|
|
1504
|
+
}, "oid4vciCombineDisplayLocalesFrom");
|
|
1505
|
+
var sdJwtGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1506
|
+
const { credentialDisplay, claimsMetadata } = args;
|
|
1507
|
+
return sdJwtCombineDisplayLocalesFrom({
|
|
1508
|
+
...claimsMetadata && {
|
|
1509
|
+
claimsMetadata: await sdJwtCredentialClaimLocalesFrom({
|
|
1510
|
+
claimsMetadata
|
|
1511
|
+
})
|
|
1321
1512
|
},
|
|
1322
|
-
...
|
|
1323
|
-
|
|
1513
|
+
...credentialDisplay && {
|
|
1514
|
+
credentialDisplayLocales: await sdJwtCredentialDisplayLocalesFrom({
|
|
1515
|
+
credentialDisplay
|
|
1516
|
+
})
|
|
1324
1517
|
}
|
|
1325
|
-
};
|
|
1326
|
-
}, "issuerLocaleBrandingFrom");
|
|
1327
|
-
|
|
1328
|
-
// src/machines/firstPartyMachine.ts
|
|
1329
|
-
var import_xstate2 = require("xstate");
|
|
1330
|
-
var import_oid4vci_common2 = require("@sphereon/oid4vci-common");
|
|
1331
|
-
|
|
1332
|
-
// src/services/FirstPartyMachineServices.ts
|
|
1333
|
-
var import_oid4vci_client = require("@sphereon/oid4vci-client");
|
|
1334
|
-
var import_uuid = require("uuid");
|
|
1335
|
-
var sendAuthorizationChallengeRequest = /* @__PURE__ */ __name(async (args) => {
|
|
1336
|
-
const { openID4VCIClientState, authSession, presentationDuringIssuanceSession } = args;
|
|
1337
|
-
const oid4vciClient = await import_oid4vci_client.OpenID4VCIClient.fromState({
|
|
1338
|
-
state: openID4VCIClientState
|
|
1339
1518
|
});
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1519
|
+
}, "sdJwtGetCredentialBrandingFrom");
|
|
1520
|
+
var sdJwtCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1521
|
+
const { credentialDisplay } = args;
|
|
1522
|
+
return credentialDisplay.reduce((localeDisplays, display) => {
|
|
1523
|
+
const localeKey = display.lang || "";
|
|
1524
|
+
localeDisplays.set(localeKey, display);
|
|
1525
|
+
return localeDisplays;
|
|
1526
|
+
}, /* @__PURE__ */ new Map());
|
|
1527
|
+
}, "sdJwtCredentialDisplayLocalesFrom");
|
|
1528
|
+
var sdJwtCredentialClaimLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1529
|
+
const { claimsMetadata } = args;
|
|
1530
|
+
const localeClaims = /* @__PURE__ */ new Map();
|
|
1531
|
+
claimsMetadata.forEach((claim) => {
|
|
1532
|
+
claim.display?.forEach((display) => {
|
|
1533
|
+
const { lang = "", label } = display;
|
|
1534
|
+
const key = claim.path.map((value) => String(value)).join(".");
|
|
1535
|
+
if (!localeClaims.has(lang)) {
|
|
1536
|
+
localeClaims.set(lang, []);
|
|
1537
|
+
}
|
|
1538
|
+
localeClaims.get(lang).push({
|
|
1539
|
+
key,
|
|
1540
|
+
name: label
|
|
1541
|
+
});
|
|
1542
|
+
});
|
|
1543
|
+
});
|
|
1544
|
+
return localeClaims;
|
|
1545
|
+
}, "sdJwtCredentialClaimLocalesFrom");
|
|
1546
|
+
var sdJwtCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1547
|
+
const { credentialDisplay } = args;
|
|
1548
|
+
return {
|
|
1549
|
+
...credentialDisplay.name && {
|
|
1550
|
+
alias: credentialDisplay.name
|
|
1347
1551
|
},
|
|
1348
|
-
|
|
1349
|
-
|
|
1552
|
+
...credentialDisplay.lang && {
|
|
1553
|
+
locale: credentialDisplay.lang
|
|
1350
1554
|
},
|
|
1351
|
-
...
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
}, "sendAuthorizationChallengeRequest");
|
|
1356
|
-
var createConfig = /* @__PURE__ */ __name(async (args, context) => {
|
|
1357
|
-
const { presentationUri } = args;
|
|
1358
|
-
if (!presentationUri) {
|
|
1359
|
-
return Promise.reject(Error("Missing presentation uri in context"));
|
|
1360
|
-
}
|
|
1361
|
-
return context.agent.siopCreateConfig({
|
|
1362
|
-
url: presentationUri
|
|
1363
|
-
});
|
|
1364
|
-
}, "createConfig");
|
|
1365
|
-
var getSiopRequest = /* @__PURE__ */ __name(async (args, context) => {
|
|
1366
|
-
const { didAuthConfig, presentationUri } = args;
|
|
1367
|
-
if (presentationUri === void 0) {
|
|
1368
|
-
return Promise.reject(Error("Missing presentation uri in context"));
|
|
1369
|
-
}
|
|
1370
|
-
if (didAuthConfig === void 0) {
|
|
1371
|
-
return Promise.reject(Error("Missing did auth config in context"));
|
|
1372
|
-
}
|
|
1373
|
-
return context.agent.siopGetSiopRequest({
|
|
1374
|
-
didAuthConfig,
|
|
1375
|
-
url: presentationUri
|
|
1376
|
-
});
|
|
1377
|
-
}, "getSiopRequest");
|
|
1378
|
-
var sendAuthorizationResponse = /* @__PURE__ */ __name(async (args, context) => {
|
|
1379
|
-
const { didAuthConfig, authorizationRequestData, selectedCredentials } = args;
|
|
1380
|
-
const responseData = await context.agent.siopSendResponse({
|
|
1381
|
-
authorizationRequestData,
|
|
1382
|
-
selectedCredentials,
|
|
1383
|
-
didAuthConfig,
|
|
1384
|
-
isFirstParty: true
|
|
1385
|
-
});
|
|
1386
|
-
return responseData.body.presentation_during_issuance_session;
|
|
1387
|
-
}, "sendAuthorizationResponse");
|
|
1388
|
-
|
|
1389
|
-
// src/machines/firstPartyMachine.ts
|
|
1390
|
-
var firstPartyMachineStates = {
|
|
1391
|
-
[FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest]: {
|
|
1392
|
-
id: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
|
|
1393
|
-
invoke: {
|
|
1394
|
-
src: FirstPartyMachineServices.sendAuthorizationChallengeRequest,
|
|
1395
|
-
onDone: {
|
|
1396
|
-
target: FirstPartyMachineStateTypes.done,
|
|
1397
|
-
actions: (0, import_xstate2.assign)({
|
|
1398
|
-
authorizationCodeResponse: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationCodeResponse")
|
|
1399
|
-
})
|
|
1400
|
-
},
|
|
1401
|
-
onError: [
|
|
1402
|
-
{
|
|
1403
|
-
target: FirstPartyMachineStateTypes.createConfig,
|
|
1404
|
-
cond: /* @__PURE__ */ __name((_ctx, _event) => _event.data.error === import_oid4vci_common2.AuthorizationChallengeError.insufficient_authorization, "cond"),
|
|
1405
|
-
actions: (0, import_xstate2.assign)({
|
|
1406
|
-
authSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data.auth_session, "authSession"),
|
|
1407
|
-
presentationUri: /* @__PURE__ */ __name((_ctx, _event) => _event.data.presentation, "presentationUri")
|
|
1408
|
-
})
|
|
1555
|
+
...credentialDisplay.rendering?.simple?.logo && {
|
|
1556
|
+
logo: {
|
|
1557
|
+
...credentialDisplay.rendering.simple.logo.uri && {
|
|
1558
|
+
uri: credentialDisplay.rendering.simple.logo.uri
|
|
1409
1559
|
},
|
|
1410
|
-
{
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1414
|
-
title: translate("oid4vci_machine_send_authorization_challenge_request_error_title"),
|
|
1415
|
-
message: _event.data.message,
|
|
1416
|
-
stack: _event.data.stack
|
|
1417
|
-
}), "error")
|
|
1418
|
-
})
|
|
1419
|
-
}
|
|
1420
|
-
]
|
|
1421
|
-
}
|
|
1422
|
-
},
|
|
1423
|
-
[FirstPartyMachineStateTypes.createConfig]: {
|
|
1424
|
-
id: FirstPartyMachineStateTypes.createConfig,
|
|
1425
|
-
invoke: {
|
|
1426
|
-
src: FirstPartyMachineServices.createConfig,
|
|
1427
|
-
onDone: {
|
|
1428
|
-
target: FirstPartyMachineStateTypes.getSiopRequest,
|
|
1429
|
-
actions: (0, import_xstate2.assign)({
|
|
1430
|
-
didAuthConfig: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "didAuthConfig")
|
|
1431
|
-
})
|
|
1432
|
-
},
|
|
1433
|
-
onError: {
|
|
1434
|
-
target: FirstPartyMachineStateTypes.error,
|
|
1435
|
-
actions: (0, import_xstate2.assign)({
|
|
1436
|
-
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1437
|
-
title: translate("oid4vci_machine_create_config_error_title"),
|
|
1438
|
-
message: _event.data.message,
|
|
1439
|
-
stack: _event.data.stack
|
|
1440
|
-
}), "error")
|
|
1441
|
-
})
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
},
|
|
1445
|
-
[FirstPartyMachineStateTypes.getSiopRequest]: {
|
|
1446
|
-
id: FirstPartyMachineStateTypes.getSiopRequest,
|
|
1447
|
-
invoke: {
|
|
1448
|
-
src: FirstPartyMachineServices.getSiopRequest,
|
|
1449
|
-
onDone: {
|
|
1450
|
-
target: FirstPartyMachineStateTypes.selectCredentials,
|
|
1451
|
-
actions: (0, import_xstate2.assign)({
|
|
1452
|
-
authorizationRequestData: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationRequestData")
|
|
1453
|
-
})
|
|
1454
|
-
},
|
|
1455
|
-
onError: {
|
|
1456
|
-
target: FirstPartyMachineStateTypes.error,
|
|
1457
|
-
actions: (0, import_xstate2.assign)({
|
|
1458
|
-
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1459
|
-
title: translate("siopV2_machine_get_request_error_title"),
|
|
1460
|
-
message: _event.data.message,
|
|
1461
|
-
stack: _event.data.stack
|
|
1462
|
-
}), "error")
|
|
1463
|
-
})
|
|
1560
|
+
...credentialDisplay.rendering.simple.logo.alt_text && {
|
|
1561
|
+
alt: credentialDisplay.rendering.simple.logo.alt_text
|
|
1562
|
+
}
|
|
1464
1563
|
}
|
|
1465
|
-
}
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
selectedCredentials: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectedCredentials")
|
|
1473
|
-
})
|
|
1474
|
-
},
|
|
1475
|
-
[FirstPartyMachineEvents.NEXT]: {
|
|
1476
|
-
target: FirstPartyMachineStateTypes.sendAuthorizationResponse
|
|
1477
|
-
},
|
|
1478
|
-
[FirstPartyMachineEvents.DECLINE]: {
|
|
1479
|
-
target: FirstPartyMachineStateTypes.declined
|
|
1480
|
-
},
|
|
1481
|
-
[FirstPartyMachineEvents.PREVIOUS]: {
|
|
1482
|
-
target: FirstPartyMachineStateTypes.aborted
|
|
1564
|
+
},
|
|
1565
|
+
...credentialDisplay.description && {
|
|
1566
|
+
description: credentialDisplay.description
|
|
1567
|
+
},
|
|
1568
|
+
...credentialDisplay.rendering?.simple?.text_color && {
|
|
1569
|
+
text: {
|
|
1570
|
+
color: credentialDisplay.rendering.simple.text_color
|
|
1483
1571
|
}
|
|
1484
|
-
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
invoke: {
|
|
1489
|
-
src: FirstPartyMachineServices.sendAuthorizationResponse,
|
|
1490
|
-
onDone: {
|
|
1491
|
-
target: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
|
|
1492
|
-
actions: (0, import_xstate2.assign)({
|
|
1493
|
-
presentationDuringIssuanceSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "presentationDuringIssuanceSession")
|
|
1494
|
-
})
|
|
1495
|
-
},
|
|
1496
|
-
onError: {
|
|
1497
|
-
target: FirstPartyMachineStateTypes.error,
|
|
1498
|
-
actions: (0, import_xstate2.assign)({
|
|
1499
|
-
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1500
|
-
title: translate("oid4vci_machine_get_request_error_title"),
|
|
1501
|
-
message: _event.data.message,
|
|
1502
|
-
stack: _event.data.stack
|
|
1503
|
-
}), "error")
|
|
1504
|
-
})
|
|
1572
|
+
},
|
|
1573
|
+
...credentialDisplay.rendering?.simple?.background_color && {
|
|
1574
|
+
background: {
|
|
1575
|
+
color: credentialDisplay.rendering.simple.background_color
|
|
1505
1576
|
}
|
|
1506
1577
|
}
|
|
1507
|
-
},
|
|
1508
|
-
[FirstPartyMachineStateTypes.aborted]: {
|
|
1509
|
-
id: FirstPartyMachineStateTypes.aborted,
|
|
1510
|
-
type: "final"
|
|
1511
|
-
},
|
|
1512
|
-
[FirstPartyMachineStateTypes.declined]: {
|
|
1513
|
-
id: FirstPartyMachineStateTypes.declined,
|
|
1514
|
-
type: "final"
|
|
1515
|
-
},
|
|
1516
|
-
[FirstPartyMachineStateTypes.error]: {
|
|
1517
|
-
id: FirstPartyMachineStateTypes.error,
|
|
1518
|
-
type: "final"
|
|
1519
|
-
},
|
|
1520
|
-
[FirstPartyMachineStateTypes.done]: {
|
|
1521
|
-
id: FirstPartyMachineStateTypes.done,
|
|
1522
|
-
type: "final"
|
|
1523
|
-
}
|
|
1524
|
-
};
|
|
1525
|
-
var createFirstPartyActivationMachine = /* @__PURE__ */ __name((opts) => {
|
|
1526
|
-
const initialContext = {
|
|
1527
|
-
openID4VCIClientState: opts.openID4VCIClientState,
|
|
1528
|
-
contact: opts.contact,
|
|
1529
|
-
selectedCredentials: []
|
|
1530
1578
|
};
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
static _instance;
|
|
1548
|
-
static hasInstance() {
|
|
1549
|
-
return _FirstPartyMachine._instance !== void 0;
|
|
1550
|
-
}
|
|
1551
|
-
static get instance() {
|
|
1552
|
-
if (!_FirstPartyMachine._instance) {
|
|
1553
|
-
throw Error("Please initialize ESIMActivation machine first");
|
|
1554
|
-
}
|
|
1555
|
-
return _FirstPartyMachine._instance;
|
|
1556
|
-
}
|
|
1557
|
-
static clearInstance(opts) {
|
|
1558
|
-
const { stop } = opts;
|
|
1559
|
-
if (_FirstPartyMachine.hasInstance()) {
|
|
1560
|
-
if (stop) {
|
|
1561
|
-
_FirstPartyMachine.stopInstance();
|
|
1562
|
-
}
|
|
1563
|
-
}
|
|
1564
|
-
_FirstPartyMachine._instance = void 0;
|
|
1565
|
-
}
|
|
1566
|
-
static stopInstance() {
|
|
1567
|
-
if (!_FirstPartyMachine.hasInstance()) {
|
|
1568
|
-
return;
|
|
1569
|
-
}
|
|
1570
|
-
_FirstPartyMachine.instance.stop();
|
|
1571
|
-
_FirstPartyMachine._instance = void 0;
|
|
1572
|
-
}
|
|
1573
|
-
static newInstance(opts) {
|
|
1574
|
-
const { agentContext } = opts;
|
|
1575
|
-
const services = {
|
|
1576
|
-
[FirstPartyMachineServices.sendAuthorizationChallengeRequest]: sendAuthorizationChallengeRequest,
|
|
1577
|
-
[FirstPartyMachineServices.createConfig]: (args) => createConfig(args, agentContext),
|
|
1578
|
-
[FirstPartyMachineServices.getSiopRequest]: (args) => getSiopRequest(args, agentContext),
|
|
1579
|
-
[FirstPartyMachineServices.sendAuthorizationResponse]: (args) => sendAuthorizationResponse(args, agentContext)
|
|
1580
|
-
};
|
|
1581
|
-
const newInst = (0, import_xstate2.interpret)(createFirstPartyActivationMachine(opts).withConfig({
|
|
1582
|
-
services: {
|
|
1583
|
-
...services,
|
|
1584
|
-
...opts?.services
|
|
1579
|
+
}, "sdJwtCredentialLocaleBrandingFrom");
|
|
1580
|
+
var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1581
|
+
const { credentialDisplayLocales = /* @__PURE__ */ new Map(), claimsMetadata = /* @__PURE__ */ new Map() } = args;
|
|
1582
|
+
const locales = Array.from(/* @__PURE__ */ new Set([
|
|
1583
|
+
...claimsMetadata.keys(),
|
|
1584
|
+
...credentialDisplayLocales.keys()
|
|
1585
|
+
]));
|
|
1586
|
+
return Promise.all(locales.map(async (locale) => {
|
|
1587
|
+
const display = credentialDisplayLocales.get(locale);
|
|
1588
|
+
const claims = claimsMetadata.get(locale);
|
|
1589
|
+
return {
|
|
1590
|
+
...display && await sdJwtCredentialLocaleBrandingFrom({
|
|
1591
|
+
credentialDisplay: display
|
|
1592
|
+
}),
|
|
1593
|
+
...locale.length > 0 && {
|
|
1594
|
+
locale
|
|
1585
1595
|
},
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1596
|
+
claims
|
|
1597
|
+
};
|
|
1598
|
+
}));
|
|
1599
|
+
}, "sdJwtCombineDisplayLocalesFrom");
|
|
1600
|
+
var issuerLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1601
|
+
const { issuerDisplay, dynamicRegistrationClientMetadata } = args;
|
|
1602
|
+
return {
|
|
1603
|
+
...dynamicRegistrationClientMetadata?.client_name && {
|
|
1604
|
+
alias: dynamicRegistrationClientMetadata.client_name
|
|
1605
|
+
},
|
|
1606
|
+
...issuerDisplay.name && {
|
|
1607
|
+
alias: issuerDisplay.name
|
|
1608
|
+
},
|
|
1609
|
+
...issuerDisplay.locale && {
|
|
1610
|
+
locale: issuerDisplay.locale
|
|
1611
|
+
},
|
|
1612
|
+
...(issuerDisplay.logo || dynamicRegistrationClientMetadata?.logo_uri) && {
|
|
1613
|
+
logo: {
|
|
1614
|
+
...dynamicRegistrationClientMetadata?.logo_uri && {
|
|
1615
|
+
uri: dynamicRegistrationClientMetadata?.logo_uri
|
|
1616
|
+
},
|
|
1617
|
+
...(issuerDisplay.logo?.url || issuerDisplay.logo?.uri) && {
|
|
1618
|
+
uri: issuerDisplay.logo?.url ?? issuerDisplay.logo?.uri
|
|
1619
|
+
},
|
|
1620
|
+
...issuerDisplay.logo?.alt_text && {
|
|
1621
|
+
alt: issuerDisplay.logo?.alt_text
|
|
1597
1622
|
}
|
|
1598
|
-
});
|
|
1599
|
-
}
|
|
1600
|
-
return newInst;
|
|
1601
|
-
}
|
|
1602
|
-
static getInstance(opts) {
|
|
1603
|
-
if (!_FirstPartyMachine._instance) {
|
|
1604
|
-
if (opts?.requireExisting === true) {
|
|
1605
|
-
throw Error(`Existing FirstPartyMachine instance requested, but none was created at this point!`);
|
|
1606
1623
|
}
|
|
1607
|
-
|
|
1624
|
+
},
|
|
1625
|
+
...issuerDisplay.description && {
|
|
1626
|
+
description: issuerDisplay.description
|
|
1627
|
+
},
|
|
1628
|
+
...issuerDisplay.text_color && {
|
|
1629
|
+
text: {
|
|
1630
|
+
color: issuerDisplay.text_color
|
|
1631
|
+
}
|
|
1632
|
+
},
|
|
1633
|
+
...dynamicRegistrationClientMetadata?.client_uri && {
|
|
1634
|
+
clientUri: dynamicRegistrationClientMetadata.client_uri
|
|
1635
|
+
},
|
|
1636
|
+
...dynamicRegistrationClientMetadata?.tos_uri && {
|
|
1637
|
+
tosUri: dynamicRegistrationClientMetadata.tos_uri
|
|
1638
|
+
},
|
|
1639
|
+
...dynamicRegistrationClientMetadata?.policy_uri && {
|
|
1640
|
+
policyUri: dynamicRegistrationClientMetadata.policy_uri
|
|
1641
|
+
},
|
|
1642
|
+
...dynamicRegistrationClientMetadata?.contacts && {
|
|
1643
|
+
contacts: dynamicRegistrationClientMetadata.contacts
|
|
1608
1644
|
}
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
};
|
|
1645
|
+
};
|
|
1646
|
+
}, "issuerLocaleBrandingFrom");
|
|
1612
1647
|
|
|
1613
1648
|
// src/services/OID4VCIHolderService.ts
|
|
1614
|
-
var import_ssi_sdk = require("@sphereon/ssi-sdk.core");
|
|
1615
1649
|
var getCredentialBranding = /* @__PURE__ */ __name(async (args) => {
|
|
1616
1650
|
const { credentialsSupported, context } = args;
|
|
1617
1651
|
const credentialBranding = {};
|
|
1618
1652
|
await Promise.all(Object.entries(credentialsSupported).map(async ([configId, credentialsConfigSupported]) => {
|
|
1619
1653
|
let sdJwtTypeMetadata;
|
|
1620
|
-
if (credentialsConfigSupported.format === "
|
|
1654
|
+
if (credentialsConfigSupported.format === "dc+sd-jwt") {
|
|
1621
1655
|
const vct = credentialsConfigSupported.vct;
|
|
1622
1656
|
if (vct.startsWith("http")) {
|
|
1623
1657
|
try {
|
|
@@ -1683,10 +1717,7 @@ var selectCredentialLocaleBranding = /* @__PURE__ */ __name(async (args) => {
|
|
|
1683
1717
|
}, "selectCredentialLocaleBranding");
|
|
1684
1718
|
var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
1685
1719
|
const { mappedCredential, hasher, onVerifyEBSICredentialIssuer, schemaValidation, context } = args;
|
|
1686
|
-
const credential = mappedCredential.credentialToAccept.credentialResponse
|
|
1687
|
-
if (!credential) {
|
|
1688
|
-
return Promise.reject(Error("No credential found in credential response"));
|
|
1689
|
-
}
|
|
1720
|
+
const credential = extractCredentialFromResponse(mappedCredential.credentialToAccept.credentialResponse);
|
|
1690
1721
|
const wrappedVC = import_ssi_types.CredentialMapper.toWrappedVerifiableCredential(credential, {
|
|
1691
1722
|
hasher: hasher ?? import_ssi_sdk.defaultHasher
|
|
1692
1723
|
});
|
|
@@ -1738,17 +1769,13 @@ var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
|
1738
1769
|
}, "verifyCredentialToAccept");
|
|
1739
1770
|
var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
1740
1771
|
const { credentialToAccept, hasher } = args;
|
|
1741
|
-
const
|
|
1742
|
-
const verifiableCredential = credentialResponse.credential;
|
|
1743
|
-
if (!verifiableCredential) {
|
|
1744
|
-
return Promise.reject(Error("No credential found in credential response"));
|
|
1745
|
-
}
|
|
1772
|
+
const verifiableCredential = extractCredentialFromResponse(credentialToAccept.credentialResponse);
|
|
1746
1773
|
const wrappedVerifiableCredential = import_ssi_types.CredentialMapper.toWrappedVerifiableCredential(verifiableCredential, {
|
|
1747
1774
|
hasher
|
|
1748
1775
|
});
|
|
1749
1776
|
let uniformVerifiableCredential;
|
|
1750
1777
|
if (import_ssi_types.CredentialMapper.isSdJwtDecodedCredential(wrappedVerifiableCredential.credential)) {
|
|
1751
|
-
uniformVerifiableCredential =
|
|
1778
|
+
uniformVerifiableCredential = (0, import_ssi_types.sdJwtDecodedCredentialToUniformCredential)(wrappedVerifiableCredential.credential);
|
|
1752
1779
|
} else if (import_ssi_types.CredentialMapper.isSdJwtEncoded(wrappedVerifiableCredential.credential)) {
|
|
1753
1780
|
if (!hasher) {
|
|
1754
1781
|
return Promise.reject("a hasher is required for encoded SD-JWT credentials");
|
|
@@ -1762,6 +1789,7 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
|
1762
1789
|
uniformVerifiableCredential = wrappedVerifiableCredential.credential;
|
|
1763
1790
|
}
|
|
1764
1791
|
const correlationId = typeof uniformVerifiableCredential.issuer === "string" ? uniformVerifiableCredential.issuer : import_ssi_types.CredentialMapper.isSdJwtDecodedCredential(uniformVerifiableCredential) ? uniformVerifiableCredential.decodedPayload.iss : uniformVerifiableCredential.issuer.id;
|
|
1792
|
+
const credentialResponse = credentialToAccept.credentialResponse;
|
|
1765
1793
|
return {
|
|
1766
1794
|
correlationId,
|
|
1767
1795
|
credentialToAccept,
|
|
@@ -1773,6 +1801,18 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
|
1773
1801
|
}
|
|
1774
1802
|
};
|
|
1775
1803
|
}, "mapCredentialToAccept");
|
|
1804
|
+
var extractCredentialFromResponse = /* @__PURE__ */ __name((credentialResponse) => {
|
|
1805
|
+
let credential;
|
|
1806
|
+
if ("credential" in credentialResponse) {
|
|
1807
|
+
credential = credentialResponse.credential;
|
|
1808
|
+
} else if ("credentials" in credentialResponse && credentialResponse.credentials && Array.isArray(credentialResponse.credentials) && credentialResponse.credentials.length > 0) {
|
|
1809
|
+
credential = credentialResponse.credentials[0].credential;
|
|
1810
|
+
}
|
|
1811
|
+
if (!credential) {
|
|
1812
|
+
throw new Error("No credential found in credential response");
|
|
1813
|
+
}
|
|
1814
|
+
return credential;
|
|
1815
|
+
}, "extractCredentialFromResponse");
|
|
1776
1816
|
var getIdentifierOpts = /* @__PURE__ */ __name(async (args) => {
|
|
1777
1817
|
const { issuanceOpt, context } = args;
|
|
1778
1818
|
const { identifier: identifierArg } = issuanceOpt;
|
|
@@ -1881,24 +1921,19 @@ var getCredentialConfigsSupportedBySingleTypeOrId = /* @__PURE__ */ __name(async
|
|
|
1881
1921
|
}
|
|
1882
1922
|
__name(createIdFromTypes, "createIdFromTypes");
|
|
1883
1923
|
if (configurationId) {
|
|
1884
|
-
const allSupported2 = client.getCredentialsSupported(
|
|
1924
|
+
const allSupported2 = client.getCredentialsSupported(void 0, format);
|
|
1885
1925
|
return Object.fromEntries(Object.entries(allSupported2).filter(([id, supported]) => id === configurationId || supported.id === configurationId || createIdFromTypes(supported) === configurationId));
|
|
1886
1926
|
}
|
|
1887
|
-
if (!
|
|
1888
|
-
return Promise.reject(Error("openID4VCIClient has no credentialOffer
|
|
1927
|
+
if (!client.credentialOffer) {
|
|
1928
|
+
return Promise.reject(Error("openID4VCIClient has no credentialOffer"));
|
|
1889
1929
|
}
|
|
1890
|
-
if (!
|
|
1891
|
-
|
|
1892
|
-
format = client.credentialOffer.credential_offer.credentials.filter((cred) => typeof cred !== "string").map((cred) => cred.format);
|
|
1893
|
-
if (format?.length === 0) {
|
|
1894
|
-
format = void 0;
|
|
1895
|
-
}
|
|
1896
|
-
}
|
|
1930
|
+
if (!types) {
|
|
1931
|
+
return Promise.reject(Error("openID4VCIClient has no types"));
|
|
1897
1932
|
}
|
|
1898
1933
|
const offerSupported = (0, import_oid4vci_common3.getSupportedCredentials)({
|
|
1899
|
-
types:
|
|
1934
|
+
types: [
|
|
1900
1935
|
types
|
|
1901
|
-
]
|
|
1936
|
+
],
|
|
1902
1937
|
format,
|
|
1903
1938
|
version: client.version(),
|
|
1904
1939
|
issuerMetadata: client.endpointMetadata.credentialIssuerMetadata
|
|
@@ -2073,7 +2108,8 @@ var getIssuanceCryptoSuite = /* @__PURE__ */ __name(async (opts) => {
|
|
|
2073
2108
|
case "jwt":
|
|
2074
2109
|
case "jwt_vc_json":
|
|
2075
2110
|
case "jwt_vc":
|
|
2076
|
-
case
|
|
2111
|
+
//case 'vc+sd-jwt': // TODO see SSISDK-52 concerning vc+sd-jwt
|
|
2112
|
+
case "dc+sd-jwt":
|
|
2077
2113
|
case "mso_mdoc": {
|
|
2078
2114
|
const supportedPreferences = jwtCryptographicSuitePreferences.filter((suite) => signing_algs_supported.includes(suite));
|
|
2079
2115
|
if (supportedPreferences.length > 0) {
|
|
@@ -2141,8 +2177,6 @@ var startFirstPartApplicationMachine = /* @__PURE__ */ __name(async (args, conte
|
|
|
2141
2177
|
}, "startFirstPartApplicationMachine");
|
|
2142
2178
|
|
|
2143
2179
|
// src/agent/OID4VCIHolder.ts
|
|
2144
|
-
var import_polyfill = require("cross-fetch/polyfill");
|
|
2145
|
-
var import_ssi_sdk3 = require("@sphereon/ssi-sdk.core");
|
|
2146
2180
|
var oid4vciHolderContextMethods = [
|
|
2147
2181
|
"cmGetContacts",
|
|
2148
2182
|
"cmGetContact",
|
|
@@ -2158,7 +2192,7 @@ var oid4vciHolderContextMethods = [
|
|
|
2158
2192
|
];
|
|
2159
2193
|
var logger = import_ssi_types2.Loggers.DEFAULT.get("sphereon:oid4vci:holder");
|
|
2160
2194
|
function signCallback(identifier, context, nonce) {
|
|
2161
|
-
return async (jwt, kid) => {
|
|
2195
|
+
return async (jwt, kid, noIssPayloadUpdate) => {
|
|
2162
2196
|
let resolution = await context.agent.identifierManagedGet(identifier);
|
|
2163
2197
|
const jwk = jwt.header.jwk ?? (resolution.method === "jwk" ? resolution.jwk : void 0);
|
|
2164
2198
|
if (!resolution.issuer && !jwt.payload.iss) {
|
|
@@ -2176,7 +2210,7 @@ function signCallback(identifier, context, nonce) {
|
|
|
2176
2210
|
return (await context.agent.jwtCreateJwsCompactSignature({
|
|
2177
2211
|
issuer: {
|
|
2178
2212
|
...resolution,
|
|
2179
|
-
noIssPayloadUpdate: false
|
|
2213
|
+
noIssPayloadUpdate: noIssPayloadUpdate ?? false
|
|
2180
2214
|
},
|
|
2181
2215
|
protectedHeader: header,
|
|
2182
2216
|
payload
|
|
@@ -2198,6 +2232,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2198
2232
|
oid4vciHolderStart: this.oid4vciHolderStart.bind(this),
|
|
2199
2233
|
oid4vciHolderGetIssuerMetadata: this.oid4vciHolderGetIssuerMetadata.bind(this),
|
|
2200
2234
|
oid4vciHolderGetMachineInterpreter: this.oid4vciHolderGetMachineInterpreter.bind(this),
|
|
2235
|
+
oid4vciHolderPrepareAuthorizationRequest: this.oid4vciHolderPrepareAuthorizationRequest.bind(this),
|
|
2201
2236
|
oid4vciHolderCreateCredentialsToSelectFrom: this.oid4vciHolderCreateCredentialsToSelectFrom.bind(this),
|
|
2202
2237
|
oid4vciHolderGetContact: this.oid4vciHolderGetContact.bind(this),
|
|
2203
2238
|
oid4vciHolderGetCredentials: this.oid4vciHolderGetCredentials.bind(this),
|
|
@@ -2211,6 +2246,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2211
2246
|
oid4vciHolderStoreIssuerBranding: this.oid4vciHolderStoreIssuerBranding.bind(this)
|
|
2212
2247
|
};
|
|
2213
2248
|
vcFormatPreferences = [
|
|
2249
|
+
"dc+sd-jwt",
|
|
2214
2250
|
"vc+sd-jwt",
|
|
2215
2251
|
"mso_mdoc",
|
|
2216
2252
|
"jwt_vc_json",
|
|
@@ -2244,7 +2280,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2244
2280
|
onIdentifierCreated;
|
|
2245
2281
|
onVerifyEBSICredentialIssuer;
|
|
2246
2282
|
constructor(options) {
|
|
2247
|
-
const { onContactIdentityCreated, onCredentialStored, onIdentifierCreated, onVerifyEBSICredentialIssuer, vcFormatPreferences, jsonldCryptographicSuitePreferences, didMethodPreferences, jwtCryptographicSuitePreferences, defaultAuthorizationRequestOptions, hasher =
|
|
2283
|
+
const { onContactIdentityCreated, onCredentialStored, onIdentifierCreated, onVerifyEBSICredentialIssuer, vcFormatPreferences, jsonldCryptographicSuitePreferences, didMethodPreferences, jwtCryptographicSuitePreferences, defaultAuthorizationRequestOptions, hasher = import_ssi_sdk2.defaultHasher } = {
|
|
2248
2284
|
...options
|
|
2249
2285
|
};
|
|
2250
2286
|
this.hasher = hasher;
|
|
@@ -2301,6 +2337,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2301
2337
|
stateNavigationListener: opts.firstPartyStateNavigationListener
|
|
2302
2338
|
}, context),
|
|
2303
2339
|
[OID4VCIMachineServices.createCredentialsToSelectFrom]: (args) => this.oid4vciHolderCreateCredentialsToSelectFrom(args, context),
|
|
2340
|
+
[OID4VCIMachineServices.prepareAuthorizationRequest]: (args) => this.oid4vciHolderPrepareAuthorizationRequest(args, context),
|
|
2304
2341
|
[OID4VCIMachineServices.getContact]: (args) => this.oid4vciHolderGetContact(args, context),
|
|
2305
2342
|
[OID4VCIMachineServices.getCredentials]: (args) => this.oid4vciHolderGetCredentials({
|
|
2306
2343
|
accessTokenOpts: args.accessTokenOpts ?? opts.accessTokenOpts,
|
|
@@ -2349,7 +2386,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2349
2386
|
...this.defaultAuthorizationRequestOpts,
|
|
2350
2387
|
...args.authorizationRequestOpts
|
|
2351
2388
|
};
|
|
2352
|
-
authorizationRequestOpts.authorizationDetails = authorizationRequestOpts?.authorizationDetails ? (0, import_utils2.asArray)(authorizationRequestOpts.authorizationDetails)
|
|
2389
|
+
authorizationRequestOpts.authorizationDetails = authorizationRequestOpts?.authorizationDetails ? (0, import_utils2.asArray)(authorizationRequestOpts.authorizationDetails) : void 0;
|
|
2353
2390
|
if (!authorizationRequestOpts.redirectUri) {
|
|
2354
2391
|
authorizationRequestOpts.redirectUri = _OID4VCIHolder.DEFAULT_MOBILE_REDIRECT_URI;
|
|
2355
2392
|
}
|
|
@@ -2362,10 +2399,9 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2362
2399
|
formats = Array.from(new Set(authFormats));
|
|
2363
2400
|
}
|
|
2364
2401
|
let oid4vciClient;
|
|
2365
|
-
let types = void 0;
|
|
2366
2402
|
let offer;
|
|
2367
2403
|
if (requestData.existingClientState) {
|
|
2368
|
-
oid4vciClient = await import_oid4vci_client3.
|
|
2404
|
+
oid4vciClient = await import_oid4vci_client3.OpenID4VCIClientV1_0_15.fromState({
|
|
2369
2405
|
state: requestData.existingClientState
|
|
2370
2406
|
});
|
|
2371
2407
|
offer = oid4vciClient.credentialOffer;
|
|
@@ -2382,50 +2418,78 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2382
2418
|
}
|
|
2383
2419
|
if (!offer) {
|
|
2384
2420
|
logger.log(`Issuer url received (no credential offer): ${uri}`);
|
|
2385
|
-
oid4vciClient = await import_oid4vci_client3.
|
|
2421
|
+
oid4vciClient = await import_oid4vci_client3.OpenID4VCIClientV1_0_15.fromCredentialIssuer({
|
|
2386
2422
|
credentialIssuer: uri,
|
|
2387
2423
|
authorizationRequest: authorizationRequestOpts,
|
|
2388
2424
|
clientId: authorizationRequestOpts.clientId,
|
|
2389
|
-
createAuthorizationRequestURL:
|
|
2425
|
+
createAuthorizationRequestURL: false
|
|
2390
2426
|
});
|
|
2391
2427
|
} else {
|
|
2392
2428
|
logger.log(`Credential offer received: ${uri}`);
|
|
2393
|
-
oid4vciClient = await import_oid4vci_client3.
|
|
2429
|
+
oid4vciClient = await import_oid4vci_client3.OpenID4VCIClientV1_0_15.fromURI({
|
|
2394
2430
|
uri,
|
|
2395
2431
|
authorizationRequest: authorizationRequestOpts,
|
|
2396
2432
|
clientId: authorizationRequestOpts.clientId,
|
|
2397
|
-
createAuthorizationRequestURL:
|
|
2433
|
+
createAuthorizationRequestURL: false
|
|
2398
2434
|
});
|
|
2399
2435
|
}
|
|
2400
2436
|
}
|
|
2437
|
+
let configurationIds = [];
|
|
2401
2438
|
if (offer) {
|
|
2402
|
-
|
|
2439
|
+
configurationIds = offer.original_credential_offer.credential_configuration_ids;
|
|
2403
2440
|
} else {
|
|
2404
|
-
|
|
2441
|
+
configurationIds = (0, import_utils2.asArray)(authorizationRequestOpts.authorizationDetails).map((authReqOpts) => authReqOpts.credential_configuration_id).filter((id) => !!id);
|
|
2405
2442
|
}
|
|
2406
|
-
const serverMetadata = await oid4vciClient.retrieveServerMetadata();
|
|
2407
2443
|
const credentialsSupported = await getCredentialConfigsSupportedMerged({
|
|
2408
2444
|
client: oid4vciClient,
|
|
2409
2445
|
vcFormatPreferences: formats,
|
|
2410
|
-
|
|
2446
|
+
configurationIds
|
|
2411
2447
|
});
|
|
2448
|
+
const serverMetadata = await oid4vciClient.retrieveServerMetadata();
|
|
2412
2449
|
const credentialBranding = await getCredentialBranding({
|
|
2413
2450
|
credentialsSupported,
|
|
2414
2451
|
context
|
|
2415
2452
|
});
|
|
2416
|
-
const authorizationCodeURL = oid4vciClient.authorizationURL;
|
|
2417
|
-
if (authorizationCodeURL) {
|
|
2418
|
-
logger.log(`authorization code URL ${authorizationCodeURL}`);
|
|
2419
|
-
}
|
|
2420
2453
|
const oid4vciClientState = JSON.parse(await oid4vciClient.exportState());
|
|
2421
2454
|
return {
|
|
2422
|
-
authorizationCodeURL,
|
|
2423
2455
|
credentialBranding,
|
|
2424
2456
|
credentialsSupported,
|
|
2425
2457
|
serverMetadata,
|
|
2426
2458
|
oid4vciClientState
|
|
2427
2459
|
};
|
|
2428
2460
|
}
|
|
2461
|
+
async oid4vciHolderPrepareAuthorizationRequest(args, context) {
|
|
2462
|
+
const { openID4VCIClientState, contact } = args;
|
|
2463
|
+
if (!openID4VCIClientState) {
|
|
2464
|
+
return Promise.reject(Error("Missing openID4VCI client state in context"));
|
|
2465
|
+
}
|
|
2466
|
+
const clientId = contact?.identities.map((identity) => {
|
|
2467
|
+
const connectionConfig = identity.connection?.config;
|
|
2468
|
+
if (connectionConfig && "clientId" in connectionConfig) {
|
|
2469
|
+
return connectionConfig.clientId;
|
|
2470
|
+
}
|
|
2471
|
+
return void 0;
|
|
2472
|
+
}).find((clientId2) => clientId2);
|
|
2473
|
+
if (!clientId) {
|
|
2474
|
+
return Promise.reject(Error(`Missing client id in contact's connectionConfig`));
|
|
2475
|
+
}
|
|
2476
|
+
const client = await import_oid4vci_client3.OpenID4VCIClient.fromState({
|
|
2477
|
+
state: openID4VCIClientState
|
|
2478
|
+
});
|
|
2479
|
+
const authorizationCodeURL = await client.createAuthorizationRequestUrl({
|
|
2480
|
+
authorizationRequest: {
|
|
2481
|
+
clientId
|
|
2482
|
+
}
|
|
2483
|
+
});
|
|
2484
|
+
if (authorizationCodeURL) {
|
|
2485
|
+
logger.log(`authorization code URL ${authorizationCodeURL}`);
|
|
2486
|
+
}
|
|
2487
|
+
return {
|
|
2488
|
+
authorizationCodeURL,
|
|
2489
|
+
// Needed, because the above createAuthorizationRequestUrl manipulates the state, adding pkce opts to the state
|
|
2490
|
+
oid4vciClientState: JSON.parse(await client.exportState())
|
|
2491
|
+
};
|
|
2492
|
+
}
|
|
2429
2493
|
async oid4vciHolderCreateCredentialsToSelectFrom(args, context) {
|
|
2430
2494
|
const { credentialBranding, locale, selectedCredentials, credentialsSupported } = args;
|
|
2431
2495
|
logger.info(`Credentials supported ${Object.keys(credentialsSupported).join(", ")}`);
|
|
@@ -2497,7 +2561,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2497
2561
|
if (!openID4VCIClientState) {
|
|
2498
2562
|
return Promise.reject(Error("Missing openID4VCI client state in context"));
|
|
2499
2563
|
}
|
|
2500
|
-
const client = await import_oid4vci_client3.
|
|
2564
|
+
const client = await import_oid4vci_client3.OpenID4VCIClientV1_0_15.fromState({
|
|
2501
2565
|
state: openID4VCIClientState
|
|
2502
2566
|
});
|
|
2503
2567
|
const credentialsSupported = await getCredentialConfigsSupportedMerged({
|
|
@@ -2625,26 +2689,26 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2625
2689
|
return Promise.reject(Error("Missing credential offers in context"));
|
|
2626
2690
|
}
|
|
2627
2691
|
let correlationId = credentialsToAccept[0].correlationId;
|
|
2628
|
-
let identifierType =
|
|
2692
|
+
let identifierType = import_ssi_sdk3.CorrelationIdentifierType.DID;
|
|
2629
2693
|
if (!correlationId.toLowerCase().startsWith("did:")) {
|
|
2630
|
-
identifierType =
|
|
2694
|
+
identifierType = import_ssi_sdk3.CorrelationIdentifierType.URL;
|
|
2631
2695
|
if (correlationId.startsWith("http")) {
|
|
2632
2696
|
correlationId = new URL(correlationId).hostname;
|
|
2633
2697
|
}
|
|
2634
2698
|
}
|
|
2635
2699
|
const identity = {
|
|
2636
2700
|
alias: credentialsToAccept[0].correlationId,
|
|
2637
|
-
origin:
|
|
2701
|
+
origin: import_ssi_sdk3.IdentityOrigin.EXTERNAL,
|
|
2638
2702
|
roles: [
|
|
2639
|
-
|
|
2703
|
+
import_ssi_types2.CredentialRole.ISSUER
|
|
2640
2704
|
],
|
|
2641
2705
|
identifier: {
|
|
2642
2706
|
type: identifierType,
|
|
2643
2707
|
correlationId
|
|
2644
2708
|
},
|
|
2645
|
-
...identifierType ===
|
|
2709
|
+
...identifierType === import_ssi_sdk3.CorrelationIdentifierType.URL && {
|
|
2646
2710
|
connection: {
|
|
2647
|
-
type:
|
|
2711
|
+
type: import_ssi_sdk3.ConnectionType.OPENID_CONNECT,
|
|
2648
2712
|
config: {
|
|
2649
2713
|
clientId: "138d7bf8-c930-4c6e-b928-97d3a4928b01",
|
|
2650
2714
|
clientSecret: "03b3955f-d020-4f2a-8a27-4e452d4e27a0",
|
|
@@ -2671,7 +2735,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2671
2735
|
}
|
|
2672
2736
|
async oid4vciHolderGetIssuerBranding(args, context) {
|
|
2673
2737
|
const { serverMetadata, contact } = args;
|
|
2674
|
-
const issuerCorrelationId = contact?.identities.filter((identity) => identity.roles.includes(
|
|
2738
|
+
const issuerCorrelationId = contact?.identities.filter((identity) => identity.roles.includes(import_ssi_types2.CredentialRole.ISSUER)).map((identity) => identity.identifier.correlationId)[0];
|
|
2675
2739
|
if (issuerCorrelationId) {
|
|
2676
2740
|
const branding = await context.agent.ibGetIssuerBranding({
|
|
2677
2741
|
filter: [
|
|
@@ -2701,7 +2765,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2701
2765
|
if (!contact) {
|
|
2702
2766
|
return Promise.reject(Error("Missing contact in context"));
|
|
2703
2767
|
}
|
|
2704
|
-
const issuerCorrelationId = contact?.identities.filter((identity) => identity.roles.includes(
|
|
2768
|
+
const issuerCorrelationId = contact?.identities.filter((identity) => identity.roles.includes(import_ssi_types2.CredentialRole.ISSUER)).map((identity) => identity.identifier.correlationId)[0];
|
|
2705
2769
|
const branding = await context.agent.ibGetIssuerBranding({
|
|
2706
2770
|
filter: [
|
|
2707
2771
|
{
|
|
@@ -2737,9 +2801,19 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2737
2801
|
}
|
|
2738
2802
|
let counter = 0;
|
|
2739
2803
|
for (const credentialId of selectedCredentials) {
|
|
2740
|
-
const
|
|
2804
|
+
const configId = credentialId;
|
|
2805
|
+
const types = credentialsToAccept.find((ac) => ac.correlationId === configId || ac.credentialToAccept.id === configId || ac.types.includes(configId))?.types?.filter((type) => type != "VerifiableCredential") ?? [];
|
|
2806
|
+
const localeBranding = credentialBranding?.[configId] ?? [];
|
|
2807
|
+
if (localeBranding.length === 0) {
|
|
2808
|
+
for (const type of types) {
|
|
2809
|
+
const branding = credentialBranding?.[type] ?? [];
|
|
2810
|
+
if (branding.length > 0) {
|
|
2811
|
+
localeBranding.push(...branding);
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
}
|
|
2741
2815
|
if (localeBranding && localeBranding.length > 0) {
|
|
2742
|
-
const credential = credentialsToAccept.find((credAccept) => credAccept.credentialToAccept.id === credentialId || JSON.stringify(credAccept.types) === credentialId || credentialsToAccept[counter]);
|
|
2816
|
+
const credential = credentialsToAccept.find((credAccept) => credAccept.credentialToAccept.id === credentialId || JSON.stringify(credAccept.types) === credentialId || JSON.stringify(credAccept.types.filter((cred) => cred !== "VerifiableCredential")) === JSON.stringify(types) || credentialsToAccept[counter]);
|
|
2743
2817
|
counter++;
|
|
2744
2818
|
await context.agent.ibAddCredentialBranding({
|
|
2745
2819
|
vcHash: (0, import_utils2.computeEntryHash)(credential.rawVerifiableCredential),
|
|
@@ -2787,9 +2861,9 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2787
2861
|
if (Array.isArray(subjectIssuance?.notification_events_supported)) {
|
|
2788
2862
|
event = subjectIssuance.notification_events_supported.includes("credential_accepted_holder_signed") ? "credential_accepted_holder_signed" : "credential_deleted_holder_signed";
|
|
2789
2863
|
logger.log(`Subject issuance/signing will be used, with event`, event);
|
|
2790
|
-
const issuerVC = mappedCredentialToAccept.credentialToAccept.credentialResponse
|
|
2864
|
+
const issuerVC = extractCredentialFromResponse(mappedCredentialToAccept.credentialToAccept.credentialResponse);
|
|
2791
2865
|
const wrappedIssuerVC = import_ssi_types2.CredentialMapper.toWrappedVerifiableCredential(issuerVC, {
|
|
2792
|
-
hasher: this.hasher ??
|
|
2866
|
+
hasher: this.hasher ?? import_ssi_sdk2.defaultHasher
|
|
2793
2867
|
});
|
|
2794
2868
|
console.log(`Wrapped VC: ${wrappedIssuerVC.type}, ${wrappedIssuerVC.format}`);
|
|
2795
2869
|
let issuer;
|
|
@@ -2890,11 +2964,11 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2890
2964
|
const [subjectCorrelationType, subjectCorrelationId] = this.determineSubjectCorrelation(issuanceOpt.identifier, issuer);
|
|
2891
2965
|
const persistedCredential = await context.agent.crsAddCredential({
|
|
2892
2966
|
credential: {
|
|
2893
|
-
rawDocument: (0,
|
|
2967
|
+
rawDocument: (0, import_ssi_sdk3.ensureRawDocument)(persistCredential),
|
|
2894
2968
|
kmsKeyRef,
|
|
2895
2969
|
identifierMethod: method,
|
|
2896
|
-
credentialRole:
|
|
2897
|
-
issuerCorrelationType: issuer?.startsWith("did:") ?
|
|
2970
|
+
credentialRole: import_ssi_types2.CredentialRole.HOLDER,
|
|
2971
|
+
issuerCorrelationType: issuer?.startsWith("did:") ? import_ssi_sdk3.CredentialCorrelationType.DID : import_ssi_sdk3.CredentialCorrelationType.URL,
|
|
2898
2972
|
issuerCorrelationId: issuer,
|
|
2899
2973
|
subjectCorrelationType,
|
|
2900
2974
|
subjectCorrelationId
|
|
@@ -2962,12 +3036,12 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2962
3036
|
case "did":
|
|
2963
3037
|
if ((0, import_ssi_sdk_ext6.isManagedIdentifierResult)(identifier) && (0, import_ssi_sdk_ext6.isManagedIdentifierDidResult)(identifier)) {
|
|
2964
3038
|
return [
|
|
2965
|
-
|
|
3039
|
+
import_ssi_sdk3.CredentialCorrelationType.DID,
|
|
2966
3040
|
identifier.did
|
|
2967
3041
|
];
|
|
2968
3042
|
} else if ((0, import_ssi_sdk_ext6.isManagedIdentifierDidOpts)(identifier)) {
|
|
2969
3043
|
return [
|
|
2970
|
-
|
|
3044
|
+
import_ssi_sdk3.CredentialCorrelationType.DID,
|
|
2971
3045
|
typeof identifier.identifier === "string" ? identifier.identifier : identifier.identifier.did
|
|
2972
3046
|
];
|
|
2973
3047
|
}
|
|
@@ -2975,12 +3049,12 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2975
3049
|
case "kid":
|
|
2976
3050
|
if ((0, import_ssi_sdk_ext6.isManagedIdentifierResult)(identifier) && (0, import_ssi_sdk_ext6.isManagedIdentifierKidResult)(identifier)) {
|
|
2977
3051
|
return [
|
|
2978
|
-
|
|
3052
|
+
import_ssi_sdk3.CredentialCorrelationType.KID,
|
|
2979
3053
|
identifier.kid
|
|
2980
3054
|
];
|
|
2981
3055
|
} else if ((0, import_ssi_sdk_ext6.isManagedIdentifierDidOpts)(identifier)) {
|
|
2982
3056
|
return [
|
|
2983
|
-
|
|
3057
|
+
import_ssi_sdk3.CredentialCorrelationType.KID,
|
|
2984
3058
|
identifier.identifier
|
|
2985
3059
|
];
|
|
2986
3060
|
}
|
|
@@ -2988,19 +3062,19 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2988
3062
|
case "x5c":
|
|
2989
3063
|
if ((0, import_ssi_sdk_ext6.isManagedIdentifierResult)(identifier) && (0, import_ssi_sdk_ext6.isManagedIdentifierX5cResult)(identifier)) {
|
|
2990
3064
|
return [
|
|
2991
|
-
|
|
3065
|
+
import_ssi_sdk3.CredentialCorrelationType.X509_SAN,
|
|
2992
3066
|
identifier.x5c.join("\r\n")
|
|
2993
3067
|
];
|
|
2994
3068
|
} else if ((0, import_ssi_sdk_ext6.isManagedIdentifierX5cOpts)(identifier)) {
|
|
2995
3069
|
return [
|
|
2996
|
-
|
|
3070
|
+
import_ssi_sdk3.CredentialCorrelationType.X509_SAN,
|
|
2997
3071
|
identifier.identifier.join("\r\n")
|
|
2998
3072
|
];
|
|
2999
3073
|
}
|
|
3000
3074
|
break;
|
|
3001
3075
|
}
|
|
3002
3076
|
return [
|
|
3003
|
-
|
|
3077
|
+
import_ssi_sdk3.CredentialCorrelationType.URL,
|
|
3004
3078
|
issuer
|
|
3005
3079
|
];
|
|
3006
3080
|
}
|