Implemented ApplySettings, removed SetMaxFeeKb

pull/1/head
slush0 11 years ago
parent 31aa66e1a2
commit 8d100bee0c

@ -37,7 +37,6 @@ class BitkeyClient(object):
def init_device(self):
self.master_public_key = None
self.features = self.call(proto.Initialize())
self.uuid = self.get_uuid()
def get_master_public_key(self):
if self.master_public_key:
@ -51,7 +50,23 @@ class BitkeyClient(object):
def get_entropy(self, size):
return self.call(proto.GetEntropy(size=size)).entropy
def ping(self, msg):
return self.call(proto.Ping(message=msg)).message
def get_serial_number(self):
return self.features.serial_number
def apply_settings(self, label=None, coin_shortcut=None, language=None):
settings = proto.ApplySettings()
if label:
settings.label = label
if coin_shortcut:
settings.coin_shortcut = coin_shortcut
if language:
settings.language = language
return self.call(settings).message
def _pprint(self, msg):
return "<%s>:\n%s" % (msg.__class__.__name__, msg)
@ -108,12 +123,6 @@ class BitkeyClient(object):
print "Received", self._pprint(resp)
return resp
def ping(self, msg):
return self.call(proto.Ping(message=msg)).message
def get_uuid(self):
return self.call(proto.GetUUID()).UUID
def sign_tx(self, inputs, outputs):
'''
@ -233,4 +242,4 @@ class BitkeyClient(object):
def load_device(self, seed, pin):
resp = self.call(proto.LoadDevice(seed=seed, pin=pin))
self.init_device()
return isinstance(resp, proto.Success)
return isinstance(resp, proto.Success)

@ -5,8 +5,8 @@ map_type_to_class = {
1: proto.Ping,
2: proto.Success,
3: proto.Failure,
4: proto.GetUUID,
5: proto.UUID,
#4: proto.GetUID,
#5: proto.UUID,
9: proto.GetEntropy,
10: proto.Entropy,
11: proto.GetMasterPublicKey,
@ -14,7 +14,7 @@ map_type_to_class = {
13: proto.LoadDevice,
14: proto.ResetDevice,
15: proto.SignTx,
# 16: proto.SignedTx,
16: proto.SimpleSignTx,
17: proto.Features,
18: proto.PinMatrixRequest,
19: proto.PinMatrixAck,
@ -23,12 +23,15 @@ map_type_to_class = {
# 22: proto.OutputRequest,
23: proto.TxInput,
24: proto.TxOutput,
25: proto.SetMaxFeeKb,
25: proto.ApplySettings,
26: proto.ButtonRequest,
27: proto.ButtonAck,
28: proto.ButtonCancel,
29: proto.GetAddress,
30: proto.Address,
31: proto.SettingsType,
32: proto.XprvType,
33: proto.CoinType,
100: proto.DebugLinkDecision,
101: proto.DebugLinkGetState,
102: proto.DebugLinkState,

@ -3,10 +3,10 @@ import binascii
import argparse
import json
import bitkeylib.trezor_pb2 as proto
from bitkeylib.client import BitkeyClient
from bitkeylib.debuglink import DebugLink
from bitkeylib.protobuf_json import pb2json
def parse_args(commands):
parser = argparse.ArgumentParser(description='Commandline tool for Bitkey devices.')
parser.add_argument('-t', '--transport', dest='transport', choices=['usb', 'serial', 'pipe', 'socket'], default='usb', help="Transport used for talking with the device")
@ -87,22 +87,38 @@ class Commands(object):
def get_entropy(self, args):
return binascii.hexlify(self.client.get_entropy(args.size))
def get_features(self, args):
return pb2json(self.client.features)
def ping(self, args):
return self.client.ping(args.msg)
def get_master_public_key(self, args):
return binascii.hexlify(self.client.get_master_public_key())
def get_uuid(self, args):
return binascii.hexlify(self.client.get_uuid())
def get_serial_number(self, args):
return binascii.hexlify(self.client.get_serial_number())
def set_label(self, args):
return self.client.apply_settings(label=args.label)
def set_coin(self, args):
return self.client.apply_settings(coin_shortcut=args.coin_shortcut)
def load_device(self, args):
seed = ' '.join(args.seed)
return self.client.load_device(seed, args.pin)
list.help = 'List connected Trezor USB devices'
ping.help = 'Send ping message'
get_address.help = 'Get bitcoin address in base58 encoding'
get_entropy.help = 'Get example entropy'
get_uuid.help = 'Get device\'s unique identifier'
get_features.help = 'Retrieve device features and settings'
get_serial_number.help = 'Get device\'s unique identifier'
get_master_public_key.help = 'Get master public key'
set_label.help = 'Set new wallet label'
set_coin.help = 'Switch device to another crypto currency'
load_device.help = 'Load custom configuration to the device'
get_address.arguments = (
@ -112,7 +128,21 @@ class Commands(object):
get_entropy.arguments = (
(('size',), {'type': int}),
)
get_features.arguments = ()
ping.arguments = (
(('msg',), {'type': str}),
)
set_label.arguments = (
(('label',), {'type': str}),
)
set_coin.arguments = (
(('coin_shortcut',), {'type': str}),
)
load_device.arguments = (
(('-s', '--seed'), {'type': str, 'nargs': '+'}),
(('-n', '--pin'), {'type': str, 'default': ''}),
@ -149,7 +179,7 @@ def main():
res = args.func(cmds, args)
if args.json:
print json.dumps(res)
print json.dumps(res, sort_keys=True, indent=4)
else:
print res

@ -3,7 +3,7 @@
Author: Marek "slush" Palatinus <info@bitcoin.cz>
Version: 0.1
Version: 0.4
*/
// Specifies which script will be used for given transaction output.
@ -18,7 +18,31 @@ enum RequestType {
TXOUTPUT = 1;
}
// Ask for device details
// Structure for BIP32-encoded node
// Used for imports into the device
message XprvType {
required bytes version = 1;
required uint32 depth = 2;
required uint32 fingerprint = 3;
required uint32 child_num = 4;
required bytes chain_code = 5;
required bytes private_key = 6;
}
message CoinType {
optional bytes coin_name = 2;
optional bytes coin_shortcut = 3;
optional uint32 address_type = 4;
optional uint64 maxfee_kb = 5;
}
message SettingsType {
optional bytes language = 1; // Trezor uses 'english' as default
optional CoinType coin = 2;
optional bytes label = 3; // Human readable wallet name
}
// Reset device to default state and ask for device details
//
// Response: Features
message Initialize {
@ -29,7 +53,15 @@ message Features {
optional bytes vendor = 1; // Name of the manufacturer, e.g. "trezor"
optional uint32 major_version = 2; // Major version of the device, e.g. 1
optional uint32 minor_version = 3; // Minor version of the device, e.g. 0
optional uint64 maxfee_kb = 4; // Maximum accepted fee per kilobyte of signed transaction
optional SettingsType settings = 4; // User-level settings of the device
optional bytes serial_number = 5; // Device's unique identifier
}
// Overwrites only filled fields of the structure
message ApplySettings {
optional bytes language = 1;
optional bytes coin_shortcut = 2;
optional bytes label = 3;
}
// Test if device is live, device will send back the message on success
@ -82,18 +114,6 @@ message Failure {
optional bytes message = 2; // May contain human-readable message of the error state
}
// Ask device for unique identifier.
//
// Response: UUID
message GetUUID {
}
// Identifier of the device. This identifier must be composed from CPU serial number
// or other persistent source and must be the same for consecutive requests.
message UUID {
required bytes UUID = 1;
}
// Message can be sent by the *device* as a resopnse to any request.
// Device is waiting for HW button press. No action is required from computer
// Computer should respond with ButtonAck message or ButtonCancel to cancel
@ -140,15 +160,6 @@ message Entropy {
required bytes entropy = 1; // Stream of generated bytes
}
// Set maximum allowed fee per kB of transaction. This is used by internal sanity checking
// in SignTx method. Transaction won't be signed if requested transaction fees are above
// current value.
//
// Response: Success, PinMatrixRequest, Failure
message SetMaxFeeKb {
required uint64 maxfee_kb = 1; // Maximum allowed transaction fee in satoshis per kB
}
// Ask device for it's current master public key. This may be used for generating
// public keys on the computer independently to the device. API doesn't provide
// any other way how to get bitcoin addresses from the device.
@ -174,8 +185,9 @@ message Address {
//
// Response: Success, PinMatrixRequest, Failure
message LoadDevice {
required bytes seed = 1; // Seed encoded as a mnemonic (12 english words)
optional bytes pin = 2; // Set PIN protection for important actions
optional bytes seed = 1; // Seed encoded as a mnemonic (12 english words)
optional XprvType xprv = 2;
optional bytes pin = 3; // Set PIN protection for important actions
}
// Request device to do full-reset, to generate new seed
@ -195,6 +207,23 @@ message SignTx {
required uint32 inputs_count = 5; // Count of inputs of the transaction
}
// Request a simplified workflow of signing.
// This method doesn't support streaming,
// so there may be hardware limits
// in number of inputs and outputs.
//
// This simplified workflow should not be used
// in production, it is designed mainly for debug purposes.
//
// When everything is fine, Success.message contains
// serialized transaction.
//
// Response: Success, PinMatrixRequest, Failure
message SimpleSignTx {
repeated TxInput inputs = 1;
repeated TxOutput outputs = 2;
}
// Sent by the device as a response for SignTx. Device asks for information for signing transaction.
// If request_index is set, device asks for TxInput/TxOutput message (depends on request_type)
// with details of index's input.

@ -14,7 +14,7 @@ class BitkeyTest(unittest.TestCase):
self.bitkey.setup_debuglink(button=True, pin_correct=True)
self.bitkey.load_device(
seed='beyond neighbor scratch swirl embarrass doll cause also stick softly physical nice',
seed='soda country ghost glove unusual dose blouse cope bless medal block car',
pin='1234')
print "Setup finished"

Loading…
Cancel
Save