internal RipTaskTransferResponse Rip_Sign(int[] SecretSalt, int[] SecretPW, BitfiWallet.NOXWS.NoxTxnProcess tproc)
        {
            RipTaskTransferResponse taskTransferResponse = new RipTaskTransferResponse();

            byte[] keybytes = HDDerriveKey(SecretSalt, SecretPW, 0, "xrp");

            byte[] bts   = Convert.FromBase64String(tproc.MXTxn);
            string MXTxn = System.Text.Encoding.UTF8.GetString(bts);

            RipGen ripGen = new RipGen();

            string fromadr = ripGen.GetAddress(keybytes);

            if (fromadr != tproc.NoxAddress.BTCAddress)
            {
                Sclear.EraseBytes(keybytes);
                taskTransferResponse.Error = "Invalid information.";
                return(taskTransferResponse);
            }

            JsonSerializerSettings ser = new JsonSerializerSettings();

            ser.MissingMemberHandling  = MissingMemberHandling.Ignore;
            ser.NullValueHandling      = NullValueHandling.Ignore;
            ser.ObjectCreationHandling = ObjectCreationHandling.Auto;
            ser.TypeNameHandling       = TypeNameHandling.All;
            var data = JsonConvert.DeserializeObject <RipTxnModel>(MXTxn, ser);


            var chamount = Convert.ToDecimal(data.Amount) * 0.000001M;

            if (chamount > Convert.ToDecimal(tproc.Amount))
            {
                Sclear.EraseBytes(keybytes);
                taskTransferResponse.Error = "Error parsing amount.";
                return(taskTransferResponse);
            }
            if (data.Destination.ToUpper() != tproc.ToAddress.ToUpper())
            {
                Sclear.EraseBytes(keybytes);
                taskTransferResponse.Error = "Error parsing destination.";
                return(taskTransferResponse);
            }

            try
            {
                string txn = ripGen.CreateTxn(keybytes, MXTxn);

                Sclear.EraseBytes(keybytes);
                taskTransferResponse.TxnHex = txn;
                return(taskTransferResponse);
            }
            catch (Exception ex)
            {
                Sclear.EraseBytes(keybytes);
                taskTransferResponse.Error = ex.Message;
                return(taskTransferResponse);
            }
        }
        internal ETHTaskTransferResponse ETH_Sign(int[] SecretSalt, int[] SecretPW, BitfiWallet.NOXWS.NoxTxnProcess tproc)
        {
            ETHTaskTransferResponse taskTransferResponse = new ETHTaskTransferResponse();

            byte[] keybytes = HDDerriveKey(SecretSalt, SecretPW, 0, "eth");

            EthECKey key = new EthECKey(keybytes, true);

            Sclear.EraseBytes(keybytes);

            string ethadr = key.GetPublicAddress();

            if (ethadr != tproc.NoxAddress.BTCAddress)
            {
                taskTransferResponse.Error = "Invalid information.";
                return(taskTransferResponse);
            }


            //TO DO
            if (tproc.ETCToken != null)
            {
                var contractAddress = tproc.ETCToken.EnsureHexPrefix();
                var to       = tproc.ToAddress.EnsureHexPrefix();
                var amount   = NumUtils.Utils.ParseMoney(tproc.Amount, 18);
                var nonce    = System.Numerics.BigInteger.Parse(tproc.ETCNonce);
                var gasPrice = NumUtils.Utils.ParseMoney(tproc.FeeValue, 18);
                var gasLimit = new System.Numerics.BigInteger(Int64.Parse(tproc.ETCGasUsed));
                var tx       = new EthereumLibrary.Signer.Transaction(contractAddress, to, amount, nonce, gasPrice, gasLimit);
                tx.Sign(key);
                var signedHex = tx.ToHex();
                key = null;
                taskTransferResponse.TxnHex = signedHex;
                return(taskTransferResponse);
            }
            else
            {
                var to       = tproc.ToAddress.EnsureHexPrefix();
                var amount   = NumUtils.Utils.ParseMoney(tproc.Amount, 18);
                var nonce    = System.Numerics.BigInteger.Parse(tproc.ETCNonce);
                var gasPrice = NumUtils.Utils.ParseMoney(tproc.FeeValue, 18);
                var gasLimit = new System.Numerics.BigInteger(Int64.Parse(tproc.ETCGasUsed));

                var tx = new EthereumLibrary.Signer.Transaction(to, amount, nonce, gasPrice, gasLimit);
                tx.Sign(key);
                var signedHex = tx.ToHex();
                key = null;
                taskTransferResponse.TxnHex = signedHex;
                return(taskTransferResponse);
            }
        }
