@eudiplo/sdk-core 1.14.0-main.fd4c0a7

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/README.md ADDED
@@ -0,0 +1,271 @@
1
+ # @eudiplo/sdk-core
2
+
3
+ Framework-agnostic EUDIPLO SDK for demos and integrations. Works with Node.js, browsers, React, Vue, vanilla JS, and any other JavaScript environment.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @eudiplo/sdk-core
9
+ # or
10
+ pnpm add @eudiplo/sdk-core
11
+ # or
12
+ yarn add @eudiplo/sdk-core
13
+ ```
14
+
15
+ ## Quick Start - The Simplest Way
16
+
17
+ ### One-liner for Age Verification
18
+
19
+ ```typescript
20
+ import { verifyAndWait } from '@eudiplo/sdk-core';
21
+
22
+ const session = await verifyAndWait({
23
+ baseUrl: 'https://eudiplo.example.com',
24
+ clientId: 'my-demo',
25
+ clientSecret: 'secret',
26
+ configId: 'age-over-18',
27
+ onUri: (uri) => showQRCode(uri), // Your QR code display function
28
+ onUpdate: (s) => console.log('Status:', s.status),
29
+ });
30
+
31
+ console.log('Verified!', session.credentials);
32
+ ```
33
+
34
+ ### Two-step Flow (More Control)
35
+
36
+ ```typescript
37
+ import { verify } from '@eudiplo/sdk-core';
38
+
39
+ // Step 1: Create the request
40
+ const { uri, sessionId, waitForCompletion } = await verify({
41
+ baseUrl: 'https://eudiplo.example.com',
42
+ clientId: 'my-demo',
43
+ clientSecret: 'secret',
44
+ configId: 'age-over-18',
45
+ });
46
+
47
+ // Step 2: Show QR code
48
+ showQRCode(uri);
49
+
50
+ // Step 3: Wait for user to scan and respond
51
+ const session = await waitForCompletion();
52
+ console.log('Verified credentials:', session.credentials);
53
+ ```
54
+
55
+ ### Credential Issuance
56
+
57
+ ```typescript
58
+ import { issue } from '@eudiplo/sdk-core';
59
+
60
+ const { uri, waitForCompletion } = await issue({
61
+ baseUrl: 'https://eudiplo.example.com',
62
+ clientId: 'my-demo',
63
+ clientSecret: 'secret',
64
+ credentialConfigurationIds: ['PID'],
65
+ claims: {
66
+ PID: { given_name: 'John', family_name: 'Doe', birthdate: '1990-01-15' },
67
+ },
68
+ });
69
+
70
+ showQRCode(uri);
71
+ await waitForCompletion();
72
+ ```
73
+
74
+ ## Full API
75
+
76
+ ### Factory Functions (Easiest)
77
+
78
+ | Function | Description |
79
+ | ------------------------ | ----------------------------------------------------------------------------------------- |
80
+ | `verify(options)` | Create a presentation request, returns `{ uri, sessionId, waitForCompletion, getStatus }` |
81
+ | `issue(options)` | Create an issuance offer, returns `{ uri, sessionId, waitForCompletion, getStatus }` |
82
+ | `verifyAndWait(options)` | One-liner: create request + wait for result |
83
+ | `issueAndWait(options)` | One-liner: create offer + wait for result |
84
+
85
+ ### Class-based API (More Control)
86
+
87
+ ```typescript
88
+ import { EudiploClient } from '@eudiplo/sdk-core';
89
+
90
+ const client = new EudiploClient({
91
+ baseUrl: 'https://eudiplo.example.com',
92
+ clientId: 'my-demo-client',
93
+ clientSecret: 'your-secret',
94
+ });
95
+
96
+ // Create a presentation request (e.g., for age verification)
97
+ const { uri, sessionId } = await client.createPresentationRequest({
98
+ configId: 'age-over-18',
99
+ });
100
+
101
+ console.log('Show this QR code:', uri);
102
+
103
+ // Wait for the user to scan and respond
104
+ const session = await client.waitForSession(sessionId, {
105
+ onUpdate: (s) => console.log('Status:', s.status),
106
+ });
107
+
108
+ console.log('Verified credentials:', session.credentials);
109
+ ```
110
+
111
+ ## API
112
+
113
+ ### `new EudiploClient(config)`
114
+
115
+ Create a new client instance.
116
+
117
+ ```typescript
118
+ const client = new EudiploClient({
119
+ baseUrl: 'https://eudiplo.example.com', // EUDIPLO server URL
120
+ clientId: 'my-client', // OAuth2 client ID
121
+ clientSecret: 'secret', // OAuth2 client secret
122
+ autoRefresh: true, // Auto-refresh tokens (default: true)
123
+ });
124
+ ```
125
+
126
+ ### `createPresentationRequest(options)`
127
+
128
+ Create a presentation request for credential verification.
129
+
130
+ ```typescript
131
+ const { uri, sessionId } = await client.createPresentationRequest({
132
+ configId: 'age-over-18', // Presentation config ID
133
+ responseType: 'uri', // 'uri' | 'qrcode' | 'dc-api'
134
+ redirectUri: 'https://...', // Optional redirect after completion
135
+ });
136
+ ```
137
+
138
+ ### `createIssuanceOffer(options)`
139
+
140
+ Create a credential issuance offer.
141
+
142
+ ```typescript
143
+ const { uri, sessionId } = await client.createIssuanceOffer({
144
+ credentialConfigurationIds: ['PID', 'mDL'],
145
+ claims: {
146
+ PID: { given_name: 'John', family_name: 'Doe' },
147
+ mDL: { driving_privileges: [...] }
148
+ },
149
+ flow: 'pre_authorized_code', // or 'authorization_code'
150
+ txCode: '1234' // Optional transaction code
151
+ });
152
+ ```
153
+
154
+ ### `getSession(sessionId)`
155
+
156
+ Get the current state of a session.
157
+
158
+ ```typescript
159
+ const session = await client.getSession(sessionId);
160
+ console.log(session.status); // 'active' | 'fetched' | 'completed' | 'expired' | 'failed'
161
+ ```
162
+
163
+ ### `waitForSession(sessionId, options)`
164
+
165
+ Poll until a session completes or fails.
166
+
167
+ ```typescript
168
+ const session = await client.waitForSession(sessionId, {
169
+ interval: 1000, // Poll every 1 second
170
+ timeout: 60000, // Timeout after 60 seconds
171
+ signal: abortController.signal, // Optional abort signal
172
+ onUpdate: (session) => {
173
+ console.log('Status:', session.status);
174
+ },
175
+ });
176
+ ```
177
+
178
+ ## Examples
179
+
180
+ ### Age Verification in a Web Shop
181
+
182
+ ```typescript
183
+ import { EudiploClient } from '@eudiplo/sdk-core';
184
+
185
+ const client = new EudiploClient({
186
+ baseUrl: process.env.EUDIPLO_URL,
187
+ clientId: process.env.EUDIPLO_CLIENT_ID,
188
+ clientSecret: process.env.EUDIPLO_CLIENT_SECRET,
189
+ });
190
+
191
+ // Express.js route handler
192
+ app.post('/api/verify-age', async (req, res) => {
193
+ const { uri, sessionId } = await client.createPresentationRequest({
194
+ configId: 'age-over-18',
195
+ redirectUri: `${req.headers.origin}/checkout`,
196
+ });
197
+
198
+ res.json({ qrCodeUri: uri, sessionId });
199
+ });
200
+
201
+ app.get('/api/verify-age/:sessionId', async (req, res) => {
202
+ const session = await client.getSession(req.params.sessionId);
203
+ res.json({
204
+ status: session.status,
205
+ verified: session.status === 'completed',
206
+ });
207
+ });
208
+ ```
209
+
210
+ ### React Hook Example
211
+
212
+ ```typescript
213
+ import { useState, useEffect } from 'react';
214
+ import { EudiploClient } from '@eudiplo/sdk-core';
215
+
216
+ const client = new EudiploClient({...});
217
+
218
+ function useAgeVerification(configId: string) {
219
+ const [uri, setUri] = useState<string>();
220
+ const [status, setStatus] = useState<string>('idle');
221
+ const [verified, setVerified] = useState(false);
222
+
223
+ const startVerification = async () => {
224
+ setStatus('pending');
225
+ const { uri, sessionId } = await client.createPresentationRequest({ configId });
226
+ setUri(uri);
227
+
228
+ try {
229
+ const session = await client.waitForSession(sessionId, {
230
+ onUpdate: (s) => setStatus(s.status)
231
+ });
232
+ setVerified(true);
233
+ setStatus('completed');
234
+ } catch (e) {
235
+ setStatus('failed');
236
+ }
237
+ };
238
+
239
+ return { uri, status, verified, startVerification };
240
+ }
241
+ ```
242
+
243
+ ## Advanced: Direct API Access
244
+
245
+ For advanced use cases, you can access the generated API functions directly:
246
+
247
+ ```typescript
248
+ import {
249
+ client,
250
+ sessionControllerGetAllSessions,
251
+ credentialConfigControllerGetConfigs,
252
+ } from '@eudiplo/sdk-core/api';
253
+
254
+ // Configure the client
255
+ client.setConfig({
256
+ baseUrl: 'https://eudiplo.example.com',
257
+ headers: { Authorization: 'Bearer your-token' },
258
+ });
259
+
260
+ // Use any API endpoint
261
+ const configs = await credentialConfigControllerGetConfigs({});
262
+ ```
263
+
264
+ ## Requirements
265
+
266
+ - Node.js 20+ (uses native `fetch`)
267
+ - For older environments, use a `fetch` polyfill
268
+
269
+ ## License
270
+
271
+ Apache-2.0