trufo 2.2.2__tar.gz → 2.3.0__tar.gz
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.
- {trufo-2.2.2 → trufo-2.3.0}/PKG-INFO +4 -4
- {trufo-2.2.2 → trufo-2.3.0}/pyproject.toml +4 -4
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/__init__.py +37 -15
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/loopback_auth.py +7 -5
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/tca/certs_c2pa.py +31 -21
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/tca/certs_cawg_interim.py +4 -3
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/tps/bind.py +45 -46
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/tps/io.py +6 -3
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/tps/records.py +5 -2
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/tps/sign_c2pa.py +105 -18
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/tps/tasks.py +31 -11
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/c2pa/__init__.py +9 -1
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/c2pa/watermark.py +30 -0
- trufo-2.3.0/src/trufo/crypt/kms.py +136 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/crypt/tca_certs.py +2 -1
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/intf/api_credentials.py +2 -2
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo.egg-info/PKG-INFO +4 -4
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo.egg-info/SOURCES.txt +1 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo.egg-info/requires.txt +3 -3
- {trufo-2.2.2 → trufo-2.3.0}/LICENSE +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/README.md +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/setup.cfg +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/__init__.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/auth.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/endpoints.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/headers.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/session.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/tca/__init__.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/tca/certs_test.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/tps/__init__.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/api/tps/recover.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/c2pa/actions.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/c2pa/ai_system.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/c2pa/assertions.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/c2pa/manifest.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/c2pa/redactions.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/c2pa/source_types.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/c2pa/thumbnails.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/crypt/__init__.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/crypt/algorithms.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/crypt/keygen.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/intf/__init__.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/intf/c2pa_certificates.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/intf/cli.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/py.typed +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/util/__init__.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/util/credentials.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/util/deprecation.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/util/optional_imports.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo/util/warnings.py +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo.egg-info/dependency_links.txt +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo.egg-info/entry_points.txt +0 -0
- {trufo-2.2.2 → trufo-2.3.0}/src/trufo.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: trufo
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3.0
|
|
4
4
|
Summary: Trufo SDK for content provenance API services.
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
Project-URL: Homepage, https://trufo.ai
|
|
@@ -15,11 +15,11 @@ Requires-Dist: PyJWT>=2.6
|
|
|
15
15
|
Requires-Dist: requests>=2.28
|
|
16
16
|
Requires-Dist: uuid-utils>=0.6
|
|
17
17
|
Provides-Extra: local-sign-only
|
|
18
|
-
Requires-Dist: trufo-provenance[c2pa]<2.
|
|
18
|
+
Requires-Dist: trufo-provenance[c2pa]<2.4.0,>=2.3.0; extra == "local-sign-only"
|
|
19
19
|
Provides-Extra: local-full
|
|
20
|
-
Requires-Dist: trufo-provenance[c2pa,pawprint]<2.
|
|
20
|
+
Requires-Dist: trufo-provenance[c2pa,pawprint]<2.4.0,>=2.3.0; extra == "local-full"
|
|
21
21
|
Provides-Extra: provenance
|
|
22
|
-
Requires-Dist: trufo-provenance[c2pa]<2.
|
|
22
|
+
Requires-Dist: trufo-provenance[c2pa]<2.4.0,>=2.3.0; extra == "provenance"
|
|
23
23
|
Provides-Extra: test
|
|
24
24
|
Requires-Dist: pytest>=7.0; extra == "test"
|
|
25
25
|
Dynamic: license-file
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "trufo"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.3.0"
|
|
8
8
|
requires-python = ">=3.10"
|
|
9
9
|
description = "Trufo SDK for content provenance API services."
|
|
10
10
|
readme = "README.md"
|
|
@@ -21,9 +21,9 @@ dependencies = [
|
|
|
21
21
|
# local-sign-only: distributed C2PA signing without the watermark engine
|
|
22
22
|
# (no torch); local-full adds trufo-pawprint for local watermark embedding.
|
|
23
23
|
# provenance is the legacy alias of local-sign-only.
|
|
24
|
-
local-sign-only = ["trufo-provenance[c2pa]>=2.
|
|
25
|
-
local-full = ["trufo-provenance[c2pa,pawprint]>=2.
|
|
26
|
-
provenance = ["trufo-provenance[c2pa]>=2.
|
|
24
|
+
local-sign-only = ["trufo-provenance[c2pa]>=2.3.0,<2.4.0"]
|
|
25
|
+
local-full = ["trufo-provenance[c2pa,pawprint]>=2.3.0,<2.4.0"]
|
|
26
|
+
provenance = ["trufo-provenance[c2pa]>=2.3.0,<2.4.0"]
|
|
27
27
|
test = ["pytest>=7.0"]
|
|
28
28
|
|
|
29
29
|
[project.urls]
|
|
@@ -10,49 +10,71 @@ from trufo.api.tca.certs_c2pa import (
|
|
|
10
10
|
from trufo.api.tca.certs_cawg_interim import request_cawg_interim_cert
|
|
11
11
|
from trufo.api.tca.certs_test import request_c2pa_dummy_cert, request_cawg_dummy_cert
|
|
12
12
|
from trufo.api.tps.bind import (
|
|
13
|
-
BindWatermarkResult,
|
|
14
13
|
BindReserveResult,
|
|
14
|
+
BindWatermarkResult,
|
|
15
15
|
bind_commit,
|
|
16
16
|
bind_commit_test,
|
|
17
17
|
bind_reserve,
|
|
18
18
|
bind_reserve_test,
|
|
19
19
|
bind_watermark,
|
|
20
20
|
bind_watermark_test,
|
|
21
|
-
watermark_media,
|
|
22
21
|
submit_bind_watermark,
|
|
22
|
+
watermark_media,
|
|
23
23
|
)
|
|
24
|
-
from trufo.api.tps.records import get_content, list_content, set_content_status
|
|
25
24
|
from trufo.api.tps.io import GetS3UploadURLResult, get_s3_upload_url
|
|
26
|
-
from trufo.api.tps.
|
|
27
|
-
ExecutionMode, TaskType, TaskStatus, TaskReceipt, TaskInfo,
|
|
28
|
-
SignC2PATaskResult, BindWatermarkTaskResult, TaskFailedError, TaskWaitTimeoutError,
|
|
29
|
-
get_task, wait_for_task,
|
|
30
|
-
)
|
|
25
|
+
from trufo.api.tps.records import get_content, list_content, set_content_status
|
|
31
26
|
from trufo.api.tps.recover import RecoverContentResult, recover_content
|
|
32
27
|
from trufo.api.tps.sign_c2pa import (
|
|
33
28
|
SignC2PAS3Result,
|
|
34
29
|
sign_c2pa,
|
|
35
30
|
sign_c2pa_distributed,
|
|
36
31
|
sign_c2pa_distributed_test,
|
|
32
|
+
sign_c2pa_s3,
|
|
37
33
|
sign_c2pa_test,
|
|
38
34
|
sign_c2pa_via_s3,
|
|
39
35
|
sign_c2pa_via_s3_test,
|
|
40
|
-
sign_c2pa_s3,
|
|
41
36
|
submit_c2pa_sign,
|
|
42
37
|
)
|
|
38
|
+
from trufo.api.tps.tasks import (
|
|
39
|
+
BindWatermarkTaskResult,
|
|
40
|
+
ExecutionMode,
|
|
41
|
+
SignC2PATaskResult,
|
|
42
|
+
TaskFailedError,
|
|
43
|
+
TaskInfo,
|
|
44
|
+
TaskReceipt,
|
|
45
|
+
TaskStatus,
|
|
46
|
+
TaskType,
|
|
47
|
+
TaskWaitTimeoutError,
|
|
48
|
+
get_task,
|
|
49
|
+
wait_for_task,
|
|
50
|
+
)
|
|
43
51
|
from trufo.crypt.keygen import generate_keypair
|
|
44
52
|
from trufo.util.credentials import load_api_key, save_api_key
|
|
45
53
|
from trufo.util.deprecation import deprecated_aliases
|
|
46
54
|
from trufo.util.warnings import TrufoServerWarning
|
|
47
55
|
|
|
48
|
-
__version__ = "2.
|
|
56
|
+
__version__ = "2.3.0"
|
|
49
57
|
|
|
50
58
|
__all__ = [
|
|
51
|
-
"ExecutionMode",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
59
|
+
"ExecutionMode",
|
|
60
|
+
"TaskType",
|
|
61
|
+
"TaskStatus",
|
|
62
|
+
"TaskReceipt",
|
|
63
|
+
"TaskInfo",
|
|
64
|
+
"SignC2PATaskResult",
|
|
65
|
+
"BindWatermarkTaskResult",
|
|
66
|
+
"TaskFailedError",
|
|
67
|
+
"TaskWaitTimeoutError",
|
|
68
|
+
"BindWatermarkResult",
|
|
69
|
+
"BindReserveResult",
|
|
70
|
+
"RecoverContentResult",
|
|
71
|
+
"GetS3UploadURLResult",
|
|
72
|
+
"SignC2PAS3Result",
|
|
73
|
+
"get_task",
|
|
74
|
+
"wait_for_task",
|
|
75
|
+
"submit_c2pa_sign",
|
|
76
|
+
"submit_bind_watermark",
|
|
77
|
+
"sign_c2pa_s3",
|
|
56
78
|
"__version__",
|
|
57
79
|
"bind_commit",
|
|
58
80
|
"bind_commit_test",
|
|
@@ -168,11 +168,13 @@ def run_loopback_login(
|
|
|
168
168
|
port = httpd.server_address[1]
|
|
169
169
|
redirect_uri = f"http://127.0.0.1:{port}/callback"
|
|
170
170
|
|
|
171
|
-
query = urlencode(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
query = urlencode(
|
|
172
|
+
{
|
|
173
|
+
"code_challenge": pkce.challenge,
|
|
174
|
+
"state": state,
|
|
175
|
+
"redirect_uri": redirect_uri,
|
|
176
|
+
}
|
|
177
|
+
)
|
|
176
178
|
authorize_url = f"{app_url}{LOOPBACK_AUTH_PATH}?{query}"
|
|
177
179
|
|
|
178
180
|
# webbrowser.open returns False when it cannot find a browser to launch,
|
|
@@ -10,7 +10,7 @@ from pathlib import Path
|
|
|
10
10
|
import jwt as pyjwt
|
|
11
11
|
import requests
|
|
12
12
|
from cryptography.hazmat.primitives import serialization
|
|
13
|
-
from cryptography.hazmat.primitives.asymmetric import ec
|
|
13
|
+
from cryptography.hazmat.primitives.asymmetric import ec, ed25519
|
|
14
14
|
|
|
15
15
|
from trufo.api.auth import extract_detail
|
|
16
16
|
from trufo.api.endpoints import (
|
|
@@ -22,8 +22,8 @@ from trufo.api.endpoints import (
|
|
|
22
22
|
TRUFO_CA_URL,
|
|
23
23
|
TRUFO_CA_URL_TEST,
|
|
24
24
|
)
|
|
25
|
-
from trufo.api.session import TrufoSession
|
|
26
25
|
from trufo.api.headers import sdk_headers
|
|
26
|
+
from trufo.api.session import TrufoSession
|
|
27
27
|
from trufo.crypt.algorithms import infer_signing_algorithm
|
|
28
28
|
from trufo.crypt.tca_certs import LeafType, build_csr, est_enroll, extract_cert_chain
|
|
29
29
|
|
|
@@ -99,7 +99,7 @@ def register_credential(
|
|
|
99
99
|
def _build_gpic_assertion(
|
|
100
100
|
gpi_id: str,
|
|
101
101
|
gpic_id: str,
|
|
102
|
-
|
|
102
|
+
instance_key: ec.EllipticCurvePrivateKey | ed25519.Ed25519PrivateKey,
|
|
103
103
|
algorithm: str,
|
|
104
104
|
) -> str:
|
|
105
105
|
"""Build a GPIC assertion JWT signed with the instance private key.
|
|
@@ -111,7 +111,7 @@ def _build_gpic_assertion(
|
|
|
111
111
|
Args:
|
|
112
112
|
gpi_id: Generator product instance ID (``"gpi_..."``)
|
|
113
113
|
gpic_id: Instance credential ID (``"gpic_..."``)
|
|
114
|
-
|
|
114
|
+
instance_key: Instance private key.
|
|
115
115
|
algorithm: JWA algorithm name (e.g. ``"ES256"``).
|
|
116
116
|
|
|
117
117
|
Returns:
|
|
@@ -125,7 +125,7 @@ def _build_gpic_assertion(
|
|
|
125
125
|
"iat": now,
|
|
126
126
|
"exp": now + 60,
|
|
127
127
|
}
|
|
128
|
-
return pyjwt.encode(payload,
|
|
128
|
+
return pyjwt.encode(payload, instance_key, algorithm=algorithm)
|
|
129
129
|
|
|
130
130
|
|
|
131
131
|
def _request_c2pa_csr_jwt(
|
|
@@ -176,7 +176,7 @@ def _request_c2pa_csr_jwt(
|
|
|
176
176
|
def request_c2pa_cert(
|
|
177
177
|
gpi_id: str,
|
|
178
178
|
gpic_id: str,
|
|
179
|
-
instance_key_pem: str,
|
|
179
|
+
instance_key_pem: str | bytes | ec.EllipticCurvePrivateKey,
|
|
180
180
|
private_key_signer: str | Path | bytes | ec.EllipticCurvePrivateKey,
|
|
181
181
|
leaf_type: LeafType = LeafType.C2PA_L1,
|
|
182
182
|
validity_days: int | None = None,
|
|
@@ -192,11 +192,15 @@ def request_c2pa_cert(
|
|
|
192
192
|
Args:
|
|
193
193
|
gpi_id: Instance ID (e.g. ``"gpi_..."``)
|
|
194
194
|
gpic_id: Credential ID (e.g. ``"gpic_..."``)
|
|
195
|
-
instance_key_pem: Instance private key PEM (
|
|
196
|
-
|
|
195
|
+
instance_key_pem: Instance private key — PEM (``str`` or
|
|
196
|
+
``bytes``) or an ``ec.EllipticCurvePrivateKey`` (e.g.
|
|
197
|
+
``trufo.crypt.kms.AWSKMSPrivateKey`` or
|
|
198
|
+
``GCPKMSPrivateKey``); signs the GPIC assertion.
|
|
197
199
|
private_key_signer: Leaf private key — PEM ``bytes``, a
|
|
198
200
|
filesystem path (``str`` / ``Path``), or an
|
|
199
|
-
``ec.EllipticCurvePrivateKey`` (e.g.
|
|
201
|
+
``ec.EllipticCurvePrivateKey`` (e.g.
|
|
202
|
+
``trufo.crypt.kms.AWSKMSPrivateKey`` or
|
|
203
|
+
``GCPKMSPrivateKey``).
|
|
200
204
|
leaf_type: Certificate type (default: ``C2PA_L1``).
|
|
201
205
|
validity_days: Requested validity in days. ``None`` lets the
|
|
202
206
|
server decide.
|
|
@@ -207,18 +211,20 @@ def request_c2pa_cert(
|
|
|
207
211
|
PEM bytes for the certificate chain (leaf + intermediates,
|
|
208
212
|
self-signed root excluded).
|
|
209
213
|
"""
|
|
210
|
-
# 1.
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
+
# 1. load the instance key, infer its algorithm for JWT signing
|
|
215
|
+
instance_key = instance_key_pem
|
|
216
|
+
if isinstance(instance_key, str):
|
|
217
|
+
instance_key = instance_key.encode()
|
|
218
|
+
if isinstance(instance_key, bytes):
|
|
219
|
+
instance_key = serialization.load_pem_private_key(instance_key, password=None)
|
|
214
220
|
instance_alg = infer_signing_algorithm(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
221
|
+
instance_key.public_key().public_bytes(
|
|
222
|
+
serialization.Encoding.PEM, serialization.PublicFormat.SubjectPublicKeyInfo
|
|
223
|
+
)
|
|
218
224
|
)
|
|
219
225
|
|
|
220
226
|
# 2. build GPIC assertion, request CSR JWT
|
|
221
|
-
assertion = _build_gpic_assertion(gpi_id, gpic_id,
|
|
227
|
+
assertion = _build_gpic_assertion(gpi_id, gpic_id, instance_key, instance_alg.alg_name)
|
|
222
228
|
csr_jwt = _request_c2pa_csr_jwt(
|
|
223
229
|
assertion, leaf_type, validity_days, trufo_api_url=trufo_api_url
|
|
224
230
|
)
|
|
@@ -237,7 +243,7 @@ def request_c2pa_cert(
|
|
|
237
243
|
def request_c2pa_cert_test(
|
|
238
244
|
gpi_id: str,
|
|
239
245
|
gpic_id: str,
|
|
240
|
-
instance_key_pem: str,
|
|
246
|
+
instance_key_pem: str | bytes | ec.EllipticCurvePrivateKey,
|
|
241
247
|
private_key_signer: str | Path | bytes | ec.EllipticCurvePrivateKey,
|
|
242
248
|
validity_days: int | None = None,
|
|
243
249
|
*,
|
|
@@ -254,11 +260,15 @@ def request_c2pa_cert_test(
|
|
|
254
260
|
Args:
|
|
255
261
|
gpi_id: Instance ID (e.g. ``"gpi_..."``)
|
|
256
262
|
gpic_id: Credential ID (e.g. ``"gpic_..."``)
|
|
257
|
-
instance_key_pem: Instance private key PEM (
|
|
258
|
-
|
|
263
|
+
instance_key_pem: Instance private key — PEM (``str`` or
|
|
264
|
+
``bytes``) or an ``ec.EllipticCurvePrivateKey`` (e.g.
|
|
265
|
+
``trufo.crypt.kms.AWSKMSPrivateKey`` or
|
|
266
|
+
``GCPKMSPrivateKey``); signs the GPIC assertion.
|
|
259
267
|
private_key_signer: Leaf private key — PEM ``bytes``, a
|
|
260
268
|
filesystem path (``str`` / ``Path``), or an
|
|
261
|
-
``ec.EllipticCurvePrivateKey`` (e.g.
|
|
269
|
+
``ec.EllipticCurvePrivateKey`` (e.g.
|
|
270
|
+
``trufo.crypt.kms.AWSKMSPrivateKey`` or
|
|
271
|
+
``GCPKMSPrivateKey``).
|
|
262
272
|
validity_days: Requested validity in days. ``None`` lets the
|
|
263
273
|
server decide.
|
|
264
274
|
trufo_api_url: Trufo API base URL. Defaults to the Trufo test host (test.api.trufo.ai).
|
|
@@ -66,9 +66,10 @@ def request_cawg_interim_cert(
|
|
|
66
66
|
client: Authenticated TrufoSession (Bearer JWT).
|
|
67
67
|
private_key_signer: Leaf private key — PEM ``bytes``, a
|
|
68
68
|
filesystem path (``str``/``Path``), or an
|
|
69
|
-
``ec.EllipticCurvePrivateKey`` (e.g.
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
``ec.EllipticCurvePrivateKey`` (e.g.
|
|
70
|
+
``trufo.crypt.kms.AWSKMSPrivateKey`` or
|
|
71
|
+
``GCPKMSPrivateKey``). The CA enforces the allowed key
|
|
72
|
+
algorithms (currently EC P-256 / P-384).
|
|
72
73
|
validity_days: Requested validity in days. Must be in
|
|
73
74
|
``[1, 366]``. ``None`` lets the server use its default
|
|
74
75
|
(366).
|
|
@@ -9,8 +9,7 @@ media with your own certificate, then complete the record with
|
|
|
9
9
|
the mark with a ``c2pa.soft-binding`` assertion (algorithm
|
|
10
10
|
``ai.trufo.pawprint.watermark``, block value = the watermark ID) paired with a
|
|
11
11
|
``c2pa.watermarked.bound`` action, per the C2PA specification. Trufo hosts the
|
|
12
|
-
manifest for soft-binding resolution
|
|
13
|
-
with ``manifest_endpoint``.
|
|
12
|
+
manifest for soft-binding resolution.
|
|
14
13
|
|
|
15
14
|
Two routes share the commit step:
|
|
16
15
|
|
|
@@ -25,7 +24,8 @@ Two routes share the commit step:
|
|
|
25
24
|
A per-AI-system bind (``wid_allocation_mode="per_ai_system"`` with
|
|
26
25
|
``ai_system_id`` and ``ai_involvement``) embeds your AI system's watermark ID
|
|
27
26
|
for that AI involvement instead of a new one. It is not a C2PA soft binding,
|
|
28
|
-
and
|
|
27
|
+
and its commit is optional but recommended. Declare it with a
|
|
28
|
+
``c2pa.watermarked.unbound`` action.
|
|
29
29
|
|
|
30
30
|
Production requires a ``watermark-prod`` key, an active C2PA Signing or
|
|
31
31
|
Watermark API plan, and completed organization validation; the ``_test``
|
|
@@ -49,9 +49,15 @@ from trufo.api.endpoints import (
|
|
|
49
49
|
)
|
|
50
50
|
from trufo.api.headers import sdk_headers
|
|
51
51
|
from trufo.api.tps.io import _upload_task_input
|
|
52
|
-
from trufo.api.tps.tasks import
|
|
52
|
+
from trufo.api.tps.tasks import (
|
|
53
|
+
ExecutionMode,
|
|
54
|
+
TaskReceipt,
|
|
55
|
+
_download_task_output,
|
|
56
|
+
_submit_task,
|
|
57
|
+
wait_for_task,
|
|
58
|
+
)
|
|
53
59
|
from trufo.c2pa.ai_system import AIInvolvement
|
|
54
|
-
from trufo.c2pa.watermark import WatermarkIDAllocationMode, WatermarkMode
|
|
60
|
+
from trufo.c2pa.watermark import WatermarkIDAllocationMode, WatermarkMode, WatermarkSettings
|
|
55
61
|
from trufo.util.deprecation import deprecated_aliases
|
|
56
62
|
from trufo.util.warnings import emit_server_warnings
|
|
57
63
|
|
|
@@ -70,8 +76,7 @@ _C2PA_HINT = (
|
|
|
70
76
|
class BindWatermarkResult:
|
|
71
77
|
"""Result of :func:`bind_watermark`.
|
|
72
78
|
|
|
73
|
-
``cid`` addresses the record for the commit step
|
|
74
|
-
nothing to commit.
|
|
79
|
+
``cid`` addresses the record for the commit step.
|
|
75
80
|
"""
|
|
76
81
|
|
|
77
82
|
media: bytes
|
|
@@ -193,7 +198,9 @@ def bind_watermark(
|
|
|
193
198
|
mode=mode,
|
|
194
199
|
trufo_api_url=trufo_api_url,
|
|
195
200
|
)
|
|
196
|
-
task = wait_for_task(
|
|
201
|
+
task = wait_for_task(
|
|
202
|
+
api_key, receipt.task_id, wait_seconds=wait_seconds, trufo_api_url=trufo_api_url
|
|
203
|
+
)
|
|
197
204
|
return BindWatermarkResult(_download_task_output(task), task.result.wid, task.result.cid)
|
|
198
205
|
body: dict = {
|
|
199
206
|
"media_input": base64.b64encode(media_bytes).decode(),
|
|
@@ -275,30 +282,45 @@ def bind_reserve(
|
|
|
275
282
|
payload = _post(api_key, trufo_api_url + TPS_BIND_RESERVE_PATH, body)
|
|
276
283
|
package = payload["wid_package"]
|
|
277
284
|
return BindReserveResult(
|
|
278
|
-
cid=payload["cid"],
|
|
285
|
+
cid=payload["cid"],
|
|
286
|
+
wid=package["wid"],
|
|
287
|
+
expires_at=package["expires_at"],
|
|
288
|
+
wid_package=dict(package),
|
|
279
289
|
)
|
|
280
290
|
|
|
281
291
|
|
|
282
|
-
def watermark_media(
|
|
292
|
+
def watermark_media(
|
|
293
|
+
media_bytes: bytes,
|
|
294
|
+
wid_package: dict,
|
|
295
|
+
*,
|
|
296
|
+
watermark_settings: WatermarkSettings | None = None,
|
|
297
|
+
) -> bytes:
|
|
283
298
|
"""lpls step 2: embed a reserved watermark ID with the local Trufo engine.
|
|
284
299
|
|
|
285
300
|
Args:
|
|
286
301
|
media_bytes: Raw bytes of the media file to watermark.
|
|
287
302
|
wid_package: ``BindReserveResult.wid_package`` (or the ``wid_package``
|
|
288
303
|
of a Trufo API response).
|
|
304
|
+
watermark_settings: Optional local embedding profile.
|
|
289
305
|
|
|
290
306
|
Returns:
|
|
291
307
|
The watermarked media bytes, in the input's format.
|
|
292
308
|
|
|
293
309
|
Raises:
|
|
294
310
|
ImportError: If the engine (``trufo[local-full]``) is not installed.
|
|
311
|
+
TypeError: If watermark_settings is not WatermarkSettings or None.
|
|
295
312
|
"""
|
|
313
|
+
if watermark_settings is not None and not isinstance(watermark_settings, WatermarkSettings):
|
|
314
|
+
raise TypeError("watermark_settings must be WatermarkSettings or None.")
|
|
296
315
|
try:
|
|
297
316
|
from tfprov.util import pawprint_import
|
|
298
317
|
except ImportError as exc:
|
|
299
318
|
raise ImportError(_ENGINE_HINT) from exc
|
|
319
|
+
options = {}
|
|
320
|
+
if watermark_settings is not None:
|
|
321
|
+
options = {"mode": watermark_settings.profile.value}
|
|
300
322
|
package = pawprint_import.WatermarkIdPackage(**wid_package)
|
|
301
|
-
return pawprint_import.embed(media_bytes, package)
|
|
323
|
+
return pawprint_import.embed(media_bytes, package, **options)
|
|
302
324
|
|
|
303
325
|
|
|
304
326
|
def _manifest_store_from_media(signed_media_bytes: bytes) -> bytes:
|
|
@@ -323,21 +345,17 @@ def bind_commit(
|
|
|
323
345
|
wid: str,
|
|
324
346
|
*,
|
|
325
347
|
manifest_bytes: bytes | None = None,
|
|
326
|
-
manifest_id: str | None = None,
|
|
327
|
-
manifest_endpoint: str | None = None,
|
|
328
348
|
signed_media_bytes: bytes | None = None,
|
|
329
349
|
trufo_api_url: str = TRUFO_API_URL,
|
|
330
350
|
) -> None:
|
|
331
351
|
"""Complete a bind record with your signed C2PA manifest.
|
|
332
352
|
|
|
333
|
-
Give exactly one manifest source: ``manifest_bytes`` (the serialized
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
module docstring); the API returns 400 and leaves the record incomplete
|
|
340
|
-
otherwise.
|
|
353
|
+
Give exactly one manifest source: ``manifest_bytes`` (the serialized C2PA
|
|
354
|
+
manifest store) or ``signed_media_bytes`` (the signed media; the store is
|
|
355
|
+
read out locally, which needs ``trufo[local-sign-only]``). The manifest
|
|
356
|
+
should declare the mark issued with the record (see the module docstring);
|
|
357
|
+
otherwise the API still commits it and emits a
|
|
358
|
+
:class:`~trufo.util.warnings.TrufoServerWarning`.
|
|
341
359
|
|
|
342
360
|
Args:
|
|
343
361
|
api_key: API key with scope ``watermark-prod`` (``watermark-test`` on
|
|
@@ -345,38 +363,23 @@ def bind_commit(
|
|
|
345
363
|
cid: Record ID from :func:`bind_watermark` or :func:`bind_reserve`.
|
|
346
364
|
wid: Watermark ID issued with that record.
|
|
347
365
|
manifest_bytes: Raw bytes of the C2PA manifest store.
|
|
348
|
-
manifest_id: The manifest's id (its urn); requires ``manifest_endpoint``.
|
|
349
|
-
manifest_endpoint: Base URI of your own C2PA manifest store
|
|
350
|
-
(``https://…``; the manifest must be reachable at
|
|
351
|
-
``{manifest_endpoint}/manifests/{manifestId}``). Omit to have
|
|
352
|
-
Trufo host the manifest.
|
|
353
366
|
signed_media_bytes: Raw bytes of the C2PA-signed watermarked media.
|
|
354
367
|
trufo_api_url: Trufo API base URL. Defaults to production.
|
|
355
368
|
|
|
356
369
|
Raises:
|
|
357
|
-
ValueError: If not exactly one manifest source is given
|
|
358
|
-
``manifest_id`` comes without ``manifest_endpoint``.
|
|
370
|
+
ValueError: If not exactly one manifest source is given.
|
|
359
371
|
ImportError: If ``signed_media_bytes`` is given without the local
|
|
360
372
|
C2PA library.
|
|
361
373
|
requests.HTTPError: If the API returns a non-2xx response.
|
|
362
374
|
"""
|
|
363
|
-
sources = [s for s in (manifest_bytes,
|
|
375
|
+
sources = [s for s in (manifest_bytes, signed_media_bytes) if s is not None]
|
|
364
376
|
if len(sources) != 1:
|
|
365
|
-
raise ValueError(
|
|
366
|
-
"Provide exactly one of manifest_bytes, manifest_id, or signed_media_bytes."
|
|
367
|
-
)
|
|
368
|
-
if manifest_id is not None and manifest_endpoint is None:
|
|
369
|
-
raise ValueError("manifest_id requires manifest_endpoint.")
|
|
377
|
+
raise ValueError("Provide exactly one of manifest_bytes or signed_media_bytes.")
|
|
370
378
|
if signed_media_bytes is not None:
|
|
371
379
|
manifest_bytes = _manifest_store_from_media(signed_media_bytes)
|
|
372
|
-
body
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
else:
|
|
376
|
-
body["manifest_id"] = manifest_id
|
|
377
|
-
if manifest_endpoint is not None:
|
|
378
|
-
body["manifest_endpoint"] = manifest_endpoint
|
|
379
|
-
_post(api_key, trufo_api_url + TPS_BIND_COMMIT_PATH, body)
|
|
380
|
+
body = {"cid": cid, "wid": wid, "manifest": base64.b64encode(manifest_bytes).decode()}
|
|
381
|
+
payload = _post(api_key, trufo_api_url + TPS_BIND_COMMIT_PATH, body)
|
|
382
|
+
emit_server_warnings(payload)
|
|
380
383
|
|
|
381
384
|
|
|
382
385
|
def bind_watermark_test(
|
|
@@ -429,8 +432,6 @@ def bind_commit_test(
|
|
|
429
432
|
wid: str,
|
|
430
433
|
*,
|
|
431
434
|
manifest_bytes: bytes | None = None,
|
|
432
|
-
manifest_id: str | None = None,
|
|
433
|
-
manifest_endpoint: str | None = None,
|
|
434
435
|
signed_media_bytes: bytes | None = None,
|
|
435
436
|
trufo_api_url: str = TRUFO_API_URL_TEST,
|
|
436
437
|
) -> None:
|
|
@@ -440,8 +441,6 @@ def bind_commit_test(
|
|
|
440
441
|
cid,
|
|
441
442
|
wid,
|
|
442
443
|
manifest_bytes=manifest_bytes,
|
|
443
|
-
manifest_id=manifest_id,
|
|
444
|
-
manifest_endpoint=manifest_endpoint,
|
|
445
444
|
signed_media_bytes=signed_media_bytes,
|
|
446
445
|
trufo_api_url=trufo_api_url,
|
|
447
446
|
)
|
|
@@ -54,13 +54,16 @@ def get_s3_upload_url(
|
|
|
54
54
|
)
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
def _upload_task_input(
|
|
57
|
+
def _upload_task_input(
|
|
58
|
+
api_key: str, media_bytes: bytes, mime_type: str | None, *, trufo_api_url: str
|
|
59
|
+
) -> str:
|
|
58
60
|
"""Upload once; content classification and eligibility remain server-side."""
|
|
59
61
|
if not mime_type:
|
|
60
62
|
raise ValueError("Provide mime_type when uploading bytes for TASK execution.")
|
|
61
63
|
upload = get_s3_upload_url(api_key, mime_type, trufo_api_url=trufo_api_url)
|
|
62
|
-
response = requests.put(
|
|
63
|
-
|
|
64
|
+
response = requests.put(
|
|
65
|
+
upload.upload_url, data=media_bytes, headers={"Content-Type": mime_type}, timeout=120
|
|
66
|
+
)
|
|
64
67
|
response.raise_for_status()
|
|
65
68
|
return upload.media_input_s3
|
|
66
69
|
|
|
@@ -137,8 +137,11 @@ def list_content(
|
|
|
137
137
|
"""
|
|
138
138
|
body: dict = {"limit": limit}
|
|
139
139
|
for name, value in (
|
|
140
|
-
("status", status),
|
|
141
|
-
("
|
|
140
|
+
("status", status),
|
|
141
|
+
("origin", origin),
|
|
142
|
+
("created_after", created_after),
|
|
143
|
+
("created_before", created_before),
|
|
144
|
+
("cursor", cursor),
|
|
142
145
|
):
|
|
143
146
|
if value is not None:
|
|
144
147
|
body[name] = value
|