Python base58.b58encode_check() Examples
The following are 30
code examples of base58.b58encode_check().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
base58
, or try the search function
.
Example #1
Source File: keys.py From pywallet with MIT License | 6 votes |
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))
Example #2
Source File: bip38.py From moneywagon with MIT License | 6 votes |
def create(cls, flagbyte, ownerentropy, factorb, derivedhalf1, derivedhalf2, addresshash): pointb = compress(*fast_multiply(G, factorb)) pointbprefix = bytearray([ord(pointb[:1]) ^ (ord(derivedhalf2[-1:]) & 1)]) aes = AES.new(derivedhalf2) block1 = long(hexlify(pointb[1:17]), 16) ^ long(hexlify(derivedhalf1[:16]), 16) pointbx1 = aes.encrypt(unhexlify("%0.32x" % block1)) block2 = long(hexlify(pointb[17:]), 16) ^ long(hexlify(derivedhalf1[16:]), 16) pointbx2 = aes.encrypt(unhexlify("%0.32x" % block2)) # 33 bytes 1 16 16 encryptedpointb = pointbprefix + pointbx1 + pointbx2 # 5 (cfrm38 prefix) 1 4 8 33 payload = b'\x64\x3B\xF6\xA8\x9A' + flagbyte + addresshash + ownerentropy + encryptedpointb return cls(b58encode_check(payload))
Example #3
Source File: keys.py From multimerchant-python with MIT License | 6 votes |
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))
Example #4
Source File: keys.py From multimerchant-python with MIT License | 6 votes |
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))
Example #5
Source File: keys.py From pywallet with MIT License | 6 votes |
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))
Example #6
Source File: ethereum.py From pywallet with MIT License | 6 votes |
def address(self, compressed=True, testnet=False): """ Address property that returns the Base58Check encoded version of the HASH160. Args: compressed (bool): Whether or not the compressed key should be used. testnet (bool): Whether or not the key is intended for testnet usage. False indicates mainnet usage. Returns: bytes: Base58Check encoded string """ version = '0x' return version + binascii.hexlify(self.keccak[12:]).decode('ascii') # Put the version byte in front, 0x00 for Mainnet, 0x6F for testnet # version = bytes([self.TESTNET_VERSION]) if testnet else bytes([self.MAINNET_VERSION]) # return base58.b58encode_check(version + self.hash160(compressed))
Example #7
Source File: __init__.py From moneywagon with MIT License | 6 votes |
def change_version_byte(address, new_version=None, new_crypto=None): """ Convert the passed in address (or any base58 encoded string), and change the version byte to `new_version`. """ if not new_version and new_crypto: try: new_version = crypto_data[new_crypto]['address_version_byte'] except KeyError: raise CurrencyNotSupported("Unknown currency symbol: " + new_crypto) if not new_version: raise CurrencyNotSupported("Can't yet make %s addresses." % new_crypto) payload = b58decode_check(address)[1:] if is_py2: byte = chr(new_version) else: byte = bytes(chr(new_version), 'ascii') return b58encode_check(byte + payload)
Example #8
Source File: keys.py From bitmerchant with MIT License | 6 votes |
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(ensure_bytes(extended_key_hex)) if compressed is None: compressed = self.compressed if compressed: extended_key_bytes += b'\01' # And return the base58-encoded result with a checksum return ensure_str(base58.b58encode_check(extended_key_bytes))
Example #9
Source File: keys.py From bitmerchant with MIT License | 6 votes |
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(ensure_bytes(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))
Example #10
Source File: bip32.py From pywallet with MIT License | 5 votes |
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))
Example #11
Source File: hd_private_key.py From ontology-python-sdk with GNU Lesser General Public License v3.0 | 5 votes |
def b58encode(self) -> str: """ Generates a Base58Check encoding of this private key. """ return base58.b58encode_check(bytes(self)).decode('ascii')
Example #12
Source File: ethereum.py From pywallet with MIT License | 5 votes |
def to_b58check(self, testnet=False): """ Generates a Base58Check encoding of this key. Args: testnet (bool): True if the key is to be used with testnet, False otherwise. Returns: str: A Base58Check encoded string representing the key. """ b = self.testnet_bytes if testnet else bytes(self) return base58.b58encode_check(b)
Example #13
Source File: testvectors.py From slips with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def b58xprv(parent_fingerprint, private_key, chain, depth, childnr): raw = ('\x04\x88\xad\xe4' + chr(depth) + parent_fingerprint + int_to_string(childnr, 4) + chain + '\x00' + private_key) return b58encode_check(raw)
Example #14
Source File: testvectors.py From slips with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def b58xpub(parent_fingerprint, public_key, chain, depth, childnr): raw = ('\x04\x88\xb2\x1e' + chr(depth) + parent_fingerprint + int_to_string(childnr, 4) + chain + public_key) return b58encode_check(raw)
Example #15
Source File: encoding.py From pytezos with MIT License | 5 votes |
def base58_encode(v: bytes, prefix: bytes) -> bytes: try: encoding = next( encoding for encoding in base58_encodings if len(v) == encoding[3] and prefix == encoding[0] ) except StopIteration: raise ValueError('Invalid encoding, prefix or length mismatch.') return base58.b58encode_check(encoding[2] + v)
Example #16
Source File: bip38.py From moneywagon with MIT License | 5 votes |
def encrypt(cls, crypto, privkey, passphrase): """ BIP0038 non-ec-multiply encryption. Returns BIP0038 encrypted privkey. """ pub_byte, priv_byte = get_magic_bytes(crypto) privformat = get_privkey_format(privkey) if privformat in ['wif_compressed','hex_compressed']: compressed = True flagbyte = b'\xe0' if privformat == 'wif_compressed': privkey = encode_privkey(privkey, 'hex_compressed') privformat = get_privkey_format(privkey) if privformat in ['wif', 'hex']: compressed = False flagbyte = b'\xc0' if privformat == 'wif': privkey = encode_privkey(privkey,'hex') privformat = get_privkey_format(privkey) pubkey = privtopub(privkey) addr = pubtoaddr(pubkey, pub_byte) passphrase = normalize('NFC', unicode(passphrase)) if is_py2: ascii_key = addr passphrase = passphrase.encode('utf8') else: ascii_key = bytes(addr,'ascii') salt = sha256(sha256(ascii_key).digest()).digest()[0:4] key = scrypt.hash(passphrase, salt, 16384, 8, 8) derivedhalf1, derivedhalf2 = key[:32], key[32:] aes = AES.new(derivedhalf2) encryptedhalf1 = aes.encrypt(unhexlify('%0.32x' % (long(privkey[0:32], 16) ^ long(hexlify(derivedhalf1[0:16]), 16)))) encryptedhalf2 = aes.encrypt(unhexlify('%0.32x' % (long(privkey[32:64], 16) ^ long(hexlify(derivedhalf1[16:32]), 16)))) # 39 bytes 2 (6P) 1(R/Y) 4 16 16 payload = b'\x01\x42' + flagbyte + salt + encryptedhalf1 + encryptedhalf2 return cls(crypto, b58encode_check(payload))
Example #17
Source File: bip38.py From moneywagon with MIT License | 5 votes |
def create(cls, passphrase, seed=None, ownersalt=None, lot=None, sequence=None): passphrase = normalize('NFC', unicode(passphrase)) if is_py2: passphrase = passphrase.encode('utf8') if seed and not is_py2: seed = bytes(seed, 'ascii') if ownersalt and len(ownersalt) != 8: raise Exception("Invalid salt") if lot and sequence: if not ownersalt: ownersalt = sha256(seed).digest()[:4] lotseq = unhexlify("%0.8x" % (self.lotseq_constant * lot + sequence)) ownerentropy = ownersalt + lotseq else: if not ownersalt: ownersalt = ownerentropy = sha256(seed).digest()[:8] else: ownerentropy = ownersalt prefactor = scrypt.hash(passphrase, ownersalt, 16384, 8, 8, 32) if lot and sequence: passfactor = sha256(sha256(prefactor + ownerentropy).digest()).digest() else: passfactor = prefactor passpoint = compress(*fast_multiply(G, bytes_to_int(passfactor))) last_byte = b'\x53' if not lot and not sequence else b'\x51' # 7 1 8 33 payload = b'\x2C\xE9\xB3\xE1\xFF\x39\xE2' + last_byte + ownerentropy + passpoint return cls(b58encode_check(payload))
Example #18
Source File: tinychain.py From tinychain with MIT License | 5 votes |
def pubkey_to_address(pubkey: bytes) -> str: if 'ripemd160' not in hashlib.algorithms_available: raise RuntimeError('missing ripemd160 hash algorithm') sha = hashlib.sha256(pubkey).digest() ripe = hashlib.new('ripemd160', sha).digest() return b58encode_check(b'\x00' + ripe)
Example #19
Source File: glacierscript.py From GlacierProtocol with MIT License | 5 votes |
def hex_private_key_to_WIF_private_key(hex_key): """ Converts a raw 256-bit hex private key to WIF format returns => <string> in hex format """ hex_key_with_prefix = wif_prefix + hex_key + "01" wif_key = b58encode_check(bytes.fromhex(hex_key_with_prefix)) return wif_key.decode('ascii') ################################################################################################ # # Bitcoin helper functions # ################################################################################################
Example #20
Source File: bip32.py From pywallet with MIT License | 5 votes |
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)
Example #21
Source File: account.py From tron-api-python with MIT License | 5 votes |
def address(self): public_key = self._key.public_key address = '41' + public_key.to_address()[2:] to_base58 = base58.b58encode_check(bytes.fromhex(address)) # If bytecode then convert to string if is_bytes(to_base58): to_base58 = to_base58.decode() return AttributeDict({ 'hex': address, 'base58': to_base58 })
Example #22
Source File: account.py From tron-api-python with MIT License | 5 votes |
def from_hex(address): """Helper function that will convert a generic value from hex""" if not is_hex(address): return address return base58.b58encode_check(bytes.fromhex(address))
Example #23
Source File: bip32.py From bitmerchant with MIT License | 5 votes |
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(ensure_bytes(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))
Example #24
Source File: bip32.py From bitmerchant with MIT License | 5 votes |
def serialize_b58(self, private=True): """Encode the serialized node in base58.""" return ensure_str( base58.b58encode_check( unhexlify(ensure_bytes(self.serialize(private)))))
Example #25
Source File: bip32.py From pywallet with MIT License | 5 votes |
def serialize_b58(self, private=True): """Encode the serialized node in base58.""" return ensure_str( base58.b58encode_check(unhexlify(self.serialize(private))))
Example #26
Source File: bip32.py From bitmerchant with MIT License | 5 votes |
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(ensure_bytes(extended_key_hex)) + b'\01' # And return the base58-encoded result with a checksum return base58.b58encode_check(extended_key_bytes)
Example #27
Source File: hd_public_key.py From ontology-python-sdk with GNU Lesser General Public License v3.0 | 5 votes |
def b58encode(self) -> str: """ Generates a Base58Check encoding of this key. """ return base58.b58encode_check(bytes(self)).decode('ascii')
Example #28
Source File: bip32.py From multimerchant-python with MIT License | 5 votes |
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))
Example #29
Source File: bip32.py From multimerchant-python with MIT License | 5 votes |
def serialize_b58(self, private=True): """Encode the serialized node in base58.""" return ensure_str( base58.b58encode_check(unhexlify(self.serialize(private))))
Example #30
Source File: mnemonic_utils.py From ethereum-mnemonic-utils with MIT License | 5 votes |
def b58xprv(parent_fingerprint, private_key, chain, depth, childnr): """ Private key b58 serialization format. """ raw = ( b'\x04\x88\xad\xe4' + bytes(chr(depth), 'utf-8') + parent_fingerprint + childnr.to_bytes(4, byteorder='big') + chain + b'\x00' + private_key) return b58encode_check(raw)