Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: nethereum signing memory #1830

Merged
merged 18 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"GUID:b46779583a009f04ba9f5f31d0e7e6ac",
"GUID:56e8195b069a4dca9c4c4f313c65f526",
"GUID:e25ef972de004615a22937e739de2def",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b",
"GUID:5ab29fa8ae5769b49ab29e390caca7a4",
"GUID:91cf8206af184dac8e30eb46747e9939"
],
Expand Down
3 changes: 2 additions & 1 deletion Explorer/Assets/DCL/Backpack/Backpack.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"GUID:eec0964c48f6f4e40bc3ec2257ccf8c5",
"GUID:ac3295688c7c22745a96e6ac34718181",
"GUID:d832748739a186646b8656bdbd447ad0",
"GUID:f95dba842fdbb470fb6d1dced822ba04"
"GUID:f95dba842fdbb470fb6d1dced822ba04",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
3 changes: 2 additions & 1 deletion Explorer/Assets/DCL/Chat/Chat.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"GUID:e0eedfa2deb9406daf86fd8368728e39",
"GUID:7175400a68914a45acecc9fb068de3b8",
"GUID:875a5d5129614170bd769ed012c2eb3d",
"GUID:f4a0f40a2545482b8929d4c3c642f50a"
"GUID:f4a0f40a2545482b8929d4c3c642f50a",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
3 changes: 2 additions & 1 deletion Explorer/Assets/DCL/FeatureFlags/DCL.FeatureFlags.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"GUID:5ab29fa8ae5769b49ab29e390caca7a4",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:101b8b6ebaf64668909b49c4b7a1420d",
"GUID:91cf8206af184dac8e30eb46747e9939"
"GUID:91cf8206af184dac8e30eb46747e9939",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"GUID:006c0e0a70294dbba8a4cbcfb77e1f7d",
"GUID:e0eedfa2deb9406daf86fd8368728e39",
"GUID:3640f3c0b42946b0b8794a1ed8e06ca5",
"GUID:d414ef88f3b15f746a4b97636b50dfb4"
"GUID:d414ef88f3b15f746a4b97636b50dfb4",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"GUID:5eabe9a3d4dd19d42a16208ea5411062",
"GUID:6830e2f56251b492e9934f1fafbc8c7d",
"GUID:45fc0f02fe4e57c4a93a421d8f6f53df",
"GUID:e169fa6683c924c7e99a85981a91d953"
"GUID:e169fa6683c924c7e99a85981a91d953",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
3 changes: 2 additions & 1 deletion Explorer/Assets/DCL/PluginSystem/DCL.Plugins.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@
"GUID:df934776371151c45b473e9aa39efd1b",
"GUID:c5db5ed4ea75a402dba1512abe9482ec",
"GUID:a285ec5e26824438b1b2ab8f22969298",
"GUID:a0d83a4df040477894e767d4333169ec"
"GUID:a0d83a4df040477894e767d4333169ec",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
3 changes: 2 additions & 1 deletion Explorer/Assets/DCL/Profiles/DCL.Profiles.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"GUID:9e314663ce958b746873cb22d57ede55",
"GUID:9e24947de15b9834991c9d8411ea37cf",
"GUID:166b65e6dfc848bb9fb075f53c293a38",
"GUID:3c7b57a14671040bd8c549056adc04f5"
"GUID:3c7b57a14671040bd8c549056adc04f5",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
1 change: 1 addition & 0 deletions Explorer/Assets/DCL/Tests/Editor/ValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ValidationTests
private readonly IReadOnlyCollection<string> pathIgnores = new List<string>
{
"node_modules",
"sign-server"
};

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"GUID:45f6fff651a0a514f8edfdaf9cce45af",
"GUID:5ab29fa8ae5769b49ab29e390caca7a4",
"GUID:4a12c0b1b77ec6b418a8d7bd5c925be3",
"GUID:fa7b3fdbb04d67549916da7bd2af58ab"
"GUID:fa7b3fdbb04d67549916da7bd2af58ab",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
3 changes: 2 additions & 1 deletion Explorer/Assets/DCL/UI/Sidebar/UI.Sidebar.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"GUID:a327cdd867b4c134c92b67c566c92ad7",
"GUID:766b242fb43af451aaa331f39872177d",
"GUID:52421c42d33594c47a6fbd48b45b1259",
"GUID:df934776371151c45b473e9aa39efd1b"
"GUID:df934776371151c45b473e9aa39efd1b",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
1 change: 1 addition & 0 deletions Explorer/Assets/DCL/UI/Sidebar/csc.rsp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-nullable:enable
3 changes: 3 additions & 0 deletions Explorer/Assets/DCL/UI/Sidebar/csc.rsp.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Explorer/Assets/DCL/UI/SystemMenu/UI.SystemMenu.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"GUID:ae249ee11a6e0ea4aa01cefc0246a151",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:2f30d6e5229a74284acedda491abcc6e",
"GUID:029c1c1b674aaae47a6841a0b89ad80e"
"GUID:029c1c1b674aaae47a6841a0b89ad80e",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"GUID:91cf8206af184dac8e30eb46747e9939",
"GUID:3584eeba5aa04262ac61bf2cd833becc",
"GUID:4a12c0b1b77ec6b418a8d7bd5c925be3",
"GUID:7175400a68914a45acecc9fb068de3b8"
"GUID:7175400a68914a45acecc9fb068de3b8",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
3 changes: 3 additions & 0 deletions Explorer/Assets/DCL/Web3/Abstract.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Nethereum.Signer;

namespace DCL.Web3.Accounts
namespace DCL.Web3.Abstract
{
public interface IEthKeyOwner
NickKhalow marked this conversation as resolved.
Show resolved Hide resolved
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DCL.Web3.Accounts
namespace DCL.Web3.Abstract
{
public interface IWeb3Account
{
Expand Down
11 changes: 11 additions & 0 deletions Explorer/Assets/DCL/Web3/Abstract/IWeb3AccountFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Nethereum.Signer;

namespace DCL.Web3.Abstract
{
public interface IWeb3AccountFactory
NickKhalow marked this conversation as resolved.
Show resolved Hide resolved
{
IWeb3Account CreateAccount(EthECKey key);

IWeb3Account CreateRandomAccount();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions Explorer/Assets/DCL/Web3/Abstract/Web3.Abstract.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "Web3.Abstract",
"rootNamespace": "",
"references": [
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:fa7b3fdbb04d67549916da7bd2af58ab",
"GUID:3640f3c0b42946b0b8794a1ed8e06ca5",
"GUID:91cf8206af184dac8e30eb46747e9939",
"GUID:29f99fa49221a4df7aecb5cd50457e5f",
"GUID:92920c790fc0443e9a7ec2f7d1e5308f",
"GUID:101b8b6ebaf64668909b49c4b7a1420d"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"Newtonsoft.Json.dll",
"Nethereum.Signer.dll",
"SocketIO.Serializer.Core.dll",
"SocketIO.Serializer.SystemTextJson.dll",
"System.Text.Json.dll"
],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
3 changes: 3 additions & 0 deletions Explorer/Assets/DCL/Web3/Abstract/Web3.Abstract.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Explorer/Assets/DCL/Web3/Abstract/csc.rsp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-nullable:enable
3 changes: 3 additions & 0 deletions Explorer/Assets/DCL/Web3/Abstract/csc.rsp.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Explorer/Assets/DCL/Web3/Accounts/Factory.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Explorer/Assets/DCL/Web3/Accounts/Factory/Web3AccountFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using DCL.Web3.Abstract;
using Nethereum.Signer;
using Plugins.RustEthereum.SignServerWrap;

namespace DCL.Web3.Accounts.Factory
{
public class Web3AccountFactory : IWeb3AccountFactory
{
public IWeb3Account CreateAccount(EthECKey key) =>
new RustEthereumAccount(key);

public IWeb3Account CreateRandomAccount()
{
var randomKey = EthECKey.GenerateKey()!;
return CreateAccount(randomKey);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Explorer/Assets/DCL/Web3/Accounts/LogWeb3Account.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DCL.Diagnostics;
using DCL.Web3.Abstract;
using Nethereum.Signer;
using System;
using UnityEngine;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Cysharp.Threading.Tasks;
using DCL.Browser;
using DCL.Multiplayer.Connections.DecentralandUrls;
using DCL.Web3.Abstract;
using DCL.Web3.Accounts;
using DCL.Web3.Accounts.Factory;
using DCL.Web3.Chains;
using DCL.Web3.Identities;
using Newtonsoft.Json;
Expand All @@ -25,6 +27,7 @@ public partial class DappWeb3Authenticator : IWeb3VerifiedAuthenticator, IVerifi
private readonly string signatureUrl;
private readonly IWeb3IdentityCache identityCache;
private readonly HashSet<string> whitelistMethods;
private readonly IWeb3AccountFactory accountFactory = new Web3AccountFactory();

private SocketIO? webSocket;
private UniTaskCompletionSource<SocketIOResponse>? signatureOutcomeTask;
Expand Down Expand Up @@ -101,7 +104,7 @@ public async UniTask<IWeb3Identity> LoginAsync(CancellationToken ct)
{
await ConnectToServerAsync();

var ephemeralAccount = NethereumAccount.CreateRandom();
var ephemeralAccount = accountFactory.CreateRandomAccount();

// 1 week expiration day, just like unity-renderer
DateTime sessionExpiration = DateTime.UtcNow.AddDays(7);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Cysharp.Threading.Tasks;
using DCL.Web3.Abstract;
using DCL.Web3.Accounts;
using DCL.Web3.Accounts.Factory;
using DCL.Web3.Chains;
using DCL.Web3.Identities;
using System;
Expand All @@ -9,14 +11,16 @@ namespace DCL.Web3.Authenticators
{
public class RandomGeneratedWeb3Authenticator : IWeb3Authenticator
{
private readonly IWeb3AccountFactory accountFactory = new Web3AccountFactory();

public void Dispose()
{
}

public UniTask<IWeb3Identity> LoginAsync(CancellationToken ct)
{
var signer = NethereumAccount.CreateRandom();
var ephemeralAccount = NethereumAccount.CreateRandom();
var signer = accountFactory.CreateRandomAccount();
var ephemeralAccount = accountFactory.CreateRandomAccount();
DateTime expiration = DateTime.Now.AddMinutes(600);

var ephemeralMessage = $"Decentraland Login\nEphemeral address: {ephemeralAccount.Address}\nExpiration: {expiration:s}";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using DCL.Web3.Abstract;
using DCL.Web3.Accounts;
using DCL.Web3.Chains;
using System;
Expand Down
9 changes: 6 additions & 3 deletions Explorer/Assets/DCL/Web3/Identities/IWeb3Identity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DCL.Web3.Accounts;
using DCL.Web3.Abstract;
using DCL.Web3.Accounts.Factory;
using DCL.Web3.Chains;
using System;

Expand All @@ -16,10 +17,12 @@ public interface IWeb3Identity : IDisposable

class Random : IWeb3Identity
{
private static readonly IWeb3AccountFactory ACCOUNT_FACTORY = new Web3AccountFactory();

public Random(IWeb3Account? account = null) : this(
NethereumAccount.CreateRandom().Address,
ACCOUNT_FACTORY.CreateRandomAccount().Address,
DateTime.MaxValue,
account ?? NethereumAccount.CreateRandom(),
account ?? ACCOUNT_FACTORY.CreateRandomAccount(),
false,
AuthChain.Create()
) { }
Expand Down
1 change: 1 addition & 0 deletions Explorer/Assets/DCL/Web3/Identities/LogWeb3Identity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DCL.Diagnostics;
using DCL.Web3.Abstract;
using DCL.Web3.Accounts;
using DCL.Web3.Chains;
using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DCL.Web3.Accounts;
using DCL.Web3.Abstract;
using DCL.Web3.Accounts.Factory;
using DCL.Web3.Chains;
using Nethereum.Signer;
using Newtonsoft.Json;
Expand All @@ -12,6 +13,7 @@ public partial class PlayerPrefsIdentityProvider
public class DecentralandIdentityWithNethereumAccountJsonSerializer : IWeb3IdentityJsonSerializer
{
private readonly IdentityJsonDto jsonRoot = new ();
private readonly IWeb3AccountFactory accountFactory = new Web3AccountFactory();

public IWeb3Identity? Deserialize(string json)
{
Expand All @@ -26,7 +28,7 @@ public class DecentralandIdentityWithNethereumAccountJsonSerializer : IWeb3Ident
authChain.Set(link);

return new DecentralandIdentity(new Web3Address(jsonRoot.address),
new NethereumAccount(new EthECKey(jsonRoot.key)),
accountFactory.CreateAccount(new EthECKey(jsonRoot.key)),
DateTime.Parse(jsonRoot.expiration, null, DateTimeStyles.RoundtripKind),
authChain);
}
Expand Down
3 changes: 3 additions & 0 deletions Explorer/Assets/DCL/Web3/Nethereum.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nethereum.Signer;
using DCL.Web3.Abstract;
using Nethereum.Signer;

namespace DCL.Web3.Accounts
{
Expand All @@ -11,14 +12,14 @@ public class NethereumAccount : IWeb3Account, IEthKeyOwner

public EthECKey Key => key;

public NethereumAccount(EthECKey key)
private NethereumAccount(EthECKey key)
{
this.key = key;
Address = new Web3Address(key.GetPublicAddress());
}

public static NethereumAccount CreateRandom() =>
new (EthECKey.GenerateKey());
public static NethereumAccount CreateForVerifyOnly(EthECKey key) =>
new (key);

public string Sign(string message) =>
signer.EncodeUTF8AndSign(message, key);
Expand Down
Loading
Loading