SecretStorage
Official
A secret storage.
Import:
import { SecretStorage } from 'obsidian';Signature:
export class SecretStorage extends EventsExtends: Events
Constructor
new SecretStorage(app: App)Constructor.
To get the constructor instance, use getSecretStorageConstructor from obsidian-typings/implementations.
Properties
| Property | Type | Description | |
|---|---|---|---|
| _ | Record<string, EventsEntry[]> | Internal storage of registered event handlers by event name. (Inherited from Events) | |
| adapter | unknown | The platform-specific storage backend (OS-keychain-encrypted on desktop, plain on mobile), or null when none is available. | |
| app | App | Reference to the app instance. | |
| saveMeta | Debouncer<[], void> | Debounced callback that persists SecretStorage.secretsMeta to local storage. | |
| secrets | Record<string, string> | Map of secret ID to its stored secret value. | |
| secretsMeta | Record<string, SecretMetadata> | Map of secret ID to its access metadata. |
Methods
| Method | Returns | Description | |
|---|---|---|---|
| deleteSecret(id) | boolean | Deletes a secret from storage. | |
| getLastAccess(id) | null | number | Gets the timestamp of the last recorded access for a secret. | |
| getSecret(id) | string | null | Gets a secret from storage | |
| isEncryptionAvailable() | boolean | Checks whether OS-level encryption is available for the storage backend. | |
| listSecrets() | string[] | Lists all secrets in storage | |
| load() | Promise<void> | Loads secrets and their metadata from the backend into memory. | |
| off(name, callback) | void | Remove an event listener. (Inherited from Events) | |
| offref(ref) | void | Remove an event listener by reference. (Inherited from Events) | |
| on(name, callback, ctx?) | EventRef | Add an event listener. (Inherited from Events) | |
| peekSecret(id) | null | string | Reads a secret without recording an access in its metadata. | |
| recordAccess(id) | void | Records an access to a secret, updating its last-access metadata. | |
| setSecret(id, secret) | void | Sets a secret in the storage. | |
| setupStorage() | unknown | Creates the platform-specific storage backend. | |
| trigger(name, data?) | void | Trigger an event, executing all the listeners in order even if some of them throw an error. (Inherited from Events) | |
| tryTrigger(evt, args) | void | Try to trigger an event, executing all the listeners in order even if some of them throw an error. (Inherited from Events) | |
| validateId(id) | boolean | Validates a secret ID (lowercase alphanumeric with optional dashes, at most 64 characters). |
Links to this page: