def debug_load_wallet(self, algo, seed_words, otp, pin, spv): self.wallet.load_seed(seed_words) self.wallet.struct.algo = algo self.wallet.struct.has_otp = otp self.wallet.struct.pin = pin self.wallet.struct.has_spv = spv self.wallet.save() return proto.Success(message='Wallet loaded')
def _reset_device2(self, random, pin, is_otp, is_spv): self.device.set_pin(pin) self.device.set_otp(is_otp) self.device.set_spv(is_spv) seed = tools.generate_seed(random) seed_words = tools.get_mnemonic(seed) self.device.load_seed(seed_words) print "PIN:", pin print "Seed:", seed print "Mnemonic:", seed_words print "Write down your seed and keep it secret!" return proto.Success()
def _process_message(self, msg): if isinstance(msg, proto.Initialize): self.set_main_state() m = self.wallet.get_features() m.session_id = msg.session_id return m if self.otp.is_waiting(): '''OTP response is expected''' if isinstance(msg, proto.OtpAck): return self.otp.check(msg.otp) if isinstance(msg, proto.OtpCancel): self.otp.cancel() return proto.Success(message="OTP cancelled") self.set_main_state() return proto.Failure(code=2, message='OTP expected') if self.pin.is_waiting(): '''PIN response is expected''' if isinstance(msg, proto.PinAck): return self.pin.check(msg.pin) if isinstance(msg, proto.PinCancel): self.pin_cancel() return proto.Success(message="PIN request cancelled") self.set_main_state() return proto.Failure(code=5, message='PIN expected') if self.yesno.is_waiting(): '''Button confirmation is expected''' if isinstance(msg, proto.ButtonAck): self.yesno.allow() return self.yesno.resolve() # Process if button has been already pressed if isinstance(msg, proto.ButtonCancel): self.set_main_state() return proto.Success(message="Button confirmation cancelled") self.set_main_state() return proto.Failure(code=2, message='Button confirmation expected') if isinstance(msg, proto.Ping): return proto.Success(message=msg.message) if isinstance(msg, proto.GetUUID): return proto.UUID(UUID=self.wallet.get_UUID()) if isinstance(msg, proto.GetEntropy): return self.protect_call(["Send %d bytes" % msg.size, "of entropy", "to computer?"], '', '{ Cancel', 'Confirm }', None, None, self._get_entropy, msg.size) if isinstance(msg, proto.GetMasterPublicKey): return proto.MasterPublicKey(key=self.wallet.get_master_public_key()) if isinstance(msg, proto.GetAddress): address = self.wallet.get_address(list(msg.address_n)) self.layout.show_receiving_address(address) self.custom_message = True # Yes button will redraw screen return proto.Address(address=address) if isinstance(msg, proto.SetMaxFeeKb): return self.protect_call(["Current maximal fee", "is %s per kB." % self.wallet.maxfee_kb, "Set transaction fee", "to %s per kB?" % msg.maxfee_kb], '', '{ Cancel', 'Confirm }', None, None, self._set_maxfee_kb, msg.maxfee_kb) if isinstance(msg, proto.ResetDevice): return self.protect_reset("Reset device?", '', '{ Cancel', 'Confirm }', None, msg.random) if isinstance(msg, (proto.SignTx, proto.TxInput, proto.TxOutput)): return self.signing.process_message(msg) self.set_main_state() return proto.Failure(code=1, message="Unexpected message")
def _reset_wallet(self, random): # TODO print "Starting setup wizard..." # self.wallet.save() return proto.Success()
def process_message(self, msg): if isinstance(msg, proto.Initialize): self.otp_cancel() self.pin_cancel() m = proto.Features() m.session_id = msg.session_id m.vendor = self.device.vendor m.major_version = self.device.major_version m.minor_version = self.device.minor_version m.otp = self.device.otp == True m.pin = self.device.pin != '' m.spv = self.device.spv == True m.algo.extend(self.device.algo) m.maxfee_kb = self.device.maxfee_kb m.debug_link = self.device.debug_link return m if self.otp != None: '''OTP response is expected''' if isinstance(msg, proto.OtpAck): return self.otp_check(msg.otp) if isinstance(msg, proto.OtpCancel): self.otp_cancel() return proto.Success(message="OTP cancelled") return proto.Failure(code=2, message='Waiting for OTP') if self.pin_func != None: '''PIN response is expected''' if isinstance(msg, proto.PinAck): return self.pin_check(msg.pin) if isinstance(msg, proto.PinCancel): self.pin_cancel() return proto.Success(message="PIN request cancelled") return proto.Failure(code=5, message='Waiting for PIN') if isinstance(msg, proto.Ping): return proto.Success(message=msg.message) if isinstance(msg, proto.GetUUID): return proto.UUID(UUID='device-UUID') if isinstance(msg, proto.GetEntropy): return self.protect_call( "Send %d bytes of entropy to computer?" % msg.size, None, None, self._get_entropy, msg.size) if isinstance(msg, proto.GetMasterPublicKey): return proto.MasterPublicKey( key=self.device.get_master_public_key(msg.algo)) if isinstance(msg, proto.SetMaxFeeKb): return self.protect_call("Current maximal fee is %s per kB. Set transaction fee to %s per kilobyte?" % \ (self.device.maxfee_kb, msg.maxfee_kb), None, None, self._set_maxfee_kb, msg.maxfee_kb) if isinstance(msg, proto.LoadDevice): return self.protect_call("Load device with custom seed?", None, None, self._load_device, msg.seed, msg.otp, msg.pin, msg.spv) if isinstance(msg, proto.ResetDevice): return self.protect_call("Reset device?", None, None, self._reset_device, msg.random) if isinstance(msg, proto.SignTx): print "<TODO: Print transaction details>" return self.protect_call("Sign transaction?", None, None, self._sign_tx, msg) return proto.Failure(code=1, message='Unknown method')
def _load_device(self, seed_words, otp, pin, spv): self.device.load_seed(seed_words) self.device.set_otp(otp) self.device.set_pin(pin) self.device.set_spv(spv) return proto.Success()
def _set_maxfee_kb(self, maxfee_kb): self.device.maxfee_kb = maxfee_kb return proto.Success()