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,289 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.19;
3
+
4
+ import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
5
+ import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
6
+ import "@openzeppelin/contracts/access/Ownable.sol";
7
+
8
+ /**
9
+ * @title ZipFileNFT Enhanced
10
+ * @dev Enhanced NFT contract for tokenizing ZIP files with comprehensive blockchain metadata
11
+ * Version 2.0 - Includes block number, block hash, and reorganized timestamp structure
12
+ * Allows multiple tokens for the same content by using timestamp as a differentiator
13
+ */
14
+ contract ZipFileNFTEnhanced is ERC721, ERC721URIStorage, Ownable {
15
+
16
+ // Counter for token IDs
17
+ uint256 private _tokenIdCounter;
18
+
19
+ // Struct to store ZIP file information - Enhanced Version 2.0
20
+ struct ZipFileInfo {
21
+ // File identification
22
+ string fileName; // Original ZIP file name
23
+ string merkleRootHash; // Merkle root hash of the ZIP contents
24
+ string ipfsHash; // IPFS hash where the ZIP file is stored
25
+ address creator; // Address that created/minted this token
26
+
27
+ // Timestamps (grouped together)
28
+ uint256 creationTimestamp; // Timestamp when the ZIP was created (user-provided)
29
+ uint256 tokenizationTime; // Timestamp when the NFT was minted (block.timestamp)
30
+
31
+ // Blockchain metadata (grouped with timestamps)
32
+ uint256 blockNumber; // Block number when the token was minted
33
+ bytes32 blockHash; // Block hash when the token was minted
34
+ }
35
+
36
+ // Mapping from token ID to ZIP file information
37
+ mapping(uint256 => ZipFileInfo) public zipFileInfo;
38
+
39
+ // Mapping from composite key (merkleRoot + timestamp) to token ID
40
+ // This prevents duplicate tokens with same content AND same timestamp
41
+ mapping(bytes32 => uint256) public compositeKeyToTokenId;
42
+
43
+ // Events - Enhanced with blockchain metadata
44
+ event ZipFileTokenized(
45
+ uint256 indexed tokenId,
46
+ address indexed creator,
47
+ string fileName,
48
+ string merkleRootHash,
49
+ uint256 creationTimestamp,
50
+ string ipfsHash,
51
+ uint256 tokenizationTime,
52
+ uint256 blockNumber,
53
+ bytes32 blockHash
54
+ );
55
+
56
+ constructor() ERC721("NeoZip File NFT Enhanced", "NZIP") Ownable(msg.sender) {}
57
+
58
+ /**
59
+ * @dev Generate composite key from merkle root and timestamp
60
+ * @param merkleRootHash The merkle root hash
61
+ * @param creationTimestamp The creation timestamp
62
+ * @return The composite key
63
+ */
64
+ function _generateCompositeKey(
65
+ string memory merkleRootHash,
66
+ uint256 creationTimestamp
67
+ ) internal pure returns (bytes32) {
68
+ return keccak256(abi.encodePacked(merkleRootHash, creationTimestamp));
69
+ }
70
+
71
+ /**
72
+ * @dev Mint a new NFT representing a ZIP file with timestamp
73
+ * @param to Address to mint the token to
74
+ * @param fileName Original name of the ZIP file
75
+ * @param merkleRootHash Merkle root hash of the ZIP contents
76
+ * @param creationTimestamp Timestamp when the ZIP was created
77
+ * @param ipfsHash IPFS hash where the ZIP file is stored
78
+ * @param tokenURI Metadata URI for the token
79
+ * @return tokenId The ID of the newly minted token
80
+ */
81
+ function mintZipFileToken(
82
+ address to,
83
+ string memory fileName,
84
+ string memory merkleRootHash,
85
+ uint256 creationTimestamp,
86
+ string memory ipfsHash,
87
+ string memory tokenURI
88
+ ) public returns (uint256) {
89
+ require(bytes(merkleRootHash).length > 0, "Merkle root hash cannot be empty");
90
+ require(bytes(fileName).length > 0, "File name cannot be empty");
91
+ require(creationTimestamp > 0, "Creation timestamp must be greater than 0");
92
+
93
+ // Generate composite key
94
+ bytes32 compositeKey = _generateCompositeKey(merkleRootHash, creationTimestamp);
95
+
96
+ // Check that this specific combination hasn't been tokenized before
97
+ require(compositeKeyToTokenId[compositeKey] == 0, "ZIP file with this timestamp already tokenized");
98
+
99
+ uint256 tokenId = _tokenIdCounter;
100
+ _tokenIdCounter++;
101
+
102
+ // Mint the token
103
+ _safeMint(to, tokenId);
104
+ _setTokenURI(tokenId, tokenURI);
105
+
106
+ // Store ZIP file information with enhanced blockchain metadata
107
+ zipFileInfo[tokenId] = ZipFileInfo({
108
+ fileName: fileName,
109
+ merkleRootHash: merkleRootHash,
110
+ ipfsHash: ipfsHash,
111
+ creator: msg.sender,
112
+ creationTimestamp: creationTimestamp,
113
+ tokenizationTime: block.timestamp,
114
+ blockNumber: block.number,
115
+ blockHash: blockhash(block.number)
116
+ });
117
+
118
+ // Map composite key to token ID for duplicate prevention
119
+ compositeKeyToTokenId[compositeKey] = tokenId;
120
+
121
+ // Emit enhanced event with blockchain metadata
122
+ emit ZipFileTokenized(
123
+ tokenId,
124
+ to,
125
+ fileName,
126
+ merkleRootHash,
127
+ creationTimestamp,
128
+ ipfsHash,
129
+ block.timestamp,
130
+ block.number,
131
+ blockhash(block.number)
132
+ );
133
+
134
+ return tokenId;
135
+ }
136
+
137
+ /**
138
+ * @dev Public minting function with timestamp
139
+ * @param fileName Name of the ZIP file
140
+ * @param merkleRootHash Merkle root hash of the ZIP contents
141
+ * @param creationTimestamp Timestamp when the ZIP was created
142
+ * @param ipfsHash IPFS hash where the ZIP file is stored
143
+ * @param tokenURI Metadata URI for the token
144
+ * @return tokenId The ID of the newly minted token
145
+ */
146
+ function publicMintZipFile(
147
+ string memory fileName,
148
+ string memory merkleRootHash,
149
+ uint256 creationTimestamp,
150
+ string memory ipfsHash,
151
+ string memory tokenURI
152
+ ) public returns (uint256) {
153
+ return mintZipFileToken(
154
+ msg.sender,
155
+ fileName,
156
+ merkleRootHash,
157
+ creationTimestamp,
158
+ ipfsHash,
159
+ tokenURI
160
+ );
161
+ }
162
+
163
+ /**
164
+ * @dev Verify a ZIP file against its token
165
+ * @param tokenId Token ID to verify
166
+ * @param providedMerkleRoot Merkle root to verify against
167
+ * @return isValid Whether the provided hash matches the stored one
168
+ */
169
+ function verifyZipFile(
170
+ uint256 tokenId,
171
+ string memory providedMerkleRoot
172
+ ) public view returns (bool isValid) {
173
+ require(_ownerOf(tokenId) != address(0), "Token does not exist");
174
+
175
+ ZipFileInfo memory info = zipFileInfo[tokenId];
176
+
177
+ isValid = keccak256(abi.encodePacked(info.merkleRootHash)) == keccak256(abi.encodePacked(providedMerkleRoot));
178
+
179
+ return isValid;
180
+ }
181
+
182
+ /**
183
+ * @dev Get information about a ZIP file token - Enhanced version
184
+ * @param tokenId Token ID to query
185
+ * @return info Complete ZipFileInfo struct with blockchain metadata
186
+ */
187
+ function getZipFileInfo(uint256 tokenId) public view returns (ZipFileInfo memory info) {
188
+ require(_ownerOf(tokenId) != address(0), "Token does not exist");
189
+ return zipFileInfo[tokenId];
190
+ }
191
+
192
+ /**
193
+ * @dev Check if a ZIP file with specific timestamp has been tokenized
194
+ * @param merkleRootHash Merkle root to check
195
+ * @param creationTimestamp Creation timestamp to check
196
+ * @return exists Whether a token exists for this combination
197
+ * @return tokenId The token ID if it exists (0 if not)
198
+ */
199
+ function isZipFileTokenized(
200
+ string memory merkleRootHash,
201
+ uint256 creationTimestamp
202
+ ) public view returns (bool exists, uint256 tokenId) {
203
+ bytes32 compositeKey = _generateCompositeKey(merkleRootHash, creationTimestamp);
204
+ tokenId = compositeKeyToTokenId[compositeKey];
205
+ exists = (tokenId != 0);
206
+ return (exists, tokenId);
207
+ }
208
+
209
+ /**
210
+ * @dev Get all tokens for a specific merkle root (regardless of timestamp)
211
+ * @param merkleRootHash Merkle root to search for
212
+ * @return tokenIds Array of token IDs that match this merkle root
213
+ */
214
+ function getTokensByMerkleRoot(string memory merkleRootHash) public view returns (uint256[] memory tokenIds) {
215
+ uint256 totalSupply = _tokenIdCounter;
216
+ uint256[] memory tempTokenIds = new uint256[](totalSupply);
217
+ uint256 count = 0;
218
+
219
+ for (uint256 i = 0; i < totalSupply; i++) {
220
+ if (_ownerOf(i) != address(0)) {
221
+ ZipFileInfo memory info = zipFileInfo[i];
222
+ if (keccak256(abi.encodePacked(info.merkleRootHash)) == keccak256(abi.encodePacked(merkleRootHash))) {
223
+ tempTokenIds[count] = i;
224
+ count++;
225
+ }
226
+ }
227
+ }
228
+
229
+ // Create properly sized array
230
+ tokenIds = new uint256[](count);
231
+ for (uint256 i = 0; i < count; i++) {
232
+ tokenIds[i] = tempTokenIds[i];
233
+ }
234
+
235
+ return tokenIds;
236
+ }
237
+
238
+ /**
239
+ * @dev Get the current token ID counter
240
+ * @return The next token ID that will be minted
241
+ */
242
+ function getCurrentTokenId() public view returns (uint256) {
243
+ return _tokenIdCounter;
244
+ }
245
+
246
+ /**
247
+ * @dev Get total number of tokens minted
248
+ * @return Total supply of tokens
249
+ */
250
+ function totalSupply() public view returns (uint256) {
251
+ return _tokenIdCounter;
252
+ }
253
+
254
+ /**
255
+ * @dev Update IPFS hash for a token (only by token owner)
256
+ * @param tokenId Token ID to update
257
+ * @param ipfsHash New IPFS hash
258
+ */
259
+ function updateIpfsHash(uint256 tokenId, string memory ipfsHash) public {
260
+ require(ownerOf(tokenId) == msg.sender, "Only token owner can update IPFS hash");
261
+ zipFileInfo[tokenId].ipfsHash = ipfsHash;
262
+ }
263
+
264
+ /**
265
+ * @dev Get blockchain metadata for a token
266
+ * @param tokenId Token ID to query
267
+ * @return blockNumber Block number when token was minted
268
+ * @return blockHash Block hash when token was minted
269
+ * @return tokenizationTime Exact timestamp when token was minted
270
+ */
271
+ function getBlockchainMetadata(uint256 tokenId) public view returns (
272
+ uint256 blockNumber,
273
+ bytes32 blockHash,
274
+ uint256 tokenizationTime
275
+ ) {
276
+ require(_ownerOf(tokenId) != address(0), "Token does not exist");
277
+ ZipFileInfo memory info = zipFileInfo[tokenId];
278
+ return (info.blockNumber, info.blockHash, info.tokenizationTime);
279
+ }
280
+
281
+ // Override required by Solidity
282
+ function tokenURI(uint256 tokenId) public view override(ERC721, ERC721URIStorage) returns (string memory) {
283
+ return super.tokenURI(tokenId);
284
+ }
285
+
286
+ function supportsInterface(bytes4 interfaceId) public view override(ERC721, ERC721URIStorage) returns (bool) {
287
+ return super.supportsInterface(interfaceId);
288
+ }
289
+ }
@@ -0,0 +1,75 @@
1
+ import { ZipEntry } from '../shared/ZipKit';
2
+ import { BlockchainVerification } from './TokenVerifierBrowser';
3
+ export interface TokenInfo {
4
+ tokenId: string;
5
+ contractAddress: string;
6
+ network: string;
7
+ transactionHash: string;
8
+ wallet?: string;
9
+ timestamp?: number;
10
+ note?: string;
11
+ }
12
+ export interface WalletInfo {
13
+ address: string;
14
+ network: string;
15
+ balance?: string;
16
+ ensName?: string;
17
+ }
18
+ export interface ZipFileInfo {
19
+ filename: string;
20
+ size: number;
21
+ date: string;
22
+ hash: string;
23
+ }
24
+ /**
25
+ * Browser-compatible certificate generator class
26
+ */
27
+ export declare class CertificateGeneratorBrowser {
28
+ /**
29
+ * Generates a certificate HTML document for tokenized ZIP files
30
+ */
31
+ createTokenCertificate(tokenInfo: TokenInfo, zipFile: string, blockchainVerification: BlockchainVerification, walletInfo?: WalletInfo, zipFiles?: ZipFileInfo[], options?: {
32
+ narrow?: boolean;
33
+ includeQR?: boolean;
34
+ }): string;
35
+ /**
36
+ * Saves a certificate as a downloadable file (browser-compatible)
37
+ */
38
+ saveCertificate(fileName: string, certificateHTML: string): void;
39
+ /**
40
+ * Generate token information section
41
+ */
42
+ private generateTokenSection;
43
+ /**
44
+ * Generate blockchain verification section
45
+ */
46
+ private generateVerificationSection;
47
+ /**
48
+ * Generate wallet information section
49
+ */
50
+ private generateWalletSection;
51
+ /**
52
+ * Generate files table
53
+ */
54
+ private generateFilesTable;
55
+ /**
56
+ * Get the HTML template for certificates
57
+ */
58
+ private getCertificateTemplate;
59
+ /**
60
+ * Prepares file information from ZIP entries for certificate generation
61
+ */
62
+ prepareZipFileInfo(zipEntries: ZipEntry[]): ZipFileInfo[];
63
+ /**
64
+ * Formats the date from a ZIP entry
65
+ */
66
+ private formatEntryDate;
67
+ }
68
+ /**
69
+ * Creates a new CertificateGeneratorBrowser instance
70
+ */
71
+ export declare function createCertificateGenerator(): CertificateGeneratorBrowser;
72
+ /**
73
+ * Convenience function to generate a certificate
74
+ */
75
+ export declare function generateTokenCertificate(tokenInfo: TokenInfo, zipFile: string, blockchainVerification: BlockchainVerification, walletInfo?: WalletInfo, zipFiles?: ZipFileInfo[]): string;