<s> __author__ = '<STR_LIT>' <EOL> from binascii import hexlify , unhexlify <EOL> import nacl . signing <EOL> import nacl . hash <EOL> import nacl . encoding <EOL> def _testpow ( pow_hash ) : <EOL> return True if int ( pow_hash , <NUM_LIT:16> ) < <NUM_LIT:50> else False <EOL> class GUID ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , keys = None , use_C_lib = False ) : <EOL> if keys is None : <EOL> if use_C_lib : <EOL> self . privkey = None <EOL> self . signing_key = nacl . signing . SigningKey ( self . privkey ) <EOL> self . verify_key = verify_key = self . signing_key . verify_key <EOL> h = nacl . hash . sha512 ( verify_key . encode ( ) ) <EOL> self . guid = unhexlify ( h [ : <NUM_LIT> ] ) <EOL> else : <EOL> self . generate ( ) <EOL> else : <EOL> self . signing_key , self . verify_key , self . guid = keys <EOL> def generate ( self ) : <EOL> valid_pow = False <EOL> while not valid_pow : <EOL> signing_key = nacl . signing . SigningKey . generate ( ) <EOL> verify_key = signing_key . verify_key <EOL> h = nacl . hash . sha512 ( verify_key . encode ( ) ) <EOL> pow_hash = h [ <NUM_LIT> : ] <EOL> valid_pow = _testpow ( pow_hash [ : <NUM_LIT:6> ] ) <EOL> self . signing_key = signing_key <EOL> self . verify_key = verify_key <EOL> self . guid = unhexlify ( h [ : <NUM_LIT> ] ) <EOL> @ classmethod <EOL> def from_privkey ( cls , privkey ) : <EOL> signing_key = nacl . signing . SigningKey ( privkey , encoder = nacl . encoding . HexEncoder ) <EOL> verify_key = signing_key . verify_key <EOL> h = nacl . hash . sha512 ( verify_key . encode ( ) ) <EOL> pow_hash = h [ <NUM_LIT> : ] <EOL> if _testpow ( pow_hash [ : <NUM_LIT:6> ] ) : <EOL> return GUID ( ( signing_key , verify_key , unhexlify ( h [ : <NUM_LIT> ] ) ) ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( <EOL> self . signing_key . encode ( encoder = nacl . encoding . HexEncoder ) , <EOL> self . verify_key . encode ( encoder = nacl . encoding . HexEncoder ) , <EOL> hexlify ( self . guid ) ) </s>
