@@ -66,10 +66,18 @@ export const signPermission = async (
66
66
amount : amount ,
67
67
nonce : vaultNonce ,
68
68
}
69
- // sign permission
70
- // todo: add fallback if wallet does not support eip 712 rpc
71
- const signedPermission = await owner . _signTypedData ( domain , types , value )
72
- // return
69
+
70
+ // Try to sign with EIP-712
71
+ let signedPermission
72
+ try {
73
+ signedPermission = await owner . _signTypedData ( domain , types , value )
74
+ } catch ( error ) {
75
+ console . log ( 'EIP-712 signing failed, falling back to eth_sign:' , error )
76
+
77
+ // Fallback to eth_sign
78
+ const messageHash = ethers . utils . _TypedDataEncoder . hash ( domain , types , value )
79
+ signedPermission = await owner . provider . send ( 'eth_sign' , [ owner . address , messageHash ] )
80
+ }
73
81
74
82
const replaceV : any = [ ]
75
83
replaceV [ '00' ] = '1b'
@@ -114,9 +122,23 @@ export const signPermitEIP2612 = async (
114
122
nonce : nonce ,
115
123
deadline : deadline ,
116
124
}
117
- // sign permission
118
- // todo: add fallback if wallet does not support eip 712 rpc
119
- const signedPermission = await owner . _signTypedData ( domainSeparator , types , values )
125
+
126
+ // Try to sign with EIP-712
127
+ let signedPermission
128
+ try {
129
+ signedPermission = await owner . _signTypedData ( domainSeparator , types , values )
130
+ } catch ( error ) {
131
+ console . log ( 'EIP-712 signing failed, falling back to eth_sign:' , error )
132
+
133
+ // Fallback to eth_sign
134
+ const messageHash = ethers . utils . _TypedDataEncoder . hash (
135
+ { chainId : await token . provider . getNetwork ( ) . chainId , ...domainSeparator } ,
136
+ types ,
137
+ values ,
138
+ )
139
+ signedPermission = await owner . provider . send ( 'eth_sign' , [ owner . address , messageHash ] )
140
+ }
141
+
120
142
// split signature
121
143
const sig = splitSignature ( signedPermission )
122
144
// return
0 commit comments