If you are using Cobo’s WaaS SDKs, you can skip this topic because the SDKs already encapsulate the authentication mechanism for you.
- Biz-Api-Key: The public key you generate in Generate an API key.
- Biz-Api-Nonce: A nonce is the current time in Unix timestamp format, measured in milliseconds.
- Biz-Api-Signature: The API signature. To learn how to calculate an API signature, see Calculate an API Signature.
API key
The API key is used to identify the client making the API request. It is associated with a certain level of access to the API’s resources. Different API keys can be assigned with different permissions, allowing you to control what actions the client can perform.Generate an API key
This section introduces how to generate an API key using the Ed25519 algorithm. You can use either OpenSSL or the Python library to generate an Ed25519 key pair. The public key will be used as an API key, and the private key will be used as an API secret to sign an API request.Use OpenSSL
In a terminal window, run the following OpenSSL commands:private.key.pem file, and the public key is saved in the public.key.pem file.
Use the Python library
-
Install the ed25519 Python library. In a terminal window, run the following command:
-
Generate a key pair. Import the function from the Python library to generate a key pair as follows:
Register the API key
After generating an API key, you need to register the key and configure related permissions on Cobo Portal. To learn how to register an API key, see Register an API key.Nonce
A nonce is the current time in Unix timestamp format, measured in milliseconds.Calculate the API signature
The following steps introduce how to calculate an API signature.-
First, concatenate a string based on your request as follows:
str_to_sign =
{METHOD}|{PATH}|{TIMESTAMP}|{PARAMS}|{BODY}Field Description Example METHOD The HTTP method. GETPATH The API endpoint. /v2/transactions/transferTIMESTAMP The current time in Unix timestamp format, measured in milliseconds. This value must be the same as the nonce in the request header. 1718587017026PARAMS (If applicable) The query parameters. chain_id=ETH&limit=10BODY (If applicable) The raw request body in string format. {"name":"Default","wallet_subtype":"Asset","wallet_type":"Custodial"} -
Use the
hashliblibrary to perform SHA-256 hashing twice on the string as follows: -
Use the private key of your API key to sign the string as follows:
