fix: stop shadowing json module in GlobalClient HTTP helper
Live VeraeTime token is stored in ~/.verae/auth.properties (not committed).
This commit is contained in:
parent
107fa785b0
commit
0714fff7fa
3 changed files with 19 additions and 17 deletions
|
|
@ -33,12 +33,12 @@ Tests:
|
||||||
uv run pytest
|
uv run pytest
|
||||||
```
|
```
|
||||||
|
|
||||||
Global stamp (central VeraeTime):
|
Global stamp (central VeraeTime). Token lives at `~/.verae/auth.properties` (mode 600):
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
export VERAE_GLOBAL_URL=https://api.veraetime.net
|
# refresh: POST https://api.veraetime.net/auth/login → access_token=
|
||||||
export VERAE_GLOBAL_TOKEN= # or put access_token= in ~/.verae/auth.properties
|
# or: export VERAE_GLOBAL_TOKEN=...
|
||||||
# then call tool stamp with scope=global
|
# then stamp with scope=global
|
||||||
```
|
```
|
||||||
|
|
||||||
Do not send file bytes to `stamp`. Local receipts persist at `~/.verae/mcp-timestamp-local.json` (`VERAE_LEDGER_PATH`).
|
Do not send file bytes to `stamp`. Local receipts persist at `~/.verae/mcp-timestamp-local.json` (`VERAE_LEDGER_PATH`).
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ DEFAULT_GLOBAL_URL = "https://api.veraetime.net"
|
||||||
|
|
||||||
class HttpTransport(Protocol):
|
class HttpTransport(Protocol):
|
||||||
def request(
|
def request(
|
||||||
self, method: str, url: str, json: dict[str, Any], headers: dict[str, str]
|
self, method: str, url: str, payload: dict[str, Any], headers: dict[str, str]
|
||||||
) -> Any: ...
|
) -> Any: ...
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -40,9 +40,9 @@ class _UrllibResp:
|
||||||
|
|
||||||
class UrllibHttp:
|
class UrllibHttp:
|
||||||
def request(
|
def request(
|
||||||
self, method: str, url: str, json: dict[str, Any], headers: dict[str, str]
|
self, method: str, url: str, payload: dict[str, Any], headers: dict[str, str]
|
||||||
) -> _UrllibResp:
|
) -> _UrllibResp:
|
||||||
data = json_dumps(json).encode()
|
data = json.dumps(payload).encode()
|
||||||
req = urllib.request.Request(url, data=data, method=method)
|
req = urllib.request.Request(url, data=data, method=method)
|
||||||
for key, value in headers.items():
|
for key, value in headers.items():
|
||||||
req.add_header(key, value)
|
req.add_header(key, value)
|
||||||
|
|
@ -60,10 +60,6 @@ class UrllibHttp:
|
||||||
return _UrllibResp(status, body, raw)
|
return _UrllibResp(status, body, raw)
|
||||||
|
|
||||||
|
|
||||||
def json_dumps(payload: dict[str, Any]) -> str:
|
|
||||||
return json.dumps(payload)
|
|
||||||
|
|
||||||
|
|
||||||
def load_auth_token() -> str:
|
def load_auth_token() -> str:
|
||||||
env = os.environ.get("VERAE_GLOBAL_TOKEN", "").strip()
|
env = os.environ.get("VERAE_GLOBAL_TOKEN", "").strip()
|
||||||
if env:
|
if env:
|
||||||
|
|
@ -108,7 +104,10 @@ class GlobalClient:
|
||||||
def submit(self, digest: str, cube_id: str = "") -> Receipt:
|
def submit(self, digest: str, cube_id: str = "") -> Receipt:
|
||||||
url = f"{self.base_url}/api/timestamp"
|
url = f"{self.base_url}/api/timestamp"
|
||||||
res = self.http.request(
|
res = self.http.request(
|
||||||
"POST", url, {"hash": digest, "sync": True}, self._headers()
|
"POST",
|
||||||
|
url,
|
||||||
|
payload={"hash": digest, "sync": True},
|
||||||
|
headers=self._headers(),
|
||||||
)
|
)
|
||||||
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}")
|
||||||
|
|
@ -128,7 +127,10 @@ class GlobalClient:
|
||||||
def verify_certificate(self, receipt_id: str) -> VerifyResult:
|
def verify_certificate(self, receipt_id: str) -> VerifyResult:
|
||||||
url = f"{self.base_url}/api/verify"
|
url = f"{self.base_url}/api/verify"
|
||||||
res = self.http.request(
|
res = self.http.request(
|
||||||
"POST", url, {"certificate": receipt_id}, self._headers()
|
"POST",
|
||||||
|
url,
|
||||||
|
payload={"certificate": receipt_id},
|
||||||
|
headers=self._headers(),
|
||||||
)
|
)
|
||||||
if res.status_code >= 300:
|
if res.status_code >= 300:
|
||||||
return VerifyResult(valid=False, error=f"verify HTTP {res.status_code}")
|
return VerifyResult(valid=False, error=f"verify HTTP {res.status_code}")
|
||||||
|
|
|
||||||
|
|
@ -22,20 +22,20 @@ class FakeHttp:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.calls: list[tuple[str, str, dict, dict]] = []
|
self.calls: list[tuple[str, str, dict, dict]] = []
|
||||||
|
|
||||||
def request(self, method: str, url: str, json: dict, headers: dict) -> _Resp:
|
def request(self, method: str, url: str, payload: dict, headers: dict) -> _Resp:
|
||||||
self.calls.append((method, url, json, headers))
|
self.calls.append((method, url, payload, headers))
|
||||||
if url.endswith("/api/timestamp"):
|
if url.endswith("/api/timestamp"):
|
||||||
return _Resp(
|
return _Resp(
|
||||||
200,
|
200,
|
||||||
{
|
{
|
||||||
"jobId": "job-1",
|
"jobId": "job-1",
|
||||||
"hash": json["hash"],
|
"hash": payload["hash"],
|
||||||
"timestamp": "2026-08-15T00:00:00Z",
|
"timestamp": "2026-08-15T00:00:00Z",
|
||||||
"blockHash": "0xdead",
|
"blockHash": "0xdead",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if url.endswith("/api/verify"):
|
if url.endswith("/api/verify"):
|
||||||
if json.get("certificate") == "job-1":
|
if payload.get("certificate") == "job-1":
|
||||||
return _Resp(200, {"valid": True, "hash": SHA256_EMPTY})
|
return _Resp(200, {"valid": True, "hash": SHA256_EMPTY})
|
||||||
return _Resp(200, {"valid": False})
|
return _Resp(200, {"valid": False})
|
||||||
return _Resp(404, {"error": "nope"})
|
return _Resp(404, {"error": "nope"})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue