internal string GetNewAddress(int[] SecretSalt, int[] SecretPW, int hdIndex, string currencySymbol, string firstaddress, bool DoSegwit)
        {
            try
            {
                ExtKey masterKey  = GetExtKey(SecretSalt, SecretPW);
                ExtKey masterKeyD = masterKey.Derive(GetCurrencyIndex("btc"), hardened: true);
                ExtKey key        = masterKeyD.Derive((uint)0);
                byte[] keybytes   = key.PrivateKey.ToBytes();
                Key    pkey       = new Key(keybytes, -1, false);
                var    address    = pkey.PubKey.GetAddress(GetBLKNetworkAlt("btc")).ToString();
                if (address != firstaddress)
                {
                    Sclear.EraseBytes(keybytes);
                    masterKey  = null;
                    masterKeyD = null;
                    key        = null;
                    pkey       = null;
                    return(null);
                }
                ExtKey masterKeyA = masterKey.Derive(GetCurrencyIndex(currencySymbol), hardened: true);
                key      = masterKeyA.Derive((uint)hdIndex);
                keybytes = key.PrivateKey.ToBytes();

                if (GetBLKNetworkAlt(currencySymbol) != null)
                {
                    BitfiWallet.AltCoinGen altCoinGen = new BitfiWallet.AltCoinGen(GetBLKNetworkAlt(currencySymbol));
                    address = altCoinGen.GetNewAddress(keybytes, DoSegwit);
                }
                else
                {
                    if (currencySymbol == "apl")
                    {
                        APLGen aPL = new APLGen();
                        address = aPL.GetPublicKey(keybytes);
                    }



                    if (currencySymbol == "xrp" && hdIndex == 0)
                    {
                        RipGen ripGen = new RipGen();
                        address = ripGen.GetAddress(keybytes);
                    }
                }

                Sclear.EraseBytes(keybytes);
                masterKey  = null;
                masterKeyD = null;
                masterKeyA = null;
                key        = null;
                pkey       = null;

                return(address);
            }
            catch
            {
                return(null);
            }
        }
        internal MsgTaskTransferResponse SignUserMsg(int[] SecretSalt, int[] SecretPW, BitfiWallet.NOXWS.NoxMsgProcess req)
        {
            MsgTaskTransferResponse msgTaskTransferResponse = new MsgTaskTransferResponse();

            try
            {
                byte[] Msg      = Convert.FromBase64String(req.Msg);
                byte[] keybytes = HDDerriveKey(SecretSalt, SecretPW, req.NoxAddress.HDIndex, req.BlkNet);

                if (req.BlkNet == "eth")
                {
                    EthECKey ekey = new EthECKey(keybytes, true);

                    string ethadr = ekey.GetPublicAddress();
                    if (ethadr != req.NoxAddress.BTCAddress)
                    {
                        msgTaskTransferResponse.Error = "Invalid information.";
                    }
                    else
                    {
                        EthereumLibrary.MsgSigning elib = new EthereumLibrary.MsgSigning();
                        msgTaskTransferResponse.MsgSig = elib.ETHMsgSign(Msg, ekey);
                    }
                }
                else
                {
                    BitfiWallet.AltCoinGen altCoinGen = new BitfiWallet.AltCoinGen(GetBLKNetworkAlt(req.BlkNet));
                    msgTaskTransferResponse.MsgSig = altCoinGen.AltMsgSign(keybytes, req.NoxAddress.BTCAddress, System.Text.Encoding.UTF8.GetString(Msg));
                }



                Sclear.EraseBytes(keybytes);
                return(msgTaskTransferResponse);
            }
            catch (Exception ex)
            {
                msgTaskTransferResponse.Error = ex.Message;
                return(msgTaskTransferResponse);
            }
        }
Ejemplo n.º 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;
            }     
        }
Ejemplo n.º 4
0
        internal List\\ GetReviewIndexes(BitfiWallet.SGADWS.NoxAddressReviewV3 noxAddressReviews, ExtKey masterKey)
        {
            List\\ noxAddresses = new List\\();

            foreach (var adrReview in noxAddressReviews.AdrReview)
            {
                string currencySymbol = adrReview.Blk;
                ExtKey ASmasterKey = masterKey.Derive(GetCurrencyIndex(currencySymbol), hardened: true);


                for (int i = 0; i \                {

                    string address = "";
                    ExtKey key = ASmasterKey.Derive((uint)i);
                    byte[] keybytes = key.PrivateKey.ToBytes();

                    if (GetBLKNetworkAlt(adrReview.Blk) != null)
                    {

                        foreach(var nadr in noxAddressReviews.Addresses)
                        {
                            if (nadr.BlkNet == adrReview.Blk && nadr.HDIndex == i)
                            {
                                BitfiWallet.AltCoinGen altCoinGen = new BitfiWallet.AltCoinGen(GetBLKNetworkAlt(adrReview.Blk));
                                address = altCoinGen.GetNewAddress(keybytes, nadr.DoSegwit);
                                break;
                            }
                        }


                    }
                    if (adrReview.Blk == "apl")
                    {
                        APLGen aPL = new APLGen();
                        address =  aPL.GetAccountID(keybytes);
                    }
                    if (adrReview.Blk == "neo")
                    {
                         var NEOkeypair = new KeyPair(keybytes);
                        address = NEOkeypair.address;
                        NEOkeypair.Dispose();
                    }
                    if (adrReview.Blk == "xmr")
                    {
                        MoneroWallet.Wallet wallet = MoneroWallet.Wallet.OpenWallet(keybytes);
                        address = wallet.Address;
                        wallet.Dispose();

                    }
                    if (adrReview.Blk == "eth")
                    {
                        EthECKey ETHkey = new EthECKey(keybytes, true);
                        address = ETHkey.GetPublicAddress();
                    }
                    if (adrReview.Blk == "xrp")
                    {
                        RipGen ripGen = new RipGen();
                        address = ripGen.GetAddress(keybytes);
                    }
                    Sclear.EraseBytes(keybytes);
                    key = null;

                    noxAddresses.Add(new BitfiWallet.NOXWS.NoxAddresses { BlkNet = currencySymbol, BTCAddress = address}

                    );

                }

            }
            masterKey = null;

            return noxAddresses;
        }