@sphereon/ssi-sdk.oid4vci-holder 0.34.1-next.3 → 0.34.1-next.322
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 +650 -579
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -17
- package/dist/index.d.ts +27 -17
- package/dist/index.js +628 -557
- package/dist/index.js.map +1 -1
- package/package.json +25 -24
- package/src/agent/OID4VCIHolder.ts +109 -54
- package/src/machines/firstPartyMachine.ts +1 -1
- package/src/machines/oid4vciMachine.ts +38 -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 +22 -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,28 @@ 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
|
+
})
|
|
706
|
+
},
|
|
707
|
+
onError: {
|
|
708
|
+
target: OID4VCIMachineStates.handleError,
|
|
709
|
+
actions: assign({
|
|
710
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
711
|
+
title: translate("oid4vci_machine_prepare_authorization_error_title"),
|
|
712
|
+
message: _event.data.message,
|
|
713
|
+
stack: _event.data.stack
|
|
714
|
+
}), "error")
|
|
715
|
+
})
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
},
|
|
687
719
|
[OID4VCIMachineStates.initiateAuthorizationRequest]: {
|
|
688
720
|
id: OID4VCIMachineStates.initiateAuthorizationRequest,
|
|
689
721
|
on: {
|
|
@@ -976,219 +1008,410 @@ var OID4VCIMachine = class {
|
|
|
976
1008
|
|
|
977
1009
|
// src/services/OID4VCIHolderService.ts
|
|
978
1010
|
import { LOG } from "@sphereon/oid4vci-client";
|
|
979
|
-
import { getSupportedCredentials, getTypesFromCredentialSupported, getTypesFromObject
|
|
1011
|
+
import { getSupportedCredentials, getTypesFromCredentialSupported, getTypesFromObject } from "@sphereon/oid4vci-common";
|
|
980
1012
|
import { KeyUse } from "@sphereon/ssi-sdk-ext.did-resolver-jwk";
|
|
981
1013
|
import { getOrCreatePrimaryIdentifier, SupportedDidMethodEnum } from "@sphereon/ssi-sdk-ext.did-utils";
|
|
982
1014
|
import { isIIdentifier, isManagedIdentifierDidResult, isManagedIdentifierResult, managedIdentifierToJwk } from "@sphereon/ssi-sdk-ext.identifier-resolution";
|
|
983
1015
|
import { keyTypeFromCryptographicSuite } from "@sphereon/ssi-sdk-ext.key-utils";
|
|
1016
|
+
import { defaultHasher } from "@sphereon/ssi-sdk.core";
|
|
984
1017
|
import { CredentialMapper, JoseSignatureAlgorithm, mdocDecodedCredentialToUniformCredential, sdJwtDecodedCredentialToUniformCredential } from "@sphereon/ssi-types";
|
|
985
1018
|
import { asArray } from "@veramo/utils";
|
|
986
1019
|
|
|
987
|
-
// src/
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
credentialDisplay
|
|
999
|
-
})
|
|
1000
|
-
}
|
|
1020
|
+
// src/machines/firstPartyMachine.ts
|
|
1021
|
+
import { assign as assign2, createMachine as createMachine2, interpret as interpret2 } from "xstate";
|
|
1022
|
+
import { AuthorizationChallengeError } from "@sphereon/oid4vci-common";
|
|
1023
|
+
|
|
1024
|
+
// src/services/FirstPartyMachineServices.ts
|
|
1025
|
+
import { OpenID4VCIClient } from "@sphereon/oid4vci-client";
|
|
1026
|
+
import { v4 as uuidv4 } from "uuid";
|
|
1027
|
+
var sendAuthorizationChallengeRequest = /* @__PURE__ */ __name(async (args) => {
|
|
1028
|
+
const { openID4VCIClientState, authSession, presentationDuringIssuanceSession } = args;
|
|
1029
|
+
const oid4vciClient = await OpenID4VCIClient.fromState({
|
|
1030
|
+
state: openID4VCIClientState
|
|
1001
1031
|
});
|
|
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
|
-
}
|
|
1032
|
+
return oid4vciClient.acquireAuthorizationChallengeCode({
|
|
1033
|
+
clientId: oid4vciClient.clientId ?? uuidv4(),
|
|
1034
|
+
...authSession && {
|
|
1035
|
+
authSession
|
|
1058
1036
|
},
|
|
1059
|
-
|
|
1060
|
-
|
|
1037
|
+
...!authSession && openID4VCIClientState.credentialOffer?.preAuthorizedCode && {
|
|
1038
|
+
issuerState: openID4VCIClientState.credentialOffer?.preAuthorizedCode
|
|
1061
1039
|
},
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
color: credentialDisplay.text_color
|
|
1065
|
-
}
|
|
1040
|
+
...!authSession && openID4VCIClientState.credentialOffer?.issuerState && {
|
|
1041
|
+
issuerState: openID4VCIClientState.credentialOffer?.issuerState
|
|
1066
1042
|
},
|
|
1067
|
-
...
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1043
|
+
...presentationDuringIssuanceSession && {
|
|
1044
|
+
presentationDuringIssuanceSession
|
|
1045
|
+
}
|
|
1046
|
+
});
|
|
1047
|
+
}, "sendAuthorizationChallengeRequest");
|
|
1048
|
+
var createConfig = /* @__PURE__ */ __name(async (args, context) => {
|
|
1049
|
+
const { presentationUri } = args;
|
|
1050
|
+
if (!presentationUri) {
|
|
1051
|
+
return Promise.reject(Error("Missing presentation uri in context"));
|
|
1052
|
+
}
|
|
1053
|
+
return context.agent.siopCreateConfig({
|
|
1054
|
+
url: presentationUri
|
|
1055
|
+
});
|
|
1056
|
+
}, "createConfig");
|
|
1057
|
+
var getSiopRequest = /* @__PURE__ */ __name(async (args, context) => {
|
|
1058
|
+
const { didAuthConfig, presentationUri } = args;
|
|
1059
|
+
if (presentationUri === void 0) {
|
|
1060
|
+
return Promise.reject(Error("Missing presentation uri in context"));
|
|
1061
|
+
}
|
|
1062
|
+
if (didAuthConfig === void 0) {
|
|
1063
|
+
return Promise.reject(Error("Missing did auth config in context"));
|
|
1064
|
+
}
|
|
1065
|
+
return context.agent.siopGetSiopRequest({
|
|
1066
|
+
didAuthConfig,
|
|
1067
|
+
url: presentationUri
|
|
1068
|
+
});
|
|
1069
|
+
}, "getSiopRequest");
|
|
1070
|
+
var sendAuthorizationResponse = /* @__PURE__ */ __name(async (args, context) => {
|
|
1071
|
+
const { didAuthConfig, authorizationRequestData, selectedCredentials } = args;
|
|
1072
|
+
const responseData = await context.agent.siopSendResponse({
|
|
1073
|
+
authorizationRequestData,
|
|
1074
|
+
selectedCredentials,
|
|
1075
|
+
didAuthConfig,
|
|
1076
|
+
isFirstParty: true
|
|
1077
|
+
});
|
|
1078
|
+
return responseData.body.presentation_during_issuance_session;
|
|
1079
|
+
}, "sendAuthorizationResponse");
|
|
1080
|
+
|
|
1081
|
+
// src/machines/firstPartyMachine.ts
|
|
1082
|
+
var firstPartyMachineStates = {
|
|
1083
|
+
[FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest]: {
|
|
1084
|
+
id: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
|
|
1085
|
+
invoke: {
|
|
1086
|
+
src: FirstPartyMachineServices.sendAuthorizationChallengeRequest,
|
|
1087
|
+
onDone: {
|
|
1088
|
+
target: FirstPartyMachineStateTypes.done,
|
|
1089
|
+
actions: assign2({
|
|
1090
|
+
authorizationCodeResponse: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationCodeResponse")
|
|
1091
|
+
})
|
|
1092
|
+
},
|
|
1093
|
+
onError: [
|
|
1094
|
+
{
|
|
1095
|
+
target: FirstPartyMachineStateTypes.createConfig,
|
|
1096
|
+
cond: /* @__PURE__ */ __name((_ctx, _event) => _event.data.error === AuthorizationChallengeError.insufficient_authorization, "cond"),
|
|
1097
|
+
actions: assign2({
|
|
1098
|
+
authSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data.auth_session, "authSession"),
|
|
1099
|
+
presentationUri: /* @__PURE__ */ __name((_ctx, _event) => _event.data.presentation, "presentationUri")
|
|
1100
|
+
})
|
|
1078
1101
|
},
|
|
1079
|
-
|
|
1080
|
-
|
|
1102
|
+
{
|
|
1103
|
+
target: FirstPartyMachineStateTypes.error,
|
|
1104
|
+
actions: assign2({
|
|
1105
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1106
|
+
title: translate("oid4vci_machine_send_authorization_challenge_request_error_title"),
|
|
1107
|
+
message: _event.data.message,
|
|
1108
|
+
stack: _event.data.stack
|
|
1109
|
+
}), "error")
|
|
1110
|
+
})
|
|
1081
1111
|
}
|
|
1112
|
+
]
|
|
1113
|
+
}
|
|
1114
|
+
},
|
|
1115
|
+
[FirstPartyMachineStateTypes.createConfig]: {
|
|
1116
|
+
id: FirstPartyMachineStateTypes.createConfig,
|
|
1117
|
+
invoke: {
|
|
1118
|
+
src: FirstPartyMachineServices.createConfig,
|
|
1119
|
+
onDone: {
|
|
1120
|
+
target: FirstPartyMachineStateTypes.getSiopRequest,
|
|
1121
|
+
actions: assign2({
|
|
1122
|
+
didAuthConfig: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "didAuthConfig")
|
|
1123
|
+
})
|
|
1124
|
+
},
|
|
1125
|
+
onError: {
|
|
1126
|
+
target: FirstPartyMachineStateTypes.error,
|
|
1127
|
+
actions: assign2({
|
|
1128
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1129
|
+
title: translate("oid4vci_machine_create_config_error_title"),
|
|
1130
|
+
message: _event.data.message,
|
|
1131
|
+
stack: _event.data.stack
|
|
1132
|
+
}), "error")
|
|
1133
|
+
})
|
|
1082
1134
|
}
|
|
1083
1135
|
}
|
|
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
|
|
1136
|
+
},
|
|
1137
|
+
[FirstPartyMachineStateTypes.getSiopRequest]: {
|
|
1138
|
+
id: FirstPartyMachineStateTypes.getSiopRequest,
|
|
1139
|
+
invoke: {
|
|
1140
|
+
src: FirstPartyMachineServices.getSiopRequest,
|
|
1141
|
+
onDone: {
|
|
1142
|
+
target: FirstPartyMachineStateTypes.selectCredentials,
|
|
1143
|
+
actions: assign2({
|
|
1144
|
+
authorizationRequestData: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationRequestData")
|
|
1145
|
+
})
|
|
1101
1146
|
},
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1147
|
+
onError: {
|
|
1148
|
+
target: FirstPartyMachineStateTypes.error,
|
|
1149
|
+
actions: assign2({
|
|
1150
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1151
|
+
title: translate("siopV2_machine_get_request_error_title"),
|
|
1152
|
+
message: _event.data.message,
|
|
1153
|
+
stack: _event.data.stack
|
|
1154
|
+
}), "error")
|
|
1155
|
+
})
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
},
|
|
1159
|
+
[FirstPartyMachineStateTypes.selectCredentials]: {
|
|
1160
|
+
id: FirstPartyMachineStateTypes.selectCredentials,
|
|
1161
|
+
on: {
|
|
1162
|
+
[FirstPartyMachineEvents.SET_SELECTED_CREDENTIALS]: {
|
|
1163
|
+
actions: assign2({
|
|
1164
|
+
selectedCredentials: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectedCredentials")
|
|
1165
|
+
})
|
|
1166
|
+
},
|
|
1167
|
+
[FirstPartyMachineEvents.NEXT]: {
|
|
1168
|
+
target: FirstPartyMachineStateTypes.sendAuthorizationResponse
|
|
1169
|
+
},
|
|
1170
|
+
[FirstPartyMachineEvents.DECLINE]: {
|
|
1171
|
+
target: FirstPartyMachineStateTypes.declined
|
|
1172
|
+
},
|
|
1173
|
+
[FirstPartyMachineEvents.PREVIOUS]: {
|
|
1174
|
+
target: FirstPartyMachineStateTypes.aborted
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
},
|
|
1178
|
+
[FirstPartyMachineStateTypes.sendAuthorizationResponse]: {
|
|
1179
|
+
id: FirstPartyMachineStateTypes.sendAuthorizationResponse,
|
|
1180
|
+
invoke: {
|
|
1181
|
+
src: FirstPartyMachineServices.sendAuthorizationResponse,
|
|
1182
|
+
onDone: {
|
|
1183
|
+
target: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
|
|
1184
|
+
actions: assign2({
|
|
1185
|
+
presentationDuringIssuanceSession: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "presentationDuringIssuanceSession")
|
|
1186
|
+
})
|
|
1187
|
+
},
|
|
1188
|
+
onError: {
|
|
1189
|
+
target: FirstPartyMachineStateTypes.error,
|
|
1190
|
+
actions: assign2({
|
|
1191
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1192
|
+
title: translate("oid4vci_machine_get_request_error_title"),
|
|
1193
|
+
message: _event.data.message,
|
|
1194
|
+
stack: _event.data.stack
|
|
1195
|
+
}), "error")
|
|
1196
|
+
})
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
},
|
|
1200
|
+
[FirstPartyMachineStateTypes.aborted]: {
|
|
1201
|
+
id: FirstPartyMachineStateTypes.aborted,
|
|
1202
|
+
type: "final"
|
|
1203
|
+
},
|
|
1204
|
+
[FirstPartyMachineStateTypes.declined]: {
|
|
1205
|
+
id: FirstPartyMachineStateTypes.declined,
|
|
1206
|
+
type: "final"
|
|
1207
|
+
},
|
|
1208
|
+
[FirstPartyMachineStateTypes.error]: {
|
|
1209
|
+
id: FirstPartyMachineStateTypes.error,
|
|
1210
|
+
type: "final"
|
|
1211
|
+
},
|
|
1212
|
+
[FirstPartyMachineStateTypes.done]: {
|
|
1213
|
+
id: FirstPartyMachineStateTypes.done,
|
|
1214
|
+
type: "final"
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
var createFirstPartyActivationMachine = /* @__PURE__ */ __name((opts) => {
|
|
1218
|
+
const initialContext = {
|
|
1219
|
+
openID4VCIClientState: opts.openID4VCIClientState,
|
|
1220
|
+
contact: opts.contact,
|
|
1221
|
+
selectedCredentials: []
|
|
1222
|
+
};
|
|
1223
|
+
return createMachine2({
|
|
1224
|
+
id: opts?.machineId ?? "FirstParty",
|
|
1225
|
+
predictableActionArguments: true,
|
|
1226
|
+
initial: FirstPartyMachineStateTypes.sendAuthorizationChallengeRequest,
|
|
1227
|
+
context: initialContext,
|
|
1228
|
+
states: firstPartyMachineStates,
|
|
1229
|
+
schema: {
|
|
1230
|
+
events: {},
|
|
1231
|
+
services: {}
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
}, "createFirstPartyActivationMachine");
|
|
1235
|
+
var FirstPartyMachine = class _FirstPartyMachine {
|
|
1236
|
+
static {
|
|
1237
|
+
__name(this, "FirstPartyMachine");
|
|
1238
|
+
}
|
|
1239
|
+
static _instance;
|
|
1240
|
+
static hasInstance() {
|
|
1241
|
+
return _FirstPartyMachine._instance !== void 0;
|
|
1242
|
+
}
|
|
1243
|
+
static get instance() {
|
|
1244
|
+
if (!_FirstPartyMachine._instance) {
|
|
1245
|
+
throw Error("Please initialize ESIMActivation machine first");
|
|
1246
|
+
}
|
|
1247
|
+
return _FirstPartyMachine._instance;
|
|
1248
|
+
}
|
|
1249
|
+
static clearInstance(opts) {
|
|
1250
|
+
const { stop } = opts;
|
|
1251
|
+
if (_FirstPartyMachine.hasInstance()) {
|
|
1252
|
+
if (stop) {
|
|
1253
|
+
_FirstPartyMachine.stopInstance();
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
_FirstPartyMachine._instance = void 0;
|
|
1257
|
+
}
|
|
1258
|
+
static stopInstance() {
|
|
1259
|
+
if (!_FirstPartyMachine.hasInstance()) {
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
_FirstPartyMachine.instance.stop();
|
|
1263
|
+
_FirstPartyMachine._instance = void 0;
|
|
1264
|
+
}
|
|
1265
|
+
static newInstance(opts) {
|
|
1266
|
+
const { agentContext } = opts;
|
|
1267
|
+
const services = {
|
|
1268
|
+
[FirstPartyMachineServices.sendAuthorizationChallengeRequest]: sendAuthorizationChallengeRequest,
|
|
1269
|
+
[FirstPartyMachineServices.createConfig]: (args) => createConfig(args, agentContext),
|
|
1270
|
+
[FirstPartyMachineServices.getSiopRequest]: (args) => getSiopRequest(args, agentContext),
|
|
1271
|
+
[FirstPartyMachineServices.sendAuthorizationResponse]: (args) => sendAuthorizationResponse(args, agentContext)
|
|
1272
|
+
};
|
|
1273
|
+
const newInst = interpret2(createFirstPartyActivationMachine(opts).withConfig({
|
|
1274
|
+
services: {
|
|
1275
|
+
...services,
|
|
1276
|
+
...opts?.services
|
|
1277
|
+
},
|
|
1278
|
+
guards: {
|
|
1279
|
+
...opts?.guards
|
|
1280
|
+
}
|
|
1281
|
+
}));
|
|
1282
|
+
if (typeof opts?.subscription === "function") {
|
|
1283
|
+
newInst.onTransition(opts.subscription);
|
|
1284
|
+
}
|
|
1285
|
+
if (opts?.requireCustomNavigationHook !== true) {
|
|
1286
|
+
newInst.onTransition((snapshot) => {
|
|
1287
|
+
if (opts?.stateNavigationListener) {
|
|
1288
|
+
void opts.stateNavigationListener(newInst, snapshot);
|
|
1289
|
+
}
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
return newInst;
|
|
1293
|
+
}
|
|
1294
|
+
static getInstance(opts) {
|
|
1295
|
+
if (!_FirstPartyMachine._instance) {
|
|
1296
|
+
if (opts?.requireExisting === true) {
|
|
1297
|
+
throw Error(`Existing FirstPartyMachine instance requested, but none was created at this point!`);
|
|
1298
|
+
}
|
|
1299
|
+
_FirstPartyMachine._instance = _FirstPartyMachine.newInstance(opts);
|
|
1300
|
+
}
|
|
1301
|
+
return _FirstPartyMachine._instance;
|
|
1302
|
+
}
|
|
1303
|
+
};
|
|
1304
|
+
|
|
1305
|
+
// src/mappers/OIDC4VCIBrandingMapper.ts
|
|
1306
|
+
var oid4vciGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1307
|
+
const { credentialDisplay, issuerCredentialSubject } = args;
|
|
1308
|
+
return oid4vciCombineDisplayLocalesFrom({
|
|
1309
|
+
...issuerCredentialSubject && {
|
|
1310
|
+
issuerCredentialSubjectLocales: await oid4vciIssuerCredentialSubjectLocalesFrom({
|
|
1311
|
+
issuerCredentialSubject
|
|
1112
1312
|
})
|
|
1113
1313
|
},
|
|
1114
1314
|
...credentialDisplay && {
|
|
1115
|
-
credentialDisplayLocales: await
|
|
1315
|
+
credentialDisplayLocales: await oid4vciCredentialDisplayLocalesFrom({
|
|
1116
1316
|
credentialDisplay
|
|
1117
1317
|
})
|
|
1118
1318
|
}
|
|
1119
1319
|
});
|
|
1120
|
-
}, "
|
|
1121
|
-
var
|
|
1320
|
+
}, "oid4vciGetCredentialBrandingFrom");
|
|
1321
|
+
var oid4vciCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1122
1322
|
const { credentialDisplay } = args;
|
|
1123
1323
|
return credentialDisplay.reduce((localeDisplays, display) => {
|
|
1124
|
-
const localeKey = display.
|
|
1324
|
+
const localeKey = display.locale || "";
|
|
1125
1325
|
localeDisplays.set(localeKey, display);
|
|
1126
1326
|
return localeDisplays;
|
|
1127
1327
|
}, /* @__PURE__ */ new Map());
|
|
1128
|
-
}, "
|
|
1129
|
-
var
|
|
1130
|
-
const {
|
|
1328
|
+
}, "oid4vciCredentialDisplayLocalesFrom");
|
|
1329
|
+
var oid4vciIssuerCredentialSubjectLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1330
|
+
const { issuerCredentialSubject } = args;
|
|
1131
1331
|
const localeClaims = /* @__PURE__ */ new Map();
|
|
1132
|
-
|
|
1133
|
-
claim.
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1332
|
+
const processClaimObject = /* @__PURE__ */ __name((claim, parentKey = "") => {
|
|
1333
|
+
Object.entries(claim).forEach(([key, value]) => {
|
|
1334
|
+
if (key === "mandatory" || key === "value_type") {
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1337
|
+
if (key === "display" && Array.isArray(value)) {
|
|
1338
|
+
value.forEach(({ name, locale = "" }) => {
|
|
1339
|
+
if (!name) {
|
|
1340
|
+
return;
|
|
1341
|
+
}
|
|
1342
|
+
if (!localeClaims.has(locale)) {
|
|
1343
|
+
localeClaims.set(locale, []);
|
|
1344
|
+
}
|
|
1345
|
+
localeClaims.get(locale).push({
|
|
1346
|
+
key: parentKey,
|
|
1347
|
+
name
|
|
1348
|
+
});
|
|
1349
|
+
});
|
|
1350
|
+
} else if (typeof value === "object" && value !== null) {
|
|
1351
|
+
processClaimObject(value, parentKey ? `${parentKey}.${key}` : key);
|
|
1138
1352
|
}
|
|
1139
|
-
localeClaims.get(lang).push({
|
|
1140
|
-
key,
|
|
1141
|
-
name: label
|
|
1142
|
-
});
|
|
1143
1353
|
});
|
|
1144
|
-
});
|
|
1354
|
+
}, "processClaimObject");
|
|
1355
|
+
processClaimObject(issuerCredentialSubject);
|
|
1145
1356
|
return localeClaims;
|
|
1146
|
-
}, "
|
|
1147
|
-
var
|
|
1357
|
+
}, "oid4vciIssuerCredentialSubjectLocalesFrom");
|
|
1358
|
+
var oid4vciCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1148
1359
|
const { credentialDisplay } = args;
|
|
1149
1360
|
return {
|
|
1150
1361
|
...credentialDisplay.name && {
|
|
1151
1362
|
alias: credentialDisplay.name
|
|
1152
1363
|
},
|
|
1153
|
-
...credentialDisplay.
|
|
1154
|
-
locale: credentialDisplay.
|
|
1364
|
+
...credentialDisplay.locale && {
|
|
1365
|
+
locale: credentialDisplay.locale
|
|
1155
1366
|
},
|
|
1156
|
-
...credentialDisplay.
|
|
1367
|
+
...credentialDisplay.logo && {
|
|
1157
1368
|
logo: {
|
|
1158
|
-
...credentialDisplay.
|
|
1159
|
-
uri: credentialDisplay.
|
|
1369
|
+
...(credentialDisplay.logo.url || credentialDisplay.logo.uri) && {
|
|
1370
|
+
uri: credentialDisplay.logo?.url ?? credentialDisplay.logo.uri
|
|
1160
1371
|
},
|
|
1161
|
-
...credentialDisplay.
|
|
1162
|
-
alt: credentialDisplay.
|
|
1372
|
+
...credentialDisplay.logo.alt_text && {
|
|
1373
|
+
alt: credentialDisplay.logo?.alt_text
|
|
1163
1374
|
}
|
|
1164
1375
|
}
|
|
1165
1376
|
},
|
|
1166
1377
|
...credentialDisplay.description && {
|
|
1167
1378
|
description: credentialDisplay.description
|
|
1168
1379
|
},
|
|
1169
|
-
...credentialDisplay.
|
|
1380
|
+
...credentialDisplay.text_color && {
|
|
1170
1381
|
text: {
|
|
1171
|
-
color: credentialDisplay.
|
|
1382
|
+
color: credentialDisplay.text_color
|
|
1172
1383
|
}
|
|
1173
1384
|
},
|
|
1174
|
-
...credentialDisplay.
|
|
1385
|
+
...(credentialDisplay.background_image || credentialDisplay.background_color) && {
|
|
1175
1386
|
background: {
|
|
1176
|
-
|
|
1387
|
+
...credentialDisplay.background_image && {
|
|
1388
|
+
image: {
|
|
1389
|
+
...(credentialDisplay.background_image.url || credentialDisplay.background_image.uri) && {
|
|
1390
|
+
uri: credentialDisplay.background_image?.url ?? credentialDisplay.background_image.uri
|
|
1391
|
+
},
|
|
1392
|
+
...credentialDisplay.background_image.alt_text && {
|
|
1393
|
+
alt: credentialDisplay.background_image?.alt_text
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
},
|
|
1397
|
+
...credentialDisplay.background_color && {
|
|
1398
|
+
color: credentialDisplay.background_color
|
|
1399
|
+
}
|
|
1177
1400
|
}
|
|
1178
1401
|
}
|
|
1179
1402
|
};
|
|
1180
|
-
}, "
|
|
1181
|
-
var
|
|
1182
|
-
const { credentialDisplayLocales = /* @__PURE__ */ new Map(),
|
|
1403
|
+
}, "oid4vciCredentialLocaleBrandingFrom");
|
|
1404
|
+
var oid4vciCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1405
|
+
const { credentialDisplayLocales = /* @__PURE__ */ new Map(), issuerCredentialSubjectLocales = /* @__PURE__ */ new Map() } = args;
|
|
1183
1406
|
const locales = Array.from(/* @__PURE__ */ new Set([
|
|
1184
|
-
...
|
|
1407
|
+
...issuerCredentialSubjectLocales.keys(),
|
|
1185
1408
|
...credentialDisplayLocales.keys()
|
|
1186
1409
|
]));
|
|
1187
1410
|
return Promise.all(locales.map(async (locale) => {
|
|
1188
1411
|
const display = credentialDisplayLocales.get(locale);
|
|
1189
|
-
const claims =
|
|
1412
|
+
const claims = issuerCredentialSubjectLocales.get(locale);
|
|
1190
1413
|
return {
|
|
1191
|
-
...display && await
|
|
1414
|
+
...display && await oid4vciCredentialLocaleBrandingFrom({
|
|
1192
1415
|
credentialDisplay: display
|
|
1193
1416
|
}),
|
|
1194
1417
|
...locale.length > 0 && {
|
|
@@ -1197,348 +1420,157 @@ var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
|
1197
1420
|
claims
|
|
1198
1421
|
};
|
|
1199
1422
|
}));
|
|
1200
|
-
}, "
|
|
1201
|
-
var
|
|
1202
|
-
const {
|
|
1203
|
-
return {
|
|
1204
|
-
...
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
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
|
|
1423
|
+
}, "oid4vciCombineDisplayLocalesFrom");
|
|
1424
|
+
var sdJwtGetCredentialBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1425
|
+
const { credentialDisplay, claimsMetadata } = args;
|
|
1426
|
+
return sdJwtCombineDisplayLocalesFrom({
|
|
1427
|
+
...claimsMetadata && {
|
|
1428
|
+
claimsMetadata: await sdJwtCredentialClaimLocalesFrom({
|
|
1429
|
+
claimsMetadata
|
|
1430
|
+
})
|
|
1242
1431
|
},
|
|
1243
|
-
...
|
|
1244
|
-
|
|
1432
|
+
...credentialDisplay && {
|
|
1433
|
+
credentialDisplayLocales: await sdJwtCredentialDisplayLocalesFrom({
|
|
1434
|
+
credentialDisplay
|
|
1435
|
+
})
|
|
1245
1436
|
}
|
|
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
1437
|
});
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1438
|
+
}, "sdJwtGetCredentialBrandingFrom");
|
|
1439
|
+
var sdJwtCredentialDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1440
|
+
const { credentialDisplay } = args;
|
|
1441
|
+
return credentialDisplay.reduce((localeDisplays, display) => {
|
|
1442
|
+
const localeKey = display.lang || "";
|
|
1443
|
+
localeDisplays.set(localeKey, display);
|
|
1444
|
+
return localeDisplays;
|
|
1445
|
+
}, /* @__PURE__ */ new Map());
|
|
1446
|
+
}, "sdJwtCredentialDisplayLocalesFrom");
|
|
1447
|
+
var sdJwtCredentialClaimLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1448
|
+
const { claimsMetadata } = args;
|
|
1449
|
+
const localeClaims = /* @__PURE__ */ new Map();
|
|
1450
|
+
claimsMetadata.forEach((claim) => {
|
|
1451
|
+
claim.display?.forEach((display) => {
|
|
1452
|
+
const { lang = "", label } = display;
|
|
1453
|
+
const key = claim.path.map((value) => String(value)).join(".");
|
|
1454
|
+
if (!localeClaims.has(lang)) {
|
|
1455
|
+
localeClaims.set(lang, []);
|
|
1456
|
+
}
|
|
1457
|
+
localeClaims.get(lang).push({
|
|
1458
|
+
key,
|
|
1459
|
+
name: label
|
|
1460
|
+
});
|
|
1461
|
+
});
|
|
1462
|
+
});
|
|
1463
|
+
return localeClaims;
|
|
1464
|
+
}, "sdJwtCredentialClaimLocalesFrom");
|
|
1465
|
+
var sdJwtCredentialLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1466
|
+
const { credentialDisplay } = args;
|
|
1467
|
+
return {
|
|
1468
|
+
...credentialDisplay.name && {
|
|
1469
|
+
alias: credentialDisplay.name
|
|
1268
1470
|
},
|
|
1269
|
-
|
|
1270
|
-
|
|
1471
|
+
...credentialDisplay.lang && {
|
|
1472
|
+
locale: credentialDisplay.lang
|
|
1271
1473
|
},
|
|
1272
|
-
...
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
},
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
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
|
-
})
|
|
1474
|
+
...credentialDisplay.rendering?.simple?.logo && {
|
|
1475
|
+
logo: {
|
|
1476
|
+
...credentialDisplay.rendering.simple.logo.uri && {
|
|
1477
|
+
uri: credentialDisplay.rendering.simple.logo.uri
|
|
1478
|
+
},
|
|
1479
|
+
...credentialDisplay.rendering.simple.logo.alt_text && {
|
|
1480
|
+
alt: credentialDisplay.rendering.simple.logo.alt_text
|
|
1481
|
+
}
|
|
1385
1482
|
}
|
|
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
|
|
1483
|
+
},
|
|
1484
|
+
...credentialDisplay.description && {
|
|
1485
|
+
description: credentialDisplay.description
|
|
1486
|
+
},
|
|
1487
|
+
...credentialDisplay.rendering?.simple?.text_color && {
|
|
1488
|
+
text: {
|
|
1489
|
+
color: credentialDisplay.rendering.simple.text_color
|
|
1404
1490
|
}
|
|
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
|
-
})
|
|
1491
|
+
},
|
|
1492
|
+
...credentialDisplay.rendering?.simple?.background_color && {
|
|
1493
|
+
background: {
|
|
1494
|
+
color: credentialDisplay.rendering.simple.background_color
|
|
1426
1495
|
}
|
|
1427
1496
|
}
|
|
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
1497
|
};
|
|
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
|
|
1498
|
+
}, "sdJwtCredentialLocaleBrandingFrom");
|
|
1499
|
+
var sdJwtCombineDisplayLocalesFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1500
|
+
const { credentialDisplayLocales = /* @__PURE__ */ new Map(), claimsMetadata = /* @__PURE__ */ new Map() } = args;
|
|
1501
|
+
const locales = Array.from(/* @__PURE__ */ new Set([
|
|
1502
|
+
...claimsMetadata.keys(),
|
|
1503
|
+
...credentialDisplayLocales.keys()
|
|
1504
|
+
]));
|
|
1505
|
+
return Promise.all(locales.map(async (locale) => {
|
|
1506
|
+
const display = credentialDisplayLocales.get(locale);
|
|
1507
|
+
const claims = claimsMetadata.get(locale);
|
|
1508
|
+
return {
|
|
1509
|
+
...display && await sdJwtCredentialLocaleBrandingFrom({
|
|
1510
|
+
credentialDisplay: display
|
|
1511
|
+
}),
|
|
1512
|
+
...locale.length > 0 && {
|
|
1513
|
+
locale
|
|
1506
1514
|
},
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1515
|
+
claims
|
|
1516
|
+
};
|
|
1517
|
+
}));
|
|
1518
|
+
}, "sdJwtCombineDisplayLocalesFrom");
|
|
1519
|
+
var issuerLocaleBrandingFrom = /* @__PURE__ */ __name(async (args) => {
|
|
1520
|
+
const { issuerDisplay, dynamicRegistrationClientMetadata } = args;
|
|
1521
|
+
return {
|
|
1522
|
+
...dynamicRegistrationClientMetadata?.client_name && {
|
|
1523
|
+
alias: dynamicRegistrationClientMetadata.client_name
|
|
1524
|
+
},
|
|
1525
|
+
...issuerDisplay.name && {
|
|
1526
|
+
alias: issuerDisplay.name
|
|
1527
|
+
},
|
|
1528
|
+
...issuerDisplay.locale && {
|
|
1529
|
+
locale: issuerDisplay.locale
|
|
1530
|
+
},
|
|
1531
|
+
...(issuerDisplay.logo || dynamicRegistrationClientMetadata?.logo_uri) && {
|
|
1532
|
+
logo: {
|
|
1533
|
+
...dynamicRegistrationClientMetadata?.logo_uri && {
|
|
1534
|
+
uri: dynamicRegistrationClientMetadata?.logo_uri
|
|
1535
|
+
},
|
|
1536
|
+
...(issuerDisplay.logo?.url || issuerDisplay.logo?.uri) && {
|
|
1537
|
+
uri: issuerDisplay.logo?.url ?? issuerDisplay.logo?.uri
|
|
1538
|
+
},
|
|
1539
|
+
...issuerDisplay.logo?.alt_text && {
|
|
1540
|
+
alt: issuerDisplay.logo?.alt_text
|
|
1518
1541
|
}
|
|
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
1542
|
}
|
|
1528
|
-
|
|
1543
|
+
},
|
|
1544
|
+
...issuerDisplay.description && {
|
|
1545
|
+
description: issuerDisplay.description
|
|
1546
|
+
},
|
|
1547
|
+
...issuerDisplay.text_color && {
|
|
1548
|
+
text: {
|
|
1549
|
+
color: issuerDisplay.text_color
|
|
1550
|
+
}
|
|
1551
|
+
},
|
|
1552
|
+
...dynamicRegistrationClientMetadata?.client_uri && {
|
|
1553
|
+
clientUri: dynamicRegistrationClientMetadata.client_uri
|
|
1554
|
+
},
|
|
1555
|
+
...dynamicRegistrationClientMetadata?.tos_uri && {
|
|
1556
|
+
tosUri: dynamicRegistrationClientMetadata.tos_uri
|
|
1557
|
+
},
|
|
1558
|
+
...dynamicRegistrationClientMetadata?.policy_uri && {
|
|
1559
|
+
policyUri: dynamicRegistrationClientMetadata.policy_uri
|
|
1560
|
+
},
|
|
1561
|
+
...dynamicRegistrationClientMetadata?.contacts && {
|
|
1562
|
+
contacts: dynamicRegistrationClientMetadata.contacts
|
|
1529
1563
|
}
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
};
|
|
1564
|
+
};
|
|
1565
|
+
}, "issuerLocaleBrandingFrom");
|
|
1533
1566
|
|
|
1534
1567
|
// src/services/OID4VCIHolderService.ts
|
|
1535
|
-
import { defaultHasher } from "@sphereon/ssi-sdk.core";
|
|
1536
1568
|
var getCredentialBranding = /* @__PURE__ */ __name(async (args) => {
|
|
1537
1569
|
const { credentialsSupported, context } = args;
|
|
1538
1570
|
const credentialBranding = {};
|
|
1539
1571
|
await Promise.all(Object.entries(credentialsSupported).map(async ([configId, credentialsConfigSupported]) => {
|
|
1540
1572
|
let sdJwtTypeMetadata;
|
|
1541
|
-
if (credentialsConfigSupported.format === "
|
|
1573
|
+
if (credentialsConfigSupported.format === "dc+sd-jwt") {
|
|
1542
1574
|
const vct = credentialsConfigSupported.vct;
|
|
1543
1575
|
if (vct.startsWith("http")) {
|
|
1544
1576
|
try {
|
|
@@ -1604,10 +1636,7 @@ var selectCredentialLocaleBranding = /* @__PURE__ */ __name(async (args) => {
|
|
|
1604
1636
|
}, "selectCredentialLocaleBranding");
|
|
1605
1637
|
var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
1606
1638
|
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
|
-
}
|
|
1639
|
+
const credential = extractCredentialFromResponse(mappedCredential.credentialToAccept.credentialResponse);
|
|
1611
1640
|
const wrappedVC = CredentialMapper.toWrappedVerifiableCredential(credential, {
|
|
1612
1641
|
hasher: hasher ?? defaultHasher
|
|
1613
1642
|
});
|
|
@@ -1659,17 +1688,13 @@ var verifyCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
|
1659
1688
|
}, "verifyCredentialToAccept");
|
|
1660
1689
|
var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
1661
1690
|
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
|
-
}
|
|
1691
|
+
const verifiableCredential = extractCredentialFromResponse(credentialToAccept.credentialResponse);
|
|
1667
1692
|
const wrappedVerifiableCredential = CredentialMapper.toWrappedVerifiableCredential(verifiableCredential, {
|
|
1668
1693
|
hasher
|
|
1669
1694
|
});
|
|
1670
1695
|
let uniformVerifiableCredential;
|
|
1671
1696
|
if (CredentialMapper.isSdJwtDecodedCredential(wrappedVerifiableCredential.credential)) {
|
|
1672
|
-
uniformVerifiableCredential =
|
|
1697
|
+
uniformVerifiableCredential = sdJwtDecodedCredentialToUniformCredential(wrappedVerifiableCredential.credential);
|
|
1673
1698
|
} else if (CredentialMapper.isSdJwtEncoded(wrappedVerifiableCredential.credential)) {
|
|
1674
1699
|
if (!hasher) {
|
|
1675
1700
|
return Promise.reject("a hasher is required for encoded SD-JWT credentials");
|
|
@@ -1683,6 +1708,7 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
|
1683
1708
|
uniformVerifiableCredential = wrappedVerifiableCredential.credential;
|
|
1684
1709
|
}
|
|
1685
1710
|
const correlationId = typeof uniformVerifiableCredential.issuer === "string" ? uniformVerifiableCredential.issuer : CredentialMapper.isSdJwtDecodedCredential(uniformVerifiableCredential) ? uniformVerifiableCredential.decodedPayload.iss : uniformVerifiableCredential.issuer.id;
|
|
1711
|
+
const credentialResponse = credentialToAccept.credentialResponse;
|
|
1686
1712
|
return {
|
|
1687
1713
|
correlationId,
|
|
1688
1714
|
credentialToAccept,
|
|
@@ -1694,6 +1720,18 @@ var mapCredentialToAccept = /* @__PURE__ */ __name(async (args) => {
|
|
|
1694
1720
|
}
|
|
1695
1721
|
};
|
|
1696
1722
|
}, "mapCredentialToAccept");
|
|
1723
|
+
var extractCredentialFromResponse = /* @__PURE__ */ __name((credentialResponse) => {
|
|
1724
|
+
let credential;
|
|
1725
|
+
if ("credential" in credentialResponse) {
|
|
1726
|
+
credential = credentialResponse.credential;
|
|
1727
|
+
} else if ("credentials" in credentialResponse && credentialResponse.credentials && Array.isArray(credentialResponse.credentials) && credentialResponse.credentials.length > 0) {
|
|
1728
|
+
credential = credentialResponse.credentials[0].credential;
|
|
1729
|
+
}
|
|
1730
|
+
if (!credential) {
|
|
1731
|
+
throw new Error("No credential found in credential response");
|
|
1732
|
+
}
|
|
1733
|
+
return credential;
|
|
1734
|
+
}, "extractCredentialFromResponse");
|
|
1697
1735
|
var getIdentifierOpts = /* @__PURE__ */ __name(async (args) => {
|
|
1698
1736
|
const { issuanceOpt, context } = args;
|
|
1699
1737
|
const { identifier: identifierArg } = issuanceOpt;
|
|
@@ -1802,24 +1840,19 @@ var getCredentialConfigsSupportedBySingleTypeOrId = /* @__PURE__ */ __name(async
|
|
|
1802
1840
|
}
|
|
1803
1841
|
__name(createIdFromTypes, "createIdFromTypes");
|
|
1804
1842
|
if (configurationId) {
|
|
1805
|
-
const allSupported2 = client.getCredentialsSupported(
|
|
1843
|
+
const allSupported2 = client.getCredentialsSupported(void 0, format);
|
|
1806
1844
|
return Object.fromEntries(Object.entries(allSupported2).filter(([id, supported]) => id === configurationId || supported.id === configurationId || createIdFromTypes(supported) === configurationId));
|
|
1807
1845
|
}
|
|
1808
|
-
if (!
|
|
1809
|
-
return Promise.reject(Error("openID4VCIClient has no credentialOffer
|
|
1846
|
+
if (!client.credentialOffer) {
|
|
1847
|
+
return Promise.reject(Error("openID4VCIClient has no credentialOffer"));
|
|
1810
1848
|
}
|
|
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
|
-
}
|
|
1849
|
+
if (!types) {
|
|
1850
|
+
return Promise.reject(Error("openID4VCIClient has no types"));
|
|
1818
1851
|
}
|
|
1819
1852
|
const offerSupported = getSupportedCredentials({
|
|
1820
|
-
types:
|
|
1853
|
+
types: [
|
|
1821
1854
|
types
|
|
1822
|
-
]
|
|
1855
|
+
],
|
|
1823
1856
|
format,
|
|
1824
1857
|
version: client.version(),
|
|
1825
1858
|
issuerMetadata: client.endpointMetadata.credentialIssuerMetadata
|
|
@@ -1994,7 +2027,8 @@ var getIssuanceCryptoSuite = /* @__PURE__ */ __name(async (opts) => {
|
|
|
1994
2027
|
case "jwt":
|
|
1995
2028
|
case "jwt_vc_json":
|
|
1996
2029
|
case "jwt_vc":
|
|
1997
|
-
case
|
|
2030
|
+
//case 'vc+sd-jwt': // TODO see SSISDK-52 concerning vc+sd-jwt
|
|
2031
|
+
case "dc+sd-jwt":
|
|
1998
2032
|
case "mso_mdoc": {
|
|
1999
2033
|
const supportedPreferences = jwtCryptographicSuitePreferences.filter((suite) => signing_algs_supported.includes(suite));
|
|
2000
2034
|
if (supportedPreferences.length > 0) {
|
|
@@ -2062,8 +2096,6 @@ var startFirstPartApplicationMachine = /* @__PURE__ */ __name(async (args, conte
|
|
|
2062
2096
|
}, "startFirstPartApplicationMachine");
|
|
2063
2097
|
|
|
2064
2098
|
// src/agent/OID4VCIHolder.ts
|
|
2065
|
-
import "cross-fetch/polyfill";
|
|
2066
|
-
import { defaultHasher as defaultHasher2 } from "@sphereon/ssi-sdk.core";
|
|
2067
2099
|
var oid4vciHolderContextMethods = [
|
|
2068
2100
|
"cmGetContacts",
|
|
2069
2101
|
"cmGetContact",
|
|
@@ -2079,7 +2111,7 @@ var oid4vciHolderContextMethods = [
|
|
|
2079
2111
|
];
|
|
2080
2112
|
var logger = Loggers.DEFAULT.get("sphereon:oid4vci:holder");
|
|
2081
2113
|
function signCallback(identifier, context, nonce) {
|
|
2082
|
-
return async (jwt, kid) => {
|
|
2114
|
+
return async (jwt, kid, noIssPayloadUpdate) => {
|
|
2083
2115
|
let resolution = await context.agent.identifierManagedGet(identifier);
|
|
2084
2116
|
const jwk = jwt.header.jwk ?? (resolution.method === "jwk" ? resolution.jwk : void 0);
|
|
2085
2117
|
if (!resolution.issuer && !jwt.payload.iss) {
|
|
@@ -2097,7 +2129,7 @@ function signCallback(identifier, context, nonce) {
|
|
|
2097
2129
|
return (await context.agent.jwtCreateJwsCompactSignature({
|
|
2098
2130
|
issuer: {
|
|
2099
2131
|
...resolution,
|
|
2100
|
-
noIssPayloadUpdate: false
|
|
2132
|
+
noIssPayloadUpdate: noIssPayloadUpdate ?? false
|
|
2101
2133
|
},
|
|
2102
2134
|
protectedHeader: header,
|
|
2103
2135
|
payload
|
|
@@ -2119,6 +2151,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2119
2151
|
oid4vciHolderStart: this.oid4vciHolderStart.bind(this),
|
|
2120
2152
|
oid4vciHolderGetIssuerMetadata: this.oid4vciHolderGetIssuerMetadata.bind(this),
|
|
2121
2153
|
oid4vciHolderGetMachineInterpreter: this.oid4vciHolderGetMachineInterpreter.bind(this),
|
|
2154
|
+
oid4vciHolderPrepareAuthorizationRequest: this.oid4vciHolderPrepareAuthorizationRequest.bind(this),
|
|
2122
2155
|
oid4vciHolderCreateCredentialsToSelectFrom: this.oid4vciHolderCreateCredentialsToSelectFrom.bind(this),
|
|
2123
2156
|
oid4vciHolderGetContact: this.oid4vciHolderGetContact.bind(this),
|
|
2124
2157
|
oid4vciHolderGetCredentials: this.oid4vciHolderGetCredentials.bind(this),
|
|
@@ -2132,6 +2165,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2132
2165
|
oid4vciHolderStoreIssuerBranding: this.oid4vciHolderStoreIssuerBranding.bind(this)
|
|
2133
2166
|
};
|
|
2134
2167
|
vcFormatPreferences = [
|
|
2168
|
+
"dc+sd-jwt",
|
|
2135
2169
|
"vc+sd-jwt",
|
|
2136
2170
|
"mso_mdoc",
|
|
2137
2171
|
"jwt_vc_json",
|
|
@@ -2222,6 +2256,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2222
2256
|
stateNavigationListener: opts.firstPartyStateNavigationListener
|
|
2223
2257
|
}, context),
|
|
2224
2258
|
[OID4VCIMachineServices.createCredentialsToSelectFrom]: (args) => this.oid4vciHolderCreateCredentialsToSelectFrom(args, context),
|
|
2259
|
+
[OID4VCIMachineServices.prepareAuthorizationRequest]: (args) => this.oid4vciHolderPrepareAuthorizationRequest(args, context),
|
|
2225
2260
|
[OID4VCIMachineServices.getContact]: (args) => this.oid4vciHolderGetContact(args, context),
|
|
2226
2261
|
[OID4VCIMachineServices.getCredentials]: (args) => this.oid4vciHolderGetCredentials({
|
|
2227
2262
|
accessTokenOpts: args.accessTokenOpts ?? opts.accessTokenOpts,
|
|
@@ -2270,7 +2305,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2270
2305
|
...this.defaultAuthorizationRequestOpts,
|
|
2271
2306
|
...args.authorizationRequestOpts
|
|
2272
2307
|
};
|
|
2273
|
-
authorizationRequestOpts.authorizationDetails = authorizationRequestOpts?.authorizationDetails ? asArray2(authorizationRequestOpts.authorizationDetails)
|
|
2308
|
+
authorizationRequestOpts.authorizationDetails = authorizationRequestOpts?.authorizationDetails ? asArray2(authorizationRequestOpts.authorizationDetails) : void 0;
|
|
2274
2309
|
if (!authorizationRequestOpts.redirectUri) {
|
|
2275
2310
|
authorizationRequestOpts.redirectUri = _OID4VCIHolder.DEFAULT_MOBILE_REDIRECT_URI;
|
|
2276
2311
|
}
|
|
@@ -2283,10 +2318,9 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2283
2318
|
formats = Array.from(new Set(authFormats));
|
|
2284
2319
|
}
|
|
2285
2320
|
let oid4vciClient;
|
|
2286
|
-
let types = void 0;
|
|
2287
2321
|
let offer;
|
|
2288
2322
|
if (requestData.existingClientState) {
|
|
2289
|
-
oid4vciClient = await
|
|
2323
|
+
oid4vciClient = await OpenID4VCIClientV1_0_15.fromState({
|
|
2290
2324
|
state: requestData.existingClientState
|
|
2291
2325
|
});
|
|
2292
2326
|
offer = oid4vciClient.credentialOffer;
|
|
@@ -2303,50 +2337,76 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2303
2337
|
}
|
|
2304
2338
|
if (!offer) {
|
|
2305
2339
|
logger.log(`Issuer url received (no credential offer): ${uri}`);
|
|
2306
|
-
oid4vciClient = await
|
|
2340
|
+
oid4vciClient = await OpenID4VCIClientV1_0_15.fromCredentialIssuer({
|
|
2307
2341
|
credentialIssuer: uri,
|
|
2308
2342
|
authorizationRequest: authorizationRequestOpts,
|
|
2309
2343
|
clientId: authorizationRequestOpts.clientId,
|
|
2310
|
-
createAuthorizationRequestURL:
|
|
2344
|
+
createAuthorizationRequestURL: false
|
|
2311
2345
|
});
|
|
2312
2346
|
} else {
|
|
2313
2347
|
logger.log(`Credential offer received: ${uri}`);
|
|
2314
|
-
oid4vciClient = await
|
|
2348
|
+
oid4vciClient = await OpenID4VCIClientV1_0_15.fromURI({
|
|
2315
2349
|
uri,
|
|
2316
2350
|
authorizationRequest: authorizationRequestOpts,
|
|
2317
2351
|
clientId: authorizationRequestOpts.clientId,
|
|
2318
|
-
createAuthorizationRequestURL:
|
|
2352
|
+
createAuthorizationRequestURL: false
|
|
2319
2353
|
});
|
|
2320
2354
|
}
|
|
2321
2355
|
}
|
|
2356
|
+
let configurationIds = [];
|
|
2322
2357
|
if (offer) {
|
|
2323
|
-
|
|
2358
|
+
configurationIds = offer.original_credential_offer.credential_configuration_ids;
|
|
2324
2359
|
} else {
|
|
2325
|
-
|
|
2360
|
+
configurationIds = asArray2(authorizationRequestOpts.authorizationDetails).map((authReqOpts) => authReqOpts.credential_configuration_id).filter((id) => !!id);
|
|
2326
2361
|
}
|
|
2327
|
-
const serverMetadata = await oid4vciClient.retrieveServerMetadata();
|
|
2328
2362
|
const credentialsSupported = await getCredentialConfigsSupportedMerged({
|
|
2329
2363
|
client: oid4vciClient,
|
|
2330
2364
|
vcFormatPreferences: formats,
|
|
2331
|
-
|
|
2365
|
+
configurationIds
|
|
2332
2366
|
});
|
|
2367
|
+
const serverMetadata = await oid4vciClient.retrieveServerMetadata();
|
|
2333
2368
|
const credentialBranding = await getCredentialBranding({
|
|
2334
2369
|
credentialsSupported,
|
|
2335
2370
|
context
|
|
2336
2371
|
});
|
|
2337
|
-
const authorizationCodeURL = oid4vciClient.authorizationURL;
|
|
2338
|
-
if (authorizationCodeURL) {
|
|
2339
|
-
logger.log(`authorization code URL ${authorizationCodeURL}`);
|
|
2340
|
-
}
|
|
2341
2372
|
const oid4vciClientState = JSON.parse(await oid4vciClient.exportState());
|
|
2342
2373
|
return {
|
|
2343
|
-
authorizationCodeURL,
|
|
2344
2374
|
credentialBranding,
|
|
2345
2375
|
credentialsSupported,
|
|
2346
2376
|
serverMetadata,
|
|
2347
2377
|
oid4vciClientState
|
|
2348
2378
|
};
|
|
2349
2379
|
}
|
|
2380
|
+
async oid4vciHolderPrepareAuthorizationRequest(args, context) {
|
|
2381
|
+
const { openID4VCIClientState, contact } = args;
|
|
2382
|
+
if (!openID4VCIClientState) {
|
|
2383
|
+
return Promise.reject(Error("Missing openID4VCI client state in context"));
|
|
2384
|
+
}
|
|
2385
|
+
const clientId = contact?.identities.map((identity) => {
|
|
2386
|
+
const connectionConfig = identity.connection?.config;
|
|
2387
|
+
if (connectionConfig && "clientId" in connectionConfig) {
|
|
2388
|
+
return connectionConfig.clientId;
|
|
2389
|
+
}
|
|
2390
|
+
return void 0;
|
|
2391
|
+
}).find((clientId2) => clientId2);
|
|
2392
|
+
if (!clientId) {
|
|
2393
|
+
return Promise.reject(Error(`Missing client id in contact's connectionConfig`));
|
|
2394
|
+
}
|
|
2395
|
+
const client = await OpenID4VCIClient2.fromState({
|
|
2396
|
+
state: openID4VCIClientState
|
|
2397
|
+
});
|
|
2398
|
+
const authorizationCodeURL = await client.createAuthorizationRequestUrl({
|
|
2399
|
+
authorizationRequest: {
|
|
2400
|
+
clientId
|
|
2401
|
+
}
|
|
2402
|
+
});
|
|
2403
|
+
if (authorizationCodeURL) {
|
|
2404
|
+
logger.log(`authorization code URL ${authorizationCodeURL}`);
|
|
2405
|
+
}
|
|
2406
|
+
return {
|
|
2407
|
+
authorizationCodeURL
|
|
2408
|
+
};
|
|
2409
|
+
}
|
|
2350
2410
|
async oid4vciHolderCreateCredentialsToSelectFrom(args, context) {
|
|
2351
2411
|
const { credentialBranding, locale, selectedCredentials, credentialsSupported } = args;
|
|
2352
2412
|
logger.info(`Credentials supported ${Object.keys(credentialsSupported).join(", ")}`);
|
|
@@ -2418,7 +2478,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2418
2478
|
if (!openID4VCIClientState) {
|
|
2419
2479
|
return Promise.reject(Error("Missing openID4VCI client state in context"));
|
|
2420
2480
|
}
|
|
2421
|
-
const client = await
|
|
2481
|
+
const client = await OpenID4VCIClientV1_0_15.fromState({
|
|
2422
2482
|
state: openID4VCIClientState
|
|
2423
2483
|
});
|
|
2424
2484
|
const credentialsSupported = await getCredentialConfigsSupportedMerged({
|
|
@@ -2658,9 +2718,19 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2658
2718
|
}
|
|
2659
2719
|
let counter = 0;
|
|
2660
2720
|
for (const credentialId of selectedCredentials) {
|
|
2661
|
-
const
|
|
2721
|
+
const configId = credentialId;
|
|
2722
|
+
const types = credentialsToAccept.find((ac) => ac.correlationId === configId || ac.credentialToAccept.id === configId || ac.types.includes(configId))?.types?.filter((type) => type != "VerifiableCredential") ?? [];
|
|
2723
|
+
const localeBranding = credentialBranding?.[configId] ?? [];
|
|
2724
|
+
if (localeBranding.length === 0) {
|
|
2725
|
+
for (const type of types) {
|
|
2726
|
+
const branding = credentialBranding?.[type] ?? [];
|
|
2727
|
+
if (branding.length > 0) {
|
|
2728
|
+
localeBranding.push(...branding);
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2662
2732
|
if (localeBranding && localeBranding.length > 0) {
|
|
2663
|
-
const credential = credentialsToAccept.find((credAccept) => credAccept.credentialToAccept.id === credentialId || JSON.stringify(credAccept.types) === credentialId || credentialsToAccept[counter]);
|
|
2733
|
+
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
2734
|
counter++;
|
|
2665
2735
|
await context.agent.ibAddCredentialBranding({
|
|
2666
2736
|
vcHash: computeEntryHash(credential.rawVerifiableCredential),
|
|
@@ -2708,7 +2778,7 @@ var OID4VCIHolder = class _OID4VCIHolder {
|
|
|
2708
2778
|
if (Array.isArray(subjectIssuance?.notification_events_supported)) {
|
|
2709
2779
|
event = subjectIssuance.notification_events_supported.includes("credential_accepted_holder_signed") ? "credential_accepted_holder_signed" : "credential_deleted_holder_signed";
|
|
2710
2780
|
logger.log(`Subject issuance/signing will be used, with event`, event);
|
|
2711
|
-
const issuerVC = mappedCredentialToAccept.credentialToAccept.credentialResponse
|
|
2781
|
+
const issuerVC = extractCredentialFromResponse(mappedCredentialToAccept.credentialToAccept.credentialResponse);
|
|
2712
2782
|
const wrappedIssuerVC = CredentialMapper2.toWrappedVerifiableCredential(issuerVC, {
|
|
2713
2783
|
hasher: this.hasher ?? defaultHasher2
|
|
2714
2784
|
});
|
|
@@ -3079,6 +3149,7 @@ export {
|
|
|
3079
3149
|
RequestType,
|
|
3080
3150
|
SupportedLanguage,
|
|
3081
3151
|
createConfig,
|
|
3152
|
+
extractCredentialFromResponse,
|
|
3082
3153
|
getBasicIssuerLocaleBranding,
|
|
3083
3154
|
getCredentialBranding,
|
|
3084
3155
|
getCredentialConfigsBasedOnFormatPref,
|