@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth 0.33.1-next.3 → 0.33.1-next.73
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 +1010 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{types/ISIOPv2RP.d.ts → index.d.cts} +83 -31
- package/dist/index.d.ts +214 -4
- package/dist/index.js +988 -24
- package/dist/index.js.map +1 -1
- package/package.json +35 -25
- package/dist/RPInstance.d.ts +0 -21
- package/dist/RPInstance.d.ts.map +0 -1
- package/dist/RPInstance.js +0 -139
- package/dist/RPInstance.js.map +0 -1
- package/dist/agent/SIOPv2RP.d.ts +0 -31
- package/dist/agent/SIOPv2RP.d.ts.map +0 -1
- package/dist/agent/SIOPv2RP.js +0 -284
- package/dist/agent/SIOPv2RP.js.map +0 -1
- package/dist/functions.d.ts +0 -26
- package/dist/functions.d.ts.map +0 -1
- package/dist/functions.js +0 -243
- package/dist/functions.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/types/ISIOPv2RP.d.ts.map +0 -1
- package/dist/types/ISIOPv2RP.js +0 -10
- package/dist/types/ISIOPv2RP.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1010 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
|
|
24
|
+
// plugin.schema.json
|
|
25
|
+
var require_plugin_schema = __commonJS({
|
|
26
|
+
"plugin.schema.json"(exports, module2) {
|
|
27
|
+
module2.exports = {
|
|
28
|
+
IDidAuthSiopOpAuthenticator: {
|
|
29
|
+
components: {
|
|
30
|
+
schemas: {
|
|
31
|
+
IGetSiopSessionArgs: {
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {
|
|
34
|
+
sessionId: {
|
|
35
|
+
type: "string"
|
|
36
|
+
},
|
|
37
|
+
additionalProperties: false
|
|
38
|
+
},
|
|
39
|
+
required: ["sessionId"],
|
|
40
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.getSessionForSiop } "
|
|
41
|
+
},
|
|
42
|
+
IRegisterSiopSessionArgs: {
|
|
43
|
+
type: "object",
|
|
44
|
+
properties: {
|
|
45
|
+
identifier: {
|
|
46
|
+
type: "object",
|
|
47
|
+
properties: {
|
|
48
|
+
did: {
|
|
49
|
+
type: "string"
|
|
50
|
+
},
|
|
51
|
+
alias: {
|
|
52
|
+
type: "string"
|
|
53
|
+
},
|
|
54
|
+
provider: {
|
|
55
|
+
type: "string"
|
|
56
|
+
},
|
|
57
|
+
controllerKeyId: {
|
|
58
|
+
type: "string"
|
|
59
|
+
},
|
|
60
|
+
keys: {
|
|
61
|
+
type: "array",
|
|
62
|
+
items: {
|
|
63
|
+
type: "object",
|
|
64
|
+
properties: {
|
|
65
|
+
additionalProperties: true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
services: {
|
|
70
|
+
type: "array",
|
|
71
|
+
items: {
|
|
72
|
+
type: "object",
|
|
73
|
+
properties: {
|
|
74
|
+
additionalProperties: true
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
additionalProperties: false,
|
|
80
|
+
required: ["did", "provider", "keys", "services"]
|
|
81
|
+
},
|
|
82
|
+
sessionId: {
|
|
83
|
+
type: "string"
|
|
84
|
+
},
|
|
85
|
+
expiresIn: {
|
|
86
|
+
type: "number"
|
|
87
|
+
},
|
|
88
|
+
additionalProperties: false
|
|
89
|
+
},
|
|
90
|
+
required: ["identifier"],
|
|
91
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.registerSessionForSiop } "
|
|
92
|
+
},
|
|
93
|
+
IRemoveSiopSessionArgs: {
|
|
94
|
+
type: "object",
|
|
95
|
+
properties: {
|
|
96
|
+
sessionId: {
|
|
97
|
+
type: "string"
|
|
98
|
+
},
|
|
99
|
+
additionalProperties: false
|
|
100
|
+
},
|
|
101
|
+
required: ["sessionId"],
|
|
102
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.removeSessionForSiop } "
|
|
103
|
+
},
|
|
104
|
+
IAuthenticateWithSiopArgs: {
|
|
105
|
+
type: "object",
|
|
106
|
+
properties: {
|
|
107
|
+
sessionId: {
|
|
108
|
+
type: "string"
|
|
109
|
+
},
|
|
110
|
+
stateId: {
|
|
111
|
+
type: "string"
|
|
112
|
+
},
|
|
113
|
+
redirectUrl: {
|
|
114
|
+
type: "string"
|
|
115
|
+
},
|
|
116
|
+
additionalProperties: false
|
|
117
|
+
},
|
|
118
|
+
required: ["sessionId", "stateId", "redirectUrl"],
|
|
119
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.authenticateWithSiop } "
|
|
120
|
+
},
|
|
121
|
+
IResponse: {
|
|
122
|
+
type: "object",
|
|
123
|
+
properties: {
|
|
124
|
+
status: {
|
|
125
|
+
type: "number"
|
|
126
|
+
},
|
|
127
|
+
additionalProperties: true
|
|
128
|
+
},
|
|
129
|
+
required: ["status"],
|
|
130
|
+
description: "Result of {@link DidAuthSiopOpAuthenticator.authenticateWithSiop & DidAuthSiopOpAuthenticator.sendSiopAuthenticationResponse } "
|
|
131
|
+
},
|
|
132
|
+
IGetSiopAuthenticationRequestFromRpArgs: {
|
|
133
|
+
type: "object",
|
|
134
|
+
properties: {
|
|
135
|
+
sessionId: {
|
|
136
|
+
type: "string"
|
|
137
|
+
},
|
|
138
|
+
stateId: {
|
|
139
|
+
type: "string"
|
|
140
|
+
},
|
|
141
|
+
redirectUrl: {
|
|
142
|
+
type: "string"
|
|
143
|
+
},
|
|
144
|
+
additionalProperties: false
|
|
145
|
+
},
|
|
146
|
+
required: ["sessionId", "stateId", "redirectUrl"],
|
|
147
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.getSiopAuthenticationRequestFromRP } "
|
|
148
|
+
},
|
|
149
|
+
ParsedAuthenticationRequestURI: {
|
|
150
|
+
type: "object",
|
|
151
|
+
properties: {
|
|
152
|
+
jwt: {
|
|
153
|
+
type: "string"
|
|
154
|
+
},
|
|
155
|
+
requestPayload: {
|
|
156
|
+
type: "object",
|
|
157
|
+
properties: {
|
|
158
|
+
additionalProperties: true
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
registration: {
|
|
162
|
+
type: "object",
|
|
163
|
+
properties: {
|
|
164
|
+
additionalProperties: true
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
additionalProperties: false
|
|
168
|
+
},
|
|
169
|
+
required: ["jwt", "requestPayload", "registration"],
|
|
170
|
+
description: "Result of {@link DidAuthSiopOpAuthenticator.getSiopAuthenticationRequestFromRP } "
|
|
171
|
+
},
|
|
172
|
+
IGetSiopAuthenticationRequestDetailsArgs: {
|
|
173
|
+
type: "object",
|
|
174
|
+
properties: {
|
|
175
|
+
sessionId: {
|
|
176
|
+
type: "string"
|
|
177
|
+
},
|
|
178
|
+
verifiedAuthenticationRequest: {
|
|
179
|
+
type: "object",
|
|
180
|
+
properties: {
|
|
181
|
+
additionalProperties: true
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
credentialFilter: {
|
|
185
|
+
type: "object",
|
|
186
|
+
properties: {
|
|
187
|
+
additionalProperties: true
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
additionalProperties: false
|
|
191
|
+
},
|
|
192
|
+
required: ["sessionId", "verifiedAuthenticationRequest"],
|
|
193
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.getSiopAuthenticationRequestDetails } "
|
|
194
|
+
},
|
|
195
|
+
IAuthRequestDetails: {
|
|
196
|
+
type: "object",
|
|
197
|
+
properties: {
|
|
198
|
+
id: {
|
|
199
|
+
type: "string"
|
|
200
|
+
},
|
|
201
|
+
alsoKnownAs: {
|
|
202
|
+
type: "array",
|
|
203
|
+
items: {
|
|
204
|
+
type: "string"
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
vpResponseOpts: {
|
|
208
|
+
type: "object",
|
|
209
|
+
properties: {
|
|
210
|
+
additionalProperties: true
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
additionalProperties: false
|
|
214
|
+
},
|
|
215
|
+
required: ["id", "vpResponseOpts"],
|
|
216
|
+
description: "Result of {@link DidAuthSiopOpAuthenticator.getSiopAuthenticationRequestDetails } "
|
|
217
|
+
},
|
|
218
|
+
IVerifySiopAuthenticationRequestUriArgs: {
|
|
219
|
+
type: "object",
|
|
220
|
+
properties: {
|
|
221
|
+
sessionId: {
|
|
222
|
+
type: "string"
|
|
223
|
+
},
|
|
224
|
+
ParsedAuthenticationRequestURI: {
|
|
225
|
+
type: "object",
|
|
226
|
+
properties: {
|
|
227
|
+
additionalProperties: true
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
additionalProperties: false
|
|
231
|
+
},
|
|
232
|
+
required: ["sessionId", "ParsedAuthenticationRequestURI"],
|
|
233
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.verifySiopAuthenticationRequestURI } "
|
|
234
|
+
},
|
|
235
|
+
VerifiedAuthorizationRequest: {
|
|
236
|
+
type: "object",
|
|
237
|
+
properties: {
|
|
238
|
+
payload: {
|
|
239
|
+
type: "object",
|
|
240
|
+
properties: {
|
|
241
|
+
additionalProperties: true
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
presentationDefinitions: {
|
|
245
|
+
type: "object",
|
|
246
|
+
properties: {
|
|
247
|
+
additionalProperties: true
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
verifyOpts: {
|
|
251
|
+
type: "object",
|
|
252
|
+
properties: {
|
|
253
|
+
additionalProperties: true
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
additionalProperties: false
|
|
257
|
+
},
|
|
258
|
+
required: ["payload", "verifyOpts"],
|
|
259
|
+
description: "Result of {@link DidAuthSiopOpAuthenticator.verifySiopAuthenticationRequestURI } "
|
|
260
|
+
},
|
|
261
|
+
ISendSiopAuthenticationResponseArgs: {
|
|
262
|
+
type: "object",
|
|
263
|
+
properties: {
|
|
264
|
+
sessionId: {
|
|
265
|
+
type: "string"
|
|
266
|
+
},
|
|
267
|
+
verifiedAuthenticationRequest: {
|
|
268
|
+
type: "object",
|
|
269
|
+
properties: {
|
|
270
|
+
additionalProperties: true
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
verifiablePresentationResponse: {
|
|
274
|
+
type: "object",
|
|
275
|
+
properties: {
|
|
276
|
+
additionalProperties: true
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
additionalProperties: false
|
|
280
|
+
},
|
|
281
|
+
required: ["sessionId", "verifiedAuthenticationRequest"],
|
|
282
|
+
description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.sendSiopAuthenticationResponse } "
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
methods: {
|
|
286
|
+
getSessionForSiop: {
|
|
287
|
+
description: "Get SIOP session",
|
|
288
|
+
arguments: {
|
|
289
|
+
$ref: "#/components/schemas/IGetSiopSessionArgs"
|
|
290
|
+
},
|
|
291
|
+
returnType: "object"
|
|
292
|
+
},
|
|
293
|
+
registerSessionForSiop: {
|
|
294
|
+
description: "Register SIOP session",
|
|
295
|
+
arguments: {
|
|
296
|
+
$ref: "#/components/schemas/IRegisterSiopSessionArgs"
|
|
297
|
+
},
|
|
298
|
+
returnType: "object"
|
|
299
|
+
},
|
|
300
|
+
removeSessionForSiop: {
|
|
301
|
+
description: "Remove SIOP session",
|
|
302
|
+
arguments: {
|
|
303
|
+
$ref: "#/components/schemas/IRemoveSiopSessionArgs"
|
|
304
|
+
},
|
|
305
|
+
returnType: "boolean"
|
|
306
|
+
},
|
|
307
|
+
authenticateWithSiop: {
|
|
308
|
+
description: "Authenticate using DID Auth SIOP",
|
|
309
|
+
arguments: {
|
|
310
|
+
$ref: "#/components/schemas/IAuthenticateWithSiopArgs"
|
|
311
|
+
},
|
|
312
|
+
returnType: {
|
|
313
|
+
$ref: "#/components/schemas/Response"
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
getSiopAuthenticationRequestFromRP: {
|
|
317
|
+
description: "Get authentication request from RP",
|
|
318
|
+
arguments: {
|
|
319
|
+
$ref: "#/components/schemas/IGetSiopAuthenticationRequestFromRpArgs"
|
|
320
|
+
},
|
|
321
|
+
returnType: {
|
|
322
|
+
$ref: "#/components/schemas/ParsedAuthenticationRequestURI"
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
getSiopAuthenticationRequestDetails: {
|
|
326
|
+
description: "Get authentication request details",
|
|
327
|
+
arguments: {
|
|
328
|
+
$ref: "#/components/schemas/IGetSiopAuthenticationRequestDetailsArgs"
|
|
329
|
+
},
|
|
330
|
+
returnType: {
|
|
331
|
+
$ref: "#/components/schemas/IAuthRequestDetails"
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
verifySiopAuthenticationRequestURI: {
|
|
335
|
+
description: "Verify authentication request URI",
|
|
336
|
+
arguments: {
|
|
337
|
+
$ref: "#/components/schemas/IVerifySiopAuthenticationRequestUriArgs"
|
|
338
|
+
},
|
|
339
|
+
returnType: {
|
|
340
|
+
$ref: "#/components/schemas/VerifiedAuthorizationRequest"
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
sendSiopAuthenticationResponse: {
|
|
344
|
+
description: "Send authentication response",
|
|
345
|
+
arguments: {
|
|
346
|
+
$ref: "#/components/schemas/ISendSiopAuthenticationResponseArgs"
|
|
347
|
+
},
|
|
348
|
+
returnType: {
|
|
349
|
+
$ref: "#/components/schemas/IRequiredContext"
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// src/index.ts
|
|
360
|
+
var index_exports = {};
|
|
361
|
+
__export(index_exports, {
|
|
362
|
+
SIOPv2RP: () => SIOPv2RP,
|
|
363
|
+
VerifiedDataMode: () => VerifiedDataMode,
|
|
364
|
+
schema: () => schema
|
|
365
|
+
});
|
|
366
|
+
module.exports = __toCommonJS(index_exports);
|
|
367
|
+
|
|
368
|
+
// src/agent/SIOPv2RP.ts
|
|
369
|
+
var import_did_auth_siop2 = require("@sphereon/did-auth-siop");
|
|
370
|
+
var import_ssi_sdk_ext4 = require("@sphereon/ssi-sdk-ext.did-utils");
|
|
371
|
+
var import_ssi_types2 = require("@sphereon/ssi-types");
|
|
372
|
+
|
|
373
|
+
// src/functions.ts
|
|
374
|
+
var import_did_auth_siop = require("@sphereon/did-auth-siop");
|
|
375
|
+
var import_oid4vc_common = require("@sphereon/oid4vc-common");
|
|
376
|
+
var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.did-utils");
|
|
377
|
+
var import_ssi_sdk_ext2 = require("@sphereon/ssi-sdk-ext.identifier-resolution");
|
|
378
|
+
var import_ssi_types = require("@sphereon/ssi-types");
|
|
379
|
+
var import_events = require("events");
|
|
380
|
+
var import_ssi_sdk = require("@sphereon/ssi-sdk.core");
|
|
381
|
+
function getRequestVersion(rpOptions) {
|
|
382
|
+
if (Array.isArray(rpOptions.supportedVersions) && rpOptions.supportedVersions.length > 0) {
|
|
383
|
+
return rpOptions.supportedVersions[0];
|
|
384
|
+
}
|
|
385
|
+
return import_did_auth_siop.SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1;
|
|
386
|
+
}
|
|
387
|
+
__name(getRequestVersion, "getRequestVersion");
|
|
388
|
+
function getWellKnownDIDVerifyCallback(siopIdentifierOpts, context) {
|
|
389
|
+
return siopIdentifierOpts.wellknownDIDVerifyCallback ? siopIdentifierOpts.wellknownDIDVerifyCallback : async (args) => {
|
|
390
|
+
const result = await context.agent.cvVerifyCredential({
|
|
391
|
+
credential: args.credential,
|
|
392
|
+
fetchRemoteContexts: true
|
|
393
|
+
});
|
|
394
|
+
return {
|
|
395
|
+
verified: result.result
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
__name(getWellKnownDIDVerifyCallback, "getWellKnownDIDVerifyCallback");
|
|
400
|
+
function getPresentationVerificationCallback(idOpts, context) {
|
|
401
|
+
async function presentationVerificationCallback(args, presentationSubmission) {
|
|
402
|
+
if (import_ssi_types.CredentialMapper.isSdJwtEncoded(args)) {
|
|
403
|
+
const result2 = await context.agent.verifySdJwtPresentation({
|
|
404
|
+
presentation: args,
|
|
405
|
+
kb: true
|
|
406
|
+
});
|
|
407
|
+
return {
|
|
408
|
+
verified: !!result2.payload
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
if (import_ssi_types.CredentialMapper.isMsoMdocOid4VPEncoded(args)) {
|
|
412
|
+
if (context.agent.mdocOid4vpRPVerify === void 0) {
|
|
413
|
+
return Promise.reject("ImDLMdoc agent plugin must be enabled to support MsoMdoc types");
|
|
414
|
+
}
|
|
415
|
+
if (presentationSubmission !== void 0 && presentationSubmission !== null) {
|
|
416
|
+
const verifyResult = await context.agent.mdocOid4vpRPVerify({
|
|
417
|
+
vp_token: args,
|
|
418
|
+
presentation_submission: presentationSubmission
|
|
419
|
+
});
|
|
420
|
+
return {
|
|
421
|
+
verified: !verifyResult.error
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
throw Error(`mdocOid4vpRPVerify(...) method requires a presentation submission`);
|
|
425
|
+
}
|
|
426
|
+
const result = await context.agent.verifyPresentation({
|
|
427
|
+
presentation: args,
|
|
428
|
+
fetchRemoteContexts: true,
|
|
429
|
+
domain: (await context.agent.identifierManagedGet(idOpts)).kid?.split("#")[0]
|
|
430
|
+
});
|
|
431
|
+
return {
|
|
432
|
+
verified: result.verified
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
__name(presentationVerificationCallback, "presentationVerificationCallback");
|
|
436
|
+
return presentationVerificationCallback;
|
|
437
|
+
}
|
|
438
|
+
__name(getPresentationVerificationCallback, "getPresentationVerificationCallback");
|
|
439
|
+
async function createRPBuilder(args) {
|
|
440
|
+
const { rpOpts, pexOpts, context } = args;
|
|
441
|
+
const { identifierOpts } = rpOpts;
|
|
442
|
+
let definition = args.definition;
|
|
443
|
+
let dcqlQuery = args.dcql;
|
|
444
|
+
if (!definition && pexOpts && pexOpts.definitionId) {
|
|
445
|
+
const presentationDefinitionItems = await context.agent.pdmGetDefinitions({
|
|
446
|
+
filter: [
|
|
447
|
+
{
|
|
448
|
+
definitionId: pexOpts.definitionId,
|
|
449
|
+
version: pexOpts.version,
|
|
450
|
+
tenantId: pexOpts.tenantId
|
|
451
|
+
}
|
|
452
|
+
]
|
|
453
|
+
});
|
|
454
|
+
if (presentationDefinitionItems.length > 0) {
|
|
455
|
+
const presentationDefinitionItem = presentationDefinitionItems[0];
|
|
456
|
+
definition = presentationDefinitionItem.definitionPayload;
|
|
457
|
+
if (!dcqlQuery && presentationDefinitionItem.dcqlPayload) {
|
|
458
|
+
dcqlQuery = presentationDefinitionItem.dcqlPayload;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
const didMethods = identifierOpts.supportedDIDMethods ?? await (0, import_ssi_sdk_ext.getAgentDIDMethods)(context);
|
|
463
|
+
const eventEmitter = rpOpts.eventEmitter ?? new import_events.EventEmitter();
|
|
464
|
+
const defaultClientMetadata = {
|
|
465
|
+
// FIXME: All of the below should be configurable. Some should come from builder, some should be determined by the agent.
|
|
466
|
+
// For now it is either preconfigured or everything passed in as a single object
|
|
467
|
+
idTokenSigningAlgValuesSupported: [
|
|
468
|
+
import_oid4vc_common.SigningAlgo.EDDSA,
|
|
469
|
+
import_oid4vc_common.SigningAlgo.ES256,
|
|
470
|
+
import_oid4vc_common.SigningAlgo.ES256K
|
|
471
|
+
],
|
|
472
|
+
requestObjectSigningAlgValuesSupported: [
|
|
473
|
+
import_oid4vc_common.SigningAlgo.EDDSA,
|
|
474
|
+
import_oid4vc_common.SigningAlgo.ES256,
|
|
475
|
+
import_oid4vc_common.SigningAlgo.ES256K
|
|
476
|
+
],
|
|
477
|
+
responseTypesSupported: [
|
|
478
|
+
import_did_auth_siop.ResponseType.ID_TOKEN
|
|
479
|
+
],
|
|
480
|
+
client_name: "Sphereon",
|
|
481
|
+
vpFormatsSupported: {
|
|
482
|
+
jwt_vc: {
|
|
483
|
+
alg: [
|
|
484
|
+
"EdDSA",
|
|
485
|
+
"ES256K"
|
|
486
|
+
]
|
|
487
|
+
},
|
|
488
|
+
jwt_vp: {
|
|
489
|
+
alg: [
|
|
490
|
+
"ES256K",
|
|
491
|
+
"EdDSA"
|
|
492
|
+
]
|
|
493
|
+
}
|
|
494
|
+
},
|
|
495
|
+
scopesSupported: [
|
|
496
|
+
import_did_auth_siop.Scope.OPENID_DIDAUTHN
|
|
497
|
+
],
|
|
498
|
+
subjectTypesSupported: [
|
|
499
|
+
import_did_auth_siop.SubjectType.PAIRWISE
|
|
500
|
+
],
|
|
501
|
+
subject_syntax_types_supported: didMethods.map((method) => `did:${method}`),
|
|
502
|
+
passBy: import_did_auth_siop.PassBy.VALUE
|
|
503
|
+
};
|
|
504
|
+
const resolver = rpOpts.identifierOpts.resolveOpts?.resolver ?? (0, import_ssi_sdk_ext.getAgentResolver)(context, {
|
|
505
|
+
resolverResolution: true,
|
|
506
|
+
localResolution: true,
|
|
507
|
+
uniresolverResolution: rpOpts.identifierOpts.resolveOpts?.noUniversalResolverFallback !== true
|
|
508
|
+
});
|
|
509
|
+
let hasher = rpOpts.credentialOpts?.hasher;
|
|
510
|
+
if (!rpOpts.credentialOpts?.hasher || typeof rpOpts.credentialOpts?.hasher !== "function") {
|
|
511
|
+
hasher = import_ssi_sdk.defaultHasher;
|
|
512
|
+
}
|
|
513
|
+
const builder = import_did_auth_siop.RP.builder({
|
|
514
|
+
requestVersion: getRequestVersion(rpOpts)
|
|
515
|
+
}).withScope("openid", import_did_auth_siop.PropertyTarget.REQUEST_OBJECT).withResponseMode(rpOpts.responseMode ?? import_did_auth_siop.ResponseMode.POST).withResponseType(import_did_auth_siop.ResponseType.VP_TOKEN, import_did_auth_siop.PropertyTarget.REQUEST_OBJECT).withSupportedVersions(rpOpts.supportedVersions ?? [
|
|
516
|
+
import_did_auth_siop.SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1,
|
|
517
|
+
import_did_auth_siop.SupportedVersion.SIOPv2_ID1,
|
|
518
|
+
import_did_auth_siop.SupportedVersion.SIOPv2_D11
|
|
519
|
+
]).withEventEmitter(eventEmitter).withSessionManager(rpOpts.sessionManager ?? new import_did_auth_siop.InMemoryRPSessionManager(eventEmitter)).withClientMetadata(rpOpts.clientMetadataOpts ?? defaultClientMetadata, import_did_auth_siop.PropertyTarget.REQUEST_OBJECT).withVerifyJwtCallback(rpOpts.verifyJwtCallback ? rpOpts.verifyJwtCallback : getVerifyJwtCallback({
|
|
520
|
+
resolver,
|
|
521
|
+
verifyOpts: {
|
|
522
|
+
wellknownDIDVerifyCallback: getWellKnownDIDVerifyCallback(rpOpts.identifierOpts, context),
|
|
523
|
+
checkLinkedDomain: "if_present"
|
|
524
|
+
}
|
|
525
|
+
}, context)).withRevocationVerification(import_did_auth_siop.RevocationVerification.NEVER).withPresentationVerification(getPresentationVerificationCallback(identifierOpts.idOpts, context));
|
|
526
|
+
const oidfOpts = identifierOpts.oidfOpts;
|
|
527
|
+
if (oidfOpts && (0, import_ssi_sdk_ext2.isExternalIdentifierOIDFEntityIdOpts)(oidfOpts)) {
|
|
528
|
+
builder.withEntityId(oidfOpts.identifier, import_did_auth_siop.PropertyTarget.REQUEST_OBJECT).withClientIdScheme("entity_id", import_did_auth_siop.PropertyTarget.REQUEST_OBJECT);
|
|
529
|
+
} else {
|
|
530
|
+
const resolution = await context.agent.identifierManagedGet(identifierOpts.idOpts);
|
|
531
|
+
builder.withClientId(resolution.issuer ?? ((0, import_ssi_sdk_ext2.isManagedIdentifierDidResult)(resolution) ? resolution.did : resolution.jwkThumbprint), import_did_auth_siop.PropertyTarget.REQUEST_OBJECT).withClientIdScheme(resolution.clientIdScheme ?? identifierOpts.idOpts.clientIdScheme, import_did_auth_siop.PropertyTarget.REQUEST_OBJECT);
|
|
532
|
+
}
|
|
533
|
+
if (hasher) {
|
|
534
|
+
builder.withHasher(hasher);
|
|
535
|
+
}
|
|
536
|
+
if (definition) {
|
|
537
|
+
builder.withPresentationDefinition({
|
|
538
|
+
definition
|
|
539
|
+
}, import_did_auth_siop.PropertyTarget.REQUEST_OBJECT);
|
|
540
|
+
}
|
|
541
|
+
if (dcqlQuery) {
|
|
542
|
+
builder.withDcqlQuery(dcqlQuery);
|
|
543
|
+
}
|
|
544
|
+
if (rpOpts.responseRedirectUri) {
|
|
545
|
+
builder.withResponseRedirectUri(rpOpts.responseRedirectUri);
|
|
546
|
+
}
|
|
547
|
+
const createJwtCallback = signCallback(rpOpts.identifierOpts.idOpts, context);
|
|
548
|
+
builder.withCreateJwtCallback(createJwtCallback);
|
|
549
|
+
return builder;
|
|
550
|
+
}
|
|
551
|
+
__name(createRPBuilder, "createRPBuilder");
|
|
552
|
+
function signCallback(idOpts, context) {
|
|
553
|
+
return async (jwtIssuer, jwt, kid) => {
|
|
554
|
+
if (!((0, import_ssi_sdk_ext2.isManagedIdentifierDidOpts)(idOpts) || (0, import_ssi_sdk_ext2.isManagedIdentifierX5cOpts)(idOpts))) {
|
|
555
|
+
return Promise.reject(Error(`JWT issuer method ${jwtIssuer.method} not yet supported`));
|
|
556
|
+
}
|
|
557
|
+
const result = await context.agent.jwtCreateJwsCompactSignature({
|
|
558
|
+
// FIXME fix cose-key inference
|
|
559
|
+
// @ts-ignore
|
|
560
|
+
issuer: {
|
|
561
|
+
identifier: idOpts.identifier,
|
|
562
|
+
kmsKeyRef: idOpts.kmsKeyRef,
|
|
563
|
+
noIdentifierInHeader: false
|
|
564
|
+
},
|
|
565
|
+
// FIXME fix JWK key_ops
|
|
566
|
+
// @ts-ignore
|
|
567
|
+
protectedHeader: jwt.header,
|
|
568
|
+
payload: jwt.payload
|
|
569
|
+
});
|
|
570
|
+
return result.jwt;
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
__name(signCallback, "signCallback");
|
|
574
|
+
function getVerifyJwtCallback(_opts, context) {
|
|
575
|
+
return async (_jwtVerifier, jwt) => {
|
|
576
|
+
const result = await context.agent.jwtVerifyJwsSignature({
|
|
577
|
+
jws: jwt.raw
|
|
578
|
+
});
|
|
579
|
+
console.log(result.message);
|
|
580
|
+
return !result.error;
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
__name(getVerifyJwtCallback, "getVerifyJwtCallback");
|
|
584
|
+
function getSigningAlgo(type) {
|
|
585
|
+
switch (type) {
|
|
586
|
+
case "Ed25519":
|
|
587
|
+
return import_oid4vc_common.SigningAlgo.EDDSA;
|
|
588
|
+
case "Secp256k1":
|
|
589
|
+
return import_oid4vc_common.SigningAlgo.ES256K;
|
|
590
|
+
case "Secp256r1":
|
|
591
|
+
return import_oid4vc_common.SigningAlgo.ES256;
|
|
592
|
+
// @ts-ignore
|
|
593
|
+
case "RSA":
|
|
594
|
+
return import_oid4vc_common.SigningAlgo.RS256;
|
|
595
|
+
default:
|
|
596
|
+
throw Error("Key type not yet supported");
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
__name(getSigningAlgo, "getSigningAlgo");
|
|
600
|
+
|
|
601
|
+
// src/RPInstance.ts
|
|
602
|
+
var import_uuid = require("uuid");
|
|
603
|
+
var import_ssi_sdk_ext3 = require("@sphereon/ssi-sdk-ext.identifier-resolution");
|
|
604
|
+
var RPInstance = class {
|
|
605
|
+
static {
|
|
606
|
+
__name(this, "RPInstance");
|
|
607
|
+
}
|
|
608
|
+
_rp;
|
|
609
|
+
_pexOptions;
|
|
610
|
+
_rpOptions;
|
|
611
|
+
constructor({ rpOpts, pexOpts }) {
|
|
612
|
+
this._rpOptions = rpOpts;
|
|
613
|
+
this._pexOptions = pexOpts;
|
|
614
|
+
}
|
|
615
|
+
async get(context) {
|
|
616
|
+
if (!this._rp) {
|
|
617
|
+
const builder = await createRPBuilder({
|
|
618
|
+
rpOpts: this._rpOptions,
|
|
619
|
+
pexOpts: this._pexOptions,
|
|
620
|
+
context
|
|
621
|
+
});
|
|
622
|
+
this._rp = builder.build();
|
|
623
|
+
}
|
|
624
|
+
return this._rp;
|
|
625
|
+
}
|
|
626
|
+
get rpOptions() {
|
|
627
|
+
return this._rpOptions;
|
|
628
|
+
}
|
|
629
|
+
get pexOptions() {
|
|
630
|
+
return this._pexOptions;
|
|
631
|
+
}
|
|
632
|
+
hasDefinition() {
|
|
633
|
+
return this.definitionId !== void 0;
|
|
634
|
+
}
|
|
635
|
+
get definitionId() {
|
|
636
|
+
return this.pexOptions?.definitionId;
|
|
637
|
+
}
|
|
638
|
+
async getPresentationDefinition(context) {
|
|
639
|
+
return this.definitionId ? await context.agent.pexStoreGetDefinition({
|
|
640
|
+
definitionId: this.definitionId,
|
|
641
|
+
tenantId: this.pexOptions?.tenantId
|
|
642
|
+
}) : void 0;
|
|
643
|
+
}
|
|
644
|
+
async createAuthorizationRequestURI(createArgs, context) {
|
|
645
|
+
const { correlationId, claims, requestByReferenceURI, responseURI, responseURIType } = createArgs;
|
|
646
|
+
const nonce = createArgs.nonce ?? (0, import_uuid.v4)();
|
|
647
|
+
const state = createArgs.state ?? correlationId;
|
|
648
|
+
let jwtIssuer;
|
|
649
|
+
const idOpts = this.rpOptions.identifierOpts.idOpts;
|
|
650
|
+
const resolution = await (0, import_ssi_sdk_ext3.ensureManagedIdentifierResult)(idOpts, context);
|
|
651
|
+
if ((0, import_ssi_sdk_ext3.isManagedIdentifierDidResult)(resolution)) {
|
|
652
|
+
jwtIssuer = {
|
|
653
|
+
didUrl: resolution.kid,
|
|
654
|
+
method: "did",
|
|
655
|
+
alg: getSigningAlgo(resolution.key.type)
|
|
656
|
+
};
|
|
657
|
+
} else if ((0, import_ssi_sdk_ext3.isManagedIdentifierX5cResult)(resolution)) {
|
|
658
|
+
if (!resolution.issuer) {
|
|
659
|
+
return Promise.reject("missing issuer in idOpts");
|
|
660
|
+
}
|
|
661
|
+
jwtIssuer = {
|
|
662
|
+
issuer: resolution.issuer,
|
|
663
|
+
x5c: resolution.x5c,
|
|
664
|
+
method: "x5c",
|
|
665
|
+
alg: getSigningAlgo(resolution.key.type)
|
|
666
|
+
};
|
|
667
|
+
} else {
|
|
668
|
+
return Promise.reject(Error(`JWT issuer method ${resolution.method} not yet supported`));
|
|
669
|
+
}
|
|
670
|
+
return await this.get(context).then((rp) => rp.createAuthorizationRequestURI({
|
|
671
|
+
version: getRequestVersion(this.rpOptions),
|
|
672
|
+
correlationId,
|
|
673
|
+
nonce,
|
|
674
|
+
state,
|
|
675
|
+
claims,
|
|
676
|
+
requestByReferenceURI,
|
|
677
|
+
responseURI,
|
|
678
|
+
responseURIType,
|
|
679
|
+
jwtIssuer
|
|
680
|
+
}));
|
|
681
|
+
}
|
|
682
|
+
async createAuthorizationRequest(createArgs, context) {
|
|
683
|
+
const { correlationId, claims, requestByReferenceURI, responseURI, responseURIType } = createArgs;
|
|
684
|
+
const nonce = createArgs.nonce ?? (0, import_uuid.v4)();
|
|
685
|
+
const state = createArgs.state ?? correlationId;
|
|
686
|
+
const idOpts = this.rpOptions.identifierOpts.idOpts;
|
|
687
|
+
const resolution = await (0, import_ssi_sdk_ext3.ensureManagedIdentifierResult)(idOpts, context);
|
|
688
|
+
let jwtIssuer;
|
|
689
|
+
if ((0, import_ssi_sdk_ext3.isManagedIdentifierX5cResult)(resolution) && resolution.issuer) {
|
|
690
|
+
jwtIssuer = {
|
|
691
|
+
method: resolution.method,
|
|
692
|
+
alg: getSigningAlgo(resolution.key.type),
|
|
693
|
+
x5c: resolution.x5c,
|
|
694
|
+
issuer: resolution.issuer
|
|
695
|
+
};
|
|
696
|
+
} else if ((0, import_ssi_sdk_ext3.isManagedIdentifierDidResult)(resolution)) {
|
|
697
|
+
jwtIssuer = {
|
|
698
|
+
method: resolution.method,
|
|
699
|
+
alg: getSigningAlgo(resolution.key.type),
|
|
700
|
+
didUrl: resolution.did
|
|
701
|
+
};
|
|
702
|
+
} else {
|
|
703
|
+
return Promise.reject(Error("Only did & x5c supported at present"));
|
|
704
|
+
}
|
|
705
|
+
return await this.get(context).then((rp) => rp.createAuthorizationRequest({
|
|
706
|
+
version: getRequestVersion(this.rpOptions),
|
|
707
|
+
correlationId,
|
|
708
|
+
nonce,
|
|
709
|
+
state,
|
|
710
|
+
claims,
|
|
711
|
+
requestByReferenceURI,
|
|
712
|
+
responseURIType,
|
|
713
|
+
responseURI,
|
|
714
|
+
jwtIssuer
|
|
715
|
+
}));
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
// src/agent/SIOPv2RP.ts
|
|
720
|
+
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.core");
|
|
721
|
+
var SIOPv2RP = class _SIOPv2RP {
|
|
722
|
+
static {
|
|
723
|
+
__name(this, "SIOPv2RP");
|
|
724
|
+
}
|
|
725
|
+
opts;
|
|
726
|
+
static _DEFAULT_OPTS_KEY = "_default";
|
|
727
|
+
instances = /* @__PURE__ */ new Map();
|
|
728
|
+
schema = schema.IDidAuthSiopOpAuthenticator;
|
|
729
|
+
methods = {
|
|
730
|
+
siopCreateAuthRequestURI: this.createAuthorizationRequestURI.bind(this),
|
|
731
|
+
siopCreateAuthRequestPayloads: this.createAuthorizationRequestPayloads.bind(this),
|
|
732
|
+
siopGetAuthRequestState: this.siopGetRequestState.bind(this),
|
|
733
|
+
siopGetAuthResponseState: this.siopGetResponseState.bind(this),
|
|
734
|
+
siopUpdateAuthRequestState: this.siopUpdateRequestState.bind(this),
|
|
735
|
+
siopDeleteAuthState: this.siopDeleteState.bind(this),
|
|
736
|
+
siopVerifyAuthResponse: this.siopVerifyAuthResponse.bind(this),
|
|
737
|
+
siopImportDefinitions: this.siopImportDefinitions.bind(this),
|
|
738
|
+
siopGetRedirectURI: this.siopGetRedirectURI.bind(this)
|
|
739
|
+
};
|
|
740
|
+
constructor(opts) {
|
|
741
|
+
this.opts = opts;
|
|
742
|
+
}
|
|
743
|
+
setDefaultOpts(rpDefaultOpts, context) {
|
|
744
|
+
this.opts.defaultOpts = rpDefaultOpts;
|
|
745
|
+
if (!this.opts.defaultOpts.identifierOpts.resolveOpts?.resolver || typeof this.opts.defaultOpts.identifierOpts.resolveOpts.resolver.resolve !== "function") {
|
|
746
|
+
this.opts.defaultOpts.identifierOpts.resolveOpts = {
|
|
747
|
+
...this.opts.defaultOpts.identifierOpts.resolveOpts,
|
|
748
|
+
resolver: (0, import_ssi_sdk_ext4.getAgentResolver)(context, {
|
|
749
|
+
uniresolverResolution: true,
|
|
750
|
+
resolverResolution: true,
|
|
751
|
+
localResolution: true
|
|
752
|
+
})
|
|
753
|
+
};
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
async createAuthorizationRequestURI(createArgs, context) {
|
|
757
|
+
return await this.getRPInstance({
|
|
758
|
+
definitionId: createArgs.definitionId,
|
|
759
|
+
responseRedirectURI: createArgs.responseRedirectURI
|
|
760
|
+
}, context).then((rp) => rp.createAuthorizationRequestURI(createArgs, context)).then((URI) => URI.encodedUri);
|
|
761
|
+
}
|
|
762
|
+
async createAuthorizationRequestPayloads(createArgs, context) {
|
|
763
|
+
return await this.getRPInstance({
|
|
764
|
+
definitionId: createArgs.definitionId
|
|
765
|
+
}, context).then((rp) => rp.createAuthorizationRequest(createArgs, context)).then(async (request) => {
|
|
766
|
+
const authRequest = {
|
|
767
|
+
authorizationRequest: request.payload,
|
|
768
|
+
requestObject: await request.requestObjectJwt(),
|
|
769
|
+
requestObjectDecoded: await request.requestObject?.getPayload()
|
|
770
|
+
};
|
|
771
|
+
return authRequest;
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
async siopGetRequestState(args, context) {
|
|
775
|
+
return await this.getRPInstance({
|
|
776
|
+
definitionId: args.definitionId
|
|
777
|
+
}, context).then((rp) => rp.get(context).then((rp2) => rp2.sessionManager.getRequestStateByCorrelationId(args.correlationId, args.errorOnNotFound)));
|
|
778
|
+
}
|
|
779
|
+
async siopGetResponseState(args, context) {
|
|
780
|
+
const rpInstance = await this.getRPInstance({
|
|
781
|
+
definitionId: args.definitionId
|
|
782
|
+
}, context);
|
|
783
|
+
const authorizationResponseState = await rpInstance.get(context).then((rp) => rp.sessionManager.getResponseStateByCorrelationId(args.correlationId, args.errorOnNotFound));
|
|
784
|
+
if (authorizationResponseState === void 0) {
|
|
785
|
+
return void 0;
|
|
786
|
+
}
|
|
787
|
+
const responseState = authorizationResponseState;
|
|
788
|
+
if (responseState.status === import_did_auth_siop2.AuthorizationResponseStateStatus.VERIFIED && args.includeVerifiedData && args.includeVerifiedData !== VerifiedDataMode.NONE) {
|
|
789
|
+
let hasher;
|
|
790
|
+
if (import_ssi_types2.CredentialMapper.isSdJwtEncoded(responseState.response.payload.vp_token) && (!rpInstance.rpOptions.credentialOpts?.hasher || typeof rpInstance.rpOptions.credentialOpts?.hasher !== "function")) {
|
|
791
|
+
hasher = import_ssi_sdk2.shaHasher;
|
|
792
|
+
}
|
|
793
|
+
const presentationDecoded = import_ssi_types2.CredentialMapper.decodeVerifiablePresentation(
|
|
794
|
+
responseState.response.payload.vp_token,
|
|
795
|
+
//todo: later we want to conditionally pass in options for mdl-mdoc here
|
|
796
|
+
hasher
|
|
797
|
+
);
|
|
798
|
+
switch (args.includeVerifiedData) {
|
|
799
|
+
case VerifiedDataMode.VERIFIED_PRESENTATION:
|
|
800
|
+
responseState.response.payload.verifiedData = this.presentationOrClaimsFrom(presentationDecoded);
|
|
801
|
+
break;
|
|
802
|
+
case VerifiedDataMode.CREDENTIAL_SUBJECT_FLATTENED:
|
|
803
|
+
const allClaims = {};
|
|
804
|
+
for (const credential of this.presentationOrClaimsFrom(presentationDecoded).verifiableCredential || []) {
|
|
805
|
+
const vc = credential;
|
|
806
|
+
const schemaValidationResult = await context.agent.cvVerifySchema({
|
|
807
|
+
credential,
|
|
808
|
+
hasher,
|
|
809
|
+
validationPolicy: rpInstance.rpOptions.verificationPolicies?.schemaValidation
|
|
810
|
+
});
|
|
811
|
+
if (!schemaValidationResult.result) {
|
|
812
|
+
responseState.status = import_did_auth_siop2.AuthorizationResponseStateStatus.ERROR;
|
|
813
|
+
responseState.error = new Error(schemaValidationResult.error);
|
|
814
|
+
return responseState;
|
|
815
|
+
}
|
|
816
|
+
const credentialSubject = vc.credentialSubject;
|
|
817
|
+
if (!("id" in allClaims)) {
|
|
818
|
+
allClaims["id"] = credentialSubject.id;
|
|
819
|
+
}
|
|
820
|
+
Object.entries(credentialSubject).forEach(([key, value]) => {
|
|
821
|
+
if (!(key in allClaims)) {
|
|
822
|
+
allClaims[key] = value;
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
responseState.verifiedData = allClaims;
|
|
827
|
+
break;
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
return responseState;
|
|
831
|
+
}
|
|
832
|
+
presentationOrClaimsFrom = /* @__PURE__ */ __name((presentationDecoded) => import_ssi_types2.CredentialMapper.isSdJwtDecodedCredential(presentationDecoded) ? presentationDecoded.decodedPayload : import_ssi_types2.CredentialMapper.toUniformPresentation(presentationDecoded), "presentationOrClaimsFrom");
|
|
833
|
+
async siopUpdateRequestState(args, context) {
|
|
834
|
+
if (args.state !== "sent") {
|
|
835
|
+
throw Error(`Only 'sent' status is supported for this method at this point`);
|
|
836
|
+
}
|
|
837
|
+
return await this.getRPInstance({
|
|
838
|
+
definitionId: args.definitionId
|
|
839
|
+
}, context).then((rp) => rp.get(context).then(async (rp2) => {
|
|
840
|
+
await rp2.signalAuthRequestRetrieved({
|
|
841
|
+
correlationId: args.correlationId,
|
|
842
|
+
error: args.error ? new Error(args.error) : void 0
|
|
843
|
+
});
|
|
844
|
+
return await rp2.sessionManager.getRequestStateByCorrelationId(args.correlationId, true);
|
|
845
|
+
}));
|
|
846
|
+
}
|
|
847
|
+
async siopDeleteState(args, context) {
|
|
848
|
+
return await this.getRPInstance({
|
|
849
|
+
definitionId: args.definitionId
|
|
850
|
+
}, context).then((rp) => rp.get(context).then((rp2) => rp2.sessionManager.deleteStateForCorrelationId(args.correlationId))).then(() => true);
|
|
851
|
+
}
|
|
852
|
+
async siopVerifyAuthResponse(args, context) {
|
|
853
|
+
if (!args.authorizationResponse) {
|
|
854
|
+
throw Error("No SIOPv2 Authorization Response received");
|
|
855
|
+
}
|
|
856
|
+
const authResponse = typeof args.authorizationResponse === "string" ? (0, import_did_auth_siop2.decodeUriAsJson)(args.authorizationResponse) : args.authorizationResponse;
|
|
857
|
+
return await this.getRPInstance({
|
|
858
|
+
definitionId: args.definitionId
|
|
859
|
+
}, context).then((rp) => rp.get(context).then((rp2) => rp2.verifyAuthorizationResponse(authResponse, {
|
|
860
|
+
correlationId: args.correlationId,
|
|
861
|
+
...args.presentationDefinitions && !args.dcqlQuery ? {
|
|
862
|
+
presentationDefinitions: args.presentationDefinitions
|
|
863
|
+
} : {},
|
|
864
|
+
...args.dcqlQuery ? {
|
|
865
|
+
dcqlQuery: args.dcqlQuery
|
|
866
|
+
} : {},
|
|
867
|
+
audience: args.audience
|
|
868
|
+
})));
|
|
869
|
+
}
|
|
870
|
+
async siopImportDefinitions(args, context) {
|
|
871
|
+
const { definitions, tenantId, version, versionControlMode } = args;
|
|
872
|
+
await Promise.all(definitions.map(async (definitionPair) => {
|
|
873
|
+
const definitionPayload = definitionPair.definitionPayload;
|
|
874
|
+
await context.agent.pexValidateDefinition({
|
|
875
|
+
definition: definitionPayload
|
|
876
|
+
});
|
|
877
|
+
console.log(`persisting definition ${definitionPayload.id} / ${definitionPayload.name} with versionControlMode ${versionControlMode}`);
|
|
878
|
+
return context.agent.pdmPersistDefinition({
|
|
879
|
+
definitionItem: {
|
|
880
|
+
tenantId,
|
|
881
|
+
version,
|
|
882
|
+
definitionPayload,
|
|
883
|
+
dcqlPayload: definitionPair.dcqlPayload
|
|
884
|
+
},
|
|
885
|
+
opts: {
|
|
886
|
+
versionControlMode
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
}));
|
|
890
|
+
}
|
|
891
|
+
async siopGetRedirectURI(args, context) {
|
|
892
|
+
const instanceId = args.definitionId ?? _SIOPv2RP._DEFAULT_OPTS_KEY;
|
|
893
|
+
if (this.instances.has(instanceId)) {
|
|
894
|
+
const rpInstance = this.instances.get(instanceId);
|
|
895
|
+
if (rpInstance !== void 0) {
|
|
896
|
+
const rp = await rpInstance.get(context);
|
|
897
|
+
return rp.getResponseRedirectUri({
|
|
898
|
+
correlation_id: args.correlationId,
|
|
899
|
+
correlationId: args.correlationId,
|
|
900
|
+
...args.state && {
|
|
901
|
+
state: args.state
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
return void 0;
|
|
907
|
+
}
|
|
908
|
+
async getRPInstance({ definitionId, responseRedirectURI }, context) {
|
|
909
|
+
const instanceId = definitionId ?? _SIOPv2RP._DEFAULT_OPTS_KEY;
|
|
910
|
+
if (!this.instances.has(instanceId)) {
|
|
911
|
+
const instanceOpts = this.getInstanceOpts(definitionId);
|
|
912
|
+
const rpOpts = await this.getRPOptions(context, {
|
|
913
|
+
definitionId,
|
|
914
|
+
responseRedirectURI
|
|
915
|
+
});
|
|
916
|
+
if (!rpOpts.identifierOpts.resolveOpts?.resolver || typeof rpOpts.identifierOpts.resolveOpts.resolver.resolve !== "function") {
|
|
917
|
+
if (!rpOpts.identifierOpts?.resolveOpts) {
|
|
918
|
+
rpOpts.identifierOpts = {
|
|
919
|
+
...rpOpts.identifierOpts
|
|
920
|
+
};
|
|
921
|
+
rpOpts.identifierOpts.resolveOpts = {
|
|
922
|
+
...rpOpts.identifierOpts.resolveOpts
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
console.log("Using agent DID resolver for RP instance with definition id " + definitionId);
|
|
926
|
+
rpOpts.identifierOpts.resolveOpts.resolver = (0, import_ssi_sdk_ext4.getAgentResolver)(context, {
|
|
927
|
+
uniresolverResolution: true,
|
|
928
|
+
localResolution: true,
|
|
929
|
+
resolverResolution: true
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
this.instances.set(instanceId, new RPInstance({
|
|
933
|
+
rpOpts,
|
|
934
|
+
pexOpts: instanceOpts
|
|
935
|
+
}));
|
|
936
|
+
}
|
|
937
|
+
const rpInstance = this.instances.get(instanceId);
|
|
938
|
+
if (responseRedirectURI) {
|
|
939
|
+
rpInstance.rpOptions.responseRedirectUri = responseRedirectURI;
|
|
940
|
+
}
|
|
941
|
+
return rpInstance;
|
|
942
|
+
}
|
|
943
|
+
async getRPOptions(context, opts) {
|
|
944
|
+
const { definitionId, responseRedirectURI } = opts;
|
|
945
|
+
const options = this.getInstanceOpts(definitionId)?.rpOpts ?? this.opts.defaultOpts;
|
|
946
|
+
if (!options) {
|
|
947
|
+
throw Error(`Could not get specific nor default options for definition ${definitionId}`);
|
|
948
|
+
}
|
|
949
|
+
if (this.opts.defaultOpts) {
|
|
950
|
+
if (!options.identifierOpts) {
|
|
951
|
+
options.identifierOpts = this.opts.defaultOpts?.identifierOpts;
|
|
952
|
+
} else {
|
|
953
|
+
if (!options.identifierOpts.idOpts) {
|
|
954
|
+
options.identifierOpts.idOpts = this.opts.defaultOpts.identifierOpts.idOpts;
|
|
955
|
+
}
|
|
956
|
+
if (!options.identifierOpts.supportedDIDMethods) {
|
|
957
|
+
options.identifierOpts.supportedDIDMethods = this.opts.defaultOpts.identifierOpts.supportedDIDMethods;
|
|
958
|
+
}
|
|
959
|
+
if (!options.supportedVersions) {
|
|
960
|
+
options.supportedVersions = this.opts.defaultOpts.supportedVersions;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
if (!options.identifierOpts.resolveOpts || typeof options.identifierOpts.resolveOpts.resolver?.resolve !== "function") {
|
|
964
|
+
options.identifierOpts.resolveOpts = {
|
|
965
|
+
...this.opts.defaultOpts.identifierOpts.resolveOpts,
|
|
966
|
+
resolver: this.opts.defaultOpts.identifierOpts?.resolveOpts?.resolver ?? (0, import_ssi_sdk_ext4.getAgentResolver)(context, {
|
|
967
|
+
localResolution: true,
|
|
968
|
+
resolverResolution: true,
|
|
969
|
+
uniresolverResolution: true
|
|
970
|
+
})
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
if (responseRedirectURI !== void 0 && responseRedirectURI !== options.responseRedirectUri) {
|
|
975
|
+
options.responseRedirectUri = responseRedirectURI;
|
|
976
|
+
}
|
|
977
|
+
return options;
|
|
978
|
+
}
|
|
979
|
+
getInstanceOpts(definitionId) {
|
|
980
|
+
if (!this.opts.instanceOpts) return void 0;
|
|
981
|
+
const instanceOpt = definitionId ? this.opts.instanceOpts.find((i) => i.definitionId === definitionId) : void 0;
|
|
982
|
+
return instanceOpt ?? this.getDefaultOptions(definitionId);
|
|
983
|
+
}
|
|
984
|
+
getDefaultOptions(definitionId) {
|
|
985
|
+
if (!this.opts.instanceOpts) return void 0;
|
|
986
|
+
const defaultOptions = this.opts.instanceOpts.find((i) => i.definitionId === "default");
|
|
987
|
+
if (defaultOptions) {
|
|
988
|
+
const clonedOptions = {
|
|
989
|
+
...defaultOptions
|
|
990
|
+
};
|
|
991
|
+
if (definitionId !== void 0) {
|
|
992
|
+
clonedOptions.definitionId = definitionId;
|
|
993
|
+
}
|
|
994
|
+
return clonedOptions;
|
|
995
|
+
}
|
|
996
|
+
return void 0;
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
|
|
1000
|
+
// src/types/ISIOPv2RP.ts
|
|
1001
|
+
var VerifiedDataMode = /* @__PURE__ */ function(VerifiedDataMode2) {
|
|
1002
|
+
VerifiedDataMode2["NONE"] = "none";
|
|
1003
|
+
VerifiedDataMode2["VERIFIED_PRESENTATION"] = "vp";
|
|
1004
|
+
VerifiedDataMode2["CREDENTIAL_SUBJECT_FLATTENED"] = "cs-flat";
|
|
1005
|
+
return VerifiedDataMode2;
|
|
1006
|
+
}({});
|
|
1007
|
+
|
|
1008
|
+
// src/index.ts
|
|
1009
|
+
var schema = require_plugin_schema();
|
|
1010
|
+
//# sourceMappingURL=index.cjs.map
|