Skip to content

Commit

Permalink
Merge branch 'release/v0.7.0' into 'main'
Browse files Browse the repository at this point in the history
chore: Merge release v0.7.0 to main

See merge request elympics/unity-sdk-package!175
  • Loading branch information
Dawid Sygocki committed May 19, 2023
2 parents c6f4809 + 39f281f commit c6482a3
Show file tree
Hide file tree
Showing 122 changed files with 4,580 additions and 972 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [0.7.0](https://github.com/Elympics/Unity-SDK/compare/v0.6.3...v0.7.0) (2023-05-05)


### Features

* Add communication with Leaderboards API ([f42a1a3](https://github.com/Elympics/Unity-SDK/commit/f42a1a359fafcfba902812514caa28caecc97dde))
* Allow authentication using Ethereum signature ([254ad16](https://github.com/Elympics/Unity-SDK/commit/254ad16c5521db9ebbc426c8fab7d2dd97607ed3))
* Introduce SignOut method to ElympicsLobbyClient ([ff3bdd0](https://github.com/Elympics/Unity-SDK/commit/ff3bdd00d018b85765ef4df0e09214caef334eed))
* Add method allowing to play online in closest region ([b212572](https://github.com/Elympics/Unity-SDK/commit/b212572be7a3fce5e7d30a25b90fd0a8519ec6b4))



## [0.6.3](https://github.com/Elympics/Unity-SDK/compare/v0.6.2...v0.6.3) (2023-04-27)


Expand Down
2 changes: 1 addition & 1 deletion Editor/ElympicsWebIntegration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private static JwtMidPart GetAuthTokenMid(string authToken)
{
var authTokenParts = authToken.Split('.');
var authTokenMidPadded = authTokenParts[1].PadRight(4 * ((authTokenParts[1].Length + 3) / 4), '=');
var authTokenMidStr = Encoding.ASCII.GetString(Convert.FromBase64String(authTokenMidPadded));
var authTokenMidStr = Encoding.ASCII.GetString(Convert.FromBase64String(authTokenMidPadded.Replace('-', '+').Replace('_', '/'))); // JWT is encoded as URL-safe base64, some characters have to be replaced
var authTokenMid = JsonConvert.DeserializeObject<JwtMidPart>(authTokenMidStr);
return authTokenMid;
}
Expand Down
2 changes: 1 addition & 1 deletion Runtime/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

[assembly: InternalsVisibleTo("Elympics.Tests")]
[assembly: InternalsVisibleTo("Elympics.Editor")]
[assembly: AssemblyVersion("0.6.3.0")]
[assembly: AssemblyVersion("0.7.0.0")]
6 changes: 3 additions & 3 deletions Runtime/Blockchain.meta

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

4 changes: 0 additions & 4 deletions Runtime/Blockchain/BlockchainFeedbackData.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Elympics
{
public struct BlockchainFeedbackData
Expand Down
3 changes: 0 additions & 3 deletions Runtime/Blockchain/ElympicsBlockchain.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Elympics;
using UnityEngine;

namespace Elympics
Expand Down
15 changes: 15 additions & 0 deletions Runtime/Blockchain/ElympicsEthSigner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;

namespace Elympics
{
public abstract class ElympicsEthSigner : MonoBehaviour, IEthSigner
{
public virtual string ProvideMessage(string nonce) =>
$"Please sign the following nonce so we can authenticate you as Elympics player:\n\n{nonce}";

public abstract Task<string> ProvideAddressAsync(CancellationToken ct = default);
public abstract Task<string> SignAsync(string message, CancellationToken ct = default);
}
}
3 changes: 3 additions & 0 deletions Runtime/Blockchain/ElympicsEthSigner.cs.meta

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

31 changes: 31 additions & 0 deletions Runtime/Blockchain/IEthSigner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Threading;
using System.Threading.Tasks;

namespace Elympics
{
public interface IEthSigner
{
/// <summary>
/// Method for providing Ethereum public address.
/// It is called by Elympics in authentication process.
/// </summary>
/// <param name="ct">Cancellation token managed by Elympics.</param>
Task<string> ProvideAddressAsync(CancellationToken ct = default);

/// <summary>
/// Method for preparing a message for the player to sign. It MUST contain the nonce passed in the argument.
/// It is called by Elympics in authentication process.
/// </summary>
/// <param name="nonce">A nonce to be included in the message.</param>
/// <returns>Human-readable message for a player to sign</returns>
string ProvideMessage(string nonce);

/// <summary>
/// Method for signing authentication message from Elympics using "personal_sign" Ethereum method.
/// It is called by Elympics in authentication process.
/// </summary>
/// <param name="message">Hex-encoded UTF-8 message to sign using "personal_sign" algorithm.</param>
/// <param name="ct">Cancellation token managed by Elympics.</param>
Task<string> SignAsync(string message, CancellationToken ct = default);
}
}
3 changes: 3 additions & 0 deletions Runtime/Blockchain/IEthSigner.cs.meta

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

27 changes: 27 additions & 0 deletions Runtime/Communication/Authentication/Models/AuthData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;

namespace Elympics.Models.Authentication
{
public class AuthData
{
public Guid UserId { get; }
public string JwtToken { get; }
public AuthType AuthType { get; }

internal string BearerAuthorization => $"Bearer {JwtToken}";

public AuthData(Guid userId, string jwtToken, AuthType authType = AuthType.None)
{
UserId = userId;
JwtToken = jwtToken;
AuthType = authType;
}

public AuthData(AuthenticationDataResponse response, AuthType authType = AuthType.None)
{
UserId = new Guid(response.userId);
JwtToken = response.jwtToken;
AuthType = authType;
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Communication/Authentication/Models/AuthData.cs.meta

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

12 changes: 12 additions & 0 deletions Runtime/Communication/Authentication/Models/AuthType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Elympics.Models.Authentication
{
[Serializable]
public enum AuthType
{
None = 0,
ClientSecret = 1,
EthAddress = 2,
}
}
3 changes: 3 additions & 0 deletions Runtime/Communication/Authentication/Models/AuthType.cs.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,16 +1,16 @@
using System;
using Elympics.Models.Authentication;

namespace Elympics
{
public class AuthenticationData
// TODO: in the process of renaming to shorter AuthData (backwards compatibility) ~dsygocki 2023-04-28
public class AuthenticationData : AuthData
{
public Guid UserId { get; }
public string JwtToken { get; }

public AuthenticationData(Guid userId, string jwtToken)
{
UserId = userId;
JwtToken = jwtToken;
}
public AuthenticationData(AuthData authData)
: base(authData.UserId, authData.JwtToken, authData.AuthType) { }
public AuthenticationData(Guid userId, string jwtToken, AuthType authType = AuthType.None)
: base(userId, jwtToken, authType) { }
public AuthenticationData(AuthenticationDataResponse response, AuthType authType = AuthType.None)
: base(response, authType) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Elympics.Models.Authentication
{
[Serializable]
public class AuthenticationDataResponse
{
public string userId;
public string jwtToken;
}
}

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
@@ -0,0 +1,10 @@
using System;

namespace Elympics.Models.Authentication
{
[Serializable]
public class ClientSecretAuthRequest
{
public string clientSecret;
}
}

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
@@ -0,0 +1,12 @@
using System;

namespace Elympics.Models.Authentication
{
[Serializable]
public struct EthAddressAuthRequest
{
public string address;
public string msg;
public string sig;
}
}

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
@@ -0,0 +1,10 @@
using System;

namespace Elympics.Models.Authentication
{
[Serializable]
public struct EthAddressNonceRequest
{
public string address;
}
}

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

7 changes: 6 additions & 1 deletion Runtime/Communication/Authentication/Models/Routes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ public static class Routes
{
public const string Base = "user";

public const string AuthenticateUserId = "authUserId";
public const string ClientSecretAuth = "clientSecretAuth";

public const string EthAddressNonce = "ethAddressNonce";
public const string EthAddressAuth = "ethAddressAuth";

public const string LoginStatus = "loginStatus";
}
}
12 changes: 12 additions & 0 deletions Runtime/Communication/IAuthClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Threading;
using Elympics.Models.Authentication;

namespace Elympics
{
internal interface IAuthClient
{
void AuthenticateWithClientSecret(string clientSecret, Action<Result<AuthData, string>> onResult, CancellationToken ct = default);
void AuthenticateWithEthAddress(IEthSigner ethSigner, Action<Result<AuthData, string>> onResult, CancellationToken ct = default);
}
}
File renamed without changes.
9 changes: 0 additions & 9 deletions Runtime/Communication/IAuthenticationClient.cs

This file was deleted.

8 changes: 8 additions & 0 deletions Runtime/Communication/Leaderboards.meta

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

0 comments on commit c6482a3

Please sign in to comment.