API Reference¶
import * as Dea from '@dea/react-native';
// or named imports: import {init, getClassification, deaTarget} from '@dea/react-native';
The SDK is a set of module-level functions; there is no instance to hold. Every function that talks
to the SDK returns a promise. Calls that read or change the session run on the main thread in the
order they are made; attest() and renewAttestation() run on a background thread. Every function
except init, deaTarget, getTargetTally and onAttestationEvent rejects (error code E_DEA)
until init has run, and after dispose(). getClassification() has one more error code of its
own, threshold_missing.
Pass init the appKey DEA issued with your appId. See Accounts and keys
and Attest.
Lifecycle¶
init¶
Starts the SDK and capture. A repeat call resolves with the running session and keeps the first
call's options. Scoring problems do not reject: they resolve with ready: false and a
coreFault. Rejects with an Error whose message ends is not supported on a platform other
than Android or iOS.
See Options.
Returns: Started
dispose¶
Stops capture and releases the SDK. A later init starts a new session.
Human scoring¶
getClassification¶
The one score read: the score, the evidence behind it and the loaded model's thresholds, classified
as human, bot, undetermined or insufficient in one snapshot. Includes the user's most recent touch. The
thresholds come from the loaded model only. See Human Scoring.
Rejects with code threshold_missing when the loaded model has no bot threshold; the error's
userInfo.modelVersion names that model, and the constant THRESHOLD_MISSING holds the code.
deaTarget¶
function deaTarget(
name: string,
bucket?: 'button' | 'link' | 'input' | 'canvas' | 'scroller',
): DeaTargetProps
Synchronous. Props to spread onto a view so the SDK can name it and tell what kind of control it is. See Name your views.
| Parameter | Type | Description |
|---|---|---|
name |
string |
A control's name, hashed on the device. Never content or personal information |
bucket |
string |
The kind of control. Omit to only name the view |
getTargetTally¶
Presses per TargetBucket code since init, when init was given countTargets: true; empty
otherwise. Always empty with a production appId: the native SDKs refuse the counter on a
production account. Resolves an empty object before init instead of rejecting.
Consent¶
setConsent¶
Records the user's answer and stores it on the device. Takes effect immediately. See User Consent.
getConsent¶
'unknown' until the user has answered, then 'granted' or 'denied'.
Capture¶
pause¶
Stops recording. The session is kept. See Sensitive Screens.
resume¶
Starts recording again after pause(). Does not override consent.
captureEvent¶
| Parameter | Type | Description |
|---|---|---|
name |
string |
1 to 64 characters, or the event is dropped |
data |
Record<string, unknown> |
Optional; at most 1024 bytes as JSON, or the event is dropped |
Resolves true when the event was recorded. See Custom Events.
Sessions¶
reset¶
Ends the current session and starts a new one. See Sessions.
getSessionInfo¶
The current session id, device and SDK version. See SessionInfo for the shape.
Attestation¶
Attestation needs the appKey passed to init, and on Android the playIntegrityProject. See
Attest.
attest¶
Registers the device key with DEA and resolves the result; the first call turns on automatic
renewal. Without an appKey, with a production appId, resolves at once with
verdict: 'unsupported', supported: false and a detail that starts with no appKey, without
contacting DEA, and automatic renewal does not start.
renewAttestation¶
Registers again now, even while the current result is still valid, and re-plans automatic
renewal. A refusal keeps the registration already held. Without an appKey, the same answer as
attest().
getLastAttestation¶
The last registration result, without attesting again. null before the first attest().
getNextAttestationRefresh¶
When the next automatic renewal is scheduled, in epoch seconds, or null when none is planned.
onAttestationEvent¶
Calls listener with every decision automatic renewal makes. Synchronous; call remove() on the
returned subscription to stop. Subscribe before the first attest(), which schedules the first
renewal.
Ads¶
Not available on React Native. See Ads.
Types¶
DeaConfig¶
| Field | Type | Description |
|---|---|---|
appId |
string |
Required. The appId DEA issued for this app |
requireConsent |
boolean? |
Default true |
consent |
boolean? |
An answer your app already has |
motionRate |
number? |
Android only. Motion samples per second |
appKey |
string? |
The appKey DEA issued with appId. Required for attestation |
playIntegrityProject |
number? |
Android only. The Google Cloud project number DEA issued for Play Integrity. Required for attestation on Android |
countTargets |
boolean? |
Count presses per bucket for getTargetTally(); no effect with a production appId |
debug |
boolean? |
Android only. Logs to Logcat |
See Options.
Started¶
| Field | Type | Description |
|---|---|---|
ready |
boolean |
false means the SDK captures but cannot score |
coreFault |
string \| null |
Why scoring could not start |
modelRunning |
string \| null |
A label for a stored model the SDK loaded, or null. Android does not report a model downloaded over the air here; getClassification().modelVersion always names the model that is scoring |
sdkVersion |
string |
SDK version |
Classification¶
| Field | Type | Description |
|---|---|---|
result |
ClassificationResult |
The answer |
value |
number \| null |
The human score, from 0 to 1. null exactly when result is 'insufficient' |
actions |
number |
How many scored actions value is based on. For "N more actions" |
botThreshold |
number \| null |
The model's bot threshold. null before a model loads |
humanThreshold |
number \| null |
The model's human threshold. null when the model sets none, and then every value at or above botThreshold is 'human' |
modelVersion |
number \| null |
The model the thresholds come from; 0 for the one built in. null before a model loads |
ClassificationResult¶
Checked in this order:
| Value | When |
|---|---|
'insufficient' |
Scoring or the model not loaded, or fewer actions than the model asks for (8 with the built-in model). value is null, and no proof can be signed |
'human' |
value at or above humanThreshold |
'bot' |
value below botThreshold |
'human' |
humanThreshold is null, and value at or above botThreshold |
'undetermined' |
value at or above botThreshold and below humanThreshold |
Migrating to this release:
Classification.sufficientis gone, andClassificationResulthas a fourth value.
Before This release c.sufficient === falsec.result === 'insufficient'c.valuewhile not sufficient: a numbernullClassificationResulthas three valuesFour: handle 'insufficient'in everyswitchNo humanThreshold,valueat or abovebotThreshold:'undetermined''human'
ConsentState¶
'unknown', 'granted', 'denied'.
DeaTargetProps¶
| Field | Type | Description |
|---|---|---|
nativeID |
string |
The name, read on Android |
testID |
string |
The name, read on iOS |
accessibilityRole |
'button' \| 'link' \| 'search' \| 'image' \| 'scrollbar', optional |
The kind of control; absent when bucket is omitted |
TargetBucket¶
The codes getTargetTally() is keyed by: unknown 0, button 1, link 2, input 3,
scroller 4, canvas 5, background 6.
SessionInfo¶
getSessionInfo() resolves an object of this shape:
| Field | Type | Description |
|---|---|---|
session |
string |
Current session id, a UUID |
sdk.version |
string |
SDK version |
sdk.core |
string |
Scoring engine build |
device.runtime |
number |
3 on Android, 4 on iOS |
device.os |
number |
1 Android, 2 iOS |
device.surface |
{width, height} |
Screen size in logical pixels |
device.pixelRatio |
number |
Physical pixels per logical pixel |
device.rotation |
number |
Screen rotation: 0, 90, 180 or 270 |
device.maxTouchPoints |
number |
Simultaneous touches the screen supports |
device.sensorRate |
number |
The motion rate requested, in Hz, once motion samples are arriving; 0 until the first sample arrives, and on a device that delivers none |
Attestation¶
| Field | Type | Description |
|---|---|---|
supported |
boolean |
Whether a key could be created |
verdict |
'passed' \| 'failed' \| 'unsupported' |
The outcome |
platformAttested |
boolean |
Whether Play Integrity or App Attest vouched for the device |
expiresAt |
number \| null |
Expiry, epoch seconds |
kid |
string \| null |
Key identifier |
tier |
string \| null |
Trust tier assigned by DEA |
backing |
string \| null |
Where the key is kept |
detail |
string \| null |
Why attestation failed |
AttestationEvent¶
type |
Other fields | Meaning |
|---|---|---|
'scheduled' |
afterSeconds, nextRefresh |
A renewal is scheduled |
'fired' |
verdict, nextRefresh |
A renewal ran |
'idle' |
nextRefresh |
Nothing to renew |
nextRefresh is epoch seconds, or null.