def _read_signer(key_filename): """Reads the given file as a hex key. Args: key_filename: The filename where the key is stored. If None, defaults to the default key for the current user. Returns: Signer: the signer Raises: CliException: If unable to read the file. """ filename = key_filename if filename is None: filename = os.path.join(config.get_key_dir(), 'validator.priv') try: with open(filename, 'r') as key_file: signing_key = key_file.read().strip() except IOError as e: raise CliException('Unable to read key file: {}'.format(str(e))) try: private_key = Secp256k1PrivateKey.from_hex(signing_key) except ParseError as e: raise CliException('Unable to read key in file: {}'.format(str(e))) context = create_context('secp256k1') crypto_factory = CryptoFactory(context) return crypto_factory.new_signer(private_key)
def _read_signing_keys(key_filename): """Reads the given file as a default-encoded private key Args: key_filename: The filename where the key is stored. If None, defaults to the default key for the validator Returns: tuple (str, str): the public and private key pair Raises: CliException: If unable to read the file. """ filename = key_filename if key_filename is None: filename = os.path.join(config.get_key_dir(), 'validator.priv') try: with open(filename, 'r') as key_file: signing_key = key_file.read().strip() public_key = signing.generate_public_key(signing_key) return public_key, signing_key except IOError as e: raise CliException('Unable to read key file: {}'.format(str(e)))
def _read_signing_keys(key_filename): """Reads the given file as a default-encoded private key Args: key_filename: The filename where the key is stored. If None, defaults to the default key for the validator Returns: tuple (str, str): the public and private key pair Raises: CliException: If unable to read the file. """ filename = key_filename if key_filename is None: filename = os.path.join(config.get_key_dir(), 'validator.priv') try: with open(filename, 'r') as key_file: signing_key = key_file.read().strip() pubkey = signing.generate_pubkey(signing_key) return pubkey, signing_key except IOError as e: raise CliException('Unable to read key file: {}'.format(str(e)))