Skip to content

Commit

Permalink
Savepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
skibitsky committed Sep 27, 2024
1 parent 927f004 commit 0fc82bf
Show file tree
Hide file tree
Showing 45 changed files with 1,553 additions and 171 deletions.
204 changes: 94 additions & 110 deletions .idea/.idea.Reown/.idea/workspace.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Reown.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=caip/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=reown/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
15 changes: 15 additions & 0 deletions src/Reown.Core.Common/Runtime/Utils/LowerCaseNamingStrategy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Newtonsoft.Json.Serialization;

namespace Reown.Core.Common.Utils
{
/// <summary>
/// Newtonsoft.Json naming strategy that converts property names to lower case
/// </summary>
public class LowerCaseNamingStrategy : NamingStrategy
{
protected override string ResolvePropertyName(string name)
{
return name.ToLowerInvariant();
}
}
}
9 changes: 7 additions & 2 deletions src/Reown.Core/Runtime/Controllers/Pairing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public async Task<PairingStruct> Pair(string uri, bool activatePairing = true)
/// A new instance of <see cref="CreatePairingData" /> that includes the pairing topic and
/// uri
/// </returns>
public async Task<CreatePairingData> Create()
public async Task<CreatePairingData> Create(string[] methods = null)
{
var symKeyRaw = new byte[KeyLength];
RandomNumberGenerator.Fill(symKeyRaw);
Expand All @@ -224,13 +224,18 @@ public async Task<CreatePairingData> Create()
Relay = relay,
Active = false
};

var uri = $"{ICoreClient.Protocol}:{topic}@{ICoreClient.Version}?"
.AddQueryParam("symKey", symKey)
.AddQueryParam("relay-protocol", relay.Protocol);
.AddQueryParam("relay-protocol", relay.Protocol)
.AddQueryParam("expiryTimestamp", expiry.ToString());

if (!string.IsNullOrWhiteSpace(relay.Data))
uri = uri.AddQueryParam("relay-data", relay.Data);

if (methods is { Length: > 0 })
uri = uri.AddQueryParam("methods", string.Join(",", methods));

await Store.Set(topic, pairing);
await CoreClient.Relayer.Subscribe(topic);
CoreClient.Expirer.Set(topic, expiry);
Expand Down
2 changes: 1 addition & 1 deletion src/Reown.Core/Runtime/Interfaces/IPairing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public interface IPairing : IModule
/// A new instance of <see cref="CreatePairingData" /> that includes the pairing topic and
/// uri
/// </returns>
Task<CreatePairingData> Create();
Task<CreatePairingData> Create(string[] methods = null);

/// <summary>
/// Activate a previously created pairing at the given topic
Expand Down
2 changes: 1 addition & 1 deletion src/Reown.Core/Runtime/Models/Verify/VerifiedContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private Validation FromString()
}
}

private string AsString(Validation str)
private static string AsString(Validation str)
{
switch (str)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Reown.Sign/Reown.Sign.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
<ItemGroup>
<ProjectReference Include="..\Reown.Core\Reown.Core.csproj"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Nethereum.Signer"/>
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions src/Reown.Sign/Runtime/Constants/AuthConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Reown.Sign.Constants
{
public static class AuthConstants
{
public const string AuthProtocol = "wc";
public const double AuthVersion = 1.5;
public const string AuthContext = "auth";
public const string AuthKeysContext = "authKeys";
public const string AuthPairingTopicContext = "pairingTopics";
public const string AuthPendingRequestContext = "requests";

public static readonly string AuthStoragePrefix = $"{AuthProtocol}@{AuthVersion}:{AuthContext}:";
public static readonly string AuthPublicKeyName = $"{AuthStoragePrefix}:PUB_KEY";
}
}
2 changes: 1 addition & 1 deletion src/Reown.Sign/Runtime/Controllers/AddressProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public async Task SetDefaultChainIdAsync(string chainId)
throw new ArgumentNullException(nameof(chainId));
}

if (!Utils.IsValidChainId(chainId))
if (!Core.Utils.IsValidChainId(chainId))
{
throw new ArgumentException("The format of 'chainId' is invalid. Must be in the format of 'namespace:chainId' (e.g. 'eip155:10'). See CAIP-2 for more information.");
}
Expand Down
30 changes: 30 additions & 0 deletions src/Reown.Sign/Runtime/Controllers/Auth.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Threading.Tasks;
using Reown.Core.Interfaces;
using Reown.Sign.Interfaces;
using Reown.Sign.Models;

namespace Reown.Sign.Controllers
{
public class Auth : IAuth
{
public Auth(ICoreClient coreClient)
{
Keys = new AuthKeyStore(coreClient);
Pairings = new AuthPairingTopics(coreClient);
PendingRequests = new AuthPendingRequests(coreClient);
}

public Task Init()
{
return Task.WhenAll(
Keys.Init(),
Pairings.Init(),
PendingRequests.Init()
);
}

public IStore<string, AuthKey> Keys { get; }
public IStore<string, AuthPairing> Pairings { get; }
public IStore<long, AuthPendingRequest> PendingRequests { get; }
}
}
14 changes: 14 additions & 0 deletions src/Reown.Sign/Runtime/Controllers/AuthKeyStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Reown.Core.Controllers;
using Reown.Core.Interfaces;
using Reown.Sign.Constants;
using Reown.Sign.Models;

namespace Reown.Sign.Controllers
{
public class AuthKeyStore : Store<string, AuthKey>
{
public AuthKeyStore(ICoreClient coreClient) : base(coreClient, AuthConstants.AuthKeysContext, AuthConstants.AuthStoragePrefix)
{
}
}
}
14 changes: 14 additions & 0 deletions src/Reown.Sign/Runtime/Controllers/AuthPairingTopics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Reown.Core.Controllers;
using Reown.Core.Interfaces;
using Reown.Sign.Constants;
using Reown.Sign.Models;

namespace Reown.Sign.Controllers
{
public class AuthPairingTopics : Store<string, AuthPairing>
{
public AuthPairingTopics(ICoreClient coreClient) : base(coreClient, AuthConstants.AuthPairingTopicContext, AuthConstants.AuthStoragePrefix)
{
}
}
}
14 changes: 14 additions & 0 deletions src/Reown.Sign/Runtime/Controllers/AuthPendingRequests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Reown.Core.Controllers;
using Reown.Core.Interfaces;
using Reown.Sign.Constants;
using Reown.Sign.Models;

namespace Reown.Sign.Controllers
{
public class AuthPendingRequests : Store<long, AuthPendingRequest>
{
public AuthPendingRequests(ICoreClient coreClient) : base(coreClient, AuthConstants.AuthPendingRequestContext, AuthConstants.AuthStoragePrefix)
{
}
}
}
Loading

0 comments on commit 0fc82bf

Please sign in to comment.