Esempio n. 1
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;
     }
 }
        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);
            }
        }