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

refactor(signers): use signer for single credentials and wallet for credential stores #883

Merged
merged 34 commits into from
Jun 13, 2024

Conversation

zerosnacks
Copy link
Member

@zerosnacks zerosnacks commented Jun 12, 2024

Motivation

Closes: #575

Related downstream PR: alloy-rs/examples#92

Solution

Current naming of signer types is somewhat confusing. Move to standardize naming by reviewing usage of the words "signer" and "wallet":

  • A signer is a single credential capable of signing hashes or txns or other data under a single address.
  • A wallet is a credential store capable of storing multiple signers, and selecting a signer to use to sign hashes, or txns, or other data.

Changes:

  • NetworkSigner -> NetworkWallet
  • LocalWallet -> LocalSigner
  • signer-wallet -> signer-local (note: updated crate name!)
  • LocalSigner<SigningKey> previously exported as LocalSigner -> PrivateKeySigner

Expected change in syntax:

-    // Set up wallet from the first default Anvil account (Alice).
-    let wallet: LocalWallet = anvil.keys()[0].clone().into();

+    // Set up signer from the first default Anvil account (Alice).
+    let signer: PrivateKeySigner = anvil.keys()[0].clone().into();

     let provider = ProviderBuilder::new()
         .with_recommended_fillers()
-        .signer(EthereumSigner::from(wallet))
+        .wallet(EthereumSigner::from(signer))
         .on_http(rpc_url);

Major breaking / invasive changes, in the context of @prestwich's request

yes all things named "Signer" or "Wallet" should conform to new naming convention. refactor should be as extensive as possible
the signer- crates contain only signers. however, we may want to introduce wallet- crates to take over GCP/AWS/Ledger/Trezor, which are inappropriately handled as single credentials

Renaming of signer-* to wallet-* crates is not handled in this PR per comment: #883 (comment)

Included deprecation notices where I thought it made sense (and was possible)

Note: @yash-atreya / @zerosnacks / @gakonst requires changes in alloy-rs/book / alloy-rs/examples and examples in public relations

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@zerosnacks zerosnacks changed the title Zerosnacks/refactor signer wallet refactor(signers): use signer for single credentials and wallet for credential stores Jun 12, 2024
Comment on lines 36 to 41
/// A signer instantiated with a locally stored private key.
pub type FilledLocalSigner = LocalSigner<SigningKey>;

/// A wallet instantiated with a YubiHSM
/// A signer instantiated with a YubiHSM.
#[cfg(feature = "yubihsm")]
pub type YubiWallet = Wallet<yubihsm::ecdsa::Signer<k256::Secp256k1>>;
pub type FilledYubiSigner = LocalSigner<yubihsm::ecdsa::Signer<k256::Secp256k1>>;
Copy link
Member Author

Choose a reason for hiding this comment

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

Not a fan of the Filled* name, any suggestions @prestwich?

Copy link
Member Author

@zerosnacks zerosnacks Jun 13, 2024

Choose a reason for hiding this comment

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

Went with PrivateKeySigner (prev. LocalSigner) and YubiSigner for now

@prestwich
Copy link
Member

hold off on moving the signer-* crates for now. Right now they all still are signers, as they manage only a single credential. introducing wallet-* is significant future work

