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.
Files changed (115) hide show
  1. package/README.md +52 -105
  2. package/contracts/INTEGRATION.md +338 -0
  3. package/contracts/NETWORKS.md +156 -0
  4. package/contracts/README.md +152 -0
  5. package/{src/server/blockchain → contracts}/constants.ts +5 -22
  6. package/contracts/deploy-bytecode.mjs +94 -0
  7. package/dist/blockchain/ZipKitMinter.d.ts +106 -0
  8. package/dist/blockchain/ZipKitMinter.js +347 -0
  9. package/dist/blockchain/ZipKitNFT.d.ts +3 -0
  10. package/dist/blockchain/ZipKitNFT.js +7 -0
  11. package/dist/blockchain/ZipKitOTS.d.ts +135 -0
  12. package/dist/blockchain/ZipKitOTS.js +564 -0
  13. package/dist/blockchain/ZipKitVerifier.d.ts +69 -0
  14. package/dist/blockchain/ZipKitVerifier.js +289 -0
  15. package/dist/{server/blockchain/WalletAnalyzer.d.ts → blockchain/ZipKitWallet.d.ts} +31 -43
  16. package/dist/{server/blockchain/WalletAnalyzer.js → blockchain/ZipKitWallet.js} +193 -161
  17. package/dist/blockchain/contracts.d.ts +14 -0
  18. package/dist/blockchain/contracts.js +77 -0
  19. package/dist/blockchain/index.d.ts +7 -0
  20. package/dist/blockchain/index.js +50 -0
  21. package/dist/{server/blockchain → blockchain}/types.d.ts +12 -34
  22. package/dist/{server/blockchain → blockchain}/types.js +1 -22
  23. package/dist/browser-index.d.ts +0 -3
  24. package/dist/browser-index.js +4 -5
  25. package/dist/browser.d.ts +0 -3
  26. package/dist/browser.js +4 -5
  27. package/dist/index.d.ts +8 -15
  28. package/dist/index.js +12 -24
  29. package/dist/server/{platform/server/ZipKitServer.d.ts → ZipKitServer.d.ts} +4 -35
  30. package/dist/server/{platform/server/ZipKitServer.js → ZipKitServer.js} +55 -182
  31. package/dist/shared/ZipEntry.js +1 -1
  32. package/dist/shared/ZipKit.d.ts +0 -6
  33. package/dist/shared/ZipKit.js +1 -18
  34. package/dist/shared/types.js +2 -2
  35. package/dist/shared/version.d.ts +2 -4
  36. package/dist/shared/version.js +4 -5
  37. package/package.json +13 -3
  38. package/src/blockchain/README.md +229 -0
  39. package/src/blockchain/ZipKitMinter.ts +470 -0
  40. package/src/blockchain/ZipKitNFT.ts +12 -0
  41. package/src/blockchain/ZipKitOTS.ts +622 -0
  42. package/src/blockchain/ZipKitVerifier.ts +382 -0
  43. package/src/blockchain/ZipKitWallet.ts +338 -0
  44. package/src/blockchain/contracts.ts +88 -0
  45. package/src/blockchain/index.ts +61 -0
  46. package/src/blockchain/types.ts +91 -0
  47. package/src/browser/{TokenVerifierBrowser.ts → TokenVerifierBrowser.ts-remove} +1 -1
  48. package/src/browser-index.ts +3 -3
  49. package/src/index.ts +10 -17
  50. package/src/server/README.md +25 -0
  51. package/src/server/ZipKitServer.ts +305 -0
  52. package/src/shared/ZipEntry.ts +1 -1
  53. package/src/shared/ZipKit.ts +1 -19
  54. package/src/shared/types.ts +3 -3
  55. package/src/shared/version.ts +3 -4
  56. package/src/types/modules.d.ts +11 -1
  57. package/contracts/Lock.sol +0 -34
  58. package/contracts/compile-contract.js +0 -168
  59. package/contracts/deploy/deploy-both-contracts.js +0 -286
  60. package/contracts/deploy/deploy-enhanced-contract.js +0 -197
  61. package/contracts/deploy/deploy-private-contract.js +0 -190
  62. package/contracts/deploy/deploy-public-clean.js +0 -1063
  63. package/contracts/deploy/deploy-public-contract.js +0 -1107
  64. package/contracts/deployment.config.example.js +0 -25
  65. package/contracts/remix-compile.js +0 -222
  66. package/contracts/setup-deployment.js +0 -51
  67. package/contracts/src/ZipFileNFT-DEPRECATED-6field.sol +0 -260
  68. package/contracts/src/ZipFileNFT-DEPRECATED-Enhanced.sol +0 -289
  69. package/dist/browser/CertificateGeneratorBrowser.d.ts +0 -75
  70. package/dist/browser/CertificateGeneratorBrowser.js +0 -433
  71. package/dist/browser/TokenVerifierBrowser.d.ts +0 -76
  72. package/dist/browser/TokenVerifierBrowser.js +0 -299
  73. package/dist/server/blockchain/NFTMinter.d.ts +0 -41
  74. package/dist/server/blockchain/NFTMinter.js +0 -323
  75. package/dist/server/blockchain/TokenQuerier.d.ts +0 -31
  76. package/dist/server/blockchain/TokenQuerier.js +0 -259
  77. package/dist/server/blockchain/TokenVerifier.d.ts +0 -20
  78. package/dist/server/blockchain/TokenVerifier.js +0 -395
  79. package/dist/server/blockchain/WalletFormatter.d.ts +0 -39
  80. package/dist/server/blockchain/WalletFormatter.js +0 -196
  81. package/dist/server/blockchain/WalletManager.d.ts +0 -46
  82. package/dist/server/blockchain/WalletManager.js +0 -294
  83. package/dist/server/blockchain/ZipMetadata.d.ts +0 -27
  84. package/dist/server/blockchain/ZipMetadata.js +0 -131
  85. package/dist/server/blockchain/ZipTokenProcessor.d.ts +0 -44
  86. package/dist/server/blockchain/ZipTokenProcessor.js +0 -204
  87. package/dist/server/blockchain/constants.d.ts +0 -102
  88. package/dist/server/blockchain/constants.js +0 -968
  89. package/dist/server/blockchain/index.d.ts +0 -9
  90. package/dist/server/blockchain/index.js +0 -44
  91. package/dist/server/blockchain/test-certificate.d.ts +0 -8
  92. package/dist/server/blockchain/test-certificate.js +0 -100
  93. package/dist/server/platform/servercomponents/ZipKitOTS.d.ts +0 -91
  94. package/dist/server/platform/servercomponents/ZipKitOTS.js +0 -271
  95. package/examples/unzip-token.ts +0 -488
  96. package/examples/zip-token.ts +0 -604
  97. package/src/server/blockchain/NFTMinter.ts +0 -357
  98. package/src/server/blockchain/TokenQuerier.ts +0 -287
  99. package/src/server/blockchain/TokenVerifier.ts +0 -453
  100. package/src/server/blockchain/WalletAnalyzer.ts +0 -397
  101. package/src/server/blockchain/WalletFormatter.ts +0 -206
  102. package/src/server/blockchain/WalletManager.ts +0 -294
  103. package/src/server/blockchain/ZipMetadata.ts +0 -117
  104. package/src/server/blockchain/ZipTokenProcessor.ts +0 -234
  105. package/src/server/blockchain/index.ts +0 -42
  106. package/src/server/blockchain/test-certificate.ts +0 -137
  107. package/src/server/blockchain/types.ts +0 -134
  108. package/src/server/platform/server/ZipKitServer.ts +0 -459
  109. package/src/server/platform/servercomponents/ZipKitOTS.ts +0 -313
  110. package/src/server/platform/servercomponents/opentimestamps.d.ts +0 -23
  111. /package/contracts/{bytecode.txt → NZIP-NFT-bytecode.txt} +0 -0
  112. /package/dist/{server/blockchain → blockchain}/CertificateToken.d.ts +0 -0
  113. /package/dist/{server/blockchain → blockchain}/CertificateToken.js +0 -0
  114. /package/src/{server/blockchain → blockchain}/CertificateToken.ts +0 -0
  115. /package/src/browser/{CertificateGeneratorBrowser.ts → CertificateGeneratorBrowser.ts-remove} +0 -0
@@ -1,31 +0,0 @@
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[]>;
@@ -1,259 +0,0 @@
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
- }
@@ -1,20 +0,0 @@
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>;