diff --git a/Thirdweb/Thirdweb.RPC/ThirdwebRPC.cs b/Thirdweb/Thirdweb.RPC/ThirdwebRPC.cs index 88884a7..c07d512 100644 --- a/Thirdweb/Thirdweb.RPC/ThirdwebRPC.cs +++ b/Thirdweb/Thirdweb.RPC/ThirdwebRPC.cs @@ -25,6 +25,7 @@ public class ThirdwebRPC : IDisposable private readonly object _responseLock = new(); private readonly object _cacheLock = new(); private readonly CancellationTokenSource _cancellationTokenSource = new(); + private readonly JsonSerializerSettings _jsonSerializerSettings = new() { NullValueHandling = NullValueHandling.Ignore, }; private int _requestIdCounter = 1; @@ -167,7 +168,7 @@ private ThirdwebRPC(ThirdwebClient client, BigInteger chainId) private async Task SendBatchAsync(List batch) { - var batchJson = JsonConvert.SerializeObject(batch); + var batchJson = JsonConvert.SerializeObject(batch, this._jsonSerializerSettings); var content = new StringContent(batchJson, Encoding.UTF8, "application/json"); try diff --git a/Thirdweb/Thirdweb.Wallets/EngineWallet/EngineWallet.cs b/Thirdweb/Thirdweb.Wallets/EngineWallet/EngineWallet.cs index 876fcd7..fc3eede 100644 --- a/Thirdweb/Thirdweb.Wallets/EngineWallet/EngineWallet.cs +++ b/Thirdweb/Thirdweb.Wallets/EngineWallet/EngineWallet.cs @@ -188,7 +188,7 @@ public Task EthSign(string message) throw new NotImplementedException(); } - public async Task PersonalSign(byte[] rawMessage) + public async Task PersonalSign(byte[] rawMessage, object originalMessage = null, BigInteger? chainId = null) { if (rawMessage == null) { @@ -207,7 +207,7 @@ public async Task PersonalSign(byte[] rawMessage) return JObject.Parse(content)["result"].Value(); } - public async Task PersonalSign(string message) + public async Task PersonalSign(string message, object originalMessage = null, BigInteger? chainId = null) { if (string.IsNullOrEmpty(message)) { diff --git a/Thirdweb/Thirdweb.Wallets/IThirdwebWallet.cs b/Thirdweb/Thirdweb.Wallets/IThirdwebWallet.cs index 78cfdd5..e06768b 100644 --- a/Thirdweb/Thirdweb.Wallets/IThirdwebWallet.cs +++ b/Thirdweb/Thirdweb.Wallets/IThirdwebWallet.cs @@ -56,15 +56,19 @@ public interface IThirdwebWallet /// Signs a raw message using personal signing. /// /// The raw message to sign. + /// Used for Ecosystem signing policies purposes only. + /// Used for Ecosystem signing policies purposes only. /// The signed message. - public Task PersonalSign(byte[] rawMessage); + public Task PersonalSign(byte[] rawMessage, object originalMessage = null, BigInteger? chainId = null); /// /// Signs a message using personal signing. /// /// The message to sign. + /// Used for Ecosystem signing polciies purposes only. + /// Used for Ecosystem signing polciies purposes only. /// The signed message. - public Task PersonalSign(string message); + public Task PersonalSign(string message, object originalMessage = null, BigInteger? chainId = null); /// /// Recovers the address from a signed message using personal signing. diff --git a/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs b/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs index 555c313..c071526 100644 --- a/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs +++ b/Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs @@ -48,6 +48,8 @@ public partial class EcosystemWallet : IThirdwebWallet private const string EMBEDDED_WALLET_PATH_V1 = $"{EMBEDDED_WALLET_BASE_PATH}/v1"; private const string ENCLAVE_PATH = $"{EMBEDDED_WALLET_PATH_V1}/enclave-wallet"; + private readonly JsonSerializerSettings _jsonSerializerSettings = new() { NullValueHandling = NullValueHandling.Ignore, }; + internal EcosystemWallet( string ecosystemId, string ecosystemPartnerId, @@ -1001,7 +1003,7 @@ public Task EthSign(string message) throw new NotImplementedException(); } - public async Task PersonalSign(byte[] rawMessage) + public async Task PersonalSign(byte[] rawMessage, object originalMessage = null, BigInteger? chainId = null) { if (rawMessage == null) { @@ -1009,9 +1011,18 @@ public async Task PersonalSign(byte[] rawMessage) } var url = $"{ENCLAVE_PATH}/sign-message"; - var payload = new { messagePayload = new { message = rawMessage.BytesToHex(), isRaw = true } }; + var payload = new + { + messagePayload = new + { + message = rawMessage.BytesToHex(), + isRaw = true, + originalMessage, + chainId + } + }; - var requestContent = new StringContent(JsonConvert.SerializeObject(payload), Encoding.UTF8, "application/json"); + var requestContent = new StringContent(JsonConvert.SerializeObject(payload, this._jsonSerializerSettings), Encoding.UTF8, "application/json"); var response = await this.HttpClient.PostAsync(url, requestContent).ConfigureAwait(false); _ = response.EnsureSuccessStatusCode(); @@ -1021,7 +1032,7 @@ public async Task PersonalSign(byte[] rawMessage) return res.Signature; } - public async Task PersonalSign(string message) + public async Task PersonalSign(string message, object originalMessage = null, BigInteger? chainId = null) { if (string.IsNullOrEmpty(message)) { @@ -1029,9 +1040,18 @@ public async Task PersonalSign(string message) } var url = $"{ENCLAVE_PATH}/sign-message"; - var payload = new { messagePayload = new { message, isRaw = false } }; + var payload = new + { + messagePayload = new + { + message, + isRaw = false, + originalMessage, + chainId + } + }; - var requestContent = new StringContent(JsonConvert.SerializeObject(payload), Encoding.UTF8, "application/json"); + var requestContent = new StringContent(JsonConvert.SerializeObject(payload, this._jsonSerializerSettings), Encoding.UTF8, "application/json"); var response = await this.HttpClient.PostAsync(url, requestContent).ConfigureAwait(false); _ = response.EnsureSuccessStatusCode(); diff --git a/Thirdweb/Thirdweb.Wallets/PrivateKeyWallet/PrivateKeyWallet.cs b/Thirdweb/Thirdweb.Wallets/PrivateKeyWallet/PrivateKeyWallet.cs index 1529d49..90f9ece 100644 --- a/Thirdweb/Thirdweb.Wallets/PrivateKeyWallet/PrivateKeyWallet.cs +++ b/Thirdweb/Thirdweb.Wallets/PrivateKeyWallet/PrivateKeyWallet.cs @@ -209,7 +209,7 @@ public virtual Task RecoverAddressFromEthSign(string message, string sig return Task.FromResult(address); } - public virtual Task PersonalSign(byte[] rawMessage) + public virtual Task PersonalSign(byte[] rawMessage, object originalMessage = null, BigInteger? chainId = null) { if (rawMessage == null) { @@ -221,7 +221,7 @@ public virtual Task PersonalSign(byte[] rawMessage) return Task.FromResult(signature); } - public virtual Task PersonalSign(string message) + public virtual Task PersonalSign(string message, object originalMessage = null, BigInteger? chainId = null) { if (string.IsNullOrEmpty(message)) { diff --git a/Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs b/Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs index 8f36b9b..478d23f 100644 --- a/Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs +++ b/Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs @@ -873,11 +873,12 @@ private async Task GetPaymasterAndData(object reques private async Task HashAndSignUserOp(UserOperationV6 userOp, ThirdwebContract entryPointContract) { + var hexified = EncodeUserOperation(userOp); var userOpHash = await ThirdwebContract.Read(entryPointContract, "getUserOpHash", userOp); var sig = this._personalAccount.AccountType == ThirdwebAccountType.ExternalAccount - ? await this._personalAccount.PersonalSign(userOpHash.BytesToHex()).ConfigureAwait(false) - : await this._personalAccount.PersonalSign(userOpHash).ConfigureAwait(false); + ? await this._personalAccount.PersonalSign(userOpHash.BytesToHex(), hexified, this.ActiveChainId).ConfigureAwait(false) + : await this._personalAccount.PersonalSign(userOpHash, hexified, this.ActiveChainId).ConfigureAwait(false); return sig.HexToBytes(); } @@ -945,10 +946,11 @@ private async Task HashAndSignUserOp(UserOperationV7 userOp, ThirdwebCon var userOpHash = await ThirdwebContract.Read(entryPointContract, "getUserOpHash", packedOp).ConfigureAwait(false); + var hexified = EncodeUserOperation(userOp); var sig = this._personalAccount.AccountType == ThirdwebAccountType.ExternalAccount - ? await this._personalAccount.PersonalSign(userOpHash.BytesToHex()).ConfigureAwait(false) - : await this._personalAccount.PersonalSign(userOpHash).ConfigureAwait(false); + ? await this._personalAccount.PersonalSign(userOpHash.BytesToHex(), hexified, this.ActiveChainId).ConfigureAwait(false) + : await this._personalAccount.PersonalSign(userOpHash, hexified, this.ActiveChainId).ConfigureAwait(false); return sig.HexToBytes(); } @@ -1081,7 +1083,7 @@ public Task RecoverAddressFromEthSign(string message, string signature) throw new NotImplementedException(); } - public Task PersonalSign(byte[] rawMessage) + public Task PersonalSign(byte[] rawMessage, object originalMessage = null, BigInteger? chainId = null) { throw new NotImplementedException(); } @@ -1089,9 +1091,7 @@ public Task PersonalSign(byte[] rawMessage) /// /// Signs a message with the personal account. The message will be verified using EIPs 1271 and 6492 if applicable. /// - /// The message to sign. - /// The signature. - public async Task PersonalSign(string message) + public async Task PersonalSign(string message, object originalMessage = null, BigInteger? chainId = null) { if (await Utils.IsZkSync(this.Client, this.ActiveChainId).ConfigureAwait(false)) { diff --git a/Thirdweb/Thirdweb.Wallets/SmartWallet/Thirdweb.AccountAbstraction/AATypes.cs b/Thirdweb/Thirdweb.Wallets/SmartWallet/Thirdweb.AccountAbstraction/AATypes.cs index 2885553..fa13caf 100644 --- a/Thirdweb/Thirdweb.Wallets/SmartWallet/Thirdweb.AccountAbstraction/AATypes.cs +++ b/Thirdweb/Thirdweb.Wallets/SmartWallet/Thirdweb.AccountAbstraction/AATypes.cs @@ -119,6 +119,7 @@ public class PackedUserOperation public virtual byte[] Signature { get; set; } } +[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] public class UserOperationHexifiedV6 { [JsonProperty("sender")] @@ -155,6 +156,7 @@ public class UserOperationHexifiedV6 public string Signature { get; set; } } +[JsonObject(ItemNullValueHandling = NullValueHandling.Ignore)] public class UserOperationHexifiedV7 { [JsonProperty("sender")]