Skip to content

Commit dd2985b

Browse files
authored
Merge pull request #98 from Sphereon-Opensource/develop
new release
2 parents b0dfe6e + 757eb73 commit dd2985b

9 files changed

Lines changed: 122 additions & 130 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/client/lib/OpenID4VCIClient.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface OpenID4VCIClientState {
4646
endpointMetadata?: EndpointMetadataResult;
4747
accessTokenResponse?: AccessTokenResponse;
4848
authorizationRequestOpts?: AuthorizationRequestOpts;
49+
authorizationCodeResponse?: AuthorizationResponse;
4950
pkce: PKCEOpts;
5051
authorizationURL?: string;
5152
}
@@ -65,6 +66,7 @@ export class OpenID4VCIClient {
6566
endpointMetadata,
6667
accessTokenResponse,
6768
authorizationRequestOpts,
69+
authorizationCodeResponse,
6870
authorizationURL,
6971
}: {
7072
credentialOffer?: CredentialOfferRequestWithBaseUrl;
@@ -78,6 +80,7 @@ export class OpenID4VCIClient {
7880
endpointMetadata?: EndpointMetadataResult;
7981
accessTokenResponse?: AccessTokenResponse;
8082
authorizationRequestOpts?: AuthorizationRequestOpts;
83+
authorizationCodeResponse?: AuthorizationResponse;
8184
authorizationURL?: string;
8285
}) {
8386
const issuer = credentialIssuer ?? (credentialOffer ? getIssuerFromCredentialOfferPayload(credentialOffer.credential_offer) : undefined);
@@ -93,6 +96,7 @@ export class OpenID4VCIClient {
9396
clientId: clientId ?? (credentialOffer && getClientIdFromCredentialOfferPayload(credentialOffer.credential_offer)) ?? kid?.split('#')[0],
9497
pkce: { disabled: false, codeChallengeMethod: CodeChallengeMethod.S256, ...pkce },
9598
authorizationRequestOpts,
99+
authorizationCodeResponse,
96100
jwk,
97101
endpointMetadata,
98102
accessTokenResponse,
@@ -254,7 +258,12 @@ export class OpenID4VCIClient {
254258
}): Promise<AccessTokenResponse> {
255259
const { pin, clientId } = opts ?? {};
256260
let { redirectUri } = opts ?? {};
257-
const code = opts?.code ?? (opts?.authorizationResponse ? toAuthorizationResponsePayload(opts.authorizationResponse).code : undefined);
261+
if (opts?.authorizationResponse) {
262+
this._state.authorizationCodeResponse = { ...toAuthorizationResponsePayload(opts.authorizationResponse) };
263+
} else if (opts?.code) {
264+
this._state.authorizationCodeResponse = { code: opts.code };
265+
}
266+
const code = this._state.authorizationCodeResponse?.code;
258267

259268
if (opts?.codeVerifier) {
260269
this._state.pkce.codeVerifier = opts.codeVerifier;
@@ -288,7 +297,7 @@ export class OpenID4VCIClient {
288297
});
289298

290299
if (response.errorBody) {
291-
debug(`Access token error:\r\n${response.errorBody}`);
300+
debug(`Access token error:\r\n${JSON.stringify(response.errorBody)}`);
292301
throw Error(
293302
`Retrieving an access token from ${this._state.endpointMetadata?.token_endpoint} for issuer ${this.getIssuer()} failed with status: ${
294303
response.origResponse.status

packages/common/lib/functions/CredentialRequestUtil.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ export function getTypesFromRequest(credentialRequest: UniformCredentialRequest,
77
if (credentialRequest.format === 'jwt_vc_json' || credentialRequest.format === 'jwt_vc') {
88
types = credentialRequest.types;
99
} else if (credentialRequest.format === 'jwt_vc_json-ld' || credentialRequest.format === 'ldp_vc') {
10-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
11-
// @ts-ignore
1210
types =
1311
'credential_definition' in credentialRequest && credentialRequest.credential_definition
14-
? // eslint-disable-next-line @typescript-eslint/ban-ts-comment
12+
? credentialRequest.credential_definition.types
13+
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
1514
// @ts-ignore
16-
credentialRequest.credential_definition.types
17-
: credentialRequest.types;
15+
credentialRequest.types;
1816
} else if (credentialRequest.format === 'vc+sd-jwt') {
1917
types = [credentialRequest.vct];
2018
}

packages/common/lib/types/OpenID4VCIErrors.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { Alg } from './CredentialIssuance.types'
1+
import { Alg } from './CredentialIssuance.types';
22

33
export const BAD_PARAMS = 'Wrong parameters provided';
44
export const URL_NOT_VALID = 'Request url is not valid';
55
export const JWS_NOT_VALID = 'JWS is not valid';
66
export const PROOF_CANT_BE_CONSTRUCTED = "Proof can't be constructed.";
77
export const NO_JWT_PROVIDED = 'No JWT provided';
88
export const TYP_ERROR = 'Typ must be "openid4vci-proof+jwt"';
9-
export const ALG_ERROR = `Algorithm is a required field, you are free to use the signing algorithm of your choice or one of the following: ${Object.keys(Alg).join(', ')}`;
9+
export const ALG_ERROR = `Algorithm is a required field, you are free to use the signing algorithm of your choice or one of the following: ${Object.keys(
10+
Alg,
11+
).join(', ')}`;
1012
export const KID_JWK_X5C_ERROR = 'Only one must be present: kid, jwk or x5c';
1113
export const KID_DID_NO_DID_ERROR = 'A DID value needs to be returned when kid is present';
1214
export const DID_NO_DIDDOC_ERROR = 'A DID Document needs to be resolved when a DID is encountered';

packages/common/lib/types/v1_0_11.types.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {
55
CredentialIssuerMetadataOpts,
66
CredentialOfferFormat,
77
CredentialRequestJwtVcJson,
8+
CredentialRequestJwtVcJsonLdAndLdpVc,
89
CredentialRequestSdJwtVc,
910
Grant,
10-
JsonLdIssuerCredentialDefinition,
1111
} from './Generic.types';
1212
import { QRCodeOpts } from './QRCode.types';
1313
import { AuthorizationServerMetadata } from './ServerMetadata';
@@ -58,13 +58,8 @@ export interface CredentialOfferPayloadV1_0_11 {
5858
}
5959

6060
export type CredentialRequestV1_0_11 = CommonCredentialRequest &
61-
(CredentialRequestJwtVcJson | CredentialRequestJwtVcJsonLdAndLdpVcV1_0_11 | CredentialRequestSdJwtVc);
61+
(CredentialRequestJwtVcJson | CredentialRequestJwtVcJsonLdAndLdpVc | CredentialRequestSdJwtVc);
6262

63-
export interface CredentialRequestJwtVcJsonLdAndLdpVcV1_0_11
64-
extends CommonCredentialRequest,
65-
Pick<JsonLdIssuerCredentialDefinition, 'credentialSubject' | 'types'> {
66-
format: 'ldp_vc' | 'jwt_vc_json-ld';
67-
}
6863
export interface CredentialIssuerMetadataV1_0_11 extends CredentialIssuerMetadataOpts, Partial<AuthorizationServerMetadata> {
6964
credential_endpoint: string; // REQUIRED. URL of the Credential Issuer's Credential Endpoint. This URL MUST use the https scheme and MAY contain port, path and query parameter components.
7065
authorization_server?: string;

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
}

0 commit comments

Comments
 (0)