@sd-jwt/core 0.3.2-next.101 → 0.3.2-next.103

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
@@ -129,7 +129,7 @@ var Jwt = class _Jwt {
129
129
  const header = (0, import_utils.Base64urlEncode)(JSON.stringify(this.header));
130
130
  const payload = (0, import_utils.Base64urlEncode)(JSON.stringify(this.payload));
131
131
  const data = `${header}.${payload}`;
132
- const verified = verifier(data, this.signature);
132
+ const verified = yield verifier(data, this.signature);
133
133
  if (!verified) {
134
134
  throw new import_utils.SDJWTException("Verify Error: Invalid JWT Signature");
135
135
  }
@@ -511,18 +511,17 @@ var _SDJwtInstance = class _SDJwtInstance {
511
511
  }
512
512
  present(encodedSDJwt, presentationKeys, options) {
513
513
  return __async(this, null, function* () {
514
- var _a;
515
- if (!presentationKeys)
516
- return encodedSDJwt;
514
+ var _a, _b;
517
515
  if (!this.userConfig.hasher) {
518
516
  throw new import_utils5.SDJWTException("Hasher not found");
519
517
  }
520
518
  const hasher = this.userConfig.hasher;
521
519
  const sdjwt = yield SDJwt.fromEncode(encodedSDJwt, hasher);
522
- if (!((_a = sdjwt.jwt) == null ? void 0 : _a.payload))
520
+ const sortedpresentationKeys = (_a = presentationKeys == null ? void 0 : presentationKeys.sort()) != null ? _a : yield sdjwt.presentableKeys(hasher);
521
+ if (!((_b = sdjwt.jwt) == null ? void 0 : _b.payload))
523
522
  throw new import_utils5.SDJWTException("Payload not found");
524
523
  const presentSdJwtWithoutKb = yield sdjwt.present(
525
- presentationKeys.sort(),
524
+ sortedpresentationKeys,
526
525
  hasher
527
526
  );
528
527
  if (!(options == null ? void 0 : options.kb)) {
@@ -534,7 +533,7 @@ var _SDJwtInstance = class _SDJwtInstance {
534
533
  hasher
535
534
  );
536
535
  sdjwt.kbJwt = yield this.createKBJwt(options.kb, sdHashStr);
537
- return sdjwt.present(presentationKeys.sort(), hasher);
536
+ return sdjwt.present(sortedpresentationKeys, hasher);
538
537
  });
539
538
  }
540
539
  // This function is for verifying the SD JWT
package/dist/index.mjs CHANGED
@@ -102,7 +102,7 @@ var Jwt = class _Jwt {
102
102
  const header = Base64urlEncode(JSON.stringify(this.header));
103
103
  const payload = Base64urlEncode(JSON.stringify(this.payload));
104
104
  const data = `${header}.${payload}`;
105
- const verified = verifier(data, this.signature);
105
+ const verified = yield verifier(data, this.signature);
106
106
  if (!verified) {
107
107
  throw new SDJWTException("Verify Error: Invalid JWT Signature");
108
108
  }
@@ -491,18 +491,17 @@ var _SDJwtInstance = class _SDJwtInstance {
491
491
  }
492
492
  present(encodedSDJwt, presentationKeys, options) {
493
493
  return __async(this, null, function* () {
494
- var _a;
495
- if (!presentationKeys)
496
- return encodedSDJwt;
494
+ var _a, _b;
497
495
  if (!this.userConfig.hasher) {
498
496
  throw new SDJWTException4("Hasher not found");
499
497
  }
500
498
  const hasher = this.userConfig.hasher;
501
499
  const sdjwt = yield SDJwt.fromEncode(encodedSDJwt, hasher);
502
- if (!((_a = sdjwt.jwt) == null ? void 0 : _a.payload))
500
+ const sortedpresentationKeys = (_a = presentationKeys == null ? void 0 : presentationKeys.sort()) != null ? _a : yield sdjwt.presentableKeys(hasher);
501
+ if (!((_b = sdjwt.jwt) == null ? void 0 : _b.payload))
503
502
  throw new SDJWTException4("Payload not found");
504
503
  const presentSdJwtWithoutKb = yield sdjwt.present(
505
- presentationKeys.sort(),
504
+ sortedpresentationKeys,
506
505
  hasher
507
506
  );
508
507
  if (!(options == null ? void 0 : options.kb)) {
@@ -514,7 +513,7 @@ var _SDJwtInstance = class _SDJwtInstance {
514
513
  hasher
515
514
  );
516
515
  sdjwt.kbJwt = yield this.createKBJwt(options.kb, sdHashStr);
517
- return sdjwt.present(presentationKeys.sort(), hasher);
516
+ return sdjwt.present(sortedpresentationKeys, hasher);
518
517
  });
519
518
  }
520
519
  // This function is for verifying the SD JWT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sd-jwt/core",
3
- "version": "0.3.2-next.101+5906908",
3
+ "version": "0.3.2-next.103+a28ae21",
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.101+5906908"
41
+ "@sd-jwt/crypto-nodejs": "0.3.2-next.103+a28ae21"
42
42
  },
43
43
  "dependencies": {
44
- "@sd-jwt/decode": "0.3.2-next.101+5906908",
45
- "@sd-jwt/types": "0.3.2-next.101+5906908",
46
- "@sd-jwt/utils": "0.3.2-next.101+5906908"
44
+ "@sd-jwt/decode": "0.3.2-next.103+a28ae21",
45
+ "@sd-jwt/types": "0.3.2-next.103+a28ae21",
46
+ "@sd-jwt/utils": "0.3.2-next.103+a28ae21"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"
@@ -61,5 +61,5 @@
61
61
  "esm"
62
62
  ]
63
63
  },
64
- "gitHead": "5906908ea5584e2dc5b83212fdac36754ff3240a"
64
+ "gitHead": "a28ae21d24c2e20f41857f2205c24a2609c10736"
65
65
  }
package/src/index.ts CHANGED
@@ -146,7 +146,6 @@ export class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
146
146
  kb?: KBOptions;
147
147
  },
