Skip to main content

Settle protocol SDK for Python — receipt kernel, verifyReceipt, and LangChain + CrewAI adapters.

Project description

settle-sdk (Python)

F5.2 — Python port of the Settle TypeScript SDK. Same canonical hashing algorithm; outputs are byte-identical so a Python verifier can confirm a TS-emitted receipt and vice versa.

Install

pip install settle-sdk

(Until first PyPI publish, install from this repo: pip install -e packages/python-sdk from a Settle clone.)

Requires blake3 (auto-installed).

Quick start

from settle_sdk import kernel_commit, verify_receipt, compute_capability_hash_hex

# Compute a capability hash for a tool spec
hash_hex = compute_capability_hash_hex({
    "domain": "translate.example.com",
    "method": "POST",
    "path": "/v1/translate",
    "amount_lamports": "20000",
    "version": 1,
})

# Compute the 4-hash kernel commit for a payment
result = kernel_commit({
    "kind": "direct_send",
    "request_id": "11111111-2222-3333-4444-555555555555",
    "amount_lamports": "500000",
    "sender": "B4cArR1M1MySM4dn4HeDdifdPiF98wTNmbzKYg6to2Cp",
    "recipient": "C9HAssvFBtEgHvZRVGdfxcUwrGfu5iK4Z3FKn52Ns7yY",
    "decision_slot": 1000,
    "purpose_text": "test payment",
})

print("receipt_hash:", result.receipt_hash)
print("context_hash:", result.context_hash)

# Verify a receipt by re-deriving its hashes
v = verify_receipt({
    "receipt": result.canonical_receipt,
    "reason": result.canonical_reason,
    "policy_snapshot": result.canonical_policy_snapshot,
    "http": { "method": "POST", "path": "/_kernel/direct_send" },
    "expected": {
        "receipt_hash": result.receipt_hash,
        "reason_hash": result.reason_hash,
        "policy_snapshot_hash": result.policy_snapshot_hash,
        "purpose_hash": result.purpose_hash,
    },
})
assert v.ok, f"verification failed: {v.mismatches}"

What's in this port

  • purpose_text_hash, canonical_receipt_hash, canonical_reason_hash, canonical_policy_snapshot_hash, canonical_purpose_hash — the 5 canonical hash functions.
  • compute_capability_hash_hex — capability hash derivation.
  • kernel_commit — F2.0 universal receipt kernel for any kind (x402_spend, direct_send, link_send, streaming_claim, escrow_*, refund).
  • verify_receipt — recompute and compare against expected hashes.

What's NOT in this port (yet)

  • Solana transaction building (use solders / solana-py directly).
  • On-chain record_receipt ix builder (build manually from the IDL JSON in programs/settle-agent-card/target/idl/settle_agent_card.json).
  • Sealed-box encryption (use pynacl directly with the same X25519 + XChaCha20 parameters as @settle/sdk).

These will land in subsequent versions if there's demand. The hashing core ships first because it's what every verifier needs.

Cross-implementation parity

If you compute a hash in TypeScript and a hash in Python from the same canonical object, you must get the same bytes. This is enforced by:

  1. JSON serialization: sorted keys, no whitespace, both runtimes use the exact same algorithm in _stable_json.
  2. NFC Unicode normalization for purpose text in both runtimes.
  3. BLAKE3 — both runtimes use the reference blake3 implementation.

If you find a parity bug, file an issue with reproducer inputs from both sides.

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

settle_protocol_sdk-0.2.1.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

settle_protocol_sdk-0.2.1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file settle_protocol_sdk-0.2.1.tar.gz.

File metadata

  • Download URL: settle_protocol_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for settle_protocol_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6cb4afb1abb4fe49472a73e8209097eaba53cd73d49e272488c1782945b280dc
MD5 77559669331f43d3a1cff8eb4b675293
BLAKE2b-256 f3f3b57a2c6831c9a1223f1abba274eb448f265623c0e14fe66ff03f5f418826

See more details on using hashes here.

File details

Details for the file settle_protocol_sdk-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for settle_protocol_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f719977ef30dc2fb03cfb5a76321e938fec0acd5c4ac56d6338a3531567baed
MD5 44863504d25a73dcd2b5f5c12ba4c560
BLAKE2b-256 047e50848d46bc6292648879cea4755949c930b600751f1d3429946285b54fdc

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