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 16 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
@@ -1,6 +1,7 @@
using Arch.Core;
using Cysharp.Threading.Tasks;
using DCL.Audio;
using DCL.Web3;
using DCL.Browser;
using DCL.CharacterPreview;
using DCL.Diagnostics;
Expand All @@ -10,13 +11,12 @@
using DCL.Profiles.Self;
using DCL.SceneLoadingScreens.SplashScreen;
using DCL.UI;
using DCL.Web3;
using DCL.Web3.Authenticators;
using DCL.Web3.Identities;
using MVC;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Localization.SmartFormat.PersistentVariables;
Expand All @@ -34,6 +34,7 @@ private enum ViewState
Loading,
Finalize,
}

private const int ANIMATION_DELAY = 300;

private const string REQUEST_BETA_ACCESS_LINK = "https://68zbqa0m12c.typeform.com/to/y9fZeNWm";
Expand Down Expand Up @@ -153,6 +154,7 @@ private async UniTaskVoid CheckValidIdentityAndStartInitialFlowAsync()
IWeb3Identity? storedIdentity = storedIdentityProvider.Identity;

if (storedIdentity is { IsExpired: false }

// Force to re-login if the identity will expire in 24hs or less, so we mitigate the chances on
// getting the identity expired while in-world, provoking signed-fetch requests to fail
&& storedIdentity.Expiration - DateTime.UtcNow > TimeSpan.FromDays(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"GUID:ace653ac543d483ba8abee112a3ba2a6",
"GUID:e169fa6683c924c7e99a85981a91d953",
"GUID:e7751264a6735a942a64770d71eb49e0",
"GUID:0401f68d61b24c63a3abf51e27bb46f1"
"GUID:0401f68d61b24c63a3abf51e27bb46f1",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
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
@@ -1,5 +1,6 @@
using Cysharp.Threading.Tasks;
using DCL.Multiplayer.Connections.DecentralandUrls;
using DCL.Web3.Abstract;
using DCL.Web3.Authenticators;
using DCL.Web3.Identities;
using System.Threading;
Expand All @@ -8,19 +9,24 @@ namespace DCL.Multiplayer.Connections.Demo
{
public static class ArchipelagoFakeIdentityCache
{
public static async UniTask<IWeb3IdentityCache> NewAsync(IDecentralandUrlsSource decentralandUrlsSource)
public static async UniTask<IWeb3IdentityCache> NewAsync(
IDecentralandUrlsSource decentralandUrlsSource,
IWeb3AccountFactory web3AccountFactory
)
{
IWeb3IdentityCache identityCache = new ProxyIdentityCache(
new MemoryWeb3IdentityCache(),
new PlayerPrefsIdentityProvider(
new PlayerPrefsIdentityProvider.DecentralandIdentityWithNethereumAccountJsonSerializer(),
new PlayerPrefsIdentityProvider.DecentralandIdentityWithNethereumAccountJsonSerializer(
web3AccountFactory
),
"ArchipelagoTestIdentity"
)
);

if (identityCache.Identity is null)
{
IWeb3Identity? identity = await new DappWeb3Authenticator.Default(identityCache, decentralandUrlsSource)
IWeb3Identity? identity = await new DappWeb3Authenticator.Default(identityCache, decentralandUrlsSource, web3AccountFactory)
.LoginAsync(CancellationToken.None);

identityCache.Identity = identity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using DCL.Multiplayer.Connections.Pools;
using DCL.Multiplayer.Connections.Systems;
using DCL.UserInAppInitializationFlow;
using DCL.Web3.Accounts.Factory;
using DCL.Web3.Identities;
using ECS;
using ECS.Abstract;
Expand Down Expand Up @@ -59,7 +60,7 @@ private async UniTaskVoid LaunchAsync()
multiPool
).WithLog();

IWeb3IdentityCache? identityCache = await ArchipelagoFakeIdentityCache.NewAsync(new DecentralandUrlsSource(DecentralandEnvironment.Zone));
IWeb3IdentityCache? identityCache = await ArchipelagoFakeIdentityCache.NewAsync(new DecentralandUrlsSource(DecentralandEnvironment.Zone), new Web3AccountFactory());

var archipelagoIslandRoom = new ArchipelagoIslandRoom(
identityCache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using DCL.Multiplayer.Connections.GateKeeper.Meta;
using DCL.Multiplayer.Connections.GateKeeper.Rooms;
using DCL.PlacesAPIService;
using DCL.Web3.Accounts.Factory;
using DCL.Web3.Identities;
using DCL.WebRequests;
using ECS;
Expand All @@ -32,7 +33,7 @@ private async UniTaskVoid LaunchAsync()

var urlsSource = new DecentralandUrlsSource(DecentralandEnvironment.Zone);

IWeb3IdentityCache? identityCache = await ArchipelagoFakeIdentityCache.NewAsync(urlsSource);
IWeb3IdentityCache? identityCache = await ArchipelagoFakeIdentityCache.NewAsync(urlsSource, new Web3AccountFactory());
var character = new ICharacterObject.Fake(Vector3.zero);
var webRequests = new LogWebRequestController(new WebRequestController(identityCache));
var places = new PlacesAPIService.PlacesAPIService(new PlacesAPIClient(webRequests, urlsSource));
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
using DCL.Multiplayer.Connections.Messaging.Hubs;
using DCL.Multiplayer.Connections.RoomHubs;
using DCL.PluginSystem;
using DCL.PluginSystem.Global;
using DCL.PluginSystem.World;
using DCL.Profiles;
using DCL.Web3;
using DCL.Web3.Accounts.Factory;
using DCL.Web3.Authenticators;
using DCL.Web3.Identities;
using DCL.WebRequests;
Expand Down Expand Up @@ -91,8 +91,9 @@ private async UniTask InitializationFlowAsync(CancellationToken ct)
try
{
var identityCache = new MemoryWeb3IdentityCache();
var web3AccountFactory = new Web3AccountFactory();

var web3Authenticator = new ProxyWeb3Authenticator(new RandomGeneratedWeb3Authenticator(), identityCache);
var web3Authenticator = new ProxyWeb3Authenticator(new RandomGeneratedWeb3Authenticator(web3AccountFactory), identityCache);
await web3Authenticator.LoginAsync(ct);

SceneSharedContainer sceneSharedContainer;
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 @@ -60,7 +60,8 @@
"GUID:c54a193e9535e43d8a25007ab5ee28b1",
"GUID:91cf8206af184dac8e30eb46747e9939",
"GUID:7175400a68914a45acecc9fb068de3b8",
"GUID:a0d83a4df040477894e767d4333169ec"
"GUID:a0d83a4df040477894e767d4333169ec",
"GUID:ca4e81cdd6a34d1aa54c32ad41fc5b3b"
],
"includePlatforms": [],
"excludePlatforms": [
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,9 +1,11 @@
namespace DCL.Web3.Accounts
namespace DCL.Web3.Abstract
{
public interface IWeb3Account
{
public Web3Address Address { get; }

public string PrivateKey { get; }

string Sign(string message);

/// <summary>
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.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using DCL.Web3.Abstract;
using System;

namespace DCL.Web3
Expand All @@ -6,9 +7,12 @@ public readonly struct Web3Address
{
private readonly string address;

public Web3Address(IWeb3Account web3Account) : this(web3Account.Address.address) {
}

public Web3Address(string address)
{
this.address = address;
this.address = address.ToLower();
}

public override string ToString() =>
Expand Down
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.

Loading
Loading