umf-access 0.1.0.dev8__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.
Files changed (117) hide show
  1. umf_access/__init__.py +109 -0
  2. umf_access/adoption.py +41 -0
  3. umf_access/build/__init__.py +2 -0
  4. umf_access/build/approximate.py +34 -0
  5. umf_access/build/catalog.py +1626 -0
  6. umf_access/build/commands.py +394 -0
  7. umf_access/build/pg_privileges.py +1544 -0
  8. umf_access/build/privileges.py +134 -0
  9. umf_access/build/search.py +365 -0
  10. umf_access/build/unity_search.py +104 -0
  11. umf_access/bulk.py +227 -0
  12. umf_access/canonical.py +23 -0
  13. umf_access/capture.py +410 -0
  14. umf_access/catalog.py +325 -0
  15. umf_access/codec_support.py +427 -0
  16. umf_access/commands.py +93 -0
  17. umf_access/delta_read.py +758 -0
  18. umf_access/dsl/__init__.py +148 -0
  19. umf_access/dsl/_context.py +36 -0
  20. umf_access/dsl/_expressions.py +625 -0
  21. umf_access/dsl/_joined.py +4 -0
  22. umf_access/dsl/_nodes.py +207 -0
  23. umf_access/dsl/_query.py +5559 -0
  24. umf_access/dsl/_selection.py +143 -0
  25. umf_access/dsl/navigation.py +302 -0
  26. umf_access/dsl/render.py +516 -0
  27. umf_access/dsl/search.py +343 -0
  28. umf_access/engine_catalog.py +563 -0
  29. umf_access/generated_core.py +5 -0
  30. umf_access/lifecycle/__init__.py +46 -0
  31. umf_access/lifecycle/_darwin_process_observer.c +306 -0
  32. umf_access/lifecycle/approval.py +366 -0
  33. umf_access/lifecycle/backfills.py +79 -0
  34. umf_access/lifecycle/catalog.py +289 -0
  35. umf_access/lifecycle/cli.py +231 -0
  36. umf_access/lifecycle/concurrent.py +196 -0
  37. umf_access/lifecycle/conversion_policy.py +188 -0
  38. umf_access/lifecycle/correspondence.py +203 -0
  39. umf_access/lifecycle/generation_authority_bootstrap.py +1491 -0
  40. umf_access/lifecycle/generation_authority_session.py +125 -0
  41. umf_access/lifecycle/generation_enrollment_authority.py +1108 -0
  42. umf_access/lifecycle/generation_enrollment_ledger.py +698 -0
  43. umf_access/lifecycle/generation_ingress.py +185 -0
  44. umf_access/lifecycle/generation_root_registry.py +138 -0
  45. umf_access/lifecycle/head.py +250 -0
  46. umf_access/lifecycle/head_view.py +81 -0
  47. umf_access/lifecycle/host.py +1183 -0
  48. umf_access/lifecycle/ingress_custody.py +750 -0
  49. umf_access/lifecycle/ingress_local_postgres.py +7990 -0
  50. umf_access/lifecycle/ingress_store.py +1488 -0
  51. umf_access/lifecycle/ledger.py +276 -0
  52. umf_access/lifecycle/ledger_schema.py +116 -0
  53. umf_access/lifecycle/mixed.py +593 -0
  54. umf_access/lifecycle/outcome_schema.py +136 -0
  55. umf_access/lifecycle/owner_approval_core.py +1810 -0
  56. umf_access/lifecycle/owner_authority.py +472 -0
  57. umf_access/lifecycle/owner_bootstrap.py +2077 -0
  58. umf_access/lifecycle/owner_wire.py +161 -0
  59. umf_access/lifecycle/phase_fence.py +52 -0
  60. umf_access/lifecycle/phase_policy.py +422 -0
  61. umf_access/lifecycle/privileges.py +145 -0
  62. umf_access/lifecycle/probe.py +39 -0
  63. umf_access/lifecycle/progress.py +497 -0
  64. umf_access/lifecycle/roles.py +96 -0
  65. umf_access/lifecycle/row_originals.py +1712 -0
  66. umf_access/lifecycle/row_originals_creation.py +759 -0
  67. umf_access/lifecycle/row_originals_receipt.py +413 -0
  68. umf_access/lifecycle/seeds.py +99 -0
  69. umf_access/lifecycle/sql_containment.py +358 -0
  70. umf_access/lifecycle/sql_containment_cli.py +33 -0
  71. umf_access/lifecycle/sql_containment_parser.py +20 -0
  72. umf_access/lifecycle/supervisor_journal_codec.py +1251 -0
  73. umf_access/lifecycle/table_boundary.py +22 -0
  74. umf_access/lifecycle/target_custody_codec.py +788 -0
  75. umf_access/lifecycle/witness.py +72 -0
  76. umf_access/managed_actions.py +271 -0
  77. umf_access/managed_bulk.py +353 -0
  78. umf_access/managed_delta.py +150 -0
  79. umf_access/managed_support.py +166 -0
  80. umf_access/manifest_commands.py +278 -0
  81. umf_access/native_actions.py +1007 -0
  82. umf_access/native_program.py +570 -0
  83. umf_access/pages.py +125 -0
  84. umf_access/postgres_bulk.py +509 -0
  85. umf_access/postgres_read.py +1230 -0
  86. umf_access/postgres_search.py +639 -0
  87. umf_access/protocols.py +665 -0
  88. umf_access/py.typed +0 -0
  89. umf_access/related_keys.py +233 -0
  90. umf_access/reviewed.py +706 -0
  91. umf_access/search_catalog.py +122 -0
  92. umf_access/targets.py +312 -0
  93. umf_access/types.py +220 -0
  94. umf_access/unified/__init__.py +187 -0
  95. umf_access/unified/_binding.py +654 -0
  96. umf_access/unified/head_session.py +144 -0
  97. umf_access/unified/native_binding.py +143 -0
  98. umf_access/unified/operation_values.py +173 -0
  99. umf_access/unified/outcome_values.py +76 -0
  100. umf_access/unified/session_async.py +161 -0
  101. umf_access/unified/session_binding.py +108 -0
  102. umf_access/unified/session_policy.py +152 -0
  103. umf_access/unified/session_psycopg2.py +70 -0
  104. umf_access/unified/session_sqlalchemy.py +161 -0
  105. umf_access/unified/session_sync.py +148 -0
  106. umf_access/unified/table_reads.py +314 -0
  107. umf_access/unified/table_writes.py +193 -0
  108. umf_access/unity_search.py +312 -0
  109. umf_access/values.py +280 -0
  110. umf_access/verification.py +64 -0
  111. umf_access-0.1.0.dev8.dist-info/METADATA +15 -0
  112. umf_access-0.1.0.dev8.dist-info/RECORD +117 -0
  113. umf_access-0.1.0.dev8.dist-info/WHEEL +4 -0
  114. umf_access-0.1.0.dev8.dist-info/entry_points.txt +4 -0
  115. umf_access-0.1.0.dev8.dist-info/licenses/LICENSE-APACHE +201 -0
  116. umf_access-0.1.0.dev8.dist-info/licenses/LICENSE-MIT +21 -0
  117. umf_access-0.1.0.dev8.dist-info/licenses/LICENSE.md +239 -0
