MCPcopy Create free account
hub / github.com/ccxt/ccxt / create_auth_token

Method create_auth_token

python/ccxt/coinbase.py:4851–4885  ·  view source on GitHub ↗
(self, seconds: Int, method: Str = None, url: Str = None, useEddsa=False)

Source from the content-addressed store, hash-verified

4849 return parsedPositions
4850
4851 def create_auth_token(self, seconds: Int, method: Str = None, url: Str = None, useEddsa=False):
4852 # v1 https://docs.cdp.coinbase.com/api-reference/authentication#php-2
4853 # v2 https://docs.cdp.coinbase.com/api-reference/v2/authentication
4854 uri = None
4855 if url is not None:
4856 uri = method + ' ' + url.replace('https://', '')
4857 quesPos = uri.find('?')
4858 # Due to we use mb_strpos, quesPos could be False in php. In that case, the quesPos >= 0 is True
4859 # Also it's not possible that the question mark is first character, only check > 0 here.
4860 if quesPos > 0:
4861 uri = uri[0:quesPos]
4862 # self.eddsa{"sub":"d2efa49a-369c-43d7-a60e-ae26e28853c2","iss":"cdp","aud":["cdp_service"],"uris":["GET api.coinbase.com/api/v3/brokerage/transaction_summary"]}
4863 nonce = self.random_bytes(16)
4864 aud = 'cdp_service' if useEddsa else 'retail_rest_api_proxy'
4865 iss = 'cdp' if useEddsa else 'coinbase-cloud'
4866 request = {
4867 'aud': [aud],
4868 'iss': iss,
4869 'nbf': seconds,
4870 'exp': seconds + 120,
4871 'sub': self.apiKey,
4872 'iat': seconds,
4873 }
4874 if uri is not None:
4875 if not useEddsa:
4876 request['uri'] = uri
4877 else:
4878 request['uris'] = [uri]
4879 if useEddsa:
4880 byteArray = self.base64_to_binary(self.secret)
4881 seed = self.array_slice(byteArray, 0, 32)
4882 return self.jwt(request, seed, 'sha256', False, {'kid': self.apiKey, 'nonce': nonce, 'alg': 'EdDSA'})
4883 else:
4884 # self.ecdsawith p256
4885 return self.jwt(request, self.encode(self.secret), 'sha256', False, {'kid': self.apiKey, 'nonce': nonce, 'alg': 'ES256'})
4886
4887 def nonce(self):
4888 return self.milliseconds() - self.options['timeDifference']

Callers 1

signMethod · 0.95

Calls 7

replaceMethod · 0.80
findMethod · 0.80
random_bytesMethod · 0.80
base64_to_binaryMethod · 0.80
array_sliceMethod · 0.80
jwtMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected