opengradient 0.5.10__py3-none-any.whl → 0.5.11__py3-none-any.whl
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.
- opengradient/client.py +1 -1
- opengradient/x402_auth.py +44 -47
- {opengradient-0.5.10.dist-info → opengradient-0.5.11.dist-info}/METADATA +1 -1
- {opengradient-0.5.10.dist-info → opengradient-0.5.11.dist-info}/RECORD +8 -8
- {opengradient-0.5.10.dist-info → opengradient-0.5.11.dist-info}/WHEEL +0 -0
- {opengradient-0.5.10.dist-info → opengradient-0.5.11.dist-info}/entry_points.txt +0 -0
- {opengradient-0.5.10.dist-info → opengradient-0.5.11.dist-info}/licenses/LICENSE +0 -0
- {opengradient-0.5.10.dist-info → opengradient-0.5.11.dist-info}/top_level.txt +0 -0
opengradient/client.py
CHANGED
|
@@ -1152,7 +1152,7 @@ class Client:
|
|
|
1152
1152
|
limits=LIMITS,
|
|
1153
1153
|
http2=False,
|
|
1154
1154
|
follow_redirects=False,
|
|
1155
|
-
auth=X402Auth(account=self._wallet_account), # type: ignore
|
|
1155
|
+
auth=X402Auth(account=self._wallet_account, network_filter=DEFAULT_NETWORK_FILTER), # type: ignore
|
|
1156
1156
|
) as client:
|
|
1157
1157
|
headers = {
|
|
1158
1158
|
"Content-Type": "application/json",
|
opengradient/x402_auth.py
CHANGED
|
@@ -5,12 +5,12 @@ This module provides an httpx Auth class that handles x402 payment protocol
|
|
|
5
5
|
authentication for streaming responses.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
from typing import Generator, Optional
|
|
9
|
-
|
|
10
8
|
import httpx
|
|
11
|
-
|
|
9
|
+
import typing
|
|
10
|
+
import logging
|
|
11
|
+
|
|
12
12
|
from x402.clients.base import x402Client
|
|
13
|
-
from x402.types import x402PaymentRequiredResponse
|
|
13
|
+
from x402.types import x402PaymentRequiredResponse, PaymentRequirements
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class X402Auth(httpx.Auth):
|
|
@@ -29,10 +29,20 @@ class X402Auth(httpx.Auth):
|
|
|
29
29
|
|
|
30
30
|
def __init__(
|
|
31
31
|
self,
|
|
32
|
-
account:
|
|
33
|
-
max_value: Optional[int] = None,
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
account: typing.Any,
|
|
33
|
+
max_value: typing.Optional[int] = None,
|
|
34
|
+
payment_requirements_selector: typing.Optional[
|
|
35
|
+
typing.Callable[
|
|
36
|
+
[
|
|
37
|
+
list[PaymentRequirements],
|
|
38
|
+
typing.Optional[str],
|
|
39
|
+
typing.Optional[str],
|
|
40
|
+
typing.Optional[int],
|
|
41
|
+
],
|
|
42
|
+
PaymentRequirements,
|
|
43
|
+
]
|
|
44
|
+
] = None,
|
|
45
|
+
network_filter: typing.Optional[str] = None,
|
|
36
46
|
):
|
|
37
47
|
"""
|
|
38
48
|
Initialize X402Auth with an Ethereum account for signing payments.
|
|
@@ -43,60 +53,47 @@ class X402Auth(httpx.Auth):
|
|
|
43
53
|
network_filter: Optional network filter for selecting payment requirements
|
|
44
54
|
scheme_filter: Optional scheme filter for selecting payment requirements
|
|
45
55
|
"""
|
|
46
|
-
self.
|
|
47
|
-
self._max_value = max_value
|
|
48
|
-
self._network_filter = network_filter
|
|
49
|
-
self._scheme_filter = scheme_filter
|
|
50
|
-
self._x402_client = x402Client(
|
|
56
|
+
self.x402_client = x402Client(
|
|
51
57
|
account,
|
|
52
58
|
max_value=max_value,
|
|
53
|
-
|
|
54
|
-
scheme_filter=scheme_filter,
|
|
59
|
+
payment_requirements_selector=payment_requirements_selector, # type: ignore
|
|
55
60
|
)
|
|
61
|
+
self.network_filter = network_filter
|
|
56
62
|
|
|
57
|
-
def
|
|
63
|
+
async def async_auth_flow(
|
|
58
64
|
self, request: httpx.Request
|
|
59
|
-
) ->
|
|
65
|
+
) -> typing.AsyncGenerator[httpx.Request, httpx.Response]:
|
|
60
66
|
"""
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
This method yields the initial request, and if a 402 response is received,
|
|
64
|
-
it creates a payment header and retries the request.
|
|
67
|
+
Handle authentication flow for x402 payment protocol.
|
|
65
68
|
|
|
66
69
|
Args:
|
|
67
|
-
request:
|
|
70
|
+
request: httpx Request object to be authenticated
|
|
68
71
|
|
|
69
72
|
Yields:
|
|
70
|
-
httpx
|
|
73
|
+
httpx Request object with authentication headers attached
|
|
71
74
|
"""
|
|
72
|
-
# Send the initial request
|
|
73
75
|
response = yield request
|
|
74
76
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
# Handle 402 Payment Required
|
|
80
|
-
try:
|
|
81
|
-
data = response.json()
|
|
82
|
-
payment_response = x402PaymentRequiredResponse(**data)
|
|
77
|
+
if response.status_code == 402:
|
|
78
|
+
try:
|
|
79
|
+
await response.aread()
|
|
80
|
+
data = response.json()
|
|
83
81
|
|
|
84
|
-
|
|
85
|
-
selected_requirements = self._x402_client.select_payment_requirements(
|
|
86
|
-
payment_response.accepts
|
|
87
|
-
)
|
|
82
|
+
payment_response = x402PaymentRequiredResponse(**data)
|
|
88
83
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
selected_requirements = self.x402_client.select_payment_requirements(
|
|
85
|
+
payment_response.accepts,
|
|
86
|
+
self.network_filter,
|
|
87
|
+
)
|
|
93
88
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
payment_header = self.x402_client.create_payment_header(
|
|
90
|
+
selected_requirements, payment_response.x402_version
|
|
91
|
+
)
|
|
97
92
|
|
|
98
|
-
|
|
93
|
+
request.headers["X-Payment"] = payment_header
|
|
94
|
+
request.headers["Access-Control-Expose-Headers"] = "X-Payment-Response"
|
|
95
|
+
yield request
|
|
99
96
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
except Exception as e:
|
|
98
|
+
logging.error(f"X402Auth: Error handling payment: {e}")
|
|
99
|
+
return
|
|
@@ -2,12 +2,12 @@ opengradient/__init__.py,sha256=hRGex2VGwAQ-lqBNphW93D4R3wPHQpQrTkwgGLe2MoA,1025
|
|
|
2
2
|
opengradient/account.py,sha256=5wrYpws_1lozjOFjLCTHtxgoxK-LmObDAaVy9eDcJY4,1145
|
|
3
3
|
opengradient/alpha.py,sha256=WAtL1GGbEpoeLO89rOMd8-YAgAFJYM1UJlICm6YGsPs,15195
|
|
4
4
|
opengradient/cli.py,sha256=pfgyLfD1MIDifKmGLFsJqBlgvqIcnsIh3zzg7PaIeH4,33670
|
|
5
|
-
opengradient/client.py,sha256=
|
|
5
|
+
opengradient/client.py,sha256=KQZI1WZaMqyIHRWFH4HA1fFd1JtSdkrUYa7RX_bIwJA,65289
|
|
6
6
|
opengradient/defaults.py,sha256=8faLPwvp_BQdErY_SEjBzvmGVuOBdZ2zKcoryD8SCXk,797
|
|
7
7
|
opengradient/exceptions.py,sha256=88tfegboGtlehQcwhxsl6ZzhLJWZWlkf_bkHTiCtXpo,3391
|
|
8
8
|
opengradient/types.py,sha256=bADakUM6WwdMORGC5HvQvWCezNwIlVc7l0zodPapbhQ,14622
|
|
9
9
|
opengradient/utils.py,sha256=ZUq4OBIml2vsC0tRqus4Zwb_e3g4woo00apByrafuVw,8058
|
|
10
|
-
opengradient/x402_auth.py,sha256=
|
|
10
|
+
opengradient/x402_auth.py,sha256=fuSsgFmvrlZ3X6uAlUnqtkQ485NECxHfBr3IFADpKAg,3309
|
|
11
11
|
opengradient/abi/InferencePrecompile.abi,sha256=reepTHg6Q01UrFP0Gexc-JayplsvOLPfG7jrEZ-cV28,10197
|
|
12
12
|
opengradient/abi/PriceHistoryInference.abi,sha256=ZB3fZdx1kaFlp2wt1vTbTZZG1k8HPvmNtkG5Q8Bnajw,5098
|
|
13
13
|
opengradient/abi/WorkflowScheduler.abi,sha256=yEGs76qO4S1z980KL5hBdfyXiJ6k-kERcB1O_o73AEU,416
|
|
@@ -29,9 +29,9 @@ opengradient/workflow_models/constants.py,sha256=viIkb_LGcfVprqQNaA80gBTj6cfYam0
|
|
|
29
29
|
opengradient/workflow_models/types.py,sha256=Z22hF6c8Y4D2GlzVEIBODGwsqSjSrQvUcpZ7R-mIJdI,409
|
|
30
30
|
opengradient/workflow_models/utils.py,sha256=aL2-Hp5J5qlJft6-wx4GnZNOXZ1vjYaTF1uEgYavWdI,1509
|
|
31
31
|
opengradient/workflow_models/workflow_models.py,sha256=d4C_gs39DAfy4cdY9Ee6GMXpPfzwvKFpmxzK1A7LNgU,3900
|
|
32
|
-
opengradient-0.5.
|
|
33
|
-
opengradient-0.5.
|
|
34
|
-
opengradient-0.5.
|
|
35
|
-
opengradient-0.5.
|
|
36
|
-
opengradient-0.5.
|
|
37
|
-
opengradient-0.5.
|
|
32
|
+
opengradient-0.5.11.dist-info/licenses/LICENSE,sha256=xEcvQ3AxZOtDkrqkys2Mm6Y9diEnaSeQRKvxi-JGnNA,1069
|
|
33
|
+
opengradient-0.5.11.dist-info/METADATA,sha256=qJZT1jnWcmpeBQsLN1YrmPRCfMzD4nk7saMguFYNmyc,5437
|
|
34
|
+
opengradient-0.5.11.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
35
|
+
opengradient-0.5.11.dist-info/entry_points.txt,sha256=yUKTaJx8RXnybkob0J62wVBiCp_1agVbgw9uzsmaeJc,54
|
|
36
|
+
opengradient-0.5.11.dist-info/top_level.txt,sha256=oC1zimVLa2Yi1LQz8c7x-0IQm92milb5ax8gHBHwDqU,13
|
|
37
|
+
opengradient-0.5.11.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|