View as Markdown

Attest · Guide

Capture on a phone

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 natively, signs it in the phone's secure hardware, and hands your JavaScript only the signed result.

In the capture-to-verify path, 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 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.

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

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:

{
  "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. 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:

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!,
});
tierWhen
sepAn iPhone verified through App Attest. Otherwise an iPhone reports software
strongboxAn Android phone with a StrongBox secure chip
teeAn Android phone with TrustZone and no StrongBox
softwareAn emulator or no hardware backing; verifications add hardware_backing_absent

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

ValueMeaning
grantedAllowed. With location allowed, every capture carries the phone's position
deniedDeclined. A declined location still lets enrollment and captures work; captures carry no location and add gps_absent (+30)
undeterminedNot 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:

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 walks through a selfie and an ID photo on one case.

<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, then read the result as in insurance claims. 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. 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 or a claim session, 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:

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:

CallWhat it does
fetchCaptureSessionReads the session and its steps
chooseCaptureDocumentSets the person's document in an any ID session
prepareCaptureShot, then captureGets the shot's nonce and takes the signed photo
analyzeShotThe phone's pre-check
submitCaptureShotSends the photo; returns the server's checks
finishCaptureItemFinishes a claim's photos
startHeadTurnThe head-turn steps before an ID session's selfie
finishCaptureSessionSends the session; returns your redirect

6. The terms sheet

When the capture release 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:

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.

HelperStarts
prepareCaptureShotA shot of any item
chooseCaptureDocumentAn any ID session's document
startHeadTurnAn 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.

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).

When your company's consent mode 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.

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 and Text consent for Kotlin.

8. A native app without React Native

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

PlatformWhat to use
AndroidThe Android library in android/: AndroidCapture makes the key attested over your challenge, takes the photo and signs its bundle; ReleaseSheetDialog is the terms sheet
iPhoneThe 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), makes the key over it, and your backend enrolls the phone with the evidence (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.

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

SymptomCauseFix
The module isn't found at runtimeRunning in Expo GoBuild a development client.
tier is software on a real phoneThe hardware evidence couldn't be verifiedCheck the device and the server's integrity settings.
onError with user_cancelledThe person declined or failed the face or fingerprint checkAsk them to try again; no bundle was signed.
onError with not_enrolledA capture before enrollDevice on this installEnroll the device first.
Verifications add gps_absentLocation was declined or no fix arrivedAsk the person to allow location in Settings; the capture is valid either way.
Verifications add cert_unknown_ca on a real phoneThe 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_requiredYour own screens skipped the termsShow <ProvenanceReleaseSheet> first, or pass termsAccepted: true.
onError with release_unavailableThe answer couldn't be recordedTry again shortly; the camera stays closed until it is.

See also