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.
- package/LICENSE +22 -0
- package/README.md +410 -186
- package/contracts/ABI.txt +889 -0
- package/contracts/Bytecode.txt +1 -0
- package/contracts/COMPILATION_NOTES.md +59 -0
- package/contracts/QUICK_DEPLOY.md +286 -0
- package/contracts/README.md +235 -131
- package/contracts/VERIFICATION.md +308 -0
- package/contracts/deploy-interactive.js +448 -0
- package/contracts/deployment-arbitrum-sepolia.json +12 -0
- package/contracts/deployment-arbitrum.json +12 -0
- package/contracts/deployment-eth-sepolia.json +12 -0
- package/contracts/hardhat.config.js +114 -0
- package/contracts/package.json +20 -0
- package/contracts/scripts/compile-and-extract.js +119 -0
- package/contracts/scripts/verify-contract.js +223 -0
- package/contracts/src/{NZIP-NFT-Private.sol → NZIP-NFT-v2.0.sol} +66 -151
- package/contracts/src/NZIP-NFT.sol +9 -15
- package/dist/blockchain/browser/TokenVerifierBrowser.d.ts +67 -0
- package/dist/blockchain/browser/TokenVerifierBrowser.d.ts.map +1 -0
- package/dist/blockchain/browser/TokenVerifierBrowser.js +313 -0
- package/dist/blockchain/browser/TokenVerifierBrowser.js.map +1 -0
- package/dist/blockchain/browser/WalletManagerBrowser.d.ts +98 -0
- package/dist/blockchain/browser/WalletManagerBrowser.d.ts.map +1 -0
- package/dist/blockchain/browser/WalletManagerBrowser.js +434 -0
- package/dist/blockchain/browser/WalletManagerBrowser.js.map +1 -0
- package/dist/blockchain/browser/ZipkitMinterBrowser.d.ts +58 -0
- package/dist/blockchain/browser/ZipkitMinterBrowser.d.ts.map +1 -0
- package/dist/blockchain/browser/ZipkitMinterBrowser.js +317 -0
- package/dist/blockchain/browser/ZipkitMinterBrowser.js.map +1 -0
- package/dist/blockchain/browser/index.d.ts +11 -0
- package/dist/blockchain/browser/index.d.ts.map +1 -0
- package/dist/blockchain/browser/index.js +16 -0
- package/dist/blockchain/browser/index.js.map +1 -0
- package/dist/blockchain/core/WalletManager.d.ts +124 -0
- package/dist/blockchain/core/WalletManager.d.ts.map +1 -0
- package/dist/blockchain/{ZipKitWallet.js → core/WalletManager.js} +157 -177
- package/dist/blockchain/core/WalletManager.js.map +1 -0
- package/dist/blockchain/{ZipKitMinter.d.ts → core/ZipkitMinter.d.ts} +46 -11
- package/dist/blockchain/core/ZipkitMinter.d.ts.map +1 -0
- package/dist/blockchain/core/ZipkitMinter.js +548 -0
- package/dist/blockchain/core/ZipkitMinter.js.map +1 -0
- package/dist/blockchain/{ZipKitOTS.d.ts → core/ZipkitOTS.d.ts} +6 -15
- package/dist/blockchain/core/ZipkitOTS.d.ts.map +1 -0
- package/dist/blockchain/{ZipKitOTS.js → core/ZipkitOTS.js} +26 -84
- package/dist/blockchain/core/ZipkitOTS.js.map +1 -0
- package/dist/blockchain/core/ZipkitVerifier.d.ts +177 -0
- package/dist/blockchain/core/ZipkitVerifier.d.ts.map +1 -0
- package/dist/blockchain/core/ZipkitVerifier.js +632 -0
- package/dist/blockchain/core/ZipkitVerifier.js.map +1 -0
- package/dist/blockchain/core/contracts.d.ts +83 -0
- package/dist/blockchain/core/contracts.d.ts.map +1 -0
- package/dist/blockchain/core/contracts.js +341 -0
- package/dist/blockchain/core/contracts.js.map +1 -0
- package/dist/blockchain/core/index.d.ts +12 -0
- package/dist/blockchain/core/index.d.ts.map +1 -0
- package/dist/blockchain/core/index.js +59 -0
- package/dist/blockchain/core/index.js.map +1 -0
- package/dist/blockchain/index.d.ts +11 -7
- package/dist/blockchain/index.d.ts.map +1 -0
- package/dist/blockchain/index.js +18 -34
- package/dist/blockchain/index.js.map +1 -0
- package/dist/blockchain/node/WalletManagerNode.d.ts +47 -0
- package/dist/blockchain/node/WalletManagerNode.d.ts.map +1 -0
- package/dist/blockchain/node/WalletManagerNode.js +203 -0
- package/dist/blockchain/node/WalletManagerNode.js.map +1 -0
- package/dist/blockchain/node/index.d.ts +12 -0
- package/dist/blockchain/node/index.d.ts.map +1 -0
- package/dist/blockchain/node/index.js +24 -0
- package/dist/blockchain/node/index.js.map +1 -0
- package/dist/browser/ZipkitBrowser.d.ts +27 -0
- package/dist/browser/ZipkitBrowser.d.ts.map +1 -0
- package/dist/browser/{ZipKitBrowser.js → ZipkitBrowser.js} +96 -43
- package/dist/browser/ZipkitBrowser.js.map +1 -0
- package/dist/browser/index.d.ts +12 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +42 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser-esm/index.d.ts +12 -0
- package/dist/browser-esm/index.js +59559 -0
- package/dist/browser-esm/index.js.map +7 -0
- package/dist/browser-umd/index.d.ts +12 -0
- package/dist/browser-umd/index.js +59576 -0
- package/dist/browser-umd/index.js.map +7 -0
- package/dist/browser-umd/index.min.js +63 -0
- package/dist/browser.d.ts +8 -14
- package/dist/browser.js +13 -28
- package/dist/core/ZipCompress.d.ts +99 -0
- package/dist/core/ZipCompress.d.ts.map +1 -0
- package/dist/core/ZipCompress.js +309 -0
- package/dist/core/ZipCompress.js.map +1 -0
- package/dist/core/ZipDecompress.d.ts +58 -0
- package/dist/core/ZipDecompress.d.ts.map +1 -0
- package/dist/core/ZipDecompress.js +172 -0
- package/dist/core/ZipDecompress.js.map +1 -0
- package/dist/{shared → core}/ZipEntry.d.ts +8 -1
- package/dist/core/ZipEntry.d.ts.map +1 -0
- package/dist/{shared → core}/ZipEntry.js +225 -82
- package/dist/core/ZipEntry.js.map +1 -0
- package/dist/core/Zipkit.d.ts +315 -0
- package/dist/core/Zipkit.d.ts.map +1 -0
- package/dist/core/Zipkit.js +647 -0
- package/dist/core/Zipkit.js.map +1 -0
- package/dist/core/components/HashCalculator.d.ts +138 -0
- package/dist/core/components/HashCalculator.d.ts.map +1 -0
- package/dist/core/components/HashCalculator.js +360 -0
- package/dist/core/components/HashCalculator.js.map +1 -0
- package/dist/core/components/Logger.d.ts +73 -0
- package/dist/core/components/Logger.d.ts.map +1 -0
- package/dist/core/components/Logger.js +156 -0
- package/dist/core/components/Logger.js.map +1 -0
- package/dist/core/components/ProgressTracker.d.ts +43 -0
- package/dist/core/components/ProgressTracker.d.ts.map +1 -0
- package/dist/core/components/ProgressTracker.js +112 -0
- package/dist/core/components/ProgressTracker.js.map +1 -0
- package/dist/{shared → core}/components/Support.d.ts +1 -0
- package/dist/core/components/Support.d.ts.map +1 -0
- package/dist/{shared → core}/components/Support.js +1 -0
- package/dist/core/components/Support.js.map +1 -0
- package/dist/{shared → core}/components/Util.d.ts +7 -2
- package/dist/core/components/Util.d.ts.map +1 -0
- package/dist/{shared → core}/components/Util.js +14 -34
- package/dist/core/components/Util.js.map +1 -0
- package/dist/{shared → core}/constants/Errors.d.ts +1 -2
- package/dist/core/constants/Errors.d.ts.map +1 -0
- package/dist/{shared → core}/constants/Errors.js +1 -3
- package/dist/core/constants/Errors.js.map +1 -0
- package/dist/{shared → core}/constants/Headers.d.ts +3 -0
- package/dist/core/constants/Headers.d.ts.map +1 -0
- package/dist/{shared → core}/constants/Headers.js +20 -17
- package/dist/core/constants/Headers.js.map +1 -0
- package/dist/core/encryption/Manager.d.ts +58 -0
- package/dist/core/encryption/Manager.d.ts.map +1 -0
- package/dist/core/encryption/Manager.js +121 -0
- package/dist/core/encryption/Manager.js.map +1 -0
- package/dist/core/encryption/ZipCrypto.d.ts +172 -0
- package/dist/core/encryption/ZipCrypto.d.ts.map +1 -0
- package/dist/core/encryption/ZipCrypto.js +554 -0
- package/dist/core/encryption/ZipCrypto.js.map +1 -0
- package/dist/core/encryption/index.d.ts +9 -0
- package/dist/core/encryption/index.d.ts.map +1 -0
- package/dist/core/encryption/index.js +17 -0
- package/dist/core/encryption/index.js.map +1 -0
- package/dist/core/encryption/types.d.ts +29 -0
- package/dist/core/encryption/types.d.ts.map +1 -0
- package/dist/core/encryption/types.js +12 -0
- package/dist/core/encryption/types.js.map +1 -0
- package/dist/core/index.d.ts +24 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +57 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/version.d.ts +5 -0
- package/dist/core/version.d.ts.map +1 -0
- package/dist/core/version.js +31 -0
- package/dist/core/version.js.map +1 -0
- package/dist/index.d.ts +8 -18
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -35
- package/dist/index.js.map +1 -0
- package/dist/node/ZipCompressNode.d.ts +123 -0
- package/dist/node/ZipCompressNode.d.ts.map +1 -0
- package/dist/node/ZipCompressNode.js +576 -0
- package/dist/node/ZipCompressNode.js.map +1 -0
- package/dist/node/ZipDecompressNode.d.ts +120 -0
- package/dist/node/ZipDecompressNode.d.ts.map +1 -0
- package/dist/node/ZipDecompressNode.js +461 -0
- package/dist/node/ZipDecompressNode.js.map +1 -0
- package/dist/node/ZipkitNode.d.ts +406 -0
- package/dist/node/ZipkitNode.d.ts.map +1 -0
- package/dist/node/ZipkitNode.js +1305 -0
- package/dist/node/ZipkitNode.js.map +1 -0
- package/dist/node/index.d.ts +26 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +65 -0
- package/dist/node/index.js.map +1 -0
- package/dist/types/index.d.ts +59 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +36 -1
- package/dist/types/index.js.map +1 -0
- package/examples/README.md +269 -0
- package/examples/blockchain-tokenize.ts +354 -0
- package/examples/create-zip.ts +172 -0
- package/examples/extract-zip.ts +158 -0
- package/examples/list-zip.ts +161 -0
- package/examples/test-files/data.json +116 -0
- package/examples/test-files/document.md +80 -0
- package/examples/test-files/document.txt +2 -0
- package/examples/test-files/file1.txt +48 -0
- package/examples/test-files/file2.txt +80 -0
- package/examples/tsconfig.json +44 -0
- package/examples/unzip-token.ts +491 -0
- package/examples/verify-tokenized-zip.ts +305 -0
- package/examples/zip-token.ts +604 -0
- package/package.json +108 -24
- package/src/blockchain/README.md +59 -66
- package/src/{browser/TokenVerifierBrowser.ts-remove → blockchain/browser/TokenVerifierBrowser.ts} +125 -79
- package/src/blockchain/browser/WalletManagerBrowser.ts +486 -0
- package/src/blockchain/browser/ZipkitMinterBrowser.ts +400 -0
- package/src/blockchain/browser/index.ts +13 -0
- package/src/blockchain/{ZipKitWallet.ts → core/WalletManager.ts} +241 -143
- package/src/blockchain/core/ZipkitMinter.ts +716 -0
- package/src/blockchain/{ZipKitOTS.ts → core/ZipkitOTS.ts} +28 -62
- package/src/blockchain/core/ZipkitVerifier.ts +853 -0
- package/src/blockchain/core/contracts.ts +370 -0
- package/src/blockchain/core/index.ts +71 -0
- package/src/blockchain/index.ts +21 -55
- package/src/blockchain/node/WalletManagerNode.ts +171 -0
- package/src/blockchain/node/index.ts +40 -0
- package/src/browser/{ZipKitBrowser.ts → ZipkitBrowser.ts} +104 -41
- package/src/browser/index.esm.ts +37 -0
- package/src/browser/index.ts +25 -0
- package/src/core/ZipCompress.ts +398 -0
- package/src/core/ZipDecompress.ts +212 -0
- package/src/{shared → core}/ZipEntry.ts +240 -90
- package/src/core/Zipkit.ts +794 -0
- package/src/core/components/HashCalculator.ts +384 -0
- package/src/core/components/Logger.ts +180 -0
- package/src/core/components/ProgressTracker.ts +134 -0
- package/src/{shared → core}/components/Util.ts +12 -34
- package/src/{shared → core}/constants/Errors.ts +0 -4
- package/src/{shared → core}/constants/Headers.ts +19 -17
- package/src/core/encryption/Manager.ts +137 -0
- package/src/core/encryption/ZipCrypto.ts +650 -0
- package/src/core/encryption/index.ts +15 -0
- package/src/core/encryption/types.ts +33 -0
- package/src/core/index.ts +34 -0
- package/src/core/version.ts +33 -0
- package/src/index.ts +54 -25
- package/src/node/ZipCompressNode.ts +632 -0
- package/src/node/ZipDecompressNode.ts +508 -0
- package/src/node/ZipkitNode.ts +1559 -0
- package/src/node/index.ts +69 -0
- package/src/types/index.ts +131 -1
- package/src/types/modules.d.ts +1 -11
- package/src/types/opentimestamps.d.ts +1 -23
- package/contracts/INTEGRATION.md +0 -338
- package/contracts/NETWORKS.md +0 -156
- package/contracts/NZIP-NFT-bytecode.txt +0 -1
- package/contracts/constants.ts +0 -952
- package/contracts/deploy-bytecode.mjs +0 -94
- package/dist/blockchain/CertificateToken.d.ts +0 -48
- package/dist/blockchain/CertificateToken.js +0 -386
- package/dist/blockchain/ZipKitMinter.js +0 -347
- package/dist/blockchain/ZipKitNFT.d.ts +0 -3
- package/dist/blockchain/ZipKitNFT.js +0 -7
- package/dist/blockchain/ZipKitVerifier.d.ts +0 -69
- package/dist/blockchain/ZipKitVerifier.js +0 -289
- package/dist/blockchain/ZipKitWallet.d.ts +0 -69
- package/dist/blockchain/contracts.d.ts +0 -14
- package/dist/blockchain/contracts.js +0 -77
- package/dist/blockchain/types.d.ts +0 -47
- package/dist/blockchain/types.js +0 -30
- package/dist/browser/ZipKitBrowser.d.ts +0 -18
- package/dist/browser/ZipKitStampBrowser.d.ts +0 -2
- package/dist/browser/ZipKitStampBrowser.js +0 -12
- package/dist/browser-index.d.ts +0 -18
- package/dist/browser-index.js +0 -57
- package/dist/server/ZipKitServer.d.ts +0 -74
- package/dist/server/ZipKitServer.js +0 -310
- package/dist/shared/ZipKit.d.ts +0 -243
- package/dist/shared/ZipKit.js +0 -772
- package/dist/shared/components/CertificateOTS.d.ts +0 -15
- package/dist/shared/components/CertificateOTS.js +0 -116
- package/dist/shared/components/FileSys.d.ts +0 -2
- package/dist/shared/components/FileSys.js +0 -113
- package/dist/shared/components/HashAccumulator.d.ts +0 -55
- package/dist/shared/components/HashAccumulator.js +0 -100
- package/dist/shared/components/ZipCrypto.d.ts +0 -3
- package/dist/shared/components/ZipCrypto.js +0 -78
- package/dist/shared/components/merkleTree.d.ts +0 -66
- package/dist/shared/components/merkleTree.js +0 -136
- package/dist/shared/types/index.d.ts +0 -21
- package/dist/shared/types/index.js +0 -3
- package/dist/shared/types.d.ts +0 -33
- package/dist/shared/types.js +0 -8
- package/dist/shared/version.d.ts +0 -2
- package/dist/shared/version.js +0 -6
- package/src/blockchain/CertificateToken.ts +0 -444
- package/src/blockchain/ZipKitMinter.ts +0 -470
- package/src/blockchain/ZipKitNFT.ts +0 -12
- package/src/blockchain/ZipKitVerifier.ts +0 -382
- package/src/blockchain/contracts.ts +0 -88
- package/src/blockchain/types.ts +0 -91
- package/src/browser/CertificateGeneratorBrowser.ts-remove +0 -498
- package/src/browser/ZipKitStampBrowser.ts +0 -9
- package/src/browser-index.ts +0 -36
- package/src/server/README.md +0 -25
- package/src/server/ZipKitServer.ts +0 -305
- package/src/shared/ZipKit.ts +0 -881
- package/src/shared/components/CertificateOTS.ts +0 -132
- package/src/shared/components/FileSys.ts +0 -87
- package/src/shared/components/HashAccumulator.ts +0 -113
- package/src/shared/components/ZipCrypto.ts +0 -91
- package/src/shared/components/merkleTree.ts +0 -162
- package/src/shared/types/index.ts +0 -25
- package/src/shared/types/modules.d.ts +0 -22
- package/src/shared/types/opentimestamps.d.ts +0 -23
- package/src/shared/types.d.ts +0 -8
- package/src/shared/types.ts +0 -43
- package/src/shared/version.ts +0 -3
- /package/src/{shared → core}/components/Support.ts +0 -0
package/src/{browser/TokenVerifierBrowser.ts-remove → blockchain/browser/TokenVerifierBrowser.ts}
RENAMED
|
@@ -4,23 +4,12 @@
|
|
|
4
4
|
// Copyright (c) 2025 NeoWare, Inc. All rights reserved.
|
|
5
5
|
// ======================================
|
|
6
6
|
|
|
7
|
-
import
|
|
8
|
-
import { ZipEntry } from '
|
|
9
|
-
import { TOKENIZED_METADATA } from '
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export interface NZipTokenInfo {
|
|
14
|
-
version: string;
|
|
15
|
-
tokenId: string;
|
|
16
|
-
contractAddress: string;
|
|
17
|
-
network: string;
|
|
18
|
-
networkChainId: number;
|
|
19
|
-
transactionHash: string;
|
|
20
|
-
merkleRoot: string;
|
|
21
|
-
fileName: string;
|
|
22
|
-
mintedAt: string;
|
|
23
|
-
}
|
|
7
|
+
import ZipkitBrowser from '../../browser/ZipkitBrowser';
|
|
8
|
+
import { ZipEntry } from '../../core';
|
|
9
|
+
import { TOKENIZED_METADATA } from '../../core/constants/Headers';
|
|
10
|
+
import { TokenMetadata } from '../../types';
|
|
11
|
+
import { NZIP_CONTRACT_ABI, getContractConfig } from '../core/contracts';
|
|
12
|
+
import { ethers } from 'ethers';
|
|
24
13
|
|
|
25
14
|
export interface TokenVerificationOptions {
|
|
26
15
|
skipHash?: boolean;
|
|
@@ -31,7 +20,7 @@ export interface TokenVerificationOptions {
|
|
|
31
20
|
|
|
32
21
|
export interface TokenVerificationResult {
|
|
33
22
|
isTokenized: boolean;
|
|
34
|
-
tokenMetadata:
|
|
23
|
+
tokenMetadata: TokenMetadata | null;
|
|
35
24
|
calculatedMerkleRoot: string | null;
|
|
36
25
|
blockchainMerkleRoot: string | null;
|
|
37
26
|
blockchainTimestamp?: number; // Actual blockchain timestamp from tokenizationTime
|
|
@@ -49,28 +38,6 @@ export interface BlockchainVerification {
|
|
|
49
38
|
blockNumber?: number;
|
|
50
39
|
}
|
|
51
40
|
|
|
52
|
-
// Network configuration for blockchain queries
|
|
53
|
-
const NETWORK_CONFIG: Record<string, any> = {
|
|
54
|
-
'Base Sepolia': {
|
|
55
|
-
chainId: 84532,
|
|
56
|
-
rpcUrls: [
|
|
57
|
-
'https://sepolia.base.org',
|
|
58
|
-
'https://base-sepolia.g.alchemy.com/v2/demo',
|
|
59
|
-
'https://base-sepolia-rpc.publicnode.com',
|
|
60
|
-
'https://base-sepolia.blockpi.network/v1/rpc/public'
|
|
61
|
-
]
|
|
62
|
-
},
|
|
63
|
-
'Base Mainnet': {
|
|
64
|
-
chainId: 8453,
|
|
65
|
-
rpcUrls: [
|
|
66
|
-
'https://mainnet.base.org',
|
|
67
|
-
'https://base-mainnet.g.alchemy.com/v2/demo',
|
|
68
|
-
'https://base-rpc.publicnode.com',
|
|
69
|
-
'https://base.blockpi.network/v1/rpc/public'
|
|
70
|
-
]
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
|
|
74
41
|
// Use the complete contract ABI from constants
|
|
75
42
|
const CONTRACT_ABI = NZIP_CONTRACT_ABI;
|
|
76
43
|
|
|
@@ -78,10 +45,10 @@ const CONTRACT_ABI = NZIP_CONTRACT_ABI;
|
|
|
78
45
|
* Browser-compatible token verification class
|
|
79
46
|
*/
|
|
80
47
|
export class TokenVerifierBrowser {
|
|
81
|
-
private
|
|
48
|
+
private zipkit: ZipkitBrowser;
|
|
82
49
|
|
|
83
|
-
constructor(
|
|
84
|
-
this.
|
|
50
|
+
constructor(zipkit: ZipkitBrowser) {
|
|
51
|
+
this.zipkit = zipkit;
|
|
85
52
|
}
|
|
86
53
|
|
|
87
54
|
/**
|
|
@@ -106,7 +73,7 @@ export class TokenVerifierBrowser {
|
|
|
106
73
|
|
|
107
74
|
try {
|
|
108
75
|
// Extract the token metadata
|
|
109
|
-
const tokenData = await this.
|
|
76
|
+
const tokenData = await this.zipkit.extractBlob(tokenEntry);
|
|
110
77
|
|
|
111
78
|
if (!tokenData) {
|
|
112
79
|
return {
|
|
@@ -164,9 +131,15 @@ export class TokenVerifierBrowser {
|
|
|
164
131
|
const blockchainData = await this.queryBlockchainData(tokenMetadata);
|
|
165
132
|
|
|
166
133
|
if (!blockchainData.merkleRoot) {
|
|
134
|
+
// Add owner information to tokenMetadata even if merkle root is not available
|
|
135
|
+
const enhancedTokenMetadata = {
|
|
136
|
+
...tokenMetadata,
|
|
137
|
+
owner: blockchainData.owner || undefined
|
|
138
|
+
};
|
|
139
|
+
|
|
167
140
|
return {
|
|
168
141
|
isTokenized: true,
|
|
169
|
-
tokenMetadata,
|
|
142
|
+
tokenMetadata: enhancedTokenMetadata,
|
|
170
143
|
calculatedMerkleRoot,
|
|
171
144
|
blockchainMerkleRoot: null,
|
|
172
145
|
blockchainTimestamp: blockchainData.timestamp ?? undefined,
|
|
@@ -175,16 +148,30 @@ export class TokenVerifierBrowser {
|
|
|
175
148
|
};
|
|
176
149
|
}
|
|
177
150
|
|
|
178
|
-
|
|
151
|
+
// Normalize both merkle roots for comparison (trim whitespace, lowercase)
|
|
152
|
+
const normalizedBlockchain = blockchainData.merkleRoot?.toLowerCase().trim() || '';
|
|
153
|
+
const normalizedCalculated = calculatedMerkleRoot?.toLowerCase().trim() || '';
|
|
154
|
+
const verificationPassed = normalizedBlockchain === normalizedCalculated;
|
|
155
|
+
|
|
156
|
+
// Log mismatch only (success is silent)
|
|
157
|
+
if (!verificationPassed) {
|
|
158
|
+
console.warn(`[TokenVerifier] ⚠️ Merkle root mismatch - Calculated: ${calculatedMerkleRoot}, Blockchain: ${blockchainData.merkleRoot}`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Add owner information to tokenMetadata
|
|
162
|
+
const enhancedTokenMetadata = {
|
|
163
|
+
...tokenMetadata,
|
|
164
|
+
owner: blockchainData.owner || undefined
|
|
165
|
+
};
|
|
179
166
|
|
|
180
167
|
return {
|
|
181
168
|
isTokenized: true,
|
|
182
|
-
tokenMetadata,
|
|
169
|
+
tokenMetadata: enhancedTokenMetadata,
|
|
183
170
|
calculatedMerkleRoot,
|
|
184
171
|
blockchainMerkleRoot: blockchainData.merkleRoot,
|
|
185
172
|
blockchainTimestamp: blockchainData.timestamp ?? undefined,
|
|
186
173
|
verificationPassed,
|
|
187
|
-
errorMessage: verificationPassed ? undefined :
|
|
174
|
+
errorMessage: verificationPassed ? undefined : `Merkle root mismatch - Calculated: ${calculatedMerkleRoot}, Blockchain: ${blockchainData.merkleRoot}`
|
|
188
175
|
};
|
|
189
176
|
|
|
190
177
|
} catch (error) {
|
|
@@ -202,7 +189,7 @@ export class TokenVerifierBrowser {
|
|
|
202
189
|
/**
|
|
203
190
|
* Validates token metadata structure
|
|
204
191
|
*/
|
|
205
|
-
private validateTokenInfo(tokenMetadata: any): tokenMetadata is
|
|
192
|
+
private validateTokenInfo(tokenMetadata: any): tokenMetadata is TokenMetadata {
|
|
206
193
|
return tokenMetadata &&
|
|
207
194
|
typeof tokenMetadata.version === 'string' &&
|
|
208
195
|
typeof tokenMetadata.tokenId === 'string' &&
|
|
@@ -211,7 +198,6 @@ export class TokenVerifierBrowser {
|
|
|
211
198
|
typeof tokenMetadata.networkChainId === 'number' &&
|
|
212
199
|
typeof tokenMetadata.transactionHash === 'string' &&
|
|
213
200
|
typeof tokenMetadata.merkleRoot === 'string' &&
|
|
214
|
-
typeof tokenMetadata.fileName === 'string' &&
|
|
215
201
|
typeof tokenMetadata.mintedAt === 'string';
|
|
216
202
|
}
|
|
217
203
|
|
|
@@ -224,6 +210,7 @@ export class TokenVerifierBrowser {
|
|
|
224
210
|
const contentEntries = zipEntries.filter(entry => entry.filename !== TOKENIZED_METADATA);
|
|
225
211
|
|
|
226
212
|
if (contentEntries.length === 0) {
|
|
213
|
+
console.error(`[TokenVerifier] ❌ No content entries found after filtering`);
|
|
227
214
|
return null;
|
|
228
215
|
}
|
|
229
216
|
|
|
@@ -231,41 +218,96 @@ export class TokenVerifierBrowser {
|
|
|
231
218
|
for (const entry of contentEntries) {
|
|
232
219
|
if (!entry.sha256) {
|
|
233
220
|
// Extract the file to calculate its SHA-256 hash
|
|
234
|
-
await this.
|
|
221
|
+
await this.zipkit.extractBlob(entry);
|
|
235
222
|
}
|
|
236
223
|
}
|
|
237
224
|
|
|
238
225
|
// Calculate merkle root from content files
|
|
239
|
-
//
|
|
240
|
-
|
|
241
|
-
|
|
226
|
+
// getMerkleRoot() already excludes TOKENIZED_METADATA, TIMESTAMP_SUBMITTED, and TIMESTAMP_METADATA
|
|
227
|
+
const merkleRoot = await this.zipkit.getMerkleRoot?.() || null;
|
|
228
|
+
|
|
229
|
+
if (!merkleRoot) {
|
|
230
|
+
console.error(`[TokenVerifier] ❌ Failed to calculate merkle root`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return merkleRoot;
|
|
242
234
|
} catch (error) {
|
|
243
|
-
console.error(
|
|
235
|
+
console.error(`[TokenVerifier] ❌ Error calculating merkle root:`, error);
|
|
244
236
|
return null;
|
|
245
237
|
}
|
|
246
238
|
}
|
|
247
239
|
|
|
248
240
|
/**
|
|
249
|
-
* Queries the blockchain to get the actual merkle root and
|
|
241
|
+
* Queries the blockchain to get the actual merkle root, timestamp, and owner stored in the smart contract
|
|
250
242
|
*/
|
|
251
|
-
private async queryBlockchainData(tokenMetadata:
|
|
243
|
+
private async queryBlockchainData(tokenMetadata: TokenMetadata): Promise<{merkleRoot: string | null, timestamp: number | null, owner: string | null}> {
|
|
252
244
|
try {
|
|
253
|
-
//
|
|
254
|
-
|
|
245
|
+
// Get network configuration from contracts.ts (single source of truth)
|
|
246
|
+
if (!tokenMetadata.networkChainId) {
|
|
247
|
+
console.error(`[TokenVerifier] ❌ No chainId in token metadata`);
|
|
248
|
+
return { merkleRoot: null, timestamp: null, owner: null };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const networkConfig = getContractConfig(tokenMetadata.networkChainId);
|
|
255
252
|
|
|
256
|
-
const networkConfig = NETWORK_CONFIG[tokenMetadata.network];
|
|
257
253
|
if (!networkConfig) {
|
|
258
|
-
console.
|
|
259
|
-
return { merkleRoot: null, timestamp: null };
|
|
254
|
+
console.error(`[TokenVerifier] ❌ Could not resolve network configuration for chainId: ${tokenMetadata.networkChainId}`);
|
|
255
|
+
return { merkleRoot: null, timestamp: null, owner: null };
|
|
260
256
|
}
|
|
261
257
|
|
|
262
|
-
//
|
|
258
|
+
// Test RPC endpoints first to find working ones (same as server-side)
|
|
259
|
+
const workingRpcUrls: string[] = [];
|
|
260
|
+
|
|
263
261
|
for (const rpcUrl of networkConfig.rpcUrls) {
|
|
262
|
+
try {
|
|
263
|
+
const controller = new AbortController();
|
|
264
|
+
const timeoutId = setTimeout(() => controller.abort(), 5000);
|
|
265
|
+
|
|
266
|
+
const testResponse = await fetch(rpcUrl, {
|
|
267
|
+
method: 'POST',
|
|
268
|
+
headers: { 'Content-Type': 'application/json' },
|
|
269
|
+
body: JSON.stringify({
|
|
270
|
+
jsonrpc: '2.0',
|
|
271
|
+
method: 'eth_chainId',
|
|
272
|
+
params: [],
|
|
273
|
+
id: 1
|
|
274
|
+
}),
|
|
275
|
+
signal: controller.signal
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
clearTimeout(timeoutId);
|
|
279
|
+
|
|
280
|
+
if (testResponse.ok) {
|
|
281
|
+
const contentType = testResponse.headers.get('content-type');
|
|
282
|
+
if (contentType && contentType.includes('application/json')) {
|
|
283
|
+
const testData = await testResponse.json() as { jsonrpc?: string; result?: string };
|
|
284
|
+
if (testData?.jsonrpc && testData?.result) {
|
|
285
|
+
const actualChainId = parseInt(testData.result, 16);
|
|
286
|
+
if (actualChainId === tokenMetadata.networkChainId) {
|
|
287
|
+
workingRpcUrls.push(rpcUrl);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
} catch (testError: any) {
|
|
293
|
+
// Silently skip failed endpoints
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (workingRpcUrls.length === 0) {
|
|
298
|
+
// Fallback to all endpoints if none tested successfully
|
|
299
|
+
workingRpcUrls.push(...networkConfig.rpcUrls);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Try multiple RPC endpoints (only working ones if available)
|
|
303
|
+
for (let i = 0; i < workingRpcUrls.length; i++) {
|
|
304
|
+
const rpcUrl = workingRpcUrls[i];
|
|
305
|
+
|
|
264
306
|
try {
|
|
265
307
|
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
|
266
308
|
|
|
267
309
|
// Test connection with a timeout
|
|
268
|
-
|
|
310
|
+
await Promise.race([
|
|
269
311
|
provider.getBlockNumber(),
|
|
270
312
|
new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout')), 5000))
|
|
271
313
|
]);
|
|
@@ -276,23 +318,27 @@ export class TokenVerifierBrowser {
|
|
|
276
318
|
// Call getZipFileInfo to get the blockchain-stored data
|
|
277
319
|
const zipInfo = await contract.getZipFileInfo(tokenMetadata.tokenId);
|
|
278
320
|
|
|
321
|
+
// Get the token owner
|
|
322
|
+
const owner = await contract.ownerOf(tokenMetadata.tokenId);
|
|
323
|
+
|
|
279
324
|
return {
|
|
280
325
|
merkleRoot: zipInfo.merkleRootHash,
|
|
281
|
-
timestamp: Number(zipInfo.tokenizationTime)
|
|
326
|
+
timestamp: Number(zipInfo.tokenizationTime),
|
|
327
|
+
owner: owner
|
|
282
328
|
};
|
|
283
329
|
|
|
284
|
-
} catch (error) {
|
|
285
|
-
|
|
330
|
+
} catch (error: any) {
|
|
331
|
+
// Continue to next endpoint on error
|
|
286
332
|
continue;
|
|
287
333
|
}
|
|
288
334
|
}
|
|
289
335
|
|
|
290
|
-
console.
|
|
291
|
-
return { merkleRoot: null, timestamp: null };
|
|
336
|
+
console.error(`[TokenVerifier] ❌ All RPC endpoints failed for network: ${tokenMetadata.network}`);
|
|
337
|
+
return { merkleRoot: null, timestamp: null, owner: null };
|
|
292
338
|
|
|
293
|
-
} catch (error) {
|
|
294
|
-
console.error(
|
|
295
|
-
return { merkleRoot: null, timestamp: null };
|
|
339
|
+
} catch (error: any) {
|
|
340
|
+
console.error(`[TokenVerifier] ❌ Blockchain query error:`, error?.message || error);
|
|
341
|
+
return { merkleRoot: null, timestamp: null, owner: null };
|
|
296
342
|
}
|
|
297
343
|
}
|
|
298
344
|
|
|
@@ -311,15 +357,15 @@ export class TokenVerifierBrowser {
|
|
|
311
357
|
/**
|
|
312
358
|
* Creates a formatted summary of token information
|
|
313
359
|
*/
|
|
314
|
-
createTokenSummary(tokenMetadata:
|
|
360
|
+
createTokenSummary(tokenMetadata: TokenMetadata): string {
|
|
315
361
|
return `
|
|
316
362
|
🎫 NFT Token Information:
|
|
317
363
|
Token ID: ${tokenMetadata.tokenId}
|
|
318
364
|
Network: ${tokenMetadata.network}
|
|
319
365
|
Contract: ${tokenMetadata.contractAddress}
|
|
320
366
|
Transaction: ${tokenMetadata.transactionHash}
|
|
321
|
-
|
|
322
|
-
Minted: ${new Date(tokenMetadata.mintedAt).toLocaleString()}
|
|
367
|
+
Type: Tokenized Archive
|
|
368
|
+
Minted: ${tokenMetadata.mintedAt ? new Date(tokenMetadata.mintedAt).toLocaleString() : 'Unknown'}
|
|
323
369
|
`;
|
|
324
370
|
}
|
|
325
371
|
}
|
|
@@ -327,18 +373,18 @@ export class TokenVerifierBrowser {
|
|
|
327
373
|
/**
|
|
328
374
|
* Creates a new TokenVerifierBrowser instance
|
|
329
375
|
*/
|
|
330
|
-
export function createTokenVerifier(
|
|
331
|
-
return new TokenVerifierBrowser(
|
|
376
|
+
export function createTokenVerifier(zipkit: ZipkitBrowser): TokenVerifierBrowser {
|
|
377
|
+
return new TokenVerifierBrowser(zipkit);
|
|
332
378
|
}
|
|
333
379
|
|
|
334
380
|
/**
|
|
335
381
|
* Convenience function to check for tokenization
|
|
336
382
|
*/
|
|
337
383
|
export async function checkForTokenization(
|
|
338
|
-
|
|
384
|
+
zipkit: ZipkitBrowser,
|
|
339
385
|
zipEntries: ZipEntry[],
|
|
340
386
|
options: TokenVerificationOptions = {}
|
|
341
387
|
): Promise<TokenVerificationResult> {
|
|
342
|
-
const verifier = new TokenVerifierBrowser(
|
|
388
|
+
const verifier = new TokenVerifierBrowser(zipkit);
|
|
343
389
|
return verifier.checkForTokenization(zipEntries, options);
|
|
344
390
|
}
|