To ensure the security and integrity of your API requests to Tylt, each payload must be signed using your API Secret Key. This process generates a unique signature that verifies the authenticity of the request.
Signing a Request
The following steps outline how to sign your API requests:
Retrieve Your API Keys
You need your API Key and API Secret Key, which should be stored securely. Ensure these keys are kept confidential and are not exposed in client-side code.
Generate the Signature
You will create a signature using HMAC SHA-256 encryption. This signature will be included in the headers of your API requests.
Example Codes
Here’s how you can sign requests using different programming languages:
// Common function to create HMAC SHA-256 signatureconstcreateSignature=(secret,data)=>{returncrypto.createHmac('sha256',secret).update(data).digest('hex');};
constaxios=require('axios');constcrypto=require('crypto');// Replace with your API Key and SecretconstapiKey='your-api-key';constapiSecret='your-api-secret';// Function to send a POST requestconstsendPostRequest=async(url,body)=>{constraw=JSON.stringify(body);constsignature=createSignature(apiSecret,raw);constheaders={"X-TLP-APIKEY":apiKey,"X-TLP-SIGNATURE":signature};constresponse=awaitaxios.post(url,body,{headers});returnresponse.data;};// Function to send a GET requestconstsendGetRequest=async(url,params)=>{constraw=newURLSearchParams(params).toString();constsignature=createSignature(apiSecret,JSON.stringify(params));constheaders={"X-TLP-APIKEY":apiKey,"X-TLP-SIGNATURE":signature};constresponse=awaitaxios.get(`${url}?${raw}`,{headers});returnresponse.data;};
By following these steps and using the provided code examples, you can securely sign your API requests to Tylt, ensuring the integrity and authenticity of your transactions.
Important Considerations
Keep Your Keys Secure: Always use environment variables or secure storage for sensitive information like your API Secret Key.
Regenerate Keys if Compromised: If your API keys are exposed or compromised, regenerate them immediately and update your secure storage.