neozipkit 0.1.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 +400 -0
- package/contracts/Lock.sol +34 -0
- package/contracts/bytecode.txt +1 -0
- package/contracts/compile-contract.js +168 -0
- package/contracts/deploy/deploy-both-contracts.js +286 -0
- package/contracts/deploy/deploy-enhanced-contract.js +197 -0
- package/contracts/deploy/deploy-private-contract.js +190 -0
- package/contracts/deploy/deploy-public-clean.js +1063 -0
- package/contracts/deploy/deploy-public-contract.js +1107 -0
- package/contracts/deployment.config.example.js +25 -0
- package/contracts/remix-compile.js +222 -0
- package/contracts/setup-deployment.js +51 -0
- package/contracts/src/NZIP-NFT-Private.sol +350 -0
- package/contracts/src/NZIP-NFT.sol +265 -0
- package/contracts/src/ZipFileNFT-DEPRECATED-6field.sol +260 -0
- package/contracts/src/ZipFileNFT-DEPRECATED-Enhanced.sol +289 -0
- package/dist/browser/CertificateGeneratorBrowser.d.ts +75 -0
- package/dist/browser/CertificateGeneratorBrowser.js +433 -0
- package/dist/browser/TokenVerifierBrowser.d.ts +76 -0
- package/dist/browser/TokenVerifierBrowser.js +299 -0
- package/dist/browser/ZipKitBrowser.d.ts +18 -0
- package/dist/browser/ZipKitBrowser.js +250 -0
- package/dist/browser/ZipKitStampBrowser.d.ts +2 -0
- package/dist/browser/ZipKitStampBrowser.js +12 -0
- package/dist/browser-index.d.ts +21 -0
- package/dist/browser-index.js +58 -0
- package/dist/browser.d.ts +21 -0
- package/dist/browser.js +58 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +76 -0
- package/dist/server/blockchain/CertificateToken.d.ts +48 -0
- package/dist/server/blockchain/CertificateToken.js +386 -0
- package/dist/server/blockchain/NFTMinter.d.ts +41 -0
- package/dist/server/blockchain/NFTMinter.js +323 -0
- package/dist/server/blockchain/TokenQuerier.d.ts +31 -0
- package/dist/server/blockchain/TokenQuerier.js +259 -0
- package/dist/server/blockchain/TokenVerifier.d.ts +20 -0
- package/dist/server/blockchain/TokenVerifier.js +395 -0
- package/dist/server/blockchain/WalletAnalyzer.d.ts +81 -0
- package/dist/server/blockchain/WalletAnalyzer.js +356 -0
- package/dist/server/blockchain/WalletFormatter.d.ts +39 -0
- package/dist/server/blockchain/WalletFormatter.js +196 -0
- package/dist/server/blockchain/WalletManager.d.ts +46 -0
- package/dist/server/blockchain/WalletManager.js +294 -0
- package/dist/server/blockchain/ZipMetadata.d.ts +27 -0
- package/dist/server/blockchain/ZipMetadata.js +131 -0
- package/dist/server/blockchain/ZipTokenProcessor.d.ts +44 -0
- package/dist/server/blockchain/ZipTokenProcessor.js +204 -0
- package/dist/server/blockchain/constants.d.ts +102 -0
- package/dist/server/blockchain/constants.js +968 -0
- package/dist/server/blockchain/index.d.ts +9 -0
- package/dist/server/blockchain/index.js +44 -0
- package/dist/server/blockchain/test-certificate.d.ts +8 -0
- package/dist/server/blockchain/test-certificate.js +100 -0
- package/dist/server/blockchain/types.d.ts +69 -0
- package/dist/server/blockchain/types.js +51 -0
- package/dist/server/platform/server/ZipKitServer.d.ts +105 -0
- package/dist/server/platform/server/ZipKitServer.js +437 -0
- package/dist/server/platform/servercomponents/ZipKitOTS.d.ts +91 -0
- package/dist/server/platform/servercomponents/ZipKitOTS.js +271 -0
- package/dist/shared/ZipEntry.d.ts +131 -0
- package/dist/shared/ZipEntry.js +686 -0
- package/dist/shared/ZipKit.d.ts +249 -0
- package/dist/shared/ZipKit.js +789 -0
- package/dist/shared/components/CertificateOTS.d.ts +15 -0
- package/dist/shared/components/CertificateOTS.js +116 -0
- package/dist/shared/components/FileSys.d.ts +2 -0
- package/dist/shared/components/FileSys.js +113 -0
- package/dist/shared/components/HashAccumulator.d.ts +55 -0
- package/dist/shared/components/HashAccumulator.js +100 -0
- package/dist/shared/components/Support.d.ts +63 -0
- package/dist/shared/components/Support.js +70 -0
- package/dist/shared/components/Util.d.ts +21 -0
- package/dist/shared/components/Util.js +115 -0
- package/dist/shared/components/ZipCrypto.d.ts +3 -0
- package/dist/shared/components/ZipCrypto.js +78 -0
- package/dist/shared/components/merkleTree.d.ts +66 -0
- package/dist/shared/components/merkleTree.js +136 -0
- package/dist/shared/constants/Errors.d.ts +53 -0
- package/dist/shared/constants/Errors.js +69 -0
- package/dist/shared/constants/Headers.d.ts +167 -0
- package/dist/shared/constants/Headers.js +191 -0
- package/dist/shared/types/index.d.ts +21 -0
- package/dist/shared/types/index.js +3 -0
- package/dist/shared/types.d.ts +33 -0
- package/dist/shared/types.js +8 -0
- package/dist/shared/version.d.ts +4 -0
- package/dist/shared/version.js +7 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/index.js +3 -0
- package/examples/unzip-token.ts +488 -0
- package/examples/zip-token.ts +604 -0
- package/package.json +117 -0
- package/src/browser/CertificateGeneratorBrowser.ts +498 -0
- package/src/browser/TokenVerifierBrowser.ts +344 -0
- package/src/browser/ZipKitBrowser.ts +242 -0
- package/src/browser/ZipKitStampBrowser.ts +9 -0
- package/src/browser-index.ts +36 -0
- package/src/index.ts +48 -0
- package/src/server/blockchain/CertificateToken.ts +444 -0
- package/src/server/blockchain/NFTMinter.ts +357 -0
- package/src/server/blockchain/TokenQuerier.ts +287 -0
- package/src/server/blockchain/TokenVerifier.ts +453 -0
- package/src/server/blockchain/WalletAnalyzer.ts +397 -0
- package/src/server/blockchain/WalletFormatter.ts +206 -0
- package/src/server/blockchain/WalletManager.ts +294 -0
- package/src/server/blockchain/ZipMetadata.ts +117 -0
- package/src/server/blockchain/ZipTokenProcessor.ts +234 -0
- package/src/server/blockchain/constants.ts +969 -0
- package/src/server/blockchain/index.ts +42 -0
- package/src/server/blockchain/test-certificate.ts +137 -0
- package/src/server/blockchain/types.ts +134 -0
- package/src/server/platform/server/ZipKitServer.ts +459 -0
- package/src/server/platform/servercomponents/ZipKitOTS.ts +313 -0
- package/src/server/platform/servercomponents/opentimestamps.d.ts +23 -0
- package/src/shared/ZipEntry.ts +767 -0
- package/src/shared/ZipKit.ts +899 -0
- package/src/shared/components/CertificateOTS.ts +132 -0
- package/src/shared/components/FileSys.ts +87 -0
- package/src/shared/components/HashAccumulator.ts +113 -0
- package/src/shared/components/Support.ts +77 -0
- package/src/shared/components/Util.ts +113 -0
- package/src/shared/components/ZipCrypto.ts +91 -0
- package/src/shared/components/merkleTree.ts +162 -0
- package/src/shared/constants/Errors.ts +82 -0
- package/src/shared/constants/Headers.ts +203 -0
- package/src/shared/types/index.ts +25 -0
- package/src/shared/types/modules.d.ts +22 -0
- package/src/shared/types/opentimestamps.d.ts +23 -0
- package/src/shared/types.d.ts +8 -0
- package/src/shared/types.ts +43 -0
- package/src/shared/version.ts +4 -0
- package/src/types/index.ts +25 -0
- package/src/types/modules.d.ts +22 -0
- package/src/types/opentimestamps.d.ts +23 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.NFTMinter = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const ethers_1 = require("ethers");
|
|
40
|
+
const types_1 = require("./types");
|
|
41
|
+
class NFTMinter {
|
|
42
|
+
constructor(wallet, provider) {
|
|
43
|
+
this.wallet = wallet;
|
|
44
|
+
this.provider = provider;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates NFT metadata for the ZIP archive
|
|
48
|
+
*/
|
|
49
|
+
createNFTMetadata(zipTokenData) {
|
|
50
|
+
const metadata = { ...types_1.NFT_METADATA_TEMPLATE };
|
|
51
|
+
metadata.name = `${zipTokenData.fileName} Archive`;
|
|
52
|
+
metadata.description = `Verified archive created on ${zipTokenData.timestamp}`;
|
|
53
|
+
metadata.attributes[0].value = zipTokenData.merkleRoot;
|
|
54
|
+
metadata.attributes[1].value = zipTokenData.timestamp;
|
|
55
|
+
return metadata;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Loads contract deployment information
|
|
59
|
+
*/
|
|
60
|
+
loadContractInfo() {
|
|
61
|
+
try {
|
|
62
|
+
const contractInfoPath = path.join(process.cwd(), 'zipfile-nft-deployment.json');
|
|
63
|
+
if (!fs.existsSync(contractInfoPath)) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const contractInfo = JSON.parse(fs.readFileSync(contractInfoPath, 'utf8'));
|
|
67
|
+
return contractInfo;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error('Error loading contract info:', error);
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Check for existing tokens with the same merkle root
|
|
76
|
+
* This is efficient because it uses the contract's getTokensByMerkleRoot function
|
|
77
|
+
*/
|
|
78
|
+
async findExistingTokensByMerkleRoot(merkleRoot) {
|
|
79
|
+
if (!this.provider || !this.wallet) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const contractInfo = this.loadContractInfo();
|
|
84
|
+
if (!contractInfo) {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
console.log(`🔍 Checking for existing tokens with merkle root: ${merkleRoot}`);
|
|
88
|
+
const contract = new ethers_1.ethers.Contract(contractInfo.address, contractInfo.abi, this.provider);
|
|
89
|
+
// Use the efficient contract function to get tokens by merkle root
|
|
90
|
+
const tokenIds = await contract.getTokensByMerkleRoot(merkleRoot);
|
|
91
|
+
if (tokenIds.length === 0) {
|
|
92
|
+
console.log(` ✅ No existing tokens found for this content`);
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
console.log(` 📋 Found ${tokenIds.length} existing token(s) for this content:`);
|
|
96
|
+
const existingTokens = [];
|
|
97
|
+
for (const tokenId of tokenIds) {
|
|
98
|
+
try {
|
|
99
|
+
// Get token info
|
|
100
|
+
const zipInfo = await contract.getZipFileInfo(tokenId);
|
|
101
|
+
const owner = await contract.ownerOf(tokenId);
|
|
102
|
+
const tokenInfo = {
|
|
103
|
+
tokenId: tokenId.toString(),
|
|
104
|
+
fileName: zipInfo.fileName,
|
|
105
|
+
merkleRootHash: zipInfo.merkleRootHash,
|
|
106
|
+
creationTimestamp: Number(zipInfo.creationTimestamp),
|
|
107
|
+
tokenizationTime: Number(zipInfo.tokenizationTime),
|
|
108
|
+
creator: zipInfo.creator,
|
|
109
|
+
isOwnedByWallet: owner.toLowerCase() === this.wallet.address.toLowerCase()
|
|
110
|
+
};
|
|
111
|
+
existingTokens.push(tokenInfo);
|
|
112
|
+
const ownershipStatus = tokenInfo.isOwnedByWallet ? "👤 (owned by you)" : `👥 (owned by ${owner})`;
|
|
113
|
+
const createdDate = new Date(tokenInfo.creationTimestamp * 1000).toISOString();
|
|
114
|
+
const mintedDate = new Date(tokenInfo.tokenizationTime * 1000).toISOString();
|
|
115
|
+
console.log(` 📄 Token ID ${tokenInfo.tokenId}: ${tokenInfo.fileName}`);
|
|
116
|
+
console.log(` Created: ${createdDate}`);
|
|
117
|
+
console.log(` Minted: ${mintedDate}`);
|
|
118
|
+
console.log(` Owner: ${ownershipStatus}`);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
console.warn(` ⚠️ Could not retrieve info for token ${tokenId}: ${error}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return existingTokens;
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.warn(`Error checking for existing tokens: ${error}`);
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Prompts user to choose between reusing an existing timestamp or creating a new token
|
|
133
|
+
*/
|
|
134
|
+
async promptUserChoice(existingTokens, fileName) {
|
|
135
|
+
return new Promise((resolve) => {
|
|
136
|
+
const readline = require('readline');
|
|
137
|
+
const rl = readline.createInterface({
|
|
138
|
+
input: process.stdin,
|
|
139
|
+
output: process.stdout
|
|
140
|
+
});
|
|
141
|
+
console.log('\n🤔 What would you like to do?');
|
|
142
|
+
console.log('═'.repeat(60));
|
|
143
|
+
console.log('1. Create a new token with current timestamp (recommended)');
|
|
144
|
+
// Show existing tokens as options
|
|
145
|
+
existingTokens.forEach((token, index) => {
|
|
146
|
+
const createdDate = new Date(token.creationTimestamp * 1000).toLocaleString();
|
|
147
|
+
const ownershipNote = token.isOwnedByWallet ? ' (you own this)' : ` (owned by ${token.creator.slice(0, 8)}...)`;
|
|
148
|
+
console.log(`${index + 2}. Reuse timestamp from Token ${token.tokenId}: ${createdDate}${ownershipNote}`);
|
|
149
|
+
});
|
|
150
|
+
console.log('═'.repeat(60));
|
|
151
|
+
rl.question('Enter your choice (1-' + (existingTokens.length + 1) + '): ', (answer) => {
|
|
152
|
+
rl.close();
|
|
153
|
+
const choice = parseInt(answer.trim());
|
|
154
|
+
if (choice === 1) {
|
|
155
|
+
resolve({ useExisting: false });
|
|
156
|
+
}
|
|
157
|
+
else if (choice >= 2 && choice <= existingTokens.length + 1) {
|
|
158
|
+
const selectedToken = existingTokens[choice - 2];
|
|
159
|
+
resolve({
|
|
160
|
+
useExisting: true,
|
|
161
|
+
selectedTimestamp: selectedToken.creationTimestamp,
|
|
162
|
+
selectedTokenId: selectedToken.tokenId
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
console.log('❌ Invalid choice. Creating new token with current timestamp.');
|
|
167
|
+
resolve({ useExisting: false });
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Mints an NFT token for the ZIP archive using the timestamped contract
|
|
174
|
+
*/
|
|
175
|
+
async mintZipFileNFT(zipTokenData) {
|
|
176
|
+
if (!this.wallet) {
|
|
177
|
+
return {
|
|
178
|
+
success: false,
|
|
179
|
+
message: 'Wallet not set up. Cannot mint token.'
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (!this.provider) {
|
|
183
|
+
return {
|
|
184
|
+
success: false,
|
|
185
|
+
message: 'Network connection failed. Cannot mint token without blockchain connectivity.'
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
console.log(`\nArchive Merkle root: ${zipTokenData.merkleRoot}`);
|
|
190
|
+
// Check for existing tokens with the same merkle root
|
|
191
|
+
const existingTokens = await this.findExistingTokensByMerkleRoot(zipTokenData.merkleRoot);
|
|
192
|
+
let creationTimestamp;
|
|
193
|
+
let reusingExistingToken = false;
|
|
194
|
+
let selectedTokenId;
|
|
195
|
+
if (existingTokens.length > 0) {
|
|
196
|
+
console.log(`\n💡 Found ${existingTokens.length} existing token(s) with the same content.`);
|
|
197
|
+
console.log(' You can create a new token or reuse an existing timestamp.');
|
|
198
|
+
const userChoice = await this.promptUserChoice(existingTokens, zipTokenData.fileName);
|
|
199
|
+
if (userChoice.useExisting && userChoice.selectedTimestamp) {
|
|
200
|
+
creationTimestamp = userChoice.selectedTimestamp;
|
|
201
|
+
selectedTokenId = userChoice.selectedTokenId;
|
|
202
|
+
reusingExistingToken = true;
|
|
203
|
+
console.log(`\n✅ Reusing timestamp ${creationTimestamp} from Token ID ${selectedTokenId}`);
|
|
204
|
+
// Check if this exact combination already exists
|
|
205
|
+
const contractInfo = this.loadContractInfo();
|
|
206
|
+
if (contractInfo) {
|
|
207
|
+
const contract = new ethers_1.ethers.Contract(contractInfo.address, contractInfo.abi, this.provider);
|
|
208
|
+
const [exists, existingTokenId] = await contract.isZipFileTokenized(zipTokenData.merkleRoot, creationTimestamp);
|
|
209
|
+
if (exists) {
|
|
210
|
+
return {
|
|
211
|
+
success: false,
|
|
212
|
+
message: `A token with this exact merkle root and timestamp already exists (Token ID: ${existingTokenId}). Cannot create duplicate.`
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
creationTimestamp = Math.floor(Date.now() / 1000);
|
|
219
|
+
console.log(`\n✅ Creating new token with current timestamp: ${creationTimestamp}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
// No existing tokens, use current timestamp
|
|
224
|
+
creationTimestamp = Math.floor(Date.now() / 1000);
|
|
225
|
+
console.log('Creating new NFT token for this ZIP archive...');
|
|
226
|
+
}
|
|
227
|
+
// Create token metadata
|
|
228
|
+
const metadata = this.createNFTMetadata(zipTokenData);
|
|
229
|
+
console.log('Token metadata created:');
|
|
230
|
+
console.log(JSON.stringify(metadata, null, 2));
|
|
231
|
+
// Load contract information
|
|
232
|
+
const contractInfo = this.loadContractInfo();
|
|
233
|
+
if (!contractInfo) {
|
|
234
|
+
return {
|
|
235
|
+
success: false,
|
|
236
|
+
message: 'No deployed contract found. Deploy the contract using: npm run deploy-nft'
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
console.log(`Found deployed contract at ${contractInfo.address}`);
|
|
240
|
+
try {
|
|
241
|
+
// Create contract instance
|
|
242
|
+
const contract = new ethers_1.ethers.Contract(contractInfo.address, contractInfo.abi, this.wallet);
|
|
243
|
+
console.log(`\nMinting NFT token...`);
|
|
244
|
+
console.log(`Merkle Root: ${zipTokenData.merkleRoot}`);
|
|
245
|
+
console.log(`Creation Timestamp: ${creationTimestamp}${reusingExistingToken ? ' (reused)' : ' (new)'}`);
|
|
246
|
+
// Use the timestamped contract (5 parameters)
|
|
247
|
+
console.log(`Using ZipFileNFT contract`);
|
|
248
|
+
console.log(`contract.publicMintZipFile(`);
|
|
249
|
+
console.log(` fileName: ${zipTokenData.fileName},`);
|
|
250
|
+
console.log(` merkleRootHash: ${zipTokenData.merkleRoot},`);
|
|
251
|
+
console.log(` creationTimestamp: ${creationTimestamp},`);
|
|
252
|
+
console.log(` ipfsHash: "",`);
|
|
253
|
+
console.log(` tokenURI: ""`);
|
|
254
|
+
console.log(`)`);
|
|
255
|
+
const tx = await contract.publicMintZipFile(zipTokenData.fileName, zipTokenData.merkleRoot, // Use original merkle root
|
|
256
|
+
creationTimestamp, // Use selected timestamp (new or reused)
|
|
257
|
+
"", // Empty ipfsHash - not implemented yet
|
|
258
|
+
"" // Empty tokenURI - not implemented yet
|
|
259
|
+
);
|
|
260
|
+
console.log(`Transaction submitted: ${tx.hash}`);
|
|
261
|
+
console.log('Waiting for confirmation...');
|
|
262
|
+
const receipt = await tx.wait();
|
|
263
|
+
console.log(`Transaction confirmed in block: ${receipt.blockNumber}`);
|
|
264
|
+
// Extract token ID from the transfer event
|
|
265
|
+
let tokenId;
|
|
266
|
+
for (const log of receipt.logs) {
|
|
267
|
+
try {
|
|
268
|
+
const parsedLog = contract.interface.parseLog(log);
|
|
269
|
+
if (parsedLog && parsedLog.name === 'Transfer' && parsedLog.args.from === ethers_1.ethers.ZeroAddress) {
|
|
270
|
+
tokenId = parsedLog.args.tokenId.toString();
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
// Skip logs that can't be parsed
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (!tokenId) {
|
|
279
|
+
// Try to get token ID from ZipFileTokenized event
|
|
280
|
+
for (const log of receipt.logs) {
|
|
281
|
+
try {
|
|
282
|
+
const parsedLog = contract.interface.parseLog(log);
|
|
283
|
+
if (parsedLog && parsedLog.name === 'ZipFileTokenized') {
|
|
284
|
+
tokenId = parsedLog.args.tokenId.toString();
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
// Skip logs that can't be parsed
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const successMessage = reusingExistingToken
|
|
294
|
+
? `NFT minted successfully! Token ID: ${tokenId || 'Unknown'} (reused timestamp from Token ${selectedTokenId})`
|
|
295
|
+
: `NFT minted successfully! Token ID: ${tokenId || 'Unknown'} (new timestamp)`;
|
|
296
|
+
return {
|
|
297
|
+
success: true,
|
|
298
|
+
txHash: tx.hash,
|
|
299
|
+
tokenId: tokenId,
|
|
300
|
+
message: successMessage,
|
|
301
|
+
creationTimestamp: creationTimestamp
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
catch (contractError) {
|
|
305
|
+
const errorMessage = contractError instanceof Error ? contractError.message : String(contractError);
|
|
306
|
+
console.error(`Contract interaction failed: ${errorMessage}`);
|
|
307
|
+
return {
|
|
308
|
+
success: false,
|
|
309
|
+
message: `Contract interaction failed: ${errorMessage}`
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
315
|
+
console.error(`Error minting NFT: ${errorMessage}`);
|
|
316
|
+
return {
|
|
317
|
+
success: false,
|
|
318
|
+
message: `Error minting NFT: ${errorMessage}`
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
exports.NFTMinter = NFTMinter;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface ExistingTokenInfo {
|
|
2
|
+
version: string;
|
|
3
|
+
tokenId: string;
|
|
4
|
+
contractAddress: string;
|
|
5
|
+
network: string;
|
|
6
|
+
networkChainId: number;
|
|
7
|
+
transactionHash?: string;
|
|
8
|
+
merkleRoot: string;
|
|
9
|
+
fileName: string;
|
|
10
|
+
mintedAt: string;
|
|
11
|
+
}
|
|
12
|
+
export interface TokenQueryOptions {
|
|
13
|
+
network?: string;
|
|
14
|
+
walletAddress?: string;
|
|
15
|
+
contractAddress?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Queries the blockchain for an existing token with the given merkle root
|
|
19
|
+
* @param merkleRoot - The merkle root hash to search for
|
|
20
|
+
* @param fileName - The name of the ZIP file
|
|
21
|
+
* @param options - Optional query parameters
|
|
22
|
+
* @returns Promise resolving to token info if found, null otherwise
|
|
23
|
+
*/
|
|
24
|
+
export declare function queryBlockchainForExistingToken(merkleRoot: string, fileName: string, options?: TokenQueryOptions): Promise<ExistingTokenInfo | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Queries all tokens owned by a specific wallet address
|
|
27
|
+
* @param walletAddress - The wallet address to query
|
|
28
|
+
* @param options - Optional query parameters
|
|
29
|
+
* @returns Promise resolving to array of token info
|
|
30
|
+
*/
|
|
31
|
+
export declare function queryWalletTokens(walletAddress: string, options?: TokenQueryOptions): Promise<ExistingTokenInfo[]>;
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ======================================
|
|
3
|
+
// TokenQuerier.ts
|
|
4
|
+
// Blockchain token querying utilities for ZIP archives
|
|
5
|
+
// Copyright (c) 2025 NeoWare, Inc. All rights reserved.
|
|
6
|
+
// ======================================
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.queryBlockchainForExistingToken = queryBlockchainForExistingToken;
|
|
42
|
+
exports.queryWalletTokens = queryWalletTokens;
|
|
43
|
+
const fs = __importStar(require("fs"));
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const constants_1 = require("./constants");
|
|
46
|
+
// Network configuration for blockchain queries
|
|
47
|
+
const NETWORK_CONFIG = {
|
|
48
|
+
'Base Sepolia': {
|
|
49
|
+
rpcUrls: [
|
|
50
|
+
'https://sepolia.base.org',
|
|
51
|
+
'https://base-sepolia.g.alchemy.com/v2/demo',
|
|
52
|
+
'https://base-sepolia-rpc.publicnode.com',
|
|
53
|
+
'https://base-sepolia.blockpi.network/v1/rpc/public'
|
|
54
|
+
],
|
|
55
|
+
contractAddress: constants_1.CURRENT_DEPLOYMENT.address, // NZIP NFT Contract v2.0
|
|
56
|
+
chainId: 84532
|
|
57
|
+
},
|
|
58
|
+
'Base Mainnet': {
|
|
59
|
+
rpcUrls: [
|
|
60
|
+
'https://mainnet.base.org',
|
|
61
|
+
'https://base-mainnet.g.alchemy.com/v2/demo',
|
|
62
|
+
'https://base-rpc.publicnode.com',
|
|
63
|
+
'https://base.blockpi.network/v1/rpc/public'
|
|
64
|
+
],
|
|
65
|
+
contractAddress: "0x...", // Add mainnet contract address when deployed
|
|
66
|
+
chainId: 8453
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Queries the blockchain for an existing token with the given merkle root
|
|
71
|
+
* @param merkleRoot - The merkle root hash to search for
|
|
72
|
+
* @param fileName - The name of the ZIP file
|
|
73
|
+
* @param options - Optional query parameters
|
|
74
|
+
* @returns Promise resolving to token info if found, null otherwise
|
|
75
|
+
*/
|
|
76
|
+
async function queryBlockchainForExistingToken(merkleRoot, fileName, options = {}) {
|
|
77
|
+
try {
|
|
78
|
+
const { ethers } = await Promise.resolve().then(() => __importStar(require('ethers')));
|
|
79
|
+
// Use Base Sepolia as default network
|
|
80
|
+
const network = options.network || 'Base Sepolia';
|
|
81
|
+
const networkConfig = NETWORK_CONFIG[network];
|
|
82
|
+
if (!networkConfig) {
|
|
83
|
+
console.log(`⚠️ Unsupported network: ${network}`);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
// Load the contract ABI from deployment file
|
|
87
|
+
const deploymentPath = path.join(process.cwd(), 'zipfile-nft-deployment.json');
|
|
88
|
+
if (!fs.existsSync(deploymentPath)) {
|
|
89
|
+
console.log(`⚠️ Deployment file not found: ${deploymentPath}`);
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const deploymentInfo = JSON.parse(fs.readFileSync(deploymentPath, 'utf8'));
|
|
93
|
+
const contractAddress = options.contractAddress || networkConfig.contractAddress;
|
|
94
|
+
// Default wallet address - this should ideally be passed in from the calling context
|
|
95
|
+
const walletAddress = options.walletAddress || "0x6d4d3075d102376164818471c2f974b9ef211df2";
|
|
96
|
+
// Try multiple RPC endpoints
|
|
97
|
+
for (const rpcUrl of networkConfig.rpcUrls) {
|
|
98
|
+
try {
|
|
99
|
+
console.log(` Trying RPC: ${rpcUrl}`);
|
|
100
|
+
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
|
101
|
+
const contract = new ethers.Contract(contractAddress, deploymentInfo.abi, provider);
|
|
102
|
+
// Get balance of current wallet to know how many tokens to check
|
|
103
|
+
const balance = await contract.balanceOf(walletAddress);
|
|
104
|
+
console.log(` Wallet owns ${balance} tokens, checking each for merkle root match...`);
|
|
105
|
+
// Search through wallet's tokens to find one with our merkle root
|
|
106
|
+
// First try: Query the ZipFileTokenized events for efficiency
|
|
107
|
+
try {
|
|
108
|
+
const filter = contract.filters.ZipFileTokenized();
|
|
109
|
+
const events = await contract.queryFilter(filter, 0, 'latest');
|
|
110
|
+
for (const event of events) {
|
|
111
|
+
if ('args' in event && event.args) {
|
|
112
|
+
const tokenId = event.args.tokenId.toString();
|
|
113
|
+
const eventMerkleRoot = event.args.merkleRootHash;
|
|
114
|
+
const eventCreator = event.args.creator;
|
|
115
|
+
// Check if this is our token (same merkle root and created by our wallet)
|
|
116
|
+
if (eventMerkleRoot === merkleRoot && eventCreator.toLowerCase() === walletAddress.toLowerCase()) {
|
|
117
|
+
console.log(` ✅ Found token ${tokenId} with matching merkle root (created by our wallet)`);
|
|
118
|
+
// Get block timestamp for more accurate mint time
|
|
119
|
+
const block = await provider.getBlock(event.blockNumber);
|
|
120
|
+
const mintTime = block ? new Date(block.timestamp * 1000).toISOString() : new Date().toISOString();
|
|
121
|
+
// Create token metadata with the information we have
|
|
122
|
+
const tokenInfo = {
|
|
123
|
+
version: "1.0",
|
|
124
|
+
tokenId: tokenId,
|
|
125
|
+
contractAddress: contractAddress,
|
|
126
|
+
network: network,
|
|
127
|
+
networkChainId: networkConfig.chainId,
|
|
128
|
+
transactionHash: event.transactionHash,
|
|
129
|
+
merkleRoot: merkleRoot,
|
|
130
|
+
fileName: fileName,
|
|
131
|
+
mintedAt: mintTime
|
|
132
|
+
};
|
|
133
|
+
return tokenInfo;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (eventError) {
|
|
139
|
+
console.log(` ⚠️ Event query failed, trying direct token scan...`);
|
|
140
|
+
// Fallback: try scanning recent token IDs directly
|
|
141
|
+
const totalSupply = await contract.totalSupply();
|
|
142
|
+
console.log(` Scanning ${totalSupply} total tokens...`);
|
|
143
|
+
// Limit scanning to avoid RPC timeouts
|
|
144
|
+
const maxTokensToScan = Math.min(Number(totalSupply), 1000);
|
|
145
|
+
for (let tokenId = 0; tokenId < maxTokensToScan; tokenId++) {
|
|
146
|
+
try {
|
|
147
|
+
const owner = await contract.ownerOf(tokenId);
|
|
148
|
+
if (owner.toLowerCase() === walletAddress.toLowerCase()) {
|
|
149
|
+
const zipInfo = await contract.getZipFileInfo(tokenId);
|
|
150
|
+
if (zipInfo.merkleRootHash === merkleRoot) {
|
|
151
|
+
console.log(` ✅ Found token ${tokenId} with matching merkle root (owned by our wallet)`);
|
|
152
|
+
const tokenInfo = {
|
|
153
|
+
version: "1.0",
|
|
154
|
+
tokenId: tokenId.toString(),
|
|
155
|
+
contractAddress: contractAddress,
|
|
156
|
+
network: network,
|
|
157
|
+
networkChainId: networkConfig.chainId,
|
|
158
|
+
merkleRoot: merkleRoot,
|
|
159
|
+
fileName: fileName,
|
|
160
|
+
mintedAt: new Date(Number(zipInfo.tokenizationTime) * 1000).toISOString()
|
|
161
|
+
};
|
|
162
|
+
return tokenInfo;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (tokenError) {
|
|
167
|
+
// Token might not exist or be accessible, continue searching
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (Number(totalSupply) > maxTokensToScan) {
|
|
172
|
+
console.log(` ⚠️ Only scanned first ${maxTokensToScan} tokens (total: ${totalSupply})`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
console.log(' ❌ No token found with matching merkle root');
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
catch (rpcError) {
|
|
179
|
+
const errorMessage = rpcError instanceof Error ? rpcError.message : String(rpcError);
|
|
180
|
+
console.log(` ⚠️ RPC ${rpcUrl} failed: ${errorMessage.substring(0, 80)}...`);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
console.log(' ❌ All RPC endpoints failed');
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
189
|
+
console.log(' ❌ Blockchain query failed:', errorMessage);
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Queries all tokens owned by a specific wallet address
|
|
195
|
+
* @param walletAddress - The wallet address to query
|
|
196
|
+
* @param options - Optional query parameters
|
|
197
|
+
* @returns Promise resolving to array of token info
|
|
198
|
+
*/
|
|
199
|
+
async function queryWalletTokens(walletAddress, options = {}) {
|
|
200
|
+
try {
|
|
201
|
+
const { ethers } = await Promise.resolve().then(() => __importStar(require('ethers')));
|
|
202
|
+
const network = options.network || 'Base Sepolia';
|
|
203
|
+
const networkConfig = NETWORK_CONFIG[network];
|
|
204
|
+
if (!networkConfig) {
|
|
205
|
+
console.log(`⚠️ Unsupported network: ${network}`);
|
|
206
|
+
return [];
|
|
207
|
+
}
|
|
208
|
+
const deploymentPath = path.join(process.cwd(), 'zipfile-nft-deployment.json');
|
|
209
|
+
if (!fs.existsSync(deploymentPath)) {
|
|
210
|
+
console.log(`⚠️ Deployment file not found: ${deploymentPath}`);
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
213
|
+
const deploymentInfo = JSON.parse(fs.readFileSync(deploymentPath, 'utf8'));
|
|
214
|
+
const contractAddress = options.contractAddress || networkConfig.contractAddress;
|
|
215
|
+
const tokens = [];
|
|
216
|
+
// Try the first available RPC endpoint
|
|
217
|
+
const rpcUrl = networkConfig.rpcUrls[0];
|
|
218
|
+
try {
|
|
219
|
+
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
|
220
|
+
const contract = new ethers.Contract(contractAddress, deploymentInfo.abi, provider);
|
|
221
|
+
const balance = await contract.balanceOf(walletAddress);
|
|
222
|
+
console.log(` Wallet ${walletAddress} owns ${balance} tokens`);
|
|
223
|
+
// Query events for tokens created by this wallet
|
|
224
|
+
const filter = contract.filters.ZipFileTokenized();
|
|
225
|
+
const events = await contract.queryFilter(filter, 0, 'latest');
|
|
226
|
+
for (const event of events) {
|
|
227
|
+
if ('args' in event && event.args) {
|
|
228
|
+
const eventCreator = event.args.creator;
|
|
229
|
+
if (eventCreator.toLowerCase() === walletAddress.toLowerCase()) {
|
|
230
|
+
const tokenId = event.args.tokenId.toString();
|
|
231
|
+
const merkleRoot = event.args.merkleRootHash;
|
|
232
|
+
const block = await provider.getBlock(event.blockNumber);
|
|
233
|
+
const mintTime = block ? new Date(block.timestamp * 1000).toISOString() : new Date().toISOString();
|
|
234
|
+
const tokenInfo = {
|
|
235
|
+
version: "1.0",
|
|
236
|
+
tokenId: tokenId,
|
|
237
|
+
contractAddress: contractAddress,
|
|
238
|
+
network: network,
|
|
239
|
+
networkChainId: networkConfig.chainId,
|
|
240
|
+
transactionHash: event.transactionHash,
|
|
241
|
+
merkleRoot: merkleRoot,
|
|
242
|
+
fileName: `token-${tokenId}.zip`, // Placeholder filename
|
|
243
|
+
mintedAt: mintTime
|
|
244
|
+
};
|
|
245
|
+
tokens.push(tokenInfo);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
console.log(' ❌ Failed to query wallet tokens:', error instanceof Error ? error.message : String(error));
|
|
252
|
+
}
|
|
253
|
+
return tokens;
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
console.log(' ❌ Wallet query failed:', error instanceof Error ? error.message : String(error));
|
|
257
|
+
return [];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import ZipKitServer from '../platform/server/ZipKitServer';
|
|
2
|
+
import { NZipTokenInfo } from './types';
|
|
3
|
+
export interface TokenVerificationOptions {
|
|
4
|
+
skipHash?: boolean;
|
|
5
|
+
skipToken?: boolean;
|
|
6
|
+
generateCertificate?: boolean;
|
|
7
|
+
zipFileName?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface TokenVerificationResult {
|
|
10
|
+
isTokenized: boolean;
|
|
11
|
+
tokenMetadata: NZipTokenInfo | null;
|
|
12
|
+
calculatedMerkleRoot: string | null;
|
|
13
|
+
blockchainMerkleRoot: string | null;
|
|
14
|
+
verificationPassed: boolean;
|
|
15
|
+
certificatePath?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Checks if the ZIP file contains NFT token metadata and verifies the merkle root
|
|
19
|
+
*/
|
|
20
|
+
export declare function checkForTokenization(zipKit: ZipKitServer, options?: TokenVerificationOptions): Promise<TokenVerificationResult>;
|