def get_keyfile_path() -> Path: ethpm_xdg_root = get_xdg_ethpmcli_root() keyfile_path = ethpm_xdg_root / KEYFILE_PATH if not keyfile_path.is_file(): raise AuthorizationError(f"No keyfile located at {keyfile_path}.") if not keyfile_path.read_text(): raise AuthorizationError(f"Empty keyfile located at {keyfile_path}.") return keyfile_path
def get_authorized_private_key(password: str) -> str: """ Returns the private key associated with stored keyfile. Password required. """ keyfile_path = get_keyfile_path() try: private_key = eth_keyfile.extract_key_from_keyfile( str(keyfile_path), to_bytes(text=password)) except ValueError: raise AuthorizationError( f"Provided keyfile password: {password} is not a valid " f"password for encrypted keyfile at {keyfile_path}.") return private_key
def deploy_registry(config: Config, alias: str = None) -> str: if not config.private_key: raise AuthorizationError( "To deploy a registry, you must provide the password for your local keyfile." ) chain_id = config.w3.eth.chainId chain_name = SUPPORTED_CHAIN_IDS[chain_id] cli_logger.info( f"Deploying a new registry to {chain_name}, this may take a minute...") # todo: handle tx timeout error gracefully registry_address = config.w3.pm.deploy_and_set_registry() cli_logger.info( f"New registry deployed to {registry_address} on {chain_name}.") registry_uri = URI(f"erc1319://{registry_address}:{chain_id}") add_registry(registry_uri, alias, config) activate_registry(registry_uri, config) return registry_address
def release_package(package_name: str, version: str, manifest_uri: URI, config: Config) -> bytes: if not config.private_key: raise AuthorizationError( "To release a package you must provide the password for your local keyfile." ) registry_store_path = config.xdg_ethpmcli_root / REGISTRY_STORE active_registry = get_active_registry(registry_store_path) parsed_uri = parse_registry_uri(active_registry.uri) if config.w3.net.version != parsed_uri.chain_id: w3 = setup_w3(to_int(text=parsed_uri.chain_id), config.private_key) else: w3 = config.w3 w3.pm.set_registry(parsed_uri.address) release_id = w3.pm.release_package(package_name, version, manifest_uri) return release_id
def validate_keyfile(keyfile_path: Path) -> None: keyfile_data = eth_keyfile.load_keyfile(str(keyfile_path)) if keyfile_data["version"] != 3: raise AuthorizationError( f"Keyfile found at {keyfile_path} does not look like a supported eth-keyfile object." )