astreum 0.1.15__py3-none-any.whl → 0.1.17__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of astreum might be problematic. Click here for more details.
- astreum/node/crypto/__init__.py +0 -0
- astreum/node/crypto/ed25519.py +50 -0
- astreum/node/crypto/x25519.py +31 -0
- astreum/node/relay/__init__.py +3 -0
- astreum/node/storage/merkle.py +224 -734
- astreum/node/storage/patricia.py +289 -0
- astreum/node/validation/account.py +99 -874
- astreum/node/validation/block.py +30 -0
- astreum/node/validation/transaction.py +146 -0
- {astreum-0.1.15.dist-info → astreum-0.1.17.dist-info}/METADATA +3 -2
- {astreum-0.1.15.dist-info → astreum-0.1.17.dist-info}/RECORD +18 -13
- {astreum-0.1.15.dist-info → astreum-0.1.17.dist-info}/WHEEL +1 -1
- astreum/node/storage/trie.py +0 -146
- /astreum/node/validation/{block → _block}/__init__.py +0 -0
- /astreum/node/validation/{block → _block}/create.py +0 -0
- /astreum/node/validation/{block → _block}/model.py +0 -0
- /astreum/node/validation/{block → _block}/validate.py +0 -0
- {astreum-0.1.15.dist-info → astreum-0.1.17.dist-info/licenses}/LICENSE +0 -0
- {astreum-0.1.15.dist-info → astreum-0.1.17.dist-info}/top_level.txt +0 -0
|
File without changes
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# EdDSA signature algorithm over Curve25519
|
|
2
|
+
|
|
3
|
+
# ed25519.py
|
|
4
|
+
from cryptography.hazmat.primitives.asymmetric import ed25519
|
|
5
|
+
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey, Ed25519PublicKey
|
|
6
|
+
from cryptography.exceptions import InvalidSignature
|
|
7
|
+
from typing import Tuple
|
|
8
|
+
|
|
9
|
+
def generate_key_pair() -> Tuple[Ed25519PrivateKey, Ed25519PublicKey]:
|
|
10
|
+
"""
|
|
11
|
+
Generate an Ed25519 private and public key pair.
|
|
12
|
+
|
|
13
|
+
Returns:
|
|
14
|
+
Tuple[Ed25519PrivateKey, Ed25519PublicKey]: The generated key pair.
|
|
15
|
+
"""
|
|
16
|
+
private_key: Ed25519PrivateKey = ed25519.Ed25519PrivateKey.generate()
|
|
17
|
+
public_key: Ed25519PublicKey = private_key.public_key()
|
|
18
|
+
return private_key, public_key
|
|
19
|
+
|
|
20
|
+
def sign_message(private_key: Ed25519PrivateKey, message: bytes) -> bytes:
|
|
21
|
+
"""
|
|
22
|
+
Sign a message using the provided Ed25519 private key.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
private_key (Ed25519PrivateKey): The private key used for signing.
|
|
26
|
+
message (bytes): The message to sign.
|
|
27
|
+
|
|
28
|
+
Returns:
|
|
29
|
+
bytes: The signature.
|
|
30
|
+
"""
|
|
31
|
+
signature: bytes = private_key.sign(message)
|
|
32
|
+
return signature
|
|
33
|
+
|
|
34
|
+
def verify_signature(public_key: Ed25519PublicKey, message: bytes, signature: bytes) -> bool:
|
|
35
|
+
"""
|
|
36
|
+
Verify a message signature using the provided Ed25519 public key.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
public_key (Ed25519PublicKey): The public key corresponding to the private key that signed.
|
|
40
|
+
message (bytes): The original message.
|
|
41
|
+
signature (bytes): The signature to verify.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
bool: True if the signature is valid, False otherwise.
|
|
45
|
+
"""
|
|
46
|
+
try:
|
|
47
|
+
public_key.verify(signature, message)
|
|
48
|
+
return True
|
|
49
|
+
except InvalidSignature:
|
|
50
|
+
return False
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Diffie-Hellman key exchange over Curve25519
|
|
2
|
+
|
|
3
|
+
# x25519.py
|
|
4
|
+
from cryptography.hazmat.primitives.asymmetric import x25519
|
|
5
|
+
from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey, X25519PublicKey
|
|
6
|
+
from typing import Tuple
|
|
7
|
+
|
|
8
|
+
def generate_key_pair() -> Tuple[X25519PrivateKey, X25519PublicKey]:
|
|
9
|
+
"""
|
|
10
|
+
Generate an X25519 private and public key pair.
|
|
11
|
+
|
|
12
|
+
Returns:
|
|
13
|
+
Tuple[X25519PrivateKey, X25519PublicKey]: The generated key pair.
|
|
14
|
+
"""
|
|
15
|
+
private_key: X25519PrivateKey = x25519.X25519PrivateKey.generate()
|
|
16
|
+
public_key: X25519PublicKey = private_key.public_key()
|
|
17
|
+
return private_key, public_key
|
|
18
|
+
|
|
19
|
+
def generate_shared_key(private_key: X25519PrivateKey, peer_public_key: X25519PublicKey) -> bytes:
|
|
20
|
+
"""
|
|
21
|
+
Generate a shared key using the provided private key and peer's public key.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
private_key (X25519PrivateKey): Our private key.
|
|
25
|
+
peer_public_key (X25519PublicKey): The peer's public key.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
bytes: The shared key.
|
|
29
|
+
"""
|
|
30
|
+
shared_key: bytes = private_key.exchange(peer_public_key)
|
|
31
|
+
return shared_key
|
astreum/node/relay/__init__.py
CHANGED