Download src/nacc_node/pairing.py from MCP-1st-Birthday/NACC-Network_Agentic_Command_Control: direct link, hf CLI and curl.
- Browser
- Download file 940 Bytes
-
https://huggingface.co/spaces/MCP-1st-Birthday/NACC-Network_Agentic_Command_Control/resolve/main/src/nacc_node/pairing.py
- Command line
-
hf download hf://spaces/MCP-1st-Birthday/NACC-Network_Agentic_Command_Control/src/nacc_node/pairing.py
-
curl -L -o pairing.py https://huggingface.co/spaces/MCP-1st-Birthday/NACC-Network_Agentic_Command_Control/resolve/main/src/nacc_node/pairing.py
940 Bytes
| """ | |
| Node Pairing Logic | |
| Generates and verifies 6-digit pairing codes for secure node initialization. | |
| """ | |
| import secrets | |
| import string | |
| import time | |
| from dataclasses import dataclass | |
| from typing import Optional | |
| class PairingSession: | |
| code: str | |
| node_id: str | |
| created_at: float | |
| expires_at: float | |
| def is_expired(self) -> bool: | |
| return time.time() > self.expires_at | |
| def generate_pairing_code(length: int = 6) -> str: | |
| """Generate a secure random numeric code.""" | |
| alphabet = string.digits | |
| return ''.join(secrets.choice(alphabet) for _ in range(length)) | |
| def create_session(node_id: str, ttl_seconds: int = 300) -> PairingSession: | |
| """Create a new pairing session with a unique code.""" | |
| code = generate_pairing_code() | |
| now = time.time() | |
| return PairingSession( | |
| code=code, | |
| node_id=node_id, | |
| created_at=now, | |
| expires_at=now + ttl_seconds | |
| ) | |