keys
flavor.psp.format_2025.keys
¶
PSPF Key Management - Functions for handling cryptographic keys.
Provides pure functions for key resolution, generation, and persistence. Supports multiple key sources with clear priority ordering.
Classes¶
Functions¶
create_key_config
¶
create_key_config(
seed: str | None = None,
private_key: bytes | None = None,
public_key: bytes | None = None,
key_path: Path | None = None,
) -> KeyConfig
Helper function to create a KeyConfig with validation.
Ensures that key configuration is consistent and valid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
str | None
|
Seed for deterministic generation |
None
|
private_key
|
bytes | None
|
Explicit private key bytes |
None
|
public_key
|
bytes | None
|
Explicit public key bytes |
None
|
key_path
|
Path | None
|
Path to load keys from |
None
|
Returns:
| Type | Description |
|---|---|
KeyConfig
|
Validated KeyConfig instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If configuration is invalid |
Source code in flavor/psp/format_2025/keys.py
generate_deterministic_keys
¶
Generate deterministic Ed25519 keys from a seed string.
Uses SHA256 to derive a 32-byte seed from the input string, ensuring reproducible key generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
str
|
Seed string for deterministic generation |
required |
Returns:
| Type | Description |
|---|---|
tuple[bytes, bytes]
|
Tuple of (private_key, public_key) as bytes |
Source code in flavor/psp/format_2025/keys.py
generate_ephemeral_keys
¶
Generate new ephemeral Ed25519 keys.
Creates a new random key pair that will be discarded after use.
Returns:
| Type | Description |
|---|---|
tuple[bytes, bytes]
|
Tuple of (private_key, public_key) as bytes |
Source code in flavor/psp/format_2025/keys.py
load_keys_from_path
¶
Load Ed25519 keys from filesystem.
Expects to find: - flavor-private.key: Raw 32-byte private key - flavor-public.key: Raw 32-byte public key
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_path
|
Path
|
Directory containing key files |
required |
Returns:
| Type | Description |
|---|---|
tuple[bytes, bytes]
|
Tuple of (private_key, public_key) as bytes |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If key files don't exist |
ValueError
|
If key files are invalid |
Source code in flavor/psp/format_2025/keys.py
resolve_keys
¶
Resolve keys based on configuration priority.
Priority order: 1. Explicit keys (if both provided) 2. Deterministic from seed 3. Load from filesystem path 4. Generate ephemeral (default)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
KeyConfig
|
Key configuration specifying key source |
required |
Returns:
| Type | Description |
|---|---|
tuple[bytes, bytes]
|
Tuple of (private_key, public_key) as bytes |
Source code in flavor/psp/format_2025/keys.py
save_keys_to_path
¶
Save Ed25519 keys to filesystem.
Saves raw key bytes to: - flavor-private.key: Raw 32-byte private key - flavor-public.key: Raw 32-byte public key
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
private_key
|
bytes
|
32-byte private key |
required |
public_key
|
bytes
|
32-byte public key |
required |
key_path
|
Path
|
Directory to save keys in |
required |