Signing requests
Every request to a /bookings route is signed by your server with an Ed25519 key whose public half the property registered with Tulo. A stolen secret key alone cannot book or read guest details.
Which requests are signed#
All four /bookings routes: list, get, create and cancel. They need a secret key and a signature. /place, /calendar, /quote, /signing-keys and every publishable-key request are unsigned.
Headers#
- X-Tulo-Key-Idstring (uuid) · required
The id Tulo gave the signing key when it was registered.
- X-Tulo-Timestampstring · required
Now, in unix seconds, in decimal, for example
1800000000.1 to 12 digits · within 5 minutes of Tulo's clock
- X-Tulo-Noncestring · required
A fresh random value for every request, including a retry. A random UUID works.
16 to 128 of A-Z a-z 0-9 - _
- X-Tulo-Signaturestring · required
The 64-byte Ed25519 signature of the signing string, base64url without padding (Tulo also accepts it padded).
The signing string#
Six parts joined by ., UTF-8, with no trailing newline:
v1.{METHOD}.{path_with_query}.{timestamp}.{nonce}.{body_sha256_hex}| Part | Value |
|---|---|
| v1 | The literal version prefix. |
| METHOD | The HTTP method in upper case, for example POST. |
| path_with_query | The request target exactly as sent: the path from /partner/v1/, then ? and the query string with the same order and encoding when there is one. No scheme, no host. For example /partner/v1/bookings?from=2026-12-01&to=2026-12-31. |
| timestamp | The X-Tulo-Timestamp value. |
| nonce | The X-Tulo-Nonce value. |
| body_sha256_hex | Lower-case hex SHA-256 of the exact body bytes sent. For an empty body (every GET): e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855. |
What Tulo checks#
In this order. The first failure answers 401 with its code and nothing else happens.
- 1.
signature_missing: one of the four headers is absent. - 2.
signature_invalid: the timestamp or the nonce is malformed. - 3.
signature_expired: the timestamp is more than 5 minutes before or after Tulo's clock. Keep your server clock synced (NTP). - 4.
signing_key_unknown: the key id is not an active (unrevoked) signing key of the same property as the API key. - 5.
signature_invalid: the signature does not verify. - 6.
signature_replayed: the nonce was already used. Tulo claims a nonce only after the signature verifies, and holds it until its timestamp leaves the 5-minute window.
A body over 1 MiB is 413 request_too_large. If the nonce store is down, Tulo answers 503 unavailable; retry with a new nonce.
Registering a key#
Generate an Ed25519 key pair on your server (see the Quickstart) and keep the private key there. A manager or the owner registers the public key with a name in the Tulo console under Settings, then API keys, then Signing keys (from 1.4.1; before that, Tulo registers it for the property). Tulo accepts:
- The raw 32-byte key in base64url, which is the
xof an OKP JWK. In Node.js:publicKey.export({format: "jwk"}).x. In PHP:sodium_crypto_sign_publickey(), then base64url. - The same bytes in standard base64, padded or not.
- A PEM
PUBLIC KEYblock (whatopenssl pkey -puboutprints).
Tulo answers with the key's id: that is your X-Tulo-Key-Id. A property holds at most 5 active signing keys, and the same active key cannot be registered twice. To rotate: register the new key, deploy your server with it and its new id, then revoke the old one.
Code#
Complete helpers with no dependencies. The Node.js file is the one Tulo's docs tests run against the published test vectors.
// tulo-signing.mjs: sign requests to the Tulo website API and verify Tulo's
// webhooks. Node.js 18 or later, no dependencies.
import { createHash, createPrivateKey, createPublicKey, randomUUID, sign, verify } from "node:crypto";
export const TULO_API = "https://api.tulo.homes";
const b64url = (bytes) => Buffer.from(bytes).toString("base64url");
// Your private key from a PEM string (what generateKeyPairSync gives you).
export function privateKeyFromPem(pem) {
return createPrivateKey(pem);
}
// A private key from its raw 32-byte seed in base64url (the test vectors).
export function privateKeyFromSeed(seedB64url) {
const prefix = Buffer.from("302e020100300506032b657004220420", "hex");
const der = Buffer.concat([prefix, Buffer.from(seedB64url, "base64url")]);
return createPrivateKey({ key: der, format: "der", type: "pkcs8" });
}
// A public key from its raw 32 bytes in base64url (GET /signing-keys).
export function publicKeyFromRaw(rawB64url) {
return createPublicKey({ key: { kty: "OKP", crv: "Ed25519", x: rawB64url }, format: "jwk" });
}
// The raw public key to register with Tulo (the JWK "x" value).
export function rawPublicKey(key) {
return createPublicKey(key).export({ format: "jwk" }).x;
}
// v1.{METHOD}.{path_with_query}.{timestamp}.{nonce}.{body_sha256_hex}
export function requestSigningString({ method, pathWithQuery, timestamp, nonce, body = "" }) {
const bodyHash = createHash("sha256").update(body).digest("hex");
return ["v1", method.toUpperCase(), pathWithQuery, timestamp, nonce, bodyHash].join(".");
}
export function signRequest(privateKey, request) {
return b64url(sign(null, Buffer.from(requestSigningString(request), "utf8"), privateKey));
}
// Tulo's side of the check, for your own tests.
export function verifyRequest(publicKey, request, signature) {
const message = Buffer.from(requestSigningString(request), "utf8");
return verify(null, message, publicKey, Buffer.from(signature, "base64url"));
}
// The four signature headers for one request. A fresh timestamp and nonce
// every time, including on a retry.
export function signatureHeaders({ keyId, privateKey, method, pathWithQuery, body = "" }) {
const timestamp = String(Math.floor(Date.now() / 1000));
const nonce = randomUUID();
const signature = signRequest(privateKey, { method, pathWithQuery, timestamp, nonce, body });
return {
"X-Tulo-Key-Id": keyId,
"X-Tulo-Timestamp": timestamp,
"X-Tulo-Nonce": nonce,
"X-Tulo-Signature": signature,
};
}
// A signed request from your server. `body` is a JS object or undefined; it
// is serialised once, and those exact bytes are both hashed and sent.
export async function tuloRequest({ secretKey, keyId, privateKey, method, pathWithQuery, body, idempotencyKey }) {
const raw = body === undefined ? "" : JSON.stringify(body);
const headers = {
Authorization: `Bearer ${secretKey}`,
...signatureHeaders({ keyId, privateKey, method, pathWithQuery, body: raw }),
};
if (raw) headers["Content-Type"] = "application/json";
if (idempotencyKey) headers["Idempotency-Key"] = idempotencyKey;
const res = await fetch(TULO_API + pathWithQuery, { method, headers, body: raw || undefined });
const json = await res.json();
if (!res.ok) {
const err = new Error(json.error?.message ?? `HTTP ${res.status}`);
Object.assign(err, { status: res.status, code: json.error?.code, details: json.error });
throw err;
}
return json;
}
// v1.{delivery_id}.{timestamp}.{raw_body}
export function webhookSigningString({ deliveryId, timestamp, rawBody }) {
return Buffer.concat([Buffer.from(`v1.${deliveryId}.${timestamp}.`, "utf8"), Buffer.from(rawBody)]);
}
// Check one delivery: the signature over the exact bytes received, and the
// timestamp within 5 minutes of your clock. Run it before parsing the JSON.
export function verifyWebhook({ publicKey, deliveryId, timestamp, rawBody, signature, now = Date.now() }) {
if (!/^[0-9]{1,12}$/.test(timestamp)) return false;
if (Math.abs(now / 1000 - Number(timestamp)) > 300) return false;
const message = webhookSigningString({ deliveryId, timestamp, rawBody });
return verify(null, message, publicKey, Buffer.from(signature, "base64url"));
}Test vectors#
Ed25519 signatures are deterministic, so a correct implementation with the published key produces exactly the published signatures. Download partner-v1-signing-test-vectors.json. The keys in it are public test keys: never use them for anything real.
Worked example#
- method
POST- path_with_query
/partner/v1/bookings- timestamp
1800000000- nonce
6c1f0e9a2b7d4c58a3e1f0b9d2c7a4e6- body
{"room_type_id":"9a8b7c6d-5e4f-4a3b-8c2d-1e0f9a8b7c6d","check_in":"2026-12-01","check_out":"2026-12-03","adults":2,"guest":{"name":"Mwila Banda","phone":"0971234567"}}- private_seed
ISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0-P0A- public_key
5_FioQvsVZr-oZXk3OhLaVaNXSywlj60RsBoXisX8vA- body_sha256_hex
836cfd3391372093da1b66c1a3af035e2a86bd94d2a3048fd29edbea2b901abb- signing_string
v1.POST./partner/v1/bookings.1800000000.6c1f0e9a2b7d4c58a3e1f0b9d2c7a4e6.836cfd3391372093da1b66c1a3af035e2a86bd94d2a3048fd29edbea2b901abb- signature
TDC28M-qm8v2c9bHWRRf2SGJBzB5SgI2joEZd6o6OKnBopy-BjlABDMNtaswGL4y31kftdg1jo55zezbZuU6Cw
Reproduce it:
import { readFileSync } from "node:fs";
import { privateKeyFromSeed, requestSigningString, signRequest } from "./tulo-signing.mjs";
const vectors = JSON.parse(readFileSync("partner-v1-signing-test-vectors.json", "utf8"));
const r = vectors.request;
const key = privateKeyFromSeed(r.website_key.private_seed);
const req = { method: r.method, pathWithQuery: r.path_with_query, timestamp: r.timestamp, nonce: r.nonce, body: r.body };
console.assert(requestSigningString(req) === r.signing_string);
console.assert(signRequest(key, req) === r.signature);The file has three valid request vectors (request, request_empty_body for a GET with a query string, request_multi_room) and one webhook vector, used on the Webhooks page.
Vectors that must fail#
Each case takes a valid vector, changes one thing and keeps the original signature. Your verifier must reject every one.
| Case | Based on | Changes |
|---|---|---|
| webhook body changed (status) | webhook | body |
| webhook delivery id changed | webhook | delivery id |
| request body changed (adults 3) | request | body |
| request method changed to PUT | request | method |
| request query reordered | request_empty_body | path with query |
| request timestamp changed | request | timestamp |
| multi-room request body changed (room 3 removed) | request_multi_room | body |
