Skip to content

Commit

Permalink
[Coinbase] handle UnexpectedDER
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDSM committed May 24, 2024
1 parent 9fd4bfb commit a0c2afb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tests/exchanges/test_coinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ async def test_invalid_api_key_get_api_key_rights(coinbase_exchange):
exchange._exchange.connector.client.apiKey = "-----BEGIN EC PRIVATE KEY----b43c5889-a3b5-4ab5-a606-578b4d74f3db"
exchange._exchange.connector.client.secret = "-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIK/XmQtNSTD2pqrhyZFvBuExnlyLOPcDzT+fsm1sq3ZCoAoGCCqGSM49\nAwEHoUQDQgAErQXGFQUMqPT5fQUVcCchCaomapu0y952+XgveL2QjgghGCeFbLfR\nTSg2RgUUtGbG3TIBEomwzbRAOEeYdjK06w"
assert await exchange._get_api_key_rights()
with pytest.raises(ccxt.AuthenticationError):
# added chars after private key
# ccxt.static_dependencies.ecdsa.der.UnexpectedDER turned into ccxt.AuthenticationError
exchange._exchange.connector.client.apiKey = "organizations/1e7665a0-440b-495f-8a49-5365841e196e/apiKeys/b43c5889-a3b5-4ab5-a606-578b4d74f3db"
exchange._exchange.connector.client.secret = "-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIK/XmQtNSTD2pqrhyZFvBuExnlyLOPcDzT+fsm1sq3ZCoAoGCCqGSM49\nAwEHoUQDQgAErQXGFQUMqPT5fQUVcCchCaomapu0y952+XgveL2QjgghGCeFbLfR\nTSg2RgUUtGbG3TIBEomwzbRAOEeYdjK06w" + b'488347'.decode()
assert await exchange._get_api_key_rights()


# @pytest.mark.asyncio
Expand Down
6 changes: 5 additions & 1 deletion trading_backend/exchanges/coinbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
import ccxt
import ccxt.static_dependencies.ecdsa.der
import binascii
import trading_backend.exchanges as exchanges
import trading_backend.enums
Expand Down Expand Up @@ -113,7 +114,10 @@ async def _get_api_key_rights(self) -> list[trading_backend.enums.APIKeyRights]:
return await self._get_api_key_rights_using_order()
except ccxt.AuthenticationError:
raise
except (binascii.Error, AssertionError, IndexError, ccxt.ArgumentsRequired) as err:
except (
binascii.Error, AssertionError, IndexError,
ccxt.ArgumentsRequired, ccxt.static_dependencies.ecdsa.der.UnexpectedDER
) as err:
raise ccxt.AuthenticationError(f"Invalid key format ({err})")
except ccxt.BaseError as err:
self._exchange.logger.exception(
Expand Down

0 comments on commit a0c2afb

Please sign in to comment.