mirror of
https://github.com/status-im/nft-faucet.git
synced 2025-02-24 12:38:30 +00:00
40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
|
using Solnet.Wallet;
|
||
|
using Solnet.Wallet.Bip39;
|
||
|
|
||
|
namespace NftFaucetRadzen.Models;
|
||
|
|
||
|
public class SolanaKey
|
||
|
{
|
||
|
public string MnemonicPhrase { get; }
|
||
|
public string PrivateKey { get; }
|
||
|
public string Address { get; }
|
||
|
|
||
|
public SolanaKey(string mnemonicPhrase)
|
||
|
{
|
||
|
MnemonicPhrase = mnemonicPhrase ?? throw new ArgumentNullException(nameof(mnemonicPhrase));
|
||
|
PrivateKey = GetPrivateKeyFromMnemonicPhrase(mnemonicPhrase);
|
||
|
Address = GetAddressFromMnemonicPhrase(mnemonicPhrase);
|
||
|
}
|
||
|
|
||
|
public static SolanaKey GenerateNew()
|
||
|
{
|
||
|
var words = new Mnemonic(WordList.English, WordCount.Twelve).Words;
|
||
|
var mnemonicPhrase = string.Join(" ", words);
|
||
|
return new SolanaKey(mnemonicPhrase);
|
||
|
}
|
||
|
|
||
|
public static string GetPrivateKeyFromMnemonicPhrase(string mnemonicPhrase)
|
||
|
{
|
||
|
var mnemonic = new Mnemonic(mnemonicPhrase, WordList.English);
|
||
|
var wallet = new Wallet(mnemonic);
|
||
|
return wallet.Account.PrivateKey;
|
||
|
}
|
||
|
|
||
|
public static string GetAddressFromMnemonicPhrase(string mnemonicPhrase)
|
||
|
{
|
||
|
var mnemonic = new Mnemonic(mnemonicPhrase, WordList.English);
|
||
|
var wallet = new Wallet(mnemonic);
|
||
|
return wallet.Account.PublicKey.Key;
|
||
|
}
|
||
|
}
|