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
|
@@ -1,382 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// Contract addresses and configurations for different networks
|
|
2
|
-
|
|
3
|
-
export interface ContractConfig {
|
|
4
|
-
address: string
|
|
5
|
-
network: string
|
|
6
|
-
chainId: number
|
|
7
|
-
explorerUrl: string
|
|
8
|
-
rpcUrls: string[]
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// NZIP NFT Contract configurations by network
|
|
12
|
-
export const CONTRACT_CONFIGS: Record<number, ContractConfig> = {
|
|
13
|
-
// Base Sepolia (Primary testnet)
|
|
14
|
-
84532: {
|
|
15
|
-
address: '0xFD76a5d420704F34d84b0767961835c43D7b30a8', // Production contract v2.0
|
|
16
|
-
network: 'Base Sepolia',
|
|
17
|
-
chainId: 84532,
|
|
18
|
-
explorerUrl: 'https://sepolia.basescan.org',
|
|
19
|
-
rpcUrls: [
|
|
20
|
-
'https://sepolia.base.org',
|
|
21
|
-
'https://base-sepolia.g.alchemy.com/v2/demo',
|
|
22
|
-
'https://base-sepolia-rpc.publicnode.com'
|
|
23
|
-
]
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
// Base Mainnet (Production)
|
|
27
|
-
8453: {
|
|
28
|
-
address: '0x2716c4609fD97DaEdF429BC4B4Ec2faa81e2cC60',
|
|
29
|
-
network: 'Base Mainnet',
|
|
30
|
-
chainId: 8453,
|
|
31
|
-
explorerUrl: 'https://basescan.org',
|
|
32
|
-
rpcUrls: [
|
|
33
|
-
'https://mainnet.base.org',
|
|
34
|
-
'https://base.drpc.org',
|
|
35
|
-
'https://base.gateway.tenderly.co'
|
|
36
|
-
]
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
// Ethereum Sepolia (Testnet) - disabled until NZIP is deployed
|
|
40
|
-
// 11155111: {
|
|
41
|
-
// address: '0x0000000000000000000000000000000000000000',
|
|
42
|
-
// network: 'Sepolia Testnet',
|
|
43
|
-
// chainId: 11155111,
|
|
44
|
-
// explorerUrl: 'https://sepolia.etherscan.io',
|
|
45
|
-
// rpcUrls: []
|
|
46
|
-
// },
|
|
47
|
-
|
|
48
|
-
// Ethereum Mainnet (Production) - disabled until NZIP is deployed
|
|
49
|
-
// 1: {
|
|
50
|
-
// address: '0x0000000000000000000000000000000000000000',
|
|
51
|
-
// network: 'Ethereum Mainnet',
|
|
52
|
-
// chainId: 1,
|
|
53
|
-
// explorerUrl: 'https://etherscan.io',
|
|
54
|
-
// rpcUrls: []
|
|
55
|
-
// }
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Contract ABI (same for all networks)
|
|
59
|
-
export const NZIP_CONTRACT_ABI = [
|
|
60
|
-
"function publicMintZipFile(string memory fileName, string memory merkleRootHash, uint256 creationTimestamp, string memory ipfsHash, string memory metadataURI) public returns (uint256)",
|
|
61
|
-
"function totalSupply() external view returns (uint256)",
|
|
62
|
-
"function getTokensByMerkleRoot(string memory merkleRoot) external view returns (uint256[])",
|
|
63
|
-
"function getZipFileInfo(uint256 tokenId) external view returns (tuple(string fileName, string merkleRootHash, string ipfsHash, address creator, uint256 creationTimestamp, uint256 tokenizationTime, uint256 blockNumber))",
|
|
64
|
-
"function ownerOf(uint256 tokenId) external view returns (address)",
|
|
65
|
-
"function balanceOf(address owner) external view returns (uint256)",
|
|
66
|
-
"function isZipFileTokenized(string memory merkleRootHash, uint256 creationTimestamp) external view returns (bool exists, uint256 tokenId)",
|
|
67
|
-
"function verifyZipFile(uint256 tokenId, string memory providedMerkleRoot) external view returns (bool isValid)",
|
|
68
|
-
"function getVersion() external pure returns (string memory)",
|
|
69
|
-
"event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)",
|
|
70
|
-
"event ZipFileTokenized(uint256 indexed tokenId, address indexed creator, string fileName, string merkleRootHash, uint256 creationTimestamp, string ipfsHash, uint256 tokenizationTime, uint256 blockNumber)"
|
|
71
|
-
]
|
|
72
|
-
|
|
73
|
-
// Default configuration (Base Sepolia for development)
|
|
74
|
-
export const DEFAULT_NETWORK = 84532
|
|
75
|
-
export const CURRENT_DEPLOYMENT = CONTRACT_CONFIGS[DEFAULT_NETWORK]
|
|
76
|
-
|
|
77
|
-
// Helper functions
|
|
78
|
-
export const getContractConfig = (chainId: number): ContractConfig => {
|
|
79
|
-
return CONTRACT_CONFIGS[chainId] || CURRENT_DEPLOYMENT
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export const getSupportedNetworks = (): number[] => {
|
|
83
|
-
return Object.keys(CONTRACT_CONFIGS).map(Number)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export const isNetworkSupported = (chainId: number): boolean => {
|
|
87
|
-
return chainId in CONTRACT_CONFIGS
|
|
88
|
-
}
|
package/src/blockchain/types.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import type { Wallet, JsonRpcProvider } from 'ethers';
|
|
2
|
-
|
|
3
|
-
// Wallet and network types
|
|
4
|
-
export interface WalletInfo {
|
|
5
|
-
address: string;
|
|
6
|
-
privateKey: string;
|
|
7
|
-
mnemonic: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface NetworkConfig {
|
|
11
|
-
name: string;
|
|
12
|
-
rpcUrl: string;
|
|
13
|
-
chainId: number;
|
|
14
|
-
explorerUrl: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface WalletSetupResult {
|
|
18
|
-
wallet: Wallet | null;
|
|
19
|
-
provider: JsonRpcProvider | null;
|
|
20
|
-
success: boolean;
|
|
21
|
-
message?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface MintingResult {
|
|
25
|
-
success: boolean;
|
|
26
|
-
message: string;
|
|
27
|
-
tokenId?: string;
|
|
28
|
-
txHash?: string;
|
|
29
|
-
creationTimestamp?: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface MintingOptions {
|
|
33
|
-
wallet?: string;
|
|
34
|
-
network: string;
|
|
35
|
-
mintToken: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Canonical token metadata used across minting, verification, and ZIP embedding
|
|
39
|
-
export interface TokenMetadata {
|
|
40
|
-
// Core identifiers
|
|
41
|
-
tokenId: string;
|
|
42
|
-
contractAddress: string;
|
|
43
|
-
network: string;
|
|
44
|
-
merkleRoot: string;
|
|
45
|
-
|
|
46
|
-
// Optional chain info
|
|
47
|
-
networkChainId?: number;
|
|
48
|
-
transactionHash?: string;
|
|
49
|
-
blockNumber?: number;
|
|
50
|
-
|
|
51
|
-
// Names and timestamps (support both archiveName/fileName and mintedAt/mintDate)
|
|
52
|
-
fileName?: string;
|
|
53
|
-
archiveName?: string;
|
|
54
|
-
mintedAt?: string;
|
|
55
|
-
mintDate?: string;
|
|
56
|
-
creationTimestamp?: number;
|
|
57
|
-
|
|
58
|
-
// Optional content link
|
|
59
|
-
ipfsHash?: string;
|
|
60
|
-
|
|
61
|
-
// Versioning
|
|
62
|
-
version?: string;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Network configuration
|
|
66
|
-
export const NETWORKS: Record<string, NetworkConfig> = {
|
|
67
|
-
'base': {
|
|
68
|
-
name: 'Base Mainnet',
|
|
69
|
-
rpcUrl: 'https://mainnet.base.org',
|
|
70
|
-
chainId: 8453,
|
|
71
|
-
explorerUrl: 'https://basescan.org'
|
|
72
|
-
},
|
|
73
|
-
'base-sepolia': {
|
|
74
|
-
name: 'Base Sepolia',
|
|
75
|
-
rpcUrl: 'https://sepolia.base.org',
|
|
76
|
-
chainId: 84532,
|
|
77
|
-
explorerUrl: 'https://sepolia.basescan.org'
|
|
78
|
-
},
|
|
79
|
-
'base-goerli': {
|
|
80
|
-
name: 'Base Goerli',
|
|
81
|
-
rpcUrl: 'https://goerli.base.org',
|
|
82
|
-
chainId: 84531,
|
|
83
|
-
explorerUrl: 'https://goerli.basescan.org'
|
|
84
|
-
},
|
|
85
|
-
'localhost': {
|
|
86
|
-
name: 'Localhost',
|
|
87
|
-
rpcUrl: 'http://localhost:8545',
|
|
88
|
-
chainId: 31337,
|
|
89
|
-
explorerUrl: 'http://localhost:8545'
|
|
90
|
-
}
|
|
91
|
-
};
|