Skip to main content
‹ Storage
Types

Types of storage

The options of a write and of a read, what getItemInfo reports, and the credentials with the server they are for.

Import
import { type SetOptions, type GetOptions, type ItemInfo, type Credentials, type CredentialsOptions } from '@apexnative/keychain';

SetOptions​

type SetOptions = {
accessible?: Accessible;
accessControl?: AccessControl;
authValidity?: number;
synchronizable?: boolean;
android?: AndroidOptions;
label?: string;
};

The options of a write: setItem, setBytes, setItemSync, and, without label, setCredentials. Each protection option overrides the storage's for this item; what isn't given comes from the storage, then from the defaults. The combination is checked as a whole: { authValidity: 30 } on a storage of biometryCurrentSet throws INVALID_ARGUMENT.

FieldTypeDescription
accessibleAccessibleWhen the item can be read. See KeychainOptions.
accessControlAccessControlWhat unlocks the item. See KeychainOptions.
authValiditynumberSeconds one prompt opens the item for. See KeychainOptions.
synchronizablebooleaniOS: keep the item in iCloud Keychain. See KeychainOptions.
androidAndroidOptionsWhere Android keeps the item's key. See KeychainOptions.
labelstringA text that isn't secret, stored next to the item and readable without a prompt through `getItemInfo`. A write without one removes the label; '' is a label, not the absence of one. Can't contain U+0000. Not taken by setCredentials, whose label is the username.

The service and the access group aren't write options: they belong to the storage.

GetOptions​

type GetOptions = {
prompt?: Prompt;
};

The options of a read: getItem, getBytes, getCredentials.

FieldTypeDescription
promptPromptThe texts of the prompt of this read, merged field by field over the storage's: { title } keeps the storage's cancel. See Prompt.

A read uses the protection the item was written with; there is nothing else to choose.

ItemInfo​

type ItemInfo = {
key: string;
label?: string;
accessible: Accessible;
accessControl: AccessControl;
synchronizable: boolean;
createdAt: number;
modifiedAt: number;
android?: {
securityLevel: HardwareSecurityLevel;
};
};

What getItemInfo reports about an item, without a prompt.

FieldTypeDescription
keyRequiredstringThe key of the item.
labelstringThe item's label. Absent when the item has none; '' when the label is the empty string. For credentials, the username.
accessibleRequiredAccessibleWhen the item can be read, as it was written.
accessControlRequiredAccessControlWhat unlocks the item, as it was written.
synchronizableRequiredbooleanWhether the item is in iCloud Keychain. Always false on Android.
createdAtRequirednumberWhen the item was first written, in milliseconds since the Unix epoch. A write that replaces the item keeps it.
modifiedAtRequirednumberWhen the item was last written, in milliseconds since the Unix epoch.
android{ securityLevel }Android only: where the item's Keystore key lives, 'strongbox', 'tee' or 'software', measured when the item was written.

Credentials​

type Credentials = {
username: string;
password: string;
};

A username and a password, written by setCredentials as one item and read back by getCredentials.

FieldTypeDescription
usernameRequiredstringKept as the item's label, readable without a prompt. Can't be empty or contain U+0000.
passwordRequiredstringKept as the item's value. May be empty; can't contain U+0000.

CredentialsOptions​

type CredentialsOptions = {
server?: string;
};

Which credentials: the app's own, or those of a server.

FieldTypeDescription
serverstringThe server the credentials are for, such as api.example.com. The item's key is credentials:<server>; without a server it is credentials. Must be non-empty, and the key must fit the rules of a key.

See also​