Skip to content

API Reference parrot.security.credentials_utils

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.security.credentials_utils

View source

Credential encryption helpers — envelope v2 (FEAT-099).

Credentials are sealed with the navigator-session vault kernel and bound (AEAD associated data) to the document they live in::

user_credentials   purpose="parrot-credential"  (user_id, name, field="credential")
user_llm_keys      purpose="parrot-llm-key"     (user_id, provider, field="api_key")

A ciphertext copied to another user, credential name or provider therefore fails to decrypt instead of silently opening.

The stored representation stays a base64 ASCII string, so DocumentDB string fields are unchanged.

Attribute CREDENTIAL_FIELD

Attribute CREDENTIAL_PURPOSE

Attribute LLM_KEY_FIELD

Attribute LLM_KEY_PURPOSE

Function credential_context

Context of user_credentials.credential for (user_id, name).

credential_context(user_id: Any, name: str) -> VaultContext

Parameter Type Default Description
user_id Any
name str

Returns: VaultContext

Function decrypt_credential

Decrypt a credential string stored by :func:encrypt_credential.

decrypt_credential(encrypted: str, context: VaultContext, keyring: KeyRing) -> dict

Parameter Type Default Description
encrypted str Base64-encoded sealed envelope.
context VaultContext Expected context of the document and field.
keyring KeyRing Vault key ring holding the referenced key version.

Returns: dict — Original credential dict.

Raises:

  • navigator_session.vault.VaultCryptoError — Tampered ciphertext, wrong document/field, unknown key version or legacy (v1) format.
  • binascii.Error — If encrypted is not valid base64.

Function encrypt_credential

Encrypt a credential dict for DocumentDB storage.

encrypt_credential(credential: dict, context: VaultContext, keyring: KeyRing, *, key_id: Optional[int] = None) -> str

Parameter Type Default Description
credential dict Dict of secret values (e.g. asyncdb connection params or {"api_key": "sk-..."}). All unicode values round-trip.
context VaultContext Context binding the ciphertext to its document and field (see :func:credential_context / :func:llm_key_context).
keyring KeyRing Vault key ring; new ciphertexts use its active key.
key_id Optional[int] None Optional master key version override (rotation/migration).

Returns: str — Base64-encoded (ASCII) sealed envelope, ready for DocumentDB.

Function llm_key_context

Context of user_llm_keys.api_key for (user_id, provider).

llm_key_context(user_id: Any, provider: str) -> VaultContext

Parameter Type Default Description
user_id Any
provider str

Returns: VaultContext

Function normalize_user_id

Canonical user_id for credential contexts.

Session user ids reach these helpers as int or str; digit-only strings are normalized to int so the same document opens regardless of the caller. Runtime and the migration target must use this function.

normalize_user_id(user_id: Any) -> Any

Parameter Type Default Description
user_id Any

Returns: Any

Raises:

  • ValueError — If user_id is empty, a bool, or of another type.

Function reseal_credential

Re-seal a credential for a new context (rename of name/provider).

reseal_credential(encrypted: str, old_context: VaultContext, new_context: VaultContext, keyring: KeyRing) -> str

Parameter Type Default Description
encrypted str Currently stored ciphertext.
old_context VaultContext Context it was sealed with.
new_context VaultContext Context of the new document identity.
keyring KeyRing Vault key ring.

Returns: str — Base64-encoded ciphertext bound to new_context.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally