Skip to content

Commit 963fb88

Browse files
committed
fix: await session state updates
Signed-off-by: Timo Glastra <timo@animo.id>
1 parent 7a221bb commit 963fb88

4 files changed

Lines changed: 14 additions & 19 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
@@ -139,7 +139,7 @@ describe('issuerCallback', () => {
139139
})
140140

141141
const nonces = new MemoryStates<CNonceState>()
142-
nonces.set('test_value', { cNonce: 'test_value', createdAt: +new Date(), issuerState: 'existing-state' })
142+
await nonces.set('test_value', { cNonce: 'test_value', createdAt: +new Date(), issuerState: 'existing-state' })
143143
vcIssuer = new VcIssuerBuilder<DIDDocument>()
144144
.withAuthorizationServer('https://authorization-server')
145145
.withCredentialEndpoint('https://credential-endpoint')

packages/issuer/lib/VcIssuer.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,14 @@ import {
3232
toUniformCredentialOfferRequest,
3333
TYP_ERROR,
3434
UniformCredentialRequest,
35-
URIState
35+
URIState,
3636
} from '@sphereon/oid4vci-common'
3737
import { CompactSdJwtVc, CredentialMapper, W3CVerifiableCredential } from '@sphereon/ssi-types'
3838
import { v4 } from 'uuid'
3939

4040
import { assertValidPinNumber, createCredentialOfferObject, createCredentialOfferURIFromObject } from './functions'
4141
import { LookupStateManager } from './state-manager'
42-
import {
43-
CredentialDataSupplier,
44-
CredentialDataSupplierArgs,
45-
CredentialIssuanceInput,
46-
CredentialSignerCallback
47-
} from './types'
42+
import { CredentialDataSupplier, CredentialDataSupplierArgs, CredentialIssuanceInput, CredentialSignerCallback } from './types'
4843

4944
const SECOND = 1000
5045

@@ -350,17 +345,17 @@ export class VcIssuer<DIDDoc extends object> {
350345
throw new Error(CREDENTIAL_MISSING_ERROR)
351346
}
352347
// remove the previous nonce
353-
this.cNonces.delete(cNonceState.cNonce)
348+
await this.cNonces.delete(cNonceState.cNonce)
354349

355350
if (preAuthorizedCode && preAuthSession) {
356351
preAuthSession.lastUpdatedAt = +new Date()
357352
preAuthSession.status = IssueStatus.CREDENTIAL_ISSUED
358-
this._credentialOfferSessions.set(preAuthorizedCode, preAuthSession)
353+
await this._credentialOfferSessions.set(preAuthorizedCode, preAuthSession)
359354
} else if (issuerState && authSession) {
360355
// If both were set we used the pre auth flow above as well, hence the else if
361356
authSession.lastUpdatedAt = +new Date()
362357
authSession.status = IssueStatus.CREDENTIAL_ISSUED
363-
this._credentialOfferSessions.set(issuerState, authSession)
358+
await this._credentialOfferSessions.set(issuerState, authSession)
364359
}
365360

366361
return {
@@ -390,7 +385,7 @@ export class VcIssuer<DIDDoc extends object> {
390385
preAuthSession.lastUpdatedAt = +new Date()
391386
preAuthSession.status = IssueStatus.ERROR
392387
preAuthSession.error = error instanceof Error ? error.message : error?.toString()
393-
this._credentialOfferSessions.set(preAuthorizedCode, preAuthSession)
388+
await this._credentialOfferSessions.set(preAuthorizedCode, preAuthSession)
394389
}
395390
}
396391
if (issuerState) {
@@ -399,7 +394,7 @@ export class VcIssuer<DIDDoc extends object> {
399394
authSession.lastUpdatedAt = +new Date()
400395
authSession.status = IssueStatus.ERROR
401396
authSession.error = error instanceof Error ? error.message : error?.toString()
402-
this._credentialOfferSessions.set(issuerState, authSession)
397+
await this._credentialOfferSessions.set(issuerState, authSession)
403398
}
404399
}
405400
}

packages/issuer/lib/state-manager/LookupStateManager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export class LookupStateManager<K extends StateType, V extends StateType> implem
4848
}
4949

5050
async delete(id: string): Promise<boolean> {
51-
return await this.assertedValueId(id).then((value) => {
52-
this.keyValueMapper.delete(id)
51+
return await this.assertedValueId(id).then(async (value) => {
52+
await this.keyValueMapper.delete(id)
5353
return this.valueStateManager.delete(value)
5454
})
5555
}
@@ -68,8 +68,8 @@ export class LookupStateManager<K extends StateType, V extends StateType> implem
6868
}
6969

7070
async setMapped(id: string, keyValue: K, stateValue: V): Promise<void> {
71-
this.keyValueMapper.set(id, keyValue)
72-
this.valueStateManager.set(id, stateValue)
71+
await this.keyValueMapper.set(id, keyValue)
72+
await this.valueStateManager.set(id, stateValue)
7373
}
7474

7575
async getAsserted(id: string): Promise<V> {

packages/issuer/lib/tokens/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const assertValidAccessTokenRequest = async (
8888
const credentialOfferSession = await credentialOfferSessions.getAsserted(request[PRE_AUTH_CODE_LITERAL])
8989
credentialOfferSession.status = IssueStatus.ACCESS_TOKEN_REQUESTED
9090
credentialOfferSession.lastUpdatedAt = +new Date()
91-
credentialOfferSessions.set(request[PRE_AUTH_CODE_LITERAL], credentialOfferSession)
91+
await credentialOfferSessions.set(request[PRE_AUTH_CODE_LITERAL], credentialOfferSession)
9292
if (!isValidGrant(credentialOfferSession, request.grant_type)) {
9393
throw new TokenError(400, TokenErrorResponse.invalid_grant, UNSUPPORTED_GRANT_TYPE_ERROR)
9494
}
@@ -165,6 +165,6 @@ export const createAccessTokenResponse = async (
165165
const credentialOfferSession = await credentialOfferSessions.getAsserted(preAuthorizedCode)
166166
credentialOfferSession.status = IssueStatus.ACCESS_TOKEN_CREATED
167167
credentialOfferSession.lastUpdatedAt = +new Date()
168-
credentialOfferSessions.set(preAuthorizedCode, credentialOfferSession)
168+
await credentialOfferSessions.set(preAuthorizedCode, credentialOfferSession)
169169
return response
170170
}

0 commit comments

Comments
 (0)