neozipkit 0.1.1 → 0.2.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 (115) hide show
  1. package/README.md +52 -105
  2. package/contracts/INTEGRATION.md +338 -0
  3. package/contracts/NETWORKS.md +156 -0
  4. package/contracts/README.md +152 -0
  5. package/{src/server/blockchain → contracts}/constants.ts +5 -22
  6. package/contracts/deploy-bytecode.mjs +94 -0
  7. package/dist/blockchain/ZipKitMinter.d.ts +106 -0
  8. package/dist/blockchain/ZipKitMinter.js +347 -0
  9. package/dist/blockchain/ZipKitNFT.d.ts +3 -0
  10. package/dist/blockchain/ZipKitNFT.js +7 -0
  11. package/dist/blockchain/ZipKitOTS.d.ts +135 -0
  12. package/dist/blockchain/ZipKitOTS.js +564 -0
  13. package/dist/blockchain/ZipKitVerifier.d.ts +69 -0
  14. package/dist/blockchain/ZipKitVerifier.js +289 -0
  15. package/dist/{server/blockchain/WalletAnalyzer.d.ts → blockchain/ZipKitWallet.d.ts} +31 -43
  16. package/dist/{server/blockchain/WalletAnalyzer.js → blockchain/ZipKitWallet.js} +193 -161
  17. package/dist/blockchain/contracts.d.ts +14 -0
  18. package/dist/blockchain/contracts.js +77 -0
  19. package/dist/blockchain/index.d.ts +7 -0
  20. package/dist/blockchain/index.js +50 -0
  21. package/dist/{server/blockchain → blockchain}/types.d.ts +12 -34
  22. package/dist/{server/blockchain → blockchain}/types.js +1 -22
  23. package/dist/browser-index.d.ts +0 -3
  24. package/dist/browser-index.js +4 -5
  25. package/dist/browser.d.ts +0 -3
  26. package/dist/browser.js +4 -5
  27. package/dist/index.d.ts +8 -15
  28. package/dist/index.js +12 -24
  29. package/dist/server/{platform/server/ZipKitServer.d.ts → ZipKitServer.d.ts} +4 -35
  30. package/dist/server/{platform/server/ZipKitServer.js → ZipKitServer.js} +55 -182
  31. package/dist/shared/ZipEntry.js +1 -1
  32. package/dist/shared/ZipKit.d.ts +0 -6
  33. package/dist/shared/ZipKit.js +1 -18
  34. package/dist/shared/types.js +2 -2
  35. package/dist/shared/version.d.ts +2 -4
  36. package/dist/shared/version.js +4 -5
  37. package/package.json +13 -3
  38. package/src/blockchain/README.md +229 -0
  39. package/src/blockchain/ZipKitMinter.ts +470 -0
  40. package/src/blockchain/ZipKitNFT.ts +12 -0
  41. package/src/blockchain/ZipKitOTS.ts +622 -0
  42. package/src/blockchain/ZipKitVerifier.ts +382 -0
  43. package/src/blockchain/ZipKitWallet.ts +338 -0
  44. package/src/blockchain/contracts.ts +88 -0
  45. package/src/blockchain/index.ts +61 -0
  46. package/src/blockchain/types.ts +91 -0
  47. package/src/browser/{TokenVerifierBrowser.ts → TokenVerifierBrowser.ts-remove} +1 -1
  48. package/src/browser-index.ts +3 -3
  49. package/src/index.ts +10 -17
  50. package/src/server/README.md +25 -0
  51. package/src/server/ZipKitServer.ts +305 -0
  52. package/src/shared/ZipEntry.ts +1 -1
  53. package/src/shared/ZipKit.ts +1 -19
  54. package/src/shared/types.ts +3 -3
  55. package/src/shared/version.ts +3 -4
  56. package/src/types/modules.d.ts +11 -1
  57. package/contracts/Lock.sol +0 -34
  58. package/contracts/compile-contract.js +0 -168
  59. package/contracts/deploy/deploy-both-contracts.js +0 -286
  60. package/contracts/deploy/deploy-enhanced-contract.js +0 -197
  61. package/contracts/deploy/deploy-private-contract.js +0 -190
  62. package/contracts/deploy/deploy-public-clean.js +0 -1063
  63. package/contracts/deploy/deploy-public-contract.js +0 -1107
  64. package/contracts/deployment.config.example.js +0 -25
  65. package/contracts/remix-compile.js +0 -222
  66. package/contracts/setup-deployment.js +0 -51
  67. package/contracts/src/ZipFileNFT-DEPRECATED-6field.sol +0 -260
  68. package/contracts/src/ZipFileNFT-DEPRECATED-Enhanced.sol +0 -289
  69. package/dist/browser/CertificateGeneratorBrowser.d.ts +0 -75
  70. package/dist/browser/CertificateGeneratorBrowser.js +0 -433
  71. package/dist/browser/TokenVerifierBrowser.d.ts +0 -76
  72. package/dist/browser/TokenVerifierBrowser.js +0 -299
  73. package/dist/server/blockchain/NFTMinter.d.ts +0 -41
  74. package/dist/server/blockchain/NFTMinter.js +0 -323
  75. package/dist/server/blockchain/TokenQuerier.d.ts +0 -31
  76. package/dist/server/blockchain/TokenQuerier.js +0 -259
  77. package/dist/server/blockchain/TokenVerifier.d.ts +0 -20
  78. package/dist/server/blockchain/TokenVerifier.js +0 -395
  79. package/dist/server/blockchain/WalletFormatter.d.ts +0 -39
  80. package/dist/server/blockchain/WalletFormatter.js +0 -196
  81. package/dist/server/blockchain/WalletManager.d.ts +0 -46
  82. package/dist/server/blockchain/WalletManager.js +0 -294
  83. package/dist/server/blockchain/ZipMetadata.d.ts +0 -27
  84. package/dist/server/blockchain/ZipMetadata.js +0 -131
  85. package/dist/server/blockchain/ZipTokenProcessor.d.ts +0 -44
  86. package/dist/server/blockchain/ZipTokenProcessor.js +0 -204
  87. package/dist/server/blockchain/constants.d.ts +0 -102
  88. package/dist/server/blockchain/constants.js +0 -968
  89. package/dist/server/blockchain/index.d.ts +0 -9
  90. package/dist/server/blockchain/index.js +0 -44
  91. package/dist/server/blockchain/test-certificate.d.ts +0 -8
  92. package/dist/server/blockchain/test-certificate.js +0 -100
  93. package/dist/server/platform/servercomponents/ZipKitOTS.d.ts +0 -91
  94. package/dist/server/platform/servercomponents/ZipKitOTS.js +0 -271
  95. package/examples/unzip-token.ts +0 -488
  96. package/examples/zip-token.ts +0 -604
  97. package/src/server/blockchain/NFTMinter.ts +0 -357
  98. package/src/server/blockchain/TokenQuerier.ts +0 -287
  99. package/src/server/blockchain/TokenVerifier.ts +0 -453
  100. package/src/server/blockchain/WalletAnalyzer.ts +0 -397
  101. package/src/server/blockchain/WalletFormatter.ts +0 -206
  102. package/src/server/blockchain/WalletManager.ts +0 -294
  103. package/src/server/blockchain/ZipMetadata.ts +0 -117
  104. package/src/server/blockchain/ZipTokenProcessor.ts +0 -234
  105. package/src/server/blockchain/index.ts +0 -42
  106. package/src/server/blockchain/test-certificate.ts +0 -137
  107. package/src/server/blockchain/types.ts +0 -134
  108. package/src/server/platform/server/ZipKitServer.ts +0 -459
  109. package/src/server/platform/servercomponents/ZipKitOTS.ts +0 -313
  110. package/src/server/platform/servercomponents/opentimestamps.d.ts +0 -23
  111. /package/contracts/{bytecode.txt → NZIP-NFT-bytecode.txt} +0 -0
  112. /package/dist/{server/blockchain → blockchain}/CertificateToken.d.ts +0 -0
  113. /package/dist/{server/blockchain → blockchain}/CertificateToken.js +0 -0
  114. /package/src/{server/blockchain → blockchain}/CertificateToken.ts +0 -0
  115. /package/src/browser/{CertificateGeneratorBrowser.ts → CertificateGeneratorBrowser.ts-remove} +0 -0
