feature: allow signature to recover typed_data payloads (#2120)

* feature: allow signature to recover typed_data payloads

* fix: under feature flag and Changelog

* fix: undo accidental doc mangling
This commit is contained in:
James Prestwich 2023-02-06 16:27:35 -05:00 committed by GitHub
parent 0236de8d2a
commit e5e4da07c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -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)

View File

@ -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>