neozipkit 0.1.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 +371 -200
- 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 +256 -0
- 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/{browser → blockchain/browser}/TokenVerifierBrowser.d.ts +11 -20
- package/dist/blockchain/browser/TokenVerifierBrowser.d.ts.map +1 -0
- package/dist/{browser → blockchain/browser}/TokenVerifierBrowser.js +106 -92
- 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/{server/blockchain/WalletAnalyzer.d.ts → blockchain/core/WalletManager.d.ts} +69 -26
- package/dist/blockchain/core/WalletManager.d.ts.map +1 -0
- package/dist/{server/blockchain/WalletAnalyzer.js → blockchain/core/WalletManager.js} +172 -160
- package/dist/blockchain/core/WalletManager.js.map +1 -0
- package/dist/blockchain/core/ZipkitMinter.d.ts +141 -0
- 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/core/ZipkitOTS.d.ts +126 -0
- package/dist/blockchain/core/ZipkitOTS.d.ts.map +1 -0
- package/dist/blockchain/core/ZipkitOTS.js +506 -0
- 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 -0
- package/dist/blockchain/index.d.ts.map +1 -0
- package/dist/blockchain/index.js +34 -0
- 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 -17
- package/dist/browser.js +13 -29
- 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 +224 -81
- 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/{shared → core}/version.d.ts +1 -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 -25
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -47
- 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 +6 -3
- package/examples/verify-tokenized-zip.ts +305 -0
- package/package.json +117 -23
- package/src/blockchain/README.md +222 -0
- package/src/{browser → 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/core/WalletManager.ts +436 -0
- package/src/blockchain/core/ZipkitMinter.ts +716 -0
- package/src/blockchain/core/ZipkitOTS.ts +588 -0
- 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 +27 -0
- 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 +239 -89
- 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 -32
- 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/opentimestamps.d.ts +1 -23
- package/contracts/Lock.sol +0 -34
- package/contracts/bytecode.txt +0 -1
- package/contracts/compile-contract.js +0 -168
- package/contracts/deploy/deploy-both-contracts.js +0 -286
- package/contracts/deploy/deploy-enhanced-contract.js +0 -197
- package/contracts/deploy/deploy-private-contract.js +0 -190
- package/contracts/deploy/deploy-public-clean.js +0 -1063
- package/contracts/deploy/deploy-public-contract.js +0 -1107
- package/contracts/deployment.config.example.js +0 -25
- package/contracts/remix-compile.js +0 -222
- package/contracts/setup-deployment.js +0 -51
- package/contracts/src/ZipFileNFT-DEPRECATED-6field.sol +0 -260
- package/contracts/src/ZipFileNFT-DEPRECATED-Enhanced.sol +0 -289
- package/dist/browser/CertificateGeneratorBrowser.d.ts +0 -75
- package/dist/browser/CertificateGeneratorBrowser.js +0 -433
- 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 -21
- package/dist/browser-index.js +0 -58
- package/dist/server/blockchain/CertificateToken.d.ts +0 -48
- package/dist/server/blockchain/CertificateToken.js +0 -386
- package/dist/server/blockchain/NFTMinter.d.ts +0 -41
- package/dist/server/blockchain/NFTMinter.js +0 -323
- package/dist/server/blockchain/TokenQuerier.d.ts +0 -31
- package/dist/server/blockchain/TokenQuerier.js +0 -259
- package/dist/server/blockchain/TokenVerifier.d.ts +0 -20
- package/dist/server/blockchain/TokenVerifier.js +0 -395
- package/dist/server/blockchain/WalletFormatter.d.ts +0 -39
- package/dist/server/blockchain/WalletFormatter.js +0 -196
- package/dist/server/blockchain/WalletManager.d.ts +0 -46
- package/dist/server/blockchain/WalletManager.js +0 -294
- package/dist/server/blockchain/ZipMetadata.d.ts +0 -27
- package/dist/server/blockchain/ZipMetadata.js +0 -131
- package/dist/server/blockchain/ZipTokenProcessor.d.ts +0 -44
- package/dist/server/blockchain/ZipTokenProcessor.js +0 -204
- package/dist/server/blockchain/constants.d.ts +0 -102
- package/dist/server/blockchain/constants.js +0 -968
- package/dist/server/blockchain/index.d.ts +0 -9
- package/dist/server/blockchain/index.js +0 -44
- package/dist/server/blockchain/test-certificate.d.ts +0 -8
- package/dist/server/blockchain/test-certificate.js +0 -100
- package/dist/server/blockchain/types.d.ts +0 -69
- package/dist/server/blockchain/types.js +0 -51
- package/dist/server/platform/server/ZipKitServer.d.ts +0 -105
- package/dist/server/platform/server/ZipKitServer.js +0 -437
- package/dist/server/platform/servercomponents/ZipKitOTS.d.ts +0 -91
- package/dist/server/platform/servercomponents/ZipKitOTS.js +0 -271
- package/dist/shared/ZipKit.d.ts +0 -249
- package/dist/shared/ZipKit.js +0 -789
- 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.js +0 -7
- package/src/browser/CertificateGeneratorBrowser.ts +0 -498
- package/src/browser/ZipKitStampBrowser.ts +0 -9
- package/src/browser-index.ts +0 -36
- package/src/server/blockchain/CertificateToken.ts +0 -444
- package/src/server/blockchain/NFTMinter.ts +0 -357
- package/src/server/blockchain/TokenQuerier.ts +0 -287
- package/src/server/blockchain/TokenVerifier.ts +0 -453
- package/src/server/blockchain/WalletAnalyzer.ts +0 -397
- package/src/server/blockchain/WalletFormatter.ts +0 -206
- package/src/server/blockchain/WalletManager.ts +0 -294
- package/src/server/blockchain/ZipMetadata.ts +0 -117
- package/src/server/blockchain/ZipTokenProcessor.ts +0 -234
- package/src/server/blockchain/constants.ts +0 -969
- package/src/server/blockchain/index.ts +0 -42
- package/src/server/blockchain/test-certificate.ts +0 -137
- package/src/server/blockchain/types.ts +0 -134
- package/src/server/platform/server/ZipKitServer.ts +0 -459
- package/src/server/platform/servercomponents/ZipKitOTS.ts +0 -313
- package/src/server/platform/servercomponents/opentimestamps.d.ts +0 -23
- package/src/shared/ZipKit.ts +0 -899
- 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 -4
- /package/src/{shared → core}/components/Support.ts +0 -0
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core WalletManager - Platform-agnostic wallet functionality
|
|
3
|
+
* Provides core wallet operations that work in both browser and server environments
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ethers } from 'ethers';
|
|
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
|
+
}
|
|
38
|
+
|
|
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
|
+
}
|
|
49
|
+
|
|
50
|
+
const NZIP_CONTRACT_ABI = [
|
|
51
|
+
"function getZipFileInfo(uint256 tokenId) view returns (tuple(string merkleRootHash, string ipfsHash, address creator, uint256 creationTimestamp, uint256 tokenizationTime, uint256 blockNumber))",
|
|
52
|
+
"function ownerOf(uint256 tokenId) view returns (address)",
|
|
53
|
+
"function name() view returns (string)",
|
|
54
|
+
"function symbol() view returns (string)",
|
|
55
|
+
"function totalSupply() view returns (uint256)",
|
|
56
|
+
"function getTokensByMerkleRoot(string merkleRootHash) view returns (uint256[])",
|
|
57
|
+
"event ZipFileTokenized(uint256 indexed tokenId, address indexed creator, string merkleRootHash, uint256 creationTimestamp, string ipfsHash, uint256 tokenizationTime, uint256 blockNumber)"
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
const ERC20_ABI = [
|
|
61
|
+
"function balanceOf(address owner) view returns (uint256)",
|
|
62
|
+
"function name() view returns (string)",
|
|
63
|
+
"function symbol() view returns (string)",
|
|
64
|
+
"function decimals() view returns (uint8)"
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
const ERC721_ABI = [
|
|
68
|
+
"function balanceOf(address owner) view returns (uint256)",
|
|
69
|
+
"function name() view returns (string)",
|
|
70
|
+
"function symbol() view returns (string)",
|
|
71
|
+
"function tokenOfOwnerByIndex(address owner, uint256 index) view returns (uint256)"
|
|
72
|
+
];
|
|
73
|
+
|
|
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;
|
|
80
|
+
|
|
81
|
+
constructor() {}
|
|
82
|
+
|
|
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> {
|
|
94
|
+
try {
|
|
95
|
+
const networkConfig = NETWORKS[network] || NETWORKS['base-sepolia'];
|
|
96
|
+
|
|
97
|
+
this.wallet = new ethers.Wallet(privateKey);
|
|
98
|
+
Logger.log(`Using wallet: ${this.wallet.address}`);
|
|
99
|
+
|
|
100
|
+
const ok = await this.connectToNetwork(networkConfig, mintToken);
|
|
101
|
+
if (!ok) {
|
|
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
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
wallet: this.wallet,
|
|
112
|
+
provider: this.provider,
|
|
113
|
+
success: true,
|
|
114
|
+
message: `Wallet setup successful for ${networkConfig.name}`
|
|
115
|
+
};
|
|
116
|
+
} catch (error) {
|
|
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
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Connect to the specified network
|
|
129
|
+
*/
|
|
130
|
+
protected async connectToNetwork(networkConfig: NetworkConfig, mintToken: boolean): Promise<boolean> {
|
|
131
|
+
try {
|
|
132
|
+
Logger.log(`Attempting to connect to ${networkConfig.name} network...`);
|
|
133
|
+
this.provider = new ethers.JsonRpcProvider(networkConfig.rpcUrl);
|
|
134
|
+
|
|
135
|
+
let networkTimedOut = false;
|
|
136
|
+
const networkTimeout = setTimeout(() => {
|
|
137
|
+
networkTimedOut = true;
|
|
138
|
+
Logger.error("Network connection timeout");
|
|
139
|
+
}, 5000);
|
|
140
|
+
|
|
141
|
+
await Promise.race([
|
|
142
|
+
this.provider.getNetwork(),
|
|
143
|
+
new Promise((_, reject) =>
|
|
144
|
+
setTimeout(() => {
|
|
145
|
+
if (networkTimedOut) reject(new Error("Network connection timeout"));
|
|
146
|
+
}, 5100)
|
|
147
|
+
)
|
|
148
|
+
]);
|
|
149
|
+
|
|
150
|
+
clearTimeout(networkTimeout);
|
|
151
|
+
|
|
152
|
+
if (this.wallet) {
|
|
153
|
+
this.wallet = this.wallet.connect(this.provider);
|
|
154
|
+
const balance = await this.provider.getBalance(this.wallet.address);
|
|
155
|
+
const balanceEth = ethers.formatEther(balance);
|
|
156
|
+
Logger.log(`Wallet balance: ${balanceEth} ETH`);
|
|
157
|
+
|
|
158
|
+
const minBalance = 0.0001;
|
|
159
|
+
if (parseFloat(balanceEth) < minBalance && mintToken) {
|
|
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');
|
|
162
|
+
throw new Error(`Insufficient balance for minting. Current: ${balanceEth} ETH, Required: ${minBalance} ETH`);
|
|
163
|
+
} else if (mintToken) {
|
|
164
|
+
Logger.log(`✅ Sufficient balance for token minting`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
Logger.log(`✅ Successfully connected to ${networkConfig.name}`);
|
|
169
|
+
return true;
|
|
170
|
+
} catch (networkError: unknown) {
|
|
171
|
+
const errorMessage = networkError instanceof Error ? networkError.message : String(networkError);
|
|
172
|
+
Logger.error(`Failed to connect to ${networkConfig.name} network: ${errorMessage}`);
|
|
173
|
+
this.provider = null;
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
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
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Wallet analyzer for blockchain operations
|
|
209
|
+
*/
|
|
210
|
+
export class WalletAnalyzer {
|
|
211
|
+
private provider: ethers.JsonRpcProvider;
|
|
212
|
+
|
|
213
|
+
constructor(provider: ethers.JsonRpcProvider) {
|
|
214
|
+
this.provider = provider;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Get basic wallet information
|
|
219
|
+
*/
|
|
220
|
+
async getWalletBasics(address: string): Promise<WalletBasicInfo> {
|
|
221
|
+
const balance = await this.provider.getBalance(address);
|
|
222
|
+
const ethBalance = ethers.formatEther(balance);
|
|
223
|
+
const txCount = await this.provider.getTransactionCount(address);
|
|
224
|
+
const network = await this.provider.getNetwork();
|
|
225
|
+
const latestBlock = await this.provider.getBlockNumber();
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
ethBalance,
|
|
229
|
+
transactionCount: txCount,
|
|
230
|
+
networkName: network.name,
|
|
231
|
+
chainId: network.chainId,
|
|
232
|
+
latestBlock
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Scan for NZIP tokens owned by an address
|
|
238
|
+
*/
|
|
239
|
+
async scanForNZipTokens(contractAddress: string, ownerAddress: string): Promise<TokenScanResult> {
|
|
240
|
+
const contract = new ethers.Contract(contractAddress, NZIP_CONTRACT_ABI, this.provider);
|
|
241
|
+
let foundTokens: number[] = [];
|
|
242
|
+
let searchMethod: TokenScanResult['searchMethod'] = 'none';
|
|
243
|
+
|
|
244
|
+
try {
|
|
245
|
+
const latestBlock = await this.provider.getBlockNumber();
|
|
246
|
+
const startBlock = Math.max(0, latestBlock - 50000);
|
|
247
|
+
const filter = contract.filters.ZipFileTokenized(null, ownerAddress);
|
|
248
|
+
const events = await contract.queryFilter(filter, startBlock, 'latest');
|
|
249
|
+
|
|
250
|
+
for (const event of events) {
|
|
251
|
+
if ('args' in event && event.args && (event as any).args.tokenId) {
|
|
252
|
+
const tokenId = Number((event as any).args.tokenId);
|
|
253
|
+
if (!foundTokens.includes(tokenId)) foundTokens.push(tokenId);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (foundTokens.length > 0) {
|
|
258
|
+
return { foundTokens, searchMethod: 'recent-events' };
|
|
259
|
+
}
|
|
260
|
+
} catch {}
|
|
261
|
+
|
|
262
|
+
try {
|
|
263
|
+
const totalSupply = await contract.totalSupply();
|
|
264
|
+
const maxCheck = Math.min(Number(totalSupply), 50);
|
|
265
|
+
|
|
266
|
+
for (let tokenId = 0; tokenId < maxCheck; tokenId++) {
|
|
267
|
+
try {
|
|
268
|
+
const owner = await contract.ownerOf(tokenId);
|
|
269
|
+
if (owner.toLowerCase() === ownerAddress.toLowerCase()) foundTokens.push(tokenId);
|
|
270
|
+
} catch {}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (foundTokens.length > 0) return { foundTokens, searchMethod: 'iteration' };
|
|
274
|
+
} catch {}
|
|
275
|
+
|
|
276
|
+
const commonTokenIds = Array.from({length: 20}, (_, i) => i);
|
|
277
|
+
for (const tokenId of commonTokenIds) {
|
|
278
|
+
try {
|
|
279
|
+
const owner = await contract.ownerOf(tokenId);
|
|
280
|
+
if (owner.toLowerCase() === ownerAddress.toLowerCase()) foundTokens.push(tokenId);
|
|
281
|
+
} catch {}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return { foundTokens, searchMethod: foundTokens.length > 0 ? 'common-ids' : 'none' };
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Get detailed information for NZIP tokens
|
|
289
|
+
*/
|
|
290
|
+
async getNZipTokenDetails(contractAddress: string, tokenIds: number[]): Promise<NZipTokenDetails[]> {
|
|
291
|
+
const contract = new ethers.Contract(contractAddress, NZIP_CONTRACT_ABI, this.provider);
|
|
292
|
+
const tokenDetails: NZipTokenDetails[] = [];
|
|
293
|
+
|
|
294
|
+
for (const tokenId of tokenIds) {
|
|
295
|
+
try {
|
|
296
|
+
const zipInfo = await contract.getZipFileInfo(tokenId);
|
|
297
|
+
tokenDetails.push({
|
|
298
|
+
tokenId: tokenId.toString(),
|
|
299
|
+
merkleRootHash: zipInfo.merkleRootHash,
|
|
300
|
+
timestamp: Number(zipInfo.creationTimestamp),
|
|
301
|
+
creator: zipInfo.creator,
|
|
302
|
+
creationTimestamp: Number(zipInfo.creationTimestamp),
|
|
303
|
+
tokenizationTime: Number(zipInfo.tokenizationTime),
|
|
304
|
+
ipfsHash: zipInfo.ipfsHash || undefined
|
|
305
|
+
});
|
|
306
|
+
} catch (error) {
|
|
307
|
+
Logger.error(`Error fetching details for token ${tokenId}:`, error);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return tokenDetails;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Get contract information
|
|
316
|
+
*/
|
|
317
|
+
async getContractInfo(contractAddress: string): Promise<{name: string, symbol: string, totalSupply: string} | null> {
|
|
318
|
+
try {
|
|
319
|
+
const contract = new ethers.Contract(contractAddress, NZIP_CONTRACT_ABI, this.provider);
|
|
320
|
+
const [name, symbol, totalSupply] = await Promise.all([
|
|
321
|
+
contract.name(),
|
|
322
|
+
contract.symbol(),
|
|
323
|
+
contract.totalSupply()
|
|
324
|
+
]);
|
|
325
|
+
return { name, symbol, totalSupply: totalSupply.toString() };
|
|
326
|
+
} catch {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Check for ERC20 tokens
|
|
333
|
+
*/
|
|
334
|
+
async checkERC20Tokens(ownerAddress: string, tokenConfigs: CommonTokenConfig[]): Promise<TokenInfo[]> {
|
|
335
|
+
const foundTokens: TokenInfo[] = [];
|
|
336
|
+
|
|
337
|
+
for (const tokenConfig of tokenConfigs.filter(t => t.type === 'ERC20')) {
|
|
338
|
+
try {
|
|
339
|
+
const contract = new ethers.Contract(tokenConfig.address, ERC20_ABI, this.provider);
|
|
340
|
+
const balance = await contract.balanceOf(ownerAddress);
|
|
341
|
+
|
|
342
|
+
if (balance > 0) {
|
|
343
|
+
let name = tokenConfig.name, symbol = tokenConfig.symbol, decimals = 18;
|
|
344
|
+
try {
|
|
345
|
+
[name, symbol, decimals] = await Promise.all([
|
|
346
|
+
contract.name(),
|
|
347
|
+
contract.symbol(),
|
|
348
|
+
contract.decimals()
|
|
349
|
+
]);
|
|
350
|
+
} catch {}
|
|
351
|
+
|
|
352
|
+
const formattedBalance = ethers.formatUnits(balance, decimals);
|
|
353
|
+
foundTokens.push({
|
|
354
|
+
address: tokenConfig.address,
|
|
355
|
+
name,
|
|
356
|
+
symbol,
|
|
357
|
+
balance: formattedBalance,
|
|
358
|
+
decimals,
|
|
359
|
+
type: 'ERC20'
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
} catch {}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
return foundTokens;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Check for NFT collections
|
|
370
|
+
*/
|
|
371
|
+
async checkNFTCollections(ownerAddress: string, nftConfigs: CommonTokenConfig[]): Promise<TokenInfo[]> {
|
|
372
|
+
const foundNFTs: TokenInfo[] = [];
|
|
373
|
+
|
|
374
|
+
for (const nftConfig of nftConfigs) {
|
|
375
|
+
try {
|
|
376
|
+
const contract = new ethers.Contract(nftConfig.address, ERC721_ABI, this.provider);
|
|
377
|
+
const balance = await contract.balanceOf(ownerAddress);
|
|
378
|
+
|
|
379
|
+
if (balance > 0) {
|
|
380
|
+
let name = nftConfig.name, symbol = nftConfig.symbol;
|
|
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
|
+
});
|
|
395
|
+
}
|
|
396
|
+
} catch {}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return foundNFTs;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Get common token configurations for a network
|
|
404
|
+
*/
|
|
405
|
+
static getCommonTokens(network: string): CommonTokenConfig[] {
|
|
406
|
+
const commonTokens: Record<string, CommonTokenConfig[]> = {
|
|
407
|
+
'base-sepolia': [
|
|
408
|
+
{ address: '0x036CbD53842c5426634e7929541eC2318f3dCF7e', name: 'USD Coin', symbol: 'USDC', type: 'ERC20' },
|
|
409
|
+
{ address: '0x4200000000000000000000000000000000000006', name: 'Wrapped Ether', symbol: 'WETH', type: 'ERC20' },
|
|
410
|
+
{ address: '0xE4aB69C077896252FAFBD49EFD26B5D171A32410', name: 'Coinbase Wrapped Staked ETH', symbol: 'cbETH', type: 'ERC20' },
|
|
411
|
+
],
|
|
412
|
+
'base': [
|
|
413
|
+
{ address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', name: 'USD Coin', symbol: 'USDC', type: 'ERC20' },
|
|
414
|
+
{ address: '0x4200000000000000000000000000000000000006', name: 'Wrapped Ether', symbol: 'WETH', type: 'ERC20' },
|
|
415
|
+
{ address: '0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb', name: 'Dai Stablecoin', symbol: 'DAI', type: 'ERC20' },
|
|
416
|
+
{ address: '0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22', name: 'Coinbase Wrapped Staked ETH', symbol: 'cbETH', type: 'ERC20' },
|
|
417
|
+
{ address: '0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA', name: 'USD Base Coin', symbol: 'USDbC', type: 'ERC20' },
|
|
418
|
+
]
|
|
419
|
+
};
|
|
420
|
+
return commonTokens[network] || [];
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Get common NFT configurations for a network
|
|
425
|
+
*/
|
|
426
|
+
static getCommonNFTs(network: string): CommonTokenConfig[] {
|
|
427
|
+
const commonNFTs: Record<string, CommonTokenConfig[]> = {
|
|
428
|
+
'base-sepolia': [ ],
|
|
429
|
+
'base': [
|
|
430
|
+
{ address: '0x1234567890123456789012345678901234567890', name: 'Base Punks', symbol: 'BPUNK', type: 'ERC721' },
|
|
431
|
+
{ address: '0x0987654321098765432109876543210987654321', name: 'Base Bears', symbol: 'BBEAR', type: 'ERC721' },
|
|
432
|
+
]
|
|
433
|
+
};
|
|
434
|
+
return commonNFTs[network] || [];
|
|
435
|
+
}
|
|
436
|
+
}
|