Skip to content

Commit

Permalink
Merge pull request #100 from Sphereon-Opensource/develop
Browse files Browse the repository at this point in the history
new release
  • Loading branch information
nklomp authored Mar 13, 2024
2 parents 05e8ea5 + 1ee1261 commit 5d63db1
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ describe('issuerCallback', () => {

expect(credentialResponse).toEqual({
c_nonce: expect.any(String),
c_nonce_expires_in: 300000,
c_nonce_expires_in: 300,
credential: {
'@context': ['https://www.w3.org/2018/credentials/v1', 'https://w3id.org/security/suites/ed25519-2020/v1'],
credentialSubject: {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/__tests__/SdJwt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('sd-jwt vc', () => {

expect(credentials).toEqual({
c_nonce: 'new-c-nonce',
c_nonce_expires_in: 300000,
c_nonce_expires_in: 300,
credential: 'sd-jwt',
format: 'vc+sd-jwt',
});
Expand Down
2 changes: 1 addition & 1 deletion packages/issuer-rest/lib/__tests__/ClientIssuerIT.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ describe('VcIssuer', () => {
proofCallbacks: { signCallback: proofOfPossessionCallbackFunction },
})
expect(credentialResponse).toMatchObject({
c_nonce_expires_in: 300000,
c_nonce_expires_in: 300,
credential: {
'@context': ['https://www.w3.org/2018/credentials/v1'],
credentialSubject: {},
Expand Down
8 changes: 4 additions & 4 deletions packages/issuer-rest/lib/__tests__/IssuerTokenServer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('OID4VCIServer', () => {
accessTokenSignerCallback: signerCallback,
accessTokenIssuer: 'https://www.example.com',
preAuthorizedCodeExpirationDuration: 2000,
tokenExpiresIn: 300000,
tokenExpiresIn: 300,
},
},
})
Expand All @@ -172,11 +172,11 @@ describe('OID4VCIServer', () => {
expect(actual).toEqual({
access_token: expect.stringContaining('eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJpYXQi'),
token_type: 'bearer',
expires_in: 300000,
expires_in: 300,
c_nonce: expect.any(String),
c_nonce_expires_in: 300000,
c_nonce_expires_in: 300,
authorization_pending: false,
interval: 300000,
interval: 300,
})
})
it('should return http code 400 with message User pin is required', async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/issuer-rest/lib/oid4vci-api-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export function accessTokenEndpoint<DIDDoc extends object>(
const accessTokenIssuer = opts?.accessTokenIssuer ?? process.env.ACCESS_TOKEN_ISSUER ?? issuer.issuerMetadata.credential_issuer

const preAuthorizedCodeExpirationDuration =
opts?.preAuthorizedCodeExpirationDuration ?? getNumberOrUndefined(process.env.PRE_AUTHORIZED_CODE_EXPIRATION_DURATION) ?? 300000
const interval = opts?.interval ?? getNumberOrUndefined(process.env.INTERVAL) ?? 300000
opts?.preAuthorizedCodeExpirationDuration ?? getNumberOrUndefined(process.env.PRE_AUTHORIZED_CODE_EXPIRATION_DURATION) ?? 300
const interval = opts?.interval ?? getNumberOrUndefined(process.env.INTERVAL) ?? 300
const tokenExpiresIn = opts?.tokenExpiresIn ?? 300

// todo: this means we cannot sign JWTs or issue access tokens when configured from env vars!
Expand Down
7 changes: 2 additions & 5 deletions packages/issuer/lib/VcIssuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ import { assertValidPinNumber, createCredentialOfferObject, createCredentialOffe
import { LookupStateManager } from './state-manager'
import { CredentialDataSupplier, CredentialDataSupplierArgs, CredentialIssuanceInput, CredentialSignerCallback } from './types'

const SECOND = 1000

export class VcIssuer<DIDDoc extends object> {
private readonly _issuerMetadata: CredentialIssuerMetadataOpts
private readonly _userPinRequired: boolean
Expand Down Expand Up @@ -79,8 +77,7 @@ export class VcIssuer<DIDDoc extends object> {
this._credentialSignerCallback = args?.credentialSignerCallback
this._jwtVerifyCallback = args?.jwtVerifyCallback
this._credentialDataSupplier = args?.credentialDataSupplier
this._cNonceExpiresIn =
((args?.cNonceExpiresIn ?? (process.env.C_NONCE_EXPIRES_IN ? parseInt(process.env.C_NONCE_EXPIRES_IN) : 300)) as number) * SECOND
this._cNonceExpiresIn = (args?.cNonceExpiresIn ?? (process.env.C_NONCE_EXPIRES_IN ? parseInt(process.env.C_NONCE_EXPIRES_IN) : 300)) as number
}

public getCredentialOfferSessionById(id: string): Promise<CredentialOfferSession> {
Expand Down Expand Up @@ -247,7 +244,7 @@ export class VcIssuer<DIDDoc extends object> {
}
const validated = await this.validateCredentialRequestProof({
...opts,
tokenExpiresIn: opts.tokenExpiresIn ?? 180000,
tokenExpiresIn: opts.tokenExpiresIn ?? 180,
})
preAuthorizedCode = validated.preAuthorizedCode
issuerState = validated.issuerState
Expand Down
2 changes: 1 addition & 1 deletion packages/issuer/lib/__tests__/VcIssuer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ describe('VcIssuer', () => {
}),
).resolves.toEqual({
c_nonce: 'new-test-nonce',
c_nonce_expires_in: 300000,
c_nonce_expires_in: 300,
credential: {
'@context': ['https://www.w3.org/2018/credentials/v1'],
credentialSubject: {},
Expand Down
6 changes: 4 additions & 2 deletions packages/issuer/lib/tokens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ export const generateAccessToken = async (
},
): Promise<string> => {
const { accessTokenIssuer, alg, accessTokenSignerCallback, tokenExpiresIn, preAuthorizedCode } = opts
const iat = new Date().getTime()
// JWT uses seconds for iat and exp
const iat = new Date().getTime() / 1000
const exp = iat + tokenExpiresIn
const jwt: Jwt = {
header: { typ: 'JWT', alg: alg ?? Alg.ES256K },
payload: {
iat,
exp: tokenExpiresIn,
exp,
iss: accessTokenIssuer,
...(preAuthorizedCode && { preAuthorizedCode }),
},
Expand Down

0 comments on commit 5d63db1

Please sign in to comment.