@@ -27,18 +27,16 @@ public async static Task<string> GenerateSignature_TokenERC20(
27
27
string privateKeyOverride = null
28
28
)
29
29
{
30
- if ( privateKeyOverride != null || ThirdwebManager . Instance . SDK . nativeSession . account != null )
31
- {
32
- var signer = new Eip712TypedDataSigner ( ) ;
33
- var key = new EthECKey ( privateKeyOverride ?? ThirdwebManager . Instance . SDK . nativeSession . account . PrivateKey ) ;
34
- var typedData = GetTypedDefinition_TokenERC20 ( domainName , version , chainId , verifyingContract ) ;
35
- var signature = signer . SignTypedDataV4 ( mintRequest , typedData , key ) ;
36
- return signature ;
37
- }
38
- else
30
+ var typedData = GetTypedDefinition_TokenERC20 ( domainName , version , chainId , verifyingContract ) ;
31
+
32
+ switch ( ThirdwebManager . Instance . SDK . nativeSession . provider )
39
33
{
40
- if ( Utils . ActiveWalletConnectSession ( ) )
41
- {
34
+ case WalletProvider . LocalWallet :
35
+ var signer = new Eip712TypedDataSigner ( ) ;
36
+ var key = new EthECKey ( privateKeyOverride ?? ThirdwebManager . Instance . SDK . nativeSession . account . PrivateKey ) ;
37
+ var signature = signer . SignTypedDataV4 ( mintRequest , typedData , key ) ;
38
+ return signature ;
39
+ case WalletProvider . WalletConnectV1 :
42
40
var walletConnectMintRequest = new ERC20MintRequestWalletConnect ( )
43
41
{
44
42
To = mintRequest . To ,
@@ -50,21 +48,12 @@ public async static Task<string> GenerateSignature_TokenERC20(
50
48
ValidityEndTimestamp = mintRequest . ValidityEndTimestamp ,
51
49
Uid = mintRequest . Uid . ByteArrayToHexString ( )
52
50
} ;
53
- var typedData = GetTypedDefinition_TokenERC20 ( domainName , version , chainId , verifyingContract ) ;
54
51
return await WalletConnect . Instance . Session . EthSignTypedData ( await ThirdwebManager . Instance . SDK . wallet . GetAddress ( ) , walletConnectMintRequest , typedData ) ;
55
- }
56
- else
57
- {
52
+ case WalletProvider . MagicLink :
53
+ throw new UnityException ( "Magic Auth does not support EIP712 signing" ) ;
54
+ default :
58
55
throw new UnityException ( "No account connected!" ) ;
59
- }
60
56
}
61
-
62
- // Debug.Log("Typed Data JSON: " + typedData.ToJson(mintRequest));
63
- // Debug.Log("Signing address: " + key.GetPublicAddress());
64
- // Debug.Log("Signature: " + signature);
65
-
66
- // var addressRecovered = signer.RecoverFromSignatureV4(mintRequest, typedData, signature);
67
- // Debug.Log("Recovered address from signature:" + addressRecovered);
68
57
}
69
58
70
59
public partial class ERC20MintRequestWalletConnect : ERC20MintRequestBaseWalletConnect { }
@@ -105,18 +94,16 @@ public async static Task<string> GenerateSignature_TokenERC721(
105
94
string privateKeyOverride = null
106
95
)
107
96
{
108
- if ( privateKeyOverride != null || ThirdwebManager . Instance . SDK . nativeSession . account != null )
109
- {
110
- var signer = new Eip712TypedDataSigner ( ) ;
111
- var key = new EthECKey ( privateKeyOverride ?? ThirdwebManager . Instance . SDK . nativeSession . account . PrivateKey ) ;
112
- var typedData = GetTypedDefinition_TokenERC721 ( domainName , version , chainId , verifyingContract ) ;
113
- var signature = signer . SignTypedDataV4 ( mintRequest , typedData , key ) ;
114
- return signature ;
115
- }
116
- else
97
+ var typedData = GetTypedDefinition_TokenERC721 ( domainName , version , chainId , verifyingContract ) ;
98
+
99
+ switch ( ThirdwebManager . Instance . SDK . nativeSession . provider )
117
100
{
118
- if ( Utils . ActiveWalletConnectSession ( ) )
119
- {
101
+ case WalletProvider . LocalWallet :
102
+ var signer = new Eip712TypedDataSigner ( ) ;
103
+ var key = new EthECKey ( privateKeyOverride ?? ThirdwebManager . Instance . SDK . nativeSession . account . PrivateKey ) ;
104
+ var signature = signer . SignTypedDataV4 ( mintRequest , typedData , key ) ;
105
+ return signature ;
106
+ case WalletProvider . WalletConnectV1 :
120
107
var walletConnectMintRequest = new ERC721MintRequestWalletConnect ( )
121
108
{
122
109
To = mintRequest . To ,
@@ -130,13 +117,11 @@ public async static Task<string> GenerateSignature_TokenERC721(
130
117
ValidityEndTimestamp = mintRequest . ValidityEndTimestamp ,
131
118
Uid = mintRequest . Uid . ByteArrayToHexString ( )
132
119
} ;
133
- var typedData = GetTypedDefinition_TokenERC721 ( domainName , version , chainId , verifyingContract ) ;
134
120
return await WalletConnect . Instance . Session . EthSignTypedData ( await ThirdwebManager . Instance . SDK . wallet . GetAddress ( ) , walletConnectMintRequest , typedData ) ;
135
- }
136
- else
137
- {
121
+ case WalletProvider . MagicLink :
122
+ throw new UnityException ( "Magic Auth does not support EIP712 signing" ) ;
123
+ default :
138
124
throw new UnityException ( "No account connected!" ) ;
139
- }
140
125
}
141
126
}
142
127
@@ -184,18 +169,16 @@ public async static Task<string> GenerateSignature_TokenERC1155(
184
169
string privateKeyOverride = null
185
170
)
186
171
{
187
- if ( privateKeyOverride != null || ThirdwebManager . Instance . SDK . nativeSession . account != null )
188
- {
189
- var signer = new Eip712TypedDataSigner ( ) ;
190
- var key = new EthECKey ( privateKeyOverride ?? ThirdwebManager . Instance . SDK . nativeSession . account . PrivateKey ) ;
191
- var typedData = GetTypedDefinition_TokenERC1155 ( domainName , version , chainId , verifyingContract ) ;
192
- var signature = signer . SignTypedDataV4 ( mintRequest , typedData , key ) ;
193
- return signature ;
194
- }
195
- else
172
+ var typedData = GetTypedDefinition_TokenERC1155 ( domainName , version , chainId , verifyingContract ) ;
173
+
174
+ switch ( ThirdwebManager . Instance . SDK . nativeSession . provider )
196
175
{
197
- if ( Utils . ActiveWalletConnectSession ( ) )
198
- {
176
+ case WalletProvider . LocalWallet :
177
+ var signer = new Eip712TypedDataSigner ( ) ;
178
+ var key = new EthECKey ( privateKeyOverride ?? ThirdwebManager . Instance . SDK . nativeSession . account . PrivateKey ) ;
179
+ var signature = signer . SignTypedDataV4 ( mintRequest , typedData , key ) ;
180
+ return signature ;
181
+ case WalletProvider . WalletConnectV1 :
199
182
var walletConnectMintRequest = new ERC1155MintRequestWalletConnect ( )
200
183
{
201
184
To = mintRequest . To ,
@@ -211,13 +194,11 @@ public async static Task<string> GenerateSignature_TokenERC1155(
211
194
ValidityEndTimestamp = mintRequest . ValidityEndTimestamp ,
212
195
Uid = mintRequest . Uid . ByteArrayToHexString ( )
213
196
} ;
214
- var typedData = GetTypedDefinition_TokenERC1155 ( domainName , version , chainId , verifyingContract ) ;
215
197
return await WalletConnect . Instance . Session . EthSignTypedData ( await ThirdwebManager . Instance . SDK . wallet . GetAddress ( ) , walletConnectMintRequest , typedData ) ;
216
- }
217
- else
218
- {
198
+ case WalletProvider . MagicLink :
199
+ throw new UnityException ( "Magic Auth does not support EIP712 signing" ) ;
200
+ default :
219
201
throw new UnityException ( "No account connected!" ) ;
220
- }
221
202
}
222
203
}
223
204
@@ -323,25 +304,20 @@ public async static Task<string> GenerateSignature_MinimalForwarder(
323
304
string privateKeyOverride = null
324
305
)
325
306
{
326
- if ( privateKeyOverride != null || ThirdwebManager . Instance . SDK . nativeSession . account != null )
327
- {
328
- var signer = new Eip712TypedDataSigner ( ) ;
329
- var key = new EthECKey ( privateKeyOverride ?? ThirdwebManager . Instance . SDK . nativeSession . account . PrivateKey ) ;
330
- var typedData = GetTypedDefinition_MinimalForwarder ( domainName , version , chainId , verifyingContract ) ;
331
- var signature = signer . SignTypedDataV4 ( forwardRequest , typedData , key ) ;
332
- return signature ;
333
- }
334
- else
307
+ var typedData = GetTypedDefinition_MinimalForwarder ( domainName , version , chainId , verifyingContract ) ;
308
+
309
+ switch ( ThirdwebManager . Instance . SDK . nativeSession . provider )
335
310
{
336
- if ( Utils . ActiveWalletConnectSession ( ) )
337
- {
338
- var typedData = GetTypedDefinition_MinimalForwarder ( domainName , version , chainId , verifyingContract ) ;
311
+ case WalletProvider . LocalWallet :
312
+ var signer = new Eip712TypedDataSigner ( ) ;
313
+ var key = new EthECKey ( privateKeyOverride ?? ThirdwebManager . Instance . SDK . nativeSession . account . PrivateKey ) ;
314
+ return signer . SignTypedDataV4 ( forwardRequest , typedData , key ) ;
315
+ case WalletProvider . WalletConnectV1 :
339
316
return await WalletConnect . Instance . Session . EthSignTypedData ( await ThirdwebManager . Instance . SDK . wallet . GetAddress ( ) , forwardRequest , typedData ) ;
340
- }
341
- else
342
- {
317
+ case WalletProvider . MagicLink :
318
+ throw new UnityException ( "Magic Auth does not support EIP712 signing" ) ;
319
+ default :
343
320
throw new UnityException ( "No account connected!" ) ;
344
- }
345
321
}
346
322
}
347
323
0 commit comments