cdp.auth package¶
Subpackages¶
- cdp.auth.clients package
 - cdp.auth.test package
- Subpackages
- cdp.auth.test.factories package
- Submodules
 - cdp.auth.test.factories.auth_client_options_factory module
 - cdp.auth.test.factories.auth_headers_factory module
 - cdp.auth.test.factories.auth_options_factory module
 - cdp.auth.test.factories.http_client_factory module
 - cdp.auth.test.factories.http_response_factory module
 - cdp.auth.test.factories.jwt_options_factory module
 - cdp.auth.test.factories.private_key_factory module
 - Module contents
 
 
 - cdp.auth.test.factories package
 - Submodules
 - cdp.auth.test.test_client module
 - cdp.auth.test.test_http module
 - cdp.auth.test.test_jwt module
ec_private_key()ed25519_private_key()jwt_options()test_generate_jwt_custom_expiry()test_generate_jwt_default_expiry()test_generate_jwt_ec()test_generate_jwt_ed25519()test_generate_jwt_missing_params()test_generate_nonce()test_generate_websocket_jwt_ec()test_generate_websocket_jwt_ed25519()test_invalid_request_parameters_mix()test_parse_private_key_ec()test_parse_private_key_ed25519()test_parse_private_key_invalid()websocket_jwt_options()
 - cdp.auth.test.test_ws module
 - Module contents
 
 - Subpackages
 - cdp.auth.utils package
- Submodules
 - cdp.auth.utils.http module
GetAuthHeadersOptionsGetAuthHeadersOptions.api_key_idGetAuthHeadersOptions.api_key_secretGetAuthHeadersOptions.audienceGetAuthHeadersOptions.expires_inGetAuthHeadersOptions.model_configGetAuthHeadersOptions.request_bodyGetAuthHeadersOptions.request_hostGetAuthHeadersOptions.request_methodGetAuthHeadersOptions.request_pathGetAuthHeadersOptions.sourceGetAuthHeadersOptions.source_versionGetAuthHeadersOptions.wallet_secret
get_auth_headers()
 - cdp.auth.utils.jwt module
 - cdp.auth.utils.ws module
 - Module contents
GetAuthHeadersOptionsGetAuthHeadersOptions.api_key_idGetAuthHeadersOptions.api_key_secretGetAuthHeadersOptions.audienceGetAuthHeadersOptions.expires_inGetAuthHeadersOptions.model_configGetAuthHeadersOptions.request_bodyGetAuthHeadersOptions.request_hostGetAuthHeadersOptions.request_methodGetAuthHeadersOptions.request_pathGetAuthHeadersOptions.sourceGetAuthHeadersOptions.source_versionGetAuthHeadersOptions.wallet_secret
GetWebSocketAuthHeadersOptionsJwtOptionsWalletJwtOptionsgenerate_jwt()generate_wallet_jwt()get_auth_headers()get_websocket_auth_headers()
 
 
Module contents¶
Authentication package for the SDK.
This package provides authentication utilities and JWT token handling functionality.
- class cdp.auth.GetAuthHeadersOptions(**data)¶
 Bases:
BaseModelOptions for generating authentication headers.
- api_key_id - The API key ID
 
- api_key_secret - The API key secret
 
- request_method - The HTTP method
 
- request_host - The request host
 
- request_path - The request path
 
- [request_body] - Optional request body
 
- [wallet_secret] - Optional wallet secret for wallet authentication
 
- [source] - Optional source identifier
 
- [source_version] - Optional source version
 
- [expires_in] - Optional JWT expiration time in seconds
 
- [audience] - Optional audience claim for the JWT
 
- 
api_key_id: 
str¶ 
- 
api_key_secret: 
str¶ 
- 
audience: 
list[str] |None¶ 
- 
expires_in: 
int|None¶ 
- model_config: ClassVar[ConfigDict] = {}¶
 Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- 
request_body: 
dict[str,Any] |None¶ 
- 
request_host: 
str¶ 
- 
request_method: 
str¶ 
- 
request_path: 
str¶ 
- 
source: 
str|None¶ 
- 
source_version: 
str|None¶ 
- 
wallet_secret: 
str|None¶ 
- class cdp.auth.GetWebSocketAuthHeadersOptions(**data)¶
 Bases:
BaseModelOptions for generating WebSocket authentication headers.
- api_key_id - The API key ID
 
- api_key_secret - The API key secret
 
- [source] - Optional source identifier
 
- [source_version] - Optional source version
 
- [expires_in] - Optional JWT expiration time in seconds
 
- [audience] - Optional audience claim for the JWT
 
- 
api_key_id: 
str¶ 
- 
api_key_secret: 
str¶ 
- 
audience: 
list[str] |None¶ 
- 
expires_in: 
int|None¶ 
- model_config: ClassVar[ConfigDict] = {}¶
 Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- 
source: 
str|None¶ 
- 
source_version: 
str|None¶ 
- class cdp.auth.JwtOptions(**data)¶
 Bases:
BaseModelConfiguration options for JWT generation.
This class holds all necessary parameters for generating a JWT token for authenticating with Coinbase’s REST APIs. It supports both EC (ES256) and Ed25519 (EdDSA) keys.
- api_key_id - The API key ID
 Examples
‘xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx’ ‘organizations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/apiKeys/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx’
- api_key_secret - The API key secret
 Examples
‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==’ (Edwards key (Ed25519)) ‘—–BEGIN EC PRIVATE KEY—–\n…\n…\n…==\n—–END EC PRIVATE KEY—–\n’ (EC key (ES256))
- request_method - The HTTP method for the request
 - Type:
 e.g. ‘GET’, ‘POST’
