@@ -27,18 +27,16 @@ public async static Task<string> GenerateSignature_TokenERC20(
2727 string privateKeyOverride = null
2828 )
2929 {
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 )
3933 {
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 :
4240 var walletConnectMintRequest = new ERC20MintRequestWalletConnect ( )
4341 {
4442 To = mintRequest . To ,
@@ -50,21 +48,12 @@ public async static Task<string> GenerateSignature_TokenERC20(
5048 ValidityEndTimestamp = mintRequest . ValidityEndTimestamp ,
5149 Uid = mintRequest . Uid . ByteArrayToHexString ( )
5250 } ;
53- var typedData = GetTypedDefinition_TokenERC20 ( domainName , version , chainId , verifyingContract ) ;
5451 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 :
5855 throw new UnityException ( "No account connected!" ) ;
59- }
6056 }
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);
6857 }
6958
7059 public partial class ERC20MintRequestWalletConnect : ERC20MintRequestBaseWalletConnect { }
@@ -105,18 +94,16 @@ public async static Task<string> GenerateSignature_TokenERC721(
10594 string privateKeyOverride = null
10695 )
10796 {
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 )
117100 {
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 :
120107 var walletConnectMintRequest = new ERC721MintRequestWalletConnect ( )
121108 {
122109 To = mintRequest . To ,
@@ -130,13 +117,11 @@ public async static Task<string> GenerateSignature_TokenERC721(
130117 ValidityEndTimestamp = mintRequest . ValidityEndTimestamp ,
131118 Uid = mintRequest . Uid . ByteArrayToHexString ( )
132119 } ;
133- var typedData = GetTypedDefinition_TokenERC721 ( domainName , version , chainId , verifyingContract ) ;
134120 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 :
138124 throw new UnityException ( "No account connected!" ) ;
139- }
140125 }
141126 }
142127
@@ -184,18 +169,16 @@ public async static Task<string> GenerateSignature_TokenERC1155(
184169 string privateKeyOverride = null
185170 )
186171 {
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 )
196175 {
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 :
199182 var walletConnectMintRequest = new ERC1155MintRequestWalletConnect ( )
200183 {
201184 To = mintRequest . To ,
@@ -211,13 +194,11 @@ public async static Task<string> GenerateSignature_TokenERC1155(
211194 ValidityEndTimestamp = mintRequest . ValidityEndTimestamp ,
212195 Uid = mintRequest . Uid . ByteArrayToHexString ( )
213196 } ;
214- var typedData = GetTypedDefinition_TokenERC1155 ( domainName , version , chainId , verifyingContract ) ;
215197 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 :
219201 throw new UnityException ( "No account connected!" ) ;
220- }
221202 }
222203 }
223204
@@ -323,25 +304,20 @@ public async static Task<string> GenerateSignature_MinimalForwarder(
323304 string privateKeyOverride = null
324305 )
325306 {
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 )
335310 {
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 :
339316 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 :
343320 throw new UnityException ( "No account connected!" ) ;
344- }
345321 }
346322 }
347323
0 commit comments