Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions ChainSafe.Gaming.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chainsafe.Gaming.Chainlink"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.Debugging", "src\ChainSafe.Gaming.Debugging\ChainSafe.Gaming.Debugging.csproj", "{88B2E2F4-96BC-44B1-AE4D-5FBA6B4C399F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.MetaMask", "src\ChainSafe.Gaming.MetaMask\ChainSafe.Gaming.MetaMask.csproj", "{0631D9F5-2942-4ECE-A0B5-7C3AF54E87AA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.MetaMask.Unity", "src\ChainSafe.Gaming.MetaMask.Unity\ChainSafe.Gaming.MetaMask.Unity.csproj", "{AF45F008-6ABC-4F37-82BF-4814B7F15B30}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ChainSafe.Gaming.SygmaClient", "src\ChainSafe.Gaming.SygmaClient\ChainSafe.Gaming.SygmaClient.csproj", "{6D329479-C391-4BF9-B6FC-FFA3AD3A12D7}"
Expand Down Expand Up @@ -123,12 +121,6 @@ Global
{88B2E2F4-96BC-44B1-AE4D-5FBA6B4C399F}.Release|Any CPU.Build.0 = Release|Any CPU
{88B2E2F4-96BC-44B1-AE4D-5FBA6B4C399F}.Test|Any CPU.ActiveCfg = Debug|Any CPU
{88B2E2F4-96BC-44B1-AE4D-5FBA6B4C399F}.Test|Any CPU.Build.0 = Debug|Any CPU
{0631D9F5-2942-4ECE-A0B5-7C3AF54E87AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0631D9F5-2942-4ECE-A0B5-7C3AF54E87AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0631D9F5-2942-4ECE-A0B5-7C3AF54E87AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0631D9F5-2942-4ECE-A0B5-7C3AF54E87AA}.Release|Any CPU.Build.0 = Release|Any CPU
{0631D9F5-2942-4ECE-A0B5-7C3AF54E87AA}.Test|Any CPU.ActiveCfg = Debug|Any CPU
{0631D9F5-2942-4ECE-A0B5-7C3AF54E87AA}.Test|Any CPU.Build.0 = Debug|Any CPU
{AF45F008-6ABC-4F37-82BF-4814B7F15B30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF45F008-6ABC-4F37-82BF-4814B7F15B30}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF45F008-6ABC-4F37-82BF-4814B7F15B30}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace ChainSafe.Gaming.WalletConnect
[CreateAssetMenu(menuName = "ChainSafe/WalletConnect/WalletConnect Config", fileName = "WalletConnectConfig", order = 0)]
public class WalletConnectConfigSO : ScriptableObject, IWalletConnectConfig
{
public string SignMessageRpcMethodName => "personal_sign";
public string SignTypedMessageRpcMethodName => "eth_signTypedData";

[field: SerializeField] public bool AutoRenewSession { get; set; } = true;
[field: SerializeField] public string ProjectName { get; set; }
[field: SerializeField] public string ProjectId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ internal static ValueTask<Web3> BuildTestWeb3(Web3Builder.ConfigureServicesDeleg

services.AddSingleton(new StubWalletConnectProviderConfig()); // can be replaced
services.AddSingleton<IWalletProvider, StubWalletConnectProvider>();
services.UseWalletConnectSigner();
services.UseWalletConnectTransactionExecutor();
services.UseWalletSigner();
services.UseWalletTransactionExecutor();

// Add any contracts we would want to use
services.ConfigureRegisteredContracts(contracts =>
Expand Down
2 changes: 1 addition & 1 deletion scripts/data/published_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Packages/io.chainsafe.web3-unity/Runtime/Libraries/:ADRaffy.ENSNormalize;Nethereum.Model;BouncyCastle.Crypto;Nethereum.RLP;ChainSafe.Gaming.Debugging;Nethereum.RPC;ChainSafe.Gaming.Gelato;ChainSafe.Gaming.SygmaClient;Nethereum.Signer.EIP712;ChainSafe.Gaming.InProcessSigner;Nethereum.Signer;ChainSafe.Gaming.InProcessTransactionExecutor;Nethereum.Util;ChainSafe.Gaming.Unity.ThirdParty;Nethereum.Web3;ChainSafe.Gaming.Unity;System.Buffers;ChainSafe.Gaming.WalletConnect;System.Memory;ChainSafe.Gaming;System.Numerics.Vectors;Microsoft.Bcl.AsyncInterfaces;System.Reactive;Microsoft.Extensions.DependencyInjection.Abstractions;System.Runtime.CompilerServices.Unsafe;Microsoft.Extensions.DependencyInjection;System.Runtime.InteropServices.WindowsRuntime;Microsoft.Extensions.Logging.Abstractions;System.Security.Cryptography.Cng;Microsoft.IdentityModel.Abstractions;System.Text.Encodings.Web;Microsoft.IdentityModel.Logging;System.Text.Json;Microsoft.IdentityModel.Tokens;System.Threading.Channels;NBitcoin;System.Threading.Tasks.Extensions;Nethereum.ABI;WalletConnectSharp.Auth;Nethereum.Accounts;WalletConnectSharp.Common;WalletConnectSharp.Events;Nethereum.BlockchainProcessing;WalletConnectSharp.Core;Nethereum.Contracts;WalletConnectSharp.Crypto;Nethereum.Hex;Nethereum.JsonRpc.Client;WalletConnectSharp.Network.Websocket;Nethereum.JsonRpc.IpcClient;WalletConnectSharp.Network;Nethereum.JsonRpc.RpcClient;WalletConnectSharp.Sign;Nethereum.KeyStore;WalletConnectSharp.Storage;Nethereum.Merkle.Patricia;WalletConnectSharp.Web3Wallet;Nethereum.Merkle;Websocket.Client;Nethereum.Metamask;Nethereum.Siwe.Core;Nethereum.Siwe;Nethereum.UI;Nethereum.Unity.Metamask;Nethereum.Unity;ChainSafe.Gaming.MetaMask;ChainSafe.Gaming.MetaMask.Unity;ChainSafe.Gaming.Marketplace
Packages/io.chainsafe.web3-unity/Runtime/Libraries/:ADRaffy.ENSNormalize;Nethereum.Model;BouncyCastle.Crypto;Nethereum.RLP;ChainSafe.Gaming.Debugging;Nethereum.RPC;ChainSafe.Gaming.Gelato;ChainSafe.Gaming.SygmaClient;Nethereum.Signer.EIP712;ChainSafe.Gaming.InProcessSigner;Nethereum.Signer;ChainSafe.Gaming.InProcessTransactionExecutor;Nethereum.Util;ChainSafe.Gaming.Unity.ThirdParty;Nethereum.Web3;ChainSafe.Gaming.Unity;System.Buffers;ChainSafe.Gaming.WalletConnect;System.Memory;ChainSafe.Gaming;System.Numerics.Vectors;Microsoft.Bcl.AsyncInterfaces;System.Reactive;Microsoft.Extensions.DependencyInjection.Abstractions;System.Runtime.CompilerServices.Unsafe;Microsoft.Extensions.DependencyInjection;System.Runtime.InteropServices.WindowsRuntime;Microsoft.Extensions.Logging.Abstractions;System.Security.Cryptography.Cng;Microsoft.IdentityModel.Abstractions;System.Text.Encodings.Web;Microsoft.IdentityModel.Logging;System.Text.Json;Microsoft.IdentityModel.Tokens;System.Threading.Channels;NBitcoin;System.Threading.Tasks.Extensions;Nethereum.ABI;WalletConnectSharp.Auth;Nethereum.Accounts;WalletConnectSharp.Common;WalletConnectSharp.Events;Nethereum.BlockchainProcessing;WalletConnectSharp.Core;Nethereum.Contracts;WalletConnectSharp.Crypto;Nethereum.Hex;Nethereum.JsonRpc.Client;WalletConnectSharp.Network.Websocket;Nethereum.JsonRpc.IpcClient;WalletConnectSharp.Network;Nethereum.JsonRpc.RpcClient;WalletConnectSharp.Sign;Nethereum.KeyStore;WalletConnectSharp.Storage;Nethereum.Merkle.Patricia;WalletConnectSharp.Web3Wallet;Nethereum.Merkle;Websocket.Client;Nethereum.Metamask;Nethereum.Siwe.Core;Nethereum.Siwe;Nethereum.UI;Nethereum.Unity.Metamask;Nethereum.Unity;ChainSafe.Gaming.MetaMask.Unity;ChainSafe.Gaming.Marketplace
Packages/io.chainsafe.web3-unity.lootboxes/Chainlink/Runtime/Libraries/:Chainsafe.Gaming.Chainlink;ChainSafe.Gaming.Lootboxes.Chainlink
Packages/io.chainsafe.web3-unity.hyperplay/Runtime/Libraries/:ChainSafe.Gaming.HyperPlay
4 changes: 4 additions & 0 deletions src/ChainSafe.Gaming.HyperPlay/HyperPlayConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ namespace ChainSafe.Gaming.HyperPlay
/// </summary>
public class HyperPlayConfig : IHyperPlayConfig
{
public string SignMessageRpcMethodName => "personal_sign";

public string SignTypedMessageRpcMethodName => "eth_signTypedData_v3";

/// <summary>
/// Remember the HyperPlay session.
/// Like remember me for login.
Expand Down
34 changes: 4 additions & 30 deletions src/ChainSafe.Gaming.HyperPlay/HyperPlayExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,15 @@ public static class HyperPlayExtensions
/// <returns>The same service collection that was passed in. This enables fluent style.</returns>
public static IWeb3ServiceCollection UseHyperPlay(this IWeb3ServiceCollection collection, IHyperPlayConfig config)
{
collection.AssertServiceNotBound<IWalletProvider>();

collection.AddSingleton<IWalletProvider, HyperPlayProvider>();
collection.AssertServiceNotBound<IHyperPlayData>();

collection.AddSingleton<IHyperPlayData, IStorable, HyperPlayData>();

collection.Replace(ServiceDescriptor.Singleton(typeof(IHyperPlayConfig), config));

return collection;
}

/// <summary>
/// Binds implementation of <see cref="ISigner"/> as <see cref="HyperPlaySigner"/> to Web3 as a service.
/// </summary>
/// <param name="collection">Service collection to bind implementations to.</param>
/// <returns>The same service collection that was passed in. This enables fluent style.</returns>
public static IWeb3ServiceCollection UseHyperPlaySigner(this IWeb3ServiceCollection collection)
{
collection.AssertServiceNotBound<ISigner>();
collection.AssertServiceNotBound<IHyperPlayConfig>();

collection.AddSingleton<ILifecycleParticipant, ISigner, ILogoutHandler, HyperPlaySigner>();

return collection;
}

/// <summary>
/// Binds implementation of <see cref="ITransactionExecutor"/> as <see cref="HyperPlayTransactionExecutor"/> to Web3 as a service.
/// </summary>
/// <param name="collection">Service collection to bind implementations to.</param>
/// <returns>The same service collection that was passed in. This enables fluent style.</returns>
public static IWeb3ServiceCollection UseHyperPlayTransactionExecutor(this IWeb3ServiceCollection collection)
{
collection.AssertServiceNotBound<ITransactionExecutor>();
collection.Replace(ServiceDescriptor.Singleton(typeof(IHyperPlayConfig), config));

collection.AddSingleton<ITransactionExecutor, HyperPlayTransactionExecutor>();
collection.UseWalletProvider<HyperPlayProvider>(config);

return collection;
}
Expand Down
17 changes: 2 additions & 15 deletions src/ChainSafe.Gaming.HyperPlay/HyperPlayProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override async Task<string> Connect()
{
string[] accounts = await Perform<string[]>("eth_accounts");

string account = accounts[0].AssertIsPublicAddress(nameof(account));
string account = accounts[0];

// Saved account exists.
if (data.RememberSession && data.SavedAccount == account)
Expand All @@ -66,20 +66,7 @@ public override async Task<string> Connect()

string hash = await Perform<string>("personal_sign", message, account);

// Verify signature.
// TODO: Make into a Util Method.
EthECDSASignature signature = MessageSigner.ExtractEcdsaSignature(hash);

string messageToHash = "\x19" + "Ethereum Signed Message:\n" + message.Length + message;

byte[] messageHash = new Sha3Keccack().CalculateHash(Encoding.UTF8.GetBytes(messageToHash));

var key = EthECKey.RecoverFromSignature(signature, messageHash);

if (key.GetPublicAddress().ToLower().Trim() != account.ToLower().Trim())
{
throw new Web3Exception("Fetched address does not match the signing address.");
}
hash.AssertSignatureValid(message, account);

if (config.RememberSession)
{
Expand Down
67 changes: 0 additions & 67 deletions src/ChainSafe.Gaming.HyperPlay/HyperPlaySigner.cs

This file was deleted.

69 changes: 0 additions & 69 deletions src/ChainSafe.Gaming.HyperPlay/HyperPlayTransactionExecutor.cs

This file was deleted.

4 changes: 3 additions & 1 deletion src/ChainSafe.Gaming.HyperPlay/IHyperPlayConfig.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using ChainSafe.Gaming.Web3.Evm.Wallet;

namespace ChainSafe.Gaming.HyperPlay
{
/// <summary>
/// Config for a HyperPlay connection.
/// </summary>
public interface IHyperPlayConfig
public interface IHyperPlayConfig : IWalletProviderConfig
{
/// <summary>
/// Url for connecting to HyperPlay desktop client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../ChainSafe.Gaming.MetaMask/ChainSafe.Gaming.MetaMask.csproj" />
<ProjectReference Include="../ChainSafe.Gaming/ChainSafe.Gaming.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 14 additions & 0 deletions src/ChainSafe.Gaming.MetaMask.Unity/MetaMaskConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using ChainSafe.Gaming.Web3.Evm.Wallet;

namespace ChainSafe.Gaming.MetaMask.Unity
{
/// <summary>
/// Concrete implementation of <see cref="IWalletProviderConfig"/> for connecting to MetaMask wallet.
/// </summary>
public class MetaMaskConfig : IWalletProviderConfig
{
public string SignMessageRpcMethodName => "personal_sign";

public string SignTypedMessageRpcMethodName => "eth_signTypedData_v4";
}
}
14 changes: 4 additions & 10 deletions src/ChainSafe.Gaming.MetaMask.Unity/MetaMaskProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
namespace ChainSafe.Gaming.MetaMask.Unity
{
/// <summary>
/// Concrete implementation of <see cref="IMetaMaskProvider"/>.
/// Concrete implementation of <see cref="MetaMaskProvider"/>.
/// </summary>
public class MetaMaskProvider : WalletProvider, ILogoutHandler
public class MetaMaskProvider : WalletProvider
{
private readonly ILogWriter logWriter;

Expand Down Expand Up @@ -63,7 +63,8 @@ public MetaMaskProvider(ILogWriter logWriter, IAnalyticsClient analyticsClient,

public override Task Disconnect()
{
// Currently no disconnect logic for MetaMask lib on NEthereum.
Object.Destroy(metaMaskController.gameObject);

return Task.CompletedTask;
}

Expand All @@ -89,12 +90,5 @@ public override async Task<string> Connect()

return await metaMaskController.Connect();
}

public Task OnLogout()
{
Object.Destroy(metaMaskController.gameObject);

return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ public static class MetaMaskProviderExtensions
/// <returns>The same service collection that was passed in. This enables fluent style.</returns>
public static IWeb3ServiceCollection UseMetaMask(this IWeb3ServiceCollection collection)
{
collection.AssertServiceNotBound<IWalletProvider>();

// wallet
collection.AddSingleton<ILogoutHandler, IWalletProvider, MetaMaskProvider>();
collection.UseWalletProvider<MetaMaskProvider>(new MetaMaskConfig());

return collection;
}
Expand Down
24 changes: 0 additions & 24 deletions src/ChainSafe.Gaming.MetaMask/ChainSafe.Gaming.MetaMask.csproj

This file was deleted.

Loading