@sphereon/ssi-sdk.vc-status-list-issuer-drivers 0.34.1-feature.SSISDK.17.bitstring.sl.14 → 0.34.1-feature.SSISDK.17.bitstring.sl.16
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 +86 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +105 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.js +86 -0
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/drivers.ts +105 -0
package/dist/index.cjs
CHANGED
|
@@ -118,11 +118,23 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
118
118
|
_statusListStore;
|
|
119
119
|
options;
|
|
120
120
|
_statusListLength;
|
|
121
|
+
/**
|
|
122
|
+
* Creates a new AgentDataSourceStatusListDriver instance
|
|
123
|
+
* @param _dataSource - TypeORM DataSource for database operations
|
|
124
|
+
* @param _statusListStore - StatusListStore for data persistence
|
|
125
|
+
* @param options - Driver configuration options
|
|
126
|
+
*/
|
|
121
127
|
constructor(_dataSource, _statusListStore, options) {
|
|
122
128
|
this._dataSource = _dataSource;
|
|
123
129
|
this._statusListStore = _statusListStore;
|
|
124
130
|
this.options = options;
|
|
125
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Initializes and creates a new AgentDataSourceStatusListDriver instance
|
|
134
|
+
* @param options - Status list management configuration
|
|
135
|
+
* @param dbArgs - Database connection arguments
|
|
136
|
+
* @returns Promise resolving to initialized driver instance
|
|
137
|
+
*/
|
|
126
138
|
static async init(options, dbArgs) {
|
|
127
139
|
if (options.driverType !== import_ssi_types2.StatusListDriverType.AGENT_TYPEORM) {
|
|
128
140
|
throw Error(`TypeORM driver can only be used when the TypeORM driver type is selected in the configuration. Got: ${options.driverType}`);
|
|
@@ -145,24 +157,45 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
145
157
|
statusListStore = new import_ssi_sdk3.StatusListStore(dataSource);
|
|
146
158
|
return new _AgentDataSourceStatusListDriver(dataSource, statusListStore, options);
|
|
147
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Gets the TypeORM DataSource instance
|
|
162
|
+
* @returns DataSource instance for database operations
|
|
163
|
+
*/
|
|
148
164
|
get dataSource() {
|
|
149
165
|
if (!this._dataSource) {
|
|
150
166
|
throw Error(`Datasource not available yet for ${this.options.driverOptions?.dbName}`);
|
|
151
167
|
}
|
|
152
168
|
return this._dataSource;
|
|
153
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Gets the StatusListStore instance
|
|
172
|
+
* @returns StatusListStore for data persistence operations
|
|
173
|
+
*/
|
|
154
174
|
get statusListStore() {
|
|
155
175
|
if (!this._statusListStore) {
|
|
156
176
|
this._statusListStore = new import_ssi_sdk3.StatusListStore(this.dataSource);
|
|
157
177
|
}
|
|
158
178
|
return this._statusListStore;
|
|
159
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Gets the driver configuration options
|
|
182
|
+
* @returns DriverOptions configuration
|
|
183
|
+
*/
|
|
160
184
|
getOptions() {
|
|
161
185
|
return this.options.driverOptions ?? {};
|
|
162
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Gets the driver type
|
|
189
|
+
* @returns StatusListDriverType enum value
|
|
190
|
+
*/
|
|
163
191
|
getType() {
|
|
164
192
|
return this.options.driverType;
|
|
165
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Creates a new status list credential and stores it in the database
|
|
196
|
+
* @param args - Status list creation parameters
|
|
197
|
+
* @returns Promise resolving to StatusListResult
|
|
198
|
+
*/
|
|
166
199
|
async createStatusList(args) {
|
|
167
200
|
const correlationId = args.correlationId ?? this.options.correlationId;
|
|
168
201
|
if (!correlationId) {
|
|
@@ -186,6 +219,11 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
186
219
|
this._statusListLength = implementationResult.length;
|
|
187
220
|
return implementationResult;
|
|
188
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Updates an existing status list credential in the database
|
|
224
|
+
* @param args - Status list update parameters
|
|
225
|
+
* @returns Promise resolving to StatusListResult
|
|
226
|
+
*/
|
|
189
227
|
async updateStatusList(args) {
|
|
190
228
|
const correlationId = args.correlationId ?? this.options.correlationId;
|
|
191
229
|
const extractedDetails = await (0, import_ssi_sdk4.extractCredentialDetails)(args.statusListCredential);
|
|
@@ -214,6 +252,10 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
214
252
|
...details
|
|
215
253
|
};
|
|
216
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* Deletes the status list from the database
|
|
257
|
+
* @returns Promise resolving to boolean indicating success
|
|
258
|
+
*/
|
|
217
259
|
async deleteStatusList() {
|
|
218
260
|
await this.statusListStore.removeStatusList({
|
|
219
261
|
id: this.options.id,
|
|
@@ -221,6 +263,11 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
221
263
|
});
|
|
222
264
|
return Promise.resolve(true);
|
|
223
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Updates a status list entry and returns the credential status
|
|
268
|
+
* @param args - Status list entry update parameters
|
|
269
|
+
* @returns Promise resolving to credential status and entry
|
|
270
|
+
*/
|
|
224
271
|
async updateStatusListEntry(args) {
|
|
225
272
|
const statusListEntity = statusListResultToEntity(await this.getStatusList());
|
|
226
273
|
const statusListEntry = await this.statusListStore.updateStatusListEntry({
|
|
@@ -237,12 +284,27 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
237
284
|
statusListEntry
|
|
238
285
|
};
|
|
239
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Retrieves a status list entry by credential ID
|
|
289
|
+
* @param args - Query parameters including credential ID
|
|
290
|
+
* @returns Promise resolving to status list entry or undefined
|
|
291
|
+
*/
|
|
240
292
|
async getStatusListEntryByCredentialId(args) {
|
|
241
293
|
return await this.statusListStore.getStatusListEntryByCredentialId(args);
|
|
242
294
|
}
|
|
295
|
+
/**
|
|
296
|
+
* Retrieves a status list entry by index
|
|
297
|
+
* @param args - Query parameters including status list index
|
|
298
|
+
* @returns Promise resolving to status list entry or undefined
|
|
299
|
+
*/
|
|
243
300
|
async getStatusListEntryByIndex(args) {
|
|
244
301
|
return await this.statusListStore.getStatusListEntryByIndex(args);
|
|
245
302
|
}
|
|
303
|
+
/**
|
|
304
|
+
* Generates a random available index for new status list entries
|
|
305
|
+
* @param args - Optional correlation ID parameter
|
|
306
|
+
* @returns Promise resolving to available index number
|
|
307
|
+
*/
|
|
246
308
|
async getRandomNewStatusListIndex(args) {
|
|
247
309
|
let result = -1;
|
|
248
310
|
let tries = 0;
|
|
@@ -251,6 +313,12 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
251
313
|
}
|
|
252
314
|
return result;
|
|
253
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* Implementation for generating random status list indices with retry logic
|
|
318
|
+
* @param tries - Number of attempts made
|
|
319
|
+
* @param args - Optional correlation ID parameter
|
|
320
|
+
* @returns Promise resolving to available index or -1 if none found
|
|
321
|
+
*/
|
|
254
322
|
async getRandomNewStatusListIndexImpl(tries, args) {
|
|
255
323
|
const statusListId = this.options.id;
|
|
256
324
|
const correlationId = args?.correlationId ?? this.options.correlationId;
|
|
@@ -273,12 +341,22 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
273
341
|
}
|
|
274
342
|
return -1;
|
|
275
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Gets the length of the status list
|
|
346
|
+
* @param args - Optional correlation ID parameter
|
|
347
|
+
* @returns Promise resolving to status list length
|
|
348
|
+
*/
|
|
276
349
|
async getStatusListLength(args) {
|
|
277
350
|
if (!this._statusListLength) {
|
|
278
351
|
this._statusListLength = await this.getStatusList(args).then((details) => details.length);
|
|
279
352
|
}
|
|
280
353
|
return this._statusListLength;
|
|
281
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* Retrieves the status list details
|
|
357
|
+
* @param args - Optional correlation ID parameter
|
|
358
|
+
* @returns Promise resolving to StatusListResult
|
|
359
|
+
*/
|
|
282
360
|
async getStatusList(args) {
|
|
283
361
|
const id = this.options.id;
|
|
284
362
|
const correlationId = args?.correlationId ?? this.options.correlationId;
|
|
@@ -294,6 +372,10 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
294
372
|
driverType: statusListEntity.driverType
|
|
295
373
|
});
|
|
296
374
|
}
|
|
375
|
+
/**
|
|
376
|
+
* Retrieves all status lists
|
|
377
|
+
* @returns Promise resolving to array of StatusListResult
|
|
378
|
+
*/
|
|
297
379
|
async getStatusLists() {
|
|
298
380
|
const statusLists = await this.statusListStore.getStatusLists({});
|
|
299
381
|
return Promise.all(statusLists.map(async (statusListEntity) => {
|
|
@@ -306,6 +388,10 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
306
388
|
});
|
|
307
389
|
}));
|
|
308
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* Checks if a status list index is currently in use
|
|
393
|
+
* @returns Promise resolving to boolean indicating usage status
|
|
394
|
+
*/
|
|
309
395
|
isStatusListIndexInUse() {
|
|
310
396
|
return Promise.resolve(false);
|
|
311
397
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/drivers.ts","../src/status-list-adapters.ts"],"sourcesContent":["/**\n * @public\n */\nexport * from './types'\nexport * from './drivers'\n","/**\n * StatusList Driver Implementation for TypeORM/Agent Data Sources\n *\n * This module provides the database-backed implementation of the IStatusListDriver interface,\n * handling persistence and retrieval of status list credentials and entries using TypeORM.\n * It delegates status list format-specific operations to the functions layer while managing\n * database interactions, driver configuration, and entity lifecycle.\n *\n * Key responsibilities:\n * - Database connection and store management\n * - Status list CRUD operations\n * - Status list entry management\n * - Random index generation for new entries\n * - Integration with multiple data sources\n *\n * @author Sphereon International B.V.\n * @since 2024\n */\n\nimport { DataSources } from '@sphereon/ssi-sdk.agent-config'\nimport {\n BitstringStatusListEntryCredentialStatus,\n IAddStatusListArgs,\n IAddStatusListEntryArgs,\n IBitstringStatusListEntryEntity,\n IGetStatusListEntryByCredentialIdArgs,\n IGetStatusListEntryByIndexArgs,\n IStatusListEntryEntity,\n StatusListEntity,\n StatusListStore,\n} from '@sphereon/ssi-sdk.data-store'\nimport {\n createCredentialStatusFromStatusList,\n extractCredentialDetails,\n StatusList2021EntryCredentialStatus,\n StatusListOAuthEntryCredentialStatus,\n StatusListResult,\n toStatusListDetails,\n} from '@sphereon/ssi-sdk.vc-status-list'\nimport { StatusListCredential, StatusListCredentialIdMode, StatusListDriverType, StatusListType } from '@sphereon/ssi-types'\nimport { DataSource } from 'typeorm'\nimport { IStatusListDriver } from './types'\nimport { statusListResultToEntity } from './status-list-adapters'\n\nexport interface StatusListManagementOptions {\n id?: string\n correlationId?: string\n driverType: StatusListDriverType\n driverOptions?: DriverOptions\n}\n\nexport type DriverOptions = TypeORMOptions\n\nexport interface TypeORMOptions {\n dbName?: string\n}\n\nexport interface FilesystemOptions {\n path: string // The base path where statusList Credentials will be persisted. Should be a folder and thus not include the VC/StatusList itself\n}\n\nexport function getOptions(args: { id?: string; correlationId?: string; dbName: string }): StatusListManagementOptions {\n return {\n id: args.id,\n correlationId: args.correlationId,\n driverType: StatusListDriverType.AGENT_TYPEORM,\n driverOptions: { dbName: args.dbName },\n }\n}\n\nexport async function getDriver(args: {\n id?: string\n correlationId?: string\n dbName?: string\n dataSource?: DataSource\n dataSources?: DataSources\n}): Promise<IStatusListDriver> {\n const dbName = args.dbName ?? args.dataSource?.name\n if (!dbName) {\n throw Error(`Please provide either a DB name or data source`)\n }\n const dataSources = args.dataSources ?? DataSources.singleInstance()\n return await AgentDataSourceStatusListDriver.init(\n getOptions({\n ...args,\n dbName,\n }),\n { dataSource: args.dataSource ?? (await dataSources.getDbConnection(dbName)), dataSources },\n )\n}\n\n/**\n * TypeORM-based implementation of the IStatusListDriver interface\n *\n * Manages status list credentials and entries using a TypeORM data source.\n * Handles database operations while delegating format-specific logic to the functions layer.\n */\nexport class AgentDataSourceStatusListDriver implements IStatusListDriver {\n private _statusListLength: number | undefined\n\n constructor(\n private _dataSource: DataSource,\n private _statusListStore: StatusListStore,\n private options: StatusListManagementOptions,\n ) {}\n\n public static async init(\n options: StatusListManagementOptions,\n dbArgs?: {\n dataSources?: DataSources\n dataSource?: DataSource\n },\n ): Promise<AgentDataSourceStatusListDriver> {\n if (options.driverType !== StatusListDriverType.AGENT_TYPEORM) {\n throw Error(`TypeORM driver can only be used when the TypeORM driver type is selected in the configuration. Got: ${options.driverType}`)\n } else if (!options.driverOptions) {\n throw Error(`TypeORM driver can only be used when the TypeORM options are provided.`)\n }\n let dataSource: DataSource\n let statusListStore: StatusListStore\n if (dbArgs?.dataSource) {\n dataSource = dbArgs.dataSource\n } else if (options.driverOptions.dbName) {\n if (dbArgs?.dataSources) {\n dataSource = await dbArgs.dataSources.getDbConnection(options.driverOptions.dbName)\n } else {\n dataSource = await DataSources.singleInstance().getDbConnection(options.driverOptions.dbName)\n }\n } else {\n return Promise.reject(Error(`Either a datasource or dbName needs to be provided`))\n }\n\n statusListStore = new StatusListStore(dataSource)\n return new AgentDataSourceStatusListDriver(dataSource, statusListStore, options)\n }\n\n get dataSource(): DataSource {\n if (!this._dataSource) {\n throw Error(`Datasource not available yet for ${this.options.driverOptions?.dbName}`)\n }\n return this._dataSource\n }\n\n get statusListStore(): StatusListStore {\n if (!this._statusListStore) {\n this._statusListStore = new StatusListStore(this.dataSource)\n }\n return this._statusListStore\n }\n\n getOptions(): DriverOptions {\n return this.options.driverOptions ?? {}\n }\n\n getType(): StatusListDriverType {\n return this.options.driverType\n }\n\n async createStatusList(args: {\n statusListType: StatusListType\n statusListCredential: StatusListCredential\n correlationId?: string\n credentialIdMode?: StatusListCredentialIdMode\n bitsPerStatus?: number\n }): Promise<StatusListResult> {\n const correlationId = args.correlationId ?? this.options.correlationId\n if (!correlationId) {\n throw Error('Either a correlationId needs to be set as an option, or it needs to be provided when creating a status list. None found')\n }\n const credentialIdMode = args.credentialIdMode ?? StatusListCredentialIdMode.ISSUANCE\n\n // Convert credential to implementation details using CREATE/READ context\n const implementationResult = await toStatusListDetails({\n statusListCredential: args.statusListCredential,\n statusListType: args.statusListType,\n bitsPerStatus: args.bitsPerStatus,\n correlationId,\n driverType: this.getType(),\n })\n\n // Add driver-specific fields to create complete entity\n const statusListArgs = {\n ...implementationResult,\n credentialIdMode,\n correlationId,\n driverType: this.getType(),\n } as IAddStatusListArgs\n\n await this.statusListStore.addStatusList(statusListArgs)\n this._statusListLength = implementationResult.length\n return implementationResult\n }\n\n async updateStatusList(args: { statusListCredential: StatusListCredential; correlationId: string }): Promise<StatusListResult> {\n const correlationId = args.correlationId ?? this.options.correlationId\n\n const extractedDetails = await extractCredentialDetails(args.statusListCredential)\n const entity = await this.statusListStore.getStatusList({\n id: extractedDetails.id,\n correlationId,\n })\n if (!entity) {\n throw Error(`Status list ${extractedDetails.id}, correlationId ${correlationId} could not be found`)\n }\n\n entity.statusListCredential = args.statusListCredential\n\n const details = await toStatusListDetails({\n extractedDetails,\n statusListEntity: entity,\n })\n\n // Merge details with existing entity and driver properties\n const updateArgs = {\n ...entity,\n ...details,\n correlationId,\n driverType: this.getType(),\n } as IAddStatusListArgs\n\n await this.statusListStore.updateStatusList(updateArgs)\n this._statusListLength = details.length\n return { ...entity, ...details }\n }\n\n async deleteStatusList(): Promise<boolean> {\n await this.statusListStore.removeStatusList({ id: this.options.id, correlationId: this.options.correlationId })\n return Promise.resolve(true)\n }\n\n async updateStatusListEntry(args: IAddStatusListEntryArgs): Promise<{\n credentialStatus: StatusList2021EntryCredentialStatus | StatusListOAuthEntryCredentialStatus | BitstringStatusListEntryCredentialStatus\n statusListEntry: IStatusListEntryEntity | IBitstringStatusListEntryEntity\n }> {\n // Get status list entity\n const statusListEntity: StatusListEntity = statusListResultToEntity(await this.getStatusList())\n\n // Update the entry in the store\n const statusListEntry = await this.statusListStore.updateStatusListEntry({ ...args, statusListId: statusListEntity.id })\n\n // Use implementation to create the credential status - this moves type-specific logic to implementations\n const credentialStatus = await createCredentialStatusFromStatusList({\n statusList: statusListEntity,\n statusListEntry,\n statusListIndex: statusListEntry.statusListIndex,\n })\n\n return {\n credentialStatus,\n statusListEntry,\n }\n }\n\n async getStatusListEntryByCredentialId(\n args: IGetStatusListEntryByCredentialIdArgs,\n ): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity | undefined> {\n return await this.statusListStore.getStatusListEntryByCredentialId(args)\n }\n\n async getStatusListEntryByIndex(\n args: IGetStatusListEntryByIndexArgs,\n ): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity | undefined> {\n return await this.statusListStore.getStatusListEntryByIndex(args)\n }\n\n async getRandomNewStatusListIndex(args?: { correlationId?: string }): Promise<number> {\n let result = -1\n let tries = 0\n while (result < 0) {\n // no tries guard, because we will throw an error when they are exhausted anyway\n result = await this.getRandomNewStatusListIndexImpl(tries++, args)\n }\n return result\n }\n\n private async getRandomNewStatusListIndexImpl(tries: number, args?: { correlationId?: string }): Promise<number> {\n const statusListId = this.options.id\n const correlationId = args?.correlationId ?? this.options.correlationId\n if (tries >= 10) {\n throw Error(`We could not find any random status list index that is available in the statuslist ${statusListId}`)\n }\n // TODO: Check against DB\n const length = await this.getStatusListLength(args)\n const statusListIndex = Array.from({ length: 20 }, () => Math.floor(Math.random() * length))\n const available = await this.statusListStore.availableStatusListEntries({\n statusListId,\n ...(correlationId && { correlationId }),\n statusListIndex,\n })\n if (available.length > 0) {\n return available[0] // doesn't matter we pick the first element, as they are all random anyway\n }\n return -1\n }\n\n async getStatusListLength(args?: { correlationId?: string }): Promise<number> {\n if (!this._statusListLength) {\n this._statusListLength = await this.getStatusList(args).then((details) => details.length)\n }\n return this._statusListLength!\n }\n\n async getStatusList(args?: { correlationId?: string }): Promise<StatusListResult> {\n const id = this.options.id\n const correlationId = args?.correlationId ?? this.options.correlationId\n\n const statusListEntity = await this.statusListStore.getStatusList({ id, correlationId })\n\n // Convert entity to result using CREATE/READ context\n return await toStatusListDetails({\n statusListCredential: statusListEntity.statusListCredential!,\n statusListType: statusListEntity.type,\n bitsPerStatus: statusListEntity.bitsPerStatus,\n correlationId: statusListEntity.correlationId,\n driverType: statusListEntity.driverType,\n })\n }\n\n async getStatusLists(): Promise<Array<StatusListResult>> {\n const statusLists = await this.statusListStore.getStatusLists({})\n return Promise.all(\n statusLists.map(async (statusListEntity) => {\n return toStatusListDetails({\n statusListCredential: statusListEntity.statusListCredential!,\n statusListType: statusListEntity.type,\n bitsPerStatus: statusListEntity.bitsPerStatus,\n correlationId: statusListEntity.correlationId,\n driverType: statusListEntity.driverType,\n })\n }),\n )\n }\n\n isStatusListIndexInUse(): Promise<boolean> {\n return Promise.resolve(false)\n }\n}\n","import { StatusListType } from '@sphereon/ssi-types'\nimport { BitstringStatusListEntity, OAuthStatusListEntity, StatusList2021Entity } from '@sphereon/ssi-sdk.data-store'\nimport { StatusListResult } from '@sphereon/ssi-sdk.vc-status-list'\n\nexport function statusListResultToEntity(result: StatusListResult): StatusList2021Entity | OAuthStatusListEntity | BitstringStatusListEntity {\n const baseFields = {\n id: result.id,\n correlationId: result.correlationId,\n driverType: result.driverType,\n credentialIdMode: result.credentialIdMode,\n length: result.length,\n issuer: result.issuer,\n type: result.type,\n proofFormat: result.proofFormat,\n statusListCredential: result.statusListCredential,\n }\n\n if (result.type === StatusListType.StatusList2021) {\n if (!result.statusList2021) {\n throw new Error('Missing statusList2021 details')\n }\n return Object.assign(new StatusList2021Entity(), {\n ...baseFields,\n indexingDirection: result.statusList2021.indexingDirection,\n statusPurpose: result.statusList2021.statusPurpose,\n })\n } else if (result.type === StatusListType.OAuthStatusList) {\n if (!result.oauthStatusList) {\n throw new Error('Missing oauthStatusList details')\n }\n return Object.assign(new OAuthStatusListEntity(), {\n ...baseFields,\n bitsPerStatus: result.oauthStatusList.bitsPerStatus,\n expiresAt: result.oauthStatusList.expiresAt,\n })\n } else if (result.type === StatusListType.BitstringStatusList) {\n if (!result.bitstringStatusList) {\n throw new Error('Missing bitstringStatusList details')\n }\n return Object.assign(new BitstringStatusListEntity(), {\n ...baseFields,\n statusPurpose: result.bitstringStatusList.statusPurpose,\n ttl: result.bitstringStatusList.ttl,\n bitsPerStatus: result.bitstringStatusList.bitsPerStatus,\n validFrom: result.bitstringStatusList.validFrom,\n validUntil: result.bitstringStatusList.validUntil,\n })\n }\n throw new Error(`Unsupported status list type: ${result.type}`)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACmBA,IAAAA,kBAA4B;AAC5B,IAAAA,kBAUO;AACP,IAAAA,kBAOO;AACP,IAAAC,oBAAuG;;;ACvCvG,uBAA+B;AAC/B,qBAAuF;AAGhF,SAASC,yBAAyBC,QAAwB;AAC/D,QAAMC,aAAa;IACjBC,IAAIF,OAAOE;IACXC,eAAeH,OAAOG;IACtBC,YAAYJ,OAAOI;IACnBC,kBAAkBL,OAAOK;IACzBC,QAAQN,OAAOM;IACfC,QAAQP,OAAOO;IACfC,MAAMR,OAAOQ;IACbC,aAAaT,OAAOS;IACpBC,sBAAsBV,OAAOU;EAC/B;AAEA,MAAIV,OAAOQ,SAASG,gCAAeC,gBAAgB;AACjD,QAAI,CAACZ,OAAOa,gBAAgB;AAC1B,YAAM,IAAIC,MAAM,gCAAA;IAClB;AACA,WAAOC,OAAOC,OAAO,IAAIC,oCAAAA,GAAwB;MAC/C,GAAGhB;MACHiB,mBAAmBlB,OAAOa,eAAeK;MACzCC,eAAenB,OAAOa,eAAeM;IACvC,CAAA;EACF,WAAWnB,OAAOQ,SAASG,gCAAeS,iBAAiB;AACzD,QAAI,CAACpB,OAAOqB,iBAAiB;AAC3B,YAAM,IAAIP,MAAM,iCAAA;IAClB;AACA,WAAOC,OAAOC,OAAO,IAA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;AACA,WAAO;EACT;EAEA,MAAMN,oBAAoBlE,MAAoD;AAC5E,QAAI,CAAC,KAAKkB,mBAAmB;AAC3B,WAAKA,oBAAoB,MAAM,KAAK2B,cAAc7C,IAAAA,EAAM0E,KAAK,CAAC5B,YAAYA,QAAQN,MAAM;IAC1F;AACA,WAAO,KAAKtB;EACd;EAEA,MAAM2B,cAAc7C,MAA8D;AAChF,UAAMC,KAAK,KAAKqB,QAAQrB;AACxB,UAAMC,gBAAgBF,MAAME,iBAAiB,KAAKoB,QAAQpB;AAE1D,UAAM6C,mBAAmB,MAAM,KAAKvB,gBAAgBqB,cAAc;MAAE5C;MAAIC;IAAc,CAAA;AAGtF,WAAO,UAAMgC,qCAAoB;MAC/BC,sBAAsBY,iBAAiBZ;MACvCC,gBAAgBW,iBAAiB4B;MACjCtC,eAAeU,iBAAiBV;MAChCnC,eAAe6C,iBAAiB7C;MAChCC,YAAY4C,iBAAiB5C;IAC/B,CAAA;EACF;EAEA,MAAMyE,iBAAmD;AACvD,UAAMC,cAAc,MAAM,KAAKrD,gBAAgBoD,eAAe,CAAC,CAAA;AAC/D,WAAOnD,QAAQqD,IACbD,YAAYE,IAAI,OAAOhC,qBAAAA;AACrB,iBAAOb,qCAAoB;QACzBC,sBAAsBY,iBAAiBZ;QACvCC,gBAAgBW,iBAAiB4B;QACjCtC,eAAeU,iBAAiBV;QAChCnC,eAAe6C,iBAAiB7C;QAChCC,YAAY4C,iBAAiB5C;MAC/B,CAAA;IACF,CAAA,CAAA;EAEJ;EAEA6E,yBAA2C;AACzC,WAAOvD,QAAQ0B,QAAQ,KAAA;EACzB;AACF;","names":["import_ssi_sdk","import_ssi_types","statusListResultToEntity","result","baseFields","id","correlationId","driverType","credentialIdMode","length","issuer","type","proofFormat","statusListCredential","StatusListType","StatusList2021","statusList2021","Error","Object","assign","StatusList2021Entity","indexingDirection","statusPurpose","OAuthStatusList","oauthStatusList","OAuthStatusListEntity","bitsPerStatus","expiresAt","BitstringStatusList","bitstringStatusList","BitstringStatusListEntity","ttl","validFrom","validUntil","getOptions","args","id","correlationId","driverType","StatusListDriverType","AGENT_TYPEORM","driverOptions","dbName","getDriver","dataSource","name","Error","dataSources","DataSources","singleInstance","AgentDataSourceStatusListDriver","init","getDbConnection","_statusListLength","constructor","_dataSource","_statusListStore","options","dbArgs","statusListStore","Promise","reject","StatusListStore","getType","createStatusList","credentialIdMode","StatusListCredentialIdMode","ISSUANCE","implementationResult","toStatusListDetails","statusListCredential","statusListType","bitsPerStatus","statusListArgs","addStatusList","length","updateStatusList","extractedDetails","extractCredentialDetails","entity","getStatusList","details","statusListEntity","updateArgs","deleteStatusList","removeStatusList","resolve","updateStatusListEntry","statusListResultToEntity","statusListEntry","statusListId","credentialStatus","createCredentialStatusFromStatusList","statusList","statusListIndex","getStatusListEntryByCredentialId","getStatusListEntryByIndex","getRandomNewStatusListIndex","result","tries","getRandomNewStatusListIndexImpl","getStatusListLength","Array","from","Math","floor","random","available","availableStatusListEntries","then","type","getStatusLists","statusLists","all","map","isStatusListIndexInUse"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/drivers.ts","../src/status-list-adapters.ts"],"sourcesContent":["/**\n * @public\n */\nexport * from './types'\nexport * from './drivers'\n","/**\n * StatusList Driver Implementation for TypeORM/Agent Data Sources\n *\n * This module provides the database-backed implementation of the IStatusListDriver interface,\n * handling persistence and retrieval of status list credentials and entries using TypeORM.\n * It delegates status list format-specific operations to the functions layer while managing\n * database interactions, driver configuration, and entity lifecycle.\n *\n * Key responsibilities:\n * - Database connection and store management\n * - Status list CRUD operations\n * - Status list entry management\n * - Random index generation for new entries\n * - Integration with multiple data sources\n *\n * @author Sphereon International B.V.\n * @since 2024\n */\n\nimport { DataSources } from '@sphereon/ssi-sdk.agent-config'\nimport {\n BitstringStatusListEntryCredentialStatus,\n IAddStatusListArgs,\n IAddStatusListEntryArgs,\n IBitstringStatusListEntryEntity,\n IGetStatusListEntryByCredentialIdArgs,\n IGetStatusListEntryByIndexArgs,\n IStatusListEntryEntity,\n StatusListEntity,\n StatusListStore,\n} from '@sphereon/ssi-sdk.data-store'\nimport {\n createCredentialStatusFromStatusList,\n extractCredentialDetails,\n StatusList2021EntryCredentialStatus,\n StatusListOAuthEntryCredentialStatus,\n StatusListResult,\n toStatusListDetails,\n} from '@sphereon/ssi-sdk.vc-status-list'\nimport { StatusListCredential, StatusListCredentialIdMode, StatusListDriverType, StatusListType } from '@sphereon/ssi-types'\nimport { DataSource } from 'typeorm'\nimport { IStatusListDriver } from './types'\nimport { statusListResultToEntity } from './status-list-adapters'\n\n/**\n * Configuration options for status list management\n */\nexport interface StatusListManagementOptions {\n id?: string\n correlationId?: string\n driverType: StatusListDriverType\n driverOptions?: DriverOptions\n}\n\nexport type DriverOptions = TypeORMOptions\n\n/**\n * TypeORM-specific configuration options\n */\nexport interface TypeORMOptions {\n dbName?: string\n}\n\n/**\n * Filesystem-specific configuration options\n */\nexport interface FilesystemOptions {\n path: string // The base path where statusList Credentials will be persisted. Should be a folder and thus not include the VC/StatusList itself\n}\n\n/**\n * Creates status list management options for TypeORM driver\n * @param args - Configuration parameters including id, correlationId, and database name\n * @returns StatusListManagementOptions configured for TypeORM\n */\nexport function getOptions(args: { id?: string; correlationId?: string; dbName: string }): StatusListManagementOptions {\n return {\n id: args.id,\n correlationId: args.correlationId,\n driverType: StatusListDriverType.AGENT_TYPEORM,\n driverOptions: { dbName: args.dbName },\n }\n}\n\n/**\n * Creates and initializes a status list driver instance\n * @param args - Configuration parameters including database connection details\n * @returns Promise resolving to initialized IStatusListDriver instance\n */\nexport async function getDriver(args: {\n id?: string\n correlationId?: string\n dbName?: string\n dataSource?: DataSource\n dataSources?: DataSources\n}): Promise<IStatusListDriver> {\n const dbName = args.dbName ?? args.dataSource?.name\n if (!dbName) {\n throw Error(`Please provide either a DB name or data source`)\n }\n const dataSources = args.dataSources ?? DataSources.singleInstance()\n return await AgentDataSourceStatusListDriver.init(\n getOptions({\n ...args,\n dbName,\n }),\n { dataSource: args.dataSource ?? (await dataSources.getDbConnection(dbName)), dataSources },\n )\n}\n\n/**\n * TypeORM-based implementation of the IStatusListDriver interface\n *\n * Manages status list credentials and entries using a TypeORM data source.\n * Handles database operations while delegating format-specific logic to the functions layer.\n */\nexport class AgentDataSourceStatusListDriver implements IStatusListDriver {\n private _statusListLength: number | undefined\n\n /**\n * Creates a new AgentDataSourceStatusListDriver instance\n * @param _dataSource - TypeORM DataSource for database operations\n * @param _statusListStore - StatusListStore for data persistence\n * @param options - Driver configuration options\n */\n constructor(\n private _dataSource: DataSource,\n private _statusListStore: StatusListStore,\n private options: StatusListManagementOptions,\n ) {}\n\n /**\n * Initializes and creates a new AgentDataSourceStatusListDriver instance\n * @param options - Status list management configuration\n * @param dbArgs - Database connection arguments\n * @returns Promise resolving to initialized driver instance\n */\n public static async init(\n options: StatusListManagementOptions,\n dbArgs?: {\n dataSources?: DataSources\n dataSource?: DataSource\n },\n ): Promise<AgentDataSourceStatusListDriver> {\n if (options.driverType !== StatusListDriverType.AGENT_TYPEORM) {\n throw Error(`TypeORM driver can only be used when the TypeORM driver type is selected in the configuration. Got: ${options.driverType}`)\n } else if (!options.driverOptions) {\n throw Error(`TypeORM driver can only be used when the TypeORM options are provided.`)\n }\n let dataSource: DataSource\n let statusListStore: StatusListStore\n if (dbArgs?.dataSource) {\n dataSource = dbArgs.dataSource\n } else if (options.driverOptions.dbName) {\n if (dbArgs?.dataSources) {\n dataSource = await dbArgs.dataSources.getDbConnection(options.driverOptions.dbName)\n } else {\n dataSource = await DataSources.singleInstance().getDbConnection(options.driverOptions.dbName)\n }\n } else {\n return Promise.reject(Error(`Either a datasource or dbName needs to be provided`))\n }\n\n statusListStore = new StatusListStore(dataSource)\n return new AgentDataSourceStatusListDriver(dataSource, statusListStore, options)\n }\n\n /**\n * Gets the TypeORM DataSource instance\n * @returns DataSource instance for database operations\n */\n get dataSource(): DataSource {\n if (!this._dataSource) {\n throw Error(`Datasource not available yet for ${this.options.driverOptions?.dbName}`)\n }\n return this._dataSource\n }\n\n /**\n * Gets the StatusListStore instance\n * @returns StatusListStore for data persistence operations\n */\n get statusListStore(): StatusListStore {\n if (!this._statusListStore) {\n this._statusListStore = new StatusListStore(this.dataSource)\n }\n return this._statusListStore\n }\n\n /**\n * Gets the driver configuration options\n * @returns DriverOptions configuration\n */\n getOptions(): DriverOptions {\n return this.options.driverOptions ?? {}\n }\n\n /**\n * Gets the driver type\n * @returns StatusListDriverType enum value\n */\n getType(): StatusListDriverType {\n return this.options.driverType\n }\n\n /**\n * Creates a new status list credential and stores it in the database\n * @param args - Status list creation parameters\n * @returns Promise resolving to StatusListResult\n */\n async createStatusList(args: {\n statusListType: StatusListType\n statusListCredential: StatusListCredential\n correlationId?: string\n credentialIdMode?: StatusListCredentialIdMode\n bitsPerStatus?: number\n }): Promise<StatusListResult> {\n const correlationId = args.correlationId ?? this.options.correlationId\n if (!correlationId) {\n throw Error('Either a correlationId needs to be set as an option, or it needs to be provided when creating a status list. None found')\n }\n const credentialIdMode = args.credentialIdMode ?? StatusListCredentialIdMode.ISSUANCE\n\n // Convert credential to implementation details using CREATE/READ context\n const implementationResult = await toStatusListDetails({\n statusListCredential: args.statusListCredential,\n statusListType: args.statusListType,\n bitsPerStatus: args.bitsPerStatus,\n correlationId,\n driverType: this.getType(),\n })\n\n // Add driver-specific fields to create complete entity\n const statusListArgs = {\n ...implementationResult,\n credentialIdMode,\n correlationId,\n driverType: this.getType(),\n } as IAddStatusListArgs\n\n await this.statusListStore.addStatusList(statusListArgs)\n this._statusListLength = implementationResult.length\n return implementationResult\n }\n\n /**\n * Updates an existing status list credential in the database\n * @param args - Status list update parameters\n * @returns Promise resolving to StatusListResult\n */\n async updateStatusList(args: { statusListCredential: StatusListCredential; correlationId: string }): Promise<StatusListResult> {\n const correlationId = args.correlationId ?? this.options.correlationId\n\n const extractedDetails = await extractCredentialDetails(args.statusListCredential)\n const entity = await this.statusListStore.getStatusList({\n id: extractedDetails.id,\n correlationId,\n })\n if (!entity) {\n throw Error(`Status list ${extractedDetails.id}, correlationId ${correlationId} could not be found`)\n }\n\n entity.statusListCredential = args.statusListCredential\n\n const details = await toStatusListDetails({\n extractedDetails,\n statusListEntity: entity,\n })\n\n // Merge details with existing entity and driver properties\n const updateArgs = {\n ...entity,\n ...details,\n correlationId,\n driverType: this.getType(),\n } as IAddStatusListArgs\n\n await this.statusListStore.updateStatusList(updateArgs)\n this._statusListLength = details.length\n return { ...entity, ...details }\n }\n\n /**\n * Deletes the status list from the database\n * @returns Promise resolving to boolean indicating success\n */\n async deleteStatusList(): Promise<boolean> {\n await this.statusListStore.removeStatusList({ id: this.options.id, correlationId: this.options.correlationId })\n return Promise.resolve(true)\n }\n\n /**\n * Updates a status list entry and returns the credential status\n * @param args - Status list entry update parameters\n * @returns Promise resolving to credential status and entry\n */\n async updateStatusListEntry(args: IAddStatusListEntryArgs): Promise<{\n credentialStatus: StatusList2021EntryCredentialStatus | StatusListOAuthEntryCredentialStatus | BitstringStatusListEntryCredentialStatus\n statusListEntry: IStatusListEntryEntity | IBitstringStatusListEntryEntity\n }> {\n // Get status list entity\n const statusListEntity: StatusListEntity = statusListResultToEntity(await this.getStatusList())\n\n // Update the entry in the store\n const statusListEntry = await this.statusListStore.updateStatusListEntry({ ...args, statusListId: statusListEntity.id })\n\n // Use implementation to create the credential status - this moves type-specific logic to implementations\n const credentialStatus = await createCredentialStatusFromStatusList({\n statusList: statusListEntity,\n statusListEntry,\n statusListIndex: statusListEntry.statusListIndex,\n })\n\n return {\n credentialStatus,\n statusListEntry,\n }\n }\n\n /**\n * Retrieves a status list entry by credential ID\n * @param args - Query parameters including credential ID\n * @returns Promise resolving to status list entry or undefined\n */\n async getStatusListEntryByCredentialId(\n args: IGetStatusListEntryByCredentialIdArgs,\n ): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity | undefined> {\n return await this.statusListStore.getStatusListEntryByCredentialId(args)\n }\n\n /**\n * Retrieves a status list entry by index\n * @param args - Query parameters including status list index\n * @returns Promise resolving to status list entry or undefined\n */\n async getStatusListEntryByIndex(\n args: IGetStatusListEntryByIndexArgs,\n ): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity | undefined> {\n return await this.statusListStore.getStatusListEntryByIndex(args)\n }\n\n /**\n * Generates a random available index for new status list entries\n * @param args - Optional correlation ID parameter\n * @returns Promise resolving to available index number\n */\n async getRandomNewStatusListIndex(args?: { correlationId?: string }): Promise<number> {\n let result = -1\n let tries = 0\n while (result < 0) {\n // no tries guard, because we will throw an error when they are exhausted anyway\n result = await this.getRandomNewStatusListIndexImpl(tries++, args)\n }\n return result\n }\n\n /**\n * Implementation for generating random status list indices with retry logic\n * @param tries - Number of attempts made\n * @param args - Optional correlation ID parameter\n * @returns Promise resolving to available index or -1 if none found\n */\n private async getRandomNewStatusListIndexImpl(tries: number, args?: { correlationId?: string }): Promise<number> {\n const statusListId = this.options.id\n const correlationId = args?.correlationId ?? this.options.correlationId\n if (tries >= 10) {\n throw Error(`We could not find any random status list index that is available in the statuslist ${statusListId}`)\n }\n // TODO: Check against DB\n const length = await this.getStatusListLength(args)\n const statusListIndex = Array.from({ length: 20 }, () => Math.floor(Math.random() * length))\n const available = await this.statusListStore.availableStatusListEntries({\n statusListId,\n ...(correlationId && { correlationId }),\n statusListIndex,\n })\n if (available.length > 0) {\n return available[0] // doesn't matter we pick the first element, as they are all random anyway\n }\n return -1\n }\n\n /**\n * Gets the length of the status list\n * @param args - Optional correlation ID parameter\n * @returns Promise resolving to status list length\n */\n async getStatusListLength(args?: { correlationId?: string }): Promise<number> {\n if (!this._statusListLength) {\n this._statusListLength = await this.getStatusList(args).then((details) => details.length)\n }\n return this._statusListLength!\n }\n\n /**\n * Retrieves the status list details\n * @param args - Optional correlation ID parameter\n * @returns Promise resolving to StatusListResult\n */\n async getStatusList(args?: { correlationId?: string }): Promise<StatusListResult> {\n const id = this.options.id\n const correlationId = args?.correlationId ?? this.options.correlationId\n\n const statusListEntity = await this.statusListStore.getStatusList({ id, correlationId })\n\n // Convert entity to result using CREATE/READ context\n return await toStatusListDetails({\n statusListCredential: statusListEntity.statusListCredential!,\n statusListType: statusListEntity.type,\n bitsPerStatus: statusListEntity.bitsPerStatus,\n correlationId: statusListEntity.correlationId,\n driverType: statusListEntity.driverType,\n })\n }\n\n /**\n * Retrieves all status lists\n * @returns Promise resolving to array of StatusListResult\n */\n async getStatusLists(): Promise<Array<StatusListResult>> {\n const statusLists = await this.statusListStore.getStatusLists({})\n return Promise.all(\n statusLists.map(async (statusListEntity) => {\n return toStatusListDetails({\n statusListCredential: statusListEntity.statusListCredential!,\n statusListType: statusListEntity.type,\n bitsPerStatus: statusListEntity.bitsPerStatus,\n correlationId: statusListEntity.correlationId,\n driverType: statusListEntity.driverType,\n })\n }),\n )\n }\n\n /**\n * Checks if a status list index is currently in use\n * @returns Promise resolving to boolean indicating usage status\n */\n isStatusListIndexInUse(): Promise<boolean> {\n return Promise.resolve(false)\n }\n}\n","import { StatusListType } from '@sphereon/ssi-types'\nimport { BitstringStatusListEntity, OAuthStatusListEntity, StatusList2021Entity } from '@sphereon/ssi-sdk.data-store'\nimport { StatusListResult } from '@sphereon/ssi-sdk.vc-status-list'\n\nexport function statusListResultToEntity(result: StatusListResult): StatusList2021Entity | OAuthStatusListEntity | BitstringStatusListEntity {\n const baseFields = {\n id: result.id,\n correlationId: result.correlationId,\n driverType: result.driverType,\n credentialIdMode: result.credentialIdMode,\n length: result.length,\n issuer: result.issuer,\n type: result.type,\n proofFormat: result.proofFormat,\n statusListCredential: result.statusListCredential,\n }\n\n if (result.type === StatusListType.StatusList2021) {\n if (!result.statusList2021) {\n throw new Error('Missing statusList2021 details')\n }\n return Object.assign(new StatusList2021Entity(), {\n ...baseFields,\n indexingDirection: result.statusList2021.indexingDirection,\n statusPurpose: result.statusList2021.statusPurpose,\n })\n } else if (result.type === StatusListType.OAuthStatusList) {\n if (!result.oauthStatusList) {\n throw new Error('Missing oauthStatusList details')\n }\n return Object.assign(new OAuthStatusListEntity(), {\n ...baseFields,\n bitsPerStatus: result.oauthStatusList.bitsPerStatus,\n expiresAt: result.oauthStatusList.expiresAt,\n })\n } else if (result.type === StatusListType.BitstringStatusList) {\n if (!result.bitstringStatusList) {\n throw new Error('Missing bitstringStatusList details')\n }\n return Object.assign(new BitstringStatusListEntity(), {\n ...baseFields,\n statusPurpose: result.bitstringStatusList.statusPurpose,\n ttl: result.bitstringStatusList.ttl,\n bitsPerStatus: result.bitstringStatusList.bitsPerStatus,\n validFrom: result.bitstringStatusList.validFrom,\n validUntil: result.bitstringStatusList.validUntil,\n })\n }\n throw new Error(`Unsupported status list type: ${result.type}`)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACmBA,IAAAA,kBAA4B;AAC5B,IAAAA,kBAUO;AACP,IAAAA,kBAOO;AACP,IAAAC,oBAAuG;;;ACvCvG,uBAA+B;AAC/B,qBAAuF;AAGhF,SAASC,yBAAyBC,QAAwB;AAC/D,QAAMC,aAAa;IACjBC,IAAIF,OAAOE;IACXC,eAAeH,OAAOG;IACtBC,YAAYJ,OAAOI;IACnBC,kBAAkBL,OAAOK;IACzBC,QAAQN,OAAOM;IACfC,QAAQP,OAAOO;IACfC,MAAMR,OAAOQ;IACbC,aAAaT,OAAOS;IACpBC,sBAAsBV,OAAOU;EAC/B;AAEA,MAAIV,OAAOQ,SAASG,gCAAeC,gBAAgB;AACjD,QAAI,CAACZ,OAAOa,gBAAgB;AAC1B,YAAM,IAAIC,MAAM,gCAAA;IAClB;AACA,WAAOC,OAAOC,OAAO,IAAIC,oCAAAA,GAAwB;MAC/C,GAAGhB;MACHiB,mBAAmBlB,OAAOa,eAAeK;MACzCC,eAAenB,OAAOa,eAAeM;IACvC,CAAA;EACF,WAAWnB,OAAOQ,SAASG,gCAAeS,iBAAiB;AACzD,QAAI,CAACpB,OAAOqB,iBAAiB;AAC3B,YAAM,IAAIP,MAAM,iCAAA;IAClB;AACA,WAAOC,OAAOC,OAAO,IAAIM,qCAAAA,G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AA;AACA,QAAIa,UAAUhC,SAAS,GAAG;AACxB,aAAOgC,UAAU,CAAA;IACnB;AACA,WAAO;EACT;;;;;;EAOA,MAAMN,oBAAoBlE,MAAoD;AAC5E,QAAI,CAAC,KAAKkB,mBAAmB;AAC3B,WAAKA,oBAAoB,MAAM,KAAK2B,cAAc7C,IAAAA,EAAM0E,KAAK,CAAC5B,YAAYA,QAAQN,MAAM;IAC1F;AACA,WAAO,KAAKtB;EACd;;;;;;EAOA,MAAM2B,cAAc7C,MAA8D;AAChF,UAAMC,KAAK,KAAKqB,QAAQrB;AACxB,UAAMC,gBAAgBF,MAAME,iBAAiB,KAAKoB,QAAQpB;AAE1D,UAAM6C,mBAAmB,MAAM,KAAKvB,gBAAgBqB,cAAc;MAAE5C;MAAIC;IAAc,CAAA;AAGtF,WAAO,UAAMgC,qCAAoB;MAC/BC,sBAAsBY,iBAAiBZ;MACvCC,gBAAgBW,iBAAiB4B;MACjCtC,eAAeU,iBAAiBV;MAChCnC,eAAe6C,iBAAiB7C;MAChCC,YAAY4C,iBAAiB5C;IAC/B,CAAA;EACF;;;;;EAMA,MAAMyE,iBAAmD;AACvD,UAAMC,cAAc,MAAM,KAAKrD,gBAAgBoD,eAAe,CAAC,CAAA;AAC/D,WAAOnD,QAAQqD,IACbD,YAAYE,IAAI,OAAOhC,qBAAAA;AACrB,iBAAOb,qCAAoB;QACzBC,sBAAsBY,iBAAiBZ;QACvCC,gBAAgBW,iBAAiB4B;QACjCtC,eAAeU,iBAAiBV;QAChCnC,eAAe6C,iBAAiB7C;QAChCC,YAAY4C,iBAAiB5C;MAC/B,CAAA;IACF,CAAA,CAAA;EAEJ;;;;;EAMA6E,yBAA2C;AACzC,WAAOvD,QAAQ0B,QAAQ,KAAA;EACzB;AACF;","names":["import_ssi_sdk","import_ssi_types","statusListResultToEntity","result","baseFields","id","correlationId","driverType","credentialIdMode","length","issuer","type","proofFormat","statusListCredential","StatusListType","StatusList2021","statusList2021","Error","Object","assign","StatusList2021Entity","indexingDirection","statusPurpose","OAuthStatusList","oauthStatusList","OAuthStatusListEntity","bitsPerStatus","expiresAt","BitstringStatusList","bitstringStatusList","BitstringStatusListEntity","ttl","validFrom","validUntil","getOptions","args","id","correlationId","driverType","StatusListDriverType","AGENT_TYPEORM","driverOptions","dbName","getDriver","dataSource","name","Error","dataSources","DataSources","singleInstance","AgentDataSourceStatusListDriver","init","getDbConnection","_statusListLength","constructor","_dataSource","_statusListStore","options","dbArgs","statusListStore","Promise","reject","StatusListStore","getType","createStatusList","credentialIdMode","StatusListCredentialIdMode","ISSUANCE","implementationResult","toStatusListDetails","statusListCredential","statusListType","bitsPerStatus","statusListArgs","addStatusList","length","updateStatusList","extractedDetails","extractCredentialDetails","entity","getStatusList","details","statusListEntity","updateArgs","deleteStatusList","removeStatusList","resolve","updateStatusListEntry","statusListResultToEntity","statusListEntry","statusListId","credentialStatus","createCredentialStatusFromStatusList","statusList","statusListIndex","getStatusListEntryByCredentialId","getStatusListEntryByIndex","getRandomNewStatusListIndex","result","tries","getRandomNewStatusListIndexImpl","getStatusListLength","Array","from","Math","floor","random","available","availableStatusListEntries","then","type","getStatusLists","statusLists","all","map","isStatusListIndexInUse"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -26,6 +26,9 @@ import { IVcdmCredentialPlugin } from '@sphereon/ssi-sdk.credential-vcdm';
|
|
|
26
26
|
* @since 2024
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Configuration options for status list management
|
|
31
|
+
*/
|
|
29
32
|
interface StatusListManagementOptions {
|
|
30
33
|
id?: string;
|
|
31
34
|
correlationId?: string;
|
|
@@ -33,17 +36,33 @@ interface StatusListManagementOptions {
|
|
|
33
36
|
driverOptions?: DriverOptions;
|
|
34
37
|
}
|
|
35
38
|
type DriverOptions = TypeORMOptions;
|
|
39
|
+
/**
|
|
40
|
+
* TypeORM-specific configuration options
|
|
41
|
+
*/
|
|
36
42
|
interface TypeORMOptions {
|
|
37
43
|
dbName?: string;
|
|
38
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Filesystem-specific configuration options
|
|
47
|
+
*/
|
|
39
48
|
interface FilesystemOptions {
|
|
40
49
|
path: string;
|
|
41
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates status list management options for TypeORM driver
|
|
53
|
+
* @param args - Configuration parameters including id, correlationId, and database name
|
|
54
|
+
* @returns StatusListManagementOptions configured for TypeORM
|
|
55
|
+
*/
|
|
42
56
|
declare function getOptions(args: {
|
|
43
57
|
id?: string;
|
|
44
58
|
correlationId?: string;
|
|
45
59
|
dbName: string;
|
|
46
60
|
}): StatusListManagementOptions;
|
|
61
|
+
/**
|
|
62
|
+
* Creates and initializes a status list driver instance
|
|
63
|
+
* @param args - Configuration parameters including database connection details
|
|
64
|
+
* @returns Promise resolving to initialized IStatusListDriver instance
|
|
65
|
+
*/
|
|
47
66
|
declare function getDriver(args: {
|
|
48
67
|
id?: string;
|
|
49
68
|
correlationId?: string;
|
|
@@ -62,15 +81,48 @@ declare class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
62
81
|
private _statusListStore;
|
|
63
82
|
private options;
|
|
64
83
|
private _statusListLength;
|
|
84
|
+
/**
|
|
85
|
+
* Creates a new AgentDataSourceStatusListDriver instance
|
|
86
|
+
* @param _dataSource - TypeORM DataSource for database operations
|
|
87
|
+
* @param _statusListStore - StatusListStore for data persistence
|
|
88
|
+
* @param options - Driver configuration options
|
|
89
|
+
*/
|
|
65
90
|
constructor(_dataSource: DataSource, _statusListStore: StatusListStore, options: StatusListManagementOptions);
|
|
91
|
+
/**
|
|
92
|
+
* Initializes and creates a new AgentDataSourceStatusListDriver instance
|
|
93
|
+
* @param options - Status list management configuration
|
|
94
|
+
* @param dbArgs - Database connection arguments
|
|
95
|
+
* @returns Promise resolving to initialized driver instance
|
|
96
|
+
*/
|
|
66
97
|
static init(options: StatusListManagementOptions, dbArgs?: {
|
|
67
98
|
dataSources?: DataSources;
|
|
68
99
|
dataSource?: DataSource;
|
|
69
100
|
}): Promise<AgentDataSourceStatusListDriver>;
|
|
101
|
+
/**
|
|
102
|
+
* Gets the TypeORM DataSource instance
|
|
103
|
+
* @returns DataSource instance for database operations
|
|
104
|
+
*/
|
|
70
105
|
get dataSource(): DataSource;
|
|
106
|
+
/**
|
|
107
|
+
* Gets the StatusListStore instance
|
|
108
|
+
* @returns StatusListStore for data persistence operations
|
|
109
|
+
*/
|
|
71
110
|
get statusListStore(): StatusListStore;
|
|
111
|
+
/**
|
|
112
|
+
* Gets the driver configuration options
|
|
113
|
+
* @returns DriverOptions configuration
|
|
114
|
+
*/
|
|
72
115
|
getOptions(): DriverOptions;
|
|
116
|
+
/**
|
|
117
|
+
* Gets the driver type
|
|
118
|
+
* @returns StatusListDriverType enum value
|
|
119
|
+
*/
|
|
73
120
|
getType(): StatusListDriverType;
|
|
121
|
+
/**
|
|
122
|
+
* Creates a new status list credential and stores it in the database
|
|
123
|
+
* @param args - Status list creation parameters
|
|
124
|
+
* @returns Promise resolving to StatusListResult
|
|
125
|
+
*/
|
|
74
126
|
createStatusList(args: {
|
|
75
127
|
statusListType: StatusListType;
|
|
76
128
|
statusListCredential: StatusListCredential;
|
|
@@ -78,28 +130,81 @@ declare class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
78
130
|
credentialIdMode?: StatusListCredentialIdMode;
|
|
79
131
|
bitsPerStatus?: number;
|
|
80
132
|
}): Promise<StatusListResult>;
|
|
133
|
+
/**
|
|
134
|
+
* Updates an existing status list credential in the database
|
|
135
|
+
* @param args - Status list update parameters
|
|
136
|
+
* @returns Promise resolving to StatusListResult
|
|
137
|
+
*/
|
|
81
138
|
updateStatusList(args: {
|
|
82
139
|
statusListCredential: StatusListCredential;
|
|
83
140
|
correlationId: string;
|
|
84
141
|
}): Promise<StatusListResult>;
|
|
142
|
+
/**
|
|
143
|
+
* Deletes the status list from the database
|
|
144
|
+
* @returns Promise resolving to boolean indicating success
|
|
145
|
+
*/
|
|
85
146
|
deleteStatusList(): Promise<boolean>;
|
|
147
|
+
/**
|
|
148
|
+
* Updates a status list entry and returns the credential status
|
|
149
|
+
* @param args - Status list entry update parameters
|
|
150
|
+
* @returns Promise resolving to credential status and entry
|
|
151
|
+
*/
|
|
86
152
|
updateStatusListEntry(args: IAddStatusListEntryArgs): Promise<{
|
|
87
153
|
credentialStatus: StatusList2021EntryCredentialStatus | StatusListOAuthEntryCredentialStatus | BitstringStatusListEntryCredentialStatus;
|
|
88
154
|
statusListEntry: IStatusListEntryEntity | IBitstringStatusListEntryEntity;
|
|
89
155
|
}>;
|
|
156
|
+
/**
|
|
157
|
+
* Retrieves a status list entry by credential ID
|
|
158
|
+
* @param args - Query parameters including credential ID
|
|
159
|
+
* @returns Promise resolving to status list entry or undefined
|
|
160
|
+
*/
|
|
90
161
|
getStatusListEntryByCredentialId(args: IGetStatusListEntryByCredentialIdArgs): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity | undefined>;
|
|
162
|
+
/**
|
|
163
|
+
* Retrieves a status list entry by index
|
|
164
|
+
* @param args - Query parameters including status list index
|
|
165
|
+
* @returns Promise resolving to status list entry or undefined
|
|
166
|
+
*/
|
|
91
167
|
getStatusListEntryByIndex(args: IGetStatusListEntryByIndexArgs): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity | undefined>;
|
|
168
|
+
/**
|
|
169
|
+
* Generates a random available index for new status list entries
|
|
170
|
+
* @param args - Optional correlation ID parameter
|
|
171
|
+
* @returns Promise resolving to available index number
|
|
172
|
+
*/
|
|
92
173
|
getRandomNewStatusListIndex(args?: {
|
|
93
174
|
correlationId?: string;
|
|
94
175
|
}): Promise<number>;
|
|
176
|
+
/**
|
|
177
|
+
* Implementation for generating random status list indices with retry logic
|
|
178
|
+
* @param tries - Number of attempts made
|
|
179
|
+
* @param args - Optional correlation ID parameter
|
|
180
|
+
* @returns Promise resolving to available index or -1 if none found
|
|
181
|
+
*/
|
|
95
182
|
private getRandomNewStatusListIndexImpl;
|
|
183
|
+
/**
|
|
184
|
+
* Gets the length of the status list
|
|
185
|
+
* @param args - Optional correlation ID parameter
|
|
186
|
+
* @returns Promise resolving to status list length
|
|
187
|
+
*/
|
|
96
188
|
getStatusListLength(args?: {
|
|
97
189
|
correlationId?: string;
|
|
98
190
|
}): Promise<number>;
|
|
191
|
+
/**
|
|
192
|
+
* Retrieves the status list details
|
|
193
|
+
* @param args - Optional correlation ID parameter
|
|
194
|
+
* @returns Promise resolving to StatusListResult
|
|
195
|
+
*/
|
|
99
196
|
getStatusList(args?: {
|
|
100
197
|
correlationId?: string;
|
|
101
198
|
}): Promise<StatusListResult>;
|
|
199
|
+
/**
|
|
200
|
+
* Retrieves all status lists
|
|
201
|
+
* @returns Promise resolving to array of StatusListResult
|
|
202
|
+
*/
|
|
102
203
|
getStatusLists(): Promise<Array<StatusListResult>>;
|
|
204
|
+
/**
|
|
205
|
+
* Checks if a status list index is currently in use
|
|
206
|
+
* @returns Promise resolving to boolean indicating usage status
|
|
207
|
+
*/
|
|
103
208
|
isStatusListIndexInUse(): Promise<boolean>;
|
|
104
209
|
}
|
|
105
210
|
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,9 @@ import { IVcdmCredentialPlugin } from '@sphereon/ssi-sdk.credential-vcdm';
|
|
|
26
26
|
* @since 2024
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Configuration options for status list management
|
|
31
|
+
*/
|
|
29
32
|
interface StatusListManagementOptions {
|
|
30
33
|
id?: string;
|
|
31
34
|
correlationId?: string;
|
|
@@ -33,17 +36,33 @@ interface StatusListManagementOptions {
|
|
|
33
36
|
driverOptions?: DriverOptions;
|
|
34
37
|
}
|
|
35
38
|
type DriverOptions = TypeORMOptions;
|
|
39
|
+
/**
|
|
40
|
+
* TypeORM-specific configuration options
|
|
41
|
+
*/
|
|
36
42
|
interface TypeORMOptions {
|
|
37
43
|
dbName?: string;
|
|
38
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Filesystem-specific configuration options
|
|
47
|
+
*/
|
|
39
48
|
interface FilesystemOptions {
|
|
40
49
|
path: string;
|
|
41
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Creates status list management options for TypeORM driver
|
|
53
|
+
* @param args - Configuration parameters including id, correlationId, and database name
|
|
54
|
+
* @returns StatusListManagementOptions configured for TypeORM
|
|
55
|
+
*/
|
|
42
56
|
declare function getOptions(args: {
|
|
43
57
|
id?: string;
|
|
44
58
|
correlationId?: string;
|
|
45
59
|
dbName: string;
|
|
46
60
|
}): StatusListManagementOptions;
|
|
61
|
+
/**
|
|
62
|
+
* Creates and initializes a status list driver instance
|
|
63
|
+
* @param args - Configuration parameters including database connection details
|
|
64
|
+
* @returns Promise resolving to initialized IStatusListDriver instance
|
|
65
|
+
*/
|
|
47
66
|
declare function getDriver(args: {
|
|
48
67
|
id?: string;
|
|
49
68
|
correlationId?: string;
|
|
@@ -62,15 +81,48 @@ declare class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
62
81
|
private _statusListStore;
|
|
63
82
|
private options;
|
|
64
83
|
private _statusListLength;
|
|
84
|
+
/**
|
|
85
|
+
* Creates a new AgentDataSourceStatusListDriver instance
|
|
86
|
+
* @param _dataSource - TypeORM DataSource for database operations
|
|
87
|
+
* @param _statusListStore - StatusListStore for data persistence
|
|
88
|
+
* @param options - Driver configuration options
|
|
89
|
+
*/
|
|
65
90
|
constructor(_dataSource: DataSource, _statusListStore: StatusListStore, options: StatusListManagementOptions);
|
|
91
|
+
/**
|
|
92
|
+
* Initializes and creates a new AgentDataSourceStatusListDriver instance
|
|
93
|
+
* @param options - Status list management configuration
|
|
94
|
+
* @param dbArgs - Database connection arguments
|
|
95
|
+
* @returns Promise resolving to initialized driver instance
|
|
96
|
+
*/
|
|
66
97
|
static init(options: StatusListManagementOptions, dbArgs?: {
|
|
67
98
|
dataSources?: DataSources;
|
|
68
99
|
dataSource?: DataSource;
|
|
69
100
|
}): Promise<AgentDataSourceStatusListDriver>;
|
|
101
|
+
/**
|
|
102
|
+
* Gets the TypeORM DataSource instance
|
|
103
|
+
* @returns DataSource instance for database operations
|
|
104
|
+
*/
|
|
70
105
|
get dataSource(): DataSource;
|
|
106
|
+
/**
|
|
107
|
+
* Gets the StatusListStore instance
|
|
108
|
+
* @returns StatusListStore for data persistence operations
|
|
109
|
+
*/
|
|
71
110
|
get statusListStore(): StatusListStore;
|
|
111
|
+
/**
|
|
112
|
+
* Gets the driver configuration options
|
|
113
|
+
* @returns DriverOptions configuration
|
|
114
|
+
*/
|
|
72
115
|
getOptions(): DriverOptions;
|
|
116
|
+
/**
|
|
117
|
+
* Gets the driver type
|
|
118
|
+
* @returns StatusListDriverType enum value
|
|
119
|
+
*/
|
|
73
120
|
getType(): StatusListDriverType;
|
|
121
|
+
/**
|
|
122
|
+
* Creates a new status list credential and stores it in the database
|
|
123
|
+
* @param args - Status list creation parameters
|
|
124
|
+
* @returns Promise resolving to StatusListResult
|
|
125
|
+
*/
|
|
74
126
|
createStatusList(args: {
|
|
75
127
|
statusListType: StatusListType;
|
|
76
128
|
statusListCredential: StatusListCredential;
|
|
@@ -78,28 +130,81 @@ declare class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
78
130
|
credentialIdMode?: StatusListCredentialIdMode;
|
|
79
131
|
bitsPerStatus?: number;
|
|
80
132
|
}): Promise<StatusListResult>;
|
|
133
|
+
/**
|
|
134
|
+
* Updates an existing status list credential in the database
|
|
135
|
+
* @param args - Status list update parameters
|
|
136
|
+
* @returns Promise resolving to StatusListResult
|
|
137
|
+
*/
|
|
81
138
|
updateStatusList(args: {
|
|
82
139
|
statusListCredential: StatusListCredential;
|
|
83
140
|
correlationId: string;
|
|
84
141
|
}): Promise<StatusListResult>;
|
|
142
|
+
/**
|
|
143
|
+
* Deletes the status list from the database
|
|
144
|
+
* @returns Promise resolving to boolean indicating success
|
|
145
|
+
*/
|
|
85
146
|
deleteStatusList(): Promise<boolean>;
|
|
147
|
+
/**
|
|
148
|
+
* Updates a status list entry and returns the credential status
|
|
149
|
+
* @param args - Status list entry update parameters
|
|
150
|
+
* @returns Promise resolving to credential status and entry
|
|
151
|
+
*/
|
|
86
152
|
updateStatusListEntry(args: IAddStatusListEntryArgs): Promise<{
|
|
87
153
|
credentialStatus: StatusList2021EntryCredentialStatus | StatusListOAuthEntryCredentialStatus | BitstringStatusListEntryCredentialStatus;
|
|
88
154
|
statusListEntry: IStatusListEntryEntity | IBitstringStatusListEntryEntity;
|
|
89
155
|
}>;
|
|
156
|
+
/**
|
|
157
|
+
* Retrieves a status list entry by credential ID
|
|
158
|
+
* @param args - Query parameters including credential ID
|
|
159
|
+
* @returns Promise resolving to status list entry or undefined
|
|
160
|
+
*/
|
|
90
161
|
getStatusListEntryByCredentialId(args: IGetStatusListEntryByCredentialIdArgs): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity | undefined>;
|
|
162
|
+
/**
|
|
163
|
+
* Retrieves a status list entry by index
|
|
164
|
+
* @param args - Query parameters including status list index
|
|
165
|
+
* @returns Promise resolving to status list entry or undefined
|
|
166
|
+
*/
|
|
91
167
|
getStatusListEntryByIndex(args: IGetStatusListEntryByIndexArgs): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity | undefined>;
|
|
168
|
+
/**
|
|
169
|
+
* Generates a random available index for new status list entries
|
|
170
|
+
* @param args - Optional correlation ID parameter
|
|
171
|
+
* @returns Promise resolving to available index number
|
|
172
|
+
*/
|
|
92
173
|
getRandomNewStatusListIndex(args?: {
|
|
93
174
|
correlationId?: string;
|
|
94
175
|
}): Promise<number>;
|
|
176
|
+
/**
|
|
177
|
+
* Implementation for generating random status list indices with retry logic
|
|
178
|
+
* @param tries - Number of attempts made
|
|
179
|
+
* @param args - Optional correlation ID parameter
|
|
180
|
+
* @returns Promise resolving to available index or -1 if none found
|
|
181
|
+
*/
|
|
95
182
|
private getRandomNewStatusListIndexImpl;
|
|
183
|
+
/**
|
|
184
|
+
* Gets the length of the status list
|
|
185
|
+
* @param args - Optional correlation ID parameter
|
|
186
|
+
* @returns Promise resolving to status list length
|
|
187
|
+
*/
|
|
96
188
|
getStatusListLength(args?: {
|
|
97
189
|
correlationId?: string;
|
|
98
190
|
}): Promise<number>;
|
|
191
|
+
/**
|
|
192
|
+
* Retrieves the status list details
|
|
193
|
+
* @param args - Optional correlation ID parameter
|
|
194
|
+
* @returns Promise resolving to StatusListResult
|
|
195
|
+
*/
|
|
99
196
|
getStatusList(args?: {
|
|
100
197
|
correlationId?: string;
|
|
101
198
|
}): Promise<StatusListResult>;
|
|
199
|
+
/**
|
|
200
|
+
* Retrieves all status lists
|
|
201
|
+
* @returns Promise resolving to array of StatusListResult
|
|
202
|
+
*/
|
|
102
203
|
getStatusLists(): Promise<Array<StatusListResult>>;
|
|
204
|
+
/**
|
|
205
|
+
* Checks if a status list index is currently in use
|
|
206
|
+
* @returns Promise resolving to boolean indicating usage status
|
|
207
|
+
*/
|
|
103
208
|
isStatusListIndexInUse(): Promise<boolean>;
|
|
104
209
|
}
|
|
105
210
|
|
package/dist/index.js
CHANGED
|
@@ -92,11 +92,23 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
92
92
|
_statusListStore;
|
|
93
93
|
options;
|
|
94
94
|
_statusListLength;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a new AgentDataSourceStatusListDriver instance
|
|
97
|
+
* @param _dataSource - TypeORM DataSource for database operations
|
|
98
|
+
* @param _statusListStore - StatusListStore for data persistence
|
|
99
|
+
* @param options - Driver configuration options
|
|
100
|
+
*/
|
|
95
101
|
constructor(_dataSource, _statusListStore, options) {
|
|
96
102
|
this._dataSource = _dataSource;
|
|
97
103
|
this._statusListStore = _statusListStore;
|
|
98
104
|
this.options = options;
|
|
99
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Initializes and creates a new AgentDataSourceStatusListDriver instance
|
|
108
|
+
* @param options - Status list management configuration
|
|
109
|
+
* @param dbArgs - Database connection arguments
|
|
110
|
+
* @returns Promise resolving to initialized driver instance
|
|
111
|
+
*/
|
|
100
112
|
static async init(options, dbArgs) {
|
|
101
113
|
if (options.driverType !== StatusListDriverType.AGENT_TYPEORM) {
|
|
102
114
|
throw Error(`TypeORM driver can only be used when the TypeORM driver type is selected in the configuration. Got: ${options.driverType}`);
|
|
@@ -119,24 +131,45 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
119
131
|
statusListStore = new StatusListStore(dataSource);
|
|
120
132
|
return new _AgentDataSourceStatusListDriver(dataSource, statusListStore, options);
|
|
121
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Gets the TypeORM DataSource instance
|
|
136
|
+
* @returns DataSource instance for database operations
|
|
137
|
+
*/
|
|
122
138
|
get dataSource() {
|
|
123
139
|
if (!this._dataSource) {
|
|
124
140
|
throw Error(`Datasource not available yet for ${this.options.driverOptions?.dbName}`);
|
|
125
141
|
}
|
|
126
142
|
return this._dataSource;
|
|
127
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Gets the StatusListStore instance
|
|
146
|
+
* @returns StatusListStore for data persistence operations
|
|
147
|
+
*/
|
|
128
148
|
get statusListStore() {
|
|
129
149
|
if (!this._statusListStore) {
|
|
130
150
|
this._statusListStore = new StatusListStore(this.dataSource);
|
|
131
151
|
}
|
|
132
152
|
return this._statusListStore;
|
|
133
153
|
}
|
|
154
|
+
/**
|
|
155
|
+
* Gets the driver configuration options
|
|
156
|
+
* @returns DriverOptions configuration
|
|
157
|
+
*/
|
|
134
158
|
getOptions() {
|
|
135
159
|
return this.options.driverOptions ?? {};
|
|
136
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Gets the driver type
|
|
163
|
+
* @returns StatusListDriverType enum value
|
|
164
|
+
*/
|
|
137
165
|
getType() {
|
|
138
166
|
return this.options.driverType;
|
|
139
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Creates a new status list credential and stores it in the database
|
|
170
|
+
* @param args - Status list creation parameters
|
|
171
|
+
* @returns Promise resolving to StatusListResult
|
|
172
|
+
*/
|
|
140
173
|
async createStatusList(args) {
|
|
141
174
|
const correlationId = args.correlationId ?? this.options.correlationId;
|
|
142
175
|
if (!correlationId) {
|
|
@@ -160,6 +193,11 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
160
193
|
this._statusListLength = implementationResult.length;
|
|
161
194
|
return implementationResult;
|
|
162
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Updates an existing status list credential in the database
|
|
198
|
+
* @param args - Status list update parameters
|
|
199
|
+
* @returns Promise resolving to StatusListResult
|
|
200
|
+
*/
|
|
163
201
|
async updateStatusList(args) {
|
|
164
202
|
const correlationId = args.correlationId ?? this.options.correlationId;
|
|
165
203
|
const extractedDetails = await extractCredentialDetails(args.statusListCredential);
|
|
@@ -188,6 +226,10 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
188
226
|
...details
|
|
189
227
|
};
|
|
190
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Deletes the status list from the database
|
|
231
|
+
* @returns Promise resolving to boolean indicating success
|
|
232
|
+
*/
|
|
191
233
|
async deleteStatusList() {
|
|
192
234
|
await this.statusListStore.removeStatusList({
|
|
193
235
|
id: this.options.id,
|
|
@@ -195,6 +237,11 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
195
237
|
});
|
|
196
238
|
return Promise.resolve(true);
|
|
197
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Updates a status list entry and returns the credential status
|
|
242
|
+
* @param args - Status list entry update parameters
|
|
243
|
+
* @returns Promise resolving to credential status and entry
|
|
244
|
+
*/
|
|
198
245
|
async updateStatusListEntry(args) {
|
|
199
246
|
const statusListEntity = statusListResultToEntity(await this.getStatusList());
|
|
200
247
|
const statusListEntry = await this.statusListStore.updateStatusListEntry({
|
|
@@ -211,12 +258,27 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
211
258
|
statusListEntry
|
|
212
259
|
};
|
|
213
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Retrieves a status list entry by credential ID
|
|
263
|
+
* @param args - Query parameters including credential ID
|
|
264
|
+
* @returns Promise resolving to status list entry or undefined
|
|
265
|
+
*/
|
|
214
266
|
async getStatusListEntryByCredentialId(args) {
|
|
215
267
|
return await this.statusListStore.getStatusListEntryByCredentialId(args);
|
|
216
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Retrieves a status list entry by index
|
|
271
|
+
* @param args - Query parameters including status list index
|
|
272
|
+
* @returns Promise resolving to status list entry or undefined
|
|
273
|
+
*/
|
|
217
274
|
async getStatusListEntryByIndex(args) {
|
|
218
275
|
return await this.statusListStore.getStatusListEntryByIndex(args);
|
|
219
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Generates a random available index for new status list entries
|
|
279
|
+
* @param args - Optional correlation ID parameter
|
|
280
|
+
* @returns Promise resolving to available index number
|
|
281
|
+
*/
|
|
220
282
|
async getRandomNewStatusListIndex(args) {
|
|
221
283
|
let result = -1;
|
|
222
284
|
let tries = 0;
|
|
@@ -225,6 +287,12 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
225
287
|
}
|
|
226
288
|
return result;
|
|
227
289
|
}
|
|
290
|
+
/**
|
|
291
|
+
* Implementation for generating random status list indices with retry logic
|
|
292
|
+
* @param tries - Number of attempts made
|
|
293
|
+
* @param args - Optional correlation ID parameter
|
|
294
|
+
* @returns Promise resolving to available index or -1 if none found
|
|
295
|
+
*/
|
|
228
296
|
async getRandomNewStatusListIndexImpl(tries, args) {
|
|
229
297
|
const statusListId = this.options.id;
|
|
230
298
|
const correlationId = args?.correlationId ?? this.options.correlationId;
|
|
@@ -247,12 +315,22 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
247
315
|
}
|
|
248
316
|
return -1;
|
|
249
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Gets the length of the status list
|
|
320
|
+
* @param args - Optional correlation ID parameter
|
|
321
|
+
* @returns Promise resolving to status list length
|
|
322
|
+
*/
|
|
250
323
|
async getStatusListLength(args) {
|
|
251
324
|
if (!this._statusListLength) {
|
|
252
325
|
this._statusListLength = await this.getStatusList(args).then((details) => details.length);
|
|
253
326
|
}
|
|
254
327
|
return this._statusListLength;
|
|
255
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* Retrieves the status list details
|
|
331
|
+
* @param args - Optional correlation ID parameter
|
|
332
|
+
* @returns Promise resolving to StatusListResult
|
|
333
|
+
*/
|
|
256
334
|
async getStatusList(args) {
|
|
257
335
|
const id = this.options.id;
|
|
258
336
|
const correlationId = args?.correlationId ?? this.options.correlationId;
|
|
@@ -268,6 +346,10 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
268
346
|
driverType: statusListEntity.driverType
|
|
269
347
|
});
|
|
270
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* Retrieves all status lists
|
|
351
|
+
* @returns Promise resolving to array of StatusListResult
|
|
352
|
+
*/
|
|
271
353
|
async getStatusLists() {
|
|
272
354
|
const statusLists = await this.statusListStore.getStatusLists({});
|
|
273
355
|
return Promise.all(statusLists.map(async (statusListEntity) => {
|
|
@@ -280,6 +362,10 @@ var AgentDataSourceStatusListDriver = class _AgentDataSourceStatusListDriver {
|
|
|
280
362
|
});
|
|
281
363
|
}));
|
|
282
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* Checks if a status list index is currently in use
|
|
367
|
+
* @returns Promise resolving to boolean indicating usage status
|
|
368
|
+
*/
|
|
283
369
|
isStatusListIndexInUse() {
|
|
284
370
|
return Promise.resolve(false);
|
|
285
371
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/drivers.ts","../src/status-list-adapters.ts"],"sourcesContent":["/**\n * StatusList Driver Implementation for TypeORM/Agent Data Sources\n *\n * This module provides the database-backed implementation of the IStatusListDriver interface,\n * handling persistence and retrieval of status list credentials and entries using TypeORM.\n * It delegates status list format-specific operations to the functions layer while managing\n * database interactions, driver configuration, and entity lifecycle.\n *\n * Key responsibilities:\n * - Database connection and store management\n * - Status list CRUD operations\n * - Status list entry management\n * - Random index generation for new entries\n * - Integration with multiple data sources\n *\n * @author Sphereon International B.V.\n * @since 2024\n */\n\nimport { DataSources } from '@sphereon/ssi-sdk.agent-config'\nimport {\n BitstringStatusListEntryCredentialStatus,\n IAddStatusListArgs,\n IAddStatusListEntryArgs,\n IBitstringStatusListEntryEntity,\n IGetStatusListEntryByCredentialIdArgs,\n IGetStatusListEntryByIndexArgs,\n IStatusListEntryEntity,\n StatusListEntity,\n StatusListStore,\n} from '@sphereon/ssi-sdk.data-store'\nimport {\n createCredentialStatusFromStatusList,\n extractCredentialDetails,\n StatusList2021EntryCredentialStatus,\n StatusListOAuthEntryCredentialStatus,\n StatusListResult,\n toStatusListDetails,\n} from '@sphereon/ssi-sdk.vc-status-list'\nimport { StatusListCredential, StatusListCredentialIdMode, StatusListDriverType, StatusListType } from '@sphereon/ssi-types'\nimport { DataSource } from 'typeorm'\nimport { IStatusListDriver } from './types'\nimport { statusListResultToEntity } from './status-list-adapters'\n\nexport interface StatusListManagementOptions {\n id?: string\n correlationId?: string\n driverType: StatusListDriverType\n driverOptions?: DriverOptions\n}\n\nexport type DriverOptions = TypeORMOptions\n\nexport interface TypeORMOptions {\n dbName?: string\n}\n\nexport interface FilesystemOptions {\n path: string // The base path where statusList Credentials will be persisted. Should be a folder and thus not include the VC/StatusList itself\n}\n\nexport function getOptions(args: { id?: string; correlationId?: string; dbName: string }): StatusListManagementOptions {\n return {\n id: args.id,\n correlationId: args.correlationId,\n driverType: StatusListDriverType.AGENT_TYPEORM,\n driverOptions: { dbName: args.dbName },\n }\n}\n\nexport async function getDriver(args: {\n id?: string\n correlationId?: string\n dbName?: string\n dataSource?: DataSource\n dataSources?: DataSources\n}): Promise<IStatusListDriver> {\n const dbName = args.dbName ?? args.dataSource?.name\n if (!dbName) {\n throw Error(`Please provide either a DB name or data source`)\n }\n const dataSources = args.dataSources ?? DataSources.singleInstance()\n return await AgentDataSourceStatusListDriver.init(\n getOptions({\n ...args,\n dbName,\n }),\n { dataSource: args.dataSource ?? (await dataSources.getDbConnection(dbName)), dataSources },\n )\n}\n\n/**\n * TypeORM-based implementation of the IStatusListDriver interface\n *\n * Manages status list credentials and entries using a TypeORM data source.\n * Handles database operations while delegating format-specific logic to the functions layer.\n */\nexport class AgentDataSourceStatusListDriver implements IStatusListDriver {\n private _statusListLength: number | undefined\n\n constructor(\n private _dataSource: DataSource,\n private _statusListStore: StatusListStore,\n private options: StatusListManagementOptions,\n ) {}\n\n public static async init(\n options: StatusListManagementOptions,\n dbArgs?: {\n dataSources?: DataSources\n dataSource?: DataSource\n },\n ): Promise<AgentDataSourceStatusListDriver> {\n if (options.driverType !== StatusListDriverType.AGENT_TYPEORM) {\n throw Error(`TypeORM driver can only be used when the TypeORM driver type is selected in the configuration. Got: ${options.driverType}`)\n } else if (!options.driverOptions) {\n throw Error(`TypeORM driver can only be used when the TypeORM options are provided.`)\n }\n let dataSource: DataSource\n let statusListStore: StatusListStore\n if (dbArgs?.dataSource) {\n dataSource = dbArgs.dataSource\n } else if (options.driverOptions.dbName) {\n if (dbArgs?.dataSources) {\n dataSource = await dbArgs.dataSources.getDbConnection(options.driverOptions.dbName)\n } else {\n dataSource = await DataSources.singleInstance().getDbConnection(options.driverOptions.dbName)\n }\n } else {\n return Promise.reject(Error(`Either a datasource or dbName needs to be provided`))\n }\n\n statusListStore = new StatusListStore(dataSource)\n return new AgentDataSourceStatusListDriver(dataSource, statusListStore, options)\n }\n\n get dataSource(): DataSource {\n if (!this._dataSource) {\n throw Error(`Datasource not available yet for ${this.options.driverOptions?.dbName}`)\n }\n return this._dataSource\n }\n\n get statusListStore(): StatusListStore {\n if (!this._statusListStore) {\n this._statusListStore = new StatusListStore(this.dataSource)\n }\n return this._statusListStore\n }\n\n getOptions(): DriverOptions {\n return this.options.driverOptions ?? {}\n }\n\n getType(): StatusListDriverType {\n return this.options.driverType\n }\n\n async createStatusList(args: {\n statusListType: StatusListType\n statusListCredential: StatusListCredential\n correlationId?: string\n credentialIdMode?: StatusListCredentialIdMode\n bitsPerStatus?: number\n }): Promise<StatusListResult> {\n const correlationId = args.correlationId ?? this.options.correlationId\n if (!correlationId) {\n throw Error('Either a correlationId needs to be set as an option, or it needs to be provided when creating a status list. None found')\n }\n const credentialIdMode = args.credentialIdMode ?? StatusListCredentialIdMode.ISSUANCE\n\n // Convert credential to implementation details using CREATE/READ context\n const implementationResult = await toStatusListDetails({\n statusListCredential: args.statusListCredential,\n statusListType: args.statusListType,\n bitsPerStatus: args.bitsPerStatus,\n correlationId,\n driverType: this.getType(),\n })\n\n // Add driver-specific fields to create complete entity\n const statusListArgs = {\n ...implementationResult,\n credentialIdMode,\n correlationId,\n driverType: this.getType(),\n } as IAddStatusListArgs\n\n await this.statusListStore.addStatusList(statusListArgs)\n this._statusListLength = implementationResult.length\n return implementationResult\n }\n\n async updateStatusList(args: { statusListCredential: StatusListCredential; correlationId: string }): Promise<StatusListResult> {\n const correlationId = args.correlationId ?? this.options.correlationId\n\n const extractedDetails = await extractCredentialDetails(args.statusListCredential)\n const entity = await this.statusListStore.getStatusList({\n id: extractedDetails.id,\n correlationId,\n })\n if (!entity) {\n throw Error(`Status list ${extractedDetails.id}, correlationId ${correlationId} could not be found`)\n }\n\n entity.statusListCredential = args.statusListCredential\n\n const details = await toStatusListDetails({\n extractedDetails,\n statusListEntity: entity,\n })\n\n // Merge details with existing entity and driver properties\n const updateArgs = {\n ...entity,\n ...details,\n correlationId,\n driverType: this.getType(),\n } as IAddStatusListArgs\n\n await this.statusListStore.updateStatusList(updateArgs)\n this._statusListLength = details.length\n return { ...entity, ...details }\n }\n\n async deleteStatusList(): Promise<boolean> {\n await this.statusListStore.removeStatusList({ id: this.options.id, correlationId: this.options.correlationId })\n return Promise.resolve(true)\n }\n\n async updateStatusListEntry(args: IAddStatusListEntryArgs): Promise<{\n credentialStatus: StatusList2021EntryCredentialStatus | StatusListOAuthEntryCredentialStatus | BitstringStatusListEntryCredentialStatus\n statusListEntry: IStatusListEntryEntity | IBitstringStatusListEntryEntity\n }> {\n // Get status list entity\n const statusListEntity: StatusListEntity = statusListResultToEntity(await this.getStatusList())\n\n // Update the entry in the store\n const statusListEntry = await this.statusListStore.updateStatusListEntry({ ...args, statusListId: statusListEntity.id })\n\n // Use implementation to create the credential status - this moves type-specific logic to implementations\n const credentialStatus = await createCredentialStatusFromStatusList({\n statusList: statusListEntity,\n statusListEntry,\n statusListIndex: statusListEntry.statusListIndex,\n })\n\n return {\n credentialStatus,\n statusListEntry,\n }\n }\n\n async getStatusListEntryByCredentialId(\n args: IGetStatusListEntryByCredentialIdArgs,\n ): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity | undefined> {\n return await this.statusListStore.getStatusListEntryByCredentialId(args)\n }\n\n async getStatusListEntryByIndex(\n args: IGetStatusListEntryByIndexArgs,\n ): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity | undefined> {\n return await this.statusListStore.getStatusListEntryByIndex(args)\n }\n\n async getRandomNewStatusListIndex(args?: { correlationId?: string }): Promise<number> {\n let result = -1\n let tries = 0\n while (result < 0) {\n // no tries guard, because we will throw an error when they are exhausted anyway\n result = await this.getRandomNewStatusListIndexImpl(tries++, args)\n }\n return result\n }\n\n private async getRandomNewStatusListIndexImpl(tries: number, args?: { correlationId?: string }): Promise<number> {\n const statusListId = this.options.id\n const correlationId = args?.correlationId ?? this.options.correlationId\n if (tries >= 10) {\n throw Error(`We could not find any random status list index that is available in the statuslist ${statusListId}`)\n }\n // TODO: Check against DB\n const length = await this.getStatusListLength(args)\n const statusListIndex = Array.from({ length: 20 }, () => Math.floor(Math.random() * length))\n const available = await this.statusListStore.availableStatusListEntries({\n statusListId,\n ...(correlationId && { correlationId }),\n statusListIndex,\n })\n if (available.length > 0) {\n return available[0] // doesn't matter we pick the first element, as they are all random anyway\n }\n return -1\n }\n\n async getStatusListLength(args?: { correlationId?: string }): Promise<number> {\n if (!this._statusListLength) {\n this._statusListLength = await this.getStatusList(args).then((details) => details.length)\n }\n return this._statusListLength!\n }\n\n async getStatusList(args?: { correlationId?: string }): Promise<StatusListResult> {\n const id = this.options.id\n const correlationId = args?.correlationId ?? this.options.correlationId\n\n const statusListEntity = await this.statusListStore.getStatusList({ id, correlationId })\n\n // Convert entity to result using CREATE/READ context\n return await toStatusListDetails({\n statusListCredential: statusListEntity.statusListCredential!,\n statusListType: statusListEntity.type,\n bitsPerStatus: statusListEntity.bitsPerStatus,\n correlationId: statusListEntity.correlationId,\n driverType: statusListEntity.driverType,\n })\n }\n\n async getStatusLists(): Promise<Array<StatusListResult>> {\n const statusLists = await this.statusListStore.getStatusLists({})\n return Promise.all(\n statusLists.map(async (statusListEntity) => {\n return toStatusListDetails({\n statusListCredential: statusListEntity.statusListCredential!,\n statusListType: statusListEntity.type,\n bitsPerStatus: statusListEntity.bitsPerStatus,\n correlationId: statusListEntity.correlationId,\n driverType: statusListEntity.driverType,\n })\n }),\n )\n }\n\n isStatusListIndexInUse(): Promise<boolean> {\n return Promise.resolve(false)\n }\n}\n","import { StatusListType } from '@sphereon/ssi-types'\nimport { BitstringStatusListEntity, OAuthStatusListEntity, StatusList2021Entity } from '@sphereon/ssi-sdk.data-store'\nimport { StatusListResult } from '@sphereon/ssi-sdk.vc-status-list'\n\nexport function statusListResultToEntity(result: StatusListResult): StatusList2021Entity | OAuthStatusListEntity | BitstringStatusListEntity {\n const baseFields = {\n id: result.id,\n correlationId: result.correlationId,\n driverType: result.driverType,\n credentialIdMode: result.credentialIdMode,\n length: result.length,\n issuer: result.issuer,\n type: result.type,\n proofFormat: result.proofFormat,\n statusListCredential: result.statusListCredential,\n }\n\n if (result.type === StatusListType.StatusList2021) {\n if (!result.statusList2021) {\n throw new Error('Missing statusList2021 details')\n }\n return Object.assign(new StatusList2021Entity(), {\n ...baseFields,\n indexingDirection: result.statusList2021.indexingDirection,\n statusPurpose: result.statusList2021.statusPurpose,\n })\n } else if (result.type === StatusListType.OAuthStatusList) {\n if (!result.oauthStatusList) {\n throw new Error('Missing oauthStatusList details')\n }\n return Object.assign(new OAuthStatusListEntity(), {\n ...baseFields,\n bitsPerStatus: result.oauthStatusList.bitsPerStatus,\n expiresAt: result.oauthStatusList.expiresAt,\n })\n } else if (result.type === StatusListType.BitstringStatusList) {\n if (!result.bitstringStatusList) {\n throw new Error('Missing bitstringStatusList details')\n }\n return Object.assign(new BitstringStatusListEntity(), {\n ...baseFields,\n statusPurpose: result.bitstringStatusList.statusPurpose,\n ttl: result.bitstringStatusList.ttl,\n bitsPerStatus: result.bitstringStatusList.bitsPerStatus,\n validFrom: result.bitstringStatusList.validFrom,\n validUntil: result.bitstringStatusList.validUntil,\n })\n }\n throw new Error(`Unsupported status list type: ${result.type}`)\n}\n"],"mappings":";;;;AAmBA,SAASA,mBAAmB;AAC5B,SASEC,uBACK;AACP,SACEC,sCACAC,0BAIAC,2BACK;AACP,SAA+BC,4BAA4BC,4BAA4C;;;ACvCvG,SAASC,sBAAsB;AAC/B,SAASC,2BAA2BC,uBAAuBC,4BAA4B;AAGhF,SAASC,yBAAyBC,QAAwB;AAC/D,QAAMC,aAAa;IACjBC,IAAIF,OAAOE;IACXC,eAAeH,OAAOG;IACtBC,YAAYJ,OAAOI;IACnBC,kBAAkBL,OAAOK;IACzBC,QAAQN,OAAOM;IACfC,QAAQP,OAAOO;IACfC,MAAMR,OAAOQ;IACbC,aAAaT,OAAOS;IACpBC,sBAAsBV,OAAOU;EAC/B;AAEA,MAAIV,OAAOQ,SAASG,eAAeC,gBAAgB;AACjD,QAAI,CAACZ,OAAOa,gBAAgB;AAC1B,YAAM,IAAIC,MAAM,gCAAA;IAClB;AACA,WAAOC,OAAOC,OAAO,IAAIC,qBAAAA,GAAwB;MAC/C,GAAGhB;MACHiB,mBAAmBl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atusFromStatusList","extractCredentialDetails","toStatusListDetails","StatusListCredentialIdMode","StatusListDriverType","StatusListType","BitstringStatusListEntity","OAuthStatusListEntity","StatusList2021Entity","statusListResultToEntity","result","baseFields","id","correlationId","driverType","credentialIdMode","length","issuer","type","proofFormat","statusListCredential","StatusListType","StatusList2021","statusList2021","Error","Object","assign","StatusList2021Entity","indexingDirection","statusPurpose","OAuthStatusList","oauthStatusList","OAuthStatusListEntity","bitsPerStatus","expiresAt","BitstringStatusList","bitstringStatusList","BitstringStatusListEntity","ttl","validFrom","validUntil","getOptions","args","id","correlationId","driverType","StatusListDriverType","AGENT_TYPEORM","driverOptions","dbName","getDriver","dataSource","name","Error","dataSources","DataSources","singleInstance","AgentDataSourceStatusListDriver","init","getDbConnection","_statusListLength","constructor","_dataSource","_statusListStore","options","dbArgs","statusListStore","Promise","reject","StatusListStore","getType","createStatusList","credentialIdMode","StatusListCredentialIdMode","ISSUANCE","implementationResult","toStatusListDetails","statusListCredential","statusListType","bitsPerStatus","statusListArgs","addStatusList","length","updateStatusList","extractedDetails","extractCredentialDetails","entity","getStatusList","details","statusListEntity","updateArgs","deleteStatusList","removeStatusList","resolve","updateStatusListEntry","statusListResultToEntity","statusListEntry","statusListId","credentialStatus","createCredentialStatusFromStatusList","statusList","statusListIndex","getStatusListEntryByCredentialId","getStatusListEntryByIndex","getRandomNewStatusListIndex","result","tries","getRandomNewStatusListIndexImpl","getStatusListLength","Array","from","Math","floor","random","available","availableStatusListEntries","then","type","getStatusLists","statusLists","all","map","isStatusListIndexInUse"]}
|
|
1
|
+
{"version":3,"sources":["../src/drivers.ts","../src/status-list-adapters.ts"],"sourcesContent":["/**\n * StatusList Driver Implementation for TypeORM/Agent Data Sources\n *\n * This module provides the database-backed implementation of the IStatusListDriver interface,\n * handling persistence and retrieval of status list credentials and entries using TypeORM.\n * It delegates status list format-specific operations to the functions layer while managing\n * database interactions, driver configuration, and entity lifecycle.\n *\n * Key responsibilities:\n * - Database connection and store management\n * - Status list CRUD operations\n * - Status list entry management\n * - Random index generation for new entries\n * - Integration with multiple data sources\n *\n * @author Sphereon International B.V.\n * @since 2024\n */\n\nimport { DataSources } from '@sphereon/ssi-sdk.agent-config'\nimport {\n BitstringStatusListEntryCredentialStatus,\n IAddStatusListArgs,\n IAddStatusListEntryArgs,\n IBitstringStatusListEntryEntity,\n IGetStatusListEntryByCredentialIdArgs,\n IGetStatusListEntryByIndexArgs,\n IStatusListEntryEntity,\n StatusListEntity,\n StatusListStore,\n} from '@sphereon/ssi-sdk.data-store'\nimport {\n createCredentialStatusFromStatusList,\n extractCredentialDetails,\n StatusList2021EntryCredentialStatus,\n StatusListOAuthEntryCredentialStatus,\n StatusListResult,\n toStatusListDetails,\n} from '@sphereon/ssi-sdk.vc-status-list'\nimport { StatusListCredential, StatusListCredentialIdMode, StatusListDriverType, StatusListType } from '@sphereon/ssi-types'\nimport { DataSource } from 'typeorm'\nimport { IStatusListDriver } from './types'\nimport { statusListResultToEntity } from './status-list-adapters'\n\n/**\n * Configuration options for status list management\n */\nexport interface StatusListManagementOptions {\n id?: string\n correlationId?: string\n driverType: StatusListDriverType\n driverOptions?: DriverOptions\n}\n\nexport type DriverOptions = TypeORMOptions\n\n/**\n * TypeORM-specific configuration options\n */\nexport interface TypeORMOptions {\n dbName?: string\n}\n\n/**\n * Filesystem-specific configuration options\n */\nexport interface FilesystemOptions {\n path: string // The base path where statusList Credentials will be persisted. Should be a folder and thus not include the VC/StatusList itself\n}\n\n/**\n * Creates status list management options for TypeORM driver\n * @param args - Configuration parameters including id, correlationId, and database name\n * @returns StatusListManagementOptions configured for TypeORM\n */\nexport function getOptions(args: { id?: string; correlationId?: string; dbName: string }): StatusListManagementOptions {\n return {\n id: args.id,\n correlationId: args.correlationId,\n driverType: StatusListDriverType.AGENT_TYPEORM,\n driverOptions: { dbName: args.dbName },\n }\n}\n\n/**\n * Creates and initializes a status list driver instance\n * @param args - Configuration parameters including database connection details\n * @returns Promise resolving to initialized IStatusListDriver instance\n */\nexport async function getDriver(args: {\n id?: string\n correlationId?: string\n dbName?: string\n dataSource?: DataSource\n dataSources?: DataSources\n}): Promise<IStatusListDriver> {\n const dbName = args.dbName ?? args.dataSource?.name\n if (!dbName) {\n throw Error(`Please provide either a DB name or data source`)\n }\n const dataSources = args.dataSources ?? DataSources.singleInstance()\n return await AgentDataSourceStatusListDriver.init(\n getOptions({\n ...args,\n dbName,\n }),\n { dataSource: args.dataSource ?? (await dataSources.getDbConnection(dbName)), dataSources },\n )\n}\n\n/**\n * TypeORM-based implementation of the IStatusListDriver interface\n *\n * Manages status list credentials and entries using a TypeORM data source.\n * Handles database operations while delegating format-specific logic to the functions layer.\n */\nexport class AgentDataSourceStatusListDriver implements IStatusListDriver {\n private _statusListLength: number | undefined\n\n /**\n * Creates a new AgentDataSourceStatusListDriver instance\n * @param _dataSource - TypeORM DataSource for database operations\n * @param _statusListStore - StatusListStore for data persistence\n * @param options - Driver configuration options\n */\n constructor(\n private _dataSource: DataSource,\n private _statusListStore: StatusListStore,\n private options: StatusListManagementOptions,\n ) {}\n\n /**\n * Initializes and creates a new AgentDataSourceStatusListDriver instance\n * @param options - Status list management configuration\n * @param dbArgs - Database connection arguments\n * @returns Promise resolving to initialized driver instance\n */\n public static async init(\n options: StatusListManagementOptions,\n dbArgs?: {\n dataSources?: DataSources\n dataSource?: DataSource\n },\n ): Promise<AgentDataSourceStatusListDriver> {\n if (options.driverType !== StatusListDriverType.AGENT_TYPEORM) {\n throw Error(`TypeORM driver can only be used when the TypeORM driver type is selected in the configuration. Got: ${options.driverType}`)\n } else if (!options.driverOptions) {\n throw Error(`TypeORM driver can only be used when the TypeORM options are provided.`)\n }\n let dataSource: DataSource\n let statusListStore: StatusListStore\n if (dbArgs?.dataSource) {\n dataSource = dbArgs.dataSource\n } else if (options.driverOptions.dbName) {\n if (dbArgs?.dataSources) {\n dataSource = await dbArgs.dataSources.getDbConnection(options.driverOptions.dbName)\n } else {\n dataSource = await DataSources.singleInstance().getDbConnection(options.driverOptions.dbName)\n }\n } else {\n return Promise.reject(Error(`Either a datasource or dbName needs to be provided`))\n }\n\n statusListStore = new StatusListStore(dataSource)\n return new AgentDataSourceStatusListDriver(dataSource, statusListStore, options)\n }\n\n /**\n * Gets the TypeORM DataSource instance\n * @returns DataSource instance for database operations\n */\n get dataSource(): DataSource {\n if (!this._dataSource) {\n throw Error(`Datasource not available yet for ${this.options.driverOptions?.dbName}`)\n }\n return this._dataSource\n }\n\n /**\n * Gets the StatusListStore instance\n * @returns StatusListStore for data persistence operations\n */\n get statusListStore(): StatusListStore {\n if (!this._statusListStore) {\n this._statusListStore = new StatusListStore(this.dataSource)\n }\n return this._statusListStore\n }\n\n /**\n * Gets the driver configuration options\n * @returns DriverOptions configuration\n */\n getOptions(): DriverOptions {\n return this.options.driverOptions ?? {}\n }\n\n /**\n * Gets the driver type\n * @returns StatusListDriverType enum value\n */\n getType(): StatusListDriverType {\n return this.options.driverType\n }\n\n /**\n * Creates a new status list credential and stores it in the database\n * @param args - Status list creation parameters\n * @returns Promise resolving to StatusListResult\n */\n async createStatusList(args: {\n statusListType: StatusListType\n statusListCredential: StatusListCredential\n correlationId?: string\n credentialIdMode?: StatusListCredentialIdMode\n bitsPerStatus?: number\n }): Promise<StatusListResult> {\n const correlationId = args.correlationId ?? this.options.correlationId\n if (!correlationId) {\n throw Error('Either a correlationId needs to be set as an option, or it needs to be provided when creating a status list. None found')\n }\n const credentialIdMode = args.credentialIdMode ?? StatusListCredentialIdMode.ISSUANCE\n\n // Convert credential to implementation details using CREATE/READ context\n const implementationResult = await toStatusListDetails({\n statusListCredential: args.statusListCredential,\n statusListType: args.statusListType,\n bitsPerStatus: args.bitsPerStatus,\n correlationId,\n driverType: this.getType(),\n })\n\n // Add driver-specific fields to create complete entity\n const statusListArgs = {\n ...implementationResult,\n credentialIdMode,\n correlationId,\n driverType: this.getType(),\n } as IAddStatusListArgs\n\n await this.statusListStore.addStatusList(statusListArgs)\n this._statusListLength = implementationResult.length\n return implementationResult\n }\n\n /**\n * Updates an existing status list credential in the database\n * @param args - Status list update parameters\n * @returns Promise resolving to StatusListResult\n */\n async updateStatusList(args: { statusListCredential: StatusListCredential; correlationId: string }): Promise<StatusListResult> {\n const correlationId = args.correlationId ?? this.options.correlationId\n\n const extractedDetails = await extractCredentialDetails(args.statusListCredential)\n const entity = await this.statusListStore.getStatusList({\n id: extractedDetails.id,\n correlationId,\n })\n if (!entity) {\n throw Error(`Status list ${extractedDetails.id}, correlationId ${correlationId} could not be found`)\n }\n\n entity.statusListCredential = args.statusListCredential\n\n const details = await toStatusListDetails({\n extractedDetails,\n statusListEntity: entity,\n })\n\n // Merge details with existing entity and driver properties\n const updateArgs = {\n ...entity,\n ...details,\n correlationId,\n driverType: this.getType(),\n } as IAddStatusListArgs\n\n await this.statusListStore.updateStatusList(updateArgs)\n this._statusListLength = details.length\n return { ...entity, ...details }\n }\n\n /**\n * Deletes the status list from the database\n * @returns Promise resolving to boolean indicating success\n */\n async deleteStatusList(): Promise<boolean> {\n await this.statusListStore.removeStatusList({ id: this.options.id, correlationId: this.options.correlationId })\n return Promise.resolve(true)\n }\n\n /**\n * Updates a status list entry and returns the credential status\n * @param args - Status list entry update parameters\n * @returns Promise resolving to credential status and entry\n */\n async updateStatusListEntry(args: IAddStatusListEntryArgs): Promise<{\n credentialStatus: StatusList2021EntryCredentialStatus | StatusListOAuthEntryCredentialStatus | BitstringStatusListEntryCredentialStatus\n statusListEntry: IStatusListEntryEntity | IBitstringStatusListEntryEntity\n }> {\n // Get status list entity\n const statusListEntity: StatusListEntity = statusListResultToEntity(await this.getStatusList())\n\n // Update the entry in the store\n const statusListEntry = await this.statusListStore.updateStatusListEntry({ ...args, statusListId: statusListEntity.id })\n\n // Use implementation to create the credential status - this moves type-specific logic to implementations\n const credentialStatus = await createCredentialStatusFromStatusList({\n statusList: statusListEntity,\n statusListEntry,\n statusListIndex: statusListEntry.statusListIndex,\n })\n\n return {\n credentialStatus,\n statusListEntry,\n }\n }\n\n /**\n * Retrieves a status list entry by credential ID\n * @param args - Query parameters including credential ID\n * @returns Promise resolving to status list entry or undefined\n */\n async getStatusListEntryByCredentialId(\n args: IGetStatusListEntryByCredentialIdArgs,\n ): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity | undefined> {\n return await this.statusListStore.getStatusListEntryByCredentialId(args)\n }\n\n /**\n * Retrieves a status list entry by index\n * @param args - Query parameters including status list index\n * @returns Promise resolving to status list entry or undefined\n */\n async getStatusListEntryByIndex(\n args: IGetStatusListEntryByIndexArgs,\n ): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity | undefined> {\n return await this.statusListStore.getStatusListEntryByIndex(args)\n }\n\n /**\n * Generates a random available index for new status list entries\n * @param args - Optional correlation ID parameter\n * @returns Promise resolving to available index number\n */\n async getRandomNewStatusListIndex(args?: { correlationId?: string }): Promise<number> {\n let result = -1\n let tries = 0\n while (result < 0) {\n // no tries guard, because we will throw an error when they are exhausted anyway\n result = await this.getRandomNewStatusListIndexImpl(tries++, args)\n }\n return result\n }\n\n /**\n * Implementation for generating random status list indices with retry logic\n * @param tries - Number of attempts made\n * @param args - Optional correlation ID parameter\n * @returns Promise resolving to available index or -1 if none found\n */\n private async getRandomNewStatusListIndexImpl(tries: number, args?: { correlationId?: string }): Promise<number> {\n const statusListId = this.options.id\n const correlationId = args?.correlationId ?? this.options.correlationId\n if (tries >= 10) {\n throw Error(`We could not find any random status list index that is available in the statuslist ${statusListId}`)\n }\n // TODO: Check against DB\n const length = await this.getStatusListLength(args)\n const statusListIndex = Array.from({ length: 20 }, () => Math.floor(Math.random() * length))\n const available = await this.statusListStore.availableStatusListEntries({\n statusListId,\n ...(correlationId && { correlationId }),\n statusListIndex,\n })\n if (available.length > 0) {\n return available[0] // doesn't matter we pick the first element, as they are all random anyway\n }\n return -1\n }\n\n /**\n * Gets the length of the status list\n * @param args - Optional correlation ID parameter\n * @returns Promise resolving to status list length\n */\n async getStatusListLength(args?: { correlationId?: string }): Promise<number> {\n if (!this._statusListLength) {\n this._statusListLength = await this.getStatusList(args).then((details) => details.length)\n }\n return this._statusListLength!\n }\n\n /**\n * Retrieves the status list details\n * @param args - Optional correlation ID parameter\n * @returns Promise resolving to StatusListResult\n */\n async getStatusList(args?: { correlationId?: string }): Promise<StatusListResult> {\n const id = this.options.id\n const correlationId = args?.correlationId ?? this.options.correlationId\n\n const statusListEntity = await this.statusListStore.getStatusList({ id, correlationId })\n\n // Convert entity to result using CREATE/READ context\n return await toStatusListDetails({\n statusListCredential: statusListEntity.statusListCredential!,\n statusListType: statusListEntity.type,\n bitsPerStatus: statusListEntity.bitsPerStatus,\n correlationId: statusListEntity.correlationId,\n driverType: statusListEntity.driverType,\n })\n }\n\n /**\n * Retrieves all status lists\n * @returns Promise resolving to array of StatusListResult\n */\n async getStatusLists(): Promise<Array<StatusListResult>> {\n const statusLists = await this.statusListStore.getStatusLists({})\n return Promise.all(\n statusLists.map(async (statusListEntity) => {\n return toStatusListDetails({\n statusListCredential: statusListEntity.statusListCredential!,\n statusListType: statusListEntity.type,\n bitsPerStatus: statusListEntity.bitsPerStatus,\n correlationId: statusListEntity.correlationId,\n driverType: statusListEntity.driverType,\n })\n }),\n )\n }\n\n /**\n * Checks if a status list index is currently in use\n * @returns Promise resolving to boolean indicating usage status\n */\n isStatusListIndexInUse(): Promise<boolean> {\n return Promise.resolve(false)\n }\n}\n","import { StatusListType } from '@sphereon/ssi-types'\nimport { BitstringStatusListEntity, OAuthStatusListEntity, StatusList2021Entity } from '@sphereon/ssi-sdk.data-store'\nimport { StatusListResult } from '@sphereon/ssi-sdk.vc-status-list'\n\nexport function statusListResultToEntity(result: StatusListResult): StatusList2021Entity | OAuthStatusListEntity | BitstringStatusListEntity {\n const baseFields = {\n id: result.id,\n correlationId: result.correlationId,\n driverType: result.driverType,\n credentialIdMode: result.credentialIdMode,\n length: result.length,\n issuer: result.issuer,\n type: result.type,\n proofFormat: result.proofFormat,\n statusListCredential: result.statusListCredential,\n }\n\n if (result.type === StatusListType.StatusList2021) {\n if (!result.statusList2021) {\n throw new Error('Missing statusList2021 details')\n }\n return Object.assign(new StatusList2021Entity(), {\n ...baseFields,\n indexingDirection: result.statusList2021.indexingDirection,\n statusPurpose: result.statusList2021.statusPurpose,\n })\n } else if (result.type === StatusListType.OAuthStatusList) {\n if (!result.oauthStatusList) {\n throw new Error('Missing oauthStatusList details')\n }\n return Object.assign(new OAuthStatusListEntity(), {\n ...baseFields,\n bitsPerStatus: result.oauthStatusList.bitsPerStatus,\n expiresAt: result.oauthStatusList.expiresAt,\n })\n } else if (result.type === StatusListType.BitstringStatusList) {\n if (!result.bitstringStatusList) {\n throw new Error('Missing bitstringStatusList details')\n }\n return Object.assign(new BitstringStatusListEntity(), {\n ...baseFields,\n statusPurpose: result.bitstringStatusList.statusPurpose,\n ttl: result.bitstringStatusList.ttl,\n bitsPerStatus: result.bitstringStatusList.bitsPerStatus,\n validFrom: result.bitstringStatusList.validFrom,\n validUntil: result.bitstringStatusList.validUntil,\n })\n }\n throw new Error(`Unsupported status list type: ${result.type}`)\n}\n"],"mappings":";;;;AAmBA,SAASA,mBAAmB;AAC5B,SASEC,uBACK;AACP,SACEC,sCACAC,0BAIAC,2BACK;AACP,SAA+BC,4BAA4BC,4BAA4C;;;ACvCvG,SAASC,sBAAsB;AAC/B,SAASC,2BAA2BC,uBAAuBC,4BAA4B;AAGhF,SAASC,yBAAyBC,QAAwB;AAC/D,QAAMC,aAAa;IACjBC,IAAIF,OAAOE;IACXC,eAAeH,OAAOG;IACtBC,YAAYJ,OAAOI;IACnBC,kBAAkBL,OAAOK;IACzBC,QAAQN,OAAOM;IACfC,QAAQP,OAAOO;IACfC,MAAMR,OAAOQ;IACbC,aAAaT,OAAOS;IACpBC,sBAAsBV,OAAOU;EAC/B;AAEA,MAAIV,OAAOQ,SAASG,eAAeC,gBAAgB;AACjD,QAAI,CAACZ,OAAOa,gBAAgB;AAC1B,YAAM,IAAIC,MAAM,gCAAA;IAClB;AACA,WAAOC,OAAOC,OAAO,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CC,YAAY4C,iBAAiB5C;MAC/B,CAAA;IACF,CAAA,CAAA;EAEJ;;;;;EAMA6E,yBAA2C;AACzC,WAAOvD,QAAQ0B,QAAQ,KAAA;EACzB;AACF;","names":["DataSources","StatusListStore","createCredentialStatusFromStatusList","extractCredentialDetails","toStatusListDetails","StatusListCredentialIdMode","StatusListDriverType","StatusListType","BitstringStatusListEntity","OAuthStatusListEntity","StatusList2021Entity","statusListResultToEntity","result","baseFields","id","correlationId","driverType","credentialIdMode","length","issuer","type","proofFormat","statusListCredential","StatusListType","StatusList2021","statusList2021","Error","Object","assign","StatusList2021Entity","indexingDirection","statusPurpose","OAuthStatusList","oauthStatusList","OAuthStatusListEntity","bitsPerStatus","expiresAt","BitstringStatusList","bitstringStatusList","BitstringStatusListEntity","ttl","validFrom","validUntil","getOptions","args","id","correlationId","driverType","StatusListDriverType","AGENT_TYPEORM","driverOptions","dbName","getDriver","dataSource","name","Error","dataSources","DataSources","singleInstance","AgentDataSourceStatusListDriver","init","getDbConnection","_statusListLength","constructor","_dataSource","_statusListStore","options","dbArgs","statusListStore","Promise","reject","StatusListStore","getType","createStatusList","credentialIdMode","StatusListCredentialIdMode","ISSUANCE","implementationResult","toStatusListDetails","statusListCredential","statusListType","bitsPerStatus","statusListArgs","addStatusList","length","updateStatusList","extractedDetails","extractCredentialDetails","entity","getStatusList","details","statusListEntity","updateArgs","deleteStatusList","removeStatusList","resolve","updateStatusListEntry","statusListResultToEntity","statusListEntry","statusListId","credentialStatus","createCredentialStatusFromStatusList","statusList","statusListIndex","getStatusListEntryByCredentialId","getStatusListEntryByIndex","getRandomNewStatusListIndex","result","tries","getRandomNewStatusListIndexImpl","getStatusListLength","Array","from","Math","floor","random","available","availableStatusListEntries","then","type","getStatusLists","statusLists","all","map","isStatusListIndexInUse"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk.vc-status-list-issuer-drivers",
|
|
3
3
|
"description": "Sphereon SSI-SDK plugin for Status List management, like StatusList2021. Issuer drivers module",
|
|
4
|
-
"version": "0.34.1-feature.SSISDK.17.bitstring.sl.
|
|
4
|
+
"version": "0.34.1-feature.SSISDK.17.bitstring.sl.16+6964608d",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"build": "tsup --config ../../tsup.config.ts --tsconfig ../../tsconfig.tsup.json"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@sphereon/ssi-express-support": "0.34.1-feature.SSISDK.17.bitstring.sl.
|
|
25
|
+
"@sphereon/ssi-express-support": "0.34.1-feature.SSISDK.17.bitstring.sl.16+6964608d",
|
|
26
26
|
"@sphereon/ssi-sdk-ext.did-utils": "0.29.0",
|
|
27
27
|
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.29.0",
|
|
28
|
-
"@sphereon/ssi-sdk.agent-config": "0.34.1-feature.SSISDK.17.bitstring.sl.
|
|
29
|
-
"@sphereon/ssi-sdk.core": "0.34.1-feature.SSISDK.17.bitstring.sl.
|
|
30
|
-
"@sphereon/ssi-sdk.credential-vcdm": "0.34.1-feature.SSISDK.17.bitstring.sl.
|
|
31
|
-
"@sphereon/ssi-sdk.data-store": "0.34.1-feature.SSISDK.17.bitstring.sl.
|
|
32
|
-
"@sphereon/ssi-sdk.vc-status-list": "0.34.1-feature.SSISDK.17.bitstring.sl.
|
|
33
|
-
"@sphereon/ssi-types": "0.34.1-feature.SSISDK.17.bitstring.sl.
|
|
28
|
+
"@sphereon/ssi-sdk.agent-config": "0.34.1-feature.SSISDK.17.bitstring.sl.16+6964608d",
|
|
29
|
+
"@sphereon/ssi-sdk.core": "0.34.1-feature.SSISDK.17.bitstring.sl.16+6964608d",
|
|
30
|
+
"@sphereon/ssi-sdk.credential-vcdm": "0.34.1-feature.SSISDK.17.bitstring.sl.16+6964608d",
|
|
31
|
+
"@sphereon/ssi-sdk.data-store": "0.34.1-feature.SSISDK.17.bitstring.sl.16+6964608d",
|
|
32
|
+
"@sphereon/ssi-sdk.vc-status-list": "0.34.1-feature.SSISDK.17.bitstring.sl.16+6964608d",
|
|
33
|
+
"@sphereon/ssi-types": "0.34.1-feature.SSISDK.17.bitstring.sl.16+6964608d",
|
|
34
34
|
"@sphereon/vc-status-list": "7.0.0-next.0",
|
|
35
35
|
"@veramo/core": "4.2.0",
|
|
36
36
|
"debug": "^4.3.5",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"SSI",
|
|
62
62
|
"StatusList2021"
|
|
63
63
|
],
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "6964608dcd10f9cc0935ef31e7dec85fb4fe55fd"
|
|
65
65
|
}
|
package/src/drivers.ts
CHANGED
|
@@ -42,6 +42,9 @@ import { DataSource } from 'typeorm'
|
|
|
42
42
|
import { IStatusListDriver } from './types'
|
|
43
43
|
import { statusListResultToEntity } from './status-list-adapters'
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Configuration options for status list management
|
|
47
|
+
*/
|
|
45
48
|
export interface StatusListManagementOptions {
|
|
46
49
|
id?: string
|
|
47
50
|
correlationId?: string
|
|
@@ -51,14 +54,25 @@ export interface StatusListManagementOptions {
|
|
|
51
54
|
|
|
52
55
|
export type DriverOptions = TypeORMOptions
|
|
53
56
|
|
|
57
|
+
/**
|
|
58
|
+
* TypeORM-specific configuration options
|
|
59
|
+
*/
|
|
54
60
|
export interface TypeORMOptions {
|
|
55
61
|
dbName?: string
|
|
56
62
|
}
|
|
57
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Filesystem-specific configuration options
|
|
66
|
+
*/
|
|
58
67
|
export interface FilesystemOptions {
|
|
59
68
|
path: string // The base path where statusList Credentials will be persisted. Should be a folder and thus not include the VC/StatusList itself
|
|
60
69
|
}
|
|
61
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Creates status list management options for TypeORM driver
|
|
73
|
+
* @param args - Configuration parameters including id, correlationId, and database name
|
|
74
|
+
* @returns StatusListManagementOptions configured for TypeORM
|
|
75
|
+
*/
|
|
62
76
|
export function getOptions(args: { id?: string; correlationId?: string; dbName: string }): StatusListManagementOptions {
|
|
63
77
|
return {
|
|
64
78
|
id: args.id,
|
|
@@ -68,6 +82,11 @@ export function getOptions(args: { id?: string; correlationId?: string; dbName:
|
|
|
68
82
|
}
|
|
69
83
|
}
|
|
70
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Creates and initializes a status list driver instance
|
|
87
|
+
* @param args - Configuration parameters including database connection details
|
|
88
|
+
* @returns Promise resolving to initialized IStatusListDriver instance
|
|
89
|
+
*/
|
|
71
90
|
export async function getDriver(args: {
|
|
72
91
|
id?: string
|
|
73
92
|
correlationId?: string
|
|
@@ -98,12 +117,24 @@ export async function getDriver(args: {
|
|
|
98
117
|
export class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
99
118
|
private _statusListLength: number | undefined
|
|
100
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Creates a new AgentDataSourceStatusListDriver instance
|
|
122
|
+
* @param _dataSource - TypeORM DataSource for database operations
|
|
123
|
+
* @param _statusListStore - StatusListStore for data persistence
|
|
124
|
+
* @param options - Driver configuration options
|
|
125
|
+
*/
|
|
101
126
|
constructor(
|
|
102
127
|
private _dataSource: DataSource,
|
|
103
128
|
private _statusListStore: StatusListStore,
|
|
104
129
|
private options: StatusListManagementOptions,
|
|
105
130
|
) {}
|
|
106
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Initializes and creates a new AgentDataSourceStatusListDriver instance
|
|
134
|
+
* @param options - Status list management configuration
|
|
135
|
+
* @param dbArgs - Database connection arguments
|
|
136
|
+
* @returns Promise resolving to initialized driver instance
|
|
137
|
+
*/
|
|
107
138
|
public static async init(
|
|
108
139
|
options: StatusListManagementOptions,
|
|
109
140
|
dbArgs?: {
|
|
@@ -134,6 +165,10 @@ export class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
134
165
|
return new AgentDataSourceStatusListDriver(dataSource, statusListStore, options)
|
|
135
166
|
}
|
|
136
167
|
|
|
168
|
+
/**
|
|
169
|
+
* Gets the TypeORM DataSource instance
|
|
170
|
+
* @returns DataSource instance for database operations
|
|
171
|
+
*/
|
|
137
172
|
get dataSource(): DataSource {
|
|
138
173
|
if (!this._dataSource) {
|
|
139
174
|
throw Error(`Datasource not available yet for ${this.options.driverOptions?.dbName}`)
|
|
@@ -141,6 +176,10 @@ export class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
141
176
|
return this._dataSource
|
|
142
177
|
}
|
|
143
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Gets the StatusListStore instance
|
|
181
|
+
* @returns StatusListStore for data persistence operations
|
|
182
|
+
*/
|
|
144
183
|
get statusListStore(): StatusListStore {
|
|
145
184
|
if (!this._statusListStore) {
|
|
146
185
|
this._statusListStore = new StatusListStore(this.dataSource)
|
|
@@ -148,14 +187,27 @@ export class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
148
187
|
return this._statusListStore
|
|
149
188
|
}
|
|
150
189
|
|
|
190
|
+
/**
|
|
191
|
+
* Gets the driver configuration options
|
|
192
|
+
* @returns DriverOptions configuration
|
|
193
|
+
*/
|
|
151
194
|
getOptions(): DriverOptions {
|
|
152
195
|
return this.options.driverOptions ?? {}
|
|
153
196
|
}
|
|
154
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Gets the driver type
|
|
200
|
+
* @returns StatusListDriverType enum value
|
|
201
|
+
*/
|
|
155
202
|
getType(): StatusListDriverType {
|
|
156
203
|
return this.options.driverType
|
|
157
204
|
}
|
|
158
205
|
|
|
206
|
+
/**
|
|
207
|
+
* Creates a new status list credential and stores it in the database
|
|
208
|
+
* @param args - Status list creation parameters
|
|
209
|
+
* @returns Promise resolving to StatusListResult
|
|
210
|
+
*/
|
|
159
211
|
async createStatusList(args: {
|
|
160
212
|
statusListType: StatusListType
|
|
161
213
|
statusListCredential: StatusListCredential
|
|
@@ -191,6 +243,11 @@ export class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
191
243
|
return implementationResult
|
|
192
244
|
}
|
|
193
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Updates an existing status list credential in the database
|
|
248
|
+
* @param args - Status list update parameters
|
|
249
|
+
* @returns Promise resolving to StatusListResult
|
|
250
|
+
*/
|
|
194
251
|
async updateStatusList(args: { statusListCredential: StatusListCredential; correlationId: string }): Promise<StatusListResult> {
|
|
195
252
|
const correlationId = args.correlationId ?? this.options.correlationId
|
|
196
253
|
|
|
@@ -223,11 +280,20 @@ export class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
223
280
|
return { ...entity, ...details }
|
|
224
281
|
}
|
|
225
282
|
|
|
283
|
+
/**
|
|
284
|
+
* Deletes the status list from the database
|
|
285
|
+
* @returns Promise resolving to boolean indicating success
|
|
286
|
+
*/
|
|
226
287
|
async deleteStatusList(): Promise<boolean> {
|
|
227
288
|
await this.statusListStore.removeStatusList({ id: this.options.id, correlationId: this.options.correlationId })
|
|
228
289
|
return Promise.resolve(true)
|
|
229
290
|
}
|
|
230
291
|
|
|
292
|
+
/**
|
|
293
|
+
* Updates a status list entry and returns the credential status
|
|
294
|
+
* @param args - Status list entry update parameters
|
|
295
|
+
* @returns Promise resolving to credential status and entry
|
|
296
|
+
*/
|
|
231
297
|
async updateStatusListEntry(args: IAddStatusListEntryArgs): Promise<{
|
|
232
298
|
credentialStatus: StatusList2021EntryCredentialStatus | StatusListOAuthEntryCredentialStatus | BitstringStatusListEntryCredentialStatus
|
|
233
299
|
statusListEntry: IStatusListEntryEntity | IBitstringStatusListEntryEntity
|
|
@@ -251,18 +317,33 @@ export class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
251
317
|
}
|
|
252
318
|
}
|
|
253
319
|
|
|
320
|
+
/**
|
|
321
|
+
* Retrieves a status list entry by credential ID
|
|
322
|
+
* @param args - Query parameters including credential ID
|
|
323
|
+
* @returns Promise resolving to status list entry or undefined
|
|
324
|
+
*/
|
|
254
325
|
async getStatusListEntryByCredentialId(
|
|
255
326
|
args: IGetStatusListEntryByCredentialIdArgs,
|
|
256
327
|
): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity | undefined> {
|
|
257
328
|
return await this.statusListStore.getStatusListEntryByCredentialId(args)
|
|
258
329
|
}
|
|
259
330
|
|
|
331
|
+
/**
|
|
332
|
+
* Retrieves a status list entry by index
|
|
333
|
+
* @param args - Query parameters including status list index
|
|
334
|
+
* @returns Promise resolving to status list entry or undefined
|
|
335
|
+
*/
|
|
260
336
|
async getStatusListEntryByIndex(
|
|
261
337
|
args: IGetStatusListEntryByIndexArgs,
|
|
262
338
|
): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity | undefined> {
|
|
263
339
|
return await this.statusListStore.getStatusListEntryByIndex(args)
|
|
264
340
|
}
|
|
265
341
|
|
|
342
|
+
/**
|
|
343
|
+
* Generates a random available index for new status list entries
|
|
344
|
+
* @param args - Optional correlation ID parameter
|
|
345
|
+
* @returns Promise resolving to available index number
|
|
346
|
+
*/
|
|
266
347
|
async getRandomNewStatusListIndex(args?: { correlationId?: string }): Promise<number> {
|
|
267
348
|
let result = -1
|
|
268
349
|
let tries = 0
|
|
@@ -273,6 +354,12 @@ export class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
273
354
|
return result
|
|
274
355
|
}
|
|
275
356
|
|
|
357
|
+
/**
|
|
358
|
+
* Implementation for generating random status list indices with retry logic
|
|
359
|
+
* @param tries - Number of attempts made
|
|
360
|
+
* @param args - Optional correlation ID parameter
|
|
361
|
+
* @returns Promise resolving to available index or -1 if none found
|
|
362
|
+
*/
|
|
276
363
|
private async getRandomNewStatusListIndexImpl(tries: number, args?: { correlationId?: string }): Promise<number> {
|
|
277
364
|
const statusListId = this.options.id
|
|
278
365
|
const correlationId = args?.correlationId ?? this.options.correlationId
|
|
@@ -293,6 +380,11 @@ export class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
293
380
|
return -1
|
|
294
381
|
}
|
|
295
382
|
|
|
383
|
+
/**
|
|
384
|
+
* Gets the length of the status list
|
|
385
|
+
* @param args - Optional correlation ID parameter
|
|
386
|
+
* @returns Promise resolving to status list length
|
|
387
|
+
*/
|
|
296
388
|
async getStatusListLength(args?: { correlationId?: string }): Promise<number> {
|
|
297
389
|
if (!this._statusListLength) {
|
|
298
390
|
this._statusListLength = await this.getStatusList(args).then((details) => details.length)
|
|
@@ -300,6 +392,11 @@ export class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
300
392
|
return this._statusListLength!
|
|
301
393
|
}
|
|
302
394
|
|
|
395
|
+
/**
|
|
396
|
+
* Retrieves the status list details
|
|
397
|
+
* @param args - Optional correlation ID parameter
|
|
398
|
+
* @returns Promise resolving to StatusListResult
|
|
399
|
+
*/
|
|
303
400
|
async getStatusList(args?: { correlationId?: string }): Promise<StatusListResult> {
|
|
304
401
|
const id = this.options.id
|
|
305
402
|
const correlationId = args?.correlationId ?? this.options.correlationId
|
|
@@ -316,6 +413,10 @@ export class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
316
413
|
})
|
|
317
414
|
}
|
|
318
415
|
|
|
416
|
+
/**
|
|
417
|
+
* Retrieves all status lists
|
|
418
|
+
* @returns Promise resolving to array of StatusListResult
|
|
419
|
+
*/
|
|
319
420
|
async getStatusLists(): Promise<Array<StatusListResult>> {
|
|
320
421
|
const statusLists = await this.statusListStore.getStatusLists({})
|
|
321
422
|
return Promise.all(
|
|
@@ -331,6 +432,10 @@ export class AgentDataSourceStatusListDriver implements IStatusListDriver {
|
|
|
331
432
|
)
|
|
332
433
|
}
|
|
333
434
|
|
|
435
|
+
/**
|
|
436
|
+
* Checks if a status list index is currently in use
|
|
437
|
+
* @returns Promise resolving to boolean indicating usage status
|
|
438
|
+
*/
|
|
334
439
|
isStatusListIndexInUse(): Promise<boolean> {
|
|
335
440
|
return Promise.resolve(false)
|
|
336
441
|
}
|