@ripwords/myinvois-client 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +4 -5
  3. package/src/index.ts +2 -1
  4. package/src/types/documents.d.ts +5 -6
  5. package/bun.lock +0 -460
  6. package/dist/0X-CTIq3y3a.d.ts +0 -210
  7. package/dist/0X-Cr3M7hci.d.cts +0 -211
  8. package/dist/1X-Bu4oiv8D.d.ts +0 -111
  9. package/dist/1X-BywXCqtn.d.ts +0 -19
  10. package/dist/1X-CWwmfCzo.d.cts +0 -112
  11. package/dist/1X-ClnJ79HH.d.cts +0 -20
  12. package/dist/2X-3fSEGIuE.d.ts +0 -39
  13. package/dist/2X-CV9eYhog.d.cts +0 -40
  14. package/dist/2X-DNtkJ0tj.d.cts +0 -140
  15. package/dist/2X-DnG3FY1f.d.ts +0 -139
  16. package/dist/3X--VWVsC84.d.cts +0 -21
  17. package/dist/3X-BOxfatu3.d.cts +0 -62
  18. package/dist/3X-CLdmoel1.d.ts +0 -61
  19. package/dist/3X-Ynjfgoll.d.ts +0 -20
  20. package/dist/4X-B5ePdMky.d.ts +0 -30
  21. package/dist/4X-BTG6o1Gn.d.ts +0 -264
  22. package/dist/4X-By9PzHaY.d.cts +0 -31
  23. package/dist/4X-C7fzDWJ_.d.cts +0 -265
  24. package/dist/5X-B5M0Cv_K.d.cts +0 -22
  25. package/dist/5X-CNAFsDm2.d.cts +0 -77
  26. package/dist/5X-CjSz1zxJ.d.ts +0 -76
  27. package/dist/5X-dhP6fyou.d.ts +0 -21
  28. package/dist/6X-B9KP_vEn.d.ts +0 -104
  29. package/dist/6X-BHaY0TCf.d.ts +0 -15
  30. package/dist/6X-C3elgd-n.d.cts +0 -16
  31. package/dist/6X-uObUP4VG.d.cts +0 -105
  32. package/dist/7X-BifJnY24.d.cts +0 -71
  33. package/dist/7X-C4eX_tAk.d.ts +0 -15
  34. package/dist/7X-D3idQBl9.d.cts +0 -16
  35. package/dist/7X-DtkQutx2.d.ts +0 -70
  36. package/dist/8X-5n9seY3z.d.ts +0 -109
  37. package/dist/8X-C6UMFvQW.d.cts +0 -19
  38. package/dist/8X-D6HTLShY.d.ts +0 -18
  39. package/dist/8X-DioBXCJ0.d.cts +0 -110
  40. package/dist/9X-BjffnXuq.d.cts +0 -98
  41. package/dist/9X-CHZKsIdD.d.ts +0 -14
  42. package/dist/9X-CJjPJgIG.d.cts +0 -15
  43. package/dist/9X-Cpb6V4JC.d.ts +0 -97
  44. package/dist/AX-C0w_r3PA.d.ts +0 -110
  45. package/dist/AX-DrEd2Ov6.d.cts +0 -111
  46. package/dist/BX-C5jc6myN.d.cts +0 -115
  47. package/dist/BX-RadlZ-6m.d.ts +0 -114
  48. package/dist/CX-CT1Zzb9D.d.ts +0 -127
  49. package/dist/CX-oSgvmn3h.d.cts +0 -128
  50. package/dist/DX-CtUeTKMM.d.ts +0 -114
  51. package/dist/DX-ZIG0enmK.d.cts +0 -115
  52. package/dist/EX-084Yu7Wt.d.ts +0 -106
  53. package/dist/EX-BpWZ5ADq.d.cts +0 -107
  54. package/dist/FX-BrbQM0CW.d.ts +0 -126
  55. package/dist/FX-CvYBEc51.d.cts +0 -127
  56. package/dist/GX-CU8PZy0G.d.cts +0 -136
  57. package/dist/GX-gKj8iAAh.d.ts +0 -135
  58. package/dist/HX-9D-ZXTy5.d.ts +0 -125
  59. package/dist/HX-DoEErDeE.d.cts +0 -126
  60. package/dist/IX-DR4Fc92A.d.ts +0 -22
  61. package/dist/IX-jLAUHe8i.d.cts +0 -23
  62. package/dist/JX-DIKa9ma-.d.ts +0 -103
  63. package/dist/JX-DX8BjYQC.d.cts +0 -104
  64. package/dist/KX-DpsJ_unT.d.ts +0 -150
  65. package/dist/KX-fZb4_vhw.d.cts +0 -151
  66. package/dist/LX-D_mI1bk-.d.cts +0 -123
  67. package/dist/LX-DeXPPWUX.d.ts +0 -122
  68. package/dist/MX-CKMjg_zK.d.ts +0 -152
  69. package/dist/MX-DlYZhpkT.d.cts +0 -153
  70. package/dist/NX-DELEEbad.d.cts +0 -122
  71. package/dist/NX-oYdb4NDo.d.ts +0 -121
  72. package/dist/OX-Bid9es3D.d.ts +0 -25
  73. package/dist/OX-CKPyrIFf.d.cts +0 -26
  74. package/dist/PX-D7jy9CFk.d.ts +0 -120
  75. package/dist/PX-SP6NxBtG.d.cts +0 -121
  76. package/dist/QX-BFWOR4g3.d.ts +0 -58
  77. package/dist/QX-QZA7E2O-.d.cts +0 -59
  78. package/dist/RX-DBcgbdeE.d.cts +0 -23
  79. package/dist/RX-XHgCyMV1.d.ts +0 -22
  80. package/dist/SX-Cl8RN8oH.d.ts +0 -39
  81. package/dist/SX-DmiJeCMN.d.cts +0 -40
  82. package/dist/TX-C1SoDobK.d.cts +0 -31
  83. package/dist/TX-ZymoIbtr.d.ts +0 -30
  84. package/dist/UX-D-Ndd1ov.d.ts +0 -17
  85. package/dist/UX-DFVynFhQ.d.cts +0 -18
  86. package/dist/VX-B-1b34r7.d.ts +0 -16
  87. package/dist/VX-DsRum5k3.d.cts +0 -17
  88. package/dist/WX-0GuMjPNZ.d.ts +0 -25
  89. package/dist/WX-VReU5R5M.d.cts +0 -26
  90. package/dist/XX-CF2NANsy.d.ts +0 -827
  91. package/dist/XX-ChAviUMj.d.cts +0 -828
  92. package/dist/YX-B51BbNSg.d.ts +0 -19
  93. package/dist/YX-QfzeMEKx.d.cts +0 -20
  94. package/dist/ZX-BMJS1iAv.d.ts +0 -21
  95. package/dist/ZX-Ca2E726a.d.cts +0 -22
  96. package/dist/api/platform/platformLogin.d.ts +0 -65
  97. package/dist/api/platform/platformLogin.js +0 -3
  98. package/dist/certificate-DFK-788s.cjs +0 -62
  99. package/dist/certificate-DFK-788s.cjs.map +0 -1
  100. package/dist/certificate-aooIRf9A.js +0 -49
  101. package/dist/chunk-CUT6urMc.cjs +0 -30
  102. package/dist/classification-codes-B15PbWxz.d.cts +0 -118
  103. package/dist/classification-codes-BKxV-rO9.d.ts +0 -117
  104. package/dist/country-code-CQuaiQm2.d.ts +0 -542
  105. package/dist/country-code-DPeNFMMi.d.cts +0 -543
  106. package/dist/currencies-BYJK-m6v.d.ts +0 -207
  107. package/dist/currencies-S5g1gzBU.d.cts +0 -208
  108. package/dist/document-CARHiGdp.cjs +0 -472
  109. package/dist/document-CARHiGdp.cjs.map +0 -1
  110. package/dist/document-D6VKMAtx.js +0 -405
  111. package/dist/documents-CJ8hqIGH.d.ts +0 -858
  112. package/dist/documents-MGs0EvXh.d.cts +0 -859
  113. package/dist/e-invoice-BuwtFnlI.d.cts +0 -44
  114. package/dist/e-invoice-CmbLQkHw.d.ts +0 -43
  115. package/dist/getBaseUrl-CO7Jp27d.cjs +0 -14
  116. package/dist/getBaseUrl-CO7Jp27d.cjs.map +0 -1
  117. package/dist/getBaseUrl-R3IdgCu3.js +0 -7
  118. package/dist/index-0-EvC6Nv.d.ts +0 -15
  119. package/dist/index-D2_HVwCz.d.cts +0 -16
  120. package/dist/index.cjs +0 -309
  121. package/dist/index.cjs.map +0 -1
  122. package/dist/index.d.ts +0 -233
  123. package/dist/index.js +0 -308
  124. package/dist/index10.cjs +0 -0
  125. package/dist/index11.cjs +0 -34
  126. package/dist/index11.cjs.map +0 -1
  127. package/dist/index12.cjs +0 -24
  128. package/dist/index12.cjs.map +0 -1
  129. package/dist/index13.cjs +0 -0
  130. package/dist/index14.cjs +0 -13
  131. package/dist/index14.cjs.map +0 -1
  132. package/dist/index15.cjs +0 -4
  133. package/dist/index16.cjs +0 -13
  134. package/dist/index17.cjs +0 -3
  135. package/dist/index18.cjs +0 -340
  136. package/dist/index18.cjs.map +0 -1
  137. package/dist/index19.cjs +0 -329
  138. package/dist/index19.cjs.map +0 -1
  139. package/dist/index2.cjs +0 -62
  140. package/dist/index2.cjs.map +0 -1
  141. package/dist/index20.cjs +0 -140
  142. package/dist/index20.cjs.map +0 -1
  143. package/dist/index21.cjs +0 -208
  144. package/dist/index21.cjs.map +0 -1
  145. package/dist/index22.cjs +0 -109
  146. package/dist/index22.cjs.map +0 -1
  147. package/dist/index23.cjs +0 -137
  148. package/dist/index23.cjs.map +0 -1
  149. package/dist/index24.cjs +0 -64
  150. package/dist/index24.cjs.map +0 -1
  151. package/dist/index25.cjs +0 -267
  152. package/dist/index25.cjs.map +0 -1
  153. package/dist/index26.cjs +0 -79
  154. package/dist/index26.cjs.map +0 -1
  155. package/dist/index27.cjs +0 -107
  156. package/dist/index27.cjs.map +0 -1
  157. package/dist/index28.cjs +0 -73
  158. package/dist/index28.cjs.map +0 -1
  159. package/dist/index29.cjs +0 -112
  160. package/dist/index29.cjs.map +0 -1
  161. package/dist/index3.cjs +0 -532
  162. package/dist/index3.cjs.map +0 -1
  163. package/dist/index30.cjs +0 -100
  164. package/dist/index30.cjs.map +0 -1
  165. package/dist/index31.cjs +0 -18
  166. package/dist/index31.cjs.map +0 -1
  167. package/dist/index32.cjs +0 -38
  168. package/dist/index32.cjs.map +0 -1
  169. package/dist/index33.cjs +0 -19
  170. package/dist/index33.cjs.map +0 -1
  171. package/dist/index34.cjs +0 -29
  172. package/dist/index34.cjs.map +0 -1
  173. package/dist/index35.cjs +0 -20
  174. package/dist/index35.cjs.map +0 -1
  175. package/dist/index36.cjs +0 -14
  176. package/dist/index36.cjs.map +0 -1
  177. package/dist/index37.cjs +0 -14
  178. package/dist/index37.cjs.map +0 -1
  179. package/dist/index38.cjs +0 -17
  180. package/dist/index38.cjs.map +0 -1
  181. package/dist/index39.cjs +0 -13
  182. package/dist/index39.cjs.map +0 -1
  183. package/dist/index4.cjs +0 -196
  184. package/dist/index4.cjs.map +0 -1
  185. package/dist/index40.cjs +0 -108
  186. package/dist/index40.cjs.map +0 -1
  187. package/dist/index41.cjs +0 -113
  188. package/dist/index41.cjs.map +0 -1
  189. package/dist/index42.cjs +0 -126
  190. package/dist/index42.cjs.map +0 -1
  191. package/dist/index43.cjs +0 -113
  192. package/dist/index43.cjs.map +0 -1
  193. package/dist/index44.cjs +0 -105
  194. package/dist/index44.cjs.map +0 -1
  195. package/dist/index45.cjs +0 -125
  196. package/dist/index45.cjs.map +0 -1
  197. package/dist/index46.cjs +0 -134
  198. package/dist/index46.cjs.map +0 -1
  199. package/dist/index47.cjs +0 -124
  200. package/dist/index47.cjs.map +0 -1
  201. package/dist/index48.cjs +0 -21
  202. package/dist/index48.cjs.map +0 -1
  203. package/dist/index49.cjs +0 -102
  204. package/dist/index49.cjs.map +0 -1
  205. package/dist/index5.cjs +0 -0
  206. package/dist/index50.cjs +0 -149
  207. package/dist/index50.cjs.map +0 -1
  208. package/dist/index51.cjs +0 -121
  209. package/dist/index51.cjs.map +0 -1
  210. package/dist/index52.cjs +0 -151
  211. package/dist/index52.cjs.map +0 -1
  212. package/dist/index53.cjs +0 -120
  213. package/dist/index53.cjs.map +0 -1
  214. package/dist/index54.cjs +0 -24
  215. package/dist/index54.cjs.map +0 -1
  216. package/dist/index55.cjs +0 -119
  217. package/dist/index55.cjs.map +0 -1
  218. package/dist/index56.cjs +0 -54
  219. package/dist/index56.cjs.map +0 -1
  220. package/dist/index57.cjs +0 -21
  221. package/dist/index57.cjs.map +0 -1
  222. package/dist/index58.cjs +0 -35
  223. package/dist/index58.cjs.map +0 -1
  224. package/dist/index58.cts.map +0 -1
  225. package/dist/index59.cjs +0 -29
  226. package/dist/index59.cjs.map +0 -1
  227. package/dist/index59.cts.map +0 -1
  228. package/dist/index6.cjs +0 -25
  229. package/dist/index6.cjs.map +0 -1
  230. package/dist/index60.cjs +0 -16
  231. package/dist/index60.cjs.map +0 -1
  232. package/dist/index60.cts.map +0 -1
  233. package/dist/index61.cjs +0 -15
  234. package/dist/index61.cjs.map +0 -1
  235. package/dist/index61.cts.map +0 -1
  236. package/dist/index62.cjs +0 -24
  237. package/dist/index62.cjs.map +0 -1
  238. package/dist/index62.cts.map +0 -1
  239. package/dist/index63.cjs +0 -419
  240. package/dist/index63.cjs.map +0 -1
  241. package/dist/index63.cts.map +0 -1
  242. package/dist/index64.cjs +0 -15
  243. package/dist/index64.cjs.map +0 -1
  244. package/dist/index64.cts.map +0 -1
  245. package/dist/index65.cjs +0 -16
  246. package/dist/index65.cjs.map +0 -1
  247. package/dist/index65.cts.map +0 -1
  248. package/dist/index66.cjs +0 -3
  249. package/dist/index66.cts.map +0 -1
  250. package/dist/index7.cjs +0 -0
  251. package/dist/index8.cjs +0 -0
  252. package/dist/index9.cjs +0 -25
  253. package/dist/index9.cjs.map +0 -1
  254. package/dist/msic-codes-C8PJVOaA.d.ts +0 -25
  255. package/dist/msic-codes-CIKdPqag.d.cts +0 -26
  256. package/dist/payment-modes-BOTSRC_X.d.ts +0 -43
  257. package/dist/payment-modes-ghFEXnUl.d.cts +0 -44
  258. package/dist/platformLogin-PGzMhw1X.cjs +0 -37
  259. package/dist/platformLogin-PGzMhw1X.cjs.map +0 -1
  260. package/dist/platformLogin-f0bNAoZI.js +0 -30
  261. package/dist/signatures-W-_brwdb.d.ts +0 -172
  262. package/dist/signatures-hFbt_std.d.cts +0 -173
  263. package/dist/state-codes-BlILGZ9d.d.cts +0 -62
  264. package/dist/state-codes-oeFKlwXZ.d.ts +0 -61
  265. package/dist/tax-types-B5sQ8UyN.d.cts +0 -42
  266. package/dist/tax-types-CsQ76JMf.d.ts +0 -41
  267. package/dist/types/classification-codes.d.ts +0 -2
  268. package/dist/types/country-code.d.ts +0 -2
  269. package/dist/types/currencies.d.ts +0 -2
  270. package/dist/types/documents.d.ts +0 -18
  271. package/dist/types/e-invoice.d.ts +0 -2
  272. package/dist/types/index.d.ts +0 -58
  273. package/dist/types/msic/0X.d.ts +0 -2
  274. package/dist/types/msic/1X.d.ts +0 -2
  275. package/dist/types/msic/2X.d.ts +0 -2
  276. package/dist/types/msic/3X.d.ts +0 -2
  277. package/dist/types/msic/4X.d.ts +0 -2
  278. package/dist/types/msic/5X.d.ts +0 -2
  279. package/dist/types/msic/6X.d.ts +0 -2
  280. package/dist/types/msic/7X.d.ts +0 -2
  281. package/dist/types/msic/8X.d.ts +0 -2
  282. package/dist/types/msic/9X.d.ts +0 -2
  283. package/dist/types/msic-codes.d.ts +0 -12
  284. package/dist/types/payment-modes.d.ts +0 -2
  285. package/dist/types/signatures.d.ts +0 -2
  286. package/dist/types/state-codes.d.ts +0 -2
  287. package/dist/types/tax-types.d.ts +0 -2
  288. package/dist/types/unit/1X.d.ts +0 -2
  289. package/dist/types/unit/2X.d.ts +0 -2
  290. package/dist/types/unit/3X.d.ts +0 -2
  291. package/dist/types/unit/4X.d.ts +0 -2
  292. package/dist/types/unit/5X.d.ts +0 -2
  293. package/dist/types/unit/6X.d.ts +0 -2
  294. package/dist/types/unit/7X.d.ts +0 -2
  295. package/dist/types/unit/8X.d.ts +0 -2
  296. package/dist/types/unit/9X.d.ts +0 -2
  297. package/dist/types/unit/AX.d.ts +0 -2
  298. package/dist/types/unit/BX.d.ts +0 -2
  299. package/dist/types/unit/CX.d.ts +0 -2
  300. package/dist/types/unit/DX.d.ts +0 -2
  301. package/dist/types/unit/EX.d.ts +0 -2
  302. package/dist/types/unit/FX.d.ts +0 -2
  303. package/dist/types/unit/GX.d.ts +0 -2
  304. package/dist/types/unit/HX.d.ts +0 -2
  305. package/dist/types/unit/IX.d.ts +0 -2
  306. package/dist/types/unit/JX.d.ts +0 -2
  307. package/dist/types/unit/KX.d.ts +0 -2
  308. package/dist/types/unit/LX.d.ts +0 -2
  309. package/dist/types/unit/MX.d.ts +0 -2
  310. package/dist/types/unit/NX.d.ts +0 -2
  311. package/dist/types/unit/OX.d.ts +0 -2
  312. package/dist/types/unit/PX.d.ts +0 -2
  313. package/dist/types/unit/QX.d.ts +0 -2
  314. package/dist/types/unit/RX.d.ts +0 -2
  315. package/dist/types/unit/SX.d.ts +0 -2
  316. package/dist/types/unit/TX.d.ts +0 -2
  317. package/dist/types/unit/UX.d.ts +0 -2
  318. package/dist/types/unit/VX.d.ts +0 -2
  319. package/dist/types/unit/WX.d.ts +0 -2
  320. package/dist/types/unit/XX.d.ts +0 -2
  321. package/dist/types/unit/YX.d.ts +0 -2
  322. package/dist/types/unit/ZX.d.ts +0 -2
  323. package/dist/types/unit-types.d.ts +0 -37
  324. package/dist/unit-types-B41YFOLT.d.ts +0 -55
  325. package/dist/unit-types-CjWNk2wS.d.cts +0 -56
  326. package/dist/utils/base64.d.ts +0 -5
  327. package/dist/utils/base64.js +0 -10
  328. package/dist/utils/certificate.d.ts +0 -22
  329. package/dist/utils/certificate.js +0 -3
  330. package/dist/utils/document.d.ts +0 -135
  331. package/dist/utils/document.js +0 -3
  332. package/dist/utils/getBaseUrl.d.ts +0 -4
  333. package/dist/utils/getBaseUrl.js +0 -3
  334. package/dist/utils/helpers.d.ts +0 -271
  335. package/dist/utils/helpers.js +0 -330
  336. package/dist/utils/signature-diagnostics.d.ts +0 -93
  337. package/dist/utils/signature-diagnostics.js +0 -326
  338. package/dist/utils/validation.d.ts +0 -46
  339. package/dist/utils/validation.js +0 -134
