Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/CWALL-174_impl-draft1-sa…
Browse files Browse the repository at this point in the history
…djad' into feature/CWALL-174_impl-draft1-sadjad

# Conflicts:
#	packages/issuer-rest/lib/oid4vci-api-functions.ts
  • Loading branch information
sanderPostma committed May 22, 2024
2 parents 337775a + fc8cdf0 commit cd8c11d
Show file tree
Hide file tree
Showing 5 changed files with 8,923 additions and 6,333 deletions.
15 changes: 3 additions & 12 deletions packages/client/lib/__tests__/SdJwt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,15 @@ describe('sd-jwt vc', () => {
'pre-authorized_code': '123',
},
},
credentials: {
SdJwtCredentialId: {
credential_definition: {
type: ['SdJwtCredential'],
},
format: 'vc+sd-jwt',
vct: 'SdJwtCredential',
id: 'SdJwtCredentialId',
},
},
credential_configuration_ids: ['SdJwtCredential'],
});

nock(vcIssuer.issuerMetadata.credential_issuer).get('/.well-known/openid-credential-issuer').reply(200, JSON.stringify(issuerMetadata));
nock(vcIssuer.issuerMetadata.credential_issuer).get('/.well-known/openid-configuration').reply(404);
nock(vcIssuer.issuerMetadata.credential_issuer).get('/.well-known/oauth-authorization-server').reply(404);

expect(offerUri.uri).toEqual(
'openid-credential-offer://?credential_offer=%7B%22grants%22%3A%7B%22urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Apre-authorized_code%22%3A%7B%22pre-authorized_code%22%3A%22123%22%2C%22tx_code%22%3A%7B%22input_mode%22%3A%22text%22%2C%22length%22%3A3%7D%7D%7D%2C%22credential_configuration_ids%22%3A%5B%22SdJwtCredentialId%22%5D%2C%22credential_issuer%22%3A%22https%3A%2F%2Fexample.com%22%7D',
'openid-credential-offer://?credential_offer=%7B%22grants%22%3A%7B%22urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Apre-authorized_code%22%3A%7B%22pre-authorized_code%22%3A%22123%22%2C%22tx_code%22%3A%7B%22input_mode%22%3A%22text%22%2C%22length%22%3A3%7D%7D%7D%2C%22credential_configuration_ids%22%3A%5B%22SdJwtCredential%22%5D%2C%22credential_issuer%22%3A%22https%3A%2F%2Fexample.com%22%7D',
);

const client = await OpenID4VCIClient.fromURI({
Expand All @@ -103,7 +94,7 @@ describe('sd-jwt vc', () => {

expect(client.credentialOffer?.credential_offer).toEqual({
credential_issuer: 'https://example.com',
credential_configuration_ids: ['SdJwtCredentialId'],
credential_configuration_ids: ['SdJwtCredential'],
grants: {
'urn:ietf:params:oauth:grant-type:pre-authorized_code': {
'pre-authorized_code': '123',
Expand Down
9 changes: 1 addition & 8 deletions packages/issuer-rest/lib/__tests__/ClientIssuerIT.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,7 @@ describe('VcIssuer', () => {
},
},
},
credentials: {
UniversityDegree_JWT: {
format: 'ldp_vc',
credential_definition: {
type: ['VerifiableCredential'],
},
} as CredentialConfigurationSupportedV1_0_13,
},
credential_configuration_ids: ['UniversityDegree_JWT'],
scheme: 'http',
})
.then((response) => response.uri)
Expand Down
28 changes: 19 additions & 9 deletions packages/issuer-rest/lib/oid4vci-api-functions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {
ACCESS_TOKEN_ISSUER_REQUIRED_ERROR,
AuthorizationRequest, CredentialOfferRESTRequest, CredentialRequestV1_0_11,
determineGrantTypes, determineSpecVersionFromOffer,
AuthorizationRequest,
CredentialOfferRESTRequest,
CredentialRequestV1_0_11,
determineGrantTypes,
determineSpecVersionFromOffer,
getNumberOrUndefined,
Grant,
IssueStatusResponse,
JWT_SIGNER_CALLBACK_REQUIRED_ERROR, OpenId4VCIVersion,
TokenErrorResponse
} from '@sphereon/oid4vci-common';
JWT_SIGNER_CALLBACK_REQUIRED_ERROR,
OpenId4VCIVersion,
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 @@ -194,18 +198,24 @@ export function createCredentialOfferEndpoint<DIDDoc extends object>(
router.post(path, async (request: Request<CredentialOfferRESTRequest>, response: Response<ICreateCredentialOfferURIResponse>) => {
try {
const specVersion = determineSpecVersionFromOffer(request.body.original_credential_offer)
if(specVersion < OpenId4VCIVersion.VER_1_0_13) {
return sendErrorResponse(response, 400, { error: TokenErrorResponse.invalid_client, error_description: 'credential offer request should be of spec version 1.0.13 or above' })
if (specVersion < OpenId4VCIVersion.VER_1_0_13) {
return sendErrorResponse(response, 400, {
error: TokenErrorResponse.invalid_client,
error_description: 'credential offer request should be of spec version 1.0.13 or above',
})
}

const grantTypes = determineGrantTypes(request.body)
if (grantTypes.length === 0) {
return sendErrorResponse(response, 400, { error: TokenErrorResponse.invalid_grant, error_description: 'No grant type supplied' })
}
const grants = request.body.grants as Grant
const credentialConfigIds = request.body.credential_configuration_ids as string []
const credentialConfigIds = request.body.credential_configuration_ids as string[]
if (!credentialConfigIds || credentialConfigIds.length === 0) {
return sendErrorResponse(response, 400, { error: TokenErrorResponse.invalid_request, error_description: 'credential_configuration_ids missing credential_configuration_ids in credential offer payload' })
return sendErrorResponse(response, 400, {
error: TokenErrorResponse.invalid_request,
error_description: 'credential_configuration_ids missing credential_configuration_ids in credential offer payload',
})
}
const qrCodeOpts = request.body.qrCodeOpts ?? opts?.qrCodeOpts
const result = await issuer.createCredentialOfferURI({ ...request.body, qrCodeOpts, grants })
Expand Down
7 changes: 1 addition & 6 deletions packages/issuer/lib/__tests__/VcIssuer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,7 @@ describe('VcIssuer', () => {
},
scheme: 'http',
baseUri: 'issuer-example.com',
credentials: {
Credential: {
credential_definition: { type: ['VerifiableCredential'] },
format: 'ldp_vc',
},
},
credential_configuration_ids: ['VerifiableCredential'],
credentialOfferUri: 'https://somehost.com/offer-id',
})
.then((response) => response.uri),
Expand Down
Loading

0 comments on commit cd8c11d

Please sign in to comment.