create-fhevm-example 1.0.3 → 1.0.6
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 +74 -246
- package/dist/config.d.ts +6 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +197 -193
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +14 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +191 -114
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -2,317 +2,145 @@
|
|
|
2
2
|
|
|
3
3
|
Create FHEVM example projects with a single command.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
### Interactive Mode
|
|
5
|
+
## Quick Start
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
8
|
npx create-fhevm-example
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
This
|
|
14
|
-
|
|
15
|
-
1. Choosing between a single example or category project
|
|
16
|
-
2. **For single examples**: First selecting a category, then choosing an example from that category
|
|
17
|
-
3. **For category projects**: Selecting the category directly
|
|
18
|
-
4. Setting the project name and output directory
|
|
19
|
-
5. Optionally installing dependencies and running tests
|
|
20
|
-
|
|
21
|
-
### Direct Mode
|
|
11
|
+
This launches an interactive CLI that guides you through creating a project.
|
|
22
12
|
|
|
23
|
-
|
|
13
|
+
## Direct Mode
|
|
24
14
|
|
|
25
15
|
```bash
|
|
16
|
+
# Create single example
|
|
26
17
|
npx create-fhevm-example --example fhe-counter
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
Create a category project:
|
|
30
18
|
|
|
31
|
-
|
|
19
|
+
# Create category project
|
|
32
20
|
npx create-fhevm-example --category basic
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
With custom output directory:
|
|
36
21
|
|
|
37
|
-
|
|
38
|
-
npx create-fhevm-example --example fhe-counter --output ./my-project
|
|
22
|
+
# With options
|
|
23
|
+
npx create-fhevm-example --example fhe-counter --output ./my-project --install
|
|
39
24
|
```
|
|
40
25
|
|
|
41
|
-
|
|
26
|
+
## CLI Options
|
|
42
27
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
28
|
+
| Option | Description |
|
|
29
|
+
|--------|-------------|
|
|
30
|
+
| `--example <name>` | Create a single example project |
|
|
31
|
+
| `--category <name>` | Create a category project |
|
|
32
|
+
| `--output <dir>` | Output directory |
|
|
33
|
+
| `--install` | Auto-install dependencies |
|
|
34
|
+
| `--test` | Auto-run tests |
|
|
35
|
+
| `--help` | Show help |
|
|
46
36
|
|
|
47
37
|
## Available Examples
|
|
48
38
|
|
|
49
|
-
|
|
50
|
-
- `encrypt-single-value` - FHE encryption mechanism
|
|
51
|
-
- `encrypt-multiple-values` - Multiple value encryption
|
|
52
|
-
- `user-decrypt-single-value` - User decryption mechanism
|
|
53
|
-
- `user-decrypt-multiple-values` - Multiple value decryption
|
|
54
|
-
- `public-decrypt-single-value` - Public decryption
|
|
55
|
-
- `public-decrypt-multiple-values` - Multiple public decryption
|
|
56
|
-
- `fhe-add` - Addition operations on encrypted values
|
|
57
|
-
- `fhe-if-then-else` - Conditional operations with FHE
|
|
58
|
-
- `fhe-arithmetic` - All arithmetic operations
|
|
59
|
-
- `fhe-comparison` - All comparison operations
|
|
60
|
-
- `fhe-access-control` - Access control patterns
|
|
61
|
-
- `fhe-input-proof` - Input proof validation
|
|
62
|
-
- `fhe-handles` - FHE handle lifecycle
|
|
63
|
-
- `fhe-anti-patterns` - Common mistakes and solutions
|
|
64
|
-
- `erc7984` - Confidential token standard
|
|
65
|
-
- `erc7984-erc20-wrapper` - ERC20 to ERC7984 wrapper
|
|
66
|
-
- `swap-erc7984-to-erc20` - Token swap example
|
|
67
|
-
- `swap-erc7984-to-erc7984` - Confidential token swap
|
|
68
|
-
- `vesting-wallet` - Token vesting example
|
|
69
|
-
- `blind-auction` - Encrypted blind auction
|
|
70
|
-
- `hidden-voting` - Encrypted voting system
|
|
39
|
+
**Basic**: `fhe-counter`, `encrypt-single-value`, `encrypt-multiple-values`, `user-decrypt-single-value`, `user-decrypt-multiple-values`, `public-decrypt-single-value`, `public-decrypt-multiple-values`
|
|
71
40
|
|
|
72
|
-
|
|
41
|
+
**FHE Operations**: `fhe-add`, `fhe-if-then-else`, `fhe-arithmetic`, `fhe-comparison`
|
|
73
42
|
|
|
74
|
-
- `
|
|
75
|
-
- `concepts` - Critical Concepts (4 contracts)
|
|
76
|
-
- `operations` - FHE Operations (4 contracts)
|
|
77
|
-
- `openzeppelin` - OpenZeppelin Confidential Contracts (5 contracts)
|
|
78
|
-
- `advanced` - Advanced Examples (2 contracts)
|
|
43
|
+
**Concepts**: `fhe-access-control`, `fhe-input-proof`, `fhe-handles`, `fhe-anti-patterns`
|
|
79
44
|
|
|
80
|
-
|
|
45
|
+
**OpenZeppelin**: `erc7984`, `erc7984-erc20-wrapper`, `swap-erc7984-to-erc20`, `swap-erc7984-to-erc7984`, `vesting-wallet`
|
|
81
46
|
|
|
82
|
-
-
|
|
83
|
-
- `--category <name>` - Create a category project
|
|
84
|
-
- `--output <dir>` - Output directory (default: `./<project-name>`)
|
|
85
|
-
- `--install` - Auto-install dependencies
|
|
86
|
-
- `--test` - Auto-run tests (requires `--install`)
|
|
87
|
-
- `--help`, `-h` - Show help message
|
|
47
|
+
**Advanced**: `blind-auction`, `hidden-voting`
|
|
88
48
|
|
|
89
|
-
##
|
|
49
|
+
## Available Categories
|
|
50
|
+
|
|
51
|
+
| Category | Description |
|
|
52
|
+
|----------|-------------|
|
|
53
|
+
| `basic` | Encryption, decryption, basic operations (9 contracts) |
|
|
54
|
+
| `concepts` | Access control, proofs, handles (4 contracts) |
|
|
55
|
+
| `operations` | Arithmetic, comparison operations (4 contracts) |
|
|
56
|
+
| `openzeppelin` | ERC7984, wrappers, swaps (5 contracts) |
|
|
57
|
+
| `advanced` | Blind auction, voting (2 contracts) |
|
|
90
58
|
|
|
91
|
-
|
|
59
|
+
## What Gets Created
|
|
92
60
|
|
|
93
61
|
- ✅ Hardhat configuration for FHEVM
|
|
94
|
-
- ✅ Smart contracts
|
|
95
|
-
- ✅ Comprehensive test files
|
|
62
|
+
- ✅ Smart contracts and test files
|
|
96
63
|
- ✅ Deployment scripts
|
|
97
|
-
- ✅
|
|
98
|
-
- ✅ All necessary dependencies configured
|
|
64
|
+
- ✅ All dependencies configured
|
|
99
65
|
|
|
100
66
|
## Requirements
|
|
101
67
|
|
|
102
68
|
- Node.js >= 20
|
|
103
|
-
- Git
|
|
104
|
-
|
|
105
|
-
## Configuration
|
|
106
|
-
|
|
107
|
-
### Repository Settings
|
|
69
|
+
- Git
|
|
108
70
|
|
|
109
|
-
|
|
71
|
+
---
|
|
110
72
|
|
|
111
|
-
|
|
112
|
-
export const REPO_URL = "https://github.com/NecipAkgz/fhevm-example-factory";
|
|
113
|
-
export const REPO_BRANCH = "main";
|
|
114
|
-
export const TEMPLATE_SUBMODULE_PATH = "fhevm-hardhat-template";
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
**Important**: If you fork this repository or want to use a different source:
|
|
118
|
-
|
|
119
|
-
1. Update `REPO_URL` to your repository URL
|
|
120
|
-
2. Ensure the repository has the same structure (contracts, test, fhevm-hardhat-template submodule)
|
|
121
|
-
3. Rebuild the package: `npm run build`
|
|
73
|
+
## Developer Only
|
|
122
74
|
|
|
123
|
-
|
|
75
|
+
>This section is for contributors and maintainers of the package.
|
|
124
76
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
### 1. Add Example Configuration
|
|
128
|
-
|
|
129
|
-
Edit [`src/config.ts`](./src/config.ts) and add your example to the `EXAMPLES` object:
|
|
77
|
+
### Configuration
|
|
130
78
|
|
|
131
|
-
|
|
132
|
-
export const EXAMPLES: Record<string, ExampleConfig> = {
|
|
133
|
-
// ... existing examples
|
|
134
|
-
"my-new-example": {
|
|
135
|
-
contract: "contracts/path/to/MyContract.sol",
|
|
136
|
-
test: "test/path/to/MyContract.ts",
|
|
137
|
-
description: "Description of what this example demonstrates",
|
|
138
|
-
category: "Basic", // or "Concepts", "Operations", "OpenZeppelin", "Advanced"
|
|
139
|
-
title: "My New Example",
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
```
|
|
79
|
+
The CLI uses a configuration file that defines all available examples and categories. This file is **auto-generated** from the main repository.
|
|
143
80
|
|
|
144
|
-
|
|
81
|
+
**Source of Truth**: [`scripts/shared/config.ts`](https://github.com/NecipAkgz/fhevm-example-factory/blob/main/scripts/shared/config.ts)
|
|
82
|
+
**Generated File**: `src/config.ts` (do not edit manually)
|
|
145
83
|
|
|
146
|
-
|
|
84
|
+
To customize the repository URL or branch:
|
|
147
85
|
|
|
148
86
|
```typescript
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
description: "...",
|
|
153
|
-
contracts: [
|
|
154
|
-
// ... existing contracts
|
|
155
|
-
{
|
|
156
|
-
sol: "contracts/path/to/MyContract.sol",
|
|
157
|
-
test: "test/path/to/MyContract.ts",
|
|
158
|
-
},
|
|
159
|
-
],
|
|
160
|
-
},
|
|
161
|
-
};
|
|
87
|
+
// In src/config.ts (after sync)
|
|
88
|
+
export const REPO_URL = "https://github.com/YourUsername/your-repo";
|
|
89
|
+
export const REPO_BRANCH = "main";
|
|
162
90
|
```
|
|
163
91
|
|
|
164
|
-
###
|
|
165
|
-
|
|
166
|
-
Make sure the contract and test files exist in your repository at the specified paths:
|
|
92
|
+
### Adding New Examples
|
|
167
93
|
|
|
168
|
-
|
|
169
|
-
- `test/path/to/MyContract.ts`
|
|
94
|
+
To add a new example to the CLI:
|
|
170
95
|
|
|
171
|
-
|
|
96
|
+
1. **Edit the source config** in the main repository:
|
|
97
|
+
```bash
|
|
98
|
+
# Edit scripts/shared/config.ts
|
|
99
|
+
# Add your example to EXAMPLES and CATEGORIES
|
|
100
|
+
```
|
|
172
101
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
102
|
+
2. **Publish**:
|
|
103
|
+
```bash
|
|
104
|
+
npm version patch # Increments version
|
|
105
|
+
npm publish # Auto-runs: sync:config → build → publish
|
|
106
|
+
```
|
|
177
107
|
|
|
178
|
-
|
|
108
|
+
The `prepublishOnly` hook automatically:
|
|
109
|
+
- Syncs config from `scripts/shared/config.ts` to `src/config.ts`
|
|
110
|
+
- Builds TypeScript to `dist/`
|
|
111
|
+
- Publishes to NPM
|
|
179
112
|
|
|
180
|
-
### Local Development
|
|
113
|
+
### Local Development
|
|
181
114
|
|
|
182
115
|
```bash
|
|
183
|
-
# Clone
|
|
116
|
+
# Clone and setup
|
|
184
117
|
git clone https://github.com/NecipAkgz/fhevm-example-factory.git
|
|
185
118
|
cd fhevm-example-factory/packages/create-fhevm-example
|
|
186
|
-
|
|
187
|
-
# Install dependencies
|
|
188
119
|
npm install
|
|
189
120
|
|
|
190
|
-
# Build
|
|
121
|
+
# Build
|
|
191
122
|
npm run build
|
|
192
123
|
|
|
193
|
-
#
|
|
124
|
+
# Test locally
|
|
194
125
|
npm link
|
|
195
|
-
|
|
196
|
-
# Now you can use it globally
|
|
197
126
|
create-fhevm-example --help
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
### Making Changes
|
|
201
127
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
3. **Test locally**: `create-fhevm-example --example fhe-counter --output /tmp/test`
|
|
205
|
-
|
|
206
|
-
### File Structure
|
|
207
|
-
|
|
208
|
-
```
|
|
209
|
-
src/
|
|
210
|
-
├── index.ts # Main CLI entry point (interactive + direct modes)
|
|
211
|
-
├── config.ts # Examples and categories configuration
|
|
212
|
-
└── utils.ts # Helper functions (GitHub download, file ops, README generation)
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
## Publishing to NPM
|
|
216
|
-
|
|
217
|
-
### Pre-publish Checklist
|
|
218
|
-
|
|
219
|
-
- [ ] Update version in `package.json`
|
|
220
|
-
- [ ] Test locally with `npm link`
|
|
221
|
-
- [ ] Verify all examples work
|
|
222
|
-
- [ ] Update README if needed
|
|
223
|
-
- [ ] Commit all changes
|
|
224
|
-
|
|
225
|
-
### Publish Steps
|
|
226
|
-
|
|
227
|
-
```bash
|
|
228
|
-
# Dry run to see what will be published
|
|
229
|
-
npm publish --dry-run
|
|
230
|
-
|
|
231
|
-
# Check package contents
|
|
232
|
-
npm pack
|
|
233
|
-
tar -xvzf create-fhevm-example-*.tgz
|
|
234
|
-
rm -rf package create-fhevm-example-*.tgz
|
|
235
|
-
|
|
236
|
-
# Publish to NPM
|
|
237
|
-
npm publish
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
### Post-publish Verification
|
|
241
|
-
|
|
242
|
-
```bash
|
|
243
|
-
# Test from NPM in a clean directory
|
|
244
|
-
cd /tmp
|
|
245
|
-
npx create-fhevm-example@latest --example fhe-counter
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
## Troubleshooting
|
|
249
|
-
|
|
250
|
-
### "Repository not found" Error
|
|
251
|
-
|
|
252
|
-
**Problem**: Git clone fails with repository not found.
|
|
253
|
-
|
|
254
|
-
**Solution**: Check `REPO_URL` in `src/config.ts`. Make sure:
|
|
255
|
-
|
|
256
|
-
- The repository exists and is public
|
|
257
|
-
- The URL is correct (without trailing slash)
|
|
258
|
-
- You have internet connection
|
|
259
|
-
|
|
260
|
-
### "Failed to download" Error
|
|
261
|
-
|
|
262
|
-
**Problem**: File download from GitHub fails.
|
|
263
|
-
|
|
264
|
-
**Solution**:
|
|
265
|
-
|
|
266
|
-
- Verify the file paths in `config.ts` match actual files in the repository
|
|
267
|
-
- Check that `REPO_BRANCH` is correct (usually "main" or "master")
|
|
268
|
-
- Ensure the repository is public or you have access
|
|
269
|
-
|
|
270
|
-
### Build Errors
|
|
271
|
-
|
|
272
|
-
**Problem**: TypeScript compilation fails.
|
|
273
|
-
|
|
274
|
-
**Solution**:
|
|
275
|
-
|
|
276
|
-
```bash
|
|
277
|
-
# Clean and rebuild
|
|
278
|
-
rm -rf dist
|
|
279
|
-
npm run build
|
|
128
|
+
# Unlink when done
|
|
129
|
+
npm unlink -g create-fhevm-example
|
|
280
130
|
```
|
|
281
131
|
|
|
282
|
-
###
|
|
283
|
-
|
|
284
|
-
**Problem**: New example doesn't appear in the CLI.
|
|
285
|
-
|
|
286
|
-
**Solution**:
|
|
287
|
-
|
|
288
|
-
- Make sure you added it to `EXAMPLES` in `config.ts`
|
|
289
|
-
- Rebuild: `npm run build`
|
|
290
|
-
- If using `npm link`, unlink and relink:
|
|
291
|
-
```bash
|
|
292
|
-
npm unlink -g create-fhevm-example
|
|
293
|
-
npm link
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
## Maintenance
|
|
297
|
-
|
|
298
|
-
### Updating Template Repository
|
|
299
|
-
|
|
300
|
-
When the `fhevm-hardhat-template` submodule is updated:
|
|
301
|
-
|
|
302
|
-
1. No changes needed in this package - it clones fresh each time
|
|
303
|
-
2. Users will automatically get the latest template
|
|
304
|
-
|
|
305
|
-
### Syncing Examples
|
|
132
|
+
### Scripts
|
|
306
133
|
|
|
307
|
-
|
|
134
|
+
- `npm run build` - Compile TypeScript
|
|
135
|
+
- `npm run dev` - Watch mode
|
|
136
|
+
- `npm run sync:config` - Sync config from main repo
|
|
137
|
+
- `npm run prepublishOnly` - Auto-runs sync + build before publish
|
|
308
138
|
|
|
309
|
-
|
|
310
|
-
2. Increment version in `package.json`
|
|
311
|
-
3. Rebuild and publish: `npm run build && npm publish`
|
|
139
|
+
---
|
|
312
140
|
|
|
313
141
|
## Learn More
|
|
314
142
|
|
|
315
|
-
- [FHEVM Documentation](https://docs.zama.
|
|
143
|
+
- [FHEVM Documentation](https://docs.zama.org/protocol)
|
|
316
144
|
- [Example Repository](https://github.com/NecipAkgz/fhevm-example-factory)
|
|
317
145
|
- [Zama](https://www.zama.ai/)
|
|
318
146
|
|
package/dist/config.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* ⚠️ AUTO-GENERATED FILE - DO NOT EDIT MANUALLY ⚠️
|
|
3
3
|
*
|
|
4
|
-
* This
|
|
4
|
+
* This file is auto-generated from scripts/shared/config.ts
|
|
5
|
+
* Run 'npm run sync:config' to update it.
|
|
6
|
+
*
|
|
7
|
+
* Source: scripts/shared/config.ts
|
|
8
|
+
* Generated: 2025-12-09T16:46:12.589Z
|
|
5
9
|
*/
|
|
6
10
|
export interface ExampleConfig {
|
|
7
11
|
/** Path to the Solidity contract file */
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,WAAW,EAAE,MAAM,CAAC;IACpB,4BAA4B;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,SAAS,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAClD;AAMD,eAAO,MAAM,QAAQ,uDAAuD,CAAC;AAC7E,eAAO,MAAM,WAAW,SAAS,CAAC;AAClC,eAAO,MAAM,uBAAuB,2BAA2B,CAAC;AAMhE,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CA2JlD,CAAC;AAMF,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CA+HrD,CAAC"}
|