DIAP Python SDK
Decentralized Intelligent Agent Protocol — Python implementation.
中文版说明:README.zh-CN.md — 完整中文文档,含 ZKP 证明原理说明。
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:keyimplementation (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
Metadata
Release files for diap-sdk 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| diap_sdk-0.1.5.tar.gz | 66.0 kB | Without provenance | Details for diap_sdk-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| diap_sdk-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for diap_sdk-0.1.5-py3-none-any.whl |
Total release size: 143.7 kB
Release files / diap_sdk-0.1.5.tar.gz
| Download URL | diap_sdk-0.1.5.tar.gz |
|---|---|
| Size | 66.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3186a1d367604e53a872d8f72901caff248626c8dd9f09086cbb8fe514934792
|
|
BLAKE2b-256 checksum How to use checksums |
9fcfd66682bd361df2f1284f245bd78b11ddba2d7be865a9ab1fa9754fbdcc8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.8
|
Release files / diap_sdk-0.1.5-py3-none-any.whl
| Download URL | diap_sdk-0.1.5-py3-none-any.whl |
|---|---|
| Size | 77.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aaa5dc37377e5329f3def7c030d0f5734365007aace0bbbc554b4000f8573b25
|
|
BLAKE2b-256 checksum How to use checksums |
aceef781be55dd35ea709342085631a6e5c4620daeca1c06652deb19de0177ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.8
|
Security for diap-sdk 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.