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

Commit

Permalink
feat(eip712): add raw_salt attribute (#2331)
Browse files Browse the repository at this point in the history
* chore: bump syn to 2.0, fix breaking changes

* chore: update ethers-contract-derive to use syn 2

* chore: move eip712 into ethers-contract-derive

* fix: temp disable prettyplease formatting

* chore: update prettyplease

* fix mergings

* fix

* ci: disable live-tests since it doesn't do anything

* update

* chore: re-add eip712 feature for backwards compatibility

* chore: bump dependencies

* feat(eip712): add raw_salt attribute
  • Loading branch information
DaniPopes authored Apr 12, 2023
1 parent 7cae405 commit 9a5b31a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion ethers-contract/ethers-contract-derive/src/eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::utils;
use ethers_core::{
abi::{Address, ParamType},
macros::ethers_core_crate,
types::transaction::eip712::EIP712Domain,
types::{transaction::eip712::EIP712Domain, H256},
utils::keccak256,
};
use inflector::Inflector;
Expand Down Expand Up @@ -109,12 +109,20 @@ fn parse_attributes(input: &DeriveInput) -> Result<EIP712Domain> {
litstr.value().parse().map_err(|e| Error::new(litstr.span(), e))?;
domain.verifying_contract = Some(addr);
}
// hash string
"salt", domain.salt => {
meta.input.parse::<Token![=]>()?;
let litstr: LitStr = meta.input.parse()?;
let hash = keccak256(litstr.value());
domain.salt = Some(hash);
}
// parse string as H256
"raw_salt", domain.salt => {
meta.input.parse::<Token![=]>()?;
let litstr: LitStr = meta.input.parse()?;
let bytes = litstr.value().parse::<H256>().map_err(|e| Error::new(litstr.span(), e))?;
domain.salt = Some(bytes.0);
}
);
Ok(domain)
}
Expand Down
3 changes: 2 additions & 1 deletion ethers-contract/tests/it/eip712.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ fn derive_eip712() {
name = "Radicle",
version = "1",
chain_id = 1,
verifying_contract = "0x0000000000000000000000000000000000000001"
verifying_contract = "0x0000000000000000000000000000000000000001",
raw_salt = "0x3000000000000000000000000000000000000000000000000000000000000000"
)]
pub struct Puzzle {
pub organization: H160,
Expand Down

0 comments on commit 9a5b31a

Please sign in to comment.