Skip to content

Commit

Permalink
Merge pull request #13 from Web3Auth/session-management
Browse files Browse the repository at this point in the history
Session management
  • Loading branch information
chaitanyapotti authored Jan 26, 2023
2 parents f603ef3 + 359d27b commit 407ca34
Show file tree
Hide file tree
Showing 70 changed files with 2,025 additions and 6 deletions.
Binary file modified Assets/Plugins/.DS_Store
Binary file not shown.
Binary file modified Assets/Plugins/Web3AuthSDK/.DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Api.meta

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

8 changes: 8 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Api/Models.meta

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

11 changes: 11 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Api/Models/LogoutApiRequest.cs
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; }
}
11 changes: 11 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Api/Models/LogoutApiRequest.cs.meta

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

8 changes: 8 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Api/Models/StoreApiResponse.cs
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; }
}
11 changes: 11 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Api/Models/StoreApiResponse.cs.meta

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

54 changes: 54 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Api/Web3AuthApi.cs
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;
}
}
}
11 changes: 11 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Api/Web3AuthApi.cs.meta

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

8 changes: 8 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Keystore.meta

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

52 changes: 52 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Keystore/KeyStoreManagerUtils.cs
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();
}
}
11 changes: 11 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Keystore/KeyStoreManagerUtils.cs.meta

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

8 changes: 8 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Nethereum.meta

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

Binary file not shown.
33 changes: 33 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Nethereum/BouncyCastle.Crypto.dll.meta

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

Binary file not shown.

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

Binary file not shown.
33 changes: 33 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Nethereum/Nethereum.ABI.dll.meta

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

Binary file not shown.
33 changes: 33 additions & 0 deletions Assets/Plugins/Web3AuthSDK/Nethereum/Nethereum.Accounts.dll.meta

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

Binary file not shown.

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

Binary file not shown.
Loading

0 comments on commit 407ca34

Please sign in to comment.