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

EIP712 #169

Open
BlinkyStitt opened this issue Nov 6, 2018 · 5 comments
Open

EIP712 #169

BlinkyStitt opened this issue Nov 6, 2018 · 5 comments
Labels

Comments

@BlinkyStitt
Copy link

I'm wanting to hash 0x orders and they use EIP712. I'm trying to write this in rust and not javascript. Is this currently possible with rust-web3?

@tomusdrw
Copy link
Owner

tomusdrw commented Nov 9, 2018

@wysenynja We don't have that method exposed yet (PRs welcome!). You can freely extend rust-web3 though, you will just need to define all the input and output types and their deserialization.

@That3Percent
Copy link
Contributor

There is a separate crate which may fit the bill here: eip-712

@gakonst
Copy link

gakonst commented Jun 18, 2020

Doesn't that conflict with this library's MIT license?

@tomusdrw
Copy link
Owner

@gakonst Correct, the crate mentioned here can't really be included in web3, but you are fine to build a GPL-3.0 project that uses both web3 and eip-712 to achieve what you need.

@That3Percent
Copy link
Contributor

Dismayed by the licensing, I went ahead to build a replacement for the GPL licensed eip-712 crate that is MIT licensed and is based on structs instead of JSON. It's not yet batteries included, but you can see examples of how to use it in the tests section.

https://github.com/graphprotocol/eip-712-derive

Example usage:

struct Mail {
    from: Person,
    to: Person,
    contents: String,
}
// This is all that is necessary to implement any EIP-712 signable struct
impl StructType for Mail {
    const TYPE_NAME: &'static str = "Mail";
    fn visit_members<T: MemberVisitor>(&self, visitor: &mut T) {
        visitor.visit("from", &self.from);
        visitor.visit("to", &self.to);
        visitor.visit("contents", &self.contents);
    }
}

/* Elided Person struct, etc */

fn test() -> (Signature, RecoveryId) {
 let domain = DomainStruct {
        name: "Ether Mail".to_owned(),
        version: "1".to_owned(),
        chain_id: chain_id::MAIN_NET,
        verifying_contract: Address(
            (&(hex::decode("CcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC").unwrap())[..])
                .try_into()
                .unwrap(),
        ),
    };
let domain_separator = DomainSeparator::new(&domain);
let message = Mail {
        from: Person { /* elided */ },
        to: Person { /* elided */ },
        contents: "Hello, Bob!".to_owned(),
    };
 sign_typed(&domain_separator, &message, &pk)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants