Пример #1
0
 def export_to_wif(self):
     """Export a key to WIF.
     See https://en.bitcoin.it/wiki/Wallet_import_format for a full
     description.
     """
     # Add the network byte, creating the "extended key"
     extended_key_hex = self.private_key.get_extended_key()
     # BIP32 wallets have a trailing \01 byte
     extended_key_bytes = unhexlify(extended_key_hex) + b"\01"
     # And return the base58-encoded result with a checksum
     return base58.b58encode_check(extended_key_bytes)
Пример #2
0
 def to_address(self):
     """Create a public address from this Wallet.
     Public addresses can accept payments.
     https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses
     """
     key = unhexlify(self.get_public_key_hex())
     # First get the hash160 of the key
     hash160_bytes = hash160(key)
     # Prepend the network address byte
     network_hash160_bytes = chr_py2(self.network.PUBKEY_ADDRESS) + hash160_bytes
     # Return a base58 encoded address with a checksum
     return ensure_str(base58.b58encode_check(network_hash160_bytes))
Пример #3
0
 def to_address(self, compressed=None):
     """Create a public address from this key.
     :param compressed: False if you want a normal uncompressed address
         (the most standard option). True if you want the compressed form.
         Note that most clients will not accept compressed addresses.
         Defaults to None, which in turn uses the self.compressed attribute.
     :type compressed: bool
     https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresses
     """
     key = unhexlify(self.get_key(compressed))
     # First get the hash160 of the key
     hash160_bytes = hash160(key)
     # Prepend the network address byte
     network_hash160_bytes = chr_py2(self.network.PUBKEY_ADDRESS) + hash160_bytes
     # Return a base58 encoded address with a checksum
     return ensure_str(base58.b58encode_check(network_hash160_bytes))
Пример #4
0
 def export_to_wif(self, compressed=None):
     """Export a key to WIF.
     :param compressed: False if you want a standard WIF export (the most
         standard option). True if you want the compressed form (Note that
         not all clients will accept this form). Defaults to None, which
         in turn uses the self.compressed attribute.
     :type compressed: bool
     See https://en.bitcoin.it/wiki/Wallet_import_format for a full
     description.
     """
     # Add the network byte, creating the "extended key"
     extended_key_hex = self.get_extended_key()
     extended_key_bytes = unhexlify(extended_key_hex)
     if compressed is None:
         compressed = self.compressed
     if compressed:
         extended_key_bytes += "\01"
     # And return the base58-encoded result with a checksum
     return ensure_str(base58.b58encode_check(extended_key_bytes))
Пример #5
0
 def serialize_b58(self, private=True):
     """Encode the serialized node in base58."""
     return ensure_str(base58.b58encode_check(unhexlify(self.serialize(private))))