midnight-mcp 0.1.21 → 0.1.22

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.
@@ -1379,6 +1379,44 @@ export async function extractContractStructure(input) {
1379
1379
  }
1380
1380
  }
1381
1381
  }
1382
+ // 10. Detect constructor parameters assigned to ledger without disclose()
1383
+ // Constructor parameters are treated as witness values and need disclose() when written to ledger
1384
+ const constructorMatch = code.match(/constructor\s*\(([^)]*)\)\s*\{([\s\S]*?)(?=\n\s*(?:export|circuit|witness|ledger|constructor|\}|$))/);
1385
+ if (constructorMatch) {
1386
+ const paramsStr = constructorMatch[1];
1387
+ const constructorBody = constructorMatch[2];
1388
+ // Extract constructor parameter names
1389
+ const paramPattern = /(\w+)\s*:\s*[^,)]+/g;
1390
+ const constructorParams = [];
1391
+ let paramMatch;
1392
+ while ((paramMatch = paramPattern.exec(paramsStr)) !== null) {
1393
+ constructorParams.push(paramMatch[1]);
1394
+ }
1395
+ // Check each parameter for direct assignment to ledger without disclose
1396
+ for (const param of constructorParams) {
1397
+ // Look for direct assignment: ledgerField = param (without disclose)
1398
+ const assignmentPattern = new RegExp(`(\\w+)\\s*=\\s*(?!disclose\\s*\\()${param}\\b`, "g");
1399
+ let assignMatch;
1400
+ while ((assignMatch = assignmentPattern.exec(constructorBody)) !== null) {
1401
+ const fieldName = assignMatch[1];
1402
+ // Check if the field is a ledger item
1403
+ const isLedgerField = ledgerItems.some((l) => l.name === fieldName);
1404
+ if (isLedgerField) {
1405
+ // Find the line number
1406
+ const beforeAssign = code.substring(0, constructorMatch.index +
1407
+ constructorMatch[0].indexOf(assignMatch[0]));
1408
+ const lineNum = (beforeAssign.match(/\n/g) || []).length + 1;
1409
+ potentialIssues.push({
1410
+ type: "undisclosed_constructor_param",
1411
+ line: lineNum,
1412
+ message: `Constructor parameter '${param}' assigned to ledger field '${fieldName}' without disclose()`,
1413
+ suggestion: `Wrap in disclose(): '${fieldName} = disclose(${param});'`,
1414
+ severity: "error",
1415
+ });
1416
+ }
1417
+ }
1418
+ }
1419
+ }
1382
1420
  const summary = [];
1383
1421
  if (circuits.length > 0) {
1384
1422
  summary.push(`${circuits.length} circuit(s)`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "midnight-mcp",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "description": "Model Context Protocol Server for Midnight Blockchain Development",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",