agent-did-sdk 0.1.0__py3-none-any.whl
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.
- agent_did_sdk/__init__.py +113 -0
- agent_did_sdk/core/__init__.py +0 -0
- agent_did_sdk/core/http_security.py +57 -0
- agent_did_sdk/core/identity.py +642 -0
- agent_did_sdk/core/signer.py +48 -0
- agent_did_sdk/core/time_utils.py +50 -0
- agent_did_sdk/core/types.py +150 -0
- agent_did_sdk/crypto/__init__.py +0 -0
- agent_did_sdk/crypto/hash.py +67 -0
- agent_did_sdk/crypto/multibase.py +116 -0
- agent_did_sdk/py.typed +0 -0
- agent_did_sdk/registry/__init__.py +0 -0
- agent_did_sdk/registry/evm_registry.py +47 -0
- agent_did_sdk/registry/evm_types.py +35 -0
- agent_did_sdk/registry/in_memory.py +45 -0
- agent_did_sdk/registry/types.py +26 -0
- agent_did_sdk/registry/web3_client.py +108 -0
- agent_did_sdk/resolver/__init__.py +0 -0
- agent_did_sdk/resolver/http_source.py +83 -0
- agent_did_sdk/resolver/in_memory.py +24 -0
- agent_did_sdk/resolver/jsonrpc_source.py +98 -0
- agent_did_sdk/resolver/types.py +59 -0
- agent_did_sdk/resolver/universal.py +200 -0
- agent_did_sdk-0.1.0.dist-info/METADATA +240 -0
- agent_did_sdk-0.1.0.dist-info/RECORD +28 -0
- agent_did_sdk-0.1.0.dist-info/WHEEL +5 -0
- agent_did_sdk-0.1.0.dist-info/licenses/LICENSE +151 -0
- agent_did_sdk-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""agent-did-sdk — Python SDK for the Agent-DID Specification (RFC-001)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .core.http_security import HttpTargetValidationOptions, validate_http_target
|
|
6
|
+
from .core.identity import (
|
|
7
|
+
AgentIdentity,
|
|
8
|
+
AgentIdentityConfig,
|
|
9
|
+
ProductionHttpResolverProfileConfig,
|
|
10
|
+
ProductionJsonRpcResolverProfileConfig,
|
|
11
|
+
ProductionResolverProfileConfig,
|
|
12
|
+
)
|
|
13
|
+
from .core.signer import AgentSigner, LocalKeySigner
|
|
14
|
+
from .core.time_utils import (
|
|
15
|
+
is_unix_timestamp_string,
|
|
16
|
+
iso_to_unix_string,
|
|
17
|
+
normalize_timestamp_to_iso,
|
|
18
|
+
unix_string_to_iso,
|
|
19
|
+
)
|
|
20
|
+
from .core.types import (
|
|
21
|
+
AgentDIDDocument,
|
|
22
|
+
AgentDocumentHistoryAction,
|
|
23
|
+
AgentDocumentHistoryEntry,
|
|
24
|
+
AgentMetadata,
|
|
25
|
+
CreateAgentParams,
|
|
26
|
+
CreateAgentResult,
|
|
27
|
+
RotateVerificationMethodResult,
|
|
28
|
+
SignHttpRequestParams,
|
|
29
|
+
UpdateAgentDocumentParams,
|
|
30
|
+
VerifiableCredentialLink,
|
|
31
|
+
VerificationMethod,
|
|
32
|
+
VerifyHttpRequestSignatureParams,
|
|
33
|
+
)
|
|
34
|
+
from .crypto.hash import format_hash_uri, generate_agent_metadata_hash, hash_payload
|
|
35
|
+
from .crypto.multibase import decode_public_key_multibase, encode_public_key_multibase
|
|
36
|
+
from .registry.evm_registry import EvmAgentRegistry
|
|
37
|
+
from .registry.evm_types import EvmAgentRegistryAdapterConfig, EvmAgentRegistryContract, EvmTxResponse
|
|
38
|
+
from .registry.in_memory import InMemoryAgentRegistry
|
|
39
|
+
from .registry.types import AgentRegistry, AgentRegistryRecord
|
|
40
|
+
from .registry.web3_client import Web3AgentRegistryContractClient
|
|
41
|
+
from .resolver.http_source import HttpDIDDocumentSource, HttpDIDDocumentSourceConfig
|
|
42
|
+
from .resolver.in_memory import InMemoryDIDResolver
|
|
43
|
+
from .resolver.jsonrpc_source import JsonRpcDIDDocumentSource, JsonRpcDIDDocumentSourceConfig
|
|
44
|
+
from .resolver.types import (
|
|
45
|
+
DIDDocumentSource,
|
|
46
|
+
DIDResolver,
|
|
47
|
+
ResolverCacheStats,
|
|
48
|
+
ResolverResolutionEvent,
|
|
49
|
+
ResolverResolutionStage,
|
|
50
|
+
UniversalResolverConfig,
|
|
51
|
+
)
|
|
52
|
+
from .resolver.universal import UniversalResolverClient
|
|
53
|
+
|
|
54
|
+
__all__ = [
|
|
55
|
+
# Core types
|
|
56
|
+
"AgentMetadata",
|
|
57
|
+
"VerifiableCredentialLink",
|
|
58
|
+
"VerificationMethod",
|
|
59
|
+
"AgentDIDDocument",
|
|
60
|
+
"CreateAgentParams",
|
|
61
|
+
"CreateAgentResult",
|
|
62
|
+
"UpdateAgentDocumentParams",
|
|
63
|
+
"RotateVerificationMethodResult",
|
|
64
|
+
"SignHttpRequestParams",
|
|
65
|
+
"VerifyHttpRequestSignatureParams",
|
|
66
|
+
"AgentDocumentHistoryAction",
|
|
67
|
+
"AgentDocumentHistoryEntry",
|
|
68
|
+
# Core signer
|
|
69
|
+
"AgentSigner",
|
|
70
|
+
"LocalKeySigner",
|
|
71
|
+
# Core HTTP security
|
|
72
|
+
"HttpTargetValidationOptions",
|
|
73
|
+
"validate_http_target",
|
|
74
|
+
# Core identity
|
|
75
|
+
"AgentIdentity",
|
|
76
|
+
"AgentIdentityConfig",
|
|
77
|
+
"ProductionResolverProfileConfig",
|
|
78
|
+
"ProductionHttpResolverProfileConfig",
|
|
79
|
+
"ProductionJsonRpcResolverProfileConfig",
|
|
80
|
+
# Core time
|
|
81
|
+
"is_unix_timestamp_string",
|
|
82
|
+
"unix_string_to_iso",
|
|
83
|
+
"iso_to_unix_string",
|
|
84
|
+
"normalize_timestamp_to_iso",
|
|
85
|
+
# Crypto
|
|
86
|
+
"hash_payload",
|
|
87
|
+
"format_hash_uri",
|
|
88
|
+
"generate_agent_metadata_hash",
|
|
89
|
+
"encode_public_key_multibase",
|
|
90
|
+
"decode_public_key_multibase",
|
|
91
|
+
# Registry
|
|
92
|
+
"AgentRegistry",
|
|
93
|
+
"AgentRegistryRecord",
|
|
94
|
+
"EvmTxResponse",
|
|
95
|
+
"EvmAgentRegistryContract",
|
|
96
|
+
"EvmAgentRegistryAdapterConfig",
|
|
97
|
+
"InMemoryAgentRegistry",
|
|
98
|
+
"EvmAgentRegistry",
|
|
99
|
+
"Web3AgentRegistryContractClient",
|
|
100
|
+
# Resolver
|
|
101
|
+
"DIDResolver",
|
|
102
|
+
"DIDDocumentSource",
|
|
103
|
+
"UniversalResolverConfig",
|
|
104
|
+
"ResolverCacheStats",
|
|
105
|
+
"ResolverResolutionEvent",
|
|
106
|
+
"ResolverResolutionStage",
|
|
107
|
+
"InMemoryDIDResolver",
|
|
108
|
+
"UniversalResolverClient",
|
|
109
|
+
"HttpDIDDocumentSource",
|
|
110
|
+
"HttpDIDDocumentSourceConfig",
|
|
111
|
+
"JsonRpcDIDDocumentSource",
|
|
112
|
+
"JsonRpcDIDDocumentSourceConfig",
|
|
113
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""SSRF protection — validates HTTP target URLs before requests."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import ipaddress
|
|
6
|
+
from urllib.parse import urlparse
|
|
7
|
+
|
|
8
|
+
__all__ = ["HttpTargetValidationOptions", "validate_http_target"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class HttpTargetValidationOptions:
|
|
12
|
+
"""Options for ``validate_http_target``."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, *, allow_private_targets: bool = False) -> None:
|
|
15
|
+
self.allow_private_targets = allow_private_targets
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _is_private_or_reserved(hostname: str) -> bool:
|
|
19
|
+
"""Return *True* if *hostname* resolves to a loopback, private, or link-local address."""
|
|
20
|
+
lower = hostname.lower()
|
|
21
|
+
if lower in ("localhost", "localhost.localdomain"):
|
|
22
|
+
return True
|
|
23
|
+
|
|
24
|
+
# Strip IPv6 bracket notation
|
|
25
|
+
bare = hostname.strip("[]")
|
|
26
|
+
try:
|
|
27
|
+
addr = ipaddress.ip_address(bare)
|
|
28
|
+
except ValueError:
|
|
29
|
+
return False
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
addr.is_loopback
|
|
33
|
+
or addr.is_private
|
|
34
|
+
or addr.is_reserved
|
|
35
|
+
or addr.is_link_local
|
|
36
|
+
or addr.is_unspecified
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def validate_http_target(url: str, options: HttpTargetValidationOptions | None = None) -> None:
|
|
41
|
+
"""Validate *url* for SSRF safety. Raises ``ValueError`` if the URL is unsafe."""
|
|
42
|
+
opts = options or HttpTargetValidationOptions()
|
|
43
|
+
|
|
44
|
+
parsed = urlparse(url)
|
|
45
|
+
|
|
46
|
+
if parsed.scheme not in ("https", "http"):
|
|
47
|
+
raise ValueError(f"Unsupported protocol: {parsed.scheme}")
|
|
48
|
+
|
|
49
|
+
if parsed.username or parsed.password:
|
|
50
|
+
raise ValueError("URLs with embedded credentials are not allowed")
|
|
51
|
+
|
|
52
|
+
if opts.allow_private_targets:
|
|
53
|
+
return
|
|
54
|
+
|
|
55
|
+
hostname = parsed.hostname or ""
|
|
56
|
+
if _is_private_or_reserved(hostname):
|
|
57
|
+
raise ValueError(f"Blocked request to private/reserved address: {hostname}")
|