@sphereon/ssi-sdk.vc-status-list 0.33.1-feature.vcdm2.tsup.32 → 0.33.1-next.2

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