npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ec-sri-invoice-signer

v1.1.0

Published

Ecuador SRI invoice signer.

Downloads

230

Readme

ec-sri-invoice-signer

Firmador de facturas basado en las especificaciones del Servicio de Rentas Internas (SRI) ecuatoriano. Está escrito en puro TypeScript/JavaScript, sin dependencias de binarios criptográficos como OpenSSL, DLLs con la lógica de firmado o similares. Por tal razón, funciona en Windows, Unix/Linux o cualquier plataforma que soporte Node.js .

Guía de uso

  1. Instala el paquete.
npm i ec-sri-invoice-signer
  1. Usa la función signInvoiceXml en tu código para firmar la factura:
import fs from 'fs';
import { signInvoiceXml } from 'ec-sri-invoice-signer';
/* Puedes user require() si usas módulos commonJS. */

/* El XML de la factura a firmarse. */
const invoiceXml = '<factura id="comprobante>...</factura>';

/* El contenido del archivo pkcs12 (.p12/.pfx extension) del firmante representado como Node Buffer o string base64.
En este caso es un Node Buffer. */
const p12FileData = fs.readFileSync('signature.p12');

/* Firma la factura. Si no se pasa la opción pkcs12Password, '' será usada como contraseña. */
const signedInvoice = signInvoiceXml(invoiceXml, p12FileData, { pkcs12Password: 'thePKCS12FilePassword' });

doSomethingWithTheSignedInvoice(signedInvoice);

Notas importantes sobre la estructura del XML

Este paquete no implementa la especificación de canonicalización http://www.w3.org/TR/2001/REC-xml-c14n-20010315 por completo. El XML es un lenguaje con muchas características sofisticadas que, probablemente, no tienen mucha cabida en una aplicación de facturación electrónica en el marco del SRI. Por tal razón, solo se implementa las partes del estándar requeridas para soportar XML con características relativamente comunes. Esto debería cubrir la mayoría de los casos de uso.

Estas son las características requeridas del XML que se pretende firmar (ninguna de las características no soportadas es requerida para el intercambio de datos con el SRI):

  • La factura a firmarse debe consistir del nodo factura con su respectivo id 'comprobante', su versión y sus etiquetas hijas describiendo el contenido de la factura (sin otros namespaces).
<?xml version="1.0" encoding="UTF-8"?>
<factura Id="comprobante" version="1.1.0">
 <infoTributaria>...</infoTributaria>
 <infoFactura>...</infoFactura>
 <detalles>...</detalles>
<factura>
  • La declaración del documento XML es opcional.
<?xml version="1.0" encoding="UTF-8"?><factura Id="comprobante" version="1.1.0">...</factura>

o

<factura Id="comprobante" version="1.1.0">...</factura>

son igual de válidos.

  • La factura debe estar en formato UTF-8.
  • No namespaces (xmlns).
<!-- En este ejemplo, el xmlns:ds="..." debe ser eliminado. Como contexto, ningún namespace es necesario
para la factura en sí. Este paquete se encarga de colocar los namespaces necesarios en la firma digital
 generada -->
<factura Id="comprobante" version="1.1.0" xmlns:ds="...">...</factura>
<!-- Esto es soportado -->
<factura Id="comprobante" version="1.1.0">...</factura>
  • No etiquetas de Document Type Definition (DOCTYPE).
<!-- Esto no es soportado -->
 <!DOCTYPE note
 [
 <!ELEMENT note (to,from,heading,body)>
 <!ELEMENT to (#PCDATA)>
 <!ELEMENT from (#PCDATA)>
 <!ELEMENT heading (#PCDATA)>
 <!ELEMENT body (#PCDATA)>
 ]>
<factura Id="comprobante" version="1.1.0">...<factura>
  • No atributos con prefijo xml (xml:<attr_name>).
<!-- Esto no es soportado -->
<factura Id="comprobante" version="1.1.0" xml:foo="123">...</factura>