create-fhevm-example 1.2.3 → 1.3.1
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 +72 -146
- package/dist/scripts/add-mode.d.ts +11 -0
- package/dist/scripts/add-mode.d.ts.map +1 -0
- package/dist/{add-mode.js → scripts/add-mode.js} +84 -58
- package/dist/scripts/builders.d.ts +19 -0
- package/dist/scripts/builders.d.ts.map +1 -0
- package/dist/scripts/builders.js +211 -0
- package/dist/{config.d.ts → scripts/config.d.ts} +24 -3
- package/dist/scripts/config.d.ts.map +1 -0
- package/dist/scripts/config.js +465 -0
- package/dist/scripts/doctor.d.ts +11 -0
- package/dist/scripts/doctor.d.ts.map +1 -0
- package/dist/scripts/doctor.js +165 -0
- package/dist/scripts/generate-config.d.ts +9 -0
- package/dist/scripts/generate-config.d.ts.map +1 -0
- package/dist/scripts/generate-config.js +323 -0
- package/dist/scripts/generate-docs.d.ts +10 -0
- package/dist/scripts/generate-docs.d.ts.map +1 -0
- package/dist/scripts/generate-docs.js +190 -0
- package/dist/scripts/index.d.ts +12 -0
- package/dist/scripts/index.d.ts.map +1 -0
- package/dist/scripts/index.js +384 -0
- package/dist/scripts/maintenance.d.ts +13 -0
- package/dist/scripts/maintenance.d.ts.map +1 -0
- package/dist/scripts/maintenance.js +271 -0
- package/dist/{prompts.d.ts → scripts/ui.d.ts} +8 -7
- package/dist/scripts/ui.d.ts.map +1 -0
- package/dist/scripts/ui.js +170 -0
- package/dist/scripts/utils.d.ts +86 -0
- package/dist/scripts/utils.d.ts.map +1 -0
- package/dist/scripts/utils.js +525 -0
- package/package.json +25 -13
- package/dist/add-mode.d.ts +0 -21
- package/dist/add-mode.d.ts.map +0 -1
- package/dist/add-mode.js.map +0 -1
- package/dist/builders.d.ts +0 -30
- package/dist/builders.d.ts.map +0 -1
- package/dist/builders.js +0 -195
- package/dist/builders.js.map +0 -1
- package/dist/commands.d.ts +0 -19
- package/dist/commands.d.ts.map +0 -1
- package/dist/commands.js +0 -91
- package/dist/commands.js.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -398
- package/dist/config.js.map +0 -1
- package/dist/constants.d.ts +0 -16
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -40
- package/dist/constants.js.map +0 -1
- package/dist/index.d.ts +0 -20
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -337
- package/dist/index.js.map +0 -1
- package/dist/prompts.d.ts.map +0 -1
- package/dist/prompts.js +0 -79
- package/dist/prompts.js.map +0 -1
- package/dist/ui.d.ts +0 -35
- package/dist/ui.d.ts.map +0 -1
- package/dist/ui.js +0 -155
- package/dist/ui.js.map +0 -1
- package/dist/utils.d.ts +0 -99
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -285
- package/dist/utils.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<strong>Create FHEVM example projects with a single command</strong>
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://docs.zama.org/protocol"><img src="https://img.shields.io/badge/docs-fhevm-blue" alt="FHEVM Docs"></a>
|
|
7
|
+
<a href="https://github.com/NecipAkgz/fhevm-example-factory/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-BSD--3--Clause--Clear-green" alt="License"></a>
|
|
8
|
+
<a href="#"><img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" alt="Node"></a>
|
|
9
|
+
</p>
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 🚀 Quick Start
|
|
15
|
+
|
|
16
|
+
Launch the interactive CLI to create your project:
|
|
6
17
|
|
|
7
18
|
```bash
|
|
8
19
|
npx create-fhevm-example
|
|
@@ -10,9 +21,29 @@ npx create-fhevm-example
|
|
|
10
21
|
|
|
11
22
|

|
|
12
23
|
|
|
13
|
-
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 🔧 Add to Existing Hardhat Project
|
|
14
27
|
|
|
15
|
-
|
|
28
|
+
Already have a Hardhat project? Inject FHEVM capabilities without starting from scratch:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx create-fhevm-example --add
|
|
32
|
+
npx create-fhevm-example --add --target ./my-existing-project
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
This will:
|
|
36
|
+
- ✅ Detect your Hardhat project
|
|
37
|
+
- ✅ Add FHEVM dependencies to `package.json`
|
|
38
|
+
- ✅ Update `hardhat.config.ts` with FHEVM plugin
|
|
39
|
+
- ✅ Add an example contract and test of your choice
|
|
40
|
+
- ✅ Handle file conflicts intelligently (skip/overwrite/rename)
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## ⚡ Quick Commands
|
|
45
|
+
|
|
46
|
+
Skip the prompts and create projects directly:
|
|
16
47
|
|
|
17
48
|
```bash
|
|
18
49
|
# Create single example
|
|
@@ -25,183 +56,78 @@ npx create-fhevm-example --category basic
|
|
|
25
56
|
npx create-fhevm-example --add
|
|
26
57
|
npx create-fhevm-example --add --target ./my-existing-project
|
|
27
58
|
|
|
28
|
-
# With
|
|
29
|
-
npx create-fhevm-example --example fhe-counter --output ./my-project --install
|
|
59
|
+
# With auto-install and testing
|
|
60
|
+
npx create-fhevm-example --example fhe-counter --output ./my-project --install --test
|
|
30
61
|
```
|
|
31
62
|
|
|
32
|
-
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## 📋 CLI Options
|
|
33
66
|
|
|
34
67
|
| Option | Description |
|
|
35
|
-
|
|
68
|
+
| :--- | :--- |
|
|
36
69
|
| `--example <name>` | Create a single example project |
|
|
37
70
|
| `--category <name>` | Create a category project |
|
|
38
|
-
| `--add` | Add FHEVM to existing Hardhat project |
|
|
39
|
-
| `--target <dir>` | Target directory for
|
|
40
|
-
| `--output <dir>` | Output directory |
|
|
41
|
-
| `--install` | Auto-install dependencies |
|
|
42
|
-
| `--test` | Auto-run tests |
|
|
43
|
-
| `--help` | Show help |
|
|
71
|
+
| `--add` | Add FHEVM to an existing Hardhat project |
|
|
72
|
+
| `--target <dir>` | Target directory for `--add` mode (default: current dir) |
|
|
73
|
+
| `--output <dir>` | Output directory for new projects |
|
|
74
|
+
| `--install` | Auto-install dependencies after scaffolding |
|
|
75
|
+
| `--test` | Auto-run tests (requires `--install`) |
|
|
76
|
+
| `--help`, `-h` | Show help information |
|
|
44
77
|
|
|
45
|
-
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 📦 Available Examples
|
|
46
81
|
|
|
47
|
-
**Basic
|
|
82
|
+
**Basic Encryption** (3): `fhe-counter`, `encrypt-single-value`, `encrypt-multiple-values`
|
|
48
83
|
|
|
49
|
-
**
|
|
84
|
+
**Decryption** (4): `user-decrypt-single-value`, `user-decrypt-multiple-values`, `public-decrypt-single-value`, `public-decrypt-multiple-values`
|
|
50
85
|
|
|
51
|
-
**
|
|
86
|
+
**FHE Operations** (4): `fhe-add`, `fhe-if-then-else`, `fhe-arithmetic`, `fhe-comparison`
|
|
52
87
|
|
|
53
|
-
**
|
|
88
|
+
**Concepts** (4): `fhe-access-control`, `fhe-input-proof`, `fhe-handles`, `fhe-anti-patterns`
|
|
54
89
|
|
|
55
|
-
**
|
|
90
|
+
**Gaming** (3): `rock-paper-scissors`, `encrypted-lottery`, `encrypted-poker`
|
|
56
91
|
|
|
57
|
-
**
|
|
92
|
+
**OpenZeppelin** (5): `erc7984`, `erc7984-erc20-wrapper`, `swap-erc7984-to-erc20`, `swap-erc7984-to-erc7984`, `vesting-wallet`
|
|
58
93
|
|
|
59
|
-
|
|
94
|
+
**Advanced** (5): `blind-auction`, `hidden-voting`, `private-payroll`, `encrypted-escrow`, `private-kyc`
|
|
60
95
|
|
|
61
|
-
|
|
62
|
-
|----------|-------------|
|
|
63
|
-
| `basic` | Basic encryption and counter examples (1 contract) |
|
|
64
|
-
| `basicencryption` | Single and multiple value encryption (2 contracts) |
|
|
65
|
-
| `basicdecryption` | Public and user decryption examples (4 contracts) |
|
|
66
|
-
| `basicfheoperations` | FHE arithmetic and comparison (4 contracts) |
|
|
67
|
-
| `concepts` | Access control, proofs, handles, anti-patterns (4 contracts) |
|
|
68
|
-
| `gaming` | Rock-paper-scissors, lottery, poker (3 contracts) |
|
|
69
|
-
| `openzeppelin` | ERC7984, wrappers, swaps, vesting (5 contracts) |
|
|
70
|
-
| `advanced` | Blind auction, voting, payroll, escrow, KYC (5 contracts) |
|
|
96
|
+
---
|
|
71
97
|
|
|
72
|
-
## What Gets Created
|
|
98
|
+
## ✅ What Gets Created
|
|
73
99
|
|
|
74
|
-
### New Projects (
|
|
100
|
+
### New Projects (`--example` / `--category`)
|
|
75
101
|
|
|
76
102
|
- ✅ Hardhat configuration for FHEVM
|
|
77
|
-
- ✅ Smart contracts and
|
|
103
|
+
- ✅ Smart contracts and comprehensive tests
|
|
78
104
|
- ✅ Deployment scripts
|
|
79
105
|
- ✅ All dependencies configured
|
|
80
106
|
|
|
81
|
-
### Existing Projects (
|
|
107
|
+
### Existing Projects (`--add`)
|
|
82
108
|
|
|
83
109
|
- ✅ FHEVM dependencies added to `package.json`
|
|
84
110
|
- ✅ FHEVM plugin imported in `hardhat.config.ts`
|
|
85
111
|
- ✅ Example contract and test of your choice
|
|
86
|
-
- ✅ Intelligent
|
|
112
|
+
- ✅ Intelligent conflict handling (skip/overwrite/rename)
|
|
87
113
|
|
|
88
|
-
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 💻 Requirements
|
|
89
117
|
|
|
90
118
|
- Node.js >= 20
|
|
91
119
|
- Git
|
|
92
120
|
|
|
93
121
|
---
|
|
94
122
|
|
|
95
|
-
##
|
|
96
|
-
|
|
97
|
-
>This section is for contributors and maintainers of the package.
|
|
123
|
+
## 🔗 Learn More
|
|
98
124
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
```
|
|
104
|
-
src/
|
|
105
|
-
├── index.ts # Main entry point + CLI modes (~320 lines)
|
|
106
|
-
├── builders.ts # createSingleExample, createCategoryProject (~250 lines)
|
|
107
|
-
├── ui.ts # Interactive prompts + install/test commands (~180 lines)
|
|
108
|
-
├── utils.ts # Utilities + constants + validation + logging (~350 lines)
|
|
109
|
-
├── config.ts # Auto-generated examples & categories (~440 lines)
|
|
110
|
-
└── add-mode.ts # Add FHEVM to existing projects (~370 lines)
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
**Key Components:**
|
|
114
|
-
- `index.ts` - Main CLI entry point, handles interactive and direct modes
|
|
115
|
-
- `builders.ts` - Project creation logic (single example, category project)
|
|
116
|
-
- `ui.ts` - User interface (prompts + commands, replaces old prompts.ts + commands.ts)
|
|
117
|
-
- `utils.ts` - File operations, constants, validation, logging utilities
|
|
118
|
-
- `config.ts` - Auto-generated configuration from monorepo contracts
|
|
119
|
-
- `add-mode.ts` - Add FHEVM to existing Hardhat projects
|
|
120
|
-
|
|
121
|
-
**Design Principles:**
|
|
122
|
-
- **Modular**: Each file has a single responsibility
|
|
123
|
-
- **Aligned**: Mirrors main project's `scripts/` structure
|
|
124
|
-
- **Maintainable**: Easy to understand and update
|
|
125
|
-
- **Type-safe**: Full TypeScript coverage
|
|
126
|
-
- **Consistent**: Standardized logging, error handling, validation
|
|
127
|
-
|
|
128
|
-
### Configuration
|
|
129
|
-
|
|
130
|
-
The CLI uses a configuration file that defines all available examples and categories. This file is **auto-generated** by scanning the monorepo's contracts directory.
|
|
131
|
-
|
|
132
|
-
**Generated File**: `src/config.ts` (do not edit manually)
|
|
133
|
-
|
|
134
|
-
To customize the repository URL or branch:
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
// In src/config.ts
|
|
138
|
-
export const REPO_URL = "https://github.com/YourUsername/your-repo";
|
|
139
|
-
export const REPO_BRANCH = "main";
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### Adding New Examples
|
|
143
|
-
|
|
144
|
-
To add a new example to the CLI:
|
|
145
|
-
|
|
146
|
-
1. **Create contract with `@notice` tag** in the main repository:
|
|
147
|
-
```solidity
|
|
148
|
-
/**
|
|
149
|
-
* @notice Your example description - auto-discovered!
|
|
150
|
-
*/
|
|
151
|
-
contract YourExample { }
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
2. **Update package config** (from monorepo):
|
|
155
|
-
```bash
|
|
156
|
-
cd packages/create-fhevm-example
|
|
157
|
-
npm run update:config # Scans ../../contracts, generates src/config.ts
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
3. **Publish**:
|
|
161
|
-
```bash
|
|
162
|
-
npm version patch # Increments version
|
|
163
|
-
npm publish # Auto-runs: update:config → build → publish
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
The `prepublishOnly` hook automatically:
|
|
167
|
-
- Updates config by scanning monorepo contracts (if available)
|
|
168
|
-
- Builds TypeScript to `dist/`
|
|
169
|
-
- Publishes to NPM
|
|
170
|
-
|
|
171
|
-
### Local Development
|
|
172
|
-
|
|
173
|
-
```bash
|
|
174
|
-
# Clone and setup
|
|
175
|
-
git clone https://github.com/NecipAkgz/fhevm-example-factory.git
|
|
176
|
-
cd fhevm-example-factory/packages/create-fhevm-example
|
|
177
|
-
npm install
|
|
178
|
-
|
|
179
|
-
# Build
|
|
180
|
-
npm run build
|
|
181
|
-
|
|
182
|
-
# Test locally
|
|
183
|
-
npm link
|
|
184
|
-
create-fhevm-example --help
|
|
185
|
-
|
|
186
|
-
# Unlink when done
|
|
187
|
-
npm unlink -g create-fhevm-example
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
### Scripts
|
|
191
|
-
|
|
192
|
-
- `npm run build` - Compile TypeScript to `dist/`
|
|
193
|
-
- `npm run dev` - Watch mode for development
|
|
194
|
-
- `npm run update:config` - Regenerate config from monorepo contracts
|
|
195
|
-
- `npm run prepublishOnly` - Auto-runs before publish (update:config + build)
|
|
125
|
+
- 📖 [FHEVM Documentation](https://docs.zama.org/protocol)
|
|
126
|
+
- 💻 [Source Repository](https://github.com/NecipAkgz/fhevm-example-factory)
|
|
127
|
+
- 🌐 [Zama](https://www.zama.ai/)
|
|
196
128
|
|
|
197
129
|
---
|
|
198
130
|
|
|
199
|
-
##
|
|
200
|
-
|
|
201
|
-
- [FHEVM Documentation](https://docs.zama.org/protocol)
|
|
202
|
-
- [Example Repository](https://github.com/NecipAkgz/fhevm-example-factory)
|
|
203
|
-
- [Zama](https://www.zama.ai/)
|
|
204
|
-
|
|
205
|
-
## License
|
|
131
|
+
## 📄 License
|
|
206
132
|
|
|
207
133
|
BSD-3-Clause-Clear
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add Mode - Feature for adding FHEVM to existing Hardhat projects.
|
|
3
|
+
*
|
|
4
|
+
* Logic for managing configuration updates, dependency installations,
|
|
5
|
+
* and scaffolding example contracts into established projects.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Main function to add FHEVM capabilities to an existing Hardhat project
|
|
9
|
+
*/
|
|
10
|
+
export declare function runAddMode(targetDir?: string): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=add-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-mode.d.ts","sourceRoot":"","sources":["../../scripts/add-mode.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkRH;;GAEG;AACH,wBAAsB,UAAU,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA8ElE"}
|
|
@@ -1,19 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Add Mode - Feature for adding FHEVM to existing Hardhat projects.
|
|
4
|
+
*
|
|
5
|
+
* Logic for managing configuration updates, dependency installations,
|
|
6
|
+
* and scaffolding example contracts into established projects.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.runAddMode = runAddMode;
|
|
46
|
+
const p = __importStar(require("@clack/prompts"));
|
|
47
|
+
const picocolors_1 = __importDefault(require("picocolors"));
|
|
48
|
+
const fs = __importStar(require("fs"));
|
|
49
|
+
const path = __importStar(require("path"));
|
|
50
|
+
const config_1 = require("./config");
|
|
51
|
+
const utils_1 = require("./utils");
|
|
7
52
|
// =============================================================================
|
|
8
53
|
// PROJECT DETECTION
|
|
9
54
|
// =============================================================================
|
|
10
55
|
/**
|
|
11
56
|
* Detects if the target directory is a valid Hardhat project
|
|
12
57
|
*/
|
|
13
|
-
|
|
58
|
+
function detectHardhatProject(targetDir) {
|
|
14
59
|
const packageJsonPath = path.join(targetDir, "package.json");
|
|
15
60
|
const hardhatConfigTs = path.join(targetDir, "hardhat.config.ts");
|
|
16
|
-
const hardhatConfigJs = path.join(targetDir, "hardhat.config
|
|
61
|
+
const hardhatConfigJs = path.join(targetDir, "hardhat.config");
|
|
17
62
|
if (!fs.existsSync(packageJsonPath)) {
|
|
18
63
|
return false;
|
|
19
64
|
}
|
|
@@ -33,20 +78,16 @@ export function detectHardhatProject(targetDir) {
|
|
|
33
78
|
/**
|
|
34
79
|
* Updates package.json with FHEVM dependencies
|
|
35
80
|
*/
|
|
36
|
-
|
|
81
|
+
function updatePackageJson(targetDir) {
|
|
37
82
|
const packageJsonPath = path.join(targetDir, "package.json");
|
|
38
83
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
39
|
-
// Add dependencies
|
|
40
84
|
packageJson.dependencies = {
|
|
41
85
|
...packageJson.dependencies,
|
|
42
|
-
|
|
43
|
-
"@fhevm/solidity": "^0.9.1",
|
|
86
|
+
...utils_1.FHEVM_DEPENDENCIES.dependencies,
|
|
44
87
|
};
|
|
45
|
-
// Add devDependencies
|
|
46
88
|
packageJson.devDependencies = {
|
|
47
89
|
...packageJson.devDependencies,
|
|
48
|
-
|
|
49
|
-
"@zama-fhe/relayer-sdk": "^0.3.0-5",
|
|
90
|
+
...utils_1.FHEVM_DEPENDENCIES.devDependencies,
|
|
50
91
|
};
|
|
51
92
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + "\n");
|
|
52
93
|
}
|
|
@@ -56,9 +97,9 @@ export function updatePackageJson(targetDir) {
|
|
|
56
97
|
/**
|
|
57
98
|
* Updates hardhat.config.ts/js with FHEVM plugin import
|
|
58
99
|
*/
|
|
59
|
-
|
|
100
|
+
function updateHardhatConfig(targetDir) {
|
|
60
101
|
const configPathTs = path.join(targetDir, "hardhat.config.ts");
|
|
61
|
-
const configPathJs = path.join(targetDir, "hardhat.config
|
|
102
|
+
const configPathJs = path.join(targetDir, "hardhat.config");
|
|
62
103
|
const actualPath = fs.existsSync(configPathTs)
|
|
63
104
|
? configPathTs
|
|
64
105
|
: fs.existsSync(configPathJs)
|
|
@@ -68,13 +109,10 @@ export function updateHardhatConfig(targetDir) {
|
|
|
68
109
|
throw new Error("hardhat.config.ts or hardhat.config.js not found");
|
|
69
110
|
}
|
|
70
111
|
let content = fs.readFileSync(actualPath, "utf-8");
|
|
71
|
-
// Check if already has FHEVM plugin
|
|
72
112
|
if (content.includes("@fhevm/hardhat-plugin")) {
|
|
73
|
-
return;
|
|
113
|
+
return;
|
|
74
114
|
}
|
|
75
|
-
// Add import at the top (after other imports)
|
|
76
115
|
const importStatement = 'import "@fhevm/hardhat-plugin";\n';
|
|
77
|
-
// Find the last import statement
|
|
78
116
|
const lines = content.split("\n");
|
|
79
117
|
let lastImportIndex = -1;
|
|
80
118
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -87,7 +125,6 @@ export function updateHardhatConfig(targetDir) {
|
|
|
87
125
|
lines.splice(lastImportIndex + 1, 0, importStatement);
|
|
88
126
|
}
|
|
89
127
|
else {
|
|
90
|
-
// No imports found, add at the beginning
|
|
91
128
|
lines.unshift(importStatement);
|
|
92
129
|
}
|
|
93
130
|
content = lines.join("\n");
|
|
@@ -99,12 +136,12 @@ export function updateHardhatConfig(targetDir) {
|
|
|
99
136
|
/**
|
|
100
137
|
* Adds example contract and test files to the project
|
|
101
138
|
*/
|
|
102
|
-
|
|
103
|
-
const example = EXAMPLES[exampleName];
|
|
139
|
+
async function addExampleFiles(exampleName, targetDir) {
|
|
140
|
+
const example = config_1.EXAMPLES[exampleName];
|
|
104
141
|
if (!example) {
|
|
105
142
|
throw new Error(`Unknown example: ${exampleName}`);
|
|
106
143
|
}
|
|
107
|
-
const contractName = getContractName(example.contract);
|
|
144
|
+
const contractName = (0, utils_1.getContractName)(example.contract);
|
|
108
145
|
if (!contractName) {
|
|
109
146
|
throw new Error("Could not extract contract name");
|
|
110
147
|
}
|
|
@@ -130,21 +167,20 @@ export async function addExampleFiles(exampleName, targetDir) {
|
|
|
130
167
|
}
|
|
131
168
|
else if (action === "rename") {
|
|
132
169
|
contractDest = path.join(targetDir, "contracts", `${contractName}_fhevm.sol`);
|
|
133
|
-
await downloadFileFromGitHub(example.contract, contractDest);
|
|
170
|
+
await (0, utils_1.downloadFileFromGitHub)(example.contract, contractDest);
|
|
134
171
|
p.log.success(`Added: ${contractName}_fhevm.sol`);
|
|
135
172
|
}
|
|
136
173
|
else {
|
|
137
|
-
await downloadFileFromGitHub(example.contract, contractDest);
|
|
174
|
+
await (0, utils_1.downloadFileFromGitHub)(example.contract, contractDest);
|
|
138
175
|
p.log.success(`Overwritten: ${contractName}.sol`);
|
|
139
176
|
}
|
|
140
177
|
}
|
|
141
178
|
else {
|
|
142
|
-
// Ensure contracts directory exists
|
|
143
179
|
const contractsDir = path.join(targetDir, "contracts");
|
|
144
180
|
if (!fs.existsSync(contractsDir)) {
|
|
145
181
|
fs.mkdirSync(contractsDir, { recursive: true });
|
|
146
182
|
}
|
|
147
|
-
await downloadFileFromGitHub(example.contract, contractDest);
|
|
183
|
+
await (0, utils_1.downloadFileFromGitHub)(example.contract, contractDest);
|
|
148
184
|
p.log.success(`Added: ${contractName}.sol`);
|
|
149
185
|
}
|
|
150
186
|
// Handle test file
|
|
@@ -165,29 +201,27 @@ export async function addExampleFiles(exampleName, targetDir) {
|
|
|
165
201
|
p.log.info(`Skipped: ${testFileName}`);
|
|
166
202
|
}
|
|
167
203
|
else {
|
|
168
|
-
await downloadFileFromGitHub(example.test, testDest);
|
|
204
|
+
await (0, utils_1.downloadFileFromGitHub)(example.test, testDest);
|
|
169
205
|
p.log.success(`Overwritten: ${testFileName}`);
|
|
170
206
|
}
|
|
171
207
|
}
|
|
172
208
|
else {
|
|
173
|
-
// Ensure test directory exists
|
|
174
209
|
const testDir = path.join(targetDir, "test");
|
|
175
210
|
if (!fs.existsSync(testDir)) {
|
|
176
211
|
fs.mkdirSync(testDir, { recursive: true });
|
|
177
212
|
}
|
|
178
|
-
await downloadFileFromGitHub(example.test, testDest);
|
|
213
|
+
await (0, utils_1.downloadFileFromGitHub)(example.test, testDest);
|
|
179
214
|
p.log.success(`Added: ${testFileName}`);
|
|
180
215
|
}
|
|
181
216
|
// Handle contract dependencies
|
|
182
217
|
if (example.dependencies) {
|
|
183
218
|
p.log.message("");
|
|
184
|
-
p.log.message(
|
|
219
|
+
p.log.message(picocolors_1.default.bold("Downloading contract dependencies..."));
|
|
185
220
|
for (const depPath of example.dependencies) {
|
|
186
221
|
const relativePath = depPath.replace(/^contracts\//, "");
|
|
187
222
|
const depDestPath = path.join(targetDir, "contracts", relativePath);
|
|
188
223
|
const depDestDir = path.dirname(depDestPath);
|
|
189
224
|
const depName = path.basename(depPath);
|
|
190
|
-
// Create directory if needed
|
|
191
225
|
if (!fs.existsSync(depDestDir)) {
|
|
192
226
|
fs.mkdirSync(depDestDir, { recursive: true });
|
|
193
227
|
}
|
|
@@ -195,7 +229,7 @@ export async function addExampleFiles(exampleName, targetDir) {
|
|
|
195
229
|
p.log.info(`Skipped (exists): ${depName}`);
|
|
196
230
|
}
|
|
197
231
|
else {
|
|
198
|
-
await downloadFileFromGitHub(depPath, depDestPath);
|
|
232
|
+
await (0, utils_1.downloadFileFromGitHub)(depPath, depDestPath);
|
|
199
233
|
p.log.success(`Added: ${depName}`);
|
|
200
234
|
}
|
|
201
235
|
}
|
|
@@ -203,7 +237,7 @@ export async function addExampleFiles(exampleName, targetDir) {
|
|
|
203
237
|
// Handle npm dependencies
|
|
204
238
|
if (example.npmDependencies) {
|
|
205
239
|
p.log.message("");
|
|
206
|
-
p.log.message(
|
|
240
|
+
p.log.message(picocolors_1.default.bold("Adding npm dependencies to package.json..."));
|
|
207
241
|
const packageJsonPath = path.join(targetDir, "package.json");
|
|
208
242
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
209
243
|
if (!packageJson.dependencies) {
|
|
@@ -231,26 +265,23 @@ export async function addExampleFiles(exampleName, targetDir) {
|
|
|
231
265
|
/**
|
|
232
266
|
* Main function to add FHEVM capabilities to an existing Hardhat project
|
|
233
267
|
*/
|
|
234
|
-
|
|
268
|
+
async function runAddMode(targetDir) {
|
|
235
269
|
console.clear();
|
|
236
|
-
p.intro(
|
|
237
|
-
// Determine target directory
|
|
270
|
+
p.intro(picocolors_1.default.bgCyan(picocolors_1.default.black(" ⚡ FHEVM Example Factory - Add Mode ")));
|
|
238
271
|
const projectDir = targetDir || process.cwd();
|
|
239
272
|
const absoluteDir = path.resolve(projectDir);
|
|
240
|
-
// Step 1: Detect Hardhat project
|
|
241
273
|
const s = p.spinner();
|
|
242
274
|
s.start("Detecting Hardhat project...");
|
|
243
275
|
if (!detectHardhatProject(absoluteDir)) {
|
|
244
|
-
s.stop(
|
|
276
|
+
s.stop(picocolors_1.default.red("✗ Not a valid Hardhat project"));
|
|
245
277
|
p.log.error("This directory does not contain a valid Hardhat project.");
|
|
246
|
-
p.log.message(
|
|
278
|
+
p.log.message(picocolors_1.default.dim("Make sure package.json and hardhat.config.ts/js exist and hardhat is installed."));
|
|
247
279
|
process.exit(1);
|
|
248
280
|
}
|
|
249
|
-
s.stop(
|
|
250
|
-
// Step 2: Select example
|
|
281
|
+
s.stop(picocolors_1.default.green("✓ Valid Hardhat project detected"));
|
|
251
282
|
const exampleName = await p.select({
|
|
252
283
|
message: "Which FHEVM example would you like to add?",
|
|
253
|
-
options: Object.entries(EXAMPLES).map(([key, config]) => ({
|
|
284
|
+
options: Object.entries(config_1.EXAMPLES).map(([key, config]) => ({
|
|
254
285
|
value: key,
|
|
255
286
|
label: config.title,
|
|
256
287
|
hint: config.category,
|
|
@@ -261,29 +292,26 @@ export async function runAddMode(targetDir) {
|
|
|
261
292
|
process.exit(0);
|
|
262
293
|
}
|
|
263
294
|
p.log.message("");
|
|
264
|
-
// Step 3: Update package.json
|
|
265
295
|
s.start("Updating package.json with FHEVM dependencies...");
|
|
266
296
|
try {
|
|
267
297
|
updatePackageJson(absoluteDir);
|
|
268
|
-
s.stop(
|
|
298
|
+
s.stop(picocolors_1.default.green("✓ package.json updated"));
|
|
269
299
|
}
|
|
270
300
|
catch (error) {
|
|
271
|
-
s.stop(
|
|
301
|
+
s.stop(picocolors_1.default.red("✗ Failed to update package.json"));
|
|
272
302
|
throw error;
|
|
273
303
|
}
|
|
274
|
-
// Step 4: Update hardhat.config
|
|
275
304
|
s.start("Updating hardhat.config with FHEVM plugin...");
|
|
276
305
|
try {
|
|
277
306
|
updateHardhatConfig(absoluteDir);
|
|
278
|
-
s.stop(
|
|
307
|
+
s.stop(picocolors_1.default.green("✓ hardhat.config updated"));
|
|
279
308
|
}
|
|
280
309
|
catch (error) {
|
|
281
|
-
s.stop(
|
|
310
|
+
s.stop(picocolors_1.default.red("✗ Failed to update hardhat.config"));
|
|
282
311
|
throw error;
|
|
283
312
|
}
|
|
284
|
-
// Step 5: Add example files
|
|
285
313
|
p.log.message("");
|
|
286
|
-
p.log.message(
|
|
314
|
+
p.log.message(picocolors_1.default.bold("Adding example files..."));
|
|
287
315
|
try {
|
|
288
316
|
await addExampleFiles(exampleName, absoluteDir);
|
|
289
317
|
}
|
|
@@ -291,11 +319,9 @@ export async function runAddMode(targetDir) {
|
|
|
291
319
|
p.log.error("Failed to add example files");
|
|
292
320
|
throw error;
|
|
293
321
|
}
|
|
294
|
-
// Success!
|
|
295
322
|
p.log.message("");
|
|
296
|
-
p.log.success(
|
|
323
|
+
p.log.success(picocolors_1.default.green("✨ FHEVM capabilities added successfully!"));
|
|
297
324
|
p.log.message("");
|
|
298
|
-
p.note(`${
|
|
299
|
-
p.outro(
|
|
325
|
+
p.note(`${picocolors_1.default.dim("$")} npm install\n${picocolors_1.default.dim("$")} npm run compile\n${picocolors_1.default.dim("$")} npm run test`, "🚀 Next Steps");
|
|
326
|
+
p.outro(picocolors_1.default.green("✅ Setup complete. Happy encrypting!"));
|
|
300
327
|
}
|
|
301
|
-
//# sourceMappingURL=add-mode.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Project Builders - Core logic for scaffolding FHEVM projects.
|
|
3
|
+
*
|
|
4
|
+
* Handles the creation of single example projects, category-based
|
|
5
|
+
* project bundles, and specialized test environments.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Creates a single example project from the template
|
|
9
|
+
*/
|
|
10
|
+
export declare function createSingleExample(exampleName: string, outputDir: string, tempRepoPath: string): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a category project with multiple examples
|
|
13
|
+
*/
|
|
14
|
+
export declare function createCategoryProject(categoryName: string, outputDir: string, tempRepoPath: string): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a temporary test project using LOCAL files (used by maintenance.ts)
|
|
17
|
+
*/
|
|
18
|
+
export declare function createLocalTestProject(exampleNames: string[], outputDir: string): Promise<void>;
|
|
19
|
+
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../scripts/builders.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA0DH;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC,CA8Cf;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC,CAiEf;AAMD;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,YAAY,EAAE,MAAM,EAAE,EACtB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAuEf"}
|