@simprints/simface-sdk 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/README.md +256 -0
- package/dist/simface-sdk.js +4761 -0
- package/dist/simface-sdk.umd.cjs +155 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# SimFace SDK
|
|
2
|
+
|
|
3
|
+
SimFace SDK provides facial recognition for web-based KYC workflows. It is a drop-in Web Component and JavaScript API that handles camera capture, face quality validation, and communication with the SimFace backend.
|
|
4
|
+
|
|
5
|
+
Works in: all modern browsers, WhatsApp in-app browser, and mobile WebViews.
|
|
6
|
+
|
|
7
|
+
This repository is the public frontend SDK and demo repo for SimFace. For frontend architecture and contributor setup, see [docs/architecture.md](docs/architecture.md) and [docs/development.md](docs/development.md).
|
|
8
|
+
|
|
9
|
+
The backend API, infrastructure, and TensorFlow Lite runtime live in the separate private backend repository.
|
|
10
|
+
|
|
11
|
+
In standard browsers, the SDK uses an in-page camera flow powered by `getUserMedia()`. In WhatsApp, it falls back to the native capture handoff because that path is more reliable in the in-app browser.
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
### 1. Include the SDK
|
|
16
|
+
|
|
17
|
+
Via npm or a private registry after publishing the package:
|
|
18
|
+
```bash
|
|
19
|
+
npm install @simprints/simface-sdk
|
|
20
|
+
```
|
|
21
|
+
```javascript
|
|
22
|
+
import { enroll, verify } from '@simprints/simface-sdk';
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Directly in a webpage from the latest GitHub release:
|
|
26
|
+
|
|
27
|
+
1. Open the latest GitHub release for this repository.
|
|
28
|
+
2. Download the `simface-sdk-<version>-dist.tgz` asset.
|
|
29
|
+
3. Extract the archive and copy `dist/simface-sdk.js` into your app's static assets, for example `public/vendor/simface-sdk.js`.
|
|
30
|
+
4. Reference the copied file from your page:
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<script type="module" src="/vendor/simface-sdk.js"></script>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
From this repository:
|
|
37
|
+
```bash
|
|
38
|
+
npm install
|
|
39
|
+
npm run build
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Then publish or serve the generated files from `dist/`.
|
|
43
|
+
The generated library files are:
|
|
44
|
+
|
|
45
|
+
- `dist/simface-sdk.js` (ES module)
|
|
46
|
+
- `dist/simface-sdk.umd.cjs` (UMD/CommonJS build)
|
|
47
|
+
|
|
48
|
+
### 2. Configure
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
const config = {
|
|
52
|
+
apiUrl: 'https://your-simface-api.run.app',
|
|
53
|
+
projectId: 'your-project-id',
|
|
54
|
+
apiKey: 'your-api-key',
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 3. Enroll a User
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
import { enroll } from '@simprints/simface-sdk';
|
|
62
|
+
|
|
63
|
+
const result = await enroll(config, 'unique-user-id');
|
|
64
|
+
|
|
65
|
+
if (result.success) {
|
|
66
|
+
console.log('User enrolled successfully!');
|
|
67
|
+
} else if (result.alreadyEnrolled) {
|
|
68
|
+
console.log('User is already enrolled - use verify() instead.');
|
|
69
|
+
} else {
|
|
70
|
+
console.log('Enrollment failed:', result.message);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 4. Verify a User
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
import { verify } from '@simprints/simface-sdk';
|
|
78
|
+
|
|
79
|
+
const result = await verify(config, 'unique-user-id');
|
|
80
|
+
|
|
81
|
+
if (result.match) {
|
|
82
|
+
console.log(`Identity verified! (score: ${result.score})`);
|
|
83
|
+
} else if (result.notEnrolled) {
|
|
84
|
+
console.log('User not enrolled - use enroll() first.');
|
|
85
|
+
} else {
|
|
86
|
+
console.log(`Verification failed (score: ${result.score}, threshold: ${result.threshold})`);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Try the local demo
|
|
91
|
+
|
|
92
|
+
Build the SDK at the repository root, then run the demo:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npm install
|
|
96
|
+
npm run build
|
|
97
|
+
|
|
98
|
+
cd demo
|
|
99
|
+
npm install
|
|
100
|
+
npm run dev
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The demo runs at `http://localhost:4173` and consumes the built SDK artifact from `dist/`.
|
|
104
|
+
|
|
105
|
+
## Web Component
|
|
106
|
+
|
|
107
|
+
For more control over the UI, use the `<simface-capture>` Web Component directly:
|
|
108
|
+
|
|
109
|
+
```html
|
|
110
|
+
<simface-capture label="Take a selfie for verification"></simface-capture>
|
|
111
|
+
|
|
112
|
+
<script type="module">
|
|
113
|
+
import '@simprints/simface-sdk';
|
|
114
|
+
import { SimFaceAPIClient } from '@simprints/simface-sdk';
|
|
115
|
+
|
|
116
|
+
const captureEl = document.querySelector('simface-capture');
|
|
117
|
+
const client = new SimFaceAPIClient({
|
|
118
|
+
apiUrl: 'https://your-simface-api.run.app',
|
|
119
|
+
projectId: 'your-project-id',
|
|
120
|
+
apiKey: 'your-api-key',
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
captureEl.addEventListener('simface-captured', async (e) => {
|
|
124
|
+
const { imageBlob } = e.detail;
|
|
125
|
+
const result = await client.verify('user-123', imageBlob);
|
|
126
|
+
console.log('Verify result:', result);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
captureEl.addEventListener('simface-cancelled', () => {
|
|
130
|
+
console.log('User cancelled capture');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
captureEl.addEventListener('simface-error', (e) => {
|
|
134
|
+
console.error('Capture error:', e.detail.error);
|
|
135
|
+
});
|
|
136
|
+
</script>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Component Attributes
|
|
140
|
+
|
|
141
|
+
| Attribute | Type | Default | Description |
|
|
142
|
+
|-----------|------|---------|-------------|
|
|
143
|
+
| `label` | String | `"Take a selfie"` | Instructional text shown on the capture button |
|
|
144
|
+
|
|
145
|
+
### Events
|
|
146
|
+
|
|
147
|
+
| Event | Detail | Description |
|
|
148
|
+
|-------|--------|-------------|
|
|
149
|
+
| `simface-captured` | `{ imageBlob: Blob }` | Fires when a quality-checked face image is confirmed |
|
|
150
|
+
| `simface-cancelled` | - | Fires when the user cancels the capture flow |
|
|
151
|
+
| `simface-error` | `{ error: string }` | Fires on capture/detection errors |
|
|
152
|
+
|
|
153
|
+
## API Reference
|
|
154
|
+
|
|
155
|
+
### `enroll(config, clientId): Promise<EnrollResult>`
|
|
156
|
+
|
|
157
|
+
Opens the camera, captures a face image with quality validation, and enrolls the user.
|
|
158
|
+
|
|
159
|
+
Parameters:
|
|
160
|
+
|
|
161
|
+
| Parameter | Type | Description |
|
|
162
|
+
|-----------|------|-------------|
|
|
163
|
+
| `config` | `SimFaceConfig` | SDK configuration (`apiUrl`, `projectId`, `apiKey`) |
|
|
164
|
+
| `clientId` | `string` | Unique identifier for the user |
|
|
165
|
+
|
|
166
|
+
Returns `EnrollResult`:
|
|
167
|
+
```typescript
|
|
168
|
+
{
|
|
169
|
+
success: boolean;
|
|
170
|
+
clientId: string;
|
|
171
|
+
message?: string;
|
|
172
|
+
alreadyEnrolled?: boolean;
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### `verify(config, clientId): Promise<VerifyResult>`
|
|
177
|
+
|
|
178
|
+
Opens the camera, captures a face image, and verifies against the enrolled face.
|
|
179
|
+
|
|
180
|
+
Parameters:
|
|
181
|
+
|
|
182
|
+
| Parameter | Type | Description |
|
|
183
|
+
|-----------|------|-------------|
|
|
184
|
+
| `config` | `SimFaceConfig` | SDK configuration (`apiUrl`, `projectId`, `apiKey`) |
|
|
185
|
+
| `clientId` | `string` | Unique identifier for the user |
|
|
186
|
+
|
|
187
|
+
Returns `VerifyResult`:
|
|
188
|
+
```typescript
|
|
189
|
+
{
|
|
190
|
+
match: boolean;
|
|
191
|
+
score: number;
|
|
192
|
+
threshold: number;
|
|
193
|
+
message?: string;
|
|
194
|
+
notEnrolled?: boolean;
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### `SimFaceConfig`
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
{
|
|
202
|
+
apiUrl: string;
|
|
203
|
+
projectId: string;
|
|
204
|
+
apiKey: string;
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Backend API Endpoints
|
|
209
|
+
|
|
210
|
+
For clients integrating directly with the REST API:
|
|
211
|
+
|
|
212
|
+
### `POST /api/v1/auth/validate`
|
|
213
|
+
Validate API credentials.
|
|
214
|
+
|
|
215
|
+
Body: `{ "projectId": "...", "apiKey": "..." }`
|
|
216
|
+
Response: `{ "valid": true, "projectId": "...", "name": "..." }`
|
|
217
|
+
|
|
218
|
+
### `POST /api/v1/enroll`
|
|
219
|
+
Enroll a new user.
|
|
220
|
+
|
|
221
|
+
Body: multipart form data with fields `projectId`, `apiKey`, `clientId`, `image`.
|
|
222
|
+
Response: `{ "success": true, "clientId": "..." }`
|
|
223
|
+
|
|
224
|
+
### `POST /api/v1/verify`
|
|
225
|
+
Verify a user against their enrollment.
|
|
226
|
+
|
|
227
|
+
Body: multipart form data with fields `projectId`, `apiKey`, `clientId`, `image`.
|
|
228
|
+
Response: `{ "match": true, "score": 0.85, "threshold": 0.6 }`
|
|
229
|
+
|
|
230
|
+
### `GET /api/v1/health`
|
|
231
|
+
Health check endpoint.
|
|
232
|
+
|
|
233
|
+
Response: `{ "status": "ok" }`
|
|
234
|
+
|
|
235
|
+
## Face Quality Checks
|
|
236
|
+
|
|
237
|
+
The SDK automatically performs these checks on captured images before submission:
|
|
238
|
+
|
|
239
|
+
1. Face presence - at least one face must be detected.
|
|
240
|
+
2. Single face - only one face should be in the frame.
|
|
241
|
+
3. Face size - face must not be too close or too far.
|
|
242
|
+
4. Centering - face must be approximately centered in the frame.
|
|
243
|
+
|
|
244
|
+
If a check fails, the user is prompted with specific guidance and asked to retake the photo.
|
|
245
|
+
|
|
246
|
+
## Browser Compatibility
|
|
247
|
+
|
|
248
|
+
| Browser | Camera Capture | Face Detection |
|
|
249
|
+
|---------|---------------|----------------|
|
|
250
|
+
| Chrome (Android/Desktop) | Yes | Yes |
|
|
251
|
+
| Safari (iOS/Desktop) | Yes | Yes |
|
|
252
|
+
| WhatsApp in-app browser | Yes (via native camera) | Yes |
|
|
253
|
+
| Firefox | Yes | Yes |
|
|
254
|
+
| Samsung Internet | Yes | Yes |
|
|
255
|
+
|
|
256
|
+
> Note: In WhatsApp's in-app browser, the camera opens via the device's native camera app rather than an in-browser preview. Face quality checks run after the photo is taken.
|