Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
6cfd5fa4
Unverified
Commit
6cfd5fa4
authored
Jan 19, 2023
by
Zach Pomerantz
Committed by
GitHub
Jan 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: allow signing from safepal (#5862)
parent
f2c5a7c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
5 deletions
+19
-5
signTypedData.ts
src/utils/signTypedData.ts
+19
-5
No files found.
src/utils/signTypedData.ts
View file @
6cfd5fa4
...
...
@@ -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
])
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment