예제 #1
0
        CreateWallet(PrivateKeys privateKeys)
        {
            string walletFilename = GetNewWalletName();
            string walletPassword = GetNewWalletPassword();

            return(WalletBackend.NewWallet(walletFilename, walletPassword));
        }
예제 #2
0
        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));
            }
        }
예제 #3
0
        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;
        }
예제 #4
0
        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));
        }
예제 #5
0
        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);
예제 #6
0
        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();
            }
        }
예제 #7
0
        /// <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);
        }
예제 #8
0
 /* 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
         )
 {
 }
예제 #9
0
파일: UserState.cs 프로젝트: eXcomm/otr-1
 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()));
 }
예제 #11
0
        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();
        }
예제 #12
0
 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()
     });
 }
예제 #13
0
        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!"
                          );
            }
            }
        }
예제 #14
0
        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);
            }));
        }
예제 #15
0
 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));
     }
 }
예제 #16
0
        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);
        }
예제 #17
0
        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();
        }
예제 #18
0
 /// <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));
 }
예제 #19
0
 public void AddKey(string key, Guid id)
 {
     PrivateKeys.Add(new KeyValuePair <string, Guid>(key, id));
     Update();
 }
 public void AddKey(string privateKey)
 {
     PrivateKeys.Add(privateKey);
 }
예제 #21
0
        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;
        }