Skip to content

Request signing ​

Every request carries four headers:

HeaderDescription
X-App-IdApp id (app_no), issued by EasyPay
X-TimestampCurrent Unix time in seconds. Rejected if more than 300 s from server time
X-NonceRandom string, 16–64 chars of [A-Za-z0-9_-]. Must not repeat for the same App within 15 minutes
X-SignatureThe signature, lower-case hex

Algorithm ​

body_hash      = hex( SHA256( raw request body bytes ) )
string_to_sign = METHOD + "\n" + PATH + "\n" + TIMESTAMP + "\n" + NONCE + "\n" + body_hash
signature      = hex( HMAC-SHA256( app_secret, string_to_sign ) )
  • METHOD is always POST; PATH is the URL path without host or query, e.g. /api/v1/payout/create.
  • Hash the exact bytes you send: serialise the request object once, hash those bytes, put the same bytes in the HTTP body. Do not serialise twice and do not let your HTTP library rewrite the body (pretty-printing, re-ordering fields, a BOM or gzip all break verification). Nested JSON, field order and whitespace are otherwise irrelevant: the server does no canonicalisation, it only looks at bytes.
  • Your source IP must be in the merchant's IP whitelist when one is configured (no whitelist means no restriction). The whitelist is checked before the signature; a miss is 403 IP_NOT_ALLOWED.

Any verification failure is 401 INVALID_SIGNATURE; the server does not disclose whether the timestamp, nonce or signature was at fault.

Test vector ​

app_secret = sk_test_secret
method     = POST
path       = /api/v1/payout/create
timestamp  = 1760400000
nonce      = n0nce-n0nce-n0nce
body       = {"reference_id":"ORD-1","amount":"50.00","currency":"BRL","payment_method":"PIX"}

Expected intermediate value and signature:

body_hash = b008e59b28ec5580d090a9b4c8f4523085172e060234041a810c866356ba1d63
signature = 39fc969d9678d0dba928c7a2a241e1082b431ed8e54b53232ba1621b4c170a0d

body_hash differs → you are not hashing the body bytes themselves (typical causes: a trailing newline, a different JSON serialiser). body_hash matches but signature differs → check the order of the five parts and the \n separator, upper-case METHOD, and that PATH has no host.

Examples ​

go
func sign(secret, method, path, ts, nonce string, body []byte) string {
	sum := sha256.Sum256(body)
	s := strings.Join([]string{strings.ToUpper(method), path, ts, nonce, hex.EncodeToString(sum[:])}, "\n")
	mac := hmac.New(sha256.New, []byte(secret))
	mac.Write([]byte(s))
	return hex.EncodeToString(mac.Sum(nil))
}
python
import hashlib, hmac, json, time, secrets, requests

def sign(secret, method, path, ts, nonce, body: bytes) -> str:
    body_hash = hashlib.sha256(body).hexdigest()
    s = "\n".join([method.upper(), path, ts, nonce, body_hash])
    return hmac.new(secret.encode(), s.encode(), hashlib.sha256).hexdigest()

body = json.dumps(payload, separators=(",", ":"), ensure_ascii=False).encode("utf-8")  # serialise once
ts, nonce = str(int(time.time())), secrets.token_hex(16)
headers = {
    "Content-Type": "application/json; charset=utf-8",
    "X-App-Id": APP_ID, "X-Timestamp": ts, "X-Nonce": nonce,
    "X-Signature": sign(APP_SECRET, "POST", "/api/v1/payout/create", ts, nonce, body),
}
r = requests.post(BASE + "/api/v1/payout/create", data=body, headers=headers)  # data= sends the raw bytes
js
const crypto = require('crypto');

function sign(secret, method, path, ts, nonce, body /* Buffer */) {
  const bodyHash = crypto.createHash('sha256').update(body).digest('hex');
  const sts = [method.toUpperCase(), path, ts, nonce, bodyHash].join('\n');
  return crypto.createHmac('sha256', secret).update(sts).digest('hex');
}

const body = Buffer.from(JSON.stringify(payload), 'utf8'); // serialise once
const ts = String(Math.floor(Date.now() / 1000));
const nonce = crypto.randomBytes(16).toString('hex');
await fetch(BASE + '/api/v1/payout/create', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json; charset=utf-8',
    'X-App-Id': APP_ID, 'X-Timestamp': ts, 'X-Nonce': nonce,
    'X-Signature': sign(APP_SECRET, 'POST', '/api/v1/payout/create', ts, nonce, body),
  },
  body, // the same bytes
});
php
function sign(string $secret, string $method, string $path, string $ts, string $nonce, string $body): string {
    $sts = implode("\n", [strtoupper($method), $path, $ts, $nonce, hash('sha256', $body)]);
    return hash_hmac('sha256', $sts, $secret);
}

$body  = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); // serialise once
$ts    = (string) time();
$nonce = bin2hex(random_bytes(16));
$headers = [
    'Content-Type: application/json; charset=utf-8',
    'X-App-Id: ' . $APP_ID, 'X-Timestamp: ' . $ts, 'X-Nonce: ' . $nonce,
    'X-Signature: ' . sign($APP_SECRET, 'POST', '/api/v1/payout/create', $ts, $nonce, $body),
];
// curl: CURLOPT_POSTFIELDS => $body (the string, sent as is)
java
static String sign(String secret, String method, String path, String ts, String nonce, byte[] body) throws Exception {
    MessageDigest sha = MessageDigest.getInstance("SHA-256");
    String bodyHash = HexFormat.of().formatHex(sha.digest(body));
    String sts = String.join("\n", method.toUpperCase(), path, ts, nonce, bodyHash);
    Mac mac = Mac.getInstance("HmacSHA256");
    mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
    return HexFormat.of().formatHex(mac.doFinal(sts.getBytes(StandardCharsets.UTF_8)));
}
// byte[] body = objectMapper.writeValueAsBytes(payload);  serialise once,
// HttpRequest.BodyPublishers.ofByteArray(body)             send the same bytes

Common mistakes ​

SymptomCause
Test vector passes locally, 401 in the wildServer clock off by more than 300 s; or a nonce reused on retry
Intermittent 401The HTTP client rewrote the body before sending (e.g. Axios re-serialising an object, a framework adding fields)
Always 401PATH includes the host or query; lower-case METHOD; \r\n instead of \n
403Source IP not whitelisted, or App / merchant disabled

EasyPay merchant API · v1