Skip to content

Commit 9f5b9de

Browse files
barrettk8090claude
andcommitted
Add complete Attestation API v2 endpoint coverage
Expanded attestation.py to include all endpoints from the DIMO Attestation API documentation, providing full support for verifiable credentials including odometer statements, vehicle health reports, and position attestations. - Updated create_vin_vc to use v2 endpoint - Added create_odometer_statement for odometer reading VCs - Added create_vehicle_health for health status verification - Added create_vehicle_position for location attestations - Added comprehensive docstrings to all methods - Maintained backward compatibility with existing v1 endpoints 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 304d5fa commit 9f5b9de

File tree

1 file changed

+114
-4
lines changed

1 file changed

+114
-4
lines changed

dimo/api/attestation.py

Lines changed: 114 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from dimo.errors import check_type
1+
from dimo.errors import check_type, check_optional_type
2+
from typing import Optional
23

34

45
class Attestation:
@@ -7,22 +8,131 @@ def __init__(self, request_method, get_auth_headers):
78
self._get_auth_headers = get_auth_headers
89

910
def create_vin_vc(self, vehicle_jwt: str, token_id: int) -> dict:
11+
"""
12+
Generate cryptographic proof of a vehicle's VIN or retrieve existing unexpired attestation.
13+
14+
Args:
15+
vehicle_jwt (str): Authentication JWT token
16+
token_id (int): Vehicle token identifier
17+
18+
Returns:
19+
dict: Response containing vcUrl, vcQuery, and confirmation message
20+
"""
1021
check_type("vehicle_jwt", vehicle_jwt, str)
1122
check_type("token_id", token_id, int)
12-
params = {"force": True}
13-
url = f"/v1/vc/vin/{token_id}"
23+
url = f"/v2/attestation/vin/{token_id}"
1424
return self._request(
1525
"POST",
1626
"Attestation",
1727
url,
18-
params=params,
1928
headers=self._get_auth_headers(vehicle_jwt),
2029
)
2130

2231
def create_pom_vc(self, vehicle_jwt: str, token_id: int) -> dict:
32+
"""
33+
Create proof of movement verifiable credential (v1 API).
34+
35+
Args:
36+
vehicle_jwt (str): Authentication JWT token
37+
token_id (int): Vehicle token identifier
38+
39+
Returns:
40+
dict: Response from the API
41+
"""
2342
check_type("vehicle_jwt", vehicle_jwt, str)
2443
check_type("token_id", token_id, int)
2544
url = f"/v1/vc/pom/{token_id}"
2645
return self._request(
2746
"POST", "Attestation", url, headers=self._get_auth_headers(vehicle_jwt)
2847
)
48+
49+
def create_odometer_statement(
50+
self, vehicle_jwt: str, token_id: int, timestamp: Optional[str] = None
51+
) -> dict:
52+
"""
53+
Produce verifiable odometer reading attestation.
54+
55+
Args:
56+
vehicle_jwt (str): Authentication JWT token
57+
token_id (int): Vehicle token identifier
58+
timestamp (str, optional): Specific moment for reading (ISO 8601 format)
59+
60+
Returns:
61+
dict: Success message directing to telemetry-api retrieval
62+
"""
63+
check_type("vehicle_jwt", vehicle_jwt, str)
64+
check_type("token_id", token_id, int)
65+
check_optional_type("timestamp", timestamp, str)
66+
67+
url = f"/v2/attestation/odometer-statement/{token_id}"
68+
data = {}
69+
if timestamp:
70+
data["timestamp"] = timestamp
71+
72+
return self._request(
73+
"POST",
74+
"Attestation",
75+
url,
76+
headers=self._get_auth_headers(vehicle_jwt),
77+
data=data if data else None,
78+
)
79+
80+
def create_vehicle_health(
81+
self, vehicle_jwt: str, token_id: int, start_time: str, end_time: str
82+
) -> dict:
83+
"""
84+
Generate health status verification for specified timeframe.
85+
86+
Args:
87+
vehicle_jwt (str): Authentication JWT token
88+
token_id (int): Vehicle token identifier
89+
start_time (str): Report beginning (ISO 8601 format)
90+
end_time (str): Report conclusion (ISO 8601 format)
91+
92+
Returns:
93+
dict: Success message with telemetry-api retrieval instructions
94+
"""
95+
check_type("vehicle_jwt", vehicle_jwt, str)
96+
check_type("token_id", token_id, int)
97+
check_type("start_time", start_time, str)
98+
check_type("end_time", end_time, str)
99+
100+
url = f"/v2/attestation/vehicle-health/{token_id}"
101+
data = {"startTime": start_time, "endTime": end_time}
102+
103+
return self._request(
104+
"POST",
105+
"Attestation",
106+
url,
107+
headers=self._get_auth_headers(vehicle_jwt),
108+
data=data,
109+
)
110+
111+
def create_vehicle_position(
112+
self, vehicle_jwt: str, token_id: int, timestamp: str
113+
) -> dict:
114+
"""
115+
Produce location verification at specified moment.
116+
117+
Args:
118+
vehicle_jwt (str): Authentication JWT token
119+
token_id (int): Vehicle token identifier
120+
timestamp (str): Location snapshot timing (ISO 8601 format)
121+
122+
Returns:
123+
dict: Success message with telemetry-api retrieval instructions
124+
"""
125+
check_type("vehicle_jwt", vehicle_jwt, str)
126+
check_type("token_id", token_id, int)
127+
check_type("timestamp", timestamp, str)
128+
129+
url = f"/v2/attestation/vehicle-position/{token_id}"
130+
data = {"timestamp": timestamp}
131+
132+
return self._request(
133+
"POST",
134+
"Attestation",
135+
url,
136+
headers=self._get_auth_headers(vehicle_jwt),
137+
data=data,
138+
)

0 commit comments

Comments
 (0)