midnight-mcp 0.1.41 → 0.2.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 +32 -1
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +10764 -0
- package/dist/index.d.ts +205 -3
- package/dist/index.js +10722 -15
- package/package.json +16 -6
- package/dist/config/compact-version.d.ts +0 -183
- package/dist/config/compact-version.js +0 -423
- package/dist/db/index.d.ts +0 -3
- package/dist/db/index.js +0 -2
- package/dist/db/vectorStore.d.ts +0 -69
- package/dist/db/vectorStore.js +0 -196
- package/dist/pipeline/embeddings.d.ts +0 -25
- package/dist/pipeline/embeddings.js +0 -103
- package/dist/pipeline/github.d.ts +0 -84
- package/dist/pipeline/github.js +0 -399
- package/dist/pipeline/index.d.ts +0 -11
- package/dist/pipeline/index.js +0 -6
- package/dist/pipeline/indexer.d.ts +0 -41
- package/dist/pipeline/indexer.js +0 -254
- package/dist/pipeline/parser.d.ts +0 -46
- package/dist/pipeline/parser.js +0 -436
- package/dist/pipeline/releases.d.ts +0 -112
- package/dist/pipeline/releases.js +0 -298
- package/dist/pipeline/repository.d.ts +0 -372
- package/dist/pipeline/repository.js +0 -520
- package/dist/prompts/index.d.ts +0 -3
- package/dist/prompts/index.js +0 -2
- package/dist/prompts/templates.d.ts +0 -26
- package/dist/prompts/templates.js +0 -443
- package/dist/resources/code.d.ts +0 -15
- package/dist/resources/code.js +0 -122
- package/dist/resources/content/code-content.d.ts +0 -6
- package/dist/resources/content/code-content.js +0 -802
- package/dist/resources/content/docs-content.d.ts +0 -14
- package/dist/resources/content/docs-content.js +0 -1202
- package/dist/resources/content/index.d.ts +0 -6
- package/dist/resources/content/index.js +0 -6
- package/dist/resources/docs.d.ts +0 -15
- package/dist/resources/docs.js +0 -98
- package/dist/resources/index.d.ts +0 -6
- package/dist/resources/index.js +0 -13
- package/dist/resources/schemas.d.ts +0 -16
- package/dist/resources/schemas.js +0 -407
- package/dist/scripts/index-repos.d.ts +0 -12
- package/dist/scripts/index-repos.js +0 -53
- package/dist/server.d.ts +0 -43
- package/dist/server.js +0 -696
- package/dist/services/index.d.ts +0 -6
- package/dist/services/index.js +0 -6
- package/dist/services/sampling.d.ts +0 -62
- package/dist/services/sampling.js +0 -277
- package/dist/tools/analyze.d.ts +0 -106
- package/dist/tools/analyze.js +0 -431
- package/dist/tools/generation.d.ts +0 -9
- package/dist/tools/generation.js +0 -285
- package/dist/tools/health.d.ts +0 -120
- package/dist/tools/health.js +0 -365
- package/dist/tools/index.d.ts +0 -14
- package/dist/tools/index.js +0 -22
- package/dist/tools/meta.d.ts +0 -61
- package/dist/tools/meta.js +0 -282
- package/dist/tools/repository/constants.d.ts +0 -19
- package/dist/tools/repository/constants.js +0 -324
- package/dist/tools/repository/handlers.d.ts +0 -373
- package/dist/tools/repository/handlers.js +0 -724
- package/dist/tools/repository/index.d.ts +0 -9
- package/dist/tools/repository/index.js +0 -13
- package/dist/tools/repository/schemas.d.ts +0 -153
- package/dist/tools/repository/schemas.js +0 -106
- package/dist/tools/repository/tools.d.ts +0 -7
- package/dist/tools/repository/tools.js +0 -484
- package/dist/tools/repository/validation.d.ts +0 -106
- package/dist/tools/repository/validation.js +0 -820
- package/dist/tools/repository.d.ts +0 -6
- package/dist/tools/repository.js +0 -7
- package/dist/tools/search.d.ts +0 -76
- package/dist/tools/search.js +0 -423
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.js +0 -2
- package/dist/types/mcp.d.ts +0 -187
- package/dist/types/mcp.js +0 -6
- package/dist/utils/cache.d.ts +0 -77
- package/dist/utils/cache.js +0 -172
- package/dist/utils/config.d.ts +0 -70
- package/dist/utils/config.js +0 -294
- package/dist/utils/errors.d.ts +0 -111
- package/dist/utils/errors.js +0 -165
- package/dist/utils/health.d.ts +0 -29
- package/dist/utils/health.js +0 -132
- package/dist/utils/hosted-api.d.ts +0 -67
- package/dist/utils/hosted-api.js +0 -119
- package/dist/utils/index.d.ts +0 -16
- package/dist/utils/index.js +0 -15
- package/dist/utils/logger.d.ts +0 -48
- package/dist/utils/logger.js +0 -124
- package/dist/utils/rate-limit.d.ts +0 -61
- package/dist/utils/rate-limit.js +0 -148
- package/dist/utils/validation.d.ts +0 -52
- package/dist/utils/validation.js +0 -255
package/package.json
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "midnight-mcp",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Model Context Protocol Server for Midnight Blockchain Development",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"bin": {
|
|
8
|
-
"midnight-mcp": "./dist/
|
|
8
|
+
"midnight-mcp": "./dist/bin.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "
|
|
12
|
-
"
|
|
13
|
-
"
|
|
11
|
+
"build": "tsup",
|
|
12
|
+
"typecheck": "tsc --noEmit",
|
|
13
|
+
"start": "node dist/bin.js --stdio",
|
|
14
|
+
"start:http": "node dist/bin.js --http",
|
|
15
|
+
"dev": "NODE_ENV=development tsup --watch",
|
|
14
16
|
"test": "vitest",
|
|
15
17
|
"test:coverage": "vitest --coverage",
|
|
16
18
|
"format": "prettier --write src/**/*.ts",
|
|
17
|
-
"prepublishOnly": "npm run build"
|
|
19
|
+
"prepublishOnly": "npm run typecheck && npm run build",
|
|
20
|
+
"ci": "npm run typecheck && npm run build && npm test"
|
|
18
21
|
},
|
|
19
22
|
"keywords": [
|
|
20
23
|
"midnight",
|
|
@@ -32,15 +35,22 @@
|
|
|
32
35
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
33
36
|
"chromadb": "^1.8.1",
|
|
34
37
|
"dotenv": "^16.3.1",
|
|
38
|
+
"express": "^5.2.1",
|
|
39
|
+
"js-yaml": "^4.1.1",
|
|
35
40
|
"octokit": "^3.1.2",
|
|
36
41
|
"openai": "^4.20.1",
|
|
42
|
+
"yargs": "^18.0.0",
|
|
37
43
|
"zod": "^3.22.4"
|
|
38
44
|
},
|
|
39
45
|
"devDependencies": {
|
|
46
|
+
"@types/express": "^5.0.6",
|
|
47
|
+
"@types/js-yaml": "^4.0.9",
|
|
40
48
|
"@types/node": "^20.10.0",
|
|
41
49
|
"@types/tar": "^6.1.13",
|
|
50
|
+
"@types/yargs": "^17.0.35",
|
|
42
51
|
"prettier": "^3.1.0",
|
|
43
52
|
"tar": "^7.5.2",
|
|
53
|
+
"tsup": "^8.5.1",
|
|
44
54
|
"tsx": "^4.6.2",
|
|
45
55
|
"typescript": "^5.3.2",
|
|
46
56
|
"vitest": "^1.0.0"
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compact Language Version Configuration
|
|
3
|
-
*
|
|
4
|
-
* MAINTAINER: Update these values when Compact language syntax changes!
|
|
5
|
-
* See docs/SYNTAX_MAINTENANCE.md for the full update checklist.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Supported Compact language version range
|
|
9
|
-
* Update when new compiler versions are released
|
|
10
|
-
*/
|
|
11
|
-
export declare const COMPACT_VERSION: {
|
|
12
|
-
/** Minimum supported version */
|
|
13
|
-
min: string;
|
|
14
|
-
/** Maximum supported version */
|
|
15
|
-
max: string;
|
|
16
|
-
/** When this config was last updated */
|
|
17
|
-
lastUpdated: string;
|
|
18
|
-
/** Source of truth for syntax patterns */
|
|
19
|
-
referenceSource: string;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Current pragma format that should be used in contracts
|
|
23
|
-
*/
|
|
24
|
-
export declare const RECOMMENDED_PRAGMA: string;
|
|
25
|
-
/**
|
|
26
|
-
* Known deprecated patterns (add new ones here when Compact evolves)
|
|
27
|
-
*/
|
|
28
|
-
export declare const DEPRECATED_PATTERNS: {
|
|
29
|
-
/** Deprecated in: 0.16 */
|
|
30
|
-
ledgerBlock: {
|
|
31
|
-
pattern: RegExp;
|
|
32
|
-
since: string;
|
|
33
|
-
replacement: string;
|
|
34
|
-
description: string;
|
|
35
|
-
};
|
|
36
|
-
/** Deprecated in: 0.15 */
|
|
37
|
-
cellWrapper: {
|
|
38
|
-
pattern: RegExp;
|
|
39
|
-
since: string;
|
|
40
|
-
replacement: string;
|
|
41
|
-
description: string;
|
|
42
|
-
};
|
|
43
|
-
/** Never existed */
|
|
44
|
-
voidType: {
|
|
45
|
-
pattern: RegExp;
|
|
46
|
-
since: string;
|
|
47
|
-
replacement: string;
|
|
48
|
-
description: string;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Reference contracts known to compile successfully
|
|
53
|
-
* Use these to verify syntax is still correct
|
|
54
|
-
*/
|
|
55
|
-
export declare const REFERENCE_CONTRACTS: {
|
|
56
|
-
name: string;
|
|
57
|
-
repo: string;
|
|
58
|
-
description: string;
|
|
59
|
-
}[];
|
|
60
|
-
/**
|
|
61
|
-
* Get the version info as a string for display
|
|
62
|
-
*/
|
|
63
|
-
export declare function getVersionInfo(): string;
|
|
64
|
-
/**
|
|
65
|
-
* Check if a version is within supported range
|
|
66
|
-
*/
|
|
67
|
-
export declare function isVersionSupported(version: string): boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Built-in functions vs patterns you must implement yourself
|
|
70
|
-
* CRITICAL: These are the actual stdlib functions available in Compact
|
|
71
|
-
*/
|
|
72
|
-
export declare const BUILTIN_FUNCTIONS: {
|
|
73
|
-
/** Actually built into the language/stdlib */
|
|
74
|
-
stdlib: {
|
|
75
|
-
name: string;
|
|
76
|
-
signature: string;
|
|
77
|
-
description: string;
|
|
78
|
-
}[];
|
|
79
|
-
/** NOT built-in - you must implement these patterns yourself */
|
|
80
|
-
notBuiltIn: {
|
|
81
|
-
name: string;
|
|
82
|
-
wrongUsage: string;
|
|
83
|
-
correctPattern: string;
|
|
84
|
-
description: string;
|
|
85
|
-
}[];
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Type compatibility rules - what types can be compared/operated together
|
|
89
|
-
*/
|
|
90
|
-
export declare const TYPE_COMPATIBILITY: {
|
|
91
|
-
comparisons: ({
|
|
92
|
-
types: string;
|
|
93
|
-
works: boolean;
|
|
94
|
-
note: string;
|
|
95
|
-
fix?: undefined;
|
|
96
|
-
} | {
|
|
97
|
-
types: string;
|
|
98
|
-
works: boolean;
|
|
99
|
-
fix: string;
|
|
100
|
-
note?: undefined;
|
|
101
|
-
})[];
|
|
102
|
-
arithmetic: ({
|
|
103
|
-
types: string;
|
|
104
|
-
works: boolean;
|
|
105
|
-
note: string;
|
|
106
|
-
fix?: undefined;
|
|
107
|
-
} | {
|
|
108
|
-
types: string;
|
|
109
|
-
works: boolean;
|
|
110
|
-
fix: string;
|
|
111
|
-
note?: undefined;
|
|
112
|
-
})[];
|
|
113
|
-
typeCasting: ({
|
|
114
|
-
from: string;
|
|
115
|
-
to: string;
|
|
116
|
-
direct: boolean;
|
|
117
|
-
fix: string;
|
|
118
|
-
note?: undefined;
|
|
119
|
-
} | {
|
|
120
|
-
from: string;
|
|
121
|
-
to: string;
|
|
122
|
-
direct: boolean;
|
|
123
|
-
note: string;
|
|
124
|
-
fix?: undefined;
|
|
125
|
-
})[];
|
|
126
|
-
assignments: {
|
|
127
|
-
types: string;
|
|
128
|
-
works: boolean;
|
|
129
|
-
fix: string;
|
|
130
|
-
}[];
|
|
131
|
-
tips: string[];
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* Ledger type limitations - what works in circuits vs TypeScript
|
|
135
|
-
*/
|
|
136
|
-
export declare const LEDGER_TYPE_LIMITS: {
|
|
137
|
-
Counter: {
|
|
138
|
-
circuitOperations: {
|
|
139
|
-
method: string;
|
|
140
|
-
works: boolean;
|
|
141
|
-
note: string;
|
|
142
|
-
}[];
|
|
143
|
-
typescriptAccess: string;
|
|
144
|
-
reason: string;
|
|
145
|
-
};
|
|
146
|
-
Map: {
|
|
147
|
-
circuitOperations: {
|
|
148
|
-
method: string;
|
|
149
|
-
works: boolean;
|
|
150
|
-
note: string;
|
|
151
|
-
}[];
|
|
152
|
-
typescriptAccess: string;
|
|
153
|
-
note: string;
|
|
154
|
-
};
|
|
155
|
-
Set: {
|
|
156
|
-
circuitOperations: {
|
|
157
|
-
method: string;
|
|
158
|
-
works: boolean;
|
|
159
|
-
note: string;
|
|
160
|
-
}[];
|
|
161
|
-
typescriptAccess: string;
|
|
162
|
-
note: string;
|
|
163
|
-
};
|
|
164
|
-
MerkleTree: {
|
|
165
|
-
circuitOperations: {
|
|
166
|
-
method: string;
|
|
167
|
-
works: boolean;
|
|
168
|
-
note: string;
|
|
169
|
-
}[];
|
|
170
|
-
typescriptAccess: string;
|
|
171
|
-
pattern: string;
|
|
172
|
-
};
|
|
173
|
-
};
|
|
174
|
-
/**
|
|
175
|
-
* Common compilation errors with their fixes
|
|
176
|
-
* Maps actual compiler error messages to solutions
|
|
177
|
-
*/
|
|
178
|
-
export declare const COMMON_ERRORS: {
|
|
179
|
-
error: string;
|
|
180
|
-
cause: string;
|
|
181
|
-
fix: string;
|
|
182
|
-
}[];
|
|
183
|
-
//# sourceMappingURL=compact-version.d.ts.map
|
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compact Language Version Configuration
|
|
3
|
-
*
|
|
4
|
-
* MAINTAINER: Update these values when Compact language syntax changes!
|
|
5
|
-
* See docs/SYNTAX_MAINTENANCE.md for the full update checklist.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Supported Compact language version range
|
|
9
|
-
* Update when new compiler versions are released
|
|
10
|
-
*/
|
|
11
|
-
export const COMPACT_VERSION = {
|
|
12
|
-
/** Minimum supported version */
|
|
13
|
-
min: "0.16",
|
|
14
|
-
/** Maximum supported version */
|
|
15
|
-
max: "0.18",
|
|
16
|
-
/** When this config was last updated */
|
|
17
|
-
lastUpdated: "2025-01-26",
|
|
18
|
-
/** Source of truth for syntax patterns */
|
|
19
|
-
referenceSource: "https://github.com/piotr-iohk/template-contract",
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Current pragma format that should be used in contracts
|
|
23
|
-
*/
|
|
24
|
-
export const RECOMMENDED_PRAGMA = `pragma language_version >= ${COMPACT_VERSION.min} && <= ${COMPACT_VERSION.max};`;
|
|
25
|
-
/**
|
|
26
|
-
* Known deprecated patterns (add new ones here when Compact evolves)
|
|
27
|
-
*/
|
|
28
|
-
export const DEPRECATED_PATTERNS = {
|
|
29
|
-
/** Deprecated in: 0.16 */
|
|
30
|
-
ledgerBlock: {
|
|
31
|
-
pattern: /ledger\s*\{/,
|
|
32
|
-
since: "0.16",
|
|
33
|
-
replacement: "export ledger fieldName: Type;",
|
|
34
|
-
description: "Block-style ledger declarations",
|
|
35
|
-
},
|
|
36
|
-
/** Deprecated in: 0.15 */
|
|
37
|
-
cellWrapper: {
|
|
38
|
-
pattern: /Cell\s*<\s*\w+\s*>/,
|
|
39
|
-
since: "0.15",
|
|
40
|
-
replacement: "Type (without Cell wrapper)",
|
|
41
|
-
description: "Cell<T> type wrapper",
|
|
42
|
-
},
|
|
43
|
-
/** Never existed */
|
|
44
|
-
voidType: {
|
|
45
|
-
pattern: /:\s*Void\b/,
|
|
46
|
-
since: "always",
|
|
47
|
-
replacement: "[] (empty tuple)",
|
|
48
|
-
description: "Void return type",
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Reference contracts known to compile successfully
|
|
53
|
-
* Use these to verify syntax is still correct
|
|
54
|
-
*/
|
|
55
|
-
export const REFERENCE_CONTRACTS = [
|
|
56
|
-
{
|
|
57
|
-
name: "template-contract",
|
|
58
|
-
repo: "piotr-iohk/template-contract",
|
|
59
|
-
description: "Official Midnight template contract",
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: "tokenomics-project",
|
|
63
|
-
repo: "piotr-iohk/tokenomics-project",
|
|
64
|
-
description: "Token implementation example",
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: "zswap-example",
|
|
68
|
-
repo: "piotr-iohk/zswap-example",
|
|
69
|
-
description: "Privacy-preserving swap example",
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
name: "reentrancy-example",
|
|
73
|
-
repo: "piotr-iohk/reentrancy-example",
|
|
74
|
-
description: "Cross-contract call patterns",
|
|
75
|
-
},
|
|
76
|
-
];
|
|
77
|
-
/**
|
|
78
|
-
* Get the version info as a string for display
|
|
79
|
-
*/
|
|
80
|
-
export function getVersionInfo() {
|
|
81
|
-
return `Compact ${COMPACT_VERSION.min}-${COMPACT_VERSION.max} (updated ${COMPACT_VERSION.lastUpdated})`;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Check if a version is within supported range
|
|
85
|
-
*/
|
|
86
|
-
export function isVersionSupported(version) {
|
|
87
|
-
const [major, minor] = version.split(".").map(Number);
|
|
88
|
-
const [minMajor, minMinor] = COMPACT_VERSION.min.split(".").map(Number);
|
|
89
|
-
const [maxMajor, maxMinor] = COMPACT_VERSION.max.split(".").map(Number);
|
|
90
|
-
const versionNum = major * 100 + minor;
|
|
91
|
-
const minNum = minMajor * 100 + minMinor;
|
|
92
|
-
const maxNum = maxMajor * 100 + maxMinor;
|
|
93
|
-
return versionNum >= minNum && versionNum <= maxNum;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Built-in functions vs patterns you must implement yourself
|
|
97
|
-
* CRITICAL: These are the actual stdlib functions available in Compact
|
|
98
|
-
*/
|
|
99
|
-
export const BUILTIN_FUNCTIONS = {
|
|
100
|
-
/** Actually built into the language/stdlib */
|
|
101
|
-
stdlib: [
|
|
102
|
-
{
|
|
103
|
-
name: "persistentHash",
|
|
104
|
-
signature: "persistentHash<T>(value: T): Bytes<32>",
|
|
105
|
-
description: "Poseidon hash that produces consistent results across calls",
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
name: "persistentCommit",
|
|
109
|
-
signature: "persistentCommit<T>(value: T): Bytes<32>",
|
|
110
|
-
description: "Creates a hiding commitment to a value",
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
name: "pad",
|
|
114
|
-
signature: "pad(length: number, value: string): Bytes<N>",
|
|
115
|
-
description: "Pads a string to fixed-length bytes",
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
name: "disclose",
|
|
119
|
-
signature: "disclose(value: T): T",
|
|
120
|
-
description: "Explicitly reveals a witness value (required in conditionals)",
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
name: "assert",
|
|
124
|
-
signature: "assert(condition: Boolean, message?: string): []",
|
|
125
|
-
description: "Fails circuit if condition is false",
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
name: "default",
|
|
129
|
-
signature: "default<T>(): T",
|
|
130
|
-
description: "Returns default value for a type (0 for numbers, empty for collections)",
|
|
131
|
-
},
|
|
132
|
-
],
|
|
133
|
-
/** NOT built-in - you must implement these patterns yourself */
|
|
134
|
-
notBuiltIn: [
|
|
135
|
-
{
|
|
136
|
-
name: "public_key",
|
|
137
|
-
wrongUsage: "public_key(sk) // ERROR: unbound identifier",
|
|
138
|
-
correctPattern: `// Derive public key using persistentHash
|
|
139
|
-
const pk = persistentHash<Vector<2, Bytes<32>>>([
|
|
140
|
-
pad(32, "midnight:pk:"),
|
|
141
|
-
sk
|
|
142
|
-
]);`,
|
|
143
|
-
description: "Public key derivation is NOT a builtin - use persistentHash pattern",
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
name: "verify_signature",
|
|
147
|
-
wrongUsage: "verify_signature(msg, sig, pk) // Does not exist",
|
|
148
|
-
correctPattern: `// Signature verification must be done via witnesses
|
|
149
|
-
// The prover verifies off-chain, then provides the boolean result
|
|
150
|
-
witness signature_valid(): Boolean;`,
|
|
151
|
-
description: "Signature verification is done off-chain in the prover",
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
name: "random",
|
|
155
|
-
wrongUsage: "random() // Does not exist in ZK circuits",
|
|
156
|
-
correctPattern: `// Randomness must come from witnesses (prover-provided)
|
|
157
|
-
witness get_random_value(): Field;`,
|
|
158
|
-
description: "ZK circuits are deterministic - randomness must come from witnesses",
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
|
-
};
|
|
162
|
-
/**
|
|
163
|
-
* Type compatibility rules - what types can be compared/operated together
|
|
164
|
-
*/
|
|
165
|
-
export const TYPE_COMPATIBILITY = {
|
|
166
|
-
comparisons: [
|
|
167
|
-
{ types: "Field == Field", works: true, note: "Direct comparison" },
|
|
168
|
-
{
|
|
169
|
-
types: "Field == Uint<N>",
|
|
170
|
-
works: false,
|
|
171
|
-
fix: "Cast with `value as Field`",
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
types: "Field >= 0",
|
|
175
|
-
works: false,
|
|
176
|
-
fix: "Use bounded Uint<0..N> parameter instead",
|
|
177
|
-
},
|
|
178
|
-
{ types: "Uint<N> == Uint<N>", works: true, note: "Same-width comparison" },
|
|
179
|
-
{
|
|
180
|
-
types: "Uint<0..2> == Uint<0..2>",
|
|
181
|
-
works: true,
|
|
182
|
-
note: "Bounded integers",
|
|
183
|
-
},
|
|
184
|
-
{ types: "Bytes<32> == Bytes<32>", works: true, note: "Direct comparison" },
|
|
185
|
-
{ types: "Boolean == Boolean", works: true, note: "Direct comparison" },
|
|
186
|
-
],
|
|
187
|
-
arithmetic: [
|
|
188
|
-
{ types: "Field + Field", works: true, note: "Field arithmetic" },
|
|
189
|
-
{ types: "Field + Uint<N>", works: false, fix: "Cast Uint to Field first" },
|
|
190
|
-
{
|
|
191
|
-
types: "Uint<N> + Uint<N>",
|
|
192
|
-
works: true,
|
|
193
|
-
note: "Result is bounded type, cast back: (a + b) as Uint<64>",
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
types: "Uint<64> + Uint<64>",
|
|
197
|
-
works: true,
|
|
198
|
-
note: "Result is Uint<0..36893488147419103230>, must cast: (a + b) as Uint<64>",
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
types: "Uint<64> * Uint<64>",
|
|
202
|
-
works: true,
|
|
203
|
-
note: "Result is wide bounded type, cast back to target type",
|
|
204
|
-
},
|
|
205
|
-
],
|
|
206
|
-
typeCasting: [
|
|
207
|
-
{
|
|
208
|
-
from: "Uint<64>",
|
|
209
|
-
to: "Bytes<32>",
|
|
210
|
-
direct: false,
|
|
211
|
-
fix: "Go through Field: (amount as Field) as Bytes<32>",
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
from: "Uint<N>",
|
|
215
|
-
to: "Field",
|
|
216
|
-
direct: true,
|
|
217
|
-
note: "Safe cast: value as Field",
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
from: "arithmetic result",
|
|
221
|
-
to: "Uint<64>",
|
|
222
|
-
direct: true,
|
|
223
|
-
note: "Required cast: (a + b) as Uint<64>",
|
|
224
|
-
},
|
|
225
|
-
],
|
|
226
|
-
assignments: [
|
|
227
|
-
{
|
|
228
|
-
types: "Field = Uint<N>",
|
|
229
|
-
works: false,
|
|
230
|
-
fix: "Cast with `value as Field`",
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
types: "Uint<N> = Field",
|
|
234
|
-
works: false,
|
|
235
|
-
fix: "Use bounded param or explicit cast",
|
|
236
|
-
},
|
|
237
|
-
],
|
|
238
|
-
tips: [
|
|
239
|
-
"Use Uint<0..N> for circuit parameters that need range validation",
|
|
240
|
-
"Field is unbounded - use for hashes, commitments, general computation",
|
|
241
|
-
"Uint<N> is bounded - use when you need range checks",
|
|
242
|
-
"Casting with `as Field` is safe but loses range information",
|
|
243
|
-
],
|
|
244
|
-
};
|
|
245
|
-
/**
|
|
246
|
-
* Ledger type limitations - what works in circuits vs TypeScript
|
|
247
|
-
*/
|
|
248
|
-
export const LEDGER_TYPE_LIMITS = {
|
|
249
|
-
Counter: {
|
|
250
|
-
circuitOperations: [
|
|
251
|
-
{ method: ".increment(n)", works: true, note: "Adds n to counter" },
|
|
252
|
-
{
|
|
253
|
-
method: ".decrement(n)",
|
|
254
|
-
works: true,
|
|
255
|
-
note: "Subtracts n from counter",
|
|
256
|
-
},
|
|
257
|
-
{ method: ".resetToDefault()", works: true, note: "Resets to 0" },
|
|
258
|
-
{ method: ".value()", works: false, note: "NOT available in circuits" },
|
|
259
|
-
],
|
|
260
|
-
typescriptAccess: "Access counter value via `ledgerState.counter` in TypeScript SDK",
|
|
261
|
-
reason: "ZK circuits cannot read current ledger state - only modify it",
|
|
262
|
-
},
|
|
263
|
-
Map: {
|
|
264
|
-
circuitOperations: [
|
|
265
|
-
{
|
|
266
|
-
method: ".insert(key, value)",
|
|
267
|
-
works: true,
|
|
268
|
-
note: "Adds/updates entry",
|
|
269
|
-
},
|
|
270
|
-
{ method: ".remove(key)", works: true, note: "Removes entry" },
|
|
271
|
-
{
|
|
272
|
-
method: ".lookup(key)",
|
|
273
|
-
works: true,
|
|
274
|
-
note: "Returns Option<ValueType> - use in circuits",
|
|
275
|
-
},
|
|
276
|
-
{
|
|
277
|
-
method: ".member(key)",
|
|
278
|
-
works: true,
|
|
279
|
-
note: "Returns Boolean - checks if key exists",
|
|
280
|
-
},
|
|
281
|
-
],
|
|
282
|
-
typescriptAccess: "Query map via `contractState.data.get(key)` in TypeScript SDK",
|
|
283
|
-
note: "Map.lookup() and Map.member() ARE available in circuits (verified with OpenZeppelin contracts)",
|
|
284
|
-
},
|
|
285
|
-
Set: {
|
|
286
|
-
circuitOperations: [
|
|
287
|
-
{ method: ".insert(value)", works: true, note: "Adds to set" },
|
|
288
|
-
{ method: ".remove(value)", works: true, note: "Removes from set" },
|
|
289
|
-
{
|
|
290
|
-
method: ".member(value)",
|
|
291
|
-
works: true,
|
|
292
|
-
note: "Returns Boolean - checks if value exists in set",
|
|
293
|
-
},
|
|
294
|
-
],
|
|
295
|
-
typescriptAccess: "Check membership via `contractState.set.has(value)` in TypeScript SDK",
|
|
296
|
-
note: "Set.member() IS available in circuits",
|
|
297
|
-
},
|
|
298
|
-
MerkleTree: {
|
|
299
|
-
circuitOperations: [
|
|
300
|
-
{ method: ".insert(leaf)", works: true, note: "Adds leaf to tree" },
|
|
301
|
-
{ method: ".root()", works: false, note: "NOT available in circuits" },
|
|
302
|
-
],
|
|
303
|
-
typescriptAccess: "Get root via `contractState.tree.root` in TypeScript SDK",
|
|
304
|
-
pattern: `// To verify a merkle proof in circuit:
|
|
305
|
-
witness get_merkle_root(): Bytes<32>;
|
|
306
|
-
witness get_merkle_proof(leaf: Bytes<32>): Vector<32, Bytes<32>>;
|
|
307
|
-
|
|
308
|
-
// Verify proof using persistentHash to compute expected root`,
|
|
309
|
-
},
|
|
310
|
-
};
|
|
311
|
-
/**
|
|
312
|
-
* Common compilation errors with their fixes
|
|
313
|
-
* Maps actual compiler error messages to solutions
|
|
314
|
-
*/
|
|
315
|
-
export const COMMON_ERRORS = [
|
|
316
|
-
{
|
|
317
|
-
error: 'unbound identifier "public_key"',
|
|
318
|
-
cause: "Trying to use public_key() as if it's a builtin function",
|
|
319
|
-
fix: `Use persistentHash pattern instead:
|
|
320
|
-
const pk = persistentHash<Vector<2, Bytes<32>>>([pad(32, "midnight:pk:"), sk]);`,
|
|
321
|
-
},
|
|
322
|
-
{
|
|
323
|
-
error: "incompatible combination of types Field and Uint",
|
|
324
|
-
cause: "Comparing or operating on Field with Uint without casting",
|
|
325
|
-
fix: `Cast Uint to Field: (myUint as Field)
|
|
326
|
-
Or use bounded Uint<0..N> for parameters that need constraints`,
|
|
327
|
-
},
|
|
328
|
-
{
|
|
329
|
-
error: 'operation "value" undefined for ledger field type Counter',
|
|
330
|
-
cause: "Trying to read Counter.value() inside a circuit",
|
|
331
|
-
fix: `Counter values cannot be read in circuits. Options:
|
|
332
|
-
1. Use a witness: witness get_counter_value(): Uint<64>;
|
|
333
|
-
2. Read from TypeScript SDK: ledgerState.counter
|
|
334
|
-
3. Track the value in a separate Field ledger variable`,
|
|
335
|
-
},
|
|
336
|
-
{
|
|
337
|
-
error: "implicit disclosure of witness value",
|
|
338
|
-
cause: "Using witness value in conditional without disclose()",
|
|
339
|
-
fix: `Wrap witness comparisons in disclose():
|
|
340
|
-
if (disclose(witness_value == expected)) { ... }`,
|
|
341
|
-
},
|
|
342
|
-
{
|
|
343
|
-
error: 'parse error: found "{" looking for an identifier',
|
|
344
|
-
cause: "Using old ledger { } block syntax",
|
|
345
|
-
fix: `Use individual exports instead:
|
|
346
|
-
export ledger field1: Type1;
|
|
347
|
-
export ledger field2: Type2;`,
|
|
348
|
-
},
|
|
349
|
-
{
|
|
350
|
-
error: 'parse error: found "{" looking for ";"',
|
|
351
|
-
cause: "Using Void as return type (doesn't exist)",
|
|
352
|
-
fix: `Use empty tuple [] for no return value:
|
|
353
|
-
export circuit myCircuit(): [] { ... }`,
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
error: 'unbound identifier "Cell"',
|
|
357
|
-
cause: "Using deprecated Cell<T> wrapper (removed in 0.15)",
|
|
358
|
-
fix: `Remove Cell wrapper, just use the type directly:
|
|
359
|
-
export ledger myField: Field; // Not Cell<Field>`,
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
error: "member access requires struct type",
|
|
363
|
-
cause: "Trying to access a field on a non-struct type",
|
|
364
|
-
fix: `Make sure you're accessing a struct field, not a primitive.
|
|
365
|
-
Map.lookup() and Map.member() ARE available in circuits.
|
|
366
|
-
Check that the base type is actually a struct.`,
|
|
367
|
-
},
|
|
368
|
-
{
|
|
369
|
-
error: "potential witness-value disclosure must be declared",
|
|
370
|
-
cause: "Circuit parameter flows to ledger operation without disclose()",
|
|
371
|
-
fix: `Disclose parameters at the start of the circuit:
|
|
372
|
-
export circuit my_circuit(param: Bytes<32>): [] {
|
|
373
|
-
const d_param = disclose(param); // Acknowledge on-chain visibility
|
|
374
|
-
ledger.insert(d_param, value); // Now use disclosed value
|
|
375
|
-
}`,
|
|
376
|
-
},
|
|
377
|
-
{
|
|
378
|
-
error: "expected second argument of insert to have type Uint<64> but received Uint<0..N>",
|
|
379
|
-
cause: "Arithmetic result has bounded type, needs cast back to target",
|
|
380
|
-
fix: `Cast arithmetic results back to the target type:
|
|
381
|
-
const new_balance = (current + amount) as Uint<64>;
|
|
382
|
-
ledger_map.insert(key, new_balance);`,
|
|
383
|
-
},
|
|
384
|
-
{
|
|
385
|
-
error: "cannot cast from type Uint<64> to type Bytes<32>",
|
|
386
|
-
cause: "Direct Uint to Bytes cast not allowed",
|
|
387
|
-
fix: `Go through Field first:
|
|
388
|
-
const amount_field = amount as Field;
|
|
389
|
-
const amount_bytes = amount_field as Bytes<32>;
|
|
390
|
-
// Or chained: (amount as Field) as Bytes<32>`,
|
|
391
|
-
},
|
|
392
|
-
{
|
|
393
|
-
error: "cannot prove assertion",
|
|
394
|
-
cause: "Assert condition cannot be proven true",
|
|
395
|
-
fix: `Check your logic. Common causes:
|
|
396
|
-
1. Witness returns unexpected value
|
|
397
|
-
2. Range check fails (use bounded Uint)
|
|
398
|
-
3. Logic error in circuit`,
|
|
399
|
-
},
|
|
400
|
-
{
|
|
401
|
-
error: 'parse error: found ":" looking for ")"',
|
|
402
|
-
cause: "Using Rust-style :: for enum variant access",
|
|
403
|
-
fix: `Use dot notation for enum variants:
|
|
404
|
-
WRONG: Choice::rock, GameState::waiting
|
|
405
|
-
CORRECT: Choice.rock, GameState.waiting`,
|
|
406
|
-
},
|
|
407
|
-
{
|
|
408
|
-
error: 'parse error: found "{" after witness declaration',
|
|
409
|
-
cause: "Trying to add implementation body to witness",
|
|
410
|
-
fix: `Witnesses are declarations only - no body allowed:
|
|
411
|
-
WRONG: witness get_caller(): Bytes<32> { return ...; }
|
|
412
|
-
CORRECT: witness get_caller(): Bytes<32>;
|
|
413
|
-
Implementation goes in TypeScript prover, not Compact.`,
|
|
414
|
-
},
|
|
415
|
-
{
|
|
416
|
-
error: 'unbound identifier "function"',
|
|
417
|
-
cause: 'Using "pure function" instead of "pure circuit"',
|
|
418
|
-
fix: `Use "pure circuit" for helper functions:
|
|
419
|
-
WRONG: pure function helper(...): Type { }
|
|
420
|
-
CORRECT: pure circuit helper(...): Type { }`,
|
|
421
|
-
},
|
|
422
|
-
];
|
|
423
|
-
//# sourceMappingURL=compact-version.js.map
|
package/dist/db/index.d.ts
DELETED
package/dist/db/index.js
DELETED