universal-paper 0.1.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.
Files changed (40) hide show
  1. universal_paper-0.1.0/LICENSE +202 -0
  2. universal_paper-0.1.0/NOTICE +24 -0
  3. universal_paper-0.1.0/PKG-INFO +191 -0
  4. universal_paper-0.1.0/README.md +146 -0
  5. universal_paper-0.1.0/pyproject.toml +80 -0
  6. universal_paper-0.1.0/setup.cfg +4 -0
  7. universal_paper-0.1.0/spec/LICENSE +156 -0
  8. universal_paper-0.1.0/src/universal_paper/__init__.py +7 -0
  9. universal_paper-0.1.0/src/universal_paper/__main__.py +206 -0
  10. universal_paper-0.1.0/src/universal_paper/build.py +145 -0
  11. universal_paper-0.1.0/src/universal_paper/canon.py +125 -0
  12. universal_paper-0.1.0/src/universal_paper/crypto.py +91 -0
  13. universal_paper-0.1.0/src/universal_paper/engine.py +1157 -0
  14. universal_paper-0.1.0/src/universal_paper/mcp_http.py +116 -0
  15. universal_paper-0.1.0/src/universal_paper/mcp_server.py +285 -0
  16. universal_paper-0.1.0/src/universal_paper/py.typed +0 -0
  17. universal_paper-0.1.0/src/universal_paper/render.py +102 -0
  18. universal_paper-0.1.0/src/universal_paper/report.py +57 -0
  19. universal_paper-0.1.0/src/universal_paper/simulate.py +59 -0
  20. universal_paper-0.1.0/src/universal_paper/terms.json +827 -0
  21. universal_paper-0.1.0/src/universal_paper/trace.py +138 -0
  22. universal_paper-0.1.0/src/universal_paper/typecheck.py +228 -0
  23. universal_paper-0.1.0/src/universal_paper/values.py +157 -0
  24. universal_paper-0.1.0/src/universal_paper.egg-info/PKG-INFO +191 -0
  25. universal_paper-0.1.0/src/universal_paper.egg-info/SOURCES.txt +38 -0
  26. universal_paper-0.1.0/src/universal_paper.egg-info/dependency_links.txt +1 -0
  27. universal_paper-0.1.0/src/universal_paper.egg-info/entry_points.txt +3 -0
  28. universal_paper-0.1.0/src/universal_paper.egg-info/requires.txt +21 -0
  29. universal_paper-0.1.0/src/universal_paper.egg-info/top_level.txt +1 -0
  30. universal_paper-0.1.0/tests/test_audit_regressions.py +155 -0
  31. universal_paper-0.1.0/tests/test_axioms.py +321 -0
  32. universal_paper-0.1.0/tests/test_canon.py +43 -0
  33. universal_paper-0.1.0/tests/test_crypto.py +148 -0
  34. universal_paper-0.1.0/tests/test_differential.py +125 -0
  35. universal_paper-0.1.0/tests/test_js_conformance.py +86 -0
  36. universal_paper-0.1.0/tests/test_mcp_server.py +148 -0
  37. universal_paper-0.1.0/tests/test_robustness.py +173 -0
  38. universal_paper-0.1.0/tests/test_rules.py +263 -0
  39. universal_paper-0.1.0/tests/test_simulate_trace.py +92 -0
  40. universal_paper-0.1.0/tests/test_terms.py +193 -0
