Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# To modify aleph.sdk.conf's settings, create a .env file and add:
# ALEPH_<KEY>=<VALUE>
# To modify active & rpc fields in CHAINS, follow this example:
# ALEPH_CHAINS_SEPOLIA_ACTIVE=True
# ALEPH_CHAINS_SEPOLIA_RPC=https://...
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ cover/*
MANIFEST

# Per-project virtualenvs
.env
.venv*/
venv/*
**/device.key

# Environment variables
.env
.env.local

.gitsigners
27 changes: 13 additions & 14 deletions src/aleph_client/commands/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import asyncio
import base64
import json
import logging
import sys
from pathlib import Path
Expand All @@ -13,7 +12,7 @@
from aleph.sdk.account import _load_account
from aleph.sdk.chains.common import generate_key
from aleph.sdk.chains.ethereum import ETHAccount
from aleph.sdk.conf import settings as sdk_settings
from aleph.sdk.conf import settings
from aleph.sdk.types import AccountFromPrivateKey
from typer.colors import RED

Expand All @@ -37,7 +36,7 @@ def create(
setup_logging(debug)

if private_key_file is None:
private_key_file = Path(typer.prompt("Enter file in which to save the key", sdk_settings.PRIVATE_KEY_FILE))
private_key_file = Path(typer.prompt("Enter file in which to save the key", settings.PRIVATE_KEY_FILE))

if private_key_file.exists() and not replace:
typer.secho(f"Error: key already exists: '{private_key_file}'", fg=RED)
Expand All @@ -63,8 +62,8 @@ def create(

@app.command()
def address(
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
):
"""
Display your public address.
Expand All @@ -82,8 +81,8 @@ def address(

@app.command()
def export_private_key(
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
):
"""
Display your private key.
Expand All @@ -105,15 +104,15 @@ def export_private_key(

@app.command()
def path():
if sdk_settings.PRIVATE_KEY_FILE:
typer.echo(sdk_settings.PRIVATE_KEY_FILE)
if settings.PRIVATE_KEY_FILE:
typer.echo(settings.PRIVATE_KEY_FILE)


@app.command("sign-bytes")
def sign_bytes(
message: Optional[str] = typer.Option(None, help="Message to sign"),
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""Sign a message using your private key."""
Expand All @@ -134,16 +133,16 @@ def sign_bytes(
@app.command()
async def balance(
address: Optional[str] = typer.Option(None, help="Address"),
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
):
account: AccountFromPrivateKey = _load_account(private_key, private_key_file)

if account and not address:
address = account.get_address()

if address:
uri = f"{sdk_settings.API_HOST}/api/v0/addresses/{address}/balance"
uri = f"{settings.API_HOST}/api/v0/addresses/{address}/balance"

async with aiohttp.ClientSession() as session:
response = await session.get(uri)
Expand Down
21 changes: 10 additions & 11 deletions src/aleph_client/commands/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import typer
from aleph.sdk.account import _load_account
from aleph.sdk.client import AuthenticatedAlephHttpClient
from aleph.sdk.conf import settings as sdk_settings
from aleph.sdk.conf import settings
from aleph.sdk.query.filters import MessageFilter
from aleph.sdk.types import AccountFromPrivateKey
from aleph.sdk.utils import extended_json_encoder
from aleph_message.models.base import MessageType

from aleph_client.commands import help_strings
from aleph_client.commands.utils import setup_logging
from aleph_client.conf import settings
from aleph_client.utils import AsyncTyper

app = AsyncTyper(no_args_is_help=True)
Expand All @@ -26,8 +25,8 @@ async def forget(
key: str = typer.Argument(..., help="Aggregate item hash to be removed."),
reason: Optional[str] = typer.Option(None, help="A description of why the messages are being forgotten"),
channel: Optional[str] = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""Forget all the messages composing an aggregate."""
Expand All @@ -36,7 +35,7 @@ async def forget(

account: AccountFromPrivateKey = _load_account(private_key, private_key_file)

async with AuthenticatedAlephHttpClient(account=account, api_server=sdk_settings.API_HOST) as client:
async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:
message_response = await client.get_messages(
message_filter=MessageFilter(
addresses=[account.get_address()],
Expand All @@ -57,8 +56,8 @@ async def post(
channel: Optional[str] = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
inline: bool = typer.Option(False, help="inline"),
sync: bool = typer.Option(False, help="Sync response"),
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""Create or Update aggregate"""
Expand All @@ -73,7 +72,7 @@ async def post(
typer.echo("Invalid JSON for content. Please provide valid JSON.")
raise typer.Exit(1)

async with AuthenticatedAlephHttpClient(account=account, api_server=sdk_settings.API_HOST) as client:
async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:
message, _ = await client.create_aggregate(
key=key,
content=content_dict,
Expand All @@ -90,8 +89,8 @@ async def post(
async def get(
key: str = typer.Argument(..., help="Aggregate key to be fetched."),
address: Optional[str] = typer.Option(default=None, help="Address"),
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""Fetch an aggregate by key and content."""
Expand All @@ -103,7 +102,7 @@ async def get(
# if no address we load current account as a private key
address = account.get_address() if address is None else address

async with AuthenticatedAlephHttpClient(account=account, api_server=sdk_settings.API_HOST) as client:
async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:
aggregates = await client.fetch_aggregate(address=address, key=key)

if aggregates:
Expand Down
24 changes: 12 additions & 12 deletions src/aleph_client/commands/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import typer
from aleph.sdk.account import _load_account
from aleph.sdk.client import AlephHttpClient, AuthenticatedAlephHttpClient
from aleph.sdk.conf import settings as sdk_settings
from aleph.sdk.conf import settings
from aleph.sdk.domain import (
DomainValidator,
Hostname,
Expand All @@ -32,7 +32,7 @@


async def get_aggregate_domain_info(account, fqdn):
async with AlephHttpClient(api_server=sdk_settings.API_HOST) as client:
async with AlephHttpClient(api_server=settings.API_HOST) as client:
aggregates = await client.get_messages(
message_filter=MessageFilter(
addresses=[str(account.get_address())],
Expand Down Expand Up @@ -105,7 +105,7 @@ async def attach_resource(
if (not interactive) or Confirm.ask("Continue"):
"""Create aggregate message"""

async with AuthenticatedAlephHttpClient(account=account, api_server=sdk_settings.API_HOST) as client:
async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:

options: Optional[Dict] = None
if catch_all_path and catch_all_path.startswith("/"):
Expand Down Expand Up @@ -158,7 +158,7 @@ async def detach_resource(account: AccountFromPrivateKey, fqdn: Hostname, intera
if (not interactive) or Confirm.ask("Continue"):
"""Update aggregate message"""

async with AuthenticatedAlephHttpClient(account=account, api_server=sdk_settings.API_HOST) as client:
async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:
aggregate_content = {str(fqdn): None}

aggregate_message, message_status = await client.create_aggregate(
Expand All @@ -173,8 +173,8 @@ async def detach_resource(account: AccountFromPrivateKey, fqdn: Hostname, intera

@app.command()
async def add(
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
fqdn: str = typer.Argument(..., help=help_strings.CUSTOM_DOMAIN_NAME),
target: Optional[TargetType] = typer.Option(None, help=help_strings.CUSTOM_DOMAIN_TARGET_TYPES),
item_hash: Optional[str] = typer.Option(None, help=help_strings.CUSTOM_DOMAIN_ITEM_HASH),
Expand Down Expand Up @@ -257,8 +257,8 @@ async def add(

@app.command()
async def attach(
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
fqdn: str = typer.Argument(..., help=help_strings.CUSTOM_DOMAIN_NAME),
item_hash: Optional[str] = typer.Option(None, help=help_strings.CUSTOM_DOMAIN_ITEM_HASH),
catch_all_path: str = typer.Option(default=None, help=help_strings.IPFS_CATCH_ALL_PATH),
Expand All @@ -279,8 +279,8 @@ async def attach(

@app.command()
async def detach(
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
fqdn: str = typer.Argument(..., help=help_strings.CUSTOM_DOMAIN_NAME),
ask: bool = typer.Option(default=True, help=help_strings.ASK_FOR_CONFIRMATION),
):
Expand All @@ -293,8 +293,8 @@ async def detach(

@app.command()
async def info(
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
fqdn: str = typer.Argument(..., help=help_strings.CUSTOM_DOMAIN_NAME),
):
"""Show Custom Domain Details."""
Expand Down
29 changes: 14 additions & 15 deletions src/aleph_client/commands/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import typer
from aleph.sdk import AlephHttpClient, AuthenticatedAlephHttpClient
from aleph.sdk.account import _load_account
from aleph.sdk.conf import settings as sdk_settings
from aleph.sdk.conf import settings
from aleph.sdk.types import AccountFromPrivateKey, StorageEnum
from aleph_message.models import ItemHash, StoreMessage
from aleph_message.status import MessageStatus
Expand All @@ -21,7 +21,6 @@

from aleph_client.commands import help_strings
from aleph_client.commands.utils import setup_logging
from aleph_client.conf import settings
from aleph_client.utils import AsyncTyper

logger = logging.getLogger(__name__)
Expand All @@ -32,8 +31,8 @@
async def pin(
item_hash: str = typer.Argument(..., help="IPFS hash to pin on aleph.im"),
channel: Optional[str] = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
ref: Optional[str] = typer.Option(None, help=help_strings.REF),
debug: bool = False,
):
Expand All @@ -43,7 +42,7 @@ async def pin(

account: AccountFromPrivateKey = _load_account(private_key, private_key_file)

async with AuthenticatedAlephHttpClient(account=account, api_server=sdk_settings.API_HOST) as client:
async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:
result: StoreMessage
status: MessageStatus
result, status = await client.create_store(
Expand All @@ -60,8 +59,8 @@ async def pin(
async def upload(
path: Path = typer.Argument(..., help="Path of the file to upload"),
channel: Optional[str] = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
ref: Optional[str] = typer.Option(None, help=help_strings.REF),
debug: bool = False,
):
Expand All @@ -71,7 +70,7 @@ async def upload(

account: AccountFromPrivateKey = _load_account(private_key, private_key_file)

async with AuthenticatedAlephHttpClient(account=account, api_server=sdk_settings.API_HOST) as client:
async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:
if not path.is_file():
typer.echo(f"Error: File not found: '{path}'")
raise typer.Exit(code=1)
Expand Down Expand Up @@ -115,7 +114,7 @@ async def download(

output_file_path = output_path / f"{file_name}{file_extension}"

async with AlephHttpClient(api_server=sdk_settings.API_HOST) as client:
async with AlephHttpClient(api_server=settings.API_HOST) as client:
logger.info(f"Downloading {hash} ...")
with open(output_file_path, "wb") as fd:
if not use_ipfs:
Expand All @@ -131,8 +130,8 @@ async def forget(
item_hash: str = typer.Argument(..., help="Hash to forget"),
reason: str = typer.Argument("User deletion", help="reason to forget"),
channel: Optional[str] = typer.Option(default=settings.DEFAULT_CHANNEL, help=help_strings.CHANNEL),
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
debug: bool = False,
):
"""forget a file and his message on aleph.im."""
Expand All @@ -141,7 +140,7 @@ async def forget(

account: AccountFromPrivateKey = _load_account(private_key, private_key_file)

async with AuthenticatedAlephHttpClient(account=account, api_server=sdk_settings.API_HOST) as client:
async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:
value = await client.forget(hashes=[ItemHash(item_hash)], reason=reason, channel=channel)
typer.echo(f"{value[0].json(indent=4)}")

Expand Down Expand Up @@ -208,8 +207,8 @@ def _show_files(files_data: dict) -> None:
@app.command()
async def list(
address: Optional[str] = typer.Option(None, help="Address"),
private_key: Optional[str] = typer.Option(sdk_settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(sdk_settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
private_key: Optional[str] = typer.Option(settings.PRIVATE_KEY_STRING, help=help_strings.PRIVATE_KEY),
private_key_file: Optional[Path] = typer.Option(settings.PRIVATE_KEY_FILE, help=help_strings.PRIVATE_KEY_FILE),
pagination: int = typer.Option(100, help="Maximum number of files to return."),
page: int = typer.Option(1, help="Offset in pages."),
sort_order: int = typer.Option(
Expand All @@ -228,7 +227,7 @@ async def list(
# Build the query parameters
query_params = GetAccountFilesQueryParams(pagination=pagination, page=page, sort_order=sort_order)

uri = f"{sdk_settings.API_HOST}/api/v0/addresses/{address}/files"
uri = f"{settings.API_HOST}/api/v0/addresses/{address}/files"
async with aiohttp.ClientSession() as session:
response = await session.get(uri, params=query_params.dict())
if response.status == 200:
Expand Down
Loading