Beispiel #1
0
 def __create_trustee(self, registry, transacting: bool = False) -> Trustee:
     client_password = None
     is_clef = ClefSigner.is_valid_clef_uri(self.signer_uri)
     if transacting and not self.hw_wallet and not is_clef:
         client_password = get_client_password(checksum_address=self.checksum_address)
     trustee = Trustee(checksum_address=self.checksum_address, registry=registry, client_password=client_password)
     return trustee
Beispiel #2
0
    def create_character(self,
                         emitter,
                         config_file,
                         json_ipc,
                         load_seednodes=True):

        # TODO: embed compatibility layer?
        ursula_config = self.config_options.create_config(emitter, config_file)
        is_clef = ClefSigner.is_valid_clef_uri(self.config_options.signer_uri)

        # TODO: Oh
        client_password = None
        if not ursula_config.federated_only:
            if not self.config_options.dev and not json_ipc and not is_clef:
                client_password = get_client_password(
                    checksum_address=ursula_config.worker_address,
                    envvar=NUCYPHER_ENVVAR_WORKER_ETH_PASSWORD)

        try:
            URSULA = make_cli_character(
                character_config=ursula_config,
                emitter=emitter,
                min_stake=self.min_stake,
                teacher_uri=self.teacher_uri,
                unlock_keyring=not self.config_options.dev,
                lonely=self.config_options.lonely,
                client_password=client_password,
                start_learning_now=load_seednodes)
            return ursula_config, URSULA

        except NucypherKeyring.AuthenticationFailed as e:
            emitter.echo(str(e), color='red', bold=True)
            # TODO: Exit codes (not only for this, but for other exceptions)
            return click.get_current_context().exit(1)
Beispiel #3
0
    def create_character(self, emitter, config_file, json_ipc, load_seednodes=True):

        config = self.config_options.create_config(emitter, config_file)

        client_password = None
        is_clef = ClefSigner.is_valid_clef_uri(self.config_options.signer_uri)
        eth_password_is_needed = not config.federated_only and not self.hw_wallet and not config.dev_mode and not is_clef
        if eth_password_is_needed:
            if json_ipc:
                client_password = os.environ.get(NUCYPHER_ENVVAR_ALICE_ETH_PASSWORD, NO_PASSWORD)
                if client_password is NO_PASSWORD:
                    message = f"--json-ipc implies the {NUCYPHER_ENVVAR_ALICE_ETH_PASSWORD} envvar must be set."
                    click.BadOptionUsage(option_name='--json-ipc', message=message)
            else:
                client_password = get_client_password(checksum_address=config.checksum_address,
                                                      envvar=NUCYPHER_ENVVAR_ALICE_ETH_PASSWORD)

        try:
            ALICE = make_cli_character(character_config=config,
                                       emitter=emitter,
                                       unlock_keyring=not config.dev_mode,
                                       teacher_uri=self.teacher_uri,
                                       min_stake=self.min_stake,
                                       client_password=client_password,
                                       start_learning_now=load_seednodes,
                                       lonely=self.config_options.lonely)
            return ALICE
        except NucypherKeyring.AuthenticationFailed as e:
            emitter.echo(str(e), color='red', bold=True)
            click.get_current_context().exit(1)
Beispiel #4
0
 def get_password(self, blockchain, client_account):
     is_clef = ClefSigner.is_valid_clef_uri(self.staker_options.config_options.signer_uri)
     eth_password_needed = not self.hw_wallet and not blockchain.client.is_local and not is_clef
     password = None
     if eth_password_needed:
         password = get_client_password(checksum_address=client_account)
     return password
Beispiel #5
0
    def create_character(self,
                         emitter,
                         config_file,
                         json_ipc,
                         load_seednodes=True):
        ursula_config = self.config_options.create_config(emitter, config_file)
        is_clef = ClefSigner.is_valid_clef_uri(self.config_options.signer_uri)
        password_required = all(
            (not ursula_config.federated_only, not self.config_options.dev,
             not json_ipc, not is_clef))
        __password = None
        if password_required:
            __password = get_client_password(
                checksum_address=ursula_config.worker_address,
                envvar=NUCYPHER_ENVVAR_WORKER_ETH_PASSWORD)

        try:
            URSULA = make_cli_character(
                character_config=ursula_config,
                emitter=emitter,
                min_stake=self.min_stake,
                teacher_uri=self.teacher_uri,
                unlock_keyring=not self.config_options.dev,
                client_password=__password,
                unlock_signer=
                False,  # Ursula's unlock is managed separately using client_password.
                lonely=self.config_options.lonely,
                start_learning_now=load_seednodes,
                json_ipc=json_ipc)
            return ursula_config, URSULA

        except NucypherKeyring.AuthenticationFailed as e:
            emitter.echo(str(e), color='red', bold=True)
            # TODO: Exit codes (not only for this, but for other exceptions)
            return click.get_current_context().exit(1)
