Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@supernova-team/xml-sunat

supernova-team212MIT0.9.6TypeScript support: included

Librería para poder firmar XML's según la SUNAT

xml, signature, SUNAT, xml signature, node

readme

xml-sunat

Logo de la superintendencia nacional de administración tributaria - SUNAT

xml-sunat es una librería de JavaScript para poder firmar xml para la entidad de SUNAT. La librería depende de xml-crypto.

Instalación

# npm
npm i @supernova-team/xml-sunat
# pnpm
pnpm add @supernova-team/xml-sunat

Modo de uso

Para poder firmar un xml, debemos importar la clase XmlSignature y pasar los argumentos al constructor.

import { XmlSignature } from "@supernova-team/xml-sunat";
import path from 'node:path';
import fs from 'fs';

//Ruta a tu archivo pfx
const pfxFilePath = path.join("path", "to", "cdr"); 
//Contraseña de tu archivo .pfx
const password = "pfxPassword";
//Xml a firmar
const xmlStringStructure = "<Invoice>...</Invoice>";

const sig = new XmlSignature(pfxFilePath, password, xmlStringStructure);

sig.getSignedXML().then((signedXML)=> {
    fs.writeFileSync('your-filename.xml', signedXML);
})
.catch((err) => {
    console.error('An error has occurred: '+ err);
})
;

Licencia

MIT