Skip to content
Closed
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
26 changes: 20 additions & 6 deletions src/aleph_client/chains/common.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
import os
from abc import abstractmethod, ABC
from pathlib import Path
from typing import Dict, Optional
from typing import Dict, Optional, Any, Mapping

from coincurve.keys import PrivateKey
from ecies import decrypt, encrypt
from aleph_message.models import Chain, MessageType

from aleph_client.conf import settings


def get_verification_buffer(message):
"""Returns a serialized string to verify the message integrity
(this is was it signed)
def get_verification_buffer(message: Mapping[str, Any]) -> bytes:
"""
return "{chain}\n{sender}\n{type}\n{item_hash}".format(**message).encode("utf-8")
Returns a buffer to sign to authenticate the message on the aleph.im network.
"""

# Support both strings and enums. Python 3.11 changed the formatting of enums,
# so we must use `.value`.
chain = message["chain"]
chain_str = chain.value if isinstance(chain, Chain) else chain

message_type = message["type"]
message_type_str = (
message_type.value if isinstance(message_type, MessageType) else message_type
)

buffer = (
f"{chain_str}\n{message['sender']}\n{message_type_str}\n{message['item_hash']}"
)
return buffer.encode("utf-8")


def get_public_key(private_key):
Expand Down Expand Up @@ -86,7 +101,6 @@ def get_fallback_private_key(path: Optional[Path] = None) -> bytes:
with open(path, "rb") as prvfile:
print(prvfile.read())


default_key_path = path.parent / "default.key"
if not default_key_path.is_symlink():
# Create a symlink to use this key by default
Expand Down
4 changes: 2 additions & 2 deletions src/aleph_client/commands/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def upload(
else StorageEnum.storage
)
logger.debug("Uploading file")
result: StoreMessage = synchronous.create_store(
message, status = synchronous.create_store(
account=account,
file_content=file_content,
storage_engine=storage_engine,
Expand All @@ -95,7 +95,7 @@ def upload(
ref=ref,
)
logger.debug("Upload finished")
typer.echo(f"{result.json(indent=4)}")
typer.echo(f"{message.json(indent=4)}")
finally:
# Prevent aiohttp unclosed connector warning
asyncio.run(get_fallback_session().close())