signunder 0.1.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.
- signunder/__init__.py +19 -0
- signunder/_client.py +225 -0
- signunder/_models.py +155 -0
- signunder/py.typed +0 -0
- signunder-0.1.0.dist-info/METADATA +62 -0
- signunder-0.1.0.dist-info/RECORD +8 -0
- signunder-0.1.0.dist-info/WHEEL +4 -0
- signunder-0.1.0.dist-info/licenses/LICENSE +202 -0
signunder/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Python client for SignUnder: sign AI-generated images under your own name, with
|
|
2
|
+
Content Credentials, an invisible watermark and a fingerprint, and verify them.
|
|
3
|
+
|
|
4
|
+
Docs: https://signunder.com/docs
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from ._client import DEFAULT_BASE_URL, AsyncSignunder, Signunder
|
|
8
|
+
from ._models import Record, SignedAsset, SignunderError, Verification
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"DEFAULT_BASE_URL",
|
|
12
|
+
"AsyncSignunder",
|
|
13
|
+
"Record",
|
|
14
|
+
"SignedAsset",
|
|
15
|
+
"Signunder",
|
|
16
|
+
"SignunderError",
|
|
17
|
+
"Verification",
|
|
18
|
+
]
|
|
19
|
+
__version__ = "0.1.0"
|
signunder/_client.py
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from os import PathLike
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import IO, Any, Union
|
|
7
|
+
from urllib.parse import quote
|
|
8
|
+
|
|
9
|
+
import httpx
|
|
10
|
+
from typing_extensions import Self
|
|
11
|
+
|
|
12
|
+
from ._models import Record, SignedAsset, SignunderError, Verification
|
|
13
|
+
|
|
14
|
+
#: Early access runs on SignUnder's staging service; production will have its own address.
|
|
15
|
+
DEFAULT_BASE_URL = "https://signunder-staging-api.fly.dev"
|
|
16
|
+
|
|
17
|
+
#: A path, the image's bytes, or an open binary file.
|
|
18
|
+
Image = Union[str, PathLike, bytes, bytearray, IO[bytes]]
|
|
19
|
+
|
|
20
|
+
_EXTENSIONS = {
|
|
21
|
+
".jpg": "image/jpeg",
|
|
22
|
+
".jpeg": "image/jpeg",
|
|
23
|
+
".png": "image/png",
|
|
24
|
+
".webp": "image/webp",
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _sniff(head: bytes) -> str | None:
|
|
29
|
+
if head.startswith(b"\xff\xd8\xff"):
|
|
30
|
+
return "image/jpeg"
|
|
31
|
+
if head.startswith(b"\x89PNG\r\n\x1a\n"):
|
|
32
|
+
return "image/png"
|
|
33
|
+
if head[:4] == b"RIFF" and head[8:12] == b"WEBP":
|
|
34
|
+
return "image/webp"
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _upload(image: Image, content_type: str | None, filename: str | None) -> tuple[str, bytes, str]:
|
|
39
|
+
"""The multipart file tuple for ``image``: its name, bytes and media type."""
|
|
40
|
+
if isinstance(image, (str, PathLike)):
|
|
41
|
+
path = Path(image)
|
|
42
|
+
data = path.read_bytes()
|
|
43
|
+
filename = filename or path.name
|
|
44
|
+
elif isinstance(image, (bytes, bytearray)):
|
|
45
|
+
data = bytes(image)
|
|
46
|
+
else:
|
|
47
|
+
data = image.read()
|
|
48
|
+
filename = filename or Path(getattr(image, "name", "") or "").name or None
|
|
49
|
+
if not data:
|
|
50
|
+
raise ValueError("The image is empty.")
|
|
51
|
+
kind = content_type or _sniff(data[:16]) or _EXTENSIONS.get(Path(filename or "").suffix.lower())
|
|
52
|
+
if kind not in _EXTENSIONS.values():
|
|
53
|
+
raise ValueError(
|
|
54
|
+
"SignUnder signs JPEG, PNG and WebP images; pass content_type if the file is one."
|
|
55
|
+
)
|
|
56
|
+
return (
|
|
57
|
+
filename
|
|
58
|
+
or "image" + {"image/jpeg": ".jpg", "image/png": ".png", "image/webp": ".webp"}[kind],
|
|
59
|
+
data,
|
|
60
|
+
kind,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _raise_unless_ok(response: httpx.Response) -> None:
|
|
65
|
+
if response.is_success:
|
|
66
|
+
return
|
|
67
|
+
detail = response.reason_phrase or "Request failed"
|
|
68
|
+
try:
|
|
69
|
+
body = response.json()
|
|
70
|
+
detail = body.get("detail") or body.get("title") or detail
|
|
71
|
+
except ValueError:
|
|
72
|
+
pass
|
|
73
|
+
raise SignunderError(response.status_code, detail)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _signed(response: httpx.Response, content_type: str) -> SignedAsset:
|
|
77
|
+
_raise_unless_ok(response)
|
|
78
|
+
record_id = response.headers.get("SignUnder-Record-Id")
|
|
79
|
+
manifest_hash = response.headers.get("SignUnder-Manifest-Hash")
|
|
80
|
+
if not record_id or not manifest_hash:
|
|
81
|
+
raise SignunderError(
|
|
82
|
+
response.status_code, "The response had no record id or manifest hash."
|
|
83
|
+
)
|
|
84
|
+
media_type = response.headers.get("content-type", content_type).split(";")[0].strip()
|
|
85
|
+
return SignedAsset(response.content, media_type, record_id, manifest_hash)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _settings(api_key: str | None, base_url: str | None) -> tuple[str, str]:
|
|
89
|
+
key = api_key or os.environ.get("SIGNUNDER_API_KEY")
|
|
90
|
+
if not key:
|
|
91
|
+
raise ValueError(
|
|
92
|
+
"No API key: pass api_key or set SIGNUNDER_API_KEY. Get one at https://signunder.com/dashboard."
|
|
93
|
+
)
|
|
94
|
+
return key, (base_url or os.environ.get("SIGNUNDER_BASE_URL") or DEFAULT_BASE_URL).rstrip("/")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class Signunder:
|
|
98
|
+
"""Calls the SignUnder API. Reuse one client; close it, or use it as a context manager.
|
|
99
|
+
|
|
100
|
+
>>> from signunder import Signunder
|
|
101
|
+
>>> with Signunder() as client: # key from SIGNUNDER_API_KEY
|
|
102
|
+
... signed = client.sign("picture.png")
|
|
103
|
+
... signed.save("picture.signed.png")
|
|
104
|
+
"""
|
|
105
|
+
|
|
106
|
+
def __init__(
|
|
107
|
+
self,
|
|
108
|
+
api_key: str | None = None,
|
|
109
|
+
*,
|
|
110
|
+
base_url: str | None = None,
|
|
111
|
+
timeout: float = 90.0,
|
|
112
|
+
http_client: httpx.Client | None = None,
|
|
113
|
+
):
|
|
114
|
+
key, url = _settings(api_key, base_url)
|
|
115
|
+
self._owns_http = http_client is None
|
|
116
|
+
self._http = http_client or httpx.Client(timeout=timeout)
|
|
117
|
+
self._base = url
|
|
118
|
+
self._headers = {"Authorization": f"Bearer {key}", "User-Agent": "signunder-python/0.1.0"}
|
|
119
|
+
|
|
120
|
+
def sign(
|
|
121
|
+
self, image: Image, *, content_type: str | None = None, filename: str | None = None
|
|
122
|
+
) -> SignedAsset:
|
|
123
|
+
"""Signs an image with your company's key: Content Credentials, an invisible
|
|
124
|
+
watermark and a fingerprint on record. Returns the signed file and its record id."""
|
|
125
|
+
upload = _upload(image, content_type, filename)
|
|
126
|
+
response = self._send("POST", "/v1/sign", files={"file": upload})
|
|
127
|
+
return _signed(response, upload[2])
|
|
128
|
+
|
|
129
|
+
def verify(
|
|
130
|
+
self, image: Image, *, content_type: str | None = None, filename: str | None = None
|
|
131
|
+
) -> Verification:
|
|
132
|
+
"""Reads and validates the Content Credentials in any image. An image without
|
|
133
|
+
any is not an error: ``manifest_found`` is False."""
|
|
134
|
+
response = self._send(
|
|
135
|
+
"POST", "/v1/verify", files={"file": _upload(image, content_type, filename)}
|
|
136
|
+
)
|
|
137
|
+
_raise_unless_ok(response)
|
|
138
|
+
return Verification.from_json(response.json())
|
|
139
|
+
|
|
140
|
+
def get_record(self, record_id: str) -> Record | None:
|
|
141
|
+
"""One of your company's records, or None if you have none with that id."""
|
|
142
|
+
response = self._send("GET", f"/v1/records/{quote(record_id, safe='')}")
|
|
143
|
+
if response.status_code == 404:
|
|
144
|
+
return None
|
|
145
|
+
_raise_unless_ok(response)
|
|
146
|
+
return Record.from_json(response.json())
|
|
147
|
+
|
|
148
|
+
def _send(self, method: str, path: str, **kwargs: Any) -> httpx.Response:
|
|
149
|
+
try:
|
|
150
|
+
return self._http.request(method, self._base + path, headers=self._headers, **kwargs)
|
|
151
|
+
except httpx.HTTPError as error:
|
|
152
|
+
raise SignunderError(None, f"SignUnder could not be reached: {error}") from error
|
|
153
|
+
|
|
154
|
+
def close(self) -> None:
|
|
155
|
+
if self._owns_http:
|
|
156
|
+
self._http.close()
|
|
157
|
+
|
|
158
|
+
def __enter__(self) -> Self:
|
|
159
|
+
return self
|
|
160
|
+
|
|
161
|
+
def __exit__(self, *exc: object) -> None:
|
|
162
|
+
self.close()
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
class AsyncSignunder:
|
|
166
|
+
"""The same calls as :class:`Signunder`, for asyncio.
|
|
167
|
+
|
|
168
|
+
>>> async with AsyncSignunder() as client:
|
|
169
|
+
... signed = await client.sign(image_bytes)
|
|
170
|
+
"""
|
|
171
|
+
|
|
172
|
+
def __init__(
|
|
173
|
+
self,
|
|
174
|
+
api_key: str | None = None,
|
|
175
|
+
*,
|
|
176
|
+
base_url: str | None = None,
|
|
177
|
+
timeout: float = 90.0,
|
|
178
|
+
http_client: httpx.AsyncClient | None = None,
|
|
179
|
+
):
|
|
180
|
+
key, url = _settings(api_key, base_url)
|
|
181
|
+
self._owns_http = http_client is None
|
|
182
|
+
self._http = http_client or httpx.AsyncClient(timeout=timeout)
|
|
183
|
+
self._base = url
|
|
184
|
+
self._headers = {"Authorization": f"Bearer {key}", "User-Agent": "signunder-python/0.1.0"}
|
|
185
|
+
|
|
186
|
+
async def sign(
|
|
187
|
+
self, image: Image, *, content_type: str | None = None, filename: str | None = None
|
|
188
|
+
) -> SignedAsset:
|
|
189
|
+
upload = _upload(image, content_type, filename)
|
|
190
|
+
response = await self._send("POST", "/v1/sign", files={"file": upload})
|
|
191
|
+
return _signed(response, upload[2])
|
|
192
|
+
|
|
193
|
+
async def verify(
|
|
194
|
+
self, image: Image, *, content_type: str | None = None, filename: str | None = None
|
|
195
|
+
) -> Verification:
|
|
196
|
+
response = await self._send(
|
|
197
|
+
"POST", "/v1/verify", files={"file": _upload(image, content_type, filename)}
|
|
198
|
+
)
|
|
199
|
+
_raise_unless_ok(response)
|
|
200
|
+
return Verification.from_json(response.json())
|
|
201
|
+
|
|
202
|
+
async def get_record(self, record_id: str) -> Record | None:
|
|
203
|
+
response = await self._send("GET", f"/v1/records/{quote(record_id, safe='')}")
|
|
204
|
+
if response.status_code == 404:
|
|
205
|
+
return None
|
|
206
|
+
_raise_unless_ok(response)
|
|
207
|
+
return Record.from_json(response.json())
|
|
208
|
+
|
|
209
|
+
async def _send(self, method: str, path: str, **kwargs: Any) -> httpx.Response:
|
|
210
|
+
try:
|
|
211
|
+
return await self._http.request(
|
|
212
|
+
method, self._base + path, headers=self._headers, **kwargs
|
|
213
|
+
)
|
|
214
|
+
except httpx.HTTPError as error:
|
|
215
|
+
raise SignunderError(None, f"SignUnder could not be reached: {error}") from error
|
|
216
|
+
|
|
217
|
+
async def close(self) -> None:
|
|
218
|
+
if self._owns_http:
|
|
219
|
+
await self._http.aclose()
|
|
220
|
+
|
|
221
|
+
async def __aenter__(self) -> Self:
|
|
222
|
+
return self
|
|
223
|
+
|
|
224
|
+
async def __aexit__(self, *exc: object) -> None:
|
|
225
|
+
await self.close()
|
signunder/_models.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from collections.abc import Mapping
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from os import PathLike
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SignunderError(Exception):
|
|
13
|
+
"""The SignUnder API refused a request, or could not be reached."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, status_code: int | None, detail: str):
|
|
16
|
+
super().__init__(f"{status_code}: {detail}" if status_code else detail)
|
|
17
|
+
#: The HTTP status the API answered with; None if it was not reached.
|
|
18
|
+
self.status_code = status_code
|
|
19
|
+
#: The API's explanation.
|
|
20
|
+
self.detail = detail
|
|
21
|
+
match = re.search(r"Quote reference (\w+)", detail)
|
|
22
|
+
#: For a failure on SignUnder's side, the reference to quote to support.
|
|
23
|
+
self.reference: str | None = match.group(1) if match else None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _time(value: str | None) -> datetime | None:
|
|
27
|
+
"""An ISO 8601 time from the API. .NET writes one to seven fractional digits and
|
|
28
|
+
Python before 3.11 reads exactly three or six, so the fraction is made six."""
|
|
29
|
+
if not value:
|
|
30
|
+
return None
|
|
31
|
+
value = value.replace("Z", "+00:00")
|
|
32
|
+
value = re.sub(r"\.(\d+)", lambda m: "." + (m.group(1) + "000000")[:6], value, count=1)
|
|
33
|
+
return datetime.fromisoformat(value)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass(frozen=True)
|
|
37
|
+
class SignedAsset:
|
|
38
|
+
"""A signed image and the id of its registry record."""
|
|
39
|
+
|
|
40
|
+
#: The signed file. Serve these bytes unchanged: re-encoding breaks the signature.
|
|
41
|
+
content: bytes
|
|
42
|
+
#: The file's media type, the same as the upload's.
|
|
43
|
+
content_type: str
|
|
44
|
+
#: The registry record for this output (also how its verify page links to it).
|
|
45
|
+
record_id: str
|
|
46
|
+
#: SHA-256 of the C2PA manifest store, lower-case hex.
|
|
47
|
+
manifest_hash: str
|
|
48
|
+
|
|
49
|
+
def save(self, path: str | PathLike) -> Path:
|
|
50
|
+
"""Writes the signed file to ``path`` and returns it."""
|
|
51
|
+
target = Path(path)
|
|
52
|
+
target.write_bytes(self.content)
|
|
53
|
+
return target
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@dataclass(frozen=True)
|
|
57
|
+
class Verification:
|
|
58
|
+
"""What an image's Content Credentials say, and whether they still hold."""
|
|
59
|
+
|
|
60
|
+
#: False if the image carries no Content Credentials; the rest is then empty.
|
|
61
|
+
manifest_found: bool
|
|
62
|
+
#: ``invalid``, ``valid`` or ``trusted``.
|
|
63
|
+
validation_state: str | None = None
|
|
64
|
+
manifest_label: str | None = None
|
|
65
|
+
#: The organisation, or failing that the common name, on the signing certificate.
|
|
66
|
+
signed_by: str | None = None
|
|
67
|
+
cert_subject: dict[str, str] = field(default_factory=dict)
|
|
68
|
+
#: ``trusted`` if the certificate chains to the C2PA trust list, else ``untrusted``.
|
|
69
|
+
trust_status: str | None = None
|
|
70
|
+
#: The trusted timestamp on the signature, if it has one.
|
|
71
|
+
issued_at: datetime | None = None
|
|
72
|
+
#: The actions the manifest declares, for example ``c2pa.created``.
|
|
73
|
+
actions: list[str] = field(default_factory=list)
|
|
74
|
+
#: True if the image no longer matches what was signed.
|
|
75
|
+
altered: bool = False
|
|
76
|
+
#: C2PA validation failure codes.
|
|
77
|
+
failures: list[str] = field(default_factory=list)
|
|
78
|
+
#: The full crJSON validation report.
|
|
79
|
+
report: dict[str, Any] | None = None
|
|
80
|
+
|
|
81
|
+
@classmethod
|
|
82
|
+
def from_json(cls, body: Mapping[str, Any]) -> Verification:
|
|
83
|
+
if not body.get("manifest_found"):
|
|
84
|
+
return cls(manifest_found=False)
|
|
85
|
+
return cls(
|
|
86
|
+
manifest_found=True,
|
|
87
|
+
validation_state=body.get("validation_state"),
|
|
88
|
+
manifest_label=body.get("manifest_label"),
|
|
89
|
+
signed_by=body.get("signed_by"),
|
|
90
|
+
cert_subject=dict(body.get("cert_subject") or {}),
|
|
91
|
+
trust_status=body.get("trust_status"),
|
|
92
|
+
issued_at=_time(body.get("issued_at")),
|
|
93
|
+
actions=list(body.get("actions") or []),
|
|
94
|
+
altered=bool(body.get("altered")),
|
|
95
|
+
failures=list(body.get("failures") or []),
|
|
96
|
+
report=body.get("report"),
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@dataclass(frozen=True)
|
|
101
|
+
class Record:
|
|
102
|
+
"""The registry's record of one signed output. It holds hashes, never the media."""
|
|
103
|
+
|
|
104
|
+
id: str
|
|
105
|
+
created_at: datetime
|
|
106
|
+
#: For example ``image``.
|
|
107
|
+
modality: str
|
|
108
|
+
mime: str
|
|
109
|
+
size: int
|
|
110
|
+
#: SHA-256 of the signed file, lower-case hex.
|
|
111
|
+
bytes_sha256: str
|
|
112
|
+
#: SHA-256 of the C2PA manifest store, lower-case hex.
|
|
113
|
+
manifest_hash: str
|
|
114
|
+
manifest_label: str | None
|
|
115
|
+
#: The state the output validated to when it was signed.
|
|
116
|
+
validation_state: str
|
|
117
|
+
actions: list[str]
|
|
118
|
+
#: Which marks the output carries: ``manifest``, ``watermark``, ``fingerprint``.
|
|
119
|
+
layers: dict[str, bool]
|
|
120
|
+
#: The number in the output's invisible watermark, as 16 hex digits.
|
|
121
|
+
wm_payload: str | None = None
|
|
122
|
+
#: The output's PDQ perceptual hash, as 64 hex digits.
|
|
123
|
+
fingerprint: str | None = None
|
|
124
|
+
fingerprint_quality: int | None = None
|
|
125
|
+
#: Where the output came from in proxy mode, for example ``fal``.
|
|
126
|
+
provider: str | None = None
|
|
127
|
+
model_name: str | None = None
|
|
128
|
+
#: Where SignUnder serves its own copy (proxy mode), while it keeps one.
|
|
129
|
+
media_url: str | None = None
|
|
130
|
+
validation_report: dict[str, Any] | None = None
|
|
131
|
+
|
|
132
|
+
@classmethod
|
|
133
|
+
def from_json(cls, body: Mapping[str, Any]) -> Record:
|
|
134
|
+
created = _time(body["created_at"])
|
|
135
|
+
assert created is not None
|
|
136
|
+
return cls(
|
|
137
|
+
id=body["id"],
|
|
138
|
+
created_at=created,
|
|
139
|
+
modality=body["modality"],
|
|
140
|
+
mime=body["mime"],
|
|
141
|
+
size=int(body["size"]),
|
|
142
|
+
bytes_sha256=body["bytes_sha256"],
|
|
143
|
+
manifest_hash=body["manifest_hash"],
|
|
144
|
+
manifest_label=body.get("manifest_label"),
|
|
145
|
+
validation_state=body["validation_state"],
|
|
146
|
+
actions=list(body.get("actions") or []),
|
|
147
|
+
layers=dict(body.get("layers") or {}),
|
|
148
|
+
wm_payload=body.get("wm_payload"),
|
|
149
|
+
fingerprint=body.get("fingerprint"),
|
|
150
|
+
fingerprint_quality=body.get("fingerprint_quality"),
|
|
151
|
+
provider=body.get("provider"),
|
|
152
|
+
model_name=body.get("model_name"),
|
|
153
|
+
media_url=body.get("media_url"),
|
|
154
|
+
validation_report=body.get("validation_report"),
|
|
155
|
+
)
|
signunder/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: signunder
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python client for SignUnder: sign AI-generated images with Content Credentials, an invisible watermark and a fingerprint, and verify them.
|
|
5
|
+
Project-URL: Homepage, https://signunder.com
|
|
6
|
+
Project-URL: Documentation, https://signunder.com/docs
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: ai-act,c2pa,content-credentials,provenance,watermark
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Typing :: Typed
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Requires-Dist: httpx>=0.27
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# signunder
|
|
17
|
+
|
|
18
|
+
Python client for [SignUnder](https://signunder.com): sign the images your product generates under your own company's name, with C2PA Content Credentials, an invisible watermark and a fingerprint on record, and verify them later, even after a platform strips the metadata.
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
pip install signunder
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Get an API key at [signunder.com/dashboard](https://signunder.com/dashboard) and set it as `SIGNUNDER_API_KEY`.
|
|
25
|
+
|
|
26
|
+
## Sign
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from signunder import Signunder
|
|
30
|
+
|
|
31
|
+
with Signunder() as client: # reads SIGNUNDER_API_KEY
|
|
32
|
+
signed = client.sign("picture.png") # a path, bytes or an open file: JPEG, PNG or WebP
|
|
33
|
+
signed.save("picture.signed.png")
|
|
34
|
+
print(signed.record_id)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Serve the signed bytes unchanged: re-encoding the image breaks the signature, though the watermark and fingerprint still identify it on your public verify page, `https://signunder.com/verify?t=<your-company>&id=<record_id>`.
|
|
38
|
+
|
|
39
|
+
## Verify and look up
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
result = client.verify("downloaded.png")
|
|
43
|
+
if result.manifest_found:
|
|
44
|
+
print(result.signed_by, result.validation_state, "altered" if result.altered else "intact")
|
|
45
|
+
|
|
46
|
+
record = client.get_record(signed.record_id) # None if it is not one of yours
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Async
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from signunder import AsyncSignunder
|
|
53
|
+
|
|
54
|
+
async with AsyncSignunder() as client:
|
|
55
|
+
signed = await client.sign(image_bytes)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Errors
|
|
59
|
+
|
|
60
|
+
Every refusal raises `SignunderError` with the HTTP `status_code` and the API's `detail`. A failure on SignUnder's side carries a `reference` to quote to support. A month's allowance used up is a 429 whose detail says when it resets.
|
|
61
|
+
|
|
62
|
+
Early access runs on SignUnder's staging service and signs with a test certificate until your company is listed with the C2PA. Full API reference: [signunder.com/docs](https://signunder.com/docs).
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
signunder/__init__.py,sha256=5f6t3H2faCLGmEpWvaf0nKC7pSYyf8NRGpkIKimWS24,513
|
|
2
|
+
signunder/_client.py,sha256=ADfs1ZQErR7LEE_dQiapjLjieCdQwL_2MrUSneMgSRk,8289
|
|
3
|
+
signunder/_models.py,sha256=S7m7RbZO5XeIbqM40Xn0G0iQyuReJ9BLnGCEll1zs2I,6094
|
|
4
|
+
signunder/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
signunder-0.1.0.dist-info/METADATA,sha256=Kx2Oz7Zmc_wvVVkDbOMPAyBra2bm8YTiowzpg1lzA-Q,2383
|
|
6
|
+
signunder-0.1.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
7
|
+
signunder-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
8
|
+
signunder-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|