[#60] Wallet tools in SDK
Some checks failed
DCO / DCO (pull_request) Successful in 21s
lint-build / dotnet8.0 (pull_request) Successful in 43s
lint-build / dotnet8.0 (push) Has been cancelled

Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
Pavel Gross 2025-04-11 15:52:31 +03:00
parent 42f4507638
commit 5f451c8818
14 changed files with 296 additions and 1 deletions

View file

@ -45,6 +45,7 @@
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="7.0.0" />
<PackageReference Include="System.Runtime.Caching" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.4" />
</ItemGroup>
<ItemGroup>

View file

@ -0,0 +1,31 @@
using System.Text.Json;
using System;
using FrostFS.SDK.Client.Wallets;
using FrostFS.SDK.Cryptography;
namespace FrostFS.SDK.Client;
public static class WalletTools
{
public static string GetWifFromWallet(string walletJsonText, byte[] password, int accountIndex = 0)
{
var wallet = JsonSerializer.Deserialize<Wallet>(walletJsonText) ?? throw new ArgumentException("Wrong wallet format");
if (wallet.Accounts == null || wallet.Accounts.Length < accountIndex + 1)
{
throw new ArgumentException("Wrong wallet content");
}
var encryptedKey = wallet.Accounts[accountIndex].Key;
if (string.IsNullOrEmpty(encryptedKey))
{
throw new ArgumentException("Cannot get encrypted WIF");
}
var privateKey = CryptoWallet.GetKeyFromEncodedWif(password, encryptedKey!);
var wif = privateKey.GetWIFFromPrivateKey();
return wif;
}
}

View file

@ -0,0 +1,24 @@
using System.Text.Json.Serialization;
namespace FrostFS.SDK.Client.Wallets;
public class Account
{
[JsonPropertyName("address")]
public string? Address { get; set; }
[JsonPropertyName("key")]
public string? Key { get; set; }
[JsonPropertyName("label")]
public string? Label { get; set; }
[JsonPropertyName("contract")]
public Contract? Contract { get; set; }
[JsonPropertyName("lock")]
public bool Lock { get; set; }
[JsonPropertyName("isDefault")]
public bool IsDefault { get; set; }
}

View file

@ -0,0 +1,15 @@
using System.Text.Json.Serialization;
namespace FrostFS.SDK.Client.Wallets;
public class Contract
{
[JsonPropertyName("script")]
public string? Script { get; set; }
[JsonPropertyName("parameters")]
public Parameter[]? Parameters { get; set; }
[JsonPropertyName("deployed")]
public bool Deployed { get; set; }
}

View file

@ -0,0 +1,6 @@
namespace FrostFS.SDK.Client.Wallets;
public class Extra
{
public string? Tokens { get; set; }
}

View file

@ -0,0 +1,12 @@
using System.Text.Json.Serialization;
namespace FrostFS.SDK.Client.Wallets;
public class Parameter
{
[JsonPropertyName("name")]
public string? Name { get; set; }
[JsonPropertyName("type")]
public string? Type { get; set; }
}

View file

@ -0,0 +1,15 @@
using System.Text.Json.Serialization;
namespace FrostFS.SDK.Client.Wallets;
public class ScryptValue
{
[JsonPropertyName("n")]
public int N { get; set; }
[JsonPropertyName("r")]
public int R { get; set; }
[JsonPropertyName("p")]
public int P { get; set; }
}

View file

@ -0,0 +1,18 @@
using System.Text.Json.Serialization;
namespace FrostFS.SDK.Client.Wallets;
public class Wallet
{
[JsonPropertyName("version")]
public string? Version { get; set; }
[JsonPropertyName("accounts")]
public Account[]? Accounts { get; set; }
[JsonPropertyName("scrypt")]
public ScryptValue? Scrypt { get; set; }
[JsonPropertyName("extra")]
public Extra? Extra { get; set; }
}