@sphereon/ssi-types 0.33.1-next.3 → 0.33.1-next.68

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 (122) hide show
  1. package/dist/index.cjs +1773 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +1589 -0
  4. package/dist/index.d.ts +1589 -6
  5. package/dist/index.js +1741 -24
  6. package/dist/index.js.map +1 -1
  7. package/package.json +23 -14
  8. package/src/index.ts +3 -2
  9. package/src/logging/index.ts +6 -4
  10. package/src/mapper/credential-constraints.ts +14 -1
  11. package/src/mapper/credential-mapper.ts +61 -23
  12. package/src/mapper/index.ts +1 -0
  13. package/src/types/cose.ts +5 -51
  14. package/src/types/did.ts +0 -90
  15. package/src/types/index.ts +13 -13
  16. package/src/types/jose.ts +18 -65
  17. package/src/types/mso_mdoc.ts +10 -138
  18. package/src/types/sd-jwt-vc.ts +4 -178
  19. package/src/types/status-list.ts +1 -8
  20. package/src/types/vc.ts +7 -29
  21. package/src/types/w3c-vc.ts +3 -26
  22. package/src/utils/cose.ts +46 -0
  23. package/src/utils/did.ts +91 -0
  24. package/src/utils/hasher.ts +5 -2
  25. package/src/utils/index.ts +6 -0
  26. package/src/utils/jose.ts +47 -0
  27. package/src/utils/mdoc.ts +144 -0
  28. package/src/utils/sd-jwt.ts +179 -0
  29. package/src/utils/vc.ts +54 -0
  30. package/dist/events/index.d.ts +0 -116
  31. package/dist/events/index.d.ts.map +0 -1
  32. package/dist/events/index.js +0 -165
  33. package/dist/events/index.js.map +0 -1
  34. package/dist/index.d.ts.map +0 -1
  35. package/dist/logging/index.d.ts +0 -73
  36. package/dist/logging/index.d.ts.map +0 -1
  37. package/dist/logging/index.js +0 -186
  38. package/dist/logging/index.js.map +0 -1
  39. package/dist/mapper/credential-constraints.d.ts +0 -16
  40. package/dist/mapper/credential-constraints.d.ts.map +0 -1
  41. package/dist/mapper/credential-constraints.js +0 -3
  42. package/dist/mapper/credential-constraints.js.map +0 -1
  43. package/dist/mapper/credential-mapper.d.ts +0 -124
  44. package/dist/mapper/credential-mapper.d.ts.map +0 -1
  45. package/dist/mapper/credential-mapper.js +0 -774
  46. package/dist/mapper/credential-mapper.js.map +0 -1
  47. package/dist/mapper/index.d.ts +0 -3
  48. package/dist/mapper/index.d.ts.map +0 -1
  49. package/dist/mapper/index.js +0 -19
  50. package/dist/mapper/index.js.map +0 -1
  51. package/dist/mapper/jsonld-language-values.d.ts +0 -18
  52. package/dist/mapper/jsonld-language-values.d.ts.map +0 -1
  53. package/dist/mapper/jsonld-language-values.js +0 -79
  54. package/dist/mapper/jsonld-language-values.js.map +0 -1
  55. package/dist/types/cose.d.ts +0 -77
  56. package/dist/types/cose.d.ts.map +0 -1
  57. package/dist/types/cose.js +0 -51
  58. package/dist/types/cose.js.map +0 -1
  59. package/dist/types/dcql.d.ts +0 -33
  60. package/dist/types/dcql.d.ts.map +0 -1
  61. package/dist/types/dcql.js +0 -4
  62. package/dist/types/dcql.js.map +0 -1
  63. package/dist/types/did.d.ts +0 -186
  64. package/dist/types/did.d.ts.map +0 -1
  65. package/dist/types/did.js +0 -78
  66. package/dist/types/did.js.map +0 -1
  67. package/dist/types/generic.d.ts +0 -44
  68. package/dist/types/generic.d.ts.map +0 -1
  69. package/dist/types/generic.js +0 -3
  70. package/dist/types/generic.js.map +0 -1
  71. package/dist/types/index.d.ts +0 -14
  72. package/dist/types/index.d.ts.map +0 -1
  73. package/dist/types/index.js +0 -30
  74. package/dist/types/index.js.map +0 -1
  75. package/dist/types/jose.d.ts +0 -89
  76. package/dist/types/jose.d.ts.map +0 -1
  77. package/dist/types/jose.js +0 -55
  78. package/dist/types/jose.js.map +0 -1
  79. package/dist/types/metadata-types.d.ts +0 -5
  80. package/dist/types/metadata-types.d.ts.map +0 -1
  81. package/dist/types/metadata-types.js +0 -3
  82. package/dist/types/metadata-types.js.map +0 -1
  83. package/dist/types/mso_mdoc.d.ts +0 -94
  84. package/dist/types/mso_mdoc.d.ts.map +0 -1
  85. package/dist/types/mso_mdoc.js +0 -121
  86. package/dist/types/mso_mdoc.js.map +0 -1
  87. package/dist/types/pex.d.ts +0 -36
  88. package/dist/types/pex.d.ts.map +0 -1
  89. package/dist/types/pex.js +0 -3
  90. package/dist/types/pex.js.map +0 -1
  91. package/dist/types/sd-jwt-type-metadata.d.ts +0 -191
  92. package/dist/types/sd-jwt-type-metadata.d.ts.map +0 -1
  93. package/dist/types/sd-jwt-type-metadata.js +0 -3
  94. package/dist/types/sd-jwt-type-metadata.js.map +0 -1
  95. package/dist/types/sd-jwt-vc.d.ts +0 -196
  96. package/dist/types/sd-jwt-vc.d.ts.map +0 -1
  97. package/dist/types/sd-jwt-vc.js +0 -142
  98. package/dist/types/sd-jwt-vc.js.map +0 -1
  99. package/dist/types/status-list.d.ts +0 -10
  100. package/dist/types/status-list.d.ts.map +0 -1
  101. package/dist/types/status-list.js +0 -9
  102. package/dist/types/status-list.js.map +0 -1
  103. package/dist/types/vc.d.ts +0 -28
  104. package/dist/types/vc.d.ts.map +0 -1
  105. package/dist/types/vc.js +0 -28
  106. package/dist/types/vc.js.map +0 -1
  107. package/dist/types/w3c-vc.d.ts +0 -243
  108. package/dist/types/w3c-vc.d.ts.map +0 -1
  109. package/dist/types/w3c-vc.js +0 -26
  110. package/dist/types/w3c-vc.js.map +0 -1
  111. package/dist/utils/hasher.d.ts +0 -4
  112. package/dist/utils/hasher.d.ts.map +0 -1
  113. package/dist/utils/hasher.js +0 -40
  114. package/dist/utils/hasher.js.map +0 -1
  115. package/dist/utils/index.d.ts +0 -3
  116. package/dist/utils/index.d.ts.map +0 -1
  117. package/dist/utils/index.js +0 -19
  118. package/dist/utils/index.js.map +0 -1
  119. package/dist/utils/object.d.ts +0 -8
  120. package/dist/utils/object.d.ts.map +0 -1
  121. package/dist/utils/object.js +0 -28
  122. package/dist/utils/object.js.map +0 -1
