@sphereon/ssi-sdk.oid4vci-issuer 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.
Files changed (38) hide show
  1. package/dist/index.cjs +959 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +210 -0
  4. package/dist/index.d.ts +206 -6
  5. package/dist/index.js +927 -26
  6. package/dist/index.js.map +1 -1
  7. package/package.json +38 -28
  8. package/src/functions.ts +2 -2
  9. package/src/types/IOID4VCIIssuer.ts +1 -1
  10. package/dist/IssuerInstance.d.ts +0 -26
  11. package/dist/IssuerInstance.d.ts.map +0 -1
  12. package/dist/IssuerInstance.js +0 -52
  13. package/dist/IssuerInstance.js.map +0 -1
  14. package/dist/agent/OID4VCIIssuer.d.ts +0 -25
  15. package/dist/agent/OID4VCIIssuer.d.ts.map +0 -1
  16. package/dist/agent/OID4VCIIssuer.js +0 -210
  17. package/dist/agent/OID4VCIIssuer.js.map +0 -1
  18. package/dist/functions.d.ts +0 -74
  19. package/dist/functions.d.ts.map +0 -1
  20. package/dist/functions.js +0 -328
  21. package/dist/functions.js.map +0 -1
  22. package/dist/index.d.ts.map +0 -1
  23. package/dist/state-manager/TypeOrmStateManager.d.ts +0 -1
  24. package/dist/state-manager/TypeOrmStateManager.d.ts.map +0 -1
  25. package/dist/state-manager/TypeOrmStateManager.js +0 -2
  26. package/dist/state-manager/TypeOrmStateManager.js.map +0 -1
  27. package/dist/state-manager/oid4vcState/IAbstractMachineStateStore.d.ts +0 -39
  28. package/dist/state-manager/oid4vcState/IAbstractMachineStateStore.d.ts.map +0 -1
  29. package/dist/state-manager/oid4vcState/IAbstractMachineStateStore.js +0 -3
  30. package/dist/state-manager/oid4vcState/IAbstractMachineStateStore.js.map +0 -1
  31. package/dist/state-manager/oid4vcState/MachineStateStore.d.ts +0 -1
  32. package/dist/state-manager/oid4vcState/MachineStateStore.d.ts.map +0 -1
  33. package/dist/state-manager/oid4vcState/MachineStateStore.js +0 -137
  34. package/dist/state-manager/oid4vcState/MachineStateStore.js.map +0 -1
  35. package/dist/types/IOID4VCIIssuer.d.ts +0 -90
  36. package/dist/types/IOID4VCIIssuer.d.ts.map +0 -1
  37. package/dist/types/IOID4VCIIssuer.js +0 -3
  38. package/dist/types/IOID4VCIIssuer.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,28 +1,929 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __commonJS = (cb, mod) => function __require() {
5
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
6
+ };
7
+
8
+ // plugin.schema.json
9
+ var require_plugin_schema = __commonJS({
10
+ "plugin.schema.json"(exports, module) {
11
+ module.exports = {
12
+ IDidAuthSiopOpAuthenticator: {
13
+ components: {
14
+ schemas: {
15
+ IGetSiopSessionArgs: {
16
+ type: "object",
17
+ properties: {
18
+ sessionId: {
19
+ type: "string"
20
+ },
21
+ additionalProperties: false
22
+ },
23
+ required: ["sessionId"],
24
+ description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.getSessionForSiop } "
25
+ },
26
+ IRegisterSiopSessionArgs: {
27
+ type: "object",
28
+ properties: {
29
+ identifier: {
30
+ type: "object",
31
+ properties: {
32
+ did: {
33
+ type: "string"
34
+ },
35
+ alias: {
36
+ type: "string"
37
+ },
38
+ provider: {
39
+ type: "string"
40
+ },
41
+ controllerKeyId: {
42
+ type: "string"
43
+ },
44
+ keys: {
45
+ type: "array",
46
+ items: {
47
+ type: "object",
48
+ properties: {
49
+ additionalProperties: true
50
+ }
51
+ }
52
+ },
53
+ services: {
54
+ type: "array",
55
+ items: {
56
+ type: "object",
57
+ properties: {
58
+ additionalProperties: true
59
+ }
60
+ }
61
+ }
62
+ },
63
+ additionalProperties: false,
64
+ required: ["did", "provider", "keys", "services"]
65
+ },
66
+ sessionId: {
67
+ type: "string"
68
+ },
69
+ expiresIn: {
70
+ type: "number"
71
+ },
72
+ additionalProperties: false
73
+ },
74
+ required: ["identifier"],
75
+ description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.registerSessionForSiop } "
76
+ },
77
+ IRemoveSiopSessionArgs: {
78
+ type: "object",
79
+ properties: {
80
+ sessionId: {
81
+ type: "string"
82
+ },
83
+ additionalProperties: false
84
+ },
85
+ required: ["sessionId"],
86
+ description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.removeSessionForSiop } "
87
+ },
88
+ IAuthenticateWithSiopArgs: {
89
+ type: "object",
90
+ properties: {
91
+ sessionId: {
92
+ type: "string"
93
+ },
94
+ stateId: {
95
+ type: "string"
96
+ },
97
+ redirectUrl: {
98
+ type: "string"
99
+ },
100
+ additionalProperties: false
101
+ },
102
+ required: ["sessionId", "stateId", "redirectUrl"],
103
+ description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.authenticateWithSiop } "
104
+ },
105
+ IResponse: {
106
+ type: "object",
107
+ properties: {
108
+ status: {
109
+ type: "number"
110
+ },
111
+ additionalProperties: true
112
+ },
113
+ required: ["status"],
114
+ description: "Result of {@link DidAuthSiopOpAuthenticator.authenticateWithSiop & DidAuthSiopOpAuthenticator.sendSiopAuthenticationResponse } "
115
+ },
116
+ IGetSiopAuthenticationRequestFromRpArgs: {
117
+ type: "object",
118
+ properties: {
119
+ sessionId: {
120
+ type: "string"
121
+ },
122
+ stateId: {
123
+ type: "string"
124
+ },
125
+ redirectUrl: {
126
+ type: "string"
127
+ },
128
+ additionalProperties: false
129
+ },
130
+ required: ["sessionId", "stateId", "redirectUrl"],
131
+ description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.getSiopAuthenticationRequestFromRP } "
132
+ },
133
+ ParsedAuthenticationRequestURI: {
134
+ type: "object",
135
+ properties: {
136
+ jwt: {
137
+ type: "string"
138
+ },
139
+ requestPayload: {
140
+ type: "object",
141
+ properties: {
142
+ additionalProperties: true
143
+ }
144
+ },
145
+ registration: {
146
+ type: "object",
147
+ properties: {
148
+ additionalProperties: true
149
+ }
150
+ },
151
+ additionalProperties: false
152
+ },
153
+ required: ["jwt", "requestPayload", "registration"],
154
+ description: "Result of {@link DidAuthSiopOpAuthenticator.getSiopAuthenticationRequestFromRP } "
155
+ },
156
+ IGetSiopAuthenticationRequestDetailsArgs: {
157
+ type: "object",
158
+ properties: {
159
+ sessionId: {
160
+ type: "string"
161
+ },
162
+ verifiedAuthenticationRequest: {
163
+ type: "object",
164
+ properties: {
165
+ additionalProperties: true
166
+ }
167
+ },
168
+ credentialFilter: {
169
+ type: "object",
170
+ properties: {
171
+ additionalProperties: true
172
+ }
173
+ },
174
+ additionalProperties: false
175
+ },
176
+ required: ["sessionId", "verifiedAuthenticationRequest"],
177
+ description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.getSiopAuthenticationRequestDetails } "
178
+ },
179
+ IAuthRequestDetails: {
180
+ type: "object",
181
+ properties: {
182
+ id: {
183
+ type: "string"
184
+ },
185
+ alsoKnownAs: {
186
+ type: "array",
187
+ items: {
188
+ type: "string"
189
+ }
190
+ },
191
+ vpResponseOpts: {
192
+ type: "object",
193
+ properties: {
194
+ additionalProperties: true
195
+ }
196
+ },
197
+ additionalProperties: false
198
+ },
199
+ required: ["id", "vpResponseOpts"],
200
+ description: "Result of {@link DidAuthSiopOpAuthenticator.getSiopAuthenticationRequestDetails } "
201
+ },
202
+ IVerifySiopAuthenticationRequestUriArgs: {
203
+ type: "object",
204
+ properties: {
205
+ sessionId: {
206
+ type: "string"
207
+ },
208
+ ParsedAuthenticationRequestURI: {
209
+ type: "object",
210
+ properties: {
211
+ additionalProperties: true
212
+ }
213
+ },
214
+ additionalProperties: false
215
+ },
216
+ required: ["sessionId", "ParsedAuthenticationRequestURI"],
217
+ description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.verifySiopAuthenticationRequestURI } "
218
+ },
219
+ VerifiedAuthorizationRequest: {
220
+ type: "object",
221
+ properties: {
222
+ payload: {
223
+ type: "object",
224
+ properties: {
225
+ additionalProperties: true
226
+ }
227
+ },
228
+ presentationDefinitions: {
229
+ type: "object",
230
+ properties: {
231
+ additionalProperties: true
232
+ }
233
+ },
234
+ verifyOpts: {
235
+ type: "object",
236
+ properties: {
237
+ additionalProperties: true
238
+ }
239
+ },
240
+ additionalProperties: false
241
+ },
242
+ required: ["payload", "verifyOpts"],
243
+ description: "Result of {@link DidAuthSiopOpAuthenticator.verifySiopAuthenticationRequestURI } "
244
+ },
245
+ ISendSiopAuthenticationResponseArgs: {
246
+ type: "object",
247
+ properties: {
248
+ sessionId: {
249
+ type: "string"
250
+ },
251
+ verifiedAuthenticationRequest: {
252
+ type: "object",
253
+ properties: {
254
+ additionalProperties: true
255
+ }
256
+ },
257
+ verifiablePresentationResponse: {
258
+ type: "object",
259
+ properties: {
260
+ additionalProperties: true
261
+ }
262
+ },
263
+ additionalProperties: false
264
+ },
265
+ required: ["sessionId", "verifiedAuthenticationRequest"],
266
+ description: "Arguments needed for {@link DidAuthSiopOpAuthenticator.sendSiopAuthenticationResponse } "
267
+ }
268
+ },
269
+ methods: {
270
+ getSessionForSiop: {
271
+ description: "Get SIOP session",
272
+ arguments: {
273
+ $ref: "#/components/schemas/IGetSiopSessionArgs"
274
+ },
275
+ returnType: "object"
276
+ },
277
+ registerSessionForSiop: {
278
+ description: "Register SIOP session",
279
+ arguments: {
280
+ $ref: "#/components/schemas/IRegisterSiopSessionArgs"
281
+ },
282
+ returnType: "object"
283
+ },
284
+ removeSessionForSiop: {
285
+ description: "Remove SIOP session",
286
+ arguments: {
287
+ $ref: "#/components/schemas/IRemoveSiopSessionArgs"
288
+ },
289
+ returnType: "boolean"
290
+ },
291
+ authenticateWithSiop: {
292
+ description: "Authenticate using DID Auth SIOP",
293
+ arguments: {
294
+ $ref: "#/components/schemas/IAuthenticateWithSiopArgs"
295
+ },
296
+ returnType: {
297
+ $ref: "#/components/schemas/Response"
298
+ }
299
+ },
300
+ getSiopAuthenticationRequestFromRP: {
301
+ description: "Get authentication request from RP",
302
+ arguments: {
303
+ $ref: "#/components/schemas/IGetSiopAuthenticationRequestFromRpArgs"
304
+ },
305
+ returnType: {
306
+ $ref: "#/components/schemas/ParsedAuthenticationRequestURI"
307
+ }
308
+ },
309
+ getSiopAuthenticationRequestDetails: {
310
+ description: "Get authentication request details",
311
+ arguments: {
312
+ $ref: "#/components/schemas/IGetSiopAuthenticationRequestDetailsArgs"
313
+ },
314
+ returnType: {
315
+ $ref: "#/components/schemas/IAuthRequestDetails"
316
+ }
317
+ },
318
+ verifySiopAuthenticationRequestURI: {
319
+ description: "Verify authentication request URI",
320
+ arguments: {
321
+ $ref: "#/components/schemas/IVerifySiopAuthenticationRequestUriArgs"
322
+ },
323
+ returnType: {
324
+ $ref: "#/components/schemas/VerifiedAuthorizationRequest"
325
+ }
326
+ },
327
+ sendSiopAuthenticationResponse: {
328
+ description: "Send authentication response",
329
+ arguments: {
330
+ $ref: "#/components/schemas/ISendSiopAuthenticationResponseArgs"
331
+ },
332
+ returnType: {
333
+ $ref: "#/components/schemas/IRequiredContext"
334
+ }
335
+ }
336
+ }
337
+ }
338
+ }
339
+ };
340
+ }
341
+ });
342
+
343
+ // src/agent/OID4VCIIssuer.ts
344
+ import { WellKnownEndpoints } from "@sphereon/oid4vci-common";
345
+ import { assertValidAccessTokenRequest, createAccessTokenResponse } from "@sphereon/oid4vci-issuer";
346
+ import { retrieveWellknown } from "@sphereon/oid4vci-client";
347
+ import { getAgentResolver as getAgentResolver2 } from "@sphereon/ssi-sdk-ext.did-utils";
348
+
349
+ // src/functions.ts
350
+ import { VcIssuerBuilder } from "@sphereon/oid4vci-issuer";
351
+ import { getAgentResolver } from "@sphereon/ssi-sdk-ext.did-utils";
352
+ import { legacyKeyRefsToIdentifierOpts } from "@sphereon/ssi-sdk-ext.identifier-resolution";
353
+ import { contextHasPlugin } from "@sphereon/ssi-sdk.agent-config";
354
+ import { CredentialMapper } from "@sphereon/ssi-types";
355
+ import { bytesToBase64 } from "@veramo/utils";
356
+ import { createJWT, decodeJWT, verifyJWT } from "did-jwt";
357
+ import { jwtDecode } from "jwt-decode";
358
+ import fetch from "cross-fetch";
359
+ import { AuthorizationResponseStateStatus } from "@sphereon/did-auth-siop";
360
+ function getJwtVerifyCallback({ verifyOpts }, _context) {
361
+ return async (args) => {
362
+ const resolver = getAgentResolver(_context, {
363
+ resolverResolution: true,
364
+ uniresolverResolution: true,
365
+ localResolution: true
366
+ });
367
+ verifyOpts = {
368
+ ...verifyOpts,
369
+ resolver: verifyOpts?.resolver
370
+ };
371
+ if (!verifyOpts?.resolver || typeof verifyOpts?.resolver?.resolve !== "function") {
372
+ verifyOpts.resolver = resolver;
373
+ }
374
+ const result = await _context.agent.jwtVerifyJwsSignature({
375
+ jws: args.jwt
376
+ });
377
+ if (!result.error) {
378
+ const identifier = result.jws.signatures[0].identifier;
379
+ if (!identifier) {
380
+ return Promise.reject(Error("the jws did not contain a signature with an identifier"));
381
+ }
382
+ const jwkInfo = identifier.jwks[0];
383
+ if (!jwkInfo) {
384
+ return Promise.reject(Error(`the identifier of type ${identifier.method} is missing jwks (ExternalJwkInfo)`));
385
+ }
386
+ const { alg: alg2 } = jwkInfo.jwk;
387
+ const header = jwtDecode(args.jwt, {
388
+ header: true
389
+ });
390
+ const payload = jwtDecode(args.jwt, {
391
+ header: false
392
+ });
393
+ const kid2 = args.kid ?? header.kid;
394
+ const jwk = jwkInfo.jwk;
395
+ return {
396
+ alg: alg2,
397
+ ...identifier,
398
+ jwt: {
399
+ header,
400
+ payload
401
+ },
402
+ ...kid2 && {
403
+ kid: kid2
404
+ },
405
+ ...jwk && {
406
+ jwk
407
+ }
408
+ };
409
+ }
410
+ const decodedJwt = await decodeJWT(args.jwt);
411
+ const kid = args.kid ?? decodedJwt.header.kid;
412
+ if (!kid || !kid.startsWith("did:")) {
413
+ return {
414
+ alg: decodedJwt.header.alg,
415
+ jwt: decodedJwt
416
+ };
417
+ }
418
+ const did = kid.split("#")[0];
419
+ const didResult = await verifyJWT(args.jwt, verifyOpts);
420
+ if (!didResult.verified) {
421
+ console.log(`JWT invalid: ${args.jwt}`);
422
+ throw Error("JWT did not verify successfully");
423
+ }
424
+ const didResolution = await resolver.resolve(did);
425
+ if (!didResolution || !didResolution.didDocument) {
426
+ throw Error(`Could not resolve did: ${did}, metadata: ${didResolution?.didResolutionMetadata}`);
427
+ }
428
+ const alg = decodedJwt.header.alg;
429
+ return {
430
+ alg,
431
+ kid,
432
+ did,
433
+ didDocument: didResolution.didDocument,
434
+ jwt: decodedJwt
435
+ };
436
+ };
437
+ }
438
+ __name(getJwtVerifyCallback, "getJwtVerifyCallback");
439
+ async function getAccessTokenKeyRef(opts, context) {
440
+ let identifier = legacyKeyRefsToIdentifierOpts(opts);
441
+ return await context.agent.identifierManagedGet(identifier);
442
+ }
443
+ __name(getAccessTokenKeyRef, "getAccessTokenKeyRef");
444
+ async function getAccessTokenSignerCallback(opts, context) {
445
+ const signer = /* @__PURE__ */ __name(async (data) => {
446
+ let dataString, encoding;
447
+ const resolution = await legacyKeyRefsToIdentifierOpts(opts);
448
+ const keyRef = resolution.kmsKeyRef;
449
+ if (!keyRef) {
450
+ throw Error("Cannot sign access tokens without a key ref");
451
+ }
452
+ if (typeof data === "string") {
453
+ dataString = data;
454
+ encoding = void 0;
455
+ } else {
456
+ dataString = bytesToBase64(data);
457
+ encoding = "base64";
458
+ }
459
+ return context.agent.keyManagerSign({
460
+ keyRef,
461
+ data: dataString,
462
+ encoding
463
+ });
464
+ }, "signer");
465
+ async function accessTokenSignerCallback(jwt, kid) {
466
+ const issuer = opts.idOpts?.issuer ?? (typeof opts.idOpts?.identifier === "string" ? opts.idOpts.identifier : opts.didOpts?.idOpts?.identifier?.toString() ?? opts?.iss);
467
+ if (!issuer) {
468
+ throw Error("No issuer configured for access tokens");
469
+ }
470
+ let kidHeader = jwt?.header?.kid ?? kid;
471
+ if (!kidHeader) {
472
+ if (opts.idOpts?.method === "did" || opts.idOpts?.method === "kid" || typeof opts.didOpts?.idOpts.identifier === "string" && opts.didOpts?.idOpts?.identifier?.startsWith("did:")) {
473
+ kidHeader = opts.idOpts?.kid ?? opts.didOpts?.idOpts?.kid ?? opts?.didOpts?.identifierOpts?.kid;
474
+ }
475
+ }
476
+ return await createJWT(jwt.payload, {
477
+ signer,
478
+ issuer
479
+ }, {
480
+ ...jwt.header,
481
+ ...kidHeader && {
482
+ kid: kidHeader
483
+ },
484
+ typ: "JWT"
485
+ });
486
+ }
487
+ __name(accessTokenSignerCallback, "accessTokenSignerCallback");
488
+ return accessTokenSignerCallback;
489
+ }
490
+ __name(getAccessTokenSignerCallback, "getAccessTokenSignerCallback");
491
+ async function getCredentialSignerCallback(idOpts, context) {
492
+ async function issueVCCallback(args) {
493
+ const { jwtVerifyResult, format, statusLists } = args;
494
+ const credential = args.credential;
495
+ let proofFormat;
496
+ const resolution = await context.agent.identifierManagedGet(idOpts);
497
+ proofFormat = format?.includes("ld") ? "lds" : "jwt";
498
+ const issuer = resolution.issuer ?? resolution.kmsKeyRef;
499
+ if (CredentialMapper.isW3cCredential(credential)) {
500
+ if (!credential.issuer) {
501
+ credential.issuer = {
502
+ id: issuer
503
+ };
504
+ } else if (typeof credential.issuer === "object" && !credential.issuer.id) {
505
+ credential.issuer.id = issuer;
506
+ }
507
+ const subjectIsArray = Array.isArray(credential.credentialSubject);
508
+ let credentialSubjects = Array.isArray(credential.credentialSubject) ? credential.credentialSubject : [
509
+ credential.credentialSubject
510
+ ];
511
+ credentialSubjects = credentialSubjects.map((subject) => {
512
+ if (!subject.id) {
513
+ subject.id = jwtVerifyResult.did;
514
+ }
515
+ return subject;
516
+ });
517
+ credential.credentialSubject = subjectIsArray ? credentialSubjects : credentialSubjects[0];
518
+ if (contextHasPlugin(context, "slAddStatusToCredential")) {
519
+ const credentialStatusVC = await context.agent.slAddStatusToCredential({
520
+ credential,
521
+ statusLists
522
+ });
523
+ if (credential.credentialStatus && !credential.credentialStatus.statusListCredential) {
524
+ credential.credentialStatus = credentialStatusVC.credentialStatus;
525
+ }
526
+ }
527
+ const result = await context.agent.createVerifiableCredential({
528
+ credential,
529
+ proofFormat,
530
+ removeOriginalFields: false,
531
+ fetchRemoteContexts: true,
532
+ domain: typeof credential.issuer === "object" ? credential.issuer.id : credential.issuer,
533
+ ...resolution.kid && {
534
+ header: {
535
+ kid: resolution.kid
536
+ }
537
+ }
538
+ });
539
+ return proofFormat === "jwt" && "jwt" in result.proof ? result.proof.jwt : result;
540
+ } else if (CredentialMapper.isSdJwtDecodedCredentialPayload(credential)) {
541
+ const sdJwtPayload = credential;
542
+ if (sdJwtPayload.iss === void 0) {
543
+ sdJwtPayload.iss = issuer;
544
+ }
545
+ if (sdJwtPayload.iat === void 0) {
546
+ sdJwtPayload.iat = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
547
+ }
548
+ let disclosureFrame;
549
+ if ("disclosureFrame" in credential) {
550
+ disclosureFrame = credential["disclosureFrame"];
551
+ delete credential["disclosureFrame"];
552
+ } else {
553
+ disclosureFrame = {
554
+ _sd: credential["_sd"]
555
+ };
556
+ }
557
+ if (contextHasPlugin(context, "slAddStatusToSdJwtCredential")) {
558
+ if (sdJwtPayload.status && sdJwtPayload.status.status_list || statusLists && statusLists.length > 0) {
559
+ const sdJwtPayloadWithStatus = await context.agent.slAddStatusToSdJwtCredential({
560
+ credential: sdJwtPayload,
561
+ statusLists
562
+ });
563
+ if (sdJwtPayload.status?.status_list?.idx) {
564
+ if (!sdJwtPayloadWithStatus.status || !sdJwtPayloadWithStatus.status.status_list) {
565
+ return Promise.reject(Error("slAddStatusToSdJwtCredential did not return a status_list"));
566
+ }
567
+ if (statusLists && statusLists.length > 0) {
568
+ const statusList = statusLists[0];
569
+ statusList.statusListId = sdJwtPayloadWithStatus.status.status_list.uri;
570
+ statusList.statusListIndex = sdJwtPayloadWithStatus.status.status_list.idx;
571
+ }
572
+ sdJwtPayload.status.status_list.idx = sdJwtPayloadWithStatus.status.status_list.idx;
573
+ }
574
+ }
575
+ }
576
+ const result = await context.agent.createSdJwtVc({
577
+ credentialPayload: sdJwtPayload,
578
+ disclosureFrame,
579
+ resolution
580
+ });
581
+ return result.credential;
582
+ }
583
+ return Promise.reject("VC issuance failed, an incorrect or unsupported credential was supplied");
584
+ }
585
+ __name(issueVCCallback, "issueVCCallback");
586
+ return issueVCCallback;
587
+ }
588
+ __name(getCredentialSignerCallback, "getCredentialSignerCallback");
589
+ async function createVciIssuerBuilder(args, context) {
590
+ const { issuerOpts, issuerMetadata, authorizationServerMetadata } = args;
591
+ const builder = new VcIssuerBuilder();
592
+ const resolver = args.resolver ?? args?.issuerOpts?.didOpts?.resolveOpts?.resolver ?? args.issuerOpts?.didOpts?.resolveOpts?.jwtVerifyOpts?.resolver ?? getAgentResolver(context);
593
+ if (!resolver) {
594
+ throw Error("A Resolver is necessary to verify DID JWTs");
595
+ }
596
+ const idOpts = legacyKeyRefsToIdentifierOpts({
597
+ didOpts: issuerOpts.didOpts,
598
+ idOpts: issuerOpts.idOpts
599
+ });
600
+ const jwtVerifyOpts = {
601
+ ...issuerOpts?.didOpts?.resolveOpts?.jwtVerifyOpts,
602
+ ...args?.issuerOpts?.resolveOpts?.jwtVerifyOpts,
603
+ resolver,
604
+ audience: issuerMetadata.credential_issuer
605
+ };
606
+ builder.withIssuerMetadata(issuerMetadata);
607
+ builder.withAuthorizationMetadata(authorizationServerMetadata);
608
+ builder.withCredentialSignerCallback(await getCredentialSignerCallback(idOpts, context));
609
+ if (issuerOpts.asClientOpts) {
610
+ builder.withASClientMetadata(issuerOpts.asClientOpts);
611
+ }
612
+ builder.withJWTVerifyCallback(getJwtVerifyCallback({
613
+ verifyOpts: jwtVerifyOpts
614
+ }, context));
615
+ if (args.credentialDataSupplier) {
616
+ builder.withCredentialDataSupplier(args.credentialDataSupplier);
617
+ }
618
+ builder.withInMemoryCNonceState();
619
+ builder.withInMemoryCredentialOfferState();
620
+ builder.withInMemoryCredentialOfferURIState();
621
+ return builder;
622
+ }
623
+ __name(createVciIssuerBuilder, "createVciIssuerBuilder");
624
+ async function createVciIssuer({ issuerOpts, issuerMetadata, authorizationServerMetadata, credentialDataSupplier }, context) {
625
+ return (await createVciIssuerBuilder({
626
+ issuerOpts,
627
+ issuerMetadata,
628
+ authorizationServerMetadata,
629
+ credentialDataSupplier
630
+ }, context)).build();
631
+ }
632
+ __name(createVciIssuer, "createVciIssuer");
633
+ async function createAuthRequestUriCallback(opts) {
634
+ async function authRequestUriCallback() {
635
+ const path = opts.path.replace(":definitionId", opts.presentationDefinitionId);
636
+ return fetch(path, {
637
+ method: "POST",
638
+ headers: {
639
+ "Content-Type": "application/json"
640
+ }
641
+ }).then(async (response) => {
642
+ if (response.status >= 400) {
643
+ return Promise.reject(Error(await response.text()));
644
+ } else {
645
+ const responseData = await response.json();
646
+ if (!responseData.authRequestURI) {
647
+ return Promise.reject(Error("Missing auth request uri in response body"));
648
+ }
649
+ return responseData.authRequestURI;
650
+ }
651
+ });
652
+ }
653
+ __name(authRequestUriCallback, "authRequestUriCallback");
654
+ return authRequestUriCallback;
655
+ }
656
+ __name(createAuthRequestUriCallback, "createAuthRequestUriCallback");
657
+ async function createVerifyAuthResponseCallback(opts) {
658
+ async function verifyAuthResponseCallback(correlationId) {
659
+ return fetch(opts.path, {
660
+ method: "POST",
661
+ headers: {
662
+ "Content-Type": "application/json"
663
+ },
664
+ body: JSON.stringify({
665
+ definitionId: opts.presentationDefinitionId,
666
+ correlationId
667
+ })
668
+ }).then(async (response) => {
669
+ if (response.status >= 400) {
670
+ return Promise.reject(Error(await response.text()));
671
+ } else {
672
+ const responseData = await response.json();
673
+ if (!responseData.status) {
674
+ return Promise.reject(Error("Missing status in response body"));
675
+ }
676
+ return responseData.status === AuthorizationResponseStateStatus.VERIFIED;
677
+ }
678
+ });
679
+ }
680
+ __name(verifyAuthResponseCallback, "verifyAuthResponseCallback");
681
+ return verifyAuthResponseCallback;
682
+ }
683
+ __name(createVerifyAuthResponseCallback, "createVerifyAuthResponseCallback");
684
+
685
+ // src/IssuerInstance.ts
686
+ var IssuerInstance = class {
687
+ static {
688
+ __name(this, "IssuerInstance");
689
+ }
690
+ _issuer;
691
+ _metadataOptions;
692
+ _issuerOptions;
693
+ _issuerMetadata;
694
+ _authorizationServerMetadata;
695
+ constructor({ issuerOpts, metadataOpts, issuerMetadata, authorizationServerMetadata }) {
696
+ this._issuerOptions = issuerOpts;
697
+ this._metadataOptions = metadataOpts;
698
+ this._issuerMetadata = issuerMetadata;
699
+ this._authorizationServerMetadata = authorizationServerMetadata;
700
+ }
701
+ async get(opts) {
702
+ if (!this._issuer) {
703
+ const builder = await createVciIssuerBuilder({
704
+ issuerOpts: this.issuerOptions,
705
+ issuerMetadata: this.issuerMetadata,
706
+ authorizationServerMetadata: this.authorizationServerMetadata,
707
+ credentialDataSupplier: opts?.credentialDataSupplier
708
+ }, opts.context);
709
+ this._issuer = builder.build();
710
+ }
711
+ return this._issuer;
712
+ }
713
+ get issuerOptions() {
714
+ return this._issuerOptions;
715
+ }
716
+ get metadataOptions() {
717
+ return this._metadataOptions;
718
+ }
719
+ get issuerMetadata() {
720
+ return this._issuerMetadata;
721
+ }
722
+ set issuerMetadata(value) {
723
+ this._issuerMetadata = value;
724
+ }
725
+ get authorizationServerMetadata() {
726
+ return this._authorizationServerMetadata;
727
+ }
728
+ };
729
+
730
+ // src/agent/OID4VCIIssuer.ts
731
+ var OID4VCIIssuer = class _OID4VCIIssuer {
732
+ static {
733
+ __name(this, "OID4VCIIssuer");
734
+ }
735
+ static _DEFAULT_OPTS_KEY = "_default";
736
+ instances = /* @__PURE__ */ new Map();
737
+ schema = schema.IDidAuthSiopOpAuthenticator;
738
+ methods = {
739
+ oid4vciCreateOfferURI: this.oid4vciCreateOfferURI.bind(this),
740
+ oid4vciIssueCredential: this.oid4vciIssueCredential.bind(this),
741
+ oid4vciCreateAccessTokenResponse: this.oid4vciCreateAccessTokenResponse.bind(this),
742
+ oid4vciGetInstance: this.oid4vciGetInstance.bind(this)
743
+ };
744
+ _opts;
745
+ constructor(opts) {
746
+ this._opts = opts ?? {};
747
+ }
748
+ async oid4vciCreateOfferURI(createArgs, context) {
749
+ return await this.oid4vciGetInstance(createArgs, context).then((instance) => instance.get({
750
+ context
751
+ })).then((issuer) => issuer.createCredentialOfferURI(createArgs).then((response) => {
752
+ const result = response;
753
+ if (this._opts.returnSessions === false) {
754
+ delete result.session;
755
+ }
756
+ return result;
757
+ }));
758
+ }
759
+ async oid4vciIssueCredential(issueArgs, context) {
760
+ return await this.oid4vciGetInstance(issueArgs, context).then((instance) => instance.get({
761
+ context
762
+ })).then((issuer) => issuer.issueCredential(issueArgs));
763
+ }
764
+ async oid4vciCreateAccessTokenResponse(accessTokenArgs, context) {
765
+ return await this.oid4vciGetInstance(accessTokenArgs, context).then(async (instance) => {
766
+ const issuer = await instance.get({
767
+ context
768
+ });
769
+ await assertValidAccessTokenRequest(accessTokenArgs.request, {
770
+ credentialOfferSessions: issuer.credentialOfferSessions,
771
+ expirationDuration: accessTokenArgs.expirationDuration
772
+ });
773
+ const accessTokenIssuer = instance.issuerOptions.idOpts?.issuer ?? instance.issuerOptions.didOpts?.idOpts.identifier.toString();
774
+ if (!accessTokenIssuer) {
775
+ return Promise.reject(Error(`Could not determine access token issuer`));
776
+ }
777
+ return createAccessTokenResponse(accessTokenArgs.request, {
778
+ accessTokenIssuer,
779
+ tokenExpiresIn: accessTokenArgs.expirationDuration,
780
+ cNonceExpiresIn: accessTokenArgs.expirationDuration,
781
+ cNonces: issuer.cNonces,
782
+ credentialOfferSessions: issuer.credentialOfferSessions,
783
+ accessTokenSignerCallback: await getAccessTokenSignerCallback(instance.issuerOptions, context)
784
+ });
785
+ });
786
+ }
787
+ getExternalAS(issuerMetadata) {
788
+ if ("authorization_servers" in issuerMetadata && Array.isArray(issuerMetadata.authorization_servers)) {
789
+ return issuerMetadata.authorization_servers.find((as) => as !== issuerMetadata.credential_issuer);
790
+ }
791
+ return void 0;
792
+ }
793
+ async createIssuerInstance(args, context) {
794
+ const credentialIssuer = args.credentialIssuer ?? _OID4VCIIssuer._DEFAULT_OPTS_KEY;
795
+ const metadataOpts = await this.getMetadataOpts({
796
+ ...args,
797
+ credentialIssuer
798
+ }, context);
799
+ const issuerMetadata = await this.getIssuerMetadata({
800
+ ...args,
801
+ credentialIssuer
802
+ }, context);
803
+ const externalAS = this.getExternalAS(issuerMetadata);
804
+ let asMetadataResponse = void 0;
805
+ if (externalAS) {
806
+ asMetadataResponse = await retrieveWellknown(externalAS, WellKnownEndpoints.OPENID_CONFIGURATION, {
807
+ errorOnNotFound: false
808
+ });
809
+ if (!asMetadataResponse) {
810
+ asMetadataResponse = await retrieveWellknown(externalAS, WellKnownEndpoints.OAUTH_AS, {
811
+ errorOnNotFound: true
812
+ });
813
+ }
814
+ }
815
+ const authorizationServerMetadata = asMetadataResponse?.successBody ? asMetadataResponse.successBody : await this.getAuthorizationServerMetadataFromStore({
816
+ ...args,
817
+ credentialIssuer
818
+ }, context);
819
+ const issuerOpts = await this.getIssuerOptsFromStore({
820
+ ...args,
821
+ credentialIssuer
822
+ }, context);
823
+ if (!issuerOpts.resolveOpts) {
824
+ issuerOpts.resolveOpts = {
825
+ ...issuerOpts.didOpts?.resolveOpts,
826
+ ...this._opts.resolveOpts
827
+ };
828
+ }
829
+ if (!issuerOpts.resolveOpts?.resolver) {
830
+ issuerOpts.resolveOpts.resolver = getAgentResolver2(context);
831
+ }
832
+ this.instances.set(credentialIssuer, new IssuerInstance({
833
+ issuerOpts,
834
+ metadataOpts,
835
+ issuerMetadata,
836
+ authorizationServerMetadata
837
+ }));
838
+ return this.oid4vciGetInstance(args, context);
839
+ }
840
+ async oid4vciGetInstance(args, context) {
841
+ const credentialIssuer = args.credentialIssuer ?? _OID4VCIIssuer._DEFAULT_OPTS_KEY;
842
+ if (!this.instances.has(credentialIssuer)) {
843
+ await this.createIssuerInstance(args, context);
844
+ }
845
+ return this.instances.get(credentialIssuer);
846
+ }
847
+ async getIssuerOptsFromStore(opts, context) {
848
+ const credentialIssuer = opts.credentialIssuer;
849
+ const storeId = await this.storeId(opts, context);
850
+ const namespace = await this.namespace(opts, context);
851
+ const options = await context.agent.oid4vciStoreGetIssuerOpts({
852
+ metadataType: "issuer",
853
+ correlationId: credentialIssuer,
854
+ storeId,
855
+ namespace
856
+ });
857
+ if (!options) {
858
+ throw Error(`Could not get specific nor default options for definition ${credentialIssuer}`);
859
+ }
860
+ return options;
861
+ }
862
+ async getMetadataOpts(opts, context) {
863
+ const credentialIssuer = opts.credentialIssuer;
864
+ const storeId = await this.storeId(opts, context);
865
+ const storeNamespace = await this.namespace(opts, context);
866
+ return {
867
+ credentialIssuer,
868
+ storeId,
869
+ storeNamespace
870
+ };
871
+ }
872
+ async getIssuerMetadata(opts, context) {
873
+ const metadataOpts = await this.getMetadataOpts(opts, context);
874
+ const metadata = await context.agent.oid4vciStoreGetMetadata({
875
+ metadataType: "issuer",
876
+ correlationId: metadataOpts.credentialIssuer,
877
+ namespace: metadataOpts.storeNamespace,
878
+ storeId: metadataOpts.storeId
879
+ });
880
+ if (!metadata) {
881
+ throw Error(`Issuer metadata not found for issuer ${opts.credentialIssuer}, namespace ${opts.namespace} and store ${opts.storeId}`);
882
+ }
883
+ return metadata;
884
+ }
885
+ async getAuthorizationServerMetadataFromStore(opts, context) {
886
+ const metadataOpts = await this.getMetadataOpts(opts, context);
887
+ const metadata = await context.agent.oid4vciStoreGetMetadata({
888
+ metadataType: "authorizationServer",
889
+ correlationId: metadataOpts.credentialIssuer,
890
+ namespace: metadataOpts.storeNamespace,
891
+ storeId: metadataOpts.storeId
892
+ });
893
+ if (!metadata) {
894
+ throw Error(`Authorization server ${opts.credentialIssuer} metadata not found for namespace ${metadataOpts.storeNamespace} and store ${metadataOpts.storeId}`);
895
+ }
896
+ return metadata;
897
+ }
898
+ async storeId(opts, context) {
899
+ const storeId = opts?.storeId ?? this._opts?.defaultStoreId ?? await context?.agent.oid4vciStoreDefaultStoreId();
900
+ if (!storeId) {
901
+ throw Error("Please provide a store id a default value, or provide the context for a global default store id");
902
+ }
903
+ return storeId;
904
+ }
905
+ async namespace(opts, context) {
906
+ const namespace = opts?.namespace ?? this._opts?.defaultNamespace ?? await context?.agent.oid4vciStoreDefaultNamespace();
907
+ if (!namespace) {
908
+ throw Error("Please provide a namespace a default value, or provide the context for a global default namespace");
909
+ }
910
+ return namespace;
911
+ }
912
+ };
913
+
914
+ // src/index.ts
915
+ var schema = require_plugin_schema();
916
+ export {
917
+ IssuerInstance,
918
+ OID4VCIIssuer,
919
+ createAuthRequestUriCallback,
920
+ createVciIssuer,
921
+ createVciIssuerBuilder,
922
+ createVerifyAuthResponseCallback,
923
+ getAccessTokenKeyRef,
924
+ getAccessTokenSignerCallback,
925
+ getCredentialSignerCallback,
926
+ getJwtVerifyCallback,
927
+ schema
15
928
  };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.OID4VCIIssuer = exports.schema = void 0;
18
- /**
19
- * @public
20
- */
21
- const schema = require('../plugin.schema.json');
22
- exports.schema = schema;
23
- var OID4VCIIssuer_1 = require("./agent/OID4VCIIssuer");
24
- Object.defineProperty(exports, "OID4VCIIssuer", { enumerable: true, get: function () { return OID4VCIIssuer_1.OID4VCIIssuer; } });
25
- __exportStar(require("./functions"), exports);
26
- __exportStar(require("./IssuerInstance"), exports);
27
- __exportStar(require("./types/IOID4VCIIssuer"), exports);
28
929
  //# sourceMappingURL=index.js.map