@@ -1,326 +0,0 @@
1
- import { calculateCertificateDigest, calculateDocumentDigest, calculateSignedPropertiesDigest, createSignedProperties, extractCertificateInfo } from "../document-D6VKMAtx.js";
2
- import crypto from "crypto";
3
-
4
- //#region src/utils/signature-diagnostics.ts
5
- /**
6
- * Analyzes certificate for MyInvois compatibility issues
7
- */
8
- function analyzeCertificateForDiagnostics(certificatePem) {
9
- const issues = [];
10
- const recommendations = [];
11
- try {
12
- const cert = new crypto.X509Certificate(certificatePem);
13
- const certInfo = extractCertificateInfo(certificatePem);
14
- const parseSubjectFields = (dn) => {
15
- const fields = {};
16
- dn.split("\n").forEach((line) => {
17
- const trimmed = line.trim();
18
- if (trimmed.includes("=")) {
19
- const [key, ...valueParts] = trimmed.split("=");
20
- if (key) fields[key.trim()] = valueParts.join("=").trim();
21
- }
22
- });
23
- return fields;
24
- };
25
- const subjectFields = parseSubjectFields(cert.subject);
26
- const organizationIdentifier = subjectFields["organizationIdentifier"] || subjectFields["2.5.4.97"];
27
- const serialNumber = subjectFields["serialNumber"];
28
- if (!organizationIdentifier) {
29
- issues.push("DS311: Certificate missing organizationIdentifier field (TIN)");
30
- recommendations.push("CRITICAL: Generate new certificate with organizationIdentifier matching your MyInvois TIN");
31
- recommendations.push("Portal Error: \"Signer of invoice doesn't match the submitter of document. TIN doesn't match with the OI.\"");
32
- } else if (organizationIdentifier.length < 10) {
33
- issues.push("DS311: OrganizationIdentifier (TIN) appears too short - may cause submission rejection");
34
- recommendations.push("Verify TIN format matches exactly what is registered in MyInvois");
35
- }
36
- if (!serialNumber) {
37
- issues.push("DS312: Certificate missing serialNumber field (business registration)");
38
- recommendations.push("CRITICAL: Generate new certificate with serialNumber matching your business registration");
39
- recommendations.push("Portal Error: \"Submitter registration/identity number doesn't match with the certificate SERIALNUMBER.\"");
40
- }
41
- if (cert.issuer === cert.subject) {
42
- issues.push("DS329: Self-signed certificate detected - will fail chain of trust validation");
43
- recommendations.push("BLOCKING: Obtain certificate from MyInvois-approved CA:");
44
- recommendations.push("• MSC Trustgate Sdn Bhd");
45
- recommendations.push("• DigiCert Sdn Bhd");
46
- recommendations.push("• Cybersign Asia Sdn Bhd");
47
- recommendations.push("Portal Error: \"Certificate is not valid according to the chain of trust validation or has been issued by an untrusted certificate authority.\"");
48
- } else {
49
- const issuerName = cert.issuer.toLowerCase();
50
- const approvedCAs = [
51
- "msc trustgate",
52
- "digicert",
53
- "cybersign"
54
- ];
55
- const isFromApprovedCA = approvedCAs.some((ca) => issuerName.includes(ca));
56
- if (!isFromApprovedCA) {
57
- issues.push("DS329: Certificate may not be from MyInvois-approved CA");
58
- recommendations.push("Verify certificate was issued by an approved CA for MyInvois");
59
- }
60
- }
61
- const rawIssuer = cert.issuer;
62
- const normalizedIssuer = certInfo.issuerName;
63
- const normalizedIssuerIssues = [
64
- {
65
- check: normalizedIssuer.includes("\n"),
66
- issue: "Normalized issuer still contains newlines"
67
- },
68
- {
69
- check: normalizedIssuer.includes(" "),
70
- issue: "Normalized issuer contains double spaces"
71
- },
72
- {
73
- check: /=\s+/.test(normalizedIssuer),
74
- issue: "Normalized issuer has spaces after equals"
75
- },
76
- {
77
- check: /\s+=/.test(normalizedIssuer),
78
- issue: "Normalized issuer has spaces before equals"
79
- },
80
- {
81
- check: normalizedIssuer.includes("\r"),
82
- issue: "Normalized issuer contains carriage returns"
83
- }
84
- ];
85
- const hasActualFormatIssues = normalizedIssuerIssues.some(({ check, issue }) => {
86
- if (check) {
87
- issues.push(`DS326: ${issue} - will cause X509IssuerName mismatch`);
88
- return true;
89
- }
90
- return false;
91
- });
92
- const hasRawIssuesButNormalizedOk = rawIssuer.includes("\n") && !normalizedIssuer.includes("\n");
93
- if (hasActualFormatIssues) {
94
- recommendations.push("CRITICAL: Fix issuer name normalization in signature generation");
95
- recommendations.push("Portal Error: \"Certificate X509IssuerName doesn't match the X509IssuerName value provided in the signed properties section.\"");
96
- recommendations.push("The normalization function is not properly formatting the issuer name");
97
- recommendations.push("Debug: Check document.ts extractCertificateInfo() normalization logic");
98
- } else if (hasRawIssuesButNormalizedOk) console.log("ℹ️ Note: Raw certificate issuer has newlines but normalization is handling them correctly");
99
- const now = /* @__PURE__ */ new Date();
100
- const validFrom = new Date(cert.validFrom);
101
- const validTo = new Date(cert.validTo);
102
- if (now < validFrom) {
103
- issues.push("DS329: Certificate not yet valid (future start date)");
104
- recommendations.push("Wait until certificate validity period begins");
105
- }
106
- if (now > validTo) {
107
- issues.push("DS329: Certificate has expired");
108
- recommendations.push("BLOCKING: Renew certificate - expired certificates are rejected");
109
- }
110
- try {
111
- if (cert.keyUsage && !cert.keyUsage.includes("digital signature")) {
112
- issues.push("DS333: Certificate lacks digitalSignature key usage");
113
- recommendations.push("Generate new certificate with digitalSignature key usage enabled");
114
- }
115
- } catch {
116
- console.log("Note: Could not check key usage extensions");
117
- }
118
- return {
119
- organizationIdentifier,
120
- serialNumber,
121
- issuerName: certInfo.issuerName,
122
- subjectName: certInfo.subjectName,
123
- issues,
124
- recommendations
125
- };
126
- } catch (error) {
127
- issues.push(`Certificate parsing failed: ${error}`);
128
- recommendations.push("Verify certificate format and validity");
129
- return {
130
- issuerName: "",
131
- subjectName: "",
132
- issues,
133
- recommendations
134
- };
135
- }
136
- }
137
- /**
138
- * Analyzes signature generation for potential issues
139
- */
140
- function analyzeSignatureForDiagnostics(invoices, certificatePem) {
141
- const issues = [];
142
- const recommendations = [];
143
- try {
144
- const documentDigest = calculateDocumentDigest(invoices);
145
- const certificateDigest = calculateCertificateDigest(certificatePem);
146
- const certInfo = extractCertificateInfo(certificatePem);
147
- const signingTime = (/* @__PURE__ */ new Date()).toISOString();
148
- const signedProperties = createSignedProperties(certificateDigest, signingTime, certInfo.issuerName, certInfo.serialNumber);
149
- const signedPropertiesDigest = calculateSignedPropertiesDigest(signedProperties);
150
- if (documentDigest.length === 0) {
151
- issues.push("DS333: Document digest generation failed");
152
- recommendations.push("CRITICAL: Verify document serialization excludes UBLExtensions/Signature");
153
- recommendations.push("Portal Error: \"Document signature value is not a valid signature of the document digest using the public key of the certificate provided.\"");
154
- }
155
- if (certificateDigest.length === 0) {
156
- issues.push("DS333: Certificate digest generation failed");
157
- recommendations.push("CRITICAL: Verify certificate format and encoding");
158
- recommendations.push("Certificate must be properly base64 encoded without headers/footers");
159
- }
160
- if (signedPropertiesDigest.length === 0) {
161
- issues.push("DS333: Signed properties digest generation failed");
162
- recommendations.push("CRITICAL: Verify signed properties structure and canonicalization");
163
- recommendations.push("Check XML canonicalization (C14N) is applied correctly");
164
- }
165
- try {
166
- const cert = new crypto.X509Certificate(certificatePem);
167
- const publicKey = cert.publicKey;
168
- const keyDetails = publicKey.asymmetricKeyDetails;
169
- if (keyDetails) {
170
- if (publicKey.asymmetricKeyType === "rsa" && keyDetails.modulusLength && keyDetails.modulusLength < 2048) {
171
- issues.push("DS333: RSA key size too small (minimum 2048 bits required)");
172
- recommendations.push("CRITICAL: Generate new certificate with RSA 2048+ bits");
173
- }
174
- const supportedKeyTypes = ["rsa", "ec"];
175
- if (!supportedKeyTypes.includes(publicKey.asymmetricKeyType || "")) {
176
- issues.push(`DS333: Unsupported key type: ${publicKey.asymmetricKeyType}`);
177
- recommendations.push("CRITICAL: Use RSA or EC key types for MyInvois compatibility");
178
- }
179
- }
180
- const certBuffer = Buffer.from(certificatePem.replace(/-----[^-]+-----/g, "").replace(/\s/g, ""), "base64");
181
- if (certBuffer.length === 0) {
182
- issues.push("DS333: Certificate encoding appears invalid");
183
- recommendations.push("CRITICAL: Verify certificate is properly PEM encoded");
184
- }
185
- } catch (error) {
186
- issues.push(`DS333: Certificate validation failed - ${error}`);
187
- recommendations.push("CRITICAL: Verify certificate format and structure are valid");
188
- }
189
- const isValidBase64 = (str) => {
190
- try {
191
- return Buffer.from(str, "base64").toString("base64") === str;
192
- } catch {
193
- return false;
194
- }
195
- };
196
- if (documentDigest && !isValidBase64(documentDigest)) {
197
- issues.push("DS333: Document digest is not valid base64 format");
198
- recommendations.push("Ensure digest is properly base64 encoded");
199
- }
200
- if (certificateDigest && !isValidBase64(certificateDigest)) {
201
- issues.push("DS333: Certificate digest is not valid base64 format");
202
- recommendations.push("Ensure certificate digest is properly base64 encoded");
203
- }
204
- if (signedPropertiesDigest && !isValidBase64(signedPropertiesDigest)) {
205
- issues.push("DS333: Signed properties digest is not valid base64 format");
206
- recommendations.push("Ensure signed properties digest is properly base64 encoded");
207
- }
208
- return {
209
- documentDigest,
210
- certificateDigest,
211
- signedPropertiesDigest,
212
- issues,
213
- recommendations
214
- };
215
- } catch (error) {
216
- issues.push(`Signature analysis failed: ${error}`);
217
- recommendations.push("Review signature generation implementation");
218
- return {
219
- documentDigest: "",
220
- certificateDigest: "",
221
- signedPropertiesDigest: "",
222
- issues,
223
- recommendations
224
- };
225
- }
226
- }
227
- /**
228
- * Comprehensive signature diagnostics
229
- */
230
- function diagnoseSignatureIssues(invoices, certificatePem) {
231
- const certificateAnalysis = analyzeCertificateForDiagnostics(certificatePem);
232
- const signatureAnalysis = analyzeSignatureForDiagnostics(invoices, certificatePem);
233
- const certificateIssues = certificateAnalysis.issues.length;
234
- const signatureIssues = signatureAnalysis.issues.length;
235
- return {
236
- certificateAnalysis,
237
- signatureAnalysis,
238
- summary: {
239
- totalIssues: certificateIssues + signatureIssues,
240
- certificateIssues,
241
- signatureIssues
242
- }
243
- };
244
- }
245
- /**
246
- * Prints diagnostic results in a formatted way
247
- */
248
- function printDiagnostics(result) {
249
- console.log("\n🔍 MyInvois Signature Diagnostics Report");
250
- console.log("=".repeat(60));
251
- console.log("\n📜 CERTIFICATE ANALYSIS");
252
- console.log("-".repeat(30));
253
- console.log(` Issuer: ${result.certificateAnalysis.issuerName}`);
254
- console.log(` Subject: ${result.certificateAnalysis.subjectName}`);
255
- if (result.certificateAnalysis.organizationIdentifier) console.log(` Organization ID (TIN): ${result.certificateAnalysis.organizationIdentifier}`);
256
- if (result.certificateAnalysis.serialNumber) console.log(` Serial Number: ${result.certificateAnalysis.serialNumber}`);
257
- if (result.certificateAnalysis.issues.length > 0) {
258
- console.log("\n 🚨 Certificate Issues:");
259
- result.certificateAnalysis.issues.forEach((issue, index) => {
260
- console.log(` ${index + 1}. ${issue}`);
261
- });
262
- }
263
- if (result.certificateAnalysis.recommendations.length > 0) {
264
- console.log("\n 💡 Certificate Recommendations:");
265
- result.certificateAnalysis.recommendations.forEach((rec, index) => {
266
- console.log(` ${index + 1}. ${rec}`);
267
- });
268
- }
269
- console.log("\n🔐 SIGNATURE ANALYSIS");
270
- console.log("-".repeat(30));
271
- console.log(` Document Digest: ${result.signatureAnalysis.documentDigest.substring(0, 32)}...`);
272
- console.log(` Certificate Digest: ${result.signatureAnalysis.certificateDigest.substring(0, 32)}...`);
273
- console.log(` Signed Properties Digest: ${result.signatureAnalysis.signedPropertiesDigest.substring(0, 32)}...`);
274
- if (result.signatureAnalysis.issues.length > 0) {
275
- console.log("\n 🚨 Signature Issues:");
276
- result.signatureAnalysis.issues.forEach((issue, index) => {
277
- console.log(` ${index + 1}. ${issue}`);
278
- });
279
- }
280
- if (result.signatureAnalysis.recommendations.length > 0) {
281
- console.log("\n 💡 Signature Recommendations:");
282
- result.signatureAnalysis.recommendations.forEach((rec, index) => {
283
- console.log(` ${index + 1}. ${rec}`);
284
- });
285
- }
286
- console.log("\n📊 SUMMARY");
287
- console.log("-".repeat(30));
288
- console.log(` Total Issues Found: ${result.summary.totalIssues}`);
289
- console.log(` Certificate Issues: ${result.summary.certificateIssues}`);
290
- console.log(` Signature Issues: ${result.summary.signatureIssues}`);
291
- if (result.summary.totalIssues === 0) {
292
- console.log("\n ✅ No issues detected in current analysis");
293
- console.log(" 🎉 Certificate and signature implementation appear valid");
294
- } else {
295
- console.log("\n ⚠️ Issues detected - review recommendations above");
296
- const hasDS311 = result.certificateAnalysis.issues.some((issue) => issue.includes("DS311"));
297
- const hasDS312 = result.certificateAnalysis.issues.some((issue) => issue.includes("DS312"));
298
- const hasDS326 = result.certificateAnalysis.issues.some((issue) => issue.includes("DS326"));
299
- const hasDS329 = result.certificateAnalysis.issues.some((issue) => issue.includes("DS329"));
300
- const hasDS333 = result.signatureAnalysis.issues.some((issue) => issue.includes("DS333"));
301
- console.log("\n 🎯 MYINVOIS PORTAL ERROR ANALYSIS:");
302
- if (hasDS311) console.log(" ❌ DS311 - TIN mismatch between certificate and submitter");
303
- if (hasDS312) console.log(" ❌ DS312 - Registration number mismatch with certificate");
304
- if (hasDS326) console.log(" ❌ DS326 - X509IssuerName format inconsistency");
305
- if (hasDS329) console.log(" ❌ DS329 - Certificate trust chain validation failure");
306
- if (hasDS333) console.log(" ❌ DS333 - Document signature validation failure");
307
- if (result.summary.certificateIssues > 0) {
308
- console.log("\n 🚨 PRIMARY ACTION REQUIRED:");
309
- console.log(" Certificate issues must be resolved first");
310
- console.log(" Self-generated certificates cannot pass MyInvois validation");
311
- }
312
- if (result.summary.signatureIssues > 0) {
313
- console.log("\n ⚙️ SECONDARY ACTION:");
314
- console.log(" Review and optimize signature implementation");
315
- }
316
- console.log("\n 📋 NEXT STEPS:");
317
- console.log(" 1. Address BLOCKING/CRITICAL issues first");
318
- console.log(" 2. Test with updated certificate/implementation");
319
- console.log(" 3. Re-run diagnostics to verify fixes");
320
- console.log(" 4. Submit test document to MyInvois portal");
321
- }
322
- console.log("\n" + "=".repeat(60));
323
- }
324
-
325
- //#endregion
326
- export { diagnoseSignatureIssues, printDiagnostics };
@@ -1,46 +0,0 @@
1
- import { InvoiceV1_1 } from "../types/documents/index.js";
2
-
3
- //#region src/utils/validation.d.ts
4
-
5
- /**
6
- * MyInvois Invoice Validation Utilities
7
- *
8
- * Provides comprehensive validation for invoice data before document generation
9
- * and submission to ensure compliance with MyInvois business rules and format requirements.
10
- */
11
- interface ValidationResult {
12
- isValid: boolean;
13
- errors: ValidationError[];
14
- warnings: ValidationWarning[];
15
- }
16
- interface ValidationError {
17
- field: string;
18
- code: string;
19
- message: string;
20
- severity: "error" | "warning";
21
- }
22
- interface ValidationWarning extends ValidationError {
23
- severity: "warning";
24
- }
25
- /**
26
- * Validates TIN format based on registration type
27
- */
28
- declare const validateTIN: (tin: string, registrationType?: string) => ValidationError[];
29
- /**
30
- * Validates contact number format (E.164 standard)
31
- */
32
- declare const validateContactNumber: (contactNumber: string) => ValidationError[];
33
- /**
34
- * Validates monetary amounts
35
- */
36
- declare const validateMonetaryAmount: (amount: number, fieldName: string, maxDigits?: number, maxDecimals?: number) => ValidationError[];
37
- /**
38
- * Validates tax calculation consistency
39
- */
40
- declare const validateTaxCalculations: (invoice: InvoiceV1_1) => ValidationError[];
41
- /**
42
- * Main validation function for complete invoice
43
- */
44
- declare const validateInvoice: (invoice: InvoiceV1_1) => ValidationResult;
45
- //#endregion
46
- export { ValidationError, ValidationResult, ValidationWarning, validateContactNumber, validateInvoice, validateMonetaryAmount, validateTIN, validateTaxCalculations };
@@ -1,134 +0,0 @@
1
- //#region src/utils/validation.ts
2
- /**
3
- * Validates TIN format based on registration type
4
- */
5
- const validateTIN = (tin, registrationType) => {
6
- const errors = [];
7
- if (!tin) {
8
- errors.push({
9
- field: "tin",
10
- code: "TIN_REQUIRED",
11
- message: "TIN is required",
12
- severity: "error"
13
- });
14
- return errors;
15
- }
16
- if (registrationType === "BRN" && !tin.startsWith("C")) errors.push({
17
- field: "tin",
18
- code: "TIN_FORMAT_INVALID",
19
- message: "Company TIN should start with \"C\" for BRN registration",
20
- severity: "warning"
21
- });
22
- if (registrationType === "NRIC" && !tin.startsWith("IG")) errors.push({
23
- field: "tin",
24
- code: "TIN_FORMAT_INVALID",
25
- message: "Individual TIN should start with \"IG\" for NRIC registration",
26
- severity: "warning"
27
- });
28
- if (tin.length > 14) errors.push({
29
- field: "tin",
30
- code: "TIN_LENGTH_INVALID",
31
- message: "TIN cannot exceed 14 characters",
32
- severity: "error"
33
- });
34
- return errors;
35
- };
36
- /**
37
- * Validates contact number format (E.164 standard)
38
- */
39
- const validateContactNumber = (contactNumber) => {
40
- const errors = [];
41
- if (!contactNumber || contactNumber === "NA") return errors;
42
- const e164Regex = /^\+[1-9]\d{1,14}$/;
43
- if (!e164Regex.test(contactNumber)) errors.push({
44
- field: "contactNumber",
45
- code: "CONTACT_FORMAT_INVALID",
46
- message: "Contact number must be in E.164 format (e.g., +60123456789)",
47
- severity: "error"
48
- });
49
- if (contactNumber.length < 8) errors.push({
50
- field: "contactNumber",
51
- code: "CONTACT_LENGTH_INVALID",
52
- message: "Contact number must be at least 8 characters",
53
- severity: "error"
54
- });
55
- return errors;
56
- };
57
- /**
58
- * Validates monetary amounts
59
- */
60
- const validateMonetaryAmount = (amount, fieldName, maxDigits = 18, maxDecimals = 2) => {
61
- const errors = [];
62
- if (amount < 0) errors.push({
63
- field: fieldName,
64
- code: "AMOUNT_NEGATIVE",
65
- message: `${fieldName} cannot be negative`,
66
- severity: "error"
67
- });
68
- const amountStr = amount.toString();
69
- const [integerPart, decimalPart] = amountStr.split(".");
70
- if (integerPart && integerPart.length > maxDigits - maxDecimals) errors.push({
71
- field: fieldName,
72
- code: "AMOUNT_DIGITS_EXCEEDED",
73
- message: `${fieldName} exceeds maximum ${maxDigits} digits`,
74
- severity: "error"
75
- });
76
- if (decimalPart && decimalPart.length > maxDecimals) errors.push({
77
- field: fieldName,
78
- code: "AMOUNT_DECIMALS_EXCEEDED",
79
- message: `${fieldName} exceeds maximum ${maxDecimals} decimal places`,
80
- severity: "error"
81
- });
82
- return errors;
83
- };
84
- /**
85
- * Validates tax calculation consistency
86
- */
87
- const validateTaxCalculations = (invoice) => {
88
- const errors = [];
89
- const expectedTaxExclusive = invoice.invoiceLineItems.reduce((sum, item) => sum + item.totalTaxableAmountPerLine, 0);
90
- const expectedTaxAmount = invoice.invoiceLineItems.reduce((sum, item) => sum + item.taxAmount, 0);
91
- const tolerance = .01;
92
- if (Math.abs(invoice.legalMonetaryTotal.taxExclusiveAmount - expectedTaxExclusive) > tolerance) errors.push({
93
- field: "legalMonetaryTotal.taxExclusiveAmount",
94
- code: "TAX_EXCLUSIVE_MISMATCH",
95
- message: `Tax exclusive amount (${invoice.legalMonetaryTotal.taxExclusiveAmount}) doesn't match sum of line items (${expectedTaxExclusive})`,
96
- severity: "error"
97
- });
98
- if (Math.abs(invoice.taxTotal.taxAmount - expectedTaxAmount) > tolerance) errors.push({
99
- field: "taxTotal.taxAmount",
100
- code: "TAX_AMOUNT_MISMATCH",
101
- message: `Tax amount (${invoice.taxTotal.taxAmount}) doesn't match sum of line item taxes (${expectedTaxAmount})`,
102
- severity: "error"
103
- });
104
- return errors;
105
- };
106
- /**
107
- * Main validation function for complete invoice
108
- */
109
- const validateInvoice = (invoice) => {
110
- const allErrors = [];
111
- allErrors.push(...validateTIN(invoice.supplier.tin, invoice.supplier.registrationType));
112
- allErrors.push(...validateTIN(invoice.buyer.tin, invoice.buyer.registrationType));
113
- allErrors.push(...validateContactNumber(invoice.supplier.contactNumber));
114
- allErrors.push(...validateContactNumber(invoice.buyer.contactNumber));
115
- allErrors.push(...validateMonetaryAmount(invoice.legalMonetaryTotal.taxExclusiveAmount, "taxExclusiveAmount"));
116
- allErrors.push(...validateMonetaryAmount(invoice.legalMonetaryTotal.payableAmount, "payableAmount"));
117
- allErrors.push(...validateMonetaryAmount(invoice.taxTotal.taxAmount, "taxAmount"));
118
- invoice.invoiceLineItems.forEach((item, index) => {
119
- allErrors.push(...validateMonetaryAmount(item.unitPrice, `lineItem[${index}].unitPrice`));
120
- allErrors.push(...validateMonetaryAmount(item.taxAmount, `lineItem[${index}].taxAmount`));
121
- allErrors.push(...validateMonetaryAmount(item.totalTaxableAmountPerLine, `lineItem[${index}].totalTaxableAmountPerLine`));
122
- });
123
- allErrors.push(...validateTaxCalculations(invoice));
124
- const errors = allErrors.filter((e) => e.severity === "error");
125
- const warnings = allErrors.filter((e) => e.severity === "warning");
126
- return {
127
- isValid: errors.length === 0,
128
- errors,
129
- warnings
130
- };
131
- };
132
-
133
- //#endregion
134
- export { validateContactNumber, validateInvoice, validateMonetaryAmount, validateTIN, validateTaxCalculations };