Skip to content

Commit a2161f9

Browse files
committedNov 21, 2022
Added initialize Account class instance from Base58 Secret Key. The secret key is the "private key" exported by wallets like phantom.
1 parent c164d5d commit a2161f9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎src/Solnet.Wallet/Account.cs

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Chaos.NaCl;
22
using Solnet.Wallet.Utilities;
3+
using System;
34
using System.Diagnostics;
45

56
namespace Solnet.Wallet
@@ -50,7 +51,23 @@ public Account(byte[] privateKey, byte[] publicKey)
5051
PrivateKey = new PrivateKey(privateKey);
5152
PublicKey = new PublicKey(publicKey);
5253
}
54+
/// <summary>
55+
/// Initialize an account with the passed secret key
56+
/// </summary>
57+
/// <param name="secretKey">The private key.</param>
58+
public static Account FromSecretKey(string secretKey)
59+
{
60+
var B58 = new Base58Encoder();
61+
byte[] skeyBytes = B58.DecodeData(secretKey);
62+
if (skeyBytes.Length != 64)
63+
{
64+
throw new ArgumentException("Not a secret key");
65+
}
5366

67+
Account acc = new Account(skeyBytes, skeyBytes.Slice(32, 64));
68+
69+
return acc;
70+
}
5471
/// <summary>
5572
/// Verify the signed message.
5673
/// </summary>

0 commit comments

Comments
 (0)