import { TruncatedEcfField } from '../utils/limitEcfFieldLengths'; /** * Common DGII electronic document types. * Provides autocomplete for known types while allowing any custom string. */ export type DGIIDocumentType = 'SemillaModel' | 'ECF' | 'RFCE' | 'ARECF' | 'ACECF' | 'ANECF' | (string & {}); export interface SignXmlOptions { /** * For an `ECF`, cut every free-text field longer than the DGII allows * (e.g. `NombreItem` > 80) before signing. Default `true`: the DGII rejects * an e-CF with a field over its limit and still consumes its e-NCF. * Set `false` to sign the document exactly as given. */ limitFieldLengths?: boolean; /** Called once per field cut by `limitFieldLengths`, e.g. to log it. */ onFieldTruncated?: (info: TruncatedEcfField) => void; } /** * @deprecated Use DGIIDocumentType instead */ export type XMLTag = DGIIDocumentType; declare class Signature { private _privateKey; private _certificatePEM; constructor(privateKey: string, _certificatePEM: string); /** * Remove empty spaces and new lines * @param node */ private cleanNodes; /** * Parses XML string with strict error handling. * @param xml - The XML document as a string * @returns The parsed Document * @throws Error if XML is invalid or cannot be parsed */ private parseXmlStrict; /** * Signs an XML document with DGII-compliant digital signature. * * @param xml - The XML document to sign as a string * @param rootElName - Optional root element name. If not provided, it will be auto-detected from the XML. * Common DGII types: 'ECF', 'RFCE', 'ARECF', 'ACECF', 'ANECF', 'SemillaModel' * Can also be any custom element like 'Postulacion', 'CustomDocument', etc. * @param options - For an `ECF`, free-text fields over their DGII limit are cut before * signing unless `limitFieldLengths` is `false` (see {@link SignXmlOptions}). * @returns The signed XML document with embedded element * @throws Error if XML is invalid or cannot be parsed * * @example * // Auto-detect root element (recommended for simplicity) * const signedXml = signature.signXml(xmlString); * * @example * // Explicitly specify root element * const signedECF = signature.signXml(xmlString, 'ECF'); * * @example * // Sign any arbitrary XML document * const signedPostulacion = signature.signXml(postulacionXml); */ signXml: (xml: string, rootElName?: DGIIDocumentType, options?: SignXmlOptions) => string; } export default Signature;