@sphereon/oid4vci-client 0.12.1-next.2 → 0.12.1-next.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AccessTokenClient.d.ts.map +1 -1
- package/dist/AccessTokenClient.js +7 -5
- package/dist/AccessTokenClient.js.map +1 -1
- package/dist/AccessTokenClientV1_0_11.d.ts.map +1 -1
- package/dist/AccessTokenClientV1_0_11.js +7 -5
- package/dist/AccessTokenClientV1_0_11.js.map +1 -1
- package/dist/CredentialRequestClient.d.ts +3 -2
- package/dist/CredentialRequestClient.d.ts.map +1 -1
- package/dist/CredentialRequestClient.js.map +1 -1
- package/dist/CredentialRequestClientBuilder.d.ts +7 -15
- package/dist/CredentialRequestClientBuilder.d.ts.map +1 -1
- package/dist/CredentialRequestClientBuilder.js +79 -55
- package/dist/CredentialRequestClientBuilder.js.map +1 -1
- package/dist/CredentialRequestClientBuilderV1_0_13.d.ts +51 -0
- package/dist/CredentialRequestClientBuilderV1_0_13.d.ts.map +1 -0
- package/dist/CredentialRequestClientBuilderV1_0_13.js +130 -0
- package/dist/CredentialRequestClientBuilderV1_0_13.js.map +1 -0
- package/dist/OpenID4VCIClient.d.ts +3 -1
- package/dist/OpenID4VCIClient.d.ts.map +1 -1
- package/dist/OpenID4VCIClient.js +31 -16
- package/dist/OpenID4VCIClient.js.map +1 -1
- package/dist/OpenID4VCIClientV1_0_11.d.ts +3 -2
- package/dist/OpenID4VCIClientV1_0_11.d.ts.map +1 -1
- package/dist/OpenID4VCIClientV1_0_11.js +26 -10
- package/dist/OpenID4VCIClientV1_0_11.js.map +1 -1
- package/dist/OpenID4VCIClientV1_0_13.d.ts +2 -1
- package/dist/OpenID4VCIClientV1_0_13.d.ts.map +1 -1
- package/dist/OpenID4VCIClientV1_0_13.js +26 -12
- package/dist/OpenID4VCIClientV1_0_13.js.map +1 -1
- package/dist/functions/AccessTokenUtil.d.ts +5 -0
- package/dist/functions/AccessTokenUtil.d.ts.map +1 -0
- package/dist/functions/AccessTokenUtil.js +55 -0
- package/dist/functions/AccessTokenUtil.js.map +1 -0
- package/dist/functions/index.d.ts +2 -0
- package/dist/functions/index.d.ts.map +1 -1
- package/dist/functions/index.js +2 -0
- package/dist/functions/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/lib/AccessTokenClient.ts +5 -4
- package/lib/AccessTokenClientV1_0_11.ts +6 -3
- package/lib/CredentialRequestClient.ts +3 -2
- package/lib/CredentialRequestClientBuilder.ts +98 -67
- package/lib/CredentialRequestClientBuilderV1_0_13.ts +173 -0
- package/lib/OpenID4VCIClient.ts +33 -6
- package/lib/OpenID4VCIClientV1_0_11.ts +32 -5
- package/lib/OpenID4VCIClientV1_0_13.ts +30 -5
- package/lib/__tests__/CredentialRequestClient.spec.ts +8 -13
- package/lib/__tests__/CredentialRequestClientBuilder.spec.ts +40 -2
- package/lib/__tests__/CredentialRequestClientV1_0_11.spec.ts +96 -0
- package/lib/__tests__/IT.spec.ts +148 -111
- package/lib/__tests__/MetadataMocks.ts +35 -0
- package/lib/__tests__/ProofOfPossessionBuilder.spec.ts +85 -0
- package/lib/__tests__/SdJwt.spec.ts +103 -0
- package/lib/functions/AccessTokenUtil.ts +45 -0
- package/lib/functions/index.ts +2 -0
- package/lib/index.ts +1 -0
- package/package.json +3 -3
|
@@ -166,4 +166,107 @@ describe('sd-jwt vc', () => {
|
|
|
166
166
|
},
|
|
167
167
|
UNIT_TEST_TIMEOUT,
|
|
168
168
|
);
|
|
169
|
+
|
|
170
|
+
it(
|
|
171
|
+
'succeed with a full flow without did',
|
|
172
|
+
async () => {
|
|
173
|
+
const offerUri = await vcIssuer.createCredentialOfferURI({
|
|
174
|
+
grants: {
|
|
175
|
+
'urn:ietf:params:oauth:grant-type:pre-authorized_code': {
|
|
176
|
+
tx_code: {
|
|
177
|
+
input_mode: 'text',
|
|
178
|
+
length: 3,
|
|
179
|
+
},
|
|
180
|
+
'pre-authorized_code': '123',
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
credential_configuration_ids: ['SdJwtCredential'],
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
nock(vcIssuer.issuerMetadata.credential_issuer).get('/.well-known/openid-credential-issuer').reply(200, JSON.stringify(issuerMetadata));
|
|
187
|
+
nock(vcIssuer.issuerMetadata.credential_issuer).get('/.well-known/openid-configuration').reply(404);
|
|
188
|
+
nock(vcIssuer.issuerMetadata.credential_issuer).get('/.well-known/oauth-authorization-server').reply(404);
|
|
189
|
+
|
|
190
|
+
expect(offerUri.uri).toEqual(
|
|
191
|
+
'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',
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
const client = await OpenID4VCIClientV1_0_13.fromURI({
|
|
195
|
+
uri: offerUri.uri,
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
expect(client.credentialOffer?.credential_offer).toEqual({
|
|
199
|
+
credential_issuer: 'https://example.com',
|
|
200
|
+
credential_configuration_ids: ['SdJwtCredential'],
|
|
201
|
+
grants: {
|
|
202
|
+
'urn:ietf:params:oauth:grant-type:pre-authorized_code': {
|
|
203
|
+
'pre-authorized_code': '123',
|
|
204
|
+
tx_code: {
|
|
205
|
+
input_mode: 'text',
|
|
206
|
+
length: 3,
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const supported = client.getCredentialsSupported('vc+sd-jwt');
|
|
213
|
+
expect(supported).toEqual({ SdJwtCredentialId: { format: 'vc+sd-jwt', id: 'SdJwtCredentialId', vct: 'SdJwtCredentialId' } });
|
|
214
|
+
|
|
215
|
+
const offered = supported['SdJwtCredentialId'] as CredentialSupportedSdJwtVc;
|
|
216
|
+
|
|
217
|
+
nock(issuerMetadata.token_endpoint as string)
|
|
218
|
+
.post('/')
|
|
219
|
+
.reply(200, async (_, body: string) => {
|
|
220
|
+
const parsedBody = Object.fromEntries(body.split('&').map((x) => x.split('=')));
|
|
221
|
+
return createAccessTokenResponse(parsedBody as AccessTokenRequest, {
|
|
222
|
+
credentialOfferSessions: vcIssuer.credentialOfferSessions,
|
|
223
|
+
accessTokenIssuer: 'https://issuer.example.com',
|
|
224
|
+
cNonces: vcIssuer.cNonces,
|
|
225
|
+
cNonce: 'a-c-nonce',
|
|
226
|
+
accessTokenSignerCallback: async () => 'ey.val.ue',
|
|
227
|
+
tokenExpiresIn: 500,
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
await client.acquireAccessToken({ pin: '123' });
|
|
232
|
+
nock(issuerMetadata.credential_endpoint as string)
|
|
233
|
+
.post('/')
|
|
234
|
+
.reply(200, async (_, body) =>
|
|
235
|
+
vcIssuer.issueCredential({
|
|
236
|
+
credentialRequest: { ...(body as CredentialRequestV1_0_13), credential_identifier: offered.vct },
|
|
237
|
+
credential: {
|
|
238
|
+
vct: 'Hello',
|
|
239
|
+
iss: 'example.com',
|
|
240
|
+
iat: 123,
|
|
241
|
+
// Defines what can be disclosed (optional)
|
|
242
|
+
__disclosureFrame: {
|
|
243
|
+
name: true,
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
newCNonce: 'new-c-nonce',
|
|
247
|
+
}),
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
const credentials = await client.acquireCredentials({
|
|
251
|
+
credentialIdentifier: offered.vct,
|
|
252
|
+
// format: 'vc+sd-jwt',
|
|
253
|
+
alg,
|
|
254
|
+
jwk,
|
|
255
|
+
proofCallbacks: {
|
|
256
|
+
// When using sd-jwt for real, this jwt should include a jwk
|
|
257
|
+
signCallback: async () => 'ey.ja.ja',
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
expect(credentials).toEqual({
|
|
262
|
+
notification_id: expect.any(String),
|
|
263
|
+
access_token: 'ey.val.ue',
|
|
264
|
+
c_nonce: 'new-c-nonce',
|
|
265
|
+
c_nonce_expires_in: 300,
|
|
266
|
+
credential: 'sd-jwt',
|
|
267
|
+
// format: 'vc+sd-jwt',
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
UNIT_TEST_TIMEOUT,
|
|
271
|
+
);
|
|
169
272
|
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { AccessTokenRequest, AccessTokenRequestOpts, Jwt, OpenId4VCIVersion } from '@sphereon/oid4vci-common';
|
|
2
|
+
import { v4 } from 'uuid';
|
|
3
|
+
|
|
4
|
+
import { ProofOfPossessionBuilder } from '../ProofOfPossessionBuilder';
|
|
5
|
+
|
|
6
|
+
export const createJwtBearerClientAssertion = async (
|
|
7
|
+
request: Partial<AccessTokenRequest>,
|
|
8
|
+
opts: AccessTokenRequestOpts & {
|
|
9
|
+
version?: OpenId4VCIVersion;
|
|
10
|
+
},
|
|
11
|
+
): Promise<void> => {
|
|
12
|
+
const { asOpts } = opts;
|
|
13
|
+
if (asOpts?.clientOpts?.clientAssertionType === 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer') {
|
|
14
|
+
if (!request.client_id) {
|
|
15
|
+
throw Error(`Not client_id supplied, but client-assertion jwt-bearer requested.`);
|
|
16
|
+
} else if (!asOpts.clientOpts.kid) {
|
|
17
|
+
throw Error(`No kid supplied, but client-assertion jwt-bearer requested.`);
|
|
18
|
+
} else if (!asOpts.clientOpts.signCallbacks) {
|
|
19
|
+
throw Error(`No sign callback supplied, but client-assertion jwt-bearer requested.`);
|
|
20
|
+
}
|
|
21
|
+
const jwt: Jwt = {
|
|
22
|
+
header: {
|
|
23
|
+
typ: 'JWT',
|
|
24
|
+
kid: asOpts.clientOpts.kid,
|
|
25
|
+
alg: asOpts.clientOpts.alg ?? 'ES256',
|
|
26
|
+
},
|
|
27
|
+
payload: {
|
|
28
|
+
iss: request.client_id,
|
|
29
|
+
sub: request.client_id,
|
|
30
|
+
aud: opts.credentialIssuer,
|
|
31
|
+
jti: v4(),
|
|
32
|
+
exp: Date.now() / 1000 + 60,
|
|
33
|
+
iat: Date.now() / 1000 - 60,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const pop = await ProofOfPossessionBuilder.fromJwt({
|
|
37
|
+
jwt,
|
|
38
|
+
callbacks: asOpts.clientOpts.signCallbacks,
|
|
39
|
+
version: opts.version ?? OpenId4VCIVersion.VER_1_0_13,
|
|
40
|
+
mode: 'jwt',
|
|
41
|
+
}).build();
|
|
42
|
+
request.client_assertion_type = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer';
|
|
43
|
+
request.client_assertion = pop.jwt;
|
|
44
|
+
}
|
|
45
|
+
};
|
package/lib/functions/index.ts
CHANGED
package/lib/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from './CredentialOfferClientV1_0_11';
|
|
|
13
13
|
export * from './CredentialOfferClientV1_0_13';
|
|
14
14
|
export * from './CredentialRequestClientV1_0_11';
|
|
15
15
|
export * from './CredentialRequestClientBuilder';
|
|
16
|
+
export * from './CredentialRequestClientBuilderV1_0_13';
|
|
16
17
|
export * from './CredentialRequestClientBuilderV1_0_11';
|
|
17
18
|
export * from './functions';
|
|
18
19
|
export * from './MetadataClient';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/oid4vci-client",
|
|
3
|
-
"version": "0.12.1-next.
|
|
3
|
+
"version": "0.12.1-next.22+2759750",
|
|
4
4
|
"description": "OpenID for Verifiable Credential Issuance (OpenID4VCI) client",
|
|
5
5
|
"source": "lib/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"build": "tsc"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@sphereon/oid4vci-common": "0.12.1-next.
|
|
18
|
+
"@sphereon/oid4vci-common": "0.12.1-next.22+2759750",
|
|
19
19
|
"@sphereon/ssi-types": "0.25.1-unstable.87",
|
|
20
20
|
"cross-fetch": "^3.1.8",
|
|
21
21
|
"debug": "^4.3.4"
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"OIDC4VCI",
|
|
70
70
|
"OID4VCI"
|
|
71
71
|
],
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "2759750708d523a023b89db337a148299d2abc6d"
|
|
73
73
|
}
|