Update: Added RelayServer Logic

This commit is contained in:
2026-03-19 16:48:56 -04:00
parent 46ba326150
commit aac69ea770
12 changed files with 270 additions and 22 deletions

View File

@@ -0,0 +1,44 @@
using System.Security.Cryptography;
using System.Text;
namespace RelayServer.Services;
public sealed class ChannelCryptoService
{
public string GenerateKey()
{
return Convert.ToBase64String(RandomNumberGenerator.GetBytes(32));
}
public (string cipherText, string nonce, string tag) Encrypt(string plainText, string keyBase64)
{
var key = Convert.FromBase64String(keyBase64);
var nonce = RandomNumberGenerator.GetBytes(12);
var plainBytes = Encoding.UTF8.GetBytes(plainText);
var cipherBytes = new byte[plainBytes.Length];
var tag = new byte[16];
using var aes = new AesGcm(key, 16);
aes.Encrypt(nonce, plainBytes, cipherBytes, tag);
return (
Convert.ToBase64String(cipherBytes),
Convert.ToBase64String(nonce),
Convert.ToBase64String(tag)
);
}
public string Decrypt(string cipherTextBase64, string nonceBase64, string tagBase64, string keyBase64)
{
var key = Convert.FromBase64String(keyBase64);
var nonce = Convert.FromBase64String(nonceBase64);
var tag = Convert.FromBase64String(tagBase64);
var cipherBytes = Convert.FromBase64String(cipherTextBase64);
var plainBytes = new byte[cipherBytes.Length];
using var aes = new AesGcm(key, 16);
aes.Decrypt(nonce, cipherBytes, tag, plainBytes);
return Encoding.UTF8.GetString(plainBytes);
}
}

View File

@@ -0,0 +1,6 @@
namespace RelayServer.Services;
public class ChannelMessageService
{
}

View File

@@ -0,0 +1,16 @@
namespace RelayServer.Services;
public sealed class CoreClientService
{
public Task<CoreUser?> GetUserByUsernameAsync(string username)
{
return Task.FromResult<CoreUser?>(username switch
{
"Keeper317" => new CoreUser("users:keeper317", "Keeper317", true),
"Ru_Kira" => new CoreUser("users:ru_kira", "Ru_Kira", true),
_ => null
});
}
}
public sealed record CoreUser(string Id, string Username, bool Licensed);

View File

@@ -0,0 +1,6 @@
namespace RelayServer.Services;
public class ServerBootstrapService
{
}

View File

@@ -0,0 +1,21 @@
using SurrealDb.Net;
using SurrealDb.Net.Models.Auth;
namespace RelayServer.Services;
public sealed class SurrealService
{
public async Task<SurrealDbClient> ConnectAsync()
{
var db = new SurrealDbClient("ws://127.0.0.1:8000/rpc");
await db.SignIn(new RootAuth
{
Username = "root",
Password = "secret"
});
await db.Use("test", "test");
return db;
}
}