protocol-utils: Signing with SignatureType.EIP712 throws error
Caveman07 opened this issue · 7 comments
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 |
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?
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.
Are you signing from a hardware wallet?
Are you signing from a hardware wallet?
No
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));
}
Just merged and published the fixes. Try updating your dependencies and let me know if they work for you.
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!