neozipkit 0.2.1 → 0.3.0

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 (301) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +410 -186
  3. package/contracts/ABI.txt +889 -0
  4. package/contracts/Bytecode.txt +1 -0
  5. package/contracts/COMPILATION_NOTES.md +59 -0
  6. package/contracts/QUICK_DEPLOY.md +286 -0
  7. package/contracts/README.md +235 -131
  8. package/contracts/VERIFICATION.md +308 -0
  9. package/contracts/deploy-interactive.js +448 -0
  10. package/contracts/deployment-arbitrum-sepolia.json +12 -0
  11. package/contracts/deployment-arbitrum.json +12 -0
  12. package/contracts/deployment-eth-sepolia.json +12 -0
  13. package/contracts/hardhat.config.js +114 -0
  14. package/contracts/package.json +20 -0
  15. package/contracts/scripts/compile-and-extract.js +119 -0
  16. package/contracts/scripts/verify-contract.js +223 -0
  17. package/contracts/src/{NZIP-NFT-Private.sol → NZIP-NFT-v2.0.sol} +66 -151
  18. package/contracts/src/NZIP-NFT.sol +9 -15
  19. package/dist/blockchain/browser/TokenVerifierBrowser.d.ts +67 -0
  20. package/dist/blockchain/browser/TokenVerifierBrowser.d.ts.map +1 -0
  21. package/dist/blockchain/browser/TokenVerifierBrowser.js +313 -0
  22. package/dist/blockchain/browser/TokenVerifierBrowser.js.map +1 -0
  23. package/dist/blockchain/browser/WalletManagerBrowser.d.ts +98 -0
  24. package/dist/blockchain/browser/WalletManagerBrowser.d.ts.map +1 -0
  25. package/dist/blockchain/browser/WalletManagerBrowser.js +434 -0
  26. package/dist/blockchain/browser/WalletManagerBrowser.js.map +1 -0
  27. package/dist/blockchain/browser/ZipkitMinterBrowser.d.ts +58 -0
  28. package/dist/blockchain/browser/ZipkitMinterBrowser.d.ts.map +1 -0
  29. package/dist/blockchain/browser/ZipkitMinterBrowser.js +317 -0
  30. package/dist/blockchain/browser/ZipkitMinterBrowser.js.map +1 -0
  31. package/dist/blockchain/browser/index.d.ts +11 -0
  32. package/dist/blockchain/browser/index.d.ts.map +1 -0
  33. package/dist/blockchain/browser/index.js +16 -0
  34. package/dist/blockchain/browser/index.js.map +1 -0
  35. package/dist/blockchain/core/WalletManager.d.ts +124 -0
  36. package/dist/blockchain/core/WalletManager.d.ts.map +1 -0
  37. package/dist/blockchain/{ZipKitWallet.js → core/WalletManager.js} +157 -177
  38. package/dist/blockchain/core/WalletManager.js.map +1 -0
  39. package/dist/blockchain/{ZipKitMinter.d.ts → core/ZipkitMinter.d.ts} +46 -11
  40. package/dist/blockchain/core/ZipkitMinter.d.ts.map +1 -0
  41. package/dist/blockchain/core/ZipkitMinter.js +548 -0
  42. package/dist/blockchain/core/ZipkitMinter.js.map +1 -0
  43. package/dist/blockchain/{ZipKitOTS.d.ts → core/ZipkitOTS.d.ts} +6 -15
  44. package/dist/blockchain/core/ZipkitOTS.d.ts.map +1 -0
  45. package/dist/blockchain/{ZipKitOTS.js → core/ZipkitOTS.js} +26 -84
  46. package/dist/blockchain/core/ZipkitOTS.js.map +1 -0
  47. package/dist/blockchain/core/ZipkitVerifier.d.ts +177 -0
  48. package/dist/blockchain/core/ZipkitVerifier.d.ts.map +1 -0
  49. package/dist/blockchain/core/ZipkitVerifier.js +632 -0
  50. package/dist/blockchain/core/ZipkitVerifier.js.map +1 -0
  51. package/dist/blockchain/core/contracts.d.ts +83 -0
  52. package/dist/blockchain/core/contracts.d.ts.map +1 -0
  53. package/dist/blockchain/core/contracts.js +341 -0
  54. package/dist/blockchain/core/contracts.js.map +1 -0
  55. package/dist/blockchain/core/index.d.ts +12 -0
  56. package/dist/blockchain/core/index.d.ts.map +1 -0
  57. package/dist/blockchain/core/index.js +59 -0
  58. package/dist/blockchain/core/index.js.map +1 -0
  59. package/dist/blockchain/index.d.ts +11 -7
  60. package/dist/blockchain/index.d.ts.map +1 -0
  61. package/dist/blockchain/index.js +18 -34
  62. package/dist/blockchain/index.js.map +1 -0
  63. package/dist/blockchain/node/WalletManagerNode.d.ts +47 -0
  64. package/dist/blockchain/node/WalletManagerNode.d.ts.map +1 -0
  65. package/dist/blockchain/node/WalletManagerNode.js +203 -0
  66. package/dist/blockchain/node/WalletManagerNode.js.map +1 -0
  67. package/dist/blockchain/node/index.d.ts +12 -0
  68. package/dist/blockchain/node/index.d.ts.map +1 -0
  69. package/dist/blockchain/node/index.js +24 -0
  70. package/dist/blockchain/node/index.js.map +1 -0
  71. package/dist/browser/ZipkitBrowser.d.ts +27 -0
  72. package/dist/browser/ZipkitBrowser.d.ts.map +1 -0
  73. package/dist/browser/{ZipKitBrowser.js → ZipkitBrowser.js} +96 -43
  74. package/dist/browser/ZipkitBrowser.js.map +1 -0
  75. package/dist/browser/index.d.ts +12 -0
  76. package/dist/browser/index.d.ts.map +1 -0
  77. package/dist/browser/index.js +42 -0
  78. package/dist/browser/index.js.map +1 -0
  79. package/dist/browser-esm/index.d.ts +12 -0
  80. package/dist/browser-esm/index.js +59559 -0
  81. package/dist/browser-esm/index.js.map +7 -0
  82. package/dist/browser-umd/index.d.ts +12 -0
  83. package/dist/browser-umd/index.js +59576 -0
  84. package/dist/browser-umd/index.js.map +7 -0
  85. package/dist/browser-umd/index.min.js +63 -0
  86. package/dist/browser.d.ts +8 -14
  87. package/dist/browser.js +13 -28
  88. package/dist/core/ZipCompress.d.ts +99 -0
  89. package/dist/core/ZipCompress.d.ts.map +1 -0
  90. package/dist/core/ZipCompress.js +309 -0
  91. package/dist/core/ZipCompress.js.map +1 -0
  92. package/dist/core/ZipDecompress.d.ts +58 -0
  93. package/dist/core/ZipDecompress.d.ts.map +1 -0
  94. package/dist/core/ZipDecompress.js +172 -0
  95. package/dist/core/ZipDecompress.js.map +1 -0
  96. package/dist/{shared → core}/ZipEntry.d.ts +8 -1
  97. package/dist/core/ZipEntry.d.ts.map +1 -0
  98. package/dist/{shared → core}/ZipEntry.js +225 -82
  99. package/dist/core/ZipEntry.js.map +1 -0
  100. package/dist/core/Zipkit.d.ts +315 -0
  101. package/dist/core/Zipkit.d.ts.map +1 -0
  102. package/dist/core/Zipkit.js +647 -0
  103. package/dist/core/Zipkit.js.map +1 -0
  104. package/dist/core/components/HashCalculator.d.ts +138 -0
  105. package/dist/core/components/HashCalculator.d.ts.map +1 -0
  106. package/dist/core/components/HashCalculator.js +360 -0
  107. package/dist/core/components/HashCalculator.js.map +1 -0
  108. package/dist/core/components/Logger.d.ts +73 -0
  109. package/dist/core/components/Logger.d.ts.map +1 -0
  110. package/dist/core/components/Logger.js +156 -0
  111. package/dist/core/components/Logger.js.map +1 -0
  112. package/dist/core/components/ProgressTracker.d.ts +43 -0
  113. package/dist/core/components/ProgressTracker.d.ts.map +1 -0
  114. package/dist/core/components/ProgressTracker.js +112 -0
  115. package/dist/core/components/ProgressTracker.js.map +1 -0
  116. package/dist/{shared → core}/components/Support.d.ts +1 -0
  117. package/dist/core/components/Support.d.ts.map +1 -0
  118. package/dist/{shared → core}/components/Support.js +1 -0
  119. package/dist/core/components/Support.js.map +1 -0
  120. package/dist/{shared → core}/components/Util.d.ts +7 -2
  121. package/dist/core/components/Util.d.ts.map +1 -0
  122. package/dist/{shared → core}/components/Util.js +14 -34
  123. package/dist/core/components/Util.js.map +1 -0
  124. package/dist/{shared → core}/constants/Errors.d.ts +1 -2
  125. package/dist/core/constants/Errors.d.ts.map +1 -0
  126. package/dist/{shared → core}/constants/Errors.js +1 -3
  127. package/dist/core/constants/Errors.js.map +1 -0
  128. package/dist/{shared → core}/constants/Headers.d.ts +3 -0
  129. package/dist/core/constants/Headers.d.ts.map +1 -0
  130. package/dist/{shared → core}/constants/Headers.js +20 -17
  131. package/dist/core/constants/Headers.js.map +1 -0
  132. package/dist/core/encryption/Manager.d.ts +58 -0
  133. package/dist/core/encryption/Manager.d.ts.map +1 -0
  134. package/dist/core/encryption/Manager.js +121 -0
  135. package/dist/core/encryption/Manager.js.map +1 -0
  136. package/dist/core/encryption/ZipCrypto.d.ts +172 -0
  137. package/dist/core/encryption/ZipCrypto.d.ts.map +1 -0
  138. package/dist/core/encryption/ZipCrypto.js +554 -0
  139. package/dist/core/encryption/ZipCrypto.js.map +1 -0
  140. package/dist/core/encryption/index.d.ts +9 -0
  141. package/dist/core/encryption/index.d.ts.map +1 -0
  142. package/dist/core/encryption/index.js +17 -0
  143. package/dist/core/encryption/index.js.map +1 -0
  144. package/dist/core/encryption/types.d.ts +29 -0
  145. package/dist/core/encryption/types.d.ts.map +1 -0
  146. package/dist/core/encryption/types.js +12 -0
  147. package/dist/core/encryption/types.js.map +1 -0
  148. package/dist/core/index.d.ts +24 -0
  149. package/dist/core/index.d.ts.map +1 -0
  150. package/dist/core/index.js +57 -0
  151. package/dist/core/index.js.map +1 -0
  152. package/dist/core/version.d.ts +5 -0
  153. package/dist/core/version.d.ts.map +1 -0
  154. package/dist/core/version.js +31 -0
  155. package/dist/core/version.js.map +1 -0
  156. package/dist/index.d.ts +8 -18
  157. package/dist/index.d.ts.map +1 -0
  158. package/dist/index.js +29 -35
  159. package/dist/index.js.map +1 -0
  160. package/dist/node/ZipCompressNode.d.ts +123 -0
  161. package/dist/node/ZipCompressNode.d.ts.map +1 -0
  162. package/dist/node/ZipCompressNode.js +576 -0
  163. package/dist/node/ZipCompressNode.js.map +1 -0
  164. package/dist/node/ZipDecompressNode.d.ts +120 -0
  165. package/dist/node/ZipDecompressNode.d.ts.map +1 -0
  166. package/dist/node/ZipDecompressNode.js +461 -0
  167. package/dist/node/ZipDecompressNode.js.map +1 -0
  168. package/dist/node/ZipkitNode.d.ts +406 -0
  169. package/dist/node/ZipkitNode.d.ts.map +1 -0
  170. package/dist/node/ZipkitNode.js +1305 -0
  171. package/dist/node/ZipkitNode.js.map +1 -0
  172. package/dist/node/index.d.ts +26 -0
  173. package/dist/node/index.d.ts.map +1 -0
  174. package/dist/node/index.js +65 -0
  175. package/dist/node/index.js.map +1 -0
  176. package/dist/types/index.d.ts +59 -0
  177. package/dist/types/index.d.ts.map +1 -0
  178. package/dist/types/index.js +36 -1
  179. package/dist/types/index.js.map +1 -0
  180. package/examples/README.md +269 -0
  181. package/examples/blockchain-tokenize.ts +354 -0
  182. package/examples/create-zip.ts +172 -0
  183. package/examples/extract-zip.ts +158 -0
  184. package/examples/list-zip.ts +161 -0
  185. package/examples/test-files/data.json +116 -0
  186. package/examples/test-files/document.md +80 -0
  187. package/examples/test-files/document.txt +2 -0
  188. package/examples/test-files/file1.txt +48 -0
  189. package/examples/test-files/file2.txt +80 -0
  190. package/examples/tsconfig.json +44 -0
  191. package/examples/unzip-token.ts +491 -0
  192. package/examples/verify-tokenized-zip.ts +305 -0
  193. package/examples/zip-token.ts +604 -0
  194. package/package.json +108 -24
  195. package/src/blockchain/README.md +59 -66
  196. package/src/{browser/TokenVerifierBrowser.ts-remove → blockchain/browser/TokenVerifierBrowser.ts} +125 -79
  197. package/src/blockchain/browser/WalletManagerBrowser.ts +486 -0
  198. package/src/blockchain/browser/ZipkitMinterBrowser.ts +400 -0
  199. package/src/blockchain/browser/index.ts +13 -0
  200. package/src/blockchain/{ZipKitWallet.ts → core/WalletManager.ts} +241 -143
  201. package/src/blockchain/core/ZipkitMinter.ts +716 -0
  202. package/src/blockchain/{ZipKitOTS.ts → core/ZipkitOTS.ts} +28 -62
  203. package/src/blockchain/core/ZipkitVerifier.ts +853 -0
  204. package/src/blockchain/core/contracts.ts +370 -0
  205. package/src/blockchain/core/index.ts +71 -0
  206. package/src/blockchain/index.ts +21 -55
  207. package/src/blockchain/node/WalletManagerNode.ts +171 -0
  208. package/src/blockchain/node/index.ts +40 -0
  209. package/src/browser/{ZipKitBrowser.ts → ZipkitBrowser.ts} +104 -41
  210. package/src/browser/index.esm.ts +37 -0
  211. package/src/browser/index.ts +25 -0
  212. package/src/core/ZipCompress.ts +398 -0
  213. package/src/core/ZipDecompress.ts +212 -0
  214. package/src/{shared → core}/ZipEntry.ts +240 -90
  215. package/src/core/Zipkit.ts +794 -0
  216. package/src/core/components/HashCalculator.ts +384 -0
  217. package/src/core/components/Logger.ts +180 -0
  218. package/src/core/components/ProgressTracker.ts +134 -0
  219. package/src/{shared → core}/components/Util.ts +12 -34
  220. package/src/{shared → core}/constants/Errors.ts +0 -4
  221. package/src/{shared → core}/constants/Headers.ts +19 -17
  222. package/src/core/encryption/Manager.ts +137 -0
  223. package/src/core/encryption/ZipCrypto.ts +650 -0
  224. package/src/core/encryption/index.ts +15 -0
  225. package/src/core/encryption/types.ts +33 -0
  226. package/src/core/index.ts +34 -0
  227. package/src/core/version.ts +33 -0
  228. package/src/index.ts +54 -25
  229. package/src/node/ZipCompressNode.ts +632 -0
  230. package/src/node/ZipDecompressNode.ts +508 -0
  231. package/src/node/ZipkitNode.ts +1559 -0
  232. package/src/node/index.ts +69 -0
  233. package/src/types/index.ts +131 -1
  234. package/src/types/modules.d.ts +1 -11
  235. package/src/types/opentimestamps.d.ts +1 -23
  236. package/contracts/INTEGRATION.md +0 -338
  237. package/contracts/NETWORKS.md +0 -156
  238. package/contracts/NZIP-NFT-bytecode.txt +0 -1
  239. package/contracts/constants.ts +0 -952
  240. package/contracts/deploy-bytecode.mjs +0 -94
  241. package/dist/blockchain/CertificateToken.d.ts +0 -48
  242. package/dist/blockchain/CertificateToken.js +0 -386
  243. package/dist/blockchain/ZipKitMinter.js +0 -347
  244. package/dist/blockchain/ZipKitNFT.d.ts +0 -3
  245. package/dist/blockchain/ZipKitNFT.js +0 -7
  246. package/dist/blockchain/ZipKitVerifier.d.ts +0 -69
  247. package/dist/blockchain/ZipKitVerifier.js +0 -289
  248. package/dist/blockchain/ZipKitWallet.d.ts +0 -69
  249. package/dist/blockchain/contracts.d.ts +0 -14
  250. package/dist/blockchain/contracts.js +0 -77
  251. package/dist/blockchain/types.d.ts +0 -47
  252. package/dist/blockchain/types.js +0 -30
  253. package/dist/browser/ZipKitBrowser.d.ts +0 -18
  254. package/dist/browser/ZipKitStampBrowser.d.ts +0 -2
  255. package/dist/browser/ZipKitStampBrowser.js +0 -12
  256. package/dist/browser-index.d.ts +0 -18
  257. package/dist/browser-index.js +0 -57
  258. package/dist/server/ZipKitServer.d.ts +0 -74
  259. package/dist/server/ZipKitServer.js +0 -310
  260. package/dist/shared/ZipKit.d.ts +0 -243
  261. package/dist/shared/ZipKit.js +0 -772
  262. package/dist/shared/components/CertificateOTS.d.ts +0 -15
  263. package/dist/shared/components/CertificateOTS.js +0 -116
  264. package/dist/shared/components/FileSys.d.ts +0 -2
  265. package/dist/shared/components/FileSys.js +0 -113
  266. package/dist/shared/components/HashAccumulator.d.ts +0 -55
  267. package/dist/shared/components/HashAccumulator.js +0 -100
  268. package/dist/shared/components/ZipCrypto.d.ts +0 -3
  269. package/dist/shared/components/ZipCrypto.js +0 -78
  270. package/dist/shared/components/merkleTree.d.ts +0 -66
  271. package/dist/shared/components/merkleTree.js +0 -136
  272. package/dist/shared/types/index.d.ts +0 -21
  273. package/dist/shared/types/index.js +0 -3
  274. package/dist/shared/types.d.ts +0 -33
  275. package/dist/shared/types.js +0 -8
  276. package/dist/shared/version.d.ts +0 -2
  277. package/dist/shared/version.js +0 -6
  278. package/src/blockchain/CertificateToken.ts +0 -444
  279. package/src/blockchain/ZipKitMinter.ts +0 -470
  280. package/src/blockchain/ZipKitNFT.ts +0 -12
  281. package/src/blockchain/ZipKitVerifier.ts +0 -382
  282. package/src/blockchain/contracts.ts +0 -88
  283. package/src/blockchain/types.ts +0 -91
  284. package/src/browser/CertificateGeneratorBrowser.ts-remove +0 -498
  285. package/src/browser/ZipKitStampBrowser.ts +0 -9
  286. package/src/browser-index.ts +0 -36
  287. package/src/server/README.md +0 -25
  288. package/src/server/ZipKitServer.ts +0 -305
  289. package/src/shared/ZipKit.ts +0 -881
  290. package/src/shared/components/CertificateOTS.ts +0 -132
  291. package/src/shared/components/FileSys.ts +0 -87
  292. package/src/shared/components/HashAccumulator.ts +0 -113
  293. package/src/shared/components/ZipCrypto.ts +0 -91
  294. package/src/shared/components/merkleTree.ts +0 -162
  295. package/src/shared/types/index.ts +0 -25
  296. package/src/shared/types/modules.d.ts +0 -22
  297. package/src/shared/types/opentimestamps.d.ts +0 -23
  298. package/src/shared/types.d.ts +0 -8
  299. package/src/shared/types.ts +0 -43
  300. package/src/shared/version.ts +0 -3
  301. /package/src/{shared → core}/components/Support.ts +0 -0
