astreum 0.2.12__py3-none-any.whl → 0.2.13__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.

@@ -0,0 +1,83 @@
1
+ from ..format import encode, decode
2
+ from ..crypto import ed25519
3
+ import blake3
4
+
5
+ class Transaction:
6
+ def __init__(
7
+ self,
8
+ sender_pk: bytes,
9
+ recipient_pk: bytes,
10
+ amount: int,
11
+ fee: int,
12
+ nonce: int,
13
+ signature: bytes | None = None,
14
+ ) -> None:
15
+ self.sender_pk = sender_pk
16
+ self.recipient_pk = recipient_pk
17
+ self.amount = amount
18
+ self.fee = fee
19
+ self.nonce = nonce
20
+ self.signature = signature
21
+
22
+ if self.amount < 0 or self.fee < 0:
23
+ raise ValueError("amount and fee must be non-negative")
24
+
25
+ if self.fee % 2 != 0:
26
+ raise ValueError("fee must be divisible by two")
27
+
28
+ self.tx_body_hash: bytes = blake3.blake3(self._body_bytes()).digest()
29
+
30
+ if self.signature is not None:
31
+ self.tx_hash = blake3.blake3(self.tx_body_hash + self.signature).digest()
32
+ else:
33
+ self.tx_hash = None
34
+
35
+ def sign(self, priv_key: ed25519.Ed25519PrivateKey) -> None:
36
+ if self.signature is not None:
37
+ raise ValueError("transaction already signed")
38
+ sig = priv_key.sign(self.tx_body_hash)
39
+ self.signature = sig
40
+ self.tx_hash = blake3.blake3(self.tx_body_hash + sig).digest()
41
+
42
+ def verify_signature(self) -> bool:
43
+ if self.signature is None:
44
+ return False
45
+ try:
46
+ pub = ed25519.Ed25519PublicKey.from_public_bytes(self.sender_pk)
47
+ pub.verify(self.signature, self.tx_body_hash)
48
+ return True
49
+ except Exception:
50
+ return False
51
+
52
+ def to_bytes(self) -> bytes:
53
+ sig = self.signature or b""
54
+ return encode([
55
+ self.sender_pk,
56
+ self.recipient_pk,
57
+ self.amount,
58
+ self.fee,
59
+ self.nonce,
60
+ sig,
61
+ ])
62
+
63
+ @classmethod
64
+ def from_bytes(cls, blob: bytes) -> 'Transaction':
65
+ sender, recipient, amount, fee, nonce, sig = decode(blob)
66
+ return cls(sender, recipient, int(amount), int(fee), int(nonce), sig)
67
+
68
+ def _body_bytes(self) -> bytes:
69
+ return encode([
70
+ self.sender_pk,
71
+ self.recipient_pk,
72
+ self.amount,
73
+ self.fee,
74
+ self.nonce,
75
+ ])
76
+
77
+ def __eq__(self, other: "Transaction") -> bool:
78
+ if not isinstance(other, Transaction):
79
+ return NotImplemented
80
+ return self.tx_hash == other.tx_hash
81
+
82
+ def __hash__(self) -> int:
83
+ return int.from_bytes(self.tx_hash, 'big')
astreum/node.py CHANGED
@@ -6,6 +6,8 @@ from pathlib import Path
6
6
  from typing import Tuple, Dict, Union, Optional, List
7
7
  from datetime import datetime, timedelta, timezone
8
8
  import uuid
9
+
10
+ from .models.transaction import Transaction
9
11
  from .format import encode, decode
10
12
  from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey, X25519PublicKey
11
13
  from cryptography.hazmat.primitives import serialization
@@ -323,87 +325,6 @@ class Env:
323
325
  f"parent_id={self.parent_id})"
324
326
  )
325
327
 
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
328
  class Block:
