A production-ready, W3C DID Core v1.0 compliant Python SDK and CLI tool for creating, managing, and resolving Decentralized Identifiers (DIDs) for AI agents. Built with type safety, full specification compliance, and developer experience in mind, this SDK enables seamless integration of decentralized identity into agent-based systems.
The SDK provides a clean, intuitive API centered around the Identity abstraction, making it easy for developers to generate did:key identifiers, build compliant DID documents, and resolve existing DIDs—all while maintaining strict adherence to W3C standards. Whether you're building autonomous agents, multi-agent systems, or agent-to-agent communication protocols, this SDK provides the foundational identity layer your agents need.
Part of the PayeLink Agent SDK suite:
payelink-agent-identity-sdk- This package (DID generation for agent identity)payelink-agent-pay-sdk- Agent-to-agent paymentspayelink-agent-search-sdk- Agent discovery and search
- ✅ W3C DID Core v1.0 Compliant - Full specification compliance
- ✅ did:key Method - Purely generative, no ledger required
- ✅ Ed25519 Support - Recommended cryptographic keys
- ✅ DID Resolution - Computational resolution for did:key
- ✅ Type Safety - Pydantic models for validation
- ✅ CLI Tool - Command-line interface for quick operations
- ✅ SDK - Programmatic access for agent integration
pip install -e .Or with development dependencies:
pip install -e ".[dev]"from payelink_agent_identity import Identity
# Create a new identity
identity = Identity.create()
print(identity.did)
print(identity.document.json(indent=2))
# Resolve an existing DID
identity = Identity.resolve("did:key:z6Mk...")# Generate a new DID
payelink-agent-identity generate
# Generate with specific verification relationships
payelink-agent-identity generate -vr authentication -vr assertionMethod
# Generate with service endpoint
payelink-agent-identity generate --service-type MessagingService:https://agent.example.com/inbox
# Resolve a DID
payelink-agent-identity resolve did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK
# Validate DID syntax
payelink-agent-identity validate did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doKfrom payelink_agent_identity import Identity
# Create a new identity
identity = Identity.create()
# Access the DID and document
did = identity.did
document = identity.document
public_key = identity.public_key
private_key = identity.private_key # ⚠️ Handle securely!
# Export document
print(identity.document.json(indent=2))from payelink_agent_identity import Identity
from payelink_agent_identity.utils.constants import (
VR_AUTHENTICATION,
VR_ASSERTION,
VR_KEY_AGREEMENT
)
identity = Identity.create(
verification_relationships=[
VR_AUTHENTICATION,
VR_ASSERTION,
VR_KEY_AGREEMENT
]
)from payelink_agent_identity import Identity, ServiceEndpoint
service = ServiceEndpoint(
id="#agent-inbox",
type="MessagingService",
serviceEndpoint="https://agent.example.com/inbox"
)
identity = Identity.create(services=[service])from payelink_agent_identity import Identity
# Resolve any did:key DID
identity = Identity.resolve("did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK")
print(identity.document.json(indent=2))# Export as JSON
json_output = identity.document.json(indent=2)
# Export as JSON-LD
json_ld_output = identity.document.json_ld(indent=2)Generate a new DID for an agent.
Options:
--key-type: Cryptographic key type (default: Ed25519)--verification-relationships/-vr: Verification relationships (can specify multiple)--service-type/-st: Service endpoint (format: type:endpoint_url)--output-format: Output format (json or json-ld, default: json-ld)--save-to: Save DID document to file--save-keys: Save private key to .key file (⚠️ WARNING: Handle with care!)--also-known-as/-aka: Alternative identifiers (can specify multiple)
Examples:
# Basic generation
payelink-agent-identity generate
# With verification relationships
payelink-agent-identity generate -vr authentication -vr assertionMethod
# With service endpoint
payelink-agent-identity generate --service-type MessagingService:https://agent.example.com/inbox
# Save to file
payelink-agent-identity generate --save-to my-did.json --save-keysResolve a DID to its document.
Options:
--output-format: Output format (json or json-ld)
Example:
payelink-agent-identity resolve did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doKValidate DID syntax.
Example:
payelink-agent-identity validate did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doKVerify a DID document file is valid.
Example:
payelink-agent-identity verify-document my-did.jsonThe SDK is organized into the following modules:
payelink_agent_identity.sdk- Core SDK classes (Identity, Generator, Resolver, DocumentBuilder)payelink_agent_identity.sdk.types- Pydantic models for DID documentspayelink_agent_identity.crypto- Cryptographic key operationspayelink_agent_identity.utils- Utilities (encoding, validation, constants)payelink_agent_identity.cli- CLI commands
- Never expose private keys in DID documents (W3C Spec Section 9.2)
- Store private keys securely - Use proper key management systems
- Key rotation - Support for key rotation is planned for future releases
- Verification method separation - Use different keys for different purposes
See the examples/ directory for complete usage examples:
basic_generation.py- Basic DID generationagent_usage.py- Creating DIDs for agents with services
pytestblack payelink_did/
ruff check payelink_did/This implementation follows the W3C DID Core v1.0 specification:
- ✅ Section 3: Identifier syntax
- ✅ Section 4: Data model
- ✅ Section 5: Core properties
- ✅ Section 6: Representations (JSON, JSON-LD)
- ✅ Section 7: Resolution
- ✅ Section 8: Methods (did:key)
MIT
Contributions welcome! Please see the project repository for guidelines.