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

@@ -5,11 +5,11 @@ This module provides functions to convert Lispeum expressions to an
5
5
  object-based Merkle tree representation for storage and retrieval.
6
6
  """
7
7
 
8
- import hashlib
9
8
  import struct
10
9
  from typing import Dict, Tuple, Any, List, Optional
11
10
 
12
11
  from astreum.lispeum.expression import Expr
12
+ from .utils import hash_data
13
13
 
14
14
 
15
15
  def expr_to_objects(expr: Any) -> Tuple[bytes, Dict[bytes, bytes]]:
@@ -61,7 +61,7 @@ def _serialize_expr(expr: Any, objects: Dict[bytes, bytes]) -> bytes:
61
61
 
62
62
  # Create the object with leaf flag and body
63
63
  object_bytes = struct.pack("?", is_leaf) + type_bytes
64
- object_hash = hashlib.sha256(object_bytes).digest()
64
+ object_hash = hash_data(object_bytes)
65
65
  objects[object_hash] = object_bytes
66
66
 
67
67
  return object_hash
@@ -82,7 +82,7 @@ def _serialize_expr(expr: Any, objects: Dict[bytes, bytes]) -> bytes:
82
82
 
83
83
  # Create the object with leaf flag and body
84
84
  object_bytes = struct.pack("?", is_leaf) + type_bytes + value_bytes
85
- object_hash = hashlib.sha256(object_bytes).digest()
85
+ object_hash = hash_data(object_bytes)
86
86
  objects[object_hash] = object_bytes
87
87
 
88
88
  return object_hash
@@ -95,7 +95,7 @@ def _serialize_expr(expr: Any, objects: Dict[bytes, bytes]) -> bytes:
95
95
 
96
96
  # Create the object with leaf flag and body
97
97
  object_bytes = struct.pack("?", is_leaf) + type_bytes + value_bytes
98
- object_hash = hashlib.sha256(object_bytes).digest()
98
+ object_hash = hash_data(object_bytes)
99
99
  objects[object_hash] = object_bytes
100
100
 
101
101
  return object_hash
@@ -108,7 +108,7 @@ def _serialize_expr(expr: Any, objects: Dict[bytes, bytes]) -> bytes:
108
108
 
109
109
  # Create the object with leaf flag and body
110
110
  object_bytes = struct.pack("?", is_leaf) + type_bytes + value_bytes
111
- object_hash = hashlib.sha256(object_bytes).digest()
111
+ object_hash = hash_data(object_bytes)
112
112
  objects[object_hash] = object_bytes
113
113
 
114
114
  return object_hash
@@ -121,7 +121,7 @@ def _serialize_expr(expr: Any, objects: Dict[bytes, bytes]) -> bytes:
121
121
 
122
122
  # Create the object with leaf flag and body
123
123
  object_bytes = struct.pack("?", is_leaf) + type_bytes + value_bytes
124
- object_hash = hashlib.sha256(object_bytes).digest()
124
+ object_hash = hash_data(object_bytes)
125
125
  objects[object_hash] = object_bytes
126
126
 
127
127
  return object_hash
@@ -134,7 +134,7 @@ def _serialize_expr(expr: Any, objects: Dict[bytes, bytes]) -> bytes:
134
134
 
135
135
  # Create the object with leaf flag and body
136
136
  object_bytes = struct.pack("?", is_leaf) + type_bytes + value_bytes
137
- object_hash = hashlib.sha256(object_bytes).digest()
137
+ object_hash = hash_data(object_bytes)
138
138
  objects[object_hash] = object_bytes
139
139
 
140
140
  return object_hash
@@ -155,7 +155,7 @@ def _serialize_expr(expr: Any, objects: Dict[bytes, bytes]) -> bytes:
155
155
 
156
156
  # Create the object with leaf flag and body
157
157
  object_bytes = struct.pack("?", is_leaf) + type_bytes + params_bytes + body_hash
158
- object_hash = hashlib.sha256(object_bytes).digest()
158
+ object_hash = hash_data(object_bytes)
159
159
  objects[object_hash] = object_bytes
160
160
 
161
161
  return object_hash
@@ -172,7 +172,7 @@ def _serialize_expr(expr: Any, objects: Dict[bytes, bytes]) -> bytes:
172
172
 
173
173
  # Create the object with leaf flag and body
174
174
  object_bytes = struct.pack("?", is_leaf) + type_bytes + category_bytes + b'\0' + message_bytes + b'\0' + details_bytes
175
- object_hash = hashlib.sha256(object_bytes).digest()
175
+ object_hash = hash_data(object_bytes)
176
176
  objects[object_hash] = object_bytes
177
177
 
178
178
  return object_hash
@@ -185,7 +185,7 @@ def _serialize_expr(expr: Any, objects: Dict[bytes, bytes]) -> bytes:
185
185
 
186
186
  # Create the object with leaf flag and body
187
187
  object_bytes = struct.pack("?", is_leaf) + type_bytes + value_bytes
188
- object_hash = hashlib.sha256(object_bytes).digest()
188
+ object_hash = hash_data(object_bytes)
189
189
  objects[object_hash] = object_bytes
190
190
 
191
191
  return object_hash
@@ -0,0 +1,17 @@
1
+ """
2
+ Utility functions for the Lispeum module.
3
+ """
4
+
5
+ import blake3
6
+
7
+ def hash_data(data: bytes) -> bytes:
8
+ """
9
+ Hash data using BLAKE3.
10
+
11
+ Args:
12
+ data: Data to hash
13
+
14
+ Returns:
15
+ 32-byte BLAKE3 hash
16
+ """
17
+ return blake3.blake3(data).digest()