@@ -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.
@@ -0,0 +1,24 @@
1
+ Universal Paper
2
+ https://universalpaper.org
3
+
4
+ Copyright 2026 Uppercentile
5
+
6
+ Universal Paper was created by Uppercentile, which offers it to everyone for
7
+ free under open licenses:
8
+
9
+ - Specification, Term library and documentation (spec/, DESIGN_NOTES.md,
10
+ and the text of the website in site/): Creative Commons Attribution 4.0
11
+ International (CC BY 4.0). See spec/LICENSE.
12
+ - Code, JSON Schemas, tools, tests and test vectors (src/, explorer/,
13
+ schema/, tools/, tests/, site/*.py): Apache License, Version 2.0.
14
+ See LICENSE.
15
+ - Example agreements, bundles and traces (examples/): CC0 1.0 Universal
16
+ public domain dedication. See examples/LICENSE.
17
+
18
+ No account, fee or license key is required to use, implement or build on
19
+ Universal Paper.
20
+
21
+ This product includes no third-party code. The Python reference interpreter
22
+ depends at runtime on the "cryptography" package (Apache-2.0 or BSD-3-Clause).
23
+ Web pages load the Inter, Inter Tight, JetBrains Mono and Source Serif 4
24
+ fonts from Google Fonts (SIL Open Font License 1.1).
@@ -0,0 +1,191 @@
1
+ Metadata-Version: 2.4
2
+ Name: universal-paper
3
+ Version: 0.1.0
4
+ Summary: Reference interpreter for Universal Paper, a first-order language for GPO agreements
5
+ Author: Uppercentile
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://universalpaper.org
8
+ Project-URL: Documentation, https://universalpaper.org/spec/
9
+ Project-URL: Source, https://github.com/Uppercentile/universal-paper
10
+ Project-URL: Issues, https://github.com/Uppercentile/universal-paper/issues
11
+ Keywords: agreements,contracts,group purchasing,GPO,ricardian,canonical json,ed25519
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Office/Business
21
+ Classifier: Topic :: Security :: Cryptography
22
+ Requires-Python: >=3.11
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ License-File: NOTICE
26
+ License-File: spec/LICENSE
27
+ Requires-Dist: cryptography>=41
28
+ Provides-Extra: test
29
+ Requires-Dist: pytest>=7; extra == "test"
30
+ Requires-Dist: jsonschema>=4; extra == "test"
31
+ Requires-Dist: hypothesis>=6.100; extra == "test"
32
+ Requires-Dist: pytest-cov>=4; extra == "test"
33
+ Requires-Dist: mcp>=1.2; extra == "test"
34
+ Requires-Dist: httpx>=0.27; extra == "test"
35
+ Provides-Extra: mcp
36
+ Requires-Dist: mcp>=1.2; extra == "mcp"
37
+ Provides-Extra: hosted
38
+ Requires-Dist: mcp>=2; extra == "hosted"
39
+ Requires-Dist: uvicorn>=0.30; extra == "hosted"
40
+ Provides-Extra: dev
41
+ Requires-Dist: universal-paper[test]; extra == "dev"
42
+ Requires-Dist: ruff>=0.6; extra == "dev"
43
+ Requires-Dist: mypy>=1.10; extra == "dev"
44
+ Dynamic: license-file
45
+
46
+ <p align="center">
47
+ <picture>
48
+ <source media="(prefers-color-scheme: dark)" srcset="assets/universal-paper-mark-white-512.png">
49
+ <img src="assets/universal-paper-mark-black-512.png" alt="Universal Paper logo" width="120">
50
+ </picture>
51
+ </p>
52
+
53
+ # Universal Paper
54
+
55
+ A first-order language for agreements between group purchasing organizations, suppliers, and members.
56
+
57
+ Universal Paper is a vocabulary, a grammar, and a set of validity rules. It is not an application. Anyone can verify an agreement written in it, offline, from the specification alone. The code here is a reference implementation of the language, never the language itself.
58
+
59
+ **Website:** [universalpaper.org](https://universalpaper.org) · [Playground](https://universalpaper.org/#playground) · [FAQ](https://universalpaper.org/faq/)
60
+
61
+ **Status:** `UP/0.1-draft`. Working draft, not yet reviewed by counsel. Until 1.0, changes to the spec may change what is valid and the hashes of Term definitions. Open questions are listed in [DESIGN_NOTES.md](DESIGN_NOTES.md#6-open-questions-for-the-steward). The pre-release audit is in [AUDIT.md](AUDIT.md).
62
+
63
+ | Path | What it is |
64
+ |---|---|
65
+ | [spec/](spec/00-overview.md) | The language specification (start here) |
66
+ | [DESIGN_NOTES.md](DESIGN_NOTES.md) | What was cut, merged, or added, and why |
67
+ | [schema/](schema/) | JSON Schemas for every primitive and for trace files |
68
+ | [src/universal_paper/](src/universal_paper/) | Reference interpreter (library and CLI) |
69
+ | [examples/](examples/) | Worked examples as full chains of signed events, plus traces |
70
+ | [explorer/index.html](explorer/index.html) | Universal Paper Playground: an ecosystem view, the Playground (write, compare, history), and conformance (built from `explorer/src/`) |
71
+ | [explorer/src/](explorer/src/) | The JavaScript second engine (`up-crypto.js`, `up-engine.js`), the random-run lab (`up-lab.js`), the history player (`up-play.js`), and the page |
72
+ | [site/](site/) | The universalpaper.org website build (`python3 site/build_site.py`), deployed to GitHub Pages |
73
+ | [tests/](tests/) | Tests for every axiom, transition rule, clause form, and Term, plus cross-engine differential and fuzz tests |
74
+ | [AUDIT.md](AUDIT.md) | Pre-release audit: findings, fixes, and what remains open |
75
+
76
+ ## Quick start
77
+
78
+ Requires Python 3.11+ and Git. From an empty terminal on macOS or Linux:
79
+
80
+ ```sh
81
+ git clone https://github.com/Uppercentile/universal-paper.git
82
+ cd universal-paper
83
+ python3 -m venv .venv && source .venv/bin/activate
84
+ pip install -e '.[test]'
85
+
86
+ up validate examples/conventional/bundle.json
87
+ ```
88
+
89
+ On Windows (PowerShell), activate the environment with `.venv\Scripts\Activate.ps1` instead of `source .venv/bin/activate`. The virtual environment keeps the install out of your system Python, which recent macOS and Linux releases refuse to modify ([PEP 668](https://peps.python.org/pep-0668/)).
90
+
91
+ Then try the other commands, from the same folder with the environment active:
92
+
93
+ ```sh
94
+ up derive examples/conventional/bundle.json --at 2027-04-30T00:00:00Z # status, tiers, prices and what is owed on a date
95
+ up render examples/conventional/bundle.json --chain 0 # the agreement as contract text
96
+ up render examples/confidential/bundle.json --chain 0 --hashes-only # the same with every private value sealed
97
+ up trace examples/conventional/bundle.json -o conventional.trace.json # every event, every check, every state hash
98
+ up hash spec/06-terms/UP-Admin-Fee.json # the content address of a Term definition
99
+ python -m pytest # the full test suite (Node.js 20+ for the JavaScript parts)
100
+ ```
101
+
102
+ `up simulate BUNDLE EVENTS.json` runs your own hypothetical events forward against a bundle.
103
+
104
+ | Command | Does |
105
+ |---|---|
106
+ | `validate` | Checks every agreement and every event in a bundle against the axioms. Exit code 2 if any event is rejected. |
107
+ | `apply` | Applies one event to its chain's current state and prints the new state, or the rule that rejected it. |
108
+ | `derive` | Reports each agreement's status, tiers, contract prices, and obligations at a time. |
109
+ | `simulate` | Runs hypothetical events forward. Signatures are not required, but Mandate limits still apply. |
110
+ | `render` | Prints the human-readable agreement text, fixed by the agreement's hash. |
111
+ | `trace` | Writes a trace file: every event, every check, and each evaluator's state hash. |
112
+
113
+ ## MCP server for agents
114
+
115
+ <!-- mcp-name: io.github.Uppercentile/universal-paper -->
116
+
117
+ The official Universal Paper [Model Context Protocol](https://modelcontextprotocol.io) server is a read-only layer over the reference interpreter. It lets an agent check an agreement the same way every other party does, and test whether an action is within its Mandate before anyone signs. It holds no keys, signs nothing, and writes nothing.
118
+
119
+ | Use it | How |
120
+ |---|---|
121
+ | Hosted, nothing to install | `https://mcp.universalpaper.org/mcp` (Streamable HTTP, no sign-in) |
122
+ | Local, from PyPI | `uvx universal-paper-mcp` |
123
+ | Local, from this repo | `pip install -e '.[mcp]'` then `up-mcp` |
124
+
125
+ Claude Code: `claude mcp add --transport http universal-paper https://mcp.universalpaper.org/mcp`, or locally `claude mcp add universal-paper -- uvx universal-paper-mcp`. Other clients: `{"mcpServers": {"universal-paper": {"command": "uvx", "args": ["universal-paper-mcp"]}}}`, or the hosted URL wherever a client takes a remote server. It is listed in the [MCP Registry](https://registry.modelcontextprotocol.io) as `io.github.Uppercentile/universal-paper`.
126
+
127
+ The hosted endpoint (`up-mcp --hosted`, built from the [Dockerfile](Dockerfile)) is stateless: no sessions, storage, access logs or telemetry, and it never reads file paths, so a bundle is passed as an object or JSON text. It counts calls per tool name in memory and shows the totals at [/stats](https://mcp.universalpaper.org/stats); that is its only usage signal. How it is deployed and released: [deploy/README.md](deploy/README.md).
128
+
129
+ | Tool | Does |
130
+ |---|---|
131
+ | `validate_bundle` | Checks every agreement and event against the axioms and says which rule rejected what. |
132
+ | `derive_state` | Status, tiers, contract prices and obligations at a time. |
133
+ | `check_event` | Dry-runs one signed event against its chain's current state. |
134
+ | `simulate_events` | Runs hypothetical, unsigned events forward. Mandate limits still apply. |
135
+ | `render_text` | The human-readable agreement text, fixed by its hash (optionally as an outsider sees it). |
136
+ | `hash_object` | The content hash of any JSON value. |
137
+ | `list_terms`, `explain_term` | The Term library: parameters, claims, rendering template, provenance and hash. |
138
+ | `get_example` | One of the worked example bundles. |
139
+
140
+ Bundles can be passed as JSON objects, JSON text, or (local server only) file paths.
141
+
142
+ ## Examples
143
+
144
+ All parties, identifiers, prices, rates, quantities, and dates in the examples are **hypothetical**.
145
+
146
+ - **Conventional**: an aggregator–supplier agreement with three tiers and an admin fee, two members joining through participation and tier attestation, three months of sales reports, fee payments, one tier change, and a fee disclosure.
147
+ - **Generative**: an aggregator with no staff, run entirely by an agent under a Mandate, alongside a conventional aggregator. One hospital, acting through its own agent, participates in both at once without conflict. Two out-of-bounds agent actions are rejected under A9.
148
+ - **Overlay**: a 2024 contract described in Universal Paper in 2027, identified by its document hash, without renegotiation.
149
+ - **Confidential**: the conventional story with every price, rate, quantity, and amount sealed. An evaluator with no disclosures reaches the same verdicts and state hashes.
150
+
151
+ `python3 examples/build_examples.py` rebuilds every bundle and trace. Output is byte-identical across runs. Example keys and salts are derived from fixed seeds so the examples are reproducible; real keys and salts must be random.
152
+
153
+ ## Playground page
154
+
155
+ Open `explorer/index.html` in a browser. It is one self-contained file; apart from web fonts it makes no network requests. Its look follows the shared design tokens in `explorer/src/tokens.css`, also used by the developer explainer. It has four parts:
156
+
157
+ - **How it works**: a scroll explainer that follows one fee clause from words to a fingerprint, signatures, and a caught edit, computed live. On a phone the visual pins at the top and the steps scroll under it.
158
+ - **Vision**: an illustration of where Universal Paper could sit, under apps for contracting, procurement, pricing, and settlement, with agents acting for parties under Mandates. The apps are hypothetical. The events are not: each scenario is generated, signed, and checked by the engine in the page, including an agent action outside its Mandate that every party rejects.
159
+ - **Playground**: start from an example and change the few things people try first (the fee, the length, the supplier, whether the rate is sealed) while the cover sheet, the contract, and the fingerprint update. Every clause stays editable under “Edit every clause”. **Compare** shows what changed between two versions, clause by clause and word by word, and whether existing signatures still cover it. **History** signs the agreement and plays it forward: enter monthly sales and payments and see the reports, fees, and the status of every duty on any date.
160
+ - **Conformance**: the test suite by file, the audit findings, and a button that runs random agreements and attacks in the browser against eight invariants.
161
+
162
+ Everything live runs on a second, independent engine in JavaScript (`explorer/src/`). `tests/test_js_conformance.py` requires it to reproduce every Python trace, rendering, and simulation byte for byte, and to pass every invariant on 60 fixed seeds. Rebuild the page after editing `explorer/src/` with `python3 tools/build_explorer.py`; add `--run-tests` to run the suite first and record the result shown on the page (`explorer/conformance-results.json`). The plain build is deterministic so CI can check the committed page.
163
+
164
+ ## How it is tested
165
+
166
+ `python -m pytest` runs about 170 tests in a few minutes. Node.js 20 or later is needed for the JavaScript parts, which are skipped without it. CI runs everything on Python 3.11 to 3.13.
167
+
168
+ - **Rules.** Every axiom (A1 to A13), every transition rule, and every clause form has tests that build small hypothetical agreements and try to break them.
169
+ - **Every Term.** All sixteen Terms are executed in a valid agreement, every parameter is checked against its declared type, and every claim type is attested, acknowledged, and attempted with ill-typed data.
170
+ - **Two engines, one answer.** The JavaScript engine must reproduce every Python trace, render, and simulation byte for byte, including a trace for every claim type of every Term. Differential tests run both engines on tens of thousands of seeded random inputs (canonical JSON, hashes, Ed25519 edge cases, times, periods, exact decimals, type checks) and require identical results, including identical rejections.
171
+ - **Published vectors.** Ed25519 against RFC 8032, SHA-256 and SHA-512 against known digests, and a check that the small-order key table is exactly the curve's torsion points.
172
+ - **Hostile input.** Hypothesis mutates signed example events and feeds arbitrary JSON to the evaluator: altered events are always rejected, nothing crashes or hangs, and derived values stay computable. `HYPOTHESIS_PROFILE=deep` runs a longer search.
173
+ - **Reproducibility.** Rebuilding the Term library, examples, traces, and the Playground page must produce byte-identical files.
174
+
175
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the full list and how to add tests.
176
+
177
+ ## Contributing and security
178
+
179
+ Contributions to the specification and the code are welcome: see [CONTRIBUTING.md](CONTRIBUTING.md) and the [Code of Conduct](CODE_OF_CONDUCT.md). Please report vulnerabilities privately, as described in [SECURITY.md](SECURITY.md). Changes are recorded in [CHANGELOG.md](CHANGELOG.md).
180
+
181
+ ## Licenses
182
+
183
+ Universal Paper was created by [Uppercentile](https://uppercentile.com), which offers it to the market for free. Anyone may use, implement, extend, fork, and build commercial products on it, without permission or payment. No account, fee, or license key is ever required.
184
+
185
+ | What | License |
186
+ |---|---|
187
+ | Specification, Term library, and documentation (`spec/`, `DESIGN_NOTES.md`, website text) | [CC BY 4.0](spec/LICENSE) |
188
+ | Code, JSON Schemas, tools, tests, and test vectors | [Apache-2.0](LICENSE) (see [NOTICE](NOTICE)) |
189
+ | Example agreements, bundles, and traces (`examples/`) | [CC0 1.0](examples/LICENSE) (public domain) |
190
+
191
+ To credit the specification: *"Universal Paper" specification by Uppercentile, https://universalpaper.org, licensed under CC BY 4.0.* Details: [universalpaper.org/license](https://universalpaper.org/license/). Uppercentile is the specification's steward, not its owner; see the [neutrality charter](spec/08-neutrality-charter.md).
@@ -0,0 +1,146 @@
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="assets/universal-paper-mark-white-512.png">
4
+ <img src="assets/universal-paper-mark-black-512.png" alt="Universal Paper logo" width="120">
5
+ </picture>
6
+ </p>
7
+
8
+ # Universal Paper
9
+
10
+ A first-order language for agreements between group purchasing organizations, suppliers, and members.
11
+
12
+ Universal Paper is a vocabulary, a grammar, and a set of validity rules. It is not an application. Anyone can verify an agreement written in it, offline, from the specification alone. The code here is a reference implementation of the language, never the language itself.
13
+
14
+ **Website:** [universalpaper.org](https://universalpaper.org) · [Playground](https://universalpaper.org/#playground) · [FAQ](https://universalpaper.org/faq/)
15
+
16
+ **Status:** `UP/0.1-draft`. Working draft, not yet reviewed by counsel. Until 1.0, changes to the spec may change what is valid and the hashes of Term definitions. Open questions are listed in [DESIGN_NOTES.md](DESIGN_NOTES.md#6-open-questions-for-the-steward). The pre-release audit is in [AUDIT.md](AUDIT.md).
17
+
18
+ | Path | What it is |
19
+ |---|---|
20
+ | [spec/](spec/00-overview.md) | The language specification (start here) |
21
+ | [DESIGN_NOTES.md](DESIGN_NOTES.md) | What was cut, merged, or added, and why |
22
+ | [schema/](schema/) | JSON Schemas for every primitive and for trace files |
23
+ | [src/universal_paper/](src/universal_paper/) | Reference interpreter (library and CLI) |
24
+ | [examples/](examples/) | Worked examples as full chains of signed events, plus traces |
25
+ | [explorer/index.html](explorer/index.html) | Universal Paper Playground: an ecosystem view, the Playground (write, compare, history), and conformance (built from `explorer/src/`) |
26
+ | [explorer/src/](explorer/src/) | The JavaScript second engine (`up-crypto.js`, `up-engine.js`), the random-run lab (`up-lab.js`), the history player (`up-play.js`), and the page |
27
+ | [site/](site/) | The universalpaper.org website build (`python3 site/build_site.py`), deployed to GitHub Pages |
28
+ | [tests/](tests/) | Tests for every axiom, transition rule, clause form, and Term, plus cross-engine differential and fuzz tests |
29
+ | [AUDIT.md](AUDIT.md) | Pre-release audit: findings, fixes, and what remains open |
30
+
31
+ ## Quick start
32
+
33
+ Requires Python 3.11+ and Git. From an empty terminal on macOS or Linux:
34
+
35
+ ```sh
36
+ git clone https://github.com/Uppercentile/universal-paper.git
37
+ cd universal-paper
38
+ python3 -m venv .venv && source .venv/bin/activate
39
+ pip install -e '.[test]'
40
+
41
+ up validate examples/conventional/bundle.json
42
+ ```
43
+
44
+ On Windows (PowerShell), activate the environment with `.venv\Scripts\Activate.ps1` instead of `source .venv/bin/activate`. The virtual environment keeps the install out of your system Python, which recent macOS and Linux releases refuse to modify ([PEP 668](https://peps.python.org/pep-0668/)).
45
+
46
+ Then try the other commands, from the same folder with the environment active:
47
+
48
+ ```sh
49
+ up derive examples/conventional/bundle.json --at 2027-04-30T00:00:00Z # status, tiers, prices and what is owed on a date
50
+ up render examples/conventional/bundle.json --chain 0 # the agreement as contract text
51
+ up render examples/confidential/bundle.json --chain 0 --hashes-only # the same with every private value sealed
52
+ up trace examples/conventional/bundle.json -o conventional.trace.json # every event, every check, every state hash
53
+ up hash spec/06-terms/UP-Admin-Fee.json # the content address of a Term definition
54
+ python -m pytest # the full test suite (Node.js 20+ for the JavaScript parts)
55
+ ```
56
+
57
+ `up simulate BUNDLE EVENTS.json` runs your own hypothetical events forward against a bundle.
58
+
59
+ | Command | Does |
60
+ |---|---|
61
+ | `validate` | Checks every agreement and every event in a bundle against the axioms. Exit code 2 if any event is rejected. |
62
+ | `apply` | Applies one event to its chain's current state and prints the new state, or the rule that rejected it. |
63
+ | `derive` | Reports each agreement's status, tiers, contract prices, and obligations at a time. |
64
+ | `simulate` | Runs hypothetical events forward. Signatures are not required, but Mandate limits still apply. |
65
+ | `render` | Prints the human-readable agreement text, fixed by the agreement's hash. |
66
+ | `trace` | Writes a trace file: every event, every check, and each evaluator's state hash. |
67
+
68
+ ## MCP server for agents
69
+
70
+ <!-- mcp-name: io.github.Uppercentile/universal-paper -->
71
+
72
+ The official Universal Paper [Model Context Protocol](https://modelcontextprotocol.io) server is a read-only layer over the reference interpreter. It lets an agent check an agreement the same way every other party does, and test whether an action is within its Mandate before anyone signs. It holds no keys, signs nothing, and writes nothing.
73
+
74
+ | Use it | How |
75
+ |---|---|
76
+ | Hosted, nothing to install | `https://mcp.universalpaper.org/mcp` (Streamable HTTP, no sign-in) |
77
+ | Local, from PyPI | `uvx universal-paper-mcp` |
78
+ | Local, from this repo | `pip install -e '.[mcp]'` then `up-mcp` |
79
+
80
+ Claude Code: `claude mcp add --transport http universal-paper https://mcp.universalpaper.org/mcp`, or locally `claude mcp add universal-paper -- uvx universal-paper-mcp`. Other clients: `{"mcpServers": {"universal-paper": {"command": "uvx", "args": ["universal-paper-mcp"]}}}`, or the hosted URL wherever a client takes a remote server. It is listed in the [MCP Registry](https://registry.modelcontextprotocol.io) as `io.github.Uppercentile/universal-paper`.
81
+
82
+ The hosted endpoint (`up-mcp --hosted`, built from the [Dockerfile](Dockerfile)) is stateless: no sessions, storage, access logs or telemetry, and it never reads file paths, so a bundle is passed as an object or JSON text. It counts calls per tool name in memory and shows the totals at [/stats](https://mcp.universalpaper.org/stats); that is its only usage signal. How it is deployed and released: [deploy/README.md](deploy/README.md).
83
+
84
+ | Tool | Does |
85
+ |---|---|
86
+ | `validate_bundle` | Checks every agreement and event against the axioms and says which rule rejected what. |
87
+ | `derive_state` | Status, tiers, contract prices and obligations at a time. |
88
+ | `check_event` | Dry-runs one signed event against its chain's current state. |
89
+ | `simulate_events` | Runs hypothetical, unsigned events forward. Mandate limits still apply. |
90
+ | `render_text` | The human-readable agreement text, fixed by its hash (optionally as an outsider sees it). |
91
+ | `hash_object` | The content hash of any JSON value. |
92
+ | `list_terms`, `explain_term` | The Term library: parameters, claims, rendering template, provenance and hash. |
93
+ | `get_example` | One of the worked example bundles. |
94
+
95
+ Bundles can be passed as JSON objects, JSON text, or (local server only) file paths.
96
+
97
+ ## Examples
98
+
99
+ All parties, identifiers, prices, rates, quantities, and dates in the examples are **hypothetical**.
100
+
101
+ - **Conventional**: an aggregator–supplier agreement with three tiers and an admin fee, two members joining through participation and tier attestation, three months of sales reports, fee payments, one tier change, and a fee disclosure.
102
+ - **Generative**: an aggregator with no staff, run entirely by an agent under a Mandate, alongside a conventional aggregator. One hospital, acting through its own agent, participates in both at once without conflict. Two out-of-bounds agent actions are rejected under A9.
103
+ - **Overlay**: a 2024 contract described in Universal Paper in 2027, identified by its document hash, without renegotiation.
104
+ - **Confidential**: the conventional story with every price, rate, quantity, and amount sealed. An evaluator with no disclosures reaches the same verdicts and state hashes.
105
+
106
+ `python3 examples/build_examples.py` rebuilds every bundle and trace. Output is byte-identical across runs. Example keys and salts are derived from fixed seeds so the examples are reproducible; real keys and salts must be random.
107
+
108
+ ## Playground page
109
+
110
+ Open `explorer/index.html` in a browser. It is one self-contained file; apart from web fonts it makes no network requests. Its look follows the shared design tokens in `explorer/src/tokens.css`, also used by the developer explainer. It has four parts:
111
+
112
+ - **How it works**: a scroll explainer that follows one fee clause from words to a fingerprint, signatures, and a caught edit, computed live. On a phone the visual pins at the top and the steps scroll under it.
113
+ - **Vision**: an illustration of where Universal Paper could sit, under apps for contracting, procurement, pricing, and settlement, with agents acting for parties under Mandates. The apps are hypothetical. The events are not: each scenario is generated, signed, and checked by the engine in the page, including an agent action outside its Mandate that every party rejects.
114
+ - **Playground**: start from an example and change the few things people try first (the fee, the length, the supplier, whether the rate is sealed) while the cover sheet, the contract, and the fingerprint update. Every clause stays editable under “Edit every clause”. **Compare** shows what changed between two versions, clause by clause and word by word, and whether existing signatures still cover it. **History** signs the agreement and plays it forward: enter monthly sales and payments and see the reports, fees, and the status of every duty on any date.
115
+ - **Conformance**: the test suite by file, the audit findings, and a button that runs random agreements and attacks in the browser against eight invariants.
116
+
117
+ Everything live runs on a second, independent engine in JavaScript (`explorer/src/`). `tests/test_js_conformance.py` requires it to reproduce every Python trace, rendering, and simulation byte for byte, and to pass every invariant on 60 fixed seeds. Rebuild the page after editing `explorer/src/` with `python3 tools/build_explorer.py`; add `--run-tests` to run the suite first and record the result shown on the page (`explorer/conformance-results.json`). The plain build is deterministic so CI can check the committed page.
118
+
119
+ ## How it is tested
120
+
121
+ `python -m pytest` runs about 170 tests in a few minutes. Node.js 20 or later is needed for the JavaScript parts, which are skipped without it. CI runs everything on Python 3.11 to 3.13.
122
+
123
+ - **Rules.** Every axiom (A1 to A13), every transition rule, and every clause form has tests that build small hypothetical agreements and try to break them.
124
+ - **Every Term.** All sixteen Terms are executed in a valid agreement, every parameter is checked against its declared type, and every claim type is attested, acknowledged, and attempted with ill-typed data.
125
+ - **Two engines, one answer.** The JavaScript engine must reproduce every Python trace, render, and simulation byte for byte, including a trace for every claim type of every Term. Differential tests run both engines on tens of thousands of seeded random inputs (canonical JSON, hashes, Ed25519 edge cases, times, periods, exact decimals, type checks) and require identical results, including identical rejections.
126
+ - **Published vectors.** Ed25519 against RFC 8032, SHA-256 and SHA-512 against known digests, and a check that the small-order key table is exactly the curve's torsion points.
127
+ - **Hostile input.** Hypothesis mutates signed example events and feeds arbitrary JSON to the evaluator: altered events are always rejected, nothing crashes or hangs, and derived values stay computable. `HYPOTHESIS_PROFILE=deep` runs a longer search.
128
+ - **Reproducibility.** Rebuilding the Term library, examples, traces, and the Playground page must produce byte-identical files.
129
+
130
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the full list and how to add tests.
131
+
132
+ ## Contributing and security
133
+
134
+ Contributions to the specification and the code are welcome: see [CONTRIBUTING.md](CONTRIBUTING.md) and the [Code of Conduct](CODE_OF_CONDUCT.md). Please report vulnerabilities privately, as described in [SECURITY.md](SECURITY.md). Changes are recorded in [CHANGELOG.md](CHANGELOG.md).
135
+
136
+ ## Licenses
137
+
138
+ Universal Paper was created by [Uppercentile](https://uppercentile.com), which offers it to the market for free. Anyone may use, implement, extend, fork, and build commercial products on it, without permission or payment. No account, fee, or license key is ever required.
139
+
140
+ | What | License |
141
+ |---|---|
142
+ | Specification, Term library, and documentation (`spec/`, `DESIGN_NOTES.md`, website text) | [CC BY 4.0](spec/LICENSE) |
143
+ | Code, JSON Schemas, tools, tests, and test vectors | [Apache-2.0](LICENSE) (see [NOTICE](NOTICE)) |
144
+ | Example agreements, bundles, and traces (`examples/`) | [CC0 1.0](examples/LICENSE) (public domain) |
145
+
146
+ To credit the specification: *"Universal Paper" specification by Uppercentile, https://universalpaper.org, licensed under CC BY 4.0.* Details: [universalpaper.org/license](https://universalpaper.org/license/). Uppercentile is the specification's steward, not its owner; see the [neutrality charter](spec/08-neutrality-charter.md).
@@ -0,0 +1,80 @@
1
+ [project]
2
+ name = "universal-paper"
3
+ version = "0.1.0"
4
+ description = "Reference interpreter for Universal Paper, a first-order language for GPO agreements"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = "Apache-2.0"
8
+ authors = [{ name = "Uppercentile" }]
9
+ license-files = ["LICENSE", "NOTICE", "spec/LICENSE"]
10
+ keywords = ["agreements", "contracts", "group purchasing", "GPO", "ricardian", "canonical json", "ed25519"]
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Intended Audience :: Developers",
14
+ "Operating System :: OS Independent",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3 :: Only",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Topic :: Office/Business",
21
+ "Topic :: Security :: Cryptography",
22
+ ]
23
+ dependencies = ["cryptography>=41"]
24
+
25
+ [project.optional-dependencies]
26
+ test = ["pytest>=7", "jsonschema>=4", "hypothesis>=6.100", "pytest-cov>=4", "mcp>=1.2", "httpx>=0.27"]
27
+ mcp = ["mcp>=1.2"]
28
+ # The hosted endpoint (up-mcp --hosted): Streamable HTTP, served by uvicorn.
29
+ hosted = ["mcp>=2", "uvicorn>=0.30"]
30
+ dev = ["universal-paper[test]", "ruff>=0.6", "mypy>=1.10"]
31
+
32
+ [project.scripts]
33
+ up = "universal_paper.__main__:main"
34
+ up-mcp = "universal_paper.mcp_server:main"
35
+
36
+ [build-system]
37
+ requires = ["setuptools>=77"]
38
+ build-backend = "setuptools.build_meta"
39
+
40
+ [tool.setuptools.packages.find]
41
+ where = ["src"]
42
+
43
+ [tool.setuptools.package-data]
44
+ universal_paper = ["terms.json", "py.typed"]
45
+
46
+ [tool.pytest.ini_options]
47
+ testpaths = ["tests"]
48
+ pythonpath = ["src", "examples"]
49
+
50
+ [project.urls]
51
+ Homepage = "https://universalpaper.org"
52
+ Documentation = "https://universalpaper.org/spec/"
53
+ Source = "https://github.com/Uppercentile/universal-paper"
54
+ Issues = "https://github.com/Uppercentile/universal-paper/issues"
55
+
56
+ [tool.ruff]
57
+ line-length = 140
58
+ target-version = "py311"
59
+ extend-exclude = ["explorer"]
60
+
61
+ [tool.ruff.lint]
62
+ select = ["E", "F", "W", "I", "B", "UP"]
63
+ # Long lines, one-line argparse wiring, and short math names (l, I) are deliberate in this codebase.
64
+ ignore = ["E501", "E702", "E741", "E731", "B905", "UP031"]
65
+
66
+ [tool.ruff.lint.isort]
67
+ known-first-party = ["universal_paper"]
68
+ known-local-folder = ["build_examples", "helpers", "oracle", "samples", "test_terms"]
69
+
70
+ [tool.mypy]
71
+ python_version = "3.11"
72
+ files = ["src/universal_paper"]
73
+ ignore_missing_imports = true
74
+ warn_unused_ignores = true
75
+
76
+ [[tool.mypy.overrides]]
77
+ # The evaluator reads untrusted JSON and treats any exception as a rejection (engine.apply), so
78
+ # many lookups are deliberately unguarded. Optional-narrowing errors are relaxed here only.
79
+ module = "universal_paper.engine"
80
+ disable_error_code = ["arg-type", "index", "operator", "union-attr", "assignment"]