import type { CoID } from "../coValue.js"; import type { AvailableCoValueCore, CoValueCore, DecryptedTransaction } from "../coValueCore/coValueCore.js"; import type { CoValueUniqueness } from "../coValueCore/verifiedState.js"; import type { CryptoProvider, Encrypted, KeyID, KeySecret, Sealed, SealedForGroup, SealerID, SealerSecret } from "../crypto/crypto.js"; import { AgentID, ChildGroupReference, ParentGroupReference } from "../ids.js"; import { JsonObject, JsonValue } from "../jsonValue.js"; import { AccountRole, Role } from "../permissions.js"; import { ControlledAccountOrAgent, RawAccount, RawAccountID } from "./account.js"; import { RawCoList } from "./coList.js"; import { RawCoMap } from "./coMap.js"; import { RawCoPlainText } from "./coPlainText.js"; import { RawBinaryCoStream } from "./binaryCoStream.js"; import { RawCoStream } from "./coStream.js"; export declare const EVERYONE: "everyone"; export type Everyone = "everyone"; /** * Format a composite groupSealer value that includes the readKeyID. * New format: "readKeyID@sealerID" - explicitly associates the sealer with * the readKey it was derived from. This prevents inconsistency when different * admins concurrently rotate keys and migrate the groupSealer. * * @internal */ export declare function formatGroupSealerValue(readKeyID: KeyID, sealerID: SealerID): `key_z${string}@sealer_z${string}`; export type ParentGroupReferenceRole = "revoked" | "extend" | "reader" | "writer" | "manager" | "admin"; export type GroupShape = { profile: CoID | null; root: CoID | null; [key: RawAccountID | AgentID]: Role; [EVERYONE]?: Role; readKey?: KeyID; groupSealer?: `${KeyID}@${SealerID}`; [writeKeyFor: `writeKeyFor_${RawAccountID | AgentID}`]: KeyID; [revelationFor: `${KeyID}_for_${RawAccountID | AgentID}`]: Sealed; [revelationFor: `${KeyID}_for_${Everyone}`]: KeySecret; [oldKeyForNewKey: `${KeyID}_for_${KeyID}`]: Encrypted; [keyForSealer: `${KeyID}_sealedFor_${SealerID}`]: SealedForGroup; [parent: ParentGroupReference]: ParentGroupReferenceRole; [child: ChildGroupReference]: "revoked" | "extend"; }; /** A `Group` is a scope for permissions of its members (`"reader" | "writer" | "admin"`), applying to objects owned by that group. * * A `Group` object exposes methods for permission management and allows you to create new CoValues owned by that group. * * (Internally, a `Group` is also just a `CoMap`, mapping member accounts to roles and containing some * state management for making cryptographic keys available to current members) * * @example * You typically get a group from a CoValue that you already have loaded: * * ```typescript * const group = coMap.group; * ``` * * @example * Or, you can create a new group with a `LocalNode`: * * ```typescript * const localNode.createGroup(); * ``` * */ export declare class RawGroup extends RawCoMap { protected readonly crypto: CryptoProvider; _lastReadableKeyId?: KeyID; private parentGroupsChanges; private keyRevelations; protected resetInternalState(): void; constructor(core: AvailableCoValueCore, options?: { ignorePrivateTransactions: boolean; }); handleNewTransaction(transaction: DecryptedTransaction): void; private updateKeyRevelationsCache; private updateParentGroupCache; migrate(): void; /** * Optional display name set at group creation. Immutable; stored in plaintext in header meta. */ get name(): string | undefined; /** * Returns the current role of a given account. * * @category 1. Role reading */ roleOf(accountID: RawAccountID | typeof EVERYONE): Role | undefined; /** * This is a performance-critical function, micro-optimizing it is important * * Avoid to add objects/array allocations in this function */ /** @internal */ roleOfInternal(accountID: RawAccountID | AgentID | typeof EVERYONE): Role | undefined; getParentGroup(id: CoID, atTime?: number): RawGroup; getParentGroups(): RawGroup[]; forEachChildGroup(callback: (child: RawGroup) => void): void; /** * Returns the role of the current account in the group. * * @category 1. Role reading */ myRole(): Role | undefined; /** * Directly grants a new member a role in the group. The current account must be an * admin to be able to do so. Throws otherwise. * * @category 2. Role changing */ addMember(account: RawAccount | ControlledAccountOrAgent | Everyone, role: Role): void; /** @internal */ addMemberInternal(account: RawAccount | ControlledAccountOrAgent | AgentID | Everyone, role: Role): void; private internalCreateWriteOnlyKeyForMember; private storeKeyRevelationForMember; private storeKeyRevelationForParentGroup; private getWriteOnlyKeys; getCurrentReadKeyId(): `key_z${string}` | undefined; getMemberKeys(): (RawAccountID | AgentID)[]; getAllMemberKeysSet(): Set; getReadKey(keyID: KeyID): KeySecret | undefined; getUncachedReadKey(keyID: KeyID): `keySecret_z${string}` | undefined; /** * Try to decrypt a key that was revealed via a parent group's sealer. * Walks the parent group's groupSealer history backwards (newest first) * and tries to unseal the key revelation for each historical sealer value. * * New format groupSealer values embed the readKeyID directly (e.g., "key_z..._sealer_z...") * so we can deterministically find the correct readKey without time-based correlation. * Legacy format values (just "sealer_z...") fall back to time-based readKey lookup. */ private tryDecryptWithGroupSealer; private findValidParentKeys; /** @internal */ rotateReadKey(removedMemberKey?: RawAccountID | AgentID | "everyone"): void; /** Detect circular references in group inheritance */ isSelfExtension(parent: RawGroup): boolean; getCurrentReadKey(): { secret: `keySecret_z${string}` | undefined; id: `key_z${string}`; }; /** * Get the group sealer secret by deriving it from the associated read key. * Uses the readKeyID embedded in the composite groupSealer value (new format), * or falls back to the current read key (legacy format). * Returns undefined if we don't have access to the read key. */ getGroupSealerSecret(): SealerSecret | undefined; extend(parent: RawGroup, role?: "reader" | "writer" | "manager" | "admin" | "inherit"): void; private revealReadKeyToParentGroup; /** * Store a key revelation encrypted to a parent group's sealer (anonymous box). * Used when extending a child group to a parent group we don't have access to. */ private storeKeyRevelationForGroupSealer; revokeExtend(parent: RawGroup): void; /** * Strips the specified member of all roles (preventing future writes in * the group and owned values) and rotates the read encryption key for that group * (preventing reads of new content in the group and owned values) * * @category 2. Role changing */ removeMember(account: RawAccount | ControlledAccountOrAgent | Everyone): void; /** * Creates an invite for new members to indirectly join the group, * allowing them to grant themselves the specified role with the InviteSecret * (a string starting with "inviteSecret_") - use `LocalNode.acceptInvite()` for this purpose. * * @category 2. Role changing */ createInvite(role: AccountRole): InviteSecret; private assertCanWrite; /** * Creates a new `CoMap` within this group, with the specified specialized * `CoMap` type `M` and optional static metadata. * * @category 3. Value creation */ createMap(init?: M["_shape"], meta?: M["headerMeta"], initPrivacy?: "trusting" | "private", uniqueness?: CoValueUniqueness, initMeta?: JsonObject): M; /** * Creates a new `CoList` within this group, with the specified specialized * `CoList` type `L` and optional static metadata. * * @category 3. Value creation */ createList(init?: L["_item"][], meta?: L["headerMeta"], initPrivacy?: "trusting" | "private", uniqueness?: CoValueUniqueness, initMeta?: JsonObject, options?: { restrictDeletion?: boolean; }): L; /** * Creates a new `CoPlainText` within this group, with the specified specialized * `CoPlainText` type `T` and optional static metadata. * * @category 3. Value creation */ createPlainText(init?: string, meta?: T["headerMeta"], initPrivacy?: "trusting" | "private"): T; /** @category 3. Value creation */ createStream(init?: JsonValue[], initPrivacy?: "trusting" | "private", meta?: C["headerMeta"], uniqueness?: CoValueUniqueness, initMeta?: JsonObject): C; /** @category 3. Value creation */ createBinaryStream(meta?: C["headerMeta"], uniqueness?: CoValueUniqueness): C; } export declare function isInheritableRole(roleInParent: Role | undefined): roleInParent is "revoked" | "admin" | "manager" | "writer" | "reader"; export type InviteSecret = `inviteSecret_z${string}`; export declare function secretSeedFromInviteSecret(inviteSecret: InviteSecret): Uint8Array; export declare function isSelfExtension(coValue: CoValueCore, parent: RawGroup): boolean; //# sourceMappingURL=group.d.ts.map