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,132 +0,0 @@
1
- // ======================================
2
- // CertificateOTS.ts
3
- // Copyright (c) 2025 NeoWare, Inc. All rights reserved.
4
- // ======================================
5
-
6
- import fs from 'fs';
7
- import path from 'path';
8
- import ZipEntry from '../ZipEntry';
9
-
10
- import {
11
- TIMESTAMP_SUBMITTED,
12
- TIMESTAMP_METADATA,
13
- } from '../constants/Headers';
14
-
15
- // Add this at the top of the file
16
- import type { AttestationValue } from '../types';
17
-
18
- /**
19
- * Generates a certificate HTML document based on timestamp information
20
- *
21
- * @param attestStr - Attestation message
22
- * @param zipFile - Name of the zip file
23
- * @param hashDigest - Hash digest of the zip file
24
- * @param needsUpdateMsg - Message indicating if update is needed
25
- * @param attestationValues - Array of attestation values
26
- * @param zipEntries - Array of ZipEntry objects
27
- * @param narrow - Whether to use narrow layout
28
- * @returns Generated HTML certificate as string
29
- */
30
- export default function CertificateTemplate(
31
- attestStr: string | null,
32
- zipFile: string,
33
- hashDigest: string,
34
- needsUpdateMsg: string,
35
- attestationValues: AttestationValue[],
36
- zipEntries: ZipEntry[],
37
- narrow?: boolean
38
- ): string {
39
- // Load the HTML template
40
- let templatePath;
41
- try {
42
- // Try to find the template from the package root
43
- templatePath = path.resolve(process.cwd(), 'assets/templates/certificate.html');
44
- if (!fs.existsSync(templatePath)) {
45
- // If not found in current working directory, try relative to this file
46
- templatePath = path.resolve(__dirname, '../../assets/templates/certificate.html');
47
- }
48
-
49
- if (!fs.existsSync(templatePath)) {
50
- throw new Error('Certificate template not found');
51
- }
52
- } catch (error) {
53
- console.error('Error resolving template path:', error);
54
- return '';
55
- }
56
-
57
- // Read the template file
58
- let htmlTemplate;
59
- try {
60
- htmlTemplate = fs.readFileSync(templatePath, 'utf8');
61
- } catch (error) {
62
- console.error('Error reading template file:', error);
63
- return '';
64
- }
65
-
66
- const updateWarning = needsUpdateMsg || '';
67
-
68
- // Generate attestation HTML
69
- let attestHTML = '';
70
- if (attestationValues && attestationValues.length > 0) {
71
- attestationValues.forEach((attest) => {
72
- attestHTML += `
73
- <div class="key-value-pair">
74
- <div class="key">Block Height:</div>
75
- <div class="value">${attest['blockHeight']}</div>
76
- </div>
77
- <div class="key-value-pair">
78
- <div class="key">Transaction:</div>
79
- <div class="value">${attest['transactionId']}</div>
80
- </div>
81
- <div class="key-value-pair">
82
- <div class="key">Merkle Root:</div>
83
- <div class="value">${attest['merkleRoot']}</div>
84
- </div>
85
- <br/>
86
- `;
87
- });
88
- }
89
-
90
- // Generate files table HTML
91
- let stampEntry = null;
92
- let files = [];
93
- for (const entry of zipEntries) {
94
- if (entry.filename === TIMESTAMP_METADATA) {
95
- stampEntry = entry;
96
- } else if (entry.filename === TIMESTAMP_SUBMITTED) {
97
- if (stampEntry == null)
98
- stampEntry = entry;
99
- } else if (entry.sha256) {
100
- let file = {
101
- name: entry.filename,
102
- size: entry.uncompressedSize.toString(),
103
- date: entry.toFormattedUTCDateString(),
104
- hash: entry.sha256,
105
- }
106
- files.push(file);
107
- }
108
- }
109
-
110
- let filesTableHTML = '';
111
- files.forEach((file) => {
112
- filesTableHTML += `
113
- <tr>
114
- <td class="table-data1">${file.name}</td>
115
- <td class="table-data">${file.size}</td>
116
- <td class="table-data">${file.date}</td>
117
- <td class="table-data">${file.hash}</td>
118
- </tr>
119
- `;
120
- });
121
-
122
- // Replace placeholders in the template
123
- let html = htmlTemplate
124
- .replace(/{{ATTEST_STR}}/g, attestStr || '')
125
- .replace(/{{UPDATE_WARNING}}/g, needsUpdateMsg ? `<div class="warning">${needsUpdateMsg}</div>` : '')
126
- .replace(/{{ZIP_FILE}}/g, zipFile)
127
- .replace(/{{HASH_DIGEST}}/g, hashDigest)
128
- .replace(/{{ATTESTATION_HTML}}/g, attestHTML)
129
- .replace(/{{FILES_TABLE_HTML}}/g, filesTableHTML);
130
-
131
- return html;
132
- }
@@ -1,87 +0,0 @@
1
- // ======================================
2
- // FileSys.ts
3
- // Copyright (c) 2024 NeoWare, Inc. All rights reserved.
4
- // ======================================
5
-
6
- import * as fs from 'fs';
7
- import * as pth from 'path';
8
-
9
- import Errors from '../constants/Errors';
10
-
11
- // Output a buffer to a file
12
- export function outputToFile(
13
- fileName: string,
14
- buffer: Buffer,
15
- dirPath: string,
16
- overwrite: boolean,
17
- never: boolean,
18
- fileAttr: number)
19
- {
20
- // get Unix file permissions
21
- const _fattr = fileAttr ? (((fileAttr >>> 0) | 0) >> 16) & 0xfff : 0;
22
-
23
- const _path = dirPath ? dirPath + pth.sep + fileName : fileName;
24
-
25
- if (fs.existsSync(_path)) {
26
- console.log('File exists: ', _path);
27
- if (never)
28
- return false;
29
- if (!overwrite) {
30
- console.log('Overwrite file: ', _path);
31
- return false; // cannot overwrite
32
- }
33
-
34
- const stat = fs.statSync(_path);
35
- if (stat.isDirectory())
36
- return false;
37
- }
38
-
39
- // Check if we need to create a new folder
40
- const _folder = pth.dirname(_path);
41
- if (!fs.existsSync(_folder)) {
42
- makeDir(_folder);
43
- }
44
-
45
- var fd;
46
- try {
47
- fd = fs.openSync(_path, "w", 438); // 0666
48
- } catch (e) {
49
- fs.chmodSync(_path, 438);
50
- fd = fs.openSync(_path, "w", 438);
51
- }
52
- if (fd) {
53
- try {
54
- fs.writeSync(fd, buffer, 0, buffer.length, 0);
55
- } finally {
56
- fs.closeSync(fd);
57
- }
58
- }
59
-
60
- if (_fattr)
61
- fs.chmodSync(_path, _fattr);
62
-
63
- return true;
64
- }
65
-
66
- // Make directories tree for a given path
67
- export function makeDir(folder: string) {
68
- console.log('mkDir: ', folder);
69
-
70
- // Sync - make directories tree
71
- function mkdirSync(fpath: string) {
72
- let resolvedPath = fpath.split(pth.sep)[0];
73
- fpath.split(pth.sep).forEach(function (name) {
74
- if (!name || name.endsWith(":")) return;
75
- resolvedPath += pth.sep + name;
76
- var stat;
77
- try {
78
- stat = fs.statSync(resolvedPath);
79
- } catch (e) {
80
- fs.mkdirSync(resolvedPath);
81
- }
82
- if (stat && stat.isFile()) throw Errors.FILE_IN_THE_WAY.replace("%s", resolvedPath);
83
- });
84
- }
85
-
86
- mkdirSync(folder);
87
- };
@@ -1,113 +0,0 @@
1
- // ======================================
2
- // HashAccumulator.ts
3
- // ======================================
4
-
5
- import { MerkleTree } from './merkleTree';
6
-
7
- /**
8
- * Class for accumulating and combining SHA-256 hashes using both XOR and Merkle tree methods
9
- *
10
- * Usage example:
11
- * ```typescript
12
- * const accumulator = new HashAccumulator();
13
- * accumulator.addHash('a1b2c3d4');
14
- * accumulator.addHash('12345678');
15
- * console.log(accumulator.xorHash()); // Outputs the accumulated XOR result
16
- * console.log(accumulator.merkleRoot()); // Outputs the accumulated Merkle root
17
- * ```
18
- */
19
- export default class HashAccumulator {
20
- private hashes: Buffer[]; // Array of hash buffers for Merkle tree
21
- private xorResult: Buffer; // Running XOR of all hashes
22
-
23
- /**
24
- * Creates a new HashAccumulator instance
25
- * Initializes empty hash array and zero-filled XOR buffer
26
- */
27
- constructor() {
28
- this.hashes = [];
29
- this.xorResult = Buffer.alloc(32, 0);
30
- }
31
-
32
- /**
33
- * Adds a hash to both the XOR accumulation and hash array
34
- * @param hash - Hash value as hex string or Buffer
35
- * The hash must be 32 bytes (SHA-256)
36
- */
37
- addHash(hash: string | Buffer) {
38
- // Convert hash to Buffer if it's a string
39
- const hashBuffer = typeof hash === 'string'
40
- ? Buffer.from(hash, 'hex')
41
- : hash;
42
-
43
- // Add to array for Merkle tree
44
- this.hashes.push(hashBuffer);
45
-
46
- // XOR accumulation
47
- for (let i = 0; i < 32; i++) {
48
- this.xorResult[i] ^= hashBuffer[i];
49
- }
50
- }
51
-
52
- /**
53
- * Gets the accumulated XOR of all added hashes
54
- * @returns Hex string of XOR result
55
- */
56
- xorHash(): string {
57
- return this.xorResult.toString('hex');
58
- }
59
-
60
- /**
61
- * Creates a Merkle tree from accumulated hashes and returns the root
62
- * @returns Hex string of Merkle root, or null if no hashes added
63
- */
64
- merkleRoot(): string | null {
65
- let merkleRoot = null;
66
- if (this.hashes.length > 0) {
67
- const tree = new MerkleTree(this.hashes, {
68
- hashLeaves: false, // Leaves are already hashed
69
- sortLeaves: true, // Sort leaves for consistent results
70
- sortPairs: true, // Sort pairs for consistent results
71
- duplicateOdd: true // Duplicate odd leaf for balanced tree
72
- });
73
- merkleRoot = tree.getRoot().toString('hex');
74
- }
75
-
76
- return merkleRoot;
77
- }
78
-
79
- /**
80
- * Gets the number of hashes accumulated
81
- * @returns Number of accumulated hashes
82
- */
83
- leafCount(): number {
84
- return this.hashes.length;
85
- }
86
-
87
- /**
88
- * Resets the accumulator to initial state
89
- * Clears hash array and zeroes XOR buffer
90
- */
91
- clear() {
92
- this.hashes = [];
93
- this.xorResult = Buffer.alloc(32, 0);
94
- }
95
-
96
- /**
97
- * Combines multiple hash results into a single Merkle root
98
- * @param results - Array of objects containing merkleRoot properties
99
- * @returns Combined Merkle root as hex string, or null if no valid roots
100
- */
101
- static combineResults(results: { merkleRoot?: string }[]) {
102
- const accumulator = new HashAccumulator();
103
-
104
- // Combine all hashes
105
- for (const result of results) {
106
- if (result.merkleRoot) {
107
- accumulator.addHash(result.merkleRoot);
108
- }
109
- }
110
-
111
- return accumulator.merkleRoot();
112
- }
113
- }
@@ -1,91 +0,0 @@
1
- // ======================================
2
- // ZipCrypto.ts
3
- // Copyright (c) 2024 NeoWare, Inc. All rights reserved.
4
- // ======================================
5
- // Zip Cryptography Routines
6
-
7
- "use strict";
8
-
9
- import { createHash, randomFillSync } from 'crypto';
10
-
11
- import { crc32update, uMul } from './Util';
12
- import { ENCRYPT_HDR_SIZE } from '../constants/Headers';
13
-
14
- // Return the SHA256 hash of a buffer
15
- export function sha256(data: Buffer): string {
16
- const hash = createHash('sha256');
17
-
18
- return hash
19
- .update(data)
20
- .digest('hex');
21
- }
22
-
23
- class InitKeys {
24
- private keys: Uint32Array;
25
-
26
- constructor(pw: string | Buffer) {
27
- this.keys = new Uint32Array([0x12345678, 0x23456789, 0x34567890]);
28
- const pass = typeof pw === 'string' ? Buffer.from(pw) : pw;
29
- for (let i = 0; i < pass.length; i++) {
30
- this.updateKeys(pass[i]);
31
- }
32
- }
33
-
34
- updateKeys(byteValue: number): number {
35
- this.keys[0] = crc32update(this.keys[0], byteValue);
36
- this.keys[1] = ((this.keys[1] + (this.keys[0] & 0xff)) * 0x08088405 + 1) >>> 0;
37
- this.keys[2] = crc32update(this.keys[2], this.keys[1] >>> 24);
38
- return byteValue;
39
- }
40
-
41
- next(): number {
42
- const k = (this.keys[2] | 2) >>> 0; // key
43
- return (uMul(k, k ^ 1) >> 8) & 0xff; // decode
44
- }
45
- }
46
-
47
- // Return encrypting function, result and pos is here so we dont have to merge buffers later
48
- function make_encrypter(pwd: string | Buffer): Function {
49
- const keys = new InitKeys(pwd);
50
-
51
- return function (data: Buffer, result: Buffer, pos: number = 0): Buffer {
52
- // result - we create new Buffer for results
53
- if (!result) result = Buffer.alloc(data.length);
54
- // process input data
55
- for (let c of data) {
56
- const k = keys.next(); // save key byte
57
- result[pos++] = c ^ k; // save val
58
- keys.updateKeys(c); // update keys with decoded byte
59
- }
60
- return result;
61
- };
62
- }
63
-
64
- // Encrypt data with password and include a checkByte verification byte at the end
65
- export function encrypter(data: Buffer | null, checkByte: number, pwd: string): Buffer | null {
66
- if (!data) return null;
67
-
68
- const _encrypter = make_encrypter(pwd);
69
-
70
- const salt = randomFillSync(Buffer.alloc(ENCRYPT_HDR_SIZE));
71
- salt[ENCRYPT_HDR_SIZE - 1] = checkByte;
72
-
73
- // create encryption header
74
- const result = Buffer.alloc(data.length + ENCRYPT_HDR_SIZE);
75
- _encrypter(salt, result);
76
-
77
- // encode content
78
- return _encrypter(data, result, ENCRYPT_HDR_SIZE);
79
- }
80
-
81
- // Return the decrypter function
82
- export function decrypter(pwd: string | Buffer): Function {
83
- const keys = new InitKeys(pwd);
84
-
85
- return function (data: Buffer): Buffer {
86
- for (let i=0; i<data.length; i++) {
87
- data[i] = keys.updateKeys(data[i] ^ keys.next());
88
- }
89
- return data;
90
- };
91
- }
@@ -1,162 +0,0 @@
1
- import { createHash } from 'crypto';
2
-
3
- /**
4
- * Configuration options for Merkle tree construction
5
- */
6
- interface MerkleTreeOptions {
7
- hashLeaves: boolean; // Whether to hash the leaf nodes before adding to tree
8
- sortLeaves: boolean; // Whether to sort leaf nodes for consistent trees
9
- sortPairs: boolean; // Whether to sort each pair before hashing
10
- duplicateOdd: boolean; // Whether to duplicate last leaf when odd number of leaves
11
- }
12
-
13
- /**
14
- * Implementation of a Merkle Tree (hash tree) using SHA-256
15
- *
16
- * A Merkle tree is a binary tree where each non-leaf node is the hash of its two children.
17
- * This allows efficient verification of large datasets by only storing/transmitting the root hash
18
- * and generating proofs of inclusion for individual items.
19
- */
20
- export class MerkleTree {
21
- private leaves: Buffer[]; // Leaf nodes (original data or hashes)
22
- private layers: Buffer[][]; // All layers of the tree, from leaves to root
23
- private options: MerkleTreeOptions;
24
-
25
- /**
26
- * Creates a new Merkle tree from an array of leaf nodes
27
- * @param leaves - Array of leaf node data as Buffers
28
- * @param options - Configuration options for tree construction
29
- */
30
- constructor(leaves: Buffer[], options: Partial<MerkleTreeOptions> = {}) {
31
- this.options = {
32
- hashLeaves: false,
33
- sortLeaves: true,
34
- sortPairs: true,
35
- duplicateOdd: true,
36
- ...options
37
- };
38
-
39
- // Process leaves according to options
40
- this.leaves = leaves.map(leaf => {
41
- if (this.options.hashLeaves) {
42
- return this.hash(leaf);
43
- }
44
- return Buffer.isBuffer(leaf) ? leaf : Buffer.from(leaf);
45
- });
46
-
47
- if (this.options.sortLeaves) {
48
- this.leaves.sort(Buffer.compare);
49
- }
50
-
51
- this.layers = [this.leaves];
52
- this.createHashes(this.leaves);
53
- }
54
-
55
- /**
56
- * Computes SHA-256 hash of input data
57
- * @param data - Data to hash
58
- * @returns Buffer containing hash
59
- */
60
- private hash(data: Buffer): Buffer {
61
- return createHash('sha256').update(data).digest();
62
- }
63
-
64
- /**
65
- * Combines two child hashes to create parent hash
66
- * @param left - Left child hash
67
- * @param right - Right child hash
68
- * @returns Combined hash of children
69
- */
70
- private combinedHash(left: Buffer, right: Buffer): Buffer {
71
- if (this.options.sortPairs && Buffer.compare(left, right) > 0) {
72
- [left, right] = [right, left];
73
- }
74
- return this.hash(Buffer.concat([left, right]));
75
- }
76
-
77
- /**
78
- * Builds the Merkle tree by creating successive layers of hashes
79
- * @param nodes - Array of nodes in current layer
80
- */
81
- private createHashes(nodes: Buffer[]) {
82
- while (nodes.length > 1) {
83
- const layerIndex = this.layers.length;
84
- this.layers.push([]);
85
-
86
- // Process pairs of nodes
87
- for (let i = 0; i < nodes.length - 1; i += 2) {
88
- const left = nodes[i];
89
- const right = nodes[i + 1];
90
- const hash = this.combinedHash(left, right);
91
- this.layers[layerIndex].push(hash);
92
- }
93
-
94
- // Handle odd number of nodes
95
- if (nodes.length % 2 === 1) {
96
- const last = nodes[nodes.length - 1];
97
- if (this.options.duplicateOdd) {
98
- // Duplicate the last node if odd
99
- const hash = this.combinedHash(last, last);
100
- this.layers[layerIndex].push(hash);
101
- } else {
102
- // Push last node up to next layer
103
- this.layers[layerIndex].push(last);
104
- }
105
- }
106
-
107
- nodes = this.layers[layerIndex];
108
- }
109
- }
110
-
111
- /**
112
- * Gets the root hash of the Merkle tree
113
- * @returns Buffer containing root hash
114
- */
115
- public getRoot(): Buffer {
116
- return this.layers[this.layers.length - 1][0];
117
- }
118
-
119
- /**
120
- * Generates a proof of inclusion for a leaf node
121
- * @param leaf - The leaf node to generate proof for
122
- * @returns Array of sibling hashes needed to reconstruct root
123
- * @throws Error if leaf not found in tree
124
- */
125
- public getProof(leaf: Buffer): Buffer[] {
126
- let index = this.leaves.findIndex(item => item.equals(leaf));
127
- if (index === -1) {
128
- throw new Error('Leaf not found in tree');
129
- }
130
-
131
- return this.layers.reduce((proof, layer) => {
132
- if (layer.length === 1) return proof;
133
-
134
- const pairIndex = index % 2 === 0 ? index + 1 : index - 1;
135
- if (pairIndex < layer.length) {
136
- proof.push(layer[pairIndex]);
137
- }
138
-
139
- index = Math.floor(index / 2);
140
- return proof;
141
- }, [] as Buffer[]);
142
- }
143
-
144
- /**
145
- * Verifies a proof of inclusion for a leaf node
146
- * @param proof - Array of sibling hashes from getProof()
147
- * @param targetHash - Hash of the leaf node being verified
148
- * @param root - Expected root hash
149
- * @returns boolean indicating if proof is valid
150
- */
151
- public verify(proof: Buffer[], targetHash: Buffer, root: Buffer): boolean {
152
- let computedHash = targetHash;
153
-
154
- for (const proofElement of proof) {
155
- computedHash = Buffer.compare(computedHash, proofElement) <= 0
156
- ? this.combinedHash(computedHash, proofElement)
157
- : this.combinedHash(proofElement, computedHash);
158
- }
159
-
160
- return computedHash.equals(root);
161
- }
162
- }
@@ -1,25 +0,0 @@
1
- export interface FileData {
2
- name: string;
3
- size: number;
4
- lastModified: number;
5
- arrayBuffer(): Promise<ArrayBuffer>;
6
- }
7
-
8
- export interface ZipFileEntry {
9
- fileData?: FileData;
10
- }
11
-
12
- export interface Support {
13
- base64: boolean;
14
- array: boolean;
15
- string: boolean;
16
- isNode: boolean;
17
- buffer: boolean;
18
- uint8array: boolean;
19
- arrayBuffer: boolean;
20
- blob: boolean;
21
- streams: boolean;
22
- fileReader: boolean;
23
- }
24
-
25
- // External module types are handled by installed @types packages
@@ -1,22 +0,0 @@
1
- declare module 'pako' {
2
- export function deflateRaw(data: Uint8Array | Buffer, options?: any): Buffer;
3
- export function inflateRaw(data: Uint8Array | Buffer): Buffer;
4
- }
5
-
6
- declare module 'opentimestamps' {
7
- export class Ops {
8
- static OpSHA256: any;
9
- }
10
- export class DetachedTimestampFile {
11
- static fromHash(op: any, digest: Buffer): DetachedTimestampFile;
12
- static deserialize(ots: Buffer): DetachedTimestampFile;
13
- serializeToBytes(): Uint8Array;
14
- timestamp?: {
15
- allAttestations(): string[];
16
- };
17
- }
18
- export function stamp(detached: DetachedTimestampFile[]): Promise<void>;
19
- export function upgrade(ots: DetachedTimestampFile): Promise<boolean>;
20
- export function verify(ots: DetachedTimestampFile, hash: DetachedTimestampFile, options?: any): Promise<any>;
21
- export function info(detached: DetachedTimestampFile): string;
22
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * Type declarations for OpenTimestamps module
3
- */
4
- declare module 'opentimestamps' {
5
- namespace stamp {
6
- function create(fileBuffer: Buffer): Promise<Buffer>;
7
- }
8
-
9
- namespace verify {
10
- function verifyTimestamp(ots: Buffer, fileHash: Buffer): Promise<any>;
11
- }
12
-
13
- namespace utils {
14
- function hexToBytes(hex: string): number[];
15
- function bytesToHex(bytes: number[]): string;
16
- }
17
-
18
- export default {
19
- stamp,
20
- verify,
21
- utils
22
- };
23
- }
@@ -1,8 +0,0 @@
1
- // Type declarations for modules without proper TypeScript support
2
-
3
- declare module 'opentimestamps' {
4
- export default class OpenTimestamps {
5
- static stamp(data: Buffer): Promise<any>;
6
- static verify(timestamp: any, data: Buffer): Promise<boolean>;
7
- }
8
- }