Skip to content

feat: Encrypt secret keys at rest in config.toml #9

@Nanle-code

Description

@Nanle-code

Summary

Secret keys are currently stored in plaintext in ~/.starforge/config.toml.
While this is acceptable for throwaway testnet wallets, it is a security risk
for any wallet holding real value. Encrypting keys at rest with a user-provided
passphrase would significantly improve security.

Task

Add opt-in passphrase-based encryption for secret keys stored in config.toml,
using AES-256-GCM. When a passphrase is set, secret keys are stored encrypted
and decrypted on-demand when needed for signing.

Acceptance Criteria

  • starforge wallet create alice --encrypt prompts for a passphrase and stores the key encrypted
  • Encrypted keys are stored as base64 ciphertext in config.toml
  • starforge wallet show alice --reveal prompts for the passphrase to decrypt and display the key
  • If the wrong passphrase is entered, a clear error is shown (no panic)
  • Unencrypted wallets continue to work without any change
  • The encryption scheme (AES-256-GCM + PBKDF2) is documented in the README

Files Likely Touched

  • Cargo.toml — add aes-gcm and pbkdf2 crates
  • src/utils/config.rs — add encrypt_key and decrypt_key functions
  • src/commands/wallet.rs — add --encrypt flag and passphrase prompts

Notes

Use aes-gcm crate for encryption and pbkdf2 with SHA-256 for key derivation
from the passphrase. Store the salt alongside the ciphertext in config.toml.
Never store the passphrase itself. Prompt securely using the rpassword crate.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions