HMAC Signature Verification

Verify the X-Tente-Signature header in incoming webhook payloads to validate origin authenticity and prevent spoofing.

💡
Signature Verification Formula:

signature = hash_hmac('sha512', raw_request_body, YOUR_WEBHOOK_SECRET)

Implementation Examples

PHP (Laravel / Native)

// In your Webhook Controller
$rawBody = $request->getContent(); // Raw unparsed request body
$signature = $request->header('X-Tente-Signature');
$secret = env('TENTE_WEBHOOK_SECRET');

$computed = hash_hmac('sha512', $rawBody, $secret);

if (!hash_equals($computed, (string) $signature)) {
    return response()->json(['message' => 'Invalid signature'], 401);
}

// Signature is authentic - process deposit / order
$event = $request->all();

Node.js (Express)

const crypto = require('crypto');

app.post('/webhook/tente', express.raw({ type: 'application/json' }), (req, res) => {
    const signature = req.headers['x-tente-signature'];
    const secret = process.env.TENTE_WEBHOOK_SECRET;

    const computed = crypto
        .createHmac('sha512', secret)
        .update(req.body)
        .digest('hex');

    if (computed !== signature) {
        return res.status(401).send('Unauthorized: Invalid signature');
    }

    const event = JSON.parse(req.body.toString());
    // Process verified event...
    res.sendStatus(200);
});

Python (Flask / FastAPI)

import hmac
import hashlib
import os

@app.route('/webhook/tente', methods=['POST'])
def handle_webhook():
    signature = request.headers.get('X-Tente-Signature')
    secret = os.environ.get('TENTE_WEBHOOK_SECRET')
    raw_body = request.get_data()

    computed = hmac.new(secret.encode('utf-8'), raw_body, hashlib.sha512).hexdigest()

    if not hmac.compare_digest(computed, signature or ''):
        return {'message': 'Invalid signature'}, 401

    payload = request.get_json()
    # Process verified event...
    return {'status': 'success'}, 200