Skip to main content

Python SDK for the Shadownet protocol.

Project description

shadownet-py

PyPI Python CI License: MIT Typed

Python SDK for the Shadownet protocol. Implements the v0.1 RFCs in idiomatic, async, fully-typed Python.

What this is

A reusable library — not a server, not a canonical core. It exposes the protocol primitives needed to build a Shadow:

  • DID resolutiondid:key (local) and did:web (async, cached, 16 KiB cap per RFC-0002).
  • Verifiable Credentials — VC-JWT issuance + verification, freshness proofs, BitstringStatusList revocation (fail-closed >L1 per RFC-0003).
  • SCA client — proof-session, issuance, freshness, callback-HMAC verification (RFC-0004).
  • SNS client — async resolver with TTL + negative cache, signed-record verification (RFC-0005).
  • A2A profile — session-token + Verifiable Presentation handshake; framework-agnostic verifier; optional FastAPI dependency (RFC-0006).
  • Webhooks — outbound dispatcher with the spec retry schedule + degraded-state tracking; receiver-side verifier (RFC-0007).
  • MCP — Pydantic models + a Sidecar Protocol + a one-call helper that wires every RFC-0007 tool onto a FastMCP server.

It is consumed by:

  • hermes-social — the Sidecar reference implementation.
  • shadownet-cloud — the multi-tenant Sidecar host (forthcoming).

Interop with shadownet-go and shadownet-ts is verified at the wire level by shadownet-conformance.

Install

pip install shadownet
# or
uv add shadownet

Python 3.12+ required. For the optional FastAPI helpers:

pip install 'shadownet[fastapi]'

Quick examples

Issue and verify a credential

from shadownet.crypto.ed25519 import Ed25519KeyPair
from shadownet.did.key import derive_did_key
from shadownet.did.resolver import Resolver
from shadownet.vc.credential import issue_credential, new_credential, verify_credential

issuer_kp = Ed25519KeyPair.generate()
issuer_did = derive_did_key(issuer_kp.public_bytes)

subject_kp = Ed25519KeyPair.generate()
subject_did = derive_did_key(subject_kp.public_bytes)

cred = new_credential(
    issuer=issuer_did,
    subject=subject_did,
    level="urn:shadownet:level:L2",
    subject_type="person",
)
token = issue_credential(issuer_key=issuer_kp, issuer_kid=issuer_did, credential=cred)

verified = await verify_credential(token, resolver=Resolver())
assert verified.level == "urn:shadownet:level:L2"

Mint and verify a presentation

from shadownet.vc.presentation import mint_presentation, verify_presentation
from shadownet.trust import TrustStore

verifier_did = "did:key:z6MkVerifier..."
vp_jwt = mint_presentation(
    holder_key=subject_kp,
    holder_did=subject_did,
    audience_did=verifier_did,
    credentials=[token],
)

trust = TrustStore.from_pairs([(issuer_did, ["urn:shadownet:level:L2"])])
result = await verify_presentation(
    vp_jwt,
    resolver=Resolver(),
    expected_audience=verifier_did,
    trust_store=trust,
)
assert len(result.credentials) == 1

Run the inbound A2A handshake

from shadownet.a2a.server import verify_handshake
from shadownet.sca.predicate import LevelLeaf

ctx = await verify_handshake(
    request_headers,                 # any Mapping[str, str]
    expected_audience=my_did,
    resolver=Resolver(),
    trust_store=trust,
    required_predicate=LevelLeaf(level="urn:shadownet:level:L2"),
)
# ctx.caller_did is the verified peer DID
# ctx.presentation.credentials are the credentials that survived every check

Register the RFC-0007 MCP tools

from mcp.server.fastmcp import FastMCP
from shadownet.mcp.register import register_shadownet_tools

server = FastMCP(name="my-sidecar")
register_shadownet_tools(server, my_sidecar_implementation)
# all required RFC-0007 tools are now exposed; opt into the optional ones with
# include_optional={"present", "audit"}

The full set of public APIs is curated under shadownet.{crypto, did, vc, sca, sns, trust, a2a, webhook, mcp}. See the tests/integration/test_birthday_flow.py for an end-to-end Sarah → Lukas walkthrough.

Conformance

tests/conformance/ validates every Pydantic wire model against the JSON Schemas in shadownet-specs/schemas/. CI fails on any drift.

Develop

uv sync --all-extras           # runtime + dev + extras
uv run pytest                  # full suite (incl. conformance), with coverage
uv run pytest -m network       # opt-in network tests
uv run ruff check .            # lint
uv run ruff format .           # format
uv run mypy src/shadownet      # strict typing

Engineering conventions and contribution rules live in CLAUDE.md.

Specifications

Versioning

Releases track the protocol version they implement (0.1.x while the spec is at v0.1). Pre-releases use the PEP 440 form (0.1.0rc1) and the matching git tag (v0.1.0-rc.1).

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

shadownet-0.1.1.tar.gz (39.5 kB view details)

Uploaded Source

Built Distribution

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

shadownet-0.1.1-py3-none-any.whl (59.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shadownet-0.1.1.tar.gz
  • Upload date:
  • Size: 39.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for shadownet-0.1.1.tar.gz
Algorithm Hash digest
SHA256 990d17d451a2f4a7cb735a814152a21a5df97ad84a507231fd211eae26d02649
MD5 7477ac857ea1db30d52e0641d0d31b45
BLAKE2b-256 3d7eb9eeee669cfd9a77f02200572e0d9d43fc293b580bc898e8c2ae3e741204

See more details on using hashes here.

Provenance

The following attestation bundles were made for shadownet-0.1.1.tar.gz:

Publisher: release.yml on shadownet-protocol/shadownet-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: shadownet-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 59.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for shadownet-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fcc0535aaa9cf2f7b743cf475312d3f67944be3face1a5cf4ae21ef09baf94ea
MD5 5e5c565bd6cde8795b2bbd24c2403c9b
BLAKE2b-256 e22bbfcf11922a1e7105938f30469b836b1dfbe0c0b3ae0506c1b92b08d947d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for shadownet-0.1.1-py3-none-any.whl:

Publisher: release.yml on shadownet-protocol/shadownet-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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