Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wallet import #1

Closed
wants to merge 4 commits into from
Closed

feat: wallet import #1

wants to merge 4 commits into from

Conversation

rplusq
Copy link
Owner

@rplusq rplusq commented Jul 26, 2023

Motivation

Intro

Most of the motivation comes from these issues:
Issue#1869
Issue#3818

Big shoutout to @PatrickAlphaC for the proposed API

Summary

If you want to use your own private keys, you are going to either: expose them on the terminal or type them every time through --interactive. A great alternative would be to use keystores, but these are limited to random ones created through cast wallet new PATH.

It would also be good to be able to set some env vars and then forget about that, while also maintaining a high security standard.

Solution

New Features

cast wallet import

Encrypt private keys through JSON keystores into a default directory (~/.foundry/keystores) that can later be accessed through their assigned names when using cast send, forge create or forge script.

cast wallet import --interactive

Which then prompts the user for a password, and encrypts it locally on the default directory.

cast wallet list

Have a command to list stored keystores in the default directory

cast wallet list

Changes to the codebase

Extraction of Wallet's Raw Opts

I had to extract the raw options from the opts/wallet:Wallet struct. This is cause I wanted to reduce the amount of code duplication, so now I could use that in the use of cast wallet import, which really only cares about the handling of mnemonics and private keys.

Adding of --account option for MultiWallet and Wallet

In order to leverage the imported keystores by name, I had to create a new option: --account or ETH_KEYSTORE_ACCOUNT. This enables to simplify the following command:

forge script scripts/<YOUR_SCRIPT> --keystore ~/.foundry/keystotres/<account_name>.json --broadcast

into the smaller / simpler:

forge script scripts/<YOUR_SCRIPT> --account <account_name> --broadcast

Copy link

@nopestack nopestack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1st pass, looks good overall, only a few minor improvements

cli/src/cmd/cast/wallet/mod.rs Outdated Show resolved Hide resolved
cli/src/cmd/cast/wallet/mod.rs Outdated Show resolved Hide resolved
cli/src/cmd/cast/wallet/mod.rs Show resolved Hide resolved
cli/src/cmd/cast/wallet/mod.rs Show resolved Hide resolved
cli/src/opts/wallet/multi_wallet.rs Show resolved Hide resolved
@rplusq rplusq force-pushed the feat/wallet-import branch from 2d7132a to ede2d55 Compare August 5, 2023 13:15
@rplusq rplusq force-pushed the feat/wallet-import branch 2 times, most recently from 7897626 to 13ed300 Compare August 6, 2023 01:21
@rplusq rplusq force-pushed the feat/wallet-import branch from 13ed300 to 215f6f4 Compare August 6, 2023 20:17
@rplusq
Copy link
Owner Author

rplusq commented Aug 6, 2023

Created the PR into foundry, thanks @nopestack for the guidance

@rplusq rplusq closed this Aug 6, 2023
rplusq pushed a commit that referenced this pull request Oct 16, 2023
* fuzz single refactor

* add struct docs

* Update crates/evm/src/fuzz/mod.rs

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>

* add docs and move types to types.rs

* fmt

* add docki docs

* fmt

---------

Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
rplusq pushed a commit that referenced this pull request Oct 16, 2023
* feat: use alloy revm branch

* fuzz/mod migrated

* progress

* progress, fmt

* fix imdb

* feat: cheatcodes compile

* feat: fork backend compiles

* feat: trace

* fuzz

* anvil progress

* chore: mem, fmt

* chore: db.rs

* chore: it lives

* fix test

* chore: clippy

* workin

* main backend stuff migrated

* chore: add glue on other crates

* chore: make executor use alloy types

* add glue for executor migration

* chore: use workspace alloy

* chore: undo revm bump changes

* chore: remove unneded prefix

* chore: fix fork fixture

* chore: uncomment tests

* chore: switch to up-to-date revm

* chore: clippy

* (foundry-rs#2) Alloy Migration: Migrate non-cheatcode inspectors (foundry-rs#5770)

* feat: migrate non-cheatcode inspectors

* fix: properly create both create and create2 addresses

* chore: clippy

* (foundry-rs#3) Alloy Migration: migrate fork-adjacent files to alloy primitives (foundry-rs#5771)

* chore: use create2_from_code

* borrow it brah

* chore: use from word

* chore: drop to_be_bytes

* fmt

* chore: use from_word on both palces

* chore: use address::random

* chore: make failure slot b256

* chore: use address::random

* chore: fix indexes

* chore: use contract.hash

* chore: do not collect

* chore: use display on alloy nums

* use + operator

* chore: unwrap bytes and replace import

* chore: Into:: -> ::from

* chore: fix test

* chore: use alloy imports

* chore: switch to alloy typesd

* chore: fix test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants