|
| 1 | +--- |
| 2 | +outline: [2,4] |
| 3 | +--- |
| 4 | + |
| 5 | +[opengradient](../index) / [client](./index) / tee_connection |
| 6 | + |
| 7 | +# Package opengradient.client.tee_connection |
| 8 | + |
| 9 | +Manages the lifecycle of a connection to a TEE endpoint. |
| 10 | + |
| 11 | +## Classes |
| 12 | + |
| 13 | +### `ActiveTEE` |
| 14 | + |
| 15 | +Snapshot of the currently connected TEE. |
| 16 | + |
| 17 | +#### Constructor |
| 18 | + |
| 19 | +```python |
| 20 | +def __init__( |
| 21 | + endpoint: str, |
| 22 | + http_client: `x402HttpxClient`, |
| 23 | + tee_id: Optional[str], |
| 24 | + payment_address: Optional[str] |
| 25 | +) |
| 26 | +``` |
| 27 | + |
| 28 | +#### Methods |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +#### `metadata()` |
| 33 | + |
| 34 | +```python |
| 35 | +def metadata(self) ‑> Dict |
| 36 | +``` |
| 37 | +Return TEE metadata dict for decorating responses. |
| 38 | + |
| 39 | +#### Variables |
| 40 | + |
| 41 | +* static `endpoint` : str |
| 42 | +* static `http_client` : `x402HttpxClient` |
| 43 | +* static `payment_address` : Optional[str] |
| 44 | +* static `tee_id` : Optional[str] |
| 45 | + |
| 46 | +### `RegistryTEEConnection` |
| 47 | + |
| 48 | +TEE connection resolved from the on-chain registry. |
| 49 | + |
| 50 | +Handles TLS certificate pinning, background health checks, and automatic |
| 51 | +failover when the current TEE becomes unavailable. |
| 52 | + |
| 53 | +#### Constructor |
| 54 | + |
| 55 | +```python |
| 56 | +def __init__(x402_client: `x402Client`, registry: [TEERegistry](./tee_registry)) |
| 57 | +``` |
| 58 | + |
| 59 | +**Arguments** |
| 60 | + |
| 61 | +* **`x402_client`**: Configured x402 payment client for creating HTTP clients. |
| 62 | +* **`registry`**: TEERegistry for looking up active TEEs. |
| 63 | + |
| 64 | +#### Methods |
| 65 | + |
| 66 | +--- |
| 67 | + |
| 68 | +#### `close()` |
| 69 | + |
| 70 | +```python |
| 71 | +async def close(self) ‑> None |
| 72 | +``` |
| 73 | +Cancel the background refresh loop and close the HTTP client. |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +#### `ensure_refresh_loop()` |
| 78 | + |
| 79 | +```python |
| 80 | +def ensure_refresh_loop(self) ‑> None |
| 81 | +``` |
| 82 | +Start the background TEE refresh loop if not already running. |
| 83 | + |
| 84 | +Called lazily from async request methods since ``__init__`` is synchronous. |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +#### `get()` |
| 89 | + |
| 90 | +```python |
| 91 | +def get(self) ‑> `ActiveTEE` |
| 92 | +``` |
| 93 | +Return a snapshot of the current TEE connection. |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +#### `reconnect()` |
| 98 | + |
| 99 | +```python |
| 100 | +async def reconnect(self) ‑> None |
| 101 | +``` |
| 102 | +Connect to a new TEE from the registry and rebuild the HTTP client. |
| 103 | + |
| 104 | +### `StaticTEEConnection` |
| 105 | + |
| 106 | +TEE connection with a hardcoded endpoint URL. |
| 107 | + |
| 108 | +No registry lookup, no background refresh. TLS certificate verification |
| 109 | +is disabled because self-hosted TEE servers typically use self-signed certs. |
| 110 | + |
| 111 | +#### Constructor |
| 112 | + |
| 113 | +```python |
| 114 | +def __init__(x402_client: `x402Client`, endpoint: str) |
| 115 | +``` |
| 116 | + |
| 117 | +**Arguments** |
| 118 | + |
| 119 | +* **`x402_client`**: Configured x402 payment client for creating HTTP clients. |
| 120 | +* **`endpoint`**: The TEE endpoint URL to connect to. |
| 121 | + |
| 122 | +#### Methods |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +#### `close()` |
| 127 | + |
| 128 | +```python |
| 129 | +async def close(self) ‑> None |
| 130 | +``` |
| 131 | +Close the HTTP client. |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +#### `ensure_refresh_loop()` |
| 136 | + |
| 137 | +```python |
| 138 | +def ensure_refresh_loop(self) ‑> None |
| 139 | +``` |
| 140 | +No-op — static connections don't refresh. |
| 141 | + |
| 142 | +--- |
| 143 | + |
| 144 | +#### `get()` |
| 145 | + |
| 146 | +```python |
| 147 | +def get(self) ‑> `ActiveTEE` |
| 148 | +``` |
| 149 | +Return a snapshot of the current TEE connection. |
| 150 | + |
| 151 | +--- |
| 152 | + |
| 153 | +#### `reconnect()` |
| 154 | + |
| 155 | +```python |
| 156 | +async def reconnect(self) ‑> None |
| 157 | +``` |
| 158 | +Rebuild the HTTP client (same endpoint). |
| 159 | + |
| 160 | +### `TEEConnectionInterface` |
| 161 | + |
| 162 | +Interface for TEE connection implementations. |
| 163 | + |
| 164 | +#### Constructor |
| 165 | + |
| 166 | +```python |
| 167 | +def __init__(*args, **kwargs) |
| 168 | +``` |
| 169 | + |
| 170 | +#### Methods |
| 171 | + |
| 172 | +--- |
| 173 | + |
| 174 | +#### `close()` |
| 175 | + |
| 176 | +```python |
| 177 | +async def close(self) ‑> None |
| 178 | +``` |
| 179 | + |
| 180 | +--- |
| 181 | + |
| 182 | +#### `ensure_refresh_loop()` |
| 183 | + |
| 184 | +```python |
| 185 | +def ensure_refresh_loop(self) ‑> None |
| 186 | +``` |
| 187 | + |
| 188 | +--- |
| 189 | + |
| 190 | +#### `get()` |
| 191 | + |
| 192 | +```python |
| 193 | +def get(self) ‑> `ActiveTEE` |
| 194 | +``` |
| 195 | + |
| 196 | +--- |
| 197 | + |
| 198 | +#### `reconnect()` |
| 199 | + |
| 200 | +```python |
| 201 | +async def reconnect(self) ‑> None |
| 202 | +``` |
0 commit comments