UNPKG

dte-signer-sv

Version:

Sign Digital Tax Documents (DTE) for El Salvador's Ministry of Finance

58 lines (57 loc) 1.83 kB
export interface SignDTEParams { /** * The DTE (Digital Tax Document) object to be signed */ dte: object; /** * The password for the private key */ privatePassword: string; /** * The certificate in XML format (string) or path to the certificate file */ certificate: string; /** * If true, the certificate parameter is treated as a file path. * If false or undefined, the certificate parameter is treated as the XML content. * @default false */ loadCertificateFromPath?: boolean; } /** * Signs a DTE (Digital Tax Document) for El Salvador using a certificate and private key password. * * @param params - The parameters for signing the DTE * @returns A Promise that resolves to the signed DTE in JWS compact format * * @example * // Example 1: Using certificate file path * const signedDTE = await signDTE({ * dte: { * identificacion: { * version: 1, * ambiente: "00", * tipoDte: "01", * // ... other DTE fields * } * }, * privatePassword: "mySecurePassword123", * certificate: "./certificates/88888888888888.crt", * loadCertificateFromPath: true * }); * * @example * // Example 2: Using certificate XML content directly * const certXML = fs.readFileSync("./certificate.crt", "utf8"); * const signedDTE = await signDTE({ * dte: myDTEObject, * privatePassword: "mySecurePassword123", * certificate: certXML * }); * * @throws {Error} Throws an error if the private password is invalid * @throws {Error} Throws an error if the certificate cannot be parsed * @throws {Error} Throws an error if the certificate file is not found (when loadCertificateFromPath is true) */ export declare const signDTE: (params: SignDTEParams) => Promise<string>; export default signDTE;