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

feature: allow signature to recover typed_data payloads #2120

Merged
merged 3 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Unreleased

- Add `Signature::recover_typed_data` [#2120](https://github.com/gakonst/ethers-rs/pull/2120)
- Add `abi::encode_packed` [#2104](https://github.com/gakonst/ethers-rs/pull/2104)
- Add support for custom JavaScript tracer to `debug_traceCall` and `debug_traceTransaction` [#2064](https://github.com/gakonst/ethers-rs/pull/2064)
- Add a `Send` bound to the `IntoFuture` implementation of `ContractCall` [#2083](https://github.com/gakonst/ethers-rs/pull/2083)
Expand Down
16 changes: 16 additions & 0 deletions ethers-core/src/types/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ impl fmt::Display for Signature {
}
}

#[cfg(feature = "eip712")]
impl Signature {
/// Recovers the ethereum address which was used to sign a given EIP712
/// typed data payload.
///
/// Recovery signature data uses 'Electrum' notation, this means the `v`
/// value is expected to be either `27` or `28`.
pub fn recover_typed_data<T>(&self, payload: T) -> Result<Address, SignatureError>
where
T: super::transaction::eip712::Eip712,
{
let encoded = payload.encode_eip712().map_err(|_| SignatureError::RecoveryError)?;
self.recover(encoded)
}
}

impl Signature {
/// Verifies that signature on `message` was produced by `address`
pub fn verify<M, A>(&self, message: M, address: A) -> Result<(), SignatureError>
Expand Down