refactor(signer-local): replace eth-keystore with inline keystore implementation#3831
Open
refactor(signer-local): replace eth-keystore with inline keystore implementation#3831
Conversation
…lementation Removes the eth-keystore dependency by reimplementing the Web3 Secret Storage keystore logic directly using alloy primitives and the same underlying crypto crates (aes, ctr, scrypt, pbkdf2, hmac, sha2). - Uses alloy_primitives::keccak256 instead of sha3::Keccak256 - Uses alloy_primitives::hex for serde helpers instead of the hex crate - Uses alloy_primitives::Address instead of ethereum_types::H160 - Replaces keystore-geth-compat feature with always-available Option<Address> on EthKeystore - Adds input validation: dklen >= 32, iv >= 16 bytes, scrypt n must be a power of two (uses integer ilog2 instead of float log2) - Renames error variant from EthKeystoreError to KeystoreError - Re-exports keystore types from crate root under keystore feature Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d1c07-7274-7568-8ce0-a01fc3f8c7ca
- Re-add keystore-geth-compat feature that derives address from pk during encrypt_key using alloy_signer::utils::secret_key_to_address - Add Apache-2.0 attribution to eth-keystore (Rohit Narurkar) in module doc header - Restore geth-compat test asserting address is populated - Fix KeystoreError display strings to match original eth-keystore messages (Mac Mismatch, IO:, serde-json:, scrypt) Co-authored-by: zerosnacks <95942363+zerosnacks@users.noreply.github.com> Amp-Thread-ID: https://ampcode.com/threads/T-019d1c07-7274-7568-8ce0-a01fc3f8c7ca
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.
Removes the
eth-keystoredependency fromalloy-signer-localby reimplementing the Web3 Secret Storage keystore logic directly.Motivation
eth-keystoreis unmaintained (last published 2022). Inlining the implementation gives alloy full control over the keystore code, removes an external dependency, and allows using alloy primitives natively.Changes
keystoremodule (src/keystore/mod.rs): Reimplementsnew,decrypt_key,encrypt_keyand all keystore types (EthKeystore,CryptoJson,CipherparamsJson,KdfType,KdfparamsType,KeystoreError)aes,ctr,scrypt,pbkdf2,hmac,sha2,uuid— same crates, just owned directly behind thekeystorefeaturealloy_primitives::keccak256(replacessha3),alloy_primitives::hex(replaceshexcrate),alloy_primitives::Address(replacesethereum_types::H160)keystore-geth-compatfeature: Address field is nowOption<Address>always, no feature flag neededdklen >= 32,iv >= 16 bytes, scryptnmust be a power of two (integerilog2instead of floatlog2)LocalSignerError::EthKeystoreError→LocalSignerError::KeystoreErrorBreaking changes
LocalSignerError::EthKeystoreErrorrenamed toLocalSignerError::KeystoreErrorwith inner typekeystore::KeystoreErrorinstead ofeth_keystore::KeystoreErrorkeystore-geth-compat/signer-keystore-geth-compatfeatures removedEthKeystore::addressis nowOption<Address>instead of being conditionally compiledPrompted by: zerosnacks