Getting started

Quick start

Store a token, use a session store and keep a wallet key in the vault, from JavaScript and from Rust.

After installation the plugin is registered and your window has keyring-store:default.

Store a token

The simplest use: one secret under one account name.

import { setPasswords, getPasswords, passwordExists, deletePasswords } from "tauri-plugin-keyring-store-api";

await setPasswords([{ account: "app.api_token", secret: "s3cr3t" }]);

const [token] = await getPasswords(["app.api_token"]); // "s3cr3t", or null if missing
const exists = await passwordExists("app.api_token"); // true

await deletePasswords(["app.api_token"]);

More in Password accounts.

Session and store

The Stronghold-shaped API. The first argument of load is a logical id, not a file path.

import { KeyringSession } from "tauri-plugin-keyring-store-api";

const session = await KeyringSession.load("/app/secrets", "");
const client = await session.createClient("desktop");
const store = client.getStore();

await store.insert("prefs", new TextEncoder().encode('{"theme":"dark"}'));
const raw = await store.get("prefs"); // Uint8Array | null
await store.remove("prefs");

await session.unload();

More in Sessions and store.

Wallet key in the vault

Needs the crypto feature (on by default). The private key is generated in Rust and stays in the OS store; JavaScript gets the mnemonic once, the public key and signatures.

import { KeyringSession, Location } from "tauri-plugin-keyring-store-api";

const session = await KeyringSession.load("/wallet/main", "");
const vault = (await session.createClient("main")).getVault("PRIMARY");
const master = Location.generic("PRIMARY", "master");

const words = new TextDecoder().decode(await vault.generateBIP39(master)); // 24 words: show once
const publicKey = await vault.getEd25519PublicKey(master); // 32 bytes
const signature = await vault.signEd25519(master, "hello"); // 64 bytes

await session.unload();

More in Vault and procedures.

From Rust

The same store is available to your own commands:

src-tauri/src/lib.rs
use tauri_plugin_keyring_store::KeyringExt;

#[tauri::command]
async fn save_api_token(app: tauri::AppHandle, token: String) -> Result<(), String> {
    // KeyringStore calls block (OS prompts, D-Bus): keep them off the async runtime.
    tauri::async_runtime::spawn_blocking(move || app.keyring().store.set_password("app.api_token", &token))
        .await
        .map_err(|e| e.to_string())?
        .map_err(|e| e.to_string())
}

More in Rust backend.

Example app

examples/tauri-app runs on desktop, Android and iOS and shows the password API, sessions, the vault and Rust-side access.

cd examples/tauri-app
pnpm install
pnpm tauri dev