@sphereon/ssi-sdk.vc-status-list 0.33.1-feature.vcdm2.tsup.32 → 0.33.1-next.3
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/functions.d.ts +69 -0
- package/dist/functions.d.ts.map +1 -0
- package/dist/functions.js +200 -0
- package/dist/functions.js.map +1 -0
- package/dist/impl/IStatusList.d.ts +26 -0
- package/dist/impl/IStatusList.d.ts.map +1 -0
- package/dist/impl/IStatusList.js +3 -0
- package/dist/impl/IStatusList.js.map +1 -0
- package/dist/impl/OAuthStatusList.d.ts +21 -0
- package/dist/impl/OAuthStatusList.d.ts.map +1 -0
- package/dist/impl/OAuthStatusList.js +155 -0
- package/dist/impl/OAuthStatusList.js.map +1 -0
- package/dist/impl/StatusList2021.d.ts +16 -0
- package/dist/impl/StatusList2021.d.ts.map +1 -0
- package/dist/impl/StatusList2021.js +186 -0
- package/dist/impl/StatusList2021.js.map +1 -0
- package/dist/impl/StatusListFactory.d.ts +11 -0
- package/dist/impl/StatusListFactory.d.ts.map +1 -0
- package/dist/impl/StatusListFactory.js +32 -0
- package/dist/impl/StatusListFactory.js.map +1 -0
- package/dist/impl/encoding/cbor.d.ts +6 -0
- package/dist/impl/encoding/cbor.d.ts.map +1 -0
- package/dist/impl/encoding/cbor.js +140 -0
- package/dist/impl/encoding/cbor.js.map +1 -0
- package/dist/impl/encoding/common.d.ts +12 -0
- package/dist/impl/encoding/common.d.ts.map +1 -0
- package/dist/impl/encoding/common.js +17 -0
- package/dist/impl/encoding/common.js.map +1 -0
- package/dist/impl/encoding/jwt.d.ts +9 -0
- package/dist/impl/encoding/jwt.d.ts.map +1 -0
- package/dist/impl/encoding/jwt.js +74 -0
- package/dist/impl/encoding/jwt.js.map +1 -0
- package/dist/index.d.ts +3 -273
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -944
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +209 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +15 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils.d.ts +17 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +88 -0
- package/dist/utils.js.map +1 -0
- package/package.json +16 -27
- package/src/functions.ts +0 -2
- package/src/impl/encoding/cbor.ts +1 -1
- package/src/types/index.ts +1 -1
- package/dist/index.cjs +0 -977
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -275
package/dist/index.cjs
DELETED
|
@@ -1,977 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
|
|
31
|
-
// src/index.ts
|
|
32
|
-
var index_exports = {};
|
|
33
|
-
__export(index_exports, {
|
|
34
|
-
Status2021: () => Status2021,
|
|
35
|
-
StatusOAuth: () => StatusOAuth,
|
|
36
|
-
checkStatusForCredential: () => checkStatusForCredential,
|
|
37
|
-
checkStatusIndexFromStatusListCredential: () => checkStatusIndexFromStatusListCredential,
|
|
38
|
-
createNewStatusList: () => createNewStatusList,
|
|
39
|
-
fetchStatusListCredential: () => fetchStatusListCredential,
|
|
40
|
-
simpleCheckStatusFromStatusListUrl: () => simpleCheckStatusFromStatusListUrl,
|
|
41
|
-
statusList2021ToVerifiableCredential: () => statusList2021ToVerifiableCredential,
|
|
42
|
-
statusListCredentialToDetails: () => statusListCredentialToDetails,
|
|
43
|
-
statusPluginStatusFunction: () => statusPluginStatusFunction,
|
|
44
|
-
updateStatusIndexFromStatusListCredential: () => updateStatusIndexFromStatusListCredential,
|
|
45
|
-
updateStatusListIndexFromEncodedList: () => updateStatusListIndexFromEncodedList,
|
|
46
|
-
vcLibCheckStatusFunction: () => vcLibCheckStatusFunction
|
|
47
|
-
});
|
|
48
|
-
module.exports = __toCommonJS(index_exports);
|
|
49
|
-
|
|
50
|
-
// src/types/index.ts
|
|
51
|
-
var StatusOAuth = /* @__PURE__ */ function(StatusOAuth2) {
|
|
52
|
-
StatusOAuth2[StatusOAuth2["Valid"] = 0] = "Valid";
|
|
53
|
-
StatusOAuth2[StatusOAuth2["Invalid"] = 1] = "Invalid";
|
|
54
|
-
StatusOAuth2[StatusOAuth2["Suspended"] = 2] = "Suspended";
|
|
55
|
-
return StatusOAuth2;
|
|
56
|
-
}({});
|
|
57
|
-
var Status2021 = /* @__PURE__ */ function(Status20212) {
|
|
58
|
-
Status20212[Status20212["Valid"] = 0] = "Valid";
|
|
59
|
-
Status20212[Status20212["Invalid"] = 1] = "Invalid";
|
|
60
|
-
return Status20212;
|
|
61
|
-
}({});
|
|
62
|
-
|
|
63
|
-
// src/functions.ts
|
|
64
|
-
var import_ssi_types6 = require("@sphereon/ssi-types");
|
|
65
|
-
var import_vc_status_list2 = require("@sphereon/vc-status-list");
|
|
66
|
-
|
|
67
|
-
// src/utils.ts
|
|
68
|
-
var import_ssi_types = require("@sphereon/ssi-types");
|
|
69
|
-
var import_jwt_decode = require("jwt-decode");
|
|
70
|
-
function getAssertedStatusListType(type) {
|
|
71
|
-
const assertedType = type ?? import_ssi_types.StatusListType.StatusList2021;
|
|
72
|
-
if (![
|
|
73
|
-
import_ssi_types.StatusListType.StatusList2021,
|
|
74
|
-
import_ssi_types.StatusListType.OAuthStatusList
|
|
75
|
-
].includes(assertedType)) {
|
|
76
|
-
throw Error(`StatusList type ${assertedType} is not supported (yet)`);
|
|
77
|
-
}
|
|
78
|
-
return assertedType;
|
|
79
|
-
}
|
|
80
|
-
__name(getAssertedStatusListType, "getAssertedStatusListType");
|
|
81
|
-
function getAssertedValue(name, value) {
|
|
82
|
-
if (value === void 0 || value === null) {
|
|
83
|
-
throw Error(`Missing required ${name} value`);
|
|
84
|
-
}
|
|
85
|
-
return value;
|
|
86
|
-
}
|
|
87
|
-
__name(getAssertedValue, "getAssertedValue");
|
|
88
|
-
function getAssertedValues(args) {
|
|
89
|
-
const type = getAssertedStatusListType(args?.type);
|
|
90
|
-
const id = getAssertedValue("id", args.id);
|
|
91
|
-
const issuer = getAssertedValue("issuer", args.issuer);
|
|
92
|
-
return {
|
|
93
|
-
id,
|
|
94
|
-
issuer,
|
|
95
|
-
type
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
__name(getAssertedValues, "getAssertedValues");
|
|
99
|
-
function getAssertedProperty(propertyName, obj) {
|
|
100
|
-
if (!(propertyName in obj)) {
|
|
101
|
-
throw Error(`The input object does not contain required property: ${propertyName}`);
|
|
102
|
-
}
|
|
103
|
-
return getAssertedValue(propertyName, obj[propertyName]);
|
|
104
|
-
}
|
|
105
|
-
__name(getAssertedProperty, "getAssertedProperty");
|
|
106
|
-
var ValidProofTypeMap = /* @__PURE__ */ new Map([
|
|
107
|
-
[
|
|
108
|
-
import_ssi_types.StatusListType.StatusList2021,
|
|
109
|
-
[
|
|
110
|
-
"jwt",
|
|
111
|
-
"lds",
|
|
112
|
-
"EthereumEip712Signature2021"
|
|
113
|
-
]
|
|
114
|
-
],
|
|
115
|
-
[
|
|
116
|
-
import_ssi_types.StatusListType.OAuthStatusList,
|
|
117
|
-
[
|
|
118
|
-
"jwt",
|
|
119
|
-
"cbor"
|
|
120
|
-
]
|
|
121
|
-
]
|
|
122
|
-
]);
|
|
123
|
-
function assertValidProofType(type, proofFormat) {
|
|
124
|
-
const validProofTypes = ValidProofTypeMap.get(type);
|
|
125
|
-
if (!validProofTypes?.includes(proofFormat)) {
|
|
126
|
-
throw Error(`Invalid proof format '${proofFormat}' for status list type ${type}`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
__name(assertValidProofType, "assertValidProofType");
|
|
130
|
-
function determineStatusListType(credential) {
|
|
131
|
-
const proofFormat = determineProofFormat(credential);
|
|
132
|
-
switch (proofFormat) {
|
|
133
|
-
case "jwt":
|
|
134
|
-
const payload = (0, import_jwt_decode.jwtDecode)(credential);
|
|
135
|
-
const keys = Object.keys(payload);
|
|
136
|
-
if (keys.includes("status_list")) {
|
|
137
|
-
return import_ssi_types.StatusListType.OAuthStatusList;
|
|
138
|
-
} else if (keys.includes("vc")) {
|
|
139
|
-
return import_ssi_types.StatusListType.StatusList2021;
|
|
140
|
-
}
|
|
141
|
-
break;
|
|
142
|
-
case "lds":
|
|
143
|
-
const uniform = import_ssi_types.CredentialMapper.toUniformCredential(credential);
|
|
144
|
-
const type = uniform.type.find((t) => {
|
|
145
|
-
return Object.values(import_ssi_types.StatusListType).some((statusType) => t.includes(statusType));
|
|
146
|
-
});
|
|
147
|
-
if (!type) {
|
|
148
|
-
throw new Error("Invalid status list credential type");
|
|
149
|
-
}
|
|
150
|
-
return type.replace("Credential", "");
|
|
151
|
-
case "cbor":
|
|
152
|
-
return import_ssi_types.StatusListType.OAuthStatusList;
|
|
153
|
-
}
|
|
154
|
-
throw new Error("Cannot determine status list type from credential payload");
|
|
155
|
-
}
|
|
156
|
-
__name(determineStatusListType, "determineStatusListType");
|
|
157
|
-
function determineProofFormat(credential) {
|
|
158
|
-
const type = import_ssi_types.CredentialMapper.detectDocumentType(credential);
|
|
159
|
-
switch (type) {
|
|
160
|
-
case import_ssi_types.DocumentFormat.JWT:
|
|
161
|
-
return "jwt";
|
|
162
|
-
case import_ssi_types.DocumentFormat.MSO_MDOC:
|
|
163
|
-
return "cbor";
|
|
164
|
-
case import_ssi_types.DocumentFormat.JSONLD:
|
|
165
|
-
return "lds";
|
|
166
|
-
default:
|
|
167
|
-
throw Error("Cannot determine credential payload type");
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
__name(determineProofFormat, "determineProofFormat");
|
|
171
|
-
|
|
172
|
-
// src/impl/StatusList2021.ts
|
|
173
|
-
var import_ssi_types2 = require("@sphereon/ssi-types");
|
|
174
|
-
var import_vc_status_list = require("@sphereon/vc-status-list");
|
|
175
|
-
var DEFAULT_LIST_LENGTH = 25e4;
|
|
176
|
-
var DEFAULT_PROOF_FORMAT = "lds";
|
|
177
|
-
var StatusList2021Implementation = class {
|
|
178
|
-
static {
|
|
179
|
-
__name(this, "StatusList2021Implementation");
|
|
180
|
-
}
|
|
181
|
-
async createNewStatusList(args, context) {
|
|
182
|
-
const length = args?.length ?? DEFAULT_LIST_LENGTH;
|
|
183
|
-
const proofFormat = args?.proofFormat ?? DEFAULT_PROOF_FORMAT;
|
|
184
|
-
assertValidProofType(import_ssi_types2.StatusListType.StatusList2021, proofFormat);
|
|
185
|
-
const veramoProofFormat = proofFormat;
|
|
186
|
-
const { issuer, id } = args;
|
|
187
|
-
const correlationId = getAssertedValue("correlationId", args.correlationId);
|
|
188
|
-
const list = new import_vc_status_list.StatusList({
|
|
189
|
-
length
|
|
190
|
-
});
|
|
191
|
-
const encodedList = await list.encode();
|
|
192
|
-
const statusPurpose = "revocation";
|
|
193
|
-
const statusListCredential = await this.createVerifiableCredential({
|
|
194
|
-
...args,
|
|
195
|
-
encodedList,
|
|
196
|
-
proofFormat: veramoProofFormat
|
|
197
|
-
}, context);
|
|
198
|
-
return {
|
|
199
|
-
encodedList,
|
|
200
|
-
statusListCredential,
|
|
201
|
-
statusList2021: {
|
|
202
|
-
statusPurpose,
|
|
203
|
-
indexingDirection: "rightToLeft"
|
|
204
|
-
},
|
|
205
|
-
length,
|
|
206
|
-
type: import_ssi_types2.StatusListType.StatusList2021,
|
|
207
|
-
proofFormat,
|
|
208
|
-
id,
|
|
209
|
-
correlationId,
|
|
210
|
-
issuer,
|
|
211
|
-
statuslistContentType: this.buildContentType(proofFormat)
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
async updateStatusListIndex(args, context) {
|
|
215
|
-
const credential = args.statusListCredential;
|
|
216
|
-
const uniform = import_ssi_types2.CredentialMapper.toUniformCredential(credential);
|
|
217
|
-
const { issuer, credentialSubject } = uniform;
|
|
218
|
-
const id = getAssertedValue("id", uniform.id);
|
|
219
|
-
const origEncodedList = getAssertedProperty("encodedList", credentialSubject);
|
|
220
|
-
const index = typeof args.statusListIndex === "number" ? args.statusListIndex : parseInt(args.statusListIndex);
|
|
221
|
-
const statusList = await import_vc_status_list.StatusList.decode({
|
|
222
|
-
encodedList: origEncodedList
|
|
223
|
-
});
|
|
224
|
-
statusList.setStatus(index, args.value != 0);
|
|
225
|
-
const encodedList = await statusList.encode();
|
|
226
|
-
const proofFormat = import_ssi_types2.CredentialMapper.detectDocumentType(credential) === import_ssi_types2.DocumentFormat.JWT ? "jwt" : "lds";
|
|
227
|
-
const updatedCredential = await this.createVerifiableCredential({
|
|
228
|
-
...args,
|
|
229
|
-
id,
|
|
230
|
-
issuer,
|
|
231
|
-
encodedList,
|
|
232
|
-
proofFormat
|
|
233
|
-
}, context);
|
|
234
|
-
return {
|
|
235
|
-
statusListCredential: updatedCredential,
|
|
236
|
-
encodedList,
|
|
237
|
-
statusList2021: {
|
|
238
|
-
..."statusPurpose" in credentialSubject ? {
|
|
239
|
-
statusPurpose: credentialSubject.statusPurpose
|
|
240
|
-
} : {},
|
|
241
|
-
indexingDirection: "rightToLeft"
|
|
242
|
-
},
|
|
243
|
-
length: statusList.length - 1,
|
|
244
|
-
type: import_ssi_types2.StatusListType.StatusList2021,
|
|
245
|
-
proofFormat,
|
|
246
|
-
id,
|
|
247
|
-
issuer,
|
|
248
|
-
statuslistContentType: this.buildContentType(proofFormat)
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
async updateStatusListFromEncodedList(args, context) {
|
|
252
|
-
if (!args.statusList2021) {
|
|
253
|
-
throw new Error("statusList2021 options required for type StatusList2021");
|
|
254
|
-
}
|
|
255
|
-
const proofFormat = args?.proofFormat ?? DEFAULT_PROOF_FORMAT;
|
|
256
|
-
assertValidProofType(import_ssi_types2.StatusListType.StatusList2021, proofFormat);
|
|
257
|
-
const veramoProofFormat = proofFormat;
|
|
258
|
-
const { issuer, id } = getAssertedValues(args);
|
|
259
|
-
const statusList = await import_vc_status_list.StatusList.decode({
|
|
260
|
-
encodedList: args.encodedList
|
|
261
|
-
});
|
|
262
|
-
const index = typeof args.statusListIndex === "number" ? args.statusListIndex : parseInt(args.statusListIndex);
|
|
263
|
-
statusList.setStatus(index, args.value);
|
|
264
|
-
const newEncodedList = await statusList.encode();
|
|
265
|
-
const credential = await this.createVerifiableCredential({
|
|
266
|
-
id,
|
|
267
|
-
issuer,
|
|
268
|
-
encodedList: newEncodedList,
|
|
269
|
-
proofFormat: veramoProofFormat,
|
|
270
|
-
keyRef: args.keyRef
|
|
271
|
-
}, context);
|
|
272
|
-
return {
|
|
273
|
-
type: import_ssi_types2.StatusListType.StatusList2021,
|
|
274
|
-
statusListCredential: credential,
|
|
275
|
-
encodedList: newEncodedList,
|
|
276
|
-
statusList2021: {
|
|
277
|
-
statusPurpose: args.statusList2021.statusPurpose,
|
|
278
|
-
indexingDirection: "rightToLeft"
|
|
279
|
-
},
|
|
280
|
-
length: statusList.length,
|
|
281
|
-
proofFormat: args.proofFormat ?? "lds",
|
|
282
|
-
id,
|
|
283
|
-
issuer,
|
|
284
|
-
statuslistContentType: this.buildContentType(proofFormat)
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
async checkStatusIndex(args) {
|
|
288
|
-
const uniform = import_ssi_types2.CredentialMapper.toUniformCredential(args.statusListCredential);
|
|
289
|
-
const { credentialSubject } = uniform;
|
|
290
|
-
const encodedList = getAssertedProperty("encodedList", credentialSubject);
|
|
291
|
-
const statusList = await import_vc_status_list.StatusList.decode({
|
|
292
|
-
encodedList
|
|
293
|
-
});
|
|
294
|
-
const status = statusList.getStatus(typeof args.statusListIndex === "number" ? args.statusListIndex : parseInt(args.statusListIndex));
|
|
295
|
-
return status ? Status2021.Invalid : Status2021.Valid;
|
|
296
|
-
}
|
|
297
|
-
async toStatusListDetails(args) {
|
|
298
|
-
const { statusListPayload } = args;
|
|
299
|
-
const uniform = import_ssi_types2.CredentialMapper.toUniformCredential(statusListPayload);
|
|
300
|
-
const { issuer, credentialSubject } = uniform;
|
|
301
|
-
const id = getAssertedValue("id", uniform.id);
|
|
302
|
-
const encodedList = getAssertedProperty("encodedList", credentialSubject);
|
|
303
|
-
const proofFormat = import_ssi_types2.CredentialMapper.detectDocumentType(statusListPayload) === import_ssi_types2.DocumentFormat.JWT ? "jwt" : "lds";
|
|
304
|
-
const statusPurpose = getAssertedProperty("statusPurpose", credentialSubject);
|
|
305
|
-
const list = await import_vc_status_list.StatusList.decode({
|
|
306
|
-
encodedList
|
|
307
|
-
});
|
|
308
|
-
return {
|
|
309
|
-
id,
|
|
310
|
-
encodedList,
|
|
311
|
-
issuer,
|
|
312
|
-
type: import_ssi_types2.StatusListType.StatusList2021,
|
|
313
|
-
proofFormat,
|
|
314
|
-
length: list.length,
|
|
315
|
-
statusListCredential: statusListPayload,
|
|
316
|
-
statuslistContentType: this.buildContentType(proofFormat),
|
|
317
|
-
statusList2021: {
|
|
318
|
-
indexingDirection: "rightToLeft",
|
|
319
|
-
statusPurpose
|
|
320
|
-
},
|
|
321
|
-
...args.correlationId && {
|
|
322
|
-
correlationId: args.correlationId
|
|
323
|
-
},
|
|
324
|
-
...args.driverType && {
|
|
325
|
-
driverType: args.driverType
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
async createVerifiableCredential(args, context) {
|
|
330
|
-
const identifier = await context.agent.identifierManagedGet({
|
|
331
|
-
identifier: typeof args.issuer === "string" ? args.issuer : args.issuer.id,
|
|
332
|
-
vmRelationship: "assertionMethod",
|
|
333
|
-
offlineWhenNoDIDRegistered: true
|
|
334
|
-
});
|
|
335
|
-
const credential = {
|
|
336
|
-
"@context": [
|
|
337
|
-
"https://www.w3.org/2018/credentials/v1",
|
|
338
|
-
"https://w3id.org/vc/status-list/2021/v1"
|
|
339
|
-
],
|
|
340
|
-
id: args.id,
|
|
341
|
-
issuer: args.issuer,
|
|
342
|
-
type: [
|
|
343
|
-
"VerifiableCredential",
|
|
344
|
-
"StatusList2021Credential"
|
|
345
|
-
],
|
|
346
|
-
credentialSubject: {
|
|
347
|
-
id: args.id,
|
|
348
|
-
type: "StatusList2021",
|
|
349
|
-
statusPurpose: "revocation",
|
|
350
|
-
encodedList: args.encodedList
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
const verifiableCredential = await context.agent.createVerifiableCredential({
|
|
354
|
-
credential,
|
|
355
|
-
keyRef: args.keyRef ?? identifier.kmsKeyRef,
|
|
356
|
-
proofFormat: args.proofFormat,
|
|
357
|
-
fetchRemoteContexts: true
|
|
358
|
-
});
|
|
359
|
-
return import_ssi_types2.CredentialMapper.toWrappedVerifiableCredential(verifiableCredential).original;
|
|
360
|
-
}
|
|
361
|
-
buildContentType(proofFormat) {
|
|
362
|
-
switch (proofFormat) {
|
|
363
|
-
case "jwt":
|
|
364
|
-
return `application/statuslist+jwt`;
|
|
365
|
-
case "cbor":
|
|
366
|
-
return `application/statuslist+cwt`;
|
|
367
|
-
case "lds":
|
|
368
|
-
return "application/statuslist+ld+json";
|
|
369
|
-
default:
|
|
370
|
-
throw Error(`Unsupported content type '${proofFormat}' for status lists`);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
// src/impl/OAuthStatusList.ts
|
|
376
|
-
var import_ssi_types4 = require("@sphereon/ssi-types");
|
|
377
|
-
var import_jwt_status_list3 = require("@sd-jwt/jwt-status-list");
|
|
378
|
-
|
|
379
|
-
// src/impl/encoding/jwt.ts
|
|
380
|
-
var import_ssi_types3 = require("@sphereon/ssi-types");
|
|
381
|
-
var import_jwt_status_list = require("@sd-jwt/jwt-status-list");
|
|
382
|
-
var import_base64url = __toESM(require("base64url"), 1);
|
|
383
|
-
|
|
384
|
-
// src/impl/encoding/common.ts
|
|
385
|
-
var resolveIdentifier = /* @__PURE__ */ __name(async (context, issuer, keyRef) => {
|
|
386
|
-
return await context.agent.identifierManagedGet({
|
|
387
|
-
identifier: issuer,
|
|
388
|
-
vmRelationship: "assertionMethod",
|
|
389
|
-
offlineWhenNoDIDRegistered: true,
|
|
390
|
-
...keyRef && {
|
|
391
|
-
kmsKeyRef: keyRef
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
}, "resolveIdentifier");
|
|
395
|
-
|
|
396
|
-
// src/impl/encoding/jwt.ts
|
|
397
|
-
var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.identifier-resolution");
|
|
398
|
-
var STATUS_LIST_JWT_TYP = "statuslist+jwt";
|
|
399
|
-
var createSignedJwt = /* @__PURE__ */ __name(async (context, statusList, issuerString, id, expiresAt, keyRef) => {
|
|
400
|
-
const identifier = await resolveIdentifier(context, issuerString, keyRef);
|
|
401
|
-
const resolution = await (0, import_ssi_sdk_ext.ensureManagedIdentifierResult)(identifier, context);
|
|
402
|
-
const payload = {
|
|
403
|
-
iss: issuerString,
|
|
404
|
-
sub: id,
|
|
405
|
-
iat: Math.floor(Date.now() / 1e3),
|
|
406
|
-
...expiresAt && {
|
|
407
|
-
exp: Math.floor(expiresAt.getTime() / 1e3)
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
const header = {
|
|
411
|
-
alg: getSigningAlgo(resolution.key.type),
|
|
412
|
-
typ: STATUS_LIST_JWT_TYP
|
|
413
|
-
};
|
|
414
|
-
const values = (0, import_jwt_status_list.createHeaderAndPayload)(statusList, payload, header);
|
|
415
|
-
const signedJwt = await context.agent.jwtCreateJwsCompactSignature({
|
|
416
|
-
issuer: {
|
|
417
|
-
...identifier,
|
|
418
|
-
noIssPayloadUpdate: false
|
|
419
|
-
},
|
|
420
|
-
protectedHeader: values.header,
|
|
421
|
-
payload: values.payload
|
|
422
|
-
});
|
|
423
|
-
return {
|
|
424
|
-
statusListCredential: signedJwt.jwt,
|
|
425
|
-
encodedList: values.payload.status_list.lst
|
|
426
|
-
};
|
|
427
|
-
}, "createSignedJwt");
|
|
428
|
-
var decodeStatusListJWT = /* @__PURE__ */ __name((jwt) => {
|
|
429
|
-
const [, payloadBase64] = jwt.split(".");
|
|
430
|
-
const payload = JSON.parse(import_base64url.default.decode(payloadBase64));
|
|
431
|
-
if (!payload.iss || !payload.sub || !payload.status_list) {
|
|
432
|
-
throw new Error("Missing required fields in JWT payload");
|
|
433
|
-
}
|
|
434
|
-
const statusList = import_jwt_status_list.StatusList.decompressStatusList(payload.status_list.lst, payload.status_list.bits);
|
|
435
|
-
return {
|
|
436
|
-
issuer: payload.iss,
|
|
437
|
-
id: payload.sub,
|
|
438
|
-
statusList,
|
|
439
|
-
exp: payload.exp,
|
|
440
|
-
ttl: payload.ttl,
|
|
441
|
-
iat: payload.iat
|
|
442
|
-
};
|
|
443
|
-
}, "decodeStatusListJWT");
|
|
444
|
-
var getSigningAlgo = /* @__PURE__ */ __name((type) => {
|
|
445
|
-
switch (type) {
|
|
446
|
-
case "Ed25519":
|
|
447
|
-
return import_ssi_types3.JoseSignatureAlgorithm.EdDSA;
|
|
448
|
-
case "Secp256k1":
|
|
449
|
-
return import_ssi_types3.JoseSignatureAlgorithm.ES256K;
|
|
450
|
-
case "Secp256r1":
|
|
451
|
-
return import_ssi_types3.JoseSignatureAlgorithm.ES256;
|
|
452
|
-
case "RSA":
|
|
453
|
-
return import_ssi_types3.JoseSignatureAlgorithm.RS256;
|
|
454
|
-
default:
|
|
455
|
-
throw Error("Key type not yet supported");
|
|
456
|
-
}
|
|
457
|
-
}, "getSigningAlgo");
|
|
458
|
-
|
|
459
|
-
// src/impl/encoding/cbor.ts
|
|
460
|
-
var import_jwt_status_list2 = require("@sd-jwt/jwt-status-list");
|
|
461
|
-
var import_pako = require("pako");
|
|
462
|
-
var import_kmp_cbor = require("@sphereon/kmp-cbor");
|
|
463
|
-
var import_base64url2 = __toESM(require("base64url"), 1);
|
|
464
|
-
var cbor = import_kmp_cbor.com.sphereon.cbor;
|
|
465
|
-
var kmp = import_kmp_cbor.com.sphereon.kmp;
|
|
466
|
-
var decompressRawStatusList = import_jwt_status_list2.StatusList.decodeStatusList.bind(import_jwt_status_list2.StatusList);
|
|
467
|
-
var CWT_CLAIMS = {
|
|
468
|
-
SUBJECT: 2,
|
|
469
|
-
ISSUER: 1,
|
|
470
|
-
ISSUED_AT: 6,
|
|
471
|
-
EXPIRATION: 4,
|
|
472
|
-
TIME_TO_LIVE: 65534,
|
|
473
|
-
STATUS_LIST: 65533
|
|
474
|
-
};
|
|
475
|
-
var createSignedCbor = /* @__PURE__ */ __name(async (context, statusList, issuerString, id, expiresAt, keyRef) => {
|
|
476
|
-
const identifier = await resolveIdentifier(context, issuerString, keyRef);
|
|
477
|
-
const encodeStatusList = statusList.encodeStatusList();
|
|
478
|
-
const compressedList = (0, import_pako.deflate)(encodeStatusList, {
|
|
479
|
-
level: 9
|
|
480
|
-
});
|
|
481
|
-
const compressedBytes = new Int8Array(compressedList);
|
|
482
|
-
const statusListMap = new cbor.CborMap(import_kmp_cbor.kotlin.collections.KtMutableMap.fromJsMap(/* @__PURE__ */ new Map([
|
|
483
|
-
[
|
|
484
|
-
new cbor.CborString("bits"),
|
|
485
|
-
new cbor.CborUInt(kmp.LongKMP.fromNumber(statusList.getBitsPerStatus()))
|
|
486
|
-
],
|
|
487
|
-
[
|
|
488
|
-
new cbor.CborString("lst"),
|
|
489
|
-
new cbor.CborByteString(compressedBytes)
|
|
490
|
-
]
|
|
491
|
-
])));
|
|
492
|
-
const protectedHeader = new cbor.CborMap(import_kmp_cbor.kotlin.collections.KtMutableMap.fromJsMap(/* @__PURE__ */ new Map([
|
|
493
|
-
[
|
|
494
|
-
new cbor.CborUInt(kmp.LongKMP.fromNumber(16)),
|
|
495
|
-
new cbor.CborString("statuslist+cwt")
|
|
496
|
-
]
|
|
497
|
-
])));
|
|
498
|
-
const protectedHeaderEncoded = cbor.Cbor.encode(protectedHeader);
|
|
499
|
-
const claimsMap = buildClaimsMap(id, issuerString, statusListMap, expiresAt);
|
|
500
|
-
const claimsEncoded = cbor.Cbor.encode(claimsMap);
|
|
501
|
-
const signedCWT = await context.agent.keyManagerSign({
|
|
502
|
-
keyRef: identifier.kmsKeyRef,
|
|
503
|
-
data: import_base64url2.default.encode(Buffer.from(claimsEncoded)),
|
|
504
|
-
encoding: void 0
|
|
505
|
-
});
|
|
506
|
-
const protectedHeaderEncodedInt8 = new Int8Array(protectedHeaderEncoded);
|
|
507
|
-
const claimsEncodedInt8 = new Int8Array(claimsEncoded);
|
|
508
|
-
const signatureBytes = import_base64url2.default.decode(signedCWT);
|
|
509
|
-
const signatureInt8 = new Int8Array(Buffer.from(signatureBytes));
|
|
510
|
-
const cwtArrayElements = [
|
|
511
|
-
new cbor.CborByteString(protectedHeaderEncodedInt8),
|
|
512
|
-
new cbor.CborByteString(claimsEncodedInt8),
|
|
513
|
-
new cbor.CborByteString(signatureInt8)
|
|
514
|
-
];
|
|
515
|
-
const cwtArray = new cbor.CborArray(import_kmp_cbor.kotlin.collections.KtMutableList.fromJsArray(cwtArrayElements));
|
|
516
|
-
const cwtEncoded = cbor.Cbor.encode(cwtArray);
|
|
517
|
-
const cwtBuffer = Buffer.from(cwtEncoded);
|
|
518
|
-
return {
|
|
519
|
-
statusListCredential: import_base64url2.default.encode(cwtBuffer),
|
|
520
|
-
encodedList: import_base64url2.default.encode(compressedList)
|
|
521
|
-
};
|
|
522
|
-
}, "createSignedCbor");
|
|
523
|
-
function buildClaimsMap(id, issuerString, statusListMap, expiresAt) {
|
|
524
|
-
const ttl = 65535;
|
|
525
|
-
const claimsEntries = [
|
|
526
|
-
[
|
|
527
|
-
new cbor.CborUInt(kmp.LongKMP.fromNumber(CWT_CLAIMS.SUBJECT)),
|
|
528
|
-
new cbor.CborString(id)
|
|
529
|
-
],
|
|
530
|
-
[
|
|
531
|
-
new cbor.CborUInt(kmp.LongKMP.fromNumber(CWT_CLAIMS.ISSUER)),
|
|
532
|
-
new cbor.CborString(issuerString)
|
|
533
|
-
],
|
|
534
|
-
[
|
|
535
|
-
new cbor.CborUInt(kmp.LongKMP.fromNumber(CWT_CLAIMS.ISSUED_AT)),
|
|
536
|
-
new cbor.CborUInt(kmp.LongKMP.fromNumber(Math.floor(Date.now() / 1e3)))
|
|
537
|
-
]
|
|
538
|
-
];
|
|
539
|
-
if (expiresAt) {
|
|
540
|
-
claimsEntries.push([
|
|
541
|
-
new cbor.CborUInt(kmp.LongKMP.fromNumber(CWT_CLAIMS.EXPIRATION)),
|
|
542
|
-
new cbor.CborUInt(kmp.LongKMP.fromNumber(Math.floor(expiresAt.getTime() / 1e3)))
|
|
543
|
-
]);
|
|
544
|
-
}
|
|
545
|
-
if (ttl) {
|
|
546
|
-
claimsEntries.push([
|
|
547
|
-
new cbor.CborUInt(kmp.LongKMP.fromNumber(CWT_CLAIMS.TIME_TO_LIVE)),
|
|
548
|
-
new cbor.CborUInt(kmp.LongKMP.fromNumber(ttl))
|
|
549
|
-
]);
|
|
550
|
-
}
|
|
551
|
-
claimsEntries.push([
|
|
552
|
-
new cbor.CborUInt(kmp.LongKMP.fromNumber(CWT_CLAIMS.STATUS_LIST)),
|
|
553
|
-
statusListMap
|
|
554
|
-
]);
|
|
555
|
-
const claimsMap = new cbor.CborMap(import_kmp_cbor.kotlin.collections.KtMutableMap.fromJsMap(new Map(claimsEntries)));
|
|
556
|
-
return claimsMap;
|
|
557
|
-
}
|
|
558
|
-
__name(buildClaimsMap, "buildClaimsMap");
|
|
559
|
-
var getCborValueFromMap = /* @__PURE__ */ __name((map, key) => {
|
|
560
|
-
const value = getCborOptionalValueFromMap(map, key);
|
|
561
|
-
if (value === void 0) {
|
|
562
|
-
throw new Error(`Required claim ${key} not found`);
|
|
563
|
-
}
|
|
564
|
-
return value;
|
|
565
|
-
}, "getCborValueFromMap");
|
|
566
|
-
var getCborOptionalValueFromMap = /* @__PURE__ */ __name((map, key) => {
|
|
567
|
-
const value = map.get(new import_kmp_cbor.com.sphereon.cbor.CborUInt(kmp.LongKMP.fromNumber(key)));
|
|
568
|
-
if (!value) {
|
|
569
|
-
return void 0;
|
|
570
|
-
}
|
|
571
|
-
return value.value;
|
|
572
|
-
}, "getCborOptionalValueFromMap");
|
|
573
|
-
var decodeStatusListCWT = /* @__PURE__ */ __name((cwt) => {
|
|
574
|
-
const encodedCbor = import_base64url2.default.toBuffer(cwt);
|
|
575
|
-
const encodedCborArray = new Int8Array(encodedCbor);
|
|
576
|
-
const decodedCbor = import_kmp_cbor.com.sphereon.cbor.Cbor.decode(encodedCborArray);
|
|
577
|
-
if (!(decodedCbor instanceof import_kmp_cbor.com.sphereon.cbor.CborArray)) {
|
|
578
|
-
throw new Error("Invalid CWT format: Expected a CBOR array");
|
|
579
|
-
}
|
|
580
|
-
const [, payload] = decodedCbor.value.asJsArrayView();
|
|
581
|
-
if (!(payload instanceof import_kmp_cbor.com.sphereon.cbor.CborByteString)) {
|
|
582
|
-
throw new Error("Invalid payload format: Expected a CBOR ByteString");
|
|
583
|
-
}
|
|
584
|
-
const claims = import_kmp_cbor.com.sphereon.cbor.Cbor.decode(payload.value);
|
|
585
|
-
if (!(claims instanceof import_kmp_cbor.com.sphereon.cbor.CborMap)) {
|
|
586
|
-
throw new Error("Invalid claims format: Expected a CBOR map");
|
|
587
|
-
}
|
|
588
|
-
const claimsMap = claims.value.asJsMapView();
|
|
589
|
-
const statusListMap = claimsMap.get(new import_kmp_cbor.com.sphereon.cbor.CborUInt(kmp.LongKMP.fromNumber(65533))).value.asJsMapView();
|
|
590
|
-
const bits = Number(statusListMap.get(new import_kmp_cbor.com.sphereon.cbor.CborString("bits")).value);
|
|
591
|
-
const decoded = new Uint8Array(statusListMap.get(new import_kmp_cbor.com.sphereon.cbor.CborString("lst")).value);
|
|
592
|
-
const uint8Array = (0, import_pako.inflate)(decoded);
|
|
593
|
-
const rawStatusList = decompressRawStatusList(uint8Array, bits);
|
|
594
|
-
const statusList = new import_jwt_status_list2.StatusList(rawStatusList, bits);
|
|
595
|
-
return {
|
|
596
|
-
issuer: getCborValueFromMap(claimsMap, CWT_CLAIMS.ISSUER),
|
|
597
|
-
id: getCborValueFromMap(claimsMap, CWT_CLAIMS.SUBJECT),
|
|
598
|
-
statusList,
|
|
599
|
-
iat: Number(getCborValueFromMap(claimsMap, CWT_CLAIMS.ISSUED_AT)),
|
|
600
|
-
exp: getCborOptionalValueFromMap(claimsMap, CWT_CLAIMS.EXPIRATION),
|
|
601
|
-
ttl: getCborOptionalValueFromMap(claimsMap, CWT_CLAIMS.TIME_TO_LIVE)
|
|
602
|
-
};
|
|
603
|
-
}, "decodeStatusListCWT");
|
|
604
|
-
|
|
605
|
-
// src/impl/OAuthStatusList.ts
|
|
606
|
-
var DEFAULT_BITS_PER_STATUS = 1;
|
|
607
|
-
var DEFAULT_LIST_LENGTH2 = 25e4;
|
|
608
|
-
var DEFAULT_PROOF_FORMAT2 = "jwt";
|
|
609
|
-
var OAuthStatusListImplementation = class {
|
|
610
|
-
static {
|
|
611
|
-
__name(this, "OAuthStatusListImplementation");
|
|
612
|
-
}
|
|
613
|
-
async createNewStatusList(args, context) {
|
|
614
|
-
if (!args.oauthStatusList) {
|
|
615
|
-
throw new Error("OAuthStatusList options are required for type OAuthStatusList");
|
|
616
|
-
}
|
|
617
|
-
const proofFormat = args?.proofFormat ?? DEFAULT_PROOF_FORMAT2;
|
|
618
|
-
const { issuer, id, oauthStatusList, keyRef } = args;
|
|
619
|
-
const { bitsPerStatus, expiresAt } = oauthStatusList;
|
|
620
|
-
const length = args.length ?? DEFAULT_LIST_LENGTH2;
|
|
621
|
-
const issuerString = typeof issuer === "string" ? issuer : issuer.id;
|
|
622
|
-
const correlationId = getAssertedValue("correlationId", args.correlationId);
|
|
623
|
-
const statusList = new import_jwt_status_list3.StatusList(new Array(length).fill(0), bitsPerStatus ?? DEFAULT_BITS_PER_STATUS);
|
|
624
|
-
const encodedList = statusList.compressStatusList();
|
|
625
|
-
const { statusListCredential } = await this.createSignedStatusList(proofFormat, context, statusList, issuerString, id, expiresAt, keyRef);
|
|
626
|
-
return {
|
|
627
|
-
encodedList,
|
|
628
|
-
statusListCredential,
|
|
629
|
-
oauthStatusList: {
|
|
630
|
-
bitsPerStatus
|
|
631
|
-
},
|
|
632
|
-
length,
|
|
633
|
-
type: import_ssi_types4.StatusListType.OAuthStatusList,
|
|
634
|
-
proofFormat,
|
|
635
|
-
id,
|
|
636
|
-
correlationId,
|
|
637
|
-
issuer,
|
|
638
|
-
statuslistContentType: this.buildContentType(proofFormat)
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
async updateStatusListIndex(args, context) {
|
|
642
|
-
const { statusListCredential, value, expiresAt, keyRef } = args;
|
|
643
|
-
if (typeof statusListCredential !== "string") {
|
|
644
|
-
return Promise.reject("statusListCredential in neither JWT nor CWT");
|
|
645
|
-
}
|
|
646
|
-
const proofFormat = determineProofFormat(statusListCredential);
|
|
647
|
-
const decoded = proofFormat === "jwt" ? decodeStatusListJWT(statusListCredential) : decodeStatusListCWT(statusListCredential);
|
|
648
|
-
const { statusList, issuer, id } = decoded;
|
|
649
|
-
const index = typeof args.statusListIndex === "number" ? args.statusListIndex : parseInt(args.statusListIndex);
|
|
650
|
-
if (index < 0 || index >= statusList.statusList.length) {
|
|
651
|
-
throw new Error("Status list index out of bounds");
|
|
652
|
-
}
|
|
653
|
-
statusList.setStatus(index, value);
|
|
654
|
-
const { statusListCredential: signedCredential, encodedList } = await this.createSignedStatusList(proofFormat, context, statusList, issuer, id, expiresAt, keyRef);
|
|
655
|
-
return {
|
|
656
|
-
statusListCredential: signedCredential,
|
|
657
|
-
encodedList,
|
|
658
|
-
oauthStatusList: {
|
|
659
|
-
bitsPerStatus: statusList.getBitsPerStatus()
|
|
660
|
-
},
|
|
661
|
-
length: statusList.statusList.length,
|
|
662
|
-
type: import_ssi_types4.StatusListType.OAuthStatusList,
|
|
663
|
-
proofFormat,
|
|
664
|
-
id,
|
|
665
|
-
issuer,
|
|
666
|
-
statuslistContentType: this.buildContentType(proofFormat)
|
|
667
|
-
};
|
|
668
|
-
}
|
|
669
|
-
// FIXME: This still assumes only two values (boolean), whilst this list supports 8 bits max
|
|
670
|
-
async updateStatusListFromEncodedList(args, context) {
|
|
671
|
-
if (!args.oauthStatusList) {
|
|
672
|
-
throw new Error("OAuthStatusList options are required for type OAuthStatusList");
|
|
673
|
-
}
|
|
674
|
-
const { proofFormat, oauthStatusList, keyRef } = args;
|
|
675
|
-
const { bitsPerStatus, expiresAt } = oauthStatusList;
|
|
676
|
-
const { issuer, id } = getAssertedValues(args);
|
|
677
|
-
const issuerString = typeof issuer === "string" ? issuer : issuer.id;
|
|
678
|
-
const listToUpdate = import_jwt_status_list3.StatusList.decompressStatusList(args.encodedList, bitsPerStatus ?? DEFAULT_BITS_PER_STATUS);
|
|
679
|
-
const index = typeof args.statusListIndex === "number" ? args.statusListIndex : parseInt(args.statusListIndex);
|
|
680
|
-
listToUpdate.setStatus(index, args.value ? 1 : 0);
|
|
681
|
-
const { statusListCredential, encodedList } = await this.createSignedStatusList(proofFormat ?? DEFAULT_PROOF_FORMAT2, context, listToUpdate, issuerString, id, expiresAt, keyRef);
|
|
682
|
-
return {
|
|
683
|
-
encodedList,
|
|
684
|
-
statusListCredential,
|
|
685
|
-
oauthStatusList: {
|
|
686
|
-
bitsPerStatus,
|
|
687
|
-
expiresAt
|
|
688
|
-
},
|
|
689
|
-
length: listToUpdate.statusList.length,
|
|
690
|
-
type: import_ssi_types4.StatusListType.OAuthStatusList,
|
|
691
|
-
proofFormat: proofFormat ?? DEFAULT_PROOF_FORMAT2,
|
|
692
|
-
id,
|
|
693
|
-
issuer,
|
|
694
|
-
statuslistContentType: this.buildContentType(proofFormat)
|
|
695
|
-
};
|
|
696
|
-
}
|
|
697
|
-
buildContentType(proofFormat) {
|
|
698
|
-
return `application/statuslist+${proofFormat === "cbor" ? "cwt" : "jwt"}`;
|
|
699
|
-
}
|
|
700
|
-
async checkStatusIndex(args) {
|
|
701
|
-
const { statusListCredential, statusListIndex } = args;
|
|
702
|
-
if (typeof statusListCredential !== "string") {
|
|
703
|
-
return Promise.reject("statusListCredential in neither JWT nor CWT");
|
|
704
|
-
}
|
|
705
|
-
const proofFormat = determineProofFormat(statusListCredential);
|
|
706
|
-
const { statusList } = proofFormat === "jwt" ? decodeStatusListJWT(statusListCredential) : decodeStatusListCWT(statusListCredential);
|
|
707
|
-
const index = typeof statusListIndex === "number" ? statusListIndex : parseInt(statusListIndex);
|
|
708
|
-
if (index < 0 || index >= statusList.statusList.length) {
|
|
709
|
-
throw new Error("Status list index out of bounds");
|
|
710
|
-
}
|
|
711
|
-
return statusList.getStatus(index);
|
|
712
|
-
}
|
|
713
|
-
async toStatusListDetails(args) {
|
|
714
|
-
const { statusListPayload } = args;
|
|
715
|
-
const proofFormat = determineProofFormat(statusListPayload);
|
|
716
|
-
const decoded = proofFormat === "jwt" ? decodeStatusListJWT(statusListPayload) : decodeStatusListCWT(statusListPayload);
|
|
717
|
-
const { statusList, issuer, id, exp } = decoded;
|
|
718
|
-
return {
|
|
719
|
-
id,
|
|
720
|
-
encodedList: statusList.compressStatusList(),
|
|
721
|
-
issuer,
|
|
722
|
-
type: import_ssi_types4.StatusListType.OAuthStatusList,
|
|
723
|
-
proofFormat,
|
|
724
|
-
length: statusList.statusList.length,
|
|
725
|
-
statusListCredential: statusListPayload,
|
|
726
|
-
statuslistContentType: this.buildContentType(proofFormat),
|
|
727
|
-
oauthStatusList: {
|
|
728
|
-
bitsPerStatus: statusList.getBitsPerStatus(),
|
|
729
|
-
...exp && {
|
|
730
|
-
expiresAt: new Date(exp * 1e3)
|
|
731
|
-
}
|
|
732
|
-
},
|
|
733
|
-
...args.correlationId && {
|
|
734
|
-
correlationId: args.correlationId
|
|
735
|
-
},
|
|
736
|
-
...args.driverType && {
|
|
737
|
-
driverType: args.driverType
|
|
738
|
-
}
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
|
-
async createSignedStatusList(proofFormat, context, statusList, issuerString, id, expiresAt, keyRef) {
|
|
742
|
-
switch (proofFormat) {
|
|
743
|
-
case "jwt": {
|
|
744
|
-
return await createSignedJwt(context, statusList, issuerString, id, expiresAt, keyRef);
|
|
745
|
-
}
|
|
746
|
-
case "cbor": {
|
|
747
|
-
return await createSignedCbor(context, statusList, issuerString, id, expiresAt, keyRef);
|
|
748
|
-
}
|
|
749
|
-
default:
|
|
750
|
-
throw new Error(`Invalid proof format '${proofFormat}' for OAuthStatusList`);
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
};
|
|
754
|
-
|
|
755
|
-
// src/impl/StatusListFactory.ts
|
|
756
|
-
var import_ssi_types5 = require("@sphereon/ssi-types");
|
|
757
|
-
var StatusListFactory = class _StatusListFactory {
|
|
758
|
-
static {
|
|
759
|
-
__name(this, "StatusListFactory");
|
|
760
|
-
}
|
|
761
|
-
static instance;
|
|
762
|
-
implementations;
|
|
763
|
-
constructor() {
|
|
764
|
-
this.implementations = /* @__PURE__ */ new Map();
|
|
765
|
-
this.implementations.set(import_ssi_types5.StatusListType.StatusList2021, new StatusList2021Implementation());
|
|
766
|
-
this.implementations.set(import_ssi_types5.StatusListType.OAuthStatusList, new OAuthStatusListImplementation());
|
|
767
|
-
}
|
|
768
|
-
static getInstance() {
|
|
769
|
-
if (!_StatusListFactory.instance) {
|
|
770
|
-
_StatusListFactory.instance = new _StatusListFactory();
|
|
771
|
-
}
|
|
772
|
-
return _StatusListFactory.instance;
|
|
773
|
-
}
|
|
774
|
-
getByType(type) {
|
|
775
|
-
const statusList = this.implementations.get(type);
|
|
776
|
-
if (!statusList) {
|
|
777
|
-
throw new Error(`No implementation found for status list type: ${type}`);
|
|
778
|
-
}
|
|
779
|
-
return statusList;
|
|
780
|
-
}
|
|
781
|
-
};
|
|
782
|
-
function getStatusListImplementation(type) {
|
|
783
|
-
return StatusListFactory.getInstance().getByType(type);
|
|
784
|
-
}
|
|
785
|
-
__name(getStatusListImplementation, "getStatusListImplementation");
|
|
786
|
-
|
|
787
|
-
// src/functions.ts
|
|
788
|
-
async function fetchStatusListCredential(args) {
|
|
789
|
-
const url = getAssertedValue("statusListCredential", args.statusListCredential);
|
|
790
|
-
try {
|
|
791
|
-
const response = await fetch(url);
|
|
792
|
-
if (!response.ok) {
|
|
793
|
-
throw Error(`Fetching status list ${url} resulted in an error: ${response.status} : ${response.statusText}`);
|
|
794
|
-
}
|
|
795
|
-
const responseAsText = await response.text();
|
|
796
|
-
if (responseAsText.trim().startsWith("{")) {
|
|
797
|
-
return JSON.parse(responseAsText);
|
|
798
|
-
}
|
|
799
|
-
return responseAsText;
|
|
800
|
-
} catch (error) {
|
|
801
|
-
console.error(`Fetching status list ${url} resulted in an unexpected error: ${error instanceof Error ? error.message : JSON.stringify(error)}`);
|
|
802
|
-
throw error;
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
__name(fetchStatusListCredential, "fetchStatusListCredential");
|
|
806
|
-
function statusPluginStatusFunction(args) {
|
|
807
|
-
return async (credential, didDoc) => {
|
|
808
|
-
const result = await checkStatusForCredential({
|
|
809
|
-
...args,
|
|
810
|
-
documentLoader: args.documentLoader,
|
|
811
|
-
credential,
|
|
812
|
-
errorUnknownListType: args.errorUnknownListType
|
|
813
|
-
});
|
|
814
|
-
return {
|
|
815
|
-
revoked: !result.verified || result.error,
|
|
816
|
-
...result.error && {
|
|
817
|
-
error: result.error
|
|
818
|
-
}
|
|
819
|
-
};
|
|
820
|
-
};
|
|
821
|
-
}
|
|
822
|
-
__name(statusPluginStatusFunction, "statusPluginStatusFunction");
|
|
823
|
-
function vcLibCheckStatusFunction(args) {
|
|
824
|
-
const { mandatoryCredentialStatus, verifyStatusListCredential, verifyMatchingIssuers, errorUnknownListType } = args;
|
|
825
|
-
return (args2) => {
|
|
826
|
-
return checkStatusForCredential({
|
|
827
|
-
...args2,
|
|
828
|
-
mandatoryCredentialStatus,
|
|
829
|
-
verifyStatusListCredential,
|
|
830
|
-
verifyMatchingIssuers,
|
|
831
|
-
errorUnknownListType
|
|
832
|
-
});
|
|
833
|
-
};
|
|
834
|
-
}
|
|
835
|
-
__name(vcLibCheckStatusFunction, "vcLibCheckStatusFunction");
|
|
836
|
-
async function checkStatusForCredential(args) {
|
|
837
|
-
const verifyStatusListCredential = args.verifyStatusListCredential ?? true;
|
|
838
|
-
const verifyMatchingIssuers = args.verifyMatchingIssuers ?? true;
|
|
839
|
-
const uniform = import_ssi_types6.CredentialMapper.toUniformCredential(args.credential);
|
|
840
|
-
if (!("credentialStatus" in uniform) || !uniform.credentialStatus) {
|
|
841
|
-
if (args.mandatoryCredentialStatus) {
|
|
842
|
-
const error = "No credential status object found in the Verifiable Credential and it is mandatory";
|
|
843
|
-
console.log(error);
|
|
844
|
-
return {
|
|
845
|
-
verified: false,
|
|
846
|
-
error
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
return {
|
|
850
|
-
verified: true
|
|
851
|
-
};
|
|
852
|
-
}
|
|
853
|
-
if ("credentialStatus" in uniform && uniform.credentialStatus) {
|
|
854
|
-
if (uniform.credentialStatus.type === "StatusList2021Entry") {
|
|
855
|
-
return (0, import_vc_status_list2.checkStatus)({
|
|
856
|
-
...args,
|
|
857
|
-
verifyStatusListCredential,
|
|
858
|
-
verifyMatchingIssuers
|
|
859
|
-
});
|
|
860
|
-
} else if (args?.errorUnknownListType) {
|
|
861
|
-
const error = `Credential status type ${uniform.credentialStatus.type} is not supported, and check status has been configured to not allow for that`;
|
|
862
|
-
console.log(error);
|
|
863
|
-
return {
|
|
864
|
-
verified: false,
|
|
865
|
-
error
|
|
866
|
-
};
|
|
867
|
-
} else {
|
|
868
|
-
console.log(`Skipped verification of status type ${uniform.credentialStatus.type} as we do not support it (yet)`);
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
return {
|
|
872
|
-
verified: true
|
|
873
|
-
};
|
|
874
|
-
}
|
|
875
|
-
__name(checkStatusForCredential, "checkStatusForCredential");
|
|
876
|
-
async function simpleCheckStatusFromStatusListUrl(args) {
|
|
877
|
-
return checkStatusIndexFromStatusListCredential({
|
|
878
|
-
...args,
|
|
879
|
-
statusListCredential: await fetchStatusListCredential(args)
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
__name(simpleCheckStatusFromStatusListUrl, "simpleCheckStatusFromStatusListUrl");
|
|
883
|
-
async function checkStatusIndexFromStatusListCredential(args) {
|
|
884
|
-
const statusListType = determineStatusListType(args.statusListCredential);
|
|
885
|
-
const implementation = getStatusListImplementation(statusListType);
|
|
886
|
-
return implementation.checkStatusIndex(args);
|
|
887
|
-
}
|
|
888
|
-
__name(checkStatusIndexFromStatusListCredential, "checkStatusIndexFromStatusListCredential");
|
|
889
|
-
async function createNewStatusList(args, context) {
|
|
890
|
-
const { type } = getAssertedValues(args);
|
|
891
|
-
const implementation = getStatusListImplementation(type);
|
|
892
|
-
return implementation.createNewStatusList(args, context);
|
|
893
|
-
}
|
|
894
|
-
__name(createNewStatusList, "createNewStatusList");
|
|
895
|
-
async function updateStatusIndexFromStatusListCredential(args, context) {
|
|
896
|
-
const credential = getAssertedValue("statusListCredential", args.statusListCredential);
|
|
897
|
-
const statusListType = determineStatusListType(credential);
|
|
898
|
-
const implementation = getStatusListImplementation(statusListType);
|
|
899
|
-
return implementation.updateStatusListIndex(args, context);
|
|
900
|
-
}
|
|
901
|
-
__name(updateStatusIndexFromStatusListCredential, "updateStatusIndexFromStatusListCredential");
|
|
902
|
-
async function statusListCredentialToDetails(args) {
|
|
903
|
-
const credential = getAssertedValue("statusListCredential", args.statusListCredential);
|
|
904
|
-
let statusListType;
|
|
905
|
-
const documentFormat = import_ssi_types6.CredentialMapper.detectDocumentType(credential);
|
|
906
|
-
if (documentFormat === import_ssi_types6.DocumentFormat.JWT) {
|
|
907
|
-
const [header] = credential.split(".");
|
|
908
|
-
const decodedHeader = JSON.parse(Buffer.from(header, "base64").toString());
|
|
909
|
-
if (decodedHeader.typ === "statuslist+jwt") {
|
|
910
|
-
statusListType = import_ssi_types6.StatusListType.OAuthStatusList;
|
|
911
|
-
}
|
|
912
|
-
} else if (documentFormat === import_ssi_types6.DocumentFormat.MSO_MDOC) {
|
|
913
|
-
statusListType = import_ssi_types6.StatusListType.OAuthStatusList;
|
|
914
|
-
}
|
|
915
|
-
if (!statusListType) {
|
|
916
|
-
const uniform = import_ssi_types6.CredentialMapper.toUniformCredential(credential);
|
|
917
|
-
const type = uniform.type.find((t) => t.includes("StatusList2021") || t.includes("OAuth2StatusList"));
|
|
918
|
-
if (!type) {
|
|
919
|
-
throw new Error("Invalid status list credential type");
|
|
920
|
-
}
|
|
921
|
-
statusListType = type.replace("Credential", "");
|
|
922
|
-
}
|
|
923
|
-
const implementation = getStatusListImplementation(statusListType);
|
|
924
|
-
return await implementation.toStatusListDetails({
|
|
925
|
-
statusListPayload: credential,
|
|
926
|
-
correlationId: args.correlationId,
|
|
927
|
-
driverType: args.driverType
|
|
928
|
-
});
|
|
929
|
-
}
|
|
930
|
-
__name(statusListCredentialToDetails, "statusListCredentialToDetails");
|
|
931
|
-
async function updateStatusListIndexFromEncodedList(args, context) {
|
|
932
|
-
const { type } = getAssertedValue("type", args);
|
|
933
|
-
const implementation = getStatusListImplementation(type);
|
|
934
|
-
return implementation.updateStatusListFromEncodedList(args, context);
|
|
935
|
-
}
|
|
936
|
-
__name(updateStatusListIndexFromEncodedList, "updateStatusListIndexFromEncodedList");
|
|
937
|
-
async function statusList2021ToVerifiableCredential(args, context) {
|
|
938
|
-
const { issuer, id, type } = getAssertedValues(args);
|
|
939
|
-
const identifier = await context.agent.identifierManagedGet({
|
|
940
|
-
identifier: typeof issuer === "string" ? issuer : issuer.id,
|
|
941
|
-
vmRelationship: "assertionMethod",
|
|
942
|
-
offlineWhenNoDIDRegistered: true
|
|
943
|
-
});
|
|
944
|
-
const proofFormat = args?.proofFormat ?? "lds";
|
|
945
|
-
assertValidProofType(import_ssi_types6.StatusListType.StatusList2021, proofFormat);
|
|
946
|
-
const veramoProofFormat = proofFormat;
|
|
947
|
-
const encodedList = getAssertedValue("encodedList", args.encodedList);
|
|
948
|
-
const statusPurpose = getAssertedValue("statusPurpose", args.statusPurpose);
|
|
949
|
-
const credential = {
|
|
950
|
-
"@context": [
|
|
951
|
-
"https://www.w3.org/2018/credentials/v1",
|
|
952
|
-
"https://w3id.org/vc/status-list/2021/v1"
|
|
953
|
-
],
|
|
954
|
-
id,
|
|
955
|
-
issuer,
|
|
956
|
-
// issuanceDate: "2021-03-10T04:24:12.164Z",
|
|
957
|
-
type: [
|
|
958
|
-
"VerifiableCredential",
|
|
959
|
-
`${type}Credential`
|
|
960
|
-
],
|
|
961
|
-
credentialSubject: {
|
|
962
|
-
id,
|
|
963
|
-
type,
|
|
964
|
-
statusPurpose,
|
|
965
|
-
encodedList
|
|
966
|
-
}
|
|
967
|
-
};
|
|
968
|
-
const verifiableCredential = await context.agent.createVerifiableCredential({
|
|
969
|
-
credential,
|
|
970
|
-
keyRef: identifier.kmsKeyRef,
|
|
971
|
-
proofFormat: veramoProofFormat,
|
|
972
|
-
fetchRemoteContexts: true
|
|
973
|
-
});
|
|
974
|
-
return import_ssi_types6.CredentialMapper.toWrappedVerifiableCredential(verifiableCredential).original;
|
|
975
|
-
}
|
|
976
|
-
__name(statusList2021ToVerifiableCredential, "statusList2021ToVerifiableCredential");
|
|
977
|
-
//# sourceMappingURL=index.cjs.map
|