Skip to main content

Python SDK for Observer Protocol — agent identity, verification, and trust scoring

Project description

Observer Protocol Python SDK

Register agents, verify transactions, and manage attestations on Observer Protocol.

Install

pip install observer-protocol

Quick start

from observer_protocol import ObserverClient

client = ObserverClient()

# Generate a keypair (or use your existing Ed25519 key)
public_key, private_key = ObserverClient.generate_keypair()

# Register your agent
agent = client.register_agent(public_key=public_key, agent_name="My Agent")
print(f"Agent DID: {agent.agent_did}")

# Prove key ownership
challenge = client.request_challenge(agent.agent_id)
signature = ObserverClient.sign_challenge(private_key, challenge.nonce)
client.verify_agent(agent.agent_id, signature)

# Retrieve your VAC (Verified Agent Credential)
vac = client.get_vac(agent.agent_id)

# Check your trust score
score = client.get_trust_score(agent.agent_id)
print(f"Trust score: {score.trust_score}/100")

Verify a Lightning payment

import hashlib

client = ObserverClient(api_key="your_api_key")

preimage = "your_preimage_hex"
payment_hash = hashlib.sha256(bytes.fromhex(preimage)).hexdigest()

result = client.verify_lightning_payment(
    receipt_reference="urn:uuid:unique-tx-id",
    payment_hash=payment_hash,
    preimage=preimage,
    presenter_role="payee",  # "payee" or "payer"
)

print(f"Verified: {result.verified}")
print(f"Tier: {result.chain_specific.get('verification_tier')}")

Verify a TRON transaction

result = client.verify_tron_transaction(
    receipt_reference="urn:uuid:unique-tx-id",
    tron_tx_hash="abc123...",
)

print(f"Verified: {result.verified}")
print(f"TRONScan: {result.explorer_url}")

Register a VAC extension

# Register your platform's reputation system as a VAC extension
client.register_extension(
    extension_id="myplatform_reputation_v1",
    display_name="My Reputation Score",
    issuer_did="did:web:myplatform.com:op-identity",
    schema={
        "type": "object",
        "properties": {
            "score": {"type": "integer", "minimum": 0, "maximum": 1000},
            "last_evaluated": {"type": "string", "format": "date-time"},
        },
    },
)

# Issue an attestation for an agent
client.submit_extension_attestation(
    extension_id="myplatform_reputation_v1",
    credential={...},  # Pre-signed W3C VC
    summary_fields=["score"],
)

Get agent data

# Public profile
agent = client.get_agent("agent_id")
print(f"{agent.agent_name}: {agent.trust_score}/100, {agent.transaction_count} txns")

# Attestations
attestations = client.get_attestations("agent_id")
for att in attestations:
    print(f"  {att.partner_name} ({att.partner_type}): {att.claims}")

# Trust score breakdown
score = client.get_trust_score("agent_id")
if score.components:
    print(f"  Transactions: {score.components.receipt_score}")
    print(f"  Counterparties: {score.components.counterparty_score}")
    print(f"  Recency: {score.components.recency_score}")

# Activity history
activities = client.get_activities("did:web:observerprotocol.org:agents:agent_id")
for act in activities:
    print(f"  {act.activity_type} on {act.transaction_rail}: {act.transaction_amount}")

# DID document
did_doc = client.get_did_document("agent_id")

Authentication

Most endpoints are public. Chain verification, audit writes, and extension registration require an API key:

# Public (no key needed)
client = ObserverClient()
agent = client.get_agent("agent_id")

# Authenticated (key required)
client = ObserverClient(api_key="your_api_key")
result = client.verify_lightning_payment(...)

To get an API key, email dev@observerprotocol.org.

Supported chains

Chain Method Status
Lightning verify_lightning_payment() Live
TRON verify_tron_transaction() Live
Stacks verify_chain("stacks", ...) Stub

Documentation

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

observer_protocol-0.1.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

observer_protocol-0.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file observer_protocol-0.1.0.tar.gz.

File metadata

  • Download URL: observer_protocol-0.1.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for observer_protocol-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9d81bd29432c75b803f307e8383ad1e10177622c067b3f1d19856a6e9d0666a2
MD5 a73efefadb172bfda47ca9e9b86d4f3d
BLAKE2b-256 6c13490ce01d5add8837e22c0acac3820646a6fed5b0dd24a431bfef3b016c5e

See more details on using hashes here.

File details

Details for the file observer_protocol-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for observer_protocol-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb44391eb196087b4eae733030348621aef3ddf86f6deb4759eb5b8956f73157
MD5 3352649bb0886312c6d0ab92786d46ee
BLAKE2b-256 c7ec99dfa67e861155223fd36bebb2ab3e93e26408afdb430e8073a3a08d50d6

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