astreum 0.2.9__tar.gz → 0.2.11__tar.gz

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.

Files changed (28) hide show
  1. {astreum-0.2.9/src/astreum.egg-info → astreum-0.2.11}/PKG-INFO +1 -1
  2. {astreum-0.2.9 → astreum-0.2.11}/pyproject.toml +1 -1
  3. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/node.py +95 -0
  4. astreum-0.2.11/src/astreum/utils/__init__.py +0 -0
  5. astreum-0.2.11/src/astreum/utils/patricia.py +45 -0
  6. {astreum-0.2.9 → astreum-0.2.11/src/astreum.egg-info}/PKG-INFO +1 -1
  7. {astreum-0.2.9 → astreum-0.2.11}/src/astreum.egg-info/SOURCES.txt +2 -0
  8. {astreum-0.2.9 → astreum-0.2.11}/LICENSE +0 -0
  9. {astreum-0.2.9 → astreum-0.2.11}/README.md +0 -0
  10. {astreum-0.2.9 → astreum-0.2.11}/setup.cfg +0 -0
  11. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/__init__.py +0 -0
  12. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/_node/__init__.py +0 -0
  13. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/_node/storage/__init__.py +0 -0
  14. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/_node/storage/merkle.py +0 -0
  15. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/_node/storage/patricia.py +0 -0
  16. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/crypto/__init__.py +0 -0
  17. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/crypto/ed25519.py +0 -0
  18. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/crypto/quadratic_form.py +0 -0
  19. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/crypto/wesolowski.py +0 -0
  20. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/crypto/x25519.py +0 -0
  21. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/format.py +0 -0
  22. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/lispeum/__init__.py +0 -0
  23. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/lispeum/parser.py +0 -0
  24. {astreum-0.2.9 → astreum-0.2.11}/src/astreum/lispeum/tokenizer.py +0 -0
  25. {astreum-0.2.9 → astreum-0.2.11}/src/astreum.egg-info/dependency_links.txt +0 -0
  26. {astreum-0.2.9 → astreum-0.2.11}/src/astreum.egg-info/requires.txt +0 -0
  27. {astreum-0.2.9 → astreum-0.2.11}/src/astreum.egg-info/top_level.txt +0 -0
  28. {astreum-0.2.9 → astreum-0.2.11}/tests/test_node_machine.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: astreum
3
- Version: 0.2.9
3
+ Version: 0.2.11
4
4
  Summary: Python library to interact with the Astreum blockchain and its Lispeum virtual machine.
5
5
  Author-email: "Roy R. O. Okello" <roy@stelar.xyz>
6
6
  Project-URL: Homepage, https://github.com/astreum/lib
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "astreum"
3
- version = "0.2.9"
3
+ version = "0.2.11"
4
4
  authors = [
5
5
  { name="Roy R. O. Okello", email="roy@stelar.xyz" },
6
6
  ]
@@ -403,7 +403,102 @@ class Transaction:
403
403
 
404
404
  def __hash__(self) -> int:
405
405
  return int.from_bytes(self.tx_hash, 'big')
406
+
407
+ class Block:
408
+ def __init__(
409
+ self,
410
+ *,
411
+ number: int,
412
+ prev_block_hash: bytes,
413
+ timestamp: int,
414
+ accounts_hash: bytes,
415
+ total_astre_burned: int,
416
+ tx_limit: int,
417
+ tx_root: bytes,
418
+ vdf_difficulty: int,
419
+ vdf_output: bytes,
420
+ vdf_proof: bytes,
421
+ validator_pk: bytes,
422
+ signature: bytes,
423
+ ) -> None:
424
+ self.accounts_hash = accounts_hash
425
+ self.number = int(number)
426
+ self.prev_block_hash = prev_block_hash
427
+ self.timestamp = int(timestamp)
428
+ self.total_astre_burned = int(total_astre_burned)
429
+ self.tx_limit = int(tx_limit)
430
+ self.tx_root = tx_root
431
+ self.validator_pk = validator_pk
432
+ self.vdf_difficulty = int(vdf_difficulty)
433
+ self.vdf_output = vdf_output
434
+ self.vdf_proof = vdf_proof
435
+ self.signature = signature
436
+ self.body_hash = self._compute_body_hash()
437
+
438
+ def _body_fields_without_sig(self) -> list:
439
+ return [
440
+ self.accounts_hash,
441
+ self.number,
442
+ self.prev_block_hash,
443
+ self.timestamp,
444
+ self.total_astre_burned,
445
+ self.tx_limit,
446
+ self.tx_root,
447
+ self.validator_pk,
448
+ self.vdf_difficulty,
449
+ self.vdf_output,
450
+ self.vdf_proof,
451
+ ]
452
+
453
+ def _compute_body_hash(self) -> bytes:
454
+ return blake3.blake3(encode(self._body_fields_without_sig())).digest()
406
455
 
