@sphereon/ssi-sdk.vc-status-list-issuer-drivers 0.34.1-next.88 → 0.36.0
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 +11 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -8
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
- package/src/status-list-adapters.ts +10 -7
package/dist/index.cjs
CHANGED
|
@@ -41,7 +41,6 @@ function statusListResultToEntity(result) {
|
|
|
41
41
|
id: result.id,
|
|
42
42
|
correlationId: result.correlationId,
|
|
43
43
|
driverType: result.driverType,
|
|
44
|
-
credentialIdMode: result.credentialIdMode,
|
|
45
44
|
length: result.length,
|
|
46
45
|
issuer: result.issuer,
|
|
47
46
|
type: result.type,
|
|
@@ -52,32 +51,36 @@ function statusListResultToEntity(result) {
|
|
|
52
51
|
if (!result.statusList2021) {
|
|
53
52
|
throw new Error("Missing statusList2021 details");
|
|
54
53
|
}
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const entity = new import_ssi_sdk.StatusList2021Entity();
|
|
55
|
+
Object.assign(entity, baseFields, {
|
|
57
56
|
indexingDirection: result.statusList2021.indexingDirection,
|
|
58
|
-
statusPurpose: result.statusList2021.statusPurpose
|
|
57
|
+
statusPurpose: result.statusList2021.statusPurpose,
|
|
58
|
+
credentialIdMode: result.statusList2021.credentialIdMode
|
|
59
59
|
});
|
|
60
|
+
return entity;
|
|
60
61
|
} else if (result.type === import_ssi_types.StatusListType.OAuthStatusList) {
|
|
61
62
|
if (!result.oauthStatusList) {
|
|
62
63
|
throw new Error("Missing oauthStatusList details");
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
const entity = new import_ssi_sdk.OAuthStatusListEntity();
|
|
66
|
+
Object.assign(entity, baseFields, {
|
|
66
67
|
bitsPerStatus: result.oauthStatusList.bitsPerStatus,
|
|
67
68
|
expiresAt: result.oauthStatusList.expiresAt
|
|
68
69
|
});
|
|
70
|
+
return entity;
|
|
69
71
|
} else if (result.type === import_ssi_types.StatusListType.BitstringStatusList) {
|
|
70
72
|
if (!result.bitstringStatusList) {
|
|
71
73
|
throw new Error("Missing bitstringStatusList details");
|
|
72
74
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
const entity = new import_ssi_sdk.BitstringStatusListEntity();
|
|
76
|
+
Object.assign(entity, baseFields, {
|
|
75
77
|
statusPurpose: result.bitstringStatusList.statusPurpose,
|
|
76
78
|
ttl: result.bitstringStatusList.ttl,
|
|
77
79
|
bitsPerStatus: result.bitstringStatusList.bitsPerStatus,
|
|
78
80
|
validFrom: result.bitstringStatusList.validFrom,
|
|
79
81
|
validUntil: result.bitstringStatusList.validUntil
|
|
80
82
|
});
|
|
83
|
+
return entity;
|
|
81
84
|
}
|
|
82
85
|
throw new Error(`Unsupported status list type: ${result.type}`);
|
|
83
86
|
}
|
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 { StatusListCredentialIdMode, StatusListDriverType } from '@sphereon/ssi-types'\nimport { DataSource } from 'typeorm'\nimport {\n ICreateStatusListArgs,\n IGetRandomNewStatusListIndexArgs,\n IGetStatusListArgs,\n IGetStatusListLengthArgs,\n IStatusListDriver,\n IUpdateStatusListArgs,\n} 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: ICreateStatusListArgs): 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: IUpdateStatusListArgs): 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?: IGetRandomNewStatusListIndexArgs): 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?: IGetStatusListLengthArgs): 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?: IGetStatusListArgs): 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,oBAAiE;;;ACvCjE,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,GAAyB;MAChD,GAAGrB;MACHsB,e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GAAG;AACxB,aAAOgC,UAAU,CAAA;IACnB;AACA,WAAO;EACT;;;;;;EAOA,MAAMN,oBAAoBjE,MAAkD;AAC1E,QAAI,CAAC,KAAKkB,mBAAmB;AAC3B,WAAKA,oBAAoB,MAAM,KAAK0B,cAAc5C,IAAAA,EAAMyE,KAAK,CAAC5B,YAAYA,QAAQN,MAAM;IAC1F;AACA,WAAO,KAAKrB;EACd;;;;;;EAOA,MAAM0B,cAAc5C,MAAsD;AACxE,UAAMC,KAAK,KAAKoB,QAAQpB;AACxB,UAAMC,gBAAgBF,MAAME,iBAAiB,KAAKmB,QAAQnB;AAE1D,UAAM4C,mBAAmB,MAAM,KAAKvB,gBAAgBqB,cAAc;MAAE3C;MAAIC;IAAc,CAAA;AAGtF,WAAO,UAAM+B,qCAAoB;MAC/BC,sBAAsBY,iBAAiBZ;MACvCC,gBAAgBW,iBAAiB4B;MACjCtC,eAAeU,iBAAiBV;MAChClC,eAAe4C,iBAAiB5C;MAChCC,YAAY2C,iBAAiB3C;IAC/B,CAAA;EACF;;;;;EAMA,MAAMwE,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;QAChClC,eAAe4C,iBAAiB5C;QAChCC,YAAY2C,iBAAiB3C;MAC/B,CAAA;IACF,CAAA,CAAA;EAEJ;;;;;EAMA4E,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","_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 { StatusListCredentialIdMode, StatusListDriverType } from '@sphereon/ssi-types'\nimport { DataSource } from 'typeorm'\nimport {\n ICreateStatusListArgs,\n IGetRandomNewStatusListIndexArgs,\n IGetStatusListArgs,\n IGetStatusListLengthArgs,\n IStatusListDriver,\n IUpdateStatusListArgs,\n} 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: ICreateStatusListArgs): 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: IUpdateStatusListArgs): 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?: IGetRandomNewStatusListIndexArgs): 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?: IGetStatusListLengthArgs): 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?: IGetStatusListArgs): 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 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 const entity = new StatusList2021Entity()\n Object.assign(entity, baseFields, {\n indexingDirection: result.statusList2021.indexingDirection,\n statusPurpose: result.statusList2021.statusPurpose,\n credentialIdMode: result.statusList2021.credentialIdMode,\n })\n return entity\n } else if (result.type === StatusListType.OAuthStatusList) {\n if (!result.oauthStatusList) {\n throw new Error('Missing oauthStatusList details')\n }\n const entity = new OAuthStatusListEntity()\n Object.assign(entity, baseFields, {\n bitsPerStatus: result.oauthStatusList.bitsPerStatus,\n expiresAt: result.oauthStatusList.expiresAt,\n })\n return entity\n } else if (result.type === StatusListType.BitstringStatusList) {\n if (!result.bitstringStatusList) {\n throw new Error('Missing bitstringStatusList details')\n }\n const entity = new BitstringStatusListEntity()\n Object.assign(entity, 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 return entity\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,oBAAiE;;;ACvCjE,uBAA+B;AAC/B,qBAAuF;AAGhF,SAASC,yBAAyBC,QAAwB;AAC/D,QAAMC,aAAa;IACjBC,IAAIF,OAAOE;IACXC,eAAeH,OAAOG;IACtBC,YAAYJ,OAAOI;IACnBC,QAAQL,OAAOK;IACfC,QAAQN,OAAOM;IACfC,MAAMP,OAAOO;IACbC,aAAaR,OAAOQ;IACpBC,sBAAsBT,OAAOS;EAC/B;AAEA,MAAIT,OAAOO,SAASG,gCAAeC,gBAAgB;AACjD,QAAI,CAACX,OAAOY,gBAAgB;AAC1B,YAAM,IAAIC,MAAM,gCAAA;IAClB;AACA,UAAMC,SAAS,IAAIC,oCAAAA;AACnBC,WAAOC,OAAOH,QAAQb,YAAY;MAChCiB,mBAAmBlB,OAAOY,eAAeM;MACzCC,eAAenB,OAAOY,eAAeO;MACrCC,kBAAkBpB,OAAOY,eAAeQ;IAC1C,CAAA;AACA,WAAON;EACT,WAAWd,OAAOO,SAASG,gCAAeW,iBAAiB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;EACzB;AACF;","names":["import_ssi_sdk","import_ssi_types","statusListResultToEntity","result","baseFields","id","correlationId","driverType","length","issuer","type","proofFormat","statusListCredential","StatusListType","StatusList2021","statusList2021","Error","entity","StatusList2021Entity","Object","assign","indexingDirection","statusPurpose","credentialIdMode","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","_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.js
CHANGED
|
@@ -15,7 +15,6 @@ function statusListResultToEntity(result) {
|
|
|
15
15
|
id: result.id,
|
|
16
16
|
correlationId: result.correlationId,
|
|
17
17
|
driverType: result.driverType,
|
|
18
|
-
credentialIdMode: result.credentialIdMode,
|
|
19
18
|
length: result.length,
|
|
20
19
|
issuer: result.issuer,
|
|
21
20
|
type: result.type,
|
|
@@ -26,32 +25,36 @@ function statusListResultToEntity(result) {
|
|
|
26
25
|
if (!result.statusList2021) {
|
|
27
26
|
throw new Error("Missing statusList2021 details");
|
|
28
27
|
}
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
const entity = new StatusList2021Entity();
|
|
29
|
+
Object.assign(entity, baseFields, {
|
|
31
30
|
indexingDirection: result.statusList2021.indexingDirection,
|
|
32
|
-
statusPurpose: result.statusList2021.statusPurpose
|
|
31
|
+
statusPurpose: result.statusList2021.statusPurpose,
|
|
32
|
+
credentialIdMode: result.statusList2021.credentialIdMode
|
|
33
33
|
});
|
|
34
|
+
return entity;
|
|
34
35
|
} else if (result.type === StatusListType.OAuthStatusList) {
|
|
35
36
|
if (!result.oauthStatusList) {
|
|
36
37
|
throw new Error("Missing oauthStatusList details");
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const entity = new OAuthStatusListEntity();
|
|
40
|
+
Object.assign(entity, baseFields, {
|
|
40
41
|
bitsPerStatus: result.oauthStatusList.bitsPerStatus,
|
|
41
42
|
expiresAt: result.oauthStatusList.expiresAt
|
|
42
43
|
});
|
|
44
|
+
return entity;
|
|
43
45
|
} else if (result.type === StatusListType.BitstringStatusList) {
|
|
44
46
|
if (!result.bitstringStatusList) {
|
|
45
47
|
throw new Error("Missing bitstringStatusList details");
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
const entity = new BitstringStatusListEntity();
|
|
50
|
+
Object.assign(entity, baseFields, {
|
|
49
51
|
statusPurpose: result.bitstringStatusList.statusPurpose,
|
|
50
52
|
ttl: result.bitstringStatusList.ttl,
|
|
51
53
|
bitsPerStatus: result.bitstringStatusList.bitsPerStatus,
|
|
52
54
|
validFrom: result.bitstringStatusList.validFrom,
|
|
53
55
|
validUntil: result.bitstringStatusList.validUntil
|
|
54
56
|
});
|
|
57
|
+
return entity;
|
|
55
58
|
}
|
|
56
59
|
throw new Error(`Unsupported status list type: ${result.type}`);
|
|
57
60
|
}
|
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 { StatusListCredentialIdMode, StatusListDriverType } from '@sphereon/ssi-types'\nimport { DataSource } from 'typeorm'\nimport {\n ICreateStatusListArgs,\n IGetRandomNewStatusListIndexArgs,\n IGetStatusListArgs,\n IGetStatusListLengthArgs,\n IStatusListDriver,\n IUpdateStatusListArgs,\n} 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: ICreateStatusListArgs): 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: IUpdateStatusListArgs): 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?: IGetRandomNewStatusListIndexArgs): 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?: IGetStatusListLengthArgs): 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?: IGetStatusListArgs): 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,SAASC,4BAA4BC,4BAA4B;;;ACvCjE,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,QA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rD,gBAAgBoD,eAAe,CAAC,CAAA;AAC/D,WAAOnD,QAAQqD,IACbD,YAAYE,IAAI,OAAOhC,qBAAAA;AACrB,aAAOb,oBAAoB;QACzBC,sBAAsBY,iBAAiBZ;QACvCC,gBAAgBW,iBAAiB4B;QACjCtC,eAAeU,iBAAiBV;QAChClC,eAAe4C,iBAAiB5C;QAChCC,YAAY2C,iBAAiB3C;MAC/B,CAAA;IACF,CAAA,CAAA;EAEJ;;;;;EAMA4E,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","_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 { StatusListCredentialIdMode, StatusListDriverType } from '@sphereon/ssi-types'\nimport { DataSource } from 'typeorm'\nimport {\n ICreateStatusListArgs,\n IGetRandomNewStatusListIndexArgs,\n IGetStatusListArgs,\n IGetStatusListLengthArgs,\n IStatusListDriver,\n IUpdateStatusListArgs,\n} 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: ICreateStatusListArgs): 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: IUpdateStatusListArgs): 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?: IGetRandomNewStatusListIndexArgs): 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?: IGetStatusListLengthArgs): 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?: IGetStatusListArgs): 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 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 const entity = new StatusList2021Entity()\n Object.assign(entity, baseFields, {\n indexingDirection: result.statusList2021.indexingDirection,\n statusPurpose: result.statusList2021.statusPurpose,\n credentialIdMode: result.statusList2021.credentialIdMode,\n })\n return entity\n } else if (result.type === StatusListType.OAuthStatusList) {\n if (!result.oauthStatusList) {\n throw new Error('Missing oauthStatusList details')\n }\n const entity = new OAuthStatusListEntity()\n Object.assign(entity, baseFields, {\n bitsPerStatus: result.oauthStatusList.bitsPerStatus,\n expiresAt: result.oauthStatusList.expiresAt,\n })\n return entity\n } else if (result.type === StatusListType.BitstringStatusList) {\n if (!result.bitstringStatusList) {\n throw new Error('Missing bitstringStatusList details')\n }\n const entity = new BitstringStatusListEntity()\n Object.assign(entity, 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 return entity\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,SAASC,4BAA4BC,4BAA4B;;;ACvCjE,SAASC,sBAAsB;AAC/B,SAASC,2BAA2B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,CAAA;AAGtF,WAAO,MAAM+B,oBAAoB;MAC/BC,sBAAsBY,iBAAiBZ;MACvCC,gBAAgBW,iBAAiB4B;MACjCtC,eAAeU,iBAAiBV;MAChClC,eAAe4C,iBAAiB5C;MAChCC,YAAY2C,iBAAiB3C;IAC/B,CAAA;EACF;;;;;EAMA,MAAMwE,iBAAmD;AACvD,UAAMC,cAAc,MAAM,KAAKrD,gBAAgBoD,eAAe,CAAC,CAAA;AAC/D,WAAOnD,QAAQqD,IACbD,YAAYE,IAAI,OAAOhC,qBAAAA;AACrB,aAAOb,oBAAoB;QACzBC,sBAAsBY,iBAAiBZ;QACvCC,gBAAgBW,iBAAiB4B;QACjCtC,eAAeU,iBAAiBV;QAChClC,eAAe4C,iBAAiB5C;QAChCC,YAAY2C,iBAAiB3C;MAC/B,CAAA;IACF,CAAA,CAAA;EAEJ;;;;;EAMA4E,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","length","issuer","type","proofFormat","statusListCredential","StatusListType","StatusList2021","statusList2021","Error","entity","StatusList2021Entity","Object","assign","indexingDirection","statusPurpose","credentialIdMode","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","_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.
|
|
4
|
+
"version": "0.36.0",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
@@ -22,15 +22,16 @@
|
|
|
22
22
|
"build": "tsup --config ../../tsup.config.ts --tsconfig ../../tsconfig.tsup.json"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@sphereon/ssi-express-support": "0.
|
|
26
|
-
"@sphereon/ssi-sdk-ext.did-utils": "0.
|
|
27
|
-
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.
|
|
28
|
-
"@sphereon/ssi-sdk.agent-config": "0.
|
|
29
|
-
"@sphereon/ssi-sdk.core": "0.
|
|
30
|
-
"@sphereon/ssi-sdk.credential-vcdm": "0.
|
|
31
|
-
"@sphereon/ssi-sdk.data-store": "0.
|
|
32
|
-
"@sphereon/ssi-sdk.
|
|
33
|
-
"@sphereon/ssi-
|
|
25
|
+
"@sphereon/ssi-express-support": "0.36.0",
|
|
26
|
+
"@sphereon/ssi-sdk-ext.did-utils": "0.36.0",
|
|
27
|
+
"@sphereon/ssi-sdk-ext.identifier-resolution": "0.36.0",
|
|
28
|
+
"@sphereon/ssi-sdk.agent-config": "0.36.0",
|
|
29
|
+
"@sphereon/ssi-sdk.core": "0.36.0",
|
|
30
|
+
"@sphereon/ssi-sdk.credential-vcdm": "0.36.0",
|
|
31
|
+
"@sphereon/ssi-sdk.data-store": "0.36.0",
|
|
32
|
+
"@sphereon/ssi-sdk.data-store-types": "0.36.0",
|
|
33
|
+
"@sphereon/ssi-sdk.vc-status-list": "0.36.0",
|
|
34
|
+
"@sphereon/ssi-types": "0.36.0",
|
|
34
35
|
"@sphereon/vc-status-list": "7.0.0-next.0",
|
|
35
36
|
"@veramo/core": "4.2.0",
|
|
36
37
|
"debug": "^4.3.5",
|
|
@@ -61,5 +62,5 @@
|
|
|
61
62
|
"SSI",
|
|
62
63
|
"StatusList2021"
|
|
63
64
|
],
|
|
64
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "f713d3a83948ef69aaa7d435700b16d5655ac863"
|
|
65
66
|
}
|
|
@@ -7,7 +7,6 @@ export function statusListResultToEntity(result: StatusListResult): StatusList20
|
|
|
7
7
|
id: result.id,
|
|
8
8
|
correlationId: result.correlationId,
|
|
9
9
|
driverType: result.driverType,
|
|
10
|
-
credentialIdMode: result.credentialIdMode,
|
|
11
10
|
length: result.length,
|
|
12
11
|
issuer: result.issuer,
|
|
13
12
|
type: result.type,
|
|
@@ -19,32 +18,36 @@ export function statusListResultToEntity(result: StatusListResult): StatusList20
|
|
|
19
18
|
if (!result.statusList2021) {
|
|
20
19
|
throw new Error('Missing statusList2021 details')
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const entity = new StatusList2021Entity()
|
|
22
|
+
Object.assign(entity, baseFields, {
|
|
24
23
|
indexingDirection: result.statusList2021.indexingDirection,
|
|
25
24
|
statusPurpose: result.statusList2021.statusPurpose,
|
|
25
|
+
credentialIdMode: result.statusList2021.credentialIdMode,
|
|
26
26
|
})
|
|
27
|
+
return entity
|
|
27
28
|
} else if (result.type === StatusListType.OAuthStatusList) {
|
|
28
29
|
if (!result.oauthStatusList) {
|
|
29
30
|
throw new Error('Missing oauthStatusList details')
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
const entity = new OAuthStatusListEntity()
|
|
33
|
+
Object.assign(entity, baseFields, {
|
|
33
34
|
bitsPerStatus: result.oauthStatusList.bitsPerStatus,
|
|
34
35
|
expiresAt: result.oauthStatusList.expiresAt,
|
|
35
36
|
})
|
|
37
|
+
return entity
|
|
36
38
|
} else if (result.type === StatusListType.BitstringStatusList) {
|
|
37
39
|
if (!result.bitstringStatusList) {
|
|
38
40
|
throw new Error('Missing bitstringStatusList details')
|
|
39
41
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
const entity = new BitstringStatusListEntity()
|
|
43
|
+
Object.assign(entity, baseFields, {
|
|
42
44
|
statusPurpose: result.bitstringStatusList.statusPurpose,
|
|
43
45
|
ttl: result.bitstringStatusList.ttl,
|
|
44
46
|
bitsPerStatus: result.bitstringStatusList.bitsPerStatus,
|
|
45
47
|
validFrom: result.bitstringStatusList.validFrom,
|
|
46
48
|
validUntil: result.bitstringStatusList.validUntil,
|
|
47
49
|
})
|
|
50
|
+
return entity
|
|
48
51
|
}
|
|
49
52
|
throw new Error(`Unsupported status list type: ${result.type}`)
|
|
50
53
|
}
|