408
329
  def __init__(
409
330
  self,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: astreum
3
- Version: 0.2.12
3
+ Version: 0.2.13
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
@@ -118,6 +118,6 @@ except ParseError as e:
118
118
  ## Testing
119
119
 
120
120
  ```bash
121
-
121
+ source venv/bin/activate
122
122
  python3 -m unittest discover -s tests
123
123
  ```
@@ -1,6 +1,6 @@
1
1
  astreum/__init__.py,sha256=y2Ok3EY_FstcmlVASr80lGR_0w-dH-SXDCCQFmL6uwA,28
2
2
  astreum/format.py,sha256=X4tG5GGPweNCE54bHYkLFiuLTbmpy5upO_s1Cef-MGA,2711
3
- astreum/node.py,sha256=neP-Ix5m0dm0eGOpaVkk9YmtB6LMvtCN8bnx25ZkW1E,51513
3
+ astreum/node.py,sha256=B0v9KIoL16TmzQloDdUkPk7e-3_aDc2FS3-ggu1HtB0,49116
4
4
  astreum/_node/__init__.py,sha256=7yz1YHo0DCUgUQvJf75qdUo_ocl5-XZRU-Vc2NhcvJs,18639
5
5
  astreum/_node/storage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  astreum/_node/storage/merkle.py,sha256=XCQBrHbwI0FuPTCUwHOy-Kva3uWbvCdw_-13hRPf1UI,10219
@@ -13,10 +13,11 @@ astreum/crypto/x25519.py,sha256=i29v4BmwKRcbz9E7NKqFDQyxzFtJUqN0St9jd7GS1uA,1137
13
13
  astreum/lispeum/__init__.py,sha256=K-NDzIjtIsXzC9X7lnYvlvIaVxjFcY7WNsgLIE3DH3U,58
14
14
  astreum/lispeum/parser.py,sha256=jQRzZYvBuSg8t_bxsbt1-WcHaR_LPveHNX7Qlxhaw-M,1165
15
15
  astreum/lispeum/tokenizer.py,sha256=J-I7MEd0r2ZoVqxvRPlu-Afe2ZdM0tKXXhf1R4SxYTo,1429
16
- astreum/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
- astreum/utils/patricia.py,sha256=D7UVU4b6Yvn2_McI35VoMEbpqwR8OmZon5LGoUSRADo,8913
18
- astreum-0.2.12.dist-info/licenses/LICENSE,sha256=gYBvRDP-cPLmTyJhvZ346QkrYW_eleke4Z2Yyyu43eQ,1089
19
- astreum-0.2.12.dist-info/METADATA,sha256=lpoXNcNED3phD7Rb3PuwLYjy6cpoQFcsR9exdUAs42Q,5454
20
- astreum-0.2.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
21
- astreum-0.2.12.dist-info/top_level.txt,sha256=1EG1GmkOk3NPmUA98FZNdKouhRyget-KiFiMk0i2Uz0,8
22
- astreum-0.2.12.dist-info/RECORD,,
16
+ astreum/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
+ astreum/models/patricia.py,sha256=D7UVU4b6Yvn2_McI35VoMEbpqwR8OmZon5LGoUSRADo,8913
18
+ astreum/models/transaction.py,sha256=Vu0cfmh80S31nEbxyJfv1dk9_zqtgGNyMdhlM0uQF4E,2611
19
+ astreum-0.2.13.dist-info/licenses/LICENSE,sha256=gYBvRDP-cPLmTyJhvZ346QkrYW_eleke4Z2Yyyu43eQ,1089
20
+ astreum-0.2.13.dist-info/METADATA,sha256=ZSKRGYPgPEaAgzNzKgYlEk2hWQP7nOZX3hNl5H76JFs,5478
21
+ astreum-0.2.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
22
+ astreum-0.2.13.dist-info/top_level.txt,sha256=1EG1GmkOk3NPmUA98FZNdKouhRyget-KiFiMk0i2Uz0,8
23
+ astreum-0.2.13.dist-info/RECORD,,
File without changes
File without changes