HMAC Request Signing
Every /v1/* endpoint (including GET reads) must be signed with a single HMAC-SHA256 formula. There are no exceptions and no unauthenticated bypasses. Server-side signature evaluation uses constant-time comparison to prevent timing attacks.
Want ready-to-run files instead of copy-pasting a snippet? See the Self-Integration page to download runnable example files, a Postman collection, and an .http bundle — same signing formula as this page, just pre-packaged.
View Self-IntegrationRequired Headers
The first 4 headers are required on EVERY request. This list is derived directly from the security scheme in openapi.json and cannot drift from the backend.
| Header | Type | Meaning |
|---|---|---|
X-TKE-Key | every request | Public key_id (tke_live_… / tke_test_… / tke_member_live_… / tke_member_test_…) |
X-TKE-Timestamp | every request | Dispatch epoch milliseconds (integer string) |
X-TKE-Nonce | every request | UUID (v4 or v7), unique per request |
X-TKE-Signature | every request | HMAC-SHA256 hex lowercase (formula below) |
Idempotency-Key | 5 endpoints | A client-generated string — the same key + body executes exactly once (a retry returns the original result). Scoped by |
Idempotency-Key/v1/ordersPOST/v1/orders/bulkPOST/v1/esims/{id}/cancelPOST/v1/esims/{id}/change-planPOST/v1/esims/{id}/refund-requestsSignature Canonical Formula
HMAC-SHA256 authentication (§4). Send 4 headers: X-TKE-Key (public key_id), X-TKE-Timestamp (epoch ms), X-TKE-Nonce (a UUID per request), X-TKE-Signature (hex lowercase). signing_string = method\npath\ntimestamp\nnonce\nbody_hash; body_hash = SHA256(raw_body) hex. Compared with constant-time comparison. path INCLUDES the query string.
Segments are joined by newline characters \n (LF), and signed over SHA256(raw_body) rather than the direct body bytes. The server hashes the exact received bytes again to verify the request.
signing_string = method + "\n"
+ path + "\n" # includes query string if present, excludes scheme/host
+ timestamp + "\n" # = header X-TKE-Timestamp (epoch ms)
+ nonce + "\n" # = header X-TKE-Nonce
+ body_hash # SHA256(raw_body) hex lowercase
signature = HMAC_SHA256(secret, signing_string) → hex lowercaseraw_body = "" → body_hash = SHA256("") = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.HMAC Signing Code Snippets
Copy-paste and substitute your actual secret and key_id. Always send the exact hashed bytes as the body — do not re-stringify after signing.
#!/usr/bin/env bash
# Yeu cau: openssl. Ky POST /v1/orders.
KEY_ID="tke_test_ab12cd34..."
SECRET="tke_secret_test_0123456789abcdef"
METHOD="POST"
PATH_Q="/v1/orders"
BODY='{"items":[{"package_code":"THAY-BANG-MA-GOI-CUA-BAN","quantity":2}]}'
TS="$(date +%s000)" # epoch milliseconds
NONCE="$(uuidgen)"
BODY_HASH="$(printf '%s' "$BODY" | openssl dgst -sha256 -hex | awk '{print $NF}')"
SIGNING="$METHOD"$'
'"$PATH_Q"$'
'"$TS"$'
'"$NONCE"$'
'"$BODY_HASH"
SIG="$(printf '%s' "$SIGNING" | openssl dgst -sha256 -hmac "$SECRET" -hex | awk '{print $NF}')"
curl -sS "https://api.tongkhoesim.com$PATH_Q" -H "X-TKE-Key: $KEY_ID" -H "X-TKE-Timestamp: $TS" -H "X-TKE-Nonce: $NONCE" -H "X-TKE-Signature: $SIG" -H "Idempotency-Key: $(uuidgen)" -H "Content-Type: application/json" --data-raw "$BODY"Live Backend Test Vectors
Below are authoritative test vectors generated by the backend during build. Use them to verify your signing algorithm implementation.
Usage: configure your implementation to sign the exact inputs below (same method, path, timestamp, nonce, body) and verify the resulting signature. If mismatched, compare the intermediate signing_string to isolate the discrepancy.
tke_secret_test_0123456789abcdefPOST/v1/orders172068000000011111111-1111-4111-8111-111111111111{"items":[{"package_code":"VN_5GB_30D","quantity":2}]}c197853f7fe46a9f2de1478e565c48ef9369d0152af5117434be8ccfa9391b31POST
/v1/orders
1720680000000
11111111-1111-4111-8111-111111111111
c197853f7fe46a9f2de1478e565c48ef9369d0152af5117434be8ccfa9391b3197147afdebb5d15cf8441278ef524ce15c715ca95962ddb1cb2604a1672fc5d5GET/v1/wallet/balance172068000000022222222-2222-4222-8222-222222222222(empty)e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855GET
/v1/wallet/balance
1720680000000
22222222-2222-4222-8222-222222222222
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855ab16941884d407924c7b15dea008d6f1d8c0c1be96dca3745344218a99257dbe