neozipkit 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +410 -186
  3. package/contracts/ABI.txt +889 -0
  4. package/contracts/Bytecode.txt +1 -0
  5. package/contracts/COMPILATION_NOTES.md +59 -0
  6. package/contracts/QUICK_DEPLOY.md +286 -0
  7. package/contracts/README.md +235 -131
  8. package/contracts/VERIFICATION.md +308 -0
  9. package/contracts/deploy-interactive.js +448 -0
  10. package/contracts/deployment-arbitrum-sepolia.json +12 -0
  11. package/contracts/deployment-arbitrum.json +12 -0
  12. package/contracts/deployment-eth-sepolia.json +12 -0
  13. package/contracts/hardhat.config.js +114 -0
  14. package/contracts/package.json +20 -0
  15. package/contracts/scripts/compile-and-extract.js +119 -0
  16. package/contracts/scripts/verify-contract.js +223 -0
  17. package/contracts/src/{NZIP-NFT-Private.sol → NZIP-NFT-v2.0.sol} +66 -151
  18. package/contracts/src/NZIP-NFT.sol +9 -15
  19. package/dist/blockchain/browser/TokenVerifierBrowser.d.ts +67 -0
  20. package/dist/blockchain/browser/TokenVerifierBrowser.d.ts.map +1 -0
  21. package/dist/blockchain/browser/TokenVerifierBrowser.js +313 -0
  22. package/dist/blockchain/browser/TokenVerifierBrowser.js.map +1 -0
  23. package/dist/blockchain/browser/WalletManagerBrowser.d.ts +98 -0
  24. package/dist/blockchain/browser/WalletManagerBrowser.d.ts.map +1 -0
  25. package/dist/blockchain/browser/WalletManagerBrowser.js +434 -0
  26. package/dist/blockchain/browser/WalletManagerBrowser.js.map +1 -0
  27. package/dist/blockchain/browser/ZipkitMinterBrowser.d.ts +58 -0
  28. package/dist/blockchain/browser/ZipkitMinterBrowser.d.ts.map +1 -0
  29. package/dist/blockchain/browser/ZipkitMinterBrowser.js +317 -0
  30. package/dist/blockchain/browser/ZipkitMinterBrowser.js.map +1 -0
  31. package/dist/blockchain/browser/index.d.ts +11 -0
  32. package/dist/blockchain/browser/index.d.ts.map +1 -0
  33. package/dist/blockchain/browser/index.js +16 -0
  34. package/dist/blockchain/browser/index.js.map +1 -0
  35. package/dist/blockchain/core/WalletManager.d.ts +124 -0
  36. package/dist/blockchain/core/WalletManager.d.ts.map +1 -0
  37. package/dist/blockchain/{ZipKitWallet.js → core/WalletManager.js} +157 -177
  38. package/dist/blockchain/core/WalletManager.js.map +1 -0
  39. package/dist/blockchain/{ZipKitMinter.d.ts → core/ZipkitMinter.d.ts} +46 -11
  40. package/dist/blockchain/core/ZipkitMinter.d.ts.map +1 -0
  41. package/dist/blockchain/core/ZipkitMinter.js +548 -0
  42. package/dist/blockchain/core/ZipkitMinter.js.map +1 -0
  43. package/dist/blockchain/{ZipKitOTS.d.ts → core/ZipkitOTS.d.ts} +6 -15
  44. package/dist/blockchain/core/ZipkitOTS.d.ts.map +1 -0
  45. package/dist/blockchain/{ZipKitOTS.js → core/ZipkitOTS.js} +26 -84
  46. package/dist/blockchain/core/ZipkitOTS.js.map +1 -0
  47. package/dist/blockchain/core/ZipkitVerifier.d.ts +177 -0
  48. package/dist/blockchain/core/ZipkitVerifier.d.ts.map +1 -0
  49. package/dist/blockchain/core/ZipkitVerifier.js +632 -0
  50. package/dist/blockchain/core/ZipkitVerifier.js.map +1 -0
  51. package/dist/blockchain/core/contracts.d.ts +83 -0
  52. package/dist/blockchain/core/contracts.d.ts.map +1 -0
  53. package/dist/blockchain/core/contracts.js +341 -0
  54. package/dist/blockchain/core/contracts.js.map +1 -0
  55. package/dist/blockchain/core/index.d.ts +12 -0
  56. package/dist/blockchain/core/index.d.ts.map +1 -0
  57. package/dist/blockchain/core/index.js +59 -0
  58. package/dist/blockchain/core/index.js.map +1 -0
  59. package/dist/blockchain/index.d.ts +11 -7
  60. package/dist/blockchain/index.d.ts.map +1 -0
  61. package/dist/blockchain/index.js +18 -34
  62. package/dist/blockchain/index.js.map +1 -0
  63. package/dist/blockchain/node/WalletManagerNode.d.ts +47 -0
  64. package/dist/blockchain/node/WalletManagerNode.d.ts.map +1 -0
  65. package/dist/blockchain/node/WalletManagerNode.js +203 -0
  66. package/dist/blockchain/node/WalletManagerNode.js.map +1 -0
  67. package/dist/blockchain/node/index.d.ts +12 -0
  68. package/dist/blockchain/node/index.d.ts.map +1 -0
  69. package/dist/blockchain/node/index.js +24 -0
  70. package/dist/blockchain/node/index.js.map +1 -0
  71. package/dist/browser/ZipkitBrowser.d.ts +27 -0
  72. package/dist/browser/ZipkitBrowser.d.ts.map +1 -0
  73. package/dist/browser/{ZipKitBrowser.js → ZipkitBrowser.js} +96 -43
  74. package/dist/browser/ZipkitBrowser.js.map +1 -0
  75. package/dist/browser/index.d.ts +12 -0
  76. package/dist/browser/index.d.ts.map +1 -0
  77. package/dist/browser/index.js +42 -0
  78. package/dist/browser/index.js.map +1 -0
  79. package/dist/browser-esm/index.d.ts +12 -0
  80. package/dist/browser-esm/index.js +59559 -0
  81. package/dist/browser-esm/index.js.map +7 -0
  82. package/dist/browser-umd/index.d.ts +12 -0
  83. package/dist/browser-umd/index.js +59576 -0
  84. package/dist/browser-umd/index.js.map +7 -0
  85. package/dist/browser-umd/index.min.js +63 -0
  86. package/dist/browser.d.ts +8 -14
  87. package/dist/browser.js +13 -28
  88. package/dist/core/ZipCompress.d.ts +99 -0
  89. package/dist/core/ZipCompress.d.ts.map +1 -0
  90. package/dist/core/ZipCompress.js +309 -0
  91. package/dist/core/ZipCompress.js.map +1 -0
  92. package/dist/core/ZipDecompress.d.ts +58 -0
  93. package/dist/core/ZipDecompress.d.ts.map +1 -0
  94. package/dist/core/ZipDecompress.js +172 -0
  95. package/dist/core/ZipDecompress.js.map +1 -0
  96. package/dist/{shared → core}/ZipEntry.d.ts +8 -1
  97. package/dist/core/ZipEntry.d.ts.map +1 -0
  98. package/dist/{shared → core}/ZipEntry.js +225 -82
  99. package/dist/core/ZipEntry.js.map +1 -0
  100. package/dist/core/Zipkit.d.ts +315 -0
  101. package/dist/core/Zipkit.d.ts.map +1 -0
  102. package/dist/core/Zipkit.js +647 -0
  103. package/dist/core/Zipkit.js.map +1 -0
  104. package/dist/core/components/HashCalculator.d.ts +138 -0
  105. package/dist/core/components/HashCalculator.d.ts.map +1 -0
  106. package/dist/core/components/HashCalculator.js +360 -0
  107. package/dist/core/components/HashCalculator.js.map +1 -0
  108. package/dist/core/components/Logger.d.ts +73 -0
  109. package/dist/core/components/Logger.d.ts.map +1 -0
  110. package/dist/core/components/Logger.js +156 -0
  111. package/dist/core/components/Logger.js.map +1 -0
  112. package/dist/core/components/ProgressTracker.d.ts +43 -0
  113. package/dist/core/components/ProgressTracker.d.ts.map +1 -0
  114. package/dist/core/components/ProgressTracker.js +112 -0
  115. package/dist/core/components/ProgressTracker.js.map +1 -0
  116. package/dist/{shared → core}/components/Support.d.ts +1 -0
  117. package/dist/core/components/Support.d.ts.map +1 -0
  118. package/dist/{shared → core}/components/Support.js +1 -0
  119. package/dist/core/components/Support.js.map +1 -0
  120. package/dist/{shared → core}/components/Util.d.ts +7 -2
  121. package/dist/core/components/Util.d.ts.map +1 -0
  122. package/dist/{shared → core}/components/Util.js +14 -34
  123. package/dist/core/components/Util.js.map +1 -0
  124. package/dist/{shared → core}/constants/Errors.d.ts +1 -2
  125. package/dist/core/constants/Errors.d.ts.map +1 -0
  126. package/dist/{shared → core}/constants/Errors.js +1 -3
  127. package/dist/core/constants/Errors.js.map +1 -0
  128. package/dist/{shared → core}/constants/Headers.d.ts +3 -0
  129. package/dist/core/constants/Headers.d.ts.map +1 -0
  130. package/dist/{shared → core}/constants/Headers.js +20 -17
  131. package/dist/core/constants/Headers.js.map +1 -0
  132. package/dist/core/encryption/Manager.d.ts +58 -0
  133. package/dist/core/encryption/Manager.d.ts.map +1 -0
  134. package/dist/core/encryption/Manager.js +121 -0
  135. package/dist/core/encryption/Manager.js.map +1 -0
  136. package/dist/core/encryption/ZipCrypto.d.ts +172 -0
  137. package/dist/core/encryption/ZipCrypto.d.ts.map +1 -0
  138. package/dist/core/encryption/ZipCrypto.js +554 -0
  139. package/dist/core/encryption/ZipCrypto.js.map +1 -0
  140. package/dist/core/encryption/index.d.ts +9 -0
  141. package/dist/core/encryption/index.d.ts.map +1 -0
  142. package/dist/core/encryption/index.js +17 -0
  143. package/dist/core/encryption/index.js.map +1 -0
  144. package/dist/core/encryption/types.d.ts +29 -0
  145. package/dist/core/encryption/types.d.ts.map +1 -0
  146. package/dist/core/encryption/types.js +12 -0
  147. package/dist/core/encryption/types.js.map +1 -0
  148. package/dist/core/index.d.ts +24 -0
  149. package/dist/core/index.d.ts.map +1 -0
  150. package/dist/core/index.js +57 -0
  151. package/dist/core/index.js.map +1 -0
  152. package/dist/core/version.d.ts +5 -0
  153. package/dist/core/version.d.ts.map +1 -0
  154. package/dist/core/version.js +31 -0
  155. package/dist/core/version.js.map +1 -0
  156. package/dist/index.d.ts +8 -18
  157. package/dist/index.d.ts.map +1 -0
  158. package/dist/index.js +29 -35
  159. package/dist/index.js.map +1 -0
  160. package/dist/node/ZipCompressNode.d.ts +123 -0
  161. package/dist/node/ZipCompressNode.d.ts.map +1 -0
  162. package/dist/node/ZipCompressNode.js +576 -0
  163. package/dist/node/ZipCompressNode.js.map +1 -0
  164. package/dist/node/ZipDecompressNode.d.ts +120 -0
  165. package/dist/node/ZipDecompressNode.d.ts.map +1 -0
  166. package/dist/node/ZipDecompressNode.js +461 -0
  167. package/dist/node/ZipDecompressNode.js.map +1 -0
  168. package/dist/node/ZipkitNode.d.ts +406 -0
  169. package/dist/node/ZipkitNode.d.ts.map +1 -0
  170. package/dist/node/ZipkitNode.js +1305 -0
  171. package/dist/node/ZipkitNode.js.map +1 -0
  172. package/dist/node/index.d.ts +26 -0
  173. package/dist/node/index.d.ts.map +1 -0
  174. package/dist/node/index.js +65 -0
  175. package/dist/node/index.js.map +1 -0
  176. package/dist/types/index.d.ts +59 -0
  177. package/dist/types/index.d.ts.map +1 -0
  178. package/dist/types/index.js +36 -1
  179. package/dist/types/index.js.map +1 -0
  180. package/examples/README.md +269 -0
  181. package/examples/blockchain-tokenize.ts +354 -0
  182. package/examples/create-zip.ts +172 -0
  183. package/examples/extract-zip.ts +158 -0
  184. package/examples/list-zip.ts +161 -0
  185. package/examples/test-files/data.json +116 -0
  186. package/examples/test-files/document.md +80 -0
  187. package/examples/test-files/document.txt +2 -0
  188. package/examples/test-files/file1.txt +48 -0
  189. package/examples/test-files/file2.txt +80 -0
  190. package/examples/tsconfig.json +44 -0
  191. package/examples/unzip-token.ts +491 -0
  192. package/examples/verify-tokenized-zip.ts +305 -0
  193. package/examples/zip-token.ts +604 -0
  194. package/package.json +108 -24
  195. package/src/blockchain/README.md +59 -66
  196. package/src/{browser/TokenVerifierBrowser.ts-remove → blockchain/browser/TokenVerifierBrowser.ts} +125 -79
  197. package/src/blockchain/browser/WalletManagerBrowser.ts +486 -0
  198. package/src/blockchain/browser/ZipkitMinterBrowser.ts +400 -0
  199. package/src/blockchain/browser/index.ts +13 -0
  200. package/src/blockchain/{ZipKitWallet.ts → core/WalletManager.ts} +241 -143
  201. package/src/blockchain/core/ZipkitMinter.ts +716 -0
  202. package/src/blockchain/{ZipKitOTS.ts → core/ZipkitOTS.ts} +28 -62
  203. package/src/blockchain/core/ZipkitVerifier.ts +853 -0
  204. package/src/blockchain/core/contracts.ts +370 -0
  205. package/src/blockchain/core/index.ts +71 -0
  206. package/src/blockchain/index.ts +21 -55
  207. package/src/blockchain/node/WalletManagerNode.ts +171 -0
  208. package/src/blockchain/node/index.ts +40 -0
  209. package/src/browser/{ZipKitBrowser.ts → ZipkitBrowser.ts} +104 -41
  210. package/src/browser/index.esm.ts +37 -0
  211. package/src/browser/index.ts +25 -0
  212. package/src/core/ZipCompress.ts +398 -0
  213. package/src/core/ZipDecompress.ts +212 -0
  214. package/src/{shared → core}/ZipEntry.ts +240 -90
  215. package/src/core/Zipkit.ts +794 -0
  216. package/src/core/components/HashCalculator.ts +384 -0
  217. package/src/core/components/Logger.ts +180 -0
  218. package/src/core/components/ProgressTracker.ts +134 -0
  219. package/src/{shared → core}/components/Util.ts +12 -34
  220. package/src/{shared → core}/constants/Errors.ts +0 -4
  221. package/src/{shared → core}/constants/Headers.ts +19 -17
  222. package/src/core/encryption/Manager.ts +137 -0
  223. package/src/core/encryption/ZipCrypto.ts +650 -0
  224. package/src/core/encryption/index.ts +15 -0
  225. package/src/core/encryption/types.ts +33 -0
  226. package/src/core/index.ts +34 -0
  227. package/src/core/version.ts +33 -0
  228. package/src/index.ts +54 -25
  229. package/src/node/ZipCompressNode.ts +632 -0
  230. package/src/node/ZipDecompressNode.ts +508 -0
  231. package/src/node/ZipkitNode.ts +1559 -0
  232. package/src/node/index.ts +69 -0
  233. package/src/types/index.ts +131 -1
  234. package/src/types/modules.d.ts +1 -11
  235. package/src/types/opentimestamps.d.ts +1 -23
  236. package/contracts/INTEGRATION.md +0 -338
  237. package/contracts/NETWORKS.md +0 -156
  238. package/contracts/NZIP-NFT-bytecode.txt +0 -1
  239. package/contracts/constants.ts +0 -952
  240. package/contracts/deploy-bytecode.mjs +0 -94
  241. package/dist/blockchain/CertificateToken.d.ts +0 -48
  242. package/dist/blockchain/CertificateToken.js +0 -386
  243. package/dist/blockchain/ZipKitMinter.js +0 -347
  244. package/dist/blockchain/ZipKitNFT.d.ts +0 -3
  245. package/dist/blockchain/ZipKitNFT.js +0 -7
  246. package/dist/blockchain/ZipKitVerifier.d.ts +0 -69
  247. package/dist/blockchain/ZipKitVerifier.js +0 -289
  248. package/dist/blockchain/ZipKitWallet.d.ts +0 -69
  249. package/dist/blockchain/contracts.d.ts +0 -14
  250. package/dist/blockchain/contracts.js +0 -77
  251. package/dist/blockchain/types.d.ts +0 -47
  252. package/dist/blockchain/types.js +0 -30
  253. package/dist/browser/ZipKitBrowser.d.ts +0 -18
  254. package/dist/browser/ZipKitStampBrowser.d.ts +0 -2
  255. package/dist/browser/ZipKitStampBrowser.js +0 -12
  256. package/dist/browser-index.d.ts +0 -18
  257. package/dist/browser-index.js +0 -57
  258. package/dist/server/ZipKitServer.d.ts +0 -74
  259. package/dist/server/ZipKitServer.js +0 -310
  260. package/dist/shared/ZipKit.d.ts +0 -243
  261. package/dist/shared/ZipKit.js +0 -772
  262. package/dist/shared/components/CertificateOTS.d.ts +0 -15
  263. package/dist/shared/components/CertificateOTS.js +0 -116
  264. package/dist/shared/components/FileSys.d.ts +0 -2
  265. package/dist/shared/components/FileSys.js +0 -113
  266. package/dist/shared/components/HashAccumulator.d.ts +0 -55
  267. package/dist/shared/components/HashAccumulator.js +0 -100
  268. package/dist/shared/components/ZipCrypto.d.ts +0 -3
  269. package/dist/shared/components/ZipCrypto.js +0 -78
  270. package/dist/shared/components/merkleTree.d.ts +0 -66
  271. package/dist/shared/components/merkleTree.js +0 -136
  272. package/dist/shared/types/index.d.ts +0 -21
  273. package/dist/shared/types/index.js +0 -3
  274. package/dist/shared/types.d.ts +0 -33
  275. package/dist/shared/types.js +0 -8
  276. package/dist/shared/version.d.ts +0 -2
  277. package/dist/shared/version.js +0 -6
  278. package/src/blockchain/CertificateToken.ts +0 -444
  279. package/src/blockchain/ZipKitMinter.ts +0 -470
  280. package/src/blockchain/ZipKitNFT.ts +0 -12
  281. package/src/blockchain/ZipKitVerifier.ts +0 -382
  282. package/src/blockchain/contracts.ts +0 -88
  283. package/src/blockchain/types.ts +0 -91
  284. package/src/browser/CertificateGeneratorBrowser.ts-remove +0 -498
  285. package/src/browser/ZipKitStampBrowser.ts +0 -9
  286. package/src/browser-index.ts +0 -36
  287. package/src/server/README.md +0 -25
  288. package/src/server/ZipKitServer.ts +0 -305
  289. package/src/shared/ZipKit.ts +0 -881
  290. package/src/shared/components/CertificateOTS.ts +0 -132
  291. package/src/shared/components/FileSys.ts +0 -87
  292. package/src/shared/components/HashAccumulator.ts +0 -113
  293. package/src/shared/components/ZipCrypto.ts +0 -91
  294. package/src/shared/components/merkleTree.ts +0 -162
  295. package/src/shared/types/index.ts +0 -25
  296. package/src/shared/types/modules.d.ts +0 -22
  297. package/src/shared/types/opentimestamps.d.ts +0 -23
  298. package/src/shared/types.d.ts +0 -8
  299. package/src/shared/types.ts +0 -43
  300. package/src/shared/version.ts +0 -3
  301. /package/src/{shared → core}/components/Support.ts +0 -0
