Skip to content

keyring

Store and retrieve secrets in the operating system's keyring, so API keys and tokens never touch plaintext files.

ts
import { setSecret, getSecret, deleteSecret, isKeyringAvailable } from "std::auth/keyring"

node main() {
  if (isKeyringAvailable()) {
    setSecret("my-api-key", "sk-abc123")
    const key = getSecret("my-api-key")
    print(key)
    deleteSecret("my-api-key")
  }
}

On macOS this uses the Keychain, and on Linux the Secret Service. Windows is not yet supported, so fall back to environment variables there. Secrets live under the "agency-lang" service name unless you pass a custom service.

Effects

std::setSecret

ts
effect std::setSecret {
  key: string;
  service: string
}

(source)

std::getSecret

ts
effect std::getSecret {
  key: string;
  service: string
}

(source)

std::deleteSecret

ts
effect std::deleteSecret {
  key: string;
  service: string
}

(source)

Functions

setSecret

ts
setSecret(key: string, value: string, service: string): Result

Store a secret in the system keyring, overwriting any existing value for the same key.

@param key - The secret key name @param value - The secret value to store @param service - Keyring namespace the secret is stored under

Parameters:

NameTypeDefault
keystring
valuestring
servicestring"agency-lang"

Returns: Result

Throws: std::setSecret

(source)

getSecret

ts
getSecret(key: string, service: string): Result

Retrieve a secret from the system keyring. Returns the secret value, or null if not found.

@param key - The secret key name @param service - Keyring namespace to read from

Parameters:

NameTypeDefault
keystring
servicestring"agency-lang"

Returns: Result

Throws: std::getSecret

(source)

deleteSecret

ts
deleteSecret(key: string, service: string): Result

Delete a secret from the system keyring. Returns true if deleted, false if the key did not exist.

@param key - The secret key name @param service - Keyring namespace to delete from

Parameters:

NameTypeDefault
keystring
servicestring"agency-lang"

Returns: Result

Throws: std::deleteSecret

(source)

isKeyringAvailable

ts
isKeyringAvailable(): boolean

Check if the system keyring is available on this platform. Returns true on macOS and on Linux with secret-tool installed, false otherwise.

Returns: boolean

(source)