Signature Code Examples
HMAC-SHA256 Authentication
Code examples for generating signatures to use with Trustsig API. Supports multiple languages and can be adapted for your backend immediately
💻
Select Programming Language
signature.example.selectLanguageDesc
⬢
Node.js Implementation
JavaScript Runtime Environment
v18+
generateSignature.js
// ติดตั้ง 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);
Installation Note
Install crypto with: npm install crypto
Usage Instructions
- 1Replace 'YOUR_SECRET_KEY' with your Secret Key
- 2Modify method, URL and body according to your API usage
- 3Use the generated signature in the 'X-Signature' header of HTTP request