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