API Users and Access Control
API users function similarly to human users in that they are assigned roles, permissions, and vault access at the time of creation. When an API user interacts with the system, these settings are enforced to control which data they can access and which actions they can perform. However, unlike regular users, API users cannot log in to the Custody application. Their interaction with the system is limited strictly to API calls, making them an essential component for programmatic access while maintaining strict security boundaries.Creating a new API Key
A system administrator must initiate the creation of a new API user before generating an API key:- Log in to your Custody environment
- Navigate to Settings → Users → API Users
- Submit a request for a new API user and complete the two-factor authentication (2FA) process
- The request will appear under Tasks → Pending until it is approved by the Admin Quorum
- Once approved, open the request details to view the API key information
- The admin user who submitted the request can access the API key and secret from the API key details page
Authentication Parameters
For the REST API, the following parameters are used for authentication to endpoints which contain private data:API-KeyHTTP header parameter: the public key from your API key-pair.API-SignHTTP header parameter: encrypted signature of message.noncepayload parameter: always increasing, unsigned 64-bit integer.
Setting the API-Key Parameter
The value for theAPI-Key HTTP header parameter is your public API key.
An API key-pair is required to access the authenticated endpoints.
Setting the API-Sign Parameter
The value for theAPI-Sign HTTP header parameter is a signature generated from encoding your private API key, nonce, encoded payload, and URI path.
Examples
The following is a specific example of a signature generated with a particular private key, nonce, and payload corresponding to a new limit order (buy 1.25 XBTUSD at $37,500). If your code is generating a different signature (API-Sign) for this example, then there is likely an issue with your application of the above methodology. Code snippets for generating the signature in Python, Golang and Node.js follow below.
- Python
- Go
- Node JS
Setting the nonce Parameter
The value for thenonce payload body parameter is an always increasing, unsigned 64-bit integer for each request that is made with a particular API key.
While a simple counter would provide a valid nonce, a more usual method of generating a valid nonce is to use e.g. a UNIX timestamp in milliseconds. There is no way to reset the nonce for an API key to a lower value, so be sure to use a nonce generation method that won’t produce numbers less than the previous nonce.
Too many requests with invalid nonces (EAPI:Invalid nonce) can result in temporary bans.
Problems can arise from requests arriving out of order due to API keys being shared across processes, or from system clock drift/recalibration. An optional “nonce window” can be configured to specify a tolerance between nonce values.
Examples
The following are some examples of how to generate valid millisecond resolution nonce values in different programming languages:- Python
- JavaScript
- PHP