security: encrypt EOA private key with keystore JSON#34
Open
Conversation
The EOA vanity miner previously printed the raw private key to stdout, creating a data leak risk via terminal logs, screen capture, or piped output. Now the key is encrypted using the standard Ethereum Web3 Secret Storage format (scrypt + AES-128-CTR) and saved to a JSON keystore file with 0600 permissions. The raw key is never printed and is zeroed from memory after encryption. New flags: --output/-o, --password, --light-kdf Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use unix.Mlock() to lock private key memory pages, preventing the OS from swapping them to disk where they could be recovered. The memory is unlocked with Munlock() after the key bytes are zeroed. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
big.Int.Bytes() strips leading zeros, which causes crypto.ToECDSA to reject keys shorter than 32 bytes with "invalid length, need 256 bits". Use FillBytes to always produce a fixed 32-byte slice. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
0600permissions — the same format used bygeth account new--output/-ofor custom file path,--passwordfor scripted use,--light-kdffor faster encryption in testingSecurity details
golang.org/x/term.ReadPassword()(no echo) with confirmation0600permissions (owner read/write only)big.Intbits and[]byteslice) is explicitly zeroed after useUsage
Test plan
go build ./...compiles cleanlygo vet ./...passesgo test ./...passes--light-kdf --password test, verify keystore JSON is written🤖 Generated with Claude Code