@zenuinebit/einvoice-irn
v0.1.0
Published
E-invoice (IRP) JSON builder and IRN hash for GST invoices. SHA-256 included, no dependencies.
Readme
@zenuinebit/einvoice-irn
Builds the e-invoice JSON (IRP "INV-01" layout) for a GST invoice and computes its IRN. Includes a small SHA-256, so it runs in Node and the browser with no extra dependency. Builds on @zenuinebit/gst-report, @zenuinebit/address-india and @zenuinebit/invoice-number.
Check before you rely on it. Field names, codes and limits follow the e-invoice schema as commonly documented. The schema, the IRN rule and who must use e-invoicing change over time. Validate the JSON with the official tools or the IRP sandbox first. Only B2B supplies are built.
import { buildEinvoice, toEinvoiceJson, irnFor, computeIrn, cancelPayload } from "@zenuinebit/einvoice-irn";
const input = {
invoice: { // the same SaleInvoice used by gst-report (tax-exclusive prices)
number: "INV/2025-26/0042",
date: "2025-04-10",
placeOfSupply: "Karnataka",
buyer: { gstin: "29ABCPD1234E1ZA", name: "Bengaluru Traders" },
lines: [{ description: "Tea 250g", hsn: "0902", quantity: 10, unitPrice: 10_000, taxRate: 5 }],
},
seller: { gstin: "27AAPFU0939F1ZV", name: "ZenuineBit Foods Pvt Ltd", address1: "1 Main Rd", place: "Pune", pincode: "411001" },
buyer: { gstin: "29ABCPD1234E1ZA", name: "Bengaluru Traders", address1: "5 MG Rd", place: "Bengaluru", pincode: "560001" },
unitByHsn: { "0902": "KGS" },
};
const json = buildEinvoice(input); // plain object: TranDtls, DocDtls, SellerDtls, BuyerDtls, ItemList, ValDtls
await fs.writeFile("einv.json", toEinvoiceJson(input));
irnFor(input); // 64-hex IRN of this invoice
computeIrn(sellerGstin, "INV", "INV/2025-26/0042", "2025-04-10");
cancelPayload(irn, "data-entry-mistake", "Wrong buyer"); // { Irn, CnlRsn: "2", CnlRem }How it works
- IRN = SHA-256 of supplier GSTIN + financial year (
2025-26) + document type (INV,CRN,DBN) + document number, as 64 lowercase hex characters. The portal computes it again when you register, so this lets you show or check it up front. It is tested againstnode:crypto. - Amounts are in rupees, the date is
dd/MM/yyyy, tax is CGST+SGST within a state and IGST between states (same maths asgst-report). An HSN starting with99is treated as a service. - Credit notes keep positive amounts and use document type
CRN. - Throws a clear message for a bad GSTIN, PIN, HSN or SAC (4 to 8 digits), a document number the portal would refuse (1-16 characters, letters, digits,
/and-, not starting with 0), tax-inclusive prices, or a missing buyer GSTIN.
Not included: calling the IRP (authentication, registration, QR code and signed invoice), B2C, exports and SEZ, dispatch and ship-to details, payment and reference details, cess, round-off, and the rules about who must issue e-invoices and by when.
