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,453 @@
1
+ // ======================================
2
+ // TokenVerifier.ts
3
+ // Blockchain token verification utilities for ZIP archives
4
+ // Copyright (c) 2024 NeoWare, Inc. All rights reserved.
5
+ // ======================================
6
+
7
+ import * as fs from 'fs';
8
+ import * as path from 'path';
9
+ import ZipKitServer from '../platform/server/ZipKitServer';
10
+ import ZipEntry from '../../shared/ZipEntry';
11
+ import { NZipTokenInfo } from './types';
12
+ import { TOKENIZED_METADATA } from '../../shared/constants/Headers';
13
+ import { ZipMetadata } from './ZipMetadata';
14
+ import {
15
+ createTokenCertificate,
16
+ saveCertificate,
17
+ TokenInfo,
18
+ BlockchainVerification,
19
+ WalletInfo,
20
+ ZipFileInfo
21
+ } from './CertificateToken';
22
+
23
+ // Network configuration for blockchain queries
24
+ const NETWORK_CONFIG: Record<string, any> = {
25
+ 'Base Sepolia': {
26
+ rpcUrls: [
27
+ 'https://sepolia.base.org',
28
+ 'https://base-sepolia.g.alchemy.com/v2/demo',
29
+ 'https://base-sepolia-rpc.publicnode.com',
30
+ 'https://base-sepolia.blockpi.network/v1/rpc/public'
31
+ ]
32
+ },
33
+ 'Base Mainnet': {
34
+ rpcUrls: [
35
+ 'https://mainnet.base.org',
36
+ 'https://base-mainnet.g.alchemy.com/v2/demo',
37
+ 'https://base-rpc.publicnode.com',
38
+ 'https://base.blockpi.network/v1/rpc/public'
39
+ ]
40
+ }
41
+ };
42
+
43
+ export interface TokenVerificationOptions {
44
+ skipHash?: boolean;
45
+ skipToken?: boolean;
46
+ generateCertificate?: boolean;
47
+ zipFileName?: string;
48
+ }
49
+
50
+ export interface TokenVerificationResult {
51
+ isTokenized: boolean;
52
+ tokenMetadata: NZipTokenInfo | null;
53
+ calculatedMerkleRoot: string | null;
54
+ blockchainMerkleRoot: string | null;
55
+ verificationPassed: boolean;
56
+ certificatePath?: string;
57
+ }
58
+
59
+ /**
60
+ * Checks if the ZIP file contains NFT token metadata and verifies the merkle root
61
+ */
62
+ export async function checkForTokenization(
63
+ zipKit: ZipKitServer,
64
+ options: TokenVerificationOptions = {}
65
+ ): Promise<TokenVerificationResult> {
66
+ const zipEntries = zipKit.getDirectory() as ZipEntry[];
67
+
68
+ // Look for the tokenized metadata file
69
+ const tokenEntry = zipEntries.find(entry => entry.filename === TOKENIZED_METADATA);
70
+
71
+ if (tokenEntry) {
72
+ console.log('\n🔍 Tokenized ZIP detected!');
73
+ console.log('═'.repeat(60));
74
+
75
+ try {
76
+ // Extract the token metadata
77
+ console.log('📄 Reading token metadata...');
78
+ const tokenData = await zipKit.extract(tokenEntry);
79
+
80
+ if (tokenData) {
81
+ const tokenContent = tokenData.toString('utf8');
82
+ const tokenMetadata = JSON.parse(tokenContent);
83
+
84
+ // Validate token metadata structure - only accept full NFT tokens
85
+ if (ZipMetadata.validateTokenInfo(tokenMetadata) && tokenMetadata) {
86
+ console.log('✅ Valid NFT token metadata found');
87
+
88
+ // Display token information
89
+ console.log(ZipMetadata.createTokenSummary(tokenMetadata));
90
+
91
+ // Automatically verify token merkle root unless skipped or hash calculation is disabled
92
+ if (options.skipHash) {
93
+ console.log('\n⏭️ Token verification skipped (--skip-hash prevents merkle root calculation)');
94
+ console.log('💡 Use -H flag to enable hash calculation and token verification');
95
+
96
+ return {
97
+ isTokenized: true,
98
+ tokenMetadata,
99
+ calculatedMerkleRoot: null,
100
+ blockchainMerkleRoot: null,
101
+ verificationPassed: false
102
+ };
103
+ } else if (options.skipToken) {
104
+ console.log('\n⏭️ Token verification skipped (--skip-token flag)');
105
+ console.log('⚠️ WARNING: Archive integrity cannot be verified without token validation');
106
+
107
+ return {
108
+ isTokenized: true,
109
+ tokenMetadata,
110
+ calculatedMerkleRoot: null,
111
+ blockchainMerkleRoot: null,
112
+ verificationPassed: false
113
+ };
114
+ } else {
115
+ console.log('\n🔒 Verifying archive integrity against blockchain...');
116
+ const calculatedMerkleRoot = calculateMerkleRootExcludingToken(zipKit);
117
+
118
+ if (calculatedMerkleRoot && tokenMetadata) {
119
+ // Query blockchain for the actual merkle root (full NFT tokens only)
120
+ console.log('🌐 Querying blockchain for stored merkle root...');
121
+ const blockchainMerkleRoot = await queryBlockchainMerkleRoot(tokenMetadata);
122
+
123
+ if (blockchainMerkleRoot) {
124
+ console.log(`Blockchain Merkle Root: ${blockchainMerkleRoot}`);
125
+ console.log(`Calculated Merkle Root: ${calculatedMerkleRoot}`);
126
+
127
+ if (blockchainMerkleRoot === calculatedMerkleRoot) {
128
+ console.log('✅ BLOCKCHAIN VERIFICATION: PASSED');
129
+ console.log(' Archive contents match the blockchain-recorded merkle root!');
130
+
131
+ // Generate certificate if requested
132
+ let certificatePath: string | undefined;
133
+ if (options.generateCertificate) {
134
+ certificatePath = await generateCertificate(
135
+ tokenMetadata,
136
+ options.zipFileName || 'unknown.zip',
137
+ zipEntries,
138
+ {
139
+ merkleRootMatches: true,
140
+ blockchainMerkleRoot,
141
+ calculatedMerkleRoot,
142
+ verificationStatus: 'PASSED',
143
+ verificationTime: Math.floor(Date.now() / 1000)
144
+ }
145
+ );
146
+ }
147
+
148
+ return {
149
+ isTokenized: true,
150
+ tokenMetadata,
151
+ calculatedMerkleRoot,
152
+ blockchainMerkleRoot,
153
+ verificationPassed: true,
154
+ certificatePath
155
+ };
156
+ } else {
157
+ console.log('❌ BLOCKCHAIN VERIFICATION: FAILED');
158
+ console.log(' WARNING: Archive contents do not match the blockchain record!');
159
+ console.log(' This archive may have been tampered with or corrupted.');
160
+
161
+ // Generate certificate for failed verification if requested
162
+ let certificatePath: string | undefined;
163
+ if (options.generateCertificate) {
164
+ certificatePath = await generateCertificate(
165
+ tokenMetadata,
166
+ options.zipFileName || 'unknown.zip',
167
+ zipEntries,
168
+ {
169
+ merkleRootMatches: false,
170
+ blockchainMerkleRoot,
171
+ calculatedMerkleRoot,
172
+ verificationStatus: 'FAILED',
173
+ verificationTime: Math.floor(Date.now() / 1000)
174
+ }
175
+ );
176
+ }
177
+
178
+ return {
179
+ isTokenized: true,
180
+ tokenMetadata,
181
+ calculatedMerkleRoot,
182
+ blockchainMerkleRoot,
183
+ verificationPassed: false,
184
+ certificatePath
185
+ };
186
+ }
187
+ } else {
188
+ console.log('❌ BLOCKCHAIN VERIFICATION: FAILED');
189
+ console.log(' Could not retrieve merkle root from blockchain');
190
+ console.log(' Token metadata may be invalid or network unreachable');
191
+
192
+ // Handle unavailable blockchain verification
193
+ let certificatePath: string | undefined;
194
+ if (options.generateCertificate && tokenMetadata) {
195
+ certificatePath = await generateCertificate(
196
+ tokenMetadata,
197
+ options.zipFileName || 'unknown.zip',
198
+ zipEntries,
199
+ {
200
+ merkleRootMatches: false,
201
+ blockchainMerkleRoot: "Unavailable",
202
+ calculatedMerkleRoot: zipKit.getMerkleRoot() || 'Unable to calculate',
203
+ verificationStatus: 'UNAVAILABLE',
204
+ verificationTime: Math.floor(Date.now() / 1000)
205
+ }
206
+ );
207
+ }
208
+
209
+ return {
210
+ isTokenized: true,
211
+ tokenMetadata,
212
+ calculatedMerkleRoot,
213
+ blockchainMerkleRoot: null,
214
+ verificationPassed: false,
215
+ certificatePath
216
+ };
217
+ }
218
+ }
219
+ }
220
+ } else {
221
+ console.log('❌ Invalid token metadata structure');
222
+ console.log(' This archive contains invalid or unsupported token metadata');
223
+ console.log(' Only full NFT tokens with blockchain verification are supported');
224
+
225
+ return {
226
+ isTokenized: false,
227
+ tokenMetadata: null,
228
+ calculatedMerkleRoot: null,
229
+ blockchainMerkleRoot: null,
230
+ verificationPassed: false
231
+ };
232
+ }
233
+ } else {
234
+ console.log('❌ Could not read token metadata');
235
+
236
+ return {
237
+ isTokenized: false,
238
+ tokenMetadata: null,
239
+ calculatedMerkleRoot: null,
240
+ blockchainMerkleRoot: null,
241
+ verificationPassed: false
242
+ };
243
+ }
244
+ } catch (error) {
245
+ console.error('❌ Error reading token metadata:', error);
246
+
247
+ return {
248
+ isTokenized: false,
249
+ tokenMetadata: null,
250
+ calculatedMerkleRoot: null,
251
+ blockchainMerkleRoot: null,
252
+ verificationPassed: false
253
+ };
254
+ }
255
+
256
+ console.log('═'.repeat(60));
257
+ } else {
258
+ console.log('\n📦 Standard ZIP archive (not tokenized)');
259
+ if (options.skipHash) {
260
+ console.log('⏭️ SHA-256 hash validation disabled');
261
+ }
262
+
263
+ return {
264
+ isTokenized: false,
265
+ tokenMetadata: null,
266
+ calculatedMerkleRoot: null,
267
+ blockchainMerkleRoot: null,
268
+ verificationPassed: false
269
+ };
270
+ }
271
+
272
+ // Fallback return for cases where calculatedMerkleRoot is null
273
+ return {
274
+ isTokenized: true,
275
+ tokenMetadata: null,
276
+ calculatedMerkleRoot: null,
277
+ blockchainMerkleRoot: null,
278
+ verificationPassed: false
279
+ };
280
+ }
281
+
282
+ /**
283
+ * Queries the blockchain to get the actual merkle root stored in the smart contract
284
+ */
285
+ async function queryBlockchainMerkleRoot(tokenMetadata: NZipTokenInfo): Promise<string | null> {
286
+ try {
287
+ const { ethers } = await import('ethers');
288
+
289
+ const networkConfig = NETWORK_CONFIG[tokenMetadata.network];
290
+ if (!networkConfig) {
291
+ console.log(`⚠️ Unsupported network: ${tokenMetadata.network}`);
292
+ return null;
293
+ }
294
+
295
+ // Try multiple RPC endpoints
296
+ for (const rpcUrl of networkConfig.rpcUrls) {
297
+ try {
298
+ console.log(` Trying RPC: ${rpcUrl}`);
299
+ const provider = new ethers.JsonRpcProvider(rpcUrl);
300
+
301
+ // Test connection
302
+ await provider.getBlockNumber();
303
+
304
+ // Use hardcoded ABI for NZIP NFT Contract v2.0
305
+ const CONTRACT_ABI = [
306
+ {
307
+ "inputs": [{"internalType": "uint256", "name": "tokenId", "type": "uint256"}],
308
+ "name": "getZipFileInfo",
309
+ "outputs": [
310
+ {
311
+ "components": [
312
+ {"internalType": "string", "name": "fileName", "type": "string"},
313
+ {"internalType": "string", "name": "merkleRootHash", "type": "string"},
314
+ {"internalType": "string", "name": "ipfsHash", "type": "string"},
315
+ {"internalType": "address", "name": "creator", "type": "address"},
316
+ {"internalType": "uint256", "name": "creationTimestamp", "type": "uint256"},
317
+ {"internalType": "uint256", "name": "tokenizationTime", "type": "uint256"},
318
+ {"internalType": "uint256", "name": "blockNumber", "type": "uint256"}
319
+ ],
320
+ "internalType": "struct ZipFileNFT.ZipFileInfo",
321
+ "name": "",
322
+ "type": "tuple"
323
+ }
324
+ ],
325
+ "stateMutability": "view",
326
+ "type": "function"
327
+ }
328
+ ];
329
+
330
+ // Create contract instance
331
+ const contract = new ethers.Contract(tokenMetadata.contractAddress, CONTRACT_ABI, provider);
332
+
333
+ // Call getZipFileInfo to get the blockchain-stored merkle root
334
+ const zipInfo = await contract.getZipFileInfo(tokenMetadata.tokenId);
335
+ console.log(` ✅ Connected to blockchain successfully`);
336
+
337
+ return zipInfo.merkleRootHash;
338
+
339
+ } catch (error) {
340
+ const errorMessage = error instanceof Error ? error.message : String(error);
341
+ console.log(` ❌ RPC failed: ${errorMessage.substring(0, 80)}...`);
342
+ continue;
343
+ }
344
+ }
345
+
346
+ console.log(`⚠️ All RPC endpoints failed for network: ${tokenMetadata.network}`);
347
+ return null;
348
+
349
+ } catch (error) {
350
+ const errorMessage = error instanceof Error ? error.message : String(error);
351
+ console.log(`⚠️ Blockchain query error: ${errorMessage}`);
352
+ return null;
353
+ }
354
+ }
355
+
356
+ /**
357
+ * Calculates the merkle root excluding the token metadata file
358
+ * This represents the original content that was tokenized
359
+ */
360
+ function calculateMerkleRootExcludingToken(zipKit: ZipKitServer): string | null {
361
+ try {
362
+ // Get all entries except the token file
363
+ const zipEntries = zipKit.getDirectory() as ZipEntry[];
364
+ const contentEntries = zipEntries.filter(entry => entry.filename !== TOKENIZED_METADATA);
365
+
366
+ if (contentEntries.length === 0) {
367
+ console.log('⚠️ No content files found for merkle root calculation');
368
+ return null;
369
+ }
370
+
371
+ console.log(`📊 Calculating merkle root for ${contentEntries.length} content files...`);
372
+
373
+ // For each content entry, ensure we have SHA-256 hash calculated
374
+ for (const entry of contentEntries) {
375
+ if (!entry.sha256) {
376
+ // Extract the file to calculate its SHA-256 hash
377
+ try {
378
+ const fileData = zipKit.extract(entry);
379
+ // The extraction process should calculate and set the SHA-256 hash
380
+ console.log(` Calculated SHA-256 for: ${entry.filename}`);
381
+ } catch (error) {
382
+ console.log(` ⚠️ Could not process: ${entry.filename}`);
383
+ return null; // Cannot calculate merkle root without all hashes
384
+ }
385
+ }
386
+ }
387
+
388
+ // Now calculate the merkle root from the content files
389
+ const merkleRoot = zipKit.getMerkleRoot();
390
+
391
+ return merkleRoot;
392
+ } catch (error) {
393
+ console.error('Error calculating merkle root:', error);
394
+ return null;
395
+ }
396
+ }
397
+
398
+ /**
399
+ * Generates a token certificate
400
+ */
401
+ async function generateCertificate(
402
+ tokenMetadata: NZipTokenInfo,
403
+ zipFileName: string,
404
+ zipEntries: ZipEntry[],
405
+ blockchainVerification: BlockchainVerification
406
+ ): Promise<string> {
407
+ console.log('\n📜 Generating Token Certificate...');
408
+
409
+ try {
410
+ // Prepare token information
411
+ const tokenInfo: TokenInfo = {
412
+ tokenId: tokenMetadata.tokenId,
413
+ contractAddress: tokenMetadata.contractAddress,
414
+ network: tokenMetadata.network,
415
+ transactionHash: tokenMetadata.transactionHash
416
+ };
417
+
418
+ // Prepare file information from ZIP entries
419
+ const zipFiles: ZipFileInfo[] = [];
420
+ for (const entry of zipEntries) {
421
+ // Skip the token file itself and directories
422
+ if (entry.filename !== TOKENIZED_METADATA &&
423
+ !entry.isDirectory &&
424
+ entry.sha256) {
425
+ zipFiles.push({
426
+ filename: entry.filename,
427
+ size: entry.uncompressedSize,
428
+ date: entry.toFormattedUTCDateString(),
429
+ hash: entry.sha256
430
+ });
431
+ }
432
+ }
433
+
434
+ // Generate the certificate
435
+ const certificateHTML = createTokenCertificate(
436
+ tokenInfo,
437
+ zipFileName,
438
+ blockchainVerification,
439
+ undefined, // walletInfo
440
+ zipFiles
441
+ );
442
+
443
+ // Save the certificate
444
+ const certPath = saveCertificate(zipFileName, certificateHTML);
445
+ console.log(`✅ Certificate generated: ${certPath}`);
446
+
447
+ return certPath;
448
+
449
+ } catch (error) {
450
+ console.error('❌ Failed to generate certificate:', error);
451
+ throw error;
452
+ }
453
+ }