Skip to main content
‹ /compat
Types

Types of /compat

The option and result types of react-native-keychain 10, as far as this package takes them: which item, how to protect it, the texts of the prompt, and what the calls resolve with.

Import
import { type SetOptions, type UserCredentials } from '@apexnative/keychain/compat';

The types have rnk's names, so code that annotates its options or results keeps compiling. The constants they use, ACCESSIBLE and the rest, are on Constants.

BaseOptions​

Which item: a service for a generic password, a server for internet credentials.

type BaseOptions = {
service?: string;
server?: string;
cloudSync?: boolean;
accessGroup?: string;
};
FieldTypeDescription
servicestringThe service of a generic password: the store of that service. Without it, the app's default service, the bundle identifier or the applicationId.
serverstringThe server of internet credentials, for hasInternetCredentials and resetInternetCredentials. The other functions take it as an argument.
cloudSyncbooleaniOS: keep the item in iCloud Keychain, the core's `synchronizable`. Read by the writes only.
accessGroupstringiOS: the keychain access group of the store.

AccessControlOption​

type AccessControlOption = {
accessControl?: ACCESS_CONTROL;
};
FieldTypeDescription
accessControlACCESS_CONTROLWhat unlocks the item: see ACCESS_CONTROL. A write protects the item with it; a read and getSecurityLevel only check it, and APPLICATION_PASSWORD is UNSUPPORTED everywhere.

AuthenticationTypeOption​

type AuthenticationTypeOption = {
authenticationType?: AUTHENTICATION_TYPE;
};
FieldTypeDescription
authenticationTypeAUTHENTICATION_TYPEWhat `canImplyAuthentication` asks about. In the options of a read it is accepted and ignored. Default DEVICE_PASSCODE_OR_BIOMETRICS.

AuthenticationPrompt​

The texts of the prompt a protected read shows. Where a read takes it, a plain string is the title.

type AuthenticationPrompt = {
title?: string;
subtitle?: string;
description?: string;
cancel?: string;
};
FieldTypeDescription
titlestringThe reason on iOS, the title on Android. Default 'Authenticate to retrieve secret'.
subtitlestringAndroid only.
descriptionstringAndroid only.
cancelstringThe cancel button. Default 'Cancel'.

The core's Prompt has two more fields, fallback and confirmationRequired; /compat keeps the core's defaults for them.

SetOptions​

The options of setGenericPassword and setInternetCredentials.

type SetOptions = BaseOptions &
AccessControlOption & {
accessible?: ACCESSIBLE;
securityLevel?: SECURITY_LEVEL;
storage?: STORAGE_TYPE;
authenticationPrompt?: AuthenticationPrompt | string;
};
FieldTypeDescription
accessibleACCESSIBLEWhen the item can be read: see ACCESSIBLE. ALWAYS is UNSUPPORTED. Default AFTER_FIRST_UNLOCK.
securityLevelSECURITY_LEVELAndroid: SECURE_HARDWARE fails with HARDWARE_UNAVAILABLE on a device that keeps keys in software. The other values change nothing.
storageSTORAGE_TYPENot supported: any value is UNSUPPORTED. The package chooses its cipher.
authenticationPromptAuthenticationPrompt | stringAccepted and ignored: a write never shows a prompt.

And the fields of BaseOptions and AccessControlOption. Other names that rnk has dropped or never had are ignored.

GetOptions​

The options of getGenericPassword and getInternetCredentials.

type GetOptions = BaseOptions &
AccessControlOption &
Partial<AuthenticationTypeOption> & {
authenticationPrompt?: AuthenticationPrompt | string;
};
FieldTypeDescription
authenticationPromptAuthenticationPrompt | stringThe texts of the prompt, when the item is protected. A string is the title. Without it, rnk's texts: Authenticate to retrieve secret and Cancel.

And the fields of BaseOptions, AccessControlOption and AuthenticationTypeOption: of those, a read uses service and accessGroup; accessControl is only checked, authenticationType and cloudSync are ignored.

GetAllOptions​

type GetAllOptions = {
skipUIAuth?: boolean;
};
FieldTypeDescription
skipUIAuthbooleanAccepted and changes nothing: `getAllGenericPasswordServices` never shows a prompt.

Result​

What a write resolves with.

type Result = {
service: string;
storage: STORAGE_TYPE | 'keychain';
};
FieldTypeDescription
servicestringThe service of a generic password, the server of internet credentials.
storageSTORAGE_TYPE | 'keychain''keychain' on iOS, 'KeystoreAESGCM' on Android.

UserCredentials​

What getGenericPassword resolves with when there is a password.

type UserCredentials = Result & {
username: string;
password: string;
};
FieldTypeDescription
usernamestringThe user name, kept as the item's label.
passwordstringThe secret.

And service and storage of Result.

InternetCredentials​

What getInternetCredentials resolves with when there are credentials.

type InternetCredentials = UserCredentials & {
server: string;
};
FieldTypeDescription
serverstringThe server. service holds it too.

And the fields of UserCredentials.

See also​