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
@@ -1,271 +0,0 @@
1
- // ======================================
2
- // ZipKitOTS.ts
3
- // Copyright (c) 2025 NeoWare, Inc. All rights reserved.
4
- // ======================================
5
- // ZipKit OpenTimestamps Routines
6
- "use server";
7
- "use strict";
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
- Object.defineProperty(o, "default", { enumerable: true, value: v });
21
- }) : function(o, v) {
22
- o["default"] = v;
23
- });
24
- var __importStar = (this && this.__importStar) || (function () {
25
- var ownKeys = function(o) {
26
- ownKeys = Object.getOwnPropertyNames || function (o) {
27
- var ar = [];
28
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
- return ar;
30
- };
31
- return ownKeys(o);
32
- };
33
- return function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
- })();
41
- var __importDefault = (this && this.__importDefault) || function (mod) {
42
- return (mod && mod.__esModule) ? mod : { "default": mod };
43
- };
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.verifyTimestamp = verifyTimestamp;
46
- exports.createTimestamp = createTimestamp;
47
- exports.deserializeOts = deserializeOts;
48
- exports.parseVerifyResult = parseVerifyResult;
49
- const moment_timezone_1 = __importDefault(require("moment-timezone"));
50
- if (global._bitcore)
51
- delete global._bitcore;
52
- let OTSInstance = null;
53
- async function getOTS() {
54
- if (!OTSInstance) {
55
- OTSInstance = (await Promise.resolve().then(() => __importStar(require('opentimestamps')))).default;
56
- }
57
- return OTSInstance;
58
- }
59
- /**
60
- * Verifies a timestamp proof against a file hash
61
- *
62
- * @param hashDigest - SHA-256 hash digest of the file or merkle root (hex string)
63
- * @param otsData - The OpenTimestamps proof data
64
- * @returns Promise with verification result or null on critical failure
65
- *
66
- * @example
67
- * // Verify a timestamp proof
68
- * const hashDigest = "8a9d..."; // SHA-256 digest in hex format
69
- * const result = await verifyTimestamp(hashDigest, otsBuffer);
70
- *
71
- * if (result) {
72
- * if (result.error) {
73
- * console.error("Verification failed:", result.error);
74
- * } else {
75
- * console.log("Verification succeeded:", result.verified);
76
- *
77
- * if (result.upgradedOts) {
78
- * // Save the upgraded timestamp
79
- * }
80
- * }
81
- * }
82
- */
83
- async function verifyTimestamp(hashDigest, ots) {
84
- if (!hashDigest || !ots) {
85
- console.error('verifyTimestamp - Invalid parameters');
86
- return null;
87
- }
88
- const tsResult = {
89
- merkleRoot: hashDigest,
90
- ots: ots,
91
- verified: false,
92
- results: null,
93
- error: null,
94
- attestations: null,
95
- upgradedOts: null,
96
- };
97
- try {
98
- const OpenTimestamps = await getOTS();
99
- // Convert the base64 string to a Buffer
100
- // const _otsBuffer = Buffer.from(ots, 'base64');
101
- const _otsBuffer = Buffer.from(ots);
102
- const detachedOts = OpenTimestamps.DetachedTimestampFile.deserialize(_otsBuffer);
103
- const digest = Buffer.from(hashDigest, 'hex');
104
- const hashOts = OpenTimestamps.DetachedTimestampFile.fromHash(new OpenTimestamps.Ops.OpSHA256(), digest);
105
- // Check if the MetaStamp should be upgraded
106
- const upgrade = await OpenTimestamps.upgrade(detachedOts);
107
- if (upgrade) {
108
- console.log('verifyTimestamp === Timestamp should be upgraded!');
109
- tsResult.upgradedOts = detachedOts.serializeToBytes();
110
- }
111
- // Verify the MetaStamp
112
- tsResult.results = await OpenTimestamps.verify(detachedOts, hashOts, {
113
- ignoreBitcoinNode: true, // Don't check for local Bitcoin node
114
- timeout: 5000
115
- });
116
- var _attest = [];
117
- detachedOts.timestamp.allAttestations().forEach((attestation) => {
118
- if (attestation instanceof OpenTimestamps.Notary.UnknownAttestation) {
119
- console.log('Unknown attestation type');
120
- }
121
- else {
122
- // console.log(attestation);
123
- _attest.push(attestation);
124
- }
125
- });
126
- tsResult.attestations = JSON.stringify(_attest);
127
- // Check if the results show a verified timestamp
128
- if (Object.keys(tsResult.results).length < 1) {
129
- tsResult.results = null;
130
- tsResult.verified = false;
131
- }
132
- else {
133
- tsResult.verified = true;
134
- }
135
- console.log('verifyTimestamp === tsResult: ', tsResult);
136
- return tsResult;
137
- }
138
- catch (error) {
139
- let errMsg = error?.message || 'Timestamp Verification Failed!';
140
- if (errMsg.indexOf('ESOCKETTIMEDOUT') != -1) {
141
- errMsg = 'Server timed out, Try again in a few minutes.';
142
- }
143
- else if (errMsg.indexOf('502') != -1) {
144
- errMsg = 'Server failed to respond, Try again in a few minutes.';
145
- }
146
- else if (errMsg.indexOf('ECONNRESET') != -1) {
147
- errMsg = 'Server connection reset, Try again in a few minutes.';
148
- }
149
- return { error: errMsg };
150
- }
151
- }
152
- /**
153
- * Creates a timestamp proof for a file hash using OpenTimestamps
154
- *
155
- * @param hashDigest - SHA-256 hash digest of the file or merkle root (hex string)
156
- * @returns Promise containing the OpenTimestamps proof or null on failure
157
- *
158
- * @example
159
- * // Create a timestamp for a file hash
160
- * const hashDigest = "8a9d..."; // SHA-256 digest in hex format
161
- * const timestampProof = await createTimestamp(hashDigest);
162
- *
163
- * if (timestampProof) {
164
- * // Save the timestamp proof to storage
165
- * }
166
- */
167
- async function createTimestamp(hashDigest) {
168
- if (!hashDigest)
169
- return null;
170
- try {
171
- const OpenTimestamps = await getOTS();
172
- // Convert hex string to Buffer
173
- const hashBuffer = Buffer.from(hashDigest, 'hex');
174
- // Create detached timestamp file
175
- const detached = OpenTimestamps.DetachedTimestampFile.fromHash(new OpenTimestamps.Ops.OpSHA256(), hashBuffer);
176
- // Create the timestamp
177
- await OpenTimestamps.stamp(detached);
178
- // Return the serialized timestamp
179
- return Buffer.from(detached.serializeToBytes());
180
- }
181
- catch (error) {
182
- console.error('Error creating timestamp:', error);
183
- throw new Error('Error creating timestamp');
184
- }
185
- }
186
- /**
187
- * Deserializes timestamp metadata to extract attestation information
188
- * Used for generating timestamp certificates and displaying verification details
189
- *
190
- * @param tsResult - Timestamp verification result to deserialize
191
- * @returns JSON string of deserialized data or null on failure
192
- */
193
- async function deserializeOts(tsResult) {
194
- let result = {
195
- attestStr: null,
196
- needsUpdateMsg: null,
197
- attestationValues: [],
198
- };
199
- for (const chain in tsResult.results) {
200
- let _results = tsResult.results[chain];
201
- const _attestDate = (0, moment_timezone_1.default)(_results.timestamp * 1000).tz(moment_timezone_1.default.tz.guess()).format('MM-DD-YYYY hh:mma z');
202
- const blockchain = chain.charAt(0).toUpperCase() + chain.slice(1);
203
- result.attestStr = `<b>${blockchain} block ${_results.height}</b> attests existence as of <b>${_attestDate}</b>`;
204
- }
205
- ;
206
- let timestamp = tsResult.ots;
207
- if (tsResult.upgradedOts != null) {
208
- result.needsUpdateMsg = "This Zip file requires updated Timestamp Metadata!";
209
- // Use the updated timestamp metadata
210
- timestamp = tsResult.upgradedOts;
211
- }
212
- // Extract the attestation values from the timestamp metadata
213
- if (!timestamp)
214
- return null;
215
- const OpenTimestamps = await getOTS();
216
- const detached = OpenTimestamps.DetachedTimestampFile.deserialize(Buffer.from(timestamp));
217
- const infoResult = OpenTimestamps.info(detached);
218
- // Extract all transaction IDs using a regular expression
219
- const transactionIdMatches = [...infoResult.matchAll(/transaction id ([a-f0-9]+)/gi)];
220
- const transactionIds = transactionIdMatches.map(match => match[1]);
221
- // Extract the value inside the parentheses using a regular expression
222
- const blockHeightMatches = [...infoResult.matchAll(/verify BitcoinBlockHeaderAttestation\((\d+)\)/g)];
223
- const blockHeights = blockHeightMatches.map(match => match[1]);
224
- // Extract all values after "block merkle root" using a regular expression
225
- const merkleRootMatches = [...infoResult.matchAll(/block merkle root ([a-f0-9]+)/gi)];
226
- const merkleRoots = merkleRootMatches.map(match => match[1]);
227
- // Group the values in a loop
228
- result.attestationValues = [];
229
- if (transactionIds.length === blockHeights.length && transactionIds.length === merkleRoots.length) {
230
- for (let i = 0; i < transactionIds.length; i++) {
231
- result.attestationValues.push({
232
- blockHeight: blockHeights[i],
233
- transactionId: transactionIds[i],
234
- merkleRoot: merkleRoots[i]
235
- });
236
- }
237
- // Sort the grouped values by blockHeight in ascending order
238
- result.attestationValues.sort((a, b) => a.blockHeight - b.blockHeight);
239
- }
240
- return JSON.stringify(result);
241
- }
242
- // Parse the verifyResult into a TimestampInfo object
243
- async function parseVerifyResult(verifyResult) {
244
- let tsInfo = {
245
- message: '',
246
- results: [],
247
- attestDate: null,
248
- attestHeight: null,
249
- submittedUri: null,
250
- otsUpgraded: false
251
- };
252
- for (const chain in verifyResult?.results) {
253
- let _results = verifyResult.results[chain];
254
- const _date = (0, moment_timezone_1.default)(_results.timestamp * 1000)
255
- .tz('UTC')
256
- .format('MM-DD-YYYY hh:mma z');
257
- const _blockchain = chain.charAt(0).toUpperCase() + chain.slice(1);
258
- tsInfo.message = 'Validated - ' + _blockchain + ' block ' + _results.height + ' attests existence as of ' + _date;
259
- if (tsInfo.attestHeight == null) {
260
- tsInfo.attestDate = new Date(_results.timestamp * 1000);
261
- tsInfo.attestHeight = _results.height;
262
- }
263
- tsInfo.results.push(tsInfo.message);
264
- }
265
- ;
266
- if (verifyResult?.upgradedOts) {
267
- tsInfo.otsUpgraded = true;
268
- tsInfo.results.push('Notice: Please select "Upgrade Timestamp" to save the upgraded timestamp.');
269
- }
270
- return tsInfo;
271
- }
@@ -1,249 +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
- * Creates a new timestamp metadata entry for the ZIP file
217
- * Calculates merkle root from file hashes and obtains blockchain timestamp
218
- * @returns Promise<ZipEntry | null> The created timestamp metadata entry or null if failed
219
- */
220
- createTimestampMetadataEntry(ots: Buffer | null): ZipEntry | null;
221
- /**
222
- * Sets the ZIP file comment
223
- * @param msg - Comment to set
224
- */
225
- setZipComment(msg: string | null): void;
226
- /**
227
- * Gets the ZIP file comment
228
- * @returns string | null - The ZIP file comment
229
- */
230
- getZipComment(): string | null;
231
- /**
232
- * Converts the compression method to a string
233
- * @param cmpMethod - Compression method number
234
- * @returns string - Compression method as a string
235
- */
236
- cmpMethodToString(cmpMethod: number): string;
237
- /**
238
- * Ensures ZIP entries are loaded
239
- * @returns Array of ZIP entries
240
- * @throws Error if no ZIP entries are loaded
241
- */
242
- private ensureZipEntries;
243
- /**
244
- * Ensures ZIP data buffer is loaded
245
- * @returns Buffer containing ZIP data
246
- * @throws Error if no ZIP data is loaded
247
- */
248
- private ensureBuffer;
249
- }