@sphereon/oid4vci-client 0.7.4-unstable.8 → 0.8.2-next.4

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.
@@ -20,7 +20,7 @@ const jwk: JWK = {
20
20
  // priv hex: 913466d1a38d1d8c0d3c0fb0fc3b633075085a31372bbd2a8022215a88d9d1e5
21
21
  const did = `did:key:z6Mki5ZwZKN1dBQprfJTikUvkDxrHijiiQngkWviMF5gw2Hv`;
22
22
  const kid = `${did}#z6Mki5ZwZKN1dBQprfJTikUvkDxrHijiiQngkWviMF5gw2Hv`;
23
- describe('OID4VCI-Client using Mattr issuer should', () => {
23
+ describe.skip('OID4VCI-Client using Mattr issuer should', () => {
24
24
  async function test(format: 'ldp_vc' | 'jwt_vc_json') {
25
25
  const offer = await getCredentialOffer(format);
26
26
  const client = await OpenID4VCIClient.fromURI({
@@ -0,0 +1,169 @@
1
+ import * as crypto from 'crypto';
2
+
3
+ import { Alg, Jwt, ProofOfPossessionCallbacks } from '@sphereon/oid4vci-common';
4
+ import { CredentialMapper } from '@sphereon/ssi-types';
5
+ import * as didts from '@transmute/did-key.js';
6
+ import { fetch } from 'cross-fetch';
7
+ import debug from 'debug';
8
+ import { importJWK, JWK, SignJWT } from 'jose';
9
+ import { v4 } from 'uuid';
10
+
11
+ import { OpenID4VCIClient } from '..';
12
+
13
+ export const UNIT_TEST_TIMEOUT = 30000;
14
+
15
+ const ISSUER_URL = 'https://ssi.sphereon.com/pf3';
16
+
17
+ const jwk: JWK = {
18
+ crv: 'Ed25519',
19
+ d: 'kTRm0aONHYwNPA-w_DtjMHUIWjE3K70qgCIhWojZ0eU',
20
+ x: 'NeA0d8sp86xRh3DczU4m5wPNIbl0HCSwOBcMN3sNmdk',
21
+ kty: 'OKP',
22
+ };
23
+
24
+ // pub hex: 35e03477cb29f3ac518770dccd4e26e703cd21b9741c24b038170c377b0d99d9
25
+ // priv hex: 913466d1a38d1d8c0d3c0fb0fc3b633075085a31372bbd2a8022215a88d9d1e5
26
+ const did = `did:key:z6Mki5ZwZKN1dBQprfJTikUvkDxrHijiiQngkWviMF5gw2Hv`;
27
+ const kid = `${did}#z6Mki5ZwZKN1dBQprfJTikUvkDxrHijiiQngkWviMF5gw2Hv`;
28
+ describe('OID4VCI-Client using Sphereon issuer should', () => {
29
+ async function test(format: 'ldp_vc' | 'jwt_vc_json') {
30
+ debug.enable('*');
31
+ const offer = await getCredentialOffer(format);
32
+ const client = await OpenID4VCIClient.fromURI({
33
+ uri: offer.uri,
34
+ kid,
35
+ alg: Alg.EdDSA,
36
+ });
37
+ expect(client.credentialOffer).toBeDefined();
38
+ expect(client.endpointMetadata).toBeDefined();
39
+ expect(client.getCredentialEndpoint()).toEqual(`${ISSUER_URL}/credentials`);
40
+ expect(client.getAccessTokenEndpoint()).toEqual(`${ISSUER_URL}/token`);
41
+
42
+ const accessToken = await client.acquireAccessToken();
43
+ // console.log(accessToken);
44
+ expect(accessToken).toMatchObject({
45
+ expires_in: 300,
46
+ // scope: 'GuestCredential',
47
+ token_type: 'bearer',
48
+ });
49
+
50
+ const credentialResponse = await client.acquireCredentials({
51
+ credentialTypes: 'GuestCredential',
52
+ format,
53
+ proofCallbacks: {
54
+ signCallback: proofOfPossessionCallbackFunction,
55
+ },
56
+ });
57
+ expect(credentialResponse.credential).toBeDefined();
58
+ const wrappedVC = CredentialMapper.toWrappedVerifiableCredential(credentialResponse.credential!);
59
+ expect(format.startsWith(wrappedVC.format)).toEqual(true);
60
+ }
61
+
62
+ xit(
63
+ 'succeed in a full flow with the client using OpenID4VCI version 11 and ldp_vc',
64
+ async () => {
65
+ await test('ldp_vc');
66
+ },
67
+ UNIT_TEST_TIMEOUT,
68
+ );
69
+ it(
70
+ 'succeed in a full flow with the client using OpenID4VCI version 11 and jwt_vc_json',
71
+ async () => {
72
+ await test('jwt_vc_json');
73
+ },
74
+ UNIT_TEST_TIMEOUT,
75
+ );
76
+ });
77
+
78
+ interface CreateCredentialOfferResponse {
79
+ uri: string;
80
+ userPinRequired: boolean;
81
+ }
82
+
83
+ async function getCredentialOffer(format: 'ldp_vc' | 'jwt_vc_json'): Promise<CreateCredentialOfferResponse> {
84
+ const credentialOffer = await fetch('https://ssi.sphereon.com/pf3/webapp/credential-offers', {
85
+ method: 'post',
86
+ headers: {
87
+ Accept: 'application/json',
88
+ 'Content-Type': 'application/json',
89
+ },
90
+
91
+ //make sure to serialize your JSON body
92
+ body: JSON.stringify({
93
+ credentials: ['GuestCredential'],
94
+ grants: {
95
+ 'urn:ietf:params:oauth:grant-type:pre-authorized_code': {
96
+ 'pre-authorized_code': v4().substring(0, 10),
97
+ user_pin_required: false,
98
+ },
99
+ },
100
+ credentialDataSupplierInput: { firstName: 'Hello', lastName: 'World', email: 'hello.world@example.com' },
101
+ }),
102
+ });
103
+
104
+ return (await credentialOffer.json()) as CreateCredentialOfferResponse;
105
+ }
106
+
107
+ async function proofOfPossessionCallbackFunction(args: Jwt, kid?: string): Promise<string> {
108
+ const importedJwk = await importJWK(jwk, 'EdDSA');
109
+ return await new SignJWT({ ...args.payload })
110
+ .setProtectedHeader({ ...args.header, kid: kid! })
111
+ .setIssuer(kid!)
112
+ .setIssuedAt()
113
+ .setExpirationTime('2h')
114
+ .sign(importedJwk);
115
+ }
116
+
117
+ describe('ismapolis bug report #63, https://github.com/Sphereon-Opensource/OID4VC-demo/issues/63, should', () => {
118
+ it('work as expected provided a correct JWT is supplied', async () => {
119
+ debug.enable('*');
120
+ const { uri } = await getCredentialOffer('jwt_vc_json');
121
+ const client = await OpenID4VCIClient.fromURI({ uri: uri, clientId: 'test-clientID' });
122
+ const metadata = await client.retrieveServerMetadata();
123
+ console.log(JSON.stringify(metadata));
124
+
125
+ //2. Adquire acces token from authorization server endpoint
126
+
127
+ const accessToken = await client.acquireAccessToken({});
128
+ console.log(`Access token: ${JSON.stringify(accessToken)}`);
129
+
130
+ //3. Create DID needed for later proof of possession
131
+ const { keys, didDocument } = await didts.jwk.generate({
132
+ type: 'secp256k1', // 'P-256', 'P-384', 'X25519', 'secp256k1'
133
+ accept: 'application/did+json',
134
+ secureRandom: () => {
135
+ return crypto.randomBytes(32);
136
+ },
137
+ });
138
+ const edPrivateKey = await importJWK(keys[0].privateKeyJwk);
139
+
140
+ async function signCallback(args: Jwt, kid?: string): Promise<string> {
141
+ if (!args.payload.aud) {
142
+ throw Error('aud required');
143
+ } else if (!kid) {
144
+ throw Error('kid required');
145
+ }
146
+ return await new SignJWT({ ...args.payload })
147
+ .setProtectedHeader({ alg: args.header.alg, kid, typ: 'openid4vci-proof+jwt' })
148
+ .setIssuedAt()
149
+ .setIssuer(kid)
150
+ .setAudience(args.payload.aud)
151
+ .setExpirationTime('2h')
152
+ .sign(edPrivateKey);
153
+ }
154
+
155
+ const callbacks: ProofOfPossessionCallbacks<never> = {
156
+ signCallback: signCallback,
157
+ };
158
+
159
+ const credentialResponse = await client.acquireCredentials({
160
+ credentialTypes: 'GuestCredential',
161
+ proofCallbacks: callbacks,
162
+ format: 'jwt_vc_json',
163
+ alg: Alg.ES256K,
164
+ kid: didDocument.verificationMethod[0].id,
165
+ jti: v4(),
166
+ });
167
+ console.log(JSON.stringify(credentialResponse.credential));
168
+ });
169
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/oid4vci-client",
3
- "version": "0.7.4-unstable.8+1114e83",
3
+ "version": "0.8.2-next.4+07286fa",
4
4
  "description": "OpenID for Verifiable Credential Issuance (OpenID4VCI) client",
5
5
  "source": "lib/index.ts",
6
6
  "main": "dist/index.js",
@@ -15,14 +15,16 @@
15
15
  "build": "tsc"
16
16
  },
17
17
  "dependencies": {
18
- "@sphereon/oid4vci-common": "0.7.4-unstable.8+1114e83",
18
+ "@sphereon/oid4vci-common": "0.8.2-next.4+07286fa",
19
19
  "@sphereon/ssi-types": "0.17.2",
20
20
  "cross-fetch": "^3.1.8",
21
21
  "debug": "^4.3.4"
22
22
  },
23
23
  "devDependencies": {
24
+ "@transmute/did-key.js": "^0.3.0-unstable.10",
24
25
  "@types/jest": "^29.5.3",
25
26
  "@types/node": "^18.17.4",
27
+ "@types/uuid": "^9.0.6",
26
28
  "@typescript-eslint/eslint-plugin": "^5.62.0",
27
29
  "@typescript-eslint/parser": "^5.62.0",
28
30
  "codecov": "^3.8.3",
@@ -40,7 +42,8 @@
40
42
  "ts-jest": "^29.1.1",
41
43
  "ts-node": "^10.9.1",
42
44
  "typescript": "4.9.5",
43
- "uint8arrays": "3.1.1"
45
+ "uint8arrays": "3.1.1",
46
+ "uuid": "^9.0.1"
44
47
  },
45
48
  "engines": {
46
49
  "node": ">=16"
@@ -64,5 +67,5 @@
64
67
  "OIDC4VCI",
65
68
  "OID4VCI"
66
69
  ],
67
- "gitHead": "1114e8308ee421aeb08fda65d1bc311182a2f95a"
70
+ "gitHead": "07286fa2c4963e0edfacd8eb85773b650e769d49"
68
71
  }