- request_host - The host for the request
 - Type:
 e.g. ‘api.cdp.coinbase.com’
- request_path - The path for the request
 - Type:
 e.g. ‘/platform/v1/wallets’
- expires_in - Optional expiration time in seconds
 - Type:
 defaults to 120
- audience - Optional audience claim for the JWT
 
- 
api_key_id: 
str¶ 
- 
api_key_secret: 
str¶ 
- 
audience: 
list[str] |None¶ 
- 
expires_in: 
int|None¶ 
- model_config: ClassVar[ConfigDict] = {}¶
 Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- 
request_host: 
str|None¶ 
- 
request_method: 
str|None¶ 
- 
request_path: 
str|None¶ 
- classmethod validate_request_method(v)¶
 Validate the HTTP request method.
- Parameters:
 v (
str|None) – The request method to validate, or None for JWTs intended for websocket connections- Return type:
 str|None- Returns:
 The validated request method in uppercase, or None
- Raises:
 ValueError – If the request method is invalid
- class cdp.auth.Urllib3AuthClient(options, base_url, debug=False)¶
 Bases:
objectHTTP client that automatically adds authentication headers.
- request(method, url, headers=None, body=None, **kwargs)¶
 Make an authenticated HTTP request.
- Parameters:
 method (
str) – The HTTP methodurl (
str) – The URL to request (relative or absolute)headers (
Optional[dict[str,str]]) – Optional additional headersbody (
Union[dict[str,Any],bytes,None]) – Optional request body (can be a dict for JSON or bytes)**kwargs (
Any) – Additional arguments passed to urllib3.request()
- Return type:
 HTTPResponse- Returns:
 urllib3.HTTPResponse
- class cdp.auth.Urllib3AuthClientOptions(**data)¶
 Bases:
BaseModelConfiguration options for the authenticated HTTP client.
- api_key_id - The API key ID
 Examples
‘xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx’ ‘organizations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/apiKeys/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx’
- api_key_secret - The API key secret
 Examples
‘xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx==’ (Edwards key (Ed25519)) ‘—–BEGIN EC PRIVATE KEY—–n…n…n…==n—–END EC PRIVATE KEY—–n’ (EC key (ES256))
- [wallet_secret] - Optional wallet secret for authenticating with endpoints that require wallet authentication.
 
- [source] - Optional source of the request
 
- [source_version] - Optional version of the source of the request
 
- [expires_in] - Optional expiration time in seconds
 - Type:
 defaults to 120
- 
api_key_id: 
str¶ 
- 
api_key_secret: 
str¶ 
- 
expires_in: 
int|None¶ 
- model_config: ClassVar[ConfigDict] = {}¶
 Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- 
source: 
str|None¶ 
- 
source_version: 
str|None¶ 
- 
wallet_secret: 
str|None¶ 
- class cdp.auth.WalletJwtOptions(**data)¶
 Bases:
BaseModelConfiguration options for Wallet Auth JWT generation.
This class holds all necessary parameters for generating a Wallet Auth JWT for authenticating with endpoints that require wallet authentication.
- wallet_auth_key - The wallet authentication key
 
- request_method - The HTTP method for the request
 - Type:
 e.g. ‘GET’, ‘POST’
- request_host - The host for the request
 - Type:
 e.g. ‘api.cdp.coinbase.com’
- request_path - The path for the request
 - Type:
 e.g. ‘/platform/v1/wallets/{wallet_id}/addresses’
- request_data - The request data for the request (e.g. { "wallet_id"
 “1234567890” })
- model_config: ClassVar[ConfigDict] = {}¶
 Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- 
request_data: 
dict[str,Any]¶ 
- 
request_host: 
str¶ 
- 
request_method: 
str¶ 
- 
request_path: 
str¶ 
- classmethod validate_request_method(v)¶
 Validate the HTTP request method.
- Parameters:
 v (
str) – The request method to validate- Return type:
 str- Returns:
 The validated request method in uppercase
- Raises:
 ValueError – If the request method is invalid
- 
wallet_auth_key: 
str¶ 
- cdp.auth.generate_jwt(options)¶
 Generate a JWT (Bearer token) for authenticating with Coinbase’s APIs.
Supports both EC (ES256) and Ed25519 (EdDSA) keys. Also supports JWTs meant for websocket connections by allowing request_method, request_host, and request_path to all be None, in which case the ‘uris’ claim is omitted from the JWT.
- Parameters:
 options (
JwtOptions) – The configuration options for generating the JWT- Return type:
 str- Returns:
 The generated JWT (Bearer token) string
- Raises:
 ValueError – If required parameters are missing, invalid, or if JWT signing fails
- cdp.auth.generate_wallet_jwt(options)¶
 Build a wallet authentication JWT for the given API endpoint URL.
Used for authenticating with specific endpoints that require wallet authentication.
- Parameters:
 options (
WalletJwtOptions) – The configuration options for generating the wallet auth JWT- Return type:
 str- Returns:
 The generated JWT (Bearer token) string
- Raises:
 ValueError – If required parameters are missing or if JWT signing fails
- cdp.auth.get_auth_headers(options)¶
 Get authentication headers for a request.
- Parameters:
 options (
GetAuthHeadersOptions) – The authentication header options- Return type:
 dict[str,str]- Returns:
 Dict with authentication headers
- cdp.auth.get_websocket_auth_headers(options)¶
 Get authentication headers for a WebSocket connection.
- Parameters:
 options (
GetWebSocketAuthHeadersOptions) – The WebSocket authentication header options- Return type:
 dict[str,str]- Returns:
 Dict with authentication headers