Beispiel #6
0
    def __create_bidder(self,
                        registry,
                        domain: str,
                        transacting: bool = True,
                        hw_wallet: bool = False,
                        ) -> Bidder:

        is_clef = ClefSigner.is_valid_clef_uri(self.signer_uri)
        testnet = self.network != NetworksInventory.MAINNET
        signer = Signer.from_signer_uri(self.signer_uri, testnet=testnet) if self.signer_uri else None
        password_required = (not is_clef and not hw_wallet)
        if signer and transacting and password_required:
            client_password = get_client_password(checksum_address=self.bidder_address)
            signer.unlock_account(account=self.bidder_address, password=client_password)

        transacting_power = None
        if transacting:
            transacting_power = TransactingPower(account=self.bidder_address, signer=signer)
            transacting_power.unlock(password=client_password)

        bidder = Bidder(registry=registry,
                        transacting_power=transacting_power,
                        checksum_address=self.bidder_address if not transacting_power else None,
                        domain=domain)
        return bidder
Beispiel #7
0
    def create_character(self, emitter, config_file, debug):

        felix_config = self.config_options.create_config(emitter, config_file)

        try:
            # Authenticate
            unlock_nucypher_keyring(
                emitter,
                character_configuration=felix_config,
                password=get_nucypher_password(confirm=False))

            client_password = get_client_password(
                checksum_address=felix_config.checksum_address,
                envvar=NUCYPHER_ENVVAR_WORKER_ETH_PASSWORD)

            # Produce Felix
            FELIX = felix_config.produce(domain=self.config_options.domain,
                                         client_password=client_password)
            FELIX.make_web_app(
            )  # attach web application, but dont start service

            return FELIX
        except Exception as e:
            if debug:
                raise
            else:
                emitter.echo(str(e), color='red', bold=True)
                raise click.Abort
Beispiel #8
0
 def __create_executive(self, registry, transacting: bool = False) -> Executive:
     client_password = None
     is_clef = ClefSigner.is_valid_clef_uri(self.signer_uri)
     if transacting and not self.hw_wallet and not is_clef:
         client_password = get_client_password(checksum_address=self.checksum_address)
     executive = Executive(checksum_address=self.checksum_address,
                           registry=registry,
                           signer=ClefSigner(self.signer_uri),
                           client_password=client_password)
     return executive
Beispiel #9
0
def unbond(registry_filepath, eth_provider_uri, signer_uri, staking_provider,
           network, force):
    """Unbonds an operator from an authorized staking provider."""

    #
    # Setup
    #

    emitter = StdoutEmitter()
    if not signer_uri:
        emitter.message('--signer is required', color='red')
        raise click.Abort()
    if not network:
        network = select_network(emitter=emitter,
                                 network_type=NetworksInventory.ETH)

    connect_to_blockchain(eth_provider_uri=eth_provider_uri, emitter=emitter)
    registry = get_registry(network=network,
                            registry_filepath=registry_filepath)
    agent = ContractAgency.get_agent(PREApplicationAgent, registry=registry)
    signer = Signer.from_signer_uri(signer_uri)
    transacting_power = TransactingPower(account=staking_provider,
                                         signer=signer)

    #
    # Check
    #

    bonded, onchain_operator_address = is_bonded(
        agent=agent, staking_provider=staking_provider, return_address=True)
    if not bonded:
        emitter.message(NOT_BONDED.format(provider=staking_provider),
                        color='red')
        raise click.Abort()
    check_bonding_requirements(emitter=emitter,
                               agent=agent,
                               staking_provider=staking_provider)

    #
    # Unbond
    #

    if not force:
        click.confirm(CONFIRM_UNBONDING.format(
            provider=staking_provider, operator=onchain_operator_address),
                      abort=True)
    transacting_power.unlock(password=get_client_password(
        checksum_address=staking_provider,
        envvar=NUCYPHER_ENVVAR_STAKING_PROVIDER_ETH_PASSWORD))
    emitter.echo(UNBONDING.format(operator=onchain_operator_address))
    receipt = agent.bond_operator(operator=NULL_ADDRESS,
                                  transacting_power=transacting_power,
                                  staking_provider=staking_provider)
    paint_receipt_summary(receipt=receipt, emitter=emitter)
