Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs
    1. Home
    2. srikanth yarra
    3. Posts
    S
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Posts made by srikanth yarra

    • RE: Connect/Login using TOTP

      @amrutjk public class Totp : Otp
      {
      private const long unixEpochTicks = 621355968000000000L;

          private const long ticksToSeconds = 10000000L;
      
          private readonly int step;
          private readonly int totpSize;
          private readonly TimeCorrection correctedTime;
      
          public Totp(byte[] secretKey, int step = 30, OtpHashMode mode = OtpHashMode.Sha1, int totpSize = 6, TimeCorrection timeCorrection = null)
              : base(secretKey, mode)
          {
              VerifyParameters(step, totpSize);
      
              this.step = step;
              this.totpSize = totpSize;
      
              // we never null check the corrected time object.  Since it's readonly, we'll ensure that it isn't null here and provide neatral functionality in this case.
              correctedTime = timeCorrection ?? TimeCorrection.UncorrectedInstance;
          }
      
          public Totp(IKeyProvider key, int step = 30, OtpHashMode mode = OtpHashMode.Sha1, int totpSize = 6, TimeCorrection timeCorrection = null)
              : base(key, mode)
          {
              VerifyParameters(step, totpSize);
      
              this.step = step;
              this.totpSize = totpSize;
      
              // we never null check the corrected time object.  Since it's readonly, we'll ensure that it isn't null here and provide neatral functionality in this case.
              correctedTime = timeCorrection ?? TimeCorrection.UncorrectedInstance;
          }
      
          private static void VerifyParameters(int step, int totpSize)
          {
              if (!(step > 0))
              {
                  throw new ArgumentOutOfRangeException(nameof(step));
              }
      
              if (!(totpSize > 0))
              {
                  throw new ArgumentOutOfRangeException(nameof(totpSize));
              }
      
              if (!(totpSize <= 10))
              {
                  throw new ArgumentOutOfRangeException(nameof(totpSize));
              }
          }
      
          public string ComputeTotp(DateTime timestamp)
          {
              return ComputeTotpFromSpecificTime(correctedTime.GetCorrectedTime(timestamp));
          }
      
          public string ComputeTotp()
          {
              return ComputeTotpFromSpecificTime(correctedTime.CorrectedUtcNow);
          }
      
          private string ComputeTotpFromSpecificTime(DateTime timestamp)
          {
              long window = CalculateTimeStepFromTimestamp(timestamp);
              return Compute(window, hashMode);
          }
      
          public bool VerifyTotp(string totp, out long timeStepMatched, VerificationWindow window = null)
          {
              return VerifyTotpForSpecificTime(correctedTime.CorrectedUtcNow, totp, window, out timeStepMatched);
          }
      
          public bool VerifyTotp(DateTime timestamp, string totp, out long timeStepMatched, VerificationWindow window = null)
          {
              return VerifyTotpForSpecificTime(correctedTime.GetCorrectedTime(timestamp), totp, window, out timeStepMatched);
          }
      
          private bool VerifyTotpForSpecificTime(DateTime timestamp, string totp, VerificationWindow window, out long timeStepMatched)
          {
              long initialStep = CalculateTimeStepFromTimestamp(timestamp);
              return Verify(initialStep, totp, out timeStepMatched, window);
          }
      
          private long CalculateTimeStepFromTimestamp(DateTime timestamp)
          {
              long unixTimestamp = (timestamp.Ticks - unixEpochTicks) / ticksToSeconds;
              long window = unixTimestamp / step;
              return window;
          }
      
          public int RemainingSeconds()
          {
              return RemainingSecondsForSpecificTime(correctedTime.CorrectedUtcNow);
          }
      
          public int RemainingSeconds(DateTime timestamp)
          {
              return RemainingSecondsForSpecificTime(correctedTime.GetCorrectedTime(timestamp));
          }
      
          private int RemainingSecondsForSpecificTime(DateTime timestamp)
          {
              return step - (int)(((timestamp.Ticks - unixEpochTicks) / ticksToSeconds) % step);
          }
      
          protected override string Compute(long counter, OtpHashMode mode)
          {
              byte[] data = KeyUtilities.GetBigEndianBytes(counter);
              long otp = CalculateOtp(data, mode);
              return Digits(otp, totpSize);
          }
      }
      
      posted in C#/.Net SDK
      S
      srikanth yarra
    • RE: Connect/Login using TOTP

      @amrutjk

      public static string GetTOTP(string secretKey, int step = 30, OtpHashMode mode = OtpHashMode.Sha1, int length = 6)
      {
      Totp otpCalc = new(Base32Encoding.ToBytes(secretKey), step, mode, length);
      int rmngTime = otpCalc.RemainingSeconds() - 1;
      if (rmngTime < 5)
      {
      Thread.Sleep(rmngTime * 1000);
      }
      return otpCalc.ComputeTotp();
      }

      posted in C#/.Net SDK
      S
      srikanth yarra
    • RE: Error while placing order- TPIN is not validated - AB4013

      @admin Thanks!!, i found this post !!

      posted in C#/.Net SDK
      S
      srikanth yarra
    • Error while placing order- TPIN is not validated - AB4013

      Please help, i have generated the tokens still i get below. could not find any docuemntation for this error code

      {"message":"TPIN is not validated","errorcode":"AB4013","status":false,"data":null}

      posted in C#/.Net SDK
      S
      srikanth yarra
    • RE: unable to generate tokens

      @admin yes thank you, yea its working for me now

      posted in Bugs
      S
      srikanth yarra
    • unable to generate tokens

      Is anyone else facing same issue today?

      Response Status : 200
      Response String trade : {"message":"Something Went Wrong, Please Try After Sometime","errorcode":"AB1004","status":false,"data":null}

      posted in Bugs
      S
      srikanth yarra