neozipkit 0.1.1

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 (135) hide show
  1. package/README.md +400 -0
  2. package/contracts/Lock.sol +34 -0
  3. package/contracts/bytecode.txt +1 -0
  4. package/contracts/compile-contract.js +168 -0
  5. package/contracts/deploy/deploy-both-contracts.js +286 -0
  6. package/contracts/deploy/deploy-enhanced-contract.js +197 -0
  7. package/contracts/deploy/deploy-private-contract.js +190 -0
  8. package/contracts/deploy/deploy-public-clean.js +1063 -0
  9. package/contracts/deploy/deploy-public-contract.js +1107 -0
  10. package/contracts/deployment.config.example.js +25 -0
  11. package/contracts/remix-compile.js +222 -0
  12. package/contracts/setup-deployment.js +51 -0
  13. package/contracts/src/NZIP-NFT-Private.sol +350 -0
  14. package/contracts/src/NZIP-NFT.sol +265 -0
  15. package/contracts/src/ZipFileNFT-DEPRECATED-6field.sol +260 -0
  16. package/contracts/src/ZipFileNFT-DEPRECATED-Enhanced.sol +289 -0
  17. package/dist/browser/CertificateGeneratorBrowser.d.ts +75 -0
  18. package/dist/browser/CertificateGeneratorBrowser.js +433 -0
  19. package/dist/browser/TokenVerifierBrowser.d.ts +76 -0
  20. package/dist/browser/TokenVerifierBrowser.js +299 -0
  21. package/dist/browser/ZipKitBrowser.d.ts +18 -0
  22. package/dist/browser/ZipKitBrowser.js +250 -0
  23. package/dist/browser/ZipKitStampBrowser.d.ts +2 -0
  24. package/dist/browser/ZipKitStampBrowser.js +12 -0
  25. package/dist/browser-index.d.ts +21 -0
  26. package/dist/browser-index.js +58 -0
  27. package/dist/browser.d.ts +21 -0
  28. package/dist/browser.js +58 -0
  29. package/dist/index.d.ts +29 -0
  30. package/dist/index.js +76 -0
  31. package/dist/server/blockchain/CertificateToken.d.ts +48 -0
  32. package/dist/server/blockchain/CertificateToken.js +386 -0
  33. package/dist/server/blockchain/NFTMinter.d.ts +41 -0
  34. package/dist/server/blockchain/NFTMinter.js +323 -0
  35. package/dist/server/blockchain/TokenQuerier.d.ts +31 -0
  36. package/dist/server/blockchain/TokenQuerier.js +259 -0
  37. package/dist/server/blockchain/TokenVerifier.d.ts +20 -0
  38. package/dist/server/blockchain/TokenVerifier.js +395 -0
  39. package/dist/server/blockchain/WalletAnalyzer.d.ts +81 -0
  40. package/dist/server/blockchain/WalletAnalyzer.js +356 -0
  41. package/dist/server/blockchain/WalletFormatter.d.ts +39 -0
  42. package/dist/server/blockchain/WalletFormatter.js +196 -0
  43. package/dist/server/blockchain/WalletManager.d.ts +46 -0
  44. package/dist/server/blockchain/WalletManager.js +294 -0
  45. package/dist/server/blockchain/ZipMetadata.d.ts +27 -0
  46. package/dist/server/blockchain/ZipMetadata.js +131 -0
  47. package/dist/server/blockchain/ZipTokenProcessor.d.ts +44 -0
  48. package/dist/server/blockchain/ZipTokenProcessor.js +204 -0
  49. package/dist/server/blockchain/constants.d.ts +102 -0
  50. package/dist/server/blockchain/constants.js +968 -0
  51. package/dist/server/blockchain/index.d.ts +9 -0
  52. package/dist/server/blockchain/index.js +44 -0
  53. package/dist/server/blockchain/test-certificate.d.ts +8 -0
  54. package/dist/server/blockchain/test-certificate.js +100 -0
  55. package/dist/server/blockchain/types.d.ts +69 -0
  56. package/dist/server/blockchain/types.js +51 -0
  57. package/dist/server/platform/server/ZipKitServer.d.ts +105 -0
  58. package/dist/server/platform/server/ZipKitServer.js +437 -0
  59. package/dist/server/platform/servercomponents/ZipKitOTS.d.ts +91 -0
  60. package/dist/server/platform/servercomponents/ZipKitOTS.js +271 -0
  61. package/dist/shared/ZipEntry.d.ts +131 -0
  62. package/dist/shared/ZipEntry.js +686 -0
  63. package/dist/shared/ZipKit.d.ts +249 -0
  64. package/dist/shared/ZipKit.js +789 -0
  65. package/dist/shared/components/CertificateOTS.d.ts +15 -0
  66. package/dist/shared/components/CertificateOTS.js +116 -0
  67. package/dist/shared/components/FileSys.d.ts +2 -0
  68. package/dist/shared/components/FileSys.js +113 -0
  69. package/dist/shared/components/HashAccumulator.d.ts +55 -0
  70. package/dist/shared/components/HashAccumulator.js +100 -0
  71. package/dist/shared/components/Support.d.ts +63 -0
  72. package/dist/shared/components/Support.js +70 -0
  73. package/dist/shared/components/Util.d.ts +21 -0
  74. package/dist/shared/components/Util.js +115 -0
  75. package/dist/shared/components/ZipCrypto.d.ts +3 -0
  76. package/dist/shared/components/ZipCrypto.js +78 -0
  77. package/dist/shared/components/merkleTree.d.ts +66 -0
  78. package/dist/shared/components/merkleTree.js +136 -0
  79. package/dist/shared/constants/Errors.d.ts +53 -0
  80. package/dist/shared/constants/Errors.js +69 -0
  81. package/dist/shared/constants/Headers.d.ts +167 -0
  82. package/dist/shared/constants/Headers.js +191 -0
  83. package/dist/shared/types/index.d.ts +21 -0
  84. package/dist/shared/types/index.js +3 -0
  85. package/dist/shared/types.d.ts +33 -0
  86. package/dist/shared/types.js +8 -0
  87. package/dist/shared/version.d.ts +4 -0
  88. package/dist/shared/version.js +7 -0
  89. package/dist/types/index.d.ts +21 -0
  90. package/dist/types/index.js +3 -0
  91. package/examples/unzip-token.ts +488 -0
  92. package/examples/zip-token.ts +604 -0
  93. package/package.json +117 -0
  94. package/src/browser/CertificateGeneratorBrowser.ts +498 -0
  95. package/src/browser/TokenVerifierBrowser.ts +344 -0
  96. package/src/browser/ZipKitBrowser.ts +242 -0
  97. package/src/browser/ZipKitStampBrowser.ts +9 -0
  98. package/src/browser-index.ts +36 -0
  99. package/src/index.ts +48 -0
  100. package/src/server/blockchain/CertificateToken.ts +444 -0
  101. package/src/server/blockchain/NFTMinter.ts +357 -0
  102. package/src/server/blockchain/TokenQuerier.ts +287 -0
  103. package/src/server/blockchain/TokenVerifier.ts +453 -0
  104. package/src/server/blockchain/WalletAnalyzer.ts +397 -0
  105. package/src/server/blockchain/WalletFormatter.ts +206 -0
  106. package/src/server/blockchain/WalletManager.ts +294 -0
  107. package/src/server/blockchain/ZipMetadata.ts +117 -0
  108. package/src/server/blockchain/ZipTokenProcessor.ts +234 -0
  109. package/src/server/blockchain/constants.ts +969 -0
  110. package/src/server/blockchain/index.ts +42 -0
  111. package/src/server/blockchain/test-certificate.ts +137 -0
  112. package/src/server/blockchain/types.ts +134 -0
  113. package/src/server/platform/server/ZipKitServer.ts +459 -0
  114. package/src/server/platform/servercomponents/ZipKitOTS.ts +313 -0
  115. package/src/server/platform/servercomponents/opentimestamps.d.ts +23 -0
  116. package/src/shared/ZipEntry.ts +767 -0
  117. package/src/shared/ZipKit.ts +899 -0
  118. package/src/shared/components/CertificateOTS.ts +132 -0
  119. package/src/shared/components/FileSys.ts +87 -0
  120. package/src/shared/components/HashAccumulator.ts +113 -0
  121. package/src/shared/components/Support.ts +77 -0
  122. package/src/shared/components/Util.ts +113 -0
  123. package/src/shared/components/ZipCrypto.ts +91 -0
  124. package/src/shared/components/merkleTree.ts +162 -0
  125. package/src/shared/constants/Errors.ts +82 -0
  126. package/src/shared/constants/Headers.ts +203 -0
  127. package/src/shared/types/index.ts +25 -0
  128. package/src/shared/types/modules.d.ts +22 -0
  129. package/src/shared/types/opentimestamps.d.ts +23 -0
  130. package/src/shared/types.d.ts +8 -0
  131. package/src/shared/types.ts +43 -0
  132. package/src/shared/version.ts +4 -0
  133. package/src/types/index.ts +25 -0
  134. package/src/types/modules.d.ts +22 -0
  135. package/src/types/opentimestamps.d.ts +23 -0
@@ -0,0 +1,249 @@
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
+ }