Build
Sign every request
Each request carries four headers. The signature proves the request came from you, was made just now, and was not changed on the way.
The four headers
| Header | Value |
|---|---|
X-Connect-Key | Your key, for example nc_test_… |
X-Connect-Timestamp | The current time in Unix seconds. Refused if more than 5 minutes off. |
X-Connect-Nonce | 16 to 64 random letters, digits, - or _. Never reuse one. |
X-Connect-Signature | Hex HMAC-SHA256, made with your secret, of the string below. |
The string to sign
Five parts joined with dots:
pathis exactly what you request, including the query:/v1/transactions?limit=20.bodyis the exact JSON text you send. Sign the same bytes you put on the wire.
Example in Node
import crypto from 'node:crypto';
function connectHeaders({ keyId, secret, method, path, body = '' }) {
const timestamp = String(Math.floor(Date.now() / 1000));
const nonce = crypto.randomBytes(16).toString('hex');
const bodyHash = crypto.createHash('sha256').update(body).digest('hex');
const signature = crypto
.createHmac('sha256', secret)
.update([timestamp, nonce, method.toUpperCase(), path, bodyHash].join('.'))
.digest('hex');
return {
'X-Connect-Key': keyId,
'X-Connect-Timestamp': timestamp,
'X-Connect-Nonce': nonce,
'X-Connect-Signature': signature,
};
}Retries need a fresh nonce. A nonce works once, so sign again with a new nonce and timestamp every time you retry a request.
Calls on behalf of a user
The read routes need the four signature headers plus the user's access token: Authorization: Bearer <access_token>.
When signing goes wrong
| Code | Status | What to do |
|---|---|---|
INVALID_CREDENTIALS | 401 | Unknown or revoked key, or the signature does not match. Check the string you sign. |
TIMESTAMP_OUT_OF_RANGE | 401 | Check your server clock. |
INVALID_NONCE, NONCE_REUSED | 401 | Use a fresh nonce for every request, including retries. |
IP_NOT_ALLOWED | 403 | The call came from a server address that is not registered for you. |