neozipkit 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -105
- package/contracts/INTEGRATION.md +338 -0
- package/contracts/NETWORKS.md +156 -0
- package/contracts/README.md +152 -0
- package/{src/server/blockchain → contracts}/constants.ts +5 -22
- package/contracts/deploy-bytecode.mjs +94 -0
- package/dist/blockchain/ZipKitMinter.d.ts +106 -0
- package/dist/blockchain/ZipKitMinter.js +347 -0
- package/dist/blockchain/ZipKitNFT.d.ts +3 -0
- package/dist/blockchain/ZipKitNFT.js +7 -0
- package/dist/blockchain/ZipKitOTS.d.ts +135 -0
- package/dist/blockchain/ZipKitOTS.js +564 -0
- package/dist/blockchain/ZipKitVerifier.d.ts +69 -0
- package/dist/blockchain/ZipKitVerifier.js +289 -0
- package/dist/{server/blockchain/WalletAnalyzer.d.ts → blockchain/ZipKitWallet.d.ts} +31 -43
- package/dist/{server/blockchain/WalletAnalyzer.js → blockchain/ZipKitWallet.js} +193 -161
- package/dist/blockchain/contracts.d.ts +14 -0
- package/dist/blockchain/contracts.js +77 -0
- package/dist/blockchain/index.d.ts +7 -0
- package/dist/blockchain/index.js +50 -0
- package/dist/{server/blockchain → blockchain}/types.d.ts +12 -34
- package/dist/{server/blockchain → blockchain}/types.js +1 -22
- package/dist/browser-index.d.ts +0 -3
- package/dist/browser-index.js +4 -5
- package/dist/browser.d.ts +0 -3
- package/dist/browser.js +4 -5
- package/dist/index.d.ts +8 -15
- package/dist/index.js +12 -24
- package/dist/server/{platform/server/ZipKitServer.d.ts → ZipKitServer.d.ts} +4 -35
- package/dist/server/{platform/server/ZipKitServer.js → ZipKitServer.js} +55 -182
- package/dist/shared/ZipEntry.js +1 -1
- package/dist/shared/ZipKit.d.ts +0 -6
- package/dist/shared/ZipKit.js +1 -18
- package/dist/shared/types.js +2 -2
- package/dist/shared/version.d.ts +2 -4
- package/dist/shared/version.js +4 -5
- package/package.json +13 -3
- package/src/blockchain/README.md +229 -0
- package/src/blockchain/ZipKitMinter.ts +470 -0
- package/src/blockchain/ZipKitNFT.ts +12 -0
- package/src/blockchain/ZipKitOTS.ts +622 -0
- package/src/blockchain/ZipKitVerifier.ts +382 -0
- package/src/blockchain/ZipKitWallet.ts +338 -0
- package/src/blockchain/contracts.ts +88 -0
- package/src/blockchain/index.ts +61 -0
- package/src/blockchain/types.ts +91 -0
- package/src/browser/{TokenVerifierBrowser.ts → TokenVerifierBrowser.ts-remove} +1 -1
- package/src/browser-index.ts +3 -3
- package/src/index.ts +10 -17
- package/src/server/README.md +25 -0
- package/src/server/ZipKitServer.ts +305 -0
- package/src/shared/ZipEntry.ts +1 -1
- package/src/shared/ZipKit.ts +1 -19
- package/src/shared/types.ts +3 -3
- package/src/shared/version.ts +3 -4
- package/src/types/modules.d.ts +11 -1
- package/contracts/Lock.sol +0 -34
- 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/TokenVerifierBrowser.d.ts +0 -76
- package/dist/browser/TokenVerifierBrowser.js +0 -299
- 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/platform/servercomponents/ZipKitOTS.d.ts +0 -91
- package/dist/server/platform/servercomponents/ZipKitOTS.js +0 -271
- package/examples/unzip-token.ts +0 -488
- package/examples/zip-token.ts +0 -604
- 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/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/contracts/{bytecode.txt → NZIP-NFT-bytecode.txt} +0 -0
- /package/dist/{server/blockchain → blockchain}/CertificateToken.d.ts +0 -0
- /package/dist/{server/blockchain → blockchain}/CertificateToken.js +0 -0
- /package/src/{server/blockchain → blockchain}/CertificateToken.ts +0 -0
- /package/src/browser/{CertificateGeneratorBrowser.ts → CertificateGeneratorBrowser.ts-remove} +0 -0
package/README.md
CHANGED
|
@@ -56,6 +56,39 @@ for (const entry of entries) {
|
|
|
56
56
|
|
|
57
57
|
### Unified Directory Structure
|
|
58
58
|
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Merkle Root API (getMerkleRoot)
|
|
62
|
+
|
|
63
|
+
The `getMerkleRoot()` symbol is an instance method on `ZipKit`/`ZipKitServer` (not a top‑level export). Instantiate and call it on the object:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import ZipKitServer from 'neozipkit/server/platform/server/ZipKitServer';
|
|
67
|
+
|
|
68
|
+
// Load an existing ZIP from disk and compute Merkle Root (server/Node.js)
|
|
69
|
+
const zip = new ZipKitServer();
|
|
70
|
+
zip.loadUnzipFile('/path/to/archive.zip');
|
|
71
|
+
const merkleRoot = zip.getMerkleRoot(); // string | null
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Notes:
|
|
75
|
+
- `getMerkleRoot()` returns `null` if no entries are loaded or if entries don’t have `sha256` set.
|
|
76
|
+
- Ensure each content file has a SHA‑256 hash recorded:
|
|
77
|
+
- When creating ZIPs, set `useSHA256: true` in `CompressOptions` so hashes are written during compression.
|
|
78
|
+
- When reading existing ZIPs, calling `extract(entry)` will compute and set `entry.sha256` before you call `getMerkleRoot()`.
|
|
79
|
+
|
|
80
|
+
Example (creating and then reading back):
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import ZipKitServer, { CMP_METHOD } from 'neozipkit/server/platform/server/ZipKitServer';
|
|
84
|
+
|
|
85
|
+
const zk = new ZipKitServer();
|
|
86
|
+
// createZip uses CompressOptions internally; ensure useSHA256 when you pass options to compression
|
|
87
|
+
await zk.createZip('/tmp/out.zip', { level: 6, useSHA256: true, useZstd: false });
|
|
88
|
+
|
|
89
|
+
// Load file and compute
|
|
90
|
+
zk.loadUnzipFile('/tmp/out.zip');
|
|
91
|
+
const root = zk.getMerkleRoot();
|
|
59
92
|
```
|
|
60
93
|
packages/neozipkit/
|
|
61
94
|
├── src/ # TypeScript source files
|
|
@@ -85,7 +118,7 @@ packages/neozipkit/
|
|
|
85
118
|
│ ├── server/ # Server bundle
|
|
86
119
|
│ ├── shared/ # Shared code
|
|
87
120
|
│ └── index.js/.d.ts # Main bundle
|
|
88
|
-
├── contracts/ # Smart contracts
|
|
121
|
+
├── contracts/ # Smart contracts and documentation
|
|
89
122
|
├── examples/ # Usage examples
|
|
90
123
|
└── docs/ # Documentation
|
|
91
124
|
```
|
|
@@ -118,26 +151,11 @@ import { ZipKitOTS } from 'neozipkit/server/platform/servercomponents/ZipKitOTS'
|
|
|
118
151
|
|
|
119
152
|
## 🔗 Blockchain Integration
|
|
120
153
|
|
|
121
|
-
NeoZipKit includes comprehensive blockchain integration for creating and verifying tokenized ZIP files
|
|
122
|
-
|
|
123
|
-
### Supported Features
|
|
124
|
-
|
|
125
|
-
- **NFT Tokenization**: Convert ZIP files into ERC-721 NFTs with complete metadata
|
|
126
|
-
- **Blockchain Verification**: Verify ZIP file authenticity against blockchain tokens
|
|
127
|
-
- **OpenTimestamps**: Bitcoin blockchain timestamping for file integrity
|
|
128
|
-
- **Multi-Network Support**: Base Mainnet, Base Sepolia, Ethereum, Polygon, Arbitrum
|
|
129
|
-
- **Smart Contracts**: Production-ready contracts for public and private tokenization
|
|
154
|
+
NeoZipKit includes comprehensive blockchain integration for creating and verifying tokenized ZIP files.
|
|
130
155
|
|
|
131
|
-
|
|
156
|
+
**📄 For detailed information about smart contracts, deployment, and blockchain integration, see the [contracts documentation](./contracts/).**
|
|
132
157
|
|
|
133
|
-
|
|
134
|
-
- **`NFTMinter`** - Mint NFTs for ZIP files
|
|
135
|
-
- **`TokenQuerier`** - Query token information from blockchain
|
|
136
|
-
- **`CertificateToken`** - Generate certificates for tokenized files
|
|
137
|
-
- **`ZipTokenProcessor`** - Process ZIP files for tokenization
|
|
138
|
-
- **`WalletManager`** - Manage wallet connections and networks
|
|
139
|
-
|
|
140
|
-
### Usage Example
|
|
158
|
+
### Quick Example
|
|
141
159
|
|
|
142
160
|
```typescript
|
|
143
161
|
import { ZipTokenProcessor, MintingOptions } from 'neozipkit/server/blockchain';
|
|
@@ -150,60 +168,6 @@ const options: MintingOptions = {
|
|
|
150
168
|
|
|
151
169
|
const processor = new ZipTokenProcessor('archive.zip', 'merkle_root_hash', options);
|
|
152
170
|
const result = await processor.processZipToken(options);
|
|
153
|
-
|
|
154
|
-
if (result.error) {
|
|
155
|
-
console.error('Processing failed:', result.error);
|
|
156
|
-
} else {
|
|
157
|
-
console.log('Success!', result);
|
|
158
|
-
}
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
## 🎯 Smart Contracts
|
|
162
|
-
|
|
163
|
-
The package includes production-ready smart contracts for ZIP file tokenization:
|
|
164
|
-
|
|
165
|
-
### Contract Types
|
|
166
|
-
|
|
167
|
-
#### 🌐 Public Contract (`NZIP-NFT.sol`)
|
|
168
|
-
- **Universal verification** - Anyone can verify any token
|
|
169
|
-
- **Public blockchain metadata** - All data visible on blockchain
|
|
170
|
-
- **Use cases**: Certificates, public records, open-source projects
|
|
171
|
-
- **Symbol**: `NZIP`
|
|
172
|
-
|
|
173
|
-
#### 🔒 Private Contract (`NZIP-NFT-Private.sol`)
|
|
174
|
-
- **Owner-only verification** - Only token owners can verify their tokens
|
|
175
|
-
- **Private blockchain metadata** - Sensitive data hidden from public
|
|
176
|
-
- **Selective authorization** - Owners can authorize specific verifiers
|
|
177
|
-
- **Use cases**: Medical records, legal documents, private archives
|
|
178
|
-
- **Symbol**: `NZIPPRV`
|
|
179
|
-
|
|
180
|
-
### Current Deployment
|
|
181
|
-
|
|
182
|
-
**✅ Production Contract (v2.0)**:
|
|
183
|
-
```
|
|
184
|
-
Address: 0xFD76a5d420704F34d84b0767961835c43D7b30a8
|
|
185
|
-
Network: Base Sepolia
|
|
186
|
-
Version: 2.0.0
|
|
187
|
-
Status: ✅ ACTIVE - Use for all new integrations
|
|
188
|
-
Explorer: https://sepolia.basescan.org/address/0xFD76a5d420704F34d84b0767961835c43D7b30a8
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
### Contract Deployment
|
|
192
|
-
|
|
193
|
-
Deploy your own contracts using the included scripts:
|
|
194
|
-
|
|
195
|
-
```bash
|
|
196
|
-
# Setup deployment configuration
|
|
197
|
-
npm run setup-deployment
|
|
198
|
-
|
|
199
|
-
# Deploy both contracts (public + private)
|
|
200
|
-
npm run deploy:both
|
|
201
|
-
|
|
202
|
-
# Deploy only public contract
|
|
203
|
-
npm run deploy:public
|
|
204
|
-
|
|
205
|
-
# Deploy to mainnet
|
|
206
|
-
npm run deploy:both:mainnet
|
|
207
171
|
```
|
|
208
172
|
|
|
209
173
|
## 🔧 Development Workflow
|
|
@@ -233,6 +197,16 @@ This runs:
|
|
|
233
197
|
- **Output**: `./dist`
|
|
234
198
|
- **Declarations**: Generated alongside JavaScript files
|
|
235
199
|
|
|
200
|
+
### Version constants
|
|
201
|
+
|
|
202
|
+
Import the library version and release date anywhere in your app:
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
import { NEOZIPKIT_VERSION, NEOZIPKIT_RELEASE_DATE } from 'neozipkit';
|
|
206
|
+
|
|
207
|
+
console.log('NeoZipKit', NEOZIPKIT_VERSION, NEOZIPKIT_RELEASE_DATE);
|
|
208
|
+
```
|
|
209
|
+
|
|
236
210
|
## 📖 API Reference
|
|
237
211
|
|
|
238
212
|
### Core Classes
|
|
@@ -288,48 +262,21 @@ accumulator.addFile('example.txt', fileBuffer);
|
|
|
288
262
|
const merkleRoot = accumulator.finalize();
|
|
289
263
|
```
|
|
290
264
|
|
|
291
|
-
## 🌐 Network Support
|
|
292
|
-
|
|
293
|
-
### Supported Networks
|
|
294
265
|
|
|
295
|
-
- **Base Sepolia** (Chain ID: 84532) - Testing
|
|
296
|
-
- **Base Mainnet** (Chain ID: 8453) - Production
|
|
297
|
-
- **Ethereum Mainnet** - Production
|
|
298
|
-
- **Polygon** - Production
|
|
299
|
-
- **Arbitrum** - Production
|
|
300
|
-
|
|
301
|
-
### Network Configuration
|
|
302
|
-
|
|
303
|
-
```typescript
|
|
304
|
-
// Networks are configured in blockchain components
|
|
305
|
-
const networkConfig = {
|
|
306
|
-
'base': {
|
|
307
|
-
chainId: 8453,
|
|
308
|
-
rpcUrl: 'https://mainnet.base.org',
|
|
309
|
-
explorer: 'https://basescan.org'
|
|
310
|
-
},
|
|
311
|
-
'base-sepolia': {
|
|
312
|
-
chainId: 84532,
|
|
313
|
-
rpcUrl: 'https://sepolia.base.org',
|
|
314
|
-
explorer: 'https://sepolia.basescan.org'
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
```
|
|
318
266
|
|
|
319
267
|
## 🔐 Security Considerations
|
|
320
268
|
|
|
321
269
|
### Development Best Practices
|
|
322
270
|
|
|
323
|
-
- **Private Keys**: Never commit private keys or mnemonics to version control
|
|
324
|
-
- **Network Security**: Use secure RPC endpoints and validate all inputs
|
|
325
|
-
- **Smart Contract Audits**: Audit contracts before production deployment
|
|
326
271
|
- **Error Handling**: Implement comprehensive error handling for all operations
|
|
327
272
|
- **Type Safety**: Leverage TypeScript for compile-time error detection
|
|
273
|
+
- **Input Validation**: Validate all file inputs before processing
|
|
274
|
+
- **Memory Management**: Handle large ZIP files efficiently
|
|
328
275
|
|
|
329
276
|
### File Verification
|
|
330
277
|
|
|
331
278
|
- **Merkle Trees**: All ZIP files use cryptographic Merkle trees for integrity verification
|
|
332
|
-
- **
|
|
279
|
+
- **Hash Verification**: Multiple hash algorithms for file integrity checking
|
|
333
280
|
- **Multi-Layer Verification**: Support for both OpenTimestamps and NFT-based verification
|
|
334
281
|
|
|
335
282
|
## 📦 Dependencies
|
|
@@ -394,7 +341,7 @@ Ready to start using NeoZipKit? Here are some next steps:
|
|
|
394
341
|
1. **Install the package**: `yarn add neozipkit`
|
|
395
342
|
2. **Choose your use case**: Basic ZIP operations, OpenTimestamps, or NFT tokenization
|
|
396
343
|
3. **Follow the examples**: Check the `examples/` directory for complete implementations
|
|
397
|
-
4. **Deploy contracts**:
|
|
344
|
+
4. **Deploy contracts**: See [contracts documentation](./contracts/) for blockchain features
|
|
398
345
|
5. **Build something amazing**: Leverage the full power of blockchain-backed file verification
|
|
399
346
|
|
|
400
|
-
For detailed examples and advanced usage, explore the examples directory
|
|
347
|
+
For detailed examples and advanced usage, explore the examples directory. For blockchain integration, see the [contracts documentation](./contracts/).
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
# Contract Integration Guide
|
|
2
|
+
|
|
3
|
+
This guide shows how to integrate NeoZipKit smart contracts into your application.
|
|
4
|
+
|
|
5
|
+
## 🚀 Quick Integration
|
|
6
|
+
|
|
7
|
+
### Basic Setup
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { ZipTokenProcessor, MintingOptions } from 'neozipkit/server/blockchain';
|
|
11
|
+
|
|
12
|
+
// Configure minting options
|
|
13
|
+
const options: MintingOptions = {
|
|
14
|
+
contractAddress: 'YOUR_DEPLOYED_CONTRACT_ADDRESS',
|
|
15
|
+
network: 'base-sepolia',
|
|
16
|
+
mintToken: true
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Create processor
|
|
20
|
+
const processor = new ZipTokenProcessor('archive.zip', 'merkle_root_hash', options);
|
|
21
|
+
|
|
22
|
+
// Process and mint token
|
|
23
|
+
const result = await processor.processZipToken(options);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Environment Configuration
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Required environment variables
|
|
30
|
+
export RPC_URL="https://sepolia.base.org"
|
|
31
|
+
export NETWORK="base-sepolia"
|
|
32
|
+
export CONTRACT_ADDRESS="0xYourDeployedContractAddress"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 🔧 Core Components
|
|
36
|
+
|
|
37
|
+
### TokenVerifier
|
|
38
|
+
Verify tokenized ZIP files against blockchain:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { TokenVerifier } from 'neozipkit/server/blockchain/TokenVerifier';
|
|
42
|
+
|
|
43
|
+
const verifier = new TokenVerifier({
|
|
44
|
+
network: 'base-sepolia',
|
|
45
|
+
contractAddress: '0xYourContractAddress'
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const isValid = await verifier.verifyToken(tokenId, merkleRoot);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### NFTMinter
|
|
52
|
+
Mint NFTs for ZIP files:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { NFTMinter } from 'neozipkit/server/blockchain/NFTMinter';
|
|
56
|
+
|
|
57
|
+
const minter = new NFTMinter({
|
|
58
|
+
network: 'base-sepolia',
|
|
59
|
+
contractAddress: process.env.CONTRACT_ADDRESS
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const tokenId = await minter.mintToken({
|
|
63
|
+
to: '0xRecipientAddress',
|
|
64
|
+
merkleRoot: 'merkle_root_hash',
|
|
65
|
+
metadata: {
|
|
66
|
+
name: 'My ZIP Archive',
|
|
67
|
+
description: 'Tokenized ZIP file',
|
|
68
|
+
// ... additional metadata
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### TokenQuerier
|
|
74
|
+
Query token information from blockchain:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { TokenQuerier } from 'neozipkit/server/blockchain/TokenQuerier';
|
|
78
|
+
|
|
79
|
+
const querier = new TokenQuerier({
|
|
80
|
+
network: 'base-sepolia',
|
|
81
|
+
contractAddress: '0xYourContractAddress'
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Get token metadata
|
|
85
|
+
const metadata = await querier.getTokenMetadata(tokenId);
|
|
86
|
+
|
|
87
|
+
// Get token owner
|
|
88
|
+
const owner = await querier.getTokenOwner(tokenId);
|
|
89
|
+
|
|
90
|
+
// Check if token exists
|
|
91
|
+
const exists = await querier.tokenExists(tokenId);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### WalletManager
|
|
95
|
+
Manage wallet connections and networks:
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { WalletManager } from 'neozipkit/server/blockchain/WalletManager';
|
|
99
|
+
|
|
100
|
+
const walletManager = new WalletManager({
|
|
101
|
+
network: 'base-sepolia',
|
|
102
|
+
rpcUrl: process.env.RPC_URL
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Get wallet balance
|
|
106
|
+
const balance = await walletManager.getBalance();
|
|
107
|
+
|
|
108
|
+
// Get network information
|
|
109
|
+
const networkInfo = await walletManager.getNetworkInfo();
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 🌐 Browser Integration
|
|
113
|
+
|
|
114
|
+
### Browser-Compatible Components
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { TokenVerifierBrowser } from 'neozipkit/browser';
|
|
118
|
+
|
|
119
|
+
const verifier = new TokenVerifierBrowser({
|
|
120
|
+
network: 'base-sepolia',
|
|
121
|
+
rpcUrl: 'https://sepolia.base.org',
|
|
122
|
+
contractAddress: '0xYourContractAddress'
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Verify token (read-only operation)
|
|
126
|
+
const isValid = await verifier.verifyToken(tokenId, merkleRoot);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Web3 Wallet Integration
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
// Connect to user's wallet (MetaMask, etc.)
|
|
133
|
+
if (window.ethereum) {
|
|
134
|
+
const provider = new ethers.providers.Web3Provider(window.ethereum);
|
|
135
|
+
await provider.send("eth_requestAccounts", []);
|
|
136
|
+
|
|
137
|
+
const signer = provider.getSigner();
|
|
138
|
+
const userAddress = await signer.getAddress();
|
|
139
|
+
|
|
140
|
+
// Use with NeoZipKit components
|
|
141
|
+
const minter = new NFTMinter({
|
|
142
|
+
signer: signer,
|
|
143
|
+
contractAddress: process.env.CONTRACT_ADDRESS
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## 📝 Complete Example
|
|
149
|
+
|
|
150
|
+
### Server-Side Token Creation
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import {
|
|
154
|
+
ZipTokenProcessor,
|
|
155
|
+
NFTMinter,
|
|
156
|
+
TokenVerifier
|
|
157
|
+
} from 'neozipkit/server/blockchain';
|
|
158
|
+
|
|
159
|
+
async function createAndVerifyToken() {
|
|
160
|
+
try {
|
|
161
|
+
// 1. Process ZIP file and create Merkle root
|
|
162
|
+
const processor = new ZipTokenProcessor('archive.zip', null, {
|
|
163
|
+
network: 'base-sepolia',
|
|
164
|
+
contractAddress: process.env.CONTRACT_ADDRESS
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const { merkleRoot, zipHash } = await processor.generateHashes();
|
|
168
|
+
|
|
169
|
+
// 2. Mint NFT token
|
|
170
|
+
const minter = new NFTMinter({
|
|
171
|
+
network: 'base-sepolia',
|
|
172
|
+
contractAddress: process.env.CONTRACT_ADDRESS
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const tokenId = await minter.mintToken({
|
|
176
|
+
to: '0xRecipientAddress',
|
|
177
|
+
merkleRoot: merkleRoot,
|
|
178
|
+
metadata: {
|
|
179
|
+
name: 'Archive Token',
|
|
180
|
+
description: 'Verified ZIP archive',
|
|
181
|
+
zipHash: zipHash
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
console.log(`Token minted with ID: ${tokenId}`);
|
|
186
|
+
|
|
187
|
+
// 3. Verify the token
|
|
188
|
+
const verifier = new TokenVerifier({
|
|
189
|
+
network: 'base-sepolia',
|
|
190
|
+
contractAddress: process.env.CONTRACT_ADDRESS
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const isValid = await verifier.verifyToken(tokenId, merkleRoot);
|
|
194
|
+
console.log(`Token verification: ${isValid ? 'VALID' : 'INVALID'}`);
|
|
195
|
+
|
|
196
|
+
return { tokenId, merkleRoot, isValid };
|
|
197
|
+
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.error('Error creating token:', error);
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Client-Side Token Verification
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
import { TokenVerifierBrowser } from 'neozipkit/browser';
|
|
209
|
+
|
|
210
|
+
async function verifyTokenFromBrowser(tokenId: string, merkleRoot: string) {
|
|
211
|
+
const verifier = new TokenVerifierBrowser({
|
|
212
|
+
network: 'base-sepolia',
|
|
213
|
+
rpcUrl: 'https://sepolia.base.org',
|
|
214
|
+
contractAddress: '0xYourContractAddress'
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
try {
|
|
218
|
+
const isValid = await verifier.verifyToken(tokenId, merkleRoot);
|
|
219
|
+
|
|
220
|
+
if (isValid) {
|
|
221
|
+
console.log('✅ Token is valid and verified on blockchain');
|
|
222
|
+
} else {
|
|
223
|
+
console.log('❌ Token verification failed');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return isValid;
|
|
227
|
+
|
|
228
|
+
} catch (error) {
|
|
229
|
+
console.error('Verification error:', error);
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## 🔒 Security Best Practices
|
|
236
|
+
|
|
237
|
+
### Contract Address Management
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
// ✅ DO: Use environment variables for contract addresses
|
|
241
|
+
const contractAddress = process.env.CONTRACT_ADDRESS;
|
|
242
|
+
|
|
243
|
+
// ✅ DO: Validate contract addresses
|
|
244
|
+
import { ethers } from 'ethers';
|
|
245
|
+
if (!ethers.utils.isAddress(contractAddress)) {
|
|
246
|
+
throw new Error('Invalid contract address');
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Input Validation
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
import { ethers } from 'ethers';
|
|
254
|
+
|
|
255
|
+
function validateInputs(tokenId: string, address: string) {
|
|
256
|
+
// Validate token ID
|
|
257
|
+
if (!tokenId || !/^\d+$/.test(tokenId)) {
|
|
258
|
+
throw new Error('Invalid token ID');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Validate Ethereum address
|
|
262
|
+
if (!ethers.utils.isAddress(address)) {
|
|
263
|
+
throw new Error('Invalid Ethereum address');
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Error Handling
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
async function safeTokenOperation() {
|
|
272
|
+
try {
|
|
273
|
+
const result = await processor.processZipToken(options);
|
|
274
|
+
return result;
|
|
275
|
+
} catch (error) {
|
|
276
|
+
if (error.code === 'NETWORK_ERROR') {
|
|
277
|
+
console.error('Network connectivity issue');
|
|
278
|
+
} else if (error.code === 'CONTRACT_ERROR') {
|
|
279
|
+
console.error('Contract interaction failed');
|
|
280
|
+
} else {
|
|
281
|
+
console.error('Unexpected error:', error.message);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Log error for monitoring
|
|
285
|
+
logger.error('Token operation failed', { error, options });
|
|
286
|
+
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## 📊 Monitoring and Analytics
|
|
293
|
+
|
|
294
|
+
### Event Listening
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
import { ethers } from 'ethers';
|
|
298
|
+
|
|
299
|
+
// Listen for token mint events
|
|
300
|
+
const contract = new ethers.Contract(contractAddress, abi, provider);
|
|
301
|
+
|
|
302
|
+
contract.on('Transfer', (from, to, tokenId) => {
|
|
303
|
+
if (from === ethers.constants.AddressZero) {
|
|
304
|
+
console.log(`New token minted: ${tokenId} to ${to}`);
|
|
305
|
+
// Log to analytics
|
|
306
|
+
analytics.track('token_minted', { tokenId, recipient: to });
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Health Monitoring
|
|
312
|
+
|
|
313
|
+
```typescript
|
|
314
|
+
async function checkContractHealth() {
|
|
315
|
+
try {
|
|
316
|
+
const querier = new TokenQuerier({
|
|
317
|
+
network: process.env.NETWORK,
|
|
318
|
+
contractAddress: process.env.CONTRACT_ADDRESS
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// Check if contract is responding
|
|
322
|
+
const totalSupply = await querier.getTotalSupply();
|
|
323
|
+
|
|
324
|
+
return {
|
|
325
|
+
status: 'healthy',
|
|
326
|
+
totalSupply: totalSupply,
|
|
327
|
+
timestamp: new Date().toISOString()
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
} catch (error) {
|
|
331
|
+
return {
|
|
332
|
+
status: 'unhealthy',
|
|
333
|
+
error: error.message,
|
|
334
|
+
timestamp: new Date().toISOString()
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
```
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Network Support
|
|
2
|
+
|
|
3
|
+
NeoZipKit smart contracts support multiple Ethereum-compatible networks for both testing and production use.
|
|
4
|
+
|
|
5
|
+
## 🌐 Supported Networks
|
|
6
|
+
|
|
7
|
+
### Testing Networks
|
|
8
|
+
|
|
9
|
+
#### Base Sepolia (Recommended for Testing)
|
|
10
|
+
- **Chain ID**: 84532
|
|
11
|
+
- **RPC URL**: https://sepolia.base.org
|
|
12
|
+
- **Explorer**: https://sepolia.basescan.org
|
|
13
|
+
- **Faucet**: https://bridge.base.org/deposit
|
|
14
|
+
- **Gas Token**: ETH (Sepolia)
|
|
15
|
+
- **Use Case**: Development and testing
|
|
16
|
+
|
|
17
|
+
### Production Networks
|
|
18
|
+
|
|
19
|
+
#### Base Mainnet (Recommended for Production)
|
|
20
|
+
- **Chain ID**: 8453
|
|
21
|
+
- **RPC URL**: https://mainnet.base.org
|
|
22
|
+
- **Explorer**: https://basescan.org
|
|
23
|
+
- **Gas Token**: ETH
|
|
24
|
+
- **Use Case**: Production deployments
|
|
25
|
+
|
|
26
|
+
#### Ethereum Mainnet
|
|
27
|
+
- **Chain ID**: 1
|
|
28
|
+
- **RPC URL**: https://mainnet.infura.io/v3/YOUR-PROJECT-ID
|
|
29
|
+
- **Explorer**: https://etherscan.io
|
|
30
|
+
- **Gas Token**: ETH
|
|
31
|
+
- **Use Case**: High-security production deployments
|
|
32
|
+
|
|
33
|
+
#### Polygon
|
|
34
|
+
- **Chain ID**: 137
|
|
35
|
+
- **RPC URL**: https://polygon-rpc.com
|
|
36
|
+
- **Explorer**: https://polygonscan.com
|
|
37
|
+
- **Gas Token**: MATIC
|
|
38
|
+
- **Use Case**: Low-cost production deployments
|
|
39
|
+
|
|
40
|
+
#### Arbitrum One
|
|
41
|
+
- **Chain ID**: 42161
|
|
42
|
+
- **RPC URL**: https://arb1.arbitrum.io/rpc
|
|
43
|
+
- **Explorer**: https://arbiscan.io
|
|
44
|
+
- **Gas Token**: ETH
|
|
45
|
+
- **Use Case**: Fast, low-cost production deployments
|
|
46
|
+
|
|
47
|
+
## ⚙️ Network Configuration
|
|
48
|
+
|
|
49
|
+
### JavaScript/TypeScript Configuration
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
// Networks are configured in blockchain components
|
|
53
|
+
const networkConfig = {
|
|
54
|
+
'base': {
|
|
55
|
+
chainId: 8453,
|
|
56
|
+
rpcUrl: 'https://mainnet.base.org',
|
|
57
|
+
explorer: 'https://basescan.org'
|
|
58
|
+
},
|
|
59
|
+
'base-sepolia': {
|
|
60
|
+
chainId: 84532,
|
|
61
|
+
rpcUrl: 'https://sepolia.base.org',
|
|
62
|
+
explorer: 'https://sepolia.basescan.org'
|
|
63
|
+
},
|
|
64
|
+
'ethereum': {
|
|
65
|
+
chainId: 1,
|
|
66
|
+
rpcUrl: 'https://mainnet.infura.io/v3/YOUR-PROJECT-ID',
|
|
67
|
+
explorer: 'https://etherscan.io'
|
|
68
|
+
},
|
|
69
|
+
'polygon': {
|
|
70
|
+
chainId: 137,
|
|
71
|
+
rpcUrl: 'https://polygon-rpc.com',
|
|
72
|
+
explorer: 'https://polygonscan.com'
|
|
73
|
+
},
|
|
74
|
+
'arbitrum': {
|
|
75
|
+
chainId: 42161,
|
|
76
|
+
rpcUrl: 'https://arb1.arbitrum.io/rpc',
|
|
77
|
+
explorer: 'https://arbiscan.io'
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Environment Configuration
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Base Sepolia (Testing)
|
|
86
|
+
export NETWORK="base-sepolia"
|
|
87
|
+
export RPC_URL="https://sepolia.base.org"
|
|
88
|
+
export CHAIN_ID="84532"
|
|
89
|
+
|
|
90
|
+
# Base Mainnet (Production)
|
|
91
|
+
export NETWORK="base-mainnet"
|
|
92
|
+
export RPC_URL="https://mainnet.base.org"
|
|
93
|
+
export CHAIN_ID="8453"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## 💰 Gas Costs Comparison
|
|
97
|
+
|
|
98
|
+
| Network | Average Gas Price | Contract Deployment Cost | Token Mint Cost |
|
|
99
|
+
|---------|------------------|-------------------------|-----------------|
|
|
100
|
+
| Base Sepolia | ~0.001 gwei | ~$0.01 | ~$0.001 |
|
|
101
|
+
| Base Mainnet | ~0.01 gwei | ~$0.10 | ~$0.01 |
|
|
102
|
+
| Ethereum | ~20 gwei | ~$50-200 | ~$10-50 |
|
|
103
|
+
| Polygon | ~30 gwei | ~$0.05 | ~$0.01 |
|
|
104
|
+
| Arbitrum | ~0.1 gwei | ~$1-5 | ~$0.25 |
|
|
105
|
+
|
|
106
|
+
*Costs are approximate and vary based on network congestion*
|
|
107
|
+
|
|
108
|
+
## 🔧 Setup Instructions
|
|
109
|
+
|
|
110
|
+
### 1. Choose Your Network
|
|
111
|
+
|
|
112
|
+
For development: **Base Sepolia**
|
|
113
|
+
For production: **Base Mainnet** or **Ethereum**
|
|
114
|
+
|
|
115
|
+
### 2. Get Test Tokens (for testnets)
|
|
116
|
+
|
|
117
|
+
**Base Sepolia**:
|
|
118
|
+
1. Visit https://bridge.base.org/deposit
|
|
119
|
+
2. Connect your wallet
|
|
120
|
+
3. Bridge Ethereum Sepolia ETH to Base Sepolia
|
|
121
|
+
|
|
122
|
+
### 3. Configure RPC Endpoints
|
|
123
|
+
|
|
124
|
+
**Recommended RPC Providers**:
|
|
125
|
+
- **Alchemy**: https://dashboard.alchemy.com/
|
|
126
|
+
- **Infura**: https://infura.io/
|
|
127
|
+
- **QuickNode**: https://quicknode.com/
|
|
128
|
+
- **Public RPCs**: Use for testing only
|
|
129
|
+
|
|
130
|
+
### 4. Update Application Configuration
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { WalletManager } from 'neozipkit/server/blockchain';
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
## 🚨 Important Notes
|
|
137
|
+
|
|
138
|
+
### Testnet Limitations
|
|
139
|
+
- **No real value**: Testnet tokens have no monetary value
|
|
140
|
+
- **Reset periodically**: Testnet data may be wiped
|
|
141
|
+
- **Limited faucets**: May have daily limits for test tokens
|
|
142
|
+
|
|
143
|
+
### Mainnet Considerations
|
|
144
|
+
- **Real costs**: All transactions cost real money
|
|
145
|
+
- **Irreversible**: Mistakes cannot be undone
|
|
146
|
+
- **Security critical**: Use secure key management
|
|
147
|
+
- **Audit first**: Thoroughly test on testnets before mainnet
|
|
148
|
+
|
|
149
|
+
### Network Selection Guidelines
|
|
150
|
+
|
|
151
|
+
- **Development**: Use Base Sepolia for fastest, cheapest testing
|
|
152
|
+
- **Staging**: Use Base Sepolia or Ethereum Sepolia for final testing
|
|
153
|
+
- **Production**: Choose based on cost, speed, and security requirements
|
|
154
|
+
- **High security**: Ethereum Mainnet
|
|
155
|
+
- **Balanced**: Base Mainnet
|
|
156
|
+
- **Low cost**: Polygon or Arbitrum
|