@cofhe/react 0.0.0-alpha-20260409113701

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/README.md ADDED
@@ -0,0 +1,159 @@
1
+ # @cofhe/react
2
+
3
+ React component and hook for the CoFHE SDK - featuring the advanced FnxEncryptInput component.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @cofhe/react @cofhe/sdk @mui/icons-material @mui/material
9
+ # or
10
+ pnpm add @cofhe/react @cofhe/sdk @mui/icons-material @mui/material
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ### 1. Wrap your app with CofheProvider
16
+
17
+ ```tsx
18
+ import { CofheProvider } from '@cofhe/react';
19
+ import '@cofhe/react/styles.css'; // Import component styles
20
+ import { createCofheClient } from '@cofhe/sdk/web';
21
+
22
+ const client = createCofheClient(config);
23
+
24
+ function App() {
25
+ return (
26
+ <CofheProvider client={client}>
27
+ <YourApp />
28
+ </CofheProvider>
29
+ );
30
+ }
31
+ ```
32
+
33
+ ### 2. Use the FnxEncryptInput component
34
+
35
+ ```tsx
36
+ import { FnxEncryptInput, FheTypesList } from '@cofhe/react';
37
+
38
+ function MyComponent() {
39
+ return (
40
+ <FnxEncryptInput
41
+ placeholder="Enter value to encrypt..."
42
+ options={FheTypesList} // Pre-defined FHE types
43
+ showProgressBar={true}
44
+ onEncryptComplete={(data) => console.log('Encrypted:', data)}
45
+ onEncryptError={(error) => console.error('Error:', error)}
46
+ />
47
+ );
48
+ }
49
+ ```
50
+
51
+ ### 3. Use the hook directly for custom implementations
52
+
53
+ ```tsx
54
+ import { useEncryptInput } from '@cofhe/react';
55
+
56
+ function CustomComponent() {
57
+ const { onEncryptInput, isEncryptingInput, encryptionProgress } = useEncryptInput();
58
+
59
+ const handleEncrypt = async () => {
60
+ try {
61
+ const result = await onEncryptInput('uint32', '42');
62
+ console.log('Encrypted:', result);
63
+ } catch (error) {
64
+ console.error('Encryption failed:', error);
65
+ }
66
+ };
67
+
68
+ return (
69
+ <div>
70
+ <button onClick={handleEncrypt} disabled={isEncryptingInput}>
71
+ {isEncryptingInput ? `Encrypting... ${encryptionProgress}%` : 'Encrypt Value'}
72
+ </button>
73
+ </div>
74
+ );
75
+ }
76
+ ```
77
+
78
+ ## FnxEncryptInput Component
79
+
80
+ Advanced input component with integrated features:
81
+
82
+ ### Features
83
+
84
+ - ✅ **Type Selection Dropdown** - Choose from uint8, uint16, uint32, uint64, uint128, bool, address
85
+ - ✅ **Real-time Input Validation** - Validates input against selected FHE type
86
+ - ✅ **Progress Tracking** - Shows encryption steps with progress bar
87
+ - ✅ **Copy to Clipboard** - Copy encrypted results with one click
88
+ - ✅ **Material-UI Icons** - Beautiful, consistent iconography
89
+ - ✅ **Responsive Design** - Works on desktop and mobile
90
+ - ✅ **Dark Mode Support** - Automatic dark/light theme support
91
+ - ✅ **TypeScript Support** - Full type safety
92
+
93
+ ### Props
94
+
95
+ ```tsx
96
+ interface FnxEncryptInputProps {
97
+ placeholder?: string;
98
+ initialValue?: string;
99
+ options?: FheTypeOption[]; // Use FheTypesList or custom options
100
+ size?: 'sm' | 'md' | 'lg';
101
+ hasError?: boolean;
102
+ errorMessage?: string;
103
+ disabled?: boolean;
104
+ showProgressBar?: boolean;
105
+ debounceMs?: number;
106
+ onTextChange?: (value: string) => void;
107
+ onTypeChange?: (value: string) => void;
108
+ onEncryptStart?: (data: EncryptionStartData) => void;
109
+ onEncryptProgress?: (data: EncryptionProgressData) => void;
110
+ onEncryptComplete?: (data: EncryptionResultData) => void;
111
+ onEncryptError?: (error: string) => void;
112
+ className?: string;
113
+ testId?: string;
114
+ }
115
+ ```
116
+
117
+ ## useEncryptInput Hook
118
+
119
+ Hook for custom encryption workflows with progress tracking:
120
+
121
+ ```tsx
122
+ const {
123
+ onEncryptInput, // (type, value) => Promise<encrypted>
124
+ isEncryptingInput, // boolean - encryption in progress
125
+ encryptionStep, // Current step: 'fetchKeys' | 'pack' | 'prove' | 'verify' | 'done'
126
+ encryptionProgress, // Progress percentage (0-100)
127
+ encryptionProgressLabel, // Human-readable progress label
128
+ inputEncryptionDisabled, // boolean - whether encryption is disabled
129
+ } = useEncryptInput();
130
+ ```
131
+
132
+ ## Styling
133
+
134
+ The package includes Tailwind CSS styles. Import them in your app:
135
+
136
+ ```tsx
137
+ import '@cofhe/react/styles.css';
138
+ ```
139
+
140
+ If you're using Tailwind CSS in your project, the component classes will work automatically.
141
+
142
+ ## Dependencies
143
+
144
+ ### Required Peer Dependencies
145
+
146
+ - `@mui/icons-material` ^5.0.0
147
+ - `@mui/material` ^5.0.0
148
+ - `react` ^16.8.0 || ^17.0.0 || ^18.0.0
149
+ - `react-dom` ^16.8.0 || ^17.0.0 || ^18.0.0
150
+
151
+ ### CoFHE SDK Dependencies
152
+
153
+ - `@cofhe/sdk/web` - Web-specific CoFHE SDK
154
+ - `@cofhe/sdk/adapters` - Provider adapters
155
+ - `@cofhe/sdk/chains` - Chain configurations
156
+
157
+ ## Example
158
+
159
+ See the complete example application in the `/example` directory of this repository for interactive demonstrations of all features.