-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'dump' option to ledgerctl CLI install command.
- Loading branch information
1 parent
ca3debd
commit a851c09
Showing
6 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import sys | ||
|
||
from ..client import LedgerIns, VersionInfo | ||
from .device import Device | ||
|
||
|
||
class FileDevice(Device): | ||
def __init__(self, target_id, out=None): | ||
if out is None: | ||
out = sys.stdout | ||
t_id = int(target_id, 16) | ||
self.version_info = VersionInfo.build( | ||
dict(target_id=t_id, se_version="0", flags=0, mcu_version="0") | ||
) | ||
self.buffer = None | ||
self.out = out | ||
|
||
@classmethod | ||
def enumerate_devices(cls): | ||
return None | ||
|
||
def open(self): | ||
pass | ||
|
||
def write(self, data: bytes): | ||
self.buffer = data | ||
if not self.buffer[1] == LedgerIns.GET_VERSION: | ||
print(data.hex(), file=self.out) | ||
|
||
def read(self, timeout: int = 0) -> bytes: | ||
if self.buffer[1] == LedgerIns.GET_VERSION: | ||
return self.version_info + b"\x90\x00" | ||
return b"\x00\x00\x00\x02\x90\x00" | ||
|
||
def exchange(self, data: bytes, timeout: int = 0) -> bytes: | ||
self.write(data) | ||
return self.read() | ||
|
||
def close(self): | ||
if self.out: | ||
self.out.close() |