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
3 changes: 1 addition & 2 deletions src/aleph/sdk/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def account_from_hex_string(private_key_str: str, account_type: Type[T]) -> T:


def account_from_file(private_key_path: Path, account_type: Type[T]) -> T:
with open(private_key_path, "rb") as pk_fd:
private_key: bytes = pk_fd.read()
private_key = private_key_path.read_bytes()
return account_type(private_key)


Expand Down
16 changes: 5 additions & 11 deletions src/aleph/sdk/chains/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Dict, Optional
Expand Down Expand Up @@ -114,19 +113,14 @@ def get_fallback_private_key(path: Optional[Path] = None) -> bytes:
path = path or settings.PRIVATE_KEY_FILE
private_key: bytes
if path.exists() and path.stat().st_size > 0:
with open(path, "rb") as prvfile:
private_key = prvfile.read()
private_key = path.read_bytes()
else:
private_key = generate_key()
os.makedirs(path.parent, exist_ok=True)
with open(path, "wb") as prvfile:
prvfile.write(private_key)

with open(path, "rb") as prvfile:
print(prvfile.read())
path.parent.mkdir(exist_ok=True, parents=True)
path.write_bytes(private_key)

default_key_path = path.parent / "default.key"
if not default_key_path.is_symlink():
if not default_key_path.exists():
# Create a symlink to use this key by default
os.symlink(path, default_key_path)
default_key_path.symlink_to(path)
return private_key
26 changes: 1 addition & 25 deletions src/aleph/sdk/chains/sol.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import os
from pathlib import Path
from typing import Dict, Optional, Union

Expand All @@ -8,9 +7,8 @@
from nacl.public import PrivateKey, SealedBox
from nacl.signing import SigningKey, VerifyKey

from ..conf import settings
from ..exceptions import BadSignatureError
from .common import BaseAccount, get_verification_buffer
from .common import BaseAccount, get_fallback_private_key, get_verification_buffer


def encode(item):
Expand Down Expand Up @@ -63,28 +61,6 @@ def generate_key() -> bytes:
return privkey


def get_fallback_private_key(path: Optional[Path] = None) -> bytes:
path = path or settings.PRIVATE_KEY_FILE
private_key: bytes
if path.exists() and path.stat().st_size > 0:
with open(path, "rb") as prvfile:
private_key = prvfile.read()
else:
private_key = generate_key()
os.makedirs(path.parent, exist_ok=True)
with open(path, "wb") as prvfile:
prvfile.write(private_key)

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
os.symlink(path, default_key_path)
return private_key


def verify_signature(
signature: Union[bytes, str],
public_key: Union[bytes, str],
Expand Down
6 changes: 2 additions & 4 deletions src/aleph/sdk/chains/substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ def get_fallback_account():

def get_fallback_mnemonics():
try:
with open(settings.PRIVATE_KEY_FILE, "r") as prvfile:
mnemonic = prvfile.read()
mnemonic = settings.PRIVATE_KEY_FILE.read_text()
except OSError:
mnemonic = Keypair.generate_mnemonic()
with open(settings.PRIVATE_KEY_FILE, "w") as prvfile:
prvfile.write(mnemonic)
settings.PRIVATE_KEY_FILE.write_text(mnemonic)

return mnemonic

Expand Down
2 changes: 1 addition & 1 deletion src/aleph/sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ async def create_store(
"Please specify at least a file_content, a file_hash or a file_path"
)
else:
file_content = open(file_path, "rb").read()
file_content = Path(file_path).read_bytes()

if storage_engine == StorageEnum.storage:
file_hash = await self.storage_push_file(file_content=file_content)
Expand Down