protected override IEnumerable <WalletKeyPairBase> LoadKeyPairs() { using (WalletDataContext ctx = new WalletDataContext(DbPath)) { foreach (Account item in ctx.Accounts.Select(p => p)) { if ((KeyType)item.nVersion == KeyType.Anonymous || (KeyType)item.nVersion == KeyType.Transparent) { byte[] decryptedPrivateKey = DecryptPrivateKey(item.PrivateKeyEncrypted); WalletKeyPair account = new WalletKeyPair(decryptedPrivateKey, (KeyType)item.nVersion); Array.Clear(decryptedPrivateKey, 0, decryptedPrivateKey.Length); yield return(account); } else if ((KeyType)item.nVersion == KeyType.Stealth) { byte[] decryptedPrivateKey = DecryptPrivateKey(item.PrivateKeyEncrypted); byte[] decryptedViewKey = DecryptPrivateKey(item.PrivateViewKeyEncrypted); StealthKeyPair account = new StealthKeyPair(decryptedPrivateKey, decryptedViewKey); Array.Clear(decryptedPrivateKey, 0, decryptedPrivateKey.Length); Array.Clear(decryptedViewKey, 0, decryptedViewKey.Length); yield return(account); } } } }
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(VerificationContract.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 override WalletKeyPair CreateKey(byte[] privateKey, KeyType nVersion = KeyType.Transparent) { if (nVersion == KeyType.Transparent) { WalletKeyPair account = base.CreateKey(privateKey, nVersion); OnCreateAccount(account); AddContract(VerificationContract.CreateSignatureContract(account.PublicKey)); return(account); } else if (nVersion == KeyType.Anonymous) { WalletKeyPair account = base.CreateKey(privateKey, nVersion); SpendingKey sKey; sKey = new SpendingKey(new UInt256(privateKey)); OnCreateAccount(account); AddContract(VerificationContract.CreateSignatureAnonymousContract(account.PublicKey, sKey.address())); return(account); } else { return(null); } }