Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Feat/is middleware signer #182

Merged
merged 4 commits into from
Jan 28, 2021

Conversation

roynalnaruto
Copy link
Collaborator

Motivation

It would be useful to have a way to know if a middleware can sign data.

A way to know if one of the two is true:

  • The middleware stack contains SignerMiddleware
  • The JSON-RPC provider has an unlocked key and it supports the eth_sign call

Solution

  • Add is_signer method to the Middleware trait
  • is_signer is always true for SignerMiddleware
  • is_signer is true if the JSON-RPC provider has an unlocked key and supports eth_sign call

Comment on lines 341 to 349
// deserialize the signature from its {r, s, v} components.
let v = sig[128..130].parse::<u64>().unwrap();
let sig_json = format!(
r#"{{"r": "0x{}", "s": "0x{}", "v": {}}}"#,
&sig[..64],
&sig[64..128],
v
);
Ok(serde_json::from_str(&sig_json).map_err(ProviderError::SerdeJson)?)
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of this, should we instead use the Signature TryFrom?

let sig = hex::decode(sig)?
Ok(Signature::try_from(sig)?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed 👍

@gakonst gakonst merged commit 4c8d3c8 into gakonst:master Jan 28, 2021
@roynalnaruto roynalnaruto deleted the feat/is-middleware-signer branch April 16, 2022 15:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants