mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-01-09 06:50:58 +00:00
Some basic commands (still under heavy development)
This commit is contained in:
parent
52c50cd442
commit
c164eba47b
24
cmd.py
24
cmd.py
@ -14,7 +14,7 @@ def parse_args(commands):
|
|||||||
parser.add_argument('-dt', '--debuglink-transport', dest='debuglink_transport', choices=['usb', 'serial', 'pipe', 'socket'], default='socket', help="Debuglink transport")
|
parser.add_argument('-dt', '--debuglink-transport', dest='debuglink_transport', choices=['usb', 'serial', 'pipe', 'socket'], default='socket', help="Debuglink transport")
|
||||||
parser.add_argument('-dp', '--debuglink-path', dest='debuglink_path', default='0.0.0.0:8001', help="Path used by the transport (usually serial port)")
|
parser.add_argument('-dp', '--debuglink-path', dest='debuglink_path', default='0.0.0.0:8001', help="Path used by the transport (usually serial port)")
|
||||||
parser.add_argument('-j', '--json', dest='json', action='store_true', help="Prints result as json object")
|
parser.add_argument('-j', '--json', dest='json', action='store_true', help="Prints result as json object")
|
||||||
# parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='Enable low-level debugging messages')
|
parser.add_argument('-d', '--debug', dest='debug', action='store_true', help='Enable low-level debugging')
|
||||||
|
|
||||||
cmdparser = parser.add_subparsers(title='Available commands')
|
cmdparser = parser.add_subparsers(title='Available commands')
|
||||||
|
|
||||||
@ -51,8 +51,8 @@ def get_transport(transport_string, path):
|
|||||||
return PipeTransport(path, is_device=False)
|
return PipeTransport(path, is_device=False)
|
||||||
|
|
||||||
if transport_string == 'socket':
|
if transport_string == 'socket':
|
||||||
from bitkeylib.transport_socket import SocketTransport
|
from bitkeylib.transport_socket import SocketTransportClient
|
||||||
return SocketTransport(path, listen=False)
|
return SocketTransportClient(path)
|
||||||
|
|
||||||
if transport_string == 'fake':
|
if transport_string == 'fake':
|
||||||
from bitkeylib.transport_fake import FakeTransport
|
from bitkeylib.transport_fake import FakeTransport
|
||||||
@ -74,18 +74,34 @@ class Commands(object):
|
|||||||
def get_entropy(self, args):
|
def get_entropy(self, args):
|
||||||
return binascii.hexlify(self.client.get_entropy(args.size))
|
return binascii.hexlify(self.client.get_entropy(args.size))
|
||||||
|
|
||||||
|
def load_device(self, args):
|
||||||
|
seed = ' '.join(args.seed)
|
||||||
|
|
||||||
|
return self.client.load_device(seed, args.otp, args.pin, args.spv)
|
||||||
|
|
||||||
get_entropy.help = 'Get example entropy'
|
get_entropy.help = 'Get example entropy'
|
||||||
get_master_public_key.help = 'Get master public key'
|
get_master_public_key.help = 'Get master public key'
|
||||||
|
load_device.help = 'Load custom configuration to the device'
|
||||||
|
|
||||||
get_entropy.arguments = (
|
get_entropy.arguments = (
|
||||||
(('size',), {'type': int}),
|
(('size',), {'type': int}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
load_device.arguments = (
|
||||||
|
(('-s', '--seed'), {'type': str, 'nargs': '+'}),
|
||||||
|
(('-n', '--pin'), {'type': str, 'default': ''}),
|
||||||
|
(('-o', '--otp'), {'action': 'store_true'}),
|
||||||
|
(('-p', '--spv'), {'action': 'store_true'}),
|
||||||
|
)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args(Commands)
|
args = parse_args(Commands)
|
||||||
|
|
||||||
transport = get_transport(args.transport, args.path)
|
transport = get_transport(args.transport, args.path)
|
||||||
|
if args.debug:
|
||||||
debuglink_transport = get_transport(args.debuglink_transport, args.debuglink_path)
|
debuglink_transport = get_transport(args.debuglink_transport, args.debuglink_path)
|
||||||
|
else:
|
||||||
|
debuglink_transport = get_transport('fake', '')
|
||||||
|
|
||||||
if args.algorithm == 'electrum':
|
if args.algorithm == 'electrum':
|
||||||
algo = proto.ELECTRUM
|
algo = proto.ELECTRUM
|
||||||
@ -94,7 +110,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
raise Exception("Unknown algorithm")
|
raise Exception("Unknown algorithm")
|
||||||
|
|
||||||
client = BitkeyClient(transport, debuglink_transport, algo=algo)
|
client = BitkeyClient(transport, debuglink=None, algo=algo)
|
||||||
cmds = Commands(client)
|
cmds = Commands(client)
|
||||||
|
|
||||||
res = args.func(cmds, args)
|
res = args.func(cmds, args)
|
||||||
|
Loading…
Reference in New Issue
Block a user