Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parse_fallback(fallback, currency):
if currency == 'bc' or currency == 'tb':
wver = fallback[0:5].uint
if wver == 17:
addr=base58.b58encode_check(bytes([base58_prefix_map[currency][0]])
+ fallback[5:].tobytes())
elif wver == 18:
addr=base58.b58encode_check(bytes([base58_prefix_map[currency][1]])
+ fallback[5:].tobytes())
elif wver <= 16:
addr=bech32_encode(currency, bitarray_to_u5(fallback))
else:
return None
else:
addr=fallback.tobytes()
return addr
def b58encode(self) -> str:
""" Generates a Base58Check encoding of this key.
"""
return base58.b58encode_check(bytes(self)).decode('ascii')
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
"""
# 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))
def publicKeyGenerator():
sk = ecdsa.SigningKey.from_string(start[0:64].decode('hex'), curve=ecdsa.SECP256k1)
vk = sk.verifying_key
publicKey = ('\04' + sk.verifying_key.to_string()).encode('hex')
ripemd160 = hashlib.new('ripemd160')
ripemd160.update(hashlib.sha256(publicKey.decode('hex')).digest())
address = base58.b58encode_check(chr(0) + ripemd160.digest())
print("Public Address: " + address)
addrFile = address[-8:]
img2 = qrcode.make(address)
img2.save("Address_" + addrFile + ".png")
def from_hex(address):
"""Helper function that will convert a generic value from hex
Args:
address (str): address
"""
return base58.b58encode_check(bytes.fromhex(address))
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))
def _base58_encode(data):
"""create a base58 encoded string with checksum"""
return base58.b58encode_check(data).decode("ascii")
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)
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)