asi-names-payee 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.
- asi_names_payee-0.1.0/LICENSE +25 -0
- asi_names_payee-0.1.0/PKG-INFO +101 -0
- asi_names_payee-0.1.0/README.md +83 -0
- asi_names_payee-0.1.0/pyproject.toml +35 -0
- asi_names_payee-0.1.0/setup.cfg +4 -0
- asi_names_payee-0.1.0/src/asi_names_payee.egg-info/PKG-INFO +101 -0
- asi_names_payee-0.1.0/src/asi_names_payee.egg-info/SOURCES.txt +13 -0
- asi_names_payee-0.1.0/src/asi_names_payee.egg-info/dependency_links.txt +1 -0
- asi_names_payee-0.1.0/src/asi_names_payee.egg-info/requires.txt +5 -0
- asi_names_payee-0.1.0/src/asi_names_payee.egg-info/top_level.txt +1 -0
- asi_names_payee-0.1.0/src/asi_payee/__init__.py +131 -0
- asi_names_payee-0.1.0/src/asi_payee/reader.py +197 -0
- asi_names_payee-0.1.0/src/asi_payee/verify.py +352 -0
- asi_names_payee-0.1.0/tests/test_live.py +74 -0
- asi_names_payee-0.1.0/tests/test_unit.py +238 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ASI Names
|
|
4
|
+
|
|
5
|
+
Portions of contracts/ens are derived from the ENS contracts (https://github.com/ensdomains/ens-contracts),
|
|
6
|
+
Copyright (c) ENS Labs Ltd and the ENS contributors, also released under the MIT License. Their
|
|
7
|
+
original notices are kept in those source files.
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: asi-names-payee
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Verify x402 payees by their .asi name: the name's onchain records bind the origin and payTo.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://asinames.xyz/developers/
|
|
7
|
+
Project-URL: Source, https://github.com/RWA-ID/asi-names/tree/main/payee-py
|
|
8
|
+
Keywords: x402,asi,ens,payments,agents
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: pycryptodome>=3.18
|
|
14
|
+
Requires-Dist: ens-normalize>=3.0
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# asi-names-payee (Python)
|
|
20
|
+
|
|
21
|
+
Check an x402 payee against its `.asi` name before paying. The name's records on Ethereum mainnet
|
|
22
|
+
list the origins the payee serves from (`org.x402.origins`) and where it gets paid (its address
|
|
23
|
+
records, or `org.x402.payto`). A payment goes ahead only if both match.
|
|
24
|
+
|
|
25
|
+
This is the Python port of [`@asi-names/payee`](https://github.com/RWA-ID/asi-names/tree/main/payee). Its verdicts are identical: same steps,
|
|
26
|
+
reason codes and fields, checked field by field against the TypeScript package on live mainnet.
|
|
27
|
+
|
|
28
|
+
- Depends on `pycryptodome` (keccak) and `ens-normalize` (ENSIP-15). Chain reads use plain
|
|
29
|
+
JSON-RPC from the standard library.
|
|
30
|
+
- Read-only `eth_call`s to Ethereum mainnet. No keys, no gateway, no CCIP-Read.
|
|
31
|
+
- Python 3.9+.
|
|
32
|
+
|
|
33
|
+
## Two ways to use it
|
|
34
|
+
|
|
35
|
+
**The buyer names the payee** (works with x402 v1 and v2). The seller declares nothing; the
|
|
36
|
+
buyer's config says who it means to pay, and the name's records decide whether this `payTo` is
|
|
37
|
+
that payee:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from asi_payee import check_expected_payee
|
|
41
|
+
|
|
42
|
+
v = check_expected_payee(
|
|
43
|
+
"test.asi", # the payee, from the buyer's own config
|
|
44
|
+
"https://test.asinames.xyz/hello", # the URL the client is calling (never resource.url)
|
|
45
|
+
"base", # v1 network name or CAIP-2 ("eip155:8453")
|
|
46
|
+
requirement["payTo"], # the payTo about to be signed
|
|
47
|
+
"https://ethereum-rpc.publicnode.com",
|
|
48
|
+
)
|
|
49
|
+
if v["verdict"] is not True:
|
|
50
|
+
raise PermissionError(f"refusing to pay: {v['reason']}")
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
When the payee rotates its wallet, it updates its own record. Buyers' configs don't change.
|
|
54
|
+
|
|
55
|
+
**The seller declares its name** in the 402's `payee-name` extension (x402 v2, proposed in
|
|
56
|
+
[x402-foundation/x402#3755](https://github.com/x402-foundation/x402/pull/3755)):
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from asi_payee import verify_asi_payee
|
|
60
|
+
|
|
61
|
+
verdicts = verify_asi_payee(payment_required, request_url, rpc_url)
|
|
62
|
+
# None: the 402 declares no name. Otherwise one verdict per entry in `accepts`.
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`acheck_expected_payee` and `averify_asi_payee` are the async versions.
|
|
66
|
+
|
|
67
|
+
## Verdicts
|
|
68
|
+
|
|
69
|
+
`verdict` is `True`, `False` or `"inconclusive"`. Pay only on `True`.
|
|
70
|
+
|
|
71
|
+
| `reason` | `verdict` | Meaning |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `payee-bound` | `True` | Origin listed and `payTo` matched (`matched_by`: `addr` or `org.x402.payto`) |
|
|
74
|
+
| `origin-not-listed` | `False` | The name doesn't list the origin you called |
|
|
75
|
+
| `payto-not-listed` | `False` | The name doesn't list this `payTo` for this network |
|
|
76
|
+
| `name-not-normalized` | `False` | Not in ENSIP-15 normal form (lookalikes are refused, never normalized) |
|
|
77
|
+
| `name-expired` | `False` | Expired past grace, or never registered (`detail.got: "not registered"`) |
|
|
78
|
+
| `name-in-grace` | `"inconclusive"` | Expired, inside the 90-day grace period |
|
|
79
|
+
| `no-records` | `"inconclusive"` | The name has no origins, payTo list or addresses |
|
|
80
|
+
| `resolution-failed` | `"inconclusive"` | A chain read failed (outage, rate limit). Never read as "not listed" |
|
|
81
|
+
| `unsupported-name` | `"inconclusive"` | Not a `.asi` name |
|
|
82
|
+
|
|
83
|
+
Each verdict also carries `expires_at` and `parent_can_control`: `True` when a parent name's owner
|
|
84
|
+
could still rewrite a subname's records.
|
|
85
|
+
|
|
86
|
+
## Records the payee sets
|
|
87
|
+
|
|
88
|
+
| Record | Example |
|
|
89
|
+
|---|---|
|
|
90
|
+
| `org.x402.origins` (text) | `https://test.asinames.xyz` (space-separated) |
|
|
91
|
+
| Default EVM address (coin type `0x80000000`) | answers for every EVM chain without its own record |
|
|
92
|
+
| Solana address (coin type 501) | matched against a base58 `payTo` on `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` |
|
|
93
|
+
| `org.x402.payto` (text) | `eip155:8453:0xabc… eip155:1:0xdef…` |
|
|
94
|
+
|
|
95
|
+
## Tests
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
pip install -e ".[test]"
|
|
99
|
+
pytest # offline
|
|
100
|
+
ASI_RPC_URL=<mainnet RPC> pytest -m live # mainnet + the live 402 at test.asinames.xyz
|
|
101
|
+
```
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# asi-names-payee (Python)
|
|
2
|
+
|
|
3
|
+
Check an x402 payee against its `.asi` name before paying. The name's records on Ethereum mainnet
|
|
4
|
+
list the origins the payee serves from (`org.x402.origins`) and where it gets paid (its address
|
|
5
|
+
records, or `org.x402.payto`). A payment goes ahead only if both match.
|
|
6
|
+
|
|
7
|
+
This is the Python port of [`@asi-names/payee`](https://github.com/RWA-ID/asi-names/tree/main/payee). Its verdicts are identical: same steps,
|
|
8
|
+
reason codes and fields, checked field by field against the TypeScript package on live mainnet.
|
|
9
|
+
|
|
10
|
+
- Depends on `pycryptodome` (keccak) and `ens-normalize` (ENSIP-15). Chain reads use plain
|
|
11
|
+
JSON-RPC from the standard library.
|
|
12
|
+
- Read-only `eth_call`s to Ethereum mainnet. No keys, no gateway, no CCIP-Read.
|
|
13
|
+
- Python 3.9+.
|
|
14
|
+
|
|
15
|
+
## Two ways to use it
|
|
16
|
+
|
|
17
|
+
**The buyer names the payee** (works with x402 v1 and v2). The seller declares nothing; the
|
|
18
|
+
buyer's config says who it means to pay, and the name's records decide whether this `payTo` is
|
|
19
|
+
that payee:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from asi_payee import check_expected_payee
|
|
23
|
+
|
|
24
|
+
v = check_expected_payee(
|
|
25
|
+
"test.asi", # the payee, from the buyer's own config
|
|
26
|
+
"https://test.asinames.xyz/hello", # the URL the client is calling (never resource.url)
|
|
27
|
+
"base", # v1 network name or CAIP-2 ("eip155:8453")
|
|
28
|
+
requirement["payTo"], # the payTo about to be signed
|
|
29
|
+
"https://ethereum-rpc.publicnode.com",
|
|
30
|
+
)
|
|
31
|
+
if v["verdict"] is not True:
|
|
32
|
+
raise PermissionError(f"refusing to pay: {v['reason']}")
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
When the payee rotates its wallet, it updates its own record. Buyers' configs don't change.
|
|
36
|
+
|
|
37
|
+
**The seller declares its name** in the 402's `payee-name` extension (x402 v2, proposed in
|
|
38
|
+
[x402-foundation/x402#3755](https://github.com/x402-foundation/x402/pull/3755)):
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from asi_payee import verify_asi_payee
|
|
42
|
+
|
|
43
|
+
verdicts = verify_asi_payee(payment_required, request_url, rpc_url)
|
|
44
|
+
# None: the 402 declares no name. Otherwise one verdict per entry in `accepts`.
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`acheck_expected_payee` and `averify_asi_payee` are the async versions.
|
|
48
|
+
|
|
49
|
+
## Verdicts
|
|
50
|
+
|
|
51
|
+
`verdict` is `True`, `False` or `"inconclusive"`. Pay only on `True`.
|
|
52
|
+
|
|
53
|
+
| `reason` | `verdict` | Meaning |
|
|
54
|
+
|---|---|---|
|
|
55
|
+
| `payee-bound` | `True` | Origin listed and `payTo` matched (`matched_by`: `addr` or `org.x402.payto`) |
|
|
56
|
+
| `origin-not-listed` | `False` | The name doesn't list the origin you called |
|
|
57
|
+
| `payto-not-listed` | `False` | The name doesn't list this `payTo` for this network |
|
|
58
|
+
| `name-not-normalized` | `False` | Not in ENSIP-15 normal form (lookalikes are refused, never normalized) |
|
|
59
|
+
| `name-expired` | `False` | Expired past grace, or never registered (`detail.got: "not registered"`) |
|
|
60
|
+
| `name-in-grace` | `"inconclusive"` | Expired, inside the 90-day grace period |
|
|
61
|
+
| `no-records` | `"inconclusive"` | The name has no origins, payTo list or addresses |
|
|
62
|
+
| `resolution-failed` | `"inconclusive"` | A chain read failed (outage, rate limit). Never read as "not listed" |
|
|
63
|
+
| `unsupported-name` | `"inconclusive"` | Not a `.asi` name |
|
|
64
|
+
|
|
65
|
+
Each verdict also carries `expires_at` and `parent_can_control`: `True` when a parent name's owner
|
|
66
|
+
could still rewrite a subname's records.
|
|
67
|
+
|
|
68
|
+
## Records the payee sets
|
|
69
|
+
|
|
70
|
+
| Record | Example |
|
|
71
|
+
|---|---|
|
|
72
|
+
| `org.x402.origins` (text) | `https://test.asinames.xyz` (space-separated) |
|
|
73
|
+
| Default EVM address (coin type `0x80000000`) | answers for every EVM chain without its own record |
|
|
74
|
+
| Solana address (coin type 501) | matched against a base58 `payTo` on `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` |
|
|
75
|
+
| `org.x402.payto` (text) | `eip155:8453:0xabc… eip155:1:0xdef…` |
|
|
76
|
+
|
|
77
|
+
## Tests
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install -e ".[test]"
|
|
81
|
+
pytest # offline
|
|
82
|
+
ASI_RPC_URL=<mainnet RPC> pytest -m live # mainnet + the live 402 at test.asinames.xyz
|
|
83
|
+
```
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "asi-names-payee"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Verify x402 payees by their .asi name: the name's onchain records bind the origin and payTo."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
dependencies = [
|
|
14
|
+
"pycryptodome>=3.18",
|
|
15
|
+
"ens-normalize>=3.0",
|
|
16
|
+
]
|
|
17
|
+
keywords = ["x402", "asi", "ens", "payments", "agents"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://asinames.xyz/developers/"
|
|
24
|
+
Source = "https://github.com/RWA-ID/asi-names/tree/main/payee-py"
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
test = ["pytest>=7"]
|
|
28
|
+
|
|
29
|
+
[tool.setuptools.packages.find]
|
|
30
|
+
where = ["src"]
|
|
31
|
+
|
|
32
|
+
[tool.pytest.ini_options]
|
|
33
|
+
testpaths = ["tests"]
|
|
34
|
+
markers = ["live: reads Ethereum mainnet (set ASI_RPC_URL)"]
|
|
35
|
+
addopts = "-m 'not live'"
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: asi-names-payee
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Verify x402 payees by their .asi name: the name's onchain records bind the origin and payTo.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://asinames.xyz/developers/
|
|
7
|
+
Project-URL: Source, https://github.com/RWA-ID/asi-names/tree/main/payee-py
|
|
8
|
+
Keywords: x402,asi,ens,payments,agents
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: pycryptodome>=3.18
|
|
14
|
+
Requires-Dist: ens-normalize>=3.0
|
|
15
|
+
Provides-Extra: test
|
|
16
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# asi-names-payee (Python)
|
|
20
|
+
|
|
21
|
+
Check an x402 payee against its `.asi` name before paying. The name's records on Ethereum mainnet
|
|
22
|
+
list the origins the payee serves from (`org.x402.origins`) and where it gets paid (its address
|
|
23
|
+
records, or `org.x402.payto`). A payment goes ahead only if both match.
|
|
24
|
+
|
|
25
|
+
This is the Python port of [`@asi-names/payee`](https://github.com/RWA-ID/asi-names/tree/main/payee). Its verdicts are identical: same steps,
|
|
26
|
+
reason codes and fields, checked field by field against the TypeScript package on live mainnet.
|
|
27
|
+
|
|
28
|
+
- Depends on `pycryptodome` (keccak) and `ens-normalize` (ENSIP-15). Chain reads use plain
|
|
29
|
+
JSON-RPC from the standard library.
|
|
30
|
+
- Read-only `eth_call`s to Ethereum mainnet. No keys, no gateway, no CCIP-Read.
|
|
31
|
+
- Python 3.9+.
|
|
32
|
+
|
|
33
|
+
## Two ways to use it
|
|
34
|
+
|
|
35
|
+
**The buyer names the payee** (works with x402 v1 and v2). The seller declares nothing; the
|
|
36
|
+
buyer's config says who it means to pay, and the name's records decide whether this `payTo` is
|
|
37
|
+
that payee:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from asi_payee import check_expected_payee
|
|
41
|
+
|
|
42
|
+
v = check_expected_payee(
|
|
43
|
+
"test.asi", # the payee, from the buyer's own config
|
|
44
|
+
"https://test.asinames.xyz/hello", # the URL the client is calling (never resource.url)
|
|
45
|
+
"base", # v1 network name or CAIP-2 ("eip155:8453")
|
|
46
|
+
requirement["payTo"], # the payTo about to be signed
|
|
47
|
+
"https://ethereum-rpc.publicnode.com",
|
|
48
|
+
)
|
|
49
|
+
if v["verdict"] is not True:
|
|
50
|
+
raise PermissionError(f"refusing to pay: {v['reason']}")
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
When the payee rotates its wallet, it updates its own record. Buyers' configs don't change.
|
|
54
|
+
|
|
55
|
+
**The seller declares its name** in the 402's `payee-name` extension (x402 v2, proposed in
|
|
56
|
+
[x402-foundation/x402#3755](https://github.com/x402-foundation/x402/pull/3755)):
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from asi_payee import verify_asi_payee
|
|
60
|
+
|
|
61
|
+
verdicts = verify_asi_payee(payment_required, request_url, rpc_url)
|
|
62
|
+
# None: the 402 declares no name. Otherwise one verdict per entry in `accepts`.
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`acheck_expected_payee` and `averify_asi_payee` are the async versions.
|
|
66
|
+
|
|
67
|
+
## Verdicts
|
|
68
|
+
|
|
69
|
+
`verdict` is `True`, `False` or `"inconclusive"`. Pay only on `True`.
|
|
70
|
+
|
|
71
|
+
| `reason` | `verdict` | Meaning |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `payee-bound` | `True` | Origin listed and `payTo` matched (`matched_by`: `addr` or `org.x402.payto`) |
|
|
74
|
+
| `origin-not-listed` | `False` | The name doesn't list the origin you called |
|
|
75
|
+
| `payto-not-listed` | `False` | The name doesn't list this `payTo` for this network |
|
|
76
|
+
| `name-not-normalized` | `False` | Not in ENSIP-15 normal form (lookalikes are refused, never normalized) |
|
|
77
|
+
| `name-expired` | `False` | Expired past grace, or never registered (`detail.got: "not registered"`) |
|
|
78
|
+
| `name-in-grace` | `"inconclusive"` | Expired, inside the 90-day grace period |
|
|
79
|
+
| `no-records` | `"inconclusive"` | The name has no origins, payTo list or addresses |
|
|
80
|
+
| `resolution-failed` | `"inconclusive"` | A chain read failed (outage, rate limit). Never read as "not listed" |
|
|
81
|
+
| `unsupported-name` | `"inconclusive"` | Not a `.asi` name |
|
|
82
|
+
|
|
83
|
+
Each verdict also carries `expires_at` and `parent_can_control`: `True` when a parent name's owner
|
|
84
|
+
could still rewrite a subname's records.
|
|
85
|
+
|
|
86
|
+
## Records the payee sets
|
|
87
|
+
|
|
88
|
+
| Record | Example |
|
|
89
|
+
|---|---|
|
|
90
|
+
| `org.x402.origins` (text) | `https://test.asinames.xyz` (space-separated) |
|
|
91
|
+
| Default EVM address (coin type `0x80000000`) | answers for every EVM chain without its own record |
|
|
92
|
+
| Solana address (coin type 501) | matched against a base58 `payTo` on `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` |
|
|
93
|
+
| `org.x402.payto` (text) | `eip155:8453:0xabc… eip155:1:0xdef…` |
|
|
94
|
+
|
|
95
|
+
## Tests
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
pip install -e ".[test]"
|
|
99
|
+
pytest # offline
|
|
100
|
+
ASI_RPC_URL=<mainnet RPC> pytest -m live # mainnet + the live 402 at test.asinames.xyz
|
|
101
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/asi_names_payee.egg-info/PKG-INFO
|
|
5
|
+
src/asi_names_payee.egg-info/SOURCES.txt
|
|
6
|
+
src/asi_names_payee.egg-info/dependency_links.txt
|
|
7
|
+
src/asi_names_payee.egg-info/requires.txt
|
|
8
|
+
src/asi_names_payee.egg-info/top_level.txt
|
|
9
|
+
src/asi_payee/__init__.py
|
|
10
|
+
src/asi_payee/reader.py
|
|
11
|
+
src/asi_payee/verify.py
|
|
12
|
+
tests/test_live.py
|
|
13
|
+
tests/test_unit.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
asi_payee
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Verify x402 payees by their .asi name.
|
|
2
|
+
|
|
3
|
+
Two ways in:
|
|
4
|
+
|
|
5
|
+
* ``verify_asi_payee(payment_required, origin, source)``: the seller's 402 declares its name in
|
|
6
|
+
the ``payee-name`` extension (x402 v2). Same verdicts as ``@asi-names/payee`` in TypeScript.
|
|
7
|
+
* ``check_expected_payee(name, url, network, pay_to, source)``: the buyer's own config names the
|
|
8
|
+
payee, so it works with x402 v1 too. The seller declares nothing; the name's records decide.
|
|
9
|
+
|
|
10
|
+
``source`` is a mainnet JSON-RPC URL or a Reader. Only read-only ``eth_call``s are made.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import asyncio
|
|
16
|
+
from typing import Any, List, Mapping, Optional, Union
|
|
17
|
+
|
|
18
|
+
from .reader import AsiReader
|
|
19
|
+
from .verify import (
|
|
20
|
+
ASI_BASE_REGISTRAR,
|
|
21
|
+
ASI_GRACE_PERIOD,
|
|
22
|
+
ASI_NAME_WRAPPER,
|
|
23
|
+
ASI_REGISTRY,
|
|
24
|
+
ASI_UNIVERSAL_RESOLVER,
|
|
25
|
+
EXTENSION_KEY,
|
|
26
|
+
ORIGINS_KEY,
|
|
27
|
+
PARENT_CANNOT_CONTROL,
|
|
28
|
+
PAYTO_KEY,
|
|
29
|
+
SOLANA_MAINNET,
|
|
30
|
+
Reader,
|
|
31
|
+
Verdict,
|
|
32
|
+
coin_type_for,
|
|
33
|
+
declared_name,
|
|
34
|
+
to_origin,
|
|
35
|
+
verify_payee,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
__version__ = "0.1.0"
|
|
39
|
+
|
|
40
|
+
Source = Union[str, Reader]
|
|
41
|
+
|
|
42
|
+
#: x402 v1 network names -> CAIP-2 (v2 already uses CAIP-2 and passes through unchanged).
|
|
43
|
+
V1_NETWORKS = {
|
|
44
|
+
"ethereum": "eip155:1",
|
|
45
|
+
"sepolia": "eip155:11155111",
|
|
46
|
+
"base": "eip155:8453",
|
|
47
|
+
"base-sepolia": "eip155:84532",
|
|
48
|
+
"optimism": "eip155:10",
|
|
49
|
+
"arbitrum": "eip155:42161",
|
|
50
|
+
"polygon": "eip155:137",
|
|
51
|
+
"polygon-amoy": "eip155:80002",
|
|
52
|
+
"avalanche": "eip155:43114",
|
|
53
|
+
"avalanche-fuji": "eip155:43113",
|
|
54
|
+
"sei": "eip155:1329",
|
|
55
|
+
"sei-testnet": "eip155:1328",
|
|
56
|
+
"iotex": "eip155:4689",
|
|
57
|
+
"solana": SOLANA_MAINNET,
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def to_caip2(network: str) -> str:
|
|
62
|
+
"""A v1 network name ("base") as its CAIP-2 id ("eip155:8453"); CAIP-2 ids pass through."""
|
|
63
|
+
return V1_NETWORKS.get(network, network)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _reader(source: Source) -> Reader:
|
|
67
|
+
return AsiReader(source) if isinstance(source, str) else source
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def verify_asi_payee(payment_required: Mapping[str, Any], origin: str, source: Source) -> Optional[List[Verdict]]:
|
|
71
|
+
"""Verify a 402 challenge's ``payee-name`` declaration of a .asi name.
|
|
72
|
+
|
|
73
|
+
:param payment_required: the decoded 402 (``accepts`` with ``network``/``payTo``, ``extensions``)
|
|
74
|
+
:param origin: the origin the client actually contacted, from its own request URL.
|
|
75
|
+
Never ``resource.url``: the server writes that.
|
|
76
|
+
:returns: one verdict per entry in ``accepts``, or None when the 402 declares no name.
|
|
77
|
+
A name outside .asi gets ``unsupported-name``.
|
|
78
|
+
"""
|
|
79
|
+
pr = dict(payment_required)
|
|
80
|
+
pr["accepts"] = [{**a, "network": to_caip2(str(a.get("network")))} for a in pr.get("accepts") or []]
|
|
81
|
+
return verify_payee(pr, origin, _reader(source))
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def check_expected_payee(name: str, url: str, network: str, pay_to: str, source: Source) -> Verdict:
|
|
85
|
+
"""Check one payment against a payee name the buyer configured.
|
|
86
|
+
|
|
87
|
+
Pays only if ``name``'s records list the origin of ``url`` (``org.x402.origins``) and
|
|
88
|
+
``pay_to`` for ``network`` (its address record, or ``org.x402.payto``). ``verdict`` is True,
|
|
89
|
+
False or "inconclusive"; anything but True means do not pay.
|
|
90
|
+
"""
|
|
91
|
+
pr = {
|
|
92
|
+
"accepts": [{"network": to_caip2(network), "payTo": pay_to}],
|
|
93
|
+
"extensions": {EXTENSION_KEY: {"info": {"name": name}}},
|
|
94
|
+
}
|
|
95
|
+
return verify_payee(pr, url, _reader(source))[0]
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
async def acheck_expected_payee(name: str, url: str, network: str, pay_to: str, source: Source) -> Verdict:
|
|
99
|
+
"""``check_expected_payee`` for async callers (runs the blocking reads in a thread)."""
|
|
100
|
+
return await asyncio.to_thread(check_expected_payee, name, url, network, pay_to, source)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
async def averify_asi_payee(payment_required: Mapping[str, Any], origin: str, source: Source) -> Optional[List[Verdict]]:
|
|
104
|
+
"""``verify_asi_payee`` for async callers."""
|
|
105
|
+
return await asyncio.to_thread(verify_asi_payee, payment_required, origin, source)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
__all__ = [
|
|
109
|
+
"AsiReader",
|
|
110
|
+
"Reader",
|
|
111
|
+
"Verdict",
|
|
112
|
+
"verify_asi_payee",
|
|
113
|
+
"averify_asi_payee",
|
|
114
|
+
"check_expected_payee",
|
|
115
|
+
"acheck_expected_payee",
|
|
116
|
+
"verify_payee",
|
|
117
|
+
"to_caip2",
|
|
118
|
+
"to_origin",
|
|
119
|
+
"coin_type_for",
|
|
120
|
+
"declared_name",
|
|
121
|
+
"V1_NETWORKS",
|
|
122
|
+
"EXTENSION_KEY",
|
|
123
|
+
"ORIGINS_KEY",
|
|
124
|
+
"PAYTO_KEY",
|
|
125
|
+
"PARENT_CANNOT_CONTROL",
|
|
126
|
+
"ASI_REGISTRY",
|
|
127
|
+
"ASI_BASE_REGISTRAR",
|
|
128
|
+
"ASI_NAME_WRAPPER",
|
|
129
|
+
"ASI_UNIVERSAL_RESOLVER",
|
|
130
|
+
"ASI_GRACE_PERIOD",
|
|
131
|
+
]
|