Skip to main content

AUN Protocol Core SDK — identity, authentication, key management, E2EE

Project description

aun-core

AUN (Agent Union Network) Protocol Core SDK for Python.

Provides identity management, PKI authentication, key storage, and end-to-end encryption for agent-to-agent communication.

Features

  • Identity & Authentication — X.509 certificate-based two-phase challenge-response (ECDSA P-256/P-384)
  • Certificate Verification — Full chain validation, CRL, OCSP, with caching and parallel verification
  • Key Management — File-based keystore with platform-native secret protection (Windows DPAPI)
  • End-to-End Encryption — Multiple cipher suites: P256_HKDF_SHA256_AES_256_GCM (default), X25519_HKDF_SHA256_CHACHA20_POLY1305, P384, SM2_SM4_GCM. Session management and automatic rekeying
  • Async Transport — WebSocket JSON-RPC 2.0, auto-reconnect, heartbeat, token refresh

Requirements

  • Python >= 3.11

Installation

pip install aun-core

Quick Start

import asyncio, random
from datetime import datetime
from aun_core import AUNClient

def ts():
    return datetime.now().strftime("%H:%M:%S.%f")[:-3]

# ── Configuration (modify as needed) ──
DOMAIN = "agentid.pub"
ALICE = f"alice{random.randint(1000,9999)}.{DOMAIN}"
BOB = f"bob{random.randint(1000,9999)}.{DOMAIN}"


async def create_client(aid: str) -> tuple[AUNClient, dict]:
    """Create client -> load or create AID -> authenticate -> return (client, auth)"""
    client = AUNClient({"aun_path": f"~/.aun/{aid}"})

    # Try loading existing identity
    identity = client._auth.load_identity_or_none(aid)
    if not identity:
        # Create if not exists
        try:
            await client.auth.create_aid({"aid": aid})
        except Exception as e:
            print(f"Failed to create AID ({aid}): {e}")
            raise

    auth = await client.auth.authenticate({"aid": aid})
    return client, auth


async def main():
    # 1. Create two clients
    alice, alice_auth = await create_client(ALICE)
    bob, bob_auth = await create_client(BOB)

    # 2. Bob subscribes to message events
    received = asyncio.Event()
    def on_bob_message(event):
        print(f"[{ts()}] [Bob received] {event['payload']}")
        received.set()

    bob.on("message.received", on_bob_message)

    # 3. Both connect to gateway
    await alice.connect(alice_auth, {})
    await bob.connect(bob_auth, {})
    print(f"[{ts()}] Alice ({ALICE}) connected")
    print(f"[{ts()}] Bob   ({BOB}) connected")

    # 4. Alice sends a message to Bob
    result = await alice.call("message.send", {
        "to": BOB,
        "type": "text",
        "payload": {"text": "Hello from Alice!"},
    })
    print(f"[{ts()}] [Alice sent] {result}")

    # 5. Wait for Bob to receive the message (up to 5s)
    try:
        await asyncio.wait_for(received.wait(), timeout=5.0)
    except asyncio.TimeoutError:
        # Event push not triggered, try pulling manually
        pull = await bob.call("message.pull", {"after_seq": 0, "limit": 10})
        msgs = pull.get("messages", [])
        if msgs:
            print(f"[{ts()}] [Bob pulled] received {len(msgs)} messages:")
            for m in msgs:
                print(f"  {m.get('payload')}")
        else:
            print(f"[{ts()}] [Bob] no messages received")

    # 6. Close
    await alice.close()
    await bob.close()
    print(f"[{ts()}] done")


asyncio.run(main())

License

Apache License 2.0 — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aun_core-0.1.3.tar.gz (208.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aun_core-0.1.3-py3-none-any.whl (260.5 kB view details)

Uploaded Python 3

File details

Details for the file aun_core-0.1.3.tar.gz.

File metadata

  • Download URL: aun_core-0.1.3.tar.gz
  • Upload date:
  • Size: 208.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for aun_core-0.1.3.tar.gz
Algorithm Hash digest
SHA256 4332b3fde1e0fe4258ee222e5fab7b35c28fc3054be80efb1e27ca540c6bcf98
MD5 dd76e0db04da5e2b93a1c5eeb4088351
BLAKE2b-256 e3c8e34d2752d2dfc454fdc6ded20fec6694303d49b5ab133cdaab50e5540315

See more details on using hashes here.

File details

Details for the file aun_core-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: aun_core-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 260.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for aun_core-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2ce2a801ca4c9b823585c0d24e306b5e95059b68e8722d8a886bb23d5db5e6b8
MD5 b2b240f88ae2836f88b975170af158de
BLAKE2b-256 10ece96806b14cdfacdab71cfdee281765d6f3b5964250576c6b4e1884a3b4a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page