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

Create a EIP712 TypedData signature #617

Closed
OnChainArt opened this issue Sep 23, 2022 · 3 comments
Closed

Create a EIP712 TypedData signature #617

OnChainArt opened this issue Sep 23, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@OnChainArt
Copy link

OnChainArt commented Sep 23, 2022

Hi,

I need to do a EIP712 signature in my app. I saw that web3swift allowed EIP712 but when I saw the test file https://github.com/skywinder/web3swift/blob/e733e077a613cba3a68ec7b480f1f7ef1a22d316/Tests/web3swiftTests/localTests/EIP712Tests.swift I saw that it uses a predetermined Gnosis SafeTX. I would like to know how to change the parameters of the safetx to be able to create a correct signature.

@JeneaVranceanu
Copy link
Collaborator

JeneaVranceanu commented Sep 25, 2022

Hello, @OnChainArt !
Looks like Web3Signer.signEIP712 must accept any EIP712Hashable object and not just SafeTx. That's a mistake on the side of the library. I've just updated locally the type of the first input argument of that function, ran tests and can confirm that it will fix the issue.
We will fix that in the upcoming release.

Temporarily you can use the implementation from Web3Signer.signEIP712 in a place where you need to construct a signature or you can create a copy of that function temporarily if you need that in multiple places:

public func signEIP712(_ eip712HashableMessage: EIP712Hashable,
                       keystore: BIP32Keystore,
                       verifyingContract: EthereumAddress,
                       account: EthereumAddress,
                       password: String? = nil,
                       chainId: BigUInt? = nil) throws -> Data {

    let domainSeparator: EIP712DomainHashable = EIP712Domain(chainId: chainId, verifyingContract: verifyingContract)

    let password = password ?? ""
    let hash = try eip712encode(domainSeparator: domainSeparator, message: eip712HashableMessage)

    guard let signature = try Web3Signer.signPersonalMessage(hash, keystore: keystore, account: account, password: password) else {
        throw Web3Error.dataError
    }

    return signature
}

You can even copy-paste this function outside of any class/struct to make it accessible globally.
I'll post updates here as PR will be opened and merged.

@JeneaVranceanu
Copy link
Collaborator

Looks like you'll have to wait until this fix is released as eip712encode function is not public.

@OnChainArt
Copy link
Author

Looks like you'll have to wait until this fix is released as eip712encode function is not public.

Thanks for your reply! I hope it gets fixed soon as it is really relevant for my app.

@Kristenlike1234 Kristenlike1234 added the FAQ common questions tend to recur about web3 infra label Oct 4, 2022
@Kristenlike1234 Kristenlike1234 added bug Something isn't working and removed FAQ common questions tend to recur about web3 infra labels Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants