@le-space/rootfs 0.3.19 → 0.3.20

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@le-space/rootfs",
3
- "version": "0.3.19",
3
+ "version": "0.3.20",
4
4
  "description": "Shared rootfs contract parsing, reference profile assets, and build helpers.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -60,7 +60,8 @@ def dedupe(values: list[str]) -> list[str]:
60
60
  def sign_personal_message(private_key: str, payload: str) -> str:
61
61
  message = encode_defunct(text=payload)
62
62
  signed = Account.sign_message(message, private_key=private_key)
63
- return signed.signature.hex()
63
+ signature = signed.signature.hex()
64
+ return signature if signature.startswith("0x") else f"0x{signature}"
64
65
 
65
66
 
66
67
  def address_from_private_key(private_key: str) -> str:
@@ -110,6 +111,30 @@ def sign_aleph_message(unsigned_message: dict[str, object], private_key: str) ->
110
111
  return signed
111
112
 
112
113
 
114
+ def is_invalid_message_format(http_status: int, payload: dict) -> bool:
115
+ if http_status != 422:
116
+ return False
117
+ details = payload.get("details")
118
+ if isinstance(details, str) and "InvalidMessageFormat" in details:
119
+ return True
120
+ if isinstance(details, dict):
121
+ message = details.get("message")
122
+ if isinstance(message, str) and "InvalidMessageFormat" in message:
123
+ return True
124
+ return False
125
+
126
+
127
+ def is_retryable_broadcast_failure(http_status: int, payload: dict) -> bool:
128
+ if http_status >= 500:
129
+ return True
130
+ publication_status = payload.get("publication_status")
131
+ if isinstance(publication_status, dict):
132
+ status = publication_status.get("status")
133
+ if isinstance(status, str) and status.strip().lower() == "error":
134
+ return True
135
+ return False
136
+
137
+
113
138
  def broadcast_aleph_message(api_host: str, message: dict[str, object]) -> tuple[int, dict]:
114
139
  url = urllib.parse.urljoin(api_host.rstrip("/") + "/", "api/v0/messages")
115
140
  attempts = [
@@ -117,14 +142,17 @@ def broadcast_aleph_message(api_host: str, message: dict[str, object]) -> tuple[
117
142
  {**message, "sync": True},
118
143
  dict(message),
119
144
  ]
120
- last: tuple[int, dict] | None = None
121
- for attempt in attempts:
122
- last = post_json(url, attempt)
123
- if 200 <= last[0] < 300:
124
- return last
125
- if last is None:
126
- raise RuntimeError("Aleph broadcast failed before any attempt was made")
127
- raise RuntimeError(f"Aleph broadcast failed: {last[0]} {json_dumps(last[1])}")
145
+ for index, attempt in enumerate(attempts):
146
+ http_status, payload = post_json(url, attempt)
147
+ if 200 <= http_status < 300:
148
+ return http_status, payload
149
+ can_retry = index < len(attempts) - 1 and (
150
+ is_invalid_message_format(http_status, payload)
151
+ or is_retryable_broadcast_failure(http_status, payload)
152
+ )
153
+ if not can_retry:
154
+ raise RuntimeError(f"Aleph broadcast failed: {http_status} {json_dumps(payload)}")
155
+ raise RuntimeError("Aleph broadcast failed: no compatible request format was accepted")
128
156
 
129
157
 
130
158
  def parse_post_record(entry: object) -> dict[str, object] | None:
@@ -117,7 +117,8 @@ def json_dumps(payload: object) -> str:
117
117
  def sign_personal_message(private_key: str, payload: str) -> str:
118
118
  message = encode_defunct(text=payload)
119
119
  signed = Account.sign_message(message, private_key=private_key)
120
- return signed.signature.hex()
120
+ signature = signed.signature.hex()
121
+ return signature if signature.startswith("0x") else f"0x{signature}"
121
122
 
122
123
 
123
124
  def address_from_private_key(private_key: str) -> str:
@@ -302,6 +303,30 @@ def sign_aleph_message(unsigned_message: dict[str, object], private_key: str) ->
302
303
  return signed
303
304
 
304
305
 
306
+ def is_invalid_message_format(http_status: int, payload: dict) -> bool:
307
+ if http_status != 422:
308
+ return False
309
+ details = payload.get("details")
310
+ if isinstance(details, str) and "InvalidMessageFormat" in details:
311
+ return True
312
+ if isinstance(details, dict):
313
+ message = details.get("message")
314
+ if isinstance(message, str) and "InvalidMessageFormat" in message:
315
+ return True
316
+ return False
317
+
318
+
319
+ def is_retryable_broadcast_failure(http_status: int, payload: dict) -> bool:
320
+ if http_status >= 500:
321
+ return True
322
+ publication_status = payload.get("publication_status")
323
+ if isinstance(publication_status, dict):
324
+ status = publication_status.get("status")
325
+ if isinstance(status, str) and status.strip().lower() == "error":
326
+ return True
327
+ return False
328
+
329
+
305
330
  def broadcast_aleph_message(api_host: str, message: dict[str, object]) -> tuple[int, dict]:
306
331
  url = urllib.parse.urljoin(api_host.rstrip("/") + "/", "api/v0/messages")
307
332
  attempts = [
@@ -309,14 +334,17 @@ def broadcast_aleph_message(api_host: str, message: dict[str, object]) -> tuple[
309
334
  {**message, "sync": True},
310
335
  dict(message),
311
336
  ]
312
- last: tuple[int, dict] | None = None
313
- for attempt in attempts:
314
- last = post_json(url, attempt)
315
- if 200 <= last[0] < 300:
316
- return last
317
- if last is None:
318
- raise RuntimeError("Aleph broadcast failed before any attempt was made")
319
- raise RuntimeError(f"Aleph broadcast failed: {last[0]} {json_dumps(last[1])}")
337
+ for index, attempt in enumerate(attempts):
338
+ http_status, payload = post_json(url, attempt)
339
+ if 200 <= http_status < 300:
340
+ return http_status, payload
341
+ can_retry = index < len(attempts) - 1 and (
342
+ is_invalid_message_format(http_status, payload)
343
+ or is_retryable_broadcast_failure(http_status, payload)
344
+ )
345
+ if not can_retry:
346
+ raise RuntimeError(f"Aleph broadcast failed: {http_status} {json_dumps(payload)}")
347
+ raise RuntimeError("Aleph broadcast failed: no compatible request format was accepted")
320
348
 
321
349
 
322
350
  def parse_post_record(entry: object) -> dict[str, object] | None: