Exemplo n.º 1
0
        /// <summary>
        /// Adds the transaction.
        /// </summary>
        /// <returns>The transaction.</returns>
        /// <param name="identifier">Identifier.</param>
        /// <param name="password">Password.</param>
        /// <param name="transaction">Transaction.</param>
        public async Task AddTransaction(SecureString identifier, SecureString password, TransactionDto transaction)
        {
            if (identifier == null)
            {
                throw new ArgumentNullException(nameof(identifier));
            }

            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            using (var insecureIdentifier = identifier.Insecure())
            {
                var found = false;
                var data  = await vaultService.GetDataAsync(identifier, password, $"wallets/{insecureIdentifier.Value}/wallet");

                if (data.Data.TryGetValue("transactions", out object txs))
                {
                    foreach (JObject item in ((JArray)txs).Children().ToList())
                    {
                        var hash = item.GetValue("Hash");
                        found = hash.Value <string>().Equals(transaction.Hash);
                    }
                    if (!found)
                    {
                        ((JArray)txs).Add(JObject.FromObject(transaction));
                    }
                }
                else
                {
                    data.Data.Add("transactions", new List <TransactionDto> {
                        transaction
                    });
                }

                await vaultService.SaveDataAsync(identifier, password, $"wallets/{insecureIdentifier.Value}/wallet", data.Data);
            }
        }
Exemplo n.º 2
0
        public override async Task Execute()
        {
            var walletId   = walletService.NewID(16);
            var passphrase = walletService.Passphrase();
            var pkSk       = walletService.CreatePkSk();

            walletId.MakeReadOnly();
            passphrase.MakeReadOnly();

            try
            {
                await vaultService.CreateUserAsync(walletId, passphrase);

                // TODO: Add list for multiple store keys.
                //var dic = new Dictionary<string, object>
                //{
                //    { "storeKeys", new List<PkSkDto> { pkSk } }
                //};

                var dic = new Dictionary <string, object>
                {
                    { "storeKeys", pkSk }
                };

                await vaultService.SaveDataAsync(
                    walletId,
                    passphrase,
                    $"wallets/{walletId.ToUnSecureString()}/wallet",
                    dic);

                console.WriteLine($"Created Wallet {walletId.ToUnSecureString()} with password: {passphrase.ToUnSecureString()}");
            }
            catch (Exception)
            {
                console.WriteLine("Failed to create wallet. Is the vault unsealed?");
                throw;
            }
            finally
            {
                walletId.Dispose();
                passphrase.Dispose();
            }
        }