@didit-protocol/sdk-web 0.1.0
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/LICENSE +21 -0
- package/README.md +410 -0
- package/dist/didit-sdk.cjs.js +738 -0
- package/dist/didit-sdk.cjs.js.map +1 -0
- package/dist/didit-sdk.esm.js +732 -0
- package/dist/didit-sdk.esm.js.map +1 -0
- package/dist/didit-sdk.umd.js +744 -0
- package/dist/didit-sdk.umd.js.map +1 -0
- package/dist/didit-sdk.umd.min.js +7 -0
- package/dist/didit-sdk.umd.min.js.map +1 -0
- package/dist/index.d.ts +95 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Didit
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
# DiditSDK for Web
|
|
2
|
+
|
|
3
|
+
A lightweight JavaScript/TypeScript SDK for embedding Didit identity verification in web applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎯 **Simple API** - Singleton pattern with easy-to-use methods
|
|
8
|
+
- 🔐 **Flexible Integration** - Use UniLink URL directly or create sessions via backend
|
|
9
|
+
- 📱 **Responsive** - Works on desktop and mobile browsers
|
|
10
|
+
- 🎨 **Customizable** - Configuration options for styling and behavior
|
|
11
|
+
- 📦 **Multiple Formats** - ESM, CommonJS, and UMD builds
|
|
12
|
+
- 🔷 **TypeScript** - Full type definitions included
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
### NPM/Yarn
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @didit-protocol/sdk-web
|
|
20
|
+
# or
|
|
21
|
+
yarn add @didit-protocol/sdk-web
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### CDN (UMD)
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
<script src="https://unpkg.com/@didit-protocol/sdk-web/dist/didit-sdk.umd.min.js"></script>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### ES Modules / TypeScript
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { DiditSdk } from '@didit-protocol/sdk-web';
|
|
36
|
+
|
|
37
|
+
// Set up completion callback
|
|
38
|
+
DiditSdk.shared.onComplete = (result) => {
|
|
39
|
+
switch (result.type) {
|
|
40
|
+
case 'completed':
|
|
41
|
+
console.log('Verification completed!');
|
|
42
|
+
console.log('Session ID:', result.session?.sessionId);
|
|
43
|
+
console.log('Status:', result.session?.status);
|
|
44
|
+
break;
|
|
45
|
+
case 'cancelled':
|
|
46
|
+
console.log('User cancelled verification');
|
|
47
|
+
break;
|
|
48
|
+
case 'failed':
|
|
49
|
+
console.error('Verification failed:', result.error?.message);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Start verification with URL (from your backend or UniLink)
|
|
55
|
+
DiditSdk.shared.startVerification({
|
|
56
|
+
url: 'https://verify.didit.me/session/session-token'
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Script Tag (UMD)
|
|
61
|
+
|
|
62
|
+
```html
|
|
63
|
+
<script src="https://unpkg.com/@didit-protocol/sdk-web/dist/didit-sdk.umd.min.js"></script>
|
|
64
|
+
<script>
|
|
65
|
+
const { DiditSdk } = DiditSDK;
|
|
66
|
+
|
|
67
|
+
DiditSdk.shared.onComplete = (result) => {
|
|
68
|
+
if (result.type === 'completed') {
|
|
69
|
+
alert('Verification completed: ' + result.session.status);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
function startVerification() {
|
|
74
|
+
DiditSdk.shared.startVerification({
|
|
75
|
+
// You can get this link by clicking on "copy link" in the workflows view
|
|
76
|
+
url: 'https://verify.didit.me/u/WORKFLOW_ID_IN_BASE_64'
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<button onclick="startVerification()">Verify Identity</button>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Integration Methods
|
|
85
|
+
|
|
86
|
+
There are two ways to integrate the SDK:
|
|
87
|
+
|
|
88
|
+
### Method 1: UniLink URL (Simplest)
|
|
89
|
+
|
|
90
|
+
Use your workflow's UniLink URL directly from the Didit Console. No backend required.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
DiditSdk.shared.startVerification({
|
|
94
|
+
// You can get this link by clicking on "copy link" in the workflows view
|
|
95
|
+
url: 'https://verify.didit.me/u/WORKFLOW_ID_IN_BASE_64'
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Get your UniLink URL from the [Didit Console](https://business.didit.me) → Your Workflow → Copy Link.
|
|
100
|
+
|
|
101
|
+
### Method 2: Backend Session (Recommended for production)
|
|
102
|
+
|
|
103
|
+
Your backend creates a session via the Didit API and returns the verification URL. This gives you more control over session creation, user tracking, and security.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// Get the verification URL from your backend
|
|
107
|
+
const { url } = await yourBackend.createVerificationSession();
|
|
108
|
+
|
|
109
|
+
DiditSdk.shared.startVerification({
|
|
110
|
+
url,
|
|
111
|
+
configuration: {
|
|
112
|
+
loggingEnabled: true
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### Session Creation Options
|
|
118
|
+
|
|
119
|
+
When creating sessions via your backend, you can include additional parameters:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
// Example backend request body to Didit API
|
|
123
|
+
{
|
|
124
|
+
"vendor_data": "user-123", // Your user identifier
|
|
125
|
+
"metadata": "{\"source\": \"web\"}", // Custom JSON metadata
|
|
126
|
+
"contact_details": { // Prefill contact info
|
|
127
|
+
"email": "user@example.com",
|
|
128
|
+
"phone": "+14155552671",
|
|
129
|
+
"send_notification_emails": true
|
|
130
|
+
},
|
|
131
|
+
"expected_details": { // Cross-validation data
|
|
132
|
+
"first_name": "John",
|
|
133
|
+
"last_name": "Doe",
|
|
134
|
+
"date_of_birth": "1990-05-15",
|
|
135
|
+
"country": "USA"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Configuration
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
interface DiditSdkConfiguration {
|
|
144
|
+
/**
|
|
145
|
+
* Enable SDK logging for debugging
|
|
146
|
+
* @default false
|
|
147
|
+
*/
|
|
148
|
+
loggingEnabled?: boolean;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Custom container element to mount the modal
|
|
152
|
+
* @default document.body
|
|
153
|
+
*/
|
|
154
|
+
containerElement?: HTMLElement;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Z-index for the modal overlay
|
|
158
|
+
* @default 9999
|
|
159
|
+
*/
|
|
160
|
+
zIndex?: number;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Show close button on modal
|
|
164
|
+
* @default true
|
|
165
|
+
*/
|
|
166
|
+
showCloseButton?: boolean;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Show exit confirmation dialog when closing
|
|
170
|
+
* @default true
|
|
171
|
+
*/
|
|
172
|
+
showExitConfirmation?: boolean;
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Verification Results
|
|
177
|
+
|
|
178
|
+
The SDK returns three types of results:
|
|
179
|
+
|
|
180
|
+
### Completed
|
|
181
|
+
|
|
182
|
+
Verification flow finished (approved, pending, or declined).
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
{
|
|
186
|
+
type: 'completed',
|
|
187
|
+
session: {
|
|
188
|
+
sessionId: 'session-uuid',
|
|
189
|
+
status: 'Approved' | 'Pending' | 'Declined',
|
|
190
|
+
country: 'USA', // ISO 3166-1 alpha-3
|
|
191
|
+
documentType: 'passport'
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Cancelled
|
|
197
|
+
|
|
198
|
+
User closed the verification modal.
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
{
|
|
202
|
+
type: 'cancelled',
|
|
203
|
+
session: {
|
|
204
|
+
sessionId: 'session-uuid',
|
|
205
|
+
status: 'Pending',
|
|
206
|
+
// ...
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Failed
|
|
212
|
+
|
|
213
|
+
An error occurred during verification.
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
{
|
|
217
|
+
type: 'failed',
|
|
218
|
+
error: {
|
|
219
|
+
type: 'sessionExpired' | 'networkError' | 'cameraAccessDenied' | 'unknown',
|
|
220
|
+
message: 'Your verification session has expired.'
|
|
221
|
+
},
|
|
222
|
+
session: { /* if available */ }
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Contact Details
|
|
227
|
+
|
|
228
|
+
When creating sessions via your backend, you can provide contact details to prefill verification forms and enable notifications:
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
interface ContactDetails {
|
|
232
|
+
/** Email address for verification and notifications */
|
|
233
|
+
email?: string;
|
|
234
|
+
|
|
235
|
+
/** Send status update emails to user */
|
|
236
|
+
sendNotificationEmails?: boolean;
|
|
237
|
+
|
|
238
|
+
/** Language code (ISO 639-1) for emails */
|
|
239
|
+
emailLang?: string;
|
|
240
|
+
|
|
241
|
+
/** Phone number in E.164 format (e.g., "+14155552671") */
|
|
242
|
+
phone?: string;
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Expected Details
|
|
247
|
+
|
|
248
|
+
When creating sessions via your backend, you can provide expected user details for cross-validation with extracted document data:
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
interface ExpectedDetails {
|
|
252
|
+
firstName?: string; // Fuzzy comparison
|
|
253
|
+
lastName?: string; // Fuzzy comparison
|
|
254
|
+
dateOfBirth?: string; // YYYY-MM-DD format
|
|
255
|
+
gender?: string; // "M" or "F"
|
|
256
|
+
nationality?: string; // ISO 3166-1 alpha-3
|
|
257
|
+
country?: string; // ISO 3166-1 alpha-3
|
|
258
|
+
address?: string; // Full address
|
|
259
|
+
identificationNumber?: string;
|
|
260
|
+
ipAddress?: string; // Expected IP
|
|
261
|
+
portraitImage?: string; // Base64 encoded (max 1MB)
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## State Management
|
|
266
|
+
|
|
267
|
+
You can observe the SDK state for custom UI:
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
DiditSdk.shared.onStateChange = (state, error) => {
|
|
271
|
+
switch (state) {
|
|
272
|
+
case 'idle':
|
|
273
|
+
// Ready to start
|
|
274
|
+
break;
|
|
275
|
+
case 'loading':
|
|
276
|
+
// Loading verification iframe
|
|
277
|
+
showLoadingSpinner();
|
|
278
|
+
break;
|
|
279
|
+
case 'ready':
|
|
280
|
+
// Verification in progress
|
|
281
|
+
hideLoadingSpinner();
|
|
282
|
+
break;
|
|
283
|
+
case 'error':
|
|
284
|
+
// Error occurred
|
|
285
|
+
showError(error);
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
// Check current state
|
|
291
|
+
console.log(DiditSdk.shared.state);
|
|
292
|
+
|
|
293
|
+
// Check if verification is presented
|
|
294
|
+
console.log(DiditSdk.shared.isPresented);
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## API Reference
|
|
298
|
+
|
|
299
|
+
### DiditSdk.shared
|
|
300
|
+
|
|
301
|
+
The singleton SDK instance.
|
|
302
|
+
|
|
303
|
+
### Methods
|
|
304
|
+
|
|
305
|
+
| Method | Description |
|
|
306
|
+
|--------|-------------|
|
|
307
|
+
| `startVerification(options)` | Start the verification flow |
|
|
308
|
+
| `close()` | Programmatically close the verification modal |
|
|
309
|
+
| `destroy()` | Destroy the SDK instance and clean up |
|
|
310
|
+
|
|
311
|
+
### Properties
|
|
312
|
+
|
|
313
|
+
| Property | Type | Description |
|
|
314
|
+
|----------|------|-------------|
|
|
315
|
+
| `state` | `DiditSdkState` | Current SDK state |
|
|
316
|
+
| `configuration` | `DiditSdkConfiguration` | Current configuration |
|
|
317
|
+
| `isPresented` | `boolean` | Whether verification modal is open |
|
|
318
|
+
| `errorMessage` | `string` | Error message (when in error state) |
|
|
319
|
+
|
|
320
|
+
### Callbacks
|
|
321
|
+
|
|
322
|
+
| Callback | Parameters | Description |
|
|
323
|
+
|----------|------------|-------------|
|
|
324
|
+
| `onComplete` | `(result: VerificationResult)` | Called when verification finishes |
|
|
325
|
+
| `onStateChange` | `(state: DiditSdkState, error?: string)` | Called on state changes |
|
|
326
|
+
| `onEvent` | `(event: VerificationEvent)` | Called on granular verification events |
|
|
327
|
+
|
|
328
|
+
## Granular Events
|
|
329
|
+
|
|
330
|
+
Track verification progress with the `onEvent` callback:
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
DiditSdk.shared.onEvent = (event) => {
|
|
334
|
+
console.log('Event:', event.type, event.data);
|
|
335
|
+
};
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Event Reference
|
|
339
|
+
|
|
340
|
+
| Event | Description | Data Payload |
|
|
341
|
+
|-------|-------------|--------------|
|
|
342
|
+
| `didit:ready` | Verification iframe loaded | `{ sessionId? }` |
|
|
343
|
+
| `didit:started` | User started verification | `{ sessionId? }` |
|
|
344
|
+
| `didit:step_started` | A verification step began | `{ step, sessionId? }` |
|
|
345
|
+
| `didit:step_completed` | A step finished successfully | `{ step, nextStep?, sessionId? }` |
|
|
346
|
+
| `didit:step_changed` | Current step changed | `{ step, previousStep?, sessionId? }` |
|
|
347
|
+
| `didit:media_started` | Camera/media capture started | `{ step, mediaType }` |
|
|
348
|
+
| `didit:media_captured` | Photo/video captured | `{ step, isAuto }` |
|
|
349
|
+
| `didit:document_selected` | User selected document type and country | `{ documentType, country }` |
|
|
350
|
+
| `didit:verification_submitted` | Data submitted for processing | `{ step, sessionId? }` |
|
|
351
|
+
| `didit:code_sent` | OTP code sent | `{ step, channel?, codeSize?, sessionId? }` |
|
|
352
|
+
| `didit:code_verified` | OTP code verified | `{ step, sessionId? }` |
|
|
353
|
+
| `didit:status_updated` | Session status changed | `{ status, previousStep?, sessionId? }` |
|
|
354
|
+
| `didit:completed` | Verification flow completed | `{ sessionId?, status?, country?, documentType? }` |
|
|
355
|
+
| `didit:cancelled` | User cancelled verification | `{ sessionId? }` |
|
|
356
|
+
| `didit:error` | An error occurred | `{ error, step?, sessionId? }` |
|
|
357
|
+
| `didit:close_request` | User requested to close modal | (no data) |
|
|
358
|
+
|
|
359
|
+
### Step Values
|
|
360
|
+
|
|
361
|
+
The `step` field can be one of:
|
|
362
|
+
- `document_selection` - Document type selection
|
|
363
|
+
- `document_front` - Front side of document
|
|
364
|
+
- `document_back` - Back side of document
|
|
365
|
+
- `face` - Face/liveness verification
|
|
366
|
+
- `email` - Email verification
|
|
367
|
+
- `phone` - Phone verification
|
|
368
|
+
- `poa` - Proof of address
|
|
369
|
+
- `questionnaire` - Questionnaire step
|
|
370
|
+
|
|
371
|
+
### Channel Values
|
|
372
|
+
|
|
373
|
+
The `channel` field in `code_sent` can be:
|
|
374
|
+
- `email` - Code sent via email
|
|
375
|
+
- `sms` - Code sent via SMS
|
|
376
|
+
- `whatsapp` - Code sent via WhatsApp
|
|
377
|
+
|
|
378
|
+
### Code Size
|
|
379
|
+
|
|
380
|
+
The `codeSize` field in `code_sent` indicates the OTP code length (e.g., 4 or 6 digits).
|
|
381
|
+
|
|
382
|
+
## Browser Support
|
|
383
|
+
|
|
384
|
+
- Chrome 70+
|
|
385
|
+
- Firefox 65+
|
|
386
|
+
- Safari 12+
|
|
387
|
+
- Edge 79+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
Open http://localhost:3000 in your browser.
|
|
391
|
+
|
|
392
|
+
## Building
|
|
393
|
+
|
|
394
|
+
```bash
|
|
395
|
+
# Install dependencies
|
|
396
|
+
npm install
|
|
397
|
+
|
|
398
|
+
# Build for production
|
|
399
|
+
npm run build
|
|
400
|
+
|
|
401
|
+
# Watch mode for development
|
|
402
|
+
npm run build:watch
|
|
403
|
+
|
|
404
|
+
# Type check
|
|
405
|
+
npm run typecheck
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
## License
|
|
409
|
+
|
|
410
|
+
Copyright © 2026 Didit. All rights reserved.
|