Skip to content

Commit

Permalink
CWALL-174: fixed createCredentialOfferEndpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderPostma committed May 21, 2024
1 parent d348641 commit bd7bfa0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@
"OID4VCI"
]
}

15 changes: 7 additions & 8 deletions packages/issuer-rest/lib/oid4vci-api-functions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import {
ACCESS_TOKEN_ISSUER_REQUIRED_ERROR,
AuthorizationRequest,
CredentialOfferRESTRequestV1_0_11,
AuthorizationRequest, CredentialOfferRESTRequestV1_0_11,
CredentialRequestV1_0_11,
determineGrantTypes,
getNumberOrUndefined,
Grant,
IssueStatusResponse,
JWT_SIGNER_CALLBACK_REQUIRED_ERROR,
TokenErrorResponse,
} from '@sphereon/oid4vci-common'
TokenErrorResponse
} from '@sphereon/oid4vci-common';
import { adjustUrl, trimBoth, trimEnd, trimStart } from '@sphereon/oid4vci-common/dist/functions/HttpUtils'
import { ITokenEndpointOpts, VcIssuer } from '@sphereon/oid4vci-issuer'
import { env, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'
Expand Down Expand Up @@ -201,12 +200,12 @@ export function createCredentialOfferEndpoint<DIDDoc extends object>(
return sendErrorResponse(response, 400, { error: TokenErrorResponse.invalid_grant, error_description: 'No grant type supplied' })
}
const grants = request.body.grants as Grant
const credentials = request.body.credentials as (string | CredentialFormat)[]
if (!credentials || credentials.length === 0) {
return sendErrorResponse(response, 400, { error: TokenErrorResponse.invalid_request, error_description: 'No credentials supplied' })
const credentialIds = request.body.credentials as (string | CredentialFormat)[]
if (!credentialIds || credentialIds.length === 0) {
return sendErrorResponse(response, 400, { error: TokenErrorResponse.invalid_request, error_description: 'No credential ids supplied' })
}
const qrCodeOpts = request.body.qrCodeOpts ?? opts?.qrCodeOpts
const result = await issuer.createCredentialOfferURI({ ...request.body, qrCodeOpts, grants, credentials })
const result = await issuer.createCredentialOfferURI({ ...request.body, qrCodeOpts, grants })
const resultResponse: ICreateCredentialOfferURIResponse = result
if ('session' in resultResponse) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
5 changes: 2 additions & 3 deletions packages/issuer/lib/VcIssuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
CNonceState,
CreateCredentialOfferURIResult,
CREDENTIAL_MISSING_ERROR,
CredentialConfigurationSupported,
CredentialConfigurationSupportedV1_0_13,
CredentialDataSupplierInput,
CredentialOfferPayloadV1_0_13,
Expand Down Expand Up @@ -89,7 +88,7 @@ export class VcIssuer<DIDDoc extends object> {

public async createCredentialOfferURI(opts: {
grants?: Grant
credentials?: Record<string, CredentialConfigurationSupported>
credentials?: Array<string>
credentialDefinition?: JsonLdIssuerCredentialDefinition
credentialOfferUri?: string
credentialDataSupplierInput?: CredentialDataSupplierInput // Optional storage that can help the credential Data Supplier. For instance to store credential input data during offer creation, if no additional data can be supplied later on
Expand All @@ -107,7 +106,7 @@ export class VcIssuer<DIDDoc extends object> {
}
const credentialOfferPayload: CredentialOfferPayloadV1_0_13 = {
...(grants && { grants }),
...(credentials && { credential_configuration_ids: credentials ? Object.keys(credentials) : [] }),
...(credentials && { credential_configuration_ids: credentials ?? [] }),
credential_issuer: this.issuerMetadata.credential_issuer,
} as CredentialOfferPayloadV1_0_13
if (grants?.authorization_code) {
Expand Down

0 comments on commit bd7bfa0

Please sign in to comment.