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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ltorresu82/firmagob-client

v0.1.3

Published

Cliente TypeScript para integrar FirmaGob Chile con firma por hash y PDFs firmados externamente

Readme

@ltorresu82/firmagob-client

CI npm version

Cliente TypeScript para integrar FirmaGob Chile sin depender de librerias PDF deprecadas.

Estado inicial:

  • cliente HTTP/JWT para FirmaGob v2;
  • soporte para firma por hash;
  • utilidades para preparar e inyectar una firma PKCS#7 externa en PDFs;
  • sin dependencias runtime.

Este paquete no es un SDK oficial de Gobierno Digital.

Fuentes oficiales

El diseño del cliente se guia por la documentacion y ejemplos publicados por Gobierno Digital:

Cuando exista diferencia entre este paquete y una fuente oficial vigente, debe prevalecer la fuente oficial.

Instalacion

npm install @ltorresu82/firmagob-client

Firma de hashes

import { FirmaGobClient, Purpose } from "@ltorresu82/firmagob-client";

const client = new FirmaGobClient({
  apiTokenKey: process.env.FIRMAGOB_API_TOKEN_KEY!,
  secret: process.env.FIRMAGOB_SECRET!,
  entity: process.env.FIRMAGOB_ENTITY!,
  run: process.env.FIRMAGOB_RUN!,
  purpose: Purpose.Unattended,
  environment: "test",
});

const response = await client.signHashes([
  { content: "sha256-base64-del-pdf-preparado", contentType: "application/pdf" },
]);

El JWT incluye los claims entity, run, purpose, expiration e iat. Por defecto el token expira en 5 minutos, alineado con los ejemplos oficiales. expiration se serializa como yyyy-MM-dd'T'HH:mm:ss en zona horaria America/Santiago, porque FirmaGob interpreta ese valor como fecha local sin zona. Se puede ajustar con tokenTtlSeconds y tokenTimeZone si el ambiente lo requiere.

PDF con firma externa

import {
  embedExternalSignature,
  preparePdfForExternalSignature,
  sha256Base64,
} from "@ltorresu82/firmagob-client";

const prepared = preparePdfForExternalSignature(pdfWithPlaceholder);
const hash = sha256Base64(prepared.bytesToHash);

// Enviar hash a FirmaGob y recibir PKCS#7 base64.
const signedPdf = embedExternalSignature({
  preparedPdf: prepared.bytesToHash,
  pkcs7Signature: firmaGobPkcs7Base64,
  placeholderLength: prepared.placeholderLength,
  signatureOffset: prepared.signatureOffset,
});

Validacion sandbox

El repositorio incluye un ejemplo de firma por hash basado en el flujo oficial. Por seguridad, no trae credenciales embebidas; las lee desde variables de entorno.

Variables requeridas:

  • FIRMAGOB_ENTITY
  • FIRMAGOB_API_TOKEN_KEY
  • FIRMAGOB_RUN
  • FIRMAGOB_PURPOSE
  • FIRMAGOB_SECRET
  • FIRMAGOB_ENDPOINT_API

Validacion local sin llamada a FirmaGob:

npm run validate:sandbox:dry-run

Validacion real contra sandbox:

npm run validate:sandbox

El ejemplo escribe evidencia temporal en tmp/sandbox-hash/.

Para solicitar credenciales a la institucion o al equipo FirmaGob, ver docs/credentials.md.

Ejemplos de integracion

Ejemplos completos con CLI Node.js, API Hono y app Angular:

https://github.com/ltorresu82/firmagob-client-examples

Desarrollo

npm install
npm test
npm pack --dry-run