shield-python 0.1.4__py3-none-any.whl → 0.2.0__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.
- shield/__init__.py +1 -1
- shield/client.py +42 -11
- shield/exceptions.py +4 -12
- {shield_python-0.1.4.dist-info → shield_python-0.2.0.dist-info}/METADATA +17 -6
- shield_python-0.2.0.dist-info/RECORD +12 -0
- shield_python-0.2.0.dist-info/licenses/LICENSE +21 -0
- shield_python-0.1.4.dist-info/RECORD +0 -11
- {shield_python-0.1.4.dist-info → shield_python-0.2.0.dist-info}/WHEEL +0 -0
- {shield_python-0.1.4.dist-info → shield_python-0.2.0.dist-info}/top_level.txt +0 -0
shield/__init__.py
CHANGED
shield/client.py
CHANGED
|
@@ -3,7 +3,7 @@ import hmac as hmac_mod
|
|
|
3
3
|
import json
|
|
4
4
|
import time
|
|
5
5
|
from typing import Any, Dict, Optional
|
|
6
|
-
from urllib.parse import
|
|
6
|
+
from urllib.parse import urlencode
|
|
7
7
|
|
|
8
8
|
import requests
|
|
9
9
|
|
|
@@ -12,6 +12,10 @@ from .resources.sessions import Sessions
|
|
|
12
12
|
from .resources.events import Events
|
|
13
13
|
from .resources.verify import Verify
|
|
14
14
|
|
|
15
|
+
# ARCH-019: kept static to avoid leaking Python version / OS into server logs.
|
|
16
|
+
# Bumped alongside setup.py version on each release.
|
|
17
|
+
SDK_USER_AGENT = "shield-python/0.2.0"
|
|
18
|
+
|
|
15
19
|
|
|
16
20
|
class Client:
|
|
17
21
|
"""Official Shield Python SDK client.
|
|
@@ -30,6 +34,14 @@ class Client:
|
|
|
30
34
|
hmac_secret: Optional[str] = None,
|
|
31
35
|
timeout: int = 30,
|
|
32
36
|
):
|
|
37
|
+
if not hmac_secret:
|
|
38
|
+
raise ShieldError(
|
|
39
|
+
message=(
|
|
40
|
+
"hmac_secret is required. All write operations must be signed. "
|
|
41
|
+
"See https://docs.getshield.dev/authentication"
|
|
42
|
+
),
|
|
43
|
+
status_code=0,
|
|
44
|
+
)
|
|
33
45
|
self.api_key = api_key
|
|
34
46
|
self.base_url = base_url.rstrip("/")
|
|
35
47
|
self.hmac_secret = hmac_secret
|
|
@@ -64,12 +76,29 @@ class Client:
|
|
|
64
76
|
Raises:
|
|
65
77
|
ShieldError: On non-2xx responses or request failures.
|
|
66
78
|
"""
|
|
67
|
-
url = f"{self.base_url}{path}"
|
|
68
79
|
method = method.upper()
|
|
69
80
|
|
|
81
|
+
# C-1 (v0.1.6): fold query params into `path` BEFORE signing so the
|
|
82
|
+
# canonical message matches what the server validates against
|
|
83
|
+
# http.Request.URL.RequestURI(). Previously `params` was passed to
|
|
84
|
+
# requests.request() separately — requests would append them to the
|
|
85
|
+
# wire URL, but the SDK signed only the bare path, guaranteeing a
|
|
86
|
+
# signature mismatch on any request with query params. We pre-encode
|
|
87
|
+
# here and pass params=None to requests so there is exactly one
|
|
88
|
+
# canonical query string, controlled by this SDK, for both signing
|
|
89
|
+
# and transmission. doseq=True matches requests' own encoding for
|
|
90
|
+
# list-valued params (?tag=a&tag=b).
|
|
91
|
+
if params:
|
|
92
|
+
path_with_query = f"{path}?{urlencode(params, doseq=True)}"
|
|
93
|
+
else:
|
|
94
|
+
path_with_query = path
|
|
95
|
+
|
|
96
|
+
url = f"{self.base_url}{path_with_query}"
|
|
97
|
+
|
|
70
98
|
headers = {
|
|
71
99
|
"X-Shield-Key": self.api_key,
|
|
72
100
|
"Content-Type": "application/json",
|
|
101
|
+
"User-Agent": SDK_USER_AGENT,
|
|
73
102
|
}
|
|
74
103
|
|
|
75
104
|
# Serialize body
|
|
@@ -83,7 +112,7 @@ class Client:
|
|
|
83
112
|
timestamp = str(int(time.time()))
|
|
84
113
|
nonce = str(uuid.uuid4())
|
|
85
114
|
body_hash = hashlib.sha256(body).hexdigest()
|
|
86
|
-
message = f"{timestamp}.{method}.{
|
|
115
|
+
message = f"{timestamp}.{method}.{path_with_query}.{body_hash}"
|
|
87
116
|
signature = hmac_mod.new(
|
|
88
117
|
self.hmac_secret.encode("utf-8"),
|
|
89
118
|
message.encode("utf-8"),
|
|
@@ -99,29 +128,31 @@ class Client:
|
|
|
99
128
|
url=url,
|
|
100
129
|
headers=headers,
|
|
101
130
|
data=body if body else None,
|
|
102
|
-
params=
|
|
131
|
+
params=None,
|
|
103
132
|
timeout=self.timeout,
|
|
104
133
|
)
|
|
105
134
|
except requests.RequestException as e:
|
|
106
135
|
raise ShieldError(
|
|
107
136
|
message=f"Request failed: {str(e)}",
|
|
108
137
|
status_code=0,
|
|
109
|
-
code="request_error",
|
|
110
138
|
)
|
|
111
139
|
|
|
112
140
|
if not (200 <= response.status_code < 300):
|
|
113
|
-
|
|
114
|
-
|
|
141
|
+
# Backend returns {"error": "..."} (always) and sometimes
|
|
142
|
+
# {"message": "..."} with extra detail. Prefer message when present.
|
|
143
|
+
error_message = response.text or response.reason
|
|
115
144
|
try:
|
|
116
145
|
error_body = response.json()
|
|
117
|
-
error_message =
|
|
118
|
-
|
|
119
|
-
|
|
146
|
+
error_message = (
|
|
147
|
+
error_body.get("message")
|
|
148
|
+
or error_body.get("error")
|
|
149
|
+
or error_message
|
|
150
|
+
)
|
|
151
|
+
except ValueError:
|
|
120
152
|
pass
|
|
121
153
|
raise ShieldError(
|
|
122
154
|
message=error_message,
|
|
123
155
|
status_code=response.status_code,
|
|
124
|
-
code=error_code,
|
|
125
156
|
)
|
|
126
157
|
|
|
127
158
|
if raw_response:
|
shield/exceptions.py
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
class ShieldError(Exception):
|
|
2
2
|
"""Base exception for Shield SDK errors."""
|
|
3
3
|
|
|
4
|
-
def __init__(self, message: str, status_code: int = None
|
|
4
|
+
def __init__(self, message: str, status_code: int = None):
|
|
5
5
|
super().__init__(message)
|
|
6
6
|
self.message = message
|
|
7
7
|
self.status_code = status_code
|
|
8
|
-
self.code = code
|
|
9
8
|
|
|
10
9
|
def __str__(self):
|
|
11
|
-
parts = []
|
|
12
10
|
if self.status_code:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
parts.append(f"({self.code})")
|
|
16
|
-
parts.append(self.message)
|
|
17
|
-
return " ".join(parts)
|
|
11
|
+
return f"[{self.status_code}] {self.message}"
|
|
12
|
+
return self.message
|
|
18
13
|
|
|
19
14
|
def __repr__(self):
|
|
20
|
-
return (
|
|
21
|
-
f"ShieldError(message={self.message!r}, "
|
|
22
|
-
f"status_code={self.status_code!r}, code={self.code!r})"
|
|
23
|
-
)
|
|
15
|
+
return f"ShieldError(message={self.message!r}, status_code={self.status_code!r})"
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: shield-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Official Shield SDK for Python
|
|
5
5
|
License: MIT
|
|
6
6
|
Project-URL: Homepage, https://getshield.dev
|
|
7
|
-
Project-URL: Documentation, https://
|
|
7
|
+
Project-URL: Documentation, https://getshield.dev/docs
|
|
8
8
|
Requires-Python: >=3.8
|
|
9
9
|
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
10
11
|
Requires-Dist: requests>=2.28.0
|
|
12
|
+
Dynamic: license-file
|
|
11
13
|
|
|
12
14
|
# Shield Python SDK
|
|
13
15
|
|
|
@@ -16,7 +18,7 @@ Official Python SDK for [Shield](https://getshield.dev) ??tamper-evident session
|
|
|
16
18
|
## Installation
|
|
17
19
|
|
|
18
20
|
```bash
|
|
19
|
-
pip install shield-python
|
|
21
|
+
pip install shield-python==0.1.6
|
|
20
22
|
```
|
|
21
23
|
|
|
22
24
|
## Quick Start
|
|
@@ -54,7 +56,7 @@ client.events.create(
|
|
|
54
56
|
|
|
55
57
|
# Verify session integrity
|
|
56
58
|
result = client.verify.session(session_id)
|
|
57
|
-
print(result["
|
|
59
|
+
print(result["valid"]) # True
|
|
58
60
|
|
|
59
61
|
# Export session
|
|
60
62
|
pdf_bytes = client.sessions.export(session_id, format="pdf")
|
|
@@ -123,7 +125,7 @@ def sign_agreement(session_id):
|
|
|
123
125
|
session_id=session_id,
|
|
124
126
|
event_type="shield.agreement.signed",
|
|
125
127
|
actor=data["signer_email"],
|
|
126
|
-
data={"document": data["document_name"]
|
|
128
|
+
data={"document": data["document_name"]},
|
|
127
129
|
)
|
|
128
130
|
return jsonify({"status": "signed"}), 200
|
|
129
131
|
```
|
|
@@ -192,7 +194,7 @@ async def verify_session(session_id: str):
|
|
|
192
194
|
|
|
193
195
|
## Event Types Reference
|
|
194
196
|
|
|
195
|
-
Shield Standard Event Taxonomy v1.0
|
|
197
|
+
Shield Standard Event Taxonomy v1.0 — 39 event types across 8 categories:
|
|
196
198
|
|
|
197
199
|
### Party Events
|
|
198
200
|
| Event Type | Description |
|
|
@@ -264,3 +266,12 @@ Shield Standard Event Taxonomy v1.0 ??37 event types across 7 categories:
|
|
|
264
266
|
| `shield.evidence.exported` | Evidence was exported |
|
|
265
267
|
| `shield.evidence.verified` | Evidence was verified |
|
|
266
268
|
| `shield.evidence.tampered_detected` | Evidence tampering was detected |
|
|
269
|
+
|
|
270
|
+
## Versioning & API compatibility
|
|
271
|
+
|
|
272
|
+
This SDK follows [Semantic Versioning](https://semver.org/).
|
|
273
|
+
|
|
274
|
+
- **Pre-1.0** (current): minor-version bumps may ship breaking changes. Pin the full version in `requirements.txt`.
|
|
275
|
+
- **1.0 and later**: the public API is stable within a major version. Breaking changes require a major-version bump.
|
|
276
|
+
|
|
277
|
+
The Shield HTTP API is versioned at the URL path (`/api/v1`). This SDK targets `/api/v1` and will not transparently follow a server-side version bump — a new server major version will be delivered as a new SDK major version so callers opt in explicitly.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
shield/__init__.py,sha256=5SoNzgp4CLk9XCzh3XlYfdRtXZXkXRBvtnKAIU0T6xA,122
|
|
2
|
+
shield/client.py,sha256=hNzvYzymJmwR-nrn3wQJ2QvBlORfGBPDMJsNoXmZqt8,5583
|
|
3
|
+
shield/exceptions.py,sha256=GgC2gtEvgCTxqekJyu7BJdHGi3sY1NzGWOEWkARpci8,500
|
|
4
|
+
shield/resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
shield/resources/events.py,sha256=uH0TG235kRsoS6sOp-zPIcy5WbbtaPNAhC8aFMy00Po,1093
|
|
6
|
+
shield/resources/sessions.py,sha256=qOnJlpCx2Zk5nEh5TCFkf6v05l4M5SKAeF7klQ9YCQM,1268
|
|
7
|
+
shield/resources/verify.py,sha256=vGN51EWU56jOl8BVfNlfiP0ivkNvkLykicupGIGcpAw,498
|
|
8
|
+
shield_python-0.2.0.dist-info/licenses/LICENSE,sha256=q9AbInAHssIXz7La3zZMTD7ZAkEdS7RZ3W1rBiDrmAw,1063
|
|
9
|
+
shield_python-0.2.0.dist-info/METADATA,sha256=MXqZ_3B22TaQT_i84s9RvEtEnRy0JmQ5L-DOXpUHa08,8668
|
|
10
|
+
shield_python-0.2.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
11
|
+
shield_python-0.2.0.dist-info/top_level.txt,sha256=XumpIzJqChucal6arFU8u2d4ua7RA9yPcBSJFUi0JDU,7
|
|
12
|
+
shield_python-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shield
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
shield/__init__.py,sha256=nXw1gar8DlzsZvb057b9Z3Gn4Fuudow06cbyizD4yfM,122
|
|
2
|
-
shield/client.py,sha256=bTt-QylDQ92sIVBo3Q5aBe9aCDNmWmlQDYby8s5dGl4,4091
|
|
3
|
-
shield/exceptions.py,sha256=PunpNnkqyP-9ZhLwPAwH4ZqpxL6rg_KxwaQi9_hdo9I,717
|
|
4
|
-
shield/resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
shield/resources/events.py,sha256=uH0TG235kRsoS6sOp-zPIcy5WbbtaPNAhC8aFMy00Po,1093
|
|
6
|
-
shield/resources/sessions.py,sha256=qOnJlpCx2Zk5nEh5TCFkf6v05l4M5SKAeF7klQ9YCQM,1268
|
|
7
|
-
shield/resources/verify.py,sha256=vGN51EWU56jOl8BVfNlfiP0ivkNvkLykicupGIGcpAw,498
|
|
8
|
-
shield_python-0.1.4.dist-info/METADATA,sha256=fUMubnzO_KaApcKE6hLQJzbgveIocWYNwO_v_itkXYI,8044
|
|
9
|
-
shield_python-0.1.4.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
10
|
-
shield_python-0.1.4.dist-info/top_level.txt,sha256=XumpIzJqChucal6arFU8u2d4ua7RA9yPcBSJFUi0JDU,7
|
|
11
|
-
shield_python-0.1.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|