Skip to main content

self_agent_sdk/
constants.rs

1// SPDX-FileCopyrightText: 2025-2026 Social Connect Labs, Inc.
2// SPDX-License-Identifier: BUSL-1.1
3// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
4
5use alloy::primitives::Address;
6use alloy::sol;
7use std::str::FromStr;
8
9/// Supported network names.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum NetworkName {
12    Mainnet,
13    Testnet,
14}
15
16/// Per-network configuration (registry address + RPC URL).
17#[derive(Debug, Clone)]
18pub struct NetworkConfig {
19    pub registry_address: Address,
20    pub rpc_url: &'static str,
21}
22
23/// Get the network configuration for a given network.
24pub fn network_config(network: NetworkName) -> NetworkConfig {
25    match network {
26        NetworkName::Mainnet => NetworkConfig {
27            registry_address: Address::from_str("0xaC3DF9ABf80d0F5c020C06B04Cced27763355944")
28                .unwrap(),
29            rpc_url: "https://forno.celo.org",
30        },
31        NetworkName::Testnet => NetworkConfig {
32            registry_address: Address::from_str("0x043DaCac8b0771DD5b444bCC88f2f8BBDBEdd379")
33                .unwrap(),
34            rpc_url: "https://forno.celo-sepolia.celo-testnet.org",
35        },
36    }
37}
38
39/// Default network — production-safe.
40pub const DEFAULT_NETWORK: NetworkName = NetworkName::Mainnet;
41
42/// Default signature validity window (5 minutes).
43pub const DEFAULT_MAX_AGE_MS: u64 = 5 * 60 * 1000;
44
45/// Default cache TTL for on-chain status (1 minute).
46pub const DEFAULT_CACHE_TTL_MS: u64 = 60_000;
47
48/// Warning threshold: proofs expiring within this many days trigger `is_expiring_soon`.
49pub const EXPIRY_WARNING_DAYS: i32 = 30;
50
51/// Action byte for proof refresh requests.
52pub const ACTION_REFRESH: u8 = 0x46;
53
54/// Action byte for read-only nullifier identification.
55pub const ACTION_IDENTIFY: u8 = 0x49;
56
57/// Request headers used by the signing protocol.
58pub mod headers {
59    /// Agent's Ethereum address (informational — identity is recovered from signature).
60    pub const ADDRESS: &str = "x-self-agent-address";
61    /// ECDSA or Ed25519 signature over the request.
62    pub const SIGNATURE: &str = "x-self-agent-signature";
63    /// Unix timestamp (milliseconds) for replay protection.
64    pub const TIMESTAMP: &str = "x-self-agent-timestamp";
65    /// Key type: "ed25519" for Ed25519 agents; absent implies secp256k1 ECDSA.
66    pub const KEYTYPE: &str = "x-self-agent-keytype";
67    /// Agent's public key (used for Ed25519 agents).
68    pub const KEY: &str = "x-self-agent-key";
69}
70
71// Registry ABI — matches the TS SDK's REGISTRY_ABI exactly.
72sol! {
73    #[sol(rpc)]
74    interface IAgentRegistry {
75        function isVerifiedAgent(bytes32 agentPubKey) external view returns (bool);
76        function getAgentId(bytes32 agentPubKey) external view returns (uint256);
77        function hasHumanProof(uint256 agentId) external view returns (bool);
78        function getHumanNullifier(uint256 agentId) external view returns (uint256);
79        function getAgentCountForHuman(uint256 nullifier) external view returns (uint256);
80        function sameHuman(uint256 agentIdA, uint256 agentIdB) external view returns (bool);
81        function getProofProvider(uint256 agentId) external view returns (address);
82        function isProofFresh(uint256 agentId) external view returns (bool);
83        function selfProofProvider() external view returns (address);
84        function ownerOf(uint256 tokenId) external view returns (address);
85
86        struct AgentCredentials {
87            string issuingState;
88            string[] name;
89            string idNumber;
90            string nationality;
91            string dateOfBirth;
92            string gender;
93            string expiryDate;
94            uint256 olderThan;
95            bool[3] ofac;
96        }
97        function getAgentCredentials(uint256 agentId) external view returns (AgentCredentials);
98
99        // A2A Agent Cards
100        function getAgentMetadata(uint256 agentId) external view returns (string);
101        function updateAgentMetadata(uint256 agentId, string metadata) external;
102        function agentRegisteredAt(uint256 agentId) external view returns (uint256);
103        // ERC-8004: proof expiry
104        function proofExpiresAt(uint256 agentId) external view returns (uint256);
105        // Replay-protection nonces for registration signatures
106        function agentNonces(address agent) external view returns (uint256);
107    }
108}
109
110// Provider ABI — used to query provider metadata.
111sol! {
112    #[sol(rpc)]
113    interface IHumanProofProvider {
114        function providerName() external view returns (string);
115        function verificationStrength() external view returns (uint8);
116    }
117}