# How the SDK works

> Enrol a face once, verify it on the device with no network. What happens on the phone, what's stored, and how the sandbox differs from production.

Source: https://docs.faceping.ai/sdk/

The FacePing SDK does two things: **enrol** a face (turn one photo into a face template) and **verify** a face (check that the person in front of the camera matches a template). Verification always runs on the device, with no network.

## Platforms

| Platform | Package | Get started | Reference |
|---|---|---|---|
| .NET MAUI | [`FacePing.Sdk.Maui`](https://www.nuget.org/packages/FacePing.Sdk.Maui) on NuGet | [Walkthrough](https://docs.faceping.ai/start/maui/) | [.NET MAUI reference](https://docs.faceping.ai/sdk/maui/) |
| iOS (Swift) | [`faceping-ios`](https://github.com/faceping/faceping-ios) Swift package | [Walkthrough](https://docs.faceping.ai/start/ios/) | [iOS reference](https://docs.faceping.ai/sdk/ios/) |
| Android (Kotlin) | [`ai.faceping:faceping-android`](https://central.sonatype.com/artifact/ai.faceping/faceping-android) on Maven Central | [Walkthrough](https://docs.faceping.ai/start/android/) | [Android reference](https://docs.faceping.ai/sdk/android/) |
| Flutter | [`faceping`](https://pub.dev/packages/faceping) on pub.dev | [Walkthrough](https://docs.faceping.ai/start/flutter/) | [Flutter reference](https://docs.faceping.ai/sdk/flutter/) |
| React Native | [`@faceping/react-native`](https://www.npmjs.com/package/@faceping/react-native) on npm | [Walkthrough](https://docs.faceping.ai/start/react-native/) | [React Native reference](https://docs.faceping.ai/sdk/react-native/) |
| Capacitor | [`@faceping/capacitor`](https://www.npmjs.com/package/@faceping/capacitor) on npm | [Walkthrough](https://docs.faceping.ai/start/capacitor/) | [Capacitor reference](https://docs.faceping.ai/sdk/capacitor/) |
| Avalonia | [`FacePing.Sdk.Avalonia`](https://www.nuget.org/packages/FacePing.Sdk.Avalonia) on NuGet | [Walkthrough](https://docs.faceping.ai/start/avalonia/) | [Avalonia reference](https://docs.faceping.ai/sdk/avalonia/) |

All seven are in preview, and share one engine, so the calls, outcomes and limits are the same everywhere. Flutter, React Native and Capacitor are thin bridges over the iOS and Android SDKs; Avalonia uses the same .NET layer as .NET MAUI.

## The three calls

| Call | What it does |
|---|---|
| **Enrol** (`enroll`; `EnrollAsync` in C#) | Finds the face, checks it's a real person and good enough to match later, and stores a face template under your `id`. The photo itself is discarded. |
| **Live check** (`verifyLive`; `VerifyLiveAsync` in C#) | Watches the camera, matches the face to `id`, and asks the person to turn their head to prove they're really there. Returns a match or a reason it didn't. |
| **Photo check** (`verify`; `VerifyAsync` in C#) | The same match from a single photo, with a passive liveness check only. Use it for tests and back-office tools, not at an unattended entrance or kiosk. |

Every platform has the same three calls, in its own style: `EnrollAsync` in .NET MAUI and Avalonia, `enroll` in Kotlin, Swift, Dart and TypeScript. Each SDK reference has the exact signatures.

All three calls run in the FacePing core, a native engine written in Rust that the SDK ships as compiled code. See [Security](https://docs.faceping.ai/security/).

The `id` is yours: a ticket number or member number. FacePing never needs a name.

## What a result tells you

```csharp title=".NET MAUI"
var result = await faceping.VerifyLiveAsync("TKT-104823", Camera);

switch (result.Outcome)
{
    case VerifyOutcome.Match:           // let them in
    case VerifyOutcome.NoMatch:         // a different person: send to staff
    case VerifyOutcome.NotEnrolled:     // no face stored for this id: use your normal entry
    case VerifyOutcome.LivenessFailed:  // a photo or screen held up: send to staff
    case VerifyOutcome.ChallengeFailed: // turned the wrong way or not at all: try again or staff
    case VerifyOutcome.NoFace:          // nobody in view
    case VerifyOutcome.Expired:         // the stored faces have passed their deletion date
    case VerifyOutcome.LeaseExpired:    // the device hasn't synced in 24 hours: use your normal entry
        break;
}
```

```csharp title="Avalonia"
var result = await IFacePing.Current.VerifyLiveAsync("TKT-104823", Camera);

switch (result.Outcome)
{
    case VerifyOutcome.Match:           // let them in
    case VerifyOutcome.NoMatch:         // a different person: send to staff
    case VerifyOutcome.NotEnrolled:     // no face stored for this id: use your normal entry
    case VerifyOutcome.LivenessFailed:  // a photo or screen held up: send to staff
    case VerifyOutcome.ChallengeFailed: // turned the wrong way or not at all: try again or staff
    case VerifyOutcome.NoFace:          // nobody in view
    case VerifyOutcome.Expired:         // the stored faces have passed their deletion date
    case VerifyOutcome.LeaseExpired:    // the device hasn't synced in 24 hours: use your normal entry
        break;
}
```

```kotlin title="Android (Kotlin)"
val result = faceping.verifyLive("TKT-104823", camera)

when (result.outcome) {
    VerifyOutcome.MATCH -> { }             // let them in
    VerifyOutcome.NO_MATCH -> { }          // a different person: send to staff
    VerifyOutcome.NOT_ENROLLED -> { }      // no face stored for this id: use your normal entry
    VerifyOutcome.LIVENESS_FAILED -> { }   // a photo or screen held up: send to staff
    VerifyOutcome.CHALLENGE_FAILED -> { }  // turned the wrong way or not at all: try again or staff
    VerifyOutcome.NO_FACE -> { }           // nobody in view
    VerifyOutcome.EXPIRED -> { }           // the stored faces have passed their deletion date
    VerifyOutcome.LEASE_EXPIRED -> { }     // the device hasn't synced in 24 hours: use your normal entry
}
```

```swift title="iOS (Swift)"
let result = try await faceping.verifyLive(id: "TKT-104823", camera: camera)

switch result.outcome {
case .match: break            // let them in
case .noMatch: break          // a different person: send to staff
case .notEnrolled: break      // no face stored for this id: use your normal entry
case .livenessFailed: break   // a photo or screen held up: send to staff
case .challengeFailed: break  // turned the wrong way or not at all: try again or staff
case .noFace: break           // nobody in view
case .expired: break          // the stored faces have passed their deletion date
case .leaseExpired: break     // the device hasn't synced in 24 hours: use your normal entry
@unknown default: break
}
```

```dart title="Flutter"
final result = await faceping.verifyLive('TKT-104823', camera);

switch (result.outcome) {
  case VerifyOutcome.match:           // let them in
  case VerifyOutcome.noMatch:         // a different person: send to staff
  case VerifyOutcome.notEnrolled:     // no face stored for this id: use your normal entry
  case VerifyOutcome.livenessFailed:  // a photo or screen held up: send to staff
  case VerifyOutcome.challengeFailed: // turned the wrong way or not at all: try again or staff
  case VerifyOutcome.noFace:          // nobody in view
  case VerifyOutcome.expired:         // the stored faces have passed their deletion date
  case VerifyOutcome.leaseExpired:    // the device hasn't synced in 24 hours: use your normal entry
    break;
}
```

```ts title="React Native"
const result = await FacePing.verifyLive('TKT-104823', camera);

switch (result.outcome) {
  case 'match':           // let them in
  case 'noMatch':         // a different person: send to staff
  case 'notEnrolled':     // no face stored for this id: use your normal entry
  case 'livenessFailed':  // a photo or screen held up: send to staff
  case 'challengeFailed': // turned the wrong way or not at all: try again or staff
  case 'noFace':          // nobody in view
  case 'expired':         // the stored faces have passed their deletion date
  case 'leaseExpired':    // the device hasn't synced in 24 hours: use your normal entry
    break;
}
```

```ts title="Capacitor"
const result = await FacePing.verifyLive('TKT-104823');   // opens FacePing's camera screen

switch (result.outcome) {
  case 'match':           // let them in
  case 'noMatch':         // a different person: send to staff
  case 'notEnrolled':     // no face stored for this id: use your normal entry
  case 'livenessFailed':  // a photo or screen held up: send to staff
  case 'challengeFailed': // turned the wrong way or not at all: try again or staff
  case 'noFace':          // nobody in view
  case 'expired':         // the stored faces have passed their deletion date
  case 'leaseExpired':    // the device hasn't synced in 24 hours: use your normal entry
    break;
}
```

Every result also has the similarity (0 to 1), the liveness score (0 to 1), how long the check took and whether it ran in the sandbox: `Similarity`, `LivenessScore`, `Elapsed` and `IsSandbox` in C#, and `similarity`, `livenessScore`, `elapsed` (`elapsedMs` in TypeScript) and `isSandbox` elsewhere.

On a check-in device (a device token), every result is also signed by the device: `SignedResult` in C#, `signedResult` elsewhere. Your server can check it to prove the check happened; pass your server's nonce to the verify call to bind it to that check. See [Signed check results](https://docs.faceping.ai/signed-results/).

## Liveness

Every frame gets a **passive** check that it's a real face, not a photo or a screen. The live check (`verifyLive`, `VerifyLiveAsync` in C#) adds an **active** check: after the first match, the person turns their head left or right (chosen at random), then looks back for a second match. Any failed liveness check ends the attempt; there's no retrying until a lucky frame passes. The camera view shows the prompts for you.

## Where faces are stored

On the device, face templates are kept in an encrypted store: AES-256-GCM, with the key in the platform's secure storage (Keychain on iOS, Keystore on Android). Templates are numbers, not photos; they can't be turned back into a picture of the person. The store never leaves the phone: on iOS FacePing keeps it out of iCloud and computer backups, and on Android your app's backup rules leave it out (each Get started guide shows them; see [Going to production](https://docs.faceping.ai/going-live/)).

| | Sandbox | Production |
|---|---|---|
| Faces come from | The app's enrol call on the device, or your sandbox's practice list (with a device token) | Your FacePing check-in list, synced to the device |
| Kept on the device | Up to 25, each for 24 hours | Until your retention date or the device is revoked |
| Network needed | To activate the sandbox key, then to renew its licence at least every 30 days | To sync new faces and renew the device's lease (24 hours by default); verification is offline |

## Sandbox and production

The **sandbox** is for building and testing. Use a `fp_test_` key when you set FacePing up. It needs a connection once, the first time the app runs, to activate the key; after that it works offline for 30 days. Results have `IsSandbox = true`. Faces you enrol in the SDK sandbox stay on that device and never reach FacePing.

The same sandbox key also works on the [server API](https://docs.faceping.ai/quickstart/), on one **practice check-in list**: up to 25 people, each face deleted 24 hours after enrolment, nothing billed. That's how you try the production flow before you apply: create the list, enrol people with the widget or from your server, add a check-in device and give its device token to the app. Practice-list faces are held by FacePing (like a live list's) until they're deleted 24 hours after enrolment.

**Production** faces are enrolled with consent through your server, the FacePing widget or the dashboard, and each device syncs an encrypted copy of the faces it needs. Your verify code doesn't change. See [Going to production](https://docs.faceping.ai/going-live/).

## Limits

- One face per photo when enrolling; the largest face is used when verifying.
- Faces should be at least 60 pixels across: about arm's length from a phone. Enrolment tells you `FaceTooSmall` if someone is too far away.
- Release builds check a face in under 0.3 seconds on a mid-range phone. With .NET MAUI and Avalonia, Debug builds are several times slower (the camera frames pass through .NET code, which Debug doesn't optimise), so try those in Release. With the other SDKs a debug build is fine: the FacePing core is already compiled for speed.
