Skip to content

SecretStorage

Official

A secret storage.

Import:

import { SecretStorage } from 'obsidian';

Signature:

export class SecretStorage extends Events

Extends: Events

Constructor

new SecretStorage(app: App)

Constructor.

To get the constructor instance, use getSecretStorageConstructor from obsidian-typings/implementations.

Properties

PropertyTypeDescription
_Record<string, EventsEntry[]>Internal storage of registered event handlers by event name.
(Inherited from Events)
adapterunknownThe platform-specific storage backend (OS-keychain-encrypted on desktop, plain on mobile), or null when none is available.
appAppReference to the app instance.
saveMetaDebouncer<[], void>Debounced callback that persists SecretStorage.secretsMeta to local storage.
secretsRecord<string, string>Map of secret ID to its stored secret value.
secretsMetaRecord<string, SecretMetadata>Map of secret ID to its access metadata.

Methods

MethodReturnsDescription
deleteSecret(id)booleanDeletes a secret from storage.
getLastAccess(id)null | numberGets the timestamp of the last recorded access for a secret.
getSecret(id)string | nullGets a secret from storage
isEncryptionAvailable()booleanChecks 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)voidRemove an event listener.
(Inherited from Events)
offref(ref)voidRemove an event listener by reference.
(Inherited from Events)
on(name, callback, ctx?)EventRefAdd an event listener.
(Inherited from Events)
peekSecret(id)null | stringReads a secret without recording an access in its metadata.
recordAccess(id)voidRecords an access to a secret, updating its last-access metadata.
setSecret(id, secret)voidSets a secret in the storage.
setupStorage()unknownCreates the platform-specific storage backend.
trigger(name, data?)voidTrigger an event, executing all the listeners in order even if some of them throw an error.
(Inherited from Events)
tryTrigger(evt, args)voidTry to trigger an event, executing all the listeners in order even if some of them throw an error.
(Inherited from Events)
validateId(id)booleanValidates a secret ID (lowercase alphanumeric with optional dashes, at most 64 characters).

Links to this page: