foliant-protocol 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.
- foliant_protocol-0.1.0/LICENSE +202 -0
- foliant_protocol-0.1.0/NOTICE +14 -0
- foliant_protocol-0.1.0/PKG-INFO +120 -0
- foliant_protocol-0.1.0/README.md +101 -0
- foliant_protocol-0.1.0/foliant/__init__.py +18 -0
- foliant_protocol-0.1.0/foliant/accounts.py +232 -0
- foliant_protocol-0.1.0/foliant/agent.py +139 -0
- foliant_protocol-0.1.0/foliant/channels.py +149 -0
- foliant_protocol-0.1.0/foliant/crypto.py +111 -0
- foliant_protocol-0.1.0/foliant/errors.py +26 -0
- foliant_protocol-0.1.0/foliant/ledger.py +363 -0
- foliant_protocol-0.1.0/foliant/market.py +88 -0
- foliant_protocol-0.1.0/foliant/pools.py +123 -0
- foliant_protocol-0.1.0/foliant/x402.py +225 -0
- foliant_protocol-0.1.0/foliant_protocol.egg-info/PKG-INFO +120 -0
- foliant_protocol-0.1.0/foliant_protocol.egg-info/SOURCES.txt +24 -0
- foliant_protocol-0.1.0/foliant_protocol.egg-info/dependency_links.txt +1 -0
- foliant_protocol-0.1.0/foliant_protocol.egg-info/requires.txt +7 -0
- foliant_protocol-0.1.0/foliant_protocol.egg-info/top_level.txt +1 -0
- foliant_protocol-0.1.0/pyproject.toml +26 -0
- foliant_protocol-0.1.0/setup.cfg +4 -0
- foliant_protocol-0.1.0/tests/test_accounts_and_market.py +118 -0
- foliant_protocol-0.1.0/tests/test_channels.py +129 -0
- foliant_protocol-0.1.0/tests/test_pools.py +107 -0
- foliant_protocol-0.1.0/tests/test_tree.py +227 -0
- foliant_protocol-0.1.0/tests/test_x402.py +94 -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,14 @@
|
|
|
1
|
+
Foliant reference implementation
|
|
2
|
+
Copyright 2026 Machine Quotient Ltd
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: foliant-protocol
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Foliant reference implementation: agent accounts with hierarchical spending policies, payment channels, pooled settlement and HTTP 402 metering in the x402 wire format
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://foliant.network
|
|
7
|
+
Project-URL: Source, https://github.com/gazoy/concord
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: NOTICE
|
|
12
|
+
Requires-Dist: cryptography>=42
|
|
13
|
+
Requires-Dist: fastapi>=0.110
|
|
14
|
+
Requires-Dist: httpx>=0.27
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
17
|
+
Requires-Dist: hypothesis>=6; extra == "test"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# Foliant — reference implementation (Python)
|
|
21
|
+
|
|
22
|
+
Executable specification of the Foliant protocol: budgets and settlement for
|
|
23
|
+
AI agent crews. Agent accounts with spending policies the agent's code cannot
|
|
24
|
+
bypass, arranged in a tree so a whole crew shares one bound, TEE-style attestation, payment channels and streams, Ark-style pooled
|
|
25
|
+
channels a whole crew pays through, HTTP 402 metering in the x402 wire format,
|
|
26
|
+
and the compute-and-data market objects (whitepaper §6).
|
|
27
|
+
|
|
28
|
+
Foliant is a protocol, not a chain: on-chain contracts, an x402 payment scheme
|
|
29
|
+
and an SDK, deployable on chains agents already use. First targets are Base and
|
|
30
|
+
Avalanche. The whitepaper also describes a sovereign chain the protocol could
|
|
31
|
+
grow into if adoption warrants it; that is a direction, not the product. §11a
|
|
32
|
+
of the whitepaper records the prior art (Tempo, the x402 batch-settlement
|
|
33
|
+
scheme and others) and what Foliant adds.
|
|
34
|
+
|
|
35
|
+
This is a **spec plus demo**, not a deployment. It runs in one process with an
|
|
36
|
+
in-memory ledger so the state machines and their invariants can be read,
|
|
37
|
+
changed and tested quickly. The Solidity port implements the same state
|
|
38
|
+
machines as contracts; the tests here become its conformance suite.
|
|
39
|
+
|
|
40
|
+
## Name
|
|
41
|
+
|
|
42
|
+
The project was called Concord until 28 September 2026; the name was changed to Foliant after a UK trade-mark search. Older links, issues and messages that say Concord refer to this project.
|
|
43
|
+
|
|
44
|
+
## Documents
|
|
45
|
+
|
|
46
|
+
- Website: [foliant.network](https://foliant.network) (served from `docs/` via GitHub Pages)
|
|
47
|
+
- [Whitepaper v0.1](docs/whitepaper.md) — the full design (§6 is what this repo implements)
|
|
48
|
+
- [Design, feasibility and cost study](docs/study.md) — chain survey, build routes, costs, risks
|
|
49
|
+
|
|
50
|
+
## Demo
|
|
51
|
+
|
|
52
|
+

|
|
53
|
+
|
|
54
|
+
[Two-minute narrated walkthrough (MP4)](demo/video/foliant-demo-voiced.mp4) of the first four scenarios, by the author (scenario E, the crew, was added afterwards and is not in the recording).
|
|
55
|
+
|
|
56
|
+
`python demo/make_video.py` regenerates the captioned video, GIF and voiceover script in `demo/video/`; pass the voiceover's section boundaries in seconds to re-time the captions.
|
|
57
|
+
|
|
58
|
+
## Run
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pip install -r requirements.txt
|
|
62
|
+
python demo/run_demo.py # five scenarios: channel, pool, policy, exit, crew; ~1 s
|
|
63
|
+
python demo/run_uses.py # six further uses: containment, insurable agent, abuse control,
|
|
64
|
+
# cross-company trade, delegated money, device fleet
|
|
65
|
+
pytest # 34 tests incl. property-based invariants
|
|
66
|
+
python sim/crosschain.py --quick # cross-ledger budget-tree simulation, smoke run
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Layout
|
|
70
|
+
|
|
71
|
+
| Path | Whitepaper | What it holds |
|
|
72
|
+
| --- | --- | --- |
|
|
73
|
+
| `foliant/crypto.py` | §2 principle 9 | Ed25519 keys, canonical hashing, `Signed` messages with a `scheme` tag for signature agility |
|
|
74
|
+
| `foliant/accounts.py` | §6.1-6.3a | `AgentAccount` (with `parent`), `Policy` (with `within`), `Attestation`, `AgentSigner` (the enclave side that refuses to sign outside policy) |
|
|
75
|
+
| `foliant/channels.py` | §6.4, §6.6 | `Channel`: monotonic signed updates, settle, close with timeout, streams |
|
|
76
|
+
| `foliant/pools.py` | §6.10 | `Pool`: shared deposit, per-member claims, batch settlement, unilateral exit, contest |
|
|
77
|
+
| `foliant/market.py` | §6.7, §6.11 | `ServiceOffer`, `Receipt`, `Contribution` and royalty cascade |
|
|
78
|
+
| `foliant/ledger.py` | §5 (state only) | In-memory ledger: envelopes, nonces, policy enforcement up the account tree, delegation and recall, escrow accounting |
|
|
79
|
+
| `foliant/agent.py` | SDK | Agent-side helper: builds envelopes and off-chain updates |
|
|
80
|
+
| `foliant/x402.py` | §6.5, §6.9 | `PaymentGate` (provider middleware, FastAPI) and `AgentHttpClient` (pays on 402) |
|
|
81
|
+
| `demo/` | | A metered API, the four-scenario demo and six further use-case scenarios |
|
|
82
|
+
| `tests/` | §10 | Invariants: conservation, bounds, replay, stale/forged updates, unilateral exit, policy windows, the budget tree |
|
|
83
|
+
| `sim/` | §12 open problems | Cross-ledger budget tree study: specification, simulation, results, two independent audits |
|
|
84
|
+
|
|
85
|
+
## The rule that matters
|
|
86
|
+
|
|
87
|
+
The spending policy bounds **committed** value. A deposit into a channel or
|
|
88
|
+
pool is the spend that the policy sees, on both the signer (enclave) side and
|
|
89
|
+
the ledger side, using the same `Policy.check`. Off-chain updates are bounded
|
|
90
|
+
by the deposit they draw on, so they need no further budget check; the signer
|
|
91
|
+
still enforces allow/deny lists, expiry and monotonic balances on every update.
|
|
92
|
+
This is what makes "the enclave refuses to sign" and "the chain refuses to
|
|
93
|
+
apply" the same decision.
|
|
94
|
+
|
|
95
|
+
Accounts form a tree. A signer may **delegate** a child account with a policy
|
|
96
|
+
no wider than its own and fund it; value leaving the tree is checked against,
|
|
97
|
+
and recorded in, every ancestor's policy, all or nothing, so no branch can
|
|
98
|
+
commit more than any ancestor allows even after a parent is tightened. Moves
|
|
99
|
+
inside the tree are not spends. Any ancestor's signer can set a descendant's
|
|
100
|
+
policy, rotate its signer or recall its funds. That is how an orchestrator
|
|
101
|
+
gives its crew a budget and takes it away without a human.
|
|
102
|
+
|
|
103
|
+
## What is not here
|
|
104
|
+
|
|
105
|
+
Fees, the paymaster and the zero-fee lane (§5); consensus, data availability
|
|
106
|
+
and checkpoints (§4-5); IBC (§7); governance and token issuance (§8-9). Those
|
|
107
|
+
are borrowed components and are specified in the whitepaper, not prototyped.
|
|
108
|
+
|
|
109
|
+
## Invariants tested
|
|
110
|
+
|
|
111
|
+
- Channel: payee receives exactly the highest signed balance; payer gets back the rest; escrow ends at zero; stale, forged and tampered updates are rejected; a close finalises after the timeout regardless of the payee; a payee beats a dishonest close with a newer update.
|
|
112
|
+
- Pool: coordinator receives exactly the sum of highest signed balances; every member can exit unilaterally with or without the coordinator; a stale exit is contested; a stale update in a batch is skipped, not fatal; supply is conserved.
|
|
113
|
+
- Policy: for any sequence of attempted spends, committed value in any window never exceeds `per_window_max`, and signer and ledger agree at every step; escalation co-signature lifts `per_tx_max`; nonces prevent replay; the owner rotates the signer and the old key is dead.
|
|
114
|
+
- Tree: a child policy wider than its parent is refused; over random trees and random spends, no subtree ever commits more than its root's cap and every ancestor's window equals its subtree's total; a tightened parent binds existing children at once; funding and recall are not spends; only the owner or an ancestor's signer administers a descendant.
|
|
115
|
+
- Attestation: only quotes from a trusted vendor, for the account's own signer key, are accepted; an offer can require a code hash.
|
|
116
|
+
- 402: terms are x402-shaped; replay and underpayment get a 402 with a reason; receipts are provider-signed; one `settle()` pays out many calls.
|
|
117
|
+
|
|
118
|
+
## Licence
|
|
119
|
+
|
|
120
|
+
Copyright 2026 Machine Quotient Ltd. Licensed under the [Apache License 2.0](LICENSE).
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Foliant — reference implementation (Python)
|
|
2
|
+
|
|
3
|
+
Executable specification of the Foliant protocol: budgets and settlement for
|
|
4
|
+
AI agent crews. Agent accounts with spending policies the agent's code cannot
|
|
5
|
+
bypass, arranged in a tree so a whole crew shares one bound, TEE-style attestation, payment channels and streams, Ark-style pooled
|
|
6
|
+
channels a whole crew pays through, HTTP 402 metering in the x402 wire format,
|
|
7
|
+
and the compute-and-data market objects (whitepaper §6).
|
|
8
|
+
|
|
9
|
+
Foliant is a protocol, not a chain: on-chain contracts, an x402 payment scheme
|
|
10
|
+
and an SDK, deployable on chains agents already use. First targets are Base and
|
|
11
|
+
Avalanche. The whitepaper also describes a sovereign chain the protocol could
|
|
12
|
+
grow into if adoption warrants it; that is a direction, not the product. §11a
|
|
13
|
+
of the whitepaper records the prior art (Tempo, the x402 batch-settlement
|
|
14
|
+
scheme and others) and what Foliant adds.
|
|
15
|
+
|
|
16
|
+
This is a **spec plus demo**, not a deployment. It runs in one process with an
|
|
17
|
+
in-memory ledger so the state machines and their invariants can be read,
|
|
18
|
+
changed and tested quickly. The Solidity port implements the same state
|
|
19
|
+
machines as contracts; the tests here become its conformance suite.
|
|
20
|
+
|
|
21
|
+
## Name
|
|
22
|
+
|
|
23
|
+
The project was called Concord until 28 September 2026; the name was changed to Foliant after a UK trade-mark search. Older links, issues and messages that say Concord refer to this project.
|
|
24
|
+
|
|
25
|
+
## Documents
|
|
26
|
+
|
|
27
|
+
- Website: [foliant.network](https://foliant.network) (served from `docs/` via GitHub Pages)
|
|
28
|
+
- [Whitepaper v0.1](docs/whitepaper.md) — the full design (§6 is what this repo implements)
|
|
29
|
+
- [Design, feasibility and cost study](docs/study.md) — chain survey, build routes, costs, risks
|
|
30
|
+
|
|
31
|
+
## Demo
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
[Two-minute narrated walkthrough (MP4)](demo/video/foliant-demo-voiced.mp4) of the first four scenarios, by the author (scenario E, the crew, was added afterwards and is not in the recording).
|
|
36
|
+
|
|
37
|
+
`python demo/make_video.py` regenerates the captioned video, GIF and voiceover script in `demo/video/`; pass the voiceover's section boundaries in seconds to re-time the captions.
|
|
38
|
+
|
|
39
|
+
## Run
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install -r requirements.txt
|
|
43
|
+
python demo/run_demo.py # five scenarios: channel, pool, policy, exit, crew; ~1 s
|
|
44
|
+
python demo/run_uses.py # six further uses: containment, insurable agent, abuse control,
|
|
45
|
+
# cross-company trade, delegated money, device fleet
|
|
46
|
+
pytest # 34 tests incl. property-based invariants
|
|
47
|
+
python sim/crosschain.py --quick # cross-ledger budget-tree simulation, smoke run
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Layout
|
|
51
|
+
|
|
52
|
+
| Path | Whitepaper | What it holds |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| `foliant/crypto.py` | §2 principle 9 | Ed25519 keys, canonical hashing, `Signed` messages with a `scheme` tag for signature agility |
|
|
55
|
+
| `foliant/accounts.py` | §6.1-6.3a | `AgentAccount` (with `parent`), `Policy` (with `within`), `Attestation`, `AgentSigner` (the enclave side that refuses to sign outside policy) |
|
|
56
|
+
| `foliant/channels.py` | §6.4, §6.6 | `Channel`: monotonic signed updates, settle, close with timeout, streams |
|
|
57
|
+
| `foliant/pools.py` | §6.10 | `Pool`: shared deposit, per-member claims, batch settlement, unilateral exit, contest |
|
|
58
|
+
| `foliant/market.py` | §6.7, §6.11 | `ServiceOffer`, `Receipt`, `Contribution` and royalty cascade |
|
|
59
|
+
| `foliant/ledger.py` | §5 (state only) | In-memory ledger: envelopes, nonces, policy enforcement up the account tree, delegation and recall, escrow accounting |
|
|
60
|
+
| `foliant/agent.py` | SDK | Agent-side helper: builds envelopes and off-chain updates |
|
|
61
|
+
| `foliant/x402.py` | §6.5, §6.9 | `PaymentGate` (provider middleware, FastAPI) and `AgentHttpClient` (pays on 402) |
|
|
62
|
+
| `demo/` | | A metered API, the four-scenario demo and six further use-case scenarios |
|
|
63
|
+
| `tests/` | §10 | Invariants: conservation, bounds, replay, stale/forged updates, unilateral exit, policy windows, the budget tree |
|
|
64
|
+
| `sim/` | §12 open problems | Cross-ledger budget tree study: specification, simulation, results, two independent audits |
|
|
65
|
+
|
|
66
|
+
## The rule that matters
|
|
67
|
+
|
|
68
|
+
The spending policy bounds **committed** value. A deposit into a channel or
|
|
69
|
+
pool is the spend that the policy sees, on both the signer (enclave) side and
|
|
70
|
+
the ledger side, using the same `Policy.check`. Off-chain updates are bounded
|
|
71
|
+
by the deposit they draw on, so they need no further budget check; the signer
|
|
72
|
+
still enforces allow/deny lists, expiry and monotonic balances on every update.
|
|
73
|
+
This is what makes "the enclave refuses to sign" and "the chain refuses to
|
|
74
|
+
apply" the same decision.
|
|
75
|
+
|
|
76
|
+
Accounts form a tree. A signer may **delegate** a child account with a policy
|
|
77
|
+
no wider than its own and fund it; value leaving the tree is checked against,
|
|
78
|
+
and recorded in, every ancestor's policy, all or nothing, so no branch can
|
|
79
|
+
commit more than any ancestor allows even after a parent is tightened. Moves
|
|
80
|
+
inside the tree are not spends. Any ancestor's signer can set a descendant's
|
|
81
|
+
policy, rotate its signer or recall its funds. That is how an orchestrator
|
|
82
|
+
gives its crew a budget and takes it away without a human.
|
|
83
|
+
|
|
84
|
+
## What is not here
|
|
85
|
+
|
|
86
|
+
Fees, the paymaster and the zero-fee lane (§5); consensus, data availability
|
|
87
|
+
and checkpoints (§4-5); IBC (§7); governance and token issuance (§8-9). Those
|
|
88
|
+
are borrowed components and are specified in the whitepaper, not prototyped.
|
|
89
|
+
|
|
90
|
+
## Invariants tested
|
|
91
|
+
|
|
92
|
+
- Channel: payee receives exactly the highest signed balance; payer gets back the rest; escrow ends at zero; stale, forged and tampered updates are rejected; a close finalises after the timeout regardless of the payee; a payee beats a dishonest close with a newer update.
|
|
93
|
+
- Pool: coordinator receives exactly the sum of highest signed balances; every member can exit unilaterally with or without the coordinator; a stale exit is contested; a stale update in a batch is skipped, not fatal; supply is conserved.
|
|
94
|
+
- Policy: for any sequence of attempted spends, committed value in any window never exceeds `per_window_max`, and signer and ledger agree at every step; escalation co-signature lifts `per_tx_max`; nonces prevent replay; the owner rotates the signer and the old key is dead.
|
|
95
|
+
- Tree: a child policy wider than its parent is refused; over random trees and random spends, no subtree ever commits more than its root's cap and every ancestor's window equals its subtree's total; a tightened parent binds existing children at once; funding and recall are not spends; only the owner or an ancestor's signer administers a descendant.
|
|
96
|
+
- Attestation: only quotes from a trusted vendor, for the account's own signer key, are accepted; an offer can require a code hash.
|
|
97
|
+
- 402: terms are x402-shaped; replay and underpayment get a 402 with a reason; receipts are provider-signed; one `settle()` pays out many calls.
|
|
98
|
+
|
|
99
|
+
## Licence
|
|
100
|
+
|
|
101
|
+
Copyright 2026 Machine Quotient Ltd. Licensed under the [Apache License 2.0](LICENSE).
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Foliant reference implementation (Python) — agent accounts, policies, channels, pools.
|
|
2
|
+
|
|
3
|
+
Executable specification for whitepaper §6; the Cosmos SDK port follows these
|
|
4
|
+
state machines one-to-one and reuses the tests in `tests/` as a conformance suite.
|
|
5
|
+
"""
|
|
6
|
+
from .accounts import AgentAccount, AgentSigner, Attestation, Policy
|
|
7
|
+
from .agent import Agent
|
|
8
|
+
from .channels import Channel
|
|
9
|
+
from .crypto import KeyPair, PublicKey, Signed, sign
|
|
10
|
+
from .ledger import Ledger
|
|
11
|
+
from .market import Contribution, Receipt, ServiceOffer, royalty_split
|
|
12
|
+
from .pools import Pool
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"Agent", "AgentAccount", "AgentSigner", "Attestation", "Channel", "Contribution",
|
|
16
|
+
"KeyPair", "Ledger", "Policy", "Pool", "PublicKey", "Receipt", "ServiceOffer",
|
|
17
|
+
"Signed", "royalty_split", "sign",
|
|
18
|
+
]
|