Skip to content

orbit-secure-store ​

@c9up/orbit-secure-store: strings kept encrypted on the phone (Android Keystore), optionally behind a biometric check. Guide: Device APIs.

Installation ​

bash
pnpm add @c9up/orbit-secure-store

On a phone, React Native's autolinking adds the native module to an app built by ream android:*; there is nothing to wire.

Entry points ​

ImportContents
@c9up/orbit-secure-storeThe four store calls, their option types and the error class. The import resolves per platform: the react-native build (the condition and the react-native field) on a phone, the default build elsewhere. Both builds export the same names.
PlatformBehaviour
Phone (Android)Each value is AES-256-GCM ciphertext under a key that never leaves the Android Keystore, kept in the app's no-backup directory. A value set with requireAuthentication has its own key, unlocked only by a strong biometric check, each time; enrolling a new biometric invalidates it. Nothing logs a value.
Browser, serverNo secure store: setItem, getItem and deleteItem reject with E_ORBIT_SECURE_STORE_UNAVAILABLE (after the key check), and biometricStatus() answers { hardware: false, enrolled: false }.

iOS is not supported yet.

Exports ​

ExportKindDescription
setItemfunctionKeeps a value under a key, encrypted.
getItemfunctionReads the value under a key.
deleteItemfunctionForgets the value under a key.
biometricStatusfunctionWhether a strong biometric can protect a value here.
SetItemOptionsinterfaceOptions of setItem.
GetItemOptionsinterfaceOptions of getItem.
PromptTextinterfaceThe words of the biometric prompt.
BiometricStatusinterfaceWhat biometricStatus() answers.
errorsnamespaceThe package's errors, one class per code, see Errors

Functions ​

A key is 1 to 128 characters of A-Z a-z 0-9 . _ - (not . or ..); any other key is refused with E_ORBIT_SECURE_STORE_INVALID_KEY before anything reaches the platform. Every key has a value of its own: token, token.bak and token.new never read, overwrite or delete one another, and each value is sealed with its key, so it opens under no other name. Values stored by version 0.1.0 still read: each moves to the new layout the first time it is read, after which 0.1.0 no longer sees it.

FunctionSignatureDescription
setItemsetItem(key: string, value: string, options?: SetItemOptions): Promise<void>Keeps value under key, encrypted; with requireAuthentication, behind a biometric check.
getItemgetItem(key: string, options?: GetItemOptions): Promise<string | null>The value under key, or null when there is none.
deleteItemdeleteItem(key: string): Promise<void>Forgets the value under key; nothing happens when there is none.
biometricStatusbiometricStatus(): Promise<BiometricStatus>Whether a strong biometric can protect a value on this phone.

Option types ​

TypeFieldTypeDescription
SetItemOptionsrequireAuthenticationbooleanThe value is readable only after a strong biometric check, each time.
SetItemOptionspromptPromptTextThe biometric prompt's words, when one is shown.
GetItemOptionspromptPromptTextThe biometric prompt's words, when the value requires one.
PromptTexttitle, subtitlestringThe prompt's title and subtitle.
PromptTextcancelstringThe label of the button that dismisses it.
BiometricStatushardwarebooleanThe phone has a strong biometric sensor it can use.
BiometricStatusenrolledbooleanA strong biometric is enrolled: requireAuthentication will work.

Errors ​

Each code is a class of the errors export. An error never carries the stored value.

A cancelled biometric check has its own code, distinct from a failed one.

CodeRaised when
E_ORBIT_SECURE_STORE_UNAVAILABLEThere is no secure store: the browser, the server, or an app built without the module.
E_ORBIT_SECURE_STORE_INVALID_KEYA key is not 1 to 128 of A-Z a-z 0-9 . _ -.
E_ORBIT_SECURE_STORE_NO_BIOMETRICSrequireAuthentication is asked on a phone with no strong biometric enrolled.
E_ORBIT_SECURE_STORE_AUTH_CANCELLEDThe user dismissed the biometric prompt.
E_ORBIT_SECURE_STORE_AUTH_FAILEDThe biometric check failed for good: too many attempts, a lockout, a hardware error.
E_ORBIT_SECURE_STORE_INVALIDATEDThe key behind the value is gone (a new biometric enrolled, the app's data restored), and the value with it.
E_ORBIT_SECURE_STORE_FAILEDThe platform reported any other failure.

See also ​