def test_get_client_password(mock_stdin, mock_account, confirm, capsys):
    mock_stdin.password(INSECURE_DEVELOPMENT_PASSWORD, confirm=confirm)
    result = get_client_password(checksum_address=mock_account.address,
                                 confirm=confirm)
    assert result == INSECURE_DEVELOPMENT_PASSWORD
    assert mock_stdin.empty()
    message = COLLECT_ETH_PASSWORD.format(
        checksum_address=mock_account.address)
    captured = capsys.readouterr()
    assert message in captured.out
    if confirm:
        assert "Repeat for confirmation:" in captured.out
Beispiel #11
0
    def __create_bidder(self,
                        registry,
                        transacting: bool = True,
                        hw_wallet: bool = False) -> Bidder:

        client_password = None
        is_clef = ClefSigner.is_valid_clef_uri(self.signer_uri)
        if transacting and not is_clef and not hw_wallet:
            client_password = get_client_password(checksum_address=self.bidder_address)
        signer = Signer.from_signer_uri(self.signer_uri) if self.signer_uri else None
        bidder = Bidder(checksum_address=self.bidder_address,
                        registry=registry,
                        client_password=client_password,
                        signer=signer,
                        transacting=transacting)
        return bidder
Beispiel #12
0
    def __create_participant(self,
                             registry,
                             transacting: bool = True,
                             hw_wallet: bool = False) -> DaoActor:

        client_password = None
        is_clef = ClefSigner.is_valid_clef_uri(self.signer_uri)  # TODO: why not allow the clef signer's validator act on this?
        if transacting and not is_clef and not hw_wallet:
            client_password = get_client_password(checksum_address=self.participant_address)

        testnet = self.network != NetworksInventory.MAINNET
        signer = Signer.from_signer_uri(self.signer_uri, testnet=testnet) if self.signer_uri else None
        actor = DaoActor(checksum_address=self.participant_address,
                         network=self.network,
                         registry=registry,
                         signer=signer,
                         transacting=transacting)
        return actor
Beispiel #13
0
    def __create_participant(self,
                             registry,
                             transacting: bool = True,
                             hw_wallet: bool = False) -> BaseActor:

        client_password = None
        is_clef = ClefSigner.is_valid_clef_uri(self.signer_uri)
        if transacting and not is_clef and not hw_wallet:
            client_password = get_client_password(
                checksum_address=self.participant_address)
        signer = Signer.from_signer_uri(
            self.signer_uri) if self.signer_uri else None
        actor = EmergencyResponseManager(
            checksum_address=self.participant_address,
            network=self.network,
            registry=registry,
            client_password=client_password,
            signer=signer,
            transacting=transacting)
        return actor
