Skip to content

Commit 5218c5c

Browse files
authored
Merge pull request #97 from TimoGlastra/fix/await-state-updates
fix: await session state updates
2 parents 3b4a735 + 963fb88 commit 5218c5c

4 files changed

Lines changed: 12 additions & 12 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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,17 +345,17 @@ export class VcIssuer<DIDDoc extends object> {
345345
throw new Error(CREDENTIAL_MISSING_ERROR)
346346
}
347347
// remove the previous nonce
348-
this.cNonces.delete(cNonceState.cNonce)
348+
await this.cNonces.delete(cNonceState.cNonce)
349349

350350
if (preAuthorizedCode && preAuthSession) {
351351
preAuthSession.lastUpdatedAt = +new Date()
352352
preAuthSession.status = IssueStatus.CREDENTIAL_ISSUED
353-
this._credentialOfferSessions.set(preAuthorizedCode, preAuthSession)
353+
await this._credentialOfferSessions.set(preAuthorizedCode, preAuthSession)
354354
} else if (issuerState && authSession) {
355355
// If both were set we used the pre auth flow above as well, hence the else if
356356
authSession.lastUpdatedAt = +new Date()
357357
authSession.status = IssueStatus.CREDENTIAL_ISSUED
358-
this._credentialOfferSessions.set(issuerState, authSession)
358+
await this._credentialOfferSessions.set(issuerState, authSession)
359359
}
360360

361361
return {
@@ -385,7 +385,7 @@ export class VcIssuer<DIDDoc extends object> {
385385
preAuthSession.lastUpdatedAt = +new Date()
386386
preAuthSession.status = IssueStatus.ERROR
387387
preAuthSession.error = error instanceof Error ? error.message : error?.toString()
388-
this._credentialOfferSessions.set(preAuthorizedCode, preAuthSession)
388+
await this._credentialOfferSessions.set(preAuthorizedCode, preAuthSession)
389389
}
390390
}
391391
if (issuerState) {
@@ -394,7 +394,7 @@ export class VcIssuer<DIDDoc extends object> {
394394
authSession.lastUpdatedAt = +new Date()
395395
authSession.status = IssueStatus.ERROR
396396
authSession.error = error instanceof Error ? error.message : error?.toString()
397-
this._credentialOfferSessions.set(issuerState, authSession)
397+
await this._credentialOfferSessions.set(issuerState, authSession)
398398
}
399399
}
400400
}

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)