@eudiplo/sdk-core 1.14.0-main.1b9bbd4 → 1.14.0-main.256e1f0

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 CHANGED
@@ -82,6 +82,156 @@ await waitForCompletion();
82
82
  | `verifyAndWait(options)` | One-liner: create request + wait for result |
83
83
  | `issueAndWait(options)` | One-liner: create offer + wait for result |
84
84
 
85
+ ### Digital Credentials API (Browser Native)
86
+
87
+ The SDK includes utilities for the [Digital Credentials API](https://wicg.github.io/digital-credentials/), enabling browser-native credential presentation without QR codes.
88
+
89
+ ```typescript
90
+ import { isDcApiAvailable, verifyWithDcApi } from '@eudiplo/sdk-core';
91
+
92
+ // Check if browser supports DC API
93
+ if (isDcApiAvailable()) {
94
+ const result = await verifyWithDcApi({
95
+ baseUrl: 'https://eudiplo.example.com',
96
+ clientId: 'my-demo',
97
+ clientSecret: 'secret',
98
+ configId: 'age-over-18',
99
+ });
100
+
101
+ console.log('Verified!', result.session.credentials);
102
+ } else {
103
+ // Fall back to QR code flow
104
+ const session = await verifyAndWait({...});
105
+ }
106
+ ```
107
+
108
+ #### DC API Functions
109
+
110
+ | Function | Description |
111
+ | ---------------------- | --------------------------------------------------- |
112
+ | `isDcApiAvailable()` | Check if browser supports Digital Credentials API |
113
+ | `verifyWithDcApi()` | Complete verification flow using browser-native API |
114
+ | `createDcApiRequest()` | Create a `DigitalCredentialRequestOptions` object |
115
+
116
+ #### Lower-level DC API Usage
117
+
118
+ ```typescript
119
+ import { createDcApiRequest, EudiploClient } from '@eudiplo/sdk-core';
120
+
121
+ const client = new EudiploClient({...});
122
+
123
+ // Create presentation request
124
+ const { uri, sessionId } = await client.createPresentationRequest({
125
+ configId: 'age-over-18',
126
+ responseType: 'dc-api',
127
+ });
128
+
129
+ // Create the browser request object
130
+ const request = createDcApiRequest(uri);
131
+
132
+ // Call the browser API directly
133
+ const credential = await navigator.credentials.get(request);
134
+
135
+ // Submit the response and get verified session
136
+ const session = await client.submitDcApiResponse(sessionId, credential);
137
+ ```
138
+
139
+ #### Secure Server/Client Deployment (Recommended for Production)
140
+
141
+ When deploying to production, you should **never expose your client credentials to the browser**. The SDK provides helper functions to split the DC API flow between your server (where credentials are safe) and the browser (where the DC API runs).
142
+
143
+ **Server-side Functions:**
144
+ | Function | Description |
145
+ | ---------------------- | --------------------------------------------------- |
146
+ | `createDcApiRequestForBrowser()` | Create request on server, return safe data for browser |
147
+ | `submitDcApiWalletResponse()` | Submit wallet response to EUDIPLO from server |
148
+
149
+ **Browser-side Functions:**
150
+ | Function | Description |
151
+ | ---------------------- | --------------------------------------------------- |
152
+ | `callDcApi()` | Call the native DC API with a request from your server |
153
+
154
+ ##### Example: Express.js Backend + Browser Frontend
155
+
156
+ **Server (Express.js / Next.js API route):**
157
+
158
+ ```typescript
159
+ import {
160
+ createDcApiRequestForBrowser,
161
+ submitDcApiWalletResponse,
162
+ } from '@eudiplo/sdk-core';
163
+
164
+ // POST /api/start-verification
165
+ app.post('/api/start-verification', async (req, res) => {
166
+ const requestData = await createDcApiRequestForBrowser({
167
+ baseUrl: process.env.EUDIPLO_URL,
168
+ clientId: process.env.EUDIPLO_CLIENT_ID, // ✅ Safe on server
169
+ clientSecret: process.env.EUDIPLO_SECRET, // ✅ Safe on server
170
+ configId: 'age-over-18',
171
+ });
172
+
173
+ // Only safe data is sent to browser (no secrets)
174
+ res.json(requestData);
175
+ });
176
+
177
+ // POST /api/complete-verification
178
+ app.post('/api/complete-verification', async (req, res) => {
179
+ const { responseUri, walletResponse } = req.body;
180
+
181
+ const result = await submitDcApiWalletResponse({
182
+ responseUri,
183
+ walletResponse,
184
+ sendResponse: true, // Get verified claims back
185
+ });
186
+
187
+ // result.credentials contains the verified data
188
+ res.json(result);
189
+ });
190
+ ```
191
+
192
+ **Browser (React / vanilla JS):**
193
+
194
+ ```typescript
195
+ import { callDcApi, isDcApiAvailable } from '@eudiplo/sdk-core';
196
+
197
+ async function verifyAge() {
198
+ // 1. Get the request from your server (credentials stay on server)
199
+ const requestData = await fetch('/api/start-verification', {
200
+ method: 'POST',
201
+ }).then((r) => r.json());
202
+
203
+ // 2. Check DC API support and call it locally
204
+ if (!isDcApiAvailable()) {
205
+ throw new Error('Digital Credentials API not supported');
206
+ }
207
+
208
+ const walletResponse = await callDcApi(requestData.requestObject);
209
+
210
+ // 3. Send the wallet response back to your server for verification
211
+ const result = await fetch('/api/complete-verification', {
212
+ method: 'POST',
213
+ headers: { 'Content-Type': 'application/json' },
214
+ body: JSON.stringify({
215
+ responseUri: requestData.responseUri,
216
+ walletResponse,
217
+ }),
218
+ }).then((r) => r.json());
219
+
220
+ console.log('Verified!', result.credentials);
221
+ return result;
222
+ }
223
+ ```
224
+
225
+ **What stays where:**
226
+
227
+ | Data | Location | Safe to expose? |
228
+ |------|----------|-----------------|
229
+ | `clientId` / `clientSecret` | Server only | ❌ Never expose |
230
+ | `requestObject` (signed JWT) | Server → Browser | ✅ Yes |
231
+ | `responseUri` | Server → Browser | ✅ Yes |
232
+ | Wallet response (encrypted VP) | Browser → Server | ✅ Yes |
233
+ | Verified credentials | Server only | Depends on use case |
234
+
85
235
  ### Class-based API (More Control)
86
236
 
87
237
  ```typescript
@@ -0,0 +1,5 @@
1
+ import { b as Config, C as Client } from '../../types.gen-DDunhhsd.mjs';
2
+
3
+ declare const createClient: (config?: Config) => Client;
4
+
5
+ export { createClient };
@@ -0,0 +1,5 @@
1
+ import { b as Config, C as Client } from '../../types.gen-DDunhhsd.js';
2
+
3
+ declare const createClient: (config?: Config) => Client;
4
+
5
+ export { createClient };