feat: encrypt private keys at rest using keystore#44
Open
mvanhorn wants to merge 2 commits intoPolymarket:mainfrom
Open
feat: encrypt private keys at rest using keystore#44mvanhorn wants to merge 2 commits intoPolymarket:mainfrom
mvanhorn wants to merge 2 commits intoPolymarket:mainfrom
Conversation
Wallet create and import now encrypt private keys using the standard Ethereum keystore format (AES-128-CTR + scrypt), the same format used by MetaMask, Geth, and Foundry. Users are prompted for a password on key creation/import and when any command needs the key. The POLYMARKET_PASSWORD env var supports non-interactive use (CI/scripts). Use --no-password to opt into plaintext storage (not recommended). Adds wallet export subcommand to decrypt and display the key. Fixes Polymarket#18 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
…xt path Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
Addressed both cursor findings in d491d80:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
~/.config/polymarket/config.jsonwere stored as plaintext - any process running as the same user could read themwallet createandwallet importnow encrypt keys using the standard Ethereum keystore format (AES-128-CTR + scrypt), the same format used by MetaMask, Geth, and FoundryPOLYMARKET_PASSWORDenv var for CI/scripts)--no-passwordflag available for plaintext storage (not recommended)wallet exportsubcommand to decrypt and display the key for backupNew dependencies
rpassword- secure terminal password input (no echo)rand0.8 - RNG for keystore encryptionalloysigner-keystorefeature - standard keystore encrypt/decryptFixes #18
Supersedes #19 (pre-refactor, needs full rewrite after #13)
Test plan
cargo fmt --checkpassescargo clippy -- -D warningspassescargo testpasses (131 tests)polymarket wallet createprompts for password and stores encrypted keystorepolymarket wallet create --no-passwordstores plaintext (with warning)polymarket wallet import <key>prompts for passwordpolymarket wallet exportdecrypts and shows keyPOLYMARKET_PASSWORD=xxx polymarket wallet addressworks without interactive promptThis contribution was developed with AI assistance (Claude Code).
Note
High Risk
Changes wallet key storage and retrieval to support encrypted keystore files and password prompting, which is security-sensitive and affects all commands that need a private key. Misconfiguration or edge cases (missing keystore, password handling, filesystem moves) could block access to funds or break automation.
Overview
Private keys are no longer stored in plaintext by default:
wallet create/wallet importnow write an Ethereum keystore file under~/.config/polymarket/keystoreand mark the config with anencryptedflag, prompting for a password (or usingPOLYMARKET_PASSWORD).Adds
wallet exportto decrypt and print the private key for backup, and introduces--no-passwordon create/import to explicitly keep legacy plaintext storage (with warnings/cleanup of leftover keystore files). This also updates dependencies to enable Alloy keystore support and addsrpassword/rand, with the lockfile pulling in keystore/crypto crates.Written by Cursor Bugbot for commit d491d80. This will update automatically on new commits. Configure here.