public static string GetAccountIdFromPrivateKey(string privateKey) { var pvtKey = Base58Encoding.DecodePrivateKey(privateKey); var kp = new Neo.Wallets.KeyPair(pvtKey); return(Base58Encoding.EncodeAccountId(kp.PublicKey.EncodePoint(false).Skip(1).ToArray())); }
private void OnCreateAccount(WalletKeyPair account) { byte[] decryptedPrivateKey = new byte[96]; Buffer.BlockCopy(account.PublicKey.EncodePoint(false), 1, decryptedPrivateKey, 0, 64); using (account.Decrypt()) { Buffer.BlockCopy(account.PrivateKey, 0, decryptedPrivateKey, 64, 32); } byte[] encryptedPrivateKey = EncryptPrivateKey(decryptedPrivateKey); Array.Clear(decryptedPrivateKey, 0, decryptedPrivateKey.Length); using (WalletDataContext ctx = new WalletDataContext(DbPath)) { Account db_account = ctx.Accounts.FirstOrDefault(p => p.PublicKeyHash.SequenceEqual(account.PublicKeyHash.ToArray())); if (db_account == null) { db_account = ctx.Accounts.Add(new Account { PrivateKeyEncrypted = encryptedPrivateKey, PublicKeyHash = account.PublicKeyHash.ToArray() }).Entity; } else { db_account.PrivateKeyEncrypted = encryptedPrivateKey; } ctx.SaveChanges(); } }
public override WalletKeyPair CreateKey(byte[] privateKey) { WalletKeyPair account = base.CreateKey(privateKey); OnCreateAccount(account); AddContract(WalletContract.CreateSignatureContract(account.PublicKey)); return(account); }
protected override IEnumerable <WalletKeyPair> LoadKeyPairs() { using (WalletDataContext ctx = new WalletDataContext(DbPath)) { foreach (byte[] encryptedPrivateKey in ctx.Accounts.Select(p => p.PrivateKeyEncrypted)) { byte[] decryptedPrivateKey = DecryptPrivateKey(encryptedPrivateKey); WalletKeyPair account = new WalletKeyPair(decryptedPrivateKey); Array.Clear(decryptedPrivateKey, 0, decryptedPrivateKey.Length); yield return(account); } } }
public abstract WalletAccount CreateAccount(Contract contract, KeyPair key = null);