Example #3
0
        internal AltoCoinTaskTransferResponse Alt_Sign(int[] SecretSalt, int[] SecretPW, BitfiWallet.NOXWS.NoxTxnProcess tproc, string currencySymbol)
        {
            AltoCoinTaskTransferResponse taskTransferResponse = new AltoCoinTaskTransferResponse();
            ExtKey masterKey = GetExtKey(SecretSalt, SecretPW);
            masterKey = masterKey.Derive(GetCurrencyIndex(currencySymbol), hardened: true);

            var HDIndexes = tproc.HDIndexList;
            List\\ kbList = new List\\();
            for (int i = 0; i \            {
                int HDIndex = Convert.ToInt32(HDIndexes[i]);
                ExtKey key = masterKey.Derive((uint)HDIndex);
                kbList.Add(key.PrivateKey.ToBytes());
                key = null;
            }
            masterKey = null;
            BitfiWallet.AltCoinGen altCoinGen = new BitfiWallet.AltCoinGen(GetBLKNetworkAlt(currencySymbol));
            List\\ txnRaw = new List\\();
            foreach (var txnin in tproc.UnspentList)
            {
                BCUnspent bCUnspent = new BCUnspent();
                bCUnspent.Address = txnin.Address;
                bCUnspent.OutputN = txnin.OutputN;
                bCUnspent.TxHash = txnin.TxHash;
                bCUnspent.Amount = txnin.Amount;
                txnRaw.Add(bCUnspent);
            }
            try
            {
                var txn = altCoinGen.AltCoinSign(kbList, tproc.ToAddress, txnRaw, tproc.Amount, tproc.NoxAddress.BTCAddress, tproc.FeeTotal);
                if (txn.IsError != true)
                {

                    decimal FeeUSD = tproc.USDRate * txn.Fee;
                    taskTransferResponse.TxnHex = txn.TxnHex;
                    taskTransferResponse.FeeAmount = txn.Fee.ToString();
                    if (FeeUSD \>\ .0099M)
                    {
                        taskTransferResponse.FeeAmount = taskTransferResponse.FeeAmount + "|\>\" + FeeUSD.ToString("C2");
                    }

                    if (FeeUSD \>\ 4) taskTransferResponse.FeeWarning = "HIGH FEE ALERT!";
                    if (txn.Fee \>\ (Convert.ToDecimal(tproc.Amount) * .04M))
                    {
                        decimal feePer = (txn.Fee / Convert.ToDecimal(tproc.Amount)) * 100;
                        taskTransferResponse.FeeWarning = "CHECK FEE! CHARGE IS " + feePer.ToString("N2") + "% OF PAYMENT.";
                    }
                    if (string.IsNullOrEmpty(taskTransferResponse.FeeWarning))
                    {
                        taskTransferResponse.FeeAmount = "";
                    }
                    return taskTransferResponse;
                }
                else
                {
                    taskTransferResponse.Error = txn.ErrorMessage;
                    return taskTransferResponse;
                }
            }
            catch (Exception ex)
            {
                taskTransferResponse.Error = ex.Message;
                return taskTransferResponse;
            }     
        }
Example #4
0
 internal ApolloTaskTransferResponse APL_Sign(int[] SecretSalt, int[] SecretPW, BitfiWallet.NOXWS.NoxTxnProcess tproc)
 {
     ApolloTaskTransferResponse taskTransferResponse = new ApolloTaskTransferResponse();
     byte[] keybytes = HDDerriveKey(SecretSalt, SecretPW, tproc.NoxAddress.HDIndex, "apl");
     APLGen aPL = new APLGen();
     string fromadr = aPL.GetPublicKey(keybytes);
     if (fromadr != tproc.NoxAddress.BTCAddress)
     {
         Sclear.EraseBytes(keybytes);
         taskTransferResponse.Error = "Invalid information.";
         return taskTransferResponse;
     }
     try
     {
         string check = aPL.CheckTransactionError(tproc.MXTxn, tproc.ToAddress, tproc.Amount, tproc.FeeValue);
         if (!string.IsNullOrEmpty(check))
         {
             Sclear.EraseBytes(keybytes);
             taskTransferResponse.Error = check;
             return taskTransferResponse;
         }
         var signedtxn = aPL.SignTransaction(keybytes, tproc.MXTxn);
         Sclear.EraseBytes(keybytes);
         taskTransferResponse.TxnHex = signedtxn;
         return taskTransferResponse;
     }
     catch (Exception ex)
     {
         Sclear.EraseBytes(keybytes);
         taskTransferResponse.Error = ex.Message;
         return taskTransferResponse;
     }
 }