@cofhe/react 0.1.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/README.md +156 -0
- package/dist/index.cjs +619 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +859 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.cts +106 -0
- package/dist/index.d.ts +106 -0
- package/dist/index.js +576 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +859 -0
- package/dist/styles.css.map +1 -0
- package/dist/styles.d.cts +2 -0
- package/dist/styles.d.ts +2 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# @cofhesdk/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 @cofhesdk/react @cofhesdk/web @cofhesdk/adapters @mui/icons-material @mui/material
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @cofhesdk/react @cofhesdk/web @cofhesdk/adapters @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 '@cofhesdk/react';
|
|
19
|
+
import '@cofhesdk/react/styles.css'; // Import component styles
|
|
20
|
+
import { createCofhesdkClient } from '@cofhesdk/web';
|
|
21
|
+
|
|
22
|
+
const client = createCofhesdkClient(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 '@cofhesdk/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 '@cofhesdk/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
|
+
- ✅ **Type Selection Dropdown** - Choose from uint8, uint16, uint32, uint64, uint128, bool, address
|
|
84
|
+
- ✅ **Real-time Input Validation** - Validates input against selected FHE type
|
|
85
|
+
- ✅ **Progress Tracking** - Shows encryption steps with progress bar
|
|
86
|
+
- ✅ **Copy to Clipboard** - Copy encrypted results with one click
|
|
87
|
+
- ✅ **Material-UI Icons** - Beautiful, consistent iconography
|
|
88
|
+
- ✅ **Responsive Design** - Works on desktop and mobile
|
|
89
|
+
- ✅ **Dark Mode Support** - Automatic dark/light theme support
|
|
90
|
+
- ✅ **TypeScript Support** - Full type safety
|
|
91
|
+
|
|
92
|
+
### Props
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
interface FnxEncryptInputProps {
|
|
96
|
+
placeholder?: string;
|
|
97
|
+
initialValue?: string;
|
|
98
|
+
options?: FheTypeOption[]; // Use FheTypesList or custom options
|
|
99
|
+
size?: 'sm' | 'md' | 'lg';
|
|
100
|
+
hasError?: boolean;
|
|
101
|
+
errorMessage?: string;
|
|
102
|
+
disabled?: boolean;
|
|
103
|
+
showProgressBar?: boolean;
|
|
104
|
+
debounceMs?: number;
|
|
105
|
+
onTextChange?: (value: string) => void;
|
|
106
|
+
onTypeChange?: (value: string) => void;
|
|
107
|
+
onEncryptStart?: (data: EncryptionStartData) => void;
|
|
108
|
+
onEncryptProgress?: (data: EncryptionProgressData) => void;
|
|
109
|
+
onEncryptComplete?: (data: EncryptionResultData) => void;
|
|
110
|
+
onEncryptError?: (error: string) => void;
|
|
111
|
+
className?: string;
|
|
112
|
+
testId?: string;
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## useEncryptInput Hook
|
|
117
|
+
|
|
118
|
+
Hook for custom encryption workflows with progress tracking:
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
const {
|
|
122
|
+
onEncryptInput, // (type, value) => Promise<encrypted>
|
|
123
|
+
isEncryptingInput, // boolean - encryption in progress
|
|
124
|
+
encryptionStep, // Current step: 'fetchKeys' | 'pack' | 'prove' | 'verify' | 'done'
|
|
125
|
+
encryptionProgress, // Progress percentage (0-100)
|
|
126
|
+
encryptionProgressLabel, // Human-readable progress label
|
|
127
|
+
inputEncryptionDisabled, // boolean - whether encryption is disabled
|
|
128
|
+
} = useEncryptInput();
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Styling
|
|
132
|
+
|
|
133
|
+
The package includes Tailwind CSS styles. Import them in your app:
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
import '@cofhesdk/react/styles.css';
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
If you're using Tailwind CSS in your project, the component classes will work automatically.
|
|
140
|
+
|
|
141
|
+
## Dependencies
|
|
142
|
+
|
|
143
|
+
### Required Peer Dependencies
|
|
144
|
+
- `@mui/icons-material` ^5.0.0
|
|
145
|
+
- `@mui/material` ^5.0.0
|
|
146
|
+
- `react` ^16.8.0 || ^17.0.0 || ^18.0.0
|
|
147
|
+
- `react-dom` ^16.8.0 || ^17.0.0 || ^18.0.0
|
|
148
|
+
|
|
149
|
+
### CoFHE SDK Dependencies
|
|
150
|
+
- `@cofhesdk/web` - Web-specific CoFHE SDK
|
|
151
|
+
- `@cofhesdk/adapters` - Provider adapters
|
|
152
|
+
- `@cofhesdk/chains` - Chain configurations
|
|
153
|
+
|
|
154
|
+
## Example
|
|
155
|
+
|
|
156
|
+
See the complete example application in the `/example` directory of this repository for interactive demonstrations of all features.
|