@@ -1,382 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * ZipKitVerifier - Handles NFT token verification for ZIP files
5
- * Verifier API for NZIP-NFT smart contract.
6
- */
7
-
8
- import { ethers } from 'ethers';
9
- import { NZIP_CONTRACT_ABI, CONTRACT_CONFIGS } from './contracts';
10
- import type { TokenMetadata } from './types';
11
-
12
- // Network configurations
13
- const NETWORK_CONFIGS = {
14
- 'base-sepolia': {
15
- name: 'Base Sepolia',
16
- rpcUrl: 'https://sepolia.base.org',
17
- contractAddress: 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: CONTRACT_CONFIGS[8453].address, // Use real contract address
25
- explorerUrl: 'https://basescan.org',
26
- chainId: 8453
27
- }
28
- };
29
-
30
- export interface VerificationOptions {
31
- debug?: boolean;
32
- skipHash?: boolean;
33
- }
34
-
35
- export interface VerificationResult {
36
- success: boolean;
37
- message: string;
38
- tokenMetadata?: TokenMetadata;
39
- verificationDetails?: {
40
- tokenId: string;
41
- network: string;
42
- contractAddress: string;
43
- merkleRoot: string;
44
- mintDate: string;
45
- calculatedMerkleRoot?: string;
46
- declaredMerkleRoot?: string;
47
- merkleRootMatch?: boolean;
48
- onChainValid?: boolean;
49
- };
50
- errorDetails?: {
51
- errorType: 'METADATA_ERROR' | 'MERKLE_ERROR' | 'NETWORK_ERROR' | 'CONTRACT_ERROR';
52
- networkName?: string;
53
- rpcUrl?: string;
54
- contractAddress?: string;
55
- tokenId?: string;
56
- merkleRoot?: string;
57
- };
58
- }
59
-
60
- /**
61
- * Blockchain Token Verifier for ZIP files
62
- */
63
- export class ZipKitVerifier {
64
- private debug: boolean;
65
-
66
- constructor(options: VerificationOptions = {}) {
67
- this.debug = options.debug || false;
68
-
69
- if (this.debug) {
70
- console.log(`[DEBUG] ZipKitVerifier initialized`);
71
- }
72
- }
73
-
74
- /**
75
- * Extract and validate token metadata from ZIP
76
- */
77
- async extractTokenMetadata(tokenBuffer: Buffer): Promise<{ success: boolean; metadata?: TokenMetadata; error?: string }> {
78
- try {
79
- if (this.debug) {
80
- console.log(`[DEBUG] Extracting token metadata from buffer (${tokenBuffer.length} bytes)`);
81
- }
82
-
83
- const tokenData = JSON.parse(tokenBuffer.toString('utf8'));
84
-
85
- // Validate required fields
86
- const requiredFields = ['tokenId', 'contractAddress', 'network'];
87
- for (const field of requiredFields) {
88
- if (!tokenData[field]) {
89
- if (this.debug) {
90
- console.log(`[DEBUG] Missing required field: ${field}`);
91
- }
92
- return {
93
- success: false,
94
- error: `Missing required field: ${field}`
95
- };
96
- }
97
- }
98
-
99
- if (this.debug) {
100
- console.log(`[DEBUG] Token metadata extracted successfully`);
101
- console.log(`[DEBUG] Token ID: ${tokenData.tokenId}, Network: ${tokenData.network}`);
102
- }
103
-
104
- return {
105
- success: true,
106
- metadata: tokenData as TokenMetadata
107
- };
108
-
109
- } catch (error) {
110
- const errorMessage = error instanceof Error ? error.message : 'Invalid JSON format';
111
-
112
- if (this.debug) {
113
- console.log(`[DEBUG] Failed to parse token metadata: ${errorMessage}`);
114
- }
115
-
116
- return {
117
- success: false,
118
- error: `Invalid token metadata format: ${errorMessage}`
119
- };
120
- }
121
- }
122
-
123
- /**
124
- * Map network name to RPC configuration
125
- */
126
- private getNetworkConfig(networkName: string): { success: boolean; config?: any; error?: string } {
127
- const normalizedName = networkName.toLowerCase();
128
-
129
- if (this.debug) {
130
- console.log(`[DEBUG] Looking up network config for: ${normalizedName}`);
131
- }
132
-
133
- // Map various network name variations to our configs
134
- if (normalizedName.includes('sepolia')) {
135
- return { success: true, config: NETWORK_CONFIGS['base-sepolia'] };
136
- } else if (normalizedName.includes('base') && !normalizedName.includes('sepolia')) {
137
- return { success: true, config: NETWORK_CONFIGS['base-mainnet'] };
138
- }
139
-
140
- if (this.debug) {
141
- console.log(`[DEBUG] Unsupported network: ${normalizedName}`);
142
- }
143
-
144
- return {
145
- success: false,
146
- error: `Unsupported network: ${networkName}`
147
- };
148
- }
149
-
150
- /**
151
- * Perform merkle root comparison
152
- */
153
- private compareMerkleRoots(calculated: string | null, declared: string | null): {
154
- success: boolean;
155
- match: boolean;
156
- calculated?: string;
157
- declared?: string;
158
- error?: string;
159
- } {
160
- if (this.debug) {
161
- console.log(`[DEBUG] Comparing merkle roots`);
162
- console.log(`[DEBUG] Calculated: ${calculated || 'null'}`);
163
- console.log(`[DEBUG] Declared: ${declared || 'null'}`);
164
- }
165
-
166
- if (!calculated) {
167
- return {
168
- success: false,
169
- match: false,
170
- error: 'Cannot calculate merkle root from archive contents'
171
- };
172
- }
173
-
174
- if (!declared) {
175
- return {
176
- success: false,
177
- match: false,
178
- calculated,
179
- error: 'No merkle root found in token metadata'
180
- };
181
- }
182
-
183
- const match = calculated === declared;
184
-
185
- if (this.debug) {
186
- console.log(`[DEBUG] Merkle root match: ${match}`);
187
- }
188
-
189
- return {
190
- success: true,
191
- match,
192
- calculated,
193
- declared
194
- };
195
- }
196
-
197
- /**
198
- * Verify token against blockchain
199
- */
200
- async verifyOnChain(
201
- tokenId: string,
202
- contractAddress: string,
203
- networkConfig: any,
204
- merkleRoot: string
205
- ): Promise<{ success: boolean; isValid?: boolean; error?: string }> {
206
- try {
207
- if (this.debug) {
208
- console.log(`[DEBUG] Starting on-chain verification`);
209
- console.log(`[DEBUG] Token ID: ${tokenId}, Contract: ${contractAddress}`);
210
- console.log(`[DEBUG] Network: ${networkConfig.name}, RPC: ${networkConfig.rpcUrl}`);
211
- }
212
-
213
- const provider = new ethers.JsonRpcProvider(networkConfig.rpcUrl);
214
- const contract = new ethers.Contract(contractAddress, NZIP_CONTRACT_ABI, provider);
215
-
216
- if (this.debug) {
217
- console.log(`[DEBUG] Calling contract.verifyZipFile(${tokenId}, ${merkleRoot.substring(0, 10)}...)`);
218
- }
219
-
220
- const isValid: boolean = await contract.verifyZipFile(tokenId, merkleRoot);
221
-
222
- if (this.debug) {
223
- console.log(`[DEBUG] On-chain verification result: ${isValid}`);
224
- }
225
-
226
- return { success: true, isValid };
227
-
228
- } catch (error) {
229
- const errorMessage = error instanceof Error ? error.message : 'Network error';
230
-
231
- if (this.debug) {
232
- console.log(`[DEBUG] On-chain verification failed: ${errorMessage}`);
233
- }
234
-
235
- return {
236
- success: false,
237
- error: errorMessage
238
- };
239
- }
240
- }
241
-
242
- /**
243
- * Complete verification process
244
- */
245
- async verifyToken(
246
- tokenMetadata: TokenMetadata,
247
- calculatedMerkleRoot: string | null,
248
- options: VerificationOptions = {}
249
- ): Promise<VerificationResult> {
250
- try {
251
- if (this.debug) {
252
- console.log(`[DEBUG] Starting complete token verification`);
253
- }
254
-
255
- // Get network configuration
256
- const networkResult = this.getNetworkConfig(tokenMetadata.network);
257
- if (!networkResult.success || !networkResult.config) {
258
- return {
259
- success: false,
260
- message: networkResult.error || 'Unknown network error',
261
- errorDetails: {
262
- errorType: 'NETWORK_ERROR',
263
- networkName: tokenMetadata.network
264
- }
265
- };
266
- }
267
-
268
- const networkConfig = networkResult.config;
269
- const declaredMerkleRoot = tokenMetadata.merkleRoot;
270
-
271
- // Compare merkle roots if hash verification is not skipped
272
- if (!options.skipHash) {
273
- const merkleComparison = this.compareMerkleRoots(calculatedMerkleRoot, declaredMerkleRoot);
274
-
275
- if (!merkleComparison.success) {
276
- return {
277
- success: false,
278
- message: merkleComparison.error || 'Merkle root verification failed',
279
- errorDetails: {
280
- errorType: 'MERKLE_ERROR',
281
- merkleRoot: declaredMerkleRoot || 'null'
282
- }
283
- };
284
- }
285
-
286
- if (!merkleComparison.match) {
287
- return {
288
- success: false,
289
- message: 'Archive integrity verification FAILED - merkle root mismatch',
290
- errorDetails: {
291
- errorType: 'MERKLE_ERROR',
292
- merkleRoot: `calculated: ${merkleComparison.calculated}, declared: ${merkleComparison.declared}`
293
- }
294
- };
295
- }
296
- }
297
-
298
- // Perform on-chain verification
299
- const merkleToVerify = calculatedMerkleRoot;
300
- if (!merkleToVerify) {
301
- return {
302
- success: false,
303
- message: 'No merkle root available for verification',
304
- errorDetails: {
305
- errorType: 'MERKLE_ERROR'
306
- }
307
- };
308
- }
309
-
310
- const onChainResult = await this.verifyOnChain(
311
- tokenMetadata.tokenId,
312
- tokenMetadata.contractAddress,
313
- networkConfig,
314
- merkleToVerify
315
- );
316
-
317
- if (!onChainResult.success) {
318
- return {
319
- success: false,
320
- message: `Blockchain verification failed: ${onChainResult.error}`,
321
- errorDetails: {
322
- errorType: 'CONTRACT_ERROR',
323
- networkName: tokenMetadata.network,
324
- rpcUrl: networkConfig.rpcUrl,
325
- contractAddress: tokenMetadata.contractAddress,
326
- tokenId: tokenMetadata.tokenId
327
- }
328
- };
329
- }
330
-
331
- if (!onChainResult.isValid) {
332
- return {
333
- success: false,
334
- message: 'Blockchain verification FAILED - token or merkle root invalid',
335
- errorDetails: {
336
- errorType: 'CONTRACT_ERROR',
337
- tokenId: tokenMetadata.tokenId,
338
- contractAddress: tokenMetadata.contractAddress,
339
- merkleRoot: merkleToVerify
340
- }
341
- };
342
- }
343
-
344
- // Success - create verification details
345
- const mintDate = tokenMetadata.mintDate ||
346
- (tokenMetadata.creationTimestamp ? new Date(tokenMetadata.creationTimestamp * 1000).toLocaleString() : '') ||
347
- '8/01/2025 at 1:00:00 PM'; // fallback
348
-
349
- return {
350
- success: true,
351
- message: 'Archive integrity VERIFIED against blockchain records',
352
- tokenMetadata,
353
- verificationDetails: {
354
- tokenId: tokenMetadata.tokenId,
355
- network: tokenMetadata.network,
356
- contractAddress: tokenMetadata.contractAddress,
357
- merkleRoot: merkleToVerify,
358
- mintDate,
359
- calculatedMerkleRoot: calculatedMerkleRoot || undefined,
360
- declaredMerkleRoot: declaredMerkleRoot || undefined,
361
- merkleRootMatch: !options.skipHash ? calculatedMerkleRoot === declaredMerkleRoot : undefined,
362
- onChainValid: true
363
- }
364
- };
365
-
366
- } catch (error) {
367
- const errorMessage = error instanceof Error ? error.message : 'Unknown verification error';
368
-
369
- if (this.debug) {
370
- console.log(`[DEBUG] Verification process failed: ${errorMessage}`);
371
- }
372
-
373
- return {
374
- success: false,
375
- message: `Tokenization verification failed: ${errorMessage}`,
376
- errorDetails: {
377
- errorType: 'METADATA_ERROR'
378
- }
379
- };
380
- }
381
- }
382
- }
@@ -1,88 +0,0 @@
1
- // Contract addresses and configurations for different networks
2
-
3
- export interface ContractConfig {
4
- address: string
5
- network: string
6
- chainId: number
7
- explorerUrl: string
8
- rpcUrls: string[]
9
- }
10
-
11
- // NZIP NFT Contract configurations by network
12
- export const CONTRACT_CONFIGS: Record<number, ContractConfig> = {
13
- // Base Sepolia (Primary testnet)
14
- 84532: {
15
- address: '0xFD76a5d420704F34d84b0767961835c43D7b30a8', // Production contract v2.0
16
- network: 'Base Sepolia',
17
- chainId: 84532,
18
- explorerUrl: 'https://sepolia.basescan.org',
19
- rpcUrls: [
20
- 'https://sepolia.base.org',
21
- 'https://base-sepolia.g.alchemy.com/v2/demo',
22
- 'https://base-sepolia-rpc.publicnode.com'
23
- ]
24
- },
25
-
26
- // Base Mainnet (Production)
27
- 8453: {
28
- address: '0x2716c4609fD97DaEdF429BC4B4Ec2faa81e2cC60',
29
- network: 'Base Mainnet',
30
- chainId: 8453,
31
- explorerUrl: 'https://basescan.org',
32
- rpcUrls: [
33
- 'https://mainnet.base.org',
34
- 'https://base.drpc.org',
35
- 'https://base.gateway.tenderly.co'
36
- ]
37
- },
38
-
39
- // Ethereum Sepolia (Testnet) - disabled until NZIP is deployed
40
- // 11155111: {
41
- // address: '0x0000000000000000000000000000000000000000',
42
- // network: 'Sepolia Testnet',
43
- // chainId: 11155111,
44
- // explorerUrl: 'https://sepolia.etherscan.io',
45
- // rpcUrls: []
46
- // },
47
-
48
- // Ethereum Mainnet (Production) - disabled until NZIP is deployed
49
- // 1: {
50
- // address: '0x0000000000000000000000000000000000000000',
51
- // network: 'Ethereum Mainnet',
52
- // chainId: 1,
53
- // explorerUrl: 'https://etherscan.io',
54
- // rpcUrls: []
55
- // }
56
- }
57
-
58
- // Contract ABI (same for all networks)
59
- export const NZIP_CONTRACT_ABI = [
60
- "function publicMintZipFile(string memory fileName, string memory merkleRootHash, uint256 creationTimestamp, string memory ipfsHash, string memory metadataURI) public returns (uint256)",
61
- "function totalSupply() external view returns (uint256)",
62
- "function getTokensByMerkleRoot(string memory merkleRoot) external view returns (uint256[])",
63
- "function getZipFileInfo(uint256 tokenId) external view returns (tuple(string fileName, string merkleRootHash, string ipfsHash, address creator, uint256 creationTimestamp, uint256 tokenizationTime, uint256 blockNumber))",
64
- "function ownerOf(uint256 tokenId) external view returns (address)",
65
- "function balanceOf(address owner) external view returns (uint256)",
66
- "function isZipFileTokenized(string memory merkleRootHash, uint256 creationTimestamp) external view returns (bool exists, uint256 tokenId)",
67
- "function verifyZipFile(uint256 tokenId, string memory providedMerkleRoot) external view returns (bool isValid)",
68
- "function getVersion() external pure returns (string memory)",
69
- "event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)",
70
- "event ZipFileTokenized(uint256 indexed tokenId, address indexed creator, string fileName, string merkleRootHash, uint256 creationTimestamp, string ipfsHash, uint256 tokenizationTime, uint256 blockNumber)"
71
- ]
72
-
73
- // Default configuration (Base Sepolia for development)
74
- export const DEFAULT_NETWORK = 84532
75
- export const CURRENT_DEPLOYMENT = CONTRACT_CONFIGS[DEFAULT_NETWORK]
76
-
77
- // Helper functions
78
- export const getContractConfig = (chainId: number): ContractConfig => {
79
- return CONTRACT_CONFIGS[chainId] || CURRENT_DEPLOYMENT
80
- }
81
-
82
- export const getSupportedNetworks = (): number[] => {
83
- return Object.keys(CONTRACT_CONFIGS).map(Number)
84
- }
85
-
86
- export const isNetworkSupported = (chainId: number): boolean => {
87
- return chainId in CONTRACT_CONFIGS
88
- }
@@ -1,91 +0,0 @@
1
- import type { Wallet, JsonRpcProvider } from 'ethers';
2
-
3
- // Wallet and network types
4
- export interface WalletInfo {
5
- address: string;
6
- privateKey: string;
7
- mnemonic: string;
8
- }
9
-
10
- export interface NetworkConfig {
11
- name: string;
12
- rpcUrl: string;
13
- chainId: number;
14
- explorerUrl: string;
15
- }
16
-
17
- export interface WalletSetupResult {
18
- wallet: Wallet | null;
19
- provider: JsonRpcProvider | null;
20
- success: boolean;
21
- message?: string;
22
- }
23
-
24
- export interface MintingResult {
25
- success: boolean;
26
- message: string;
27
- tokenId?: string;
28
- txHash?: string;
29
- creationTimestamp?: number;
30
- }
31
-
32
- export interface MintingOptions {
33
- wallet?: string;
34
- network: string;
35
- mintToken: boolean;
36
- }
37
-
38
- // Canonical token metadata used across minting, verification, and ZIP embedding
39
- export interface TokenMetadata {
40
- // Core identifiers
41
- tokenId: string;
42
- contractAddress: string;
43
- network: string;
44
- merkleRoot: string;
45
-
46
- // Optional chain info
47
- networkChainId?: number;
48
- transactionHash?: string;
49
- blockNumber?: number;
50
-
51
- // Names and timestamps (support both archiveName/fileName and mintedAt/mintDate)
52
- fileName?: string;
53
- archiveName?: string;
54
- mintedAt?: string;
55
- mintDate?: string;
56
- creationTimestamp?: number;
57
-
58
- // Optional content link
59
- ipfsHash?: string;
60
-
61
- // Versioning
62
- version?: string;
63
- }
64
-
65
- // Network configuration
66
- export const NETWORKS: Record<string, NetworkConfig> = {
67
- 'base': {
68
- name: 'Base Mainnet',
69
- rpcUrl: 'https://mainnet.base.org',
70
- chainId: 8453,
71
- explorerUrl: 'https://basescan.org'
72
- },
73
- 'base-sepolia': {
74
- name: 'Base Sepolia',
75
- rpcUrl: 'https://sepolia.base.org',
76
- chainId: 84532,
77
- explorerUrl: 'https://sepolia.basescan.org'
78
- },
79
- 'base-goerli': {
80
- name: 'Base Goerli',
81
- rpcUrl: 'https://goerli.base.org',
82
- chainId: 84531,
83
- explorerUrl: 'https://goerli.basescan.org'
84
- },
85
- 'localhost': {
86
- name: 'Localhost',
87
- rpcUrl: 'http://localhost:8545',
88
- chainId: 31337,
89
- explorerUrl: 'http://localhost:8545'
90
- }
91
- };