@@ -1,74 +0,0 @@
1
- /**
2
- * ZipKitServer
3
- * Copyright (c) 2025 NeoWare, Inc. All rights reserved.
4
- *
5
- * Server-side implementation of ZipKit that passes through all functions
6
- * directly to the parent ZipKit class. This class provides a consistent interface
7
- * for server environments and ensures all ZipKit functionality is available.
8
- */
9
- import ZipKit, { CompressOptions } from '../shared/ZipKit';
10
- import * as Headers from '../shared/constants/Headers';
11
- export * from '../shared/ZipKit';
12
- export { Headers };
13
- /**
14
- * This implementation is optimized for server environments and handles all
15
- * ZIP operations including compression, extraction, encryption, and file management.
16
- */
17
- export default class ZipKitServer extends ZipKit {
18
- /**
19
- * Creates a new ZipKitServer instance
20
- *
21
- * Initializes the parent ZipKit class and logs environment support information
22
- * for diagnostic purposes.
23
- */
24
- constructor();
25
- /**
26
- * Loads a ZIP file from the filesystem for updating/creating operations
27
- *
28
- * Attempts to read an existing ZIP file, but creates a new empty archive if
29
- * the file doesn't exist. This method is used when adding or updating entries
30
- * in an archive, handling both new and existing ZIP files gracefully.
31
- *
32
- * @param zipFile - Path to the ZIP file to load or create
33
- */
34
- loadZipFile(zipFile: string): void;
35
- /**
36
- * Loads a ZIP file from the filesystem for extraction and listing operations
37
- *
38
- * Reads an existing ZIP file and throws an error if the file doesn't exist.
39
- * Use this method when working with existing archives that need to be extracted.
40
- *
41
- * @param zipFile - Path to the ZIP file to load
42
- * @throws Error if the file doesn't exist or can't be read
43
- */
44
- loadUnzipFile(zipFile: string): void;
45
- /**
46
- * Adds a single file to the ZIP archive
47
- * @param filename - Path to the file to be added
48
- * @param comment - Optional comment for the file entry
49
- *
50
- * Handles:
51
- * - Creating/updating ZipEntry objects
52
- * - Setting file attributes and timestamps
53
- * - Respecting freshen (-f) and update (-u) flags
54
- * - Setting compression method
55
- */
56
- addFile(filename: string, freshen?: boolean, update?: boolean): void;
57
- /**
58
- * Processes files to be added to the ZIP archive
59
- * Creates ZipEntry objects for each file and initiates the compression process
60
- */
61
- addFiles(files: string[], freshen?: boolean, update?: boolean): number;
62
- /**
63
- * Creates a ZIP file
64
- */
65
- createZip(zipFile: string, compressOptions: CompressOptions): Promise<void>;
66
- /**
67
- * Creates a ZIP file with OpenTimestamps (OTS) metadata
68
- */
69
- /**
70
- * Removes specified files from the ZIP archive
71
- * Deletes matching ZipEntry objects and rebuilds the archive if any files were removed
72
- */
73
- deleteFiles(delFiles: string[]): number;
74
- }
@@ -1,310 +0,0 @@
1
- "use strict";
2
- /**
3
- * ZipKitServer
4
- * Copyright (c) 2025 NeoWare, Inc. All rights reserved.
5
- *
6
- * Server-side implementation of ZipKit that passes through all functions
7
- * directly to the parent ZipKit class. This class provides a consistent interface
8
- * for server environments and ensures all ZipKit functionality is available.
9
- */
10
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- var desc = Object.getOwnPropertyDescriptor(m, k);
13
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
- desc = { enumerable: true, get: function() { return m[k]; } };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }) : (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- o[k2] = m[k];
20
- }));
21
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
- Object.defineProperty(o, "default", { enumerable: true, value: v });
23
- }) : function(o, v) {
24
- o["default"] = v;
25
- });
26
- var __importStar = (this && this.__importStar) || (function () {
27
- var ownKeys = function(o) {
28
- ownKeys = Object.getOwnPropertyNames || function (o) {
29
- var ar = [];
30
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
- return ar;
32
- };
33
- return ownKeys(o);
34
- };
35
- return function (mod) {
36
- if (mod && mod.__esModule) return mod;
37
- var result = {};
38
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
- __setModuleDefault(result, mod);
40
- return result;
41
- };
42
- })();
43
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
44
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
45
- };
46
- var __importDefault = (this && this.__importDefault) || function (mod) {
47
- return (mod && mod.__esModule) ? mod : { "default": mod };
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.Headers = void 0;
51
- const fs = __importStar(require("fs"));
52
- const path = __importStar(require("path"));
53
- const uuid_1 = require("uuid");
54
- const process_1 = require("process");
55
- const ZipKit_1 = __importDefault(require("../shared/ZipKit"));
56
- const Headers = __importStar(require("../shared/constants/Headers"));
57
- exports.Headers = Headers;
58
- // Re-export everything from ZipKit
59
- __exportStar(require("../shared/ZipKit"), exports);
60
- /**
61
- * This implementation is optimized for server environments and handles all
62
- * ZIP operations including compression, extraction, encryption, and file management.
63
- */
64
- class ZipKitServer extends ZipKit_1.default {
65
- /**
66
- * Creates a new ZipKitServer instance
67
- *
68
- * Initializes the parent ZipKit class and logs environment support information
69
- * for diagnostic purposes.
70
- */
71
- constructor() {
72
- super(); // Call the parent constructor
73
- }
74
- /**
75
- * Loads a ZIP file from the filesystem for updating/creating operations
76
- *
77
- * Attempts to read an existing ZIP file, but creates a new empty archive if
78
- * the file doesn't exist. This method is used when adding or updating entries
79
- * in an archive, handling both new and existing ZIP files gracefully.
80
- *
81
- * @param zipFile - Path to the ZIP file to load or create
82
- */
83
- loadZipFile(zipFile) {
84
- let inBuffer = null;
85
- let fdIn = null;
86
- try {
87
- if (fs.existsSync(zipFile)) {
88
- fdIn = fs.openSync(zipFile, 'r');
89
- const stats = fs.fstatSync(fdIn);
90
- inBuffer = Buffer.alloc(stats.size);
91
- // inBuffer is allocated above; ensure non-null for readSync
92
- fs.readSync(fdIn, inBuffer, 0, stats.size, 0);
93
- }
94
- else {
95
- // File doesn't exist, use an empty buffer
96
- inBuffer = Buffer.alloc(0);
97
- }
98
- }
99
- catch (error) {
100
- console.log('Warning: Could not open existing file. Creating new archive.');
101
- inBuffer = Buffer.alloc(0);
102
- }
103
- finally {
104
- if (fdIn !== null) {
105
- fs.closeSync(fdIn);
106
- }
107
- }
108
- // Initialize empty buffer if null
109
- const buffer = inBuffer ?? Buffer.alloc(0);
110
- super.loadZip(buffer);
111
- }
112
- /**
113
- * Loads a ZIP file from the filesystem for extraction and listing operations
114
- *
115
- * Reads an existing ZIP file and throws an error if the file doesn't exist.
116
- * Use this method when working with existing archives that need to be extracted.
117
- *
118
- * @param zipFile - Path to the ZIP file to load
119
- * @throws Error if the file doesn't exist or can't be read
120
- */
121
- loadUnzipFile(zipFile) {
122
- try {
123
- // Check if the file exists before trying to read it
124
- if (!fs.existsSync(zipFile)) {
125
- console.error(`Error: Zip file "${zipFile}" does not exist`);
126
- (0, process_1.exit)(1);
127
- }
128
- const inBuffer = fs.readFileSync(zipFile);
129
- super.loadZip(inBuffer);
130
- }
131
- catch (error) {
132
- console.error(`Error: Failed to read zip file "${zipFile}"`);
133
- (0, process_1.exit)(1);
134
- }
135
- }
136
- /**
137
- * Adds a single file to the ZIP archive
138
- * @param filename - Path to the file to be added
139
- * @param comment - Optional comment for the file entry
140
- *
141
- * Handles:
142
- * - Creating/updating ZipEntry objects
143
- * - Setting file attributes and timestamps
144
- * - Respecting freshen (-f) and update (-u) flags
145
- * - Setting compression method
146
- */
147
- addFile(filename, freshen = false, update = false) {
148
- let entry = super.getZipEntry(filename);
149
- if (!entry) {
150
- // Check for Freshen option
151
- if (freshen)
152
- return;
153
- entry = super.createZipEntry(filename);
154
- }
155
- else if (!update) {
156
- // Mark this entry as not being updated
157
- entry.isUpdated = false;
158
- return;
159
- }
160
- entry.platform = process.platform;
161
- // Correctly retrieve file stats
162
- let attr = fs.statSync(filename); // Synchronously get the stats of the file
163
- entry.uncompressedSize = attr.size;
164
- // Set the DOS file time/date based on the Date stamp of the file.
165
- const utcDate = new Date(attr.mtime.getTime());
166
- entry.timeDateDOS = entry.setDateTime(utcDate);
167
- entry.universalTime = Math.floor(attr.mtime.getTime() / 1000); // Store Unix timestamp
168
- // Set Unix UID/GID if on Unix-like system
169
- if (process.platform !== 'win32') {
170
- entry.uid = attr.uid;
171
- entry.gid = attr.gid;
172
- }
173
- // Use attr.mode for file permissions
174
- entry.isDirectory = attr.isDirectory();
175
- let _fattr = (attr.mode & 0xfff) | (entry.isDirectory ? 0x4000 : 0x8000);
176
- entry.extFileAttr = ((_fattr << 16) | (entry.isDirectory ? 0x10 : 0)) >>> 0;
177
- }
178
- /**
179
- * Processes files to be added to the ZIP archive
180
- * Creates ZipEntry objects for each file and initiates the compression process
181
- */
182
- addFiles(files, freshen = false, update = false) {
183
- let filesAdded = 0;
184
- for (var i = 0; files[i] != undefined; i++) {
185
- const filename = String(files[i]);
186
- // Skip arguments that look like options (start with hyphen but aren't files)
187
- if (filename.startsWith('-') && !fs.existsSync(filename)) {
188
- console.warn(`Warning: Skipping '${filename}' which appears to be an option, not a file.`);
189
- continue;
190
- }
191
- this.addFile(filename, freshen, update);
192
- filesAdded++;
193
- }
194
- return filesAdded;
195
- }
196
- /**
197
- * Creates a ZIP file
198
- */
199
- async createZip(zipFile, compressOptions) {
200
- // Ensure the directory structure for the output file exists
201
- const outputDir = path.dirname(zipFile);
202
- if (!fs.existsSync(outputDir)) {
203
- fs.mkdirSync(outputDir, { recursive: true });
204
- }
205
- // Generate a unique temporary file name in the output directory
206
- const _tempZipFile = path.join(outputDir, `neozip-${(0, uuid_1.v4)()}.zip`);
207
- // Open or create the .zip file for writing
208
- const fd = fs.openSync(_tempZipFile, 'w');
209
- let offset = await super.createZipFileData(compressOptions, {
210
- onReadEntryData: (entry) => {
211
- try {
212
- return fs.readFileSync(entry.filename);
213
- }
214
- catch (error) {
215
- throw new Error(`Failed to read file: ${entry.filename}`);
216
- }
217
- },
218
- onOutputBuffer: (buffer) => {
219
- fs.writeSync(fd, buffer);
220
- },
221
- onEntryDone: (entry, status) => {
222
- console.log(`${status} ${entry.filename} to ${zipFile}`);
223
- }
224
- });
225
- // Write the metadata entry to the .zip fi
226
- await super.finishZipFileData(offset, function onOutputBuffer(buffer) {
227
- fs.writeSync(fd, buffer);
228
- }, undefined);
229
- // Close the .zip file
230
- fs.closeSync(fd);
231
- // Delete the existing .zip file if it exists
232
- if (fs.existsSync(zipFile)) {
233
- fs.unlinkSync(zipFile);
234
- }
235
- // Replace the existing .zip file with the temporary file
236
- fs.renameSync(_tempZipFile, zipFile);
237
- }
238
- /**
239
- * Creates a ZIP file with OpenTimestamps (OTS) metadata
240
- */
241
- // async createZipOTS(zipFile: string, compressOptions: CompressOptions) {
242
- // // Ensure the directory structure for the output file exists
243
- // const outputDir = path.dirname(zipFile);
244
- // if (!fs.existsSync(outputDir)) {
245
- // fs.mkdirSync(outputDir, { recursive: true });
246
- // }
247
- // // Generate a unique temporary file name in the output directory
248
- // const _tempZipFile = path.join(outputDir, `neozip-${uuidv4()}.zip`);
249
- // // Open or create the .zip file for writing
250
- // const fd = fs.openSync(_tempZipFile, 'w');
251
- // let offset = await super.createZipFileData(compressOptions, {
252
- // onReadEntryData: (entry: ZipEntry) => {
253
- // try {
254
- // return fs.readFileSync(entry.filename);
255
- // } catch (error) {
256
- // throw new Error(`Failed to read file: ${entry.filename}`);
257
- // }
258
- // },
259
- // onOutputBuffer: (buffer: Buffer) => {
260
- // fs.writeSync(fd, buffer);
261
- // },
262
- // onEntryDone: (entry: ZipEntry, status: string) => {
263
- // console.log(`${status} ${entry.filename} to ${zipFile}`);
264
- // }
265
- // });
266
- // // Timestamp the zip file to the Bitcoin blockchain
267
- // let _metadataEntry = null;
268
- // console.log('Timestamping to Bitcoin blockchain...');
269
- // const _merkleRoot = super.getMerkleRoot();
270
- // console.log('Merkle Root: ' + _merkleRoot);
271
- // const _ots = await createTimestamp(_merkleRoot);
272
- // _metadataEntry = super.createTimestampMetadataEntry(_ots);
273
- // // Write the metadata entry to the .zip fi
274
- // await super.finishZipFileData(
275
- // offset,
276
- // function onOutputBuffer(buffer: Buffer) {
277
- // fs.writeSync(fd, buffer);
278
- // },
279
- // _metadataEntry || undefined
280
- // );
281
- // // Close the .zip file
282
- // fs.closeSync(fd);
283
- // // Delete the existing .zip file if it exists
284
- // if (fs.existsSync(zipFile)) {
285
- // fs.unlinkSync(zipFile);
286
- // }
287
- // // Replace the existing .zip file with the temporary file
288
- // fs.renameSync(_tempZipFile, zipFile);
289
- // }
290
- /**
291
- * Removes specified files from the ZIP archive
292
- * Deletes matching ZipEntry objects and rebuilds the archive if any files were removed
293
- */
294
- deleteFiles(delFiles) {
295
- super.getDirectory();
296
- let filesDel = 0;
297
- delFiles.forEach(fname => {
298
- const deleted = super.deleteFile(fname);
299
- if (deleted) {
300
- console.log(' deleting: ' + fname + "\n");
301
- ++filesDel;
302
- }
303
- else {
304
- console.log(' warning: name not found: ' + fname + "\n");
305
- }
306
- });
307
- return filesDel;
308
- }
309
- }
310
- exports.default = ZipKitServer;
@@ -1,243 +0,0 @@
1
- import ZipEntry from './ZipEntry';
2
- import Errors from './constants/Errors';
3
- import { LOCAL_HDR, ENCRYPT_HDR_SIZE, CMP_METHOD, CENTRAL_END, CENTRAL_DIR, ZIP64_CENTRAL_END, ZIP64_CENTRAL_DIR, GP_FLAG, TIMESTAMP_SUBMITTED, TIMESTAMP_METADATA, TOKENIZED_METADATA, LOCAL_FILE_HEADER, CENTRAL_FILE_HEADER, CENTRAL_DIRECTORY_END, HDR_ID } from './constants/Headers';
4
- export { ZipEntry, Errors, CMP_METHOD, TIMESTAMP_METADATA, TIMESTAMP_SUBMITTED, TOKENIZED_METADATA, LOCAL_HDR, ENCRYPT_HDR_SIZE, CENTRAL_END, CENTRAL_DIR, ZIP64_CENTRAL_END, ZIP64_CENTRAL_DIR, GP_FLAG, LOCAL_FILE_HEADER, CENTRAL_FILE_HEADER, CENTRAL_DIRECTORY_END, HDR_ID };
5
- /**
6
- * Options for compressing files in a ZIP archive
7
- */
8
- export interface CompressOptions {
9
- level?: number;
10
- password?: string | null;
11
- useSHA256?: boolean;
12
- useZstd?: boolean;
13
- }
14
- /**
15
- * Callbacks for ZIP file creation process
16
- */
17
- export interface CreateZipOptions {
18
- onError?: (error: Error) => void;
19
- onEntryDone?: (entry: ZipEntry, status: string) => void;
20
- onReadEntryData?: (entry: ZipEntry) => Buffer;
21
- onOutputBuffer?: (data: Buffer) => void;
22
- }
23
- /**
24
- * Main class for ZIP file operations including compression, extraction, and encryption
25
- */
26
- export default class ZipKit {
27
- static readonly version: string;
28
- static readonly releaseDate: string;
29
- private inBuffer;
30
- private zipEntries;
31
- private sortName;
32
- private centralDirSize;
33
- private centralDirOffset;
34
- private stampEntry;
35
- zipComment: string | null;
36
- static support: {
37
- base64: boolean;
38
- array: boolean;
39
- string: boolean;
40
- isNode: boolean;
41
- buffer: boolean;
42
- uint8array: boolean;
43
- arrayBuffer: boolean;
44
- blob: boolean;
45
- streams: boolean;
46
- fileReader: boolean;
47
- };
48
- /**
49
- * Creates a new ZipKit instance
50
- */
51
- constructor();
52
- /**
53
- * Resets all ZIP-related data to initial state
54
- */
55
- resetZipData(): void;
56
- /**
57
- * Loads a ZIP file from a buffer
58
- * @param inBuf - Buffer containing ZIP file data
59
- */
60
- loadZip(inBuf: Buffer): void;
61
- /**
62
- * Tests if data matches the CRC32 checksum
63
- * @param entry - ZIP entry to check
64
- * @param data - Data buffer to verify
65
- * @returns boolean indicating if CRC matches
66
- */
67
- testCRC32(entry: ZipEntry, data: Buffer): boolean;
68
- /**
69
- * Tests if data matches the SHA256 hash
70
- * @param entry - ZIP entry to check
71
- * @param data - Data buffer to verify
72
- * @returns boolean indicating if SHA256 matches
73
- * @throws Error if entry has no SHA256 hash
74
- */
75
- testSHA256(entry: ZipEntry, data: Buffer): boolean;
76
- /**
77
- * Locates and parses the central end directory
78
- * @param inBuffer - Buffer containing ZIP file data
79
- * @returns Number of entries in ZIP file
80
- * @throws Error if central directory is invalid
81
- */
82
- getCentralEnd(inBuffer: Buffer): number;
83
- /**
84
- * Creates the central end directory header
85
- * @param centralDirSize - Size of central directory
86
- * @param centralDirOffset - Offset to central directory
87
- * @returns Buffer containing end directory header
88
- */
89
- centralEndHdr(centralDirSize: number, centralDirOffset: number): Buffer;
90
- /**
91
- * Reads and parses the ZIP file directory
92
- * @param debug - Enable debug logging
93
- * @returns Array of ZIP entries
94
- */
95
- getDirectory(debug?: boolean): ZipEntry[];
96
- /**
97
- * Gets a ZIP entry by filename
98
- * @param fname - Filename to search for
99
- * @returns ZipEntry if found, null otherwise
100
- */
101
- getZipEntry(fname: string): ZipEntry | null;
102
- /**
103
- * Creates a new ZIP entry
104
- * @param fname - Filename for new entry
105
- * @param comment - Optional entry comment
106
- * @returns Created ZipEntry
107
- */
108
- createZipEntry(fname: string, comment?: string): ZipEntry;
109
- /**
110
- * Deletes an entry from the ZIP file
111
- * @param fname - Filename to delete
112
- * @returns boolean indicating if file was deleted
113
- */
114
- deleteFile(fname: string): boolean;
115
- /**
116
- * Parses local header and returns entry data
117
- * @param entry - ZIP entry to parse
118
- * @param withLocalHdrData - Include header in returned data
119
- * @returns Buffer containing entry data
120
- * @throws Error if header is invalid
121
- */
122
- parseLocalHeader(entry: ZipEntry, withLocalHdrData?: boolean): Buffer;
123
- /**
124
- * Copies an entry's data from source ZIP
125
- * @param entry - Entry to copy
126
- * @returns Buffer containing entry data with headers
127
- */
128
- copyEntry(entry: ZipEntry): Buffer;
129
- /**
130
- * Compresses data for a ZIP entry
131
- * @param entry - ZIP entry to compress
132
- * @param data - Data to compress
133
- * @param options - Compression options
134
- * @returns Buffer containing compressed data
135
- */
136
- compressData(entry: ZipEntry, data: Buffer, options?: CompressOptions): Promise<Buffer>;
137
- /**
138
- * Compresses data using deflate algorithm
139
- * @param inbuf - Data to compress
140
- * @param options - Compression options
141
- * @returns Compressed data buffer
142
- */
143
- private deflate;
144
- /**
145
- * Compresses data using Zstandard (zstd) algorithm
146
- * @param inbuf - Data to compress
147
- * @param options - Compression options
148
- * @returns Compressed data buffer
149
- */
150
- private zstdCompress;
151
- /**
152
- * Decompresses data using Zstandard (zstd) algorithm
153
- * @param inbuf - Compressed data buffer
154
- * @returns Decompressed data buffer
155
- */
156
- zstdDecompress(inbuf: Buffer): Promise<Buffer>;
157
- /**
158
- * Creates new Zip data file with the passed ZipEntries
159
- * @param cmpOptions - Compression options
160
- * @param zipOptions - Create ZIP options
161
- * @returns Promise<number> - The offset of the last entry
162
- */
163
- createZipFileData(cmpOptions?: CompressOptions, zipOptions?: CreateZipOptions): Promise<number>;
164
- /**
165
- * Finishes Zip data file by adding any Metadata entries and the Central End Directory
166
- * @param offset - The current offset in the zip data file
167
- * @param onOutputBuffer - The callback function to output the data buffer
168
- * @param metaEntry - The Metadata ZipEntry to add to the Zip file
169
- */
170
- finishZipFileData(offset: number, onOutputBuffer: (data: Buffer) => void, metaEntry?: ZipEntry): Promise<void>;
171
- /**
172
- * Unzips the data buffer using pako inflate method
173
- * @param inbuf - Data buffer to inflate
174
- * @returns Inflated data buffer
175
- * @throws Error if extraction fails
176
- */
177
- inflate(inbuf: Buffer): Buffer;
178
- /**
179
- * Extracts the data from the ZipEntry and returns the data as a Buffer
180
- * @param entry - ZIP entry to extract
181
- * @param skipHashCheck - Whether to skip hash checking
182
- * @returns Buffer containing extracted data or null if extraction fails
183
- */
184
- extract(entry: ZipEntry, skipHashCheck?: boolean): Promise<Buffer | null>;
185
- /**
186
- * Decrypts the entry data
187
- * @param entry - ZIP entry to decrypt
188
- * @param password - Password for decryption
189
- * @returns Decrypted data buffer or null if decryption fails
190
- */
191
- decryptEntry(entry: ZipEntry, password: string): Buffer | null;
192
- /**
193
- * Checks if a filename is a blockchain metadata file that should be excluded from Merkle Root calculation
194
- * @param filename - The filename to check
195
- * @returns boolean - True if the file is a metadata file
196
- */
197
- private isMetadataFile;
198
- /**
199
- * Calculates the Merkle Root of the ZIP file
200
- * Excludes blockchain metadata files (META-INF/*) to ensure consistent calculation
201
- * @returns string - The Merkle Root of the ZIP file
202
- */
203
- getMerkleRoot(): string | null;
204
- /**
205
- * Checks if a ZIP file contains valid timestamp metadata
206
- * @returns { merkleRoot: string | null, ots: Buffer | null }
207
- * Returns the merkle root hash and timestamp metadata if found, null otherwise
208
- */
209
- checkForTimestamp(): string | null;
210
- /**
211
- * Gets the OTS from the timestamp metadata entry
212
- * @returns Promise<Buffer | null> - The OTS from the timestamp metadata entry or null if not found
213
- */
214
- getOts(): Promise<Buffer | null>;
215
- /**
216
- * Sets the ZIP file comment
217
- * @param msg - Comment to set
218
- */
219
- setZipComment(msg: string | null): void;
220
- /**
221
- * Gets the ZIP file comment
222
- * @returns string | null - The ZIP file comment
223
- */
224
- getZipComment(): string | null;
225
- /**
226
- * Converts the compression method to a string
227
- * @param cmpMethod - Compression method number
228
- * @returns string - Compression method as a string
229
- */
230
- cmpMethodToString(cmpMethod: number): string;
231
- /**
232
- * Ensures ZIP entries are loaded
233
- * @returns Array of ZIP entries
234
- * @throws Error if no ZIP entries are loaded
235
- */
236
- private ensureZipEntries;
237
- /**
238
- * Ensures ZIP data buffer is loaded
239
- * @returns Buffer containing ZIP data
240
- * @throws Error if no ZIP data is loaded
241
- */
242
- private ensureBuffer;
243
- }