write thumbnail to wallet store

This commit is contained in:
TheXamlGuy
2024-06-29 19:39:34 +01:00
parent c1713b1372
commit 29e41d821f
14 changed files with 117 additions and 76 deletions
+28 -8
View File
@@ -1,18 +1,38 @@
using Toolkit.Foundation;
using Microsoft.Extensions.Hosting;
using System.Text;
using Toolkit.Foundation;
namespace Wallet;
public class WalletFactory(IComponentFactory componentFactory) :
public class WalletFactory(ISecurityKeyFactory securityKeyFactory,
IDecoratorService<SecurityKey> secureKeyStore,
IWalletStoreFactory walletStoreFactory,
IWritableConfiguration<WalletConfiguration> configuration,
IHostEnvironment environment,
IImageWriter imageWriter) :
IWalletFactory
{
public IComponentHost? Create(string key)
public async Task<bool> Create(string name,
string password,
IImageDescriptor thumbnail)
{
if (componentFactory.Create<WalletComponent, WalletConfiguration>($"Wallet:{key}",
new WalletConfiguration()) is IComponentHost host)
if (securityKeyFactory.Create(Encoding.UTF8.GetBytes(password)) is SecurityKey key)
{
return host;
secureKeyStore.Set(key);
if (await walletStoreFactory.Create(name, key))
{
configuration.Write(args => args.Key = $"{Convert.ToBase64String(key.Salt)}:" +
$"{Convert.ToBase64String(key.EncryptedKey)}:{Convert.ToBase64String(key.DecryptedKey)}");
string file = Path.Combine(environment.ContentRootPath, "Thumbnail.png");
using FileStream stream = File.OpenWrite(file);
imageWriter.Write(thumbnail, stream);
return true;
}
}
return default;
return false;
}
}
}