Skip to content

Commit

Permalink
Add Trezor to Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 committed Dec 12, 2023
1 parent d39adeb commit 66e4fdc
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 deletions.
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ the information about the Safe using:
```
> refresh
```
## Ledger module
## Hardware wallets support
**NOTE**: before signing anything ensure that the data showing on your hardware wallet device is the same as the safe-cli data.
### Ledger
Ledger module is an optional feature of safe-cli to sign transactions with the help of [ledgereth](https://github.com/mikeshultz/ledger-eth-lib) library based on [ledgerblue](https://github.com/LedgerHQ/blue-loader-python).
To enable, safe-cli must be installed as follows:
Expand All @@ -155,7 +158,19 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0004", MODE="0660
Safe-cli Ledger commands:
- `load_ledger_cli_owners [--legacy-accounts] [--derivation-path <str>]`: show a list of the first 5 accounts (--legacy-accounts search using ledger legacy derivation) or load an account from provided derivation path.
**NOTE**: before signing anything ensure that the data showing on your ledger is the same as the safe-cli data.
### Trezor
Trezor module is an optional feature of safe-cli to sign transactions from Trezor hardware wallet using the [trezor](https://pypi.org/project/trezor/).
To enable, safe-cli must be installed as follows:
```
pip install safe-cli[trezor]
```
### Enable multiple hardware wallets
```
pip install safe-cli[ledger, trezor]
```
## Creating a new Safe
Use `safe-creator <node_url> <private_key> --owners <checksummed_address_1> <checksummed_address_2> --threshold <uint> --salt-nonce <uint256>`.
Expand Down
11 changes: 11 additions & 0 deletions safe_cli/operators/hw_wallets/hw_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ def sign_typed_hash(self, domain_hash: bytes, message_hash: bytes) -> bytes:
:return: signature bytes
"""

@abstractmethod
def print_type(self) -> str:
"""
:return: str represantation of wallet type
"""
pass

def __str__(self):
return f"{self.print_type()} device with address {self.address}"

def __eq__(self, other):
if isinstance(other, HwWallet):
return (
Expand Down
21 changes: 10 additions & 11 deletions safe_cli/operators/hw_wallets/hw_wallet_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,33 @@ def delete_accounts(self, addresses: List[ChecksumAddress]) -> Set:
self.wallets = self.wallets.difference(accounts_to_remove)
return accounts_to_remove

def sign_eip712(self, safe_tx: SafeTx, accounts: List[HwWallet]) -> SafeTx:
def sign_eip712(self, safe_tx: SafeTx, wallets: List[HwWallet]) -> SafeTx:
"""
Call ledger ethereum app method to sign eip712 hashes with a ledger account
Sign a safeTx EIP-712 hashes with supported hw wallet devices
:param domain_hash:
:param message_hash:
:param account: ledger account
:return: bytes of signature
:param wallets: list of HwWallet
:return: signed safeTx
"""
encode_hash = eip712_encode(safe_tx.eip712_structured_data)
domain_hash = encode_hash[1]
message_hash = encode_hash[2]
for account in accounts:
for wallet in wallets:
print_formatted_text(
HTML(
"<ansired>Make sure in your ledger before signing that domain_hash and message_hash are both correct</ansired>"
f"<ansired>Make sure before signing in your {wallet} that the domain_hash and message_hash are both correct</ansired>"
)
)
print_formatted_text(HTML(f"Domain_hash: <b>{domain_hash.hex()}</b>"))
print_formatted_text(HTML(f"Message_hash: <b>{message_hash.hex()}</b>"))
signature = account.sign_typed_hash(domain_hash, message_hash)
signature = wallet.sign_typed_hash(domain_hash, message_hash)

# TODO should be refactored on safe_eth_py function insert_signature_sorted
# Insert signature sorted
if account.address not in safe_tx.signers:
new_owners = safe_tx.signers + [account.address]
if wallet.address not in safe_tx.signers:
new_owners = safe_tx.signers + [wallet.address]
new_owner_pos = sorted(new_owners, key=lambda x: int(x, 16)).index(
account.address
wallet.address
)
safe_tx.signatures = (
safe_tx.signatures[: 65 * new_owner_pos]
Expand Down
7 changes: 7 additions & 0 deletions safe_cli/operators/hw_wallets/ledger_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ def sign_typed_hash(self, domain_hash: bytes, message_hash: bytes) -> bytes:
)

return signature_to_bytes(signed.v, signed.r, signed.s)

def print_type(self) -> str:
"""
:return: str represantation of wallet type
"""
return "Ledger"
7 changes: 7 additions & 0 deletions safe_cli/operators/hw_wallets/trezor_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ def sign_typed_hash(self, domain_hash: bytes, message_hash: bytes) -> bytes:
self.client, n=address_n, domain_hash=domain_hash, message_hash=message_hash
)
return signed.signature

def print_type(self) -> str:
"""
:return: str represantation of wallet type
"""
return "Ledger"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"safe-eth-py==6.0.0b8",
"tabulate>=0.8",
],
extras_require={"ledger": ["ledgereth==0.9.1"]},
extras_require={"ledger": ["ledgereth==0.9.1"], "trezor": ["trezor==0.13.8"]},
packages=setuptools.find_packages(),
entry_points={
"console_scripts": [
Expand Down

0 comments on commit 66e4fdc

Please sign in to comment.