@@ -1034,7 +1034,38 @@ public async Task<string> SignTransaction(ThirdwebTransactionInput transaction)
1034
1034
throw new ArgumentException ( "GasPrice or MaxFeePerGas and MaxPriorityFeePerGas are required for transaction signing." ) ;
1035
1035
}
1036
1036
1037
- object payload = new { transactionPayload = transaction } ;
1037
+ object payload = new
1038
+ {
1039
+ transactionPayload = new
1040
+ {
1041
+ nonce = transaction . Nonce ,
1042
+ from = transaction . From ,
1043
+ to = transaction . To ,
1044
+ gas = transaction . Gas ,
1045
+ gasPrice = transaction . GasPrice ,
1046
+ value = transaction . Value ,
1047
+ data = transaction . Data ,
1048
+ maxFeePerGas = transaction . MaxFeePerGas ,
1049
+ maxPriorityFeePerGas = transaction . MaxPriorityFeePerGas ,
1050
+ chainId = transaction . ChainId ,
1051
+ authorizationList = transaction . AuthorizationList != null && transaction . AuthorizationList . Count > 0
1052
+ ? transaction . AuthorizationList
1053
+ . Select (
1054
+ authorization =>
1055
+ new
1056
+ {
1057
+ chainId = authorization . ChainId . HexToNumber ( ) ,
1058
+ address = authorization . Address ,
1059
+ nonce = authorization . Nonce . HexToNumber ( ) . ToString ( ) ,
1060
+ yParity = authorization . YParity . HexToNumber ( ) ,
1061
+ r = authorization . R . HexToNumber ( ) . ToString ( ) ,
1062
+ s = authorization . S . HexToNumber ( ) . ToString ( )
1063
+ }
1064
+ )
1065
+ . ToArray ( )
1066
+ : null
1067
+ }
1068
+ } ;
1038
1069
1039
1070
var url = $ "{ ENCLAVE_PATH } /sign-transaction";
1040
1071
@@ -1114,9 +1145,40 @@ public virtual Task<string> RecoverAddressFromTypedDataV4<T, TDomain>(T data, Ty
1114
1145
return Task . FromResult ( address ) ;
1115
1146
}
1116
1147
1117
- public Task < EIP7702Authorization > SignAuthorization ( BigInteger chainId , string contractAddress , bool willSelfExecute )
1148
+ public async Task < EIP7702Authorization > SignAuthorization ( BigInteger chainId , string contractAddress , bool willSelfExecute )
1118
1149
{
1119
- throw new NotImplementedException ( ) ;
1150
+ var nonce = await this . GetTransactionCount ( chainId ) ;
1151
+
1152
+ if ( willSelfExecute )
1153
+ {
1154
+ nonce ++ ;
1155
+ }
1156
+
1157
+ var url = $ "{ ENCLAVE_PATH } /sign-authorization";
1158
+
1159
+ var payload = new
1160
+ {
1161
+ address = contractAddress ,
1162
+ chainId ,
1163
+ nonce
1164
+ } ;
1165
+
1166
+ var requestContent = new StringContent ( JsonConvert . SerializeObject ( payload ) , Encoding . UTF8 , "application/json" ) ;
1167
+
1168
+ var response = await this . HttpClient . PostAsync ( url , requestContent ) . ConfigureAwait ( false ) ;
1169
+ _ = response . EnsureSuccessStatusCode ( ) ;
1170
+
1171
+ var content = await response . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
1172
+ var signResponseObj = JObject . Parse ( content ) ;
1173
+
1174
+ return new EIP7702Authorization (
1175
+ chainId : BigInteger . Parse ( signResponseObj [ "chainId" ] . ToString ( ) ) ,
1176
+ address : signResponseObj [ "address" ] . ToString ( ) ,
1177
+ nonce : BigInteger . Parse ( signResponseObj [ "nonce" ] . ToString ( ) ) ,
1178
+ yParity : BigInteger . Parse ( signResponseObj [ "yParity" ] . ToString ( ) ) . NumberToHex ( ) . HexToBytes ( ) ,
1179
+ r : BigInteger . Parse ( signResponseObj [ "r" ] . ToString ( ) ) . NumberToHex ( ) . HexToBytes ( ) ,
1180
+ s : BigInteger . Parse ( signResponseObj [ "s" ] . ToString ( ) ) . NumberToHex ( ) . HexToBytes ( )
1181
+ ) ;
1120
1182
}
1121
1183
1122
1184
public Task SwitchNetwork ( BigInteger chainId )
0 commit comments