đŸ“Ļ Secure Storage API

What is the Secure Storage API?

This API enables you to securely store sensitive data. This data is stored in the following ways for each desktop platform.

  • Linux: Using the Secret Service API/libsecret

  • Mac: Using Keychain

  • Windows: Using Credential Vault

Using the Secure Storage API

This API can be used for storing sensitive information such as access tokens or other secret credentials.

We expose a secureStorage object with set, get, getAll and remove helper methods.

Set

window.todesktop.secureStorage.set(identifier, value) stores the value under the identifier given. The identifier and the value are of type string.

If there was already a value stored at the identifier, it will be overwritten. It returns a Promise which resolves without a value.

/*
Securely store the value "secret" at the identifier "SDF34FSDG"
*/
​
await window.todesktop.secureStorage.set("SDF34FSDG", "secret")
​

​

Get

window.todesktop.secureStorage.get(identifier) returns a Promise which resolves to the stored value if the identifier exists, or undefined if it does not.

/*
Get the value which is stored at the identifier "SDF34FSDG"
*/
​
const secret = await window.todesktop.secureStorage.get("SDF34FSDG")

​

Get All

window.todesktop.secureStorage.getAll() returns a Promise which resolves to an array of { identifier, value } objects.

This retrieves all stored values for the app. The array will be empty if there are no values stored.

const secrets = await window.todesktop.secureStorage.getAll()
​
console.log(secrets)
// [
// {
// identifier: "SDF34FSDG",
// value: "secret"
// }
// ]

​

Remove

window.todesktop.secureStorage.remove(identifier) returns a Promise which resolves to a boolean: true if there was a value at the identifier and it was removed, false if the identifier didn't exist.

/*
removes the value stored at the identifier "SDF34FSDG" if it exists
*/
​
const isRemoved = await window.todesktop.secureStorage.remove("SDF34FSDG")