Commit 6cfd5fa4 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: allow signing from safepal (#5862)

parent f2c5a7c0
......@@ -15,13 +15,27 @@ JsonRpcSigner.prototype._signTypedData = async function signTypedDataWithFallbac
const address = await this.getAddress()
try {
return await this.provider.send('eth_signTypedData_v4', [
address.toLowerCase(),
JSON.stringify(_TypedDataEncoder.getPayload(populated.domain, types, populated.value)),
])
try {
// We must try the unversioned eth_signTypedData first, because some wallets (eg SafePal) will hang on _v4.
return await this.provider.send('eth_signTypedData', [
address.toLowerCase(),
JSON.stringify(_TypedDataEncoder.getPayload(populated.domain, types, populated.value)),
])
} catch (error) {
// MetaMask complains that the unversioned eth_signTypedData is formatted incorrectly (32602) - it prefers _v4.
if (error.code === -32602) {
console.warn('eth_signTypedData failed, falling back to eth_signTypedData_v4:', error)
return await this.provider.send('eth_signTypedData_v4', [
address.toLowerCase(),
JSON.stringify(_TypedDataEncoder.getPayload(populated.domain, types, populated.value)),
])
}
throw error
}
} catch (error) {
// If neither other method is available (eg Zerion), fallback to eth_sign.
if (typeof error.message === 'string' && error.message.match(/not found/i)) {
console.warn('eth_signTypedData_v4 failed, falling back to eth_sign:', error)
console.warn('eth_signTypedData_* failed, falling back to eth_sign:', error)
const hash = _TypedDataEncoder.hash(populated.domain, types, populated.value)
return await this.provider.send('eth_sign', [address, hash])
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment