@eudiplo/sdk-core 1.14.0-main.879de64 → 1.14.0-main.8a62e9c

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
@@ -12,227 +12,102 @@ pnpm add @eudiplo/sdk-core
12
12
  yarn add @eudiplo/sdk-core
13
13
  ```
14
14
 
15
- ## Quick Start - The Simplest Way
16
-
17
- ### One-liner for Age Verification
15
+ ## Quick Start
18
16
 
19
17
  ```typescript
20
- import { verifyAndWait } from '@eudiplo/sdk-core';
18
+ import { EudiploClient } from '@eudiplo/sdk-core';
21
19
 
22
- const session = await verifyAndWait({
20
+ const client = new EudiploClient({
23
21
  baseUrl: 'https://eudiplo.example.com',
24
22
  clientId: 'my-demo',
25
23
  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
24
  });
30
25
 
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',
26
+ // Verification (QR flow)
27
+ const verifyOffer = await client.createPresentationRequest({
44
28
  configId: 'age-over-18',
45
29
  });
30
+ showQRCode(verifyOffer.uri);
31
+ const verifiedSession = await client.waitForSession(verifyOffer.sessionId);
46
32
 
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',
33
+ // Issuance (QR flow)
34
+ const issuanceOffer = await client.createIssuanceOffer({
64
35
  credentialConfigurationIds: ['PID'],
65
36
  claims: {
66
37
  PID: { given_name: 'John', family_name: 'Doe', birthdate: '1990-01-15' },
67
38
  },
68
39
  });
69
-
70
- showQRCode(uri);
71
- await waitForCompletion();
40
+ showQRCode(issuanceOffer.uri);
41
+ await client.waitForSession(issuanceOffer.sessionId);
72
42
  ```
73
43
 
74
44
  ## Full API
75
45
 
76
- ### Factory Functions (Easiest)
46
+ ### Class API
77
47
 
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 |
48
+ Use `EudiploClient` methods directly:
49
+
50
+ | Method | Description |
51
+ | ----------------------------- | ---------------------------------------------- |
52
+ | `createPresentationRequest()` | Create verification request URI and session ID |
53
+ | `createIssuanceOffer()` | Create issuance offer URI and session ID |
54
+ | `waitForSession()` | Poll session until terminal state |
55
+ | `subscribeToSession()` | Subscribe via SSE |
56
+ | `verifyWithDcApi()` | Browser-native DC API end-to-end flow |
84
57
 
85
58
  ### Digital Credentials API (Browser Native)
86
59
 
87
60
  The SDK includes utilities for the [Digital Credentials API](https://wicg.github.io/digital-credentials/), enabling browser-native credential presentation without QR codes.
88
61
 
89
62
  ```typescript
90
- import { isDcApiAvailable, verifyWithDcApi } from '@eudiplo/sdk-core';
63
+ import { isDcApiAvailable, EudiploClient } from '@eudiplo/sdk-core';
64
+
65
+ const client = new EudiploClient({
66
+ baseUrl: 'https://eudiplo.example.com',
67
+ clientId: 'my-demo',
68
+ clientSecret: 'secret',
69
+ });
91
70
 
92
71
  // Check if browser supports DC API
93
72
  if (isDcApiAvailable()) {
94
- const result = await verifyWithDcApi({
95
- baseUrl: 'https://eudiplo.example.com',
96
- clientId: 'my-demo',
97
- clientSecret: 'secret',
73
+ const result = await client.verifyWithDcApi({
98
74
  configId: 'age-over-18',
99
75
  });
100
76
 
101
- console.log('Verified!', result.session.credentials);
77
+ console.log('Verified!', result.credentials);
102
78
  } else {
103
- // Fall back to QR code flow
104
- const session = await verifyAndWait({...});
79
+ // Fall back to QR code flow using EudiploClient methods
105
80
  }
106
81
  ```
107
82
 
108
- #### DC API Functions
83
+ #### DC API Methods
109
84
 
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 |
85
+ | Method | Description |
86
+ | -------------------------------------------- | --------------------------------------------------- |
87
+ | `isDcApiAvailable()` | Check if browser supports Digital Credentials API |
88
+ | `client.verifyWithDcApi()` | Complete verification flow using browser-native API |
89
+ | `client.createDcApiPresentationRequest(...)` | Create DC API session with request object |
115
90
 
116
91
  #### Lower-level DC API Usage
117
92
 
118
93
  ```typescript
119
- import { createDcApiRequest, EudiploClient } from '@eudiplo/sdk-core';
94
+ import { EudiploClient } from '@eudiplo/sdk-core';
120
95
 
121
96
  const client = new EudiploClient({...});
122
97
 
123
- // Create presentation request
124
- const { uri, sessionId } = await client.createPresentationRequest({
98
+ // Create DC API session with request object
99
+ const session = await client.createDcApiPresentationRequest({
125
100
  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
-
145
- | Function | Description |
146
- | -------------------------------- | ------------------------------------------------------ |
147
- | `createDcApiRequestForBrowser()` | Create request on server, return safe data for browser |
148
- | `submitDcApiWalletResponse()` | Submit wallet response to EUDIPLO from server |
149
-
150
- **Browser-side Functions:**
151
-
152
- | Function | Description |
153
- | ------------- | ------------------------------------------------------ |
154
- | `callDcApi()` | Call the native DC API with a request from your server |
155
-
156
- ##### Example: Express.js Backend + Browser Frontend
157
-
158
- **Server (Express.js / Next.js API route):**
159
-
160
- ```typescript
161
- import {
162
- createDcApiRequestForBrowser,
163
- submitDcApiWalletResponse,
164
- } from '@eudiplo/sdk-core';
165
-
166
- // POST /api/start-verification
167
- app.post('/api/start-verification', async (req, res) => {
168
- const requestData = await createDcApiRequestForBrowser({
169
- baseUrl: process.env.EUDIPLO_URL,
170
- clientId: process.env.EUDIPLO_CLIENT_ID, // ✅ Safe on server
171
- clientSecret: process.env.EUDIPLO_SECRET, // ✅ Safe on server
172
- configId: 'age-over-18',
173
- });
174
-
175
- // Only safe data is sent to browser (no secrets)
176
- res.json(requestData);
177
- });
178
-
179
- // POST /api/complete-verification
180
- app.post('/api/complete-verification', async (req, res) => {
181
- const { responseUri, walletResponse } = req.body;
182
-
183
- const result = await submitDcApiWalletResponse({
184
- responseUri,
185
- walletResponse,
186
- sendResponse: true, // Get verified claims back
187
- });
188
-
189
- // result.credentials contains the verified data
190
- res.json(result);
191
101
  });
192
- ```
193
-
194
- **Browser (React / vanilla JS):**
195
102
 
196
- ```typescript
197
- import { callDcApi, isDcApiAvailable } from '@eudiplo/sdk-core';
198
-
199
- async function verifyAge() {
200
- // 1. Get the request from your server (credentials stay on server)
201
- const requestData = await fetch('/api/start-verification', {
202
- method: 'POST',
203
- }).then((r) => r.json());
204
-
205
- // 2. Check DC API support and call it locally
206
- if (!isDcApiAvailable()) {
207
- throw new Error('Digital Credentials API not supported');
208
- }
209
-
210
- const walletResponse = await callDcApi(requestData.requestObject);
211
-
212
- // 3. Send the wallet response back to your server for verification
213
- const result = await fetch('/api/complete-verification', {
214
- method: 'POST',
215
- headers: { 'Content-Type': 'application/json' },
216
- body: JSON.stringify({
217
- responseUri: requestData.responseUri,
218
- walletResponse,
219
- }),
220
- }).then((r) => r.json());
221
-
222
- console.log('Verified!', result.credentials);
223
- return result;
224
- }
103
+ // Submit using the browser-native DC API end-to-end
104
+ const result = await client.submitDcApiPresentation(session);
225
105
  ```
226
106
 
227
- **What stays where:**
107
+ #### Secure Deployment Note
228
108
 
229
- | Data | Location | Safe to expose? |
230
- | ------------------------------ | ---------------- | ------------------- |
231
- | `clientId` / `clientSecret` | Server only | ❌ Never expose |
232
- | `requestObject` (signed JWT) | Server → Browser | ✅ Yes |
233
- | `responseUri` | Server → Browser | ✅ Yes |
234
- | Wallet response (encrypted VP) | Browser → Server | ✅ Yes |
235
- | Verified credentials | Server only | Depends on use case |
109
+ For production deployments, keep `clientId` and `clientSecret` on the server.
110
+ Use `EudiploClient` methods to run the full flow (`createDcApiPresentationRequest` + `submitDcApiPresentation`) from trusted backend/application code.
236
111
 
237
112
  ### Class-based API (More Control)
238
113
 
@@ -1,4 +1,4 @@
1
- import { b as Config, C as Client } from '../../types.gen-B0nhFpj5.mjs';
1
+ import { b as Config, C as Client } from '../../types.gen-Cc6DtXw9.mjs';
2
2
 
3
3
  declare const createClient: (config?: Config) => Client;
4
4
 
@@ -1,4 +1,4 @@
1
- import { b as Config, C as Client } from '../../types.gen-B0nhFpj5.js';
1
+ import { b as Config, C as Client } from '../../types.gen-Cc6DtXw9.js';
2
2
 
3
3
  declare const createClient: (config?: Config) => Client;
4
4
 
@@ -447,11 +447,8 @@ var checkForExistence = (options, name) => {
447
447
  }
448
448
  return false;
449
449
  };
450
- var setAuthParams = async ({
451
- security,
452
- ...options
453
- }) => {
454
- for (const auth of security) {
450
+ async function setAuthParams(options) {
451
+ for (const auth of options.security ?? []) {
455
452
  if (checkForExistence(options, auth.name)) {
456
453
  continue;
457
454
  }
@@ -476,7 +473,7 @@ var setAuthParams = async ({
476
473
  break;
477
474
  }
478
475
  }
479
- };
476
+ }
480
477
  var buildUrl = (options) => getUrl({
481
478
  baseUrl: options.baseUrl,
482
479
  path: options.path,
@@ -602,10 +599,7 @@ var createClient = (config = {}) => {
602
599
  serializedBody: void 0
603
600
  };
604
601
  if (opts.security) {
605
- await setAuthParams({
606
- ...opts,
607
- security: opts.security
608
- });
602
+ await setAuthParams(opts);
609
603
  }
610
604
  if (opts.requestValidator) {
611
605
  await opts.requestValidator(opts);
@@ -445,11 +445,8 @@ var checkForExistence = (options, name) => {
445
445
  }
446
446
  return false;
447
447
  };
448
- var setAuthParams = async ({
449
- security,
450
- ...options
451
- }) => {
452
- for (const auth of security) {
448
+ async function setAuthParams(options) {
449
+ for (const auth of options.security ?? []) {
453
450
  if (checkForExistence(options, auth.name)) {
454
451
  continue;
455
452
  }
@@ -474,7 +471,7 @@ var setAuthParams = async ({
474
471
  break;
475
472
  }
476
473
  }
477
- };
474
+ }
478
475
  var buildUrl = (options) => getUrl({
479
476
  baseUrl: options.baseUrl,
480
477
  path: options.path,
@@ -600,10 +597,7 @@ var createClient = (config = {}) => {
600
597
  serializedBody: void 0
601
598
  };
602
599
  if (opts.security) {
603
- await setAuthParams({
604
- ...opts,
605
- security: opts.security
606
- });
600
+ await setAuthParams(opts);
607
601
  }
608
602
  if (opts.requestValidator) {
609
603
  await opts.requestValidator(opts);
@@ -1,4 +1,4 @@
1
- export { A as Auth, C as Client, a as ClientOptions, b as Config, c as CreateClientConfig, O as Options, Q as QuerySerializerOptions, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape, g as createConfig, h as formDataBodySerializer, j as jsonBodySerializer, m as mergeHeaders, u as urlSearchParamsBodySerializer } from '../../types.gen-B0nhFpj5.mjs';
1
+ export { A as Auth, C as Client, a as ClientOptions, b as Config, c as CreateClientConfig, O as Options, Q as QuerySerializerOptions, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape, g as createConfig, h as formDataBodySerializer, j as jsonBodySerializer, m as mergeHeaders, u as urlSearchParamsBodySerializer } from '../../types.gen-Cc6DtXw9.mjs';
2
2
  export { createClient } from './client.gen.mjs';
3
3
 
4
4
  type Slot = 'body' | 'headers' | 'path' | 'query';
@@ -1,4 +1,4 @@
1
- export { A as Auth, C as Client, a as ClientOptions, b as Config, c as CreateClientConfig, O as Options, Q as QuerySerializerOptions, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape, g as createConfig, h as formDataBodySerializer, j as jsonBodySerializer, m as mergeHeaders, u as urlSearchParamsBodySerializer } from '../../types.gen-B0nhFpj5.js';
1
+ export { A as Auth, C as Client, a as ClientOptions, b as Config, c as CreateClientConfig, O as Options, Q as QuerySerializerOptions, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape, g as createConfig, h as formDataBodySerializer, j as jsonBodySerializer, m as mergeHeaders, u as urlSearchParamsBodySerializer } from '../../types.gen-Cc6DtXw9.js';
2
2
  export { createClient } from './client.gen.js';
3
3
 
4
4
  type Slot = 'body' | 'headers' | 'path' | 'query';
@@ -92,10 +92,10 @@ var stripEmptySlots = (params) => {
92
92
  };
93
93
  var buildClientParams = (args, fields) => {
94
94
  const params = {
95
- body: {},
96
- headers: {},
97
- path: {},
98
- query: {}
95
+ body: /* @__PURE__ */ Object.create(null),
96
+ headers: /* @__PURE__ */ Object.create(null),
97
+ path: /* @__PURE__ */ Object.create(null),
98
+ query: /* @__PURE__ */ Object.create(null)
99
99
  };
100
100
  const map = buildKeyMap(fields);
101
101
  let config;
@@ -665,11 +665,8 @@ var checkForExistence = (options, name) => {
665
665
  }
666
666
  return false;
667
667
  };
668
- var setAuthParams = async ({
669
- security,
670
- ...options
671
- }) => {
672
- for (const auth of security) {
668
+ async function setAuthParams(options) {
669
+ for (const auth of options.security ?? []) {
673
670
  if (checkForExistence(options, auth.name)) {
674
671
  continue;
675
672
  }
@@ -694,7 +691,7 @@ var setAuthParams = async ({
694
691
  break;
695
692
  }
696
693
  }
697
- };
694
+ }
698
695
  var buildUrl = (options) => getUrl({
699
696
  baseUrl: options.baseUrl,
700
697
  path: options.path,
@@ -820,10 +817,7 @@ var createClient = (config = {}) => {
820
817
  serializedBody: void 0
821
818
  };
822
819
  if (opts.security) {
823
- await setAuthParams({
824
- ...opts,
825
- security: opts.security
826
- });
820
+ await setAuthParams(opts);
827
821
  }
828
822
  if (opts.requestValidator) {
829
823
  await opts.requestValidator(opts);
@@ -90,10 +90,10 @@ var stripEmptySlots = (params) => {
90
90
  };
91
91
  var buildClientParams = (args, fields) => {
92
92
  const params = {
93
- body: {},
94
- headers: {},
95
- path: {},
96
- query: {}
93
+ body: /* @__PURE__ */ Object.create(null),
94
+ headers: /* @__PURE__ */ Object.create(null),
95
+ path: /* @__PURE__ */ Object.create(null),
96
+ query: /* @__PURE__ */ Object.create(null)
97
97
  };
98
98
  const map = buildKeyMap(fields);
99
99
  let config;
@@ -663,11 +663,8 @@ var checkForExistence = (options, name) => {
663
663
  }
664
664
  return false;
665
665
  };
666
- var setAuthParams = async ({
667
- security,
668
- ...options
669
- }) => {
670
- for (const auth of security) {
666
+ async function setAuthParams(options) {
667
+ for (const auth of options.security ?? []) {
671
668
  if (checkForExistence(options, auth.name)) {
672
669
  continue;
673
670
  }
@@ -692,7 +689,7 @@ var setAuthParams = async ({
692
689
  break;
693
690
  }
694
691
  }
695
- };
692
+ }
696
693
  var buildUrl = (options) => getUrl({
697
694
  baseUrl: options.baseUrl,
698
695
  path: options.path,
@@ -818,10 +815,7 @@ var createClient = (config = {}) => {
818
815
  serializedBody: void 0
819
816
  };
820
817
  if (opts.security) {
821
- await setAuthParams({
822
- ...opts,
823
- security: opts.security
824
- });
818
+ await setAuthParams(opts);
825
819
  }
826
820
  if (opts.requestValidator) {
827
821
  await opts.requestValidator(opts);
@@ -1 +1 @@
1
- export { C as Client, a as ClientOptions, b as Config, c as CreateClientConfig, O as Options, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape } from '../../types.gen-B0nhFpj5.mjs';
1
+ export { C as Client, a as ClientOptions, b as Config, c as CreateClientConfig, O as Options, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape } from '../../types.gen-Cc6DtXw9.mjs';
@@ -1 +1 @@
1
- export { C as Client, a as ClientOptions, b as Config, c as CreateClientConfig, O as Options, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape } from '../../types.gen-B0nhFpj5.js';
1
+ export { C as Client, a as ClientOptions, b as Config, c as CreateClientConfig, O as Options, R as RequestOptions, d as RequestResult, e as ResolvedRequestOptions, f as ResponseStyle, T as TDataShape } from '../../types.gen-Cc6DtXw9.js';
@@ -1,5 +1,5 @@
1
- import { C as Client, a as ClientOptions, b as Config } from '../types.gen-B0nhFpj5.mjs';
2
- import { C as ClientOptions$1 } from '../types.gen-Dx5V0pli.mjs';
1
+ import { C as Client, a as ClientOptions, b as Config } from '../types.gen-Cc6DtXw9.mjs';
2
+ import { C as ClientOptions$1 } from '../types.gen-z3We9JHj.mjs';
3
3
 
4
4
  /**
5
5
  * The `createClientConfig()` function will be called on client initialization
@@ -1,5 +1,5 @@
1
- import { C as Client, a as ClientOptions, b as Config } from '../types.gen-B0nhFpj5.js';
2
- import { C as ClientOptions$1 } from '../types.gen-Dx5V0pli.js';
1
+ import { C as Client, a as ClientOptions, b as Config } from '../types.gen-Cc6DtXw9.js';
2
+ import { C as ClientOptions$1 } from '../types.gen-z3We9JHj.js';
3
3
 
4
4
  /**
5
5
  * The `createClientConfig()` function will be called on client initialization
@@ -447,11 +447,8 @@ var checkForExistence = (options, name) => {
447
447
  }
448
448
  return false;
449
449
  };
450
- var setAuthParams = async ({
451
- security,
452
- ...options
453
- }) => {
454
- for (const auth of security) {
450
+ async function setAuthParams(options) {
451
+ for (const auth of options.security ?? []) {
455
452
  if (checkForExistence(options, auth.name)) {
456
453
  continue;
457
454
  }
@@ -476,7 +473,7 @@ var setAuthParams = async ({
476
473
  break;
477
474
  }
478
475
  }
479
- };
476
+ }
480
477
  var buildUrl = (options) => getUrl({
481
478
  baseUrl: options.baseUrl,
482
479
  path: options.path,
@@ -602,10 +599,7 @@ var createClient = (config = {}) => {
602
599
  serializedBody: void 0
603
600
  };
604
601
  if (opts.security) {
605
- await setAuthParams({
606
- ...opts,
607
- security: opts.security
608
- });
602
+ await setAuthParams(opts);
609
603
  }
610
604
  if (opts.requestValidator) {
611
605
  await opts.requestValidator(opts);
@@ -445,11 +445,8 @@ var checkForExistence = (options, name) => {
445
445
  }
446
446
  return false;
447
447
  };
448
- var setAuthParams = async ({
449
- security,
450
- ...options
451
- }) => {
452
- for (const auth of security) {
448
+ async function setAuthParams(options) {
449
+ for (const auth of options.security ?? []) {
453
450
  if (checkForExistence(options, auth.name)) {
454
451
  continue;
455
452
  }
@@ -474,7 +471,7 @@ var setAuthParams = async ({
474
471
  break;
475
472
  }
476
473
  }
477
- };
474
+ }
478
475
  var buildUrl = (options) => getUrl({
479
476
  baseUrl: options.baseUrl,
480
477
  path: options.path,
@@ -600,10 +597,7 @@ var createClient = (config = {}) => {
600
597
  serializedBody: void 0
601
598
  };
602
599
  if (opts.security) {
603
- await setAuthParams({
604
- ...opts,
605
- security: opts.security
606
- });
600
+ await setAuthParams(opts);
607
601
  }
608
602
  if (opts.requestValidator) {
609
603
  await opts.requestValidator(opts);