astreum 0.1.14__py3-none-any.whl → 0.1.16__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/lispeum/storage.py +10 -10
- astreum/lispeum/utils.py +17 -0
- astreum/node/__init__.py +333 -552
- astreum/node/crypto/__init__.py +0 -0
- astreum/node/crypto/ed25519.py +50 -0
- astreum/node/crypto/x25519.py +31 -0
- astreum/node/relay/envelope.py +5 -5
- astreum/node/storage/__init__.py +13 -0
- astreum/node/storage/merkle.py +734 -0
- astreum/node/{models.py → storage/storage.py} +41 -99
- astreum/node/storage/trie.py +146 -0
- astreum/node/storage/utils.py +137 -0
- astreum/node/utils.py +34 -0
- astreum/node/validation/__init__.py +84 -0
- astreum/node/validation/account.py +874 -0
- astreum/node/validation/block/__init__.py +12 -0
- astreum/node/validation/block/create.py +98 -0
- astreum/node/validation/block/model.py +81 -0
- astreum/node/validation/block/validate.py +196 -0
- astreum/node/validation/constants.py +15 -0
- astreum/node/validation/stake.py +229 -0
- astreum/node/validation/state.py +230 -0
- astreum/node/validation/transaction.py +90 -0
- astreum/node/validation/vdf.py +80 -0
- {astreum-0.1.14.dist-info → astreum-0.1.16.dist-info}/METADATA +4 -2
- astreum-0.1.16.dist-info/RECORD +57 -0
- {astreum-0.1.14.dist-info → astreum-0.1.16.dist-info}/WHEEL +1 -1
- astreum-0.1.14.dist-info/RECORD +0 -37
- {astreum-0.1.14.dist-info → astreum-0.1.16.dist-info/licenses}/LICENSE +0 -0
- {astreum-0.1.14.dist-info → astreum-0.1.16.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/envelope.py
CHANGED
|
@@ -31,11 +31,11 @@ determined by the difficulty parameter. The nonce is adjusted until this require
|
|
|
31
31
|
import struct
|
|
32
32
|
import time
|
|
33
33
|
import os
|
|
34
|
-
import hashlib
|
|
35
34
|
from dataclasses import dataclass
|
|
36
35
|
from typing import Optional, Tuple, List
|
|
37
36
|
from .message import Message, Topic
|
|
38
37
|
from astreum.utils.bytes_format import encode, decode
|
|
38
|
+
from ..utils import hash_data
|
|
39
39
|
|
|
40
40
|
@dataclass
|
|
41
41
|
class Envelope:
|
|
@@ -153,13 +153,13 @@ class Envelope:
|
|
|
153
153
|
bytes: The Merkle root hash
|
|
154
154
|
"""
|
|
155
155
|
if not leaves:
|
|
156
|
-
return
|
|
156
|
+
return hash_data(b'')
|
|
157
157
|
|
|
158
158
|
if len(leaves) == 1:
|
|
159
|
-
return
|
|
159
|
+
return hash_data(leaves[0])
|
|
160
160
|
|
|
161
161
|
# Hash all leaf nodes
|
|
162
|
-
hashed_leaves = [
|
|
162
|
+
hashed_leaves = [hash_data(leaf) for leaf in leaves]
|
|
163
163
|
|
|
164
164
|
# Build the Merkle tree
|
|
165
165
|
while len(hashed_leaves) > 1:
|
|
@@ -171,7 +171,7 @@ class Envelope:
|
|
|
171
171
|
next_level = []
|
|
172
172
|
for i in range(0, len(hashed_leaves), 2):
|
|
173
173
|
combined = hashed_leaves[i] + hashed_leaves[i+1]
|
|
174
|
-
next_level.append(
|
|
174
|
+
next_level.append(hash_data(combined))
|
|
175
175
|
|
|
176
176
|
hashed_leaves = next_level
|
|
177
177
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Storage utilities for the Astreum node.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .merkle import MerkleTree, MerkleProof, MerkleNode
|
|
6
|
+
from .merkle import find_first, find_all, map, binary_search
|
|
7
|
+
from .storage import Storage
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"MerkleTree", "MerkleProof", "MerkleNode",
|
|
11
|
+
"find_first", "find_all", "map", "binary_search",
|
|
12
|
+
"Storage"
|
|
13
|
+
]
|