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.
Files changed (135) hide show
  1. package/README.md +400 -0
  2. package/contracts/Lock.sol +34 -0
  3. package/contracts/bytecode.txt +1 -0
  4. package/contracts/compile-contract.js +168 -0
  5. package/contracts/deploy/deploy-both-contracts.js +286 -0
  6. package/contracts/deploy/deploy-enhanced-contract.js +197 -0
  7. package/contracts/deploy/deploy-private-contract.js +190 -0
  8. package/contracts/deploy/deploy-public-clean.js +1063 -0
  9. package/contracts/deploy/deploy-public-contract.js +1107 -0
  10. package/contracts/deployment.config.example.js +25 -0
  11. package/contracts/remix-compile.js +222 -0
  12. package/contracts/setup-deployment.js +51 -0
  13. package/contracts/src/NZIP-NFT-Private.sol +350 -0
  14. package/contracts/src/NZIP-NFT.sol +265 -0
  15. package/contracts/src/ZipFileNFT-DEPRECATED-6field.sol +260 -0
  16. package/contracts/src/ZipFileNFT-DEPRECATED-Enhanced.sol +289 -0
  17. package/dist/browser/CertificateGeneratorBrowser.d.ts +75 -0
  18. package/dist/browser/CertificateGeneratorBrowser.js +433 -0
  19. package/dist/browser/TokenVerifierBrowser.d.ts +76 -0
  20. package/dist/browser/TokenVerifierBrowser.js +299 -0
  21. package/dist/browser/ZipKitBrowser.d.ts +18 -0
  22. package/dist/browser/ZipKitBrowser.js +250 -0
  23. package/dist/browser/ZipKitStampBrowser.d.ts +2 -0
  24. package/dist/browser/ZipKitStampBrowser.js +12 -0
  25. package/dist/browser-index.d.ts +21 -0
  26. package/dist/browser-index.js +58 -0
  27. package/dist/browser.d.ts +21 -0
  28. package/dist/browser.js +58 -0
  29. package/dist/index.d.ts +29 -0
  30. package/dist/index.js +76 -0
  31. package/dist/server/blockchain/CertificateToken.d.ts +48 -0
  32. package/dist/server/blockchain/CertificateToken.js +386 -0
  33. package/dist/server/blockchain/NFTMinter.d.ts +41 -0
  34. package/dist/server/blockchain/NFTMinter.js +323 -0
  35. package/dist/server/blockchain/TokenQuerier.d.ts +31 -0
  36. package/dist/server/blockchain/TokenQuerier.js +259 -0
  37. package/dist/server/blockchain/TokenVerifier.d.ts +20 -0
  38. package/dist/server/blockchain/TokenVerifier.js +395 -0
  39. package/dist/server/blockchain/WalletAnalyzer.d.ts +81 -0
  40. package/dist/server/blockchain/WalletAnalyzer.js +356 -0
  41. package/dist/server/blockchain/WalletFormatter.d.ts +39 -0
  42. package/dist/server/blockchain/WalletFormatter.js +196 -0
  43. package/dist/server/blockchain/WalletManager.d.ts +46 -0
  44. package/dist/server/blockchain/WalletManager.js +294 -0
  45. package/dist/server/blockchain/ZipMetadata.d.ts +27 -0
  46. package/dist/server/blockchain/ZipMetadata.js +131 -0
  47. package/dist/server/blockchain/ZipTokenProcessor.d.ts +44 -0
  48. package/dist/server/blockchain/ZipTokenProcessor.js +204 -0
  49. package/dist/server/blockchain/constants.d.ts +102 -0
  50. package/dist/server/blockchain/constants.js +968 -0
  51. package/dist/server/blockchain/index.d.ts +9 -0
  52. package/dist/server/blockchain/index.js +44 -0
  53. package/dist/server/blockchain/test-certificate.d.ts +8 -0
  54. package/dist/server/blockchain/test-certificate.js +100 -0
  55. package/dist/server/blockchain/types.d.ts +69 -0
  56. package/dist/server/blockchain/types.js +51 -0
  57. package/dist/server/platform/server/ZipKitServer.d.ts +105 -0
  58. package/dist/server/platform/server/ZipKitServer.js +437 -0
  59. package/dist/server/platform/servercomponents/ZipKitOTS.d.ts +91 -0
  60. package/dist/server/platform/servercomponents/ZipKitOTS.js +271 -0
  61. package/dist/shared/ZipEntry.d.ts +131 -0
  62. package/dist/shared/ZipEntry.js +686 -0
  63. package/dist/shared/ZipKit.d.ts +249 -0
  64. package/dist/shared/ZipKit.js +789 -0
  65. package/dist/shared/components/CertificateOTS.d.ts +15 -0
  66. package/dist/shared/components/CertificateOTS.js +116 -0
  67. package/dist/shared/components/FileSys.d.ts +2 -0
  68. package/dist/shared/components/FileSys.js +113 -0
  69. package/dist/shared/components/HashAccumulator.d.ts +55 -0
  70. package/dist/shared/components/HashAccumulator.js +100 -0
  71. package/dist/shared/components/Support.d.ts +63 -0
  72. package/dist/shared/components/Support.js +70 -0
  73. package/dist/shared/components/Util.d.ts +21 -0
  74. package/dist/shared/components/Util.js +115 -0
  75. package/dist/shared/components/ZipCrypto.d.ts +3 -0
  76. package/dist/shared/components/ZipCrypto.js +78 -0
  77. package/dist/shared/components/merkleTree.d.ts +66 -0
  78. package/dist/shared/components/merkleTree.js +136 -0
  79. package/dist/shared/constants/Errors.d.ts +53 -0
  80. package/dist/shared/constants/Errors.js +69 -0
  81. package/dist/shared/constants/Headers.d.ts +167 -0
  82. package/dist/shared/constants/Headers.js +191 -0
  83. package/dist/shared/types/index.d.ts +21 -0
  84. package/dist/shared/types/index.js +3 -0
  85. package/dist/shared/types.d.ts +33 -0
  86. package/dist/shared/types.js +8 -0
  87. package/dist/shared/version.d.ts +4 -0
  88. package/dist/shared/version.js +7 -0
  89. package/dist/types/index.d.ts +21 -0
  90. package/dist/types/index.js +3 -0
  91. package/examples/unzip-token.ts +488 -0
  92. package/examples/zip-token.ts +604 -0
  93. package/package.json +117 -0
  94. package/src/browser/CertificateGeneratorBrowser.ts +498 -0
  95. package/src/browser/TokenVerifierBrowser.ts +344 -0
  96. package/src/browser/ZipKitBrowser.ts +242 -0
  97. package/src/browser/ZipKitStampBrowser.ts +9 -0
  98. package/src/browser-index.ts +36 -0
  99. package/src/index.ts +48 -0
  100. package/src/server/blockchain/CertificateToken.ts +444 -0
  101. package/src/server/blockchain/NFTMinter.ts +357 -0
  102. package/src/server/blockchain/TokenQuerier.ts +287 -0
  103. package/src/server/blockchain/TokenVerifier.ts +453 -0
  104. package/src/server/blockchain/WalletAnalyzer.ts +397 -0
  105. package/src/server/blockchain/WalletFormatter.ts +206 -0
  106. package/src/server/blockchain/WalletManager.ts +294 -0
  107. package/src/server/blockchain/ZipMetadata.ts +117 -0
  108. package/src/server/blockchain/ZipTokenProcessor.ts +234 -0
  109. package/src/server/blockchain/constants.ts +969 -0
  110. package/src/server/blockchain/index.ts +42 -0
  111. package/src/server/blockchain/test-certificate.ts +137 -0
  112. package/src/server/blockchain/types.ts +134 -0
  113. package/src/server/platform/server/ZipKitServer.ts +459 -0
  114. package/src/server/platform/servercomponents/ZipKitOTS.ts +313 -0
  115. package/src/server/platform/servercomponents/opentimestamps.d.ts +23 -0
  116. package/src/shared/ZipEntry.ts +767 -0
  117. package/src/shared/ZipKit.ts +899 -0
  118. package/src/shared/components/CertificateOTS.ts +132 -0
  119. package/src/shared/components/FileSys.ts +87 -0
  120. package/src/shared/components/HashAccumulator.ts +113 -0
  121. package/src/shared/components/Support.ts +77 -0
  122. package/src/shared/components/Util.ts +113 -0
  123. package/src/shared/components/ZipCrypto.ts +91 -0
  124. package/src/shared/components/merkleTree.ts +162 -0
  125. package/src/shared/constants/Errors.ts +82 -0
  126. package/src/shared/constants/Headers.ts +203 -0
  127. package/src/shared/types/index.ts +25 -0
  128. package/src/shared/types/modules.d.ts +22 -0
  129. package/src/shared/types/opentimestamps.d.ts +23 -0
  130. package/src/shared/types.d.ts +8 -0
  131. package/src/shared/types.ts +43 -0
  132. package/src/shared/version.ts +4 -0
  133. package/src/types/index.ts +25 -0
  134. package/src/types/modules.d.ts +22 -0
  135. package/src/types/opentimestamps.d.ts +23 -0
