trooth 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.
- trooth/__init__.py +14 -0
- trooth/integrations/__init__.py +16 -0
- trooth/integrations/langchain.py +33 -0
- trooth/integrations/llama_index.py +34 -0
- trooth/integrations/openai_agents.py +44 -0
- trooth-0.1.0.dist-info/METADATA +88 -0
- trooth-0.1.0.dist-info/RECORD +20 -0
- trooth-0.1.0.dist-info/WHEEL +5 -0
- trooth-0.1.0.dist-info/entry_points.txt +2 -0
- trooth-0.1.0.dist-info/licenses/LICENSE +70 -0
- trooth-0.1.0.dist-info/top_level.txt +2 -0
- trooth_semanto_verify/__init__.py +94 -0
- trooth_semanto_verify/__main__.py +8 -0
- trooth_semanto_verify/canonical.py +88 -0
- trooth_semanto_verify/cli.py +246 -0
- trooth_semanto_verify/client.py +127 -0
- trooth_semanto_verify/httpsig.py +217 -0
- trooth_semanto_verify/jws.py +255 -0
- trooth_semanto_verify/merkle.py +110 -0
- trooth_semanto_verify/verify.py +541 -0
trooth/__init__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright (c) 2026 Trooth, LLC
|
|
3
|
+
"""Trooth for Python: read a company's Semanto signed copy and check it.
|
|
4
|
+
|
|
5
|
+
from trooth import SemantoClient
|
|
6
|
+
r = SemantoClient().read("https://acme.com/pricing")
|
|
7
|
+
|
|
8
|
+
The checks themselves live in trooth_semanto_verify (the same functions and reason codes as the JavaScript and Go
|
|
9
|
+
kits). Framework integrations are optional extras: trooth[langchain], trooth[llama-index], trooth[openai-agents].
|
|
10
|
+
"""
|
|
11
|
+
from trooth_semanto_verify.client import SemantoClient
|
|
12
|
+
|
|
13
|
+
__version__ = "0.1.0"
|
|
14
|
+
__all__ = ["SemantoClient", "__version__"]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright (c) 2026 Trooth, LLC
|
|
3
|
+
"""Framework integrations, each behind its own extra so the base install pulls in no framework."""
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def metadata_of(url: str, r: dict) -> dict:
|
|
7
|
+
"""The Semanto fields every integration puts beside the text."""
|
|
8
|
+
return {
|
|
9
|
+
"source": url,
|
|
10
|
+
"semanto_ok": bool(r["ok"]),
|
|
11
|
+
"semanto_reason": r.get("reason"),
|
|
12
|
+
"semanto_version": r.get("version"),
|
|
13
|
+
"semanto_signed_by": r.get("signed_by"),
|
|
14
|
+
"semanto_keyid": r.get("keyid"),
|
|
15
|
+
"semanto_dns": r.get("dns"),
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright (c) 2026 Trooth, LLC
|
|
3
|
+
"""LangChain document loader (pip install "trooth[langchain]")."""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from typing import Any, Iterator, List, Optional, Sequence
|
|
7
|
+
|
|
8
|
+
from langchain_core.document_loaders import BaseLoader
|
|
9
|
+
from langchain_core.documents import Document
|
|
10
|
+
from trooth_semanto_verify.client import SemantoClient
|
|
11
|
+
|
|
12
|
+
from . import metadata_of
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SemantoLoader(BaseLoader):
|
|
16
|
+
"""Load pages as markdown from a company's domain, each checked against its signature."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, urls: Sequence[str], client: Optional[Any] = None, only_signed: bool = False):
|
|
19
|
+
self.urls = list(urls)
|
|
20
|
+
self.client = client or SemantoClient()
|
|
21
|
+
self.only_signed = only_signed
|
|
22
|
+
self.skipped: List[dict] = []
|
|
23
|
+
|
|
24
|
+
def lazy_load(self) -> Iterator[Document]:
|
|
25
|
+
for url in self.urls:
|
|
26
|
+
r = self.client.read(url)
|
|
27
|
+
if self.only_signed and not r["ok"]:
|
|
28
|
+
self.skipped.append({"url": url, "reason": r.get("reason")})
|
|
29
|
+
continue
|
|
30
|
+
yield Document(page_content=r["text"], metadata=metadata_of(url, r))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
__all__ = ["SemantoLoader"]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright (c) 2026 Trooth, LLC
|
|
3
|
+
"""LlamaIndex reader (pip install "trooth[llama-index]")."""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from typing import Any, List, Optional
|
|
7
|
+
|
|
8
|
+
from llama_index.core.readers.base import BaseReader
|
|
9
|
+
from llama_index.core.schema import Document
|
|
10
|
+
from trooth_semanto_verify.client import SemantoClient
|
|
11
|
+
|
|
12
|
+
from . import metadata_of
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SemantoReader(BaseReader):
|
|
16
|
+
"""Read pages as markdown from a company's domain, each checked against its signature."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, client: Optional[Any] = None, only_signed: bool = False):
|
|
19
|
+
self.client = client or SemantoClient()
|
|
20
|
+
self.only_signed = only_signed
|
|
21
|
+
self.skipped: List[dict] = []
|
|
22
|
+
|
|
23
|
+
def load_data(self, urls: List[str]) -> List[Document]: # type: ignore[override]
|
|
24
|
+
out: List[Document] = []
|
|
25
|
+
for url in urls:
|
|
26
|
+
r = self.client.read(url)
|
|
27
|
+
if self.only_signed and not r["ok"]:
|
|
28
|
+
self.skipped.append({"url": url, "reason": r.get("reason")})
|
|
29
|
+
continue
|
|
30
|
+
out.append(Document(text=r["text"], metadata=metadata_of(url, r)))
|
|
31
|
+
return out
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
__all__ = ["SemantoReader"]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright (c) 2026 Trooth, LLC
|
|
3
|
+
"""A function tool for the OpenAI Agents SDK (pip install "trooth[openai-agents]")."""
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
from typing import Any, Optional
|
|
8
|
+
|
|
9
|
+
from agents import FunctionTool, function_tool
|
|
10
|
+
from trooth_semanto_verify.client import SemantoClient
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def read_as_json(client: Any, url: str, max_chars: int = 20_000) -> str:
|
|
14
|
+
"""The tool's answer: whether the copy checked out, and the text, as one JSON string."""
|
|
15
|
+
r = client.read(url)
|
|
16
|
+
text = r["text"]
|
|
17
|
+
return json.dumps({
|
|
18
|
+
"url": url,
|
|
19
|
+
"ok": bool(r["ok"]),
|
|
20
|
+
"reason": r.get("reason"),
|
|
21
|
+
"version": r.get("version"),
|
|
22
|
+
"signed_by": r.get("signed_by") or ("company" if r.get("keyid") else None),
|
|
23
|
+
"dns": r.get("dns"),
|
|
24
|
+
"text": text[:max_chars],
|
|
25
|
+
"cut": len(text) > max_chars,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def semanto_read_tool(client: Optional[Any] = None, max_chars: int = 20_000) -> FunctionTool:
|
|
30
|
+
c = client or SemantoClient()
|
|
31
|
+
|
|
32
|
+
@function_tool(name_override="semanto_read")
|
|
33
|
+
def semanto_read(url: str) -> str:
|
|
34
|
+
"""Read a page from a company's website as its signed Semanto copy, and say whether the signature checked out.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
url: The page's address on the company's own domain, for example https://acme.com/pricing.
|
|
38
|
+
"""
|
|
39
|
+
return read_as_json(c, url, max_chars)
|
|
40
|
+
|
|
41
|
+
return semanto_read
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
__all__ = ["semanto_read_tool", "read_as_json"]
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: trooth
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Read a company's Semanto signed copy and check it: signatures, keys, DNS binding, page proofs and the public log.
|
|
5
|
+
Author: Trooth, LLC
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://trooth.co/docs/semanto
|
|
8
|
+
Project-URL: Documentation, https://trooth.co/docs/semanto
|
|
9
|
+
Project-URL: Source, https://github.com/troothllc/trooth-semanto-worker/tree/main/verifier/python
|
|
10
|
+
Project-URL: Issues, https://github.com/troothllc/trooth-semanto-worker/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/troothllc/trooth-semanto-worker/releases
|
|
12
|
+
Keywords: semanto,trooth,signatures,rfc9421,web-bot-auth,transparency-log,ai-agents
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Topic :: Security :: Cryptography
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: cryptography>=41
|
|
23
|
+
Provides-Extra: langchain
|
|
24
|
+
Requires-Dist: langchain-core>=0.3; extra == "langchain"
|
|
25
|
+
Provides-Extra: llama-index
|
|
26
|
+
Requires-Dist: llama-index-core>=0.12; extra == "llama-index"
|
|
27
|
+
Provides-Extra: openai-agents
|
|
28
|
+
Requires-Dist: openai-agents>=0.2; extra == "openai-agents"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
<!-- SPDX-License-Identifier: Apache-2.0 -->
|
|
32
|
+
<!-- Copyright (c) 2026 Trooth, LLC -->
|
|
33
|
+
|
|
34
|
+
# trooth (Python)
|
|
35
|
+
|
|
36
|
+
Read a company's Semanto signed copy and check it: the file, a page proof, a signed response or the public log, offline. Standard library plus `cryptography` (for Ed25519). Python 3.11 or newer.
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
pip install trooth # the checks, SemantoClient and the semanto-verify command
|
|
40
|
+
pip install "trooth[langchain]" # plus trooth.integrations.langchain.SemantoLoader
|
|
41
|
+
pip install "trooth[llama-index]" # plus trooth.integrations.llama_index.SemantoReader
|
|
42
|
+
pip install "trooth[openai-agents]" # plus trooth.integrations.openai_agents.semanto_read_tool
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Every release is built and published by GitHub Actions through PyPI Trusted Publishing, with no stored token, and carries PEP 740 attestations that tie each file to the workflow run that built it.
|
|
46
|
+
|
|
47
|
+
Without installing: `PYTHONPATH=verifier/python python3 -m trooth_semanto_verify file verifier/test-vectors/v1/semanto.json --pages verifier/test-vectors/v1/pages`
|
|
48
|
+
|
|
49
|
+
## Commands
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
semanto-verify file <semanto.json> [--pages <dir>] [--keys <keys.json>] [--now <iso>] [--revocations <file>]
|
|
53
|
+
semanto-verify page <url> [--trooth <base>] [--now <iso>]
|
|
54
|
+
semanto-verify response <url> [--keys <keys.json>]
|
|
55
|
+
semanto-verify log --from <n> --to <m> [--log <url>] [--keys <keys.json>]
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`file` needs no network when `--keys` is given or a `keys.json` sits beside the file. Pages are read from `<dir>/<page id>.md`. Exit code 0 means every check passed; 1 means at least one failed.
|
|
59
|
+
|
|
60
|
+
## Library
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import json, trooth_semanto_verify as V
|
|
64
|
+
|
|
65
|
+
file = json.load(open("semanto.json"))
|
|
66
|
+
keys = [json.load(open("acme-keys.json")), json.load(open("trooth-keys.json"))]
|
|
67
|
+
result = V.verify_semanto(file, {"https://acme.com/security": open("security.md", "rb").read()}, keys)
|
|
68
|
+
for check in result["checks"]:
|
|
69
|
+
print("ok " if check["ok"] else "FAIL", check["name"], check["detail"])
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The functions and the reason codes are the same as the JavaScript and Go kits: `verify_semanto`, `verify_page_proof`, `verify_response`, `verify_web_bot_auth_request`, `verify_tree_head`, `verify_inclusion_in_log`, `verify_consistency`, `verify_checkpoint`, `verify_offer`, `verify_revocation_list`, `state_of`, plus `canonicalize` (RFC 8785), the RFC 6962 primitives and `verify_jws`.
|
|
73
|
+
|
|
74
|
+
Canonical JSON here supports integers exactly. A non-integer float raises `CanonicalizeError` with a message saying to use minor units or a string, because Semanto never signs one.
|
|
75
|
+
|
|
76
|
+
## Tests
|
|
77
|
+
|
|
78
|
+
`python3 -m pytest` runs every shared vector in `verifier/test-vectors/v1` (positive and negative), the RFC 6962 known roots, the RFC 8785 cases, the state rules and the command line.
|
|
79
|
+
|
|
80
|
+
## SemantoClient
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from trooth_semanto_verify.client import SemantoClient
|
|
84
|
+
r = SemantoClient().read("https://acme.com/pricing")
|
|
85
|
+
print(r["ok"], r["dns"], r["reason"])
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
It fetches with the standard library (pass `fetch=` to use your own), checks the response signature and the domain's `_trooth-keys` TXT record over DNS over HTTPS, and keeps key sets and DNS answers five minutes.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
trooth/__init__.py,sha256=-HEmIomyD1vyaJXClxUsXTCMAxXT0-enjgf6Cwvv3KI,593
|
|
2
|
+
trooth/integrations/__init__.py,sha256=1Daek-5nXmiqzFU0nlA2Hsm86YYsGoZW0Ey27rInkYw,579
|
|
3
|
+
trooth/integrations/langchain.py,sha256=xmdKUnI5u-D0LtFVDFLXrGb5zEfxtwz8uXkscx7rEtc,1183
|
|
4
|
+
trooth/integrations/llama_index.py,sha256=e1KoIE7d4S0ZVk7fWidhxSmrKCRBDVECcDFGB-VgLSI,1186
|
|
5
|
+
trooth/integrations/openai_agents.py,sha256=3ZGanLE-D52Df4v9bNdyA7GzwYMEs9vLdDN6uYaK2gI,1483
|
|
6
|
+
trooth-0.1.0.dist-info/licenses/LICENSE,sha256=V7I1GHdYftWhGbN-x3vS4SfgJxAs8q7RxmceSh4T9KM,9963
|
|
7
|
+
trooth_semanto_verify/__init__.py,sha256=MT5Nf3Vp0LnYHDXV3ZriYnaaJ_iAM82CgDPnNaq34WI,2421
|
|
8
|
+
trooth_semanto_verify/__main__.py,sha256=e5ejnrv8VJEBnzjZlL59hAPp0HMNI94e5i9KKcz64Pc,182
|
|
9
|
+
trooth_semanto_verify/canonical.py,sha256=dRdFvmQRKj-GYHSq6m2SyPSZDgyrJPUgChEqPER3zrc,2829
|
|
10
|
+
trooth_semanto_verify/cli.py,sha256=3kBLYTt_ZfaY1LxlO-KrhqRNPDcaMwxzP9i-WwtAVSs,11668
|
|
11
|
+
trooth_semanto_verify/client.py,sha256=2KLRZhoyDkZAFVENSWH3H459hgon11VZPcPmoG39vXk,5667
|
|
12
|
+
trooth_semanto_verify/httpsig.py,sha256=WZOm7-iaEKputhQUmB2xMV3ZwBpmf4FkCPS7D7Svw7s,8761
|
|
13
|
+
trooth_semanto_verify/jws.py,sha256=9lp9uDm7NVtH7PbdztIEb1Pe3fGu2bZcPbWEPyE4F50,9726
|
|
14
|
+
trooth_semanto_verify/merkle.py,sha256=eTbHZIVCX8ZyJO5fAQf0xwycSDHOC8CxBAqe_t3QGE8,3243
|
|
15
|
+
trooth_semanto_verify/verify.py,sha256=AGyiKPmdgYOHy_RMgzlbVSOpkH4t3_Ys5lW5CbbAm4o,31306
|
|
16
|
+
trooth-0.1.0.dist-info/METADATA,sha256=SyJdnfmVzT4IL6K0GLHcfn-KW1UK6_OSLGJDPodeCow,4481
|
|
17
|
+
trooth-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
18
|
+
trooth-0.1.0.dist-info/entry_points.txt,sha256=UKoBCtXccDm0qbrzNMksc68wG2t_HVTKrZGckChmpsw,66
|
|
19
|
+
trooth-0.1.0.dist-info/top_level.txt,sha256=W3czcRYb9UJL1sX-RZ0iOaIYKxPcxPDa-cCb4-FEdcM,29
|
|
20
|
+
trooth-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
16
|
+
|
|
17
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
18
|
+
|
|
19
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
20
|
+
|
|
21
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
22
|
+
|
|
23
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
24
|
+
|
|
25
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
26
|
+
|
|
27
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
28
|
+
|
|
29
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
30
|
+
|
|
31
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
32
|
+
|
|
33
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
34
|
+
|
|
35
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
36
|
+
|
|
37
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
38
|
+
|
|
39
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
40
|
+
|
|
41
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
42
|
+
|
|
43
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
|
56
|
+
|
|
57
|
+
Copyright (c) 2026 Trooth, LLC
|
|
58
|
+
|
|
59
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use the files in this
|
|
60
|
+
verifier/ folder except in compliance with the License. You may obtain a copy of the License at
|
|
61
|
+
|
|
62
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
63
|
+
|
|
64
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is
|
|
65
|
+
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
66
|
+
implied. See the License for the specific language governing permissions and limitations under the
|
|
67
|
+
License.
|
|
68
|
+
|
|
69
|
+
This license covers the verifier/ folder only. Every other file in this repository is proprietary to
|
|
70
|
+
Trooth, LLC (LicenseRef-Trooth-Proprietary) unless its own header says otherwise.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright (c) 2026 Trooth, LLC
|
|
3
|
+
#
|
|
4
|
+
# trooth_semanto_verify: check a Semanto file, a page proof, a signed response
|
|
5
|
+
# or the public log, offline, with the standard library plus `cryptography`.
|
|
6
|
+
# The same functions, names and reason codes as the JavaScript and Go kits, so
|
|
7
|
+
# the shared vectors in verifier/test-vectors/v1 run unchanged.
|
|
8
|
+
|
|
9
|
+
from .canonical import CanonicalizeError, canonical_bytes, canonicalize
|
|
10
|
+
from .httpsig import (
|
|
11
|
+
SEMANTO_RESPONSE_COMPONENTS,
|
|
12
|
+
SEMANTO_RESPONSE_TAG,
|
|
13
|
+
WEB_BOT_AUTH_TAG,
|
|
14
|
+
parse_signature,
|
|
15
|
+
parse_signature_input,
|
|
16
|
+
signature_base,
|
|
17
|
+
verify_content_digest,
|
|
18
|
+
verify_message,
|
|
19
|
+
)
|
|
20
|
+
from .jws import JWS_TYPES, has_roles, key_resolver, key_valid_at, key_valid_at_signing, parse_dns_key_records, role_keys, role_resolver, thumbprint, verify_jws
|
|
21
|
+
from .merkle import digest, digest_bytes, is_digest, leaf_hash, node_hash, root_from_leaf_hashes, verify_inclusion
|
|
22
|
+
from .verify import (
|
|
23
|
+
fact_id,
|
|
24
|
+
facts_root,
|
|
25
|
+
pages_root,
|
|
26
|
+
parse_link,
|
|
27
|
+
root_hash,
|
|
28
|
+
semanto_id,
|
|
29
|
+
state_of,
|
|
30
|
+
tier_hash,
|
|
31
|
+
verify_checkpoint,
|
|
32
|
+
verify_consistency,
|
|
33
|
+
verify_inclusion_in_log,
|
|
34
|
+
verify_offer,
|
|
35
|
+
verify_page_proof,
|
|
36
|
+
verify_response,
|
|
37
|
+
verify_revocation_list,
|
|
38
|
+
verify_semanto,
|
|
39
|
+
verify_tree_head,
|
|
40
|
+
verify_web_bot_auth_request,
|
|
41
|
+
version_id,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
__all__ = [
|
|
45
|
+
"CanonicalizeError",
|
|
46
|
+
"canonicalize",
|
|
47
|
+
"canonical_bytes",
|
|
48
|
+
"SEMANTO_RESPONSE_COMPONENTS",
|
|
49
|
+
"SEMANTO_RESPONSE_TAG",
|
|
50
|
+
"WEB_BOT_AUTH_TAG",
|
|
51
|
+
"parse_signature",
|
|
52
|
+
"parse_signature_input",
|
|
53
|
+
"signature_base",
|
|
54
|
+
"verify_content_digest",
|
|
55
|
+
"verify_message",
|
|
56
|
+
"JWS_TYPES",
|
|
57
|
+
"key_resolver",
|
|
58
|
+
"key_valid_at",
|
|
59
|
+
"key_valid_at_signing",
|
|
60
|
+
"has_roles",
|
|
61
|
+
"role_keys",
|
|
62
|
+
"role_resolver",
|
|
63
|
+
"parse_dns_key_records",
|
|
64
|
+
"thumbprint",
|
|
65
|
+
"verify_jws",
|
|
66
|
+
"digest",
|
|
67
|
+
"digest_bytes",
|
|
68
|
+
"is_digest",
|
|
69
|
+
"leaf_hash",
|
|
70
|
+
"node_hash",
|
|
71
|
+
"root_from_leaf_hashes",
|
|
72
|
+
"verify_inclusion",
|
|
73
|
+
"fact_id",
|
|
74
|
+
"facts_root",
|
|
75
|
+
"pages_root",
|
|
76
|
+
"parse_link",
|
|
77
|
+
"root_hash",
|
|
78
|
+
"semanto_id",
|
|
79
|
+
"state_of",
|
|
80
|
+
"tier_hash",
|
|
81
|
+
"verify_checkpoint",
|
|
82
|
+
"verify_consistency",
|
|
83
|
+
"verify_inclusion_in_log",
|
|
84
|
+
"verify_offer",
|
|
85
|
+
"verify_page_proof",
|
|
86
|
+
"verify_response",
|
|
87
|
+
"verify_revocation_list",
|
|
88
|
+
"verify_semanto",
|
|
89
|
+
"verify_tree_head",
|
|
90
|
+
"verify_web_bot_auth_request",
|
|
91
|
+
"version_id",
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright (c) 2026 Trooth, LLC
|
|
3
|
+
#
|
|
4
|
+
# JSON Canonicalization Scheme, RFC 8785, written by hand so the package needs
|
|
5
|
+
# no dependency for it. Semanto signs integers only; a non-integer float raises
|
|
6
|
+
# with a clear message instead of guessing at ECMAScript number formatting.
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
_ESCAPES = {
|
|
13
|
+
0x22: '\\"',
|
|
14
|
+
0x5C: "\\\\",
|
|
15
|
+
0x08: "\\b",
|
|
16
|
+
0x0C: "\\f",
|
|
17
|
+
0x0A: "\\n",
|
|
18
|
+
0x0D: "\\r",
|
|
19
|
+
0x09: "\\t",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
_MAX_SAFE = 2**53
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class CanonicalizeError(ValueError):
|
|
26
|
+
"""Raised when a value cannot be canonicalized the way Semanto signs it."""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _string(s: str) -> str:
|
|
30
|
+
out = ['"']
|
|
31
|
+
for ch in s:
|
|
32
|
+
c = ord(ch)
|
|
33
|
+
esc = _ESCAPES.get(c)
|
|
34
|
+
if esc is not None:
|
|
35
|
+
out.append(esc)
|
|
36
|
+
elif c < 0x20:
|
|
37
|
+
out.append(f"\\u{c:04x}")
|
|
38
|
+
else:
|
|
39
|
+
out.append(ch)
|
|
40
|
+
out.append('"')
|
|
41
|
+
return "".join(out)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _utf16_key(s: str) -> bytes:
|
|
45
|
+
# RFC 8785 sorts member names by UTF-16 code units; comparing UTF-16-BE
|
|
46
|
+
# byte strings gives exactly that order.
|
|
47
|
+
return s.encode("utf-16-be")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def canonicalize(value: Any) -> str:
|
|
51
|
+
"""Return the RFC 8785 canonical JSON text of `value`."""
|
|
52
|
+
if value is None:
|
|
53
|
+
return "null"
|
|
54
|
+
if value is True:
|
|
55
|
+
return "true"
|
|
56
|
+
if value is False:
|
|
57
|
+
return "false"
|
|
58
|
+
if isinstance(value, int):
|
|
59
|
+
if abs(value) >= _MAX_SAFE:
|
|
60
|
+
raise CanonicalizeError(
|
|
61
|
+
f"canonicalize: integer {value} is outside the range Semanto signs (less than 2**53 in magnitude)"
|
|
62
|
+
)
|
|
63
|
+
return str(value)
|
|
64
|
+
if isinstance(value, float):
|
|
65
|
+
if value != value or value in (float("inf"), float("-inf")):
|
|
66
|
+
raise CanonicalizeError("canonicalize: non-finite number")
|
|
67
|
+
if value.is_integer() and abs(value) < _MAX_SAFE:
|
|
68
|
+
return str(int(value))
|
|
69
|
+
raise CanonicalizeError(
|
|
70
|
+
f"canonicalize: {value!r} is not an integer. Semanto signs integers only; "
|
|
71
|
+
"represent amounts in minor units (cents) and other decimals as strings."
|
|
72
|
+
)
|
|
73
|
+
if isinstance(value, str):
|
|
74
|
+
return _string(value)
|
|
75
|
+
if isinstance(value, (list, tuple)):
|
|
76
|
+
return "[" + ",".join(canonicalize(v) for v in value) + "]"
|
|
77
|
+
if isinstance(value, dict):
|
|
78
|
+
items = []
|
|
79
|
+
for k in sorted(value.keys(), key=lambda k: _utf16_key(str(k))):
|
|
80
|
+
if not isinstance(k, str):
|
|
81
|
+
raise CanonicalizeError("canonicalize: object keys must be strings")
|
|
82
|
+
items.append(_string(k) + ":" + canonicalize(value[k]))
|
|
83
|
+
return "{" + ",".join(items) + "}"
|
|
84
|
+
raise CanonicalizeError(f"canonicalize: cannot serialize {type(value).__name__}")
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def canonical_bytes(value: Any) -> bytes:
|
|
88
|
+
return canonicalize(value).encode("utf-8")
|