1- from .auth import Authenticator , KeyfileAuthenticator , PrivateKeyAuthenticator
1+ from .auth import (
2+ Authenticator ,
3+ KeyfileAuthenticator ,
4+ PrivateKeyAuthenticator ,
5+ TrezorAuthenticator ,
6+ )
27from .config import Config
38from .api .admin import Admin
49from .api .margin_account import MarginAccount
@@ -25,9 +30,10 @@ class AFP:
2530 ----------
2631 authenticator : afp.Authenticator, optional
2732 The default authenticator for signing transactions & messages. Can also be set
28- with environment variables; use `AFP_PRIVATE_KEY` for private key
29- authentication, `AFP_KEYFILE` and `AFP_KEYFILE_PASSWORD` for keyfile
30- authentication.
33+ with environment variables: use `AFP_PRIVATE_KEY` for private key
34+ authentication; `AFP_KEYFILE` and `AFP_KEYFILE_PASSWORD` for keyfile
35+ authentication; `AFP_TREZOR_PATH_OR_INDEX` and `AFP_TREZOR_PASSPHRASE` for
36+ Trezor device authentication.
3137 rpc_url : str, optional
3238 The URL of an Autonity RPC provider. Can also be set with the `AFP_RPC_URL`
3339 environment variable.
@@ -217,13 +223,25 @@ def Trading(
217223
218224
219225def _default_authenticator () -> Authenticator | None :
220- if defaults .PRIVATE_KEY is not None and defaults .KEYFILE is not None :
226+ auth_variable_count = sum (
227+ [
228+ int (bool (defaults .PRIVATE_KEY )),
229+ int (bool (defaults .KEYFILE )),
230+ int (bool (defaults .TREZOR_PATH_OR_INDEX )),
231+ ]
232+ )
233+ if auth_variable_count > 1 :
221234 raise ConfigurationError (
222- "Only one of AFP_PRIVATE_KEY and AFP_KEYFILE environment "
223- "variables should be specified"
235+ "Only one of AFP_PRIVATE_KEY, AFP_KEYFILE and AFP_TREZOR_PATH_OR_INDEX "
236+ "environment variables should be specified"
224237 )
225- if defaults .PRIVATE_KEY is not None :
238+
239+ if defaults .PRIVATE_KEY :
226240 return PrivateKeyAuthenticator (defaults .PRIVATE_KEY )
227- if defaults .KEYFILE is not None :
241+ if defaults .KEYFILE :
228242 return KeyfileAuthenticator (defaults .KEYFILE , defaults .KEYFILE_PASSWORD )
243+ if defaults .TREZOR_PATH_OR_INDEX :
244+ return TrezorAuthenticator (
245+ defaults .TREZOR_PATH_OR_INDEX , defaults .TREZOR_PASSPHRASE
246+ )
229247 return None
0 commit comments