Skip to main content

A Python library for Akta Agent to Agent Trust Protocol

Project description

pyakta

PyPI version

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:key and did:web methods).
  • 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.1
  • pynacl>=1.5.0
  • pydantic>=2.11.0
  • pyld>=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 VerifiableCredential with 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:

  1. Ensure you have the development dependencies installed:
    pip install -e ".[dev]"
    # or if using PDM:
    # pdm install -G dev
    
  2. Navigate to the root of the project and run:
    pytest
    
    Or, if you have a Makefile with 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

pyakta-0.5.0.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

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

pyakta-0.5.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

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

Hashes for pyakta-0.5.0.tar.gz
Algorithm Hash digest
SHA256 7bff358f6ecc1f05aa96e221cd61afac0a8b3c7e209e4987200fd1a492e4d662
MD5 92e3c512a5be26c0db813bc583e95211
BLAKE2b-256 9a1e43c9d77278b9f49f6182cc5d3edf44538edd6a9c796555c8ca9995ca2a90

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyakta-0.5.0.tar.gz:

Publisher: publish.yml on lukehinds/pyakta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for pyakta-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9827a56d0f0f11b3eac40b0f4a53bf77527b856664e44676e9943f05c425bb38
MD5 27e243b456344fe4386fd925622fda67
BLAKE2b-256 1488e83755b94cb5416b50e2515ae90328abab4b4a080d12e6245cd5e433f87c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyakta-0.5.0-py3-none-any.whl:

Publisher: publish.yml on lukehinds/pyakta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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