macauleyjustin/ANproto-Python
null
{ "createdAt": "2025-11-07T18:41:58Z", "defaultBranch": "main", "description": null, "fullName": "macauleyjustin/ANproto-Python", "homepage": null, "language": "Python", "name": "ANproto-Python", "pushedAt": "2025-11-07T18:42:04Z", "stargazersCount": 1, "topics": [], "updatedAt": "2025-11-22T19:48:43Z", "url": "https://github.com/macauleyjustin/ANproto-Python"}ANProto Python Implementation
Section titled “ANProto Python Implementation”A minimal Python implementation of ANProto, providing Ed25519-based message signing and verification with timestamps. This implementation is compatible with the Go and JS versions of ANProto.
Features
Section titled “Features”- Ed25519 key pair generation
- Message hashing (SHA-256)
- Message signing with timestamps
- Signature verification and message extraction
- Command-line interface
- Cross-implementation compatibility
Quick Start
Section titled “Quick Start”Installation (Using Virtual Environment - Recommended)
Section titled “Installation (Using Virtual Environment - Recommended)”# Create and activate virtual environmentpython3 -m venv .venvsource .venv/bin/activate # On Windows use: .venv\Scripts\activate
# Install packagepip install -e .Basic Usage
Section titled “Basic Usage”# Generate a new key pairpython an_cli.py gen > key.txt
# Hash and sign a messageHASH=$(python -c "import anproto; print(anproto.Hash('hello'))")python an_cli.py sign "$HASH" "$(cat key.txt)" > signed.txt
# Verify a signed messagepython an_cli.py open "$(cat signed.txt)"Python API Example
Section titled “Python API Example”from anproto import Gen, Hash, Sign, Open
# Generate a new key pairkey = Gen() # Returns base64(pub) + base64(priv)
# Hash a messagemsg_hash = Hash("Hello World") # Returns base64(sha256(msg))
# Sign a messagesigned = Sign(msg_hash, key) # Returns pubB64 + base64(sig || timestamp || msg)
# Verify and extract messagemessage = Open(signed) # Returns timestamp + payload as stringAPI Reference
Section titled “API Reference”Gen() → str
Section titled “Gen() → str”Generates a new Ed25519 key pair and returns them as concatenated base64 strings:
- First 44 characters: base64(public key)
- Remaining 88 characters: base64(private key seed || public key)
Hash(d: str) → str
Section titled “Hash(d: str) → str”Computes SHA-256 hash of the input string and returns it as base64.
Sign(h: str, k: str) → str
Section titled “Sign(h: str, k: str) → str”Signs a message hash using the provided key:
h: Message hash (from Hash())k: Key string from Gen() Returns: pubB64 + base64(signature || timestamp || hash)
Open(m: str) → str
Section titled “Open(m: str) → str”Verifies and extracts the message from a signed payload:
m: Signed message from Sign() Returns: timestamp + payload as string Raises: ValueError for invalid format, InvalidSignature for verification failure
Development
Section titled “Development”Running Tests
Section titled “Running Tests”# Using the test scriptbash run_tests.sh
# Or directly with unittestpython -m unittest discover -s tests -p "test*.py" -vMaking CLI Executable (Optional)
Section titled “Making CLI Executable (Optional)”chmod +x an_cli.pyRequirements
Section titled “Requirements”- Python 3.8 or higher
- cryptography >= 40.0
- See requirements.txt for full dependencies
License
Section titled “License”This is a minimal implementation for demonstration purposes. See the original protocol specification for licensing details.