Skip to content

Commit 2876207

Browse files
authored
Merge pull request #529 from multiversx/remove-password-file
Deprecate password file cli argument
2 parents 85aa606 + 7253269 commit 2876207

8 files changed

Lines changed: 76 additions & 51 deletions

File tree

multiversx_sdk_cli/address_config.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,33 @@
1616

1717

1818
def get_defaults() -> dict[str, str]:
19-
"""Not all values are required for a config to be valid.
20-
21-
Valid config for PEM wallets:
19+
"""
20+
Not all values are required for a config to be valid.
2221
22+
Valid config for PEM wallets:
23+
```
2324
{
24-
"kind": "pem",
25-
"path": "/path/to/wallet.pem",
26-
"index": "0", # optional, defaults to 0
25+
"kind": "pem",
26+
"path": "/path/to/wallet.pem",
27+
"index": "0" # optional, defaults to 0
2728
}
29+
```
2830
29-
Valid config for KEYSTORE wallets:
30-
31+
Valid config for KEYSTORE wallets:
32+
```
3133
{
32-
"kind": "keystore",
33-
"path": "/path/to/wallet.json",
34-
"password": "somePassword", # if not set, passwordPath must be set
35-
"passwordPath": "/path/to/password.txt", # if not set, password must be set
36-
"index": "0", # optional, defaults to 0
34+
"kind": "keystore",
35+
"path": "/path/to/wallet.json",
36+
"index": "0" # optional, defaults to 0
3737
}
38+
```
3839
40+
For keystore wallets, you'll be prompted to enter the password when using the wallet.
3941
"""
4042
return {
4143
"kind": "",
4244
"path": "",
4345
"index": "",
44-
"password": "",
45-
"passwordPath": "",
4646
}
4747

4848

multiversx_sdk_cli/cli_password.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
1+
import logging
12
from getpass import getpass
23
from typing import Any
34

5+
logger = logging.getLogger("cli.password")
6+
47

58
def load_password(args: Any) -> str:
69
if args.passfile:
10+
logger.warning(
11+
"Using a password file is DEPRECATED and will be removed in a future version. Instead, you'll be prompted to enter the password when using keystore wallets."
12+
)
713
with open(args.passfile) as pass_file:
814
return pass_file.read().strip()
915
return getpass("Keyfile's password: ")
1016

1117

1218
def load_guardian_password(args: Any) -> str:
1319
if args.guardian_passfile:
20+
logger.warning(
21+
"Using a password file is DEPRECATED and will be removed in a future version. Instead, you'll be prompted to enter the password when using keystore wallets."
22+
)
1423
with open(args.guardian_passfile) as pass_file:
1524
return pass_file.read().strip()
1625
return getpass("Keyfile's password: ")
1726

1827

1928
def load_relayer_password(args: Any) -> str:
2029
if args.relayer_passfile:
30+
logger.warning(
31+
"Using a password file is DEPRECATED and will be removed in a future version. Instead, you'll be prompted to enter the password when using keystore wallets."
32+
)
2133
with open(args.relayer_passfile) as pass_file:
2234
return pass_file.read().strip()
2335
return getpass("Keyfile's password: ")

multiversx_sdk_cli/cli_shared.py

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
from argparse import FileType
77
from functools import cache
8+
from getpass import getpass
89
from pathlib import Path
910
from typing import Any, Optional, Text, Union, cast
1011

@@ -47,6 +48,7 @@
4748
LedgerError,
4849
NoWalletProvided,
4950
UnknownAddressAliasError,
51+
WalletError,
5052
)
5153
from multiversx_sdk_cli.guardian_relayer_data import GuardianRelayerData
5254
from multiversx_sdk_cli.interfaces import IAccount
@@ -181,7 +183,7 @@ def add_wallet_args(args: list[str], sub: Any):
181183
)
182184
sub.add_argument(
183185
"--passfile",
184-
help="🔑 a file containing keyfile's password, if keyfile provided. If not provided, you'll be prompted to enter the password.",
186+
help="DEPRECATED, do not use it anymore. Instead, you'll be prompted to enter the password.",
185187
)
186188
sub.add_argument(
187189
"--ledger",
@@ -225,7 +227,7 @@ def add_guardian_wallet_args(args: list[str], sub: Any):
225227
)
226228
sub.add_argument(
227229
"--guardian-passfile",
228-
help="🔑 a file containing keyfile's password, if keyfile provided. If not provided, you'll be prompted to enter the password.",
230+
help="DEPRECATED, do not use it anymore. Instead, you'll be prompted to enter the password.",
229231
)
230232
sub.add_argument(
231233
"--guardian-ledger",
@@ -246,7 +248,7 @@ def add_relayed_v3_wallet_args(args: list[str], sub: Any):
246248
sub.add_argument("--relayer-keyfile", help="🔑 a JSON keyfile, if PEM not provided")
247249
sub.add_argument(
248250
"--relayer-passfile",
249-
help="🔑 a file containing keyfile's password, if keyfile provided. If not provided, you'll be prompted to enter the password.",
251+
help="DEPRECATED, do not use it anymore. Instead, you'll be prompted to enter the password.",
250252
)
251253
sub.add_argument(
252254
"--relayer-ledger",
@@ -357,12 +359,10 @@ def prepare_account(args: Any):
357359
password = load_password(args)
358360
index = args.sender_wallet_index if args.sender_wallet_index != 0 else None
359361

360-
return Account.new_from_keystore(
361-
file_path=Path(args.keyfile),
362-
password=password,
363-
address_index=index,
364-
hrp=hrp,
365-
)
362+
try:
363+
return Account.new_from_keystore(Path(args.keyfile), password=password, address_index=index, hrp=hrp)
364+
except Exception as e:
365+
raise WalletError(str(e))
366366
elif args.ledger:
367367
try:
368368
return LedgerAccount(address_index=args.sender_wallet_index)
@@ -414,18 +414,13 @@ def _load_wallet_from_address_config(wallet: dict[str, str], hrp: str) -> Accoun
414414
if kind == "pem":
415415
return Account.new_from_pem(file_path=path, index=index, hrp=hrp)
416416
else:
417-
password = wallet.get("password", "")
418-
password_path = wallet.get("passwordPath", None)
419-
420-
if not password and not password_path:
421-
raise AddressConfigFileError(
422-
"'password' or 'passwordPath' must be set in the address config for keystore wallets."
423-
)
424-
425-
if password_path:
426-
password = Path(password_path).read_text().splitlines()[0].strip()
427-
428-
return Account.new_from_keystore(file_path=path, password=password, address_index=index, hrp=hrp)
417+
logger.info("Using keystore wallet.")
418+
password = getpass("Please enter the wallet password: ")
419+
logger.info(f"Loading keystore wallet from path: {path}")
420+
try:
421+
return Account.new_from_keystore(file_path=path, password=password, address_index=index, hrp=hrp)
422+
except Exception as e:
423+
raise WalletError(str(e))
429424

430425

431426
def _get_address_hrp(args: Any) -> str:
@@ -472,12 +467,15 @@ def load_guardian_account(args: Any) -> Union[IAccount, None]:
472467
password = load_guardian_password(args)
473468
index = args.guardian_wallet_index if args.guardian_wallet_index != 0 else None
474469

475-
return Account.new_from_keystore(
476-
file_path=Path(args.guardian_keyfile),
477-
password=password,
478-
address_index=index,
479-
hrp=hrp,
480-
)
470+
try:
471+
return Account.new_from_keystore(
472+
Path(args.guardian_keyfile),
473+
password=password,
474+
address_index=index,
475+
hrp=hrp,
476+
)
477+
except Exception as e:
478+
raise WalletError(str(e))
481479
elif args.guardian_ledger:
482480
try:
483481
return LedgerAccount(address_index=args.guardian_wallet_index)
@@ -606,12 +604,15 @@ def load_relayer_account(args: Any) -> Union[IAccount, None]:
606604
password = load_relayer_password(args)
607605
index = args.relayer_wallet_index if args.relayer_wallet_index != 0 else None
608606

609-
return Account.new_from_keystore(
610-
file_path=Path(args.relayer_keyfile),
611-
password=password,
612-
address_index=index,
613-
hrp=hrp,
614-
)
607+
try:
608+
return Account.new_from_keystore(
609+
Path(args.relayer_keyfile),
610+
password=password,
611+
address_index=index,
612+
hrp=hrp,
613+
)
614+
except Exception as e:
615+
raise WalletError(str(e))
615616
elif args.relayer_ledger:
616617
try:
617618
return LedgerAccount(address_index=args.relayer_wallet_index)

multiversx_sdk_cli/errors.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,8 @@ def __init__(self, message: str):
211211
class AddressConfigFileError(KnownError):
212212
def __init__(self, message: str):
213213
super().__init__(message)
214+
215+
216+
class WalletError(KnownError):
217+
def __init__(self, message: str):
218+
super().__init__(message)

multiversx_sdk_cli/tests/test_cli_default_wallet.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pathlib import Path
33
from typing import Any
44

5+
from multiversx_sdk_cli import cli_shared
56
from multiversx_sdk_cli.cli import main
67

78

@@ -247,6 +248,8 @@ def test_incomplete_address_config(capsys: Any, monkeypatch: Any, tmp_path: Path
247248
monkeypatch.setattr(multiversx_sdk_cli.address_config, "LOCAL_ADDRESS_CONFIG_PATH", test_file)
248249
multiversx_sdk_cli.address_config.read_address_config_file.cache_clear()
249250

251+
monkeypatch.setattr(cli_shared, "getpass", lambda *args, **kwargs: "")
252+
250253
return_code = main(
251254
[
252255
"tx",
@@ -255,6 +258,10 @@ def test_incomplete_address_config(capsys: Any, monkeypatch: Any, tmp_path: Path
255258
"erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx",
256259
"--gas-limit",
257260
"50000",
261+
"--nonce",
262+
"0",
263+
"--chain",
264+
"D",
258265
]
259266
)
260267
assert return_code

multiversx_sdk_cli/tests/test_cli_multisig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def test_transfer_and_execute_esdt(capsys: Any):
503503
data = base64.b64decode(data).decode()
504504
assert (
505505
data
506-
== "proposeTransferExecuteEsdt@0000000000000000050049bff963bdfa3ea02713362095df32e3d708eaccfc57@0000000c414c4943452d3536323766310000000000000000000000010a@0100000000004c4b40@3634363937333734373236393632373537343635"
506+
== "proposeTransferExecuteEsdt@0000000000000000050049bff963bdfa3ea02713362095df32e3d708eaccfc57@0000000c414c4943452d3536323766310000000000000000000000010a@0100000000004c4b40@64697374726962757465"
507507
)
508508

509509

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies = [
2525
"ledgercomm[hid]",
2626
"rich==13.3.4",
2727
"argcomplete==3.2.2",
28-
"multiversx-sdk[ledger]==1.6.0"
28+
"multiversx-sdk[ledger]==1.6.1"
2929
]
3030

3131
[project.scripts]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ ledgercomm[hid]
66
rich==13.3.4
77
argcomplete==3.2.2
88

9-
multiversx-sdk[ledger]==1.6.0
9+
multiversx-sdk[ledger]==1.6.1

0 commit comments

Comments
 (0)