@sd-jwt/sd-jwt-vc 0.12.0 → 0.12.1-next.1

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/README.md CHANGED
@@ -41,7 +41,7 @@ import { DisclosureFrame } from '@sd-jwt/sd-jwt-vc';
41
41
  const iss = 'University';
42
42
 
43
43
  // issuance time
44
- const iat = new Date().getTime() / 1000;
44
+ const iat = Math.floor(Date.now() / 1000); // current time in seconds
45
45
 
46
46
  //unique identifier of the schema
47
47
  const vct = 'University-Degree';
package/dist/index.d.mts CHANGED
@@ -215,8 +215,9 @@ declare class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
215
215
  private statusValidator;
216
216
  /**
217
217
  * Verifies the SD-JWT-VC. It will validate the signature, the keybindings when required, the status, and the VCT.
218
+ * @param currentDate current time in seconds
218
219
  */
219
- verify(encodedSDJwt: string, requiredClaimKeys?: string[], requireKeyBindings?: boolean): Promise<VerificationResult>;
220
+ verify(encodedSDJwt: string, requiredClaimKeys?: string[], requireKeyBindings?: boolean, currentDate?: number): Promise<VerificationResult>;
220
221
  /**
221
222
  * Gets VCT Metadata of the raw SD-JWT-VC. Returns the type metadata format. If the SD-JWT-VC is invalid or does not contain a vct claim, an error is thrown.
222
223
  * @param encodedSDJwt
@@ -256,6 +257,7 @@ declare class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
256
257
  /**
257
258
  * Verifies the status of the SD-JWT-VC.
258
259
  * @param result
260
+ * @param currentDate current time in seconds
259
261
  */
260
262
  private verifyStatus;
261
263
  }
package/dist/index.d.ts CHANGED
@@ -215,8 +215,9 @@ declare class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
215
215
  private statusValidator;
216
216
  /**
217
217
  * Verifies the SD-JWT-VC. It will validate the signature, the keybindings when required, the status, and the VCT.
218
+ * @param currentDate current time in seconds
218
219
  */
219
- verify(encodedSDJwt: string, requiredClaimKeys?: string[], requireKeyBindings?: boolean): Promise<VerificationResult>;
220
+ verify(encodedSDJwt: string, requiredClaimKeys?: string[], requireKeyBindings?: boolean, currentDate?: number): Promise<VerificationResult>;
220
221
  /**
221
222
  * Gets VCT Metadata of the raw SD-JWT-VC. Returns the type metadata format. If the SD-JWT-VC is invalid or does not contain a vct claim, an error is thrown.
222
223
  * @param encodedSDJwt
@@ -256,6 +257,7 @@ declare class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
256
257
  /**
257
258
  * Verifies the status of the SD-JWT-VC.
258
259
  * @param result
260
+ * @param currentDate current time in seconds
259
261
  */
260
262
  private verifyStatus;
261
263
  }
package/dist/index.js CHANGED
@@ -129,9 +129,10 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends import_core.SDJwtInstance {
129
129
  }
130
130
  /**
131
131
  * Verifies the SD-JWT-VC. It will validate the signature, the keybindings when required, the status, and the VCT.
132
+ * @param currentDate current time in seconds
132
133
  */
