CreateWallet(PrivateKeys privateKeys) { string walletFilename = GetNewWalletName(); string walletPassword = GetNewWalletPassword(); return(WalletBackend.NewWallet(walletFilename, walletPassword)); }
public async Task RemoveAddressAsync(Address address) { if (IsLocked) { throw new LockedException(); } if (Addresses.Contains(address)) { if (PrivateKeys.Contains(address)) { await privateKeyLock.WaitAsync(); try { PrivateKeys.Remove(address); } finally { privateKeyLock.Release(); } } if (PublicAddresses.Contains(address)) { PublicAddresses.Remove(address); } await SaveAsync(); } else { throw new OperationException(String.Format("Your wallet doesn't contain the address {0}", address)); } }
public void GetKeysForShare(string shareName, out string access_id, out string secret_key) { PrivateKeys pkeys = new PrivateKeys(ini.Application, shareName); access_id = pkeys.AccessId; secret_key = pkeys.SecretKey; }
NewWallet(string filename, string password, PrivateKeys privateKeys) { if (!KeyOps.IsValidKey(privateKeys.spendKey) || !KeyOps.IsValidKey(privateKeys.viewKey)) { return(Either.Left <Error, WalletBackend>( Error.InvalidPrivateKey() )); } if (File.Exists(filename)) { return(Either.Left <Error, WalletBackend>( Error.FileAlreadyExists() )); } /* Create the wallet instance */ WalletBackend wallet = new WalletBackend( filename, password, privateKeys ); /* Save it */ wallet.Save(); /* Return it */ return(Either.Right <Error, WalletBackend>(wallet)); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var result = new List <ValidationResult>(); var sequenceService = (ISequenceService)validationContext.GetService(typeof(ISequenceService)); if (PrivateKeys == null || !PrivateKeys.Any()) { result.Add(new ValidationResult( $"{nameof(PrivateKeys)} array can not be empty", new[] { nameof(PrivateKeys) })); } var num = 0; foreach (var key in PrivateKeys) { if (!sequenceService.IsValidPrivateKey(key)) { result.Add(new ValidationResult( $"{nameof(PrivateKeys)}.[{num}] is not a valid", new[] { nameof(PrivateKeys) })); } num++; } if (Tx == null && Coins == null) { try { (Tx, Coins) = Serializer.ToObject <(Transaction, ICoin[])>(TransactionContext);
async Task LockAsync(byte[] passphrase) { await lockLock.WaitAsync(); try { if (IsLocked) { throw new OperationException("Wallet is already locked"); } await EncryptAsync(passphrase); Array.Clear(EncryptionKey, 0, EncryptionKey.Length); EncryptionKey = new byte[] { }; await privateKeyLock.WaitAsync(); try { PrivateKeys.Clear(); // TODO: Is this safe? } finally { privateKeyLock.Release(); } LockTimer.Stop(); IsLocked = true; DidLock(this, new EventArgs()); } finally { lockLock.Release(); } }
/// <summary> /// Adds a private key to be managed by the wallet and sign transactions. /// </summary> /// <param name="privateKey">The private key to be stored by the wallet.</param> /// <returns>The address derived from the <paramref name="privateKey" /></returns> public string AddRawKey(string privateKey) { string address = GetAddress(privateKey); PrivateKeys.Add(address.ToLower(), privateKey); return(address); }
/* Makes a new wallet with the given private keys */ private WalletBackend(string filename, string password, PrivateKeys privateKeys) : this( filename, password, privateKeys.spendKey, privateKeys.viewKey, KeyOps.PrivateKeyToPublicKey(privateKeys.spendKey), KeyOps.PrivateKeyToPublicKey(privateKeys.viewKey), false ) { }
internal UserState() { ConnectionContexts = new ConnectionContexts(); PrivateKeys = new PrivateKeys(); InstanceTags = new InstanceTags(); PendingPrivateKey = null; TimerRunning = 0; }
internal void Save() { if (!Directory.Exists(WalletDir)) { Directory.CreateDirectory(WalletDir); } using (var fs = File.Open(WalletFile(), FileMode.Create)) { Wallet.Save(fs); } File.WriteAllText(PrivateKeyFile(), string.Join(",", PrivateKeys.AsEnumerable())); }
public void AddShareS3(string shareName, string s3bucket, string cacheDir, string access_id, string secret_key) { var section = ShareSection(shareName); ini.SetParam(section, "shareName", shareName); ini.SetParam(section, "s3bucket", s3bucket); ini.SetParam(section, "cacheDirectory", cacheDir); PrivateKeys pkeys = new PrivateKeys(ini.Application, shareName); pkeys.AccessId = access_id; pkeys.SecretKey = secret_key; pkeys.SaveConfig(); }
internal WalletFileInfoViewModel Save() { if (!Directory.Exists(WalletDir)) { Directory.CreateDirectory(WalletDir); } using (var fs = File.Open(WalletFile(), FileMode.Create)) { Wallet.Save(fs); } File.WriteAllText(PrivateKeyFile(), string.Join(",", PrivateKeys.AsEnumerable())); return(new WalletFileInfoViewModel { WalletFile = WalletFile(), PrivateKeyFile = PrivateKeyFile() }); }
HandleAction(LaunchAction action) { switch (action) { case LaunchAction.Open: { return(OpenWallet()); } case LaunchAction.Create: { return(CreateWallet()); } case LaunchAction.SeedRestore: { /* We can create a wallet directly from a seed - but * we'd rather alert the user whenever a single part of * the input is incorrect, rather than getting them to * enter the walletname, walletpass, and seed, and then * alerting one bit is wrong */ PrivateKeys keys = GetPrivateKeysFromSeed(); return(CreateWallet(keys)); } case LaunchAction.KeyRestore: { PrivateKeys keys = GetPrivateKeys(); return(CreateWallet(keys)); } case LaunchAction.ViewWallet: { PrivateKey privateViewKey = GetPrivateKey("Private view key: "); string address = GetAddress(); return(CreateWallet(privateViewKey, address)); } default: { throw new ArgumentException( "Programmer error: Unhandled action!" ); } } }
NewWallet(string filename, string password, string mnemonicSeed) { /* Derive the mnemonic into a private spend key if possible */ return(Mnemonics.MnemonicToPrivateKey(mnemonicSeed) .Fmap(privateSpendKey => { /* Derive the private view key from the private spend key */ var privateKeys = new PrivateKeys( privateSpendKey, KeyOps.GenerateDeterministicKeys(privateSpendKey).privateKey ); /* Try and create the new wallet from the private keys */ return NewWallet(filename, password, privateKeys); })); }
public async Task HideAddressAsync(Address address) { if (IsLocked) { throw new LockedException(); } if (PrivateKeys.Contains(address) && PublicAddresses.Contains(address)) { PublicAddresses.Remove(address); await SaveAsync(); } else { // TODO: Tailor this message for both the key not being present and the address already being private throw new OperationException(String.Format("Address '{0}' isnt public", address)); } }
public async Task <Transaction> CreateTransactionAsync(Dictionary <Address, Money> destinations, Address changeAddress = null) { Money change; List <Transaction.Output> inpoints = CoinPicker.SelectInpoints(await GetSpendableOutputsAsync(), destinations, out change); var destinationsWithChange = new Dictionary <Address, Money>(destinations); if (change > new Money(0, "BTC")) { changeAddress = changeAddress ?? (await GenerateAddressAsync("Change")).Address; destinationsWithChange.Add(changeAddress, change); } Transaction tx = Transaction.Create(inpoints, destinationsWithChange, PrivateKeys.ToDictionary(k => k.Address, k => k.PrivateKey)); if (!tx.IncludesStandardFee) { throw new OperationException("Transaction generated without proper fee!"); } return(tx); }
public async Task ImportKeyAsync(PrivateKeyDetails key, bool isPublic = true) { if (IsLocked) { throw new LockedException(); } if (isPublic) { await ImportReadOnlyAddressAsync(key); } await privateKeyLock.WaitAsync(); try { PrivateKeys.Add(key); } finally { privateKeyLock.Release(); } await SaveAsync(); }
/// <summary> /// Check if this address is managed by this wallet. /// </summary> /// <param name="address">The address. Value returned by <see cref="SimpleWallet.AddRawKey" />.</param> /// <returns><see langword="true" /> if the address is managed by this wallter, <see langword="false" /> if not.</returns> public bool CanSign(string address) { return(PrivateKeys.ContainsKey(address)); }
public void AddKey(string key, Guid id) { PrivateKeys.Add(new KeyValuePair <string, Guid>(key, id)); Update(); }
public void AddKey(string privateKey) { PrivateKeys.Add(privateKey); }
private static PrivateKeys GetPrivateKeys(privkeys keys) { var privateKeys = new PrivateKeys(); foreach (account account in keys.account) { var privateKey = new PrivateKey(account.private_key.dsa.GetDSAParameters(true)); privateKey.AccountName = account.name; privateKey.Protocol = account.protocol; privateKeys.Add(privateKey); } return privateKeys; }