Skip to main content

Authentication

All API calls related to a user account, require authentication. You need to provide 4 parameters to authenticate a request:

KeyValue
X-PCKAPI Public Key
X-StampTimestamp
X-NonceDelay Tolerance
X-SignatureSignature of Request
warning

All these parameters must be sent from the header before sending a new request.


Signature

Signature is a HMAC-SHA256 encoded message. The HMAC-SHA256 code must be generated using a private key that contains a current timestamp and your API key.

Nonce

Nonce is a integer number. The value sent determines the connection delay tolerance. For example, if the Nonce value is 15000 (15 seconds), and your request meets the condition (X-Stamp + X-Nonce < Current Server Timestamp), your request will fail. This is because the request you sent reaches the server later than the Nonce value

Code Examples:

    public async Task Connect()
{
string publicKey = "PUBLIC_KEY";
string privateKey = "PRIVATE_KEY";
long nonce = 60000;
long timestamp = DateTimeExtension.ToUnixTime(DateTime.UtcNow);
string baseString = $"{publicKey}{timestamp}";
string signature = ComputeHash(privateKey, baseString);

Dictionary<string, string> headers = new Dictionary<string, string>
{
{"X-PCK", publicKey},
{"X-Signature", signature},
{"X-Stamp", timestamp.ToString()},
{"X-Nonce", nonce.ToString()}
};
}

private string ComputeHash(string privateKey, string message)
{
byte[] key = Convert.FromBase64String(privateKey);
string hashString;

using (HMACSHA256 hmac = new HMACSHA256(key))
{
byte[] hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(message));
hashString = Convert.ToBase64String(hash);
}

return hashString;
}