@@ -0,0 +1,472 @@
1
+ # SPDX-License-Identifier: MIT OR Apache-2.0
2
+ """Public owner-approval facade and native lifecycle orchestration."""
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from functools import wraps
7
+ from pathlib import Path
8
+ from typing import Any
9
+
10
+ from .owner_approval_core import (
11
+ _SCOPES,
12
+ _SIGNATURE_DOMAIN,
13
+ OWNER_APPROVAL_PROFILE,
14
+ OWNER_AUTHORITY_PROFILE,
15
+ OWNER_INTENT_PROFILE,
16
+ OWNER_LEDGER_PROFILE,
17
+ OWNER_PURPOSES,
18
+ OriginalApprovalOutcome,
19
+ OwnerApprovalCore,
20
+ OwnerApprovalRequest,
21
+ OwnerAuthorityError,
22
+ VerifiedOwnerApproval,
23
+ _canonical_bytes,
24
+ _digest,
25
+ _digest_bytes,
26
+ _reject,
27
+ _validate_config,
28
+ )
29
+ from .owner_bootstrap import (
30
+ LocalPostgresProfile,
31
+ OwnerAuthorityContext,
32
+ _issue_owner_authority_context,
33
+ _LocalOwnerBootstrapIssuer,
34
+ )
35
+
36
+ __all__ = [
37
+ 'OWNER_APPROVAL_PROFILE',
38
+ 'OWNER_AUTHORITY_PROFILE',
39
+ 'OWNER_INTENT_PROFILE',
40
+ 'OWNER_LEDGER_PROFILE',
41
+ 'OWNER_PURPOSES',
42
+ '_SCOPES',
43
+ '_SIGNATURE_DOMAIN',
44
+ 'ConfiguredEd25519OwnerAuthority',
45
+ 'LocalPostgresProfile',
46
+ 'OriginalApprovalOutcome',
47
+ 'OriginalEffectBinding',
48
+ 'OwnerApprovalCore',
49
+ 'OwnerApprovalRequest',
50
+ 'OwnerAuthorityContext',
51
+ 'OwnerAuthorityError',
52
+ 'OwnerAuthoritySession',
53
+ 'VerifiedOwnerApproval',
54
+ '_canonical_bytes',
55
+ '_digest',
56
+ '_digest_bytes',
57
+ '_reject',
58
+ '_validate_config',
59
+ 'create_owner_authority_session',
60
+ ]
61
+
62
+ _EFFECT_SEAL = object()
63
+
64
+ class OriginalEffectBinding:
65
+ """Opaque durable link from a verified approval to one native reservation."""
66
+
67
+ __slots__ = ('_core_handle', '_issuer', '_kind', '_request', '_reservation',
68
+ '_reservation_digest')
69
+
70
+ def __init__(self, seal: object, issuer: object, request: OwnerApprovalRequest,
71
+ reservation: object, reservation_digest: str,
72
+ core_handle: object):
73
+ if seal is not _EFFECT_SEAL:
74
+ raise TypeError('native effect bindings are authority-issued')
75
+ object.__setattr__(self, '_issuer', issuer)
76
+ object.__setattr__(self, '_kind', 'umf.owner-native-effect-binding/0.1')
77
+ object.__setattr__(self, '_request', request)
78
+ object.__setattr__(self, '_reservation', reservation)
79
+ object.__setattr__(self, '_reservation_digest', _digest(reservation_digest))
80
+ object.__setattr__(self, '_core_handle', core_handle)
81
+
82
+ def __setattr__(self, _name: str, _value: object) -> None:
83
+ raise AttributeError('native effect binding is immutable')
84
+
85
+ def __reduce_ex__(self, _protocol: int):
86
+ raise TypeError('native effect binding cannot be serialized')
87
+
88
+ def __repr__(self) -> str:
89
+ return '<OriginalEffectBinding opaque>'
90
+
91
+
92
+ class ConfiguredEd25519OwnerAuthority:
93
+ """Pure configured owner-approval facade over the native-free core."""
94
+
95
+ __slots__ = ('_core',)
96
+
97
+ def __init__(self, configuration: object, *, ledger_path: str | os.PathLike[str],
98
+ context: OwnerAuthorityContext):
99
+ self._core = OwnerApprovalCore(configuration, ledger_path=ledger_path,
100
+ context=context)
101
+
102
+ @property
103
+ def authority_id(self) -> str:
104
+ return self._core.authority_id
105
+
106
+ @property
107
+ def policy_revision(self) -> str:
108
+ return self._core.policy_revision
109
+
110
+ @property
111
+ def configuration_digest(self) -> str:
112
+ return self._core.configuration_digest
113
+
114
+ @property
115
+ def authority_context(self) -> OwnerAuthorityContext:
116
+ return self._core.authority_context
117
+
118
+ def prepare_request(self, scope: str, exact_intent_bytes: bytes, *,
119
+ context: OwnerAuthorityContext) -> OwnerApprovalRequest:
120
+ return self._core.prepare_request(scope, exact_intent_bytes, context=context)
121
+
122
+ def export_signing_request(self, original_request: OwnerApprovalRequest) -> dict[str, Any]:
123
+ return self._core.export_signing_request(original_request)
124
+
125
+ def verify_approval(self, original_request: OwnerApprovalRequest,
126
+ signed_envelope: object) -> VerifiedOwnerApproval:
127
+ return self._core.verify_approval(original_request, signed_envelope)
128
+
129
+ def observe_approval(self, original_request: OwnerApprovalRequest) -> OriginalApprovalOutcome:
130
+ return self._core.observe_approval(original_request)
131
+
132
+ def observe_original_request(self, context: OwnerAuthorityContext,
133
+ effect_key: tuple[object, ...]) -> OriginalApprovalOutcome:
134
+ return self._core.observe_original_request(context, effect_key)
135
+
136
+ def _recover_original_request(self, scope: str, exact_intent_bytes: bytes, *,
137
+ context: OwnerAuthorityContext,
138
+ expected_approval_id: str) -> OwnerApprovalRequest:
139
+ return self._core._recover_original_request(
140
+ scope, exact_intent_bytes, context=context,
141
+ expected_approval_id=expected_approval_id)
142
+
143
+ def _recover_verified_approval(
144
+ self, original_request: OwnerApprovalRequest) -> VerifiedOwnerApproval:
145
+ return self._core._recover_verified_approval(original_request)
146
+
147
+ def _resolve_verified_approval(self, value: object, *,
148
+ original_request: OwnerApprovalRequest,
149
+ scope: str,
150
+ intent_digest: str) -> VerifiedOwnerApproval:
151
+ return self._core._resolve_verified_approval(
152
+ value, original_request=original_request,
153
+ scope=scope, intent_digest=intent_digest)
154
+
155
+
156
+ def _under_native_control_lease(operation_kind: str):
157
+ """Keep one fixed original physical lease across a complete facade call."""
158
+ def decorate(method):
159
+ @wraps(method)
160
+ def invoke(self, *args, **kwargs):
161
+ with self._supervisor._original_control_lease(
162
+ operation_kind=operation_kind) as lease:
163
+ result = method(self, *args, **kwargs)
164
+ self._supervisor._require_original_control_lease(
165
+ lease, operation_kind=operation_kind)
166
+ return result
167
+ return invoke
168
+ return decorate
169
+
170
+
171
+ class OwnerAuthoritySession:
172
+ """Native owner-session facade; all core/native transitions are joined here."""
173
+
174
+ __slots__ = ('_authority', '_bootstrap_issuer', '_effect_bindings', '_supervisor')
175
+
176
+ def __init__(self, authority: ConfiguredEd25519OwnerAuthority, *,
177
+ bootstrap_issuer: object, supervisor: object):
178
+ from .ingress_local_postgres import LocalPostgresSupervisor
179
+ if (type(authority) is not ConfiguredEd25519OwnerAuthority
180
+ or type(supervisor) is not LocalPostgresSupervisor
181
+ or type(bootstrap_issuer) is not _LocalOwnerBootstrapIssuer):
182
+ _reject('owner-native-session-untrusted')
183
+ if (supervisor._owner_core is not authority._core
184
+ or supervisor.authority_context is not authority.authority_context
185
+ or supervisor._bootstrap_issuer is not bootstrap_issuer):
186
+ _reject('owner-native-session-mismatch')
187
+ self._authority = authority
188
+ self._bootstrap_issuer = bootstrap_issuer
189
+ self._supervisor = supervisor
190
+ self._effect_bindings: dict[int, OriginalEffectBinding] = {}
191
+
192
+ @property
193
+ def authority(self) -> ConfiguredEd25519OwnerAuthority:
194
+ return self._authority
195
+
196
+ @property
197
+ def supervisor(self):
198
+ return self._supervisor
199
+
200
+ @property
201
+ def authority_context(self) -> OwnerAuthorityContext:
202
+ return self._authority.authority_context
203
+
204
+ @property
205
+ def authority_id(self) -> str:
206
+ return self._authority.authority_id
207
+
208
+ @property
209
+ def policy_revision(self) -> str:
210
+ return self._authority.policy_revision
211
+
212
+ def bind_native_effect(self, verified_approval: VerifiedOwnerApproval,
213
+ reservation: object) -> OriginalEffectBinding:
214
+ self._supervisor._require_original_control_lease()
215
+ request = (verified_approval._request
216
+ if type(verified_approval) is VerifiedOwnerApproval else None)
217
+ if type(request) is not OwnerApprovalRequest:
218
+ _reject('owner-approval-capability-mismatch')
219
+ verified = self._authority._resolve_verified_approval(
220
+ verified_approval, original_request=request, scope=request._scope,
221
+ intent_digest=request._intent_digest)
222
+ from .ingress_local_postgres import (
223
+ LocalPostgresSupervisor,
224
+ _NativeEffectReservation,
225
+ )
226
+ supervisor = self._supervisor
227
+ if (type(supervisor) is not LocalPostgresSupervisor
228
+ or type(reservation) is not _NativeEffectReservation):
229
+ _reject('owner-native-reservation-untrusted')
230
+ if (supervisor._native_effect_reservations.get(id(reservation)) is not reservation
231
+ or reservation._supervisor is not supervisor):
232
+ _reject('owner-native-reservation-untrusted')
233
+ if supervisor._resolve_native_effect_reservation(reservation, verified) is None:
234
+ _reject('owner-native-reservation-untrusted')
235
+ context = self.authority_context
236
+ if (reservation.scope != request._scope
237
+ or tuple(reservation.effect_key) != request._effect_key
238
+ or reservation.purpose != context._purpose
239
+ or reservation.request_id != request._approval_id
240
+ or reservation.request_digest != request._intent_digest
241
+ or reservation.approval_id != verified.approval_id
242
+ or reservation.approval_digest != verified.approval_digest):
243
+ _reject('owner-native-reservation-mismatch')
244
+ existing = next((binding for binding in self._effect_bindings.values()
245
+ if binding._request is request), None)
246
+ if existing is not None:
247
+ if existing._reservation is reservation:
248
+ return existing
249
+ _reject('owner-approval-already-consumed')
250
+ reservation_digest = _digest(reservation.journal_record_digest)
251
+ core_handle = self._authority._core._bind_effect_digest(verified, reservation_digest)
252
+ binding = OriginalEffectBinding(_EFFECT_SEAL, self, request, reservation,
253
+ reservation_digest, core_handle)
254
+ self._effect_bindings[id(binding)] = binding
255
+ return binding
256
+
257
+ def _binding_for_reservation(self, reservation: object) -> OriginalEffectBinding:
258
+ binding = next((item for item in self._effect_bindings.values()
259
+ if item._reservation is reservation), None)
260
+ if binding is None:
261
+ _reject('owner-native-effect-binding-required')
262
+ return binding
263
+
264
+ def _pending_effect_handle(self, binding: object, *, mode: str = 'execute') -> object:
265
+ """Return only this session's exact core handle for native verification."""
266
+ if (type(binding) is not OriginalEffectBinding or binding._issuer is not self
267
+ or self._effect_bindings.get(id(binding)) is not binding):
268
+ _reject('owner-native-effect-binding-required')
269
+ try:
270
+ self._authority._core._resolve_pending_effect(
271
+ binding._core_handle, original_request=binding._request,
272
+ reservation_digest=binding._reservation_digest, mode=mode)
273
+ except OwnerAuthorityError:
274
+ _reject('owner-native-effect-binding-required')
275
+ return binding._core_handle
276
+
277
+ def record_native_outcome(self, binding: OriginalEffectBinding,
278
+ outcome: object) -> OriginalApprovalOutcome:
279
+ self._supervisor._require_original_control_lease()
280
+ if (type(binding) is not OriginalEffectBinding or binding._issuer is not self
281
+ or self._effect_bindings.get(id(binding)) is not binding
282
+ or binding._kind != 'umf.owner-native-effect-binding/0.1'):
283
+ _reject('owner-native-effect-binding-required')
284
+ from .ingress_local_postgres import _VerifiedNativeEffectOutcome
285
+ supervisor = self._supervisor
286
+ reservation = binding._reservation
287
+ if type(outcome) is not _VerifiedNativeEffectOutcome:
288
+ _reject('owner-native-outcome-untrusted')
289
+ if (supervisor._native_effect_outcomes.get(id(outcome)) is not outcome
290
+ or outcome._issuer is not supervisor
291
+ or outcome._reservation is not reservation):
292
+ _reject('owner-native-outcome-untrusted')
293
+ from .ingress_local_postgres import LocalPostgresSupervisor
294
+ if type(supervisor) is not LocalPostgresSupervisor:
295
+ _reject('owner-native-outcome-untrusted')
296
+ if supervisor._resolve_native_effect_outcome(outcome, reservation) is None:
297
+ _reject('owner-native-outcome-untrusted')
298
+ if outcome.status not in ('confirmed', 'known-aborted'):
299
+ _reject('owner-native-outcome-untrusted')
300
+ result = self._authority._core._finish_effect_digest(
301
+ binding._request, binding._reservation_digest,
302
+ status='confirmed' if outcome.status == 'confirmed' else 'aborted',
303
+ receipt_digest=outcome.receipt_digest)
304
+ return result
305
+
306
+ @_under_native_control_lease('target-prepare')
307
+ def prepare_target_creation(self):
308
+ return self._supervisor.prepare_target_creation()
309
+
310
+ @_under_native_control_lease('target-recover')
311
+ def reattach_original_target(self):
312
+ """Reattach native state, then settle its exact owner-ledger outcome."""
313
+ target = self._supervisor.reattach_original_target()
314
+ reservation = target._reservation
315
+ binding = self.bind_native_effect(reservation._approval, reservation)
316
+ handle = self._pending_effect_handle(binding, mode='recover')
317
+ self._supervisor.confirm_reattached_target_creation(target, handle)
318
+ outcome = next((item for item in self._supervisor._native_effect_outcomes.values()
319
+ if item._reservation is reservation), None)
320
+ if outcome is None:
321
+ _reject('owner-native-outcome-untrusted')
322
+ binding = next((item for item in self._effect_bindings.values()
323
+ if item._reservation is reservation), None)
324
+ if binding is None:
325
+ _reject('owner-native-effect-binding-required')
326
+ self.record_native_outcome(binding, outcome)
327
+ return target
328
+
329
+ def export_owner_signing_request(self, request: object) -> dict[str, Any]:
330
+ return self._supervisor.export_owner_signing_request(request)
331
+
332
+ @_under_native_control_lease('target-apply')
333
+ def create_target(self, pending: object, signed_envelope: object) -> object:
334
+ request = pending._request
335
+ approval = self._authority.verify_approval(request, signed_envelope)
336
+ self._authority._resolve_verified_approval(
337
+ approval, original_request=request, scope='local-target-creation',
338
+ intent_digest=request._intent_digest)
339
+ reservation = self._supervisor.reserve_target_creation(pending, approval)
340
+ binding = self.bind_native_effect(approval, reservation)
341
+ handle = self._pending_effect_handle(binding)
342
+ target = self._supervisor.execute_target_creation(pending, reservation, handle)
343
+ outcome = next((item for item in self._supervisor._native_effect_outcomes.values()
344
+ if item._reservation is reservation), None)
345
+ if outcome is None:
346
+ _reject('owner-native-outcome-untrusted')
347
+ binding = next((item for item in self._effect_bindings.values()
348
+ if item._reservation is reservation), None)
349
+ if binding is None:
350
+ _reject('owner-native-effect-binding-required')
351
+ self.record_native_outcome(binding, outcome)
352
+ return target
353
+
354
+ @_under_native_control_lease('principals-prepare')
355
+ def prepare_original_principals(self, target: object):
356
+ return self._supervisor.prepare_original_principals(target)
357
+
358
+ @_under_native_control_lease('principals-recover')
359
+ def resume_original_principal_stage(self, target: object) -> dict[str, Any]:
360
+ reservation = self._supervisor.prepare_original_principal_recovery(target)
361
+ binding = self.bind_native_effect(reservation._approval, reservation)
362
+ handle = self._pending_effect_handle(binding, mode='recover')
363
+ receipt = self._supervisor.execute_original_principal_recovery(reservation, handle)
364
+ outcome = next((item for item in self._supervisor._native_effect_outcomes.values()
365
+ if item._reservation is reservation), None)
366
+ if outcome is None:
367
+ _reject('owner-native-outcome-untrusted')
368
+ binding = next((item for item in self._effect_bindings.values()
369
+ if item._reservation is reservation), None)
370
+ if binding is None:
371
+ _reject('owner-native-effect-binding-required')
372
+ self.record_native_outcome(binding, outcome)
373
+ return receipt
374
+
375
+ def export_principal_signing_request(self, prepared: object) -> dict[str, Any]:
376
+ return self._supervisor.export_principal_signing_request(prepared)
377
+
378
+ @_under_native_control_lease('principals-apply')
379
+ def apply_original_principals(self, prepared: object,
380
+ signed_envelope: object) -> dict[str, Any]:
381
+ request = prepared._request
382
+ approval = self._authority.verify_approval(request, signed_envelope)
383
+ self._authority._resolve_verified_approval(
384
+ approval, original_request=request,
385
+ scope='native-principal-preparation', intent_digest=request._intent_digest)
386
+ reservation = self._supervisor.reserve_original_principals(prepared, approval)
387
+ binding = self.bind_native_effect(approval, reservation)
388
+ handle = self._pending_effect_handle(binding)
389
+ receipt = self._supervisor.execute_original_principals(prepared, reservation, handle)
390
+ outcome = next((item for item in self._supervisor._native_effect_outcomes.values()
391
+ if item._reservation is reservation), None)
392
+ if outcome is None:
393
+ _reject('owner-native-outcome-untrusted')
394
+ binding = next((item for item in self._effect_bindings.values()
395
+ if item._reservation is reservation), None)
396
+ if binding is None:
397
+ _reject('owner-native-effect-binding-required')
398
+ self.record_native_outcome(binding, outcome)
399
+ return receipt
400
+
401
+ @_under_native_control_lease('registration-prepare')
402
+ def prepare_target_registration(self, target: object):
403
+ return self._supervisor.prepare_target_registration(target)
404
+
405
+ @_under_native_control_lease('registration-recover')
406
+ def reattach_original_registration(self, target: object) -> object:
407
+ reservation = self._supervisor.prepare_original_registration_reattachment(target)
408
+ binding = self.bind_native_effect(reservation._approval, reservation)
409
+ handle = self._pending_effect_handle(binding, mode='recover')
410
+ result = self._supervisor.execute_original_registration_reattachment(
411
+ reservation, handle)
412
+ outcome = next((item for item in self._supervisor._native_effect_outcomes.values()
413
+ if item._reservation is reservation), None)
414
+ if outcome is None:
415
+ _reject('owner-native-outcome-untrusted')
416
+ binding = next((item for item in self._effect_bindings.values()
417
+ if item._reservation is reservation), None)
418
+ if binding is None:
419
+ _reject('owner-native-effect-binding-required')
420
+ self.record_native_outcome(binding, outcome)
421
+ return result
422
+
423
+ def export_target_registration_request(self, prepared: object) -> dict[str, Any]:
424
+ return self._supervisor.export_target_registration_request(prepared)
425
+
426
+ @_under_native_control_lease('registration-apply')
427
+ def apply_target_registration(self, prepared: object,
428
+ signed_envelope: object) -> object:
429
+ request = prepared._request
430
+ approval = self._authority.verify_approval(request, signed_envelope)
431
+ self._authority._resolve_verified_approval(
432
+ approval, original_request=request, scope='local-target-registration',
433
+ intent_digest=request._intent_digest)
434
+ reservation = self._supervisor.reserve_target_registration(prepared, approval)
435
+ binding = self.bind_native_effect(approval, reservation)
436
+ handle = self._pending_effect_handle(binding)
437
+ result = self._supervisor.execute_target_registration(prepared, reservation, handle)
438
+ outcome = next((item for item in self._supervisor._native_effect_outcomes.values()
439
+ if item._reservation is reservation), None)
440
+ if outcome is None:
441
+ _reject('owner-native-outcome-untrusted')
442
+ binding = next((item for item in self._effect_bindings.values()
443
+ if item._reservation is reservation), None)
444
+ if binding is None:
445
+ _reject('owner-native-effect-binding-required')
446
+ self.record_native_outcome(binding, outcome)
447
+ return result
448
+
449
+
450
+ def create_owner_authority_session(profile: LocalPostgresProfile, *,
451
+ ledger_path: str | os.PathLike[str]) -> OwnerAuthoritySession:
452
+ """Create a native session only from original enrollment and a durably bound ledger."""
453
+ from .ingress_local_postgres import (
454
+ LocalPostgresSupervisor,
455
+ _issue_local_owner_bootstrap_issuer,
456
+ )
457
+ from .owner_bootstrap import _settle_original_owner_setup
458
+
459
+ _settle_original_owner_setup(profile, ledger_path)
460
+ issuer = _issue_local_owner_bootstrap_issuer(profile)
461
+ config, _keys = _validate_config(issuer.owner_configuration)
462
+ configuration_digest = _digest_bytes(_canonical_bytes(config))
463
+ context = _issue_owner_authority_context(issuer, configuration_digest)
464
+ bound_path = Path(ledger_path)
465
+ authority = ConfiguredEd25519OwnerAuthority(
466
+ config, ledger_path=bound_path, context=context)
467
+ authority._core._ensure_ledger_initialized()
468
+ supervisor = LocalPostgresSupervisor(
469
+ profile, owner_core=authority._core, authority_context=context,
470
+ bootstrap_issuer=issuer)
471
+ return OwnerAuthoritySession(authority, bootstrap_issuer=issuer,
472
+ supervisor=supervisor)