sgf-gstin-validator
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -27,6 +27,6 @@ /* | ||
\**********************/ | ||
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { | ||
/***/ ((module, __webpack_exports__, __webpack_require__) => { | ||
"use strict"; | ||
eval("\n\nvar jwt = __webpack_require__(/*! jsonwebtoken */ \"?d57b\");\nvar certs = __webpack_require__(/*! ./certs */ \"./src/certs.js\");\n\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\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\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}\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}\n\nfunction getInfo(gstin) {\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\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\n gstin = gstin.toUpperCase();\n\n if (!isValidGSTNumber(gstin)) return 'Invalid GSTIN';\n\n var state = states.find(function(o) {\n return o.state_code === gstin.slice(0, 2);\n });\n var info_msg =\n 'The GSTIN ' +\n gstin +\n ' is entity #' +\n parseInt(gstin.slice(12, 13), 36) +\n ' belonging to ' +\n panTypes.find(function(o) {\n return o.code === gstin[5];\n }).pan_type +\n ' whose PAN is ' +\n gstin.slice(2, 12) +\n ' registered in ' +\n state.state_name +\n ' (' +\n state.state_shortcode +\n ')';\n return info_msg;\n}\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\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 } catch (err) {\n throw new Error('Signature Verification Failed!');\n }\n return decodedQR;\n}\n\nfunction validateSignedInvoice(signedInvoiceJWT, publickey) {\n var cert = getCert(publickey);\n try {\n var invoice = jwt.verify(signedInvoiceJWT, cert, {issuer: 'NIC'});\n } catch (err) {\n throw new Error('Signature Verification Failed!');\n }\n return invoice;\n\n}\n\nmodule.exports = {\n isValidGSTNumber: isValidGSTNumber ,\n\n ValidateGSTIN: function(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 } else {\n if (gstin.toUpperCase()[14] !== calcCheckSum(gstin.toUpperCase())) {\n return 'Invalid checksum character in GSTIN';\n } else return 'Valid GSTIN';\n }\n },\n\n validateEInvoiceSignedQR: validateEInvoiceSignedQR,\n\n validateSignedInvoice: validateSignedInvoice,\n\n getGSTINInfo: getInfo,\n};\n\n\n//# sourceURL=webpack://sgf-gstin-validator/./src/index.js?"); | ||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"isValidGSTNumber\": () => (/* binding */ isValidGSTNumber)\n/* harmony export */ });\n/* module decorator */ module = __webpack_require__.hmd(module);\n\n\nvar jwt = __webpack_require__(/*! jsonwebtoken */ \"?d57b\");\nvar certs = __webpack_require__(/*! ./certs */ \"./src/certs.js\");\n\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\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\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}\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}\n\nfunction getInfo(gstin) {\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\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\n gstin = gstin.toUpperCase();\n\n if (!isValidGSTNumber(gstin)) return 'Invalid GSTIN';\n\n var state = states.find(function(o) {\n return o.state_code === gstin.slice(0, 2);\n });\n var info_msg =\n 'The GSTIN ' +\n gstin +\n ' is entity #' +\n parseInt(gstin.slice(12, 13), 36) +\n ' belonging to ' +\n panTypes.find(function(o) {\n return o.code === gstin[5];\n }).pan_type +\n ' whose PAN is ' +\n gstin.slice(2, 12) +\n ' registered in ' +\n state.state_name +\n ' (' +\n state.state_shortcode +\n ')';\n return info_msg;\n}\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\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 } catch (err) {\n throw new Error('Signature Verification Failed!');\n }\n return decodedQR;\n}\n\nfunction validateSignedInvoice(signedInvoiceJWT, publickey) {\n var cert = getCert(publickey);\n try {\n var invoice = jwt.verify(signedInvoiceJWT, cert, {issuer: 'NIC'});\n } catch (err) {\n throw new Error('Signature Verification Failed!');\n }\n return invoice;\n\n}\n\nmodule.exports = {\n isValidGSTNumber: isValidGSTNumber ,\n\n ValidateGSTIN: function(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 } else {\n if (gstin.toUpperCase()[14] !== calcCheckSum(gstin.toUpperCase())) {\n return 'Invalid checksum character in GSTIN';\n } else return 'Valid GSTIN';\n }\n },\n\n validateEInvoiceSignedQR: validateEInvoiceSignedQR,\n\n validateSignedInvoice: validateSignedInvoice,\n\n getGSTINInfo: getInfo,\n};\n\n\n//# sourceURL=webpack://sgf-gstin-validator/./src/index.js?"); | ||
@@ -59,4 +59,4 @@ /***/ }), | ||
/******/ var module = __webpack_module_cache__[moduleId] = { | ||
/******/ // no module.id needed | ||
/******/ // no module.loaded needed | ||
/******/ id: moduleId, | ||
/******/ loaded: false, | ||
/******/ exports: {} | ||
@@ -68,2 +68,5 @@ /******/ }; | ||
/******/ | ||
/******/ // Flag the module as loaded | ||
/******/ module.loaded = true; | ||
/******/ | ||
/******/ // Return the exports of the module | ||
@@ -74,3 +77,47 @@ /******/ return module.exports; | ||
/************************************************************************/ | ||
/******/ /* webpack/runtime/define property getters */ | ||
/******/ (() => { | ||
/******/ // define getter functions for harmony exports | ||
/******/ __webpack_require__.d = (exports, definition) => { | ||
/******/ for(var key in definition) { | ||
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | ||
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | ||
/******/ } | ||
/******/ } | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/harmony module decorator */ | ||
/******/ (() => { | ||
/******/ __webpack_require__.hmd = (module) => { | ||
/******/ module = Object.create(module); | ||
/******/ if (!module.children) module.children = []; | ||
/******/ Object.defineProperty(module, 'exports', { | ||
/******/ enumerable: true, | ||
/******/ set: () => { | ||
/******/ throw new Error('ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: ' + module.id); | ||
/******/ } | ||
/******/ }); | ||
/******/ return module; | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/hasOwnProperty shorthand */ | ||
/******/ (() => { | ||
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/make namespace object */ | ||
/******/ (() => { | ||
/******/ // define __esModule on exports | ||
/******/ __webpack_require__.r = (exports) => { | ||
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { | ||
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); | ||
/******/ } | ||
/******/ Object.defineProperty(exports, '__esModule', { value: true }); | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/************************************************************************/ | ||
/******/ | ||
/******/ // startup | ||
@@ -77,0 +124,0 @@ /******/ // Load entry module and return exports |
{ | ||
"name": "sgf-gstin-validator", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Module to validate GSTIN and verify Signed QR of GST eInvoice", | ||
@@ -5,0 +5,0 @@ "main": "dist/gstin-validator.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17497
145