nirium 0.2.0__tar.gz → 0.4.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.
- {nirium-0.2.0 → nirium-0.4.0}/PKG-INFO +6 -4
- {nirium-0.2.0 → nirium-0.4.0}/pyproject.toml +4 -3
- nirium-0.4.0/setup.py +17 -0
- {nirium-0.2.0 → nirium-0.4.0}/src/nirium/__init__.py +1 -1
- {nirium-0.2.0 → nirium-0.4.0}/src/nirium/client.py +153 -2
- {nirium-0.2.0 → nirium-0.4.0}/src/nirium.egg-info/PKG-INFO +6 -4
- {nirium-0.2.0 → nirium-0.4.0}/src/nirium.egg-info/requires.txt +1 -0
- nirium-0.2.0/setup.py +0 -14
- {nirium-0.2.0 → nirium-0.4.0}/README.md +0 -0
- {nirium-0.2.0 → nirium-0.4.0}/setup.cfg +0 -0
- {nirium-0.2.0 → nirium-0.4.0}/src/nirium.egg-info/SOURCES.txt +0 -0
- {nirium-0.2.0 → nirium-0.4.0}/src/nirium.egg-info/dependency_links.txt +0 -0
- {nirium-0.2.0 → nirium-0.4.0}/src/nirium.egg-info/top_level.txt +0 -0
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nirium
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Official Python SDK for
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Official Python SDK for Nirium autonomous agents on Stellar (x402 + MPP)
|
|
5
5
|
Author: Nirium Protocol
|
|
6
6
|
License: MIT
|
|
7
7
|
Project-URL: Homepage, https://nirium.dev
|
|
8
8
|
Project-URL: Repository, https://github.com/nirium/nirium
|
|
9
9
|
Project-URL: Documentation, https://nirium.dev/docs
|
|
10
|
-
Keywords: nirium,stellar,defi,sdk,soroban,agent
|
|
11
|
-
Requires-Python: >=3.
|
|
10
|
+
Keywords: nirium,stellar,defi,sdk,soroban,agent,x402,mpp,agentic-payments,usdc
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
Requires-Dist: aiohttp>=3.9.0
|
|
14
14
|
Requires-Dist: websockets>=13.0
|
|
15
|
+
Requires-Dist: stellar-sdk>=11.0.0
|
|
16
|
+
Dynamic: requires-python
|
|
15
17
|
|
|
16
18
|
# nirium
|
|
17
19
|
|
|
@@ -4,16 +4,17 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "nirium"
|
|
7
|
-
version = "0.
|
|
8
|
-
description = "Official Python SDK for
|
|
7
|
+
version = "0.4.0"
|
|
8
|
+
description = "Official Python SDK for Nirium autonomous agents on Stellar (x402 + MPP)"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
license = {text = "MIT"}
|
|
12
12
|
authors = [{name = "Nirium Protocol"}]
|
|
13
|
-
keywords = ["nirium", "stellar", "defi", "sdk", "soroban", "agent"]
|
|
13
|
+
keywords = ["nirium", "stellar", "defi", "sdk", "soroban", "agent", "x402", "mpp", "agentic-payments", "usdc"]
|
|
14
14
|
dependencies = [
|
|
15
15
|
"aiohttp>=3.9.0",
|
|
16
16
|
"websockets>=13.0",
|
|
17
|
+
"stellar-sdk>=11.0.0",
|
|
17
18
|
]
|
|
18
19
|
|
|
19
20
|
[project.urls]
|
nirium-0.4.0/setup.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="nirium",
|
|
5
|
+
version="0.4.0",
|
|
6
|
+
package_dir={"": "src"},
|
|
7
|
+
packages=find_packages(where="src"),
|
|
8
|
+
install_requires=[
|
|
9
|
+
"websockets>=11.0.3",
|
|
10
|
+
"aiohttp>=3.8.4",
|
|
11
|
+
"stellar-sdk>=11.0.0",
|
|
12
|
+
],
|
|
13
|
+
author="Nirium Team",
|
|
14
|
+
description="Official Python SDK for Nirium autonomous agents on Stellar (x402 + MPP)",
|
|
15
|
+
keywords=["nirium", "stellar", "defi", "x402", "mpp", "agentic-payments", "soroban"],
|
|
16
|
+
python_requires=">=3.9",
|
|
17
|
+
)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# ═══════════════════════════════════════════════════════════════
|
|
2
|
-
# Nirium Python SDK v0.
|
|
2
|
+
# Nirium Python SDK v0.3.0 — Official Client (x402 + MPP)
|
|
3
3
|
# Synced with backend API (real Horizon data, Soroban execution)
|
|
4
4
|
# ═══════════════════════════════════════════════════════════════
|
|
5
5
|
import asyncio
|
|
@@ -8,6 +8,8 @@ import logging
|
|
|
8
8
|
import aiohttp # type: ignore
|
|
9
9
|
import websockets # type: ignore
|
|
10
10
|
from typing import Callable, Dict, Any, List, Optional
|
|
11
|
+
from stellar_sdk import Keypair, Network, Server, TransactionBuilder, Asset # type: ignore
|
|
12
|
+
from stellar_sdk import scval # type: ignore
|
|
11
13
|
|
|
12
14
|
logger = logging.getLogger("nirium.client")
|
|
13
15
|
|
|
@@ -83,7 +85,7 @@ class Agent:
|
|
|
83
85
|
"""Check if the agent is reachable."""
|
|
84
86
|
try:
|
|
85
87
|
data = await self._get("/health")
|
|
86
|
-
return data.get("status")
|
|
88
|
+
return data.get("status") in ("operational", "online")
|
|
87
89
|
except Exception:
|
|
88
90
|
return False
|
|
89
91
|
|
|
@@ -175,6 +177,155 @@ class Agent:
|
|
|
175
177
|
"""Send a test event to a webhook."""
|
|
176
178
|
return await self._post(f"/api/webhooks/{webhook_id}/test")
|
|
177
179
|
|
|
180
|
+
# ─── x402 Protocol ───────────────────────────────────────
|
|
181
|
+
|
|
182
|
+
def init_x402(self, secret_key: str, network: str = "stellar:testnet"):
|
|
183
|
+
"""
|
|
184
|
+
Initialize x402 pay-per-request client.
|
|
185
|
+
|
|
186
|
+
Python SDK implements the x402 HTTP flow directly:
|
|
187
|
+
1. GET resource -> receive 402 + payment requirements
|
|
188
|
+
2. Build Soroban SAC USDC transfer auth entry
|
|
189
|
+
3. Retry with X-PAYMENT header containing signed auth entry
|
|
190
|
+
|
|
191
|
+
Args:
|
|
192
|
+
secret_key: Stellar secret key (S...) for signing
|
|
193
|
+
network: CAIP-2 network ID ('stellar:testnet' or 'stellar:pubnet')
|
|
194
|
+
"""
|
|
195
|
+
self._x402_keypair = Keypair.from_secret(secret_key)
|
|
196
|
+
self._x402_network = network
|
|
197
|
+
self._x402_passphrase = (
|
|
198
|
+
Network.TESTNET_NETWORK_PASSPHRASE if "testnet" in network
|
|
199
|
+
else Network.PUBLIC_NETWORK_PASSPHRASE
|
|
200
|
+
)
|
|
201
|
+
self._x402_horizon = Server(
|
|
202
|
+
"https://horizon-testnet.stellar.org" if "testnet" in network
|
|
203
|
+
else "https://horizon.stellar.org"
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
async def x402_fetch(self, url: str, method: str = "GET") -> Dict[str, Any]:
|
|
207
|
+
"""
|
|
208
|
+
Fetch a paid resource via x402 protocol.
|
|
209
|
+
|
|
210
|
+
Sends the initial request, receives 402 with payment requirements,
|
|
211
|
+
builds and signs a USDC payment, retries with the payment proof.
|
|
212
|
+
|
|
213
|
+
Returns the JSON payload from the paid resource.
|
|
214
|
+
"""
|
|
215
|
+
if not hasattr(self, "_x402_keypair"):
|
|
216
|
+
raise RuntimeError("x402 client not initialized. Call agent.init_x402() first.")
|
|
217
|
+
|
|
218
|
+
async with aiohttp.ClientSession() as session:
|
|
219
|
+
# Step 1: Initial request — expect 402
|
|
220
|
+
async with session.request(method, url) as resp:
|
|
221
|
+
if resp.status != 402:
|
|
222
|
+
return await resp.json()
|
|
223
|
+
|
|
224
|
+
requirements = await resp.json()
|
|
225
|
+
|
|
226
|
+
# Step 2: Build USDC payment from requirements
|
|
227
|
+
pay_req = requirements.get("paymentRequirements", [{}])[0]
|
|
228
|
+
dest = pay_req.get("receiver") or pay_req.get("destination", "")
|
|
229
|
+
amount = pay_req.get("maxAmountRequired") or pay_req.get("amount", "0.01")
|
|
230
|
+
usdc_issuer = "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5"
|
|
231
|
+
usdc_asset = Asset("USDC", usdc_issuer)
|
|
232
|
+
|
|
233
|
+
account = self._x402_horizon.load_account(self._x402_keypair.public_key)
|
|
234
|
+
tx = (
|
|
235
|
+
TransactionBuilder(
|
|
236
|
+
source_account=account,
|
|
237
|
+
network_passphrase=self._x402_passphrase,
|
|
238
|
+
base_fee=100,
|
|
239
|
+
)
|
|
240
|
+
.append_payment_op(dest, usdc_asset, str(amount))
|
|
241
|
+
.set_timeout(30)
|
|
242
|
+
.build()
|
|
243
|
+
)
|
|
244
|
+
tx.sign(self._x402_keypair)
|
|
245
|
+
xdr = tx.to_xdr()
|
|
246
|
+
|
|
247
|
+
# Step 3: Retry with payment proof
|
|
248
|
+
payment_header = json.dumps({"transaction": xdr})
|
|
249
|
+
headers = {"X-PAYMENT": payment_header, "Content-Type": "application/json"}
|
|
250
|
+
async with session.request(method, url, headers=headers) as resp:
|
|
251
|
+
resp.raise_for_status()
|
|
252
|
+
return await resp.json()
|
|
253
|
+
|
|
254
|
+
# ─── MPP Protocol (Charge Mode) ─────────────────────────
|
|
255
|
+
|
|
256
|
+
def init_mpp(self, secret_key: str, network: str = "stellar:testnet"):
|
|
257
|
+
"""
|
|
258
|
+
Initialize MPP Charge client for per-request Soroban SAC payments.
|
|
259
|
+
|
|
260
|
+
Python SDK implements the MPP charge flow directly:
|
|
261
|
+
1. GET resource -> receive 402 + charge challenge
|
|
262
|
+
2. Sign Soroban auth entries for SAC USDC transfer
|
|
263
|
+
3. Retry with signed auth in X-PAYMENT header
|
|
264
|
+
|
|
265
|
+
Args:
|
|
266
|
+
secret_key: Stellar secret key (S...) for signing
|
|
267
|
+
network: CAIP-2 network ID ('stellar:testnet' or 'stellar:pubnet')
|
|
268
|
+
"""
|
|
269
|
+
self._mpp_keypair = Keypair.from_secret(secret_key)
|
|
270
|
+
self._mpp_network = network
|
|
271
|
+
self._mpp_passphrase = (
|
|
272
|
+
Network.TESTNET_NETWORK_PASSPHRASE if "testnet" in network
|
|
273
|
+
else Network.PUBLIC_NETWORK_PASSPHRASE
|
|
274
|
+
)
|
|
275
|
+
self._mpp_horizon = Server(
|
|
276
|
+
"https://horizon-testnet.stellar.org" if "testnet" in network
|
|
277
|
+
else "https://horizon.stellar.org"
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
async def mpp_fetch(self, url: str, method: str = "GET") -> Dict[str, Any]:
|
|
281
|
+
"""
|
|
282
|
+
Fetch a paid resource via MPP Charge protocol.
|
|
283
|
+
|
|
284
|
+
Sends the initial request, receives 402 with charge challenge,
|
|
285
|
+
builds and signs a USDC payment, retries with payment proof.
|
|
286
|
+
In pull mode, the server assembles and broadcasts the Soroban tx.
|
|
287
|
+
|
|
288
|
+
Returns the JSON payload from the paid resource.
|
|
289
|
+
"""
|
|
290
|
+
if not hasattr(self, "_mpp_keypair"):
|
|
291
|
+
raise RuntimeError("MPP client not initialized. Call agent.init_mpp() first.")
|
|
292
|
+
|
|
293
|
+
async with aiohttp.ClientSession() as session:
|
|
294
|
+
# Step 1: Initial request — expect 402
|
|
295
|
+
async with session.request(method, url) as resp:
|
|
296
|
+
if resp.status != 402:
|
|
297
|
+
return await resp.json()
|
|
298
|
+
|
|
299
|
+
challenge = await resp.json()
|
|
300
|
+
|
|
301
|
+
# Step 2: Build USDC payment from challenge
|
|
302
|
+
pay_req = challenge.get("paymentRequirements", [{}])[0]
|
|
303
|
+
dest = pay_req.get("receiver") or pay_req.get("destination", "")
|
|
304
|
+
amount = pay_req.get("maxAmountRequired") or pay_req.get("amount", "0.01")
|
|
305
|
+
usdc_issuer = "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5"
|
|
306
|
+
usdc_asset = Asset("USDC", usdc_issuer)
|
|
307
|
+
|
|
308
|
+
account = self._mpp_horizon.load_account(self._mpp_keypair.public_key)
|
|
309
|
+
tx = (
|
|
310
|
+
TransactionBuilder(
|
|
311
|
+
source_account=account,
|
|
312
|
+
network_passphrase=self._mpp_passphrase,
|
|
313
|
+
base_fee=100,
|
|
314
|
+
)
|
|
315
|
+
.append_payment_op(dest, usdc_asset, str(amount))
|
|
316
|
+
.set_timeout(30)
|
|
317
|
+
.build()
|
|
318
|
+
)
|
|
319
|
+
tx.sign(self._mpp_keypair)
|
|
320
|
+
xdr = tx.to_xdr()
|
|
321
|
+
|
|
322
|
+
# Step 3: Retry with payment proof
|
|
323
|
+
payment_header = json.dumps({"transaction": xdr, "mode": "pull"})
|
|
324
|
+
headers = {"X-PAYMENT": payment_header, "Content-Type": "application/json"}
|
|
325
|
+
async with session.request(method, url, headers=headers) as resp:
|
|
326
|
+
resp.raise_for_status()
|
|
327
|
+
return await resp.json()
|
|
328
|
+
|
|
178
329
|
# ─── WebSocket ───────────────────────────────────────────
|
|
179
330
|
|
|
180
331
|
async def subscribe(self, callback: Optional[Callable] = None):
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nirium
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Official Python SDK for
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Official Python SDK for Nirium autonomous agents on Stellar (x402 + MPP)
|
|
5
5
|
Author: Nirium Protocol
|
|
6
6
|
License: MIT
|
|
7
7
|
Project-URL: Homepage, https://nirium.dev
|
|
8
8
|
Project-URL: Repository, https://github.com/nirium/nirium
|
|
9
9
|
Project-URL: Documentation, https://nirium.dev/docs
|
|
10
|
-
Keywords: nirium,stellar,defi,sdk,soroban,agent
|
|
11
|
-
Requires-Python: >=3.
|
|
10
|
+
Keywords: nirium,stellar,defi,sdk,soroban,agent,x402,mpp,agentic-payments,usdc
|
|
11
|
+
Requires-Python: >=3.9
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
Requires-Dist: aiohttp>=3.9.0
|
|
14
14
|
Requires-Dist: websockets>=13.0
|
|
15
|
+
Requires-Dist: stellar-sdk>=11.0.0
|
|
16
|
+
Dynamic: requires-python
|
|
15
17
|
|
|
16
18
|
# nirium
|
|
17
19
|
|
nirium-0.2.0/setup.py
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
from setuptools import setup, find_packages
|
|
2
|
-
|
|
3
|
-
setup(
|
|
4
|
-
name="nirium-sdk",
|
|
5
|
-
version="1.0.0",
|
|
6
|
-
package_dir={"": "src"},
|
|
7
|
-
packages=find_packages(where="src"),
|
|
8
|
-
install_requires=[
|
|
9
|
-
"websockets>=11.0.3",
|
|
10
|
-
"aiohttp>=3.8.4",
|
|
11
|
-
],
|
|
12
|
-
author="Nirium Team",
|
|
13
|
-
description="Official Python SDK for Nirium Autonomous Agents",
|
|
14
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|