Pular para o conteúdo principal

Assinatura das chamadas

Toda chamada da Qeizzy para o gateway, exceto GET /v1/manifest, é assinada com HMAC-SHA256 usando o Client Secret. O segredo nunca viaja.

Cabeçalhos​

CabeçalhoConteúdo
x-qeizzy-client-idO Client ID
x-qeizzy-timestampSegundos desde 1970 (Unix)
x-qeizzy-nonceCódigo único da chamada, 16 a 64 caracteres A-Z a-z 0-9 _ -
x-qeizzy-signaturev1= seguido do HMAC-SHA256 em hexadecimal minúsculo

Texto assinado​

Cinco linhas, separadas por \n, sem quebra no final:

MÉTODO
/caminho/completo?com=consulta
timestamp
nonce
sha256 do corpo em hexadecimal
  • MÉTODO em maiúsculas (GET, POST).
  • Caminho completo no seu domínio, incluindo o caminho da URL que o lojista informou. Para a URL https://gw.com/qeizzy, criar cobrança assina /qeizzy/v1/charges.
  • Corpo exatamente como recebido (os bytes). Em GET, o hash do texto vazio: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.

Como conferir​

  1. O x-qeizzy-client-id é o da loja.
  2. O x-qeizzy-timestamp está a no máximo 5 minutos do seu relógio.
  3. O x-qeizzy-nonce não foi usado nos últimos 5 minutos (guarde-os por esse tempo e recuse repetidos).
  4. O HMAC calculado bate com o recebido, comparado em tempo constante.

Se algo falhar, responda 401 com { "code": "signature_invalid" }.

Valores de teste​

Use estes valores para conferir a sua implementação. Eles foram gerados com o mesmo código que a Qeizzy usa.

  • Client ID: client_demo
  • Client Secret: segredo-de-exemplo-nao-use
  • Timestamp: 1796126400

POST /qeizzy/v1/charges​

Corpo (uma linha, exatamente assim):

{"chargeId":"pi_test_0001","orderId":"order_0001","amount":{"valueInCents":4990,"currency":"BRL"},"method":"PIX","description":"Pedido 1042","payer":{"name":"Ana","email":"[email protected]"},"returnUrl":"https://loja.exemplo.com/pedido/order_0001","notifyUrl":"https://p-api.qeizzy.com/api/payment/webhook/bridge/pi_test_0001?t=abc"}

Texto assinado:

POST
/qeizzy/v1/charges
1796126400
0123456789abcdef0123456789abcdef
3cd1b91eb82b2098863f2eb3de558e50160d97919d712336010f1f586c9ce12a

Assinatura esperada:

x-qeizzy-signature: v1=0995dea14a2402dbbba21f8682797aacd75a2b4a3f90cdd5875fd939ddb7e5c9

GET /qeizzy/v1/charges/pi_test_0001​

Nonce fedcba9876543210fedcba9876543210, corpo vazio:

x-qeizzy-signature: v1=14b3f230a063c38576fcee4a300c8f89e3fdca73d5928a9b69442e22f1aa2f31

Exemplos de conferência​

Node.js​

import { createHash, createHmac, timingSafeEqual } from 'node:crypto';

export function verify({ headers, method, path, body, clientId, clientSecret, seenNonces }) {
if (headers['x-qeizzy-client-id'] !== clientId) return false;
const timestamp = String(headers['x-qeizzy-timestamp'] || '');
const nonce = String(headers['x-qeizzy-nonce'] || '');
if (!/^\d{9,12}$/.test(timestamp) || Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
if (!/^[A-Za-z0-9_-]{16,64}$/.test(nonce) || seenNonces.has(nonce)) return false;
const given = String(headers['x-qeizzy-signature'] || '').replace(/^v1=/, '');
if (!/^[a-f0-9]{64}$/.test(given)) return false;
const base = [method.toUpperCase(), path, timestamp, nonce, createHash('sha256').update(body).digest('hex')].join('\n');
const expected = createHmac('sha256', clientSecret).update(base).digest();
const received = Buffer.from(given, 'hex');
if (expected.length !== received.length || !timingSafeEqual(expected, received)) return false;
seenNonces.set(nonce, Date.now());
return true;
}

PHP​

function qeizzy_verify(array $headers, string $method, string $path, string $body, string $clientId, string $clientSecret): bool {
if (($headers['x-qeizzy-client-id'] ?? '') !== $clientId) return false;
$timestamp = (string) ($headers['x-qeizzy-timestamp'] ?? '');
$nonce = (string) ($headers['x-qeizzy-nonce'] ?? '');
if (!preg_match('/^\d{9,12}$/', $timestamp) || abs(time() - (int) $timestamp) > 300) return false;
if (!preg_match('/^[A-Za-z0-9_-]{16,64}$/', $nonce)) return false; // e recuse nonces repetidos
$given = preg_replace('/^v1=/', '', (string) ($headers['x-qeizzy-signature'] ?? ''));
$base = strtoupper($method) . "\n" . $path . "\n" . $timestamp . "\n" . $nonce . "\n" . hash('sha256', $body);
return hash_equals(hash_hmac('sha256', $base, $clientSecret), $given);
}