Skip to content

Commit 5c21911

Browse files
committed
Adding a Not Before date to the JWT
1 parent a34ccef commit 5c21911

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/shc.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@ const URI_SCHEMA = 'shc';
88
/*
99
* I am not sure if I should build this by hand.
1010
*/
11-
export async function makeJWT(payload, monthsToExpire, issuer) {
11+
export async function makeJWT(payload, monthsToExpire, issuer, notBeforeDate) {
1212
let iss = new Date();
1313
let exp = new Date(iss);
1414
exp.setMonth(exp.getMonth()+monthsToExpire);
1515

16-
return {
16+
let jwt = {
1717
iss: issuer,
1818
iat: Math.round(iss.getTime()/1000),
1919
exp: Math.round(exp.getTime()/1000),
2020
vc: payload
2121
};
22+
23+
if (notBeforeDate)
24+
jwt['nbf'] = Math.round(notBeforeDate.getTime()/1000);
25+
26+
return jwt;
2227
}
2328

2429
export async function parseJWT(jwt) {

test/sign-verify.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,12 @@ describe('JWS Crypto w/ New Keys', function() {
276276
const result = await verify(signed, GENERATED_PUBLIC_KEY);
277277
expect(result).to.be.true;
278278
});
279+
});
280+
281+
describe('JWS Crypto w/ New Keys', function() {
282+
it('should sign and verify the package w/ Not Before Date', async function() {
283+
const signed = await sign(await makeJWT(TEST_PAYLOAD, 48, "https://pcf.pw", new Date()), GENERATED_PRIVATE_KEY);
284+
const result = await verify(signed, GENERATED_PUBLIC_KEY);
285+
expect(result).to.be.true;
286+
});
279287
});

0 commit comments

Comments
 (0)