a2a-protocol-core 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.
- a2a_protocol_core-0.1.0/.gitignore +6 -0
- a2a_protocol_core-0.1.0/CHANGELOG.md +24 -0
- a2a_protocol_core-0.1.0/LICENSE +201 -0
- a2a_protocol_core-0.1.0/PKG-INFO +111 -0
- a2a_protocol_core-0.1.0/README.md +87 -0
- a2a_protocol_core-0.1.0/examples/trigger_payment_hook.py +49 -0
- a2a_protocol_core-0.1.0/pyproject.toml +62 -0
- a2a_protocol_core-0.1.0/src/a2a_protocol_core/__init__.py +62 -0
- a2a_protocol_core-0.1.0/src/a2a_protocol_core/addressing.py +29 -0
- a2a_protocol_core-0.1.0/src/a2a_protocol_core/canonical_hash.py +79 -0
- a2a_protocol_core-0.1.0/src/a2a_protocol_core/client.py +104 -0
- a2a_protocol_core-0.1.0/src/a2a_protocol_core/py.typed +0 -0
- a2a_protocol_core-0.1.0/src/a2a_protocol_core/schemas.py +72 -0
- a2a_protocol_core-0.1.0/src/a2a_protocol_core/semantic_normalizer.py +75 -0
- a2a_protocol_core-0.1.0/tests/test_addressing.py +36 -0
- a2a_protocol_core-0.1.0/tests/test_canonical_hash.py +37 -0
- a2a_protocol_core-0.1.0/tests/test_schemas.py +50 -0
- a2a_protocol_core-0.1.0/tests/test_semantic_normalizer.py +43 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `a2a-protocol-core` are documented here. This project
|
|
4
|
+
adheres to [Semantic Versioning](https://semver.org/).
|
|
5
|
+
|
|
6
|
+
## [0.1.0] — Unreleased
|
|
7
|
+
|
|
8
|
+
Initial public protocol-core extraction from the DNS of Money Financial
|
|
9
|
+
Autonomy Stack.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- `pay:` URI addressing (FAS-1 grammar): `is_valid_pay_uri`, `assert_valid_pay_uri`,
|
|
13
|
+
`PAY_URI_PATTERN`.
|
|
14
|
+
- A2A-009 semantic normalizer: `normalize_action`, `normalize_message`,
|
|
15
|
+
`compute_semantic_hash`, `SYNONYM_MAP`, `CANONICAL_ACTIONS`.
|
|
16
|
+
- A2A-008 canonical hashing: `compute_canonical_hash` — metadata-stable,
|
|
17
|
+
vocabulary-stable payment-intent hashing.
|
|
18
|
+
- A2A-041 wire schemas: `A2APaymentHookRequest`, `A2APaymentHookResponse`,
|
|
19
|
+
`ResolutionDetail`, `SettlementDetail`, `A2ACapabilities`.
|
|
20
|
+
- `A2APaymentHookClient` — synchronous payment-hook + capabilities client with
|
|
21
|
+
client-side validation.
|
|
22
|
+
- Test suite covering addressing, normalization, canonical hashing, and schema
|
|
23
|
+
validation.
|
|
24
|
+
- Apache-2.0 license, `py.typed` marker, runnable example.
|
|
@@ -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 2026 DNS of Money
|
|
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.
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: a2a-protocol-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Open, deterministic protocol core for the DNS of Money A2A payment surface (FAS-1 pay: addressing, canonical hashing, payment-hook client).
|
|
5
|
+
Project-URL: Homepage, https://dnsofmoney.com
|
|
6
|
+
Project-URL: Specification, https://github.com/dnsofmoney/dns-of-money
|
|
7
|
+
Project-URL: Source, https://github.com/dnsofmoney/a2a-protocol-core
|
|
8
|
+
Author: DNS of Money
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: a2a,ai-agents,fas-1,iso20022,pay-uri,payments,xrpl
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Requires-Dist: pydantic>=2.10.0
|
|
19
|
+
Requires-Dist: requests>=2.31.0
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=8.3.0; extra == 'dev'
|
|
22
|
+
Requires-Dist: ruff>=0.8.0; extra == 'dev'
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# a2a-protocol-core
|
|
26
|
+
|
|
27
|
+
[](LICENSE)
|
|
28
|
+
|
|
29
|
+
The open, **deterministic** protocol core of the [DNS of Money](https://dnsofmoney.com)
|
|
30
|
+
agent-to-agent (A2A) payment surface — the dependency-light layer external AI
|
|
31
|
+
agents adopt to resolve, hash, and initiate `pay:` payments.
|
|
32
|
+
|
|
33
|
+
> The intelligence lives in the **calling agent**. This package serves
|
|
34
|
+
> deterministic, inspectable primitives — no rail selection, no scoring, no
|
|
35
|
+
> model anywhere in the money path.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install a2a-protocol-core
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Runtime deps are intentionally minimal: `pydantic` and `requests`.
|
|
44
|
+
|
|
45
|
+
## What's in here
|
|
46
|
+
|
|
47
|
+
| Module | A2A ref | Purpose |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| `addressing` | FAS-1 | `pay:` URI grammar + validation (`is_valid_pay_uri`) |
|
|
50
|
+
| `semantic_normalizer` | A2A-009 | collapse synonym verbs → canonical action codes |
|
|
51
|
+
| `canonical_hash` | A2A-008 | metadata- & vocabulary-stable payment-intent hash |
|
|
52
|
+
| `schemas` | A2A-041 | payment-hook request/response wire models |
|
|
53
|
+
| `client` | A2A-041 | `A2APaymentHookClient` over `/v1/a2a/*` |
|
|
54
|
+
|
|
55
|
+
## Quick start
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from a2a_protocol_core import (
|
|
59
|
+
A2APaymentHookClient,
|
|
60
|
+
compute_canonical_hash,
|
|
61
|
+
normalize_message,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
# Your agent describes intent however it likes...
|
|
65
|
+
intent = {"action": "send", "amount": "2.50", "currency": "USD", "alias": "pay:agent.compute"}
|
|
66
|
+
|
|
67
|
+
# ...which collapses to a stable hash regardless of wording ("send" == "transfer" == "pay").
|
|
68
|
+
semantic_hash = compute_canonical_hash(normalize_message(intent))
|
|
69
|
+
|
|
70
|
+
client = A2APaymentHookClient(base_url="https://api.dnsofmoney.com")
|
|
71
|
+
result = client.trigger(
|
|
72
|
+
job_id="job-001",
|
|
73
|
+
provider_pay_address="pay:agent.compute",
|
|
74
|
+
requester_pay_address="pay:vendor.alpha",
|
|
75
|
+
amount="2.50",
|
|
76
|
+
currency="USD",
|
|
77
|
+
semantic_hash=semantic_hash,
|
|
78
|
+
)
|
|
79
|
+
print(result.settlement_result.status, result.iso_message_ref)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
See [`examples/trigger_payment_hook.py`](examples/trigger_payment_hook.py).
|
|
83
|
+
|
|
84
|
+
## Why canonical hashing?
|
|
85
|
+
|
|
86
|
+
Two agents describing the same payment with different words ("send" vs
|
|
87
|
+
"transfer") or different session/trace metadata must produce the **same**
|
|
88
|
+
intent fingerprint. `compute_canonical_hash` excludes non-semantic noise
|
|
89
|
+
(session/request/trace ids, timestamps, idempotency keys, memos) and
|
|
90
|
+
normalizes the action verb, so the hash captures *what* is being paid — not
|
|
91
|
+
*how it was phrased*. That fingerprint binds an agent's intent to a settlement
|
|
92
|
+
without trusting free text.
|
|
93
|
+
|
|
94
|
+
## Design constraints
|
|
95
|
+
|
|
96
|
+
- **Deterministic only.** Nothing here selects or scores a rail.
|
|
97
|
+
- **Off the money path.** The hash and client describe and carry intent; the
|
|
98
|
+
deterministic core (server-side) resolves, generates ISO 20022, and settles.
|
|
99
|
+
- **Dependency-light.** Safe to embed in an agent runtime.
|
|
100
|
+
|
|
101
|
+
## Development
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
pip install -e ".[dev]"
|
|
105
|
+
pytest
|
|
106
|
+
ruff check src tests
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## License
|
|
110
|
+
|
|
111
|
+
Apache-2.0 — permissive with an explicit patent grant. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# a2a-protocol-core
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
|
|
5
|
+
The open, **deterministic** protocol core of the [DNS of Money](https://dnsofmoney.com)
|
|
6
|
+
agent-to-agent (A2A) payment surface — the dependency-light layer external AI
|
|
7
|
+
agents adopt to resolve, hash, and initiate `pay:` payments.
|
|
8
|
+
|
|
9
|
+
> The intelligence lives in the **calling agent**. This package serves
|
|
10
|
+
> deterministic, inspectable primitives — no rail selection, no scoring, no
|
|
11
|
+
> model anywhere in the money path.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install a2a-protocol-core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Runtime deps are intentionally minimal: `pydantic` and `requests`.
|
|
20
|
+
|
|
21
|
+
## What's in here
|
|
22
|
+
|
|
23
|
+
| Module | A2A ref | Purpose |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| `addressing` | FAS-1 | `pay:` URI grammar + validation (`is_valid_pay_uri`) |
|
|
26
|
+
| `semantic_normalizer` | A2A-009 | collapse synonym verbs → canonical action codes |
|
|
27
|
+
| `canonical_hash` | A2A-008 | metadata- & vocabulary-stable payment-intent hash |
|
|
28
|
+
| `schemas` | A2A-041 | payment-hook request/response wire models |
|
|
29
|
+
| `client` | A2A-041 | `A2APaymentHookClient` over `/v1/a2a/*` |
|
|
30
|
+
|
|
31
|
+
## Quick start
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from a2a_protocol_core import (
|
|
35
|
+
A2APaymentHookClient,
|
|
36
|
+
compute_canonical_hash,
|
|
37
|
+
normalize_message,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# Your agent describes intent however it likes...
|
|
41
|
+
intent = {"action": "send", "amount": "2.50", "currency": "USD", "alias": "pay:agent.compute"}
|
|
42
|
+
|
|
43
|
+
# ...which collapses to a stable hash regardless of wording ("send" == "transfer" == "pay").
|
|
44
|
+
semantic_hash = compute_canonical_hash(normalize_message(intent))
|
|
45
|
+
|
|
46
|
+
client = A2APaymentHookClient(base_url="https://api.dnsofmoney.com")
|
|
47
|
+
result = client.trigger(
|
|
48
|
+
job_id="job-001",
|
|
49
|
+
provider_pay_address="pay:agent.compute",
|
|
50
|
+
requester_pay_address="pay:vendor.alpha",
|
|
51
|
+
amount="2.50",
|
|
52
|
+
currency="USD",
|
|
53
|
+
semantic_hash=semantic_hash,
|
|
54
|
+
)
|
|
55
|
+
print(result.settlement_result.status, result.iso_message_ref)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
See [`examples/trigger_payment_hook.py`](examples/trigger_payment_hook.py).
|
|
59
|
+
|
|
60
|
+
## Why canonical hashing?
|
|
61
|
+
|
|
62
|
+
Two agents describing the same payment with different words ("send" vs
|
|
63
|
+
"transfer") or different session/trace metadata must produce the **same**
|
|
64
|
+
intent fingerprint. `compute_canonical_hash` excludes non-semantic noise
|
|
65
|
+
(session/request/trace ids, timestamps, idempotency keys, memos) and
|
|
66
|
+
normalizes the action verb, so the hash captures *what* is being paid — not
|
|
67
|
+
*how it was phrased*. That fingerprint binds an agent's intent to a settlement
|
|
68
|
+
without trusting free text.
|
|
69
|
+
|
|
70
|
+
## Design constraints
|
|
71
|
+
|
|
72
|
+
- **Deterministic only.** Nothing here selects or scores a rail.
|
|
73
|
+
- **Off the money path.** The hash and client describe and carry intent; the
|
|
74
|
+
deterministic core (server-side) resolves, generates ISO 20022, and settles.
|
|
75
|
+
- **Dependency-light.** Safe to embed in an agent runtime.
|
|
76
|
+
|
|
77
|
+
## Development
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install -e ".[dev]"
|
|
81
|
+
pytest
|
|
82
|
+
ruff check src tests
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
Apache-2.0 — permissive with an explicit patent grant. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Minimal example: fire an A2A-041 payment hook from a calling agent.
|
|
3
|
+
|
|
4
|
+
pip install a2a-protocol-core
|
|
5
|
+
python examples/trigger_payment_hook.py
|
|
6
|
+
|
|
7
|
+
The agent decides *what* to pay and *why*; a2a-protocol-core carries a
|
|
8
|
+
validated, deterministic request to the DNS of Money core and parses the
|
|
9
|
+
result. No rail selection or scoring happens here — that stays server-side
|
|
10
|
+
and deterministic.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from a2a_protocol_core import (
|
|
14
|
+
A2APaymentHookClient,
|
|
15
|
+
compute_canonical_hash,
|
|
16
|
+
normalize_message,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def main() -> None:
|
|
21
|
+
# 1. The calling agent describes its intent however it likes...
|
|
22
|
+
intent = {
|
|
23
|
+
"action": "send", # synonym of EXECUTE_PAYMENT
|
|
24
|
+
"amount": "2.50",
|
|
25
|
+
"currency": "USD",
|
|
26
|
+
"alias": "pay:agent.compute",
|
|
27
|
+
}
|
|
28
|
+
# 2. ...which normalizes to a stable canonical hash regardless of vocabulary.
|
|
29
|
+
semantic_hash = compute_canonical_hash(normalize_message(intent))
|
|
30
|
+
|
|
31
|
+
# 3. Fire the hook against a running DNS of Money node.
|
|
32
|
+
client = A2APaymentHookClient(base_url="https://api.dnsofmoney.com")
|
|
33
|
+
|
|
34
|
+
print("capabilities:", client.capabilities())
|
|
35
|
+
|
|
36
|
+
result = client.trigger(
|
|
37
|
+
job_id="job-demo-001",
|
|
38
|
+
provider_pay_address="pay:agent.compute",
|
|
39
|
+
requester_pay_address="pay:vendor.alpha",
|
|
40
|
+
amount="2.50",
|
|
41
|
+
currency="USD",
|
|
42
|
+
semantic_hash=semantic_hash,
|
|
43
|
+
)
|
|
44
|
+
print("settlement:", result.settlement_result.status, result.settlement_result.rail)
|
|
45
|
+
print("iso ref:", result.iso_message_ref)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if __name__ == "__main__":
|
|
49
|
+
main()
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "a2a-protocol-core"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Open, deterministic protocol core for the DNS of Money A2A payment surface (FAS-1 pay: addressing, canonical hashing, payment-hook client)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "DNS of Money" }]
|
|
14
|
+
keywords = ["a2a", "payments", "ai-agents", "fas-1", "iso20022", "pay-uri", "xrpl"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: Apache Software License",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Topic :: Office/Business :: Financial",
|
|
21
|
+
]
|
|
22
|
+
dependencies = [
|
|
23
|
+
"pydantic>=2.10.0",
|
|
24
|
+
"requests>=2.31.0",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://dnsofmoney.com"
|
|
29
|
+
Specification = "https://github.com/dnsofmoney/dns-of-money"
|
|
30
|
+
Source = "https://github.com/dnsofmoney/a2a-protocol-core"
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = [
|
|
34
|
+
"pytest>=8.3.0",
|
|
35
|
+
"ruff>=0.8.0",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[tool.hatch.build.targets.wheel]
|
|
39
|
+
packages = ["src/a2a_protocol_core"]
|
|
40
|
+
|
|
41
|
+
# Explicit allowlist so a manual sdist build in a dirty working dir can never
|
|
42
|
+
# sweep in stray untracked files (e.g. a local venv). CI builds from a clean
|
|
43
|
+
# checkout, but this keeps hand-built sdists deterministic too.
|
|
44
|
+
[tool.hatch.build.targets.sdist]
|
|
45
|
+
include = [
|
|
46
|
+
"src/",
|
|
47
|
+
"tests/",
|
|
48
|
+
"examples/",
|
|
49
|
+
"README.md",
|
|
50
|
+
"CHANGELOG.md",
|
|
51
|
+
"LICENSE",
|
|
52
|
+
"pyproject.toml",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[tool.pytest.ini_options]
|
|
56
|
+
testpaths = ["tests"]
|
|
57
|
+
python_files = ["test_*.py"]
|
|
58
|
+
python_functions = ["test_*"]
|
|
59
|
+
|
|
60
|
+
[tool.ruff]
|
|
61
|
+
target-version = "py310"
|
|
62
|
+
line-length = 120
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""
|
|
2
|
+
a2a-protocol-core — the open, deterministic core of the DNS of Money A2A surface.
|
|
3
|
+
|
|
4
|
+
What lives here is the dependency-light, verifiable protocol layer that external
|
|
5
|
+
AI agents adopt: the ``pay:`` address grammar, the canonical/semantic hashing
|
|
6
|
+
used to make payment intent stable across vocabularies, the A2A-041 wire schemas,
|
|
7
|
+
and a thin payment-hook client.
|
|
8
|
+
|
|
9
|
+
The intelligence lives in the calling agent. This package serves deterministic,
|
|
10
|
+
inspectable primitives — no rail selection, no scoring, no model in the path.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from a2a_protocol_core.addressing import (
|
|
16
|
+
MAX_PAY_URI_LENGTH,
|
|
17
|
+
PAY_URI_PATTERN,
|
|
18
|
+
assert_valid_pay_uri,
|
|
19
|
+
is_valid_pay_uri,
|
|
20
|
+
)
|
|
21
|
+
from a2a_protocol_core.canonical_hash import compute_canonical_hash
|
|
22
|
+
from a2a_protocol_core.client import A2APaymentHookClient
|
|
23
|
+
from a2a_protocol_core.schemas import (
|
|
24
|
+
A2ACapabilities,
|
|
25
|
+
A2APaymentHookRequest,
|
|
26
|
+
A2APaymentHookResponse,
|
|
27
|
+
ResolutionDetail,
|
|
28
|
+
SettlementDetail,
|
|
29
|
+
)
|
|
30
|
+
from a2a_protocol_core.semantic_normalizer import (
|
|
31
|
+
CANONICAL_ACTIONS,
|
|
32
|
+
SYNONYM_MAP,
|
|
33
|
+
compute_semantic_hash,
|
|
34
|
+
normalize_action,
|
|
35
|
+
normalize_message,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
__version__ = "0.1.0"
|
|
39
|
+
|
|
40
|
+
__all__ = [
|
|
41
|
+
"__version__",
|
|
42
|
+
# addressing
|
|
43
|
+
"PAY_URI_PATTERN",
|
|
44
|
+
"MAX_PAY_URI_LENGTH",
|
|
45
|
+
"is_valid_pay_uri",
|
|
46
|
+
"assert_valid_pay_uri",
|
|
47
|
+
# hashing
|
|
48
|
+
"compute_canonical_hash",
|
|
49
|
+
"compute_semantic_hash",
|
|
50
|
+
"normalize_action",
|
|
51
|
+
"normalize_message",
|
|
52
|
+
"CANONICAL_ACTIONS",
|
|
53
|
+
"SYNONYM_MAP",
|
|
54
|
+
# schemas
|
|
55
|
+
"A2APaymentHookRequest",
|
|
56
|
+
"A2APaymentHookResponse",
|
|
57
|
+
"ResolutionDetail",
|
|
58
|
+
"SettlementDetail",
|
|
59
|
+
"A2ACapabilities",
|
|
60
|
+
# client
|
|
61
|
+
"A2APaymentHookClient",
|
|
62
|
+
]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""
|
|
2
|
+
FAS-1 ``pay:`` URI addressing.
|
|
3
|
+
|
|
4
|
+
The single source of truth for the ``pay:`` address grammar used across the
|
|
5
|
+
A2A protocol surface. Kept dependency-free (stdlib only) so it can be imported
|
|
6
|
+
anywhere — validators, schemas, clients.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import re
|
|
12
|
+
|
|
13
|
+
# pay:<label>(.<label>)* — labels are lowercase alphanumeric + hyphen,
|
|
14
|
+
# 1..63 chars, no leading hyphen. Total length capped at 128.
|
|
15
|
+
PAY_URI_PATTERN = re.compile(r"^pay:[a-z0-9][a-z0-9\-]{0,62}(\.[a-z0-9][a-z0-9\-]{0,62})*$")
|
|
16
|
+
|
|
17
|
+
MAX_PAY_URI_LENGTH = 128
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def is_valid_pay_uri(value: str) -> bool:
|
|
21
|
+
"""Return True if ``value`` is a syntactically valid ``pay:`` URI."""
|
|
22
|
+
return bool(PAY_URI_PATTERN.match(value)) and len(value) <= MAX_PAY_URI_LENGTH
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def assert_valid_pay_uri(value: str) -> str:
|
|
26
|
+
"""Return ``value`` if valid, else raise ``ValueError``."""
|
|
27
|
+
if not is_valid_pay_uri(value):
|
|
28
|
+
raise ValueError(f"Invalid pay: URI format: {value}")
|
|
29
|
+
return value
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""
|
|
2
|
+
A2A-008 Canonical Hash computation.
|
|
3
|
+
|
|
4
|
+
Produces a SHA256 hash of the semantically significant fields of a payment
|
|
5
|
+
request. Two semantically equivalent payments (same amount, currency, rail,
|
|
6
|
+
alias, category) produce the same ``canonical_hash`` regardless of
|
|
7
|
+
session/trace/idempotency metadata.
|
|
8
|
+
|
|
9
|
+
Excluded fields: session_id, request_id, trace_id, timestamp,
|
|
10
|
+
idempotency_key, memo, payload_hash, canonical_hash, created_at, updated_at.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import hashlib
|
|
16
|
+
import json
|
|
17
|
+
|
|
18
|
+
from a2a_protocol_core.semantic_normalizer import normalize_action
|
|
19
|
+
|
|
20
|
+
# Fields that carry no semantic payment meaning — excluded from the hash.
|
|
21
|
+
_EXCLUDED_KEYS = frozenset(
|
|
22
|
+
{
|
|
23
|
+
"session_id",
|
|
24
|
+
"request_id",
|
|
25
|
+
"trace_id",
|
|
26
|
+
"timestamp",
|
|
27
|
+
"idempotency_key",
|
|
28
|
+
"memo",
|
|
29
|
+
"payload_hash",
|
|
30
|
+
"canonical_hash",
|
|
31
|
+
"created_at",
|
|
32
|
+
"updated_at",
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# Fields that carry semantic payment meaning — included if present.
|
|
37
|
+
_INCLUDED_KEYS = (
|
|
38
|
+
"amount",
|
|
39
|
+
"currency",
|
|
40
|
+
"rail",
|
|
41
|
+
"preferred_rail",
|
|
42
|
+
"alias",
|
|
43
|
+
"alias_uri",
|
|
44
|
+
"alias_name",
|
|
45
|
+
"payment_category",
|
|
46
|
+
"payment_type",
|
|
47
|
+
"action",
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def compute_canonical_hash(payment_request: dict) -> str:
|
|
52
|
+
"""
|
|
53
|
+
Compute the SHA256 canonical hash of semantically significant payment fields.
|
|
54
|
+
|
|
55
|
+
Rules:
|
|
56
|
+
- Include: amount, currency, rail/preferred_rail, alias/alias_uri,
|
|
57
|
+
payment_category/payment_type, action.
|
|
58
|
+
- Exclude: session_id, request_id, trace_id, timestamp,
|
|
59
|
+
idempotency_key, memo, payload_hash, canonical_hash.
|
|
60
|
+
- Normalize ``action`` via the A2A-009 semantic normalizer.
|
|
61
|
+
- Sort keys, JSON serialize, SHA256.
|
|
62
|
+
"""
|
|
63
|
+
canonical: dict = {}
|
|
64
|
+
for key in _INCLUDED_KEYS:
|
|
65
|
+
if key in payment_request and payment_request[key] is not None:
|
|
66
|
+
val = payment_request[key]
|
|
67
|
+
# Normalize numeric types to string for consistency.
|
|
68
|
+
if isinstance(val, (int, float)):
|
|
69
|
+
val = str(val)
|
|
70
|
+
# Normalize action via the semantic normalizer (best-effort).
|
|
71
|
+
if key == "action" and isinstance(val, str):
|
|
72
|
+
try:
|
|
73
|
+
val = normalize_action(val)
|
|
74
|
+
except ValueError:
|
|
75
|
+
pass # keep raw if not a recognized action
|
|
76
|
+
canonical[key] = val
|
|
77
|
+
|
|
78
|
+
serialized = json.dumps(canonical, sort_keys=True)
|
|
79
|
+
return hashlib.sha256(serialized.encode()).hexdigest()
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""
|
|
2
|
+
A2A-041 Payment Hook client.
|
|
3
|
+
|
|
4
|
+
A thin, synchronous client over the DNS of Money A2A surface. Intelligence
|
|
5
|
+
lives in the *calling* agent; this client only carries a well-formed,
|
|
6
|
+
validated request to the deterministic core and parses the response.
|
|
7
|
+
|
|
8
|
+
from a2a_protocol_core import A2APaymentHookClient
|
|
9
|
+
|
|
10
|
+
client = A2APaymentHookClient(base_url="https://api.dnsofmoney.com")
|
|
11
|
+
result = client.trigger(
|
|
12
|
+
job_id="job-123",
|
|
13
|
+
provider_pay_address="pay:agent.compute",
|
|
14
|
+
requester_pay_address="pay:vendor.alpha",
|
|
15
|
+
amount="2.50",
|
|
16
|
+
currency="USD",
|
|
17
|
+
semantic_hash="abc123...",
|
|
18
|
+
)
|
|
19
|
+
print(result.settlement_result.status, result.iso_message_ref)
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
from decimal import Decimal
|
|
25
|
+
from typing import Optional, Union
|
|
26
|
+
|
|
27
|
+
import requests
|
|
28
|
+
|
|
29
|
+
from a2a_protocol_core.schemas import (
|
|
30
|
+
A2ACapabilities,
|
|
31
|
+
A2APaymentHookRequest,
|
|
32
|
+
A2APaymentHookResponse,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
DEFAULT_TIMEOUT = 30
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class A2APaymentHookClient:
|
|
39
|
+
def __init__(
|
|
40
|
+
self,
|
|
41
|
+
base_url: str,
|
|
42
|
+
api_key: Optional[str] = None,
|
|
43
|
+
verify_ssl: bool = True,
|
|
44
|
+
timeout: int = DEFAULT_TIMEOUT,
|
|
45
|
+
session: Optional[requests.Session] = None,
|
|
46
|
+
) -> None:
|
|
47
|
+
self.base_url = base_url.rstrip("/")
|
|
48
|
+
self.api_key = api_key
|
|
49
|
+
self.verify_ssl = verify_ssl
|
|
50
|
+
self.timeout = timeout
|
|
51
|
+
self._session = session or requests.Session()
|
|
52
|
+
|
|
53
|
+
def _headers(self) -> dict:
|
|
54
|
+
headers = {"Content-Type": "application/json"}
|
|
55
|
+
if self.api_key:
|
|
56
|
+
headers["X-API-Key"] = self.api_key
|
|
57
|
+
return headers
|
|
58
|
+
|
|
59
|
+
def capabilities(self) -> A2ACapabilities:
|
|
60
|
+
"""Fetch the server's advertised A2A capabilities."""
|
|
61
|
+
resp = self._session.get(
|
|
62
|
+
f"{self.base_url}/v1/a2a/capabilities",
|
|
63
|
+
headers=self._headers(),
|
|
64
|
+
verify=self.verify_ssl,
|
|
65
|
+
timeout=self.timeout,
|
|
66
|
+
)
|
|
67
|
+
resp.raise_for_status()
|
|
68
|
+
return A2ACapabilities.model_validate(resp.json())
|
|
69
|
+
|
|
70
|
+
def trigger(
|
|
71
|
+
self,
|
|
72
|
+
job_id: str,
|
|
73
|
+
provider_pay_address: str,
|
|
74
|
+
requester_pay_address: str,
|
|
75
|
+
amount: Union[str, int, float, Decimal],
|
|
76
|
+
semantic_hash: str,
|
|
77
|
+
currency: str = "USD",
|
|
78
|
+
receipt_ref: Optional[str] = None,
|
|
79
|
+
) -> A2APaymentHookResponse:
|
|
80
|
+
"""
|
|
81
|
+
Fire the A2A-041 payment hook.
|
|
82
|
+
|
|
83
|
+
The request is validated client-side (pay: URI grammar, non-empty
|
|
84
|
+
semantic hash) before it ever hits the wire, so malformed intents fail
|
|
85
|
+
fast and locally.
|
|
86
|
+
"""
|
|
87
|
+
request = A2APaymentHookRequest(
|
|
88
|
+
job_id=job_id,
|
|
89
|
+
provider_pay_address=provider_pay_address,
|
|
90
|
+
requester_pay_address=requester_pay_address,
|
|
91
|
+
amount=Decimal(str(amount)),
|
|
92
|
+
currency=currency,
|
|
93
|
+
semantic_hash=semantic_hash,
|
|
94
|
+
receipt_ref=receipt_ref,
|
|
95
|
+
)
|
|
96
|
+
resp = self._session.post(
|
|
97
|
+
f"{self.base_url}/v1/a2a/payment-hook",
|
|
98
|
+
data=request.model_dump_json(),
|
|
99
|
+
headers=self._headers(),
|
|
100
|
+
verify=self.verify_ssl,
|
|
101
|
+
timeout=self.timeout,
|
|
102
|
+
)
|
|
103
|
+
resp.raise_for_status()
|
|
104
|
+
return A2APaymentHookResponse.model_validate(resp.json())
|
|
File without changes
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Wire schemas for the A2A-041 Payment Hook.
|
|
3
|
+
|
|
4
|
+
Pydantic v2 models shared between client and server. These define the public
|
|
5
|
+
request/response contract for ``POST /v1/a2a/payment-hook``.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import uuid
|
|
11
|
+
from datetime import datetime
|
|
12
|
+
from decimal import Decimal
|
|
13
|
+
from typing import Optional
|
|
14
|
+
|
|
15
|
+
from pydantic import BaseModel, field_validator
|
|
16
|
+
|
|
17
|
+
from a2a_protocol_core.addressing import is_valid_pay_uri
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class A2APaymentHookRequest(BaseModel):
|
|
21
|
+
"""A2A-041 compute-marketplace receipt -> settlement trigger."""
|
|
22
|
+
|
|
23
|
+
job_id: str
|
|
24
|
+
provider_pay_address: str
|
|
25
|
+
requester_pay_address: str
|
|
26
|
+
amount: Decimal
|
|
27
|
+
currency: str = "USD"
|
|
28
|
+
semantic_hash: str
|
|
29
|
+
receipt_ref: Optional[str] = None
|
|
30
|
+
|
|
31
|
+
@field_validator("provider_pay_address", "requester_pay_address")
|
|
32
|
+
@classmethod
|
|
33
|
+
def _validate_pay_uri(cls, v: str) -> str:
|
|
34
|
+
if not is_valid_pay_uri(v):
|
|
35
|
+
raise ValueError(f"Invalid pay: URI format: {v}")
|
|
36
|
+
return v
|
|
37
|
+
|
|
38
|
+
@field_validator("semantic_hash")
|
|
39
|
+
@classmethod
|
|
40
|
+
def _validate_semantic_hash(cls, v: str) -> str:
|
|
41
|
+
if not v or not v.strip():
|
|
42
|
+
raise ValueError("semantic_hash must not be empty")
|
|
43
|
+
return v
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ResolutionDetail(BaseModel):
|
|
47
|
+
provider_address: Optional[str] = None
|
|
48
|
+
rail: Optional[str] = None
|
|
49
|
+
endpoint: Optional[str] = None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class SettlementDetail(BaseModel):
|
|
53
|
+
status: str
|
|
54
|
+
rail: Optional[str] = None
|
|
55
|
+
tx_ref: Optional[str] = None
|
|
56
|
+
amount: Decimal
|
|
57
|
+
currency: str
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class A2APaymentHookResponse(BaseModel):
|
|
61
|
+
hook_id: uuid.UUID
|
|
62
|
+
job_id: str
|
|
63
|
+
resolution: ResolutionDetail
|
|
64
|
+
settlement_result: SettlementDetail
|
|
65
|
+
iso_message_ref: Optional[str] = None
|
|
66
|
+
created_at: datetime
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class A2ACapabilities(BaseModel):
|
|
70
|
+
binding_version: str
|
|
71
|
+
supported_schemes: list[str]
|
|
72
|
+
protocol_versions: list[str]
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
A2A-009 Semantic Normalizer.
|
|
3
|
+
|
|
4
|
+
Collapses synonym verbs ("send", "pay", "transfer") into canonical
|
|
5
|
+
action codes ("EXECUTE_PAYMENT", "QUERY", "VERIFY", "REPORT").
|
|
6
|
+
|
|
7
|
+
Used by A2A-008 ``canonical_hash`` for action field normalization. Two agents
|
|
8
|
+
that describe the same intent with different words produce the same canonical
|
|
9
|
+
action, so the canonical hash is stable across vocabularies.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import hashlib
|
|
15
|
+
import json
|
|
16
|
+
from copy import deepcopy
|
|
17
|
+
|
|
18
|
+
SYNONYM_MAP: dict[str, str] = {
|
|
19
|
+
"transfer": "EXECUTE_PAYMENT",
|
|
20
|
+
"send": "EXECUTE_PAYMENT",
|
|
21
|
+
"pay": "EXECUTE_PAYMENT",
|
|
22
|
+
"payment": "EXECUTE_PAYMENT",
|
|
23
|
+
"resolve": "QUERY",
|
|
24
|
+
"lookup": "QUERY",
|
|
25
|
+
"verify": "VERIFY",
|
|
26
|
+
"check": "VERIFY",
|
|
27
|
+
"confirm": "VERIFY",
|
|
28
|
+
"report": "REPORT",
|
|
29
|
+
"status": "REPORT",
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
CANONICAL_ACTIONS: frozenset[str] = frozenset(
|
|
33
|
+
{
|
|
34
|
+
"EXECUTE_PAYMENT",
|
|
35
|
+
"QUERY",
|
|
36
|
+
"VERIFY",
|
|
37
|
+
"REPORT",
|
|
38
|
+
}
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def normalize_action(raw_action: str) -> str:
|
|
43
|
+
"""
|
|
44
|
+
Normalize a raw action string to its canonical form.
|
|
45
|
+
|
|
46
|
+
Lowercases, strips whitespace, collapses synonyms.
|
|
47
|
+
Raises ValueError if the result is not in CANONICAL_ACTIONS.
|
|
48
|
+
"""
|
|
49
|
+
cleaned = raw_action.strip().lower()
|
|
50
|
+
canonical = SYNONYM_MAP.get(cleaned, cleaned.upper())
|
|
51
|
+
if canonical not in CANONICAL_ACTIONS:
|
|
52
|
+
raise ValueError(f"Unknown action '{raw_action}' — not in {sorted(CANONICAL_ACTIONS)}")
|
|
53
|
+
return canonical
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def normalize_message(message: dict) -> dict:
|
|
57
|
+
"""
|
|
58
|
+
Normalize the 'action' field of an A2A message.
|
|
59
|
+
|
|
60
|
+
Returns a normalized copy — does NOT mutate the input.
|
|
61
|
+
"""
|
|
62
|
+
normalized = deepcopy(message)
|
|
63
|
+
if "action" in normalized:
|
|
64
|
+
normalized["action"] = normalize_action(normalized["action"])
|
|
65
|
+
return normalized
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def compute_semantic_hash(normalized_message: dict) -> str:
|
|
69
|
+
"""
|
|
70
|
+
SHA256 of the canonical representation of a normalized message.
|
|
71
|
+
|
|
72
|
+
Deterministic: same normalized content -> same hash.
|
|
73
|
+
"""
|
|
74
|
+
serialized = json.dumps(normalized_message, sort_keys=True)
|
|
75
|
+
return hashlib.sha256(serialized.encode()).hexdigest()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from a2a_protocol_core.addressing import assert_valid_pay_uri, is_valid_pay_uri
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@pytest.mark.parametrize(
|
|
7
|
+
"uri",
|
|
8
|
+
[
|
|
9
|
+
"pay:alice",
|
|
10
|
+
"pay:vendor.alpha",
|
|
11
|
+
"pay:agent.compute.us-east",
|
|
12
|
+
"pay:a",
|
|
13
|
+
"pay:a1-b2.c3",
|
|
14
|
+
],
|
|
15
|
+
)
|
|
16
|
+
def test_valid_uris(uri):
|
|
17
|
+
assert is_valid_pay_uri(uri)
|
|
18
|
+
assert assert_valid_pay_uri(uri) == uri
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@pytest.mark.parametrize(
|
|
22
|
+
"uri",
|
|
23
|
+
[
|
|
24
|
+
"",
|
|
25
|
+
"alice", # missing scheme
|
|
26
|
+
"pay:", # empty body
|
|
27
|
+
"pay:-alice", # leading hyphen
|
|
28
|
+
"pay:Alice", # uppercase
|
|
29
|
+
"pay:a..b", # empty label
|
|
30
|
+
"pay:" + "a" * 130, # too long
|
|
31
|
+
],
|
|
32
|
+
)
|
|
33
|
+
def test_invalid_uris(uri):
|
|
34
|
+
assert not is_valid_pay_uri(uri)
|
|
35
|
+
with pytest.raises(ValueError):
|
|
36
|
+
assert_valid_pay_uri(uri)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from a2a_protocol_core.canonical_hash import compute_canonical_hash
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_metadata_does_not_change_hash():
|
|
5
|
+
base = {"amount": 10, "currency": "USD", "alias": "pay:vendor.alpha"}
|
|
6
|
+
noisy = {
|
|
7
|
+
**base,
|
|
8
|
+
"session_id": "s-1",
|
|
9
|
+
"request_id": "r-1",
|
|
10
|
+
"trace_id": "t-1",
|
|
11
|
+
"timestamp": "2026-06-28T00:00:00Z",
|
|
12
|
+
"idempotency_key": "idem-1",
|
|
13
|
+
"memo": "hello",
|
|
14
|
+
}
|
|
15
|
+
assert compute_canonical_hash(base) == compute_canonical_hash(noisy)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_numeric_and_string_amount_match():
|
|
19
|
+
assert compute_canonical_hash({"amount": 10}) == compute_canonical_hash({"amount": "10"})
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_synonym_action_collapses():
|
|
23
|
+
a = compute_canonical_hash({"action": "send", "amount": "1"})
|
|
24
|
+
b = compute_canonical_hash({"action": "transfer", "amount": "1"})
|
|
25
|
+
assert a == b
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_semantic_difference_changes_hash():
|
|
29
|
+
a = compute_canonical_hash({"amount": "1", "currency": "USD"})
|
|
30
|
+
b = compute_canonical_hash({"amount": "2", "currency": "USD"})
|
|
31
|
+
assert a != b
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_unknown_action_kept_raw():
|
|
35
|
+
# Unknown actions don't raise; they fall through to the raw value.
|
|
36
|
+
h = compute_canonical_hash({"action": "frobnicate", "amount": "1"})
|
|
37
|
+
assert isinstance(h, str) and len(h) == 64
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from pydantic import ValidationError
|
|
3
|
+
|
|
4
|
+
from a2a_protocol_core.schemas import A2APaymentHookRequest
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_valid_request():
|
|
8
|
+
req = A2APaymentHookRequest(
|
|
9
|
+
job_id="job-1",
|
|
10
|
+
provider_pay_address="pay:agent.compute",
|
|
11
|
+
requester_pay_address="pay:vendor.alpha",
|
|
12
|
+
amount="2.50",
|
|
13
|
+
semantic_hash="abc123",
|
|
14
|
+
)
|
|
15
|
+
assert req.currency == "USD"
|
|
16
|
+
assert str(req.amount) == "2.50"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def test_invalid_pay_uri_rejected():
|
|
20
|
+
with pytest.raises(ValidationError):
|
|
21
|
+
A2APaymentHookRequest(
|
|
22
|
+
job_id="job-1",
|
|
23
|
+
provider_pay_address="not-a-pay-uri",
|
|
24
|
+
requester_pay_address="pay:vendor.alpha",
|
|
25
|
+
amount="1",
|
|
26
|
+
semantic_hash="abc",
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_empty_semantic_hash_rejected():
|
|
31
|
+
with pytest.raises(ValidationError):
|
|
32
|
+
A2APaymentHookRequest(
|
|
33
|
+
job_id="job-1",
|
|
34
|
+
provider_pay_address="pay:agent.compute",
|
|
35
|
+
requester_pay_address="pay:vendor.alpha",
|
|
36
|
+
amount="1",
|
|
37
|
+
semantic_hash=" ",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_json_roundtrip_serializes_decimal():
|
|
42
|
+
req = A2APaymentHookRequest(
|
|
43
|
+
job_id="job-1",
|
|
44
|
+
provider_pay_address="pay:agent.compute",
|
|
45
|
+
requester_pay_address="pay:vendor.alpha",
|
|
46
|
+
amount="2.50",
|
|
47
|
+
semantic_hash="abc",
|
|
48
|
+
)
|
|
49
|
+
payload = req.model_dump_json()
|
|
50
|
+
assert "2.50" in payload
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from a2a_protocol_core.semantic_normalizer import (
|
|
4
|
+
compute_semantic_hash,
|
|
5
|
+
normalize_action,
|
|
6
|
+
normalize_message,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@pytest.mark.parametrize(
|
|
11
|
+
"raw,expected",
|
|
12
|
+
[
|
|
13
|
+
("send", "EXECUTE_PAYMENT"),
|
|
14
|
+
("pay", "EXECUTE_PAYMENT"),
|
|
15
|
+
("transfer", "EXECUTE_PAYMENT"),
|
|
16
|
+
(" Transfer ", "EXECUTE_PAYMENT"),
|
|
17
|
+
("resolve", "QUERY"),
|
|
18
|
+
("lookup", "QUERY"),
|
|
19
|
+
("verify", "VERIFY"),
|
|
20
|
+
("status", "REPORT"),
|
|
21
|
+
("EXECUTE_PAYMENT", "EXECUTE_PAYMENT"),
|
|
22
|
+
],
|
|
23
|
+
)
|
|
24
|
+
def test_normalize_action(raw, expected):
|
|
25
|
+
assert normalize_action(raw) == expected
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_normalize_action_unknown_raises():
|
|
29
|
+
with pytest.raises(ValueError):
|
|
30
|
+
normalize_action("frobnicate")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_normalize_message_does_not_mutate():
|
|
34
|
+
msg = {"action": "send", "amount": "5"}
|
|
35
|
+
out = normalize_message(msg)
|
|
36
|
+
assert out["action"] == "EXECUTE_PAYMENT"
|
|
37
|
+
assert msg["action"] == "send" # original untouched
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_synonyms_produce_same_semantic_hash():
|
|
41
|
+
a = compute_semantic_hash(normalize_message({"action": "send", "amount": "5"}))
|
|
42
|
+
b = compute_semantic_hash(normalize_message({"action": "transfer", "amount": "5"}))
|
|
43
|
+
assert a == b
|