@sd-jwt/sd-jwt-vc 0.12.1-next.0 → 0.12.1-next.2
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 +1 -1
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +10 -7
- package/dist/index.mjs +10 -7
- package/package.json +7 -7
- package/src/sd-jwt-vc-instance.ts +14 -8
- package/src/test/index.spec.ts +2 -2
- package/src/test/vct.spec.ts +1 -1
- package/test/app-e2e.spec.ts +1 -1
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 =
|
|
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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SDJWTConfig, kbPayload, kbHeader, DisclosureFrame } from '@sd-jwt/types';
|
|
2
|
-
import { SdJwtPayload, SDJwtInstance } from '@sd-jwt/core';
|
|
2
|
+
import { SdJwtPayload, SDJwtInstance, VerifierOptions } from '@sd-jwt/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Logo metadata used in rendering a credential.
|
|
@@ -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, options?: VerifierOptions): 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 options
|
|
259
261
|
*/
|
|
260
262
|
private verifyStatus;
|
|
261
263
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SDJWTConfig, kbPayload, kbHeader, DisclosureFrame } from '@sd-jwt/types';
|
|
2
|
-
import { SdJwtPayload, SDJwtInstance } from '@sd-jwt/core';
|
|
2
|
+
import { SdJwtPayload, SDJwtInstance, VerifierOptions } from '@sd-jwt/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Logo metadata used in rendering a credential.
|
|
@@ -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, options?: VerifierOptions): 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 options
|
|
259
261
|
*/
|
|
260
262
|
private verifyStatus;
|
|
261
263
|
}
|
package/dist/index.js
CHANGED
|
@@ -129,8 +129,9 @@ 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
|
+
verify(encodedSDJwt, requiredClaimKeys, requireKeyBindings, options) {
|
|
134
135
|
return __async(this, null, function* () {
|
|
135
136
|
const result = yield __superGet(_SDJwtVcInstance.prototype, this, "verify").call(this, encodedSDJwt, requiredClaimKeys, requireKeyBindings).then((res) => {
|
|
136
137
|
return {
|
|
@@ -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, options);
|
|
143
144
|
if (this.userConfig.loadTypeMetadataFormat) {
|
|
144
145
|
yield this.verifyVct(result);
|
|
145
146
|
}
|
|
@@ -291,10 +292,11 @@ 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 options
|
|
294
296
|
*/
|
|
295
|
-
verifyStatus(result) {
|
|
297
|
+
verifyStatus(result, options) {
|
|
296
298
|
return __async(this, null, function* () {
|
|
297
|
-
var _a, _b, _c;
|
|
299
|
+
var _a, _b, _c, _d;
|
|
298
300
|
if (result.payload.status) {
|
|
299
301
|
if (result.payload.status.status_list) {
|
|
300
302
|
const fetcher = (_a = this.userConfig.statusListFetcher) != null ? _a : this.statusListFetcher.bind(this);
|
|
@@ -302,15 +304,16 @@ 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
|
-
|
|
307
|
+
yield slJWT.verify(this.userConfig.verifier, options);
|
|
308
|
+
const currentDate = (_b = options == null ? void 0 : options.currentDate) != null ? _b : Math.floor(Date.now() / 1e3);
|
|
309
|
+
if (((_c = slJWT.payload) == null ? void 0 : _c.exp) && slJWT.payload.exp < currentDate) {
|
|
307
310
|
throw new import_utils.SDJWTException("Status list is expired");
|
|
308
311
|
}
|
|
309
312
|
const statusList = (0, import_jwt_status_list.getListFromStatusListJWT)(statusListJWT);
|
|
310
313
|
const status = statusList.getStatus(
|
|
311
314
|
result.payload.status.status_list.idx
|
|
312
315
|
);
|
|
313
|
-
const statusValidator = (
|
|
316
|
+
const statusValidator = (_d = this.userConfig.statusValidator) != null ? _d : this.statusValidator.bind(this);
|
|
314
317
|
yield statusValidator(status);
|
|
315
318
|
}
|
|
316
319
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -97,8 +97,9 @@ 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
|
+
verify(encodedSDJwt, requiredClaimKeys, requireKeyBindings, options) {
|
|
102
103
|
return __async(this, null, function* () {
|
|
103
104
|
const result = yield __superGet(_SDJwtVcInstance.prototype, this, "verify").call(this, encodedSDJwt, requiredClaimKeys, requireKeyBindings).then((res) => {
|
|
104
105
|
return {
|
|
@@ -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, options);
|
|
111
112
|
if (this.userConfig.loadTypeMetadataFormat) {
|
|
112
113
|
yield this.verifyVct(result);
|
|
113
114
|
}
|
|
@@ -259,10 +260,11 @@ var SDJwtVcInstance = class _SDJwtVcInstance extends SDJwtInstance {
|
|
|
259
260
|
/**
|
|
260
261
|
* Verifies the status of the SD-JWT-VC.
|
|
261
262
|
* @param result
|
|
263
|
+
* @param options
|
|
262
264
|
*/
|
|
263
|
-
verifyStatus(result) {
|
|
265
|
+
verifyStatus(result, options) {
|
|
264
266
|
return __async(this, null, function* () {
|
|
265
|
-
var _a, _b, _c;
|
|
267
|
+
var _a, _b, _c, _d;
|
|
266
268
|
if (result.payload.status) {
|
|
267
269
|
if (result.payload.status.status_list) {
|
|
268
270
|
const fetcher = (_a = this.userConfig.statusListFetcher) != null ? _a : this.statusListFetcher.bind(this);
|
|
@@ -270,15 +272,16 @@ 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
|
-
|
|
275
|
+
yield slJWT.verify(this.userConfig.verifier, options);
|
|
276
|
+
const currentDate = (_b = options == null ? void 0 : options.currentDate) != null ? _b : Math.floor(Date.now() / 1e3);
|
|
277
|
+
if (((_c = slJWT.payload) == null ? void 0 : _c.exp) && slJWT.payload.exp < currentDate) {
|
|
275
278
|
throw new SDJWTException("Status list is expired");
|
|
276
279
|
}
|
|
277
280
|
const statusList = getListFromStatusListJWT(statusListJWT);
|
|
278
281
|
const status = statusList.getStatus(
|
|
279
282
|
result.payload.status.status_list.idx
|
|
280
283
|
);
|
|
281
|
-
const statusValidator = (
|
|
284
|
+
const statusValidator = (_d = this.userConfig.statusValidator) != null ? _d : this.statusValidator.bind(this);
|
|
282
285
|
yield statusValidator(status);
|
|
283
286
|
}
|
|
284
287
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sd-jwt/sd-jwt-vc",
|
|
3
|
-
"version": "0.12.1-next.
|
|
3
|
+
"version": "0.12.1-next.2+1eefb26",
|
|
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.1-next.
|
|
43
|
-
"@sd-jwt/jwt-status-list": "0.12.1-next.
|
|
44
|
-
"@sd-jwt/utils": "0.12.1-next.
|
|
42
|
+
"@sd-jwt/core": "0.12.1-next.2+1eefb26",
|
|
43
|
+
"@sd-jwt/jwt-status-list": "0.12.1-next.2+1eefb26",
|
|
44
|
+
"@sd-jwt/utils": "0.12.1-next.2+1eefb26",
|
|
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.1-next.
|
|
50
|
-
"@sd-jwt/types": "0.12.1-next.
|
|
49
|
+
"@sd-jwt/crypto-nodejs": "0.12.1-next.2+1eefb26",
|
|
50
|
+
"@sd-jwt/types": "0.12.1-next.2+1eefb26",
|
|
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": "
|
|
70
|
+
"gitHead": "1eefb262c40ea23e999cdef6e75222e5b4df1e2c"
|
|
71
71
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Jwt, SDJwt, SDJwtInstance } from '@sd-jwt/core';
|
|
1
|
+
import { Jwt, SDJwt, SDJwtInstance, type VerifierOptions } from '@sd-jwt/core';
|
|
2
2
|
import type { DisclosureFrame, Hasher, Verifier } from '@sd-jwt/types';
|
|
3
3
|
import { SDJWTException } from '@sd-jwt/utils';
|
|
4
4
|
import type { SdJwtVcPayload } from './sd-jwt-vc-payload';
|
|
@@ -106,11 +106,14 @@ 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,
|
|
113
|
+
//TODO: we need to move these values in options, causing a breaking change
|
|
112
114
|
requiredClaimKeys?: string[],
|
|
113
115
|
requireKeyBindings?: boolean,
|
|
116
|
+
options?: VerifierOptions,
|
|
114
117
|
) {
|
|
115
118
|
// Call the parent class's verify method
|
|
116
119
|
const result: VerificationResult = await super
|
|
@@ -123,7 +126,7 @@ export class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
|
|
|
123
126
|
};
|
|
124
127
|
});
|
|
125
128
|
|
|
126
|
-
await this.verifyStatus(result);
|
|
129
|
+
await this.verifyStatus(result, options);
|
|
127
130
|
if (this.userConfig.loadTypeMetadataFormat) {
|
|
128
131
|
await this.verifyVct(result);
|
|
129
132
|
}
|
|
@@ -300,8 +303,12 @@ export class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
|
|
|
300
303
|
/**
|
|
301
304
|
* Verifies the status of the SD-JWT-VC.
|
|
302
305
|
* @param result
|
|
306
|
+
* @param options
|
|
303
307
|
*/
|
|
304
|
-
private async verifyStatus(
|
|
308
|
+
private async verifyStatus(
|
|
309
|
+
result: VerificationResult,
|
|
310
|
+
options?: VerifierOptions,
|
|
311
|
+
): Promise<void> {
|
|
305
312
|
if (result.payload.status) {
|
|
306
313
|
//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
314
|
if (result.payload.status.status_list) {
|
|
@@ -319,13 +326,12 @@ export class SDJwtVcInstance extends SDJwtInstance<SdJwtVcPayload> {
|
|
|
319
326
|
StatusListJWTPayload
|
|
320
327
|
>(statusListJWT);
|
|
321
328
|
// 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);
|
|
329
|
+
await slJWT.verify(this.userConfig.verifier as Verifier, options);
|
|
323
330
|
|
|
331
|
+
const currentDate =
|
|
332
|
+
options?.currentDate ?? Math.floor(Date.now() / 1000);
|
|
324
333
|
//check if the status list is expired
|
|
325
|
-
if (
|
|
326
|
-
slJWT.payload?.exp &&
|
|
327
|
-
(slJWT.payload.exp as number) < Date.now() / 1000
|
|
328
|
-
) {
|
|
334
|
+
if (slJWT.payload?.exp && (slJWT.payload.exp as number) < currentDate) {
|
|
329
335
|
throw new SDJWTException('Status list is expired');
|
|
330
336
|
}
|
|
331
337
|
|
package/src/test/index.spec.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { SignJWT } from 'jose';
|
|
|
18
18
|
|
|
19
19
|
const iss = 'ExampleIssuer';
|
|
20
20
|
const vct = 'ExampleCredentialType';
|
|
21
|
-
const iat =
|
|
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:
|
|
48
|
+
iat: Math.floor(Date.now() / 1000),
|
|
49
49
|
};
|
|
50
50
|
const header: StatusListJWTHeaderParameters = {
|
|
51
51
|
alg: 'EdDSA',
|
package/src/test/vct.spec.ts
CHANGED
|
@@ -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 =
|
|
73
|
+
const iat = Math.floor(Date.now() / 1000); // current time in seconds
|
|
74
74
|
|
|
75
75
|
const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
|
|
76
76
|
|
package/test/app-e2e.spec.ts
CHANGED
|
@@ -30,7 +30,7 @@ const createSignerVerifier = () => {
|
|
|
30
30
|
|
|
31
31
|
const iss = 'ExampleIssuer';
|
|
32
32
|
const vct = 'ExampleCredentials';
|
|
33
|
-
const iat =
|
|
33
|
+
const iat = Math.floor(Date.now() / 1000); // current time in seconds
|
|
34
34
|
|
|
35
35
|
describe('App', () => {
|
|
36
36
|
test('Example', async () => {
|