HMAC-SHA256 Authentication
Code examples for generating signatures to use with Trustsig API. Supports multiple languages and can be adapted for your backend immediately
JavaScript Runtime Environment
// ติดตั้ง crypto ด้วย: npm install crypto
const crypto = require('crypto');
function generateSignature(secretKey, method, fullUrl, body, timestamp) {
const bodyString = body ? JSON.stringify(body) : '';
const signatureContent = [timestamp, method, fullUrl, bodyString].join('|');
return crypto.createHmac('sha256', secretKey)
.update(signatureContent)
.digest('hex');
}
// ตัวอย่างการใช้งาน
const secretKey = 'YOUR_SECRET_KEY';
const method = 'GET';
const fullUrl = 'https://testnet.trustsig.xyz/v1/balance/query';
const body = '';
const timestamp = Date.now();
const signature = generateSignature(secretKey, method, fullUrl, body, timestamp);
console.log('Signature:', signature);
Install crypto with: npm install crypto