@ripwords/myinvois-client 0.1.6 → 0.2.0

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 (413) hide show
  1. package/dist/api/documentManagement.d.ts +89 -0
  2. package/dist/api/documentManagement.js +3 -0
  3. package/dist/api/documentSubmission.d.ts +92 -0
  4. package/dist/api/documentSubmission.js +4 -0
  5. package/dist/api/documentTypeManagement.d.ts +70 -0
  6. package/dist/api/documentTypeManagement.js +3 -0
  7. package/dist/api/notificationManagement.d.ts +68 -0
  8. package/dist/api/notificationManagement.js +3 -0
  9. package/dist/api/platformLogin.d.ts +68 -0
  10. package/dist/api/platformLogin.js +3 -0
  11. package/dist/api/taxpayerValidation.d.ts +79 -0
  12. package/dist/api/taxpayerValidation.js +3 -0
  13. package/dist/{certificate-DFK-788s.cjs → certificate-CxsfE91s.cjs} +1 -1
  14. package/dist/{certificate-DFK-788s.cjs.map → certificate-CxsfE91s.cjs.map} +1 -1
  15. package/dist/{document-CARHiGdp.cjs → document-vDphtJTv.cjs} +1 -1
  16. package/dist/{document-CARHiGdp.cjs.map → document-vDphtJTv.cjs.map} +1 -1
  17. package/dist/documentManagement-CIQPkmyb.js +35 -0
  18. package/dist/documentManagement-DQ7JEcBq.cjs +54 -0
  19. package/dist/documentManagement-DQ7JEcBq.cjs.map +1 -0
  20. package/dist/documentSubmission-BdJxIB_I.js +119 -0
  21. package/dist/documentSubmission-D5TC0MPC.cjs +137 -0
  22. package/dist/documentSubmission-D5TC0MPC.cjs.map +1 -0
  23. package/dist/documentTypeManagement-DXRLfTsW.cjs +41 -0
  24. package/dist/documentTypeManagement-DXRLfTsW.cjs.map +1 -0
  25. package/dist/documentTypeManagement-tojgXfm9.js +22 -0
  26. package/dist/{documents-i5EV868Y.d.ts → documents-BgXt86Qp.d.ts} +44 -7
  27. package/dist/{documents-CQy_uB6C.d.cts → documents-BqM9qOnB.d.cts} +39 -2
  28. package/dist/{getBaseUrl-CO7Jp27d.cjs → getBaseUrl-D2iJdUGL.cjs} +1 -1
  29. package/dist/{getBaseUrl-CO7Jp27d.cjs.map → getBaseUrl-D2iJdUGL.cjs.map} +1 -1
  30. package/dist/{index-D2_HVwCz.d.cts → index-Yr1QAbIF.d.cts} +1 -1
  31. package/dist/index.cjs +234 -131
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.ts +250 -60
  34. package/dist/index.js +234 -131
  35. package/dist/index10.cjs +196 -0
  36. package/dist/index10.cjs.map +1 -0
  37. package/dist/index11.cjs +0 -34
  38. package/dist/index12.cjs +16 -15
  39. package/dist/index12.cjs.map +1 -1
  40. package/dist/index14.cjs +0 -13
  41. package/dist/index15.cjs +28 -3
  42. package/dist/index15.cjs.map +1 -0
  43. package/dist/index16.cjs +24 -12
  44. package/dist/index16.cjs.map +1 -0
  45. package/dist/index17.cjs +0 -3
  46. package/dist/index18.cjs +28 -334
  47. package/dist/index18.cjs.map +1 -1
  48. package/dist/index19.cjs +18 -323
  49. package/dist/index19.cjs.map +1 -1
  50. package/dist/index2.cjs +4 -61
  51. package/dist/index20.cjs +0 -140
  52. package/dist/index21.cjs +0 -3
  53. package/dist/index22.cjs +0 -208
  54. package/dist/index23.cjs +9 -105
  55. package/dist/index23.cjs.map +1 -1
  56. package/dist/index24.cjs +3 -136
  57. package/dist/index25.cjs +12 -63
  58. package/dist/index26.cjs +2 -266
  59. package/dist/index27.cjs +325 -75
  60. package/dist/index27.cjs.map +1 -1
  61. package/dist/index28.cjs +136 -103
  62. package/dist/index28.cjs.map +1 -1
  63. package/dist/index29.cjs +203 -68
  64. package/dist/index29.cjs.map +1 -1
  65. package/dist/index3.cjs +5 -531
  66. package/dist/index30.cjs +104 -107
  67. package/dist/index30.cjs.map +1 -1
  68. package/dist/index31.cjs +132 -95
  69. package/dist/index31.cjs.map +1 -1
  70. package/dist/index32.cjs +59 -13
  71. package/dist/index32.cjs.map +1 -1
  72. package/dist/index33.cjs +262 -33
  73. package/dist/index33.cjs.map +1 -1
  74. package/dist/index34.cjs +74 -14
  75. package/dist/index34.cjs.map +1 -1
  76. package/dist/index35.cjs +102 -24
  77. package/dist/index35.cjs.map +1 -1
  78. package/dist/index36.cjs +68 -15
  79. package/dist/index36.cjs.map +1 -1
  80. package/dist/index37.cjs +107 -9
  81. package/dist/index37.cjs.map +1 -1
  82. package/dist/index38.cjs +95 -9
  83. package/dist/index38.cjs.map +1 -1
  84. package/dist/index39.cjs +11 -10
  85. package/dist/index39.cjs.map +1 -1
  86. package/dist/index4.cjs +4 -195
  87. package/dist/index40.cjs +31 -6
  88. package/dist/index40.cjs.map +1 -1
  89. package/dist/index41.cjs +12 -101
  90. package/dist/index41.cjs.map +1 -1
  91. package/dist/index42.cjs +22 -106
  92. package/dist/index42.cjs.map +1 -1
  93. package/dist/index43.cjs +13 -119
  94. package/dist/index43.cjs.map +1 -1
  95. package/dist/index44.cjs +7 -106
  96. package/dist/index44.cjs.map +1 -1
  97. package/dist/index45.cjs +7 -98
  98. package/dist/index45.cjs.map +1 -1
  99. package/dist/index46.cjs +10 -118
  100. package/dist/index46.cjs.map +1 -1
  101. package/dist/index47.cjs +6 -127
  102. package/dist/index47.cjs.map +1 -1
  103. package/dist/index48.cjs +101 -117
  104. package/dist/index48.cjs.map +1 -1
  105. package/dist/index49.cjs +106 -14
  106. package/dist/index49.cjs.map +1 -1
  107. package/dist/index5.cjs +3 -0
  108. package/dist/index50.cjs +119 -95
  109. package/dist/index50.cjs.map +1 -1
  110. package/dist/index51.cjs +106 -142
  111. package/dist/index51.cjs.map +1 -1
  112. package/dist/index52.cjs +98 -114
  113. package/dist/index52.cjs.map +1 -1
  114. package/dist/index53.cjs +118 -144
  115. package/dist/index53.cjs.map +1 -1
  116. package/dist/index54.cjs +127 -113
  117. package/dist/index54.cjs.map +1 -1
  118. package/dist/index55.cjs +117 -17
  119. package/dist/index55.cjs.map +1 -1
  120. package/dist/index56.cjs +14 -112
  121. package/dist/index56.cjs.map +1 -1
  122. package/dist/index57.cjs +95 -47
  123. package/dist/index57.cjs.map +1 -1
  124. package/dist/index58.cjs +142 -14
  125. package/dist/index58.cjs.map +1 -1
  126. package/dist/index59.cjs +114 -28
  127. package/dist/index59.cjs.map +1 -1
  128. package/dist/index6.cjs +2 -24
  129. package/dist/index60.cjs +144 -22
  130. package/dist/index60.cjs.map +1 -1
  131. package/dist/index61.cjs +113 -9
  132. package/dist/index61.cjs.map +1 -1
  133. package/dist/index61.cts.map +1 -1
  134. package/dist/index62.cjs +17 -8
  135. package/dist/index62.cjs.map +1 -1
  136. package/dist/index62.cts.map +1 -1
  137. package/dist/index63.cjs +112 -17
  138. package/dist/index63.cjs.map +1 -1
  139. package/dist/index63.cts.map +1 -1
  140. package/dist/index64.cjs +47 -412
  141. package/dist/index64.cjs.map +1 -1
  142. package/dist/index64.cts.map +1 -1
  143. package/dist/index65.cjs +14 -8
  144. package/dist/index65.cjs.map +1 -1
  145. package/dist/index65.cts.map +1 -1
  146. package/dist/index66.cjs +28 -9
  147. package/dist/index66.cjs.map +1 -1
  148. package/dist/index66.cts.map +1 -1
  149. package/dist/index67.cjs +29 -0
  150. package/dist/index67.cjs.map +1 -0
  151. package/dist/index67.cts.map +1 -0
  152. package/dist/index68.cjs +16 -0
  153. package/dist/index68.cjs.map +1 -0
  154. package/dist/{index60.cts.map → index68.cts.map} +1 -1
  155. package/dist/index69.cjs +15 -0
  156. package/dist/index69.cjs.map +1 -0
  157. package/dist/index69.cts.map +1 -0
  158. package/dist/index7.cjs +5 -0
  159. package/dist/index70.cjs +24 -0
  160. package/dist/index70.cjs.map +1 -0
  161. package/dist/index70.cts.map +1 -0
  162. package/dist/index71.cjs +419 -0
  163. package/dist/index71.cjs.map +1 -0
  164. package/dist/index71.cts.map +1 -0
  165. package/dist/index72.cjs +15 -0
  166. package/dist/index72.cjs.map +1 -0
  167. package/dist/index72.cts.map +1 -0
  168. package/dist/index73.cjs +16 -0
  169. package/dist/index73.cjs.map +1 -0
  170. package/dist/index73.cts.map +1 -0
  171. package/dist/index8.cjs +62 -0
  172. package/dist/{index2.cjs.map → index8.cjs.map} +1 -1
  173. package/dist/index9.cjs +523 -16
  174. package/dist/index9.cjs.map +1 -1
  175. package/dist/{msic-codes-C8PJVOaA.d.ts → msic-codes-CiPeemFK.d.ts} +10 -10
  176. package/dist/notificationManagement-CHDRVy8J.js +19 -0
  177. package/dist/notificationManagement-C_qrFwWL.cjs +26 -0
  178. package/dist/notificationManagement-C_qrFwWL.cjs.map +1 -0
  179. package/dist/notifications-B4l_qRj7.d.ts +62 -0
  180. package/dist/notifications-DdlEkprb.d.cts +63 -0
  181. package/dist/{platformLogin-PGzMhw1X.cjs → platformLogin-CPiPiVUh.cjs} +2 -2
  182. package/dist/platformLogin-CPiPiVUh.cjs.map +1 -0
  183. package/dist/{platformLogin-f0bNAoZI.js → platformLogin-Ck1Fge2n.js} +1 -1
  184. package/dist/taxpayer-D67d2zAC.d.ts +26 -0
  185. package/dist/taxpayer-sGkviG8J.d.cts +27 -0
  186. package/dist/taxpayerValidation-DI4B6kWx.js +54 -0
  187. package/dist/taxpayerValidation-DdeXCvPT.cjs +73 -0
  188. package/dist/taxpayerValidation-DdeXCvPT.cjs.map +1 -0
  189. package/dist/types/classification-codes.d.ts +1 -1
  190. package/dist/types/country-code.d.ts +1 -1
  191. package/dist/types/currencies.d.ts +1 -1
  192. package/dist/types/documents.d.ts +18 -18
  193. package/dist/types/e-invoice.d.ts +1 -1
  194. package/dist/types/index.d.ts +61 -58
  195. package/dist/types/msic/0X.d.ts +1 -1
  196. package/dist/types/msic/1X.d.ts +1 -1
  197. package/dist/types/msic/2X.d.ts +1 -1
  198. package/dist/types/msic/3X.d.ts +1 -1
  199. package/dist/types/msic/4X.d.ts +1 -1
  200. package/dist/types/msic/5X.d.ts +1 -1
  201. package/dist/types/msic/6X.d.ts +1 -1
  202. package/dist/types/msic/7X.d.ts +1 -1
  203. package/dist/types/msic/8X.d.ts +1 -1
  204. package/dist/types/msic/9X.d.ts +1 -1
  205. package/dist/types/msic-codes.d.ts +11 -11
  206. package/dist/types/notifications.d.ts +2 -0
  207. package/dist/types/payment-modes.d.ts +1 -1
  208. package/dist/types/signatures.d.ts +1 -1
  209. package/dist/types/state-codes.d.ts +1 -1
  210. package/dist/types/tax-types.d.ts +1 -1
  211. package/dist/types/taxpayer.d.ts +19 -0
  212. package/dist/types/unit/1X.d.ts +1 -1
  213. package/dist/types/unit/2X.d.ts +1 -1
  214. package/dist/types/unit/3X.d.ts +1 -1
  215. package/dist/types/unit/4X.d.ts +1 -1
  216. package/dist/types/unit/5X.d.ts +1 -1
  217. package/dist/types/unit/6X.d.ts +1 -1
  218. package/dist/types/unit/7X.d.ts +1 -1
  219. package/dist/types/unit/8X.d.ts +1 -1
  220. package/dist/types/unit/9X.d.ts +1 -1
  221. package/dist/types/unit/AX.d.ts +1 -1
  222. package/dist/types/unit/BX.d.ts +1 -1
  223. package/dist/types/unit/CX.d.ts +1 -1
  224. package/dist/types/unit/DX.d.ts +1 -1
  225. package/dist/types/unit/EX.d.ts +1 -1
  226. package/dist/types/unit/FX.d.ts +1 -1
  227. package/dist/types/unit/GX.d.ts +1 -1
  228. package/dist/types/unit/HX.d.ts +1 -1
  229. package/dist/types/unit/IX.d.ts +1 -1
  230. package/dist/types/unit/JX.d.ts +1 -1
  231. package/dist/types/unit/KX.d.ts +1 -1
  232. package/dist/types/unit/LX.d.ts +1 -1
  233. package/dist/types/unit/MX.d.ts +1 -1
  234. package/dist/types/unit/NX.d.ts +1 -1
  235. package/dist/types/unit/OX.d.ts +1 -1
  236. package/dist/types/unit/PX.d.ts +1 -1
  237. package/dist/types/unit/QX.d.ts +1 -1
  238. package/dist/types/unit/RX.d.ts +1 -1
  239. package/dist/types/unit/SX.d.ts +1 -1
  240. package/dist/types/unit/TX.d.ts +1 -1
  241. package/dist/types/unit/UX.d.ts +1 -1
  242. package/dist/types/unit/VX.d.ts +1 -1
  243. package/dist/types/unit/WX.d.ts +1 -1
  244. package/dist/types/unit/XX.d.ts +1 -1
  245. package/dist/types/unit/YX.d.ts +1 -1
  246. package/dist/types/unit/ZX.d.ts +1 -1
  247. package/dist/types/unit-types.d.ts +36 -36
  248. package/dist/types/utils.d.ts +2 -0
  249. package/dist/unit-types-VgYXIwTT.d.ts +55 -0
  250. package/dist/utils/certificate.js +1 -1
  251. package/dist/utils/document.d.ts +60 -57
  252. package/dist/utils/document.js +1 -1
  253. package/dist/utils/getBaseUrl.js +1 -1
  254. package/dist/utils/signature-diagnostics.d.ts +60 -57
  255. package/dist/utils/signature-diagnostics.js +1 -1
  256. package/dist/utils-B3mo51Zp.d.ts +4 -0
  257. package/dist/utils-Cdqbbzca.d.cts +5 -0
  258. package/package.json +5 -8
  259. package/.prettierrc +0 -8
  260. package/CHANGELOG.md +0 -152
  261. package/bun.lock +0 -460
  262. package/dist/api/platform/platformLogin.d.ts +0 -65
  263. package/dist/api/platform/platformLogin.js +0 -3
  264. package/dist/index11.cjs.map +0 -1
  265. package/dist/index14.cjs.map +0 -1
  266. package/dist/index20.cjs.map +0 -1
  267. package/dist/index22.cjs.map +0 -1
  268. package/dist/index24.cjs.map +0 -1
  269. package/dist/index25.cjs.map +0 -1
  270. package/dist/index26.cjs.map +0 -1
  271. package/dist/index3.cjs.map +0 -1
  272. package/dist/index4.cjs.map +0 -1
  273. package/dist/index58.cts.map +0 -1
  274. package/dist/index59.cts.map +0 -1
  275. package/dist/index6.cjs.map +0 -1
  276. package/dist/platformLogin-PGzMhw1X.cjs.map +0 -1
  277. package/dist/unit-types-B41YFOLT.d.ts +0 -55
  278. package/dist/utils/helpers.d.ts +0 -271
  279. package/dist/utils/helpers.js +0 -330
  280. package/myinvois-cert.conf.template +0 -23
  281. package/scripts/gen-cert.sh +0 -159
  282. package/src/api/platform/platformLogin.ts +0 -34
  283. package/src/index.ts +0 -530
  284. package/src/types/classification-codes.d.ts +0 -115
  285. package/src/types/country-code.d.ts +0 -790
  286. package/src/types/currencies.d.ts +0 -383
  287. package/src/types/documents.d.ts +0 -869
  288. package/src/types/e-invoice.d.ts +0 -41
  289. package/src/types/index.d.ts +0 -24
  290. package/src/types/msic/0X.d.ts +0 -408
  291. package/src/types/msic/1X.d.ts +0 -210
  292. package/src/types/msic/2X.d.ts +0 -266
  293. package/src/types/msic/3X.d.ts +0 -114
  294. package/src/types/msic/4X.d.ts +0 -520
  295. package/src/types/msic/5X.d.ts +0 -144
  296. package/src/types/msic/6X.d.ts +0 -200
  297. package/src/types/msic/7X.d.ts +0 -132
  298. package/src/types/msic/8X.d.ts +0 -210
  299. package/src/types/msic/9X.d.ts +0 -186
  300. package/src/types/msic-codes.d.ts +0 -31
  301. package/src/types/payment-modes.d.ts +0 -41
  302. package/src/types/signatures.d.ts +0 -169
  303. package/src/types/state-codes.d.ts +0 -59
  304. package/src/types/tax-types.d.ts +0 -39
  305. package/src/types/unit/1X.d.ts +0 -16
  306. package/src/types/unit/2X.d.ts +0 -62
  307. package/src/types/unit/3X.d.ts +0 -17
  308. package/src/types/unit/4X.d.ts +0 -44
  309. package/src/types/unit/5X.d.ts +0 -26
  310. package/src/types/unit/6X.d.ts +0 -12
  311. package/src/types/unit/7X.d.ts +0 -12
  312. package/src/types/unit/8X.d.ts +0 -15
  313. package/src/types/unit/9X.d.ts +0 -11
  314. package/src/types/unit/AX.d.ts +0 -202
  315. package/src/types/unit/BX.d.ts +0 -212
  316. package/src/types/unit/CX.d.ts +0 -238
  317. package/src/types/unit/DX.d.ts +0 -212
  318. package/src/types/unit/EX.d.ts +0 -196
  319. package/src/types/unit/FX.d.ts +0 -236
  320. package/src/types/unit/GX.d.ts +0 -254
  321. package/src/types/unit/HX.d.ts +0 -234
  322. package/src/types/unit/IX.d.ts +0 -28
  323. package/src/types/unit/JX.d.ts +0 -190
  324. package/src/types/unit/KX.d.ts +0 -284
  325. package/src/types/unit/LX.d.ts +0 -228
  326. package/src/types/unit/MX.d.ts +0 -288
  327. package/src/types/unit/NX.d.ts +0 -226
  328. package/src/types/unit/OX.d.ts +0 -34
  329. package/src/types/unit/PX.d.ts +0 -224
  330. package/src/types/unit/QX.d.ts +0 -94
  331. package/src/types/unit/RX.d.ts +0 -28
  332. package/src/types/unit/SX.d.ts +0 -56
  333. package/src/types/unit/TX.d.ts +0 -44
  334. package/src/types/unit/UX.d.ts +0 -14
  335. package/src/types/unit/VX.d.ts +0 -13
  336. package/src/types/unit/WX.d.ts +0 -34
  337. package/src/types/unit/XX.d.ts +0 -825
  338. package/src/types/unit/YX.d.ts +0 -17
  339. package/src/types/unit/ZX.d.ts +0 -19
  340. package/src/types/unit-types.d.ts +0 -86
  341. package/src/utils/base64.ts +0 -7
  342. package/src/utils/certificate.ts +0 -60
  343. package/src/utils/document.ts +0 -852
  344. package/src/utils/getBaseUrl.ts +0 -5
  345. package/src/utils/helpers.ts +0 -552
  346. package/src/utils/signature-diagnostics.ts +0 -583
  347. package/src/utils/validation.ts +0 -268
  348. package/test/MyInvoiClientWithRealData.test.ts +0 -40
  349. package/test/MyInvoisClient.test.ts +0 -204
  350. package/test/base64.test.ts +0 -43
  351. package/test/dynamicInvoiceFeatures.test.ts +0 -451
  352. package/test/signAndSubmitInvoice.test.ts +0 -452
  353. package/test/signature-diagnostics.test.ts +0 -130
  354. package/tsconfig.json +0 -39
  355. package/tsdown.config.ts +0 -31
  356. package/vitest.config.ts +0 -8
  357. /package/dist/{0X-CTIq3y3a.d.ts → 0X-DZnB0al0.d.ts} +0 -0
  358. /package/dist/{1X-BywXCqtn.d.ts → 1X-C72Wa4pk.d.ts} +0 -0
  359. /package/dist/{1X-Bu4oiv8D.d.ts → 1X-Dg5J6Bfg.d.ts} +0 -0
  360. /package/dist/{2X-3fSEGIuE.d.ts → 2X-CH89y3Af.d.ts} +0 -0
  361. /package/dist/{2X-DnG3FY1f.d.ts → 2X-D_qwTeDT.d.ts} +0 -0
  362. /package/dist/{3X-CLdmoel1.d.ts → 3X-BJHYxgxa.d.ts} +0 -0
  363. /package/dist/{3X-Ynjfgoll.d.ts → 3X-DryrwYRf.d.ts} +0 -0
  364. /package/dist/{4X-B5ePdMky.d.ts → 4X-BPMLRoDv.d.ts} +0 -0
  365. /package/dist/{4X-BTG6o1Gn.d.ts → 4X-BbZgoRHO.d.ts} +0 -0
  366. /package/dist/{5X-dhP6fyou.d.ts → 5X-Bv7M6KyG.d.ts} +0 -0
  367. /package/dist/{5X-CjSz1zxJ.d.ts → 5X-oQRBnO0f.d.ts} +0 -0
  368. /package/dist/{6X-B9KP_vEn.d.ts → 6X-B9I2XJa4.d.ts} +0 -0
  369. /package/dist/{6X-BHaY0TCf.d.ts → 6X-ZeZ8OB57.d.ts} +0 -0
  370. /package/dist/{7X-DtkQutx2.d.ts → 7X-Ckv9bbzG.d.ts} +0 -0
  371. /package/dist/{7X-C4eX_tAk.d.ts → 7X-Dvw2Z2VN.d.ts} +0 -0
  372. /package/dist/{8X-D6HTLShY.d.ts → 8X-BkgoX8dg.d.ts} +0 -0
  373. /package/dist/{8X-5n9seY3z.d.ts → 8X-C37BJTl6.d.ts} +0 -0
  374. /package/dist/{9X-CHZKsIdD.d.ts → 9X-Du0e44cq.d.ts} +0 -0
  375. /package/dist/{9X-Cpb6V4JC.d.ts → 9X-_XRgT2-_.d.ts} +0 -0
  376. /package/dist/{AX-C0w_r3PA.d.ts → AX-BSPLpkVT.d.ts} +0 -0
  377. /package/dist/{BX-RadlZ-6m.d.ts → BX-u4yMaIkz.d.ts} +0 -0
  378. /package/dist/{CX-CT1Zzb9D.d.ts → CX-BKZG0pVE.d.ts} +0 -0
  379. /package/dist/{DX-CtUeTKMM.d.ts → DX-CwA9WJAf.d.ts} +0 -0
  380. /package/dist/{EX-084Yu7Wt.d.ts → EX-BRNu1Ooi.d.ts} +0 -0
  381. /package/dist/{FX-BrbQM0CW.d.ts → FX-DBxjq6xY.d.ts} +0 -0
  382. /package/dist/{GX-gKj8iAAh.d.ts → GX-B3CvWNrP.d.ts} +0 -0
  383. /package/dist/{HX-9D-ZXTy5.d.ts → HX-D7FABgTv.d.ts} +0 -0
  384. /package/dist/{IX-DR4Fc92A.d.ts → IX-D3ZknsAB.d.ts} +0 -0
  385. /package/dist/{JX-DIKa9ma-.d.ts → JX-BRaZM3Gc.d.ts} +0 -0
  386. /package/dist/{KX-DpsJ_unT.d.ts → KX-B1K0OWoi.d.ts} +0 -0
  387. /package/dist/{LX-DeXPPWUX.d.ts → LX-CKRefinL.d.ts} +0 -0
  388. /package/dist/{MX-CKMjg_zK.d.ts → MX-DKmaeO9r.d.ts} +0 -0
  389. /package/dist/{NX-oYdb4NDo.d.ts → NX-CJL2Gn1U.d.ts} +0 -0
  390. /package/dist/{OX-Bid9es3D.d.ts → OX-Do2ap5v_.d.ts} +0 -0
  391. /package/dist/{PX-D7jy9CFk.d.ts → PX-_DOr_rm9.d.ts} +0 -0
  392. /package/dist/{QX-BFWOR4g3.d.ts → QX-HlXLkIki.d.ts} +0 -0
  393. /package/dist/{RX-XHgCyMV1.d.ts → RX-DVPGOVES.d.ts} +0 -0
  394. /package/dist/{SX-Cl8RN8oH.d.ts → SX-OGT3qwlS.d.ts} +0 -0
  395. /package/dist/{TX-ZymoIbtr.d.ts → TX-cPDINmZ5.d.ts} +0 -0
  396. /package/dist/{UX-D-Ndd1ov.d.ts → UX-Be3sqvPV.d.ts} +0 -0
  397. /package/dist/{VX-B-1b34r7.d.ts → VX-CoEuBNDK.d.ts} +0 -0
  398. /package/dist/{WX-0GuMjPNZ.d.ts → WX-DMvw__jH.d.ts} +0 -0
  399. /package/dist/{XX-CF2NANsy.d.ts → XX-DOA-10JW.d.ts} +0 -0
  400. /package/dist/{YX-B51BbNSg.d.ts → YX-F34sJ7Ik.d.ts} +0 -0
  401. /package/dist/{ZX-BMJS1iAv.d.ts → ZX-CDQOfsHh.d.ts} +0 -0
  402. /package/dist/{certificate-aooIRf9A.js → certificate-BDECQL9C.js} +0 -0
  403. /package/dist/{classification-codes-BKxV-rO9.d.ts → classification-codes-B1D5xbq5.d.ts} +0 -0
  404. /package/dist/{country-code-CQuaiQm2.d.ts → country-code-D42kAyNH.d.ts} +0 -0
  405. /package/dist/{currencies-BYJK-m6v.d.ts → currencies-CDveO_yz.d.ts} +0 -0
  406. /package/dist/{document-D6VKMAtx.js → document-BSuYbfXR.js} +0 -0
  407. /package/dist/{e-invoice-CmbLQkHw.d.ts → e-invoice-BxNC6V_j.d.ts} +0 -0
  408. /package/dist/{getBaseUrl-R3IdgCu3.js → getBaseUrl-BYkBwhQP.js} +0 -0
  409. /package/dist/{index-0-EvC6Nv.d.ts → index-FTgB2nM6.d.ts} +0 -0
  410. /package/dist/{payment-modes-BOTSRC_X.d.ts → payment-modes-NpE3OcCV.d.ts} +0 -0
  411. /package/dist/{signatures-W-_brwdb.d.ts → signatures-DOKNMiZI.d.ts} +0 -0
  412. /package/dist/{state-codes-oeFKlwXZ.d.ts → state-codes-VOFWhHA0.d.ts} +0 -0
  413. /package/dist/{tax-types-CsQ76JMf.d.ts → tax-types-ieqw5Ze7.d.ts} +0 -0
@@ -1,852 +0,0 @@
1
- import crypto, { X509Certificate } from 'crypto'
2
- import {
3
- InvoiceSubmission,
4
- InvoiceV1_1,
5
- SigningCredentials,
6
- SignedPropertiesObject,
7
- UBLDocument,
8
- CompleteInvoice,
9
- SignedInfoObject,
10
- } from '../types'
11
-
12
- /**
13
- * MyInvois v1.1 Document Generation and Signing Utilities
14
- * Strictly follows: https://sdk.myinvois.hasil.gov.my/documents/invoice-v1-1
15
- * JSON Signature Guide: https://sdk.myinvois.hasil.gov.my/signature-creation-json/
16
- */
17
-
18
- /**
19
- * Helper function to recursively sort object keys for JSON canonicalization
20
- */
21
- export function sortObjectKeys(obj: unknown): unknown {
22
- if (obj === null || typeof obj !== 'object') {
23
- return obj
24
- }
25
-
26
- if (Array.isArray(obj)) {
27
- return obj.map(sortObjectKeys)
28
- }
29
-
30
- const sortedObj: Record<string, unknown> = {}
31
- const keys = Object.keys(obj as Record<string, unknown>).sort()
32
-
33
- for (const key of keys) {
34
- sortedObj[key] = sortObjectKeys((obj as Record<string, unknown>)[key])
35
- }
36
-
37
- return sortedObj
38
- }
39
-
40
- /**
41
- * Enhanced canonicalization following MyInvois specification exactly
42
- * Key changes: ensure consistent ordering and formatting
43
- */
44
- export const canonicalizeJSON = (obj: unknown): string => {
45
- const sortedObj = sortObjectKeys(obj)
46
- // Use compact JSON with no extra whitespace
47
- return JSON.stringify(sortedObj, null, 0)
48
- }
49
-
50
- /**
51
- * Generates a clean invoice object following MyInvois v1.1 specification exactly
52
- * This is the base invoice structure WITHOUT signature elements (for hash calculation)
53
- *
54
- * Key requirements from working documents:
55
- * - All mandatory fields must be present
56
- * - Many optional fields must be present even if empty
57
- * - Specific field ordering and structure
58
- * - Correct listID values (e.g., "3166-1" not "ISO3166-1")
59
- */
60
- export const generateCleanInvoiceObject = (
61
- invoice: InvoiceV1_1,
62
- ): InvoiceSubmission => {
63
- return {
64
- // === MANDATORY CORE FIELDS ===
65
- ID: [{ _: invoice.eInvoiceCodeOrNumber }],
66
- IssueDate: [{ _: invoice.eInvoiceDate }],
67
- IssueTime: [{ _: invoice.eInvoiceTime }],
68
- InvoiceTypeCode: [
69
- {
70
- _: invoice.eInvoiceTypeCode,
71
- listVersionID: invoice.eInvoiceVersion || '1.1',
72
- },
73
- ],
74
- DocumentCurrencyCode: [{ _: invoice.invoiceCurrencyCode }],
75
-
76
- // === SUPPLIER PARTY (AccountingSupplierParty) ===
77
- AccountingSupplierParty: [
78
- {
79
- Party: [
80
- {
81
- // Industry Classification - required field
82
- IndustryClassificationCode: [
83
- {
84
- _: invoice.supplier.industryClassificationCode,
85
- name: invoice.supplier.industryClassificationDescription,
86
- },
87
- ],
88
-
89
- // Party Identifications
90
- PartyIdentification: [
91
- {
92
- ID: [
93
- {
94
- _: invoice.supplier.tin,
95
- schemeID: 'TIN',
96
- },
97
- ],
98
- },
99
- {
100
- ID: [
101
- {
102
- _: invoice.supplier.registrationNumber,
103
- schemeID: invoice.supplier.registrationType || 'NRIC',
104
- },
105
- ],
106
- },
107
- ],
108
-
109
- // Postal Address - FIXED listID format
110
- PostalAddress: [
111
- {
112
- CityName: [{ _: invoice.supplier.address.cityName }],
113
- CountrySubentityCode: [{ _: invoice.supplier.address.state }],
114
- AddressLine: [
115
- {
116
- Line: [{ _: invoice.supplier.address.addressLine0 }],
117
- },
118
- ],
119
- Country: [
120
- {
121
- IdentificationCode: [
122
- {
123
- _: invoice.supplier.address.country || 'MYS',
124
- listID: '3166-1', // FIXED: was "ISO3166-1"
125
- listAgencyID: 'ISO',
126
- },
127
- ],
128
- },
129
- ],
130
- },
131
- ],
132
-
133
- // Party Legal Entity
134
- PartyLegalEntity: [
135
- {
136
- RegistrationName: [{ _: invoice.supplier.name }],
137
- },
138
- ],
139
-
140
- // Contact Information
141
- Contact: [
142
- {
143
- Telephone: [{ _: invoice.supplier.contactNumber || '' }],
144
- },
145
- ],
146
- },
147
- ],
148
- },
149
- ],
150
-
151
- // === BUYER PARTY (AccountingCustomerParty) ===
152
- AccountingCustomerParty: [
153
- {
154
- Party: [
155
- {
156
- // Party Identifications
157
- PartyIdentification: [
158
- {
159
- ID: [
160
- {
161
- _: invoice.buyer.tin,
162
- schemeID: 'TIN',
163
- },
164
- ],
165
- },
166
- {
167
- ID: [
168
- {
169
- _: invoice.buyer.registrationNumber,
170
- schemeID: invoice.buyer.registrationType || 'NRIC',
171
- },
172
- ],
173
- },
174
- {
175
- ID: [
176
- {
177
- _: invoice.buyer.sstRegistrationNumber || 'NA',
178
- schemeID: 'SST',
179
- },
180
- ],
181
- },
182
- ],
183
-
184
- // Postal Address - FIXED listID format
185
- PostalAddress: [
186
- {
187
- CityName: [{ _: invoice.buyer.address.cityName }],
188
- CountrySubentityCode: [{ _: invoice.buyer.address.state }],
189
- AddressLine: [
190
- {
191
- Line: [{ _: invoice.buyer.address.addressLine0 }],
192
- },
193
- ],
194
- Country: [
195
- {
196
- IdentificationCode: [
197
- {
198
- _: invoice.buyer.address.country || 'MYS',
199
- listID: '3166-1', // FIXED: was "ISO3166-1"
200
- listAgencyID: 'ISO',
201
- },
202
- ],
203
- },
204
- ],
205
- },
206
- ],
207
-
208
- // Party Legal Entity
209
- PartyLegalEntity: [
210
- {
211
- RegistrationName: [{ _: invoice.buyer.name }],
212
- },
213
- ],
214
-
215
- // Contact Information
216
- Contact: [
217
- {
218
- Telephone: [{ _: invoice.buyer.contactNumber || '' }],
219
- },
220
- ],
221
- },
222
- ],
223
- },
224
- ],
225
-
226
- // === TAX TOTAL ===
227
- TaxTotal: [
228
- {
229
- TaxAmount: [
230
- {
231
- _: invoice.taxTotal.taxAmount,
232
- currencyID: invoice.invoiceCurrencyCode,
233
- },
234
- ],
235
- TaxSubtotal: [
236
- // Generate basic tax subtotal from invoice line items
237
- {
238
- TaxableAmount: [
239
- {
240
- _: invoice.legalMonetaryTotal.taxExclusiveAmount,
241
- currencyID: invoice.invoiceCurrencyCode,
242
- },
243
- ],
244
- TaxAmount: [
245
- {
246
- _: invoice.taxTotal.taxAmount,
247
- currencyID: invoice.invoiceCurrencyCode,
248
- },
249
- ],
250
- TaxCategory: [
251
- {
252
- ID: [{ _: invoice.invoiceLineItems[0]?.taxType || '01' }],
253
- TaxScheme: [
254
- {
255
- ID: [
256
- {
257
- _: 'OTH',
258
- schemeAgencyID: '6',
259
- schemeID: 'UN/ECE 5153',
260
- },
261
- ],
262
- },
263
- ],
264
- },
265
- ],
266
- },
267
- ],
268
- },
269
- ],
270
-
271
- // === LEGAL MONETARY TOTAL ===
272
- LegalMonetaryTotal: [
273
- {
274
- LineExtensionAmount: [
275
- {
276
- _: invoice.legalMonetaryTotal.taxExclusiveAmount,
277
- currencyID: invoice.invoiceCurrencyCode,
278
- },
279
- ],
280
- TaxExclusiveAmount: [
281
- {
282
- _: invoice.legalMonetaryTotal.taxExclusiveAmount,
283
- currencyID: invoice.invoiceCurrencyCode,
284
- },
285
- ],
286
- TaxInclusiveAmount: [
287
- {
288
- _: invoice.legalMonetaryTotal.taxInclusiveAmount,
289
- currencyID: invoice.invoiceCurrencyCode,
290
- },
291
- ],
292
- PayableAmount: [
293
- {
294
- _: invoice.legalMonetaryTotal.payableAmount,
295
- currencyID: invoice.invoiceCurrencyCode,
296
- },
297
- ],
298
- },
299
- ],
300
-
301
- // === INVOICE LINES ===
302
- InvoiceLine: invoice.invoiceLineItems.map((item, index) => ({
303
- ID: [{ _: (index + 1).toString() }],
304
-
305
- // Item Information
306
- Item: [
307
- {
308
- CommodityClassification: [
309
- {
310
- ItemClassificationCode: [
311
- {
312
- _: item.itemClassificationCode,
313
- listID: 'CLASS',
314
- },
315
- ],
316
- },
317
- ],
318
- Description: [{ _: item.itemDescription }],
319
- },
320
- ],
321
-
322
- ItemPriceExtension: [
323
- {
324
- Amount: [
325
- {
326
- _: item.totalTaxableAmountPerLine,
327
- currencyID: invoice.invoiceCurrencyCode,
328
- },
329
- ],
330
- },
331
- ],
332
-
333
- LineExtensionAmount: [
334
- {
335
- _: item.totalTaxableAmountPerLine,
336
- currencyID: invoice.invoiceCurrencyCode,
337
- },
338
- ],
339
-
340
- // Price Information
341
- Price: [
342
- {
343
- PriceAmount: [
344
- {
345
- _: item.unitPrice,
346
- currencyID: invoice.invoiceCurrencyCode,
347
- },
348
- ],
349
- },
350
- ],
351
-
352
- // Tax Information for line
353
- TaxTotal: [
354
- {
355
- TaxAmount: [
356
- {
357
- _: item.taxAmount,
358
- currencyID: invoice.invoiceCurrencyCode,
359
- },
360
- ],
361
- TaxSubtotal: [
362
- {
363
- TaxableAmount: [
364
- {
365
- _: item.totalTaxableAmountPerLine,
366
- currencyID: invoice.invoiceCurrencyCode,
367
- },
368
- ],
369
- TaxAmount: [
370
- {
371
- _: item.taxAmount,
372
- currencyID: invoice.invoiceCurrencyCode,
373
- },
374
- ],
375
- TaxCategory: [
376
- {
377
- ID: [{ _: item.taxType }],
378
- TaxScheme: [
379
- {
380
- ID: [
381
- {
382
- _: 'OTH',
383
- schemeAgencyID: '6',
384
- schemeID: 'UN/ECE 5153',
385
- },
386
- ],
387
- },
388
- ],
389
- },
390
- ],
391
- },
392
- ],
393
- },
394
- ],
395
- })),
396
-
397
- // === TAX EXCHANGE RATE (mandatory where applicable) ===
398
- TaxExchangeRate: invoice.currencyExchangeRate
399
- ? [
400
- {
401
- SourceCurrencyCode: [
402
- {
403
- _: invoice.invoiceCurrencyCode,
404
- },
405
- ],
406
- TargetCurrencyCode: [
407
- {
408
- _: 'MYR',
409
- },
410
- ],
411
- CalculationRate: [
412
- {
413
- _: invoice.currencyExchangeRate,
414
- },
415
- ],
416
- },
417
- ]
418
- : undefined,
419
- }
420
- }
421
-
422
- /**
423
- * Generates the complete UBL document structure with namespace declarations
424
- */
425
- export const generateCleanUBLDocument = (
426
- invoices: InvoiceV1_1[],
427
- ): UBLDocument => {
428
- return {
429
- _D: 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2',
430
- _A: 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2',
431
- _B: 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2',
432
- Invoice: invoices.map(generateCleanInvoiceObject),
433
- }
434
- }
435
-
436
- /**
437
- * Step 2: Calculate Document Digest
438
- * FIXED: Remove UBLExtensions and Signature before hashing (DS322)
439
- * Based on working implementation pattern
440
- */
441
- export const calculateDocumentDigest = (invoices: InvoiceV1_1[]): string => {
442
- // Generate clean UBL document structure
443
- const cleanDocument = generateCleanUBLDocument(invoices)
444
-
445
- // CRITICAL FIX: Remove UBLExtensions and Signature from each invoice before hashing
446
- const documentForHashing = JSON.parse(JSON.stringify(cleanDocument))
447
- if (documentForHashing.Invoice && Array.isArray(documentForHashing.Invoice)) {
448
- documentForHashing.Invoice.forEach((invoice: any) => {
449
- delete invoice.UBLExtensions
450
- delete invoice.Signature
451
- })
452
- }
453
-
454
- // Convert to string for hashing (no canonicalization - use direct JSON.stringify)
455
- const documentString = JSON.stringify(documentForHashing)
456
-
457
- // Calculate SHA-256 hash
458
- const hash = crypto.createHash('sha256')
459
- hash.update(documentString, 'utf8')
460
-
461
- // Return as Base64 (DocDigest)
462
- return hash.digest('base64')
463
- }
464
-
465
- /**
466
- * Step 4: Calculate Certificate Digest
467
- * Enhanced to handle certificate content properly
468
- */
469
- export const calculateCertificateDigest = (certificatePem: string): string => {
470
- // Extract certificate content (Base64 without PEM headers/footers)
471
- const certificateContent = certificatePem
472
- .replace(/-----BEGIN CERTIFICATE-----/g, '')
473
- .replace(/-----END CERTIFICATE-----/g, '')
474
- .replace(/\s+/g, '') // Remove all whitespace
475
-
476
- // Convert Base64 to binary
477
- const certificateBinary = Buffer.from(certificateContent, 'base64')
478
-
479
- // Calculate SHA-256 hash of binary content
480
- const hash = crypto.createHash('sha256')
481
- hash.update(certificateBinary)
482
-
483
- // Return as Base64
484
- return hash.digest('base64')
485
- }
486
-
487
- /**
488
- * Enhanced certificate info extraction with better error handling
489
- * FIXED: Normalize issuer name format to match MyInvois expectations (DS326)
490
- */
491
- export const extractCertificateInfo = (
492
- certificatePem: string,
493
- ): {
494
- issuerName: string
495
- serialNumber: string
496
- subjectName: string
497
- } => {
498
- try {
499
- const cert = new X509Certificate(certificatePem)
500
-
501
- // Extract serial number and convert to decimal string
502
- const serialNumberHex = cert.serialNumber
503
-
504
- // ENHANCED: Normalize distinguished name format (DS326)
505
- // Ensures MyInvois portal compatibility for X509IssuerName matching
506
- const normalizeDistinguishedName = (dn: string): string => {
507
- // Convert multi-line format to comma-separated RFC2253 format
508
- const normalized = dn
509
- .split('\n')
510
- .map(line => line.trim())
511
- .filter(line => line.length > 0)
512
- .join(', ')
513
-
514
- // MyInvois-specific normalization to prevent DS326 errors
515
- return normalized
516
- .replace(/\s*=\s*/g, '=') // Remove spaces around equals (CRITICAL for portal)
517
- .replace(/,\s+/g, ', ') // Ensure single space after commas
518
- .replace(/\r/g, '') // Remove any carriage returns
519
- .replace(/\s{2,}/g, ' ') // Replace multiple spaces with single space
520
- .trim() // Remove leading/trailing whitespace
521
- }
522
-
523
- // Enhanced serial number formatting
524
- const formatSerialNumber = (serialHex: string): string => {
525
- // Convert hex to decimal and ensure it's a string
526
- const decimal = BigInt('0x' + serialHex).toString()
527
- return decimal
528
- }
529
-
530
- return {
531
- issuerName: normalizeDistinguishedName(cert.issuer),
532
- serialNumber: formatSerialNumber(serialNumberHex),
533
- subjectName: normalizeDistinguishedName(cert.subject),
534
- }
535
- } catch (error: unknown) {
536
- throw new Error(
537
- `Failed to extract certificate info: ${error instanceof Error ? error.message : String(error)}`,
538
- )
539
- }
540
- }
541
-
542
- /**
543
- * Step 5: Create SignedProperties with enhanced structure
544
- * FIXED: Simplified structure to match MyInvois expectations (DS320)
545
- * Following MyInvois JSON signature specification exactly
546
- */
547
- export const createSignedProperties = (
548
- certificateDigest: string,
549
- signingTime: string,
550
- issuerName: string,
551
- serialNumber: string,
552
- ): SignedPropertiesObject => {
553
- return {
554
- SignedProperties: [
555
- {
556
- Id: 'id-xades-signed-props',
557
- SignedSignatureProperties: [
558
- {
559
- SigningTime: [{ _: signingTime }],
560
- SigningCertificate: [
561
- {
562
- Cert: [
563
- {
564
- CertDigest: [
565
- {
566
- DigestMethod: [
567
- {
568
- Algorithm:
569
- 'http://www.w3.org/2001/04/xmlenc#sha256',
570
- },
571
- ],
572
- DigestValue: [{ _: certificateDigest }],
573
- },
574
- ],
575
- IssuerSerial: [
576
- {
577
- X509IssuerName: [{ _: issuerName }],
578
- X509SerialNumber: [{ _: serialNumber }],
579
- },
580
- ],
581
- },
582
- ],
583
- },
584
- ],
585
- },
586
- ],
587
- },
588
- ],
589
- }
590
- }
591
-
592
- /**
593
- * Step 6: Calculate SignedProperties Digest
594
- * FIXED: Add Target wrapper and use direct JSON stringify (DS320)
595
- * Based on working implementation pattern
596
- */
597
- export const calculateSignedPropertiesDigest = (
598
- signedProperties: SignedPropertiesObject,
599
- ): string => {
600
- // CRITICAL FIX: Wrap with Target as per working implementation
601
- const signedPropertiesWithTarget = {
602
- Target: 'signature',
603
- SignedProperties: signedProperties.SignedProperties,
604
- }
605
-
606
- // Convert to string for hashing (no canonicalization - use direct JSON.stringify)
607
- const signedPropertiesString = JSON.stringify(signedPropertiesWithTarget)
608
-
609
- // Calculate SHA-256 hash
610
- const hash = crypto.createHash('sha256')
611
- hash.update(signedPropertiesString, 'utf8')
612
-
613
- // Return as Base64 (PropsDigest)
614
- return hash.digest('base64')
615
- }
616
-
617
- /**
618
- * Step 3: Create SignedInfo and calculate signature
619
- * Enhanced with better structure and signature generation
620
- */
621
- export const createSignedInfoAndSign = (
622
- docDigest: string,
623
- propsDigest: string,
624
- privateKeyPem: string,
625
- ): { signedInfo: SignedInfoObject; signatureValue: string } => {
626
- // Create SignedInfo structure following specification exactly
627
- const signedInfo = {
628
- CanonicalizationMethod: [
629
- {
630
- _: '',
631
- Algorithm: 'http://www.w3.org/2006/12/xml-c14n11',
632
- },
633
- ],
634
- SignatureMethod: [
635
- {
636
- _: '',
637
- Algorithm: 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256',
638
- },
639
- ],
640
- Reference: [
641
- {
642
- Id: 'id-doc-signed-data',
643
- Type: '',
644
- URI: '',
645
- DigestMethod: [
646
- {
647
- _: '',
648
- Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256',
649
- },
650
- ],
651
- DigestValue: [{ _: docDigest }],
652
- },
653
- {
654
- Id: 'id-xades-signed-props',
655
- Type: 'http://uri.etsi.org/01903/v1.3.2#SignedProperties',
656
- URI: '#id-xades-signed-props',
657
- DigestMethod: [
658
- {
659
- _: '',
660
- Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256',
661
- },
662
- ],
663
- DigestValue: [{ _: propsDigest }],
664
- },
665
- ],
666
- }
667
-
668
- // FIXED: Use direct JSON.stringify instead of canonicalization (DS333)
669
- // Based on working implementation pattern
670
- const signedInfoString = JSON.stringify(signedInfo)
671
-
672
- // Sign with RSA-SHA256 directly (RSA-SHA256 handles hashing internally)
673
- // FIXED: Removed double-hashing bug that was causing DS333 errors
674
- try {
675
- const signer = crypto.createSign('RSA-SHA256')
676
- signer.update(signedInfoString, 'utf8')
677
- const signatureValue = signer.sign(privateKeyPem, 'base64')
678
-
679
- return { signedInfo, signatureValue }
680
- } catch (error) {
681
- throw new Error(
682
- `Signature generation failed: ${error instanceof Error ? error.message : String(error)}`,
683
- )
684
- }
685
- }
686
-
687
- /**
688
- * Complete document generation with signatures
689
- * Follows the complete MyInvois JSON signature creation process (Steps 1-7)
690
- */
691
- export const generateCompleteDocument = (
692
- invoices: InvoiceV1_1[],
693
- signingCredentials: SigningCredentials,
694
- ): CompleteInvoice => {
695
- try {
696
- // Step 1: Generate clean document (done in calculateDocumentDigest)
697
- // Step 2: Calculate document digest
698
- const docDigest = calculateDocumentDigest(invoices)
699
-
700
- // Generate signing time in proper ISO format
701
- const signingTime = new Date().toISOString()
702
-
703
- // Extract certificate information (enhanced)
704
- const certInfo = extractCertificateInfo(signingCredentials.certificatePem)
705
-
706
- // Step 4: Calculate certificate digest
707
- const certificateDigest = calculateCertificateDigest(
708
- signingCredentials.certificatePem,
709
- )
710
-
711
- // Step 5: Create SignedProperties using extracted cert info
712
- const signedProperties = createSignedProperties(
713
- certificateDigest,
714
- signingTime,
715
- certInfo.issuerName,
716
- certInfo.serialNumber,
717
- )
718
-
719
- // Step 6: Calculate SignedProperties digest
720
- const propsDigest = calculateSignedPropertiesDigest(signedProperties)
721
-
722
- // Step 3: Create SignedInfo and generate signature
723
- const { signedInfo, signatureValue } = createSignedInfoAndSign(
724
- docDigest,
725
- propsDigest,
726
- signingCredentials.privateKeyPem,
727
- )
728
-
729
- // Extract certificate content (Base64 without PEM headers)
730
- const certificate = signingCredentials.certificatePem
731
- .replace(/-----BEGIN CERTIFICATE-----/g, '')
732
- .replace(/-----END CERTIFICATE-----/g, '')
733
- .replace(/\s+/g, '')
734
-
735
- // Step 7: Create final signed document
736
- const signedInvoices = invoices.map(invoice => {
737
- const cleanInvoice = generateCleanInvoiceObject(invoice)
738
-
739
- return {
740
- ...cleanInvoice,
741
-
742
- // Add UBLExtensions with complete signature structure
743
- UBLExtensions: [
744
- {
745
- UBLExtension: [
746
- {
747
- ExtensionURI: [
748
- {
749
- _: 'urn:oasis:names:specification:ubl:dsig:enveloped:xades',
750
- },
751
- ],
752
- ExtensionContent: [
753
- {
754
- UBLDocumentSignatures: [
755
- {
756
- SignatureInformation: [
757
- {
758
- ID: [
759
- {
760
- _: 'urn:oasis:names:specification:ubl:signature:1',
761
- },
762
- ],
763
- ReferencedSignatureID: [
764
- {
765
- _: 'urn:oasis:names:specification:ubl:signature:Invoice',
766
- },
767
- ],
768
- Signature: [
769
- {
770
- Id: 'signature',
771
- Object: [
772
- {
773
- QualifyingProperties: [
774
- {
775
- Target: 'signature',
776
- SignedProperties:
777
- signedProperties.SignedProperties,
778
- },
779
- ],
780
- },
781
- ],
782
- KeyInfo: [
783
- {
784
- X509Data: [
785
- {
786
- X509Certificate: [{ _: certificate }],
787
- X509SubjectName: [
788
- { _: certInfo.subjectName },
789
- ],
790
- X509IssuerSerial: [
791
- {
792
- X509IssuerName: [
793
- {
794
- _: certInfo.issuerName,
795
- },
796
- ],
797
- X509SerialNumber: [
798
- {
799
- _: certInfo.serialNumber,
800
- },
801
- ],
802
- },
803
- ],
804
- },
805
- ],
806
- },
807
- ],
808
- SignatureValue: [{ _: signatureValue }],
809
- SignedInfo: [signedInfo],
810
- },
811
- ],
812
- },
813
- ],
814
- },
815
- ],
816
- },
817
- ],
818
- },
819
- ],
820
- },
821
- ],
822
-
823
- // Add simple Signature reference
824
- Signature: [
825
- {
826
- ID: [
827
- {
828
- _: 'urn:oasis:names:specification:ubl:signature:Invoice',
829
- },
830
- ],
831
- SignatureMethod: [
832
- {
833
- _: 'urn:oasis:names:specification:ubl:dsig:enveloped:xades',
834
- },
835
- ],
836
- },
837
- ],
838
- }
839
- })
840
-
841
- return {
842
- _D: 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2',
843
- _A: 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2',
844
- _B: 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2',
845
- Invoice: signedInvoices,
846
- }
847
- } catch (error) {
848
- throw new Error(
849
- `Document generation failed: ${error instanceof Error ? error.message : String(error)}`,
850
- )
851
- }
852
- }