Skip to content

Commit 108020e

Browse files
committed
EcosystemWallet SignAuthorization Implementation
1 parent 0dd7293 commit 108020e

File tree

1 file changed

+65
-3
lines changed

1 file changed

+65
-3
lines changed

Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs

+65-3
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,38 @@ public async Task<string> SignTransaction(ThirdwebTransactionInput transaction)
10341034
throw new ArgumentException("GasPrice or MaxFeePerGas and MaxPriorityFeePerGas are required for transaction signing.");
10351035
}
10361036

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+
};
10381069

10391070
var url = $"{ENCLAVE_PATH}/sign-transaction";
10401071

@@ -1114,9 +1145,40 @@ public virtual Task<string> RecoverAddressFromTypedDataV4<T, TDomain>(T data, Ty
11141145
return Task.FromResult(address);
11151146
}
11161147

1117-
public Task<EIP7702Authorization> SignAuthorization(BigInteger chainId, string contractAddress, bool willSelfExecute)
1148+
public async Task<EIP7702Authorization> SignAuthorization(BigInteger chainId, string contractAddress, bool willSelfExecute)
11181149
{
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+
);
11201182
}
11211183

11221184
public Task SwitchNetwork(BigInteger chainId)

0 commit comments

Comments
 (0)