def data(self, index, role=Qt.DisplayRole): data = None if not index.isValid(): return QVariant(data) if role not in [ Qt.DisplayRole, Qt.EditRole, Qt.ToolTipRole, Qt.FontRole, Qt.BackgroundRole ]: return None mn = self.smartnodes[index.row()] i = index.column() if i == self.ALIAS: data = mn.alias elif i == self.STATUS: status = self.manager.masternode_statuses.get( mn.get_collateral_str()) data = smartnode_status(status) if role == Qt.BackgroundRole: data = QBrush( QColor(ENABLED_SMARTNODE_BG)) if data[0] else None # Return the long description for data widget mappers. elif role == Qt.EditRole: data = data[2] else: data = data[1] elif i == self.VIN_PREVOUT_HASH: data = mn.vin.get('prevout_hash', '') elif i == self.VIN_PREVOUT_N: data = str(mn.vin.get('prevout_n', '')) elif i == self.VIN_ADDRESS: data = mn.vin.get('address', '') elif i == self.VIN_VALUE: data = str(mn.vin.get('value', '')) elif i == self.VIN_SCRIPTSIG: data = mn.vin.get('scriptSig', '') elif i == self.COLLATERAL: data = mn.collateral_key if role in [Qt.EditRole, Qt.DisplayRole, Qt.ToolTipRole] and data: data = bitcoin.public_key_to_p2pkh(bfh(data)) elif role == Qt.FontRole: data = util.MONOSPACE_FONT elif i == self.DELEGATE: data = mn.delegate_key if role in [Qt.EditRole, Qt.DisplayRole, Qt.ToolTipRole] and data: data = self.manager.get_delegate_privkey(data) elif role == Qt.FontRole: data = util.MONOSPACE_FONT elif i == self.ADDR: data = '' if mn.addr.ip: data = str(mn.addr) elif i == self.PROTOCOL_VERSION: data = mn.protocol_version return QVariant(data)
def sign_message(self, sequence, message, password): sig = None try: message = message.encode('utf8') inputPath = self.get_derivation() + "/%d/%d" % sequence msg_hash = Hash(msg_magic(message)) inputHash = to_hexstr(msg_hash) hasharray = [] hasharray.append({'hash': inputHash, 'keypath': inputPath}) hasharray = json.dumps(hasharray) msg = b'{"sign":{"meta":"sign message", "data":%s}}' % hasharray.encode( 'utf8') dbb_client = self.plugin.get_client(self) if not dbb_client.is_paired(): raise Exception(_("Could not sign message.")) reply = dbb_client.hid_send_encrypt(msg) self.handler.show_message( _("Signing message ...") + "\n\n" + _("To continue, touch the Digital Bitbox's blinking light for 3 seconds." ) + "\n\n" + _("To cancel, briefly touch the blinking light or wait for the timeout." )) reply = dbb_client.hid_send_encrypt( msg ) # Send twice, first returns an echo for smart verification (not implemented) self.handler.finished() if 'error' in reply: raise Exception(reply['error']['message']) if 'sign' not in reply: raise Exception(_("Could not sign message.")) if 'recid' in reply['sign'][0]: # firmware > v2.1.1 sig = bytes([27 + int(reply['sign'][0]['recid'], 16) + 4 ]) + binascii.unhexlify(reply['sign'][0]['sig']) pk, compressed = pubkey_from_signature(sig, msg_hash) pk = point_to_ser(pk.pubkey.point, compressed) addr = public_key_to_p2pkh(pk) if verify_message(addr, sig, message) is False: raise Exception(_("Could not sign message")) elif 'pubkey' in reply['sign'][0]: # firmware <= v2.1.1 for i in range(4): sig = bytes([27 + i + 4]) + binascii.unhexlify( reply['sign'][0]['sig']) try: addr = public_key_to_p2pkh( binascii.unhexlify(reply['sign'][0]['pubkey'])) if verify_message(addr, sig, message): break except Exception: continue else: raise Exception(_("Could not sign message")) except BaseException as e: self.give_error(e) return sig
def make_billing_address(wallet, num): long_id, short_id = wallet.get_user_id() xpub = make_xpub(get_billing_xpub(), long_id) version, _, _, _, c, cK = deserialize_xpub(xpub) cK, c = bitcoin.CKD_pub(cK, c, num) return bitcoin.public_key_to_p2pkh(cK)