@eudiplo/sdk-core 1.14.0-main.748e526 → 1.14.0-main.7d9c81c
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 +96 -0
- package/dist/index.d.mts +110 -1
- package/dist/index.d.ts +110 -1
- package/dist/index.js +80 -0
- package/dist/index.mjs +78 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -136,6 +136,102 @@ const credential = await navigator.credentials.get(request);
|
|
|
136
136
|
const session = await client.submitDcApiResponse(sessionId, credential);
|
|
137
137
|
```
|
|
138
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
|
+
|
|
139
235
|
### Class-based API (More Control)
|
|
140
236
|
|
|
141
237
|
```typescript
|
package/dist/index.d.mts
CHANGED
|
@@ -436,5 +436,114 @@ declare function createDcApiRequest(options: DcApiVerifyOptions): Promise<{
|
|
|
436
436
|
session: Session;
|
|
437
437
|
submit: (dcOptions?: DcApiPresentationOptions) => Promise<DcApiPresentationResult>;
|
|
438
438
|
}>;
|
|
439
|
+
/**
|
|
440
|
+
* Data returned from server to browser for DC API flow
|
|
441
|
+
*/
|
|
442
|
+
interface DcApiRequestData {
|
|
443
|
+
/** The signed JWT request object to pass to the DC API */
|
|
444
|
+
requestObject: string;
|
|
445
|
+
/** Session ID for tracking */
|
|
446
|
+
sessionId: string;
|
|
447
|
+
/** The response_uri where wallet responses should be submitted */
|
|
448
|
+
responseUri: string;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Wallet response data from the DC API to send back to server
|
|
452
|
+
*/
|
|
453
|
+
interface DcApiWalletResponse {
|
|
454
|
+
/** The encrypted VP token response from the wallet */
|
|
455
|
+
response?: string;
|
|
456
|
+
/** Error code if the wallet returned an error */
|
|
457
|
+
error?: string;
|
|
458
|
+
/** Error description if available */
|
|
459
|
+
error_description?: string;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* SERVER-SIDE: Create a DC API request and return the data needed by the browser.
|
|
463
|
+
* Use this on your server where credentials are stored securely.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```typescript
|
|
467
|
+
* // On your server (e.g., Express/Next.js API route)
|
|
468
|
+
* import { createDcApiRequestForBrowser } from '@eudiplo/sdk-core';
|
|
469
|
+
*
|
|
470
|
+
* app.post('/api/start-verification', async (req, res) => {
|
|
471
|
+
* const requestData = await createDcApiRequestForBrowser({
|
|
472
|
+
* baseUrl: 'https://eudiplo.example.com',
|
|
473
|
+
* clientId: process.env.EUDIPLO_CLIENT_ID, // Safe on server
|
|
474
|
+
* clientSecret: process.env.EUDIPLO_SECRET, // Safe on server
|
|
475
|
+
* configId: 'age-over-18',
|
|
476
|
+
* });
|
|
477
|
+
*
|
|
478
|
+
* // Send only the safe data to the browser
|
|
479
|
+
* res.json(requestData);
|
|
480
|
+
* });
|
|
481
|
+
* ```
|
|
482
|
+
*/
|
|
483
|
+
declare function createDcApiRequestForBrowser(options: DcApiVerifyOptions): Promise<DcApiRequestData>;
|
|
484
|
+
/**
|
|
485
|
+
* BROWSER-SIDE: Call the Digital Credentials API with a request from your server.
|
|
486
|
+
* This function runs in the browser and invokes the native DC API.
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* // In your browser code
|
|
491
|
+
* import { callDcApi, isDcApiAvailable } from '@eudiplo/sdk-core';
|
|
492
|
+
*
|
|
493
|
+
* // Get request data from your server
|
|
494
|
+
* const requestData = await fetch('/api/start-verification', { method: 'POST' })
|
|
495
|
+
* .then(r => r.json());
|
|
496
|
+
*
|
|
497
|
+
* if (isDcApiAvailable()) {
|
|
498
|
+
* // This calls the browser's native Digital Credentials API
|
|
499
|
+
* const walletResponse = await callDcApi(requestData.requestObject);
|
|
500
|
+
*
|
|
501
|
+
* // Send the wallet response back to your server for verification
|
|
502
|
+
* const result = await fetch('/api/complete-verification', {
|
|
503
|
+
* method: 'POST',
|
|
504
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
505
|
+
* body: JSON.stringify({
|
|
506
|
+
* sessionId: requestData.sessionId,
|
|
507
|
+
* walletResponse,
|
|
508
|
+
* }),
|
|
509
|
+
* }).then(r => r.json());
|
|
510
|
+
* }
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
declare function callDcApi(requestObject: string): Promise<DcApiWalletResponse>;
|
|
514
|
+
/**
|
|
515
|
+
* SERVER-SIDE: Submit the wallet response to EUDIPLO and get verified credentials.
|
|
516
|
+
* Use this on your server after receiving the wallet response from the browser.
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```typescript
|
|
520
|
+
* // On your server
|
|
521
|
+
* import { submitDcApiWalletResponse } from '@eudiplo/sdk-core';
|
|
522
|
+
*
|
|
523
|
+
* app.post('/api/complete-verification', async (req, res) => {
|
|
524
|
+
* const { sessionId, walletResponse } = req.body;
|
|
525
|
+
*
|
|
526
|
+
* // You stored the responseUri when creating the request, or pass it from client
|
|
527
|
+
* const result = await submitDcApiWalletResponse({
|
|
528
|
+
* responseUri: storedResponseUri, // or from request
|
|
529
|
+
* walletResponse,
|
|
530
|
+
* sendResponse: true, // Get verified claims back
|
|
531
|
+
* });
|
|
532
|
+
*
|
|
533
|
+
* // result.credentials contains the verified data
|
|
534
|
+
* res.json(result);
|
|
535
|
+
* });
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
declare function submitDcApiWalletResponse(options: {
|
|
539
|
+
/** The response_uri from the request (from DcApiRequestData.responseUri) */
|
|
540
|
+
responseUri: string;
|
|
541
|
+
/** The wallet response from callDcApi() */
|
|
542
|
+
walletResponse: DcApiWalletResponse;
|
|
543
|
+
/** Whether to return full credential data (default: true) */
|
|
544
|
+
sendResponse?: boolean;
|
|
545
|
+
/** Custom fetch implementation (optional) */
|
|
546
|
+
fetch?: typeof fetch;
|
|
547
|
+
}): Promise<DcApiPresentationResult>;
|
|
439
548
|
|
|
440
|
-
export { type DcApiPresentationOptions, type DcApiPresentationResult, type DcApiVerifyOptions, type DigitalCredentialResponse, EudiploClient, type EudiploClientConfig, type EudiploCredentials, type FlowResult, type IssuanceOfferOptions, type IssueOptions, type OfferResult, type PresentationRequestOptions, Session, type SessionPollingOptions, type VerifyOptions, createDcApiRequest, isDcApiAvailable, issue, issueAndWait, verify, verifyAndWait, verifyWithDcApi };
|
|
549
|
+
export { type DcApiPresentationOptions, type DcApiPresentationResult, type DcApiRequestData, type DcApiVerifyOptions, type DcApiWalletResponse, type DigitalCredentialResponse, EudiploClient, type EudiploClientConfig, type EudiploCredentials, type FlowResult, type IssuanceOfferOptions, type IssueOptions, type OfferResult, type PresentationRequestOptions, Session, type SessionPollingOptions, type VerifyOptions, callDcApi, createDcApiRequest, createDcApiRequestForBrowser, isDcApiAvailable, issue, issueAndWait, submitDcApiWalletResponse, verify, verifyAndWait, verifyWithDcApi };
|
package/dist/index.d.ts
CHANGED
|
@@ -436,5 +436,114 @@ declare function createDcApiRequest(options: DcApiVerifyOptions): Promise<{
|
|
|
436
436
|
session: Session;
|
|
437
437
|
submit: (dcOptions?: DcApiPresentationOptions) => Promise<DcApiPresentationResult>;
|
|
438
438
|
}>;
|
|
439
|
+
/**
|
|
440
|
+
* Data returned from server to browser for DC API flow
|
|
441
|
+
*/
|
|
442
|
+
interface DcApiRequestData {
|
|
443
|
+
/** The signed JWT request object to pass to the DC API */
|
|
444
|
+
requestObject: string;
|
|
445
|
+
/** Session ID for tracking */
|
|
446
|
+
sessionId: string;
|
|
447
|
+
/** The response_uri where wallet responses should be submitted */
|
|
448
|
+
responseUri: string;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Wallet response data from the DC API to send back to server
|
|
452
|
+
*/
|
|
453
|
+
interface DcApiWalletResponse {
|
|
454
|
+
/** The encrypted VP token response from the wallet */
|
|
455
|
+
response?: string;
|
|
456
|
+
/** Error code if the wallet returned an error */
|
|
457
|
+
error?: string;
|
|
458
|
+
/** Error description if available */
|
|
459
|
+
error_description?: string;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* SERVER-SIDE: Create a DC API request and return the data needed by the browser.
|
|
463
|
+
* Use this on your server where credentials are stored securely.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```typescript
|
|
467
|
+
* // On your server (e.g., Express/Next.js API route)
|
|
468
|
+
* import { createDcApiRequestForBrowser } from '@eudiplo/sdk-core';
|
|
469
|
+
*
|
|
470
|
+
* app.post('/api/start-verification', async (req, res) => {
|
|
471
|
+
* const requestData = await createDcApiRequestForBrowser({
|
|
472
|
+
* baseUrl: 'https://eudiplo.example.com',
|
|
473
|
+
* clientId: process.env.EUDIPLO_CLIENT_ID, // Safe on server
|
|
474
|
+
* clientSecret: process.env.EUDIPLO_SECRET, // Safe on server
|
|
475
|
+
* configId: 'age-over-18',
|
|
476
|
+
* });
|
|
477
|
+
*
|
|
478
|
+
* // Send only the safe data to the browser
|
|
479
|
+
* res.json(requestData);
|
|
480
|
+
* });
|
|
481
|
+
* ```
|
|
482
|
+
*/
|
|
483
|
+
declare function createDcApiRequestForBrowser(options: DcApiVerifyOptions): Promise<DcApiRequestData>;
|
|
484
|
+
/**
|
|
485
|
+
* BROWSER-SIDE: Call the Digital Credentials API with a request from your server.
|
|
486
|
+
* This function runs in the browser and invokes the native DC API.
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* // In your browser code
|
|
491
|
+
* import { callDcApi, isDcApiAvailable } from '@eudiplo/sdk-core';
|
|
492
|
+
*
|
|
493
|
+
* // Get request data from your server
|
|
494
|
+
* const requestData = await fetch('/api/start-verification', { method: 'POST' })
|
|
495
|
+
* .then(r => r.json());
|
|
496
|
+
*
|
|
497
|
+
* if (isDcApiAvailable()) {
|
|
498
|
+
* // This calls the browser's native Digital Credentials API
|
|
499
|
+
* const walletResponse = await callDcApi(requestData.requestObject);
|
|
500
|
+
*
|
|
501
|
+
* // Send the wallet response back to your server for verification
|
|
502
|
+
* const result = await fetch('/api/complete-verification', {
|
|
503
|
+
* method: 'POST',
|
|
504
|
+
* headers: { 'Content-Type': 'application/json' },
|
|
505
|
+
* body: JSON.stringify({
|
|
506
|
+
* sessionId: requestData.sessionId,
|
|
507
|
+
* walletResponse,
|
|
508
|
+
* }),
|
|
509
|
+
* }).then(r => r.json());
|
|
510
|
+
* }
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
declare function callDcApi(requestObject: string): Promise<DcApiWalletResponse>;
|
|
514
|
+
/**
|
|
515
|
+
* SERVER-SIDE: Submit the wallet response to EUDIPLO and get verified credentials.
|
|
516
|
+
* Use this on your server after receiving the wallet response from the browser.
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```typescript
|
|
520
|
+
* // On your server
|
|
521
|
+
* import { submitDcApiWalletResponse } from '@eudiplo/sdk-core';
|
|
522
|
+
*
|
|
523
|
+
* app.post('/api/complete-verification', async (req, res) => {
|
|
524
|
+
* const { sessionId, walletResponse } = req.body;
|
|
525
|
+
*
|
|
526
|
+
* // You stored the responseUri when creating the request, or pass it from client
|
|
527
|
+
* const result = await submitDcApiWalletResponse({
|
|
528
|
+
* responseUri: storedResponseUri, // or from request
|
|
529
|
+
* walletResponse,
|
|
530
|
+
* sendResponse: true, // Get verified claims back
|
|
531
|
+
* });
|
|
532
|
+
*
|
|
533
|
+
* // result.credentials contains the verified data
|
|
534
|
+
* res.json(result);
|
|
535
|
+
* });
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
declare function submitDcApiWalletResponse(options: {
|
|
539
|
+
/** The response_uri from the request (from DcApiRequestData.responseUri) */
|
|
540
|
+
responseUri: string;
|
|
541
|
+
/** The wallet response from callDcApi() */
|
|
542
|
+
walletResponse: DcApiWalletResponse;
|
|
543
|
+
/** Whether to return full credential data (default: true) */
|
|
544
|
+
sendResponse?: boolean;
|
|
545
|
+
/** Custom fetch implementation (optional) */
|
|
546
|
+
fetch?: typeof fetch;
|
|
547
|
+
}): Promise<DcApiPresentationResult>;
|
|
439
548
|
|
|
440
|
-
export { type DcApiPresentationOptions, type DcApiPresentationResult, type DcApiVerifyOptions, type DigitalCredentialResponse, EudiploClient, type EudiploClientConfig, type EudiploCredentials, type FlowResult, type IssuanceOfferOptions, type IssueOptions, type OfferResult, type PresentationRequestOptions, Session, type SessionPollingOptions, type VerifyOptions, createDcApiRequest, isDcApiAvailable, issue, issueAndWait, verify, verifyAndWait, verifyWithDcApi };
|
|
549
|
+
export { type DcApiPresentationOptions, type DcApiPresentationResult, type DcApiRequestData, type DcApiVerifyOptions, type DcApiWalletResponse, type DigitalCredentialResponse, EudiploClient, type EudiploClientConfig, type EudiploCredentials, type FlowResult, type IssuanceOfferOptions, type IssueOptions, type OfferResult, type PresentationRequestOptions, Session, type SessionPollingOptions, type VerifyOptions, callDcApi, createDcApiRequest, createDcApiRequestForBrowser, isDcApiAvailable, issue, issueAndWait, submitDcApiWalletResponse, verify, verifyAndWait, verifyWithDcApi };
|
package/dist/index.js
CHANGED
|
@@ -1786,6 +1786,83 @@ async function createDcApiRequest(options) {
|
|
|
1786
1786
|
})
|
|
1787
1787
|
};
|
|
1788
1788
|
}
|
|
1789
|
+
async function createDcApiRequestForBrowser(options) {
|
|
1790
|
+
const eudiploClient = new EudiploClient({
|
|
1791
|
+
baseUrl: options.baseUrl,
|
|
1792
|
+
clientId: options.clientId,
|
|
1793
|
+
clientSecret: options.clientSecret
|
|
1794
|
+
});
|
|
1795
|
+
const session = await eudiploClient.createDcApiPresentationRequest({
|
|
1796
|
+
configId: options.configId,
|
|
1797
|
+
redirectUri: options.redirectUri
|
|
1798
|
+
});
|
|
1799
|
+
if (!session.requestObject) {
|
|
1800
|
+
throw new Error("Session does not contain a requestObject");
|
|
1801
|
+
}
|
|
1802
|
+
const requestPayload = decodeJwtPayload(
|
|
1803
|
+
session.requestObject
|
|
1804
|
+
);
|
|
1805
|
+
if (!requestPayload.response_uri) {
|
|
1806
|
+
throw new Error("No response_uri found in request object");
|
|
1807
|
+
}
|
|
1808
|
+
return {
|
|
1809
|
+
requestObject: session.requestObject,
|
|
1810
|
+
sessionId: session.id,
|
|
1811
|
+
responseUri: requestPayload.response_uri
|
|
1812
|
+
};
|
|
1813
|
+
}
|
|
1814
|
+
async function callDcApi(requestObject) {
|
|
1815
|
+
if (!isDcApiAvailable()) {
|
|
1816
|
+
throw new Error(
|
|
1817
|
+
"Digital Credentials API is not available in this browser. Please use a supported browser or fall back to QR code flow."
|
|
1818
|
+
);
|
|
1819
|
+
}
|
|
1820
|
+
const dcResponse = await navigator.credentials.get({
|
|
1821
|
+
mediation: "required",
|
|
1822
|
+
digital: {
|
|
1823
|
+
requests: [
|
|
1824
|
+
{
|
|
1825
|
+
protocol: "openid4vp-v1-signed",
|
|
1826
|
+
data: { request: requestObject }
|
|
1827
|
+
}
|
|
1828
|
+
]
|
|
1829
|
+
}
|
|
1830
|
+
});
|
|
1831
|
+
if (!dcResponse) {
|
|
1832
|
+
throw new Error("No response from Digital Credentials API");
|
|
1833
|
+
}
|
|
1834
|
+
if (dcResponse.data?.error) {
|
|
1835
|
+
throw new Error(
|
|
1836
|
+
`Wallet error: ${dcResponse.data.error}${dcResponse.data.error_description ? ` - ${dcResponse.data.error_description}` : ""}`
|
|
1837
|
+
);
|
|
1838
|
+
}
|
|
1839
|
+
return dcResponse.data;
|
|
1840
|
+
}
|
|
1841
|
+
async function submitDcApiWalletResponse(options) {
|
|
1842
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
1843
|
+
const submitResponse = await fetchImpl(options.responseUri, {
|
|
1844
|
+
method: "POST",
|
|
1845
|
+
headers: {
|
|
1846
|
+
"Content-Type": "application/json"
|
|
1847
|
+
},
|
|
1848
|
+
body: JSON.stringify({
|
|
1849
|
+
...options.walletResponse,
|
|
1850
|
+
sendResponse: options.sendResponse ?? true
|
|
1851
|
+
})
|
|
1852
|
+
});
|
|
1853
|
+
if (!submitResponse.ok) {
|
|
1854
|
+
const errorText = await submitResponse.text();
|
|
1855
|
+
throw new Error(
|
|
1856
|
+
`Failed to submit presentation: ${submitResponse.status} ${errorText}`
|
|
1857
|
+
);
|
|
1858
|
+
}
|
|
1859
|
+
const result = await submitResponse.json();
|
|
1860
|
+
return {
|
|
1861
|
+
credentials: result.credentials ?? result,
|
|
1862
|
+
response: result,
|
|
1863
|
+
redirectUri: result.redirect_uri
|
|
1864
|
+
};
|
|
1865
|
+
}
|
|
1789
1866
|
|
|
1790
1867
|
exports.EudiploClient = EudiploClient;
|
|
1791
1868
|
exports.appControllerMain = appControllerMain;
|
|
@@ -1796,6 +1873,7 @@ exports.authorizeControllerAuthorizationChallengeEndpoint = authorizeControllerA
|
|
|
1796
1873
|
exports.authorizeControllerAuthorize = authorizeControllerAuthorize;
|
|
1797
1874
|
exports.authorizeControllerPar = authorizeControllerPar;
|
|
1798
1875
|
exports.authorizeControllerToken = authorizeControllerToken;
|
|
1876
|
+
exports.callDcApi = callDcApi;
|
|
1799
1877
|
exports.certControllerAddCertificate = certControllerAddCertificate;
|
|
1800
1878
|
exports.certControllerDeleteCertificate = certControllerDeleteCertificate;
|
|
1801
1879
|
exports.certControllerExportConfig = certControllerExportConfig;
|
|
@@ -1810,6 +1888,7 @@ exports.clientControllerGetClientSecret = clientControllerGetClientSecret;
|
|
|
1810
1888
|
exports.clientControllerGetClients = clientControllerGetClients;
|
|
1811
1889
|
exports.clientControllerUpdateClient = clientControllerUpdateClient;
|
|
1812
1890
|
exports.createDcApiRequest = createDcApiRequest;
|
|
1891
|
+
exports.createDcApiRequestForBrowser = createDcApiRequestForBrowser;
|
|
1813
1892
|
exports.credentialConfigControllerDeleteIssuanceConfiguration = credentialConfigControllerDeleteIssuanceConfiguration;
|
|
1814
1893
|
exports.credentialConfigControllerGetConfigById = credentialConfigControllerGetConfigById;
|
|
1815
1894
|
exports.credentialConfigControllerGetConfigs = credentialConfigControllerGetConfigs;
|
|
@@ -1864,6 +1943,7 @@ exports.statusListManagementControllerGetLists = statusListManagementControllerG
|
|
|
1864
1943
|
exports.statusListManagementControllerUpdateList = statusListManagementControllerUpdateList;
|
|
1865
1944
|
exports.storageControllerDownload = storageControllerDownload;
|
|
1866
1945
|
exports.storageControllerUpload = storageControllerUpload;
|
|
1946
|
+
exports.submitDcApiWalletResponse = submitDcApiWalletResponse;
|
|
1867
1947
|
exports.tenantControllerDeleteTenant = tenantControllerDeleteTenant;
|
|
1868
1948
|
exports.tenantControllerGetTenant = tenantControllerGetTenant;
|
|
1869
1949
|
exports.tenantControllerGetTenants = tenantControllerGetTenants;
|
package/dist/index.mjs
CHANGED
|
@@ -1784,7 +1784,84 @@ async function createDcApiRequest(options) {
|
|
|
1784
1784
|
})
|
|
1785
1785
|
};
|
|
1786
1786
|
}
|
|
1787
|
+
async function createDcApiRequestForBrowser(options) {
|
|
1788
|
+
const eudiploClient = new EudiploClient({
|
|
1789
|
+
baseUrl: options.baseUrl,
|
|
1790
|
+
clientId: options.clientId,
|
|
1791
|
+
clientSecret: options.clientSecret
|
|
1792
|
+
});
|
|
1793
|
+
const session = await eudiploClient.createDcApiPresentationRequest({
|
|
1794
|
+
configId: options.configId,
|
|
1795
|
+
redirectUri: options.redirectUri
|
|
1796
|
+
});
|
|
1797
|
+
if (!session.requestObject) {
|
|
1798
|
+
throw new Error("Session does not contain a requestObject");
|
|
1799
|
+
}
|
|
1800
|
+
const requestPayload = decodeJwtPayload(
|
|
1801
|
+
session.requestObject
|
|
1802
|
+
);
|
|
1803
|
+
if (!requestPayload.response_uri) {
|
|
1804
|
+
throw new Error("No response_uri found in request object");
|
|
1805
|
+
}
|
|
1806
|
+
return {
|
|
1807
|
+
requestObject: session.requestObject,
|
|
1808
|
+
sessionId: session.id,
|
|
1809
|
+
responseUri: requestPayload.response_uri
|
|
1810
|
+
};
|
|
1811
|
+
}
|
|
1812
|
+
async function callDcApi(requestObject) {
|
|
1813
|
+
if (!isDcApiAvailable()) {
|
|
1814
|
+
throw new Error(
|
|
1815
|
+
"Digital Credentials API is not available in this browser. Please use a supported browser or fall back to QR code flow."
|
|
1816
|
+
);
|
|
1817
|
+
}
|
|
1818
|
+
const dcResponse = await navigator.credentials.get({
|
|
1819
|
+
mediation: "required",
|
|
1820
|
+
digital: {
|
|
1821
|
+
requests: [
|
|
1822
|
+
{
|
|
1823
|
+
protocol: "openid4vp-v1-signed",
|
|
1824
|
+
data: { request: requestObject }
|
|
1825
|
+
}
|
|
1826
|
+
]
|
|
1827
|
+
}
|
|
1828
|
+
});
|
|
1829
|
+
if (!dcResponse) {
|
|
1830
|
+
throw new Error("No response from Digital Credentials API");
|
|
1831
|
+
}
|
|
1832
|
+
if (dcResponse.data?.error) {
|
|
1833
|
+
throw new Error(
|
|
1834
|
+
`Wallet error: ${dcResponse.data.error}${dcResponse.data.error_description ? ` - ${dcResponse.data.error_description}` : ""}`
|
|
1835
|
+
);
|
|
1836
|
+
}
|
|
1837
|
+
return dcResponse.data;
|
|
1838
|
+
}
|
|
1839
|
+
async function submitDcApiWalletResponse(options) {
|
|
1840
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
1841
|
+
const submitResponse = await fetchImpl(options.responseUri, {
|
|
1842
|
+
method: "POST",
|
|
1843
|
+
headers: {
|
|
1844
|
+
"Content-Type": "application/json"
|
|
1845
|
+
},
|
|
1846
|
+
body: JSON.stringify({
|
|
1847
|
+
...options.walletResponse,
|
|
1848
|
+
sendResponse: options.sendResponse ?? true
|
|
1849
|
+
})
|
|
1850
|
+
});
|
|
1851
|
+
if (!submitResponse.ok) {
|
|
1852
|
+
const errorText = await submitResponse.text();
|
|
1853
|
+
throw new Error(
|
|
1854
|
+
`Failed to submit presentation: ${submitResponse.status} ${errorText}`
|
|
1855
|
+
);
|
|
1856
|
+
}
|
|
1857
|
+
const result = await submitResponse.json();
|
|
1858
|
+
return {
|
|
1859
|
+
credentials: result.credentials ?? result,
|
|
1860
|
+
response: result,
|
|
1861
|
+
redirectUri: result.redirect_uri
|
|
1862
|
+
};
|
|
1863
|
+
}
|
|
1787
1864
|
|
|
1788
|
-
export { EudiploClient, appControllerMain, authControllerGetGlobalJwks, authControllerGetOAuth2Token, authControllerGetOidcDiscovery, authorizeControllerAuthorizationChallengeEndpoint, authorizeControllerAuthorize, authorizeControllerPar, authorizeControllerToken, certControllerAddCertificate, certControllerDeleteCertificate, certControllerExportConfig, certControllerGetCertificate, certControllerGetCertificates, certControllerUpdateCertificate, client, clientControllerCreateClient, clientControllerDeleteClient, clientControllerGetClient, clientControllerGetClientSecret, clientControllerGetClients, clientControllerUpdateClient, createDcApiRequest, credentialConfigControllerDeleteIssuanceConfiguration, credentialConfigControllerGetConfigById, credentialConfigControllerGetConfigs, credentialConfigControllerStoreCredentialConfiguration, credentialConfigControllerUpdateCredentialConfiguration, credentialOfferControllerGetOffer, healthControllerCheck, isDcApiAvailable, issuanceConfigControllerGetIssuanceConfigurations, issuanceConfigControllerStoreIssuanceConfiguration, issue, issueAndWait, keyControllerAddKey, keyControllerDeleteKey, keyControllerGetKey, keyControllerGetKeys, keyControllerUpdateKey, oid4VciControllerCredential, oid4VciControllerNonce, oid4VciControllerNotifications, oid4VciMetadataControllerVct, oid4VpControllerGetPostRequestWithSession, oid4VpControllerGetRequestWithSession, oid4VpControllerGetResponse, presentationManagementControllerConfiguration, presentationManagementControllerDeleteConfiguration, presentationManagementControllerGetConfiguration, presentationManagementControllerStorePresentationConfig, presentationManagementControllerUpdateConfiguration, prometheusControllerIndex, registrarControllerCreateAccessCertificate, registrarControllerCreateConfig, registrarControllerDeleteConfig, registrarControllerGetConfig, registrarControllerUpdateConfig, sessionConfigControllerGetConfig, sessionConfigControllerResetConfig, sessionConfigControllerUpdateConfig, sessionControllerDeleteSession, sessionControllerGetAllSessions, sessionControllerGetSession, sessionControllerRevokeAll, statusListConfigControllerGetConfig, statusListConfigControllerResetConfig, statusListConfigControllerUpdateConfig, statusListControllerGetList, statusListControllerGetStatusListAggregation, statusListManagementControllerCreateList, statusListManagementControllerDeleteList, statusListManagementControllerGetList, statusListManagementControllerGetLists, statusListManagementControllerUpdateList, storageControllerDownload, storageControllerUpload, tenantControllerDeleteTenant, tenantControllerGetTenant, tenantControllerGetTenants, tenantControllerInitTenant, tenantControllerUpdateTenant, trustListControllerCreateTrustList, trustListControllerDeleteTrustList, trustListControllerExportTrustList, trustListControllerGetAllTrustLists, trustListControllerGetTrustList, trustListControllerGetTrustListVersion, trustListControllerGetTrustListVersions, trustListControllerUpdateTrustList, trustListPublicControllerGetTrustListJwt, verifierOfferControllerGetOffer, verify, verifyAndWait, verifyWithDcApi, wellKnownControllerAuthzMetadata0, wellKnownControllerAuthzMetadata1, wellKnownControllerGetJwks0, wellKnownControllerGetJwks1, wellKnownControllerIssuerMetadata0, wellKnownControllerIssuerMetadata1 };
|
|
1865
|
+
export { EudiploClient, appControllerMain, authControllerGetGlobalJwks, authControllerGetOAuth2Token, authControllerGetOidcDiscovery, authorizeControllerAuthorizationChallengeEndpoint, authorizeControllerAuthorize, authorizeControllerPar, authorizeControllerToken, callDcApi, certControllerAddCertificate, certControllerDeleteCertificate, certControllerExportConfig, certControllerGetCertificate, certControllerGetCertificates, certControllerUpdateCertificate, client, clientControllerCreateClient, clientControllerDeleteClient, clientControllerGetClient, clientControllerGetClientSecret, clientControllerGetClients, clientControllerUpdateClient, createDcApiRequest, createDcApiRequestForBrowser, credentialConfigControllerDeleteIssuanceConfiguration, credentialConfigControllerGetConfigById, credentialConfigControllerGetConfigs, credentialConfigControllerStoreCredentialConfiguration, credentialConfigControllerUpdateCredentialConfiguration, credentialOfferControllerGetOffer, healthControllerCheck, isDcApiAvailable, issuanceConfigControllerGetIssuanceConfigurations, issuanceConfigControllerStoreIssuanceConfiguration, issue, issueAndWait, keyControllerAddKey, keyControllerDeleteKey, keyControllerGetKey, keyControllerGetKeys, keyControllerUpdateKey, oid4VciControllerCredential, oid4VciControllerNonce, oid4VciControllerNotifications, oid4VciMetadataControllerVct, oid4VpControllerGetPostRequestWithSession, oid4VpControllerGetRequestWithSession, oid4VpControllerGetResponse, presentationManagementControllerConfiguration, presentationManagementControllerDeleteConfiguration, presentationManagementControllerGetConfiguration, presentationManagementControllerStorePresentationConfig, presentationManagementControllerUpdateConfiguration, prometheusControllerIndex, registrarControllerCreateAccessCertificate, registrarControllerCreateConfig, registrarControllerDeleteConfig, registrarControllerGetConfig, registrarControllerUpdateConfig, sessionConfigControllerGetConfig, sessionConfigControllerResetConfig, sessionConfigControllerUpdateConfig, sessionControllerDeleteSession, sessionControllerGetAllSessions, sessionControllerGetSession, sessionControllerRevokeAll, statusListConfigControllerGetConfig, statusListConfigControllerResetConfig, statusListConfigControllerUpdateConfig, statusListControllerGetList, statusListControllerGetStatusListAggregation, statusListManagementControllerCreateList, statusListManagementControllerDeleteList, statusListManagementControllerGetList, statusListManagementControllerGetLists, statusListManagementControllerUpdateList, storageControllerDownload, storageControllerUpload, submitDcApiWalletResponse, tenantControllerDeleteTenant, tenantControllerGetTenant, tenantControllerGetTenants, tenantControllerInitTenant, tenantControllerUpdateTenant, trustListControllerCreateTrustList, trustListControllerDeleteTrustList, trustListControllerExportTrustList, trustListControllerGetAllTrustLists, trustListControllerGetTrustList, trustListControllerGetTrustListVersion, trustListControllerGetTrustListVersions, trustListControllerUpdateTrustList, trustListPublicControllerGetTrustListJwt, verifierOfferControllerGetOffer, verify, verifyAndWait, verifyWithDcApi, wellKnownControllerAuthzMetadata0, wellKnownControllerAuthzMetadata1, wellKnownControllerGetJwks0, wellKnownControllerGetJwks1, wellKnownControllerIssuerMetadata0, wellKnownControllerIssuerMetadata1 };
|
|
1789
1866
|
//# sourceMappingURL=index.mjs.map
|
|
1790
1867
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED