/** * DOCX Module - Document Protection * * Provides APIs for setting document protection passwords and restrictions. * Supports all protection types defined in OOXML: * - Read-only (no modifications allowed) * - Comments only (only add comments) * - Forms only (only fill form fields) * - Tracked changes (all changes are tracked) * - Sections (specific sections editable) * * Password hashing follows the ECMA-376 specification using * iterative SHA-based hashing with salt. */ import type { DocxDocument } from "../types.js"; /** Document protection type (edit restriction). */ export type ProtectionEditType = "none" | "readOnly" | "comments" | "trackedChanges" | "forms"; /** Hash algorithm for protection password. */ export type ProtectionHashAlgorithm = "SHA-1" | "SHA-256" | "SHA-384" | "SHA-512"; /** Options for setting document protection. */ export interface DocumentProtectionOptions { /** Type of edit restriction. */ readonly edit: ProtectionEditType; /** Password to protect the document (will be hashed). */ readonly password?: string; /** Hash algorithm. Default: "SHA-256". */ readonly hashAlgorithm?: ProtectionHashAlgorithm; /** Number of hash iterations (spin count). Default: 100000. */ readonly spinCount?: number; /** Whether protection is enforced. Default: true. */ readonly enforcement?: boolean; /** Formatting restriction (prevent style changes). */ readonly formatting?: boolean; } /** Protection state as stored in settings. */ export interface ProtectionState { /** Edit restriction type. */ readonly edit: ProtectionEditType; /** Whether protection is enforced. */ readonly enforcement: boolean; /** Hash algorithm used. */ readonly hashAlgorithm?: string; /** Computed hash value (base64). */ readonly hashValue?: string; /** Salt (base64). */ readonly saltValue?: string; /** Spin count (iterations). */ readonly spinCount?: number; /** Formatting restriction. */ readonly formatting?: boolean; } /** * Set document protection on a DocxDocument. * Returns a new document with protection settings applied. * * @param doc - The document to protect. * @param options - Protection options. * @returns A new document with protection settings. * * @example * ```ts * const protected = await protectDocument(doc, { * edit: "readOnly", * password: "secret123", * hashAlgorithm: "SHA-256" * }); * ``` */ export declare function protectDocument(doc: DocxDocument, options: DocumentProtectionOptions): Promise; /** * Remove document protection. * * @param doc - The protected document. * @returns A new document without protection. */ export declare function unprotectDocument(doc: DocxDocument): DocxDocument; /** * Check if a document is protected. */ export declare function isDocumentProtected(doc: DocxDocument): boolean; /** * Get the protection state of a document. */ export declare function getProtectionState(doc: DocxDocument): ProtectionState | undefined; /** * Verify a password against the document's protection hash. * Returns true if the password matches, false otherwise. * * @param doc - The protected document. * @param password - The password to verify. * @returns Whether the password is correct. */ export declare function verifyProtectionPassword(doc: DocxDocument, password: string): Promise;