Skip to content

Commit 57e0995

Browse files
committed
chore: Fixed createdAt in cNonce endpoint + remove useless functionality
1 parent 6cbc2a9 commit 57e0995

1 file changed

Lines changed: 6 additions & 34 deletions

File tree

packages/issuer-rest/lib/oid4vci-api-functions.ts

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { epochTime, uuidv4 } from '@sphereon/oid4vc-common'
1+
import { uuidv4 } from '@sphereon/oid4vc-common'
22
import {
33
ACCESS_TOKEN_ISSUER_REQUIRED_ERROR,
44
AccessTokenRequest,
@@ -434,46 +434,18 @@ export function nonceEndpoint(router: Router, issuer: VcIssuer, opts: INonceEndp
434434

435435
router.post(path, async (request: Request, response: Response) => {
436436
try {
437-
let preAuthorizedCode: string | undefined
438-
let issuerState: string | undefined
439-
440-
// Verify access token if present (optional per spec)
441-
// If not present, the nonce will be unbound to any session
442-
if (request.header('Authorization')) {
443-
try {
444-
const jwt = extractBearerToken(request.header('Authorization'))
445-
const jwtResult = await validateJWT(jwt, {
446-
accessTokenVerificationCallback: issuer.jwtVerifyCallback
447-
})
448-
449-
// Extract session info from access token
450-
const accessToken = jwtResult.jwt.payload as AccessTokenRequest
451-
preAuthorizedCode = accessToken['pre-authorized_code']
452-
} catch (e) {
453-
LOG.warning(e)
454-
return sendErrorResponse(response, 400, {
455-
error: 'invalid_token'
456-
})
457-
}
458-
}
459-
460437
const cNonce = uuidv4()
461438
const cNonceExpiresIn = issuer.cNonceExpiresIn || 300
462439

463-
const createdAt = epochTime()
440+
const createdAt = +Date.now()
441+
const expiresAt = createdAt + Math.abs(cNonceExpiresIn) * 1000
442+
464443

465444
// Create nonce state - only include session identifiers if available
466445
const cNonceState: any = {
467446
cNonce,
468-
createdAt: createdAt,
469-
expiresAt: createdAt + cNonceExpiresIn
470-
}
471-
472-
if (preAuthorizedCode) {
473-
cNonceState.preAuthorizedCode = preAuthorizedCode
474-
}
475-
if (issuerState) {
476-
cNonceState.issuerState = issuerState
447+
createdAt,
448+
expiresAt
477449
}
478450

479451
await issuer.cNonces.set(cNonce, cNonceState)

0 commit comments

Comments
 (0)