@sd-jwt/core 0.15.2-next.8 → 0.15.2-next.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -39,6 +39,11 @@ var __async = (__this, __arguments, generator) => {
39
39
  };
40
40
 
41
41
  // src/index.ts
42
+ import { getSDAlgAndPayload as getSDAlgAndPayload2 } from "@sd-jwt/decode";
43
+ import {
44
+ IANA_HASH_ALGORITHMS,
45
+ KB_JWT_TYP as KB_JWT_TYP2
46
+ } from "@sd-jwt/types";
42
47
  import {
43
48
  base64urlDecode,
44
49
  base64urlEncode as base64urlEncode3,
@@ -46,9 +51,179 @@ import {
46
51
  uint8ArrayToBase64Url as uint8ArrayToBase64Url2
47
52
  } from "@sd-jwt/utils";
48
53
 
54
+ // src/flattenJSON.ts
55
+ import { splitSdJwt } from "@sd-jwt/decode";
56
+ import { SD_SEPARATOR } from "@sd-jwt/types";
57
+ import { SDJWTException } from "@sd-jwt/utils";
58
+ var FlattenJSON = class _FlattenJSON {
59
+ constructor(data) {
60
+ this.disclosures = data.disclosures;
61
+ this.kb_jwt = data.kb_jwt;
62
+ this.payload = data.jwtData.payload;
63
+ this.signature = data.jwtData.signature;
64
+ this.protected = data.jwtData.protected;
65
+ }
66
+ static fromEncode(encodedSdJwt) {
67
+ const { jwt, disclosures, kbJwt } = splitSdJwt(encodedSdJwt);
68
+ const { 0: protectedHeader, 1: payload, 2: signature } = jwt.split(".");
69
+ if (!protectedHeader || !payload || !signature) {
70
+ throw new SDJWTException("Invalid JWT");
71
+ }
72
+ return new _FlattenJSON({
73
+ jwtData: {
74
+ protected: protectedHeader,
75
+ payload,
76
+ signature
77
+ },
78
+ disclosures,
79
+ kb_jwt: kbJwt
80
+ });
81
+ }
82
+ static fromSerialized(json) {
83
+ return new _FlattenJSON({
84
+ jwtData: {
85
+ protected: json.protected,
86
+ payload: json.payload,
87
+ signature: json.signature
88
+ },
89
+ disclosures: json.header.disclosures,
90
+ kb_jwt: json.header.kb_jwt
91
+ });
92
+ }
93
+ toJson() {
94
+ return {
95
+ payload: this.payload,
96
+ signature: this.signature,
97
+ protected: this.protected,
98
+ header: {
99
+ disclosures: this.disclosures,
100
+ kb_jwt: this.kb_jwt
101
+ }
102
+ };
103
+ }
104
+ toEncoded() {
105
+ var _a;
106
+ const data = [];
107
+ const jwt = `${this.protected}.${this.payload}.${this.signature}`;
108
+ data.push(jwt);
109
+ if (this.disclosures && this.disclosures.length > 0) {
110
+ const disclosures = this.disclosures.join(SD_SEPARATOR);
111
+ data.push(disclosures);
112
+ }
113
+ const kb_jwt = (_a = this.kb_jwt) != null ? _a : "";
114
+ data.push(kb_jwt);
115
+ return data.join(SD_SEPARATOR);
116
+ }
117
+ };
118
+
119
+ // src/generalJSON.ts
120
+ import { splitSdJwt as splitSdJwt2 } from "@sd-jwt/decode";
121
+ import { SD_SEPARATOR as SD_SEPARATOR2 } from "@sd-jwt/types";
122
+ import { base64urlEncode, SDJWTException as SDJWTException2 } from "@sd-jwt/utils";
123
+ var GeneralJSON = class _GeneralJSON {
124
+ constructor(data) {
125
+ this.payload = data.payload;
126
+ this.disclosures = data.disclosures;
127
+ this.kb_jwt = data.kb_jwt;
128
+ this.signatures = data.signatures;
129
+ }
130
+ static fromEncode(encodedSdJwt) {
131
+ const { jwt, disclosures, kbJwt } = splitSdJwt2(encodedSdJwt);
132
+ const { 0: protectedHeader, 1: payload, 2: signature } = jwt.split(".");
133
+ if (!protectedHeader || !payload || !signature) {
134
+ throw new SDJWTException2("Invalid JWT");
135
+ }
136
+ return new _GeneralJSON({
137
+ payload,
138
+ disclosures,
139
+ kb_jwt: kbJwt,
140
+ signatures: [
141
+ {
142
+ protected: protectedHeader,
143
+ signature
144
+ }
145
+ ]
146
+ });
147
+ }
148
+ static fromSerialized(json) {
149
+ var _a, _b, _c;
150
+ if (!json.signatures[0]) {
151
+ throw new SDJWTException2("Invalid JSON");
152
+ }
153
+ const disclosures = (_b = (_a = json.signatures[0].header) == null ? void 0 : _a.disclosures) != null ? _b : [];
154
+ const kb_jwt = (_c = json.signatures[0].header) == null ? void 0 : _c.kb_jwt;
155
+ return new _GeneralJSON({
156
+ payload: json.payload,
157
+ disclosures,
158
+ kb_jwt,
159
+ signatures: json.signatures.map((s) => {
160
+ var _a2;
161
+ return {
162
+ protected: s.protected,
163
+ signature: s.signature,
164
+ kid: (_a2 = s.header) == null ? void 0 : _a2.kid
165
+ };
166
+ })
167
+ });
168
+ }
169
+ toJson() {
170
+ return {
171
+ payload: this.payload,
172
+ signatures: this.signatures.map((s, i) => {
173
+ if (i !== 0) {
174
+ return {
175
+ header: {
176
+ kid: s.kid
177
+ },
178
+ protected: s.protected,
179
+ signature: s.signature
180
+ };
181
+ }
182
+ return {
183
+ header: {
184
+ disclosures: this.disclosures,
185
+ kid: s.kid,
186
+ kb_jwt: this.kb_jwt
187
+ },
188
+ protected: s.protected,
189
+ signature: s.signature
190
+ };
191
+ })
192
+ };
193
+ }
194
+ toEncoded(index) {
195
+ var _a;
196
+ if (index < 0 || index >= this.signatures.length) {
197
+ throw new SDJWTException2("Index out of bounds");
198
+ }
199
+ const data = [];
200
+ const { protected: protectedHeader, signature } = this.signatures[index];
201
+ const jwt = `${protectedHeader}.${this.payload}.${signature}`;
202
+ data.push(jwt);
203
+ if (this.disclosures && this.disclosures.length > 0) {
204
+ const disclosures = this.disclosures.join(SD_SEPARATOR2);
205
+ data.push(disclosures);
206
+ }
207
+ const kb = (_a = this.kb_jwt) != null ? _a : "";
208
+ data.push(kb);
209
+ return data.join(SD_SEPARATOR2);
210
+ }
211
+ addSignature(protectedHeader, signer, kid) {
212
+ return __async(this, null, function* () {
213
+ const header = base64urlEncode(JSON.stringify(protectedHeader));
214
+ const signature = yield signer(`${header}.${this.payload}`);
215
+ this.signatures.push({
216
+ protected: header,
217
+ signature,
218
+ kid
219
+ });
220
+ });
221
+ }
222
+ };
223
+
49
224
  // src/jwt.ts
50
- import { base64urlEncode, SDJWTException } from "@sd-jwt/utils";
51
225
  import { decodeJwt } from "@sd-jwt/decode";
226
+ import { base64urlEncode as base64urlEncode2, SDJWTException as SDJWTException3 } from "@sd-jwt/utils";
52
227
  var Jwt = class _Jwt {
53
228
  constructor(data) {
54
229
  this.header = data == null ? void 0 : data.header;
@@ -83,18 +258,18 @@ var Jwt = class _Jwt {
83
258
  }
84
259
  getUnsignedToken() {
85
260
  if (!this.header || !this.payload) {
86
- throw new SDJWTException("Serialize Error: Invalid JWT");
261
+ throw new SDJWTException3("Serialize Error: Invalid JWT");
87
262
  }
88
263
  if (this.encoded) {
89
264
  const parts = this.encoded.split(".");
90
265
  if (parts.length !== 3) {
91
- throw new SDJWTException(`Invalid JWT format: ${this.encoded}`);
266
+ throw new SDJWTException3(`Invalid JWT format: ${this.encoded}`);
92
267
  }
93
268
  const unsignedToken = parts.slice(0, 2).join(".");
94
269
  return unsignedToken;
95
270
  }
96
- const header = base64urlEncode(JSON.stringify(this.header));
97
- const payload = base64urlEncode(JSON.stringify(this.payload));
271
+ const header = base64urlEncode2(JSON.stringify(this.header));
272
+ const payload = base64urlEncode2(JSON.stringify(this.payload));
98
273
  return `${header}.${payload}`;
99
274
  }
100
275
  sign(signer) {
@@ -109,10 +284,10 @@ var Jwt = class _Jwt {
109
284
  return this.encoded;
110
285
  }
111
286
  if (!this.header || !this.payload || !this.signature) {
112
- throw new SDJWTException("Serialize Error: Invalid JWT");
287
+ throw new SDJWTException3("Serialize Error: Invalid JWT");
113
288
  }
114
- const header = base64urlEncode(JSON.stringify(this.header));
115
- const payload = base64urlEncode(JSON.stringify(this.payload));
289
+ const header = base64urlEncode2(JSON.stringify(this.header));
290
+ const payload = base64urlEncode2(JSON.stringify(this.payload));
116
291
  const signature = this.signature;
117
292
  const compact = `${header}.${payload}.${signature}`;
118
293
  this.encoded = compact;
@@ -131,21 +306,21 @@ var Jwt = class _Jwt {
131
306
  const skew = (options == null ? void 0 : options.skewSeconds) ? options.skewSeconds : 0;
132
307
  const currentDate = (_a = options == null ? void 0 : options.currentDate) != null ? _a : Math.floor(Date.now() / 1e3);
133
308
  if (((_b = this.payload) == null ? void 0 : _b.iat) && this.payload.iat - skew > currentDate) {
134
- throw new SDJWTException("Verify Error: JWT is not yet valid");
309
+ throw new SDJWTException3("Verify Error: JWT is not yet valid");
135
310
  }
136
311
  if (((_c = this.payload) == null ? void 0 : _c.nbf) && this.payload.nbf - skew > currentDate) {
137
- throw new SDJWTException("Verify Error: JWT is not yet valid");
312
+ throw new SDJWTException3("Verify Error: JWT is not yet valid");
138
313
  }
139
314
  if (((_d = this.payload) == null ? void 0 : _d.exp) && this.payload.exp + skew < currentDate) {
140
- throw new SDJWTException("Verify Error: JWT is expired");
315
+ throw new SDJWTException3("Verify Error: JWT is expired");
141
316
  }
142
317
  if (!this.signature) {
143
- throw new SDJWTException("Verify Error: no signature in JWT");
318
+ throw new SDJWTException3("Verify Error: no signature in JWT");
144
319
  }
145
320
  const data = this.getUnsignedToken();
146
321
  const verified = yield verifier(data, this.signature);
147
322
  if (!verified) {
148
- throw new SDJWTException("Verify Error: Invalid JWT Signature");
323
+ throw new SDJWTException3("Verify Error: Invalid JWT Signature");
149
324
  }
150
325
  return { payload: this.payload, header: this.header };
151
326
  });
@@ -153,10 +328,10 @@ var Jwt = class _Jwt {
153
328
  };
154
329
 
155
330
  // src/kbjwt.ts
156
- import { SDJWTException as SDJWTException2 } from "@sd-jwt/utils";
157
331
  import {
158
332
  KB_JWT_TYP
159
333
  } from "@sd-jwt/types";
334
+ import { SDJWTException as SDJWTException4 } from "@sd-jwt/utils";
160
335
  var KBJwt = class _KBJwt extends Jwt {
161
336
  // Checking the validity of the key binding jwt
162
337
  // the type unknown is not good, but we don't know at this point how to get the public key of the signer, this is defined in the kbVerifier
@@ -164,11 +339,11 @@ var KBJwt = class _KBJwt extends Jwt {
164
339
  return __async(this, null, function* () {
165
340
  var _a;
166
341
  if (!this.header || !this.payload || !this.signature) {
167
- throw new SDJWTException2("Verify Error: Invalid JWT");
342
+ throw new SDJWTException4("Verify Error: Invalid JWT");
168
343
  }
169
344
  if (!this.header.alg || this.header.alg === "none" || !this.header.typ || this.header.typ !== KB_JWT_TYP || !this.payload.iat || !this.payload.aud || !this.payload.nonce || // this is for backward compatibility with version 06
170
345
  !(this.payload.sd_hash || ((_a = this.payload) == null ? void 0 : _a._sd_hash))) {
171
- throw new SDJWTException2("Invalid Key Binding Jwt");
346
+ throw new SDJWTException4("Invalid Key Binding Jwt");
172
347
  }
173
348
  const data = this.getUnsignedToken();
174
349
  const verified = yield values.verifier(
@@ -177,10 +352,10 @@ var KBJwt = class _KBJwt extends Jwt {
177
352
  values.payload
178
353
  );
179
354
  if (!verified) {
180
- throw new SDJWTException2("Verify Error: Invalid JWT Signature");
355
+ throw new SDJWTException4("Verify Error: Invalid JWT Signature");
181
356
  }
182
357
  if (this.payload.nonce !== values.nonce) {
183
- throw new SDJWTException2("Verify Error: Invalid Nonce");
358
+ throw new SDJWTException4("Verify Error: Invalid Nonce");
184
359
  }
185
360
  return { payload: this.payload, header: this.header };
186
361
  });
@@ -200,9 +375,20 @@ var KBJwt = class _KBJwt extends Jwt {
200
375
  }
201
376
  };
202
377
 
378
+ // src/sdjwt.ts
379
+ import { createHashMapping, getSDAlgAndPayload, unpack } from "@sd-jwt/decode";
380
+ import { transformPresentationFrame } from "@sd-jwt/present";
381
+ import {
382
+ SD_DECOY,
383
+ SD_DIGEST,
384
+ SD_LIST_KEY,
385
+ SD_SEPARATOR as SD_SEPARATOR3
386
+ } from "@sd-jwt/types";
387
+ import { Disclosure, SDJWTException as SDJWTException5 } from "@sd-jwt/utils";
388
+
203
389
  // src/decoy.ts
204
390
  import { uint8ArrayToBase64Url } from "@sd-jwt/utils";
205
- var createDecoy = (hash, saltGenerator) => __async(void 0, null, function* () {
391
+ var createDecoy = (hash, saltGenerator) => __async(null, null, function* () {
206
392
  const { hasher, alg } = hash;
207
393
  const salt = yield saltGenerator(16);
208
394
  const decoy = yield hasher(salt, alg);
@@ -210,15 +396,6 @@ var createDecoy = (hash, saltGenerator) => __async(void 0, null, function* () {
210
396
  });
211
397
 
212
398
  // src/sdjwt.ts
213
- import { SDJWTException as SDJWTException3, Disclosure } from "@sd-jwt/utils";
214
- import {
215
- SD_DECOY,
216
- SD_DIGEST,
217
- SD_LIST_KEY,
218
- SD_SEPARATOR
219
- } from "@sd-jwt/types";
220
- import { createHashMapping, getSDAlgAndPayload, unpack } from "@sd-jwt/decode";
221
- import { transformPresentationFrame } from "@sd-jwt/present";
222
399
  var SDJwt = class _SDJwt {
223
400
  constructor(data) {
224
401
  this.jwt = data == null ? void 0 : data.jwt;
@@ -227,7 +404,7 @@ var SDJwt = class _SDJwt {
227
404
  }
228
405
  static decodeSDJwt(sdjwt, hasher) {
229
406
  return __async(this, null, function* () {
230
- const [encodedJwt, ...encodedDisclosures] = sdjwt.split(SD_SEPARATOR);
407
+ const [encodedJwt, ...encodedDisclosures] = sdjwt.split(SD_SEPARATOR3);
231
408
  const jwt = Jwt.fromEncode(encodedJwt);
232
409
  if (!jwt.payload) {
233
410
  throw new Error("Payload is undefined on the JWT. Invalid state reached");
@@ -255,7 +432,7 @@ var SDJwt = class _SDJwt {
255
432
  }
256
433
  static extractJwt(encodedSdJwt) {
257
434
  return __async(this, null, function* () {
258
- const [encodedJwt, ..._encodedDisclosures] = encodedSdJwt.split(SD_SEPARATOR);
435
+ const [encodedJwt, ..._encodedDisclosures] = encodedSdJwt.split(SD_SEPARATOR3);
259
436
  return Jwt.fromEncode(encodedJwt);
260
437
  });
261
438
  }
@@ -284,7 +461,7 @@ var SDJwt = class _SDJwt {
284
461
  return __async(this, null, function* () {
285
462
  var _a;
286
463
  if (!((_a = this.jwt) == null ? void 0 : _a.payload) || !this.disclosures) {
287
- throw new SDJWTException3("Invalid sd-jwt: jwt or disclosures is missing");
464
+ throw new SDJWTException5("Invalid sd-jwt: jwt or disclosures is missing");
288
465
  }
289
466
  const { _sd_alg: alg } = getSDAlgAndPayload(this.jwt.payload);
290
467
  const hash = { alg, hasher };
@@ -302,16 +479,16 @@ var SDJwt = class _SDJwt {
302
479
  encodeSDJwt() {
303
480
  const data = [];
304
481
  if (!this.jwt) {
305
- throw new SDJWTException3("Invalid sd-jwt: jwt is missing");
482
+ throw new SDJWTException5("Invalid sd-jwt: jwt is missing");
306
483
  }
307
484
  const encodedJwt = this.jwt.encodeJwt();
308
485
  data.push(encodedJwt);
309
486
  if (this.disclosures && this.disclosures.length > 0) {
310
- const encodeddisclosures = this.disclosures.map((dc) => dc.encode()).join(SD_SEPARATOR);
487
+ const encodeddisclosures = this.disclosures.map((dc) => dc.encode()).join(SD_SEPARATOR3);
311
488
  data.push(encodeddisclosures);
312
489
  }
313
490
  data.push(this.kbJwt ? this.kbJwt.encodeJwt() : "");
314
- return data.join(SD_SEPARATOR);
491
+ return data.join(SD_SEPARATOR3);
315
492
  }
316
493
  keys(hasher) {
317
494
  return __async(this, null, function* () {
@@ -322,7 +499,7 @@ var SDJwt = class _SDJwt {
322
499
  return __async(this, null, function* () {
323
500
  var _a, _b;
324
501
  if (!((_a = this.jwt) == null ? void 0 : _a.payload) || !this.disclosures) {
325
- throw new SDJWTException3("Invalid sd-jwt: jwt or disclosures is missing");
502
+ throw new SDJWTException5("Invalid sd-jwt: jwt or disclosures is missing");
326
503
  }
327
504
  const { disclosureKeymap } = yield unpack(
328
505
  (_b = this.jwt) == null ? void 0 : _b.payload,
@@ -336,7 +513,7 @@ var SDJwt = class _SDJwt {
336
513
  return __async(this, null, function* () {
337
514
  var _a;
338
515
  if (!((_a = this.jwt) == null ? void 0 : _a.payload) || !this.disclosures) {
339
- throw new SDJWTException3("Invalid sd-jwt: jwt or disclosures is missing");
516
+ throw new SDJWTException5("Invalid sd-jwt: jwt or disclosures is missing");
340
517
  }
341
518
  const { unpackedObj } = yield unpack(
342
519
  this.jwt.payload,
@@ -359,7 +536,7 @@ var listKeys = (obj, prefix = "") => {
359
536
  }
360
537
  return keys;
361
538
  };
362
- var pack = (claims, disclosureFrame, hash, saltGenerator) => __async(void 0, null, function* () {
539
+ var pack = (claims, disclosureFrame, hash, saltGenerator) => __async(null, null, function* () {
363
540
  var _a, _b;
364
541
  if (!disclosureFrame) {
365
542
  return {
@@ -375,7 +552,7 @@ var pack = (claims, disclosureFrame, hash, saltGenerator) => __async(void 0, nul
375
552
  const recursivePackedClaims2 = {};
376
553
  for (const key in disclosureFrame) {
377
554
  if (key !== SD_DIGEST) {
378
- const idx = Number.parseInt(key);
555
+ const idx = Number.parseInt(key, 10);
379
556
  const packed = yield pack(
380
557
  claims[idx],
381
558
  disclosureFrame[idx],
@@ -410,7 +587,7 @@ var pack = (claims, disclosureFrame, hash, saltGenerator) => __async(void 0, nul
410
587
  for (const key in disclosureFrame) {
411
588
  if (key !== SD_DIGEST) {
412
589
  const packed = yield pack(
413
- // @ts-ignore
590
+ // @ts-expect-error
414
591
  claims[key],
415
592
  disclosureFrame[key],
416
593
  hash,
@@ -443,183 +620,6 @@ var pack = (claims, disclosureFrame, hash, saltGenerator) => __async(void 0, nul
443
620
  return { packedClaims, disclosures };
444
621
  });
445
622
 
446
- // src/index.ts
447
- import {
448
- KB_JWT_TYP as KB_JWT_TYP2,
449
- IANA_HASH_ALGORITHMS
450
- } from "@sd-jwt/types";
451
- import { getSDAlgAndPayload as getSDAlgAndPayload2 } from "@sd-jwt/decode";
452
-
453
- // src/flattenJSON.ts
454
- import { SDJWTException as SDJWTException4 } from "@sd-jwt/utils";
455
- import { splitSdJwt } from "@sd-jwt/decode";
456
- import { SD_SEPARATOR as SD_SEPARATOR2 } from "@sd-jwt/types";
457
- var FlattenJSON = class _FlattenJSON {
458
- constructor(data) {
459
- this.disclosures = data.disclosures;
460
- this.kb_jwt = data.kb_jwt;
461
- this.payload = data.jwtData.payload;
462
- this.signature = data.jwtData.signature;
463
- this.protected = data.jwtData.protected;
464
- }
465
- static fromEncode(encodedSdJwt) {
466
- const { jwt, disclosures, kbJwt } = splitSdJwt(encodedSdJwt);
467
- const { 0: protectedHeader, 1: payload, 2: signature } = jwt.split(".");
468
- if (!protectedHeader || !payload || !signature) {
469
- throw new SDJWTException4("Invalid JWT");
470
- }
471
- return new _FlattenJSON({
472
- jwtData: {
473
- protected: protectedHeader,
474
- payload,
475
- signature
476
- },
477
- disclosures,
478
- kb_jwt: kbJwt
479
- });
480
- }
481
- static fromSerialized(json) {
482
- return new _FlattenJSON({
483
- jwtData: {
484
- protected: json.protected,
485
- payload: json.payload,
486
- signature: json.signature
487
- },
488
- disclosures: json.header.disclosures,
489
- kb_jwt: json.header.kb_jwt
490
- });
491
- }
492
- toJson() {
493
- return {
494
- payload: this.payload,
495
- signature: this.signature,
496
- protected: this.protected,
497
- header: {
498
- disclosures: this.disclosures,
499
- kb_jwt: this.kb_jwt
500
- }
501
- };
502
- }
503
- toEncoded() {
504
- var _a;
505
- const data = [];
506
- const jwt = `${this.protected}.${this.payload}.${this.signature}`;
507
- data.push(jwt);
508
- if (this.disclosures && this.disclosures.length > 0) {
509
- const disclosures = this.disclosures.join(SD_SEPARATOR2);
510
- data.push(disclosures);
511
- }
512
- const kb_jwt = (_a = this.kb_jwt) != null ? _a : "";
513
- data.push(kb_jwt);
514
- return data.join(SD_SEPARATOR2);
515
- }
516
- };
517
-
518
- // src/generalJSON.ts
519
- import { base64urlEncode as base64urlEncode2, SDJWTException as SDJWTException5 } from "@sd-jwt/utils";
520
- import { splitSdJwt as splitSdJwt2 } from "@sd-jwt/decode";
521
- import { SD_SEPARATOR as SD_SEPARATOR3 } from "@sd-jwt/types";
522
- var GeneralJSON = class _GeneralJSON {
523
- constructor(data) {
524
- this.payload = data.payload;
525
- this.disclosures = data.disclosures;
526
- this.kb_jwt = data.kb_jwt;
527
- this.signatures = data.signatures;
528
- }
529
- static fromEncode(encodedSdJwt) {
530
- const { jwt, disclosures, kbJwt } = splitSdJwt2(encodedSdJwt);
531
- const { 0: protectedHeader, 1: payload, 2: signature } = jwt.split(".");
532
- if (!protectedHeader || !payload || !signature) {
533
- throw new SDJWTException5("Invalid JWT");
534
- }
535
- return new _GeneralJSON({
536
- payload,
537
- disclosures,
538
- kb_jwt: kbJwt,
539
- signatures: [
540
- {
541
- protected: protectedHeader,
542
- signature
543
- }
544
- ]
545
- });
546
- }
547
- static fromSerialized(json) {
548
- var _a, _b, _c;
549
- if (!json.signatures[0]) {
550
- throw new SDJWTException5("Invalid JSON");
551
- }
552
- const disclosures = (_b = (_a = json.signatures[0].header) == null ? void 0 : _a.disclosures) != null ? _b : [];
553
- const kb_jwt = (_c = json.signatures[0].header) == null ? void 0 : _c.kb_jwt;
554
- return new _GeneralJSON({
555
- payload: json.payload,
556
- disclosures,
557
- kb_jwt,
558
- signatures: json.signatures.map((s) => {
559
- var _a2;
560
- return {
561
- protected: s.protected,
562
- signature: s.signature,
563
- kid: (_a2 = s.header) == null ? void 0 : _a2.kid
564
- };
565
- })
566
- });
567
- }
568
- toJson() {
569
- return {
570
- payload: this.payload,
571
- signatures: this.signatures.map((s, i) => {
572
- if (i !== 0) {
573
- return {
574
- header: {
575
- kid: s.kid
576
- },
577
- protected: s.protected,
578
- signature: s.signature
579
- };
580
- }
581
- return {
582
- header: {
583
- disclosures: this.disclosures,
584
- kid: s.kid,
585
- kb_jwt: this.kb_jwt
586
- },
587
- protected: s.protected,
588
- signature: s.signature
589
- };
590
- })
591
- };
592
- }
593
- toEncoded(index) {
594
- var _a;
595
- if (index < 0 || index >= this.signatures.length) {
596
- throw new SDJWTException5("Index out of bounds");
597
- }
598
- const data = [];
599
- const { protected: protectedHeader, signature } = this.signatures[index];
600
- const jwt = `${protectedHeader}.${this.payload}.${signature}`;
601
- data.push(jwt);
602
- if (this.disclosures && this.disclosures.length > 0) {
603
- const disclosures = this.disclosures.join(SD_SEPARATOR3);
604
- data.push(disclosures);
605
- }
606
- const kb = (_a = this.kb_jwt) != null ? _a : "";
607
- data.push(kb);
608
- return data.join(SD_SEPARATOR3);
609
- }
610
- addSignature(protectedHeader, signer, kid) {
611
- return __async(this, null, function* () {
612
- const header = base64urlEncode2(JSON.stringify(protectedHeader));
613
- const signature = yield signer(`${header}.${this.payload}`);
614
- this.signatures.push({
615
- protected: header,
616
- signature,
617
- kid
618
- });
619
- });
620
- }
621
- };
622
-
623
623
  // src/index.ts
624
624
  var _SDJwtInstance = class _SDJwtInstance {
625
625
  constructor(userConfig) {
@@ -716,7 +716,7 @@ var _SDJwtInstance = class _SDJwtInstance {
716
716
  * @param disclosureFrame
717
717
  * @returns
718
718
  */
719
- validateReservedFields(disclosureFrame) {
719
+ validateReservedFields(_disclosureFrame) {
720
720
  return;
721
721
  }
722
722
  present(encodedSDJwt, presentationFrame, options) {
@@ -971,7 +971,7 @@ var SDJwtGeneralJSONInstance = class {
971
971
  * @param disclosureFrame
972
972
  * @returns
973
973
  */
974
- validateReservedFields(disclosureFrame) {
974
+ validateReservedFields(_disclosureFrame) {
975
975
  return;
976
976
  }
977
977
  present(generalJSON, presentationFrame, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sd-jwt/core",
3
- "version": "0.15.2-next.8+f68c847",
3
+ "version": "0.15.2-next.9+75d5780",
4
4
  "description": "sd-jwt draft 7 implementation in typescript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -25,7 +25,7 @@
25
25
  "sd-jwt-vc"
26
26
  ],
27
27
  "engines": {
28
- "node": ">=18"
28
+ "node": ">=20"
29
29
  },
30
30
  "repository": {
31
31
  "url": "https://github.com/openwallet-foundation/sd-jwt-js"
@@ -37,13 +37,13 @@
37
37
  },
38
38
  "license": "Apache-2.0",
39
39
  "devDependencies": {
40
- "@sd-jwt/crypto-nodejs": "0.15.2-next.8+f68c847"
40
+ "@sd-jwt/crypto-nodejs": "0.15.2-next.9+75d5780"
41
41
  },
42
42
  "dependencies": {
43
- "@sd-jwt/decode": "0.15.2-next.8+f68c847",
44
- "@sd-jwt/present": "0.15.2-next.8+f68c847",
45
- "@sd-jwt/types": "0.15.2-next.8+f68c847",
46
- "@sd-jwt/utils": "0.15.2-next.8+f68c847"
43
+ "@sd-jwt/decode": "0.15.2-next.9+75d5780",
44
+ "@sd-jwt/present": "0.15.2-next.9+75d5780",
45
+ "@sd-jwt/types": "0.15.2-next.9+75d5780",
46
+ "@sd-jwt/utils": "0.15.2-next.9+75d5780"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"
@@ -61,5 +61,5 @@
61
61
  "esm"
62
62
  ]
63
63
  },
64
- "gitHead": "f68c8476c2f04bb9d53acd4059b59caf271df015"
64
+ "gitHead": "75d5780fb53c5e2c886537b283503fc6fb088a4a"
65
65
  }
@@ -1,6 +1,6 @@
1
- import { SDJWTException } from '@sd-jwt/utils';
2
1
  import { splitSdJwt } from '@sd-jwt/decode';
3
2
  import { SD_SEPARATOR } from '@sd-jwt/types';
3
+ import { SDJWTException } from '@sd-jwt/utils';
4
4
 
5
5
  export type FlattenJSONData = {
6
6
  jwtData: {
@@ -1,6 +1,6 @@
1
- import { base64urlEncode, SDJWTException } from '@sd-jwt/utils';
2
1
  import { splitSdJwt } from '@sd-jwt/decode';
3
2
  import { SD_SEPARATOR, type Signer } from '@sd-jwt/types';
3
+ import { base64urlEncode, SDJWTException } from '@sd-jwt/utils';
4
4
 
5
5
  export type GeneralJSONData = {
6
6
  payload: string;