API Reference

PreRequisites

Get below information from TradeX tech team via an email to [email protected]

  1. Get Partner ID in development environment
  2. Get subdomain for the partner ID

Steps to Generate Iframe / Webview Url

The user will auto-login while opening the TradeX page on the Partner Application. We have to get Unique user IDs for each user to identify them. Below flow has to be invoked every time the partner application is opened or when the TradeX page on partner application is about to be loaded.

  1. Call the TradeX Auth Key generation API, this will return below fields

    1. auth_key
    2. public_key
  2. Use the below snippet to generate an encrypted query parameter for Iframe / Webview

    1. const payload = {
             partner_id: <One time partner Id shared by the tradeX team>,
             partner_user_id: <Unique identifer of the user in partner DB>,
             device_id: <a unique device id of the user>
         };
      const data = JSON.stringify( payload );
      const encrypted = crypto.publicEncrypt({
          key: <public_key from step 1>
       }, Buffer.from( data ) );
      const encryptedString = encodeURIComponent(encrypted.toString( 'base64’));
      
      import java.io.IOException;
      import java.net.URISyntaxException;
      import java.nio.file.Files;
      import java.nio.file.Paths;
      import java.security.*;
      import java.security.KeyFactory;
      import java.security.NoSuchAlgorithmException;
      import java.security.PrivateKey;
      import java.security.PublicKey;
      import java.security.interfaces.RSAPublicKey;
      import java.security.spec.InvalidKeySpecException;
      import java.security.spec.PKCS8EncodedKeySpec;
      import java.security.spec.X509EncodedKeySpec;
      import java.util.Base64;
      import javax.crypto.*;
      import java.nio.charset.StandardCharsets;
      
      
      
      
      class Main {
         public static void main(String[] args) throws InvalidKeySpecException, NoSuchAlgorithmException, IOException, URISyntaxException, BadPaddingException, InvalidKeyException, NoSuchPaddingException, IllegalBlockSizeException {
           
              //  String key = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA39wq9t6OPDd9Ynqoug0p\nmcCFvz9xQZ1AmCsFf5L9UAnXo3i9FThlfn9Ywd3Uwena4NhodNjtOQfSlbPJAa2Y\nF5osMrTOptcEBbSCum0bvn06Uh9mpfUpIzXAlo/hfgqc90xAxmAQmtdj5GMg8oje\nZ+I14gGSCKO4vpAbEPlZjTARMcR+PYx5/l1w78ee55TujzHCDfHJAZbEYfyC7euC\ncYjiRk/qJwvoJyMSVbIEFN3xvGieNusebpxjiPSRbYFF53Hb9pMH60qoJv2Z9DPD\ng8fitzq5JquE80uYT/OQVn3lPh7husJXD/nfpnspe7OpSU7HR0S8BnbVaGDWbK/U\n0QIDAQAB\n-----END PUBLIC KEY-----\n";
               String key = <public_key from step 1>
               String publicKeyContent = key.replaceAll("\\n", "").replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "");;
      
               KeyFactory kf = KeyFactory.getInstance("RSA");
      
      
      
              System.out.println(publicKeyContent);
              X509EncodedKeySpec keySpecX509 = new X509EncodedKeySpec(Base64.getDecoder().decode(publicKeyContent));
              RSAPublicKey pubKey = (RSAPublicKey) kf.generatePublic(keySpecX509);
              String secretMessage = "{\"partner_id\":<One time partner Id shared by the tradeX team>,\"partner_user_id\":\"[email protected]\",\"device_id\":\"B692AB-41E1-55CD-8314-A6063FFB290A\"}";
              
              Cipher encryptCipher = Cipher.getInstance("RSA");
              encryptCipher.init(Cipher.ENCRYPT_MODE, pubKey);
      
              byte[] secretMessageBytes = secretMessage.getBytes(StandardCharsets.UTF_8);
              byte[] encryptedMessageBytes = encryptCipher.doFinal(secretMessageBytes);
      
              String encodedMessage = Base64.getEncoder().encodeToString(encryptedMessageBytes);
      
              System.out.println(pubKey);
              System.out.println(encodedMessage);
              
          }
      }
      
  3. Open the webview or iframe using below URL format

    1. https://<subdomain>.tradexapp.co/Home/Markets?payload=<encryptedString from step 2>&auth_key=<auth_key from step 1>
      
  4. This URL will create a new user in the system or sign in an existing user based on the partner_user_idfield