예제 #1
0
async def sign_and_broadcast_operation_if_valid(
    duty: Duty,
    operation: Operation,
    signature_store: SignatoryDatabaseAPI,
    beacon_node: BeaconNodeAPI,
    private_key_provider: PrivateKeyProvider,
) -> None:
    try:
        await _validate_duty(duty, operation, signature_store)
    except ValidationError as e:
        logger.warning("a duty %s was not valid: %s", duty, e)
        return
    else:
        logger.debug(
            "received a valid duty %s for the operation with hash tree root %s; signing...",
            duty,
            humanize_bytes(operation.hash_tree_root),
        )

    await signature_store.record_signature_for(duty, operation)
    signature = sign(duty, operation, private_key_provider)

    operation_with_signature = _attach_signature(duty, operation, signature)

    logger.debug(
        "got signature %s for duty %s with (signed) hash tree root %s",
        humanize_bytes(signature),
        duty,
        humanize_bytes(operation_with_signature.hash_tree_root),
    )
    await beacon_node.publish(duty, operation_with_signature)
예제 #2
0
 async def publish(self, duty: Duty, signature: BLSSignature) -> None:
     self.logger.debug(
         "publishing %s with signature %s to beacon node",
         duty,
         humanize_bytes(signature),
     )
     self.published_signatures[duty] = signature
예제 #3
0
 def _load_key_file(self, key_file: Path) -> KeyPair:
     with open(key_file) as key_file_handle:
         keyfile_json = json.load(key_file_handle)
         public_key = decode_hex(keyfile_json["public_key"])
         if not self._demo_mode:
             self.logger.warn(
                 "please enter password for protected keyfile with public key %s:",
                 humanize_bytes(public_key),
             )
             password = getpass.getpass().encode()
         else:
             password = EMPTY_PASSWORD
         private_key = eth_keyfile.decode_keyfile_json(
             keyfile_json, password)
         return _compute_key_pair_from_private_key_bytes(private_key)