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: allow multiple signing credentials in NetworkSigner #515

Merged
merged 9 commits into from
Apr 12, 2024

Conversation

prestwich
Copy link
Member

Resolves signer filler not setting from and failing to sign

Motivation

Unblock foundry dev

Solution

  • NetworkSigner<N> is now expected to contain a store of credentials, by address.
  • NetworkSigner<N> now selects credentials based on request from field
  • NetworkSigner<N> allows user-specified sender when signing

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@prestwich prestwich added enhancement New feature or request debt Tech debt which needs to be addressed labels Apr 11, 2024
@prestwich prestwich self-assigned this Apr 11, 2024
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.

I like this, this is pretty much exactly what we have here:

https://github.com/paradigmxyz/reth/blob/39dea65b63d1acac8370bac12ddea2c809ed7803/crates/rpc/rpc/src/eth/signer.rs#L44-L49

can we also add, or similar:

/// Returns `true` whether this signer can sign for this address
    fn is_signer_for(&self, addr: &Address) -> bool

Comment on lines 25 to 31
/// Asynchronously sign an unsigned transaction, with a specified
/// credential.
async fn sign_transaction_from(
&self,
sender: Option<Address>,
tx: N::UnsignedTx,
) -> alloy_signer::Result<N::TxEnvelope>;
Copy link
Member

Choose a reason for hiding this comment

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

this makes sense to me and is convenient to have,
it should be trivial for any, non-multiplex signers to implement by ensuring the default signer is Some(sender)

Copy link
Member Author

Choose a reason for hiding this comment

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

doing a slight cleanup here as i wrote this function signature before i added the default signer

Copy link
Member Author

Choose a reason for hiding this comment

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

removed the Option because we can rely on the caller to call default_signer

@prestwich
Copy link
Member Author

I like this, this is pretty much exactly what we have here:

https://github.com/paradigmxyz/reth/blob/39dea65b63d1acac8370bac12ddea2c809ed7803/crates/rpc/rpc/src/eth/signer.rs#L44-L49

can we also add, or similar:

/// Returns `true` whether this signer can sign for this address
    fn is_signer_for(&self, addr: &Address) -> bool

Added that, and a method to get an iterator of addresses that we can sign with

@@ -148,7 +148,7 @@ impl TransactionBuilder<Ethereum> for TransactionRequest {
self,
signer: &S,
) -> BuilderResult<<Ethereum as Network>::TxEnvelope> {
Ok(signer.sign_transaction(self.build_unsigned()?).await?)
Ok(signer.sign_request(self).await?)
Copy link
Member Author

Choose a reason for hiding this comment

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

these were dropping the from field during the build process regardless of whether it were set in the first place 😓

@prestwich prestwich merged commit f44973a into main Apr 12, 2024
18 checks passed
@prestwich prestwich deleted the prestwich/signer-multiplex branch April 12, 2024 12:13
@DaniPopes
Copy link
Member

What does "Preswitch/signer multiplex" mean? 😄

@prestwich
Copy link
Member Author

branch name 😅

@prestwich prestwich changed the title Prestwich/signer multiplex Feat: allow multiple signing credentials in NetworkSigner Apr 12, 2024
ben186 pushed a commit to ben186/alloy that referenced this pull request Jul 27, 2024
* feature: signer multiplexing

* fix: register default on instantiation

* docs: fixup

* fix: clippy

* fix: sign_request

* fix: clippy

* feat: is_signer_for and signers

* fix: signer returns copied addresses

* fix: remove unnecessary option
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debt Tech debt which needs to be addressed enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants