Python SDK for Agent Action Receipts (AAR)
Project description
botindex-aar
Python SDK for Agent Action Receipts (AAR).
This package is a Python 3.9+ port of the TypeScript SDK in ts-reference/, with:
- Ed25519 signing via
PyNaCl JCS-SORTED-UTF8-NOWScanonicalization- SHA-256 input/output hashing with base64url digests
- receipt creation and verification
- FastAPI and Flask middleware
- Mastercard Verifiable Intent compatibility mapping
Install
pip install botindex-aar
Quick Start
from botindex_aar import (
create_receipt,
generate_key_pair,
hash_input,
hash_output,
sign_and_finalize,
verify_receipt,
)
keys = generate_key_pair()
unsigned = create_receipt({
"agent": {"id": "trading-bot/v2", "name": "TradingBot"},
"principal": {"id": "user:alice", "type": "user"},
"action": {
"type": "trade.execute",
"target": "binance/BTCUSDT",
"method": "POST",
"status": "success",
},
"scope": {"permissions": ["trade.spot"]},
"inputHash": hash_input({"pair": "BTCUSDT", "side": "buy", "qty": 0.5}),
"outputHash": hash_output('{"orderId":"12345","filled":0.5}'),
"cost": {"amount": "0.02", "currency": "USDC"},
})
receipt = sign_and_finalize(unsigned, keys.secretKey)
result = verify_receipt(receipt)
assert result.ok
Middleware
FastAPI
from fastapi import FastAPI
from botindex_aar.middleware.fastapi import AARMiddleware
app = FastAPI()
app.add_middleware(
AARMiddleware,
agent_id="my-agent/v1",
secret_key="<base64url-or-base64-or-pem-secret>",
)
Flask
from flask import Flask
from botindex_aar.middleware.flask import install_aar_middleware
app = Flask(__name__)
install_aar_middleware(
app,
agent_id="my-agent/v1",
secret_key="<base64url-or-base64-or-pem-secret>",
)
API Reference
Core
generate_key_pair()/generateKeyPair()load_secret_key(input)/loadSecretKey(input)public_key_from_secret(secret)/publicKeyFromSecret(secret)create_receipt(opts)/createReceipt(opts)sign_receipt(unsigned, secret)/signReceipt(unsigned, secret)sign_and_finalize(unsigned, secret)/signAndFinalize(unsigned, secret)verify_receipt(receipt, public_key=None)/verifyReceipt(...)hash_input(data)/hashInput(data)hash_output(data)/hashOutput(data)canonicalize(value)canonicalize_for_signing(receipt)/canonicalizeForSigning(receipt)encode_receipt_header(receipt)/encodeReceiptHeader(receipt)
Encoding
utf8_encode,utf8_decodeencode_base64,decode_base64encode_base64url,decode_base64url
Discovery
build_well_known_config(options)/buildWellKnownConfig(options)well_known_handler(options)/wellKnownHandler(options)
Compatibility
aar_to_verifiable_intent(receipt)/aarToVerifiableIntent(receipt)verifiable_intent_to_aar(record)/verifiableIntentToAAR(record)
Typing
The package ships with py.typed (PEP 561).
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
botindex_aar-0.1.0.tar.gz
(16.0 kB
view details)
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 botindex_aar-0.1.0.tar.gz.
File metadata
- Download URL: botindex_aar-0.1.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5560c2f446dc2da5a62ec05a9e40dd6d2ec8566b0b657a5f9233f96318030882
|
|
| MD5 |
a165bd75612fc5c3d97226b5c69a3b5b
|
|
| BLAKE2b-256 |
84c28735849c8e61b79a70b0726968a25e9ab0df64eef7bcf1ba9ea601fee934
|
File details
Details for the file botindex_aar-0.1.0-py3-none-any.whl.
File metadata
- Download URL: botindex_aar-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
538a2fb85b8a9d364b9e5d13b7f5ce37d96c3332e5a822dc5be5b707c184e6de
|
|
| MD5 |
4063f711a3e514c5cd8838c58c349608
|
|
| BLAKE2b-256 |
02d85b3c98b754a7f79e6a67d6e70ec036629589fe4bd33342449ec5a5e99042
|