Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sgf-gstin-validator

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sgf-gstin-validator - npm Package Compare versions

Comparing version 1.0.8 to 2.0.0

2

dist/gstin-validator.js

@@ -40,3 +40,3 @@ /*

"use strict";
eval("\nvar jwt = __webpack_require__(/*! jsonwebtoken */ \"?44a0\");\nvar certs = __webpack_require__(/*! ./certs.js */ \"./dist/certs.js\");\nfunction calcCheckSum(gstin) {\n var GSTN_CODEPOINT_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';\n var factor = 2;\n var sum = 0;\n var checkCodePoint = 0;\n var mod = GSTN_CODEPOINT_CHARS.length;\n var i;\n for (i = gstin.length - 2; i >= 0; i--) {\n var codePoint = -1;\n for (var j = 0; j < GSTN_CODEPOINT_CHARS.length; j++) {\n if (GSTN_CODEPOINT_CHARS[j] === gstin[i]) {\n codePoint = j;\n }\n }\n var digit = factor * codePoint;\n factor = factor === 2 ? 1 : 2;\n digit = Math.floor(digit / mod) + (digit % mod);\n sum += digit;\n }\n checkCodePoint = (mod - (sum % mod)) % mod;\n return GSTN_CODEPOINT_CHARS[checkCodePoint];\n}\n// GSTIN Regex validation result\nfunction validatePattern(gstin) {\n // eslint-disable-next-line max-len\n var gstinRegexPattern = /^([0-2][0-9]|[3][0-8])[A-Z]{3}[ABCFGHLJPTK][A-Z]\\d{4}[A-Z][A-Z0-9][Z][A-Z0-9]$/;\n return gstinRegexPattern.test(gstin);\n}\nfunction isValidGSTNumber(gstin) {\n gstin = gstin.toUpperCase();\n if (gstin.length !== 15) {\n return false;\n }\n if (validatePattern(gstin)) {\n return gstin[14] === calcCheckSum(gstin.toUpperCase());\n }\n return false;\n}\nfunction getGSTINInfo(gstin) {\n var _a;\n var states = [\n {\n state_name: 'Andaman and Nicobar Islands',\n state_code: '35',\n state_shortcode: 'AN',\n },\n { state_name: 'Andhra Pradesh', state_code: '28', state_shortcode: 'AP' },\n {\n state_name: 'Andhra Pradesh (New)',\n state_code: '37',\n state_shortcode: 'AD',\n },\n {\n state_name: 'Arunachal Pradesh',\n state_code: '12',\n state_shortcode: 'AR',\n },\n { state_name: 'Assam', state_code: '18', state_shortcode: 'AS' },\n { state_name: 'Bihar', state_code: '10', state_shortcode: 'BH' },\n { state_name: 'Chandigarh', state_code: '04', state_shortcode: 'CH' },\n { state_name: 'Chattisgarh', state_code: '22', state_shortcode: 'CT' },\n {\n state_name: 'Dadra and Nagar Haveli',\n state_code: '26',\n state_shortcode: 'DN',\n },\n { state_name: 'Daman and Diu', state_code: '25', state_shortcode: 'DD' },\n { state_name: 'Delhi', state_code: '07', state_shortcode: 'DL' },\n { state_name: 'Goa', state_code: '30', state_shortcode: 'GA' },\n { state_name: 'Gujarat', state_code: '24', state_shortcode: 'GJ' },\n { state_name: 'Haryana', state_code: '06', state_shortcode: 'HR' },\n { state_name: 'Himachal Pradesh', state_code: '02', state_shortcode: 'HP' },\n {\n state_name: 'Jammu and Kashmir',\n state_code: '01',\n state_shortcode: 'JK',\n },\n { state_name: 'Jharkhand', state_code: '20', state_shortcode: 'JH' },\n { state_name: 'Karnataka', state_code: '29', state_shortcode: 'KA' },\n { state_name: 'Kerala', state_code: '32', state_shortcode: 'KL' },\n { state_name: 'Ladakh', state_code: '38', state_shortcode: 'LA' },\n {\n state_name: 'Lakshadweep Islands',\n state_code: '31',\n state_shortcode: 'LD',\n },\n { state_name: 'Madhya Pradesh', state_code: '23', state_shortcode: 'MP' },\n { state_name: 'Maharashtra', state_code: '27', state_shortcode: 'MH' },\n { state_name: 'Manipur', state_code: '14', state_shortcode: 'MN' },\n { state_name: 'Meghalaya', state_code: '17', state_shortcode: 'ME' },\n { state_name: 'Mizoram', state_code: '15', state_shortcode: 'MI' },\n { state_name: 'Nagaland', state_code: '13', state_shortcode: 'NL' },\n { state_name: 'Odisha', state_code: '21', state_shortcode: 'OR' },\n { state_name: 'Pondicherry', state_code: '34', state_shortcode: 'PY' },\n { state_name: 'Punjab', state_code: '03', state_shortcode: 'PB' },\n { state_name: 'Rajasthan', state_code: '08', state_shortcode: 'RJ' },\n { state_name: 'Sikkim', state_code: '11', state_shortcode: 'SK' },\n { state_name: 'Tamil Nadu', state_code: '33', state_shortcode: 'TN' },\n { state_name: 'Telangana', state_code: '36', state_shortcode: 'TS' },\n { state_name: 'Tripura', state_code: '16', state_shortcode: 'TR' },\n { state_name: 'Uttar Pradesh', state_code: '09', state_shortcode: 'UP' },\n { state_name: 'Uttarakhand', state_code: '05', state_shortcode: 'UT' },\n { state_name: 'West Bengal', state_code: '19', state_shortcode: 'WB' },\n ];\n var panTypes = [\n { code: 'C', pan_type: 'Company' },\n { code: 'P', pan_type: 'Person' },\n { code: 'H', pan_type: 'HUF (Hindu Undivided Family)' },\n { code: 'F', pan_type: 'Firm' },\n { code: 'A', pan_type: 'Association of Persons (AOP)' },\n { code: 'T', pan_type: 'AOP (Trust)' },\n { code: 'B', pan_type: 'Body of Individuals (BOI)' },\n { code: 'L', pan_type: 'Local Authority' },\n { code: 'J', pan_type: 'Artificial Juridical Person ' },\n { code: 'G', pan_type: 'Government' },\n ];\n gstin = gstin.toUpperCase();\n if (!isValidGSTNumber(gstin))\n return 'Invalid GSTIN';\n var state = states.find(function (o) {\n return o.state_code === gstin.slice(0, 2);\n });\n var info_msg = 'The GSTIN ' +\n gstin +\n ' is entity #' +\n parseInt(gstin.slice(12, 13), 36) +\n ' belonging to ' +\n ((_a = panTypes === null || panTypes === void 0 ? void 0 : panTypes.find(function (o) {\n return o.code === gstin[5];\n })) === null || _a === void 0 ? void 0 : _a.pan_type) +\n ' whose PAN is ' +\n gstin.slice(2, 12) +\n ' registered in ' +\n (state === null || state === void 0 ? void 0 : state.state_name) +\n ' (' +\n (state === null || state === void 0 ? void 0 : state.state_shortcode) +\n ')';\n return info_msg;\n}\nfunction getCert(certname) {\n if (certname === undefined) {\n certname = 'einv_prod';\n }\n if (certname.endsWith('.pem')) {\n certname = certname.replace('.pem', '');\n }\n // get public key\n var buf = Buffer.from(certs[certname], 'base64');\n return buf.toString();\n}\n// This function is to validate a eInvoice QR\nfunction validateEInvoiceSignedQR(qrText, publickey) {\n var cert = getCert(publickey);\n try {\n var decodedQR = jwt.verify(qrText, cert, { issuer: 'NIC' });\n }\n catch (err) {\n throw new Error('Signature Verification Failed!');\n }\n return decodedQR;\n}\nfunction validateSignedInvoice(signedInvoiceJWT, publickey) {\n var cert = getCert(publickey);\n try {\n var invoice = jwt.verify(signedInvoiceJWT, cert, { issuer: 'NIC' });\n }\n catch (err) {\n throw new Error('Signature Verification Failed!');\n }\n return invoice;\n}\nfunction ValidateGSTIN(gstin) {\n gstin = gstin.toUpperCase();\n if (gstin.length !== 15) {\n return 'Enter a valid 15 character GSTIN';\n }\n if (!validatePattern(gstin)) {\n return 'Invalid GSTIN format';\n }\n else {\n if (gstin.toUpperCase()[14] !== calcCheckSum(gstin.toUpperCase())) {\n return 'Invalid checksum character in GSTIN';\n }\n else\n return 'Valid GSTIN';\n }\n}\nmodule.exports = {\n isValidGSTNumber: isValidGSTNumber,\n ValidateGSTIN: ValidateGSTIN,\n validateEInvoiceSignedQR: validateEInvoiceSignedQR,\n validateSignedInvoice: validateSignedInvoice,\n getGSTINInfo: getGSTINInfo,\n};\n//# sourceMappingURL=index.js.map\n\n//# sourceURL=webpack://sgf-gstin-validator/./dist/index.js?");
eval("\nvar jwt = __webpack_require__(/*! jsonwebtoken */ \"?44a0\");\nvar certs = __webpack_require__(/*! ./certs.js */ \"./dist/certs.js\");\nfunction calcCheckSum(gstin) {\n var GSTN_CODEPOINT_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';\n var factor = 2;\n var sum = 0;\n var checkCodePoint = 0;\n var mod = GSTN_CODEPOINT_CHARS.length;\n var i;\n for (i = gstin.length - 2; i >= 0; i--) {\n var codePoint = -1;\n for (var j = 0; j < GSTN_CODEPOINT_CHARS.length; j++) {\n if (GSTN_CODEPOINT_CHARS[j] === gstin[i]) {\n codePoint = j;\n }\n }\n var digit = factor * codePoint;\n factor = factor === 2 ? 1 : 2;\n digit = Math.floor(digit / mod) + (digit % mod);\n sum += digit;\n }\n checkCodePoint = (mod - (sum % mod)) % mod;\n return GSTN_CODEPOINT_CHARS[checkCodePoint];\n}\n// GSTIN Regex validation result\nfunction validatePattern(gstin) {\n // eslint-disable-next-line max-len\n var gstinRegexPattern = /^([0-2][0-9]|[3][0-8])[A-Z]{3}[ABCFGHLJPTK][A-Z]\\d{4}[A-Z][A-Z0-9][Z][A-Z0-9]$/;\n return gstinRegexPattern.test(gstin);\n}\nfunction isValidGSTNumber(gstin) {\n gstin = gstin.toUpperCase();\n if (gstin.length !== 15) {\n return false;\n }\n if (validatePattern(gstin)) {\n return gstin[14] === calcCheckSum(gstin.toUpperCase());\n }\n return false;\n}\nfunction getGSTINInfo(gstin) {\n var _a;\n var states = [\n {\n state_name: 'Andaman and Nicobar Islands',\n state_code: '35',\n state_shortcode: 'AN',\n },\n { state_name: 'Andhra Pradesh', state_code: '28', state_shortcode: 'AP' },\n {\n state_name: 'Andhra Pradesh (New)',\n state_code: '37',\n state_shortcode: 'AD',\n },\n {\n state_name: 'Arunachal Pradesh',\n state_code: '12',\n state_shortcode: 'AR',\n },\n { state_name: 'Assam', state_code: '18', state_shortcode: 'AS' },\n { state_name: 'Bihar', state_code: '10', state_shortcode: 'BH' },\n { state_name: 'Chandigarh', state_code: '04', state_shortcode: 'CH' },\n { state_name: 'Chattisgarh', state_code: '22', state_shortcode: 'CT' },\n {\n state_name: 'Dadra and Nagar Haveli',\n state_code: '26',\n state_shortcode: 'DN',\n },\n { state_name: 'Daman and Diu', state_code: '25', state_shortcode: 'DD' },\n { state_name: 'Delhi', state_code: '07', state_shortcode: 'DL' },\n { state_name: 'Goa', state_code: '30', state_shortcode: 'GA' },\n { state_name: 'Gujarat', state_code: '24', state_shortcode: 'GJ' },\n { state_name: 'Haryana', state_code: '06', state_shortcode: 'HR' },\n { state_name: 'Himachal Pradesh', state_code: '02', state_shortcode: 'HP' },\n {\n state_name: 'Jammu and Kashmir',\n state_code: '01',\n state_shortcode: 'JK',\n },\n { state_name: 'Jharkhand', state_code: '20', state_shortcode: 'JH' },\n { state_name: 'Karnataka', state_code: '29', state_shortcode: 'KA' },\n { state_name: 'Kerala', state_code: '32', state_shortcode: 'KL' },\n { state_name: 'Ladakh', state_code: '38', state_shortcode: 'LA' },\n {\n state_name: 'Lakshadweep Islands',\n state_code: '31',\n state_shortcode: 'LD',\n },\n { state_name: 'Madhya Pradesh', state_code: '23', state_shortcode: 'MP' },\n { state_name: 'Maharashtra', state_code: '27', state_shortcode: 'MH' },\n { state_name: 'Manipur', state_code: '14', state_shortcode: 'MN' },\n { state_name: 'Meghalaya', state_code: '17', state_shortcode: 'ME' },\n { state_name: 'Mizoram', state_code: '15', state_shortcode: 'MI' },\n { state_name: 'Nagaland', state_code: '13', state_shortcode: 'NL' },\n { state_name: 'Odisha', state_code: '21', state_shortcode: 'OR' },\n { state_name: 'Pondicherry', state_code: '34', state_shortcode: 'PY' },\n { state_name: 'Punjab', state_code: '03', state_shortcode: 'PB' },\n { state_name: 'Rajasthan', state_code: '08', state_shortcode: 'RJ' },\n { state_name: 'Sikkim', state_code: '11', state_shortcode: 'SK' },\n { state_name: 'Tamil Nadu', state_code: '33', state_shortcode: 'TN' },\n { state_name: 'Telangana', state_code: '36', state_shortcode: 'TS' },\n { state_name: 'Tripura', state_code: '16', state_shortcode: 'TR' },\n { state_name: 'Uttar Pradesh', state_code: '09', state_shortcode: 'UP' },\n { state_name: 'Uttarakhand', state_code: '05', state_shortcode: 'UT' },\n { state_name: 'West Bengal', state_code: '19', state_shortcode: 'WB' },\n ];\n var panTypes = [\n { code: 'C', pan_type: 'Company' },\n { code: 'P', pan_type: 'Person' },\n { code: 'H', pan_type: 'HUF (Hindu Undivided Family)' },\n { code: 'F', pan_type: 'Firm' },\n { code: 'A', pan_type: 'Association of Persons (AOP)' },\n { code: 'T', pan_type: 'AOP (Trust)' },\n { code: 'B', pan_type: 'Body of Individuals (BOI)' },\n { code: 'L', pan_type: 'Local Authority' },\n { code: 'J', pan_type: 'Artificial Juridical Person ' },\n { code: 'G', pan_type: 'Government' },\n ];\n gstin = gstin.toUpperCase();\n if (!isValidGSTNumber(gstin))\n return 'Invalid GSTIN';\n var state = states.find(function (o) {\n return o.state_code === gstin.slice(0, 2);\n });\n var info_msg = 'The GSTIN ' +\n gstin +\n ' is entity #' +\n parseInt(gstin.slice(12, 13), 36) +\n ' belonging to ' +\n ((_a = panTypes.find(function (o) {\n return o.code === gstin[5];\n })) === null || _a === void 0 ? void 0 : _a.pan_type) +\n ' whose PAN is ' +\n gstin.slice(2, 12) +\n ' registered in ' +\n (state === null || state === void 0 ? void 0 : state.state_name) +\n ' (' +\n (state === null || state === void 0 ? void 0 : state.state_shortcode) +\n ')';\n return info_msg;\n}\nfunction getCert(certname) {\n if (certname === undefined) {\n certname = 'einv_prod';\n }\n if (certname.endsWith('.pem')) {\n certname = certname.replace('.pem', '');\n }\n // get public key\n var buf = Buffer.from(certs[certname], 'base64');\n return buf.toString();\n}\n// This function is to validate a eInvoice QR\nfunction validateEInvoiceSignedQR(qrText, publickey) {\n var cert = getCert(publickey);\n try {\n var decodedQR = jwt.verify(qrText, cert, { issuer: 'NIC' });\n }\n catch (err) {\n throw new Error('Signature Verification Failed!');\n }\n return decodedQR;\n}\nfunction validateSignedInvoice(signedInvoiceJWT, publickey) {\n var cert = getCert(publickey);\n try {\n var invoice = jwt.verify(signedInvoiceJWT, cert, { issuer: 'NIC' });\n }\n catch (err) {\n throw new Error('Signature Verification Failed!');\n }\n return invoice;\n}\nfunction ValidateGSTIN(gstin) {\n gstin = gstin.toUpperCase();\n if (gstin.length !== 15) {\n return 'Enter a valid 15 character GSTIN';\n }\n if (!validatePattern(gstin)) {\n return 'Invalid GSTIN format';\n }\n else {\n if (gstin.toUpperCase()[14] !== calcCheckSum(gstin.toUpperCase())) {\n return 'Invalid checksum character in GSTIN';\n }\n else\n return 'Valid GSTIN';\n }\n}\nmodule.exports = {\n isValidGSTNumber: isValidGSTNumber,\n ValidateGSTIN: ValidateGSTIN,\n validateEInvoiceSignedQR: validateEInvoiceSignedQR,\n validateSignedInvoice: validateSignedInvoice,\n getGSTINInfo: getGSTINInfo,\n};\n//# sourceMappingURL=index.js.map\n\n//# sourceURL=webpack://sgf-gstin-validator/./dist/index.js?");

@@ -43,0 +43,0 @@ /***/ })

@@ -131,3 +131,3 @@ 'use strict';

' belonging to ' +
((_a = panTypes === null || panTypes === void 0 ? void 0 : panTypes.find(function (o) {
((_a = panTypes.find(function (o) {
return o.code === gstin[5];

@@ -134,0 +134,0 @@ })) === null || _a === void 0 ? void 0 : _a.pan_type) +

{
"name": "sgf-gstin-validator",
"version": "1.0.8",
"version": "2.0.0",
"description": "Module to validate GSTIN and verify Signed QR of GST eInvoice",

@@ -8,5 +8,5 @@ "main": "dist/index.js",

"scripts": {
"test": "mocha src/index.test.js",
"test": "jest",
"test-coverage": "nyc mocha src/index.test.js",
"build": "rm -rf ./dist &&tsc && npx webpack --config webpack.config.cjs",
"build": "rm -rf ./dist && tsc && npx webpack --config webpack.config.cjs",
"build-web": "npx webpack --config webpack.config.cjs",

@@ -36,9 +36,17 @@ "dist": "uglifyjs dist/gstin-validator.js -o dist/gstin-validator.min.js",

"devDependencies": {
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.3",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-transform-modules-commonjs": "^7.17.9",
"@babel/preset-typescript": "^7.18.6",
"@types/jest": "^27.5.1",
"chai": "^4.3.4",
"eslint": "^7.32.0",
"eslint-config-strongloop": "^2.1.0",
"jest": "^29.1.2",
"jest-html-reporters": "^3.0.11",
"mocha": "^9.2.2",
"nyc": "^15.1.0",
"ts-loader": "^9.4.1",
"ts-node": "^10.9.1",
"typescript": "^4.8.4",

@@ -50,4 +58,5 @@ "uglify-js": "^3.14.1",

"dependencies": {
"jsonwebtoken": "^8.5.1"
"jsonwebtoken": "^8.5.1",
"ts-jest": "^29.0.3"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc