internal static ExportKeysResponse ExportKeys(ExportKeysRequest exportKeysRequest, IReadOnlyCollection <ISegWitAddress> addresses) { var header = new StringBuilder(); header.AppendLine($"Starting export from wallet {exportKeysRequest.WalletName}, network {C.Network.Name} on {DateTime.UtcNow} UTC."); var errors = new StringBuilder(); errors.AppendLine("Errors"); var success = new StringBuilder(); success.AppendLine("Exported Private Key (Hex); Unix Time UTC; IsChange; Address; Label:"); int errorCount = 0; int successCount = 0; try { header.AppendLine($"{addresses.Count} found in wallet."); var enc = new Bech32Encoder($"{C.Network.CoinTicker.ToLowerInvariant()}key"); foreach (var a in addresses) { try { var decryptedKey = VCL.DecryptWithPassphrase(exportKeysRequest.WalletPassphrase, a.GetEncryptedPrivateKey()); if (decryptedKey == null) { errorCount++; header.AppendLine( $"Address '{a.Address}' could not be decrpted with this passphrase."); } else { var privateKey = enc.Encode(0, decryptedKey); success.AppendLine($"{privateKey};{a.Address}"); successCount++; } } catch (Exception e) { header.AppendLine($"Exception processing Address '{a.Address}': {e.Message}"); } } header.AppendLine($"{errorCount} errors occured."); header.AppendLine($"{successCount} addresses with private keys successfully exported."); } catch (Exception e) { errors.AppendLine(e.Message); return(new ExportKeysResponse { Message = $"Export failed because an exception occured: {e.Message}" }); } return(new ExportKeysResponse { Message = $"{header}{Environment.NewLine}{success}{Environment.NewLine}{errors}{Environment.NewLine}" }); }
internal ExportKeysResponse ExportKeys(ExportKeysRequest exportKeysRequest) { // TODO //return ImportExportService.ExportKeys(exportKeysRequest, this.x1WalletFile.PubKeyHashAddresses.Values); return(null); }
public ExportKeysResponse ExportKeys(ExportKeysRequest importKeysRequest) { using var context = GetWalletContext(); return(context.WalletManager.ExportKeys(importKeysRequest)); }