import type { ColdCode } from "../core/types.js"; import { Matter, type MatterInit } from "./matter.js"; /** * SAD-facing textual threshold weight token such as `"1"` or `"1/2"`. * * KERIpy correspondence: weighted threshold members are expressed as strings * in the event body, then normalized into exact rational arithmetic for * satisfaction checks. */ export type ThresholdWeight = string; /** * Single nested weighted group inside one clause. * * Boundary contract: * - the map must contain exactly one entry * - the key is the outer group weight contributed to the clause when the group * itself is satisfied * - the value array lists the nested member weights that consume consecutive * signer slots inside the group */ export type ThresholdNestedGroup = Record; /** One top-level entry inside a weighted clause. */ export type ThresholdClauseEntry = ThresholdWeight | ThresholdNestedGroup; /** * One weighted clause. * * Maintainer model: entries inside a clause contribute toward that clause's * `>= 1` satisfaction test, while multiple clauses in a full threshold are * AND'ed together. */ export type ThresholdClause = ThresholdClauseEntry[]; /** * Full weighted threshold expression. * * A single clause may be represented directly as `ThresholdClause`; a * multi-clause threshold is represented as `ThresholdClause[]`. */ export type WeightedThreshold = ThresholdClause | ThresholdClause[]; /** * Public semantic threshold union used at SAD and state-record boundaries. * * Examples for maintainers defining thresholds with the exported type system: * ```ts * const numeric: ThresholdSith = "2"; * * const flatWeighted: ThresholdSith = ["1/2", "1/2", "1/4", "1/4"]; * * const groupedWeighted: ThresholdSith = [ * { "1/2": ["1/2", "1/4", "1/4"] }, * "1/2", * ]; * * const multiClause: ThresholdSith = [ * ["1/2", "1/2"], * [{ "1/2": ["1/3", "1/3", "1/3"] }, "1/2"], * ]; * ``` * * Slot-order rule: * - signer slots are consumed from left to right * - plain weights consume one signer slot each * - nested groups consume one signer slot per nested member, not one slot for * the outer map wrapper */ export type ThresholdSith = string | WeightedThreshold; /** * Constructor-friendly threshold input accepted by `Tholder`. * * Numeric thresholds may arrive as numbers/bigints or through the SAD-facing * lowercase-hex string forms inside `ThresholdSith`. */ export type ThresholdInput = ThresholdSith | number | bigint; /** Exact rational used internally so weighted arithmetic never depends on floats. */ interface Rational { numerator: bigint; denominator: bigint; } /** * Normalized nested group. * * `weight` is the clause contribution unlocked by the group, and `members` * holds the nested signer-member weights that must themselves sum to `>= 1`. */ interface WeightedGroup { weight: Rational; members: Rational[]; } /** Internal union for one normalized weighted clause entry. */ type NormalizedClauseEntry = Rational | WeightedGroup; /** Internal normalized clause representation used by satisfaction logic. */ type NormalizedWeightedThreshold = NormalizedClauseEntry[]; /** * Threshold expression primitive. * * KERIpy substance: * - `Tholder` supports both numeric thresholds and weighted threshold * expressions encoded as StrB64 payloads * - `satisfy(indices)` is the semantic contract upper layers rely on when * validating current and prior-next threshold satisfaction * - `limen` reuses the CESR `Number` family for numeric thresholds and the * `Bexter` bext encoding for weighted thresholds */ export declare class Tholder extends Matter { private readonly _weighted; private readonly _num; private readonly _size; private readonly _thold; private readonly _sith; /** * Construct from wire material (`Matter`, `MatterInit`, `limen`) or semantic * threshold input (`sith`, bigint, number, hex string, weighted arrays). */ constructor(init: Matter | MatterInit | ThresholdInput | { limen?: string | Uint8Array; sith?: ThresholdInput; }); /** True when this instance represents a weighted threshold rather than a numeric count. */ get weighted(): boolean; /** * Number of signer slots consumed by this threshold expression. * * For nested groups this counts nested members, because those are the real * contiguous signer slots upper layers index into. */ get size(): number; /** Internal normalized threshold semantics exposed for maintainer debugging and tests. */ get thold(): bigint | NormalizedWeightedThreshold[]; /** Numeric threshold value when `weighted === false`, otherwise `null`. */ get num(): bigint | null; /** * Qualified CESR threshold representation used in event bodies and state. * * Numeric thresholds are encoded through the numeric matter family; weighted * thresholds are encoded through the compact bext/limen form KERIpy uses. */ get limen(): string; /** Public semantic threshold expression cloned back into SAD-facing shape. */ get sith(): ThresholdSith; /** * Test whether the provided signer indices satisfy this threshold. * * Maintainer model: * - numeric thresholds are pure cardinality checks after deduplication is * handled by the caller or irrelevant to the count * - weighted thresholds project indices onto consecutive signer slots from * left to right across clauses and nested-group members * - each clause must accumulate at least weight `1` */ satisfy(indices: readonly number[]): boolean; } /** * Parse and hydrate `Tholder` from txt/qb2 bytes. * * Boundary contract: stream parsing decides whether the next token is text or * binary CESR, while `Tholder` owns threshold-codex validation and semantic * hydration after the underlying `Matter` is parsed. */ export declare function parseTholder(input: Uint8Array, cold: Extract): Tholder; export {}; //# sourceMappingURL=tholder.d.ts.map