456
+ def to_bytes(self) -> bytes:
457
+ return encode(self._body_fields_without_sig() + [self.signature])
458
+
459
+ @classmethod
460
+ def from_bytes(cls, blob: bytes) -> "Block":
461
+ (
462
+ accounts_hash,
463
+ number,
464
+ prev_block_hash,
465
+ timestamp,
466
+ total_astre_burned,
467
+ tx_limit,
468
+ tx_root,
469
+ validator_pk,
470
+ vdf_difficulty,
471
+ vdf_output,
472
+ vdf_proof,
473
+ signature
474
+ ) = decode(blob)
475
+ return cls(
476
+ number=int(number),
477
+ prev_block_hash=prev_block_hash,
478
+ timestamp=int(timestamp),
479
+ accounts_hash=accounts_hash,
480
+ total_astre_burned=int(total_astre_burned),
481
+ tx_limit=int(tx_limit),
482
+ tx_root=tx_root,
483
+ vdf_difficulty=int(vdf_difficulty),
484
+ vdf_output=vdf_output,
485
+ vdf_proof=vdf_proof,
486
+ validator_pk=validator_pk,
487
+ signature=signature,
488
+ )
489
+
490
+ @property
491
+ def hash(self) -> bytes:
492
+ return blake3.blake3(self.body_hash + self.signature).digest()
493
+
494
+ def verify_block_signature(self) -> bool:
495
+ try:
496
+ pub = ed25519.Ed25519PublicKey.from_public_bytes(self.validator_pk)
497
+ pub.verify(self.signature, self.body_hash)
498
+ return True
499
+ except Exception:
500
+ return False
501
+
407
502
  class Node:
408
503
  def __init__(self, config: dict = {}):
409
504
  self._machine_setup()
File without changes
@@ -0,0 +1,45 @@
1
+ import blake3
2
+ from typing import Callable, Dict, List, Optional
3
+ from astreum import format
4
+
5
+ EMPTY_HASH = b"\x00" * 32
6
+
7
+ class PatriciaNode:
8
+ def __init__(
9
+ self,
10
+ key_len: int,
11
+ key_bits: bytes,
12
+ value: bytes,
13
+ children: List[bytes]|None = None
14
+ ):
15
+ self.key_len = key_len
16
+ self.key_bits = key_bits
17
+ self.value = value
18
+ self.children = children
19
+ self._hash: bytes | None = None
20
+
21
+ def to_bytes(self) -> bytes:
22
+ key_field = bytes([self.key_len]) + self.key_bits
23
+ return format.encode([key_field, self.value, self.children])
24
+
25
+ @classmethod
26
+ def from_bytes(cls, blob: bytes) -> "PatriciaNode":
27
+ key_field, value, children = format.decode(blob)
28
+ key_len = key_field[0]
29
+ key_bits = key_field[1:]
30
+ return cls(key_len, key_bits, value, children)
31
+
32
+ def hash(self) -> bytes:
33
+ if self._hash is None:
34
+ self._hash = blake3.blake3(self.to_bytes()).digest()
35
+ return self._hash
36
+
37
+ class PatriciaTrie:
38
+ def __init__(
39
+ self,
40
+ node_get: Callable[[bytes], Optional[bytes]],
41
+ root_hash: Optional[bytes] = None,
42
+ ) -> None:
43
+ self._node_get = node_get
44
+ self.nodes: Dict[bytes, bytes] = {}
45
+ self.root_hash: Optional[bytes] = root_hash
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: astreum
3
- Version: 0.2.9
3
+ Version: 0.2.11
4
4
  Summary: Python library to interact with the Astreum blockchain and its Lispeum virtual machine.
5
5
  Author-email: "Roy R. O. Okello" <roy@stelar.xyz>
6
6
  Project-URL: Homepage, https://github.com/astreum/lib
@@ -21,4 +21,6 @@ src/astreum/crypto/x25519.py
21
21
  src/astreum/lispeum/__init__.py
22
22
  src/astreum/lispeum/parser.py
23
23
  src/astreum/lispeum/tokenizer.py
24
+ src/astreum/utils/__init__.py
25
+ src/astreum/utils/patricia.py
24
26
  tests/test_node_machine.py
File without changes
File without changes
File without changes
File without changes