maiap-client 1.3.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.
- aiap_client/__init__.py +36 -0
- maiap_client/__init__.py +206 -0
- maiap_client/aggregation.py +101 -0
- maiap_client/client.py +714 -0
- maiap_client/compliance.py +157 -0
- maiap_client/consent.py +226 -0
- maiap_client/credentials.py +101 -0
- maiap_client/delegation.py +338 -0
- maiap_client/did.py +249 -0
- maiap_client/errors.py +81 -0
- maiap_client/eudi.py +268 -0
- maiap_client/lifecycle.py +107 -0
- maiap_client/models.py +237 -0
- maiap_client/signer.py +148 -0
- maiap_client-1.3.0.dist-info/METADATA +194 -0
- maiap_client-1.3.0.dist-info/RECORD +18 -0
- maiap_client-1.3.0.dist-info/WHEEL +4 -0
- maiap_client-1.3.0.dist-info/licenses/LICENSE.md +65 -0
aiap_client/__init__.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Deprecated import name for the Mediated AI Agency Protocol SDK.
|
|
2
|
+
|
|
3
|
+
The SDK is ``maiap_client`` (PyPI: ``maiap-client``). This module keeps ``import aiap_client`` and
|
|
4
|
+
``from aiap_client.<module> import ...`` working during the deprecation period: every name and every
|
|
5
|
+
submodule here is the *same object* as in ``maiap_client``, so isinstance checks and module state are
|
|
6
|
+
shared. It is removed in maiap-client 2.0.0. Change ``aiap_client`` to ``maiap_client`` in your imports.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import importlib
|
|
12
|
+
import sys
|
|
13
|
+
import warnings
|
|
14
|
+
|
|
15
|
+
warnings.warn(
|
|
16
|
+
"The 'aiap_client' import name is deprecated: the SDK is now 'maiap_client' (PyPI: maiap-client). "
|
|
17
|
+
"Replace 'aiap_client' with 'maiap_client' in your imports. 'aiap_client' is removed in maiap-client 2.0.0.",
|
|
18
|
+
DeprecationWarning,
|
|
19
|
+
stacklevel=2,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
import maiap_client as _maiap # noqa: E402
|
|
23
|
+
|
|
24
|
+
_SUBMODULES = (
|
|
25
|
+
"aggregation", "client", "compliance", "consent", "credentials", "delegation",
|
|
26
|
+
"did", "errors", "eudi", "lifecycle", "models", "signer",
|
|
27
|
+
)
|
|
28
|
+
for _name in _SUBMODULES:
|
|
29
|
+
_module = importlib.import_module(f"maiap_client.{_name}")
|
|
30
|
+
sys.modules[f"{__name__}.{_name}"] = _module
|
|
31
|
+
globals()[_name] = _module
|
|
32
|
+
|
|
33
|
+
from maiap_client import * # noqa: E402,F401,F403
|
|
34
|
+
from maiap_client import __version__ # noqa: E402,F401
|
|
35
|
+
|
|
36
|
+
__all__ = list(getattr(_maiap, "__all__", ())) + list(_SUBMODULES)
|
maiap_client/__init__.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"""AIAP Client v1.1.0 — AI Agency Protocol client.
|
|
2
|
+
|
|
3
|
+
Provides:
|
|
4
|
+
- Agency request/grant/deny lifecycle
|
|
5
|
+
- JIT credential management (auto-refresh, boto3 session)
|
|
6
|
+
- Mediated execution (Level 2 — agent never sees credentials)
|
|
7
|
+
- Delegated agency (Level 3 — attenuated delegation chains, RFC-002)
|
|
8
|
+
- MAC and certificate authentication, and token mode (workload identity, RFC-001 §5.2)
|
|
9
|
+
- AIGP trace binding (RFC-001 §5.4)
|
|
10
|
+
- Operator revocation and holder release (RFC-001 §11)
|
|
11
|
+
- Typed, fail-closed errors (RFC-001 §5.5)
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
__version__ = "1.3.0"
|
|
15
|
+
|
|
16
|
+
from .client import AgencyClient, TRACE_HEADER
|
|
17
|
+
from .errors import (
|
|
18
|
+
AgencyError,
|
|
19
|
+
AgencyConfigError,
|
|
20
|
+
AgencyTokenError,
|
|
21
|
+
AgencyTransportError,
|
|
22
|
+
AgencyProtocolError,
|
|
23
|
+
AgencyBrokerError,
|
|
24
|
+
AgencyAuthError,
|
|
25
|
+
AgencyNotFoundError,
|
|
26
|
+
AgencyRefusedError,
|
|
27
|
+
)
|
|
28
|
+
from .models import (
|
|
29
|
+
AgencyCredentials,
|
|
30
|
+
AgencyDeny,
|
|
31
|
+
AgencyGrant,
|
|
32
|
+
AgencyLevel,
|
|
33
|
+
AgencyRelease,
|
|
34
|
+
AgencyRequest,
|
|
35
|
+
AgencyRevoke,
|
|
36
|
+
DenyCode,
|
|
37
|
+
ReleaseResult,
|
|
38
|
+
ExecutionResult,
|
|
39
|
+
MediatedRequest,
|
|
40
|
+
SafetyTier,
|
|
41
|
+
AgencyDecisionResult,
|
|
42
|
+
)
|
|
43
|
+
from .credentials import CredentialSession
|
|
44
|
+
from .signer import MacSigner, CertificateSigner, Signer
|
|
45
|
+
from .delegation import (
|
|
46
|
+
DelegationLink,
|
|
47
|
+
DelegationError,
|
|
48
|
+
MAX_CHAIN_DEPTH,
|
|
49
|
+
build_root_link,
|
|
50
|
+
attenuate,
|
|
51
|
+
check_attenuation,
|
|
52
|
+
verify_chain,
|
|
53
|
+
effective_scope,
|
|
54
|
+
chain_model_attribution,
|
|
55
|
+
)
|
|
56
|
+
from .consent import (
|
|
57
|
+
ConsentGrant,
|
|
58
|
+
ConsentError,
|
|
59
|
+
build_consent_grant,
|
|
60
|
+
verify_consent,
|
|
61
|
+
anchor_consent,
|
|
62
|
+
chain_is_anchored,
|
|
63
|
+
TTL_HIGH_STAKES,
|
|
64
|
+
TTL_STANDARD,
|
|
65
|
+
TTL_BACKGROUND,
|
|
66
|
+
)
|
|
67
|
+
from .lifecycle import (
|
|
68
|
+
AgentLifecycleState,
|
|
69
|
+
LifecycleError,
|
|
70
|
+
TRANSITIONS,
|
|
71
|
+
TERMINAL,
|
|
72
|
+
OPERATIONAL,
|
|
73
|
+
can_transition,
|
|
74
|
+
apply_transition,
|
|
75
|
+
is_operational,
|
|
76
|
+
is_terminal,
|
|
77
|
+
)
|
|
78
|
+
from .aggregation import (
|
|
79
|
+
Grant,
|
|
80
|
+
ToxicCombinationPolicy,
|
|
81
|
+
AggregationError,
|
|
82
|
+
effective_authority,
|
|
83
|
+
check_aggregate,
|
|
84
|
+
)
|
|
85
|
+
from .did import (
|
|
86
|
+
DidError,
|
|
87
|
+
DidDocument,
|
|
88
|
+
VerificationMethod,
|
|
89
|
+
DidKeySigner,
|
|
90
|
+
parse_did,
|
|
91
|
+
is_did,
|
|
92
|
+
verify_did_signature,
|
|
93
|
+
multibase_encode_ed25519,
|
|
94
|
+
multibase_decode,
|
|
95
|
+
)
|
|
96
|
+
from .eudi import (
|
|
97
|
+
EudiError,
|
|
98
|
+
EudiRepresentationAttestation,
|
|
99
|
+
EudiWalletSigner,
|
|
100
|
+
issue_attestation,
|
|
101
|
+
verify_eudi_presentation,
|
|
102
|
+
consent_ref_from_attestation,
|
|
103
|
+
)
|
|
104
|
+
from .compliance import (
|
|
105
|
+
ComplianceError,
|
|
106
|
+
Obligation,
|
|
107
|
+
ComplianceMapping,
|
|
108
|
+
ComplianceMap,
|
|
109
|
+
ComplianceReport,
|
|
110
|
+
default_map,
|
|
111
|
+
collect_evidence,
|
|
112
|
+
ARTIFACTS,
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
__all__ = [
|
|
116
|
+
"AgencyClient",
|
|
117
|
+
"TRACE_HEADER",
|
|
118
|
+
"AgencyError",
|
|
119
|
+
"AgencyConfigError",
|
|
120
|
+
"AgencyTokenError",
|
|
121
|
+
"AgencyTransportError",
|
|
122
|
+
"AgencyProtocolError",
|
|
123
|
+
"AgencyBrokerError",
|
|
124
|
+
"AgencyAuthError",
|
|
125
|
+
"AgencyNotFoundError",
|
|
126
|
+
"AgencyRefusedError",
|
|
127
|
+
"AgencyCredentials",
|
|
128
|
+
"AgencyDeny",
|
|
129
|
+
"AgencyGrant",
|
|
130
|
+
"AgencyLevel",
|
|
131
|
+
"AgencyRelease",
|
|
132
|
+
"AgencyRequest",
|
|
133
|
+
"AgencyRevoke",
|
|
134
|
+
"DenyCode",
|
|
135
|
+
"ReleaseResult",
|
|
136
|
+
"ExecutionResult",
|
|
137
|
+
"MediatedRequest",
|
|
138
|
+
"SafetyTier",
|
|
139
|
+
"AgencyDecisionResult",
|
|
140
|
+
"CredentialSession",
|
|
141
|
+
"MacSigner",
|
|
142
|
+
"CertificateSigner",
|
|
143
|
+
"Signer",
|
|
144
|
+
# Level 3 delegation (RFC-002)
|
|
145
|
+
"DelegationLink",
|
|
146
|
+
"DelegationError",
|
|
147
|
+
"MAX_CHAIN_DEPTH",
|
|
148
|
+
"build_root_link",
|
|
149
|
+
"attenuate",
|
|
150
|
+
"check_attenuation",
|
|
151
|
+
"verify_chain",
|
|
152
|
+
"effective_scope",
|
|
153
|
+
"chain_model_attribution",
|
|
154
|
+
# Human consent evidence (RFC-003)
|
|
155
|
+
"ConsentGrant",
|
|
156
|
+
"ConsentError",
|
|
157
|
+
"build_consent_grant",
|
|
158
|
+
"verify_consent",
|
|
159
|
+
"anchor_consent",
|
|
160
|
+
"chain_is_anchored",
|
|
161
|
+
"TTL_HIGH_STAKES",
|
|
162
|
+
"TTL_STANDARD",
|
|
163
|
+
"TTL_BACKGROUND",
|
|
164
|
+
# Agent lifecycle governance (RFC-004)
|
|
165
|
+
"AgentLifecycleState",
|
|
166
|
+
"LifecycleError",
|
|
167
|
+
"TRANSITIONS",
|
|
168
|
+
"TERMINAL",
|
|
169
|
+
"OPERATIONAL",
|
|
170
|
+
"can_transition",
|
|
171
|
+
"apply_transition",
|
|
172
|
+
"is_operational",
|
|
173
|
+
"is_terminal",
|
|
174
|
+
# Aggregation-inference defense (RFC-005)
|
|
175
|
+
"Grant",
|
|
176
|
+
"ToxicCombinationPolicy",
|
|
177
|
+
"AggregationError",
|
|
178
|
+
"effective_authority",
|
|
179
|
+
"check_aggregate",
|
|
180
|
+
# DID-based identity (RFC-006, optional)
|
|
181
|
+
"DidError",
|
|
182
|
+
"DidDocument",
|
|
183
|
+
"VerificationMethod",
|
|
184
|
+
"DidKeySigner",
|
|
185
|
+
"parse_did",
|
|
186
|
+
"is_did",
|
|
187
|
+
"verify_did_signature",
|
|
188
|
+
"multibase_encode_ed25519",
|
|
189
|
+
"multibase_decode",
|
|
190
|
+
# eIDAS 2 / EUDI Wallet identity (RFC-007, optional)
|
|
191
|
+
"EudiError",
|
|
192
|
+
"EudiRepresentationAttestation",
|
|
193
|
+
"EudiWalletSigner",
|
|
194
|
+
"issue_attestation",
|
|
195
|
+
"verify_eudi_presentation",
|
|
196
|
+
"consent_ref_from_attestation",
|
|
197
|
+
# Compliance-evidence mapping (RFC-008)
|
|
198
|
+
"ComplianceError",
|
|
199
|
+
"Obligation",
|
|
200
|
+
"ComplianceMapping",
|
|
201
|
+
"ComplianceMap",
|
|
202
|
+
"ComplianceReport",
|
|
203
|
+
"default_map",
|
|
204
|
+
"collect_evidence",
|
|
205
|
+
"ARTIFACTS",
|
|
206
|
+
]
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""AIAP aggregation-inference defense — RFC-005.
|
|
2
|
+
|
|
3
|
+
Reasons about an agent's authority **in aggregate**, not just per grant. An agent may hold several
|
|
4
|
+
individually-legitimate grants; the union can exceed what any single grant intended — either an
|
|
5
|
+
incompatible combination (segregation-of-duties break) or a mosaic inference. The defense:
|
|
6
|
+
|
|
7
|
+
- **Effective authority** ``EA(agent, purpose)`` = union of the scopes of the agent's active grants
|
|
8
|
+
**that share that purpose**. Grants of different purposes are never unioned (purpose-binding).
|
|
9
|
+
- A **ToxicCombinationPolicy** lists forbidden capability sets. Deny if ``EA' ⊇ F`` for any forbidden
|
|
10
|
+
set ``F`` (checked when a new grant would *complete* the set).
|
|
11
|
+
- Optional aggregate ceilings bound distinct capabilities / concurrent grants per purpose.
|
|
12
|
+
|
|
13
|
+
``check_aggregate`` returns ``(allowed, reason)`` where reason is ``TOXIC_COMBINATION`` /
|
|
14
|
+
``AGGREGATE_CEILING`` / ``""``. Callers treat any deny uniformly.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from dataclasses import dataclass, field
|
|
20
|
+
from typing import Optional
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class AggregationError(Exception):
|
|
24
|
+
"""Raised on a malformed aggregation policy."""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(frozen=True)
|
|
28
|
+
class Grant:
|
|
29
|
+
"""Minimal view of an active grant for aggregation: its scope and declared purpose."""
|
|
30
|
+
scope: frozenset[str]
|
|
31
|
+
purpose: str
|
|
32
|
+
|
|
33
|
+
@staticmethod
|
|
34
|
+
def of(scope, purpose: str) -> "Grant":
|
|
35
|
+
return Grant(frozenset(scope), purpose)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass
|
|
39
|
+
class ToxicCombinationPolicy:
|
|
40
|
+
"""Aggregation-inference policy (RFC-005 §3, §5)."""
|
|
41
|
+
forbidden_sets: list[frozenset[str]] = field(default_factory=list)
|
|
42
|
+
max_capabilities_per_purpose: Optional[int] = None
|
|
43
|
+
max_concurrent_grants_per_purpose: Optional[int] = None
|
|
44
|
+
|
|
45
|
+
@classmethod
|
|
46
|
+
def from_dict(cls, d: dict) -> "ToxicCombinationPolicy":
|
|
47
|
+
raw = d.get("forbidden_sets", [])
|
|
48
|
+
sets: list[frozenset[str]] = []
|
|
49
|
+
for entry in raw:
|
|
50
|
+
caps = entry.get("capabilities") if isinstance(entry, dict) else entry
|
|
51
|
+
if not caps:
|
|
52
|
+
raise AggregationError("forbidden set must have at least one capability")
|
|
53
|
+
sets.append(frozenset(caps))
|
|
54
|
+
return cls(
|
|
55
|
+
forbidden_sets=sets,
|
|
56
|
+
max_capabilities_per_purpose=d.get("max_capabilities_per_purpose"),
|
|
57
|
+
max_concurrent_grants_per_purpose=d.get("max_concurrent_grants_per_purpose"),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def effective_authority(grants: list[Grant], purpose: str) -> set[str]:
|
|
62
|
+
"""Union of scopes of active grants sharing ``purpose`` (RFC-005 §2)."""
|
|
63
|
+
ea: set[str] = set()
|
|
64
|
+
for g in grants:
|
|
65
|
+
if g.purpose == purpose:
|
|
66
|
+
ea |= set(g.scope)
|
|
67
|
+
return ea
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _grants_for_purpose(grants: list[Grant], purpose: str) -> int:
|
|
71
|
+
return sum(1 for g in grants if g.purpose == purpose)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def check_aggregate(
|
|
75
|
+
active_grants: list[Grant],
|
|
76
|
+
new_scope,
|
|
77
|
+
purpose: str,
|
|
78
|
+
policy: ToxicCombinationPolicy,
|
|
79
|
+
) -> tuple[bool, str]:
|
|
80
|
+
"""Evaluate whether granting ``new_scope`` under ``purpose`` is allowed (RFC-005 §6).
|
|
81
|
+
|
|
82
|
+
Only same-purpose grants pool (purpose-binding). Returns (allowed, reason).
|
|
83
|
+
"""
|
|
84
|
+
new_scope = set(new_scope)
|
|
85
|
+
ea_prime = effective_authority(active_grants, purpose) | new_scope
|
|
86
|
+
|
|
87
|
+
# Toxic combinations: deny if the prospective effective authority contains any forbidden set.
|
|
88
|
+
for forbidden in policy.forbidden_sets:
|
|
89
|
+
if forbidden <= ea_prime:
|
|
90
|
+
return False, "TOXIC_COMBINATION"
|
|
91
|
+
|
|
92
|
+
# Aggregate ceilings (per purpose).
|
|
93
|
+
if policy.max_capabilities_per_purpose is not None:
|
|
94
|
+
if len(ea_prime) > policy.max_capabilities_per_purpose:
|
|
95
|
+
return False, "AGGREGATE_CEILING"
|
|
96
|
+
if policy.max_concurrent_grants_per_purpose is not None:
|
|
97
|
+
# +1 for the prospective new grant
|
|
98
|
+
if _grants_for_purpose(active_grants, purpose) + 1 > policy.max_concurrent_grants_per_purpose:
|
|
99
|
+
return False, "AGGREGATE_CEILING"
|
|
100
|
+
|
|
101
|
+
return True, ""
|