@treza/react 0.0.4

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.
@@ -0,0 +1,347 @@
1
+ import React from 'react';
2
+ import { ethers } from 'ethers';
3
+ import { ComplianceRequirements, VerificationResult, TrezaComplianceSDK, ComplianceStatus } from '@treza/sdk';
4
+ export { ComplianceRequirements, ComplianceStatus, TrezaComplianceConfig, VerificationResult } from '@treza/sdk';
5
+
6
+ /**
7
+ * React Components for TREZA Compliance Integration
8
+ *
9
+ * These components provide easy-to-use React integration for DApps
10
+ * that want to add ZKPassport compliance features.
11
+ */
12
+ interface ComplianceProviderProps {
13
+ provider: ethers.Provider;
14
+ signer?: ethers.Signer;
15
+ children: React.ReactNode;
16
+ }
17
+ interface ComplianceContextType {
18
+ sdk: TrezaComplianceSDK | null;
19
+ isLoading: boolean;
20
+ error: string | null;
21
+ }
22
+ /**
23
+ * Provider component that initializes the compliance SDK
24
+ */
25
+ declare const ComplianceProvider: React.FC<ComplianceProviderProps>;
26
+ /**
27
+ * Hook to use compliance context (for use within ComplianceProvider)
28
+ */
29
+ declare const useComplianceContext: () => ComplianceContextType;
30
+ /**
31
+ * Props for ComplianceVerification component
32
+ */
33
+ interface ComplianceVerificationProps {
34
+ userAddress: string;
35
+ requirements?: ComplianceRequirements;
36
+ onVerificationComplete?: (result: VerificationResult) => void;
37
+ onError?: (error: string) => void;
38
+ className?: string;
39
+ }
40
+ /**
41
+ * Main compliance verification component
42
+ */
43
+ declare const ComplianceVerification: React.FC<ComplianceVerificationProps>;
44
+ /**
45
+ * Props for ComplianceStatus component
46
+ */
47
+ interface ComplianceStatusProps {
48
+ userAddress: string;
49
+ showDetails?: boolean;
50
+ className?: string;
51
+ }
52
+ /**
53
+ * Component to display current compliance status
54
+ */
55
+ declare const ComplianceStatusDisplay: React.FC<ComplianceStatusProps>;
56
+ /**
57
+ * Props for GovernanceEligibility component
58
+ */
59
+ interface GovernanceEligibilityProps {
60
+ userAddress: string;
61
+ proposalId: number;
62
+ className?: string;
63
+ }
64
+ /**
65
+ * Component to display governance eligibility
66
+ */
67
+ declare const GovernanceEligibility: React.FC<GovernanceEligibilityProps>;
68
+ declare const complianceStyles = "\n.treza-compliance-verification {\n max-width: 500px;\n margin: 0 auto;\n padding: 20px;\n border: 1px solid #e0e0e0;\n border-radius: 8px;\n background: #fff;\n}\n\n.verification-header h3 {\n margin: 0 0 10px 0;\n color: #333;\n}\n\n.verification-header p {\n margin: 0 0 20px 0;\n color: #666;\n font-size: 14px;\n}\n\n.btn-primary, .btn-secondary {\n padding: 12px 24px;\n border: none;\n border-radius: 6px;\n font-size: 16px;\n cursor: pointer;\n transition: background-color 0.2s;\n}\n\n.btn-primary {\n background: #007bff;\n color: white;\n}\n\n.btn-primary:hover {\n background: #0056b3;\n}\n\n.btn-primary:disabled {\n background: #ccc;\n cursor: not-allowed;\n}\n\n.btn-secondary {\n background: #6c757d;\n color: white;\n}\n\n.qr-code {\n max-width: 200px;\n height: auto;\n margin: 10px 0;\n}\n\n.spinner {\n width: 20px;\n height: 20px;\n border: 2px solid #f3f3f3;\n border-top: 2px solid #007bff;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n display: inline-block;\n margin-right: 10px;\n}\n\n@keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n}\n\n.compliance-status {\n display: flex;\n align-items: center;\n padding: 10px;\n border-radius: 6px;\n margin: 10px 0;\n}\n\n.compliance-status.compliant {\n background: #d4edda;\n color: #155724;\n border: 1px solid #c3e6cb;\n}\n\n.compliance-status.non-compliant {\n background: #f8d7da;\n color: #721c24;\n border: 1px solid #f5c6cb;\n}\n\n.status-icon {\n margin-right: 8px;\n font-size: 18px;\n}\n\n.status-details {\n margin-top: 10px;\n font-size: 14px;\n}\n\n.detail-item {\n margin: 5px 0;\n}\n\n.label {\n font-weight: bold;\n margin-right: 8px;\n}\n\n.attributes {\n display: flex;\n gap: 8px;\n flex-wrap: wrap;\n}\n\n.attribute {\n background: #e9ecef;\n padding: 2px 6px;\n border-radius: 4px;\n font-size: 12px;\n}\n";
69
+
70
+ /**
71
+ * React-specific service wrapper for TREZA Compliance SDK
72
+ *
73
+ * This service provides React-optimized methods for compliance operations
74
+ * with proper error handling and state management integration.
75
+ */
76
+ interface ComplianceServiceConfig {
77
+ zkPassportDomain?: string;
78
+ zkVerifyEndpoint?: string;
79
+ zkVerifyApiKey?: string;
80
+ trezaTokenAddress?: string;
81
+ complianceVerifierAddress?: string;
82
+ complianceIntegrationAddress?: string;
83
+ }
84
+ declare class ComplianceService {
85
+ private sdk;
86
+ private config;
87
+ constructor(config?: ComplianceServiceConfig);
88
+ /**
89
+ * Initialize the compliance SDK with provider and signer
90
+ */
91
+ initialize(provider: ethers.Provider, signer?: ethers.Signer): Promise<void>;
92
+ /**
93
+ * Get the initialized SDK instance
94
+ */
95
+ getSDK(): TrezaComplianceSDK;
96
+ /**
97
+ * Check if the service is initialized
98
+ */
99
+ isInitialized(): boolean;
100
+ /**
101
+ * Initiate verification with React-friendly error handling
102
+ */
103
+ initiateVerification(requirements?: ComplianceRequirements): Promise<{
104
+ success: boolean;
105
+ url?: string;
106
+ error?: string;
107
+ }>;
108
+ /**
109
+ * Process verification result with React-friendly error handling
110
+ */
111
+ processVerificationResult(zkPassportResult: any, userAddress: string): Promise<{
112
+ success: boolean;
113
+ result?: VerificationResult;
114
+ error?: string;
115
+ }>;
116
+ /**
117
+ * Check compliance status with React-friendly error handling
118
+ */
119
+ checkComplianceStatus(userAddress: string): Promise<{
120
+ success: boolean;
121
+ status?: ComplianceStatus;
122
+ error?: string;
123
+ }>;
124
+ /**
125
+ * Generate QR code for verification URL
126
+ */
127
+ generateQRCode(url: string): Promise<{
128
+ success: boolean;
129
+ qrCode?: string;
130
+ error?: string;
131
+ }>;
132
+ /**
133
+ * Batch check compliance for multiple users
134
+ */
135
+ batchCheckCompliance(userAddresses: string[]): Promise<{
136
+ success: boolean;
137
+ results?: ComplianceStatus[];
138
+ error?: string;
139
+ }>;
140
+ /**
141
+ * Check governance eligibility
142
+ */
143
+ checkGovernanceEligibility(userAddress: string, proposalId?: string): Promise<{
144
+ success: boolean;
145
+ eligibility?: any;
146
+ error?: string;
147
+ }>;
148
+ /**
149
+ * Cleanup resources
150
+ */
151
+ destroy(): void;
152
+ }
153
+ /**
154
+ * Get or create the global compliance service instance
155
+ */
156
+ declare function getComplianceService(config?: ComplianceServiceConfig): ComplianceService;
157
+ /**
158
+ * Reset the global compliance service instance
159
+ */
160
+ declare function resetComplianceService(): void;
161
+
162
+ /**
163
+ * Wallet Service for React applications
164
+ *
165
+ * Provides React-friendly wallet connection and management utilities
166
+ * with proper error handling and state management integration.
167
+ */
168
+ interface WalletConnectionResult {
169
+ success: boolean;
170
+ provider?: ethers.Provider;
171
+ signer?: ethers.Signer;
172
+ address?: string;
173
+ chainId?: number;
174
+ error?: string;
175
+ }
176
+ interface WalletInfo {
177
+ address: string;
178
+ chainId: number;
179
+ balance: string;
180
+ isConnected: boolean;
181
+ }
182
+ declare class WalletService {
183
+ private provider;
184
+ private signer;
185
+ private currentAddress;
186
+ /**
187
+ * Connect to MetaMask or other Web3 wallet
188
+ */
189
+ connectWallet(): Promise<WalletConnectionResult>;
190
+ /**
191
+ * Disconnect wallet
192
+ */
193
+ disconnect(): void;
194
+ /**
195
+ * Get current wallet info
196
+ */
197
+ getWalletInfo(): Promise<WalletInfo | null>;
198
+ /**
199
+ * Switch to a specific network
200
+ */
201
+ switchNetwork(chainId: number): Promise<{
202
+ success: boolean;
203
+ error?: string;
204
+ }>;
205
+ /**
206
+ * Add a custom network to the wallet
207
+ */
208
+ addNetwork(networkConfig: {
209
+ chainId: number;
210
+ chainName: string;
211
+ rpcUrls: string[];
212
+ nativeCurrency: {
213
+ name: string;
214
+ symbol: string;
215
+ decimals: number;
216
+ };
217
+ blockExplorerUrls?: string[];
218
+ }): Promise<{
219
+ success: boolean;
220
+ error?: string;
221
+ }>;
222
+ /**
223
+ * Sign a message
224
+ */
225
+ signMessage(message: string): Promise<{
226
+ success: boolean;
227
+ signature?: string;
228
+ error?: string;
229
+ }>;
230
+ /**
231
+ * Get current provider
232
+ */
233
+ getProvider(): ethers.Provider | null;
234
+ /**
235
+ * Get current signer
236
+ */
237
+ getSigner(): ethers.Signer | null;
238
+ /**
239
+ * Get current address
240
+ */
241
+ getCurrentAddress(): string | null;
242
+ /**
243
+ * Check if wallet is connected
244
+ */
245
+ isConnected(): boolean;
246
+ /**
247
+ * Listen for account changes
248
+ */
249
+ onAccountsChanged(callback: (accounts: string[]) => void): void;
250
+ /**
251
+ * Listen for chain changes
252
+ */
253
+ onChainChanged(callback: (chainId: string) => void): void;
254
+ /**
255
+ * Remove event listeners
256
+ */
257
+ removeAllListeners(): void;
258
+ }
259
+ /**
260
+ * Get or create the global wallet service instance
261
+ */
262
+ declare function getWalletService(): WalletService;
263
+ /**
264
+ * Reset the global wallet service instance
265
+ */
266
+ declare function resetWalletService(): void;
267
+ declare global {
268
+ interface Window {
269
+ ethereum?: {
270
+ request: (args: {
271
+ method: string;
272
+ params?: any[];
273
+ }) => Promise<any>;
274
+ on: (event: string, callback: (...args: any[]) => void) => void;
275
+ removeAllListeners: (event: string) => void;
276
+ };
277
+ }
278
+ }
279
+
280
+ /**
281
+ * Custom React hooks for TREZA SDK integration
282
+ *
283
+ * These hooks provide easy-to-use React integration for compliance and wallet functionality
284
+ */
285
+ interface UseWalletResult {
286
+ isConnected: boolean;
287
+ isConnecting: boolean;
288
+ walletInfo: WalletInfo | null;
289
+ provider: ethers.Provider | null;
290
+ signer: ethers.Signer | null;
291
+ address: string | null;
292
+ error: string | null;
293
+ connect: () => Promise<void>;
294
+ disconnect: () => void;
295
+ switchNetwork: (chainId: number) => Promise<void>;
296
+ }
297
+ /**
298
+ * Hook for wallet connection and management
299
+ */
300
+ declare function useWallet(): UseWalletResult;
301
+ interface UseComplianceResult {
302
+ isInitialized: boolean;
303
+ isLoading: boolean;
304
+ error: string | null;
305
+ initiateVerification: (requirements?: ComplianceRequirements) => Promise<string | null>;
306
+ processVerification: (zkPassportResult: any, userAddress: string) => Promise<VerificationResult | null>;
307
+ checkCompliance: (userAddress: string) => Promise<ComplianceStatus | null>;
308
+ generateQRCode: (url: string) => Promise<string | null>;
309
+ }
310
+ /**
311
+ * Hook for compliance operations
312
+ */
313
+ declare function useCompliance(provider?: ethers.Provider, signer?: ethers.Signer): UseComplianceResult;
314
+ interface UseTrezaResult {
315
+ wallet: UseWalletResult;
316
+ compliance: UseComplianceResult;
317
+ isReady: boolean;
318
+ }
319
+ /**
320
+ * Combined hook for wallet and compliance functionality
321
+ */
322
+ declare function useTreza(): UseTrezaResult;
323
+ interface UseVerificationFlowResult {
324
+ status: 'idle' | 'generating' | 'waiting' | 'processing' | 'completed' | 'error';
325
+ verificationUrl: string | null;
326
+ qrCode: string | null;
327
+ result: VerificationResult | null;
328
+ error: string | null;
329
+ startVerification: (userAddress: string, requirements?: ComplianceRequirements) => Promise<void>;
330
+ processResult: (zkPassportResult: any) => Promise<void>;
331
+ reset: () => void;
332
+ }
333
+ /**
334
+ * Hook for managing the complete verification flow
335
+ */
336
+ declare function useVerificationFlow(provider?: ethers.Provider, signer?: ethers.Signer): UseVerificationFlowResult;
337
+
338
+ /**
339
+ * @treza/react - React components for TREZA SDK
340
+ *
341
+ * Privacy-first DeFi UI components with zero-knowledge compliance
342
+ */
343
+
344
+ declare const VERSION = "1.0.0";
345
+
346
+ export { ComplianceProvider, ComplianceService, ComplianceStatusDisplay, ComplianceVerification, GovernanceEligibility, VERSION, WalletService, complianceStyles, getComplianceService, getWalletService, resetComplianceService, resetWalletService, useCompliance, useComplianceContext, useTreza, useVerificationFlow, useWallet };
347
+ export type { ComplianceServiceConfig, UseComplianceResult, UseTrezaResult, UseVerificationFlowResult, UseWalletResult, WalletConnectionResult, WalletInfo };