/// The wallet's address.
pub struct LocalSigner<C> {
/// The signers' credential.
pub(crate) credential: C,
Copy link
Member Author

Choose a reason for hiding this comment

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

Referring to inner private_key as credential for flexibility, open to changing it

README.md Outdated Show resolved Hide resolved
@zerosnacks zerosnacks marked this pull request as ready for review June 13, 2024 10:06
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

lgtm

crates/signer-local/src/lib.rs Outdated Show resolved Hide resolved
crates/signer-local/src/lib.rs Outdated Show resolved Hide resolved
crates/signer/README.md Outdated Show resolved Hide resolved
crates/signer-local/src/lib.rs Show resolved Hide resolved
zerosnacks added a commit that referenced this pull request Jun 13, 2024
zerosnacks added a commit to alloy-rs/examples that referenced this pull request Jun 13, 2024
Copy link
Member

@prestwich prestwich left a comment

Choose a reason for hiding this comment

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

few things now called wallets that should not have been changed

crates/signer-trezor/src/signer.rs Outdated Show resolved Hide resolved
crates/signer-ledger/src/signer.rs Outdated Show resolved Hide resolved
@@ -437,11 +439,17 @@ impl<L, F> ProviderBuilder<L, F, Ethereum> {
let anvil_layer = crate::layers::AnvilLayer::from(f(Default::default()));
let url = anvil_layer.endpoint_url();

let wallet = alloy_signer_wallet::Wallet::from(anvil_layer.instance().keys()[0].clone());
let default_keys = anvil_layer.instance().keys().to_vec();
let (default_key, remaining_keys) = default_keys.split_first().expect("no keys available");
Copy link
Member

Choose a reason for hiding this comment

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

prevent panic from having 0 keys when calling on_anvil_with_wallet_and_config

This can panic if the f function sets accounts to 0. This is not concerning (and is the pre-existing behavior) but we should probably fix it

followup work (not this PR)

Copy link
Member

Choose a reason for hiding this comment

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

@prestwich
Copy link
Member

tests are broken because they iterate over the hashmap in the NetworkWallet. just remove the use of iteration and use contains instead 👍

@zerosnacks
Copy link
Member Author

tests are broken because they iterate over the hashmap in the NetworkWallet. just remove the use of iteration and use contains instead 👍

Will do

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgtm

@zerosnacks zerosnacks merged commit b000e16 into main Jun 13, 2024
22 checks passed
@zerosnacks zerosnacks deleted the zerosnacks/refactor-signer-wallet branch June 13, 2024 15:28
zerosnacks added a commit to alloy-rs/examples that referenced this pull request Jun 13, 2024
* update according to proposed changes alloy-rs/alloy#883

* Trezor|Ledger|Aws wallet -> signer

* bump to latest alloy version incl. signer -> wallet commit
ben186 pushed a commit to ben186/alloy that referenced this pull request Jul 27, 2024
…or credential stores (alloy-rs#883)

* NetworkSigner -> NetworkWallet

* LocalWallet -> LocalSigner, TrezorSigner -> TrezorWallet, LedgerSigner -> LedgerWallet, GcpSigner -> GcpWallet, AwsSigner stays because it is a single credential mapping to a single public key - not a keyring like Gcp

* EthereumSigner -> EthereumWallet, SignerFiller -> WalletFiller

* start major refactor

* signer -> credential

* minor fixes, still issue with on_http method cannot be called due to unsatisfied trait bounds

* fix tests

* signer-(aws|gcp|ledger|trezor) -> wallet-(aws|gcp|ledger|trezor)

* update docs

* more doc fixes

* move wallet implementations into its own block

* wallet -> signer, come up with better name than FilledLocalSigner

* default MnemonicBuilder to English

* fix docs

* fix doctests

* revert signer -> wallet crate renaming

* pull in main fix for rust-tls, fix flag

* FilledLocalSigner -> PrivateKeySigner

* minor fixes

* minor fixes

* fix clippy

* Update README.md

Co-authored-by: DaniPopes <[email protected]>

* add private key signer to list

* Update crates/signer-local/src/lib.rs

Co-authored-by: DaniPopes <[email protected]>

* Update crates/signer-local/src/lib.rs

Co-authored-by: DaniPopes <[email protected]>

* Update crates/signer/README.md

Co-authored-by: DaniPopes <[email protected]>

* add deprecation notice on LocalWallet and YubiWallet

* fix my broken english

* TrezorWallet -> TrezorSigner, GcpWallet -> GcpSigner, AwsWallet -> AwsSigner, LedgerWallet -> LedgerSigner

* populate wallet with all known default anvil keys

* revert, due to the way BTreeMap backing the signer_addresses it does not retain the insertion order

* add back multi-key insertion

* fix build issues

---------

Co-authored-by: DaniPopes <[email protected]>
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.

[Refactor]: use "signer" for single credentials and "wallet" for credential stores
4 participants