-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
chore: Merge release v0.7.0 to main See merge request elympics/unity-sdk-package!175
- Loading branch information
There are no files selected for viewing
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,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); | ||
} | ||
} |
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,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); | ||
} | ||
} |
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,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; | ||
} | ||
} | ||
} |
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 enum AuthType | ||
{ | ||
None = 0, | ||
ClientSecret = 1, | ||
EthAddress = 2, | ||
} | ||
} |
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.
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); | ||
} | ||
} |
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.