@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.js
CHANGED
|
@@ -55,14 +55,16 @@ var require_nl = __commonJS({
|
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
// src/agent/OID4VCIHolder.ts
|
|
58
|
-
import { CredentialOfferClient, MetadataClient, OpenID4VCIClient as OpenID4VCIClient2 } from "@sphereon/oid4vci-client";
|
|
59
|
-
import { DefaultURISchemes,
|
|
58
|
+
import { CredentialOfferClient, MetadataClient, OpenID4VCIClient as OpenID4VCIClient2, OpenID4VCIClientV1_0_15 } from "@sphereon/oid4vci-client";
|
|
59
|
+
import { DefaultURISchemes, getTypesFromObject as getTypesFromObject2 } from "@sphereon/oid4vci-common";
|
|
60
60
|
import { SupportedDidMethodEnum as SupportedDidMethodEnum2 } from "@sphereon/ssi-sdk-ext.did-utils";
|
|
61
61
|
import { isManagedIdentifierDidOpts, isManagedIdentifierDidResult as isManagedIdentifierDidResult2, isManagedIdentifierJwkResult, isManagedIdentifierKidResult, isManagedIdentifierResult as isManagedIdentifierResult2, isManagedIdentifierX5cOpts, isManagedIdentifierX5cResult } from "@sphereon/ssi-sdk-ext.identifier-resolution";
|
|
62
62
|
import { signatureAlgorithmFromKey } from "@sphereon/ssi-sdk-ext.key-utils";
|
|
63
|
-
import {
|
|
64
|
-
import {
|
|
63
|
+
import { defaultHasher as defaultHasher2 } from "@sphereon/ssi-sdk.core";
|
|
64
|
+
import { ConnectionType, CorrelationIdentifierType, CredentialCorrelationType, ensureRawDocument, IdentityOrigin } from "@sphereon/ssi-sdk.data-store-types";
|
|
65
|
+
import { CredentialMapper as CredentialMapper2, CredentialRole, JoseSignatureAlgorithm as JoseSignatureAlgorithm2, Loggers, parseDid } from "@sphereon/ssi-types";
|
|
65
66
|
import { asArray as asArray2, computeEntryHash } from "@veramo/utils";
|
|
67
|
+
import fetch from "cross-fetch";
|
|
66
68
|
import { decodeJWT } from "did-jwt";
|
|
67
69
|
import { v4 as uuidv42 } from "uuid";
|
|
68
70
|
|
|
@@ -75,18 +77,18 @@ import i18n from "i18n-js";
|
|
|
75
77
|
import memoize from "lodash.memoize";
|
|
76
78
|
|
|
77
79
|
// src/types/IOID4VCIHolder.ts
|
|
78
|
-
var OID4VCIHolderEvent = /* @__PURE__ */ function(OID4VCIHolderEvent2) {
|
|
80
|
+
var OID4VCIHolderEvent = /* @__PURE__ */ (function(OID4VCIHolderEvent2) {
|
|
79
81
|
OID4VCIHolderEvent2["CONTACT_IDENTITY_CREATED"] = "contact_identity_created";
|
|
80
82
|
OID4VCIHolderEvent2["CREDENTIAL_STORED"] = "credential_stored";
|
|
81
83
|
OID4VCIHolderEvent2["IDENTIFIER_CREATED"] = "identifier_created";
|
|
82
84
|
return OID4VCIHolderEvent2;
|
|
83
|
-
}({});
|
|
84
|
-
var SupportedLanguage = /* @__PURE__ */ function(SupportedLanguage2) {
|
|
85
|
+
})({});
|
|
86
|
+
var SupportedLanguage = /* @__PURE__ */ (function(SupportedLanguage2) {
|
|
85
87
|
SupportedLanguage2["ENGLISH"] = "en";
|
|
86
88
|
SupportedLanguage2["DUTCH"] = "nl";
|
|
87
89
|
return SupportedLanguage2;
|
|
88
|
-
}({});
|
|
89
|
-
var OID4VCIMachineStates = /* @__PURE__ */ function(OID4VCIMachineStates2) {
|
|
90
|
+
})({});
|
|
91
|
+
var OID4VCIMachineStates = /* @__PURE__ */ (function(OID4VCIMachineStates2) {
|
|
90
92
|
OID4VCIMachineStates2["start"] = "start";
|
|
91
93
|
OID4VCIMachineStates2["createCredentialsToSelectFrom"] = "createCredentialsToSelectFrom";
|
|
92
94
|
OID4VCIMachineStates2["getContact"] = "getContact";
|
|
@@ -102,6 +104,7 @@ var OID4VCIMachineStates = /* @__PURE__ */ function(OID4VCIMachineStates2) {
|
|
|
102
104
|
OID4VCIMachineStates2["selectCredentials"] = "selectCredentials";
|
|
103
105
|
OID4VCIMachineStates2["transitionFromSelectingCredentials"] = "transitionFromSelectingCredentials";
|
|
104
106
|
OID4VCIMachineStates2["verifyPin"] = "verifyPin";
|
|
107
|
+
OID4VCIMachineStates2["prepareAuthorizationRequest"] = "prepareAuthorizationRequest";
|
|
105
108
|
OID4VCIMachineStates2["initiateAuthorizationRequest"] = "initiateAuthorizationRequest";
|
|
106
109
|
OID4VCIMachineStates2["waitForAuthorizationResponse"] = "waitForAuthorizationResponse";
|
|
107
110
|
OID4VCIMachineStates2["getCredentials"] = "getCredentials";
|
|
@@ -117,18 +120,18 @@ var OID4VCIMachineStates = /* @__PURE__ */ function(OID4VCIMachineStates2) {
|
|
|
117
120
|
OID4VCIMachineStates2["error"] = "error";
|
|
118
121
|
OID4VCIMachineStates2["done"] = "done";
|
|
119
122
|
return OID4VCIMachineStates2;
|
|
120
|
-
}({});
|
|
121
|
-
var OID4VCIMachineAddContactStates = /* @__PURE__ */ function(OID4VCIMachineAddContactStates2) {
|
|
123
|
+
})({});
|
|
124
|
+
var OID4VCIMachineAddContactStates = /* @__PURE__ */ (function(OID4VCIMachineAddContactStates2) {
|
|
122
125
|
OID4VCIMachineAddContactStates2["idle"] = "idle";
|
|
123
126
|
OID4VCIMachineAddContactStates2["next"] = "next";
|
|
124
127
|
return OID4VCIMachineAddContactStates2;
|
|
125
|
-
}({});
|
|
126
|
-
var OID4VCIMachineVerifyPinStates = /* @__PURE__ */ function(OID4VCIMachineVerifyPinStates2) {
|
|
128
|
+
})({});
|
|
129
|
+
var OID4VCIMachineVerifyPinStates = /* @__PURE__ */ (function(OID4VCIMachineVerifyPinStates2) {
|
|
127
130
|
OID4VCIMachineVerifyPinStates2["idle"] = "idle";
|
|
128
131
|
OID4VCIMachineVerifyPinStates2["next"] = "next";
|
|
129
132
|
return OID4VCIMachineVerifyPinStates2;
|
|
130
|
-
}({});
|
|
131
|
-
var OID4VCIMachineEvents = /* @__PURE__ */ function(OID4VCIMachineEvents2) {
|
|
133
|
+
})({});
|
|
134
|
+
var OID4VCIMachineEvents = /* @__PURE__ */ (function(OID4VCIMachineEvents2) {
|
|
132
135
|
OID4VCIMachineEvents2["NEXT"] = "NEXT";
|
|
133
136
|
OID4VCIMachineEvents2["PREVIOUS"] = "PREVIOUS";
|
|
134
137
|
OID4VCIMachineEvents2["DECLINE"] = "DECLINE";
|
|
@@ -141,14 +144,15 @@ var OID4VCIMachineEvents = /* @__PURE__ */ function(OID4VCIMachineEvents2) {
|
|
|
141
144
|
OID4VCIMachineEvents2["INVOKED_AUTHORIZATION_CODE_REQUEST"] = "INVOKED_AUTHORIZATION_CODE_REQUEST";
|
|
142
145
|
OID4VCIMachineEvents2["PROVIDE_AUTHORIZATION_CODE_RESPONSE"] = "PROVIDE_AUTHORIZATION_CODE_RESPONSE";
|
|
143
146
|
return OID4VCIMachineEvents2;
|
|
144
|
-
}({});
|
|
145
|
-
var OID4VCIMachineGuards = /* @__PURE__ */ function(OID4VCIMachineGuards2) {
|
|
147
|
+
})({});
|
|
148
|
+
var OID4VCIMachineGuards = /* @__PURE__ */ (function(OID4VCIMachineGuards2) {
|
|
146
149
|
OID4VCIMachineGuards2["hasContactGuard"] = "oid4vciHasContactGuard";
|
|
147
150
|
OID4VCIMachineGuards2["hasNoContactGuard"] = "oid4vciHasNoContactGuard";
|
|
148
151
|
OID4VCIMachineGuards2["credentialsToSelectRequiredGuard"] = "oid4vciCredentialsToSelectRequiredGuard";
|
|
149
152
|
OID4VCIMachineGuards2["requirePinGuard"] = "oid4vciRequirePinGuard";
|
|
150
153
|
OID4VCIMachineGuards2["requireAuthorizationGuard"] = "oid4vciRequireAuthorizationGuard";
|
|
151
154
|
OID4VCIMachineGuards2["noAuthorizationGuard"] = "oid4vciNoAuthorizationGuard";
|
|
155
|
+
OID4VCIMachineGuards2["hasNonceEndpointGuard"] = "oid4vciHasNonceEndpointGuard ";
|
|
152
156
|
OID4VCIMachineGuards2["hasAuthorizationResponse"] = "oid4vciHasAuthorizationResponse";
|
|
153
157
|
OID4VCIMachineGuards2["hasNoContactIdentityGuard"] = "oid4vciHasNoContactIdentityGuard";
|
|
154
158
|
OID4VCIMachineGuards2["verificationCodeGuard"] = "oid4vciVerificationCodeGuard";
|
|
@@ -158,13 +162,14 @@ var OID4VCIMachineGuards = /* @__PURE__ */ function(OID4VCIMachineGuards2) {
|
|
|
158
162
|
OID4VCIMachineGuards2["contactHasLowTrustGuard"] = "oid4vciContactHasLowTrustGuard";
|
|
159
163
|
OID4VCIMachineGuards2["isFirstPartyApplication"] = "oid4vciIsFirstPartyApplication";
|
|
160
164
|
return OID4VCIMachineGuards2;
|
|
161
|
-
}({});
|
|
162
|
-
var OID4VCIMachineServices = /* @__PURE__ */ function(OID4VCIMachineServices2) {
|
|
165
|
+
})({});
|
|
166
|
+
var OID4VCIMachineServices = /* @__PURE__ */ (function(OID4VCIMachineServices2) {
|
|
163
167
|
OID4VCIMachineServices2["start"] = "start";
|
|
164
168
|
OID4VCIMachineServices2["getContact"] = "getContact";
|
|
165
169
|
OID4VCIMachineServices2["getFederationTrust"] = "getFederationTrust";
|
|
166
170
|
OID4VCIMachineServices2["addContactIdentity"] = "addContactIdentity";
|
|
167
171
|
OID4VCIMachineServices2["createCredentialsToSelectFrom"] = "createCredentialsToSelectFrom";
|
|
172
|
+
OID4VCIMachineServices2["prepareAuthorizationRequest"] = "prepareAuthorizationRequest";
|
|
168
173
|
OID4VCIMachineServices2["getIssuerBranding"] = "getIssuerBranding";
|
|
169
174
|
OID4VCIMachineServices2["storeIssuerBranding"] = "storeIssuerBranding";
|
|
170
175
|
OID4VCIMachineServices2["getCredentials"] = "getCredentials";
|
|
@@ -174,17 +179,17 @@ var OID4VCIMachineServices = /* @__PURE__ */ function(OID4VCIMachineServices2) {
|
|
|
174
179
|
OID4VCIMachineServices2["storeCredentials"] = "storeCredentials";
|
|
175
180
|
OID4VCIMachineServices2["startFirstPartApplicationFlow"] = "startFirstPartApplicationFlow";
|
|
176
181
|
return OID4VCIMachineServices2;
|
|
177
|
-
}({});
|
|
178
|
-
var RequestType = /* @__PURE__ */ function(RequestType2) {
|
|
182
|
+
})({});
|
|
183
|
+
var RequestType = /* @__PURE__ */ (function(RequestType2) {
|
|
179
184
|
RequestType2["OPENID_INITIATE_ISSUANCE"] = "openid-initiate-issuance";
|
|
180
185
|
RequestType2["OPENID_CREDENTIAL_OFFER"] = "openid-credential-offer";
|
|
181
186
|
RequestType2["URL"] = "URL";
|
|
182
187
|
return RequestType2;
|
|
183
|
-
}({});
|
|
184
|
-
var IdentifierAliasEnum = /* @__PURE__ */ function(IdentifierAliasEnum2) {
|
|
188
|
+
})({});
|
|
189
|
+
var IdentifierAliasEnum = /* @__PURE__ */ (function(IdentifierAliasEnum2) {
|
|
185
190
|
IdentifierAliasEnum2["PRIMARY"] = "primary";
|
|
186
191
|
return IdentifierAliasEnum2;
|
|
187
|
-
}({});
|
|
192
|
+
})({});
|
|
188
193
|
|
|
189
194
|
// src/localization/Localization.ts
|
|
190
195
|
var Localization = class Localization2 {
|
|
@@ -226,7 +231,7 @@ var Localization = class Localization2 {
|
|
|
226
231
|
var translate = Localization.translate;
|
|
227
232
|
|
|
228
233
|
// src/types/FirstPartyMachine.ts
|
|
229
|
-
var FirstPartyMachineStateTypes = /* @__PURE__ */ function(FirstPartyMachineStateTypes2) {
|
|
234
|
+
var FirstPartyMachineStateTypes = /* @__PURE__ */ (function(FirstPartyMachineStateTypes2) {
|
|
230
235
|
FirstPartyMachineStateTypes2["sendAuthorizationChallengeRequest"] = "sendAuthorizationChallengeRequest";
|
|
231
236
|
FirstPartyMachineStateTypes2["sendAuthorizationResponse"] = "sendAuthorizationResponse";
|
|
232
237
|
FirstPartyMachineStateTypes2["selectCredentials"] = "selectCredentials";
|
|
@@ -237,21 +242,21 @@ var FirstPartyMachineStateTypes = /* @__PURE__ */ function(FirstPartyMachineStat
|
|
|
237
242
|
FirstPartyMachineStateTypes2["aborted"] = "aborted";
|
|
238
243
|
FirstPartyMachineStateTypes2["declined"] = "declined";
|
|
239
244
|
return FirstPartyMachineStateTypes2;
|
|
240
|
-
}({});
|
|
241
|
-
var FirstPartyMachineServices = /* @__PURE__ */ function(FirstPartyMachineServices2) {
|
|
245
|
+
})({});
|
|
246
|
+
var FirstPartyMachineServices = /* @__PURE__ */ (function(FirstPartyMachineServices2) {
|
|
242
247
|
FirstPartyMachineServices2["sendAuthorizationChallengeRequest"] = "sendAuthorizationChallengeRequest";
|
|
243
248
|
FirstPartyMachineServices2["sendAuthorizationResponse"] = "sendAuthorizationResponse";
|
|
244
249
|
FirstPartyMachineServices2["createConfig"] = "createConfig";
|
|
245
250
|
FirstPartyMachineServices2["getSiopRequest"] = "getSiopRequest";
|
|
246
251
|
return FirstPartyMachineServices2;
|
|
247
|
-
}({});
|
|
248
|
-
var FirstPartyMachineEvents = /* @__PURE__ */ function(FirstPartyMachineEvents2) {
|
|
252
|
+
})({});
|
|
253
|
+
var FirstPartyMachineEvents = /* @__PURE__ */ (function(FirstPartyMachineEvents2) {
|
|
249
254
|
FirstPartyMachineEvents2["NEXT"] = "NEXT";
|
|
250
255
|
FirstPartyMachineEvents2["PREVIOUS"] = "PREVIOUS";
|
|
251
256
|
FirstPartyMachineEvents2["DECLINE"] = "DECLINE";
|
|
252
257
|
FirstPartyMachineEvents2["SET_SELECTED_CREDENTIALS"] = "SET_SELECTED_CREDENTIALS";
|
|
253
258
|
return FirstPartyMachineEvents2;
|
|
254
|
-
}({});
|
|
259
|
+
})({});
|
|
255
260
|
|
|
256
261
|
// src/machines/oid4vciMachine.ts
|
|
257
262
|
var oid4vciHasNoContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
@@ -306,9 +311,7 @@ var oid4vciRequireAuthorizationGuard = /* @__PURE__ */ __name((ctx, _event) => {
|
|
|
306
311
|
if (!openID4VCIClientState) {
|
|
307
312
|
throw Error("Missing openID4VCI client state in context");
|
|
308
313
|
}
|
|
309
|
-
if (
|
|
310
|
-
return false;
|
|
311
|
-
} else if (openID4VCIClientState.authorizationRequestOpts) {
|
|
314
|
+
if (openID4VCIClientState.authorizationURL && openID4VCIClientState.authorizationRequestOpts) {
|
|
312
315
|
return !ctx.openID4VCIClientState?.authorizationCodeResponse;
|
|
313
316
|
} else if (openID4VCIClientState.credentialOffer?.supportedFlows?.includes(AuthzFlowType.AUTHORIZATION_CODE_FLOW)) {
|
|
314
317
|
return !ctx.openID4VCIClientState?.authorizationCodeResponse;
|
|
@@ -359,7 +362,6 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
|
|
|
359
362
|
onDone: {
|
|
360
363
|
target: OID4VCIMachineStates.createCredentialsToSelectFrom,
|
|
361
364
|
actions: assign({
|
|
362
|
-
authorizationCodeURL: /* @__PURE__ */ __name((_ctx, _event) => _event.data.authorizationCodeURL, "authorizationCodeURL"),
|
|
363
365
|
credentialBranding: /* @__PURE__ */ __name((_ctx, _event) => _event.data.credentialBranding ?? {}, "credentialBranding"),
|
|
364
366
|
credentialsSupported: /* @__PURE__ */ __name((_ctx, _event) => _event.data.credentialsSupported, "credentialsSupported"),
|
|
365
367
|
serverMetadata: /* @__PURE__ */ __name((_ctx, _event) => _event.data.serverMetadata, "serverMetadata"),
|
|
@@ -596,6 +598,10 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
|
|
|
596
598
|
target: OID4VCIMachineStates.startFirstPartApplicationFlow,
|
|
597
599
|
cond: OID4VCIMachineGuards.isFirstPartyApplication
|
|
598
600
|
},
|
|
601
|
+
{
|
|
602
|
+
target: OID4VCIMachineStates.prepareAuthorizationRequest,
|
|
603
|
+
cond: OID4VCIMachineGuards.requireAuthorizationGuard
|
|
604
|
+
},
|
|
599
605
|
{
|
|
600
606
|
target: OID4VCIMachineStates.initiateAuthorizationRequest,
|
|
601
607
|
cond: OID4VCIMachineGuards.requireAuthorizationGuard
|
|
@@ -671,12 +677,16 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
|
|
|
671
677
|
target: OID4VCIMachineStates.startFirstPartApplicationFlow,
|
|
672
678
|
cond: OID4VCIMachineGuards.isFirstPartyApplication
|
|
673
679
|
},
|
|
680
|
+
{
|
|
681
|
+
target: OID4VCIMachineStates.prepareAuthorizationRequest,
|
|
682
|
+
cond: OID4VCIMachineGuards.requireAuthorizationGuard
|
|
683
|
+
},
|
|
674
684
|
{
|
|
675
685
|
target: OID4VCIMachineStates.verifyPin,
|
|
676
686
|
cond: OID4VCIMachineGuards.requirePinGuard
|
|
677
687
|
},
|
|
678
688
|
{
|
|
679
|
-
target: OID4VCIMachineStates.
|
|
689
|
+
target: OID4VCIMachineStates.prepareAuthorizationRequest,
|
|
680
690
|
cond: OID4VCIMachineGuards.requireAuthorizationGuard
|
|
681
691
|
},
|
|
682
692
|
{
|
|
@@ -684,6 +694,29 @@ var createOID4VCIMachine = /* @__PURE__ */ __name((opts) => {
|
|
|
684
694
|
}
|
|
685
695
|
]
|
|
686
696
|
},
|
|
697
|
+
[OID4VCIMachineStates.prepareAuthorizationRequest]: {
|
|
698
|
+
id: OID4VCIMachineStates.prepareAuthorizationRequest,
|
|
699
|
+
invoke: {
|
|
700
|
+
src: OID4VCIMachineServices.prepareAuthorizationRequest,
|
|
701
|
+
onDone: {
|
|
702
|
+
target: OID4VCIMachineStates.initiateAuthorizationRequest,
|
|
703
|
+
actions: assign({
|
|
704
|
+
authorizationCodeURL: /* @__PURE__ */ __name((_ctx, _event) => _event.data.authorizationCodeURL, "authorizationCodeURL"),
|
|
705
|
+
openID4VCIClientState: /* @__PURE__ */ __name((_ctx, _event) => _event.data.oid4vciClientState, "openID4VCIClientState")
|
|
706
|
+
})
|
|
707
|
+
},
|
|
708
|
+
onError: {
|
|
709
|
+
target: OID4VCIMachineStates.handleError,
|
|
710
|
+
actions: assign({
|
|
711
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
712
|
+
title: translate("oid4vci_machine_prepare_authorization_error_title"),
|
|
713
|
+
message: _event.data.message,
|
|
714
|
+
stack: _event.data.stack
|
|
715
|
+
}), "error")
|
|
716
|
+
})
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
},
|
|
687
720
|
[OID4VCIMachineStates.initiateAuthorizationRequest]: {
|
|
688
721
|
id: OID4VCIMachineStates.initiateAuthorizationRequest,
|
|
689
722
|
on: {
|
|
@@ -976,131 +1009,417 @@ var OID4VCIMachine = class {
|
|
|
976
1009
|
|
|
977
1010
|
// src/services/OID4VCIHolderService.ts
|
|
978
1011
|
import { LOG } from "@sphereon/oid4vci-client";
|
|
979
|
-
import { getSupportedCredentials, getTypesFromCredentialSupported, getTypesFromObject
|
|
1012
|
+
import { getSupportedCredentials, getTypesFromCredentialSupported, getTypesFromObject } from "@sphereon/oid4vci-common";
|
|
980
1013
|
import { KeyUse } from "@sphereon/ssi-sdk-ext.did-resolver-jwk";
|
|
981
1014
|
import { getOrCreatePrimaryIdentifier, SupportedDidMethodEnum } from "@sphereon/ssi-sdk-ext.did-utils";
|
|
982
1015
|
import { isIIdentifier, isManagedIdentifierDidResult, isManagedIdentifierResult, managedIdentifierToJwk } from "@sphereon/ssi-sdk-ext.identifier-resolution";
|
|
983
1016
|
import { keyTypeFromCryptographicSuite } from "@sphereon/ssi-sdk-ext.key-utils";
|
|
1017
|
+
import { defaultHasher } from "@sphereon/ssi-sdk.core";
|
|
984
1018
|
import { CredentialMapper, JoseSignatureAlgorithm, mdocDecodedCredentialToUniformCredential, sdJwtDecodedCredentialToUniformCredential } from "@sphereon/ssi-types";
|
|
985
1019
|
import { asArray } from "@veramo/utils";
|
|
986
1020
|
|
|
987
|
-
// src/
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
credentialDisplay
|
|
999
|
-
})
|
|
1000
|
-
}
|
|
1021
|
+
// src/machines/firstPartyMachine.ts
|
|
1022
|
+
import { assign as assign2, createMachine as createMachine2, interpret as interpret2 } from "xstate";
|
|
1023
|
+
import { AuthorizationChallengeError } from "@sphereon/oid4vci-common";
|
|
1024
|
+
|
|
1025
|
+
// src/services/FirstPartyMachineServices.ts
|
|
1026
|
+
import { OpenID4VCIClient } from "@sphereon/oid4vci-client";
|
|
1027
|
+
import { v4 as uuidv4 } from "uuid";
|
|
1028
|
+
var sendAuthorizationChallengeRequest = /* @__PURE__ */ __name(async (args) => {
|
|
1029
|
+
const { openID4VCIClientState, authSession, presentationDuringIssuanceSession } = args;
|
|
1030
|
+
const oid4vciClient = await OpenID4VCIClient.fromState({
|
|
1031
|
+
state: openID4VCIClientState
|
|
1001
1032
|
});
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
const localeKey = display.locale || "";
|
|
1007
|
-
localeDisplays.set(localeKey, display);
|
|
1008
|
-
return localeDisplays;
|
|
1009
|
-
}, /* @__PURE__ */ new Map());
|
|
1010
|
-
}, "oid4vciCredentialDisplayLocalesFrom");
|
|
1011
|
-
var oid4vciIssuerCredentialSubjectLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1012
|
-
const { issuerCredentialSubject } = args;
|
|
1013
|
-
const localeClaims = /* @__PURE__ */ new Map();
|
|
1014
|
-
const processClaimObject = /* @__PURE__ */ __name((claim, parentKey = "") => {
|
|
1015
|
-
Object.entries(claim).forEach(([key, value]) => {
|
|
1016
|
-
if (key === "mandatory" || key === "value_type") {
|
|
1017
|
-
return;
|
|
1018
|
-
}
|
|
1019
|
-
if (key === "display" && Array.isArray(value)) {
|
|
1020
|
-
value.forEach(({ name, locale = "" }) => {
|
|
1021
|
-
if (!name) {
|
|
1022
|
-
return;
|
|
1023
|
-
}
|
|
1024
|
-
if (!localeClaims.has(locale)) {
|
|
1025
|
-
localeClaims.set(locale, []);
|
|
1026
|
-
}
|
|
1027
|
-
localeClaims.get(locale).push({
|
|
1028
|
-
key: parentKey,
|
|
1029
|
-
name
|
|
1030
|
-
});
|
|
1031
|
-
});
|
|
1032
|
-
} else if (typeof value === "object" && value !== null) {
|
|
1033
|
-
processClaimObject(value, parentKey ? `${parentKey}.${key}` : key);
|
|
1034
|
-
}
|
|
1035
|
-
});
|
|
1036
|
-
}, "processClaimObject");
|
|
1037
|
-
processClaimObject(issuerCredentialSubject);
|
|
1038
|
-
return localeClaims;
|
|
1039
|
-
}, "oid4vciIssuerCredentialSubjectLocalesFrom");
|
|
1040
|
-
var oid4vciCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1041
|
-
const { credentialDisplay } = args;
|
|
1042
|
-
return {
|
|
1043
|
-
...credentialDisplay.name && {
|
|
1044
|
-
alias: credentialDisplay.name
|
|
1045
|
-
},
|
|
1046
|
-
...credentialDisplay.locale && {
|
|
1047
|
-
locale: credentialDisplay.locale
|
|
1048
|
-
},
|
|
1049
|
-
...credentialDisplay.logo && {
|
|
1050
|
-
logo: {
|
|
1051
|
-
...(credentialDisplay.logo.url || credentialDisplay.logo.uri) && {
|
|
1052
|
-
uri: credentialDisplay.logo?.url ?? credentialDisplay.logo.uri
|
|
1053
|
-
},
|
|
1054
|
-
...credentialDisplay.logo.alt_text && {
|
|
1055
|
-
alt: credentialDisplay.logo?.alt_text
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1033
|
+
return oid4vciClient.acquireAuthorizationChallengeCode({
|
|
1034
|
+
clientId: oid4vciClient.clientId ?? uuidv4(),
|
|
1035
|
+
...authSession && {
|
|
1036
|
+
authSession
|
|
1058
1037
|
},
|
|
1059
|
-
|
|
1060
|
-
|
|
1038
|
+
...!authSession && openID4VCIClientState.credentialOffer?.preAuthorizedCode && {
|
|
1039
|
+
issuerState: openID4VCIClientState.credentialOffer?.preAuthorizedCode
|
|
1061
1040
|
},
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
color: credentialDisplay.text_color
|
|
1065
|
-
}
|
|
1041
|
+
...!authSession && openID4VCIClientState.credentialOffer?.issuerState && {
|
|
1042
|
+
issuerState: openID4VCIClientState.credentialOffer?.issuerState
|
|
1066
1043
|
},
|
|
1067
|
-
...
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1044
|
+
...presentationDuringIssuanceSession && {
|
|
1045
|
+
presentationDuringIssuanceSession
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
}, "sendAuthorizationChallengeRequest");
|
|
1049
|
+
var createConfig = /* @__PURE__ */ __name(async (args, context) => {
|
|
1050
|
+
const { presentationUri } = args;
|
|
1051
|
+
if (!presentationUri) {
|
|
1052
|
+
return Promise.reject(Error("Missing presentation uri in context"));
|
|
1053
|
+
}
|
|
1054
|
+
return context.agent.siopCreateConfig({
|
|
1055
|
+
url: presentationUri
|
|
1056
|
+
});
|
|
1057
|
+
}, "createConfig");
|
|
1058
|
+
var getSiopRequest = /* @__PURE__ */ __name(async (args, context) => {
|
|
1059
|
+
const { didAuthConfig, presentationUri } = args;
|
|
1060
|
+
if (presentationUri === void 0) {
|
|
1061
|
+
return Promise.reject(Error("Missing presentation uri in context"));
|
|
1062
|
+
}
|
|
1063
|
+
if (didAuthConfig === void 0) {
|
|
1064
|
+
return Promise.reject(Error("Missing did auth config in context"));
|
|
1065
|
+
}
|
|
1066
|
+
return context.agent.siopGetSiopRequest({
|
|
1067
|
+
didAuthConfig,
|
|
1068
|
+
url: presentationUri
|
|
1069
|
+
});
|
|
1070
|
+
}, "getSiopRequest");
|
|
1071
|
+
var sendAuthorizationResponse = /* @__PURE__ */ __name(async (args, context) => {
|
|
1072
|
+
const { didAuthConfig, authorizationRequestData, selectedCredentials } = args;
|
|
1073
|
+
const responseData = await context.agent.siopSendResponse({
|
|
1074
|
+
authorizationRequestData,
|
|
1075
|
+
selectedCredentials,
|
|
1076
|
+
didAuthConfig,
|
|
1077
|
+
isFirstParty: true
|
|
1078
|
+
});
|
|
1079
|
+
return responseData.body.presentation_during_issuance_session;
|
|
1080
|
+
}, "sendAuthorizationResponse");
|
|
1081
|
+
|
|
1082
|
+
// src/machines/firstPartyMachine.ts
|
|
1083
|
+
var firstPartyMachineStates = {
|
|
1084
|
+
[FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest]: {
|
|
1085
|
+
id: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
|
|
1086
|
+
invoke: {
|
|
1087
|
+
src: FirstPartyMachineServices.sendAuthorizationChallengeRequest,
|
|
1088
|
+
onDone: {
|
|
1089
|
+
target: FirstPartyMachineStateTypes.done,
|
|
1090
|
+
actions: assign2({
|
|
1091
|
+
authorizationCodeResponse: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationCodeResponse")
|
|
1092
|
+
})
|
|
1093
|
+
},
|
|
1094
|
+
onError: [
|
|
1095
|
+
{
|
|
1096
|
+
target: FirstPartyMachineStateTypes.createConfig,
|
|
1097
|
+
cond: /* @__PURE__ */ __name((_ctx, _event) => _event.data.error === AuthorizationChallengeError.insufficient_authorization, "cond"),
|
|
1098
|
+
actions: assign2({
|
|
1099
|
+
authSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data.auth_session, "authSession"),
|
|
1100
|
+
presentationUri: /* @__PURE__ */ __name((_ctx, _event) => _event.data.presentation, "presentationUri")
|
|
1101
|
+
})
|
|
1078
1102
|
},
|
|
1079
|
-
|
|
1080
|
-
|
|
1103
|
+
{
|
|
1104
|
+
target: FirstPartyMachineStateTypes.error,
|
|
1105
|
+
actions: assign2({
|
|
1106
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1107
|
+
title: translate("oid4vci_machine_send_authorization_challenge_request_error_title"),
|
|
1108
|
+
message: _event.data.message,
|
|
1109
|
+
stack: _event.data.stack
|
|
1110
|
+
}), "error")
|
|
1111
|
+
})
|
|
1081
1112
|
}
|
|
1113
|
+
]
|
|
1114
|
+
}
|
|
1115
|
+
},
|
|
1116
|
+
[FirstPartyMachineStateTypes.createConfig]: {
|
|
1117
|
+
id: FirstPartyMachineStateTypes.createConfig,
|
|
1118
|
+
invoke: {
|
|
1119
|
+
src: FirstPartyMachineServices.createConfig,
|
|
1120
|
+
onDone: {
|
|
1121
|
+
target: FirstPartyMachineStateTypes.getSiopRequest,
|
|
1122
|
+
actions: assign2({
|
|
1123
|
+
didAuthConfig: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "didAuthConfig")
|
|
1124
|
+
})
|
|
1125
|
+
},
|
|
1126
|
+
onError: {
|
|
1127
|
+
target: FirstPartyMachineStateTypes.error,
|
|
1128
|
+
actions: assign2({
|
|
1129
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1130
|
+
title: translate("oid4vci_machine_create_config_error_title"),
|
|
1131
|
+
message: _event.data.message,
|
|
1132
|
+
stack: _event.data.stack
|
|
1133
|
+
}), "error")
|
|
1134
|
+
})
|
|
1082
1135
|
}
|
|
1083
1136
|
}
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
const claims = issuerCredentialSubjectLocales.get(locale);
|
|
1095
|
-
return {
|
|
1096
|
-
...display && await oid4vciCredentialLocaleBrandingFrom({
|
|
1097
|
-
credentialDisplay: display
|
|
1098
|
-
}),
|
|
1099
|
-
...locale.length > 0 && {
|
|
1100
|
-
locale
|
|
1137
|
+
},
|
|
1138
|
+
[FirstPartyMachineStateTypes.getSiopRequest]: {
|
|
1139
|
+
id: FirstPartyMachineStateTypes.getSiopRequest,
|
|
1140
|
+
invoke: {
|
|
1141
|
+
src: FirstPartyMachineServices.getSiopRequest,
|
|
1142
|
+
onDone: {
|
|
1143
|
+
target: FirstPartyMachineStateTypes.selectCredentials,
|
|
1144
|
+
actions: assign2({
|
|
1145
|
+
authorizationRequestData: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationRequestData")
|
|
1146
|
+
})
|
|
1101
1147
|
},
|
|
1102
|
-
|
|
1103
|
-
|
|
1148
|
+
onError: {
|
|
1149
|
+
target: FirstPartyMachineStateTypes.error,
|
|
1150
|
+
actions: assign2({
|
|
1151
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1152
|
+
title: translate("siopV2_machine_get_request_error_title"),
|
|
1153
|
+
message: _event.data.message,
|
|
1154
|
+
stack: _event.data.stack
|
|
1155
|
+
}), "error")
|
|
1156
|
+
})
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
},
|
|
1160
|
+
[FirstPartyMachineStateTypes.selectCredentials]: {
|
|
1161
|
+
id: FirstPartyMachineStateTypes.selectCredentials,
|
|
1162
|
+
on: {
|
|
1163
|
+
[FirstPartyMachineEvents.SET_SELECTED_CREDENTIALS]: {
|
|
1164
|
+
actions: assign2({
|
|
1165
|
+
selectedCredentials: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectedCredentials")
|
|
1166
|
+
})
|
|
1167
|
+
},
|
|
1168
|
+
[FirstPartyMachineEvents.NEXT]: {
|
|
1169
|
+
target: FirstPartyMachineStateTypes.sendAuthorizationResponse
|
|
1170
|
+
},
|
|
1171
|
+
[FirstPartyMachineEvents.DECLINE]: {
|
|
1172
|
+
target: FirstPartyMachineStateTypes.declined
|
|
1173
|
+
},
|
|
1174
|
+
[FirstPartyMachineEvents.PREVIOUS]: {
|
|
1175
|
+
target: FirstPartyMachineStateTypes.aborted
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
},
|
|
1179
|
+
[FirstPartyMachineStateTypes.sendAuthorizationResponse]: {
|
|
1180
|
+
id: FirstPartyMachineStateTypes.sendAuthorizationResponse,
|
|
1181
|
+
invoke: {
|
|
1182
|
+
src: FirstPartyMachineServices.sendAuthorizationResponse,
|
|
1183
|
+
onDone: {
|
|
1184
|
+
target: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
|
|
1185
|
+
actions: assign2({
|
|
1186
|
+
presentationDuringIssuanceSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "presentationDuringIssuanceSession")
|
|
1187
|
+
})
|
|
1188
|
+
},
|
|
1189
|
+
onError: {
|
|
1190
|
+
target: FirstPartyMachineStateTypes.error,
|
|
1191
|
+
actions: assign2({
|
|
1192
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1193
|
+
title: translate("oid4vci_machine_get_request_error_title"),
|
|
1194
|
+
message: _event.data.message,
|
|
1195
|
+
stack: _event.data.stack
|
|
1196
|
+
}), "error")
|
|
1197
|
+
})
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
},
|
|
1201
|
+
[FirstPartyMachineStateTypes.aborted]: {
|
|
1202
|
+
id: FirstPartyMachineStateTypes.aborted,
|
|
1203
|
+
type: "final"
|
|
1204
|
+
},
|
|
1205
|
+
[FirstPartyMachineStateTypes.declined]: {
|
|
1206
|
+
id: FirstPartyMachineStateTypes.declined,
|
|
1207
|
+
type: "final"
|
|
1208
|
+
},
|
|
1209
|
+
[FirstPartyMachineStateTypes.error]: {
|
|
1210
|
+
id: FirstPartyMachineStateTypes.error,
|
|
1211
|
+
type: "final"
|
|
1212
|
+
},
|
|
1213
|
+
[FirstPartyMachineStateTypes.done]: {
|
|
1214
|
+
id: FirstPartyMachineStateTypes.done,
|
|
1215
|
+
type: "final"
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1218
|
+
var createFirstPartyActivationMachine = /* @__PURE__ */ __name((opts) => {
|
|
1219
|
+
const initialContext = {
|
|
1220
|
+
openID4VCIClientState: opts.openID4VCIClientState,
|
|
1221
|
+
contact: opts.contact,
|
|
1222
|
+
selectedCredentials: []
|
|
1223
|
+
};
|
|
1224
|
+
return createMachine2({
|
|
1225
|
+
id: opts?.machineId ?? "FirstParty",
|
|
1226
|
+
predictableActionArguments: true,
|
|
1227
|
+
initial: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
|
|
1228
|
+
context: initialContext,
|
|
1229
|
+
states: firstPartyMachineStates,
|
|
1230
|
+
schema: {
|
|
1231
|
+
events: {},
|
|
1232
|
+
services: {}
|
|
1233
|
+
}
|
|
1234
|
+
});
|
|
1235
|
+
}, "createFirstPartyActivationMachine");
|
|
1236
|
+
var FirstPartyMachine = class _FirstPartyMachine {
|
|
1237
|
+
static {
|
|
1238
|
+
__name(this, "FirstPartyMachine");
|
|
1239
|
+
}
|
|
1240
|
+
static _instance;
|
|
1241
|
+
static hasInstance() {
|
|
1242
|
+
return _FirstPartyMachine._instance !== void 0;
|
|
1243
|
+
}
|
|
1244
|
+
static get instance() {
|
|
1245
|
+
if (!_FirstPartyMachine._instance) {
|
|
1246
|
+
throw Error("Please initialize ESIMActivation machine first");
|
|
1247
|
+
}
|
|
1248
|
+
return _FirstPartyMachine._instance;
|
|
1249
|
+
}
|
|
1250
|
+
static clearInstance(opts) {
|
|
1251
|
+
const { stop } = opts;
|
|
1252
|
+
if (_FirstPartyMachine.hasInstance()) {
|
|
1253
|
+
if (stop) {
|
|
1254
|
+
_FirstPartyMachine.stopInstance();
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
_FirstPartyMachine._instance = void 0;
|
|
1258
|
+
}
|
|
1259
|
+
static stopInstance() {
|
|
1260
|
+
if (!_FirstPartyMachine.hasInstance()) {
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
_FirstPartyMachine.instance.stop();
|
|
1264
|
+
_FirstPartyMachine._instance = void 0;
|
|
1265
|
+
}
|
|
1266
|
+
static newInstance(opts) {
|
|
1267
|
+
const { agentContext } = opts;
|
|
1268
|
+
const services = {
|
|
1269
|
+
[FirstPartyMachineServices.sendAuthorizationChallengeRequest]: sendAuthorizationChallengeRequest,
|
|
1270
|
+
[FirstPartyMachineServices.createConfig]: (args) => createConfig(args, agentContext),
|
|
1271
|
+
[FirstPartyMachineServices.getSiopRequest]: (args) => getSiopRequest(args, agentContext),
|
|
1272
|
+
[FirstPartyMachineServices.sendAuthorizationResponse]: (args) => sendAuthorizationResponse(args, agentContext)
|
|
1273
|
+
};
|
|
1274
|
+
const newInst = interpret2(createFirstPartyActivationMachine(opts).withConfig({
|
|
1275
|
+
services: {
|
|
1276
|
+
...services,
|
|
1277
|
+
...opts?.services
|
|
1278
|
+
},
|
|
1279
|
+
guards: {
|
|
1280
|
+
...opts?.guards
|
|
1281
|
+
}
|
|
1282
|
+
}));
|
|
1283
|
+
if (typeof opts?.subscription === "function") {
|
|
1284
|
+
newInst.onTransition(opts.subscription);
|
|
1285
|
+
}
|
|
1286
|
+
if (opts?.requireCustomNavigationHook !== true) {
|
|
1287
|
+
newInst.onTransition((snapshot) => {
|
|
1288
|
+
if (opts?.stateNavigationListener) {
|
|
1289
|
+
void opts.stateNavigationListener(newInst, snapshot);
|
|
1290
|
+
}
|
|
1291
|
+
});
|
|
1292
|
+
}
|
|
1293
|
+
return newInst;
|
|
1294
|
+
}
|
|
1295
|
+
static getInstance(opts) {
|
|
1296
|
+
if (!_FirstPartyMachine._instance) {
|
|
1297
|
+
if (opts?.requireExisting === true) {
|
|
1298
|
+
throw Error(`Existing FirstPartyMachine instance requested, but none was created at this point!`);
|
|
1299
|
+
}
|
|
1300
|
+
_FirstPartyMachine._instance = _FirstPartyMachine.newInstance(opts);
|
|
1301
|
+
}
|
|
1302
|
+
return _FirstPartyMachine._instance;
|
|
1303
|
+
}
|
|
1304
|
+
};
|
|
1305
|
+
|
|
1306
|
+
// src/mappers/OIDC4VCIBrandingMapper.ts
|
|
1307
|
+
var oid4vciGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1308
|
+
const { credentialDisplay, issuerCredentialSubject } = args;
|
|
1309
|
+
return oid4vciCombineDisplayLocalesFrom({
|
|
1310
|
+
...issuerCredentialSubject && {
|
|
1311
|
+
issuerCredentialSubjectLocales: await oid4vciIssuerCredentialSubjectLocalesFrom({
|
|
1312
|
+
issuerCredentialSubject
|
|
1313
|
+
})
|
|
1314
|
+
},
|
|
1315
|
+
...credentialDisplay && {
|
|
1316
|
+
credentialDisplayLocales: await oid4vciCredentialDisplayLocalesFrom({
|
|
1317
|
+
credentialDisplay
|
|
1318
|
+
})
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1321
|
+
}, "oid4vciGetCredentialBrandingFrom");
|
|
1322
|
+
var oid4vciCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1323
|
+
const { credentialDisplay } = args;
|
|
1324
|
+
return credentialDisplay.reduce((localeDisplays, display) => {
|
|
1325
|
+
const localeKey = display.locale || "";
|
|
1326
|
+
localeDisplays.set(localeKey, display);
|
|
1327
|
+
return localeDisplays;
|
|
1328
|
+
}, /* @__PURE__ */ new Map());
|
|
1329
|
+
}, "oid4vciCredentialDisplayLocalesFrom");
|
|
1330
|
+
var oid4vciIssuerCredentialSubjectLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1331
|
+
const { issuerCredentialSubject } = args;
|
|
1332
|
+
const localeClaims = /* @__PURE__ */ new Map();
|
|
1333
|
+
const processClaimObject = /* @__PURE__ */ __name((claim, parentKey = "") => {
|
|
1334
|
+
Object.entries(claim).forEach(([key, value]) => {
|
|
1335
|
+
if (key === "mandatory" || key === "value_type") {
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
if (key === "display" && Array.isArray(value)) {
|
|
1339
|
+
value.forEach(({ name, locale = "" }) => {
|
|
1340
|
+
if (!name) {
|
|
1341
|
+
return;
|
|
1342
|
+
}
|
|
1343
|
+
if (!localeClaims.has(locale)) {
|
|
1344
|
+
localeClaims.set(locale, []);
|
|
1345
|
+
}
|
|
1346
|
+
localeClaims.get(locale).push({
|
|
1347
|
+
key: parentKey,
|
|
1348
|
+
name
|
|
1349
|
+
});
|
|
1350
|
+
});
|
|
1351
|
+
} else if (typeof value === "object" && value !== null) {
|
|
1352
|
+
processClaimObject(value, parentKey ? `${parentKey}.${key}` : key);
|
|
1353
|
+
}
|
|
1354
|
+
});
|
|
1355
|
+
}, "processClaimObject");
|
|
1356
|
+
processClaimObject(issuerCredentialSubject);
|
|
1357
|
+
return localeClaims;
|
|
1358
|
+
}, "oid4vciIssuerCredentialSubjectLocalesFrom");
|
|
1359
|
+
var oid4vciCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1360
|
+
const { credentialDisplay } = args;
|
|
1361
|
+
return {
|
|
1362
|
+
...credentialDisplay.name && {
|
|
1363
|
+
alias: credentialDisplay.name
|
|
1364
|
+
},
|
|
1365
|
+
...credentialDisplay.locale && {
|
|
1366
|
+
locale: credentialDisplay.locale
|
|
1367
|
+
},
|
|
1368
|
+
...credentialDisplay.logo && {
|
|
1369
|
+
logo: {
|
|
1370
|
+
...(credentialDisplay.logo.url || credentialDisplay.logo.uri) && {
|
|
1371
|
+
uri: credentialDisplay.logo?.url ?? credentialDisplay.logo.uri
|
|
1372
|
+
},
|
|
1373
|
+
...credentialDisplay.logo.alt_text && {
|
|
1374
|
+
alt: credentialDisplay.logo?.alt_text
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
},
|
|
1378
|
+
...credentialDisplay.description && {
|
|
1379
|
+
description: credentialDisplay.description
|
|
1380
|
+
},
|
|
1381
|
+
...credentialDisplay.text_color && {
|
|
1382
|
+
text: {
|
|
1383
|
+
color: credentialDisplay.text_color
|
|
1384
|
+
}
|
|
1385
|
+
},
|
|
1386
|
+
...(credentialDisplay.background_image || credentialDisplay.background_color) && {
|
|
1387
|
+
background: {
|
|
1388
|
+
...credentialDisplay.background_image && {
|
|
1389
|
+
image: {
|
|
1390
|
+
...(credentialDisplay.background_image.url || credentialDisplay.background_image.uri) && {
|
|
1391
|
+
uri: credentialDisplay.background_image?.url ?? credentialDisplay.background_image.uri
|
|
1392
|
+
},
|
|
1393
|
+
...credentialDisplay.background_image.alt_text && {
|
|
1394
|
+
alt: credentialDisplay.background_image?.alt_text
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
},
|
|
1398
|
+
...credentialDisplay.background_color && {
|
|
1399
|
+
color: credentialDisplay.background_color
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
}, "oid4vciCredentialLocaleBrandingFrom");
|
|
1405
|
+
var oid4vciCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1406
|
+
const { credentialDisplayLocales = /* @__PURE__ */ new Map(), issuerCredentialSubjectLocales = /* @__PURE__ */ new Map() } = args;
|
|
1407
|
+
const locales = Array.from(/* @__PURE__ */ new Set([
|
|
1408
|
+
...issuerCredentialSubjectLocales.keys(),
|
|
1409
|
+
...credentialDisplayLocales.keys()
|
|
1410
|
+
]));
|
|
1411
|
+
return Promise.all(locales.map(async (locale) => {
|
|
1412
|
+
const display = credentialDisplayLocales.get(locale);
|
|
1413
|
+
const claims = issuerCredentialSubjectLocales.get(locale);
|
|
1414
|
+
return {
|
|
1415
|
+
...display && await oid4vciCredentialLocaleBrandingFrom({
|
|
1416
|
+
credentialDisplay: display
|
|
1417
|
+
}),
|
|
1418
|
+
...locale.length > 0 && {
|
|
1419
|
+
locale
|
|
1420
|
+
},
|
|
1421
|
+
claims
|
|
1422
|
+
};
|
|
1104
1423
|
}));
|
|
1105
1424
|
}, "oid4vciCombineDisplayLocalesFrom");
|
|
1106
1425
|
var sdJwtGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
@@ -1159,386 +1478,100 @@ var sdJwtCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
|
1159
1478
|
uri: credentialDisplay.rendering.simple.logo.uri
|
|
1160
1479
|
},
|
|
1161
1480
|
...credentialDisplay.rendering.simple.logo.alt_text && {
|
|
1162
|
-
alt: credentialDisplay.rendering.simple.logo.alt_text
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
},
|
|
1166
|
-
...credentialDisplay.description && {
|
|
1167
|
-
description: credentialDisplay.description
|
|
1168
|
-
},
|
|
1169
|
-
...credentialDisplay.rendering?.simple?.text_color && {
|
|
1170
|
-
text: {
|
|
1171
|
-
color: credentialDisplay.rendering.simple.text_color
|
|
1172
|
-
}
|
|
1173
|
-
},
|
|
1174
|
-
...credentialDisplay.rendering?.simple?.background_color && {
|
|
1175
|
-
background: {
|
|
1176
|
-
color: credentialDisplay.rendering.simple.background_color
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
};
|
|
1180
|
-
}, "sdJwtCredentialLocaleBrandingFrom");
|
|
1181
|
-
var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1182
|
-
const { credentialDisplayLocales = /* @__PURE__ */ new Map(), claimsMetadata = /* @__PURE__ */ new Map() } = args;
|
|
1183
|
-
const locales = Array.from(/* @__PURE__ */ new Set([
|
|
1184
|
-
...claimsMetadata.keys(),
|
|
1185
|
-
...credentialDisplayLocales.keys()
|
|
1186
|
-
]));
|
|
1187
|
-
return Promise.all(locales.map(async (locale) => {
|
|
1188
|
-
const display = credentialDisplayLocales.get(locale);
|
|
1189
|
-
const claims = claimsMetadata.get(locale);
|
|
1190
|
-
return {
|
|
1191
|
-
...display && await sdJwtCredentialLocaleBrandingFrom({
|
|
1192
|
-
credentialDisplay: display
|
|
1193
|
-
}),
|
|
1194
|
-
...locale.length > 0 && {
|
|
1195
|
-
locale
|
|
1196
|
-
},
|
|
1197
|
-
claims
|
|
1198
|
-
};
|
|
1199
|
-
}));
|
|
1200
|
-
}, "sdJwtCombineDisplayLocalesFrom");
|
|
1201
|
-
var issuerLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1202
|
-
const { issuerDisplay, dynamicRegistrationClientMetadata } = args;
|
|
1203
|
-
return {
|
|
1204
|
-
...dynamicRegistrationClientMetadata?.client_name && {
|
|
1205
|
-
alias: dynamicRegistrationClientMetadata.client_name
|
|
1206
|
-
},
|
|
1207
|
-
...issuerDisplay.name && {
|
|
1208
|
-
alias: issuerDisplay.name
|
|
1209
|
-
},
|
|
1210
|
-
...issuerDisplay.locale && {
|
|
1211
|
-
locale: issuerDisplay.locale
|
|
1212
|
-
},
|
|
1213
|
-
...(issuerDisplay.logo || dynamicRegistrationClientMetadata?.logo_uri) && {
|
|
1214
|
-
logo: {
|
|
1215
|
-
...dynamicRegistrationClientMetadata?.logo_uri && {
|
|
1216
|
-
uri: dynamicRegistrationClientMetadata?.logo_uri
|
|
1217
|
-
},
|
|
1218
|
-
...(issuerDisplay.logo?.url || issuerDisplay.logo?.uri) && {
|
|
1219
|
-
uri: issuerDisplay.logo?.url ?? issuerDisplay.logo?.uri
|
|
1220
|
-
},
|
|
1221
|
-
...issuerDisplay.logo?.alt_text && {
|
|
1222
|
-
alt: issuerDisplay.logo?.alt_text
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
},
|
|
1226
|
-
...issuerDisplay.description && {
|
|
1227
|
-
description: issuerDisplay.description
|
|
1228
|
-
},
|
|
1229
|
-
...issuerDisplay.text_color && {
|
|
1230
|
-
text: {
|
|
1231
|
-
color: issuerDisplay.text_color
|
|
1232
|
-
}
|
|
1233
|
-
},
|
|
1234
|
-
...dynamicRegistrationClientMetadata?.client_uri && {
|
|
1235
|
-
clientUri: dynamicRegistrationClientMetadata.client_uri
|
|
1236
|
-
},
|
|
1237
|
-
...dynamicRegistrationClientMetadata?.tos_uri && {
|
|
1238
|
-
tosUri: dynamicRegistrationClientMetadata.tos_uri
|
|
1239
|
-
},
|
|
1240
|
-
...dynamicRegistrationClientMetadata?.policy_uri && {
|
|
1241
|
-
policyUri: dynamicRegistrationClientMetadata.policy_uri
|
|
1242
|
-
},
|
|
1243
|
-
...dynamicRegistrationClientMetadata?.contacts && {
|
|
1244
|
-
contacts: dynamicRegistrationClientMetadata.contacts
|
|
1245
|
-
}
|
|
1246
|
-
};
|
|
1247
|
-
}, "issuerLocaleBrandingFrom");
|
|
1248
|
-
|
|
1249
|
-
// src/machines/firstPartyMachine.ts
|
|
1250
|
-
import { assign as assign2, createMachine as createMachine2, interpret as interpret2 } from "xstate";
|
|
1251
|
-
import { AuthorizationChallengeError } from "@sphereon/oid4vci-common";
|
|
1252
|
-
|
|
1253
|
-
// src/services/FirstPartyMachineServices.ts
|
|
1254
|
-
import { OpenID4VCIClient } from "@sphereon/oid4vci-client";
|
|
1255
|
-
import { v4 as uuidv4 } from "uuid";
|
|
1256
|
-
var sendAuthorizationChallengeRequest = /* @__PURE__ */ __name(async (args) => {
|
|
1257
|
-
const { openID4VCIClientState, authSession, presentationDuringIssuanceSession } = args;
|
|
1258
|
-
const oid4vciClient = await OpenID4VCIClient.fromState({
|
|
1259
|
-
state: openID4VCIClientState
|
|
1260
|
-
});
|
|
1261
|
-
return oid4vciClient.acquireAuthorizationChallengeCode({
|
|
1262
|
-
clientId: oid4vciClient.clientId ?? uuidv4(),
|
|
1263
|
-
...authSession && {
|
|
1264
|
-
authSession
|
|
1265
|
-
},
|
|
1266
|
-
...!authSession && openID4VCIClientState.credentialOffer?.preAuthorizedCode && {
|
|
1267
|
-
issuerState: openID4VCIClientState.credentialOffer?.preAuthorizedCode
|
|
1268
|
-
},
|
|
1269
|
-
...!authSession && openID4VCIClientState.credentialOffer?.issuerState && {
|
|
1270
|
-
issuerState: openID4VCIClientState.credentialOffer?.issuerState
|
|
1271
|
-
},
|
|
1272
|
-
...presentationDuringIssuanceSession && {
|
|
1273
|
-
presentationDuringIssuanceSession
|
|
1274
|
-
}
|
|
1275
|
-
});
|
|
1276
|
-
}, "sendAuthorizationChallengeRequest");
|
|
1277
|
-
var createConfig = /* @__PURE__ */ __name(async (args, context) => {
|
|
1278
|
-
const { presentationUri } = args;
|
|
1279
|
-
if (!presentationUri) {
|
|
1280
|
-
return Promise.reject(Error("Missing presentation uri in context"));
|
|
1281
|
-
}
|
|
1282
|
-
return context.agent.siopCreateConfig({
|
|
1283
|
-
url: presentationUri
|
|
1284
|
-
});
|
|
1285
|
-
}, "createConfig");
|
|
1286
|
-
var getSiopRequest = /* @__PURE__ */ __name(async (args, context) => {
|
|
1287
|
-
const { didAuthConfig, presentationUri } = args;
|
|
1288
|
-
if (presentationUri === void 0) {
|
|
1289
|
-
return Promise.reject(Error("Missing presentation uri in context"));
|
|
1290
|
-
}
|
|
1291
|
-
if (didAuthConfig === void 0) {
|
|
1292
|
-
return Promise.reject(Error("Missing did auth config in context"));
|
|
1293
|
-
}
|
|
1294
|
-
return context.agent.siopGetSiopRequest({
|
|
1295
|
-
didAuthConfig,
|
|
1296
|
-
url: presentationUri
|
|
1297
|
-
});
|
|
1298
|
-
}, "getSiopRequest");
|
|
1299
|
-
var sendAuthorizationResponse = /* @__PURE__ */ __name(async (args, context) => {
|
|
1300
|
-
const { didAuthConfig, authorizationRequestData, selectedCredentials } = args;
|
|
1301
|
-
const responseData = await context.agent.siopSendResponse({
|
|
1302
|
-
authorizationRequestData,
|
|
1303
|
-
selectedCredentials,
|
|
1304
|
-
didAuthConfig,
|
|
1305
|
-
isFirstParty: true
|
|
1306
|
-
});
|
|
1307
|
-
return responseData.body.presentation_during_issuance_session;
|
|
1308
|
-
}, "sendAuthorizationResponse");
|
|
1309
|
-
|
|
1310
|
-
// src/machines/firstPartyMachine.ts
|
|
1311
|
-
var firstPartyMachineStates = {
|
|
1312
|
-
[FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest]: {
|
|
1313
|
-
id: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
|
|
1314
|
-
invoke: {
|
|
1315
|
-
src: FirstPartyMachineServices.sendAuthorizationChallengeRequest,
|
|
1316
|
-
onDone: {
|
|
1317
|
-
target: FirstPartyMachineStateTypes.done,
|
|
1318
|
-
actions: assign2({
|
|
1319
|
-
authorizationCodeResponse: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationCodeResponse")
|
|
1320
|
-
})
|
|
1321
|
-
},
|
|
1322
|
-
onError: [
|
|
1323
|
-
{
|
|
1324
|
-
target: FirstPartyMachineStateTypes.createConfig,
|
|
1325
|
-
cond: /* @__PURE__ */ __name((_ctx, _event) => _event.data.error === AuthorizationChallengeError.insufficient_authorization, "cond"),
|
|
1326
|
-
actions: assign2({
|
|
1327
|
-
authSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data.auth_session, "authSession"),
|
|
1328
|
-
presentationUri: /* @__PURE__ */ __name((_ctx, _event) => _event.data.presentation, "presentationUri")
|
|
1329
|
-
})
|
|
1330
|
-
},
|
|
1331
|
-
{
|
|
1332
|
-
target: FirstPartyMachineStateTypes.error,
|
|
1333
|
-
actions: assign2({
|
|
1334
|
-
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1335
|
-
title: translate("oid4vci_machine_send_authorization_challenge_request_error_title"),
|
|
1336
|
-
message: _event.data.message,
|
|
1337
|
-
stack: _event.data.stack
|
|
1338
|
-
}), "error")
|
|
1339
|
-
})
|
|
1340
|
-
}
|
|
1341
|
-
]
|
|
1342
|
-
}
|
|
1343
|
-
},
|
|
1344
|
-
[FirstPartyMachineStateTypes.createConfig]: {
|
|
1345
|
-
id: FirstPartyMachineStateTypes.createConfig,
|
|
1346
|
-
invoke: {
|
|
1347
|
-
src: FirstPartyMachineServices.createConfig,
|
|
1348
|
-
onDone: {
|
|
1349
|
-
target: FirstPartyMachineStateTypes.getSiopRequest,
|
|
1350
|
-
actions: assign2({
|
|
1351
|
-
didAuthConfig: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "didAuthConfig")
|
|
1352
|
-
})
|
|
1353
|
-
},
|
|
1354
|
-
onError: {
|
|
1355
|
-
target: FirstPartyMachineStateTypes.error,
|
|
1356
|
-
actions: assign2({
|
|
1357
|
-
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1358
|
-
title: translate("oid4vci_machine_create_config_error_title"),
|
|
1359
|
-
message: _event.data.message,
|
|
1360
|
-
stack: _event.data.stack
|
|
1361
|
-
}), "error")
|
|
1362
|
-
})
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
},
|
|
1366
|
-
[FirstPartyMachineStateTypes.getSiopRequest]: {
|
|
1367
|
-
id: FirstPartyMachineStateTypes.getSiopRequest,
|
|
1368
|
-
invoke: {
|
|
1369
|
-
src: FirstPartyMachineServices.getSiopRequest,
|
|
1370
|
-
onDone: {
|
|
1371
|
-
target: FirstPartyMachineStateTypes.selectCredentials,
|
|
1372
|
-
actions: assign2({
|
|
1373
|
-
authorizationRequestData: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationRequestData")
|
|
1374
|
-
})
|
|
1375
|
-
},
|
|
1376
|
-
onError: {
|
|
1377
|
-
target: FirstPartyMachineStateTypes.error,
|
|
1378
|
-
actions: assign2({
|
|
1379
|
-
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1380
|
-
title: translate("siopV2_machine_get_request_error_title"),
|
|
1381
|
-
message: _event.data.message,
|
|
1382
|
-
stack: _event.data.stack
|
|
1383
|
-
}), "error")
|
|
1384
|
-
})
|
|
1481
|
+
alt: credentialDisplay.rendering.simple.logo.alt_text
|
|
1482
|
+
}
|
|
1385
1483
|
}
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
selectedCredentials: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectedCredentials")
|
|
1394
|
-
})
|
|
1395
|
-
},
|
|
1396
|
-
[FirstPartyMachineEvents.NEXT]: {
|
|
1397
|
-
target: FirstPartyMachineStateTypes.sendAuthorizationResponse
|
|
1398
|
-
},
|
|
1399
|
-
[FirstPartyMachineEvents.DECLINE]: {
|
|
1400
|
-
target: FirstPartyMachineStateTypes.declined
|
|
1401
|
-
},
|
|
1402
|
-
[FirstPartyMachineEvents.PREVIOUS]: {
|
|
1403
|
-
target: FirstPartyMachineStateTypes.aborted
|
|
1484
|
+
},
|
|
1485
|
+
...credentialDisplay.description && {
|
|
1486
|
+
description: credentialDisplay.description
|
|
1487
|
+
},
|
|
1488
|
+
...credentialDisplay.rendering?.simple?.text_color && {
|
|
1489
|
+
text: {
|
|
1490
|
+
color: credentialDisplay.rendering.simple.text_color
|
|
1404
1491
|
}
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
invoke: {
|
|
1410
|
-
src: FirstPartyMachineServices.sendAuthorizationResponse,
|
|
1411
|
-
onDone: {
|
|
1412
|
-
target: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
|
|
1413
|
-
actions: assign2({
|
|
1414
|
-
presentationDuringIssuanceSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "presentationDuringIssuanceSession")
|
|
1415
|
-
})
|
|
1416
|
-
},
|
|
1417
|
-
onError: {
|
|
1418
|
-
target: FirstPartyMachineStateTypes.error,
|
|
1419
|
-
actions: assign2({
|
|
1420
|
-
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1421
|
-
title: translate("oid4vci_machine_get_request_error_title"),
|
|
1422
|
-
message: _event.data.message,
|
|
1423
|
-
stack: _event.data.stack
|
|
1424
|
-
}), "error")
|
|
1425
|
-
})
|
|
1492
|
+
},
|
|
1493
|
+
...credentialDisplay.rendering?.simple?.background_color && {
|
|
1494
|
+
background: {
|
|
1495
|
+
color: credentialDisplay.rendering.simple.background_color
|
|
1426
1496
|
}
|
|
1427
1497
|
}
|
|
1428
|
-
},
|
|
1429
|
-
[FirstPartyMachineStateTypes.aborted]: {
|
|
1430
|
-
id: FirstPartyMachineStateTypes.aborted,
|
|
1431
|
-
type: "final"
|
|
1432
|
-
},
|
|
1433
|
-
[FirstPartyMachineStateTypes.declined]: {
|
|
1434
|
-
id: FirstPartyMachineStateTypes.declined,
|
|
1435
|
-
type: "final"
|
|
1436
|
-
},
|
|
1437
|
-
[FirstPartyMachineStateTypes.error]: {
|
|
1438
|
-
id: FirstPartyMachineStateTypes.error,
|
|
1439
|
-
type: "final"
|
|
1440
|
-
},
|
|
1441
|
-
[FirstPartyMachineStateTypes.done]: {
|
|
1442
|
-
id: FirstPartyMachineStateTypes.done,
|
|
1443
|
-
type: "final"
|
|
1444
|
-
}
|
|
1445
|
-
};
|
|
1446
|
-
var createFirstPartyActivationMachine = /* @__PURE__ */ __name((opts) => {
|
|
1447
|
-
const initialContext = {
|
|
1448
|
-
openID4VCIClientState: opts.openID4VCIClientState,
|
|
1449
|
-
contact: opts.contact,
|
|
1450
|
-
selectedCredentials: []
|
|
1451
1498
|
};
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
static _instance;
|
|
1469
|
-
static hasInstance() {
|
|
1470
|
-
return _FirstPartyMachine._instance !== void 0;
|
|
1471
|
-
}
|
|
1472
|
-
static get instance() {
|
|
1473
|
-
if (!_FirstPartyMachine._instance) {
|
|
1474
|
-
throw Error("Please initialize ESIMActivation machine first");
|
|
1475
|
-
}
|
|
1476
|
-
return _FirstPartyMachine._instance;
|
|
1477
|
-
}
|
|
1478
|
-
static clearInstance(opts) {
|
|
1479
|
-
const { stop } = opts;
|
|
1480
|
-
if (_FirstPartyMachine.hasInstance()) {
|
|
1481
|
-
if (stop) {
|
|
1482
|
-
_FirstPartyMachine.stopInstance();
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
_FirstPartyMachine._instance = void 0;
|
|
1486
|
-
}
|
|
1487
|
-
static stopInstance() {
|
|
1488
|
-
if (!_FirstPartyMachine.hasInstance()) {
|
|
1489
|
-
return;
|
|
1490
|
-
}
|
|
1491
|
-
_FirstPartyMachine.instance.stop();
|
|
1492
|
-
_FirstPartyMachine._instance = void 0;
|
|
1493
|
-
}
|
|
1494
|
-
static newInstance(opts) {
|
|
1495
|
-
const { agentContext } = opts;
|
|
1496
|
-
const services = {
|
|
1497
|
-
[FirstPartyMachineServices.sendAuthorizationChallengeRequest]: sendAuthorizationChallengeRequest,
|
|
1498
|
-
[FirstPartyMachineServices.createConfig]: (args) => createConfig(args, agentContext),
|
|
1499
|
-
[FirstPartyMachineServices.getSiopRequest]: (args) => getSiopRequest(args, agentContext),
|
|
1500
|
-
[FirstPartyMachineServices.sendAuthorizationResponse]: (args) => sendAuthorizationResponse(args, agentContext)
|
|
1501
|
-
};
|
|
1502
|
-
const newInst = interpret2(createFirstPartyActivationMachine(opts).withConfig({
|
|
1503
|
-
services: {
|
|
1504
|
-
...services,
|
|
1505
|
-
...opts?.services
|
|
1499
|
+
}, "sdJwtCredentialLocaleBrandingFrom");
|
|
1500
|
+
var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1501
|
+
const { credentialDisplayLocales = /* @__PURE__ */ new Map(), claimsMetadata = /* @__PURE__ */ new Map() } = args;
|
|
1502
|
+
const locales = Array.from(/* @__PURE__ */ new Set([
|
|
1503
|
+
...claimsMetadata.keys(),
|
|
1504
|
+
...credentialDisplayLocales.keys()
|
|
1505
|
+
]));
|
|
1506
|
+
return Promise.all(locales.map(async (locale) => {
|
|
1507
|
+
const display = credentialDisplayLocales.get(locale);
|
|
1508
|
+
const claims = claimsMetadata.get(locale);
|
|
1509
|
+
return {
|
|
1510
|
+
...display && await sdJwtCredentialLocaleBrandingFrom({
|
|
1511
|
+
credentialDisplay: display
|
|
1512
|
+
}),
|
|
1513
|
+
...locale.length > 0 && {
|
|
1514
|
+
locale
|
|
1506
1515
|
},
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1516
|
+
claims
|
|
1517
|
+
};
|
|
1518
|
+
}));
|
|
1519
|
+
}, "sdJwtCombineDisplayLocalesFrom");
|
|
1520
|
+
var issuerLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1521
|
+
const { issuerDisplay, dynamicRegistrationClientMetadata } = args;
|
|
1522
|
+
return {
|
|
1523
|
+
...dynamicRegistrationClientMetadata?.client_name && {
|
|
1524
|
+
alias: dynamicRegistrationClientMetadata.client_name
|
|
1525
|
+
},
|
|
1526
|
+
...issuerDisplay.name && {
|
|
1527
|
+
alias: issuerDisplay.name
|
|
1528
|
+
},
|
|
1529
|
+
...issuerDisplay.locale && {
|
|
1530
|
+
locale: issuerDisplay.locale
|
|
1531
|
+
},
|
|
1532
|
+
...(issuerDisplay.logo || dynamicRegistrationClientMetadata?.logo_uri) && {
|
|
1533
|
+
logo: {
|
|
1534
|
+
...dynamicRegistrationClientMetadata?.logo_uri && {
|
|
1535
|
+
uri: dynamicRegistrationClientMetadata?.logo_uri
|
|
1536
|
+
},
|
|
1537
|
+
...(issuerDisplay.logo?.url || issuerDisplay.logo?.uri) && {
|
|
1538
|
+
uri: issuerDisplay.logo?.url ?? issuerDisplay.logo?.uri
|
|
1539
|
+
},
|
|
1540
|
+
...issuerDisplay.logo?.alt_text && {
|
|
1541
|
+
alt: issuerDisplay.logo?.alt_text
|
|
1518
1542
|
}
|
|
1519
|
-
});
|
|
1520
|
-
}
|
|
1521
|
-
return newInst;
|
|
1522
|
-
}
|
|
1523
|
-
static getInstance(opts) {
|
|
1524
|
-
if (!_FirstPartyMachine._instance) {
|
|
1525
|
-
if (opts?.requireExisting === true) {
|
|
1526
|
-
throw Error(`Existing FirstPartyMachine instance requested, but none was created at this point!`);
|
|
1527
1543
|
}
|
|
1528
|
-
|
|
1544
|
+
},
|
|
1545
|
+
...issuerDisplay.description && {
|
|
1546
|
+
description: issuerDisplay.description
|
|
1547
|
+
},
|
|
1548
|
+
...issuerDisplay.text_color && {
|
|
1549
|
+
text: {
|
|
1550
|
+
color: issuerDisplay.text_color
|
|
1551
|
+
}
|
|
1552
|
+
},
|
|
1553
|
+
...dynamicRegistrationClientMetadata?.client_uri && {
|
|
1554
|
+
clientUri: dynamicRegistrationClientMetadata.client_uri
|
|
1555
|
+
},
|
|
1556
|
+
...dynamicRegistrationClientMetadata?.tos_uri && {
|
|
1557
|
+
tosUri: dynamicRegistrationClientMetadata.tos_uri
|
|
1558
|
+
},
|
|
1559
|
+
...dynamicRegistrationClientMetadata?.policy_uri && {
|
|
1560
|
+
policyUri: dynamicRegistrationClientMetadata.policy_uri
|
|
1561
|
+
},
|
|
1562
|
+
...dynamicRegistrationClientMetadata?.contacts && {
|
|
1563
|
+
contacts: dynamicRegistrationClientMetadata.contacts
|
|
1529
1564
|
}
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
};
|
|
1565
|
+
};
|
|
1566
|
+
}, "issuerLocaleBrandingFrom");
|
|
1533
1567
|
|
|
1534
1568
|
// src/services/OID4VCIHolderService.ts
|
|
1535
|
-
import { defaultHasher } from "@sphereon/ssi-sdk.core";
|
|
1536
1569
|
var getCredentialBranding = /* @__PURE__ */ __name(async (args) => {
|
|
1537
1570
|
const { credentialsSupported, context } = args;
|
|
1538
1571
|
const credentialBranding = {};
|
|
1539
1572
|
await Promise.all(Object.entries(credentialsSupported).map(async ([configId, credentialsConfigSupported]) => {
|
|
1540
1573
|
let sdJwtTypeMetadata;
|
|
1541
|
-
if (credentialsConfigSupported.format === "
|
|
1574
|
+
if (credentialsConfigSupported.format === "dc+sd-jwt") {
|
|
1542
1575
|
const vct = credentialsConfigSupported.vct;
|
|
1543
1576
|
if (vct.startsWith("http")) {
|
|
1544
1577
|
try {
|
|
@@ -1604,10 +1637,7 @@ var selectCredentialLocaleBranding = /* @__PURE__ */ __name(async (args) => {
|
|
|
1604
1637
|
}, "selectCredentialLocaleBranding");
|
|
1605
1638
|
var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
1606
1639
|
const { mappedCredential, hasher, onVerifyEBSICredentialIssuer, schemaValidation, context } = args;
|
|
1607
|
-
const credential = mappedCredential.credentialToAccept.credentialResponse
|
|
1608
|
-
if (!credential) {
|
|
1609
|
-
return Promise.reject(Error("No credential found in credential response"));
|
|
1610
|
-
}
|
|
1640
|
+
const credential = extractCredentialFromResponse(mappedCredential.credentialToAccept.credentialResponse);
|
|
1611
1641
|
const wrappedVC = CredentialMapper.toWrappedVerifiableCredential(credential, {
|
|
1612
1642
|
hasher: hasher ?? defaultHasher
|
|
1613
1643
|
});
|
|
@@ -1659,17 +1689,13 @@ var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
|
1659
1689
|
}, "verifyCredentialToAccept");
|
|
1660
1690
|
var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
1661
1691
|
const { credentialToAccept, hasher } = args;
|
|
1662
|
-
const
|
|
1663
|
-
const verifiableCredential = credentialResponse.credential;
|
|
1664
|
-
if (!verifiableCredential) {
|
|
1665
|
-
return Promise.reject(Error("No credential found in credential response"));
|
|
1666
|
-
}
|
|
1692
|
+
const verifiableCredential = extractCredentialFromResponse(credentialToAccept.credentialResponse);
|
|
1667
1693
|
const wrappedVerifiableCredential = CredentialMapper.toWrappedVerifiableCredential(verifiableCredential, {
|
|
1668
1694
|
hasher
|
|
1669
1695
|
});
|
|
1670
1696
|
let uniformVerifiableCredential;
|
|
1671
1697
|
if (CredentialMapper.isSdJwtDecodedCredential(wrappedVerifiableCredential.credential)) {
|
|
1672
|
-
uniformVerifiableCredential =
|
|
1698
|
+
uniformVerifiableCredential = sdJwtDecodedCredentialToUniformCredential(wrappedVerifiableCredential.credential);
|
|
1673
1699
|
} else if (CredentialMapper.isSdJwtEncoded(wrappedVerifiableCredential.credential)) {
|
|
1674
1700
|
if (!hasher) {
|
|
1675
1701
|
return Promise.reject("a hasher is required for encoded SD-JWT credentials");
|
|
@@ -1683,6 +1709,7 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
|
1683
1709
|
uniformVerifiableCredential = wrappedVerifiableCredential.credential;
|
|
1684
1710
|
}
|
|
1685
1711
|
const correlationId = typeof uniformVerifiableCredential.issuer === "string" ? uniformVerifiableCredential.issuer : CredentialMapper.isSdJwtDecodedCredential(uniformVerifiableCredential) ? uniformVerifiableCredential.decodedPayload.iss : uniformVerifiableCredential.issuer.id;
|
|
1712
|
+
const credentialResponse = credentialToAccept.credentialResponse;
|
|
1686
1713
|
return {
|
|
1687
1714
|
correlationId,
|
|
1688
1715
|
credentialToAccept,
|
|
@@ -1694,6 +1721,18 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
|
1694
1721
|
}
|
|
1695
1722
|
};
|
|
1696
1723
|
}, "mapCredentialToAccept");
|
|
1724
|
+
var extractCredentialFromResponse = /* @__PURE__ */ __name((credentialResponse) => {
|
|
1725
|
+
let credential;
|
|
1726
|
+
if ("credential" in credentialResponse) {
|
|
1727
|
+
credential = credentialResponse.credential;
|
|
1728
|
+
} else if ("credentials" in credentialResponse && credentialResponse.credentials && Array.isArray(credentialResponse.credentials) && credentialResponse.credentials.length > 0) {
|
|
1729
|
+
credential = credentialResponse.credentials[0].credential;
|
|
1730
|
+
}
|
|
1731
|
+
if (!credential) {
|
|
1732
|
+
throw new Error("No credential found in credential response");
|
|
1733
|
+
}
|
|
1734
|
+
return credential;
|
|
1735
|
+
}, "extractCredentialFromResponse");
|
|
1697
1736
|
var getIdentifierOpts = /* @__PURE__ */ __name(async (args) => {
|
|
1698
1737
|
const { issuanceOpt, context } = args;
|
|
1699
1738
|
const { identifier: identifierArg } = issuanceOpt;
|
|
@@ -1802,24 +1841,19 @@ var getCredentialConfigsSupportedBySingleTypeOrId = /* @__PURE__ */ __name(async
|
|
|
1802
1841
|
}
|
|
1803
1842
|
__name(createIdFromTypes, "createIdFromTypes");
|
|
1804
1843
|
if (configurationId) {
|
|
1805
|
-
const allSupported2 = client.getCredentialsSupported(
|
|
1844
|
+
const allSupported2 = client.getCredentialsSupported(void 0, format);
|
|
1806
1845
|
return Object.fromEntries(Object.entries(allSupported2).filter(([id, supported]) => id === configurationId || supported.id === configurationId || createIdFromTypes(supported) === configurationId));
|
|
1807
1846
|
}
|
|
1808
|
-
if (!
|
|
1809
|
-
return Promise.reject(Error("openID4VCIClient has no credentialOffer
|
|
1847
|
+
if (!client.credentialOffer) {
|
|
1848
|
+
return Promise.reject(Error("openID4VCIClient has no credentialOffer"));
|
|
1810
1849
|
}
|
|
1811
|
-
if (!
|
|
1812
|
-
|
|
1813
|
-
format = client.credentialOffer.credential_offer.credentials.filter((cred) => typeof cred !== "string").map((cred) => cred.format);
|
|
1814
|
-
if (format?.length === 0) {
|
|
1815
|
-
format = void 0;
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1850
|
+
if (!types) {
|
|
1851
|
+
return Promise.reject(Error("openID4VCIClient has no types"));
|
|
1818
1852
|
}
|
|
1819
1853
|
const offerSupported = getSupportedCredentials({
|
|
1820
|
-
types:
|
|
1854
|
+
types: [
|
|
1821
1855
|
types
|
|
1822
|
-
]
|
|
1856
|
+
],
|
|
1823
1857
|
format,
|
|
1824
1858
|
version: client.version(),
|
|
1825
1859
|
issuerMetadata: client.endpointMetadata.credentialIssuerMetadata
|
|
@@ -1994,7 +2028,8 @@ var getIssuanceCryptoSuite = /* @__PURE__ */ __name(async (opts) => {
|
|
|
1994
2028
|
case "jwt":
|
|
1995
2029
|
case "jwt_vc_json":
|
|
1996
2030
|
case "jwt_vc":
|
|
1997
|
-
case
|
|
2031
|
+
//case 'vc+sd-jwt': // TODO see SSISDK-52 concerning vc+sd-jwt
|
|
2032
|
+
case "dc+sd-jwt":
|
|
1998
2033
|
case "mso_mdoc": {
|
|
1999
2034
|
const supportedPreferences = jwtCryptographicSuitePreferences.filter((suite) => signing_algs_supported.includes(suite));
|
|
2000
2035
|
if (supportedPreferences.length > 0) {
|
|
@@ -2062,8 +2097,6 @@ var startFirstPartApplicationMachine = /* @__PURE__ */ __name(async (args, conte
|
|
|
2062
2097
|
}, "startFirstPartApplicationMachine");
|
|
2063
2098
|
|
|
2064
2099
|
// src/agent/OID4VCIHolder.ts
|
|
2065
|
-
import "cross-fetch/polyfill";
|
|
2066
|
-
import { defaultHasher as defaultHasher2 } from "@sphereon/ssi-sdk.core";
|
|
2067
2100
|
var oid4vciHolderContextMethods = [
|
|
2068
2101
|
"cmGetContacts",
|
|
2069
2102
|
"cmGetContact",
|
|
@@ -2079,7 +2112,7 @@ var oid4vciHolderContextMethods = [
|
|
|
2079
2112
|
];
|
|
2080
2113
|
var logger = Loggers.DEFAULT.get("sphereon:oid4vci:holder");
|
|
2081
2114
|
function signCallback(identifier, context, nonce) {
|
|
2082
|
-
return async (jwt, kid) => {
|
|
2115
|
+
return async (jwt, kid, noIssPayloadUpdate) => {
|
|
2083
2116
|
let resolution = await context.agent.identifierManagedGet(identifier);
|
|
2084
2117
|
const jwk = jwt.header.jwk ?? (resolution.method === "jwk" ? resolution.jwk : void 0);
|
|
2085
2118
|
if (!resolution.issuer && !jwt.payload.iss) {
|
|
@@ -2097,7 +2130,7 @@ function signCallback(identifier, context, nonce) {
|
|
|
2097
2130
|
return (await context.agent.jwtCreateJwsCompactSignature({
|
|
2098
2131
|
issuer: {
|
|
2099
2132
|
...resolution,
|
|
2100
|
-
noIssPayloadUpdate: false
|
|
2133
|
+
noIssPayloadUpdate: noIssPayloadUpdate ?? false
|
|
2101
2134
|
},
|
|
2102
2135
|
protectedHeader: header,
|
|
2103
2136
|
payload
|
|
@@ -2119,6 +2152,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2119
2152
|
oid4vciHolderStart: this.oid4vciHolderStart.bind(this),
|
|
2120
2153
|
oid4vciHolderGetIssuerMetadata: this.oid4vciHolderGetIssuerMetadata.bind(this),
|
|
2121
2154
|
oid4vciHolderGetMachineInterpreter: this.oid4vciHolderGetMachineInterpreter.bind(this),
|
|
2155
|
+
oid4vciHolderPrepareAuthorizationRequest: this.oid4vciHolderPrepareAuthorizationRequest.bind(this),
|
|
2122
2156
|
oid4vciHolderCreateCredentialsToSelectFrom: this.oid4vciHolderCreateCredentialsToSelectFrom.bind(this),
|
|
2123
2157
|
oid4vciHolderGetContact: this.oid4vciHolderGetContact.bind(this),
|
|
2124
2158
|
oid4vciHolderGetCredentials: this.oid4vciHolderGetCredentials.bind(this),
|
|
@@ -2132,6 +2166,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2132
2166
|
oid4vciHolderStoreIssuerBranding: this.oid4vciHolderStoreIssuerBranding.bind(this)
|
|
2133
2167
|
};
|
|
2134
2168
|
vcFormatPreferences = [
|
|
2169
|
+
"dc+sd-jwt",
|
|
2135
2170
|
"vc+sd-jwt",
|
|
2136
2171
|
"mso_mdoc",
|
|
2137
2172
|
"jwt_vc_json",
|
|
@@ -2222,6 +2257,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2222
2257
|
stateNavigationListener: opts.firstPartyStateNavigationListener
|
|
2223
2258
|
}, context),
|
|
2224
2259
|
[OID4VCIMachineServices.createCredentialsToSelectFrom]: (args) => this.oid4vciHolderCreateCredentialsToSelectFrom(args, context),
|
|
2260
|
+
[OID4VCIMachineServices.prepareAuthorizationRequest]: (args) => this.oid4vciHolderPrepareAuthorizationRequest(args, context),
|
|
2225
2261
|
[OID4VCIMachineServices.getContact]: (args) => this.oid4vciHolderGetContact(args, context),
|
|
2226
2262
|
[OID4VCIMachineServices.getCredentials]: (args) => this.oid4vciHolderGetCredentials({
|
|
2227
2263
|
accessTokenOpts: args.accessTokenOpts ?? opts.accessTokenOpts,
|
|
@@ -2270,7 +2306,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2270
2306
|
...this.defaultAuthorizationRequestOpts,
|
|
2271
2307
|
...args.authorizationRequestOpts
|
|
2272
2308
|
};
|
|
2273
|
-
authorizationRequestOpts.authorizationDetails = authorizationRequestOpts?.authorizationDetails ? asArray2(authorizationRequestOpts.authorizationDetails)
|
|
2309
|
+
authorizationRequestOpts.authorizationDetails = authorizationRequestOpts?.authorizationDetails ? asArray2(authorizationRequestOpts.authorizationDetails) : void 0;
|
|
2274
2310
|
if (!authorizationRequestOpts.redirectUri) {
|
|
2275
2311
|
authorizationRequestOpts.redirectUri = _OID4VCIHolder.DEFAULT_MOBILE_REDIRECT_URI;
|
|
2276
2312
|
}
|
|
@@ -2283,10 +2319,9 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2283
2319
|
formats = Array.from(new Set(authFormats));
|
|
2284
2320
|
}
|
|
2285
2321
|
let oid4vciClient;
|
|
2286
|
-
let types = void 0;
|
|
2287
2322
|
let offer;
|
|
2288
2323
|
if (requestData.existingClientState) {
|
|
2289
|
-
oid4vciClient = await
|
|
2324
|
+
oid4vciClient = await OpenID4VCIClientV1_0_15.fromState({
|
|
2290
2325
|
state: requestData.existingClientState
|
|
2291
2326
|
});
|
|
2292
2327
|
offer = oid4vciClient.credentialOffer;
|
|
@@ -2303,50 +2338,78 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2303
2338
|
}
|
|
2304
2339
|
if (!offer) {
|
|
2305
2340
|
logger.log(`Issuer url received (no credential offer): ${uri}`);
|
|
2306
|
-
oid4vciClient = await
|
|
2341
|
+
oid4vciClient = await OpenID4VCIClientV1_0_15.fromCredentialIssuer({
|
|
2307
2342
|
credentialIssuer: uri,
|
|
2308
2343
|
authorizationRequest: authorizationRequestOpts,
|
|
2309
2344
|
clientId: authorizationRequestOpts.clientId,
|
|
2310
|
-
createAuthorizationRequestURL:
|
|
2345
|
+
createAuthorizationRequestURL: false
|
|
2311
2346
|
});
|
|
2312
2347
|
} else {
|
|
2313
2348
|
logger.log(`Credential offer received: ${uri}`);
|
|
2314
|
-
oid4vciClient = await
|
|
2349
|
+
oid4vciClient = await OpenID4VCIClientV1_0_15.fromURI({
|
|
2315
2350
|
uri,
|
|
2316
2351
|
authorizationRequest: authorizationRequestOpts,
|
|
2317
2352
|
clientId: authorizationRequestOpts.clientId,
|
|
2318
|
-
createAuthorizationRequestURL:
|
|
2353
|
+
createAuthorizationRequestURL: false
|
|
2319
2354
|
});
|
|
2320
2355
|
}
|
|
2321
2356
|
}
|
|
2357
|
+
let configurationIds = [];
|
|
2322
2358
|
if (offer) {
|
|
2323
|
-
|
|
2359
|
+
configurationIds = offer.original_credential_offer.credential_configuration_ids;
|
|
2324
2360
|
} else {
|
|
2325
|
-
|
|
2361
|
+
configurationIds = asArray2(authorizationRequestOpts.authorizationDetails).map((authReqOpts) => authReqOpts.credential_configuration_id).filter((id) => !!id);
|
|
2326
2362
|
}
|
|
2327
|
-
const serverMetadata = await oid4vciClient.retrieveServerMetadata();
|
|
2328
2363
|
const credentialsSupported = await getCredentialConfigsSupportedMerged({
|
|
2329
2364
|
client: oid4vciClient,
|
|
2330
2365
|
vcFormatPreferences: formats,
|
|
2331
|
-
|
|
2366
|
+
configurationIds
|
|
2332
2367
|
});
|
|
2368
|
+
const serverMetadata = await oid4vciClient.retrieveServerMetadata();
|
|
2333
2369
|
const credentialBranding = await getCredentialBranding({
|
|
2334
2370
|
credentialsSupported,
|
|
2335
2371
|
context
|
|
2336
2372
|
});
|
|
2337
|
-
const authorizationCodeURL = oid4vciClient.authorizationURL;
|
|
2338
|
-
if (authorizationCodeURL) {
|
|
2339
|
-
logger.log(`authorization code URL ${authorizationCodeURL}`);
|
|
2340
|
-
}
|
|
2341
2373
|
const oid4vciClientState = JSON.parse(await oid4vciClient.exportState());
|
|
2342
2374
|
return {
|
|
2343
|
-
authorizationCodeURL,
|
|
2344
2375
|
credentialBranding,
|
|
2345
2376
|
credentialsSupported,
|
|
2346
2377
|
serverMetadata,
|
|
2347
2378
|
oid4vciClientState
|
|
2348
2379
|
};
|
|
2349
2380
|
}
|
|
2381
|
+
async oid4vciHolderPrepareAuthorizationRequest(args, context) {
|
|
2382
|
+
const { openID4VCIClientState, contact } = args;
|
|
2383
|
+
if (!openID4VCIClientState) {
|
|
2384
|
+
return Promise.reject(Error("Missing openID4VCI client state in context"));
|
|
2385
|
+
}
|
|
2386
|
+
const clientId = contact?.identities.map((identity) => {
|
|
2387
|
+
const connectionConfig = identity.connection?.config;
|
|
2388
|
+
if (connectionConfig && "clientId" in connectionConfig) {
|
|
2389
|
+
return connectionConfig.clientId;
|
|
2390
|
+
}
|
|
2391
|
+
return void 0;
|
|
2392
|
+
}).find((clientId2) => clientId2);
|
|
2393
|
+
if (!clientId) {
|
|
2394
|
+
return Promise.reject(Error(`Missing client id in contact's connectionConfig`));
|
|
2395
|
+
}
|
|
2396
|
+
const client = await OpenID4VCIClient2.fromState({
|
|
2397
|
+
state: openID4VCIClientState
|
|
2398
|
+
});
|
|
2399
|
+
const authorizationCodeURL = await client.createAuthorizationRequestUrl({
|
|
2400
|
+
authorizationRequest: {
|
|
2401
|
+
clientId
|
|
2402
|
+
}
|
|
2403
|
+
});
|
|
2404
|
+
if (authorizationCodeURL) {
|
|
2405
|
+
logger.log(`authorization code URL ${authorizationCodeURL}`);
|
|
2406
|
+
}
|
|
2407
|
+
return {
|
|
2408
|
+
authorizationCodeURL,
|
|
2409
|
+
// Needed, because the above createAuthorizationRequestUrl manipulates the state, adding pkce opts to the state
|
|
2410
|
+
oid4vciClientState: JSON.parse(await client.exportState())
|
|
2411
|
+
};
|
|
2412
|
+
}
|
|
2350
2413
|
async oid4vciHolderCreateCredentialsToSelectFrom(args, context) {
|
|
2351
2414
|
const { credentialBranding, locale, selectedCredentials, credentialsSupported } = args;
|
|
2352
2415
|
logger.info(`Credentials supported ${Object.keys(credentialsSupported).join(", ")}`);
|
|
@@ -2418,7 +2481,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2418
2481
|
if (!openID4VCIClientState) {
|
|
2419
2482
|
return Promise.reject(Error("Missing openID4VCI client state in context"));
|
|
2420
2483
|
}
|
|
2421
|
-
const client = await
|
|
2484
|
+
const client = await OpenID4VCIClientV1_0_15.fromState({
|
|
2422
2485
|
state: openID4VCIClientState
|
|
2423
2486
|
});
|
|
2424
2487
|
const credentialsSupported = await getCredentialConfigsSupportedMerged({
|
|
@@ -2658,9 +2721,19 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2658
2721
|
}
|
|
2659
2722
|
let counter = 0;
|
|
2660
2723
|
for (const credentialId of selectedCredentials) {
|
|
2661
|
-
const
|
|
2724
|
+
const configId = credentialId;
|
|
2725
|
+
const types = credentialsToAccept.find((ac) => ac.correlationId === configId || ac.credentialToAccept.id === configId || ac.types.includes(configId))?.types?.filter((type) => type != "VerifiableCredential") ?? [];
|
|
2726
|
+
const localeBranding = credentialBranding?.[configId] ?? [];
|
|
2727
|
+
if (localeBranding.length === 0) {
|
|
2728
|
+
for (const type of types) {
|
|
2729
|
+
const branding = credentialBranding?.[type] ?? [];
|
|
2730
|
+
if (branding.length > 0) {
|
|
2731
|
+
localeBranding.push(...branding);
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2662
2735
|
if (localeBranding && localeBranding.length > 0) {
|
|
2663
|
-
const credential = credentialsToAccept.find((credAccept) => credAccept.credentialToAccept.id === credentialId || JSON.stringify(credAccept.types) === credentialId || credentialsToAccept[counter]);
|
|
2736
|
+
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]);
|
|
2664
2737
|
counter++;
|
|
2665
2738
|
await context.agent.ibAddCredentialBranding({
|
|
2666
2739
|
vcHash: computeEntryHash(credential.rawVerifiableCredential),
|
|
@@ -2708,7 +2781,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2708
2781
|
if (Array.isArray(subjectIssuance?.notification_events_supported)) {
|
|
2709
2782
|
event = subjectIssuance.notification_events_supported.includes("credential_accepted_holder_signed") ? "credential_accepted_holder_signed" : "credential_deleted_holder_signed";
|
|
2710
2783
|
logger.log(`Subject issuance/signing will be used, with event`, event);
|
|
2711
|
-
const issuerVC = mappedCredentialToAccept.credentialToAccept.credentialResponse
|
|
2784
|
+
const issuerVC = extractCredentialFromResponse(mappedCredentialToAccept.credentialToAccept.credentialResponse);
|
|
2712
2785
|
const wrappedIssuerVC = CredentialMapper2.toWrappedVerifiableCredential(issuerVC, {
|
|
2713
2786
|
hasher: this.hasher ?? defaultHasher2
|
|
2714
2787
|
});
|
|
@@ -3079,6 +3152,7 @@ export {
|
|
|
3079
3152
|
RequestType,
|
|
3080
3153
|
SupportedLanguage,
|
|
3081
3154
|
createConfig,
|
|
3155
|
+
extractCredentialFromResponse,
|
|
3082
3156
|
getBasicIssuerLocaleBranding,
|
|
3083
3157
|
getCredentialBranding,
|
|
3084
3158
|
getCredentialConfigsBasedOnFormatPref,
|