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

protocol-utils: Signing with SignatureType.EIP712 throws error #116

Closed
Caveman07 opened this issue Jan 17, 2021 · 7 comments
Closed

protocol-utils: Signing with SignatureType.EIP712 throws error #116

Caveman07 opened this issue Jan 17, 2021 · 7 comments

Comments

@Caveman07
Copy link

Current Behavior

Signing RFQ orders as follows:

const order = new RfqOrder({
        makerToken: makerTokenAddress,
        takerToken: takerTokenAddress,
        txOrigin,
        maker: address.toLowerCase(),
        taker: NULL_ADDRESS, 
        makerAmount,
        takerAmount,
        pool: NULL_ADDRESS, 
        expiry: expiryInSeconds,
        salt: generatePseudoRandomSalt(),
        chainId,
    });
await order.getSignatureWithProviderAsync(providerEngine, SignatureType.EIP712);

throws error:

Error: Request for method "eth_signTypedData_v4" not handled by any subprovider. Please check your subprovider configuration to ensure this method is handled.
    at next (index.js:112)
    at MetamaskSubprovider._callee$ (metamask_subprovider.ts:106)
    at tryCatch (runtime.js:63)
    at Generator.invoke [as _invoke] (runtime.js:293)
    at Generator.next (runtime.js:118)
    at ledger.ts:33
    at new Promise (<anonymous>)
    at push../node_modules/@0x/subproviders/lib/src/subproviders/metamask_subprovider.js.__awaiter (ledger.ts:33)
    at MetamaskSubprovider.handleRequest (metamask_subprovider.ts:39)
    at next (index.js:116)
    at Web3ProviderEngine.push../node_modules/web3-provider-engine/index.js.Web3ProviderEngine._handleAsync (index.js:103)
    at index.js:87

On the other hand, signing with SignatureType.EthSign works fine.
It is possible eth_signTypedData_v4 method has limited support by the subprovider engine.

Environment

"@0x/protocol-utils": "^1.1.4",
"@0x/subproviders": "^6.3.0"

| Network |
| mainnet |

@dorothy-zbornak
Copy link
Contributor

eth_signTypedData_v4 is only available on recent versions of metamask. Are you actually using the metamask extension here? Is this embedded in a webpage?

@Caveman07
Copy link
Author

eth_signTypedData_v4 is only available on recent versions of metamask. Are you actually using the metamask extension here? Is this embedded in a webpage?

Yes, I use the 8.1.11 version extension on Chrome browser. Also, signing V3 Limit Orders worked with the same setup.

@dorothy-zbornak
Copy link
Contributor

Are you signing from a hardware wallet?

@Caveman07
Copy link
Author

Are you signing from a hardware wallet?

No

@dorothy-zbornak
Copy link
Contributor

Alright, so I'm actually having trouble replicating your issue but I do see how it could happen. I have a couple PRs in the works to address this (0xProject/tools#21 and #124). Could you maybe show me how you create providerEngine to confirm on my end?

FWIW I am able to get it to work using the following:

import { LimitOrder, SignatureType } from '@0x/protocol-utils';
import { providerUtils } from '@0x/utils';
import { Web3ProviderEngine, MetamaskSubprovider } from '@0x/subproviders';
import { Web3Wrapper } from '@0x/web3-wrapper';

async signOrder() {
    const [maker] = await window.ethereum.request({ method: 'eth_requestAccounts' });
    const provider = providerUtils.standardizeOrThrow(window.ethereum);
    const order = new LimitOrder({ maker, chainId: parseInt(window.ethereum.chainId.slice(2), 16) });
    console.log(await order.getSignatureWithProviderAsync(provider, SignatureType.EIP712));
}

@dorothy-zbornak
Copy link
Contributor

Just merged and published the fixes. Try updating your dependencies and let me know if they work for you.

@Caveman07
Copy link
Author

Alright, so I'm actually having trouble replicating your issue but I do see how it could happen. I have a couple PRs in the works to address this (0xProject/tools#21 and #124). Could you maybe show me how you create providerEngine to confirm on my end?

FWIW I am able to get it to work using the following:

import { LimitOrder, SignatureType } from '@0x/protocol-utils';
import { providerUtils } from '@0x/utils';
import { Web3ProviderEngine, MetamaskSubprovider } from '@0x/subproviders';
import { Web3Wrapper } from '@0x/web3-wrapper';

async signOrder() {
    const [maker] = await window.ethereum.request({ method: 'eth_requestAccounts' });
    const provider = providerUtils.standardizeOrThrow(window.ethereum);
    const order = new LimitOrder({ maker, chainId: parseInt(window.ethereum.chainId.slice(2), 16) });
    console.log(await order.getSignatureWithProviderAsync(provider, SignatureType.EIP712));
}

Confirm this works!

Removing ProviderEngine dependency and Subproviders solved the problem.
Thanks!

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

No branches or pull requests

2 participants