agentguard-python-sdk 0.2.0__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (17) hide show
  1. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/PKG-INFO +7 -2
  2. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/README.md +6 -1
  3. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/agentguard/client.py +12 -2
  4. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/agentguard/consent.py +21 -38
  5. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/agentguard_python_sdk.egg-info/PKG-INFO +7 -2
  6. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/pyproject.toml +1 -1
  7. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/agentguard/__init__.py +0 -0
  8. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/agentguard/auth.py +0 -0
  9. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/agentguard/config.py +0 -0
  10. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/agentguard/errors.py +0 -0
  11. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/agentguard/observability.py +0 -0
  12. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/agentguard/types.py +0 -0
  13. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/agentguard_python_sdk.egg-info/SOURCES.txt +0 -0
  14. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/agentguard_python_sdk.egg-info/dependency_links.txt +0 -0
  15. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/agentguard_python_sdk.egg-info/requires.txt +0 -0
  16. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/agentguard_python_sdk.egg-info/top_level.txt +0 -0
  17. {agentguard_python_sdk-0.2.0 → agentguard_python_sdk-0.2.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agentguard-python-sdk
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: A production-grade middleware for AI agents to perform on-chain payments and verifiable consent.
5
5
  Author: AgentGuard Team
6
6
  License-Expression: MIT
@@ -32,7 +32,12 @@ from agentguard import AgentGuardClient
32
32
 
33
33
  async def main():
34
34
  # 1. Initialize the client
35
- async with AgentGuardClient(wallet_address="YOUR_WALLET_ADDRESS") as client:
35
+ # NOTE: The backend requires a cryptographic signature on `/pay`.
36
+ # Provide `private_key` as a base64-encoded Algorand private key seed for request signing.
37
+ async with AgentGuardClient(
38
+ wallet_address="YOUR_WALLET_ADDRESS",
39
+ private_key="YOUR_PRIVATE_KEY_B64",
40
+ ) as client:
36
41
 
37
42
  # 2. Perform a secure payment (includes automatic DPDP consent hashing)
38
43
  receipt = await client.pay_and_fetch(
@@ -18,7 +18,12 @@ from agentguard import AgentGuardClient
18
18
 
19
19
  async def main():
20
20
  # 1. Initialize the client
21
- async with AgentGuardClient(wallet_address="YOUR_WALLET_ADDRESS") as client:
21
+ # NOTE: The backend requires a cryptographic signature on `/pay`.
22
+ # Provide `private_key` as a base64-encoded Algorand private key seed for request signing.
23
+ async with AgentGuardClient(
24
+ wallet_address="YOUR_WALLET_ADDRESS",
25
+ private_key="YOUR_PRIVATE_KEY_B64",
26
+ ) as client:
22
27
 
23
28
  # 2. Perform a secure payment (includes automatic DPDP consent hashing)
24
29
  receipt = await client.pay_and_fetch(
@@ -273,9 +273,19 @@ class AgentGuardClient:
273
273
  canonical_json = res_data.get("canonical_json")
274
274
 
275
275
  if not canonical_json and local_proof:
276
- # [Priority 8 BONUS] Reconstruct canonical JSON from raw local proof
276
+ # [Priority 8 BONUS] Reconstruct canonical JSON using SHARED SCHEMA BUILDER
277
+ from .consent import build_canonical_payload
277
278
  from .auth import canonicalize_payload
278
- canonical_bytes = canonicalize_payload(local_proof)
279
+
280
+ canonical_payload = build_canonical_payload(
281
+ principal_id=local_proof.get("principal_id", self.wallet_address),
282
+ resource_url=local_proof.get("resource_url", ""),
283
+ purpose=local_proof.get("purpose", ""),
284
+ microalgos=int(local_proof.get("microalgos", 0)),
285
+ nonce=local_proof.get("nonce", ""),
286
+ timestamp=int(local_proof.get("timestamp", 0))
287
+ )
288
+ canonical_bytes = canonicalize_payload(canonical_payload)
279
289
  canonical_json = canonical_bytes.decode("utf-8")
280
290
 
281
291
  if not canonical_json:
@@ -8,56 +8,36 @@ from typing import Dict, Any
8
8
  # Configure logging
9
9
  logger = logging.getLogger("agentguard-sdk")
10
10
 
11
- def generate_consent(
11
+ def build_canonical_payload(
12
12
  principal_id: str,
13
+ resource_url: str,
13
14
  purpose: str,
14
- item: str,
15
- nonce: str,
16
15
  microalgos: int,
17
- data_fiduciary: str = "AlgoBharat Agentic Node",
18
- timestamp: int = None
16
+ nonce: str,
17
+ timestamp: int,
18
+ data_fiduciary: str = "AlgoBharat Agentic Node"
19
19
  ) -> Dict[str, Any]:
20
20
  """
21
- Creates a user consent object dictionary containing DPDP compliant fields.
22
- Includes microalgos (int) and hash_version for future-proofing.
23
-
24
- Representation Rule:
25
- - Internal: microalgos (int) is the single source of truth.
26
- - Strings: All metadata is normalized to NFC.
21
+ SINGLE SOURCE OF TRUTH for the audit payload schema.
22
+ Guarantees deterministic parity between SDK, Backend, and recovery logic.
27
23
  """
28
- if timestamp is None:
29
- timestamp = int(time.time())
30
-
31
- # Normalize strings to NFC at the creation boundary
32
- consent_obj = {
33
- "principal_id": unicodedata.normalize("NFC", principal_id),
24
+ return {
34
25
  "data_fiduciary": unicodedata.normalize("NFC", data_fiduciary),
35
- "purpose": unicodedata.normalize("NFC", purpose),
36
- "item": unicodedata.normalize("NFC", item),
37
- "microalgos": microalgos,
38
- "timestamp": timestamp,
26
+ "hash_version": 2, # Current Refactor Version
27
+ "item": unicodedata.normalize("NFC", resource_url),
28
+ "microalgos": int(microalgos),
39
29
  "nonce": nonce,
40
- "hash_version": 2 # Current Refactor Version
30
+ "principal_id": unicodedata.normalize("NFC", principal_id),
31
+ "purpose": unicodedata.normalize("NFC", purpose),
32
+ "timestamp": int(timestamp)
41
33
  }
42
-
43
- logger.info(f"Generated DPDP consent (v2) for principal={principal_id} at {timestamp}")
44
- return consent_obj
45
34
 
46
35
  def hash_consent(consent: Dict[str, Any]) -> str:
47
36
  """
48
37
  Canonical hashing implementation.
49
38
  MUST REMAINT SYNCED with Backend and MCP Server.
50
-
51
- Rules:
52
- 1. sort_keys=True
53
- 2. separators=(',', ':')
54
- 3. ensure_ascii=False
55
- 4. Encoding: utf-8
56
39
  """
57
- # Convert consent dict to JSON string with strict canonical form:
58
- # - Sorted keys
59
- # - No spaces (separators=(",", ":"))
60
- # Use separators=(",", ":") and ensure_ascii=False for identical bytes across boundaries
40
+ # Convert consent dict to JSON string with strict canonical form
61
41
  consent_json = json.dumps(consent, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
62
42
  consent_hash = hashlib.sha256(consent_json.encode("utf-8")).hexdigest()
63
43
 
@@ -68,12 +48,15 @@ def generate_consent_proof(principal_id: str, resource_url: str, purpose: str, n
68
48
  """
69
49
  High-level helper to generate a consent hash and return the timestamp used.
70
50
  """
71
- consent = generate_consent(
51
+ if timestamp is None:
52
+ timestamp = int(time.time())
53
+
54
+ consent = build_canonical_payload(
72
55
  principal_id=principal_id,
56
+ resource_url=resource_url,
73
57
  purpose=purpose,
74
- item=resource_url,
75
- nonce=nonce,
76
58
  microalgos=microalgos,
59
+ nonce=nonce,
77
60
  timestamp=timestamp
78
61
  )
79
62
  return hash_consent(consent), consent["timestamp"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agentguard-python-sdk
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: A production-grade middleware for AI agents to perform on-chain payments and verifiable consent.
5
5
  Author: AgentGuard Team
6
6
  License-Expression: MIT
@@ -32,7 +32,12 @@ from agentguard import AgentGuardClient
32
32
 
33
33
  async def main():
34
34
  # 1. Initialize the client
35
- async with AgentGuardClient(wallet_address="YOUR_WALLET_ADDRESS") as client:
35
+ # NOTE: The backend requires a cryptographic signature on `/pay`.
36
+ # Provide `private_key` as a base64-encoded Algorand private key seed for request signing.
37
+ async with AgentGuardClient(
38
+ wallet_address="YOUR_WALLET_ADDRESS",
39
+ private_key="YOUR_PRIVATE_KEY_B64",
40
+ ) as client:
36
41
 
37
42
  # 2. Perform a secure payment (includes automatic DPDP consent hashing)
38
43
  receipt = await client.pay_and_fetch(
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "agentguard-python-sdk"
7
- version = "0.2.0"
7
+ version = "0.2.1"
8
8
  description = "A production-grade middleware for AI agents to perform on-chain payments and verifiable consent."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"