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,23 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Core WalletManager - Platform-agnostic wallet functionality
|
|
3
|
+
* Provides core wallet operations that work in both browser and server environments
|
|
4
|
+
*/
|
|
5
|
+
|
|
4
6
|
import { ethers } from 'ethers';
|
|
5
|
-
import { WalletSetupResult, WalletInfo, NetworkConfig, NETWORKS, MintingOptions } from '
|
|
7
|
+
import { WalletSetupResult, WalletInfo, NetworkConfig, NETWORKS, MintingOptions } from '../../types';
|
|
8
|
+
import { Logger } from '../../core/components/Logger';
|
|
9
|
+
|
|
10
|
+
export interface CommonTokenConfig {
|
|
11
|
+
address: string;
|
|
12
|
+
name: string;
|
|
13
|
+
symbol: string;
|
|
14
|
+
type: 'ERC20' | 'ERC721';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface TokenInfo {
|
|
18
|
+
address: string;
|
|
19
|
+
name: string;
|
|
20
|
+
symbol: string;
|
|
21
|
+
balance: string;
|
|
22
|
+
decimals?: number;
|
|
23
|
+
type: 'ERC20' | 'ERC721' | 'NZIP';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface WalletBasicInfo {
|
|
27
|
+
ethBalance: string;
|
|
28
|
+
transactionCount: number;
|
|
29
|
+
networkName: string;
|
|
30
|
+
chainId: bigint;
|
|
31
|
+
latestBlock: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface TokenScanResult {
|
|
35
|
+
foundTokens: number[];
|
|
36
|
+
searchMethod: 'recent-events' | 'iteration' | 'common-ids' | 'none';
|
|
37
|
+
}
|
|
6
38
|
|
|
7
|
-
export interface
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
39
|
+
export interface NZipTokenDetails {
|
|
40
|
+
tokenId: string;
|
|
41
|
+
merkleRootHash: string;
|
|
42
|
+
timestamp: number;
|
|
43
|
+
tokenURI?: string;
|
|
44
|
+
creator: string;
|
|
45
|
+
creationTimestamp: number;
|
|
46
|
+
tokenizationTime: number;
|
|
47
|
+
ipfsHash?: string;
|
|
48
|
+
}
|
|
12
49
|
|
|
13
50
|
const NZIP_CONTRACT_ABI = [
|
|
14
|
-
"function getZipFileInfo(uint256 tokenId) view returns (tuple(string
|
|
51
|
+
"function getZipFileInfo(uint256 tokenId) view returns (tuple(string merkleRootHash, string ipfsHash, address creator, uint256 creationTimestamp, uint256 tokenizationTime, uint256 blockNumber))",
|
|
15
52
|
"function ownerOf(uint256 tokenId) view returns (address)",
|
|
16
53
|
"function name() view returns (string)",
|
|
17
54
|
"function symbol() view returns (string)",
|
|
18
55
|
"function totalSupply() view returns (uint256)",
|
|
19
56
|
"function getTokensByMerkleRoot(string merkleRootHash) view returns (uint256[])",
|
|
20
|
-
"event ZipFileTokenized(uint256 indexed tokenId, address indexed creator, string
|
|
57
|
+
"event ZipFileTokenized(uint256 indexed tokenId, address indexed creator, string merkleRootHash, uint256 creationTimestamp, string ipfsHash, uint256 tokenizationTime, uint256 blockNumber)"
|
|
21
58
|
];
|
|
22
59
|
|
|
23
60
|
const ERC20_ABI = [
|
|
@@ -34,195 +71,208 @@ const ERC721_ABI = [
|
|
|
34
71
|
"function tokenOfOwnerByIndex(address owner, uint256 index) view returns (uint256)"
|
|
35
72
|
];
|
|
36
73
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return new Promise<string>((resolve) => {
|
|
44
|
-
rl.question(question, (answer: string) => { rl.close(); resolve(answer.trim()); });
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
private findExistingWallets(): string[] {
|
|
49
|
-
const walletFiles: string[] = [];
|
|
50
|
-
const currentDir = process.cwd();
|
|
51
|
-
const walletDir = path.join(currentDir, 'wallet');
|
|
52
|
-
const walletFileNames = ['neozip-wallet.json'];
|
|
53
|
-
for (const fileName of walletFileNames) {
|
|
54
|
-
const filePath = path.join(currentDir, fileName);
|
|
55
|
-
if (fs.existsSync(filePath)) walletFiles.push(filePath);
|
|
56
|
-
}
|
|
57
|
-
if (fs.existsSync(walletDir)) {
|
|
58
|
-
for (const fileName of walletFileNames) {
|
|
59
|
-
const filePath = path.join(walletDir, fileName);
|
|
60
|
-
if (fs.existsSync(filePath)) walletFiles.push(filePath);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return walletFiles;
|
|
64
|
-
}
|
|
74
|
+
/**
|
|
75
|
+
* Core wallet functionality that works in both browser and server environments
|
|
76
|
+
*/
|
|
77
|
+
export class CoreWalletManager {
|
|
78
|
+
protected wallet: ethers.Wallet | null = null;
|
|
79
|
+
protected provider: ethers.JsonRpcProvider | null = null;
|
|
65
80
|
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
const content = fs.readFileSync(filePath, 'utf8').trim();
|
|
69
|
-
try {
|
|
70
|
-
const walletData = JSON.parse(content);
|
|
71
|
-
if (walletData.privateKey) {
|
|
72
|
-
console.log(`Found wallet file: ${filePath}`);
|
|
73
|
-
console.log(`Wallet address: ${walletData.address}`);
|
|
74
|
-
return walletData.privateKey;
|
|
75
|
-
}
|
|
76
|
-
} catch {
|
|
77
|
-
if (content.startsWith('0x') && content.length === 66) {
|
|
78
|
-
console.log(`Found private key file: ${filePath}`);
|
|
79
|
-
return content;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return null;
|
|
83
|
-
} catch (error) {
|
|
84
|
-
console.warn(`Could not read wallet file ${filePath}:`, error);
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
81
|
+
constructor() {}
|
|
88
82
|
|
|
89
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Setup wallet with private key and connect to network
|
|
85
|
+
*
|
|
86
|
+
* SECURITY WARNING: This method accepts a private key as a parameter.
|
|
87
|
+
* - Never hardcode private keys in source code
|
|
88
|
+
* - Always use environment variables for private keys
|
|
89
|
+
* - Use testnet keys for development/testing
|
|
90
|
+
* - Use secure key management (HSMs, KMS) for production
|
|
91
|
+
* - See SECURITY.md for complete security guidelines
|
|
92
|
+
*/
|
|
93
|
+
async setupWallet(privateKey: string, network: string, mintToken: boolean = false): Promise<WalletSetupResult> {
|
|
90
94
|
try {
|
|
91
|
-
const networkConfig = NETWORKS[
|
|
92
|
-
|
|
93
|
-
if ((options as any).wallet) {
|
|
94
|
-
const val = (options as any).wallet as string;
|
|
95
|
-
if (fs.existsSync(val)) {
|
|
96
|
-
const loaded = this.loadWalletFromFile(val);
|
|
97
|
-
if (!loaded) throw new Error(`Could not load valid private key from ${val}`);
|
|
98
|
-
privateKey = loaded;
|
|
99
|
-
} else {
|
|
100
|
-
privateKey = val;
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
const existing = this.findExistingWallets();
|
|
104
|
-
if (existing.length > 0) {
|
|
105
|
-
const selected = existing[0];
|
|
106
|
-
const relativePath = path.relative(process.cwd(), selected);
|
|
107
|
-
console.log(`Using existing wallet: ${relativePath}`);
|
|
108
|
-
const loaded = this.loadWalletFromFile(selected);
|
|
109
|
-
if (!loaded) throw new Error(`Could not load valid private key from ${selected}`);
|
|
110
|
-
privateKey = loaded;
|
|
111
|
-
} else {
|
|
112
|
-
console.log('No existing wallet found. Creating new wallet...');
|
|
113
|
-
privateKey = await this.createNewWallet();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
95
|
+
const networkConfig = NETWORKS[network] || NETWORKS['base-sepolia'];
|
|
96
|
+
|
|
117
97
|
this.wallet = new ethers.Wallet(privateKey);
|
|
118
|
-
|
|
119
|
-
|
|
98
|
+
Logger.log(`Using wallet: ${this.wallet.address}`);
|
|
99
|
+
|
|
100
|
+
const ok = await this.connectToNetwork(networkConfig, mintToken);
|
|
120
101
|
if (!ok) {
|
|
121
|
-
return {
|
|
102
|
+
return {
|
|
103
|
+
wallet: null,
|
|
104
|
+
provider: null,
|
|
105
|
+
success: false,
|
|
106
|
+
message: `Failed to connect to ${networkConfig.name} network. Blockchain operations require network connectivity.`
|
|
107
|
+
};
|
|
122
108
|
}
|
|
123
|
-
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
wallet: this.wallet,
|
|
112
|
+
provider: this.provider,
|
|
113
|
+
success: true,
|
|
114
|
+
message: `Wallet setup successful for ${networkConfig.name}`
|
|
115
|
+
};
|
|
124
116
|
} catch (error) {
|
|
125
|
-
|
|
126
|
-
return {
|
|
117
|
+
Logger.error('Error setting up wallet:', error);
|
|
118
|
+
return {
|
|
119
|
+
wallet: null,
|
|
120
|
+
provider: null,
|
|
121
|
+
success: false,
|
|
122
|
+
message: `Wallet setup failed: ${error instanceof Error ? error.message : String(error)}`
|
|
123
|
+
};
|
|
127
124
|
}
|
|
128
125
|
}
|
|
129
126
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const walletDir = path.join(process.cwd(), 'wallet');
|
|
135
|
-
if (!fs.existsSync(walletDir)) fs.mkdirSync(walletDir, { recursive: true });
|
|
136
|
-
const walletFilePath = path.join(walletDir, 'neozip-wallet.json');
|
|
137
|
-
fs.writeFileSync(walletFilePath, JSON.stringify(walletInfo, null, 2));
|
|
138
|
-
console.log(`New wallet created and saved to ${walletFilePath}`);
|
|
139
|
-
console.log(`Wallet address: ${newWallet.address}`);
|
|
140
|
-
console.log(`IMPORTANT: Please fund this wallet with BASE to use for minting NFTs!`);
|
|
141
|
-
return newWallet.privateKey;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
private async connectToNetwork(networkConfig: NetworkConfig, mintToken: boolean): Promise<boolean> {
|
|
127
|
+
/**
|
|
128
|
+
* Connect to the specified network
|
|
129
|
+
*/
|
|
130
|
+
protected async connectToNetwork(networkConfig: NetworkConfig, mintToken: boolean): Promise<boolean> {
|
|
145
131
|
try {
|
|
146
|
-
|
|
132
|
+
Logger.log(`Attempting to connect to ${networkConfig.name} network...`);
|
|
147
133
|
this.provider = new ethers.JsonRpcProvider(networkConfig.rpcUrl);
|
|
134
|
+
|
|
148
135
|
let networkTimedOut = false;
|
|
149
|
-
const networkTimeout = setTimeout(() => {
|
|
136
|
+
const networkTimeout = setTimeout(() => {
|
|
137
|
+
networkTimedOut = true;
|
|
138
|
+
Logger.error("Network connection timeout");
|
|
139
|
+
}, 5000);
|
|
140
|
+
|
|
150
141
|
await Promise.race([
|
|
151
142
|
this.provider.getNetwork(),
|
|
152
|
-
new Promise((_, reject) =>
|
|
143
|
+
new Promise((_, reject) =>
|
|
144
|
+
setTimeout(() => {
|
|
145
|
+
if (networkTimedOut) reject(new Error("Network connection timeout"));
|
|
146
|
+
}, 5100)
|
|
147
|
+
)
|
|
153
148
|
]);
|
|
149
|
+
|
|
154
150
|
clearTimeout(networkTimeout);
|
|
151
|
+
|
|
155
152
|
if (this.wallet) {
|
|
156
153
|
this.wallet = this.wallet.connect(this.provider);
|
|
157
154
|
const balance = await this.provider.getBalance(this.wallet.address);
|
|
158
155
|
const balanceEth = ethers.formatEther(balance);
|
|
159
|
-
|
|
156
|
+
Logger.log(`Wallet balance: ${balanceEth} ETH`);
|
|
157
|
+
|
|
160
158
|
const minBalance = 0.0001;
|
|
161
159
|
if (parseFloat(balanceEth) < minBalance && mintToken) {
|
|
162
|
-
|
|
163
|
-
|
|
160
|
+
Logger.error(`ERROR: Insufficient balance (${balanceEth} ETH). Minimum required: ${minBalance} ETH`);
|
|
161
|
+
Logger.error('Get testnet ETH from: https://www.coinbase.com/faucets/base-ethereum-sepolia-faucet');
|
|
164
162
|
throw new Error(`Insufficient balance for minting. Current: ${balanceEth} ETH, Required: ${minBalance} ETH`);
|
|
165
163
|
} else if (mintToken) {
|
|
166
|
-
|
|
164
|
+
Logger.log(`✅ Sufficient balance for token minting`);
|
|
167
165
|
}
|
|
168
166
|
}
|
|
169
|
-
|
|
167
|
+
|
|
168
|
+
Logger.log(`✅ Successfully connected to ${networkConfig.name}`);
|
|
170
169
|
return true;
|
|
171
170
|
} catch (networkError: unknown) {
|
|
172
171
|
const errorMessage = networkError instanceof Error ? networkError.message : String(networkError);
|
|
173
|
-
|
|
172
|
+
Logger.error(`Failed to connect to ${networkConfig.name} network: ${errorMessage}`);
|
|
174
173
|
this.provider = null;
|
|
175
174
|
return false;
|
|
176
175
|
}
|
|
177
176
|
}
|
|
178
177
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
178
|
+
/**
|
|
179
|
+
* Get the current wallet instance
|
|
180
|
+
*/
|
|
181
|
+
getWallet(): ethers.Wallet | null {
|
|
182
|
+
return this.wallet;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Get the current provider instance
|
|
187
|
+
*/
|
|
188
|
+
getProvider(): ethers.JsonRpcProvider | null {
|
|
189
|
+
return this.provider;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Check if wallet is ready
|
|
194
|
+
*/
|
|
195
|
+
isReady(): boolean {
|
|
196
|
+
return this.wallet !== null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Check if connected to network
|
|
201
|
+
*/
|
|
202
|
+
isOnline(): boolean {
|
|
203
|
+
return this.provider !== null;
|
|
204
|
+
}
|
|
183
205
|
}
|
|
184
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Wallet analyzer for blockchain operations
|
|
209
|
+
*/
|
|
185
210
|
export class WalletAnalyzer {
|
|
186
211
|
private provider: ethers.JsonRpcProvider;
|
|
187
|
-
|
|
212
|
+
|
|
213
|
+
constructor(provider: ethers.JsonRpcProvider) {
|
|
214
|
+
this.provider = provider;
|
|
215
|
+
}
|
|
188
216
|
|
|
217
|
+
/**
|
|
218
|
+
* Get basic wallet information
|
|
219
|
+
*/
|
|
189
220
|
async getWalletBasics(address: string): Promise<WalletBasicInfo> {
|
|
190
221
|
const balance = await this.provider.getBalance(address);
|
|
191
222
|
const ethBalance = ethers.formatEther(balance);
|
|
192
223
|
const txCount = await this.provider.getTransactionCount(address);
|
|
193
224
|
const network = await this.provider.getNetwork();
|
|
194
225
|
const latestBlock = await this.provider.getBlockNumber();
|
|
195
|
-
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
ethBalance,
|
|
229
|
+
transactionCount: txCount,
|
|
230
|
+
networkName: network.name,
|
|
231
|
+
chainId: network.chainId,
|
|
232
|
+
latestBlock
|
|
233
|
+
};
|
|
196
234
|
}
|
|
197
235
|
|
|
236
|
+
/**
|
|
237
|
+
* Scan for NZIP tokens owned by an address
|
|
238
|
+
*/
|
|
198
239
|
async scanForNZipTokens(contractAddress: string, ownerAddress: string): Promise<TokenScanResult> {
|
|
199
240
|
const contract = new ethers.Contract(contractAddress, NZIP_CONTRACT_ABI, this.provider);
|
|
200
241
|
let foundTokens: number[] = [];
|
|
201
242
|
let searchMethod: TokenScanResult['searchMethod'] = 'none';
|
|
243
|
+
|
|
202
244
|
try {
|
|
203
245
|
const latestBlock = await this.provider.getBlockNumber();
|
|
204
246
|
const startBlock = Math.max(0, latestBlock - 50000);
|
|
205
247
|
const filter = contract.filters.ZipFileTokenized(null, ownerAddress);
|
|
206
248
|
const events = await contract.queryFilter(filter, startBlock, 'latest');
|
|
249
|
+
|
|
207
250
|
for (const event of events) {
|
|
208
251
|
if ('args' in event && event.args && (event as any).args.tokenId) {
|
|
209
252
|
const tokenId = Number((event as any).args.tokenId);
|
|
210
253
|
if (!foundTokens.includes(tokenId)) foundTokens.push(tokenId);
|
|
211
254
|
}
|
|
212
255
|
}
|
|
213
|
-
|
|
256
|
+
|
|
257
|
+
if (foundTokens.length > 0) {
|
|
258
|
+
return { foundTokens, searchMethod: 'recent-events' };
|
|
259
|
+
}
|
|
214
260
|
} catch {}
|
|
261
|
+
|
|
215
262
|
try {
|
|
216
263
|
const totalSupply = await contract.totalSupply();
|
|
217
264
|
const maxCheck = Math.min(Number(totalSupply), 50);
|
|
265
|
+
|
|
218
266
|
for (let tokenId = 0; tokenId < maxCheck; tokenId++) {
|
|
219
267
|
try {
|
|
220
268
|
const owner = await contract.ownerOf(tokenId);
|
|
221
269
|
if (owner.toLowerCase() === ownerAddress.toLowerCase()) foundTokens.push(tokenId);
|
|
222
270
|
} catch {}
|
|
223
271
|
}
|
|
272
|
+
|
|
224
273
|
if (foundTokens.length > 0) return { foundTokens, searchMethod: 'iteration' };
|
|
225
274
|
} catch {}
|
|
275
|
+
|
|
226
276
|
const commonTokenIds = Array.from({length: 20}, (_, i) => i);
|
|
227
277
|
for (const tokenId of commonTokenIds) {
|
|
228
278
|
try {
|
|
@@ -230,19 +280,23 @@ export class WalletAnalyzer {
|
|
|
230
280
|
if (owner.toLowerCase() === ownerAddress.toLowerCase()) foundTokens.push(tokenId);
|
|
231
281
|
} catch {}
|
|
232
282
|
}
|
|
283
|
+
|
|
233
284
|
return { foundTokens, searchMethod: foundTokens.length > 0 ? 'common-ids' : 'none' };
|
|
234
285
|
}
|
|
235
286
|
|
|
287
|
+
/**
|
|
288
|
+
* Get detailed information for NZIP tokens
|
|
289
|
+
*/
|
|
236
290
|
async getNZipTokenDetails(contractAddress: string, tokenIds: number[]): Promise<NZipTokenDetails[]> {
|
|
237
291
|
const contract = new ethers.Contract(contractAddress, NZIP_CONTRACT_ABI, this.provider);
|
|
238
292
|
const tokenDetails: NZipTokenDetails[] = [];
|
|
293
|
+
|
|
239
294
|
for (const tokenId of tokenIds) {
|
|
240
295
|
try {
|
|
241
296
|
const zipInfo = await contract.getZipFileInfo(tokenId);
|
|
242
297
|
tokenDetails.push({
|
|
243
298
|
tokenId: tokenId.toString(),
|
|
244
299
|
merkleRootHash: zipInfo.merkleRootHash,
|
|
245
|
-
fileName: zipInfo.fileName,
|
|
246
300
|
timestamp: Number(zipInfo.creationTimestamp),
|
|
247
301
|
creator: zipInfo.creator,
|
|
248
302
|
creationTimestamp: Number(zipInfo.creationTimestamp),
|
|
@@ -250,61 +304,104 @@ export class WalletAnalyzer {
|
|
|
250
304
|
ipfsHash: zipInfo.ipfsHash || undefined
|
|
251
305
|
});
|
|
252
306
|
} catch (error) {
|
|
253
|
-
|
|
307
|
+
Logger.error(`Error fetching details for token ${tokenId}:`, error);
|
|
254
308
|
}
|
|
255
309
|
}
|
|
310
|
+
|
|
256
311
|
return tokenDetails;
|
|
257
312
|
}
|
|
258
313
|
|
|
314
|
+
/**
|
|
315
|
+
* Get contract information
|
|
316
|
+
*/
|
|
259
317
|
async getContractInfo(contractAddress: string): Promise<{name: string, symbol: string, totalSupply: string} | null> {
|
|
260
318
|
try {
|
|
261
319
|
const contract = new ethers.Contract(contractAddress, NZIP_CONTRACT_ABI, this.provider);
|
|
262
|
-
const [name, symbol, totalSupply] = await Promise.all([
|
|
320
|
+
const [name, symbol, totalSupply] = await Promise.all([
|
|
321
|
+
contract.name(),
|
|
322
|
+
contract.symbol(),
|
|
323
|
+
contract.totalSupply()
|
|
324
|
+
]);
|
|
263
325
|
return { name, symbol, totalSupply: totalSupply.toString() };
|
|
264
|
-
} catch {
|
|
326
|
+
} catch {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
265
329
|
}
|
|
266
330
|
|
|
331
|
+
/**
|
|
332
|
+
* Check for ERC20 tokens
|
|
333
|
+
*/
|
|
267
334
|
async checkERC20Tokens(ownerAddress: string, tokenConfigs: CommonTokenConfig[]): Promise<TokenInfo[]> {
|
|
268
335
|
const foundTokens: TokenInfo[] = [];
|
|
336
|
+
|
|
269
337
|
for (const tokenConfig of tokenConfigs.filter(t => t.type === 'ERC20')) {
|
|
270
338
|
try {
|
|
271
339
|
const contract = new ethers.Contract(tokenConfig.address, ERC20_ABI, this.provider);
|
|
272
340
|
const balance = await contract.balanceOf(ownerAddress);
|
|
341
|
+
|
|
273
342
|
if (balance > 0) {
|
|
274
343
|
let name = tokenConfig.name, symbol = tokenConfig.symbol, decimals = 18;
|
|
275
|
-
try {
|
|
344
|
+
try {
|
|
345
|
+
[name, symbol, decimals] = await Promise.all([
|
|
346
|
+
contract.name(),
|
|
347
|
+
contract.symbol(),
|
|
348
|
+
contract.decimals()
|
|
349
|
+
]);
|
|
350
|
+
} catch {}
|
|
351
|
+
|
|
276
352
|
const formattedBalance = ethers.formatUnits(balance, decimals);
|
|
277
|
-
foundTokens.push({
|
|
353
|
+
foundTokens.push({
|
|
354
|
+
address: tokenConfig.address,
|
|
355
|
+
name,
|
|
356
|
+
symbol,
|
|
357
|
+
balance: formattedBalance,
|
|
358
|
+
decimals,
|
|
359
|
+
type: 'ERC20'
|
|
360
|
+
});
|
|
278
361
|
}
|
|
279
362
|
} catch {}
|
|
280
363
|
}
|
|
364
|
+
|
|
281
365
|
return foundTokens;
|
|
282
366
|
}
|
|
283
367
|
|
|
368
|
+
/**
|
|
369
|
+
* Check for NFT collections
|
|
370
|
+
*/
|
|
284
371
|
async checkNFTCollections(ownerAddress: string, nftConfigs: CommonTokenConfig[]): Promise<TokenInfo[]> {
|
|
285
372
|
const foundNFTs: TokenInfo[] = [];
|
|
373
|
+
|
|
286
374
|
for (const nftConfig of nftConfigs) {
|
|
287
375
|
try {
|
|
288
376
|
const contract = new ethers.Contract(nftConfig.address, ERC721_ABI, this.provider);
|
|
289
377
|
const balance = await contract.balanceOf(ownerAddress);
|
|
378
|
+
|
|
290
379
|
if (balance > 0) {
|
|
291
380
|
let name = nftConfig.name, symbol = nftConfig.symbol;
|
|
292
|
-
try {
|
|
293
|
-
|
|
381
|
+
try {
|
|
382
|
+
[name, symbol] = await Promise.all([
|
|
383
|
+
contract.name(),
|
|
384
|
+
contract.symbol()
|
|
385
|
+
]);
|
|
386
|
+
} catch {}
|
|
387
|
+
|
|
388
|
+
foundNFTs.push({
|
|
389
|
+
address: nftConfig.address,
|
|
390
|
+
name,
|
|
391
|
+
symbol,
|
|
392
|
+
balance: balance.toString(),
|
|
393
|
+
type: 'ERC721'
|
|
394
|
+
});
|
|
294
395
|
}
|
|
295
396
|
} catch {}
|
|
296
397
|
}
|
|
398
|
+
|
|
297
399
|
return foundNFTs;
|
|
298
400
|
}
|
|
299
401
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
try { const deploymentInfo = JSON.parse(fs.readFileSync(deploymentPath, 'utf8')); if (deploymentInfo.address) return deploymentInfo.address; } catch {}
|
|
304
|
-
}
|
|
305
|
-
return undefined;
|
|
306
|
-
}
|
|
307
|
-
|
|
402
|
+
/**
|
|
403
|
+
* Get common token configurations for a network
|
|
404
|
+
*/
|
|
308
405
|
static getCommonTokens(network: string): CommonTokenConfig[] {
|
|
309
406
|
const commonTokens: Record<string, CommonTokenConfig[]> = {
|
|
310
407
|
'base-sepolia': [
|
|
@@ -323,6 +420,9 @@ export class WalletAnalyzer {
|
|
|
323
420
|
return commonTokens[network] || [];
|
|
324
421
|
}
|
|
325
422
|
|
|
423
|
+
/**
|
|
424
|
+
* Get common NFT configurations for a network
|
|
425
|
+
*/
|
|
326
426
|
static getCommonNFTs(network: string): CommonTokenConfig[] {
|
|
327
427
|
const commonNFTs: Record<string, CommonTokenConfig[]> = {
|
|
328
428
|
'base-sepolia': [ ],
|
|
@@ -334,5 +434,3 @@ export class WalletAnalyzer {
|
|
|
334
434
|
return commonNFTs[network] || [];
|
|
335
435
|
}
|
|
336
436
|
}
|
|
337
|
-
|
|
338
|
-
|