@sphereon/ssi-sdk.data-store 0.34.1-feature.disable.test.8 → 0.34.1-next.29
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 +957 -480
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +111 -26
- package/dist/index.d.ts +111 -26
- package/dist/index.js +903 -426
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/statusList.entities.test.ts +58 -1
- package/src/__tests__/statusList.store.test.ts +64 -1
- package/src/entities/statusList/BitstringStatusListEntryEntity.ts +60 -0
- package/src/entities/statusList/StatusList2021EntryEntity.ts +4 -3
- package/src/entities/statusList/StatusListEntities.ts +54 -5
- package/src/index.ts +12 -2
- package/src/migrations/generic/12-CreateBitstringStatusList.ts +52 -0
- package/src/migrations/generic/index.ts +2 -1
- package/src/migrations/postgres/1741895823000-CreateBitstringStatusList.ts +53 -0
- package/src/migrations/sqlite/1741895823001-CreateBitstringStatusList.ts +145 -0
- package/src/statusList/IStatusListStore.ts +14 -11
- package/src/statusList/StatusListStore.ts +73 -35
- package/src/types/statusList/IAbstractStatusListStore.ts +54 -4
- package/src/types/statusList/statusList.ts +50 -2
- package/src/utils/statusList/MappingUtils.ts +71 -30
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from 'typeorm'
|
|
2
|
+
|
|
3
|
+
export class CreateBitstringStatusListSqlite1741895823001 implements MigrationInterface {
|
|
4
|
+
name = 'CreateBitstringStatusList1741895823000'
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
// Update StatusList table to include BitstringStatusList type and columns
|
|
8
|
+
await queryRunner.query(`
|
|
9
|
+
CREATE TABLE "temporary_StatusList" (
|
|
10
|
+
"id" varchar PRIMARY KEY NOT NULL,
|
|
11
|
+
"correlationId" varchar NOT NULL,
|
|
12
|
+
"length" integer NOT NULL,
|
|
13
|
+
"issuer" text NOT NULL,
|
|
14
|
+
"type" varchar CHECK( "type" IN ('StatusList2021', 'OAuthStatusList', 'BitstringStatusList') ) NOT NULL DEFAULT ('StatusList2021'),
|
|
15
|
+
"driverType" varchar CHECK( "driverType" IN ('agent_typeorm','agent_kv_store','github','agent_filesystem') ) NOT NULL DEFAULT ('agent_typeorm'),
|
|
16
|
+
"credentialIdMode" varchar CHECK( "credentialIdMode" IN ('ISSUANCE','PERSISTENCE','NEVER') ) NOT NULL DEFAULT ('ISSUANCE'),
|
|
17
|
+
"proofFormat" varchar CHECK( "proofFormat" IN ('lds','jwt', 'vc+jwt') ) NOT NULL DEFAULT ('lds'),
|
|
18
|
+
"indexingDirection" varchar CHECK( "indexingDirection" IN ('rightToLeft') ),
|
|
19
|
+
"statusPurpose" varchar,
|
|
20
|
+
"statusListCredential" text,
|
|
21
|
+
"expiresAt" datetime,
|
|
22
|
+
"bitsPerStatus" integer DEFAULT (1),
|
|
23
|
+
"ttl" integer,
|
|
24
|
+
"validFrom" datetime,
|
|
25
|
+
"validUntil" datetime,
|
|
26
|
+
CONSTRAINT "UQ_correlationId" UNIQUE ("correlationId")
|
|
27
|
+
)
|
|
28
|
+
`)
|
|
29
|
+
|
|
30
|
+
await queryRunner.query(`
|
|
31
|
+
INSERT INTO "temporary_StatusList"(
|
|
32
|
+
"id", "correlationId", "length", "issuer", "type", "driverType",
|
|
33
|
+
"credentialIdMode", "proofFormat", "indexingDirection", "statusPurpose",
|
|
34
|
+
"statusListCredential", "bitsPerStatus", "expiresAt"
|
|
35
|
+
)
|
|
36
|
+
SELECT
|
|
37
|
+
"id", "correlationId", "length", "issuer", "type", "driverType",
|
|
38
|
+
"credentialIdMode", "proofFormat", "indexingDirection", "statusPurpose",
|
|
39
|
+
"statusListCredential", "bitsPerStatus", "expiresAt"
|
|
40
|
+
FROM "StatusList"
|
|
41
|
+
`)
|
|
42
|
+
|
|
43
|
+
await queryRunner.query(`DROP TABLE "StatusList"`)
|
|
44
|
+
await queryRunner.query(`ALTER TABLE "temporary_StatusList" RENAME TO "StatusList"`)
|
|
45
|
+
|
|
46
|
+
// Update StatusListEntry table with inheritance and bitstring columns
|
|
47
|
+
await queryRunner.query(`
|
|
48
|
+
CREATE TABLE "temporary_StatusListEntry" (
|
|
49
|
+
"statusListId" varchar NOT NULL,
|
|
50
|
+
"statusListIndex" integer NOT NULL,
|
|
51
|
+
"credentialId" text,
|
|
52
|
+
"credentialHash" varchar(128),
|
|
53
|
+
"correlationId" varchar(255),
|
|
54
|
+
"value" varchar(50),
|
|
55
|
+
"type" varchar CHECK( "type" IN ('StatusListEntryEntity', 'bitstring') ) NOT NULL DEFAULT ('StatusListEntryEntity'),
|
|
56
|
+
"statusPurpose" varchar,
|
|
57
|
+
"bitsPerStatus" integer DEFAULT (1),
|
|
58
|
+
"statusMessage" text,
|
|
59
|
+
"statusReference" text,
|
|
60
|
+
PRIMARY KEY ("statusListId", "statusListIndex")
|
|
61
|
+
)
|
|
62
|
+
`)
|
|
63
|
+
|
|
64
|
+
await queryRunner.query(`
|
|
65
|
+
INSERT INTO "temporary_StatusListEntry"(
|
|
66
|
+
"statusListId", "statusListIndex", "credentialId", "credentialHash",
|
|
67
|
+
"correlationId", "value", "type"
|
|
68
|
+
)
|
|
69
|
+
SELECT
|
|
70
|
+
"statusListId", "statusListIndex", "credentialId", "credentialHash",
|
|
71
|
+
"correlationId", "value", 'StatusListEntryEntity'
|
|
72
|
+
FROM "StatusListEntry"
|
|
73
|
+
`)
|
|
74
|
+
|
|
75
|
+
await queryRunner.query(`DROP TABLE "StatusListEntry"`)
|
|
76
|
+
await queryRunner.query(`ALTER TABLE "temporary_StatusListEntry" RENAME TO "StatusListEntry"`)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
80
|
+
// Revert StatusListEntry table changes
|
|
81
|
+
await queryRunner.query(`
|
|
82
|
+
CREATE TABLE "temporary_StatusListEntry" (
|
|
83
|
+
"statusListId" varchar NOT NULL,
|
|
84
|
+
"statusListIndex" integer NOT NULL,
|
|
85
|
+
"credentialId" text,
|
|
86
|
+
"credentialHash" varchar(128),
|
|
87
|
+
"correlationId" varchar(255),
|
|
88
|
+
"value" varchar(50),
|
|
89
|
+
PRIMARY KEY ("statusListId", "statusListIndex")
|
|
90
|
+
)
|
|
91
|
+
`)
|
|
92
|
+
|
|
93
|
+
await queryRunner.query(`
|
|
94
|
+
INSERT INTO "temporary_StatusListEntry"(
|
|
95
|
+
"statusListId", "statusListIndex", "credentialId", "credentialHash",
|
|
96
|
+
"correlationId", "value"
|
|
97
|
+
)
|
|
98
|
+
SELECT
|
|
99
|
+
"statusListId", "statusListIndex", "credentialId", "credentialHash",
|
|
100
|
+
"correlationId", "value"
|
|
101
|
+
FROM "StatusListEntry"
|
|
102
|
+
WHERE "type" = 'StatusListEntryEntity'
|
|
103
|
+
`)
|
|
104
|
+
|
|
105
|
+
await queryRunner.query(`DROP TABLE "StatusListEntry"`)
|
|
106
|
+
await queryRunner.query(`ALTER TABLE "temporary_StatusListEntry" RENAME TO "StatusListEntry"`)
|
|
107
|
+
|
|
108
|
+
// Revert StatusList table changes
|
|
109
|
+
await queryRunner.query(`
|
|
110
|
+
CREATE TABLE "temporary_StatusList" (
|
|
111
|
+
"id" varchar PRIMARY KEY NOT NULL,
|
|
112
|
+
"correlationId" varchar NOT NULL,
|
|
113
|
+
"length" integer NOT NULL,
|
|
114
|
+
"issuer" text NOT NULL,
|
|
115
|
+
"type" varchar CHECK( "type" IN ('StatusList2021', 'OAuthStatusList') ) NOT NULL DEFAULT ('StatusList2021'),
|
|
116
|
+
"driverType" varchar CHECK( "driverType" IN ('agent_typeorm','agent_kv_store','github','agent_filesystem') ) NOT NULL DEFAULT ('agent_typeorm'),
|
|
117
|
+
"credentialIdMode" varchar CHECK( "credentialIdMode" IN ('ISSUANCE','PERSISTENCE','NEVER') ) NOT NULL DEFAULT ('ISSUANCE'),
|
|
118
|
+
"proofFormat" varchar CHECK( "proofFormat" IN ('lds','jwt', 'vc+jwt') ) NOT NULL DEFAULT ('lds'),
|
|
119
|
+
"indexingDirection" varchar CHECK( "indexingDirection" IN ('rightToLeft') ),
|
|
120
|
+
"statusPurpose" varchar,
|
|
121
|
+
"statusListCredential" text,
|
|
122
|
+
"bitsPerStatus" integer,
|
|
123
|
+
"expiresAt" datetime,
|
|
124
|
+
CONSTRAINT "UQ_correlationId" UNIQUE ("correlationId")
|
|
125
|
+
)
|
|
126
|
+
`)
|
|
127
|
+
|
|
128
|
+
await queryRunner.query(`
|
|
129
|
+
INSERT INTO "temporary_StatusList"(
|
|
130
|
+
"id", "correlationId", "length", "issuer", "type", "driverType",
|
|
131
|
+
"credentialIdMode", "proofFormat", "indexingDirection", "statusPurpose",
|
|
132
|
+
"statusListCredential", "bitsPerStatus", "expiresAt"
|
|
133
|
+
)
|
|
134
|
+
SELECT
|
|
135
|
+
"id", "correlationId", "length", "issuer",
|
|
136
|
+
CASE WHEN "type" = 'BitstringStatusList' THEN 'StatusList2021' ELSE "type" END,
|
|
137
|
+
"driverType", "credentialIdMode", "proofFormat", "indexingDirection",
|
|
138
|
+
"statusPurpose", "statusListCredential", "bitsPerStatus", "expiresAt"
|
|
139
|
+
FROM "StatusList"
|
|
140
|
+
`)
|
|
141
|
+
|
|
142
|
+
await queryRunner.query(`DROP TABLE "StatusList"`)
|
|
143
|
+
await queryRunner.query(`ALTER TABLE "temporary_StatusList" RENAME TO "StatusList"`)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -2,6 +2,8 @@ import { StatusListEntryEntity } from '../entities/statusList/StatusList2021Entr
|
|
|
2
2
|
import type {
|
|
3
3
|
IAddStatusListArgs,
|
|
4
4
|
IAddStatusListEntryArgs,
|
|
5
|
+
IBitstringStatusListEntity,
|
|
6
|
+
IBitstringStatusListEntryEntity,
|
|
5
7
|
IGetStatusListArgs,
|
|
6
8
|
IGetStatusListEntriesArgs,
|
|
7
9
|
IGetStatusListEntryByCredentialIdArgs,
|
|
@@ -12,33 +14,34 @@ import type {
|
|
|
12
14
|
IUpdateStatusListIndexArgs,
|
|
13
15
|
} from '../types'
|
|
14
16
|
import { IStatusListEntity, IStatusListEntryEntity } from '../types'
|
|
17
|
+
import { BitstringStatusListEntryEntity } from '../entities/statusList/BitstringStatusListEntryEntity'
|
|
15
18
|
|
|
16
19
|
export interface IStatusListStore {
|
|
17
|
-
getStatusList(args: IGetStatusListArgs): Promise<IStatusListEntity>
|
|
20
|
+
getStatusList(args: IGetStatusListArgs): Promise<IStatusListEntity | IBitstringStatusListEntity>
|
|
18
21
|
|
|
19
|
-
getStatusLists(args: IGetStatusListsArgs): Promise<Array<IStatusListEntity>>
|
|
22
|
+
getStatusLists(args: IGetStatusListsArgs): Promise<Array<IStatusListEntity | IBitstringStatusListEntity>>
|
|
20
23
|
|
|
21
24
|
removeStatusList(args: IRemoveStatusListArgs): Promise<boolean>
|
|
22
25
|
|
|
23
|
-
addStatusList(args: IAddStatusListArgs): Promise<IStatusListEntity>
|
|
26
|
+
addStatusList(args: IAddStatusListArgs): Promise<IStatusListEntity | IBitstringStatusListEntity>
|
|
24
27
|
|
|
25
|
-
updateStatusList(args: IUpdateStatusListIndexArgs): Promise<IStatusListEntity>
|
|
28
|
+
updateStatusList(args: IUpdateStatusListIndexArgs): Promise<IStatusListEntity | IBitstringStatusListEntity>
|
|
26
29
|
|
|
27
30
|
availableStatusListEntries(args: IStatusListEntryAvailableArgs): Promise<number[]>
|
|
28
31
|
|
|
29
|
-
addStatusListEntry(args: IAddStatusListEntryArgs): Promise<IStatusListEntryEntity>
|
|
32
|
+
addStatusListEntry(args: IAddStatusListEntryArgs): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity>
|
|
30
33
|
|
|
31
|
-
updateStatusListEntry(args: IAddStatusListEntryArgs): Promise<IStatusListEntryEntity>
|
|
34
|
+
updateStatusListEntry(args: IAddStatusListEntryArgs): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity>
|
|
32
35
|
|
|
33
|
-
getStatusListEntryByIndex(args: IGetStatusListEntryByIndexArgs): Promise<StatusListEntryEntity | undefined>
|
|
36
|
+
getStatusListEntryByIndex(args: IGetStatusListEntryByIndexArgs): Promise<StatusListEntryEntity | BitstringStatusListEntryEntity | undefined>
|
|
34
37
|
|
|
35
|
-
getStatusListEntryByCredentialId(
|
|
38
|
+
getStatusListEntryByCredentialId(
|
|
39
|
+
args: IGetStatusListEntryByCredentialIdArgs,
|
|
40
|
+
): Promise<StatusListEntryEntity | BitstringStatusListEntryEntity | undefined>
|
|
36
41
|
|
|
37
42
|
removeStatusListEntryByIndex(args: IGetStatusListEntryByIndexArgs): Promise<boolean>
|
|
38
43
|
|
|
39
44
|
removeStatusListEntryByCredentialId(args: IGetStatusListEntryByCredentialIdArgs): Promise<boolean>
|
|
40
45
|
|
|
41
|
-
getStatusListEntries(args: IGetStatusListEntriesArgs): Promise<IStatusListEntryEntity
|
|
42
|
-
|
|
43
|
-
getStatusList(args: IGetStatusListArgs): Promise<IStatusListEntity>
|
|
46
|
+
getStatusListEntries(args: IGetStatusListEntriesArgs): Promise<Array<IStatusListEntryEntity | IBitstringStatusListEntryEntity>>
|
|
44
47
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { type OrPromise, StatusListType } from '@sphereon/ssi-types'
|
|
2
2
|
import Debug from 'debug'
|
|
3
3
|
import { DataSource, In, type Repository } from 'typeorm'
|
|
4
|
-
import { OAuthStatusListEntity, StatusList2021Entity, StatusListEntity } from '../entities/statusList/StatusListEntities'
|
|
4
|
+
import { BitstringStatusListEntity, OAuthStatusListEntity, StatusList2021Entity, StatusListEntity } from '../entities/statusList/StatusListEntities'
|
|
5
5
|
import { StatusListEntryEntity } from '../entities/statusList/StatusList2021EntryEntity'
|
|
6
|
-
import
|
|
6
|
+
import { BitstringStatusListEntryEntity } from '../entities/statusList/BitstringStatusListEntryEntity'
|
|
7
|
+
import {
|
|
7
8
|
IAddStatusListArgs,
|
|
8
9
|
IAddStatusListEntryArgs,
|
|
10
|
+
IBitstringStatusListEntity,
|
|
11
|
+
IBitstringStatusListEntryEntity,
|
|
9
12
|
IGetStatusListArgs,
|
|
10
13
|
IGetStatusListEntriesArgs,
|
|
11
14
|
IGetStatusListEntryByCredentialIdArgs,
|
|
@@ -41,11 +44,11 @@ export class StatusListStore implements IStatusListStore {
|
|
|
41
44
|
async availableStatusListEntries(args: IStatusListEntryAvailableArgs): Promise<number[]> {
|
|
42
45
|
const statusListIndex = Array.isArray(args.statusListIndex) ? args.statusListIndex : [args.statusListIndex]
|
|
43
46
|
const statusList = await this.getStatusList({ ...args, id: args.statusListId })
|
|
44
|
-
const repo = await this.getStatusListEntryRepo()
|
|
47
|
+
const repo = await this.getStatusListEntryRepo(statusList.type)
|
|
45
48
|
const results = (
|
|
46
49
|
await repo.find({
|
|
47
50
|
where: {
|
|
48
|
-
statusList,
|
|
51
|
+
statusListId: statusList.id,
|
|
49
52
|
statusListIndex: In(statusListIndex),
|
|
50
53
|
},
|
|
51
54
|
})
|
|
@@ -53,33 +56,42 @@ export class StatusListStore implements IStatusListStore {
|
|
|
53
56
|
return statusListIndex.filter((index) => !results.includes(index))
|
|
54
57
|
}
|
|
55
58
|
|
|
56
|
-
async addStatusListEntry(args: IAddStatusListEntryArgs): Promise<IStatusListEntryEntity> {
|
|
57
|
-
|
|
59
|
+
async addStatusListEntry(args: IAddStatusListEntryArgs): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity> {
|
|
60
|
+
if (!args.statusListId) {
|
|
61
|
+
throw new Error('statusListId is required')
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const statusList = await this.getStatusList({ id: args.statusListId })
|
|
65
|
+
return await (await this.getStatusListEntryRepo(statusList.type)).save(args)
|
|
58
66
|
}
|
|
59
67
|
|
|
60
|
-
async updateStatusListEntry(args: IAddStatusListEntryArgs): Promise<IStatusListEntryEntity> {
|
|
61
|
-
const statusListId = args.statusListId
|
|
68
|
+
async updateStatusListEntry(args: IAddStatusListEntryArgs): Promise<IStatusListEntryEntity | IBitstringStatusListEntryEntity> {
|
|
69
|
+
const statusListId = args.statusListId
|
|
70
|
+
if (!statusListId) {
|
|
71
|
+
throw new Error('statusListId is required')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const statusList = await this.getStatusList({ id: statusListId })
|
|
62
75
|
const result = await this.getStatusListEntryByIndex({ ...args, statusListId, errorOnNotFound: false })
|
|
63
76
|
const updatedEntry: Partial<IStatusListEntryEntity> = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
credentialId: args.credentialId,
|
|
77
|
+
...result,
|
|
78
|
+
...args,
|
|
79
|
+
statusListId,
|
|
68
80
|
}
|
|
69
81
|
|
|
70
82
|
const updStatusListId = result?.statusListId ?? statusListId
|
|
71
83
|
const updateResult = await (
|
|
72
|
-
await this.getStatusListEntryRepo()
|
|
84
|
+
await this.getStatusListEntryRepo(statusList.type)
|
|
73
85
|
).upsert(
|
|
74
86
|
{ ...(result ?? { statusListId: updStatusListId, statusListIndex: args.statusListIndex }), ...updatedEntry },
|
|
75
87
|
{ conflictPaths: ['statusList', 'statusListIndex'] },
|
|
76
88
|
)
|
|
77
|
-
|
|
89
|
+
debug(updateResult)
|
|
78
90
|
return (await this.getStatusListEntryByIndex({
|
|
79
91
|
...args,
|
|
80
92
|
statusListId: updStatusListId,
|
|
81
93
|
errorOnNotFound: true,
|
|
82
|
-
}))
|
|
94
|
+
}))!
|
|
83
95
|
}
|
|
84
96
|
|
|
85
97
|
async getStatusListEntryByIndex({
|
|
@@ -88,7 +100,7 @@ export class StatusListStore implements IStatusListStore {
|
|
|
88
100
|
statusListIndex,
|
|
89
101
|
entryCorrelationId,
|
|
90
102
|
errorOnNotFound,
|
|
91
|
-
}: IGetStatusListEntryByIndexArgs): Promise<StatusListEntryEntity | undefined> {
|
|
103
|
+
}: IGetStatusListEntryByIndexArgs): Promise<StatusListEntryEntity | BitstringStatusListEntryEntity | undefined> {
|
|
92
104
|
if (!statusListId && !statusListCorrelationId) {
|
|
93
105
|
throw Error(`Cannot get statusList entry without either a statusList id or statusListCorrelationId`)
|
|
94
106
|
}
|
|
@@ -97,8 +109,12 @@ export class StatusListStore implements IStatusListStore {
|
|
|
97
109
|
throw Error(`Cannot get statusList entry without either a statusListIndex or entryCorrelationId`)
|
|
98
110
|
}
|
|
99
111
|
|
|
112
|
+
const statusList = statusListId
|
|
113
|
+
? await this.getStatusList({ id: statusListId })
|
|
114
|
+
: await this.getStatusList({ correlationId: statusListCorrelationId })
|
|
115
|
+
|
|
100
116
|
const result = await (
|
|
101
|
-
await this.getStatusListEntryRepo()
|
|
117
|
+
await this.getStatusListEntryRepo(statusList.type)
|
|
102
118
|
).findOne({
|
|
103
119
|
where: {
|
|
104
120
|
...(statusListId && { statusListId }),
|
|
@@ -118,7 +134,9 @@ export class StatusListStore implements IStatusListStore {
|
|
|
118
134
|
return result ?? undefined
|
|
119
135
|
}
|
|
120
136
|
|
|
121
|
-
async getStatusListEntryByCredentialId(
|
|
137
|
+
async getStatusListEntryByCredentialId(
|
|
138
|
+
args: IGetStatusListEntryByCredentialIdArgs,
|
|
139
|
+
): Promise<StatusListEntryEntity | BitstringStatusListEntryEntity | undefined> {
|
|
122
140
|
const credentialId = args.credentialId
|
|
123
141
|
if (!credentialId) {
|
|
124
142
|
throw Error('Can only get a credential by credentialId when a credentialId is supplied')
|
|
@@ -132,8 +150,8 @@ export class StatusListStore implements IStatusListStore {
|
|
|
132
150
|
...(args.entryCorrelationId && { correlationId: args.entryCorrelationId }),
|
|
133
151
|
credentialId,
|
|
134
152
|
}
|
|
135
|
-
|
|
136
|
-
const result = await (await this.getStatusListEntryRepo()).findOne({ where })
|
|
153
|
+
debug(`Entries: ${JSON.stringify(await (await this.getStatusListEntryRepo(statusList.type)).find(), null, 2)}`)
|
|
154
|
+
const result = await (await this.getStatusListEntryRepo(statusList.type)).findOne({ where })
|
|
137
155
|
|
|
138
156
|
if (!result && args.errorOnNotFound) {
|
|
139
157
|
throw Error(`Could not find status list credential id ${credentialId} for status list id ${statusList.id}`)
|
|
@@ -149,8 +167,12 @@ export class StatusListStore implements IStatusListStore {
|
|
|
149
167
|
error = true
|
|
150
168
|
}
|
|
151
169
|
if (!error) {
|
|
170
|
+
const statusList = await this.getStatusList({
|
|
171
|
+
id: args.statusListId,
|
|
172
|
+
correlationId: args.statusListCorrelationId,
|
|
173
|
+
})
|
|
152
174
|
const result = await (
|
|
153
|
-
await this.getStatusListEntryRepo()
|
|
175
|
+
await this.getStatusListEntryRepo(statusList.type)
|
|
154
176
|
).delete({
|
|
155
177
|
...(args.statusListId && { statusList: args.statusListId }),
|
|
156
178
|
...(args.entryCorrelationId && { correlationId: args.entryCorrelationId }),
|
|
@@ -169,10 +191,11 @@ export class StatusListStore implements IStatusListStore {
|
|
|
169
191
|
error = true
|
|
170
192
|
}
|
|
171
193
|
if (error) {
|
|
172
|
-
console.
|
|
194
|
+
console.error(`Could not delete statusList ${args.statusListId} entry by index ${args.statusListIndex}`)
|
|
173
195
|
} else {
|
|
196
|
+
const statusList = await this.getStatusList({ id: args.statusListId })
|
|
174
197
|
const result = await (
|
|
175
|
-
await this.getStatusListEntryRepo()
|
|
198
|
+
await this.getStatusListEntryRepo(statusList.type)
|
|
176
199
|
).delete({
|
|
177
200
|
...(args.statusListId && { statusList: args.statusListId }),
|
|
178
201
|
...(args.entryCorrelationId && { correlationId: args.entryCorrelationId }),
|
|
@@ -183,12 +206,14 @@ export class StatusListStore implements IStatusListStore {
|
|
|
183
206
|
return !error
|
|
184
207
|
}
|
|
185
208
|
|
|
186
|
-
async getStatusListEntries(args: IGetStatusListEntriesArgs): Promise<
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
209
|
+
async getStatusListEntries(args: IGetStatusListEntriesArgs): Promise<Array<IStatusListEntryEntity | IBitstringStatusListEntryEntity>> {
|
|
210
|
+
const statusList = await this.getStatusList({ id: args.statusListId })
|
|
211
|
+
const results = await (
|
|
212
|
+
await this.getStatusListEntryRepo(statusList.type)
|
|
213
|
+
).find({
|
|
214
|
+
where: { ...args?.filter, statusList: args.statusListId },
|
|
215
|
+
})
|
|
216
|
+
return results as Array<IStatusListEntryEntity | IBitstringStatusListEntryEntity>
|
|
192
217
|
}
|
|
193
218
|
|
|
194
219
|
private async getStatusListEntity(args: IGetStatusListArgs): Promise<StatusListEntity> {
|
|
@@ -208,7 +233,12 @@ export class StatusListStore implements IStatusListStore {
|
|
|
208
233
|
return result
|
|
209
234
|
}
|
|
210
235
|
|
|
211
|
-
async
|
|
236
|
+
async getStatusList(args: IGetStatusListArgs): Promise<IStatusListEntity | IBitstringStatusListEntity> {
|
|
237
|
+
const entity = await this.getStatusListEntity(args)
|
|
238
|
+
return statusListFrom(entity) as IStatusListEntity | IBitstringStatusListEntity
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async getStatusLists(args: IGetStatusListsArgs): Promise<Array<IStatusListEntity | IBitstringStatusListEntity>> {
|
|
212
242
|
const result = await (
|
|
213
243
|
await this.getStatusListRepo()
|
|
214
244
|
).find({
|
|
@@ -219,7 +249,7 @@ export class StatusListStore implements IStatusListStore {
|
|
|
219
249
|
return []
|
|
220
250
|
}
|
|
221
251
|
|
|
222
|
-
return result.map((entity) => statusListFrom(entity))
|
|
252
|
+
return result.map((entity) => statusListFrom(entity) as IStatusListEntity | IBitstringStatusListEntity)
|
|
223
253
|
}
|
|
224
254
|
|
|
225
255
|
async addStatusList(args: IAddStatusListArgs): Promise<IStatusListEntity> {
|
|
@@ -240,7 +270,7 @@ export class StatusListStore implements IStatusListStore {
|
|
|
240
270
|
return statusListFrom(createdResult)
|
|
241
271
|
}
|
|
242
272
|
|
|
243
|
-
async updateStatusList(args: IUpdateStatusListIndexArgs): Promise<IStatusListEntity> {
|
|
273
|
+
async updateStatusList(args: IUpdateStatusListIndexArgs): Promise<IStatusListEntity | IBitstringStatusListEntity> {
|
|
244
274
|
const result = await this.getStatusList(args)
|
|
245
275
|
debug('Updating status list', result)
|
|
246
276
|
const entity = statusListEntityFrom(args)
|
|
@@ -251,7 +281,7 @@ export class StatusListStore implements IStatusListStore {
|
|
|
251
281
|
async removeStatusList(args: IRemoveStatusListArgs): Promise<boolean> {
|
|
252
282
|
const result = await this.getStatusListEntity(args)
|
|
253
283
|
|
|
254
|
-
await (await this.getStatusListEntryRepo()).delete({ statusListId: result.id })
|
|
284
|
+
await (await this.getStatusListEntryRepo(result.type)).delete({ statusListId: result.id })
|
|
255
285
|
const deletedEntity = await (await this.getStatusListRepo()).remove(result)
|
|
256
286
|
|
|
257
287
|
return Boolean(deletedEntity)
|
|
@@ -268,12 +298,20 @@ export class StatusListStore implements IStatusListStore {
|
|
|
268
298
|
return dataSource.getRepository(StatusList2021Entity)
|
|
269
299
|
case StatusListType.OAuthStatusList:
|
|
270
300
|
return dataSource.getRepository(OAuthStatusListEntity)
|
|
301
|
+
case StatusListType.BitstringStatusList:
|
|
302
|
+
return dataSource.getRepository(BitstringStatusListEntity)
|
|
271
303
|
default:
|
|
272
304
|
return dataSource.getRepository(StatusListEntity)
|
|
273
305
|
}
|
|
274
306
|
}
|
|
275
307
|
|
|
276
|
-
async getStatusListEntryRepo(): Promise<Repository<StatusListEntryEntity>> {
|
|
277
|
-
|
|
308
|
+
async getStatusListEntryRepo(type?: StatusListType): Promise<Repository<StatusListEntryEntity | BitstringStatusListEntryEntity>> {
|
|
309
|
+
const dataSource = await this.getDS()
|
|
310
|
+
switch (type) {
|
|
311
|
+
case StatusListType.BitstringStatusList:
|
|
312
|
+
return dataSource.getRepository(BitstringStatusListEntryEntity)
|
|
313
|
+
default:
|
|
314
|
+
return dataSource.getRepository(StatusListEntryEntity)
|
|
315
|
+
}
|
|
278
316
|
}
|
|
279
317
|
}
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { FindOptionsWhere } from 'typeorm'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
BitstringStatusPurpose,
|
|
4
|
+
IBitstringStatusListEntryEntity,
|
|
5
|
+
IOAuthStatusListEntity,
|
|
6
|
+
IStatusList2021Entity,
|
|
7
|
+
IStatusListEntryEntity,
|
|
8
|
+
} from './statusList'
|
|
9
|
+
import {
|
|
10
|
+
CredentialProofFormat,
|
|
11
|
+
IIssuer,
|
|
12
|
+
StatusListCredential,
|
|
13
|
+
StatusListCredentialIdMode,
|
|
14
|
+
StatusListDriverType,
|
|
15
|
+
StatusListIndexingDirection,
|
|
16
|
+
StatusListType,
|
|
17
|
+
StatusPurpose2021,
|
|
18
|
+
} from '@sphereon/ssi-types'
|
|
3
19
|
|
|
4
20
|
export type FindStatusListArgs = FindOptionsWhere<IStatusList2021Entity | IOAuthStatusListEntity>[]
|
|
5
21
|
export type FindStatusListEntryArgs = FindOptionsWhere<IStatusListEntryEntity>[] | FindOptionsWhere<IStatusListEntryEntity>
|
|
@@ -30,7 +46,7 @@ export interface IGetStatusListEntriesArgs {
|
|
|
30
46
|
filter?: FindStatusListEntryArgs
|
|
31
47
|
}
|
|
32
48
|
|
|
33
|
-
export type IAddStatusListEntryArgs = IStatusListEntryEntity
|
|
49
|
+
export type IAddStatusListEntryArgs = IStatusListEntryEntity | IBitstringStatusListEntryEntity
|
|
34
50
|
|
|
35
51
|
export interface IGetStatusListArgs {
|
|
36
52
|
id?: string
|
|
@@ -43,6 +59,40 @@ export interface IGetStatusListsArgs {
|
|
|
43
59
|
filter?: FindStatusListArgs
|
|
44
60
|
}
|
|
45
61
|
|
|
46
|
-
|
|
62
|
+
interface IBaseStatusListArgs {
|
|
63
|
+
id: string
|
|
64
|
+
correlationId: string
|
|
65
|
+
driverType: StatusListDriverType
|
|
66
|
+
credentialIdMode: StatusListCredentialIdMode
|
|
67
|
+
length: number
|
|
68
|
+
issuer: string | IIssuer
|
|
69
|
+
type: StatusListType
|
|
70
|
+
proofFormat: CredentialProofFormat
|
|
71
|
+
statusListCredential?: StatusListCredential
|
|
72
|
+
bitsPerStatus?: number
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type IStatusList2021Args = IBaseStatusListArgs & {
|
|
76
|
+
type: StatusListType.StatusList2021
|
|
77
|
+
indexingDirection: StatusListIndexingDirection
|
|
78
|
+
statusPurpose: StatusPurpose2021
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type IOAuthStatusListArgs = IBaseStatusListArgs & {
|
|
82
|
+
type: StatusListType.OAuthStatusList
|
|
83
|
+
bitsPerStatus: number
|
|
84
|
+
expiresAt?: Date
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type IBitstringStatusListArgs = IBaseStatusListArgs & {
|
|
88
|
+
type: StatusListType.BitstringStatusList
|
|
89
|
+
statusPurpose: BitstringStatusPurpose | BitstringStatusPurpose[]
|
|
90
|
+
bitsPerStatus?: number
|
|
91
|
+
validFrom?: Date
|
|
92
|
+
validUntil?: Date
|
|
93
|
+
ttl?: number
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export type IAddStatusListArgs = IStatusList2021Args | IOAuthStatusListArgs | IBitstringStatusListArgs
|
|
47
97
|
|
|
48
|
-
export type IUpdateStatusListIndexArgs =
|
|
98
|
+
export type IUpdateStatusListIndexArgs = IAddStatusListArgs
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
+
type CredentialProofFormat,
|
|
3
|
+
type ICredentialStatus,
|
|
2
4
|
IIssuer,
|
|
5
|
+
RequireOneOf,
|
|
3
6
|
StatusListCredential,
|
|
4
7
|
StatusListCredentialIdMode,
|
|
5
8
|
StatusListDriverType,
|
|
6
9
|
StatusListIndexingDirection,
|
|
7
10
|
StatusListType,
|
|
8
11
|
StatusPurpose2021,
|
|
9
|
-
type CredentialProofFormat,
|
|
10
|
-
RequireOneOf,
|
|
11
12
|
} from '@sphereon/ssi-types'
|
|
12
13
|
import { StatusListEntity } from '../../entities/statusList/StatusListEntities'
|
|
13
14
|
|
|
@@ -21,6 +22,7 @@ export interface IStatusListEntity {
|
|
|
21
22
|
type: StatusListType
|
|
22
23
|
proofFormat: CredentialProofFormat
|
|
23
24
|
statusListCredential?: StatusListCredential
|
|
25
|
+
bitsPerStatus?: number
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
export interface IStatusList2021Entity extends IStatusListEntity {
|
|
@@ -33,6 +35,14 @@ export interface IOAuthStatusListEntity extends IStatusListEntity {
|
|
|
33
35
|
expiresAt?: Date
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
export interface IBitstringStatusListEntity extends IStatusListEntity {
|
|
39
|
+
statusPurpose: BitstringStatusPurpose | Array<BitstringStatusPurpose>
|
|
40
|
+
bitsPerStatus?: number
|
|
41
|
+
validFrom?: Date
|
|
42
|
+
validUntil?: Date
|
|
43
|
+
ttl?: number
|
|
44
|
+
}
|
|
45
|
+
|
|
36
46
|
export type IStatusListEntryEntity = RequireOneOf<
|
|
37
47
|
{
|
|
38
48
|
statusList: StatusListEntity
|
|
@@ -45,3 +55,41 @@ export type IStatusListEntryEntity = RequireOneOf<
|
|
|
45
55
|
},
|
|
46
56
|
'statusList' | 'statusListId'
|
|
47
57
|
>
|
|
58
|
+
|
|
59
|
+
export type BitstringStatusPurpose = 'revocation' | 'suspension' | 'refresh' | 'message' | string // From vc-bitstring-status-lists without pulling in the whole dep for just this one type
|
|
60
|
+
|
|
61
|
+
export type BitstringStatusMessage = {
|
|
62
|
+
status: string
|
|
63
|
+
message?: string
|
|
64
|
+
[x: string]: any
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface BitstringStatusListEntryCredentialStatus extends ICredentialStatus {
|
|
68
|
+
type: 'BitstringStatusListEntry'
|
|
69
|
+
statusPurpose: BitstringStatusPurpose | Array<BitstringStatusPurpose>
|
|
70
|
+
statusListIndex: string
|
|
71
|
+
statusListCredential: string
|
|
72
|
+
bitsPerStatus?: number
|
|
73
|
+
statusMessage?: Array<BitstringStatusMessage>
|
|
74
|
+
statusReference?: string | Array<string>
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type BitstringStatusListArgs = {
|
|
78
|
+
statusPurpose: BitstringStatusPurpose
|
|
79
|
+
bitsPerStatus: number
|
|
80
|
+
ttl?: number
|
|
81
|
+
validFrom?: Date
|
|
82
|
+
validUntil?: Date
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface IBitstringStatusListEntryEntity {
|
|
86
|
+
statusListId: string
|
|
87
|
+
statusListIndex: number
|
|
88
|
+
credentialId?: string
|
|
89
|
+
credentialHash?: string
|
|
90
|
+
entryCorrelationId?: string
|
|
91
|
+
statusPurpose: string
|
|
92
|
+
bitsPerStatus?: number
|
|
93
|
+
statusMessage?: Array<BitstringStatusMessage>
|
|
94
|
+
statusReference?: string | Array<string>
|
|
95
|
+
}
|