148
148
  ): Promise<SDJWTCompact> {
149
- if (!presentationKeys) return encodedSDJwt;
150
149
  if (!this.userConfig.hasher) {
151
150
  throw new SDJWTException('Hasher not found');
152
151
  }
@@ -154,9 +153,12 @@ export class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
154
153
 
155
154
  const sdjwt = await SDJwt.fromEncode(encodedSDJwt, hasher);
156
155
 
156
+ const sortedpresentationKeys =
157
+ presentationKeys?.sort() ?? (await sdjwt.presentableKeys(hasher));
158
+
157
159
  if (!sdjwt.jwt?.payload) throw new SDJWTException('Payload not found');
158
160
  const presentSdJwtWithoutKb = await sdjwt.present(
159
- presentationKeys.sort(),
161
+ sortedpresentationKeys,
160
162
  hasher,
161
163
  );
162
164
 
@@ -171,7 +173,7 @@ export class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
171
173
  );
172
174
 
173
175
  sdjwt.kbJwt = await this.createKBJwt(options.kb, sdHashStr);
174
- return sdjwt.present(presentationKeys.sort(), hasher);
176
+ return sdjwt.present(sortedpresentationKeys, hasher);
175
177
  }
176
178
 
177
179
  // This function is for verifying the SD JWT
package/src/jwt.ts CHANGED
@@ -98,7 +98,7 @@ export class Jwt<
98
98
  const payload = Base64urlEncode(JSON.stringify(this.payload));
99
99
  const data = `${header}.${payload}`;
100
100
 
101
- const verified = verifier(data, this.signature);
101
+ const verified = await verifier(data, this.signature);
102
102
  if (!verified) {
103
103
  throw new SDJWTException('Verify Error: Invalid JWT Signature');
104
104
  }
@@ -525,4 +525,42 @@ describe('index', () => {
525
525
  expect(keys).toBeDefined();
526
526
  expect(keys).toEqual(['foo']);
527
527
  });
528
+
529
+ test('present all disclosures with kb jwt', async () => {
530
+ const { signer } = createSignerVerifier();
531
+ const sdjwt = new SDJwtInstance<SdJwtPayload>({
532
+ signer,
533
+ kbSigner: signer,
534
+ hasher: digest,
535
+ saltGenerator: generateSalt,
536
+ signAlg: 'EdDSA',
537
+ kbSignAlg: 'EdDSA',
538
+ });
539
+ const credential = await sdjwt.issue(
540
+ {
541
+ foo: 'bar',
542
+ iss: 'Issuer',
543
+ iat: new Date().getTime(),
544
+ vct: '',
545
+ },
546
+ {
547
+ _sd: ['foo'],
548
+ },
549
+ );
550
+
551
+ const presentation = await sdjwt.present(credential, undefined, {
552
+ kb: {
553
+ payload: {
554
+ aud: '1',
555
+ iat: 1,
556
+ nonce: '342',
557
+ },
558
+ },
559
+ });
560
+
561
+ const decoded = await sdjwt.decode(presentation);
562
+ expect(decoded.jwt).toBeDefined();
563
+ expect(decoded.disclosures).toBeDefined();
564
+ expect(decoded.kbJwt).toBeDefined();
565
+ });
528
566
  });