import { PublicSignKey } from "@peerbit/crypto"; import { NetworkDescriptorV2, PolicySnapshotBodyV2, PolicySubjectBindingV2 } from "./v2.js"; /** * Internal policy reducer for the non-activatable TrustedNetwork v2 scaffold. * * The reducer intentionally is not exported from the package entry point. It * retains one accepted snapshot, a bounded pending working set, and (after * equivocation) two child proofs. Historical snapshots are supplied by the * resolver instead of being accumulated in memory. */ /** Internal protocol ceiling; this module is not part of the package root. */ export declare const TRUSTED_NETWORK_V2_MAX_PENDING_POLICIES = 64; type ValidatedPolicySnapshotV2 = { body: PolicySnapshotBodyV2; digest: Uint8Array; digestKey: string; entryBytes: Uint8Array; accountedBytes: number; }; export type PolicySnapshotResolverV2 = (digest: Uint8Array, options: { signal: AbortSignal; }) => Uint8Array | undefined | Promise; export type PolicyParentFetchHintV2 = { kind: "policy-parent"; digest: Uint8Array; }; export type PolicyHeadProjectionV2 = { sequence: bigint; digest: Uint8Array; bindings: PolicySubjectBindingV2[]; }; /** Internal read-only resolution used by the durable policy-prefix lease. */ export type AcceptedPolicyPrefixResolutionV2 = { status: "resolved"; policy: PolicyHeadProjectionV2; acceptedHead: PolicyHeadProjectionV2; } | { status: "unavailable" | "rejected" | "halted"; reason: string; }; /** Per-call bounds for the internal accepted-prefix history walk. */ export type AcceptedPolicyPrefixTraversalV2 = { /** Maximum number of authenticated parent edges that may be resolved. */ maxSteps?: number; /** Absolute wall-clock deadline, in milliseconds since the Unix epoch. */ deadline?: number; /** Cancels this resolution without halting the reducer. */ signal?: AbortSignal; }; export type PolicyForkChildProofV2 = { sequence: bigint; digest: Uint8Array; entryBytes: Uint8Array; }; export type PolicyForkEvidenceV2 = { commonParent: PolicyHeadProjectionV2; children: [PolicyForkChildProofV2, PolicyForkChildProofV2]; }; export type PolicyAdmissionStatusV2 = "accepted" | "duplicate" | "pending" | "unavailable" | "capacity" | "rejected" | "forked" | "halted"; export type PolicyAdmissionResultV2 = { status: PolicyAdmissionStatusV2; reason?: string; head?: PolicyHeadProjectionV2; /** * Authenticated direct children surfaced while entering or already in * FORKED. The outer durable layer can persist these proofs without decoding * or verifying them a second time. They are bounded by one admission plus the * pending working set and are not accumulated by this reducer. */ forkObservations?: PolicyForkChildProofV2[]; fetchHints: PolicyParentFetchHintV2[]; pendingCount: number; pendingBytes: number; evictedPolicyDigests?: Uint8Array[]; }; export type PolicyReducerDurableStateV2 = { formatVersion: 1; state: "EMPTY"; } | { formatVersion: 1; state: "ACTIVE"; acceptedHeadEntryBytes: Uint8Array; } | { formatVersion: 1; state: "UNAVAILABLE"; acceptedHeadEntryBytes: Uint8Array; comparisonCandidateEntryBytes: Uint8Array; acceptedAncestorDigest: Uint8Array; reason: string; } | { formatVersion: 1; state: "FORKED"; commonParentEntryBytes: Uint8Array; childEntryBytes: [Uint8Array, Uint8Array]; }; export type TrustedNetworkV2PolicyReducerProperties = { descriptor: NetworkDescriptorV2; resolvePolicyEntry: PolicySnapshotResolverV2; resolveTimeoutMs?: number; signal?: AbortSignal; maxPending?: number; maxPendingPolicyBytes?: number; }; export declare const authenticatePolicySnapshotEntryV2: (entryBytes: Uint8Array, descriptor: NetworkDescriptorV2) => Promise; export declare class TrustedNetworkV2PolicyReducer { private readonly descriptor; private readonly resolvePolicyEntry; private readonly resolveTimeoutMs; private readonly maxPending; private readonly maxPendingPolicyBytes; private readonly lifecycleController; private externalSignal?; private externalAbortListener?; private acceptedHead?; private projectedRoles; private readonly pending; private unavailable?; private fork?; private admissionTail; constructor(properties: TrustedNetworkV2PolicyReducerProperties); static restore(properties: TrustedNetworkV2PolicyReducerProperties & { durableState: PolicyReducerDurableStateV2; }): Promise; get state(): "EMPTY" | "ACTIVE" | "UNAVAILABLE" | "FORKED" | "HALTED"; get head(): PolicyHeadProjectionV2 | undefined; get forkEvidence(): PolicyForkEvidenceV2 | undefined; get pendingCount(): number; get pendingBytes(): number; get pendingDigests(): Uint8Array[]; exportDurableState(): PolicyReducerDurableStateV2; rolesFor(subject: PublicSignKey): number; isAuthorized(subject: PublicSignKey, roles: number): boolean; /** * Resolve one exact digest on the currently accepted policy prefix. * * The durable wrapper serializes this read with publication and owns the * callback lifetime. The core still serializes the resolver work with direct * users of this internal class. Historical snapshots remain resolver-backed; * this walk retains only one authenticated cursor at a time. */ resolveAcceptedPolicyPrefix(reference: { sequence: bigint; digest: Uint8Array; }, traversal?: AcceptedPolicyPrefixTraversalV2): Promise; abort(): void; private resolveAcceptedPolicyPrefixOne; private acceptedPrefixInterruption; private fetchHints; private result; private forkedResult; private haltedResult; private unavailableResult; private completedDrainResult; private project; private retainCanonicalHeadEntry; private resolveExternalSnapshot; private resolveSnapshot; private parentOf; private candidateAncestryResult; private acceptedAncestryUnavailable; private evaluate; private setFork; private retainCanonicalForkChild; private observeAfterFork; private addPending; private enterUnavailable; private drainPending; private enqueueAdmission; ingest(entryBytes: Uint8Array): Promise; retryUnavailable(): Promise; private ingestOne; private retryUnavailableOne; } export {}; //# sourceMappingURL=v2-policy-engine.d.ts.map