Repository navigation
feat(sdk): implement Phase 3 SDK tooling for agentguard-py and agentguard-js. - #102
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Title: feat(sdk): Implement Phase 3 SDK Tooling (
agentguard-py&agentguard-js)Overview
This pull request implements Phase 3: SDK Development (Tooling) for the AgentGuard on-chain Identity and RBAC ecosystem on Stellar & Soroban. It delivers two standalone, fully-tested, zero-defect SDKs:
agentguard-py: A Python SDK for autonomous AI agents and LLM scripts to manage Ed25519 cryptographic keypairs, deterministically serialize payloads, and sign requests with replay protection.agentguard-js: A TypeScript/Node.js SDK for Web2 Resource Providers to cryptographically verify agent signatures, enforce strict 5-minute replay thresholds, simulate Soroban smart contracts with automatic retry resilience, and gate endpoints via Express.js middleware.Both packages achieve 100.00% line coverage, strict typing (
mypy --strict& TypeScriptstrict: true), custom error handling, and verified cross-language cryptographic interoperability.Key Changes & Architecture
1. Python SDK (
agentguard-py)agentguard/keys.py):stellar-sdk&pynacl/ libsodium).AgentKeypair.generate()creates new Ed25519 keypairs mapped to Stellar StrKey G-addresses and S-seeds.AgentKeypair.from_secret(secret_seed)loads keys from Stellar S-seeds, 64-char hex strings, or raw 32-byte seeds.AgentKeypair.from_public_key(public_key)allows initialization of verifier-only instances.raw_public_key,raw_secret_seed,sign(), andverify().agentguard/signer.py):canonicalize_payload) ensuring identical key ordering and compact spacing across runtimes.${timestamp}.${canonical_json}.AgentAuthHeadermodel andcreate_auth_headers(...)helper generating:X-Agent-Public-KeyX-Agent-TimestampX-Agent-SignatureAuthorization: AgentGuard key="...",ts="...",sig="..."validate_timestamp(timestamp)enforcing a 5-minute maximum age and clock drift bounds.agentguard/errors.py):AgentGuardError, plusAgentKeyError,AgentSigningError,AgentSignatureInvalid,AgentTimestampExpiredError, andSerializationError.pyproject.tomltargeting Python 3.10+, PEP 561 marker (py.typed), andREADME.mdwith a 5-line agent quickstart.2. TypeScript / Node.js SDK (
agentguard-js)src/verifier.ts):validateTimestamp(timestamp, options)strictly rejecting timestamps older than 5 minutes (300,000ms) or exceeding forward clock skew tolerance.verifySignature(publicKey, payload, signature, timestamp)andassertSignatureValid(...)supporting hex (128 chars) and base64 formats.src/contract.ts):@stellar/stellar-sdkwith fully configurable endpoints (no hardcoded RPC URLs).AgentGuardContract.checkAccess(agentId, role, resourceId) -> Promise<boolean>simulating on-chaincheck_access.AgentGuardContract.verifyAgent(agentId, role) -> Promise<boolean>simulating on-chainverify_agent.AgentGuardContract.setDefault(instance)for zero-boilerplate middleware integration.src/middleware.ts):requireAgentRole(role: string, options?: RequireRoleOptions):AgentAuthHeaderfrom headers (case-insensitiveX-Agent-*orAuthorization).401 Unauthorizedwithcode: "TIMESTAMP_EXPIRED"if stale).401 Unauthorizedwithcode: "INVALID_SIGNATURE"if invalid).checkAccesson-chain (returns403 Forbiddenwithcode: "FORBIDDEN"if unauthorized).503 Service Unavailablewithcode: "CONTRACT_READ_ERROR"if RPC network fails after retries.req.agentId,req.agentPublicKey, andreq.agentTimestampon success and callsnext().src/errors.ts):AgentGuardError,AgentSignatureInvalid,AgentTimestampExpiredError,ContractReadError,NetworkRetryExhaustedError,AgentUnauthorizedError, andAgentPermissionDeniedError.dist/esm/) and CommonJS (dist/cjs/) with declaration maps (.d.ts).3. Cross-SDK Interoperability (
tests/interop.test.ts)agentguard-pyto generate an identity, canonically encode a nested dictionary payload, bind an epoch timestamp, and sign it.agentguard-jsingests the payload, timestamp, and signature, verifying cryptographic validity with zero discrepancy.Test & Coverage Results
agentguard-py