package/dist/index.cjs ADDED
@@ -0,0 +1,1773 @@
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
+ ActionType: () => ActionType,
35
+ BasicEventEmitter: () => BasicEventEmitter,
36
+ CredentialMapper: () => CredentialMapper,
37
+ DefaultActionSubType: () => DefaultActionSubType,
38
+ DocumentFormat: () => DocumentFormat,
39
+ EventManager: () => EventManager,
40
+ ICoseCurve: () => ICoseCurve,
41
+ ICoseKeyOperation: () => ICoseKeyOperation,
42
+ ICoseKeyType: () => ICoseKeyType,
43
+ ICoseSignatureAlgorithm: () => ICoseSignatureAlgorithm,
44
+ IProofPurpose: () => IProofPurpose,
45
+ IProofType: () => IProofType,
46
+ InitiatorType: () => InitiatorType,
47
+ JWT_PROOF_TYPE_2020: () => JWT_PROOF_TYPE_2020,
48
+ JoseCurve: () => JoseCurve,
49
+ JoseKeyOperation: () => JoseKeyOperation,
50
+ JoseSignatureAlgorithm: () => JoseSignatureAlgorithm,
51
+ JwkKeyType: () => JwkKeyType,
52
+ LogLevel: () => LogLevel,
53
+ LogMethod: () => LogMethod,
54
+ Loggers: () => Loggers,
55
+ LoggingEventType: () => LoggingEventType,
56
+ ObjectUtils: () => ObjectUtils,
57
+ OriginalType: () => OriginalType,
58
+ SimpleLogger: () => SimpleLogger,
59
+ SimpleRecordLogger: () => SimpleRecordLogger,
60
+ StatusListCredentialIdMode: () => StatusListCredentialIdMode,
61
+ StatusListDriverType: () => StatusListDriverType,
62
+ StatusListType: () => StatusListType,
63
+ SubSystem: () => SubSystem,
64
+ System: () => System,
65
+ SystemCorrelationIdType: () => SystemCorrelationIdType,
66
+ VCDM_CREDENTIAL_CONTEXT_V1: () => VCDM_CREDENTIAL_CONTEXT_V1,
67
+ VCDM_CREDENTIAL_CONTEXT_V2: () => VCDM_CREDENTIAL_CONTEXT_V2,
68
+ VCDM_CREDENTIAL_CONTEXT_VERSIONS: () => VCDM_CREDENTIAL_CONTEXT_VERSIONS,
69
+ addVcdmContextIfNeeded: () => addVcdmContextIfNeeded,
70
+ decodeMdocDeviceResponse: () => decodeMdocDeviceResponse,
71
+ decodeMdocIssuerSigned: () => decodeMdocIssuerSigned,
72
+ decodeSdJwtVc: () => decodeSdJwtVc,
73
+ decodeSdJwtVcAsync: () => decodeSdJwtVcAsync,
74
+ defaultHasher: () => defaultHasher,
75
+ encodeMdocIssuerSigned: () => encodeMdocIssuerSigned,
76
+ getMdocDecodedPayload: () => getMdocDecodedPayload,
77
+ isLanguageValueObject: () => isLanguageValueObject,
78
+ isLanguageValueObjects: () => isLanguageValueObjects,
79
+ isVcdm1Credential: () => isVcdm1Credential,
80
+ isVcdm2Credential: () => isVcdm2Credential,
81
+ isWrappedMdocCredential: () => isWrappedMdocCredential,
82
+ isWrappedMdocPresentation: () => isWrappedMdocPresentation,
83
+ isWrappedSdJwtVerifiableCredential: () => isWrappedSdJwtVerifiableCredential,
84
+ isWrappedSdJwtVerifiablePresentation: () => isWrappedSdJwtVerifiablePresentation,
85
+ isWrappedW3CVerifiableCredential: () => isWrappedW3CVerifiableCredential,
86
+ isWrappedW3CVerifiablePresentation: () => isWrappedW3CVerifiablePresentation,
87
+ logOptions: () => logOptions,
88
+ mapLanguageValue: () => mapLanguageValue,
89
+ mapLanguageValues: () => mapLanguageValues,
90
+ mdocDecodedCredentialToUniformCredential: () => mdocDecodedCredentialToUniformCredential,
91
+ parseDid: () => parseDid,
92
+ sdJwtDecodedCredentialToUniformCredential: () => sdJwtDecodedCredentialToUniformCredential,
93
+ sha256: () => sha2562,
94
+ shaHasher: () => shaHasher,
95
+ toLanguageValueObject: () => toLanguageValueObject,
96
+ toLanguageValueObjects: () => toLanguageValueObjects
97
+ });
98
+ module.exports = __toCommonJS(index_exports);
99
+
100
+ // src/logging/index.ts
101
+ var import_debug = __toESM(require("debug"), 1);
102
+ var import_events = require("events");
103
+ var LogLevel = /* @__PURE__ */ function(LogLevel2) {
104
+ LogLevel2[LogLevel2["TRACE"] = 0] = "TRACE";
105
+ LogLevel2[LogLevel2["DEBUG"] = 1] = "DEBUG";
106
+ LogLevel2[LogLevel2["INFO"] = 2] = "INFO";
107
+ LogLevel2[LogLevel2["WARNING"] = 3] = "WARNING";
108
+ LogLevel2[LogLevel2["ERROR"] = 4] = "ERROR";
109
+ return LogLevel2;
110
+ }({});
111
+ var LoggingEventType = /* @__PURE__ */ function(LoggingEventType2) {
112
+ LoggingEventType2["AUDIT"] = "audit";
113
+ LoggingEventType2["ACTIVITY"] = "activity";
114
+ LoggingEventType2["GENERAL"] = "general";
115
+ return LoggingEventType2;
116
+ }({});
117
+ var LogMethod = /* @__PURE__ */ function(LogMethod2) {
118
+ LogMethod2[LogMethod2["DEBUG_PKG"] = 0] = "DEBUG_PKG";
119
+ LogMethod2[LogMethod2["CONSOLE"] = 1] = "CONSOLE";
120
+ LogMethod2[LogMethod2["EVENT"] = 2] = "EVENT";
121
+ return LogMethod2;
122
+ }({});
123
+ function logOptions(opts) {
124
+ return {
125
+ namespace: opts?.namespace ?? "sphereon",
126
+ eventName: opts?.eventName ?? "sphereon:default",
127
+ defaultLogLevel: opts?.defaultLogLevel ?? 2,
128
+ methods: opts?.methods ?? [
129
+ 0,
130
+ 2
131
+ ]
132
+ };
133
+ }
134
+ __name(logOptions, "logOptions");
135
+ var Loggers = class _Loggers {
136
+ static {
137
+ __name(this, "Loggers");
138
+ }
139
+ static DEFAULT_KEY = "__DEFAULT__";
140
+ static DEFAULT = new _Loggers({
141
+ defaultLogLevel: 2,
142
+ methods: [
143
+ 0,
144
+ 2
145
+ ]
146
+ });
147
+ namespaceOptions = /* @__PURE__ */ new Map();
148
+ loggers = /* @__PURE__ */ new WeakMap();
149
+ constructor(defaultOptions) {
150
+ this.defaultOptions(logOptions(defaultOptions));
151
+ }
152
+ options(namespace, options) {
153
+ this.namespaceOptions.set(namespace, logOptions({
154
+ ...options,
155
+ namespace
156
+ }));
157
+ return this;
158
+ }
159
+ defaultOptions(options) {
160
+ this.options(_Loggers.DEFAULT_KEY, options);
161
+ return this;
162
+ }
163
+ register(namespace, logger2) {
164
+ return this.get(namespace, logger2);
165
+ }
166
+ get(namespace, registerLogger) {
167
+ const options = this.namespaceOptions.get(namespace) ?? registerLogger?.options ?? this.namespaceOptions.get(_Loggers.DEFAULT_KEY);
168
+ if (!options) {
169
+ throw Error(`No logging options found for namespace ${namespace}`);
170
+ }
171
+ this.namespaceOptions.set(namespace, options);
172
+ let logger2 = this.loggers.get(options);
173
+ if (!logger2) {
174
+ logger2 = registerLogger ?? new SimpleLogger(options);
175
+ this.loggers.set(options, logger2);
176
+ }
177
+ return logger2;
178
+ }
179
+ };
180
+ var SimpleLogger = class {
181
+ static {
182
+ __name(this, "SimpleLogger");
183
+ }
184
+ _eventEmitter = new import_events.EventEmitter({
185
+ captureRejections: true
186
+ });
187
+ _options;
188
+ constructor(opts) {
189
+ this._options = logOptions(opts);
190
+ }
191
+ get eventEmitter() {
192
+ return this._eventEmitter;
193
+ }
194
+ get options() {
195
+ return this._options;
196
+ }
197
+ trace(value, ...args) {
198
+ this.logImpl(0, value, ...args);
199
+ }
200
+ debug(value, ...args) {
201
+ this.logImpl(1, value, ...args);
202
+ }
203
+ info(value, ...args) {
204
+ this.logImpl(2, value, ...args);
205
+ }
206
+ warning(value, ...args) {
207
+ this.logImpl(3, value, ...args);
208
+ }
209
+ error(value, ...args) {
210
+ this.logImpl(4, value, ...args);
211
+ }
212
+ logl(level, value, ...args) {
213
+ this.logImpl(level, value, ...args);
214
+ }
215
+ logImpl(level, value, ...args) {
216
+ const date = (/* @__PURE__ */ new Date()).toISOString();
217
+ const filteredArgs = args?.filter((v) => v) ?? [];
218
+ const arg = filteredArgs.length === 0 || filteredArgs[0] == void 0 ? void 0 : filteredArgs;
219
+ function toLogValue(options) {
220
+ if (typeof value === "string") {
221
+ return `${date}-(${options.namespace}) ${value}`;
222
+ } else if (typeof value === "object") {
223
+ value["namespace"] = options.namespace;
224
+ value["time"] = date;
225
+ }
226
+ return value;
227
+ }
228
+ __name(toLogValue, "toLogValue");
229
+ const logValue = toLogValue(this.options);
230
+ const logArgs = [
231
+ logValue
232
+ ];
233
+ if (arg) {
234
+ logArgs.push(args);
235
+ }
236
+ let debugPkgEnabled = false;
237
+ if (debugPkgEnabled) {
238
+ const debugPkgDebugger = import_debug.default.default(this._options.namespace);
239
+ debugPkgEnabled = debugPkgDebugger.enabled;
240
+ if (debugPkgEnabled) {
241
+ if (arg) {
242
+ debugPkgDebugger(`${date}- ${value},`, ...arg);
243
+ } else {
244
+ debugPkgDebugger(`${date}- ${value}`);
245
+ }
246
+ }
247
+ }
248
+ if (this.options.methods.includes(1) && !debugPkgEnabled) {
249
+ const [value2, args2] = logArgs;
250
+ let logMethod = console.info;
251
+ switch (level) {
252
+ case 0:
253
+ logMethod = console.trace;
254
+ break;
255
+ case 1:
256
+ logMethod = console.debug;
257
+ break;
258
+ case 2:
259
+ logMethod = console.info;
260
+ break;
261
+ case 3:
262
+ logMethod = console.warn;
263
+ break;
264
+ case 4:
265
+ logMethod = console.error;
266
+ break;
267
+ }
268
+ if (args2) {
269
+ logMethod(value2 + ",", ...args2);
270
+ } else {
271
+ logMethod(value2);
272
+ }
273
+ }
274
+ if (this.options.methods.includes(2)) {
275
+ this._eventEmitter.emit(this.options.eventName, {
276
+ data: value.toString(),
277
+ timestamp: new Date(date),
278
+ level,
279
+ type: "general",
280
+ diagnosticData: logArgs
281
+ });
282
+ }
283
+ }
284
+ log(value, ...args) {
285
+ this.logImpl(this.options.defaultLogLevel, value, ...args);
286
+ }
287
+ };
288
+ var SimpleRecordLogger = class extends SimpleLogger {
289
+ static {
290
+ __name(this, "SimpleRecordLogger");
291
+ }
292
+ constructor(opts) {
293
+ super(opts);
294
+ }
295
+ };
296
+
297
+ // src/events/index.ts
298
+ var import_events2 = require("events");
299
+ var System = /* @__PURE__ */ function(System2) {
300
+ System2["GENERAL"] = "general";
301
+ System2["KMS"] = "kms";
302
+ System2["IDENTITY"] = "identity";
303
+ System2["OID4VCI"] = "oid4vci";
304
+ System2["OID4VP"] = "oid4vp";
305
+ System2["SIOPv2"] = "siopv2";
306
+ System2["PE"] = "PE";
307
+ System2["CREDENTIALS"] = "credentials";
308
+ System2["WEB3"] = "web3";
309
+ System2["PROFILE"] = "profile";
310
+ System2["CONTACT"] = "contact";
311
+ return System2;
312
+ }({});
313
+ var SubSystem = /* @__PURE__ */ function(SubSystem2) {
314
+ SubSystem2["KEY"] = "key";
315
+ SubSystem2["DID_PROVIDER"] = "did_provider";
316
+ SubSystem2["DID_RESOLVER"] = "did_resolver";
317
+ SubSystem2["OID4VP_OP"] = "oid4vp_op";
318
+ SubSystem2["OID4VCI_CLIENT"] = "oid4vci_client";
319
+ SubSystem2["SIOPv2_OP"] = "siopv2_op";
320
+ SubSystem2["CONTACT_MANAGER"] = "contact_manager";
321
+ SubSystem2["VC_ISSUER"] = "vc_issuer";
322
+ SubSystem2["VC_VERIFIER"] = "vc_verifier";
323
+ SubSystem2["VC_PERSISTENCE"] = "vc_persistence";
324
+ SubSystem2["TRANSPORT"] = "transport";
325
+ SubSystem2["PROFILE"] = "profile";
326
+ SubSystem2["API"] = "api";
327
+ return SubSystem2;
328
+ }({});
329
+ var ActionType = /* @__PURE__ */ function(ActionType2) {
330
+ ActionType2["CREATE"] = "create";
331
+ ActionType2["READ"] = "read";
332
+ ActionType2["UPDATE"] = "update";
333
+ ActionType2["DELETE"] = "delete";
334
+ ActionType2["EXECUTE"] = "execute";
335
+ return ActionType2;
336
+ }({});
337
+ var DefaultActionSubType = /* @__PURE__ */ function(DefaultActionSubType2) {
338
+ DefaultActionSubType2["KEY_GENERATION"] = "Key generation";
339
+ DefaultActionSubType2["KEY_IMPORT"] = "Key import";
340
+ DefaultActionSubType2["KEY_PERSISTENCE"] = "Key persistence";
341
+ DefaultActionSubType2["KEY_REMOVAL"] = "Key removal";
342
+ DefaultActionSubType2["DID_CREATION"] = "DID creation";
343
+ DefaultActionSubType2["DID_RESOLUTION"] = "DID resolution";
344
+ DefaultActionSubType2["DID_SERVICE_UPDATE"] = "DID service update";
345
+ DefaultActionSubType2["VC_ISSUE"] = "VC issue";
346
+ DefaultActionSubType2["VC_VERIFY"] = "VC verify";
347
+ DefaultActionSubType2["VC_SHARE"] = "VC share";
348
+ DefaultActionSubType2["VC_DELETE"] = "VC delete";
349
+ DefaultActionSubType2["VC_ISSUE_DECLINE"] = "VC issue decline";
350
+ DefaultActionSubType2["VC_SHARE_DECLINE"] = "VC share decline";
351
+ return DefaultActionSubType2;
352
+ }({});
353
+ var InitiatorType = /* @__PURE__ */ function(InitiatorType2) {
354
+ InitiatorType2["USER"] = "user";
355
+ InitiatorType2["SYSTEM"] = "system";
356
+ InitiatorType2["EXTERNAL"] = "external";
357
+ return InitiatorType2;
358
+ }({});
359
+ var SystemCorrelationIdType = /* @__PURE__ */ function(SystemCorrelationIdType2) {
360
+ SystemCorrelationIdType2["DID"] = "did";
361
+ SystemCorrelationIdType2["URL"] = "url";
362
+ SystemCorrelationIdType2["EMAIL"] = "email";
363
+ SystemCorrelationIdType2["HOSTNAME"] = "hostname";
364
+ SystemCorrelationIdType2["PHONE"] = "phone";
365
+ SystemCorrelationIdType2["USER"] = "user";
366
+ return SystemCorrelationIdType2;
367
+ }({});
368
+ var EventManager = class _EventManager {
369
+ static {
370
+ __name(this, "EventManager");
371
+ }
372
+ static INSTANCE = new _EventManager();
373
+ _emitters = /* @__PURE__ */ new Map();
374
+ constructor() {
375
+ }
376
+ static instance() {
377
+ return _EventManager.INSTANCE;
378
+ }
379
+ register(name, emitter, opts) {
380
+ this._emitters.set(name, {
381
+ emitter,
382
+ enabled: opts?.disabled !== true
383
+ });
384
+ return emitter;
385
+ }
386
+ get(name, opts) {
387
+ const { emitter, enabled } = this._emitters.get(name) ?? {};
388
+ if (!emitter) {
389
+ throw Error(`No emitter registered with name ${name}`);
390
+ } else if (opts?.onlyEnabled && !enabled) {
391
+ throw Error(`Emitter with name ${name} is not enabled`);
392
+ }
393
+ return emitter;
394
+ }
395
+ getOrCreate(name, opts) {
396
+ if (this.has(name)) {
397
+ return this.get(name, opts);
398
+ }
399
+ return this.register(name, new BasicEventEmitter());
400
+ }
401
+ has(name) {
402
+ return this._emitters.has(name);
403
+ }
404
+ emitters(filter) {
405
+ const all = Array.from(new Set(this._emitters.values()));
406
+ return this.emittersImpl(all, filter).map((e) => e.emitter);
407
+ }
408
+ hasEventName(eventName) {
409
+ return this.eventNames().includes(eventName);
410
+ }
411
+ eventNames() {
412
+ return Array.from(new Set(this.emitters().flatMap((emitter) => emitter.eventNames())));
413
+ }
414
+ emitBasic(event, ...args) {
415
+ return this.emit(event.eventName, event, args);
416
+ }
417
+ emit(eventName, event, ...args) {
418
+ if ("id" in event && "system" in event && !event.eventName) {
419
+ event.eventName = eventName;
420
+ }
421
+ Loggers.DEFAULT.options("sphereon:events", {
422
+ methods: [
423
+ LogMethod.CONSOLE
424
+ ],
425
+ defaultLogLevel: LogLevel.INFO
426
+ }).get("sphereon:events").log(`Emitting '${eventName.toString()}' event`, event);
427
+ const emitters = this.emitters({
428
+ eventName
429
+ });
430
+ emitters.flatMap((emitter) => emitter.emit(eventName, event, args));
431
+ }
432
+ listenerCount(eventName) {
433
+ const emitters = this.emitters({
434
+ eventName
435
+ });
436
+ return emitters.map((emitter) => emitter.listenerCount(eventName)).reduce((previous, current) => current + previous);
437
+ }
438
+ listeners(filter) {
439
+ const emitters = filter?.emitterName ? [
440
+ this.get(filter.emitterName, filter)
441
+ ] : this.emitters(filter);
442
+ return Array.from(new Set(this.emittersImpl(emitters.map((emitter) => {
443
+ return {
444
+ emitter,
445
+ enabled: true
446
+ };
447
+ }), filter).flatMap((emitter) => emitter.emitter.listeners(filter.eventName))));
448
+ }
449
+ emittersImpl(all, filter) {
450
+ const { eventName } = filter ?? {};
451
+ if (!eventName) {
452
+ return all;
453
+ }
454
+ const filtered = all.filter((emitter) => emitter.emitter.eventNames().includes(eventName) && (emitter.enabled || filter?.onlyEnabled !== true));
455
+ return Array.from(new Set(filtered));
456
+ }
457
+ };
458
+ var BasicEventEmitter = class extends import_events2.EventEmitter {
459
+ static {
460
+ __name(this, "BasicEventEmitter");
461
+ }
462
+ addListener(eventName, listener) {
463
+ return super.addListener(eventName, listener);
464
+ }
465
+ once(eventName, listener) {
466
+ return super.once(eventName, listener);
467
+ }
468
+ emit(eventName, event, ...args) {
469
+ return super.emit(eventName, ...args);
470
+ }
471
+ };
472
+
473
+ // src/utils/object.ts
474
+ var BASE64_REGEX = /^[-A-Za-z0-9+_/]*={0,3}$/g;
475
+ var ObjectUtils = class _ObjectUtils {
476
+ static {
477
+ __name(this, "ObjectUtils");
478
+ }
479
+ static asArray(value) {
480
+ return Array.isArray(value) ? value : [
481
+ value
482
+ ];
483
+ }
484
+ static isObject(value) {
485
+ return typeof value === "object" || Object.prototype.toString.call(value) === "[object Object]";
486
+ }
487
+ static isUrlAbsolute(url) {
488
+ const isAbsoluteRegex = /^([A-Za-z][A-Za-z0-9+-.]*|_):[^\s]*$/;
489
+ _ObjectUtils.isString(url) && isAbsoluteRegex.test(url);
490
+ }
491
+ static isString(value) {
492
+ return typeof value === "string" || Object.prototype.toString.call(value) === "[object String]";
493
+ }
494
+ static isBase64(value) {
495
+ if (!_ObjectUtils.isString(value)) {
496
+ return false;
497
+ }
498
+ return value.match(BASE64_REGEX) !== null;
499
+ }
500
+ };
501
+
502
+ // src/utils/hasher.ts
503
+ var import_sha2 = require("@noble/hashes/sha2");
504
+ var u8a = __toESM(require("uint8arrays"), 1);
505
+ var { fromString } = u8a;
506
+ var supportedAlgorithms = [
507
+ "sha256",
508
+ "sha384",
509
+ "sha512"
510
+ ];
511
+ var shaHasher = /* @__PURE__ */ __name((data, algorithm) => {
512
+ const sanitizedAlgorithm = algorithm.toLowerCase().replace(/[-_]/g, "");
513
+ if (!supportedAlgorithms.includes(sanitizedAlgorithm)) {
514
+ throw new Error(`Unsupported hashing algorithm ${algorithm}`);
515
+ }
516
+ const hasher = sanitizedAlgorithm === "sha384" ? import_sha2.sha384 : sanitizedAlgorithm === "sha512" ? import_sha2.sha512 : import_sha2.sha256;
517
+ return hasher(typeof data === "string" ? fromString(data) : new Uint8Array(data));
518
+ }, "shaHasher");
519
+ var defaultHasher = shaHasher;
520
+
521
+ // src/utils/vc.ts
522
+ function isWrappedW3CVerifiableCredential(vc) {
523
+ return vc.format === "jwt_vc" || vc.format === "ldp_vc";
524
+ }
525
+ __name(isWrappedW3CVerifiableCredential, "isWrappedW3CVerifiableCredential");
526
+ function isWrappedW3CVerifiablePresentation(vp) {
527
+ return vp.format === "jwt_vp" || vp.format === "ldp_vp";
528
+ }
529
+ __name(isWrappedW3CVerifiablePresentation, "isWrappedW3CVerifiablePresentation");
530
+ var StatusListType = /* @__PURE__ */ function(StatusListType2) {
531
+ StatusListType2["StatusList2021"] = "StatusList2021";
532
+ StatusListType2["OAuthStatusList"] = "OAuthStatusList";
533
+ return StatusListType2;
534
+ }({});
535
+ function isVcdmCredential(credential, vcdmType) {
536
+ if (!credential || typeof credential !== "object") {
537
+ return false;
538
+ } else if (!("@context" in credential && Array.isArray(credential["@context"]))) {
539
+ return false;
540
+ }
541
+ return credential["@context"].includes(vcdmType);
542
+ }
543
+ __name(isVcdmCredential, "isVcdmCredential");
544
+ function isVcdm1Credential(credential) {
545
+ return isVcdmCredential(credential, VCDM_CREDENTIAL_CONTEXT_V1);
546
+ }
547
+ __name(isVcdm1Credential, "isVcdm1Credential");
548
+ function isVcdm2Credential(credential) {
549
+ return isVcdmCredential(credential, VCDM_CREDENTIAL_CONTEXT_V2);
550
+ }
551
+ __name(isVcdm2Credential, "isVcdm2Credential");
552
+ function addVcdmContextIfNeeded(context, defaultValue = VCDM_CREDENTIAL_CONTEXT_V2) {
553
+ const newContext = [
554
+ ...context ?? []
555
+ ];
556
+ const vcdmContext = context?.find((val) => VCDM_CREDENTIAL_CONTEXT_VERSIONS.includes(val));
557
+ if (!vcdmContext) {
558
+ newContext.unshift(defaultValue);
559
+ }
560
+ return newContext;
561
+ }
562
+ __name(addVcdmContextIfNeeded, "addVcdmContextIfNeeded");
563
+ var VCDM_CREDENTIAL_CONTEXT_V1 = "https://www.w3.org/2018/credentials/v1";
564
+ var VCDM_CREDENTIAL_CONTEXT_V2 = "https://www.w3.org/ns/credentials/v2";
565
+ var VCDM_CREDENTIAL_CONTEXT_VERSIONS = [
566
+ VCDM_CREDENTIAL_CONTEXT_V2,
567
+ VCDM_CREDENTIAL_CONTEXT_V1
568
+ ];
569
+
570
+ // src/utils/did.ts
571
+ var IProofPurpose = /* @__PURE__ */ function(IProofPurpose2) {
572
+ IProofPurpose2["verificationMethod"] = "verificationMethod";
573
+ IProofPurpose2["assertionMethod"] = "assertionMethod";
574
+ IProofPurpose2["authentication"] = "authentication";
575
+ IProofPurpose2["keyAgreement"] = "keyAgreement";
576
+ IProofPurpose2["contractAgreement"] = "contactAgreement";
577
+ IProofPurpose2["capabilityInvocation"] = "capabilityInvocation";
578
+ IProofPurpose2["capabilityDelegation"] = "capabilityDelegation";
579
+ return IProofPurpose2;
580
+ }({});
581
+ var IProofType = /* @__PURE__ */ function(IProofType2) {
582
+ IProofType2["Ed25519Signature2018"] = "Ed25519Signature2018";
583
+ IProofType2["Ed25519Signature2020"] = "Ed25519Signature2020";
584
+ IProofType2["EcdsaSecp256k1Signature2019"] = "EcdsaSecp256k1Signature2019";
585
+ IProofType2["EcdsaSecp256k1RecoverySignature2020"] = "EcdsaSecp256k1RecoverySignature2020";
586
+ IProofType2["JsonWebSignature2020"] = "JsonWebSignature2020";
587
+ IProofType2["RsaSignature2018"] = "RsaSignature2018";
588
+ IProofType2["GpgSignature2020"] = "GpgSignature2020";
589
+ IProofType2["JcsEd25519Signature2020"] = "JcsEd25519Signature2020";
590
+ IProofType2["BbsBlsSignatureProof2020"] = "BbsBlsSignatureProof2020";
591
+ IProofType2["BbsBlsBoundSignatureProof2020"] = "BbsBlsBoundSignatureProof2020";
592
+ IProofType2["JwtProof2020"] = "JwtProof2020";
593
+ IProofType2["SdJwtProof2024"] = "SdJwtProof2024";
594
+ IProofType2["MdocProof2024"] = "MsoMdocProof2024";
595
+ return IProofType2;
596
+ }({});
597
+ var parseDid = /* @__PURE__ */ __name((did) => {
598
+ const parsedDid = parse(did);
599
+ if (parsedDid === null) {
600
+ throw new Error("invalid did");
601
+ }
602
+ return parsedDid;
603
+ }, "parseDid");
604
+ var parse = /* @__PURE__ */ __name((didUrl) => {
605
+ const PCT_ENCODED = "(?:%[0-9a-fA-F]{2})";
606
+ const ID_CHAR = `(?:[a-zA-Z0-9._-]|${PCT_ENCODED})`;
607
+ const METHOD = "([a-z0-9]+)";
608
+ const METHOD_ID = `((?:${ID_CHAR}*:)*(${ID_CHAR}+))`;
609
+ const PARAM_CHAR = "[a-zA-Z0-9_.:%-]";
610
+ const PARAM = `;${PARAM_CHAR}+=${PARAM_CHAR}*`;
611
+ const PARAMS = `((${PARAM})*)`;
612
+ const PATH = `(/[^#?]*)?`;
613
+ const QUERY = `([?][^#]*)?`;
614
+ const FRAGMENT = `(#.*)?`;
615
+ const DID_MATCHER = new RegExp(`^did:${METHOD}:${METHOD_ID}${PARAMS}${PATH}${QUERY}${FRAGMENT}$`);
616
+ if (didUrl === "" || !didUrl) return null;
617
+ const sections = didUrl.match(DID_MATCHER);
618
+ if (sections) {
619
+ const parts = {
620
+ did: `did:${sections[1]}:${sections[2]}`,
621
+ method: sections[1],
622
+ id: sections[2],
623
+ didUrl
624
+ };
625
+ if (sections[4]) {
626
+ const params = sections[4].slice(1).split(";");
627
+ parts.params = {};
628
+ for (const p of params) {
629
+ const kv = p.split("=");
630
+ parts.params[kv[0]] = kv[1];
631
+ }
632
+ }
633
+ if (sections[6]) parts.path = sections[6];
634
+ if (sections[7]) parts.query = sections[7].slice(1);
635
+ if (sections[8]) parts.fragment = sections[8].slice(1);
636
+ return parts;
637
+ }
638
+ return null;
639
+ }, "parse");
640
+
641
+ // src/utils/mdoc.ts
642
+ var mdoc = __toESM(require("@sphereon/kmp-mdoc-core"), 1);
643
+ function isWrappedMdocCredential(vc) {
644
+ return vc.format === "mso_mdoc";
645
+ }
646
+ __name(isWrappedMdocCredential, "isWrappedMdocCredential");
647
+ function isWrappedMdocPresentation(vp) {
648
+ return vp.format === "mso_mdoc";
649
+ }
650
+ __name(isWrappedMdocPresentation, "isWrappedMdocPresentation");
651
+ function getMdocDecodedPayload(mdoc2) {
652
+ const mdocJson = mdoc2.toJson();
653
+ if (!mdocJson.issuerSigned.nameSpaces) {
654
+ throw Error(`Cannot access Issuer Signed items from the Mdoc`);
655
+ }
656
+ const issuerSignedJson = mdoc2.issuerSigned.toJsonDTO();
657
+ const namespaces = issuerSignedJson.nameSpaces;
658
+ const decodedPayload = {};
659
+ for (const [namespace, items] of Object.entries(namespaces)) {
660
+ decodedPayload[namespace] = items.reduce((acc, item) => ({
661
+ ...acc,
662
+ [item.key]: item.value.value
663
+ }), {});
664
+ }
665
+ return decodedPayload;
666
+ }
667
+ __name(getMdocDecodedPayload, "getMdocDecodedPayload");
668
+ function decodeMdocIssuerSigned(oid4vpIssuerSigned) {
669
+ const issuerSigned = mdoc.com.sphereon.mdoc.data.device.IssuerSignedCbor.Static.cborDecode(mdoc.com.sphereon.kmp.decodeFrom(oid4vpIssuerSigned, mdoc.com.sphereon.kmp.Encoding.BASE64URL));
670
+ const holderMdoc = issuerSigned.toDocument();
671
+ return holderMdoc;
672
+ }
673
+ __name(decodeMdocIssuerSigned, "decodeMdocIssuerSigned");
674
+ function encodeMdocIssuerSigned(issuerSigned, encoding = "base64url") {
675
+ return mdoc.com.sphereon.kmp.encodeTo(issuerSigned.cborEncode(), mdoc.com.sphereon.kmp.Encoding.BASE64URL);
676
+ }
677
+ __name(encodeMdocIssuerSigned, "encodeMdocIssuerSigned");
678
+ function decodeMdocDeviceResponse(vpToken) {
679
+ const deviceResponse = mdoc.com.sphereon.mdoc.data.device.DeviceResponseCbor.Static.cborDecode(mdoc.com.sphereon.kmp.decodeFrom(vpToken, mdoc.com.sphereon.kmp.Encoding.BASE64URL));
680
+ return deviceResponse;
681
+ }
682
+ __name(decodeMdocDeviceResponse, "decodeMdocDeviceResponse");
683
+ var mdocDecodedCredentialToUniformCredential = /* @__PURE__ */ __name((decoded, opts) => {
684
+ const document = decoded.toJson();
685
+ const json = document.toJsonDTO();
686
+ const type = "Personal Identification Data";
687
+ const MSO = document.MSO;
688
+ if (!MSO || !json.issuerSigned?.nameSpaces) {
689
+ throw Error(`Cannot access Mobile Security Object or Issuer Signed items from the Mdoc`);
690
+ }
691
+ const nameSpaces = json.issuerSigned.nameSpaces;
692
+ if (!("eu.europa.ec.eudi.pid.1" in nameSpaces)) {
693
+ throw Error(`Only PID supported at present`);
694
+ }
695
+ const items = nameSpaces["eu.europa.ec.eudi.pid.1"];
696
+ if (!items || items.length === 0) {
697
+ throw Error(`No issuer signed items were found`);
698
+ }
699
+ const credentialSubject = items.reduce((acc, item) => {
700
+ if (Array.isArray(item.value)) {
701
+ acc[item.key] = item.value.map((val) => val.value).join(", ");
702
+ } else {
703
+ acc[item.key] = item.value.value;
704
+ }
705
+ return acc;
706
+ }, {});
707
+ const validFrom = MSO.validityInfo.validFrom;
708
+ const validUntil = MSO.validityInfo.validUntil;
709
+ const docType = MSO.docType;
710
+ const expirationDate = validUntil;
711
+ let issuanceDateStr = validFrom;
712
+ const issuanceDate = issuanceDateStr;
713
+ if (!issuanceDate) {
714
+ throw Error(`JWT issuance date is required but was not present`);
715
+ }
716
+ const credential = {
717
+ type: [
718
+ docType
719
+ ],
720
+ "@context": [],
721
+ credentialSubject: {
722
+ type,
723
+ ...credentialSubject
724
+ },
725
+ issuanceDate,
726
+ expirationDate,
727
+ proof: {
728
+ type: IProofType.MdocProof2024,
729
+ created: issuanceDate,
730
+ proofPurpose: IProofPurpose.authentication,
731
+ verificationMethod: json.issuerSigned.issuerAuth.payload,
732
+ mso_mdoc: mdoc.com.sphereon.kmp.encodeTo(decoded.cborEncode(), mdoc.com.sphereon.kmp.Encoding.BASE64URL)
733
+ }
734
+ };
735
+ return credential;
736
+ }, "mdocDecodedCredentialToUniformCredential");
737
+
738
+ // src/utils/sd-jwt.ts
739
+ var import_decode = require("@sd-jwt/decode");
740
+ function decodeSdJwtVc(compactSdJwtVc, hasher) {
741
+ const { jwt, disclosures, kbJwt } = (0, import_decode.decodeSdJwtSync)(compactSdJwtVc, hasher);
742
+ const signedPayload = jwt.payload;
743
+ const decodedPayload = (0, import_decode.getClaimsSync)(signedPayload, disclosures, hasher);
744
+ const compactKeyBindingJwt = kbJwt ? compactSdJwtVc.split("~").pop() : void 0;
745
+ return {
746
+ compactSdJwtVc,
747
+ decodedPayload,
748
+ disclosures: disclosures.map((d) => {
749
+ const decoded = d.key ? [
750
+ d.salt,
751
+ d.key,
752
+ d.value
753
+ ] : [
754
+ d.salt,
755
+ d.value
756
+ ];
757
+ if (!d._digest) throw new Error("Implementation error: digest not present in disclosure");
758
+ return {
759
+ decoded,
760
+ digest: d._digest,
761
+ encoded: d.encode()
762
+ };
763
+ }),
764
+ signedPayload,
765
+ ...compactKeyBindingJwt && kbJwt && {
766
+ kbJwt: {
767
+ header: kbJwt.header,
768
+ compact: compactKeyBindingJwt,
769
+ payload: kbJwt.payload
770
+ }
771
+ }
772
+ };
773
+ }
774
+ __name(decodeSdJwtVc, "decodeSdJwtVc");
775
+ async function decodeSdJwtVcAsync(compactSdJwtVc, hasher) {
776
+ const { jwt, disclosures, kbJwt } = await (0, import_decode.decodeSdJwt)(compactSdJwtVc, hasher);
777
+ const signedPayload = jwt.payload;
778
+ const decodedPayload = await (0, import_decode.getClaims)(signedPayload, disclosures, hasher);
779
+ const compactKeyBindingJwt = kbJwt ? compactSdJwtVc.split("~").pop() : void 0;
780
+ return {
781
+ compactSdJwtVc,
782
+ decodedPayload,
783
+ disclosures: disclosures.map((d) => {
784
+ const decoded = d.key ? [
785
+ d.salt,
786
+ d.key,
787
+ d.value
788
+ ] : [
789
+ d.salt,
790
+ d.value
791
+ ];
792
+ if (!d._digest) throw new Error("Implementation error: digest not present in disclosure");
793
+ return {
794
+ decoded,
795
+ digest: d._digest,
796
+ encoded: d.encode()
797
+ };
798
+ }),
799
+ signedPayload,
800
+ ...compactKeyBindingJwt && kbJwt && {
801
+ kbJwt: {
802
+ header: kbJwt.header,
803
+ payload: kbJwt.payload,
804
+ compact: compactKeyBindingJwt
805
+ }
806
+ }
807
+ };
808
+ }
809
+ __name(decodeSdJwtVcAsync, "decodeSdJwtVcAsync");
810
+ var sdJwtDecodedCredentialToUniformCredential = /* @__PURE__ */ __name((decoded, opts) => {
811
+ const { decodedPayload } = decoded;
812
+ const { exp, nbf, iss, iat, vct, cnf, status, sub, jti } = decodedPayload;
813
+ const maxSkewInMS = opts?.maxTimeSkewInMS ?? 1500;
814
+ const expirationDate = jwtDateToISOString({
815
+ jwtClaim: exp,
816
+ claimName: "exp"
817
+ });
818
+ let issuanceDateStr = jwtDateToISOString({
819
+ jwtClaim: iat,
820
+ claimName: "iat"
821
+ });
822
+ let nbfDateAsStr;
823
+ if (nbf) {
824
+ nbfDateAsStr = jwtDateToISOString({
825
+ jwtClaim: nbf,
826
+ claimName: "nbf"
827
+ });
828
+ if (issuanceDateStr && nbfDateAsStr && issuanceDateStr !== nbfDateAsStr) {
829
+ const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(iss).getTime());
830
+ if (!maxSkewInMS || diff > maxSkewInMS) {
831
+ throw Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${iss})`);
832
+ }
833
+ }
834
+ issuanceDateStr = nbfDateAsStr;
835
+ }
836
+ const issuanceDate = issuanceDateStr;
837
+ if (!issuanceDate) {
838
+ throw Error(`JWT issuance date is required but was not present`);
839
+ }
840
+ const excludedFields = /* @__PURE__ */ new Set([
841
+ "vct",
842
+ "cnf",
843
+ "iss",
844
+ "iat",
845
+ "exp",
846
+ "nbf",
847
+ "jti",
848
+ "sub"
849
+ ]);
850
+ const credentialSubject = Object.entries(decodedPayload).reduce((acc, [key, value]) => {
851
+ if (!excludedFields.has(key) && value !== void 0 && value !== "" && !(typeof value === "object" && value !== null && Object.keys(value).length === 0)) {
852
+ acc[key] = value;
853
+ }
854
+ return acc;
855
+ }, {});
856
+ const credential = {
857
+ type: [
858
+ vct
859
+ ],
860
+ "@context": [],
861
+ credentialSubject: {
862
+ ...credentialSubject,
863
+ id: credentialSubject.id ?? sub ?? jti
864
+ },
865
+ issuanceDate,
866
+ expirationDate,
867
+ issuer: iss,
868
+ ...cnf && {
869
+ cnf
870
+ },
871
+ ...status && {
872
+ status
873
+ },
874
+ proof: {
875
+ type: IProofType.SdJwtProof2024,
876
+ created: nbfDateAsStr ?? issuanceDate,
877
+ proofPurpose: IProofPurpose.authentication,
878
+ verificationMethod: iss,
879
+ jwt: decoded.compactSdJwtVc
880
+ }
881
+ };
882
+ return credential;
883
+ }, "sdJwtDecodedCredentialToUniformCredential");
884
+ var jwtDateToISOString = /* @__PURE__ */ __name(({ jwtClaim, claimName, isRequired = false }) => {
885
+ if (jwtClaim) {
886
+ const claim = parseInt(jwtClaim.toString());
887
+ return new Date(claim * (claim < 9999999999 ? 1e3 : 1)).toISOString().replace(/\.000Z/, "Z");
888
+ } else if (isRequired) {
889
+ throw Error(`JWT claim ${claimName} is required but was not present`);
890
+ }
891
+ return void 0;
892
+ }, "jwtDateToISOString");
893
+
894
+ // src/utils/jose.ts
895
+ var JwkKeyType = /* @__PURE__ */ function(JwkKeyType2) {
896
+ JwkKeyType2["EC"] = "EC";
897
+ JwkKeyType2["RSA"] = "RSA";
898
+ JwkKeyType2["oct"] = "oct";
899
+ JwkKeyType2["OKP"] = "OKP";
900
+ return JwkKeyType2;
901
+ }({});
902
+ var JoseSignatureAlgorithm = /* @__PURE__ */ function(JoseSignatureAlgorithm2) {
903
+ JoseSignatureAlgorithm2["RS256"] = "RS256";
904
+ JoseSignatureAlgorithm2["RS384"] = "RS384";
905
+ JoseSignatureAlgorithm2["RS512"] = "RS512";
906
+ JoseSignatureAlgorithm2["ES256"] = "ES256";
907
+ JoseSignatureAlgorithm2["ES256K"] = "ES256K";
908
+ JoseSignatureAlgorithm2["ES384"] = "ES384";
909
+ JoseSignatureAlgorithm2["ES512"] = "ES512";
910
+ JoseSignatureAlgorithm2["EdDSA"] = "EdDSA";
911
+ JoseSignatureAlgorithm2["HS256"] = "HS256";
912
+ JoseSignatureAlgorithm2["HS384"] = "HS384";
913
+ JoseSignatureAlgorithm2["HS512"] = "HS512";
914
+ JoseSignatureAlgorithm2["PS256"] = "PS256";
915
+ JoseSignatureAlgorithm2["PS384"] = "PS384";
916
+ JoseSignatureAlgorithm2["PS512"] = "PS512";
917
+ JoseSignatureAlgorithm2["none"] = "none";
918
+ return JoseSignatureAlgorithm2;
919
+ }({});
920
+ var JoseKeyOperation = /* @__PURE__ */ function(JoseKeyOperation2) {
921
+ JoseKeyOperation2["SIGN"] = "sign";
922
+ JoseKeyOperation2["VERIFY"] = "verify";
923
+ JoseKeyOperation2["ENCRYPT"] = "encrypt";
924
+ JoseKeyOperation2["DECRYPT"] = "decrypt";
925
+ JoseKeyOperation2["WRAP_KEY"] = "wrapKey";
926
+ JoseKeyOperation2["UNWRAP_KEY"] = "unwrapKey";
927
+ JoseKeyOperation2["DERIVE_KEY"] = "deriveKey";
928
+ JoseKeyOperation2["DERIVE_BITS"] = "deriveBits";
929
+ return JoseKeyOperation2;
930
+ }({});
931
+ var JoseCurve = /* @__PURE__ */ function(JoseCurve2) {
932
+ JoseCurve2["P_256"] = "P-256";
933
+ JoseCurve2["P_384"] = "P-384";
934
+ JoseCurve2["P_521"] = "P-521";
935
+ JoseCurve2["X25519"] = "X25519";
936
+ JoseCurve2["X448"] = "X448";
937
+ JoseCurve2["EdDSA"] = "EdDSA";
938
+ JoseCurve2["Ed25519"] = "Ed25519";
939
+ JoseCurve2["Ed448"] = "Ed448";
940
+ JoseCurve2["secp256k1"] = "secp256k1";
941
+ return JoseCurve2;
942
+ }({});
943
+
944
+ // src/utils/cose.ts
945
+ var ICoseKeyType = /* @__PURE__ */ function(ICoseKeyType2) {
946
+ ICoseKeyType2[ICoseKeyType2["OKP"] = 1] = "OKP";
947
+ ICoseKeyType2[ICoseKeyType2["EC2"] = 2] = "EC2";
948
+ ICoseKeyType2[ICoseKeyType2["RSA"] = 3] = "RSA";
949
+ ICoseKeyType2[ICoseKeyType2["Symmetric"] = 4] = "Symmetric";
950
+ ICoseKeyType2[ICoseKeyType2["Reserved"] = 0] = "Reserved";
951
+ return ICoseKeyType2;
952
+ }({});
953
+ var ICoseSignatureAlgorithm = /* @__PURE__ */ function(ICoseSignatureAlgorithm2) {
954
+ ICoseSignatureAlgorithm2[ICoseSignatureAlgorithm2["ES256"] = -7] = "ES256";
955
+ ICoseSignatureAlgorithm2[ICoseSignatureAlgorithm2["ES256K"] = -47] = "ES256K";
956
+ ICoseSignatureAlgorithm2[ICoseSignatureAlgorithm2["ES384"] = -35] = "ES384";
957
+ ICoseSignatureAlgorithm2[ICoseSignatureAlgorithm2["ES512"] = -36] = "ES512";
958
+ ICoseSignatureAlgorithm2[ICoseSignatureAlgorithm2["EdDSA"] = -8] = "EdDSA";
959
+ ICoseSignatureAlgorithm2[ICoseSignatureAlgorithm2["HS256_64"] = 4] = "HS256_64";
960
+ ICoseSignatureAlgorithm2[ICoseSignatureAlgorithm2["HS256"] = 5] = "HS256";
961
+ ICoseSignatureAlgorithm2[ICoseSignatureAlgorithm2["HS384"] = 6] = "HS384";
962
+ ICoseSignatureAlgorithm2[ICoseSignatureAlgorithm2["HS512"] = 7] = "HS512";
963
+ ICoseSignatureAlgorithm2[ICoseSignatureAlgorithm2["PS256"] = -37] = "PS256";
964
+ ICoseSignatureAlgorithm2[ICoseSignatureAlgorithm2["PS384"] = -38] = "PS384";
965
+ ICoseSignatureAlgorithm2[ICoseSignatureAlgorithm2["PS512"] = -39] = "PS512";
966
+ return ICoseSignatureAlgorithm2;
967
+ }({});
968
+ var ICoseKeyOperation = /* @__PURE__ */ function(ICoseKeyOperation2) {
969
+ ICoseKeyOperation2[ICoseKeyOperation2["SIGN"] = 1] = "SIGN";
970
+ ICoseKeyOperation2[ICoseKeyOperation2["VERIFY"] = 2] = "VERIFY";
971
+ ICoseKeyOperation2[ICoseKeyOperation2["ENCRYPT"] = 3] = "ENCRYPT";
972
+ ICoseKeyOperation2[ICoseKeyOperation2["DECRYPT"] = 4] = "DECRYPT";
973
+ ICoseKeyOperation2[ICoseKeyOperation2["WRAP_KEY"] = 5] = "WRAP_KEY";
974
+ ICoseKeyOperation2[ICoseKeyOperation2["UNWRAP_KEY"] = 6] = "UNWRAP_KEY";
975
+ ICoseKeyOperation2[ICoseKeyOperation2["DERIVE_KEY"] = 7] = "DERIVE_KEY";
976
+ ICoseKeyOperation2[ICoseKeyOperation2["DERIVE_BITS"] = 8] = "DERIVE_BITS";
977
+ ICoseKeyOperation2[ICoseKeyOperation2["MAC_CREATE"] = 9] = "MAC_CREATE";
978
+ ICoseKeyOperation2[ICoseKeyOperation2["MAC_VERIFY"] = 10] = "MAC_VERIFY";
979
+ return ICoseKeyOperation2;
980
+ }({});
981
+ var ICoseCurve = /* @__PURE__ */ function(ICoseCurve2) {
982
+ ICoseCurve2[ICoseCurve2["P_256"] = 1] = "P_256";
983
+ ICoseCurve2[ICoseCurve2["P_384"] = 2] = "P_384";
984
+ ICoseCurve2[ICoseCurve2["P_521"] = 3] = "P_521";
985
+ ICoseCurve2[ICoseCurve2["X25519"] = 4] = "X25519";
986
+ ICoseCurve2[ICoseCurve2["X448"] = 5] = "X448";
987
+ ICoseCurve2[ICoseCurve2["Ed25519"] = 6] = "Ed25519";
988
+ ICoseCurve2[ICoseCurve2["Ed448"] = 7] = "Ed448";
989
+ ICoseCurve2[ICoseCurve2["secp256k1"] = -1] = "secp256k1";
990
+ return ICoseCurve2;
991
+ }({});
992
+
993
+ // src/mapper/credential-constraints.ts
994
+ var StatusListCredentialIdMode = /* @__PURE__ */ function(StatusListCredentialIdMode2) {
995
+ StatusListCredentialIdMode2["ISSUANCE"] = "ISSUANCE";
996
+ StatusListCredentialIdMode2["NEVER"] = "NEVER";
997
+ return StatusListCredentialIdMode2;
998
+ }({});
999
+ var StatusListDriverType = /* @__PURE__ */ function(StatusListDriverType2) {
1000
+ StatusListDriverType2["AGENT_TYPEORM"] = "agent_typeorm";
1001
+ return StatusListDriverType2;
1002
+ }({});
1003
+
1004
+ // src/mapper/credential-mapper.ts
1005
+ var import_jwt_decode = require("jwt-decode");
1006
+ var sha2562 = /* @__PURE__ */ __name((data) => {
1007
+ return defaultHasher(data, "sha256");
1008
+ }, "sha256");
1009
+ var CredentialMapper = class _CredentialMapper {
1010
+ static {
1011
+ __name(this, "CredentialMapper");
1012
+ }
1013
+ /**
1014
+ * Decodes a compact SD-JWT vc to it's decoded variant. This method can be used when the hasher implementation used is Async, and therefore not suitable for usage
1015
+ * with the other decode methods.
1016
+ */
1017
+ static decodeSdJwtVcAsync(compactSdJwtVc, hasher) {
1018
+ return decodeSdJwtVcAsync(compactSdJwtVc, hasher ?? sha2562);
1019
+ }
1020
+ /**
1021
+ * Decodes a Verifiable Presentation to a uniform format.
1022
+ *
1023
+ * When decoding SD-JWT credentials, a hasher implementation must be provided. The hasher implementation must be sync. When using
1024
+ * an async hasher implementation, use the decodeSdJwtVcAsync method instead and you can provide the decoded payload to methods
1025
+ * instead of the compact SD-JWT.
1026
+ *
1027
+ * @param presentation
1028
+ * @param hasher Hasher implementation to use for SD-JWT decoding.
1029
+ */
1030
+ static decodeVerifiablePresentation(presentation, hasher) {
1031
+ if (_CredentialMapper.isJwtEncoded(presentation)) {
1032
+ const payload = (0, import_jwt_decode.jwtDecode)(presentation);
1033
+ const header = (0, import_jwt_decode.jwtDecode)(presentation, {
1034
+ header: true
1035
+ });
1036
+ payload.vp.proof = {
1037
+ type: IProofType.JwtProof2020,
1038
+ created: payload.nbf,
1039
+ proofPurpose: IProofPurpose.authentication,
1040
+ verificationMethod: header["kid"] ?? payload.iss,
1041
+ jwt: presentation
1042
+ };
1043
+ return payload;
1044
+ } else if (_CredentialMapper.isJwtDecodedPresentation(presentation)) {
1045
+ return presentation;
1046
+ } else if (_CredentialMapper.isSdJwtEncoded(presentation)) {
1047
+ return decodeSdJwtVc(presentation, hasher ?? sha2562);
1048
+ } else if (_CredentialMapper.isSdJwtDecodedCredential(presentation)) {
1049
+ return presentation;
1050
+ } else if (_CredentialMapper.isMsoMdocOid4VPEncoded(presentation)) {
1051
+ return presentation;
1052
+ } else if (_CredentialMapper.isMsoMdocDecodedPresentation(presentation)) {
1053
+ return presentation;
1054
+ } else if (_CredentialMapper.isJsonLdAsString(presentation)) {
1055
+ return JSON.parse(presentation);
1056
+ } else {
1057
+ return presentation;
1058
+ }
1059
+ }
1060
+ /**
1061
+ * Decodes a Verifiable Credential to a uniform format.
1062
+ *
1063
+ * When decoding SD-JWT credentials, a hasher implementation must be provided. The hasher implementation must be sync. When using
1064
+ * an async hasher implementation, use the decodeSdJwtVcAsync method instead and you can provide the decoded payload to methods
1065
+ * instead of the compact SD-JWT.
1066
+ *
1067
+ * @param hasher Hasher implementation to use for SD-JWT decoding
1068
+ */
1069
+ static decodeVerifiableCredential(credential, hasher) {
1070
+ if (_CredentialMapper.isJwtEncoded(credential)) {
1071
+ const payload = (0, import_jwt_decode.jwtDecode)(credential);
1072
+ const header = (0, import_jwt_decode.jwtDecode)(credential, {
1073
+ header: true
1074
+ });
1075
+ payload.vc = payload.vc ?? {};
1076
+ payload.vc.proof = {
1077
+ type: IProofType.JwtProof2020,
1078
+ created: payload.nbf,
1079
+ proofPurpose: IProofPurpose.authentication,
1080
+ verificationMethod: header["kid"] ?? payload.iss,
1081
+ jwt: credential
1082
+ };
1083
+ return payload;
1084
+ } else if (_CredentialMapper.isJwtDecodedCredential(credential)) {
1085
+ return credential;
1086
+ } else if (_CredentialMapper.isJsonLdAsString(credential)) {
1087
+ return JSON.parse(credential);
1088
+ } else if (_CredentialMapper.isSdJwtEncoded(credential)) {
1089
+ return decodeSdJwtVc(credential, hasher ?? sha2562);
1090
+ } else if (_CredentialMapper.isSdJwtDecodedCredential(credential)) {
1091
+ return credential;
1092
+ } else {
1093
+ return credential;
1094
+ }
1095
+ }
1096
+ /**
1097
+ * Converts a presentation to a wrapped presentation.
1098
+ *
1099
+ * When decoding SD-JWT credentials, a hasher implementation must be provided. The hasher implementation must be sync. When using
1100
+ * an async hasher implementation, use the decodeSdJwtVcAsync method instead and you can provide the decoded payload to methods
1101
+ * instead of the compact SD-JWT.
1102
+ *
1103
+ * @param hasher Hasher implementation to use for SD-JWT decoding
1104
+ */
1105
+ static toWrappedVerifiablePresentation(originalPresentation, opts) {
1106
+ if (_CredentialMapper.isMsoMdocDecodedPresentation(originalPresentation) || _CredentialMapper.isMsoMdocOid4VPEncoded(originalPresentation)) {
1107
+ let deviceResponse;
1108
+ let originalType;
1109
+ if (_CredentialMapper.isMsoMdocOid4VPEncoded(originalPresentation)) {
1110
+ deviceResponse = decodeMdocDeviceResponse(originalPresentation);
1111
+ originalType = "mso_mdoc-encoded";
1112
+ } else {
1113
+ deviceResponse = originalPresentation;
1114
+ originalType = "mso_mdoc-decoded";
1115
+ }
1116
+ const mdocCredentials = deviceResponse.documents?.map((doc) => _CredentialMapper.toWrappedVerifiableCredential(doc, opts));
1117
+ if (!mdocCredentials || mdocCredentials.length === 0) {
1118
+ throw new Error("could not extract any mdoc credentials from mdoc device response");
1119
+ }
1120
+ return {
1121
+ type: originalType,
1122
+ format: "mso_mdoc",
1123
+ original: originalPresentation,
1124
+ presentation: deviceResponse,
1125
+ decoded: deviceResponse,
1126
+ vcs: mdocCredentials
1127
+ };
1128
+ }
1129
+ if (_CredentialMapper.isSdJwtDecodedCredential(originalPresentation) || _CredentialMapper.isSdJwtEncoded(originalPresentation)) {
1130
+ let decodedPresentation;
1131
+ if (_CredentialMapper.isSdJwtEncoded(originalPresentation)) {
1132
+ decodedPresentation = decodeSdJwtVc(originalPresentation, opts?.hasher ?? sha2562);
1133
+ } else {
1134
+ decodedPresentation = originalPresentation;
1135
+ }
1136
+ return {
1137
+ type: _CredentialMapper.isSdJwtDecodedCredential(originalPresentation) ? "sd-jwt-vc-decoded" : "sd-jwt-vc-encoded",
1138
+ format: "vc+sd-jwt",
1139
+ original: originalPresentation,
1140
+ presentation: decodedPresentation,
1141
+ decoded: decodedPresentation.decodedPayload,
1142
+ // NOTE: we also include the SD-JWT VC as the VC, as the SD-JWT acts as both the VC and the VP
1143
+ vcs: [
1144
+ _CredentialMapper.toWrappedVerifiableCredential(originalPresentation, opts)
1145
+ ]
1146
+ };
1147
+ }
1148
+ const proof = _CredentialMapper.getFirstProof(originalPresentation);
1149
+ const original = typeof originalPresentation !== "string" && _CredentialMapper.hasJWTProofType(originalPresentation) ? proof?.jwt : originalPresentation;
1150
+ if (!original) {
1151
+ throw Error("Could not determine original presentation, probably it was a converted JWT presentation, that is now missing the JWT value in the proof");
1152
+ }
1153
+ const decoded = _CredentialMapper.decodeVerifiablePresentation(original);
1154
+ const isJwtEncoded = _CredentialMapper.isJwtEncoded(original);
1155
+ const isJwtDecoded = _CredentialMapper.isJwtDecodedPresentation(original);
1156
+ const type = isJwtEncoded ? "jwt-encoded" : isJwtDecoded ? "jwt-decoded" : "json-ld";
1157
+ const format = isJwtDecoded || isJwtEncoded ? "jwt_vp" : "ldp_vp";
1158
+ let vp;
1159
+ if (isJwtEncoded || isJwtDecoded) {
1160
+ vp = _CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false, opts);
1161
+ } else {
1162
+ vp = decoded;
1163
+ }
1164
+ if (!vp) {
1165
+ throw Error(`VP key not found`);
1166
+ }
1167
+ const noVCs = !("verifiableCredential" in vp) || !vp.verifiableCredential || vp.verifiableCredential.length === 0;
1168
+ if (noVCs) {
1169
+ console.warn(`Presentation without verifiable credentials. That is rare! `);
1170
+ }
1171
+ const vcs = noVCs ? [] : _CredentialMapper.toWrappedVerifiableCredentials(vp.verifiableCredential ?? [], opts);
1172
+ const presentation = {
1173
+ ...vp,
1174
+ verifiableCredential: vcs
1175
+ };
1176
+ return {
1177
+ type,
1178
+ format,
1179
+ original,
1180
+ decoded,
1181
+ presentation,
1182
+ vcs
1183
+ };
1184
+ }
1185
+ /**
1186
+ * Converts a list of credentials to a list of wrapped credentials.
1187
+ *
1188
+ * When decoding SD-JWT credentials, a hasher implementation must be provided. The hasher implementation must be sync. When using
1189
+ * an async hasher implementation, use the decodeSdJwtVcAsync method instead and you can provide the decoded payload to methods
1190
+ * instead of the compact SD-JWT.
1191
+ *
1192
+ * @param hasher Hasher implementation to use for SD-JWT decoding
1193
+ */
1194
+ static toWrappedVerifiableCredentials(verifiableCredentials, opts) {
1195
+ return verifiableCredentials.map((vc) => _CredentialMapper.toWrappedVerifiableCredential(vc, opts));
1196
+ }
1197
+ /**
1198
+ * Converts a credential to a wrapped credential.
1199
+ *
1200
+ * When decoding SD-JWT credentials, a hasher implementation must be provided. The hasher implementation must be sync. When using
1201
+ * an async hasher implementation, use the decodeSdJwtVcAsync method instead and you can provide the decoded payload to methods
1202
+ * instead of the compact SD-JWT.
1203
+ *
1204
+ * @param hasher Hasher implementation to use for SD-JWT decoding
1205
+ */
1206
+ static toWrappedVerifiableCredential(verifiableCredential, opts) {
1207
+ if (_CredentialMapper.isMsoMdocDecodedCredential(verifiableCredential) || _CredentialMapper.isMsoMdocOid4VPEncoded(verifiableCredential)) {
1208
+ let mdoc2;
1209
+ if (_CredentialMapper.isMsoMdocOid4VPEncoded(verifiableCredential)) {
1210
+ mdoc2 = decodeMdocIssuerSigned(verifiableCredential);
1211
+ } else {
1212
+ mdoc2 = verifiableCredential;
1213
+ }
1214
+ return {
1215
+ type: _CredentialMapper.isMsoMdocDecodedCredential(verifiableCredential) ? "mso_mdoc-decoded" : "mso_mdoc-encoded",
1216
+ format: "mso_mdoc",
1217
+ original: verifiableCredential,
1218
+ credential: mdoc2,
1219
+ decoded: getMdocDecodedPayload(mdoc2)
1220
+ };
1221
+ }
1222
+ if (_CredentialMapper.isSdJwtDecodedCredential(verifiableCredential) || _CredentialMapper.isSdJwtEncoded(verifiableCredential)) {
1223
+ let decodedCredential;
1224
+ if (_CredentialMapper.isSdJwtEncoded(verifiableCredential)) {
1225
+ const hasher = opts?.hasher ?? sha2562;
1226
+ decodedCredential = decodeSdJwtVc(verifiableCredential, hasher);
1227
+ } else {
1228
+ decodedCredential = verifiableCredential;
1229
+ }
1230
+ return {
1231
+ type: _CredentialMapper.isSdJwtDecodedCredential(verifiableCredential) ? "sd-jwt-vc-decoded" : "sd-jwt-vc-encoded",
1232
+ format: "vc+sd-jwt",
1233
+ original: verifiableCredential,
1234
+ credential: decodedCredential,
1235
+ decoded: decodedCredential.decodedPayload
1236
+ };
1237
+ }
1238
+ const proof = _CredentialMapper.getFirstProof(verifiableCredential);
1239
+ const original = _CredentialMapper.hasJWTProofType(verifiableCredential) && proof ? proof.jwt ?? verifiableCredential : verifiableCredential;
1240
+ if (!original) {
1241
+ throw Error("Could not determine original credential, probably it was a converted JWT credential, that is now missing the JWT value in the proof");
1242
+ }
1243
+ const decoded = _CredentialMapper.decodeVerifiableCredential(original);
1244
+ const isJwtEncoded = _CredentialMapper.isJwtEncoded(original);
1245
+ const isJwtDecoded = _CredentialMapper.isJwtDecodedCredential(original);
1246
+ const type = isJwtEncoded ? "jwt-encoded" : isJwtDecoded ? "jwt-decoded" : "json-ld";
1247
+ const credential = isJwtEncoded || isJwtDecoded ? _CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded, opts) : decoded;
1248
+ const format = isJwtEncoded || isJwtDecoded ? "jwt_vc" : "ldp_vc";
1249
+ return {
1250
+ original,
1251
+ decoded,
1252
+ format,
1253
+ type,
1254
+ credential
1255
+ };
1256
+ }
1257
+ static isJwtEncoded(original) {
1258
+ return ObjectUtils.isString(original) && original.startsWith("ey") && !original.includes("~");
1259
+ }
1260
+ static isSdJwtEncoded(original) {
1261
+ return ObjectUtils.isString(original) && original.startsWith("ey") && original.includes("~");
1262
+ }
1263
+ static isMsoMdocOid4VPEncoded(original) {
1264
+ return ObjectUtils.isString(original) && !original.startsWith("ey") && ObjectUtils.isBase64(original);
1265
+ }
1266
+ static isW3cCredential(credential) {
1267
+ return typeof credential === "object" && "@context" in credential && (credential.type?.includes("VerifiableCredential") || false);
1268
+ }
1269
+ static isCredential(original) {
1270
+ try {
1271
+ if (_CredentialMapper.isJwtEncoded(original)) {
1272
+ const vc = _CredentialMapper.toUniformCredential(original);
1273
+ return _CredentialMapper.isW3cCredential(vc);
1274
+ } else if (_CredentialMapper.isSdJwtEncoded(original)) {
1275
+ return true;
1276
+ } else if (_CredentialMapper.isMsoMdocDecodedCredential(original)) {
1277
+ return true;
1278
+ } else if (_CredentialMapper.isMsoMdocOid4VPEncoded(original)) {
1279
+ return true;
1280
+ }
1281
+ return _CredentialMapper.isW3cCredential(original) || _CredentialMapper.isSdJwtDecodedCredentialPayload(original) || _CredentialMapper.isJwtDecodedCredential(original) || _CredentialMapper.isSdJwtDecodedCredential(original);
1282
+ } catch (e) {
1283
+ return false;
1284
+ }
1285
+ }
1286
+ static isPresentation(original) {
1287
+ try {
1288
+ if (_CredentialMapper.isJwtEncoded(original)) {
1289
+ const vp = _CredentialMapper.toUniformPresentation(original);
1290
+ return _CredentialMapper.isW3cPresentation(vp);
1291
+ } else if (_CredentialMapper.isSdJwtEncoded(original)) {
1292
+ return false;
1293
+ } else if (_CredentialMapper.isMsoMdocDecodedPresentation(original)) {
1294
+ return true;
1295
+ } else if (_CredentialMapper.isMsoMdocOid4VPEncoded(original)) {
1296
+ return true;
1297
+ }
1298
+ return _CredentialMapper.isW3cPresentation(original) || _CredentialMapper.isSdJwtDecodedCredentialPayload(original) || _CredentialMapper.isJwtDecodedPresentation(original) || _CredentialMapper.isSdJwtDecodedCredential(original);
1299
+ } catch (e) {
1300
+ return false;
1301
+ }
1302
+ }
1303
+ static hasProof(original) {
1304
+ try {
1305
+ if (_CredentialMapper.isMsoMdocOid4VPEncoded(original)) {
1306
+ return false;
1307
+ } else if (_CredentialMapper.isMsoMdocDecodedCredential(original) || _CredentialMapper.isMsoMdocDecodedPresentation(original)) {
1308
+ return true;
1309
+ } else if (_CredentialMapper.isJwtEncoded(original) || _CredentialMapper.isJwtDecodedCredential(original)) {
1310
+ return true;
1311
+ } else if (_CredentialMapper.isSdJwtEncoded(original) || _CredentialMapper.isSdJwtDecodedCredential(original)) {
1312
+ return true;
1313
+ }
1314
+ if (typeof original !== "object") {
1315
+ return false;
1316
+ }
1317
+ if ("vc" in original && original.vc.proof) {
1318
+ return true;
1319
+ }
1320
+ if ("vp" in original && original.vp.proof) {
1321
+ return true;
1322
+ }
1323
+ return !!original.proof;
1324
+ } catch (e) {
1325
+ return false;
1326
+ }
1327
+ }
1328
+ static isW3cPresentation(presentation) {
1329
+ return typeof presentation === "object" && "@context" in presentation && (presentation.type?.includes("VerifiablePresentation") || false);
1330
+ }
1331
+ static isSdJwtDecodedCredentialPayload(credential) {
1332
+ return typeof credential === "object" && "vct" in credential;
1333
+ }
1334
+ static areOriginalVerifiableCredentialsEqual(firstOriginal, secondOriginal) {
1335
+ if (typeof firstOriginal === "string" || typeof secondOriginal === "string") {
1336
+ return firstOriginal === secondOriginal;
1337
+ } else if (_CredentialMapper.isMsoMdocDecodedCredential(firstOriginal) || _CredentialMapper.isMsoMdocDecodedCredential(secondOriginal)) {
1338
+ if (!_CredentialMapper.isMsoMdocDecodedCredential(firstOriginal) || !_CredentialMapper.isMsoMdocDecodedCredential(secondOriginal)) {
1339
+ return false;
1340
+ }
1341
+ return firstOriginal.issuerSigned.equals(secondOriginal.issuerSigned);
1342
+ } else if (_CredentialMapper.isSdJwtDecodedCredential(firstOriginal) || _CredentialMapper.isSdJwtDecodedCredential(secondOriginal)) {
1343
+ return firstOriginal.compactSdJwtVc === secondOriginal.compactSdJwtVc;
1344
+ } else {
1345
+ return JSON.stringify(secondOriginal.proof) === JSON.stringify(firstOriginal.proof);
1346
+ }
1347
+ }
1348
+ static isJsonLdAsString(original) {
1349
+ return ObjectUtils.isString(original) && original.includes("@context");
1350
+ }
1351
+ static isSdJwtDecodedCredential(original) {
1352
+ return typeof original === "object" && (original.compactSdJwtVc !== void 0 || original.kbJwt !== void 0);
1353
+ }
1354
+ static isMsoMdocDecodedCredential(original) {
1355
+ return typeof original === "object" && "issuerSigned" in original && original.issuerSigned !== void 0;
1356
+ }
1357
+ static isMsoMdocDecodedPresentation(original) {
1358
+ return typeof original === "object" && "version" in original && original.version !== void 0;
1359
+ }
1360
+ static isJwtDecodedCredential(original) {
1361
+ return typeof original === "object" && original.vc !== void 0 && original.iss !== void 0;
1362
+ }
1363
+ static isJwtDecodedPresentation(original) {
1364
+ return typeof original === "object" && original.vp !== void 0 && original.iss !== void 0;
1365
+ }
1366
+ static isWrappedSdJwtVerifiableCredential = isWrappedSdJwtVerifiableCredential;
1367
+ static isWrappedSdJwtVerifiablePresentation = isWrappedSdJwtVerifiablePresentation;
1368
+ static isWrappedW3CVerifiableCredential = isWrappedW3CVerifiableCredential;
1369
+ static isWrappedW3CVerifiablePresentation = isWrappedW3CVerifiablePresentation;
1370
+ static isWrappedMdocCredential = isWrappedMdocCredential;
1371
+ static isWrappedMdocPresentation = isWrappedMdocPresentation;
1372
+ static jwtEncodedPresentationToUniformPresentation(jwt, makeCredentialsUniform = true, opts) {
1373
+ return _CredentialMapper.jwtDecodedPresentationToUniformPresentation((0, import_jwt_decode.jwtDecode)(jwt), makeCredentialsUniform, opts);
1374
+ }
1375
+ static jwtDecodedPresentationToUniformPresentation(decoded, makeCredentialsUniform = true, opts) {
1376
+ const { iss, aud, jti, vp, ...rest } = decoded;
1377
+ const presentation = {
1378
+ ...rest,
1379
+ ...vp
1380
+ };
1381
+ if (makeCredentialsUniform) {
1382
+ if (!vp.verifiableCredential) {
1383
+ throw Error("Verifiable Presentation should have a verifiable credential at this point");
1384
+ }
1385
+ presentation.verifiableCredential = vp.verifiableCredential.map((vc) => _CredentialMapper.toUniformCredential(vc, opts));
1386
+ }
1387
+ if (iss) {
1388
+ const holder = presentation.holder;
1389
+ if (holder) {
1390
+ if (holder !== iss) {
1391
+ throw new Error(`Inconsistent holders between JWT claim (${iss}) and VC value (${holder})`);
1392
+ }
1393
+ }
1394
+ presentation.holder = iss;
1395
+ }
1396
+ if (aud) {
1397
+ const verifier = presentation.verifier;
1398
+ if (verifier) {
1399
+ if (verifier !== aud) {
1400
+ throw new Error(`Inconsistent holders between JWT claim (${aud}) and VC value (${verifier})`);
1401
+ }
1402
+ }
1403
+ presentation.verifier = aud;
1404
+ }
1405
+ if (jti) {
1406
+ const id = presentation.id;
1407
+ if (id && id !== jti) {
1408
+ throw new Error(`Inconsistent VP ids between JWT claim (${jti}) and VP value (${id})`);
1409
+ }
1410
+ presentation.id = jti;
1411
+ }
1412
+ return presentation;
1413
+ }
1414
+ static toUniformCredential(verifiableCredential, opts) {
1415
+ if (_CredentialMapper.isMsoMdocDecodedCredential(verifiableCredential)) {
1416
+ return mdocDecodedCredentialToUniformCredential(verifiableCredential);
1417
+ }
1418
+ if (_CredentialMapper.isSdJwtDecodedCredential(verifiableCredential)) {
1419
+ return sdJwtDecodedCredentialToUniformCredential(verifiableCredential, opts);
1420
+ }
1421
+ const original = typeof verifiableCredential !== "string" && _CredentialMapper.hasJWTProofType(verifiableCredential) ? _CredentialMapper.getFirstProof(verifiableCredential)?.jwt : verifiableCredential;
1422
+ if (!original) {
1423
+ throw Error("Could not determine original credential from passed in credential. Probably because a JWT proof type was present, but now is not available anymore");
1424
+ }
1425
+ const decoded = _CredentialMapper.decodeVerifiableCredential(original, opts?.hasher ?? sha2562);
1426
+ const isJwtEncoded = _CredentialMapper.isJwtEncoded(original);
1427
+ const isJwtDecoded = _CredentialMapper.isJwtDecodedCredential(original);
1428
+ const isSdJwtEncoded = _CredentialMapper.isSdJwtEncoded(original);
1429
+ const isMdocEncoded = _CredentialMapper.isMsoMdocOid4VPEncoded(original);
1430
+ if (isSdJwtEncoded) {
1431
+ return sdJwtDecodedCredentialToUniformCredential(decoded, opts);
1432
+ } else if (isMdocEncoded) {
1433
+ return mdocDecodedCredentialToUniformCredential(decodeMdocIssuerSigned(original));
1434
+ } else if (isJwtDecoded || isJwtEncoded) {
1435
+ return _CredentialMapper.jwtDecodedCredentialToUniformCredential(decoded, opts);
1436
+ } else {
1437
+ return decoded;
1438
+ }
1439
+ }
1440
+ static toUniformPresentation(presentation, opts) {
1441
+ if (_CredentialMapper.isSdJwtDecodedCredential(presentation)) {
1442
+ throw new Error("Converting SD-JWT VC to uniform VP is not supported.");
1443
+ } else if (_CredentialMapper.isMsoMdocDecodedPresentation(presentation)) {
1444
+ throw new Error("Converting MSO_MDOC to uniform VP is not supported yet.");
1445
+ }
1446
+ const proof = _CredentialMapper.getFirstProof(presentation);
1447
+ const original = typeof presentation !== "string" && _CredentialMapper.hasJWTProofType(presentation) ? proof?.jwt : presentation;
1448
+ if (!original) {
1449
+ throw Error("Could not determine original presentation, probably it was a converted JWT presentation, that is now missing the JWT value in the proof");
1450
+ }
1451
+ const decoded = _CredentialMapper.decodeVerifiablePresentation(original, opts?.hasher ?? sha2562);
1452
+ const isJwtEncoded = _CredentialMapper.isJwtEncoded(original);
1453
+ const isJwtDecoded = _CredentialMapper.isJwtDecodedPresentation(original);
1454
+ const uniformPresentation = isJwtEncoded || isJwtDecoded ? _CredentialMapper.jwtDecodedPresentationToUniformPresentation(decoded, false) : decoded;
1455
+ if (opts?.addContextIfMissing && !uniformPresentation["@context"]) {
1456
+ uniformPresentation["@context"] = [
1457
+ "https://www.w3.org/2018/credentials/v1"
1458
+ ];
1459
+ }
1460
+ uniformPresentation.verifiableCredential = uniformPresentation.verifiableCredential?.map((vc) => _CredentialMapper.toUniformCredential(vc, opts));
1461
+ return uniformPresentation;
1462
+ }
1463
+ static jwtEncodedCredentialToUniformCredential(jwt, opts) {
1464
+ return _CredentialMapper.jwtDecodedCredentialToUniformCredential((0, import_jwt_decode.jwtDecode)(jwt), opts);
1465
+ }
1466
+ static jwtDecodedCredentialToUniformCredential(decoded, opts) {
1467
+ const { exp, nbf, iss, vc, sub, jti, ...rest } = decoded;
1468
+ const credential = {
1469
+ ...rest,
1470
+ ...vc
1471
+ };
1472
+ const maxSkewInMS = opts?.maxTimeSkewInMS ?? 1500;
1473
+ if (exp) {
1474
+ const expDate = credential.expirationDate;
1475
+ const jwtExp = parseInt(exp.toString());
1476
+ const expDateAsStr = jwtExp < 9999999999 ? new Date(jwtExp * 1e3).toISOString().replace(/\.000Z/, "Z") : new Date(jwtExp).toISOString();
1477
+ if (expDate && expDate !== expDateAsStr) {
1478
+ const diff = Math.abs(new Date(expDateAsStr).getTime() - new Date(expDate).getTime());
1479
+ if (!maxSkewInMS || diff > maxSkewInMS) {
1480
+ throw new Error(`Inconsistent expiration dates between JWT claim (${expDateAsStr}) and VC value (${expDate})`);
1481
+ }
1482
+ }
1483
+ credential.expirationDate = expDateAsStr;
1484
+ }
1485
+ if (nbf) {
1486
+ const issuanceDate = credential.issuanceDate;
1487
+ const jwtNbf = parseInt(nbf.toString());
1488
+ const nbfDateAsStr = jwtNbf < 9999999999 ? new Date(jwtNbf * 1e3).toISOString().replace(/\.000Z/, "Z") : new Date(jwtNbf).toISOString();
1489
+ if (issuanceDate && issuanceDate !== nbfDateAsStr) {
1490
+ const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(issuanceDate).getTime());
1491
+ if (!maxSkewInMS || diff > maxSkewInMS) {
1492
+ throw new Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${issuanceDate})`);
1493
+ }
1494
+ }
1495
+ credential.issuanceDate = nbfDateAsStr;
1496
+ }
1497
+ if (iss) {
1498
+ const issuer = credential.issuer;
1499
+ if (issuer) {
1500
+ if (typeof issuer === "string") {
1501
+ if (issuer !== iss) {
1502
+ throw new Error(`Inconsistent issuers between JWT claim (${iss}) and VC value (${issuer})`);
1503
+ }
1504
+ } else {
1505
+ if (!issuer.id && Object.keys(issuer).length > 0) {
1506
+ issuer.id = iss;
1507
+ }
1508
+ if (issuer.id !== iss) {
1509
+ throw new Error(`Inconsistent issuers between JWT claim (${iss}) and VC value (${issuer.id})`);
1510
+ }
1511
+ }
1512
+ } else {
1513
+ credential.issuer = iss;
1514
+ }
1515
+ }
1516
+ if (sub) {
1517
+ const subjects = Array.isArray(credential.credentialSubject) ? credential.credentialSubject : [
1518
+ credential.credentialSubject
1519
+ ];
1520
+ for (let i = 0; i < subjects.length; i++) {
1521
+ const csId = subjects[i].id;
1522
+ if (csId && csId !== sub) {
1523
+ throw new Error(`Inconsistent credential subject ids between JWT claim (${sub}) and VC value (${csId})`);
1524
+ }
1525
+ Array.isArray(credential.credentialSubject) ? credential.credentialSubject[i].id = sub : credential.credentialSubject.id = sub;
1526
+ }
1527
+ }
1528
+ if (jti) {
1529
+ const id = credential.id;
1530
+ if (id && id !== jti) {
1531
+ throw new Error(`Inconsistent credential ids between JWT claim (${jti}) and VC value (${id})`);
1532
+ }
1533
+ credential.id = jti;
1534
+ }
1535
+ return credential;
1536
+ }
1537
+ static toExternalVerifiableCredential(verifiableCredential) {
1538
+ let proof;
1539
+ if (verifiableCredential.proof) {
1540
+ if (!verifiableCredential.proof.type) {
1541
+ throw new Error("Verifiable credential proof is missing a type");
1542
+ }
1543
+ if (!verifiableCredential.proof.created) {
1544
+ throw new Error("Verifiable credential proof is missing a created date");
1545
+ }
1546
+ if (!verifiableCredential.proof.proofPurpose) {
1547
+ throw new Error("Verifiable credential proof is missing a proof purpose");
1548
+ }
1549
+ if (!verifiableCredential.proof.verificationMethod) {
1550
+ throw new Error("Verifiable credential proof is missing a verification method");
1551
+ }
1552
+ proof = {
1553
+ ...verifiableCredential.proof,
1554
+ type: verifiableCredential.proof.type,
1555
+ created: verifiableCredential.proof.created,
1556
+ proofPurpose: verifiableCredential.proof.proofPurpose,
1557
+ verificationMethod: verifiableCredential.proof.verificationMethod
1558
+ };
1559
+ }
1560
+ return {
1561
+ ...verifiableCredential,
1562
+ type: verifiableCredential.type ? typeof verifiableCredential.type === "string" ? [
1563
+ verifiableCredential.type
1564
+ ] : verifiableCredential.type : [
1565
+ "VerifiableCredential"
1566
+ ],
1567
+ proof
1568
+ };
1569
+ }
1570
+ static storedCredentialToOriginalFormat(credential) {
1571
+ const type = _CredentialMapper.detectDocumentType(credential);
1572
+ if (typeof credential === "string") {
1573
+ if (type === 0) {
1574
+ return _CredentialMapper.toCompactJWT(credential);
1575
+ } else if (type === 1) {
1576
+ return JSON.parse(credential);
1577
+ } else if (type === 2) {
1578
+ return credential;
1579
+ }
1580
+ } else if (type === 0 && ObjectUtils.isObject(credential) && "vc" in credential) {
1581
+ return _CredentialMapper.toCompactJWT(credential);
1582
+ } else if (ObjectUtils.isObject(credential) && "proof" in credential && credential.proof.type === "JwtProof2020" && credential.proof.jwt) {
1583
+ return credential.proof.jwt;
1584
+ } else if (ObjectUtils.isObject(credential) && "proof" in credential && credential.proof.type === IProofType.SdJwtProof2024 && credential.proof.jwt) {
1585
+ return credential.proof.jwt;
1586
+ } else if (type === 2 && this.isSdJwtDecodedCredential(credential)) {
1587
+ return credential.compactSdJwtVc;
1588
+ }
1589
+ return credential;
1590
+ }
1591
+ static storedPresentationToOriginalFormat(presentation) {
1592
+ const type = _CredentialMapper.detectDocumentType(presentation);
1593
+ if (typeof presentation === "string") {
1594
+ if (type === 0) {
1595
+ return _CredentialMapper.toCompactJWT(presentation);
1596
+ } else if (type === 1) {
1597
+ return JSON.parse(presentation);
1598
+ }
1599
+ } else if (type === 0 && ObjectUtils.isObject(presentation) && "vp" in presentation) {
1600
+ return _CredentialMapper.toCompactJWT(presentation);
1601
+ } else if (ObjectUtils.isObject(presentation) && "proof" in presentation && presentation.proof.type === "JwtProof2020" && presentation.proof.jwt) {
1602
+ return presentation.proof.jwt;
1603
+ }
1604
+ return presentation;
1605
+ }
1606
+ static toCompactJWT(jwtDocument) {
1607
+ if (!jwtDocument || _CredentialMapper.detectDocumentType(jwtDocument) !== 0) {
1608
+ throw Error("Cannot convert non JWT credential to JWT");
1609
+ }
1610
+ if (typeof jwtDocument === "string") {
1611
+ return jwtDocument;
1612
+ }
1613
+ let proof;
1614
+ if (ObjectUtils.isObject(jwtDocument) && "vp" in jwtDocument) {
1615
+ proof = "jwt" in jwtDocument.vp.proof ? jwtDocument.vp.proof.jwt : jwtDocument.vp.proof;
1616
+ } else if (ObjectUtils.isObject(jwtDocument) && "vc" in jwtDocument) {
1617
+ proof = "jwt" in jwtDocument.vc.proof ? jwtDocument.vc.proof.jwt : jwtDocument.vc.proof;
1618
+ } else {
1619
+ proof = Array.isArray(jwtDocument.proof) ? jwtDocument.proof[0].jwt : jwtDocument.proof.jwt;
1620
+ }
1621
+ if (!proof) {
1622
+ throw Error(`Could not get JWT from supplied document`);
1623
+ }
1624
+ return proof;
1625
+ }
1626
+ static detectDocumentType(document) {
1627
+ if (this.isMsoMdocOid4VPEncoded(document) || this.isMsoMdocDecodedCredential(document)) {
1628
+ return 4;
1629
+ } else if (this.isMsoMdocDecodedPresentation(document) || this.isMsoMdocDecodedPresentation(document)) {
1630
+ return 4;
1631
+ } else if (this.isJsonLdAsString(document)) {
1632
+ return 1;
1633
+ } else if (this.isJwtEncoded(document)) {
1634
+ return 0;
1635
+ } else if (this.isSdJwtEncoded(document) || this.isSdJwtDecodedCredential(document)) {
1636
+ return 2;
1637
+ }
1638
+ const proofs = typeof document !== "string" && ("vc" in document ? document.vc.proof : "vp" in document ? document.vp.proof : document.proof);
1639
+ const proof = Array.isArray(proofs) ? proofs[0] : proofs;
1640
+ if (proof?.jwt) {
1641
+ return 0;
1642
+ } else if (proof?.type === "EthereumEip712Signature2021") {
1643
+ return 3;
1644
+ }
1645
+ return 1;
1646
+ }
1647
+ static hasJWTProofType(document) {
1648
+ if (typeof document === "string") {
1649
+ return false;
1650
+ }
1651
+ return !!_CredentialMapper.getFirstProof(document)?.jwt;
1652
+ }
1653
+ static getFirstProof(document) {
1654
+ if (!document || typeof document === "string") {
1655
+ return void 0;
1656
+ }
1657
+ const proofs = "vc" in document ? document.vc.proof : "vp" in document ? document.vp.proof : document.proof;
1658
+ return Array.isArray(proofs) ? proofs[0] : proofs;
1659
+ }
1660
+ static issuerCorrelationIdFromIssuerType(issuer) {
1661
+ if (issuer === void 0) {
1662
+ throw new Error("Issuer type us undefined");
1663
+ } else if (typeof issuer === "string") {
1664
+ return issuer;
1665
+ } else if (typeof issuer === "object") {
1666
+ if ("id" in issuer) {
1667
+ return issuer.id;
1668
+ } else {
1669
+ throw new Error("Encountered an invalid issuer object: missing id property");
1670
+ }
1671
+ } else {
1672
+ throw new Error("Invalid issuer type");
1673
+ }
1674
+ }
1675
+ };
1676
+ function isWrappedSdJwtVerifiableCredential(vc) {
1677
+ return vc.format === "vc+sd-jwt";
1678
+ }
1679
+ __name(isWrappedSdJwtVerifiableCredential, "isWrappedSdJwtVerifiableCredential");
1680
+ function isWrappedSdJwtVerifiablePresentation(vp) {
1681
+ return vp.format === "vc+sd-jwt";
1682
+ }
1683
+ __name(isWrappedSdJwtVerifiablePresentation, "isWrappedSdJwtVerifiablePresentation");
1684
+ var OriginalType = /* @__PURE__ */ function(OriginalType2) {
1685
+ OriginalType2["JSONLD"] = "json-ld";
1686
+ OriginalType2["JWT_ENCODED"] = "jwt-encoded";
1687
+ OriginalType2["JWT_DECODED"] = "jwt-decoded";
1688
+ OriginalType2["SD_JWT_VC_ENCODED"] = "sd-jwt-vc-encoded";
1689
+ OriginalType2["SD_JWT_VC_DECODED"] = "sd-jwt-vc-decoded";
1690
+ OriginalType2["MSO_MDOC_ENCODED"] = "mso_mdoc-encoded";
1691
+ OriginalType2["MSO_MDOC_DECODED"] = "mso_mdoc-decoded";
1692
+ return OriginalType2;
1693
+ }({});
1694
+ var JWT_PROOF_TYPE_2020 = "JwtProof2020";
1695
+ var DocumentFormat = /* @__PURE__ */ function(DocumentFormat2) {
1696
+ DocumentFormat2[DocumentFormat2["JWT"] = 0] = "JWT";
1697
+ DocumentFormat2[DocumentFormat2["JSONLD"] = 1] = "JSONLD";
1698
+ DocumentFormat2[DocumentFormat2["SD_JWT_VC"] = 2] = "SD_JWT_VC";
1699
+ DocumentFormat2[DocumentFormat2["EIP712"] = 3] = "EIP712";
1700
+ DocumentFormat2[DocumentFormat2["MSO_MDOC"] = 4] = "MSO_MDOC";
1701
+ return DocumentFormat2;
1702
+ }({});
1703
+
1704
+ // src/mapper/jsonld-language-values.ts
1705
+ var isLanguageValueObject = /* @__PURE__ */ __name((claim) => {
1706
+ if (!claim || !ObjectUtils.isObject(claim) || Array.isArray(claim)) {
1707
+ return false;
1708
+ }
1709
+ const keys = Object.keys(claim);
1710
+ if (keys.length !== 2) {
1711
+ return false;
1712
+ } else if (!("language" in claim && !!claim.language)) {
1713
+ return false;
1714
+ } else if (!("value" in claim && !!claim.value)) {
1715
+ return false;
1716
+ }
1717
+ return true;
1718
+ }, "isLanguageValueObject");
1719
+ var isLanguageValueObjects = /* @__PURE__ */ __name((claim) => {
1720
+ if (!claim || !Array.isArray(claim)) {
1721
+ return false;
1722
+ }
1723
+ return claim.every((val) => isLanguageValueObject(val));
1724
+ }, "isLanguageValueObjects");
1725
+ var toLanguageValueObject = /* @__PURE__ */ __name((claim) => {
1726
+ return isLanguageValueObject(claim) ? claim : void 0;
1727
+ }, "toLanguageValueObject");
1728
+ var toLanguageValueObjects = /* @__PURE__ */ __name((claim) => {
1729
+ if (isLanguageValueObject(claim)) {
1730
+ return ObjectUtils.asArray(toLanguageValueObject(claim));
1731
+ } else if (isLanguageValueObjects(claim)) {
1732
+ return claim;
1733
+ }
1734
+ return void 0;
1735
+ }, "toLanguageValueObjects");
1736
+ var mapLanguageValue = /* @__PURE__ */ __name((claim, opts) => {
1737
+ const langValues = toLanguageValueObjects(claim);
1738
+ if (Array.isArray(langValues)) {
1739
+ if (langValues.length === 0) {
1740
+ return claim;
1741
+ }
1742
+ const filteredLangValues = langValues.filter((val) => opts?.language ? val.language.toLowerCase().includes(opts.language.toLowerCase()) : true);
1743
+ let langValue;
1744
+ if (filteredLangValues.length > 0) {
1745
+ langValue = filteredLangValues[0];
1746
+ } else {
1747
+ if (opts?.fallbackToFirstObject === false) {
1748
+ return claim;
1749
+ }
1750
+ langValue = langValues[0];
1751
+ }
1752
+ return langValue.value;
1753
+ }
1754
+ return claim;
1755
+ }, "mapLanguageValue");
1756
+ var mapLanguageValues = /* @__PURE__ */ __name((claimsOrCredential, opts) => {
1757
+ const result = opts?.noDeepClone ? claimsOrCredential : JSON.parse(JSON.stringify(claimsOrCredential));
1758
+ Object.keys(claimsOrCredential).forEach((key) => {
1759
+ result[key] = mapLanguageValue(result[key], opts);
1760
+ if (ObjectUtils.isObject(result[key]) || Array.isArray(result[key])) {
1761
+ result[key] = mapLanguageValues(result[key], {
1762
+ ...opts,
1763
+ noDeepClone: true
1764
+ });
1765
+ }
1766
+ });
1767
+ return result;
1768
+ }, "mapLanguageValues");
1769
+
1770
+ // src/index.ts
1771
+ var logger = Loggers.DEFAULT.get("sphereon:ssi");
1772
+ logger.debug(`Sphereon logger initialized`);
1773
+ //# sourceMappingURL=index.cjs.map