Agent Network Protocol (ANP)

repository·master·Indexed 43 days ago

https://github.com/agent-network-protocol/anp

An SDK and reference implementation for the Agent Network Protocol (ANP) version 1.0.3. It enables interoperable agents to perform identity authentication via DID, end-to-end encrypted communication, and automatic protocol negotiation. The SDK includes the ANPCrawler for discovering agent capabilities via OpenRPC and converting interfaces to OpenAI Tools format, the ANPClient for low-level JSON-RPC requests, and the AP2 module for secure commerce workflows including Cart and Payment Mandates.

Tokens
146.4K
Snippets
373
Records
543
Agent score
54%

What's inside ANP

  1. Overview of DID-WBA Python examples

    master

    This directory contains examples specifically for the current Python DID-WBA flow.

    Important Note on Versions:

    • New Integrations: Should use the e1 identity profile combined with HTTP Message Signatures.
    • Legacy Support: Older k1 identities and Authorization: DIDWba compatibility behaviors are maintained via SDK test coverage but no longer have independent runnable examples.

    For advanced implementation details such as FastAPI middleware integration, challenge handling, and production DID publishing, refer to DID_WBA_AUTH_GUIDE.md.

  2. Overview of AP2 Protocol Tools

    master

    The anp.ap2 module provides a set of orthogonal tools for constructing and verifying AP2 protocol data structures. It is designed to facilitate secure interactions between a 'Shopper' and a 'Merchant' through signed mandates and receipts.

    Core Components

    • Data Models: pydantic models representing core structures like CartMandate, PaymentMandate, and PaymentReceipt.
    • Builders: Functions to construct and sign mandates and credentials (e.g., build_cart_mandate, build_payment_receipt).
    • Validators: Functions to verify integrity and signatures (e.g., validate_payment_mandate, validate_credential).

    Design Principles

    • Robustness: Uses pydantic for strict data validation.
    • Extensibility: Composable models and functions for complex workflows.
    • Orthogonality: Clear separation of concerns between cart logic, payment authorization, and receipt issuance.
  3. Overview of ANP Go SDK capabilities

    master

    The ANP Go SDK provides core protocol implementations across several functional areas:

    • authentication: DID WBA document generation, legacy DIDWba auth header generation/verification, HTTP Message Signatures, DID resolvers (did:wba and did:web), and request verification with bearer token issuance.
    • proof: W3C Data Integrity proof generation/verification, Appendix-B object proofs, group receipt proofs, did:wba binding proofs, IM proofs, and RFC 9421 origin proofs.
    • wns: Handle validation, URI parsing, handle resolution, and handle binding verification.
    • direct_e2ee: Prekey bundle helpers, X3DH-derived initial session setup, symmetric ratchet step derivation, direct init/cipher message processing, and file-backed stores.
  4. Overview of ANP SDK Direct E2EE P5

    master

    The ANP SDK provides the cryptographic and wire semantics for private-chat End-to-End Encryption (E2EE) under the P5 protocol. It manages the lifecycle of secure sessions, including key exchange (X3DH-like), Double Ratchet-like send/receive chains, replay protection, and skipped-key handling.

    Supported Languages & Packages:

    • Go: golang/direct_e2ee/
    • Rust: rust/src/direct_e2ee/ (includes the V2DirectE2eeSession runtime)
    • Python: anp/direct_e2ee/
    • Dart: dart/lib/src/direct_e2ee/ (wire models and verifier adapter only; no Ratchet implementation)

    Core Primitives Managed by SDK:

    • PrekeyBundle and OneTimePrekey
    • DirectInitBody (application/anp-direct-init+json)
    • DirectCipherBody (application/anp-direct-cipher+json)
    • DirectEnvelopeMetadata and canonical AAD builders
    • ApplicationPlaintext
    • Session state (pending-confirmation, ratchet chains, replay protection)
    • File-backed reference stores for sessions, keys, and outbox records.
  5. Overview of ANP Dart SDK modules

    master

    The ANP Dart SDK provides baseline modules for the Agent Network Protocol, targeting pure Dart environments and Flutter.

    Implemented Modules:

    • Codec Helpers: base64, base64url, base58, and canonical JSON.
    • Key Material Models: Support for secp256k1, secp256r1, ed25519, and x25519 with standard PKCS#8/SPKI PEM persistence.
    • Authentication Helpers: DID WBA document creation, legacy auth header/JSON verification, HTTP Message Signatures, DID resolver shapes, and verifier/authenticator facades.
    • Proof Helpers: Go-compatible W3C proof signing input, object/group/DID-WBA wrappers, IM helpers, and RFC9421 origin proof helpers.
    • WNS Helpers: Go-compatible dot-handle validation, URI parsing/building, resolver status handling, and binding helpers.

    Limitations:

    • direct_e2ee / X3DH is intentionally not exported in v1.
  6. What is OpenANP?

    master

    OpenANP is a modern Python SDK designed to simplify development based on the Agent Network Protocol (ANP). It abstracts low-level protocol details such as DID authentication, JSON-RPC communication, OpenRPC documentation generation, and session management, allowing developers to focus on business logic.

    Key features include:

    • Rapid Server Setup: Use decorators to automatically generate protocol documentation and endpoints.
    • Simplified Client Implementation: Automatically discover and call remote agents as if they were local methods.
    • Zero-Config Schema Generation: Automatically derives JSON Schemas from Python type hints.
    • Built-in Authentication: Out-of-the-box support for DID WBA authentication.
  7. Use the P6 v2 SDK for Group End-to-End Encryption

    master

    The P6 v2 SDK implements the anp.group.e2ee.v2 protocol. It is a side-by-side implementation with v1 and does not reinterpret v1 wire objects as v2.

    Language Support:

    • Rust: Available under the anp::group_e2ee module.
    • Go: Available from the golang/group_e2ee package.

    Core Capabilities:

    • Management of closed DTOs (publish, get, create, add, remove, send, notice, incoming).
    • Handling of stable Notice IDs and specific error allocations (e.g., 5013 / group.e2ee.leaf_not_current).
    • Authentication of group.incoming via origin_context and reconstruction of group.e2ee.send Signed Request Objects.
    • owner_did + owner_device_id KeyPackage binding.
    • Canonical MLS authenticated_data and Group Application Plaintext helpers.
    • P6 did_wba_binding Object Proof and P2 Manifest eligibility verification.
    • Same-DID sibling-leaf validation.

    Note: The SDK provides the cryptographic and wire-format helpers, but the Group Host/Product remains responsible for P4 membership, owner authorization, and group-state CAS.

  8. Understand the ANP Unit Testing Framework Structure

    master

    The ANP testing framework is organized into four main modules. The directory structure is located under anp/unittest/:

    • authentication/: Completed tests for authentication logic.
    • ap2/: High-priority tests for the AP2 protocol, including mandates, hash chains, and Pydantic models.
    • fastanp/: High-priority tests for the FastANP framework, including interface management, context/session handling, and middleware.
    • anp_crawler/: Tests for the crawler component (uses existing tests in anp/anp_crawler/test/).
  9. Core Features and Design Principles of FastANP

    master

    FastANP is designed as a plugin-based utility for FastAPI rather than a rigid framework. This allows developers to maintain full control over their FastAPI application and routing while leveraging FastANP's helper tools.

    Key technical highlights include:

    • Plugin-based Design: FastANP provides auxiliary tools that do not intrude on your core logic; you define all routes.
    • Automatic Context Injection: Uses type annotations for automatic dependency injection and manages sessions based on DID + Token with zero configuration.
    • Flexibility: Supports both URL reference and embedded Interface modes, and offers optional DID WBA authentication.
    • Type Safety: Leverages full type annotations and Pydantic for data validation and automatic type conversion.
    • Standard Compliance: Fully compatible with ANP 1.0.0, OpenRPC 1.3.2, JSON-RPC 2.0, and DID WBA authentication specifications.
  10. Platform support status for ANP Dart/Flutter

    master
    The Agent Network Protocol (ANP) Dart implementation is verified for the Dart VM, Flutter mobile (Android), and Flutter Web. Desktop support is provided on a 'best effort' basis using pure Dart and Flutter test imports without platform channel code. Note that iOS/macOS builds are currently not verified due to environment requirements (Xcode/CocoaPods).
  11. Capabilities of the ANP Go SDK

    master

    The SDK provides implementations for several core ANP functional areas:

    Authentication

    • Generation and verification of DID WBA documents.
    • Generation and verification of legacy DIDWba authentication headers.
    • Generation and verification of HTTP Message Signatures.
    • Parsing of did:wba and did:web documents.
    • Request validators and Bearer Token issuance.
    • Helpers for federated request verification.

    Proofs

    • Generation and verification of W3C Data Integrity proofs.
    • Helpers for strict Appendix-B object proofs.
    • Group receipt proofs.
    • did:wba binding proofs.
    • IM proofs.

    WNS (WBA Name Service)

    • Handle validation and URI parsing.
    • Handle parsing.
    • Handle binding validation.

    Direct E2EE (End-to-End Encryption)

    • Prekey bundle helpers.
    • X3DH initial session establishment.
    • Symmetric ratchet derivation.
    • Direct init and cipher message processing.
    • File storage and reference client helpers.
  12. Use the W3C Data Integrity Proof module

    master

    The anp.proof module provides tools for generating and verifying digital signatures for JSON documents following the W3C Data Integrity specification. It is designed for long-term verifiable claims like Verifiable Credentials (VCs), Agent Identity Claims, and DID documentation, as opposed to short-lived session tokens (JWT/JWS).

    Key Features:

    • W3C Standard Compliance: Fully follows the W3C Data Integrity spec.
    • Signature Suites: Supports EcdsaSecp256k1Signature2019 (for secp256k1 keys) and Ed25519Signature2020 (for Ed25519 keys).
    • Deterministic: Uses RFC 8785 (JSON Canonicalization Scheme) to ensure signatures are consistent.
    • Security: Supports domain binding and challenge strings to prevent replay attacks.
    • Offline Verification: Any third party with the public key can verify the proof without contacting a central server.
    from cryptography.hazmat.primitives.asymmetric import ec
    from anp.proof import generate_w3c_proof, verify_w3c_proof
    
    # 1. Generate key pair
    private_key = ec.generate_private_key(ec.SECP256K1())
    public_key = private_key.public_key()
    
    # 2. Generate Proof for a document
    document = {
        "@context": ["https://www.w3.org/ns/did/v1"],
        "id": "did:wba:example.com:alice",
        "name": "Agent Alice",
        "capabilities": ["search", "booking"]
    }
    
    signed_doc = generate_w3c_proof(
        document=document,
        private_key=private_key,
        verification_method="did:wba:example.com:alice#key-1",
        proof_purpose="assertionMethod"
    )
    
    # 3. Verify Proof
    is_valid = verify_w3c_proof(signed_doc, public_key)
    print(f"Verification result: {is_valid}")  # Output: True