create-fhevm-example 1.4.2 โ†’ 1.4.3

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.
@@ -12,6 +12,18 @@ export declare function cleanupTemplate(outputDir: string): void;
12
12
  * Generates a deploy script for a contract
13
13
  */
14
14
  export declare function generateDeployScript(contractName: string): string;
15
+ /**
16
+ * Extracts FHE function names used in contract
17
+ */
18
+ export declare function extractFHEFunctions(contractContent: string): string[];
19
+ /**
20
+ * Extracts FHE types used in contract (from imports and declarations)
21
+ */
22
+ export declare function extractFHETypes(contractContent: string): string[];
23
+ /**
24
+ * Generates FHE API Reference markdown section (collapsible format)
25
+ */
26
+ export declare function generateFHEApiSection(functions: string[], types: string[]): string;
15
27
  /**
16
28
  * Generates GitBook-compatible markdown documentation
17
29
  */
@@ -1 +1 @@
1
- {"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../../../scripts/shared/generators.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH;;GAEG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAuDvD;AAMD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAkCjE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,MAAM,CA2BR;AAMD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,EACpB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACvC,IAAI,CAiBN;AAMD;;GAEG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EAAE,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,CAAC,CA+BjB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EAAE,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CA2B/C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAchE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CA4B1D"}
1
+ {"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../../../scripts/shared/generators.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH;;GAEG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAuDvD;AAMD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAkCjE;AAgFD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,EAAE,CAUrE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,EAAE,CASjE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,EAAE,EACnB,KAAK,EAAE,MAAM,EAAE,GACd,MAAM,CAwBR;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,MAAM,CAgCR;AAMD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,MAAM,EACpB,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACvC,IAAI,CAiBN;AAMD;;GAEG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EAAE,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,CAAC,CAgCjB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EAAE,EACd,GAAG,EAAE,MAAM,GACV,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CA4B/C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAchE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CA4B1D"}
@@ -41,6 +41,9 @@ var __importStar = (this && this.__importStar) || (function () {
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.cleanupTemplate = cleanupTemplate;
43
43
  exports.generateDeployScript = generateDeployScript;
44
+ exports.extractFHEFunctions = extractFHEFunctions;
45
+ exports.extractFHETypes = extractFHETypes;
46
+ exports.generateFHEApiSection = generateFHEApiSection;
44
47
  exports.generateGitBookMarkdown = generateGitBookMarkdown;
45
48
  exports.updateProjectPackageJson = updateProjectPackageJson;
46
49
  exports.runCommand = runCommand;
@@ -140,6 +143,121 @@ func.id = "deploy_${contractName.toLowerCase()}";
140
143
  func.tags = ["${contractName}"];
141
144
  `;
142
145
  }
146
+ // =============================================================================
147
+ // FHE API Reference (from @fhevm/solidity)
148
+ // =============================================================================
149
+ /** FHE Library Functions with developer-friendly descriptions */
150
+ const FHE_FUNCTION_DESCRIPTIONS = {
151
+ // Type Conversion & Initialization
152
+ asEbool: "Encrypts a plaintext boolean into ebool",
153
+ asEuint8: "Encrypts a plaintext uint8 value into euint8",
154
+ asEuint16: "Encrypts a plaintext uint16 value into euint16",
155
+ asEuint32: "Encrypts a plaintext uint32 value into euint32",
156
+ asEuint64: "Encrypts a plaintext uint64 value into euint64",
157
+ asEuint128: "Encrypts a plaintext uint128 value into euint128",
158
+ asEuint256: "Encrypts a plaintext uint256 value into euint256",
159
+ asEaddress: "Encrypts a plaintext address into eaddress",
160
+ fromExternal: "Validates and converts external encrypted input using inputProof",
161
+ isInitialized: "Checks if an encrypted value has been set (handle != 0)",
162
+ // Arithmetic Operations
163
+ add: "Homomorphic addition: result = a + b (overflow wraps)",
164
+ sub: "Homomorphic subtraction: result = a - b (underflow wraps)",
165
+ mul: "Homomorphic multiplication: result = a * b",
166
+ div: "Homomorphic division: result = a / b (plaintext divisor only)",
167
+ rem: "Homomorphic remainder: result = a % b (plaintext divisor only)",
168
+ neg: "Homomorphic negation (two's complement)",
169
+ min: "Returns smaller of two encrypted values",
170
+ max: "Returns larger of two encrypted values",
171
+ // Comparison Operations (return ebool)
172
+ eq: "Encrypted equality: returns ebool(a == b)",
173
+ ne: "Encrypted inequality: returns ebool(a != b)",
174
+ gt: "Encrypted greater-than: returns ebool(a > b)",
175
+ lt: "Encrypted less-than: returns ebool(a < b)",
176
+ ge: "Encrypted greater-or-equal: returns ebool(a >= b)",
177
+ le: "Encrypted less-or-equal: returns ebool(a <= b)",
178
+ // Bitwise Operations
179
+ and: "Homomorphic bitwise AND",
180
+ or: "Homomorphic bitwise OR",
181
+ xor: "Homomorphic bitwise XOR",
182
+ not: "Homomorphic bitwise NOT",
183
+ shl: "Homomorphic shift left",
184
+ shr: "Homomorphic shift right",
185
+ rotl: "Homomorphic rotate left",
186
+ rotr: "Homomorphic rotate right",
187
+ // Conditional Logic
188
+ select: "Encrypted if-then-else: select(cond, a, b) โ†’ returns a if true, b if false",
189
+ // Random Number Generation
190
+ randEbool: "Generates random encrypted boolean",
191
+ randEuint8: "Generates random encrypted 8-bit integer",
192
+ randEuint16: "Generates random encrypted 16-bit integer",
193
+ randEuint32: "Generates random encrypted 32-bit integer",
194
+ randEuint64: "Generates random encrypted 64-bit integer",
195
+ randEuint128: "Generates random encrypted 128-bit integer",
196
+ randEuint256: "Generates random encrypted 256-bit integer",
197
+ // Access Control
198
+ allow: "Grants PERMANENT permission for address to decrypt/use value",
199
+ allowThis: "Grants contract permission to operate on ciphertext",
200
+ allowTransient: "Grants TEMPORARY permission (expires at tx end)",
201
+ isAllowed: "Checks if address has permission to use ciphertext",
202
+ isSenderAllowed: "Checks if msg.sender has permission",
203
+ // Decryption
204
+ makePubliclyDecryptable: "Marks ciphertext for public decryption via relayer",
205
+ isPubliclyDecryptable: "Checks if ciphertext is publicly decryptable",
206
+ checkSignatures: "Verifies KMS decryption proof (reverts if invalid)",
207
+ toBytes32: "Converts encrypted handle to bytes32 for proof arrays",
208
+ // Utility
209
+ cleanTransientStorage: "Clears transient permissions (for AA bundled UserOps)",
210
+ };
211
+ /**
212
+ * Extracts FHE function names used in contract
213
+ */
214
+ function extractFHEFunctions(contractContent) {
215
+ const pattern = /FHE\.([a-zA-Z0-9]+)\s*[(<]/g;
216
+ const matches = new Set();
217
+ let match;
218
+ while ((match = pattern.exec(contractContent)) !== null) {
219
+ if (FHE_FUNCTION_DESCRIPTIONS[match[1]]) {
220
+ matches.add(match[1]);
221
+ }
222
+ }
223
+ return Array.from(matches).sort();
224
+ }
225
+ /**
226
+ * Extracts FHE types used in contract (from imports and declarations)
227
+ */
228
+ function extractFHETypes(contractContent) {
229
+ const pattern = /\b(ebool|euint(?:8|16|32|64|128|256)|eaddress|externalEbool|externalEuint(?:8|16|32|64|128|256)|externalEaddress)\b/g;
230
+ const matches = new Set();
231
+ let match;
232
+ while ((match = pattern.exec(contractContent)) !== null) {
233
+ matches.add(match[1]);
234
+ }
235
+ return Array.from(matches).sort();
236
+ }
237
+ /**
238
+ * Generates FHE API Reference markdown section (collapsible format)
239
+ */
240
+ function generateFHEApiSection(functions, types) {
241
+ if (functions.length === 0 && types.length === 0)
242
+ return "";
243
+ const totalCount = functions.length + types.length;
244
+ let section = `<details>\n`;
245
+ section += `<summary>๐Ÿ” FHE API Reference (${totalCount} items)</summary>\n\n`;
246
+ // Types
247
+ if (types.length > 0) {
248
+ section += `**Types:** ${types.map((t) => `\`${t}\``).join(" ยท ")}\n\n`;
249
+ }
250
+ // Functions as list
251
+ if (functions.length > 0) {
252
+ section += `**Functions:**\n`;
253
+ for (const f of functions) {
254
+ section += `- \`FHE.${f}()\` - ${FHE_FUNCTION_DESCRIPTIONS[f]}\n`;
255
+ }
256
+ section += `\n`;
257
+ }
258
+ section += `</details>\n\n`;
259
+ return section;
260
+ }
143
261
  /**
144
262
  * Generates GitBook-compatible markdown documentation
145
263
  */
@@ -151,6 +269,10 @@ function generateGitBookMarkdown(description, contractContent, testContent, cont
151
269
  markdown += `- \`.ts\` file โ†’ \`<your-project-root-dir>/test/\`\n\n`;
152
270
  markdown += `This ensures Hardhat can compile and test your contracts as expected.\n`;
153
271
  markdown += `{% endhint %}\n\n`;
272
+ // Extract and add FHE API Reference section
273
+ const fheFunctions = extractFHEFunctions(contractContent);
274
+ const fheTypes = extractFHETypes(contractContent);
275
+ markdown += generateFHEApiSection(fheFunctions, fheTypes);
154
276
  markdown += `{% tabs %}\n\n`;
155
277
  markdown += `{% tab title="${contractName}.sol" %}\n\n`;
156
278
  markdown += `\`\`\`solidity\n`;
@@ -194,7 +316,8 @@ function updateProjectPackageJson(outputDir, projectName, description, npmDepend
194
316
  */
195
317
  function runCommand(cmd, args, cwd) {
196
318
  return new Promise((resolve, reject) => {
197
- const child = (0, child_process_1.spawn)(cmd, args, {
319
+ const fullCommand = [cmd, ...args].join(" ");
320
+ const child = (0, child_process_1.spawn)(fullCommand, [], {
198
321
  cwd,
199
322
  shell: true,
200
323
  stdio: "pipe",
@@ -224,7 +347,8 @@ function runCommand(cmd, args, cwd) {
224
347
  function runCommandWithStatus(cmd, args, cwd) {
225
348
  return new Promise((resolve) => {
226
349
  let output = "";
227
- const proc = (0, child_process_1.spawn)(cmd, args, {
350
+ const fullCommand = [cmd, ...args].join(" ");
351
+ const proc = (0, child_process_1.spawn)(fullCommand, [], {
228
352
  cwd,
229
353
  shell: true,
230
354
  stdio: ["ignore", "pipe", "pipe"],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-fhevm-example",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "Create FHEVM example projects with a single command - A comprehensive toolkit for building privacy-preserving smart contracts",
5
5
  "bin": {
6
6
  "create-fhevm-example": "./dist/scripts/index.js"