@@ -0,0 +1,382 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * ZipKitVerifier - Handles NFT token verification for ZIP files
5
+ * Verifier API for NZIP-NFT smart contract.
6
+ */
7
+
8
+ import { ethers } from 'ethers';
9
+ import { NZIP_CONTRACT_ABI, CONTRACT_CONFIGS } from './contracts';
10
+ import type { TokenMetadata } from './types';
11
+
12
+ // Network configurations
13
+ const NETWORK_CONFIGS = {
14
+ 'base-sepolia': {
15
+ name: 'Base Sepolia',
16
+ rpcUrl: 'https://sepolia.base.org',
17
+ contractAddress: CONTRACT_CONFIGS[84532].address, // Use real contract address
18
+ explorerUrl: 'https://sepolia.basescan.org',
19
+ chainId: 84532
20
+ },
21
+ 'base-mainnet': {
22
+ name: 'Base Mainnet',
23
+ rpcUrl: 'https://mainnet.base.org',
24
+ contractAddress: CONTRACT_CONFIGS[8453].address, // Use real contract address
25
+ explorerUrl: 'https://basescan.org',
26
+ chainId: 8453
27
+ }
28
+ };
29
+
30
+ export interface VerificationOptions {
31
+ debug?: boolean;
32
+ skipHash?: boolean;
33
+ }
34
+
35
+ export interface VerificationResult {
36
+ success: boolean;
37
+ message: string;
38
+ tokenMetadata?: TokenMetadata;
39
+ verificationDetails?: {
40
+ tokenId: string;
41
+ network: string;
42
+ contractAddress: string;
43
+ merkleRoot: string;
44
+ mintDate: string;
45
+ calculatedMerkleRoot?: string;
46
+ declaredMerkleRoot?: string;
47
+ merkleRootMatch?: boolean;
48
+ onChainValid?: boolean;
49
+ };
50
+ errorDetails?: {
51
+ errorType: 'METADATA_ERROR' | 'MERKLE_ERROR' | 'NETWORK_ERROR' | 'CONTRACT_ERROR';
52
+ networkName?: string;
53
+ rpcUrl?: string;
54
+ contractAddress?: string;
55
+ tokenId?: string;
56
+ merkleRoot?: string;
57
+ };
58
+ }
59
+
60
+ /**
61
+ * Blockchain Token Verifier for ZIP files
62
+ */
63
+ export class ZipKitVerifier {
64
+ private debug: boolean;
65
+
66
+ constructor(options: VerificationOptions = {}) {
67
+ this.debug = options.debug || false;
68
+
69
+ if (this.debug) {
70
+ console.log(`[DEBUG] ZipKitVerifier initialized`);
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Extract and validate token metadata from ZIP
76
+ */
77
+ async extractTokenMetadata(tokenBuffer: Buffer): Promise<{ success: boolean; metadata?: TokenMetadata; error?: string }> {
78
+ try {
79
+ if (this.debug) {
80
+ console.log(`[DEBUG] Extracting token metadata from buffer (${tokenBuffer.length} bytes)`);
81
+ }
82
+
83
+ const tokenData = JSON.parse(tokenBuffer.toString('utf8'));
84
+
85
+ // Validate required fields
86
+ const requiredFields = ['tokenId', 'contractAddress', 'network'];
87
+ for (const field of requiredFields) {
88
+ if (!tokenData[field]) {
89
+ if (this.debug) {
90
+ console.log(`[DEBUG] Missing required field: ${field}`);
91
+ }
92
+ return {
93
+ success: false,
94
+ error: `Missing required field: ${field}`
95
+ };
96
+ }
97
+ }
98
+
99
+ if (this.debug) {
100
+ console.log(`[DEBUG] Token metadata extracted successfully`);
101
+ console.log(`[DEBUG] Token ID: ${tokenData.tokenId}, Network: ${tokenData.network}`);
102
+ }
103
+
104
+ return {
105
+ success: true,
106
+ metadata: tokenData as TokenMetadata
107
+ };
108
+
109
+ } catch (error) {
110
+ const errorMessage = error instanceof Error ? error.message : 'Invalid JSON format';
111
+
112
+ if (this.debug) {
113
+ console.log(`[DEBUG] Failed to parse token metadata: ${errorMessage}`);
114
+ }
115
+
116
+ return {
117
+ success: false,
118
+ error: `Invalid token metadata format: ${errorMessage}`
119
+ };
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Map network name to RPC configuration
125
+ */
126
+ private getNetworkConfig(networkName: string): { success: boolean; config?: any; error?: string } {
127
+ const normalizedName = networkName.toLowerCase();
128
+
129
+ if (this.debug) {
130
+ console.log(`[DEBUG] Looking up network config for: ${normalizedName}`);
131
+ }
132
+
133
+ // Map various network name variations to our configs
134
+ if (normalizedName.includes('sepolia')) {
135
+ return { success: true, config: NETWORK_CONFIGS['base-sepolia'] };
136
+ } else if (normalizedName.includes('base') && !normalizedName.includes('sepolia')) {
137
+ return { success: true, config: NETWORK_CONFIGS['base-mainnet'] };
138
+ }
139
+
140
+ if (this.debug) {
141
+ console.log(`[DEBUG] Unsupported network: ${normalizedName}`);
142
+ }
143
+
144
+ return {
145
+ success: false,
146
+ error: `Unsupported network: ${networkName}`
147
+ };
148
+ }
149
+
150
+ /**
151
+ * Perform merkle root comparison
152
+ */
153
+ private compareMerkleRoots(calculated: string | null, declared: string | null): {
154
+ success: boolean;
155
+ match: boolean;
156
+ calculated?: string;
157
+ declared?: string;
158
+ error?: string;
159
+ } {
160
+ if (this.debug) {
161
+ console.log(`[DEBUG] Comparing merkle roots`);
162
+ console.log(`[DEBUG] Calculated: ${calculated || 'null'}`);
163
+ console.log(`[DEBUG] Declared: ${declared || 'null'}`);
164
+ }
165
+
166
+ if (!calculated) {
167
+ return {
168
+ success: false,
169
+ match: false,
170
+ error: 'Cannot calculate merkle root from archive contents'
171
+ };
172
+ }
173
+
174
+ if (!declared) {
175
+ return {
176
+ success: false,
177
+ match: false,
178
+ calculated,
179
+ error: 'No merkle root found in token metadata'
180
+ };
181
+ }
182
+
183
+ const match = calculated === declared;
184
+
185
+ if (this.debug) {
186
+ console.log(`[DEBUG] Merkle root match: ${match}`);
187
+ }
188
+
189
+ return {
190
+ success: true,
191
+ match,
192
+ calculated,
193
+ declared
194
+ };
195
+ }
196
+
197
+ /**
198
+ * Verify token against blockchain
199
+ */
200
+ async verifyOnChain(
201
+ tokenId: string,
202
+ contractAddress: string,
203
+ networkConfig: any,
204
+ merkleRoot: string
205
+ ): Promise<{ success: boolean; isValid?: boolean; error?: string }> {
206
+ try {
207
+ if (this.debug) {
208
+ console.log(`[DEBUG] Starting on-chain verification`);
209
+ console.log(`[DEBUG] Token ID: ${tokenId}, Contract: ${contractAddress}`);
210
+ console.log(`[DEBUG] Network: ${networkConfig.name}, RPC: ${networkConfig.rpcUrl}`);
211
+ }
212
+
213
+ const provider = new ethers.JsonRpcProvider(networkConfig.rpcUrl);
214
+ const contract = new ethers.Contract(contractAddress, NZIP_CONTRACT_ABI, provider);
215
+
216
+ if (this.debug) {
217
+ console.log(`[DEBUG] Calling contract.verifyZipFile(${tokenId}, ${merkleRoot.substring(0, 10)}...)`);
218
+ }
219
+
220
+ const isValid: boolean = await contract.verifyZipFile(tokenId, merkleRoot);
221
+
222
+ if (this.debug) {
223
+ console.log(`[DEBUG] On-chain verification result: ${isValid}`);
224
+ }
225
+
226
+ return { success: true, isValid };
227
+
228
+ } catch (error) {
229
+ const errorMessage = error instanceof Error ? error.message : 'Network error';
230
+
231
+ if (this.debug) {
232
+ console.log(`[DEBUG] On-chain verification failed: ${errorMessage}`);
233
+ }
234
+
235
+ return {
236
+ success: false,
237
+ error: errorMessage
238
+ };
239
+ }
240
+ }
241
+
242
+ /**
243
+ * Complete verification process
244
+ */
245
+ async verifyToken(
246
+ tokenMetadata: TokenMetadata,
247
+ calculatedMerkleRoot: string | null,
248
+ options: VerificationOptions = {}
249
+ ): Promise<VerificationResult> {
250
+ try {
251
+ if (this.debug) {
252
+ console.log(`[DEBUG] Starting complete token verification`);
253
+ }
254
+
255
+ // Get network configuration
256
+ const networkResult = this.getNetworkConfig(tokenMetadata.network);
257
+ if (!networkResult.success || !networkResult.config) {
258
+ return {
259
+ success: false,
260
+ message: networkResult.error || 'Unknown network error',
261
+ errorDetails: {
262
+ errorType: 'NETWORK_ERROR',
263
+ networkName: tokenMetadata.network
264
+ }
265
+ };
266
+ }
267
+
268
+ const networkConfig = networkResult.config;
269
+ const declaredMerkleRoot = tokenMetadata.merkleRoot;
270
+
271
+ // Compare merkle roots if hash verification is not skipped
272
+ if (!options.skipHash) {
273
+ const merkleComparison = this.compareMerkleRoots(calculatedMerkleRoot, declaredMerkleRoot);
274
+
275
+ if (!merkleComparison.success) {
276
+ return {
277
+ success: false,
278
+ message: merkleComparison.error || 'Merkle root verification failed',
279
+ errorDetails: {
280
+ errorType: 'MERKLE_ERROR',
281
+ merkleRoot: declaredMerkleRoot || 'null'
282
+ }
283
+ };
284
+ }
285
+
286
+ if (!merkleComparison.match) {
287
+ return {
288
+ success: false,
289
+ message: 'Archive integrity verification FAILED - merkle root mismatch',
290
+ errorDetails: {
291
+ errorType: 'MERKLE_ERROR',
292
+ merkleRoot: `calculated: ${merkleComparison.calculated}, declared: ${merkleComparison.declared}`
293
+ }
294
+ };
295
+ }
296
+ }
297
+
298
+ // Perform on-chain verification
299
+ const merkleToVerify = calculatedMerkleRoot;
300
+ if (!merkleToVerify) {
301
+ return {
302
+ success: false,
303
+ message: 'No merkle root available for verification',
304
+ errorDetails: {
305
+ errorType: 'MERKLE_ERROR'
306
+ }
307
+ };
308
+ }
309
+
310
+ const onChainResult = await this.verifyOnChain(
311
+ tokenMetadata.tokenId,
312
+ tokenMetadata.contractAddress,
313
+ networkConfig,
314
+ merkleToVerify
315
+ );
316
+
317
+ if (!onChainResult.success) {
318
+ return {
319
+ success: false,
320
+ message: `Blockchain verification failed: ${onChainResult.error}`,
321
+ errorDetails: {
322
+ errorType: 'CONTRACT_ERROR',
323
+ networkName: tokenMetadata.network,
324
+ rpcUrl: networkConfig.rpcUrl,
325
+ contractAddress: tokenMetadata.contractAddress,
326
+ tokenId: tokenMetadata.tokenId
327
+ }
328
+ };
329
+ }
330
+
331
+ if (!onChainResult.isValid) {
332
+ return {
333
+ success: false,
334
+ message: 'Blockchain verification FAILED - token or merkle root invalid',
335
+ errorDetails: {
336
+ errorType: 'CONTRACT_ERROR',
337
+ tokenId: tokenMetadata.tokenId,
338
+ contractAddress: tokenMetadata.contractAddress,
339
+ merkleRoot: merkleToVerify
340
+ }
341
+ };
342
+ }
343
+
344
+ // Success - create verification details
345
+ const mintDate = tokenMetadata.mintDate ||
346
+ (tokenMetadata.creationTimestamp ? new Date(tokenMetadata.creationTimestamp * 1000).toLocaleString() : '') ||
347
+ '8/01/2025 at 1:00:00 PM'; // fallback
348
+
349
+ return {
350
+ success: true,
351
+ message: 'Archive integrity VERIFIED against blockchain records',
352
+ tokenMetadata,
353
+ verificationDetails: {
354
+ tokenId: tokenMetadata.tokenId,
355
+ network: tokenMetadata.network,
356
+ contractAddress: tokenMetadata.contractAddress,
357
+ merkleRoot: merkleToVerify,
358
+ mintDate,
359
+ calculatedMerkleRoot: calculatedMerkleRoot || undefined,
360
+ declaredMerkleRoot: declaredMerkleRoot || undefined,
361
+ merkleRootMatch: !options.skipHash ? calculatedMerkleRoot === declaredMerkleRoot : undefined,
362
+ onChainValid: true
363
+ }
364
+ };
365
+
366
+ } catch (error) {
367
+ const errorMessage = error instanceof Error ? error.message : 'Unknown verification error';
368
+
369
+ if (this.debug) {
370
+ console.log(`[DEBUG] Verification process failed: ${errorMessage}`);
371
+ }
372
+
373
+ return {
374
+ success: false,
375
+ message: `Tokenization verification failed: ${errorMessage}`,
376
+ errorDetails: {
377
+ errorType: 'METADATA_ERROR'
378
+ }
379
+ };
380
+ }
381
+ }
382
+ }