Skip to content

Commit a04152d

Browse files
authored
Merge pull request #123 from Sphereon-Opensource/develop
New release
2 parents 4ae9812 + 5323f58 commit a04152d

28 files changed

Lines changed: 3818 additions & 3620 deletions

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@
3232
"printWidth": 150
3333
},
3434
"devDependencies": {
35-
"@types/debug": "^4.1.8",
36-
"@types/jest": "^29.5.3",
37-
"@types/node": "^18.17.3",
35+
"@types/debug": "^4.1.12",
36+
"@types/jest": "^29.5.12",
37+
"@types/node": "^18.19.39",
3838
"codecov": "^3.8.3",
39-
"jest": "^29.6.2",
40-
"lerna": "^8.1.2",
39+
"jest": "^29.7.0",
40+
"lerna": "^8.1.6",
4141
"lerna-changelog": "^2.2.0",
4242
"npm-run-all": "^4.1.5",
43-
"prettier": "^3.2.5",
44-
"rimraf": "^5.0.5",
45-
"ts-jest": "^29.1.2",
43+
"prettier": "^3.3.2",
44+
"rimraf": "^5.0.8",
45+
"ts-jest": "^29.1.5",
4646
"typescript": "5.4.5"
4747
},
4848
"keywords": [

packages/callback-example/lib/__tests__/issuerCallback.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe('issuerCallback', () => {
119119
lastUpdatedAt: +new Date(),
120120
status: IssueStatus.OFFER_CREATED,
121121
notification_id: v4(),
122-
userPin: '123456',
122+
txCode: '123456',
123123
credentialOffer: {
124124
credential_offer: {
125125
credential_issuer: 'did:key:test',

packages/client/lib/AccessTokenClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
JsonURIMode,
1515
OpenIDResponse,
1616
PRE_AUTH_CODE_LITERAL,
17+
PRE_AUTH_GRANT_LITERAL,
1718
TokenErrorResponse,
1819
toUniformCredentialOfferRequest,
1920
TxCodeAndPinRequired,
@@ -107,8 +108,7 @@ export class AccessTokenClient {
107108

108109
request.grant_type = GrantTypes.PRE_AUTHORIZED_CODE;
109110
// we actually know it is there because of the isPreAuthCode call
110-
request[PRE_AUTH_CODE_LITERAL] =
111-
credentialOfferRequest?.credential_offer.grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.[PRE_AUTH_CODE_LITERAL];
111+
request[PRE_AUTH_CODE_LITERAL] = credentialOfferRequest?.credential_offer.grants?.[PRE_AUTH_GRANT_LITERAL]?.[PRE_AUTH_CODE_LITERAL];
112112

113113
return request as AccessTokenRequest;
114114
}
@@ -146,7 +146,7 @@ export class AccessTokenClient {
146146
}
147147
const issuer = getIssuerFromCredentialOfferPayload(requestPayload);
148148

149-
const grantDetails = requestPayload.grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code'];
149+
const grantDetails = requestPayload.grants?.[PRE_AUTH_GRANT_LITERAL];
150150
const isPinRequired = !!grantDetails?.tx_code ?? false;
151151

152152
LOG.warning(`Pin required for issuer ${issuer}: ${isPinRequired}`);
@@ -211,7 +211,7 @@ export class AccessTokenClient {
211211
if (accessTokenRequest.grant_type === GrantTypes.PRE_AUTHORIZED_CODE) {
212212
this.assertPreAuthorizedGrantType(accessTokenRequest.grant_type);
213213
this.assertNonEmptyPreAuthorizedCode(accessTokenRequest);
214-
this.assertAlphanumericPin(pinMeta, accessTokenRequest.user_pin);
214+
this.assertAlphanumericPin(pinMeta, accessTokenRequest.tx_code ?? accessTokenRequest.user_pin);
215215
} else if (accessTokenRequest.grant_type === GrantTypes.AUTHORIZATION_CODE) {
216216
this.assertAuthorizationGrantType(accessTokenRequest.grant_type);
217217
this.assertNonEmptyCodeVerifier(accessTokenRequest);

packages/client/lib/AccessTokenClientV1_0_11.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
OpenId4VCIVersion,
1818
OpenIDResponse,
1919
PRE_AUTH_CODE_LITERAL,
20+
PRE_AUTH_GRANT_LITERAL,
2021
TokenErrorResponse,
2122
toUniformCredentialOfferRequest,
2223
UniformCredentialOfferPayload,
@@ -112,8 +113,7 @@ export class AccessTokenClientV1_0_11 {
112113

113114
request.grant_type = GrantTypes.PRE_AUTHORIZED_CODE;
114115
// we actually know it is there because of the isPreAuthCode call
115-
request[PRE_AUTH_CODE_LITERAL] =
116-
credentialOfferRequest?.credential_offer.grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.[PRE_AUTH_CODE_LITERAL];
116+
request[PRE_AUTH_CODE_LITERAL] = credentialOfferRequest?.credential_offer.grants?.[PRE_AUTH_GRANT_LITERAL]?.[PRE_AUTH_CODE_LITERAL];
117117

118118
return request as AccessTokenRequest;
119119
}
@@ -135,7 +135,7 @@ export class AccessTokenClientV1_0_11 {
135135

136136
private assertPreAuthorizedGrantType(grantType: GrantTypes): void {
137137
if (GrantTypes.PRE_AUTHORIZED_CODE !== grantType) {
138-
throw new Error("grant type must be 'urn:ietf:params:oauth:grant-type:pre-authorized_code'");
138+
throw new Error('grant type must be PRE_AUTH_GRANT_LITERAL');
139139
}
140140
}
141141

@@ -151,8 +151,8 @@ export class AccessTokenClientV1_0_11 {
151151
throw new Error(TokenErrorResponse.invalid_request);
152152
}
153153
const issuer = getIssuerFromCredentialOfferPayload(requestPayload);
154-
if (requestPayload.grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']) {
155-
isPinRequired = requestPayload.grants['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.user_pin_required ?? false;
154+
if (requestPayload.grants?.[PRE_AUTH_GRANT_LITERAL]) {
155+
isPinRequired = requestPayload.grants[PRE_AUTH_GRANT_LITERAL]?.user_pin_required ?? false;
156156
}
157157
debug(`Pin required for issuer ${issuer}: ${isPinRequired}`);
158158
return isPinRequired;

packages/client/lib/CredentialOfferClient.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
determineSpecVersionFromURI,
1111
getClientIdFromCredentialOfferPayload,
1212
OpenId4VCIVersion,
13+
PRE_AUTH_CODE_LITERAL,
14+
PRE_AUTH_GRANT_LITERAL,
1315
toUniformCredentialOfferRequest,
1416
} from '@sphereon/oid4vci-common';
1517
import Debug from 'debug';
@@ -64,17 +66,16 @@ export class CredentialOfferClient {
6466
...(clientId && { clientId }),
6567
...request,
6668
...(grants?.authorization_code?.issuer_state && { issuerState: grants.authorization_code.issuer_state }),
67-
...(grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.['pre-authorized_code'] && {
68-
preAuthorizedCode: grants['urn:ietf:params:oauth:grant-type:pre-authorized_code']['pre-authorized_code'],
69+
...(grants?.[PRE_AUTH_GRANT_LITERAL]?.[PRE_AUTH_CODE_LITERAL] && {
70+
preAuthorizedCode: grants[PRE_AUTH_GRANT_LITERAL][PRE_AUTH_CODE_LITERAL],
6971
}),
7072
userPinRequired:
71-
request.credential_offer?.grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.user_pin_required ??
72-
!!request.credential_offer?.grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.tx_code ??
73+
request.credential_offer?.grants?.[PRE_AUTH_GRANT_LITERAL]?.user_pin_required ??
74+
!!request.credential_offer?.grants?.[PRE_AUTH_GRANT_LITERAL]?.tx_code ??
7375
false,
74-
...(request.credential_offer?.grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.tx_code &&
75-
{
76-
// txCode: request.credential_offer?.grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.tx_code,
77-
}),
76+
...(request.credential_offer?.grants?.[PRE_AUTH_GRANT_LITERAL]?.tx_code && {
77+
txCode: request.credential_offer.grants[PRE_AUTH_GRANT_LITERAL].tx_code,
78+
}),
7879
};
7980
}
8081

packages/client/lib/CredentialOfferClientV1_0_11.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
determineSpecVersionFromURI,
1111
getClientIdFromCredentialOfferPayload,
1212
OpenId4VCIVersion,
13+
PRE_AUTH_CODE_LITERAL,
14+
PRE_AUTH_GRANT_LITERAL,
1315
toUniformCredentialOfferRequest,
1416
} from '@sphereon/oid4vci-common';
1517
import Debug from 'debug';
@@ -59,10 +61,10 @@ export class CredentialOfferClientV1_0_11 {
5961
...(clientId && { clientId }),
6062
...request,
6163
...(grants?.authorization_code?.issuer_state && { issuerState: grants.authorization_code.issuer_state }),
62-
...(grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.['pre-authorized_code'] && {
63-
preAuthorizedCode: grants['urn:ietf:params:oauth:grant-type:pre-authorized_code']['pre-authorized_code'],
64+
...(grants?.[PRE_AUTH_GRANT_LITERAL]?.[PRE_AUTH_CODE_LITERAL] && {
65+
preAuthorizedCode: grants[PRE_AUTH_GRANT_LITERAL][PRE_AUTH_CODE_LITERAL],
6466
}),
65-
userPinRequired: !!request.credential_offer?.grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.user_pin_required ?? false,
67+
userPinRequired: !!request.credential_offer?.grants?.[PRE_AUTH_GRANT_LITERAL]?.user_pin_required ?? false,
6668
};
6769
}
6870

packages/client/lib/CredentialOfferClientV1_0_13.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
determineSpecVersionFromURI,
77
getClientIdFromCredentialOfferPayload,
88
OpenId4VCIVersion,
9+
PRE_AUTH_CODE_LITERAL,
10+
PRE_AUTH_GRANT_LITERAL,
911
toUniformCredentialOfferRequest,
1012
} from '@sphereon/oid4vci-common';
1113
import Debug from 'debug';
@@ -46,14 +48,13 @@ export class CredentialOfferClientV1_0_13 {
4648
...(clientId && { clientId }),
4749
...request,
4850
...(grants?.authorization_code?.issuer_state && { issuerState: grants.authorization_code.issuer_state }),
49-
...(grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.['pre-authorized_code'] && {
50-
preAuthorizedCode: grants['urn:ietf:params:oauth:grant-type:pre-authorized_code']['pre-authorized_code'],
51+
...(grants?.[PRE_AUTH_GRANT_LITERAL]?.[PRE_AUTH_CODE_LITERAL] && {
52+
preAuthorizedCode: grants[PRE_AUTH_GRANT_LITERAL][PRE_AUTH_CODE_LITERAL],
53+
}),
54+
userPinRequired: !!request.credential_offer?.grants?.[PRE_AUTH_GRANT_LITERAL]?.tx_code ?? false,
55+
...(request.credential_offer?.grants?.[PRE_AUTH_GRANT_LITERAL]?.tx_code && {
56+
txCode: request.credential_offer.grants[PRE_AUTH_GRANT_LITERAL].tx_code,
5157
}),
52-
userPinRequired: !!request.credential_offer?.grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.tx_code ?? false,
53-
...(request.credential_offer?.grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.tx_code &&
54-
{
55-
// txCode: request.credential_offer?.grants?.['urn:ietf:params:oauth:grant-type:pre-authorized_code']?.tx_code,
56-
}),
5758
};
5859
}
5960

packages/client/lib/__tests__/AccessTokenClient.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { AccessTokenRequest, AccessTokenResponse, GrantTypes, OpenIDResponse, WellKnownEndpoints } from '@sphereon/oid4vci-common';
1+
import {
2+
AccessTokenRequest,
3+
AccessTokenResponse,
4+
GrantTypes,
5+
OpenIDResponse,
6+
PRE_AUTH_CODE_LITERAL,
7+
WellKnownEndpoints,
8+
} from '@sphereon/oid4vci-common';
29
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
310
// @ts-ignore
411
import nock from 'nock';
@@ -48,7 +55,7 @@ describe('AccessTokenClient should', () => {
4855
pinMetadata: {
4956
isPinRequired: true,
5057
txCode: {
51-
length: accessTokenRequest['pre-authorized_code'].length,
58+
length: accessTokenRequest[PRE_AUTH_CODE_LITERAL].length,
5259
input_mode: 'numeric',
5360
},
5461
},

packages/client/lib/__tests__/MetadataClient.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getIssuerFromCredentialOfferPayload, WellKnownEndpoints } from '@sphereon/oid4vci-common';
1+
import { getIssuerFromCredentialOfferPayload, PRE_AUTH_GRANT_LITERAL, WellKnownEndpoints } from '@sphereon/oid4vci-common';
22
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
33
// @ts-ignore
44
import nock from 'nock';
@@ -241,7 +241,7 @@ describe.skip('Metadataclient with SpruceId should', () => {
241241
credential_endpoint: 'https://ngi-oidc4vci-test.spruceid.xyz/credential',
242242
token_endpoint: 'https://ngi-oidc4vci-test.spruceid.xyz/token',
243243
jwks_uri: 'https://ngi-oidc4vci-test.spruceid.xyz/jwks',
244-
grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],
244+
grant_types_supported: [PRE_AUTH_GRANT_LITERAL],
245245
credentials_supported: {
246246
OpenBadgeCredential: {
247247
formats: {
@@ -277,7 +277,7 @@ describe.skip('Metadataclient with SpruceId should', () => {
277277
credential_endpoint: 'https://ngi-oidc4vci-test.spruceid.xyz/credential',
278278
token_endpoint: 'https://ngi-oidc4vci-test.spruceid.xyz/token',
279279
jwks_uri: 'https://ngi-oidc4vci-test.spruceid.xyz/jwks',
280-
grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],
280+
grant_types_supported: [PRE_AUTH_GRANT_LITERAL],
281281
credentials_supported: {
282282
OpenBadgeCredential: {
283283
formats: {

packages/client/lib/__tests__/MetadataMocks.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuthzFlowType, CredentialOfferPayloadV1_0_13, CredentialOfferRequestWithBaseUrl } from '@sphereon/oid4vci-common';
1+
import { AuthzFlowType, CredentialOfferPayloadV1_0_13, CredentialOfferRequestWithBaseUrl, PRE_AUTH_GRANT_LITERAL } from '@sphereon/oid4vci-common';
22

33
export const IDENTIPROOF_ISSUER_URL = 'https://issuer.research.identiproof.io';
44
export const IDENTIPROOF_AS_URL = 'https://auth.research.identiproof.io';
@@ -48,6 +48,11 @@ export const INITIATION_TEST: CredentialOfferRequestWithBaseUrl = {
4848
scheme: 'openid-credential-offer',
4949
supportedFlows: [AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW],
5050
version: 1013,
51+
txCode: {
52+
description: 'Please provide the one-time code that was sent via e-mail',
53+
input_mode: 'numeric',
54+
length: 4,
55+
},
5156
userPinRequired: true, // Determined from above tx_code
5257
};
5358
export const INITIATION_TEST_V1_0_08: CredentialOfferRequestWithBaseUrl = {
@@ -84,7 +89,7 @@ export const IDENTIPROOF_AS_METADATA = {
8489
token_endpoint_auth_methods_supported: ['client_secret_basic', 'client_secret_post', 'client_secret_jwt', 'private_key_jwt'],
8590
jwks_uri: 'https://auth.research.identiproof.io/oauth2/jwks',
8691
response_types_supported: ['code'],
87-
grant_types_supported: ['authorization_code', 'urn:ietf:params:oauth:grant-type:pre-authorized_code', 'client_credentials', 'refresh_token'],
92+
grant_types_supported: ['authorization_code', PRE_AUTH_GRANT_LITERAL, 'client_credentials', 'refresh_token'],
8893
revocation_endpoint: 'https://auth.research.identiproof.io/oauth2/revoke',
8994
revocation_endpoint_auth_methods_supported: ['client_secret_basic', 'client_secret_post', 'client_secret_jwt', 'private_key_jwt'],
9095
introspection_endpoint: 'https://auth.research.identiproof.io/oauth2/introspect',
@@ -168,7 +173,7 @@ export const SPRUCE_OID4VCI_METADATA = {
168173
credential_endpoint: 'https://ngi-oidc4vci-test.spruceid.xyz/credential',
169174
token_endpoint: 'https://ngi-oidc4vci-test.spruceid.xyz/token',
170175
jwks_uri: 'https://ngi-oidc4vci-test.spruceid.xyz/jwks',
171-
grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],
176+
grant_types_supported: [PRE_AUTH_GRANT_LITERAL],
172177
credentials_supported: {
173178
OpenBadgeCredential: {
174179
formats: {
@@ -232,7 +237,7 @@ export const DANUBE_OIDC_METADATA = {
232237
],
233238
},
234239
code_challenge_methods_supported: ['plain', 'S256'],
235-
grant_types_supported: ['authorization_code', 'urn:ietf:params:oauth:grant-type:pre-authorized_code'],
240+
grant_types_supported: ['authorization_code', PRE_AUTH_GRANT_LITERAL],
236241
token_endpoint_auth_methods_supported: ['client_secret_post', 'client_secret_basic'],
237242
authorization_endpoint: 'https://oidc4vc.uniissuer.io/authorize',
238243
token_endpoint: 'https://oidc4vc.uniissuer.io/token',
@@ -245,7 +250,7 @@ export const WALT_OID4VCI_METADATA = {
245250
pushed_authorization_request_endpoint: 'https://jff.walt.id/issuer-api/oidc/par',
246251
issuer: 'https://jff.walt.id/issuer-api',
247252
jwks_uri: 'https://jff.walt.id/issuer-api/oidc',
248-
grant_types_supported: ['authorization_code', 'urn:ietf:params:oauth:grant-type:pre-authorized_code'],
253+
grant_types_supported: ['authorization_code', PRE_AUTH_GRANT_LITERAL],
249254
request_uri_parameter_supported: true,
250255
credentials_supported: {
251256
VerifiableDiploma: {

0 commit comments

Comments
 (0)