astreum 0.2.8__tar.gz → 0.2.10__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 (26) hide show
  1. {astreum-0.2.8/src/astreum.egg-info → astreum-0.2.10}/PKG-INFO +1 -1
  2. {astreum-0.2.8 → astreum-0.2.10}/pyproject.toml +1 -1
  3. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/node.py +185 -0
  4. {astreum-0.2.8 → astreum-0.2.10/src/astreum.egg-info}/PKG-INFO +1 -1
  5. {astreum-0.2.8 → astreum-0.2.10}/LICENSE +0 -0
  6. {astreum-0.2.8 → astreum-0.2.10}/README.md +0 -0
  7. {astreum-0.2.8 → astreum-0.2.10}/setup.cfg +0 -0
  8. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/__init__.py +0 -0
  9. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/_node/__init__.py +0 -0
  10. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/_node/storage/__init__.py +0 -0
  11. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/_node/storage/merkle.py +0 -0
  12. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/_node/storage/patricia.py +0 -0
  13. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/crypto/__init__.py +0 -0
  14. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/crypto/ed25519.py +0 -0
  15. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/crypto/quadratic_form.py +0 -0
  16. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/crypto/wesolowski.py +0 -0
  17. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/crypto/x25519.py +0 -0
  18. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/format.py +0 -0
  19. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/lispeum/__init__.py +0 -0
  20. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/lispeum/parser.py +0 -0
  21. {astreum-0.2.8 → astreum-0.2.10}/src/astreum/lispeum/tokenizer.py +0 -0
  22. {astreum-0.2.8 → astreum-0.2.10}/src/astreum.egg-info/SOURCES.txt +0 -0
  23. {astreum-0.2.8 → astreum-0.2.10}/src/astreum.egg-info/dependency_links.txt +0 -0
  24. {astreum-0.2.8 → astreum-0.2.10}/src/astreum.egg-info/requires.txt +0 -0
  25. {astreum-0.2.8 → astreum-0.2.10}/src/astreum.egg-info/top_level.txt +0 -0
  26. {astreum-0.2.8 → astreum-0.2.10}/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.8
3
+ Version: 0.2.10
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.8"
3
+ version = "0.2.10"
4
4
  authors = [
5
5
  { name="Roy R. O. Okello", email="roy@stelar.xyz" },
6
6
  ]
@@ -324,6 +324,181 @@ class Env:
324
324
  )
325
325
 
326
326
 
327
+ class Transaction:
328
+ def __init__(
329
+ self,
330
+ sender_pk: bytes,
331
+ recipient_pk: bytes,
332
+ amount: int,
333
+ fee: int,
334
+ nonce: int,
335
+ signature: bytes | None = None,
336
+ ) -> None:
337
+ self.sender_pk = sender_pk
338
+ self.recipient_pk = recipient_pk
339
+ self.amount = amount
340
+ self.fee = fee
341
+ self.nonce = nonce
342
+ self.signature = signature
343
+
344
+ if self.amount < 0 or self.fee < 0:
345
+ raise ValueError("amount and fee must be non-negative")
346
+
347
+ if self.fee % 2 != 0:
348
+ raise ValueError("fee must be divisible by two")
349
+
350
+ self.tx_body_hash: bytes = blake3.blake3(self._body_bytes()).digest()
351
+
352
+ if self.signature is not None:
353
+ self.tx_hash = blake3.blake3(self.tx_body_hash + self.signature).digest()
354
+ else:
355
+ self.tx_hash = None
356
+
357
+ def sign(self, priv_key: ed25519.Ed25519PrivateKey) -> None:
358
+ if self.signature is not None:
359
+ raise ValueError("transaction already signed")
360
+ sig = priv_key.sign(self.tx_body_hash)
361
+ self.signature = sig
362
+ self.tx_hash = blake3.blake3(self.tx_body_hash + sig).digest()
363
+
364
+ def verify_signature(self) -> bool:
365
+ if self.signature is None:
366
+ return False
367
+ try:
368
+ pub = ed25519.Ed25519PublicKey.from_public_bytes(self.sender_pk)
369
+ pub.verify(self.signature, self.tx_body_hash)
370
+ return True
371
+ except Exception:
372
+ return False
373
+
374
+ def to_bytes(self) -> bytes:
375
+ sig = self.signature or b""
376
+ return encode([
377
+ self.sender_pk,
378
+ self.recipient_pk,
379
+ self.amount,
380
+ self.fee,
381
+ self.nonce,
382
+ sig,
383
+ ])
384
+
385
+ @classmethod
386
+ def from_bytes(cls, blob: bytes) -> 'Transaction':
387
+ sender, recipient, amount, fee, nonce, sig = decode(blob)
388
+ return cls(sender, recipient, int(amount), int(fee), int(nonce), sig)
389
+
390
+ def _body_bytes(self) -> bytes:
391
+ return encode([
392
+ self.sender_pk,
393
+ self.recipient_pk,
394
+ self.amount,
395
+ self.fee,
396
+ self.nonce,
397
+ ])
398
+
399
+ def __eq__(self, other: Any) -> bool:
400
+ if not isinstance(other, Transaction):
401
+ return NotImplemented
402
+ return self.tx_hash == other.tx_hash
403
+
404
+ def __hash__(self) -> int:
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()
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
+
327
502
  class Node:
328
503
  def __init__(self, config: dict = {}):
329
504
  self._machine_setup()
@@ -331,6 +506,16 @@ class Node:
331
506
  if not machine_only:
332
507
  self._storage_setup(config=config)
333
508
  self._relay_setup(config=config)
509
+ self._validation_setup(config=config)
510
+
511
+ def _validation_setup(self, config: dict):
512
+ if True:
513
+ self.validator_transactions: Dict[bytes, Transaction] = {}
514
+ # validator thread
515
+ pass
516
+
517
+ def _create_block(self):
518
+ pass
334
519
 
335
520
  # STORAGE METHODS
336
521
  def _storage_setup(self, config: dict):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: astreum
3
- Version: 0.2.8
3
+ Version: 0.2.10
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
File without changes
File without changes
File without changes
File without changes