Skip to content

Commit afc2a8a

Browse files
committed
fix: issuance and expiration sometimes used milliseconds instead of seconds
1 parent 1260291 commit afc2a8a

9 files changed

Lines changed: 14 additions & 14 deletions

File tree

packages/callback-example/lib/__tests__/issuerCallback.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async function proofOfPossessionCallbackFunction(args: Jwt, kid?: string): Promi
3737
}
3838
return await new jose.SignJWT({ ...args.payload })
3939
.setProtectedHeader({ ...args.header })
40-
.setIssuedAt(+new Date())
40+
.setIssuedAt(args.payload.iat ?? Math.round(+new Date()/1000))
4141
.setIssuer(kid)
4242
.setAudience(args.payload.aud)
4343
.setExpirationTime('2h')

packages/client/lib/__tests__/ProofOfPossessionBuilder.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IDENTIPROOF_ISSUER_URL } from './MetadataMocks';
99

1010
const jwt: Jwt = {
1111
header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1', typ: 'jwt' },
12-
payload: { iss: 'sphereon:wallet', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: IDENTIPROOF_ISSUER_URL, iat: Date.now() },
12+
payload: { iss: 'sphereon:wallet', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: IDENTIPROOF_ISSUER_URL, iat: Date.now()/1000 },
1313
};
1414

1515
const kid = 'did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1';

packages/client/lib/__tests__/SdJwt.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const vcIssuer = new VcIssuerBuilder()
4343
},
4444
payload: {
4545
aud: issuerMetadata.credential_issuer,
46-
iat: +new Date(),
46+
iat: +new Date()/1000,
4747
nonce: 'a-c-nonce',
4848
},
4949
},

packages/client/lib/functions/ProofUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ const createJWT = (jwtProps?: JwtProps, existingJwt?: Jwt): Jwt => {
9494
const now = +new Date();
9595
const jwtPayload: Partial<JWTPayload> = {
9696
aud,
97-
iat: jwt.payload?.iat ? jwt.payload.iat : now / 1000 - 60, // Let's ensure we subtract 60 seconds for potential time offsets
98-
exp: jwt.payload?.exp ? jwt.payload.exp : now / 1000 + 10 * 60,
97+
iat: jwt.payload?.iat ?? Math.round(now / 1000 - 60), // Let's ensure we subtract 60 seconds for potential time offsets
98+
exp: jwt.payload?.exp ?? Math.round(now / 1000 + 10 * 60),
9999
nonce,
100100
...(iss ? { iss } : {}),
101101
...(jti ? { jti } : {}),

packages/issuer-rest/lib/IssuerTokenEndpoint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import { v4 } from 'uuid'
1414
* @param interval
1515
*/
1616
export const handleTokenRequest = <T extends object>({
17-
tokenExpiresIn,
17+
tokenExpiresIn, // expiration in seconds
1818
accessTokenSignerCallback,
1919
accessTokenIssuer,
20-
cNonceExpiresIn,
20+
cNonceExpiresIn, // expiration in seconds
2121
issuer,
2222
interval,
2323
}: Required<Pick<ITokenEndpointOpts, 'accessTokenIssuer' | 'cNonceExpiresIn' | 'interval' | 'accessTokenSignerCallback' | 'tokenExpiresIn'>> & {

packages/issuer-rest/lib/__tests__/ClientIssuerIT.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ describe('VcIssuer', () => {
314314
async function proofOfPossessionCallbackFunction(args: Jwt, kid?: string): Promise<string> {
315315
return await new jose.SignJWT({ ...args.payload })
316316
.setProtectedHeader({ ...args.header })
317-
.setIssuedAt(+new Date())
317+
.setIssuedAt(args.payload.iat ?? Math.round(+new Date()/1000))
318318
.setIssuer(kid!)
319319
.setAudience(args.payload.aud!)
320320
.setExpirationTime('2h')

packages/issuer/lib/VcIssuer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ export class VcIssuer<DIDDoc extends object> {
519519
}
520520
if (!iat) {
521521
throw new Error(IAT_ERROR)
522-
} else if (iat > (createdAt/1000 + tokenExpiresIn)) {
522+
} else if (iat > Math.round(createdAt/1000) + tokenExpiresIn) {
523523
// createdAt is in milliseconds whilst iat and tokenExpiresIn are in seconds
524524
throw new Error(IAT_ERROR)
525525
}

packages/issuer/lib/__tests__/VcIssuer.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ describe('VcIssuer', () => {
284284
},
285285
payload: {
286286
aud: IDENTIPROOF_ISSUER_URL,
287-
iat: +new Date(),
287+
iat: +new Date()/1000,
288288
nonce: 'test-nonce',
289289
},
290290
},
@@ -322,7 +322,7 @@ describe('VcIssuer', () => {
322322
},
323323
payload: {
324324
aud: IDENTIPROOF_ISSUER_URL,
325-
iat: +new Date(),
325+
iat: +new Date()/1000,
326326
nonce: 'test-nonce',
327327
},
328328
},
@@ -405,7 +405,7 @@ describe('VcIssuer', () => {
405405
},
406406
payload: {
407407
aud: IDENTIPROOF_ISSUER_URL,
408-
iat: +new Date(),
408+
iat: +new Date()/1000,
409409
nonce: 'test-nonce',
410410
},
411411
},

packages/issuer/lib/tokens/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ export const createAccessTokenResponse = async (
134134
credentialOfferSessions: IStateManager<CredentialOfferSession>
135135
cNonces: IStateManager<CNonceState>
136136
cNonce?: string
137-
cNonceExpiresIn?: number
138-
tokenExpiresIn: number
137+
cNonceExpiresIn?: number // expiration in seconds
138+
tokenExpiresIn: number // expiration in seconds
139139
// preAuthorizedCodeExpirationDuration?: number
140140
accessTokenSignerCallback: JWTSignerCallback
141141
accessTokenIssuer: string

0 commit comments

Comments
 (0)