[#60] Wallet tools in SDK
Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
42f4507638
commit
5f451c8818
14 changed files with 296 additions and 1 deletions
|
@ -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>
|
||||
|
|
31
src/FrostFS.SDK.Client/Tools/WalletTools.cs
Normal file
31
src/FrostFS.SDK.Client/Tools/WalletTools.cs
Normal 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;
|
||||
}
|
||||
}
|
24
src/FrostFS.SDK.Client/Wallets/Account.cs
Normal file
24
src/FrostFS.SDK.Client/Wallets/Account.cs
Normal 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; }
|
||||
}
|
15
src/FrostFS.SDK.Client/Wallets/Contract.cs
Normal file
15
src/FrostFS.SDK.Client/Wallets/Contract.cs
Normal 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; }
|
||||
}
|
6
src/FrostFS.SDK.Client/Wallets/Extra.cs
Normal file
6
src/FrostFS.SDK.Client/Wallets/Extra.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace FrostFS.SDK.Client.Wallets;
|
||||
|
||||
public class Extra
|
||||
{
|
||||
public string? Tokens { get; set; }
|
||||
}
|
12
src/FrostFS.SDK.Client/Wallets/Parameter.cs
Normal file
12
src/FrostFS.SDK.Client/Wallets/Parameter.cs
Normal 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; }
|
||||
}
|
15
src/FrostFS.SDK.Client/Wallets/ScryptValue.cs
Normal file
15
src/FrostFS.SDK.Client/Wallets/ScryptValue.cs
Normal 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; }
|
||||
}
|
18
src/FrostFS.SDK.Client/Wallets/Wallet.cs
Normal file
18
src/FrostFS.SDK.Client/Wallets/Wallet.cs
Normal 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; }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue