def get_pubkey_derivation(self, x_pubkey): if x_pubkey[0:2] in ['02', '03', '04']: if x_pubkey in self.keypairs.keys(): return x_pubkey elif x_pubkey[0:2] == 'fd': # fixme: this assumes p2pkh _, addr = xpubkey_to_address(x_pubkey) for pubkey in self.keypairs.keys(): if public_key_to_p2pkh(pubkey.decode('hex')) == addr: return pubkey
def get_outputs(self): """convert pubkeys to addresses""" o = [] for type, x, v in self.outputs(): if type == TYPE_ADDRESS: addr = x elif type == TYPE_PUBKEY: addr = bitcoin.public_key_to_p2pkh(x.decode('hex')) else: addr = 'SCRIPT ' + x.encode('hex') o.append((addr, v)) # consider using yield (addr, v) return o
def get_outputs(self): """convert pubkeys to addresses""" o = [] for type, x, v in self.outputs(): if type == TYPE_ADDRESS: addr = x elif type == TYPE_PUBKEY: addr = bitcoin.public_key_to_p2pkh(x.decode('hex')) else: addr = 'SCRIPT ' + x.encode('hex') o.append((addr,v)) # consider using yield (addr, v) return o
def get_outputs(self): """convert pubkeys to addresses""" outputs = [] for o in self.outputs(): if o.type == TYPE_ADDRESS: addr = o.address elif o.type == TYPE_PUBKEY: # TODO do we really want this conversion? it's not really that address after all addr = bitcoin.public_key_to_p2pkh(bfh(o.address)) else: addr = 'SCRIPT ' + o.address outputs.append((addr, o.value)) # consider using yield (addr, v) return outputs
def xpubkey_to_address(x_pubkey): if x_pubkey[0:2] == 'fd': addrtype = ord(x_pubkey[2:4].decode('hex')) hash160 = x_pubkey[4:].decode('hex') address = bitcoin.hash_160_to_bc_address(hash160, addrtype) return x_pubkey, address if x_pubkey[0:2] in ['02', '03', '04']: pubkey = x_pubkey elif x_pubkey[0:2] == 'ff': xpub, s = BIP32_KeyStore.parse_xpubkey(x_pubkey) pubkey = BIP32_KeyStore.get_pubkey_from_xpub(xpub, s) elif x_pubkey[0:2] == 'fe': mpk, s = Old_KeyStore.parse_xpubkey(x_pubkey) pubkey = Old_KeyStore.get_pubkey_from_mpk(mpk, s[0], s[1]) else: raise BaseException("Cannot parse pubkey") if pubkey: address = public_key_to_p2pkh(pubkey.decode('hex')) return pubkey, address
def xpubkey_to_address(x_pubkey): if x_pubkey[0:2] == 'fd': addrtype = ord(x_pubkey[2:4].decode('hex')) hash160 = x_pubkey[4:].decode('hex') address = bitcoin.hash_160_to_bc_address(hash160, addrtype) return x_pubkey, address if x_pubkey[0:2] in ['02','03','04']: pubkey = x_pubkey elif x_pubkey[0:2] == 'ff': xpub, s = BIP32_KeyStore.parse_xpubkey(x_pubkey) pubkey = BIP32_KeyStore.get_pubkey_from_xpub(xpub, s) elif x_pubkey[0:2] == 'fe': mpk, s = Old_KeyStore.parse_xpubkey(x_pubkey) pubkey = Old_KeyStore.get_pubkey_from_mpk(mpk, s[0], s[1]) else: raise BaseException("Cannot parse pubkey") if pubkey: address = public_key_to_p2pkh(pubkey.decode('hex')) return pubkey, address
def sign_announce(self, alias, password): """Sign a Masternode Announce message for alias.""" self.check_can_sign_masternode(alias) mn = self.get_masternode(alias) # Ensure that the masternode's vin is valid. if mn.vin.get('scriptSig') is None: mn.vin['scriptSig'] = '' if mn.vin.get('sequence') is None: mn.vin['sequence'] = 0xffffffff # Ensure that the masternode's last_ping is current. height = self.wallet.get_local_height() - 12 header = self.wallet.network.get_header(height) mn.last_ping.block_hash = Blockchain.hash_header(header) mn.last_ping.vin = mn.vin # Sign ping with delegate key. self.wallet.sign_masternode_ping(mn.last_ping, mn.delegate_key) # After creating the Masternode Ping, sign the Masternode Announce. address = bitcoin.public_key_to_p2pkh(mn.collateral_key.decode('hex')) mn.sig = self.wallet.sign_message(address, mn.serialize_for_sig(update_time=True), password) return mn
def verify(self, addr=None): """Verify that our sig is signed with addr's key.""" if not addr: addr = bitcoin.public_key_to_p2pkh( self.collateral_key.decode('hex')) return bitcoin.verify_message(addr, self.sig, self.serialize_for_sig())
def get_address(self, for_change, n): pubkey = self.get_pubkey(for_change, n) address = public_key_to_p2pkh(pubkey.decode('hex')) return address