Skip to main content

DIAP Python SDK

Decentralized Intelligent Agent Protocol — Python implementation.

中文版说明:README.zh-CN.md — 完整中文文档,含 ZKP 证明原理说明。

PyPI version License: MIT Python >= 3.10

A Python implementation of the DIAP protocol for decentralized identity management and agent authentication using zero-knowledge proofs.

Implementations

Language Repository Package
Protocol Spec DIAP
Python (this repo) DIAP_Python_SDK diap-sdk on PyPI
TypeScript DIAP_TS_SDK @diap/sdk on npm
Rust DIAP_Rust_SDK diap-sdk on crates.io

各语言实现保持协议一致,可在不同语言 agent 之间互通(DID 兼容、ZKP 可交叉验证、P2P 共享 iroh/libp2p 网络)。

Features

  • Decentralized Identity: W3C did:key implementation (Ed25519)
  • Zero-Knowledge Proofs: Real BN128 elliptic-curve Schnorr proofs via py_ecc (snarkjs CLI as optional backend)
  • IPFS Integration: Decentralized storage with IPNS support (auto-installs Kubo)
  • P2P Networking: Real iroh gossip communication + libp2p identity/signing
  • Agent Authentication: Secure agent identity and verification
  • Encryption: Ed25519 keys (PyNaCl, RFC 8032) with AES-256-GCM + ECIES encryption

Installation

pip install diap-sdk

Or install from source:

git clone https://github.com/logos-42/DIAP_Python_SDK.git
cd DIAP_Python_SDK
pip install -e .

国内用户可使用镜像加速:pip install diap-sdk -i https://pypi.tuna.tsinghua.edu.cn/simple

Quick Start

from diap import KeyManager, DIDBuilder

# Generate a key pair
km = KeyManager()
key_pair = km.generate()

# Create DID document
builder = DIDBuilder()
doc = builder.create_did_document(key_pair)
print(f"DID: {doc.id}")

ZKP Proof (real elliptic-curve, py_ecc)

from diap.zkp import UniversalZKManager

mgr = UniversalZKManager()  # default backend: py_ecc (BN128 Schnorr)
inputs = {
    "expected_did_hash": [1234567890, 987654321],
    "public_key_hash": 11111111,
    "nonce_hash": 22222222,
}
proof = mgr.generate_proof(inputs)
assert mgr.verify_proof(proof)  # True

Iroh P2P Communication (real gossip)

import asyncio
from diap import IrohCommunicator

async def main():
    node = IrohCommunicator()
    await node.start()
    node.add_message_handler("default", lambda m: print(f"got: {m.payload}"))
    await node.connect(f"<peer_node_id>@<relay_url>")  # node_id@relay
    await node.broadcast(b"hello")
    await node.stop()

asyncio.run(main())

Development

Install development dependencies:

pip install -e ".[dev]"

Run tests:

pytest tests/

Project Structure

diap/
├── __init__.py           # Main package exports
├── key_manager.py         # Ed25519 key generation and management
├── did_builder.py         # W3C DID Document creation
├── did_cache.py          # DID document caching
├── identity_manager.py   # Identity registration and ZKP verification
├── noir_zkp.py          # ZKP circuit integration
├── ipfs_client.py       # IPFS HTTP API client
├── ipfs_node_manager.py # Local Kubo node management
├── ipns_manager.py      # IPNS publishing/resolution
├── kubo_installer.py    # Auto-install Kubo IPFS daemon
├── agent_auth.py        # Agent authentication
├── agent_verification.py # Agent verification
├── real_name_auth.py    # Real-name authentication
├── pubsub_authenticator.py # PubSub authentication
├── nonce_manager.py     # Nonce management
├── encrypted_peer_id.py # PeerID encryption
├── encrypted_iroh_id.py # Iroh ID encryption (ECIES)
├── iroh_communicator.py # Iroh P2P communication (real gossip)
├── iroh_node.py         # Iroh node management
├── p2p/
│   ├── hyperswarm_communicator.py  # Hyperswarm P2P (TCP adaptation)
│   └── libp2p_communicator.py      # libp2p identity/signing + TCP transport
├── types/               # Type definitions
├── utils/               # Utilities (crypto, encoding, logger)
└── zkp/                 # ZKP backends (py_ecc, snarkjs, simplified)

Publish (维护者)

One-command release (requires ~/.pypirc with PyPI token):

bash scripts/release.sh

License

MIT License


相关仓库:协议规范 DIAP · TypeScript DIAP_TS_SDK · Rust DIAP_Rust_SDK

Download files

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

Source Distribution

diap_sdk-0.1.5.tar.gz (66.0 kB view details)

Uploaded Source

Built Distribution

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

diap_sdk-0.1.5-py3-none-any.whl (77.7 kB view details)

Uploaded Python 3

File details

Details for the file diap_sdk-0.1.5.tar.gz.

File metadata

  • Download URL: diap_sdk-0.1.5.tar.gz
  • Upload date:
  • Size: 66.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.8

File hashes

Hashes for diap_sdk-0.1.5.tar.gz
Algorithm Hash digest
SHA256 3186a1d367604e53a872d8f72901caff248626c8dd9f09086cbb8fe514934792
MD5 6200845172af4412772a1bc4d8dadef9
BLAKE2b-256 9fcfd66682bd361df2f1284f245bd78b11ddba2d7be865a9ab1fa9754fbdcc8c

See more details on using hashes here.

File details

Details for the file diap_sdk-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: diap_sdk-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 77.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.8

File hashes

Hashes for diap_sdk-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 aaa5dc37377e5329f3def7c030d0f5734365007aace0bbbc554b4000f8573b25
MD5 1759a9faed2dc254c38b523dd47aa63c
BLAKE2b-256 aceef781be55dd35ea709342085631a6e5c4620daeca1c06652deb19de0177ec

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page