Skip to main content
Overview

API reference

Every export of @apexnative/keychain and its entry points, with a page each: the signature, the parameters, what it returns, whether it can show the prompt, what it throws, and examples. Below, the rules every call follows.

Entry points​

Import fromWhat it has
@apexnative/keychainThe storage, its options, the device capabilities, the errors
@apexnative/keychain/migrateMoving the items of react-native-keychain and expo-secure-store into the package
@apexnative/keychain/compatThe functions of react-native-keychain over the package's storage
@apexnative/keychain/jestThe same API over a storage in memory, and keychainMock to drive it in tests
app.plugin.jsThe Expo config plugin: "plugins": ["@apexnative/keychain"]

/migrate and /compat are separate so that an app that doesn't use them doesn't load them.

Storage​

ExportKindWhat it is
keychainObjectThe storage of the default service: the bundle identifier, the application id
createKeychainFunctionA storage of its own service, with defaults for its calls
KeychainInterfaceThe methods of a storage: strings, bytes, info, listing, sync calls, credentials
SetOptions, GetOptionsTypesThe options of a write and of a read
ItemInfoTypeWhat getItemInfo reports without a prompt
Credentials, CredentialsOptionsTypesA username and a password, and the server they are for

Options​

ExportKindWhat it is
KeychainOptionsTypeThe options of createKeychain
AccessibleConstants, typeWhen an item can be read
AccessControlConstants, typeWhat unlocks an item
KeyStorageConstants, typeWhere Android keeps the item's key
PromptTypeThe texts of the system prompt
AndroidOptionsTypeThe options for Android only

Device capabilities​

ExportKindWhat it is
getBiometryTypesFunctionThe biometrics of the device that can unlock a key
canUseAccessControlFunctionWhether an item can be written with an accessControl now, and why not
isPasscodeSetFunctionWhether the device has a passcode, PIN or pattern
getBiometryStateFunctionA token that changes when the enrolled biometrics change
getHardwareSecurityLevelFunctionWhere Android keeps new keys; null on iOS
BiometryTypeConstants, typeA biometric modality: faceID, fingerprint, …
HardwareSecurityLevelConstants, typestrongbox, tee or software
AccessControlAvailabilityTypeWhat canUseAccessControl answers

Errors​

ExportKindWhat it is
KeychainErrorClassThe error of every failed call: code, nativeCode, nativeDomain
KeychainErrorCodeConstants, typeEvery code
isKeychainErrorFunctionWhether a value is a KeychainError, optionally with a given code
KeychainErrorDetailsTypeThe native details of an error

Rules of every call​

  • Errors. Every call fails with a KeychainError: an async method rejects, a sync method throws. A missing value is null, never an error. A method without a value resolves to undefined.
  • Checks first. Keys, values and options are checked in JavaScript before the native call, the same way on iOS and Android. A key that breaks the rules, a string with U+0000, an option with a wrong value, or an option name that doesn't exist throws INVALID_ARGUMENT.
  • Prompts. Only reads of a protected item (getItem, getBytes, getCredentials, and migrateItem of a protected old item) can show the system prompt. Writes, removals, hasItem, getItemInfo, getAllKeys, clear, the sync methods and the device functions never do.
  • Never weaker. An option means the same on both platforms. A device that can't give an item its protection fails the write; the item is never stored with less.
  • Only its own items. The package reads, lists and removes only the items it wrote; those of other libraries are moved by /migrate.
  • Platforms. Every export works on iOS and Android. On the web every call throws UNSUPPORTED; so does a call in an app without the native module (Expo Go, or an app not rebuilt after the install), with a message that says how to fix it. Importing the package never fails.