a2cn 0.3.3__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.
- a2cn-0.3.3/LICENSE +201 -0
- a2cn-0.3.3/MANIFEST.in +6 -0
- a2cn-0.3.3/PKG-INFO +129 -0
- a2cn-0.3.3/README.pypi.md +83 -0
- a2cn-0.3.3/a2cn/__init__.py +40 -0
- a2cn-0.3.3/a2cn/acts.py +130 -0
- a2cn-0.3.3/a2cn/client.py +423 -0
- a2cn-0.3.3/a2cn/crypto.py +556 -0
- a2cn-0.3.3/a2cn/did.py +422 -0
- a2cn-0.3.3/a2cn/errors.py +56 -0
- a2cn-0.3.3/a2cn/evidence.py +2359 -0
- a2cn-0.3.3/a2cn/fulfillment.py +261 -0
- a2cn-0.3.3/a2cn/invitation.py +294 -0
- a2cn-0.3.3/a2cn/line_items.py +306 -0
- a2cn-0.3.3/a2cn/messages.py +1087 -0
- a2cn-0.3.3/a2cn/record.py +891 -0
- a2cn-0.3.3/a2cn/server.py +1433 -0
- a2cn-0.3.3/a2cn/session.py +1800 -0
- a2cn-0.3.3/a2cn/session_store.py +217 -0
- a2cn-0.3.3/a2cn/verify.py +994 -0
- a2cn-0.3.3/a2cn/versions.py +30 -0
- a2cn-0.3.3/a2cn.egg-info/PKG-INFO +129 -0
- a2cn-0.3.3/a2cn.egg-info/SOURCES.txt +27 -0
- a2cn-0.3.3/a2cn.egg-info/dependency_links.txt +1 -0
- a2cn-0.3.3/a2cn.egg-info/entry_points.txt +2 -0
- a2cn-0.3.3/a2cn.egg-info/requires.txt +19 -0
- a2cn-0.3.3/a2cn.egg-info/top_level.txt +1 -0
- a2cn-0.3.3/pyproject.toml +75 -0
- a2cn-0.3.3/setup.cfg +4 -0
a2cn-0.3.3/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
a2cn-0.3.3/MANIFEST.in
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# The sdist carries the package, its metadata and the licence. The tests read
|
|
2
|
+
# the spec's vectors and schemas from the rest of the repository, so they run
|
|
3
|
+
# only from a checkout; README.md is the repository's page, with relative links,
|
|
4
|
+
# and PyPI shows README.pypi.md.
|
|
5
|
+
prune tests
|
|
6
|
+
exclude README.md
|
a2cn-0.3.3/PKG-INFO
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: a2cn
|
|
3
|
+
Version: 0.3.3
|
|
4
|
+
Summary: Reference implementation of A2CN, the open protocol for agent-to-agent B2B commercial negotiation
|
|
5
|
+
Author: Avinash Saraff, Christian Magorrian
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://a2cn.io
|
|
8
|
+
Project-URL: Source, https://github.com/A2CN-protocol/A2CN
|
|
9
|
+
Project-URL: Issues, https://github.com/A2CN-protocol/A2CN/issues
|
|
10
|
+
Project-URL: Discussions, https://github.com/A2CN-protocol/A2CN/discussions
|
|
11
|
+
Project-URL: Changelog, https://github.com/A2CN-protocol/A2CN/blob/main/CHANGELOG.md
|
|
12
|
+
Project-URL: Security policy, https://github.com/A2CN-protocol/A2CN/blob/main/SECURITY.md
|
|
13
|
+
Keywords: a2cn,agents,negotiation,b2b,procurement,protocol,did,signatures
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Office/Business
|
|
23
|
+
Classifier: Topic :: Security :: Cryptography
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: fastapi>=0.133.0
|
|
29
|
+
Requires-Dist: starlette>=1.3.1
|
|
30
|
+
Requires-Dist: uvicorn>=0.32
|
|
31
|
+
Requires-Dist: httpx<0.29,>=0.27
|
|
32
|
+
Requires-Dist: httpcore<2,>=1.0.9
|
|
33
|
+
Requires-Dist: PyJWT>=2.15.0
|
|
34
|
+
Requires-Dist: cryptography>=50.0.0
|
|
35
|
+
Requires-Dist: jcs<0.4,>=0.2.1
|
|
36
|
+
Requires-Dist: jsonschema>=4.26
|
|
37
|
+
Provides-Extra: mcp
|
|
38
|
+
Requires-Dist: mcp<2,>=1.30; extra == "mcp"
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: a2cn[mcp]; extra == "dev"
|
|
41
|
+
Requires-Dist: pytest>=9.0.3; extra == "dev"
|
|
42
|
+
Requires-Dist: pytest-asyncio>=1.3; extra == "dev"
|
|
43
|
+
Requires-Dist: python-multipart>=0.0.31; extra == "dev"
|
|
44
|
+
Requires-Dist: respx>=0.22; extra == "dev"
|
|
45
|
+
Dynamic: license-file
|
|
46
|
+
|
|
47
|
+
# a2cn
|
|
48
|
+
|
|
49
|
+
The Python reference implementation of [A2CN](https://a2cn.io), the open
|
|
50
|
+
protocol for agent-to-agent B2B commercial negotiation: signed offers,
|
|
51
|
+
counteroffers and acceptances between two parties' agents, and a transaction
|
|
52
|
+
record that both sides can verify on their own.
|
|
53
|
+
|
|
54
|
+
- Specification: [spec/](https://github.com/A2CN-protocol/A2CN/tree/main/spec)
|
|
55
|
+
- Source: [reference-implementation/python](https://github.com/A2CN-protocol/A2CN/tree/main/reference-implementation/python)
|
|
56
|
+
- Changelog: [CHANGELOG.md](https://github.com/A2CN-protocol/A2CN/blob/main/CHANGELOG.md)
|
|
57
|
+
- Security policy: [SECURITY.md](https://github.com/A2CN-protocol/A2CN/blob/main/SECURITY.md)
|
|
58
|
+
|
|
59
|
+
**Status:** pre-1.0, and the specification is a draft. A minor (0.x) release
|
|
60
|
+
may change the API, the wire protocol or a record format; the
|
|
61
|
+
[CHANGELOG](https://github.com/A2CN-protocol/A2CN/blob/main/CHANGELOG.md) says
|
|
62
|
+
what changed. Security fixes go to the latest 0.3.x release, as the
|
|
63
|
+
[security policy](https://github.com/A2CN-protocol/A2CN/blob/main/SECURITY.md)
|
|
64
|
+
describes.
|
|
65
|
+
|
|
66
|
+
## Install
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install a2cn
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Requires Python 3.11 or later.
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
import a2cn
|
|
76
|
+
|
|
77
|
+
print(a2cn.__version__, a2cn.PROTOCOL_VERSIONS)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The library lives in the `a2cn` package's modules: `a2cn.client` and
|
|
81
|
+
`a2cn.server` for the HTTP client and server, `a2cn.record` and
|
|
82
|
+
`a2cn.evidence` for the transaction and evidence records, `a2cn.crypto` for
|
|
83
|
+
signing and verification, and `a2cn.did` for DID resolution. The
|
|
84
|
+
[repository README](https://github.com/A2CN-protocol/A2CN/blob/main/reference-implementation/python/README.md)
|
|
85
|
+
walks through the demos and the architecture.
|
|
86
|
+
|
|
87
|
+
## Verify a record
|
|
88
|
+
|
|
89
|
+
Installing the package installs `a2cn-verify`. Put a deal's TransactionRecord
|
|
90
|
+
and its session's evidence record in one folder, and point the verifier at it:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
a2cn-verify deal/ # or: python -m a2cn.verify deal/
|
|
94
|
+
a2cn-verify deal/ --offline # fetch nothing; use DID documents saved in the folder
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
It verifies each record with the library's own checks and fetches the parties'
|
|
98
|
+
DID documents from their sites (a did:web DID is its own address). For every
|
|
99
|
+
record it prints `VERIFIED`, `REFUSED:` with the reason, or `COULD NOT FINISH`
|
|
100
|
+
with what is missing. Exit status: 0 everything verified, 1 something was
|
|
101
|
+
refused, 3 nothing was refused but something could not finish, 2 bad usage.
|
|
102
|
+
`a2cn-verify --help` lists every option.
|
|
103
|
+
|
|
104
|
+
## MCP server
|
|
105
|
+
|
|
106
|
+
The MCP server (`mcp_server.py`) is not part of this package. Run it from a
|
|
107
|
+
source checkout with the `mcp` extra:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
git clone https://github.com/A2CN-protocol/A2CN.git
|
|
111
|
+
cd A2CN/reference-implementation/python
|
|
112
|
+
pip install -e '.[mcp]'
|
|
113
|
+
python mcp_server.py
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Questions, bugs and security
|
|
117
|
+
|
|
118
|
+
- **Questions and ideas** go in
|
|
119
|
+
[GitHub Discussions](https://github.com/A2CN-protocol/A2CN/discussions).
|
|
120
|
+
- **Bugs** go in [GitHub Issues](https://github.com/A2CN-protocol/A2CN/issues).
|
|
121
|
+
Include the package version (`a2cn.__version__`), your Python version, and how
|
|
122
|
+
you installed the package (from PyPI or from a source checkout).
|
|
123
|
+
- **Security vulnerabilities** never go in a public issue. Report them
|
|
124
|
+
privately, as [SECURITY.md](https://github.com/A2CN-protocol/A2CN/blob/main/SECURITY.md)
|
|
125
|
+
describes.
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
Apache-2.0. See [LICENSE](https://github.com/A2CN-protocol/A2CN/blob/main/LICENSE).
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# a2cn
|
|
2
|
+
|
|
3
|
+
The Python reference implementation of [A2CN](https://a2cn.io), the open
|
|
4
|
+
protocol for agent-to-agent B2B commercial negotiation: signed offers,
|
|
5
|
+
counteroffers and acceptances between two parties' agents, and a transaction
|
|
6
|
+
record that both sides can verify on their own.
|
|
7
|
+
|
|
8
|
+
- Specification: [spec/](https://github.com/A2CN-protocol/A2CN/tree/main/spec)
|
|
9
|
+
- Source: [reference-implementation/python](https://github.com/A2CN-protocol/A2CN/tree/main/reference-implementation/python)
|
|
10
|
+
- Changelog: [CHANGELOG.md](https://github.com/A2CN-protocol/A2CN/blob/main/CHANGELOG.md)
|
|
11
|
+
- Security policy: [SECURITY.md](https://github.com/A2CN-protocol/A2CN/blob/main/SECURITY.md)
|
|
12
|
+
|
|
13
|
+
**Status:** pre-1.0, and the specification is a draft. A minor (0.x) release
|
|
14
|
+
may change the API, the wire protocol or a record format; the
|
|
15
|
+
[CHANGELOG](https://github.com/A2CN-protocol/A2CN/blob/main/CHANGELOG.md) says
|
|
16
|
+
what changed. Security fixes go to the latest 0.3.x release, as the
|
|
17
|
+
[security policy](https://github.com/A2CN-protocol/A2CN/blob/main/SECURITY.md)
|
|
18
|
+
describes.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install a2cn
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Requires Python 3.11 or later.
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import a2cn
|
|
30
|
+
|
|
31
|
+
print(a2cn.__version__, a2cn.PROTOCOL_VERSIONS)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The library lives in the `a2cn` package's modules: `a2cn.client` and
|
|
35
|
+
`a2cn.server` for the HTTP client and server, `a2cn.record` and
|
|
36
|
+
`a2cn.evidence` for the transaction and evidence records, `a2cn.crypto` for
|
|
37
|
+
signing and verification, and `a2cn.did` for DID resolution. The
|
|
38
|
+
[repository README](https://github.com/A2CN-protocol/A2CN/blob/main/reference-implementation/python/README.md)
|
|
39
|
+
walks through the demos and the architecture.
|
|
40
|
+
|
|
41
|
+
## Verify a record
|
|
42
|
+
|
|
43
|
+
Installing the package installs `a2cn-verify`. Put a deal's TransactionRecord
|
|
44
|
+
and its session's evidence record in one folder, and point the verifier at it:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
a2cn-verify deal/ # or: python -m a2cn.verify deal/
|
|
48
|
+
a2cn-verify deal/ --offline # fetch nothing; use DID documents saved in the folder
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
It verifies each record with the library's own checks and fetches the parties'
|
|
52
|
+
DID documents from their sites (a did:web DID is its own address). For every
|
|
53
|
+
record it prints `VERIFIED`, `REFUSED:` with the reason, or `COULD NOT FINISH`
|
|
54
|
+
with what is missing. Exit status: 0 everything verified, 1 something was
|
|
55
|
+
refused, 3 nothing was refused but something could not finish, 2 bad usage.
|
|
56
|
+
`a2cn-verify --help` lists every option.
|
|
57
|
+
|
|
58
|
+
## MCP server
|
|
59
|
+
|
|
60
|
+
The MCP server (`mcp_server.py`) is not part of this package. Run it from a
|
|
61
|
+
source checkout with the `mcp` extra:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
git clone https://github.com/A2CN-protocol/A2CN.git
|
|
65
|
+
cd A2CN/reference-implementation/python
|
|
66
|
+
pip install -e '.[mcp]'
|
|
67
|
+
python mcp_server.py
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Questions, bugs and security
|
|
71
|
+
|
|
72
|
+
- **Questions and ideas** go in
|
|
73
|
+
[GitHub Discussions](https://github.com/A2CN-protocol/A2CN/discussions).
|
|
74
|
+
- **Bugs** go in [GitHub Issues](https://github.com/A2CN-protocol/A2CN/issues).
|
|
75
|
+
Include the package version (`a2cn.__version__`), your Python version, and how
|
|
76
|
+
you installed the package (from PyPI or from a source checkout).
|
|
77
|
+
- **Security vulnerabilities** never go in a public issue. Report them
|
|
78
|
+
privately, as [SECURITY.md](https://github.com/A2CN-protocol/A2CN/blob/main/SECURITY.md)
|
|
79
|
+
describes.
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
Apache-2.0. See [LICENSE](https://github.com/A2CN-protocol/A2CN/blob/main/LICENSE).
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""A2CN reference implementation."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from importlib.metadata import PackageNotFoundError, distribution
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from urllib.parse import urlparse
|
|
7
|
+
from urllib.request import url2pathname
|
|
8
|
+
|
|
9
|
+
_SOURCE_VERSION = "0.0.0+source"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _installed_version() -> str:
|
|
13
|
+
"""The version of the installed distribution that owns this source tree.
|
|
14
|
+
|
|
15
|
+
Another distribution named ``a2cn`` may be installed while Python imports a
|
|
16
|
+
different tree, so its version is reported only when that distribution's
|
|
17
|
+
files, or its editable install root, are the tree imported here.
|
|
18
|
+
"""
|
|
19
|
+
try:
|
|
20
|
+
dist = distribution("a2cn")
|
|
21
|
+
except PackageNotFoundError:
|
|
22
|
+
return _SOURCE_VERSION
|
|
23
|
+
here = Path(__file__).resolve()
|
|
24
|
+
if Path(dist.locate_file("a2cn/__init__.py")).resolve() == here:
|
|
25
|
+
return dist.version
|
|
26
|
+
direct_url = dist.read_text("direct_url.json")
|
|
27
|
+
if direct_url:
|
|
28
|
+
info = json.loads(direct_url)
|
|
29
|
+
url = urlparse(info.get("url", ""))
|
|
30
|
+
if info.get("dir_info", {}).get("editable") and url.scheme == "file":
|
|
31
|
+
if Path(url2pathname(url.path)).resolve() == here.parent.parent:
|
|
32
|
+
return dist.version
|
|
33
|
+
return _SOURCE_VERSION
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
__version__ = _installed_version()
|
|
37
|
+
|
|
38
|
+
from a2cn.versions import PROTOCOL_VERSIONS # noqa: E402
|
|
39
|
+
|
|
40
|
+
__all__ = ["PROTOCOL_VERSIONS", "__version__"]
|
a2cn-0.3.3/a2cn/acts.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""Verify one signed act on its own (Sections 7.3 to 7.6).
|
|
2
|
+
|
|
3
|
+
A record verifier checks the acts inside a record; this checks a single act an
|
|
4
|
+
auditor holds by itself: an offer, counteroffer, acceptance, rejection or
|
|
5
|
+
withdrawal. It rebuilds the object the act's signature covers with the same
|
|
6
|
+
primitive the records use (``rebuild_signed_act``, Section 7.3.1), requires the
|
|
7
|
+
signing method to be under the sender's DID, and verifies the signature against
|
|
8
|
+
the key that DID document lists for it. For an offer or counteroffer the act's
|
|
9
|
+
stated ``protocol_act_hash`` must also equal the rebuilt hash (Section 7.3.2).
|
|
10
|
+
|
|
11
|
+
A verified act proves who signed which terms. It says nothing about the session
|
|
12
|
+
around it: whether the act was in turn, in time, or ever accepted.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from collections.abc import Callable, Mapping
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
from jwt.exceptions import InvalidSignatureError
|
|
21
|
+
|
|
22
|
+
from a2cn.crypto import hash_object, verify_jws
|
|
23
|
+
from a2cn.did import (
|
|
24
|
+
VerificationMethodNotFoundError,
|
|
25
|
+
get_public_key,
|
|
26
|
+
get_verification_method,
|
|
27
|
+
require_did_document_for,
|
|
28
|
+
)
|
|
29
|
+
from a2cn.messages import SIGNED_ACT_SIGNATURE_FIELDS, SUPPORTED_WIRE_VERSIONS, rebuild_signed_act
|
|
30
|
+
|
|
31
|
+
DidResolver = Mapping[str, dict] | Callable[[str], dict]
|
|
32
|
+
|
|
33
|
+
#: The act types this verifies: every act that carries its own signature.
|
|
34
|
+
SIGNED_ACT_TYPES = tuple(SIGNED_ACT_SIGNATURE_FIELDS)
|
|
35
|
+
|
|
36
|
+
# Why an act does not verify. verify_signed_act_reason returns one of these, or
|
|
37
|
+
# None when the act verifies.
|
|
38
|
+
ACT_REASON_UNSUPPORTED_TYPE = "UNSUPPORTED_ACT_TYPE"
|
|
39
|
+
ACT_REASON_VERSION_UNSTATED = "WIRE_VERSION_UNSTATED"
|
|
40
|
+
ACT_REASON_NOT_RECOMPUTABLE = "ACT_NOT_RECOMPUTABLE"
|
|
41
|
+
ACT_REASON_HASH_MISMATCH = "PROTOCOL_ACT_HASH_MISMATCH"
|
|
42
|
+
ACT_REASON_SIGNATURE_MISSING = "SIGNATURE_MISSING"
|
|
43
|
+
ACT_REASON_METHOD_NOT_CONTROLLED = "VERIFICATION_METHOD_NOT_CONTROLLED"
|
|
44
|
+
ACT_REASON_KEY_NOT_FOUND = "KEY_NOT_FOUND"
|
|
45
|
+
ACT_REASON_KEY_UNUSABLE = "VERIFICATION_METHOD_UNUSABLE"
|
|
46
|
+
ACT_REASON_SIGNATURE_INVALID = "SIGNATURE_INVALID"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def verify_signed_act_reason(
|
|
50
|
+
act: Any,
|
|
51
|
+
did_resolver: DidResolver,
|
|
52
|
+
*,
|
|
53
|
+
wire_version: str | None = None,
|
|
54
|
+
) -> str | None:
|
|
55
|
+
"""Why ``act`` does not verify, or None when its signature does.
|
|
56
|
+
|
|
57
|
+
``wire_version`` stands in for a ``protocol_version`` the act does not state.
|
|
58
|
+
An act received inside a session states none and is rebuilt under the
|
|
59
|
+
session's negotiated version (Section 7.3.1); held on its own, nothing says
|
|
60
|
+
which version that was, so the caller must say. An act that states its
|
|
61
|
+
version is always rebuilt under it, and ``wire_version`` is then ignored.
|
|
62
|
+
"""
|
|
63
|
+
if not isinstance(act, Mapping) or act.get("message_type") not in SIGNED_ACT_SIGNATURE_FIELDS:
|
|
64
|
+
return ACT_REASON_UNSUPPORTED_TYPE
|
|
65
|
+
if "protocol_version" not in act and wire_version not in SUPPORTED_WIRE_VERSIONS:
|
|
66
|
+
return ACT_REASON_VERSION_UNSTATED
|
|
67
|
+
|
|
68
|
+
rebuilt = rebuild_signed_act(act, version_when_absent=wire_version or "")
|
|
69
|
+
if rebuilt is None:
|
|
70
|
+
return ACT_REASON_NOT_RECOMPUTABLE
|
|
71
|
+
try:
|
|
72
|
+
expected_hash = hash_object(rebuilt)
|
|
73
|
+
except ValueError:
|
|
74
|
+
# A string with no UTF-8 encoding (a lone surrogate) cannot be
|
|
75
|
+
# canonicalized (RFC 8785): the act cannot be recomputed.
|
|
76
|
+
return ACT_REASON_NOT_RECOMPUTABLE
|
|
77
|
+
if act["message_type"] in ("offer", "counteroffer") and act.get("protocol_act_hash") != expected_hash:
|
|
78
|
+
return ACT_REASON_HASH_MISMATCH
|
|
79
|
+
|
|
80
|
+
signature = act.get(SIGNED_ACT_SIGNATURE_FIELDS[act["message_type"]])
|
|
81
|
+
verification_method = act.get("sender_verification_method")
|
|
82
|
+
sender_did = act.get("sender_did")
|
|
83
|
+
if not (isinstance(signature, str) and signature) or not (
|
|
84
|
+
isinstance(verification_method, str) and verification_method
|
|
85
|
+
):
|
|
86
|
+
return ACT_REASON_SIGNATURE_MISSING
|
|
87
|
+
if not (
|
|
88
|
+
isinstance(sender_did, str)
|
|
89
|
+
and sender_did
|
|
90
|
+
and (verification_method == sender_did or verification_method.startswith(f"{sender_did}#"))
|
|
91
|
+
):
|
|
92
|
+
return ACT_REASON_METHOD_NOT_CONTROLLED
|
|
93
|
+
|
|
94
|
+
try:
|
|
95
|
+
did_document = require_did_document_for(
|
|
96
|
+
did_resolver(sender_did) if callable(did_resolver) else did_resolver[sender_did],
|
|
97
|
+
sender_did,
|
|
98
|
+
)
|
|
99
|
+
except Exception:
|
|
100
|
+
# A DID document the resolver cannot supply is a key that is not
|
|
101
|
+
# available, exactly like one the document does not list; so is a
|
|
102
|
+
# document whose id is not sender_did (Section 4.2).
|
|
103
|
+
return ACT_REASON_KEY_NOT_FOUND
|
|
104
|
+
try:
|
|
105
|
+
method = get_verification_method(did_document, verification_method)
|
|
106
|
+
except VerificationMethodNotFoundError:
|
|
107
|
+
# The document does not list this key: rotated, or never published. The
|
|
108
|
+
# signature cannot be checked either way, which is not a refusal.
|
|
109
|
+
return ACT_REASON_KEY_NOT_FOUND
|
|
110
|
+
except Exception:
|
|
111
|
+
return ACT_REASON_KEY_UNUSABLE
|
|
112
|
+
try:
|
|
113
|
+
public_key = get_public_key(method)
|
|
114
|
+
except Exception:
|
|
115
|
+
# Listed but unreadable (a coordinate that is not unpadded base64url,
|
|
116
|
+
# an unsupported type): the key is not available, as when unlisted.
|
|
117
|
+
return ACT_REASON_KEY_NOT_FOUND
|
|
118
|
+
try:
|
|
119
|
+
signed_payload = verify_jws(signature, public_key)
|
|
120
|
+
except (InvalidSignatureError, ValueError):
|
|
121
|
+
# A signature that does not verify, or bytes that are not a JWS at all.
|
|
122
|
+
return ACT_REASON_SIGNATURE_INVALID
|
|
123
|
+
if signed_payload != expected_hash:
|
|
124
|
+
return ACT_REASON_SIGNATURE_INVALID
|
|
125
|
+
return None
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def verify_signed_act(act: Any, did_resolver: DidResolver, *, wire_version: str | None = None) -> bool:
|
|
129
|
+
"""Whether ``act``'s signature verifies; ``verify_signed_act_reason`` says why not."""
|
|
130
|
+
return verify_signed_act_reason(act, did_resolver, wire_version=wire_version) is None
|