SigilGuard.Vault behaviour (SigilGuard v0.2.0)

View Source

Secure vaulting behaviour and utilities for the SIGIL protocol.

Provides an interface for encrypting, decrypting, and managing sensitive values (API keys, tokens, credentials) that should never appear in logs or tool call parameters.

Behaviour

Implement SigilGuard.Vault to provide a custom storage backend:

defmodule MyApp.KmsVault do
  @behaviour SigilGuard.Vault

  @impl true
  def encrypt(plaintext, description) do
    # Encrypt via AWS KMS / GCP KMS / HashiCorp Vault
    {:ok, vault_id}
  end

  @impl true
  def decrypt(vault_id) do
    {:ok, plaintext}
  end

  @impl true
  def exists?(vault_id) do
    true
  end
end

Built-in Backend

SigilGuard.Vault.InMemory provides an ETS-backed implementation using AES-256-GCM encryption. Suitable for development and testing.

Summary

Callbacks

Decrypt and return the plaintext for the given vault ID.

Encrypt plaintext and store it, returning a vault ID for later retrieval.

Check if a vault entry exists for the given ID.

Functions

Decrypt a value using the specified backend module.

Encrypt a value using the specified backend module.

Check if a vault entry exists using the specified backend module.

Types

vault_id()

@type vault_id() :: String.t()

Callbacks

decrypt(vault_id)

@callback decrypt(vault_id()) :: {:ok, binary()} | {:error, term()}

Decrypt and return the plaintext for the given vault ID.

encrypt(plaintext, description)

@callback encrypt(plaintext :: binary(), description :: String.t()) ::
  {:ok, vault_id()} | {:error, term()}

Encrypt plaintext and store it, returning a vault ID for later retrieval.

exists?(vault_id)

@callback exists?(vault_id()) :: boolean()

Check if a vault entry exists for the given ID.

Functions

decrypt(vault_id, backend)

@spec decrypt(vault_id(), module()) :: {:ok, binary()} | {:error, term()}

Decrypt a value using the specified backend module.

Examples

{:ok, plaintext} = SigilGuard.Vault.decrypt("vault_abc123", MyVault)

encrypt(plaintext, description, backend)

@spec encrypt(binary(), String.t(), module()) :: {:ok, vault_id()} | {:error, term()}

Encrypt a value using the specified backend module.

Examples

{:ok, id} = SigilGuard.Vault.encrypt("sk-abc123", "OpenAI API key", MyVault)

exists?(vault_id, backend)

@spec exists?(vault_id(), module()) :: boolean()

Check if a vault entry exists using the specified backend module.