keyring
Install the required plugin:
tynd add keyringimport { keyring } from "@tynd/plugin-keyring/client";Encrypted secret storage backed by the OS credential manager. Use this for anything sensitive — tokens, passwords, session cookies, API keys.
set(entry, value): Promise<void>
Section titled “set(entry, value): Promise<void>”const entry = { service: "com.example.myapp", account: "alice" };await keyring.set(entry, "s3cr3t-token");service— reverse-DNS recommended. Namespaces your secrets.account— arbitrary string identifying the credential (username,"access_token", etc.).value— the secret as a UTF-8 string.
service and account must be non-empty, contain no NUL character, and are
limited to 256 characters. value is limited to 8 KiB of UTF-8 data and
cannot contain NUL.
get(entry): Promise<string | null>
Section titled “get(entry): Promise<string | null>”const token = await keyring.get(entry); // string | nullReturns null if no entry matches.
delete(entry): Promise<boolean>
Section titled “delete(entry): Promise<boolean>”const existed = await keyring.delete(entry); // true if something was deletedBacking store per OS
Section titled “Backing store per OS”| OS | Backend |
|---|---|
| macOS | Keychain — encrypted with the user’s login password |
| Windows | Credential Manager + DPAPI |
| Linux | Secret Service API (GNOME Keyring / KWallet / others via D-Bus) |
On Linux, a Secret Service provider must be running (virtually every desktop environment has one). Headless VMs may not — get / set throw in that case. Fall back to a file-backed encrypted store or require the user to install gnome-keyring.
keyring vs store
Section titled “keyring vs store”keyring |
store |
|
|---|---|---|
| Encrypted at rest | ✓ | ✗ |
| Readable by other processes with user access | ✗ | ✓ |
| Suitable for tokens / passwords | ✓ | ✗ |
| Suitable for UI preferences | ✗ (overkill) | ✓ |
Example — OAuth token round-trip
Section titled “Example — OAuth token round-trip”import { keyring } from "@tynd/plugin-keyring/client";
const ENTRY = { service: "com.example.myapp", account: "access_token" };
async function getOrRefreshToken() { let token = await keyring.get(ENTRY); if (!token || isExpired(token)) { token = await refreshOAuth(); // your refresh flow await keyring.set(ENTRY, token); } return token;}- This is a host-backed plugin: credential storage is native code in the Tynd
host, compiled in once
keyringis listed inplugins. - Values are UTF-8 strings — encode binary secrets as base64 on the way in and decode on the way out.
- macOS prompts the user to grant Keychain access on first call from a newly-signed binary. A signed / notarized build avoids repeat prompts.
- There’s no “list all entries” API. Track the set of known
accountstrings instoreif you need enumeration.
Related
Section titled “Related”- store — plaintext k/v.
- Persistence guide.