# Capture on a phone

Capture attested photos in a React Native or Expo app, signed in the phone's secure hardware, with only the signed artifact handed to your JavaScript.

Use `@provenanceauth/react-native` to capture attested photos in your React Native or Expo app. The SDK hashes each photo and builds its [attestation bundle](https://provenanceauth.com/docs/attest/concepts/attestation-bundles.md) natively, signs it in the phone's secure hardware, and hands your JavaScript only the signed result.

In the [capture-to-verify path](https://provenanceauth.com/docs/attest/quickstart.md), this guide is the capture step in your own app; the quickstart reads and verifies what it signs.

**Before you begin:** an Expo or React Native app you can build as a development client, and a key with the `attest` scope. The SDK is a native module, so it doesn't run in Expo Go.

To take a [capture request](https://provenanceauth.com/docs/attest/guides/capture-requests.md#6-hand-off-to-your-app) in your app, pass the link's `capture_token` to `<ProvenanceCamera captureRequestToken>`.

## 1. Install the SDK

**This package isn't on npm yet.** Until then, every request in these docs runs over HTTP against the [sandbox](https://provenanceauth.com/docs/get-started/sandbox.md).

With access to the private Provenance repository, which your Provenance contact grants, install from it:

```bash
git clone https://github.com/michaelnbane-jpg/provenance.git provenance
cd provenance && pnpm install && pnpm build
node scripts/check-publishable.mjs --out ../provenance-packs
cd ../your-project
npm install ../provenance-packs/provenanceauth-sdk-1.0.0.tgz ../provenance-packs/provenanceauth-react-native-1.0.0.tgz
```

Add the config plugin to `app.json`, so `expo prebuild` adds the camera, location and Face ID (`NSFaceIDUsageDescription`) permissions:

```json
{
  "expo": {
    "plugins": [
      [
        "@provenanceauth/react-native",
        { "cameraUsage": "Take claim photos", "locationUsage": "Record where each photo was taken", "faceIDUsage": "Confirm it's you" }
      ]
    ]
  }
}
```

Then build a development client with `npx expo run:ios --device` or `npx expo run:android --device`.

## 2. Enroll the device

Enrollment proves the phone's secure hardware to the server, which assigns the [hardware tier](https://provenanceauth.com/docs/attest/concepts/device-registry.md). The SDK first asks for camera and location permission together, then requests a challenge, has the hardware attest a new key with it, and enrolls the device. The new key's certificate (on an iPhone a certificate the SDK makes for it, on Android the attestation certificate) is what every bundle carries, so the server checks each signature with the key that made it:

**React Native**

```ts
import { enrollDevice } from "@provenanceauth/react-native";

const { deviceId, tier, permissions } = await enrollDevice({
  baseUrl: process.env.EXPO_PUBLIC_PROVENANCE_API!,
  apiKey: process.env.EXPO_PUBLIC_PROVENANCE_KEY!,
});
```

| `tier` | When |
| --- | --- |
| `sep` | An iPhone verified through App Attest. Otherwise an iPhone reports `software` |
| `strongbox` | An Android phone with a StrongBox secure chip |
| `tee` | An Android phone with TrustZone and no StrongBox |
| `software` | An emulator or no hardware backing; verifications add `hardware_backing_absent` |

`permissions` holds the person's answers for `camera` and `location`:

| Value | Meaning |
| --- | --- |
| `granted` | Allowed. With location allowed, every capture carries the phone's position |
| `denied` | Declined. A declined location still lets enrollment and captures work; captures carry no location and add `gps_absent` (+30) |
| `undetermined` | Not asked yet |

When the server verified the tier itself (with integrity checks on: App Attest on an iPhone, key attestation to Google's root on Android, both bound to the enrolled certificate), it trusts the enrolled certificate, so a capture that carries it doesn't add `cert_unknown_ca`. A clean capture from such a phone, with biometrics and a location, scores 0. The device's `device_integrity_evidence.verification` shows what was verified.

## 3. Capture a photo

Render `<ProvenanceCamera>`. With `biometricPrompt`, the secure hardware requires face or fingerprint for the signature itself, so `biometric_present: true` means the check really ran:

**React Native**

```tsx
import { ProvenanceCamera } from "@provenanceauth/react-native";

<ProvenanceCamera
  claimId="CLM-1024"
  mode="photo"
  biometricPrompt
  onAttest={(r) => uploadBundle(r.bundleJson, r.fileUri)}
  onError={(e) => console.warn(e.code, e.message)}
/>;
```

`onAttest` gives you `{ fileUri, attestationId, bundleJson }`. If the person declines the biometric, signing fails and no unsigned bundle is produced. With location permission, the bundle's `gps` holds the phone's position (6 decimal places) and accuracy in metres; without it, or with no fix within a few seconds, `gps` is `null` and the capture still goes ahead. For your own shutter button, the imperative `capture({ claimId, mode })` returns the same result.

On Android the result also has `previewUri`, an upright copy of the photo for your screen. Android keeps the camera's orientation in the photo's EXIF data and the signed file keeps the camera's bytes, so show `previewUri` and upload `fileUri`.

To capture a selfie, set `facing="front"`; the default is `"back"`. The bundle and its signature are the same for both lenses. Any other value fails with `invalid_facing` before the camera opens. [ID capture sessions](https://provenanceauth.com/docs/attest/guides/id-capture-sessions.md#sign-the-photos-in-your-own-camera-screen) walks through a selfie and an ID photo on one case.

**React Native**

```tsx
<ProvenanceCamera claimId="ONB-48213" facing="front" onAttest={onSelfie} />;
```

## 4. Submit the bundle

Send `bundleJson`, with the photo's bytes, from your backend to [`POST /v1/attest/attestations`](https://provenanceauth.com/docs/api/claims.md#post-v1-attest-attestations), then read the result as in [insurance claims](https://provenanceauth.com/docs/attest/guides/review-claims.md). The file at `fileUri` already carries the signed bundle; you can upload it as it is, because the server leaves that embedded bundle out when it checks the photo's hash.

Raw media never crosses the React Native bridge: configuration goes in, and only the file URI and the signed bundle come out.

**Limitations:** the SDK captures photos; `mode="video"` returns `not_implemented`. For video, use [live capture sessions](https://provenanceauth.com/docs/attest/concepts/video-attestation.md). An iPhone enrolls as `sep` only when the server verifies App Attest; otherwise it enrolls as `software`. An Android phone whose attestation chain doesn't end at Google's root, such as the emulator, enrolls as `software`; the capture still goes through.

## 5. Run a guided session

For an [ID session](https://provenanceauth.com/docs/attest/guides/id-capture-sessions.md) or a [claim session](https://provenanceauth.com/docs/attest/guides/claim-capture-sessions.md), render the default screens with the session's `capture_token`. They use your branding, guide each shot, run the head turn before an ID session's selfie, show what the server's checks found with a retake offer, and send the session:

```tsx
import { ProvenanceCaptureFlow } from "@provenanceauth/react-native";
import * as FileSystem from "expo-file-system";

<ProvenanceCaptureFlow
  token={captureToken}
  baseUrl={process.env.PROVENANCE_API!}
  readFileBase64={(uri) => FileSystem.readAsStringAsync(uri, { encoding: "base64" })}
  onComplete={({ requestId, redirectUrl }) => console.log(requestId, redirectUrl)}
/>
```

Each photo is measured on the phone first with `analyzeShot(fileUri, kind)`: the same image checks the server runs (in Swift or Kotlin, checked against shared test vectors), faces from Apple's Vision or Android's face detector, and on iPhone a passport's machine-readable zone, an ID barcode and the card's shape.

The measurements stay on the device, and the pre-check goes up with the photo as context. The server checks the uploaded photo again, and its answer is the result. Native video isn't available yet: give app sessions `videos: { max: 0 }`.

To build your own screens, use these calls in order:

| Call | What it does |
| --- | --- |
| `fetchCaptureSession` | Reads the session and its steps |
| `chooseCaptureDocument` | Sets the person's document in an `any` ID session |
| `prepareCaptureShot`, then `capture` | Gets the shot's nonce and takes the signed photo |
| `analyzeShot` | The phone's pre-check |
| `submitCaptureShot` | Sends the photo; returns the server's checks |
| `finishCaptureItem` | Finishes a claim's photos |
| `startHeadTurn` | The head-turn steps before an ID session's selfie |
| `finishCaptureSession` | Sends the session; returns your redirect |

## 6. The terms sheet

When the [capture release](https://provenanceauth.com/docs/attest/guides/capture-release.md) is on, a person agrees to the terms before any camera opens. `<ProvenanceCaptureFlow>` shows the sheet over its first step, with the camera closed: "Before you continue", one sentence with a "Terms of Service" link, then **Not now** and **I agree**. The words come from the API, the link opens the in-app browser, and the colours follow your branding. No prop turns it off or changes its words.

- **I agree:** the answer is recorded and the camera opens.
- **Not now:** the answer is recorded and the flow shows "Nothing was taken" with **Start again**. `onReleaseDeclined` gets the request id and your `redirect_url` with `status=release_declined`, if you set one. The request stays open.
- **The back gesture:** the sheet closes and the flow steps back to its intro. Nothing is recorded and you aren't told.
- **The terms changed** since the person agreed: the next capture call is refused and the sheet opens again with one more line, "Our terms changed on February 3, 2027."
- **The answer can't be recorded:** the sheet stays and says why, and the camera stays closed. `onError` gets `release_unavailable`.

If you draw your own capture screens, show our sheet first with `<ProvenanceReleaseSheet>`, so the record says Provenance showed it:

```tsx
import { ProvenanceReleaseSheet } from "@provenanceauth/react-native";

<ProvenanceReleaseSheet
  token={captureToken}
  baseUrl={process.env.PROVENANCE_API!}
  visible={asking}
  onContinue={() => openMyCamera()}
  onDismissed={() => setAsking(false)}
/>
```

`onContinue` runs only when the camera may open: after **I agree**, when our sheet already recorded an agreement for this request, or when the release is off. It never runs after a failure.

Or ask on your own screen and pass `termsAccepted: true` to each helper that starts an item. The helper sends `terms_accepted` with the call.

| Helper | Starts |
| --- | --- |
| `prepareCaptureShot` | A shot of any item |
| `chooseCaptureDocument` | An `any` ID session's document |
| `startHeadTurn` | An ID session's selfie |

Without either, a face or ID capture throws a `CaptureReleaseError`. Its `code` is `terms_acceptance_required` and its `reason` says why: the sheet wasn't shown, the person declined, or the terms changed.

```tsx
import { CaptureReleaseError, prepareCaptureShot } from "@provenanceauth/react-native";

try {
  const { claimId } = await prepareCaptureShot(captureToken, 0, { baseUrl, termsAccepted: true, companyTermsVersion: "acme-2026-10" });
} catch (e) {
  if (e instanceof CaptureReleaseError && e.code === "terms_acceptance_required") askAgain(e.reason);
}
```

The Kotlin and Swift modules carry the same sheet for native screens: `ReleaseSheetDialog` on Android and `ProvenanceReleaseSheet` in SwiftUI. `CaptureRelease` reads the API's sheet, builds the answer and reads its reply, and it opens the camera only on `Continue` (`.proceed` in Swift).

## 7. Consent to texts

When your company's [consent mode](https://provenanceauth.com/docs/messaging/text-consent.md) is **Provenance asks** and the request carries a phone with no consent, `<ProvenanceCaptureFlow>` opens on the opt-in step before its intro: your company's name, the masked phone, Provenance's wording with **Terms** · **Privacy**, **Not now** and **Text me**, then **Next** with the request. **Text me** records the consent with the capture token; **Not now** records nothing. Either goes on to the intro. There is nothing to add to your code.

For your own sign-up or intake screen, `<TextConsent>` is the consent box: unticked when it mounts, the fixed wording beside it and the Provenance mark, with no style props. Pass the phone your screen collected and an embed token your backend minted for your `box_id`; see [put the consent box on your own form](https://provenanceauth.com/docs/messaging/text-consent.md#8-put-the-consent-box-on-your-own-form).

```tsx
import { TextConsent } from "@provenanceauth/react-native";

<TextConsent
  baseUrl="https://sandbox-api.provenanceauth.com"
  publishableKey={publishableKey}
  embedToken={textConsentToken}
  phone={mobile}
  onConsented={({ consentId }) => saveConsentId(consentId)}
/>;
```

`onConsented` gives the record's id; read it from your backend with `GET /v1/account/text_consents/{id}` before you rely on it. Unticking withdraws it (`onWithdrawn`). On the Free plan the box renders nothing.

A native app without React Native gets the same step and box from its own package: `TextConsentStep` and `TextConsentView` in SwiftUI, `TextConsentStep` and `TextConsent` in Jetpack Compose. The step goes before your own request screen, given the request's capture embed token or its capture link's token. See [Text consent for Swift](https://provenanceauth.com/docs/messaging/text-consent/swift.md) and [Text consent for Kotlin](https://provenanceauth.com/docs/messaging/text-consent/kotlin.md).

## 8. A native app without React Native

The package carries the same native code for a Kotlin or Swift app with no React Native:

| Platform | What to use |
| --- | --- |
| Android | The Android library in `android/`: `AndroidCapture` makes the key attested over your challenge, takes the photo and signs its bundle; `ReleaseSheetDialog` is the terms sheet |
| iPhone | The Swift package in `ios/`: the `ProvenanceCapture` library (`NativeDevice`: the Secure Enclave key, App Attest, the camera and location) over `ProvenanceCore` (`ProvenanceReleaseSheet`) |

The phone is enrolled through your backend, which holds your Attest key: the app asks your backend for a challenge ([`POST /v1/attest/devices/enrollment_challenge`](https://provenanceauth.com/docs/api/devices.md#post-v1-attest-devices-enrollment-challenge)), makes the key over it, and your backend enrolls the phone with the evidence ([`POST /v1/attest/devices`](https://provenanceauth.com/docs/api/devices.md#post-v1-attest-devices)). The key's `attest` scope is enough, and the phone goes into your own Attest carrier. The app's other calls take the capture link's token only, as in [hand off to your app](https://provenanceauth.com/docs/attest/guides/capture-requests.md#6-hand-off-to-your-app).

The examples repository has both as full apps, `capture-android` and `capture-ios`, wired to its two Attest examples. On iPhone they're graded `software` until App Attest is verified.

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| The module isn't found at runtime | Running in Expo Go | Build a development client. |
| `tier` is `software` on a real phone | The hardware evidence couldn't be verified | Check the device and the server's integrity settings. |
| `onError` with `user_cancelled` | The person declined or failed the face or fingerprint check | Ask them to try again; no bundle was signed. |
| `onError` with `not_enrolled` | A capture before `enrollDevice` on this install | Enroll the device first. |
| Verifications add `gps_absent` | Location was declined or no fix arrived | Ask the person to allow location in Settings; the capture is valid either way. |
| Verifications add `cert_unknown_ca` on a real phone | The server didn't verify the tier (integrity checks off, or an older app build) | Turn on integrity checks and re-enroll with the current SDK. |
| `CaptureReleaseError` with `terms_acceptance_required` | Your own screens skipped the terms | Show `<ProvenanceReleaseSheet>` first, or pass `termsAccepted: true`. |
| `onError` with `release_unavailable` | The answer couldn't be recorded | Try again shortly; the camera stays closed until it is. |

## See also

- [ID capture sessions](https://provenanceauth.com/docs/attest/guides/id-capture-sessions.md)
- [Claim capture sessions](https://provenanceauth.com/docs/attest/guides/claim-capture-sessions.md)
- [Device registry](https://provenanceauth.com/docs/attest/concepts/device-registry.md)
- [Attestation bundles](https://provenanceauth.com/docs/attest/concepts/attestation-bundles.md)
- [Insurance claims](https://provenanceauth.com/docs/attest/guides/review-claims.md)
