Skip to content

Commit ff6dd67

Browse files
authored
Merge pull request #461 from multiversx/fix-signing-with-ledger
Set correct options when signing with Ledger
2 parents 90a6cac + 6d8fa48 commit ff6dd67

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

multiversx_sdk_cli/accounts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def __init__(self, account_index: int = 0, address_index: int = 0) -> None:
9696
def sign_transaction(self, transaction: ITransaction) -> str:
9797
ledger_version = do_get_ledger_version()
9898
should_use_hash_signing = compare_versions(ledger_version, SIGN_USING_HASH_VERSION) >= 0
99+
100+
# TODO: This check will be removed in the next major release.
99101
if should_use_hash_signing:
100102
transaction.version = TX_HASH_SIGN_VERSION
101103
transaction.options = transaction.options | TX_HASH_SIGN_OPTIONS

multiversx_sdk_cli/transactions.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
import json
33
import logging
44
import time
5-
from typing import Any, Dict, List, Optional, Protocol, TextIO
5+
from typing import Any, Dict, List, Optional, Protocol, TextIO, Union
66

77
from multiversx_sdk import (Address, Token, TokenComputer, TokenTransfer,
88
Transaction, TransactionsConverter,
99
TransactionsFactoryConfig,
10-
TransferTransactionsFactory)
10+
TransferTransactionsFactory, TransactionComputer)
1111

1212
from multiversx_sdk_cli import errors
13-
from multiversx_sdk_cli.accounts import Account, LedgerAccount
13+
from multiversx_sdk_cli.accounts import Account, AccountBase, LedgerAccount
1414
from multiversx_sdk_cli.cli_password import (load_guardian_password,
1515
load_password)
1616
from multiversx_sdk_cli.cosign_transaction import cosign_transaction
@@ -75,6 +75,10 @@ def do_prepare_transaction(args: Any) -> Transaction:
7575
tx.version = int(args.version)
7676
tx.options = int(args.options)
7777

78+
tx_computer = TransactionComputer()
79+
if isinstance(account, LedgerAccount):
80+
tx_computer.apply_options_for_hash_signing(tx)
81+
7882
if args.guardian:
7983
tx.guardian = args.guardian
8084

@@ -86,14 +90,25 @@ def do_prepare_transaction(args: Any) -> Transaction:
8690
if relayer_account.address.to_bech32() != tx.relayer:
8791
raise IncorrectWalletError("")
8892

93+
if isinstance(relayer_account, LedgerAccount):
94+
tx_computer.apply_options_for_hash_signing(tx)
95+
8996
tx.relayer_signature = bytes.fromhex(relayer_account.sign_transaction(tx))
9097
except NoWalletProvided:
9198
logger.warning("Relayer wallet not provided. Transaction will not be signed by relayer.")
9299
except IncorrectWalletError:
93100
raise IncorrectWalletError("Relayer wallet does not match the relayer's address set in the transaction.")
94101

102+
try:
103+
guardian_account = get_guardian_account_from_args(args)
104+
if isinstance(guardian_account, LedgerAccount):
105+
tx_computer.apply_options_for_hash_signing(tx)
106+
107+
except NoWalletProvided:
108+
guardian_account = None
109+
95110
tx.signature = bytes.fromhex(account.sign_transaction(tx))
96-
tx = sign_tx_by_guardian(args, tx)
111+
tx = sign_tx_by_guardian(args, tx, guardian_account)
97112

98113
return tx
99114

@@ -141,12 +156,7 @@ def prepare_token_transfers(transfers: List[Any]) -> List[TokenTransfer]:
141156
return token_transfers
142157

143158

144-
def sign_tx_by_guardian(args: Any, tx: Transaction) -> Transaction:
145-
try:
146-
guardian_account = get_guardian_account_from_args(args)
147-
except NoWalletProvided:
148-
guardian_account = None
149-
159+
def sign_tx_by_guardian(args: Any, tx: Transaction, guardian_account: Union[AccountBase, None]) -> Transaction:
150160
if guardian_account:
151161
tx.guardian_signature = bytes.fromhex(guardian_account.sign_transaction(tx))
152162
elif args.guardian:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "multiversx-sdk-cli"
7-
version = "9.10.0"
7+
version = "9.10.1"
88
authors = [
99
{ name="MultiversX" },
1010
]

0 commit comments

Comments
 (0)