A Python library for Akta Agent to Agent Trust Protocol
Project description
pyakta
Python library for Akta.
Akta is a system designed to enable secure and verifiable interactions between AI agents. It establishes a robust framework for capability-based access control, allowing agents to confidently delegate tasks and share resources with fine-grained control. The system leverages concepts from Decentralized Identifiers (DIDs) and Verifiable Credentials (VCs) to create a cryptographically secure and auditable environment for autonomous agent operations.
Important Note: Akta is currently a prototype. The codebase has not undergone a third-party security audit and is not yet considered suitable for production environments. Development will move fast, expect breaking changes, bugs, and other issues.
Features
- Capability-based access control using Verifiable Credentials.
- Generation and management of Decentralized Identifiers (
did:keyanddid:webmethods). - Creation, signing, and verification of W3C Verifiable Credentials using Ed25519Signature2020.
- Pydantic models for core data structures (VCs, DIDs, Proofs).
- Cryptographically secure operations leveraging PyNaCl.
- JSON-LD processing for credential normalization.
Requirements
- Python 3.11+
base58>=2.1.1pynacl>=1.5.0pydantic>=2.11.0pyld>=2.0.4
Installation
You can install pyakta in a few ways:
From PyPI:
pip install pyakta
From Source:
git clone https://github.com/lukehinds/pyakta.git
cd pyakta
Usage
Here's a basic example of how to generate a DID and create/sign a Verifiable Credential:
from pyakta.did import DIDKey
from pyakta.credentials import VerifiableCredential
from datetime import datetime, timedelta, UTC # Make sure UTC is imported
# 1. Generate an issuer DID (did:key method)
issuer_did_key = DIDKey()
print(f"Issuer DID: {issuer_did_key.did}")
print(f"Issuer Public Key (Multibase): {issuer_did_key.public_key_multibase}")
# 2. Define subject and credential details
subject_did_str = "did:example:subject123"
now = datetime.now(UTC)
# 3. Build the Verifiable Credential
vc = VerifiableCredential().build(
issuer_did=issuer_did_key.did,
subject_did=subject_did_str,
types=["VerifiableCredential", "AgentAccessCredential"],
issuance_date=now,
expiration_date=now + timedelta(days=30),
credential_subject={
"id": subject_did_str,
"serviceEndpoint": "https://example.com/agent/service",
"actions": ["read", "write"]
}
)
# 4. Sign the Verifiable Credential
# The verification method ID for did:key is typically the DID itself + # + public key multibase
verification_method = f"{issuer_did_key.did}#{issuer_did_key.public_key_multibase}"
vc.sign(
issuer_signing_key=issuer_did_key.signing_key,
verification_method_id=verification_method
)
print("\nSigned Verifiable Credential:")
print(vc.to_json(indent=2))
# 5. Verify the Verifiable Credential
is_valid = vc.verify_signature(
issuer_public_key=issuer_did_key.verify_key,
expected_issuer_did=issuer_did_key.did,
expected_subject_did=subject_did_str
)
print(f"\nVC Signature Valid: {is_valid}")
# Check expiration
print(f"VC Expired: {vc.is_expired()}")
This example demonstrates:
- Generating a
did:key. - Building a
VerifiableCredentialwith specific subject data, type, issuance, and expiration. - Signing the credential using the issuer's signing key.
- Verifying the credential's signature.
Running Tests
Tests are managed using pytest. To run the tests:
- Ensure you have the development dependencies installed:
pip install -e ".[dev]" # or if using PDM: # pdm install -G dev
- Navigate to the root of the project and run:
pytest
Or, if you have aMakefilewith a test target (as indicated by your test output):make test
This will discover and run all tests in the pyakta/tests directory and provide a coverage report.
Contributing
We honestly love getting contributions, from engineers of all levels and background!
Don't be put off contributing, we're all learning as we go and everyone starts somewhere.
You could always look for good first issues to get started, and tag me in the PR (@lukehinds) and I am happy to give you plently of friendly support and guidance (if you want it).
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyakta-0.5.0.tar.gz.
File metadata
- Download URL: pyakta-0.5.0.tar.gz
- Upload date:
- Size: 25.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bff358f6ecc1f05aa96e221cd61afac0a8b3c7e209e4987200fd1a492e4d662
|
|
| MD5 |
92e3c512a5be26c0db813bc583e95211
|
|
| BLAKE2b-256 |
9a1e43c9d77278b9f49f6182cc5d3edf44538edd6a9c796555c8ca9995ca2a90
|
Provenance
The following attestation bundles were made for pyakta-0.5.0.tar.gz:
Publisher:
publish.yml on lukehinds/pyakta
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyakta-0.5.0.tar.gz -
Subject digest:
7bff358f6ecc1f05aa96e221cd61afac0a8b3c7e209e4987200fd1a492e4d662 - Sigstore transparency entry: 230170486
- Sigstore integration time:
-
Permalink:
lukehinds/pyakta@b6922613fedca75a75dea01d26a37a15262755f7 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/lukehinds
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b6922613fedca75a75dea01d26a37a15262755f7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyakta-0.5.0-py3-none-any.whl.
File metadata
- Download URL: pyakta-0.5.0-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9827a56d0f0f11b3eac40b0f4a53bf77527b856664e44676e9943f05c425bb38
|
|
| MD5 |
27e243b456344fe4386fd925622fda67
|
|
| BLAKE2b-256 |
1488e83755b94cb5416b50e2515ae90328abab4b4a080d12e6245cd5e433f87c
|
Provenance
The following attestation bundles were made for pyakta-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on lukehinds/pyakta
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyakta-0.5.0-py3-none-any.whl -
Subject digest:
9827a56d0f0f11b3eac40b0f4a53bf77527b856664e44676e9943f05c425bb38 - Sigstore transparency entry: 230170488
- Sigstore integration time:
-
Permalink:
lukehinds/pyakta@b6922613fedca75a75dea01d26a37a15262755f7 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/lukehinds
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b6922613fedca75a75dea01d26a37a15262755f7 -
Trigger Event:
release
-
Statement type: