@adnsistemas/pdf-lib 1.18.0 → 2.4.2

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 (1543) hide show
  1. package/README.md +71 -36
  2. package/cjs/api/PDFDocument.d.ts +44 -11
  3. package/cjs/api/PDFDocument.d.ts.map +1 -1
  4. package/cjs/api/PDFDocument.js +599 -609
  5. package/cjs/api/PDFDocument.js.map +1 -1
  6. package/cjs/api/PDFDocumentOptions.d.ts +4 -2
  7. package/cjs/api/PDFDocumentOptions.d.ts.map +1 -1
  8. package/cjs/api/PDFEmbeddedFile.d.ts +9 -4
  9. package/cjs/api/PDFEmbeddedFile.d.ts.map +1 -1
  10. package/cjs/api/PDFEmbeddedFile.js +54 -59
  11. package/cjs/api/PDFEmbeddedFile.js.map +1 -1
  12. package/cjs/api/PDFEmbeddedPage.d.ts +3 -3
  13. package/cjs/api/PDFEmbeddedPage.d.ts.map +1 -1
  14. package/cjs/api/PDFEmbeddedPage.js +35 -46
  15. package/cjs/api/PDFEmbeddedPage.js.map +1 -1
  16. package/cjs/api/PDFFont.d.ts +4 -4
  17. package/cjs/api/PDFFont.d.ts.map +1 -1
  18. package/cjs/api/PDFFont.js +47 -57
  19. package/cjs/api/PDFFont.js.map +1 -1
  20. package/cjs/api/PDFImage.d.ts +4 -4
  21. package/cjs/api/PDFImage.d.ts.map +1 -1
  22. package/cjs/api/PDFImage.js +50 -62
  23. package/cjs/api/PDFImage.js.map +1 -1
  24. package/cjs/api/PDFJavaScript.d.ts +4 -4
  25. package/cjs/api/PDFJavaScript.d.ts.map +1 -1
  26. package/cjs/api/PDFJavaScript.js +38 -50
  27. package/cjs/api/PDFJavaScript.js.map +1 -1
  28. package/cjs/api/PDFPage.d.ts +33 -9
  29. package/cjs/api/PDFPage.d.ts.map +1 -1
  30. package/cjs/api/PDFPage.js +478 -431
  31. package/cjs/api/PDFPage.js.map +1 -1
  32. package/cjs/api/PDFPageOptions.d.ts +35 -12
  33. package/cjs/api/PDFPageOptions.d.ts.map +1 -1
  34. package/cjs/api/PDFPageOptions.js.map +1 -1
  35. package/cjs/api/PDFSvg.d.ts +7 -0
  36. package/cjs/api/PDFSvg.d.ts.map +1 -0
  37. package/cjs/api/PDFSvg.js +10 -0
  38. package/cjs/api/PDFSvg.js.map +1 -0
  39. package/cjs/api/colors.d.ts +6 -2
  40. package/cjs/api/colors.d.ts.map +1 -1
  41. package/cjs/api/colors.js +51 -43
  42. package/cjs/api/colors.js.map +1 -1
  43. package/cjs/api/errors.js +73 -130
  44. package/cjs/api/errors.js.map +1 -1
  45. package/cjs/api/form/PDFButton.d.ts +8 -8
  46. package/cjs/api/form/PDFButton.d.ts.map +1 -1
  47. package/cjs/api/form/PDFButton.js +68 -72
  48. package/cjs/api/form/PDFButton.js.map +1 -1
  49. package/cjs/api/form/PDFCheckBox.d.ts +5 -5
  50. package/cjs/api/form/PDFCheckBox.d.ts.map +1 -1
  51. package/cjs/api/form/PDFCheckBox.js +64 -69
  52. package/cjs/api/form/PDFCheckBox.js.map +1 -1
  53. package/cjs/api/form/PDFDropdown.d.ts +6 -6
  54. package/cjs/api/form/PDFDropdown.d.ts.map +1 -1
  55. package/cjs/api/form/PDFDropdown.js +126 -132
  56. package/cjs/api/form/PDFDropdown.js.map +1 -1
  57. package/cjs/api/form/PDFField.d.ts +7 -7
  58. package/cjs/api/form/PDFField.d.ts.map +1 -1
  59. package/cjs/api/form/PDFField.js +118 -123
  60. package/cjs/api/form/PDFField.js.map +1 -1
  61. package/cjs/api/form/PDFForm.d.ts +11 -11
  62. package/cjs/api/form/PDFForm.d.ts.map +1 -1
  63. package/cjs/api/form/PDFForm.js +226 -221
  64. package/cjs/api/form/PDFForm.js.map +1 -1
  65. package/cjs/api/form/PDFOptionList.d.ts +6 -6
  66. package/cjs/api/form/PDFOptionList.d.ts.map +1 -1
  67. package/cjs/api/form/PDFOptionList.js +115 -121
  68. package/cjs/api/form/PDFOptionList.js.map +1 -1
  69. package/cjs/api/form/PDFRadioGroup.d.ts +5 -5
  70. package/cjs/api/form/PDFRadioGroup.d.ts.map +1 -1
  71. package/cjs/api/form/PDFRadioGroup.js +98 -101
  72. package/cjs/api/form/PDFRadioGroup.js.map +1 -1
  73. package/cjs/api/form/PDFSignature.d.ts +3 -3
  74. package/cjs/api/form/PDFSignature.d.ts.map +1 -1
  75. package/cjs/api/form/PDFSignature.js +25 -28
  76. package/cjs/api/form/PDFSignature.js.map +1 -1
  77. package/cjs/api/form/PDFTextField.d.ts +8 -8
  78. package/cjs/api/form/PDFTextField.d.ts.map +1 -1
  79. package/cjs/api/form/PDFTextField.js +136 -141
  80. package/cjs/api/form/PDFTextField.js.map +1 -1
  81. package/cjs/api/form/appearances.d.ts +21 -21
  82. package/cjs/api/form/appearances.d.ts.map +1 -1
  83. package/cjs/api/form/appearances.js +257 -219
  84. package/cjs/api/form/appearances.js.map +1 -1
  85. package/cjs/api/form/index.d.ts +10 -10
  86. package/cjs/api/form/index.d.ts.map +1 -1
  87. package/cjs/api/form/index.js +11 -10
  88. package/cjs/api/form/index.js.map +1 -1
  89. package/cjs/api/image/index.d.ts +1 -1
  90. package/cjs/api/image/index.d.ts.map +1 -1
  91. package/cjs/api/image/index.js +1 -1
  92. package/cjs/api/image/index.js.map +1 -1
  93. package/cjs/api/index.d.ts +22 -21
  94. package/cjs/api/index.d.ts.map +1 -1
  95. package/cjs/api/index.js +30 -27
  96. package/cjs/api/index.js.map +1 -1
  97. package/cjs/api/objects.d.ts +1 -1
  98. package/cjs/api/objects.d.ts.map +1 -1
  99. package/cjs/api/objects.js +7 -10
  100. package/cjs/api/objects.js.map +1 -1
  101. package/cjs/api/operations.d.ts +27 -13
  102. package/cjs/api/operations.d.ts.map +1 -1
  103. package/cjs/api/operations.js +373 -363
  104. package/cjs/api/operations.js.map +1 -1
  105. package/cjs/api/operators.d.ts +6 -1
  106. package/cjs/api/operators.d.ts.map +1 -1
  107. package/cjs/api/operators.js +169 -183
  108. package/cjs/api/operators.js.map +1 -1
  109. package/cjs/api/rotations.d.ts +2 -2
  110. package/cjs/api/rotations.d.ts.map +1 -1
  111. package/cjs/api/rotations.js +30 -30
  112. package/cjs/api/rotations.js.map +1 -1
  113. package/cjs/api/snapshot/DefaultDocumentSnapshot.d.ts +1 -1
  114. package/cjs/api/snapshot/DefaultDocumentSnapshot.d.ts.map +1 -1
  115. package/cjs/api/snapshot/DefaultDocumentSnapshot.js +13 -14
  116. package/cjs/api/snapshot/DefaultDocumentSnapshot.js.map +1 -1
  117. package/cjs/api/snapshot/DocumentSnapshot.d.ts +1 -1
  118. package/cjs/api/snapshot/DocumentSnapshot.d.ts.map +1 -1
  119. package/cjs/api/snapshot/IncrementalDocumentSnapshot.d.ts +1 -1
  120. package/cjs/api/snapshot/IncrementalDocumentSnapshot.d.ts.map +1 -1
  121. package/cjs/api/snapshot/IncrementalDocumentSnapshot.js +17 -22
  122. package/cjs/api/snapshot/IncrementalDocumentSnapshot.js.map +1 -1
  123. package/cjs/api/snapshot/index.js +1 -1
  124. package/cjs/api/svg.d.ts +76 -0
  125. package/cjs/api/svg.d.ts.map +1 -0
  126. package/cjs/api/svg.js +749 -0
  127. package/cjs/api/svg.js.map +1 -0
  128. package/cjs/api/svgPath.d.ts +1 -1
  129. package/cjs/api/svgPath.d.ts.map +1 -1
  130. package/cjs/api/svgPath.js +115 -118
  131. package/cjs/api/svgPath.js.map +1 -1
  132. package/cjs/api/text/index.d.ts +2 -2
  133. package/cjs/api/text/index.d.ts.map +1 -1
  134. package/cjs/api/text/index.js +1 -1
  135. package/cjs/api/text/index.js.map +1 -1
  136. package/cjs/api/text/layout.d.ts +3 -3
  137. package/cjs/api/text/layout.d.ts.map +1 -1
  138. package/cjs/api/text/layout.js +87 -88
  139. package/cjs/api/text/layout.js.map +1 -1
  140. package/cjs/core/PDFContext.d.ts +39 -19
  141. package/cjs/core/PDFContext.d.ts.map +1 -1
  142. package/cjs/core/PDFContext.js +131 -103
  143. package/cjs/core/PDFContext.js.map +1 -1
  144. package/cjs/core/PDFObjectCopier.d.ts +2 -2
  145. package/cjs/core/PDFObjectCopier.d.ts.map +1 -1
  146. package/cjs/core/PDFObjectCopier.js +58 -62
  147. package/cjs/core/PDFObjectCopier.js.map +1 -1
  148. package/cjs/core/acroform/PDFAcroButton.d.ts +7 -7
  149. package/cjs/core/acroform/PDFAcroButton.d.ts.map +1 -1
  150. package/cjs/core/acroform/PDFAcroButton.js +42 -47
  151. package/cjs/core/acroform/PDFAcroButton.js.map +1 -1
  152. package/cjs/core/acroform/PDFAcroCheckBox.d.ts +5 -5
  153. package/cjs/core/acroform/PDFAcroCheckBox.d.ts.map +1 -1
  154. package/cjs/core/acroform/PDFAcroCheckBox.js +28 -35
  155. package/cjs/core/acroform/PDFAcroCheckBox.js.map +1 -1
  156. package/cjs/core/acroform/PDFAcroChoice.d.ts +4 -4
  157. package/cjs/core/acroform/PDFAcroChoice.d.ts.map +1 -1
  158. package/cjs/core/acroform/PDFAcroChoice.js +47 -60
  159. package/cjs/core/acroform/PDFAcroChoice.js.map +1 -1
  160. package/cjs/core/acroform/PDFAcroComboBox.d.ts +4 -4
  161. package/cjs/core/acroform/PDFAcroComboBox.d.ts.map +1 -1
  162. package/cjs/core/acroform/PDFAcroComboBox.js +15 -22
  163. package/cjs/core/acroform/PDFAcroComboBox.js.map +1 -1
  164. package/cjs/core/acroform/PDFAcroField.d.ts +8 -8
  165. package/cjs/core/acroform/PDFAcroField.d.ts.map +1 -1
  166. package/cjs/core/acroform/PDFAcroField.js +80 -81
  167. package/cjs/core/acroform/PDFAcroField.js.map +1 -1
  168. package/cjs/core/acroform/PDFAcroForm.d.ts +5 -5
  169. package/cjs/core/acroform/PDFAcroForm.d.ts.map +1 -1
  170. package/cjs/core/acroform/PDFAcroForm.js +46 -47
  171. package/cjs/core/acroform/PDFAcroForm.js.map +1 -1
  172. package/cjs/core/acroform/PDFAcroListBox.d.ts +4 -4
  173. package/cjs/core/acroform/PDFAcroListBox.d.ts.map +1 -1
  174. package/cjs/core/acroform/PDFAcroListBox.js +13 -20
  175. package/cjs/core/acroform/PDFAcroListBox.js.map +1 -1
  176. package/cjs/core/acroform/PDFAcroNonTerminal.d.ts +4 -4
  177. package/cjs/core/acroform/PDFAcroNonTerminal.d.ts.map +1 -1
  178. package/cjs/core/acroform/PDFAcroNonTerminal.js +18 -25
  179. package/cjs/core/acroform/PDFAcroNonTerminal.js.map +1 -1
  180. package/cjs/core/acroform/PDFAcroPushButton.d.ts +4 -4
  181. package/cjs/core/acroform/PDFAcroPushButton.d.ts.map +1 -1
  182. package/cjs/core/acroform/PDFAcroPushButton.js +15 -22
  183. package/cjs/core/acroform/PDFAcroPushButton.js.map +1 -1
  184. package/cjs/core/acroform/PDFAcroRadioButton.d.ts +5 -5
  185. package/cjs/core/acroform/PDFAcroRadioButton.d.ts.map +1 -1
  186. package/cjs/core/acroform/PDFAcroRadioButton.js +33 -40
  187. package/cjs/core/acroform/PDFAcroRadioButton.js.map +1 -1
  188. package/cjs/core/acroform/PDFAcroSignature.d.ts +3 -3
  189. package/cjs/core/acroform/PDFAcroSignature.d.ts.map +1 -1
  190. package/cjs/core/acroform/PDFAcroSignature.js +5 -12
  191. package/cjs/core/acroform/PDFAcroSignature.js.map +1 -1
  192. package/cjs/core/acroform/PDFAcroTerminal.d.ts +5 -5
  193. package/cjs/core/acroform/PDFAcroTerminal.d.ts.map +1 -1
  194. package/cjs/core/acroform/PDFAcroTerminal.js +28 -35
  195. package/cjs/core/acroform/PDFAcroTerminal.js.map +1 -1
  196. package/cjs/core/acroform/PDFAcroText.d.ts +7 -7
  197. package/cjs/core/acroform/PDFAcroText.d.ts.map +1 -1
  198. package/cjs/core/acroform/PDFAcroText.js +40 -45
  199. package/cjs/core/acroform/PDFAcroText.js.map +1 -1
  200. package/cjs/core/acroform/flags.js +1 -1
  201. package/cjs/core/acroform/flags.js.map +1 -1
  202. package/cjs/core/acroform/index.d.ts +15 -15
  203. package/cjs/core/acroform/index.d.ts.map +1 -1
  204. package/cjs/core/acroform/index.js +15 -14
  205. package/cjs/core/acroform/index.js.map +1 -1
  206. package/cjs/core/acroform/utils.d.ts +5 -5
  207. package/cjs/core/acroform/utils.d.ts.map +1 -1
  208. package/cjs/core/acroform/utils.js +48 -48
  209. package/cjs/core/acroform/utils.js.map +1 -1
  210. package/cjs/core/annotation/AppearanceCharacteristics.d.ts +5 -5
  211. package/cjs/core/annotation/AppearanceCharacteristics.d.ts.map +1 -1
  212. package/cjs/core/annotation/AppearanceCharacteristics.js +61 -64
  213. package/cjs/core/annotation/AppearanceCharacteristics.js.map +1 -1
  214. package/cjs/core/annotation/BorderStyle.d.ts +2 -2
  215. package/cjs/core/annotation/BorderStyle.d.ts.map +1 -1
  216. package/cjs/core/annotation/BorderStyle.js +15 -16
  217. package/cjs/core/annotation/BorderStyle.js.map +1 -1
  218. package/cjs/core/annotation/PDFAnnotation.d.ts +6 -6
  219. package/cjs/core/annotation/PDFAnnotation.d.ts.map +1 -1
  220. package/cjs/core/annotation/PDFAnnotation.js +76 -77
  221. package/cjs/core/annotation/PDFAnnotation.js.map +1 -1
  222. package/cjs/core/annotation/PDFWidgetAnnotation.d.ts +9 -9
  223. package/cjs/core/annotation/PDFWidgetAnnotation.d.ts.map +1 -1
  224. package/cjs/core/annotation/PDFWidgetAnnotation.js +60 -67
  225. package/cjs/core/annotation/PDFWidgetAnnotation.js.map +1 -1
  226. package/cjs/core/annotation/flags.js +1 -1
  227. package/cjs/core/annotation/flags.js.map +1 -1
  228. package/cjs/core/annotation/index.d.ts +4 -4
  229. package/cjs/core/annotation/index.d.ts.map +1 -1
  230. package/cjs/core/annotation/index.js +5 -4
  231. package/cjs/core/annotation/index.js.map +1 -1
  232. package/cjs/core/crypto.d.ts +96 -0
  233. package/cjs/core/crypto.d.ts.map +1 -0
  234. package/cjs/core/crypto.js +1623 -0
  235. package/cjs/core/crypto.js.map +1 -0
  236. package/cjs/core/document/PDFCrossRefSection.d.ts +1 -1
  237. package/cjs/core/document/PDFCrossRefSection.d.ts.map +1 -1
  238. package/cjs/core/document/PDFCrossRefSection.js +62 -65
  239. package/cjs/core/document/PDFCrossRefSection.js.map +1 -1
  240. package/cjs/core/document/PDFHeader.d.ts +1 -0
  241. package/cjs/core/document/PDFHeader.d.ts.map +1 -1
  242. package/cjs/core/document/PDFHeader.js +21 -21
  243. package/cjs/core/document/PDFHeader.js.map +1 -1
  244. package/cjs/core/document/PDFTrailer.js +16 -19
  245. package/cjs/core/document/PDFTrailer.js.map +1 -1
  246. package/cjs/core/document/PDFTrailerDict.d.ts +1 -1
  247. package/cjs/core/document/PDFTrailerDict.d.ts.map +1 -1
  248. package/cjs/core/document/PDFTrailerDict.js +14 -15
  249. package/cjs/core/document/PDFTrailerDict.js.map +1 -1
  250. package/cjs/core/embedders/CMap.d.ts +2 -2
  251. package/cjs/core/embedders/CMap.d.ts.map +1 -1
  252. package/cjs/core/embedders/CMap.js +41 -28
  253. package/cjs/core/embedders/CMap.js.map +1 -1
  254. package/cjs/core/embedders/CustomFontEmbedder.d.ts +5 -5
  255. package/cjs/core/embedders/CustomFontEmbedder.d.ts.map +1 -1
  256. package/cjs/core/embedders/CustomFontEmbedder.js +133 -178
  257. package/cjs/core/embedders/CustomFontEmbedder.js.map +1 -1
  258. package/cjs/core/embedders/CustomFontSubsetEmbedder.d.ts +3 -3
  259. package/cjs/core/embedders/CustomFontSubsetEmbedder.d.ts.map +1 -1
  260. package/cjs/core/embedders/CustomFontSubsetEmbedder.js +38 -49
  261. package/cjs/core/embedders/CustomFontSubsetEmbedder.js.map +1 -1
  262. package/cjs/core/embedders/FileEmbedder.d.ts +3 -2
  263. package/cjs/core/embedders/FileEmbedder.d.ts.map +1 -1
  264. package/cjs/core/embedders/FileEmbedder.js +44 -48
  265. package/cjs/core/embedders/FileEmbedder.js.map +1 -1
  266. package/cjs/core/embedders/FontFlags.d.ts +1 -1
  267. package/cjs/core/embedders/FontFlags.d.ts.map +1 -1
  268. package/cjs/core/embedders/FontFlags.js +7 -6
  269. package/cjs/core/embedders/FontFlags.js.map +1 -1
  270. package/cjs/core/embedders/JavaScriptEmbedder.d.ts +2 -2
  271. package/cjs/core/embedders/JavaScriptEmbedder.d.ts.map +1 -1
  272. package/cjs/core/embedders/JavaScriptEmbedder.js +22 -27
  273. package/cjs/core/embedders/JavaScriptEmbedder.js.map +1 -1
  274. package/cjs/core/embedders/JpegEmbedder.d.ts +2 -2
  275. package/cjs/core/embedders/JpegEmbedder.d.ts.map +1 -1
  276. package/cjs/core/embedders/JpegEmbedder.js +66 -73
  277. package/cjs/core/embedders/JpegEmbedder.js.map +1 -1
  278. package/cjs/core/embedders/PDFPageEmbedder.d.ts +4 -4
  279. package/cjs/core/embedders/PDFPageEmbedder.d.ts.map +1 -1
  280. package/cjs/core/embedders/PDFPageEmbedder.js +64 -65
  281. package/cjs/core/embedders/PDFPageEmbedder.js.map +1 -1
  282. package/cjs/core/embedders/PngEmbedder.d.ts +2 -2
  283. package/cjs/core/embedders/PngEmbedder.d.ts.map +1 -1
  284. package/cjs/core/embedders/PngEmbedder.js +33 -41
  285. package/cjs/core/embedders/PngEmbedder.js.map +1 -1
  286. package/cjs/core/embedders/StandardFontEmbedder.d.ts +4 -4
  287. package/cjs/core/embedders/StandardFontEmbedder.d.ts.map +1 -1
  288. package/cjs/core/embedders/StandardFontEmbedder.js +53 -51
  289. package/cjs/core/embedders/StandardFontEmbedder.js.map +1 -1
  290. package/cjs/core/errors.d.ts +1 -1
  291. package/cjs/core/errors.d.ts.map +1 -1
  292. package/cjs/core/errors.js +147 -260
  293. package/cjs/core/errors.js.map +1 -1
  294. package/cjs/core/index.d.ts +48 -47
  295. package/cjs/core/index.d.ts.map +1 -1
  296. package/cjs/core/index.js +47 -44
  297. package/cjs/core/index.js.map +1 -1
  298. package/cjs/core/interactive/ViewerPreferences.d.ts +8 -8
  299. package/cjs/core/interactive/ViewerPreferences.d.ts.map +1 -1
  300. package/cjs/core/interactive/ViewerPreferences.js +135 -138
  301. package/cjs/core/interactive/ViewerPreferences.js.map +1 -1
  302. package/cjs/core/objects/PDFArray.d.ts +12 -12
  303. package/cjs/core/objects/PDFArray.d.ts.map +1 -1
  304. package/cjs/core/objects/PDFArray.js +72 -81
  305. package/cjs/core/objects/PDFArray.js.map +1 -1
  306. package/cjs/core/objects/PDFBool.d.ts +1 -1
  307. package/cjs/core/objects/PDFBool.d.ts.map +1 -1
  308. package/cjs/core/objects/PDFBool.js +22 -26
  309. package/cjs/core/objects/PDFBool.js.map +1 -1
  310. package/cjs/core/objects/PDFDict.d.ts +13 -12
  311. package/cjs/core/objects/PDFDict.d.ts.map +1 -1
  312. package/cjs/core/objects/PDFDict.js +76 -88
  313. package/cjs/core/objects/PDFDict.js.map +1 -1
  314. package/cjs/core/objects/PDFHexString.d.ts +2 -1
  315. package/cjs/core/objects/PDFHexString.d.ts.map +1 -1
  316. package/cjs/core/objects/PDFHexString.js +50 -52
  317. package/cjs/core/objects/PDFHexString.js.map +1 -1
  318. package/cjs/core/objects/PDFInvalidObject.d.ts +1 -1
  319. package/cjs/core/objects/PDFInvalidObject.d.ts.map +1 -1
  320. package/cjs/core/objects/PDFInvalidObject.js +19 -22
  321. package/cjs/core/objects/PDFInvalidObject.js.map +1 -1
  322. package/cjs/core/objects/PDFName.d.ts +1 -1
  323. package/cjs/core/objects/PDFName.d.ts.map +1 -1
  324. package/cjs/core/objects/PDFName.js +84 -92
  325. package/cjs/core/objects/PDFName.js.map +1 -1
  326. package/cjs/core/objects/PDFNull.d.ts +1 -1
  327. package/cjs/core/objects/PDFNull.d.ts.map +1 -1
  328. package/cjs/core/objects/PDFNull.js +15 -20
  329. package/cjs/core/objects/PDFNull.js.map +1 -1
  330. package/cjs/core/objects/PDFNumber.d.ts +1 -1
  331. package/cjs/core/objects/PDFNumber.d.ts.map +1 -1
  332. package/cjs/core/objects/PDFNumber.js +23 -26
  333. package/cjs/core/objects/PDFNumber.js.map +1 -1
  334. package/cjs/core/objects/PDFObject.d.ts +1 -1
  335. package/cjs/core/objects/PDFObject.d.ts.map +1 -1
  336. package/cjs/core/objects/PDFObject.js +13 -16
  337. package/cjs/core/objects/PDFObject.js.map +1 -1
  338. package/cjs/core/objects/PDFRawStream.d.ts +8 -5
  339. package/cjs/core/objects/PDFRawStream.d.ts.map +1 -1
  340. package/cjs/core/objects/PDFRawStream.js +24 -25
  341. package/cjs/core/objects/PDFRawStream.js.map +1 -1
  342. package/cjs/core/objects/PDFRef.d.ts +1 -1
  343. package/cjs/core/objects/PDFRef.d.ts.map +1 -1
  344. package/cjs/core/objects/PDFRef.js +31 -36
  345. package/cjs/core/objects/PDFRef.js.map +1 -1
  346. package/cjs/core/objects/PDFStream.d.ts +4 -3
  347. package/cjs/core/objects/PDFStream.d.ts.map +1 -1
  348. package/cjs/core/objects/PDFStream.js +35 -35
  349. package/cjs/core/objects/PDFStream.js.map +1 -1
  350. package/cjs/core/objects/PDFString.d.ts +1 -1
  351. package/cjs/core/objects/PDFString.d.ts.map +1 -1
  352. package/cjs/core/objects/PDFString.js +55 -58
  353. package/cjs/core/objects/PDFString.js.map +1 -1
  354. package/cjs/core/operators/PDFOperator.d.ts +9 -9
  355. package/cjs/core/operators/PDFOperator.d.ts.map +1 -1
  356. package/cjs/core/operators/PDFOperator.js +29 -32
  357. package/cjs/core/operators/PDFOperator.js.map +1 -1
  358. package/cjs/core/parser/BaseParser.d.ts +1 -1
  359. package/cjs/core/parser/BaseParser.d.ts.map +1 -1
  360. package/cjs/core/parser/BaseParser.js +40 -42
  361. package/cjs/core/parser/BaseParser.js.map +1 -1
  362. package/cjs/core/parser/ByteStream.d.ts +1 -1
  363. package/cjs/core/parser/ByteStream.d.ts.map +1 -1
  364. package/cjs/core/parser/ByteStream.js +30 -33
  365. package/cjs/core/parser/ByteStream.js.map +1 -1
  366. package/cjs/core/parser/PDFObjectParser.d.ts +23 -21
  367. package/cjs/core/parser/PDFObjectParser.d.ts.map +1 -1
  368. package/cjs/core/parser/PDFObjectParser.js +96 -88
  369. package/cjs/core/parser/PDFObjectParser.js.map +1 -1
  370. package/cjs/core/parser/PDFObjectStreamParser.d.ts +3 -3
  371. package/cjs/core/parser/PDFObjectStreamParser.d.ts.map +1 -1
  372. package/cjs/core/parser/PDFObjectStreamParser.js +42 -60
  373. package/cjs/core/parser/PDFObjectStreamParser.js.map +1 -1
  374. package/cjs/core/parser/PDFParser.d.ts +6 -4
  375. package/cjs/core/parser/PDFParser.d.ts.map +1 -1
  376. package/cjs/core/parser/PDFParser.js +169 -217
  377. package/cjs/core/parser/PDFParser.js.map +1 -1
  378. package/cjs/core/parser/PDFXRefStreamParser.d.ts +2 -2
  379. package/cjs/core/parser/PDFXRefStreamParser.d.ts.map +1 -1
  380. package/cjs/core/parser/PDFXRefStreamParser.js +38 -41
  381. package/cjs/core/parser/PDFXRefStreamParser.js.map +1 -1
  382. package/cjs/core/security/PDFSecurity.d.ts +75 -0
  383. package/cjs/core/security/PDFSecurity.d.ts.map +1 -0
  384. package/cjs/core/security/PDFSecurity.js +406 -0
  385. package/cjs/core/security/PDFSecurity.js.map +1 -0
  386. package/cjs/core/streams/Ascii85Stream.d.ts +2 -2
  387. package/cjs/core/streams/Ascii85Stream.d.ts.map +1 -1
  388. package/cjs/core/streams/Ascii85Stream.js +21 -26
  389. package/cjs/core/streams/Ascii85Stream.js.map +1 -1
  390. package/cjs/core/streams/AsciiHexStream.d.ts +2 -2
  391. package/cjs/core/streams/AsciiHexStream.d.ts.map +1 -1
  392. package/cjs/core/streams/AsciiHexStream.js +19 -22
  393. package/cjs/core/streams/AsciiHexStream.js.map +1 -1
  394. package/cjs/core/streams/DecodeStream.d.ts +1 -1
  395. package/cjs/core/streams/DecodeStream.d.ts.map +1 -1
  396. package/cjs/core/streams/DecodeStream.js +54 -61
  397. package/cjs/core/streams/DecodeStream.js.map +1 -1
  398. package/cjs/core/streams/DecryptStream.d.ts +13 -0
  399. package/cjs/core/streams/DecryptStream.d.ts.map +1 -0
  400. package/cjs/core/streams/DecryptStream.js +39 -0
  401. package/cjs/core/streams/DecryptStream.js.map +1 -0
  402. package/cjs/core/streams/FlateStream.d.ts +2 -2
  403. package/cjs/core/streams/FlateStream.d.ts.map +1 -1
  404. package/cjs/core/streams/FlateStream.js +82 -84
  405. package/cjs/core/streams/FlateStream.js.map +1 -1
  406. package/cjs/core/streams/LZWStream.d.ts +3 -3
  407. package/cjs/core/streams/LZWStream.d.ts.map +1 -1
  408. package/cjs/core/streams/LZWStream.js +42 -45
  409. package/cjs/core/streams/LZWStream.js.map +1 -1
  410. package/cjs/core/streams/RunLengthStream.d.ts +2 -2
  411. package/cjs/core/streams/RunLengthStream.d.ts.map +1 -1
  412. package/cjs/core/streams/RunLengthStream.js +16 -19
  413. package/cjs/core/streams/RunLengthStream.js.map +1 -1
  414. package/cjs/core/streams/Stream.js +45 -56
  415. package/cjs/core/streams/Stream.js.map +1 -1
  416. package/cjs/core/streams/decode.d.ts +3 -3
  417. package/cjs/core/streams/decode.d.ts.map +1 -1
  418. package/cjs/core/streams/decode.js +25 -22
  419. package/cjs/core/streams/decode.js.map +1 -1
  420. package/cjs/core/structures/PDFCatalog.d.ts +5 -5
  421. package/cjs/core/structures/PDFCatalog.d.ts.map +1 -1
  422. package/cjs/core/structures/PDFCatalog.js +40 -47
  423. package/cjs/core/structures/PDFCatalog.js.map +1 -1
  424. package/cjs/core/structures/PDFContentStream.d.ts +4 -4
  425. package/cjs/core/structures/PDFContentStream.d.ts.map +1 -1
  426. package/cjs/core/structures/PDFContentStream.js +31 -43
  427. package/cjs/core/structures/PDFContentStream.js.map +1 -1
  428. package/cjs/core/structures/PDFCrossRefStream.d.ts +6 -6
  429. package/cjs/core/structures/PDFCrossRefStream.d.ts.map +1 -1
  430. package/cjs/core/structures/PDFCrossRefStream.js +92 -100
  431. package/cjs/core/structures/PDFCrossRefStream.js.map +1 -1
  432. package/cjs/core/structures/PDFFlateStream.d.ts +5 -4
  433. package/cjs/core/structures/PDFFlateStream.d.ts.map +1 -1
  434. package/cjs/core/structures/PDFFlateStream.js +24 -24
  435. package/cjs/core/structures/PDFFlateStream.js.map +1 -1
  436. package/cjs/core/structures/PDFObjectStream.d.ts +5 -5
  437. package/cjs/core/structures/PDFObjectStream.d.ts.map +1 -1
  438. package/cjs/core/structures/PDFObjectStream.js +49 -56
  439. package/cjs/core/structures/PDFObjectStream.js.map +1 -1
  440. package/cjs/core/structures/PDFPageLeaf.d.ts +9 -9
  441. package/cjs/core/structures/PDFPageLeaf.d.ts.map +1 -1
  442. package/cjs/core/structures/PDFPageLeaf.js +126 -133
  443. package/cjs/core/structures/PDFPageLeaf.js.map +1 -1
  444. package/cjs/core/structures/PDFPageTree.d.ts +8 -8
  445. package/cjs/core/structures/PDFPageTree.d.ts.map +1 -1
  446. package/cjs/core/structures/PDFPageTree.js +67 -75
  447. package/cjs/core/structures/PDFPageTree.js.map +1 -1
  448. package/cjs/core/syntax/Delimiters.js +2 -2
  449. package/cjs/core/syntax/Delimiters.js.map +1 -1
  450. package/cjs/core/syntax/Irregular.js +5 -5
  451. package/cjs/core/syntax/Irregular.js.map +1 -1
  452. package/cjs/core/syntax/Keywords.d.ts +1 -1
  453. package/cjs/core/syntax/Keywords.d.ts.map +1 -1
  454. package/cjs/core/syntax/Keywords.js +14 -14
  455. package/cjs/core/syntax/Keywords.js.map +1 -1
  456. package/cjs/core/syntax/Numeric.js +3 -3
  457. package/cjs/core/syntax/Numeric.js.map +1 -1
  458. package/cjs/core/syntax/Whitespace.js +2 -2
  459. package/cjs/core/syntax/Whitespace.js.map +1 -1
  460. package/cjs/core/writers/PDFStreamWriter.d.ts +7 -7
  461. package/cjs/core/writers/PDFStreamWriter.d.ts.map +1 -1
  462. package/cjs/core/writers/PDFStreamWriter.js +102 -126
  463. package/cjs/core/writers/PDFStreamWriter.js.map +1 -1
  464. package/cjs/core/writers/PDFWriter.d.ts +15 -10
  465. package/cjs/core/writers/PDFWriter.d.ts.map +1 -1
  466. package/cjs/core/writers/PDFWriter.js +116 -142
  467. package/cjs/core/writers/PDFWriter.js.map +1 -1
  468. package/cjs/index.d.ts +4 -4
  469. package/cjs/index.d.ts.map +1 -1
  470. package/cjs/index.js +5 -5
  471. package/cjs/index.js.map +1 -1
  472. package/cjs/types/index.d.ts +25 -1
  473. package/cjs/types/index.d.ts.map +1 -1
  474. package/cjs/types/matrix.d.ts +8 -1
  475. package/cjs/types/matrix.d.ts.map +1 -1
  476. package/cjs/utils/Cache.js +10 -11
  477. package/cjs/utils/Cache.js.map +1 -1
  478. package/cjs/utils/arrays.d.ts +3 -1
  479. package/cjs/utils/arrays.d.ts.map +1 -1
  480. package/cjs/utils/arrays.js +97 -64
  481. package/cjs/utils/arrays.js.map +1 -1
  482. package/cjs/utils/async.d.ts.map +1 -1
  483. package/cjs/utils/async.js +4 -5
  484. package/cjs/utils/async.js.map +1 -1
  485. package/cjs/utils/base64.d.ts.map +1 -1
  486. package/cjs/utils/base64.js +29 -26
  487. package/cjs/utils/base64.js.map +1 -1
  488. package/cjs/utils/elements/Arc.d.ts +23 -0
  489. package/cjs/utils/elements/Arc.d.ts.map +1 -0
  490. package/cjs/utils/elements/Arc.js +78 -0
  491. package/cjs/utils/elements/Arc.js.map +1 -0
  492. package/cjs/utils/elements/Circle.d.ts +15 -0
  493. package/cjs/utils/elements/Circle.d.ts.map +1 -0
  494. package/cjs/utils/elements/Circle.js +41 -0
  495. package/cjs/utils/elements/Circle.js.map +1 -0
  496. package/cjs/utils/elements/Ellipse.d.ts +21 -0
  497. package/cjs/utils/elements/Ellipse.d.ts.map +1 -0
  498. package/cjs/utils/elements/Ellipse.js +91 -0
  499. package/cjs/utils/elements/Ellipse.js.map +1 -0
  500. package/cjs/utils/elements/GraphElement.d.ts +7 -0
  501. package/cjs/utils/elements/GraphElement.d.ts.map +1 -0
  502. package/cjs/utils/elements/GraphElement.js +11 -0
  503. package/cjs/utils/elements/GraphElement.js.map +1 -0
  504. package/cjs/utils/elements/Line.d.ts +24 -0
  505. package/cjs/utils/elements/Line.d.ts.map +1 -0
  506. package/cjs/utils/elements/Line.js +72 -0
  507. package/cjs/utils/elements/Line.js.map +1 -0
  508. package/cjs/utils/elements/Plot.d.ts +12 -0
  509. package/cjs/utils/elements/Plot.d.ts.map +1 -0
  510. package/cjs/utils/elements/Plot.js +46 -0
  511. package/cjs/utils/elements/Plot.js.map +1 -0
  512. package/cjs/utils/elements/Point.d.ts +19 -0
  513. package/cjs/utils/elements/Point.d.ts.map +1 -0
  514. package/cjs/utils/elements/Point.js +32 -0
  515. package/cjs/utils/elements/Point.js.map +1 -0
  516. package/cjs/utils/elements/Rectangle.d.ts +22 -0
  517. package/cjs/utils/elements/Rectangle.d.ts.map +1 -0
  518. package/cjs/utils/elements/Rectangle.js +58 -0
  519. package/cjs/utils/elements/Rectangle.js.map +1 -0
  520. package/cjs/utils/elements/Segment.d.ts +20 -0
  521. package/cjs/utils/elements/Segment.d.ts.map +1 -0
  522. package/cjs/utils/elements/Segment.js +80 -0
  523. package/cjs/utils/elements/Segment.js.map +1 -0
  524. package/cjs/utils/elements/index.d.ts +10 -0
  525. package/cjs/utils/elements/index.d.ts.map +1 -0
  526. package/cjs/utils/elements/index.js +25 -0
  527. package/cjs/utils/elements/index.js.map +1 -0
  528. package/cjs/utils/errors.js +2 -1
  529. package/cjs/utils/errors.js.map +1 -1
  530. package/cjs/utils/index.d.ts +11 -11
  531. package/cjs/utils/index.d.ts.map +1 -1
  532. package/cjs/utils/index.js +3 -2
  533. package/cjs/utils/index.js.map +1 -1
  534. package/cjs/utils/intersections.d.ts +10 -0
  535. package/cjs/utils/intersections.d.ts.map +1 -0
  536. package/cjs/utils/intersections.js +253 -0
  537. package/cjs/utils/intersections.js.map +1 -0
  538. package/cjs/utils/maths.d.ts +46 -0
  539. package/cjs/utils/maths.d.ts.map +1 -0
  540. package/cjs/utils/maths.js +89 -0
  541. package/cjs/utils/maths.js.map +1 -0
  542. package/cjs/utils/numbers.js +12 -9
  543. package/cjs/utils/numbers.js.map +1 -1
  544. package/cjs/utils/objects.js +8 -7
  545. package/cjs/utils/objects.js.map +1 -1
  546. package/cjs/utils/pdfDocEncoding.js +52 -51
  547. package/cjs/utils/pdfDocEncoding.js.map +1 -1
  548. package/cjs/utils/png.js +22 -23
  549. package/cjs/utils/png.js.map +1 -1
  550. package/cjs/utils/rng.js +7 -8
  551. package/cjs/utils/rng.js.map +1 -1
  552. package/cjs/utils/strings.d.ts +1 -0
  553. package/cjs/utils/strings.d.ts.map +1 -1
  554. package/cjs/utils/strings.js +88 -70
  555. package/cjs/utils/strings.js.map +1 -1
  556. package/cjs/utils/unicode.js +51 -64
  557. package/cjs/utils/unicode.js.map +1 -1
  558. package/cjs/utils/validators.d.ts +2 -2
  559. package/cjs/utils/validators.d.ts.map +1 -1
  560. package/cjs/utils/validators.js +84 -67
  561. package/cjs/utils/validators.js.map +1 -1
  562. package/dist/pdf-lib.esm.js +16231 -31855
  563. package/dist/pdf-lib.esm.js.map +1 -1
  564. package/dist/pdf-lib.esm.min.js +16 -13
  565. package/dist/pdf-lib.esm.min.js.map +1 -1
  566. package/dist/pdf-lib.js +16370 -32042
  567. package/dist/pdf-lib.js.map +1 -1
  568. package/dist/pdf-lib.min.js +16 -13
  569. package/dist/pdf-lib.min.js.map +1 -1
  570. package/es/api/Embeddable.js +1 -0
  571. package/es/api/PDFDocument.d.ts +44 -11
  572. package/es/api/PDFDocument.d.ts.map +1 -1
  573. package/es/api/PDFDocument.js +580 -591
  574. package/es/api/PDFDocument.js.map +1 -1
  575. package/es/api/PDFDocumentOptions.d.ts +4 -2
  576. package/es/api/PDFDocumentOptions.d.ts.map +1 -1
  577. package/es/api/PDFEmbeddedFile.d.ts +9 -4
  578. package/es/api/PDFEmbeddedFile.d.ts.map +1 -1
  579. package/es/api/PDFEmbeddedFile.js +54 -60
  580. package/es/api/PDFEmbeddedFile.js.map +1 -1
  581. package/es/api/PDFEmbeddedPage.d.ts +3 -3
  582. package/es/api/PDFEmbeddedPage.d.ts.map +1 -1
  583. package/es/api/PDFEmbeddedPage.js +31 -43
  584. package/es/api/PDFEmbeddedPage.js.map +1 -1
  585. package/es/api/PDFFont.d.ts +4 -4
  586. package/es/api/PDFFont.d.ts.map +1 -1
  587. package/es/api/PDFFont.js +38 -49
  588. package/es/api/PDFFont.js.map +1 -1
  589. package/es/api/PDFImage.d.ts +4 -4
  590. package/es/api/PDFImage.d.ts.map +1 -1
  591. package/es/api/PDFImage.js +44 -57
  592. package/es/api/PDFImage.js.map +1 -1
  593. package/es/api/PDFJavaScript.d.ts +4 -4
  594. package/es/api/PDFJavaScript.d.ts.map +1 -1
  595. package/es/api/PDFJavaScript.js +38 -51
  596. package/es/api/PDFJavaScript.js.map +1 -1
  597. package/es/api/PDFPage.d.ts +33 -9
  598. package/es/api/PDFPage.d.ts.map +1 -1
  599. package/es/api/PDFPage.js +311 -266
  600. package/es/api/PDFPage.js.map +1 -1
  601. package/es/api/PDFPageOptions.d.ts +35 -12
  602. package/es/api/PDFPageOptions.d.ts.map +1 -1
  603. package/es/api/PDFPageOptions.js.map +1 -1
  604. package/es/api/PDFSvg.d.ts +7 -0
  605. package/es/api/PDFSvg.d.ts.map +1 -0
  606. package/es/api/PDFSvg.js +7 -0
  607. package/es/api/PDFSvg.js.map +1 -0
  608. package/es/api/colors.d.ts +6 -2
  609. package/es/api/colors.d.ts.map +1 -1
  610. package/es/api/colors.js +33 -34
  611. package/es/api/colors.js.map +1 -1
  612. package/es/api/errors.js +73 -144
  613. package/es/api/errors.js.map +1 -1
  614. package/es/api/form/PDFButton.d.ts +8 -8
  615. package/es/api/form/PDFButton.d.ts.map +1 -1
  616. package/es/api/form/PDFButton.js +56 -62
  617. package/es/api/form/PDFButton.js.map +1 -1
  618. package/es/api/form/PDFCheckBox.d.ts +5 -5
  619. package/es/api/form/PDFCheckBox.d.ts.map +1 -1
  620. package/es/api/form/PDFCheckBox.js +55 -62
  621. package/es/api/form/PDFCheckBox.js.map +1 -1
  622. package/es/api/form/PDFDropdown.d.ts +6 -6
  623. package/es/api/form/PDFDropdown.d.ts.map +1 -1
  624. package/es/api/form/PDFDropdown.js +110 -118
  625. package/es/api/form/PDFDropdown.js.map +1 -1
  626. package/es/api/form/PDFField.d.ts +7 -7
  627. package/es/api/form/PDFField.d.ts.map +1 -1
  628. package/es/api/form/PDFField.js +98 -106
  629. package/es/api/form/PDFField.js.map +1 -1
  630. package/es/api/form/PDFForm.d.ts +11 -11
  631. package/es/api/form/PDFForm.d.ts.map +1 -1
  632. package/es/api/form/PDFForm.js +203 -200
  633. package/es/api/form/PDFForm.js.map +1 -1
  634. package/es/api/form/PDFOptionList.d.ts +6 -6
  635. package/es/api/form/PDFOptionList.d.ts.map +1 -1
  636. package/es/api/form/PDFOptionList.js +98 -106
  637. package/es/api/form/PDFOptionList.js.map +1 -1
  638. package/es/api/form/PDFRadioGroup.d.ts +5 -5
  639. package/es/api/form/PDFRadioGroup.d.ts.map +1 -1
  640. package/es/api/form/PDFRadioGroup.js +86 -91
  641. package/es/api/form/PDFRadioGroup.js.map +1 -1
  642. package/es/api/form/PDFSignature.d.ts +3 -3
  643. package/es/api/form/PDFSignature.d.ts.map +1 -1
  644. package/es/api/form/PDFSignature.js +23 -28
  645. package/es/api/form/PDFSignature.js.map +1 -1
  646. package/es/api/form/PDFTextField.d.ts +8 -8
  647. package/es/api/form/PDFTextField.d.ts.map +1 -1
  648. package/es/api/form/PDFTextField.js +121 -128
  649. package/es/api/form/PDFTextField.js.map +1 -1
  650. package/es/api/form/appearances.d.ts +21 -21
  651. package/es/api/form/appearances.d.ts.map +1 -1
  652. package/es/api/form/appearances.js +245 -214
  653. package/es/api/form/appearances.js.map +1 -1
  654. package/es/api/form/index.d.ts +10 -10
  655. package/es/api/form/index.d.ts.map +1 -1
  656. package/es/api/form/index.js +10 -10
  657. package/es/api/form/index.js.map +1 -1
  658. package/es/api/image/index.d.ts +1 -1
  659. package/es/api/image/index.d.ts.map +1 -1
  660. package/es/api/image/index.js +1 -1
  661. package/es/api/image/index.js.map +1 -1
  662. package/es/api/index.d.ts +22 -21
  663. package/es/api/index.d.ts.map +1 -1
  664. package/es/api/index.js +21 -20
  665. package/es/api/index.js.map +1 -1
  666. package/es/api/objects.d.ts +1 -1
  667. package/es/api/objects.d.ts.map +1 -1
  668. package/es/api/objects.js +4 -10
  669. package/es/api/objects.js.map +1 -1
  670. package/es/api/operations.d.ts +27 -13
  671. package/es/api/operations.d.ts.map +1 -1
  672. package/es/api/operations.js +266 -272
  673. package/es/api/operations.js.map +1 -1
  674. package/es/api/operators.d.ts +6 -1
  675. package/es/api/operators.d.ts.map +1 -1
  676. package/es/api/operators.js +114 -182
  677. package/es/api/operators.js.map +1 -1
  678. package/es/api/rotations.d.ts +2 -2
  679. package/es/api/rotations.d.ts.map +1 -1
  680. package/es/api/rotations.js +19 -28
  681. package/es/api/rotations.js.map +1 -1
  682. package/es/api/sizes.js +1 -1
  683. package/es/api/sizes.js.map +1 -1
  684. package/es/api/snapshot/DefaultDocumentSnapshot.d.ts +1 -1
  685. package/es/api/snapshot/DefaultDocumentSnapshot.d.ts.map +1 -1
  686. package/es/api/snapshot/DefaultDocumentSnapshot.js +14 -16
  687. package/es/api/snapshot/DefaultDocumentSnapshot.js.map +1 -1
  688. package/es/api/snapshot/DocumentSnapshot.d.ts +1 -1
  689. package/es/api/snapshot/DocumentSnapshot.d.ts.map +1 -1
  690. package/es/api/snapshot/DocumentSnapshot.js +1 -0
  691. package/es/api/snapshot/IncrementalDocumentSnapshot.d.ts +1 -1
  692. package/es/api/snapshot/IncrementalDocumentSnapshot.d.ts.map +1 -1
  693. package/es/api/snapshot/IncrementalDocumentSnapshot.js +17 -23
  694. package/es/api/snapshot/IncrementalDocumentSnapshot.js.map +1 -1
  695. package/es/api/snapshot/index.js +3 -3
  696. package/es/api/svg.d.ts +76 -0
  697. package/es/api/svg.d.ts.map +1 -0
  698. package/es/api/svg.js +742 -0
  699. package/es/api/svg.js.map +1 -0
  700. package/es/api/svgPath.d.ts +1 -1
  701. package/es/api/svgPath.d.ts.map +1 -1
  702. package/es/api/svgPath.js +104 -108
  703. package/es/api/svgPath.js.map +1 -1
  704. package/es/api/text/index.d.ts +2 -2
  705. package/es/api/text/index.d.ts.map +1 -1
  706. package/es/api/text/index.js +2 -2
  707. package/es/api/text/index.js.map +1 -1
  708. package/es/api/text/layout.d.ts +3 -3
  709. package/es/api/text/layout.d.ts.map +1 -1
  710. package/es/api/text/layout.js +84 -88
  711. package/es/api/text/layout.js.map +1 -1
  712. package/es/core/PDFContext.d.ts +39 -19
  713. package/es/core/PDFContext.d.ts.map +1 -1
  714. package/es/core/PDFContext.js +128 -101
  715. package/es/core/PDFContext.js.map +1 -1
  716. package/es/core/PDFObjectCopier.d.ts +2 -2
  717. package/es/core/PDFObjectCopier.d.ts.map +1 -1
  718. package/es/core/PDFObjectCopier.js +57 -61
  719. package/es/core/PDFObjectCopier.js.map +1 -1
  720. package/es/core/acroform/PDFAcroButton.d.ts +7 -7
  721. package/es/core/acroform/PDFAcroButton.d.ts.map +1 -1
  722. package/es/core/acroform/PDFAcroButton.js +41 -47
  723. package/es/core/acroform/PDFAcroButton.js.map +1 -1
  724. package/es/core/acroform/PDFAcroCheckBox.d.ts +5 -5
  725. package/es/core/acroform/PDFAcroCheckBox.d.ts.map +1 -1
  726. package/es/core/acroform/PDFAcroCheckBox.js +27 -35
  727. package/es/core/acroform/PDFAcroCheckBox.js.map +1 -1
  728. package/es/core/acroform/PDFAcroChoice.d.ts +4 -4
  729. package/es/core/acroform/PDFAcroChoice.d.ts.map +1 -1
  730. package/es/core/acroform/PDFAcroChoice.js +46 -60
  731. package/es/core/acroform/PDFAcroChoice.js.map +1 -1
  732. package/es/core/acroform/PDFAcroComboBox.d.ts +4 -4
  733. package/es/core/acroform/PDFAcroComboBox.d.ts.map +1 -1
  734. package/es/core/acroform/PDFAcroComboBox.js +14 -22
  735. package/es/core/acroform/PDFAcroComboBox.js.map +1 -1
  736. package/es/core/acroform/PDFAcroField.d.ts +8 -8
  737. package/es/core/acroform/PDFAcroField.d.ts.map +1 -1
  738. package/es/core/acroform/PDFAcroField.js +79 -80
  739. package/es/core/acroform/PDFAcroField.js.map +1 -1
  740. package/es/core/acroform/PDFAcroForm.d.ts +5 -5
  741. package/es/core/acroform/PDFAcroForm.d.ts.map +1 -1
  742. package/es/core/acroform/PDFAcroForm.js +43 -44
  743. package/es/core/acroform/PDFAcroForm.js.map +1 -1
  744. package/es/core/acroform/PDFAcroListBox.d.ts +4 -4
  745. package/es/core/acroform/PDFAcroListBox.d.ts.map +1 -1
  746. package/es/core/acroform/PDFAcroListBox.js +12 -20
  747. package/es/core/acroform/PDFAcroListBox.js.map +1 -1
  748. package/es/core/acroform/PDFAcroNonTerminal.d.ts +4 -4
  749. package/es/core/acroform/PDFAcroNonTerminal.d.ts.map +1 -1
  750. package/es/core/acroform/PDFAcroNonTerminal.js +17 -25
  751. package/es/core/acroform/PDFAcroNonTerminal.js.map +1 -1
  752. package/es/core/acroform/PDFAcroPushButton.d.ts +4 -4
  753. package/es/core/acroform/PDFAcroPushButton.d.ts.map +1 -1
  754. package/es/core/acroform/PDFAcroPushButton.js +14 -22
  755. package/es/core/acroform/PDFAcroPushButton.js.map +1 -1
  756. package/es/core/acroform/PDFAcroRadioButton.d.ts +5 -5
  757. package/es/core/acroform/PDFAcroRadioButton.d.ts.map +1 -1
  758. package/es/core/acroform/PDFAcroRadioButton.js +32 -40
  759. package/es/core/acroform/PDFAcroRadioButton.js.map +1 -1
  760. package/es/core/acroform/PDFAcroSignature.d.ts +3 -3
  761. package/es/core/acroform/PDFAcroSignature.d.ts.map +1 -1
  762. package/es/core/acroform/PDFAcroSignature.js +4 -12
  763. package/es/core/acroform/PDFAcroSignature.js.map +1 -1
  764. package/es/core/acroform/PDFAcroTerminal.d.ts +5 -5
  765. package/es/core/acroform/PDFAcroTerminal.d.ts.map +1 -1
  766. package/es/core/acroform/PDFAcroTerminal.js +27 -35
  767. package/es/core/acroform/PDFAcroTerminal.js.map +1 -1
  768. package/es/core/acroform/PDFAcroText.d.ts +7 -7
  769. package/es/core/acroform/PDFAcroText.d.ts.map +1 -1
  770. package/es/core/acroform/PDFAcroText.js +39 -45
  771. package/es/core/acroform/PDFAcroText.js.map +1 -1
  772. package/es/core/acroform/flags.js +1 -1
  773. package/es/core/acroform/flags.js.map +1 -1
  774. package/es/core/acroform/index.d.ts +15 -15
  775. package/es/core/acroform/index.d.ts.map +1 -1
  776. package/es/core/acroform/index.js +15 -15
  777. package/es/core/acroform/index.js.map +1 -1
  778. package/es/core/acroform/utils.d.ts +5 -5
  779. package/es/core/acroform/utils.d.ts.map +1 -1
  780. package/es/core/acroform/utils.js +44 -46
  781. package/es/core/acroform/utils.js.map +1 -1
  782. package/es/core/annotation/AppearanceCharacteristics.d.ts +5 -5
  783. package/es/core/annotation/AppearanceCharacteristics.d.ts.map +1 -1
  784. package/es/core/annotation/AppearanceCharacteristics.js +60 -63
  785. package/es/core/annotation/AppearanceCharacteristics.js.map +1 -1
  786. package/es/core/annotation/BorderStyle.d.ts +2 -2
  787. package/es/core/annotation/BorderStyle.d.ts.map +1 -1
  788. package/es/core/annotation/BorderStyle.js +14 -15
  789. package/es/core/annotation/BorderStyle.js.map +1 -1
  790. package/es/core/annotation/PDFAnnotation.d.ts +6 -6
  791. package/es/core/annotation/PDFAnnotation.d.ts.map +1 -1
  792. package/es/core/annotation/PDFAnnotation.js +75 -76
  793. package/es/core/annotation/PDFAnnotation.js.map +1 -1
  794. package/es/core/annotation/PDFWidgetAnnotation.d.ts +9 -9
  795. package/es/core/annotation/PDFWidgetAnnotation.d.ts.map +1 -1
  796. package/es/core/annotation/PDFWidgetAnnotation.js +59 -67
  797. package/es/core/annotation/PDFWidgetAnnotation.js.map +1 -1
  798. package/es/core/annotation/flags.js +1 -1
  799. package/es/core/annotation/flags.js.map +1 -1
  800. package/es/core/annotation/index.d.ts +4 -4
  801. package/es/core/annotation/index.d.ts.map +1 -1
  802. package/es/core/annotation/index.js +4 -4
  803. package/es/core/annotation/index.js.map +1 -1
  804. package/es/core/crypto.d.ts +96 -0
  805. package/es/core/crypto.d.ts.map +1 -0
  806. package/es/core/crypto.js +1609 -0
  807. package/es/core/crypto.js.map +1 -0
  808. package/es/core/document/PDFCrossRefSection.d.ts +1 -1
  809. package/es/core/document/PDFCrossRefSection.d.ts.map +1 -1
  810. package/es/core/document/PDFCrossRefSection.js +55 -58
  811. package/es/core/document/PDFCrossRefSection.js.map +1 -1
  812. package/es/core/document/PDFHeader.d.ts +1 -0
  813. package/es/core/document/PDFHeader.d.ts.map +1 -1
  814. package/es/core/document/PDFHeader.js +18 -18
  815. package/es/core/document/PDFHeader.js.map +1 -1
  816. package/es/core/document/PDFTrailer.js +14 -17
  817. package/es/core/document/PDFTrailer.js.map +1 -1
  818. package/es/core/document/PDFTrailerDict.d.ts +1 -1
  819. package/es/core/document/PDFTrailerDict.d.ts.map +1 -1
  820. package/es/core/document/PDFTrailerDict.js +13 -14
  821. package/es/core/document/PDFTrailerDict.js.map +1 -1
  822. package/es/core/embedders/CMap.d.ts +2 -2
  823. package/es/core/embedders/CMap.d.ts.map +1 -1
  824. package/es/core/embedders/CMap.js +38 -26
  825. package/es/core/embedders/CMap.js.map +1 -1
  826. package/es/core/embedders/CustomFontEmbedder.d.ts +5 -5
  827. package/es/core/embedders/CustomFontEmbedder.d.ts.map +1 -1
  828. package/es/core/embedders/CustomFontEmbedder.js +132 -177
  829. package/es/core/embedders/CustomFontEmbedder.js.map +1 -1
  830. package/es/core/embedders/CustomFontSubsetEmbedder.d.ts +3 -3
  831. package/es/core/embedders/CustomFontSubsetEmbedder.d.ts.map +1 -1
  832. package/es/core/embedders/CustomFontSubsetEmbedder.js +37 -48
  833. package/es/core/embedders/CustomFontSubsetEmbedder.js.map +1 -1
  834. package/es/core/embedders/FileEmbedder.d.ts +3 -2
  835. package/es/core/embedders/FileEmbedder.d.ts.map +1 -1
  836. package/es/core/embedders/FileEmbedder.js +44 -48
  837. package/es/core/embedders/FileEmbedder.js.map +1 -1
  838. package/es/core/embedders/FontFlags.d.ts +1 -1
  839. package/es/core/embedders/FontFlags.d.ts.map +1 -1
  840. package/es/core/embedders/FontFlags.js +6 -6
  841. package/es/core/embedders/FontFlags.js.map +1 -1
  842. package/es/core/embedders/JavaScriptEmbedder.d.ts +2 -2
  843. package/es/core/embedders/JavaScriptEmbedder.d.ts.map +1 -1
  844. package/es/core/embedders/JavaScriptEmbedder.js +22 -27
  845. package/es/core/embedders/JavaScriptEmbedder.js.map +1 -1
  846. package/es/core/embedders/JpegEmbedder.d.ts +2 -2
  847. package/es/core/embedders/JpegEmbedder.d.ts.map +1 -1
  848. package/es/core/embedders/JpegEmbedder.js +66 -73
  849. package/es/core/embedders/JpegEmbedder.js.map +1 -1
  850. package/es/core/embedders/PDFPageEmbedder.d.ts +4 -4
  851. package/es/core/embedders/PDFPageEmbedder.d.ts.map +1 -1
  852. package/es/core/embedders/PDFPageEmbedder.js +63 -64
  853. package/es/core/embedders/PDFPageEmbedder.js.map +1 -1
  854. package/es/core/embedders/PngEmbedder.d.ts +2 -2
  855. package/es/core/embedders/PngEmbedder.d.ts.map +1 -1
  856. package/es/core/embedders/PngEmbedder.js +33 -41
  857. package/es/core/embedders/PngEmbedder.js.map +1 -1
  858. package/es/core/embedders/StandardFontEmbedder.d.ts +4 -4
  859. package/es/core/embedders/StandardFontEmbedder.d.ts.map +1 -1
  860. package/es/core/embedders/StandardFontEmbedder.js +50 -48
  861. package/es/core/embedders/StandardFontEmbedder.js.map +1 -1
  862. package/es/core/errors.d.ts +1 -1
  863. package/es/core/errors.d.ts.map +1 -1
  864. package/es/core/errors.js +175 -316
  865. package/es/core/errors.js.map +1 -1
  866. package/es/core/index.d.ts +48 -47
  867. package/es/core/index.d.ts.map +1 -1
  868. package/es/core/index.js +48 -47
  869. package/es/core/index.js.map +1 -1
  870. package/es/core/interactive/ViewerPreferences.d.ts +8 -8
  871. package/es/core/interactive/ViewerPreferences.d.ts.map +1 -1
  872. package/es/core/interactive/ViewerPreferences.js +127 -130
  873. package/es/core/interactive/ViewerPreferences.js.map +1 -1
  874. package/es/core/objects/PDFArray.d.ts +12 -12
  875. package/es/core/objects/PDFArray.d.ts.map +1 -1
  876. package/es/core/objects/PDFArray.js +71 -81
  877. package/es/core/objects/PDFArray.js.map +1 -1
  878. package/es/core/objects/PDFBool.d.ts +1 -1
  879. package/es/core/objects/PDFBool.d.ts.map +1 -1
  880. package/es/core/objects/PDFBool.js +21 -26
  881. package/es/core/objects/PDFBool.js.map +1 -1
  882. package/es/core/objects/PDFDict.d.ts +13 -12
  883. package/es/core/objects/PDFDict.d.ts.map +1 -1
  884. package/es/core/objects/PDFDict.js +75 -88
  885. package/es/core/objects/PDFDict.js.map +1 -1
  886. package/es/core/objects/PDFHexString.d.ts +2 -1
  887. package/es/core/objects/PDFHexString.d.ts.map +1 -1
  888. package/es/core/objects/PDFHexString.js +45 -48
  889. package/es/core/objects/PDFHexString.js.map +1 -1
  890. package/es/core/objects/PDFInvalidObject.d.ts +1 -1
  891. package/es/core/objects/PDFInvalidObject.d.ts.map +1 -1
  892. package/es/core/objects/PDFInvalidObject.js +18 -22
  893. package/es/core/objects/PDFInvalidObject.js.map +1 -1
  894. package/es/core/objects/PDFName.d.ts +1 -1
  895. package/es/core/objects/PDFName.d.ts.map +1 -1
  896. package/es/core/objects/PDFName.js +83 -92
  897. package/es/core/objects/PDFName.js.map +1 -1
  898. package/es/core/objects/PDFNull.d.ts +1 -1
  899. package/es/core/objects/PDFNull.d.ts.map +1 -1
  900. package/es/core/objects/PDFNull.js +14 -20
  901. package/es/core/objects/PDFNull.js.map +1 -1
  902. package/es/core/objects/PDFNumber.d.ts +1 -1
  903. package/es/core/objects/PDFNumber.d.ts.map +1 -1
  904. package/es/core/objects/PDFNumber.js +22 -26
  905. package/es/core/objects/PDFNumber.js.map +1 -1
  906. package/es/core/objects/PDFObject.d.ts +1 -1
  907. package/es/core/objects/PDFObject.d.ts.map +1 -1
  908. package/es/core/objects/PDFObject.js +13 -16
  909. package/es/core/objects/PDFObject.js.map +1 -1
  910. package/es/core/objects/PDFRawStream.d.ts +8 -5
  911. package/es/core/objects/PDFRawStream.d.ts.map +1 -1
  912. package/es/core/objects/PDFRawStream.js +22 -24
  913. package/es/core/objects/PDFRawStream.js.map +1 -1
  914. package/es/core/objects/PDFRef.d.ts +1 -1
  915. package/es/core/objects/PDFRef.d.ts.map +1 -1
  916. package/es/core/objects/PDFRef.js +30 -36
  917. package/es/core/objects/PDFRef.js.map +1 -1
  918. package/es/core/objects/PDFStream.d.ts +4 -3
  919. package/es/core/objects/PDFStream.d.ts.map +1 -1
  920. package/es/core/objects/PDFStream.js +34 -35
  921. package/es/core/objects/PDFStream.js.map +1 -1
  922. package/es/core/objects/PDFString.d.ts +1 -1
  923. package/es/core/objects/PDFString.d.ts.map +1 -1
  924. package/es/core/objects/PDFString.js +50 -54
  925. package/es/core/objects/PDFString.js.map +1 -1
  926. package/es/core/operators/PDFOperator.d.ts +9 -9
  927. package/es/core/operators/PDFOperator.d.ts.map +1 -1
  928. package/es/core/operators/PDFOperator.js +26 -29
  929. package/es/core/operators/PDFOperator.js.map +1 -1
  930. package/es/core/parser/BaseParser.d.ts +1 -1
  931. package/es/core/parser/BaseParser.d.ts.map +1 -1
  932. package/es/core/parser/BaseParser.js +36 -38
  933. package/es/core/parser/BaseParser.js.map +1 -1
  934. package/es/core/parser/ByteStream.d.ts +1 -1
  935. package/es/core/parser/ByteStream.d.ts.map +1 -1
  936. package/es/core/parser/ByteStream.js +29 -32
  937. package/es/core/parser/ByteStream.js.map +1 -1
  938. package/es/core/parser/PDFObjectParser.d.ts +23 -21
  939. package/es/core/parser/PDFObjectParser.d.ts.map +1 -1
  940. package/es/core/parser/PDFObjectParser.js +92 -85
  941. package/es/core/parser/PDFObjectParser.js.map +1 -1
  942. package/es/core/parser/PDFObjectStreamParser.d.ts +3 -3
  943. package/es/core/parser/PDFObjectStreamParser.d.ts.map +1 -1
  944. package/es/core/parser/PDFObjectStreamParser.js +42 -60
  945. package/es/core/parser/PDFObjectStreamParser.js.map +1 -1
  946. package/es/core/parser/PDFParser.d.ts +6 -4
  947. package/es/core/parser/PDFParser.d.ts.map +1 -1
  948. package/es/core/parser/PDFParser.js +169 -217
  949. package/es/core/parser/PDFParser.js.map +1 -1
  950. package/es/core/parser/PDFXRefStreamParser.d.ts +2 -2
  951. package/es/core/parser/PDFXRefStreamParser.d.ts.map +1 -1
  952. package/es/core/parser/PDFXRefStreamParser.js +37 -40
  953. package/es/core/parser/PDFXRefStreamParser.js.map +1 -1
  954. package/es/core/security/PDFSecurity.d.ts +75 -0
  955. package/es/core/security/PDFSecurity.d.ts.map +1 -0
  956. package/es/core/security/PDFSecurity.js +403 -0
  957. package/es/core/security/PDFSecurity.js.map +1 -0
  958. package/es/core/streams/Ascii85Stream.d.ts +2 -2
  959. package/es/core/streams/Ascii85Stream.d.ts.map +1 -1
  960. package/es/core/streams/Ascii85Stream.js +20 -26
  961. package/es/core/streams/Ascii85Stream.js.map +1 -1
  962. package/es/core/streams/AsciiHexStream.d.ts +2 -2
  963. package/es/core/streams/AsciiHexStream.d.ts.map +1 -1
  964. package/es/core/streams/AsciiHexStream.js +18 -22
  965. package/es/core/streams/AsciiHexStream.js.map +1 -1
  966. package/es/core/streams/DecodeStream.d.ts +1 -1
  967. package/es/core/streams/DecodeStream.d.ts.map +1 -1
  968. package/es/core/streams/DecodeStream.js +53 -60
  969. package/es/core/streams/DecodeStream.js.map +1 -1
  970. package/es/core/streams/DecryptStream.d.ts +13 -0
  971. package/es/core/streams/DecryptStream.d.ts.map +1 -0
  972. package/es/core/streams/DecryptStream.js +36 -0
  973. package/es/core/streams/DecryptStream.js.map +1 -0
  974. package/es/core/streams/FlateStream.d.ts +2 -2
  975. package/es/core/streams/FlateStream.d.ts.map +1 -1
  976. package/es/core/streams/FlateStream.js +81 -84
  977. package/es/core/streams/FlateStream.js.map +1 -1
  978. package/es/core/streams/LZWStream.d.ts +3 -3
  979. package/es/core/streams/LZWStream.d.ts.map +1 -1
  980. package/es/core/streams/LZWStream.js +41 -45
  981. package/es/core/streams/LZWStream.js.map +1 -1
  982. package/es/core/streams/RunLengthStream.d.ts +2 -2
  983. package/es/core/streams/RunLengthStream.d.ts.map +1 -1
  984. package/es/core/streams/RunLengthStream.js +15 -19
  985. package/es/core/streams/RunLengthStream.js.map +1 -1
  986. package/es/core/streams/Stream.js +45 -56
  987. package/es/core/streams/Stream.js.map +1 -1
  988. package/es/core/streams/decode.d.ts +3 -3
  989. package/es/core/streams/decode.d.ts.map +1 -1
  990. package/es/core/streams/decode.js +23 -21
  991. package/es/core/streams/decode.js.map +1 -1
  992. package/es/core/structures/PDFCatalog.d.ts +5 -5
  993. package/es/core/structures/PDFCatalog.d.ts.map +1 -1
  994. package/es/core/structures/PDFCatalog.js +39 -47
  995. package/es/core/structures/PDFCatalog.js.map +1 -1
  996. package/es/core/structures/PDFContentStream.d.ts +4 -4
  997. package/es/core/structures/PDFContentStream.d.ts.map +1 -1
  998. package/es/core/structures/PDFContentStream.js +30 -43
  999. package/es/core/structures/PDFContentStream.js.map +1 -1
  1000. package/es/core/structures/PDFCrossRefStream.d.ts +6 -6
  1001. package/es/core/structures/PDFCrossRefStream.d.ts.map +1 -1
  1002. package/es/core/structures/PDFCrossRefStream.js +91 -100
  1003. package/es/core/structures/PDFCrossRefStream.js.map +1 -1
  1004. package/es/core/structures/PDFFlateStream.d.ts +5 -4
  1005. package/es/core/structures/PDFFlateStream.d.ts.map +1 -1
  1006. package/es/core/structures/PDFFlateStream.js +22 -23
  1007. package/es/core/structures/PDFFlateStream.js.map +1 -1
  1008. package/es/core/structures/PDFObjectStream.d.ts +5 -5
  1009. package/es/core/structures/PDFObjectStream.d.ts.map +1 -1
  1010. package/es/core/structures/PDFObjectStream.js +46 -54
  1011. package/es/core/structures/PDFObjectStream.js.map +1 -1
  1012. package/es/core/structures/PDFPageLeaf.d.ts +9 -9
  1013. package/es/core/structures/PDFPageLeaf.d.ts.map +1 -1
  1014. package/es/core/structures/PDFPageLeaf.js +125 -133
  1015. package/es/core/structures/PDFPageLeaf.js.map +1 -1
  1016. package/es/core/structures/PDFPageTree.d.ts +8 -8
  1017. package/es/core/structures/PDFPageTree.d.ts.map +1 -1
  1018. package/es/core/structures/PDFPageTree.js +66 -75
  1019. package/es/core/structures/PDFPageTree.js.map +1 -1
  1020. package/es/core/syntax/Delimiters.js +2 -2
  1021. package/es/core/syntax/Delimiters.js.map +1 -1
  1022. package/es/core/syntax/Irregular.js +5 -5
  1023. package/es/core/syntax/Irregular.js.map +1 -1
  1024. package/es/core/syntax/Keywords.d.ts +1 -1
  1025. package/es/core/syntax/Keywords.d.ts.map +1 -1
  1026. package/es/core/syntax/Keywords.js +14 -15
  1027. package/es/core/syntax/Keywords.js.map +1 -1
  1028. package/es/core/syntax/Numeric.js +5 -5
  1029. package/es/core/syntax/Numeric.js.map +1 -1
  1030. package/es/core/syntax/Whitespace.js +2 -2
  1031. package/es/core/syntax/Whitespace.js.map +1 -1
  1032. package/es/core/writers/PDFStreamWriter.d.ts +7 -7
  1033. package/es/core/writers/PDFStreamWriter.d.ts.map +1 -1
  1034. package/es/core/writers/PDFStreamWriter.js +102 -126
  1035. package/es/core/writers/PDFStreamWriter.js.map +1 -1
  1036. package/es/core/writers/PDFWriter.d.ts +15 -10
  1037. package/es/core/writers/PDFWriter.d.ts.map +1 -1
  1038. package/es/core/writers/PDFWriter.js +116 -142
  1039. package/es/core/writers/PDFWriter.js.map +1 -1
  1040. package/es/index.d.ts +4 -4
  1041. package/es/index.d.ts.map +1 -1
  1042. package/es/index.js +4 -4
  1043. package/es/index.js.map +1 -1
  1044. package/es/package.json +3 -0
  1045. package/es/types/fontkit.js +1 -0
  1046. package/es/types/index.d.ts +25 -1
  1047. package/es/types/index.d.ts.map +1 -1
  1048. package/es/types/index.js +1 -0
  1049. package/es/types/matrix.d.ts +8 -1
  1050. package/es/types/matrix.d.ts.map +1 -1
  1051. package/es/types/matrix.js +1 -1
  1052. package/es/types/matrix.js.map +1 -1
  1053. package/es/utils/Cache.js +10 -11
  1054. package/es/utils/Cache.js.map +1 -1
  1055. package/es/utils/arrays.d.ts +3 -1
  1056. package/es/utils/arrays.d.ts.map +1 -1
  1057. package/es/utils/arrays.js +78 -60
  1058. package/es/utils/arrays.js.map +1 -1
  1059. package/es/utils/async.d.ts.map +1 -1
  1060. package/es/utils/async.js +3 -5
  1061. package/es/utils/async.js.map +1 -1
  1062. package/es/utils/base64.d.ts.map +1 -1
  1063. package/es/utils/base64.js +24 -24
  1064. package/es/utils/base64.js.map +1 -1
  1065. package/es/utils/elements/Arc.d.ts +23 -0
  1066. package/es/utils/elements/Arc.d.ts.map +1 -0
  1067. package/es/utils/elements/Arc.js +74 -0
  1068. package/es/utils/elements/Arc.js.map +1 -0
  1069. package/es/utils/elements/Circle.d.ts +15 -0
  1070. package/es/utils/elements/Circle.d.ts.map +1 -0
  1071. package/es/utils/elements/Circle.js +37 -0
  1072. package/es/utils/elements/Circle.js.map +1 -0
  1073. package/es/utils/elements/Ellipse.d.ts +21 -0
  1074. package/es/utils/elements/Ellipse.d.ts.map +1 -0
  1075. package/es/utils/elements/Ellipse.js +87 -0
  1076. package/es/utils/elements/Ellipse.js.map +1 -0
  1077. package/es/utils/elements/GraphElement.d.ts +7 -0
  1078. package/es/utils/elements/GraphElement.d.ts.map +1 -0
  1079. package/es/utils/elements/GraphElement.js +8 -0
  1080. package/es/utils/elements/GraphElement.js.map +1 -0
  1081. package/es/utils/elements/Line.d.ts +24 -0
  1082. package/es/utils/elements/Line.d.ts.map +1 -0
  1083. package/es/utils/elements/Line.js +68 -0
  1084. package/es/utils/elements/Line.js.map +1 -0
  1085. package/es/utils/elements/Plot.d.ts +12 -0
  1086. package/es/utils/elements/Plot.d.ts.map +1 -0
  1087. package/es/utils/elements/Plot.js +42 -0
  1088. package/es/utils/elements/Plot.js.map +1 -0
  1089. package/es/utils/elements/Point.d.ts +19 -0
  1090. package/es/utils/elements/Point.d.ts.map +1 -0
  1091. package/es/utils/elements/Point.js +28 -0
  1092. package/es/utils/elements/Point.js.map +1 -0
  1093. package/es/utils/elements/Rectangle.d.ts +22 -0
  1094. package/es/utils/elements/Rectangle.d.ts.map +1 -0
  1095. package/es/utils/elements/Rectangle.js +54 -0
  1096. package/es/utils/elements/Rectangle.js.map +1 -0
  1097. package/es/utils/elements/Segment.d.ts +20 -0
  1098. package/es/utils/elements/Segment.d.ts.map +1 -0
  1099. package/es/utils/elements/Segment.js +76 -0
  1100. package/es/utils/elements/Segment.js.map +1 -0
  1101. package/es/utils/elements/index.d.ts +10 -0
  1102. package/es/utils/elements/index.d.ts.map +1 -0
  1103. package/es/utils/elements/index.js +10 -0
  1104. package/es/utils/elements/index.js.map +1 -0
  1105. package/es/utils/errors.js +1 -1
  1106. package/es/utils/errors.js.map +1 -1
  1107. package/es/utils/index.d.ts +11 -11
  1108. package/es/utils/index.d.ts.map +1 -1
  1109. package/es/utils/index.js +11 -11
  1110. package/es/utils/index.js.map +1 -1
  1111. package/es/utils/intersections.d.ts +10 -0
  1112. package/es/utils/intersections.d.ts.map +1 -0
  1113. package/es/utils/intersections.js +243 -0
  1114. package/es/utils/intersections.js.map +1 -0
  1115. package/es/utils/maths.d.ts +46 -0
  1116. package/es/utils/maths.d.ts.map +1 -0
  1117. package/es/utils/maths.js +69 -0
  1118. package/es/utils/maths.js.map +1 -0
  1119. package/es/utils/numbers.js +9 -9
  1120. package/es/utils/numbers.js.map +1 -1
  1121. package/es/utils/objects.js +4 -6
  1122. package/es/utils/objects.js.map +1 -1
  1123. package/es/utils/pdfDocEncoding.js +7 -7
  1124. package/es/utils/pdfDocEncoding.js.map +1 -1
  1125. package/es/utils/png.js +20 -22
  1126. package/es/utils/png.js.map +1 -1
  1127. package/es/utils/rng.js +7 -9
  1128. package/es/utils/rng.js.map +1 -1
  1129. package/es/utils/strings.d.ts +1 -0
  1130. package/es/utils/strings.d.ts.map +1 -1
  1131. package/es/utils/strings.js +66 -68
  1132. package/es/utils/strings.js.map +1 -1
  1133. package/es/utils/unicode.js +42 -63
  1134. package/es/utils/unicode.js.map +1 -1
  1135. package/es/utils/validators.d.ts +2 -2
  1136. package/es/utils/validators.d.ts.map +1 -1
  1137. package/es/utils/validators.js +38 -38
  1138. package/es/utils/validators.js.map +1 -1
  1139. package/package.json +70 -39
  1140. package/src/api/PDFDocument.ts +248 -22
  1141. package/src/api/PDFDocumentOptions.ts +4 -2
  1142. package/src/api/PDFEmbeddedFile.ts +12 -4
  1143. package/src/api/PDFEmbeddedPage.ts +4 -4
  1144. package/src/api/PDFFont.ts +4 -4
  1145. package/src/api/PDFImage.ts +4 -4
  1146. package/src/api/PDFJavaScript.ts +4 -4
  1147. package/src/api/PDFPage.ts +93 -20
  1148. package/src/api/PDFPageOptions.ts +34 -12
  1149. package/src/api/PDFSvg.ts +10 -0
  1150. package/src/api/colors.ts +27 -19
  1151. package/src/api/form/PDFButton.ts +11 -11
  1152. package/src/api/form/PDFCheckBox.ts +8 -8
  1153. package/src/api/form/PDFDropdown.ts +9 -9
  1154. package/src/api/form/PDFField.ts +7 -7
  1155. package/src/api/form/PDFForm.ts +56 -46
  1156. package/src/api/form/PDFOptionList.ts +9 -9
  1157. package/src/api/form/PDFRadioGroup.ts +8 -8
  1158. package/src/api/form/PDFSignature.ts +4 -4
  1159. package/src/api/form/PDFTextField.ts +15 -15
  1160. package/src/api/form/appearances.ts +41 -49
  1161. package/src/api/form/index.ts +10 -10
  1162. package/src/api/image/index.ts +1 -1
  1163. package/src/api/index.ts +1 -0
  1164. package/src/api/objects.ts +1 -1
  1165. package/src/api/operations.ts +198 -142
  1166. package/src/api/operators.ts +10 -3
  1167. package/src/api/rotations.ts +7 -9
  1168. package/src/api/svg.ts +1074 -0
  1169. package/src/api/svgPath.ts +2 -4
  1170. package/src/api/text/index.ts +2 -2
  1171. package/src/api/text/layout.ts +5 -5
  1172. package/src/core/PDFContext.ts +94 -19
  1173. package/src/core/PDFObjectCopier.ts +8 -8
  1174. package/src/core/acroform/PDFAcroButton.ts +8 -8
  1175. package/src/core/acroform/PDFAcroCheckBox.ts +6 -6
  1176. package/src/core/acroform/PDFAcroChoice.ts +7 -10
  1177. package/src/core/acroform/PDFAcroComboBox.ts +5 -5
  1178. package/src/core/acroform/PDFAcroField.ts +12 -12
  1179. package/src/core/acroform/PDFAcroForm.ts +8 -11
  1180. package/src/core/acroform/PDFAcroListBox.ts +4 -4
  1181. package/src/core/acroform/PDFAcroNonTerminal.ts +5 -5
  1182. package/src/core/acroform/PDFAcroPushButton.ts +5 -5
  1183. package/src/core/acroform/PDFAcroRadioButton.ts +7 -7
  1184. package/src/core/acroform/PDFAcroSignature.ts +3 -3
  1185. package/src/core/acroform/PDFAcroTerminal.ts +6 -6
  1186. package/src/core/acroform/PDFAcroText.ts +8 -8
  1187. package/src/core/acroform/index.ts +15 -15
  1188. package/src/core/acroform/utils.ts +20 -20
  1189. package/src/core/annotation/AppearanceCharacteristics.ts +6 -6
  1190. package/src/core/annotation/BorderStyle.ts +3 -3
  1191. package/src/core/annotation/PDFAnnotation.ts +6 -6
  1192. package/src/core/annotation/PDFWidgetAnnotation.ts +9 -9
  1193. package/src/core/annotation/index.ts +4 -4
  1194. package/src/core/crypto.ts +1997 -0
  1195. package/src/core/document/PDFCrossRefSection.ts +4 -4
  1196. package/src/core/document/PDFHeader.ts +6 -2
  1197. package/src/core/document/PDFTrailer.ts +2 -2
  1198. package/src/core/document/PDFTrailerDict.ts +2 -2
  1199. package/src/core/embedders/CMap.ts +3 -3
  1200. package/src/core/embedders/CustomFontEmbedder.ts +9 -9
  1201. package/src/core/embedders/CustomFontSubsetEmbedder.ts +10 -4
  1202. package/src/core/embedders/FileEmbedder.ts +8 -4
  1203. package/src/core/embedders/FontFlags.ts +1 -1
  1204. package/src/core/embedders/JavaScriptEmbedder.ts +3 -3
  1205. package/src/core/embedders/JpegEmbedder.ts +2 -2
  1206. package/src/core/embedders/PDFPageEmbedder.ts +24 -22
  1207. package/src/core/embedders/PngEmbedder.ts +3 -3
  1208. package/src/core/embedders/StandardFontEmbedder.ts +10 -5
  1209. package/src/core/errors.ts +15 -13
  1210. package/src/core/index.ts +52 -47
  1211. package/src/core/interactive/ViewerPreferences.ts +7 -7
  1212. package/src/core/objects/PDFArray.ts +22 -22
  1213. package/src/core/objects/PDFBool.ts +3 -3
  1214. package/src/core/objects/PDFDict.ts +14 -12
  1215. package/src/core/objects/PDFHexString.ts +8 -4
  1216. package/src/core/objects/PDFInvalidObject.ts +1 -1
  1217. package/src/core/objects/PDFName.ts +6 -6
  1218. package/src/core/objects/PDFNull.ts +2 -2
  1219. package/src/core/objects/PDFNumber.ts +3 -3
  1220. package/src/core/objects/PDFObject.ts +2 -2
  1221. package/src/core/objects/PDFRawStream.ts +24 -10
  1222. package/src/core/objects/PDFRef.ts +4 -4
  1223. package/src/core/objects/PDFStream.ts +14 -7
  1224. package/src/core/objects/PDFString.ts +4 -4
  1225. package/src/core/operators/PDFOperator.ts +10 -10
  1226. package/src/core/parser/BaseParser.ts +6 -6
  1227. package/src/core/parser/ByteStream.ts +4 -4
  1228. package/src/core/parser/PDFObjectParser.ts +78 -41
  1229. package/src/core/parser/PDFObjectStreamParser.ts +9 -9
  1230. package/src/core/parser/PDFParser.ts +43 -23
  1231. package/src/core/parser/PDFXRefStreamParser.ts +9 -9
  1232. package/src/core/security/PDFSecurity.ts +685 -0
  1233. package/src/core/streams/Ascii85Stream.ts +2 -2
  1234. package/src/core/streams/AsciiHexStream.ts +2 -2
  1235. package/src/core/streams/DecodeStream.ts +2 -2
  1236. package/src/core/streams/DecryptStream.ts +56 -0
  1237. package/src/core/streams/FlateStream.ts +3 -2
  1238. package/src/core/streams/LZWStream.ts +3 -3
  1239. package/src/core/streams/RunLengthStream.ts +2 -2
  1240. package/src/core/streams/decode.ts +23 -18
  1241. package/src/core/structures/PDFCatalog.ts +6 -6
  1242. package/src/core/structures/PDFContentStream.ts +5 -5
  1243. package/src/core/structures/PDFCrossRefStream.ts +6 -6
  1244. package/src/core/structures/PDFFlateStream.ts +10 -6
  1245. package/src/core/structures/PDFObjectStream.ts +8 -8
  1246. package/src/core/structures/PDFPageLeaf.ts +9 -9
  1247. package/src/core/structures/PDFPageTree.ts +8 -8
  1248. package/src/core/syntax/Delimiters.ts +1 -1
  1249. package/src/core/syntax/Irregular.ts +3 -3
  1250. package/src/core/syntax/Keywords.ts +1 -1
  1251. package/src/core/syntax/Numeric.ts +1 -1
  1252. package/src/core/syntax/Whitespace.ts +1 -1
  1253. package/src/core/writers/PDFStreamWriter.ts +12 -1
  1254. package/src/core/writers/PDFWriter.ts +22 -13
  1255. package/src/index.ts +4 -4
  1256. package/src/types/index.ts +38 -1
  1257. package/src/utils/arrays.ts +33 -2
  1258. package/src/utils/base64.ts +2 -1
  1259. package/src/utils/elements/Arc.ts +107 -0
  1260. package/src/utils/elements/Circle.ts +55 -0
  1261. package/src/utils/elements/Ellipse.ts +135 -0
  1262. package/src/utils/elements/GraphElement.ts +14 -0
  1263. package/src/utils/elements/Line.ts +85 -0
  1264. package/src/utils/elements/Plot.ts +50 -0
  1265. package/src/utils/elements/Point.ts +37 -0
  1266. package/src/utils/elements/Rectangle.ts +65 -0
  1267. package/src/utils/elements/Segment.ts +92 -0
  1268. package/src/utils/elements/index.ts +9 -0
  1269. package/src/utils/index.ts +11 -11
  1270. package/src/utils/intersections.ts +280 -0
  1271. package/src/utils/maths.ts +108 -0
  1272. package/src/utils/pdfDocEncoding.ts +1 -1
  1273. package/src/utils/png.ts +1 -1
  1274. package/src/utils/strings.ts +11 -1
  1275. package/src/utils/unicode.ts +1 -1
  1276. package/src/utils/validators.ts +1 -1
  1277. package/ts3.4/cjs/api/PDFDocument.d.ts +52 -13
  1278. package/ts3.4/cjs/api/PDFDocumentOptions.d.ts +4 -2
  1279. package/ts3.4/cjs/api/PDFEmbeddedFile.d.ts +9 -4
  1280. package/ts3.4/cjs/api/PDFEmbeddedPage.d.ts +3 -3
  1281. package/ts3.4/cjs/api/PDFFont.d.ts +4 -4
  1282. package/ts3.4/cjs/api/PDFImage.d.ts +4 -4
  1283. package/ts3.4/cjs/api/PDFJavaScript.d.ts +4 -4
  1284. package/ts3.4/cjs/api/PDFPage.d.ts +36 -9
  1285. package/ts3.4/cjs/api/PDFPageOptions.d.ts +35 -12
  1286. package/ts3.4/cjs/api/PDFSvg.d.ts +7 -0
  1287. package/ts3.4/cjs/api/colors.d.ts +6 -2
  1288. package/ts3.4/cjs/api/form/PDFButton.d.ts +8 -8
  1289. package/ts3.4/cjs/api/form/PDFCheckBox.d.ts +5 -5
  1290. package/ts3.4/cjs/api/form/PDFDropdown.d.ts +6 -6
  1291. package/ts3.4/cjs/api/form/PDFField.d.ts +7 -7
  1292. package/ts3.4/cjs/api/form/PDFForm.d.ts +11 -11
  1293. package/ts3.4/cjs/api/form/PDFOptionList.d.ts +6 -6
  1294. package/ts3.4/cjs/api/form/PDFRadioGroup.d.ts +5 -5
  1295. package/ts3.4/cjs/api/form/PDFSignature.d.ts +3 -3
  1296. package/ts3.4/cjs/api/form/PDFTextField.d.ts +8 -8
  1297. package/ts3.4/cjs/api/form/appearances.d.ts +21 -21
  1298. package/ts3.4/cjs/api/form/index.d.ts +10 -10
  1299. package/ts3.4/cjs/api/image/index.d.ts +1 -1
  1300. package/ts3.4/cjs/api/index.d.ts +22 -21
  1301. package/ts3.4/cjs/api/objects.d.ts +1 -1
  1302. package/ts3.4/cjs/api/operations.d.ts +27 -13
  1303. package/ts3.4/cjs/api/operators.d.ts +6 -1
  1304. package/ts3.4/cjs/api/rotations.d.ts +2 -2
  1305. package/ts3.4/cjs/api/sizes.d.ts +200 -50
  1306. package/ts3.4/cjs/api/snapshot/DefaultDocumentSnapshot.d.ts +1 -1
  1307. package/ts3.4/cjs/api/snapshot/DocumentSnapshot.d.ts +1 -1
  1308. package/ts3.4/cjs/api/snapshot/IncrementalDocumentSnapshot.d.ts +1 -1
  1309. package/ts3.4/cjs/api/svg.d.ts +76 -0
  1310. package/ts3.4/cjs/api/svgPath.d.ts +1 -1
  1311. package/ts3.4/cjs/api/text/index.d.ts +2 -2
  1312. package/ts3.4/cjs/api/text/layout.d.ts +3 -3
  1313. package/ts3.4/cjs/core/PDFContext.d.ts +43 -20
  1314. package/ts3.4/cjs/core/PDFObjectCopier.d.ts +2 -2
  1315. package/ts3.4/cjs/core/acroform/PDFAcroButton.d.ts +7 -7
  1316. package/ts3.4/cjs/core/acroform/PDFAcroCheckBox.d.ts +5 -5
  1317. package/ts3.4/cjs/core/acroform/PDFAcroChoice.d.ts +4 -4
  1318. package/ts3.4/cjs/core/acroform/PDFAcroComboBox.d.ts +4 -4
  1319. package/ts3.4/cjs/core/acroform/PDFAcroField.d.ts +8 -8
  1320. package/ts3.4/cjs/core/acroform/PDFAcroForm.d.ts +13 -7
  1321. package/ts3.4/cjs/core/acroform/PDFAcroListBox.d.ts +4 -4
  1322. package/ts3.4/cjs/core/acroform/PDFAcroNonTerminal.d.ts +4 -4
  1323. package/ts3.4/cjs/core/acroform/PDFAcroPushButton.d.ts +4 -4
  1324. package/ts3.4/cjs/core/acroform/PDFAcroRadioButton.d.ts +5 -5
  1325. package/ts3.4/cjs/core/acroform/PDFAcroSignature.d.ts +3 -3
  1326. package/ts3.4/cjs/core/acroform/PDFAcroTerminal.d.ts +5 -5
  1327. package/ts3.4/cjs/core/acroform/PDFAcroText.d.ts +7 -7
  1328. package/ts3.4/cjs/core/acroform/index.d.ts +15 -15
  1329. package/ts3.4/cjs/core/acroform/utils.d.ts +8 -5
  1330. package/ts3.4/cjs/core/annotation/AppearanceCharacteristics.d.ts +5 -5
  1331. package/ts3.4/cjs/core/annotation/BorderStyle.d.ts +2 -2
  1332. package/ts3.4/cjs/core/annotation/PDFAnnotation.d.ts +6 -6
  1333. package/ts3.4/cjs/core/annotation/PDFWidgetAnnotation.d.ts +9 -9
  1334. package/ts3.4/cjs/core/annotation/index.d.ts +4 -4
  1335. package/ts3.4/cjs/core/crypto.d.ts +96 -0
  1336. package/ts3.4/cjs/core/document/PDFCrossRefSection.d.ts +1 -1
  1337. package/ts3.4/cjs/core/document/PDFHeader.d.ts +1 -0
  1338. package/ts3.4/cjs/core/document/PDFTrailerDict.d.ts +1 -1
  1339. package/ts3.4/cjs/core/embedders/CMap.d.ts +2 -2
  1340. package/ts3.4/cjs/core/embedders/CustomFontEmbedder.d.ts +5 -5
  1341. package/ts3.4/cjs/core/embedders/CustomFontSubsetEmbedder.d.ts +3 -3
  1342. package/ts3.4/cjs/core/embedders/FileEmbedder.d.ts +3 -2
  1343. package/ts3.4/cjs/core/embedders/FontFlags.d.ts +1 -1
  1344. package/ts3.4/cjs/core/embedders/JavaScriptEmbedder.d.ts +2 -2
  1345. package/ts3.4/cjs/core/embedders/JpegEmbedder.d.ts +2 -2
  1346. package/ts3.4/cjs/core/embedders/PDFPageEmbedder.d.ts +4 -4
  1347. package/ts3.4/cjs/core/embedders/PngEmbedder.d.ts +2 -2
  1348. package/ts3.4/cjs/core/embedders/StandardFontEmbedder.d.ts +4 -4
  1349. package/ts3.4/cjs/core/errors.d.ts +1 -1
  1350. package/ts3.4/cjs/core/index.d.ts +48 -47
  1351. package/ts3.4/cjs/core/interactive/ViewerPreferences.d.ts +8 -8
  1352. package/ts3.4/cjs/core/objects/PDFArray.d.ts +12 -12
  1353. package/ts3.4/cjs/core/objects/PDFBool.d.ts +1 -1
  1354. package/ts3.4/cjs/core/objects/PDFDict.d.ts +17 -13
  1355. package/ts3.4/cjs/core/objects/PDFHexString.d.ts +2 -1
  1356. package/ts3.4/cjs/core/objects/PDFInvalidObject.d.ts +1 -1
  1357. package/ts3.4/cjs/core/objects/PDFName.d.ts +1 -1
  1358. package/ts3.4/cjs/core/objects/PDFNull.d.ts +1 -1
  1359. package/ts3.4/cjs/core/objects/PDFNumber.d.ts +1 -1
  1360. package/ts3.4/cjs/core/objects/PDFObject.d.ts +1 -1
  1361. package/ts3.4/cjs/core/objects/PDFRawStream.d.ts +8 -5
  1362. package/ts3.4/cjs/core/objects/PDFRef.d.ts +1 -1
  1363. package/ts3.4/cjs/core/objects/PDFStream.d.ts +4 -3
  1364. package/ts3.4/cjs/core/objects/PDFString.d.ts +1 -1
  1365. package/ts3.4/cjs/core/operators/PDFOperator.d.ts +9 -9
  1366. package/ts3.4/cjs/core/parser/BaseParser.d.ts +1 -1
  1367. package/ts3.4/cjs/core/parser/ByteStream.d.ts +1 -1
  1368. package/ts3.4/cjs/core/parser/PDFObjectParser.d.ts +23 -21
  1369. package/ts3.4/cjs/core/parser/PDFObjectStreamParser.d.ts +3 -3
  1370. package/ts3.4/cjs/core/parser/PDFParser.d.ts +6 -4
  1371. package/ts3.4/cjs/core/parser/PDFXRefStreamParser.d.ts +2 -2
  1372. package/ts3.4/cjs/core/security/PDFSecurity.d.ts +75 -0
  1373. package/ts3.4/cjs/core/streams/Ascii85Stream.d.ts +2 -2
  1374. package/ts3.4/cjs/core/streams/AsciiHexStream.d.ts +2 -2
  1375. package/ts3.4/cjs/core/streams/DecodeStream.d.ts +1 -1
  1376. package/ts3.4/cjs/core/streams/DecryptStream.d.ts +13 -0
  1377. package/ts3.4/cjs/core/streams/FlateStream.d.ts +2 -2
  1378. package/ts3.4/cjs/core/streams/LZWStream.d.ts +3 -3
  1379. package/ts3.4/cjs/core/streams/RunLengthStream.d.ts +2 -2
  1380. package/ts3.4/cjs/core/streams/decode.d.ts +3 -3
  1381. package/ts3.4/cjs/core/structures/PDFCatalog.d.ts +5 -5
  1382. package/ts3.4/cjs/core/structures/PDFContentStream.d.ts +4 -4
  1383. package/ts3.4/cjs/core/structures/PDFCrossRefStream.d.ts +10 -6
  1384. package/ts3.4/cjs/core/structures/PDFFlateStream.d.ts +5 -4
  1385. package/ts3.4/cjs/core/structures/PDFObjectStream.d.ts +8 -5
  1386. package/ts3.4/cjs/core/structures/PDFPageLeaf.d.ts +9 -9
  1387. package/ts3.4/cjs/core/structures/PDFPageTree.d.ts +8 -8
  1388. package/ts3.4/cjs/core/syntax/Keywords.d.ts +1 -1
  1389. package/ts3.4/cjs/core/writers/PDFStreamWriter.d.ts +11 -8
  1390. package/ts3.4/cjs/core/writers/PDFWriter.d.ts +19 -11
  1391. package/ts3.4/cjs/index.d.ts +4 -4
  1392. package/ts3.4/cjs/types/index.d.ts +25 -1
  1393. package/ts3.4/cjs/types/matrix.d.ts +8 -1
  1394. package/ts3.4/cjs/utils/arrays.d.ts +3 -1
  1395. package/ts3.4/cjs/utils/elements/Arc.d.ts +23 -0
  1396. package/ts3.4/cjs/utils/elements/Circle.d.ts +15 -0
  1397. package/ts3.4/cjs/utils/elements/Ellipse.d.ts +21 -0
  1398. package/ts3.4/cjs/utils/elements/GraphElement.d.ts +7 -0
  1399. package/ts3.4/cjs/utils/elements/Line.d.ts +24 -0
  1400. package/ts3.4/cjs/utils/elements/Plot.d.ts +12 -0
  1401. package/ts3.4/cjs/utils/elements/Point.d.ts +19 -0
  1402. package/ts3.4/cjs/utils/elements/Rectangle.d.ts +22 -0
  1403. package/ts3.4/cjs/utils/elements/Segment.d.ts +20 -0
  1404. package/ts3.4/cjs/utils/elements/index.d.ts +10 -0
  1405. package/ts3.4/cjs/utils/index.d.ts +11 -11
  1406. package/ts3.4/cjs/utils/intersections.d.ts +10 -0
  1407. package/ts3.4/cjs/utils/maths.d.ts +46 -0
  1408. package/ts3.4/cjs/utils/strings.d.ts +5 -1
  1409. package/ts3.4/cjs/utils/validators.d.ts +5 -2
  1410. package/ts3.4/es/api/PDFDocument.d.ts +52 -13
  1411. package/ts3.4/es/api/PDFDocumentOptions.d.ts +4 -2
  1412. package/ts3.4/es/api/PDFEmbeddedFile.d.ts +9 -4
  1413. package/ts3.4/es/api/PDFEmbeddedPage.d.ts +3 -3
  1414. package/ts3.4/es/api/PDFFont.d.ts +4 -4
  1415. package/ts3.4/es/api/PDFImage.d.ts +4 -4
  1416. package/ts3.4/es/api/PDFJavaScript.d.ts +4 -4
  1417. package/ts3.4/es/api/PDFPage.d.ts +36 -9
  1418. package/ts3.4/es/api/PDFPageOptions.d.ts +35 -12
  1419. package/ts3.4/es/api/PDFSvg.d.ts +7 -0
  1420. package/ts3.4/es/api/colors.d.ts +6 -2
  1421. package/ts3.4/es/api/form/PDFButton.d.ts +8 -8
  1422. package/ts3.4/es/api/form/PDFCheckBox.d.ts +5 -5
  1423. package/ts3.4/es/api/form/PDFDropdown.d.ts +6 -6
  1424. package/ts3.4/es/api/form/PDFField.d.ts +7 -7
  1425. package/ts3.4/es/api/form/PDFForm.d.ts +11 -11
  1426. package/ts3.4/es/api/form/PDFOptionList.d.ts +6 -6
  1427. package/ts3.4/es/api/form/PDFRadioGroup.d.ts +5 -5
  1428. package/ts3.4/es/api/form/PDFSignature.d.ts +3 -3
  1429. package/ts3.4/es/api/form/PDFTextField.d.ts +8 -8
  1430. package/ts3.4/es/api/form/appearances.d.ts +21 -21
  1431. package/ts3.4/es/api/form/index.d.ts +10 -10
  1432. package/ts3.4/es/api/image/index.d.ts +1 -1
  1433. package/ts3.4/es/api/index.d.ts +22 -21
  1434. package/ts3.4/es/api/objects.d.ts +1 -1
  1435. package/ts3.4/es/api/operations.d.ts +27 -13
  1436. package/ts3.4/es/api/operators.d.ts +6 -1
  1437. package/ts3.4/es/api/rotations.d.ts +2 -2
  1438. package/ts3.4/es/api/sizes.d.ts +200 -50
  1439. package/ts3.4/es/api/snapshot/DefaultDocumentSnapshot.d.ts +1 -1
  1440. package/ts3.4/es/api/snapshot/DocumentSnapshot.d.ts +1 -1
  1441. package/ts3.4/es/api/snapshot/IncrementalDocumentSnapshot.d.ts +1 -1
  1442. package/ts3.4/es/api/svg.d.ts +76 -0
  1443. package/ts3.4/es/api/svgPath.d.ts +1 -1
  1444. package/ts3.4/es/api/text/index.d.ts +2 -2
  1445. package/ts3.4/es/api/text/layout.d.ts +3 -3
  1446. package/ts3.4/es/core/PDFContext.d.ts +43 -20
  1447. package/ts3.4/es/core/PDFObjectCopier.d.ts +2 -2
  1448. package/ts3.4/es/core/acroform/PDFAcroButton.d.ts +7 -7
  1449. package/ts3.4/es/core/acroform/PDFAcroCheckBox.d.ts +5 -5
  1450. package/ts3.4/es/core/acroform/PDFAcroChoice.d.ts +4 -4
  1451. package/ts3.4/es/core/acroform/PDFAcroComboBox.d.ts +4 -4
  1452. package/ts3.4/es/core/acroform/PDFAcroField.d.ts +8 -8
  1453. package/ts3.4/es/core/acroform/PDFAcroForm.d.ts +13 -7
  1454. package/ts3.4/es/core/acroform/PDFAcroListBox.d.ts +4 -4
  1455. package/ts3.4/es/core/acroform/PDFAcroNonTerminal.d.ts +4 -4
  1456. package/ts3.4/es/core/acroform/PDFAcroPushButton.d.ts +4 -4
  1457. package/ts3.4/es/core/acroform/PDFAcroRadioButton.d.ts +5 -5
  1458. package/ts3.4/es/core/acroform/PDFAcroSignature.d.ts +3 -3
  1459. package/ts3.4/es/core/acroform/PDFAcroTerminal.d.ts +5 -5
  1460. package/ts3.4/es/core/acroform/PDFAcroText.d.ts +7 -7
  1461. package/ts3.4/es/core/acroform/index.d.ts +15 -15
  1462. package/ts3.4/es/core/acroform/utils.d.ts +8 -5
  1463. package/ts3.4/es/core/annotation/AppearanceCharacteristics.d.ts +5 -5
  1464. package/ts3.4/es/core/annotation/BorderStyle.d.ts +2 -2
  1465. package/ts3.4/es/core/annotation/PDFAnnotation.d.ts +6 -6
  1466. package/ts3.4/es/core/annotation/PDFWidgetAnnotation.d.ts +9 -9
  1467. package/ts3.4/es/core/annotation/index.d.ts +4 -4
  1468. package/ts3.4/es/core/crypto.d.ts +96 -0
  1469. package/ts3.4/es/core/document/PDFCrossRefSection.d.ts +1 -1
  1470. package/ts3.4/es/core/document/PDFHeader.d.ts +1 -0
  1471. package/ts3.4/es/core/document/PDFTrailerDict.d.ts +1 -1
  1472. package/ts3.4/es/core/embedders/CMap.d.ts +2 -2
  1473. package/ts3.4/es/core/embedders/CustomFontEmbedder.d.ts +5 -5
  1474. package/ts3.4/es/core/embedders/CustomFontSubsetEmbedder.d.ts +3 -3
  1475. package/ts3.4/es/core/embedders/FileEmbedder.d.ts +3 -2
  1476. package/ts3.4/es/core/embedders/FontFlags.d.ts +1 -1
  1477. package/ts3.4/es/core/embedders/JavaScriptEmbedder.d.ts +2 -2
  1478. package/ts3.4/es/core/embedders/JpegEmbedder.d.ts +2 -2
  1479. package/ts3.4/es/core/embedders/PDFPageEmbedder.d.ts +4 -4
  1480. package/ts3.4/es/core/embedders/PngEmbedder.d.ts +2 -2
  1481. package/ts3.4/es/core/embedders/StandardFontEmbedder.d.ts +4 -4
  1482. package/ts3.4/es/core/errors.d.ts +1 -1
  1483. package/ts3.4/es/core/index.d.ts +48 -47
  1484. package/ts3.4/es/core/interactive/ViewerPreferences.d.ts +8 -8
  1485. package/ts3.4/es/core/objects/PDFArray.d.ts +12 -12
  1486. package/ts3.4/es/core/objects/PDFBool.d.ts +1 -1
  1487. package/ts3.4/es/core/objects/PDFDict.d.ts +17 -13
  1488. package/ts3.4/es/core/objects/PDFHexString.d.ts +2 -1
  1489. package/ts3.4/es/core/objects/PDFInvalidObject.d.ts +1 -1
  1490. package/ts3.4/es/core/objects/PDFName.d.ts +1 -1
  1491. package/ts3.4/es/core/objects/PDFNull.d.ts +1 -1
  1492. package/ts3.4/es/core/objects/PDFNumber.d.ts +1 -1
  1493. package/ts3.4/es/core/objects/PDFObject.d.ts +1 -1
  1494. package/ts3.4/es/core/objects/PDFRawStream.d.ts +8 -5
  1495. package/ts3.4/es/core/objects/PDFRef.d.ts +1 -1
  1496. package/ts3.4/es/core/objects/PDFStream.d.ts +4 -3
  1497. package/ts3.4/es/core/objects/PDFString.d.ts +1 -1
  1498. package/ts3.4/es/core/operators/PDFOperator.d.ts +9 -9
  1499. package/ts3.4/es/core/parser/BaseParser.d.ts +1 -1
  1500. package/ts3.4/es/core/parser/ByteStream.d.ts +1 -1
  1501. package/ts3.4/es/core/parser/PDFObjectParser.d.ts +23 -21
  1502. package/ts3.4/es/core/parser/PDFObjectStreamParser.d.ts +3 -3
  1503. package/ts3.4/es/core/parser/PDFParser.d.ts +6 -4
  1504. package/ts3.4/es/core/parser/PDFXRefStreamParser.d.ts +2 -2
  1505. package/ts3.4/es/core/security/PDFSecurity.d.ts +75 -0
  1506. package/ts3.4/es/core/streams/Ascii85Stream.d.ts +2 -2
  1507. package/ts3.4/es/core/streams/AsciiHexStream.d.ts +2 -2
  1508. package/ts3.4/es/core/streams/DecodeStream.d.ts +1 -1
  1509. package/ts3.4/es/core/streams/DecryptStream.d.ts +13 -0
  1510. package/ts3.4/es/core/streams/FlateStream.d.ts +2 -2
  1511. package/ts3.4/es/core/streams/LZWStream.d.ts +3 -3
  1512. package/ts3.4/es/core/streams/RunLengthStream.d.ts +2 -2
  1513. package/ts3.4/es/core/streams/decode.d.ts +3 -3
  1514. package/ts3.4/es/core/structures/PDFCatalog.d.ts +5 -5
  1515. package/ts3.4/es/core/structures/PDFContentStream.d.ts +4 -4
  1516. package/ts3.4/es/core/structures/PDFCrossRefStream.d.ts +10 -6
  1517. package/ts3.4/es/core/structures/PDFFlateStream.d.ts +5 -4
  1518. package/ts3.4/es/core/structures/PDFObjectStream.d.ts +8 -5
  1519. package/ts3.4/es/core/structures/PDFPageLeaf.d.ts +9 -9
  1520. package/ts3.4/es/core/structures/PDFPageTree.d.ts +8 -8
  1521. package/ts3.4/es/core/syntax/Keywords.d.ts +1 -1
  1522. package/ts3.4/es/core/writers/PDFStreamWriter.d.ts +11 -8
  1523. package/ts3.4/es/core/writers/PDFWriter.d.ts +19 -11
  1524. package/ts3.4/es/index.d.ts +4 -4
  1525. package/ts3.4/es/types/index.d.ts +25 -1
  1526. package/ts3.4/es/types/matrix.d.ts +8 -1
  1527. package/ts3.4/es/utils/arrays.d.ts +3 -1
  1528. package/ts3.4/es/utils/elements/Arc.d.ts +23 -0
  1529. package/ts3.4/es/utils/elements/Circle.d.ts +15 -0
  1530. package/ts3.4/es/utils/elements/Ellipse.d.ts +21 -0
  1531. package/ts3.4/es/utils/elements/GraphElement.d.ts +7 -0
  1532. package/ts3.4/es/utils/elements/Line.d.ts +24 -0
  1533. package/ts3.4/es/utils/elements/Plot.d.ts +12 -0
  1534. package/ts3.4/es/utils/elements/Point.d.ts +19 -0
  1535. package/ts3.4/es/utils/elements/Rectangle.d.ts +22 -0
  1536. package/ts3.4/es/utils/elements/Segment.d.ts +20 -0
  1537. package/ts3.4/es/utils/elements/index.d.ts +10 -0
  1538. package/ts3.4/es/utils/index.d.ts +11 -11
  1539. package/ts3.4/es/utils/intersections.d.ts +10 -0
  1540. package/ts3.4/es/utils/maths.d.ts +46 -0
  1541. package/ts3.4/es/utils/strings.d.ts +5 -1
  1542. package/ts3.4/es/utils/validators.d.ts +5 -2
  1543. package/yarn.lock +0 -4446
@@ -0,0 +1,1997 @@
1
+ /* Copyright 2012 Mozilla Foundation
2
+ *
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ /* tslint:disable */
16
+
17
+ import { arrayAsString, isArrayEqual } from '../utils/arrays';
18
+ import { stringAsByteArray } from '../utils/strings';
19
+ import PDFBool from './objects/PDFBool';
20
+ import PDFDict from './objects/PDFDict';
21
+ import PDFName from './objects/PDFName';
22
+ import PDFNumber from './objects/PDFNumber';
23
+ import PDFString from './objects/PDFString';
24
+ import DecryptStream from './streams/DecryptStream';
25
+ import { StreamType } from './streams/Stream';
26
+
27
+ class ARCFourCipher {
28
+ private s: Uint8Array;
29
+ private a: number;
30
+ private b: number;
31
+
32
+ constructor(key: Uint8Array) {
33
+ this.a = 0;
34
+ this.b = 0;
35
+ const s = new Uint8Array(256);
36
+ const keyLength = key.length;
37
+
38
+ for (let i = 0; i < 256; ++i) {
39
+ s[i] = i;
40
+ }
41
+ for (let i = 0, j = 0; i < 256; ++i) {
42
+ const tmp = s[i];
43
+ j = (j + tmp + key[i % keyLength]) & 0xff;
44
+ s[i] = s[j];
45
+ s[j] = tmp;
46
+ }
47
+ this.s = s;
48
+ }
49
+
50
+ encryptBlock(data: Uint8Array) {
51
+ let a = this.a,
52
+ b = this.b;
53
+ const s = this.s;
54
+ const n = data.length;
55
+ const output = new Uint8Array(n);
56
+ for (let i = 0; i < n; ++i) {
57
+ a = (a + 1) & 0xff;
58
+ const tmp = s[a];
59
+ b = (b + tmp) & 0xff;
60
+ const tmp2 = s[b];
61
+ s[a] = tmp2;
62
+ s[b] = tmp;
63
+ output[i] = data[i] ^ s[(tmp + tmp2) & 0xff];
64
+ }
65
+ this.a = a;
66
+ this.b = b;
67
+ return output;
68
+ }
69
+
70
+ decryptBlock(data: Uint8Array) {
71
+ return this.encryptBlock(data);
72
+ }
73
+
74
+ encrypt(data: Uint8Array) {
75
+ return this.encryptBlock(data);
76
+ }
77
+ }
78
+
79
+ const calculateMD5 = (function calculateMD5Closure() {
80
+ const r = new Uint8Array([
81
+ 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5,
82
+ 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11,
83
+ 16, 23, 4, 11, 16, 23, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10,
84
+ 15, 21,
85
+ ]);
86
+
87
+ const k = new Int32Array([
88
+ -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
89
+ -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
90
+ 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
91
+ 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
92
+ 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
93
+ 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
94
+ -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
95
+ -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
96
+ -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
97
+ -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
98
+ -145523070, -1120210379, 718787259, -343485551,
99
+ ]);
100
+
101
+ function hash(data: Uint8Array, offset: number, length: number) {
102
+ let h0 = 1732584193,
103
+ h1 = -271733879,
104
+ h2 = -1732584194,
105
+ h3 = 271733878;
106
+ // pre-processing
107
+ const paddedLength = (length + 72) & ~63; // data + 9 extra bytes
108
+ const padded = new Uint8Array(paddedLength);
109
+ let i, j;
110
+ for (i = 0; i < length; ++i) {
111
+ padded[i] = data[offset++];
112
+ }
113
+ padded[i++] = 0x80;
114
+ const n = paddedLength - 8;
115
+ while (i < n) {
116
+ padded[i++] = 0;
117
+ }
118
+ padded[i++] = (length << 3) & 0xff;
119
+ padded[i++] = (length >> 5) & 0xff;
120
+ padded[i++] = (length >> 13) & 0xff;
121
+ padded[i++] = (length >> 21) & 0xff;
122
+ padded[i++] = (length >>> 29) & 0xff;
123
+ padded[i++] = 0;
124
+ padded[i++] = 0;
125
+ padded[i++] = 0;
126
+ const w = new Int32Array(16);
127
+ for (i = 0; i < paddedLength; ) {
128
+ for (j = 0; j < 16; ++j, i += 4) {
129
+ w[j] =
130
+ padded[i] |
131
+ (padded[i + 1] << 8) |
132
+ (padded[i + 2] << 16) |
133
+ (padded[i + 3] << 24);
134
+ }
135
+ let a = h0,
136
+ b = h1,
137
+ c = h2,
138
+ d = h3,
139
+ f,
140
+ g;
141
+ for (j = 0; j < 64; ++j) {
142
+ if (j < 16) {
143
+ f = (b & c) | (~b & d);
144
+ g = j;
145
+ } else if (j < 32) {
146
+ f = (d & b) | (~d & c);
147
+ g = (5 * j + 1) & 15;
148
+ } else if (j < 48) {
149
+ f = b ^ c ^ d;
150
+ g = (3 * j + 5) & 15;
151
+ } else {
152
+ f = c ^ (b | ~d);
153
+ g = (7 * j) & 15;
154
+ }
155
+ const tmp = d,
156
+ rotateArg = (a + f + k[j] + w[g]) | 0,
157
+ rotate = r[j];
158
+ d = c;
159
+ c = b;
160
+ b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
161
+ a = tmp;
162
+ }
163
+ h0 = (h0 + a) | 0;
164
+ h1 = (h1 + b) | 0;
165
+ h2 = (h2 + c) | 0;
166
+ h3 = (h3 + d) | 0;
167
+ }
168
+ // prettier-ignore
169
+ return new Uint8Array([
170
+ h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
171
+ h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
172
+ h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
173
+ h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
174
+ ]);
175
+ }
176
+
177
+ return hash;
178
+ })();
179
+
180
+ class Word64 {
181
+ private low: number;
182
+ private high: number;
183
+
184
+ constructor(highInteger: number, lowInteger: number) {
185
+ this.high = highInteger | 0;
186
+ this.low = lowInteger | 0;
187
+ }
188
+
189
+ and(word: Word64) {
190
+ this.high &= word.high;
191
+ this.low &= word.low;
192
+ }
193
+
194
+ xor(word: Word64) {
195
+ this.high ^= word.high;
196
+ this.low ^= word.low;
197
+ }
198
+
199
+ or(word: Word64) {
200
+ this.high |= word.high;
201
+ this.low |= word.low;
202
+ }
203
+
204
+ shiftRight(places: number) {
205
+ if (places >= 32) {
206
+ this.low = (this.high >>> (places - 32)) | 0;
207
+ this.high = 0;
208
+ } else {
209
+ this.low = (this.low >>> places) | (this.high << (32 - places));
210
+ this.high = (this.high >>> places) | 0;
211
+ }
212
+ }
213
+
214
+ shiftLeft(places: number) {
215
+ if (places >= 32) {
216
+ this.high = this.low << (places - 32);
217
+ this.low = 0;
218
+ } else {
219
+ this.high = (this.high << places) | (this.low >>> (32 - places));
220
+ this.low <<= places;
221
+ }
222
+ }
223
+
224
+ rotateRight(places: number) {
225
+ let low, high;
226
+ if (places & 32) {
227
+ high = this.low;
228
+ low = this.high;
229
+ } else {
230
+ low = this.low;
231
+ high = this.high;
232
+ }
233
+ places &= 31;
234
+ this.low = (low >>> places) | (high << (32 - places));
235
+ this.high = (high >>> places) | (low << (32 - places));
236
+ }
237
+
238
+ not() {
239
+ this.high = ~this.high;
240
+ this.low = ~this.low;
241
+ }
242
+
243
+ add(word: Word64) {
244
+ const lowAdd = (this.low >>> 0) + (word.low >>> 0);
245
+ let highAdd = (this.high >>> 0) + (word.high >>> 0);
246
+ if (lowAdd > 0xffffffff) {
247
+ highAdd += 1;
248
+ }
249
+ this.low = lowAdd | 0;
250
+ this.high = highAdd | 0;
251
+ }
252
+
253
+ copyTo(bytes: Uint8Array, offset: number) {
254
+ bytes[offset] = (this.high >>> 24) & 0xff;
255
+ bytes[offset + 1] = (this.high >> 16) & 0xff;
256
+ bytes[offset + 2] = (this.high >> 8) & 0xff;
257
+ bytes[offset + 3] = this.high & 0xff;
258
+ bytes[offset + 4] = (this.low >>> 24) & 0xff;
259
+ bytes[offset + 5] = (this.low >> 16) & 0xff;
260
+ bytes[offset + 6] = (this.low >> 8) & 0xff;
261
+ bytes[offset + 7] = this.low & 0xff;
262
+ }
263
+
264
+ assign(word: Word64) {
265
+ this.high = word.high;
266
+ this.low = word.low;
267
+ }
268
+ }
269
+
270
+ const calculateSHA256 = (function calculateSHA256Closure() {
271
+ function rotr(x: number, n: number) {
272
+ return (x >>> n) | (x << (32 - n));
273
+ }
274
+
275
+ function ch(x: number, y: number, z: number) {
276
+ return (x & y) ^ (~x & z);
277
+ }
278
+
279
+ function maj(x: number, y: number, z: number) {
280
+ return (x & y) ^ (x & z) ^ (y & z);
281
+ }
282
+
283
+ function sigma(x: number) {
284
+ return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
285
+ }
286
+
287
+ function sigmaPrime(x: number) {
288
+ return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
289
+ }
290
+
291
+ function littleSigma(x: number) {
292
+ return rotr(x, 7) ^ rotr(x, 18) ^ (x >>> 3);
293
+ }
294
+
295
+ function littleSigmaPrime(x: number) {
296
+ return rotr(x, 17) ^ rotr(x, 19) ^ (x >>> 10);
297
+ }
298
+
299
+ const k = [
300
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
301
+ 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
302
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
303
+ 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
304
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
305
+ 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
306
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
307
+ 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
308
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
309
+ 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
310
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
311
+ ];
312
+
313
+ function hash(data: Uint8Array, offset: number, length: number) {
314
+ // initial hash values
315
+ let h0 = 0x6a09e667,
316
+ h1 = 0xbb67ae85,
317
+ h2 = 0x3c6ef372,
318
+ h3 = 0xa54ff53a,
319
+ h4 = 0x510e527f,
320
+ h5 = 0x9b05688c,
321
+ h6 = 0x1f83d9ab,
322
+ h7 = 0x5be0cd19;
323
+ // pre-processing
324
+ const paddedLength = Math.ceil((length + 9) / 64) * 64;
325
+ const padded = new Uint8Array(paddedLength);
326
+ let i, j;
327
+ for (i = 0; i < length; ++i) {
328
+ padded[i] = data[offset++];
329
+ }
330
+ padded[i++] = 0x80;
331
+ const n = paddedLength - 8;
332
+ while (i < n) {
333
+ padded[i++] = 0;
334
+ }
335
+ padded[i++] = 0;
336
+ padded[i++] = 0;
337
+ padded[i++] = 0;
338
+ padded[i++] = (length >>> 29) & 0xff;
339
+ padded[i++] = (length >> 21) & 0xff;
340
+ padded[i++] = (length >> 13) & 0xff;
341
+ padded[i++] = (length >> 5) & 0xff;
342
+ padded[i++] = (length << 3) & 0xff;
343
+ const w = new Uint32Array(64);
344
+ // for each 512 bit block
345
+ for (i = 0; i < paddedLength; ) {
346
+ for (j = 0; j < 16; ++j) {
347
+ w[j] =
348
+ (padded[i] << 24) |
349
+ (padded[i + 1] << 16) |
350
+ (padded[i + 2] << 8) |
351
+ padded[i + 3];
352
+ i += 4;
353
+ }
354
+
355
+ for (j = 16; j < 64; ++j) {
356
+ w[j] =
357
+ (littleSigmaPrime(w[j - 2]) +
358
+ w[j - 7] +
359
+ littleSigma(w[j - 15]) +
360
+ w[j - 16]) |
361
+ 0;
362
+ }
363
+ let a = h0,
364
+ b = h1,
365
+ c = h2,
366
+ d = h3,
367
+ e = h4,
368
+ f = h5,
369
+ g = h6,
370
+ h = h7,
371
+ t1,
372
+ t2;
373
+ for (j = 0; j < 64; ++j) {
374
+ t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
375
+ t2 = sigma(a) + maj(a, b, c);
376
+ h = g;
377
+ g = f;
378
+ f = e;
379
+ e = (d + t1) | 0;
380
+ d = c;
381
+ c = b;
382
+ b = a;
383
+ a = (t1 + t2) | 0;
384
+ }
385
+ h0 = (h0 + a) | 0;
386
+ h1 = (h1 + b) | 0;
387
+ h2 = (h2 + c) | 0;
388
+ h3 = (h3 + d) | 0;
389
+ h4 = (h4 + e) | 0;
390
+ h5 = (h5 + f) | 0;
391
+ h6 = (h6 + g) | 0;
392
+ h7 = (h7 + h) | 0;
393
+ }
394
+ // prettier-ignore
395
+ return new Uint8Array([
396
+ (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
397
+ (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
398
+ (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
399
+ (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
400
+ (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
401
+ (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
402
+ (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
403
+ (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
404
+ ]);
405
+ }
406
+
407
+ return hash;
408
+ })();
409
+
410
+ const calculateSHA512 = (function calculateSHA512Closure() {
411
+ function ch(result: Word64, x: Word64, y: Word64, z: Word64, tmp: Word64) {
412
+ result.assign(x);
413
+ result.and(y);
414
+ tmp.assign(x);
415
+ tmp.not();
416
+ tmp.and(z);
417
+ result.xor(tmp);
418
+ }
419
+
420
+ function maj(result: Word64, x: Word64, y: Word64, z: Word64, tmp: Word64) {
421
+ result.assign(x);
422
+ result.and(y);
423
+ tmp.assign(x);
424
+ tmp.and(z);
425
+ result.xor(tmp);
426
+ tmp.assign(y);
427
+ tmp.and(z);
428
+ result.xor(tmp);
429
+ }
430
+
431
+ function sigma(result: Word64, x: Word64, tmp: Word64) {
432
+ result.assign(x);
433
+ result.rotateRight(28);
434
+ tmp.assign(x);
435
+ tmp.rotateRight(34);
436
+ result.xor(tmp);
437
+ tmp.assign(x);
438
+ tmp.rotateRight(39);
439
+ result.xor(tmp);
440
+ }
441
+
442
+ function sigmaPrime(result: Word64, x: Word64, tmp: Word64) {
443
+ result.assign(x);
444
+ result.rotateRight(14);
445
+ tmp.assign(x);
446
+ tmp.rotateRight(18);
447
+ result.xor(tmp);
448
+ tmp.assign(x);
449
+ tmp.rotateRight(41);
450
+ result.xor(tmp);
451
+ }
452
+
453
+ function littleSigma(result: Word64, x: Word64, tmp: Word64) {
454
+ result.assign(x);
455
+ result.rotateRight(1);
456
+ tmp.assign(x);
457
+ tmp.rotateRight(8);
458
+ result.xor(tmp);
459
+ tmp.assign(x);
460
+ tmp.shiftRight(7);
461
+ result.xor(tmp);
462
+ }
463
+
464
+ function littleSigmaPrime(result: Word64, x: Word64, tmp: Word64) {
465
+ result.assign(x);
466
+ result.rotateRight(19);
467
+ tmp.assign(x);
468
+ tmp.rotateRight(61);
469
+ result.xor(tmp);
470
+ tmp.assign(x);
471
+ tmp.shiftRight(6);
472
+ result.xor(tmp);
473
+ }
474
+
475
+ // prettier-ignore
476
+ const k = [
477
+ new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
478
+ new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
479
+ new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
480
+ new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
481
+ new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
482
+ new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
483
+ new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
484
+ new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
485
+ new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
486
+ new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
487
+ new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
488
+ new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
489
+ new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
490
+ new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
491
+ new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
492
+ new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
493
+ new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
494
+ new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
495
+ new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
496
+ new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
497
+ new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
498
+ new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
499
+ new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
500
+ new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
501
+ new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
502
+ new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
503
+ new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
504
+ new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
505
+ new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
506
+ new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
507
+ new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
508
+ new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
509
+ new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
510
+ new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
511
+ new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
512
+ new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
513
+ new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
514
+ new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
515
+ new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
516
+ new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
517
+
518
+ function hash(
519
+ data: Uint8Array,
520
+ offset: number,
521
+ length: number,
522
+ mode384: boolean = false,
523
+ ) {
524
+ // initial hash values
525
+ let h0, h1, h2, h3, h4, h5, h6, h7;
526
+ if (!mode384) {
527
+ h0 = new Word64(0x6a09e667, 0xf3bcc908);
528
+ h1 = new Word64(0xbb67ae85, 0x84caa73b);
529
+ h2 = new Word64(0x3c6ef372, 0xfe94f82b);
530
+ h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
531
+ h4 = new Word64(0x510e527f, 0xade682d1);
532
+ h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
533
+ h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
534
+ h7 = new Word64(0x5be0cd19, 0x137e2179);
535
+ } else {
536
+ // SHA384 is exactly the same
537
+ // except with different starting values and a trimmed result
538
+ h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
539
+ h1 = new Word64(0x629a292a, 0x367cd507);
540
+ h2 = new Word64(0x9159015a, 0x3070dd17);
541
+ h3 = new Word64(0x152fecd8, 0xf70e5939);
542
+ h4 = new Word64(0x67332667, 0xffc00b31);
543
+ h5 = new Word64(0x8eb44a87, 0x68581511);
544
+ h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
545
+ h7 = new Word64(0x47b5481d, 0xbefa4fa4);
546
+ }
547
+
548
+ // pre-processing
549
+ const paddedLength = Math.ceil((length + 17) / 128) * 128;
550
+ const padded = new Uint8Array(paddedLength);
551
+ let i, j;
552
+ for (i = 0; i < length; ++i) {
553
+ padded[i] = data[offset++];
554
+ }
555
+ padded[i++] = 0x80;
556
+ const n = paddedLength - 16;
557
+ while (i < n) {
558
+ padded[i++] = 0;
559
+ }
560
+ padded[i++] = 0;
561
+ padded[i++] = 0;
562
+ padded[i++] = 0;
563
+ padded[i++] = 0;
564
+ padded[i++] = 0;
565
+ padded[i++] = 0;
566
+ padded[i++] = 0;
567
+ padded[i++] = 0;
568
+ padded[i++] = 0;
569
+ padded[i++] = 0;
570
+ padded[i++] = 0;
571
+ padded[i++] = (length >>> 29) & 0xff;
572
+ padded[i++] = (length >> 21) & 0xff;
573
+ padded[i++] = (length >> 13) & 0xff;
574
+ padded[i++] = (length >> 5) & 0xff;
575
+ padded[i++] = (length << 3) & 0xff;
576
+
577
+ const w = new Array(80);
578
+ for (i = 0; i < 80; i++) {
579
+ w[i] = new Word64(0, 0);
580
+ }
581
+ let a = new Word64(0, 0),
582
+ b = new Word64(0, 0),
583
+ c = new Word64(0, 0);
584
+ let d = new Word64(0, 0),
585
+ e = new Word64(0, 0),
586
+ f = new Word64(0, 0);
587
+ let g = new Word64(0, 0),
588
+ h = new Word64(0, 0);
589
+ const t1 = new Word64(0, 0),
590
+ t2 = new Word64(0, 0);
591
+ const tmp1 = new Word64(0, 0),
592
+ tmp2 = new Word64(0, 0);
593
+ let tmp3;
594
+
595
+ // for each 1024 bit block
596
+ for (i = 0; i < paddedLength; ) {
597
+ for (j = 0; j < 16; ++j) {
598
+ w[j].high =
599
+ (padded[i] << 24) |
600
+ (padded[i + 1] << 16) |
601
+ (padded[i + 2] << 8) |
602
+ padded[i + 3];
603
+ w[j].low =
604
+ (padded[i + 4] << 24) |
605
+ (padded[i + 5] << 16) |
606
+ (padded[i + 6] << 8) |
607
+ padded[i + 7];
608
+ i += 8;
609
+ }
610
+ for (j = 16; j < 80; ++j) {
611
+ tmp3 = w[j];
612
+ littleSigmaPrime(tmp3, w[j - 2], tmp2);
613
+ tmp3.add(w[j - 7]);
614
+ littleSigma(tmp1, w[j - 15], tmp2);
615
+ tmp3.add(tmp1);
616
+ tmp3.add(w[j - 16]);
617
+ }
618
+
619
+ a.assign(h0);
620
+ b.assign(h1);
621
+ c.assign(h2);
622
+ d.assign(h3);
623
+ e.assign(h4);
624
+ f.assign(h5);
625
+ g.assign(h6);
626
+ h.assign(h7);
627
+ for (j = 0; j < 80; ++j) {
628
+ t1.assign(h);
629
+ sigmaPrime(tmp1, e, tmp2);
630
+ t1.add(tmp1);
631
+ ch(tmp1, e, f, g, tmp2);
632
+ t1.add(tmp1);
633
+ t1.add(k[j]);
634
+ t1.add(w[j]);
635
+
636
+ sigma(t2, a, tmp2);
637
+ maj(tmp1, a, b, c, tmp2);
638
+ t2.add(tmp1);
639
+
640
+ tmp3 = h;
641
+ h = g;
642
+ g = f;
643
+ f = e;
644
+ d.add(t1);
645
+ e = d;
646
+ d = c;
647
+ c = b;
648
+ b = a;
649
+ tmp3.assign(t1);
650
+ tmp3.add(t2);
651
+ a = tmp3;
652
+ }
653
+ h0.add(a);
654
+ h1.add(b);
655
+ h2.add(c);
656
+ h3.add(d);
657
+ h4.add(e);
658
+ h5.add(f);
659
+ h6.add(g);
660
+ h7.add(h);
661
+ }
662
+
663
+ let result;
664
+ if (!mode384) {
665
+ result = new Uint8Array(64);
666
+ h0.copyTo(result, 0);
667
+ h1.copyTo(result, 8);
668
+ h2.copyTo(result, 16);
669
+ h3.copyTo(result, 24);
670
+ h4.copyTo(result, 32);
671
+ h5.copyTo(result, 40);
672
+ h6.copyTo(result, 48);
673
+ h7.copyTo(result, 56);
674
+ } else {
675
+ result = new Uint8Array(48);
676
+ h0.copyTo(result, 0);
677
+ h1.copyTo(result, 8);
678
+ h2.copyTo(result, 16);
679
+ h3.copyTo(result, 24);
680
+ h4.copyTo(result, 32);
681
+ h5.copyTo(result, 40);
682
+ }
683
+ return result;
684
+ }
685
+
686
+ return hash;
687
+ })();
688
+
689
+ function calculateSHA384(data: Uint8Array, offset: number, length: number) {
690
+ return calculateSHA512(data, offset, length, /* mode384 = */ true);
691
+ }
692
+
693
+ class NullCipher {
694
+ decryptBlock(data: Uint8Array) {
695
+ return data;
696
+ }
697
+
698
+ encrypt(data: Uint8Array) {
699
+ return data;
700
+ }
701
+ }
702
+
703
+ class AESBaseCipher {
704
+ protected _s: Uint8Array;
705
+ protected _keySize!: number;
706
+ protected _key!: Uint8Array;
707
+ protected _cyclesOfRepetition!: number;
708
+ private _inv_s: Uint8Array;
709
+ private _mix: Uint32Array;
710
+ private _mixCol: Uint8Array;
711
+ buffer: Uint8Array;
712
+ bufferPosition: number;
713
+ bufferLength!: number;
714
+ iv!: Uint8Array;
715
+
716
+ constructor() {
717
+ if (this.constructor === AESBaseCipher) {
718
+ throw new Error('Cannot initialize AESBaseCipher.');
719
+ }
720
+
721
+ this._s = new Uint8Array([
722
+ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
723
+ 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
724
+ 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
725
+ 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
726
+ 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
727
+ 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
728
+ 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
729
+ 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
730
+ 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
731
+ 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
732
+ 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
733
+ 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
734
+ 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
735
+ 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
736
+ 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
737
+ 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
738
+ 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
739
+ 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
740
+ 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
741
+ 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
742
+ 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
743
+ 0xb0, 0x54, 0xbb, 0x16,
744
+ ]);
745
+
746
+ this._inv_s = new Uint8Array([
747
+ 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
748
+ 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
749
+ 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
750
+ 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
751
+ 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
752
+ 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
753
+ 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
754
+ 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
755
+ 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
756
+ 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
757
+ 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
758
+ 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
759
+ 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
760
+ 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
761
+ 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
762
+ 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
763
+ 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
764
+ 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
765
+ 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
766
+ 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
767
+ 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
768
+ 0x55, 0x21, 0x0c, 0x7d,
769
+ ]);
770
+
771
+ this._mix = new Uint32Array([
772
+ 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
773
+ 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
774
+ 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
775
+ 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
776
+ 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
777
+ 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
778
+ 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
779
+ 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
780
+ 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
781
+ 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
782
+ 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
783
+ 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
784
+ 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
785
+ 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
786
+ 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
787
+ 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
788
+ 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
789
+ 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
790
+ 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
791
+ 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
792
+ 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
793
+ 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
794
+ 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
795
+ 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
796
+ 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
797
+ 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
798
+ 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
799
+ 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
800
+ 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
801
+ 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
802
+ 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
803
+ 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
804
+ 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
805
+ 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
806
+ 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
807
+ 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
808
+ 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
809
+ 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
810
+ 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
811
+ 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
812
+ 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
813
+ 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
814
+ 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3,
815
+ ]);
816
+
817
+ this._mixCol = new Uint8Array(256);
818
+ for (let i = 0; i < 256; i++) {
819
+ if (i < 128) {
820
+ this._mixCol[i] = i << 1;
821
+ } else {
822
+ this._mixCol[i] = (i << 1) ^ 0x1b;
823
+ }
824
+ }
825
+
826
+ this.buffer = new Uint8Array(16);
827
+ this.bufferPosition = 0;
828
+ }
829
+
830
+ _expandKey(_cipherKey: Uint8Array) {
831
+ throw new Error('Cannot call `_expandKey` on the base class');
832
+ }
833
+
834
+ _decrypt(input: Uint8Array, key: Uint8Array) {
835
+ let t, u, v;
836
+ const state = new Uint8Array(16);
837
+ state.set(input);
838
+
839
+ // AddRoundKey
840
+ for (let j = 0, k = this._keySize; j < 16; ++j, ++k) {
841
+ state[j] ^= key[k];
842
+ }
843
+ for (let i = this._cyclesOfRepetition - 1; i >= 1; --i) {
844
+ // InvShiftRows
845
+ t = state[13];
846
+ state[13] = state[9];
847
+ state[9] = state[5];
848
+ state[5] = state[1];
849
+ state[1] = t;
850
+ t = state[14];
851
+ u = state[10];
852
+ state[14] = state[6];
853
+ state[10] = state[2];
854
+ state[6] = t;
855
+ state[2] = u;
856
+ t = state[15];
857
+ u = state[11];
858
+ v = state[7];
859
+ state[15] = state[3];
860
+ state[11] = t;
861
+ state[7] = u;
862
+ state[3] = v;
863
+ // InvSubBytes
864
+ for (let j = 0; j < 16; ++j) {
865
+ state[j] = this._inv_s[state[j]];
866
+ }
867
+ // AddRoundKey
868
+ for (let j = 0, k = i * 16; j < 16; ++j, ++k) {
869
+ state[j] ^= key[k];
870
+ }
871
+ // InvMixColumns
872
+ for (let j = 0; j < 16; j += 4) {
873
+ const s0 = this._mix[state[j]];
874
+ const s1 = this._mix[state[j + 1]];
875
+ const s2 = this._mix[state[j + 2]];
876
+ const s3 = this._mix[state[j + 3]];
877
+ t =
878
+ s0 ^
879
+ (s1 >>> 8) ^
880
+ (s1 << 24) ^
881
+ (s2 >>> 16) ^
882
+ (s2 << 16) ^
883
+ (s3 >>> 24) ^
884
+ (s3 << 8);
885
+ state[j] = (t >>> 24) & 0xff;
886
+ state[j + 1] = (t >> 16) & 0xff;
887
+ state[j + 2] = (t >> 8) & 0xff;
888
+ state[j + 3] = t & 0xff;
889
+ }
890
+ }
891
+ // InvShiftRows
892
+ t = state[13];
893
+ state[13] = state[9];
894
+ state[9] = state[5];
895
+ state[5] = state[1];
896
+ state[1] = t;
897
+ t = state[14];
898
+ u = state[10];
899
+ state[14] = state[6];
900
+ state[10] = state[2];
901
+ state[6] = t;
902
+ state[2] = u;
903
+ t = state[15];
904
+ u = state[11];
905
+ v = state[7];
906
+ state[15] = state[3];
907
+ state[11] = t;
908
+ state[7] = u;
909
+ state[3] = v;
910
+ for (let j = 0; j < 16; ++j) {
911
+ // InvSubBytes
912
+ state[j] = this._inv_s[state[j]];
913
+ // AddRoundKey
914
+ state[j] ^= key[j];
915
+ }
916
+ return state;
917
+ }
918
+
919
+ _encrypt(input: Uint8Array, key: Uint8Array) {
920
+ const s = this._s;
921
+
922
+ let t, u, v;
923
+ const state = new Uint8Array(16);
924
+ state.set(input);
925
+
926
+ for (let j = 0; j < 16; ++j) {
927
+ // AddRoundKey
928
+ state[j] ^= key[j];
929
+ }
930
+
931
+ for (let i = 1; i < this._cyclesOfRepetition; i++) {
932
+ // SubBytes
933
+ for (let j = 0; j < 16; ++j) {
934
+ state[j] = s[state[j]];
935
+ }
936
+ // ShiftRows
937
+ v = state[1];
938
+ state[1] = state[5];
939
+ state[5] = state[9];
940
+ state[9] = state[13];
941
+ state[13] = v;
942
+ v = state[2];
943
+ u = state[6];
944
+ state[2] = state[10];
945
+ state[6] = state[14];
946
+ state[10] = v;
947
+ state[14] = u;
948
+ v = state[3];
949
+ u = state[7];
950
+ t = state[11];
951
+ state[3] = state[15];
952
+ state[7] = v;
953
+ state[11] = u;
954
+ state[15] = t;
955
+ // MixColumns
956
+ for (let j = 0; j < 16; j += 4) {
957
+ const s0 = state[j + 0];
958
+ const s1 = state[j + 1];
959
+ const s2 = state[j + 2];
960
+ const s3 = state[j + 3];
961
+ t = s0 ^ s1 ^ s2 ^ s3;
962
+ state[j + 0] ^= t ^ this._mixCol[s0 ^ s1];
963
+ state[j + 1] ^= t ^ this._mixCol[s1 ^ s2];
964
+ state[j + 2] ^= t ^ this._mixCol[s2 ^ s3];
965
+ state[j + 3] ^= t ^ this._mixCol[s3 ^ s0];
966
+ }
967
+ // AddRoundKey
968
+ for (let j = 0, k = i * 16; j < 16; ++j, ++k) {
969
+ state[j] ^= key[k];
970
+ }
971
+ }
972
+
973
+ // SubBytes
974
+ for (let j = 0; j < 16; ++j) {
975
+ state[j] = s[state[j]];
976
+ }
977
+ // ShiftRows
978
+ v = state[1];
979
+ state[1] = state[5];
980
+ state[5] = state[9];
981
+ state[9] = state[13];
982
+ state[13] = v;
983
+ v = state[2];
984
+ u = state[6];
985
+ state[2] = state[10];
986
+ state[6] = state[14];
987
+ state[10] = v;
988
+ state[14] = u;
989
+ v = state[3];
990
+ u = state[7];
991
+ t = state[11];
992
+ state[3] = state[15];
993
+ state[7] = v;
994
+ state[11] = u;
995
+ state[15] = t;
996
+ // AddRoundKey
997
+ for (let j = 0, k = this._keySize; j < 16; ++j, ++k) {
998
+ state[j] ^= key[k];
999
+ }
1000
+ return state;
1001
+ }
1002
+
1003
+ _decryptBlock2(data: Uint8Array, finalize: boolean) {
1004
+ const sourceLength = data.length;
1005
+ let buffer = this.buffer,
1006
+ bufferLength = this.bufferPosition;
1007
+ const result: Uint8Array[] = [];
1008
+ let iv = this.iv;
1009
+
1010
+ for (let i = 0; i < sourceLength; ++i) {
1011
+ buffer[bufferLength] = data[i];
1012
+ ++bufferLength;
1013
+ if (bufferLength < 16) {
1014
+ continue;
1015
+ }
1016
+ // buffer is full, decrypting
1017
+ const plain = this._decrypt(buffer, this._key);
1018
+ // xor-ing the IV vector to get plain text
1019
+ for (let j = 0; j < 16; ++j) {
1020
+ plain[j] ^= iv[j];
1021
+ }
1022
+ iv = buffer;
1023
+ result.push(plain);
1024
+ buffer = new Uint8Array(16);
1025
+ bufferLength = 0;
1026
+ }
1027
+ // saving incomplete buffer
1028
+ this.buffer = buffer;
1029
+ this.bufferLength = bufferLength;
1030
+ this.iv = iv;
1031
+ if (result.length === 0) {
1032
+ return new Uint8Array(0);
1033
+ }
1034
+ // combining plain text blocks into one
1035
+ let outputLength = 16 * result.length;
1036
+ if (finalize) {
1037
+ // undo a padding that is described in RFC 2898
1038
+ const lastBlock = result[result.length - 1];
1039
+ let psLen = lastBlock[15];
1040
+ if (psLen <= 16) {
1041
+ for (let i = 15, ii = 16 - psLen; i >= ii; --i) {
1042
+ if (lastBlock[i] !== psLen) {
1043
+ // Invalid padding, assume that the block has no padding.
1044
+ psLen = 0;
1045
+ break;
1046
+ }
1047
+ }
1048
+ outputLength -= psLen;
1049
+ result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
1050
+ }
1051
+ }
1052
+ const output = new Uint8Array(outputLength);
1053
+ for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
1054
+ output.set(result[i], j);
1055
+ }
1056
+ return output;
1057
+ }
1058
+
1059
+ decryptBlock(
1060
+ data: Uint8Array,
1061
+ finalize: boolean,
1062
+ iv?: Uint8Array,
1063
+ ): Uint8Array {
1064
+ const sourceLength = data.length;
1065
+ const buffer = this.buffer;
1066
+ let bufferLength = this.bufferPosition;
1067
+ // If an IV is not supplied, wait for IV values. They are at the start
1068
+ // of the stream.
1069
+ if (iv) {
1070
+ this.iv = iv;
1071
+ } else {
1072
+ for (
1073
+ let i = 0;
1074
+ bufferLength < 16 && i < sourceLength;
1075
+ ++i, ++bufferLength
1076
+ ) {
1077
+ buffer[bufferLength] = data[i];
1078
+ }
1079
+ if (bufferLength < 16) {
1080
+ // Need more data.
1081
+ this.bufferLength = bufferLength;
1082
+ return new Uint8Array(0);
1083
+ }
1084
+ this.iv = buffer;
1085
+ data = data.subarray(16);
1086
+ }
1087
+ this.buffer = new Uint8Array(16);
1088
+ this.bufferLength = 0;
1089
+ // starting decryption
1090
+ this.decryptBlock = this._decryptBlock2;
1091
+ return this.decryptBlock(data, finalize);
1092
+ }
1093
+
1094
+ encrypt(data: Uint8Array, iv: Uint8Array) {
1095
+ const sourceLength = data.length;
1096
+ let buffer = this.buffer,
1097
+ bufferLength = this.bufferPosition;
1098
+ const result = [];
1099
+
1100
+ if (!iv) {
1101
+ iv = new Uint8Array(16);
1102
+ }
1103
+ for (let i = 0; i < sourceLength; ++i) {
1104
+ buffer[bufferLength] = data[i];
1105
+ ++bufferLength;
1106
+ if (bufferLength < 16) {
1107
+ continue;
1108
+ }
1109
+
1110
+ for (let j = 0; j < 16; ++j) {
1111
+ buffer[j] ^= iv[j];
1112
+ }
1113
+
1114
+ // buffer is full, encrypting
1115
+ const cipher = this._encrypt(buffer, this._key);
1116
+ iv = cipher;
1117
+ result.push(cipher);
1118
+ buffer = new Uint8Array(16);
1119
+ bufferLength = 0;
1120
+ }
1121
+ // saving incomplete buffer
1122
+ this.buffer = buffer;
1123
+ this.bufferLength = bufferLength;
1124
+ this.iv = iv;
1125
+ if (result.length === 0) {
1126
+ return new Uint8Array(0);
1127
+ }
1128
+ // combining plain text blocks into one
1129
+ const outputLength = 16 * result.length;
1130
+ const output = new Uint8Array(outputLength);
1131
+ for (let i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
1132
+ output.set(result[i], j);
1133
+ }
1134
+ return output;
1135
+ }
1136
+ }
1137
+
1138
+ class AES128Cipher extends AESBaseCipher {
1139
+ private _rcon: Uint8Array;
1140
+
1141
+ constructor(key: Uint8Array) {
1142
+ super();
1143
+
1144
+ this._cyclesOfRepetition = 10;
1145
+ this._keySize = 160; // bits
1146
+
1147
+ this._rcon = new Uint8Array([
1148
+ 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
1149
+ 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
1150
+ 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
1151
+ 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
1152
+ 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
1153
+ 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
1154
+ 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
1155
+ 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
1156
+ 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
1157
+ 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
1158
+ 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
1159
+ 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
1160
+ 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
1161
+ 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
1162
+ 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
1163
+ 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
1164
+ 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
1165
+ 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
1166
+ 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
1167
+ 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
1168
+ 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
1169
+ 0x74, 0xe8, 0xcb, 0x8d,
1170
+ ]);
1171
+
1172
+ this._key = this._expandKey(key);
1173
+ }
1174
+
1175
+ _expandKey(cipherKey: Uint8Array) {
1176
+ const b = 176;
1177
+ const s = this._s;
1178
+ const rcon = this._rcon;
1179
+
1180
+ const result = new Uint8Array(b);
1181
+ result.set(cipherKey);
1182
+
1183
+ for (let j = 16, i = 1; j < b; ++i) {
1184
+ // RotWord
1185
+ let t1 = result[j - 3];
1186
+ let t2 = result[j - 2];
1187
+ let t3 = result[j - 1];
1188
+ let t4 = result[j - 4];
1189
+ // SubWord
1190
+ t1 = s[t1];
1191
+ t2 = s[t2];
1192
+ t3 = s[t3];
1193
+ t4 = s[t4];
1194
+ // Rcon
1195
+ t1 ^= rcon[i];
1196
+ for (let n = 0; n < 4; ++n) {
1197
+ result[j] = t1 ^= result[j - 16];
1198
+ j++;
1199
+ result[j] = t2 ^= result[j - 16];
1200
+ j++;
1201
+ result[j] = t3 ^= result[j - 16];
1202
+ j++;
1203
+ result[j] = t4 ^= result[j - 16];
1204
+ j++;
1205
+ }
1206
+ }
1207
+ return result;
1208
+ }
1209
+ }
1210
+
1211
+ class AES256Cipher extends AESBaseCipher {
1212
+ constructor(key: Uint8Array) {
1213
+ super();
1214
+
1215
+ this._cyclesOfRepetition = 14;
1216
+ this._keySize = 224; // bits
1217
+
1218
+ this._key = this._expandKey(key);
1219
+ }
1220
+
1221
+ _expandKey(cipherKey: Uint8Array) {
1222
+ const b = 240;
1223
+ const s = this._s;
1224
+
1225
+ const result = new Uint8Array(b);
1226
+ result.set(cipherKey);
1227
+
1228
+ let r = 1;
1229
+ let t1 = 0,
1230
+ t2 = 0,
1231
+ t3 = 0,
1232
+ t4 = 0;
1233
+ for (let j = 32, i = 1; j < b; ++i) {
1234
+ if (j % 32 === 16) {
1235
+ t1 = s[t1];
1236
+ t2 = s[t2];
1237
+ t3 = s[t3];
1238
+ t4 = s[t4];
1239
+ } else if (j % 32 === 0) {
1240
+ // RotWord
1241
+ t1 = result[j - 3];
1242
+ t2 = result[j - 2];
1243
+ t3 = result[j - 1];
1244
+ t4 = result[j - 4];
1245
+ // SubWord
1246
+ t1 = s[t1];
1247
+ t2 = s[t2];
1248
+ t3 = s[t3];
1249
+ t4 = s[t4];
1250
+ // Rcon
1251
+ t1 ^= r;
1252
+ if ((r <<= 1) >= 256) {
1253
+ r = (r ^ 0x1b) & 0xff;
1254
+ }
1255
+ }
1256
+
1257
+ for (let n = 0; n < 4; ++n) {
1258
+ result[j] = t1 ^= result[j - 32];
1259
+ j++;
1260
+ result[j] = t2 ^= result[j - 32];
1261
+ j++;
1262
+ result[j] = t3 ^= result[j - 32];
1263
+ j++;
1264
+ result[j] = t4 ^= result[j - 32];
1265
+ j++;
1266
+ }
1267
+ }
1268
+ return result;
1269
+ }
1270
+ }
1271
+
1272
+ class PDF17 {
1273
+ checkOwnerPassword(
1274
+ password: Uint8Array,
1275
+ ownerValidationSalt: Uint8Array,
1276
+ userBytes: Uint8Array,
1277
+ ownerPassword: Uint8Array,
1278
+ ) {
1279
+ const hashData = new Uint8Array(password.length + 56);
1280
+ hashData.set(password, 0);
1281
+ hashData.set(ownerValidationSalt, password.length);
1282
+ hashData.set(userBytes, password.length + ownerValidationSalt.length);
1283
+ const result = calculateSHA256(hashData, 0, hashData.length);
1284
+ return isArrayEqual(result, ownerPassword);
1285
+ }
1286
+
1287
+ checkUserPassword(
1288
+ password: Uint8Array,
1289
+ userValidationSalt: Uint8Array,
1290
+ userPassword: Uint8Array,
1291
+ ) {
1292
+ const hashData = new Uint8Array(password.length + 8);
1293
+ hashData.set(password, 0);
1294
+ hashData.set(userValidationSalt, password.length);
1295
+ const result = calculateSHA256(hashData, 0, hashData.length);
1296
+ return isArrayEqual(result, userPassword);
1297
+ }
1298
+
1299
+ getOwnerKey(
1300
+ password: Uint8Array,
1301
+ ownerKeySalt: Uint8Array,
1302
+ userBytes: Uint8Array,
1303
+ ownerEncryption: Uint8Array,
1304
+ ) {
1305
+ const hashData = new Uint8Array(password.length + 56);
1306
+ hashData.set(password, 0);
1307
+ hashData.set(ownerKeySalt, password.length);
1308
+ hashData.set(userBytes, password.length + ownerKeySalt.length);
1309
+ const key = calculateSHA256(hashData, 0, hashData.length);
1310
+ const cipher = new AES256Cipher(key);
1311
+ return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
1312
+ }
1313
+
1314
+ getUserKey(
1315
+ password: Uint8Array,
1316
+ userKeySalt: Uint8Array,
1317
+ userEncryption: Uint8Array,
1318
+ ) {
1319
+ const hashData = new Uint8Array(password.length + 8);
1320
+ hashData.set(password, 0);
1321
+ hashData.set(userKeySalt, password.length);
1322
+ // `key` is the decryption key for the UE string.
1323
+ const key = calculateSHA256(hashData, 0, hashData.length);
1324
+ const cipher = new AES256Cipher(key);
1325
+ return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
1326
+ }
1327
+ }
1328
+
1329
+ class PDF20 {
1330
+ calculatePDF20Hash(
1331
+ password: Uint8Array,
1332
+ input: Uint8Array,
1333
+ userBytes: Uint8Array,
1334
+ ) {
1335
+ // This refers to Algorithm 2.B as defined in ISO 32000-2.
1336
+ let k = calculateSHA256(input, 0, input.length).subarray(0, 32);
1337
+ let e: Uint8Array = new Uint8Array([0]);
1338
+ let i = 0;
1339
+ while (i < 64 || e[e.length - 1] > i - 32) {
1340
+ const combinedLength = password.length + k.length + userBytes.length,
1341
+ combinedArray = new Uint8Array(combinedLength);
1342
+ let writeOffset = 0;
1343
+ combinedArray.set(password, writeOffset);
1344
+ writeOffset += password.length;
1345
+ combinedArray.set(k, writeOffset);
1346
+ writeOffset += k.length;
1347
+ combinedArray.set(userBytes, writeOffset);
1348
+
1349
+ const k1 = new Uint8Array(combinedLength * 64);
1350
+ for (let j = 0, pos = 0; j < 64; j++, pos += combinedLength) {
1351
+ k1.set(combinedArray, pos);
1352
+ }
1353
+ // AES128 CBC NO PADDING with first 16 bytes of k as the key
1354
+ // and the second 16 as the iv.
1355
+ const cipher = new AES128Cipher(k.subarray(0, 16));
1356
+ e = cipher.encrypt(k1, k.subarray(16, 32));
1357
+ // Now we have to take the first 16 bytes of an unsigned big endian
1358
+ // integer and compute the remainder modulo 3. That is a fairly large
1359
+ // number and JavaScript isn't going to handle that well.
1360
+ // The number is e0 + 256 * e1 + 256^2 * e2... and 256 % 3 === 1, hence
1361
+ // the powers of 256 are === 1 modulo 3 and finally the number modulo 3
1362
+ // is equal to the remainder modulo 3 of the sum of the e_n.
1363
+ const remainder = e.slice(0, 16).reduce((a, b) => a + b, 0) % 3;
1364
+ if (remainder === 0) {
1365
+ k = calculateSHA256(e, 0, e.length);
1366
+ } else if (remainder === 1) {
1367
+ k = calculateSHA384(e, 0, e.length);
1368
+ } else if (remainder === 2) {
1369
+ k = calculateSHA512(e, 0, e.length);
1370
+ }
1371
+ i++;
1372
+ }
1373
+ return k.subarray(0, 32);
1374
+ }
1375
+
1376
+ hash(password: Uint8Array, concatBytes: Uint8Array, userBytes: Uint8Array) {
1377
+ return this.calculatePDF20Hash(password, concatBytes, userBytes);
1378
+ }
1379
+
1380
+ checkOwnerPassword(
1381
+ password: Uint8Array,
1382
+ ownerValidationSalt: Uint8Array,
1383
+ userBytes: Uint8Array,
1384
+ ownerPassword: Uint8Array,
1385
+ ) {
1386
+ const hashData = new Uint8Array(password.length + 56);
1387
+ hashData.set(password, 0);
1388
+ hashData.set(ownerValidationSalt, password.length);
1389
+ hashData.set(userBytes, password.length + ownerValidationSalt.length);
1390
+ const result = this.calculatePDF20Hash(password, hashData, userBytes);
1391
+ return isArrayEqual(result, ownerPassword);
1392
+ }
1393
+
1394
+ checkUserPassword(
1395
+ password: Uint8Array,
1396
+ userValidationSalt: Uint8Array,
1397
+ userPassword: Uint8Array,
1398
+ ) {
1399
+ const hashData = new Uint8Array(password.length + 8);
1400
+ hashData.set(password, 0);
1401
+ hashData.set(userValidationSalt, password.length);
1402
+ const result = this.calculatePDF20Hash(
1403
+ password,
1404
+ hashData,
1405
+ new Uint8Array(),
1406
+ );
1407
+ return isArrayEqual(result, userPassword);
1408
+ }
1409
+
1410
+ getOwnerKey(
1411
+ password: Uint8Array,
1412
+ ownerKeySalt: Uint8Array,
1413
+ userBytes: Uint8Array,
1414
+ ownerEncryption: Uint8Array,
1415
+ ) {
1416
+ const hashData = new Uint8Array(password.length + 56);
1417
+ hashData.set(password, 0);
1418
+ hashData.set(ownerKeySalt, password.length);
1419
+ hashData.set(userBytes, password.length + ownerKeySalt.length);
1420
+ const key = this.calculatePDF20Hash(password, hashData, userBytes);
1421
+ const cipher = new AES256Cipher(key);
1422
+ return cipher.decryptBlock(ownerEncryption, false, new Uint8Array(16));
1423
+ }
1424
+
1425
+ getUserKey(
1426
+ password: Uint8Array,
1427
+ userKeySalt: Uint8Array,
1428
+ userEncryption: Uint8Array,
1429
+ ) {
1430
+ const hashData = new Uint8Array(password.length + 8);
1431
+ hashData.set(password, 0);
1432
+ hashData.set(userKeySalt, password.length);
1433
+ // `key` is the decryption key for the UE string.
1434
+ const key = this.calculatePDF20Hash(password, hashData, new Uint8Array());
1435
+ const cipher = new AES256Cipher(key);
1436
+ return cipher.decryptBlock(userEncryption, false, new Uint8Array(16));
1437
+ }
1438
+ }
1439
+
1440
+ type Cipher = ARCFourCipher | NullCipher | AES128Cipher | AES256Cipher;
1441
+ class CipherTransform {
1442
+ private StringCipherConstructor: () => Cipher;
1443
+ private StreamCipherConstructor: () => Cipher;
1444
+
1445
+ constructor(
1446
+ stringCipherConstructor: () => Cipher,
1447
+ streamCipherConstructor: () => Cipher,
1448
+ ) {
1449
+ this.StringCipherConstructor = stringCipherConstructor;
1450
+ this.StreamCipherConstructor = streamCipherConstructor;
1451
+ }
1452
+
1453
+ createStream(stream: StreamType, length: number) {
1454
+ const cipher = this.StreamCipherConstructor();
1455
+ return new DecryptStream(
1456
+ stream,
1457
+ function cipherTransformDecryptStream(data, finalize) {
1458
+ return cipher.decryptBlock(data as Uint8Array, finalize);
1459
+ },
1460
+ length,
1461
+ );
1462
+ }
1463
+
1464
+ decryptString(s: string) {
1465
+ const cipher = this.StringCipherConstructor();
1466
+ let data = stringAsByteArray(s);
1467
+ data = cipher.decryptBlock(data, true);
1468
+ return arrayAsString(data);
1469
+ }
1470
+
1471
+ decryptBytes(d: Uint8Array) {
1472
+ const cipher = this.StringCipherConstructor();
1473
+ return cipher.decryptBlock(d, true);
1474
+ }
1475
+
1476
+ encryptString(s: string) {
1477
+ const cipher = this.StringCipherConstructor();
1478
+ if (cipher instanceof AESBaseCipher) {
1479
+ // Append some chars equal to "16 - (M mod 16)"
1480
+ // where M is the string length (see section 7.6.2 in PDF specification)
1481
+ // to have a final string where the length is a multiple of 16.
1482
+ // Special note:
1483
+ // "Note that the pad is present when M is evenly divisible by 16;
1484
+ // it contains 16 bytes of 0x10."
1485
+ const strLen = s.length;
1486
+ const pad = 16 - (strLen % 16);
1487
+ s += String.fromCharCode(pad).repeat(pad);
1488
+
1489
+ // Generate an initialization vector
1490
+ const iv = new Uint8Array(16);
1491
+ if (typeof crypto !== 'undefined') {
1492
+ crypto.getRandomValues(iv);
1493
+ } else {
1494
+ for (let i = 0; i < 16; i++) {
1495
+ iv[i] = Math.floor(256 * Math.random());
1496
+ }
1497
+ }
1498
+
1499
+ let data = stringAsByteArray(s);
1500
+ data = cipher.encrypt(data, iv);
1501
+
1502
+ const buf = new Uint8Array(16 + data.length);
1503
+ buf.set(iv);
1504
+ buf.set(data, 16);
1505
+
1506
+ return arrayAsString(buf);
1507
+ }
1508
+
1509
+ let data = stringAsByteArray(s);
1510
+ data = cipher.encrypt(data);
1511
+ return arrayAsString(data);
1512
+ }
1513
+ }
1514
+
1515
+ // eslint-disable-next-line no-shadow
1516
+ class CipherTransformFactory {
1517
+ encryptMetadata: boolean;
1518
+ encryptionKey: Uint8Array;
1519
+ algorithm: number;
1520
+ filterName: string;
1521
+ dict: PDFDict;
1522
+ cf!: PDFDict;
1523
+ stmf!: PDFName;
1524
+ strf!: PDFName;
1525
+ eff!: PDFName;
1526
+
1527
+ private defaultPasswordBytes = new Uint8Array([
1528
+ 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56,
1529
+ 0xff, 0xfa, 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80,
1530
+ 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a,
1531
+ ]);
1532
+ private identityName = PDFName.of('Identity');
1533
+
1534
+ constructor(dict: PDFDict, fileIdBytes: Uint8Array, password?: string) {
1535
+ const filter = dict.get(PDFName.of('Filter')) as PDFName;
1536
+ if (filter.asString() !== '/Standard') {
1537
+ throw new Error('unknown encryption method');
1538
+ }
1539
+ this.filterName = filter.asString();
1540
+ this.dict = dict;
1541
+ const algorithm = (dict.get(PDFName.of('V')) as PDFNumber).asNumber();
1542
+ if (
1543
+ !Number.isInteger(algorithm) ||
1544
+ (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5)
1545
+ ) {
1546
+ throw new Error('unsupported encryption algorithm');
1547
+ }
1548
+ this.algorithm = algorithm;
1549
+ let keyLength = (
1550
+ dict.get(PDFName.of('Length')) as PDFNumber | undefined
1551
+ )?.asNumber();
1552
+ if (!keyLength) {
1553
+ // Spec asks to rely on encryption dictionary's Length entry, however
1554
+ // some PDFs don't have it. Trying to recover.
1555
+ if (algorithm <= 3) {
1556
+ // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
1557
+ keyLength = 40;
1558
+ } else {
1559
+ // Trying to find default handler -- it usually has Length.
1560
+ const cfDict = dict.get(PDFName.of('CF')) as PDFDict;
1561
+ const streamCryptoName = dict.get(PDFName.of('StmF')) as PDFName;
1562
+ if (cfDict instanceof PDFDict && streamCryptoName instanceof PDFName) {
1563
+ cfDict.suppressEncryption = true;
1564
+ const handlerDict = cfDict.get(
1565
+ PDFName.of(streamCryptoName.asString()),
1566
+ ) as PDFDict;
1567
+ let keyLen: PDFNumber | null = null;
1568
+ if (handlerDict) {
1569
+ keyLen = handlerDict.get(PDFName.of('Length')) as PDFNumber;
1570
+ }
1571
+ keyLength = (keyLen && keyLen.asNumber()) || 128;
1572
+ if (keyLength < 40) {
1573
+ // Sometimes it's incorrect value of bits, generators specify
1574
+ // bytes.
1575
+ keyLength <<= 3;
1576
+ }
1577
+ }
1578
+ }
1579
+ }
1580
+ if (
1581
+ keyLength === undefined ||
1582
+ !Number.isInteger(keyLength) ||
1583
+ keyLength < 40 ||
1584
+ keyLength % 8 !== 0
1585
+ ) {
1586
+ throw new Error(`invalid key length: ${keyLength}`);
1587
+ }
1588
+
1589
+ const oPdfStr = (dict.get(PDFName.of('O')) as PDFString).asBytes();
1590
+ const uPdfStr = (dict.get(PDFName.of('U')) as PDFString).asBytes();
1591
+ // prepare keys
1592
+ const ownerPassword = oPdfStr.subarray(0, 32);
1593
+ const userPassword = uPdfStr.subarray(0, 32);
1594
+ const flags = (dict.get(PDFName.of('P')) as PDFNumber).asNumber();
1595
+ const revision = (dict.get(PDFName.of('R')) as PDFNumber).asNumber();
1596
+ // meaningful when V is 4 or 5
1597
+ const encryptMetadata =
1598
+ (algorithm === 4 || algorithm === 5) &&
1599
+ (dict.get(PDFName.of('EncryptMetadata')) as PDFBool)?.asBoolean() !==
1600
+ false;
1601
+ this.encryptMetadata = encryptMetadata;
1602
+
1603
+ let passwordBytes: Uint8Array | undefined;
1604
+ if (password) {
1605
+ if (revision === 6) {
1606
+ try {
1607
+ password = unescape(encodeURIComponent(password));
1608
+ } catch (ex) {
1609
+ console.warn(
1610
+ 'CipherTransformFactory: ' +
1611
+ 'Unable to convert UTF8 encoded password.',
1612
+ );
1613
+ }
1614
+ }
1615
+ passwordBytes = stringAsByteArray(password!);
1616
+ }
1617
+
1618
+ let encryptionKey;
1619
+ if (algorithm !== 5) {
1620
+ encryptionKey = this.prepareKeyData(
1621
+ fileIdBytes,
1622
+ passwordBytes,
1623
+ ownerPassword,
1624
+ userPassword,
1625
+ flags,
1626
+ revision,
1627
+ keyLength,
1628
+ encryptMetadata,
1629
+ );
1630
+ } else {
1631
+ const ownerValidationSalt = oPdfStr.subarray(32, 40);
1632
+ const ownerKeySalt = oPdfStr.subarray(40, 48);
1633
+ const uBytes = uPdfStr.subarray(0, 48);
1634
+ const userValidationSalt = uPdfStr.subarray(32, 40);
1635
+ const userKeySalt = uPdfStr.subarray(40, 48);
1636
+
1637
+ const ownerEncryption = (
1638
+ dict.get(PDFName.of('OE')) as PDFString
1639
+ ).asBytes();
1640
+ const userEncryption = (
1641
+ dict.get(PDFName.of('UE')) as PDFString
1642
+ ).asBytes();
1643
+ const perms = (dict.get(PDFName.of('Perms')) as PDFString).asBytes();
1644
+ encryptionKey = this.createEncryptionKey20(
1645
+ revision,
1646
+ passwordBytes,
1647
+ ownerPassword,
1648
+ ownerValidationSalt,
1649
+ ownerKeySalt,
1650
+ uBytes,
1651
+ userPassword,
1652
+ userValidationSalt,
1653
+ userKeySalt,
1654
+ ownerEncryption,
1655
+ userEncryption,
1656
+ perms,
1657
+ );
1658
+ }
1659
+ if (!encryptionKey && !password) {
1660
+ throw new Error('NEEDS PASSWORD');
1661
+ } else if (!encryptionKey && password) {
1662
+ // Attempting use the password as an owner password
1663
+ const decodedPassword = this.decodeUserPassword(
1664
+ passwordBytes!,
1665
+ ownerPassword,
1666
+ revision,
1667
+ keyLength,
1668
+ );
1669
+ encryptionKey = this.prepareKeyData(
1670
+ fileIdBytes,
1671
+ decodedPassword,
1672
+ ownerPassword,
1673
+ userPassword,
1674
+ flags,
1675
+ revision,
1676
+ keyLength,
1677
+ encryptMetadata,
1678
+ );
1679
+ }
1680
+
1681
+ if (!encryptionKey) {
1682
+ throw new Error('Password incorrect');
1683
+ }
1684
+
1685
+ this.encryptionKey = encryptionKey;
1686
+
1687
+ if (algorithm >= 4) {
1688
+ const cf = dict.get(PDFName.of('CF')) as PDFDict;
1689
+ if (cf instanceof PDFDict) {
1690
+ // The 'CF' dictionary itself should not be encrypted, and by setting
1691
+ // `suppressEncryption` we can prevent an infinite loop inside of
1692
+ // `XRef_fetchUncompressed` if the dictionary contains indirect
1693
+ // objects (fixes issue7665.pdf).
1694
+ cf.suppressEncryption = true;
1695
+ }
1696
+ this.cf = cf;
1697
+ this.stmf =
1698
+ (dict.get(PDFName.of('StmF')) as PDFName) || this.identityName;
1699
+ this.strf =
1700
+ (dict.get(PDFName.of('StrF')) as PDFName) || this.identityName;
1701
+ this.eff = (dict.get(PDFName.of('EFF')) as PDFName) || this.stmf;
1702
+ }
1703
+ }
1704
+
1705
+ createCipherTransform(num: number, gen: number) {
1706
+ if (this.algorithm === 4 || this.algorithm === 5) {
1707
+ return new CipherTransform(
1708
+ this.buildCipherConstructor(
1709
+ this.cf,
1710
+ this.strf,
1711
+ num,
1712
+ gen,
1713
+ this.encryptionKey,
1714
+ ),
1715
+ this.buildCipherConstructor(
1716
+ this.cf,
1717
+ this.stmf,
1718
+ num,
1719
+ gen,
1720
+ this.encryptionKey,
1721
+ ),
1722
+ );
1723
+ }
1724
+ // algorithms 1 and 2
1725
+ const key = this.buildObjectKey(
1726
+ num,
1727
+ gen,
1728
+ this.encryptionKey,
1729
+ /* isAes = */ false,
1730
+ );
1731
+ const cipherConstructor = function buildCipherCipherConstructor() {
1732
+ return new ARCFourCipher(key);
1733
+ };
1734
+ return new CipherTransform(cipherConstructor, cipherConstructor);
1735
+ }
1736
+
1737
+ createEncryptionKey20(
1738
+ revision: number,
1739
+ password: Uint8Array | undefined,
1740
+ ownerPassword: Uint8Array,
1741
+ ownerValidationSalt: Uint8Array,
1742
+ ownerKeySalt: Uint8Array,
1743
+ uBytes: Uint8Array,
1744
+ userPassword: Uint8Array,
1745
+ userValidationSalt: Uint8Array,
1746
+ userKeySalt: Uint8Array,
1747
+ ownerEncryption: Uint8Array,
1748
+ userEncryption: Uint8Array,
1749
+ _perms: Uint8Array,
1750
+ ) {
1751
+ if (password) {
1752
+ const passwordLength = Math.min(127, password.length);
1753
+ password = password.subarray(0, passwordLength);
1754
+ } else {
1755
+ password = new Uint8Array();
1756
+ }
1757
+ let pdfAlgorithm;
1758
+ if (revision === 6) {
1759
+ pdfAlgorithm = new PDF20();
1760
+ } else {
1761
+ pdfAlgorithm = new PDF17();
1762
+ }
1763
+
1764
+ if (
1765
+ pdfAlgorithm.checkUserPassword(password, userValidationSalt, userPassword)
1766
+ ) {
1767
+ return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
1768
+ } else if (
1769
+ password.length &&
1770
+ pdfAlgorithm.checkOwnerPassword(
1771
+ password,
1772
+ ownerValidationSalt,
1773
+ uBytes,
1774
+ ownerPassword,
1775
+ )
1776
+ ) {
1777
+ return pdfAlgorithm.getOwnerKey(
1778
+ password,
1779
+ ownerKeySalt,
1780
+ uBytes,
1781
+ ownerEncryption,
1782
+ );
1783
+ }
1784
+
1785
+ return null;
1786
+ }
1787
+
1788
+ prepareKeyData(
1789
+ fileId: Uint8Array,
1790
+ password: Uint8Array | undefined,
1791
+ ownerPassword: Uint8Array,
1792
+ userPassword: Uint8Array,
1793
+ flags: number,
1794
+ revision: number,
1795
+ keyLength: number,
1796
+ encryptMetadata: boolean,
1797
+ ) {
1798
+ const hashDataSize = 40 + ownerPassword.length + fileId.length;
1799
+ const hashData = new Uint8Array(hashDataSize);
1800
+ let i = 0,
1801
+ j,
1802
+ n;
1803
+ if (password) {
1804
+ n = Math.min(32, password.length);
1805
+ for (; i < n; ++i) {
1806
+ hashData[i] = password[i];
1807
+ }
1808
+ }
1809
+ j = 0;
1810
+ while (i < 32) {
1811
+ hashData[i++] = this.defaultPasswordBytes[j++];
1812
+ }
1813
+ // as now the padded password in the hashData[0..i]
1814
+ for (j = 0, n = ownerPassword.length; j < n; ++j) {
1815
+ hashData[i++] = ownerPassword[j];
1816
+ }
1817
+ hashData[i++] = flags & 0xff;
1818
+ hashData[i++] = (flags >> 8) & 0xff;
1819
+ hashData[i++] = (flags >> 16) & 0xff;
1820
+ hashData[i++] = (flags >>> 24) & 0xff;
1821
+ for (j = 0, n = fileId.length; j < n; ++j) {
1822
+ hashData[i++] = fileId[j];
1823
+ }
1824
+ if (revision >= 4 && !encryptMetadata) {
1825
+ hashData[i++] = 0xff;
1826
+ hashData[i++] = 0xff;
1827
+ hashData[i++] = 0xff;
1828
+ hashData[i++] = 0xff;
1829
+ }
1830
+ let hash = calculateMD5(hashData, 0, i);
1831
+ const keyLengthInBytes = keyLength >> 3;
1832
+ if (revision >= 3) {
1833
+ for (j = 0; j < 50; ++j) {
1834
+ hash = calculateMD5(hash, 0, keyLengthInBytes);
1835
+ }
1836
+ }
1837
+ const encryptionKey = hash.subarray(0, keyLengthInBytes);
1838
+ let cipher, checkData;
1839
+
1840
+ if (revision >= 3) {
1841
+ for (i = 0; i < 32; ++i) {
1842
+ hashData[i] = this.defaultPasswordBytes[i];
1843
+ }
1844
+ for (j = 0, n = fileId.length; j < n; ++j) {
1845
+ hashData[i++] = fileId[j];
1846
+ }
1847
+ cipher = new ARCFourCipher(encryptionKey);
1848
+ checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
1849
+ n = encryptionKey.length;
1850
+ const derivedKey = new Uint8Array(n);
1851
+ for (j = 1; j <= 19; ++j) {
1852
+ for (let k = 0; k < n; ++k) {
1853
+ derivedKey[k] = encryptionKey[k] ^ j;
1854
+ }
1855
+ cipher = new ARCFourCipher(derivedKey);
1856
+ checkData = cipher.encryptBlock(checkData);
1857
+ }
1858
+ for (j = 0, n = checkData.length; j < n; ++j) {
1859
+ if (userPassword[j] !== checkData[j]) {
1860
+ return null;
1861
+ }
1862
+ }
1863
+ } else {
1864
+ cipher = new ARCFourCipher(encryptionKey);
1865
+ checkData = cipher.encryptBlock(this.defaultPasswordBytes);
1866
+ for (j = 0, n = checkData.length; j < n; ++j) {
1867
+ if (userPassword[j] !== checkData[j]) {
1868
+ return null;
1869
+ }
1870
+ }
1871
+ }
1872
+ return encryptionKey;
1873
+ }
1874
+
1875
+ decodeUserPassword(
1876
+ password: Uint8Array,
1877
+ ownerPassword: Uint8Array,
1878
+ revision: number,
1879
+ keyLength: number,
1880
+ ) {
1881
+ const hashData = new Uint8Array(32);
1882
+ let i = 0;
1883
+ const n = Math.min(32, password.length);
1884
+ for (; i < n; ++i) {
1885
+ hashData[i] = password[i];
1886
+ }
1887
+ let j = 0;
1888
+ while (i < 32) {
1889
+ hashData[i++] = this.defaultPasswordBytes[j++];
1890
+ }
1891
+ let hash = calculateMD5(hashData, 0, i);
1892
+ const keyLengthInBytes = keyLength >> 3;
1893
+ if (revision >= 3) {
1894
+ for (j = 0; j < 50; ++j) {
1895
+ hash = calculateMD5(hash, 0, hash.length);
1896
+ }
1897
+ }
1898
+
1899
+ let cipher, userPassword;
1900
+ if (revision >= 3) {
1901
+ userPassword = ownerPassword;
1902
+ const derivedKey = new Uint8Array(keyLengthInBytes);
1903
+ for (j = 19; j >= 0; j--) {
1904
+ for (let k = 0; k < keyLengthInBytes; ++k) {
1905
+ derivedKey[k] = hash[k] ^ j;
1906
+ }
1907
+ cipher = new ARCFourCipher(derivedKey);
1908
+ userPassword = cipher.encryptBlock(userPassword);
1909
+ }
1910
+ } else {
1911
+ cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
1912
+ userPassword = cipher.encryptBlock(ownerPassword);
1913
+ }
1914
+ return userPassword;
1915
+ }
1916
+
1917
+ buildObjectKey(
1918
+ num: number,
1919
+ gen: number,
1920
+ encryptionKey: Uint8Array,
1921
+ isAes: boolean = false,
1922
+ ) {
1923
+ const key = new Uint8Array(encryptionKey.length + 9);
1924
+ const n = encryptionKey.length;
1925
+ let i;
1926
+ for (i = 0; i < n; ++i) {
1927
+ key[i] = encryptionKey[i];
1928
+ }
1929
+ key[i++] = num & 0xff;
1930
+ key[i++] = (num >> 8) & 0xff;
1931
+ key[i++] = (num >> 16) & 0xff;
1932
+ key[i++] = gen & 0xff;
1933
+ key[i++] = (gen >> 8) & 0xff;
1934
+ if (isAes) {
1935
+ key[i++] = 0x73;
1936
+ key[i++] = 0x41;
1937
+ key[i++] = 0x6c;
1938
+ key[i++] = 0x54;
1939
+ }
1940
+ const hash = calculateMD5(key, 0, i);
1941
+ return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
1942
+ }
1943
+
1944
+ buildCipherConstructor(
1945
+ cf: PDFDict,
1946
+ name: PDFName,
1947
+ num: number,
1948
+ gen: number,
1949
+ key: Uint8Array,
1950
+ ) {
1951
+ if (!(name instanceof PDFName)) {
1952
+ throw new Error('Invalid crypt filter name.');
1953
+ }
1954
+ const cryptFilter = cf.get(
1955
+ PDFName.of(name.asString().replace('/', '')),
1956
+ ) as PDFDict;
1957
+ let cfm;
1958
+ if (cryptFilter !== null && cryptFilter !== undefined) {
1959
+ cfm = cryptFilter.get(PDFName.of('CFM')) as PDFName;
1960
+ }
1961
+ if (!cfm || cfm.asString() === '/None') {
1962
+ return function cipherTransformFactoryBuildCipherConstructorNone() {
1963
+ return new NullCipher();
1964
+ };
1965
+ }
1966
+ if (cfm.asString() === '/V2') {
1967
+ return () =>
1968
+ new ARCFourCipher(
1969
+ this.buildObjectKey(num, gen, key, /* isAes = */ false),
1970
+ );
1971
+ }
1972
+ if (cfm.asString() === '/AESV2') {
1973
+ return () =>
1974
+ new AES128Cipher(
1975
+ this.buildObjectKey(num, gen, key, /* isAes = */ true),
1976
+ );
1977
+ }
1978
+ if (cfm.asString() === '/AESV3') {
1979
+ return () => new AES256Cipher(key);
1980
+ }
1981
+ throw new Error('Unknown crypto method');
1982
+ }
1983
+ }
1984
+
1985
+ export {
1986
+ AES128Cipher,
1987
+ AES256Cipher,
1988
+ ARCFourCipher,
1989
+ calculateMD5,
1990
+ calculateSHA256,
1991
+ calculateSHA384,
1992
+ calculateSHA512,
1993
+ CipherTransformFactory,
1994
+ CipherTransform,
1995
+ PDF17,
1996
+ PDF20,
1997
+ };