@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.33.1-next.2 → 0.33.1-next.68
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 +2451 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +559 -0
- package/dist/index.d.ts +555 -8
- package/dist/index.js +2420 -31
- package/dist/index.js.map +1 -1
- package/package.json +41 -30
- package/src/agent/DidAuthSiopOpAuthenticator.ts +13 -14
- package/src/session/OpSession.ts +13 -13
- package/dist/agent/DidAuthSiopOpAuthenticator.d.ts +0 -36
- package/dist/agent/DidAuthSiopOpAuthenticator.d.ts.map +0 -1
- package/dist/agent/DidAuthSiopOpAuthenticator.js +0 -392
- package/dist/agent/DidAuthSiopOpAuthenticator.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/link-handler/index.d.ts +0 -22
- package/dist/link-handler/index.d.ts.map +0 -1
- package/dist/link-handler/index.js +0 -57
- package/dist/link-handler/index.js.map +0 -1
- package/dist/localization/Localization.d.ts +0 -9
- package/dist/localization/Localization.d.ts.map +0 -1
- package/dist/localization/Localization.js +0 -46
- package/dist/localization/Localization.js.map +0 -1
- package/dist/localization/translations/en.json +0 -9
- package/dist/localization/translations/nl.json +0 -8
- package/dist/machine/CallbackStateListener.d.ts +0 -3
- package/dist/machine/CallbackStateListener.d.ts.map +0 -1
- package/dist/machine/CallbackStateListener.js +0 -48
- package/dist/machine/CallbackStateListener.js.map +0 -1
- package/dist/machine/Siopv2Machine.d.ts +0 -8
- package/dist/machine/Siopv2Machine.d.ts.map +0 -1
- package/dist/machine/Siopv2Machine.js +0 -364
- package/dist/machine/Siopv2Machine.js.map +0 -1
- package/dist/services/IdentifierService.d.ts +0 -3
- package/dist/services/IdentifierService.d.ts.map +0 -1
- package/dist/services/IdentifierService.js +0 -28
- package/dist/services/IdentifierService.js.map +0 -1
- package/dist/services/Siopv2MachineService.d.ts +0 -18
- package/dist/services/Siopv2MachineService.d.ts.map +0 -1
- package/dist/services/Siopv2MachineService.js +0 -299
- package/dist/services/Siopv2MachineService.js.map +0 -1
- package/dist/session/OID4VP.d.ts +0 -72
- package/dist/session/OID4VP.d.ts.map +0 -1
- package/dist/session/OID4VP.js +0 -224
- package/dist/session/OID4VP.js.map +0 -1
- package/dist/session/OpSession.d.ts +0 -39
- package/dist/session/OpSession.d.ts.map +0 -1
- package/dist/session/OpSession.js +0 -365
- package/dist/session/OpSession.js.map +0 -1
- package/dist/session/functions.d.ts +0 -37
- package/dist/session/functions.d.ts.map +0 -1
- package/dist/session/functions.js +0 -163
- package/dist/session/functions.js.map +0 -1
- package/dist/session/index.d.ts +0 -4
- package/dist/session/index.d.ts.map +0 -1
- package/dist/session/index.js +0 -20
- package/dist/session/index.js.map +0 -1
- package/dist/types/IDidAuthSiopOpAuthenticator.d.ts +0 -120
- package/dist/types/IDidAuthSiopOpAuthenticator.d.ts.map +0 -1
- package/dist/types/IDidAuthSiopOpAuthenticator.js +0 -10
- package/dist/types/IDidAuthSiopOpAuthenticator.js.map +0 -1
- package/dist/types/error/index.d.ts +0 -8
- package/dist/types/error/index.d.ts.map +0 -1
- package/dist/types/error/index.js +0 -3
- package/dist/types/error/index.js.map +0 -1
- package/dist/types/identifier/index.d.ts +0 -53
- package/dist/types/identifier/index.d.ts.map +0 -1
- package/dist/types/identifier/index.js +0 -5
- package/dist/types/identifier/index.js.map +0 -1
- package/dist/types/index.d.ts +0 -6
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -22
- package/dist/types/index.js.map +0 -1
- package/dist/types/machine/index.d.ts +0 -124
- package/dist/types/machine/index.d.ts.map +0 -1
- package/dist/types/machine/index.js +0 -57
- package/dist/types/machine/index.js.map +0 -1
- package/dist/types/siop-service/index.d.ts +0 -80
- package/dist/types/siop-service/index.d.ts.map +0 -1
- package/dist/types/siop-service/index.js +0 -14
- package/dist/types/siop-service/index.js.map +0 -1
- package/dist/utils/CredentialUtils.d.ts +0 -23
- package/dist/utils/CredentialUtils.d.ts.map +0 -1
- package/dist/utils/CredentialUtils.js +0 -65
- package/dist/utils/CredentialUtils.js.map +0 -1
- package/dist/utils/dcql.d.ts +0 -5
- package/dist/utils/dcql.d.ts.map +0 -1
- package/dist/utils/dcql.js +0 -37
- package/dist/utils/dcql.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2451 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
};
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
32
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
|
|
34
|
+
// src/localization/translations/en.json
|
|
35
|
+
var require_en = __commonJS({
|
|
36
|
+
"src/localization/translations/en.json"(exports, module2) {
|
|
37
|
+
module2.exports = {
|
|
38
|
+
siopv2_machine_identifier_error_title: "Getting identifier",
|
|
39
|
+
siopv2_machine_create_config_error_title: "Creating siopV2 config",
|
|
40
|
+
siopv2_machine_get_request_error_title: "Getting siopV2 request",
|
|
41
|
+
siopv2_machine_get_selectable_credentials_error_title: "Getting siopV2 selectable credentials",
|
|
42
|
+
siopv2_machine_retrieve_contact_error_title: "Retrieve contact",
|
|
43
|
+
siopv2_machine_add_contact_identity_error_title: "Add contact identity",
|
|
44
|
+
siopv2_machine_send_response_error_title: "Sending siopV2 response"
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// src/localization/translations/nl.json
|
|
50
|
+
var require_nl = __commonJS({
|
|
51
|
+
"src/localization/translations/nl.json"(exports, module2) {
|
|
52
|
+
module2.exports = {
|
|
53
|
+
siopv2_machine_identifier_error_title: "Identifier ophalen",
|
|
54
|
+
siopv2_machine_create_config_error_title: "SiopV2 configuratie maken",
|
|
55
|
+
siopv2_machine_get_request_error_title: "SiopV2 verzoek ophalen",
|
|
56
|
+
siopv2_machine_retrieve_contact_error_title: "Ophalen credential",
|
|
57
|
+
siopv2_machine_add_contact_identity_error_title: "Toevoegen identiteit contact",
|
|
58
|
+
siopv2_machine_send_response_error_title: "SiopV2 antwoord verzenden"
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// plugin.schema.json
|
|
64
|
+
var require_plugin_schema = __commonJS({
|
|
65
|
+
"plugin.schema.json"(exports, module2) {
|
|
66
|
+
module2.exports = {
|
|
67
|
+
IDidAuthSiopOpAuthenticator: {
|
|
68
|
+
components: {
|
|
69
|
+
schemas: {
|
|
70
|
+
IGetSiopSessionArgs: {
|
|
71
|
+
type: "object",
|
|
72
|
+
properties: {
|
|
73
|
+
sessionId: {
|
|
74
|
+
type: "string"
|
|
75
|
+
},
|
|
76
|
+
additionalProperties: false
|
|
77
|
+
},
|
|
78
|
+
required: ["sessionId"],
|
|
79
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.getSessionForSiop } "
|
|
80
|
+
},
|
|
81
|
+
IRegisterSiopSessionArgs: {
|
|
82
|
+
type: "object",
|
|
83
|
+
properties: {
|
|
84
|
+
identifier: {
|
|
85
|
+
type: "object",
|
|
86
|
+
properties: {
|
|
87
|
+
did: {
|
|
88
|
+
type: "string"
|
|
89
|
+
},
|
|
90
|
+
alias: {
|
|
91
|
+
type: "string"
|
|
92
|
+
},
|
|
93
|
+
provider: {
|
|
94
|
+
type: "string"
|
|
95
|
+
},
|
|
96
|
+
controllerKeyId: {
|
|
97
|
+
type: "string"
|
|
98
|
+
},
|
|
99
|
+
keys: {
|
|
100
|
+
type: "array",
|
|
101
|
+
items: {
|
|
102
|
+
type: "object",
|
|
103
|
+
properties: {
|
|
104
|
+
additionalProperties: true
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
services: {
|
|
109
|
+
type: "array",
|
|
110
|
+
items: {
|
|
111
|
+
type: "object",
|
|
112
|
+
properties: {
|
|
113
|
+
additionalProperties: true
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
additionalProperties: false,
|
|
119
|
+
required: ["did", "provider", "keys", "services"]
|
|
120
|
+
},
|
|
121
|
+
sessionId: {
|
|
122
|
+
type: "string"
|
|
123
|
+
},
|
|
124
|
+
expiresIn: {
|
|
125
|
+
type: "number"
|
|
126
|
+
},
|
|
127
|
+
additionalProperties: false
|
|
128
|
+
},
|
|
129
|
+
required: ["identifier"],
|
|
130
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.registerSessionForSiop } "
|
|
131
|
+
},
|
|
132
|
+
IRemoveSiopSessionArgs: {
|
|
133
|
+
type: "object",
|
|
134
|
+
properties: {
|
|
135
|
+
sessionId: {
|
|
136
|
+
type: "string"
|
|
137
|
+
},
|
|
138
|
+
additionalProperties: false
|
|
139
|
+
},
|
|
140
|
+
required: ["sessionId"],
|
|
141
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.removeSessionForSiop } "
|
|
142
|
+
},
|
|
143
|
+
IAuthenticateWithSiopArgs: {
|
|
144
|
+
type: "object",
|
|
145
|
+
properties: {
|
|
146
|
+
sessionId: {
|
|
147
|
+
type: "string"
|
|
148
|
+
},
|
|
149
|
+
stateId: {
|
|
150
|
+
type: "string"
|
|
151
|
+
},
|
|
152
|
+
redirectUrl: {
|
|
153
|
+
type: "string"
|
|
154
|
+
},
|
|
155
|
+
additionalProperties: false
|
|
156
|
+
},
|
|
157
|
+
required: ["sessionId", "stateId", "redirectUrl"],
|
|
158
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.authenticateWithSiop } "
|
|
159
|
+
},
|
|
160
|
+
IResponse: {
|
|
161
|
+
type: "object",
|
|
162
|
+
properties: {
|
|
163
|
+
status: {
|
|
164
|
+
type: "number"
|
|
165
|
+
},
|
|
166
|
+
additionalProperties: true
|
|
167
|
+
},
|
|
168
|
+
required: ["status"],
|
|
169
|
+
description: "Result of {@link DidAuthSiopOpAuthenticator.authenticateWithSiop & DidAuthSiopOpAuthenticator.sendSiopAuthenticationResponse } "
|
|
170
|
+
},
|
|
171
|
+
IGetSiopAuthenticationRequestFromRpArgs: {
|
|
172
|
+
type: "object",
|
|
173
|
+
properties: {
|
|
174
|
+
sessionId: {
|
|
175
|
+
type: "string"
|
|
176
|
+
},
|
|
177
|
+
stateId: {
|
|
178
|
+
type: "string"
|
|
179
|
+
},
|
|
180
|
+
redirectUrl: {
|
|
181
|
+
type: "string"
|
|
182
|
+
},
|
|
183
|
+
additionalProperties: false
|
|
184
|
+
},
|
|
185
|
+
required: ["sessionId", "stateId", "redirectUrl"],
|
|
186
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.getSiopAuthenticationRequestFromRP } "
|
|
187
|
+
},
|
|
188
|
+
ParsedAuthenticationRequestURI: {
|
|
189
|
+
type: "object",
|
|
190
|
+
properties: {
|
|
191
|
+
jwt: {
|
|
192
|
+
type: "string"
|
|
193
|
+
},
|
|
194
|
+
requestPayload: {
|
|
195
|
+
type: "object",
|
|
196
|
+
properties: {
|
|
197
|
+
additionalProperties: true
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
registration: {
|
|
201
|
+
type: "object",
|
|
202
|
+
properties: {
|
|
203
|
+
additionalProperties: true
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
additionalProperties: false
|
|
207
|
+
},
|
|
208
|
+
required: ["jwt", "requestPayload", "registration"],
|
|
209
|
+
description: "Result of {@link DidAuthSiopOpAuthenticator.getSiopAuthenticationRequestFromRP } "
|
|
210
|
+
},
|
|
211
|
+
IGetSiopAuthenticationRequestDetailsArgs: {
|
|
212
|
+
type: "object",
|
|
213
|
+
properties: {
|
|
214
|
+
sessionId: {
|
|
215
|
+
type: "string"
|
|
216
|
+
},
|
|
217
|
+
verifiedAuthenticationRequest: {
|
|
218
|
+
type: "object",
|
|
219
|
+
properties: {
|
|
220
|
+
additionalProperties: true
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
credentialFilter: {
|
|
224
|
+
type: "object",
|
|
225
|
+
properties: {
|
|
226
|
+
additionalProperties: true
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
additionalProperties: false
|
|
230
|
+
},
|
|
231
|
+
required: ["sessionId", "verifiedAuthenticationRequest"],
|
|
232
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.getSiopAuthenticationRequestDetails } "
|
|
233
|
+
},
|
|
234
|
+
IAuthRequestDetails: {
|
|
235
|
+
type: "object",
|
|
236
|
+
properties: {
|
|
237
|
+
id: {
|
|
238
|
+
type: "string"
|
|
239
|
+
},
|
|
240
|
+
alsoKnownAs: {
|
|
241
|
+
type: "array",
|
|
242
|
+
items: {
|
|
243
|
+
type: "string"
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
vpResponseOpts: {
|
|
247
|
+
type: "object",
|
|
248
|
+
properties: {
|
|
249
|
+
additionalProperties: true
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
additionalProperties: false
|
|
253
|
+
},
|
|
254
|
+
required: ["id", "vpResponseOpts"],
|
|
255
|
+
description: "Result of {@link DidAuthSiopOpAuthenticator.getSiopAuthenticationRequestDetails } "
|
|
256
|
+
},
|
|
257
|
+
IVerifySiopAuthenticationRequestUriArgs: {
|
|
258
|
+
type: "object",
|
|
259
|
+
properties: {
|
|
260
|
+
sessionId: {
|
|
261
|
+
type: "string"
|
|
262
|
+
},
|
|
263
|
+
ParsedAuthenticationRequestURI: {
|
|
264
|
+
type: "object",
|
|
265
|
+
properties: {
|
|
266
|
+
additionalProperties: true
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
additionalProperties: false
|
|
270
|
+
},
|
|
271
|
+
required: ["sessionId", "ParsedAuthenticationRequestURI"],
|
|
272
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.verifySiopAuthenticationRequestURI } "
|
|
273
|
+
},
|
|
274
|
+
VerifiedAuthorizationRequest: {
|
|
275
|
+
type: "object",
|
|
276
|
+
properties: {
|
|
277
|
+
payload: {
|
|
278
|
+
type: "object",
|
|
279
|
+
properties: {
|
|
280
|
+
additionalProperties: true
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
presentationDefinitions: {
|
|
284
|
+
type: "object",
|
|
285
|
+
properties: {
|
|
286
|
+
additionalProperties: true
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
verifyOpts: {
|
|
290
|
+
type: "object",
|
|
291
|
+
properties: {
|
|
292
|
+
additionalProperties: true
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
additionalProperties: false
|
|
296
|
+
},
|
|
297
|
+
required: ["payload", "verifyOpts"],
|
|
298
|
+
description: "Result of {@link DidAuthSiopOpAuthenticator.verifySiopAuthenticationRequestURI } "
|
|
299
|
+
},
|
|
300
|
+
ISendSiopAuthenticationResponseArgs: {
|
|
301
|
+
type: "object",
|
|
302
|
+
properties: {
|
|
303
|
+
sessionId: {
|
|
304
|
+
type: "string"
|
|
305
|
+
},
|
|
306
|
+
verifiedAuthenticationRequest: {
|
|
307
|
+
type: "object",
|
|
308
|
+
properties: {
|
|
309
|
+
additionalProperties: true
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
verifiablePresentationResponse: {
|
|
313
|
+
type: "object",
|
|
314
|
+
properties: {
|
|
315
|
+
additionalProperties: true
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
additionalProperties: false
|
|
319
|
+
},
|
|
320
|
+
required: ["sessionId", "verifiedAuthenticationRequest"],
|
|
321
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.sendSiopAuthenticationResponse } "
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
methods: {
|
|
325
|
+
getSessionForSiop: {
|
|
326
|
+
description: "Get SIOP session",
|
|
327
|
+
arguments: {
|
|
328
|
+
$ref: "#/components/schemas/IGetSiopSessionArgs"
|
|
329
|
+
},
|
|
330
|
+
returnType: "object"
|
|
331
|
+
},
|
|
332
|
+
registerSessionForSiop: {
|
|
333
|
+
description: "Register SIOP session",
|
|
334
|
+
arguments: {
|
|
335
|
+
$ref: "#/components/schemas/IRegisterSiopSessionArgs"
|
|
336
|
+
},
|
|
337
|
+
returnType: "object"
|
|
338
|
+
},
|
|
339
|
+
removeSessionForSiop: {
|
|
340
|
+
description: "Remove SIOP session",
|
|
341
|
+
arguments: {
|
|
342
|
+
$ref: "#/components/schemas/IRemoveSiopSessionArgs"
|
|
343
|
+
},
|
|
344
|
+
returnType: "boolean"
|
|
345
|
+
},
|
|
346
|
+
authenticateWithSiop: {
|
|
347
|
+
description: "Authenticate using DID Auth SIOP",
|
|
348
|
+
arguments: {
|
|
349
|
+
$ref: "#/components/schemas/IAuthenticateWithSiopArgs"
|
|
350
|
+
},
|
|
351
|
+
returnType: {
|
|
352
|
+
$ref: "#/components/schemas/Response"
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
getSiopAuthenticationRequestFromRP: {
|
|
356
|
+
description: "Get authentication request from RP",
|
|
357
|
+
arguments: {
|
|
358
|
+
$ref: "#/components/schemas/IGetSiopAuthenticationRequestFromRpArgs"
|
|
359
|
+
},
|
|
360
|
+
returnType: {
|
|
361
|
+
$ref: "#/components/schemas/ParsedAuthenticationRequestURI"
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
getSiopAuthenticationRequestDetails: {
|
|
365
|
+
description: "Get authentication request details",
|
|
366
|
+
arguments: {
|
|
367
|
+
$ref: "#/components/schemas/IGetSiopAuthenticationRequestDetailsArgs"
|
|
368
|
+
},
|
|
369
|
+
returnType: {
|
|
370
|
+
$ref: "#/components/schemas/IAuthRequestDetails"
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
verifySiopAuthenticationRequestURI: {
|
|
374
|
+
description: "Verify authentication request URI",
|
|
375
|
+
arguments: {
|
|
376
|
+
$ref: "#/components/schemas/IVerifySiopAuthenticationRequestUriArgs"
|
|
377
|
+
},
|
|
378
|
+
returnType: {
|
|
379
|
+
$ref: "#/components/schemas/VerifiedAuthorizationRequest"
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
sendSiopAuthenticationResponse: {
|
|
383
|
+
description: "Send authentication response",
|
|
384
|
+
arguments: {
|
|
385
|
+
$ref: "#/components/schemas/ISendSiopAuthenticationResponseArgs"
|
|
386
|
+
},
|
|
387
|
+
returnType: {
|
|
388
|
+
$ref: "#/components/schemas/IRequiredContext"
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// src/index.ts
|
|
399
|
+
var index_exports = {};
|
|
400
|
+
__export(index_exports, {
|
|
401
|
+
DEFAULT_JWT_PROOF_TYPE: () => DEFAULT_JWT_PROOF_TYPE,
|
|
402
|
+
DID_PREFIX: () => DID_PREFIX,
|
|
403
|
+
DidAuthSiopOpAuthenticator: () => DidAuthSiopOpAuthenticator,
|
|
404
|
+
LOGGER_NAMESPACE: () => LOGGER_NAMESPACE,
|
|
405
|
+
OID4VP: () => OID4VP,
|
|
406
|
+
OID4VPCallbackStateListener: () => OID4VPCallbackStateListener,
|
|
407
|
+
OpSession: () => OpSession,
|
|
408
|
+
Siopv2HolderEvent: () => Siopv2HolderEvent,
|
|
409
|
+
Siopv2Machine: () => Siopv2Machine,
|
|
410
|
+
Siopv2MachineAddContactStates: () => Siopv2MachineAddContactStates,
|
|
411
|
+
Siopv2MachineEvents: () => Siopv2MachineEvents,
|
|
412
|
+
Siopv2MachineGuards: () => Siopv2MachineGuards,
|
|
413
|
+
Siopv2MachineServices: () => Siopv2MachineServices,
|
|
414
|
+
Siopv2MachineStates: () => Siopv2MachineStates,
|
|
415
|
+
Siopv2OID4VPLinkHandler: () => Siopv2OID4VPLinkHandler,
|
|
416
|
+
SupportedLanguage: () => SupportedLanguage,
|
|
417
|
+
createJwtCallbackWithIdOpts: () => createJwtCallbackWithIdOpts,
|
|
418
|
+
createJwtCallbackWithOpOpts: () => createJwtCallbackWithOpOpts,
|
|
419
|
+
createOID4VPPresentationSignCallback: () => createOID4VPPresentationSignCallback,
|
|
420
|
+
createOP: () => createOP,
|
|
421
|
+
createOPBuilder: () => createOPBuilder,
|
|
422
|
+
didAuthSiopOpAuthenticatorMethods: () => didAuthSiopOpAuthenticatorMethods,
|
|
423
|
+
events: () => events,
|
|
424
|
+
getSigningAlgo: () => getSigningAlgo,
|
|
425
|
+
schema: () => schema
|
|
426
|
+
});
|
|
427
|
+
module.exports = __toCommonJS(index_exports);
|
|
428
|
+
|
|
429
|
+
// src/agent/DidAuthSiopOpAuthenticator.ts
|
|
430
|
+
var import_did_auth_siop5 = require("@sphereon/did-auth-siop");
|
|
431
|
+
var import_ssi_sdk8 = require("@sphereon/ssi-sdk.data-store");
|
|
432
|
+
var import_ssi_types7 = require("@sphereon/ssi-types");
|
|
433
|
+
var import_uuid2 = require("uuid");
|
|
434
|
+
|
|
435
|
+
// src/session/functions.ts
|
|
436
|
+
var import_did_auth_siop = require("@sphereon/did-auth-siop");
|
|
437
|
+
var import_oid4vc_common = require("@sphereon/oid4vc-common");
|
|
438
|
+
var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.identifier-resolution");
|
|
439
|
+
var import_ssi_sdk = require("@sphereon/ssi-sdk.presentation-exchange");
|
|
440
|
+
var import_events = require("events");
|
|
441
|
+
async function createOID4VPPresentationSignCallback({ presentationSignCallback, idOpts: idOpts1, domain, fetchRemoteContexts, challenge, format, context, skipDidResolution }) {
|
|
442
|
+
if (typeof presentationSignCallback === "function") {
|
|
443
|
+
return presentationSignCallback;
|
|
444
|
+
}
|
|
445
|
+
return (0, import_ssi_sdk.createPEXPresentationSignCallback)({
|
|
446
|
+
idOpts: idOpts1,
|
|
447
|
+
fetchRemoteContexts,
|
|
448
|
+
domain,
|
|
449
|
+
challenge,
|
|
450
|
+
format,
|
|
451
|
+
skipDidResolution
|
|
452
|
+
}, context);
|
|
453
|
+
}
|
|
454
|
+
__name(createOID4VPPresentationSignCallback, "createOID4VPPresentationSignCallback");
|
|
455
|
+
async function createOPBuilder({ opOptions, idOpts: idOpts1, context }) {
|
|
456
|
+
const eventEmitter = opOptions.eventEmitter ?? new import_events.EventEmitter();
|
|
457
|
+
const builder = import_did_auth_siop.OP.builder().withResponseMode(opOptions.responseMode ?? import_did_auth_siop.ResponseMode.DIRECT_POST).withSupportedVersions(opOptions.supportedVersions ?? [
|
|
458
|
+
import_did_auth_siop.SupportedVersion.SIOPv2_ID1,
|
|
459
|
+
import_did_auth_siop.SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1,
|
|
460
|
+
import_did_auth_siop.SupportedVersion.SIOPv2_D11,
|
|
461
|
+
import_did_auth_siop.SupportedVersion.SIOPv2_D12_OID4VP_D18
|
|
462
|
+
]).withExpiresIn(opOptions.expiresIn ?? 300).withEventEmitter(eventEmitter).withRegistration({
|
|
463
|
+
passBy: import_did_auth_siop.PassBy.VALUE
|
|
464
|
+
});
|
|
465
|
+
const wellknownDIDVerifyCallback = opOptions.wellknownDIDVerifyCallback ? opOptions.wellknownDIDVerifyCallback : async (args) => {
|
|
466
|
+
const result = await context.agent.cvVerifyCredential({
|
|
467
|
+
credential: args.credential,
|
|
468
|
+
fetchRemoteContexts: true
|
|
469
|
+
});
|
|
470
|
+
return {
|
|
471
|
+
verified: result.result
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
builder.withVerifyJwtCallback(opOptions.verifyJwtCallback ? opOptions.verifyJwtCallback : getVerifyJwtCallback({
|
|
475
|
+
verifyOpts: {
|
|
476
|
+
wellknownDIDVerifyCallback,
|
|
477
|
+
checkLinkedDomain: "if_present"
|
|
478
|
+
}
|
|
479
|
+
}, context));
|
|
480
|
+
if (idOpts1) {
|
|
481
|
+
if (opOptions.skipDidResolution && (0, import_ssi_sdk_ext.isManagedIdentifierDidOpts)(idOpts1)) {
|
|
482
|
+
idOpts1.offlineWhenNoDIDRegistered = true;
|
|
483
|
+
}
|
|
484
|
+
const createJwtCallback = createJwtCallbackWithIdOpts(idOpts1, context);
|
|
485
|
+
builder.withCreateJwtCallback(createJwtCallback);
|
|
486
|
+
builder.withPresentationSignCallback(await createOID4VPPresentationSignCallback({
|
|
487
|
+
presentationSignCallback: opOptions.presentationSignCallback,
|
|
488
|
+
skipDidResolution: opOptions.skipDidResolution ?? false,
|
|
489
|
+
idOpts: idOpts1,
|
|
490
|
+
context
|
|
491
|
+
}));
|
|
492
|
+
} else {
|
|
493
|
+
const createJwtCallback = createJwtCallbackWithOpOpts(opOptions, context);
|
|
494
|
+
builder.withCreateJwtCallback(createJwtCallback);
|
|
495
|
+
}
|
|
496
|
+
return builder;
|
|
497
|
+
}
|
|
498
|
+
__name(createOPBuilder, "createOPBuilder");
|
|
499
|
+
function createJwtCallbackWithIdOpts(idOpts1, context) {
|
|
500
|
+
return async (jwtIssuer, jwt) => {
|
|
501
|
+
let issuer;
|
|
502
|
+
if ((0, import_ssi_sdk_ext.isManagedIdentifierDidOpts)(idOpts1)) {
|
|
503
|
+
issuer = {
|
|
504
|
+
...idOpts1,
|
|
505
|
+
method: idOpts1.method,
|
|
506
|
+
noIdentifierInHeader: false
|
|
507
|
+
};
|
|
508
|
+
} else if ((0, import_ssi_sdk_ext.isManagedIdentifierX5cOpts)(idOpts1)) {
|
|
509
|
+
issuer = {
|
|
510
|
+
...idOpts1,
|
|
511
|
+
method: idOpts1.method,
|
|
512
|
+
noIdentifierInHeader: false
|
|
513
|
+
};
|
|
514
|
+
} else {
|
|
515
|
+
return Promise.reject(Error(`JWT issuer method ${jwtIssuer.method} not yet supported`));
|
|
516
|
+
}
|
|
517
|
+
const result = await context.agent.jwtCreateJwsCompactSignature({
|
|
518
|
+
issuer,
|
|
519
|
+
protectedHeader: jwt.header,
|
|
520
|
+
payload: jwt.payload
|
|
521
|
+
});
|
|
522
|
+
return result.jwt;
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
__name(createJwtCallbackWithIdOpts, "createJwtCallbackWithIdOpts");
|
|
526
|
+
function createJwtCallbackWithOpOpts(opOpts, context) {
|
|
527
|
+
return async (jwtIssuer, jwt) => {
|
|
528
|
+
let identifier;
|
|
529
|
+
if (jwtIssuer.method == "did") {
|
|
530
|
+
identifier = jwtIssuer.didUrl;
|
|
531
|
+
} else if (jwtIssuer.method == "x5c") {
|
|
532
|
+
identifier = jwtIssuer.x5c;
|
|
533
|
+
} else {
|
|
534
|
+
return Promise.reject(Error(`JWT issuer method ${jwtIssuer.method} not yet supported`));
|
|
535
|
+
}
|
|
536
|
+
const result = await context.agent.jwtCreateJwsCompactSignature({
|
|
537
|
+
// FIXME fix cose-key inference
|
|
538
|
+
// @ts-ignore
|
|
539
|
+
issuer: {
|
|
540
|
+
identifier,
|
|
541
|
+
kmsKeyRef: idOpts.kmsKeyRef,
|
|
542
|
+
noIdentifierInHeader: false
|
|
543
|
+
},
|
|
544
|
+
// FIXME fix JWK key_ops
|
|
545
|
+
// @ts-ignore
|
|
546
|
+
protectedHeader: jwt.header,
|
|
547
|
+
payload: jwt.payload
|
|
548
|
+
});
|
|
549
|
+
return result.jwt;
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
__name(createJwtCallbackWithOpOpts, "createJwtCallbackWithOpOpts");
|
|
553
|
+
function getVerifyJwtCallback(_opts, context) {
|
|
554
|
+
return async (_jwtVerifier, jwt) => {
|
|
555
|
+
const result = await context.agent.jwtVerifyJwsSignature({
|
|
556
|
+
jws: jwt.raw
|
|
557
|
+
});
|
|
558
|
+
console.log(result.message);
|
|
559
|
+
return !result.error;
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
__name(getVerifyJwtCallback, "getVerifyJwtCallback");
|
|
563
|
+
async function createOP({ opOptions, idOpts: idOpts1, context }) {
|
|
564
|
+
return (await createOPBuilder({
|
|
565
|
+
opOptions,
|
|
566
|
+
idOpts: idOpts1,
|
|
567
|
+
context
|
|
568
|
+
})).build();
|
|
569
|
+
}
|
|
570
|
+
__name(createOP, "createOP");
|
|
571
|
+
function getSigningAlgo(type) {
|
|
572
|
+
switch (type) {
|
|
573
|
+
case "Ed25519":
|
|
574
|
+
return import_oid4vc_common.SigningAlgo.EDDSA;
|
|
575
|
+
case "Secp256k1":
|
|
576
|
+
return import_oid4vc_common.SigningAlgo.ES256K;
|
|
577
|
+
case "Secp256r1":
|
|
578
|
+
return import_oid4vc_common.SigningAlgo.ES256;
|
|
579
|
+
// @ts-ignore
|
|
580
|
+
case "RSA":
|
|
581
|
+
return import_oid4vc_common.SigningAlgo.RS256;
|
|
582
|
+
default:
|
|
583
|
+
throw Error("Key type not yet supported");
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
__name(getSigningAlgo, "getSigningAlgo");
|
|
587
|
+
|
|
588
|
+
// src/session/OID4VP.ts
|
|
589
|
+
var import_did_auth_siop2 = require("@sphereon/did-auth-siop");
|
|
590
|
+
var import_pex = require("@sphereon/pex");
|
|
591
|
+
var import_ssi_sdk_ext2 = require("@sphereon/ssi-sdk-ext.identifier-resolution");
|
|
592
|
+
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.core");
|
|
593
|
+
var import_ssi_sdk3 = require("@sphereon/ssi-sdk.credential-store");
|
|
594
|
+
|
|
595
|
+
// src/types/IDidAuthSiopOpAuthenticator.ts
|
|
596
|
+
var LOGGER_NAMESPACE = "sphereon:siopv2-oid4vp:op-auth";
|
|
597
|
+
var events = /* @__PURE__ */ function(events2) {
|
|
598
|
+
events2["DID_SIOP_AUTHENTICATED"] = "didSiopAuthenticated";
|
|
599
|
+
return events2;
|
|
600
|
+
}({});
|
|
601
|
+
var DEFAULT_JWT_PROOF_TYPE = "JwtProof2020";
|
|
602
|
+
|
|
603
|
+
// src/types/siop-service/index.ts
|
|
604
|
+
var Siopv2HolderEvent = /* @__PURE__ */ function(Siopv2HolderEvent2) {
|
|
605
|
+
Siopv2HolderEvent2["CONTACT_IDENTITY_CREATED"] = "contact_identity_created";
|
|
606
|
+
Siopv2HolderEvent2["IDENTIFIER_CREATED"] = "identifier_created";
|
|
607
|
+
return Siopv2HolderEvent2;
|
|
608
|
+
}({});
|
|
609
|
+
var SupportedLanguage = /* @__PURE__ */ function(SupportedLanguage2) {
|
|
610
|
+
SupportedLanguage2["ENGLISH"] = "en";
|
|
611
|
+
SupportedLanguage2["DUTCH"] = "nl";
|
|
612
|
+
return SupportedLanguage2;
|
|
613
|
+
}({});
|
|
614
|
+
|
|
615
|
+
// src/types/machine/index.ts
|
|
616
|
+
var Siopv2MachineStates = /* @__PURE__ */ function(Siopv2MachineStates2) {
|
|
617
|
+
Siopv2MachineStates2["createConfig"] = "createConfig";
|
|
618
|
+
Siopv2MachineStates2["getSiopRequest"] = "getSiopRequest";
|
|
619
|
+
Siopv2MachineStates2["getSelectableCredentials"] = "getSelectableCredentials";
|
|
620
|
+
Siopv2MachineStates2["retrieveContact"] = "retrieveContact";
|
|
621
|
+
Siopv2MachineStates2["transitionFromSetup"] = "transitionFromSetup";
|
|
622
|
+
Siopv2MachineStates2["addContact"] = "addContact";
|
|
623
|
+
Siopv2MachineStates2["addContactIdentity"] = "addContactIdentity";
|
|
624
|
+
Siopv2MachineStates2["selectCredentials"] = "selectCredentials";
|
|
625
|
+
Siopv2MachineStates2["sendResponse"] = "sendResponse";
|
|
626
|
+
Siopv2MachineStates2["handleError"] = "handleError";
|
|
627
|
+
Siopv2MachineStates2["aborted"] = "aborted";
|
|
628
|
+
Siopv2MachineStates2["declined"] = "declined";
|
|
629
|
+
Siopv2MachineStates2["error"] = "error";
|
|
630
|
+
Siopv2MachineStates2["done"] = "done";
|
|
631
|
+
return Siopv2MachineStates2;
|
|
632
|
+
}({});
|
|
633
|
+
var Siopv2MachineAddContactStates = /* @__PURE__ */ function(Siopv2MachineAddContactStates2) {
|
|
634
|
+
Siopv2MachineAddContactStates2["idle"] = "idle";
|
|
635
|
+
Siopv2MachineAddContactStates2["executing"] = "executing";
|
|
636
|
+
Siopv2MachineAddContactStates2["next"] = "next";
|
|
637
|
+
return Siopv2MachineAddContactStates2;
|
|
638
|
+
}({});
|
|
639
|
+
var Siopv2MachineEvents = /* @__PURE__ */ function(Siopv2MachineEvents2) {
|
|
640
|
+
Siopv2MachineEvents2["NEXT"] = "NEXT";
|
|
641
|
+
Siopv2MachineEvents2["PREVIOUS"] = "PREVIOUS";
|
|
642
|
+
Siopv2MachineEvents2["DECLINE"] = "DECLINE";
|
|
643
|
+
Siopv2MachineEvents2["SET_CONTACT_ALIAS"] = "SET_CONTACT_ALIAS";
|
|
644
|
+
Siopv2MachineEvents2["SET_CONTACT_CONSENT"] = "SET_CONTACT_CONSENT";
|
|
645
|
+
Siopv2MachineEvents2["CREATE_CONTACT"] = "CREATE_CONTACT";
|
|
646
|
+
Siopv2MachineEvents2["SET_SELECTED_CREDENTIALS"] = "SET_SELECTED_CREDENTIALS";
|
|
647
|
+
return Siopv2MachineEvents2;
|
|
648
|
+
}({});
|
|
649
|
+
var Siopv2MachineGuards = /* @__PURE__ */ function(Siopv2MachineGuards2) {
|
|
650
|
+
Siopv2MachineGuards2["hasNoContactGuard"] = "Siopv2HasNoContactGuard";
|
|
651
|
+
Siopv2MachineGuards2["createContactGuard"] = "Siopv2CreateContactGuard";
|
|
652
|
+
Siopv2MachineGuards2["hasContactGuard"] = "Siopv2HasContactGuard";
|
|
653
|
+
Siopv2MachineGuards2["hasAuthorizationRequestGuard"] = "Siopv2HasAuthorizationRequestGuard";
|
|
654
|
+
Siopv2MachineGuards2["hasSelectableCredentialsAndContactGuard"] = "Siopv2HasSelectableCredentialsAndContactGuard";
|
|
655
|
+
Siopv2MachineGuards2["hasSelectedRequiredCredentialsGuard"] = "Siopv2HasSelectedRequiredCredentialsGuard";
|
|
656
|
+
Siopv2MachineGuards2["siopOnlyGuard"] = "Siopv2IsSiopOnlyGuard";
|
|
657
|
+
Siopv2MachineGuards2["siopWithOID4VPGuard"] = "Siopv2IsSiopWithOID4VPGuard";
|
|
658
|
+
return Siopv2MachineGuards2;
|
|
659
|
+
}({});
|
|
660
|
+
var Siopv2MachineServices = /* @__PURE__ */ function(Siopv2MachineServices2) {
|
|
661
|
+
Siopv2MachineServices2["getSiopRequest"] = "getSiopRequest";
|
|
662
|
+
Siopv2MachineServices2["getSelectableCredentials"] = "getSelectableCredentials";
|
|
663
|
+
Siopv2MachineServices2["retrieveContact"] = "retrieveContact";
|
|
664
|
+
Siopv2MachineServices2["addContactIdentity"] = "addContactIdentity";
|
|
665
|
+
Siopv2MachineServices2["sendResponse"] = "sendResponse";
|
|
666
|
+
Siopv2MachineServices2["createConfig"] = "createConfig";
|
|
667
|
+
return Siopv2MachineServices2;
|
|
668
|
+
}({});
|
|
669
|
+
|
|
670
|
+
// src/types/identifier/index.ts
|
|
671
|
+
var DID_PREFIX = "did";
|
|
672
|
+
|
|
673
|
+
// src/session/OID4VP.ts
|
|
674
|
+
var OID4VP = class _OID4VP {
|
|
675
|
+
static {
|
|
676
|
+
__name(this, "OID4VP");
|
|
677
|
+
}
|
|
678
|
+
session;
|
|
679
|
+
allIdentifiers;
|
|
680
|
+
hasher;
|
|
681
|
+
constructor(args) {
|
|
682
|
+
const { session, allIdentifiers, hasher = import_ssi_sdk2.defaultHasher } = args;
|
|
683
|
+
this.session = session;
|
|
684
|
+
this.allIdentifiers = allIdentifiers ?? [];
|
|
685
|
+
this.hasher = hasher;
|
|
686
|
+
}
|
|
687
|
+
static async init(session, allIdentifiers, hasher) {
|
|
688
|
+
return new _OID4VP({
|
|
689
|
+
session,
|
|
690
|
+
allIdentifiers: allIdentifiers ?? await session.getSupportedDIDs(),
|
|
691
|
+
hasher
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
async getPresentationDefinitions() {
|
|
695
|
+
const definitions = await this.session.getPresentationDefinitions();
|
|
696
|
+
if (definitions) {
|
|
697
|
+
import_did_auth_siop2.PresentationExchange.assertValidPresentationDefinitionWithLocations(definitions);
|
|
698
|
+
}
|
|
699
|
+
return definitions;
|
|
700
|
+
}
|
|
701
|
+
getPresentationExchange(args) {
|
|
702
|
+
const { verifiableCredentials, allIdentifiers, hasher } = args;
|
|
703
|
+
return new import_did_auth_siop2.PresentationExchange({
|
|
704
|
+
allDIDs: allIdentifiers ?? this.allIdentifiers,
|
|
705
|
+
allVerifiableCredentials: verifiableCredentials,
|
|
706
|
+
hasher: hasher ?? this.hasher
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
async createVerifiablePresentations(credentialRole, credentialsWithDefinitions, opts) {
|
|
710
|
+
return await Promise.all(credentialsWithDefinitions.map((cred) => this.createVerifiablePresentation(credentialRole, cred, opts)));
|
|
711
|
+
}
|
|
712
|
+
async createVerifiablePresentation(credentialRole, selectedVerifiableCredentials, opts) {
|
|
713
|
+
const { subjectIsHolder, holder, forceNoCredentialsInVP = false } = {
|
|
714
|
+
...opts
|
|
715
|
+
};
|
|
716
|
+
if (subjectIsHolder && holder) {
|
|
717
|
+
throw Error("Cannot both have subject is holder and a holderDID value at the same time (programming error)");
|
|
718
|
+
}
|
|
719
|
+
if (forceNoCredentialsInVP) {
|
|
720
|
+
selectedVerifiableCredentials.credentials = [];
|
|
721
|
+
} else if (!selectedVerifiableCredentials?.credentials || selectedVerifiableCredentials.credentials.length === 0) {
|
|
722
|
+
throw Error("No verifiable verifiableCredentials provided for presentation definition");
|
|
723
|
+
}
|
|
724
|
+
const proofOptions = {
|
|
725
|
+
...opts?.proofOpts,
|
|
726
|
+
challenge: opts?.proofOpts?.nonce ?? opts?.proofOpts?.challenge ?? this.session.nonce,
|
|
727
|
+
domain: opts?.proofOpts?.domain ?? await this.session.getRedirectUri()
|
|
728
|
+
};
|
|
729
|
+
let idOpts2 = opts?.idOpts;
|
|
730
|
+
if (!idOpts2) {
|
|
731
|
+
if (opts?.subjectIsHolder) {
|
|
732
|
+
if (forceNoCredentialsInVP) {
|
|
733
|
+
return Promise.reject(Error(`Cannot have subject is holder, when force no credentials is being used, as we could never determine the holder then. Please provide holderDID`));
|
|
734
|
+
}
|
|
735
|
+
const firstUniqueDC = selectedVerifiableCredentials.credentials[0];
|
|
736
|
+
if (typeof firstUniqueDC !== "object" || !("digitalCredential" in firstUniqueDC)) {
|
|
737
|
+
return Promise.reject(Error("If no opts provided, credentials should be of type UniqueDigitalCredential"));
|
|
738
|
+
}
|
|
739
|
+
idOpts2 = (0, import_ssi_sdk_ext2.isOID4VCIssuerIdentifier)(firstUniqueDC.digitalCredential.kmsKeyRef) ? await this.session.context.agent.identifierManagedGetByIssuer({
|
|
740
|
+
identifier: firstUniqueDC.digitalCredential.kmsKeyRef
|
|
741
|
+
}) : await this.session.context.agent.identifierManagedGetByKid({
|
|
742
|
+
identifier: firstUniqueDC.digitalCredential.kmsKeyRef,
|
|
743
|
+
kmsKeyRef: firstUniqueDC.digitalCredential.kmsKeyRef
|
|
744
|
+
});
|
|
745
|
+
} else if (opts?.holder) {
|
|
746
|
+
idOpts2 = {
|
|
747
|
+
identifier: opts.holder
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
const vcs = forceNoCredentialsInVP ? selectedVerifiableCredentials : opts?.applyFilter ? await this.filterCredentials(credentialRole, selectedVerifiableCredentials.definition, {
|
|
752
|
+
restrictToFormats: opts?.restrictToFormats,
|
|
753
|
+
restrictToDIDMethods: opts?.restrictToDIDMethods,
|
|
754
|
+
filterOpts: {
|
|
755
|
+
verifiableCredentials: selectedVerifiableCredentials.credentials
|
|
756
|
+
}
|
|
757
|
+
}) : {
|
|
758
|
+
definition: selectedVerifiableCredentials.definition,
|
|
759
|
+
credentials: selectedVerifiableCredentials.credentials
|
|
760
|
+
};
|
|
761
|
+
if (!idOpts2) {
|
|
762
|
+
return Promise.reject(Error(`No identifier options present at this point`));
|
|
763
|
+
}
|
|
764
|
+
const signCallback = await createOID4VPPresentationSignCallback({
|
|
765
|
+
presentationSignCallback: this.session.options.presentationSignCallback,
|
|
766
|
+
idOpts: idOpts2,
|
|
767
|
+
context: this.session.context,
|
|
768
|
+
domain: proofOptions.domain,
|
|
769
|
+
challenge: proofOptions.challenge,
|
|
770
|
+
format: opts?.restrictToFormats ?? selectedVerifiableCredentials.definition.definition.format,
|
|
771
|
+
skipDidResolution: opts?.skipDidResolution ?? false
|
|
772
|
+
});
|
|
773
|
+
const identifier = await this.session.context.agent.identifierManagedGet(idOpts2);
|
|
774
|
+
const verifiableCredentials = vcs.credentials.map((credential) => typeof credential === "object" && "digitalCredential" in credential ? credential.originalVerifiableCredential : credential);
|
|
775
|
+
const presentationResult = await this.getPresentationExchange({
|
|
776
|
+
verifiableCredentials,
|
|
777
|
+
allIdentifiers: this.allIdentifiers,
|
|
778
|
+
hasher: opts?.hasher
|
|
779
|
+
}).createVerifiablePresentation(vcs.definition.definition, verifiableCredentials, signCallback, {
|
|
780
|
+
proofOptions,
|
|
781
|
+
// fixme: Update to newer siop-vp to not require dids here. But when Veramo is creating the VP it's still looking at this field to pass into didManagerGet
|
|
782
|
+
...identifier && (0, import_ssi_sdk_ext2.isManagedIdentifierDidResult)(identifier) && {
|
|
783
|
+
holderDID: identifier.did
|
|
784
|
+
}
|
|
785
|
+
});
|
|
786
|
+
const verifiablePresentations = presentationResult.verifiablePresentations.map((verifiablePresentation) => typeof verifiablePresentation !== "string" && "proof" in verifiablePresentation && "jwt" in verifiablePresentation.proof && verifiablePresentation.proof.jwt ? verifiablePresentation.proof.jwt : verifiablePresentation);
|
|
787
|
+
return {
|
|
788
|
+
...presentationResult,
|
|
789
|
+
verifiablePresentations,
|
|
790
|
+
verifiableCredentials,
|
|
791
|
+
definition: selectedVerifiableCredentials.definition,
|
|
792
|
+
idOpts: idOpts2
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
async filterCredentialsAgainstAllDefinitions(credentialRole, opts) {
|
|
796
|
+
const defs = await this.getPresentationDefinitions();
|
|
797
|
+
const result = [];
|
|
798
|
+
if (defs) {
|
|
799
|
+
for (const definition of defs) {
|
|
800
|
+
result.push(await this.filterCredentials(credentialRole, definition, opts));
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
return result;
|
|
804
|
+
}
|
|
805
|
+
async filterCredentials(credentialRole, presentationDefinition, opts) {
|
|
806
|
+
const udcMap = /* @__PURE__ */ new Map();
|
|
807
|
+
opts?.filterOpts?.verifiableCredentials?.forEach((credential) => {
|
|
808
|
+
if (typeof credential === "object" && "digitalCredential" in credential) {
|
|
809
|
+
udcMap.set(credential.originalVerifiableCredential, credential);
|
|
810
|
+
} else {
|
|
811
|
+
udcMap.set(credential, credential);
|
|
812
|
+
}
|
|
813
|
+
});
|
|
814
|
+
const credentials = (await this.filterCredentialsWithSelectionStatus(credentialRole, presentationDefinition, {
|
|
815
|
+
...opts,
|
|
816
|
+
filterOpts: {
|
|
817
|
+
verifiableCredentials: opts?.filterOpts?.verifiableCredentials?.map((credential) => {
|
|
818
|
+
if (typeof credential === "object" && "digitalCredential" in credential) {
|
|
819
|
+
return credential.originalVerifiableCredential;
|
|
820
|
+
} else {
|
|
821
|
+
return credential;
|
|
822
|
+
}
|
|
823
|
+
})
|
|
824
|
+
}
|
|
825
|
+
})).verifiableCredential;
|
|
826
|
+
return {
|
|
827
|
+
definition: presentationDefinition,
|
|
828
|
+
credentials: credentials?.map((vc) => udcMap.get(vc)) ?? []
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
async filterCredentialsWithSelectionStatus(credentialRole, presentationDefinition, opts) {
|
|
832
|
+
const selectionResults = await this.getPresentationExchange({
|
|
833
|
+
verifiableCredentials: await this.getCredentials(credentialRole, opts?.filterOpts)
|
|
834
|
+
}).selectVerifiableCredentialsForSubmission(presentationDefinition.definition, opts);
|
|
835
|
+
if (selectionResults.errors && selectionResults.errors.length > 0) {
|
|
836
|
+
throw Error(JSON.stringify(selectionResults.errors));
|
|
837
|
+
} else if (selectionResults.areRequiredCredentialsPresent === import_pex.Status.ERROR) {
|
|
838
|
+
throw Error(`Not all required credentials are available to satisfy the relying party's request`);
|
|
839
|
+
}
|
|
840
|
+
const matches = selectionResults.matches;
|
|
841
|
+
if (!matches || matches.length === 0 || !selectionResults.verifiableCredential || selectionResults.verifiableCredential.length === 0) {
|
|
842
|
+
throw Error(JSON.stringify(selectionResults.errors));
|
|
843
|
+
}
|
|
844
|
+
return selectionResults;
|
|
845
|
+
}
|
|
846
|
+
async getCredentials(credentialRole, filterOpts) {
|
|
847
|
+
if (filterOpts?.verifiableCredentials && filterOpts.verifiableCredentials.length > 0) {
|
|
848
|
+
return filterOpts.verifiableCredentials;
|
|
849
|
+
}
|
|
850
|
+
const filter = (0, import_ssi_sdk3.verifiableCredentialForRoleFilter)(credentialRole, filterOpts?.filter);
|
|
851
|
+
const uniqueCredentials = await this.session.context.agent.crsGetUniqueCredentials({
|
|
852
|
+
filter
|
|
853
|
+
});
|
|
854
|
+
return uniqueCredentials.map((uniqueVC) => {
|
|
855
|
+
const vc = uniqueVC.uniformVerifiableCredential;
|
|
856
|
+
const proof = Array.isArray(vc.proof) ? vc.proof : [
|
|
857
|
+
vc.proof
|
|
858
|
+
];
|
|
859
|
+
const jwtProof = proof.find((p) => p?.type === DEFAULT_JWT_PROOF_TYPE);
|
|
860
|
+
return jwtProof ? jwtProof.jwt : vc;
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
|
|
865
|
+
// src/session/OpSession.ts
|
|
866
|
+
var import_did_auth_siop3 = require("@sphereon/did-auth-siop");
|
|
867
|
+
var import_ssi_sdk_ext3 = require("@sphereon/ssi-sdk-ext.did-utils");
|
|
868
|
+
var import_ssi_sdk4 = require("@sphereon/ssi-sdk.core");
|
|
869
|
+
var import_ssi_types = require("@sphereon/ssi-types");
|
|
870
|
+
var import_uuid = require("uuid");
|
|
871
|
+
var import_pex2 = require("@sphereon/pex");
|
|
872
|
+
var import_ssi_types2 = require("@sphereon/ssi-types");
|
|
873
|
+
var logger = import_ssi_types2.Loggers.DEFAULT.get("sphereon:oid4vp:OpSession");
|
|
874
|
+
var OpSession = class _OpSession {
|
|
875
|
+
static {
|
|
876
|
+
__name(this, "OpSession");
|
|
877
|
+
}
|
|
878
|
+
ts = (/* @__PURE__ */ new Date()).getDate();
|
|
879
|
+
id;
|
|
880
|
+
options;
|
|
881
|
+
context;
|
|
882
|
+
requestJwtOrUri;
|
|
883
|
+
verifiedAuthorizationRequest;
|
|
884
|
+
_nonce;
|
|
885
|
+
_state;
|
|
886
|
+
_providedPresentationDefinitions;
|
|
887
|
+
constructor(options) {
|
|
888
|
+
this.id = options.sessionId;
|
|
889
|
+
this.options = options.op;
|
|
890
|
+
this.context = options.context;
|
|
891
|
+
this.requestJwtOrUri = options.requestJwtOrUri;
|
|
892
|
+
this._providedPresentationDefinitions = options.providedPresentationDefinitions;
|
|
893
|
+
}
|
|
894
|
+
static async init(options) {
|
|
895
|
+
return new _OpSession(options);
|
|
896
|
+
}
|
|
897
|
+
async getAuthorizationRequest() {
|
|
898
|
+
if (!this.verifiedAuthorizationRequest) {
|
|
899
|
+
const op = await createOP({
|
|
900
|
+
opOptions: this.options,
|
|
901
|
+
context: this.context
|
|
902
|
+
});
|
|
903
|
+
this.verifiedAuthorizationRequest = await op.verifyAuthorizationRequest(this.requestJwtOrUri);
|
|
904
|
+
this._nonce = await this.verifiedAuthorizationRequest.authorizationRequest.getMergedProperty("nonce");
|
|
905
|
+
this._state = await this.verifiedAuthorizationRequest.authorizationRequest.getMergedProperty("state");
|
|
906
|
+
await this.getSupportedDIDMethods();
|
|
907
|
+
}
|
|
908
|
+
return this.verifiedAuthorizationRequest;
|
|
909
|
+
}
|
|
910
|
+
async getAuthorizationRequestURI() {
|
|
911
|
+
return await import_did_auth_siop3.URI.fromAuthorizationRequest((await this.getAuthorizationRequest()).authorizationRequest);
|
|
912
|
+
}
|
|
913
|
+
get nonce() {
|
|
914
|
+
if (!this._nonce) {
|
|
915
|
+
throw Error("No nonce available. Please get authorization request first");
|
|
916
|
+
}
|
|
917
|
+
return this._nonce;
|
|
918
|
+
}
|
|
919
|
+
get state() {
|
|
920
|
+
if (!this._state) {
|
|
921
|
+
throw Error("No state available. Please get authorization request first");
|
|
922
|
+
}
|
|
923
|
+
return this._state;
|
|
924
|
+
}
|
|
925
|
+
clear() {
|
|
926
|
+
this._nonce = void 0;
|
|
927
|
+
this._state = void 0;
|
|
928
|
+
this.verifiedAuthorizationRequest = void 0;
|
|
929
|
+
return this;
|
|
930
|
+
}
|
|
931
|
+
async getSupportedDIDMethods(didPrefix) {
|
|
932
|
+
const agentMethods = this.getAgentDIDMethodsSupported({
|
|
933
|
+
didPrefix
|
|
934
|
+
});
|
|
935
|
+
let rpMethods = await this.getRPDIDMethodsSupported({
|
|
936
|
+
didPrefix,
|
|
937
|
+
agentMethods
|
|
938
|
+
});
|
|
939
|
+
logger.debug(`RP supports subject syntax types: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`);
|
|
940
|
+
if (rpMethods.dids.length === 0) {
|
|
941
|
+
logger.debug(`RP does not support DIDs. Supported: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`);
|
|
942
|
+
return [];
|
|
943
|
+
}
|
|
944
|
+
let intersection;
|
|
945
|
+
if (rpMethods.dids.includes("did")) {
|
|
946
|
+
intersection = agentMethods && agentMethods.length > 0 ? agentMethods : (await (0, import_ssi_sdk_ext3.getAgentDIDMethods)(this.context)).map((method) => convertDidMethod(method, didPrefix));
|
|
947
|
+
} else if (!agentMethods || agentMethods.length === 0) {
|
|
948
|
+
intersection = rpMethods.dids?.map((method) => convertDidMethod(method, didPrefix));
|
|
949
|
+
} else {
|
|
950
|
+
intersection = agentMethods.filter((value) => rpMethods.dids.includes(value));
|
|
951
|
+
}
|
|
952
|
+
if (intersection.length === 0) {
|
|
953
|
+
throw Error("No matching DID methods between agent and relying party");
|
|
954
|
+
}
|
|
955
|
+
return intersection.map((value) => convertDidMethod(value, didPrefix));
|
|
956
|
+
}
|
|
957
|
+
getAgentDIDMethodsSupported(opts) {
|
|
958
|
+
const agentMethods = this.options.supportedDIDMethods?.map((method) => convertDidMethod(method, opts.didPrefix));
|
|
959
|
+
logger.debug(`agent methods: ${JSON.stringify(agentMethods)}`);
|
|
960
|
+
return agentMethods;
|
|
961
|
+
}
|
|
962
|
+
async getSubjectSyntaxTypesSupported() {
|
|
963
|
+
const authReq = await this.getAuthorizationRequest();
|
|
964
|
+
const subjectSyntaxTypesSupported = authReq.registrationMetadataPayload?.subject_syntax_types_supported;
|
|
965
|
+
return subjectSyntaxTypesSupported ?? [];
|
|
966
|
+
}
|
|
967
|
+
async getRPDIDMethodsSupported(opts) {
|
|
968
|
+
let keyType;
|
|
969
|
+
const agentMethods = (opts.agentMethods ?? this.getAgentDIDMethodsSupported(opts))?.map((method) => convertDidMethod(method, opts.didPrefix)) ?? [];
|
|
970
|
+
logger.debug(`agent methods supported: ${JSON.stringify(agentMethods)}`);
|
|
971
|
+
const authReq = await this.getAuthorizationRequest();
|
|
972
|
+
const subjectSyntaxTypesSupported = authReq.registrationMetadataPayload?.subject_syntax_types_supported?.map((method) => convertDidMethod(method, opts.didPrefix)).filter((val) => !val.startsWith("did"));
|
|
973
|
+
logger.debug(`subject syntax types supported in rp method supported: ${JSON.stringify(subjectSyntaxTypesSupported)}`);
|
|
974
|
+
const aud = await authReq.authorizationRequest.getMergedProperty("aud");
|
|
975
|
+
let rpMethods = [];
|
|
976
|
+
if (aud && aud.startsWith("did:")) {
|
|
977
|
+
const didMethod = convertDidMethod((0, import_ssi_types.parseDid)(aud).method, opts.didPrefix);
|
|
978
|
+
logger.debug(`aud did method: ${didMethod}`);
|
|
979
|
+
if (subjectSyntaxTypesSupported && subjectSyntaxTypesSupported.length > 0 && !subjectSyntaxTypesSupported.includes("did") && !subjectSyntaxTypesSupported.includes(didMethod)) {
|
|
980
|
+
throw Error(`The aud DID method ${didMethod} is not in the supported types ${subjectSyntaxTypesSupported}`);
|
|
981
|
+
}
|
|
982
|
+
rpMethods = [
|
|
983
|
+
didMethod
|
|
984
|
+
];
|
|
985
|
+
} else if (subjectSyntaxTypesSupported) {
|
|
986
|
+
rpMethods = (Array.isArray(subjectSyntaxTypesSupported) ? subjectSyntaxTypesSupported : [
|
|
987
|
+
subjectSyntaxTypesSupported
|
|
988
|
+
]).map((method) => convertDidMethod(method, opts.didPrefix));
|
|
989
|
+
}
|
|
990
|
+
const isEBSI = rpMethods.length === 0 && (authReq.issuer?.includes(".ebsi.eu") || (await authReq.authorizationRequest.getMergedProperty("client_id"))?.includes(".ebsi.eu"));
|
|
991
|
+
let codecName = void 0;
|
|
992
|
+
if (isEBSI && (!aud || !aud.startsWith("http"))) {
|
|
993
|
+
logger.debug(`EBSI detected, adding did:key to supported DID methods for RP`);
|
|
994
|
+
const didKeyMethod = convertDidMethod("did:key", opts.didPrefix);
|
|
995
|
+
if (!agentMethods?.includes(didKeyMethod)) {
|
|
996
|
+
throw Error(`EBSI detected, but agent did not support did:key. Please reconfigure agent`);
|
|
997
|
+
}
|
|
998
|
+
rpMethods = [
|
|
999
|
+
didKeyMethod
|
|
1000
|
+
];
|
|
1001
|
+
keyType = "Secp256r1";
|
|
1002
|
+
codecName = "jwk_jcs-pub";
|
|
1003
|
+
}
|
|
1004
|
+
return {
|
|
1005
|
+
dids: rpMethods,
|
|
1006
|
+
codecName,
|
|
1007
|
+
keyType
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
async getSupportedIdentifiers(opts) {
|
|
1011
|
+
const methods = await this.getSupportedDIDMethods(true);
|
|
1012
|
+
logger.debug(`supported DID methods (did: prefix = true): ${JSON.stringify(methods)}`);
|
|
1013
|
+
if (methods.length === 0) {
|
|
1014
|
+
throw Error(`No DID methods are supported`);
|
|
1015
|
+
}
|
|
1016
|
+
const identifiers = await this.context.agent.didManagerFind().then((ids) => ids.filter((id) => methods.includes(id.provider)));
|
|
1017
|
+
if (identifiers.length === 0) {
|
|
1018
|
+
logger.debug(`No identifiers available in agent supporting methods ${JSON.stringify(methods)}`);
|
|
1019
|
+
if (opts?.createInCaseNoDIDFound !== false) {
|
|
1020
|
+
const { codecName, keyType } = await this.getRPDIDMethodsSupported({
|
|
1021
|
+
didPrefix: true,
|
|
1022
|
+
agentMethods: methods
|
|
1023
|
+
});
|
|
1024
|
+
const identifier = await this.context.agent.didManagerCreate({
|
|
1025
|
+
provider: methods[0],
|
|
1026
|
+
options: {
|
|
1027
|
+
codecName,
|
|
1028
|
+
keyType,
|
|
1029
|
+
type: keyType
|
|
1030
|
+
}
|
|
1031
|
+
});
|
|
1032
|
+
logger.debug(`Created a new identifier for the SIOP interaction: ${identifier.did}`);
|
|
1033
|
+
identifiers.push(identifier);
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
logger.debug(`supported identifiers: ${JSON.stringify(identifiers.map((id) => id.did))}`);
|
|
1037
|
+
return identifiers;
|
|
1038
|
+
}
|
|
1039
|
+
async getSupportedDIDs() {
|
|
1040
|
+
return (await this.getSupportedIdentifiers()).map((id) => id.did);
|
|
1041
|
+
}
|
|
1042
|
+
async getRedirectUri() {
|
|
1043
|
+
return Promise.resolve(this.verifiedAuthorizationRequest.responseURI);
|
|
1044
|
+
}
|
|
1045
|
+
async hasPresentationDefinitions() {
|
|
1046
|
+
const defs = this._providedPresentationDefinitions ?? (await this.getAuthorizationRequest()).presentationDefinitions;
|
|
1047
|
+
return defs !== void 0 && defs.length > 0;
|
|
1048
|
+
}
|
|
1049
|
+
async getPresentationDefinitions() {
|
|
1050
|
+
if (!await this.hasPresentationDefinitions()) {
|
|
1051
|
+
throw Error(`No presentation definitions found`);
|
|
1052
|
+
}
|
|
1053
|
+
return this._providedPresentationDefinitions ?? (await this.getAuthorizationRequest()).presentationDefinitions;
|
|
1054
|
+
}
|
|
1055
|
+
async getOID4VP(args) {
|
|
1056
|
+
return await OID4VP.init(this, args.allIdentifiers ?? [], args.hasher);
|
|
1057
|
+
}
|
|
1058
|
+
createPresentationVerificationCallback(context) {
|
|
1059
|
+
async function presentationVerificationCallback(args, presentationSubmission) {
|
|
1060
|
+
let result;
|
|
1061
|
+
if (import_ssi_types.CredentialMapper.isSdJwtEncoded(args)) {
|
|
1062
|
+
try {
|
|
1063
|
+
const sdJwtResult = await context.agent.verifySdJwtPresentation({
|
|
1064
|
+
presentation: args
|
|
1065
|
+
});
|
|
1066
|
+
result = {
|
|
1067
|
+
verified: "header" in sdJwtResult,
|
|
1068
|
+
error: "header" in sdJwtResult ? void 0 : {
|
|
1069
|
+
message: "could not verify SD JWT presentation"
|
|
1070
|
+
}
|
|
1071
|
+
};
|
|
1072
|
+
} catch (error) {
|
|
1073
|
+
result = {
|
|
1074
|
+
verified: false,
|
|
1075
|
+
error: {
|
|
1076
|
+
message: error.message
|
|
1077
|
+
}
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
} else {
|
|
1081
|
+
result = await context.agent.verifyPresentation({
|
|
1082
|
+
presentation: args
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
return result;
|
|
1086
|
+
}
|
|
1087
|
+
__name(presentationVerificationCallback, "presentationVerificationCallback");
|
|
1088
|
+
return presentationVerificationCallback;
|
|
1089
|
+
}
|
|
1090
|
+
async createJarmResponseCallback({ responseOpts }) {
|
|
1091
|
+
const agent = this.context.agent;
|
|
1092
|
+
return /* @__PURE__ */ __name(async function jarmResponse(opts) {
|
|
1093
|
+
const { clientMetadata, requestObjectPayload, authorizationResponsePayload: authResponse } = opts;
|
|
1094
|
+
const jwk = await import_did_auth_siop3.OP.extractEncJwksFromClientMetadata(clientMetadata);
|
|
1095
|
+
const recipientKey = await agent.identifierExternalResolveByJwk({
|
|
1096
|
+
identifier: jwk
|
|
1097
|
+
});
|
|
1098
|
+
return await agent.jwtEncryptJweCompactJwt({
|
|
1099
|
+
recipientKey,
|
|
1100
|
+
protectedHeader: {},
|
|
1101
|
+
alg: requestObjectPayload.client_metadata.authorization_encrypted_response_alg ?? "ECDH-ES",
|
|
1102
|
+
enc: requestObjectPayload.client_metadata.authorization_encrypted_response_enc ?? "A256GCM",
|
|
1103
|
+
apv: (0, import_ssi_sdk4.encodeBase64url)(opts.requestObjectPayload.nonce),
|
|
1104
|
+
apu: (0, import_ssi_sdk4.encodeBase64url)((0, import_uuid.v4)()),
|
|
1105
|
+
payload: authResponse,
|
|
1106
|
+
issuer: responseOpts.issuer,
|
|
1107
|
+
audience: responseOpts.audience
|
|
1108
|
+
}).then((result) => {
|
|
1109
|
+
return {
|
|
1110
|
+
response: result.jwt
|
|
1111
|
+
};
|
|
1112
|
+
});
|
|
1113
|
+
}, "jarmResponse");
|
|
1114
|
+
}
|
|
1115
|
+
async sendAuthorizationResponse(args) {
|
|
1116
|
+
const resolveOpts = this.options.resolveOpts ?? {
|
|
1117
|
+
resolver: (0, import_ssi_sdk_ext3.getAgentResolver)(this.context, {
|
|
1118
|
+
uniresolverResolution: true,
|
|
1119
|
+
localResolution: true,
|
|
1120
|
+
resolverResolution: true
|
|
1121
|
+
})
|
|
1122
|
+
};
|
|
1123
|
+
if (!resolveOpts.subjectSyntaxTypesSupported || resolveOpts.subjectSyntaxTypesSupported.length === 0) {
|
|
1124
|
+
resolveOpts.subjectSyntaxTypesSupported = await this.getSupportedDIDMethods(true);
|
|
1125
|
+
}
|
|
1126
|
+
const verification = {
|
|
1127
|
+
presentationVerificationCallback: this.createPresentationVerificationCallback(this.context)
|
|
1128
|
+
};
|
|
1129
|
+
const request = await this.getAuthorizationRequest();
|
|
1130
|
+
const hasDefinitions = await this.hasPresentationDefinitions();
|
|
1131
|
+
if (hasDefinitions) {
|
|
1132
|
+
const totalInputDescriptors = request.presentationDefinitions?.reduce((sum, pd) => {
|
|
1133
|
+
return sum + pd.definition.input_descriptors.length;
|
|
1134
|
+
}, 0);
|
|
1135
|
+
const totalVCs = args.verifiablePresentations ? this.countVCsInAllVPs(args.verifiablePresentations, args.hasher) : 0;
|
|
1136
|
+
if (!request.presentationDefinitions || !args.verifiablePresentations || totalVCs !== totalInputDescriptors) {
|
|
1137
|
+
throw Error(`Amount of presentations ${args.verifiablePresentations?.length}, doesn't match expected ${request.presentationDefinitions?.length}`);
|
|
1138
|
+
} else if (!args.presentationSubmission) {
|
|
1139
|
+
throw Error(`Presentation submission is required when verifiable presentations are required`);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
const verifiablePresentations = args.verifiablePresentations ? args.verifiablePresentations.map((vp) => import_ssi_types.CredentialMapper.storedPresentationToOriginalFormat(vp)) : [];
|
|
1143
|
+
const op = await createOP({
|
|
1144
|
+
opOptions: {
|
|
1145
|
+
...this.options,
|
|
1146
|
+
resolveOpts: {
|
|
1147
|
+
...this.options.resolveOpts
|
|
1148
|
+
},
|
|
1149
|
+
eventEmitter: this.options.eventEmitter,
|
|
1150
|
+
presentationSignCallback: this.options.presentationSignCallback,
|
|
1151
|
+
wellknownDIDVerifyCallback: this.options.wellknownDIDVerifyCallback,
|
|
1152
|
+
supportedVersions: request.versions
|
|
1153
|
+
},
|
|
1154
|
+
idOpts: args.responseSignerOpts,
|
|
1155
|
+
context: this.context
|
|
1156
|
+
});
|
|
1157
|
+
let issuer = args.responseSignerOpts.issuer;
|
|
1158
|
+
const responseOpts = {
|
|
1159
|
+
verification,
|
|
1160
|
+
issuer,
|
|
1161
|
+
...args.isFirstParty && {
|
|
1162
|
+
isFirstParty: args.isFirstParty
|
|
1163
|
+
},
|
|
1164
|
+
...args.verifiablePresentations && {
|
|
1165
|
+
presentationExchange: {
|
|
1166
|
+
verifiablePresentations,
|
|
1167
|
+
presentationSubmission: args.presentationSubmission
|
|
1168
|
+
}
|
|
1169
|
+
},
|
|
1170
|
+
dcqlQuery: args.dcqlResponse
|
|
1171
|
+
};
|
|
1172
|
+
const authResponse = await op.createAuthorizationResponse(request, responseOpts);
|
|
1173
|
+
const response = await op.submitAuthorizationResponse(authResponse, await this.createJarmResponseCallback({
|
|
1174
|
+
responseOpts
|
|
1175
|
+
}));
|
|
1176
|
+
if (response.status >= 400) {
|
|
1177
|
+
throw Error(`Error ${response.status}: ${response.statusText || await response.text()}`);
|
|
1178
|
+
} else {
|
|
1179
|
+
return response;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
countVCsInAllVPs(verifiablePresentations, hasher) {
|
|
1183
|
+
return verifiablePresentations.reduce((sum, vp) => {
|
|
1184
|
+
if (import_ssi_types.CredentialMapper.isMsoMdocDecodedPresentation(vp) || import_ssi_types.CredentialMapper.isMsoMdocOid4VPEncoded(vp)) {
|
|
1185
|
+
return sum + 1;
|
|
1186
|
+
}
|
|
1187
|
+
const uvp = import_ssi_types.CredentialMapper.toUniformPresentation(vp, {
|
|
1188
|
+
hasher: hasher ?? this.options.hasher
|
|
1189
|
+
});
|
|
1190
|
+
if (uvp.verifiableCredential?.length) {
|
|
1191
|
+
return sum + uvp.verifiableCredential?.length;
|
|
1192
|
+
}
|
|
1193
|
+
const isSdJWT = import_ssi_types.CredentialMapper.isSdJwtDecodedCredential(uvp);
|
|
1194
|
+
if (isSdJWT || uvp.verifiableCredential && !import_pex2.PEX.allowMultipleVCsPerPresentation(uvp.verifiableCredential)) {
|
|
1195
|
+
return sum + 1;
|
|
1196
|
+
}
|
|
1197
|
+
return sum;
|
|
1198
|
+
}, 0);
|
|
1199
|
+
}
|
|
1200
|
+
};
|
|
1201
|
+
function convertDidMethod(didMethod, didPrefix) {
|
|
1202
|
+
if (didPrefix === false) {
|
|
1203
|
+
return didMethod.startsWith("did:") ? didMethod.toLowerCase().replace("did:", "") : didMethod.toLowerCase();
|
|
1204
|
+
}
|
|
1205
|
+
return didMethod.startsWith("did:") ? didMethod.toLowerCase() : `did:${didMethod.toLowerCase().replace("did:", "")}`;
|
|
1206
|
+
}
|
|
1207
|
+
__name(convertDidMethod, "convertDidMethod");
|
|
1208
|
+
|
|
1209
|
+
// src/agent/DidAuthSiopOpAuthenticator.ts
|
|
1210
|
+
var import_pex4 = require("@sphereon/pex");
|
|
1211
|
+
var import_utils = require("@veramo/utils");
|
|
1212
|
+
var import_dcql3 = require("dcql");
|
|
1213
|
+
|
|
1214
|
+
// src/machine/Siopv2Machine.ts
|
|
1215
|
+
var import_xstate = require("xstate");
|
|
1216
|
+
|
|
1217
|
+
// src/localization/Localization.ts
|
|
1218
|
+
var import_i18n_js = __toESM(require("i18n-js"), 1);
|
|
1219
|
+
var import_lodash = __toESM(require("lodash.memoize"), 1);
|
|
1220
|
+
var Localization = class Localization2 {
|
|
1221
|
+
static {
|
|
1222
|
+
__name(this, "Localization");
|
|
1223
|
+
}
|
|
1224
|
+
static translationGetters = {
|
|
1225
|
+
[SupportedLanguage.ENGLISH]: () => require_en(),
|
|
1226
|
+
[SupportedLanguage.DUTCH]: () => require_nl()
|
|
1227
|
+
};
|
|
1228
|
+
static translate = (0, import_lodash.default)((key, config) => {
|
|
1229
|
+
if (Object.keys(import_i18n_js.default.translations).length === 0) {
|
|
1230
|
+
import_i18n_js.default.translations = {
|
|
1231
|
+
[SupportedLanguage.ENGLISH]: Localization2.translationGetters[SupportedLanguage.ENGLISH]()
|
|
1232
|
+
};
|
|
1233
|
+
import_i18n_js.default.locale = SupportedLanguage.ENGLISH;
|
|
1234
|
+
} else {
|
|
1235
|
+
import_i18n_js.default.translations = {
|
|
1236
|
+
[import_i18n_js.default.locale]: {
|
|
1237
|
+
...import_i18n_js.default.translations[import_i18n_js.default.locale],
|
|
1238
|
+
...Localization2.translationGetters[this.findSupportedLanguage(import_i18n_js.default.locale) || SupportedLanguage.ENGLISH]()
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
}
|
|
1242
|
+
return import_i18n_js.default.t(key, config);
|
|
1243
|
+
}, (key, config) => config ? key + JSON.stringify(config) : key);
|
|
1244
|
+
static findSupportedLanguage = /* @__PURE__ */ __name((locale) => {
|
|
1245
|
+
for (const language of Object.values(SupportedLanguage)) {
|
|
1246
|
+
if (language === locale) {
|
|
1247
|
+
return language;
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
return void 0;
|
|
1251
|
+
}, "findSupportedLanguage");
|
|
1252
|
+
static getLocale = /* @__PURE__ */ __name(() => {
|
|
1253
|
+
return import_i18n_js.default.locale || SupportedLanguage.ENGLISH;
|
|
1254
|
+
}, "getLocale");
|
|
1255
|
+
};
|
|
1256
|
+
var translate = Localization.translate;
|
|
1257
|
+
|
|
1258
|
+
// src/machine/Siopv2Machine.ts
|
|
1259
|
+
var import_ssi_types3 = require("@sphereon/ssi-types");
|
|
1260
|
+
var logger2 = import_ssi_types3.Loggers.DEFAULT.get(LOGGER_NAMESPACE);
|
|
1261
|
+
var Siopv2HasNoContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
1262
|
+
const { contact } = _ctx;
|
|
1263
|
+
return contact === void 0;
|
|
1264
|
+
}, "Siopv2HasNoContactGuard");
|
|
1265
|
+
var Siopv2HasContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
1266
|
+
const { contact } = _ctx;
|
|
1267
|
+
return contact !== void 0;
|
|
1268
|
+
}, "Siopv2HasContactGuard");
|
|
1269
|
+
var Siopv2HasAuthorizationRequestGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
1270
|
+
const { authorizationRequestData } = _ctx;
|
|
1271
|
+
return authorizationRequestData !== void 0;
|
|
1272
|
+
}, "Siopv2HasAuthorizationRequestGuard");
|
|
1273
|
+
var Siopv2HasSelectableCredentialsAndContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
1274
|
+
const { authorizationRequestData, contact } = _ctx;
|
|
1275
|
+
if (!authorizationRequestData) {
|
|
1276
|
+
throw new Error("Missing authorization request data in context");
|
|
1277
|
+
}
|
|
1278
|
+
if (!contact) {
|
|
1279
|
+
throw new Error("Missing contact request data in context");
|
|
1280
|
+
}
|
|
1281
|
+
return authorizationRequestData.presentationDefinitions !== void 0;
|
|
1282
|
+
}, "Siopv2HasSelectableCredentialsAndContactGuard");
|
|
1283
|
+
var Siopv2CreateContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
1284
|
+
const { contactAlias, hasContactConsent } = _ctx;
|
|
1285
|
+
return hasContactConsent && contactAlias !== void 0 && contactAlias.length > 0;
|
|
1286
|
+
}, "Siopv2CreateContactGuard");
|
|
1287
|
+
var Siopv2HasSelectedRequiredCredentialsGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
1288
|
+
const { authorizationRequestData } = _ctx;
|
|
1289
|
+
if (authorizationRequestData === void 0) {
|
|
1290
|
+
throw new Error("Missing authorization request data in context");
|
|
1291
|
+
}
|
|
1292
|
+
if (authorizationRequestData.presentationDefinitions === void 0 || authorizationRequestData.presentationDefinitions.length === 0) {
|
|
1293
|
+
throw Error("No presentation definitions present");
|
|
1294
|
+
}
|
|
1295
|
+
return _ctx.selectedCredentials.length > 0;
|
|
1296
|
+
}, "Siopv2HasSelectedRequiredCredentialsGuard");
|
|
1297
|
+
var Siopv2IsSiopOnlyGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
1298
|
+
const { authorizationRequestData } = _ctx;
|
|
1299
|
+
if (authorizationRequestData === void 0) {
|
|
1300
|
+
throw new Error("Missing authorization request data in context");
|
|
1301
|
+
}
|
|
1302
|
+
return authorizationRequestData.presentationDefinitions === void 0;
|
|
1303
|
+
}, "Siopv2IsSiopOnlyGuard");
|
|
1304
|
+
var Siopv2IsSiopWithOID4VPGuard = /* @__PURE__ */ __name((_ctx, _event) => {
|
|
1305
|
+
const { authorizationRequestData, selectableCredentialsMap } = _ctx;
|
|
1306
|
+
if (!authorizationRequestData) {
|
|
1307
|
+
throw new Error("Missing authorization request data in context");
|
|
1308
|
+
}
|
|
1309
|
+
if (!selectableCredentialsMap) {
|
|
1310
|
+
throw new Error("Missing selectableCredentialsMap in context");
|
|
1311
|
+
}
|
|
1312
|
+
return authorizationRequestData.presentationDefinitions !== void 0;
|
|
1313
|
+
}, "Siopv2IsSiopWithOID4VPGuard");
|
|
1314
|
+
var createSiopv2Machine = /* @__PURE__ */ __name((opts) => {
|
|
1315
|
+
const { url, idOpts: idOpts2 } = opts;
|
|
1316
|
+
const initialContext = {
|
|
1317
|
+
url: new URL(url).toString(),
|
|
1318
|
+
hasContactConsent: true,
|
|
1319
|
+
contactAlias: "",
|
|
1320
|
+
selectedCredentials: [],
|
|
1321
|
+
idOpts: idOpts2
|
|
1322
|
+
};
|
|
1323
|
+
return (0, import_xstate.createMachine)({
|
|
1324
|
+
id: opts?.machineId ?? "Siopv2",
|
|
1325
|
+
predictableActionArguments: true,
|
|
1326
|
+
initial: Siopv2MachineStates.createConfig,
|
|
1327
|
+
schema: {
|
|
1328
|
+
events: {},
|
|
1329
|
+
guards: {},
|
|
1330
|
+
services: {}
|
|
1331
|
+
},
|
|
1332
|
+
context: initialContext,
|
|
1333
|
+
states: {
|
|
1334
|
+
[Siopv2MachineStates.createConfig]: {
|
|
1335
|
+
id: Siopv2MachineStates.createConfig,
|
|
1336
|
+
invoke: {
|
|
1337
|
+
src: Siopv2MachineServices.createConfig,
|
|
1338
|
+
onDone: {
|
|
1339
|
+
target: Siopv2MachineStates.getSiopRequest,
|
|
1340
|
+
actions: (0, import_xstate.assign)({
|
|
1341
|
+
didAuthConfig: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "didAuthConfig")
|
|
1342
|
+
})
|
|
1343
|
+
},
|
|
1344
|
+
onError: {
|
|
1345
|
+
target: Siopv2MachineStates.handleError,
|
|
1346
|
+
actions: (0, import_xstate.assign)({
|
|
1347
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1348
|
+
title: translate("siopv2_machine_create_config_error_title"),
|
|
1349
|
+
message: _event.data.message,
|
|
1350
|
+
stack: _event.data.stack
|
|
1351
|
+
}), "error")
|
|
1352
|
+
})
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
},
|
|
1356
|
+
[Siopv2MachineStates.getSiopRequest]: {
|
|
1357
|
+
id: Siopv2MachineStates.getSiopRequest,
|
|
1358
|
+
invoke: {
|
|
1359
|
+
src: Siopv2MachineServices.getSiopRequest,
|
|
1360
|
+
onDone: {
|
|
1361
|
+
target: Siopv2MachineStates.retrieveContact,
|
|
1362
|
+
actions: (0, import_xstate.assign)({
|
|
1363
|
+
authorizationRequestData: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationRequestData")
|
|
1364
|
+
})
|
|
1365
|
+
},
|
|
1366
|
+
onError: {
|
|
1367
|
+
target: Siopv2MachineStates.handleError,
|
|
1368
|
+
actions: (0, import_xstate.assign)({
|
|
1369
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1370
|
+
title: translate("siopv2_machine_get_request_error_title"),
|
|
1371
|
+
message: _event.data.message,
|
|
1372
|
+
stack: _event.data.stack
|
|
1373
|
+
}), "error")
|
|
1374
|
+
})
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
},
|
|
1378
|
+
[Siopv2MachineStates.retrieveContact]: {
|
|
1379
|
+
id: Siopv2MachineStates.retrieveContact,
|
|
1380
|
+
invoke: {
|
|
1381
|
+
src: Siopv2MachineServices.retrieveContact,
|
|
1382
|
+
onDone: {
|
|
1383
|
+
target: Siopv2MachineStates.transitionFromSetup,
|
|
1384
|
+
actions: (0, import_xstate.assign)({
|
|
1385
|
+
contact: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "contact")
|
|
1386
|
+
})
|
|
1387
|
+
},
|
|
1388
|
+
onError: {
|
|
1389
|
+
target: Siopv2MachineStates.handleError,
|
|
1390
|
+
actions: (0, import_xstate.assign)({
|
|
1391
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1392
|
+
title: translate("siopv2_machine_retrieve_contact_error_title"),
|
|
1393
|
+
message: _event.data.message,
|
|
1394
|
+
stack: _event.data.stack
|
|
1395
|
+
}), "error")
|
|
1396
|
+
})
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
},
|
|
1400
|
+
[Siopv2MachineStates.transitionFromSetup]: {
|
|
1401
|
+
id: Siopv2MachineStates.transitionFromSetup,
|
|
1402
|
+
always: [
|
|
1403
|
+
{
|
|
1404
|
+
target: Siopv2MachineStates.addContact,
|
|
1405
|
+
cond: Siopv2MachineGuards.hasNoContactGuard
|
|
1406
|
+
},
|
|
1407
|
+
{
|
|
1408
|
+
target: Siopv2MachineStates.sendResponse,
|
|
1409
|
+
cond: Siopv2MachineGuards.siopOnlyGuard
|
|
1410
|
+
},
|
|
1411
|
+
{
|
|
1412
|
+
target: Siopv2MachineStates.getSelectableCredentials,
|
|
1413
|
+
cond: Siopv2MachineGuards.hasSelectableCredentialsAndContactGuard
|
|
1414
|
+
},
|
|
1415
|
+
{
|
|
1416
|
+
target: Siopv2MachineStates.selectCredentials,
|
|
1417
|
+
cond: Siopv2MachineGuards.siopWithOID4VPGuard
|
|
1418
|
+
}
|
|
1419
|
+
]
|
|
1420
|
+
},
|
|
1421
|
+
[Siopv2MachineStates.addContact]: {
|
|
1422
|
+
id: Siopv2MachineStates.addContact,
|
|
1423
|
+
initial: Siopv2MachineAddContactStates.idle,
|
|
1424
|
+
on: {
|
|
1425
|
+
[Siopv2MachineEvents.SET_CONTACT_CONSENT]: {
|
|
1426
|
+
actions: (0, import_xstate.assign)({
|
|
1427
|
+
hasContactConsent: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "hasContactConsent")
|
|
1428
|
+
})
|
|
1429
|
+
},
|
|
1430
|
+
[Siopv2MachineEvents.SET_CONTACT_ALIAS]: {
|
|
1431
|
+
actions: (0, import_xstate.assign)({
|
|
1432
|
+
contactAlias: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "contactAlias")
|
|
1433
|
+
})
|
|
1434
|
+
},
|
|
1435
|
+
[Siopv2MachineEvents.CREATE_CONTACT]: {
|
|
1436
|
+
target: `.${Siopv2MachineAddContactStates.next}`,
|
|
1437
|
+
actions: (0, import_xstate.assign)({
|
|
1438
|
+
contact: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "contact")
|
|
1439
|
+
}),
|
|
1440
|
+
cond: Siopv2MachineGuards.createContactGuard
|
|
1441
|
+
},
|
|
1442
|
+
[Siopv2MachineEvents.DECLINE]: {
|
|
1443
|
+
target: Siopv2MachineStates.declined
|
|
1444
|
+
},
|
|
1445
|
+
[Siopv2MachineEvents.PREVIOUS]: {
|
|
1446
|
+
target: Siopv2MachineStates.aborted
|
|
1447
|
+
}
|
|
1448
|
+
},
|
|
1449
|
+
states: {
|
|
1450
|
+
[Siopv2MachineAddContactStates.idle]: {},
|
|
1451
|
+
[Siopv2MachineAddContactStates.next]: {
|
|
1452
|
+
always: {
|
|
1453
|
+
target: `#${Siopv2MachineStates.transitionFromSetup}`,
|
|
1454
|
+
cond: Siopv2MachineGuards.hasContactGuard
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
},
|
|
1459
|
+
[Siopv2MachineStates.addContactIdentity]: {
|
|
1460
|
+
id: Siopv2MachineStates.addContactIdentity,
|
|
1461
|
+
invoke: {
|
|
1462
|
+
src: Siopv2MachineServices.addContactIdentity,
|
|
1463
|
+
onDone: [
|
|
1464
|
+
{
|
|
1465
|
+
target: Siopv2MachineStates.getSelectableCredentials,
|
|
1466
|
+
actions: /* @__PURE__ */ __name((_ctx, _event) => {
|
|
1467
|
+
_ctx.contact?.identities.push(_event.data);
|
|
1468
|
+
}, "actions"),
|
|
1469
|
+
cond: Siopv2MachineGuards.hasSelectableCredentialsAndContactGuard
|
|
1470
|
+
},
|
|
1471
|
+
{
|
|
1472
|
+
target: Siopv2MachineStates.sendResponse,
|
|
1473
|
+
actions: /* @__PURE__ */ __name((_ctx, _event) => {
|
|
1474
|
+
_ctx.contact?.identities.push(_event.data);
|
|
1475
|
+
}, "actions"),
|
|
1476
|
+
cond: Siopv2MachineGuards.siopOnlyGuard
|
|
1477
|
+
}
|
|
1478
|
+
],
|
|
1479
|
+
onError: {
|
|
1480
|
+
target: Siopv2MachineStates.handleError,
|
|
1481
|
+
actions: (0, import_xstate.assign)({
|
|
1482
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1483
|
+
title: translate("siopv2_machine_add_contact_identity_error_title"),
|
|
1484
|
+
message: _event.data.message,
|
|
1485
|
+
stack: _event.data.stack
|
|
1486
|
+
}), "error")
|
|
1487
|
+
})
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
},
|
|
1491
|
+
[Siopv2MachineStates.getSelectableCredentials]: {
|
|
1492
|
+
id: Siopv2MachineStates.getSelectableCredentials,
|
|
1493
|
+
invoke: {
|
|
1494
|
+
src: Siopv2MachineServices.getSelectableCredentials,
|
|
1495
|
+
onDone: {
|
|
1496
|
+
target: Siopv2MachineStates.selectCredentials,
|
|
1497
|
+
actions: (0, import_xstate.assign)({
|
|
1498
|
+
selectableCredentialsMap: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectableCredentialsMap")
|
|
1499
|
+
})
|
|
1500
|
+
},
|
|
1501
|
+
onError: {
|
|
1502
|
+
target: Siopv2MachineStates.handleError,
|
|
1503
|
+
actions: (0, import_xstate.assign)({
|
|
1504
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1505
|
+
title: translate("siopv2_machine_get_selectable_credentials_error_title"),
|
|
1506
|
+
message: _event.data.message,
|
|
1507
|
+
stack: _event.data.stack
|
|
1508
|
+
}), "error")
|
|
1509
|
+
})
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
},
|
|
1513
|
+
[Siopv2MachineStates.selectCredentials]: {
|
|
1514
|
+
id: Siopv2MachineStates.selectCredentials,
|
|
1515
|
+
on: {
|
|
1516
|
+
[Siopv2MachineEvents.SET_SELECTED_CREDENTIALS]: {
|
|
1517
|
+
actions: (0, import_xstate.assign)({
|
|
1518
|
+
selectedCredentials: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "selectedCredentials")
|
|
1519
|
+
})
|
|
1520
|
+
},
|
|
1521
|
+
[Siopv2MachineEvents.NEXT]: {
|
|
1522
|
+
target: Siopv2MachineStates.sendResponse,
|
|
1523
|
+
cond: Siopv2MachineGuards.hasSelectedRequiredCredentialsGuard
|
|
1524
|
+
},
|
|
1525
|
+
[Siopv2MachineEvents.DECLINE]: {
|
|
1526
|
+
target: Siopv2MachineStates.declined
|
|
1527
|
+
},
|
|
1528
|
+
[Siopv2MachineEvents.PREVIOUS]: {
|
|
1529
|
+
target: Siopv2MachineStates.aborted
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
},
|
|
1533
|
+
[Siopv2MachineStates.sendResponse]: {
|
|
1534
|
+
id: Siopv2MachineStates.sendResponse,
|
|
1535
|
+
invoke: {
|
|
1536
|
+
src: Siopv2MachineServices.sendResponse,
|
|
1537
|
+
onDone: {
|
|
1538
|
+
target: Siopv2MachineStates.done,
|
|
1539
|
+
actions: (0, import_xstate.assign)({
|
|
1540
|
+
authorizationResponseData: /* @__PURE__ */ __name((_ctx, _event) => _event.data, "authorizationResponseData")
|
|
1541
|
+
})
|
|
1542
|
+
},
|
|
1543
|
+
onError: {
|
|
1544
|
+
target: Siopv2MachineStates.handleError,
|
|
1545
|
+
actions: (0, import_xstate.assign)({
|
|
1546
|
+
error: /* @__PURE__ */ __name((_ctx, _event) => ({
|
|
1547
|
+
title: translate("siopv2_machine_send_response_error_title"),
|
|
1548
|
+
message: _event.data.message,
|
|
1549
|
+
stack: _event.data.stack
|
|
1550
|
+
}), "error")
|
|
1551
|
+
})
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
},
|
|
1555
|
+
[Siopv2MachineStates.handleError]: {
|
|
1556
|
+
id: Siopv2MachineStates.handleError,
|
|
1557
|
+
on: {
|
|
1558
|
+
[Siopv2MachineEvents.NEXT]: {
|
|
1559
|
+
target: Siopv2MachineStates.error
|
|
1560
|
+
},
|
|
1561
|
+
[Siopv2MachineEvents.PREVIOUS]: {
|
|
1562
|
+
target: Siopv2MachineStates.error
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
},
|
|
1566
|
+
[Siopv2MachineStates.aborted]: {
|
|
1567
|
+
id: Siopv2MachineStates.aborted,
|
|
1568
|
+
type: "final"
|
|
1569
|
+
},
|
|
1570
|
+
[Siopv2MachineStates.declined]: {
|
|
1571
|
+
id: Siopv2MachineStates.declined,
|
|
1572
|
+
type: "final"
|
|
1573
|
+
},
|
|
1574
|
+
[Siopv2MachineStates.error]: {
|
|
1575
|
+
id: Siopv2MachineStates.error,
|
|
1576
|
+
type: "final"
|
|
1577
|
+
},
|
|
1578
|
+
[Siopv2MachineStates.done]: {
|
|
1579
|
+
id: Siopv2MachineStates.done,
|
|
1580
|
+
type: "final"
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
});
|
|
1584
|
+
}, "createSiopv2Machine");
|
|
1585
|
+
var Siopv2Machine = class {
|
|
1586
|
+
static {
|
|
1587
|
+
__name(this, "Siopv2Machine");
|
|
1588
|
+
}
|
|
1589
|
+
static newInstance(opts) {
|
|
1590
|
+
logger2.info("New Siopv2Machine instance");
|
|
1591
|
+
const interpreter = (0, import_xstate.interpret)(createSiopv2Machine(opts).withConfig({
|
|
1592
|
+
services: {
|
|
1593
|
+
...opts?.services
|
|
1594
|
+
},
|
|
1595
|
+
guards: {
|
|
1596
|
+
Siopv2HasNoContactGuard,
|
|
1597
|
+
Siopv2HasContactGuard,
|
|
1598
|
+
Siopv2HasAuthorizationRequestGuard,
|
|
1599
|
+
Siopv2HasSelectableCredentialsAndContactGuard,
|
|
1600
|
+
Siopv2HasSelectedRequiredCredentialsGuard,
|
|
1601
|
+
Siopv2IsSiopOnlyGuard,
|
|
1602
|
+
Siopv2IsSiopWithOID4VPGuard,
|
|
1603
|
+
Siopv2CreateContactGuard,
|
|
1604
|
+
...opts?.guards
|
|
1605
|
+
}
|
|
1606
|
+
}));
|
|
1607
|
+
if (typeof opts?.subscription === "function") {
|
|
1608
|
+
interpreter.onTransition(opts.subscription);
|
|
1609
|
+
}
|
|
1610
|
+
if (opts?.requireCustomNavigationHook !== true) {
|
|
1611
|
+
interpreter.onTransition((snapshot) => {
|
|
1612
|
+
if (opts.stateNavigationListener !== void 0) {
|
|
1613
|
+
void opts.stateNavigationListener(interpreter, snapshot);
|
|
1614
|
+
}
|
|
1615
|
+
});
|
|
1616
|
+
}
|
|
1617
|
+
interpreter.onTransition((snapshot) => {
|
|
1618
|
+
logger2.info("onTransition to new state", snapshot.value);
|
|
1619
|
+
});
|
|
1620
|
+
return {
|
|
1621
|
+
interpreter
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
};
|
|
1625
|
+
|
|
1626
|
+
// src/services/Siopv2MachineService.ts
|
|
1627
|
+
var import_did_auth_siop4 = require("@sphereon/did-auth-siop");
|
|
1628
|
+
var import_pex3 = require("@sphereon/pex");
|
|
1629
|
+
var import_ssi_sdk_ext4 = require("@sphereon/ssi-sdk-ext.identifier-resolution");
|
|
1630
|
+
var import_ssi_sdk5 = require("@sphereon/ssi-sdk.credential-store");
|
|
1631
|
+
var import_ssi_sdk6 = require("@sphereon/ssi-sdk.data-store");
|
|
1632
|
+
var import_ssi_types6 = require("@sphereon/ssi-types");
|
|
1633
|
+
var import_ssi_sdk_ext5 = require("@sphereon/ssi-sdk-ext.did-utils");
|
|
1634
|
+
var import_ssi_sdk7 = require("@sphereon/ssi-sdk.core");
|
|
1635
|
+
var import_dcql = require("dcql");
|
|
1636
|
+
|
|
1637
|
+
// src/utils/dcql.ts
|
|
1638
|
+
var import_ssi_types5 = require("@sphereon/ssi-types");
|
|
1639
|
+
|
|
1640
|
+
// src/utils/CredentialUtils.ts
|
|
1641
|
+
var import_ssi_types4 = require("@sphereon/ssi-types");
|
|
1642
|
+
var getOriginalVerifiableCredential = /* @__PURE__ */ __name((credential) => {
|
|
1643
|
+
if (isUniqueDigitalCredential(credential)) {
|
|
1644
|
+
if (!credential.originalVerifiableCredential) {
|
|
1645
|
+
throw new Error("originalVerifiableCredential is not defined in UniqueDigitalCredential");
|
|
1646
|
+
}
|
|
1647
|
+
return getCredentialFromProofOrWrapped(credential.originalVerifiableCredential);
|
|
1648
|
+
}
|
|
1649
|
+
return getCredentialFromProofOrWrapped(credential);
|
|
1650
|
+
}, "getOriginalVerifiableCredential");
|
|
1651
|
+
var getCredentialFromProofOrWrapped = /* @__PURE__ */ __name((cred, hasher) => {
|
|
1652
|
+
if (typeof cred === "object" && "proof" in cred && "jwt" in cred.proof && import_ssi_types4.CredentialMapper.isSdJwtEncoded(cred.proof.jwt)) {
|
|
1653
|
+
return cred.proof.jwt;
|
|
1654
|
+
}
|
|
1655
|
+
return import_ssi_types4.CredentialMapper.toWrappedVerifiableCredential(cred, {
|
|
1656
|
+
hasher
|
|
1657
|
+
}).original;
|
|
1658
|
+
}, "getCredentialFromProofOrWrapped");
|
|
1659
|
+
var isUniqueDigitalCredential = /* @__PURE__ */ __name((credential) => {
|
|
1660
|
+
return credential.digitalCredential !== void 0;
|
|
1661
|
+
}, "isUniqueDigitalCredential");
|
|
1662
|
+
|
|
1663
|
+
// src/utils/dcql.ts
|
|
1664
|
+
function convertToDcqlCredentials(credential, hasher) {
|
|
1665
|
+
let payload;
|
|
1666
|
+
if (isUniqueDigitalCredential(credential)) {
|
|
1667
|
+
if (!credential.originalVerifiableCredential) {
|
|
1668
|
+
throw new Error("originalVerifiableCredential is not defined in UniqueDigitalCredential");
|
|
1669
|
+
}
|
|
1670
|
+
payload = import_ssi_types5.CredentialMapper.decodeVerifiableCredential(credential.originalVerifiableCredential, hasher);
|
|
1671
|
+
} else {
|
|
1672
|
+
payload = import_ssi_types5.CredentialMapper.decodeVerifiableCredential(credential, hasher);
|
|
1673
|
+
}
|
|
1674
|
+
if (!payload) {
|
|
1675
|
+
throw new Error("No payload found");
|
|
1676
|
+
}
|
|
1677
|
+
if ("decodedPayload" in payload && payload.decodedPayload) {
|
|
1678
|
+
payload = payload.decodedPayload;
|
|
1679
|
+
}
|
|
1680
|
+
if ("vct" in payload) {
|
|
1681
|
+
return {
|
|
1682
|
+
vct: payload.vct,
|
|
1683
|
+
claims: payload,
|
|
1684
|
+
credential_format: "vc+sd-jwt"
|
|
1685
|
+
};
|
|
1686
|
+
} else if ("docType" in payload && "namespaces" in payload) {
|
|
1687
|
+
return {
|
|
1688
|
+
docType: payload.docType,
|
|
1689
|
+
namespaces: payload.namespaces,
|
|
1690
|
+
claims: payload
|
|
1691
|
+
};
|
|
1692
|
+
} else {
|
|
1693
|
+
return {
|
|
1694
|
+
claims: payload,
|
|
1695
|
+
credential_format: "jwt_vc_json"
|
|
1696
|
+
};
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
__name(convertToDcqlCredentials, "convertToDcqlCredentials");
|
|
1700
|
+
|
|
1701
|
+
// src/services/Siopv2MachineService.ts
|
|
1702
|
+
var logger3 = import_ssi_types6.Loggers.DEFAULT.get(LOGGER_NAMESPACE);
|
|
1703
|
+
var createEbsiIdentifier = /* @__PURE__ */ __name(async (agentContext) => {
|
|
1704
|
+
logger3.log(`No EBSI key present yet. Creating a new one...`);
|
|
1705
|
+
const { result: newIdentifier, created } = await (0, import_ssi_sdk_ext5.getOrCreatePrimaryIdentifier)(agentContext, {
|
|
1706
|
+
method: import_ssi_sdk_ext5.SupportedDidMethodEnum.DID_KEY,
|
|
1707
|
+
createOpts: {
|
|
1708
|
+
options: {
|
|
1709
|
+
codecName: "jwk_jcs-pub",
|
|
1710
|
+
type: "Secp256r1"
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
});
|
|
1714
|
+
logger3.log(`EBSI key created: ${newIdentifier.did}`);
|
|
1715
|
+
if (created) {
|
|
1716
|
+
await agentContext.agent.emit(Siopv2HolderEvent.IDENTIFIER_CREATED, {
|
|
1717
|
+
result: newIdentifier
|
|
1718
|
+
});
|
|
1719
|
+
}
|
|
1720
|
+
return await agentContext.agent.identifierManagedGetByDid({
|
|
1721
|
+
identifier: newIdentifier.did
|
|
1722
|
+
});
|
|
1723
|
+
}, "createEbsiIdentifier");
|
|
1724
|
+
var hasEbsiClient = /* @__PURE__ */ __name(async (authorizationRequest) => {
|
|
1725
|
+
const clientId = await authorizationRequest.getMergedProperty("client_id");
|
|
1726
|
+
const redirectUri = await authorizationRequest.getMergedProperty("redirect_uri");
|
|
1727
|
+
return clientId?.toLowerCase().includes(".ebsi.eu") || redirectUri?.toLowerCase().includes(".ebsi.eu");
|
|
1728
|
+
}, "hasEbsiClient");
|
|
1729
|
+
var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType, args, context) => {
|
|
1730
|
+
const { agent } = context;
|
|
1731
|
+
const agentContext = {
|
|
1732
|
+
...context,
|
|
1733
|
+
agent: context.agent
|
|
1734
|
+
};
|
|
1735
|
+
let { idOpts: idOpts2, isFirstParty, hasher = import_ssi_sdk7.defaultHasher } = args;
|
|
1736
|
+
if (connectionType !== import_ssi_sdk6.ConnectionType.SIOPv2_OpenID4VP) {
|
|
1737
|
+
return Promise.reject(Error(`No supported authentication provider for type: ${connectionType}`));
|
|
1738
|
+
}
|
|
1739
|
+
const session = await agent.siopGetOPSession({
|
|
1740
|
+
sessionId: args.sessionId
|
|
1741
|
+
});
|
|
1742
|
+
const request = await session.getAuthorizationRequest();
|
|
1743
|
+
const aud = await request.authorizationRequest.getMergedProperty("aud");
|
|
1744
|
+
logger3.debug(`AUD: ${aud}`);
|
|
1745
|
+
logger3.debug(JSON.stringify(request.authorizationRequest));
|
|
1746
|
+
let presentationsAndDefs;
|
|
1747
|
+
let presentationSubmission;
|
|
1748
|
+
if (await session.hasPresentationDefinitions()) {
|
|
1749
|
+
const oid4vp = await session.getOID4VP({
|
|
1750
|
+
hasher
|
|
1751
|
+
});
|
|
1752
|
+
const credentialsAndDefinitions = args.verifiableCredentialsWithDefinition ? args.verifiableCredentialsWithDefinition : await oid4vp.filterCredentialsAgainstAllDefinitions(import_ssi_sdk6.CredentialRole.HOLDER);
|
|
1753
|
+
const domain = await request.authorizationRequest.getMergedProperty("client_id") ?? request.issuer ?? (request.versions.includes(import_did_auth_siop4.SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1) ? "https://self-issued.me/v2/openid-vc" : "https://self-issued.me/v2");
|
|
1754
|
+
logger3.log(`NONCE: ${session.nonce}, domain: ${domain}`);
|
|
1755
|
+
const firstUniqueDC = credentialsAndDefinitions[0].credentials[0];
|
|
1756
|
+
if (typeof firstUniqueDC !== "object" || !("digitalCredential" in firstUniqueDC)) {
|
|
1757
|
+
return Promise.reject(Error("SiopMachine only supports UniqueDigitalCredentials for now"));
|
|
1758
|
+
}
|
|
1759
|
+
let identifier;
|
|
1760
|
+
const digitalCredential = firstUniqueDC.digitalCredential;
|
|
1761
|
+
const firstVC = firstUniqueDC.uniformVerifiableCredential;
|
|
1762
|
+
const holder = import_ssi_types6.CredentialMapper.isSdJwtDecodedCredential(firstVC) ? firstVC.decodedPayload.cnf?.jwk ? (
|
|
1763
|
+
//doesn't apply to did:jwk only, as you can represent any DID key as a JWK. So whenever you encounter a JWK it doesn't mean it had to come from a did:jwk in the system. It just can always be represented as a did:jwk
|
|
1764
|
+
`did:jwk:${(0, import_ssi_sdk7.encodeJoseBlob)(firstVC.decodedPayload.cnf?.jwk)}#0`
|
|
1765
|
+
) : firstVC.decodedPayload.sub : Array.isArray(firstVC.credentialSubject) ? firstVC.credentialSubject[0].id : firstVC.credentialSubject.id;
|
|
1766
|
+
if (!digitalCredential.kmsKeyRef) {
|
|
1767
|
+
if (!holder) {
|
|
1768
|
+
return Promise.reject(`No holder found and no kmsKeyRef in DB. Cannot determine identifier to use`);
|
|
1769
|
+
}
|
|
1770
|
+
try {
|
|
1771
|
+
identifier = await session.context.agent.identifierManagedGet({
|
|
1772
|
+
identifier: holder
|
|
1773
|
+
});
|
|
1774
|
+
} catch (e) {
|
|
1775
|
+
logger3.debug(`Holder DID not found: ${holder}`);
|
|
1776
|
+
throw e;
|
|
1777
|
+
}
|
|
1778
|
+
} else if ((0, import_ssi_sdk_ext4.isOID4VCIssuerIdentifier)(digitalCredential.kmsKeyRef)) {
|
|
1779
|
+
identifier = await session.context.agent.identifierManagedGetByOID4VCIssuer({
|
|
1780
|
+
identifier: firstUniqueDC.digitalCredential.kmsKeyRef
|
|
1781
|
+
});
|
|
1782
|
+
} else {
|
|
1783
|
+
switch (digitalCredential.subjectCorrelationType) {
|
|
1784
|
+
case "DID":
|
|
1785
|
+
identifier = await session.context.agent.identifierManagedGetByDid({
|
|
1786
|
+
identifier: digitalCredential.subjectCorrelationId ?? holder,
|
|
1787
|
+
kmsKeyRef: digitalCredential.kmsKeyRef
|
|
1788
|
+
});
|
|
1789
|
+
break;
|
|
1790
|
+
// TODO other implementations?
|
|
1791
|
+
default:
|
|
1792
|
+
if (digitalCredential.subjectCorrelationId?.startsWith("did:") || holder?.startsWith("did:")) {
|
|
1793
|
+
identifier = await session.context.agent.identifierManagedGetByDid({
|
|
1794
|
+
identifier: digitalCredential.subjectCorrelationId ?? holder,
|
|
1795
|
+
kmsKeyRef: digitalCredential.kmsKeyRef
|
|
1796
|
+
});
|
|
1797
|
+
} else {
|
|
1798
|
+
identifier = await session.context.agent.identifierManagedGetByKid({
|
|
1799
|
+
identifier: digitalCredential.subjectCorrelationId ?? holder ?? digitalCredential.kmsKeyRef,
|
|
1800
|
+
kmsKeyRef: digitalCredential.kmsKeyRef
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
if (identifier === void 0 && idOpts2 !== void 0 && await hasEbsiClient(request.authorizationRequest)) {
|
|
1806
|
+
identifier = await createEbsiIdentifier(agentContext);
|
|
1807
|
+
}
|
|
1808
|
+
logger3.debug(`Identifier`, identifier);
|
|
1809
|
+
presentationsAndDefs = await oid4vp.createVerifiablePresentations(import_ssi_sdk6.CredentialRole.HOLDER, credentialsAndDefinitions, {
|
|
1810
|
+
idOpts: identifier,
|
|
1811
|
+
proofOpts: {
|
|
1812
|
+
nonce: session.nonce,
|
|
1813
|
+
domain
|
|
1814
|
+
}
|
|
1815
|
+
});
|
|
1816
|
+
if (!presentationsAndDefs || presentationsAndDefs.length === 0) {
|
|
1817
|
+
throw Error("No verifiable presentations could be created");
|
|
1818
|
+
} else if (presentationsAndDefs.length > 1) {
|
|
1819
|
+
throw Error(`Only one verifiable presentation supported for now. Got ${presentationsAndDefs.length}`);
|
|
1820
|
+
}
|
|
1821
|
+
idOpts2 = presentationsAndDefs[0].idOpts;
|
|
1822
|
+
presentationSubmission = presentationsAndDefs[0].presentationSubmission;
|
|
1823
|
+
logger3.log(`Definitions and locations:`, JSON.stringify(presentationsAndDefs?.[0]?.verifiablePresentations, null, 2));
|
|
1824
|
+
logger3.log(`Presentation Submission:`, JSON.stringify(presentationSubmission, null, 2));
|
|
1825
|
+
const mergedVerifiablePresentations = presentationsAndDefs?.flatMap((pd) => pd.verifiablePresentations) || [];
|
|
1826
|
+
return await session.sendAuthorizationResponse({
|
|
1827
|
+
...presentationsAndDefs && {
|
|
1828
|
+
verifiablePresentations: mergedVerifiablePresentations
|
|
1829
|
+
},
|
|
1830
|
+
...presentationSubmission && {
|
|
1831
|
+
presentationSubmission
|
|
1832
|
+
},
|
|
1833
|
+
// todo: Change issuer value in case we do not use identifier. Use key.meta.jwkThumbprint then
|
|
1834
|
+
responseSignerOpts: idOpts2,
|
|
1835
|
+
isFirstParty
|
|
1836
|
+
});
|
|
1837
|
+
} else if (request.dcqlQuery) {
|
|
1838
|
+
if (args.verifiableCredentialsWithDefinition !== void 0 && args.verifiableCredentialsWithDefinition !== null) {
|
|
1839
|
+
const vcs = args.verifiableCredentialsWithDefinition.flatMap((vcd) => vcd.credentials);
|
|
1840
|
+
const domain = await request.authorizationRequest.getMergedProperty("client_id") ?? request.issuer ?? (request.versions.includes(import_did_auth_siop4.SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1) ? "https://self-issued.me/v2/openid-vc" : "https://self-issued.me/v2");
|
|
1841
|
+
logger3.debug(`NONCE: ${session.nonce}, domain: ${domain}`);
|
|
1842
|
+
const firstUniqueDC = vcs[0];
|
|
1843
|
+
if (typeof firstUniqueDC !== "object" || !("digitalCredential" in firstUniqueDC)) {
|
|
1844
|
+
return Promise.reject(Error("SiopMachine only supports UniqueDigitalCredentials for now"));
|
|
1845
|
+
}
|
|
1846
|
+
let identifier;
|
|
1847
|
+
const digitalCredential = firstUniqueDC.digitalCredential;
|
|
1848
|
+
const firstVC = firstUniqueDC.uniformVerifiableCredential;
|
|
1849
|
+
const holder = import_ssi_types6.CredentialMapper.isSdJwtDecodedCredential(firstVC) ? firstVC.decodedPayload.cnf?.jwk ? (
|
|
1850
|
+
//doesn't apply to did:jwk only, as you can represent any DID key as a JWK. So whenever you encounter a JWK it doesn't mean it had to come from a did:jwk in the system. It just can always be represented as a did:jwk
|
|
1851
|
+
`did:jwk:${(0, import_ssi_sdk7.encodeJoseBlob)(firstVC.decodedPayload.cnf?.jwk)}#0`
|
|
1852
|
+
) : firstVC.decodedPayload.sub : Array.isArray(firstVC.credentialSubject) ? firstVC.credentialSubject[0].id : firstVC.credentialSubject.id;
|
|
1853
|
+
if (!digitalCredential.kmsKeyRef) {
|
|
1854
|
+
if (!holder) {
|
|
1855
|
+
return Promise.reject(`No holder found and no kmsKeyRef in DB. Cannot determine identifier to use`);
|
|
1856
|
+
}
|
|
1857
|
+
try {
|
|
1858
|
+
identifier = await session.context.agent.identifierManagedGet({
|
|
1859
|
+
identifier: holder
|
|
1860
|
+
});
|
|
1861
|
+
} catch (e) {
|
|
1862
|
+
logger3.debug(`Holder DID not found: ${holder}`);
|
|
1863
|
+
throw e;
|
|
1864
|
+
}
|
|
1865
|
+
} else if ((0, import_ssi_sdk_ext4.isOID4VCIssuerIdentifier)(digitalCredential.kmsKeyRef)) {
|
|
1866
|
+
identifier = await session.context.agent.identifierManagedGetByOID4VCIssuer({
|
|
1867
|
+
identifier: firstUniqueDC.digitalCredential.kmsKeyRef
|
|
1868
|
+
});
|
|
1869
|
+
} else {
|
|
1870
|
+
switch (digitalCredential.subjectCorrelationType) {
|
|
1871
|
+
case "DID":
|
|
1872
|
+
identifier = await session.context.agent.identifierManagedGetByDid({
|
|
1873
|
+
identifier: digitalCredential.subjectCorrelationId ?? holder,
|
|
1874
|
+
kmsKeyRef: digitalCredential.kmsKeyRef
|
|
1875
|
+
});
|
|
1876
|
+
break;
|
|
1877
|
+
// TODO other implementations?
|
|
1878
|
+
default:
|
|
1879
|
+
identifier = await session.context.agent.identifierManagedGetByKid({
|
|
1880
|
+
identifier: digitalCredential.subjectCorrelationId ?? holder ?? digitalCredential.kmsKeyRef,
|
|
1881
|
+
kmsKeyRef: digitalCredential.kmsKeyRef
|
|
1882
|
+
});
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
console.log(`Identifier`, identifier);
|
|
1886
|
+
const dcqlRepresentations = [];
|
|
1887
|
+
vcs.forEach((vc) => {
|
|
1888
|
+
const rep = convertToDcqlCredentials(vc, args.hasher);
|
|
1889
|
+
if (rep) {
|
|
1890
|
+
dcqlRepresentations.push(rep);
|
|
1891
|
+
}
|
|
1892
|
+
});
|
|
1893
|
+
const queryResult = import_dcql.DcqlQuery.query(request.dcqlQuery, dcqlRepresentations);
|
|
1894
|
+
const presentation = {};
|
|
1895
|
+
for (const [key, value] of Object.entries(queryResult.credential_matches)) {
|
|
1896
|
+
const allMatches = Array.isArray(value) ? value : [
|
|
1897
|
+
value
|
|
1898
|
+
];
|
|
1899
|
+
allMatches.forEach((match) => {
|
|
1900
|
+
if (match.success) {
|
|
1901
|
+
const originalCredential = getOriginalVerifiableCredential(vcs[match.input_credential_index]);
|
|
1902
|
+
if (!originalCredential) {
|
|
1903
|
+
throw new Error(`Index ${match.input_credential_index} out of range in credentials array`);
|
|
1904
|
+
}
|
|
1905
|
+
presentation[key] = originalCredential["compactSdJwtVc"] !== void 0 ? originalCredential.compactSdJwtVc : originalCredential;
|
|
1906
|
+
}
|
|
1907
|
+
});
|
|
1908
|
+
}
|
|
1909
|
+
const response = session.sendAuthorizationResponse({
|
|
1910
|
+
responseSignerOpts: identifier,
|
|
1911
|
+
...{
|
|
1912
|
+
dcqlQuery: {
|
|
1913
|
+
dcqlPresentation: import_dcql.DcqlPresentation.parse(presentation)
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
});
|
|
1917
|
+
logger3.debug(`Response: `, response);
|
|
1918
|
+
return response;
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
throw Error("Presentation Definition or DCQL is required");
|
|
1922
|
+
}, "siopSendAuthorizationResponse");
|
|
1923
|
+
function buildPartialPD(inputDescriptor, presentationDefinition) {
|
|
1924
|
+
return {
|
|
1925
|
+
...presentationDefinition,
|
|
1926
|
+
input_descriptors: [
|
|
1927
|
+
inputDescriptor
|
|
1928
|
+
]
|
|
1929
|
+
};
|
|
1930
|
+
}
|
|
1931
|
+
__name(buildPartialPD, "buildPartialPD");
|
|
1932
|
+
var getSelectableCredentials = /* @__PURE__ */ __name(async (presentationDefinition, context) => {
|
|
1933
|
+
const agentContext = {
|
|
1934
|
+
...context,
|
|
1935
|
+
agent: context.agent
|
|
1936
|
+
};
|
|
1937
|
+
const { agent } = agentContext;
|
|
1938
|
+
const pex = new import_pex3.PEX();
|
|
1939
|
+
const uniqueVerifiableCredentials = await agent.crsGetUniqueCredentials({
|
|
1940
|
+
filter: (0, import_ssi_sdk5.verifiableCredentialForRoleFilter)(import_ssi_sdk6.CredentialRole.HOLDER)
|
|
1941
|
+
});
|
|
1942
|
+
const credentialBranding = await agent.ibGetCredentialBranding();
|
|
1943
|
+
const selectableCredentialsMap = /* @__PURE__ */ new Map();
|
|
1944
|
+
for (const inputDescriptor of presentationDefinition.input_descriptors) {
|
|
1945
|
+
const partialPD = buildPartialPD(inputDescriptor, presentationDefinition);
|
|
1946
|
+
const originalCredentials = uniqueVerifiableCredentials.map((uniqueVC) => {
|
|
1947
|
+
return import_ssi_types6.CredentialMapper.storedCredentialToOriginalFormat(uniqueVC.originalVerifiableCredential);
|
|
1948
|
+
});
|
|
1949
|
+
const selectionResults = pex.selectFrom(partialPD, originalCredentials);
|
|
1950
|
+
const selectableCredentials = [];
|
|
1951
|
+
for (const selectedCredential of selectionResults.verifiableCredential || []) {
|
|
1952
|
+
const filteredUniqueVC = uniqueVerifiableCredentials.find((uniqueVC) => {
|
|
1953
|
+
const proof = uniqueVC.uniformVerifiableCredential.proof;
|
|
1954
|
+
return Array.isArray(proof) ? proof.some((proofItem) => proofItem.jwt === selectedCredential) : proof.jwt === selectedCredential;
|
|
1955
|
+
});
|
|
1956
|
+
if (filteredUniqueVC) {
|
|
1957
|
+
const filteredCredentialBrandings = credentialBranding.filter((cb) => cb.vcHash === filteredUniqueVC.hash);
|
|
1958
|
+
const issuerPartyIdentity = await agent.cmGetContacts({
|
|
1959
|
+
filter: [
|
|
1960
|
+
{
|
|
1961
|
+
identities: {
|
|
1962
|
+
identifier: {
|
|
1963
|
+
correlationId: filteredUniqueVC.uniformVerifiableCredential.issuerDid
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
]
|
|
1968
|
+
});
|
|
1969
|
+
const subjectPartyIdentity = await agent.cmGetContacts({
|
|
1970
|
+
filter: [
|
|
1971
|
+
{
|
|
1972
|
+
identities: {
|
|
1973
|
+
identifier: {
|
|
1974
|
+
correlationId: filteredUniqueVC.uniformVerifiableCredential.subjectDid
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
]
|
|
1979
|
+
});
|
|
1980
|
+
selectableCredentials.push({
|
|
1981
|
+
credential: filteredUniqueVC,
|
|
1982
|
+
credentialBranding: filteredCredentialBrandings[0]?.localeBranding,
|
|
1983
|
+
issuerParty: issuerPartyIdentity?.[0],
|
|
1984
|
+
subjectParty: subjectPartyIdentity?.[0]
|
|
1985
|
+
});
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
selectableCredentialsMap.set(inputDescriptor.id, selectableCredentials);
|
|
1989
|
+
}
|
|
1990
|
+
return selectableCredentialsMap;
|
|
1991
|
+
}, "getSelectableCredentials");
|
|
1992
|
+
var translateCorrelationIdToName = /* @__PURE__ */ __name(async (correlationId, context) => {
|
|
1993
|
+
const { agent } = context;
|
|
1994
|
+
const contacts = await agent.cmGetContacts({
|
|
1995
|
+
filter: [
|
|
1996
|
+
{
|
|
1997
|
+
identities: {
|
|
1998
|
+
identifier: {
|
|
1999
|
+
correlationId
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
]
|
|
2004
|
+
});
|
|
2005
|
+
if (contacts.length === 0) {
|
|
2006
|
+
return void 0;
|
|
2007
|
+
}
|
|
2008
|
+
return contacts[0].contact.displayName;
|
|
2009
|
+
}, "translateCorrelationIdToName");
|
|
2010
|
+
|
|
2011
|
+
// src/agent/DidAuthSiopOpAuthenticator.ts
|
|
2012
|
+
var logger4 = import_ssi_types7.Loggers.DEFAULT.options(LOGGER_NAMESPACE, {}).get(LOGGER_NAMESPACE);
|
|
2013
|
+
var didAuthSiopOpAuthenticatorMethods = [
|
|
2014
|
+
"cmGetContacts",
|
|
2015
|
+
"cmGetContact",
|
|
2016
|
+
"cmAddContact",
|
|
2017
|
+
"cmAddIdentity",
|
|
2018
|
+
"didManagerFind",
|
|
2019
|
+
"didManagerGet",
|
|
2020
|
+
"keyManagerSign",
|
|
2021
|
+
"didManagerGetProviders",
|
|
2022
|
+
"dataStoreORMGetVerifiableCredentials",
|
|
2023
|
+
"createVerifiablePresentation"
|
|
2024
|
+
];
|
|
2025
|
+
var DidAuthSiopOpAuthenticator = class {
|
|
2026
|
+
static {
|
|
2027
|
+
__name(this, "DidAuthSiopOpAuthenticator");
|
|
2028
|
+
}
|
|
2029
|
+
schema = schema.IDidAuthSiopOpAuthenticator;
|
|
2030
|
+
methods = {
|
|
2031
|
+
siopGetOPSession: this.siopGetOPSession.bind(this),
|
|
2032
|
+
siopRegisterOPSession: this.siopRegisterOPSession.bind(this),
|
|
2033
|
+
siopRemoveOPSession: this.siopRemoveOPSession.bind(this),
|
|
2034
|
+
siopRegisterOPCustomApproval: this.siopRegisterOPCustomApproval.bind(this),
|
|
2035
|
+
siopRemoveOPCustomApproval: this.siopRemoveOPCustomApproval.bind(this),
|
|
2036
|
+
siopGetMachineInterpreter: this.siopGetMachineInterpreter.bind(this),
|
|
2037
|
+
siopCreateConfig: this.siopCreateConfig.bind(this),
|
|
2038
|
+
siopGetSiopRequest: this.siopGetSiopRequest.bind(this),
|
|
2039
|
+
siopRetrieveContact: this.siopRetrieveContact.bind(this),
|
|
2040
|
+
siopAddIdentity: this.siopAddContactIdentity.bind(this),
|
|
2041
|
+
siopSendResponse: this.siopSendResponse.bind(this),
|
|
2042
|
+
siopGetSelectableCredentials: this.siopGetSelectableCredentials.bind(this)
|
|
2043
|
+
};
|
|
2044
|
+
sessions;
|
|
2045
|
+
customApprovals;
|
|
2046
|
+
presentationSignCallback;
|
|
2047
|
+
onContactIdentityCreated;
|
|
2048
|
+
onIdentifierCreated;
|
|
2049
|
+
eventEmitter;
|
|
2050
|
+
hasher;
|
|
2051
|
+
constructor(options) {
|
|
2052
|
+
const { onContactIdentityCreated, onIdentifierCreated, hasher, customApprovals = {}, presentationSignCallback } = {
|
|
2053
|
+
...options
|
|
2054
|
+
};
|
|
2055
|
+
this.hasher = hasher;
|
|
2056
|
+
this.onContactIdentityCreated = onContactIdentityCreated;
|
|
2057
|
+
this.onIdentifierCreated = onIdentifierCreated;
|
|
2058
|
+
this.presentationSignCallback = presentationSignCallback;
|
|
2059
|
+
this.sessions = /* @__PURE__ */ new Map();
|
|
2060
|
+
this.customApprovals = customApprovals;
|
|
2061
|
+
}
|
|
2062
|
+
async onEvent(event, context) {
|
|
2063
|
+
switch (event.type) {
|
|
2064
|
+
case Siopv2HolderEvent.CONTACT_IDENTITY_CREATED:
|
|
2065
|
+
this.onContactIdentityCreated?.(event.data);
|
|
2066
|
+
break;
|
|
2067
|
+
case Siopv2HolderEvent.IDENTIFIER_CREATED:
|
|
2068
|
+
this.onIdentifierCreated?.(event.data);
|
|
2069
|
+
break;
|
|
2070
|
+
default:
|
|
2071
|
+
return Promise.reject(Error(`Event type ${event.type} not supported`));
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
async siopGetOPSession(args, context) {
|
|
2075
|
+
if (!this.sessions.has(args.sessionId)) {
|
|
2076
|
+
throw Error(`No session found for id: ${args.sessionId}`);
|
|
2077
|
+
}
|
|
2078
|
+
return this.sessions.get(args.sessionId);
|
|
2079
|
+
}
|
|
2080
|
+
async siopRegisterOPSession(args, context) {
|
|
2081
|
+
const sessionId = args.sessionId || (0, import_uuid2.v4)();
|
|
2082
|
+
if (this.sessions.has(sessionId)) {
|
|
2083
|
+
return Promise.reject(new Error(`Session with id: ${args.sessionId} already present`));
|
|
2084
|
+
}
|
|
2085
|
+
const opts = {
|
|
2086
|
+
...args,
|
|
2087
|
+
sessionId,
|
|
2088
|
+
context
|
|
2089
|
+
};
|
|
2090
|
+
if (!opts.op?.presentationSignCallback) {
|
|
2091
|
+
opts.op = {
|
|
2092
|
+
...opts.op,
|
|
2093
|
+
presentationSignCallback: this.presentationSignCallback
|
|
2094
|
+
};
|
|
2095
|
+
}
|
|
2096
|
+
const session = await OpSession.init(opts);
|
|
2097
|
+
this.sessions.set(sessionId, session);
|
|
2098
|
+
return session;
|
|
2099
|
+
}
|
|
2100
|
+
async siopRemoveOPSession(args, context) {
|
|
2101
|
+
return this.sessions.delete(args.sessionId);
|
|
2102
|
+
}
|
|
2103
|
+
async siopRegisterOPCustomApproval(args, context) {
|
|
2104
|
+
if (this.customApprovals[args.key] !== void 0) {
|
|
2105
|
+
return Promise.reject(new Error(`Custom approval with key: ${args.key} already present`));
|
|
2106
|
+
}
|
|
2107
|
+
this.customApprovals[args.key] = args.customApproval;
|
|
2108
|
+
}
|
|
2109
|
+
async siopRemoveOPCustomApproval(args, context) {
|
|
2110
|
+
return delete this.customApprovals[args.key];
|
|
2111
|
+
}
|
|
2112
|
+
async siopGetMachineInterpreter(opts, context) {
|
|
2113
|
+
const { stateNavigationListener, url } = opts;
|
|
2114
|
+
const services = {
|
|
2115
|
+
createConfig: /* @__PURE__ */ __name((args) => this.siopCreateConfig(args), "createConfig"),
|
|
2116
|
+
getSiopRequest: /* @__PURE__ */ __name((args) => this.siopGetSiopRequest(args, context), "getSiopRequest"),
|
|
2117
|
+
getSelectableCredentials: /* @__PURE__ */ __name((args) => this.siopGetSelectableCredentials(args, context), "getSelectableCredentials"),
|
|
2118
|
+
retrieveContact: /* @__PURE__ */ __name((args) => this.siopRetrieveContact(args, context), "retrieveContact"),
|
|
2119
|
+
addContactIdentity: /* @__PURE__ */ __name((args) => this.siopAddContactIdentity(args, context), "addContactIdentity"),
|
|
2120
|
+
sendResponse: /* @__PURE__ */ __name((args) => this.siopSendResponse(args, context), "sendResponse"),
|
|
2121
|
+
...opts?.services
|
|
2122
|
+
};
|
|
2123
|
+
const siopv2MachineOpts = {
|
|
2124
|
+
...opts,
|
|
2125
|
+
url,
|
|
2126
|
+
stateNavigationListener,
|
|
2127
|
+
services: {
|
|
2128
|
+
...services,
|
|
2129
|
+
...opts.services
|
|
2130
|
+
}
|
|
2131
|
+
};
|
|
2132
|
+
return Siopv2Machine.newInstance(siopv2MachineOpts);
|
|
2133
|
+
}
|
|
2134
|
+
async siopCreateConfig(context) {
|
|
2135
|
+
const { url } = context;
|
|
2136
|
+
if (!url) {
|
|
2137
|
+
return Promise.reject(Error("Missing request uri in context"));
|
|
2138
|
+
}
|
|
2139
|
+
return {
|
|
2140
|
+
id: (0, import_uuid2.v4)(),
|
|
2141
|
+
// FIXME: Update these values in SSI-SDK. Only the URI (not a redirectURI) would be available at this point
|
|
2142
|
+
sessionId: (0, import_uuid2.v4)(),
|
|
2143
|
+
redirectUrl: url
|
|
2144
|
+
};
|
|
2145
|
+
}
|
|
2146
|
+
async siopGetSiopRequest(args, context) {
|
|
2147
|
+
const { agent } = context;
|
|
2148
|
+
const { didAuthConfig } = args;
|
|
2149
|
+
if (args.url === void 0) {
|
|
2150
|
+
return Promise.reject(Error("Missing request uri in context"));
|
|
2151
|
+
}
|
|
2152
|
+
if (didAuthConfig === void 0) {
|
|
2153
|
+
return Promise.reject(Error("Missing config in context"));
|
|
2154
|
+
}
|
|
2155
|
+
const { sessionId, redirectUrl } = didAuthConfig;
|
|
2156
|
+
const session = await agent.siopGetOPSession({
|
|
2157
|
+
sessionId
|
|
2158
|
+
}).catch(async () => await agent.siopRegisterOPSession({
|
|
2159
|
+
requestJwtOrUri: redirectUrl,
|
|
2160
|
+
sessionId,
|
|
2161
|
+
op: {
|
|
2162
|
+
eventEmitter: this.eventEmitter,
|
|
2163
|
+
hasher: this.hasher
|
|
2164
|
+
}
|
|
2165
|
+
}));
|
|
2166
|
+
logger4.debug(`session: ${JSON.stringify(session.id, null, 2)}`);
|
|
2167
|
+
const verifiedAuthorizationRequest = await session.getAuthorizationRequest();
|
|
2168
|
+
const clientName = verifiedAuthorizationRequest.registrationMetadataPayload?.client_name;
|
|
2169
|
+
const url = verifiedAuthorizationRequest.responseURI ?? (args.url.includes("request_uri") ? decodeURIComponent(args.url.split("?request_uri=")[1].trim()) : verifiedAuthorizationRequest.issuer ?? verifiedAuthorizationRequest.registrationMetadataPayload?.client_id);
|
|
2170
|
+
const uri = url.includes("://") ? new URL(url) : void 0;
|
|
2171
|
+
const correlationId = uri?.hostname ?? await this.determineCorrelationId(uri, verifiedAuthorizationRequest, clientName, context);
|
|
2172
|
+
const clientId = await verifiedAuthorizationRequest.authorizationRequest.getMergedProperty("client_id");
|
|
2173
|
+
return {
|
|
2174
|
+
issuer: verifiedAuthorizationRequest.issuer,
|
|
2175
|
+
correlationId,
|
|
2176
|
+
registrationMetadataPayload: verifiedAuthorizationRequest.registrationMetadataPayload,
|
|
2177
|
+
uri,
|
|
2178
|
+
name: clientName,
|
|
2179
|
+
clientId,
|
|
2180
|
+
presentationDefinitions: await verifiedAuthorizationRequest.authorizationRequest.containsResponseType("vp_token") || verifiedAuthorizationRequest.versions.every((version) => version <= import_did_auth_siop5.SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1) && verifiedAuthorizationRequest.presentationDefinitions && verifiedAuthorizationRequest.presentationDefinitions.length > 0 ? verifiedAuthorizationRequest.presentationDefinitions : void 0,
|
|
2181
|
+
dcqlQuery: verifiedAuthorizationRequest.dcqlQuery
|
|
2182
|
+
};
|
|
2183
|
+
}
|
|
2184
|
+
async determineCorrelationId(uri, verifiedAuthorizationRequest, clientName, context) {
|
|
2185
|
+
if (uri) {
|
|
2186
|
+
return await translateCorrelationIdToName(uri.hostname, context) ?? uri.hostname;
|
|
2187
|
+
}
|
|
2188
|
+
if (verifiedAuthorizationRequest.issuer) {
|
|
2189
|
+
const issuerHostname = verifiedAuthorizationRequest.issuer.split("://")[1];
|
|
2190
|
+
return await translateCorrelationIdToName(issuerHostname, context) ?? issuerHostname;
|
|
2191
|
+
}
|
|
2192
|
+
if (clientName) {
|
|
2193
|
+
return clientName;
|
|
2194
|
+
}
|
|
2195
|
+
throw new Error("Can't determine correlationId from request");
|
|
2196
|
+
}
|
|
2197
|
+
async siopRetrieveContact(args, context) {
|
|
2198
|
+
const { authorizationRequestData } = args;
|
|
2199
|
+
const { agent } = context;
|
|
2200
|
+
if (authorizationRequestData === void 0) {
|
|
2201
|
+
return Promise.reject(Error("Missing authorization request data in context"));
|
|
2202
|
+
}
|
|
2203
|
+
return agent.cmGetContacts({
|
|
2204
|
+
filter: [
|
|
2205
|
+
{
|
|
2206
|
+
identities: {
|
|
2207
|
+
identifier: {
|
|
2208
|
+
correlationId: authorizationRequestData.correlationId
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
]
|
|
2213
|
+
}).then((contacts) => contacts.length === 1 ? contacts[0] : void 0);
|
|
2214
|
+
}
|
|
2215
|
+
async siopAddContactIdentity(args, context) {
|
|
2216
|
+
const { agent } = context;
|
|
2217
|
+
const { contact, authorizationRequestData } = args;
|
|
2218
|
+
if (contact === void 0) {
|
|
2219
|
+
return Promise.reject(Error("Missing contact in context"));
|
|
2220
|
+
}
|
|
2221
|
+
if (authorizationRequestData === void 0) {
|
|
2222
|
+
return Promise.reject(Error("Missing authorization request data in context"));
|
|
2223
|
+
}
|
|
2224
|
+
const clientId = authorizationRequestData.clientId ?? authorizationRequestData.issuer;
|
|
2225
|
+
const correlationId = clientId ? clientId.startsWith("did:") ? clientId : `${new URL(clientId).protocol}//${new URL(clientId).hostname}` : void 0;
|
|
2226
|
+
if (correlationId) {
|
|
2227
|
+
const identity = {
|
|
2228
|
+
alias: correlationId,
|
|
2229
|
+
origin: import_ssi_sdk8.IdentityOrigin.EXTERNAL,
|
|
2230
|
+
roles: [
|
|
2231
|
+
import_ssi_sdk8.CredentialRole.ISSUER
|
|
2232
|
+
],
|
|
2233
|
+
identifier: {
|
|
2234
|
+
type: correlationId.startsWith("did:") ? import_ssi_sdk8.CorrelationIdentifierType.DID : import_ssi_sdk8.CorrelationIdentifierType.URL,
|
|
2235
|
+
correlationId
|
|
2236
|
+
}
|
|
2237
|
+
};
|
|
2238
|
+
const addedIdentity = await agent.cmAddIdentity({
|
|
2239
|
+
contactId: contact.id,
|
|
2240
|
+
identity
|
|
2241
|
+
});
|
|
2242
|
+
await context.agent.emit(Siopv2HolderEvent.CONTACT_IDENTITY_CREATED, {
|
|
2243
|
+
contactId: contact.id,
|
|
2244
|
+
identity: addedIdentity
|
|
2245
|
+
});
|
|
2246
|
+
logger4.info(`Contact identity created: ${JSON.stringify(addedIdentity)}`);
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
async siopSendResponse(args, context) {
|
|
2250
|
+
const { didAuthConfig, authorizationRequestData, selectedCredentials, isFirstParty } = args;
|
|
2251
|
+
if (didAuthConfig === void 0) {
|
|
2252
|
+
return Promise.reject(Error("Missing config in context"));
|
|
2253
|
+
}
|
|
2254
|
+
if (authorizationRequestData === void 0) {
|
|
2255
|
+
return Promise.reject(Error("Missing authorization request data in context"));
|
|
2256
|
+
}
|
|
2257
|
+
const pex = new import_pex4.PEX({
|
|
2258
|
+
hasher: this.hasher
|
|
2259
|
+
});
|
|
2260
|
+
const verifiableCredentialsWithDefinition = [];
|
|
2261
|
+
const dcqlCredentialsWithCredentials = /* @__PURE__ */ new Map();
|
|
2262
|
+
if (Array.isArray(authorizationRequestData.presentationDefinitions) && authorizationRequestData?.presentationDefinitions.length > 0) {
|
|
2263
|
+
try {
|
|
2264
|
+
authorizationRequestData.presentationDefinitions?.forEach((presentationDefinition) => {
|
|
2265
|
+
const { areRequiredCredentialsPresent, verifiableCredential: verifiableCredentials } = pex.selectFrom(presentationDefinition.definition, selectedCredentials.map((udc) => udc.originalVerifiableCredential));
|
|
2266
|
+
if (areRequiredCredentialsPresent !== import_pex4.Status.ERROR && verifiableCredentials) {
|
|
2267
|
+
let uniqueDigitalCredentials = [];
|
|
2268
|
+
uniqueDigitalCredentials = verifiableCredentials.map((vc) => {
|
|
2269
|
+
const hash = typeof vc === "string" ? (0, import_utils.computeEntryHash)(vc.split("~"[0])) : (0, import_utils.computeEntryHash)(vc);
|
|
2270
|
+
const udc = selectedCredentials.find((udc2) => udc2.hash == hash || udc2.originalVerifiableCredential == vc);
|
|
2271
|
+
if (!udc) {
|
|
2272
|
+
throw Error(`UniqueDigitalCredential could not be found in store. Either the credential is not present in the store or the hash is not correct.`);
|
|
2273
|
+
}
|
|
2274
|
+
return udc;
|
|
2275
|
+
});
|
|
2276
|
+
verifiableCredentialsWithDefinition.push({
|
|
2277
|
+
definition: presentationDefinition,
|
|
2278
|
+
credentials: uniqueDigitalCredentials
|
|
2279
|
+
});
|
|
2280
|
+
}
|
|
2281
|
+
});
|
|
2282
|
+
} catch (e) {
|
|
2283
|
+
return Promise.reject(e);
|
|
2284
|
+
}
|
|
2285
|
+
if (verifiableCredentialsWithDefinition.length === 0) {
|
|
2286
|
+
return Promise.reject(Error("None of the selected credentials match any of the presentation definitions."));
|
|
2287
|
+
}
|
|
2288
|
+
} else if (authorizationRequestData.dcqlQuery) {
|
|
2289
|
+
if (this.hasMDocCredentials(selectedCredentials) || this.hasSdJwtCredentials(selectedCredentials)) {
|
|
2290
|
+
try {
|
|
2291
|
+
selectedCredentials.forEach((vc) => {
|
|
2292
|
+
if (this.isSdJwtCredential(vc)) {
|
|
2293
|
+
const payload = vc.originalVerifiableCredential.decodedPayload;
|
|
2294
|
+
const result = {
|
|
2295
|
+
claims: payload,
|
|
2296
|
+
vct: payload.vct,
|
|
2297
|
+
credential_format: "vc+sd-jwt"
|
|
2298
|
+
};
|
|
2299
|
+
dcqlCredentialsWithCredentials.set(result, vc);
|
|
2300
|
+
} else {
|
|
2301
|
+
throw Error(`Invalid credential format: ${vc.digitalCredential.documentFormat}`);
|
|
2302
|
+
}
|
|
2303
|
+
});
|
|
2304
|
+
} catch (e) {
|
|
2305
|
+
return Promise.reject(e);
|
|
2306
|
+
}
|
|
2307
|
+
const dcqlPresentationRecord = {};
|
|
2308
|
+
const queryResult = import_dcql3.DcqlQuery.query(authorizationRequestData.dcqlQuery, Array.from(dcqlCredentialsWithCredentials.keys()));
|
|
2309
|
+
for (const [key, value] of Object.entries(queryResult.credential_matches)) {
|
|
2310
|
+
if (value.success) {
|
|
2311
|
+
dcqlPresentationRecord[key] = this.retrieveEncodedCredential(dcqlCredentialsWithCredentials.get(value.output));
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
}
|
|
2316
|
+
const response = await siopSendAuthorizationResponse(import_ssi_sdk8.ConnectionType.SIOPv2_OpenID4VP, {
|
|
2317
|
+
sessionId: didAuthConfig.sessionId,
|
|
2318
|
+
...args.idOpts && {
|
|
2319
|
+
idOpts: args.idOpts
|
|
2320
|
+
},
|
|
2321
|
+
...authorizationRequestData.presentationDefinitions !== void 0 && {
|
|
2322
|
+
verifiableCredentialsWithDefinition
|
|
2323
|
+
},
|
|
2324
|
+
isFirstParty,
|
|
2325
|
+
hasher: this.hasher
|
|
2326
|
+
}, context);
|
|
2327
|
+
const contentType = response.headers.get("content-type") || "";
|
|
2328
|
+
let responseBody = null;
|
|
2329
|
+
const text = await response.text();
|
|
2330
|
+
if (text) {
|
|
2331
|
+
responseBody = contentType.includes("application/json") || text.startsWith("{") ? JSON.parse(text) : text;
|
|
2332
|
+
}
|
|
2333
|
+
return {
|
|
2334
|
+
body: responseBody,
|
|
2335
|
+
url: response?.url,
|
|
2336
|
+
queryParams: (0, import_did_auth_siop5.decodeUriAsJson)(response?.url)
|
|
2337
|
+
};
|
|
2338
|
+
}
|
|
2339
|
+
hasMDocCredentials = /* @__PURE__ */ __name((credentials) => {
|
|
2340
|
+
return credentials.some(this.isMDocCredential);
|
|
2341
|
+
}, "hasMDocCredentials");
|
|
2342
|
+
isMDocCredential = /* @__PURE__ */ __name((credential) => {
|
|
2343
|
+
return credential.digitalCredential.documentFormat === import_ssi_sdk8.CredentialDocumentFormat.MSO_MDOC && credential.digitalCredential.documentType === import_ssi_sdk8.DocumentType.VC;
|
|
2344
|
+
}, "isMDocCredential");
|
|
2345
|
+
hasSdJwtCredentials = /* @__PURE__ */ __name((credentials) => {
|
|
2346
|
+
return credentials.some(this.isSdJwtCredential);
|
|
2347
|
+
}, "hasSdJwtCredentials");
|
|
2348
|
+
isSdJwtCredential = /* @__PURE__ */ __name((credential) => {
|
|
2349
|
+
return credential.digitalCredential.documentFormat === import_ssi_sdk8.CredentialDocumentFormat.SD_JWT && credential.digitalCredential.documentType === import_ssi_sdk8.DocumentType.VC;
|
|
2350
|
+
}, "isSdJwtCredential");
|
|
2351
|
+
retrieveEncodedCredential = /* @__PURE__ */ __name((credential) => {
|
|
2352
|
+
return credential.originalVerifiableCredential !== void 0 && credential.originalVerifiableCredential !== null && credential?.originalVerifiableCredential?.compactSdJwtVc !== void 0 && credential?.originalVerifiableCredential?.compactSdJwtVc !== null ? credential.originalVerifiableCredential.compactSdJwtVc : credential.originalVerifiableCredential;
|
|
2353
|
+
}, "retrieveEncodedCredential");
|
|
2354
|
+
async siopGetSelectableCredentials(args, context) {
|
|
2355
|
+
const { authorizationRequestData } = args;
|
|
2356
|
+
if (!authorizationRequestData || !authorizationRequestData.presentationDefinitions || authorizationRequestData.presentationDefinitions.length === 0) {
|
|
2357
|
+
return Promise.reject(Error("Missing required fields in arguments or context"));
|
|
2358
|
+
}
|
|
2359
|
+
if (authorizationRequestData.presentationDefinitions.length > 1) {
|
|
2360
|
+
return Promise.reject(Error("Multiple presentation definitions present"));
|
|
2361
|
+
}
|
|
2362
|
+
return getSelectableCredentials(authorizationRequestData.presentationDefinitions[0].definition, context);
|
|
2363
|
+
}
|
|
2364
|
+
};
|
|
2365
|
+
|
|
2366
|
+
// src/machine/CallbackStateListener.ts
|
|
2367
|
+
var import_ssi_types8 = require("@sphereon/ssi-types");
|
|
2368
|
+
var logger5 = import_ssi_types8.Loggers.DEFAULT.options("sphereon:siopv2-oid4vp:op-auth", {
|
|
2369
|
+
defaultLogLevel: import_ssi_types8.LogLevel.DEBUG,
|
|
2370
|
+
methods: [
|
|
2371
|
+
import_ssi_types8.LogMethod.CONSOLE
|
|
2372
|
+
]
|
|
2373
|
+
}).get("sphereon:siopv2-oid4vp:op-auth");
|
|
2374
|
+
var OID4VPCallbackStateListener = /* @__PURE__ */ __name((callbacks) => {
|
|
2375
|
+
return async (oid4vciMachine, state) => {
|
|
2376
|
+
if (state._event.type === "internal") {
|
|
2377
|
+
logger5.debug("oid4vpCallbackStateListener: internal event");
|
|
2378
|
+
return;
|
|
2379
|
+
}
|
|
2380
|
+
logger5.info(`VP state listener state: ${JSON.stringify(state.value)}`);
|
|
2381
|
+
if (!callbacks || callbacks.size === 0) {
|
|
2382
|
+
logger5.info(`VP no callbacks registered for state: ${JSON.stringify(state.value)}`);
|
|
2383
|
+
return;
|
|
2384
|
+
}
|
|
2385
|
+
for (const [stateKey, callback] of callbacks) {
|
|
2386
|
+
if (state.matches(stateKey)) {
|
|
2387
|
+
logger5.log(`VP state callback for state: ${JSON.stringify(state.value)}, will execute...`);
|
|
2388
|
+
await callback(oid4vciMachine, state).then(() => logger5.log(`VP state callback executed for state: ${JSON.stringify(state.value)}`)).catch((error) => {
|
|
2389
|
+
logger5.error(`VP state callback failed for state: ${JSON.stringify(state.value)}, error: ${JSON.stringify(error?.message)}, ${JSON.stringify(state.event)}`);
|
|
2390
|
+
if (error.stack) {
|
|
2391
|
+
logger5.error(error.stack);
|
|
2392
|
+
}
|
|
2393
|
+
});
|
|
2394
|
+
break;
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
};
|
|
2398
|
+
}, "OID4VPCallbackStateListener");
|
|
2399
|
+
|
|
2400
|
+
// src/link-handler/index.ts
|
|
2401
|
+
var import_ssi_sdk9 = require("@sphereon/ssi-sdk.agent-config");
|
|
2402
|
+
var import_ssi_sdk10 = require("@sphereon/ssi-sdk.core");
|
|
2403
|
+
var import_ssi_sdk11 = require("@sphereon/ssi-sdk.xstate-machine-persistence");
|
|
2404
|
+
var import_ssi_types9 = require("@sphereon/ssi-types");
|
|
2405
|
+
var logger6 = import_ssi_types9.Loggers.DEFAULT.options(LOGGER_NAMESPACE, {}).get(LOGGER_NAMESPACE);
|
|
2406
|
+
var Siopv2OID4VPLinkHandler = class extends import_ssi_sdk10.LinkHandlerAdapter {
|
|
2407
|
+
static {
|
|
2408
|
+
__name(this, "Siopv2OID4VPLinkHandler");
|
|
2409
|
+
}
|
|
2410
|
+
context;
|
|
2411
|
+
stateNavigationListener;
|
|
2412
|
+
noStateMachinePersistence;
|
|
2413
|
+
idOpts;
|
|
2414
|
+
constructor(args) {
|
|
2415
|
+
super({
|
|
2416
|
+
...args,
|
|
2417
|
+
id: "Siopv2"
|
|
2418
|
+
});
|
|
2419
|
+
this.context = args.context;
|
|
2420
|
+
this.noStateMachinePersistence = args.noStateMachinePersistence === true;
|
|
2421
|
+
this.stateNavigationListener = args.stateNavigationListener;
|
|
2422
|
+
this.idOpts = args.idOpts;
|
|
2423
|
+
}
|
|
2424
|
+
async handle(url, opts) {
|
|
2425
|
+
logger6.debug(`handling SIOP link: ${url}`);
|
|
2426
|
+
const siopv2Machine = await this.context.agent.siopGetMachineInterpreter({
|
|
2427
|
+
url,
|
|
2428
|
+
idOpts: opts?.idOpts ?? this.idOpts,
|
|
2429
|
+
stateNavigationListener: this.stateNavigationListener
|
|
2430
|
+
});
|
|
2431
|
+
const interpreter = siopv2Machine.interpreter;
|
|
2432
|
+
if (!this.noStateMachinePersistence && !opts?.machineState && (0, import_ssi_sdk9.contextHasPlugin)(this.context, "machineStatesFindActive")) {
|
|
2433
|
+
const init = await (0, import_ssi_sdk11.interpreterStartOrResume)({
|
|
2434
|
+
interpreter,
|
|
2435
|
+
context: this.context,
|
|
2436
|
+
cleanupAllOtherInstances: true,
|
|
2437
|
+
cleanupOnFinalState: true,
|
|
2438
|
+
singletonCheck: true,
|
|
2439
|
+
noRegistration: this.noStateMachinePersistence
|
|
2440
|
+
});
|
|
2441
|
+
logger6.debug(`SIOP machine started for link: ${url}`, init);
|
|
2442
|
+
} else {
|
|
2443
|
+
interpreter.start(opts?.machineState);
|
|
2444
|
+
logger6.debug(`SIOP machine started for link: ${url}`);
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
};
|
|
2448
|
+
|
|
2449
|
+
// src/index.ts
|
|
2450
|
+
var schema = require_plugin_schema();
|
|
2451
|
+
//# sourceMappingURL=index.cjs.map
|