-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
Session management
- 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.
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,11 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class LogoutApiRequest | ||
{ | ||
public string key { get; set; } | ||
public string data { get; set; } | ||
public string signature { get; set; } | ||
public long timeout { get; set; } | ||
} |
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,8 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class StoreApiResponse { | ||
public string message { get; set; } | ||
public bool success { get; set; } | ||
} |
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,54 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using System.Net.Http; | ||
using System; | ||
using Newtonsoft.Json.Linq; | ||
using Newtonsoft.Json; | ||
using System.Text; | ||
|
||
public class Web3AuthApi | ||
{ | ||
static Web3AuthApi instance; | ||
static Uri baseAddress = new Uri("https://broadcast-server.tor.us"); | ||
|
||
public static Web3AuthApi getInstance() | ||
{ | ||
if (instance == null) | ||
instance = new Web3AuthApi(); | ||
return instance; | ||
} | ||
|
||
public StoreApiResponse? authorizeSession(string key) | ||
{ | ||
using (var client = new HttpClient()) | ||
{ | ||
client.BaseAddress = baseAddress; | ||
HttpResponseMessage response = client.GetAsync("/store/get?key=" + key).Result; | ||
|
||
if (response.IsSuccessStatusCode) | ||
{ | ||
string result = response.Content.ReadAsStringAsync().Result; | ||
return Newtonsoft.Json.JsonConvert.DeserializeObject<StoreApiResponse>(result); | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
public JObject logout(LogoutApiRequest logoutApiRequest) | ||
{ | ||
using (var client = new HttpClient()) | ||
{ | ||
client.BaseAddress = baseAddress; | ||
var content = new StringContent(JsonConvert.SerializeObject(logoutApiRequest), Encoding.UTF8, "application/json"); | ||
HttpResponseMessage response = client.PostAsync("/store/set", content).Result; | ||
|
||
if (response.IsSuccessStatusCode) | ||
{ | ||
string result = response.Content.ReadAsStringAsync().Result; | ||
return Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(result); | ||
} | ||
return null; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,52 @@ | ||
using Nethereum.Hex.HexConvertors.Extensions; | ||
using Nethereum.Signer; | ||
using Nethereum.Util; | ||
using Org.BouncyCastle.Asn1; | ||
|
||
public class KeyStoreManagerUtils | ||
{ | ||
|
||
public static string SESSION_ID = "sessionId"; | ||
public static string IV_KEY = "ivKey"; | ||
public static string EPHEM_PUBLIC_Key = "ephemPublicKey"; | ||
public static string MAC = "mac"; | ||
|
||
public static string getPubKey(string sessionId) | ||
{ | ||
var privKey = new EthECKey(sessionId); | ||
return privKey.GetPubKey().ToHex(); | ||
} | ||
|
||
static KeyStoreManagerUtils() | ||
{ | ||
SecurePlayerPrefs.Init(); | ||
} | ||
|
||
public static void savePreferenceData(string key, string value) | ||
{ | ||
SecurePlayerPrefs.SetString(key, value); | ||
} | ||
|
||
public static string getPreferencesData(string key) | ||
{ | ||
return SecurePlayerPrefs.GetString(key); | ||
} | ||
public static void deletePreferencesData(string key) | ||
{ | ||
SecurePlayerPrefs.DeleteKey(key); | ||
} | ||
|
||
public static string getECDSASignature(string privateKey, string data){ | ||
var derivedECKeyPair = new EthECKey(privateKey); | ||
byte[] hashedData = new Sha3Keccack().CalculateHash(System.Text.Encoding.UTF8.GetBytes(data)); | ||
|
||
var signature = derivedECKeyPair.Sign(hashedData); | ||
var v = new Asn1EncodableVector(); | ||
v.Add(new DerInteger(signature.R)); | ||
v.Add(new DerInteger(signature.S)); | ||
|
||
var der = new DerSequence(v); | ||
var sigBytes = der.GetEncoded(); | ||
return sigBytes.ToHexCompact(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.