Beispiel #14
0
    def create_actor(self,
                     emitter: StdoutEmitter,
                     is_multisig: bool = False
                     ) -> Tuple[ContractAdministrator, str, BlockchainInterface, BaseContractRegistry]:

        ensure_config_root(self.config_root)
        deployer_interface = initialize_deployer_interface(poa=self.poa,
                                                           provider_uri=self.provider_uri,
                                                           emitter=emitter,
                                                           ignore_solidity_check=self.ignore_solidity_check,
                                                           gas_strategy=self.gas_strategy,
                                                           max_gas_price=self.max_gas_price)

        # Warnings
        deployer_pre_launch_warnings(emitter, self.etherscan, self.hw_wallet)

        #
        # Establish Registry
        #

        local_registry = establish_deployer_registry(emitter=emitter,
                                                     use_existing_registry=bool(self.contract_name),  # TODO: Issue #2314
                                                     registry_infile=self.registry_infile,
                                                     registry_outfile=self.registry_outfile,
                                                     dev=self.dev,
                                                     network=self.network)
        #
        # Make Authenticated Deployment Actor
        #
        # Verify Address & collect password
        password = None
        if is_multisig:
            multisig_agent = ContractAgency.get_agent(MultiSigAgent, registry=local_registry)
            deployer_address = multisig_agent.contract.address
            is_transacting = False
        else:
            is_transacting = True
            deployer_address = self.deployer_address
            if not deployer_address:
                deployer_address = select_client_account(emitter=emitter,
                                                         prompt=SELECT_DEPLOYER_ACCOUNT,
                                                         provider_uri=self.provider_uri,
                                                         signer_uri=self.signer_uri,
                                                         show_eth_balance=True)

            if not self.force:
                click.confirm(CONFIRM_SELECTED_ACCOUNT.format(address=deployer_address), abort=True)

            is_clef = ClefSigner.is_valid_clef_uri(self.signer_uri)
            eth_password_is_needed = not self.hw_wallet and not deployer_interface.client.is_local and not is_clef
            if eth_password_is_needed:
                password = get_client_password(checksum_address=deployer_address)

        # Produce Actor
        testnet = deployer_interface.client.chain_name != PUBLIC_CHAINS[1]  # Mainnet
        signer = Signer.from_signer_uri(self.signer_uri, testnet=testnet) if self.signer_uri else None
        ADMINISTRATOR = ContractAdministrator(registry=local_registry,
                                              client_password=password,
                                              deployer_address=deployer_address,
                                              is_transacting=is_transacting,
                                              signer=signer)
        # Verify ETH Balance
        emitter.echo(DEPLOYER_BALANCE.format(eth_balance=ADMINISTRATOR.eth_balance))
        if is_transacting and ADMINISTRATOR.eth_balance == 0:
            emitter.echo(DEPLOYER_ADDRESS_ZERO_ETH, color='red', bold=True)
            raise click.Abort()
        return ADMINISTRATOR, deployer_address, deployer_interface, local_registry
def test_get_client_password_with_invalid_address(mock_stdin):
    # `mock_stdin` used to assert the user was not prompted
    bad_address = '0xdeadbeef'
    with pytest.raises(InvalidChecksumAddress):
        get_client_password(checksum_address=bad_address)
Beispiel #16
0
def bond(registry_filepath, eth_provider_uri, signer_uri, operator_address,
         staking_provider, network, force):
    """
    Bond an operator to a staking provider.
    The staking provider must be authorized to use the PREApplication.
    """

    #
    # Setup
    #

    emitter = StdoutEmitter()
    connect_to_blockchain(eth_provider_uri=eth_provider_uri, emitter=emitter)
    if not signer_uri:
        emitter.message('--signer is required', color='red')
        raise click.Abort()
    if not network:
        network = select_network(emitter=emitter)

    signer = Signer.from_signer_uri(signer_uri)
    transacting_power = TransactingPower(account=staking_provider,
                                         signer=signer)
    registry = get_registry(network=network,
                            registry_filepath=registry_filepath)
    agent = ContractAgency.get_agent(PREApplicationAgent, registry=registry)

    #
    # Checks
    #

    # Check for authorization
    is_authorized(emitter=emitter,
                  agent=agent,
                  staking_provider=staking_provider)

    # Check bonding
    if is_bonded(agent=agent,
                 staking_provider=staking_provider,
                 return_address=False):
        # operator is already set - check timing
        check_bonding_requirements(emitter=emitter,
                                   agent=agent,
                                   staking_provider=staking_provider)

    # Check for pre-existing staking providers for this operator
    onchain_staking_provider = agent.get_staking_provider_from_operator(
        operator_address=operator_address)
    if onchain_staking_provider != NULL_ADDRESS:
        emitter.message(ALREADY_BONDED.format(
            provider=onchain_staking_provider, operator=operator_address),
                        color='red')
        raise click.Abort()  # dont steal bananas

    # Check that operator is not human
    if staking_provider != operator_address:
        # if the operator has a beneficiary it is the staking provider.
        beneficiary = agent.get_beneficiary(staking_provider=operator_address)
        if beneficiary != NULL_ADDRESS:
            emitter.message(UNEXPECTED_HUMAN_OPERATOR, color='red')
            raise click.Abort()

    #
    # Bond
    #

    if not force:
        click.confirm(CONFIRM_BONDING.format(provider=staking_provider,
                                             operator=operator_address),
                      abort=True)
    transacting_power.unlock(password=get_client_password(
        checksum_address=staking_provider,
        envvar=NUCYPHER_ENVVAR_STAKING_PROVIDER_ETH_PASSWORD))
    emitter.echo(BONDING.format(operator=operator_address))
    receipt = agent.bond_operator(operator=operator_address,
                                  transacting_power=transacting_power,
                                  staking_provider=staking_provider)
    paint_receipt_summary(receipt=receipt, emitter=emitter)