@sphereon/ssi-sdk.vc-status-list-issuer 0.34.1-feature.SSISDK.17.bitstring.sl.8 → 0.34.1-feature.disable.test.8

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.d.cts CHANGED
@@ -1,62 +1,10 @@
1
1
  import { StatusListManagementOptions } from '@sphereon/ssi-sdk.vc-status-list-issuer-drivers';
2
2
  import { OrPromise } from '@sphereon/ssi-types';
3
3
  import { DataSource } from 'typeorm';
4
- import { DataSources } from '@sphereon/ssi-sdk.agent-config';
5
- import { IStatusListPlugin } from '@sphereon/ssi-sdk.vc-status-list';
6
- import { IAgentPlugin } from '@veramo/core';
7
4
 
8
5
  type StatusListInstance = StatusListManagementOptions & {
9
6
  dataSource?: OrPromise<DataSource>;
10
7
  issuer?: string;
11
8
  };
12
9
 
13
- declare class StatusListPlugin implements IAgentPlugin {
14
- private readonly instances;
15
- private readonly defaultStatusListId?;
16
- private readonly allDataSources;
17
- private initialized;
18
- readonly methods: IStatusListPlugin;
19
- constructor(opts: {
20
- instances?: Array<StatusListInstance>;
21
- defaultStatusListId?: string;
22
- allDataSources?: DataSources;
23
- autoCreateInstances?: boolean;
24
- });
25
- private init;
26
- private slImportStatusLists;
27
- private createStatusListInstance;
28
- private getDriverForStatusListOption;
29
- private slGetStatusList;
30
- private selectDatasource;
31
- private slCreateStatusList;
32
- /**
33
- * Selects bitsPerStatus from the used status list type when applicable
34
- * @param sl
35
- * @private
36
- */
37
- private selectBitsPerStatus;
38
- /**
39
- * Adds status information to a credential by either:
40
- * 1. Using existing status ID from the credential if present
41
- * 2. Using provided status list options
42
- * 3. Falling back to the default status list ID
43
- *
44
- * @param args Contains credential and status options
45
- * @param context Required agent context
46
- * @returns Credential with added status information
47
- */
48
- private slAddStatusToCredential;
49
- /**
50
- * Adds status information to an SD-JWT credential by either:
51
- * 1. Using existing status URI from the credential if present
52
- * 2. Using provided status list options
53
- * 3. Falling back to the default status list ID
54
- *
55
- * @param args Contains SD-JWT credential and status options
56
- * @param context Required agent context
57
- * @returns SD-JWT credential with added status information
58
- */
59
- private slAddStatusToSdJwtCredential;
60
- }
61
-
62
- export { type StatusListInstance, StatusListPlugin };
10
+ export type { StatusListInstance };
package/dist/index.d.ts CHANGED
@@ -1,62 +1,10 @@
1
1
  import { StatusListManagementOptions } from '@sphereon/ssi-sdk.vc-status-list-issuer-drivers';
2
2
  import { OrPromise } from '@sphereon/ssi-types';
3
3
  import { DataSource } from 'typeorm';
4
- import { DataSources } from '@sphereon/ssi-sdk.agent-config';
5
- import { IStatusListPlugin } from '@sphereon/ssi-sdk.vc-status-list';
6
- import { IAgentPlugin } from '@veramo/core';
7
4
 
8
5
  type StatusListInstance = StatusListManagementOptions & {
9
6
  dataSource?: OrPromise<DataSource>;
10
7
  issuer?: string;
11
8
  };
12
9
 