133
- verify(encodedSDJwt, requiredClaimKeys, requireKeyBindings) {
134
- return __async(this, null, function* () {
134
+ verify(_0, _1, _2) {
135
+ return __async(this, arguments, function* (encodedSDJwt, requiredClaimKeys, requireKeyBindings, currentDate = Math.floor(Date.now() / 1e3)) {
135
136
  const result = yield __superGet(_SDJwtVcInstance.prototype, this, "verify").call(this, encodedSDJwt, requiredClaimKeys, requireKeyBindings).then((res) => {
136
137
  return {
137
138
  payload: res.payload,
@@ -139,7 +140,7 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends import_core.SDJwtInstance {
139
140
  kb: res.kb
140
141
  };
141
142
  });
142
- yield this.verifyStatus(result);
143
+ yield this.verifyStatus(result, currentDate);
143
144
  if (this.userConfig.loadTypeMetadataFormat) {
144
145
  yield this.verifyVct(result);
145
146
  }
@@ -291,8 +292,9 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends import_core.SDJwtInstance {
291
292
  /**
292
293
  * Verifies the status of the SD-JWT-VC.
293
294
  * @param result
295
+ * @param currentDate current time in seconds
294
296
  */
295
- verifyStatus(result) {
297
+ verifyStatus(result, currentDate) {
296
298
  return __async(this, null, function* () {
297
299
  var _a, _b, _c;
298
300
  if (result.payload.status) {
@@ -302,8 +304,8 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends import_core.SDJwtInstance {
302
304
  result.payload.status.status_list.uri
303
305
  );
304
306
  const slJWT = import_core.Jwt.fromEncode(statusListJWT);
305
- yield slJWT.verify(this.userConfig.verifier);
306
- if (((_b = slJWT.payload) == null ? void 0 : _b.exp) && slJWT.payload.exp < Date.now() / 1e3) {
307
+ yield slJWT.verify(this.userConfig.verifier, currentDate);
308
+ if (((_b = slJWT.payload) == null ? void 0 : _b.exp) && slJWT.payload.exp < currentDate) {
307
309
  throw new import_utils.SDJWTException("Status list is expired");
308
310
  }
309
311
  const statusList = (0, import_jwt_status_list.getListFromStatusListJWT)(statusListJWT);
package/dist/index.mjs CHANGED
@@ -97,9 +97,10 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends SDJwtInstance {
97
97
  }
98
98
  /**
99
99
  * Verifies the SD-JWT-VC. It will validate the signature, the keybindings when required, the status, and the VCT.
100
+ * @param currentDate current time in seconds
100
101
  */
101
- verify(encodedSDJwt, requiredClaimKeys, requireKeyBindings) {
102
- return __async(this, null, function* () {
102
+ verify(_0, _1, _2) {
103
+ return __async(this, arguments, function* (encodedSDJwt, requiredClaimKeys, requireKeyBindings, currentDate = Math.floor(Date.now() / 1e3)) {
103
104
  const result = yield __superGet(_SDJwtVcInstance.prototype, this, "verify").call(this, encodedSDJwt, requiredClaimKeys, requireKeyBindings).then((res) => {
104
105
  return {
105
106
  payload: res.payload,
@@ -107,7 +108,7 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends SDJwtInstance {
107
108
  kb: res.kb
108
109
  };
109
110
  });
110
- yield this.verifyStatus(result);
111
+ yield this.verifyStatus(result, currentDate);
111
112
  if (this.userConfig.loadTypeMetadataFormat) {
112
113
  yield this.verifyVct(result);
113
114
  }
@@ -259,8 +260,9 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends SDJwtInstance {
259
260
  /**
260
261
  * Verifies the status of the SD-JWT-VC.
261
262
  * @param result
263
+ * @param currentDate current time in seconds
262
264
  */
263
- verifyStatus(result) {
265
+ verifyStatus(result, currentDate) {
264
266
  return __async(this, null, function* () {
265
267
  var _a, _b, _c;
266
268
  if (result.payload.status) {
@@ -270,8 +272,8 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends SDJwtInstance {
270
272
  result.payload.status.status_list.uri
271
273
  );
272
274
  const slJWT = Jwt.fromEncode(statusListJWT);
273
- yield slJWT.verify(this.userConfig.verifier);
274
- if (((_b = slJWT.payload) == null ? void 0 : _b.exp) && slJWT.payload.exp < Date.now() / 1e3) {
275
+ yield slJWT.verify(this.userConfig.verifier, currentDate);
276
+ if (((_b = slJWT.payload) == null ? void 0 : _b.exp) && slJWT.payload.exp < currentDate) {
275
277
  throw new SDJWTException("Status list is expired");
276
278
  }
277
279
  const statusList = getListFromStatusListJWT(statusListJWT);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sd-jwt/sd-jwt-vc",
3
- "version": "0.12.0",
3
+ "version": "0.12.1-next.1+0a2f20b",
4
4
  "description": "sd-jwt draft 7 implementation in typescript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -39,15 +39,15 @@
39
39
  },
40
40
  "license": "Apache-2.0",
41
41
  "dependencies": {
42
- "@sd-jwt/core": "0.12.0",
43
- "@sd-jwt/jwt-status-list": "0.12.0",
44
- "@sd-jwt/utils": "0.12.0",
42
+ "@sd-jwt/core": "0.12.1-next.1+0a2f20b",
43
+ "@sd-jwt/jwt-status-list": "0.12.1-next.1+0a2f20b",
44
+ "@sd-jwt/utils": "0.12.1-next.1+0a2f20b",
45
45
  "ajv": "^8.17.1",
46
46
  "ajv-formats": "^3.0.1"
47
47
  },
48
48
  "devDependencies": {
49
- "@sd-jwt/crypto-nodejs": "0.12.0",
50
- "@sd-jwt/types": "0.12.0",
49
+ "@sd-jwt/crypto-nodejs": "0.12.1-next.1+0a2f20b",
50
+ "@sd-jwt/types": "0.12.1-next.1+0a2f20b",
51
51
  "jose": "^5.2.2",
52
52
  "msw": "^2.3.5"
53
53
  },
@@ -67,5 +67,5 @@
67
67
  "esm"
68
68
  ]
69
69
  },
70
- "gitHead": "36e0b22eb619f3ca9ae8522a26617e50c3680526"
70
+ "gitHead": "0a2f20b6383d2356540e7a9cc37748c7b9caced2"
71
71
  }
@@ -106,11 +106,13 @@ export class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
106
106
 
107
107
  /**
108
108
  * Verifies the SD-JWT-VC. It will validate the signature, the keybindings when required, the status, and the VCT.
109
+ * @param currentDate current time in seconds
109
110
  */
110
111
  async verify(
111
112
  encodedSDJwt: string,
112
113
  requiredClaimKeys?: string[],
113
114
  requireKeyBindings?: boolean,
115
+ currentDate: number = Math.floor(Date.now() / 1000),
114
116
  ) {
115
117
  // Call the parent class's verify method
116
118
  const result: VerificationResult = await super
@@ -123,7 +125,7 @@ export class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
123
125
  };
124
126
  });
125
127
 
126
- await this.verifyStatus(result);
128
+ await this.verifyStatus(result, currentDate);
127
129
  if (this.userConfig.loadTypeMetadataFormat) {
128
130
  await this.verifyVct(result);
129
131
  }
@@ -300,8 +302,12 @@ export class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
300
302
  /**
301
303
  * Verifies the status of the SD-JWT-VC.
302
304
  * @param result
305
+ * @param currentDate current time in seconds
303
306
  */
304
- private async verifyStatus(result: VerificationResult): Promise<void> {
307
+ private async verifyStatus(
308
+ result: VerificationResult,
309
+ currentDate: number,
310
+ ): Promise<void> {
305
311
  if (result.payload.status) {
306
312
  //checks if a status field is present in the payload based on https://www.ietf.org/archive/id/draft-ietf-oauth-status-list-02.html
307
313
  if (result.payload.status.status_list) {
@@ -319,13 +325,10 @@ export class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
319
325
  StatusListJWTPayload
320
326
  >(statusListJWT);
321
327
  // check if the status list has a valid signature. The presence of the verifier is checked in the parent class.
322
- await slJWT.verify(this.userConfig.verifier as Verifier);
328
+ await slJWT.verify(this.userConfig.verifier as Verifier, currentDate);
323
329
 
324
330
  //check if the status list is expired
325
- if (
326
- slJWT.payload?.exp &&
327
- (slJWT.payload.exp as number) < Date.now() / 1000
328
- ) {
331
+ if (slJWT.payload?.exp && (slJWT.payload.exp as number) < currentDate) {
329
332
  throw new SDJWTException('Status list is expired');
330
333
  }
331
334
 
@@ -18,7 +18,7 @@ import { SignJWT } from 'jose';
18
18
 
19
19
  const iss = 'ExampleIssuer';
20
20
  const vct = 'ExampleCredentialType';
21
- const iat = new Date().getTime() / 1000;
21
+ const iat = Math.floor(Date.now() / 1000);
22
22
 
23
23
  const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
24
24
 
@@ -45,7 +45,7 @@ const generateStatusList = async (): Promise<string> => {
45
45
  const payload: JwtPayload = {
46
46
  iss: 'https://example.com',
47
47
  sub: 'https://example.com/status/1',
48
- iat: new Date().getTime() / 1000,
48
+ iat: Math.floor(Date.now() / 1000),
49
49
  };
50
50
  const header: StatusListJWTHeaderParameters = {
51
51
  alg: 'EdDSA',
@@ -70,7 +70,7 @@ const server = setupServer(...restHandlers);
70
70
 
71
71
  const iss = 'ExampleIssuer';
72
72
  const vct = 'http://example.com/example';
73
- const iat = new Date().getTime() / 1000;
73
+ const iat = Math.floor(Date.now() / 1000); // current time in seconds
74
74
 
75
75
  const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
76
76
 
@@ -30,7 +30,7 @@ const createSignerVerifier = () => {
30
30
 
31
31
  const iss = 'ExampleIssuer';
32
32
  const vct = 'ExampleCredentials';
33
- const iat = new Date().getTime() / 1000;
33
+ const iat = Math.floor(Date.now() / 1000); // current time in seconds
34
34
 
35
35
  describe('App', () => {
36
36
  test('Example', async () => {