Skip to main content

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-NOWS canonicalization
  • 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_decode
  • encode_base64, decode_base64
  • encode_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


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)

Uploaded Source

Built Distribution

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

botindex_aar-0.1.0-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

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

Hashes for botindex_aar-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5560c2f446dc2da5a62ec05a9e40dd6d2ec8566b0b657a5f9233f96318030882
MD5 a165bd75612fc5c3d97226b5c69a3b5b
BLAKE2b-256 84c28735849c8e61b79a70b0726968a25e9ab0df64eef7bcf1ba9ea601fee934

See more details on using hashes here.

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

Hashes for botindex_aar-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 538a2fb85b8a9d364b9e5d13b7f5ce37d96c3332e5a822dc5be5b707c184e6de
MD5 4063f711a3e514c5cd8838c58c349608
BLAKE2b-256 02d85b3c98b754a7f79e6a67d6e70ec036629589fe4bd33342449ec5a5e99042

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