@sd-jwt/core 0.3.2-next.107 → 0.3.2-next.109

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.js CHANGED
@@ -140,19 +140,20 @@ var Jwt = class _Jwt {
140
140
 
141
141
  // src/kbjwt.ts
142
142
  var import_utils2 = require("@sd-jwt/utils");
143
+ var import_types = require("@sd-jwt/types");
143
144
  var KBJwt = class _KBJwt extends Jwt {
144
145
  // Checking the validity of the key binding jwt
145
146
  // 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
146
147
  verifyKB(values) {
147
148
  return __async(this, null, function* () {
148
- var _a, _b, _c, _d, _e, _f;
149
- if (!((_a = this.header) == null ? void 0 : _a.alg) || !this.header.typ || !((_b = this.payload) == null ? void 0 : _b.iat) || !((_c = this.payload) == null ? void 0 : _c.aud) || !((_d = this.payload) == null ? void 0 : _d.nonce) || // this is for backward compatibility with version 06
150
- !(((_e = this.payload) == null ? void 0 : _e.sd_hash) || ((_f = this.payload) == null ? void 0 : _f._sd_hash))) {
151
- throw new import_utils2.SDJWTException("Invalid Key Binding Jwt");
152
- }
149
+ var _a;
153
150
  if (!this.header || !this.payload || !this.signature) {
154
151
  throw new import_utils2.SDJWTException("Verify Error: Invalid JWT");
155
152
  }
153
+ if (!this.header.alg || this.header.alg === "none" || !this.header.typ || this.header.typ !== import_types.KB_JWT_TYP || !this.payload.iat || !this.payload.aud || !this.payload.nonce || // this is for backward compatibility with version 06
154
+ !(this.payload.sd_hash || ((_a = this.payload) == null ? void 0 : _a._sd_hash))) {
155
+ throw new import_utils2.SDJWTException("Invalid Key Binding Jwt");
156
+ }
156
157
  const header = (0, import_utils2.Base64urlEncode)(JSON.stringify(this.header));
157
158
  const payload = (0, import_utils2.Base64urlEncode)(JSON.stringify(this.payload));
158
159
  const data = `${header}.${payload}`;
@@ -192,7 +193,7 @@ var createDecoy = (hash, saltGenerator) => __async(void 0, null, function* () {
192
193
 
193
194
  // src/sdjwt.ts
194
195
  var import_utils4 = require("@sd-jwt/utils");
195
- var import_types = require("@sd-jwt/types");
196
+ var import_types2 = require("@sd-jwt/types");
196
197
  var import_decode2 = require("@sd-jwt/decode");
197
198
  var SDJwt = class _SDJwt {
198
199
  constructor(data) {
@@ -202,7 +203,7 @@ var SDJwt = class _SDJwt {
202
203
  }
203
204
  static decodeSDJwt(sdjwt, hasher) {
204
205
  return __async(this, null, function* () {
205
- const [encodedJwt, ...encodedDisclosures] = sdjwt.split(import_types.SD_SEPARATOR);
206
+ const [encodedJwt, ...encodedDisclosures] = sdjwt.split(import_types2.SD_SEPARATOR);
206
207
  const jwt = Jwt.fromEncode(encodedJwt);
207
208
  if (!jwt.payload) {
208
209
  throw new Error("Payload is undefined on the JWT. Invalid state reached");
@@ -276,11 +277,11 @@ var SDJwt = class _SDJwt {
276
277
  const encodedJwt = this.jwt.encodeJwt();
277
278
  data.push(encodedJwt);
278
279
  if (this.disclosures && this.disclosures.length > 0) {
279
- const encodeddisclosures = this.disclosures.map((dc) => dc.encode()).join(import_types.SD_SEPARATOR);
280
+ const encodeddisclosures = this.disclosures.map((dc) => dc.encode()).join(import_types2.SD_SEPARATOR);
280
281
  data.push(encodeddisclosures);
281
282
  }
282
283
  data.push(this.kbJwt ? this.kbJwt.encodeJwt() : "");
283
- return data.join(import_types.SD_SEPARATOR);
284
+ return data.join(import_types2.SD_SEPARATOR);
284
285
  }
285
286
  keys(hasher) {
286
287
  return __async(this, null, function* () {
@@ -337,14 +338,14 @@ var pack = (claims, disclosureFrame, hash, saltGenerator) => __async(void 0, nul
337
338
  disclosures: []
338
339
  };
339
340
  }
340
- const sd = (_a = disclosureFrame[import_types.SD_DIGEST]) != null ? _a : [];
341
- const decoyCount = (_b = disclosureFrame[import_types.SD_DECOY]) != null ? _b : 0;
341
+ const sd = (_a = disclosureFrame[import_types2.SD_DIGEST]) != null ? _a : [];
342
+ const decoyCount = (_b = disclosureFrame[import_types2.SD_DECOY]) != null ? _b : 0;
342
343
  if (Array.isArray(claims)) {
343
344
  const packedClaims2 = [];
344
345
  const disclosures2 = [];
345
346
  const recursivePackedClaims2 = {};
346
347
  for (const key in disclosureFrame) {
347
- if (key !== import_types.SD_DIGEST) {
348
+ if (key !== import_types2.SD_DIGEST) {
348
349
  const idx = parseInt(key);
349
350
  const packed = yield pack(
350
351
  claims[idx],
@@ -362,7 +363,7 @@ var pack = (claims, disclosureFrame, hash, saltGenerator) => __async(void 0, nul
362
363
  const salt = yield saltGenerator(16);
363
364
  const disclosure = new import_utils4.Disclosure([salt, claim]);
364
365
  const digest = yield disclosure.digest(hash);
365
- packedClaims2.push({ [import_types.SD_LIST_KEY]: digest });
366
+ packedClaims2.push({ [import_types2.SD_LIST_KEY]: digest });
366
367
  disclosures2.push(disclosure);
367
368
  } else {
368
369
  packedClaims2.push(claim);
@@ -370,7 +371,7 @@ var pack = (claims, disclosureFrame, hash, saltGenerator) => __async(void 0, nul
370
371
  }
371
372
  for (let j = 0; j < decoyCount; j++) {
372
373
  const decoyDigest = yield createDecoy(hash, saltGenerator);
373
- packedClaims2.push({ [import_types.SD_LIST_KEY]: decoyDigest });
374
+ packedClaims2.push({ [import_types2.SD_LIST_KEY]: decoyDigest });
374
375
  }
375
376
  return { packedClaims: packedClaims2, disclosures: disclosures2 };
376
377
  }
@@ -378,7 +379,7 @@ var pack = (claims, disclosureFrame, hash, saltGenerator) => __async(void 0, nul
378
379
  const disclosures = [];
379
380
  const recursivePackedClaims = {};
380
381
  for (const key in disclosureFrame) {
381
- if (key !== import_types.SD_DIGEST) {
382
+ if (key !== import_types2.SD_DIGEST) {
382
383
  const packed = yield pack(
383
384
  // @ts-ignore
384
385
  claims[key],
@@ -408,13 +409,13 @@ var pack = (claims, disclosureFrame, hash, saltGenerator) => __async(void 0, nul
408
409
  _sd.push(decoyDigest);
409
410
  }
410
411
  if (_sd.length > 0) {
411
- packedClaims[import_types.SD_DIGEST] = _sd.sort();
412
+ packedClaims[import_types2.SD_DIGEST] = _sd.sort();
412
413
  }
413
414
  return { packedClaims, disclosures };
414
415
  });
415
416
 
416
417
  // src/index.ts
417
- var import_types2 = require("@sd-jwt/types");
418
+ var import_types3 = require("@sd-jwt/types");
418
419
  var import_decode3 = require("@sd-jwt/decode");
419
420
  var _SDJwtInstance = class _SDJwtInstance {
420
421
  constructor(userConfig) {
@@ -434,7 +435,7 @@ var _SDJwtInstance = class _SDJwtInstance {
434
435
  const { payload } = options;
435
436
  const kbJwt = new KBJwt({
436
437
  header: {
437
- typ: import_types2.KB_JWT_TYP,
438
+ typ: import_types3.KB_JWT_TYP,
438
439
  alg: this.userConfig.kbSignAlg
439
440
  },
440
441
  payload: __spreadProps(__spreadValues({}, payload), { sd_hash: sdHash })
package/dist/index.mjs CHANGED
@@ -113,19 +113,22 @@ var Jwt = class _Jwt {
113
113
 
114
114
  // src/kbjwt.ts
115
115
  import { Base64urlEncode as Base64urlEncode2, SDJWTException as SDJWTException2 } from "@sd-jwt/utils";
116
+ import {
117
+ KB_JWT_TYP
118
+ } from "@sd-jwt/types";
116
119
  var KBJwt = class _KBJwt extends Jwt {
117
120
  // Checking the validity of the key binding jwt
118
121
  // 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
119
122
  verifyKB(values) {
120
123
  return __async(this, null, function* () {
121
- var _a, _b, _c, _d, _e, _f;
122
- if (!((_a = this.header) == null ? void 0 : _a.alg) || !this.header.typ || !((_b = this.payload) == null ? void 0 : _b.iat) || !((_c = this.payload) == null ? void 0 : _c.aud) || !((_d = this.payload) == null ? void 0 : _d.nonce) || // this is for backward compatibility with version 06
123
- !(((_e = this.payload) == null ? void 0 : _e.sd_hash) || ((_f = this.payload) == null ? void 0 : _f._sd_hash))) {
124
- throw new SDJWTException2("Invalid Key Binding Jwt");
125
- }
124
+ var _a;
126
125
  if (!this.header || !this.payload || !this.signature) {
127
126
  throw new SDJWTException2("Verify Error: Invalid JWT");
128
127
  }
128
+ 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
129
+ !(this.payload.sd_hash || ((_a = this.payload) == null ? void 0 : _a._sd_hash))) {
130
+ throw new SDJWTException2("Invalid Key Binding Jwt");
131
+ }
129
132
  const header = Base64urlEncode2(JSON.stringify(this.header));
130
133
  const payload = Base64urlEncode2(JSON.stringify(this.payload));
131
134
  const data = `${header}.${payload}`;
@@ -393,7 +396,7 @@ var pack = (claims, disclosureFrame, hash, saltGenerator) => __async(void 0, nul
393
396
 
394
397
  // src/index.ts
395
398
  import {
396
- KB_JWT_TYP as KB_JWT_TYP2
399
+ KB_JWT_TYP as KB_JWT_TYP3
397
400
  } from "@sd-jwt/types";
398
401
  import { getSDAlgAndPayload as getSDAlgAndPayload2 } from "@sd-jwt/decode";
399
402
  var _SDJwtInstance = class _SDJwtInstance {
@@ -414,7 +417,7 @@ var _SDJwtInstance = class _SDJwtInstance {
414
417
  const { payload } = options;
415
418
  const kbJwt = new KBJwt({
416
419
  header: {
417
- typ: KB_JWT_TYP2,
420
+ typ: KB_JWT_TYP3,
418
421
  alg: this.userConfig.kbSignAlg
419
422
  },
420
423
  payload: __spreadProps(__spreadValues({}, payload), { sd_hash: sdHash })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sd-jwt/core",
3
- "version": "0.3.2-next.107+7b8a217",
3
+ "version": "0.3.2-next.109+f02d6b0",
4
4
  "description": "sd-jwt draft 7 implementation in typescript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -38,12 +38,12 @@
38
38
  },
39
39
  "license": "Apache-2.0",
40
40
  "devDependencies": {
41
- "@sd-jwt/crypto-nodejs": "0.3.2-next.107+7b8a217"
41
+ "@sd-jwt/crypto-nodejs": "0.3.2-next.109+f02d6b0"
42
42
  },
43
43
  "dependencies": {
44
- "@sd-jwt/decode": "0.3.2-next.107+7b8a217",
45
- "@sd-jwt/types": "0.3.2-next.107+7b8a217",
46
- "@sd-jwt/utils": "0.3.2-next.107+7b8a217"
44
+ "@sd-jwt/decode": "0.3.2-next.109+f02d6b0",
45
+ "@sd-jwt/types": "0.3.2-next.109+f02d6b0",
46
+ "@sd-jwt/utils": "0.3.2-next.109+f02d6b0"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"
@@ -61,5 +61,5 @@
61
61
  "esm"
62
62
  ]
63
63
  },
64
- "gitHead": "7b8a217fbe9eb3c14b0893e247f47a6f224e83ec"
64
+ "gitHead": "f02d6b093dd8105560ba327c23c0f383e92d31c7"
65
65
  }
package/src/kbjwt.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import { Base64urlEncode, SDJWTException } from '@sd-jwt/utils';
2
2
  import { Jwt } from './jwt';
3
- import { JwtPayload, kbHeader, kbPayload, KbVerifier } from '@sd-jwt/types';
3
+ import {
4
+ JwtPayload,
5
+ KB_JWT_TYP,
6
+ kbHeader,
7
+ kbPayload,
8
+ KbVerifier,
9
+ } from '@sd-jwt/types';
4
10
 
5
11
  export class KBJwt<
6
12
  Header extends kbHeader = kbHeader,
@@ -9,23 +15,26 @@ export class KBJwt<
9
15
  // Checking the validity of the key binding jwt
10
16
  // 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
11
17
  public async verifyKB(values: { verifier: KbVerifier; payload: JwtPayload }) {
18
+ if (!this.header || !this.payload || !this.signature) {
19
+ throw new SDJWTException('Verify Error: Invalid JWT');
20
+ }
21
+
12
22
  if (
13
- !this.header?.alg ||
23
+ !this.header.alg ||
24
+ this.header.alg === 'none' ||
14
25
  !this.header.typ ||
15
- !this.payload?.iat ||
16
- !this.payload?.aud ||
17
- !this.payload?.nonce ||
26
+ this.header.typ !== KB_JWT_TYP ||
27
+ !this.payload.iat ||
28
+ !this.payload.aud ||
29
+ !this.payload.nonce ||
18
30
  // this is for backward compatibility with version 06
19
31
  !(
20
- this.payload?.sd_hash ||
32
+ this.payload.sd_hash ||
21
33
  (this.payload as Record<string, unknown> | undefined)?._sd_hash
22
34
  )
23
35
  ) {
24
36
  throw new SDJWTException('Invalid Key Binding Jwt');
25
37
  }
26
- if (!this.header || !this.payload || !this.signature) {
27
- throw new SDJWTException('Verify Error: Invalid JWT');
28
- }
29
38
 
30
39
  const header = Base64urlEncode(JSON.stringify(this.header));
31
40
  const payload = Base64urlEncode(JSON.stringify(this.payload));