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.1.tar.gz (10.2 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.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: observer_protocol-0.1.1.tar.gz
  • Upload date:
  • Size: 10.2 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.1.tar.gz
Algorithm Hash digest
SHA256 8e8931de0bc3fcb5b07b9196f10b4bd044ed73fe707aa6c2e31dbc0ad2da1fe1
MD5 bed444cac1eddb707aa8319a49f04e0b
BLAKE2b-256 4d30db83d2cbb00f7d47b56b01660e7114d56a1463eb8903baa6e6219b3453b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for observer_protocol-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 37f5708d27a2aa0e1b308542fd566a168cd2ebdf25def455216b5f20c3f35822
MD5 cb2be7057eb7071bfb21db5936cf2af3
BLAKE2b-256 4b2656eda9ddc9330fa3e4672dd5505b3152492c0b93f9a25ce7f38177a660d7

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