Skip to content

Commit

Permalink
refactor: Disable new API unless opted in
Browse files Browse the repository at this point in the history
Note: opt-in via Account.enable_unaudited_features()
  • Loading branch information
fubuloubu committed Feb 19, 2020
1 parent 8e73e58 commit cfb8200
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions eth_account/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ class Account(object):

_default_kdf = os.getenv('ETH_ACCOUNT_KDF', 'scrypt')

# Enable unaudited features (off by default)
_use_unaudited_features = False

@classmethod
def enable_unaudited_features(cls):
cls._use_unaudited_features = True

@combomethod
def create(self, extra_entropy=''):
r"""
Expand Down Expand Up @@ -247,6 +254,8 @@ def from_mnemonic(self, mnemonic, passphrase="", account_index=0):
.. code-block:: python
>>> from eth_account import Account
>>> Account.enabled_unaudited_features()
>>> acct = Account.from_mnemonic(
"coral allow abandon recipe top tray caught video climb similar prepare bracket "
"antenna rubber announce gauge volume hub hood burden skill immense add acid")
Expand All @@ -257,6 +266,12 @@ def from_mnemonic(self, mnemonic, passphrase="", account_index=0):
# They correspond to the same-named methods in Account.*
# but without the private key argument
"""
if not self._use_unaudited_features:
raise AttributeError(
"The use of the Mnemonic features of Account is disabled by default until "
"its API stabilizes. To use these features, please enable them by running "
"`Account.enable_unaudited_features()` and try again."
)
seed = seed_from_mnemonic(mnemonic, passphrase)
if isinstance(account_index, int):
private_key = derive_ethereum_key(seed, account_index)
Expand Down Expand Up @@ -299,6 +314,7 @@ def create_with_mnemonic(self,
.. code-block:: python
>>> from eth_account import Account
>>> Account.enabled_unaudited_features()
>>> acct, mnemonic = Account.create_with_mnemonic()
>>> acct.address
'0x5ce9454909639D2D17A3F753ce7d93fa0b9aB12E'
Expand All @@ -309,6 +325,12 @@ def create_with_mnemonic(self,
# They correspond to the same-named methods in Account.*
# but without the private key argument
"""
if not self._use_unaudited_features:
raise AttributeError(
"The use of the Mnemonic features of Account is disabled by default until "
"its API stabilizes. To use these features, please enable them by running "
"`Account.enable_unaudited_features()` and try again."
)
mnemonic = generate_mnemonic(num_words, lang=language)
return self.from_mnemonic(mnemonic, passphrase, account_index), mnemonic

Expand Down
2 changes: 2 additions & 0 deletions tests/core/test_hdaccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
Account,
)

Account.enable_unaudited_features()


@pytest.mark.parametrize("mnemonic,expected_address", [
(
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/test_ethers_fuzzing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
Mnemonic,
)

Account.enable_unaudited_features()

language_st = st.sampled_from(Mnemonic.list_languages())

seed_st = st.binary(min_size=16, max_size=32) \
Expand Down

0 comments on commit cfb8200

Please sign in to comment.