import { type Sphere } from "./did.js"; import { type Identity } from "./identity.js"; import { type Author } from "./author.js"; import { type Section } from "./ethos.js"; import { type ManifestV03 } from "./bundle-v03.js"; import { type BatchSectionEdit, type SectionChange } from "./bundle-edit.js"; /** The on-disk format a NEW edition is written in. */ export type WriteFormat = "v0.2" | "v0.3"; /** * The default on-disk write format. v0.3 (per-section) is now the default; * set `AITHOS_FORMAT=v0.2` (or `0.2.0`) to opt back into the legacy monolithic * format for a fresh `init` and to suppress auto-migration on the first write. * Any other value (unset, `v0.3`, `0.3.0`) selects v0.3. */ export declare function defaultWriteFormat(): WriteFormat; /** The `aithos` version of the installed ethos, or `null` if there is no ethos. */ export declare function keystoreEthosVersion(handle: string): string | null; /** True if the installed ethos is stored in the v0.3 per-section format. */ export declare function isV03Keystore(handle: string): boolean; export interface MigrateKeystoreArgs { handle: string; identity: Identity; now?: Date; } /** * Migrate the installed v0.2 ethos to the v0.3 per-section format IN PLACE. The * ethos dir becomes a v0.3 bundle; the prior v0.2 manifest is archived under * `history/`. Idempotent guard: throws if the ethos is already v0.3. */ export declare function migrateKeystoreInPlace(args: MigrateKeystoreArgs): ManifestV03; /** * Create a fresh, EMPTY v0.3 ethos directly in the keystore (edition height 1, * no predecessor). Used by `ethos init` / `aithos init` when v0.3 is the write * default ({@link defaultWriteFormat}). The caller must have already ensured the * target ethos dir is absent (or wiped under `--force`); the identity's * `did.json` must exist on disk (authorBundleV03 copies + hashes it). */ export declare function initKeystoreV03(args: { handle: string; identity: Identity; now?: Date; }): ManifestV03; /** * On the owner write path, migrate an installed v0.2 ethos to v0.3 IN PLACE when * v0.3 is the default write format ({@link defaultWriteFormat}). No-op when the * default is v0.2, when the ethos is already v0.3, or when there is no ethos. * Returns true iff a migration ran. Requires the owner identity (sphere keys); * delegate writers cannot migrate and should not call this. */ export declare function autoMigrateKeystoreIfDefault(args: MigrateKeystoreArgs): boolean; export interface KeystoreEditArgs { handle: string; author: Identity | Author; zone: Sphere; sectionId: string; /** Upsert (add/modify). Omit for a delete. */ change?: SectionChange; delete?: boolean; gammaRef?: string; now?: Date; } /** * Add/modify/delete a section in the installed v0.3 ethos, writing a new * edition into the keystore (only the touched section is re-encrypted; the rest * carry forward; the prior manifest is archived). Owner or delegate. */ export declare function keystoreEditSection(args: KeystoreEditArgs): ManifestV03; /** Read the installed v0.3 ethos into per-zone sections (decrypting with the owner's keys). */ export declare function keystoreReadSectionsV03(handle: string, owner: Identity): Record; /** * Apply N section edits to the installed v0.3 ethos in ONE new edition * (P2 transactional path — the batch counterpart of {@link keystoreEditSection}). * Same tmp-build + atomic swap + history-archive flow. */ export declare function keystoreEditSections(args: { handle: string; author: Identity | Author; edits: readonly BatchSectionEdit[]; now?: Date; }): ManifestV03;