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,395 @@
1
+ "use strict";
2
+ // ======================================
3
+ // TokenVerifier.ts
4
+ // Blockchain token verification utilities for ZIP archives
5
+ // Copyright (c) 2024 NeoWare, Inc. All rights reserved.
6
+ // ======================================
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.checkForTokenization = checkForTokenization;
42
+ const Headers_1 = require("../../shared/constants/Headers");
43
+ const ZipMetadata_1 = require("./ZipMetadata");
44
+ const CertificateToken_1 = require("./CertificateToken");
45
+ // Network configuration for blockchain queries
46
+ const NETWORK_CONFIG = {
47
+ 'Base Sepolia': {
48
+ rpcUrls: [
49
+ 'https://sepolia.base.org',
50
+ 'https://base-sepolia.g.alchemy.com/v2/demo',
51
+ 'https://base-sepolia-rpc.publicnode.com',
52
+ 'https://base-sepolia.blockpi.network/v1/rpc/public'
53
+ ]
54
+ },
55
+ 'Base Mainnet': {
56
+ rpcUrls: [
57
+ 'https://mainnet.base.org',
58
+ 'https://base-mainnet.g.alchemy.com/v2/demo',
59
+ 'https://base-rpc.publicnode.com',
60
+ 'https://base.blockpi.network/v1/rpc/public'
61
+ ]
62
+ }
63
+ };
64
+ /**
65
+ * Checks if the ZIP file contains NFT token metadata and verifies the merkle root
66
+ */
67
+ async function checkForTokenization(zipKit, options = {}) {
68
+ const zipEntries = zipKit.getDirectory();
69
+ // Look for the tokenized metadata file
70
+ const tokenEntry = zipEntries.find(entry => entry.filename === Headers_1.TOKENIZED_METADATA);
71
+ if (tokenEntry) {
72
+ console.log('\nšŸ” Tokenized ZIP detected!');
73
+ console.log('═'.repeat(60));
74
+ try {
75
+ // Extract the token metadata
76
+ console.log('šŸ“„ Reading token metadata...');
77
+ const tokenData = await zipKit.extract(tokenEntry);
78
+ if (tokenData) {
79
+ const tokenContent = tokenData.toString('utf8');
80
+ const tokenMetadata = JSON.parse(tokenContent);
81
+ // Validate token metadata structure - only accept full NFT tokens
82
+ if (ZipMetadata_1.ZipMetadata.validateTokenInfo(tokenMetadata) && tokenMetadata) {
83
+ console.log('āœ… Valid NFT token metadata found');
84
+ // Display token information
85
+ console.log(ZipMetadata_1.ZipMetadata.createTokenSummary(tokenMetadata));
86
+ // Automatically verify token merkle root unless skipped or hash calculation is disabled
87
+ if (options.skipHash) {
88
+ console.log('\nā­ļø Token verification skipped (--skip-hash prevents merkle root calculation)');
89
+ console.log('šŸ’” Use -H flag to enable hash calculation and token verification');
90
+ return {
91
+ isTokenized: true,
92
+ tokenMetadata,
93
+ calculatedMerkleRoot: null,
94
+ blockchainMerkleRoot: null,
95
+ verificationPassed: false
96
+ };
97
+ }
98
+ else if (options.skipToken) {
99
+ console.log('\nā­ļø Token verification skipped (--skip-token flag)');
100
+ console.log('āš ļø WARNING: Archive integrity cannot be verified without token validation');
101
+ return {
102
+ isTokenized: true,
103
+ tokenMetadata,
104
+ calculatedMerkleRoot: null,
105
+ blockchainMerkleRoot: null,
106
+ verificationPassed: false
107
+ };
108
+ }
109
+ else {
110
+ console.log('\nšŸ”’ Verifying archive integrity against blockchain...');
111
+ const calculatedMerkleRoot = calculateMerkleRootExcludingToken(zipKit);
112
+ if (calculatedMerkleRoot && tokenMetadata) {
113
+ // Query blockchain for the actual merkle root (full NFT tokens only)
114
+ console.log('🌐 Querying blockchain for stored merkle root...');
115
+ const blockchainMerkleRoot = await queryBlockchainMerkleRoot(tokenMetadata);
116
+ if (blockchainMerkleRoot) {
117
+ console.log(`Blockchain Merkle Root: ${blockchainMerkleRoot}`);
118
+ console.log(`Calculated Merkle Root: ${calculatedMerkleRoot}`);
119
+ if (blockchainMerkleRoot === calculatedMerkleRoot) {
120
+ console.log('āœ… BLOCKCHAIN VERIFICATION: PASSED');
121
+ console.log(' Archive contents match the blockchain-recorded merkle root!');
122
+ // Generate certificate if requested
123
+ let certificatePath;
124
+ if (options.generateCertificate) {
125
+ certificatePath = await generateCertificate(tokenMetadata, options.zipFileName || 'unknown.zip', zipEntries, {
126
+ merkleRootMatches: true,
127
+ blockchainMerkleRoot,
128
+ calculatedMerkleRoot,
129
+ verificationStatus: 'PASSED',
130
+ verificationTime: Math.floor(Date.now() / 1000)
131
+ });
132
+ }
133
+ return {
134
+ isTokenized: true,
135
+ tokenMetadata,
136
+ calculatedMerkleRoot,
137
+ blockchainMerkleRoot,
138
+ verificationPassed: true,
139
+ certificatePath
140
+ };
141
+ }
142
+ else {
143
+ console.log('āŒ BLOCKCHAIN VERIFICATION: FAILED');
144
+ console.log(' WARNING: Archive contents do not match the blockchain record!');
145
+ console.log(' This archive may have been tampered with or corrupted.');
146
+ // Generate certificate for failed verification if requested
147
+ let certificatePath;
148
+ if (options.generateCertificate) {
149
+ certificatePath = await generateCertificate(tokenMetadata, options.zipFileName || 'unknown.zip', zipEntries, {
150
+ merkleRootMatches: false,
151
+ blockchainMerkleRoot,
152
+ calculatedMerkleRoot,
153
+ verificationStatus: 'FAILED',
154
+ verificationTime: Math.floor(Date.now() / 1000)
155
+ });
156
+ }
157
+ return {
158
+ isTokenized: true,
159
+ tokenMetadata,
160
+ calculatedMerkleRoot,
161
+ blockchainMerkleRoot,
162
+ verificationPassed: false,
163
+ certificatePath
164
+ };
165
+ }
166
+ }
167
+ else {
168
+ console.log('āŒ BLOCKCHAIN VERIFICATION: FAILED');
169
+ console.log(' Could not retrieve merkle root from blockchain');
170
+ console.log(' Token metadata may be invalid or network unreachable');
171
+ // Handle unavailable blockchain verification
172
+ let certificatePath;
173
+ if (options.generateCertificate && tokenMetadata) {
174
+ certificatePath = await generateCertificate(tokenMetadata, options.zipFileName || 'unknown.zip', zipEntries, {
175
+ merkleRootMatches: false,
176
+ blockchainMerkleRoot: "Unavailable",
177
+ calculatedMerkleRoot: zipKit.getMerkleRoot() || 'Unable to calculate',
178
+ verificationStatus: 'UNAVAILABLE',
179
+ verificationTime: Math.floor(Date.now() / 1000)
180
+ });
181
+ }
182
+ return {
183
+ isTokenized: true,
184
+ tokenMetadata,
185
+ calculatedMerkleRoot,
186
+ blockchainMerkleRoot: null,
187
+ verificationPassed: false,
188
+ certificatePath
189
+ };
190
+ }
191
+ }
192
+ }
193
+ }
194
+ else {
195
+ console.log('āŒ Invalid token metadata structure');
196
+ console.log(' This archive contains invalid or unsupported token metadata');
197
+ console.log(' Only full NFT tokens with blockchain verification are supported');
198
+ return {
199
+ isTokenized: false,
200
+ tokenMetadata: null,
201
+ calculatedMerkleRoot: null,
202
+ blockchainMerkleRoot: null,
203
+ verificationPassed: false
204
+ };
205
+ }
206
+ }
207
+ else {
208
+ console.log('āŒ Could not read token metadata');
209
+ return {
210
+ isTokenized: false,
211
+ tokenMetadata: null,
212
+ calculatedMerkleRoot: null,
213
+ blockchainMerkleRoot: null,
214
+ verificationPassed: false
215
+ };
216
+ }
217
+ }
218
+ catch (error) {
219
+ console.error('āŒ Error reading token metadata:', error);
220
+ return {
221
+ isTokenized: false,
222
+ tokenMetadata: null,
223
+ calculatedMerkleRoot: null,
224
+ blockchainMerkleRoot: null,
225
+ verificationPassed: false
226
+ };
227
+ }
228
+ console.log('═'.repeat(60));
229
+ }
230
+ else {
231
+ console.log('\nšŸ“¦ Standard ZIP archive (not tokenized)');
232
+ if (options.skipHash) {
233
+ console.log('ā­ļø SHA-256 hash validation disabled');
234
+ }
235
+ return {
236
+ isTokenized: false,
237
+ tokenMetadata: null,
238
+ calculatedMerkleRoot: null,
239
+ blockchainMerkleRoot: null,
240
+ verificationPassed: false
241
+ };
242
+ }
243
+ // Fallback return for cases where calculatedMerkleRoot is null
244
+ return {
245
+ isTokenized: true,
246
+ tokenMetadata: null,
247
+ calculatedMerkleRoot: null,
248
+ blockchainMerkleRoot: null,
249
+ verificationPassed: false
250
+ };
251
+ }
252
+ /**
253
+ * Queries the blockchain to get the actual merkle root stored in the smart contract
254
+ */
255
+ async function queryBlockchainMerkleRoot(tokenMetadata) {
256
+ try {
257
+ const { ethers } = await Promise.resolve().then(() => __importStar(require('ethers')));
258
+ const networkConfig = NETWORK_CONFIG[tokenMetadata.network];
259
+ if (!networkConfig) {
260
+ console.log(`āš ļø Unsupported network: ${tokenMetadata.network}`);
261
+ return null;
262
+ }
263
+ // Try multiple RPC endpoints
264
+ for (const rpcUrl of networkConfig.rpcUrls) {
265
+ try {
266
+ console.log(` Trying RPC: ${rpcUrl}`);
267
+ const provider = new ethers.JsonRpcProvider(rpcUrl);
268
+ // Test connection
269
+ await provider.getBlockNumber();
270
+ // Use hardcoded ABI for NZIP NFT Contract v2.0
271
+ const CONTRACT_ABI = [
272
+ {
273
+ "inputs": [{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }],
274
+ "name": "getZipFileInfo",
275
+ "outputs": [
276
+ {
277
+ "components": [
278
+ { "internalType": "string", "name": "fileName", "type": "string" },
279
+ { "internalType": "string", "name": "merkleRootHash", "type": "string" },
280
+ { "internalType": "string", "name": "ipfsHash", "type": "string" },
281
+ { "internalType": "address", "name": "creator", "type": "address" },
282
+ { "internalType": "uint256", "name": "creationTimestamp", "type": "uint256" },
283
+ { "internalType": "uint256", "name": "tokenizationTime", "type": "uint256" },
284
+ { "internalType": "uint256", "name": "blockNumber", "type": "uint256" }
285
+ ],
286
+ "internalType": "struct ZipFileNFT.ZipFileInfo",
287
+ "name": "",
288
+ "type": "tuple"
289
+ }
290
+ ],
291
+ "stateMutability": "view",
292
+ "type": "function"
293
+ }
294
+ ];
295
+ // Create contract instance
296
+ const contract = new ethers.Contract(tokenMetadata.contractAddress, CONTRACT_ABI, provider);
297
+ // Call getZipFileInfo to get the blockchain-stored merkle root
298
+ const zipInfo = await contract.getZipFileInfo(tokenMetadata.tokenId);
299
+ console.log(` āœ… Connected to blockchain successfully`);
300
+ return zipInfo.merkleRootHash;
301
+ }
302
+ catch (error) {
303
+ const errorMessage = error instanceof Error ? error.message : String(error);
304
+ console.log(` āŒ RPC failed: ${errorMessage.substring(0, 80)}...`);
305
+ continue;
306
+ }
307
+ }
308
+ console.log(`āš ļø All RPC endpoints failed for network: ${tokenMetadata.network}`);
309
+ return null;
310
+ }
311
+ catch (error) {
312
+ const errorMessage = error instanceof Error ? error.message : String(error);
313
+ console.log(`āš ļø Blockchain query error: ${errorMessage}`);
314
+ return null;
315
+ }
316
+ }
317
+ /**
318
+ * Calculates the merkle root excluding the token metadata file
319
+ * This represents the original content that was tokenized
320
+ */
321
+ function calculateMerkleRootExcludingToken(zipKit) {
322
+ try {
323
+ // Get all entries except the token file
324
+ const zipEntries = zipKit.getDirectory();
325
+ const contentEntries = zipEntries.filter(entry => entry.filename !== Headers_1.TOKENIZED_METADATA);
326
+ if (contentEntries.length === 0) {
327
+ console.log('āš ļø No content files found for merkle root calculation');
328
+ return null;
329
+ }
330
+ console.log(`šŸ“Š Calculating merkle root for ${contentEntries.length} content files...`);
331
+ // For each content entry, ensure we have SHA-256 hash calculated
332
+ for (const entry of contentEntries) {
333
+ if (!entry.sha256) {
334
+ // Extract the file to calculate its SHA-256 hash
335
+ try {
336
+ const fileData = zipKit.extract(entry);
337
+ // The extraction process should calculate and set the SHA-256 hash
338
+ console.log(` Calculated SHA-256 for: ${entry.filename}`);
339
+ }
340
+ catch (error) {
341
+ console.log(` āš ļø Could not process: ${entry.filename}`);
342
+ return null; // Cannot calculate merkle root without all hashes
343
+ }
344
+ }
345
+ }
346
+ // Now calculate the merkle root from the content files
347
+ const merkleRoot = zipKit.getMerkleRoot();
348
+ return merkleRoot;
349
+ }
350
+ catch (error) {
351
+ console.error('Error calculating merkle root:', error);
352
+ return null;
353
+ }
354
+ }
355
+ /**
356
+ * Generates a token certificate
357
+ */
358
+ async function generateCertificate(tokenMetadata, zipFileName, zipEntries, blockchainVerification) {
359
+ console.log('\nšŸ“œ Generating Token Certificate...');
360
+ try {
361
+ // Prepare token information
362
+ const tokenInfo = {
363
+ tokenId: tokenMetadata.tokenId,
364
+ contractAddress: tokenMetadata.contractAddress,
365
+ network: tokenMetadata.network,
366
+ transactionHash: tokenMetadata.transactionHash
367
+ };
368
+ // Prepare file information from ZIP entries
369
+ const zipFiles = [];
370
+ for (const entry of zipEntries) {
371
+ // Skip the token file itself and directories
372
+ if (entry.filename !== Headers_1.TOKENIZED_METADATA &&
373
+ !entry.isDirectory &&
374
+ entry.sha256) {
375
+ zipFiles.push({
376
+ filename: entry.filename,
377
+ size: entry.uncompressedSize,
378
+ date: entry.toFormattedUTCDateString(),
379
+ hash: entry.sha256
380
+ });
381
+ }
382
+ }
383
+ // Generate the certificate
384
+ const certificateHTML = (0, CertificateToken_1.createTokenCertificate)(tokenInfo, zipFileName, blockchainVerification, undefined, // walletInfo
385
+ zipFiles);
386
+ // Save the certificate
387
+ const certPath = (0, CertificateToken_1.saveCertificate)(zipFileName, certificateHTML);
388
+ console.log(`āœ… Certificate generated: ${certPath}`);
389
+ return certPath;
390
+ }
391
+ catch (error) {
392
+ console.error('āŒ Failed to generate certificate:', error);
393
+ throw error;
394
+ }
395
+ }
@@ -0,0 +1,81 @@
1
+ import { ethers } from 'ethers';
2
+ export interface TokenInfo {
3
+ address: string;
4
+ name: string;
5
+ symbol: string;
6
+ balance: string;
7
+ decimals?: number;
8
+ type: 'ERC20' | 'ERC721' | 'NZIP';
9
+ }
10
+ export interface NZipTokenDetails {
11
+ tokenId: string;
12
+ merkleRootHash: string;
13
+ fileName: string;
14
+ timestamp: number;
15
+ tokenURI?: string;
16
+ creator: string;
17
+ creationTimestamp: number;
18
+ tokenizationTime: number;
19
+ ipfsHash?: string;
20
+ }
21
+ export interface WalletBasicInfo {
22
+ ethBalance: string;
23
+ transactionCount: number;
24
+ networkName: string;
25
+ chainId: bigint;
26
+ latestBlock: number;
27
+ }
28
+ export interface TokenScanResult {
29
+ foundTokens: number[];
30
+ searchMethod: 'recent-events' | 'iteration' | 'common-ids' | 'none';
31
+ }
32
+ export interface CommonTokenConfig {
33
+ address: string;
34
+ name: string;
35
+ symbol: string;
36
+ type: 'ERC20' | 'ERC721';
37
+ }
38
+ export declare class WalletAnalyzer {
39
+ private provider;
40
+ constructor(provider: ethers.JsonRpcProvider);
41
+ /**
42
+ * Get basic wallet information (balance, transaction count, etc.)
43
+ */
44
+ getWalletBasics(address: string): Promise<WalletBasicInfo>;
45
+ /**
46
+ * Scan for NZIP tokens owned by an address using multiple methods
47
+ */
48
+ scanForNZipTokens(contractAddress: string, ownerAddress: string): Promise<TokenScanResult>;
49
+ /**
50
+ * Get detailed information about NZIP tokens
51
+ */
52
+ getNZipTokenDetails(contractAddress: string, tokenIds: number[]): Promise<NZipTokenDetails[]>;
53
+ /**
54
+ * Get contract information (name, symbol, total supply)
55
+ */
56
+ getContractInfo(contractAddress: string): Promise<{
57
+ name: string;
58
+ symbol: string;
59
+ totalSupply: string;
60
+ } | null>;
61
+ /**
62
+ * Check ERC-20 token balances for common tokens
63
+ */
64
+ checkERC20Tokens(ownerAddress: string, tokenConfigs: CommonTokenConfig[]): Promise<TokenInfo[]>;
65
+ /**
66
+ * Check NFT collection balances
67
+ */
68
+ checkNFTCollections(ownerAddress: string, nftConfigs: CommonTokenConfig[]): Promise<TokenInfo[]>;
69
+ /**
70
+ * Detect NZIP contract from deployment file
71
+ */
72
+ static detectNZipContract(): string | undefined;
73
+ /**
74
+ * Get common token configurations for a network
75
+ */
76
+ static getCommonTokens(network: string): CommonTokenConfig[];
77
+ /**
78
+ * Get common NFT configurations for a network
79
+ */
80
+ static getCommonNFTs(network: string): CommonTokenConfig[];
81
+ }