@@ -0,0 +1,299 @@
1
+ "use strict";
2
+ // ======================================
3
+ // TokenVerifierBrowser.ts
4
+ // Browser-compatible blockchain token verification 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.TokenVerifierBrowser = void 0;
42
+ exports.createTokenVerifier = createTokenVerifier;
43
+ exports.checkForTokenization = checkForTokenization;
44
+ const Headers_1 = require("../shared/constants/Headers");
45
+ const constants_1 = require("../server/blockchain/constants");
46
+ // Network configuration for blockchain queries
47
+ const NETWORK_CONFIG = {
48
+ 'Base Sepolia': {
49
+ chainId: 84532,
50
+ rpcUrls: [
51
+ 'https://sepolia.base.org',
52
+ 'https://base-sepolia.g.alchemy.com/v2/demo',
53
+ 'https://base-sepolia-rpc.publicnode.com',
54
+ 'https://base-sepolia.blockpi.network/v1/rpc/public'
55
+ ]
56
+ },
57
+ 'Base Mainnet': {
58
+ chainId: 8453,
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
+ }
66
+ };
67
+ // Use the complete contract ABI from constants
68
+ const CONTRACT_ABI = constants_1.NZIP_CONTRACT_ABI;
69
+ /**
70
+ * Browser-compatible token verification class
71
+ */
72
+ class TokenVerifierBrowser {
73
+ constructor(zipKit) {
74
+ this.zipKit = zipKit;
75
+ }
76
+ /**
77
+ * Checks if the ZIP file contains NFT token metadata and verifies the merkle root
78
+ */
79
+ async checkForTokenization(zipEntries, options = {}) {
80
+ // Look for the tokenized metadata file
81
+ const tokenEntry = zipEntries.find(entry => entry.filename === Headers_1.TOKENIZED_METADATA);
82
+ if (!tokenEntry) {
83
+ return {
84
+ isTokenized: false,
85
+ tokenMetadata: null,
86
+ calculatedMerkleRoot: null,
87
+ blockchainMerkleRoot: null,
88
+ verificationPassed: false
89
+ };
90
+ }
91
+ try {
92
+ // Extract the token metadata
93
+ const tokenData = await this.zipKit.extractBlob(tokenEntry);
94
+ if (!tokenData) {
95
+ return {
96
+ isTokenized: false,
97
+ tokenMetadata: null,
98
+ calculatedMerkleRoot: null,
99
+ blockchainMerkleRoot: null,
100
+ verificationPassed: false,
101
+ errorMessage: 'Could not read token metadata'
102
+ };
103
+ }
104
+ const tokenContent = await this.blobToString(tokenData);
105
+ const tokenMetadata = JSON.parse(tokenContent);
106
+ // Validate token metadata structure
107
+ if (!this.validateTokenInfo(tokenMetadata)) {
108
+ return {
109
+ isTokenized: false,
110
+ tokenMetadata: null,
111
+ calculatedMerkleRoot: null,
112
+ blockchainMerkleRoot: null,
113
+ verificationPassed: false,
114
+ errorMessage: 'Invalid token metadata structure'
115
+ };
116
+ }
117
+ // Skip verification if requested
118
+ if (options.skipHash || options.skipToken) {
119
+ return {
120
+ isTokenized: true,
121
+ tokenMetadata,
122
+ calculatedMerkleRoot: null,
123
+ blockchainMerkleRoot: null,
124
+ verificationPassed: false,
125
+ errorMessage: options.skipHash ? 'Hash verification skipped' : 'Token verification skipped'
126
+ };
127
+ }
128
+ // Calculate merkle root excluding token file
129
+ const calculatedMerkleRoot = await this.calculateMerkleRootExcludingToken(zipEntries);
130
+ if (!calculatedMerkleRoot) {
131
+ return {
132
+ isTokenized: true,
133
+ tokenMetadata,
134
+ calculatedMerkleRoot: null,
135
+ blockchainMerkleRoot: null,
136
+ verificationPassed: false,
137
+ errorMessage: 'Could not calculate merkle root'
138
+ };
139
+ }
140
+ // Query blockchain for the actual merkle root and timestamp
141
+ const blockchainData = await this.queryBlockchainData(tokenMetadata);
142
+ if (!blockchainData.merkleRoot) {
143
+ return {
144
+ isTokenized: true,
145
+ tokenMetadata,
146
+ calculatedMerkleRoot,
147
+ blockchainMerkleRoot: null,
148
+ blockchainTimestamp: blockchainData.timestamp ?? undefined,
149
+ verificationPassed: false,
150
+ errorMessage: 'Could not retrieve merkle root from blockchain'
151
+ };
152
+ }
153
+ const verificationPassed = blockchainData.merkleRoot === calculatedMerkleRoot;
154
+ return {
155
+ isTokenized: true,
156
+ tokenMetadata,
157
+ calculatedMerkleRoot,
158
+ blockchainMerkleRoot: blockchainData.merkleRoot,
159
+ blockchainTimestamp: blockchainData.timestamp ?? undefined,
160
+ verificationPassed,
161
+ errorMessage: verificationPassed ? undefined : 'Merkle root mismatch - archive may be tampered'
162
+ };
163
+ }
164
+ catch (error) {
165
+ return {
166
+ isTokenized: false,
167
+ tokenMetadata: null,
168
+ calculatedMerkleRoot: null,
169
+ blockchainMerkleRoot: null,
170
+ verificationPassed: false,
171
+ errorMessage: `Error processing token: ${error instanceof Error ? error.message : String(error)}`
172
+ };
173
+ }
174
+ }
175
+ /**
176
+ * Validates token metadata structure
177
+ */
178
+ validateTokenInfo(tokenMetadata) {
179
+ return tokenMetadata &&
180
+ typeof tokenMetadata.version === 'string' &&
181
+ typeof tokenMetadata.tokenId === 'string' &&
182
+ typeof tokenMetadata.contractAddress === 'string' &&
183
+ typeof tokenMetadata.network === 'string' &&
184
+ typeof tokenMetadata.networkChainId === 'number' &&
185
+ typeof tokenMetadata.transactionHash === 'string' &&
186
+ typeof tokenMetadata.merkleRoot === 'string' &&
187
+ typeof tokenMetadata.fileName === 'string' &&
188
+ typeof tokenMetadata.mintedAt === 'string';
189
+ }
190
+ /**
191
+ * Calculates the merkle root excluding the token metadata file
192
+ */
193
+ async calculateMerkleRootExcludingToken(zipEntries) {
194
+ try {
195
+ // Get all entries except the token file
196
+ const contentEntries = zipEntries.filter(entry => entry.filename !== Headers_1.TOKENIZED_METADATA);
197
+ if (contentEntries.length === 0) {
198
+ return null;
199
+ }
200
+ // For each content entry, ensure we have SHA-256 hash calculated
201
+ for (const entry of contentEntries) {
202
+ if (!entry.sha256) {
203
+ // Extract the file to calculate its SHA-256 hash
204
+ await this.zipKit.extractBlob(entry);
205
+ }
206
+ }
207
+ // Calculate merkle root from content files
208
+ // This would need to be implemented based on the ZipKit's merkle tree functionality
209
+ // For now, we'll use a placeholder that would need to be implemented
210
+ return await this.zipKit.getMerkleRoot?.() || null;
211
+ }
212
+ catch (error) {
213
+ console.error('Error calculating merkle root:', error);
214
+ return null;
215
+ }
216
+ }
217
+ /**
218
+ * Queries the blockchain to get the actual merkle root and timestamp stored in the smart contract
219
+ */
220
+ async queryBlockchainData(tokenMetadata) {
221
+ try {
222
+ // Dynamic import of ethers to avoid SSR issues
223
+ const { ethers } = await Promise.resolve().then(() => __importStar(require('ethers')));
224
+ const networkConfig = NETWORK_CONFIG[tokenMetadata.network];
225
+ if (!networkConfig) {
226
+ console.warn(`Unsupported network: ${tokenMetadata.network}`);
227
+ return { merkleRoot: null, timestamp: null };
228
+ }
229
+ // Try multiple RPC endpoints
230
+ for (const rpcUrl of networkConfig.rpcUrls) {
231
+ try {
232
+ const provider = new ethers.JsonRpcProvider(rpcUrl);
233
+ // Test connection with a timeout
234
+ const blockNumber = await Promise.race([
235
+ provider.getBlockNumber(),
236
+ new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout')), 5000))
237
+ ]);
238
+ // Create contract instance
239
+ const contract = new ethers.Contract(tokenMetadata.contractAddress, CONTRACT_ABI, provider);
240
+ // Call getZipFileInfo to get the blockchain-stored data
241
+ const zipInfo = await contract.getZipFileInfo(tokenMetadata.tokenId);
242
+ return {
243
+ merkleRoot: zipInfo.merkleRootHash,
244
+ timestamp: Number(zipInfo.tokenizationTime)
245
+ };
246
+ }
247
+ catch (error) {
248
+ console.warn(`RPC ${rpcUrl} failed:`, error);
249
+ continue;
250
+ }
251
+ }
252
+ console.warn(`All RPC endpoints failed for network: ${tokenMetadata.network}`);
253
+ return { merkleRoot: null, timestamp: null };
254
+ }
255
+ catch (error) {
256
+ console.error('Blockchain query error:', error);
257
+ return { merkleRoot: null, timestamp: null };
258
+ }
259
+ }
260
+ /**
261
+ * Helper to convert Blob to string
262
+ */
263
+ async blobToString(blob) {
264
+ return new Promise((resolve, reject) => {
265
+ const reader = new FileReader();
266
+ reader.onload = () => resolve(reader.result);
267
+ reader.onerror = reject;
268
+ reader.readAsText(blob);
269
+ });
270
+ }
271
+ /**
272
+ * Creates a formatted summary of token information
273
+ */
274
+ createTokenSummary(tokenMetadata) {
275
+ return `
276
+ 🎫 NFT Token Information:
277
+ Token ID: ${tokenMetadata.tokenId}
278
+ Network: ${tokenMetadata.network}
279
+ Contract: ${tokenMetadata.contractAddress}
280
+ Transaction: ${tokenMetadata.transactionHash}
281
+ File: ${tokenMetadata.fileName}
282
+ Minted: ${new Date(tokenMetadata.mintedAt).toLocaleString()}
283
+ `;
284
+ }
285
+ }
286
+ exports.TokenVerifierBrowser = TokenVerifierBrowser;
287
+ /**
288
+ * Creates a new TokenVerifierBrowser instance
289
+ */
290
+ function createTokenVerifier(zipKit) {
291
+ return new TokenVerifierBrowser(zipKit);
292
+ }
293
+ /**
294
+ * Convenience function to check for tokenization
295
+ */
296
+ async function checkForTokenization(zipKit, zipEntries, options = {}) {
297
+ const verifier = new TokenVerifierBrowser(zipKit);
298
+ return verifier.checkForTokenization(zipEntries, options);
299
+ }
@@ -0,0 +1,18 @@
1
+ import ZipKit, { CompressOptions, CreateZipOptions } from '../shared/ZipKit';
2
+ import ZipEntry from '../shared/ZipEntry';
3
+ import Errors from '../shared/constants/Errors';
4
+ import * as Headers from '../shared/constants/Headers';
5
+ import { sha256 } from '../shared/components/ZipCrypto';
6
+ import { getTypeOf } from '../shared/components/Util';
7
+ import type { FileData } from '../shared/types';
8
+ export * from '../shared/ZipKit';
9
+ export { ZipEntry, Errors, Headers, sha256, getTypeOf };
10
+ export default class ZipKitBrowser extends ZipKit {
11
+ constructor();
12
+ loadZipBlob(data: Blob): Promise<ZipEntry[] | null>;
13
+ createZipFileEntry(file: FileData): ZipEntry;
14
+ hashFile(file: FileData): Promise<string>;
15
+ compressDataBlob(entry: ZipEntry, data: Blob, options?: CompressOptions): Promise<Buffer>;
16
+ extractBlob(entry: ZipEntry, skipHashCheck?: boolean): Promise<Blob | null>;
17
+ createZipBlob(cmpOptions?: CompressOptions, options?: CreateZipOptions): Promise<Blob | null>;
18
+ }
@@ -0,0 +1,250 @@
1
+ "use strict";
2
+ // ======================================
3
+ // ZipKitBrowser.ts
4
+ // Copyright (c) 2025 NeoWare, Inc. All rights reserved.
5
+ // ======================================
6
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
+ if (k2 === undefined) k2 = k;
8
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
+ desc = { enumerable: true, get: function() { return m[k]; } };
11
+ }
12
+ Object.defineProperty(o, k2, desc);
13
+ }) : (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ o[k2] = m[k];
16
+ }));
17
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
19
+ }) : function(o, v) {
20
+ o["default"] = v;
21
+ });
22
+ var __importStar = (this && this.__importStar) || (function () {
23
+ var ownKeys = function(o) {
24
+ ownKeys = Object.getOwnPropertyNames || function (o) {
25
+ var ar = [];
26
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
+ return ar;
28
+ };
29
+ return ownKeys(o);
30
+ };
31
+ return function (mod) {
32
+ if (mod && mod.__esModule) return mod;
33
+ var result = {};
34
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
+ __setModuleDefault(result, mod);
36
+ return result;
37
+ };
38
+ })();
39
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
40
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
41
+ };
42
+ var __importDefault = (this && this.__importDefault) || function (mod) {
43
+ return (mod && mod.__esModule) ? mod : { "default": mod };
44
+ };
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.getTypeOf = exports.sha256 = exports.Headers = exports.Errors = exports.ZipEntry = void 0;
47
+ const ZipKit_1 = __importDefault(require("../shared/ZipKit"));
48
+ const ZipEntry_1 = __importDefault(require("../shared/ZipEntry"));
49
+ exports.ZipEntry = ZipEntry_1.default;
50
+ const Errors_1 = __importDefault(require("../shared/constants/Errors"));
51
+ exports.Errors = Errors_1.default;
52
+ const Headers = __importStar(require("../shared/constants/Headers"));
53
+ exports.Headers = Headers;
54
+ const Headers_1 = require("../shared/constants/Headers");
55
+ const ZipCrypto_1 = require("../shared/components/ZipCrypto");
56
+ Object.defineProperty(exports, "sha256", { enumerable: true, get: function () { return ZipCrypto_1.sha256; } });
57
+ const Util_1 = require("../shared/components/Util");
58
+ const Util_2 = require("../shared/components/Util");
59
+ Object.defineProperty(exports, "getTypeOf", { enumerable: true, get: function () { return Util_2.getTypeOf; } });
60
+ // Re-export everything from ZipKit
61
+ __exportStar(require("../shared/ZipKit"), exports);
62
+ // ======================================
63
+ // ZipKitBrowser
64
+ // ======================================
65
+ class ZipKitBrowser extends ZipKit_1.default {
66
+ constructor() {
67
+ super(); // Call the parent constructor
68
+ // console.log('ZipKit.support.isNode: ', ZipKit.support.isNode);
69
+ // console.log('ZipKit.support.buffer: ', ZipKit.support.buffer);
70
+ // console.log('ZipKit.support.blob: ', ZipKit.support.blob);
71
+ // console.log('ZipKit.support.streams: ', ZipKit.support.streams);
72
+ // console.log('ZipKit.support.fileReader: ', ZipKit.support.fileReader);
73
+ }
74
+ // --------------------------------------
75
+ // Load a ZIP file from a Blob and return the ZipEntry array
76
+ async loadZipBlob(data) {
77
+ if ((0, Util_2.getTypeOf)(data) !== Util_2.DATATYPE.BLOB) {
78
+ throw new Error(Errors_1.default.DATATYPE_UNSUPPORTED);
79
+ }
80
+ return new Promise((resolve, reject) => {
81
+ const _readEntries = (data) => {
82
+ try {
83
+ super.loadZip(data);
84
+ return super.getDirectory();
85
+ }
86
+ catch (error) {
87
+ reject(error);
88
+ return null;
89
+ }
90
+ };
91
+ const reader = new window.FileReader();
92
+ reader.readAsArrayBuffer(data);
93
+ reader.onload = function (e) {
94
+ if (!this.result) {
95
+ reject(new Error('Failed to read file'));
96
+ return;
97
+ }
98
+ const _inBuf = Buffer.from(this.result);
99
+ resolve(_readEntries(_inBuf));
100
+ };
101
+ reader.onerror = function (e) {
102
+ reject(this.error || new Error('Failed to read file'));
103
+ };
104
+ });
105
+ }
106
+ // --------------------------------------
107
+ // Create a ZipEntry for a File object
108
+ createZipFileEntry(file) {
109
+ const entry = super.createZipEntry(file.name);
110
+ entry.fileData = file;
111
+ entry.uncompressedSize = file.size;
112
+ const fileDate = new Date(file.lastModified);
113
+ entry.timeDateDOS = entry.setDateTime(fileDate);
114
+ entry.cmpMethod = Headers.CMP_METHOD.DEFLATED;
115
+ return entry;
116
+ }
117
+ // --------------------------------------
118
+ // Calculate the SHA256 hash of a File object
119
+ async hashFile(file) {
120
+ const arrayBuffer = await file.arrayBuffer();
121
+ const buffer = Buffer.from(arrayBuffer);
122
+ return (0, ZipCrypto_1.sha256)(buffer);
123
+ }
124
+ // --------------------------------------
125
+ // Compress the data and return the compressed data buffer
126
+ // Set the ZipEntry compressSize and CRC32 values
127
+ async compressDataBlob(entry, data, options) {
128
+ if ((0, Util_2.getTypeOf)(data) !== Util_2.DATATYPE.BLOB) {
129
+ throw new Error(Errors_1.default.DATATYPE_UNSUPPORTED);
130
+ }
131
+ return new Promise(async (resolve, reject) => {
132
+ const _compressData = async (entry, data, options) => {
133
+ return await super.compressData(entry, data, options);
134
+ };
135
+ const reader = new window.FileReader();
136
+ reader.readAsArrayBuffer(data);
137
+ reader.onload = async function (e) {
138
+ if (!this.result) {
139
+ reject(new Error('Failed to read file'));
140
+ return;
141
+ }
142
+ try {
143
+ const _inBuf = Buffer.from(this.result);
144
+ const result = await _compressData(entry, _inBuf, options);
145
+ resolve(result);
146
+ }
147
+ catch (error) {
148
+ reject(error);
149
+ }
150
+ };
151
+ reader.onerror = function (e) {
152
+ reject(this.error || new Error('Failed to read file'));
153
+ };
154
+ });
155
+ }
156
+ // --------------------------------------
157
+ // Extract a Blob from a ZipEntry
158
+ async extractBlob(entry, skipHashCheck) {
159
+ try {
160
+ const _outBuf = await super.extract(entry, skipHashCheck);
161
+ if (!_outBuf)
162
+ return null;
163
+ // Convert Buffer to Uint8Array for Blob compatibility
164
+ const uint8Array = new Uint8Array(_outBuf);
165
+ return new Blob([uint8Array], { type: 'application/octet-stream' });
166
+ }
167
+ catch (error) {
168
+ throw error;
169
+ }
170
+ }
171
+ // --------------------------------------
172
+ // Create a ZIP file in memory and return a Blob
173
+ async createZipBlob(cmpOptions, options) {
174
+ const _onError = options?.onError || (() => { });
175
+ const _onEntryDone = options?.onEntryDone || (() => { });
176
+ const zipEntries = super.getDirectory();
177
+ if (!zipEntries) {
178
+ _onError(new Error(Errors_1.default.NO_FILES));
179
+ return null;
180
+ }
181
+ let offset = 0;
182
+ const buffers = [];
183
+ for (const entry of zipEntries) {
184
+ if (!entry.isUpdated) {
185
+ // CRITICAL FIX: Check for token files even in copy mode
186
+ if (entry.filename === Headers_1.TOKENIZED_METADATA || entry.filename === Headers_1.TIMESTAMP_SUBMITTED || entry.filename === Headers_1.TIMESTAMP_METADATA) {
187
+ // Force this entry to be processed with special handling instead of copied
188
+ entry.isUpdated = true;
189
+ // Don't continue here - let it fall through to special handling below
190
+ }
191
+ else {
192
+ const inData = super.copyEntry(entry);
193
+ entry.localHdrOffset = offset;
194
+ offset += inData.length;
195
+ buffers.push(inData);
196
+ _onEntryDone(entry, 'Copied');
197
+ continue;
198
+ }
199
+ }
200
+ if (!entry.fileData) {
201
+ _onError(new Error(Errors_1.default.FILE_NOT_FOUND));
202
+ return null;
203
+ }
204
+ const fileBuffer = await entry.fileData.arrayBuffer();
205
+ // Special handling for token metadata files - store uncompressed with CRC-32
206
+ if (entry.filename === Headers_1.TOKENIZED_METADATA || entry.filename === Headers_1.TIMESTAMP_SUBMITTED || entry.filename === Headers_1.TIMESTAMP_METADATA) {
207
+ // For token metadata, use STORED compression (no compression)
208
+ const buffer = Buffer.from(fileBuffer);
209
+ // Calculate CRC-32 for the token file (not SHA-256 to avoid Merkle Root interference)
210
+ entry.crc = (0, Util_1.crc32)(buffer);
211
+ // Set up entry for STORED compression
212
+ entry.cmpMethod = 0; // STORED
213
+ entry.compressedSize = buffer.length;
214
+ entry.uncompressedSize = buffer.length;
215
+ // Do NOT set SHA-256 hash for token metadata to avoid Merkle Root calculation
216
+ // entry.sha256 should remain undefined for metadata files
217
+ const localHdr = entry.createLocalHdr();
218
+ entry.localHdrOffset = offset;
219
+ offset += localHdr.length + buffer.length;
220
+ buffers.push(localHdr);
221
+ buffers.push(buffer);
222
+ _onEntryDone(entry, 'Stored (metadata)');
223
+ }
224
+ else {
225
+ // Normal file processing with compression
226
+ const cmpData = await super.compressData(entry, Buffer.from(fileBuffer), cmpOptions);
227
+ const localHdr = entry.createLocalHdr();
228
+ entry.localHdrOffset = offset;
229
+ offset += localHdr.length + cmpData.length;
230
+ buffers.push(localHdr);
231
+ buffers.push(cmpData);
232
+ _onEntryDone(entry, 'Written');
233
+ }
234
+ }
235
+ const centralDirOffset = offset;
236
+ for (const entry of zipEntries) {
237
+ const centralDirEntry = entry.centralDirEntry();
238
+ offset += centralDirEntry.length;
239
+ buffers.push(centralDirEntry);
240
+ }
241
+ const centralDirSize = offset - centralDirOffset;
242
+ const ceBuf = super.centralEndHdr(centralDirSize, centralDirOffset);
243
+ buffers.push(ceBuf);
244
+ const combinedBuffer = Buffer.concat(buffers);
245
+ // Convert Buffer to Uint8Array for Blob compatibility
246
+ const uint8Array = new Uint8Array(combinedBuffer);
247
+ return new Blob([uint8Array], { type: 'application/zip' });
248
+ }
249
+ }
250
+ exports.default = ZipKitBrowser;
@@ -0,0 +1,2 @@
1
+ export declare const createTimestamp: (hash: string, options?: any) => Promise<any>;
2
+ export declare const verifyTimestamp: (timestamp: any, options?: any) => Promise<any>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ // A browser-safe version of ZipKitStamp
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.verifyTimestamp = exports.createTimestamp = void 0;
5
+ const createTimestamp = async (hash, options = {}) => {
6
+ throw new Error('Blockchain timestamp creation is not supported in browsers');
7
+ };
8
+ exports.createTimestamp = createTimestamp;
9
+ const verifyTimestamp = async (timestamp, options = {}) => {
10
+ throw new Error('Blockchain timestamp verification is not supported in browsers');
11
+ };
12
+ exports.verifyTimestamp = verifyTimestamp;
@@ -0,0 +1,21 @@
1
+ import ZipKit from './shared/ZipKit';
2
+ export { ZipEntry, Errors, CMP_METHOD, TIMESTAMP_METADATA, TIMESTAMP_SUBMITTED } from './shared/ZipKit';
3
+ export type { CompressOptions } from './shared/ZipKit';
4
+ export * from './shared/ZipKit';
5
+ export * from './shared/ZipEntry';
6
+ export default ZipKit;
7
+ export { default as ZipKitBrowser } from './browser/ZipKitBrowser';
8
+ export { CertificateGeneratorBrowser } from './browser/CertificateGeneratorBrowser';
9
+ export { TokenVerificationResult, checkForTokenization as checkForTokenizationBrowser, NZipTokenInfo } from './browser/TokenVerifierBrowser';
10
+ export type { TokenVerificationOptions } from './browser/TokenVerifierBrowser';
11
+ export { default as HashAccumulator } from './shared/components/HashAccumulator';
12
+ export * from './shared/components/Util';
13
+ export * from './shared/components/Support';
14
+ export * from './shared/types';
15
+ export * from './shared/constants/Headers';
16
+ export * from './shared/constants/Errors';
17
+ export * from './shared/version';
18
+ export declare const PlatformUtils: {
19
+ isBrowser: boolean;
20
+ isNode: string | false;
21
+ };
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ // =============================================================================
3
+ // NeoZipKit - Browser-Only Package Exports
4
+ // =============================================================================
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
18
+ };
19
+ var __importDefault = (this && this.__importDefault) || function (mod) {
20
+ return (mod && mod.__esModule) ? mod : { "default": mod };
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.PlatformUtils = exports.HashAccumulator = exports.checkForTokenizationBrowser = exports.CertificateGeneratorBrowser = exports.ZipKitBrowser = exports.TIMESTAMP_SUBMITTED = exports.TIMESTAMP_METADATA = exports.CMP_METHOD = exports.Errors = exports.ZipEntry = void 0;
24
+ // Core shared exports
25
+ const ZipKit_1 = __importDefault(require("./shared/ZipKit"));
26
+ var ZipKit_2 = require("./shared/ZipKit");
27
+ Object.defineProperty(exports, "ZipEntry", { enumerable: true, get: function () { return ZipKit_2.ZipEntry; } });
28
+ Object.defineProperty(exports, "Errors", { enumerable: true, get: function () { return ZipKit_2.Errors; } });
29
+ Object.defineProperty(exports, "CMP_METHOD", { enumerable: true, get: function () { return ZipKit_2.CMP_METHOD; } });
30
+ Object.defineProperty(exports, "TIMESTAMP_METADATA", { enumerable: true, get: function () { return ZipKit_2.TIMESTAMP_METADATA; } });
31
+ Object.defineProperty(exports, "TIMESTAMP_SUBMITTED", { enumerable: true, get: function () { return ZipKit_2.TIMESTAMP_SUBMITTED; } });
32
+ __exportStar(require("./shared/ZipKit"), exports);
33
+ __exportStar(require("./shared/ZipEntry"), exports);
34
+ exports.default = ZipKit_1.default;
35
+ // Browser-only exports
36
+ var ZipKitBrowser_1 = require("./browser/ZipKitBrowser");
37
+ Object.defineProperty(exports, "ZipKitBrowser", { enumerable: true, get: function () { return __importDefault(ZipKitBrowser_1).default; } });
38
+ var CertificateGeneratorBrowser_1 = require("./browser/CertificateGeneratorBrowser");
39
+ Object.defineProperty(exports, "CertificateGeneratorBrowser", { enumerable: true, get: function () { return CertificateGeneratorBrowser_1.CertificateGeneratorBrowser; } });
40
+ var TokenVerifierBrowser_1 = require("./browser/TokenVerifierBrowser");
41
+ Object.defineProperty(exports, "checkForTokenizationBrowser", { enumerable: true, get: function () { return TokenVerifierBrowser_1.checkForTokenization; } });
42
+ // Shared component exports
43
+ var HashAccumulator_1 = require("./shared/components/HashAccumulator");
44
+ Object.defineProperty(exports, "HashAccumulator", { enumerable: true, get: function () { return __importDefault(HashAccumulator_1).default; } });
45
+ __exportStar(require("./shared/components/Util"), exports);
46
+ __exportStar(require("./shared/components/Support"), exports);
47
+ // Type and constant exports
48
+ __exportStar(require("./shared/types"), exports);
49
+ __exportStar(require("./shared/constants/Headers"), exports);
50
+ __exportStar(require("./shared/constants/Errors"), exports);
51
+ __exportStar(require("./shared/version"), exports);
52
+ // Platform-specific conditional exports
53
+ exports.PlatformUtils = {
54
+ // Browser detection
55
+ isBrowser: typeof window !== 'undefined' && typeof document !== 'undefined',
56
+ // Node.js detection
57
+ isNode: typeof process !== 'undefined' && process.versions && process.versions.node,
58
+ };