Skip to main content

Stateless Global Agent Identity Protocol (SGAIP) reference implementation

Project description

SGAIP Python Reference Implementation

Overview

sgaip is a production-ready reference implementation of the Stateless Global Agent Identity Protocol (SGAIP).

It provides:

  • Core library – deterministic identity derivation, Ed25519 operations
  • CLI tool – global sgaip command for key generation, signing, verification
  • Full type safety – complete type hints with mypy support
  • Comprehensive tests – unit tests with pytest + coverage
  • Production quality – linting, formatting, strict type checking

Installation

From PyPI

pip install sgaip

From Source

git clone https://github.com/k-kaundal/sgaip.git
cd sgaip/reference/python
pip install -e .

With Development Tools

pip install -e .[dev]

CLI Usage

The sgaip command provides three main operations:

1. Generate a Keypair

sgaip keygen --private agent.sk --public agent.pk

Outputs:

  • agent.sk – private key (keep secret!)
  • agent.pk – public key
  • Derived Agent ID (AID) to console

2. Sign a Message

sgaip sign --private agent.sk --message "Hello, World!"
sgaip sign --private agent.sk --file data.txt --out data.sig

Creates:

  • signature.bin (or custom --out file)

3. Verify Offline

sgaip verify --public agent.pk --signature signature.bin --message "Hello, World!"
sgaip verify --public agent.pk --signature data.sig --file data.txt

Prints:

  • ✅ Signature validity
  • Derived Agent ID (AID)

All operations work completely offline – no internet required.

Python API

Basic Usage

from sgaip import (
    generate_keypair,
    serialize_public_key,
    derive_agent_id,
    sign_challenge,
    verify_proof,
)

# Generate identity
private_key, public_key = generate_keypair()
public_bytes = serialize_public_key(public_key)

# Derive Agent Identity
aid = derive_agent_id(public_bytes)
print(f"Agent ID: {aid}")

# Sign a challenge
challenge = b"verifier-challenge-123"
signature = sign_challenge(private_key, challenge)

# Verify offline
is_valid = verify_proof(public_bytes, challenge, signature, expected_aid=aid)
assert is_valid

Advanced: Import from Package

import sgaip

# All public functions available
print(sgaip.__version__)
keypair = sgaip.generate_keypair()
aid = sgaip.derive_agent_id(sgaip.serialize_public_key(keypair[1]))

Development

Setup

cd sgaip/reference/python
python -m venv venv
source venv/bin/activate
pip install -e .[dev]

Testing

# Run all tests
pytest tests/

# With coverage
pytest tests/ --cov=sgaip --cov-report=html

# Watch mode
pytest-watch tests/

Linting & Formatting

# Format code
black sgaip/ tests/ bin/

# Check style
black --check sgaip/ tests/

# Lint with ruff
ruff check sgaip/ tests/
ruff check --fix sgaip/ tests/

# Type check
mypy sgaip/

Running Individual Commands

# Keygen
python -m sgaip keygen --private test.sk --public test.pk

# Sign
python -m sgaip sign --private test.sk --message "test"

# Verify
python -m sgaip verify --public test.pk --signature signature.bin --message "test"

Security Notes

⚠️ Reference implementation — not security audited.

  • Protect private key files (.sk) – anyone with the key controls the identity
  • Loss of private key means loss of identity (no recovery mechanism)
  • SGAIP provides authentication only, not trust or authorization
  • See specs/threat-model.md for detailed security analysis

Specifications

This package implements:

Testing & Interoperability

Python tests verify:

  • ✅ Deterministic identity derivation (same AID for same public key)
  • ✅ Ed25519 signature scheme correctness
  • ✅ Offline verification
  • ✅ CLI command handling

Run the full suite:

pytest tests/ --cov=sgaip

Troubleshooting

Issue: ModuleNotFoundError: No module named 'cryptography'

pip install cryptography

Issue: Type checking fails

mypy sgaip/ --ignore-missing-imports

Issue: Tests fail on import

Ensure you've installed in editable mode:

pip install -e .

Contributing

See DEVELOPMENT.md for contribution guidelines.

Key areas for contribution:

  • Additional test vectors
  • Performance optimizations
  • Documentation improvements
  • Additional language bindings

License

Apache License 2.0 – see LICENSE

Related Projects


Questions?
Open an issue on GitHub or see GOVERNANCE.md.

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

sgaip-0.1.3.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

sgaip-0.1.3-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file sgaip-0.1.3.tar.gz.

File metadata

  • Download URL: sgaip-0.1.3.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for sgaip-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d06e2fffa21200c7318e02b22b16340bc814c86316545a4482c7da053c2841da
MD5 beeea75120a2c314bfb2011193c2e954
BLAKE2b-256 f02dbc926ebc31b14870795aca98dc104a3dc5bebb39098a77aa9436d384bf07

See more details on using hashes here.

File details

Details for the file sgaip-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: sgaip-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for sgaip-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bd4e6f07814abf41399cbf542236ed66ce42c40e653fa0f22dd59a65f84e077c
MD5 0181b40e764b08fa6ebcb976d1198639
BLAKE2b-256 c9fe1b5b716092039e9ecf406c9f31ab5626e7906136c4518a2f9029d1b17980

See more details on using hashes here.

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