neozipkit 0.1.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 (330) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +371 -200
  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 +256 -0
  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/{browser → blockchain/browser}/TokenVerifierBrowser.d.ts +11 -20
  20. package/dist/blockchain/browser/TokenVerifierBrowser.d.ts.map +1 -0
  21. package/dist/{browser → blockchain/browser}/TokenVerifierBrowser.js +106 -92
  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/{server/blockchain/WalletAnalyzer.d.ts → blockchain/core/WalletManager.d.ts} +69 -26
  36. package/dist/blockchain/core/WalletManager.d.ts.map +1 -0
  37. package/dist/{server/blockchain/WalletAnalyzer.js → blockchain/core/WalletManager.js} +172 -160
  38. package/dist/blockchain/core/WalletManager.js.map +1 -0
  39. package/dist/blockchain/core/ZipkitMinter.d.ts +141 -0
  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/core/ZipkitOTS.d.ts +126 -0
  44. package/dist/blockchain/core/ZipkitOTS.d.ts.map +1 -0
  45. package/dist/blockchain/core/ZipkitOTS.js +506 -0
  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 -0
  60. package/dist/blockchain/index.d.ts.map +1 -0
  61. package/dist/blockchain/index.js +34 -0
  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 -17
  87. package/dist/browser.js +13 -29
  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 +224 -81
  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/{shared → core}/version.d.ts +1 -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 -25
  157. package/dist/index.d.ts.map +1 -0
  158. package/dist/index.js +29 -47
  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 +6 -3
  192. package/examples/verify-tokenized-zip.ts +305 -0
  193. package/package.json +117 -23
  194. package/src/blockchain/README.md +222 -0
  195. package/src/{browser → blockchain/browser}/TokenVerifierBrowser.ts +125 -79
  196. package/src/blockchain/browser/WalletManagerBrowser.ts +486 -0
  197. package/src/blockchain/browser/ZipkitMinterBrowser.ts +400 -0
  198. package/src/blockchain/browser/index.ts +13 -0
  199. package/src/blockchain/core/WalletManager.ts +436 -0
  200. package/src/blockchain/core/ZipkitMinter.ts +716 -0
  201. package/src/blockchain/core/ZipkitOTS.ts +588 -0
  202. package/src/blockchain/core/ZipkitVerifier.ts +853 -0
  203. package/src/blockchain/core/contracts.ts +370 -0
  204. package/src/blockchain/core/index.ts +71 -0
  205. package/src/blockchain/index.ts +27 -0
  206. package/src/blockchain/node/WalletManagerNode.ts +171 -0
  207. package/src/blockchain/node/index.ts +40 -0
  208. package/src/browser/{ZipKitBrowser.ts → ZipkitBrowser.ts} +104 -41
  209. package/src/browser/index.esm.ts +37 -0
  210. package/src/browser/index.ts +25 -0
  211. package/src/core/ZipCompress.ts +398 -0
  212. package/src/core/ZipDecompress.ts +212 -0
  213. package/src/{shared → core}/ZipEntry.ts +239 -89
  214. package/src/core/Zipkit.ts +794 -0
  215. package/src/core/components/HashCalculator.ts +384 -0
  216. package/src/core/components/Logger.ts +180 -0
  217. package/src/core/components/ProgressTracker.ts +134 -0
  218. package/src/{shared → core}/components/Util.ts +12 -34
  219. package/src/{shared → core}/constants/Errors.ts +0 -4
  220. package/src/{shared → core}/constants/Headers.ts +19 -17
  221. package/src/core/encryption/Manager.ts +137 -0
  222. package/src/core/encryption/ZipCrypto.ts +650 -0
  223. package/src/core/encryption/index.ts +15 -0
  224. package/src/core/encryption/types.ts +33 -0
  225. package/src/core/index.ts +34 -0
  226. package/src/core/version.ts +33 -0
  227. package/src/index.ts +54 -32
  228. package/src/node/ZipCompressNode.ts +632 -0
  229. package/src/node/ZipDecompressNode.ts +508 -0
  230. package/src/node/ZipkitNode.ts +1559 -0
  231. package/src/node/index.ts +69 -0
  232. package/src/types/index.ts +131 -1
  233. package/src/types/opentimestamps.d.ts +1 -23
  234. package/contracts/Lock.sol +0 -34
  235. package/contracts/bytecode.txt +0 -1
  236. package/contracts/compile-contract.js +0 -168
  237. package/contracts/deploy/deploy-both-contracts.js +0 -286
  238. package/contracts/deploy/deploy-enhanced-contract.js +0 -197
  239. package/contracts/deploy/deploy-private-contract.js +0 -190
  240. package/contracts/deploy/deploy-public-clean.js +0 -1063
  241. package/contracts/deploy/deploy-public-contract.js +0 -1107
  242. package/contracts/deployment.config.example.js +0 -25
  243. package/contracts/remix-compile.js +0 -222
  244. package/contracts/setup-deployment.js +0 -51
  245. package/contracts/src/ZipFileNFT-DEPRECATED-6field.sol +0 -260
  246. package/contracts/src/ZipFileNFT-DEPRECATED-Enhanced.sol +0 -289
  247. package/dist/browser/CertificateGeneratorBrowser.d.ts +0 -75
  248. package/dist/browser/CertificateGeneratorBrowser.js +0 -433
  249. package/dist/browser/ZipKitBrowser.d.ts +0 -18
  250. package/dist/browser/ZipKitStampBrowser.d.ts +0 -2
  251. package/dist/browser/ZipKitStampBrowser.js +0 -12
  252. package/dist/browser-index.d.ts +0 -21
  253. package/dist/browser-index.js +0 -58
  254. package/dist/server/blockchain/CertificateToken.d.ts +0 -48
  255. package/dist/server/blockchain/CertificateToken.js +0 -386
  256. package/dist/server/blockchain/NFTMinter.d.ts +0 -41
  257. package/dist/server/blockchain/NFTMinter.js +0 -323
  258. package/dist/server/blockchain/TokenQuerier.d.ts +0 -31
  259. package/dist/server/blockchain/TokenQuerier.js +0 -259
  260. package/dist/server/blockchain/TokenVerifier.d.ts +0 -20
  261. package/dist/server/blockchain/TokenVerifier.js +0 -395
  262. package/dist/server/blockchain/WalletFormatter.d.ts +0 -39
  263. package/dist/server/blockchain/WalletFormatter.js +0 -196
  264. package/dist/server/blockchain/WalletManager.d.ts +0 -46
  265. package/dist/server/blockchain/WalletManager.js +0 -294
  266. package/dist/server/blockchain/ZipMetadata.d.ts +0 -27
  267. package/dist/server/blockchain/ZipMetadata.js +0 -131
  268. package/dist/server/blockchain/ZipTokenProcessor.d.ts +0 -44
  269. package/dist/server/blockchain/ZipTokenProcessor.js +0 -204
  270. package/dist/server/blockchain/constants.d.ts +0 -102
  271. package/dist/server/blockchain/constants.js +0 -968
  272. package/dist/server/blockchain/index.d.ts +0 -9
  273. package/dist/server/blockchain/index.js +0 -44
  274. package/dist/server/blockchain/test-certificate.d.ts +0 -8
  275. package/dist/server/blockchain/test-certificate.js +0 -100
  276. package/dist/server/blockchain/types.d.ts +0 -69
  277. package/dist/server/blockchain/types.js +0 -51
  278. package/dist/server/platform/server/ZipKitServer.d.ts +0 -105
  279. package/dist/server/platform/server/ZipKitServer.js +0 -437
  280. package/dist/server/platform/servercomponents/ZipKitOTS.d.ts +0 -91
  281. package/dist/server/platform/servercomponents/ZipKitOTS.js +0 -271
  282. package/dist/shared/ZipKit.d.ts +0 -249
  283. package/dist/shared/ZipKit.js +0 -789
  284. package/dist/shared/components/CertificateOTS.d.ts +0 -15
  285. package/dist/shared/components/CertificateOTS.js +0 -116
  286. package/dist/shared/components/FileSys.d.ts +0 -2
  287. package/dist/shared/components/FileSys.js +0 -113
  288. package/dist/shared/components/HashAccumulator.d.ts +0 -55
  289. package/dist/shared/components/HashAccumulator.js +0 -100
  290. package/dist/shared/components/ZipCrypto.d.ts +0 -3
  291. package/dist/shared/components/ZipCrypto.js +0 -78
  292. package/dist/shared/components/merkleTree.d.ts +0 -66
  293. package/dist/shared/components/merkleTree.js +0 -136
  294. package/dist/shared/types/index.d.ts +0 -21
  295. package/dist/shared/types/index.js +0 -3
  296. package/dist/shared/types.d.ts +0 -33
  297. package/dist/shared/types.js +0 -8
  298. package/dist/shared/version.js +0 -7
  299. package/src/browser/CertificateGeneratorBrowser.ts +0 -498
  300. package/src/browser/ZipKitStampBrowser.ts +0 -9
  301. package/src/browser-index.ts +0 -36
  302. package/src/server/blockchain/CertificateToken.ts +0 -444
  303. package/src/server/blockchain/NFTMinter.ts +0 -357
  304. package/src/server/blockchain/TokenQuerier.ts +0 -287
  305. package/src/server/blockchain/TokenVerifier.ts +0 -453
  306. package/src/server/blockchain/WalletAnalyzer.ts +0 -397
  307. package/src/server/blockchain/WalletFormatter.ts +0 -206
  308. package/src/server/blockchain/WalletManager.ts +0 -294
  309. package/src/server/blockchain/ZipMetadata.ts +0 -117
  310. package/src/server/blockchain/ZipTokenProcessor.ts +0 -234
  311. package/src/server/blockchain/constants.ts +0 -969
  312. package/src/server/blockchain/index.ts +0 -42
  313. package/src/server/blockchain/test-certificate.ts +0 -137
  314. package/src/server/blockchain/types.ts +0 -134
  315. package/src/server/platform/server/ZipKitServer.ts +0 -459
  316. package/src/server/platform/servercomponents/ZipKitOTS.ts +0 -313
  317. package/src/server/platform/servercomponents/opentimestamps.d.ts +0 -23
  318. package/src/shared/ZipKit.ts +0 -899
  319. package/src/shared/components/CertificateOTS.ts +0 -132
  320. package/src/shared/components/FileSys.ts +0 -87
  321. package/src/shared/components/HashAccumulator.ts +0 -113
  322. package/src/shared/components/ZipCrypto.ts +0 -91
  323. package/src/shared/components/merkleTree.ts +0 -162
  324. package/src/shared/types/index.ts +0 -25
  325. package/src/shared/types/modules.d.ts +0 -22
  326. package/src/shared/types/opentimestamps.d.ts +0 -23
  327. package/src/shared/types.d.ts +0 -8
  328. package/src/shared/types.ts +0 -43
  329. package/src/shared/version.ts +0 -4
  330. /package/src/{shared → core}/components/Support.ts +0 -0
@@ -0,0 +1,126 @@
1
+ declare global {
2
+ var _bitcore: any;
3
+ }
4
+ export interface TimestampResult {
5
+ merkleRoot: string | null;
6
+ ots: ArrayBuffer | null;
7
+ verified: boolean;
8
+ results: any | null;
9
+ error: string | null;
10
+ attestations: any | null;
11
+ upgradedOts: ArrayBuffer | null;
12
+ }
13
+ export interface TimestampInfo {
14
+ message: string;
15
+ results: string[];
16
+ attestDate: Date | null;
17
+ attestHeight: number | null;
18
+ submittedUri: string | null;
19
+ otsUpgraded: boolean;
20
+ }
21
+ export interface DeserializeOtsResult {
22
+ attestStr: string | null;
23
+ needsUpdateMsg: string | null;
24
+ attestationValues: any[];
25
+ }
26
+ export interface OtsVerifyResult {
27
+ status: 'none' | 'valid' | 'pending' | 'error';
28
+ message?: string;
29
+ blockHeight?: number;
30
+ attestedAt?: Date;
31
+ upgraded?: boolean;
32
+ upgradedOts?: Buffer;
33
+ }
34
+ /**
35
+ * Verifies an OpenTimestamps proof against a hash digest.
36
+ * @param hashDigest - SHA256 hash as hex string to verify
37
+ * @param ots - OpenTimestamps proof data
38
+ * @param options - Configuration options
39
+ * @param options.debug - Enable debug logging
40
+ * @returns Promise resolving to verification result, error object, or null if inputs invalid
41
+ */
42
+ export declare function verifyOts(hashDigest: string | null, ots: ArrayBuffer | null, options?: {
43
+ debug?: boolean;
44
+ }): Promise<TimestampResult | {
45
+ error: string;
46
+ } | null>;
47
+ /**
48
+ * Converts a Node.js Buffer to an ArrayBuffer.
49
+ * @param buf - Buffer to convert
50
+ * @returns ArrayBuffer with same data
51
+ */
52
+ export declare function bufferToArrayBuffer(buf: Buffer): ArrayBuffer;
53
+ /**
54
+ * Finds the OpenTimestamps entry in a ZIP file.
55
+ * Searches for TIMESTAMP_METADATA first, then TIMESTAMP_SUBMITTED.
56
+ * @param zip - Zipkit instance to search
57
+ * @returns ZIP entry containing OTS proof, or null if not found
58
+ */
59
+ export declare function getOtsEntry(zip: any): any | null;
60
+ /**
61
+ * Extracts OTS proof data from a ZIP entry.
62
+ * @param zip - Zipkit instance
63
+ * @param otsEntry - ZIP entry containing OTS data
64
+ * @returns Promise resolving to OTS proof buffer, or null if extraction fails
65
+ */
66
+ export declare function getOtsBuffer(zip: any, otsEntry: any): Promise<Buffer | null>;
67
+ /**
68
+ * Safely extracts merkle root from a ZIP file.
69
+ * @param zip - Zipkit instance
70
+ * @returns Merkle root hash string, or null if not available
71
+ */
72
+ export declare function getMerkleRootSafe(zip: any): string | null;
73
+ /**
74
+ * Verifies OpenTimestamps proof within a ZIP file.
75
+ * Extracts merkle root and OTS proof, then verifies against Bitcoin blockchain.
76
+ * @param zip - Zipkit instance containing files and OTS proof
77
+ * @returns Promise resolving to verification result with status: 'none', 'error', 'pending', or 'valid'
78
+ */
79
+ export declare function verifyOtsZip(zip: any): Promise<OtsVerifyResult>;
80
+ /**
81
+ * Creates an OpenTimestamps proof for a hash digest.
82
+ * Submits hash to OpenTimestamps servers for Bitcoin blockchain anchoring.
83
+ * @param hashDigest - SHA256 hash as hex string to timestamp
84
+ * @param options - Configuration options
85
+ * @param options.debug - Enable debug logging
86
+ * @returns Promise resolving to OTS proof buffer, or null if creation failed
87
+ */
88
+ export declare function createTimestamp(hashDigest: string | null, options?: {
89
+ debug?: boolean;
90
+ }): Promise<Buffer | null>;
91
+ /**
92
+ * Deserializes OpenTimestamps verification result into JSON format.
93
+ * Extracts blockchain attestation data and transaction details.
94
+ * @param tsResult - Timestamp verification result to deserialize
95
+ * @param options - Configuration options
96
+ * @param options.debug - Enable debug logging
97
+ * @returns Promise resolving to JSON string with attestation data, or null if failed
98
+ */
99
+ export declare function deserializeOts(tsResult: TimestampResult, options?: {
100
+ debug?: boolean;
101
+ }): Promise<string | null>;
102
+ /**
103
+ * Parses timestamp verification result into readable information.
104
+ * Formats blockchain attestation data with human-readable messages and dates.
105
+ * @param verifyResult - Timestamp verification result to parse
106
+ * @returns Promise resolving to formatted timestamp information
107
+ */
108
+ export declare function parseVerifyResult(verifyResult: TimestampResult): Promise<TimestampInfo>;
109
+ /**
110
+ * Upgrades OpenTimestamps proof in an existing ZIP file.
111
+ * Replaces old timestamp metadata with upgraded OTS proof data.
112
+ * @param zipFilePath - Path to ZIP file to upgrade
113
+ * @param upgradedOts - Buffer containing upgraded OTS proof
114
+ * @returns Promise that resolves when upgrade is complete
115
+ * @throws Error if upgrade fails
116
+ */
117
+ export declare function upgradeOTS(zipFilePath: string, upgradedOts: Buffer): Promise<void>;
118
+ /**
119
+ * Creates a ZIP metadata entry containing OpenTimestamps proof.
120
+ * Creates a special ZIP entry marked as metadata that stores OTS proof data.
121
+ * @param zipKit - Zipkit instance to add metadata entry to
122
+ * @param ots - Buffer containing OpenTimestamps proof data
123
+ * @returns ZIP entry containing OTS metadata, or null if creation failed
124
+ */
125
+ export declare function createOtsMetadataEntry(zipKit: any, ots: Buffer | null): any | null;
126
+ //# sourceMappingURL=ZipkitOTS.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZipkitOTS.d.ts","sourceRoot":"","sources":["../../../src/blockchain/core/ZipkitOTS.ts"],"names":[],"mappings":"AAyCA,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,QAAQ,EAAE,GAAG,CAAC;CACnB;AAwCD,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,GAAG,EAAE,WAAW,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,YAAY,EAAE,GAAG,GAAG,IAAI,CAAC;IACzB,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;CACjC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,IAAI,GAAG,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,GAAG,IAA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AAG,EAAE,GAAG,GAAG,OAAO,CAAC,eAAe,CAAC,CAoBrE;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiBtH;AAED;;;;;;;GAOG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,eAAe,EACzB,OAAO,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiDxB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,YAAY,EAAE,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC,CA2B7F;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA8IxF;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,CAYlF"}
@@ -0,0 +1,506 @@
1
+ /**
2
+ * ======================================
3
+ * ZipkitOTS.ts - OpenTimestamps Integration
4
+ * ======================================
5
+ *
6
+ * This module provides comprehensive OpenTimestamps (OTS) functionality for ZIP files,
7
+ * including timestamp creation, verification, certificate generation, and proof upgrades.
8
+ *
9
+ * Key Features:
10
+ * - Bitcoin blockchain timestamping via OpenTimestamps
11
+ * - Merkle root calculation and verification
12
+ * - OTS proof upgrade capabilities
13
+ * - Certificate generation for verified timestamps
14
+ * - Integration with ZIP file metadata
15
+ *
16
+ * @fileoverview OpenTimestamps utilities for blockchain-enabled ZIP files
17
+ * @author NeoWare Inc.
18
+ */
19
+ "use server";
20
+ "use strict";
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.verifyOts = verifyOts;
26
+ exports.bufferToArrayBuffer = bufferToArrayBuffer;
27
+ exports.getOtsEntry = getOtsEntry;
28
+ exports.getOtsBuffer = getOtsBuffer;
29
+ exports.getMerkleRootSafe = getMerkleRootSafe;
30
+ exports.verifyOtsZip = verifyOtsZip;
31
+ exports.createTimestamp = createTimestamp;
32
+ exports.deserializeOts = deserializeOts;
33
+ exports.parseVerifyResult = parseVerifyResult;
34
+ exports.upgradeOTS = upgradeOTS;
35
+ exports.createOtsMetadataEntry = createOtsMetadataEntry;
36
+ // ===== Imports =====
37
+ const moment_timezone_1 = __importDefault(require("moment-timezone"));
38
+ const core_1 = __importDefault(require("../../core"));
39
+ const Headers_1 = require("../../core/constants/Headers");
40
+ const ZipCrypto_1 = require("../../core/encryption/ZipCrypto");
41
+ // Platform detection
42
+ const isNode = typeof process !== 'undefined' && process.versions && process.versions.node;
43
+ // Node.js specific imports
44
+ let fs = null;
45
+ if (isNode) {
46
+ fs = require('fs');
47
+ }
48
+ if (globalThis._bitcore)
49
+ delete globalThis._bitcore;
50
+ let OTSInstance = null;
51
+ /**
52
+ * Lazily loads the OpenTimestamps module to avoid import conflicts.
53
+ * @returns Promise resolving to OpenTimestamps module instance
54
+ */
55
+ async function getOpenTimestamps() {
56
+ if (!OTSInstance) {
57
+ // @ts-ignore
58
+ OTSInstance = (await import('opentimestamps')).default;
59
+ }
60
+ return OTSInstance;
61
+ }
62
+ /**
63
+ * Executes a function with OpenTimestamps logging control.
64
+ * @param debug - If true, keeps logging enabled; if false, suppresses console output
65
+ * @param fn - Function to execute with controlled logging
66
+ * @returns Promise resolving to function result
67
+ */
68
+ async function withOtsLogging(debug, fn) {
69
+ if (debug)
70
+ return fn();
71
+ const originalLog = console.log;
72
+ const originalDebug = console.debug;
73
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
74
+ console.log = () => { };
75
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
76
+ console.debug = () => { };
77
+ try {
78
+ return await fn();
79
+ }
80
+ finally {
81
+ console.log = originalLog;
82
+ console.debug = originalDebug;
83
+ }
84
+ }
85
+ /**
86
+ * Verifies an OpenTimestamps proof against a hash digest.
87
+ * @param hashDigest - SHA256 hash as hex string to verify
88
+ * @param ots - OpenTimestamps proof data
89
+ * @param options - Configuration options
90
+ * @param options.debug - Enable debug logging
91
+ * @returns Promise resolving to verification result, error object, or null if inputs invalid
92
+ */
93
+ async function verifyOts(hashDigest, ots, options) {
94
+ if (!hashDigest || !ots)
95
+ return null;
96
+ const tsResult = {
97
+ merkleRoot: hashDigest,
98
+ ots,
99
+ verified: false,
100
+ results: null,
101
+ error: null,
102
+ attestations: null,
103
+ upgradedOts: null,
104
+ };
105
+ try {
106
+ return await withOtsLogging(options?.debug, async () => {
107
+ const OpenTimestamps = await getOpenTimestamps();
108
+ const _otsBuffer = Buffer.from(ots);
109
+ const detachedOts = OpenTimestamps.DetachedTimestampFile.deserialize(_otsBuffer);
110
+ const digest = Buffer.from(hashDigest, 'hex');
111
+ const hashOts = OpenTimestamps.DetachedTimestampFile.fromHash(new OpenTimestamps.Ops.OpSHA256(), digest);
112
+ const upgrade = await OpenTimestamps.upgrade(detachedOts);
113
+ if (upgrade) {
114
+ console.log('verifyOts === Timestamp should be upgraded!');
115
+ tsResult.upgradedOts = detachedOts.serializeToBytes();
116
+ }
117
+ tsResult.results = await OpenTimestamps.verify(detachedOts, hashOts, {
118
+ ignoreBitcoinNode: true,
119
+ timeout: 5000,
120
+ });
121
+ const _attest = [];
122
+ detachedOts.timestamp.allAttestations().forEach((attestation) => {
123
+ if (!(attestation instanceof OpenTimestamps.Notary.UnknownAttestation)) {
124
+ _attest.push(attestation);
125
+ }
126
+ });
127
+ tsResult.attestations = JSON.stringify(_attest);
128
+ tsResult.verified = !!tsResult.results && Object.keys(tsResult.results).length > 0;
129
+ if (!tsResult.verified)
130
+ tsResult.results = null;
131
+ console.log('verifyOts === tsResult: ', tsResult);
132
+ return tsResult;
133
+ });
134
+ }
135
+ catch (error) {
136
+ let errMsg = error?.message || 'Timestamp Verification Failed!';
137
+ if (errMsg.includes('ESOCKETTIMEDOUT'))
138
+ errMsg = 'Server timed out, Try again in a few minutes.';
139
+ else if (errMsg.includes('502'))
140
+ errMsg = 'Server failed to respond, Try again in a few minutes.';
141
+ else if (errMsg.includes('ECONNRESET'))
142
+ errMsg = 'Server connection reset, Try again in a few minutes.';
143
+ return { error: errMsg };
144
+ }
145
+ }
146
+ /**
147
+ * Converts a Node.js Buffer to an ArrayBuffer.
148
+ * @param buf - Buffer to convert
149
+ * @returns ArrayBuffer with same data
150
+ */
151
+ function bufferToArrayBuffer(buf) {
152
+ const ab = new ArrayBuffer(buf.byteLength);
153
+ const view = new Uint8Array(ab);
154
+ view.set(buf);
155
+ return ab;
156
+ }
157
+ /**
158
+ * Finds the OpenTimestamps entry in a ZIP file.
159
+ * Searches for TIMESTAMP_METADATA first, then TIMESTAMP_SUBMITTED.
160
+ * @param zip - Zipkit instance to search
161
+ * @returns ZIP entry containing OTS proof, or null if not found
162
+ */
163
+ function getOtsEntry(zip) {
164
+ try {
165
+ // Include metadata entries in the directory
166
+ const entries = zip.getDirectory?.(true) || [];
167
+ // Prefer upgraded metadata entry first
168
+ let entry = entries.find((e) => e && e.filename === Headers_1.TIMESTAMP_METADATA);
169
+ if (entry)
170
+ return entry;
171
+ // Fallback to submitted proof entry
172
+ entry = entries.find((e) => e && e.filename === Headers_1.TIMESTAMP_SUBMITTED);
173
+ if (entry)
174
+ return entry;
175
+ }
176
+ catch {
177
+ return null;
178
+ }
179
+ }
180
+ /**
181
+ * Extracts OTS proof data from a ZIP entry.
182
+ * @param zip - Zipkit instance
183
+ * @param otsEntry - ZIP entry containing OTS data
184
+ * @returns Promise resolving to OTS proof buffer, or null if extraction fails
185
+ */
186
+ async function getOtsBuffer(zip, otsEntry) {
187
+ try {
188
+ const data = await zip.extract(otsEntry, true);
189
+ return Buffer.isBuffer(data) ? data : null;
190
+ }
191
+ catch {
192
+ return null;
193
+ }
194
+ }
195
+ /**
196
+ * Safely extracts merkle root from a ZIP file.
197
+ * @param zip - Zipkit instance
198
+ * @returns Merkle root hash string, or null if not available
199
+ */
200
+ function getMerkleRootSafe(zip) {
201
+ try {
202
+ const mr = zip.getMerkleRoot?.();
203
+ return (typeof mr === 'string' && mr.length > 0) ? mr : null;
204
+ }
205
+ catch {
206
+ return null;
207
+ }
208
+ }
209
+ /**
210
+ * Converts various date formats to a Date object.
211
+ * @param val - Date value (number timestamp, string, or Date)
212
+ * @returns Date object or undefined if invalid
213
+ */
214
+ function coerceDate(val) {
215
+ if (!val)
216
+ return undefined;
217
+ if (typeof val === 'number')
218
+ return new Date(val * (val > 10000000000 ? 1 : 1000));
219
+ if (typeof val === 'string')
220
+ return new Date(val);
221
+ return undefined;
222
+ }
223
+ /**
224
+ * Verifies OpenTimestamps proof within a ZIP file.
225
+ * Extracts merkle root and OTS proof, then verifies against Bitcoin blockchain.
226
+ * @param zip - Zipkit instance containing files and OTS proof
227
+ * @returns Promise resolving to verification result with status: 'none', 'error', 'pending', or 'valid'
228
+ */
229
+ async function verifyOtsZip(zip) {
230
+ const mr = getMerkleRootSafe(zip);
231
+ const entry = getOtsEntry(zip);
232
+ if (!entry)
233
+ return { status: 'none' };
234
+ const otsBuf = await getOtsBuffer(zip, entry);
235
+ if (!otsBuf || !mr)
236
+ return { status: 'error' };
237
+ try {
238
+ const result = await verifyOts(mr, bufferToArrayBuffer(otsBuf));
239
+ if (result?.verified === true) {
240
+ const bitcoin = result?.results?.bitcoin || {};
241
+ const blockHeight = result.blockHeight ?? result.block ?? result.height ?? bitcoin.height;
242
+ const attestedAt = coerceDate(result.attestedAt ?? result.attested ?? result.time ?? bitcoin.timestamp);
243
+ const upgraded = Boolean(result.upgraded || result.upgradedOts);
244
+ const upgradedOts = result.upgradedOts ? Buffer.from(result.upgradedOts) : undefined;
245
+ return { status: 'valid', blockHeight, attestedAt, upgraded, upgradedOts };
246
+ }
247
+ return { status: 'pending' };
248
+ }
249
+ catch (e) {
250
+ return { status: 'pending', message: e?.message };
251
+ }
252
+ }
253
+ /**
254
+ * Creates an OpenTimestamps proof for a hash digest.
255
+ * Submits hash to OpenTimestamps servers for Bitcoin blockchain anchoring.
256
+ * @param hashDigest - SHA256 hash as hex string to timestamp
257
+ * @param options - Configuration options
258
+ * @param options.debug - Enable debug logging
259
+ * @returns Promise resolving to OTS proof buffer, or null if creation failed
260
+ */
261
+ async function createTimestamp(hashDigest, options) {
262
+ if (!hashDigest)
263
+ return null;
264
+ try {
265
+ return await withOtsLogging(options?.debug, async () => {
266
+ const OpenTimestamps = await getOpenTimestamps();
267
+ const hashBuffer = Buffer.from(hashDigest, 'hex');
268
+ const detached = OpenTimestamps.DetachedTimestampFile.fromHash(new OpenTimestamps.Ops.OpSHA256(), hashBuffer);
269
+ await OpenTimestamps.stamp(detached);
270
+ return Buffer.from(detached.serializeToBytes());
271
+ });
272
+ }
273
+ catch (error) {
274
+ console.error('Error creating timestamp:', error);
275
+ throw new Error('Error creating timestamp');
276
+ }
277
+ }
278
+ /**
279
+ * Deserializes OpenTimestamps verification result into JSON format.
280
+ * Extracts blockchain attestation data and transaction details.
281
+ * @param tsResult - Timestamp verification result to deserialize
282
+ * @param options - Configuration options
283
+ * @param options.debug - Enable debug logging
284
+ * @returns Promise resolving to JSON string with attestation data, or null if failed
285
+ */
286
+ async function deserializeOts(tsResult, options) {
287
+ let result = {
288
+ attestStr: null,
289
+ needsUpdateMsg: null,
290
+ attestationValues: [],
291
+ };
292
+ for (const chain in tsResult.results) {
293
+ const _results = tsResult.results[chain];
294
+ const _attestDate = (0, moment_timezone_1.default)(_results.timestamp * 1000).tz(moment_timezone_1.default.tz.guess()).format('MM-DD-YYYY hh:mma z');
295
+ const blockchain = chain.charAt(0).toUpperCase() + chain.slice(1);
296
+ result.attestStr = `<b>${blockchain} block ${_results.height}</b> attests existence as of <b>${_attestDate}</b>`;
297
+ }
298
+ let timestamp = tsResult.ots;
299
+ if (tsResult.upgradedOts != null) {
300
+ result.needsUpdateMsg = 'This Zip file requires updated Timestamp Metadata!';
301
+ timestamp = tsResult.upgradedOts;
302
+ }
303
+ if (!timestamp)
304
+ return null;
305
+ const infoResult = await withOtsLogging(options?.debug, async () => {
306
+ const OpenTimestamps = await getOpenTimestamps();
307
+ const detached = OpenTimestamps.DetachedTimestampFile.deserialize(Buffer.from(timestamp));
308
+ return OpenTimestamps.info(detached);
309
+ });
310
+ const transactionIdMatches = [...infoResult.matchAll(/transaction id ([a-f0-9]+)/gi)];
311
+ const transactionIds = transactionIdMatches.map((m) => m[1]);
312
+ const blockHeightMatches = [...infoResult.matchAll(/verify BitcoinBlockHeaderAttestation\((\d+)\)/g)];
313
+ const blockHeights = blockHeightMatches.map((m) => m[1]);
314
+ const merkleRootMatches = [...infoResult.matchAll(/block merkle root ([a-f0-9]+)/gi)];
315
+ const merkleRoots = merkleRootMatches.map((m) => m[1]);
316
+ result.attestationValues = [];
317
+ if (transactionIds.length === blockHeights.length && transactionIds.length === merkleRoots.length) {
318
+ for (let i = 0; i < transactionIds.length; i++) {
319
+ result.attestationValues.push({
320
+ blockHeight: blockHeights[i],
321
+ transactionId: transactionIds[i],
322
+ merkleRoot: merkleRoots[i],
323
+ });
324
+ }
325
+ result.attestationValues.sort((a, b) => a.blockHeight - b.blockHeight);
326
+ }
327
+ return JSON.stringify(result);
328
+ }
329
+ /**
330
+ * Parses timestamp verification result into readable information.
331
+ * Formats blockchain attestation data with human-readable messages and dates.
332
+ * @param verifyResult - Timestamp verification result to parse
333
+ * @returns Promise resolving to formatted timestamp information
334
+ */
335
+ async function parseVerifyResult(verifyResult) {
336
+ let tsInfo = {
337
+ message: '',
338
+ results: [],
339
+ attestDate: null,
340
+ attestHeight: null,
341
+ submittedUri: null,
342
+ otsUpgraded: false,
343
+ };
344
+ for (const chain in verifyResult?.results) {
345
+ const _results = verifyResult.results[chain];
346
+ const _date = (0, moment_timezone_1.default)(_results.timestamp * 1000).tz('UTC').format('MM-DD-YYYY hh:mma z');
347
+ const _blockchain = chain.charAt(0).toUpperCase() + chain.slice(1);
348
+ tsInfo.message = `Validated - ${_blockchain} block ${_results.height} attests existence as of ${_date}`;
349
+ if (tsInfo.attestHeight == null) {
350
+ tsInfo.attestDate = new Date(_results.timestamp * 1000);
351
+ tsInfo.attestHeight = _results.height;
352
+ }
353
+ tsInfo.results.push(tsInfo.message);
354
+ }
355
+ if (verifyResult?.upgradedOts) {
356
+ tsInfo.otsUpgraded = true;
357
+ tsInfo.results.push('Notice: Please select "Upgrade Timestamp" to save the upgraded timestamp.');
358
+ }
359
+ return tsInfo;
360
+ }
361
+ /**
362
+ * Upgrades OpenTimestamps proof in an existing ZIP file.
363
+ * Replaces old timestamp metadata with upgraded OTS proof data.
364
+ * @param zipFilePath - Path to ZIP file to upgrade
365
+ * @param upgradedOts - Buffer containing upgraded OTS proof
366
+ * @returns Promise that resolves when upgrade is complete
367
+ * @throws Error if upgrade fails
368
+ */
369
+ async function upgradeOTS(zipFilePath, upgradedOts) {
370
+ if (!fs) {
371
+ throw new Error('upgradeOTS() is only available in Node.js environment');
372
+ }
373
+ if (!fs.existsSync(zipFilePath)) {
374
+ throw new Error(`Zip file not found: ${zipFilePath}`);
375
+ }
376
+ if (!upgradedOts || upgradedOts.length === 0) {
377
+ throw new Error('Invalid upgraded OTS data provided');
378
+ }
379
+ // Create a temporary file for the upgrade process
380
+ const tempPath = `${zipFilePath}.upgrading.${Date.now()}.${process.pid}`;
381
+ try {
382
+ // Load the existing zip file
383
+ const zipKit = new core_1.default();
384
+ const zipData = fs.readFileSync(zipFilePath);
385
+ zipKit.loadZip(zipData);
386
+ const zipEntries = zipKit.getDirectory(false) || [];
387
+ if (!zipEntries || zipEntries.length === 0) {
388
+ throw new Error('No entries found in zip file or file is corrupted');
389
+ }
390
+ // Prepare buffers for the new zip file
391
+ const buffers = [];
392
+ let offset = 0;
393
+ const keptEntries = [];
394
+ // Process existing entries, excluding old timestamp entries
395
+ for (const entry of zipEntries) {
396
+ if (entry.filename === Headers_1.TIMESTAMP_METADATA ||
397
+ entry.filename === Headers_1.TIMESTAMP_SUBMITTED) {
398
+ // Skip old timestamp entries - they will be replaced
399
+ continue;
400
+ }
401
+ // Copy the entry data
402
+ const entryData = await zipKit.copyEntry(entry);
403
+ if (!entryData) {
404
+ throw new Error(`Failed to copy entry data for: ${entry.filename}`);
405
+ }
406
+ // Update the entry's local header offset
407
+ entry.localHdrOffset = offset;
408
+ offset += entryData.length;
409
+ buffers.push(entryData);
410
+ keptEntries.push(entry);
411
+ }
412
+ // Create the new upgraded timestamp entry with standard filename
413
+ const tsEntry = zipKit.createZipEntry(Headers_1.TIMESTAMP_METADATA);
414
+ if (!tsEntry) {
415
+ throw new Error('Failed to create timestamp metadata entry');
416
+ }
417
+ // Configure the timestamp entry
418
+ tsEntry.timeDateDOS = tsEntry.setDateTime(new Date());
419
+ tsEntry.compressedSize = upgradedOts.length;
420
+ tsEntry.uncompressedSize = upgradedOts.length;
421
+ tsEntry.cmpMethod = Headers_1.CMP_METHOD.STORED; // Store without compression
422
+ tsEntry.crc = (0, ZipCrypto_1.crc32)(upgradedOts);
423
+ tsEntry.fileData = upgradedOts; // Cast to any to avoid type issues
424
+ // Create and add the local header for the timestamp entry
425
+ const localHdr = tsEntry.createLocalHdr();
426
+ if (!localHdr) {
427
+ throw new Error('Failed to create local header for timestamp entry');
428
+ }
429
+ tsEntry.localHdrOffset = offset;
430
+ offset += localHdr.length + tsEntry.compressedSize;
431
+ buffers.push(localHdr);
432
+ buffers.push(upgradedOts);
433
+ // Add the timestamp entry to our list of entries
434
+ keptEntries.push(tsEntry);
435
+ // Create central directory
436
+ const centralDirOffset = offset;
437
+ let centralDirSize = 0;
438
+ for (const entry of keptEntries) {
439
+ const centralDirEntry = entry.centralDirEntry();
440
+ if (!centralDirEntry) {
441
+ throw new Error(`Failed to create central directory entry for: ${entry.filename}`);
442
+ }
443
+ centralDirSize += centralDirEntry.length;
444
+ buffers.push(centralDirEntry);
445
+ }
446
+ // Create end of central directory record
447
+ const endOfCentralDir = Buffer.alloc(22);
448
+ endOfCentralDir.writeUInt32LE(0x06054b50, 0); // End of central dir signature
449
+ endOfCentralDir.writeUInt16LE(0, 4); // Number of this disk
450
+ endOfCentralDir.writeUInt16LE(0, 6); // Disk where central directory starts
451
+ endOfCentralDir.writeUInt16LE(keptEntries.length, 8); // Number of central directory records on this disk
452
+ endOfCentralDir.writeUInt16LE(keptEntries.length, 10); // Total number of central directory records
453
+ endOfCentralDir.writeUInt32LE(centralDirSize, 12); // Size of central directory
454
+ endOfCentralDir.writeUInt32LE(centralDirOffset, 16); // Offset of start of central directory
455
+ endOfCentralDir.writeUInt16LE(0, 20); // ZIP file comment length
456
+ buffers.push(endOfCentralDir);
457
+ // Write the complete new zip file to temporary location
458
+ const finalBuffer = Buffer.concat(buffers);
459
+ fs.writeFileSync(tempPath, finalBuffer);
460
+ // Validate the temporary file was created successfully
461
+ if (!fs.existsSync(tempPath)) {
462
+ throw new Error('Failed to create temporary upgraded file');
463
+ }
464
+ const tempStats = fs.statSync(tempPath);
465
+ if (tempStats.size === 0) {
466
+ throw new Error('Temporary upgraded file is empty');
467
+ }
468
+ // Replace the original file with the upgraded version
469
+ fs.unlinkSync(zipFilePath);
470
+ fs.renameSync(tempPath, zipFilePath);
471
+ }
472
+ catch (error) {
473
+ // Clean up temporary file if it exists
474
+ if (fs.existsSync(tempPath)) {
475
+ try {
476
+ fs.unlinkSync(tempPath);
477
+ }
478
+ catch (cleanupError) {
479
+ // Log cleanup error but don't throw - main error is more important
480
+ console.warn(`Warning: Could not clean up temporary file ${tempPath}: ${cleanupError}`);
481
+ }
482
+ }
483
+ // Re-throw the original error
484
+ throw error;
485
+ }
486
+ }
487
+ /**
488
+ * Creates a ZIP metadata entry containing OpenTimestamps proof.
489
+ * Creates a special ZIP entry marked as metadata that stores OTS proof data.
490
+ * @param zipKit - Zipkit instance to add metadata entry to
491
+ * @param ots - Buffer containing OpenTimestamps proof data
492
+ * @returns ZIP entry containing OTS metadata, or null if creation failed
493
+ */
494
+ function createOtsMetadataEntry(zipKit, ots) {
495
+ if (!ots || !zipKit)
496
+ return null;
497
+ const tsEntry = zipKit.createZipEntry(Headers_1.TIMESTAMP_SUBMITTED);
498
+ tsEntry.crc = (0, ZipCrypto_1.crc32)(ots);
499
+ tsEntry.uncompressedSize = ots.length;
500
+ tsEntry.compressedSize = ots.length;
501
+ tsEntry.cmpMethod = Headers_1.CMP_METHOD.STORED;
502
+ tsEntry.fileBuffer = ots;
503
+ tsEntry.isMetaData = true;
504
+ return tsEntry;
505
+ }
506
+ //# sourceMappingURL=ZipkitOTS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZipkitOTS.js","sourceRoot":"","sources":["../../../src/blockchain/core/ZipkitOTS.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,YAAY,CAAC;AACb,YAAY,CAAC;;;;;AA0Gb,8BA6DC;AAOD,kDAKC;AAQD,kCAeC;AAQD,oCAOC;AAOD,8CAOC;AAoBD,oCAoBC;AAUD,0CAiBC;AAUD,wCAoDC;AAQD,8CA2BC;AAUD,gCA8IC;AASD,wDAYC;AAtjBD,sBAAsB;AACtB,sEAAqC;AACrC,sDAAgC;AAChC,0DAAmG;AACnG,+DAAwD;AAExD,qBAAqB;AACrB,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;AAE3F,2BAA2B;AAC3B,IAAI,EAAE,GAAQ,IAAI,CAAC;AACnB,IAAI,MAAM,EAAE,CAAC;IACX,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC;AAUD,IAAK,UAAkB,CAAC,QAAQ;IAAE,OAAQ,UAAkB,CAAC,QAAQ,CAAC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