11
11
using WalletConnectSharp . Unity ;
12
12
using WalletConnectSharp . NEthereum ;
13
13
using MinimalForwarder = Thirdweb . Contracts . Forwarder . ContractDefinition ;
14
+ using MetaMask . Unity ;
14
15
15
16
namespace Thirdweb
16
17
{
17
18
public static class EIP712
18
19
{
19
20
/// SIGNATURE GENERATION ///
20
21
21
- public async static Task < string > GenerateSignature_TokenERC20 (
22
+ public async static Task < string > GenerateSignature_MinimalForwarder (
22
23
string domainName ,
23
24
string version ,
24
25
BigInteger chainId ,
25
26
string verifyingContract ,
26
- TokenERC20Contract . MintRequest mintRequest ,
27
+ MinimalForwarder . ForwardRequest forwardRequest ,
27
28
string privateKeyOverride = null
28
29
)
29
30
{
30
- var typedData = GetTypedDefinition_TokenERC20 ( domainName , version , chainId , verifyingContract ) ;
31
+ var typedData = GetTypedDefinition_MinimalForwarder ( domainName , version , chainId , verifyingContract ) ;
31
32
32
- switch ( ThirdwebManager . Instance . SDK . nativeSession . provider )
33
+ if ( privateKeyOverride != null )
34
+ {
35
+ var signer = new Eip712TypedDataSigner ( ) ;
36
+ var key = new EthECKey ( privateKeyOverride ) ;
37
+ var signature = signer . SignTypedDataV4 ( forwardRequest , typedData , key ) ;
38
+ return signature ;
39
+ }
40
+ else
33
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 :
40
- var walletConnectMintRequest = new ERC20MintRequestWalletConnect ( )
41
- {
42
- To = mintRequest . To ,
43
- PrimarySaleRecipient = mintRequest . PrimarySaleRecipient ,
44
- Quantity = mintRequest . Quantity ,
45
- Price = mintRequest . Price ,
46
- Currency = mintRequest . Currency ,
47
- ValidityStartTimestamp = mintRequest . ValidityStartTimestamp ,
48
- ValidityEndTimestamp = mintRequest . ValidityEndTimestamp ,
49
- Uid = mintRequest . Uid . ByteArrayToHexString ( )
50
- } ;
51
- return await WalletConnect . Instance . Session . EthSignTypedData ( await ThirdwebManager . Instance . SDK . wallet . GetAddress ( ) , walletConnectMintRequest , typedData ) ;
52
- case WalletProvider . MagicLink :
53
- throw new UnityException ( "Magic Auth does not support EIP712 signing" ) ;
54
- default :
55
- throw new UnityException ( "No account connected!" ) ;
42
+ return await ThirdwebManager . Instance . SDK . wallet . SignTypedDataV4 ( forwardRequest , typedData ) ;
56
43
}
57
44
}
58
45
59
- public partial class ERC20MintRequestWalletConnect : ERC20MintRequestBaseWalletConnect { }
60
-
61
- public class ERC20MintRequestBaseWalletConnect
46
+ public async static Task < string > GenerateSignature_TokenERC20 (
47
+ string domainName ,
48
+ string version ,
49
+ BigInteger chainId ,
50
+ string verifyingContract ,
51
+ TokenERC20Contract . MintRequest mintRequest ,
52
+ string privateKeyOverride = null
53
+ )
62
54
{
63
- [ Parameter ( "address" , "to" , 1 ) ]
64
- public virtual string To { get ; set ; }
65
-
66
- [ Parameter ( "address" , "primarySaleRecipient" , 2 ) ]
67
- public virtual string PrimarySaleRecipient { get ; set ; }
68
-
69
- [ Parameter ( "uint256" , "quantity" , 3 ) ]
70
- public virtual BigInteger Quantity { get ; set ; }
71
-
72
- [ Parameter ( "uint256" , "price" , 4 ) ]
73
- public virtual BigInteger Price { get ; set ; }
74
-
75
- [ Parameter ( "address" , "currency" , 5 ) ]
76
- public virtual string Currency { get ; set ; }
77
-
78
- [ Parameter ( "uint128" , "validityStartTimestamp" , 6 ) ]
79
- public virtual BigInteger ValidityStartTimestamp { get ; set ; }
80
-
81
- [ Parameter ( "uint128" , "validityEndTimestamp" , 7 ) ]
82
- public virtual BigInteger ValidityEndTimestamp { get ; set ; }
55
+ var typedData = GetTypedDefinition_TokenERC20 ( domainName , version , chainId , verifyingContract ) ;
83
56
84
- [ Parameter ( "bytes32" , "uid" , 8 ) ]
85
- public virtual string Uid { get ; set ; }
57
+ if ( privateKeyOverride != null )
58
+ {
59
+ var signer = new Eip712TypedDataSigner ( ) ;
60
+ var key = new EthECKey ( privateKeyOverride ) ;
61
+ var signature = signer . SignTypedDataV4 ( mintRequest , typedData , key ) ;
62
+ return signature ;
63
+ }
64
+ else
65
+ {
66
+ return await ThirdwebManager . Instance . SDK . wallet . SignTypedDataV4 ( mintRequest , typedData ) ;
67
+ }
86
68
}
87
69
88
70
public async static Task < string > GenerateSignature_TokenERC721 (
@@ -96,68 +78,17 @@ public async static Task<string> GenerateSignature_TokenERC721(
96
78
{
97
79
var typedData = GetTypedDefinition_TokenERC721 ( domainName , version , chainId , verifyingContract ) ;
98
80
99
- switch ( ThirdwebManager . Instance . SDK . nativeSession . provider )
81
+ if ( privateKeyOverride != null )
100
82
{
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 :
107
- var walletConnectMintRequest = new ERC721MintRequestWalletConnect ( )
108
- {
109
- To = mintRequest . To ,
110
- RoyaltyRecipient = mintRequest . RoyaltyRecipient ,
111
- RoyaltyBps = mintRequest . RoyaltyBps ,
112
- PrimarySaleRecipient = mintRequest . PrimarySaleRecipient ,
113
- Uri = mintRequest . Uri ,
114
- Price = mintRequest . Price ,
115
- Currency = mintRequest . Currency ,
116
- ValidityStartTimestamp = mintRequest . ValidityStartTimestamp ,
117
- ValidityEndTimestamp = mintRequest . ValidityEndTimestamp ,
118
- Uid = mintRequest . Uid . ByteArrayToHexString ( )
119
- } ;
120
- return await WalletConnect . Instance . Session . EthSignTypedData ( await ThirdwebManager . Instance . SDK . wallet . GetAddress ( ) , walletConnectMintRequest , typedData ) ;
121
- case WalletProvider . MagicLink :
122
- throw new UnityException ( "Magic Auth does not support EIP712 signing" ) ;
123
- default :
124
- throw new UnityException ( "No account connected!" ) ;
83
+ var signer = new Eip712TypedDataSigner ( ) ;
84
+ var key = new EthECKey ( privateKeyOverride ) ;
85
+ var signature = signer . SignTypedDataV4 ( mintRequest , typedData , key ) ;
86
+ return signature ;
87
+ }
88
+ else
89
+ {
90
+ return await ThirdwebManager . Instance . SDK . wallet . SignTypedDataV4 ( mintRequest , typedData ) ;
125
91
}
126
- }
127
-
128
- public partial class ERC721MintRequestWalletConnect : ERC721MintRequestBaseWalletConnect { }
129
-
130
- public class ERC721MintRequestBaseWalletConnect
131
- {
132
- [ Parameter ( "address" , "to" , 1 ) ]
133
- public virtual string To { get ; set ; }
134
-
135
- [ Parameter ( "address" , "royaltyRecipient" , 2 ) ]
136
- public virtual string RoyaltyRecipient { get ; set ; }
137
-
138
- [ Parameter ( "uint256" , "royaltyBps" , 3 ) ]
139
- public virtual BigInteger RoyaltyBps { get ; set ; }
140
-
141
- [ Parameter ( "address" , "primarySaleRecipient" , 4 ) ]
142
- public virtual string PrimarySaleRecipient { get ; set ; }
143
-
144
- [ Parameter ( "string" , "uri" , 5 ) ]
145
- public virtual string Uri { get ; set ; }
146
-
147
- [ Parameter ( "uint256" , "price" , 6 ) ]
148
- public virtual BigInteger Price { get ; set ; }
149
-
150
- [ Parameter ( "address" , "currency" , 7 ) ]
151
- public virtual string Currency { get ; set ; }
152
-
153
- [ Parameter ( "uint128" , "validityStartTimestamp" , 8 ) ]
154
- public virtual BigInteger ValidityStartTimestamp { get ; set ; }
155
-
156
- [ Parameter ( "uint128" , "validityEndTimestamp" , 9 ) ]
157
- public virtual BigInteger ValidityEndTimestamp { get ; set ; }
158
-
159
- [ Parameter ( "bytes32" , "uid" , 10 ) ]
160
- public virtual string Uid { get ; set ; }
161
92
}
162
93
163
94
public async static Task < string > GenerateSignature_TokenERC1155 (
@@ -171,79 +102,20 @@ public async static Task<string> GenerateSignature_TokenERC1155(
171
102
{
172
103
var typedData = GetTypedDefinition_TokenERC1155 ( domainName , version , chainId , verifyingContract ) ;
173
104
174
- switch ( ThirdwebManager . Instance . SDK . nativeSession . provider )
105
+ if ( privateKeyOverride != null )
175
106
{
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 :
182
- var walletConnectMintRequest = new ERC1155MintRequestWalletConnect ( )
183
- {
184
- To = mintRequest . To ,
185
- RoyaltyRecipient = mintRequest . RoyaltyRecipient ,
186
- RoyaltyBps = mintRequest . RoyaltyBps ,
187
- PrimarySaleRecipient = mintRequest . PrimarySaleRecipient ,
188
- TokenId = mintRequest . TokenId ,
189
- Uri = mintRequest . Uri ,
190
- Quantity = mintRequest . Quantity ,
191
- PricePerToken = mintRequest . PricePerToken ,
192
- Currency = mintRequest . Currency ,
193
- ValidityStartTimestamp = mintRequest . ValidityStartTimestamp ,
194
- ValidityEndTimestamp = mintRequest . ValidityEndTimestamp ,
195
- Uid = mintRequest . Uid . ByteArrayToHexString ( )
196
- } ;
197
- return await WalletConnect . Instance . Session . EthSignTypedData ( await ThirdwebManager . Instance . SDK . wallet . GetAddress ( ) , walletConnectMintRequest , typedData ) ;
198
- case WalletProvider . MagicLink :
199
- throw new UnityException ( "Magic Auth does not support EIP712 signing" ) ;
200
- default :
201
- throw new UnityException ( "No account connected!" ) ;
107
+ var signer = new Eip712TypedDataSigner ( ) ;
108
+ var key = new EthECKey ( privateKeyOverride ) ;
109
+ var signature = signer . SignTypedDataV4 ( mintRequest , typedData , key ) ;
110
+ return signature ;
111
+ }
112
+ else
113
+ {
114
+ return await ThirdwebManager . Instance . SDK . wallet . SignTypedDataV4 ( mintRequest , typedData ) ;
202
115
}
203
116
}
204
117
205
- public partial class ERC1155MintRequestWalletConnect : ERC1155MintRequestBaseWalletConnect { }
206
-
207
- public class ERC1155MintRequestBaseWalletConnect
208
- {
209
- [ Parameter ( "address" , "to" , 1 ) ]
210
- public virtual string To { get ; set ; }
211
-
212
- [ Parameter ( "address" , "royaltyRecipient" , 2 ) ]
213
- public virtual string RoyaltyRecipient { get ; set ; }
214
-
215
- [ Parameter ( "uint256" , "royaltyBps" , 3 ) ]
216
- public virtual BigInteger RoyaltyBps { get ; set ; }
217
-
218
- [ Parameter ( "address" , "primarySaleRecipient" , 4 ) ]
219
- public virtual string PrimarySaleRecipient { get ; set ; }
220
-
221
- [ Parameter ( "uint256" , "tokenId" , 5 ) ]
222
- public virtual BigInteger TokenId { get ; set ; }
223
-
224
- [ Parameter ( "string" , "uri" , 6 ) ]
225
- public virtual string Uri { get ; set ; }
226
-
227
- [ Parameter ( "uint256" , "quantity" , 7 ) ]
228
- public virtual BigInteger Quantity { get ; set ; }
229
-
230
- [ Parameter ( "uint256" , "pricePerToken" , 8 ) ]
231
- public virtual BigInteger PricePerToken { get ; set ; }
232
-
233
- [ Parameter ( "address" , "currency" , 9 ) ]
234
- public virtual string Currency { get ; set ; }
235
-
236
- [ Parameter ( "uint128" , "validityStartTimestamp" , 10 ) ]
237
- public virtual BigInteger ValidityStartTimestamp { get ; set ; }
238
-
239
- [ Parameter ( "uint128" , "validityEndTimestamp" , 11 ) ]
240
- public virtual BigInteger ValidityEndTimestamp { get ; set ; }
241
-
242
- [ Parameter ( "bytes32" , "uid" , 12 ) ]
243
- public virtual string Uid { get ; set ; }
244
- }
245
-
246
- /// DOMAIN TYPES ///
118
+ #region Typed Data Definitions
247
119
248
120
public static TypedData < Domain > GetTypedDefinition_TokenERC20 ( string domainName , string version , BigInteger chainId , string verifyingContract )
249
121
{
@@ -293,34 +165,6 @@ public static TypedData<Domain> GetTypedDefinition_TokenERC1155(string domainNam
293
165
} ;
294
166
}
295
167
296
- /// MINIMAL FORWARDER ///
297
-
298
- public async static Task < string > GenerateSignature_MinimalForwarder (
299
- string domainName ,
300
- string version ,
301
- BigInteger chainId ,
302
- string verifyingContract ,
303
- MinimalForwarder . ForwardRequest forwardRequest ,
304
- string privateKeyOverride = null
305
- )
306
- {
307
- var typedData = GetTypedDefinition_MinimalForwarder ( domainName , version , chainId , verifyingContract ) ;
308
-
309
- switch ( ThirdwebManager . Instance . SDK . nativeSession . provider )
310
- {
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 :
316
- return await WalletConnect . Instance . Session . EthSignTypedData ( await ThirdwebManager . Instance . SDK . wallet . GetAddress ( ) , forwardRequest , typedData ) ;
317
- case WalletProvider . MagicLink :
318
- throw new UnityException ( "Magic Auth does not support EIP712 signing" ) ;
319
- default :
320
- throw new UnityException ( "No account connected!" ) ;
321
- }
322
- }
323
-
324
168
public static TypedData < Domain > GetTypedDefinition_MinimalForwarder ( string domainName , string version , BigInteger chainId , string verifyingContract )
325
169
{
326
170
return new TypedData < Domain >
@@ -336,5 +180,7 @@ public static TypedData<Domain> GetTypedDefinition_MinimalForwarder(string domai
336
180
PrimaryType = nameof ( MinimalForwarder . ForwardRequest ) ,
337
181
} ;
338
182
}
183
+
184
+ #endregion
339
185
}
340
186
}
0 commit comments