argus-face-sdk 0.0.0-stage → 0.1.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Daertho
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 CHANGED
@@ -1,3 +1,183 @@
1
- # Temporary Holding Version
1
+ # argus-face-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A TypeScript client for the Argus face verification API. It does three things:
4
+
5
+ - On your server, it checks that a selfie shows the person in an ID or photo (`POST /v1/face/verify`), and it reads and screens an ID document (`POST /v1/screen/id`).
6
+ - In the browser, it captures a live selfie and photographs the ID by camera, using Argus's own capture scripts.
7
+ - It turns errors into typed classes and shows which checks count towards a result and which are reported only.
8
+
9
+ Node 18 or later. No runtime dependencies.
10
+
11
+ ```sh
12
+ npm install argus-face-sdk
13
+ ```
14
+
15
+ ## Quickstart (server)
16
+
17
+ ```ts
18
+ import { ArgusFace, explainResult, ArgusError } from "argus-face-sdk";
19
+ import { readFile } from "node:fs/promises";
20
+
21
+ const argus = new ArgusFace({ apiKey: process.env.ARGUS_API_KEY! });
22
+
23
+ const result = await argus.verifyFace({
24
+ reference: await readFile("passport.jpg"), // ID page or a clear photo
25
+ selfie: await readFile("selfie.jpg"),
26
+ });
27
+
28
+ console.log(result.status); // "verified" | "review" | "failed"
29
+ console.log(result.reasons); // why it isn't "verified"
30
+
31
+ const x = explainResult(result);
32
+ x.counted; // checks that changed, or could change, the status
33
+ x.shadow; // reported for a reviewer, NOT counted: never show these as verdicts
34
+ ```
35
+
36
+ A result helps a person decide. It is not a certified biometric or liveness system, and it is not an automated identity decision. Review every `review` and `failed` result before you act on it.
37
+
38
+ Keep the key on your server. The constructor refuses to run in a web page, and the API sends no CORS headers anyway.
39
+
40
+ ## ID document plus selfie
41
+
42
+ ```ts
43
+ const { id, face } = await argus.verifyIdentity({
44
+ front: await readFile("id-front.jpg"),
45
+ back: await readFile("id-back.jpg"),
46
+ selfie: await readFile("selfie.jpg"),
47
+ applicantIp: req.ip, // optional: lets the shared IP/device check run
48
+ });
49
+
50
+ id.parsed.screening_query; // the name, DOB and country read from the ID
51
+ id.screening; // sanctions / PEP result for that identity (null if no name was readable)
52
+ face.status; // the face check, run with the name and DOB read from the ID
53
+ ```
54
+
55
+ `verifyIdentity` makes two charged calls, `screenId` and then `verifyFace`. If the face check fails, the thrown error carries the ID result in `error.idResult`. You can also call each step on its own:
56
+
57
+ | Method | Endpoint |
58
+ |---|---|
59
+ | `verifyFace(input)` | `POST /v1/face/verify` |
60
+ | `getFaceCheck(refId)` | `GET /v1/face/checks/{reference_document_id}` |
61
+ | `flashChallenge()` | `POST /v1/face/flash` |
62
+ | `config()` | `GET /v1/face/config` |
63
+ | `eraseTemplates(refId?)` | `DELETE /v1/face/templates` |
64
+ | `getClip(id)` / `deleteClip(id)` | `GET` / `DELETE /v1/face/clip/{id}` |
65
+ | `startIdCapture()` | `POST /v1/screen/id/capture/start` |
66
+ | `screenId(input)` | `POST /v1/screen/id` |
67
+ | `matchSelfieToId(docId, selfie)` | `POST /v1/screen/id/{doc_id}/face` |
68
+ | `usage()` | `GET /v1/founder/usage` (founder keys; others get `null`) |
69
+
70
+ Which of these a key may call depends on its scopes. A key without the right scope gets `ArgusPermissionError` (403). A partner face key needs `face_check` (the check and the flash challenge) and `face_data` (config, the ID-capture challenge, reading a check back, clips, erasing templates). Founder keys have both. Face Terminal keys have `face_check` only.
71
+
72
+ ## A lost answer
73
+
74
+ A face check takes tens of seconds, so a connection can drop before the answer arrives. Every `verifyFace` sends an `Idempotency-Key`: a new random one, or yours (`idempotencyKey: "applicant-42-try-1"`). If you send the same request with the same key again within 24 hours:
75
+
76
+ - **The first check finished:** you get its stored result with `replayed: true`. Nothing runs and nothing is charged.
77
+ - **It is still running:** you get `ArgusConflictError` (409). Wait a few seconds and send it again.
78
+ - **It failed:** the key is released and the check runs again.
79
+ - **Different images:** you get a 422.
80
+
81
+ On a network error, the key the SDK used is on the error as `error.idempotencyKey`. A finished check can also be read back with `getFaceCheck(result.reference_document_id)`.
82
+
83
+ ## Live capture (browser)
84
+
85
+ The page asks your server for a challenge, captures, and posts the files back to your server. Your server then calls Argus.
86
+
87
+ ```ts
88
+ // browser
89
+ import { loadArgusCapture, captureSelfie, captureIdDocument, toFormData } from "argus-face-sdk/browser";
90
+
91
+ await loadArgusCapture(); // liveness.js + doccap.js from the Argus static host (or self-host: { baseUrl })
92
+
93
+ const { flash, idChallenge } = await (await fetch("/kyc/challenges", { method: "POST" })).json();
94
+
95
+ const id = await captureIdDocument({ mount: idBox, challenge: idChallenge, botdUrl: "/vendor/botd-2.0.0.esm.js" });
96
+ const selfie = await captureSelfie({ video: videoEl, flash, onPrompt: (t) => (promptEl.textContent = t) });
97
+
98
+ await fetch("/kyc/submit", { method: "POST", body: toFormData({ id, selfie, consent: consentBox.checked }) });
99
+ ```
100
+
101
+ ```ts
102
+ // server: POST /kyc/challenges
103
+ res.json({ flash: await argus.flashChallenge(), idChallenge: await argus.startIdCapture() });
104
+
105
+ // server: POST /kyc/submit (form fields from toFormData)
106
+ const clip = form.get("selfie_clip");
107
+ const { id, face } = await argus.verifyIdentity({
108
+ front: form.get("id_front"), back: form.get("id_back") ?? undefined,
109
+ idLive: { clip: form.get("id_clip"), capture: JSON.parse(form.get("id_capture")) },
110
+ selfie: form.get("selfie"),
111
+ liveness: clip && form.get("consent") === "granted"
112
+ ? { clip, challenge: JSON.parse(form.get("selfie_challenge")), consent: true }
113
+ : undefined,
114
+ applicantIp: req.ip,
115
+ });
116
+ ```
117
+
118
+ Some points about the capture:
119
+
120
+ - **Timing.** The flash challenge is good for about 2 minutes, can be used once, and only by the key that asked for it. The ID challenge is good for 10 minutes. Ask for each just before you need it.
121
+ - **Consent.** A selfie clip is sent only when the person has agreed for it to be stored (`consent: true`). The server keeps it encrypted until its retention window ends. `deleteClip` removes it sooner.
122
+ - **Liveness off.** If liveness is off on the server (`config().liveness === false`), the clip is ignored and `result.liveness` is `null`.
123
+ - **Trust.** `challenge.passed` and the device report come from the person's own browser. They are evidence for a reviewer, not proof of liveness.
124
+ - **BotD.** Both scripts load BotD from `vendor/botd-2.0.0.esm.js` next to themselves, which Argus serves with CORS. To self-host it, pass `botdUrl` to `captureSelfie` and `captureIdDocument`. liveness.js loads MediaPipe from cdn.jsdelivr.net and storage.googleapis.com, so allow those hosts, and the Argus host, in your Content-Security-Policy.
125
+ - **Live ID capture in the face check.** Pass the ID capture to `verifyFace` as `idLive`, or use `verifyIdentity`, which sends it with the ID screen.
126
+
127
+ ## What counts and what is reported only
128
+
129
+ The server sends a `mode` with each liveness and fraud check. `explainResult` sorts every check into one of three groups:
130
+
131
+ | Effect | Checks |
132
+ |---|---|
133
+ | `can_fail` | Face Match Analyst, Presentation-Attack Analyst, ID document checks (a `suspect` document fails) |
134
+ | `can_hold_at_review` | SFace matcher and Silent-Face anti-spoof: a miss holds a would-be `verified` at `review`, never fails. Also the on-device challenge, and any check below whose mode is `gate` |
135
+ | `reported_only` | pulse, screen flash, device integrity, live ID capture, apparent age, same face on another application (1:N), shared IP/device, whenever their mode is `shadow` (the server default) |
136
+
137
+ Show a `reported_only` signal as context for a reviewer, never as a pass or a fail. The 1:N same-face search runs only for API keys. It never runs for the Face Terminal, Screen Terminal or the web tools.
138
+
139
+ ## Errors
140
+
141
+ Every error is an `ArgusError` with `status`, `detail` (the server's text, never the key), `path` and `retryable`.
142
+
143
+ | Class | Status | Meaning |
144
+ |---|---|---|
145
+ | `ArgusValidationError` | 0, 400, 413, 415, 422 | Bad input. Status 0 means the SDK refused it before sending (empty file, over 12 MB, a type the API can't read such as HEIC, no consent for a clip) |
146
+ | `ArgusAuthError` | 401 | Missing, wrong, revoked or expired key |
147
+ | `ArgusAllowanceError` | 402 | Allowance used up (founder units, prepaid checks) |
148
+ | `ArgusPermissionError` | 403 | The key's scopes don't cover this endpoint, or face checks aren't on for the key |
149
+ | `ArgusNotFoundError` | 404 | No such document, clip or check for this key, or the feature is off (flash) |
150
+ | `ArgusConflictError` | 409 | A check with this Idempotency-Key is still running. Retryable |
151
+ | `ArgusRateLimitError` | 429 | `reason: "rate_limit"` (per minute, retryable) or `"monthly_cap"` / `"monthly_quota"` (wait for the 1st, UTC) |
152
+ | `ArgusUpstreamError` | 502 | A model failed during the check. Retryable |
153
+ | `ArgusUnavailableError` | 503 | Not configured on this server, or metering briefly down |
154
+ | `ArgusNetworkError` | 0 | No answer, or the timeout (default 120 s). The server may still have run the check |
155
+
156
+ The SDK retries a per-minute 429 twice, with backoff (set `maxRateLimitRetries`). It retries nothing else automatically, because a retry can be charged again.
157
+
158
+ ## Cost
159
+
160
+ What a call costs depends on the key:
161
+
162
+ - **Partner key with a monthly quota.** A check (`verifyFace`, `screenId`, `matchSelfieToId`) counts one, and only once the server has accepted its input: a 400, 409, 413, 415 or 422 costs nothing, and neither does a replayed result. A 5xx is given back unless a model had already answered. `config`, `flashChallenge`, `startIdCapture`, `getFaceCheck`, clips and `eraseTemplates` are free, though still rate-limited. Each of these calls reports its cost:
163
+
164
+ ```ts
165
+ const argus = new ArgusFace({ apiKey, onCost: (c) => log(c) }); // { method, path, unitsCharged, quotaRemaining }
166
+ argus.lastCost; // the most recent call's cost (use onCost when calls run in parallel)
167
+ error.cost; // on a failed call, what it cost (usually unitsCharged: 0)
168
+ ```
169
+
170
+ `quotaRemaining` is the checks left this month, `"unlimited"` for a key without a quota, or `null` if the server couldn't read it.
171
+ - **Founder key.** A face check is 20 units by default, at EUR 0.005 a unit (Argus can change this). A sandbox check is free. `usage()` shows the month's units. The sandbox returns a fixture in the live shape; pass `sandboxFail: true` to get the failed one.
172
+ - **Face Terminal key** (`baseUrl: "https://face.unbackoffice.com"`). One prepaid check per valid `verifyFace`. Flash challenges are free. A 502 or 503 is given back.
173
+
174
+ ## Development
175
+
176
+ ```sh
177
+ npm ci
178
+ npm test # builds, then runs the unit tests against a fake fetch (no network, no key)
179
+ ```
180
+
181
+ ## Licence
182
+
183
+ MIT for this SDK. The Argus API it calls is a paid service under its own terms.
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Browser capture for the Argus face check. It wraps Argus's own capture scripts:
3
+ * - liveness.js: selfie with a randomised on-device action challenge (MediaPipe) and the screen-flash colours,
4
+ * - doccap.js: the ID photographed by camera, front and back, with the server's signed movement challenge.
5
+ * It holds no API key and calls no Argus endpoint. Your server gets the challenges (ArgusFace.flashChallenge,
6
+ * ArgusFace.startIdCapture), hands them to the page, and receives the files back to send to Argus.
7
+ *
8
+ * What the capture proves: little on its own. The on-device result and the device report come from a browser the
9
+ * person controls; the server treats them as evidence for a reviewer. Never treat `challenge.passed` as liveness.
10
+ */
11
+ import type { FlashChallenge, IdCaptureChallenge } from "./types.js";
12
+ declare global {
13
+ interface Window {
14
+ ArgusLiveness?: {
15
+ run(opts: Record<string, unknown>): Promise<{
16
+ clip: Blob | null;
17
+ still: Blob | null;
18
+ challenge: Record<string, unknown>;
19
+ }>;
20
+ LABELS: Record<string, string>;
21
+ };
22
+ ArgusDocCapture?: {
23
+ run(opts: Record<string, unknown>): Promise<{
24
+ front: Blob;
25
+ back: Blob | null;
26
+ clip: Blob | null;
27
+ capture: Record<string, unknown>;
28
+ }>;
29
+ LABELS?: Record<string, string>;
30
+ };
31
+ }
32
+ }
33
+ export interface LoadOptions {
34
+ /** Where the scripts are served. Default https://argus.unbackoffice.com/static. Self-host them to pin a version. */
35
+ baseUrl?: string;
36
+ /** Full URLs, if you host the two files under other names. */
37
+ livenessUrl?: string;
38
+ docCaptureUrl?: string;
39
+ /** Which to load (default both). */
40
+ load?: Array<"liveness" | "doccap">;
41
+ /** Subresource-integrity hashes for the scripts, if you pin a copy. */
42
+ integrity?: {
43
+ liveness?: string;
44
+ doccap?: string;
45
+ };
46
+ }
47
+ /** Load liveness.js and/or doccap.js once. Resolves when window.ArgusLiveness / window.ArgusDocCapture exist. */
48
+ export declare function loadArgusCapture(opts?: LoadOptions): Promise<void>;
49
+ export interface SelfieCaptureOptions {
50
+ /** A <video> element to show the camera in (playsinline, muted). */
51
+ video: HTMLVideoElement;
52
+ /** From your server: ArgusFace.flashChallenge(). Start the capture within its 2 minutes. Omit to skip the flash. */
53
+ flash?: FlashChallenge | null;
54
+ /** Restrict the actions liveness.js picks from (it picks two). Default: all five. */
55
+ challenges?: string[];
56
+ /** BotD 2.0.0 (ESM) URL. Default: vendor/botd-2.0.0.esm.js next to liveness.js (served with CORS by Argus). */
57
+ botdUrl?: string;
58
+ onPrompt?: (text: string) => void;
59
+ onStatus?: (text: string) => void;
60
+ }
61
+ export interface SelfieCapture {
62
+ /** The neutral still, to send as `selfie`. Null if the camera never gave a frame. */
63
+ selfie: Blob | null;
64
+ /** The recording, to send as the liveness clip. Null when the browser can't record. */
65
+ clip: Blob | null;
66
+ /**
67
+ * The browser's report: {passed, degraded, steps, flash, device}. Send it unchanged. `passed` is the on-device
68
+ * reading only; the server decides what counts.
69
+ */
70
+ challenge: Record<string, unknown>;
71
+ }
72
+ /** Run the live selfie capture (camera, action challenge, optional screen flash). Needs loadArgusCapture first. */
73
+ export declare function captureSelfie(opts: SelfieCaptureOptions): Promise<SelfieCapture>;
74
+ export interface IdCaptureOptions {
75
+ /** An element the capture UI is drawn into. */
76
+ mount: HTMLElement;
77
+ /** From your server: ArgusFace.startIdCapture(). */
78
+ challenge: IdCaptureChallenge;
79
+ /** 'both' for an ID card or licence (default), 'front' for a passport data page. */
80
+ sides?: "both" | "front";
81
+ /** 'id1' card (default) or 'td3' passport page. */
82
+ docType?: "id1" | "td3";
83
+ /** BotD 2.0.0 (ESM) URL. Default: vendor/botd-2.0.0.esm.js next to doccap.js (served with CORS by Argus). */
84
+ botdUrl?: string;
85
+ maxClipMs?: number;
86
+ onStatus?: (text: string) => void;
87
+ }
88
+ export interface IdCapture {
89
+ front: Blob;
90
+ back: Blob | null;
91
+ clip: Blob | null;
92
+ /** {token, marks, guide, device, ...}: send unchanged as the capture report. */
93
+ capture: Record<string, unknown>;
94
+ }
95
+ /**
96
+ * Photograph the ID by camera with the signed movement challenge. Rejects with an Error whose `.code` is
97
+ * 'cancelled' | 'denied' | 'nocamera' | 'unsupported' | 'timeout'.
98
+ */
99
+ export declare function captureIdDocument(opts: IdCaptureOptions): Promise<IdCapture>;
100
+ export interface UploadParts {
101
+ selfie?: SelfieCapture | null;
102
+ id?: IdCapture | null;
103
+ /** The person ticked the consent box for their capture clip. Without it the selfie clip is left out. */
104
+ consent?: boolean;
105
+ }
106
+ /**
107
+ * The captures as one FormData for YOUR backend, with these field names:
108
+ * selfie, selfie_clip, selfie_challenge, consent, id_front, id_back, id_clip, id_capture.
109
+ * On the server, turn them back into ArgusFace inputs (see the README).
110
+ */
111
+ export declare function toFormData(parts: UploadParts): FormData;
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Browser capture for the Argus face check. It wraps Argus's own capture scripts:
3
+ * - liveness.js: selfie with a randomised on-device action challenge (MediaPipe) and the screen-flash colours,
4
+ * - doccap.js: the ID photographed by camera, front and back, with the server's signed movement challenge.
5
+ * It holds no API key and calls no Argus endpoint. Your server gets the challenges (ArgusFace.flashChallenge,
6
+ * ArgusFace.startIdCapture), hands them to the page, and receives the files back to send to Argus.
7
+ *
8
+ * What the capture proves: little on its own. The on-device result and the device report come from a browser the
9
+ * person controls; the server treats them as evidence for a reviewer. Never treat `challenge.passed` as liveness.
10
+ */
11
+ const DEFAULT_STATIC = "https://argus.unbackoffice.com/static";
12
+ function inject(src, integrity) {
13
+ return new Promise((resolve, reject) => {
14
+ const existing = document.querySelector(`script[data-argus-src="${CSS.escape(src)}"]`);
15
+ if (existing?.dataset.argusLoaded === "1")
16
+ return resolve();
17
+ const s = existing ?? document.createElement("script");
18
+ s.addEventListener("load", () => { s.dataset.argusLoaded = "1"; resolve(); }, { once: true });
19
+ s.addEventListener("error", () => reject(new Error(`could not load ${src}`)), { once: true });
20
+ if (!existing) {
21
+ s.src = src;
22
+ s.async = true;
23
+ s.dataset.argusSrc = src;
24
+ if (integrity) {
25
+ s.integrity = integrity;
26
+ s.crossOrigin = "anonymous";
27
+ }
28
+ document.head.appendChild(s);
29
+ }
30
+ });
31
+ }
32
+ /** Load liveness.js and/or doccap.js once. Resolves when window.ArgusLiveness / window.ArgusDocCapture exist. */
33
+ export async function loadArgusCapture(opts = {}) {
34
+ const base = (opts.baseUrl ?? DEFAULT_STATIC).replace(/\/+$/, "");
35
+ const which = opts.load ?? ["liveness", "doccap"];
36
+ const jobs = [];
37
+ if (which.includes("liveness") && !window.ArgusLiveness) {
38
+ jobs.push(inject(opts.livenessUrl ?? `${base}/liveness.js`, opts.integrity?.liveness));
39
+ }
40
+ if (which.includes("doccap") && !window.ArgusDocCapture) {
41
+ jobs.push(inject(opts.docCaptureUrl ?? `${base}/doccap.js`, opts.integrity?.doccap));
42
+ }
43
+ await Promise.all(jobs);
44
+ }
45
+ /** Run the live selfie capture (camera, action challenge, optional screen flash). Needs loadArgusCapture first. */
46
+ export async function captureSelfie(opts) {
47
+ const L = window.ArgusLiveness;
48
+ if (!L)
49
+ throw new Error("liveness.js is not loaded: call loadArgusCapture() first");
50
+ const r = await L.run({
51
+ video: opts.video,
52
+ flash: opts.flash && opts.flash.token ? opts.flash : null,
53
+ challenges: opts.challenges,
54
+ botdUrl: opts.botdUrl,
55
+ onPrompt: opts.onPrompt,
56
+ onStatus: opts.onStatus,
57
+ });
58
+ return { selfie: r.still ?? null, clip: r.clip ?? null, challenge: r.challenge ?? {} };
59
+ }
60
+ /**
61
+ * Photograph the ID by camera with the signed movement challenge. Rejects with an Error whose `.code` is
62
+ * 'cancelled' | 'denied' | 'nocamera' | 'unsupported' | 'timeout'.
63
+ */
64
+ export async function captureIdDocument(opts) {
65
+ const D = window.ArgusDocCapture;
66
+ if (!D)
67
+ throw new Error("doccap.js is not loaded: call loadArgusCapture() first");
68
+ const r = await D.run({
69
+ mount: opts.mount, challenge: opts.challenge, sides: opts.sides ?? "both", docType: opts.docType ?? "id1",
70
+ botdUrl: opts.botdUrl, maxClipMs: opts.maxClipMs, onStatus: opts.onStatus,
71
+ });
72
+ return { front: r.front, back: r.back ?? null, clip: r.clip ?? null, capture: r.capture ?? {} };
73
+ }
74
+ /**
75
+ * The captures as one FormData for YOUR backend, with these field names:
76
+ * selfie, selfie_clip, selfie_challenge, consent, id_front, id_back, id_clip, id_capture.
77
+ * On the server, turn them back into ArgusFace inputs (see the README).
78
+ */
79
+ export function toFormData(parts) {
80
+ const fd = new FormData();
81
+ const s = parts.selfie;
82
+ if (s?.selfie)
83
+ fd.append("selfie", s.selfie, "selfie.jpg");
84
+ if (s?.clip && parts.consent) {
85
+ fd.append("selfie_clip", s.clip, s.clip.type.includes("mp4") ? "selfie.mp4" : "selfie.webm");
86
+ fd.append("selfie_challenge", JSON.stringify(s.challenge));
87
+ fd.append("consent", "granted");
88
+ }
89
+ const id = parts.id;
90
+ if (id) {
91
+ fd.append("id_front", id.front, "id-front.jpg");
92
+ if (id.back)
93
+ fd.append("id_back", id.back, "id-back.jpg");
94
+ if (id.clip)
95
+ fd.append("id_clip", id.clip, id.clip.type.includes("mp4") ? "id.mp4" : "id.webm");
96
+ fd.append("id_capture", JSON.stringify(id.capture));
97
+ }
98
+ return fd;
99
+ }
@@ -0,0 +1,157 @@
1
+ import { type FileInput } from "./files.js";
2
+ import type { FaceConfig, FaceVerifyResult, FlashChallenge, FounderUsage, IdCaptureChallenge, IdFaceCheck, IdScreenResult } from "./types.js";
3
+ export declare const DEFAULT_BASE_URL = "https://argus.unbackoffice.com";
4
+ export interface ArgusFaceOptions {
5
+ /** Your Argus API key (`ak_...`). Keep it on your server. */
6
+ apiKey: string;
7
+ /** Default https://argus.unbackoffice.com. Must be https, except http://localhost / 127.0.0.1 for a local server. */
8
+ baseUrl?: string;
9
+ /** Per-request timeout in ms (default 120 000: a face check runs several models). */
10
+ timeoutMs?: number;
11
+ /**
12
+ * How many times to retry a 429 that is a per-minute rate limit (default 2). Those are refused before anything is
13
+ * charged. Nothing else is retried automatically: a 502 may already have been charged (see the README).
14
+ */
15
+ maxRateLimitRetries?: number;
16
+ /** Your own fetch (tests, proxies). Default: the global fetch (Node 18+). */
17
+ fetch?: typeof fetch;
18
+ /** Wait function used between retries (tests). */
19
+ sleep?: (ms: number) => Promise<void>;
20
+ /** Allow constructing the client in a browser. Don't: it exposes your key to every visitor. */
21
+ dangerouslyAllowBrowser?: boolean;
22
+ /**
23
+ * Called after every call that reports its cost (face and ID calls on a key with a monthly quota): what it
24
+ * counted and what is left this month. Safe with calls running at the same time, unlike `lastCost`.
25
+ */
26
+ onCost?: (cost: CallCost) => void;
27
+ }
28
+ /** What a call counted against a monthly quota, from the X-Argus-Units-Charged / X-Argus-Quota-Remaining headers. */
29
+ export interface CallCost {
30
+ method: string;
31
+ path: string;
32
+ /** 0 or 1. */
33
+ unitsCharged: number;
34
+ /** Checks left this month, "unlimited" for a key without a quota, or null when the server could not read it. */
35
+ quotaRemaining: number | "unlimited" | null;
36
+ }
37
+ /** A live selfie capture from `argus-face-sdk/browser` (or liveness.js): the clip and the challenge report. */
38
+ export interface LivenessCapture {
39
+ clip: FileInput;
40
+ /** The `challenge` object liveness.js resolved with (passed, steps, flash token + timings, device report). */
41
+ challenge: Record<string, unknown>;
42
+ /**
43
+ * Must be `true`: the person explicitly agreed to their capture clip being stored. The server refuses a clip without
44
+ * it, and keeps the clip encrypted until its retention window ends.
45
+ */
46
+ consent: true;
47
+ }
48
+ export interface VerifyFaceInput {
49
+ /** The ID document page or a clear photo of the person. */
50
+ reference: FileInput;
51
+ /** The selfie taken now (the still from a live capture, or an upload). */
52
+ selfie: FileInput;
53
+ /** The back of an ID card or licence: its MRZ / barcode is checked against the front. Never stored. */
54
+ back?: FileInput;
55
+ /** A live capture clip. Ignored by the server unless liveness is on there (`config().liveness`). */
56
+ liveness?: LivenessCapture;
57
+ /** What the person claims; the date of birth feeds the apparent-age check. */
58
+ claimed?: {
59
+ fullName?: string;
60
+ dateOfBirth?: string;
61
+ documentIssueDate?: string;
62
+ };
63
+ /** The applicant's IP address as your server saw it, for the shared-IP/device link check. */
64
+ applicantIp?: string;
65
+ /**
66
+ * A live ID capture of the reference (captureIdDocument after startIdCapture, same key). Its recording is analysed
67
+ * with the face check (in shadow unless Argus gates it) and not stored. Needs the face_data scope for startIdCapture.
68
+ */
69
+ idLive?: IdLiveCapture;
70
+ /**
71
+ * Sent as the Idempotency-Key header. A repeat with the same key and the same images returns the first check's
72
+ * result, uncharged, for 24 hours. Default: a new random key per call (reachable as `error.idempotencyKey` on a
73
+ * network error, so you can resend safely). Pass your own to tie it to your application; `false` sends none.
74
+ */
75
+ idempotencyKey?: string | false;
76
+ /** Sandbox keys only: return the failed fixture instead of the verified one. */
77
+ sandboxFail?: boolean;
78
+ signal?: AbortSignal;
79
+ }
80
+ /** A live ID capture from `argus-face-sdk/browser` (or doccap.js). */
81
+ export interface IdLiveCapture {
82
+ /** The whole recording (front, movements, flip, back). May be null when the browser can't record. */
83
+ clip?: FileInput | null;
84
+ /** The `capture` object doccap.js resolved with: challenge token, timing marks, device report. */
85
+ capture: Record<string, unknown>;
86
+ }
87
+ export interface ScreenIdInput {
88
+ /** The front of the ID, or the passport data page. */
89
+ front: FileInput;
90
+ back?: FileInput;
91
+ live?: IdLiveCapture;
92
+ signal?: AbortSignal;
93
+ }
94
+ export interface VerifyIdentityInput {
95
+ front: FileInput;
96
+ back?: FileInput;
97
+ /** The live ID capture, if the ID was photographed with captureIdDocument. */
98
+ idLive?: IdLiveCapture;
99
+ selfie: FileInput;
100
+ liveness?: LivenessCapture;
101
+ applicantIp?: string;
102
+ signal?: AbortSignal;
103
+ }
104
+ export interface IdentityResult {
105
+ /** The ID read and screened (sanctions / PEP) by POST /v1/screen/id. */
106
+ id: IdScreenResult;
107
+ /** The face check of the selfie against the ID front, by POST /v1/face/verify. */
108
+ face: FaceVerifyResult;
109
+ }
110
+ export declare class ArgusFace {
111
+ #private;
112
+ readonly baseUrl: string;
113
+ /** The cost of the most recent call that reported one (see `onCost` when calls run in parallel). */
114
+ lastCost: CallCost | null;
115
+ constructor(opts: ArgusFaceOptions);
116
+ /** Keep the key out of logs and console output. */
117
+ toJSON(): {
118
+ baseUrl: string;
119
+ apiKey: string;
120
+ };
121
+ /**
122
+ * POST /v1/face/verify: does the selfie show the person in the reference, and is it a genuine capture?
123
+ * One charged check. The result is advisory: a person makes the identity decision. Use `explainResult` to show it
124
+ * without presenting shadow checks as verdicts.
125
+ */
126
+ verifyFace(input: VerifyFaceInput): Promise<FaceVerifyResult>;
127
+ /** GET /v1/face/checks/{reference_document_id}: a stored face check, read back (needs the face_data scope). */
128
+ getFaceCheck(referenceDocumentId: string, signal?: AbortSignal): Promise<FaceVerifyResult>;
129
+ /** POST /v1/face/flash: a single-use screen-flash challenge for the browser's next live capture. Free. */
130
+ flashChallenge(signal?: AbortSignal): Promise<FlashChallenge>;
131
+ /** GET /v1/face/config: what the server has on (liveness, pulse / flash / device modes, limits). */
132
+ config(signal?: AbortSignal): Promise<FaceConfig>;
133
+ /** DELETE /v1/face/templates: erase the face templates and IP/device links kept for your checks (all, or one check's). */
134
+ eraseTemplates(referenceDocumentId?: string, signal?: AbortSignal): Promise<{
135
+ erased: number;
136
+ }>;
137
+ /** GET /v1/face/clip/{id}: a stored liveness clip, decrypted, for review. */
138
+ getClip(clipId: string, signal?: AbortSignal): Promise<Blob>;
139
+ /** DELETE /v1/face/clip/{id}: permanently delete a stored liveness clip. */
140
+ deleteClip(clipId: string, signal?: AbortSignal): Promise<{
141
+ deleted: string;
142
+ }>;
143
+ /** POST /v1/screen/id/capture/start: the signed movement challenge for a live ID capture (valid 10 minutes). */
144
+ startIdCapture(signal?: AbortSignal): Promise<IdCaptureChallenge>;
145
+ /** POST /v1/screen/id: read the ID, check the document, and screen the identity on it (sanctions / PEP). */
146
+ screenId(input: ScreenIdInput): Promise<IdScreenResult>;
147
+ /** POST /v1/screen/id/{doc_id}/face: compare a selfie with the portrait of an ID already read by screenId. */
148
+ matchSelfieToId(documentId: string, selfie: FileInput, signal?: AbortSignal): Promise<IdFaceCheck>;
149
+ /**
150
+ * The ID + selfie flow: screenId on the document, then verifyFace of the selfie against the ID front, with the
151
+ * name and date of birth read from the ID as the claimed identity. Two charged calls. If the face check fails to
152
+ * run, the error carries the ID result in `error.idResult`.
153
+ */
154
+ verifyIdentity(input: VerifyIdentityInput): Promise<IdentityResult>;
155
+ /** GET /v1/founder/usage: units used this month. Founder keys only; other keys get null. */
156
+ usage(signal?: AbortSignal): Promise<FounderUsage | null>;
157
+ }