| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
A Python implementation of the SchemaPin protocol for cryptographic schema integrity verification of AI tools.
SchemaPin provides cryptographic verification of AI tool schemas using ECDSA P-256 signatures and Trust-On-First-Use (TOFU) key pinning. This Python implementation serves as the reference implementation for the protocol.
This release adds two additive, optional trust signals. v1.3 verifiers ignore both fields and continue to work unchanged.
DNS lookups depend on dnspython, which is optional — install with pip install schemapin[dns] (or pip install dnspython). The parsing and match helpers themselves have no extra dependencies.
# Install latest stable version
pip install schemapin
# Install with development dependencies
pip install schemapin[dev]
# Install with testing dependencies only
pip install schemapin[test]# Clone repository and install in development mode
git clone https://github.com/thirdkey/schemapin.git
cd schemapin/python
pip install -e .[dev]After installation, the following CLI tools will be available:
SchemaPin provides three command-line tools for common operations:
Generate ECDSA or RSA key pairs with optional .well-known template:
# Generate ECDSA key pair with .well-known template
schemapin-keygen --type ecdsa --developer "Your Company" --well-known
# Generate RSA 4096-bit key pair
schemapin-keygen --type rsa --key-size 4096 --output-dir ./keys
# Generate keys in DER format
schemapin-keygen --type ecdsa --format der --prefix mykeysSign JSON schema files with private keys:
# Sign a single schema
schemapin-sign --key private.pem --schema schema.json --output signed.json
# Sign with metadata
schemapin-sign --key private.pem --schema schema.json --developer "Your Company" --version "1.0"
# Batch sign multiple schemas
schemapin-sign --key private.pem --batch ./schemas/ --output-dir ./signed/
# Sign from stdin
echo '{"type": "object"}' | schemapin-sign --key private.pem --stdinVerify signed schemas with public keys or discovery:
# Verify with public key
schemapin-verify --schema signed.json --public-key public.pem
# Verify with domain discovery and interactive pinning
schemapin-verify --schema signed.json --domain example.com --tool-id my-tool --interactive
# Batch verify with auto-pinning
schemapin-verify --batch ./signed/ --domain example.com --auto-pin
# Verify from stdin with JSON output
echo '{"schema": {...}, "signature": "..."}' | schemapin-verify --stdin --public-key public.pem --jsonRun the CLI examples script to see detailed usage patterns:
cd python/examples
python cli_usage_examples.pyfrom schemapin.utils import SchemaSigningWorkflow, create_well_known_response
from schemapin.crypto import KeyManager
# 1. Generate key pair
private_key, public_key = KeyManager.generate_keypair()
private_key_pem = KeyManager.export_private_key_pem(private_key)
public_key_pem = KeyManager.export_public_key_pem(public_key)
# 2. Sign your tool schema
schema = {
"name": "calculate_sum",
"description": "Calculates the sum of two numbers",
"parameters": {
"type": "object",
"properties": {
"a": {"type": "number", "description": "First number"},
"b": {"type": "number", "description": "Second number"}
},
"required": ["a", "b"]
}
}
signing_workflow = SchemaSigningWorkflow(private_key_pem)
signature = signing_workflow.sign_schema(schema)
# 3. Create .well-known response
well_known_response = create_well_known_response(
public_key_pem,
"Your Organization",
"contact@yourorg.com"
)
# Host well_known_response at https://yourdomain.com/.well-known/schemapin.jsonfrom schemapin.utils import SchemaVerificationWorkflow
verification_workflow = SchemaVerificationWorkflow()
# Verify schema with automatic key pinning
result = verification_workflow.verify_schema(
schema,
signature,
"yourdomain.com/calculate_sum",
"yourdomain.com",
auto_pin=True
)
if result['valid']:
print("✅ Schema signature is valid")
if result['first_use']:
print("🔑 Key pinned for future use")
else:
print("❌ Schema signature is invalid")
print("Error:", result['error'])workflow = SchemaSigningWorkflow(private_key_pem)
signature = workflow.sign_schema(schema)workflow = SchemaVerificationWorkflow()
result = workflow.verify_schema(schema, signature, tool_id, domain, auto_pin)Run the included examples:
# Tool developer workflow
cd python/examples
python tool_developer.py
# Client verification workflow
python client_verification.pycd python
python -m pytest tests/ -v
# Run code quality checks
ruff check .
bandit -r . --exclude tests/This Python implementation is designed to be fully compatible with the JavaScript implementation:
MIT License - see LICENSE file for details.
For issues and questions:
| Back | FazBrowse Home | New Git URL |