13
- declare class StatusListPlugin implements IAgentPlugin {
14
- private readonly instances;
15
- private readonly defaultStatusListId?;
16
- private readonly allDataSources;
17
- private initialized;
18
- readonly methods: IStatusListPlugin;
19
- constructor(opts: {
20
- instances?: Array<StatusListInstance>;
21
- defaultStatusListId?: string;
22
- allDataSources?: DataSources;
23
- autoCreateInstances?: boolean;
24
- });
25
- private init;
26
- private slImportStatusLists;
27
- private createStatusListInstance;
28
- private getDriverForStatusListOption;
29
- private slGetStatusList;
30
- private selectDatasource;
31
- private slCreateStatusList;
32
- /**
33
- * Selects bitsPerStatus from the used status list type when applicable
34
- * @param sl
35
- * @private
36
- */
37
- private selectBitsPerStatus;
38
- /**
39
- * Adds status information to a credential by either:
40
- * 1. Using existing status ID from the credential if present
41
- * 2. Using provided status list options
42
- * 3. Falling back to the default status list ID
43
- *
44
- * @param args Contains credential and status options
45
- * @param context Required agent context
46
- * @returns Credential with added status information
47
- */
48
- private slAddStatusToCredential;
49
- /**
50
- * Adds status information to an SD-JWT credential by either:
51
- * 1. Using existing status URI from the credential if present
52
- * 2. Using provided status list options
53
- * 3. Falling back to the default status list ID
54
- *
55
- * @param args Contains SD-JWT credential and status options
56
- * @param context Required agent context
57
- * @returns SD-JWT credential with added status information
58
- */
59
- private slAddStatusToSdJwtCredential;
60
- }
61
-
62
- export { type StatusListInstance, StatusListPlugin };
10
+ export type { StatusListInstance };
package/dist/index.js CHANGED
@@ -1,523 +1 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- // src/agent/StatusListPlugin.ts
5
- import { DataSources } from "@sphereon/ssi-sdk.agent-config";
6
- import { createNewStatusList } from "@sphereon/ssi-sdk.vc-status-list";
7
- import { getDriver as getDriver2 } from "@sphereon/ssi-sdk.vc-status-list-issuer-drivers";
8
- import { Loggers as Loggers2 } from "@sphereon/ssi-types";
9
-
10
- // src/functions.ts
11
- import { getDriver } from "@sphereon/ssi-sdk.vc-status-list-issuer-drivers";
12
- import debug from "debug";
13
- import { Loggers } from "@sphereon/ssi-types";
14
- var logger = Loggers.DEFAULT.get("sphereon:ssi-sdk:vc-status-list-issuer");
15
- async function getDriverAndStatusList(statusListId, opts) {
16
- const slDriver = opts?.driver ?? await getDriver({
17
- id: statusListId,
18
- dataSource: opts?.dataSource
19
- });
20
- const statusList = await slDriver.statusListStore.getStatusList({
21
- id: statusListId
22
- });
23
- return {
24
- slDriver,
25
- statusList
26
- };
27
- }
28
- __name(getDriverAndStatusList, "getDriverAndStatusList");
29
- function getCredentialStatusListOpts(credential, opts) {
30
- const statusListOpts = [
31
- ...opts?.statusLists ?? []
32
- ];
33
- if (statusListOpts.length === 0 && credential.credentialStatus) {
34
- if (Array.isArray(credential.credentialStatus)) {
35
- for (const credStatus of credential.credentialStatus) {
36
- if (credStatus.statusListCredential) {
37
- statusListOpts.push({
38
- statusListId: credStatus.statusListCredential,
39
- statusListIndex: credStatus.statusListIndex,
40
- statusListCorrelationId: credStatus.statusListCorrelationId,
41
- statusEntryCorrelationId: credStatus.statusEntryCorrelationId
42
- });
43
- }
44
- }
45
- } else if (credential.credentialStatus.statusListCredential) {
46
- statusListOpts.push({
47
- statusListId: credential.credentialStatus.statusListCredential,
48
- statusListIndex: credential.credentialStatus.statusListIndex,
49
- statusListCorrelationId: credential.credentialStatus.statusListCorrelationId,
50
- statusEntryCorrelationId: credential.credentialStatus.statusEntryCorrelationId
51
- });
52
- }
53
- }
54
- return statusListOpts;
55
- }
56
- __name(getCredentialStatusListOpts, "getCredentialStatusListOpts");
57
- function getSdJwtStatusListOpts(credential, opts) {
58
- const statusListOpts = [
59
- ...opts?.statusLists ?? []
60
- ];
61
- if (statusListOpts.length === 0 && credential.status?.status_list) {
62
- statusListOpts.push({
63
- statusListId: credential.status.status_list.uri,
64
- statusListIndex: credential.status.status_list.idx
65
- });
66
- }
67
- return statusListOpts;
68
- }
69
- __name(getSdJwtStatusListOpts, "getSdJwtStatusListOpts");
70
- async function processStatusListEntry(params) {
71
- let existingEntry = void 0;
72
- if (params.credentialId) {
73
- existingEntry = await params.slDriver.getStatusListEntryByCredentialId({
74
- statusListId: params.statusList.id,
75
- credentialId: params.credentialId,
76
- errorOnNotFound: false
77
- });
78
- if (existingEntry) {
79
- debug(`Existing statusList entry and index ${existingEntry.statusListIndex} found for ${params.debugCredentialInfo}. Will reuse the index`);
80
- }
81
- }
82
- let statusListIndex = existingEntry?.statusListIndex ?? params.currentIndex;
83
- if (params.useIndexCondition(statusListIndex)) {
84
- existingEntry = await params.slDriver.getStatusListEntryByIndex({
85
- statusListId: params.statusList.id,
86
- statusListIndex,
87
- errorOnNotFound: false
88
- });
89
- logger.debug(`${!existingEntry && "no"} existing statusList entry and index ${existingEntry?.statusListIndex} for ${params.debugCredentialInfo}. Will reuse the index`);
90
- if (existingEntry && params.credentialId && existingEntry.credentialId && existingEntry.credentialId !== params.credentialId && params.checkCredentialIdMismatch) {
91
- params.checkCredentialIdMismatch(existingEntry, params.credentialId, statusListIndex);
92
- }
93
- } else {
94
- debug(`Will generate a new random statusListIndex since the credential did not contain a statusListIndex for ${params.debugCredentialInfo}...`);
95
- statusListIndex = await params.slDriver.getRandomNewStatusListIndex({
96
- correlationId: params.statusList.correlationId
97
- });
98
- debug(`Random statusListIndex ${statusListIndex} assigned for ${params.debugCredentialInfo}`);
99
- }
100
- const updateArgs = {
101
- statusListId: params.statusListId,
102
- statusListIndex,
103
- correlationId: params.statusEntryCorrelationId,
104
- value: params.opts?.value ?? "0"
105
- };
106
- if (params.credentialId) {
107
- updateArgs.credentialId = params.credentialId;
108
- }
109
- const updateResult = await params.slDriver.updateStatusListEntry(updateArgs);
110
- return {
111
- statusListIndex,
112
- updateResult
113
- };
114
- }
115
- __name(processStatusListEntry, "processStatusListEntry");
116
- var createStatusList = /* @__PURE__ */ __name(async (args, dataSource, context) => {
117
- let statusList;
118
- try {
119
- statusList = await context.agent.slGetStatusList({
120
- ...args.id && {
121
- id: args.id
122
- },
123
- ...args.correlationId && {
124
- correlationId: args.correlationId
125
- },
126
- ...args.dbName && {
127
- dbName: args.dbName
128
- },
129
- dataSource: await dataSource
130
- });
131
- } catch (e) {
132
- const id = args.id;
133
- const correlationId = args.correlationId;
134
- if (!id || !correlationId) {
135
- return Promise.reject(Error(`No correlation id and id provided for status list`));
136
- }
137
- statusList = await context.agent.slCreateStatusList(args);
138
- }
139
- return statusList;
140
- }, "createStatusList");
141
- var handleCredentialStatus = /* @__PURE__ */ __name(async (credential, credentialStatusOpts) => {
142
- logger.debug(`Starting status update for credential ${credential.id ?? "without ID"}`);
143
- const statusListOpts = getCredentialStatusListOpts(credential, credentialStatusOpts);
144
- if (statusListOpts.length === 0) {
145
- logger.debug("No status list options found, skipping update");
146
- return;
147
- }
148
- const credentialId = credential.id ?? credentialStatusOpts?.credentialId;
149
- for (const statusListOpt of statusListOpts) {
150
- const statusListId = statusListOpt.statusListId;
151
- if (!statusListId) {
152
- logger.debug("Skipping status list option without ID");
153
- continue;
154
- }
155
- logger.debug(`Processing status list ${statusListId} for credential ${credentialId ?? "without ID"}`);
156
- const { slDriver, statusList } = await getDriverAndStatusList(statusListId, credentialStatusOpts);
157
- const currentIndex = statusListOpt.statusListIndex ?? 0;
158
- const { updateResult } = await processStatusListEntry({
159
- statusListId,
160
- statusList,
161
- credentialId,
162
- currentIndex,
163
- statusEntryCorrelationId: statusListOpt.statusEntryCorrelationId,
164
- opts: credentialStatusOpts,
165
- slDriver,
166
- debugCredentialInfo: `credential with id ${credentialId} and statusListId ${statusListId}`,
167
- useIndexCondition: /* @__PURE__ */ __name((index) => Boolean(index), "useIndexCondition"),
168
- checkCredentialIdMismatch: /* @__PURE__ */ __name((existingEntry, credentialId2, index) => {
169
- throw Error(`A credential with new id (${credentialId2}) is issued, but its id does not match a registered statusListEntry id ${existingEntry.credentialId} for index ${index}`);
170
- }, "checkCredentialIdMismatch")
171
- });
172
- if (!credential.credentialStatus || Array.isArray(credential.credentialStatus)) {
173
- credential.credentialStatus = {
174
- id: `${statusListId}`,
175
- statusListCredential: statusListId,
176
- ...updateResult.credentialStatus
177
- };
178
- }
179
- }
180
- logger.debug(`Completed status updates for credential ${credentialId ?? "without ID"}`);
181
- }, "handleCredentialStatus");
182
- var handleSdJwtCredentialStatus = /* @__PURE__ */ __name(async (credential, credentialStatusOpts) => {
183
- logger.debug("Starting status update for SD\u2011JWT credential");
184
- const statusListOpts = getSdJwtStatusListOpts(credential, credentialStatusOpts);
185
- if (statusListOpts.length === 0) {
186
- throw Error("No status list options available from credential or options");
187
- }
188
- for (const statusListOpt of statusListOpts) {
189
- const statusListId = statusListOpt.statusListId;
190
- if (!statusListId) {
191
- logger.debug("Skipping status list option without ID");
192
- continue;
193
- }
194
- logger.info(`Processing status list ${statusListId}`);
195
- const { slDriver, statusList } = await getDriverAndStatusList(statusListId, credentialStatusOpts);
196
- const currentIndex = statusListOpt.statusListIndex ?? 0;
197
- const { statusListIndex } = await processStatusListEntry({
198
- statusListId,
199
- statusList,
200
- currentIndex,
201
- statusEntryCorrelationId: statusListOpt.statusEntryCorrelationId,
202
- opts: credentialStatusOpts,
203
- slDriver,
204
- debugCredentialInfo: `credential with statusListId ${statusListId}`,
205
- useIndexCondition: /* @__PURE__ */ __name((index) => index > 0, "useIndexCondition")
206
- });
207
- if (!credential.status) {
208
- credential.status = {
209
- status_list: {
210
- uri: statusListId,
211
- idx: statusListIndex
212
- }
213
- };
214
- } else if (!credential.status.status_list) {
215
- credential.status.status_list = {
216
- uri: statusListId,
217
- idx: statusListIndex
218
- };
219
- } else {
220
- credential.status.status_list = {
221
- uri: credential.status.status_list.uri || statusListId,
222
- idx: statusListIndex
223
- };
224
- }
225
- }
226
- logger.debug("Completed SD\u2011JWT credential status update");
227
- }, "handleSdJwtCredentialStatus");
228
-
229
- // src/agent/StatusListPlugin.ts
230
- var logger2 = Loggers2.DEFAULT.get("sphereon:ssi-sdk:vc-status-list");
231
- var StatusListPlugin = class {
232
- static {
233
- __name(this, "StatusListPlugin");
234
- }
235
- instances = new Array();
236
- defaultStatusListId;
237
- allDataSources;
238
- initialized = false;
239
- methods = {
240
- slAddStatusToCredential: this.slAddStatusToCredential.bind(this),
241
- slAddStatusToSdJwtCredential: this.slAddStatusToSdJwtCredential.bind(this),
242
- slCreateStatusList: this.slCreateStatusList.bind(this),
243
- slGetStatusList: this.slGetStatusList.bind(this),
244
- slImportStatusLists: this.slImportStatusLists.bind(this)
245
- };
246
- constructor(opts) {
247
- this.instances = opts.instances ?? [];
248
- const instanceId = opts.defaultStatusListId ?? opts.instances?.[0]?.id;
249
- if (!instanceId) {
250
- logger2.warning(`Could not deduce the default instance id from the status lists, so no default status list will be used. Please configure the default instance id in the agent configuration.`);
251
- }
252
- this.defaultStatusListId = instanceId;
253
- this.allDataSources = opts.allDataSources ?? DataSources.singleInstance();
254
- }
255
- async init() {
256
- if (!this.initialized) {
257
- for (const dbName of this.allDataSources.getDbNames()) {
258
- const driver = await getDriver2({
259
- dbName,
260
- dataSources: this.allDataSources
261
- });
262
- const statusLists = await driver.getStatusLists();
263
- const instances = await Promise.all(statusLists.map((statusList) => {
264
- const dataSource = this.allDataSources.getDbConnection(dbName);
265
- return this.createStatusListInstance(statusList, dataSource, driver);
266
- }));
267
- this.instances.push(...instances);
268
- }
269
- this.initialized = true;
270
- }
271
- }
272
- async slImportStatusLists(imports, context) {
273
- await this.init();
274
- for (const instanceImport of imports) {
275
- const dataSource = this.allDataSources.getDbConnection(instanceImport.dbName ?? "default");
276
- await createStatusList(instanceImport, dataSource, context);
277
- }
278
- return true;
279
- }
280
- createStatusListInstance(statusList, dataSource, driver) {
281
- return {
282
- id: statusList.id,
283
- correlationId: statusList.correlationId,
284
- issuer: typeof statusList.issuer === "string" ? statusList.issuer : statusList.issuer.id,
285
- dataSource,
286
- driverOptions: driver.getOptions(),
287
- driverType: driver.getType()
288
- };
289
- }
290
- async getDriverForStatusListOption(effectiveStatusListId, correlationId) {
291
- let instance;
292
- if (correlationId && correlationId.trim() !== "") {
293
- instance = this.instances.find((inst) => inst.correlationId === correlationId);
294
- } else {
295
- instance = this.instances.find((inst) => inst.id === effectiveStatusListId);
296
- }
297
- if (!instance) {
298
- throw Error(`Status list with identifier ${correlationId ?? effectiveStatusListId} is not managed by the status list plugin`);
299
- }
300
- if (!instance.dataSource && !instance.driverOptions?.dbName) {
301
- throw Error(`Either a datasource or dbName needs to be supplied`);
302
- }
303
- const dataSource = instance.dataSource ? await instance.dataSource : await this.allDataSources.getDbConnection(instance.driverOptions.dbName);
304
- const driver = correlationId && correlationId.trim() !== "" ? await getDriver2({
305
- dataSource,
306
- correlationId
307
- }) : await getDriver2({
308
- dataSource,
309
- id: effectiveStatusListId
310
- });
311
- return driver;
312
- }
313
- async slGetStatusList(args) {
314
- await this.init();
315
- const sl = this.instances.find((instance) => instance.id === args.id || instance.correlationId === args.correlationId);
316
- const dataSource = await this.selectDatasource({
317
- dbName: args.dbName,
318
- dataSource: args.dataSource ?? sl?.dataSource,
319
- instance: sl
320
- });
321
- const driver = await getDriver2({
322
- id: args.id ?? sl?.id,
323
- correlationId: args.correlationId ?? sl?.correlationId,
324
- dataSource
325
- });
326
- return await driver.getStatusList();
327
- }
328
- async selectDatasource(args) {
329
- const dbName = args.dbName ?? this.allDataSources.getDbNames()[0];
330
- if (args?.dataSource) {
331
- return args.dataSource;
332
- } else if (args.instance?.dataSource) {
333
- return args.instance.dataSource;
334
- } else if (args.dbName) {
335
- return await this.allDataSources.getDbConnection(dbName);
336
- } else {
337
- return await this.allDataSources.getDbConnection(dbName);
338
- }
339
- }
340
- async slCreateStatusList(args, context) {
341
- await this.init();
342
- const sl = await createNewStatusList(args, context);
343
- const dataSource = await this.selectDatasource({
344
- dbName: args.dbName,
345
- dataSource: args.dataSource
346
- });
347
- const driver = await getDriver2({
348
- id: sl.id,
349
- correlationId: sl.correlationId,
350
- dataSource
351
- });
352
- let statusListDetails = void 0;
353
- try {
354
- statusListDetails = await this.slGetStatusList(args);
355
- } catch (e) {
356
- }
357
- if (statusListDetails && this.instances.find((instance) => instance.id === args.id || instance.correlationId === args.correlationId)) {
358
- return Promise.reject(Error(`Status list with id ${args.id} or correlation id ${args.correlationId} already exists`));
359
- } else {
360
- statusListDetails = await driver.createStatusList({
361
- statusListCredential: sl.statusListCredential,
362
- correlationId: sl.correlationId,
363
- bitsPerStatus: this.selectBitsPerStatus(sl)
364
- });
365
- this.instances.push(this.createStatusListInstance(statusListDetails, dataSource, driver));
366
- }
367
- return statusListDetails;
368
- }
369
- /**
370
- * Selects bitsPerStatus from the used status list type when applicable
371
- * @param sl
372
- * @private
373
- */
374
- selectBitsPerStatus(sl) {
375
- if (sl.bitstringStatusList) {
376
- return sl.bitstringStatusList.bitsPerStatus;
377
- }
378
- if (sl.oauthStatusList) {
379
- return sl.oauthStatusList.bitsPerStatus;
380
- }
381
- return 1;
382
- }
383
- /**
384
- * Adds status information to a credential by either:
385
- * 1. Using existing status ID from the credential if present
386
- * 2. Using provided status list options
387
- * 3. Falling back to the default status list ID
388
- *
389
- * @param args Contains credential and status options
390
- * @param context Required agent context
391
- * @returns Credential with added status information
392
- */
393
- async slAddStatusToCredential(args, context) {
394
- const { credential, ...rest } = args;
395
- logger2.debug(`Adding status to credential ${credential.id ?? "without ID"}`);
396
- await this.init();
397
- const credentialStatus = credential.credentialStatus;
398
- if (credentialStatus && (!rest.statusLists || rest.statusLists.length == 0)) {
399
- let existingStatusId;
400
- if (Array.isArray(credentialStatus)) {
401
- for (const stat of credentialStatus) {
402
- if (stat.id && stat.id.trim() !== "") {
403
- existingStatusId = stat.id.split("#")[0];
404
- break;
405
- }
406
- }
407
- } else if (credentialStatus.id && credentialStatus.id.trim() !== "") {
408
- existingStatusId = credentialStatus.id.split("#")[0];
409
- }
410
- if (existingStatusId) {
411
- logger2.debug(`Using existing status ID ${existingStatusId} for credential ${credential.id ?? "without ID"}`);
412
- const instance = this.instances.find((inst) => inst.id === existingStatusId);
413
- if (!instance) {
414
- throw Error(`Status list with id ${existingStatusId} is not managed by the status list plugin`);
415
- }
416
- if (!instance.dataSource && !instance.driverOptions?.dbName) {
417
- throw Error(`Either a datasource or dbName needs to be supplied`);
418
- }
419
- const credentialId2 = credential.id ?? rest.credentialId;
420
- const dataSource = instance.dataSource ? await instance.dataSource : await this.allDataSources.getDbConnection(instance.driverOptions.dbName);
421
- const driver = await getDriver2({
422
- dataSource,
423
- id: existingStatusId
424
- });
425
- await handleCredentialStatus(credential, {
426
- ...rest,
427
- credentialId: credentialId2,
428
- statusLists: [
429
- {
430
- statusListId: existingStatusId
431
- }
432
- ],
433
- driver
434
- });
435
- return credential;
436
- }
437
- }
438
- const statusListOpts = rest.statusLists?.length ? rest.statusLists : [];
439
- logger2.debug(`Adding new status using ${statusListOpts.length} status list option(s)`);
440
- const credentialId = credential.id ?? rest.credentialId;
441
- for (const opt of statusListOpts) {
442
- const effectiveStatusListId = opt.statusListId ?? this.defaultStatusListId;
443
- if (!effectiveStatusListId) {
444
- return Promise.reject(Error(`No status list ID provided and no default status list ID configured. Please provide a status list ID or configure a default status list ID in the agent configuration.`));
445
- }
446
- const driver = await this.getDriverForStatusListOption(effectiveStatusListId, opt.statusListCorrelationId);
447
- await handleCredentialStatus(credential, {
448
- ...rest,
449
- credentialId,
450
- statusLists: [
451
- {
452
- ...opt,
453
- statusListId: effectiveStatusListId
454
- }
455
- ],
456
- driver
457
- });
458
- }
459
- logger2.debug(`Successfully added status information to credential ${credential.id ?? "without ID"}`);
460
- return credential;
461
- }
462
- /**
463
- * Adds status information to an SD-JWT credential by either:
464
- * 1. Using existing status URI from the credential if present
465
- * 2. Using provided status list options
466
- * 3. Falling back to the default status list ID
467
- *
468
- * @param args Contains SD-JWT credential and status options
469
- * @param context Required agent context
470
- * @returns SD-JWT credential with added status information
471
- */
472
- async slAddStatusToSdJwtCredential(args, context) {
473
- const { credential, ...rest } = args;
474
- logger2.debug(`Adding status to SD-JWT credential`);
475
- await this.init();
476
- const credentialStatus = credential.status;
477
- if (credentialStatus && (!rest.statusLists || rest.statusLists.length == 0)) {
478
- let existingStatusUri;
479
- if (credentialStatus.status_list && credentialStatus.status_list.uri && credentialStatus.status_list.uri.trim() !== "") {
480
- existingStatusUri = credentialStatus.status_list.uri;
481
- }
482
- if (existingStatusUri) {
483
- logger2.debug(`Using existing status URI ${existingStatusUri} for SD-JWT credential`);
484
- const driver2 = await this.getDriverForStatusListOption(existingStatusUri);
485
- await handleSdJwtCredentialStatus(credential, {
486
- ...rest,
487
- statusLists: [
488
- {
489
- ...rest.statusLists,
490
- statusListId: existingStatusUri
491
- }
492
- ],
493
- driver: driver2
494
- });
495
- return credential;
496
- }
497
- }
498
- const statusListOpts = rest.statusLists?.length ? rest.statusLists : [];
499
- logger2.info(`Adding new status using status list options with ID ${statusListOpts[0].statusListId ?? this.defaultStatusListId}`);
500
- const firstOpt = statusListOpts[0];
501
- const effectiveStatusListId = firstOpt.statusListId ?? this.defaultStatusListId;
502
- if (!effectiveStatusListId) {
503
- return Promise.reject(Error(`No status list ID provided and no default status list ID configured. Please provide a status list ID or configure a default status list ID in the agent configuration.`));
504
- }
505
- const driver = await this.getDriverForStatusListOption(effectiveStatusListId, firstOpt.statusListCorrelationId);
506
- await handleSdJwtCredentialStatus(credential, {
507
- ...rest,
508
- statusLists: [
509
- {
510
- ...firstOpt,
511
- statusListId: effectiveStatusListId
512
- }
513
- ],
514
- driver
515
- });
516
- logger2.debug(`Successfully added status information to SD-JWT credential`);
517
- return credential;
518
- }
519
- };
520
- export {
521
- StatusListPlugin
522
- };
523
1
  //# sourceMappingURL=index.js.map