### Run DID WBA Authentication Examples Source: https://github.com/agent-network-protocol/agentconnect/blob/master/README.md Commands to execute the provided Python examples demonstrating Decentralized Identifier (DID) Web-based Authentication (WBA) functionality. These examples showcase basic DID creation, authentication, token verification, and client-side testing. ```bash python basic.py ``` ```bash python full.py ``` ```bash python client.py ``` -------------------------------- ### Install AgentConnect Python Library Source: https://github.com/agent-network-protocol/agentconnect/blob/master/README.md Instructions to install the `agent-connect` Python library using pip. This command fetches the package from PyPI and installs it into your Python environment, making the library's functionalities available for use. ```bash pip install agent-connect ``` -------------------------------- ### Examples of DID Document Generation Script Usage Source: https://github.com/agent-network-protocol/agentconnect/blob/master/tools/did_generater/README_did_generater.md Provides practical examples of how to invoke the `generate_did_doc.py` script for different scenarios, including basic usage, specifying an agent description URL, and enabling verbose logging. ```bash # Basic usage python generate_did_doc.py "did:wba:service.agent-network-protocol.com:wba:user:lkcoffe" # With agent description URL python generate_did_doc.py "did:wba:service.agent-network-protocol.com:wba:user:lkcoffe" --agent-description-url "https://example.com/agent.json" # Enable detailed logging python generate_did_doc.py "did:wba:service.agent-network-protocol.com:wba:user:lkcoffe" -v ``` -------------------------------- ### Python: Complete Asynchronous DID WBA Authentication Flow Source: https://github.com/agent-network-protocol/agentconnect/blob/master/docs/did/getting_started.md This comprehensive asynchronous Python example illustrates a full DID WBA authentication flow using `aiohttp` and `agent_connect`. It includes steps for generating unique identifiers, creating and persisting DID documents and associated private keys, uploading the DID document to a server, initializing an authentication client, generating DID WBA `Authorization` headers for a test URL, and sending an authenticated request to verify the setup. ```python import secrets import asyncio import aiohttp import json from pathlib import Path from agent_connect.authentication import create_did_wba_document, DIDWbaAuthHeader async def main(): # 1. Generate unique identifier unique_id = secrets.token_hex(8) # 2. Set server information server_domain = "example.com" base_path = f"/wba/user/{unique_id}" did_path = f"{base_path}/did.json" # 3. Create DID document did_document, keys = create_did_wba_document( hostname=server_domain, path_segments=["wba", "user", unique_id] ) # 4. Save private keys and DID document user_dir = Path("did_keys") / f"user_{unique_id}" user_dir.mkdir(parents=True, exist_ok=True) # Save private keys for method_fragment, (private_key_bytes, _) in keys.items(): private_key_path = user_dir / f"{method_fragment}_private.pem" with open(private_key_path, 'wb') as f: f.write(private_key_bytes) # Save DID document did_document_path = user_dir / "did.json" with open(did_document_path, 'w', encoding='utf-8') as f: json.dump(did_document, f, indent=2) # 5. Upload DID document to server document_url = f"https://{server_domain}{did_path}" async with aiohttp.ClientSession() as session: async with session.put( document_url, json=did_document, headers={'Content-Type': 'application/json'} ) as response: if response.status != 200: print(f"Failed to upload DID document: {response.status}") return # 6. Create DIDWbaAuthHeader instance private_key_path = user_dir / "key-1_private.pem" auth_client = DIDWbaAuthHeader( did_document_path=str(did_document_path), private_key_path=str(private_key_path) ) # 7. Create authentication request test_url = f"https://{server_domain}/wba/test" auth_headers = auth_client.get_auth_header(test_url) # 8. Send authentication request async with aiohttp.ClientSession() as session: async with session.get(test_url, headers=auth_headers) as response: if response.status == 200: print("DID authentication successful") # Get token from response headers token = auth_client.update_token(test_url, dict(response.headers)) if token: print(f"Received token: {token}") else: print(f"DID authentication failed: {response.status}") if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Run Meta-Protocol Negotiation Demo (Bob's Node) Source: https://github.com/agent-network-protocol/agentconnect/blob/master/README.md Command to start Bob's node for the meta-protocol negotiation demo. This node must be initiated first to establish the communication channel before Alice's node can connect and begin the negotiation process. ```bash python negotiation_bob.py ``` -------------------------------- ### Run Meta-Protocol Negotiation Demo (Alice's Node) Source: https://github.com/agent-network-protocol/agentconnect/blob/master/README.md Command to start Alice's node for the meta-protocol negotiation demo. This command should be executed after Bob's node is running to allow for successful connection, protocol negotiation, and data communication. ```bash python negotiation_alice.py ``` -------------------------------- ### Example AgentConnect Get User Education Error Response Source: https://github.com/agent-network-protocol/agentconnect/blob/master/agent_connect/python/app_protocols/protocol_base/protocol_documention.md An example JSON response illustrating an error scenario for the Get User Education API. It shows how validation errors or other issues are communicated, including the message type, ID, error code, and a detailed error message. ```json { "messageType": "getUserEducation", "messageId": "123e4567-e89b-12d3-a456-426614174000", "code": 400, "error": { "message": "Invalid user_id format", "details": "The user_id must be a valid UUID." } } ``` -------------------------------- ### Clone AgentConnect GitHub Repository Source: https://github.com/agent-network-protocol/agentconnect/blob/master/README.md Command to clone the AgentConnect project repository from GitHub. This provides access to the full source code, examples, and additional documentation, which is necessary for running the provided demos. ```bash git clone https://github.com/agent-network-protocol/AgentConnect.git ``` -------------------------------- ### Example DID Document JSON Structure Source: https://github.com/agent-network-protocol/agentconnect/blob/master/tools/did_generater/README_did_generater.md Illustrates the expected JSON structure for a generated DID document, including context, ID, verification methods, and authentication details. This document conforms to W3C DID specifications. ```json { "@context": [ "https://www.w3.org/ns/did/v1", "https://w3id.org/security/suites/jws-2020/v1", "https://w3id.org/security/suites/secp256k1-2019/v1" ], "id": "did:wba:service.agent-network-protocol.com:wba:user:lkcoffe", "verificationMethod": [ { "id": "did:wba:service.agent-network-protocol.com:wba:user:lkcoffe#key-1", "type": "EcdsaSecp256k1VerificationKey2019", "controller": "did:wba:service.agent-network-protocol.com:wba:user:lkcoffe", "publicKeyJwk": { "kty": "EC", "crv": "secp256k1", "x": "...", "y": "...", "kid": "..." } } ], "authentication": [ "did:wba:service.agent-network-protocol.com:wba:user:lkcoffe#key-1" ] } ``` -------------------------------- ### Example Private Key Document JSON Structure Source: https://github.com/agent-network-protocol/agentconnect/blob/master/tools/did_generater/README_did_generater.md Shows the JSON format for the private key document, which maps a DID to its associated private key files and their types. This document helps manage the generated private keys. ```json { "did": "did:wba:service.agent-network-protocol.com:wba:user:lkcoffe", "keys": { "key-1": { "path": "key-1_private.pem", "type": "EcdsaSecp256k1" } } } ``` -------------------------------- ### Example Education History Error Response Source: https://github.com/agent-network-protocol/agentconnect/blob/master/tests/test_code/generated_code_test/education_history_protocol/protocol_document.md This JSON snippet provides an example of an error response from the education history API. It illustrates how the API communicates issues, including the `messageType`, `messageId`, HTTP `code`, and a detailed `error` object containing an `errorCode` and `errorDescription` for diagnostic purposes. ```json { "messageType": "EducationHistoryResponse", "messageId": "abcd-1234", "code": 400, "error": { "errorCode": "INVALID_USER_ID", "errorDescription": "The provided user ID is invalid or not found." } } ``` -------------------------------- ### AgentConnect Get User Education Request Message Schema Source: https://github.com/agent-network-protocol/agentconnect/blob/master/agent_connect/python/app_protocols/protocol_base/protocol_documention.md JSON Schema defining the structure for requests to retrieve a user's educational background. It specifies required fields like 'messageType', 'messageId', 'userId', and optional parameters for 'includeDetails', 'page', and 'pageSize' to support pagination. ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "messageType": { "type": "string", "const": "getUserEducation" }, "messageId": { "type": "string", "format": "uuid" }, "userId": { "type": "string" }, "includeDetails": { "type": "boolean", "default": false }, "page": { "type": "integer", "minimum": 1, "default": 1 }, "pageSize": { "type": "integer", "minimum": 1, "default": 10 } }, "required": ["messageType", "messageId", "userId"], "additionalProperties": false } ``` -------------------------------- ### AgentConnect Get User Education API Protocol Details Source: https://github.com/agent-network-protocol/agentconnect/blob/master/agent_connect/python/app_protocols/protocol_base/protocol_documention.md Comprehensive documentation for the AgentConnect API protocol designed to retrieve a user's educational background. This section covers the core requirements, the step-by-step interaction flow between client and server, and the standard error handling mechanisms using HTTP status codes. ```APIDOC API: Get User Education Description: Protocol to retrieve educational background information for a single user. Requirements: - Allow fetching educational background details for a specified user based on `user_id`. - The educational background must include the institution name, major, degree, achievements, start and end dates. - Support error handling and parameter validation. - Implement pagination for retrieved data. Protocol Flow: Interaction Flow: 1. Request: The client sends a request to the server containing `user_id` and an optional parameter `include_details`. 2. Validation: The server validates the input parameters. 3. Fetch Data: Upon successful validation, the server retrieves the educational experience data. 4. Response: The server sends back a response containing the educational details or an error message if applicable. Error Handling: Uses standard HTTP status codes: - 200 OK: Request was successful and data is returned. - 400 Bad Request: The request parameters were invalid. The `error` field will contain details. - 404 Not Found: No educational data found for the given `user_id`. - 500 Internal Server Error: An unexpected server error occurred. ``` -------------------------------- ### AgentConnect Get User Education Response Message Schema Source: https://github.com/agent-network-protocol/agentconnect/blob/master/agent_connect/python/app_protocols/protocol_base/protocol_documention.md JSON Schema defining the structure for responses containing a user's educational background. It includes fields for 'messageType', 'messageId', 'code' (status), an array of 'data' for educational entries, 'pagination' details, and an 'error' object for failure cases. ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "messageType": { "type": "string", "const": "getUserEducation" }, "messageId": { "type": "string", "format": "uuid" }, "code": { "type": "integer" }, "data": { "type": "array", "items": { "type": "object", "properties": { "institution": { "type": "string" }, "major": { "type": "string" }, "degree": { "type": "string", "enum": ["Bachelor", "Master", "Doctorate"] }, "achievements": { "type": "string" }, "startDate": { "type": "string", "format": "date" }, "endDate": { "type": "string", "format": "date" } }, "required": ["institution", "major", "degree", "startDate", "endDate"] } }, "pagination": { "type": "object", "properties": { "currentPage": { "type": "integer" }, "totalPages": { "type": "integer" }, "totalItems": { "type": "integer" } } }, "error": { "type": "object", "properties": { "message": { "type": "string" }, "details": { "type": "string" } }, "required": ["message"] } }, "required": ["messageType", "messageId", "code"], "additionalProperties": false } ``` -------------------------------- ### JSON Schema for Get User Education Request Message Source: https://github.com/agent-network-protocol/agentconnect/blob/master/tests/test_code/generated_code_test/last_test/protocol_document.md This JSON schema defines the structure and validation rules for the request message used to fetch a user's educational background. It specifies required fields like `messageType`, `messageId`, `userId`, and optional parameters for `includeDetails`, `page`, and `pageSize`. ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "messageType": { "type": "string", "const": "getUserEducation" }, "messageId": { "type": "string", "format": "uuid" }, "userId": { "type": "string" }, "includeDetails": { "type": "boolean", "default": false }, "page": { "type": "integer", "minimum": 1, "default": 1 }, "pageSize": { "type": "integer", "minimum": 1, "default": 10 } }, "required": ["messageType", "messageId", "userId"], "additionalProperties": false } ``` -------------------------------- ### Generate DID Document and Private Key using Python Script Source: https://github.com/agent-network-protocol/agentconnect/blob/master/tools/did_generater/README_did_generater.md Shows the basic command-line usage for the `generate_did_doc.py` script, including required and optional parameters for DID string, agent description URL, and verbose logging. ```bash python generate_did_doc.py [--agent-description-url URL] [--verbose] ``` -------------------------------- ### Build AgentConnect4Java Project with Maven Source: https://github.com/agent-network-protocol/agentconnect/blob/master/agent_connect/java/README.md This command uses Maven to clean the project, compile source code, run tests, and package the application into a distributable JAR file. It's the standard way to build the project from source, ensuring all dependencies are resolved and the project is ready for deployment or execution. ```bash mvn clean package ``` -------------------------------- ### Generate DID Document using Tool Source: https://github.com/agent-network-protocol/agentconnect/blob/master/README.md Command-line tool to generate a Decentralized Identifier (DID) document. This utility supports optional arguments for specifying an agent description URL and enabling verbose output for detailed execution logs. ```bash python generate_did_doc.py [--agent-description-url URL] [--verbose] ``` -------------------------------- ### Python: Manual DID WBA Signature Generation Source: https://github.com/agent-network-protocol/agentconnect/blob/master/docs/did/getting_started.md This Python snippet demonstrates the manual process of creating a DID WBA (Decentralized Identifier Web-Based Authentication) signature. It covers loading a private key, generating a nonce and timestamp, constructing the data to be signed, canonicalizing the JSON data using `jcs`, hashing with SHA-256, signing the hash with an elliptic curve private key, and encoding the signature for use in an `Authorization` header. ```python # Load private key with open("path/to/private_key.pem", "rb") as f: private_key_bytes = f.read() private_key = load_pem_private_key(private_key_bytes, password=None) # Generate nonce and timestamp nonce = secrets.token_hex(16) timestamp = datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ') # Construct data to sign data_to_sign = { "nonce": nonce, "timestamp": timestamp, "service": "example.com", "did": "did:wba:example.com:user:alice" } # Normalize JSON import jcs canonical_json = jcs.canonicalize(data_to_sign) # Calculate SHA-256 hash content_hash = hashlib.sha256(canonical_json).digest() # Sign with private key if isinstance(private_key, ec.EllipticCurvePrivateKey): signature_bytes = private_key.sign( content_hash, ec.ECDSA(hashes.SHA256()) ) else: # Handle other types of private keys pass # Encode signature from base64 import urlsafe_b64encode signature = urlsafe_b64encode(signature_bytes).rstrip(b'=').decode('ascii') # Construct authentication JSON auth_json = { "did": "did:wba:example.com:user:alice", "nonce": nonce, "timestamp": timestamp, "verification_method": "key-1", # Verification method ID used "signature": signature } # Create Authorization header auth_header = {"Authorization": f"DID {json.dumps(auth_json)}"} ``` -------------------------------- ### Python: Configure AgentConnect Logging Levels Source: https://github.com/agent-network-protocol/agentconnect/blob/master/docs/did/getting_started.md This snippet shows how to configure logging levels for the `AgentConnect` library using `set_log_color_level`. It allows developers to set the verbosity of logs (e.g., `DEBUG`, `INFO`, `WARNING`, `ERROR`) to assist in troubleshooting DID-related issues within the application. ```python import logging from agent_connect.utils.log_base import set_log_color_level # Set log level set_log_color_level(logging.DEBUG) # or INFO, WARNING, ERROR ``` -------------------------------- ### Define Education History Response Message Schema Source: https://github.com/agent-network-protocol/agentconnect/blob/master/tests/test_code/generated_code_test/education_history_protocol/protocol_document.md This JSON Schema defines the structure for the `EducationHistoryResponse` message. It outlines the format for returning a user's education history, including fields for `messageType`, `messageId`, `code` (HTTP status), and an array of `educationHistory` records. Each record details institutional information such as name, major, degree, achievements, and attendance dates. ```APIDOC { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "EducationHistoryResponse", "type": "object", "properties": { "messageType": { "type": "string", "const": "EducationHistoryResponse" }, "messageId": { "type": "string", "description": "The unique identifier matching the request message" }, "code": { "type": "integer", "description": "HTTP status code indicating the result of the request" }, "educationHistory": { "type": "array", "description": "List of education history records", "items": { "type": "object", "properties": { "institution": { "type": "string", "description": "Name of the educational institution" }, "major": { "type": "string", "description": "Major studied at the institution" }, "degree": { "type": "string", "description": "Degree achieved", "enum": ["Bachelor", "Master", "Doctorate"] }, "achievements": { "type": "string", "description": "Achievements while attending the institution" }, "startDate": { "type": "string", "format": "date", "description": "Start date of attendance in YYYY-MM-DD format" }, "endDate": { "type": "string", "format": "date", "description": "End date of attendance in YYYY-MM-DD format" } }, "required": ["institution", "major", "degree", "startDate", "endDate"], "additionalProperties": false } } }, "required": ["messageType", "messageId", "code", "educationHistory"], "additionalProperties": false } ``` -------------------------------- ### Define Education History Request Message Schema Source: https://github.com/agent-network-protocol/agentconnect/blob/master/tests/test_code/generated_code_test/education_history_protocol/protocol_document.md This JSON Schema defines the structure for the `EducationHistoryRequest` message. It specifies required fields such as `messageType`, `messageId`, and `userId`, along with an optional `includeDetails` flag. This schema ensures proper validation and consistency of incoming requests for user education history. ```APIDOC { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "EducationHistoryRequest", "type": "object", "properties": { "messageType": { "type": "string", "const": "EducationHistoryRequest" }, "messageId": { "type": "string", "description": "A unique identifier for the request message" }, "userId": { "type": "string", "description": "The unique identifier for the user", "minLength": 1 }, "includeDetails": { "type": "boolean", "description": "Optional flag to include detailed information", "default": false } }, "required": ["messageType", "messageId", "userId"], "additionalProperties": false } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.