neozipkit 0.2.1 → 0.3.0
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.
- package/LICENSE +22 -0
- package/README.md +410 -186
- package/contracts/ABI.txt +889 -0
- package/contracts/Bytecode.txt +1 -0
- package/contracts/COMPILATION_NOTES.md +59 -0
- package/contracts/QUICK_DEPLOY.md +286 -0
- package/contracts/README.md +235 -131
- package/contracts/VERIFICATION.md +308 -0
- package/contracts/deploy-interactive.js +448 -0
- package/contracts/deployment-arbitrum-sepolia.json +12 -0
- package/contracts/deployment-arbitrum.json +12 -0
- package/contracts/deployment-eth-sepolia.json +12 -0
- package/contracts/hardhat.config.js +114 -0
- package/contracts/package.json +20 -0
- package/contracts/scripts/compile-and-extract.js +119 -0
- package/contracts/scripts/verify-contract.js +223 -0
- package/contracts/src/{NZIP-NFT-Private.sol → NZIP-NFT-v2.0.sol} +66 -151
- package/contracts/src/NZIP-NFT.sol +9 -15
- package/dist/blockchain/browser/TokenVerifierBrowser.d.ts +67 -0
- package/dist/blockchain/browser/TokenVerifierBrowser.d.ts.map +1 -0
- package/dist/blockchain/browser/TokenVerifierBrowser.js +313 -0
- package/dist/blockchain/browser/TokenVerifierBrowser.js.map +1 -0
- package/dist/blockchain/browser/WalletManagerBrowser.d.ts +98 -0
- package/dist/blockchain/browser/WalletManagerBrowser.d.ts.map +1 -0
- package/dist/blockchain/browser/WalletManagerBrowser.js +434 -0
- package/dist/blockchain/browser/WalletManagerBrowser.js.map +1 -0
- package/dist/blockchain/browser/ZipkitMinterBrowser.d.ts +58 -0
- package/dist/blockchain/browser/ZipkitMinterBrowser.d.ts.map +1 -0
- package/dist/blockchain/browser/ZipkitMinterBrowser.js +317 -0
- package/dist/blockchain/browser/ZipkitMinterBrowser.js.map +1 -0
- package/dist/blockchain/browser/index.d.ts +11 -0
- package/dist/blockchain/browser/index.d.ts.map +1 -0
- package/dist/blockchain/browser/index.js +16 -0
- package/dist/blockchain/browser/index.js.map +1 -0
- package/dist/blockchain/core/WalletManager.d.ts +124 -0
- package/dist/blockchain/core/WalletManager.d.ts.map +1 -0
- package/dist/blockchain/{ZipKitWallet.js → core/WalletManager.js} +157 -177
- package/dist/blockchain/core/WalletManager.js.map +1 -0
- package/dist/blockchain/{ZipKitMinter.d.ts → core/ZipkitMinter.d.ts} +46 -11
- package/dist/blockchain/core/ZipkitMinter.d.ts.map +1 -0
- package/dist/blockchain/core/ZipkitMinter.js +548 -0
- package/dist/blockchain/core/ZipkitMinter.js.map +1 -0
- package/dist/blockchain/{ZipKitOTS.d.ts → core/ZipkitOTS.d.ts} +6 -15
- package/dist/blockchain/core/ZipkitOTS.d.ts.map +1 -0
- package/dist/blockchain/{ZipKitOTS.js → core/ZipkitOTS.js} +26 -84
- package/dist/blockchain/core/ZipkitOTS.js.map +1 -0
- package/dist/blockchain/core/ZipkitVerifier.d.ts +177 -0
- package/dist/blockchain/core/ZipkitVerifier.d.ts.map +1 -0
- package/dist/blockchain/core/ZipkitVerifier.js +632 -0
- package/dist/blockchain/core/ZipkitVerifier.js.map +1 -0
- package/dist/blockchain/core/contracts.d.ts +83 -0
- package/dist/blockchain/core/contracts.d.ts.map +1 -0
- package/dist/blockchain/core/contracts.js +341 -0
- package/dist/blockchain/core/contracts.js.map +1 -0
- package/dist/blockchain/core/index.d.ts +12 -0
- package/dist/blockchain/core/index.d.ts.map +1 -0
- package/dist/blockchain/core/index.js +59 -0
- package/dist/blockchain/core/index.js.map +1 -0
- package/dist/blockchain/index.d.ts +11 -7
- package/dist/blockchain/index.d.ts.map +1 -0
- package/dist/blockchain/index.js +18 -34
- package/dist/blockchain/index.js.map +1 -0
- package/dist/blockchain/node/WalletManagerNode.d.ts +47 -0
- package/dist/blockchain/node/WalletManagerNode.d.ts.map +1 -0
- package/dist/blockchain/node/WalletManagerNode.js +203 -0
- package/dist/blockchain/node/WalletManagerNode.js.map +1 -0
- package/dist/blockchain/node/index.d.ts +12 -0
- package/dist/blockchain/node/index.d.ts.map +1 -0
- package/dist/blockchain/node/index.js +24 -0
- package/dist/blockchain/node/index.js.map +1 -0
- package/dist/browser/ZipkitBrowser.d.ts +27 -0
- package/dist/browser/ZipkitBrowser.d.ts.map +1 -0
- package/dist/browser/{ZipKitBrowser.js → ZipkitBrowser.js} +96 -43
- package/dist/browser/ZipkitBrowser.js.map +1 -0
- package/dist/browser/index.d.ts +12 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +42 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser-esm/index.d.ts +12 -0
- package/dist/browser-esm/index.js +59559 -0
- package/dist/browser-esm/index.js.map +7 -0
- package/dist/browser-umd/index.d.ts +12 -0
- package/dist/browser-umd/index.js +59576 -0
- package/dist/browser-umd/index.js.map +7 -0
- package/dist/browser-umd/index.min.js +63 -0
- package/dist/browser.d.ts +8 -14
- package/dist/browser.js +13 -28
- package/dist/core/ZipCompress.d.ts +99 -0
- package/dist/core/ZipCompress.d.ts.map +1 -0
- package/dist/core/ZipCompress.js +309 -0
- package/dist/core/ZipCompress.js.map +1 -0
- package/dist/core/ZipDecompress.d.ts +58 -0
- package/dist/core/ZipDecompress.d.ts.map +1 -0
- package/dist/core/ZipDecompress.js +172 -0
- package/dist/core/ZipDecompress.js.map +1 -0
- package/dist/{shared → core}/ZipEntry.d.ts +8 -1
- package/dist/core/ZipEntry.d.ts.map +1 -0
- package/dist/{shared → core}/ZipEntry.js +225 -82
- package/dist/core/ZipEntry.js.map +1 -0
- package/dist/core/Zipkit.d.ts +315 -0
- package/dist/core/Zipkit.d.ts.map +1 -0
- package/dist/core/Zipkit.js +647 -0
- package/dist/core/Zipkit.js.map +1 -0
- package/dist/core/components/HashCalculator.d.ts +138 -0
- package/dist/core/components/HashCalculator.d.ts.map +1 -0
- package/dist/core/components/HashCalculator.js +360 -0
- package/dist/core/components/HashCalculator.js.map +1 -0
- package/dist/core/components/Logger.d.ts +73 -0
- package/dist/core/components/Logger.d.ts.map +1 -0
- package/dist/core/components/Logger.js +156 -0
- package/dist/core/components/Logger.js.map +1 -0
- package/dist/core/components/ProgressTracker.d.ts +43 -0
- package/dist/core/components/ProgressTracker.d.ts.map +1 -0
- package/dist/core/components/ProgressTracker.js +112 -0
- package/dist/core/components/ProgressTracker.js.map +1 -0
- package/dist/{shared → core}/components/Support.d.ts +1 -0
- package/dist/core/components/Support.d.ts.map +1 -0
- package/dist/{shared → core}/components/Support.js +1 -0
- package/dist/core/components/Support.js.map +1 -0
- package/dist/{shared → core}/components/Util.d.ts +7 -2
- package/dist/core/components/Util.d.ts.map +1 -0
- package/dist/{shared → core}/components/Util.js +14 -34
- package/dist/core/components/Util.js.map +1 -0
- package/dist/{shared → core}/constants/Errors.d.ts +1 -2
- package/dist/core/constants/Errors.d.ts.map +1 -0
- package/dist/{shared → core}/constants/Errors.js +1 -3
- package/dist/core/constants/Errors.js.map +1 -0
- package/dist/{shared → core}/constants/Headers.d.ts +3 -0
- package/dist/core/constants/Headers.d.ts.map +1 -0
- package/dist/{shared → core}/constants/Headers.js +20 -17
- package/dist/core/constants/Headers.js.map +1 -0
- package/dist/core/encryption/Manager.d.ts +58 -0
- package/dist/core/encryption/Manager.d.ts.map +1 -0
- package/dist/core/encryption/Manager.js +121 -0
- package/dist/core/encryption/Manager.js.map +1 -0
- package/dist/core/encryption/ZipCrypto.d.ts +172 -0
- package/dist/core/encryption/ZipCrypto.d.ts.map +1 -0
- package/dist/core/encryption/ZipCrypto.js +554 -0
- package/dist/core/encryption/ZipCrypto.js.map +1 -0
- package/dist/core/encryption/index.d.ts +9 -0
- package/dist/core/encryption/index.d.ts.map +1 -0
- package/dist/core/encryption/index.js +17 -0
- package/dist/core/encryption/index.js.map +1 -0
- package/dist/core/encryption/types.d.ts +29 -0
- package/dist/core/encryption/types.d.ts.map +1 -0
- package/dist/core/encryption/types.js +12 -0
- package/dist/core/encryption/types.js.map +1 -0
- package/dist/core/index.d.ts +24 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +57 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/version.d.ts +5 -0
- package/dist/core/version.d.ts.map +1 -0
- package/dist/core/version.js +31 -0
- package/dist/core/version.js.map +1 -0
- package/dist/index.d.ts +8 -18
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -35
- package/dist/index.js.map +1 -0
- package/dist/node/ZipCompressNode.d.ts +123 -0
- package/dist/node/ZipCompressNode.d.ts.map +1 -0
- package/dist/node/ZipCompressNode.js +576 -0
- package/dist/node/ZipCompressNode.js.map +1 -0
- package/dist/node/ZipDecompressNode.d.ts +120 -0
- package/dist/node/ZipDecompressNode.d.ts.map +1 -0
- package/dist/node/ZipDecompressNode.js +461 -0
- package/dist/node/ZipDecompressNode.js.map +1 -0
- package/dist/node/ZipkitNode.d.ts +406 -0
- package/dist/node/ZipkitNode.d.ts.map +1 -0
- package/dist/node/ZipkitNode.js +1305 -0
- package/dist/node/ZipkitNode.js.map +1 -0
- package/dist/node/index.d.ts +26 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +65 -0
- package/dist/node/index.js.map +1 -0
- package/dist/types/index.d.ts +59 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +36 -1
- package/dist/types/index.js.map +1 -0
- package/examples/README.md +269 -0
- package/examples/blockchain-tokenize.ts +354 -0
- package/examples/create-zip.ts +172 -0
- package/examples/extract-zip.ts +158 -0
- package/examples/list-zip.ts +161 -0
- package/examples/test-files/data.json +116 -0
- package/examples/test-files/document.md +80 -0
- package/examples/test-files/document.txt +2 -0
- package/examples/test-files/file1.txt +48 -0
- package/examples/test-files/file2.txt +80 -0
- package/examples/tsconfig.json +44 -0
- package/examples/unzip-token.ts +491 -0
- package/examples/verify-tokenized-zip.ts +305 -0
- package/examples/zip-token.ts +604 -0
- package/package.json +108 -24
- package/src/blockchain/README.md +59 -66
- package/src/{browser/TokenVerifierBrowser.ts-remove → blockchain/browser/TokenVerifierBrowser.ts} +125 -79
- package/src/blockchain/browser/WalletManagerBrowser.ts +486 -0
- package/src/blockchain/browser/ZipkitMinterBrowser.ts +400 -0
- package/src/blockchain/browser/index.ts +13 -0
- package/src/blockchain/{ZipKitWallet.ts → core/WalletManager.ts} +241 -143
- package/src/blockchain/core/ZipkitMinter.ts +716 -0
- package/src/blockchain/{ZipKitOTS.ts → core/ZipkitOTS.ts} +28 -62
- package/src/blockchain/core/ZipkitVerifier.ts +853 -0
- package/src/blockchain/core/contracts.ts +370 -0
- package/src/blockchain/core/index.ts +71 -0
- package/src/blockchain/index.ts +21 -55
- package/src/blockchain/node/WalletManagerNode.ts +171 -0
- package/src/blockchain/node/index.ts +40 -0
- package/src/browser/{ZipKitBrowser.ts → ZipkitBrowser.ts} +104 -41
- package/src/browser/index.esm.ts +37 -0
- package/src/browser/index.ts +25 -0
- package/src/core/ZipCompress.ts +398 -0
- package/src/core/ZipDecompress.ts +212 -0
- package/src/{shared → core}/ZipEntry.ts +240 -90
- package/src/core/Zipkit.ts +794 -0
- package/src/core/components/HashCalculator.ts +384 -0
- package/src/core/components/Logger.ts +180 -0
- package/src/core/components/ProgressTracker.ts +134 -0
- package/src/{shared → core}/components/Util.ts +12 -34
- package/src/{shared → core}/constants/Errors.ts +0 -4
- package/src/{shared → core}/constants/Headers.ts +19 -17
- package/src/core/encryption/Manager.ts +137 -0
- package/src/core/encryption/ZipCrypto.ts +650 -0
- package/src/core/encryption/index.ts +15 -0
- package/src/core/encryption/types.ts +33 -0
- package/src/core/index.ts +34 -0
- package/src/core/version.ts +33 -0
- package/src/index.ts +54 -25
- package/src/node/ZipCompressNode.ts +632 -0
- package/src/node/ZipDecompressNode.ts +508 -0
- package/src/node/ZipkitNode.ts +1559 -0
- package/src/node/index.ts +69 -0
- package/src/types/index.ts +131 -1
- package/src/types/modules.d.ts +1 -11
- package/src/types/opentimestamps.d.ts +1 -23
- package/contracts/INTEGRATION.md +0 -338
- package/contracts/NETWORKS.md +0 -156
- package/contracts/NZIP-NFT-bytecode.txt +0 -1
- package/contracts/constants.ts +0 -952
- package/contracts/deploy-bytecode.mjs +0 -94
- package/dist/blockchain/CertificateToken.d.ts +0 -48
- package/dist/blockchain/CertificateToken.js +0 -386
- package/dist/blockchain/ZipKitMinter.js +0 -347
- package/dist/blockchain/ZipKitNFT.d.ts +0 -3
- package/dist/blockchain/ZipKitNFT.js +0 -7
- package/dist/blockchain/ZipKitVerifier.d.ts +0 -69
- package/dist/blockchain/ZipKitVerifier.js +0 -289
- package/dist/blockchain/ZipKitWallet.d.ts +0 -69
- package/dist/blockchain/contracts.d.ts +0 -14
- package/dist/blockchain/contracts.js +0 -77
- package/dist/blockchain/types.d.ts +0 -47
- package/dist/blockchain/types.js +0 -30
- package/dist/browser/ZipKitBrowser.d.ts +0 -18
- package/dist/browser/ZipKitStampBrowser.d.ts +0 -2
- package/dist/browser/ZipKitStampBrowser.js +0 -12
- package/dist/browser-index.d.ts +0 -18
- package/dist/browser-index.js +0 -57
- package/dist/server/ZipKitServer.d.ts +0 -74
- package/dist/server/ZipKitServer.js +0 -310
- package/dist/shared/ZipKit.d.ts +0 -243
- package/dist/shared/ZipKit.js +0 -772
- package/dist/shared/components/CertificateOTS.d.ts +0 -15
- package/dist/shared/components/CertificateOTS.js +0 -116
- package/dist/shared/components/FileSys.d.ts +0 -2
- package/dist/shared/components/FileSys.js +0 -113
- package/dist/shared/components/HashAccumulator.d.ts +0 -55
- package/dist/shared/components/HashAccumulator.js +0 -100
- package/dist/shared/components/ZipCrypto.d.ts +0 -3
- package/dist/shared/components/ZipCrypto.js +0 -78
- package/dist/shared/components/merkleTree.d.ts +0 -66
- package/dist/shared/components/merkleTree.js +0 -136
- package/dist/shared/types/index.d.ts +0 -21
- package/dist/shared/types/index.js +0 -3
- package/dist/shared/types.d.ts +0 -33
- package/dist/shared/types.js +0 -8
- package/dist/shared/version.d.ts +0 -2
- package/dist/shared/version.js +0 -6
- package/src/blockchain/CertificateToken.ts +0 -444
- package/src/blockchain/ZipKitMinter.ts +0 -470
- package/src/blockchain/ZipKitNFT.ts +0 -12
- package/src/blockchain/ZipKitVerifier.ts +0 -382
- package/src/blockchain/contracts.ts +0 -88
- package/src/blockchain/types.ts +0 -91
- package/src/browser/CertificateGeneratorBrowser.ts-remove +0 -498
- package/src/browser/ZipKitStampBrowser.ts +0 -9
- package/src/browser-index.ts +0 -36
- package/src/server/README.md +0 -25
- package/src/server/ZipKitServer.ts +0 -305
- package/src/shared/ZipKit.ts +0 -881
- package/src/shared/components/CertificateOTS.ts +0 -132
- package/src/shared/components/FileSys.ts +0 -87
- package/src/shared/components/HashAccumulator.ts +0 -113
- package/src/shared/components/ZipCrypto.ts +0 -91
- package/src/shared/components/merkleTree.ts +0 -162
- package/src/shared/types/index.ts +0 -25
- package/src/shared/types/modules.d.ts +0 -22
- package/src/shared/types/opentimestamps.d.ts +0 -23
- package/src/shared/types.d.ts +0 -8
- package/src/shared/types.ts +0 -43
- package/src/shared/version.ts +0 -3
- /package/src/{shared → core}/components/Support.ts +0 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Verify Tokenized ZIP Example
|
|
5
|
+
*
|
|
6
|
+
* Demonstrates verifying a tokenized ZIP file on the blockchain.
|
|
7
|
+
* This example:
|
|
8
|
+
* 1. Loads a tokenized ZIP file
|
|
9
|
+
* 2. Extracts token metadata from META-INF/NZIP.TOKEN
|
|
10
|
+
* 3. Calculates merkle root from ZIP contents
|
|
11
|
+
* 4. Verifies the token on the blockchain
|
|
12
|
+
* 5. Displays verification results
|
|
13
|
+
*
|
|
14
|
+
* SECURITY WARNING:
|
|
15
|
+
* - This example only reads blockchain data (no private keys required)
|
|
16
|
+
* - However, if you're verifying your own tokenized files, ensure:
|
|
17
|
+
* - Private keys used for minting are stored securely
|
|
18
|
+
* - Never commit private keys to version control
|
|
19
|
+
* - Use testnet for development and testing
|
|
20
|
+
*
|
|
21
|
+
* See SECURITY.md for complete security guidelines.
|
|
22
|
+
*
|
|
23
|
+
* Usage:
|
|
24
|
+
* ts-node examples/verify-tokenized-zip.ts [path-to-tokenized.zip]
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { ZipkitNode } from '../src/node';
|
|
28
|
+
import { ZipkitVerifier } from '../src/blockchain/core/ZipkitVerifier';
|
|
29
|
+
import type { TokenMetadata } from '../src/types';
|
|
30
|
+
import { TOKENIZED_METADATA } from '../src/core/constants/Headers';
|
|
31
|
+
import * as fs from 'fs';
|
|
32
|
+
import * as path from 'path';
|
|
33
|
+
|
|
34
|
+
async function main() {
|
|
35
|
+
console.log('Verify Tokenized ZIP Example\n');
|
|
36
|
+
|
|
37
|
+
// Get ZIP file path from command line argument or use default
|
|
38
|
+
const zipPath = process.argv[2] || path.join(__dirname, 'output', 'tokenized.zip');
|
|
39
|
+
|
|
40
|
+
if (!fs.existsSync(zipPath)) {
|
|
41
|
+
console.error(`❌ Error: ZIP file not found: ${zipPath}`);
|
|
42
|
+
console.error('\nUsage:');
|
|
43
|
+
console.error(' ts-node examples/verify-tokenized-zip.ts [path-to-tokenized.zip]');
|
|
44
|
+
console.error('\nExample:');
|
|
45
|
+
console.error(' ts-node examples/verify-tokenized-zip.ts examples/output/tokenized.zip');
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
console.log(`📦 ZIP file: ${zipPath}`);
|
|
50
|
+
const zipStats = fs.statSync(zipPath);
|
|
51
|
+
console.log(` Size: ${formatBytes(zipStats.size)}\n`);
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
// Step 1: Load ZIP file
|
|
55
|
+
console.log('Step 1: Loading ZIP file...');
|
|
56
|
+
const zip = new ZipkitNode();
|
|
57
|
+
await zip.loadZipFile(zipPath);
|
|
58
|
+
console.log('✅ ZIP file loaded successfully\n');
|
|
59
|
+
|
|
60
|
+
// Step 2: Extract token metadata
|
|
61
|
+
console.log('Step 2: Extracting token metadata...');
|
|
62
|
+
const entries = zip.getDirectory();
|
|
63
|
+
const tokenEntry = entries.find(entry => entry.filename === TOKENIZED_METADATA);
|
|
64
|
+
|
|
65
|
+
if (!tokenEntry) {
|
|
66
|
+
console.error('❌ Error: Token metadata not found in ZIP file');
|
|
67
|
+
console.error(` Expected file: ${TOKENIZED_METADATA}`);
|
|
68
|
+
console.error('\n💡 This ZIP file does not appear to be tokenized.');
|
|
69
|
+
console.error(' Use blockchain-tokenize.ts to create a tokenized ZIP file.');
|
|
70
|
+
await zip.closeFile();
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Extract token metadata content to temporary file
|
|
75
|
+
const tempTokenFile = path.join(__dirname, 'output', '.token-metadata-temp.json');
|
|
76
|
+
const tempTokenDir = path.dirname(tempTokenFile);
|
|
77
|
+
if (!fs.existsSync(tempTokenDir)) {
|
|
78
|
+
fs.mkdirSync(tempTokenDir, { recursive: true });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let tokenMetadata: TokenMetadata;
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
await zip.extractToFile(tokenEntry, tempTokenFile);
|
|
85
|
+
const tokenContent = fs.readFileSync(tempTokenFile, 'utf8');
|
|
86
|
+
|
|
87
|
+
// Clean up temp file
|
|
88
|
+
fs.unlinkSync(tempTokenFile);
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
tokenMetadata = JSON.parse(tokenContent);
|
|
92
|
+
} catch (parseError) {
|
|
93
|
+
console.error('❌ Error: Invalid token metadata format');
|
|
94
|
+
console.error(' Token metadata must be valid JSON');
|
|
95
|
+
await zip.closeFile();
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
} catch (extractError) {
|
|
99
|
+
console.error('❌ Error: Could not extract token metadata');
|
|
100
|
+
console.error(` ${extractError instanceof Error ? extractError.message : String(extractError)}`);
|
|
101
|
+
// Clean up temp file if it exists
|
|
102
|
+
if (fs.existsSync(tempTokenFile)) {
|
|
103
|
+
try {
|
|
104
|
+
fs.unlinkSync(tempTokenFile);
|
|
105
|
+
} catch (unlinkError) {
|
|
106
|
+
// Ignore
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
await zip.closeFile();
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Validate token metadata structure
|
|
114
|
+
if (!tokenMetadata.tokenId || !tokenMetadata.contractAddress || !tokenMetadata.network) {
|
|
115
|
+
console.error('❌ Error: Invalid token metadata structure');
|
|
116
|
+
console.error(' Missing required fields: tokenId, contractAddress, or network');
|
|
117
|
+
await zip.closeFile();
|
|
118
|
+
process.exit(1);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
console.log('✅ Token metadata extracted');
|
|
122
|
+
console.log(` Token ID: ${tokenMetadata.tokenId}`);
|
|
123
|
+
console.log(` Contract: ${tokenMetadata.contractAddress}`);
|
|
124
|
+
console.log(` Network: ${tokenMetadata.network}`);
|
|
125
|
+
if (tokenMetadata.transactionHash) {
|
|
126
|
+
console.log(` Transaction: ${tokenMetadata.transactionHash}`);
|
|
127
|
+
}
|
|
128
|
+
console.log();
|
|
129
|
+
|
|
130
|
+
// Step 3: Calculate merkle root from ZIP contents
|
|
131
|
+
console.log('Step 3: Calculating merkle root from ZIP contents...');
|
|
132
|
+
|
|
133
|
+
// Get merkle root (this excludes token metadata file automatically)
|
|
134
|
+
const merkleRoot = (zip as any).getMerkleRoot?.();
|
|
135
|
+
|
|
136
|
+
if (!merkleRoot) {
|
|
137
|
+
console.error('❌ Error: Could not calculate merkle root');
|
|
138
|
+
console.error(' Make sure the ZIP file was created with SHA-256 hashes enabled');
|
|
139
|
+
await zip.closeFile();
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
console.log(`✅ Merkle root calculated: ${merkleRoot}`);
|
|
144
|
+
|
|
145
|
+
// Compare with metadata merkle root if present
|
|
146
|
+
if (tokenMetadata.merkleRoot) {
|
|
147
|
+
if (tokenMetadata.merkleRoot === merkleRoot) {
|
|
148
|
+
console.log(' ✓ Matches merkle root in token metadata');
|
|
149
|
+
} else {
|
|
150
|
+
console.log(' ⚠️ WARNING: Does not match merkle root in token metadata!');
|
|
151
|
+
console.log(` Metadata: ${tokenMetadata.merkleRoot}`);
|
|
152
|
+
console.log(` Calculated: ${merkleRoot}`);
|
|
153
|
+
console.log(' This may indicate the ZIP file has been modified.');
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
console.log();
|
|
157
|
+
|
|
158
|
+
// Close file handle before verification
|
|
159
|
+
await zip.closeFile();
|
|
160
|
+
|
|
161
|
+
// Step 4: Verify token on blockchain
|
|
162
|
+
console.log('Step 4: Verifying token on blockchain...');
|
|
163
|
+
console.log(' This may take a few moments...\n');
|
|
164
|
+
|
|
165
|
+
const verifier = new ZipkitVerifier({
|
|
166
|
+
debug: false
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const verificationResult = await verifier.verifyToken(
|
|
170
|
+
tokenMetadata,
|
|
171
|
+
merkleRoot,
|
|
172
|
+
{
|
|
173
|
+
debug: false,
|
|
174
|
+
skipHash: false
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
// Step 5: Display verification results
|
|
179
|
+
console.log('Step 5: Verification Results');
|
|
180
|
+
console.log('═'.repeat(80));
|
|
181
|
+
|
|
182
|
+
if (verificationResult.success) {
|
|
183
|
+
console.log('✅ VERIFICATION SUCCESSFUL');
|
|
184
|
+
console.log('═'.repeat(80));
|
|
185
|
+
console.log(`Token ID: ${tokenMetadata.tokenId}`);
|
|
186
|
+
console.log(`Contract: ${tokenMetadata.contractAddress}`);
|
|
187
|
+
console.log(`Network: ${tokenMetadata.network}`);
|
|
188
|
+
|
|
189
|
+
if (verificationResult.verificationDetails) {
|
|
190
|
+
const details = verificationResult.verificationDetails;
|
|
191
|
+
console.log(`\nBlockchain Data:`);
|
|
192
|
+
if (details.merkleRoot) {
|
|
193
|
+
console.log(` Merkle Root: ${details.merkleRoot}`);
|
|
194
|
+
}
|
|
195
|
+
if (details.mintDate) {
|
|
196
|
+
console.log(` Tokenization Time: ${details.mintDate}`);
|
|
197
|
+
}
|
|
198
|
+
if (details.onChainValid !== undefined) {
|
|
199
|
+
console.log(` On-Chain Valid: ${details.onChainValid ? 'Yes' : 'No'}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
console.log(`\nMerkle Root Verification:`);
|
|
204
|
+
if (verificationResult.verificationDetails?.merkleRootMatch) {
|
|
205
|
+
console.log(' ✅ Calculated merkle root matches blockchain');
|
|
206
|
+
if (verificationResult.verificationDetails.calculatedMerkleRoot && verificationResult.verificationDetails.declaredMerkleRoot) {
|
|
207
|
+
console.log(` Calculated: ${verificationResult.verificationDetails.calculatedMerkleRoot}`);
|
|
208
|
+
console.log(` On-chain: ${verificationResult.verificationDetails.declaredMerkleRoot}`);
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
console.log(' ❌ Calculated merkle root does NOT match blockchain!');
|
|
212
|
+
if (verificationResult.errorDetails) {
|
|
213
|
+
if (verificationResult.errorDetails.calculatedMerkleRoot) {
|
|
214
|
+
console.log(` Calculated: ${verificationResult.errorDetails.calculatedMerkleRoot}`);
|
|
215
|
+
}
|
|
216
|
+
if (verificationResult.errorDetails.onChainMerkleRoot) {
|
|
217
|
+
console.log(` On-chain: ${verificationResult.errorDetails.onChainMerkleRoot}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (verificationResult.verificationDetails?.onChainValid) {
|
|
223
|
+
console.log('\n✅ Token is valid and verified on blockchain');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Display explorer link
|
|
227
|
+
const networkName = tokenMetadata.network.toLowerCase();
|
|
228
|
+
let explorerUrl = '';
|
|
229
|
+
|
|
230
|
+
if (networkName.includes('base') && networkName.includes('sepolia')) {
|
|
231
|
+
explorerUrl = `https://sepolia.basescan.org/token/${tokenMetadata.contractAddress}?a=${tokenMetadata.tokenId}`;
|
|
232
|
+
} else if (networkName.includes('base')) {
|
|
233
|
+
explorerUrl = `https://basescan.org/token/${tokenMetadata.contractAddress}?a=${tokenMetadata.tokenId}`;
|
|
234
|
+
} else if (networkName.includes('arbitrum') && networkName.includes('sepolia')) {
|
|
235
|
+
explorerUrl = `https://sepolia.arbiscan.io/token/${tokenMetadata.contractAddress}?a=${tokenMetadata.tokenId}`;
|
|
236
|
+
} else if (networkName.includes('arbitrum')) {
|
|
237
|
+
explorerUrl = `https://arbiscan.io/token/${tokenMetadata.contractAddress}?a=${tokenMetadata.tokenId}`;
|
|
238
|
+
} else if (networkName.includes('sepolia')) {
|
|
239
|
+
explorerUrl = `https://sepolia.etherscan.io/token/${tokenMetadata.contractAddress}?a=${tokenMetadata.tokenId}`;
|
|
240
|
+
} else if (networkName.includes('ethereum')) {
|
|
241
|
+
explorerUrl = `https://etherscan.io/token/${tokenMetadata.contractAddress}?a=${tokenMetadata.tokenId}`;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (explorerUrl) {
|
|
245
|
+
console.log(`\n📄 View token on explorer:`);
|
|
246
|
+
console.log(` ${explorerUrl}`);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
} else {
|
|
250
|
+
console.log('❌ VERIFICATION FAILED');
|
|
251
|
+
console.log('═'.repeat(80));
|
|
252
|
+
console.log(`Error: ${verificationResult.message}`);
|
|
253
|
+
|
|
254
|
+
if (verificationResult.errorDetails) {
|
|
255
|
+
console.log(`\nError Details:`);
|
|
256
|
+
console.log(` Type: ${verificationResult.errorDetails.errorType || 'UNKNOWN'}`);
|
|
257
|
+
if (verificationResult.errorDetails.networkName) {
|
|
258
|
+
console.log(` Network: ${verificationResult.errorDetails.networkName}`);
|
|
259
|
+
}
|
|
260
|
+
if (verificationResult.errorDetails.rpcUrl) {
|
|
261
|
+
console.log(` RPC URL: ${verificationResult.errorDetails.rpcUrl}`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
console.log('\n💡 Possible causes:');
|
|
266
|
+
console.log(' - Token does not exist on blockchain');
|
|
267
|
+
console.log(' - Merkle root mismatch (ZIP file may have been modified)');
|
|
268
|
+
console.log(' - Network connectivity issues');
|
|
269
|
+
console.log(' - Invalid contract address or network');
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
console.log('═'.repeat(80));
|
|
273
|
+
console.log();
|
|
274
|
+
|
|
275
|
+
// Exit with appropriate code
|
|
276
|
+
process.exit(verificationResult.success ? 0 : 1);
|
|
277
|
+
|
|
278
|
+
} catch (error) {
|
|
279
|
+
console.error('❌ Error during verification:');
|
|
280
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
281
|
+
if (error instanceof Error && error.stack) {
|
|
282
|
+
console.error('\nStack trace:');
|
|
283
|
+
console.error(error.stack);
|
|
284
|
+
}
|
|
285
|
+
process.exit(1);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Format bytes to human-readable string
|
|
291
|
+
*/
|
|
292
|
+
function formatBytes(bytes: number): string {
|
|
293
|
+
if (bytes === 0) return '0 B';
|
|
294
|
+
const k = 1024;
|
|
295
|
+
const sizes = ['B', 'KB', 'MB', 'GB'];
|
|
296
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
297
|
+
return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i];
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// Run the example
|
|
301
|
+
main().catch((error) => {
|
|
302
|
+
console.error('Fatal error:', error);
|
|
303
|
+
process.exit(1);
|
|
304
|
+
});
|
|
305
|
+
|