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

signed-invoice

v0.2.0

Published

Create cryptographically signed invoices with a QRCode

Downloads

49

Readme

Digitally signed invoice generator

What is it and how does it work?

This library allows you to generate invoices digitally signed by a QR Code.
This digital signature stamp contains general invoice information (issuer, recipient, invoice reference, due date, invoice date, number of items, number of lines, net amount payable, payment currency and status).
The QR Code contains a JWT token automatically generated from the data provided. The information is signed using the private cryptographic key of the issuer of the invoice, so the invoice cannot be falsified by a third party.

Example invoice

Here is an example of the content of the JWT token payload:

{
  "iss": "My company (SIREN 000 000 000)",
  "sub": "John Doe",
  "iat": 1660947313,
  "dueDate": 1661033713,
  "amt": 181.5,
  "curr": "EUR",
  "qty": 41,
  "line": 7,
  "ref": "MG202200000",
  "pay": "CASH"
}

Key signing ceremony

⚠️ Warning: this operation should be performed, if possible, on a newly installed computer disconnected from the internet, with openssl installed.

To generate the private key used to sign the QR code's data, execute the following command:

openssl ecparam -name prime256v1 -genkey -out privatekey.pem

Now to generate the key allowing anyone to verify the authenticity of the QR code's data, execute this command:

openssl ec -in privatekey.pem -pubout -out publickey.pem

Keep these keys on a safe backup medium.

How to check invoices?

The mobile application Invoice Verif allows you to verify invoices.
It is available for Android platforms.

Integrate this library into your application

Save your private key in an environment variable and share the public key to the people who will need to authenticate your generated documents.

const { Invoice } = require('signed-invoice')
const fs = require('fs')
const dotenv = require('dotenv')

dotenv()

const privateKey = process.env.PRIVATE_KEY ?? ''

const invoice = new Invoice({
  logoPath: 'logo.png',
  seller: {
    name: "My company",
    identifier: 'SIREN 000 000 000',
    contact: '[email protected]',
    address: {street: '4 RUE DES FLEURS', city: 'PARIS', zip: '75000'}
  },
  client: {name: 'John Doe'},
  reference: 'MG202200000',
  date: new Date(),
  dueDate: new Date(new Date().getTime() + 24 * 60 * 60 * 1e3),
  lines: [
    {
      item: 'Coffee',
      quantity: 24,
      unitPrice: 2,
      tax: 0.1,
      description: 'One coffee per hour'
    },
    {
      item: 'Pizza',
      quantity: 2,
      unitPrice: 7,
      tax: 0.1,
      description: 'Margherita'
    },
    {
      item: 'Soda',
      quantity: 3,
      unitPrice: 2,
      tax: 0.1
    },
    {
      item: 'Hot-dog',
      quantity: 1,
      unitPrice: 5,
      tax: 0.1
    },
    {
      item: 'Salad',
      quantity: 1,
      unitPrice: 8,
      tax: 0.1,
      description: 'Caesar'
    },
    {
      item: 'Pasta',
      quantity: 4,
      unitPrice: 6,
      tax: 0.1,
      description: 'A plate of bolognese pasta'
    },
    {
      item: 'Quiche Lorraine',
      quantity: 6,
      unitPrice: 10,
      tax: 0.1,
      description: 'Cream, eggs, and bacon'
    }
  ],
  terms: 'We hope you had a good time and would be happy to welcome you again',
  currency: 'EUR',
  language: 'en', // 'en' | 'fr' | 'de'
  payment: 'CASH' // 'CASH' | 'CARD' | 'BANK' | 'CHQ' | 'CRYPTO' | string | boolean
}, privateKey)

invoice.generatePDF().then(doc => doc.pipe(fs.createWriteStream('invoice.pdf')))

The invoice can be generated in different languages.