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
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* ZipKitMinter - Handles NFT token minting for ZIP files
|
|
5
|
+
* Minter API for NZIP-NFT smart contract.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.ZipKitMinter = void 0;
|
|
9
|
+
exports.validatePrivateKey = validatePrivateKey;
|
|
10
|
+
const ethers_1 = require("ethers");
|
|
11
|
+
const contracts_1 = require("./contracts");
|
|
12
|
+
// Network configurations
|
|
13
|
+
const NETWORK_CONFIGS = {
|
|
14
|
+
'base-sepolia': {
|
|
15
|
+
name: 'Base Sepolia',
|
|
16
|
+
rpcUrl: 'https://sepolia.base.org',
|
|
17
|
+
contractAddress: contracts_1.CONTRACT_CONFIGS[84532].address, // Use real contract address
|
|
18
|
+
explorerUrl: 'https://sepolia.basescan.org',
|
|
19
|
+
chainId: 84532
|
|
20
|
+
},
|
|
21
|
+
'base-mainnet': {
|
|
22
|
+
name: 'Base Mainnet',
|
|
23
|
+
rpcUrl: 'https://mainnet.base.org',
|
|
24
|
+
contractAddress: contracts_1.CONTRACT_CONFIGS[8453].address, // Use real contract address
|
|
25
|
+
explorerUrl: 'https://basescan.org',
|
|
26
|
+
chainId: 8453
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Blockchain Token Minter for ZIP files
|
|
31
|
+
*/
|
|
32
|
+
class ZipKitMinter {
|
|
33
|
+
constructor(archiveName, merkleRoot, options) {
|
|
34
|
+
this.archiveName = archiveName;
|
|
35
|
+
this.merkleRoot = merkleRoot;
|
|
36
|
+
this.debug = options.debug || false;
|
|
37
|
+
// Get network configuration
|
|
38
|
+
this.networkConfig = NETWORK_CONFIGS[options.network];
|
|
39
|
+
if (!this.networkConfig) {
|
|
40
|
+
throw new Error(`Unsupported network: ${options.network}`);
|
|
41
|
+
}
|
|
42
|
+
// Initialize provider for the specified network
|
|
43
|
+
this.provider = new ethers_1.ethers.JsonRpcProvider(this.networkConfig.rpcUrl);
|
|
44
|
+
// Initialize wallet from private key
|
|
45
|
+
this.wallet = new ethers_1.ethers.Wallet(options.walletPrivateKey, this.provider);
|
|
46
|
+
// Initialize contract instance
|
|
47
|
+
this.contract = new ethers_1.ethers.Contract(this.networkConfig.contractAddress, contracts_1.NZIP_CONTRACT_ABI, this.wallet);
|
|
48
|
+
if (this.debug) {
|
|
49
|
+
console.log(`[DEBUG] ZipKitMinter initialized for ${this.networkConfig.name}`);
|
|
50
|
+
console.log(`[DEBUG] Archive: ${archiveName}, Merkle: ${merkleRoot.substring(0, 10)}...`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get wallet information
|
|
55
|
+
*/
|
|
56
|
+
async getWalletInfo() {
|
|
57
|
+
const balance = await this.provider.getBalance(this.wallet.address);
|
|
58
|
+
const balanceInEth = ethers_1.ethers.formatEther(balance);
|
|
59
|
+
if (this.debug) {
|
|
60
|
+
console.log(`[DEBUG] Wallet ${this.wallet.address} balance: ${balanceInEth} ETH`);
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
address: this.wallet.address,
|
|
64
|
+
balance: balanceInEth,
|
|
65
|
+
networkName: this.networkConfig.name
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check for existing tokens with same merkle root and verify ownership
|
|
70
|
+
*/
|
|
71
|
+
async checkForDuplicates() {
|
|
72
|
+
try {
|
|
73
|
+
if (this.debug) {
|
|
74
|
+
console.log(`[DEBUG] Checking for existing tokens with merkle root: ${this.merkleRoot}`);
|
|
75
|
+
console.log(`[DEBUG] User wallet address: ${this.wallet.address}`);
|
|
76
|
+
}
|
|
77
|
+
// Call contract method to check if merkle root already exists
|
|
78
|
+
const existingTokenIds = await this.contract.getTokensByMerkleRoot(this.merkleRoot);
|
|
79
|
+
if (!existingTokenIds || existingTokenIds.length === 0) {
|
|
80
|
+
if (this.debug) {
|
|
81
|
+
console.log(`[DEBUG] No existing tokens found for this merkle root`);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
hasExistingTokens: false,
|
|
85
|
+
allTokens: [],
|
|
86
|
+
userOwnedTokens: [],
|
|
87
|
+
othersTokens: []
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (this.debug) {
|
|
91
|
+
console.log(`[DEBUG] Found ${existingTokenIds.length} existing token(s)`);
|
|
92
|
+
}
|
|
93
|
+
// Check ownership and get token details for each token
|
|
94
|
+
const allTokens = [];
|
|
95
|
+
const userOwnedTokens = [];
|
|
96
|
+
const othersTokens = [];
|
|
97
|
+
for (const tokenId of existingTokenIds) {
|
|
98
|
+
const tokenIdStr = tokenId.toString();
|
|
99
|
+
try {
|
|
100
|
+
// Get token owner
|
|
101
|
+
const owner = await this.contract.ownerOf(tokenId);
|
|
102
|
+
const isOwnedByUser = owner.toLowerCase() === this.wallet.address.toLowerCase();
|
|
103
|
+
// Get token data
|
|
104
|
+
let tokenData = null;
|
|
105
|
+
try {
|
|
106
|
+
tokenData = await this.contract.getZipFileInfo(tokenId);
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
if (this.debug) {
|
|
110
|
+
console.log(`[DEBUG] Could not get token data for ${tokenIdStr}: ${e}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const tokenInfo = {
|
|
114
|
+
tokenId: tokenIdStr,
|
|
115
|
+
owner: owner,
|
|
116
|
+
isOwnedByUser: isOwnedByUser,
|
|
117
|
+
tokenData: tokenData
|
|
118
|
+
};
|
|
119
|
+
allTokens.push(tokenInfo);
|
|
120
|
+
if (isOwnedByUser) {
|
|
121
|
+
userOwnedTokens.push(tokenInfo);
|
|
122
|
+
if (this.debug) {
|
|
123
|
+
console.log(`[DEBUG] Token ${tokenIdStr} is owned by user`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
othersTokens.push(tokenInfo);
|
|
128
|
+
if (this.debug) {
|
|
129
|
+
console.log(`[DEBUG] Token ${tokenIdStr} is owned by ${owner}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
if (this.debug) {
|
|
135
|
+
console.log(`[DEBUG] Error checking ownership for token ${tokenIdStr}: ${e}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
hasExistingTokens: true,
|
|
141
|
+
allTokens,
|
|
142
|
+
userOwnedTokens,
|
|
143
|
+
othersTokens
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (this.debug) {
|
|
148
|
+
console.log(`[DEBUG] Error checking duplicates: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
149
|
+
}
|
|
150
|
+
// If the contract method doesn't exist or fails, assume no duplicates
|
|
151
|
+
return {
|
|
152
|
+
hasExistingTokens: false,
|
|
153
|
+
allTokens: [],
|
|
154
|
+
userOwnedTokens: [],
|
|
155
|
+
othersTokens: []
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Estimate gas costs for minting
|
|
161
|
+
*/
|
|
162
|
+
async estimateGasCosts() {
|
|
163
|
+
const creationTimestamp = Math.floor(Date.now() / 1000);
|
|
164
|
+
const metadata = this.createTokenMetadataString();
|
|
165
|
+
// Estimate gas for the minting transaction
|
|
166
|
+
const gasLimit = await this.contract.publicMintZipFile.estimateGas(this.archiveName, this.merkleRoot, creationTimestamp, '', // ipfsHash
|
|
167
|
+
metadata);
|
|
168
|
+
const feeData = await this.provider.getFeeData();
|
|
169
|
+
const gasPrice = feeData.gasPrice || BigInt(0);
|
|
170
|
+
const estimatedCost = ethers_1.ethers.formatEther(gasLimit * gasPrice);
|
|
171
|
+
if (this.debug) {
|
|
172
|
+
console.log(`[DEBUG] Gas estimate - Limit: ${gasLimit}, Price: ${gasPrice}, Cost: ${estimatedCost} ETH`);
|
|
173
|
+
}
|
|
174
|
+
return { gasLimit, gasPrice, estimatedCost };
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Create token metadata string
|
|
178
|
+
*/
|
|
179
|
+
createTokenMetadataString() {
|
|
180
|
+
const now = new Date();
|
|
181
|
+
return JSON.stringify({
|
|
182
|
+
name: `NeoZip Archive: ${this.archiveName}`,
|
|
183
|
+
description: `Tokenized ZIP archive with cryptographic proof of integrity`,
|
|
184
|
+
image: '', // Could be a thumbnail or icon
|
|
185
|
+
archiveName: this.archiveName,
|
|
186
|
+
merkleRoot: this.merkleRoot,
|
|
187
|
+
network: this.networkConfig.name,
|
|
188
|
+
createdAt: now.toISOString(),
|
|
189
|
+
timestamp: Math.floor(now.getTime() / 1000)
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Create TokenMetadata object from minting result
|
|
194
|
+
*/
|
|
195
|
+
createTokenMetadata(tokenId, transactionHash, blockNumber) {
|
|
196
|
+
const now = new Date();
|
|
197
|
+
return {
|
|
198
|
+
tokenId,
|
|
199
|
+
network: this.networkConfig.name,
|
|
200
|
+
contractAddress: this.networkConfig.contractAddress,
|
|
201
|
+
merkleRoot: this.merkleRoot,
|
|
202
|
+
mintDate: now.toLocaleDateString('en-US') + ' at ' + now.toLocaleTimeString('en-US'),
|
|
203
|
+
creationTimestamp: Math.floor(now.getTime() / 1000),
|
|
204
|
+
archiveName: this.archiveName,
|
|
205
|
+
transactionHash,
|
|
206
|
+
blockNumber
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Mint new token on blockchain
|
|
211
|
+
*/
|
|
212
|
+
async mintToken() {
|
|
213
|
+
try {
|
|
214
|
+
if (this.debug) {
|
|
215
|
+
console.log(`[DEBUG] Starting token minting process`);
|
|
216
|
+
}
|
|
217
|
+
// Generate token ID (could be random or sequential)
|
|
218
|
+
const tokenId = Math.floor(Math.random() * 1000000).toString();
|
|
219
|
+
const metadata = this.createTokenMetadataString();
|
|
220
|
+
const creationTimestamp = Math.floor(Date.now() / 1000);
|
|
221
|
+
if (this.debug) {
|
|
222
|
+
console.log(`[DEBUG] Generated token ID: ${tokenId}`);
|
|
223
|
+
console.log(`[DEBUG] Metadata: ${metadata.substring(0, 100)}...`);
|
|
224
|
+
}
|
|
225
|
+
// Call the contract publicMintZipFile function
|
|
226
|
+
const tx = await this.contract.publicMintZipFile(this.archiveName, this.merkleRoot, creationTimestamp, '', // ipfsHash (empty since we store in ZIP)
|
|
227
|
+
metadata);
|
|
228
|
+
if (this.debug) {
|
|
229
|
+
console.log(`[DEBUG] Transaction submitted: ${tx.hash}`);
|
|
230
|
+
}
|
|
231
|
+
// Wait for transaction confirmation
|
|
232
|
+
const receipt = await tx.wait();
|
|
233
|
+
if (this.debug) {
|
|
234
|
+
console.log(`[DEBUG] Transaction confirmed in block: ${receipt.blockNumber}`);
|
|
235
|
+
console.log(`[DEBUG] Gas used: ${receipt.gasUsed}`);
|
|
236
|
+
}
|
|
237
|
+
// Extract actual token ID from contract events
|
|
238
|
+
let actualTokenId = tokenId; // fallback
|
|
239
|
+
if (receipt.logs && receipt.logs.length > 0) {
|
|
240
|
+
try {
|
|
241
|
+
const iface = new ethers_1.ethers.Interface(contracts_1.NZIP_CONTRACT_ABI);
|
|
242
|
+
for (const log of receipt.logs) {
|
|
243
|
+
try {
|
|
244
|
+
const parsed = iface.parseLog(log);
|
|
245
|
+
if (parsed?.name === 'ZipFileTokenized') {
|
|
246
|
+
actualTokenId = parsed.args.tokenId.toString();
|
|
247
|
+
if (this.debug) {
|
|
248
|
+
console.log(`[DEBUG] Actual token ID from contract event: ${actualTokenId}`);
|
|
249
|
+
}
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch (e) {
|
|
254
|
+
// Ignore parsing errors for non-matching logs
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
259
|
+
if (this.debug) {
|
|
260
|
+
console.log(`[DEBUG] Could not parse token ID from logs: ${e}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const gasCost = ethers_1.ethers.formatEther(receipt.gasUsed * (receipt.gasPrice || BigInt(0)));
|
|
265
|
+
return {
|
|
266
|
+
success: true,
|
|
267
|
+
message: `Token successfully minted`,
|
|
268
|
+
tokenId: actualTokenId,
|
|
269
|
+
transactionHash: tx.hash,
|
|
270
|
+
contractAddress: this.networkConfig.contractAddress,
|
|
271
|
+
blockNumber: receipt.blockNumber,
|
|
272
|
+
walletAddress: this.wallet.address,
|
|
273
|
+
gasUsed: receipt.gasUsed.toString(),
|
|
274
|
+
gasCost
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown minting error';
|
|
279
|
+
if (this.debug) {
|
|
280
|
+
console.log(`[DEBUG] Minting failed: ${errorMessage}`);
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
success: false,
|
|
284
|
+
message: errorMessage
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Main minting process - checks for duplicates, then mints if needed
|
|
290
|
+
*/
|
|
291
|
+
async processMinting() {
|
|
292
|
+
try {
|
|
293
|
+
// Get wallet information
|
|
294
|
+
const walletInfo = await this.getWalletInfo();
|
|
295
|
+
// Check for duplicates first (free operation)
|
|
296
|
+
const duplicateCheck = await this.checkForDuplicates();
|
|
297
|
+
if (duplicateCheck.hasExistingTokens) {
|
|
298
|
+
if (this.debug) {
|
|
299
|
+
console.log(`[DEBUG] Existing tokens found, user will choose`);
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
walletInfo,
|
|
303
|
+
duplicateCheck
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
// Estimate gas costs
|
|
307
|
+
const gasCosts = await this.estimateGasCosts();
|
|
308
|
+
// This is where the user would be prompted for confirmation in the calling code
|
|
309
|
+
// The actual minting happens in a separate call to mintToken()
|
|
310
|
+
return {
|
|
311
|
+
walletInfo,
|
|
312
|
+
duplicateCheck,
|
|
313
|
+
gasCosts
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
throw new Error(`Minting process failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Complete the minting after user confirmation
|
|
322
|
+
*/
|
|
323
|
+
async completeMinting() {
|
|
324
|
+
const mintingResult = await this.mintToken();
|
|
325
|
+
if (mintingResult.success && mintingResult.tokenId && mintingResult.transactionHash) {
|
|
326
|
+
const tokenMetadata = this.createTokenMetadata(mintingResult.tokenId, mintingResult.transactionHash, mintingResult.blockNumber);
|
|
327
|
+
return {
|
|
328
|
+
mintingResult,
|
|
329
|
+
tokenMetadata
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
return { mintingResult };
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
exports.ZipKitMinter = ZipKitMinter;
|
|
336
|
+
/**
|
|
337
|
+
* Utility function to validate Ethereum private key
|
|
338
|
+
*/
|
|
339
|
+
function validatePrivateKey(privateKey) {
|
|
340
|
+
try {
|
|
341
|
+
new ethers_1.ethers.Wallet(privateKey);
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
344
|
+
catch {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZipKitVerifier = exports.ZipKitMinter = void 0;
|
|
4
|
+
// Re-export NFT classes and types without aliases
|
|
5
|
+
var _1 = require(".");
|
|
6
|
+
Object.defineProperty(exports, "ZipKitMinter", { enumerable: true, get: function () { return _1.ZipKitMinter; } });
|
|
7
|
+
Object.defineProperty(exports, "ZipKitVerifier", { enumerable: true, get: function () { return _1.ZipKitVerifier; } });
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import ZipEntry from '../shared/ZipEntry';
|
|
2
|
+
declare global {
|
|
3
|
+
var _bitcore: any;
|
|
4
|
+
}
|
|
5
|
+
export interface TimestampResult {
|
|
6
|
+
merkleRoot: string | null;
|
|
7
|
+
ots: ArrayBuffer | null;
|
|
8
|
+
verified: boolean;
|
|
9
|
+
results: any | null;
|
|
10
|
+
error: string | null;
|
|
11
|
+
attestations: any | null;
|
|
12
|
+
upgradedOts: ArrayBuffer | null;
|
|
13
|
+
}
|
|
14
|
+
export interface TimestampInfo {
|
|
15
|
+
message: string;
|
|
16
|
+
results: string[];
|
|
17
|
+
attestDate: Date | null;
|
|
18
|
+
attestHeight: number | null;
|
|
19
|
+
submittedUri: string | null;
|
|
20
|
+
otsUpgraded: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface DeserializeOtsResult {
|
|
23
|
+
attestStr: string | null;
|
|
24
|
+
needsUpdateMsg: string | null;
|
|
25
|
+
attestationValues: any[];
|
|
26
|
+
}
|
|
27
|
+
export interface OtsVerifyResult {
|
|
28
|
+
status: 'none' | 'valid' | 'pending' | 'error';
|
|
29
|
+
message?: string;
|
|
30
|
+
blockHeight?: number;
|
|
31
|
+
attestedAt?: Date;
|
|
32
|
+
upgraded?: boolean;
|
|
33
|
+
upgradedOts?: Buffer;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Verifies an OpenTimestamps proof against a hash digest.
|
|
37
|
+
* @param hashDigest - SHA256 hash as hex string to verify
|
|
38
|
+
* @param ots - OpenTimestamps proof data
|
|
39
|
+
* @param options - Configuration options
|
|
40
|
+
* @param options.debug - Enable debug logging
|
|
41
|
+
* @returns Promise resolving to verification result, error object, or null if inputs invalid
|
|
42
|
+
*/
|
|
43
|
+
export declare function verifyOts(hashDigest: string | null, ots: ArrayBuffer | null, options?: {
|
|
44
|
+
debug?: boolean;
|
|
45
|
+
}): Promise<TimestampResult | {
|
|
46
|
+
error: string;
|
|
47
|
+
} | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Converts a Node.js Buffer to an ArrayBuffer.
|
|
50
|
+
* @param buf - Buffer to convert
|
|
51
|
+
* @returns ArrayBuffer with same data
|
|
52
|
+
*/
|
|
53
|
+
export declare function bufferToArrayBuffer(buf: Buffer): ArrayBuffer;
|
|
54
|
+
/**
|
|
55
|
+
* Finds the OpenTimestamps entry in a ZIP file.
|
|
56
|
+
* Searches for TIMESTAMP_METADATA first, then TIMESTAMP_SUBMITTED.
|
|
57
|
+
* @param zip - ZipKit instance to search
|
|
58
|
+
* @returns ZIP entry containing OTS proof, or null if not found
|
|
59
|
+
*/
|
|
60
|
+
export declare function getOtsEntry(zip: any): any | null;
|
|
61
|
+
/**
|
|
62
|
+
* Extracts OTS proof data from a ZIP entry.
|
|
63
|
+
* @param zip - ZipKit instance
|
|
64
|
+
* @param otsEntry - ZIP entry containing OTS data
|
|
65
|
+
* @returns Promise resolving to OTS proof buffer, or null if extraction fails
|
|
66
|
+
*/
|
|
67
|
+
export declare function getOtsBuffer(zip: any, otsEntry: any): Promise<Buffer | null>;
|
|
68
|
+
/**
|
|
69
|
+
* Safely extracts merkle root from a ZIP file.
|
|
70
|
+
* @param zip - ZipKit instance
|
|
71
|
+
* @returns Merkle root hash string, or null if not available
|
|
72
|
+
*/
|
|
73
|
+
export declare function getMerkleRootSafe(zip: any): string | null;
|
|
74
|
+
/**
|
|
75
|
+
* Verifies OpenTimestamps proof within a ZIP file.
|
|
76
|
+
* Extracts merkle root and OTS proof, then verifies against Bitcoin blockchain.
|
|
77
|
+
* @param zip - ZipKit instance containing files and OTS proof
|
|
78
|
+
* @returns Promise resolving to verification result with status: 'none', 'error', 'pending', or 'valid'
|
|
79
|
+
*/
|
|
80
|
+
export declare function verifyOtsZip(zip: any): Promise<OtsVerifyResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Creates an OpenTimestamps proof for a hash digest.
|
|
83
|
+
* Submits hash to OpenTimestamps servers for Bitcoin blockchain anchoring.
|
|
84
|
+
* @param hashDigest - SHA256 hash as hex string to timestamp
|
|
85
|
+
* @param options - Configuration options
|
|
86
|
+
* @param options.debug - Enable debug logging
|
|
87
|
+
* @returns Promise resolving to OTS proof buffer, or null if creation failed
|
|
88
|
+
*/
|
|
89
|
+
export declare function createTimestamp(hashDigest: string | null, options?: {
|
|
90
|
+
debug?: boolean;
|
|
91
|
+
}): Promise<Buffer | null>;
|
|
92
|
+
/**
|
|
93
|
+
* Deserializes OpenTimestamps verification result into JSON format.
|
|
94
|
+
* Extracts blockchain attestation data and transaction details.
|
|
95
|
+
* @param tsResult - Timestamp verification result to deserialize
|
|
96
|
+
* @param options - Configuration options
|
|
97
|
+
* @param options.debug - Enable debug logging
|
|
98
|
+
* @returns Promise resolving to JSON string with attestation data, or null if failed
|
|
99
|
+
*/
|
|
100
|
+
export declare function deserializeOts(tsResult: TimestampResult, options?: {
|
|
101
|
+
debug?: boolean;
|
|
102
|
+
}): Promise<string | null>;
|
|
103
|
+
/**
|
|
104
|
+
* Parses timestamp verification result into readable information.
|
|
105
|
+
* Formats blockchain attestation data with human-readable messages and dates.
|
|
106
|
+
* @param verifyResult - Timestamp verification result to parse
|
|
107
|
+
* @returns Promise resolving to formatted timestamp information
|
|
108
|
+
*/
|
|
109
|
+
export declare function parseVerifyResult(verifyResult: TimestampResult): Promise<TimestampInfo>;
|
|
110
|
+
/**
|
|
111
|
+
* Creates an HTML certificate for OpenTimestamps verification.
|
|
112
|
+
* Generates a certificate file documenting the timestamp verification results.
|
|
113
|
+
* @param fileName - Base name for the ZIP file (used for certificate filename)
|
|
114
|
+
* @param zipEntries - Array of ZIP entries to include in certificate
|
|
115
|
+
* @param timestampResult - Verification result to document
|
|
116
|
+
* @returns Promise resolving to success message with certificate filename, or error message
|
|
117
|
+
*/
|
|
118
|
+
export declare function createCertificateOts(fileName: string, zipEntries: ZipEntry[], timestampResult: TimestampResult): Promise<string>;
|
|
119
|
+
/**
|
|
120
|
+
* Upgrades OpenTimestamps proof in an existing ZIP file.
|
|
121
|
+
* Replaces old timestamp metadata with upgraded OTS proof data.
|
|
122
|
+
* @param zipFilePath - Path to ZIP file to upgrade
|
|
123
|
+
* @param upgradedOts - Buffer containing upgraded OTS proof
|
|
124
|
+
* @returns Promise that resolves when upgrade is complete
|
|
125
|
+
* @throws Error if upgrade fails
|
|
126
|
+
*/
|
|
127
|
+
export declare function upgradeOTS(zipFilePath: string, upgradedOts: Buffer): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Creates a ZIP metadata entry containing OpenTimestamps proof.
|
|
130
|
+
* Creates a special ZIP entry marked as metadata that stores OTS proof data.
|
|
131
|
+
* @param zipKit - ZipKit instance to add metadata entry to
|
|
132
|
+
* @param ots - Buffer containing OpenTimestamps proof data
|
|
133
|
+
* @returns ZIP entry containing OTS metadata, or null if creation failed
|
|
134
|
+
*/
|
|
135
|
+
export declare function createOtsMetadataEntry(zipKit: any, ots: Buffer | null): any | null;
|