feat: send digest and honor existing CID on global stamp
This commit is contained in:
parent
a6a1a70ee4
commit
a1cd93e2ce
2 changed files with 24 additions and 3 deletions
|
|
@ -126,12 +126,30 @@ class GlobalClient:
|
||||||
res = self.http.request(
|
res = self.http.request(
|
||||||
"POST",
|
"POST",
|
||||||
url,
|
url,
|
||||||
payload={"data": digest, "hashAlg": "SHA256"},
|
payload={
|
||||||
|
"data": digest,
|
||||||
|
"digest": digest,
|
||||||
|
"hashAlg": "SHA256",
|
||||||
|
"restamp": False,
|
||||||
|
},
|
||||||
headers=self._headers(),
|
headers=self._headers(),
|
||||||
)
|
)
|
||||||
|
parsed = res.json() if hasattr(res, "json") else {}
|
||||||
|
if res.status_code == 200 and isinstance(parsed, dict):
|
||||||
|
cid = str(parsed.get("certificate") or parsed.get("jobId") or "")
|
||||||
|
if cid:
|
||||||
|
return Receipt(
|
||||||
|
receipt_id=cid,
|
||||||
|
hash=digest,
|
||||||
|
scope="global",
|
||||||
|
cube_id=cube_id,
|
||||||
|
created_at=str(parsed.get("timestamp") or ""),
|
||||||
|
merkle=str(parsed.get("blockHash") or ""),
|
||||||
|
)
|
||||||
if res.status_code >= 300:
|
if res.status_code >= 300:
|
||||||
raise ValueError(f"global timestamp HTTP {res.status_code}: {res.text}")
|
raise ValueError(f"global timestamp HTTP {res.status_code}: {res.text}")
|
||||||
parsed = res.json()
|
if not isinstance(parsed, dict):
|
||||||
|
parsed = {}
|
||||||
job_id = parsed.get("jobId") or parsed.get("blockHash") or ""
|
job_id = parsed.get("jobId") or parsed.get("blockHash") or ""
|
||||||
if not job_id:
|
if not job_id:
|
||||||
raise ValueError("global timestamp response missing jobId")
|
raise ValueError("global timestamp response missing jobId")
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,10 @@ async def test_global_stamp_posts_hash_sync_and_maps_receipt():
|
||||||
method, url, payload, headers = http.calls[0]
|
method, url, payload, headers = http.calls[0]
|
||||||
assert method == "POST"
|
assert method == "POST"
|
||||||
assert url == "https://api.veraetime.net/api/timestamp"
|
assert url == "https://api.veraetime.net/api/timestamp"
|
||||||
assert payload == {"data": SHA256_EMPTY, "hashAlg": "SHA256"}
|
assert payload["data"] == SHA256_EMPTY
|
||||||
|
assert payload["digest"] == SHA256_EMPTY
|
||||||
|
assert payload["hashAlg"] == "SHA256"
|
||||||
|
assert payload["restamp"] is False
|
||||||
assert headers["Authorization"] == "Bearer secret"
|
assert headers["Authorization"] == "Bearer secret"
|
||||||
assert rec.scope == "global"
|
assert rec.scope == "global"
|
||||||
assert rec.receipt_id == "job-1"
|
assert rec.receipt_id == "job-1"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue