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 { 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;
};
| Field | Type | Description |
|---|---|---|
| service | string | The service of a generic password: the store of that service. Without it, the app's default service, the bundle identifier or the applicationId. |
| server | string | The server of internet credentials, for hasInternetCredentials and resetInternetCredentials. The other functions take it as an argument. |
| cloudSync | boolean | iOS: keep the item in iCloud Keychain, the core's `synchronizable`. Read by the writes only. |
| accessGroup | string | iOS: the keychain access group of the store. |
AccessControlOption
type AccessControlOption = {
accessControl?: ACCESS_CONTROL;
};
| Field | Type | Description |
|---|---|---|
| accessControl | ACCESS_CONTROL | What 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;
};
| Field | Type | Description |
|---|---|---|
| authenticationType | AUTHENTICATION_TYPE | What `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;
};
| Field | Type | Description |
|---|---|---|
| title | string | The reason on iOS, the title on Android. Default 'Authenticate to retrieve secret'. |
| subtitle | string | Android only. |
| description | string | Android only. |
| cancel | string | The 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;
};
| Field | Type | Description |
|---|---|---|
| accessible | ACCESSIBLE | When the item can be read: see ACCESSIBLE. ALWAYS is UNSUPPORTED. Default AFTER_FIRST_UNLOCK. |
| securityLevel | SECURITY_LEVEL | Android: SECURE_HARDWARE fails with HARDWARE_UNAVAILABLE on a device that keeps keys in software. The other values change nothing. |
| storage | STORAGE_TYPE | Not supported: any value is UNSUPPORTED. The package chooses its cipher. |
| authenticationPrompt | AuthenticationPrompt | string | Accepted 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;
};
| Field | Type | Description |
|---|---|---|
| authenticationPrompt | AuthenticationPrompt | string | The 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;
};
| Field | Type | Description |
|---|---|---|
| skipUIAuth | boolean | Accepted and changes nothing: `getAllGenericPasswordServices` never shows a prompt. |
Result
What a write resolves with.
type Result = {
service: string;
storage: STORAGE_TYPE | 'keychain';
};
| Field | Type | Description |
|---|---|---|
| service | string | The service of a generic password, the server of internet credentials. |
| storage | STORAGE_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;
};
| Field | Type | Description |
|---|---|---|
| username | string | The user name, kept as the item's label. |
| password | string | The secret. |
And service and storage of Result.
InternetCredentials
What getInternetCredentials resolves with when there are credentials.
type InternetCredentials = UserCredentials & {
server: string;
};
| Field | Type | Description |
|---|---|---|
| server | string | The server. service holds it too. |
And the fields of UserCredentials.